UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 2.11 kB
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(t,i){if(toolBaseName(t)!==`todo`||typeof i!=`object`||!i||Array.isArray(i))return;let a=i.todos;if(!Array.isArray(a))return;let o=[];for(let e of a){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,i=t.content,a=t.status;if(typeof i!=`string`||typeof a!=`string`||!TODO_STATUSES.has(a))return;o.push({content:firstLine(stripTerminalControls(i)),status:a})}return o}function allTodoItemsSettled(e){return e.every(e=>e.status===`completed`||e.status===`cancelled`)}function renderTodoPanelRows(e){let{items:n,width:r,theme:i}=e,a=i.colors,o=i.glyph,s=n.filter(e=>e.status===`completed`||e.status===`cancelled`).length,c=[e.working?` ${a.gray(o.square)} ${a.dim(`Todo`)}`:` ${a.gray(o.square)} ${a.dim(`${s}/${n.length} tasks`)}`],l=!1;for(let t of n){let n=t.status===`completed`||t.status===`cancelled`,r;l?r=` `:n?r=a.dim(o.rule):(r=a.dim(o.corner),l=!0),c.push(` ${r} ${todoItemBody(t,e,i)}`)}return c.map(e=>clipVisible(e,r))}function renderFinishedTodoRows(e,n,r){let i=r.colors,a=r.glyph,o=[` ${i.green(a.success)} ${i.dim(`Todo`)}`];for(let t of e)o.push(` ${i.dim(a.rule)} ${settledMark(t,r)} ${i.dim(t.content)}`);return o.push(` ${i.dim(a.corner)} ${i.green(`Done`)}`),o.map(e=>clipVisible(e,n))}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};