@lensmcp/protocol-types 1.26.27 → 1.26.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/lib/ai-cache-facts.js +1 -1
  2. package/lib/ai-cache-verdict.js +1 -1
  3. package/lib/ai-cache.js +3 -3
  4. package/lib/ai-call-groups.js +2 -2
  5. package/lib/ai-call-row.js +3 -3
  6. package/lib/ai-call.js +9 -9
  7. package/lib/ai-compare.js +3 -3
  8. package/lib/ai-context.js +6 -6
  9. package/lib/ai-origins.js +9 -9
  10. package/lib/ai-together.js +5 -5
  11. package/lib/bounded-clone.js +1 -1
  12. package/lib/bounded-map.js +1 -1
  13. package/lib/bounded-writer.js +1 -1
  14. package/lib/canvas-attachments.js +1 -1
  15. package/lib/canvas-catalog.js +3 -3
  16. package/lib/canvas-chat.d.ts +16 -0
  17. package/lib/canvas-chat.js +2 -2
  18. package/lib/canvas-editing.js +4 -4
  19. package/lib/canvas-frame-policy.js +1 -1
  20. package/lib/canvas-hub.js +1 -1
  21. package/lib/canvas.d.ts +77 -1
  22. package/lib/canvas.js +1 -1
  23. package/lib/capture-demand.js +1 -1
  24. package/lib/dashboard-path.js +1 -1
  25. package/lib/docker-errors.js +1 -1
  26. package/lib/docker-jobs.js +1 -1
  27. package/lib/docker-report.js +2 -2
  28. package/lib/docker-runs.js +3 -3
  29. package/lib/error-cause.js +6 -6
  30. package/lib/error-dismissal.js +1 -1
  31. package/lib/error-verdict.js +3 -3
  32. package/lib/event-loop.js +1 -1
  33. package/lib/expected-failure.js +2 -2
  34. package/lib/finding-proof.js +1 -1
  35. package/lib/flood-guard.js +1 -1
  36. package/lib/goal-design.d.ts +24 -0
  37. package/lib/goal-design.js +1 -1
  38. package/lib/host-agents.js +1 -1
  39. package/lib/lens-hosts.js +1 -1
  40. package/lib/lint-coverage.js +1 -1
  41. package/lib/lint-ignores.js +2 -2
  42. package/lib/log-query.js +1 -1
  43. package/lib/metrics-reset.js +1 -1
  44. package/lib/overseer-findings.js +1 -1
  45. package/lib/peers.js +1 -1
  46. package/lib/perf-rules.js +1 -1
  47. package/lib/pod-memory.js +1 -1
  48. package/lib/producer-health.js +1 -1
  49. package/lib/remote-instances.js +1 -1
  50. package/lib/sources.js +1 -1
  51. package/lib/static-checks.js +1 -1
  52. package/lib/system-report.js +1 -1
  53. package/lib/team.js +1 -1
  54. package/package.json +1 -1
