eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
6 lines • 1.54 kB
JavaScript
import{createCliTheme,sanitizeForTerminal}from"#cli/ui/output.js";import{clipVisible,wrapVisibleLine}from"#cli/ui/terminal-text.js";function normalizeRegistryText(e){return sanitizeForTerminal(e).replaceAll(`\\"`,`"`).replaceAll(`\\'`,`'`).replaceAll(/\s+/gu,` `).trim()}function registryDescriptionSummary(e){let t=normalizeRegistryText(e);return t.match(/^.*?[.!?](?=\s|$)/u)?.[0]??t}function renderSearchItem(e,t,n,r){let i=Math.max(1,n-4),a=wrapVisibleLine(normalizeRegistryText(t),i),o=normalizeRegistryText(e.name),s=o.split(`/`).at(-1)??o,c=[` ${r.label(s)}`,...a.map(e=>` ${e}`)];if(!e.description)return c.join(`
`);let l=registryDescriptionSummary(e.description);if(l.length===0)return c.join(`
`);let u=wrapVisibleLine(l,i),d=u.length<=2?u:[u[0],`${clipVisible(u[1],Math.max(1,i-1)).trimEnd()}…`];return c.push(...d.map(e=>r.muted(` ${e}`))),c.join(`
`)}function printRegistrySearchResults(e,t,n){if(n.json){e.log(JSON.stringify(t,null,2));return}if(t.items.length===0){let t=n.query&&normalizeRegistryText(n.query);e.log(t?`No registry items match "${t}".`:`No registry items found.`);return}let r=createCliTheme(),i=Math.max(20,process.stdout.columns??80),a=n.sections.flatMap(e=>{if(e.items.length===0)return[];let t=`${e.total} result${e.total===1?``:`s`}`,n=e.items.length<e.total?`showing ${e.items.length} of ${t}`:t;return[[`${r.label(e.label)} ${r.muted(`(${n})`)}`,...e.items.map(t=>renderSearchItem(t,e.address(t),i,r))].join(`
`)]});e.log(a.join(`
`))}export{normalizeRegistryText,printRegistrySearchResults};