@hiperplano/aluy-cli 1.0.0-rc.65 → 1.0.0-rc.66

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- var Kj=Object.defineProperty;var p=(t,e,o)=>()=>{if(o)throw o[0];try{return t&&(e=t(t=0)),e}catch(n){throw o=[n],n}};var ut=(t,e)=>{for(var o in e)Kj(t,o,{get:e[o],enumerable:!0})};import{homedir as Yj}from"node:os";import{join as Vj}from"node:path";function $l(t=Yj()){return Vj(t,".aluy")}var gm=p(()=>{"use strict"});var Fl,NE=p(()=>{"use strict";Fl="1.0.0-rc.65"});function wr(t,e){return t.decide(e)}var Zs=p(()=>{"use strict"});var Un,Ar,Er=p(()=>{"use strict";Un="remember",Ar="recall"});var Hg,Xj,oa,qg=p(()=>{"use strict";Hg=class{id;horizon;label;parentId;children;dependencies;pinned;closed;createdAt;lastAccessedAt;accessCount;context;constructor(e,o,n,r,s){this.id=e,this.horizon=o,this.label=n,this.parentId=r,this.children=new Set,this.dependencies=new Set,this.pinned=!1,this.closed=!1,this.createdAt=s,this.lastAccessedAt=s,this.accessCount=0,this.context=[]}touch(e){this.lastAccessedAt=e,this.accessCount+=1}snapshot(){return{id:this.id,horizon:this.horizon,label:this.label,parentId:this.parentId,children:[...this.children],dependencies:[...this.dependencies],pinned:this.pinned,closed:this.closed,createdAt:this.createdAt,lastAccessedAt:this.lastAccessedAt,accessCount:this.accessCount,contextSize:this.context.length}}},Xj=200,oa=class{nodes=new Map;maxBoxes;now;constructor(e){this.maxBoxes=e?.maxBoxes??Xj,this.now=e?.clock??Date.now}static boxId(e,o){return`${e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)}-${o.toString(36)}`}openBox(e,o,n,r){let s=this.nodes.get(e);if(s)return s.touch(this.now()),{box:s.snapshot(),created:!1};if(this.nodes.size>=this.maxBoxes&&(this.evictOne(),this.nodes.size>=this.maxBoxes))return null;let i=this.now(),a=new Hg(e,o,n,r??null,i);if(r){let l=this.nodes.get(r);l&&l.children.add(e)}return this.nodes.set(e,a),{box:a.snapshot(),created:!0}}closeBox(e){let o=this.nodes.get(e);return o?(o.closed=!0,o.touch(this.now()),o.snapshot()):null}isClosed(e){let o=this.nodes.get(e);return o?o.closed:!1}reopenBox(e){let o=this.nodes.get(e);return o?(o.closed=!1,o.touch(this.now()),o.snapshot()):null}setHorizon(e,o){let n=this.nodes.get(e);return n?(n.horizon=o,n.touch(this.now()),n.snapshot()):null}setParent(e,o){let n=this.nodes.get(e);return n?n.parentId===o?n.snapshot():o!==null&&this.wouldCreateCycle(e,o)?null:(n.parentId&&this.nodes.get(n.parentId)?.children.delete(e),n.parentId=o,o&&this.nodes.get(o)?.children.add(e),n.touch(this.now()),n.snapshot()):null}wouldCreateCycle(e,o){let n=new Set,r=o;for(;r!==null;){if(r===e||n.has(r))return!0;n.add(r),r=this.nodes.get(r)?.parentId??null}return!1}getBox(e){let o=this.nodes.get(e);return o?(o.touch(this.now()),o.snapshot()):null}listBoxes(e="lastAccessedAt"){let o=[...this.nodes.values()].map(n=>n.snapshot());switch(e){case"createdAt":return o.sort((n,r)=>n.createdAt-r.createdAt);case"accessCount":return o.sort((n,r)=>r.accessCount-n.accessCount);default:return o.sort((n,r)=>r.lastAccessedAt-n.lastAccessedAt)}}get size(){return this.nodes.size}addContext(e,o){let n=this.nodes.get(e);return n?(n.context.push({ts:this.now(),text:o}),n.touch(this.now()),n.snapshot()):null}getContext(e){let o=this.nodes.get(e);return o?(o.touch(this.now()),[...o.context]):[]}getContextChain(e){let o=[],n=new Set,r=e;for(;r&&!n.has(r);){n.add(r);let s=this.nodes.get(r);if(!s)break;s.touch(this.now()),o.push({boxId:s.id,entries:[...s.context]}),r=s.parentId}return o}addDependency(e,o){let n=this.nodes.get(e);return!n||!this.nodes.has(o)||n.id===o?!1:(n.dependencies.add(o),n.touch(this.now()),!0)}getDependencies(e){let o=this.nodes.get(e);return o?[...o.dependencies]:[]}pinBox(e){let o=this.nodes.get(e);return o?(o.pinned=!0,o.touch(this.now()),o.snapshot()):null}unpinBox(e){let o=this.nodes.get(e);return o?(o.pinned=!1,o.touch(this.now()),o.snapshot()):null}evictOne(){let e=[];for(let n of this.nodes.values())n.horizon==="longo"||n.pinned||e.push(n);if(e.length===0)return null;e.sort((n,r)=>{let s=n.horizon==="curto"?0:1,i=r.horizon==="curto"?0:1;if(s!==i)return s-i;let a=n.closed?0:1,l=r.closed?0:1;return a!==l?a-l:n.lastAccessedAt!==r.lastAccessedAt?n.lastAccessedAt-r.lastAccessedAt:n.accessCount-r.accessCount});let o=e[0];return this.removeNode(o)}forceEvict(e){let o=this.nodes.get(e);return!o||o.horizon==="longo"||o.pinned?null:this.removeNode(o)}removeBox(e){let o=this.nodes.get(e);return o?this.removeNode(o):null}removeNode(e){if(e.parentId){let o=this.nodes.get(e.parentId);o&&o.children.delete(e.id)}return this.nodes.delete(e.id),e.snapshot()}}});function ym(t){let e=[];for(let o of t){e.push({step:o,depth:0});for(let n of o.substeps??[])e.push({step:n,depth:1})}return e}function FE(t,e){let o,n="pending",r;if(typeof t=="string")o=t;else if(t!==null&&typeof t=="object"){let i=t,a=i.title??i.step??i.text??i.name??i.content;if(typeof a=="string"&&(o=a),typeof i.status=="string"&&Jj.has(i.status)&&(n=i.status),e){let l=i.substeps??i.subtasks??i.subpassos??i.children;if(Array.isArray(l)&&l.length>0){let c=[];for(let d of l){let m=FE(d,!1);if(typeof m=="string")return m;c.push(m)}r=c}}}if(o===void 0||o.trim()==="")return Zj;let s=o.trim().slice(0,Qj);return r?{title:s,status:n,substeps:r}:{title:s,status:n}}function eH(t){let e=t.steps??t.plan??t.todos??t.items;if(!Array.isArray(e))return{error:'update_plan: passe "steps" como uma LISTA de passos (string ou {title,status}).'};if(e.length===0)return{error:"update_plan: a lista de passos est\xE1 vazia."};let o=[];for(let i of e){let a=FE(i,!0);if(typeof a=="string")return{error:a};o.push(a)}let n=new Set,r=i=>{if(!n.has(i))return n.add(i),i;for(let a=2;;a++){let l=`${i} #${a}`;if(!n.has(l))return n.add(l),l}};for(let i=0;i<o.length;i++){let a=o[i],l=r(a.title),c=a.substeps?.map(d=>({...d,title:r(d.title)}));o[i]=c!==void 0?{...a,title:l,substeps:c}:{...a,title:l}}let s=ym(o).length;return s>DE?{error:`update_plan: no m\xE1ximo ${DE} passos (recebidos ${s}).`}:{steps:o}}function tH(t){let e=ym(t),o=e.filter(r=>r.step.status==="completed").length,n=e.map(r=>`${" ".repeat(r.depth)}${BE[r.step.status]} ${r.step.title}`).join(`
2
+ var Kj=Object.defineProperty;var p=(t,e,o)=>()=>{if(o)throw o[0];try{return t&&(e=t(t=0)),e}catch(n){throw o=[n],n}};var ut=(t,e)=>{for(var o in e)Kj(t,o,{get:e[o],enumerable:!0})};import{homedir as Yj}from"node:os";import{join as Vj}from"node:path";function $l(t=Yj()){return Vj(t,".aluy")}var gm=p(()=>{"use strict"});var Fl,NE=p(()=>{"use strict";Fl="1.0.0-rc.66"});function wr(t,e){return t.decide(e)}var Zs=p(()=>{"use strict"});var Un,Ar,Er=p(()=>{"use strict";Un="remember",Ar="recall"});var Hg,Xj,oa,qg=p(()=>{"use strict";Hg=class{id;horizon;label;parentId;children;dependencies;pinned;closed;createdAt;lastAccessedAt;accessCount;context;constructor(e,o,n,r,s){this.id=e,this.horizon=o,this.label=n,this.parentId=r,this.children=new Set,this.dependencies=new Set,this.pinned=!1,this.closed=!1,this.createdAt=s,this.lastAccessedAt=s,this.accessCount=0,this.context=[]}touch(e){this.lastAccessedAt=e,this.accessCount+=1}snapshot(){return{id:this.id,horizon:this.horizon,label:this.label,parentId:this.parentId,children:[...this.children],dependencies:[...this.dependencies],pinned:this.pinned,closed:this.closed,createdAt:this.createdAt,lastAccessedAt:this.lastAccessedAt,accessCount:this.accessCount,contextSize:this.context.length}}},Xj=200,oa=class{nodes=new Map;maxBoxes;now;constructor(e){this.maxBoxes=e?.maxBoxes??Xj,this.now=e?.clock??Date.now}static boxId(e,o){return`${e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)}-${o.toString(36)}`}openBox(e,o,n,r){let s=this.nodes.get(e);if(s)return s.touch(this.now()),{box:s.snapshot(),created:!1};if(this.nodes.size>=this.maxBoxes&&(this.evictOne(),this.nodes.size>=this.maxBoxes))return null;let i=this.now(),a=new Hg(e,o,n,r??null,i);if(r){let l=this.nodes.get(r);l&&l.children.add(e)}return this.nodes.set(e,a),{box:a.snapshot(),created:!0}}closeBox(e){let o=this.nodes.get(e);return o?(o.closed=!0,o.touch(this.now()),o.snapshot()):null}isClosed(e){let o=this.nodes.get(e);return o?o.closed:!1}reopenBox(e){let o=this.nodes.get(e);return o?(o.closed=!1,o.touch(this.now()),o.snapshot()):null}setHorizon(e,o){let n=this.nodes.get(e);return n?(n.horizon=o,n.touch(this.now()),n.snapshot()):null}setParent(e,o){let n=this.nodes.get(e);return n?n.parentId===o?n.snapshot():o!==null&&this.wouldCreateCycle(e,o)?null:(n.parentId&&this.nodes.get(n.parentId)?.children.delete(e),n.parentId=o,o&&this.nodes.get(o)?.children.add(e),n.touch(this.now()),n.snapshot()):null}wouldCreateCycle(e,o){let n=new Set,r=o;for(;r!==null;){if(r===e||n.has(r))return!0;n.add(r),r=this.nodes.get(r)?.parentId??null}return!1}getBox(e){let o=this.nodes.get(e);return o?(o.touch(this.now()),o.snapshot()):null}listBoxes(e="lastAccessedAt"){let o=[...this.nodes.values()].map(n=>n.snapshot());switch(e){case"createdAt":return o.sort((n,r)=>n.createdAt-r.createdAt);case"accessCount":return o.sort((n,r)=>r.accessCount-n.accessCount);default:return o.sort((n,r)=>r.lastAccessedAt-n.lastAccessedAt)}}get size(){return this.nodes.size}addContext(e,o){let n=this.nodes.get(e);return n?(n.context.push({ts:this.now(),text:o}),n.touch(this.now()),n.snapshot()):null}getContext(e){let o=this.nodes.get(e);return o?(o.touch(this.now()),[...o.context]):[]}getContextChain(e){let o=[],n=new Set,r=e;for(;r&&!n.has(r);){n.add(r);let s=this.nodes.get(r);if(!s)break;s.touch(this.now()),o.push({boxId:s.id,entries:[...s.context]}),r=s.parentId}return o}addDependency(e,o){let n=this.nodes.get(e);return!n||!this.nodes.has(o)||n.id===o?!1:(n.dependencies.add(o),n.touch(this.now()),!0)}getDependencies(e){let o=this.nodes.get(e);return o?[...o.dependencies]:[]}pinBox(e){let o=this.nodes.get(e);return o?(o.pinned=!0,o.touch(this.now()),o.snapshot()):null}unpinBox(e){let o=this.nodes.get(e);return o?(o.pinned=!1,o.touch(this.now()),o.snapshot()):null}evictOne(){let e=[];for(let n of this.nodes.values())n.horizon==="longo"||n.pinned||e.push(n);if(e.length===0)return null;e.sort((n,r)=>{let s=n.horizon==="curto"?0:1,i=r.horizon==="curto"?0:1;if(s!==i)return s-i;let a=n.closed?0:1,l=r.closed?0:1;return a!==l?a-l:n.lastAccessedAt!==r.lastAccessedAt?n.lastAccessedAt-r.lastAccessedAt:n.accessCount-r.accessCount});let o=e[0];return this.removeNode(o)}forceEvict(e){let o=this.nodes.get(e);return!o||o.horizon==="longo"||o.pinned?null:this.removeNode(o)}removeBox(e){let o=this.nodes.get(e);return o?this.removeNode(o):null}removeNode(e){if(e.parentId){let o=this.nodes.get(e.parentId);o&&o.children.delete(e.id)}return this.nodes.delete(e.id),e.snapshot()}}});function ym(t){let e=[];for(let o of t){e.push({step:o,depth:0});for(let n of o.substeps??[])e.push({step:n,depth:1})}return e}function FE(t,e){let o,n="pending",r;if(typeof t=="string")o=t;else if(t!==null&&typeof t=="object"){let i=t,a=i.title??i.step??i.text??i.name??i.content;if(typeof a=="string"&&(o=a),typeof i.status=="string"&&Jj.has(i.status)&&(n=i.status),e){let l=i.substeps??i.subtasks??i.subpassos??i.children;if(Array.isArray(l)&&l.length>0){let c=[];for(let d of l){let m=FE(d,!1);if(typeof m=="string")return m;c.push(m)}r=c}}}if(o===void 0||o.trim()==="")return Zj;let s=o.trim().slice(0,Qj);return r?{title:s,status:n,substeps:r}:{title:s,status:n}}function eH(t){let e=t.steps??t.plan??t.todos??t.items;if(!Array.isArray(e))return{error:'update_plan: passe "steps" como uma LISTA de passos (string ou {title,status}).'};if(e.length===0)return{error:"update_plan: a lista de passos est\xE1 vazia."};let o=[];for(let i of e){let a=FE(i,!0);if(typeof a=="string")return{error:a};o.push(a)}let n=new Set,r=i=>{if(!n.has(i))return n.add(i),i;for(let a=2;;a++){let l=`${i} #${a}`;if(!n.has(l))return n.add(l),l}};for(let i=0;i<o.length;i++){let a=o[i],l=r(a.title),c=a.substeps?.map(d=>({...d,title:r(d.title)}));o[i]=c!==void 0?{...a,title:l,substeps:c}:{...a,title:l}}let s=ym(o).length;return s>DE?{error:`update_plan: no m\xE1ximo ${DE} passos (recebidos ${s}).`}:{steps:o}}function tH(t){let e=ym(t),o=e.filter(r=>r.step.status==="completed").length,n=e.map(r=>`${" ".repeat(r.depth)}${BE[r.step.status]} ${r.step.title}`).join(`
3
3
  `);return`plano (${o}/${e.length}):
4
4
  ${n}`}function nH(t,e){return e<0?"m\xE9dio":t===e?"curto":t>e?"longo":"m\xE9dio"}function rH(t,e){let o=new Map;for(let i of e.listBoxes())o.set(i.label,i.id);let n=t.findIndex(i=>i.status==="in_progress"||(i.substeps??[]).some(a=>a.status==="in_progress")),r=(i,a,l)=>{let c=i.status==="in_progress"?"curto":l,d=o.get(i.title),m=d??oa.boxId(i.title,0);return d?(i.status!=="completed"&&e.isClosed(d)&&e.reopenBox(d),e.setHorizon(d,c),e.setParent(d,a)):e.openBox(m,c,i.title,a),i.status==="completed"&&!e.isClosed(m)&&e.closeBox(m),o.set(i.title,m),m};t.forEach((i,a)=>{let l=nH(a,n),c=r(i,null,l);for(let d of i.substeps??[])r(d,c,l)});let s=new Set;for(let i of t){s.add(i.title);for(let a of i.substeps??[])s.add(a.title)}for(let i of e.listBoxes())s.has(i.label)||e.removeBox(i.id)}function sH(t,e){if(!e)return tH(t);let o=new Map;for(let c of e.listBoxes())o.set(c.label,c);let n=new Map;for(let c of e.listBoxes())n.set(c.id,c);let r=new Map,s=(c,d=new Set)=>{let m=r.get(c);if(m!==void 0)return m;let u=n.get(c);if(!u||!u.parentId||d.has(c))return r.set(c,0),0;let h=s(u.parentId,new Set(d).add(c))+1;return r.set(c,h),h},i=ym(t),l=[`plano (${i.filter(c=>c.step.status==="completed").length}/${i.length}):`];for(let{step:c,depth:d}of i){let m=o.get(c.title),u=m?oH[m.horizon]:"",h=m?s(m.id):d,g=" ".repeat(h),b=BE[c.status];l.push(`${g}${u} ${b} ${c.title}`)}return l.join(`
5
5
  `)}var Bl,Jj,DE,Qj,Zj,BE,oH,$E,iH,UE,bm=p(()=>{"use strict";qg();Bl="update_plan";Jj=new Set(["pending","in_progress","completed"]),DE=30,Qj=120,Zj="update_plan: cada passo precisa de um t\xEDtulo (texto) n\xE3o-vazio.";BE={pending:"\u2610",in_progress:"\u25B6",completed:"\u2611"};oH={longo:"[\u{1F4D0}]",m\u00E9dio:"[\u{1F4CB}]",curto:"[\u{1F4CC}]"};$E=Object.freeze({type:"string",enum:["pending","in_progress","completed"],description:"pending (a fazer) \xB7 in_progress (em curso) \xB7 completed (feito)."}),iH=Object.freeze({type:"object",properties:{steps:{type:"array",description:"A lista COMPLETA de passos do plano (re-emita TODOS a cada atualiza\xE7\xE3o \u2014 substitui o anterior).",items:{type:"object",properties:{title:{type:"string",description:"O passo, curto e no imperativo."},status:$E,substeps:{type:"array",description:"OPCIONAL: sub-passos que detalham este passo (1 n\xEDvel). Aparecem indentados sob o passo e seguem o foco dele. Use quando um passo tem a\xE7\xF5es menores distintas.",items:{type:"object",properties:{title:{type:"string",description:"O sub-passo, curto e no imperativo."},status:$E},required:["title"],additionalProperties:!1}}},required:["title"],additionalProperties:!1}}},required:["steps"],additionalProperties:!1}),UE={name:Bl,effect:"read",description:"Declara/atualiza um PLANO vis\xEDvel (checklist de passos). Use ao iniciar uma tarefa com V\xC1RIOS passos e a cada progresso: re-emita a lista TODA marcando o status de cada passo (pending/in_progress/completed). Mantenha 1 passo in_progress por vez. N\xE3o tem efeito no sistema \u2014 \xE9 s\xF3 o seu plano, para voc\xEA e para o usu\xE1rio acompanharem.",parameters:iH,async run(t,e){let o=eH(t);return"error"in o?{ok:!1,observation:o.error}:(e.graph&&rH(o.steps,e.graph),e.plan&&e.plan.set(ym(o.steps).map(r=>({title:r.step.title,status:r.step.status}))),{ok:!0,observation:sH(o.steps,e.graph)})}}});function jE(t){let e=t.question??t.prompt??t.text??t.message;if(typeof e!="string"||e.trim()==="")return{error:'perguntar: passe "question" (a pergunta em texto). Para escolha, passe tamb\xE9m "options".'};let o=e.trim().slice(0,2e3),n=t.header??t.title,r=typeof n=="string"&&n.trim()!==""?n.trim().slice(0,200):void 0,s=t.options??t.choices,i=Array.isArray(s)?lH(s):void 0;if(typeof i=="string")return{error:i};let a,l=t.kind??t.type;if(typeof l=="string"&&aH.has(l))a=l;else{if(typeof l=="string"&&l.trim()!=="")return{error:`perguntar: "kind" inv\xE1lido "${l}". Use "single", "multi" ou "text".`};a=i!==void 0&&i.length>0?"single":"text"}if((a==="single"||a==="multi")&&(i===void 0||i.length===0))return{error:`perguntar: kind "${a}" requer "options" (uma lista de ao menos 1 op\xE7\xE3o).`};let c=t.allowOther!==!1;return{spec:{kind:a,question:o,...r!==void 0?{header:r}:{},...a!=="text"&&i!==void 0?{options:i}:{},...a!=="text"?{allowOther:c}:{}}}}function lH(t){if(t.length===0)return'perguntar: a lista de "options" est\xE1 vazia.';if(t.length>12)return`perguntar: no m\xE1ximo 12 op\xE7\xF5es (recebidas ${t.length}).`;let e=[];for(let o of t){let n,r;if(typeof o=="string")n=o;else if(o!==null&&typeof o=="object"){let s=o,i=s.label??s.text??s.value??s.name??s.title;typeof i=="string"&&(n=i),typeof s.description=="string"&&s.description.trim()!==""&&(r=s.description.trim().slice(0,300))}if(n===void 0||n.trim()==="")return'perguntar: cada op\xE7\xE3o precisa de um "label" (texto) n\xE3o-vazio.';e.push({label:n.trim().slice(0,200),...r!==void 0?{description:r}:{}})}return e}function cH(t){switch(t.kind){case"choice":return t.label;case"choices":return t.labels.length===0?"(nenhuma)":t.labels.join(", ");case"text":{let e=t.text.split(`
@@ -154,7 +154,7 @@ ${t.trim()}`}}function jO(t,e,o=nd){let{older:n,recent:r}=Uf(t,o);if(n.length===
154
154
  `);let i=bo(process.execPath,[n,"-p",o,"--yolo","--no-self-check"],{stdio:"inherit",timeout:9e5,env:{...process.env,ALUY_OVERWRITE_RENDER:"0",ALUY_SYNC_OUTPUT:"0",ALUY_NO_WEAK_YOLO_WARN:"1",ALUY_PRINT_VERBOSE:"1"}});if(t==="mem0")try{let l=ve(on(),Pr),c=ve(l,Tn);Je(l)&&gp(bp(),c)}catch{}t==="ollama"&&(await bK(),vK()),process.stderr.write(`
155
155
  verificando "${t}"\u2026 (alguns segundos; a pr\xF3xima etapa vem em seguida)
156
156
  `);let a=await fM(t,process.platform,!0);for(let l=0;l<hK&&!a;l++)await yK(gK),a=await fM(t,process.platform,!0);return{target:t,hashOk:a,installed:a,message:a?`complemento "${t}" instalado e verificado.`:`o complemento "${t}" ainda n\xE3o respondeu como esperado. O Aluy CLI funciona sem ele; voc\xEA pode tentar de novo depois com \`aluy bootstrap\`.`}}function yK(t){return new Promise(e=>setTimeout(e,t))}async function bK(){for(let t of[En,vp()])try{await(await fetch(`http://${en}:${Yn}/api/pull`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:t,stream:!1})})).text()}catch{}}function vK(){if(process.platform!=="win32")try{let t=bo("sh",["-lc","command -v ollama"],{encoding:"utf8",timeout:1e4});if(t.status===0&&(t.stdout??"").trim()!=="")return;let e=yp(),n=["/usr/local/bin/ollama","/usr/bin/ollama","/opt/homebrew/bin/ollama",ve(e,".ollama","bin","ollama"),ve(on(),ys,"bin","ollama")].find(i=>Je(i));if(n===void 0)return;let r=ve(e,".local","bin");ux(r,{recursive:!0});let s=ve(r,"ollama");try{if(cM(s)===cM(n))return;Jz(s)}catch{}try{Xz(n,s)}catch{}}catch{}}function kK(){try{return bo("python3",["-m","venv","--help"],{timeout:1e4}).status===0}catch{return!1}}function xK(){try{return bo("python3",["-m","pip","--version"],{timeout:1e4}).status===0}catch{return!1}}function SK(t){let e=[],o=[];if(t.has("ollama")&&(hM()||(e.push("zstd (extrair o Ollama)"),o.push("zstd")),gM()||(e.push("tar (extrair o Ollama)"),o.push("tar"))),t.has("mem0")||t.has("headroom")){let r=fx();r.ok?(kK()||(e.push("m\xF3dulo venv do Python (mem0/headroom criam um virtualenv)"),o.push("python3-venv")),xK()||(e.push("pip do Python (mem0/headroom instalam pacotes)"),o.push("python3-pip"))):(e.push(`python3 >= ${id} para mem0/headroom (encontrado: ${r.version||"nenhum"})`),o.push("python3","python3-venv","python3-pip"))}if(e.length===0)return[];let n=[...new Set(o)];return["Faltam pr\xE9-requisitos para o modo turbo (o que conseguir, instala; o resto fica de fora):",...e.map(r=>` \u2022 ${r}`),`Instale e rode \`aluy bootstrap\` de novo: sudo apt install -y ${n.join(" ")}`,""]}async function bM(t,e,o){let n=t??"turbo",r=Ir(e??{}),s=o?.useAgent!==!1,i=new dx({...o?.platform?{platform:o.platform}:{},...s?{agentInstaller:pK}:{}});if(!s)for(let a of SK(r))process.stderr.write(a+`
157
- `);return i.provisionAll(n,r)}var pM,$a,tK,Tn,uM,dx,mM,mK,hK,gK,px=p(()=>{"use strict";P();pM=".aluy",$a=448,tK=384;Tn="aluy-mem0-server.py";uM="application/vnd.ollama.image.model";dx=class{platform;agentInstaller;constructor(e={}){this.platform=e.platform??process.platform,this.agentInstaller=e.agentInstaller}hasPinnedArtifact(){return this.platform==="linux"}async isProvisioned(e){switch(e){case"ollama":{let o=ve(on(),ys,"bin","ollama");return Je(o)}case"mem0":{let o=ve(on(),Pr,"bin","python3");return Je(o)&&Sd(o)}case"headroom":{let o=ve(on(),bs,"bin","headroom");return Je(o)}default:return!1}}async provision(e,o){let n=Zz().uid;if(Ak(n))return{target:e,hashOk:!1,installed:!1,message:"RECUSA ROOT (uid=0): provisionamento de sidecars \xE9 user-space. Execute como usu\xE1rio normal."};if(this.agentInstaller)return this.agentInstaller(e,o);if(!this.hasPinnedArtifact())return{target:e,hashOk:!1,installed:!1,message:`SO '${this.platform}' sem artefato pinado p/ provisionamento direto. Rode \`aluy bootstrap\` (o aluy instala via o pr\xF3prio agente, \u26A0 --yolo) ou instale manualmente.`};switch(e){case"ollama":return iK();case"mem0":return dK();case"headroom":return uK();default:return{target:e,hashOk:!1,installed:!1,message:`Alvo desconhecido: ${String(e)}`}}}async provisionAll(e,o){if(!ld(e))return{profile:e,targets:[],anySuccess:!1,allFailed:!1};let n=[],r=[...o];for(let a=0;a<r.length;a++){let l=r[a],c={index:a+1,total:r.length,plan:r};try{n.push(await this.provision(l,c))}catch(d){let m=d instanceof Error?d.message:String(d);n.push({target:l,hashOk:!1,installed:!1,message:`falha inesperada ao provisionar \u2014 seguindo p/ os pr\xF3ximos (${m}).`})}}let s=n.some(a=>a.installed),i=n.length>0&&n.every(a=>!a.installed);return{profile:e,targets:n,anySuccess:s,allFailed:i}}},mM="na faixa 3.10\u20133.12 (N\xC3O use 3.13+/3.14 \u2014 as depend\xEAncias nativas n\xE3o t\xEAm wheels e o pip falha ao compilar; no Windows prefira `py -3.12` ou `py -3.11`). Se N\xC3O houver um Python 3.10\u20133.12 instalado, INSTALE primeiro (no Windows: `winget install -e --id Python.Python.3.12 --accept-source-agreements --accept-package-agreements`; no Linux/macOS use o gerenciador do sistema). Se j\xE1 existir um venv nesse caminho numa vers\xE3o incompat\xEDvel (ex.: 3.14), APAGUE e recrie com a vers\xE3o certa",mK="IMPORTANTE \u2014 o usu\xE1rio quer ACOMPANHAR: antes de cada passo, diga em 1 linha o que vai fazer; rode os comandos de instala\xE7\xE3o de forma VIS\xCDVEL (N\xC3O silencie pip/apt/curl com -q; mostre a sa\xEDda/progresso). Sem modo silencioso. ";hK=24,gK=5e3});var Xn,wd=p(()=>{"use strict";Xn="1.0.0-rc.65"});var wM={};ut(wM,{HELP_TEXT:()=>kM,parseArgs:()=>hx,suggestFlag:()=>TK,versionText:()=>xM});function it(t,e,o={}){let n=`--${e}=`;for(let r=0;r<t.length;r++){let s=t[r];if(s===`--${e}`){let i=t[r+1];return i===void 0||(o.allowDashValue?i.startsWith("--"):i.startsWith("-"))?void 0:i}if(s!==void 0&&s.startsWith(n))return s.slice(n.length)}}function wK(t,e){let o=`-${e}=`;for(let n=0;n<t.length;n++){let r=t[n];if(r===`-${e}`){let s=t[n+1];return s!==void 0&&!s.startsWith("-")?s:void 0}if(r!==void 0&&r.startsWith(o))return r.slice(o.length)}}function xM(){return`aluy ${Xn} (@hiperplano/aluy-cli-core ${Fl})`}function EK(t,e){let o=t.length,n=e.length,r=Array.from({length:n+1},(s,i)=>i);for(let s=1;s<=o;s++){let i=[s];for(let a=1;a<=n;a++){let l=t[s-1]===e[a-1]?0:1;i[a]=Math.min(r[a]+1,i[a-1]+1,r[a-1]+l)}r=i}return r[n]}function TK(t){let e,o=3;for(let n of SM){let r=EK(t,n);r<o&&(o=r,e=n)}return e}function CK(t,e){let o=[];for(let n=0;n<t.length;n++){let r=t[n];if(r==="--")break;if(!r.startsWith("--")||r.length===2||e.has(n))continue;let s=r.slice(2).split("=",1)[0];s===""||SM.has(s)||o.push(`--${s}`)}return o}function hx(t){let e=t[0];if(e==="login"&&!t.includes("-h")&&!t.includes("--help")){let G=t.slice(1),he=it(G,"token"),vt=it(G,"org"),eo=G.includes("--device"),Xo=it(G,"provider"),to=G.includes("--oauth");return{kind:"login",forceDeviceFlow:eo,...he!==void 0?{token:he}:{},...vt!==void 0?{org:vt}:{},...Xo!==void 0?{provider:Xo}:{},...to?{oauth:!0}:{}}}if(e==="logout"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"logout"};if(e==="whoami"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"whoami"};if(e==="doctor"&&!t.includes("-h")&&!t.includes("--help")){let G=t.includes("--deep")||t.includes("--test"),he=t.includes("--json");return{kind:"doctor",deep:G,json:he}}if(e==="config"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"config",json:t.includes("--json")};if(e==="agents"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"agents"};if(e==="bootstrap"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"bootstrap",agent:!t.includes("--no-agent")};if(e==="uninstall"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"uninstall",agent:t.includes("--agent")};if(e==="onboard"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"onboard"};if(e==="skills"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"skills"};if(e==="workflows"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"workflows"};if((e==="models"||e==="providers")&&!t.includes("-h")&&!t.includes("--help")){let G=t.includes("--json"),he=t.findIndex(eo=>eo==="--backend"||eo.startsWith("--backend=")),vt="both";if(he!==-1){let Xo=(t[he].includes("=")?t[he].slice(10):t[he+1]??"").trim().toLowerCase();Xo==="local"?vt="local":Xo==="broker"&&(vt="broker")}return{kind:"models",scope:vt,json:G,which:e==="providers"?"providers":"models"}}if(e==="telegram"&&!t.includes("-h")&&!t.includes("--help")){let G=t[1];if(G===void 0||!["login","logout","allow","deny","status"].includes(G))return{kind:"usage-error",message:"uso: aluy telegram <login|logout|allow|deny|status>",exitCode:2};let vt=t.slice(2);if(G==="login"){let eo=it(vt,"token");return{kind:"telegram",sub:"login",...eo!==void 0?{token:eo}:{}}}if(G==="allow"||G==="deny"){let eo=vt.find(to=>!to.startsWith("-")),Xo=eo!==void 0&&/^-?\d+$/.test(eo)?Number(eo):void 0;return Xo===void 0?{kind:"usage-error",message:`uso: aluy telegram ${G} <chat-id> (um inteiro)`,exitCode:2}:{kind:"telegram",sub:G,chatId:Xo}}return{kind:"telegram",sub:G}}if(e==="mcp"&&t[1]==="search"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"mcp-search",query:t.slice(2).filter(he=>!he.startsWith("-")).join(" ").trim()};if(e==="mcp")return{kind:"mcp",argv:t.slice(1)};if(e==="cron")return{kind:"cron",argv:t.slice(1)};if(t.includes("-v")||t.includes("--version"))return{kind:"version",text:xM()};if(t.includes("-h")||t.includes("--help"))return{kind:"help",text:kM};let o=t.includes("--plan"),n=t.includes("--unsafe"),r=t.includes("--yolo")||n,s=o?"plan":r?"unsafe":"normal",i=t.includes("--dense"),a=t.includes("--ascii"),l=t.includes("--telegram"),c=t.includes("--split")||t.includes("--view")?!0:void 0,d=t.includes("--fullscreen")||t.includes("--cockpit")?!0:void 0,m=t.includes("--no-budget")?!1:t.includes("--budget")?!0:void 0,u=it(t,"tier"),h=it(t,"lang"),g=it(t,"max-tokens"),b=it(t,"max-iterations"),y=it(t,"max-output-tokens"),S=!(t.includes("--no-subagents")||t.includes("--no-subagent")),A=t.includes("--no-self-check")?"0":t.includes("--self-check")?"1":void 0,T=t.includes("--no-autocompact")?"off":it(t,"autocompact-at"),M=t.includes("--quiet")?!0:void 0,j=t.includes("--cycle")?!0:void 0,W=it(t,"cycles"),V=it(t,"cycle-for"),z=it(t,"backend"),D=it(t,"local-provider"),Q=it(t,"local-model"),oe=it(t,"local-auth"),J=it(t,"local-base-url"),L=it(t,"model"),H=it(t,"provider");if((t.includes("--provider")||t.some(G=>G.startsWith("--provider=")))&&(L===void 0||L.trim()===""))return{kind:"usage-error",message:"aluy: --provider exige --model (ex.: --provider <provider> --model <slug>)",exitCode:2};if((L===void 0||L.trim()==="")&&u!==void 0&&u.trim().toLowerCase()==="custom")return{kind:"usage-error",message:"aluy: --tier custom exige --model <slug> (ex.: --model deepseek-v4-pro). A via Custom precisa do slug do modelo; sem ele use um tier can\xF4nico (aluy-flux, aluy-granito, \u2026).",exitCode:2};let Y=it(t,"effort"),pe=t.includes("--effort")||t.some(G=>G.startsWith("--effort=")),Z;if(Y!==void 0){if(Y.trim()==="")return{kind:"usage-error",message:"aluy: --effort requer um valor (ex.: --effort low)",exitCode:2};if(Y.length>32)return{kind:"usage-error",message:"aluy: --effort aceita no m\xE1ximo 32 caracteres",exitCode:2};Z=Y}else if(pe)return{kind:"usage-error",message:"aluy: --effort requer um valor (ex.: --effort low)",exitCode:2};let ae=t.includes("-p")||t.includes("--print")||t.includes("--exec")||t.some(G=>G.startsWith("-p=")||G.startsWith("--print=")||G.startsWith("--exec=")),N=ae?it(t,"print",{allowDashValue:!0})??it(t,"exec",{allowDashValue:!0})??wK(t,"p")??void 0:void 0,be=ae?it(t,"output-format"):void 0,ee=t.includes("--new"),ce=t.includes("--continue"),Ae=t.indexOf("--resume"),Ct=t.find(G=>G.startsWith("--resume=")),Re=Ae>=0||Ct!==void 0,ot;if(Ct!==void 0)ot=Ct.slice(9);else if(Ae>=0){let G=t[Ae+1];G!==void 0&&!G.startsWith("-")&&(ot=G)}let yt=u!==void 0?t.indexOf("--tier")+1:-1,ht=h!==void 0&&!t.some(G=>G.startsWith("--lang="))?t.indexOf("--lang")+1:-1,nt=ot!==void 0&&Ct===void 0?Ae+1:-1,_t=g!==void 0&&!t.some(G=>G.startsWith("--max-tokens="))?t.indexOf("--max-tokens")+1:-1,K=b!==void 0&&!t.some(G=>G.startsWith("--max-iterations="))?t.indexOf("--max-iterations")+1:-1,xe=W!==void 0&&!t.some(G=>G.startsWith("--cycles="))?t.indexOf("--cycles")+1:-1,Pe=V!==void 0&&!t.some(G=>G.startsWith("--cycle-for="))?t.indexOf("--cycle-for")+1:-1,q=y!==void 0&&!t.some(G=>G.startsWith("--max-output-tokens="))?t.indexOf("--max-output-tokens")+1:-1,Ft=T!==void 0&&!t.includes("--no-autocompact")&&!t.some(G=>G.startsWith("--autocompact-at="))?t.indexOf("--autocompact-at")+1:-1,Fo=z!==void 0&&!t.some(G=>G.startsWith("--backend="))?t.indexOf("--backend")+1:-1,k=(G,he)=>he!==void 0&&!t.some(vt=>vt.startsWith(`--${G}=`))?t.indexOf(`--${G}`)+1:-1,ho=k("local-provider",D),Bt=k("local-model",Q),bt=k("local-auth",oe),Zr=k("local-base-url",J),es=L!==void 0&&!t.some(G=>G.startsWith("--model="))?t.indexOf("--model")+1:-1,yr=H!==void 0&&!t.some(G=>G.startsWith("--provider="))?t.indexOf("--provider")+1:-1,br=Z!==void 0&&!t.some(G=>G.startsWith("--effort="))?t.indexOf("--effort")+1:-1,Ut=be!==void 0&&!t.some(G=>G.startsWith("--output-format="))?t.indexOf("--output-format")+1:-1,jt=N!==void 0&&!t.some(G=>G.startsWith("-p=")||G.startsWith("--print=")||G.startsWith("--exec="))?Math.max(t.indexOf("-p"),t.indexOf("--print"),t.indexOf("--exec"))+1:-1,gn=t.find((G,he)=>!G.startsWith("-")&&he!==yt&&he!==ht&&he!==Fo&&he!==ho&&he!==Bt&&he!==bt&&he!==Zr&&he!==es&&he!==yr&&he!==br&&he!==Ut&&he!==jt&&he!==nt&&he!==_t&&he!==K&&he!==q&&he!==Ft&&he!==xe&&he!==Pe),vr=ce?{kind:"continue"}:Re?{kind:"resume",...ot!==void 0?{id:ot}:{}}:void 0,ts=new Set([yt,ht,Fo,ho,Bt,bt,Zr,es,yr,br,Ut,jt,nt,_t,K,q,Ft,xe,Pe].filter(G=>G>=0));for(let G of AK){let he=t.indexOf(G);he>=0&&!t[he].includes("=")&&ts.add(he+1)}let yn=CK(t,ts);return{kind:"launch",mode:s,unsafe:s==="unsafe",unsafeAliasUsed:n,...yn.length>0?{unknownFlags:yn}:{},dense:i,fresh:ee,subAgents:S,safeGlyphs:a,telegram:l,print:ae,...c!==void 0?{split:c}:{},...d!==void 0?{fullscreen:d}:{},...m!==void 0?{budget:m}:{},...gn!==void 0?{goal:gn}:{},...u!==void 0?{tier:u}:{},...z!==void 0?{backend:z}:{},...D!==void 0?{localProvider:D}:{},...Q!==void 0?{localModel:Q}:{},...oe!==void 0?{localAuth:oe}:{},...J!==void 0?{localBaseUrl:J}:{},...L!==void 0?{model:L}:{},...H!==void 0?{provider:H}:{},...Z!==void 0?{effort:Z}:{},...N!==void 0?{printArg:N}:{},...be!==void 0?{outputFormat:be}:{},...h!==void 0?{lang:h}:{},...vr!==void 0?{resume:vr}:{},...g!==void 0?{maxTokens:g}:{},...b!==void 0?{maxIterations:b}:{},...y!==void 0?{maxOutputTokens:y}:{},...A!==void 0?{selfCheck:A}:{},...T!==void 0?{autoCompactAt:T}:{},...M!==void 0?{quiet:M}:{},...j!==void 0?{cycle:j}:{},...W!==void 0?{cycles:W}:{},...V!==void 0?{cycleFor:V}:{}}}var kM,SM,AK,gx=p(()=>{"use strict";P();wd();kM=`aluy \u2014 agente de terminal que roda na sua m\xE1quina, com o seu provider de LLM
157
+ `);return i.provisionAll(n,r)}var pM,$a,tK,Tn,uM,dx,mM,mK,hK,gK,px=p(()=>{"use strict";P();pM=".aluy",$a=448,tK=384;Tn="aluy-mem0-server.py";uM="application/vnd.ollama.image.model";dx=class{platform;agentInstaller;constructor(e={}){this.platform=e.platform??process.platform,this.agentInstaller=e.agentInstaller}hasPinnedArtifact(){return this.platform==="linux"}async isProvisioned(e){switch(e){case"ollama":{let o=ve(on(),ys,"bin","ollama");return Je(o)}case"mem0":{let o=ve(on(),Pr,"bin","python3");return Je(o)&&Sd(o)}case"headroom":{let o=ve(on(),bs,"bin","headroom");return Je(o)}default:return!1}}async provision(e,o){let n=Zz().uid;if(Ak(n))return{target:e,hashOk:!1,installed:!1,message:"RECUSA ROOT (uid=0): provisionamento de sidecars \xE9 user-space. Execute como usu\xE1rio normal."};if(this.agentInstaller)return this.agentInstaller(e,o);if(!this.hasPinnedArtifact())return{target:e,hashOk:!1,installed:!1,message:`SO '${this.platform}' sem artefato pinado p/ provisionamento direto. Rode \`aluy bootstrap\` (o aluy instala via o pr\xF3prio agente, \u26A0 --yolo) ou instale manualmente.`};switch(e){case"ollama":return iK();case"mem0":return dK();case"headroom":return uK();default:return{target:e,hashOk:!1,installed:!1,message:`Alvo desconhecido: ${String(e)}`}}}async provisionAll(e,o){if(!ld(e))return{profile:e,targets:[],anySuccess:!1,allFailed:!1};let n=[],r=[...o];for(let a=0;a<r.length;a++){let l=r[a],c={index:a+1,total:r.length,plan:r};try{n.push(await this.provision(l,c))}catch(d){let m=d instanceof Error?d.message:String(d);n.push({target:l,hashOk:!1,installed:!1,message:`falha inesperada ao provisionar \u2014 seguindo p/ os pr\xF3ximos (${m}).`})}}let s=n.some(a=>a.installed),i=n.length>0&&n.every(a=>!a.installed);return{profile:e,targets:n,anySuccess:s,allFailed:i}}},mM="na faixa 3.10\u20133.12 (N\xC3O use 3.13+/3.14 \u2014 as depend\xEAncias nativas n\xE3o t\xEAm wheels e o pip falha ao compilar; no Windows prefira `py -3.12` ou `py -3.11`). Se N\xC3O houver um Python 3.10\u20133.12 instalado, INSTALE primeiro (no Windows: `winget install -e --id Python.Python.3.12 --accept-source-agreements --accept-package-agreements`; no Linux/macOS use o gerenciador do sistema). Se j\xE1 existir um venv nesse caminho numa vers\xE3o incompat\xEDvel (ex.: 3.14), APAGUE e recrie com a vers\xE3o certa",mK="IMPORTANTE \u2014 o usu\xE1rio quer ACOMPANHAR: antes de cada passo, diga em 1 linha o que vai fazer; rode os comandos de instala\xE7\xE3o de forma VIS\xCDVEL (N\xC3O silencie pip/apt/curl com -q; mostre a sa\xEDda/progresso). Sem modo silencioso. ";hK=24,gK=5e3});var Xn,wd=p(()=>{"use strict";Xn="1.0.0-rc.66"});var wM={};ut(wM,{HELP_TEXT:()=>kM,parseArgs:()=>hx,suggestFlag:()=>TK,versionText:()=>xM});function it(t,e,o={}){let n=`--${e}=`;for(let r=0;r<t.length;r++){let s=t[r];if(s===`--${e}`){let i=t[r+1];return i===void 0||(o.allowDashValue?i.startsWith("--"):i.startsWith("-"))?void 0:i}if(s!==void 0&&s.startsWith(n))return s.slice(n.length)}}function wK(t,e){let o=`-${e}=`;for(let n=0;n<t.length;n++){let r=t[n];if(r===`-${e}`){let s=t[n+1];return s!==void 0&&!s.startsWith("-")?s:void 0}if(r!==void 0&&r.startsWith(o))return r.slice(o.length)}}function xM(){return`aluy ${Xn} (@hiperplano/aluy-cli-core ${Fl})`}function EK(t,e){let o=t.length,n=e.length,r=Array.from({length:n+1},(s,i)=>i);for(let s=1;s<=o;s++){let i=[s];for(let a=1;a<=n;a++){let l=t[s-1]===e[a-1]?0:1;i[a]=Math.min(r[a]+1,i[a-1]+1,r[a-1]+l)}r=i}return r[n]}function TK(t){let e,o=3;for(let n of SM){let r=EK(t,n);r<o&&(o=r,e=n)}return e}function CK(t,e){let o=[];for(let n=0;n<t.length;n++){let r=t[n];if(r==="--")break;if(!r.startsWith("--")||r.length===2||e.has(n))continue;let s=r.slice(2).split("=",1)[0];s===""||SM.has(s)||o.push(`--${s}`)}return o}function hx(t){let e=t[0];if(e==="login"&&!t.includes("-h")&&!t.includes("--help")){let G=t.slice(1),he=it(G,"token"),vt=it(G,"org"),eo=G.includes("--device"),Xo=it(G,"provider"),to=G.includes("--oauth");return{kind:"login",forceDeviceFlow:eo,...he!==void 0?{token:he}:{},...vt!==void 0?{org:vt}:{},...Xo!==void 0?{provider:Xo}:{},...to?{oauth:!0}:{}}}if(e==="logout"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"logout"};if(e==="whoami"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"whoami"};if(e==="doctor"&&!t.includes("-h")&&!t.includes("--help")){let G=t.includes("--deep")||t.includes("--test"),he=t.includes("--json");return{kind:"doctor",deep:G,json:he}}if(e==="config"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"config",json:t.includes("--json")};if(e==="agents"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"agents"};if(e==="bootstrap"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"bootstrap",agent:!t.includes("--no-agent")};if(e==="uninstall"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"uninstall",agent:t.includes("--agent")};if(e==="onboard"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"onboard"};if(e==="skills"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"skills"};if(e==="workflows"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"workflows"};if((e==="models"||e==="providers")&&!t.includes("-h")&&!t.includes("--help")){let G=t.includes("--json"),he=t.findIndex(eo=>eo==="--backend"||eo.startsWith("--backend=")),vt="both";if(he!==-1){let Xo=(t[he].includes("=")?t[he].slice(10):t[he+1]??"").trim().toLowerCase();Xo==="local"?vt="local":Xo==="broker"&&(vt="broker")}return{kind:"models",scope:vt,json:G,which:e==="providers"?"providers":"models"}}if(e==="telegram"&&!t.includes("-h")&&!t.includes("--help")){let G=t[1];if(G===void 0||!["login","logout","allow","deny","status"].includes(G))return{kind:"usage-error",message:"uso: aluy telegram <login|logout|allow|deny|status>",exitCode:2};let vt=t.slice(2);if(G==="login"){let eo=it(vt,"token");return{kind:"telegram",sub:"login",...eo!==void 0?{token:eo}:{}}}if(G==="allow"||G==="deny"){let eo=vt.find(to=>!to.startsWith("-")),Xo=eo!==void 0&&/^-?\d+$/.test(eo)?Number(eo):void 0;return Xo===void 0?{kind:"usage-error",message:`uso: aluy telegram ${G} <chat-id> (um inteiro)`,exitCode:2}:{kind:"telegram",sub:G,chatId:Xo}}return{kind:"telegram",sub:G}}if(e==="mcp"&&t[1]==="search"&&!t.includes("-h")&&!t.includes("--help"))return{kind:"mcp-search",query:t.slice(2).filter(he=>!he.startsWith("-")).join(" ").trim()};if(e==="mcp")return{kind:"mcp",argv:t.slice(1)};if(e==="cron")return{kind:"cron",argv:t.slice(1)};if(t.includes("-v")||t.includes("--version"))return{kind:"version",text:xM()};if(t.includes("-h")||t.includes("--help"))return{kind:"help",text:kM};let o=t.includes("--plan"),n=t.includes("--unsafe"),r=t.includes("--yolo")||n,s=o?"plan":r?"unsafe":"normal",i=t.includes("--dense"),a=t.includes("--ascii"),l=t.includes("--telegram"),c=t.includes("--split")||t.includes("--view")?!0:void 0,d=t.includes("--fullscreen")||t.includes("--cockpit")?!0:void 0,m=t.includes("--no-budget")?!1:t.includes("--budget")?!0:void 0,u=it(t,"tier"),h=it(t,"lang"),g=it(t,"max-tokens"),b=it(t,"max-iterations"),y=it(t,"max-output-tokens"),S=!(t.includes("--no-subagents")||t.includes("--no-subagent")),A=t.includes("--no-self-check")?"0":t.includes("--self-check")?"1":void 0,T=t.includes("--no-autocompact")?"off":it(t,"autocompact-at"),M=t.includes("--quiet")?!0:void 0,j=t.includes("--cycle")?!0:void 0,W=it(t,"cycles"),V=it(t,"cycle-for"),z=it(t,"backend"),D=it(t,"local-provider"),Q=it(t,"local-model"),oe=it(t,"local-auth"),J=it(t,"local-base-url"),L=it(t,"model"),H=it(t,"provider");if((t.includes("--provider")||t.some(G=>G.startsWith("--provider=")))&&(L===void 0||L.trim()===""))return{kind:"usage-error",message:"aluy: --provider exige --model (ex.: --provider <provider> --model <slug>)",exitCode:2};if((L===void 0||L.trim()==="")&&u!==void 0&&u.trim().toLowerCase()==="custom")return{kind:"usage-error",message:"aluy: --tier custom exige --model <slug> (ex.: --model deepseek-v4-pro). A via Custom precisa do slug do modelo; sem ele use um tier can\xF4nico (aluy-flux, aluy-granito, \u2026).",exitCode:2};let Y=it(t,"effort"),pe=t.includes("--effort")||t.some(G=>G.startsWith("--effort=")),Z;if(Y!==void 0){if(Y.trim()==="")return{kind:"usage-error",message:"aluy: --effort requer um valor (ex.: --effort low)",exitCode:2};if(Y.length>32)return{kind:"usage-error",message:"aluy: --effort aceita no m\xE1ximo 32 caracteres",exitCode:2};Z=Y}else if(pe)return{kind:"usage-error",message:"aluy: --effort requer um valor (ex.: --effort low)",exitCode:2};let ae=t.includes("-p")||t.includes("--print")||t.includes("--exec")||t.some(G=>G.startsWith("-p=")||G.startsWith("--print=")||G.startsWith("--exec=")),N=ae?it(t,"print",{allowDashValue:!0})??it(t,"exec",{allowDashValue:!0})??wK(t,"p")??void 0:void 0,be=ae?it(t,"output-format"):void 0,ee=t.includes("--new"),ce=t.includes("--continue"),Ae=t.indexOf("--resume"),Ct=t.find(G=>G.startsWith("--resume=")),Re=Ae>=0||Ct!==void 0,ot;if(Ct!==void 0)ot=Ct.slice(9);else if(Ae>=0){let G=t[Ae+1];G!==void 0&&!G.startsWith("-")&&(ot=G)}let yt=u!==void 0?t.indexOf("--tier")+1:-1,ht=h!==void 0&&!t.some(G=>G.startsWith("--lang="))?t.indexOf("--lang")+1:-1,nt=ot!==void 0&&Ct===void 0?Ae+1:-1,_t=g!==void 0&&!t.some(G=>G.startsWith("--max-tokens="))?t.indexOf("--max-tokens")+1:-1,K=b!==void 0&&!t.some(G=>G.startsWith("--max-iterations="))?t.indexOf("--max-iterations")+1:-1,xe=W!==void 0&&!t.some(G=>G.startsWith("--cycles="))?t.indexOf("--cycles")+1:-1,Pe=V!==void 0&&!t.some(G=>G.startsWith("--cycle-for="))?t.indexOf("--cycle-for")+1:-1,q=y!==void 0&&!t.some(G=>G.startsWith("--max-output-tokens="))?t.indexOf("--max-output-tokens")+1:-1,Ft=T!==void 0&&!t.includes("--no-autocompact")&&!t.some(G=>G.startsWith("--autocompact-at="))?t.indexOf("--autocompact-at")+1:-1,Fo=z!==void 0&&!t.some(G=>G.startsWith("--backend="))?t.indexOf("--backend")+1:-1,k=(G,he)=>he!==void 0&&!t.some(vt=>vt.startsWith(`--${G}=`))?t.indexOf(`--${G}`)+1:-1,ho=k("local-provider",D),Bt=k("local-model",Q),bt=k("local-auth",oe),Zr=k("local-base-url",J),es=L!==void 0&&!t.some(G=>G.startsWith("--model="))?t.indexOf("--model")+1:-1,yr=H!==void 0&&!t.some(G=>G.startsWith("--provider="))?t.indexOf("--provider")+1:-1,br=Z!==void 0&&!t.some(G=>G.startsWith("--effort="))?t.indexOf("--effort")+1:-1,Ut=be!==void 0&&!t.some(G=>G.startsWith("--output-format="))?t.indexOf("--output-format")+1:-1,jt=N!==void 0&&!t.some(G=>G.startsWith("-p=")||G.startsWith("--print=")||G.startsWith("--exec="))?Math.max(t.indexOf("-p"),t.indexOf("--print"),t.indexOf("--exec"))+1:-1,gn=t.find((G,he)=>!G.startsWith("-")&&he!==yt&&he!==ht&&he!==Fo&&he!==ho&&he!==Bt&&he!==bt&&he!==Zr&&he!==es&&he!==yr&&he!==br&&he!==Ut&&he!==jt&&he!==nt&&he!==_t&&he!==K&&he!==q&&he!==Ft&&he!==xe&&he!==Pe),vr=ce?{kind:"continue"}:Re?{kind:"resume",...ot!==void 0?{id:ot}:{}}:void 0,ts=new Set([yt,ht,Fo,ho,Bt,bt,Zr,es,yr,br,Ut,jt,nt,_t,K,q,Ft,xe,Pe].filter(G=>G>=0));for(let G of AK){let he=t.indexOf(G);he>=0&&!t[he].includes("=")&&ts.add(he+1)}let yn=CK(t,ts);return{kind:"launch",mode:s,unsafe:s==="unsafe",unsafeAliasUsed:n,...yn.length>0?{unknownFlags:yn}:{},dense:i,fresh:ee,subAgents:S,safeGlyphs:a,telegram:l,print:ae,...c!==void 0?{split:c}:{},...d!==void 0?{fullscreen:d}:{},...m!==void 0?{budget:m}:{},...gn!==void 0?{goal:gn}:{},...u!==void 0?{tier:u}:{},...z!==void 0?{backend:z}:{},...D!==void 0?{localProvider:D}:{},...Q!==void 0?{localModel:Q}:{},...oe!==void 0?{localAuth:oe}:{},...J!==void 0?{localBaseUrl:J}:{},...L!==void 0?{model:L}:{},...H!==void 0?{provider:H}:{},...Z!==void 0?{effort:Z}:{},...N!==void 0?{printArg:N}:{},...be!==void 0?{outputFormat:be}:{},...h!==void 0?{lang:h}:{},...vr!==void 0?{resume:vr}:{},...g!==void 0?{maxTokens:g}:{},...b!==void 0?{maxIterations:b}:{},...y!==void 0?{maxOutputTokens:y}:{},...A!==void 0?{selfCheck:A}:{},...T!==void 0?{autoCompactAt:T}:{},...M!==void 0?{quiet:M}:{},...j!==void 0?{cycle:j}:{},...W!==void 0?{cycles:W}:{},...V!==void 0?{cycleFor:V}:{}}}var kM,SM,AK,gx=p(()=>{"use strict";P();wd();kM=`aluy \u2014 agente de terminal que roda na sua m\xE1quina, com o seu provider de LLM
158
158
 
159
159
  Uso:
160
160
  aluy ["objetivo"] [--plan | --yolo] [--dense] [--tier <tier>] [--lang <pt-BR|en>]
@@ -456,7 +456,7 @@ Notas:
456
456
  `)}ensureDir(e,o){if(e==="global"){let n=sL(o),r=sL(n);iL(r)||Cx(r,{recursive:!0});for(let s of[n,o])try{Cx(s,{mode:aL})}catch(i){if(i.code!=="EEXIST")throw i}}else Cx(o,{mode:aL,recursive:!0})}}});import{accessSync as BY,constants as UY,statSync as jY}from"node:fs";import{delimiter as HY,isAbsolute as pL,join as qY}from"node:path";import{Client as WY}from"@modelcontextprotocol/sdk/client/index.js";import{StdioClientTransport as GY}from"@modelcontextprotocol/sdk/client/stdio.js";function zY(t,e,o=process.env){let n=new Set,r=YY(t,o);r&&!dL(r)&&n.add(r);for(let s of e)pL(s)&&hL(s)&&!dL(s)&&n.add(s);return[...n]}function dL(t){return KY.some(e=>t===e.replace(/\/$/,"")||t.startsWith(e))}function hL(t){try{return jY(t).isFile()}catch{return!1}}function YY(t,e){if(pL(t))return hL(t)?t:void 0;if(t.includes("/"))return;let o=e.PATH??"";for(let n of o.split(HY)){if(!n)continue;let r=qY(n,t);try{return BY(r,UY.X_OK),r}catch{}}}function gL(t,e=process.env){let o={};for(let n of VY){let r=e[n];typeof r=="string"&&!uL(n)&&(o[n]=r)}for(let[n,r]of Object.entries(t.env))uL(n)||(o[n]=r);return o}function uL(t){return XY.some(e=>e.test(t))}function ZY(t=process.env){let e=t.ALUY_MCP_TIMEOUT_MS;if(typeof e!="string"||e.trim()==="")return mL;let o=Number(e);return!Number.isFinite(o)||o<=0?mL:Math.min(QY,Math.max(JY,Math.round(o)))}function oV(t=process.env){let e=t.ALUY_MCP_CONNECT_TIMEOUT_MS;if(typeof e!="string"||e.trim()==="")return fL;let o=Number(e);return!Number.isFinite(o)||o<=0?fL:Math.min(tV,Math.max(eV,Math.round(o)))}function nV(){return new WY({name:"aluy-cli",version:Fl})}function sV(t,e){if(t.length<=e&&Buffer.byteLength(t,"utf8")<=e)return{text:t,truncated:0};let o=0,n=Math.min(t.length,e);for(;o<n;){let s=o+n+1>>1;Buffer.byteLength(t.slice(0,s),"utf8")<=e?o=s:n=s-1}return{text:t.slice(0,o),truncated:t.length-o}}function iV(t){if(!Array.isArray(t))return"";let e=[],o=0;for(let n of t){if(o>=rV){e.push("\u2026[conte\xFAdo MCP truncado: limite agregado de bytes atingido]");break}if(n!==null&&typeof n=="object"){let r=n;if(r.type==="text"&&typeof r.text=="string"){let{text:s,truncated:i}=sV(r.text,yL),a=i>0?`${s}
457
457
  \u2026[bloco MCP truncado: ${i} chars omitidos por exceder o teto de bytes]`:s;e.push(a),o+=Buffer.byteLength(a,"utf8")}else typeof r.type=="string"&&e.push(`[conte\xFAdo MCP "${r.type}" omitido]`)}}return e.join(`
458
458
  `)}var _p,cL,KY,VY,XY,mL,JY,QY,fL,eV,tV,Ur,yL,rV,Md=p(()=>{"use strict";P();_p=Symbol("mcp-call-timed-out"),cL=Symbol("mcp-call-aborted");KY=["/usr/","/bin/","/sbin/","/lib","/etc/"];VY=["PATH","HOME","USER","LOGNAME","SHELL","LANG","LC_ALL","LC_CTYPE","TERM","TMPDIR","TZ","XDG_RUNTIME_DIR","DBUS_SESSION_BUS_ADDRESS","DISPLAY","WAYLAND_DISPLAY","XAUTHORITY","SystemRoot","SystemDrive","TEMP","TMP","USERPROFILE","APPDATA","PATHEXT","COMSPEC"],XY=[/^ALUY_/i,/TOKEN$/i,/SECRET$/i,/_KEY$/i,/APIKEY$/i,/PASSWORD$/i,/REFRESH/i,/OPENAI|ANTHROPIC|OPENROUTER/i];mL=6e4,JY=1e3,QY=6e5;fL=2e4,eV=1e3,tV=12e4;Ur=class{client=null;transport=null;cwd;parentEnv;callTimeoutMs;connectTimeoutMs;clientFactory;sandboxLauncher;workspaceRoots;network;confinementCleanup;constructor(e={}){this.cwd=e.cwd??process.cwd(),this.parentEnv=e.parentEnv??process.env,this.callTimeoutMs=e.callTimeoutMs??ZY(this.parentEnv),this.connectTimeoutMs=e.connectTimeoutMs??oV(this.parentEnv),this.clientFactory=e.clientFactory??nV,this.sandboxLauncher=e.sandboxLauncher,this.workspaceRoots=e.workspaceRoots??[this.cwd],this.network=e.network??!1}async connect(e){let o=gL(e,this.parentEnv),{command:n,args:r,refused:s,warning:i}=this.resolveSpawnTarget(e);if(s)throw new Error(i??"[sandbox MCP: conex\xE3o recusada \u2014 sem piso de SO de confinamento nesta m\xE1quina (prod)]");i&&process.stderr.write(`aluy: MCP "${e.name}" \u2014 ${i}
459
- `),this.transport=new GY({command:n,args:[...r],env:o,cwd:this.cwd,stderr:"ignore"}),this.client=this.clientFactory();let a=this.client;return(await this.withConnectTimeout(async()=>(await a.connect(this.transport),a.listTools()))).tools.map(c=>({name:c.name,description:typeof c.description=="string"?c.description:"",inputSchema:c.inputSchema}))}resolveSpawnTarget(e){if(!this.sandboxLauncher)return{command:e.command,args:e.args,refused:!1};let o=zY(e.command,e.args,this.parentEnv),n=this.sandboxLauncher.buildConfinedInvocation([e.command,...e.args],{workspaceRoots:this.workspaceRoots,cwd:this.cwd,...o.length>0?{roBinds:o}:{},network:this.network});if(this.confinementCleanup=n.cleanup,!n.command)return this.runConfinementCleanup(),{command:"",args:[],refused:!0,...n.decision.warning?{warning:n.decision.warning}:{}};let r=n.decision.warning??n.warning;return{command:n.command,args:n.args??[],refused:!1,...r?{warning:r}:{}}}runConfinementCleanup(){let e=this.confinementCleanup;if(this.confinementCleanup=void 0,e)try{e()}catch{}}async withConnectTimeout(e){let o=this.connectTimeoutMs,n,r=new Promise(i=>{n=setTimeout(()=>i(_p),o),n.unref?.()}),s;try{s=await Promise.race([e(),r])}finally{n&&clearTimeout(n)}if(s===_p){let i=this.client;this.client=null,this.transport=null;try{await i?.close()}catch{}throw this.runConfinementCleanup(),new Error(`handshake MCP n\xE3o respondeu em ${Math.round(o/1e3)}s (anti-hang de boot).`)}return s}async callTool(e,o,n){let r=this.client;if(!r)return{ok:!1,content:"server n\xE3o conectado"};if(n?.aborted)return{ok:!1,content:`MCP tool "${e}" cancelada pelo usu\xE1rio (ESC/Ctrl-C) antes de iniciar.`};let s=this.callTimeoutMs,i,a=new Promise(h=>{i=setTimeout(()=>h(_p),s),i.unref?.()}),l,c=n?new Promise(h=>{l=()=>h(cL),n.addEventListener("abort",l,{once:!0})}):void 0,d;try{d=await Promise.race([r.callTool({name:e,arguments:{...o}},void 0,{timeout:s,...n?{signal:n}:{}}),a,...c?[c]:[]])}catch(h){return{ok:!1,content:`chamada falhou: ${h instanceof Error?h.message:String(h)}`}}finally{i&&clearTimeout(i),n&&l&&n.removeEventListener("abort",l)}if(d===cL)return await this.resetAfterTimeout(),{ok:!1,content:`MCP tool "${e}" cancelada pelo usu\xE1rio (ESC/Ctrl-C) \u2014 server reiniciado.`};if(d===_p)return await this.resetAfterTimeout(),{ok:!1,content:`MCP tool "${e}" n\xE3o respondeu em ${Math.round(s/1e3)}s \u2014 o server foi reiniciado (fail-soft).`};let m=iV(d.content);return{ok:!(d.isError===!0),content:m}}async resetAfterTimeout(){let e=this.client;this.client=null,this.transport=null;try{await e?.close()}catch{}this.runConfinementCleanup()}async close(){try{await this.client?.close()}finally{this.client=null,this.transport=null,this.runConfinementCleanup()}}},yL=2e4,rV=yL*4});function Mx(t,e){let o=e?.find(r=>r.key===t);if(o!==void 0)return o.displayName;let n=Cn.find(r=>r.key===t);return n!==void 0?n.displayName:t}function Lx(t){switch(t){case"economical":return"econ\xF4mico";case"premium":return"premium";case"standard":return"padr\xE3o";default:return String(t)}}function Px(t){return(t.composition.find(o=>o.role==="principal")??t.composition[0])?.name??""}function kL(t){let e=Px(t),o=Lx(t.costSignal);return e===""?`${t.displayName} \xB7 ${o}`:`${t.displayName} \xB7 ${e} \xB7 ${o}`}function xL(t){if(!t||typeof t!="string")return 0;let e=t.trim();if(e==="")return 0;let o=e.match(/^(\d+(?:\.\d+)?)\s*([kKmM]?)$/);if(!o)return 0;let n=Number(o[1]);if(!Number.isFinite(n)||n<=0)return 0;let r=o[2].toLowerCase();return Math.floor(r==="k"?n*1e3:r==="m"?n*1e6:n)}function Rp(t,e={},o,n){let r=lV(t,o);if(r>0)return r;let s=xL(e[aV]??"");return s>0?s:n!==void 0&&Number.isInteger(n)&&n>0?n:0}function lV(t,e){if(t==="custom"||t==="")return 0;if(e&&e.length>0){let o=cV(e,t);if(o){let n=o.composition.find(s=>s.role==="principal")??o.composition[0],r=n?xL(n.context):0;return r>0?r:bL[t]??vL}}return bL[t]??vL}function cV(t,e){return t.find(o=>o.key===e)}function Ix(t){let e=t.trim().toLowerCase();if(e==="")return;for(let n of Cn)if(n.key.toLowerCase()===e||n.key.toLowerCase()===`aluy-${e}`||n.displayName.toLowerCase()===e)return n.key;let o=dV[e];if(o!==void 0)return o;if(/^aluy-[a-z0-9-]+$/.test(e))return e}function Op(t,e){let o=e.trim(),n=Ix(e);return n!==void 0?(t(n),{title:"model",lines:[`tier trocado para: ${Mx(n)}`]}):o!==""?(t("custom",o),{title:"model",lines:[`modelo Custom: ${o}`,"\u25CD identificador enviado ao broker/provider sem valida\xE7\xE3o pr\xE9via","\u26A0 fora do cat\xE1logo curado: custo/qualidade vari\xE1vel, sem auditoria."]}):{title:"model",lines:['tier desconhecido: ""',`tiers conhecidos: ${Cn.map(r=>r.key).join(" \xB7 ")}`,"\u25CD a composi\xE7\xE3o (modelo por tier) vem do broker \u2014 `/model` sem argumento lista","\u25CD para modelo Custom: `/model <slug>` (ex.: `/model claude-opus-4-8`)"]}}var Cn,bL,vL,aV,dV,jr=p(()=>{"use strict";Cn=[{key:"aluy-flux",displayName:"Flui",costSignal:"economical",composition:[]},{key:"aluy-granito",displayName:"Granito",costSignal:"standard",composition:[]},{key:"aluy-strata",displayName:"Strata",costSignal:"standard",composition:[]},{key:"aluy-deep",displayName:"Cortex",costSignal:"premium",composition:[]}],bL={"aluy-flux":256e3,"aluy-granito":1e6,"aluy-strata":128e3,"aluy-deep":2e5},vL=2e5;aV="ALUY_CONTEXT_WINDOW";dV={deep:"aluy-deep"}});import{homedir as uV}from"node:os";import{join as SL}from"node:path";import{readFileSync as mV,statSync as fV}from"node:fs";var qa,pV,Hr,Ci=p(()=>{"use strict";P();qa="mcp.json",pV=256*1024,Hr=class{file;constructor(e={}){let o=e.baseDir??SL(uV(),".aluy");this.file=SL(o,qa)}get configPath(){return this.file}load(){let e;try{let n=fV(this.file);if(!n.isFile()||n.size>pV)return{config:Te};e=mV(this.file,"utf8")}catch{return{config:Te}}let o;try{o=JSON.parse(e)}catch{return{config:Te,error:`${this.file}: JSON inv\xE1lido \u2014 MCP desativado.`}}try{return{config:qo(o)}}catch(n){let r=n instanceof ge?n.message:String(n);return{config:Te,error:r}}}}});import{homedir as hV}from"node:os";import{join as wL}from"node:path";import{readFileSync as gV,statSync as yV}from"node:fs";var AL,bV,rn,Ld=p(()=>{"use strict";P();AL="config.toml",bV=256*1024,rn=class{file;constructor(e={}){let o=e.baseDir??wL(hV(),".codex");this.file=wL(o,AL)}get configPath(){return this.file}load(){let e;try{let o=yV(this.file);if(!o.isFile()||o.size>bV)return{config:Te};e=gV(this.file,"utf8")}catch{return{config:Te}}try{return{config:Lk(e)}}catch(o){let n=o instanceof ge?o.message:String(o);return{config:Te,error:n}}}}});import{posix as vV}from"node:path";function kV(t){return vV.normalize(t)}function Io(t){let e=kV(t);for(let o of xV)if(o.re.test(e))return o.deny?{kind:"deny",why:o.why}:{kind:"ask",why:o.why};return{kind:"allow"}}function Nx(t){return Io(t).kind==="allow"}var xV,_s=p(()=>{"use strict";xV=[{re:/(?:^|\/|~\/)\.ssh(?:\/|$)/,why:"chaves SSH (~/.ssh)",deny:!0},{re:/(?:^|\/|~\/)\.aws(?:\/|$)/,why:"credenciais AWS (~/.aws)",deny:!0},{re:/(?:^|\/|~\/)\.gnupg(?:\/|$)/,why:"chaves GPG (~/.gnupg)",deny:!0},{re:/(?:~\/|\$\{?HOME\}?\/|\/(?:home|Users)\/[^/]+\/)\.aluy\/rooms(?:\/|$)/,why:"arquivos de sala do Aluy (~/.aluy/rooms)",deny:!0},{re:/~\/\.aluy(?:\/|$)/,why:"estado/credencial do Aluy (~/.aluy)",deny:!0},{re:/(?:^|\/)\.aluy(?:\/(?!agents\/|workflows\/|commands\/)|$)/,why:"estado/credencial do Aluy (.aluy/)",deny:!0},{re:/(?:^|\/|~\/)\.config\/gh\/hosts\.yml$/,why:"token do gh CLI",deny:!0},{re:/(?:^|\/|~\/)\.docker\/config\.json$/,why:"credenciais Docker",deny:!0},{re:/(?:^|\/|~\/)\.kube\/config$/,why:"kubeconfig",deny:!0},{re:/(?:^|\/)id_(?:rsa|ed25519|ecdsa|dsa)\b/,why:"chave privada",deny:!0},{re:/\.pem$|\.p12$|\.pfx$|\.key$/i,why:"material de chave privada",deny:!0},{re:/(?:^|[/\w.-])\.env(?:\.(?!example$|sample$|template$|dist$)[\w.-]+)?$/,why:"arquivo .env (segredos)",deny:!1},{re:/(?:^|\/)[^/]*(?:secret|credential|token|apikey|api_key|password|passwd)[^/]*$/i,why:"arquivo com nome sens\xEDvel (token/secret)",deny:!1}]});var Go,SV,Pd,Mp=p(()=>{"use strict";P();_s();Go=".mcp.json",SV=256*1024,Pd=class{workspace;readFile;exists;constructor(e){this.workspace=e.workspace,this.readFile=e.readFile,this.exists=e.exists}get configPath(){return`${this.workspace.root}/${Go}`}async load(){try{this.workspace.resolveInside(Go)}catch{return{config:Te}}if(Io(Go).kind!=="allow")return{config:Te};let e;try{if(!await this.exists(Go))return{config:Te};e=await this.readFile(Go)}catch{return{config:Te}}if(e.length>SV)return{config:Te,error:`${Go}: grande demais \u2014 MCP de projeto desativado.`};let o;try{o=JSON.parse(e)}catch{return{config:Te,error:`${Go}: JSON inv\xE1lido \u2014 MCP de projeto desativado.`}}try{return{config:qo(o)}}catch(n){let r=n instanceof ge?n.message:String(n);return{config:Te,error:r}}}}});import{homedir as wV}from"node:os";import{join as Dx}from"node:path";import{readdirSync as AV,readFileSync as EV,mkdirSync as TV,statSync as CV}from"node:fs";var _V,Id,RV,OV,qr,Lp=p(()=>{"use strict";P();_V=448,Id="agents",RV=64*1024,OV=256,qr=class{dir;constructor(e={}){let o=e.baseDir??Dx(wV(),".aluy");this.dir=Dx(o,Id)}get agentsDir(){return this.dir}ensureDir(){try{TV(this.dir,{mode:_V,recursive:!0})}catch{}}load(){let e;try{e=AV(this.dir,{withFileTypes:!0})}catch{return{profiles:[],errors:[]}}let o=e.filter(i=>i.isFile()&&i.name.toLowerCase().endsWith(".md")).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=OV)break;let a=this.readOne(i);if(a!==null){if($c(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{profiles:r,errors:s}}readOne(e){let o=Dx(this.dir,e);try{let n=CV(o);if(!n.isFile()||n.size>RV)return null;let r=EV(o,"utf8");return Fc(e,r,"global")}catch{return null}}}});import{lookup as MV}from"node:dns";import{request as LV}from"node:https";import{request as PV}from"node:http";function $x(t){return{safe:{resolver:t.resolver??new io,fetcher:t.fetcher??new Rs},egress:new Pp(t.egress),...t.policy?{policy:t.policy}:{}}}function IV(t){return t===301||t===302||t===303||t===307||t===308}function EL(t){if(t!==void 0)return Array.isArray(t)?t[0]:t}var io,Rs,Pp,Os=p(()=>{"use strict";io=class{async resolve(e){return await new Promise((o,n)=>{MV(e,{all:!0,verbatim:!0},(r,s)=>{if(r){n(r);return}let i=(s??[]).map(a=>a.address).filter(a=>a.length>0);o(i)})})}},Rs=class{httpsRequestFn;httpRequestFn;userAgent;constructor(e={}){this.httpsRequestFn=e.httpsRequestFn??LV,this.httpRequestFn=e.httpRequestFn??PV,this.userAgent=e.userAgent??"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0 Safari/537.36 aluy-vau/web"}async fetchPinned(e){let o=new URL(e.url),n=o.protocol==="https:",r=e.pinnedIp.includes(":")?6:4,s=((a,l,c)=>{typeof l=="object"&&l!==null&&l.all===!0?c(null,[{address:e.pinnedIp,family:r}]):c(null,e.pinnedIp,r)}),i=n?this.httpsRequestFn:this.httpRequestFn;return await new Promise((a,l)=>{let c=!1,d=()=>{clearTimeout(A),e.signal&&S&&e.signal.removeEventListener("abort",S)},m=T=>{c||(c=!0,d(),a(T))},u=T=>{c||(c=!0,d(),l(T))},h=e.method??"GET",g=h==="POST"?e.body??"":void 0,b=g!==void 0?{"Content-Type":e.contentType??"application/x-www-form-urlencoded","Content-Length":String(Buffer.byteLength(g))}:{},y=i({protocol:o.protocol,host:e.host,servername:e.host,port:o.port?Number(o.port):n?443:80,path:o.pathname+o.search,method:h,lookup:s,headers:{Host:o.port?`${e.host}:${o.port}`:e.host,"User-Agent":this.userAgent,Accept:"text/html,application/xhtml+xml,text/plain,*/*","Accept-Language":"en-US,en;q=0.9",...b}},T=>{let M=T.statusCode??0,j=EL(T.headers.location),W=EL(T.headers["content-type"]);if(IV(M)&&j){T.resume(),m({status:M,location:j,body:"",...W?{contentType:W}:{}});return}let V=0,z=!1,D=[];T.on("data",Q=>{if(z)return;let oe=e.maxBytes-V;if(oe<=0){z=!0,T.destroy();return}if(Q.length>oe){D.push(Q.subarray(0,oe)),V+=oe,z=!0,T.destroy();return}D.push(Q),V+=Q.length}),T.on("end",()=>{let Q=Buffer.concat(D).toString("utf8");z&&(Q+=`
459
+ `),this.transport=new GY({command:n,args:[...r],env:o,cwd:this.cwd,stderr:"ignore"}),this.client=this.clientFactory();let a=this.client;return(await this.withConnectTimeout(async()=>(await a.connect(this.transport),a.listTools()))).tools.map(c=>({name:c.name,description:typeof c.description=="string"?c.description:"",inputSchema:c.inputSchema}))}resolveSpawnTarget(e){if(!this.sandboxLauncher)return{command:e.command,args:e.args,refused:!1};let o=zY(e.command,e.args,this.parentEnv),n=this.sandboxLauncher.buildConfinedInvocation([e.command,...e.args],{workspaceRoots:this.workspaceRoots,cwd:this.cwd,...o.length>0?{roBinds:o}:{},network:this.network});if(this.confinementCleanup=n.cleanup,!n.command)return this.runConfinementCleanup(),{command:"",args:[],refused:!0,...n.decision.warning?{warning:n.decision.warning}:{}};let r=n.decision.warning??n.warning;return{command:n.command,args:n.args??[],refused:!1,...r?{warning:r}:{}}}runConfinementCleanup(){let e=this.confinementCleanup;if(this.confinementCleanup=void 0,e)try{e()}catch{}}async withConnectTimeout(e){let o=this.connectTimeoutMs,n,r=new Promise(i=>{n=setTimeout(()=>i(_p),o),n.unref?.()}),s;try{s=await Promise.race([e(),r])}finally{n&&clearTimeout(n)}if(s===_p){let i=this.client;this.client=null,this.transport=null;try{await i?.close()}catch{}throw this.runConfinementCleanup(),new Error(`handshake MCP n\xE3o respondeu em ${Math.round(o/1e3)}s (anti-hang de boot).`)}return s}async callTool(e,o,n){let r=this.client;if(!r)return{ok:!1,content:"server n\xE3o conectado"};if(n?.aborted)return{ok:!1,content:`MCP tool "${e}" cancelada pelo usu\xE1rio (ESC/Ctrl-C) antes de iniciar.`};let s=this.callTimeoutMs,i,a=new Promise(h=>{i=setTimeout(()=>h(_p),s),i.unref?.()}),l,c=n?new Promise(h=>{l=()=>h(cL),n.addEventListener("abort",l,{once:!0})}):void 0,d;try{d=await Promise.race([r.callTool({name:e,arguments:{...o}},void 0,{timeout:s,...n?{signal:n}:{}}),a,...c?[c]:[]])}catch(h){return{ok:!1,content:`chamada falhou: ${h instanceof Error?h.message:String(h)}`}}finally{i&&clearTimeout(i),n&&l&&n.removeEventListener("abort",l)}if(d===cL)return await this.resetAfterTimeout(),{ok:!1,content:`MCP tool "${e}" cancelada pelo usu\xE1rio (ESC/Ctrl-C) \u2014 server reiniciado.`};if(d===_p)return await this.resetAfterTimeout(),{ok:!1,content:`MCP tool "${e}" n\xE3o respondeu em ${Math.round(s/1e3)}s \u2014 o server foi reiniciado (fail-soft).`};let m=iV(d.content);return{ok:!(d.isError===!0),content:m}}async resetAfterTimeout(){let e=this.client;this.client=null,this.transport=null;try{await e?.close()}catch{}this.runConfinementCleanup()}async close(){try{await this.client?.close()}finally{this.client=null,this.transport=null,this.runConfinementCleanup()}}},yL=2e4,rV=yL*4});function Mx(t,e){let o=e?.find(r=>r.key===t);if(o!==void 0)return o.displayName;let n=Cn.find(r=>r.key===t);return n!==void 0?n.displayName:t}function Lx(t){switch(t){case"economical":return"econ\xF4mico";case"premium":return"premium";case"standard":return"padr\xE3o";default:return String(t)}}function Px(t){return(t.composition.find(o=>o.role==="principal")??t.composition[0])?.name??""}function kL(t){let e=Px(t),o=Lx(t.costSignal);return e===""?`${t.displayName} \xB7 ${o}`:`${t.displayName} \xB7 ${e} \xB7 ${o}`}function xL(t){if(!t||typeof t!="string")return 0;let e=t.trim();if(e==="")return 0;let o=e.match(/^(\d+(?:\.\d+)?)\s*([kKmM]?)$/);if(!o)return 0;let n=Number(o[1]);if(!Number.isFinite(n)||n<=0)return 0;let r=o[2].toLowerCase();return Math.floor(r==="k"?n*1e3:r==="m"?n*1e6:n)}function Rp(t,e={},o,n){let r=lV(t,o);if(r>0)return r;let s=xL(e[aV]??"");return s>0?s:n!==void 0&&Number.isInteger(n)&&n>0?n:0}function lV(t,e){if(t==="custom"||t==="")return 0;if(e&&e.length>0){let o=cV(e,t);if(o){let n=o.composition.find(s=>s.role==="principal")??o.composition[0],r=n?xL(n.context):0;return r>0?r:bL[t]??vL}}return bL[t]??vL}function cV(t,e){return t.find(o=>o.key===e)}function Ix(t){let e=t.trim().toLowerCase();if(e==="")return;for(let n of Cn)if(n.key.toLowerCase()===e||n.key.toLowerCase()===`aluy-${e}`||n.displayName.toLowerCase()===e)return n.key;let o=dV[e];if(o!==void 0)return o;if(/^aluy-[a-z0-9-]+$/.test(e))return e}function Op(t,e){let o=e.trim(),n=Ix(e);return n!==void 0?(t(n),{title:"model",lines:[`tier trocado para: ${Mx(n)}`]}):o!==""?(t("custom",o),{title:"model",lines:[`modelo Custom: ${o}`,"\u25CD identificador enviado ao broker/provider sem valida\xE7\xE3o pr\xE9via","\u26A0 fora do cat\xE1logo curado: custo/qualidade vari\xE1vel, sem auditoria."]}):{title:"model",lines:['tier desconhecido: ""',`tiers conhecidos: ${Cn.map(r=>r.key).join(" \xB7 ")}`,"\u25CD a composi\xE7\xE3o (modelo por tier) vem do broker \u2014 `/model` sem argumento lista","\u25CD para modelo Custom: `/model <slug>` (ex.: `/model claude-opus-4-8`)"]}}var Cn,bL,vL,aV,dV,jr=p(()=>{"use strict";Cn=[{key:"aluy-flux",displayName:"Flui",costSignal:"economical",composition:[]},{key:"aluy-granito",displayName:"Granito",costSignal:"standard",composition:[]},{key:"aluy-strata",displayName:"Strata",costSignal:"standard",composition:[]},{key:"aluy-deep",displayName:"Cortex",costSignal:"premium",composition:[]}],bL={"aluy-flux":256e3,"aluy-granito":1e6,"aluy-strata":128e3,"aluy-deep":2e5},vL=2e5;aV="ALUY_CONTEXT_WINDOW";dV={deep:"aluy-deep"}});import{homedir as uV}from"node:os";import{join as SL}from"node:path";import{readFileSync as mV,statSync as fV}from"node:fs";var qa,pV,Hr,Ci=p(()=>{"use strict";P();qa="mcp.json",pV=256*1024,Hr=class{file;constructor(e={}){let o=e.baseDir??SL(uV(),".aluy");this.file=SL(o,qa)}get configPath(){return this.file}load(){let e;try{let n=fV(this.file);if(!n.isFile()||n.size>pV)return{config:Te};e=mV(this.file,"utf8")}catch{return{config:Te}}let o;try{o=JSON.parse(e)}catch{return{config:Te,error:`${this.file}: JSON inv\xE1lido \u2014 MCP desativado.`}}try{return{config:qo(o)}}catch(n){let r=n instanceof ge?n.message:String(n);return{config:Te,error:r}}}}});import{homedir as hV}from"node:os";import{join as wL}from"node:path";import{readFileSync as gV,statSync as yV}from"node:fs";var AL,bV,rn,Ld=p(()=>{"use strict";P();AL="config.toml",bV=256*1024,rn=class{file;constructor(e={}){let o=e.baseDir??wL(hV(),".codex");this.file=wL(o,AL)}get configPath(){return this.file}load(){let e;try{let o=yV(this.file);if(!o.isFile()||o.size>bV)return{config:Te};e=gV(this.file,"utf8")}catch{return{config:Te}}try{return{config:Lk(e)}}catch(o){let n=o instanceof ge?o.message:String(o);return{config:Te,error:n}}}}});import{posix as vV}from"node:path";function kV(t){return vV.normalize(t)}function Io(t){let e=kV(t);for(let o of xV)if(o.re.test(e))return o.deny?{kind:"deny",why:o.why}:{kind:"ask",why:o.why};return{kind:"allow"}}function Nx(t){return Io(t).kind==="allow"}var xV,_s=p(()=>{"use strict";xV=[{re:/(?:^|\/|~\/)\.ssh(?:\/|$)/,why:"chaves SSH (~/.ssh)",deny:!0},{re:/(?:^|\/|~\/)\.aws(?:\/|$)/,why:"credenciais AWS (~/.aws)",deny:!0},{re:/(?:^|\/|~\/)\.gnupg(?:\/|$)/,why:"chaves GPG (~/.gnupg)",deny:!0},{re:/(?:~\/|\$\{?HOME\}?\/|\/(?:home|Users)\/[^/]+\/)\.aluy\/rooms(?:\/|$)/,why:"arquivos de sala do Aluy (~/.aluy/rooms)",deny:!0},{re:/~\/\.aluy(?:\/|$)/,why:"estado/credencial do Aluy (~/.aluy)",deny:!0},{re:/(?:^|\/)\.aluy(?:\/(?!agents\/|workflows\/|commands\/)|$)/,why:"estado/credencial do Aluy (.aluy/)",deny:!0},{re:/(?:^|\/|~\/)\.config\/gh\/hosts\.yml$/,why:"token do gh CLI",deny:!0},{re:/(?:^|\/|~\/)\.docker\/config\.json$/,why:"credenciais Docker",deny:!0},{re:/(?:^|\/|~\/)\.kube\/config$/,why:"kubeconfig",deny:!0},{re:/(?:^|\/)id_(?:rsa|ed25519|ecdsa|dsa)\b/,why:"chave privada",deny:!0},{re:/\.pem$|\.p12$|\.pfx$|\.key$/i,why:"material de chave privada",deny:!0},{re:/(?:^|[/\w.-])\.env(?:\.(?!example$|sample$|template$|dist$)[\w.-]+)?$/,why:"arquivo .env (segredos)",deny:!1},{re:/(?:^|\/)[^/]*(?:secret|credential|token|apikey|api_key|password|passwd)[^/]*$/i,why:"arquivo com nome sens\xEDvel (token/secret)",deny:!1}]});var Go,SV,Pd,Mp=p(()=>{"use strict";P();_s();Go=".mcp.json",SV=256*1024,Pd=class{workspace;readFile;exists;constructor(e){this.workspace=e.workspace,this.readFile=e.readFile,this.exists=e.exists}get configPath(){return`${this.workspace.root}/${Go}`}async load(){try{this.workspace.resolveInside(Go)}catch{return{config:Te}}if(Io(Go).kind!=="allow")return{config:Te};let e;try{if(!await this.exists(Go))return{config:Te};e=await this.readFile(Go)}catch{return{config:Te}}if(e.length>SV)return{config:Te,error:`${Go}: grande demais \u2014 MCP de projeto desativado.`};let o;try{o=JSON.parse(e)}catch{return{config:Te,error:`${Go}: JSON inv\xE1lido \u2014 MCP de projeto desativado.`}}try{return{config:qo(o)}}catch(n){let r=n instanceof ge?n.message:String(n);return{config:Te,error:r}}}}});import{homedir as wV}from"node:os";import{join as Dx}from"node:path";import{readdirSync as AV,readFileSync as EV,mkdirSync as TV,statSync as CV}from"node:fs";var _V,Id,RV,OV,qr,Lp=p(()=>{"use strict";P();_V=448,Id="agents",RV=64*1024,OV=256,qr=class{dir;constructor(e={}){let o=e.baseDir??Dx(wV(),".aluy");this.dir=Dx(o,Id)}get agentsDir(){return this.dir}ensureDir(){try{TV(this.dir,{mode:_V,recursive:!0})}catch{}}load(){let e;try{e=AV(this.dir,{withFileTypes:!0})}catch{return{profiles:[],errors:[]}}let o=e.filter(i=>(i.isFile()||i.isSymbolicLink())&&i.name.toLowerCase().endsWith(".md")).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=OV)break;let a=this.readOne(i);if(a!==null){if($c(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{profiles:r,errors:s}}readOne(e){let o=Dx(this.dir,e);try{let n=CV(o);if(!n.isFile()||n.size>RV)return null;let r=EV(o,"utf8");return Fc(e,r,"global")}catch{return null}}}});import{lookup as MV}from"node:dns";import{request as LV}from"node:https";import{request as PV}from"node:http";function $x(t){return{safe:{resolver:t.resolver??new io,fetcher:t.fetcher??new Rs},egress:new Pp(t.egress),...t.policy?{policy:t.policy}:{}}}function IV(t){return t===301||t===302||t===303||t===307||t===308}function EL(t){if(t!==void 0)return Array.isArray(t)?t[0]:t}var io,Rs,Pp,Os=p(()=>{"use strict";io=class{async resolve(e){return await new Promise((o,n)=>{MV(e,{all:!0,verbatim:!0},(r,s)=>{if(r){n(r);return}let i=(s??[]).map(a=>a.address).filter(a=>a.length>0);o(i)})})}},Rs=class{httpsRequestFn;httpRequestFn;userAgent;constructor(e={}){this.httpsRequestFn=e.httpsRequestFn??LV,this.httpRequestFn=e.httpRequestFn??PV,this.userAgent=e.userAgent??"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0 Safari/537.36 aluy-vau/web"}async fetchPinned(e){let o=new URL(e.url),n=o.protocol==="https:",r=e.pinnedIp.includes(":")?6:4,s=((a,l,c)=>{typeof l=="object"&&l!==null&&l.all===!0?c(null,[{address:e.pinnedIp,family:r}]):c(null,e.pinnedIp,r)}),i=n?this.httpsRequestFn:this.httpRequestFn;return await new Promise((a,l)=>{let c=!1,d=()=>{clearTimeout(A),e.signal&&S&&e.signal.removeEventListener("abort",S)},m=T=>{c||(c=!0,d(),a(T))},u=T=>{c||(c=!0,d(),l(T))},h=e.method??"GET",g=h==="POST"?e.body??"":void 0,b=g!==void 0?{"Content-Type":e.contentType??"application/x-www-form-urlencoded","Content-Length":String(Buffer.byteLength(g))}:{},y=i({protocol:o.protocol,host:e.host,servername:e.host,port:o.port?Number(o.port):n?443:80,path:o.pathname+o.search,method:h,lookup:s,headers:{Host:o.port?`${e.host}:${o.port}`:e.host,"User-Agent":this.userAgent,Accept:"text/html,application/xhtml+xml,text/plain,*/*","Accept-Language":"en-US,en;q=0.9",...b}},T=>{let M=T.statusCode??0,j=EL(T.headers.location),W=EL(T.headers["content-type"]);if(IV(M)&&j){T.resume(),m({status:M,location:j,body:"",...W?{contentType:W}:{}});return}let V=0,z=!1,D=[];T.on("data",Q=>{if(z)return;let oe=e.maxBytes-V;if(oe<=0){z=!0,T.destroy();return}if(Q.length>oe){D.push(Q.subarray(0,oe)),V+=oe,z=!0,T.destroy();return}D.push(Q),V+=Q.length}),T.on("end",()=>{let Q=Buffer.concat(D).toString("utf8");z&&(Q+=`
460
460
  \u2026[truncado: corpo maior que ${e.maxBytes} bytes]`),m({status:M,body:Q,...W?{contentType:W}:{}})}),T.on("close",()=>{if(c)return;let Q=Buffer.concat(D).toString("utf8")+(z?`
461
461
  \u2026[truncado: corpo maior que ${e.maxBytes} bytes]`:"");m({status:M,body:Q,...W?{contentType:W}:{}})}),T.on("error",Q=>{if(z){if(c)return;let oe=Buffer.concat(D).toString("utf8")+`
462
462
  \u2026[truncado: corpo maior que ${e.maxBytes} bytes]`;m({status:M,body:oe,...W?{contentType:W}:{}});return}u(Q)})}),S=()=>{y.destroy(),u(new Error("cancelado"))},A=setTimeout(()=>{y.destroy(),u(new Error(`timeout de ${e.timeoutMs}ms ao buscar a URL`))},e.timeoutMs);if(A.unref?.(),e.signal){if(e.signal.aborted){y.destroy(),u(new Error("cancelado"));return}e.signal.addEventListener("abort",S)}y.on("error",u),g!==void 0&&y.write(g),y.end()})}},Pp=class{constructor(e){this.allowlist=e}allowlist;checkHost(e){let o=e.trim().toLowerCase();return{allowed:this.allowlist.isAllowed(o),host:o}}}});function NV(t){let e=t.options.map(r=>`- id: "${r.id}", label: "${r.label}"${r.detail?` (${r.detail})`:""}`).join(`
@@ -496,7 +496,7 @@ ${r.text}`).join(`
496
496
  `)});break}case"bang":{let n=[`! ${o.command} (${o.status})`];o.output&&n.push(o.output),e.push({role:"observation",toolName:fS,text:n.join(`
497
497
  `)});break}case"broker-error":e.push({role:"observation",toolName:fS,text:`(erro de broker anterior: ${o.message})`});break;case"note":case"deny":case"subagents":case"doctor":case"inject":break}return e}var f3,fS,pS=p(()=>{"use strict";f3=new Set(["you","aluy","tool","deny","bang","broker-error","note","inject","doctor"]);fS="sess\xE3o-anterior"});function v3(t){return t.kind==="tool"&&b3.has(t.verb)}function JP(t){let e=!1,o=t.map(n=>{if(n.kind==="tool"&&v3(n)){let r=Xe(n.result),s=n.output!==void 0?Xe(n.output):void 0,i=n.liveOutput!==void 0?Xe(n.liveOutput):void 0;return r===n.result&&s===n.output&&i===n.liveOutput?n:(e=!0,{...n,result:r,...s!==void 0?{output:s}:{},...i!==void 0?{liveOutput:i}:{}})}if(n.kind==="bang"){let r=yo(n.command);return r===n.command?n:(e=!0,{...n,command:r})}if(n.kind==="tool"&&y3.has(n.verb)){let r=yo(n.target);return r===n.target?n:(e=!0,{...n,target:r})}return n});return e?o:t}var y3,b3,QP=p(()=>{"use strict";P();y3=new Set(["bash","run_command"]),b3=new Set(["read","grep","attach","headroom_retrieve"])});import{homedir as k3}from"node:os";import{join as hS}from"node:path";import{randomBytes as x3}from"node:crypto";import{openSync as S3,writeSync as w3,closeSync as ZP,readFileSync as A3,readdirSync as eI,mkdirSync as E3,renameSync as T3,unlinkSync as tI,statSync as C3,existsSync as tge,constants as gS}from"node:fs";function N3(t,e){let o=[...t];return o.length>e?o.slice(0,e).join(""):t}function th(t){if(typeof t!="string")return;let e="";for(let n of t){let r=n.codePointAt(0)??0;e+=r<32||r===127?" ":n}let o=e.replace(/\s+/g," ").trim();if(o!=="")return N3(o,I3)}function D3(t){for(let e of t)if(e.kind==="you"){let o=e.text.replace(/\s+/g," ").trim();if(o==="")return;let n=[...o];return n.length>60?n.slice(0,57).join("")+"\u2026":o}}var _3,R3,oI,nI,O3,M3,yS,L3,P3,eh,I3,eu,rI=p(()=>{"use strict";pS();QP();_3=448,R3=384,oI="sessions",nI=1,O3=720*60*60*1e3,M3=50,yS=8*1024*1024,L3=yS*8,P3=Math.floor(yS*.9),eh=/^[A-Za-z0-9_-]{1,128}$/,I3=64;eu=class{base;dir;now;createdAtCache=new Map;constructor(e={}){this.base=e.baseDir??hS(k3(),".aluy"),this.dir=hS(this.base,oI),this.now=e.now??(()=>Date.now())}get sessionsDir(){return this.dir}pathFor(e){return hS(this.dir,`${e}.json`)}save(e){if(!eh.test(e.id))return!1;try{let o=this.now(),n=this.resolveCreatedAt(e.id,o),r=e.tier==="custom"&&typeof e.model=="string"&&e.model.trim()!=="",s=r&&typeof e.provider=="string"&&e.provider.trim()!=="",i=th(e.label),a=i!==void 0?th(e.labelColor):void 0,l={id:e.id,version:nI,createdAt:n,updatedAt:o,cwd:e.cwd,tier:e.tier,...r?{model:e.model.trim()}:{},...s?{provider:e.provider.trim()}:{},...i!==void 0?{label:i}:{},...a!==void 0?{labelColor:a}:{}},c=this.fitBlocks(l,JP(Zp(e.blocks))),d={...l,blocks:c};return this.writeAtomic(d),!0}catch{return!1}}resolveCreatedAt(e,o){let n=this.createdAtCache.get(e);if(n!==void 0)return n;let r=this.load(e)?.createdAt??o;return this.createdAtCache.set(e,r),r}load(e){if(!eh.test(e))return null;let o=this.pathFor(e),n,r=!1;try{let a=C3(o);if(a.size>L3)return null;r=a.size>yS,n=A3(o,"utf8")}catch{return null}let s;try{s=JSON.parse(n)}catch{return null}let i=this.sanitizeRecord(s);if(i&&r){let{blocks:a,...l}=i,c=this.fitBlocks(l,a),d=a.length-c.length,m={kind:"note",title:"sess\xE3o grande \u2014 contexto antigo omitido no resume",lines:[`Esta sess\xE3o era grande demais p/ recarregar inteira; ${d} bloco(s) antigo(s) foram omitidos e a parte recente foi preservada.`,"O contexto restante ser\xE1 resumido automaticamente na pr\xF3xima intera\xE7\xE3o."]};i={...i,blocks:d>0?[m,...c]:c}}return i&&this.createdAtCache.set(i.id,i.createdAt),i}list(){let e;try{e=eI(this.dir)}catch{return[]}let o=[];for(let n of e){if(!n.endsWith(".json"))continue;let r=n.slice(0,-5),s=this.load(r);s&&o.push({id:s.id,createdAt:s.createdAt,updatedAt:s.updatedAt,cwd:s.cwd,tier:s.tier,...s.model!==void 0?{model:s.model}:{},...s.provider!==void 0?{provider:s.provider}:{},...s.label!==void 0?{label:s.label}:{},...s.labelColor!==void 0?{labelColor:s.labelColor}:{},blockCount:s.blocks.length,title:D3(s.blocks)})}return o.sort((n,r)=>r.updatedAt-n.updatedAt),o}latestForCwd(e){let o;try{o=eI(this.dir)}catch{return null}let n=null;for(let r of o){if(!r.endsWith(".json"))continue;let s=r.slice(0,-5),i=this.load(s);!i||i.cwd!==e||(n===null||i.updatedAt>n.updatedAt)&&(n=i)}return n}remove(e){if(eh.test(e)){this.createdAtCache.delete(e);try{tI(this.pathFor(e))}catch{}}}gc(e={}){let o=e.maxAgeMs??O3,n=e.maxCount??M3,r=this.list(),s=this.now()-o;r.forEach((i,a)=>{(i.updatedAt<s||a>=n)&&this.remove(i.id)})}sanitizeRecord(e){if(typeof e!="object"||e===null)return null;let o=e;if(typeof o.id!="string"||!eh.test(o.id)||!Array.isArray(o.blocks))return null;let n=typeof o.createdAt=="number"&&o.createdAt>=0?o.createdAt:0,r=typeof o.updatedAt=="number"&&o.updatedAt>=0?o.updatedAt:n,s=typeof o.cwd=="string"?o.cwd:"",i=typeof o.tier=="string"&&o.tier.trim()!==""?o.tier:"",a=typeof o.version=="number"?o.version:0,l=i==="custom"&&typeof o.model=="string"&&o.model.trim()!==""?o.model.trim():void 0,c=l!==void 0&&typeof o.provider=="string"&&o.provider.trim()!==""?o.provider.trim():void 0,d=th(o.label),m=d!==void 0?th(o.labelColor):void 0;return{id:o.id,version:a,createdAt:n,updatedAt:r,cwd:s,tier:i,...l!==void 0?{model:l}:{},...c!==void 0?{provider:c}:{},...d!==void 0?{label:d}:{},...m!==void 0?{labelColor:m}:{},blocks:Zp(o.blocks)}}fitBlocks(e,o){let n=i=>Buffer.byteLength(JSON.stringify({...e,blocks:i})+`
498
498
  `,"utf8")<=P3;if(n(o))return o;let r=1,s=o.length;for(;r<s;){let i=r+s>>1;n(o.slice(i))?s=i:r=i+1}return o.slice(r)}writeAtomic(e){E3(this.dir,{recursive:!0,mode:_3});let o=this.pathFor(e.id),n=`${o}.${process.pid}.${x3(6).toString("hex")}.tmp`,r=JSON.stringify(e)+`
499
- `,s;try{s=S3(n,gS.O_CREAT|gS.O_EXCL|gS.O_WRONLY,R3),w3(s,r),ZP(s),s=void 0,T3(n,o)}catch(i){if(s!==void 0)try{ZP(s)}catch{}try{tI(n)}catch{}throw i}}}});import{homedir as $3}from"node:os";import{join as bS}from"node:path";import{readdirSync as F3,readFileSync as B3,mkdirSync as U3,statSync as j3}from"node:fs";var H3,sI,q3,W3,tu,iI=p(()=>{"use strict";P();H3=448,sI="commands",q3=64*1024,W3=256,tu=class{dir;constructor(e={}){let o=e.baseDir??bS($3(),".aluy");this.dir=bS(o,sI)}get commandsDir(){return this.dir}ensureDir(){try{U3(this.dir,{mode:H3,recursive:!0})}catch{}}load(){let e;try{e=F3(this.dir,{withFileTypes:!0})}catch{return[]}let o=e.filter(s=>s.isFile()&&s.name.toLowerCase().endsWith(".md")).map(s=>s.name).sort((s,i)=>s.localeCompare(i)),n=new Set,r=[];for(let s of o){if(r.length>=W3)break;let i=this.readOne(s);i&&(n.has(i.name)||(n.add(i.name),r.push(i)))}return r}readOne(e){let o=bS(this.dir,e);try{let n=j3(o);if(!n.isFile()||n.size>q3)return null;let r=B3(o,"utf8");return Kc(e,r)}catch{return null}}}});import{join as G3}from"node:path";import{readdirSync as z3,readFileSync as K3,statSync as Y3}from"node:fs";function vS(t,e){let o=new Map;for(let n of t)o.set(n.name,n);for(let n of e)o.set(n.name,n);return[...o.values()]}var aI,V3,X3,ou,lI=p(()=>{"use strict";P();_s();aI=[".claude/commands",".aluy/commands"],V3=64*1024,X3=256,ou=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[];for(let n of aI){let r;try{r=this.workspace.resolveInside(n)}catch{continue}let s;try{s=z3(r,{withFileTypes:!0})}catch{continue}let i=s.filter(a=>a.isFile()&&a.name.toLowerCase().endsWith(".md")).map(a=>a.name).sort((a,l)=>a.localeCompare(l));for(let a of i){if(o.length>=X3)break;let l=this.readOne(n,r,a);l&&(e.has(l.name)||(e.add(l.name),o.push(l)))}}return o}readOne(e,o,n){let r=`${e}/${n}`;if(Io(r).kind!=="allow")return null;let s=G3(o,n);try{this.workspace.resolveInside(r);let i=Y3(s);if(!i.isFile()||i.size>V3)return null;let a=K3(s,"utf8");return Kc(n,a)}catch{return null}}}});import{join as J3}from"node:path";import{readdirSync as Q3,readFileSync as Z3,statSync as eJ}from"node:fs";var cI,tJ,oJ,Li,kS=p(()=>{"use strict";P();_s();cI=[".claude/agents",".aluy/agents"],tJ=64*1024,oJ=256,Li=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of cI){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=Q3(s,{withFileTypes:!0})}catch{continue}let a=i.filter(l=>l.isFile()&&l.name.toLowerCase().endsWith(".md")).map(l=>l.name).sort((l,c)=>l.localeCompare(c));for(let l of a){if(o.length>=oJ)break;let c=this.readOne(r,s,l);if(c!==null){if($c(c)){n.push(c);continue}e.has(c.name)||(e.add(c.name),o.push(c))}}}return{profiles:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}`;if(Io(r).kind!=="allow")return null;let s=J3(o,n);try{this.workspace.resolveInside(r);let i=eJ(s);if(!i.isFile()||i.size>tJ)return null;let a=Z3(s,"utf8");return Fc(n,a,"project")}catch{return null}}}});var SS={};ut(SS,{UserWorkflowsLoader:()=>tr,WORKFLOWS_DIRNAME:()=>Va});import{homedir as nJ}from"node:os";import{join as xS}from"node:path";import{readdirSync as rJ,readFileSync as sJ,mkdirSync as iJ,statSync as aJ}from"node:fs";var lJ,Va,cJ,dJ,tr,nu=p(()=>{"use strict";P();lJ=448,Va="workflows",cJ=64*1024,dJ=256,tr=class{dir;constructor(e={}){let o=e.baseDir??xS(nJ(),".aluy");this.dir=xS(o,Va)}get workflowsDir(){return this.dir}ensureDir(){try{iJ(this.dir,{mode:lJ,recursive:!0})}catch{}}load(){let e;try{e=rJ(this.dir,{withFileTypes:!0})}catch{return{workflows:[],errors:[]}}let o=e.filter(i=>i.isFile()&&i.name.toLowerCase().endsWith(".md")).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=dJ)break;let a=this.readOne(i);if(a!==null){if(qc(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{workflows:r,errors:s}}readOne(e){let o=xS(this.dir,e);try{let n=aJ(o);if(!n.isFile()||n.size>cJ)return null;let r=sJ(o,"utf8");return Wc(e,r,"global")}catch{return null}}}});var AS={};ut(AS,{PROJECT_WORKFLOWS_DIRNAMES:()=>wS,ProjectWorkflowsLoader:()=>or});import{join as uJ}from"node:path";import{readdirSync as mJ,readFileSync as fJ,statSync as pJ}from"node:fs";var wS,hJ,gJ,or,ru=p(()=>{"use strict";P();_s();wS=[".claude/workflows",".aluy/workflows"],hJ=64*1024,gJ=256,or=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of wS){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=mJ(s,{withFileTypes:!0})}catch{continue}let a=i.filter(l=>l.isFile()&&l.name.toLowerCase().endsWith(".md")).map(l=>l.name).sort((l,c)=>l.localeCompare(c));for(let l of a){if(o.length>=gJ)break;let c=this.readOne(r,s,l);if(c!==null){if(qc(c)){n.push(c);continue}e.has(c.name)||(e.add(c.name),o.push(c))}}}return{workflows:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}`;if(Io(r).kind!=="allow")return null;let s=uJ(o,n);try{this.workspace.resolveInside(r);let i=pJ(s);if(!i.isFile()||i.size>hJ)return null;let a=fJ(s,"utf8");return Wc(n,a,"project")}catch{return null}}}});import{homedir as yJ}from"node:os";import{join as ES}from"node:path";import{readdirSync as bJ,readFileSync as vJ,mkdirSync as kJ,statSync as xJ}from"node:fs";var SJ,su,iu,wJ,AJ,zr,oh=p(()=>{"use strict";P();SJ=448,su="skills",iu="SKILL.md",wJ=256*1024,AJ=256,zr=class{dir;constructor(e={}){let o=e.baseDir??ES(yJ(),".aluy");this.dir=ES(o,su)}get skillsDir(){return this.dir}ensureDir(){try{kJ(this.dir,{mode:SJ,recursive:!0})}catch{}}load(){let e;try{e=bJ(this.dir,{withFileTypes:!0})}catch{return{skills:[],errors:[]}}let o=e.filter(i=>i.isDirectory()).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=AJ)break;let a=this.readOne(i);if(a!==null){if(Uc(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{skills:r,errors:s}}readOne(e){let o=ES(this.dir,e,iu);try{let n=xJ(o);if(!n.isFile()||n.size>wJ)return null;let r=vJ(o,"utf8");return jc(e,r,"global")}catch{return null}}}});import{join as EJ}from"node:path";import{readdirSync as TJ,readFileSync as CJ,statSync as _J}from"node:fs";var dI,RJ,OJ,Kr,TS=p(()=>{"use strict";P();oh();dI=[".claude/skills",".aluy/skills"],RJ=256*1024,OJ=256,Kr=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of dI){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=TJ(s,{withFileTypes:!0})}catch{continue}let a=i.filter(l=>l.isDirectory()).map(l=>l.name).sort((l,c)=>l.localeCompare(c));for(let l of a){if(o.length>=OJ)break;let c=this.readOne(r,s,l);if(c!==null){if(Uc(c)){n.push(c);continue}e.has(c.name)||(e.add(c.name),o.push(c))}}}return{skills:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}/${iu}`,s=EJ(o,n,iu);try{this.workspace.resolveInside(r);let i=_J(s);if(!i.isFile()||i.size>RJ)return null;let a=CJ(s,"utf8");return jc(n,a,"project")}catch{return null}}}});import{homedir as MJ}from"node:os";import{join as CS}from"node:path";import{readFileSync as LJ,statSync as PJ}from"node:fs";var uI,IJ,NJ,au,mI=p(()=>{"use strict";P();uI="hooks.json",IJ="settings.json",NJ=256*1024,au=class{file;claudeProjectFile;constructor(e={}){let o=e.baseDir??CS(MJ(),".aluy");this.file=CS(o,uI),e.workspaceRoot!==void 0&&(this.claudeProjectFile=CS(e.workspaceRoot,".claude",IJ))}get configPath(){return this.file}load(){let e=Pv(this.readJson(this.file));if(this.claudeProjectFile===void 0)return e;let o=Nv(this.readJson(this.claudeProjectFile));return Dv(e,o)}readJson(e){let o;try{let n=PJ(e);if(!n.isFile()||n.size>NJ)return;o=LJ(e,"utf8")}catch{return}try{return JSON.parse(o)}catch{return}}}});var lu=p(()=>{"use strict";Ha();vP();Kp();SP();TP();OP();Xp();Os();BP();Ox();jx();HP();qP();lS();dS();Mo();YP();rI();pS();iI();lI();Lp();kS();nu();ru();oh();TS();mI()});function cu(t,e){let o=t.toLowerCase(),n=e.toLowerCase();if(o==="")return{score:0,matched:[]};let r=[],s=0,i=0,a=-1,l=e.lastIndexOf("/")+1;for(let d=0;d<o.length;d++){let m=o[d],u=n.indexOf(m,s);if(u===-1)return null;r.push(u),a>=0&&u===a+1?i+=5:i+=1,u>=l&&(i+=2);let h=u>0?e[u-1]:"/";(h==="/"||h==="-"||h==="_"||h===".")&&(i+=3),a=u,s=u+1}let c=(r[r.length-1]??0)-(r[0]??0);return i-=c*.1,i-=e.length*.01,{score:i,matched:r}}function _S(t,e){let o=t.trim();if(o==="")return e.map(r=>({path:r,score:0,matched:[]}));let n=[];for(let r of e){let s=cu(o,r);s&&n.push({path:r,score:s.score,matched:s.matched})}return n.sort((r,s)=>s.score-r.score||r.path.length-s.path.length||r.path.localeCompare(s.path)),n}var RS=p(()=>{"use strict"});function $J(t){return t.replace(/\\ /g," ")}function FJ(t){return t.includes("/")?!0:/\.[A-Za-z0-9]+$/.test(t)}function BJ(t){let e=t.replace(/\.+$/,"");return{token:e,trimmed:t.length-e.length}}function Pi(t){let e=[];for(let o of t.matchAll(DJ)){let n=o[1],r=o[4],s=o[2]??o[3]??r,{token:i,trimmed:a}=r!==void 0?BJ(s):{token:s,trimmed:0},l=$J(i);if(!FJ(l))continue;let c=(o.index??0)+o[0].indexOf(n);e.push({path:l,start:c,end:c+n.length-a})}return e}function OS(t,e){if(e.length===0)return t;let o=t;for(let n of[...e].sort((r,s)=>s.start-r.start))o=o.slice(0,n.start)+o.slice(n.end);return o.replace(/\s{2,}/g," ").trim()}var DJ,fI=p(()=>{"use strict";DJ=/(?:^|\s)(@(?:"([^"]+)"|'([^']+)'|((?:[\p{L}\p{N}._/-]|\\ )+)))/gu});function nh(t){let e=t.lastIndexOf("@");if(e<0)return null;let o=e>0?t[e-1]:" ";if(o!==" "&&o!==`
499
+ `,s;try{s=S3(n,gS.O_CREAT|gS.O_EXCL|gS.O_WRONLY,R3),w3(s,r),ZP(s),s=void 0,T3(n,o)}catch(i){if(s!==void 0)try{ZP(s)}catch{}try{tI(n)}catch{}throw i}}}});import{homedir as $3}from"node:os";import{join as bS}from"node:path";import{readdirSync as F3,readFileSync as B3,mkdirSync as U3,statSync as j3}from"node:fs";var H3,sI,q3,W3,tu,iI=p(()=>{"use strict";P();H3=448,sI="commands",q3=64*1024,W3=256,tu=class{dir;constructor(e={}){let o=e.baseDir??bS($3(),".aluy");this.dir=bS(o,sI)}get commandsDir(){return this.dir}ensureDir(){try{U3(this.dir,{mode:H3,recursive:!0})}catch{}}load(){let e;try{e=F3(this.dir,{withFileTypes:!0})}catch{return[]}let o=e.filter(s=>(s.isFile()||s.isSymbolicLink())&&s.name.toLowerCase().endsWith(".md")).map(s=>s.name).sort((s,i)=>s.localeCompare(i)),n=new Set,r=[];for(let s of o){if(r.length>=W3)break;let i=this.readOne(s);i&&(n.has(i.name)||(n.add(i.name),r.push(i)))}return r}readOne(e){let o=bS(this.dir,e);try{let n=j3(o);if(!n.isFile()||n.size>q3)return null;let r=B3(o,"utf8");return Kc(e,r)}catch{return null}}}});import{join as G3}from"node:path";import{readdirSync as z3,readFileSync as K3,statSync as Y3}from"node:fs";function vS(t,e){let o=new Map;for(let n of t)o.set(n.name,n);for(let n of e)o.set(n.name,n);return[...o.values()]}var aI,V3,X3,ou,lI=p(()=>{"use strict";P();_s();aI=[".claude/commands",".aluy/commands"],V3=64*1024,X3=256,ou=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[];for(let n of aI){let r;try{r=this.workspace.resolveInside(n)}catch{continue}let s;try{s=z3(r,{withFileTypes:!0})}catch{continue}let i=s.filter(a=>(a.isFile()||a.isSymbolicLink())&&a.name.toLowerCase().endsWith(".md")).map(a=>a.name).sort((a,l)=>a.localeCompare(l));for(let a of i){if(o.length>=X3)break;let l=this.readOne(n,r,a);l&&(e.has(l.name)||(e.add(l.name),o.push(l)))}}return o}readOne(e,o,n){let r=`${e}/${n}`;if(Io(r).kind!=="allow")return null;let s=G3(o,n);try{this.workspace.resolveInside(r);let i=Y3(s);if(!i.isFile()||i.size>V3)return null;let a=K3(s,"utf8");return Kc(n,a)}catch{return null}}}});import{join as J3}from"node:path";import{readdirSync as Q3,readFileSync as Z3,statSync as eJ}from"node:fs";var cI,tJ,oJ,Li,kS=p(()=>{"use strict";P();_s();cI=[".claude/agents",".aluy/agents"],tJ=64*1024,oJ=256,Li=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of cI){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=Q3(s,{withFileTypes:!0})}catch{continue}let a=i.filter(l=>(l.isFile()||l.isSymbolicLink())&&l.name.toLowerCase().endsWith(".md")).map(l=>l.name).sort((l,c)=>l.localeCompare(c));for(let l of a){if(o.length>=oJ)break;let c=this.readOne(r,s,l);if(c!==null){if($c(c)){n.push(c);continue}e.has(c.name)||(e.add(c.name),o.push(c))}}}return{profiles:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}`;if(Io(r).kind!=="allow")return null;let s=J3(o,n);try{this.workspace.resolveInside(r);let i=eJ(s);if(!i.isFile()||i.size>tJ)return null;let a=Z3(s,"utf8");return Fc(n,a,"project")}catch{return null}}}});var SS={};ut(SS,{UserWorkflowsLoader:()=>tr,WORKFLOWS_DIRNAME:()=>Va});import{homedir as nJ}from"node:os";import{join as xS}from"node:path";import{readdirSync as rJ,readFileSync as sJ,mkdirSync as iJ,statSync as aJ}from"node:fs";var lJ,Va,cJ,dJ,tr,nu=p(()=>{"use strict";P();lJ=448,Va="workflows",cJ=64*1024,dJ=256,tr=class{dir;constructor(e={}){let o=e.baseDir??xS(nJ(),".aluy");this.dir=xS(o,Va)}get workflowsDir(){return this.dir}ensureDir(){try{iJ(this.dir,{mode:lJ,recursive:!0})}catch{}}load(){let e;try{e=rJ(this.dir,{withFileTypes:!0})}catch{return{workflows:[],errors:[]}}let o=e.filter(i=>(i.isFile()||i.isSymbolicLink())&&i.name.toLowerCase().endsWith(".md")).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=dJ)break;let a=this.readOne(i);if(a!==null){if(qc(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{workflows:r,errors:s}}readOne(e){let o=xS(this.dir,e);try{let n=aJ(o);if(!n.isFile()||n.size>cJ)return null;let r=sJ(o,"utf8");return Wc(e,r,"global")}catch{return null}}}});var AS={};ut(AS,{PROJECT_WORKFLOWS_DIRNAMES:()=>wS,ProjectWorkflowsLoader:()=>or});import{join as uJ}from"node:path";import{readdirSync as mJ,readFileSync as fJ,statSync as pJ}from"node:fs";var wS,hJ,gJ,or,ru=p(()=>{"use strict";P();_s();wS=[".claude/workflows",".aluy/workflows"],hJ=64*1024,gJ=256,or=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of wS){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=mJ(s,{withFileTypes:!0})}catch{continue}let a=i.filter(l=>(l.isFile()||l.isSymbolicLink())&&l.name.toLowerCase().endsWith(".md")).map(l=>l.name).sort((l,c)=>l.localeCompare(c));for(let l of a){if(o.length>=gJ)break;let c=this.readOne(r,s,l);if(c!==null){if(qc(c)){n.push(c);continue}e.has(c.name)||(e.add(c.name),o.push(c))}}}return{workflows:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}`;if(Io(r).kind!=="allow")return null;let s=uJ(o,n);try{this.workspace.resolveInside(r);let i=pJ(s);if(!i.isFile()||i.size>hJ)return null;let a=fJ(s,"utf8");return Wc(n,a,"project")}catch{return null}}}});import{homedir as yJ}from"node:os";import{join as ES}from"node:path";import{readdirSync as bJ,readFileSync as vJ,mkdirSync as kJ,statSync as xJ}from"node:fs";var SJ,su,iu,wJ,AJ,zr,oh=p(()=>{"use strict";P();SJ=448,su="skills",iu="SKILL.md",wJ=256*1024,AJ=256,zr=class{dir;constructor(e={}){let o=e.baseDir??ES(yJ(),".aluy");this.dir=ES(o,su)}get skillsDir(){return this.dir}ensureDir(){try{kJ(this.dir,{mode:SJ,recursive:!0})}catch{}}load(){let e;try{e=bJ(this.dir,{withFileTypes:!0})}catch{return{skills:[],errors:[]}}let o=e.filter(i=>i.isDirectory()).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=AJ)break;let a=this.readOne(i);if(a!==null){if(Uc(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{skills:r,errors:s}}readOne(e){let o=ES(this.dir,e,iu);try{let n=xJ(o);if(!n.isFile()||n.size>wJ)return null;let r=vJ(o,"utf8");return jc(e,r,"global")}catch{return null}}}});import{join as EJ}from"node:path";import{readdirSync as TJ,readFileSync as CJ,statSync as _J}from"node:fs";var dI,RJ,OJ,Kr,TS=p(()=>{"use strict";P();oh();dI=[".claude/skills",".aluy/skills"],RJ=256*1024,OJ=256,Kr=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of dI){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=TJ(s,{withFileTypes:!0})}catch{continue}let a=i.filter(l=>l.isDirectory()).map(l=>l.name).sort((l,c)=>l.localeCompare(c));for(let l of a){if(o.length>=OJ)break;let c=this.readOne(r,s,l);if(c!==null){if(Uc(c)){n.push(c);continue}e.has(c.name)||(e.add(c.name),o.push(c))}}}return{skills:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}/${iu}`,s=EJ(o,n,iu);try{this.workspace.resolveInside(r);let i=_J(s);if(!i.isFile()||i.size>RJ)return null;let a=CJ(s,"utf8");return jc(n,a,"project")}catch{return null}}}});import{homedir as MJ}from"node:os";import{join as CS}from"node:path";import{readFileSync as LJ,statSync as PJ}from"node:fs";var uI,IJ,NJ,au,mI=p(()=>{"use strict";P();uI="hooks.json",IJ="settings.json",NJ=256*1024,au=class{file;claudeProjectFile;constructor(e={}){let o=e.baseDir??CS(MJ(),".aluy");this.file=CS(o,uI),e.workspaceRoot!==void 0&&(this.claudeProjectFile=CS(e.workspaceRoot,".claude",IJ))}get configPath(){return this.file}load(){let e=Pv(this.readJson(this.file));if(this.claudeProjectFile===void 0)return e;let o=Nv(this.readJson(this.claudeProjectFile));return Dv(e,o)}readJson(e){let o;try{let n=PJ(e);if(!n.isFile()||n.size>NJ)return;o=LJ(e,"utf8")}catch{return}try{return JSON.parse(o)}catch{return}}}});var lu=p(()=>{"use strict";Ha();vP();Kp();SP();TP();OP();Xp();Os();BP();Ox();jx();HP();qP();lS();dS();Mo();YP();rI();pS();iI();lI();Lp();kS();nu();ru();oh();TS();mI()});function cu(t,e){let o=t.toLowerCase(),n=e.toLowerCase();if(o==="")return{score:0,matched:[]};let r=[],s=0,i=0,a=-1,l=e.lastIndexOf("/")+1;for(let d=0;d<o.length;d++){let m=o[d],u=n.indexOf(m,s);if(u===-1)return null;r.push(u),a>=0&&u===a+1?i+=5:i+=1,u>=l&&(i+=2);let h=u>0?e[u-1]:"/";(h==="/"||h==="-"||h==="_"||h===".")&&(i+=3),a=u,s=u+1}let c=(r[r.length-1]??0)-(r[0]??0);return i-=c*.1,i-=e.length*.01,{score:i,matched:r}}function _S(t,e){let o=t.trim();if(o==="")return e.map(r=>({path:r,score:0,matched:[]}));let n=[];for(let r of e){let s=cu(o,r);s&&n.push({path:r,score:s.score,matched:s.matched})}return n.sort((r,s)=>s.score-r.score||r.path.length-s.path.length||r.path.localeCompare(s.path)),n}var RS=p(()=>{"use strict"});function $J(t){return t.replace(/\\ /g," ")}function FJ(t){return t.includes("/")?!0:/\.[A-Za-z0-9]+$/.test(t)}function BJ(t){let e=t.replace(/\.+$/,"");return{token:e,trimmed:t.length-e.length}}function Pi(t){let e=[];for(let o of t.matchAll(DJ)){let n=o[1],r=o[4],s=o[2]??o[3]??r,{token:i,trimmed:a}=r!==void 0?BJ(s):{token:s,trimmed:0},l=$J(i);if(!FJ(l))continue;let c=(o.index??0)+o[0].indexOf(n);e.push({path:l,start:c,end:c+n.length-a})}return e}function OS(t,e){if(e.length===0)return t;let o=t;for(let n of[...e].sort((r,s)=>s.start-r.start))o=o.slice(0,n.start)+o.slice(n.end);return o.replace(/\s{2,}/g," ").trim()}var DJ,fI=p(()=>{"use strict";DJ=/(?:^|\s)(@(?:"([^"]+)"|'([^']+)'|((?:[\p{L}\p{N}._/-]|\\ )+)))/gu});function nh(t){let e=t.lastIndexOf("@");if(e<0)return null;let o=e>0?t[e-1]:" ";if(o!==" "&&o!==`
500
500
  `&&o!==" ")return null;let n=t.slice(e+1);return/\s/.test(n)?null:{at:e,query:n}}function MS(t){let e=nh(t);return e?t.slice(0,e.at).replace(/\s+$/,""):t}var pI=p(()=>{"use strict"});import{relative as UJ,sep as jJ,isAbsolute as HJ}from"node:path";var hI,qJ,du,gI=p(()=>{"use strict";P();_s();zp();hI=16e3,qJ=5*1024*1024,du=class{workspace;fs;maxChars;sniffBytes;constructor(e){this.workspace=e.workspace,this.fs=e.fs,this.maxChars=e.maxChars??hI,this.sniffBytes=e.sniffBytes??qJ}async attach(e,o={}){let n=e,r;try{r=this.workspace.resolveInside(e)}catch{return{kind:"rejected",path:n,reason:"caminho fora do workspace \u2014 recusado (o @ s\xF3 acessa a raiz do projeto)."}}let s=UJ(this.workspace.root,r).split(jJ).join("/");if(s===""||s.startsWith("..")||HJ(s))return{kind:"rejected",path:n,reason:"caminho inv\xE1lido p/ o workspace."};let i=Io(s);if(i.kind==="deny")return{kind:"rejected",path:s,reason:`bloqueado: ${i.why} \u2014 esse tipo de arquivo nunca \xE9 anexado ao contexto.`};if(i.kind==="ask"&&o.confirmSensitive!==!0)return{kind:"rejected",path:s,reason:`sens\xEDvel: ${i.why} \u2014 confirme explicitamente p/ anexar (fora do picker por padr\xE3o).`};try{if(await bP(r,this.sniffBytes))return{kind:"rejected",path:s,reason:"arquivo bin\xE1rio \u2014 n\xE3o anexado (conte\xFAdo n\xE3o \xE9 texto; evita lixo no contexto)."}}catch{}let a;try{a=await this.fs.readFile(s)}catch{return{kind:"rejected",path:s,reason:"n\xE3o foi poss\xEDvel ler o arquivo (sumiu/ileg\xEDvel)."}}let l=!1;return a.length>this.maxChars&&(a=a.slice(0,this.maxChars)+`
501
501
  [\u2026conte\xFAdo truncado: arquivo maior que ${this.maxChars} caracteres \u2014 s\xF3 o in\xEDcio foi anexado\u2026]`,l=!0),{kind:"ok",path:s,item:YC(s,a),truncated:l}}}});var uu=p(()=>{"use strict";_s();RS();fI();pI();gI()});function rh(t){return{kind:"deny",reason:t}}function WJ(t,e){return t.kind==="approve-session"&&e.alwaysAsk===!0?{kind:"approve-once"}:t}var sh,yI=p(()=>{"use strict";sh=class{observer=null;current=null;timeoutMs;setTimeoutFn;clearTimeoutFn;nonInteractive=!1;constructor(e={}){this.timeoutMs=e.timeoutMs??0,this.setTimeoutFn=e.setTimeoutFn??setTimeout,this.clearTimeoutFn=e.clearTimeoutFn??clearTimeout}setNonInteractive(e){this.nonInteractive=e}subscribe(e){this.observer=e,e(this.current)}get pending(){return this.current}resolve(e,o){return this.nonInteractive?Promise.resolve(rh("sess\xE3o n\xE3o-interativa (sem TTY) \u2014 aprova\xE7\xE3o indispon\xEDvel")):o?.aborted?Promise.resolve(rh("cancelado antes da confirma\xE7\xE3o")):new Promise(n=>{let r=!1,s,i=c=>{r||(r=!0,s&&this.clearTimeoutFn(s),o&&o.removeEventListener("abort",a),this.current=null,this.notify(),n(c))},a=()=>{i(rh("confirma\xE7\xE3o cancelada (abort/Ctrl-C)"))},l=c=>{i(WJ(c,e))};this.current={request:e,resolve:l},o&&o.addEventListener("abort",a,{once:!0}),this.timeoutMs>0&&(s=this.setTimeoutFn(()=>{i(rh("confirma\xE7\xE3o expirou sem resposta"))},this.timeoutMs),s.unref?.()),this.notify()})}notify(){this.observer?.(this.current)}}});function LS(t){return{kind:"unavailable",reason:t}}var ih,bI=p(()=>{"use strict";ih=class{observer=null;current=null;nonInteractive=!1;setNonInteractive(e){this.nonInteractive=e}subscribe(e){this.observer=e,e(this.current)}get pending(){return this.current}ask(e,o){return this.nonInteractive?Promise.resolve(LS("sess\xE3o n\xE3o-interativa (sem terminal)")):o?.aborted?Promise.resolve(LS("cancelado antes da pergunta")):new Promise(n=>{let r=!1,s=l=>{r||(r=!0,o&&o.removeEventListener("abort",i),this.current=null,this.notify(),n(l))},i=()=>{s(LS("pergunta cancelada (abort/Ctrl-C)"))},a=l=>s(l);this.current={spec:e,resolve:a},o&&o.addEventListener("abort",i,{once:!0}),this.notify()})}notify(){this.observer?.(this.current)}}});async function vI(t,e){if(t.length===0)return t;let o=e.timeoutMs??GJ,n=new AbortController,r=o>0?setTimeout(()=>n.abort(),o):void 0,s=()=>n.abort();e.signal?.addEventListener("abort",s,{once:!0}),e.signal?.aborted&&n.abort();try{let i=await Hp(e.baseUrl,"/v1/compress",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({messages:t,model:e.model??"claude-3-5-sonnet"}),signal:n.signal},{...e.resolver?{resolver:e.resolver}:{},...e.fetchFn?{fetchFn:e.fetchFn}:{}});if(!i.ok)return e.onRefused?.(i.reason),t;let a=i.response;if(!a.ok)return t;let l=await a.json(),c=l.messages;if(!Array.isArray(c)||c.length!==t.length)return t;for(let d=0;d<t.length;d++){let m=t[d],u=c[d];if(u===void 0)return t;if(u.role!==void 0&&u.role!==m.role)return e.onRefused?.(`proxy adulterou o role da mensagem ${d} (${String(u.role)})`),t;if(u.tool_calls!==void 0&&m.tool_calls===void 0)return e.onRefused?.(`proxy injetou tool_calls na mensagem ${d}`),t;if(u.tool_call_id!==void 0&&m.tool_call_id===void 0)return e.onRefused?.(`proxy injetou tool_call_id na mensagem ${d}`),t}return e.onSavings?.({before:l.tokens_before??0,after:l.tokens_after??0,ratio:l.compression_ratio??1}),t.map((d,m)=>{let u=c[m]?.content;return typeof u=="string"&&d.content!==""&&u!==d.content?{...d,content:u}:d})}catch{return t}finally{r!==void 0&&clearTimeout(r),e.signal?.removeEventListener("abort",s)}}var GJ,kI=p(()=>{"use strict";Yx();GJ=2500});var ah,xI=p(()=>{"use strict";P();kI();ah=class{client;opts;brokerSessionId;currentTier;nativeTools;customModel;customProvider;reasoningEffort;headroomRefusedWarned=!1;constructor(e){this.client=e.client,this.opts=e,this.brokerSessionId=e.sessionId,this.currentTier=e.tier,this.customModel=e.model,this.customProvider=e.tier==="custom"&&e.model!==void 0?e.provider:void 0,this.reasoningEffort=e.effort,this.nativeTools=e.nativeTools}attachNativeTools(e){this.nativeTools=e}setTier(e,o){this.currentTier=e,this.customModel=e==="custom"?o:void 0,this.customProvider=void 0}setProvider(e){this.customProvider=this.currentTier==="custom"&&this.customModel!==void 0?e:void 0}get tier(){return this.currentTier}get model(){return this.customModel}get provider(){return this.customProvider}setEffort(e){this.reasoningEffort=e}get effort(){return this.reasoningEffort}async call(e){let o=this.opts.headroomUrl,n=o===void 0?e:{...e,messages:await vI(e.messages,{baseUrl:o,...e.signal?{signal:e.signal}:{},onSavings:({before:r,after:s})=>{r>s&&process.stderr.write(`[headroom] mensagens comprimidas: ${r} \u2192 ${s} tokens (-${r-s})
502
502
  `)},onRefused:r=>{this.headroomRefusedWarned||(this.headroomRefusedWarned=!0,process.stderr.write(`[headroom] compress\xE3o DESLIGADA nesta sess\xE3o \u2014 ${r}. Rodando sem headroom (fail-open).
@@ -1,4 +1,4 @@
1
- var DN=Object.defineProperty;var S=(t,e,o)=>()=>{if(o)throw o[0];try{return t&&(e=t(t=0)),e}catch(n){throw o=[n],n}};var yp=(t,e)=>{for(var o in e)DN(t,o,{get:e[o],enumerable:!0})};var Ra,fS=S(()=>{"use strict";Ra="1.0.0-rc.65"});function Hn(t,e){return t.decide(e)}var is=S(()=>{"use strict"});var un,qn,Wn=S(()=>{"use strict";un="remember",qn="recall"});var bp,$N,ai,vp=S(()=>{"use strict";bp=class{id;horizon;label;parentId;children;dependencies;pinned;closed;createdAt;lastAccessedAt;accessCount;context;constructor(e,o,n,r,s){this.id=e,this.horizon=o,this.label=n,this.parentId=r,this.children=new Set,this.dependencies=new Set,this.pinned=!1,this.closed=!1,this.createdAt=s,this.lastAccessedAt=s,this.accessCount=0,this.context=[]}touch(e){this.lastAccessedAt=e,this.accessCount+=1}snapshot(){return{id:this.id,horizon:this.horizon,label:this.label,parentId:this.parentId,children:[...this.children],dependencies:[...this.dependencies],pinned:this.pinned,closed:this.closed,createdAt:this.createdAt,lastAccessedAt:this.lastAccessedAt,accessCount:this.accessCount,contextSize:this.context.length}}},$N=200,ai=class{nodes=new Map;maxBoxes;now;constructor(e){this.maxBoxes=e?.maxBoxes??$N,this.now=e?.clock??Date.now}static boxId(e,o){return`${e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)}-${o.toString(36)}`}openBox(e,o,n,r){let s=this.nodes.get(e);if(s)return s.touch(this.now()),{box:s.snapshot(),created:!1};if(this.nodes.size>=this.maxBoxes&&(this.evictOne(),this.nodes.size>=this.maxBoxes))return null;let i=this.now(),a=new bp(e,o,n,r??null,i);if(r){let c=this.nodes.get(r);c&&c.children.add(e)}return this.nodes.set(e,a),{box:a.snapshot(),created:!0}}closeBox(e){let o=this.nodes.get(e);return o?(o.closed=!0,o.touch(this.now()),o.snapshot()):null}isClosed(e){let o=this.nodes.get(e);return o?o.closed:!1}reopenBox(e){let o=this.nodes.get(e);return o?(o.closed=!1,o.touch(this.now()),o.snapshot()):null}setHorizon(e,o){let n=this.nodes.get(e);return n?(n.horizon=o,n.touch(this.now()),n.snapshot()):null}setParent(e,o){let n=this.nodes.get(e);return n?n.parentId===o?n.snapshot():o!==null&&this.wouldCreateCycle(e,o)?null:(n.parentId&&this.nodes.get(n.parentId)?.children.delete(e),n.parentId=o,o&&this.nodes.get(o)?.children.add(e),n.touch(this.now()),n.snapshot()):null}wouldCreateCycle(e,o){let n=new Set,r=o;for(;r!==null;){if(r===e||n.has(r))return!0;n.add(r),r=this.nodes.get(r)?.parentId??null}return!1}getBox(e){let o=this.nodes.get(e);return o?(o.touch(this.now()),o.snapshot()):null}listBoxes(e="lastAccessedAt"){let o=[...this.nodes.values()].map(n=>n.snapshot());switch(e){case"createdAt":return o.sort((n,r)=>n.createdAt-r.createdAt);case"accessCount":return o.sort((n,r)=>r.accessCount-n.accessCount);default:return o.sort((n,r)=>r.lastAccessedAt-n.lastAccessedAt)}}get size(){return this.nodes.size}addContext(e,o){let n=this.nodes.get(e);return n?(n.context.push({ts:this.now(),text:o}),n.touch(this.now()),n.snapshot()):null}getContext(e){let o=this.nodes.get(e);return o?(o.touch(this.now()),[...o.context]):[]}getContextChain(e){let o=[],n=new Set,r=e;for(;r&&!n.has(r);){n.add(r);let s=this.nodes.get(r);if(!s)break;s.touch(this.now()),o.push({boxId:s.id,entries:[...s.context]}),r=s.parentId}return o}addDependency(e,o){let n=this.nodes.get(e);return!n||!this.nodes.has(o)||n.id===o?!1:(n.dependencies.add(o),n.touch(this.now()),!0)}getDependencies(e){let o=this.nodes.get(e);return o?[...o.dependencies]:[]}pinBox(e){let o=this.nodes.get(e);return o?(o.pinned=!0,o.touch(this.now()),o.snapshot()):null}unpinBox(e){let o=this.nodes.get(e);return o?(o.pinned=!1,o.touch(this.now()),o.snapshot()):null}evictOne(){let e=[];for(let n of this.nodes.values())n.horizon==="longo"||n.pinned||e.push(n);if(e.length===0)return null;e.sort((n,r)=>{let s=n.horizon==="curto"?0:1,i=r.horizon==="curto"?0:1;if(s!==i)return s-i;let a=n.closed?0:1,c=r.closed?0:1;return a!==c?a-c:n.lastAccessedAt!==r.lastAccessedAt?n.lastAccessedAt-r.lastAccessedAt:n.accessCount-r.accessCount});let o=e[0];return this.removeNode(o)}forceEvict(e){let o=this.nodes.get(e);return!o||o.horizon==="longo"||o.pinned?null:this.removeNode(o)}removeBox(e){let o=this.nodes.get(e);return o?this.removeNode(o):null}removeNode(e){if(e.parentId){let o=this.nodes.get(e.parentId);o&&o.children.delete(e.id)}return this.nodes.delete(e.id),e.snapshot()}}});function Id(t){let e=[];for(let o of t){e.push({step:o,depth:0});for(let n of o.substeps??[])e.push({step:n,depth:1})}return e}function gS(t,e){let o,n="pending",r;if(typeof t=="string")o=t;else if(t!==null&&typeof t=="object"){let i=t,a=i.title??i.step??i.text??i.name??i.content;if(typeof a=="string"&&(o=a),typeof i.status=="string"&&FN.has(i.status)&&(n=i.status),e){let c=i.substeps??i.subtasks??i.subpassos??i.children;if(Array.isArray(c)&&c.length>0){let l=[];for(let d of c){let f=gS(d,!1);if(typeof f=="string")return f;l.push(f)}r=l}}}if(o===void 0||o.trim()==="")return UN;let s=o.trim().slice(0,BN);return r?{title:s,status:n,substeps:r}:{title:s,status:n}}function jN(t){let e=t.steps??t.plan??t.todos??t.items;if(!Array.isArray(e))return{error:'update_plan: passe "steps" como uma LISTA de passos (string ou {title,status}).'};if(e.length===0)return{error:"update_plan: a lista de passos est\xE1 vazia."};let o=[];for(let i of e){let a=gS(i,!0);if(typeof a=="string")return{error:a};o.push(a)}let n=new Set,r=i=>{if(!n.has(i))return n.add(i),i;for(let a=2;;a++){let c=`${i} #${a}`;if(!n.has(c))return n.add(c),c}};for(let i=0;i<o.length;i++){let a=o[i],c=r(a.title),l=a.substeps?.map(d=>({...d,title:r(d.title)}));o[i]=l!==void 0?{...a,title:c,substeps:l}:{...a,title:c}}let s=Id(o).length;return s>pS?{error:`update_plan: no m\xE1ximo ${pS} passos (recebidos ${s}).`}:{steps:o}}function HN(t){let e=Id(t),o=e.filter(r=>r.step.status==="completed").length,n=e.map(r=>`${" ".repeat(r.depth)}${yS[r.step.status]} ${r.step.title}`).join(`
1
+ var DN=Object.defineProperty;var S=(t,e,o)=>()=>{if(o)throw o[0];try{return t&&(e=t(t=0)),e}catch(n){throw o=[n],n}};var yp=(t,e)=>{for(var o in e)DN(t,o,{get:e[o],enumerable:!0})};var Ra,fS=S(()=>{"use strict";Ra="1.0.0-rc.66"});function Hn(t,e){return t.decide(e)}var is=S(()=>{"use strict"});var un,qn,Wn=S(()=>{"use strict";un="remember",qn="recall"});var bp,$N,ai,vp=S(()=>{"use strict";bp=class{id;horizon;label;parentId;children;dependencies;pinned;closed;createdAt;lastAccessedAt;accessCount;context;constructor(e,o,n,r,s){this.id=e,this.horizon=o,this.label=n,this.parentId=r,this.children=new Set,this.dependencies=new Set,this.pinned=!1,this.closed=!1,this.createdAt=s,this.lastAccessedAt=s,this.accessCount=0,this.context=[]}touch(e){this.lastAccessedAt=e,this.accessCount+=1}snapshot(){return{id:this.id,horizon:this.horizon,label:this.label,parentId:this.parentId,children:[...this.children],dependencies:[...this.dependencies],pinned:this.pinned,closed:this.closed,createdAt:this.createdAt,lastAccessedAt:this.lastAccessedAt,accessCount:this.accessCount,contextSize:this.context.length}}},$N=200,ai=class{nodes=new Map;maxBoxes;now;constructor(e){this.maxBoxes=e?.maxBoxes??$N,this.now=e?.clock??Date.now}static boxId(e,o){return`${e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)}-${o.toString(36)}`}openBox(e,o,n,r){let s=this.nodes.get(e);if(s)return s.touch(this.now()),{box:s.snapshot(),created:!1};if(this.nodes.size>=this.maxBoxes&&(this.evictOne(),this.nodes.size>=this.maxBoxes))return null;let i=this.now(),a=new bp(e,o,n,r??null,i);if(r){let c=this.nodes.get(r);c&&c.children.add(e)}return this.nodes.set(e,a),{box:a.snapshot(),created:!0}}closeBox(e){let o=this.nodes.get(e);return o?(o.closed=!0,o.touch(this.now()),o.snapshot()):null}isClosed(e){let o=this.nodes.get(e);return o?o.closed:!1}reopenBox(e){let o=this.nodes.get(e);return o?(o.closed=!1,o.touch(this.now()),o.snapshot()):null}setHorizon(e,o){let n=this.nodes.get(e);return n?(n.horizon=o,n.touch(this.now()),n.snapshot()):null}setParent(e,o){let n=this.nodes.get(e);return n?n.parentId===o?n.snapshot():o!==null&&this.wouldCreateCycle(e,o)?null:(n.parentId&&this.nodes.get(n.parentId)?.children.delete(e),n.parentId=o,o&&this.nodes.get(o)?.children.add(e),n.touch(this.now()),n.snapshot()):null}wouldCreateCycle(e,o){let n=new Set,r=o;for(;r!==null;){if(r===e||n.has(r))return!0;n.add(r),r=this.nodes.get(r)?.parentId??null}return!1}getBox(e){let o=this.nodes.get(e);return o?(o.touch(this.now()),o.snapshot()):null}listBoxes(e="lastAccessedAt"){let o=[...this.nodes.values()].map(n=>n.snapshot());switch(e){case"createdAt":return o.sort((n,r)=>n.createdAt-r.createdAt);case"accessCount":return o.sort((n,r)=>r.accessCount-n.accessCount);default:return o.sort((n,r)=>r.lastAccessedAt-n.lastAccessedAt)}}get size(){return this.nodes.size}addContext(e,o){let n=this.nodes.get(e);return n?(n.context.push({ts:this.now(),text:o}),n.touch(this.now()),n.snapshot()):null}getContext(e){let o=this.nodes.get(e);return o?(o.touch(this.now()),[...o.context]):[]}getContextChain(e){let o=[],n=new Set,r=e;for(;r&&!n.has(r);){n.add(r);let s=this.nodes.get(r);if(!s)break;s.touch(this.now()),o.push({boxId:s.id,entries:[...s.context]}),r=s.parentId}return o}addDependency(e,o){let n=this.nodes.get(e);return!n||!this.nodes.has(o)||n.id===o?!1:(n.dependencies.add(o),n.touch(this.now()),!0)}getDependencies(e){let o=this.nodes.get(e);return o?[...o.dependencies]:[]}pinBox(e){let o=this.nodes.get(e);return o?(o.pinned=!0,o.touch(this.now()),o.snapshot()):null}unpinBox(e){let o=this.nodes.get(e);return o?(o.pinned=!1,o.touch(this.now()),o.snapshot()):null}evictOne(){let e=[];for(let n of this.nodes.values())n.horizon==="longo"||n.pinned||e.push(n);if(e.length===0)return null;e.sort((n,r)=>{let s=n.horizon==="curto"?0:1,i=r.horizon==="curto"?0:1;if(s!==i)return s-i;let a=n.closed?0:1,c=r.closed?0:1;return a!==c?a-c:n.lastAccessedAt!==r.lastAccessedAt?n.lastAccessedAt-r.lastAccessedAt:n.accessCount-r.accessCount});let o=e[0];return this.removeNode(o)}forceEvict(e){let o=this.nodes.get(e);return!o||o.horizon==="longo"||o.pinned?null:this.removeNode(o)}removeBox(e){let o=this.nodes.get(e);return o?this.removeNode(o):null}removeNode(e){if(e.parentId){let o=this.nodes.get(e.parentId);o&&o.children.delete(e.id)}return this.nodes.delete(e.id),e.snapshot()}}});function Id(t){let e=[];for(let o of t){e.push({step:o,depth:0});for(let n of o.substeps??[])e.push({step:n,depth:1})}return e}function gS(t,e){let o,n="pending",r;if(typeof t=="string")o=t;else if(t!==null&&typeof t=="object"){let i=t,a=i.title??i.step??i.text??i.name??i.content;if(typeof a=="string"&&(o=a),typeof i.status=="string"&&FN.has(i.status)&&(n=i.status),e){let c=i.substeps??i.subtasks??i.subpassos??i.children;if(Array.isArray(c)&&c.length>0){let l=[];for(let d of c){let f=gS(d,!1);if(typeof f=="string")return f;l.push(f)}r=l}}}if(o===void 0||o.trim()==="")return UN;let s=o.trim().slice(0,BN);return r?{title:s,status:n,substeps:r}:{title:s,status:n}}function jN(t){let e=t.steps??t.plan??t.todos??t.items;if(!Array.isArray(e))return{error:'update_plan: passe "steps" como uma LISTA de passos (string ou {title,status}).'};if(e.length===0)return{error:"update_plan: a lista de passos est\xE1 vazia."};let o=[];for(let i of e){let a=gS(i,!0);if(typeof a=="string")return{error:a};o.push(a)}let n=new Set,r=i=>{if(!n.has(i))return n.add(i),i;for(let a=2;;a++){let c=`${i} #${a}`;if(!n.has(c))return n.add(c),c}};for(let i=0;i<o.length;i++){let a=o[i],c=r(a.title),l=a.substeps?.map(d=>({...d,title:r(d.title)}));o[i]=l!==void 0?{...a,title:c,substeps:l}:{...a,title:c}}let s=Id(o).length;return s>pS?{error:`update_plan: no m\xE1ximo ${pS} passos (recebidos ${s}).`}:{steps:o}}function HN(t){let e=Id(t),o=e.filter(r=>r.step.status==="completed").length,n=e.map(r=>`${" ".repeat(r.depth)}${yS[r.step.status]} ${r.step.title}`).join(`
2
2
  `);return`plano (${o}/${e.length}):
3
3
  ${n}`}function WN(t,e){return e<0?"m\xE9dio":t===e?"curto":t>e?"longo":"m\xE9dio"}function GN(t,e){let o=new Map;for(let i of e.listBoxes())o.set(i.label,i.id);let n=t.findIndex(i=>i.status==="in_progress"||(i.substeps??[]).some(a=>a.status==="in_progress")),r=(i,a,c)=>{let l=i.status==="in_progress"?"curto":c,d=o.get(i.title),f=d??ai.boxId(i.title,0);return d?(i.status!=="completed"&&e.isClosed(d)&&e.reopenBox(d),e.setHorizon(d,l),e.setParent(d,a)):e.openBox(f,l,i.title,a),i.status==="completed"&&!e.isClosed(f)&&e.closeBox(f),o.set(i.title,f),f};t.forEach((i,a)=>{let c=WN(a,n),l=r(i,null,c);for(let d of i.substeps??[])r(d,l,c)});let s=new Set;for(let i of t){s.add(i.title);for(let a of i.substeps??[])s.add(a.title)}for(let i of e.listBoxes())s.has(i.label)||e.removeBox(i.id)}function zN(t,e){if(!e)return HN(t);let o=new Map;for(let l of e.listBoxes())o.set(l.label,l);let n=new Map;for(let l of e.listBoxes())n.set(l.id,l);let r=new Map,s=(l,d=new Set)=>{let f=r.get(l);if(f!==void 0)return f;let u=n.get(l);if(!u||!u.parentId||d.has(l))return r.set(l,0),0;let p=s(u.parentId,new Set(d).add(l))+1;return r.set(l,p),p},i=Id(t),c=[`plano (${i.filter(l=>l.step.status==="completed").length}/${i.length}):`];for(let{step:l,depth:d}of i){let f=o.get(l.title),u=f?qN[f.horizon]:"",p=f?s(f.id):d,g=" ".repeat(p),y=yS[l.status];c.push(`${g}${u} ${y} ${l.title}`)}return c.join(`
4
4
  `)}var Oa,FN,pS,BN,UN,yS,qN,hS,KN,bS,Nd=S(()=>{"use strict";vp();Oa="update_plan";FN=new Set(["pending","in_progress","completed"]),pS=30,BN=120,UN="update_plan: cada passo precisa de um t\xEDtulo (texto) n\xE3o-vazio.";yS={pending:"\u2610",in_progress:"\u25B6",completed:"\u2611"};qN={longo:"[\u{1F4D0}]",m\u00E9dio:"[\u{1F4CB}]",curto:"[\u{1F4CC}]"};hS=Object.freeze({type:"string",enum:["pending","in_progress","completed"],description:"pending (a fazer) \xB7 in_progress (em curso) \xB7 completed (feito)."}),KN=Object.freeze({type:"object",properties:{steps:{type:"array",description:"A lista COMPLETA de passos do plano (re-emita TODOS a cada atualiza\xE7\xE3o \u2014 substitui o anterior).",items:{type:"object",properties:{title:{type:"string",description:"O passo, curto e no imperativo."},status:hS,substeps:{type:"array",description:"OPCIONAL: sub-passos que detalham este passo (1 n\xEDvel). Aparecem indentados sob o passo e seguem o foco dele. Use quando um passo tem a\xE7\xF5es menores distintas.",items:{type:"object",properties:{title:{type:"string",description:"O sub-passo, curto e no imperativo."},status:hS},required:["title"],additionalProperties:!1}}},required:["title"],additionalProperties:!1}}},required:["steps"],additionalProperties:!1}),bS={name:Oa,effect:"read",description:"Declara/atualiza um PLANO vis\xEDvel (checklist de passos). Use ao iniciar uma tarefa com V\xC1RIOS passos e a cada progresso: re-emita a lista TODA marcando o status de cada passo (pending/in_progress/completed). Mantenha 1 passo in_progress por vez. N\xE3o tem efeito no sistema \u2014 \xE9 s\xF3 o seu plano, para voc\xEA e para o usu\xE1rio acompanharem.",parameters:KN,async run(t,e){let o=jN(t);return"error"in o?{ok:!1,observation:o.error}:(e.graph&&GN(o.steps,e.graph),e.plan&&e.plan.set(Id(o.steps).map(r=>({title:r.step.title,status:r.step.status}))),{ok:!0,observation:zN(o.steps,e.graph)})}}});function vS(t){let e=t.question??t.prompt??t.text??t.message;if(typeof e!="string"||e.trim()==="")return{error:'perguntar: passe "question" (a pergunta em texto). Para escolha, passe tamb\xE9m "options".'};let o=e.trim().slice(0,2e3),n=t.header??t.title,r=typeof n=="string"&&n.trim()!==""?n.trim().slice(0,200):void 0,s=t.options??t.choices,i=Array.isArray(s)?VN(s):void 0;if(typeof i=="string")return{error:i};let a,c=t.kind??t.type;if(typeof c=="string"&&YN.has(c))a=c;else{if(typeof c=="string"&&c.trim()!=="")return{error:`perguntar: "kind" inv\xE1lido "${c}". Use "single", "multi" ou "text".`};a=i!==void 0&&i.length>0?"single":"text"}if((a==="single"||a==="multi")&&(i===void 0||i.length===0))return{error:`perguntar: kind "${a}" requer "options" (uma lista de ao menos 1 op\xE7\xE3o).`};let l=t.allowOther!==!1;return{spec:{kind:a,question:o,...r!==void 0?{header:r}:{},...a!=="text"&&i!==void 0?{options:i}:{},...a!=="text"?{allowOther:l}:{}}}}function VN(t){if(t.length===0)return'perguntar: a lista de "options" est\xE1 vazia.';if(t.length>12)return`perguntar: no m\xE1ximo 12 op\xE7\xF5es (recebidas ${t.length}).`;let e=[];for(let o of t){let n,r;if(typeof o=="string")n=o;else if(o!==null&&typeof o=="object"){let s=o,i=s.label??s.text??s.value??s.name??s.title;typeof i=="string"&&(n=i),typeof s.description=="string"&&s.description.trim()!==""&&(r=s.description.trim().slice(0,300))}if(n===void 0||n.trim()==="")return'perguntar: cada op\xE7\xE3o precisa de um "label" (texto) n\xE3o-vazio.';e.push({label:n.trim().slice(0,200),...r!==void 0?{description:r}:{}})}return e}function XN(t){switch(t.kind){case"choice":return t.label;case"choices":return t.labels.length===0?"(nenhuma)":t.labels.join(", ");case"text":{let e=t.text.split(`
@@ -137,7 +137,7 @@ ${t.trim()}`}}function p_(t,e,o=qc){let{older:n,recent:r}=om(t,o);if(n.length===
137
137
  \u2026[truncado: ${t.length-gb} chars omitidos]`}function $1(t){return t.length<=bb?t:`${t.slice(0,bb)}\u2026`}function Q_(t){let e=J_(t.server,t.descriptor.name),o=$1(t.descriptor.description.trim()),n=`[tool de um SERVER MCP de terceiro "${t.server}" \u2014 efeito n\xE3o-confi\xE1vel, passa pela catraca] ${o||"(sem descri\xE7\xE3o)"}`,r=t.descriptor.inputSchema,s=r!==null&&typeof r=="object"&&!Array.isArray(r)?r:void 0;return{name:e,effect:"mcp",description:n,...s?{parameters:s}:{},async run(i,a,c){try{let l=await t.transport.callTool(t.descriptor.name,i,c?.signal),d=Fe(l.content);return l.ok?{ok:!0,observation:X_(d),display:`${e}(${F1(i)})`}:{ok:!1,observation:X_(`MCP "${e}" erro: ${d}`)}}catch(l){return{ok:!1,observation:`MCP "${e}" falhou: ${l instanceof Error?l.message:String(l)}`}}}}}function vb(t,e){let o=[],n=new Set,r=new Map,s=new Map,i=new Set;for(let a of t){let c=Q_(a);if(n.has(c.name))continue;n.add(c.name);let l=a.server;s.set(l,(s.get(l)??0)+1);let d=r.get(l)??0;if(d>=yb){i.add(l);continue}r.set(l,d+1),o.push(c)}if(e)for(let a of i){let c=s.get(a)??0;e(`server MCP "${a}" exp\xF4s ${c} tools; usando as primeiras ${yb} (teto por server, anti-estouro de contexto). As demais foram ignoradas \u2014 revise o server ou reduza as tools que ele exp\xF5e.`)}return o}function F1(t){if(Object.keys(t).length===0)return"";let o=JSON.stringify(t);return o.length<=200?o:`${o.slice(0,200)}\u2026`}var gb,yb,bb,Z_=S(()=>{"use strict";Fd();Vn();gb=2e4;yb=128,bb=1024});function oC(t,e){let o=new URL(tC);return t.trim().length>0&&o.searchParams.set("search",t.trim()),o.searchParams.set("limit",String(U1)),e!==void 0&&e.length>0&&o.searchParams.set("cursor",e),o.toString()}async function xb(t,e,o){let n=t.trim(),r=[],s;for(let i=0;i<B1;i++){let a=oC(n,s),c;try{c=await e(a,o)}catch(f){return{ok:!1,query:n,reason:um(z1(f))}}if(!c.ok)return{ok:!1,query:n,reason:um(c.reason)};if(c.status<200||c.status>=300)return{ok:!1,query:n,reason:um(`HTTP ${c.status}`)};let l;try{l=JSON.parse(c.body)}catch{return{ok:!1,query:n,reason:um("resposta n\xE3o \xE9 JSON v\xE1lido")}}let d=rC(l);for(let f of d.servers)if(nC(f,n)&&r.push(f),r.length>=kb)break;if(r.length>=kb||(s=d.nextCursor,s===void 0||s.length===0))break}return{ok:!0,query:n,results:r}}function um(t){return`registro MCP indispon\xEDvel (${Di}): ${t}`}function nC(t,e){if(e.length===0)return!0;let o=e.toLowerCase();return[t.name,t.title??"",t.description,t.run.command??"",t.run.args.join(" ")].join(" ").toLowerCase().includes(o)}function rC(t){if(!Zn(t))return{servers:[]};let e=Array.isArray(t.servers)?t.servers:[],o=[];for(let s of e){let i=j1(s);i!==void 0&&o.push(i)}let n=Zn(t.metadata)?t.metadata:void 0,r=n!==void 0&&typeof n.nextCursor=="string"?n.nextCursor:void 0;return{servers:o,...r!==void 0?{nextCursor:r}:{}}}function j1(t){if(!Zn(t))return;let e=Zn(t.server)?t.server:t,o=typeof e.name=="string"?e.name.trim():"";if(o.length===0)return;let n=typeof e.description=="string"?e.description.trim():"",r=typeof e.title=="string"&&e.title.trim().length>0?e.title.trim():void 0,s=typeof e.version=="string"?e.version.trim():void 0,i=H1(e);return{name:o,description:n,run:i,...r!==void 0?{title:r}:{},...s!==void 0?{version:s}:{}}}function H1(t){let e=[],o=Array.isArray(t.remotes)?t.remotes:[];for(let r of o)Zn(r)&&typeof r.url=="string"&&e.push(r.url);let n=Array.isArray(t.packages)?t.packages:[];for(let r of n){if(!Zn(r))continue;let s=q1(r);if(s!==void 0)return{...s,remoteUrls:e}}return{args:[],env:[],remoteUrls:e}}function q1(t){let e=Ts(t.registryType)??Ts(t.registry_name),o=Ts(t.identifier)??Ts(t.name);if(o===void 0)return;let n=Ts(t.version),r=Ts(t.runtimeHint),s=Zn(t.transport)?Ts(t.transport.type):void 0,i=G1(t.environmentVariables),a=eC(t.runtimeArguments),c=eC(t.packageArguments),l=n!==void 0?`${o}@${n}`:o;return e==="npm"||r==="npx"?{command:"npx",args:W1(["-y",...a,l,...c]),env:i,...s!==void 0?{transport:s}:{}}:e==="pypi"||r==="uvx"||r==="uv"?{command:"uvx",args:[...a,o,...c],env:i,...s!==void 0?{transport:s}:{}}:e==="oci"||r==="docker"?{command:"docker",args:["run","-i","--rm",...a,l,...c],env:i,...s!==void 0?{transport:s}:{}}:{args:[l],env:i,...s!==void 0?{transport:s}:{}}}function W1(t){let e=[],o=!1;for(let n of t){if(n==="-y"||n==="--yes"){if(o)continue;o=!0}e.push(n)}return e}function eC(t){if(!Array.isArray(t))return[];let e=[];for(let o of t)Zn(o)&&typeof o.value=="string"&&e.push(o.value);return e}function G1(t){if(!Array.isArray(t))return[];let e=[];for(let o of t)Zn(o)&&typeof o.name=="string"&&o.name.length>0&&e.push({name:o.name,required:o.isRequired===!0});return e}function Ts(t){return typeof t=="string"&&t.trim().length>0?t.trim():void 0}function Zn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function z1(t){return t instanceof Error?t.message:String(t)}var Di,tC,B1,U1,kb,sC=S(()=>{"use strict";Di="registry.modelcontextprotocol.io",tC=`https://${Di}/v0/servers`,B1=5,U1=100,kb=25});function aC(t){let{command:e,args:o}=t.run;if(e===void 0)return;let n=cC(t.name);return["aluy","mcp","add",iC(n),"--",e,...o.map(iC)].join(" ")}function cC(t){let o=(t.split("/").pop()??t).replace(/[^A-Za-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"");return o.length>0?o:"server"}function iC(t){return/^[A-Za-z0-9_./@:+=-]+$/.test(t)?t:`'${t.replace(/'/g,"'\\''")}'`}function Sb(t){if(!t.ok)return`\u26A0 ${t.reason}
138
138
  Tente de novo em instantes; a busca no registro n\xE3o bloqueia o resto do aluy.`;if(t.results.length===0)return`nenhum server encontrado para "${t.query}" no registro oficial MCP.`;let e=[],o=t.results.length;e.push(`${o} server${o===1?"":"s"} para "${t.query}" (registro oficial MCP):`),e.push("");for(let n of t.results)e.push(K1(n)),e.push("");return e.push('Para instalar, copie a linha "\u2192 aluy mcp add \u2026" do server desejado.'),e.push("A sa\xEDda do registro \xE9 apenas informativa \u2014 nada \xE9 executado pela busca."),e.join(`
139
139
  `)}function K1(t){let o=[`\u2022 ${t.version!==void 0?`${t.name} (v${t.version})`:t.name}`],n=t.title!==void 0&&t.title!==t.name?t.title:void 0;n!==void 0&&o.push(` ${n}`),t.description.length>0&&o.push(` ${Y1(t.description,200)}`);let r=aC(t);if(r!==void 0){o.push(` \u2192 ${r}`),t.run.transport!==void 0&&t.run.transport!=="stdio"&&o.push(` (transporte "${t.run.transport}" \u2014 v1 do aluy s\xF3 pluga servers stdio LOCAIS)`);let s=t.run.env.filter(i=>i.required).map(i=>i.name);s.length>0&&o.push(` requer env: ${s.join(", ")} (defina por-server no mcp.json)`)}else t.run.remoteUrls.length>0?o.push(` (server REMOTO: ${t.run.remoteUrls.join(", ")} \u2014 fora do v1 de \`aluy mcp add\`)`):o.push(" (sem pacote local conhecido \u2014 nada a instalar pelo aluy)");return o.join(`
140
- `)}function Y1(t,e){return t.length<=e?t:t.slice(0,e-1).trimEnd()+"\u2026"}var lC=S(()=>{"use strict"});var dC=S(()=>{"use strict";dm();W_();G_();z_();K_();V_();Z_();Fd();sC();lC()});function wb(t){let e=/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?/.exec(t.trim());if(!e)return null;let o=e[4]?e[4].split(".").map(n=>/^\d+$/.test(n)?Number(n):n):[];return{major:Number(e[1]),minor:Number(e[2]),patch:Number(e[3]),pre:o}}function uC(t,e){let o=wb(t),n=wb(e);if(!o||!n)return null;for(let s of["major","minor","patch"])if(o[s]!==n[s])return o[s]<n[s]?-1:1;if(o.pre.length===0&&n.pre.length===0)return 0;if(o.pre.length===0)return 1;if(n.pre.length===0)return-1;let r=Math.max(o.pre.length,n.pre.length);for(let s=0;s<r;s++){let i=o.pre[s],a=n.pre[s];if(i===void 0)return-1;if(a===void 0)return 1;if(i===a)continue;let c=typeof i=="number",l=typeof a=="number";return c&&l?i<a?-1:1:c?-1:l?1:i<a?-1:1}return 0}function Ab(t,e){return uC(t,e)===1}var mC=S(()=>{"use strict"});function mm(t,e,o){if(e.size===0)return{kind:"discard",reason:"allowlist vazia (default fechado)"};if(!e.has(t.conversation))return{kind:"discard",reason:`canal ${t.conversation} n\xE3o-allowlistado`};if(t.senderIsBot===!0)return{kind:"discard",reason:"remetente \xE9 bot (anti-loop, TC-6)"};let n=t.content.trim();if(n==="")return{kind:"discard",reason:"mensagem sem conte\xFAdo"};if(o.authIsForgeable)return{kind:"data",text:n};if(t.provenance.kind==="third-party-relayed")return{kind:"data",text:n};let r=t.provenance.embeddedThirdParty?.trim();return r?{kind:"instruction",text:n,forwardedData:r}:{kind:"instruction",text:n}}var Eb=S(()=>{"use strict"});function Tb(t){let e;if(t.forwarded===!0)e={kind:"third-party-relayed"};else{let o=(t.quotedText??"").trim();e=o?{kind:"author-direct",embeddedThirdParty:o}:{kind:"author-direct"}}return{content:t.text,sender:String(t.fromId),conversation:String(t.chatId),provenance:e,...t.isBot===!0?{senderIsBot:!0}:{}}}function _b(t){let e=new Set;for(let o of t)typeof o=="number"&&Number.isFinite(o)&&Number.isInteger(o)&&e.add(o);return e}var Jc,fC=S(()=>{"use strict";Eb();Jc={id:"telegram",displayName:"Telegram",authIsForgeable:!1}});function Cb(t){return typeof t=="number"&&Number.isFinite(t)?t:void 0}function $i(t){return typeof t=="object"&&t!==null?t:void 0}function Rb(t,e){let o=$i(t);if(!o||o.ok!==!0||!Array.isArray(o.result))return{updates:[],nextOffset:e};let n=[],r=e-1;for(let s of o.result){let i=$i(s);if(!i)continue;let a=Cb(i.update_id);a!==void 0&&a>r&&(r=a);let c=$i(i.message);if(!c)continue;let l=$i(c.chat),d=Cb(l?.id);if(d===void 0||l?.type!=="private")continue;let f=$i(c.from),u=Cb(f?.id)??d,p=f?.is_bot===!0,g=typeof c.text=="string"?c.text:"",y=c.forward_origin!==void 0||c.forward_from!==void 0||c.forward_from_chat!==void 0||c.forward_sender_name!==void 0||c.forward_date!==void 0,h=(()=>{let w=$i(c.quote)?.text;return typeof w=="string"&&w.trim()!==""?w:void 0})();n.push({chatId:d,fromId:u,text:g,...y?{forwarded:!0}:{},...h!==void 0?{quotedText:h}:{},...p?{isBot:!0}:{}})}return{updates:n,nextOffset:r+1}}var pC=S(()=>{"use strict"});var Qc,hC=S(()=>{"use strict";Qc=class{maxPerWindow;windowMs;stamps=[];constructor(e,o){this.maxPerWindow=e,this.windowMs=o}tryConsume(e){let o=e-this.windowMs;for(;this.stamps.length>0&&this.stamps[0]<=o;)this.stamps.shift();return this.stamps.length>=this.maxPerWindow?!1:(this.stamps.push(e),!0)}get used(){return this.stamps.length}}});function Ob(t){return`connector-${t}-token`}function Zc(t){let e=t.trim(),o=e.indexOf(":");return o<=0?`\u2026(${e.length} chars)`:`${e.slice(0,o)}:\u2026(${e.length-o-1} chars)`}function Mb(t,e){let o=e.trim();return o.length<8?t:t.split(o).join("\xABREDACTED\xBB")}var gC=S(()=>{"use strict"});var U=S(()=>{"use strict";fS();NS();KS();mA();P_();Ty();j_();dC();nb();ju();mC();Eb();fC();pC();hC();gC()});import{posix as fH}from"node:path";function pH(t){return fH.normalize(t)}function uo(t){let e=pH(t);for(let o of hH)if(o.re.test(e))return o.deny?{kind:"deny",why:o.why}:{kind:"ask",why:o.why};return{kind:"allow"}}function Vb(t){return uo(t).kind==="allow"}var hH,Nr=S(()=>{"use strict";hH=[{re:/(?:^|\/|~\/)\.ssh(?:\/|$)/,why:"chaves SSH (~/.ssh)",deny:!0},{re:/(?:^|\/|~\/)\.aws(?:\/|$)/,why:"credenciais AWS (~/.aws)",deny:!0},{re:/(?:^|\/|~\/)\.gnupg(?:\/|$)/,why:"chaves GPG (~/.gnupg)",deny:!0},{re:/(?:~\/|\$\{?HOME\}?\/|\/(?:home|Users)\/[^/]+\/)\.aluy\/rooms(?:\/|$)/,why:"arquivos de sala do Aluy (~/.aluy/rooms)",deny:!0},{re:/~\/\.aluy(?:\/|$)/,why:"estado/credencial do Aluy (~/.aluy)",deny:!0},{re:/(?:^|\/)\.aluy(?:\/(?!agents\/|workflows\/|commands\/)|$)/,why:"estado/credencial do Aluy (.aluy/)",deny:!0},{re:/(?:^|\/|~\/)\.config\/gh\/hosts\.yml$/,why:"token do gh CLI",deny:!0},{re:/(?:^|\/|~\/)\.docker\/config\.json$/,why:"credenciais Docker",deny:!0},{re:/(?:^|\/|~\/)\.kube\/config$/,why:"kubeconfig",deny:!0},{re:/(?:^|\/)id_(?:rsa|ed25519|ecdsa|dsa)\b/,why:"chave privada",deny:!0},{re:/\.pem$|\.p12$|\.pfx$|\.key$/i,why:"material de chave privada",deny:!0},{re:/(?:^|[/\w.-])\.env(?:\.(?!example$|sample$|template$|dist$)[\w.-]+)?$/,why:"arquivo .env (segredos)",deny:!1},{re:/(?:^|\/)[^/]*(?:secret|credential|token|apikey|api_key|password|passwd)[^/]*$/i,why:"arquivo com nome sens\xEDvel (token/secret)",deny:!1}]});var bv={};yp(bv,{UserWorkflowsLoader:()=>Br,WORKFLOWS_DIRNAME:()=>yv});import{homedir as eW}from"node:os";import{join as gv}from"node:path";import{readdirSync as tW,readFileSync as oW,mkdirSync as nW,statSync as rW}from"node:fs";var sW,yv,iW,aW,Br,Mm=S(()=>{"use strict";U();sW=448,yv="workflows",iW=64*1024,aW=256,Br=class{dir;constructor(e={}){let o=e.baseDir??gv(eW(),".aluy");this.dir=gv(o,yv)}get workflowsDir(){return this.dir}ensureDir(){try{nW(this.dir,{mode:sW,recursive:!0})}catch{}}load(){let e;try{e=tW(this.dir,{withFileTypes:!0})}catch{return{workflows:[],errors:[]}}let o=e.filter(i=>i.isFile()&&i.name.toLowerCase().endsWith(".md")).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=aW)break;let a=this.readOne(i);if(a!==null){if(Rc(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{workflows:r,errors:s}}readOne(e){let o=gv(this.dir,e);try{let n=rW(o);if(!n.isFile()||n.size>iW)return null;let r=oW(o,"utf8");return Oc(e,r,"global")}catch{return null}}}});var kv={};yp(kv,{PROJECT_WORKFLOWS_DIRNAMES:()=>vv,ProjectWorkflowsLoader:()=>Ur});import{join as cW}from"node:path";import{readdirSync as lW,readFileSync as dW,statSync as uW}from"node:fs";var vv,mW,fW,Ur,Lm=S(()=>{"use strict";U();Nr();vv=[".claude/workflows",".aluy/workflows"],mW=64*1024,fW=256,Ur=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of vv){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=lW(s,{withFileTypes:!0})}catch{continue}let a=i.filter(c=>c.isFile()&&c.name.toLowerCase().endsWith(".md")).map(c=>c.name).sort((c,l)=>c.localeCompare(l));for(let c of a){if(o.length>=fW)break;let l=this.readOne(r,s,c);if(l!==null){if(Rc(l)){n.push(l);continue}e.has(l.name)||(e.add(l.name),o.push(l))}}}return{workflows:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}`;if(uo(r).kind!=="allow")return null;let s=cW(o,n);try{this.workspace.resolveInside(r);let i=uW(s);if(!i.isFile()||i.size>mW)return null;let a=dW(s,"utf8");return Oc(n,a,"project")}catch{return null}}}});var jn="1.0.0-rc.65";U();var yC=`aluy \u2014 agente de terminal que roda na sua m\xE1quina, com o seu provider de LLM
140
+ `)}function Y1(t,e){return t.length<=e?t:t.slice(0,e-1).trimEnd()+"\u2026"}var lC=S(()=>{"use strict"});var dC=S(()=>{"use strict";dm();W_();G_();z_();K_();V_();Z_();Fd();sC();lC()});function wb(t){let e=/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?/.exec(t.trim());if(!e)return null;let o=e[4]?e[4].split(".").map(n=>/^\d+$/.test(n)?Number(n):n):[];return{major:Number(e[1]),minor:Number(e[2]),patch:Number(e[3]),pre:o}}function uC(t,e){let o=wb(t),n=wb(e);if(!o||!n)return null;for(let s of["major","minor","patch"])if(o[s]!==n[s])return o[s]<n[s]?-1:1;if(o.pre.length===0&&n.pre.length===0)return 0;if(o.pre.length===0)return 1;if(n.pre.length===0)return-1;let r=Math.max(o.pre.length,n.pre.length);for(let s=0;s<r;s++){let i=o.pre[s],a=n.pre[s];if(i===void 0)return-1;if(a===void 0)return 1;if(i===a)continue;let c=typeof i=="number",l=typeof a=="number";return c&&l?i<a?-1:1:c?-1:l?1:i<a?-1:1}return 0}function Ab(t,e){return uC(t,e)===1}var mC=S(()=>{"use strict"});function mm(t,e,o){if(e.size===0)return{kind:"discard",reason:"allowlist vazia (default fechado)"};if(!e.has(t.conversation))return{kind:"discard",reason:`canal ${t.conversation} n\xE3o-allowlistado`};if(t.senderIsBot===!0)return{kind:"discard",reason:"remetente \xE9 bot (anti-loop, TC-6)"};let n=t.content.trim();if(n==="")return{kind:"discard",reason:"mensagem sem conte\xFAdo"};if(o.authIsForgeable)return{kind:"data",text:n};if(t.provenance.kind==="third-party-relayed")return{kind:"data",text:n};let r=t.provenance.embeddedThirdParty?.trim();return r?{kind:"instruction",text:n,forwardedData:r}:{kind:"instruction",text:n}}var Eb=S(()=>{"use strict"});function Tb(t){let e;if(t.forwarded===!0)e={kind:"third-party-relayed"};else{let o=(t.quotedText??"").trim();e=o?{kind:"author-direct",embeddedThirdParty:o}:{kind:"author-direct"}}return{content:t.text,sender:String(t.fromId),conversation:String(t.chatId),provenance:e,...t.isBot===!0?{senderIsBot:!0}:{}}}function _b(t){let e=new Set;for(let o of t)typeof o=="number"&&Number.isFinite(o)&&Number.isInteger(o)&&e.add(o);return e}var Jc,fC=S(()=>{"use strict";Eb();Jc={id:"telegram",displayName:"Telegram",authIsForgeable:!1}});function Cb(t){return typeof t=="number"&&Number.isFinite(t)?t:void 0}function $i(t){return typeof t=="object"&&t!==null?t:void 0}function Rb(t,e){let o=$i(t);if(!o||o.ok!==!0||!Array.isArray(o.result))return{updates:[],nextOffset:e};let n=[],r=e-1;for(let s of o.result){let i=$i(s);if(!i)continue;let a=Cb(i.update_id);a!==void 0&&a>r&&(r=a);let c=$i(i.message);if(!c)continue;let l=$i(c.chat),d=Cb(l?.id);if(d===void 0||l?.type!=="private")continue;let f=$i(c.from),u=Cb(f?.id)??d,p=f?.is_bot===!0,g=typeof c.text=="string"?c.text:"",y=c.forward_origin!==void 0||c.forward_from!==void 0||c.forward_from_chat!==void 0||c.forward_sender_name!==void 0||c.forward_date!==void 0,h=(()=>{let w=$i(c.quote)?.text;return typeof w=="string"&&w.trim()!==""?w:void 0})();n.push({chatId:d,fromId:u,text:g,...y?{forwarded:!0}:{},...h!==void 0?{quotedText:h}:{},...p?{isBot:!0}:{}})}return{updates:n,nextOffset:r+1}}var pC=S(()=>{"use strict"});var Qc,hC=S(()=>{"use strict";Qc=class{maxPerWindow;windowMs;stamps=[];constructor(e,o){this.maxPerWindow=e,this.windowMs=o}tryConsume(e){let o=e-this.windowMs;for(;this.stamps.length>0&&this.stamps[0]<=o;)this.stamps.shift();return this.stamps.length>=this.maxPerWindow?!1:(this.stamps.push(e),!0)}get used(){return this.stamps.length}}});function Ob(t){return`connector-${t}-token`}function Zc(t){let e=t.trim(),o=e.indexOf(":");return o<=0?`\u2026(${e.length} chars)`:`${e.slice(0,o)}:\u2026(${e.length-o-1} chars)`}function Mb(t,e){let o=e.trim();return o.length<8?t:t.split(o).join("\xABREDACTED\xBB")}var gC=S(()=>{"use strict"});var U=S(()=>{"use strict";fS();NS();KS();mA();P_();Ty();j_();dC();nb();ju();mC();Eb();fC();pC();hC();gC()});import{posix as fH}from"node:path";function pH(t){return fH.normalize(t)}function uo(t){let e=pH(t);for(let o of hH)if(o.re.test(e))return o.deny?{kind:"deny",why:o.why}:{kind:"ask",why:o.why};return{kind:"allow"}}function Vb(t){return uo(t).kind==="allow"}var hH,Nr=S(()=>{"use strict";hH=[{re:/(?:^|\/|~\/)\.ssh(?:\/|$)/,why:"chaves SSH (~/.ssh)",deny:!0},{re:/(?:^|\/|~\/)\.aws(?:\/|$)/,why:"credenciais AWS (~/.aws)",deny:!0},{re:/(?:^|\/|~\/)\.gnupg(?:\/|$)/,why:"chaves GPG (~/.gnupg)",deny:!0},{re:/(?:~\/|\$\{?HOME\}?\/|\/(?:home|Users)\/[^/]+\/)\.aluy\/rooms(?:\/|$)/,why:"arquivos de sala do Aluy (~/.aluy/rooms)",deny:!0},{re:/~\/\.aluy(?:\/|$)/,why:"estado/credencial do Aluy (~/.aluy)",deny:!0},{re:/(?:^|\/)\.aluy(?:\/(?!agents\/|workflows\/|commands\/)|$)/,why:"estado/credencial do Aluy (.aluy/)",deny:!0},{re:/(?:^|\/|~\/)\.config\/gh\/hosts\.yml$/,why:"token do gh CLI",deny:!0},{re:/(?:^|\/|~\/)\.docker\/config\.json$/,why:"credenciais Docker",deny:!0},{re:/(?:^|\/|~\/)\.kube\/config$/,why:"kubeconfig",deny:!0},{re:/(?:^|\/)id_(?:rsa|ed25519|ecdsa|dsa)\b/,why:"chave privada",deny:!0},{re:/\.pem$|\.p12$|\.pfx$|\.key$/i,why:"material de chave privada",deny:!0},{re:/(?:^|[/\w.-])\.env(?:\.(?!example$|sample$|template$|dist$)[\w.-]+)?$/,why:"arquivo .env (segredos)",deny:!1},{re:/(?:^|\/)[^/]*(?:secret|credential|token|apikey|api_key|password|passwd)[^/]*$/i,why:"arquivo com nome sens\xEDvel (token/secret)",deny:!1}]});var bv={};yp(bv,{UserWorkflowsLoader:()=>Br,WORKFLOWS_DIRNAME:()=>yv});import{homedir as eW}from"node:os";import{join as gv}from"node:path";import{readdirSync as tW,readFileSync as oW,mkdirSync as nW,statSync as rW}from"node:fs";var sW,yv,iW,aW,Br,Mm=S(()=>{"use strict";U();sW=448,yv="workflows",iW=64*1024,aW=256,Br=class{dir;constructor(e={}){let o=e.baseDir??gv(eW(),".aluy");this.dir=gv(o,yv)}get workflowsDir(){return this.dir}ensureDir(){try{nW(this.dir,{mode:sW,recursive:!0})}catch{}}load(){let e;try{e=tW(this.dir,{withFileTypes:!0})}catch{return{workflows:[],errors:[]}}let o=e.filter(i=>(i.isFile()||i.isSymbolicLink())&&i.name.toLowerCase().endsWith(".md")).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=aW)break;let a=this.readOne(i);if(a!==null){if(Rc(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{workflows:r,errors:s}}readOne(e){let o=gv(this.dir,e);try{let n=rW(o);if(!n.isFile()||n.size>iW)return null;let r=oW(o,"utf8");return Oc(e,r,"global")}catch{return null}}}});var kv={};yp(kv,{PROJECT_WORKFLOWS_DIRNAMES:()=>vv,ProjectWorkflowsLoader:()=>Ur});import{join as cW}from"node:path";import{readdirSync as lW,readFileSync as dW,statSync as uW}from"node:fs";var vv,mW,fW,Ur,Lm=S(()=>{"use strict";U();Nr();vv=[".claude/workflows",".aluy/workflows"],mW=64*1024,fW=256,Ur=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of vv){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=lW(s,{withFileTypes:!0})}catch{continue}let a=i.filter(c=>(c.isFile()||c.isSymbolicLink())&&c.name.toLowerCase().endsWith(".md")).map(c=>c.name).sort((c,l)=>c.localeCompare(l));for(let c of a){if(o.length>=fW)break;let l=this.readOne(r,s,c);if(l!==null){if(Rc(l)){n.push(l);continue}e.has(l.name)||(e.add(l.name),o.push(l))}}}return{workflows:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}`;if(uo(r).kind!=="allow")return null;let s=cW(o,n);try{this.workspace.resolveInside(r);let i=uW(s);if(!i.isFile()||i.size>mW)return null;let a=dW(s,"utf8");return Oc(n,a,"project")}catch{return null}}}});var jn="1.0.0-rc.66";U();var yC=`aluy \u2014 agente de terminal que roda na sua m\xE1quina, com o seu provider de LLM
141
141
 
142
142
  Uso:
143
143
  aluy ["objetivo"] [--plan | --yolo] [--dense] [--tier <tier>] [--lang <pt-BR|en>]
@@ -455,7 +455,7 @@ ${r.text}`).join(`
455
455
  `)});break}case"bang":{let n=[`! ${o.command} (${o.status})`];o.output&&n.push(o.output),e.push({role:"observation",toolName:lv,text:n.join(`
456
456
  `)});break}case"broker-error":e.push({role:"observation",toolName:lv,text:`(erro de broker anterior: ${o.message})`});break;case"note":case"deny":case"subagents":case"doctor":case"inject":break}return e}U();var sq=new Set(["bash","run_command"]),iq=new Set(["read","grep","attach","headroom_retrieve"]);function aq(t){return t.kind==="tool"&&iq.has(t.verb)}function BR(t){let e=!1,o=t.map(n=>{if(n.kind==="tool"&&aq(n)){let r=Fe(n.result),s=n.output!==void 0?Fe(n.output):void 0,i=n.liveOutput!==void 0?Fe(n.liveOutput):void 0;return r===n.result&&s===n.output&&i===n.liveOutput?n:(e=!0,{...n,result:r,...s!==void 0?{output:s}:{},...i!==void 0?{liveOutput:i}:{}})}if(n.kind==="bang"){let r=Vt(n.command);return r===n.command?n:(e=!0,{...n,command:r})}if(n.kind==="tool"&&sq.has(n.verb)){let r=Vt(n.target);return r===n.target?n:(e=!0,{...n,target:r})}return n});return e?o:t}var gq=448,yq=384,qR="sessions",WR=1,bq=720*60*60*1e3,vq=50,mv=8*1024*1024,kq=mv*8,xq=Math.floor(mv*.9),Rm=/^[A-Za-z0-9_-]{1,128}$/,Sq=64;function wq(t,e){let o=[...t];return o.length>e?o.slice(0,e).join(""):t}function Om(t){if(typeof t!="string")return;let e="";for(let n of t){let r=n.codePointAt(0)??0;e+=r<32||r===127?" ":n}let o=e.replace(/\s+/g," ").trim();if(o!=="")return wq(o,Sq)}function Aq(t){for(let e of t)if(e.kind==="you"){let o=e.text.replace(/\s+/g," ").trim();if(o==="")return;let n=[...o];return n.length>60?n.slice(0,57).join("")+"\u2026":o}}var kl=class{base;dir;now;createdAtCache=new Map;constructor(e={}){this.base=e.baseDir??dv(cq(),".aluy"),this.dir=dv(this.base,qR),this.now=e.now??(()=>Date.now())}get sessionsDir(){return this.dir}pathFor(e){return dv(this.dir,`${e}.json`)}save(e){if(!Rm.test(e.id))return!1;try{let o=this.now(),n=this.resolveCreatedAt(e.id,o),r=e.tier==="custom"&&typeof e.model=="string"&&e.model.trim()!=="",s=r&&typeof e.provider=="string"&&e.provider.trim()!=="",i=Om(e.label),a=i!==void 0?Om(e.labelColor):void 0,c={id:e.id,version:WR,createdAt:n,updatedAt:o,cwd:e.cwd,tier:e.tier,...r?{model:e.model.trim()}:{},...s?{provider:e.provider.trim()}:{},...i!==void 0?{label:i}:{},...a!==void 0?{labelColor:a}:{}},l=this.fitBlocks(c,BR(Cm(e.blocks))),d={...c,blocks:l};return this.writeAtomic(d),!0}catch{return!1}}resolveCreatedAt(e,o){let n=this.createdAtCache.get(e);if(n!==void 0)return n;let r=this.load(e)?.createdAt??o;return this.createdAtCache.set(e,r),r}load(e){if(!Rm.test(e))return null;let o=this.pathFor(e),n,r=!1;try{let a=hq(o);if(a.size>kq)return null;r=a.size>mv,n=mq(o,"utf8")}catch{return null}let s;try{s=JSON.parse(n)}catch{return null}let i=this.sanitizeRecord(s);if(i&&r){let{blocks:a,...c}=i,l=this.fitBlocks(c,a),d=a.length-l.length,f={kind:"note",title:"sess\xE3o grande \u2014 contexto antigo omitido no resume",lines:[`Esta sess\xE3o era grande demais p/ recarregar inteira; ${d} bloco(s) antigo(s) foram omitidos e a parte recente foi preservada.`,"O contexto restante ser\xE1 resumido automaticamente na pr\xF3xima intera\xE7\xE3o."]};i={...i,blocks:d>0?[f,...l]:l}}return i&&this.createdAtCache.set(i.id,i.createdAt),i}list(){let e;try{e=jR(this.dir)}catch{return[]}let o=[];for(let n of e){if(!n.endsWith(".json"))continue;let r=n.slice(0,-5),s=this.load(r);s&&o.push({id:s.id,createdAt:s.createdAt,updatedAt:s.updatedAt,cwd:s.cwd,tier:s.tier,...s.model!==void 0?{model:s.model}:{},...s.provider!==void 0?{provider:s.provider}:{},...s.label!==void 0?{label:s.label}:{},...s.labelColor!==void 0?{labelColor:s.labelColor}:{},blockCount:s.blocks.length,title:Aq(s.blocks)})}return o.sort((n,r)=>r.updatedAt-n.updatedAt),o}latestForCwd(e){let o;try{o=jR(this.dir)}catch{return null}let n=null;for(let r of o){if(!r.endsWith(".json"))continue;let s=r.slice(0,-5),i=this.load(s);!i||i.cwd!==e||(n===null||i.updatedAt>n.updatedAt)&&(n=i)}return n}remove(e){if(Rm.test(e)){this.createdAtCache.delete(e);try{HR(this.pathFor(e))}catch{}}}gc(e={}){let o=e.maxAgeMs??bq,n=e.maxCount??vq,r=this.list(),s=this.now()-o;r.forEach((i,a)=>{(i.updatedAt<s||a>=n)&&this.remove(i.id)})}sanitizeRecord(e){if(typeof e!="object"||e===null)return null;let o=e;if(typeof o.id!="string"||!Rm.test(o.id)||!Array.isArray(o.blocks))return null;let n=typeof o.createdAt=="number"&&o.createdAt>=0?o.createdAt:0,r=typeof o.updatedAt=="number"&&o.updatedAt>=0?o.updatedAt:n,s=typeof o.cwd=="string"?o.cwd:"",i=typeof o.tier=="string"&&o.tier.trim()!==""?o.tier:"",a=typeof o.version=="number"?o.version:0,c=i==="custom"&&typeof o.model=="string"&&o.model.trim()!==""?o.model.trim():void 0,l=c!==void 0&&typeof o.provider=="string"&&o.provider.trim()!==""?o.provider.trim():void 0,d=Om(o.label),f=d!==void 0?Om(o.labelColor):void 0;return{id:o.id,version:a,createdAt:n,updatedAt:r,cwd:s,tier:i,...c!==void 0?{model:c}:{},...l!==void 0?{provider:l}:{},...d!==void 0?{label:d}:{},...f!==void 0?{labelColor:f}:{},blocks:Cm(o.blocks)}}fitBlocks(e,o){let n=i=>Buffer.byteLength(JSON.stringify({...e,blocks:i})+`
457
457
  `,"utf8")<=xq;if(n(o))return o;let r=1,s=o.length;for(;r<s;){let i=r+s>>1;n(o.slice(i))?s=i:r=i+1}return o.slice(r)}writeAtomic(e){fq(this.dir,{recursive:!0,mode:gq});let o=this.pathFor(e.id),n=`${o}.${process.pid}.${lq(6).toString("hex")}.tmp`,r=JSON.stringify(e)+`
458
- `,s;try{s=dq(n,uv.O_CREAT|uv.O_EXCL|uv.O_WRONLY,yq),uq(s,r),UR(s),s=void 0,pq(n,o)}catch(i){if(s!==void 0)try{UR(s)}catch{}try{HR(n)}catch{}throw i}}};function Eq(t){return t.list().length>0}U();import{homedir as Tq}from"node:os";import{join as fv}from"node:path";import{readdirSync as _q,readFileSync as Cq,mkdirSync as Rq,statSync as Oq}from"node:fs";var Mq=448,GR="commands",Lq=64*1024,Pq=256,xl=class{dir;constructor(e={}){let o=e.baseDir??fv(Tq(),".aluy");this.dir=fv(o,GR)}get commandsDir(){return this.dir}ensureDir(){try{Rq(this.dir,{mode:Mq,recursive:!0})}catch{}}load(){let e;try{e=_q(this.dir,{withFileTypes:!0})}catch{return[]}let o=e.filter(s=>s.isFile()&&s.name.toLowerCase().endsWith(".md")).map(s=>s.name).sort((s,i)=>s.localeCompare(i)),n=new Set,r=[];for(let s of o){if(r.length>=Pq)break;let i=this.readOne(s);i&&(n.has(i.name)||(n.add(i.name),r.push(i)))}return r}readOne(e){let o=fv(this.dir,e);try{let n=Oq(o);if(!n.isFile()||n.size>Lq)return null;let r=Cq(o,"utf8");return Lc(e,r)}catch{return null}}};U();Nr();import{join as Iq}from"node:path";import{readdirSync as Nq,readFileSync as Dq,statSync as $q}from"node:fs";var zR=[".claude/commands",".aluy/commands"],Fq=64*1024,Bq=256,Sl=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[];for(let n of zR){let r;try{r=this.workspace.resolveInside(n)}catch{continue}let s;try{s=Nq(r,{withFileTypes:!0})}catch{continue}let i=s.filter(a=>a.isFile()&&a.name.toLowerCase().endsWith(".md")).map(a=>a.name).sort((a,c)=>a.localeCompare(c));for(let a of i){if(o.length>=Bq)break;let c=this.readOne(n,r,a);c&&(e.has(c.name)||(e.add(c.name),o.push(c)))}}return o}readOne(e,o,n){let r=`${e}/${n}`;if(uo(r).kind!=="allow")return null;let s=Iq(o,n);try{this.workspace.resolveInside(r);let i=$q(s);if(!i.isFile()||i.size>Fq)return null;let a=Dq(s,"utf8");return Lc(n,a)}catch{return null}}};function pv(t,e){let o=new Map;for(let n of t)o.set(n.name,n);for(let n of e)o.set(n.name,n);return[...o.values()]}U();import{homedir as Uq}from"node:os";import{join as hv}from"node:path";import{readdirSync as jq,readFileSync as Hq,mkdirSync as qq,statSync as Wq}from"node:fs";var Gq=448,KR="agents",zq=64*1024,Kq=256,Ps=class{dir;constructor(e={}){let o=e.baseDir??hv(Uq(),".aluy");this.dir=hv(o,KR)}get agentsDir(){return this.dir}ensureDir(){try{qq(this.dir,{mode:Gq,recursive:!0})}catch{}}load(){let e;try{e=jq(this.dir,{withFileTypes:!0})}catch{return{profiles:[],errors:[]}}let o=e.filter(i=>i.isFile()&&i.name.toLowerCase().endsWith(".md")).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=Kq)break;let a=this.readOne(i);if(a!==null){if(Ec(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{profiles:r,errors:s}}readOne(e){let o=hv(this.dir,e);try{let n=Wq(o);if(!n.isFile()||n.size>zq)return null;let r=Hq(o,"utf8");return Tc(e,r,"global")}catch{return null}}};U();Nr();import{join as Yq}from"node:path";import{readdirSync as Vq,readFileSync as Xq,statSync as Jq}from"node:fs";var YR=[".claude/agents",".aluy/agents"],Qq=64*1024,Zq=256,wl=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of YR){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=Vq(s,{withFileTypes:!0})}catch{continue}let a=i.filter(c=>c.isFile()&&c.name.toLowerCase().endsWith(".md")).map(c=>c.name).sort((c,l)=>c.localeCompare(l));for(let c of a){if(o.length>=Zq)break;let l=this.readOne(r,s,c);if(l!==null){if(Ec(l)){n.push(l);continue}e.has(l.name)||(e.add(l.name),o.push(l))}}}return{profiles:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}`;if(uo(r).kind!=="allow")return null;let s=Yq(o,n);try{this.workspace.resolveInside(r);let i=Jq(s);if(!i.isFile()||i.size>Qq)return null;let a=Xq(s,"utf8");return Tc(n,a,"project")}catch{return null}}};Mm();Lm();U();import{homedir as pW}from"node:os";import{join as xv}from"node:path";import{readdirSync as hW,readFileSync as gW,mkdirSync as yW,statSync as bW}from"node:fs";var vW=448,VR="skills",Al="SKILL.md",kW=256*1024,xW=256,Is=class{dir;constructor(e={}){let o=e.baseDir??xv(pW(),".aluy");this.dir=xv(o,VR)}get skillsDir(){return this.dir}ensureDir(){try{yW(this.dir,{mode:vW,recursive:!0})}catch{}}load(){let e;try{e=hW(this.dir,{withFileTypes:!0})}catch{return{skills:[],errors:[]}}let o=e.filter(i=>i.isDirectory()).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=xW)break;let a=this.readOne(i);if(a!==null){if(_c(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{skills:r,errors:s}}readOne(e){let o=xv(this.dir,e,Al);try{let n=bW(o);if(!n.isFile()||n.size>kW)return null;let r=gW(o,"utf8");return Cc(e,r,"global")}catch{return null}}};U();import{join as SW}from"node:path";import{readdirSync as wW,readFileSync as AW,statSync as EW}from"node:fs";var XR=[".claude/skills",".aluy/skills"],TW=256*1024,_W=256,Ns=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of XR){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=wW(s,{withFileTypes:!0})}catch{continue}let a=i.filter(c=>c.isDirectory()).map(c=>c.name).sort((c,l)=>c.localeCompare(l));for(let c of a){if(o.length>=_W)break;let l=this.readOne(r,s,c);if(l!==null){if(_c(l)){n.push(l);continue}e.has(l.name)||(e.add(l.name),o.push(l))}}}return{skills:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}/${Al}`,s=SW(o,n,Al);try{this.workspace.resolveInside(r);let i=EW(s);if(!i.isFile()||i.size>TW)return null;let a=AW(s,"utf8");return Cc(n,a,"project")}catch{return null}}};U();import{homedir as CW}from"node:os";import{join as Sv}from"node:path";import{readFileSync as RW,statSync as OW}from"node:fs";var JR="hooks.json",MW="settings.json",LW=256*1024,El=class{file;claudeProjectFile;constructor(e={}){let o=e.baseDir??Sv(CW(),".aluy");this.file=Sv(o,JR),e.workspaceRoot!==void 0&&(this.claudeProjectFile=Sv(e.workspaceRoot,".claude",MW))}get configPath(){return this.file}load(){let e=fy(this.readJson(this.file));if(this.claudeProjectFile===void 0)return e;let o=hy(this.readJson(this.claudeProjectFile));return gy(e,o)}readJson(e){let o;try{let n=OW(e);if(!n.isFile()||n.size>LW)return;o=RW(e,"utf8")}catch{return}try{return JSON.parse(o)}catch{return}}};Nr();function Tl(t,e){let o=t.toLowerCase(),n=e.toLowerCase();if(o==="")return{score:0,matched:[]};let r=[],s=0,i=0,a=-1,c=e.lastIndexOf("/")+1;for(let d=0;d<o.length;d++){let f=o[d],u=n.indexOf(f,s);if(u===-1)return null;r.push(u),a>=0&&u===a+1?i+=5:i+=1,u>=c&&(i+=2);let p=u>0?e[u-1]:"/";(p==="/"||p==="-"||p==="_"||p===".")&&(i+=3),a=u,s=u+1}let l=(r[r.length-1]??0)-(r[0]??0);return i-=l*.1,i-=e.length*.01,{score:i,matched:r}}function wv(t,e){let o=t.trim();if(o==="")return e.map(r=>({path:r,score:0,matched:[]}));let n=[];for(let r of e){let s=Tl(o,r);s&&n.push({path:r,score:s.score,matched:s.matched})}return n.sort((r,s)=>s.score-r.score||r.path.length-s.path.length||r.path.localeCompare(s.path)),n}var PW=/(?:^|\s)(@(?:"([^"]+)"|'([^']+)'|((?:[\p{L}\p{N}._/-]|\\ )+)))/gu;function IW(t){return t.replace(/\\ /g," ")}function NW(t){return t.includes("/")?!0:/\.[A-Za-z0-9]+$/.test(t)}function DW(t){let e=t.replace(/\.+$/,"");return{token:e,trimmed:t.length-e.length}}function Ds(t){let e=[];for(let o of t.matchAll(PW)){let n=o[1],r=o[4],s=o[2]??o[3]??r,{token:i,trimmed:a}=r!==void 0?DW(s):{token:s,trimmed:0},c=IW(i);if(!NW(c))continue;let l=(o.index??0)+o[0].indexOf(n);e.push({path:c,start:l,end:l+n.length-a})}return e}function Av(t,e){if(e.length===0)return t;let o=t;for(let n of[...e].sort((r,s)=>s.start-r.start))o=o.slice(0,n.start)+o.slice(n.end);return o.replace(/\s{2,}/g," ").trim()}function Pm(t){let e=t.lastIndexOf("@");if(e<0)return null;let o=e>0?t[e-1]:" ";if(o!==" "&&o!==`
458
+ `,s;try{s=dq(n,uv.O_CREAT|uv.O_EXCL|uv.O_WRONLY,yq),uq(s,r),UR(s),s=void 0,pq(n,o)}catch(i){if(s!==void 0)try{UR(s)}catch{}try{HR(n)}catch{}throw i}}};function Eq(t){return t.list().length>0}U();import{homedir as Tq}from"node:os";import{join as fv}from"node:path";import{readdirSync as _q,readFileSync as Cq,mkdirSync as Rq,statSync as Oq}from"node:fs";var Mq=448,GR="commands",Lq=64*1024,Pq=256,xl=class{dir;constructor(e={}){let o=e.baseDir??fv(Tq(),".aluy");this.dir=fv(o,GR)}get commandsDir(){return this.dir}ensureDir(){try{Rq(this.dir,{mode:Mq,recursive:!0})}catch{}}load(){let e;try{e=_q(this.dir,{withFileTypes:!0})}catch{return[]}let o=e.filter(s=>(s.isFile()||s.isSymbolicLink())&&s.name.toLowerCase().endsWith(".md")).map(s=>s.name).sort((s,i)=>s.localeCompare(i)),n=new Set,r=[];for(let s of o){if(r.length>=Pq)break;let i=this.readOne(s);i&&(n.has(i.name)||(n.add(i.name),r.push(i)))}return r}readOne(e){let o=fv(this.dir,e);try{let n=Oq(o);if(!n.isFile()||n.size>Lq)return null;let r=Cq(o,"utf8");return Lc(e,r)}catch{return null}}};U();Nr();import{join as Iq}from"node:path";import{readdirSync as Nq,readFileSync as Dq,statSync as $q}from"node:fs";var zR=[".claude/commands",".aluy/commands"],Fq=64*1024,Bq=256,Sl=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[];for(let n of zR){let r;try{r=this.workspace.resolveInside(n)}catch{continue}let s;try{s=Nq(r,{withFileTypes:!0})}catch{continue}let i=s.filter(a=>(a.isFile()||a.isSymbolicLink())&&a.name.toLowerCase().endsWith(".md")).map(a=>a.name).sort((a,c)=>a.localeCompare(c));for(let a of i){if(o.length>=Bq)break;let c=this.readOne(n,r,a);c&&(e.has(c.name)||(e.add(c.name),o.push(c)))}}return o}readOne(e,o,n){let r=`${e}/${n}`;if(uo(r).kind!=="allow")return null;let s=Iq(o,n);try{this.workspace.resolveInside(r);let i=$q(s);if(!i.isFile()||i.size>Fq)return null;let a=Dq(s,"utf8");return Lc(n,a)}catch{return null}}};function pv(t,e){let o=new Map;for(let n of t)o.set(n.name,n);for(let n of e)o.set(n.name,n);return[...o.values()]}U();import{homedir as Uq}from"node:os";import{join as hv}from"node:path";import{readdirSync as jq,readFileSync as Hq,mkdirSync as qq,statSync as Wq}from"node:fs";var Gq=448,KR="agents",zq=64*1024,Kq=256,Ps=class{dir;constructor(e={}){let o=e.baseDir??hv(Uq(),".aluy");this.dir=hv(o,KR)}get agentsDir(){return this.dir}ensureDir(){try{qq(this.dir,{mode:Gq,recursive:!0})}catch{}}load(){let e;try{e=jq(this.dir,{withFileTypes:!0})}catch{return{profiles:[],errors:[]}}let o=e.filter(i=>(i.isFile()||i.isSymbolicLink())&&i.name.toLowerCase().endsWith(".md")).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=Kq)break;let a=this.readOne(i);if(a!==null){if(Ec(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{profiles:r,errors:s}}readOne(e){let o=hv(this.dir,e);try{let n=Wq(o);if(!n.isFile()||n.size>zq)return null;let r=Hq(o,"utf8");return Tc(e,r,"global")}catch{return null}}};U();Nr();import{join as Yq}from"node:path";import{readdirSync as Vq,readFileSync as Xq,statSync as Jq}from"node:fs";var YR=[".claude/agents",".aluy/agents"],Qq=64*1024,Zq=256,wl=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of YR){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=Vq(s,{withFileTypes:!0})}catch{continue}let a=i.filter(c=>(c.isFile()||c.isSymbolicLink())&&c.name.toLowerCase().endsWith(".md")).map(c=>c.name).sort((c,l)=>c.localeCompare(l));for(let c of a){if(o.length>=Zq)break;let l=this.readOne(r,s,c);if(l!==null){if(Ec(l)){n.push(l);continue}e.has(l.name)||(e.add(l.name),o.push(l))}}}return{profiles:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}`;if(uo(r).kind!=="allow")return null;let s=Yq(o,n);try{this.workspace.resolveInside(r);let i=Jq(s);if(!i.isFile()||i.size>Qq)return null;let a=Xq(s,"utf8");return Tc(n,a,"project")}catch{return null}}};Mm();Lm();U();import{homedir as pW}from"node:os";import{join as xv}from"node:path";import{readdirSync as hW,readFileSync as gW,mkdirSync as yW,statSync as bW}from"node:fs";var vW=448,VR="skills",Al="SKILL.md",kW=256*1024,xW=256,Is=class{dir;constructor(e={}){let o=e.baseDir??xv(pW(),".aluy");this.dir=xv(o,VR)}get skillsDir(){return this.dir}ensureDir(){try{yW(this.dir,{mode:vW,recursive:!0})}catch{}}load(){let e;try{e=hW(this.dir,{withFileTypes:!0})}catch{return{skills:[],errors:[]}}let o=e.filter(i=>i.isDirectory()).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=xW)break;let a=this.readOne(i);if(a!==null){if(_c(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{skills:r,errors:s}}readOne(e){let o=xv(this.dir,e,Al);try{let n=bW(o);if(!n.isFile()||n.size>kW)return null;let r=gW(o,"utf8");return Cc(e,r,"global")}catch{return null}}};U();import{join as SW}from"node:path";import{readdirSync as wW,readFileSync as AW,statSync as EW}from"node:fs";var XR=[".claude/skills",".aluy/skills"],TW=256*1024,_W=256,Ns=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of XR){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=wW(s,{withFileTypes:!0})}catch{continue}let a=i.filter(c=>c.isDirectory()).map(c=>c.name).sort((c,l)=>c.localeCompare(l));for(let c of a){if(o.length>=_W)break;let l=this.readOne(r,s,c);if(l!==null){if(_c(l)){n.push(l);continue}e.has(l.name)||(e.add(l.name),o.push(l))}}}return{skills:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}/${Al}`,s=SW(o,n,Al);try{this.workspace.resolveInside(r);let i=EW(s);if(!i.isFile()||i.size>TW)return null;let a=AW(s,"utf8");return Cc(n,a,"project")}catch{return null}}};U();import{homedir as CW}from"node:os";import{join as Sv}from"node:path";import{readFileSync as RW,statSync as OW}from"node:fs";var JR="hooks.json",MW="settings.json",LW=256*1024,El=class{file;claudeProjectFile;constructor(e={}){let o=e.baseDir??Sv(CW(),".aluy");this.file=Sv(o,JR),e.workspaceRoot!==void 0&&(this.claudeProjectFile=Sv(e.workspaceRoot,".claude",MW))}get configPath(){return this.file}load(){let e=fy(this.readJson(this.file));if(this.claudeProjectFile===void 0)return e;let o=hy(this.readJson(this.claudeProjectFile));return gy(e,o)}readJson(e){let o;try{let n=OW(e);if(!n.isFile()||n.size>LW)return;o=RW(e,"utf8")}catch{return}try{return JSON.parse(o)}catch{return}}};Nr();function Tl(t,e){let o=t.toLowerCase(),n=e.toLowerCase();if(o==="")return{score:0,matched:[]};let r=[],s=0,i=0,a=-1,c=e.lastIndexOf("/")+1;for(let d=0;d<o.length;d++){let f=o[d],u=n.indexOf(f,s);if(u===-1)return null;r.push(u),a>=0&&u===a+1?i+=5:i+=1,u>=c&&(i+=2);let p=u>0?e[u-1]:"/";(p==="/"||p==="-"||p==="_"||p===".")&&(i+=3),a=u,s=u+1}let l=(r[r.length-1]??0)-(r[0]??0);return i-=l*.1,i-=e.length*.01,{score:i,matched:r}}function wv(t,e){let o=t.trim();if(o==="")return e.map(r=>({path:r,score:0,matched:[]}));let n=[];for(let r of e){let s=Tl(o,r);s&&n.push({path:r,score:s.score,matched:s.matched})}return n.sort((r,s)=>s.score-r.score||r.path.length-s.path.length||r.path.localeCompare(s.path)),n}var PW=/(?:^|\s)(@(?:"([^"]+)"|'([^']+)'|((?:[\p{L}\p{N}._/-]|\\ )+)))/gu;function IW(t){return t.replace(/\\ /g," ")}function NW(t){return t.includes("/")?!0:/\.[A-Za-z0-9]+$/.test(t)}function DW(t){let e=t.replace(/\.+$/,"");return{token:e,trimmed:t.length-e.length}}function Ds(t){let e=[];for(let o of t.matchAll(PW)){let n=o[1],r=o[4],s=o[2]??o[3]??r,{token:i,trimmed:a}=r!==void 0?DW(s):{token:s,trimmed:0},c=IW(i);if(!NW(c))continue;let l=(o.index??0)+o[0].indexOf(n);e.push({path:c,start:l,end:l+n.length-a})}return e}function Av(t,e){if(e.length===0)return t;let o=t;for(let n of[...e].sort((r,s)=>s.start-r.start))o=o.slice(0,n.start)+o.slice(n.end);return o.replace(/\s{2,}/g," ").trim()}function Pm(t){let e=t.lastIndexOf("@");if(e<0)return null;let o=e>0?t[e-1]:" ";if(o!==" "&&o!==`
459
459
  `&&o!==" ")return null;let n=t.slice(e+1);return/\s/.test(n)?null:{at:e,query:n}}function Ev(t){let e=Pm(t);return e?t.slice(0,e.at).replace(/\s+$/,""):t}U();Nr();import{relative as $W,sep as FW,isAbsolute as BW}from"node:path";var QR=16e3,UW=5*1024*1024,_l=class{workspace;fs;maxChars;sniffBytes;constructor(e){this.workspace=e.workspace,this.fs=e.fs,this.maxChars=e.maxChars??QR,this.sniffBytes=e.sniffBytes??UW}async attach(e,o={}){let n=e,r;try{r=this.workspace.resolveInside(e)}catch{return{kind:"rejected",path:n,reason:"caminho fora do workspace \u2014 recusado (o @ s\xF3 acessa a raiz do projeto)."}}let s=$W(this.workspace.root,r).split(FW).join("/");if(s===""||s.startsWith("..")||BW(s))return{kind:"rejected",path:n,reason:"caminho inv\xE1lido p/ o workspace."};let i=uo(s);if(i.kind==="deny")return{kind:"rejected",path:s,reason:`bloqueado: ${i.why} \u2014 esse tipo de arquivo nunca \xE9 anexado ao contexto.`};if(i.kind==="ask"&&o.confirmSensitive!==!0)return{kind:"rejected",path:s,reason:`sens\xEDvel: ${i.why} \u2014 confirme explicitamente p/ anexar (fora do picker por padr\xE3o).`};try{if(await IC(r,this.sniffBytes))return{kind:"rejected",path:s,reason:"arquivo bin\xE1rio \u2014 n\xE3o anexado (conte\xFAdo n\xE3o \xE9 texto; evita lixo no contexto)."}}catch{}let a;try{a=await this.fs.readFile(s)}catch{return{kind:"rejected",path:s,reason:"n\xE3o foi poss\xEDvel ler o arquivo (sumiu/ileg\xEDvel)."}}let c=!1;return a.length>this.maxChars&&(a=a.slice(0,this.maxChars)+`
