#!/usr/bin/env node
import {f,p,o,r,i,s}from'./chunk-4QADCWPU.js';import {a}from'./chunk-NKYNHSA5.js';import'./chunk-XHJ27CER.js';import t from'chalk';import S from'ora';import*as h from'fs';function I(){return `
${t.cyan("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557")}
${t.cyan("\u2551")}                    ${t.bold.white("PARADIGM SENTINEL TRIAGE")}                      ${t.cyan("\u2551")}
${t.cyan("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D")}
`}function R(e){return `${t.cyan("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557")}
${t.cyan("\u2551")}  Open: ${t.yellow(String(e.open).padEnd(4))} \u2502  Investigating: ${t.blue(String(e.investigating).padEnd(3))} \u2502  Resolved: ${t.green(String(e.resolved).padEnd(4))} \u2502  Today: ${t.magenta(`+${e.today}`)}   ${t.cyan("\u2551")}
${t.cyan("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D")}
`}function v(e,n){let o=[],r=E(e.status);o.push(t.gray("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510")),o.push(t.gray("\u2502 ")+t.bold(`[${e.id}] `)+r(e.status.toUpperCase().padEnd(12))+t.gray(e.timestamp.substring(0,19).replace("T"," ").padStart(19))+t.gray(" \u2502")),o.push(t.gray("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524")),o.push(t.gray("\u2502 ")+t.red("Error: ")+u(e.error.message,55)+t.gray(" \u2502")),o.push(t.gray("\u2502")+" ".repeat(65)+t.gray("\u2502")),o.push(t.gray("\u2502 ")+t.cyan("Symbolic Context:")+" ".repeat(47)+t.gray("\u2502"));let s=N(e.symbols);for(let a of s)o.push(t.gray("\u2502   ")+a.padEnd(61)+t.gray(" \u2502"));o.push(t.gray("\u2502")+" ".repeat(65)+t.gray("\u2502"));let c=`Environment: ${t.yellow(e.environment)}  \u2502  Service: ${t.yellow(e.service||"N/A")}  \u2502  v${e.version||"N/A"}`;if(o.push(t.gray("\u2502 ")+c.substring(0,63).padEnd(63)+t.gray(" \u2502")),n&&n.length>0){o.push(t.gray("\u2502")+" ".repeat(65)+t.gray("\u2502")),o.push(t.gray("\u2502 \u250C\u2500 ")+t.cyan("Matched Patterns")+t.gray(" \u2500".repeat(22)+"\u2510 \u2502"));for(let a=0;a<Math.min(n.length,3);a++){let l=n[a],m=a===0?t.yellow("\u2605"):t.gray("\u25CB"),d=`${l.confidence}% confidence`;o.push(t.gray("\u2502 \u2502 ")+m+" "+t.bold(u(l.pattern.id,30).padEnd(30))+t.gray(d.padStart(15))+t.gray("    \u2502 \u2502")),o.push(t.gray("\u2502 \u2502   ")+t.italic(u(l.pattern.description,45).padEnd(45))+t.gray("     \u2502 \u2502")),o.push(t.gray("\u2502 \u2502   Strategy: ")+t.cyan(l.pattern.resolution.strategy.padEnd(40))+t.gray("     \u2502 \u2502")),a<Math.min(n.length,3)-1&&o.push(t.gray("\u2502 \u2502")+" ".repeat(59)+t.gray("\u2502 \u2502"));}o.push(t.gray("\u2502 \u2514")+"\u2500".repeat(59)+t.gray("\u2518 \u2502"));}return o.push(t.gray("\u2502")+" ".repeat(65)+t.gray("\u2502")),o.push(t.gray("\u2502 ")+t.dim("Actions:")+" ".repeat(56)+t.gray("\u2502")),o.push(t.gray("\u2502   ")+t.dim(`paradigm triage resolve ${e.id}`)+" ".repeat(35-e.id.length)+t.gray("\u2502")),o.push(t.gray("\u2502   ")+t.dim(`paradigm triage show ${e.id} --timeline`)+" ".repeat(28-e.id.length)+t.gray("\u2502")),o.push(t.gray("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518")),o.join(`
`)}function j(e){let o=E(e.status)(e.status.substring(0,4).toUpperCase().padEnd(4)),r=e.timestamp.substring(5,16).replace("T"," "),s=u(e.error.message,40),c=Object.values(e.symbols).filter(Boolean).join(" ");return `${t.bold(e.id)} ${o} ${t.gray(r)} ${s}
    ${t.cyan(u(c,60))}`}function O(e){let n=[];if(n.push(t.bold.cyan(`Pattern: ${e.id}`)),n.push(t.white(`  Name: ${e.name}`)),n.push(t.gray(`  Description: ${e.description}`)),n.push(""),n.push(t.yellow("  Matching Criteria:")),e.pattern.symbols){for(let[o,r]of Object.entries(e.pattern.symbols))if(r){let s=Array.isArray(r)?r.join(", "):r;n.push(`    ${t.cyan(o)}: ${s}`);}}return e.pattern.errorContains&&n.push(`    ${t.cyan("errorContains")}: ${e.pattern.errorContains.join(", ")}`),e.pattern.missingSignals&&n.push(`    ${t.cyan("missingSignals")}: ${e.pattern.missingSignals.join(", ")}`),n.push(""),n.push(t.green("  Resolution:")),n.push(`    ${t.white(e.resolution.description)}`),n.push(`    Strategy: ${t.cyan(e.resolution.strategy)}  Priority: ${A(e.resolution.priority)(e.resolution.priority)}`),e.resolution.codeHint&&n.push(`    ${t.dim("Hint: "+e.resolution.codeHint)}`),n.push(""),n.push(t.blue("  Confidence:")),n.push(`    Score: ${T(e.confidence.score)(e.confidence.score+"%")}  Matched: ${e.confidence.timesMatched}  Resolved: ${e.confidence.timesResolved}  Recurred: ${e.confidence.timesRecurred}`),n.push(""),n.push(t.gray(`  Source: ${e.source}  Tags: ${e.tags.join(", ")||"none"}`)),n.join(`
`)}function k(e){let n=T(e.confidence.score)(`${e.confidence.score}%`),o=e.tags.slice(0,3).join(", ");return `${t.bold(e.id.padEnd(30))} ${n.padStart(8)}  ${t.gray(e.source.padEnd(10))} ${t.dim(o)}
  ${t.white(u(e.name,60))}`}function N(e){let n=[];for(let[o,r]of Object.entries(e))if(r){let s=M(o);n.push(`${s(r.padEnd(20))} ${t.dim(o)}`);}return n}function E(e){switch(e){case "open":return t.red;case "investigating":return t.yellow;case "resolved":return t.green;case "wont-fix":return t.gray;default:return t.white}}function M(e){switch(e){case "feature":return t.magenta;case "component":return t.blue;case "flow":return t.cyan;case "gate":return t.yellow;case "signal":return t.green;case "state":return t.red;case "integration":return t.white;default:return t.gray}}function A(e){switch(e){case "critical":return t.red.bold;case "high":return t.red;case "medium":return t.yellow;case "low":return t.gray;default:return t.white}}function T(e){return e>=80?t.green:e>=60?t.yellow:e>=40?t.red:t.gray}function u(e,n){return e.length<=n?e:e.substring(0,n-3)+"..."}var b=null;function g(){return b||(b=new a),b}async function U(e){let n=g(),o=new f(n),r=parseInt(e.limit||"10",10),s=e.status,c=n.getRecentIncidents({limit:r,status:s||"all",symbol:e.symbol,environment:e.env,search:e.search,dateFrom:e.from,dateTo:e.to});if(e.json){let d=c.map(p=>({incident:p,matches:o.match(p,{maxResults:3})}));console.log(JSON.stringify(d,null,2));return}let a=new p(n).getStats(7),l=new Date;l.setHours(0,0,0,0);let m=n.getIncidentCount({dateFrom:l.toISOString()});if(console.log(I()),console.log(R({open:a.incidents.open,investigating:a.incidents.total-a.incidents.open-a.incidents.resolved,resolved:a.incidents.resolved,today:m})),console.log(""),c.length===0){console.log(t.gray("No incidents found."));return}for(let d of c){let p=o.match(d,{maxResults:3});console.log(v(d,p)),console.log("");}}async function G(e,n){let o$1=g(),r=new f(o$1),s=o$1.getIncident(e);if(!s){console.log(t.red(`Incident ${e} not found.`));return}let c=r.match(s,{maxResults:5});if(n.json){let a={incident:s,matches:c};if(n.timeline&&s.flowPosition){let l=new o().build(s);a.timeline=l?new o().renderStructured(l):null;}console.log(JSON.stringify(a,null,2));return}if(console.log(v(s,c)),n.timeline&&s.flowPosition){let a=new o().build(s);a&&(console.log(""),console.log(t.cyan.bold("Flow Timeline")),console.log(t.gray("\u2500".repeat(50))),console.log(new o().renderAscii(a)));}if(s.notes.length>0){console.log(""),console.log(t.cyan.bold("Notes")),console.log(t.gray("\u2500".repeat(50)));for(let a of s.notes)console.log(t.gray(a.timestamp.substring(0,16))+" "+(a.author?t.yellow(a.author+": "):"")+a.content);}s.relatedIncidents.length>0&&(console.log(""),console.log(t.cyan.bold("Related Incidents")),console.log(t.gray("\u2500".repeat(50))),console.log("  "+s.relatedIncidents.join(", ")));}async function W(e,n){let o=g(),r=o.getIncident(e);if(!r){console.log(t.red(`Incident ${e} not found.`));return}if(r.status==="resolved"||r.status==="wont-fix"){console.log(t.yellow(`Incident ${e} is already ${r.status}.`));return}if(n.wontFix){o.updateIncident(e,{status:"wont-fix",resolvedAt:new Date().toISOString(),resolvedBy:"manual",resolution:{notes:n.notes}}),console.log(t.gray(`Incident ${e} marked as won't fix.`));return}o.recordResolution({incidentId:e,patternId:n.pattern,commitHash:n.commit,prUrl:n.pr,notes:n.notes}),console.log(t.green(`Incident ${e} resolved.`)),n.pattern&&console.log(t.gray(`  Pattern: ${n.pattern}`)),n.commit&&console.log(t.gray(`  Commit: ${n.commit}`)),n.pr&&console.log(t.gray(`  PR: ${n.pr}`));}async function q(e,n){let o=g();if(!o.getIncident(e)){console.log(t.red(`Incident ${e} not found.`));return}o.addIncidentNote(e,{timestamp:new Date().toISOString(),content:n}),console.log(t.green(`Note added to ${e}.`));}async function z(e,n){let o=g(),r=o.getIncident(e),s=o.getIncident(n);if(!r){console.log(t.red(`Incident ${e} not found.`));return}if(!s){console.log(t.red(`Incident ${n} not found.`));return}o.linkIncidents(e,n),console.log(t.green(`Linked ${e} and ${n}.`));}async function K(e){let o=g().getAllPatterns({source:e.source,minConfidence:e.minConfidence?parseInt(e.minConfidence,10):void 0,includePrivate:true});if(e.json){console.log(JSON.stringify(o,null,2));return}if(console.log(t.cyan.bold(`
Failure Patterns`)),console.log(t.gray("\u2500".repeat(70))),o.length===0){console.log(t.gray("No patterns found. Run `paradigm triage patterns seed` to load defaults."));return}for(let r of o)console.log(k(r)),console.log("");}async function Q(e,n){let r=g().getPattern(e);if(!r){console.log(t.red(`Pattern ${e} not found.`));return}if(n.json){console.log(JSON.stringify(r,null,2));return}console.log(O(r));}async function V(e){let n=g();if(e.fromIncident){let s=n.getIncident(e.fromIncident);if(!s){console.log(t.red(`Incident ${e.fromIncident} not found.`));return}let a=new r(n).suggestFromIncident(s);console.log(t.cyan(`
Suggested Pattern:`)),console.log(JSON.stringify(a,null,2)),console.log(t.gray(`
Edit and add with: paradigm triage patterns add --id <id> --name "..." ...`));return}let o={};if(e.symbols){let s=e.symbols.split(",");for(let c of s){let[a,l]=c.split(":").map(m=>m.trim());a&&l&&(o[a]=l);}}let r$1={id:e.id,name:e.name,description:e.description||"",pattern:{symbols:o,errorContains:e.errorContains?.split(",").map(s=>s.trim()),missingSignals:e.missingSignals?.split(",").map(s=>s.trim())},resolution:{description:"Resolution TBD",strategy:e.strategy||"fix-code",priority:e.priority||"medium",codeHint:e.codeHint},source:"manual",private:false,tags:e.tags?.split(",").map(s=>s.trim())||[]};n.addPattern(r$1),console.log(t.green(`Pattern ${e.id} created.`));}async function X(e){let n=g();if(!n.getPattern(e)){console.log(t.red(`Pattern ${e} not found.`));return}n.deletePattern(e),console.log(t.green(`Pattern ${e} deleted.`));}async function Y(e,n){let o=g(),r=new f(o),s=o.getPattern(e);if(!s){console.log(t.red(`Pattern ${e} not found.`));return}let c=parseInt(n.limit||"100",10),a=r.testPattern(s,c);if(n.json){console.log(JSON.stringify(a,null,2));return}if(console.log(t.cyan.bold(`
Pattern Test: ${e}`)),console.log(t.gray("\u2500".repeat(50))),console.log(`Would match: ${t.yellow(a.matchCount)} incidents`),console.log(`Average score: ${t.yellow(a.avgScore+"%")}`),a.wouldMatch.length>0){console.log(""),console.log(t.cyan("Sample matches:"));for(let l of a.wouldMatch.slice(0,5))console.log(j(l));}}async function Z(){let e=g(),n=S("Loading seed patterns...").start();try{let o=i(),r=e.importPatterns(o,{overwrite:!1});n.succeed(`Loaded ${r.imported} patterns (${r.skipped} skipped).`);}catch(o){n.fail(`Failed to load seed patterns: ${o}`);}}async function _(e,n){let o=g(),r,s;e==="patterns"?(r=o.exportPatterns({includePrivate:n.includePrivate}),s="sentinel-patterns.json"):(r=o.exportBackup(),s="sentinel-backup.json");let c=n.output||s;h.writeFileSync(c,JSON.stringify(r,null,2)),console.log(t.green(`Exported to ${c}`));}async function ee(e,n){let o=g(),r=new s,s$1=S(`Importing from ${e}...`).start();try{let c=r.loadFromFile(e),a=o.importPatterns(c,{overwrite:n.overwrite});s$1.succeed(`Imported ${a.imported} patterns (${a.skipped} skipped).`);}catch(c){s$1.fail(`Import failed: ${c}`);}}async function te(e){let n=g(),o=S(`Restoring from ${e}...`).start();try{let r=h.readFileSync(e,"utf-8"),s=JSON.parse(r);n.importBackup(s),o.succeed("Backup restored.");}catch(r){o.fail(`Restore failed: ${r}`);}}async function ne(e){let n=g(),o=new p(n),r=7;if(e.period){let c=e.period.match(/^(\d+)d$/);c&&(r=parseInt(c[1],10));}if(e.symbol){let c=o.getSymbolHealth(e.symbol);if(e.json)console.log(JSON.stringify(c,null,2));else {console.log(t.cyan.bold(`
Symbol Health: ${e.symbol}`)),console.log(t.gray("\u2500".repeat(50))),console.log(`  Incidents: ${c.incidentCount}`),console.log(`  Avg Time to Resolve: ${c.avgTimeToResolve}m`),console.log(""),console.log(t.cyan("  Top Patterns:"));for(let{patternId:a,count:l}of c.topPatterns)console.log(`    ${a}: ${l} times`);}return}let s=o.getStats(r);if(e.json){console.log(JSON.stringify(s,null,2));return}console.log(o.generateDashboard(r));}async function oe(e){let n=g(),o=new f(n),r=n.recordIncident({error:{message:e.error,stack:e.stack},symbols:{feature:e.feature,component:e.component,flow:e.flow,gate:e.gate,signal:e.signal,state:e.state,integration:e.integration},environment:e.env,service:e.service,version:e.version}),s=n.getIncident(r),c=s?o.match(s,{maxResults:3}):[];if(e.json){console.log(JSON.stringify({incidentId:r,matches:c},null,2));return}if(console.log(t.green(`Recorded incident ${r}`)),c.length>0){console.log(""),console.log(t.cyan("Matched patterns:"));for(let a of c)console.log(`  ${t.yellow("\u2605")} ${a.pattern.id} (${a.confidence}% confidence)`),console.log(t.gray(`     ${a.pattern.resolution.description}`));}}export{_ as triageExportCommand,ee as triageImportCommand,z as triageLinkCommand,U as triageListCommand,q as triageNoteCommand,V as triagePatternsAddCommand,X as triagePatternsDeleteCommand,K as triagePatternsListCommand,Z as triagePatternsSeedCommand,Q as triagePatternsShowCommand,Y as triagePatternsTestCommand,oe as triageRecordCommand,W as triageResolveCommand,te as triageRestoreCommand,G as triageShowCommand,ne as triageStatsCommand};