eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2.11 kB
JavaScript
import"./rail.js";import{toolBaseName}from"./tool-presentation.js";import{clipVisible,stripTerminalControls}from"#cli/ui/terminal-text.js";const TODO_STATUSES=new Set([`pending`,`in_progress`,`completed`,`cancelled`]);function readTodoToolItems(e,t){if(toolBaseName(e)!==`todo`||typeof t!=`object`||!t||Array.isArray(t))return;let n=t.todos;if(!Array.isArray(n))return;let r=[];for(let e of n){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=t.content,i=t.status;if(typeof n!=`string`||typeof i!=`string`||!TODO_STATUSES.has(i))return;r.push({content:firstLine(stripTerminalControls(n)),status:i})}return r}function allTodoItemsSettled(e){return e.every(e=>e.status===`completed`||e.status===`cancelled`)}function renderTodoPanelRows(e){let{items:t,width:n,theme:r}=e,i=r.colors,a=r.glyph,o=t.filter(e=>e.status===`completed`||e.status===`cancelled`).length,s=[e.working?` ${i.gray(a.square)} ${i.dim(`Todo`)}`:` ${i.gray(a.square)} ${i.dim(`${o}/${t.length} tasks`)}`],c=!1;for(let n of t){let t=n.status===`completed`||n.status===`cancelled`,o;c?o=` `:t?o=i.dim(a.rule):(o=i.dim(a.corner),c=!0),s.push(` ${o} ${todoItemBody(n,e,r)}`)}return s.map(e=>clipVisible(e,n))}function renderFinishedTodoRows(e,t,n){let r=n.colors,i=n.glyph,a=[` ${r.green(i.success)} ${r.dim(`Todo`)}`];for(let t of e)a.push(` ${r.dim(i.rule)} ${settledMark(t,n)} ${r.dim(t.content)}`);return a.push(` ${r.dim(i.corner)} ${r.green(`Done`)}`),a.map(e=>clipVisible(e,t))}function settledMark(e,t){return e.status===`cancelled`?t.colors.red(t.glyph.error):t.colors.green(t.glyph.success)}function todoItemBody(e,t,n){let r=n.colors,i=n.glyph;switch(e.status){case`completed`:return`${r.green(i.success)} ${r.dim(e.content)}`;case`cancelled`:return`${r.red(i.error)} ${r.dim(e.content)}`;case`in_progress`:{let n=t.working?t.pulse.trim().length>0?i.dotActive:` `:i.dotActive;return`${r.yellow(n)} ${e.content}`}case`pending`:return`${r.dim(i.reasoning)} ${r.dim(e.content)}`}}function firstLine(e){return e.split(/\r?\n/u,1)[0]??``}export{allTodoItemsSettled,readTodoToolItems,renderFinishedTodoRows,renderTodoPanelRows};