460
460
  [\u2026conte\xFAdo truncado: arquivo maior que ${this.maxChars} caracteres \u2014 s\xF3 o in\xEDcio foi anexado\u2026]`,c=!0),{kind:"ok",path:s,item:xA(s,a),truncated:c}}};var Cl=class{observer=null;current=null;timeoutMs;setTimeoutFn;clearTimeoutFn;nonInteractive=!1;constructor(e={}){this.timeoutMs=e.timeoutMs??0,this.setTimeoutFn=e.setTimeoutFn??setTimeout,this.clearTimeoutFn=e.clearTimeoutFn??clearTimeout}setNonInteractive(e){this.nonInteractive=e}subscribe(e){this.observer=e,e(this.current)}get pending(){return this.current}resolve(e,o){return this.nonInteractive?Promise.resolve(Im("sess\xE3o n\xE3o-interativa (sem TTY) \u2014 aprova\xE7\xE3o indispon\xEDvel")):o?.aborted?Promise.resolve(Im("cancelado antes da confirma\xE7\xE3o")):new Promise(n=>{let r=!1,s,i=l=>{r||(r=!0,s&&this.clearTimeoutFn(s),o&&o.removeEventListener("abort",a),this.current=null,this.notify(),n(l))},a=()=>{i(Im("confirma\xE7\xE3o cancelada (abort/Ctrl-C)"))},c=l=>{i(jW(l,e))};this.current={request:e,resolve:c},o&&o.addEventListener("abort",a,{once:!0}),this.timeoutMs>0&&(s=this.setTimeoutFn(()=>{i(Im("confirma\xE7\xE3o expirou sem resposta"))},this.timeoutMs),s.unref?.()),this.notify()})}notify(){this.observer?.(this.current)}};function Im(t){return{kind:"deny",reason:t}}function jW(t,e){return t.kind==="approve-session"&&e.alwaysAsk===!0?{kind:"approve-once"}:t}var Nm=class{observer=null;current=null;nonInteractive=!1;setNonInteractive(e){this.nonInteractive=e}subscribe(e){this.observer=e,e(this.current)}get pending(){return this.current}ask(e,o){return this.nonInteractive?Promise.resolve(Tv("sess\xE3o n\xE3o-interativa (sem terminal)")):o?.aborted?Promise.resolve(Tv("cancelado antes da pergunta")):new Promise(n=>{let r=!1,s=c=>{r||(r=!0,o&&o.removeEventListener("abort",i),this.current=null,this.notify(),n(c))},i=()=>{s(Tv("pergunta cancelada (abort/Ctrl-C)"))},a=c=>s(c);this.current={spec:e,resolve:a},o&&o.addEventListener("abort",i,{once:!0}),this.notify()})}notify(){this.observer?.(this.current)}};function Tv(t){return{kind:"unavailable",reason:t}}U();var HW=2500;async function ZR(t,e){if(t.length===0)return t;let o=e.timeoutMs??HW,n=new AbortController,r=o>0?setTimeout(()=>n.abort(),o):void 0,s=()=>n.abort();e.signal?.addEventListener("abort",s,{once:!0}),e.signal?.aborted&&n.abort();try{let i=await gm(e.baseUrl,"/v1/compress",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({messages:t,model:e.model??"claude-3-5-sonnet"}),signal:n.signal},{...e.resolver?{resolver:e.resolver}:{},...e.fetchFn?{fetchFn:e.fetchFn}:{}});if(!i.ok)return e.onRefused?.(i.reason),t;let a=i.response;if(!a.ok)return t;let c=await a.json(),l=c.messages;if(!Array.isArray(l)||l.length!==t.length)return t;for(let d=0;d<t.length;d++){let f=t[d],u=l[d];if(u===void 0)return t;if(u.role!==void 0&&u.role!==f.role)return e.onRefused?.(`proxy adulterou o role da mensagem ${d} (${String(u.role)})`),t;if(u.tool_calls!==void 0&&f.tool_calls===void 0)return e.onRefused?.(`proxy injetou tool_calls na mensagem ${d}`),t;if(u.tool_call_id!==void 0&&f.tool_call_id===void 0)return e.onRefused?.(`proxy injetou tool_call_id na mensagem ${d}`),t}return e.onSavings?.({before:c.tokens_before??0,after:c.tokens_after??0,ratio:c.compression_ratio??1}),t.map((d,f)=>{let u=l[f]?.content;return typeof u=="string"&&d.content!==""&&u!==d.content?{...d,content:u}:d})}catch{return t}finally{r!==void 0&&clearTimeout(r),e.signal?.removeEventListener("abort",s)}}var Dm=class{client;opts;brokerSessionId;currentTier;nativeTools;customModel;customProvider;reasoningEffort;headroomRefusedWarned=!1;constructor(e){this.client=e.client,this.opts=e,this.brokerSessionId=e.sessionId,this.currentTier=e.tier,this.customModel=e.model,this.customProvider=e.tier==="custom"&&e.model!==void 0?e.provider:void 0,this.reasoningEffort=e.effort,this.nativeTools=e.nativeTools}attachNativeTools(e){this.nativeTools=e}setTier(e,o){this.currentTier=e,this.customModel=e==="custom"?o:void 0,this.customProvider=void 0}setProvider(e){this.customProvider=this.currentTier==="custom"&&this.customModel!==void 0?e:void 0}get tier(){return this.currentTier}get model(){return this.customModel}get provider(){return this.customProvider}setEffort(e){this.reasoningEffort=e}get effort(){return this.reasoningEffort}async call(e){let o=this.opts.headroomUrl,n=o===void 0?e:{...e,messages:await ZR(e.messages,{baseUrl:o,...e.signal?{signal:e.signal}:{},onSavings:({before:r,after:s})=>{r>s&&process.stderr.write(`[headroom] mensagens comprimidas: ${r} \u2192 ${s} tokens (-${r-s})
461
461
  `)},onRefused:r=>{this.headroomRefusedWarned||(this.headroomRefusedWarned=!0,process.stderr.write(`[headroom] compress\xE3o DESLIGADA nesta sess\xE3o \u2014 ${r}. Rodando sem headroom (fail-open).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hiperplano/aluy-cli",
3
- "version": "1.0.0-rc.65",
3
+ "version": "1.0.0-rc.66",
4
4
  "description": "Aluy CLI — TUI (Ink) + binário `aluy` + wiring. Consome @hiperplano/aluy-cli-core (engine portável). Credenciais só no keychain do SO.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",