@@ -1,3 +1,3 @@
1
- "use strict";var w=Object.defineProperty;var u=(n,e)=>w(n,"name",{value:e,configurable:!0});var A=Object.defineProperty,a=u((n,e)=>A(n,"name",{value:e,configurable:!0}),"u"),M=Object.defineProperty,i=a((n,e)=>M(n,"name",{value:e,configurable:!0}),"l");import{dockerLasted as $,dockerRunReport as x,dockerTime as h}from"./docker-report.js";export function dockerRunStanding(n){return n.run.ended?n.cleanup?.done===!0?"ended":"owed":"up"}u(dockerRunStanding,"dockerRunStanding"),a(dockerRunStanding,"dockerRunStanding"),i(dockerRunStanding,"dockerRunStanding");export function dockerRunsList(n,e={}){const o=e.now??Date.now(),r=n.map(k=>{const c=x(k,o),g=dockerRunStanding(c);return{...c,standing:g,...g==="up"&&e.runnerGone?.(k)?{runnerGone:!0}:{}}}),d=i(k=>r.filter(c=>c.standing===k).sort((c,g)=>(g.run.endedAt??g.run.startedAt??g.run.createdAt)-(c.run.endedAt??c.run.startedAt??c.run.createdAt)||c.run.id.localeCompare(g.run.id)),"of"),t=d("up"),l=d("owed"),s=d("ended"),p=e.all?s.slice(0,e.endedMax??s.length):[];return{counts:{up:t.length,owed:l.length,ended:s.length},all:e.all===!0,...e.all&&p.length<s.length?{endedMore:s.length-p.length}:{},runs:[...t,...l,...p]}}u(dockerRunsList,"dockerRunsList"),a(dockerRunsList,"dockerRunsList"),i(dockerRunsList,"dockerRunsList");const L={starting:"starting",preparing:"preparing",running:"running",cleaning:"cleaning up",passed:"passed",failed:"failed",cancelled:"cancelled",timeout:"timed out",errored:"errored",lost:"lost"};export const dockerStateWord=i(n=>L[n],"dockerStateWord");export function dockerRunSince(n){const{run:e}=n;return e.ended?e.endedAt??e.startedAt??e.createdAt:e.startedAt??e.createdAt}u(dockerRunSince,"dockerRunSince"),a(dockerRunSince,"dockerRunSince"),i(dockerRunSince,"dockerRunSince");export function dockerRunHolds(n){if(n.services.some(e=>!e.unsampled))return n.totals.budgetMb===void 0?`${n.totals.lastMb} MiB`:`${n.totals.lastMb} of ${n.totals.budgetMb} MiB`}u(dockerRunHolds,"dockerRunHolds"),a(dockerRunHolds,"dockerRunHolds"),i(dockerRunHolds,"dockerRunHolds");export const RUNNER_GONE="its runner is gone: nothing runs it any more \u2014 its guard, or the sweep, writes its end and takes its stack down";export function dockerRunRemarks(n){const e=[];n.runnerGone&&!n.run.ended&&e.push(RUNNER_GONE);const o=n.services.filter(l=>l.overMb!==void 0);o.length&&e.push(`OVER its budget: ${o.map(l=>`${l.name} by ${l.overMb} MiB`).join(", ")}`);const r=n.kills.length+(n.killsMore??0),d=[...new Set(n.kills.map(l=>l.service))];r&&e.push(`killed for memory: ${r}${d.length?` (${d.join(", ")})`:""}`),n.engineLost&&e.push(`Docker stopped answering at ${h(n.engineLost.at)}${n.engineLost.backAt!==void 0?`, and answered again at ${h(n.engineLost.backAt)}`:""}`);const{cleanup:t}=n;return n.run.ended&&!t?e.push("cleanup OWED: none is recorded \u2014 its guard, or the sweep, has it"):t&&!t.done&&e.push(`cleanup OWED: ${t.why??"something that carries the run's labels is left"}${t.left?.length?` \u2014 left: ${t.left.join(", ")}`:""}`),t?.unlabeled?.length&&e.push(`in its Compose project without the run's labels, never removed: ${t.unlabeled.join(", ")}`),e}u(dockerRunRemarks,"dockerRunRemarks"),a(dockerRunRemarks,"dockerRunRemarks"),i(dockerRunRemarks,"dockerRunRemarks");function R(n){const{run:e}=n,o=dockerRunSince(n),r=e.ended?`ended ${h(o)}${e.ranMs!==void 0?` after ${$(e.ranMs)}`:""}`:e.startedAt!==void 0?`for ${$(e.ranMs??0)}, since ${h(o)}`:`since ${h(o)}`,d=n.standing==="up"?dockerRunHolds(n):void 0,t=[[e.job,`${dockerStateWord(e.state)}${n.standing==="owed"?", cleanup OWED":n.runnerGone?", its runner GONE":""}`,r,...d?[`holds ${d}`]:[],e.id].join(" ")];e.stage&&!e.ended&&t.push(` stage: ${e.stage}`),e.url?t.push(` URL: ${e.url}`):e.urlNote&&!e.ended&&t.push(` no URL: ${e.urlNote}`),e.note&&t.push(` ${e.note}`);for(const l of dockerRunRemarks(n))t.push(` ${l}`);return t}u(R,"$"),a(R,"R"),i(R,"runLines");const v=i((n,e,o)=>`${n} ${n===1?e:o}`,"plural");export function dockerRunsText(n){const{counts:e}=n;if(!(e.up+e.owed+e.ended))return["This home's registry holds no Docker run.","A job is declared in the checkout's lensmcp.json \u2192 jobs, and started with `lensmcp docker run <job>`."].join(`
2
- `);const o=e.ended?` \xB7 ${v(e.ended,"ended one is","ended ones are")} kept${n.all?"":" (--all lists them)"}`:"",r=[`Docker runs of this home \u2014 ${e.up} up, ${e.owed?`${v(e.owed,"owes","owe")} a cleanup`:"none owes a cleanup"}${o}`];n.runs.length||r.push(" Nothing of this home is in Docker now.");for(const d of n.runs)r.push(...R(d).map(t=>` ${t}`));return n.endedMore&&r.push(` \u2026 and ${n.endedMore} more ended, not listed`),e.owed&&r.push("","A cleanup that is owed is taken by the run's guard, then by the sweep: `lensmcp docker sweep --dry-run` says what one would take down."),r.join(`
3
- `)}u(dockerRunsText,"dockerRunsText"),a(dockerRunsText,"dockerRunsText"),i(dockerRunsText,"dockerRunsText");export const BLOCK_MAX_SERVICES=8,BLOCK_MAX_KILLS=5;const j=8,b=300,m=i(n=>n.length>b?`${n.slice(0,b-1)}\u2026`:n,"cut"),f=i(n=>n?.length?n.slice(0,j).map(e=>e.slice(0,120)):void 0,"names");export function dockerRunBlock(n){const{run:e,cleanup:o,engineLost:r}=n,d=n.services.slice(0,BLOCK_MAX_SERVICES),t=n.kills.slice(0,BLOCK_MAX_KILLS),l=n.kills.length-t.length+(n.killsMore??0),s=f(o?.left),p=f(o?.unlabeled),k=f(r?.killed);return{run:e.id,job:e.job,kind:e.kind,state:e.state,standing:dockerRunStanding(n),...n.runnerGone&&!e.ended?{runnerGone:!0}:{},project:e.project,...e.context?{context:e.context}:{},...e.stage?{stage:e.stage}:{},...e.url?{url:e.url}:{},...e.urlNote?{urlNote:m(e.urlNote)}:{},...e.note?{note:m(e.note)}:{},...e.startedAt!==void 0?{startedAt:e.startedAt}:{},...e.endedAt!==void 0?{endedAt:e.endedAt}:{},...e.ranMs!==void 0?{ranMs:e.ranMs}:{},...e.exit?{exit:e.exit}:{},...n.vm?{vm:n.vm}:{},services:d,...n.services.length>d.length?{servicesMore:n.services.length-d.length}:{},totals:n.totals,kills:t.map(c=>({...c,container:c.container.slice(0,12)})),...l?{killsMore:l}:{},...r?{engineLost:{at:r.at,why:m(r.why),...r.backAt!==void 0?{backAt:r.backAt}:{},...k?{killed:k}:{}}}:{},...o?{cleanup:{by:o.by,at:o.at,done:o.done,...s?{left:s}:{},...p?{unlabeled:p}:{},...o.why?{why:m(o.why)}:{}}}:{}}}u(dockerRunBlock,"dockerRunBlock"),a(dockerRunBlock,"dockerRunBlock"),i(dockerRunBlock,"dockerRunBlock");export function dockerRunBlockLess(n){if(n.services&&n.services.length>1)return{...n,services:n.services.slice(0,-1),servicesMore:(n.servicesMore??0)+1};if(n.kills&&n.kills.length>1)return{...n,kills:n.kills.slice(0,-1),killsMore:(n.killsMore??0)+1}}u(dockerRunBlockLess,"dockerRunBlockLess"),a(dockerRunBlockLess,"dockerRunBlockLess"),i(dockerRunBlockLess,"dockerRunBlockLess");export const PAGE_MAX_ROWS=50;const y=["queued","running"];export function dockerRemoteStanding(n){return n.state==="lost"?"lost":y.includes(n.state)?"up":"ended"}u(dockerRemoteStanding,"dockerRemoteStanding"),a(dockerRemoteStanding,"dockerRemoteStanding"),i(dockerRemoteStanding,"dockerRemoteStanding");export function dockerRemoteRunsList(n,e={}){const o=i(s=>s.completedAt??s.startedAt??s.queuedAt,"since"),r=[...n].sort((s,p)=>o(p)-o(s)||s.run.localeCompare(p.run)),d=r.filter(s=>dockerRemoteStanding(s)==="up"),t=r.filter(s=>dockerRemoteStanding(s)!=="up"),l=t.slice(0,e.endedMax??t.length);return{counts:{up:d.length,lost:t.filter(s=>s.state==="lost").length,ended:t.filter(s=>s.state!=="lost").length},runs:[...d,...l],...l.length<t.length?{endedMore:t.length-l.length}:{}}}u(dockerRemoteRunsList,"dockerRemoteRunsList"),a(dockerRemoteRunsList,"dockerRemoteRunsList"),i(dockerRemoteRunsList,"dockerRemoteRunsList");
1
+ "use strict";var R=Object.defineProperty;var u=(t,e)=>R(t,"name",{value:e,configurable:!0});var b=Object.defineProperty,i=u((t,e)=>b(t,"name",{value:e,configurable:!0}),"l");import{dockerLasted as m,dockerRunReport as A,dockerTime as g}from"./docker-report.js";export function dockerRunStanding(t){return t.run.ended?t.cleanup?.done===!0?"ended":"owed":"up"}u(dockerRunStanding,"dockerRunStanding"),i(dockerRunStanding,"dockerRunStanding");export function dockerRunsList(t,e={}){const o=e.now??Date.now(),s=t.map(p=>{const a=A(p,o),h=dockerRunStanding(a);return{...a,standing:h,...h==="up"&&e.runnerGone?.(p)?{runnerGone:!0}:{}}}),d=i(p=>s.filter(a=>a.standing===p).sort((a,h)=>(h.run.endedAt??h.run.startedAt??h.run.createdAt)-(a.run.endedAt??a.run.startedAt??a.run.createdAt)||a.run.id.localeCompare(h.run.id)),"of"),n=d("up"),l=d("owed"),r=d("ended"),c=e.all?r.slice(0,e.endedMax??r.length):[];return{counts:{up:n.length,owed:l.length,ended:r.length},all:e.all===!0,...e.all&&c.length<r.length?{endedMore:r.length-c.length}:{},runs:[...n,...l,...c]}}u(dockerRunsList,"dockerRunsList"),i(dockerRunsList,"dockerRunsList");const M={starting:"starting",preparing:"preparing",running:"running",cleaning:"cleaning up",passed:"passed",failed:"failed",cancelled:"cancelled",timeout:"timed out",errored:"errored",lost:"lost"};export const dockerStateWord=i(t=>M[t],"dockerStateWord");export function dockerRunSince(t){const{run:e}=t;return e.ended?e.endedAt??e.startedAt??e.createdAt:e.startedAt??e.createdAt}u(dockerRunSince,"dockerRunSince"),i(dockerRunSince,"dockerRunSince");export function dockerRunHolds(t){if(t.services.some(e=>!e.unsampled))return t.totals.budgetMb===void 0?`${t.totals.lastMb} MiB`:`${t.totals.lastMb} of ${t.totals.budgetMb} MiB`}u(dockerRunHolds,"dockerRunHolds"),i(dockerRunHolds,"dockerRunHolds");export const RUNNER_GONE="its runner is gone: nothing runs it any more \u2014 its guard, or the sweep, writes its end and takes its stack down";export function dockerRunRemarks(t){const e=[];t.runnerGone&&!t.run.ended&&e.push(RUNNER_GONE);const o=t.services.filter(l=>l.overMb!==void 0);o.length&&e.push(`OVER its budget: ${o.map(l=>`${l.name} by ${l.overMb} MiB`).join(", ")}`);const s=t.kills.length+(t.killsMore??0),d=[...new Set(t.kills.map(l=>l.service))];s&&e.push(`killed for memory: ${s}${d.length?` (${d.join(", ")})`:""}`),t.engineLost&&e.push(`Docker stopped answering at ${g(t.engineLost.at)}${t.engineLost.backAt!==void 0?`, and answered again at ${g(t.engineLost.backAt)}`:""}`);const{cleanup:n}=t;return t.run.ended&&!n?e.push("cleanup OWED: none is recorded \u2014 its guard, or the sweep, has it"):n&&!n.done&&e.push(`cleanup OWED: ${n.why??"something that carries the run's labels is left"}${n.left?.length?` \u2014 left: ${n.left.join(", ")}`:""}`),n?.unlabeled?.length&&e.push(`in its Compose project without the run's labels, never removed: ${n.unlabeled.join(", ")}`),e}u(dockerRunRemarks,"dockerRunRemarks"),i(dockerRunRemarks,"dockerRunRemarks");function $(t){const{run:e}=t,o=dockerRunSince(t),s=e.ended?`ended ${g(o)}${e.ranMs!==void 0?` after ${m(e.ranMs)}`:""}`:e.startedAt!==void 0?`for ${m(e.ranMs??0)}, since ${g(o)}`:`since ${g(o)}`,d=t.standing==="up"?dockerRunHolds(t):void 0,n=[[e.job,`${dockerStateWord(e.state)}${t.standing==="owed"?", cleanup OWED":t.runnerGone?", its runner GONE":""}`,s,...d?[`holds ${d}`]:[],e.id].join(" ")];e.stage&&!e.ended&&n.push(` stage: ${e.stage}`),e.url?n.push(` URL: ${e.url}`):e.urlNote&&!e.ended&&n.push(` no URL: ${e.urlNote}`),e.note&&n.push(` ${e.note}`);for(const l of dockerRunRemarks(t))n.push(` ${l}`);return n}u($,"R"),i($,"runLines");const v=i((t,e,o)=>`${t} ${t===1?e:o}`,"plural");export function dockerRunsText(t){const{counts:e}=t;if(!(e.up+e.owed+e.ended))return["This home's registry holds no Docker run.","A job is declared in the checkout's lensmcp.json \u2192 jobs, and started with `lensmcp docker run <job>`."].join(`
2
+ `);const o=e.ended?` \xB7 ${v(e.ended,"ended one is","ended ones are")} kept${t.all?"":" (--all lists them)"}`:"",s=[`Docker runs of this home \u2014 ${e.up} up, ${e.owed?`${v(e.owed,"owes","owe")} a cleanup`:"none owes a cleanup"}${o}`];t.runs.length||s.push(" Nothing of this home is in Docker now.");for(const d of t.runs)s.push(...$(d).map(n=>` ${n}`));return t.endedMore&&s.push(` \u2026 and ${t.endedMore} more ended, not listed`),e.owed&&s.push("","A cleanup that is owed is taken by the run's guard, then by the sweep: `lensmcp docker sweep --dry-run` says what one would take down."),s.join(`
3
+ `)}u(dockerRunsText,"dockerRunsText"),i(dockerRunsText,"dockerRunsText");export const BLOCK_MAX_SERVICES=8,BLOCK_MAX_KILLS=5;const x=8,w=300,k=i(t=>t.length>w?`${t.slice(0,w-1)}\u2026`:t,"cut"),f=i(t=>t?.length?t.slice(0,x).map(e=>e.slice(0,120)):void 0,"names");export function dockerRunBlock(t){const{run:e,cleanup:o,engineLost:s}=t,d=t.services.slice(0,BLOCK_MAX_SERVICES),n=t.kills.slice(0,BLOCK_MAX_KILLS),l=t.kills.length-n.length+(t.killsMore??0),r=f(o?.left),c=f(o?.unlabeled),p=f(s?.killed);return{run:e.id,job:e.job,kind:e.kind,state:e.state,standing:dockerRunStanding(t),...t.runnerGone&&!e.ended?{runnerGone:!0}:{},project:e.project,...e.context?{context:e.context}:{},...e.stage?{stage:e.stage}:{},...e.url?{url:e.url}:{},...e.urlNote?{urlNote:k(e.urlNote)}:{},...e.note?{note:k(e.note)}:{},...e.startedAt!==void 0?{startedAt:e.startedAt}:{},...e.endedAt!==void 0?{endedAt:e.endedAt}:{},...e.ranMs!==void 0?{ranMs:e.ranMs}:{},...e.exit?{exit:e.exit}:{},...t.vm?{vm:t.vm}:{},services:d,...t.services.length>d.length?{servicesMore:t.services.length-d.length}:{},totals:t.totals,kills:n.map(a=>({...a,container:a.container.slice(0,12)})),...l?{killsMore:l}:{},...s?{engineLost:{at:s.at,why:k(s.why),...s.backAt!==void 0?{backAt:s.backAt}:{},...p?{killed:p}:{}}}:{},...o?{cleanup:{by:o.by,at:o.at,done:o.done,...r?{left:r}:{},...c?{unlabeled:c}:{},...o.why?{why:k(o.why)}:{}}}:{}}}u(dockerRunBlock,"dockerRunBlock"),i(dockerRunBlock,"dockerRunBlock");export function dockerRunBlockLess(t){if(t.services&&t.services.length>1)return{...t,services:t.services.slice(0,-1),servicesMore:(t.servicesMore??0)+1};if(t.kills&&t.kills.length>1)return{...t,kills:t.kills.slice(0,-1),killsMore:(t.killsMore??0)+1}}u(dockerRunBlockLess,"dockerRunBlockLess"),i(dockerRunBlockLess,"dockerRunBlockLess");export const PAGE_MAX_ROWS=50;const L=["queued","running"];export function dockerRemoteStanding(t){return t.state==="lost"?"lost":L.includes(t.state)?"up":"ended"}u(dockerRemoteStanding,"dockerRemoteStanding"),i(dockerRemoteStanding,"dockerRemoteStanding");export function dockerRemoteRunsList(t,e={}){const o=i(r=>r.completedAt??r.startedAt??r.queuedAt,"since"),s=[...t].sort((r,c)=>o(c)-o(r)||r.run.localeCompare(c.run)),d=s.filter(r=>dockerRemoteStanding(r)==="up"),n=s.filter(r=>dockerRemoteStanding(r)!=="up"),l=n.slice(0,e.endedMax??n.length);return{counts:{up:d.length,lost:n.filter(r=>r.state==="lost").length,ended:n.filter(r=>r.state!=="lost").length},runs:[...d,...l],...l.length<n.length?{endedMore:n.length-l.length}:{}}}u(dockerRemoteRunsList,"dockerRemoteRunsList"),i(dockerRemoteRunsList,"dockerRemoteRunsList");
@@ -1,6 +1,6 @@
1
- "use strict";var g=Object.defineProperty;var s=(e,t)=>g(e,"name",{value:t,configurable:!0});var y=Object.defineProperty,c=s((e,t)=>y(e,"name",{value:t,configurable:!0}),"s"),E=Object.defineProperty,a=c((e,t)=>E(e,"name",{value:t,configurable:!0}),"n");export function joinId(e,t){const i=a(n=>n.replace(/%/g,"%25").replace(/:/g,"%3A"),"esc");return[e,...t.map(n=>i(n===void 0?"":String(n)))].join(":")}s(joinId,"joinId"),c(joinId,"joinId"),a(joinId,"joinId");export function foldMessage(e){return e?e.split(`
2
- `)[0].replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,"<id>").replace(/\b[0-9A-HJKMNP-TV-Z]{26}\b/g,"<id>").replace(/0x[0-9a-f]+/gi,"<hex>").replace(/\b[0-9a-f]{12,}\b/gi,"<id>").replace(/\d+/g,"#").trim().slice(0,140):""}s(foldMessage,"foldMessage"),c(foldMessage,"foldMessage"),a(foldMessage,"foldMessage");const x=a(e=>!!e&&typeof e=="object"&&typeof e.message=="string","isValidationIssue"),v=a(e=>Array.isArray(e)&&e.length?e.map(String).join("."):"(root)","issuePath"),p=3;export function readableErrorMessage(e){const t=e?.trim()??"",i=t.indexOf("["),n=t.slice(0,Math.max(i,0));if(i<0||!/^(?:[A-Za-z_$][\w$]*:\s*)?$/.test(n))return e;let d;try{d=JSON.parse(t.slice(i))}catch{return e}if(!Array.isArray(d)||!d.length||!d.every(x))return e;const o=d.map(m=>`${v(m.path)}: ${m.message}`),r=o.length===1?"1 issue":`${o.length} issues`,h=o.length>p?` (+${o.length-p} more)`:"";return[`${n}Validation failed (${r}): ${o.slice(0,p).join("; ")}${h}`,...o.map(m=>` ${m}`)].join(`
3
- `)}s(readableErrorMessage,"readableErrorMessage"),c(readableErrorMessage,"readableErrorMessage"),a(readableErrorMessage,"readableErrorMessage");const w=/^(?:Uncaught\s+(?:\(in promise\)\s+)?)?((?:[A-Za-z_$][\w$]*)?(?:Error|Exception|Failure|Fault|Rejection))(?:\s*\[[^\]]*\])?:\s*(.+)$/;function l(e){const t=w.exec((e??"").split(`
4
- `)[0].trim());return t?{name:t[1],message:t[2].trim()}:void 0}s(l,"h"),c(l,"u"),a(l,"named");export function appFrameOf(e){for(const t of(e??"").split(`
5
- `)){const i=/^\s*at\s+(.+)$/.exec(t);if(!i||/node_modules|node:internal|node:async_hooks|\(native\)|<anonymous>|\(internal\//.test(i[1]))continue;const n=/\(?([^()\s]+?):(\d+)(?::\d+)?\)?$/.exec(i[1].trim());return n?`${n[1].replace(/^.*?\/(?=(?:src|apps|libs)\/)/,"")}:${n[2]}`:i[1].trim()}}s(appFrameOf,"appFrameOf"),c(appFrameOf,"appFrameOf"),a(appFrameOf,"appFrameOf");export function errorCause(e){const t=readableErrorMessage(e.message),i=l(e.stack),n=l(t),d=l(e.title),o=e.name?.trim()||i?.name||n?.name||d?.name;if(!o)return;let r=(t!==e.message?t:void 0)??(i&&i.name===o?i.message:void 0)??t??d?.message??e.title??"";const h=l(r);h&&h.name===o&&(r=h.message),r=r.split(`
6
- `)[0].trim();const m=appFrameOf(e.stack),f=b.has(errorHeadline({name:o,message:r})?.id??"");return{id:joinId("cause",[o,foldMessage(r),f?void 0:m]),errorName:o,message:r,...m?{frame:m}:{}}}s(errorCause,"errorCause"),c(errorCause,"errorCause"),a(errorCause,"errorCause");const b=new Set(["missing-column","missing-table","connection-refused","out-of-memory"]);export function causeIdWithoutFrame(e){return joinId("cause",[e.errorName,foldMessage(e.message),void 0])}s(causeIdWithoutFrame,"causeIdWithoutFrame"),c(causeIdWithoutFrame,"causeIdWithoutFrame"),a(causeIdWithoutFrame,"causeIdWithoutFrame");const u=a(e=>e?` (\xAB${e}\xBB)`:"","q");export const ERROR_HEADLINES=[{id:"missing-column",match:a(e=>/column "?([\w.]+)"?(?: of relation "?[\w.]+"?)? does not exist|Unknown column '([^']+)'|ER_BAD_FIELD_ERROR/i.exec(e),"match"),say:a(e=>({headline:`The code expects a database column${u(e===!0?void 0:e[1]??e[2])} the database doesn't have`,hint:"Run the migrations, or add the migration the entity change needs."}),"say")},{id:"missing-table",match:a(e=>/relation "?([\w.]+)"? does not exist|Table '([^']+)' doesn't exist|ER_NO_SUCH_TABLE/i.exec(e),"match"),say:a(e=>({headline:`The code expects a database table${u(e===!0?void 0:e[1]??e[2])} the database doesn't have`,hint:"Run the migrations against this database."}),"say")},{id:"unique-violation",match:a((e,t)=>/duplicate key value violates unique constraint "?([\w.]+)"?|Duplicate entry '[^']*' for key '([^']+)'|ER_DUP_ENTRY/i.exec(e)||t.code==="23505","match"),say:a(e=>({headline:`A row with the same unique value already exists${u(e===!0?void 0:e[1]??e[2])}`,hint:"The code inserts a duplicate: look up the existing row first, or upsert."}),"say")},{id:"foreign-key-violation",match:a((e,t)=>/violates foreign key constraint "?([\w.]+)"?|a foreign key constraint fails|ER_NO_REFERENCED_ROW|ER_ROW_IS_REFERENCED/i.exec(e)||t.code==="23503","match"),say:a(e=>({headline:`A row points at a row that doesn't exist, or a row still in use was deleted${u(e===!0?void 0:e[1])}`,hint:"Create the referenced row first, or delete the rows that point at it."}),"say")},{id:"connection-refused",match:a((e,t)=>/ECONNREFUSED|connection refused|connect ECONNREFUSED/i.exec(e)||t.code==="ECONNREFUSED","match"),say:a(()=>({headline:"A service the code connects to is not running, or not listening where the code looks",hint:"Start it (database, cache, broker or API), or fix its host and port."}),"say")},{id:"out-of-memory",match:a((e,t)=>/heap out of memory|JavaScript heap|out of memory|ENOMEM|Allocation failed/i.exec(e)||t.code==="ENOMEM","match"),say:a(()=>({headline:"The process ran out of memory",hint:"Something holds or loads too much at once \u2014 look for an unbounded list, cache or query."}),"say")},{id:"jwt-expired",match:a((e,t)=>/jwt expired|token expired/i.exec(e)||t.name==="TokenExpiredError","match"),say:a(()=>({headline:"A sign-in token expired",hint:"Sign in again; if it keeps happening, the client is not refreshing its token."}),"say")},{id:"jwt-invalid",match:a((e,t)=>/jwt malformed|invalid signature|invalid token|jwt must be provided|jwt audience invalid|jwt issuer invalid/i.exec(e)||t.name==="JsonWebTokenError","match"),say:a(()=>({headline:"A sign-in token is not valid here",hint:"Its signature, audience or issuer does not match what this service expects."}),"say")},{id:"timeout",match:a((e,t)=>/ETIMEDOUT|ESOCKETTIMEDOUT|timed? ?out|timeout exceeded|statement timeout|canceling statement due to|Query read timeout/i.exec(e)||t.name==="TimeoutError"||t.code==="ETIMEDOUT","match"),say:a(()=>({headline:"Something took too long and was cut off",hint:"A slow query, a busy dependency or a lock \u2014 open the failing step to see which."}),"say")},{id:"unauthorized",match:a((e,t)=>t.status===401||t.name==="UnauthorizedException"||/^Unauthorized$/i.test(e.trim()),"match"),say:a(()=>({headline:"The request was not signed in (401)",hint:"It came without a valid session or token."}),"say")},{id:"forbidden",match:a((e,t)=>t.status===403||t.name==="ForbiddenException"||/^Forbidden(?: resource)?$/i.test(e.trim()),"match"),say:a(()=>({headline:"The signed-in user is not allowed to do this (403)",hint:"A role or permission check refused it."}),"say")}];export function errorHeadline(e){const t=[e.code,e.message].filter(Boolean).join(" ");for(const i of ERROR_HEADLINES){const n=i.match(t,e);if(n)return{id:i.id,...i.say(n)}}}s(errorHeadline,"errorHeadline"),c(errorHeadline,"errorHeadline"),a(errorHeadline,"errorHeadline");
1
+ "use strict";var f=Object.defineProperty;var s=(e,t)=>f(e,"name",{value:t,configurable:!0});var g=Object.defineProperty,i=s((e,t)=>g(e,"name",{value:t,configurable:!0}),"n");export function joinId(e,t){const a=i(n=>n.replace(/%/g,"%25").replace(/:/g,"%3A"),"esc");return[e,...t.map(n=>a(n===void 0?"":String(n)))].join(":")}s(joinId,"joinId"),i(joinId,"joinId");export function foldMessage(e){return e?e.split(`
2
+ `)[0].replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,"<id>").replace(/\b[0-9A-HJKMNP-TV-Z]{26}\b/g,"<id>").replace(/0x[0-9a-f]+/gi,"<hex>").replace(/\b[0-9a-f]{12,}\b/gi,"<id>").replace(/\d+/g,"#").trim().slice(0,140):""}s(foldMessage,"foldMessage"),i(foldMessage,"foldMessage");const y=i(e=>!!e&&typeof e=="object"&&typeof e.message=="string","isValidationIssue"),E=i(e=>Array.isArray(e)&&e.length?e.map(String).join("."):"(root)","issuePath"),u=3;export function readableErrorMessage(e){const t=e?.trim()??"",a=t.indexOf("["),n=t.slice(0,Math.max(a,0));if(a<0||!/^(?:[A-Za-z_$][\w$]*:\s*)?$/.test(n))return e;let c;try{c=JSON.parse(t.slice(a))}catch{return e}if(!Array.isArray(c)||!c.length||!c.every(y))return e;const o=c.map(d=>`${E(d.path)}: ${d.message}`),r=o.length===1?"1 issue":`${o.length} issues`,m=o.length>u?` (+${o.length-u} more)`:"";return[`${n}Validation failed (${r}): ${o.slice(0,u).join("; ")}${m}`,...o.map(d=>` ${d}`)].join(`
3
+ `)}s(readableErrorMessage,"readableErrorMessage"),i(readableErrorMessage,"readableErrorMessage");const x=/^(?:Uncaught\s+(?:\(in promise\)\s+)?)?((?:[A-Za-z_$][\w$]*)?(?:Error|Exception|Failure|Fault|Rejection))(?:\s*\[[^\]]*\])?:\s*(.+)$/;function h(e){const t=x.exec((e??"").split(`
4
+ `)[0].trim());return t?{name:t[1],message:t[2].trim()}:void 0}s(h,"u"),i(h,"named");export function appFrameOf(e){for(const t of(e??"").split(`
5
+ `)){const a=/^\s*at\s+(.+)$/.exec(t);if(!a||/node_modules|node:internal|node:async_hooks|\(native\)|<anonymous>|\(internal\//.test(a[1]))continue;const n=/\(?([^()\s]+?):(\d+)(?::\d+)?\)?$/.exec(a[1].trim());return n?`${n[1].replace(/^.*?\/(?=(?:src|apps|libs)\/)/,"")}:${n[2]}`:a[1].trim()}}s(appFrameOf,"appFrameOf"),i(appFrameOf,"appFrameOf");export function errorCause(e){const t=readableErrorMessage(e.message),a=h(e.stack),n=h(t),c=h(e.title),o=e.name?.trim()||a?.name||n?.name||c?.name;if(!o)return;let r=(t!==e.message?t:void 0)??(a&&a.name===o?a.message:void 0)??t??c?.message??e.title??"";const m=h(r);m&&m.name===o&&(r=m.message),r=r.split(`
6
+ `)[0].trim();const d=appFrameOf(e.stack),p=v.has(errorHeadline({name:o,message:r})?.id??"");return{id:joinId("cause",[o,foldMessage(r),p?void 0:d]),errorName:o,message:r,...d?{frame:d}:{}}}s(errorCause,"errorCause"),i(errorCause,"errorCause");const v=new Set(["missing-column","missing-table","connection-refused","out-of-memory"]);export function causeIdWithoutFrame(e){return joinId("cause",[e.errorName,foldMessage(e.message),void 0])}s(causeIdWithoutFrame,"causeIdWithoutFrame"),i(causeIdWithoutFrame,"causeIdWithoutFrame");const l=i(e=>e?` (\xAB${e}\xBB)`:"","q");export const ERROR_HEADLINES=[{id:"missing-column",match:i(e=>/column "?([\w.]+)"?(?: of relation "?[\w.]+"?)? does not exist|Unknown column '([^']+)'|ER_BAD_FIELD_ERROR/i.exec(e),"match"),say:i(e=>({headline:`The code expects a database column${l(e===!0?void 0:e[1]??e[2])} the database doesn't have`,hint:"Run the migrations, or add the migration the entity change needs."}),"say")},{id:"missing-table",match:i(e=>/relation "?([\w.]+)"? does not exist|Table '([^']+)' doesn't exist|ER_NO_SUCH_TABLE/i.exec(e),"match"),say:i(e=>({headline:`The code expects a database table${l(e===!0?void 0:e[1]??e[2])} the database doesn't have`,hint:"Run the migrations against this database."}),"say")},{id:"unique-violation",match:i((e,t)=>/duplicate key value violates unique constraint "?([\w.]+)"?|Duplicate entry '[^']*' for key '([^']+)'|ER_DUP_ENTRY/i.exec(e)||t.code==="23505","match"),say:i(e=>({headline:`A row with the same unique value already exists${l(e===!0?void 0:e[1]??e[2])}`,hint:"The code inserts a duplicate: look up the existing row first, or upsert."}),"say")},{id:"foreign-key-violation",match:i((e,t)=>/violates foreign key constraint "?([\w.]+)"?|a foreign key constraint fails|ER_NO_REFERENCED_ROW|ER_ROW_IS_REFERENCED/i.exec(e)||t.code==="23503","match"),say:i(e=>({headline:`A row points at a row that doesn't exist, or a row still in use was deleted${l(e===!0?void 0:e[1])}`,hint:"Create the referenced row first, or delete the rows that point at it."}),"say")},{id:"connection-refused",match:i((e,t)=>/ECONNREFUSED|connection refused|connect ECONNREFUSED/i.exec(e)||t.code==="ECONNREFUSED","match"),say:i(()=>({headline:"A service the code connects to is not running, or not listening where the code looks",hint:"Start it (database, cache, broker or API), or fix its host and port."}),"say")},{id:"out-of-memory",match:i((e,t)=>/heap out of memory|JavaScript heap|out of memory|ENOMEM|Allocation failed/i.exec(e)||t.code==="ENOMEM","match"),say:i(()=>({headline:"The process ran out of memory",hint:"Something holds or loads too much at once \u2014 look for an unbounded list, cache or query."}),"say")},{id:"jwt-expired",match:i((e,t)=>/jwt expired|token expired/i.exec(e)||t.name==="TokenExpiredError","match"),say:i(()=>({headline:"A sign-in token expired",hint:"Sign in again; if it keeps happening, the client is not refreshing its token."}),"say")},{id:"jwt-invalid",match:i((e,t)=>/jwt malformed|invalid signature|invalid token|jwt must be provided|jwt audience invalid|jwt issuer invalid/i.exec(e)||t.name==="JsonWebTokenError","match"),say:i(()=>({headline:"A sign-in token is not valid here",hint:"Its signature, audience or issuer does not match what this service expects."}),"say")},{id:"timeout",match:i((e,t)=>/ETIMEDOUT|ESOCKETTIMEDOUT|timed? ?out|timeout exceeded|statement timeout|canceling statement due to|Query read timeout/i.exec(e)||t.name==="TimeoutError"||t.code==="ETIMEDOUT","match"),say:i(()=>({headline:"Something took too long and was cut off",hint:"A slow query, a busy dependency or a lock \u2014 open the failing step to see which."}),"say")},{id:"unauthorized",match:i((e,t)=>t.status===401||t.name==="UnauthorizedException"||/^Unauthorized$/i.test(e.trim()),"match"),say:i(()=>({headline:"The request was not signed in (401)",hint:"It came without a valid session or token."}),"say")},{id:"forbidden",match:i((e,t)=>t.status===403||t.name==="ForbiddenException"||/^Forbidden(?: resource)?$/i.test(e.trim()),"match"),say:i(()=>({headline:"The signed-in user is not allowed to do this (403)",hint:"A role or permission check refused it."}),"say")}];export function errorHeadline(e){const t=[e.code,e.message].filter(Boolean).join(" ");for(const a of ERROR_HEADLINES){const n=a.match(t,e);if(n)return{id:a.id,...a.say(n)}}}s(errorHeadline,"errorHeadline"),i(errorHeadline,"errorHeadline");
@@ -1 +1 @@
1
- "use strict";var E=Object.defineProperty;var s=(e,r)=>E(e,"name",{value:r,configurable:!0});var m=Object.defineProperty,c=s((e,r)=>m(e,"name",{value:r,configurable:!0}),"s"),p=Object.defineProperty,l=c((e,r)=>p(e,"name",{value:r,configurable:!0}),"s");export const ERROR_DISMISSED="error-dismissed",ERROR_RESTORED="error-restored",LENS_EVENT_SOURCE="lens",MAX_DISMISSAL_EVENT_IDS=200;const y=2048;export const MAX_DISMISSAL_REASON_CHARS=500;const b=300,I=new Set(["dashboard","cli","agent"]);export function readErrorDismissal(e){if(e.source!==LENS_EVENT_SOURCE||!e.raw||typeof e.raw!="object")return;const r=e.raw,i=r.groupId;if(typeof i!="string"||i.length===0||i.length>2048)return;if(r.kind===ERROR_RESTORED)return{kind:ERROR_RESTORED,groupId:i};if(r.kind!==ERROR_DISMISSED)return;const n=r.until;if(typeof n!="number"||!Number.isFinite(n))return;const f=Array.isArray(r.eventIds)?r.eventIds.filter(t=>typeof t=="string"&&t.length>0).slice(0,200):[],o=I.has(r.by)?r.by:void 0,a=l((t,S)=>typeof t=="string"&&t.trim()?t.trim().slice(0,S):void 0,"text"),d=a(r.reason,500),u=a(r.title,300);return{kind:ERROR_DISMISSED,groupId:i,until:Math.min(n,e.timestamp),eventIds:f,...o?{by:o}:{},...d?{reason:d}:{},...u?{title:u}:{}}}s(readErrorDismissal,"readErrorDismissal"),c(readErrorDismissal,"readErrorDismissal"),l(readErrorDismissal,"readErrorDismissal");
1
+ "use strict";var f=Object.defineProperty;var s=(t,r)=>f(t,"name",{value:r,configurable:!0});var E=Object.defineProperty,S=s((t,r)=>E(t,"name",{value:r,configurable:!0}),"s");export const ERROR_DISMISSED="error-dismissed",ERROR_RESTORED="error-restored",LENS_EVENT_SOURCE="lens",MAX_DISMISSAL_EVENT_IDS=200;const g=2048;export const MAX_DISMISSAL_REASON_CHARS=500;const m=300,I=new Set(["dashboard","cli","agent"]);export function readErrorDismissal(t){if(t.source!==LENS_EVENT_SOURCE||!t.raw||typeof t.raw!="object")return;const r=t.raw,i=r.groupId;if(typeof i!="string"||i.length===0||i.length>2048)return;if(r.kind===ERROR_RESTORED)return{kind:ERROR_RESTORED,groupId:i};if(r.kind!==ERROR_DISMISSED)return;const n=r.until;if(typeof n!="number"||!Number.isFinite(n))return;const c=Array.isArray(r.eventIds)?r.eventIds.filter(e=>typeof e=="string"&&e.length>0).slice(0,200):[],o=I.has(r.by)?r.by:void 0,a=S((e,l)=>typeof e=="string"&&e.trim()?e.trim().slice(0,l):void 0,"text"),d=a(r.reason,500),u=a(r.title,300);return{kind:ERROR_DISMISSED,groupId:i,until:Math.min(n,t.timestamp),eventIds:c,...o?{by:o}:{},...d?{reason:d}:{},...u?{title:u}:{}}}s(readErrorDismissal,"readErrorDismissal"),S(readErrorDismissal,"readErrorDismissal");
@@ -1,3 +1,3 @@
1
- "use strict";var j=Object.defineProperty;var f=(t,e)=>j(t,"name",{value:e,configurable:!0});var N=Object.defineProperty,w=f((t,e)=>N(t,"name",{value:e,configurable:!0}),"p"),V=Object.defineProperty,c=w((t,e)=>V(t,"name",{value:e,configurable:!0}),"a");import{LENS_EVENT_SOURCE as O}from"./error-dismissal.js";export const NOT_A_BUG_KINDS=["restart","test-expected","auth-expired"];export function verdictOccurrence(t,e){return{at:t,...e.service?{service:e.service}:{},...e.flowId?{flowId:e.flowId}:{},...e.requestId?{requestId:e.requestId}:{},...e.status!==void 0?{status:e.status}:{},...e.method?{method:e.method}:{},...e.routes?{routes:e.routes}:{},...e.errorName?{errorName:e.errorName}:{},...e.message?{message:e.message}:{}}}f(verdictOccurrence,"verdictOccurrence"),w(verdictOccurrence,"verdictOccurrence"),c(verdictOccurrence,"verdictOccurrence");export const TEST_RUN="test-run",TEST_FLOW_SCOPE_ENV="LENSMCP_TEST_FLOW_SCOPE",testFlowScope=c(t=>`e2e-${t}`,"testFlowScope"),TEST_FLOW_ID=/^(verify|e2e|test|smoke|load)[-_:]/i,ERROR_VERDICT_SET="error-verdict-set",ERROR_VERDICT_CLEARED="error-verdict-cleared";const g=c(t=>typeof t=="object"&&t!==null&&!Array.isArray(t),"isObj"),a=c((t,e=300)=>typeof t=="string"&&t.trim()?t.trim().slice(0,e):void 0,"str"),$=c(t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,"num"),F=200,A=new Set(["dashboard","cli","agent"]);export function readTestRun(t){if(t.source!==O||!g(t.raw)||t.raw.kind!==TEST_RUN)return;const e=t.raw,s=a(e.runId,120),i=a(e.state,20),n=a(e.flowScope,200);if(!s||!i||!n)return;const r=g(e.counts)?e.counts:void 0,o=$(r?.passed),u=$(r?.failed),l=$(r?.total);return{runId:s,state:i,flowScope:n,...a(e.action,40)?{action:a(e.action,40)}:{},...a(e.project,200)?{project:a(e.project,200)}:{},...a(e.target,200)?{target:a(e.target,200)}:{},...o!==void 0&&u!==void 0&&l!==void 0?{counts:{passed:o,failed:u,total:l}}:{},at:t.timestamp}}f(readTestRun,"readTestRun"),w(readTestRun,"readTestRun"),c(readTestRun,"readTestRun");export function readVerdictOverride(t){if(t.source!==O||!g(t.raw))return;const e=t.raw,s=a(e.groupId,2048);if(!s)return;const i=a(e.causeId,2048);if(e.kind===ERROR_VERDICT_CLEARED)return{kind:ERROR_VERDICT_CLEARED,groupId:s,...i?{causeId:i}:{}};if(e.kind!==ERROR_VERDICT_SET||e.verdict!=="bug")return;const n=Array.isArray(e.eventIds)?e.eventIds.filter(r=>typeof r=="string"&&r.length>0).slice(0,F):[];return{kind:ERROR_VERDICT_SET,groupId:s,...i?{causeId:i}:{},eventIds:n,...A.has(e.by)?{by:e.by}:{},at:t.timestamp}}f(readVerdictOverride,"readVerdictOverride"),w(readVerdictOverride,"readVerdictOverride"),c(readVerdictOverride,"readVerdictOverride");const E=2*6e4,M=1e4;export const RECOVERY_MS=6e4;const S=50,C=200,z=200,k=2e3,y=40,B=5e3,_={"service-restart":c(t=>`restarted${a(t.reason,80)?` (${a(t.reason,80)})`:""}`,"service-restart"),"pod-handoff-start":c(t=>`handed over to a new pod${a(t.reason,80)?` (${a(t.reason,80)})`:""}`,"pod-handoff-start"),"pod-recycle":c(t=>`its pod was recycled${a(t.reason,80)?` (${a(t.reason,80)})`:""}`,"pod-recycle"),"service-recycle":c(()=>"recycled after it stopped answering","service-recycle"),"idle-kill":c(()=>"stopped while idle","idle-kill"),"service-down":c(()=>"went down","service-down"),"service-respawn":c(()=>"started again by self-heal","service-respawn"),"service-starting":c(()=>"was starting","service-starting"),"worker-stopped":c(t=>`${b(t)} stopped`,"worker-stopped"),"worker-crashed":c(t=>`${b(t)} crashed and was started again`,"worker-crashed")};function b(t){const e=a(t.worker,80);return e?`its worker ${e}`:"its worker"}f(b,"y"),w(b,"x"),c(b,"workerOf");const D=new Set(["service-up","pod-handoff-complete","pod-handoff-failed","worker-started","worker-up"]),R=/\b(?:TokenExpired(?:Error)?|JWTExpired|jwt expired|(?:token|session|jwt|credentials?) (?:has |is |was )?expired|expired (?:token|session|jwt|credentials?)|"exp" claim)/i,L=/(?:^|[/._-])(?:refresh|renew|re-?auth|silent|token)(?:[/._-]|$)/i,U=/(?:^|\/)(?:log-?in|sign-?in)(?:\/|$)/i,J=/[-_:/.]/,P=new Set(["failed","errored","cancelled","timeout"]),W=new Set(["server-request","gateway-request","fetch-done","fetch"]),I=c(t=>{const e=t.split(/[?#]/)[0]??t,s=/^[a-z][a-z0-9+.-]*:\/\/[^/]+(\/.*)?$/i.exec(e);return s?s[1]??"/":e},"pathOf"),G=c(t=>t!==void 0&&t>=200&&t<300,"ok"),T=c(t=>new Date(t).toISOString().slice(11,19),"clock");function x(t,e,s,i,n){const r=t.get(e);if(r){r.push(s),r.length>i&&r.splice(0,r.length-i);return}t.set(e,[s]),t.size>n&&t.delete(t.keys().next().value)}f(x,"$"),w(x,"E"),c(x,"push");export class ErrorVerdictIndex{static{f(this,"ErrorVerdictIndex")}static{w(this,"ErrorVerdictIndex")}static{c(this,"ErrorVerdictIndex")}constructor(){this.windows=new Map,this.runs=new Map,this.requests=new Map,this.navigations=new Map,this.tabOfFlow=new Map,this.expired=new Map}observe(e){const s=g(e.raw)?e.raw:{},i=e.context??{},n=a(s.kind,60);if(e.source==="gateway"&&n&&this.lifecycle(n,s,e.timestamp))return!0;const r=readTestRun(e);if(r)return P.has(this.runs.get(r.flowScope)?.state??"")?!1:(this.runs.delete(r.flowScope),this.runs.set(r.flowScope,r),this.runs.size>z&&this.runs.delete(this.runs.keys().next().value),!0);const o=a(i.flowId,400),u=a(i.tabId,200),l=a(i.requestId,400);o&&u&&!this.tabOfFlow.has(o)&&(this.tabOfFlow.set(o,u),this.tabOfFlow.size>k&&this.tabOfFlow.delete(this.tabOfFlow.keys().next().value)),o&&n&&W.has(n)&&this.request(o,s,e.timestamp);const d=this.navigation(n,s,i);if(d&&(o&&x(this.navigations,`flow:${o}`,{at:e.timestamp,path:d},y,k),u&&x(this.navigations,`tab:${u}`,{at:e.timestamp,path:d},y,k)),l&&(e.severity==="warning"||e.severity==="error"||e.severity==="fatal")&&!this.expired.has(l)){const v=[(g(s.request)?s.request:{}).error,g(s.span)?s.span.error:void 0,s.error].filter(g),h=[e.title,e.message,...v.flatMap(p=>[p.name,p.message])].map(p=>a(p,600)).find(p=>p!==void 0&&R.test(p));h&&(this.expired.set(l,h.split(`
2
- `)[0].slice(0,120)),this.expired.size>B&&this.expired.delete(this.expired.keys().next().value))}return!1}lifecycle(e,s,i){const n=a(s.project,200);if(!n)return!1;const r=this.windows.get(n)??[],o=r.find(l=>l.end===void 0&&i-l.start<=E),u=e==="service-crash-loop"||e==="worker-crashed"&&s.crashLooping===!0;if((e==="service-restart"?s.phase==="started":_[e])||u){const l=o??{start:i,how:(_[e]??(()=>"crash-looping"))(s)};u&&(l.looping=!0),o||r.push(l)}else if(D.has(e)||e==="service-restart"){if(!o)return!1;o.end=i}else return!1;return r.length>S&&r.splice(0,r.length-S),this.windows.delete(n),this.windows.set(n,r),this.windows.size>C&&this.windows.delete(this.windows.keys().next().value),!0}request(e,s,i){const n=g(s.request)?s.request:s,r=[a(n.route,400),a(n.url,2e3)?I(a(n.url,2e3)):void 0].filter(l=>!!l),o=a(n.method,10)?.toUpperCase(),u=$(n.status);x(this.requests,e,{at:i,...o?{method:o}:{},paths:r,...u!==void 0?{status:u}:{}},y,k)}navigation(e,s,i){if((e==="route"||e==="ready")&&a(s.url,2e3))return I(a(s.url,2e3));const n=a(i.originType,40);if(n!=="route-load"&&n!=="page-load")return;const r=a(i.originNodeId,400);return r?.startsWith("route:")?r.slice(6):a(i.route,400)??(a(i.url,2e3)?I(a(i.url,2e3)):void 0)}restartAround(e,s){const i=this.windows.get(e)?.find(n=>!n.looping&&s>=n.start&&s<=(n.end??n.start+E)+M);return i&&{...i,service:e}}testRunOf(e){if(this.runs.size)for(let s=e.length;s>0;s--){if(s<e.length&&!J.test(e[s]))continue;const i=this.runs.get(e.slice(0,s));if(i)return i}}expiredSaid(e){const s=[e.errorName,e.message].map(i=>a(i,600)).find(i=>i!==void 0&&R.test(i));return s?s.split(`
3
- `)[0].slice(0,120):e.requestId?this.expired.get(e.requestId):void 0}recovery(e){if(!e.flowId)return;const s=c(d=>d>=e.at&&d<=e.at+RECOVERY_MS,"within"),i=new Set(e.routes??[]),n=(this.requests.get(e.flowId)??[]).filter(d=>s(d.at)&&G(d.status)),r=n.find(d=>d.paths.some(v=>L.test(v))&&!d.paths.some(v=>i.has(v))),o=r&&n.find(d=>d.at>=r.at&&d!==r&&(!e.method||!d.method||d.method===e.method)&&d.paths.some(v=>i.has(v)));if(r&&o)return{line:`refreshed (${r.method??""} ${r.paths[0]} \u2192 ${r.status}) and retried (${o.paths[0]} \u2192 ${o.status})`.replace("( ","("),at:o.at};const u=this.tabOfFlow.get(e.flowId),l=[...this.navigations.get(`flow:${e.flowId}`)??[],...u?this.navigations.get(`tab:${u}`)??[]:[]].find(d=>s(d.at)&&U.test(d.path));return l?{line:`went to sign-in (${l.path})`,at:l.at}:void 0}}const q={verdict:"bug"};export function judgeOccurrence(t,e,s){let i,n;if(t.service){const r=e.restartAround(t.service,t.at);if(r){const o=`${r.service} ${r.how} at ${T(r.start)}${r.end!==void 0?`, back at ${T(r.end)}`:""} UTC`;return{verdict:"not-a-bug",kind:"restart",line:o,evidence:[{kind:"restart",line:o,at:r.start,service:r.service}]}}}if(t.flowId){const r=e.testRunOf(t.flowId);if(r?.state==="passed"){const o=r.project?` (${r.project}${r.target?`:${r.target}`:""})`:"",u=`test run ${r.runId}${o} passed${r.counts?` \u2014 ${r.counts.passed} of ${r.counts.total} tests`:""}: the failure was part of the test`;return{verdict:"not-a-bug",kind:"test-expected",line:u,evidence:[{kind:"test-expected",line:u,at:r.at,runId:r.runId,flowId:t.flowId}]}}r?.state==="running"||r?.state==="queued"?i??={verdict:"unsure",kind:"test-expected",missing:`its test run ${r.runId} has not ended`}:r?n??=`its test run ${r.runId} ${r.state} \u2014 a failing run is no evidence it was expected`:TEST_FLOW_ID.test(t.flowId)&&(i??={verdict:"unsure",kind:"test-expected",missing:`flow ${t.flowId} is a test's, but no test run the lens holds names it`})}if(t.status===401||t.status===403)if(!t.flowId)i??={verdict:"unsure",kind:"auth-expired",missing:"not part of a flow: whether the client recovered cannot be followed"};else{const r=e.expiredSaid(t),o=e.recovery(t);if(r&&o){const u=`${t.status}: the app said \xAB${r}\xBB, and the client ${o.line}`;return{verdict:"not-a-bug",kind:"auth-expired",line:u,evidence:[{kind:"auth-expired",line:u,at:o.at,flowId:t.flowId}]}}o?i??={verdict:"unsure",kind:"auth-expired",missing:`the client ${o.line}, but nothing it recorded says the token had expired \u2014 a valid token refused reads the same`}:s-t.at<RECOVERY_MS?i??={verdict:"unsure",kind:"auth-expired",missing:"waiting up to a minute for the client to refresh and retry, or go to sign-in"}:r&&(n??=`its token had expired (\xAB${r}\xBB) and the client did not recover within a minute \u2014 no refresh and retry, no sign-in`)}return i??(n?{verdict:"bug",note:n}:q)}f(judgeOccurrence,"judgeOccurrence"),w(judgeOccurrence,"judgeOccurrence"),c(judgeOccurrence,"judgeOccurrence");const K={restart:"fell inside a restart","test-expected":"came from a passing test run","auth-expired":"were an expired session the client recovered from"},Y=5;export function combineVerdicts(t,e=t.length,s="occurrences"){if(!t.length)return q;const i=t.filter(h=>h.verdict==="not-a-bug"),n=t.filter(h=>h.verdict==="bug"),r=new Map;for(const h of i)r.set(h.kind,(r.get(h.kind)??0)+1);const o=[...r].sort((h,p)=>p[1]-h[1])[0]?.[0];if(n.length){const h=n.find(m=>m.overridden)?.overridden,p=o?`${i.length} of ${t.length} ${s} ${K[o]}; ${n.length} did not`:n.find(m=>m.note)?.note;return{verdict:"bug",...p?{note:p}:{},...h?{overridden:h}:{}}}const u=t.find(h=>h.verdict==="unsure");if(u)return u;const l=e-t.length;if(l>0)return{verdict:"unsure",kind:o,missing:`${l} older occurrence${l===1?" is":"s are"} no longer held to check`};const d=[];for(const h of i)for(const p of h.evidence)d.length<Y&&!d.some(m=>m.line===p.line)&&d.push(p);const v=i.find(h=>h.kind===o);return{verdict:"not-a-bug",kind:o,line:`${v.line}${d.length>1?` (and ${d.length-1} more)`:""}`,evidence:d}}f(combineVerdicts,"combineVerdicts"),w(combineVerdicts,"combineVerdicts"),c(combineVerdicts,"combineVerdicts");export const ERROR_JUDGEMENT_ASK=`"isBug": { "verdict": "bug" | "not-a-bug" | "unsure", "kind": ${NOT_A_BUG_KINDS.map(t=>`"${t}"`).join(" | ")} | "other" (only for not-a-bug), "why": "one line, citing the evidence" } \u2014 not-a-bug only when the evidence shows it is no defect: a service stopping or restarting, a test that expected it, a session that expired and the client recovered; unsure when the evidence cannot tell`;export function readErrorJudgement(t){if(!g(t))return{verdict:"unsure",why:"the review gave no verdict"};const e=a(t.why,400),s=t.verdict;if(s!=="bug"&&s!=="not-a-bug"&&s!=="unsure")return{verdict:"unsure",why:"the review's verdict was not one of bug, not-a-bug, unsure"};if(!e)return{verdict:"unsure",why:`the review said ${s} without saying why`};if(s!=="not-a-bug")return{verdict:s,why:e};const i=NOT_A_BUG_KINDS.includes(t.kind)?t.kind:"other";return{verdict:s,kind:i,why:e}}f(readErrorJudgement,"readErrorJudgement"),w(readErrorJudgement,"readErrorJudgement"),c(readErrorJudgement,"readErrorJudgement");
1
+ "use strict";var q=Object.defineProperty;var p=(t,e)=>q(t,"name",{value:e,configurable:!0});var j=Object.defineProperty,c=p((t,e)=>j(t,"name",{value:e,configurable:!0}),"a");import{LENS_EVENT_SOURCE as I}from"./error-dismissal.js";export const NOT_A_BUG_KINDS=["restart","test-expected","auth-expired"];export function verdictOccurrence(t,e){return{at:t,...e.service?{service:e.service}:{},...e.flowId?{flowId:e.flowId}:{},...e.requestId?{requestId:e.requestId}:{},...e.status!==void 0?{status:e.status}:{},...e.method?{method:e.method}:{},...e.routes?{routes:e.routes}:{},...e.errorName?{errorName:e.errorName}:{},...e.message?{message:e.message}:{}}}p(verdictOccurrence,"verdictOccurrence"),c(verdictOccurrence,"verdictOccurrence");export const TEST_RUN="test-run",TEST_FLOW_SCOPE_ENV="LENSMCP_TEST_FLOW_SCOPE",testFlowScope=c(t=>`e2e-${t}`,"testFlowScope"),TEST_FLOW_ID=/^(verify|e2e|test|smoke|load)[-_:]/i,ERROR_VERDICT_SET="error-verdict-set",ERROR_VERDICT_CLEARED="error-verdict-cleared";const v=c(t=>typeof t=="object"&&t!==null&&!Array.isArray(t),"isObj"),a=c((t,e=300)=>typeof t=="string"&&t.trim()?t.trim().slice(0,e):void 0,"str"),m=c(t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,"num"),N=200,F=new Set(["dashboard","cli","agent"]);export function readTestRun(t){if(t.source!==I||!v(t.raw)||t.raw.kind!==TEST_RUN)return;const e=t.raw,s=a(e.runId,120),n=a(e.state,20),i=a(e.flowScope,200);if(!s||!n||!i)return;const r=v(e.counts)?e.counts:void 0,o=m(r?.passed),u=m(r?.failed),l=m(r?.total);return{runId:s,state:n,flowScope:i,...a(e.action,40)?{action:a(e.action,40)}:{},...a(e.project,200)?{project:a(e.project,200)}:{},...a(e.target,200)?{target:a(e.target,200)}:{},...o!==void 0&&u!==void 0&&l!==void 0?{counts:{passed:o,failed:u,total:l}}:{},at:t.timestamp}}p(readTestRun,"readTestRun"),c(readTestRun,"readTestRun");export function readVerdictOverride(t){if(t.source!==I||!v(t.raw))return;const e=t.raw,s=a(e.groupId,2048);if(!s)return;const n=a(e.causeId,2048);if(e.kind===ERROR_VERDICT_CLEARED)return{kind:ERROR_VERDICT_CLEARED,groupId:s,...n?{causeId:n}:{}};if(e.kind!==ERROR_VERDICT_SET||e.verdict!=="bug")return;const i=Array.isArray(e.eventIds)?e.eventIds.filter(r=>typeof r=="string"&&r.length>0).slice(0,N):[];return{kind:ERROR_VERDICT_SET,groupId:s,...n?{causeId:n}:{},eventIds:i,...F.has(e.by)?{by:e.by}:{},at:t.timestamp}}p(readVerdictOverride,"readVerdictOverride"),c(readVerdictOverride,"readVerdictOverride");const E=2*6e4,A=1e4;export const RECOVERY_MS=6e4;const O=50,M=200,V=200,x=2e3,k=40,C=5e3,S={"service-restart":c(t=>`restarted${a(t.reason,80)?` (${a(t.reason,80)})`:""}`,"service-restart"),"pod-handoff-start":c(t=>`handed over to a new pod${a(t.reason,80)?` (${a(t.reason,80)})`:""}`,"pod-handoff-start"),"pod-recycle":c(t=>`its pod was recycled${a(t.reason,80)?` (${a(t.reason,80)})`:""}`,"pod-recycle"),"service-recycle":c(()=>"recycled after it stopped answering","service-recycle"),"idle-kill":c(()=>"stopped while idle","idle-kill"),"service-down":c(()=>"went down","service-down"),"service-respawn":c(()=>"started again by self-heal","service-respawn"),"service-starting":c(()=>"was starting","service-starting"),"worker-stopped":c(t=>`${y(t)} stopped`,"worker-stopped"),"worker-crashed":c(t=>`${y(t)} crashed and was started again`,"worker-crashed")};function y(t){const e=a(t.worker,80);return e?`its worker ${e}`:"its worker"}p(y,"x"),c(y,"workerOf");const z=new Set(["service-up","pod-handoff-complete","pod-handoff-failed","worker-started","worker-up"]),_=/\b(?:TokenExpired(?:Error)?|JWTExpired|jwt expired|(?:token|session|jwt|credentials?) (?:has |is |was )?expired|expired (?:token|session|jwt|credentials?)|"exp" claim)/i,B=/(?:^|[/._-])(?:refresh|renew|re-?auth|silent|token)(?:[/._-]|$)/i,D=/(?:^|\/)(?:log-?in|sign-?in)(?:\/|$)/i,L=/[-_:/.]/,U=new Set(["failed","errored","cancelled","timeout"]),W=new Set(["server-request","gateway-request","fetch-done","fetch"]),b=c(t=>{const e=t.split(/[?#]/)[0]??t,s=/^[a-z][a-z0-9+.-]*:\/\/[^/]+(\/.*)?$/i.exec(e);return s?s[1]??"/":e},"pathOf"),P=c(t=>t!==void 0&&t>=200&&t<300,"ok"),R=c(t=>new Date(t).toISOString().slice(11,19),"clock");function $(t,e,s,n,i){const r=t.get(e);if(r){r.push(s),r.length>n&&r.splice(0,r.length-n);return}t.set(e,[s]),t.size>i&&t.delete(t.keys().next().value)}p($,"E"),c($,"push");export class ErrorVerdictIndex{static{p(this,"ErrorVerdictIndex")}static{c(this,"ErrorVerdictIndex")}constructor(){this.windows=new Map,this.runs=new Map,this.requests=new Map,this.navigations=new Map,this.tabOfFlow=new Map,this.expired=new Map}observe(e){const s=v(e.raw)?e.raw:{},n=e.context??{},i=a(s.kind,60);if(e.source==="gateway"&&i&&this.lifecycle(i,s,e.timestamp))return!0;const r=readTestRun(e);if(r)return U.has(this.runs.get(r.flowScope)?.state??"")?!1:(this.runs.delete(r.flowScope),this.runs.set(r.flowScope,r),this.runs.size>V&&this.runs.delete(this.runs.keys().next().value),!0);const o=a(n.flowId,400),u=a(n.tabId,200),l=a(n.requestId,400);o&&u&&!this.tabOfFlow.has(o)&&(this.tabOfFlow.set(o,u),this.tabOfFlow.size>x&&this.tabOfFlow.delete(this.tabOfFlow.keys().next().value)),o&&i&&W.has(i)&&this.request(o,s,e.timestamp);const d=this.navigation(i,s,n);if(d&&(o&&$(this.navigations,`flow:${o}`,{at:e.timestamp,path:d},k,x),u&&$(this.navigations,`tab:${u}`,{at:e.timestamp,path:d},k,x)),l&&(e.severity==="warning"||e.severity==="error"||e.severity==="fatal")&&!this.expired.has(l)){const w=[(v(s.request)?s.request:{}).error,v(s.span)?s.span.error:void 0,s.error].filter(v),h=[e.title,e.message,...w.flatMap(f=>[f.name,f.message])].map(f=>a(f,600)).find(f=>f!==void 0&&_.test(f));h&&(this.expired.set(l,h.split(`
2
+ `)[0].slice(0,120)),this.expired.size>C&&this.expired.delete(this.expired.keys().next().value))}return!1}lifecycle(e,s,n){const i=a(s.project,200);if(!i)return!1;const r=this.windows.get(i)??[],o=r.find(l=>l.end===void 0&&n-l.start<=E),u=e==="service-crash-loop"||e==="worker-crashed"&&s.crashLooping===!0;if((e==="service-restart"?s.phase==="started":S[e])||u){const l=o??{start:n,how:(S[e]??(()=>"crash-looping"))(s)};u&&(l.looping=!0),o||r.push(l)}else if(z.has(e)||e==="service-restart"){if(!o)return!1;o.end=n}else return!1;return r.length>O&&r.splice(0,r.length-O),this.windows.delete(i),this.windows.set(i,r),this.windows.size>M&&this.windows.delete(this.windows.keys().next().value),!0}request(e,s,n){const i=v(s.request)?s.request:s,r=[a(i.route,400),a(i.url,2e3)?b(a(i.url,2e3)):void 0].filter(l=>!!l),o=a(i.method,10)?.toUpperCase(),u=m(i.status);$(this.requests,e,{at:n,...o?{method:o}:{},paths:r,...u!==void 0?{status:u}:{}},k,x)}navigation(e,s,n){if((e==="route"||e==="ready")&&a(s.url,2e3))return b(a(s.url,2e3));const i=a(n.originType,40);if(i!=="route-load"&&i!=="page-load")return;const r=a(n.originNodeId,400);return r?.startsWith("route:")?r.slice(6):a(n.route,400)??(a(n.url,2e3)?b(a(n.url,2e3)):void 0)}restartAround(e,s){const n=this.windows.get(e)?.find(i=>!i.looping&&s>=i.start&&s<=(i.end??i.start+E)+A);return n&&{...n,service:e}}testRunOf(e){if(this.runs.size)for(let s=e.length;s>0;s--){if(s<e.length&&!L.test(e[s]))continue;const n=this.runs.get(e.slice(0,s));if(n)return n}}expiredSaid(e){const s=[e.errorName,e.message].map(n=>a(n,600)).find(n=>n!==void 0&&_.test(n));return s?s.split(`
3
+ `)[0].slice(0,120):e.requestId?this.expired.get(e.requestId):void 0}recovery(e){if(!e.flowId)return;const s=c(d=>d>=e.at&&d<=e.at+RECOVERY_MS,"within"),n=new Set(e.routes??[]),i=(this.requests.get(e.flowId)??[]).filter(d=>s(d.at)&&P(d.status)),r=i.find(d=>d.paths.some(w=>B.test(w))&&!d.paths.some(w=>n.has(w))),o=r&&i.find(d=>d.at>=r.at&&d!==r&&(!e.method||!d.method||d.method===e.method)&&d.paths.some(w=>n.has(w)));if(r&&o)return{line:`refreshed (${r.method??""} ${r.paths[0]} \u2192 ${r.status}) and retried (${o.paths[0]} \u2192 ${o.status})`.replace("( ","("),at:o.at};const u=this.tabOfFlow.get(e.flowId),l=[...this.navigations.get(`flow:${e.flowId}`)??[],...u?this.navigations.get(`tab:${u}`)??[]:[]].find(d=>s(d.at)&&D.test(d.path));return l?{line:`went to sign-in (${l.path})`,at:l.at}:void 0}}const T={verdict:"bug"};export function judgeOccurrence(t,e,s){let n,i;if(t.service){const r=e.restartAround(t.service,t.at);if(r){const o=`${r.service} ${r.how} at ${R(r.start)}${r.end!==void 0?`, back at ${R(r.end)}`:""} UTC`;return{verdict:"not-a-bug",kind:"restart",line:o,evidence:[{kind:"restart",line:o,at:r.start,service:r.service}]}}}if(t.flowId){const r=e.testRunOf(t.flowId);if(r?.state==="passed"){const o=r.project?` (${r.project}${r.target?`:${r.target}`:""})`:"",u=`test run ${r.runId}${o} passed${r.counts?` \u2014 ${r.counts.passed} of ${r.counts.total} tests`:""}: the failure was part of the test`;return{verdict:"not-a-bug",kind:"test-expected",line:u,evidence:[{kind:"test-expected",line:u,at:r.at,runId:r.runId,flowId:t.flowId}]}}r?.state==="running"||r?.state==="queued"?n??={verdict:"unsure",kind:"test-expected",missing:`its test run ${r.runId} has not ended`}:r?i??=`its test run ${r.runId} ${r.state} \u2014 a failing run is no evidence it was expected`:TEST_FLOW_ID.test(t.flowId)&&(n??={verdict:"unsure",kind:"test-expected",missing:`flow ${t.flowId} is a test's, but no test run the lens holds names it`})}if(t.status===401||t.status===403)if(!t.flowId)n??={verdict:"unsure",kind:"auth-expired",missing:"not part of a flow: whether the client recovered cannot be followed"};else{const r=e.expiredSaid(t),o=e.recovery(t);if(r&&o){const u=`${t.status}: the app said \xAB${r}\xBB, and the client ${o.line}`;return{verdict:"not-a-bug",kind:"auth-expired",line:u,evidence:[{kind:"auth-expired",line:u,at:o.at,flowId:t.flowId}]}}o?n??={verdict:"unsure",kind:"auth-expired",missing:`the client ${o.line}, but nothing it recorded says the token had expired \u2014 a valid token refused reads the same`}:s-t.at<RECOVERY_MS?n??={verdict:"unsure",kind:"auth-expired",missing:"waiting up to a minute for the client to refresh and retry, or go to sign-in"}:r&&(i??=`its token had expired (\xAB${r}\xBB) and the client did not recover within a minute \u2014 no refresh and retry, no sign-in`)}return n??(i?{verdict:"bug",note:i}:T)}p(judgeOccurrence,"judgeOccurrence"),c(judgeOccurrence,"judgeOccurrence");const J={restart:"fell inside a restart","test-expected":"came from a passing test run","auth-expired":"were an expired session the client recovered from"},G=5;export function combineVerdicts(t,e=t.length,s="occurrences"){if(!t.length)return T;const n=t.filter(h=>h.verdict==="not-a-bug"),i=t.filter(h=>h.verdict==="bug"),r=new Map;for(const h of n)r.set(h.kind,(r.get(h.kind)??0)+1);const o=[...r].sort((h,f)=>f[1]-h[1])[0]?.[0];if(i.length){const h=i.find(g=>g.overridden)?.overridden,f=o?`${n.length} of ${t.length} ${s} ${J[o]}; ${i.length} did not`:i.find(g=>g.note)?.note;return{verdict:"bug",...f?{note:f}:{},...h?{overridden:h}:{}}}const u=t.find(h=>h.verdict==="unsure");if(u)return u;const l=e-t.length;if(l>0)return{verdict:"unsure",kind:o,missing:`${l} older occurrence${l===1?" is":"s are"} no longer held to check`};const d=[];for(const h of n)for(const f of h.evidence)d.length<G&&!d.some(g=>g.line===f.line)&&d.push(f);const w=n.find(h=>h.kind===o);return{verdict:"not-a-bug",kind:o,line:`${w.line}${d.length>1?` (and ${d.length-1} more)`:""}`,evidence:d}}p(combineVerdicts,"combineVerdicts"),c(combineVerdicts,"combineVerdicts");export const ERROR_JUDGEMENT_ASK=`"isBug": { "verdict": "bug" | "not-a-bug" | "unsure", "kind": ${NOT_A_BUG_KINDS.map(t=>`"${t}"`).join(" | ")} | "other" (only for not-a-bug), "why": "one line, citing the evidence" } \u2014 not-a-bug only when the evidence shows it is no defect: a service stopping or restarting, a test that expected it, a session that expired and the client recovered; unsure when the evidence cannot tell`;export function readErrorJudgement(t){if(!v(t))return{verdict:"unsure",why:"the review gave no verdict"};const e=a(t.why,400),s=t.verdict;if(s!=="bug"&&s!=="not-a-bug"&&s!=="unsure")return{verdict:"unsure",why:"the review's verdict was not one of bug, not-a-bug, unsure"};if(!e)return{verdict:"unsure",why:`the review said ${s} without saying why`};if(s!=="not-a-bug")return{verdict:s,why:e};const n=NOT_A_BUG_KINDS.includes(t.kind)?t.kind:"other";return{verdict:s,kind:n,why:e}}p(readErrorJudgement,"readErrorJudgement"),c(readErrorJudgement,"readErrorJudgement");
package/lib/event-loop.js CHANGED
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var s=(e,t)=>f(e,"name",{value:t,configurable:!0});var w=Object.defineProperty,a=s((e,t)=>w(e,"name",{value:t,configurable:!0}),"r"),h=Object.defineProperty,l=a((e,t)=>h(e,"name",{value:t,configurable:!0}),"r");export const LENS_CAUSES={"lensmcp-gc":"forced GC","lensmcp-cleanup":"cleanup","lensmcp-write":"writing events","lensmcp-capture":"capturing values"};export function lensOwnWork(e){const t=typeof e.cause=="string"&&e.cause.startsWith("lensmcp-");if(!t&&!(typeof e.lensMs=="number"&&e.durationMs>0&&e.lensMs>=e.durationMs/2))return;const o=t?LENS_CAUSES[e.cause]:void 0;return o?`LensMCP's own work \u2014 ${o}`:"LensMCP's own work"}s(lensOwnWork,"lensOwnWork"),a(lensOwnWork,"lensOwnWork"),l(lensOwnWork,"lensOwnWork");export function waitedBehind(e){const t=new Set,o=new Set;for(const n of e.evidence)n.relation==="executing"||(n.requestId?n.requestId===e.requestId:!n.flowId||n.flowId===e.flowId)||(t.add(n.requestId??n.flowId),n.flowId&&n.flowId!==e.flowId&&o.add(n.flowId));return{requests:t.size,flows:o.size,atLeast:e.evidenceTruncated}}s(waitedBehind,"waitedBehind"),a(waitedBehind,"waitedBehind"),l(waitedBehind,"waitedBehind");export function waitedLine(e){const t=waitedBehind(e);return t.requests?`${t.atLeast?"at least ":""}${t.requests} request${t.requests===1?"":"s"} waited behind it`:void 0}s(waitedLine,"waitedLine"),a(waitedLine,"waitedLine"),l(waitedLine,"waitedLine");export function flowStalls(e,t){const o={ran:[],overlapped:[]};for(const n of e){if(lensOwnWork(n))continue;if(n.flowId===t){o.ran.push(n);continue}const u=n.endAt??n.observedAt,d=n.evidence.filter(r=>r.flowId===t).map(r=>[Math.max(r.startAt,n.startAt),Math.min(r.endAt,u)]).filter(([r,i])=>i>=r).sort((r,i)=>r[0]-i[0]);if(!d.length)continue;let p=0,c=-1/0;for(const[r,i]of d)i>c&&(p+=i-Math.max(r,c)),c=Math.max(c,i);o.overlapped.push({incident:n,overlapMs:Math.round(p*100)/100})}return o}s(flowStalls,"flowStalls"),a(flowStalls,"flowStalls"),l(flowStalls,"flowStalls");export function overlapLine(e){if(!e.length)return;const t=[...new Set(e.map(u=>u.incident.loop.project))],o=t.length<=2?t.join(" and "):`${t.length} services`,n=e.length;return{count:n,services:t,longestMs:Math.max(...e.map(u=>u.overlapMs)),text:`${n} pause${n===1?"":"s"} in ${o} while this flow was open \u2014 not this flow\u2019s code`}}s(overlapLine,"overlapLine"),a(overlapLine,"overlapLine"),l(overlapLine,"overlapLine");export const LOOP_STARTUP_MS=6e4;export function loopStartedAt(e){if(!e.startsWith("node:"))return;const t=Number(e.slice(e.lastIndexOf(":")+1));return Number.isFinite(t)&&t>0?t:void 0}s(loopStartedAt,"loopStartedAt"),a(loopStartedAt,"loopStartedAt"),l(loopStartedAt,"loopStartedAt");export function loopPhaseAt(e,t){const o=loopStartedAt(e);if(o===void 0)return;const n=Math.max(0,Math.round(t-o));return{phase:n<LOOP_STARTUP_MS?"startup":"running",sinceStartMs:n}}s(loopPhaseAt,"loopPhaseAt"),a(loopPhaseAt,"loopPhaseAt"),l(loopPhaseAt,"loopPhaseAt");
1
+ "use strict";var f=Object.defineProperty;var r=(t,e)=>f(t,"name",{value:e,configurable:!0});var p=Object.defineProperty,a=r((t,e)=>p(t,"name",{value:e,configurable:!0}),"r");export const LENS_CAUSES={"lensmcp-gc":"forced GC","lensmcp-cleanup":"cleanup","lensmcp-write":"writing events","lensmcp-capture":"capturing values"};export function lensOwnWork(t){const e=typeof t.cause=="string"&&t.cause.startsWith("lensmcp-");if(!e&&!(typeof t.lensMs=="number"&&t.durationMs>0&&t.lensMs>=t.durationMs/2))return;const o=e?LENS_CAUSES[t.cause]:void 0;return o?`LensMCP's own work \u2014 ${o}`:"LensMCP's own work"}r(lensOwnWork,"lensOwnWork"),a(lensOwnWork,"lensOwnWork");export function waitedBehind(t){const e=new Set,o=new Set;for(const n of t.evidence)n.relation==="executing"||(n.requestId?n.requestId===t.requestId:!n.flowId||n.flowId===t.flowId)||(e.add(n.requestId??n.flowId),n.flowId&&n.flowId!==t.flowId&&o.add(n.flowId));return{requests:e.size,flows:o.size,atLeast:t.evidenceTruncated}}r(waitedBehind,"waitedBehind"),a(waitedBehind,"waitedBehind");export function waitedLine(t){const e=waitedBehind(t);return e.requests?`${e.atLeast?"at least ":""}${e.requests} request${e.requests===1?"":"s"} waited behind it`:void 0}r(waitedLine,"waitedLine"),a(waitedLine,"waitedLine");export function flowStalls(t,e){const o={ran:[],overlapped:[]};for(const n of t){if(lensOwnWork(n))continue;if(n.flowId===e){o.ran.push(n);continue}const u=n.endAt??n.observedAt,c=n.evidence.filter(s=>s.flowId===e).map(s=>[Math.max(s.startAt,n.startAt),Math.min(s.endAt,u)]).filter(([s,i])=>i>=s).sort((s,i)=>s[0]-i[0]);if(!c.length)continue;let d=0,l=-1/0;for(const[s,i]of c)i>l&&(d+=i-Math.max(s,l)),l=Math.max(l,i);o.overlapped.push({incident:n,overlapMs:Math.round(d*100)/100})}return o}r(flowStalls,"flowStalls"),a(flowStalls,"flowStalls");export function overlapLine(t){if(!t.length)return;const e=[...new Set(t.map(u=>u.incident.loop.project))],o=e.length<=2?e.join(" and "):`${e.length} services`,n=t.length;return{count:n,services:e,longestMs:Math.max(...t.map(u=>u.overlapMs)),text:`${n} pause${n===1?"":"s"} in ${o} while this flow was open \u2014 not this flow\u2019s code`}}r(overlapLine,"overlapLine"),a(overlapLine,"overlapLine");export const LOOP_STARTUP_MS=6e4;export function loopStartedAt(t){if(!t.startsWith("node:"))return;const e=Number(t.slice(t.lastIndexOf(":")+1));return Number.isFinite(e)&&e>0?e:void 0}r(loopStartedAt,"loopStartedAt"),a(loopStartedAt,"loopStartedAt");export function loopPhaseAt(t,e){const o=loopStartedAt(t);if(o===void 0)return;const n=Math.max(0,Math.round(e-o));return{phase:n<LOOP_STARTUP_MS?"startup":"running",sinceStartMs:n}}r(loopPhaseAt,"loopPhaseAt"),a(loopPhaseAt,"loopPhaseAt");
@@ -1,2 +1,2 @@
1
- "use strict";var K=Object.defineProperty;var h=(t,e)=>K(t,"name",{value:e,configurable:!0});var W=Object.defineProperty,l=h((t,e)=>W(t,"name",{value:e,configurable:!0}),"h"),G=Object.defineProperty,c=l((t,e)=>G(t,"name",{value:e,configurable:!0}),"d");import{LENS_EVENT_SOURCE as J}from"./error-dismissal.js";export const EXPECTED_RULE_SET="expected-rule-set",EXPECTED_RULE_REMOVED="expected-rule-removed";const L=new Set(["dashboard","cli","agent"]),f=60*6e4;export const EXPECTED_RULE_DEFAULT_TTL_MS=168*f,EXPECTED_RULE_MAX_TTL_MS=720*f,EXPECTED_RULE_MIN_REASON_CHARS=8,MAX_EXPECTED_REASON_CHARS=500;const $=300,V=300,D=120,Z=200,U=20,p=c(t=>!!t&&typeof t=="object"&&!Array.isArray(t),"isObj"),x=c((t,e)=>typeof t=="string"&&t.trim()?t.trim().slice(0,e):void 0,"text"),_=c(t=>!!t&&t.replace(/[*?\s/:.#_-]/g,"").length>=2,"meaningful");export const EXPECTED_SCOPE_FIELDS=["route","span","flow"],EXPECTED_OUTCOME_FIELDS=["status","error","message"];export function checkExpectedMatch(t){if(!p(t))return{error:"a rule needs a match: a flow scope (route, span or flow) and an outcome (status, error or message)"};const e={};for(const r of["service","route","span","flow","error","message"]){const o=t[r];if(o==null||o==="")continue;if(typeof o!="string")return{error:`\`${r}\` must be text`};const i=o.trim();if(i.length>$)return{error:`\`${r}\` is longer than ${$} characters`};i&&(e[r]=i)}if(t.status!==void 0&&t.status!==null&&t.status!==""){const r=typeof t.status=="string"?Number(t.status):t.status;if(typeof r!="number"||!Number.isInteger(r)||r<100||r>599)return{error:"`status` must be an HTTP status (100\u2013599)"};e.status=r}const s=t.attribute;if(s!=null){const r=p(s)?x(s.name,100):void 0,o=p(s)?typeof s.value=="number"?String(s.value):x(s.value,$):void 0;if(!r||!o)return{error:"`attribute` needs a `name` and a `value` (one attribute of the flow, such as a tenant id)"};e.attribute={name:r,value:o}}return EXPECTED_SCOPE_FIELDS.some(r=>_(e[r]))?e.status===void 0&&!_(e.error)&&!_(e.message)?{error:"a rule needs an outcome \u2014 a `status`, an `error` key or a `message` pattern \u2014 saying WHICH failure is expected in that flow"}:{match:e}:{error:`a rule needs a flow scope \u2014 a \`route\`, a \`span\` or a \`flow\` \u2014 not only ${e.service?`the service \xAB${e.service}\xBB`:"an outcome"}: \xABeverything in a service\xBB is not expected, it is unwatched`}}h(checkExpectedMatch,"checkExpectedMatch"),l(checkExpectedMatch,"checkExpectedMatch"),c(checkExpectedMatch,"checkExpectedMatch");export function describeExpectedMatch(t){return[t.service,t.route,t.span,t.flow?`flow ${t.flow}`:void 0,t.status!==void 0?String(t.status):void 0,t.error,t.message?`\xAB${t.message}\xBB`:void 0,t.attribute?`${t.attribute.name}=${t.attribute.value}`:void 0].filter(Boolean).join(" \xB7 ")}h(describeExpectedMatch,"describeExpectedMatch"),l(describeExpectedMatch,"describeExpectedMatch"),c(describeExpectedMatch,"describeExpectedMatch");export function readExpectedRule(t){if(t.source!==J||!p(t.raw))return;const e=t.raw,s=x(e.id,D);if(!s)return;if(e.kind===EXPECTED_RULE_REMOVED)return{kind:EXPECTED_RULE_REMOVED,id:s,...L.has(e.by)?{by:e.by}:{}};if(e.kind!==EXPECTED_RULE_SET||!L.has(e.by))return;const r=x(e.reason,MAX_EXPECTED_REASON_CHARS);if(!r)return;const o=checkExpectedMatch(e.match);if("error"in o)return;const i=Math.min(typeof e.createdAt=="number"&&Number.isFinite(e.createdAt)?e.createdAt:t.timestamp,t.timestamp),u=typeof e.expiresAt=="number"&&Number.isFinite(e.expiresAt)?e.expiresAt:i+EXPECTED_RULE_DEFAULT_TTL_MS,a=x(e.title,V);return{kind:EXPECTED_RULE_SET,id:s,match:o.match,reason:r,by:e.by,createdAt:i,expiresAt:Math.min(u,i+EXPECTED_RULE_MAX_TTL_MS),...a?{title:a}:{}}}h(readExpectedRule,"readExpectedRule"),l(readExpectedRule,"readExpectedRule"),c(readExpectedRule,"readExpectedRule");export function expectedRuleTtlMs(t){return t===void 0||!Number.isFinite(t)||t<=0?EXPECTED_RULE_DEFAULT_TTL_MS:Math.min(Math.round(t*f),EXPECTED_RULE_MAX_TTL_MS)}h(expectedRuleTtlMs,"expectedRuleTtlMs"),l(expectedRuleTtlMs,"expectedRuleTtlMs"),c(expectedRuleTtlMs,"expectedRuleTtlMs");function j(t){let e=2166136261;for(let s=0;s<t.length;s++)e=Math.imul(e^t.charCodeAt(s),16777619);return(e>>>0).toString(36)}h(j,"F"),l(j,"z"),c(j,"hashOf");export function readRepositoryExpectedRules(t,e){const s=[],r=[];return t==null?{rules:s,problems:r}:Array.isArray(t)?(t.forEach((o,i)=>{if(!p(o))return void r.push(`expectedFailures[${i}] is not an object`);const u=checkExpectedMatch(p(o.match)?o.match:o);if("error"in u)return void r.push(`expectedFailures[${i}]: ${u.error}`);const a=x(o.reason,MAX_EXPECTED_REASON_CHARS);if(!a)return void r.push(`expectedFailures[${i}] has no reason \u2014 say why it is expected`);const d=`repository:${x(o.id,D)??j(JSON.stringify(u.match))}`;if(s.some(m=>m.id===d))return void r.push(`expectedFailures[${i}] repeats the id ${d}`);s.push({id:d,match:u.match,reason:a,by:"repository",createdAt:e})}),{rules:s,problems:r}):{rules:s,problems:["expectedFailures is not a list \u2014 no repository rule is read"]}}h(readRepositoryExpectedRules,"readRepositoryExpectedRules"),l(readRepositoryExpectedRules,"readRepositoryExpectedRules"),c(readRepositoryExpectedRules,"readRepositoryExpectedRules");const n=c(t=>typeof t=="string"&&t?t:void 0,"str"),I=c(t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,"num"),z=c(t=>{const e=t.split(/[?#]/)[0]??t,s=/^[a-z][a-z0-9+.-]*:\/\/[^/]+(\/.*)?$/i.exec(e);return s?s[1]??"/":e},"pathOf"),Q=new Set(["sessionId","flowId","requestId","parentRequestId","runId","traceparent","originNodeId","causedByNodeId","userActionId","browserContextId","frameId","tabId","url","route","projectName"]),S=24;export function eventAttributes(t){let e;const s=c((a,d)=>{if(e&&Object.keys(e).length>=S)return;const m=typeof d=="string"?d:typeof d=="number"||typeof d=="boolean"?String(d):void 0;m===void 0||m.length>$||((e??={})[a]=m)},"put"),r=t.context??{};for(const a of Object.keys(r))Q.has(a)||s(a,r[a]);const o=p(t.raw)?t.raw:void 0;if(!o)return e;const i=p(o.span)?o.span:void 0,u=p(o.request)?o.request:void 0;for(const a of[o.attributes,i?.attributes,u?.attributes,o.data,Array.isArray(i?.args)?i?.args[0]:i?.args])if(p(a))for(const d of Object.keys(a))s(d,a[d]);return e}h(eventAttributes,"eventAttributes"),l(eventAttributes,"eventAttributes"),c(eventAttributes,"eventAttributes");export function failureFacts(t){const e=p(t.raw)?t.raw:{},s=t.context??{},r=p(e.request)?e.request:{},o=p(e.span)?e.span:{},i=p(r.error)?r.error:{},u=p(o.error)?o.error:{},a=p(e.error)?e.error:{},d=n(e.kind),m=[],A=n(r.route)??(d==="egress"?n(e.path):void 0);A&&m.push(A);const y=n(e.url)??n(r.url);y&&m.push(z(y)),d!=="server-request"&&n(s.route)&&m.push(n(s.route));const v=[];if(d==="queue-failed"||d==="queue-enqueued"){const w=n(e.queue),M=e.jobId===void 0||e.jobId===null?void 0:String(e.jobId);w&&v.push(`job:${w}`),M&&v.push(`job:${M}`),w&&M&&v.push(`job:${w}#${M}`),n(e.name)&&v.push(`job:${n(e.name)}`)}const b=[i.errorKey,u.errorKey,a.errorKey,e.errorKey,i.reason,u.reason].map(n).filter(w=>!!w),k=n(i.message)??n(t.message)??n(u.message)??n(a.message)??n(e.failedReason)??n(e.error)??n(e.message)??n(t.title),P=I(r.status)??I(e.status),B=n(s.flowId)??n(o.flowId)??n(r.flowId),F=n(s.requestId)??n(r.requestId)??n(o.requestId),H=eventAttributes(t);return{...n(e.project)??n(s.projectName)?{service:n(e.project)??n(s.projectName)}:{},...n(r.method)??n(e.method)?{method:n(r.method)??n(e.method)}:{},...m.length?{routes:m}:{},...n(o.name)?{span:n(o.name)}:{},...B?{flowId:B}:{},...v.length?{flowNames:v}:{},...P!==void 0?{status:P}:{},...n(i.name)??n(u.name)??n(a.name)?{errorName:n(i.name)??n(u.name)??n(a.name)}:{},...b.length?{errorKeys:b}:{},...k?{message:k}:{},...H?{attributes:H}:{},...F?{requestId:F}:{}}}h(failureFacts,"failureFacts"),l(failureFacts,"failureFacts"),c(failureFacts,"failureFacts");export class FailureContextIndex{static{h(this,"FailureContextIndex")}static{l(this,"FailureContextIndex")}static{c(this,"FailureContextIndex")}constructor(e=5e3,s=2e3){this.maxRequests=e,this.maxFlows=s,this.requests=new Map,this.flows=new Map}observe(e){const s=p(e.raw)?e.raw:void 0,r=e.context??{},o=n(r.flowId);if(o&&(s?.attributes!==void 0||p(s?.span)||r.tenantIdHash!==void 0||r.userIdHash!==void 0||s?.data!==void 0)){const y=eventAttributes(e);if(y){const v=this.flows.get(o);this.flows.delete(o);const b={...v??{},...y};this.flows.set(o,Object.keys(b).length>S?Object.fromEntries(Object.entries(b).slice(-S)):b),this.flows.size>this.maxFlows&&this.flows.delete(this.flows.keys().next().value)}}const i=n(s?.kind);if(!s||i!=="server-request"&&i!=="gateway-request")return;const u=p(s.request)?s.request:s,a=n(r.requestId)??n(u.requestId);if(!a)return;const d=this.requests.get(a)??{},m=n(u.url),A={...d,...n(s.project)&&(i==="server-request"||!d.service)?{service:n(s.project)}:{},...n(u.method)?{method:n(u.method)}:{},...i==="server-request"&&n(u.route)?{route:n(u.route)}:{},...m?{path:z(m)}:{},...I(u.status)!==void 0&&(i==="server-request"||d.status===void 0)?{status:I(u.status)}:{}};return this.requests.delete(a),this.requests.set(a,A),this.requests.size>this.maxRequests&&this.requests.delete(this.requests.keys().next().value),i==="server-request"?a:void 0}request(e){return e?this.requests.get(e):void 0}enrich(e){const s=this.request(e.requestId),r=e.flowId?this.flows.get(e.flowId):void 0;if(!s&&!r)return e;const o=[...e.routes??[],...s?.route?[s.route]:[],...s?.path?[s.path]:[]];return{...e,...e.service??s?.service?{service:e.service??s?.service}:{},...e.method??s?.method?{method:e.method??s?.method}:{},...o.length?{routes:[...new Set(o)]}:{},...e.status??s?.status!==void 0?{status:e.status??s?.status}:{},...r||e.attributes?{attributes:{...r??{},...e.attributes??{}}}:{}}}}const R=new Map,C=c((t,e)=>t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,e).replace(/\?/g,"."),"globBody");function E(t,e="whole"){const s=`${e}\0${t}`;let r=R.get(s);return r||(r=e==="whole"?new RegExp(`^${C(t,"[\\s\\S]*")}$`,"i"):e==="anywhere"?new RegExp(C(t,"[\\s\\S]*"),"i"):new RegExp(`(?:^|[^\\w.])${C(t,"[\\w.]*")}(?:$|[^\\w.])`,"i"),R.size>1e3&&R.clear(),R.set(s,r)),r}h(E,"M"),l(E,"S"),c(E,"globRe");const g=c((t,e)=>e!==void 0&&E(t).test(e),"glob");function T(t,e){const s=e.routes??[],r=/^([A-Za-z]+)\s+(\S.*)$/.exec(t);return r&&/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|\*)$/i.test(r[1])?r[1]!=="*"&&(e.method??"").toUpperCase()!==r[1].toUpperCase()?!1:s.some(o=>g(r[2],o)):s.some(o=>g(t,o))}h(T,"D"),l(T,"B"),c(T,"routeMatches");function O(t,e){const s=[e.flowId,...e.flowNames??[]].filter(o=>!!o),r=t.endsWith(":")?`${t}*`:t;return s.some(o=>g(r,o))}h(O,"L"),l(O,"G"),c(O,"flowMatches");function N(t,e){return g(t,e.errorName)||(e.errorKeys??[]).some(s=>g(t,s))?!0:e.message!==void 0&&E(t,"word").test(e.message)}h(N,"U"),l(N,"W"),c(N,"errorMatches");export function expectedMatches(t,e){return!(t.service!==void 0&&!g(t.service,e.service)||t.route!==void 0&&!T(t.route,e)||t.span!==void 0&&!g(t.span,e.span)||t.flow!==void 0&&!O(t.flow,e)||t.status!==void 0&&e.status!==t.status||t.error!==void 0&&!N(t.error,e)||t.message!==void 0&&!(e.message!==void 0&&E(t.message,"anywhere").test(e.message))||t.attribute!==void 0&&!g(t.attribute.value,e.attributes?.[t.attribute.name]))}h(expectedMatches,"expectedMatches"),l(expectedMatches,"expectedMatches"),c(expectedMatches,"expectedMatches");export function expectedMatchIsPerOccurrence(t){return t.flow!==void 0||t.attribute!==void 0||t.message!==void 0&&/\d/.test(t.message)}h(expectedMatchIsPerOccurrence,"expectedMatchIsPerOccurrence"),l(expectedMatchIsPerOccurrence,"expectedMatchIsPerOccurrence"),c(expectedMatchIsPerOccurrence,"expectedMatchIsPerOccurrence");export function suggestExpectedMatch(t){const e=t.routes?.find(a=>a.startsWith("/")),s=t.flowNames?.find(a=>a.startsWith("job:")&&!a.includes("#"))??(t.flowId?`${t.flowId.split(":")[0]}:`:void 0),r=e?{route:t.method?`${t.method.toUpperCase()} ${e}`:e}:t.span?{span:t.span}:s?{flow:s}:{},o=t.message?.split(`
2
- `)[0]?.replace(/\d+/g,"*").replace(/\*+/g,"*").slice(0,120).trim(),i=t.status!==void 0?{status:t.status}:t.errorName&&t.errorName!=="Error"?{error:t.errorName}:o?{message:o}:{},u=checkExpectedMatch({...t.service?{service:t.service}:{},...r,...i});return"match"in u?u.match:void 0}h(suggestExpectedMatch,"suggestExpectedMatch"),l(suggestExpectedMatch,"suggestExpectedMatch"),c(suggestExpectedMatch,"suggestExpectedMatch");export const EXPECTED_SURGE_FACTOR=10,EXPECTED_SURGE_MIN_PER_HOUR=20;const Y=2*f,X=24*f,q=6e4;export class ExpectedRuleBook{static{h(this,"ExpectedRuleBook")}static{l(this,"ExpectedRuleBook")}static{c(this,"ExpectedRuleBook")}constructor(e=Date.now()){this.startedAt=e,this.runtime=new Map,this.repository=[],this.repositoryKey="",this.stats=new Map,this.ended=[],this.version=0}apply(e,s){const r=readExpectedRule(e);if(!r)return!1;const o=this.runtime.get(r.id);if(this.runtime.delete(r.id),r.kind===EXPECTED_RULE_REMOVED)o&&this.end(o,s,"removed",r.by);else{const{kind:i,...u}=r;if(this.runtime.set(u.id,u),this.stats.has(u.id)||this.stats.set(u.id,{hits:0,minutes:new Map,since:Math.max(u.createdAt,this.startedAt)}),this.runtime.size>Z){const a=this.runtime.keys().next().value,d=this.runtime.get(a);this.runtime.delete(a),this.end(d,s,"expired")}}return this.version++,!0}setRepository(e,s){const r=JSON.stringify(e.map(i=>[i.id,i.match,i.reason]));if(r===this.repositoryKey)return!1;const o=new Set(e.map(i=>i.id));for(const i of this.repository)o.has(i.id)||this.end(i,s,"dropped from lensmcp.json");this.repository=e.slice(),this.repositoryKey=r;for(const i of e)this.stats.has(i.id)||this.stats.set(i.id,{hits:0,minutes:new Map,since:Math.max(this.startedAt,Math.min(i.createdAt,s))});return this.version++,!0}expire(e){let s=!1;for(const[r,o]of this.runtime)o.expiresAt===void 0||o.expiresAt>e||(this.runtime.delete(r),this.end(o,o.expiresAt,"expired"),s=!0);return s&&this.version++,s}end(e,s,r,o){this.ended.unshift({...e,endedAt:s,why:r,...o?{removedBy:o}:{}}),this.ended.length>U&&(this.ended.length=U)}active(e){return[...this.repository,...[...this.runtime.values()].filter(s=>s.expiresAt===void 0||s.expiresAt>e)]}get(e){return this.runtime.get(e)??this.repository.find(s=>s.id===e)}isActive(e,s){const r=this.get(e);return!!r&&(r.expiresAt===void 0||r.expiresAt>s)}get size(){return this.runtime.size+this.repository.length}holderOf(e,s){if(this.size!==0)return this.active(s).find(r=>expectedMatches(r.match,e))}count(e,s,r=1){const o=this.stats.get(e);if(!o||r<=0||(o.hits+=r,s===void 0))return;o.lastHitAt=Math.max(o.lastHitAt??0,s);const i=Math.floor(s/q);if(o.minutes.set(i,(o.minutes.get(i)??0)+r),o.minutes.size>1600){const u=i-(X+f)/q;for(const a of o.minutes.keys())a<u&&o.minutes.delete(a)}}windowCount(e,s,r){let o=0;for(const[i,u]of e.minutes)i*q>=s&&i*q<r&&(o+=u);return o}judge(e,s){const r=this.windowCount(e,s-f,s+1),o=Math.max(e.since,s-f-X),i=s-f-o;if(i<Y)return e.surge=void 0;const u=this.windowCount(e,o,s-f)/(i/f),a=Math.max(EXPECTED_SURGE_MIN_PER_HOUR,EXPECTED_SURGE_FACTOR*u);return e.surge?r<a/3?e.surge=void 0:e.surge={...e.surge,lastHour:r}:r>=a&&(e.surge={since:s,lastHour:r,usualPerHour:Math.round(u*10)/10}),e.surge}list(e){return this.active(e).map(s=>{const r=this.stats.get(s.id),o=r?this.judge(r,e):void 0;return{...s,hits:r?.hits??0,...r?.lastHitAt!==void 0?{lastHitAt:r.lastHitAt}:{},lastHour:r?this.windowCount(r,e-f,e+1):0,...o?{surge:o}:{}}}).sort((s,r)=>+(s.by==="repository")-+(r.by==="repository")||r.createdAt-s.createdAt)}endedRules(){return this.ended.slice()}}export function heldBackLine(t,e,s=""){return`${t} rule${t===1?"":"s"} held back ${e} occurrence${e===1?"":"s"}${s?` ${s}`:""}`}h(heldBackLine,"heldBackLine"),l(heldBackLine,"heldBackLine"),c(heldBackLine,"heldBackLine");export function surgeLine(t){const e=t.surge;return`this expected failure is now happening much more often: ${describeExpectedMatch(t.match)} \u2014 ${e?`${e.lastHour} in the last hour, usually ${e.usualPerHour} an hour`:"its rate jumped"} (expected because: ${t.reason})`}h(surgeLine,"surgeLine"),l(surgeLine,"surgeLine"),c(surgeLine,"surgeLine");
1
+ "use strict";var z=Object.defineProperty;var h=(t,e)=>z(t,"name",{value:e,configurable:!0});var K=Object.defineProperty,c=h((t,e)=>K(t,"name",{value:e,configurable:!0}),"d");import{LENS_EVENT_SOURCE as W}from"./error-dismissal.js";export const EXPECTED_RULE_SET="expected-rule-set",EXPECTED_RULE_REMOVED="expected-rule-removed";const k=new Set(["dashboard","cli","agent"]),m=60*6e4;export const EXPECTED_RULE_DEFAULT_TTL_MS=168*m,EXPECTED_RULE_MAX_TTL_MS=720*m,EXPECTED_RULE_MIN_REASON_CHARS=8,MAX_EXPECTED_REASON_CHARS=500;const A=300,G=300,P=120,J=200,H=20,l=c(t=>!!t&&typeof t=="object"&&!Array.isArray(t),"isObj"),g=c((t,e)=>typeof t=="string"&&t.trim()?t.trim().slice(0,e):void 0,"text"),R=c(t=>!!t&&t.replace(/[*?\s/:.#_-]/g,"").length>=2,"meaningful");export const EXPECTED_SCOPE_FIELDS=["route","span","flow"],EXPECTED_OUTCOME_FIELDS=["status","error","message"];export function checkExpectedMatch(t){if(!l(t))return{error:"a rule needs a match: a flow scope (route, span or flow) and an outcome (status, error or message)"};const e={};for(const r of["service","route","span","flow","error","message"]){const o=t[r];if(o==null||o==="")continue;if(typeof o!="string")return{error:`\`${r}\` must be text`};const i=o.trim();if(i.length>A)return{error:`\`${r}\` is longer than ${A} characters`};i&&(e[r]=i)}if(t.status!==void 0&&t.status!==null&&t.status!==""){const r=typeof t.status=="string"?Number(t.status):t.status;if(typeof r!="number"||!Number.isInteger(r)||r<100||r>599)return{error:"`status` must be an HTTP status (100\u2013599)"};e.status=r}const s=t.attribute;if(s!=null){const r=l(s)?g(s.name,100):void 0,o=l(s)?typeof s.value=="number"?String(s.value):g(s.value,A):void 0;if(!r||!o)return{error:"`attribute` needs a `name` and a `value` (one attribute of the flow, such as a tenant id)"};e.attribute={name:r,value:o}}return EXPECTED_SCOPE_FIELDS.some(r=>R(e[r]))?e.status===void 0&&!R(e.error)&&!R(e.message)?{error:"a rule needs an outcome \u2014 a `status`, an `error` key or a `message` pattern \u2014 saying WHICH failure is expected in that flow"}:{match:e}:{error:`a rule needs a flow scope \u2014 a \`route\`, a \`span\` or a \`flow\` \u2014 not only ${e.service?`the service \xAB${e.service}\xBB`:"an outcome"}: \xABeverything in a service\xBB is not expected, it is unwatched`}}h(checkExpectedMatch,"checkExpectedMatch"),c(checkExpectedMatch,"checkExpectedMatch");export function describeExpectedMatch(t){return[t.service,t.route,t.span,t.flow?`flow ${t.flow}`:void 0,t.status!==void 0?String(t.status):void 0,t.error,t.message?`\xAB${t.message}\xBB`:void 0,t.attribute?`${t.attribute.name}=${t.attribute.value}`:void 0].filter(Boolean).join(" \xB7 ")}h(describeExpectedMatch,"describeExpectedMatch"),c(describeExpectedMatch,"describeExpectedMatch");export function readExpectedRule(t){if(t.source!==W||!l(t.raw))return;const e=t.raw,s=g(e.id,P);if(!s)return;if(e.kind===EXPECTED_RULE_REMOVED)return{kind:EXPECTED_RULE_REMOVED,id:s,...k.has(e.by)?{by:e.by}:{}};if(e.kind!==EXPECTED_RULE_SET||!k.has(e.by))return;const r=g(e.reason,MAX_EXPECTED_REASON_CHARS);if(!r)return;const o=checkExpectedMatch(e.match);if("error"in o)return;const i=Math.min(typeof e.createdAt=="number"&&Number.isFinite(e.createdAt)?e.createdAt:t.timestamp,t.timestamp),u=typeof e.expiresAt=="number"&&Number.isFinite(e.expiresAt)?e.expiresAt:i+EXPECTED_RULE_DEFAULT_TTL_MS,a=g(e.title,G);return{kind:EXPECTED_RULE_SET,id:s,match:o.match,reason:r,by:e.by,createdAt:i,expiresAt:Math.min(u,i+EXPECTED_RULE_MAX_TTL_MS),...a?{title:a}:{}}}h(readExpectedRule,"readExpectedRule"),c(readExpectedRule,"readExpectedRule");export function expectedRuleTtlMs(t){return t===void 0||!Number.isFinite(t)||t<=0?EXPECTED_RULE_DEFAULT_TTL_MS:Math.min(Math.round(t*m),EXPECTED_RULE_MAX_TTL_MS)}h(expectedRuleTtlMs,"expectedRuleTtlMs"),c(expectedRuleTtlMs,"expectedRuleTtlMs");function F(t){let e=2166136261;for(let s=0;s<t.length;s++)e=Math.imul(e^t.charCodeAt(s),16777619);return(e>>>0).toString(36)}h(F,"z"),c(F,"hashOf");export function readRepositoryExpectedRules(t,e){const s=[],r=[];return t==null?{rules:s,problems:r}:Array.isArray(t)?(t.forEach((o,i)=>{if(!l(o))return void r.push(`expectedFailures[${i}] is not an object`);const u=checkExpectedMatch(l(o.match)?o.match:o);if("error"in u)return void r.push(`expectedFailures[${i}]: ${u.error}`);const a=g(o.reason,MAX_EXPECTED_REASON_CHARS);if(!a)return void r.push(`expectedFailures[${i}] has no reason \u2014 say why it is expected`);const d=`repository:${g(o.id,P)??F(JSON.stringify(u.match))}`;if(s.some(p=>p.id===d))return void r.push(`expectedFailures[${i}] repeats the id ${d}`);s.push({id:d,match:u.match,reason:a,by:"repository",createdAt:e})}),{rules:s,problems:r}):{rules:s,problems:["expectedFailures is not a list \u2014 no repository rule is read"]}}h(readRepositoryExpectedRules,"readRepositoryExpectedRules"),c(readRepositoryExpectedRules,"readRepositoryExpectedRules");const n=c(t=>typeof t=="string"&&t?t:void 0,"str"),$=c(t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,"num"),B=c(t=>{const e=t.split(/[?#]/)[0]??t,s=/^[a-z][a-z0-9+.-]*:\/\/[^/]+(\/.*)?$/i.exec(e);return s?s[1]??"/":e},"pathOf"),V=new Set(["sessionId","flowId","requestId","parentRequestId","runId","traceparent","originNodeId","causedByNodeId","userActionId","browserContextId","frameId","tabId","url","route","projectName"]),_=24;export function eventAttributes(t){let e;const s=c((a,d)=>{if(e&&Object.keys(e).length>=_)return;const p=typeof d=="string"?d:typeof d=="number"||typeof d=="boolean"?String(d):void 0;p===void 0||p.length>A||((e??={})[a]=p)},"put"),r=t.context??{};for(const a of Object.keys(r))V.has(a)||s(a,r[a]);const o=l(t.raw)?t.raw:void 0;if(!o)return e;const i=l(o.span)?o.span:void 0,u=l(o.request)?o.request:void 0;for(const a of[o.attributes,i?.attributes,u?.attributes,o.data,Array.isArray(i?.args)?i?.args[0]:i?.args])if(l(a))for(const d of Object.keys(a))s(d,a[d]);return e}h(eventAttributes,"eventAttributes"),c(eventAttributes,"eventAttributes");export function failureFacts(t){const e=l(t.raw)?t.raw:{},s=t.context??{},r=l(e.request)?e.request:{},o=l(e.span)?e.span:{},i=l(r.error)?r.error:{},u=l(o.error)?o.error:{},a=l(e.error)?e.error:{},d=n(e.kind),p=[],b=n(r.route)??(d==="egress"?n(e.path):void 0);b&&p.push(b);const y=n(e.url)??n(r.url);y&&p.push(B(y)),d!=="server-request"&&n(s.route)&&p.push(n(s.route));const f=[];if(d==="queue-failed"||d==="queue-enqueued"){const w=n(e.queue),E=e.jobId===void 0||e.jobId===null?void 0:String(e.jobId);w&&f.push(`job:${w}`),E&&f.push(`job:${E}`),w&&E&&f.push(`job:${w}#${E}`),n(e.name)&&f.push(`job:${n(e.name)}`)}const x=[i.errorKey,u.errorKey,a.errorKey,e.errorKey,i.reason,u.reason].map(n).filter(w=>!!w),S=n(i.message)??n(t.message)??n(u.message)??n(a.message)??n(e.failedReason)??n(e.error)??n(e.message)??n(t.title),C=$(r.status)??$(e.status),T=n(s.flowId)??n(o.flowId)??n(r.flowId),N=n(s.requestId)??n(r.requestId)??n(o.requestId),O=eventAttributes(t);return{...n(e.project)??n(s.projectName)?{service:n(e.project)??n(s.projectName)}:{},...n(r.method)??n(e.method)?{method:n(r.method)??n(e.method)}:{},...p.length?{routes:p}:{},...n(o.name)?{span:n(o.name)}:{},...T?{flowId:T}:{},...f.length?{flowNames:f}:{},...C!==void 0?{status:C}:{},...n(i.name)??n(u.name)??n(a.name)?{errorName:n(i.name)??n(u.name)??n(a.name)}:{},...x.length?{errorKeys:x}:{},...S?{message:S}:{},...O?{attributes:O}:{},...N?{requestId:N}:{}}}h(failureFacts,"failureFacts"),c(failureFacts,"failureFacts");export class FailureContextIndex{static{h(this,"FailureContextIndex")}static{c(this,"FailureContextIndex")}constructor(e=5e3,s=2e3){this.maxRequests=e,this.maxFlows=s,this.requests=new Map,this.flows=new Map}observe(e){const s=l(e.raw)?e.raw:void 0,r=e.context??{},o=n(r.flowId);if(o&&(s?.attributes!==void 0||l(s?.span)||r.tenantIdHash!==void 0||r.userIdHash!==void 0||s?.data!==void 0)){const y=eventAttributes(e);if(y){const f=this.flows.get(o);this.flows.delete(o);const x={...f??{},...y};this.flows.set(o,Object.keys(x).length>_?Object.fromEntries(Object.entries(x).slice(-_)):x),this.flows.size>this.maxFlows&&this.flows.delete(this.flows.keys().next().value)}}const i=n(s?.kind);if(!s||i!=="server-request"&&i!=="gateway-request")return;const u=l(s.request)?s.request:s,a=n(r.requestId)??n(u.requestId);if(!a)return;const d=this.requests.get(a)??{},p=n(u.url),b={...d,...n(s.project)&&(i==="server-request"||!d.service)?{service:n(s.project)}:{},...n(u.method)?{method:n(u.method)}:{},...i==="server-request"&&n(u.route)?{route:n(u.route)}:{},...p?{path:B(p)}:{},...$(u.status)!==void 0&&(i==="server-request"||d.status===void 0)?{status:$(u.status)}:{}};return this.requests.delete(a),this.requests.set(a,b),this.requests.size>this.maxRequests&&this.requests.delete(this.requests.keys().next().value),i==="server-request"?a:void 0}request(e){return e?this.requests.get(e):void 0}enrich(e){const s=this.request(e.requestId),r=e.flowId?this.flows.get(e.flowId):void 0;if(!s&&!r)return e;const o=[...e.routes??[],...s?.route?[s.route]:[],...s?.path?[s.path]:[]];return{...e,...e.service??s?.service?{service:e.service??s?.service}:{},...e.method??s?.method?{method:e.method??s?.method}:{},...o.length?{routes:[...new Set(o)]}:{},...e.status??s?.status!==void 0?{status:e.status??s?.status}:{},...r||e.attributes?{attributes:{...r??{},...e.attributes??{}}}:{}}}}const I=new Map,j=c((t,e)=>t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,e).replace(/\?/g,"."),"globBody");function M(t,e="whole"){const s=`${e}\0${t}`;let r=I.get(s);return r||(r=e==="whole"?new RegExp(`^${j(t,"[\\s\\S]*")}$`,"i"):e==="anywhere"?new RegExp(j(t,"[\\s\\S]*"),"i"):new RegExp(`(?:^|[^\\w.])${j(t,"[\\w.]*")}(?:$|[^\\w.])`,"i"),I.size>1e3&&I.clear(),I.set(s,r)),r}h(M,"S"),c(M,"globRe");const v=c((t,e)=>e!==void 0&&M(t).test(e),"glob");function D(t,e){const s=e.routes??[],r=/^([A-Za-z]+)\s+(\S.*)$/.exec(t);return r&&/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|\*)$/i.test(r[1])?r[1]!=="*"&&(e.method??"").toUpperCase()!==r[1].toUpperCase()?!1:s.some(o=>v(r[2],o)):s.some(o=>v(t,o))}h(D,"B"),c(D,"routeMatches");function L(t,e){const s=[e.flowId,...e.flowNames??[]].filter(o=>!!o),r=t.endsWith(":")?`${t}*`:t;return s.some(o=>v(r,o))}h(L,"G"),c(L,"flowMatches");function U(t,e){return v(t,e.errorName)||(e.errorKeys??[]).some(s=>v(t,s))?!0:e.message!==void 0&&M(t,"word").test(e.message)}h(U,"W"),c(U,"errorMatches");export function expectedMatches(t,e){return!(t.service!==void 0&&!v(t.service,e.service)||t.route!==void 0&&!D(t.route,e)||t.span!==void 0&&!v(t.span,e.span)||t.flow!==void 0&&!L(t.flow,e)||t.status!==void 0&&e.status!==t.status||t.error!==void 0&&!U(t.error,e)||t.message!==void 0&&!(e.message!==void 0&&M(t.message,"anywhere").test(e.message))||t.attribute!==void 0&&!v(t.attribute.value,e.attributes?.[t.attribute.name]))}h(expectedMatches,"expectedMatches"),c(expectedMatches,"expectedMatches");export function expectedMatchIsPerOccurrence(t){return t.flow!==void 0||t.attribute!==void 0||t.message!==void 0&&/\d/.test(t.message)}h(expectedMatchIsPerOccurrence,"expectedMatchIsPerOccurrence"),c(expectedMatchIsPerOccurrence,"expectedMatchIsPerOccurrence");export function suggestExpectedMatch(t){const e=t.routes?.find(a=>a.startsWith("/")),s=t.flowNames?.find(a=>a.startsWith("job:")&&!a.includes("#"))??(t.flowId?`${t.flowId.split(":")[0]}:`:void 0),r=e?{route:t.method?`${t.method.toUpperCase()} ${e}`:e}:t.span?{span:t.span}:s?{flow:s}:{},o=t.message?.split(`
2
+ `)[0]?.replace(/\d+/g,"*").replace(/\*+/g,"*").slice(0,120).trim(),i=t.status!==void 0?{status:t.status}:t.errorName&&t.errorName!=="Error"?{error:t.errorName}:o?{message:o}:{},u=checkExpectedMatch({...t.service?{service:t.service}:{},...r,...i});return"match"in u?u.match:void 0}h(suggestExpectedMatch,"suggestExpectedMatch"),c(suggestExpectedMatch,"suggestExpectedMatch");export const EXPECTED_SURGE_FACTOR=10,EXPECTED_SURGE_MIN_PER_HOUR=20;const Z=2*m,X=24*m,q=6e4;export class ExpectedRuleBook{static{h(this,"ExpectedRuleBook")}static{c(this,"ExpectedRuleBook")}constructor(e=Date.now()){this.startedAt=e,this.runtime=new Map,this.repository=[],this.repositoryKey="",this.stats=new Map,this.ended=[],this.version=0}apply(e,s){const r=readExpectedRule(e);if(!r)return!1;const o=this.runtime.get(r.id);if(this.runtime.delete(r.id),r.kind===EXPECTED_RULE_REMOVED)o&&this.end(o,s,"removed",r.by);else{const{kind:i,...u}=r;if(this.runtime.set(u.id,u),this.stats.has(u.id)||this.stats.set(u.id,{hits:0,minutes:new Map,since:Math.max(u.createdAt,this.startedAt)}),this.runtime.size>J){const a=this.runtime.keys().next().value,d=this.runtime.get(a);this.runtime.delete(a),this.end(d,s,"expired")}}return this.version++,!0}setRepository(e,s){const r=JSON.stringify(e.map(i=>[i.id,i.match,i.reason]));if(r===this.repositoryKey)return!1;const o=new Set(e.map(i=>i.id));for(const i of this.repository)o.has(i.id)||this.end(i,s,"dropped from lensmcp.json");this.repository=e.slice(),this.repositoryKey=r;for(const i of e)this.stats.has(i.id)||this.stats.set(i.id,{hits:0,minutes:new Map,since:Math.max(this.startedAt,Math.min(i.createdAt,s))});return this.version++,!0}expire(e){let s=!1;for(const[r,o]of this.runtime)o.expiresAt===void 0||o.expiresAt>e||(this.runtime.delete(r),this.end(o,o.expiresAt,"expired"),s=!0);return s&&this.version++,s}end(e,s,r,o){this.ended.unshift({...e,endedAt:s,why:r,...o?{removedBy:o}:{}}),this.ended.length>H&&(this.ended.length=H)}active(e){return[...this.repository,...[...this.runtime.values()].filter(s=>s.expiresAt===void 0||s.expiresAt>e)]}get(e){return this.runtime.get(e)??this.repository.find(s=>s.id===e)}isActive(e,s){const r=this.get(e);return!!r&&(r.expiresAt===void 0||r.expiresAt>s)}get size(){return this.runtime.size+this.repository.length}holderOf(e,s){if(this.size!==0)return this.active(s).find(r=>expectedMatches(r.match,e))}count(e,s,r=1){const o=this.stats.get(e);if(!o||r<=0||(o.hits+=r,s===void 0))return;o.lastHitAt=Math.max(o.lastHitAt??0,s);const i=Math.floor(s/q);if(o.minutes.set(i,(o.minutes.get(i)??0)+r),o.minutes.size>1600){const u=i-(X+m)/q;for(const a of o.minutes.keys())a<u&&o.minutes.delete(a)}}windowCount(e,s,r){let o=0;for(const[i,u]of e.minutes)i*q>=s&&i*q<r&&(o+=u);return o}judge(e,s){const r=this.windowCount(e,s-m,s+1),o=Math.max(e.since,s-m-X),i=s-m-o;if(i<Z)return e.surge=void 0;const u=this.windowCount(e,o,s-m)/(i/m),a=Math.max(EXPECTED_SURGE_MIN_PER_HOUR,EXPECTED_SURGE_FACTOR*u);return e.surge?r<a/3?e.surge=void 0:e.surge={...e.surge,lastHour:r}:r>=a&&(e.surge={since:s,lastHour:r,usualPerHour:Math.round(u*10)/10}),e.surge}list(e){return this.active(e).map(s=>{const r=this.stats.get(s.id),o=r?this.judge(r,e):void 0;return{...s,hits:r?.hits??0,...r?.lastHitAt!==void 0?{lastHitAt:r.lastHitAt}:{},lastHour:r?this.windowCount(r,e-m,e+1):0,...o?{surge:o}:{}}}).sort((s,r)=>+(s.by==="repository")-+(r.by==="repository")||r.createdAt-s.createdAt)}endedRules(){return this.ended.slice()}}export function heldBackLine(t,e,s=""){return`${t} rule${t===1?"":"s"} held back ${e} occurrence${e===1?"":"s"}${s?` ${s}`:""}`}h(heldBackLine,"heldBackLine"),c(heldBackLine,"heldBackLine");export function surgeLine(t){const e=t.surge;return`this expected failure is now happening much more often: ${describeExpectedMatch(t.match)} \u2014 ${e?`${e.lastHour} in the last hour, usually ${e.usualPerHour} an hour`:"its rate jumped"} (expected because: ${t.reason})`}h(surgeLine,"surgeLine"),c(surgeLine,"surgeLine");
@@ -1 +1 @@
1
- "use strict";var o=Object.defineProperty;var a=(e,t)=>o(e,"name",{value:t,configurable:!0});var r=Object.defineProperty,s=a((e,t)=>r(e,"name",{value:t,configurable:!0}),"a"),n=Object.defineProperty,d=s((e,t)=>n(e,"name",{value:t,configurable:!0}),"s");export const FINDING_RISK_CLASSES=["same-bytes","after-the-model","moved-content","less-text-or-schema","new-mechanism"],FINDING_RISK_CLASS={"same-bytes":{label:"Same bytes",reads:"the model reads the same bytes",example:"breakpoints, a prewarm, the order requests are sent",proof:"a byte-identity spec (the new request, joined, is the old one byte for byte) and a cost measurement"},"after-the-model":{label:"After the model",reads:"the model reads the same bytes; code after it changes",example:"dropping a finding that code adds to the answer",proof:"a free replay: the same recorded answers through the old and the new code, everything else byte-equal"},"moved-content":{label:"Moved content",reads:"the model reads the same content in another place or order",example:"cache levels, moving a section",proof:"a paired comparison: before and after side by side, in one session, more than one run a side"},"less-text-or-schema":{label:"Less text or a new schema",reads:"the model reads less text, or a changed schema or instruction",example:"shorter rows, field order, a fact stated once",proof:"the full accuracy comparison"},"new-mechanism":{label:"New mechanism",reads:"the model is asked in a new way",example:"grouping products in one call",proof:"a design first"}};const m={"same-bytes":"same-bytes","same-bytes-read":"same-bytes","byte-identical":"same-bytes","after-the-model":"after-the-model","after-model":"after-the-model","code-after-the-model":"after-the-model","code-after-model":"after-the-model","moved-content":"moved-content",moved:"moved-content","same-content-moved":"moved-content","less-text-or-schema":"less-text-or-schema","less-text":"less-text-or-schema","changed-schema":"less-text-or-schema","less-text-or-a-changed-schema":"less-text-or-schema","new-mechanism":"new-mechanism",new:"new-mechanism"};export function readRiskClass(e){if(typeof e!="string")return;const t=e.trim().toLowerCase().replace(/[\s_]+/g,"-");return m[t]}a(readRiskClass,"readRiskClass"),s(readRiskClass,"readRiskClass"),d(readRiskClass,"readRiskClass");export const FINDING_PROOF_ASK=[`"riskClass": one of ${FINDING_RISK_CLASSES.map(e=>`"${e}"`).join(" | ")} \u2014 what the model reads after the change (${FINDING_RISK_CLASSES.map(e=>`${e}: ${FINDING_RISK_CLASS[e].reads}`).join("; ")}); in doubt, the riskier`,`"proofOwed": "what must be shown before it ships \u2014 its class's proof (${FINDING_RISK_CLASSES.map(e=>`${e}: ${FINDING_RISK_CLASS[e].proof}`).join("; ")}), made concrete for this change: which spec, which calls, how many runs a side"`,`"saving": { "amount": "what it saves, with its unit and per what ('$0.18 per run', '12,000 input tokens a call', '120 s off the stage')", "arithmetic": "the formula with the evidence's numbers and the prices it used", "kind": "estimate" | "measured" (measured only when the evidence holds calls from before and after the change) } or null when it saves nothing countable`];
1
+ "use strict";var s=Object.defineProperty;var a=(e,t)=>s(e,"name",{value:t,configurable:!0});var o=Object.defineProperty,r=a((e,t)=>o(e,"name",{value:t,configurable:!0}),"s");export const FINDING_RISK_CLASSES=["same-bytes","after-the-model","moved-content","less-text-or-schema","new-mechanism"],FINDING_RISK_CLASS={"same-bytes":{label:"Same bytes",reads:"the model reads the same bytes",example:"breakpoints, a prewarm, the order requests are sent",proof:"a byte-identity spec (the new request, joined, is the old one byte for byte) and a cost measurement"},"after-the-model":{label:"After the model",reads:"the model reads the same bytes; code after it changes",example:"dropping a finding that code adds to the answer",proof:"a free replay: the same recorded answers through the old and the new code, everything else byte-equal"},"moved-content":{label:"Moved content",reads:"the model reads the same content in another place or order",example:"cache levels, moving a section",proof:"a paired comparison: before and after side by side, in one session, more than one run a side"},"less-text-or-schema":{label:"Less text or a new schema",reads:"the model reads less text, or a changed schema or instruction",example:"shorter rows, field order, a fact stated once",proof:"the full accuracy comparison"},"new-mechanism":{label:"New mechanism",reads:"the model is asked in a new way",example:"grouping products in one call",proof:"a design first"}};const n={"same-bytes":"same-bytes","same-bytes-read":"same-bytes","byte-identical":"same-bytes","after-the-model":"after-the-model","after-model":"after-the-model","code-after-the-model":"after-the-model","code-after-model":"after-the-model","moved-content":"moved-content",moved:"moved-content","same-content-moved":"moved-content","less-text-or-schema":"less-text-or-schema","less-text":"less-text-or-schema","changed-schema":"less-text-or-schema","less-text-or-a-changed-schema":"less-text-or-schema","new-mechanism":"new-mechanism",new:"new-mechanism"};export function readRiskClass(e){if(typeof e!="string")return;const t=e.trim().toLowerCase().replace(/[\s_]+/g,"-");return n[t]}a(readRiskClass,"readRiskClass"),r(readRiskClass,"readRiskClass");export const FINDING_PROOF_ASK=[`"riskClass": one of ${FINDING_RISK_CLASSES.map(e=>`"${e}"`).join(" | ")} \u2014 what the model reads after the change (${FINDING_RISK_CLASSES.map(e=>`${e}: ${FINDING_RISK_CLASS[e].reads}`).join("; ")}); in doubt, the riskier`,`"proofOwed": "what must be shown before it ships \u2014 its class's proof (${FINDING_RISK_CLASSES.map(e=>`${e}: ${FINDING_RISK_CLASS[e].proof}`).join("; ")}), made concrete for this change: which spec, which calls, how many runs a side"`,`"saving": { "amount": "what it saves, with its unit and per what ('$0.18 per run', '12,000 input tokens a call', '120 s off the stage')", "arithmetic": "the formula with the evidence's numbers and the prices it used", "kind": "estimate" | "measured" (measured only when the evidence holds calls from before and after the change) } or null when it saves nothing countable`];
@@ -1 +1 @@
1
- "use strict";var S=Object.defineProperty;var i=(t,s)=>S(t,"name",{value:s,configurable:!0});var A=Object.defineProperty,f=i((t,s)=>A(t,"name",{value:s,configurable:!0}),"i"),k=Object.defineProperty,u=f((t,s)=>k(t,"name",{value:s,configurable:!0}),"o");function l(){const t=typeof process<"u"?process.env?.LENSMCP_EVENT_MAX_EPS:void 0;if(t===void 0||t==="")return;if(t==="off")return"off";const s=Number(t);if(Number.isFinite(s))return s<=0?"off":s}i(l,"d"),f(l,"S"),u(l,"envPerSec");export function createEventFloodGuard(t){const s=t?.envOverride===!1?void 0:l();if(s==="off")return{admit:u(()=>({ok:!0,suppressed:0}),"admit")};const c=s??t?.perSec??5,d=Math.max(1,t?.burst??Math.max(30,c*4)),p=t?.maxKeys??2048,n=new Map,v=u(o=>{for(const[r,e]of n)o-e.lastSeenAt>6e4&&n.delete(r);if(n.size>p){const r=[...n.entries()].sort((e,a)=>e[1].lastSeenAt-a[1].lastSeenAt);for(let e=0;e<r.length>>1;e++)n.delete(r[e][0])}},"evictStale");return{admit(o){const r=Date.now();let e=n.get(o);e||(n.size>=p&&v(r),e={tokens:d,lastRefillAt:r,suppressed:0,lastSeenAt:r},n.set(o,e)),e.lastSeenAt=r;const a=r-e.lastRefillAt;if(a>0&&(e.tokens=Math.min(d,e.tokens+a/1e3*c),e.lastRefillAt=r),e.tokens>=1){e.tokens-=1;const m=e.suppressed;return e.suppressed=0,{ok:!0,suppressed:m}}return e.suppressed+=1,{ok:!1,suppressed:0}}}}i(createEventFloodGuard,"createEventFloodGuard"),f(createEventFloodGuard,"createEventFloodGuard"),u(createEventFloodGuard,"createEventFloodGuard");
1
+ "use strict";var S=Object.defineProperty;var i=(t,n)=>S(t,"name",{value:n,configurable:!0});var m=Object.defineProperty,u=i((t,n)=>m(t,"name",{value:n,configurable:!0}),"o");function d(){const t=typeof process<"u"?process.env?.LENSMCP_EVENT_MAX_EPS:void 0;if(t===void 0||t==="")return;if(t==="off")return"off";const n=Number(t);if(Number.isFinite(n))return n<=0?"off":n}i(d,"S"),u(d,"envPerSec");export function createEventFloodGuard(t){const n=t?.envOverride===!1?void 0:d();if(n==="off")return{admit:u(()=>({ok:!0,suppressed:0}),"admit")};const l=n??t?.perSec??5,f=Math.max(1,t?.burst??Math.max(30,l*4)),c=t?.maxKeys??2048,r=new Map,p=u(o=>{for(const[s,e]of r)o-e.lastSeenAt>6e4&&r.delete(s);if(r.size>c){const s=[...r.entries()].sort((e,a)=>e[1].lastSeenAt-a[1].lastSeenAt);for(let e=0;e<s.length>>1;e++)r.delete(s[e][0])}},"evictStale");return{admit(o){const s=Date.now();let e=r.get(o);e||(r.size>=c&&p(s),e={tokens:f,lastRefillAt:s,suppressed:0,lastSeenAt:s},r.set(o,e)),e.lastSeenAt=s;const a=s-e.lastRefillAt;if(a>0&&(e.tokens=Math.min(f,e.tokens+a/1e3*l),e.lastRefillAt=s),e.tokens>=1){e.tokens-=1;const v=e.suppressed;return e.suppressed=0,{ok:!0,suppressed:v}}return e.suppressed+=1,{ok:!1,suppressed:0}}}}i(createEventFloodGuard,"createEventFloodGuard"),u(createEventFloodGuard,"createEventFloodGuard");
@@ -42,9 +42,14 @@ export interface DashDesignQuestion {
42
42
  question: string;
43
43
  /** What the overseer found that the answer turns on. */
44
44
  context?: string;
45
+ /**
46
+ * Each option: its label, the line after it (`detail`), and its write-up — the Markdown indented under it (`body`): what
47
+ * the person gets, what it costs, its risk, a diagram when it changes how it works. Absent on a version before format 2.
48
+ */
45
49
  options: Array<{
46
50
  label: string;
47
51
  detail?: string;
52
+ body?: string;
48
53
  }>;
49
54
  /** The number (1…) of the recommended option. */
50
55
  recommended: number;
@@ -118,6 +123,11 @@ export interface DashDesignVersion {
118
123
  format?: 'mdx';
119
124
  /** The canvas this version is drawn as (its questions are the canvas's decisions). Absent: not drawn as one yet. */
120
125
  canvas?: DashDesignCanvasRef;
126
+ /**
127
+ * The design format it was checked against: 2 — «How it works» with a diagram, each option written up (owner,
128
+ * 2026-11-24). Absent: handed in before; LensMCP sends a waiting one back to be written again ({@link DashGoalDesign.rewrite}).
129
+ */
130
+ form?: number;
121
131
  }
122
132
  /**
123
133
  * One version of a design as a canvas: the canvas (`cv-…`, one per design, linked to its goal) and its version. Its
@@ -127,6 +137,8 @@ export interface DashDesignVersion {
127
137
  export interface DashDesignCanvasRef {
128
138
  id: string;
129
139
  version: number;
140
+ /** How the version was laid out as a canvas: 2 — the reading order, its evidence folded. Absent: the first layout. */
141
+ layout?: number;
130
142
  }
131
143
  /** The canvas decision a design question is: its `qid` is the question's id (`q1`); an option `o<n>` is option n. */
132
144
  export declare const designOptionId: (n: number) => string;
@@ -198,6 +210,16 @@ export interface DashGoalDesign {
198
210
  file?: string;
199
211
  /** The canvas its versions are drawn as (`cv-…`): one per design, a canvas version per design version. */
200
212
  canvas?: string;
213
+ /**
214
+ * LensMCP sent this version back to the overseer to be written again in the format designs are held to now (a diagram
215
+ * of how it works, each option written up) — not the person's word: nothing they answered was sent, and the version
216
+ * stays readable. Once per version; the overseer's next version is in the new format.
217
+ */
218
+ rewrite?: {
219
+ version: number;
220
+ at: number;
221
+ why: string;
222
+ };
201
223
  }
202
224
  /** A design on the Inbox › Designs list. */
203
225
  export interface DashDesignBrief {
@@ -220,6 +242,8 @@ export interface DashDesignBrief {
220
242
  decision?: DashDesignDecision;
221
243
  /** The newest version as a canvas: the canvas's own pages (Canvases, a canvas opened anywhere) answer it too. */
222
244
  canvas?: DashDesignCanvasRef;
245
+ /** LensMCP sent the newest version back to be written again in the new format ({@link DashGoalDesign.rewrite}). */
246
+ rewrite?: boolean;
223
247
  }
224
248
  export interface DashDesignsAnswer {
225
249
  designs: DashDesignBrief[];
@@ -1 +1 @@
1
- "use strict";var o=Object.defineProperty;var r=(e,n)=>o(e,"name",{value:n,configurable:!0});var s=Object.defineProperty,a=r((e,n)=>s(e,"name",{value:n,configurable:!0}),"r"),l=Object.defineProperty,i=a((e,n)=>l(e,"name",{value:n,configurable:!0}),"r");export const DESIGN_TYPES=["bug","investigation","performance","reliability","feature","architecture","maintenance"],DESIGN_CONCERNS=["security","data","api","ui","integration","operations"],DESIGN_TYPE_INFO={bug:{label:"Bug",when:"Something works wrong, and the cause is known or can be found by reading the code."},investigation:{label:"Investigation",when:"Symptoms without a known cause: research first, and the goal ends in a decision or a fix."},performance:{label:"Performance",when:"Something is measurably slow, heavy or costly: a baseline the lens measured and a target."},reliability:{label:"Reliability",when:"Crashes, stalls, flaky tests, lost work, CI or the machine: how it fails and how often."},feature:{label:"Feature",when:"Someone can do something they cannot do now."},architecture:{label:"Architecture",when:"Boundaries, contracts or structure change, in steps that each ship."},maintenance:{label:"Maintenance",when:"Upgrades, moves, tooling and cleanup: no new behaviour, and nothing breaks."}},DESIGN_CONCERN_INFO={security:{label:"Security",when:"Auth, permissions, secrets, input from outside, or anything an attacker would read."},data:{label:"Data",when:"Schema, migrations, backfills, or data already stored."},api:{label:"API",when:"A request or response other code or other people depend on."},ui:{label:"UI",when:"Screens, flows or what a person sees."},integration:{label:"Integration",when:"A service outside the repository: its API, keys, limits and failures."},operations:{label:"Operations",when:"How it deploys, runs, is watched and is rolled back."}},DESIGN_STAGES=["proposed","requested","drafting","waiting","changes","approved","declined"],designOptionId=i(e=>`o${e}`,"designOptionId");export function designOptionOf(e){const n=typeof e=="string"?/^o([1-9])$/.exec(e):null;return n?Number(n[1]):void 0}r(designOptionOf,"designOptionOf"),a(designOptionOf,"designOptionOf"),i(designOptionOf,"designOptionOf");export function designWriter(e){if(e.writer)return e.writer;if(e.by==="user")return{kind:"person"};if(e.by==="lensmcp")return{kind:"lensmcp",...e.byName?{name:e.byName}:{}}}r(designWriter,"designWriter"),a(designWriter,"designWriter"),i(designWriter,"designWriter");const d={claude:"Claude Code",codex:"Codex"};export function designWriterText(e){const n=designWriter(e);if(!n)return"who handed it in was not recorded";const t=n.client?d[n.client]:void 0;switch(n.kind){case"person":return"written by the person";case"lensmcp":return"written by LensMCP's own run";case"terminal":return"handed in from a terminal, as the overseer";case"session":return`handed in by ${t?`a ${t}`:"an agent's"} session${n.role?`, the team's ${n.role}`:" with no role on this team"}`;case"launch":return n.purpose==="design"?`written by a design launch${t?` on ${t}`:""}`:`handed in by the overseer's ${n.purpose==="inbox"?"inbox launch":n.purpose==="round"?"round":"launch"}${t?` on ${t}`:""}`}}r(designWriterText,"designWriterText"),a(designWriterText,"designWriterText"),i(designWriterText,"designWriterText");
1
+ "use strict";var i=Object.defineProperty;var r=(e,n)=>i(e,"name",{value:n,configurable:!0});var o=Object.defineProperty,a=r((e,n)=>o(e,"name",{value:n,configurable:!0}),"r");export const DESIGN_TYPES=["bug","investigation","performance","reliability","feature","architecture","maintenance"],DESIGN_CONCERNS=["security","data","api","ui","integration","operations"],DESIGN_TYPE_INFO={bug:{label:"Bug",when:"Something works wrong, and the cause is known or can be found by reading the code."},investigation:{label:"Investigation",when:"Symptoms without a known cause: research first, and the goal ends in a decision or a fix."},performance:{label:"Performance",when:"Something is measurably slow, heavy or costly: a baseline the lens measured and a target."},reliability:{label:"Reliability",when:"Crashes, stalls, flaky tests, lost work, CI or the machine: how it fails and how often."},feature:{label:"Feature",when:"Someone can do something they cannot do now."},architecture:{label:"Architecture",when:"Boundaries, contracts or structure change, in steps that each ship."},maintenance:{label:"Maintenance",when:"Upgrades, moves, tooling and cleanup: no new behaviour, and nothing breaks."}},DESIGN_CONCERN_INFO={security:{label:"Security",when:"Auth, permissions, secrets, input from outside, or anything an attacker would read."},data:{label:"Data",when:"Schema, migrations, backfills, or data already stored."},api:{label:"API",when:"A request or response other code or other people depend on."},ui:{label:"UI",when:"Screens, flows or what a person sees."},integration:{label:"Integration",when:"A service outside the repository: its API, keys, limits and failures."},operations:{label:"Operations",when:"How it deploys, runs, is watched and is rolled back."}},DESIGN_STAGES=["proposed","requested","drafting","waiting","changes","approved","declined"],designOptionId=a(e=>`o${e}`,"designOptionId");export function designOptionOf(e){const n=typeof e=="string"?/^o([1-9])$/.exec(e):null;return n?Number(n[1]):void 0}r(designOptionOf,"designOptionOf"),a(designOptionOf,"designOptionOf");export function designWriter(e){if(e.writer)return e.writer;if(e.by==="user")return{kind:"person"};if(e.by==="lensmcp")return{kind:"lensmcp",...e.byName?{name:e.byName}:{}}}r(designWriter,"designWriter"),a(designWriter,"designWriter");const s={claude:"Claude Code",codex:"Codex"};export function designWriterText(e){const n=designWriter(e);if(!n)return"who handed it in was not recorded";const t=n.client?s[n.client]:void 0;switch(n.kind){case"person":return"written by the person";case"lensmcp":return"written by LensMCP's own run";case"terminal":return"handed in from a terminal, as the overseer";case"session":return`handed in by ${t?`a ${t}`:"an agent's"} session${n.role?`, the team's ${n.role}`:" with no role on this team"}`;case"launch":return n.purpose==="design"?`written by a design launch${t?` on ${t}`:""}`:`handed in by the overseer's ${n.purpose==="inbox"?"inbox launch":n.purpose==="round"?"round":"launch"}${t?` on ${t}`:""}`}}r(designWriterText,"designWriterText"),a(designWriterText,"designWriterText");
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty;var o=(t,e)=>c(t,"name",{value:e,configurable:!0});var u=Object.defineProperty,n=o((t,e)=>u(t,"name",{value:e,configurable:!0}),"s"),i=Object.defineProperty,s=n((t,e)=>i(t,"name",{value:e,configurable:!0}),"o");export const HOST_AGENT_CLIENTS=["claude","codex"],HOST_AGENTS_FILES={agents:"host-agents.json",ceilings:"host-ceilings.json"},HOST_AGENTS_LIMITS={accounts:32,windows:6,label:60,why:300,plan:40,name:40,agents:64},HOST_ACCOUNT_ID=/^ac-[a-z0-9]{1,12}-[a-f0-9]{6}$/;const r=[/\bsk-[A-Za-z0-9_-]{16,}/,/\b[rs]k_(?:live|test)_[A-Za-z0-9]{12,}/,/\bgh[pousr]_[A-Za-z0-9]{20,}|\bgithub_pat_[A-Za-z0-9_]{20,}/,/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/,/\bxox[abposr]-[A-Za-z0-9-]{10,}/,/\bAIza[0-9A-Za-z_-]{30,}/,/\beyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{4,}/,/-----BEGIN [A-Z ]*(?:PRIVATE KEY|CERTIFICATE)-----/,/\bbearer\s+[A-Za-z0-9._~+/=-]{12,}/i],A=/[A-Za-z0-9+/_=-]{32,}/g;export function tokenShaped(t){if(r.some(e=>e.test(t)))return!0;for(const e of t.match(A)??[])if(/\d/.test(e)&&/[A-Za-z]/.test(e))return!0;return!1}o(tokenShaped,"tokenShaped"),n(tokenShaped,"tokenShaped"),s(tokenShaped,"tokenShaped");export function withoutTokens(t){let e=t;for(const a of r)e=e.replace(new RegExp(a.source,a.flags.includes("g")?a.flags:`${a.flags}g`),"\u2026");return e.replace(A,a=>/\d/.test(a)&&/[A-Za-z]/.test(a)?"\u2026":a)}o(withoutTokens,"withoutTokens"),n(withoutTokens,"withoutTokens"),s(withoutTokens,"withoutTokens");
1
+ "use strict";var A=Object.defineProperty;var s=(t,e)=>A(t,"name",{value:e,configurable:!0});var c=Object.defineProperty,o=s((t,e)=>c(t,"name",{value:e,configurable:!0}),"o");export const HOST_AGENT_CLIENTS=["claude","codex"],HOST_AGENTS_FILES={agents:"host-agents.json",ceilings:"host-ceilings.json"},HOST_AGENTS_LIMITS={accounts:32,windows:6,label:60,why:300,plan:40,name:40,agents:64},HOST_ACCOUNT_ID=/^ac-[a-z0-9]{1,12}-[a-f0-9]{6}$/;const n=[/\bsk-[A-Za-z0-9_-]{16,}/,/\b[rs]k_(?:live|test)_[A-Za-z0-9]{12,}/,/\bgh[pousr]_[A-Za-z0-9]{20,}|\bgithub_pat_[A-Za-z0-9_]{20,}/,/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/,/\bxox[abposr]-[A-Za-z0-9-]{10,}/,/\bAIza[0-9A-Za-z_-]{30,}/,/\beyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{4,}/,/-----BEGIN [A-Z ]*(?:PRIVATE KEY|CERTIFICATE)-----/,/\bbearer\s+[A-Za-z0-9._~+/=-]{12,}/i],r=/[A-Za-z0-9+/_=-]{32,}/g;export function tokenShaped(t){if(n.some(e=>e.test(t)))return!0;for(const e of t.match(r)??[])if(/\d/.test(e)&&/[A-Za-z]/.test(e))return!0;return!1}s(tokenShaped,"tokenShaped"),o(tokenShaped,"tokenShaped");export function withoutTokens(t){let e=t;for(const a of n)e=e.replace(new RegExp(a.source,a.flags.includes("g")?a.flags:`${a.flags}g`),"\u2026");return e.replace(r,a=>/\d/.test(a)&&/[A-Za-z]/.test(a)?"\u2026":a)}s(withoutTokens,"withoutTokens"),o(withoutTokens,"withoutTokens");
package/lib/lens-hosts.js CHANGED
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty;var r=(e,n)=>c(e,"name",{value:n,configurable:!0});var i=Object.defineProperty,t=r((e,n)=>i(e,"name",{value:n,configurable:!0}),"t"),u=Object.defineProperty,o=t((e,n)=>u(e,"name",{value:n,configurable:!0}),"r");export const LENS_HOST="lensmcp.localhost",LEGACY_LENS_HOST="lensmcp.local",CANVAS_LINK_PATH="/canvas";export function lensOrigin(e={}){const n=e.port!==void 0&&e.port!==443?`:${e.port}`:"";return`https://${e.host||LENS_HOST}${n}`}r(lensOrigin,"lensOrigin"),t(lensOrigin,"lensOrigin"),o(lensOrigin,"lensOrigin");export function dashboardLink(e,n="",a={}){const s=e.replace(/\/+$/,"");return`${lensOrigin(a)}${s}/${n.replace(/^\/+/,"")}`}r(dashboardLink,"dashboardLink"),t(dashboardLink,"dashboardLink"),o(dashboardLink,"dashboardLink");export function canvasKeyFreeLink(e,n={}){return`${lensOrigin(n)}${CANVAS_LINK_PATH}/${e}`}r(canvasKeyFreeLink,"canvasKeyFreeLink"),t(canvasKeyFreeLink,"canvasKeyFreeLink"),o(canvasKeyFreeLink,"canvasKeyFreeLink");export function gatewayPortFromEnv(e){const n=Number((e.LENSMCP_GATEWAY_PORTS??"").split(",")[0]);return Number.isInteger(n)&&n>0&&n<65536?n:void 0}r(gatewayPortFromEnv,"gatewayPortFromEnv"),t(gatewayPortFromEnv,"gatewayPortFromEnv"),o(gatewayPortFromEnv,"gatewayPortFromEnv");export function currentLensHost(e){return e.trim().toLowerCase()===LEGACY_LENS_HOST?LENS_HOST:e}r(currentLensHost,"currentLensHost"),t(currentLensHost,"currentLensHost"),o(currentLensHost,"currentLensHost");
1
+ "use strict";var a=Object.defineProperty;var t=(r,e)=>a(r,"name",{value:e,configurable:!0});var c=Object.defineProperty,n=t((r,e)=>c(r,"name",{value:e,configurable:!0}),"r");export const LENS_HOST="lensmcp.localhost",LEGACY_LENS_HOST="lensmcp.local",CANVAS_LINK_PATH="/canvas";export function lensOrigin(r={}){const e=r.port!==void 0&&r.port!==443?`:${r.port}`:"";return`https://${r.host||LENS_HOST}${e}`}t(lensOrigin,"lensOrigin"),n(lensOrigin,"lensOrigin");export function dashboardLink(r,e="",o={}){const s=r.replace(/\/+$/,"");return`${lensOrigin(o)}${s}/${e.replace(/^\/+/,"")}`}t(dashboardLink,"dashboardLink"),n(dashboardLink,"dashboardLink");export function canvasKeyFreeLink(r,e={}){return`${lensOrigin(e)}${CANVAS_LINK_PATH}/${r}`}t(canvasKeyFreeLink,"canvasKeyFreeLink"),n(canvasKeyFreeLink,"canvasKeyFreeLink");export function gatewayPortFromEnv(r){const e=Number((r.LENSMCP_GATEWAY_PORTS??"").split(",")[0]);return Number.isInteger(e)&&e>0&&e<65536?e:void 0}t(gatewayPortFromEnv,"gatewayPortFromEnv"),n(gatewayPortFromEnv,"gatewayPortFromEnv");export function currentLensHost(r){return r.trim().toLowerCase()===LEGACY_LENS_HOST?LENS_HOST:r}t(currentLensHost,"currentLensHost"),n(currentLensHost,"currentLensHost");
@@ -1 +1 @@
1
- "use strict";var C=Object.defineProperty;var p=(e,r)=>C(e,"name",{value:r,configurable:!0});var k=Object.defineProperty,h=p((e,r)=>k(e,"name",{value:r,configurable:!0}),"g"),A=Object.defineProperty,d=h((e,r)=>A(e,"name",{value:r,configurable:!0}),"i");import{TRUNCATION_MARKER_KEY as j}from"./bounded-clone.js";export const LINT_COVER_KIND="lint-cover",MAX_LINT_UNCOMMITTED=500;const L=["tree","paths","changed","incremental"],m=d(e=>Array.isArray(e)?e.filter(r=>typeof r=="string"&&r.length>0):[],"strings"),i=d(e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.floor(e):void 0,"count"),l=d(e=>typeof e=="string"&&e?e:void 0,"text");export function readLintCoverage(e){if(!e||typeof e!="object"||e[j])return;const r=e.coverage;if(!r||typeof r!="object")return;const t=r,n=t.kind,a=t.root;if(!L.includes(n)||typeof a!="string"||!a)return;const u=m(t.dirs),o=m(t.files),g=m(t.gone),$=i(t.notLinted),y=i(t.untracked),s=t.base&&typeof t.base=="object"?t.base:void 0,v=s&&l(s.sha)&&l(s.run)?{from:s.from==="main"?"main":"own",sha:s.sha,run:s.run}:void 0,b=Array.isArray(t.inputs)?t.inputs.flatMap(f=>Array.isArray(f)&&typeof f[0]=="string"&&typeof f[1]=="string"?[[f[0],f[1]]]:[]):void 0;return{kind:n,root:a,dirs:u,files:o,gone:g,fileCount:i(t.fileCount)??o.length,goneCount:i(t.goneCount)??g.length,linted:i(t.linted)??0,...i(t.dirCount)!==void 0?{dirCount:i(t.dirCount)}:{},...$?{notLinted:$}:{},...y?{untracked:y}:{},...l(t.since)?{since:t.since}:{},...l(t.head)?{head:t.head}:{},...typeof t.dirty=="boolean"?{dirty:t.dirty}:{},...Array.isArray(t.uncommitted)?{uncommitted:m(t.uncommitted)}:{},...t.uncommittedMore===!0?{uncommittedMore:!0}:{},...b?{inputs:b}:{},...l(t.folder)?{folder:t.folder}:{},...t.projects===!0?{projects:!0}:{},...v?{base:v}:{},...t.fromZero===!0?{fromZero:!0}:{},...t.narrowed===!0?{narrowed:!0}:{}}}p(readLintCoverage,"readLintCoverage"),h(readLintCoverage,"readLintCoverage"),d(readLintCoverage,"readLintCoverage");const c=d((e,r)=>`${e} ${r}${e===1?"":"s"}`,"some");export function lintCoverageLabel(e,r={}){const t=e.files??0,n=e.gone??0;if(e.kind==="changed"){const o=`since ${e.since??"HEAD"}`;if(!t)return`${c(n,"deleted file")} ${o}`;const g=r.untracked&&e.untracked?` (${e.untracked} untracked)`:"";return`${c(t,"changed file")} ${o}${g}${n?`, ${n} deleted`:""}`}if(e.kind==="incremental"){const o=e.since?` since ${e.since.slice(0,7)}`:"";return!t&&!n?`nothing changed${o}`:t?`${c(t,"file")} changed${o}${n?`, ${n} deleted`:""}`:`${c(n,"file")} deleted${o}`}if(e.kind==="tree"&&e.projects)return`the workspace\u2019s ${c(e.projects,"project")}`;if(e.kind==="tree"&&e.paths[0]===".")return"whole checkout";if(e.narrowed)return`${c(t,"file")} ESLint linted with the caller\u2019s arguments`;const a=e.paths.slice(0,3).join(", "),u=(e.more??0)+Math.max(0,e.paths.length-3);return u?`${a} +${u} more`:a}p(lintCoverageLabel,"lintCoverageLabel"),h(lintCoverageLabel,"lintCoverageLabel"),d(lintCoverageLabel,"lintCoverageLabel");
1
+ "use strict";var k=Object.defineProperty;var g=(e,n)=>k(e,"name",{value:n,configurable:!0});var v=Object.defineProperty,d=g((e,n)=>v(e,"name",{value:n,configurable:!0}),"i");import{TRUNCATION_MARKER_KEY as C}from"./bounded-clone.js";export const LINT_COVER_KIND="lint-cover",MAX_LINT_UNCOMMITTED=500;const A=["tree","paths","changed","incremental"],h=d(e=>Array.isArray(e)?e.filter(n=>typeof n=="string"&&n.length>0):[],"strings"),i=d(e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.floor(e):void 0,"count"),l=d(e=>typeof e=="string"&&e?e:void 0,"text");export function readLintCoverage(e){if(!e||typeof e!="object"||e[C])return;const n=e.coverage;if(!n||typeof n!="object")return;const t=n,r=t.kind,s=t.root;if(!A.includes(r)||typeof s!="string"||!s)return;const f=h(t.dirs),o=h(t.files),p=h(t.gone),m=i(t.notLinted),$=i(t.untracked),a=t.base&&typeof t.base=="object"?t.base:void 0,y=a&&l(a.sha)&&l(a.run)?{from:a.from==="main"?"main":"own",sha:a.sha,run:a.run}:void 0,b=Array.isArray(t.inputs)?t.inputs.flatMap(u=>Array.isArray(u)&&typeof u[0]=="string"&&typeof u[1]=="string"?[[u[0],u[1]]]:[]):void 0;return{kind:r,root:s,dirs:f,files:o,gone:p,fileCount:i(t.fileCount)??o.length,goneCount:i(t.goneCount)??p.length,linted:i(t.linted)??0,...i(t.dirCount)!==void 0?{dirCount:i(t.dirCount)}:{},...m?{notLinted:m}:{},...$?{untracked:$}:{},...l(t.since)?{since:t.since}:{},...l(t.head)?{head:t.head}:{},...typeof t.dirty=="boolean"?{dirty:t.dirty}:{},...Array.isArray(t.uncommitted)?{uncommitted:h(t.uncommitted)}:{},...t.uncommittedMore===!0?{uncommittedMore:!0}:{},...b?{inputs:b}:{},...l(t.folder)?{folder:t.folder}:{},...t.projects===!0?{projects:!0}:{},...y?{base:y}:{},...t.fromZero===!0?{fromZero:!0}:{},...t.narrowed===!0?{narrowed:!0}:{}}}g(readLintCoverage,"readLintCoverage"),d(readLintCoverage,"readLintCoverage");const c=d((e,n)=>`${e} ${n}${e===1?"":"s"}`,"some");export function lintCoverageLabel(e,n={}){const t=e.files??0,r=e.gone??0;if(e.kind==="changed"){const o=`since ${e.since??"HEAD"}`;if(!t)return`${c(r,"deleted file")} ${o}`;const p=n.untracked&&e.untracked?` (${e.untracked} untracked)`:"";return`${c(t,"changed file")} ${o}${p}${r?`, ${r} deleted`:""}`}if(e.kind==="incremental"){const o=e.since?` since ${e.since.slice(0,7)}`:"";return!t&&!r?`nothing changed${o}`:t?`${c(t,"file")} changed${o}${r?`, ${r} deleted`:""}`:`${c(r,"file")} deleted${o}`}if(e.kind==="tree"&&e.projects)return`the workspace\u2019s ${c(e.projects,"project")}`;if(e.kind==="tree"&&e.paths[0]===".")return"whole checkout";if(e.narrowed)return`${c(t,"file")} ESLint linted with the caller\u2019s arguments`;const s=e.paths.slice(0,3).join(", "),f=(e.more??0)+Math.max(0,e.paths.length-3);return f?`${s} +${f} more`:s}g(lintCoverageLabel,"lintCoverageLabel"),d(lintCoverageLabel,"lintCoverageLabel");
@@ -1,2 +1,2 @@
1
- "use strict";var $=Object.defineProperty;var u=(e,r)=>$(e,"name",{value:r,configurable:!0});var w=Object.defineProperty,c=u((e,r)=>w(e,"name",{value:r,configurable:!0}),"u"),x=Object.defineProperty,l=c((e,r)=>x(e,"name",{value:r,configurable:!0}),"l");export const LINT_IGNORES_FILE=".lensmcp/lint/ignores.json",LINT_IGNORE_LIMITS={rule:200,project:200,reason:500,evidence:1e3,by:80,ignores:500},LINT_IGNORED_RULES_SAID=50,LINT_IGNORED_NOTE="The person ignored these lints in the repository (each a rule in a project, with why): they are left out of the counts, the verdict and the status \u2014 do not fix them, and do not edit the ESLint config or this file for them. ESLint itself (`nx lint`) still reports them. To ask for another, `lint_ignore_propose`; only the person accepts.";const j=l(e=>e&&typeof e=="object"&&!Array.isArray(e)?e:void 0,"obj"),h=l(e=>typeof e=="string"&&e.trim()?e.replace(/\s+/g," ").trim():void 0,"text");export function lintIgnoreKey(e,r){return`${r}\0${e}`}u(lintIgnoreKey,"lintIgnoreKey"),c(lintIgnoreKey,"lintIgnoreKey"),l(lintIgnoreKey,"lintIgnoreKey");export function checkLintIgnore(e){const r=h(e.rule),o=h(e.project),t=h(e.reason),n=LINT_IGNORE_LIMITS;return r?r==="fatal"?{problem:"a file ESLint could not parse is never ignored \u2014 fix it"}:r.length>n.rule?{problem:`the rule is at most ${n.rule} characters`}:o?o.length>n.project?{problem:`the project is at most ${n.project} characters`}:t?t.length>n.reason?{problem:`the reason is at most ${n.reason} characters`}:{rule:r,project:o,reason:t}:{problem:"say why it is not to be fixed \u2014 the reason is what a teammate and an agent read"}:{problem:"name the project that owns the files"}:{problem:"name the rule (ESLint\u2019s rule id, as the finding names it)"}}u(checkLintIgnore,"checkLintIgnore"),c(checkLintIgnore,"checkLintIgnore"),l(checkLintIgnore,"checkLintIgnore");export function parseLintIgnores(e){if(e===void 0||!e.trim())return{ignores:[],problems:[]};let r;try{r=JSON.parse(e)}catch(s){return{ignores:[],problems:[`${LINT_IGNORES_FILE} is not JSON (${s instanceof Error?s.message:String(s)}) \u2014 no lint is ignored until it is`]}}const o=j(r),t=o?o.ignores:void 0;if(!o||!Array.isArray(t))return{ignores:[],problems:[`${LINT_IGNORES_FILE} holds no "ignores" list \u2014 no lint is ignored until it does`]};const n=[],a=[],i=new Set;return t.forEach((s,p)=>{const f=j(s);if(!f){a.push(`ignores[${p}] is not an object`);return}const g=checkLintIgnore(f);if("problem"in g){a.push(`ignores[${p}]: ${g.problem}`);return}const d=lintIgnoreKey(g.rule,g.project);if(i.has(d)){a.push(`ignores[${p}]: ${g.rule} in ${g.project} is ignored above already \u2014 the first stands`);return}if(n.length>=LINT_IGNORE_LIMITS.ignores){a.push(`ignores[${p}]: past ${LINT_IGNORE_LIMITS.ignores} ignores \u2014 the rest are not read`);return}i.add(d);const b=h(f.by)?.slice(0,LINT_IGNORE_LIMITS.by),m=h(f.at),y=h(f.proposal);n.push({...g,...b?{by:b}:{},...m&&!Number.isNaN(Date.parse(m))?{at:m}:{},...y?{proposal:y.slice(0,40)}:{}})}),{ignores:n,problems:a}}u(parseLintIgnores,"parseLintIgnores"),c(parseLintIgnores,"parseLintIgnores"),l(parseLintIgnores,"parseLintIgnores");export function lintIgnoresText(e){const r=[...e].sort((t,n)=>t.project<n.project?-1:t.project>n.project?1:t.rule<n.rule?-1:t.rule>n.rule?1:0),o=l(t=>({rule:t.rule,project:t.project,reason:t.reason,...t.by?{by:t.by}:{},...t.at?{at:t.at}:{},...t.proposal?{proposal:t.proposal}:{}}),"entry");return`${JSON.stringify({version:1,ignores:r.map(o)},null,2)}
2
- `}u(lintIgnoresText,"lintIgnoresText"),c(lintIgnoresText,"lintIgnoresText"),l(lintIgnoresText,"lintIgnoresText");export function withLintIgnore(e,r){const o=lintIgnoreKey(r.rule,r.project);return[...e.filter(t=>lintIgnoreKey(t.rule,t.project)!==o),r]}u(withLintIgnore,"withLintIgnore"),c(withLintIgnore,"withLintIgnore"),l(withLintIgnore,"withLintIgnore");export function withoutLintIgnore(e,r,o){const t=lintIgnoreKey(r,o);return e.filter(n=>lintIgnoreKey(n.rule,n.project)!==t)}u(withoutLintIgnore,"withoutLintIgnore"),c(withoutLintIgnore,"withoutLintIgnore"),l(withoutLintIgnore,"withoutLintIgnore");export function lintIgnoreMatcher(e){if(!e.length)return()=>{};const r=new Map(e.map(o=>[lintIgnoreKey(o.rule,o.project),o]));return({rule:o,project:t,scope:n})=>{if(!o||o==="fatal")return;const a=t??n;return a===void 0?void 0:r.get(lintIgnoreKey(o,a))}}u(lintIgnoreMatcher,"lintIgnoreMatcher"),c(lintIgnoreMatcher,"lintIgnoreMatcher"),l(lintIgnoreMatcher,"lintIgnoreMatcher");export function lintIgnoredSummary(e,r){if(!e.ignores.length&&!e.problems.length)return;let o=0,t=0;const n=e.ignores.map(i=>{const s=r.get(lintIgnoreKey(i.rule,i.project))??{errors:0,warnings:0};return o+=s.errors,t+=s.warnings,{rule:i.rule,project:i.project,reason:i.reason,...i.by?{by:i.by}:{},...i.at?{at:i.at}:{},errors:s.errors,warnings:s.warnings}}).map((i,s)=>({r:i,i:s})).sort((i,s)=>s.r.errors-i.r.errors||s.r.warnings-i.r.warnings||i.i-s.i).map(({r:i})=>i),a=n.length-LINT_IGNORED_RULES_SAID;return{file:LINT_IGNORES_FILE,errors:o,warnings:t,rules:n.slice(0,LINT_IGNORED_RULES_SAID),...a>0?{moreRules:a}:{},...e.problems.length?{problems:e.problems.slice(0,10)}:{},note:LINT_IGNORED_NOTE}}u(lintIgnoredSummary,"lintIgnoredSummary"),c(lintIgnoredSummary,"lintIgnoredSummary"),l(lintIgnoredSummary,"lintIgnoredSummary");export function lintIgnoreTally(e){const r=lintIgnoreMatcher(e.ignores),o=new Map;return{hides(t,n,a=1){const i=r(t);if(!i)return;const s=lintIgnoreKey(i.rule,i.project),p=o.get(s)??{errors:0,warnings:0};return n==="error"?p.errors+=a:p.warnings+=a,o.set(s,p),i},summary:l(()=>lintIgnoredSummary(e,o),"summary")}}u(lintIgnoreTally,"lintIgnoreTally"),c(lintIgnoreTally,"lintIgnoreTally"),l(lintIgnoreTally,"lintIgnoreTally");const I=10,L=l((e,r)=>`${e} ${r}${e===1?"":"s"}`,"counted");export function lintIgnoredLines(e){if(!e)return[];const r=[],o=e.rules.filter(n=>n.errors||n.warnings),t=[e.errors?L(e.errors,"error"):"",e.warnings?L(e.warnings,"warning"):""].filter(Boolean).join(", ");t&&r.push(` ignored (${e.file}): ${t} left out \u2014 not counted, not to be fixed`);for(const n of o.slice(0,I))r.push(` ${n.rule} in ${n.project} \u2014 ${n.reason}`);o.length>I&&r.push(` and ${o.length-I} more (--json lists them)`);for(const n of e.problems??[])r.push(` ${e.file}: ${n}`);return r}u(lintIgnoredLines,"lintIgnoredLines"),c(lintIgnoredLines,"lintIgnoredLines"),l(lintIgnoredLines,"lintIgnoredLines");export const LINT_IGNORE_PROPOSAL_LIMITS={open:30,kept:200,requestId:200};
1
+ "use strict";var $=Object.defineProperty;var u=(r,t)=>$(r,"name",{value:t,configurable:!0});var w=Object.defineProperty,a=u((r,t)=>w(r,"name",{value:t,configurable:!0}),"l");export const LINT_IGNORES_FILE=".lensmcp/lint/ignores.json",LINT_IGNORE_LIMITS={rule:200,project:200,reason:500,evidence:1e3,by:80,ignores:500},LINT_IGNORED_RULES_SAID=50,LINT_IGNORED_NOTE="The person ignored these lints in the repository (each a rule in a project, with why): they are left out of the counts, the verdict and the status \u2014 do not fix them, and do not edit the ESLint config or this file for them. ESLint itself (`nx lint`) still reports them. To ask for another, `lint_ignore_propose`; only the person accepts.";const y=a(r=>r&&typeof r=="object"&&!Array.isArray(r)?r:void 0,"obj"),g=a(r=>typeof r=="string"&&r.trim()?r.replace(/\s+/g," ").trim():void 0,"text");export function lintIgnoreKey(r,t){return`${t}\0${r}`}u(lintIgnoreKey,"lintIgnoreKey"),a(lintIgnoreKey,"lintIgnoreKey");export function checkLintIgnore(r){const t=g(r.rule),o=g(r.project),e=g(r.reason),n=LINT_IGNORE_LIMITS;return t?t==="fatal"?{problem:"a file ESLint could not parse is never ignored \u2014 fix it"}:t.length>n.rule?{problem:`the rule is at most ${n.rule} characters`}:o?o.length>n.project?{problem:`the project is at most ${n.project} characters`}:e?e.length>n.reason?{problem:`the reason is at most ${n.reason} characters`}:{rule:t,project:o,reason:e}:{problem:"say why it is not to be fixed \u2014 the reason is what a teammate and an agent read"}:{problem:"name the project that owns the files"}:{problem:"name the rule (ESLint\u2019s rule id, as the finding names it)"}}u(checkLintIgnore,"checkLintIgnore"),a(checkLintIgnore,"checkLintIgnore");export function parseLintIgnores(r){if(r===void 0||!r.trim())return{ignores:[],problems:[]};let t;try{t=JSON.parse(r)}catch(i){return{ignores:[],problems:[`${LINT_IGNORES_FILE} is not JSON (${i instanceof Error?i.message:String(i)}) \u2014 no lint is ignored until it is`]}}const o=y(t),e=o?o.ignores:void 0;if(!o||!Array.isArray(e))return{ignores:[],problems:[`${LINT_IGNORES_FILE} holds no "ignores" list \u2014 no lint is ignored until it does`]};const n=[],l=[],s=new Set;return e.forEach((i,p)=>{const h=y(i);if(!h){l.push(`ignores[${p}] is not an object`);return}const c=checkLintIgnore(h);if("problem"in c){l.push(`ignores[${p}]: ${c.problem}`);return}const d=lintIgnoreKey(c.rule,c.project);if(s.has(d)){l.push(`ignores[${p}]: ${c.rule} in ${c.project} is ignored above already \u2014 the first stands`);return}if(n.length>=LINT_IGNORE_LIMITS.ignores){l.push(`ignores[${p}]: past ${LINT_IGNORE_LIMITS.ignores} ignores \u2014 the rest are not read`);return}s.add(d);const b=g(h.by)?.slice(0,LINT_IGNORE_LIMITS.by),f=g(h.at),I=g(h.proposal);n.push({...c,...b?{by:b}:{},...f&&!Number.isNaN(Date.parse(f))?{at:f}:{},...I?{proposal:I.slice(0,40)}:{}})}),{ignores:n,problems:l}}u(parseLintIgnores,"parseLintIgnores"),a(parseLintIgnores,"parseLintIgnores");export function lintIgnoresText(r){const t=[...r].sort((e,n)=>e.project<n.project?-1:e.project>n.project?1:e.rule<n.rule?-1:e.rule>n.rule?1:0),o=a(e=>({rule:e.rule,project:e.project,reason:e.reason,...e.by?{by:e.by}:{},...e.at?{at:e.at}:{},...e.proposal?{proposal:e.proposal}:{}}),"entry");return`${JSON.stringify({version:1,ignores:t.map(o)},null,2)}
2
+ `}u(lintIgnoresText,"lintIgnoresText"),a(lintIgnoresText,"lintIgnoresText");export function withLintIgnore(r,t){const o=lintIgnoreKey(t.rule,t.project);return[...r.filter(e=>lintIgnoreKey(e.rule,e.project)!==o),t]}u(withLintIgnore,"withLintIgnore"),a(withLintIgnore,"withLintIgnore");export function withoutLintIgnore(r,t,o){const e=lintIgnoreKey(t,o);return r.filter(n=>lintIgnoreKey(n.rule,n.project)!==e)}u(withoutLintIgnore,"withoutLintIgnore"),a(withoutLintIgnore,"withoutLintIgnore");export function lintIgnoreMatcher(r){if(!r.length)return()=>{};const t=new Map(r.map(o=>[lintIgnoreKey(o.rule,o.project),o]));return({rule:o,project:e,scope:n})=>{if(!o||o==="fatal")return;const l=e??n;return l===void 0?void 0:t.get(lintIgnoreKey(o,l))}}u(lintIgnoreMatcher,"lintIgnoreMatcher"),a(lintIgnoreMatcher,"lintIgnoreMatcher");export function lintIgnoredSummary(r,t){if(!r.ignores.length&&!r.problems.length)return;let o=0,e=0;const n=r.ignores.map(s=>{const i=t.get(lintIgnoreKey(s.rule,s.project))??{errors:0,warnings:0};return o+=i.errors,e+=i.warnings,{rule:s.rule,project:s.project,reason:s.reason,...s.by?{by:s.by}:{},...s.at?{at:s.at}:{},errors:i.errors,warnings:i.warnings}}).map((s,i)=>({r:s,i})).sort((s,i)=>i.r.errors-s.r.errors||i.r.warnings-s.r.warnings||s.i-i.i).map(({r:s})=>s),l=n.length-LINT_IGNORED_RULES_SAID;return{file:LINT_IGNORES_FILE,errors:o,warnings:e,rules:n.slice(0,LINT_IGNORED_RULES_SAID),...l>0?{moreRules:l}:{},...r.problems.length?{problems:r.problems.slice(0,10)}:{},note:LINT_IGNORED_NOTE}}u(lintIgnoredSummary,"lintIgnoredSummary"),a(lintIgnoredSummary,"lintIgnoredSummary");export function lintIgnoreTally(r){const t=lintIgnoreMatcher(r.ignores),o=new Map;return{hides(e,n,l=1){const s=t(e);if(!s)return;const i=lintIgnoreKey(s.rule,s.project),p=o.get(i)??{errors:0,warnings:0};return n==="error"?p.errors+=l:p.warnings+=l,o.set(i,p),s},summary:a(()=>lintIgnoredSummary(r,o),"summary")}}u(lintIgnoreTally,"lintIgnoreTally"),a(lintIgnoreTally,"lintIgnoreTally");const m=10,j=a((r,t)=>`${r} ${t}${r===1?"":"s"}`,"counted");export function lintIgnoredLines(r){if(!r)return[];const t=[],o=r.rules.filter(n=>n.errors||n.warnings),e=[r.errors?j(r.errors,"error"):"",r.warnings?j(r.warnings,"warning"):""].filter(Boolean).join(", ");e&&t.push(` ignored (${r.file}): ${e} left out \u2014 not counted, not to be fixed`);for(const n of o.slice(0,m))t.push(` ${n.rule} in ${n.project} \u2014 ${n.reason}`);o.length>m&&t.push(` and ${o.length-m} more (--json lists them)`);for(const n of r.problems??[])t.push(` ${r.file}: ${n}`);return t}u(lintIgnoredLines,"lintIgnoredLines"),a(lintIgnoredLines,"lintIgnoredLines");export const LINT_IGNORE_PROPOSAL_LIMITS={open:30,kept:200,requestId:200};
package/lib/log-query.js CHANGED
@@ -1 +1 @@
1
- "use strict";var L=Object.defineProperty;var a=(e,t)=>L(e,"name",{value:t,configurable:!0});var d=Object.defineProperty,c=a((e,t)=>d(e,"name",{value:t,configurable:!0}),"a"),h=Object.defineProperty,u=c((e,t)=>h(e,"name",{value:t,configurable:!0}),"c");const p={level:"level",severity:"level",service:"service",svc:"service",src:"service",source:"service",flow:"flow",trace:"trace",request:"trace",category:"category",cat:"category",ms:"ms"},C={warn:"warning",err:"error"},k=/(-?)(?:([A-Za-z]+):)?(?:"([^"]*)"|(\S+))/g;export function parseLogQuery(e){const t=[],r=[];for(const s of e.matchAll(k)){const[o,n,g,y,w]=s,i=(y??w??"").trim(),l=g?p[g.toLowerCase()]:void 0;if(l&&i){const m=l==="level"?C[i.toLowerCase()]??i.toLowerCase():i;t.push({key:l,value:m,negate:n==="-"})}else o.trim()&&r.push(o.trim())}return{tokens:t,text:r.join(" ")}}a(parseLogQuery,"parseLogQuery"),c(parseLogQuery,"parseLogQuery"),u(parseLogQuery,"parseLogQuery");export function formatLogQuery(e){const t=u(r=>/\s/.test(r)?`"${r}"`:r,"quote");return[...e.tokens.map(r=>`${r.negate?"-":""}${r.key}:${t(r.value)}`),e.text].filter(Boolean).join(" ")}a(formatLogQuery,"formatLogQuery"),c(formatLogQuery,"formatLogQuery"),u(formatLogQuery,"formatLogQuery");function v(e,t){if(e===void 0)return!1;const r=/^(>=|<=|>|<|=)?\s*(\d+(?:\.\d+)?)$/.exec(t);if(!r)return!1;const s=Number(r[2]);switch(r[1]){case">":return e>s;case"<":return e<s;case"<=":return e<=s;case"=":return e===s;default:return e>=s}}a(v,"v"),c(v,"h"),u(v,"msMatches");function f(e,t){const r=t.value.toLowerCase();switch(t.key){case"level":return e.severity.toLowerCase()===r;case"service":return e.source.toLowerCase()===r;case"flow":return!!e.flowId&&e.flowId.toLowerCase().startsWith(r);case"trace":return!!e.requestId&&e.requestId.toLowerCase().startsWith(r);case"category":return e.category.toLowerCase()===r;case"ms":return v(e.durationMs,t.value)}}a(f,"l"),c(f,"i"),u(f,"tokenMatches");export function matchesLogQuery(e,t,r){const s=new Map;for(const o of t.tokens){if(o.negate){if(f(e,o))return!1;continue}const n=s.get(o.key);n?n.push(o):s.set(o.key,[o])}for(const o of s.values())if(!o.some(n=>f(e,n)))return!1;if(t.text){const o=`${e.title} ${e.message??""} ${e.source} ${e.flowId??""}`;return r?r(o):o.toLowerCase().includes(t.text.toLowerCase())}return!0}a(matchesLogQuery,"matchesLogQuery"),c(matchesLogQuery,"matchesLogQuery"),u(matchesLogQuery,"matchesLogQuery");
1
+ "use strict";var m=Object.defineProperty;var a=(e,r)=>m(e,"name",{value:r,configurable:!0});var L=Object.defineProperty,c=a((e,r)=>L(e,"name",{value:r,configurable:!0}),"c");const d={level:"level",severity:"level",service:"service",svc:"service",src:"service",source:"service",flow:"flow",trace:"trace",request:"trace",category:"category",cat:"category",ms:"ms"},h={warn:"warning",err:"error"},p=/(-?)(?:([A-Za-z]+):)?(?:"([^"]*)"|(\S+))/g;export function parseLogQuery(e){const r=[],t=[];for(const s of e.matchAll(p)){const[o,n,f,w,g]=s,u=(w??g??"").trim(),i=f?d[f.toLowerCase()]:void 0;if(i&&u){const y=i==="level"?h[u.toLowerCase()]??u.toLowerCase():u;r.push({key:i,value:y,negate:n==="-"})}else o.trim()&&t.push(o.trim())}return{tokens:r,text:t.join(" ")}}a(parseLogQuery,"parseLogQuery"),c(parseLogQuery,"parseLogQuery");export function formatLogQuery(e){const r=c(t=>/\s/.test(t)?`"${t}"`:t,"quote");return[...e.tokens.map(t=>`${t.negate?"-":""}${t.key}:${r(t.value)}`),e.text].filter(Boolean).join(" ")}a(formatLogQuery,"formatLogQuery"),c(formatLogQuery,"formatLogQuery");function v(e,r){if(e===void 0)return!1;const t=/^(>=|<=|>|<|=)?\s*(\d+(?:\.\d+)?)$/.exec(r);if(!t)return!1;const s=Number(t[2]);switch(t[1]){case">":return e>s;case"<":return e<s;case"<=":return e<=s;case"=":return e===s;default:return e>=s}}a(v,"h"),c(v,"msMatches");function l(e,r){const t=r.value.toLowerCase();switch(r.key){case"level":return e.severity.toLowerCase()===t;case"service":return e.source.toLowerCase()===t;case"flow":return!!e.flowId&&e.flowId.toLowerCase().startsWith(t);case"trace":return!!e.requestId&&e.requestId.toLowerCase().startsWith(t);case"category":return e.category.toLowerCase()===t;case"ms":return v(e.durationMs,r.value)}}a(l,"i"),c(l,"tokenMatches");export function matchesLogQuery(e,r,t){const s=new Map;for(const o of r.tokens){if(o.negate){if(l(e,o))return!1;continue}const n=s.get(o.key);n?n.push(o):s.set(o.key,[o])}for(const o of s.values())if(!o.some(n=>l(e,n)))return!1;if(r.text){const o=`${e.title} ${e.message??""} ${e.source} ${e.flowId??""}`;return t?t(o):o.toLowerCase().includes(r.text.toLowerCase())}return!0}a(matchesLogQuery,"matchesLogQuery"),c(matchesLogQuery,"matchesLogQuery");
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var i=(e,t)=>l(e,"name",{value:t,configurable:!0});var f=Object.defineProperty,a=i((e,t)=>f(e,"name",{value:t,configurable:!0}),"i"),u=Object.defineProperty,c=a((e,t)=>u(e,"name",{value:t,configurable:!0}),"s");import{LENS_EVENT_SOURCE as S}from"./error-dismissal.js";export const METRICS_RESET="metrics-reset",METRICS_RESTORED="metrics-restored",METRICS_SCOPES=["sql","external"],MAX_METRICS_RESET_IDS=500,MAX_METRICS_RESET_ID_LENGTH=512,METRICS_RESET_IDS_PER_EVENT=64;const d=16*1024,p=c(e=>e==="sql"||e==="external","isScope"),E=c(e=>typeof e=="string"&&e.length>0&&e.length<=MAX_METRICS_RESET_ID_LENGTH,"isId");export function readMetricsReset(e){if(e.source!==S||!e.raw||typeof e.raw!="object")return;const t=e.raw,r=t.kind;if(r!==METRICS_RESET&&r!==METRICS_RESTORED)return;const n=t.scope;if(!p(n))return;let s;if(t.ids!==void 0&&(!Array.isArray(t.ids)||(s=[...new Set(t.ids.filter(E))].slice(0,METRICS_RESET_IDS_PER_EVENT),!s.length)))return;if(r===METRICS_RESTORED)return{kind:r,scope:n,...s?{ids:s}:{}};const o=t.at;if(!(typeof o!="number"||!Number.isFinite(o)))return{kind:r,scope:n,at:Math.min(o,e.timestamp),...s?{ids:s}:{}}}i(readMetricsReset,"readMetricsReset"),a(readMetricsReset,"readMetricsReset"),c(readMetricsReset,"readMetricsReset");export function metricsIdBatches(e){const t=[];let r=[],n=0;for(const s of new Set(e.filter(E)))r.length&&(r.length>=METRICS_RESET_IDS_PER_EVENT||n+s.length+3>d)&&(t.push(r),r=[],n=0),r.push(s),n+=s.length+3;return r.length&&t.push(r),t}i(metricsIdBatches,"metricsIdBatches"),a(metricsIdBatches,"metricsIdBatches"),c(metricsIdBatches,"metricsIdBatches");
1
+ "use strict";var a=Object.defineProperty;var i=(t,e)=>a(t,"name",{value:e,configurable:!0});var S=Object.defineProperty,o=i((t,e)=>S(t,"name",{value:e,configurable:!0}),"s");import{LENS_EVENT_SOURCE as f}from"./error-dismissal.js";export const METRICS_RESET="metrics-reset",METRICS_RESTORED="metrics-restored",METRICS_SCOPES=["sql","external"],MAX_METRICS_RESET_IDS=500,MAX_METRICS_RESET_ID_LENGTH=512,METRICS_RESET_IDS_PER_EVENT=64;const l=16*1024,u=o(t=>t==="sql"||t==="external","isScope"),E=o(t=>typeof t=="string"&&t.length>0&&t.length<=MAX_METRICS_RESET_ID_LENGTH,"isId");export function readMetricsReset(t){if(t.source!==f||!t.raw||typeof t.raw!="object")return;const e=t.raw,r=e.kind;if(r!==METRICS_RESET&&r!==METRICS_RESTORED)return;const n=e.scope;if(!u(n))return;let s;if(e.ids!==void 0&&(!Array.isArray(e.ids)||(s=[...new Set(e.ids.filter(E))].slice(0,METRICS_RESET_IDS_PER_EVENT),!s.length)))return;if(r===METRICS_RESTORED)return{kind:r,scope:n,...s?{ids:s}:{}};const c=e.at;if(!(typeof c!="number"||!Number.isFinite(c)))return{kind:r,scope:n,at:Math.min(c,t.timestamp),...s?{ids:s}:{}}}i(readMetricsReset,"readMetricsReset"),o(readMetricsReset,"readMetricsReset");export function metricsIdBatches(t){const e=[];let r=[],n=0;for(const s of new Set(t.filter(E)))r.length&&(r.length>=METRICS_RESET_IDS_PER_EVENT||n+s.length+3>l)&&(e.push(r),r=[],n=0),r.push(s),n+=s.length+3;return r.length&&e.push(r),e}i(metricsIdBatches,"metricsIdBatches"),o(metricsIdBatches,"metricsIdBatches");