eve 0.12.2 → 0.13.0
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.
- package/CHANGELOG.md +25 -0
- package/dist/src/cli/commands/agent-instructions.d.ts +15 -3
- package/dist/src/cli/commands/agent-instructions.js +3 -1
- package/dist/src/cli/commands/agent-prompt/build-and-verify.md +33 -0
- package/dist/src/cli/commands/agent-prompt/collect-intent.md +18 -0
- package/dist/src/cli/commands/agent-prompt/intro-handoff.md +4 -0
- package/dist/src/cli/commands/agent-prompt/intro-setup.md +5 -0
- package/dist/src/cli/commands/agent-prompt/scaffold.md +19 -0
- package/dist/src/cli/commands/agent-prompt/vercel-connect.md +3 -0
- package/dist/src/cli/commands/deploy.js +1 -1
- package/dist/src/cli/commands/init-repl.d.ts +79 -0
- package/dist/src/cli/commands/init-repl.js +1 -0
- package/dist/src/cli/commands/init.d.ts +6 -0
- package/dist/src/cli/commands/init.js +1 -1
- package/dist/src/cli/commands/link.d.ts +2 -2
- package/dist/src/cli/commands/link.js +1 -1
- package/dist/src/cli/dev/tui/line-editor.d.ts +2 -0
- package/dist/src/cli/dev/tui/line-editor.js +2 -2
- package/dist/src/cli/dev/tui/prompt-command-handler.js +1 -1
- package/dist/src/cli/dev/tui/setup-commands.d.ts +26 -7
- package/dist/src/cli/dev/tui/setup-commands.js +2 -2
- package/dist/src/cli/dev/tui/setup-flow.d.ts +10 -3
- package/dist/src/cli/dev/tui/setup-panel.d.ts +16 -8
- package/dist/src/cli/dev/tui/setup-panel.js +3 -3
- package/dist/src/cli/dev/tui/setup-selection-input.d.ts +2 -1
- package/dist/src/cli/dev/tui/setup-selection-input.js +2 -2
- package/dist/src/cli/dev/tui/terminal-renderer.js +10 -10
- package/dist/src/cli/dev/tui/terminal-text.d.ts +11 -0
- package/dist/src/cli/dev/tui/terminal-text.js +1 -1
- package/dist/src/cli/dev/tui/tui-prompter.js +1 -1
- package/dist/src/cli/run.d.ts +1 -0
- package/dist/src/cli/run.js +2 -2
- package/dist/src/cli/ui/live-row.js +1 -1
- package/dist/src/cli/ui/progress-pulse.d.ts +10 -0
- package/dist/src/cli/ui/progress-pulse.js +1 -0
- package/dist/src/discover/discover-agent.js +1 -1
- package/dist/src/evals/target.js +1 -1
- package/dist/src/execution/node-step.js +1 -1
- package/dist/src/execution/sandbox/bindings/just-bash-runtime.js +1 -1
- package/dist/src/execution/sandbox/bindings/vercel-sdk-types.d.ts +0 -1
- package/dist/src/execution/sandbox/bindings/vercel.js +1 -1
- package/dist/src/execution/sandbox/multiplexed-command.d.ts +22 -0
- package/dist/src/execution/sandbox/multiplexed-command.js +1 -0
- package/dist/src/execution/tool-auth.d.ts +17 -30
- package/dist/src/execution/tool-auth.js +1 -1
- package/dist/src/execution/workflow-steps.js +1 -1
- package/dist/src/harness/tool-loop.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/authored-module-loader.js +2 -2
- package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
- package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.js +1 -1
- package/dist/src/public/channels/github/api.d.ts +5 -0
- package/dist/src/public/channels/github/api.js +1 -1
- package/dist/src/public/channels/github/dispatch.js +1 -1
- package/dist/src/public/channels/github/pr-context.d.ts +10 -0
- package/dist/src/public/channels/github/pr-context.js +2 -2
- package/dist/src/public/channels/slack/connections.d.ts +16 -18
- package/dist/src/public/channels/slack/defaults.d.ts +1 -1
- package/dist/src/public/channels/slack/defaults.js +1 -1
- package/dist/src/public/channels/slack/slackChannel.d.ts +6 -7
- package/dist/src/public/definitions/tool.d.ts +40 -41
- package/dist/src/public/definitions/tool.js +1 -1
- package/dist/src/public/tools/index.d.ts +1 -1
- package/dist/src/runtime/connections/scoped-authorization.js +1 -1
- package/dist/src/runtime/connections/validate-authorization.js +1 -1
- package/dist/src/runtime/framework-tools/connection-search-dynamic.js +1 -1
- package/dist/src/runtime/resolve-tool.js +1 -1
- package/dist/src/runtime/types.d.ts +0 -10
- package/dist/src/setup/ai-gateway-api-key.d.ts +15 -0
- package/dist/src/setup/ai-gateway-api-key.js +1 -0
- package/dist/src/setup/boxes/apply-ai-gateway-credential.js +1 -1
- package/dist/src/setup/boxes/detect-ai-gateway.js +2 -2
- package/dist/src/setup/boxes/link-project.d.ts +8 -14
- package/dist/src/setup/boxes/link-project.js +1 -1
- package/dist/src/setup/boxes/resolve-provisioning.d.ts +2 -1
- package/dist/src/setup/boxes/resolve-provisioning.js +1 -1
- package/dist/src/setup/cli/select-component.d.ts +7 -1
- package/dist/src/setup/cli/select-component.js +1 -1
- package/dist/src/setup/cli/select-option-codec.d.ts +1 -0
- package/dist/src/setup/cli/select-option-codec.js +1 -1
- package/dist/src/setup/cli/select-state.d.ts +14 -1
- package/dist/src/setup/cli/select-state.js +1 -1
- package/dist/src/setup/flows/channels.js +1 -1
- package/dist/src/setup/flows/deploy.js +1 -1
- package/dist/src/setup/flows/install-vercel-cli.js +1 -1
- package/dist/src/setup/flows/link.d.ts +2 -1
- package/dist/src/setup/flows/link.js +1 -1
- package/dist/src/setup/flows/login.js +1 -1
- package/dist/src/setup/flows/model.d.ts +5 -4
- package/dist/src/setup/flows/model.js +1 -1
- package/dist/src/setup/flows/vercel.js +2 -2
- package/dist/src/setup/index.d.ts +1 -1
- package/dist/src/setup/package-manager.d.ts +2 -1
- package/dist/src/setup/package-manager.js +1 -1
- package/dist/src/setup/primitives/pm/index.d.ts +1 -1
- package/dist/src/setup/primitives/pm/pnpm.d.ts +11 -1
- package/dist/src/setup/primitives/pm/pnpm.js +5 -2
- package/dist/src/setup/primitives/pm/types.d.ts +10 -1
- package/dist/src/setup/project-resolution.d.ts +9 -6
- package/dist/src/setup/project-resolution.js +1 -1
- package/dist/src/setup/prompter.d.ts +13 -0
- package/dist/src/setup/prompter.js +1 -1
- package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
- package/dist/src/setup/scaffold/create/project.d.ts +8 -0
- package/dist/src/setup/scaffold/create/project.js +8 -7
- package/dist/src/setup/scaffold/update/channels.d.ts +8 -0
- package/dist/src/setup/scaffold/update/channels.js +2 -2
- package/dist/src/setup/scaffold/update/package-json.d.ts +3 -0
- package/dist/src/setup/scaffold/update/package-json.js +1 -1
- package/dist/src/setup/scaffold/workspace-glob.d.ts +5 -0
- package/dist/src/setup/scaffold/workspace-glob.js +1 -0
- package/dist/src/setup/scaffold/workspace-root.d.ts +29 -0
- package/dist/src/setup/scaffold/workspace-root.js +1 -0
- package/dist/src/setup/state.d.ts +7 -2
- package/dist/src/setup/vercel-api-failure.d.ts +9 -0
- package/dist/src/setup/vercel-api-failure.js +1 -0
- package/dist/src/setup/vercel-deployment.js +1 -1
- package/dist/src/setup/vercel-project-api.d.ts +25 -0
- package/dist/src/setup/vercel-project-api.js +1 -0
- package/dist/src/setup/vercel-project.d.ts +11 -57
- package/dist/src/setup/vercel-project.js +1 -1
- package/dist/src/setup/with-spinner.d.ts +3 -0
- package/dist/src/setup/with-spinner.js +1 -0
- package/dist/src/shared/package-name.d.ts +4 -0
- package/dist/src/shared/package-name.js +1 -0
- package/docs/channels/slack.mdx +1 -1
- package/docs/connections.mdx +9 -6
- package/docs/getting-started.mdx +8 -3
- package/docs/guides/auth-and-route-protection.md +57 -10
- package/docs/guides/dev-tui.md +3 -3
- package/docs/reference/cli.md +3 -3
- package/docs/reference/typescript-api.md +7 -7
- package/package.json +1 -1
- package/dist/src/cli/commands/init-agent-handoff.md +0 -12
- package/dist/src/cli/commands/init-agent-instructions.md +0 -16
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{clipVisible,renderInputText,visibleLength,wrapVisibleLine}from"./terminal-text.js";import{visibleLine}from"./line-editor.js";import{
|
|
2
|
-
`).map((e,r)=>` ${t===`stacked`||r>0?n.colors.bold(e):e}`);return r.push(``),r}function searchFilter(e,t,n){
|
|
3
|
-
`).map(e=>` ${
|
|
1
|
+
import{clipVisible,renderInputText,renderInputWithBlockCursor,visibleLength,wrapVisibleLine}from"./terminal-text.js";import{maskLine,visibleLine}from"./line-editor.js";import{renderCursorRow,renderOptionRow,renderOptionRowContinuation,resolveOptionRowState}from"#setup/cli/option-row.js";import{filterOptions,submitRowIndex}from"#setup/cli/select-state.js";function clip(t,n){return clipVisible(t,n)}function questionFooter(e,t){let n=t.colors;return[``,` ${n.dim(n.italic(e.join(` ${t.glyph.dot} `)))}`]}const BOLD_OR_DIM_CLOSE=`\x1B[22m`;function dimWithEmphasis(e,t){return t.colors.dim(e.replaceAll(BOLD_OR_DIM_CLOSE,`${BOLD_OR_DIM_CLOSE}[2m`))}function toneGlyph(e,t){let n=t.colors;switch(e){case`success`:return n.green(t.glyph.success);case`warning`:return n.yellow(t.glyph.warning);case`error`:return n.red(t.glyph.error);case`info`:return n.dim(t.glyph.dot)}}function renderIndicator(e,t){return e.color===`green`?t.colors.green(e.glyph):t.colors.yellow(e.glyph)}function renderFlowPanel(e,t,n){let r=t.colors,i=[r.dim(t.glyph.hrule.repeat(Math.max(1,n)))];e.title.length>0&&i.push(` ${r.bold(e.title)}`),i.push(``);let a=e.lines.slice(-6);for(let e of a){let n=e.tone===`info`?r.dim(e.text):e.text;i.push(` ${toneGlyph(e.tone,t)} ${n}`)}switch(a.length>0&&i.push(``),e.content.kind){case`question`:e.content.status!==void 0&&i.push(` ${renderIndicator(e.content.status.indicator,t)} ${r.dim(e.content.status.text)}`,``),i.push(...e.content.rows);break;case`status`:i.push(` ${renderIndicator(e.content.status.indicator,t)} ${r.dim(e.content.status.text)}`),e.content.preview!==void 0&&i.push(` ${r.dim(e.content.preview)}`);break;case`preview`:i.push(` ${renderIndicator(e.content.indicator,t)} ${r.dim(e.content.text)}`);break;case`idle`:i.push(` ${renderIndicator(e.content.indicator,t)} ${r.dim(`Working…`)}`);break}return i.map((e,t)=>t===0||e.length===0?clip(e,n):clip(` ${e}`,n))}function optionRow(e){let{option:t,theme:n}=e;return renderOptionRow({colors:n.colors,glyphs:{pointer:n.glyph.pointer,selectedPointer:n.glyph.selectedPointer,success:n.glyph.success,placeholder:n.glyph.option,dot:n.glyph.dot},label:t.label,hint:t.hint,focusHint:t.focusHint,accent:t.accent,isCursor:e.isCursor,state:resolveOptionRowState(t,e.isChecked),placeholder:e.placeholder,hintPadding:e.hintPadding})}function selectPresentation(e){switch(e.kind){case`single`:return{selection:`single`,filter:void 0,layout:`plain`,edit:void 0};case`search`:return{selection:`single`,filter:{placeholder:e.placeholder},layout:`plain`,edit:void 0};case`multi`:return{selection:`multiple`,filter:void 0,layout:`plain`,edit:void 0};case`searchable-multi`:return{selection:`multiple`,filter:{placeholder:e.placeholder},layout:`plain`,edit:void 0};case`stacked`:return{selection:`single`,filter:void 0,layout:`stacked`,edit:void 0};case`task-list`:return{selection:`single`,filter:void 0,layout:`task-list`,edit:void 0};case`editable`:return{selection:`single`,filter:void 0,layout:`task-list`,edit:e.edit}}}function selectMessageRows(e,t,n){if(e===``)return[];let r=e.split(`
|
|
2
|
+
`).map((e,r)=>` ${t===`stacked`||r>0?n.colors.bold(e):e}`);return r.push(``),r}function searchFilter(e,t,n,r){let i=r.colors.dim(r.glyph.caret),a=i;return e.length>0?a=e+i:t!==void 0&&(a=r.colors.dim(`> ${t}`)),n===void 0?a:`${a} ${r.colors.yellow(n)}`}function selectViewSize(e){return e.search?e.filter===``&&e.featuredLead>0?Math.min(e.featuredLead,8):8:e.optionCount}function noticeBody(e,t,n){return e.tone===`info`?n.colors.dim(e.text):e.tone===`success`&&t===`task-list`?n.colors.bold(e.text):e.text}function editableOption(e,t,n,r){if(!t||n?.optionValue!==e.value)return e;let i=n.editor.text||n.defaultValue,a=n.editor.text.length===0?i.length:n.editor.cursor,o=n.caretVisible?r.colors.cyan(r.glyph.caret):``,s=`${i.slice(0,a)}${o}${i.slice(a)}`;return{...e,hint:n.formatHint(s)}}function optionWithoutStackedHint(e,t){if(t!==`stacked`||e.hint===void 0)return{option:e,stackedHint:void 0};let{hint:n,...r}=e;return{option:r,stackedHint:n}}function optionUsesPlaceholder(e,t,n){let r=e.filter!==void 0,i=e.layout===`task-list`&&t===n-1,a=e.selection===`multiple`,o=e.layout!==`plain`;return!r&&!i&&(a||o)}function appendSelectOptionRows(e){let{rows:t,state:n,presentation:r,visible:i,start:a,end:o,cursor:s,visibleLabelWidth:c,theme:u}=e,d=u.colors;for(let e=a;e<o;e+=1){let f=i[e],p=e===s;r.layout===`task-list`&&e===o-1&&e>a&&t.push(``);let{option:m,stackedHint:h}=optionWithoutStackedHint(editableOption(f,p,r.edit,u),r.layout);t.push(` ${optionRow({option:m,isCursor:p,isChecked:r.selection===`multiple`&&n.select.selected.has(f.value),placeholder:optionUsesPlaceholder(r,e,i.length),hintPadding:c-f.label.length,theme:u})}`),h!==void 0&&t.push(` ${renderOptionRowContinuation(dimWithEmphasis(h,u))}`),f.description!==void 0&&(f.disabled===!0||p)&&t.push(` ${d.dim(f.description)}`),r.layout===`stacked`&&e<o-1&&t.push(``)}}function appendSubmitRow(e,t,n,r){if(n<0)return;let i=t===n,a=i?`${r.glyph.selectedPointer} ${r.colors.bold(`Submit`)}`:` Submit`;e.push(``,` ${renderCursorRow(a,i,r.colors)}`)}function appendSelectNotices(e,t,n,a,o){if(!(t===void 0||t.length===0)){e.push(``);for(let s of t){let t=toneGlyph(s.tone,a),c=` `.repeat(visibleLength(t)+1),l=Math.max(1,o-2-visibleLength(t)-1),u=wrapVisibleLine(s.text,l);for(let[r,i]of u.entries()){let o=noticeBody({...s,text:i},n,a);e.push(r===0?` ${t} ${o}`:` ${c}${o}`)}}}}function selectFooterHints(e,t,n){let r=[];return e.edit!==void 0&&t[n]?.value===e.edit.optionValue&&r.push(`type to rename`),e.filter!==void 0&&r.push(`type to filter`),r.push(`↑/↓ move`),r.push(e.selection===`multiple`?`space to toggle`:`enter to select`),e.selection===`multiple`&&r.push(`enter on Submit to confirm`),r.push(`esc to cancel`),r}function renderActionQuestion(e,t,n){let r=[` ${t.colors.dim(`${t.glyph.dot} ${e.context}`)}`,``];for(let[n,i]of e.actions.entries())r.push(` ${optionRow({option:i,isCursor:n===e.cursor,isChecked:!1,placeholder:!0,hintPadding:0,theme:t})}`);return r.push(...questionFooter([`↑/↓ move`,`enter to select`,`esc to cancel`],t)),r.map(e=>clip(e,n))}function renderSelectQuestion(e,t,n){if(e.kind===`actions`)return renderActionQuestion(e,t,n);let r=t.colors,i=selectPresentation(e),a=i.filter?filterOptions(e.options,e.select.filter,e.searchAction):e.options,o=i.selection===`multiple`?submitRowIndex(a):-1,s=e.select.cursor,c=selectMessageRows(e.message,i.layout,t);i.filter!==void 0&&c.push(` ${searchFilter(e.select.filter,i.filter.placeholder,e.loadingFrame,t)}`);let l=0;for(;a[l]?.featured;)l+=1;let u=selectViewSize({search:i.filter!==void 0,filter:e.select.filter,featuredLead:l,optionCount:a.length}),p=Math.max(0,Math.min(s-Math.floor(u/2),Math.max(0,a.length-u))),m=Math.min(p+u,a.length),h=a.slice(p,m).filter(e=>e.hint!==void 0||e.focusHint!==void 0).reduce((e,t)=>Math.max(e,t.label.length),0);return a.length===0&&c.push(` ${r.dim(`(no matches)`)}`),appendSelectOptionRows({rows:c,state:e,presentation:i,visible:a,start:p,end:m,cursor:s,visibleLabelWidth:h,theme:t}),appendSubmitRow(c,s,o,t),a.length>m-p&&c.push(` ${r.dim(`↑↓ ${a.length} options, showing ${p+1}–${m}`)}`),appendSelectNotices(c,e.notices,i.layout,t,n),e.error!==void 0&&c.push(``,` ${r.red(e.error)}`),c.push(...questionFooter(selectFooterHints(i,a,s),t)),c.map(e=>clip(e,n))}function renderTextQuestion(e,r,i,s){let c=r.colors,l=[];for(let t of e.notices??[]){let e=t.tone===`info`?c.dim(t.text):t.text;l.push(`${toneGlyph(t.tone,r)} ${e}`)}l.push(...e.message.split(`
|
|
3
|
+
`).map(e=>` ${c.bold(e)}`));let u=Math.max(4,i-4),d=e.mask?maskLine(e.editor):e.editor,f=e.editor.text.length===0?e.placeholder:void 0,p=renderInputWithBlockCursor({...visibleLine(f===void 0?d:{text:f,cursor:0},u,r.glyph.ellipsis),visible:s,inverse:c.inverse,render:f===void 0?renderInputText:e=>c.dim(renderInputText(e))});return l.push(` ${p}`),e.error!==void 0&&l.push(``,` ${c.red(e.error)}`),l.push(...questionFooter([`enter to submit`,`esc to cancel`],r)),l.map(e=>clip(e,i))}function renderAcknowledgeQuestion(e,t,n){let r=t.colors,i=[` ${r.bold(e.message)}`];if(e.lines.length>0){i.push(``);for(let t of e.lines)i.push(` ${r.dim(t)}`)}return i.push(...questionFooter([`enter to continue`],t)),i.map(e=>clip(e,n))}export{renderAcknowledgeQuestion,renderFlowPanel,renderSelectQuestion,renderTextQuestion};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PromptOption } from "#setup/cli/index.js";
|
|
2
|
-
import { type SelectState } from "#setup/cli/select-state.js";
|
|
2
|
+
import { type SearchActionOption, type SelectState } from "#setup/cli/select-state.js";
|
|
3
3
|
import type { TerminalKey } from "./stream-format.js";
|
|
4
4
|
/** Shared navigation grammar for setup selects, actions, and editable selects. */
|
|
5
5
|
export type SetupSelectionIntent = {
|
|
@@ -33,6 +33,7 @@ export type SetupSelectInputResult = {
|
|
|
33
33
|
interface SetupSelectInput {
|
|
34
34
|
key: TerminalKey;
|
|
35
35
|
options: readonly PromptOption<string>[];
|
|
36
|
+
searchAction?: SearchActionOption;
|
|
36
37
|
select: SelectState;
|
|
37
38
|
}
|
|
38
39
|
type SetupSingleSelectInput = SetupSelectInput & {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{filterOptions,orderedSelection,reduceSelect,selectValueAtCursor,submitRowIndex}from"#setup/cli/select-state.js";function setupSelectionIntent(e){switch(e.type){case`ctrl-c`:case`escape`:return{kind:`cancel`};case`up`:return{kind:`move`,direction:`up`};case`down`:return{kind:`move`,direction:`down`};case`ctrl-r`:return{kind:`repaint`};case`enter`:return{kind:`submit`};default:return}}function isMultiSelect(e){return e.kind===`multi`||e.kind===`searchable-multi`}function isSearchableSelect(e){return e.kind===`search`||e.kind===`searchable-multi`}function updatedSelect(e,t){return{kind:`update`,select:reduceSelect(e.select,t,{options:e.options,submitRow:isMultiSelect(e)})}}function submitSetupSelect(n){let a=isSearchableSelect(n)?filterOptions(n.options,n.select.filter):[...n.options];if(isMultiSelect(n))return n.select.cursor===submitRowIndex(a)?n.required&&n.select.selected.size===0?{kind:`error`,message:`Select at least one option, then submit.`}:{kind:`submit`,values:orderedSelection(n.options,n.select.selected)}:updatedSelect(n,{type:`toggle`});let o=selectValueAtCursor(a,n.select.cursor);return o===void 0?a[n.select.cursor]?.completed?{kind:`ignore`}:{kind:`error`,message:`Type to match an option, then press enter.`}:{kind:`submit`,values:[o]}}function editSetupSelect(e){switch(e.key.type){case`backspace`:return isSearchableSelect(e)?updatedSelect(e,{type:`backspace`}):{kind:`ignore`};case`text`:{if(e.key.framing===`unframed`&&isMultiSelect(e)&&e.key.value===` `)return updatedSelect(e,{type:`toggle`});if(!isSearchableSelect(e))return{kind:`ignore`};let t=e.select,r={options:e.options,submitRow:isMultiSelect(e)};for(let i of e.key.value.replaceAll(`
|
|
2
|
-
`,` `))i>=` `&&i!==``&&(t=reduceSelect(t,{type:`char`,char:i},r));return{kind:`update`,select:t}}default:return{kind:`ignore`}}}function reduceSetupSelectInput(e){let t=setupSelectionIntent(e.key);switch(t?.kind){case`cancel`:return{kind:`cancel`};case`repaint`:return{kind:`repaint`};case`move`:return updatedSelect(e,{type:t.direction});case`submit`:return submitSetupSelect(e);case void 0:return editSetupSelect(e)}}export{reduceSetupSelectInput,setupSelectionIntent};
|
|
1
|
+
import{filterOptions,orderedSelection,reduceSelect,selectValueAtCursor,submitRowIndex}from"#setup/cli/select-state.js";function setupSelectionIntent(e){switch(e.type){case`ctrl-c`:case`escape`:return{kind:`cancel`};case`up`:return{kind:`move`,direction:`up`};case`down`:return{kind:`move`,direction:`down`};case`ctrl-r`:return{kind:`repaint`};case`enter`:return{kind:`submit`};default:return}}function isMultiSelect(e){return e.kind===`multi`||e.kind===`searchable-multi`}function isSearchableSelect(e){return e.kind===`search`||e.kind===`searchable-multi`}function updatedSelect(e,t){return{kind:`update`,select:reduceSelect(e.select,t,{options:e.options,searchAction:e.searchAction,submitRow:isMultiSelect(e)})}}function submitSetupSelect(n){let a=isSearchableSelect(n)?filterOptions(n.options,n.select.filter,n.searchAction):[...n.options];if(isMultiSelect(n))return n.select.cursor===submitRowIndex(a)?n.required&&n.select.selected.size===0?{kind:`error`,message:`Select at least one option, then submit.`}:{kind:`submit`,values:orderedSelection(n.options,n.select.selected)}:updatedSelect(n,{type:`toggle`});let o=selectValueAtCursor(a,n.select.cursor);return o===void 0?a[n.select.cursor]?.completed?{kind:`ignore`}:{kind:`error`,message:`Type to match an option, then press enter.`}:{kind:`submit`,values:[o]}}function editSetupSelect(e){switch(e.key.type){case`backspace`:return isSearchableSelect(e)?updatedSelect(e,{type:`backspace`}):{kind:`ignore`};case`text`:{if(e.key.framing===`unframed`&&isMultiSelect(e)&&e.key.value===` `)return updatedSelect(e,{type:`toggle`});if(!isSearchableSelect(e))return{kind:`ignore`};let t=e.select,r={options:e.options,searchAction:e.searchAction,submitRow:isMultiSelect(e)};for(let i of e.key.value.replaceAll(`
|
|
2
|
+
`,` `))i>=` `&&i!==``&&(t=reduceSelect(t,{type:`char`,char:i},r));return{kind:`update`,select:t}}default:return{kind:`ignore`}}}function reduceSetupSelectInput(e){let t=setupSelectionIntent(e.key);switch(t?.kind){case`cancel`:return e.key.type===`escape`&&isSearchableSelect(e)&&e.select.filter.length>0?updatedSelect(e,{type:`clear`}):{kind:`cancel`};case`repaint`:return{kind:`repaint`};case`move`:return updatedSelect(e,{type:t.direction});case`submit`:return submitSetupSelect(e);case void 0:return editSetupSelect(e)}}export{reduceSetupSelectInput,setupSelectionIntent};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{clipVisible,renderInputText,stripAnsi,stripTerminalControls}from"./terminal-text.js";import{summarizeToolArgs,summarizeToolResult}from"./tool-format.js";import{buildAgentHeader}from"./agent-header.js";import{PROMPT_COMMANDS,isPromptControlCommand,parsePromptCommand}from"./prompt-commands.js";import{renderAttentionRows,renderBlockLines}from"./blocks.js";import{dismissTypeahead,inlineCommandHint,isTypeaheadOpen,moveTypeaheadSelection,renderCommandSuggestions,selectedTypeaheadCommand,typeaheadCompletion,typeaheadFor}from"./command-typeahead.js";import{formatDevRebuildStatus,summarizeChangedFiles}from"./dev-rebuild-status.js";import{interruptedError}from"./errors.js";import{EMPTY_LINE,PromptHistory,applyLineEditorKey,deleteForward,layoutPromptInput,lineOf,movePromptLine,visibleLine}from"./line-editor.js";import{LiveRegion}from"./live-region.js";import{nextLogDisplayMode}from"./log-display-mode.js";import{renderAcknowledgeQuestion,renderFlowPanel,renderSelectQuestion,renderTextQuestion}from"./setup-panel.js";import{buildStatusLine}from"./status-line.js";import{createTheme,detectUnicode}from"./theme.js";import{reduceSetupSelectInput,setupSelectionIntent}from"./setup-selection-input.js";import{formatAssistantResponseStats,formatTokenFlow,isIncompletePaste,nextKey,sanitizePastedText,stripPasteStart,stripPromptControlCharacters,takeUntil}from"./stream-format.js";import{renderCursorRow}from"#setup/cli/option-row.js";import{toErrorMessage}from"#shared/errors.js";import{StringDecoder}from"node:string_decoder";import{initialSelectState,reduceSelect,selectValueAtCursor}from"#setup/cli/select-state.js";import{parseDevRebuildLogLine}from"#internal/nitro/host/dev-watcher-log.js";function isMultiSelectRequest(e){return e.kind===`multi`||e.kind===`searchable-multi`}function moveActionCursor(e,t,n){return n===0?void 0:e===void 0?t===`down`?0:n-1:(e+(t===`down`?1:-1)+n)%n}function completedTurnStatus(e,t){return e?`Interrupted`:t?`Ready`:`Done`}const STATUS={processing:`Working…`,toolResults:`Reading results…`,streaming:`Responding…`,executingTools:`Running tools…`,connectionAuth:`Waiting for connection authorization…`};var TerminalRenderer=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f=[];#p=new Map;#m=new Set;#h=[];#g=new Set;#_=new Map;#v=new Set;#y;#b=!1;#x;#S=[];#C;#w=0;#T;#E=``;#D=0;#O=new PromptHistory;#k=!1;#A;#j
|
|
2
|
-
`);if(this.#b){t!==this.#x&&(this.#x=t,this.#
|
|
3
|
-
`),live:!1}),this.#qe({kind:`flow`,title:n.tone,body:n.text,live:!1})),e=[]}}this.#ct()}}async#ve(e){let t=this.#Ce(),n=isMultiSelectRequest(e),r={options:e.options,submitRow:n};`initialValue`in e&&e.initialValue!==void 0&&(r.defaultValue=e.initialValue),`initialValues`in e&&e.initialValues!==void 0&&(r.initialValues=e.initialValues);let i=initialSelectState(r),a,o=e.notices;if(e.kind===`task-list`){let n=t.taskListLineStart??t.lines.length,r=t.lines.slice(n).filter(e=>e.tone===`success`||e.tone===`warning`||e.tone===`error`).map(e=>({tone:e.tone,text:e.text}));o=[...e.notices??[],...r],t.taskListLineStart=t.lines.length,t.hideLinesWhileQuestion=!0}let panelState=()=>{let t={...e,select:i};return o!==void 0&&o.length>0&&(t.notices=o),a!==void 0&&(t.error=a),t};return t.question=e=>renderSelectQuestion(panelState(),this.#r,e),this.#ct(),await this.#Ee((t,r)=>{let o={key:t,options:e.options,select:i},s=reduceSetupSelectInput(n?{...o,kind:e.kind,required:e.required}:{...o,kind:e.kind});switch(s.kind){case`cancel`:r(void 0);return;case`repaint`:this.#ct();return;case`update`:i=s.select,a=void 0,this.#ct();return;case`submit`:r(s.values);return;case`error`:a=s.message,this.#ct();return;case`ignore`:return}}).promise}#ye(e){this.#Ne();let t=this.#we();t.status=e.status;let n;t.question=t=>renderSelectQuestion({kind:`actions`,context:e.context,actions:e.actions,cursor:n},this.#r,t),this.#ct();let r=this.#Ee((t,r)=>{let i=setupSelectionIntent(t);switch(i?.kind){case`cancel`:r(void 0);return;case`move`:n=moveActionCursor(n,i.direction,e.actions.length),this.#ct();return;case`repaint`:this.#ct();return;case`submit`:n!==void 0&&r(e.actions[n].value);return;case void 0:return}},()=>{t.status=void 0});return{choice:r.promise,close:()=>r.settle(void 0)}}async#be(e){let t=this.#Ce(),n={options:e.options};e.initialValue!==void 0&&(n.defaultValue=e.initialValue);let r=initialSelectState(n),i=lineOf(``),a;t.question=t=>{let n={kind:`editable`,message:e.message,options:e.options,select:r,edit:{optionValue:e.editable.value,editor:i,defaultValue:e.editable.defaultValue,formatHint:e.editable.formatHint,caretVisible:this.#I}};return a!==void 0&&(n.error=a),renderSelectQuestion(n,this.#r,t)};let onEditableRow=()=>selectValueAtCursor([...e.options],r.cursor)===e.editable.value,syncEditableRow=()=>{onEditableRow()?(i.text.length===0&&(i=lineOf(e.editable.defaultValue)),this.#He()):(i=lineOf(``),this.#Ue())};return syncEditableRow(),this.#ct(),await this.#Ee((t,n)=>{let applyEditor=e=>{i=e,a=void 0,this.#We(),this.#ct()},applySelect=t=>{r=reduceSelect(r,t,{options:e.options}),a=void 0,syncEditableRow(),this.#ct()},submit=()=>{let t=selectValueAtCursor([...e.options],r.cursor);if(t===void 0)return;if(t!==e.editable.value){n({kind:`selected`,value:t});return}let o=(i.text||e.editable.defaultValue).trim(),s=e.editable.validate?.(o);if(s!==void 0){a=s,this.#ct();return}n(o===e.editable.defaultValue?{kind:`selected`,value:t}:{kind:`edited`,value:t,text:o})},o=setupSelectionIntent(t);switch(o?.kind){case`cancel`:n(void 0);return;case`move`:applySelect({type:o.direction});return;case`submit`:submit();return;case`repaint`:this.#ct();return;case void 0:break}if(!onEditableRow())return;let s=applyLineEditorKey(i,t);s!==void 0&&applyEditor(s)},()=>this.#Ue()).promise}async#xe(e){let t=this.#Ce(),n=lineOf(``),r;return t.question=t=>{let i={message:e.message,editor:n,mask:e.mask===!0};return e.placeholder!==void 0&&(i.placeholder=e.placeholder),e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#r,t,this.#I)},this.#He(),this.#ct(),await this.#Ee((t,i)=>{let apply=e=>{n=e,r=void 0,this.#We(),this.#ct()},a=applyLineEditorKey(n,t);if(a!==void 0){apply(a);return}switch(t.type){case`ctrl-c`:case`escape`:i(void 0);return;case`ctrl-r`:this.#ct();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#ct();return}i(t);return}default:return}},()=>this.#Ue()).promise}async#Se(e){let t=this.#Ce();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#r,t),this.#ct(),await this.#Ee((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#ct();return;default:return}}).promise}#Ce(){return this.#Ne(),this.#k=!1,this.#j=!1,this.#M=``,this.#we()}#we(){return this.#le===void 0&&(this.#le={title:``,lines:[],outputBuffer:[]}),this.#le}#Te(){this.#le!==void 0&&(this.#le.question=void 0,this.#le.hideLinesWhileQuestion=!1),this.#H=void 0,this.#Ie(),this.#Oe(),this.#ct()}#Ee(e,t){let n=!1,r,i=new Promise(e=>{r=e}),settle=e=>{n||(n=!0,t?.(),this.#Te(),r(e))};return this.#H=t=>e(t,settle),this.#Fe(),{promise:i,settle}}#De(){let e,t=new Promise(t=>{e=t});return this.#de=e,this.#Oe(),{promise:t,dispose:()=>{this.#de===e&&(this.#de=void 0,this.#ke())}}}#Oe(){if(this.#de===void 0)return;let consumer=e=>{if(e.type===`ctrl-c`||e.type===`escape`){let e=this.#de;this.#de=void 0,this.#ke(),e?.();return}e.type===`ctrl-r`&&this.#ct()};this.#fe=consumer,this.#H=consumer,this.#Fe()}#ke(){this.#fe!==void 0&&(this.#H===this.#fe&&this.#Ie(),this.#fe=void 0)}#Ae(e){let t=e===void 0?void 0:stripTerminalControls(e);if(this.#le!==void 0){this.#le.status=t,t===void 0&&(this.#le.preview=void 0),this.#ct();return}if(t===void 0){this.#j=!1,this.#M=``,this.#Ke(),this.#ct();return}this.#Ne(),this.#j=!0,this.#M=t,this.#Ge(),this.#ct()}#je(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let i=this.#le;if(i!==void 0){if(i.preview=void 0,t===`warning`||t===`error`)for(let e of i.outputBuffer)i.lines.push({text:e,tone:`info`,evidence:!0});i.outputBuffer=[],i.lines.push({text:n,tone:t}),this.#ct();return}this.#Ne(),this.#qe({kind:`flow`,title:t,body:n,live:!1}),this.#ct()}#Me(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#le;if(n===void 0){this.#je(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#ct()}shutdown(){this.#Pe()}#Ne(e){this.#N=e?.title??this.#N,this.#Q=e?.contextSize??this.#l,!this.#P&&(this.#P=!0,this.#n.reset(),this.#n.hideCursor(),this.#xt(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#K=()=>this.#ct(),this.#t.on(`resize`,this.#K))}#Pe(){this.#Ie(),this.#Ue(),this.#Ke(),this.#B!==void 0&&(clearTimeout(this.#B),this.#B=void 0),this.#V=!1,this.#P&&=(this.#kt(),this.#ct(),this.#n.clear(),this.#n.showCursor(),this.#St(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#K&&=(this.#t.off(`resize`,this.#K),void 0),!1)}#Fe(){this.#e.off(`data`,this.#Le),this.#e.on(`data`,this.#Le)}#Ie(){this.#e.off(`data`,this.#Le),this.#Be(),this.#U=``,this.#W=new StringDecoder(`utf8`),this.#H=void 0}#Le=e=>{this.#Be(),this.#U+=this.#W.write(e),this.#ze(),this.#Re()};#Re(){if(this.#U===`\x1B`){this.#G=setTimeout(()=>{this.#U===`\x1B`&&(this.#U=``,this.#H?.({type:`escape`}))},30),this.#G.unref?.();return}if(isIncompletePaste(this.#U)){let e=this.#U;this.#G=setTimeout(()=>{if(this.#U!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#U=``,t.length>0&&this.#H?.({type:`text`,value:t,framing:`bracketed-paste`})},1e3),this.#G.unref?.()}}#ze(){for(;this.#U.length>0;){let e=nextKey(this.#U);if(e.incomplete)return;this.#U=this.#U.slice(e.consumed),e.key&&e.key.type!==`ignore`&&this.#H?.(e.key)}}#Be(){this.#G&&=(clearTimeout(this.#G),void 0)}#Ve(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#ct();break;case`ctrl-c`:this.#F||(this.#F=!0,this.#M=`Interrupted`,this.#q?.(),this.#ct());break;default:break}}#He(){this.#Ue(),this.#We(),this.#R=setInterval(()=>{this.#I=!this.#I,this.#ct()},500),this.#R.unref?.()}#Ue(){this.#R&&=(clearInterval(this.#R),void 0),this.#I=!0}#We(){this.#I=!0}#Ge(){this.#Ke(),this.#z=setInterval(()=>{this.#L+=1,this.#ct()},90),this.#z.unref?.()}#Ke(){this.#z&&=(clearInterval(this.#z),void 0)}#qe(e){e.id!==this.#oe?.id&&this.#kt(),this.#f.push(e),e.id&&this.#p.set(e.id,e)}#Je(e){this.#qe({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#ct()}#Ye(e){if(e!=null){if(this.#ce===e){this.#ce=void 0;return}this.#qe({kind:`user`,body:stripTerminalControls(e),live:!1})}}#Xe(e,t,n){let i={kind:`error`,title:stripTerminalControls(e),body:stripTerminalControls(t),live:!1};n!==void 0&&(i.detail=stripTerminalControls(n)),this.#qe(i),this.#ct()}#Ze(e,t){this.#v.has(e)||(this.#v.add(e),this.#qe({id:subagentHeaderId(e),kind:`subagent`,title:stripTerminalControls(t),live:!1}))}#Qe(e){if(e.id&&this.#m.has(e.id))return;let t=e.id?this.#p.get(e.id):void 0;if(t){Object.assign(t,e);return}this.#qe(e)}#$e(e){this.#f=this.#f.filter(t=>t.id!==e),this.#p.delete(e)}#et(){for(let e of this.#f)e.status===`approval`||e.status===`running`||(e.live=!1)}#tt(e,t,n){switch(e.type){case`step-start`:this.#nt(n.hasPendingToolResults?STATUS.toolResults:STATUS.processing),n.hasPendingToolResults=!1;break;case`step-finish`:this.#st(e.usage),this.#ct();break;case`assistant-delta`:{this.#nt(STATUS.streaming);let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#rt(e.id,t,!0);break}case`assistant-complete`:{let t=n.text.get(e.id)??``,i=e.text!==void 0&&t.length===0?stripTerminalControls(e.text??``):t;n.text.set(e.id,i),this.#rt(e.id,i,!1);break}case`reasoning-delta`:{if(t.reasoning===`hidden`)break;this.#nt(STATUS.streaming);let i=(n.reasoning.get(e.id)??``)+stripTerminalControls(e.delta);n.reasoning.set(e.id,i),this.#it(e.id,i,!0,t);break}case`reasoning-complete`:{if(t.reasoning===`hidden`)break;let r=n.reasoning.get(e.id)??``;this.#it(e.id,r,!1,t);break}case`tool-call`:if(t.tools===`hidden`)break;this.#nt(STATUS.executingTools),this.#at({input:e.input,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-approval-request`:{if(t.tools===`hidden`)break;let r=n.tools.get(e.toolCallId);if(r===void 0)break;this.#at({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#ot(e.toolCallId,n);if(r===void 0)break;n.hasPendingToolResults=!0,this.#nt(STATUS.toolResults),this.#at({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{if(t.tools===`hidden`)break;let r=this.#ot(e.toolCallId,n);if(r===void 0)break;n.hasPendingToolResults=!0,this.#nt(STATUS.toolResults),this.#at({...r,errorText:e.errorText,status:`error`},t,n);break}case`error`:this.#Xe(`Error`,e.errorText,e.detail);break;case`finish`:this.#st(e.usage),this.#ct();break}}#nt(e){let t=this.#w>0?STATUS.connectionAuth:e;this.#M!==t&&(this.#M=t,this.#ct())}#rt(e,t,n){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#Qe({id:e,kind:`assistant`,body:i,live:n}),this.#ct())}#it(e,t,n,i){let a=stripTerminalControls(t).trim();a.length!==0&&(this.#Qe({id:e,kind:`reasoning`,body:a,collapsed:collapseReasoning(i.reasoning,n),live:n}),this.#ct())}#at(e,t,n){if(n.tools.set(e.toolCallId,e),this.#g.has(e.toolCallId))return;let r=toolSectionId(e.toolCallId);this.#_.set(e.toolCallId,r),this.#Qe(renderNativeToolBlock(e,r,t.tools===`full`)),this.#ct()}#ot(e,t){let n=t.tools.get(e);if(n!==void 0)return n;let r=this.#_.get(e)??toolSectionId(e),i=this.#p.get(r);if(!(i===void 0||i.kind!==`tool`))return{errorText:i.status===`error`&&typeof i.result==`string`?i.result:void 0,input:i.toolInput,output:i.toolOutput,status:i.status??`running`,toolCallId:e,toolName:i.title??`tool`}}#st(e){if(e===void 0)return;let{inputTokens:t,outputTokens:n}=e;if((t!=null||n!=null)&&(this.#X=(t??0)+(n??0)),this.#Z=t??this.#Z,this.#$=n??this.#$,this.#$!=null&&this.#te!==void 0){let e=(Date.now()-this.#te)/1e3;e>0&&(this.#ee=this.#$/e)}}#ct(){if(this.#P){if(this.#J){this.#Y=!0;return}this.#J=!0;try{do this.#Y=!1,this.#lt();while(this.#Y)}finally{this.#J=!1}}}#lt(){if(!this.#P)return;let e=this.#yt(),t=this.#gt(e),n=Math.max(1,this.#bt()-t.length),r=[],i=this.#C;for(;this.#f.length>0&&this.#f[0].live===!1;){let t=this.#f.shift();if(this.#h.push(t),t.id&&(this.#m.add(t.id),this.#p.delete(t.id)),this.#jt(t))continue;let n=this.#mt(t,e,i);i=previousBlockOf(t),this.#C=i,r.push(...n),this.#S.push(...n)}let a=[];for(let t of this.#f){if(this.#jt(t))continue;let n=this.#mt(t,e,i);i=previousBlockOf(t);for(let e=0;e<n.length;e+=1)a.push({block:t,row:n[e]})}let o=[...clipLiveRows(a.map(e=>e.row),n,e,this.#r),...t];r.length>0?this.#n.flush(r,o):this.#n.update(o)}#ut(){if(!this.#P)return;let e=this.#yt(),t=this.#gt(e),n=Math.max(1,this.#bt()-t.length),r=this.#C,i=[];for(let t of this.#f){if(this.#jt(t))continue;let n=this.#mt(t,e,r);r=previousBlockOf(t),i.push(...n)}let a=[...clipLiveRows(i,n,e,this.#r),...t];this.#n.clearAll(),this.#n.flush([...this.#pt(),...this.#S],a)}logDisplayMode(){return this.#d}setLogDisplayMode(e){e!==this.#d&&(this.#d=e,e===`all`&&this.flushDelayedDevBuildErrors(),this.#ft(),this.#P&&this.#ut())}flushDelayedDevBuildErrors(){let e=this.#ae;e!==void 0&&(this.#ae=void 0,this.#qe({kind:`log`,title:`stderr`,body:e,live:!1}),this.#ct())}#dt(){this.#V=!0,this.#B!==void 0&&clearTimeout(this.#B),this.#B=setTimeout(()=>{this.#V=!1,this.#B=void 0,this.#ct()},5e3),this.setLogDisplayMode(nextLogDisplayMode(this.#d)),this.#ct()}#ft(){let e=this.#yt();this.#S.length=0;let t;for(let n of this.#h){if(this.#jt(n))continue;let r=this.#mt(n,e,t);t=previousBlockOf(n),this.#S.push(...r)}this.#C=t}#pt(){let e=this.#y;if(e===void 0)return[];let t={name:e.name,theme:this.#r,width:this.#yt()};return e.info!==void 0&&(t.info=e.info),e.tip!==void 0&&(t.tip=e.tip),buildAgentHeader(t)}#mt(e,t,n){let r={spinner:this.#ht()};n!==void 0&&(r.previous=n);let i=renderBlockLines(e,t,this.#r,r);return(e.depth??0)===0&&leadsWithGap(e,n)?[``,...i]:i}#ht(){return this.#r.spinner[this.#L%this.#r.spinner.length]??``}#gt(e){let t=this.#r.colors,n=[``],r=this.#le;if(r!==void 0){let t=this.#ht(),i;if(r.question!==void 0){let n=r.question(e);i={kind:`question`,rows:n},r.status!==void 0&&(i={kind:`question`,rows:n,status:{text:r.status,frame:t}})}else r.status===void 0?i=r.preview===void 0?{kind:`idle`,frame:t}:{kind:`preview`,text:r.preview,frame:t}:(i={kind:`status`,status:{text:r.status,frame:t}},r.preview!==void 0&&(i={kind:`status`,status:{text:r.status,frame:t},preview:r.preview}));let a={title:r.title,lines:r.hideLinesWhileQuestion===!0?[]:r.lines,content:i};return n.push(...renderFlowPanel(a,this.#r,e)),n}if(this.#ue!==void 0&&n.push(...renderAttentionRows(this.#ue,e,this.#r),``),this.#k){let r=this.#A===void 0?void 0:inlineCommandHint(this.#A);r===void 0&&this.#A!==void 0&&isTypeaheadOpen(this.#A)&&n.push(...renderCommandSuggestions(this.#A,this.#r,e));let i=isPromptControlCommand(this.#E),a=r?t.dim(` ${r}`):``,o=[];this.#_t(o,e);let s=Math.max(1,this.#bt()-1-n.length-1-o.length);return n.push(...promptInputRows({text:this.#E,cursor:this.#D,width:e,theme:this.#r,caretVisible:this.#I,isCommand:i,ghost:a,maxRows:s})),n.push(...o),n}let i=this.#j?t.yellow(this.#ht()):t.dim(this.#r.glyph.dot),a=this.#M.length>0?this.#M:`Ready`,o=this.#j?t.dim(a):a,s=this.#vt(),l=s?`${i} ${o} ${t.dim(this.#r.glyph.dot)} ${s}`:`${i} ${o}`;return n.push(clip(l,e)),this.#_t(n,e),n}#_t(e,t){let n={theme:this.#r,width:t};this.#V&&(n.logLevel=this.#d);let r=this.#y?.info?.agent.model.id;r!==void 0&&(n.model=r);let i=this.#y?.info?.agent.model.endpoint;i!==void 0&&(n.endpoint=i);let a=this.#Z??0,o=this.#$??0;if(a>0||o>0){let e={inputTokens:a,outputTokens:o};this.#Q!==void 0&&(e.contextSize=this.#Q),n.tokens=formatTokenFlow(e,this.#r.glyph)}this.#T!==void 0&&(n.vercel=this.#T);let s=buildStatusLine(n);s!==void 0&&e.push(s)}#vt(){let e=this.#r.colors,t=[],n=formatAssistantResponseStats({totalTokens:this.#X,outputTokens:this.#$,tokensPerSecond:this.#ee},this.#c);return n&&t.push(n),t.length>0?e.dim(t.join(` ${this.#r.glyph.dot} `)):``}#yt(){return Math.max(20,this.#t.columns||80)}#bt(){return Math.max(8,this.#t.rows||24)}#xt(){if(this.#ne!==void 0||!this.#u)return;this.#re=``,this.#ie=``;let capture=(e,t)=>{let n=e.write.bind(e);return e.write=((e,n,r)=>{let i=typeof n==`string`?n:void 0,a=typeof n==`function`?n:r;return this.#Ct(t,chunkToString(e,i)),a?.(),!0}),()=>{e.write=n}},e=capture(process.stdout,`stdout`),t=capture(process.stderr,`stderr`);this.#ne=()=>{e(),t()}}#St(){let e=this.#ne;e!==void 0&&(this.#ne=void 0,e(),this.#re.length>0&&(this.#At(`stdout`)&&process.stdout.write(`${this.#re}\n`),this.#re=``),this.#ie.length>0&&(this.#At(`stderr`)&&process.stderr.write(`${this.#ie}\n`),this.#ie=``))}#Ct(e,t){let r=(e===`stdout`?this.#re:this.#ie)+t,i=r.lastIndexOf(`
|
|
4
|
-
`),a=i===-1?
|
|
5
|
-
`);t=[],e.trim().length!==0&&this.#
|
|
6
|
-
`)){let e=parseSandboxLogLine(n.trimEnd());if(e!==void 0){flushPending(),this.#
|
|
7
|
-
`),n=t.findIndex(e=>parseDevRebuildLogLine(e.trimEnd())?.kind===`failed`);if(n===-1){this.#
|
|
8
|
-
`);r.trim().length>0&&this.#
|
|
9
|
-
`);this.#
|
|
10
|
-
`)}function formatQuestionContent(e,t,n){let
|
|
1
|
+
import{clipVisible,renderInputText,renderInputWithBlockCursor,stripAnsi,stripTerminalControls}from"./terminal-text.js";import{summarizeToolArgs,summarizeToolResult}from"./tool-format.js";import{buildAgentHeader}from"./agent-header.js";import{PROMPT_COMMANDS,isPromptControlCommand,parsePromptCommand}from"./prompt-commands.js";import{renderAttentionRows,renderBlockLines}from"./blocks.js";import{dismissTypeahead,inlineCommandHint,isTypeaheadOpen,moveTypeaheadSelection,renderCommandSuggestions,selectedTypeaheadCommand,typeaheadCompletion,typeaheadFor}from"./command-typeahead.js";import{formatDevRebuildStatus,summarizeChangedFiles}from"./dev-rebuild-status.js";import{interruptedError}from"./errors.js";import{EMPTY_LINE,PromptHistory,applyLineEditorKey,deleteForward,layoutPromptInput,lineOf,movePromptLine,visibleLine}from"./line-editor.js";import{LiveRegion}from"./live-region.js";import{nextLogDisplayMode}from"./log-display-mode.js";import{renderAcknowledgeQuestion,renderFlowPanel,renderSelectQuestion,renderTextQuestion}from"./setup-panel.js";import{buildStatusLine}from"./status-line.js";import{createTheme,detectUnicode}from"./theme.js";import{reduceSetupSelectInput,setupSelectionIntent}from"./setup-selection-input.js";import{formatAssistantResponseStats,formatTokenFlow,isIncompletePaste,nextKey,sanitizePastedText,stripPasteStart,stripPromptControlCharacters,takeUntil}from"./stream-format.js";import{renderCursorRow}from"#setup/cli/option-row.js";import{toErrorMessage}from"#shared/errors.js";import{StringDecoder}from"node:string_decoder";import{initialSelectState,reduceSelect,searchActionQuery,selectValueAtCursor}from"#setup/cli/select-state.js";import{parseDevRebuildLogLine}from"#internal/nitro/host/dev-watcher-log.js";import{PROGRESS_PULSE_ASCII_GLYPH,PROGRESS_PULSE_GLYPH,isProgressPulseVisible}from"#cli/ui/progress-pulse.js";function isMultiSelectRequest(e){return e.kind===`multi`||e.kind===`searchable-multi`}function moveActionCursor(e,t,n){return n===0?void 0:e===void 0?t===`down`?0:n-1:(e+(t===`down`?1:-1)+n)%n}function completedTurnStatus(e,t){return e?`Interrupted`:t?`Ready`:`Done`}const STATUS={processing:`Working…`,toolResults:`Reading results…`,streaming:`Responding…`,executingTools:`Running tools…`,connectionAuth:`Waiting for connection authorization…`};var TerminalRenderer=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f=[];#p=new Map;#m=new Set;#h=[];#g=new Set;#_=new Map;#v=new Set;#y;#b=!1;#x;#S=[];#C;#w=0;#T;#E=``;#D=0;#O=new PromptHistory;#k=!1;#A;#j={kind:`idle`};#M=STATUS.processing;#N=`eve`;#P=!1;#F=!1;#I=!0;#L=0;#R;#z;#B;#V=!1;#H;#U=``;#W=new StringDecoder(`utf8`);#G;#K;#q;#J=!1;#Y=!1;#X;#Z;#Q;#$;#ee;#te;#ne;#re=``;#ie=``;#ae;#oe;#se=0;#ce;#le;#ue;#de;#fe;setupFlow={begin:(e,t)=>this.#ge(e,t),end:e=>this.#_e(e?.preserveDiagnostics??!0),readSelect:e=>this.#ve(e),readEditableSelect:e=>this.#be(e),readText:e=>this.#xe(e),readAcknowledge:e=>this.#Se(e),readChoice:e=>this.#ye(e),setStatus:e=>this.#Ae(e),renderLine:(e,t)=>this.#je(e,t),renderOutput:e=>this.#Me(e),waitForInterrupt:()=>this.#De()};constructor(e){this.#e=e?.input??process.stdin,this.#t=e?.output??process.stdout,this.#n=new LiveRegion(this.#t),this.#r=createTheme({color:e?.color??!0,unicode:e?.unicode??detectUnicode()}),this.#i=e?.tools??`auto-collapsed`,this.#a=e?.reasoning??`full`,this.#o=e?.subagents??`auto-collapsed`,this.#s=e?.connectionAuth??`full`,this.#c=e?.assistantResponseStats??`tokensPerSecond`,this.#l=e?.contextSize,this.#Q=e?.contextSize,this.#u=e?.captureForeignOutput??this.#t===process.stdout,this.#d=e?.logs??`none`}renderAgentHeader(e){this.#N=e.name,this.#y=e,this.#Ne();let t=this.#ht().join(`
|
|
2
|
+
`);if(this.#b){t!==this.#x&&(this.#x=t,this.#Je({kind:`agent-header`,body:t,live:!1})),this.#ut();return}this.#b=!0,this.#x=t,this.#n.flush(this.#ht(),[])}async readPrompt(e){this.#Ne(e),this.#qe(),this.#k=!0,this.#j={kind:`idle`},this.#M=``;let t=lineOf(stripPromptControlCharacters(e?.initialDraft??``));return this.#O.begin(t.text),this.#pe(t),this.#A=typeaheadFor(PROMPT_COMMANDS,t.text),this.#He(),this.#ut(),await new Promise((e,n)=>{let apply=e=>{t=e,this.#We(),this.#pe(t),this.#A=typeaheadFor(PROMPT_COMMANDS,e.text,this.#A),this.#ut()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#A=void 0,this.#Ue(),this.#Pe(),n(interruptedError())},suggestions=()=>this.#A!==void 0&&isTypeaheadOpen(this.#A)?this.#A:void 0,highlighted=()=>{let e=suggestions();return e===void 0?void 0:selectedTypeaheadCommand(e)};this.#H=n=>{let r=applyLineEditorKey(t,n,{multiline:!0});if(r!==void 0){apply(r);return}switch(n.type){case`up`:{let e=suggestions();if(e!==void 0){this.#A=moveTypeaheadSelection(e,-1),this.#ut();break}let n=movePromptLine(t,`up`);n===void 0?recall(this.#O.previous(t.text)):apply(n);break}case`down`:{let e=suggestions();if(e!==void 0){this.#A=moveTypeaheadSelection(e,1),this.#ut();break}let n=movePromptLine(t,`down`);n===void 0?recall(this.#O.next()):apply(n);break}case`tab`:{let e=highlighted();e!==void 0&&apply(lineOf(typeaheadCompletion(e)));break}case`escape`:{let e=suggestions();e!==void 0&&(this.#A=dismissTypeahead(e),this.#ut());break}case`enter`:{let n=highlighted(),r=n!==void 0&&parsePromptCommand(t.text)===null?typeaheadCompletion(n).trimEnd():t.text;this.#A=void 0,this.#O.add(r),this.#k=!1,this.#Ue(),this.#Ke(),this.#M=STATUS.processing,isPromptControlCommand(r)?this.#Je({kind:`command`,body:stripTerminalControls(r.trim()),live:!1}):(this.#Ye(r),this.#ce=r),this.#pe(EMPTY_LINE),this.#ut(),this.#Ie(),e(r);break}case`ctrl-d`:t.text.length===0?interrupt():apply(deleteForward(t));break;case`ctrl-l`:this.#pt();break;case`ctrl-r`:this.#ut();break;case`ctrl-c`:t.text.length===0?interrupt():apply(EMPTY_LINE);break;default:break}},this.#Fe()})}#pe(e){this.#E=e.text,this.#D=e.cursor}async renderStream(e,t){this.#Ne(t),this.#m.clear(),this.#k=!1,this.#j.kind!==`waiting`&&(this.#j={kind:`waiting`,startedAtMs:Date.now()}),this.#M=STATUS.processing,this.#Xe(t?.submittedPrompt),this.#F=!1,this.#X=void 0,this.#Z=void 0,this.#$=void 0,this.#ee=void 0,this.#te=Date.now();let n={tools:t?.tools??this.#i,reasoning:t?.reasoning??this.#a,assistantResponseStats:t?.assistantResponseStats??this.#c};this.#Ge(),this.#ut();let r=new Promise(e=>{this.#q=e});this.#H=e=>this.#Ve(e),this.#Fe();let i={text:new Map,reasoning:new Map,tools:new Map,hasPendingToolResults:!1};try{for await(let t of takeUntil(iterateTUIStream(e.events),r)){if(this.#F)break;this.#nt(t,n,i)}}catch(e){this.#Ze(`Error`,toErrorMessage(e))}finally{this.#q=void 0,this.#F&&e.abort?.(),this.#Ie(),this.#qe(),this.#j.kind===`waiting`&&(this.#j={kind:`idle`}),this.#M=completedTurnStatus(this.#F,t?.continueSession===!0),this.#tt(),this.#ut(),t?.continueSession||this.#Pe()}}async readToolApproval(e,t){return this.#Ne(t),this.#qe(),this.#k=!1,this.#j={kind:`idle`},this.#M=`Approve ${formatToolApprovalTitle(e)}? (y/n)`,this.#F=!1,this.#ut(),await new Promise((t,n)=>{this.#H=r=>{switch(r.type){case`text`:{if(r.framing!==`unframed`)break;let n=r.value.toLowerCase();n===`y`?(this.#Ke(),this.#M=STATUS.processing,this.#Ie(),this.#ut(),t({approved:!0})):n===`n`&&(this.#Ke(),this.#M=STATUS.processing,this.#me(e.toolCallId),this.#Ie(),this.#ut(),t({approved:!1,reason:`Denied by user.`}));break}case`ctrl-r`:this.#ut();break;case`ctrl-c`:this.#F=!0,this.#Pe(),n(interruptedError());break;default:break}},this.#Fe()})}async readInputQuestion(e,t){this.#Ne(t),this.#qe(),this.#k=!1,this.#j={kind:`idle`},this.#F=!1;let n=e.options??[],r=n.length>0,a=(e.allowFreeform===!0||!r)&&r,o=n.length+ +!!a,s=questionSectionId(e.requestId),c=r?`select`:`text`,l=0,u=EMPTY_LINE,isOnFreeformRow=()=>a&&l===n.length,renderSection=()=>{this.#$e({id:s,kind:`question`,title:stripTerminalControls(e.prompt),body:formatQuestionContent(e,l,this.#r),preformatted:!0,live:!0})},repaintStatus=()=>{if(c===`select`){let e=isOnFreeformRow()?`type`:`select`;this.#M=`↑/↓ move · enter ${e} · Ctrl+C quit`,this.#k=!1}else this.#k=!0,this.#pe(u),this.#M=``;this.#ut()};renderSection(),c===`text`&&this.#He(),repaintStatus();let finalize=t=>{this.#$e({id:s,kind:`question`,title:stripTerminalControls(e.prompt),body:` ${this.#r.colors.green(this.#r.glyph.success)} ${stripTerminalControls(t.label)}`,preformatted:!0,live:!1}),this.#k=!1,this.#Ke(),this.#M=STATUS.processing,this.#Ue(),this.#Ie(),this.#ut();let n={};return t.optionId!==void 0&&(n.optionId=t.optionId),t.text!==void 0&&(n.text=t.text),n};return await new Promise((t,i)=>{this.#H=a=>{if(a.type===`ctrl-c`){if(c===`text`&&u.text.length>0){u=EMPTY_LINE,this.#We(),repaintStatus();return}this.#F=!0,this.#Ue(),this.#Pe(),i(interruptedError());return}if(a.type===`ctrl-r`){this.#ut();return}if(c===`select`){switch(a.type){case`up`:o>0&&(l=(l-1+o)%o,renderSection(),repaintStatus());break;case`down`:o>0&&(l=(l+1)%o,renderSection(),repaintStatus());break;case`enter`:{if(isOnFreeformRow()){c=`text`,u=EMPTY_LINE,this.#He(),repaintStatus();break}let e=n[l];e&&t(finalize({optionId:e.id,label:e.label}));break}default:break}return}let s=applyLineEditorKey(u,a,{multiline:!0});if(s!==void 0){u=s,this.#We(),repaintStatus();return}switch(a.type){case`up`:case`down`:{let e=movePromptLine(u,a.type);e!==void 0&&(u=e,this.#We(),repaintStatus());break}case`enter`:{let n=resolveQuestionText(u.text,e);if(n===void 0)break;t(finalize(n));break}case`escape`:if(r){if(u.text.length>0){u=EMPTY_LINE,this.#We(),repaintStatus();break}c=`select`,u=EMPTY_LINE,this.#k=!1,this.#Ue(),repaintStatus();break}u=EMPTY_LINE,this.#We(),repaintStatus();break;default:break}},this.#Fe()})}upsertSubagentStep(e){if(this.#o===`hidden`)return;let t=stripTerminalControls(e.reasoning??``).trim(),n=stripTerminalControls(e.message??``).trim();if(!(t.length===0&&n.length===0)){if(this.#Qe(e.callId,e.subagentName),this.#o===`collapsed`){this.#ut();return}this.#$e({id:subagentStepSectionId(e.callId,e.sectionKey),kind:`subagent-step`,depth:1,reasoning:t,body:n,live:!e.finalized}),this.#ut()}}upsertSubagentTool(e){if(this.#o===`hidden`)return;if(this.#Qe(e.callId,e.subagentName),this.#o===`collapsed`){this.#ut();return}let t=subagentToolStatus(e.status),n={id:subagentToolSectionId(e.callId,e.childCallId),kind:`subagent-tool`,depth:1,title:stripTerminalControls(e.toolName),subtitle:summarizeToolArgs(e.input),status:t,live:t===`running`||t===`approval`,expanded:this.#o===`full`,toolInput:e.input};e.output===void 0?e.errorText!==void 0&&(n.result=stripTerminalControls(e.errorText)):(n.result=summarizeToolResult(e.output),n.toolOutput=e.output),this.#$e(n),this.#ut()}markChildToolCallId(e){this.#g.add(e);let t=this.#_.get(e);t!==void 0&&(this.#et(t),this.#_.delete(e),this.#ut())}#me(e){let t=this.#p.get(toolSectionId(e));t!==void 0&&(t.status=`denied`,t.live=!1)}upsertConnectionAuth(e){if(this.#s===`hidden`)return;let t=e.state===`authorized`||e.state===`declined`||e.state===`failed`||e.state===`timed-out`;this.#$e({id:connectionAuthSectionId(e.name),kind:`connection-auth`,title:`${stripTerminalControls(e.name)} · authorization · ${e.state}`,body:formatConnectionAuthContent(e),preformatted:!0,live:!t}),this.#ut()}setConnectionAuthPendingCount(e){let t=Math.max(0,e);if(t===this.#w)return;let n=this.#w>0;this.#w=t,t>0?(this.#M=STATUS.connectionAuth,this.#ut()):n&&(this.#M=STATUS.processing,this.#ut())}setVercelStatus(e){this.#T=e,this.#ut()}reset(){this.#f=[],this.#p.clear(),this.#m.clear(),this.#C=void 0,this.#S.length=0,this.#h.length=0,this.#b=!1,this.#x=void 0,this.#g.clear(),this.#_.clear(),this.#v.clear(),this.#ce=void 0,this.#oe=void 0,this.#w=0,this.#X=void 0,this.#Z=void 0,this.#$=void 0,this.#ee=void 0,this.#te=void 0,this.#P&&(this.#n.clearAll(),this.#ut())}renderNotice(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#Ne(),this.#Je({kind:`notice`,body:t,live:!1}),this.#ut())}renderSandboxLog(e){let t=parseSandboxLogLine(stripTerminalControls(e));t!==void 0&&(this.#Ne(),this.#Je({kind:`sandbox`,body:t,live:!1}),this.#ut())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#he();return}this.#Ne(),this.#ue=t,this.#ut()}clearSetupWarning(){this.#he()}#he(){this.#ue!==void 0&&(this.#ue=void 0,this.#ut())}renderCommandResult(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#Ne(),this.#Je({kind:`result`,body:t,live:!1}),this.#ut())}#ge(e,t=`spinner`){this.#Ne(),this.#k=!1,this.#j={kind:`idle`},this.#M=``;let n=t===`pulse`?{kind:`pulse`,startedAtMs:Date.now()}:{kind:`spinner`};this.#le={title:stripTerminalControls(e),indicator:n,lines:[],outputBuffer:[]},this.#Ge(),this.#ut()}#_e(e){this.#de=void 0,this.#ke();let t=this.#le;if(t!==void 0){if(this.#le=void 0,this.#qe(),e){let e=[];for(let n of t.lines){if(n.evidence===!0){e.push(n.text);continue}(n.tone===`warning`||n.tone===`error`)&&(e.length>0&&this.#Je({kind:`flow`,title:`info`,body:e.join(`
|
|
3
|
+
`),live:!1}),this.#Je({kind:`flow`,title:n.tone,body:n.text,live:!1})),e=[]}}this.#ut()}}async#ve(e){let t=this.#Ce(),n=isMultiSelectRequest(e),r=e.kind===`search`?e.searchAction:void 0,i=e.options,a={options:i,searchAction:r,submitRow:n};`initialValue`in e&&e.initialValue!==void 0&&(a.defaultValue=e.initialValue),`initialValues`in e&&e.initialValues!==void 0&&(a.initialValues=e.initialValues);let o=initialSelectState(a),s,c=!1,l=0,isCurrentSearch=e=>e===l,clearSearch=()=>{l+=1,c=!1,o=reduceSelect(o,{type:`clear`},{options:i,searchAction:r,submitRow:n}),this.#ut()},loadSearch=async(e,t)=>{c=!0,s=void 0;let a=++l;this.#ut();try{let s=await t(e);if(!isCurrentSearch(a))return;let c=o.filter;i=s,o={...initialSelectState({options:s,searchAction:r,submitRow:n}),filter:c}}catch(e){isCurrentSearch(a)&&(s=toErrorMessage(e))}finally{isCurrentSearch(a)&&(c=!1,this.#ut())}},u=e.notices;if(e.kind===`task-list`){let n=t.taskListLineStart??t.lines.length,r=t.lines.slice(n).filter(e=>e.tone===`success`||e.tone===`warning`||e.tone===`error`).map(e=>({tone:e.tone,text:e.text}));u=[...e.notices??[],...r],t.taskListLineStart=t.lines.length,t.hideLinesWhileQuestion=!0}let panelState=()=>{let t={...e,options:i,select:o};return u!==void 0&&u.length>0&&(t.notices=u),s!==void 0&&(t.error=s),c&&(t.loadingFrame=this.#_t()),t};return t.question=e=>renderSelectQuestion(panelState(),this.#r,e),this.#ut(),await this.#Ee((t,a)=>{let close=e=>{l+=1,a(e)};if(c){t.type===`ctrl-c`?close(void 0):t.type===`escape`?clearSearch():t.type===`ctrl-r`&&this.#ut();return}let u={key:t,options:i,searchAction:r,select:o},d=reduceSetupSelectInput(n?{...u,kind:e.kind,required:e.required}:{...u,kind:e.kind});switch(d.kind){case`cancel`:close(void 0);return;case`repaint`:this.#ut();return;case`update`:o=d.select,s=void 0,this.#ut();return;case`submit`:{let e=searchActionQuery(d.values[0]??``),t=r?.load;if(e===void 0||t===void 0){close(d.values);return}loadSearch(e,t);return}case`error`:s=d.message,this.#ut();return;case`ignore`:return}}).promise}#ye(e){this.#Ne();let t=this.#we();t.status=e.status;let n;t.question=t=>renderSelectQuestion({kind:`actions`,context:e.context,actions:e.actions,cursor:n},this.#r,t),this.#ut();let r=this.#Ee((t,r)=>{let i=setupSelectionIntent(t);switch(i?.kind){case`cancel`:r(void 0);return;case`move`:n=moveActionCursor(n,i.direction,e.actions.length),this.#ut();return;case`repaint`:this.#ut();return;case`submit`:n!==void 0&&r(e.actions[n].value);return;case void 0:return}},()=>{t.status=void 0});return{choice:r.promise,close:()=>r.settle(void 0)}}async#be(e){let t=this.#Ce(),n={options:e.options};e.initialValue!==void 0&&(n.defaultValue=e.initialValue);let r=initialSelectState(n),i=lineOf(``),a;t.question=t=>{let n={kind:`editable`,message:e.message,options:e.options,select:r,edit:{optionValue:e.editable.value,editor:i,defaultValue:e.editable.defaultValue,formatHint:e.editable.formatHint,caretVisible:this.#I}};return a!==void 0&&(n.error=a),renderSelectQuestion(n,this.#r,t)};let onEditableRow=()=>selectValueAtCursor([...e.options],r.cursor)===e.editable.value,syncEditableRow=()=>{onEditableRow()?(i.text.length===0&&(i=lineOf(e.editable.defaultValue)),this.#He()):(i=lineOf(``),this.#Ue())};return syncEditableRow(),this.#ut(),await this.#Ee((t,n)=>{let applyEditor=e=>{i=e,a=void 0,this.#We(),this.#ut()},applySelect=t=>{r=reduceSelect(r,t,{options:e.options}),a=void 0,syncEditableRow(),this.#ut()},submit=()=>{let t=selectValueAtCursor([...e.options],r.cursor);if(t===void 0)return;if(t!==e.editable.value){n({kind:`selected`,value:t});return}let o=(i.text||e.editable.defaultValue).trim(),s=e.editable.validate?.(o);if(s!==void 0){a=s,this.#ut();return}n(o===e.editable.defaultValue?{kind:`selected`,value:t}:{kind:`edited`,value:t,text:o})},o=setupSelectionIntent(t);switch(o?.kind){case`cancel`:n(void 0);return;case`move`:applySelect({type:o.direction});return;case`submit`:submit();return;case`repaint`:this.#ut();return;case void 0:break}if(!onEditableRow())return;let s=applyLineEditorKey(i,t);s!==void 0&&applyEditor(s)},()=>this.#Ue()).promise}async#xe(e){let t=this.#Ce(),n=lineOf(``),r;return t.question=t=>{let i={message:e.message,editor:n,mask:e.mask===!0};return e.placeholder!==void 0&&(i.placeholder=e.placeholder),e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#r,t,this.#I)},this.#He(),this.#ut(),await this.#Ee((t,i)=>{let apply=e=>{n=e,r=void 0,this.#We(),this.#ut()},a=applyLineEditorKey(n,t);if(a!==void 0){apply(a);return}switch(t.type){case`ctrl-c`:case`escape`:i(void 0);return;case`ctrl-r`:this.#ut();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#ut();return}i(t);return}default:return}},()=>this.#Ue()).promise}async#Se(e){let t=this.#Ce();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#r,t),this.#ut(),await this.#Ee((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#ut();return;default:return}}).promise}#Ce(){return this.#Ne(),this.#k=!1,this.#j={kind:`idle`},this.#M=``,this.#we()}#we(){return this.#le===void 0&&(this.#le={title:``,indicator:{kind:`spinner`},lines:[],outputBuffer:[]}),this.#le}#Te(){this.#le!==void 0&&(this.#le.question=void 0,this.#le.hideLinesWhileQuestion=!1),this.#H=void 0,this.#Ie(),this.#Oe(),this.#ut()}#Ee(e,t){let n=!1,r,i=new Promise(e=>{r=e}),settle=e=>{n||(n=!0,t?.(),this.#Te(),r(e))};return this.#H=t=>e(t,settle),this.#Fe(),{promise:i,settle}}#De(){let e,t=new Promise(t=>{e=t});return this.#de=e,this.#Oe(),{promise:t,dispose:()=>{this.#de===e&&(this.#de=void 0,this.#ke())}}}#Oe(){if(this.#de===void 0)return;let consumer=e=>{if(e.type===`ctrl-c`||e.type===`escape`){let e=this.#de;this.#de=void 0,this.#ke(),e?.();return}e.type===`ctrl-r`&&this.#ut()};this.#fe=consumer,this.#H=consumer,this.#Fe()}#ke(){this.#fe!==void 0&&(this.#H===this.#fe&&this.#Ie(),this.#fe=void 0)}#Ae(e){let t=e===void 0?void 0:stripTerminalControls(e);if(this.#le!==void 0){this.#le.status=t,t===void 0&&(this.#le.preview=void 0),this.#ut();return}if(t===void 0){this.#j={kind:`idle`},this.#M=``,this.#qe(),this.#ut();return}this.#Ne(),this.#Ke(),this.#M=t,this.#ut()}#je(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#le;if(r!==void 0){if(r.preview=void 0,t===`warning`||t===`error`)for(let e of r.outputBuffer)r.lines.push({text:e,tone:`info`,evidence:!0});r.outputBuffer=[],r.lines.push({text:n,tone:t}),this.#ut();return}this.#Ne(),this.#Je({kind:`flow`,title:t,body:n,live:!1}),this.#ut()}#Me(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#le;if(n===void 0){this.#je(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#ut()}shutdown(){this.#Pe()}#Ne(e){this.#N=e?.title??this.#N,this.#Q=e?.contextSize??this.#l,!this.#P&&(this.#P=!0,this.#n.reset(),this.#n.hideCursor(),this.#Tt(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#K=()=>this.#ut(),this.#t.on(`resize`,this.#K))}#Pe(){this.#Ie(),this.#Ue(),this.#qe(),this.#B!==void 0&&(clearTimeout(this.#B),this.#B=void 0),this.#V=!1,this.#P&&=(this.#Nt(),this.#ut(),this.#n.clear(),this.#n.showCursor(),this.#Et(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#K&&=(this.#t.off(`resize`,this.#K),void 0),!1)}#Fe(){this.#e.off(`data`,this.#Le),this.#e.on(`data`,this.#Le)}#Ie(){this.#e.off(`data`,this.#Le),this.#Be(),this.#U=``,this.#W=new StringDecoder(`utf8`),this.#H=void 0}#Le=e=>{this.#Be(),this.#U+=this.#W.write(e),this.#ze(),this.#Re()};#Re(){if(this.#U===`\x1B`){this.#G=setTimeout(()=>{this.#U===`\x1B`&&(this.#U=``,this.#H?.({type:`escape`}))},30),this.#G.unref?.();return}if(isIncompletePaste(this.#U)){let e=this.#U;this.#G=setTimeout(()=>{if(this.#U!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#U=``,t.length>0&&this.#H?.({type:`text`,value:t,framing:`bracketed-paste`})},1e3),this.#G.unref?.()}}#ze(){for(;this.#U.length>0;){let e=nextKey(this.#U);if(e.incomplete)return;this.#U=this.#U.slice(e.consumed),e.key&&e.key.type!==`ignore`&&this.#H?.(e.key)}}#Be(){this.#G&&=(clearTimeout(this.#G),void 0)}#Ve(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#ut();break;case`ctrl-c`:this.#F||(this.#F=!0,this.#j={kind:`idle`},this.#M=`Interrupted`,this.#q?.(),this.#ut());break;default:break}}#He(){this.#Ue(),this.#We(),this.#R=setInterval(()=>{this.#I=!this.#I,this.#ut()},500),this.#R.unref?.()}#Ue(){this.#R&&=(clearInterval(this.#R),void 0),this.#I=!0}#We(){this.#I=!0}#Ge(){this.#qe(),this.#z=setInterval(()=>{this.#L+=1,this.#ut()},90),this.#z.unref?.()}#Ke(){this.#j={kind:`waiting`,startedAtMs:Date.now()},this.#Ge()}#qe(){this.#z&&=(clearInterval(this.#z),void 0)}#Je(e){e.id!==this.#oe?.id&&this.#Nt(),this.#f.push(e),e.id&&this.#p.set(e.id,e)}#Ye(e){this.#Je({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#ut()}#Xe(e){if(e!=null){if(this.#ce===e){this.#ce=void 0;return}this.#Je({kind:`user`,body:stripTerminalControls(e),live:!1})}}#Ze(e,t,n){let r={kind:`error`,title:stripTerminalControls(e),body:stripTerminalControls(t),live:!1};n!==void 0&&(r.detail=stripTerminalControls(n)),this.#Je(r),this.#ut()}#Qe(e,t){this.#v.has(e)||(this.#v.add(e),this.#Je({id:subagentHeaderId(e),kind:`subagent`,title:stripTerminalControls(t),live:!1}))}#$e(e){if(e.id&&this.#m.has(e.id))return;let t=e.id?this.#p.get(e.id):void 0;if(t){Object.assign(t,e);return}this.#Je(e)}#et(e){this.#f=this.#f.filter(t=>t.id!==e),this.#p.delete(e)}#tt(){for(let e of this.#f)e.status===`approval`||e.status===`running`||(e.live=!1)}#nt(e,t,n){switch(e.type){case`step-start`:this.#rt(n.hasPendingToolResults?STATUS.toolResults:STATUS.processing),n.hasPendingToolResults=!1;break;case`step-finish`:this.#lt(e.usage),this.#ut();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);this.#it(t),this.#rt(STATUS.streaming),n.text.set(e.id,t),this.#at(e.id,t,!0);break}case`assistant-complete`:{let t=n.text.get(e.id)??``,r=e.text!==void 0&&t.length===0?stripTerminalControls(e.text??``):t;this.#it(r),n.text.set(e.id,r),this.#at(e.id,r,!1);break}case`reasoning-delta`:{if(t.reasoning===`hidden`)break;let r=(n.reasoning.get(e.id)??``)+stripTerminalControls(e.delta);this.#it(r),this.#rt(STATUS.streaming),n.reasoning.set(e.id,r),this.#ot(e.id,r,!0,t);break}case`reasoning-complete`:{if(t.reasoning===`hidden`)break;let r=n.reasoning.get(e.id)??``;this.#it(r),this.#ot(e.id,r,!1,t);break}case`tool-call`:if(t.tools===`hidden`)break;this.#rt(STATUS.executingTools),this.#st({input:e.input,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-approval-request`:{if(t.tools===`hidden`)break;let r=n.tools.get(e.toolCallId);if(r===void 0)break;this.#st({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#ct(e.toolCallId,n);if(r===void 0)break;n.hasPendingToolResults=!0,this.#rt(STATUS.toolResults),this.#st({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{if(t.tools===`hidden`)break;let r=this.#ct(e.toolCallId,n);if(r===void 0)break;n.hasPendingToolResults=!0,this.#rt(STATUS.toolResults),this.#st({...r,errorText:e.errorText,status:`error`},t,n);break}case`error`:this.#Ze(`Error`,e.errorText,e.detail);break;case`finish`:this.#lt(e.usage),this.#ut();break}}#rt(e){let t=this.#w>0?STATUS.connectionAuth:e;this.#M!==t&&(this.#M=t,this.#ut())}#it(e){e.trim().length>0&&(this.#j={kind:`answering`})}#at(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#$e({id:e,kind:`assistant`,body:r,live:n}),this.#ut())}#ot(e,t,n,r){let a=stripTerminalControls(t).trim();a.length!==0&&(this.#$e({id:e,kind:`reasoning`,body:a,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#ut())}#st(e,t,n){if(n.tools.set(e.toolCallId,e),this.#g.has(e.toolCallId))return;let r=toolSectionId(e.toolCallId);this.#_.set(e.toolCallId,r),this.#$e(renderNativeToolBlock(e,r,t.tools===`full`)),this.#ut()}#ct(e,t){let n=t.tools.get(e);if(n!==void 0)return n;let r=this.#_.get(e)??toolSectionId(e),i=this.#p.get(r);if(!(i===void 0||i.kind!==`tool`))return{errorText:i.status===`error`&&typeof i.result==`string`?i.result:void 0,input:i.toolInput,output:i.toolOutput,status:i.status??`running`,toolCallId:e,toolName:i.title??`tool`}}#lt(e){if(e===void 0)return;let{inputTokens:t,outputTokens:n}=e;if((t!=null||n!=null)&&(this.#X=(t??0)+(n??0)),this.#Z=t??this.#Z,this.#$=n??this.#$,this.#$!=null&&this.#te!==void 0){let e=(Date.now()-this.#te)/1e3;e>0&&(this.#ee=this.#$/e)}}#ut(){if(this.#P){if(this.#J){this.#Y=!0;return}this.#J=!0;try{do this.#Y=!1,this.#dt();while(this.#Y)}finally{this.#J=!1}}}#dt(){if(!this.#P)return;let e=this.#Ct(),t=this.#bt(e),n=Math.max(1,this.#wt()-t.length),r=[],i=this.#C;for(;this.#f.length>0&&this.#f[0].live===!1;){let t=this.#f.shift();if(this.#h.push(t),t.id&&(this.#m.add(t.id),this.#p.delete(t.id)),this.#Ft(t))continue;let n=this.#gt(t,e,i);i=previousBlockOf(t),this.#C=i,r.push(...n),this.#S.push(...n)}let a=[];for(let t of this.#f){if(this.#Ft(t))continue;let n=this.#gt(t,e,i);i=previousBlockOf(t);for(let e=0;e<n.length;e+=1)a.push({block:t,row:n[e]})}let o=[...clipLiveRows(a.map(e=>e.row),n,e,this.#r),...t];r.length>0?this.#n.flush(r,o):this.#n.update(o)}#ft(){if(!this.#P)return;let e=this.#Ct(),t=this.#bt(e),n=Math.max(1,this.#wt()-t.length),r=this.#C,i=[];for(let t of this.#f){if(this.#Ft(t))continue;let n=this.#gt(t,e,r);r=previousBlockOf(t),i.push(...n)}let a=[...clipLiveRows(i,n,e,this.#r),...t];this.#n.clearAll(),this.#n.flush([...this.#ht(),...this.#S],a)}logDisplayMode(){return this.#d}setLogDisplayMode(e){e!==this.#d&&(this.#d=e,e===`all`&&this.flushDelayedDevBuildErrors(),this.#mt(),this.#P&&this.#ft())}flushDelayedDevBuildErrors(){let e=this.#ae;e!==void 0&&(this.#ae=void 0,this.#Je({kind:`log`,title:`stderr`,body:e,live:!1}),this.#ut())}#pt(){this.#V=!0,this.#B!==void 0&&clearTimeout(this.#B),this.#B=setTimeout(()=>{this.#V=!1,this.#B=void 0,this.#ut()},5e3),this.setLogDisplayMode(nextLogDisplayMode(this.#d)),this.#ut()}#mt(){let e=this.#Ct();this.#S.length=0;let t;for(let n of this.#h){if(this.#Ft(n))continue;let r=this.#gt(n,e,t);t=previousBlockOf(n),this.#S.push(...r)}this.#C=t}#ht(){let e=this.#y;if(e===void 0)return[];let t={name:e.name,theme:this.#r,width:this.#Ct()};return e.info!==void 0&&(t.info=e.info),e.tip!==void 0&&(t.tip=e.tip),buildAgentHeader(t)}#gt(e,t,n){let r={spinner:this.#_t()};n!==void 0&&(r.previous=n);let i=renderBlockLines(e,t,this.#r,r);return(e.depth??0)===0&&leadsWithGap(e,n)?[``,...i]:i}#_t(){return this.#r.spinner[this.#L%this.#r.spinner.length]??``}#vt(e,t){return isProgressPulseVisible(Date.now()-e)?t:` `}#yt(e){return e.indicator.kind===`spinner`?{glyph:this.#_t(),color:`yellow`}:{glyph:this.#vt(e.indicator.startedAtMs,this.#r.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),color:`green`}}#bt(e){let t=this.#r.colors,n=[``],r=this.#le;if(r!==void 0){let t=this.#yt(r),i;if(r.question!==void 0){let n=r.question(e);i={kind:`question`,rows:n},r.status!==void 0&&(i={kind:`question`,rows:n,status:{text:r.status,indicator:t}})}else r.status===void 0?i=r.preview===void 0?{kind:`idle`,indicator:t}:{kind:`preview`,text:r.preview,indicator:t}:(i={kind:`status`,status:{text:r.status,indicator:t}},r.preview!==void 0&&(i={kind:`status`,status:{text:r.status,indicator:t},preview:r.preview}));let a={title:r.title,lines:r.hideLinesWhileQuestion===!0?[]:r.lines,content:i};return n.push(...renderFlowPanel(a,this.#r,e)),n}if(this.#ue!==void 0&&n.push(...renderAttentionRows(this.#ue,e,this.#r),``),this.#k){let r=this.#A===void 0?void 0:inlineCommandHint(this.#A);r===void 0&&this.#A!==void 0&&isTypeaheadOpen(this.#A)&&n.push(...renderCommandSuggestions(this.#A,this.#r,e));let i=isPromptControlCommand(this.#E),a=r?t.dim(` ${r}`):``,o=[];this.#xt(o,e);let s=Math.max(1,this.#wt()-1-n.length-1-o.length);return n.push(...promptInputRows({text:this.#E,cursor:this.#D,width:e,theme:this.#r,caretVisible:this.#I,isCommand:i,ghost:a,maxRows:s})),n.push(...o),n}let i=this.#j;if(i.kind===`answering`)return this.#xt(n,e),n;let a=i.kind===`waiting`,o=a?t.green(this.#vt(i.startedAtMs,this.#r.unicode?`⊙`:`o`)):t.dim(this.#r.glyph.dot),s=this.#M.length>0?this.#M:`Ready`,c=a?t.dim(s):s,u=this.#St(),f=a?` `:``,p=u?`${f}${o} ${c} ${t.dim(this.#r.glyph.dot)} ${u}`:`${f}${o} ${c}`;n.push(clip(p,e));let g=[];return this.#xt(g,e),a&&g.length>0&&n.push(``),n.push(...g),n}#xt(e,t){let n={theme:this.#r,width:t};this.#V&&(n.logLevel=this.#d);let r=this.#y?.info?.agent.model.id;r!==void 0&&(n.model=r);let i=this.#y?.info?.agent.model.endpoint;i!==void 0&&(n.endpoint=i);let a=this.#Z??0,o=this.#$??0;if(a>0||o>0){let e={inputTokens:a,outputTokens:o};this.#Q!==void 0&&(e.contextSize=this.#Q),n.tokens=formatTokenFlow(e,this.#r.glyph)}this.#T!==void 0&&(n.vercel=this.#T);let s=buildStatusLine(n);s!==void 0&&e.push(s)}#St(){let e=this.#r.colors,t=[],n=formatAssistantResponseStats({totalTokens:this.#X,outputTokens:this.#$,tokensPerSecond:this.#ee},this.#c);return n&&t.push(n),t.length>0?e.dim(t.join(` ${this.#r.glyph.dot} `)):``}#Ct(){return Math.max(20,this.#t.columns||80)}#wt(){return Math.max(8,this.#t.rows||24)}#Tt(){if(this.#ne!==void 0||!this.#u)return;this.#re=``,this.#ie=``;let capture=(e,t)=>{let n=e.write.bind(e);return e.write=((e,n,r)=>{let i=typeof n==`string`?n:void 0,a=typeof n==`function`?n:r;return this.#Dt(t,chunkToString(e,i)),a?.(),!0}),()=>{e.write=n}},e=capture(process.stdout,`stdout`),t=capture(process.stderr,`stderr`);this.#ne=()=>{e(),t()}}#Et(){let e=this.#ne;e!==void 0&&(this.#ne=void 0,e(),this.#re.length>0&&(this.#Pt(`stdout`)&&process.stdout.write(`${this.#re}\n`),this.#re=``),this.#ie.length>0&&(this.#Pt(`stderr`)&&process.stderr.write(`${this.#ie}\n`),this.#ie=``))}#Dt(e,t){let n=(e===`stdout`?this.#re:this.#ie)+t,i=n.lastIndexOf(`
|
|
4
|
+
`),a=i===-1?n:n.slice(i+1);if(e===`stdout`?this.#re=a:this.#ie=a,i===-1)return;let o=stripAnsi(n.slice(0,i)).replace(/\s+$/u,``);o.trim().length!==0&&(e===`stdout`?this.#Ot(o):this.#kt(o),this.#ut())}#Ot(e){let t=[],flushPending=()=>{if(t.length===0)return;let e=t.join(`
|
|
5
|
+
`);t=[],e.trim().length!==0&&this.#Je({kind:`log`,title:`stdout`,body:e,live:!1})};for(let n of e.split(`
|
|
6
|
+
`)){let e=parseSandboxLogLine(n.trimEnd());if(e!==void 0){flushPending(),this.#Je({kind:`sandbox`,body:e,live:!1});continue}let r=parseDevRebuildLogLine(n.trimEnd());if(r===void 0){t.push(n);continue}flushPending(),this.#jt(r,n.trimEnd())}flushPending()}#kt(e){let t=e.split(`
|
|
7
|
+
`),n=t.findIndex(e=>parseDevRebuildLogLine(e.trimEnd())?.kind===`failed`);if(n===-1){this.#Je({kind:`log`,title:`stderr`,body:e,live:!1});return}let r=t.slice(0,n).join(`
|
|
8
|
+
`);r.trim().length>0&&this.#Je({kind:`log`,title:`stderr`,body:r,live:!1});let i=t.slice(n).join(`
|
|
9
|
+
`);this.#At(i)}#At(e){if(this.#d===`all`){if(e.trim().length===0)return;this.#Je({kind:`log`,title:`stderr`,body:e,live:!1});return}this.#ae=e}#jt(e,t){let n=this.#Mt();if(e.kind===`failed`){this.#At(t);return}if(e.kind===`rebuilding`){let t=summarizeChangedFiles(e.events,e.more);if(n!==void 0){n.state.summary=t,n.block.body=formatDevRebuildStatus(t,`rebuilding`);return}let r=`dev-rebuild:${this.#se}`;this.#se+=1,this.#oe={id:r,summary:t},this.#Je({kind:`log`,id:r,title:`stdout`,body:formatDevRebuildStatus(t,`rebuilding`),live:!0});return}if(n!==void 0){n.block.body=formatDevRebuildStatus(n.state.summary,e.kind),e.kind===`rebuilt`&&(this.#ae=void 0);return}e.kind===`rebuilt`&&(this.#ae=void 0),this.#Je({kind:`log`,title:`stdout`,body:t,live:!1})}#Mt(){let e=this.#oe;if(e===void 0)return;let t=this.#p.get(e.id);if(!(t===void 0||t.live!==!0))return{state:e,block:t}}#Nt(){let e=this.#oe;if(e===void 0)return;this.#oe=void 0;let t=this.#p.get(e.id);t!==void 0&&(t.live=!1)}#Pt(e){switch(this.#d){case`none`:return!1;case`stderr`:return e===`stderr`;case`sandbox`:return e===`sandbox`;case`all`:return!0}}#Ft(e){return e.kind===`sandbox`?!this.#Pt(`sandbox`):e.kind===`log`?!this.#Pt(e.title===`stderr`?`stderr`:`stdout`):!1}};function chunkToString(e,t){return typeof e==`string`?e:Buffer.from(e).toString(t)}async function*iterateTUIStream(e){if(e instanceof ReadableStream){let t=e.getReader();try{for(;;){let{done:e,value:n}=await t.read();if(e)return;yield n}}finally{t.releaseLock()}return}yield*e}function clip(t,n){return clipVisible(t,n)}function promptInputRows({text:e,cursor:r,width:i,theme:a,caretVisible:o,isCommand:s,ghost:c,maxRows:l}){let u=a.colors,style=e=>{let n=renderInputText(e);return s&&n.length>0?u.blue(n):n},d=layoutPromptInput({text:e,cursor:r}),f=Math.min(Math.max(1,l),d.rows.length),p=Math.max(0,Math.min(d.caretRow-f+1,d.rows.length-f)),m=u.cyan(a.glyph.prompt),h=u.dim(a.glyph.ellipsis),g=Math.max(1,i-4),_=[];for(let e=p;e<p+f;e+=1){let t=d.rows[e],r=e===0?m:` `;(e===p&&p>0||e===p+f-1&&p+f<d.rows.length)&&(r=h);let s;if(e===d.caretRow){let{before:e,under:r,after:i}=visibleLine({text:t.text,cursor:d.caretOffset},g,a.glyph.ellipsis);s=renderInputWithBlockCursor({before:e,under:r,after:i,visible:o,inverse:u.inverse,render:style}),c.length>0&&d.rows.length===1&&(s+=c)}else s=style(t.text);_.push(clip(` ${r} ${s}`,i))}return _.push(``),_}function previousBlockOf(e){let t={kind:e.kind};return e.title!==void 0&&(t.title=e.title),t}function leadsWithGap(e,t){if(e.kind===`sandbox`&&t?.kind===`sandbox`)return!1;if(t?.kind===`sandbox`&&e.kind!==`sandbox`)return!0;if(e.kind===`log`&&t?.kind===`log`)return t.title!==e.title;if(t?.kind===`log`&&e.kind!==`log`)return!0;switch(e.kind){case`user`:case`assistant`:case`reasoning`:case`subagent`:case`error`:case`notice`:case`question`:case`connection-auth`:case`sandbox`:case`log`:case`command`:case`warning`:case`flow`:case`agent-header`:return!0;default:return!1}}function parseSandboxLogLine(e){let t=e.trim();if(!t.startsWith(`eve: `))return;let n=t.slice(5);return/\bsandbox\b/i.test(n)&&!isLowValueSandboxLogLine(n)?n:void 0}function isLowValueSandboxLogLine(e){return/^initializing (?:\d+ )?sandbox templates?\b/i.test(e)||/^initialized \d+ sandbox\b/i.test(e)||/^reused cached sandbox template\b/i.test(e)||/^sandbox template "[^"]+" \([^)]+\): (checking|reusing|loading microsandbox runtime|microsandbox runtime ready)\b/i.test(e)}function clipLiveRows(e,t,n,r){if(e.length<=t)return[...e];if(t<=1)return[clip(hiddenRowsMarker(e.length,r),n)];let i=t-1;return[clip(hiddenRowsMarker(e.length-i,r),n),...e.slice(e.length-i)]}function hiddenRowsMarker(e,t){let n=e.toLocaleString(),r=e===1?`row`:`rows`;return t.colors.dim(`${t.glyph.dot} ${t.glyph.ellipsis} ${n} earlier ${r} hidden while streaming`)}function collapseReasoning(e,t){switch(e){case`collapsed`:return!0;case`auto-collapsed`:return!t;default:return!1}}function renderNativeToolBlock(e,t,n){let r={id:t,kind:`tool`,title:stripTerminalControls(e.toolName),subtitle:summarizeToolArgs(e.input),status:e.status,live:e.status===`running`||e.status===`approval`,expanded:n,toolInput:e.input};return e.output===void 0?e.errorText!==void 0&&(r.result=stripTerminalControls(e.errorText)):(r.result=summarizeToolResult(e.output),r.toolOutput=e.output),r}function subagentToolStatus(e){switch(e){case`approval-requested`:return`approval`;case`executing`:return`running`;case`done`:return`done`;case`failed`:return`error`}}function formatToolApprovalTitle(e){return stripTerminalControls(e.title??e.toolName)}function toolSectionId(e){return`tool:${e}`}function questionSectionId(e){return`question:${e}`}function subagentHeaderId(e){return`subagent:${e}:header`}function subagentStepSectionId(e,t){return`subagent:${e}:step:${t}`}function subagentToolSectionId(e,t){return`subagent:${e}:tool:${t}`}function connectionAuthSectionId(e){return`connection-auth:${e}`}function formatConnectionAuthContent(e){let t=[],n=stripTerminalControls(e.description);n.length>0&&t.push(n);let r=e.challenge;if(r?.url&&t.push(`URL: ${stripTerminalControls(r.url)}`),r?.userCode&&t.push(`Code: ${stripTerminalControls(r.userCode)}`),r?.expiresAt&&t.push(`Expires: ${stripTerminalControls(r.expiresAt)}`),r?.instructions&&t.push(stripTerminalControls(r.instructions)),e.reason!==void 0){let n=stripTerminalControls(e.reason);n.length>0&&t.push(`Reason: ${n}`)}return t.join(`
|
|
10
|
+
`)}function formatQuestionContent(e,t,n){let r=n.colors,a=[],o=e.options??[];if(o.length>0){for(let[e,s]of o.entries()){let o=stripTerminalControls(s.label),c=s.description===void 0?``:stripTerminalControls(s.description),l=t===e,u=c.length>0?`${l?` `:` `}${r.dim(`— ${c}`)}`:``,d=renderCursorRow(l?`${n.glyph.selectedPointer} ${o}`:` ${o}`,l,r);a.push(`${d}${u}`)}if(e.allowFreeform===!0){let e=t===o.length,i=`Type your own answer`,s=e?`${n.glyph.selectedPointer} ${i}`:` ${r.dim(i)}`;a.push(renderCursorRow(s,e,r))}}else a.push(r.dim(` (type your answer)`));return a.join(`
|
|
11
11
|
`)}function resolveQuestionText(e,t){let n=e.trim();if(n.length===0)return;let r=n.toLowerCase(),i=t.options??[];if(i.length>0){let e=matchQuestionOption(r,i);if(e!==void 0)return{optionId:e.id,label:e.label}}if(t.allowFreeform===!0||i.length===0)return{text:n,label:n}}function matchQuestionOption(e,t){let n=t.find(t=>t.id.toLowerCase()===e);if(n!==void 0)return n;let r=t.find(t=>t.label.toLowerCase()===e);if(r!==void 0)return r;let i=Number(e);if(Number.isInteger(i)&&i>0&&i<=t.length)return t[i-1]}export{TerminalRenderer};
|
|
@@ -10,6 +10,16 @@ export declare function clipVisible(input: string, width: number): string;
|
|
|
10
10
|
export declare function inputTextWidth(input: string): number;
|
|
11
11
|
/** Expands editor tabs to the same fixed four cells used by {@link inputTextWidth}. */
|
|
12
12
|
export declare function renderInputText(input: string): string;
|
|
13
|
+
interface BlockCursorInput {
|
|
14
|
+
readonly before: string;
|
|
15
|
+
readonly under: string;
|
|
16
|
+
readonly after: string;
|
|
17
|
+
readonly visible: boolean;
|
|
18
|
+
readonly inverse: (text: string) => string;
|
|
19
|
+
readonly render?: (text: string) => string;
|
|
20
|
+
}
|
|
21
|
+
/** Renders a blinking block cursor without inserting or removing a terminal cell. */
|
|
22
|
+
export declare function renderInputWithBlockCursor(input: BlockCursorInput): string;
|
|
13
23
|
/**
|
|
14
24
|
* Returns the UTF-16 offset at or immediately before a terminal column.
|
|
15
25
|
* Graphemes stay intact even when the requested column falls inside a wide one.
|
|
@@ -22,3 +32,4 @@ export declare function offsetAtVisibleColumn(input: string, column: number): nu
|
|
|
22
32
|
*/
|
|
23
33
|
export declare function wrapVisibleLine(line: string, width: number): string[];
|
|
24
34
|
export declare function codePointWidth(codePoint: number): number;
|
|
35
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{graphemes}from"#shared/text-boundaries.js";const ansiPattern=RegExp(`\x1B\\[[0-?]*[ -/]*[@-~]`,`g`),ansiPrefixPattern=RegExp(`^\x1B\\[[0-?]*[ -/]*[@-~]`),emojiPresentationPattern=/\p{Emoji_Presentation}/u,extendedPictographicPattern=/\p{Extended_Pictographic}/u,keycapPattern=/^[#*0-9]\u{fe0f}?\u{20e3}$/u;function stripAnsi(e){return stripTerminalControls(e.replaceAll(ansiPattern,``))}function stripTerminalControls(e){let t=``,n=0;for(;n<e.length;){let r=e.codePointAt(n);if(r==null)break;let i=String.fromCodePoint(r);n+=i.length,!isUnsafeTerminalControlCodePoint(r)&&(t+=i)}return t}function visibleLength(e){let t=0;for(let n of terminalTextUnits(e))t+=n.width;return t}function sliceVisible(e,t){if(t<=0)return``;let n=``,r=0,i=terminalTextUnits(e),a=0;for(;a<i.length&&r<t;){let e=i[a];if(e.width>0&&r+e.width>t)break;n+=e.text,r+=e.width,a+=1}for(;i[a]?.ansi===!0;)n+=i[a].text,a+=1;return n}function clipVisible(e,t){if(visibleLength(e)<=t)return e;let n=sliceVisible(e,t);return n.includes(`\x1B`)?`${n}[0m`:n}function inputTextWidth(t){let n=0;for(let r of graphemes(t))n+=terminalGraphemeWidth(r.text);return n}function renderInputText(e){return e.replaceAll(` `,` `)}function offsetAtVisibleColumn(t,n){if(n<=0)return 0;let r=0;for(let i of graphemes(t)){let e=r+terminalGraphemeWidth(i.text);if(e>n)return i.start;if(e===n)return i.end;r=e}return t.length}function terminalGraphemeWidth(e){let t=0;for(let n of e){let e=n.codePointAt(0);e!==void 0&&(t=Math.max(t,codePointWidth(e)))}return emojiPresentationPattern.test(e)||keycapPattern.test(e)||e.includes(`️`)&&extendedPictographicPattern.test(e)?Math.max(2,t):t}function terminalTextUnits(r){let i=[],a=0;for(;a<r.length;){let o=r.slice(a),s=o.match(ansiPrefixPattern);if(s!==null){i.push({text:s[0],width:0,ansi:!0}),a+=s[0].length;continue}let c=o.search(ansiPattern),l=o.slice(0,c===-1?o.length:c);for(let t of graphemes(l))i.push({text:t.text,width:terminalGraphemeWidth(t.text),ansi:!1});a+=l.length}return i}function wrapVisibleLine(e,t){if(t<=0)return[e];if(e.length===0)return[``];let n=[],r=e;for(;visibleLength(r)>t;){let e=findVisibleBreakPoint(r,t);n.push(r.slice(0,e).trimEnd()),r=r.slice(e).trimStart()}return(r.length>0||n.length===0)&&n.push(r),n}function findVisibleBreakPoint(e,t){let n=sliceVisible(e,t+1).lastIndexOf(` `);if(n>0)return n;let r=sliceVisible(e,t);if(visibleLength(r)>0)return r.length;let i=0,a=!1;for(let t of terminalTextUnits(e)){if(a&&t.width>0)return i;i+=t.text.length,t.width>0&&(a=!0)}return i}function codePointWidth(e){return e===9?4:e<32||e>=127&&e<160||isZeroWidthCodePoint(e)?0:isWideCodePoint(e)?2:1}function isUnsafeTerminalControlCodePoint(e){return e>=0&&e<=8||e>=11&&e<=31||e>=127&&e<=159}function isZeroWidthCodePoint(e){return e>=768&&e<=879||e>=1155&&e<=1161||e>=1425&&e<=1469||e===1471||e>=1473&&e<=1474||e>=1476&&e<=1477||e===1479||e>=1552&&e<=1562||e>=1611&&e<=1631||e===1648||e>=1750&&e<=1756||e>=1759&&e<=1764||e>=1767&&e<=1768||e>=1770&&e<=1773||e===1809||e>=1840&&e<=1866||e>=1958&&e<=1968||e>=2027&&e<=2035||e>=2070&&e<=2073||e>=2075&&e<=2083||e>=2085&&e<=2087||e>=2089&&e<=2093||e>=2137&&e<=2139||e>=2259&&e<=2306||e===2362||e===2364||e>=2369&&e<=2376||e===2381||e>=2385&&e<=2391||e===8205||e>=65024&&e<=65039||e>=917760&&e<=917999}function isWideCodePoint(e){return e>=4352&&(e<=4447||e===9001||e===9002||e>=11904&&e<=42191&&e!==12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=127744&&e<=128591||e>=129280&&e<=129535||e>=131072&&e<=262141)}export{ansiPattern,ansiPrefixPattern,clipVisible,codePointWidth,inputTextWidth,offsetAtVisibleColumn,renderInputText,sliceVisible,stripAnsi,stripTerminalControls,visibleLength,wrapVisibleLine};
|
|
1
|
+
import{graphemes}from"#shared/text-boundaries.js";const ansiPattern=RegExp(`\x1B\\[[0-?]*[ -/]*[@-~]`,`g`),ansiPrefixPattern=RegExp(`^\x1B\\[[0-?]*[ -/]*[@-~]`),emojiPresentationPattern=/\p{Emoji_Presentation}/u,extendedPictographicPattern=/\p{Extended_Pictographic}/u,keycapPattern=/^[#*0-9]\u{fe0f}?\u{20e3}$/u;function stripAnsi(e){return stripTerminalControls(e.replaceAll(ansiPattern,``))}function stripTerminalControls(e){let t=``,n=0;for(;n<e.length;){let r=e.codePointAt(n);if(r==null)break;let i=String.fromCodePoint(r);n+=i.length,!isUnsafeTerminalControlCodePoint(r)&&(t+=i)}return t}function visibleLength(e){let t=0;for(let n of terminalTextUnits(e))t+=n.width;return t}function sliceVisible(e,t){if(t<=0)return``;let n=``,r=0,i=terminalTextUnits(e),a=0;for(;a<i.length&&r<t;){let e=i[a];if(e.width>0&&r+e.width>t)break;n+=e.text,r+=e.width,a+=1}for(;i[a]?.ansi===!0;)n+=i[a].text,a+=1;return n}function clipVisible(e,t){if(visibleLength(e)<=t)return e;let n=sliceVisible(e,t);return n.includes(`\x1B`)?`${n}[0m`:n}function inputTextWidth(t){let n=0;for(let r of graphemes(t))n+=terminalGraphemeWidth(r.text);return n}function renderInputText(e){return e.replaceAll(` `,` `)}function renderInputWithBlockCursor(e){let t=e.render??renderInputText,n=e.under.length>0?e.under:` `,r=e.visible?e.inverse(renderInputText(n)):t(n);return`${t(e.before)}${r}${t(e.after)}`}function offsetAtVisibleColumn(t,n){if(n<=0)return 0;let r=0;for(let i of graphemes(t)){let e=r+terminalGraphemeWidth(i.text);if(e>n)return i.start;if(e===n)return i.end;r=e}return t.length}function terminalGraphemeWidth(e){let t=0;for(let n of e){let e=n.codePointAt(0);e!==void 0&&(t=Math.max(t,codePointWidth(e)))}return emojiPresentationPattern.test(e)||keycapPattern.test(e)||e.includes(`️`)&&extendedPictographicPattern.test(e)?Math.max(2,t):t}function terminalTextUnits(r){let i=[],a=0;for(;a<r.length;){let o=r.slice(a),s=o.match(ansiPrefixPattern);if(s!==null){i.push({text:s[0],width:0,ansi:!0}),a+=s[0].length;continue}let c=o.search(ansiPattern),l=o.slice(0,c===-1?o.length:c);for(let t of graphemes(l))i.push({text:t.text,width:terminalGraphemeWidth(t.text),ansi:!1});a+=l.length}return i}function wrapVisibleLine(e,t){if(t<=0)return[e];if(e.length===0)return[``];let n=[],r=e;for(;visibleLength(r)>t;){let e=findVisibleBreakPoint(r,t);n.push(r.slice(0,e).trimEnd()),r=r.slice(e).trimStart()}return(r.length>0||n.length===0)&&n.push(r),n}function findVisibleBreakPoint(e,t){let n=sliceVisible(e,t+1).lastIndexOf(` `);if(n>0)return n;let r=sliceVisible(e,t);if(visibleLength(r)>0)return r.length;let i=0,a=!1;for(let t of terminalTextUnits(e)){if(a&&t.width>0)return i;i+=t.text.length,t.width>0&&(a=!0)}return i}function codePointWidth(e){return e===9?4:e<32||e>=127&&e<160||isZeroWidthCodePoint(e)?0:isWideCodePoint(e)?2:1}function isUnsafeTerminalControlCodePoint(e){return e>=0&&e<=8||e>=11&&e<=31||e>=127&&e<=159}function isZeroWidthCodePoint(e){return e>=768&&e<=879||e>=1155&&e<=1161||e>=1425&&e<=1469||e===1471||e>=1473&&e<=1474||e>=1476&&e<=1477||e===1479||e>=1552&&e<=1562||e>=1611&&e<=1631||e===1648||e>=1750&&e<=1756||e>=1759&&e<=1764||e>=1767&&e<=1768||e>=1770&&e<=1773||e===1809||e>=1840&&e<=1866||e>=1958&&e<=1968||e>=2027&&e<=2035||e>=2070&&e<=2073||e>=2075&&e<=2083||e>=2085&&e<=2087||e>=2089&&e<=2093||e>=2137&&e<=2139||e>=2259&&e<=2306||e===2362||e===2364||e>=2369&&e<=2376||e===2381||e>=2385&&e<=2391||e===8205||e>=65024&&e<=65039||e>=917760&&e<=917999}function isWideCodePoint(e){return e>=4352&&(e<=4447||e===9001||e===9002||e>=11904&&e<=42191&&e!==12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=127744&&e<=128591||e>=129280&&e<=129535||e>=131072&&e<=262141)}export{ansiPattern,ansiPrefixPattern,clipVisible,codePointWidth,inputTextWidth,offsetAtVisibleColumn,renderInputText,renderInputWithBlockCursor,sliceVisible,stripAnsi,stripTerminalControls,visibleLength,wrapVisibleLine};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WizardCancelledError}from"#setup/step.js";import{createSelectOptionCodec}from"#setup/cli/select-option-codec.js";function setupSelectRequest(e,t,n){let
|
|
1
|
+
import{WizardCancelledError}from"#setup/step.js";import{searchActionQuery}from"#setup/cli/select-state.js";import{createSelectOptionCodec}from"#setup/cli/select-option-codec.js";function setupSelectRequest(e,t,n,r){let i={message:e.message,options:t},withNotices=t=>(e.notices!==void 0&&(t.notices=e.notices),t);if(e.multiple===!0){if(e.hintLayout!==void 0)throw Error(`Multi-select setup questions do not support a hint layout.`);let t;return e.search===!0?(t={...i,kind:`searchable-multi`,required:e.required??!1},e.placeholder!==void 0&&(t.placeholder=e.placeholder)):t={...i,kind:`multi`,required:e.required??!1},e.initialValues!==void 0&&(t.initialValues=e.initialValues.map(n)),withNotices(t)}if(e.search===!0&&e.hintLayout!==void 0)throw Error(`Searchable setup questions do not support a hint layout.`);let a;if(e.search===!0){if(a={...i,kind:`search`},e.placeholder!==void 0&&(a.placeholder=e.placeholder),e.searchAction!==void 0){a.searchAction={label:e.searchAction.label};let t=e.searchAction.load;t!==void 0&&(a.searchAction.load=async e=>r(await t(e)))}}else{let t=e.hintLayout===`inline`?`task-list`:e.hintLayout??`single`;a={...i,kind:t}}return e.initialValue!==void 0&&(a.initialValue=n(e.initialValue)),withNotices(a)}function createTuiPrompter(r){function guardCancel(t){if(t===void 0)throw new WizardCancelledError;return t}async function select(e){let i=createSelectOptionCodec(e.options),a=setupSelectRequest(e,i.options,i.encode,i.encodeOptions),o=guardCancel(await r.readSelect(a)).map(n=>{let r=searchActionQuery(n);return r!==void 0&&e.multiple!==!0&&e.searchAction!==void 0?e.searchAction.value(r):i.decode(n)});if(e.multiple===!0)return o;let s=o[0];if(s===void 0)throw Error(`Single-select returned no option.`);return s}function line(e){return t=>r.renderLine(t,e)}return{async text(e){let t={message:e.message};return e.placeholder!==void 0&&(t.placeholder=e.placeholder),e.defaultValue!==void 0&&(t.defaultValue=e.defaultValue),e.validate!==void 0&&(t.validate=e.validate),e.notices!==void 0&&(t.notices=e.notices),guardCancel(await r.readText(t))},async password(e){let t={message:e.message,mask:!0};return e.validate!==void 0&&(t.validate=e.validate),guardCancel(await r.readText(t))},select,async selectEditable(e){let t=createSelectOptionCodec(e.options),i={value:t.encode(e.editable.value),defaultValue:e.editable.defaultValue,formatHint:e.editable.formatHint};e.editable.validate!==void 0&&(i.validate=e.editable.validate);let a={message:e.message,options:t.options,editable:i};e.initialValue!==void 0&&(a.initialValue=t.encode(e.initialValue));let o=guardCancel(await r.readEditableSelect(a)),s=t.decode(o.value);return o.kind===`edited`?{kind:`edited`,value:s,text:o.text}:{kind:`selected`,value:s}},async acknowledge(e){await r.readAcknowledge({message:e.message,lines:e.lines??[]})},awaitChoice(e){return r.readChoice(e)},note(e,t,n){let i=n?.tone===`success`?`success`:`warning`;t&&r.renderLine(t,i),r.renderLine(e,i)},intro(){},outro(){},log:{message:line(`info`),info:line(`info`),success:line(`success`),warning:line(`warning`),error:line(`error`),commandOutput:e=>r.renderOutput(e),section(e,t){r.renderLine(e,`info`);for(let e of t)r.renderLine(` ${e}`,`info`)},spinner(e){r.setStatus(e);let t=!1;return{stop(){t||(t=!0,r.setStatus(void 0))}}}}}}export{createTuiPrompter};
|
package/dist/src/cli/run.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ interface DevelopmentCliOptions {
|
|
|
21
21
|
url?: string;
|
|
22
22
|
}
|
|
23
23
|
interface CliRuntimeDependencies {
|
|
24
|
+
isCodingAgentLaunch(): Promise<boolean>;
|
|
24
25
|
buildHost(appRoot: string): Promise<string>;
|
|
25
26
|
printApplicationInfo(logger: CliLogger, appRoot: string, options?: {
|
|
26
27
|
json?: boolean;
|
package/dist/src/cli/run.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{createLogger}from"#internal/logging.js";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{createCliTheme,renderCliTaggedLine}from"#cli/ui/output.js";import{eveCliBanner}from"#cli/banner.js";import{startCliLiveRow}from"#cli/ui/live-row.js";import{devBootPhase}from"#internal/dev-boot-progress.js";import{Command,CommanderError,InvalidArgumentError}from"#compiled/commander/index.js";import{resolveApplicationRoot}from"#internal/application/paths.js";import{registerProjectCommands}from"#cli/commands/register-project-commands.js";import{LOG_DISPLAY_MODES,parseLogDisplayMode}from"#cli/dev/tui/log-display-mode.js";import{resolveTuiTitle}from"#cli/dev/tui/target.js";import{parseDevelopmentServerUrl}from"#cli/dev/url.js";const devBootLog=createLogger(`dev.boot`);function createDevBootProgressReporter(e){return t=>{switch(t.type){case`phase-started`:e?.update(`Building your agent`,t.phase),devBootLog.debug(t.phase);return;case`phase-finished`:devBootLog.debug(`${t.phase} finished`,{ms:t.elapsedMs});return;case`before-first-paint`:e?.stop();return;default:return t}}}async function loadBuildHost(){return(await import(`#internal/nitro/host.js`)).buildApplication}async function loadPrintApplicationInfo(){return(await import(`#cli/commands/info.js`)).printApplicationInfo}async function loadRunDevelopmentTui(){return(await import(`#cli/dev/tui/tui.js`)).runDevelopmentTui}async function loadRunEvalCommand(){return(await import(`#evals/cli/eval.js`)).runEvalCommand}async function loadStartHost(){return(await import(`#internal/nitro/host.js`)).startDevelopmentServer}async function loadStartProductionHost(){return(await import(`#internal/nitro/host.js`)).startProductionServer}function shouldPrintCliBootBanner(e){return e.name()===`info`||e.name()===`dev`||e.name()===`init`}async function waitForShutdownSignal(e){await new Promise((t,n)=>{let r=!1,cleanup=()=>{process.off(`SIGINT`,handleSignal),process.off(`SIGTERM`,handleSignal)},handleSignal=()=>{r||(r=!0,cleanup(),e.close().then(t,n))};process.once(`SIGINT`,handleSignal),process.once(`SIGTERM`,handleSignal)})}async function waitForProductionServer(e){await Promise.race([e.wait(),waitForShutdownSignal({close:()=>e.close()})])}function parsePortOption(e){if(!/^-?\d+$/.test(e))throw new InvalidArgumentError(`Expected a numeric port, received "${e}".`);let t=Number(e);if(t<0||t>65535)throw new InvalidArgumentError(`Expected a port between 0 and 65535, received "${e}".`);return t}const DISPLAY_MODES=new Set([`full`,`collapsed`,`auto-collapsed`,`hidden`]),STATS_MODES=new Set([`tokens`,`tokensPerSecond`]);function parseDisplayMode(e){if(!DISPLAY_MODES.has(e))throw new InvalidArgumentError(`Expected one of ${[...DISPLAY_MODES].join(`, `)}, received "${e}".`);return e}function parseStatsMode(e){if(!STATS_MODES.has(e))throw new InvalidArgumentError(`Expected one of ${[...STATS_MODES].join(`, `)}, received "${e}".`);return e}function parseLogsMode(e){let t=parseLogDisplayMode(e);if(t===void 0)throw new InvalidArgumentError(`Expected one of ${LOG_DISPLAY_MODES.join(`, `)}, received "${e}".`);return t}function parseContextSizeOption(e){let t=Number(e);if(!Number.isFinite(t)||t<=0)throw new InvalidArgumentError(`Expected a positive number, received "${e}".`);return t}function resolveDevUiMode(e){return e.options.ui===!1||!e.interactive?`headless`:`tui`}function resolveTuiDisplayOptions(e){let t={logs:e.logs??`stderr`,reasoning:e.reasoning??`full`,tools:e.tools??`auto-collapsed`};return e.subagents!==void 0&&(t.subagents=e.subagents),e.connectionAuth!==void 0&&(t.connectionAuth=e.connectionAuth),e.assistantResponseStats!==void 0&&(t.assistantResponseStats=e.assistantResponseStats),e.contextSize!==void 0&&(t.contextSize=e.contextSize),t}function hasInteractiveTerminal(){return!!(process.stdin.isTTY&&process.stdout.isTTY)}function rewriteDevelopmentUrlShorthand(e){let t=e[1];return e[0]!==`dev`||e.length!==2||t===void 0||t.startsWith(`-`)?[...e]:[`dev`,`--url`,t]}function resolveRemoteDevelopmentServerUrl(e){if(e.url){if(e.host!==void 0)throw new InvalidArgumentError(`The --host option cannot be used with --url.`);if(e.port!==void 0)throw new InvalidArgumentError(`The --port option cannot be used with --url.`);if(e.ui===!1)throw new InvalidArgumentError(`The --no-ui option cannot be used with --url.`);return e.url}}function createCliProgram(e,
|
|
1
|
+
import{createLogger}from"#internal/logging.js";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{createCliTheme,renderCliTaggedLine}from"#cli/ui/output.js";import{isCodingAgentLaunch}from"#cli/agent-detection.js";import{eveCliBanner}from"#cli/banner.js";import{startCliLiveRow}from"#cli/ui/live-row.js";import{devBootPhase}from"#internal/dev-boot-progress.js";import{Command,CommanderError,InvalidArgumentError}from"#compiled/commander/index.js";import{resolveApplicationRoot}from"#internal/application/paths.js";import{registerProjectCommands}from"#cli/commands/register-project-commands.js";import{LOG_DISPLAY_MODES,parseLogDisplayMode}from"#cli/dev/tui/log-display-mode.js";import{resolveTuiTitle}from"#cli/dev/tui/target.js";import{parseDevelopmentServerUrl}from"#cli/dev/url.js";const devBootLog=createLogger(`dev.boot`);function createDevBootProgressReporter(e){return t=>{switch(t.type){case`phase-started`:e?.update(`Building your agent`,t.phase),devBootLog.debug(t.phase);return;case`phase-finished`:devBootLog.debug(`${t.phase} finished`,{ms:t.elapsedMs});return;case`before-first-paint`:e?.stop();return;default:return t}}}async function loadBuildHost(){return(await import(`#internal/nitro/host.js`)).buildApplication}async function loadPrintApplicationInfo(){return(await import(`#cli/commands/info.js`)).printApplicationInfo}async function loadRunDevelopmentTui(){return(await import(`#cli/dev/tui/tui.js`)).runDevelopmentTui}async function loadRunEvalCommand(){return(await import(`#evals/cli/eval.js`)).runEvalCommand}async function loadStartHost(){return(await import(`#internal/nitro/host.js`)).startDevelopmentServer}async function loadStartProductionHost(){return(await import(`#internal/nitro/host.js`)).startProductionServer}function shouldPrintCliBootBanner(e){return e.name()===`info`||e.name()===`dev`||e.name()===`init`}async function waitForShutdownSignal(e){await new Promise((t,n)=>{let r=!1,cleanup=()=>{process.off(`SIGINT`,handleSignal),process.off(`SIGTERM`,handleSignal)},handleSignal=()=>{r||(r=!0,cleanup(),e.close().then(t,n))};process.once(`SIGINT`,handleSignal),process.once(`SIGTERM`,handleSignal)})}async function waitForProductionServer(e){await Promise.race([e.wait(),waitForShutdownSignal({close:()=>e.close()})])}function parsePortOption(e){if(!/^-?\d+$/.test(e))throw new InvalidArgumentError(`Expected a numeric port, received "${e}".`);let t=Number(e);if(t<0||t>65535)throw new InvalidArgumentError(`Expected a port between 0 and 65535, received "${e}".`);return t}const DISPLAY_MODES=new Set([`full`,`collapsed`,`auto-collapsed`,`hidden`]),STATS_MODES=new Set([`tokens`,`tokensPerSecond`]);function parseDisplayMode(e){if(!DISPLAY_MODES.has(e))throw new InvalidArgumentError(`Expected one of ${[...DISPLAY_MODES].join(`, `)}, received "${e}".`);return e}function parseStatsMode(e){if(!STATS_MODES.has(e))throw new InvalidArgumentError(`Expected one of ${[...STATS_MODES].join(`, `)}, received "${e}".`);return e}function parseLogsMode(e){let t=parseLogDisplayMode(e);if(t===void 0)throw new InvalidArgumentError(`Expected one of ${LOG_DISPLAY_MODES.join(`, `)}, received "${e}".`);return t}function parseContextSizeOption(e){let t=Number(e);if(!Number.isFinite(t)||t<=0)throw new InvalidArgumentError(`Expected a positive number, received "${e}".`);return t}function resolveDevUiMode(e){return e.options.ui===!1||!e.interactive?`headless`:`tui`}function resolveTuiDisplayOptions(e){let t={logs:e.logs??`stderr`,reasoning:e.reasoning??`full`,tools:e.tools??`auto-collapsed`};return e.subagents!==void 0&&(t.subagents=e.subagents),e.connectionAuth!==void 0&&(t.connectionAuth=e.connectionAuth),e.assistantResponseStats!==void 0&&(t.assistantResponseStats=e.assistantResponseStats),e.contextSize!==void 0&&(t.contextSize=e.contextSize),t}function hasInteractiveTerminal(){return!!(process.stdin.isTTY&&process.stdout.isTTY)}function rewriteDevelopmentUrlShorthand(e){let t=e[1];return e[0]!==`dev`||e.length!==2||t===void 0||t.startsWith(`-`)?[...e]:[`dev`,`--url`,t]}function resolveRemoteDevelopmentServerUrl(e){if(e.url){if(e.host!==void 0)throw new InvalidArgumentError(`The --host option cannot be used with --url.`);if(e.port!==void 0)throw new InvalidArgumentError(`The --port option cannot be used with --url.`);if(e.ui===!1)throw new InvalidArgumentError(`The --no-ui option cannot be used with --url.`);return e.url}}function createCliProgram(e,i){let c=resolveApplicationRoot(),f=resolveInstalledPackageInfo().version,p=new Command,h=createCliTheme();p.name(`eve`).description(`Build and run an eve application.`).version(f).showHelpAfterError().exitOverride().hook(`preAction`,(t,n)=>{shouldPrintCliBootBanner(n)&&e.log(eveCliBanner())}).configureOutput({writeErr:t=>{e.error(t.trimEnd())},writeOut:t=>{e.log(t.trimEnd())}});let g=p.command(`channels`).description(`Manage user-authored channels in the current project.`);return g.command(`add [kind]`).description(`Add channels interactively, or scaffold a channel kind (slack | web).`).option(`-f, --force`,`Overwrite existing channel files`).option(`-y, --yes`,`Assume yes for confirmations; requires an explicit channel kind`).action(async(t,n)=>{let{runChannelsAddCommand:r}=await import(`#cli/commands/channels.js`);await r(e,c,{kind:t,options:n})}),g.command(`list`).description(`List user-authored channels in the current project.`).option(`--json`,`Output as JSON`).action(async t=>{let{runChannelsListCommand:n}=await import(`#cli/commands/channels.js`);await n(e,c,t)}),p.command(`init [target]`).description(`Create a new eve agent, or add one to an existing project directory.`).option(`--channel-web-nextjs`,`Add the Web Chat application (Next.js)`).action(async(t,n)=>{let{runInitCommand:r}=await import(`#cli/commands/init.js`);await r(e,c,t,n)}),registerProjectCommands({program:p,logger:e,appRoot:c}),p.command(`build`).description(`Build the current eve application.`).action(async()=>{let{loadDevelopmentEnvironmentFiles:t}=await import(`#cli/dev/environment.js`);t(c);let n=await(i.buildHost??await loadBuildHost())(c);e.log(renderCliTaggedLine(h,{message:`built output at ${n}`,tag:`build`,tone:`success`}))}),p.command(`start`).description(`Start a built eve application.`).option(`--host <host>`,`Host interface to bind`).option(`--port <port>`,`Port to listen on (defaults to $PORT, then 3000)`,parsePortOption).action(async t=>{let{loadDevelopmentEnvironmentFiles:n}=await import(`#cli/dev/environment.js`);n(c);let a=await(i.startProductionHost??await loadStartProductionHost())(c,{host:t.host,port:t.port});e.log(renderCliTaggedLine(h,{message:`server listening at ${a.url}`,tag:`start`,tone:`success`})),await waitForProductionServer(a)}),p.command(`dev`).description(`Start the eve development server or connect to an existing URL.`).option(`--host <host>`,`Host interface to bind`).option(`--port <port>`,`Port to listen on (defaults to $PORT, then 2000)`,parsePortOption).option(`-u, --url <url>`,`Connect to an existing server URL`,parseDevelopmentServerUrl).option(`--no-ui`,`Start the server without an interactive UI`).option(`--name <name>`,`Title shown in the terminal UI (defaults to the app folder name)`).option(`--input <text>`,`Pre-fill the prompt input after launching the UI`).option(`--tools <mode>`,`How tool calls render: full | collapsed | auto-collapsed | hidden`,parseDisplayMode).option(`--reasoning <mode>`,`How reasoning renders: full | collapsed | auto-collapsed | hidden`,parseDisplayMode).option(`--subagents <mode>`,`How subagent sections render: full | collapsed | auto-collapsed | hidden`,parseDisplayMode).option(`--connection-auth <mode>`,`How connection authorization renders: full | collapsed | auto-collapsed | hidden`,parseDisplayMode).option(`--assistant-response-stats <mode>`,`Assistant header statistic: tokens | tokensPerSecond`,parseStatsMode).option(`--context-size <tokens>`,`Model context window size, shown as a usage percentage`,parseContextSizeOption).option(`--logs <mode>`,`Which server/agent logs to show: all | stderr | sandbox | none`,parseLogsMode).addHelpText(`after`,`
|
|
2
2
|
You can also pass a bare URL as the only argument, for example: eve dev https://example.com
|
|
3
|
-
`).action(async t=>{let n=resolveRemoteDevelopmentServerUrl(t),
|
|
3
|
+
`).action(async t=>{let n=resolveRemoteDevelopmentServerUrl(t),a=hasInteractiveTerminal(),s=resolveDevUiMode({options:t,interactive:a});if(t.input!==void 0&&s===`headless`)throw new InvalidArgumentError(`--input requires the interactive UI.`);let{loadDevelopmentEnvironmentFiles:u}=await import(`#cli/dev/environment.js`);u(c);let runInteractiveUi=async(e,r)=>{let a=await devBootPhase(`loading interactive UI`,async()=>i.runDevelopmentTui??await loadRunDevelopmentTui(),r),o=resolveTuiDisplayOptions(t),s=n===void 0?{kind:`local`,serverUrl:e,workspaceRoot:c}:{kind:`remote`,serverUrl:e,workspaceRoot:c},l=resolveTuiTitle({name:t.name,target:s});l!==void 0&&(o.name=l),await a({target:s,initialInput:t.input,onBootProgress:r,...o})};if(n){if(e.log(renderCliTaggedLine(h,{message:`connecting to ${n}`,tag:`dev`,tone:`info`})),s===`headless`){e.log(renderCliTaggedLine(h,{message:`Interactive UI disabled because the current terminal is not a TTY.`,tag:`dev`,tone:`warning`}));return}e.log(``),await runInteractiveUi(n);return}s===`tui`&&e.log(``);let d=s===`tui`?startCliLiveRow(e):void 0,f=createDevBootProgressReporter(d);d?.update(`Building your agent`);let p=!1,m,closeServer=async()=>{p||m===void 0||(p=!0,await m.close())};try{if(m=await(i.startHost??await loadStartHost())(c,{host:t.host,onBootProgress:f,port:t.port}),s!==`tui`&&e.log(renderCliTaggedLine(h,{message:`server listening at ${m.url}`,tag:`dev`,tone:`success`})),s===`headless`)return t.ui!==!1&&!a&&e.log(renderCliTaggedLine(h,{message:`Interactive UI disabled because the current terminal is not a TTY.`,tag:`dev`,tone:`warning`})),await waitForShutdownSignal({close:closeServer});await runInteractiveUi(m.url,f)}finally{d?.stop(),await closeServer()}}),p.command(`info`).description(`Print resolved application information.`).option(`--json`,`Output as JSON`).action(async t=>{await(i.printApplicationInfo??await loadPrintApplicationInfo())(e,c,t)}),p.command(`eval`).description(`Run evals against an eve agent.`).argument(`[evalIds...]`,`Eval ids (or directory prefixes) to run (all discovered evals when omitted)`).option(`--url <url>`,`Remote agent URL (skip local host startup)`,parseDevelopmentServerUrl).option(`--tag <tag...>`,`Run only evals carrying a tag`).option(`--strict`,`Fail the exit code when any score falls below its threshold`).option(`--list`,`Print discovered evals without running them`).option(`--timeout <ms>`,`Per-eval timeout in milliseconds`).option(`--max-concurrency <n>`,`Max concurrent eval executions`).option(`--json`,`Output results as JSON`).option(`--junit <path>`,`Write JUnit XML results to a file`).option(`--skip-report`,`Skip eval-defined reporters (e.g. Braintrust)`).option(`--verbose`,`Stream per-eval t.log lines to stdout`).action(async(t,n)=>{await(i.runEvalCommand??await loadRunEvalCommand())(t,n,e)}),p}async function runCli(e=process.argv.slice(2),t=console,n={}){let r=createCliProgram(t,n),a=e.length===0?[`dev`]:rewriteDevelopmentUrlShorthand(e);try{await r.parseAsync(a,{from:`user`})}catch(e){if(e instanceof CommanderError){if(e.exitCode===0)return;let r=await(n.isCodingAgentLaunch??isCodingAgentLaunch)();if(a[0]===`init`&&r){let{initAgentInstructions:e}=await import(`#cli/commands/agent-instructions.js`);t.log(e())}throw Error(e.message)}throw e}}export{resolveDevUiMode,resolveTuiDisplayOptions,runCli};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__toESM}from"../../_virtual/_rolldown/runtime.js";import{require_picocolors}from"../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js";import{isLogLevelEnabled}from"#internal/logging.js";import{sanitizeForTerminal}from"#cli/ui/output.js";import{sliceVisible,visibleLength}from"#cli/dev/tui/terminal-text.js";var import_picocolors=__toESM(require_picocolors(),1);const REDRAW_PROGRESS_ROW=`\r\x1B[K
|
|
1
|
+
import{__toESM}from"../../_virtual/_rolldown/runtime.js";import{require_picocolors}from"../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js";import{isLogLevelEnabled}from"#internal/logging.js";import{sanitizeForTerminal}from"#cli/ui/output.js";import{PROGRESS_PULSE_DURATION_MS,PROGRESS_PULSE_GLYPH,PROGRESS_PULSE_SEQUENCE}from"#cli/ui/progress-pulse.js";import{sliceVisible,visibleLength}from"#cli/dev/tui/terminal-text.js";var import_picocolors=__toESM(require_picocolors(),1);const REDRAW_PROGRESS_ROW=`\r\x1B[K`;function validatePulseSequence(e){if(e.length!==8&&e.length!==16)throw RangeError(`Pulse sequence must contain 8 or 16 steps.`);if(/[^01]/u.test(e))throw RangeError(`Pulse sequence steps must be "0" or "1".`)}function pulseStepDurationMs(e,t){let n=Math.round(e*PROGRESS_PULSE_DURATION_MS/t);return Math.round((e+1)*PROGRESS_PULSE_DURATION_MS/t)-n}function sanitizeProgressText(e){return sanitizeForTerminal(e).replaceAll(/\s+/gu,` `).trim()}function fitProgressText(e,t){return t<=0?``:visibleLength(e)<=t?e:t===1?`…`:`${sliceVisible(e,t-1)}…`}function renderProgressRow(e,t,n,r){let i=n!==``,a=`${e} ${t}${i?``:`...`}`,o=Math.max(0,(r??80)-1),s=visibleLength(a);if(s>=o){let t=fitProgressText(a,o);return t.startsWith(e)?`${import_picocolors.default.green(e)}${t.slice(e.length)}`:t}let u=i?fitProgressText(` ${n}`,o-s):``,d=u===``?``:import_picocolors.default.dim(u);return`${import_picocolors.default.green(e)}${a.slice(e.length)}${d}`}function startCliLiveRow(e,t={}){let r=t.output??process.stdout,i=t.pulseSequence??PROGRESS_PULSE_SEQUENCE;validatePulseSequence(i);let s=r.isTTY===!0&&!isLogLevelEnabled(`debug`),c=0,l=i[0]===`1`,d,f=!1,p=!1,m=!1,h,paint=()=>{if(d===void 0)return;let e=renderProgressRow(l?PROGRESS_PULSE_GLYPH:` `,d.message,d.detail,r.columns);r.write(`${f?REDRAW_PROGRESS_ROW:``}${e}`),f=!0},schedulePulseStep=()=>{h=setTimeout(()=>{if(m)return;c=(c+1)%i.length;let e=i[c]===`1`;e!==l&&(l=e,paint()),schedulePulseStep()},pulseStepDurationMs(c,i.length)),h.unref?.()};return{update(t,n=``){if(!m){if(d={detail:sanitizeProgressText(n),message:sanitizeProgressText(t)},!s){p||=(e.log(`${d.message}...`),!0);return}paint(),h===void 0&&schedulePulseStep()}},stop(){m||(m=!0,h!==void 0&&clearTimeout(h),s&&f&&r.write(REDRAW_PROGRESS_ROW))}}}export{startCliLiveRow};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The one-cell pulse used while `eve dev` builds an agent. */
|
|
2
|
+
export declare const PROGRESS_PULSE_GLYPH = "\u25AA";
|
|
3
|
+
/** Single-cell fallback for terminals without Unicode glyph support. */
|
|
4
|
+
export declare const PROGRESS_PULSE_ASCII_GLYPH = "*";
|
|
5
|
+
/** Lit and unlit steps in the build indicator's one-second loop. */
|
|
6
|
+
export declare const PROGRESS_PULSE_SEQUENCE = "1111110000111111";
|
|
7
|
+
/** Duration of one complete build-indicator pulse. */
|
|
8
|
+
export declare const PROGRESS_PULSE_DURATION_MS = 1000;
|
|
9
|
+
/** Whether the shared build pulse is lit at an elapsed time. */
|
|
10
|
+
export declare function isProgressPulseVisible(elapsedMs: number): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const PROGRESS_PULSE_GLYPH=`▪`,PROGRESS_PULSE_ASCII_GLYPH=`*`,PROGRESS_PULSE_SEQUENCE=`1111110000111111`,PROGRESS_PULSE_DURATION_MS=1e3;function isProgressPulseVisible(e){let t=e%PROGRESS_PULSE_DURATION_MS;return PROGRESS_PULSE_SEQUENCE[Math.floor(t*16/PROGRESS_PULSE_DURATION_MS)]===`1`}export{PROGRESS_PULSE_ASCII_GLYPH,PROGRESS_PULSE_DURATION_MS,PROGRESS_PULSE_GLYPH,PROGRESS_PULSE_SEQUENCE,isProgressPulseVisible};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join,resolve}from"node:path";import{classifyAgentRootEntry}from"#discover/filesystem.js";import{createDiskProjectSource}from"#discover/project-source.js";import{createAgentSourceManifest}from"#discover/manifest.js";import{DISCOVER_CHANNELS_DIRECTORY_INVALID,DISCOVER_HOOKS_DIRECTORY_INVALID,DISCOVER_TOOLS_DIRECTORY_INVALID,createChannelNameDiagnostic,createHookNameDiagnostic,createToolNameDiagnostic,createUnsupportedRootDirectoryDiagnostics,discoverFlatModuleSource,discoverInstructionsSource,discoverNamedSourceDirectory,readSortedDirectoryEntries}from"#discover/grammar.js";import{discoverConnectionSources}from"#discover/connections.js";import{discoverSubagents}from"#discover/discover-subagent.js";import{discoverLibSources}from"#discover/lib.js";import{discoverSandboxSource}from"#discover/sandbox.js";import{discoverScheduleSources}from"#discover/schedules.js";import{discoverSkills}from"#discover/skills.js";async function discoverAgent(
|
|
1
|
+
import{join,resolve}from"node:path";import{classifyAgentRootEntry}from"#discover/filesystem.js";import{createDiskProjectSource}from"#discover/project-source.js";import{createAgentSourceManifest}from"#discover/manifest.js";import{DISCOVER_CHANNELS_DIRECTORY_INVALID,DISCOVER_HOOKS_DIRECTORY_INVALID,DISCOVER_TOOLS_DIRECTORY_INVALID,createChannelNameDiagnostic,createHookNameDiagnostic,createToolNameDiagnostic,createUnsupportedRootDirectoryDiagnostics,discoverFlatModuleSource,discoverInstructionsSource,discoverNamedSourceDirectory,readSortedDirectoryEntries}from"#discover/grammar.js";import{discoverConnectionSources}from"#discover/connections.js";import{discoverSubagents}from"#discover/discover-subagent.js";import{discoverLibSources}from"#discover/lib.js";import{discoverSandboxSource}from"#discover/sandbox.js";import{discoverScheduleSources}from"#discover/schedules.js";import{discoverSkills}from"#discover/skills.js";import{stripNpmPackageScope}from"#shared/package-name.js";async function discoverAgent(a){let o=a.source??createDiskProjectSource(),s=resolve(a.appRoot),c=resolve(a.agentRoot),l=[],u=await tryReadPackageJsonName(o,s),d=await readSortedDirectoryEntries(o,c);l.push(...createUnsupportedRootDirectoryDiagnostics({classifyEntry:classifyAgentRootEntry,createUnsupportedDirectoryMessage(e){return`Ignoring unsupported directory "${e}/" in the agent root.`},rootEntries:d,rootPath:c}));let f=await discoverInstructionsSource({rootEntries:d,rootPath:c,source:o});l.push(...f.diagnostics);let p=discoverFlatModuleSource({rootEntries:d,rootPath:c,slotName:`agent`});l.push(...p.diagnostics);let m=await discoverNamedSourceDirectory({directoryName:`channels`,invalidDirectoryCode:DISCOVER_CHANNELS_DIRECTORY_INVALID,invalidDirectoryMessage:`Expected "${join(c,`channels`)}" to be a directory of authored channels.`,recursive:!0,rootEntries:d,rootPath:c,source:o,validateSegment:createChannelNameDiagnostic});l.push(...m.diagnostics);let h=await discoverLibSources({agentRoot:c,rootEntries:d,source:o});l.push(...h.diagnostics);let g=await discoverScheduleSources({agentRoot:c,rootEntries:d,source:o});l.push(...g.diagnostics);let _=await discoverConnectionSources({rootEntries:d,rootPath:c,source:o});l.push(..._.diagnostics);let v=await discoverSandboxSource({rootEntries:d,rootPath:c,source:o});l.push(...v.diagnostics);let y=await discoverNamedSourceDirectory({directoryName:`tools`,invalidDirectoryCode:DISCOVER_TOOLS_DIRECTORY_INVALID,invalidDirectoryMessage:`Expected "${join(c,`tools`)}" to be a directory of authored tools.`,recursive:!0,rootEntries:d,rootPath:c,source:o,validateSegment:createToolNameDiagnostic});l.push(...y.diagnostics);let b=await discoverNamedSourceDirectory({directoryName:`hooks`,invalidDirectoryCode:DISCOVER_HOOKS_DIRECTORY_INVALID,invalidDirectoryMessage:`Expected "${join(c,`hooks`)}" to be a directory of authored hooks.`,recursive:!0,rootEntries:d,rootPath:c,source:o,validateSegment:createHookNameDiagnostic});l.push(...b.diagnostics);let x=await discoverSkills({agentRoot:c,source:o});l.push(...x.diagnostics);let S=await discoverSubagents({agentRoot:c,appRoot:s,source:o});l.push(...S.diagnostics);let C={agentRoot:c,appRoot:s,channels:m.sources,connections:_.connections,packageName:u,diagnostics:l,hooks:b.sources,lib:h.lib,instructions:f.instructions,sandbox:v.sandbox,sandboxWorkspaces:v.sandboxWorkspace===null?[]:[v.sandboxWorkspace],schedules:g.schedules,skills:x.skills,tools:y.sources,subagents:S.subagents};return p.module!==void 0&&(C.configModule=p.module),{diagnostics:l,manifest:createAgentSourceManifest(C)}}async function tryReadPackageJsonName(t,n){try{let r=join(n,`package.json`),i=JSON.parse(await t.readTextFile(r)).name;return typeof i!=`string`||i.length===0?void 0:stripNpmPackageScope(i)}catch{return}}export{discoverAgent};
|
package/dist/src/evals/target.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createEveDevDispatchSchedulePath}from"#protocol/routes.js";import{toErrorMessage}from"#shared/errors.js";import"#client/client.js";import{EvalSessionManager}from"#evals/session.js";import{setTimeout}from"node:timers/promises";async function resolveEvalTargetHandle(e){await waitForTargetHealth(e.client,e.url);let t=await e.client.info();if(assertAgentInfoShape(t,e.url),e.expectedAgentName!==void 0
|
|
1
|
+
import{createEveDevDispatchSchedulePath}from"#protocol/routes.js";import{toErrorMessage}from"#shared/errors.js";import"#client/client.js";import{stripNpmPackageScope}from"#shared/package-name.js";import{EvalSessionManager}from"#evals/session.js";import{setTimeout}from"node:timers/promises";async function resolveEvalTargetHandle(e){await waitForTargetHealth(e.client,e.url);let t=await e.client.info();if(assertAgentInfoShape(t,e.url),e.expectedAgentName!==void 0&&!matchesExpectedAgentName(e.expectedAgentName,t.agent.name))throw Error(`Expected eval target ${JSON.stringify(e.expectedAgentName)} at ${e.url}, but ${JSON.stringify(t.agent.name)} is responding there.`);return createEvalTargetHandle({capabilities:capabilitiesFromInfo(t),client:e.client,kind:e.kind,url:e.url})}function createEvalTargetHandle(e){return createHandle({capabilities:e.capabilities,client:e.client,kind:e.kind,sessions:void 0,url:e.url})}function scopeEvalTargetHandle(e,t){return createHandle({capabilities:e.capabilities,client:void 0,delegate:e,kind:e.kind,sessions:t.sessions,url:e.url})}function createHandle(t){let n=t.delegate,i=t.client,fetchTarget=async(e,t)=>{if(n!==void 0)return await n.fetch(e,t);if(i===void 0)throw Error(`Eval target cannot fetch without a client.`);return await i.fetch(e,t)};return{capabilities:t.capabilities,kind:t.kind,url:t.url,async attachSession(e,a){if(t.sessions!==void 0)return await t.sessions.attachSession(e,a);if(n!==void 0)return await n.attachSession(e,a);if(i===void 0)throw Error(`Eval target cannot attach sessions without a client.`);return await new EvalSessionManager({client:i}).attachSession(e,a)},async dispatchSchedule(n){if(!t.capabilities.devRoutes)throw Error(`target.dispatchSchedule() requires a target with dev routes enabled.`);let r=await fetchTarget(createEveDevDispatchSchedulePath(n),{method:`POST`});if(!r.ok){let e=await readResponseBodySafely(r);throw Error(`Schedule dispatch failed: ${r.status} ${r.statusText}`+(e.length>0?`, ${e}`:``))}return parseScheduleDispatchResult(await r.json())},async fetch(e,t){return await fetchTarget(e,t)}}}function capabilitiesFromInfo(e){return{devRoutes:e.capabilities?.devRoutes??e.mode===`development`}}function matchesExpectedAgentName(e,t){return t===e||t===stripNpmPackageScope(e)}async function waitForTargetHealth(e,n){let r=Date.now()+6e4,a;for(;Date.now()<r;)try{await e.health();return}catch(e){a=toErrorMessage(e),await setTimeout(250)}throw Error(`Timed out waiting for eval target health at ${n}.`+(a===void 0?``:` Last error: ${a}`))}function assertAgentInfoShape(e,t){if(e.kind!==`eve-agent-info`||e.version!==1)throw Error(`Eval target ${t} returned an unrecognized /eve/v1/info payload.`)}function parseScheduleDispatchResult(e){if(typeof e!=`object`||!e||!(`scheduleId`in e)||typeof e.scheduleId!=`string`||!(`sessionIds`in e)||!Array.isArray(e.sessionIds)||e.sessionIds.some(e=>typeof e!=`string`))throw Error(`Schedule dispatch returned an unexpected response shape: ${JSON.stringify(e)}`);return{scheduleId:e.scheduleId,sessionIds:[...e.sessionIds]}}async function readResponseBodySafely(e){try{return(await e.text()).trim()}catch{return``}}export{createEvalTargetHandle,resolveEvalTargetHandle,scopeEvalTargetHandle};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createLogger}from"#internal/logging.js";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{jsonSchema}from"ai";import{createToolLoopHarness}from"#harness/tool-loop.js";import{resolveCodeModeEnabled}from"#shared/code-mode.js";import{resolveRuntimeModelReference}from"#runtime/agent/resolve-model.js";import{findRegisteredRuntimeTool}from"#runtime/tools/registry.js";import{SUBAGENT_TOOL_INPUT_SCHEMA}from"#runtime/subagents/registry.js";import{preserveFrameworkStateOnCompaction}from"#execution/compaction.js";import{
|
|
1
|
+
import{createLogger}from"#internal/logging.js";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{jsonSchema}from"ai";import{createToolLoopHarness}from"#harness/tool-loop.js";import{resolveCodeModeEnabled}from"#shared/code-mode.js";import{resolveRuntimeModelReference}from"#runtime/agent/resolve-model.js";import{findRegisteredRuntimeTool}from"#runtime/tools/registry.js";import{SUBAGENT_TOOL_INPUT_SCHEMA}from"#runtime/subagents/registry.js";import{preserveFrameworkStateOnCompaction}from"#execution/compaction.js";import{createToolExecuteWithAuth}from"#execution/tool-auth.js";const log=createLogger(`execution.node-step`);function createExecutionNodeStep(e){let t=createRuntimeModelResolver(e.modelResolutionScope),n=createNodeHarnessTools({node:e.node});return createToolLoopHarness({capabilities:e.capabilities,codeMode:resolveCodeModeEnabled(e.node.agent.config?.experimental?.codeMode),workflow:e.node.agent.workflowEnabled===!0,handleEvent:e.handleEvent,mode:e.mode,onCompaction:preserveFrameworkStateOnCompaction,resolveModel:t,runtimeIdentity:buildRuntimeIdentity(e.node),tools:n})}function buildRuntimeIdentity(e){let n=resolveInstalledPackageInfo(),r={agentId:e.turnAgent.id,agentName:e.agent.config?.name,eveVersion:n.version,modelId:e.turnAgent.model.id},i=process.env.VERCEL_GIT_COMMIT_SHA?.trim(),a=process.env.VERCEL_GIT_COMMIT_REF?.trim(),o=process.env.VERCEL_DEPLOYMENT_CREATED_AT?.trim();return i||a||o?{...r,build:{deployedAt:o||void 0,gitBranch:a||void 0,gitSha:i||void 0}}:r}function createRuntimeModelResolver(e){return t=>resolveRuntimeModelReference(t,e)}function createNodeHarnessTools(e){let t=new Map;for(let n of e.node.turnAgent.tools){let r=resolveHarnessToolDefinition({node:e.node,tool:n});r!==null&&t.set(n.name,r)}return t.has(`agent`)||t.set(`agent`,{description:`Launch a new agent to handle a complex, multi-step subtask.`,inputSchema:jsonSchema(SUBAGENT_TOOL_INPUT_SCHEMA),name:`agent`,runtimeAction:{kind:`subagent-call`,nodeId:e.node.nodeId,subagentName:`agent`}}),t}function resolveHarnessToolDefinition(e){if(e.tool.kind===`subagent`)return{description:e.tool.description??``,inputSchema:jsonSchema(e.tool.inputSchema??{}),name:e.tool.name,outputSchema:e.tool.outputSchema===void 0?void 0:jsonSchema(e.tool.outputSchema),runtimeAction:{kind:`subagent-call`,nodeId:e.tool.nodeId,subagentName:e.tool.name}};if(e.tool.kind===`remote`)return{description:e.tool.description??``,inputSchema:jsonSchema(e.tool.inputSchema??{}),name:e.tool.name,outputSchema:e.tool.outputSchema===void 0?void 0:jsonSchema(e.tool.outputSchema),runtimeAction:{kind:`remote-agent-call`,nodeId:e.tool.nodeId,remoteAgentName:e.tool.name,subagentName:e.tool.name}};let t=findRegisteredRuntimeTool(e.node.toolRegistry,e.tool.name);if(t===null)return log.warn(`declared tool is not registered — omitting from toolset`,{toolName:e.tool.name,nodeId:e.node.nodeId}),null;let r=t.definition,i=r.sourceId.startsWith(`eve:`),a=r.execute;return{approvalKey:r.approvalKey,description:r.description,execute:resolveAuthoredExecute({isFrameworkTool:i,rawExecute:a,scope:r.name}),inputSchema:r.inputStandardSchema??jsonSchema(r.inputSchema??{}),name:r.name,needsApproval:r.needsApproval,outputSchema:r.outputStandardSchema??maybeJsonSchema(r.outputSchema),toModelOutput:r.toModelOutput}}function resolveAuthoredExecute(e){let{isFrameworkTool:t,rawExecute:n,scope:r}=e;return n===void 0?void 0:t?n:createToolExecuteWithAuth({execute:n,scope:r})}function maybeJsonSchema(e){return e===void 0?void 0:jsonSchema(e)}export{createExecutionNodeStep,createNodeHarnessTools};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dirname}from"node:path";import{mkdir,readFile,writeFile}from"node:fs/promises";import{loadOptionalEnginePackage}from"#internal/application/optional-package-install.js";import{WORKSPACE_ROOT}from"#runtime/workspace/types.js";import{createFileBackedInternalSandboxSession,pathExists}from"#execution/sandbox/bindings/local-backend-utils.js";import{shellQuote}from"#execution/sandbox/shell-quote.js";import{buildSandboxSession}from"#execution/sandbox/session.js";let justBashModulePromise;async function loadJustBashModule(e){return justBashModulePromise??=loadOptionalEnginePackage({appRoot:e.appRoot,autoInstall:e.autoInstall,importModule:async()=>await import(`just-bash`),missingMessage:"The just-bash sandbox backend requires the `just-bash` package, which is not bundled with eve. Install it in your application (for example `pnpm add -D just-bash`), or use docker() / defaultSandbox() instead.",packageName:`just-bash`}).catch(e=>{throw justBashModulePromise=void 0,e}),await justBashModulePromise}async function createBashSandbox(n){let{ReadWriteFs:r,Sandbox:i}=await loadJustBashModule({appRoot:n.appRoot,autoInstall:n.autoInstall}),
|
|
1
|
+
import{dirname}from"node:path";import{mkdir,readFile,writeFile}from"node:fs/promises";import{loadOptionalEnginePackage}from"#internal/application/optional-package-install.js";import{WORKSPACE_ROOT}from"#runtime/workspace/types.js";import{createFileBackedInternalSandboxSession,pathExists}from"#execution/sandbox/bindings/local-backend-utils.js";import{shellQuote}from"#execution/sandbox/shell-quote.js";import{buildSandboxSession}from"#execution/sandbox/session.js";import{adaptMultiplexedCommandToSandboxProcess}from"#execution/sandbox/multiplexed-command.js";let justBashModulePromise;async function loadJustBashModule(e){return justBashModulePromise??=loadOptionalEnginePackage({appRoot:e.appRoot,autoInstall:e.autoInstall,importModule:async()=>await import(`just-bash`),missingMessage:"The just-bash sandbox backend requires the `just-bash` package, which is not bundled with eve. Install it in your application (for example `pnpm add -D just-bash`), or use docker() / defaultSandbox() instead.",packageName:`just-bash`}).catch(e=>{throw justBashModulePromise=void 0,e}),await justBashModulePromise}async function createBashSandbox(n){let{ReadWriteFs:r,Sandbox:i}=await loadJustBashModule({appRoot:n.appRoot,autoInstall:n.autoInstall}),a=resolveLocalSandboxFilesystemRootPath(n.rootPath),o=resolveLocalSandboxMetadataPath(n.rootPath),s=await readLocalMetadata(o);await mkdir(a,{recursive:!0});let c=new r({allowSymlinks:!0,maxFileReadSize:2**53-1,root:a});await ensureLocalSandboxDirectories(c);let l=await i.create({cwd:WORKSPACE_ROOT,env:s?.env,fs:c,network:{dangerouslyAllowFullInternetAccess:!0}});return{async captureState(){return await writeLocalMetadata(o,{env:{...l.bashEnvInstance.getEnv()},version:1}),{rootPath:n.rootPath}},async dispose(){await l.stop()},async readFileBytes(e){let t;try{t=await c.readFileBuffer(e)}catch{return null}return Buffer.from(t)},async removePath(e){await c.rm(e.path,{force:e.force,recursive:e.recursive})},rootPath:n.rootPath,sessionKey:n.sessionKey,async spawn(e){if(e.abortSignal?.aborted)throw new DOMException(`The operation was aborted.`,`AbortError`);let t=e.workingDirectory===void 0?e.command:`( cd ${shellQuote(e.workingDirectory)} && ${e.command} )`;return adaptMultiplexedCommandToSandboxProcess({command:await l.runCommand({args:[t],cmd:`eval`,detached:!0,env:e.env,signal:e.abortSignal}),getOutput:e=>e.type})},async writeFiles(t){for(let n of t){let t=dirname(n.path);await c.mkdir(t,{recursive:!0}),await c.writeFile(n.path,n.content)}}}}async function justBashSetNetworkPolicyUnsupported(){throw Error(`setNetworkPolicy() is not supported on the just-bash sandbox backend. just-bash applies its network policy only at sandbox creation (no run-time update) and does not run git or other binaries. Use docker() for coarse egress control or vercel() / microsandbox() for credential brokering.`)}function createJustBashHandle(e,t){let n=buildSandboxSession(createFileBackedInternalSandboxSession({id:e.sessionKey,sandbox:e}),justBashSetNetworkPolicyUnsupported);return{session:n,useSessionFn:async()=>n,async captureState(){return{backendName:t,metadata:await e.captureState()??{},sessionKey:e.sessionKey}},async dispose(){await e.dispose()}}}function resolveLocalSandboxFilesystemRootPath(e){return`${e}/fs`}function resolveLocalSandboxMetadataPath(e){return`${e}/metadata.json`}async function ensureLocalSandboxDirectories(e){await e.mkdir(WORKSPACE_ROOT,{recursive:!0})}async function readLocalMetadata(e){if(!await pathExists(e))return null;let t=JSON.parse(await readFile(e,`utf8`));return t.version!==1||!isStringRecord(t.env)?null:{env:t.env,version:1}}async function writeLocalMetadata(n,i){await mkdir(dirname(n),{recursive:!0}),await writeFile(n,`${JSON.stringify(i,null,2)}\n`)}function isStringRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.values(e).every(e=>typeof e==`string`)}export{createBashSandbox,createJustBashHandle,justBashSetNetworkPolicyUnsupported};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type * as Vercel from "#compiled/@vercel/sandbox/index.js";
|
|
2
|
-
export type VercelCommand = Vercel.Command;
|
|
3
2
|
export type VercelCreateOptions = NonNullable<Parameters<typeof Vercel.Sandbox.create>[0]>;
|
|
4
3
|
export type VercelGetOptions = Parameters<typeof Vercel.Sandbox.get>[0];
|
|
5
4
|
export type VercelModule = typeof Vercel;
|