#!/usr/bin/env node
import{a as S}from"./chunk-APEJG7SM.js";import{a as m,c as p}from"./chunk-RX45273B.js";import{a as z}from"./chunk-JBABAK44.js";import{a as b,b as $}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var x={name:"ag-analyze",summary:"analyze code structure and provide summaries",usage:"ag-analyze <file> [--symbols]",options:["    --symbols     output JSON symbol table","    --help        display this help and exit"]},L={name:"ag-analyze",async execute(f,a){if($(f))return b(x);let u=z("ag-analyze",f,{symbols:{long:"symbols",type:"boolean"}});if(!u.ok)return u.error;let{flags:C,positional:w}=u.result,t=w[0];if(!t)return{stdout:"",stderr:`ag-analyze: missing file operand
`,exitCode:2};let r=a.fs.resolvePath(a.cwd,t);if(!await a.fs.exists(r))return{stdout:"",stderr:`ag-analyze: ${t}: No such file or directory
`,exitCode:2};let o=await a.fs.readFile(r,"utf8"),h=o.split(/\r?\n/),i=(s=>s.endsWith(".py")?"python":s.endsWith(".js")||s.endsWith(".ts")?"javascript":s.endsWith(".json")?"json":"bash")(t);try{let s=a.bash?.semanticEngine??new p;if(i==="bash"){let{parse:e}=await import("./parser-CVWY2HS3.js"),c=e(o);s.indexNode(c,r,"bash")}else{let e=S.parse(o,i);s.indexNode(e.rootNode,r,i)}let l=s.getAllSymbols();if(C.symbols)return{stdout:`${JSON.stringify(l,null,2)}
`,stderr:"",exitCode:0};let n=`--- Analysis Summary for ${t} (${i}) ---
`;n+=`Lines: ${h.length}
`,n+=`Size: ${o.length} bytes
`;let d=l.filter(e=>e.type===m.Function),g=l.filter(e=>e.type===m.Class),y=l.filter(e=>e.type===m.Variable);if(g.length>0&&(n+=`
Classes (${g.length}):
`,g.forEach(e=>{n+=`  - class ${e.name} (line ${e.line})
`})),d.length>0?(n+=`
Functions (${d.length}):
`,d.forEach(e=>{n+=`  - ${e.name} (line ${e.line})
`})):g.length===0&&(n+=`
No major symbols defined.
`),y.length>0){n+=`
Variables (${y.length} unique):
`;let e=Array.from(new Set(y.map(c=>c.name)));n+=`  ${e.slice(0,10).join(", ")}${e.length>10?"...":""}
`}return n+=`-----------------------------------
`,{stdout:n,stderr:"",exitCode:0}}catch(s){return{stdout:`File: ${t}
Lines: ${h.length}
(Error during analysis: ${s.message})
`,stderr:"",exitCode:1}}}};export{L as agAnalyzeCommand};
