dispach 0.1.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/README.md +596 -0
- package/dist/App-dxqm39zx.js +11 -0
- package/dist/App-dxqm39zx.js.map +25 -0
- package/dist/ConfigEditor-7v5nebvy.js +6 -0
- package/dist/ConfigEditor-7v5nebvy.js.map +11 -0
- package/dist/KeyProbe-vjhmdpx6.js +5 -0
- package/dist/KeyProbe-vjhmdpx6.js.map +11 -0
- package/dist/Picker-jxaesaxy.js +5 -0
- package/dist/Picker-jxaesaxy.js.map +10 -0
- package/dist/SessionPicker-z2t0p4b5.js +5 -0
- package/dist/SessionPicker-z2t0p4b5.js.map +11 -0
- package/dist/SkillBrowser-yyf2gy0q.js +5 -0
- package/dist/SkillBrowser-yyf2gy0q.js.map +11 -0
- package/dist/WizardApp-12ndxgqv.js +5 -0
- package/dist/WizardApp-12ndxgqv.js.map +13 -0
- package/dist/agents.d.ts +9 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/browse.d.ts +63 -0
- package/dist/browse.d.ts.map +1 -0
- package/dist/client.d.ts +25 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +34 -0
- package/dist/client.js.map +11 -0
- package/dist/components/App.d.ts +28 -0
- package/dist/components/App.d.ts.map +1 -0
- package/dist/components/Banner.d.ts +16 -0
- package/dist/components/Banner.d.ts.map +1 -0
- package/dist/components/Brandmark.d.ts +31 -0
- package/dist/components/Brandmark.d.ts.map +1 -0
- package/dist/components/CheckList.d.ts +38 -0
- package/dist/components/CheckList.d.ts.map +1 -0
- package/dist/components/CommandOutput.d.ts +29 -0
- package/dist/components/CommandOutput.d.ts.map +1 -0
- package/dist/components/ConfigEditor.d.ts +64 -0
- package/dist/components/ConfigEditor.d.ts.map +1 -0
- package/dist/components/HistorySearch.d.ts +23 -0
- package/dist/components/HistorySearch.d.ts.map +1 -0
- package/dist/components/KeyProbe.d.ts +36 -0
- package/dist/components/KeyProbe.d.ts.map +1 -0
- package/dist/components/LineCursor.d.ts +55 -0
- package/dist/components/LineCursor.d.ts.map +1 -0
- package/dist/components/Live.d.ts +17 -0
- package/dist/components/Live.d.ts.map +1 -0
- package/dist/components/Palette.d.ts +21 -0
- package/dist/components/Palette.d.ts.map +1 -0
- package/dist/components/Picker.d.ts +23 -0
- package/dist/components/Picker.d.ts.map +1 -0
- package/dist/components/Prompt.d.ts +20 -0
- package/dist/components/Prompt.d.ts.map +1 -0
- package/dist/components/Screen.d.ts +39 -0
- package/dist/components/Screen.d.ts.map +1 -0
- package/dist/components/SelectList.d.ts +34 -0
- package/dist/components/SelectList.d.ts.map +1 -0
- package/dist/components/SessionPicker.d.ts +26 -0
- package/dist/components/SessionPicker.d.ts.map +1 -0
- package/dist/components/SkillBrowser.d.ts +39 -0
- package/dist/components/SkillBrowser.d.ts.map +1 -0
- package/dist/components/Spinner.d.ts +13 -0
- package/dist/components/Spinner.d.ts.map +1 -0
- package/dist/components/StatusBar.d.ts +11 -0
- package/dist/components/StatusBar.d.ts.map +1 -0
- package/dist/components/SummaryCard.d.ts +11 -0
- package/dist/components/SummaryCard.d.ts.map +1 -0
- package/dist/components/TextField.d.ts +39 -0
- package/dist/components/TextField.d.ts.map +1 -0
- package/dist/components/Transcript.d.ts +23 -0
- package/dist/components/Transcript.d.ts.map +1 -0
- package/dist/components/WizardApp.d.ts +18 -0
- package/dist/components/WizardApp.d.ts.map +1 -0
- package/dist/components/WizardFrame.d.ts +19 -0
- package/dist/components/WizardFrame.d.ts.map +1 -0
- package/dist/config-yz0nz51b.js +24 -0
- package/dist/config-yz0nz51b.js.map +10 -0
- package/dist/config.d.ts +71 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/credential-wgt4gvcz.js +19 -0
- package/dist/credential-wgt4gvcz.js.map +10 -0
- package/dist/credential.d.ts +68 -0
- package/dist/credential.d.ts.map +1 -0
- package/dist/daemon.d.ts +47 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/editor.d.ts +81 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/hooks/useElapsed.d.ts +10 -0
- package/dist/hooks/useElapsed.d.ts.map +1 -0
- package/dist/hooks/useTerminalSize.d.ts +14 -0
- package/dist/hooks/useTerminalSize.d.ts.map +1 -0
- package/dist/hooks/useTurn.d.ts +41 -0
- package/dist/hooks/useTurn.d.ts.map +1 -0
- package/dist/index-2cvtz0fy.js +903 -0
- package/dist/index-2cvtz0fy.js.map +194 -0
- package/dist/index-3nwfz9jq.js +12 -0
- package/dist/index-3nwfz9jq.js.map +11 -0
- package/dist/index-6b7qvh1x.js +6 -0
- package/dist/index-6b7qvh1x.js.map +10 -0
- package/dist/index-6z0yr17z.js +12 -0
- package/dist/index-6z0yr17z.js.map +11 -0
- package/dist/index-7da4fqcr.js +7 -0
- package/dist/index-7da4fqcr.js.map +11 -0
- package/dist/index-8bmhd2hj.js +6 -0
- package/dist/index-8bmhd2hj.js.map +10 -0
- package/dist/index-9d011p3q.js +6 -0
- package/dist/index-9d011p3q.js.map +10 -0
- package/dist/index-9f9pp2ef.js +6 -0
- package/dist/index-9f9pp2ef.js.map +10 -0
- package/dist/index-9nsfs0vy.js +6 -0
- package/dist/index-9nsfs0vy.js.map +10 -0
- package/dist/index-9pj1ws0p.js +77 -0
- package/dist/index-9pj1ws0p.js.map +12 -0
- package/dist/index-b5wwtxzk.js +66 -0
- package/dist/index-b5wwtxzk.js.map +12 -0
- package/dist/index-b8zwg8a3.js +6 -0
- package/dist/index-b8zwg8a3.js.map +10 -0
- package/dist/index-bry9bzt3.js +427 -0
- package/dist/index-bry9bzt3.js.map +11 -0
- package/dist/index-bwckzbf8.js +6 -0
- package/dist/index-bwckzbf8.js.map +10 -0
- package/dist/index-cx3vz7sf.js +6 -0
- package/dist/index-cx3vz7sf.js.map +11 -0
- package/dist/index-e8n70sgj.js +6 -0
- package/dist/index-e8n70sgj.js.map +11 -0
- package/dist/index-fvhg0xyd.js +167 -0
- package/dist/index-fvhg0xyd.js.map +19 -0
- package/dist/index-gbnc99j8.js +14 -0
- package/dist/index-gbnc99j8.js.map +13 -0
- package/dist/index-h2yds678.js +7 -0
- package/dist/index-h2yds678.js.map +11 -0
- package/dist/index-j97vttdt.js +10 -0
- package/dist/index-j97vttdt.js.map +10 -0
- package/dist/index-jk0def33.js +6 -0
- package/dist/index-jk0def33.js.map +12 -0
- package/dist/index-jym27m75.js +6 -0
- package/dist/index-jym27m75.js.map +10 -0
- package/dist/index-mgdgx22q.js +10 -0
- package/dist/index-mgdgx22q.js.map +10 -0
- package/dist/index-mrtb5y08.js +6 -0
- package/dist/index-mrtb5y08.js.map +11 -0
- package/dist/index-my5cjx00.js +6 -0
- package/dist/index-my5cjx00.js.map +10 -0
- package/dist/index-qc2vrq9z.js +7 -0
- package/dist/index-qc2vrq9z.js.map +11 -0
- package/dist/index-rqbtm761.js +6 -0
- package/dist/index-rqbtm761.js.map +10 -0
- package/dist/index-rqzg861g.js +6 -0
- package/dist/index-rqzg861g.js.map +10 -0
- package/dist/index-t1xvacym.js +6 -0
- package/dist/index-t1xvacym.js.map +11 -0
- package/dist/index-xgqzk5cq.js +9 -0
- package/dist/index-xgqzk5cq.js.map +12 -0
- package/dist/index-xqyms08r.js +6 -0
- package/dist/index-xqyms08r.js.map +10 -0
- package/dist/index-yr25dnf5.js +6 -0
- package/dist/index-yr25dnf5.js.map +10 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +527 -0
- package/dist/index.js.map +48 -0
- package/dist/init.d.ts +34 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/keymap.d.ts +126 -0
- package/dist/keymap.d.ts.map +1 -0
- package/dist/keys.d.ts +17 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/lib/ambient.d.ts +69 -0
- package/dist/lib/ambient.d.ts.map +1 -0
- package/dist/lib/args.d.ts +33 -0
- package/dist/lib/args.d.ts.map +1 -0
- package/dist/lib/bootstrap.d.ts +84 -0
- package/dist/lib/bootstrap.d.ts.map +1 -0
- package/dist/lib/browse.d.ts +89 -0
- package/dist/lib/browse.d.ts.map +1 -0
- package/dist/lib/browser.d.ts +55 -0
- package/dist/lib/browser.d.ts.map +1 -0
- package/dist/lib/chat-frame.d.ts +156 -0
- package/dist/lib/chat-frame.d.ts.map +1 -0
- package/dist/lib/clipboard.d.ts +32 -0
- package/dist/lib/clipboard.d.ts.map +1 -0
- package/dist/lib/commands.d.ts +26 -0
- package/dist/lib/commands.d.ts.map +1 -0
- package/dist/lib/composer.d.ts +85 -0
- package/dist/lib/composer.d.ts.map +1 -0
- package/dist/lib/config-apply.d.ts +51 -0
- package/dist/lib/config-apply.d.ts.map +1 -0
- package/dist/lib/config-editor.d.ts +113 -0
- package/dist/lib/config-editor.d.ts.map +1 -0
- package/dist/lib/config-env.d.ts +110 -0
- package/dist/lib/config-env.d.ts.map +1 -0
- package/dist/lib/config-rows.d.ts +37 -0
- package/dist/lib/config-rows.d.ts.map +1 -0
- package/dist/lib/config-view.d.ts +133 -0
- package/dist/lib/config-view.d.ts.map +1 -0
- package/dist/lib/confirm.d.ts +86 -0
- package/dist/lib/confirm.d.ts.map +1 -0
- package/dist/lib/const.d.ts +213 -0
- package/dist/lib/const.d.ts.map +1 -0
- package/dist/lib/csi.d.ts +70 -0
- package/dist/lib/csi.d.ts.map +1 -0
- package/dist/lib/curated.d.ts +44 -0
- package/dist/lib/curated.d.ts.map +1 -0
- package/dist/lib/daemon-plan.d.ts +151 -0
- package/dist/lib/daemon-plan.d.ts.map +1 -0
- package/dist/lib/dotenv-edit.d.ts +30 -0
- package/dist/lib/dotenv-edit.d.ts.map +1 -0
- package/dist/lib/env.d.ts +10 -0
- package/dist/lib/env.d.ts.map +1 -0
- package/dist/lib/exit.d.ts +170 -0
- package/dist/lib/exit.d.ts.map +1 -0
- package/dist/lib/help.d.ts +10 -0
- package/dist/lib/help.d.ts.map +1 -0
- package/dist/lib/init-flow.d.ts +539 -0
- package/dist/lib/init-flow.d.ts.map +1 -0
- package/dist/lib/init-skills.d.ts +46 -0
- package/dist/lib/init-skills.d.ts.map +1 -0
- package/dist/lib/keyboard.d.ts +76 -0
- package/dist/lib/keyboard.d.ts.map +1 -0
- package/dist/lib/keys-view.d.ts +57 -0
- package/dist/lib/keys-view.d.ts.map +1 -0
- package/dist/lib/launchd.d.ts +151 -0
- package/dist/lib/launchd.d.ts.map +1 -0
- package/dist/lib/lifecycle.d.ts +126 -0
- package/dist/lib/lifecycle.d.ts.map +1 -0
- package/dist/lib/log-follow.d.ts +71 -0
- package/dist/lib/log-follow.d.ts.map +1 -0
- package/dist/lib/mouse.d.ts +84 -0
- package/dist/lib/mouse.d.ts.map +1 -0
- package/dist/lib/multiselect.d.ts +37 -0
- package/dist/lib/multiselect.d.ts.map +1 -0
- package/dist/lib/origins.d.ts +40 -0
- package/dist/lib/origins.d.ts.map +1 -0
- package/dist/lib/output.d.ts +29 -0
- package/dist/lib/output.d.ts.map +1 -0
- package/dist/lib/palette.d.ts +69 -0
- package/dist/lib/palette.d.ts.map +1 -0
- package/dist/lib/probe.d.ts +158 -0
- package/dist/lib/probe.d.ts.map +1 -0
- package/dist/lib/providers.d.ts +63 -0
- package/dist/lib/providers.d.ts.map +1 -0
- package/dist/lib/provision.d.ts +163 -0
- package/dist/lib/provision.d.ts.map +1 -0
- package/dist/lib/remove-plan.d.ts +120 -0
- package/dist/lib/remove-plan.d.ts.map +1 -0
- package/dist/lib/render.d.ts +78 -0
- package/dist/lib/render.d.ts.map +1 -0
- package/dist/lib/resume.d.ts +69 -0
- package/dist/lib/resume.d.ts.map +1 -0
- package/dist/lib/rows.d.ts +69 -0
- package/dist/lib/rows.d.ts.map +1 -0
- package/dist/lib/sandbox.d.ts +101 -0
- package/dist/lib/sandbox.d.ts.map +1 -0
- package/dist/lib/schema.d.ts +491 -0
- package/dist/lib/schema.d.ts.map +1 -0
- package/dist/lib/screen.d.ts +102 -0
- package/dist/lib/screen.d.ts.map +1 -0
- package/dist/lib/scroll.d.ts +64 -0
- package/dist/lib/scroll.d.ts.map +1 -0
- package/dist/lib/select.d.ts +23 -0
- package/dist/lib/select.d.ts.map +1 -0
- package/dist/lib/service-env.d.ts +38 -0
- package/dist/lib/service-env.d.ts.map +1 -0
- package/dist/lib/service.d.ts +102 -0
- package/dist/lib/service.d.ts.map +1 -0
- package/dist/lib/session-commands.d.ts +229 -0
- package/dist/lib/session-commands.d.ts.map +1 -0
- package/dist/lib/session-key.d.ts +55 -0
- package/dist/lib/session-key.d.ts.map +1 -0
- package/dist/lib/sessions-view.d.ts +31 -0
- package/dist/lib/sessions-view.d.ts.map +1 -0
- package/dist/lib/source-cache.d.ts +105 -0
- package/dist/lib/source-cache.d.ts.map +1 -0
- package/dist/lib/source.d.ts +281 -0
- package/dist/lib/source.d.ts.map +1 -0
- package/dist/lib/sources.d.ts +107 -0
- package/dist/lib/sources.d.ts.map +1 -0
- package/dist/lib/spawn.d.ts +56 -0
- package/dist/lib/spawn.d.ts.map +1 -0
- package/dist/lib/stdin-tap.d.ts +41 -0
- package/dist/lib/stdin-tap.d.ts.map +1 -0
- package/dist/lib/subcommand.d.ts +57 -0
- package/dist/lib/subcommand.d.ts.map +1 -0
- package/dist/lib/systemd.d.ts +60 -0
- package/dist/lib/systemd.d.ts.map +1 -0
- package/dist/lib/templates.d.ts +35 -0
- package/dist/lib/templates.d.ts.map +1 -0
- package/dist/lib/terminal.d.ts +98 -0
- package/dist/lib/terminal.d.ts.map +1 -0
- package/dist/lib/text-selection.d.ts +75 -0
- package/dist/lib/text-selection.d.ts.map +1 -0
- package/dist/lib/theme.d.ts +90 -0
- package/dist/lib/theme.d.ts.map +1 -0
- package/dist/lib/types.d.ts +467 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/warnings.d.ts +79 -0
- package/dist/lib/warnings.d.ts.map +1 -0
- package/dist/lib/width.d.ts +39 -0
- package/dist/lib/width.d.ts.map +1 -0
- package/dist/lib/wizard.d.ts +95 -0
- package/dist/lib/wizard.d.ts.map +1 -0
- package/dist/lib/wordmark.d.ts +60 -0
- package/dist/lib/wordmark.d.ts.map +1 -0
- package/dist/lib/wrap.d.ts +74 -0
- package/dist/lib/wrap.d.ts.map +1 -0
- package/dist/memory.d.ts +25 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/model.d.ts +47 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/plugins.d.ts +15 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/remove.d.ts +52 -0
- package/dist/remove.d.ts.map +1 -0
- package/dist/run.d.ts +42 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/schedules.d.ts +41 -0
- package/dist/schedules.d.ts.map +1 -0
- package/dist/serve.d.ts +41 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/sessions.d.ts +13 -0
- package/dist/sessions.d.ts.map +1 -0
- package/dist/skills.d.ts +80 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/soul.d.ts +19 -0
- package/dist/soul.d.ts.map +1 -0
- package/dist/sources.d.ts +32 -0
- package/dist/sources.d.ts.map +1 -0
- package/dist/start.d.ts +26 -0
- package/dist/start.d.ts.map +1 -0
- package/dist/stop.d.ts +58 -0
- package/dist/stop.d.ts.map +1 -0
- package/dist/terminal-setup.d.ts +31 -0
- package/dist/terminal-setup.d.ts.map +1 -0
- package/dist/tools.d.ts +22 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/transcript.d.ts +124 -0
- package/dist/transcript.d.ts.map +1 -0
- package/dist/validate.d.ts +36 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/web-w7r68df1.js +14 -0
- package/dist/web-w7r68df1.js.map +11 -0
- package/dist/web.d.ts +36 -0
- package/dist/web.d.ts.map +1 -0
- package/dist/wire.d.ts +10 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +33 -0
- package/dist/wire.js.map +10 -0
- package/dist/workspace.d.ts +19 -0
- package/dist/workspace.d.ts.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{e,A}from"./index-2cvtz0fy.js";import{o,zo,Bo,u,oe,S,R}from"./index-jk0def33.js";import{Qt,it,en}from"./index-cx3vz7sf.js";import{de}from"./index-b8zwg8a3.js";import{tr}from"./index-qc2vrq9z.js";import{fn,hn}from"./index-h2yds678.js";import{qn,fo,ho,Xt,Jt,xt,st,mo,fr,wo,bo}from"./index-3nwfz9jq.js";import{re}from"./index-rqbtm761.js";import"./index-bry9bzt3.js";import{le,_t}from"./index-yr25dnf5.js";import{ot,Yt}from"./index-gbnc99j8.js";import"./index-9f9pp2ef.js";import{pe}from"./index-xqyms08r.js";import{Jn,Z}from"./index-9nsfs0vy.js";import"./index-mgdgx22q.js";import{D,Mt,gt,X,Po,mn,Lt}from"./index-6z0yr17z.js";import{U,rr,Sn,Tn,Jo,ns,rs,os,ss,or,Ft,as}from"./index-my5cjx00.js";import{Box as W,Text as J,useApp as zt,useInput as et}from"ink";import{useCallback as nt,useEffect as tt,useMemo as rt,useRef as Zt,useState as O}from"react";import{Box as Oe,Text as me}from"ink";import{jsx as Se,jsxs as fe}from"react/jsx-runtime";function sn({lines:n,label:t,offset:r,maxRows:i,code:s}){if(n===void 0)return Se(Oe,{marginLeft:2,children:Se(de,{label:`running ${t}`})});if(n.length===0)return Se(Oe,{marginLeft:2,children:fe(me,{color:o.muted,children:[t," printed nothing"]})});let{from:a,to:c}=R(n.length,Math.min(r+Math.floor(i/2),n.length-1),i),m=n.slice(a,c).map((f,b)=>({row:a+b,text:f}));return fe(Oe,{flexDirection:"column",children:[s!==void 0&&s!==0?fe(me,{color:o.error,wrap:"truncate",children:[u.error,t," exited ",s]}):null,a>0?fe(me,{dimColor:!0,wrap:"truncate",children:[" ",u.ellipsis," ",a," line",a===1?"":"s"," above"]}):null,m.map((f)=>Se(me,{wrap:"truncate",children:f.text},f.row)),c<n.length?fe(me,{dimColor:!0,wrap:"truncate",children:[" ",u.ellipsis," ",n.length-c," line",n.length-c===1?"":"s"," ","below"]}):null]})}import{Box as bt,Text as V}from"ink";import{jsx as he,jsxs as Te}from"react/jsx-runtime";function an({editor:n,width:t,maxRows:r}){let i=n.search;if(i===void 0)return null;let s=Mt(n),a=Math.min(i.index,Math.max(0,s.length-1)),{from:c,to:m}=R(s.length,a,r),f=Math.max(8,t-4);return Te(bt,{flexDirection:"column",children:[s.length===0?Te(V,{color:o.muted,wrap:"truncate",children:[" ","nothing you have sent matches that"]}):s.slice(c,m).map((b,v)=>{let x=c+v===a;return Te(V,{wrap:"truncate",children:[he(V,{color:o.accent,children:x?u.pointer:" "}),he(V,{bold:x,dimColor:!x,children:S(b.replace(/\s+/g," "),f)})]},b)}),Te(V,{wrap:"truncate",children:[he(V,{color:o.muted,children:" search: "}),i.query,he(V,{inverse:!0,children:" "}),s.length>1?he(V,{color:o.muted,children:` ${a+1} of ${s.length}`}):null]})]})}import{Box as yt,Text as dn}from"ink";import{jsxs as Ie}from"react/jsx-runtime";function ln({live:n,showReasoning:t,columns:r}){let i=t&&n.reasoning!==""&&n.text==="",s=i?n.reasoning:n.text;if(s==="")return null;let a=i?"· reasoning · ":"",c=tr(s,r-[...a].length,rr),m=c.lines.map((f,b)=>({at:b,text:f}));return Ie(yt,{flexDirection:"column",children:[c.hidden>0?Ie(dn,{dimColor:!0,wrap:"truncate",children:["… ",c.hidden," earlier row(s) hidden while streaming"]}):null,m.map((f)=>Ie(dn,{dimColor:i,wrap:"truncate",children:[f.at===0?a:"",f.text]},`row-${f.at}`))]})}import{Box as St,Text as Y}from"ink";import{jsx as De,jsxs as ae}from"react/jsx-runtime";function Tt(n){return n.matches.reduce((t,r)=>Math.max(t,r.word.length),0)}function cn({palette:n,index:t,width:r,maxRows:i}){if(n.matches.length===0)return ae(Y,{color:o.muted,wrap:"truncate",children:[" ","no command starts with /",n.query]});let s=Math.min(t,n.matches.length-1),{from:a,to:c}=R(n.matches.length,s,i),m=Tt(n),f=Math.max(8,r-(2+m+2));return ae(St,{flexDirection:"column",children:[a>0?ae(Y,{dimColor:!0,wrap:"truncate",children:[" ",u.ellipsis," ",a," above"]}):null,n.matches.slice(a,c).map((b,v)=>{let M=a+v===s;return ae(Y,{wrap:"truncate",children:[De(Y,{color:o.accent,children:M?u.pointer:" "}),De(Y,{bold:M,...M?{color:o.accent}:{},children:b.word.padEnd(m)})," ",De(Y,{dimColor:!0,children:S(b.summary,f)})]},b.word)}),c<n.matches.length?ae(Y,{dimColor:!0,wrap:"truncate",children:[" ",u.ellipsis," ",n.matches.length-c," below"]}):null,ae(Y,{dimColor:!0,wrap:"truncate",children:[" ","↑↓ move · tab complete · enter run · esc close"]})]})}import{Box as un,Text as kt}from"ink";import{jsx as pn,jsxs as xn}from"react/jsx-runtime";function gn({editor:n,busy:t,placeholder:r,columns:i}){let s=n.value.split(`
|
|
3
|
+
`).length,a=Math.max(1,i-4);return xn(un,{flexDirection:"column",children:[pn(un,{borderStyle:oe,borderColor:t?o.border:o.borderActive,width:i,paddingX:1,children:pn(hn,{editor:n,gutter:Sn,maxRows:Tn,columns:a,...r===void 0?{}:{placeholder:r}})}),s>1?xn(kt,{dimColor:!0,wrap:"truncate",children:[" ",fo]}):null]})}import{Text as ke}from"ink";import{jsx as yn,jsxs as bn}from"react/jsx-runtime";var Rt={idle:"ready",thinking:"thinking",streaming:"replying",working:"running a tool",cancelling:"cancelling"};function Pt(n){return`${(n/1000).toFixed(1)}s`}function wn(n,t){if(n!=="idle")return" · ^C cancels";return t?" · ^C again to leave":" · ^C twice to leave · /exit"}function Et(n){if(n!=="idle")return"";return" · ^O show reasoning"}var vt=0.5,Ct=0.8;function kn({status:n,model:t,sessionKey:r,elapsedMs:i,last:s,quiet:a,armed:c,pressure:m,phase:f}){return bn(ke,{dimColor:!0,wrap:"truncate",children:[bn(ke,{color:zo[n],children:[u.dot,Rt[n]]}),n==="idle"?"":` ${Pt(i)}`,` · ${t} · ${r}`,f===void 0||a?"":` · ${f}`,m===void 0||m<vt||a?"":yn(ke,{...m>=Ct?{color:o.warning}:{},children:` · ctx ${Math.round(m*100)}%`}),s===void 0||a?"":` · last ${fr(s)}`,Et(n),c===!0?yn(ke,{color:o.warning,children:wn(n,!0)}):wn(n,!1)]})}import{Box as $t,Text as Re}from"ink";var z={offset:0,pinned:!0};function Rn(n,t){return Math.max(0,n-t)}function Pn(n,t,r){let i=Rn(t,r);return n.pinned?i:Math.max(0,Math.min(n.offset,i))}function En(n,t,r,i){if(t==="bottom")return z;let s=Rn(r,i);if(s===0)return z;if(t==="top")return{offset:0,pinned:!1};let a=t==="pageUp"||t==="pageDown"?Math.max(1,i-1):1,c=t==="down"||t==="pageDown"?a:-a,m=Pn(n,r,i)+c;if(m>=s)return z;return{offset:Math.max(0,m),pinned:!1}}function Mn(n,t,r){if(r<=0)return{from:0,to:0,above:t,below:0};let i=Pn(n,t,r),s=Math.min(t,i+r);return{from:i,to:s,above:i,below:t-s}}function vn(n,t){return Math.max(ns,n-t-1)}function Cn(n){let t=[];if(n.above>0)t.push(`↑ ${n.above} row${n.above===1?"":"s"} above`);if(n.below>0)t.push(`↓ ${n.below} row${n.below===1?"":"s"} below`,"esc returns");return t.length===0?"":` ${t.join(" · ")}`}function An(n){return{anchor:n,focus:n,dragging:!0}}function He(n,t){if(!n.dragging)return n;return{...n,focus:t}}function _n(n){return{...n,dragging:!1}}function $n(n,t){return{...n,focus:t,dragging:!1}}function At(n,t){return n.row<t.row||n.row===t.row&&n.column<=t.column}function Ln(n){if(n===void 0)return;let{anchor:t,focus:r}=n;if(t.row===r.row&&t.column===r.column)return;return At(t,r)?{start:t,end:r}:{start:r,end:t}}function We(n,t,r){let i=Ln(n);if(i===void 0)return;if(t<i.start.row||t>i.end.row)return;let s=t===i.start.row?Math.min(i.start.column,r):0,a=t===i.end.row?Math.min(i.end.column,r):r;return a<=s?void 0:{from:s,to:a}}function Bn(n,t){let r=Ln(t);if(r===void 0)return"";let i=[];for(let s=r.start.row;s<=r.end.row;s+=1){let a=n[s];if(a===void 0)continue;let c=[...a.text],m=We(t,s,c.length),f=m===void 0?"":c.slice(Math.max(m.from,a.lead),m.to).join("");if(a.continuation&&i.length>0){i[i.length-1]+=f;continue}i.push(f)}return i.map((s)=>s.replace(/\s+$/,"")).join(`
|
|
4
|
+
`)}function Ne(n){return n!==void 0&&!/\s/.test(n)}function On(n,t){let r=n[t.row];if(r===void 0)return{anchor:t,focus:t,dragging:!1};let i=[...r.text];if(!Ne(i[t.column]))return Fe(n,t);let{column:s,column:a}=t;while(s>r.lead&&Ne(i[s-1]))s-=1;while(a<i.length&&Ne(i[a]))a+=1;return{anchor:{row:t.row,column:s},focus:{row:t.row,column:a},dragging:!1}}function Fe(n,t){let r=n[t.row],i=r===void 0?0:[...r.text].length;return{anchor:{row:t.row,column:r?.lead??0},focus:{row:t.row,column:i},dragging:!1}}import{jsx as Ge,jsxs as In}from"react/jsx-runtime";function Dn({rows:n,slice:t,selection:r}){let i=n.slice(t.from,t.to),s=Cn(t);return In($t,{flexDirection:"column",children:[Ge(Re,{color:o.muted,wrap:"truncate",children:s===""?" ":s}),i.map((a,c)=>{let m=a.dim===!0?o.muted:Bo[a.role],f=[...a.text],b=We(r,t.from+c,f.length);if(b===void 0)return Ge(Re,{wrap:"truncate",bold:a.bold===!0,...m===void 0?{}:{color:m},children:a.text===""?" ":a.text},a.key);let v=Math.max(b.from,a.lead);return In(Re,{wrap:"truncate",bold:a.bold===!0,...m===void 0?{}:{color:m},children:[f.slice(0,v).join(""),Ge(Re,{backgroundColor:o.selection,children:f.slice(v,b.to).join("")}),f.slice(b.to).join("")]},a.key)})]})}import{useEffect as Bt,useState as Ot}from"react";var It=100;function Nn(n){let[t,r]=Ot(0);return Bt(()=>{if(!n){r(0);return}let i=Date.now();r(0);let s=setInterval(()=>r(Date.now()-i),It);return()=>clearInterval(s)},[n]),t}import{useCallback as Pe,useEffect as Dt,useReducer as Nt,useRef as Hn}from"react";function Wn(n){let{source:t,sessionKey:r,initial:i}=n,[s,a]=Nt(mo,i),c=Hn(void 0),m=Hn(t.streamFilter());Dt(()=>t.subscribe((x)=>{if(x.sessionKey!==void 0&&x.sessionKey!==r)return;if(x.type==="model.chunk"){let{delta:I,kind:N}=x.data;if(N==="reasoning"){a({kind:"delta",of:"reasoning",text:I});return}a({kind:"delta",of:"text",text:m.current.push(I)});return}if(x.type==="model.result"){a({kind:"delta",of:"text",text:m.current.endStep()});return}if(x.type==="turn.end")a({kind:"delta",of:"text",text:m.current.end()}),m.current=t.streamFilter();a({kind:"event",event:x})}),[t,r]);let f=Pe((x)=>{a({kind:"user",text:x});let I=new AbortController;c.current=I,t.send(x,{sessionKey:r,signal:I.signal}).catch((N)=>{a({kind:"event",event:{v:1,ts:new Date().toISOString(),runtimeId:"cli",sessionKey:r,type:"error",data:{code:"cli_turn_failed",message:N instanceof Error?N.message:String(N),hint:"This escaped the turn loop's own error handling. Re-run with DEBUG=1 for a stack trace."}}})}).finally(()=>{if(c.current===I)c.current=void 0})},[t,r]),b=Pe(()=>{let x=c.current;if(x===void 0||x.signal.aborted)return;a({kind:"cancelling"}),x.abort()},[]),v=Pe((x)=>a({kind:"note",text:x}),[]),M=Pe(()=>a({kind:"trim"}),[]);return{state:s,busy:s.status!=="idle",send:f,cancel:b,note:v,trim:M}}var Fn=1,Gn=1,Ye=1,Un=2,Ue=4,Ve=2,Ht=14;function Vn(n,t){let{rows:r,caretRow:i}=fn(n,Math.max(1,t-Ue-Ve)),s=r.length,{from:a,to:c}=R(s,i,Math.max(1,Math.min(s,Tn)));return Un+(c-a)+(a>0?1:0)+(s-c>0?1:0)+(n.value.includes(`
|
|
5
|
+
`)?1:0)}function Wt(n,t){if(n===void 0)return 0;if(n.matches.length===0)return 1;let r=Math.min(n.matches.length,t),i=n.matches.length>r?1:0;return r+i+1}function Gt(n,t){if(n.search===void 0)return 0;let r=Mt(n);return(r.length===0?1:Math.min(r.length,t))+1}function Yn(n){let t=n.live,r=t===void 0?"":n.showReasoning&&t.reasoning!==""&&t.text===""?t.reasoning:t.text,i=Fn+Gn+tr(r,n.columns-Ht,rr).rows+Wt(n.palette,n.paletteMaxRows)+Gt(n.editor,n.searchMaxRows)+Vn(n.editor,n.columns)+(n.confirming?1:0)+(n.hint?1:0),s=vn(n.rows,i);return{brand:n.landing?Math.max(0,s-os-or):0,body:s,transcript:Math.max(1,s-Ye),pane:Math.max(1,s-3)}}function Xn(n,t){let r=(t.brandLines===0?0:t.brandLines+or)+Fn+Ye,i=n.row-r;if(i<0)return;let s=t.from+i;if(s>=t.to)return;return{row:s,column:n.column}}function Kn(n,t){let r=fn(t.editor,Math.max(1,t.columns-Ue-Ve)),i=r.rows.length,{from:s,to:a}=R(i,r.caretRow,Math.max(1,Math.min(i,Tn))),c=s>0?1:0,m=Vn(t.editor,t.columns),b=t.rows-Gn-(t.hint?1:0)-m+Un/2+c,v=n.row-b;if(v<0||v>=a-s)return;let M=r.rows[s+v];if(M===void 0)return;let x=n.column-Ue/2-Ve;if(x<0)return M.start;return Math.min(M.end,M.start+Math.max(0,x-M.lead))}function jn(n,t){let r=t===0?0:t+or;return Math.max(1,n.body-r-Ye)}var Ut=[{command:"pbcopy",args:[]},{command:"wl-copy",args:[]},{command:"xclip",args:["-selection","clipboard"]},{command:"xsel",args:["--clipboard","--input"]}];async function Xe(n){if(n==="")return{copied:!1,problem:"nothing selected"};let t=[];for(let r of Ut){let i=await pe({command:r.command,args:r.args,input:n,timeoutMs:2000});if(i.notFound){t.push(r.command);continue}if(i.code===0)return{copied:!0,using:r.command};return{copied:!1,using:r.command,problem:i.stderr.trim()||`${r.command} exited ${i.code}`}}return{copied:!1,problem:`no clipboard command found (tried ${t.join(", ")})`}}function Ee(){let n=qn.map((i)=>({word:i.word,summary:i.summary,kind:"session"})),t=new Set(n.map((i)=>i.word)),r=le.filter((i)=>i.inSession!=="hidden").filter((i)=>!t.has(`/${i.name}`)).map((i)=>({word:`/${i.name}`,summary:i.summary,kind:i.inSession==="view"?"view":"output",spec:i}));return[...n,...r]}function zn(n,t=Ee()){if(!/^\/[A-Za-z-]*$/.test(n))return;let r=n.slice(1).toLowerCase(),i=t.filter((s)=>s.word.slice(1).toLowerCase().startsWith(r));return{query:r,matches:i}}function Ke(n,t){if(n.matches.length===0)return;return n.matches[Math.max(0,Math.min(t,n.matches.length-1))]}function Zn(){return Ee().filter((n)=>n.kind!=="session").map((n)=>n.word.slice(1))}function Vt(n){return _t(n)?.args.findIndex((t)=>t.name==="manifest")??-1}function Kt(n){let t=n.rest.trim()===""?[]:n.rest.trim().split(/\s+/),r=Vt(n.name),i=r===-1||t.length<r?t:[...t.slice(0,r),n.manifestPath,...t.slice(r)];return[n.name,...i,"--plain"]}function jt(n){let t=_t(n.name);if(t===void 0)return;let r=t.flags.find((a)=>a.name==="follow");if(r===void 0)return;if(!n.rest.trim().split(/\s+/).some((a)=>a==="--follow"||r.short!==void 0&&a===`-${r.short}`))return;return`--follow keeps printing until it is interrupted, and a pane has nothing to interrupt it with. Run it in its own terminal: ${n.name} ${n.rest.trim()}`}async function Qn(n){let t=jt(n);if(t!==void 0)return{lines:[t],code:1};let r=n.interpreter??process.execPath,i=n.script??process.argv[1]??"",s=await pe({command:r,args:[i,...Kt(n)],...n.env===void 0?{}:{env:n.env},timeoutMs:n.timeoutMs??30000}),a=[s.stdout,s.stderr].filter((m)=>m.trim()!=="").join(`
|
|
6
|
+
`),c=a===""?[]:a.replace(/\n+$/,"").split(`
|
|
7
|
+
`);if(s.notFound)return{lines:[`could not run ${r}`],code:1};if(s.signalled)return{lines:[...c,`${n.name} was stopped before it finished`],code:1};return{lines:c,code:s.code}}import{jsx as w,jsxs as Q,Fragment as qt}from"react/jsx-runtime";function qr({source:n,sessionKey:t,model:r,agentName:i,warnings:s,freshSession:a,initial:c,correctKeys:m,showReasoning:f,quiet:b,onRestart:v,onSwitch:M,onNew:x,sessions:I,initialDraft:N,manifestPath:F,catalogue:ce,status:je,contextView:ze}){let{exit:q}=zt(),ee=re(),P=Z(ee.columns,U),{state:C,busy:xe,send:at,cancel:dt,note:g,trim:Ze}=Wn({source:n,sessionKey:t,initial:c}),[B,H]=O(()=>N===void 0||N===""?D:{...D,value:N,cursor:[...N].length}),[k,L]=O({kind:"none"}),[Je,lt]=O(void 0),[Qe,ct]=O(void 0),[qe,ut]=O(void 0),[ge,Me]=O(z),[ue,ve]=O(!1),[Ce,nn]=O(!1),[tn,mt]=O(!1),[ne,K]=O(void 0),Ae=Zt(void 0),G=k.kind==="none"?zn(B.value):void 0,[_e,we]=O(0),ft=Nn(xe),pt=rt(()=>wo(C.items),[C.items]),te=rt(()=>bo(C.items,{showReasoning:f,quiet:b,columns:P,expandReasoning:tn}),[C.items,f,b,P,tn]),ie=a===!0&&!C.items.some((h)=>h.role==="user"),be=ie?rs:Jo,se=Yn({rows:ee.rows,columns:P,editor:B,live:C.live,showReasoning:f,palette:G,paletteMaxRows:be,searchMaxRows:be,confirming:Ce,landing:ie,hint:ie}),ye=se.brand>0?en(e.name,{columns:P-it,rows:se.brand}):void 0,$e=Mn(ge,te.length,jn(se,ye?.lines.length??0));tt(()=>{if(!ge.pinned)return;K(void 0),Ze()},[ge.pinned,C.items.length,Ze]),tt(()=>{if(!ue)return;let h=setTimeout(()=>ve(!1),as);return()=>clearTimeout(h)},[ue]);let on=(h,y)=>{let p=Xt(h,Zn());if(p!==void 0)switch(p.kind){case"exit":nn(!0);return;case"restart":{let d=n.reload;if(d===void 0){v?.(y),q();return}g("asking the host to reload this agent…"),d().then((l)=>g(`reloaded ${l.join(", ")} — this conversation continues`)).catch((l)=>g(`could not reload: ${l instanceof Error?l.message:String(l)}`));return}case"new":x?.(y),q();return;case"help":g(Jt());return;case"tools":n.tools().then((d)=>g(st(d))).catch((d)=>g(`could not read the tools: ${d instanceof Error?d.message:String(d)}`));return;case"context":if(ze===void 0){g("context is unavailable in this session");return}ze().then(g).catch((d)=>g(`could not read the context: ${d instanceof Error?d.message:String(d)}`));return;case"status":if(je===void 0){g("status is unavailable in this session");return}je().then(g).catch((d)=>g(`could not read the status: ${d instanceof Error?d.message:String(d)}`));return;case"reset":n.clearSession(t).then(()=>g("session cleared — memory files on disk are untouched")).catch((d)=>g(`could not clear the session: ${d instanceof Error?d.message:String(d)}`));return;case"command":if(rn(`/${p.name}`,p.rest))return;g(xt({word:`/${p.name}`}));return;case"unknown":g(xt(p));return}if(xe){g("a turn is still running — ^C cancels it, then send again");return}at(h)},Le=nt((h,y)=>{L({kind:"output",label:`/${h}`,lines:void 0,offset:0}),Qn({name:h,rest:y,manifestPath:F??""}).then((p)=>L({kind:"output",label:`/${h}`,lines:p.lines,code:p.code,offset:0})).catch((p)=>L({kind:"output",label:`/${h}`,lines:[p instanceof Error?p.message:String(p)],code:1,offset:0}))},[F]),rn=nt((h,y)=>{let p=Ee().find((d)=>d.word===h);if(p===void 0)return!1;if(p.kind==="view"){if(p.word==="/sessions"&&I!==void 0&&M!==void 0)return L({kind:"sessions",stored:void 0}),import("./SessionPicker-z2t0p4b5.js").then((d)=>ut(()=>d.SessionPicker)),I().then((d)=>L({kind:"sessions",stored:d})).catch((d)=>{L({kind:"none"}),g(`could not read the stored conversations: ${d instanceof Error?d.message:String(d)}`)}),!0;if(p.word==="/config"&&(y.trim()===""||y.trim()==="edit")){if(F===void 0)return g("this session has no manifest path, so there is nothing to edit"),!0;return L({kind:"config",rows:ot(F)}),import("./ConfigEditor-7v5nebvy.js").then((d)=>ct(()=>d.ConfigEditor)),!0}if(p.word==="/skills"&&ce!==void 0)return L({kind:"skills"}),import("./SkillBrowser-yyf2gy0q.js").then((d)=>lt(()=>d.SkillBrowser)),!0;return Le(p.word.slice(1),y),!0}if(p.kind==="output")return Le(p.word.slice(1),y),!0;return!1},[Le,ce,I,M,g,F]);if(et((h,y)=>{if(k.kind!=="output")return;if(y.escape||h==="q"){L({kind:"none"});return}let p=k.lines?.length??0,d=y.pageDown||y.pageUp?se.pane:1,l=y.downArrow||y.pageDown?d:y.upArrow||y.pageUp?-d:0;if(l!==0)L({...k,offset:Math.max(0,Math.min(k.offset+l,Math.max(0,p-1)))})},{isActive:k.kind==="output"}),et((h,y)=>{let p=m===void 0?y:m(y,h);if(Ce){if(nn(!1),h.toLowerCase()==="y"||p.return)q();return}if(G!==void 0){if(p.escape){H((E)=>X(E,{kind:"killToStart"})),we(0);return}if(p.upArrow||p.downArrow){we((E)=>Math.max(0,Math.min(E+(p.downArrow?1:-1),G.matches.length-1)));return}if(p.tab){let E=Ke(G,_e);if(E!==void 0)H((_)=>X({..._,value:"",cursor:0},{kind:"insert",text:E.word}));return}let l=Ke(G,_e);if(p.return&&l!==void 0){let E=l;if(we(0),H((_)=>({..._,value:"",cursor:0})),E.kind==="session")on(E.word,"");else rn(E.word,"");return}}let d=Lt(h,p,mn(B,xe,{armed:ue,scrolled:!ge.pinned}));if(ue&&d.kind!=="exit")ve(!1);if(d.kind==="arm"){ve(!0);return}if(d.kind==="scroll"){let l=Math.max(1,d.times??1);Me((E)=>{let _=E;for(let T=0;T<l;T+=1)_=En(_,d.move,te.length,se.transcript);return _});return}if(d.kind==="pointer"){let l=Xn({column:d.column,row:d.row},{brandLines:ye?.lines.length??0,from:$e.from,to:$e.to});if(l===void 0){let T=Kn({column:d.column,row:d.row},{editor:B,columns:P,rows:ee.rows,hint:ie});if(T===void 0){if(d.gesture==="press")K(void 0),H((j)=>({...j,anchor:void 0}));return}K(void 0),H((j)=>d.gesture==="press"&&!d.shift?{...j,cursor:T,anchor:T}:{...j,cursor:T,anchor:j.anchor??j.cursor});return}if(d.gesture==="press"){if(d.shift&&ne!==void 0){K($n(ne,l)),Ae.current=void 0;return}let T=Ae.current,Be=T!==void 0&&Date.now()-T.when<=ss&&T.at.row===l.row&&T.at.column===l.column?T.clicks%3+1:1;Ae.current={at:l,when:Date.now(),clicks:Be},H((wt)=>({...wt,anchor:void 0})),K(Be===3?Fe(te,l):Be===2?On(te,l):An(l));return}if(d.gesture==="drag"){K((T)=>T===void 0?void 0:He(T,l));return}let E=ne===void 0?void 0:_n(He(ne,l));K(E);let _=Bn(te,E);if(_!=="")Xe(_).then((T)=>{if(!T.copied&&T.problem!=="nothing selected")g(`could not copy: ${T.problem??"unknown"}`)});return}if(d.kind==="copySelection"||d.kind==="cutSelection"){let l=gt(B);if(l===void 0){g("nothing selected — hold shift with a motion, or drag in the box");return}let E=[...B.value].slice(l.start,l.end).join("");if(d.kind==="cutSelection")H((_)=>X(_,d));Xe(E).then((_)=>{if(!_.copied)g(`could not copy: ${_.problem??"unknown"}`)});return}if(d.kind==="reasoning"){if(!f){g("reasoning is off: either this model does not stream it, or --no-reasoning is set");return}if(!C.items.some((l)=>l.role==="reasoning")){g("no reasoning to show yet — this expands it once a turn has streamed some");return}mt((l)=>!l),Me(z);return}if(d.kind==="exit"){q();return}if(d.kind==="cancel"){dt();return}if(d.kind==="submit"){let l=Po(B);if(H(l.state),Me(z),l.text!=="")on(l.text,l.state.value);return}if(d.kind==="paste"){H((l)=>X(l,{kind:"insert",text:d.lines.join(`
|
|
8
|
+
`)}));return}if(G!==void 0)we(0);H((l)=>X(l,d))},{isActive:k.kind==="none"}),k.kind==="config")return Q(W,{flexDirection:"column",width:P,height:ee.rows,children:[w(J,{color:o.accent,bold:!0,wrap:"truncate",children:Jn({title:`${e.name} ${A}`,summary:"settings"},P)}),Qe===void 0?w(W,{marginLeft:2,children:w(de,{label:"reading the settings"})}):w(Qe,{rows:k.rows,apply:(h,y)=>Yt(F??"",h,y),reload:()=>ot(F??""),columns:P,window:Ft,onDone:(h)=>{if(L({kind:"none"}),h)v?.(B.value),q()}}),w(W,{flexGrow:1})]});if(k.kind==="sessions")return Q(W,{flexDirection:"column",width:P,height:ee.rows,children:[w(J,{color:o.accent,bold:!0,wrap:"truncate",children:Jn({title:`${e.name} ${A}`,summary:"pick a conversation"},P)}),w(W,{flexGrow:1}),k.stored===void 0||qe===void 0?w(W,{marginLeft:2,children:w(de,{label:"reading the stored conversations"})}):w(qe,{sessions:k.stored,now:Date.now(),columns:P,maxRows:Ft,current:t,onDone:(h)=>{if(h===void 0||h===t){L({kind:"none"});return}M?.(h,B.value),q()}}),w(W,{flexGrow:1})]});if(k.kind==="skills"&&ce!==void 0&&Je!==void 0)return w(Je,{title:`${e.name} ${A}`,agents:[],target:F??"",load:ce.load,install:ce.install,onDone:()=>L({kind:"none"})});let ht=Jn({title:`${e.name} ${A}`,summary:"",agent:{name:i,model:r},...s===void 0||s.length===0?{}:{warnings:s}},P);return Q(W,{flexDirection:"column",width:P,height:ee.rows,children:[ye===void 0?null:Q(qt,{children:[w(Qt,{lines:ye.lines}),w(J,{children:" "})]}),w(J,{color:o.accent,bold:!0,wrap:"truncate",children:ht}),k.kind==="output"?Q(W,{flexDirection:"column",children:[w(sn,{lines:k.lines,label:k.label,offset:k.offset,maxRows:se.pane,...k.code===void 0?{}:{code:k.code}}),Q(J,{dimColor:!0,wrap:"truncate",children:[" ","↑↓ scroll · esc back to the prompt"]})]}):w(Dn,{rows:te,slice:$e,...ne===void 0?{}:{selection:ne}}),w(W,{flexGrow:1}),C.live===void 0?null:w(ln,{live:C.live,showReasoning:f,columns:P}),G===void 0?null:w(cn,{palette:G,index:_e,width:P,maxRows:be}),w(an,{editor:B,width:P,maxRows:be}),Ce?w(J,{color:o.warning,wrap:"truncate",children:" leave this session? press y to confirm · any other key stays"}):null,w(gn,{editor:B,busy:xe,columns:P,...ie?{placeholder:"Ask anything…"}:{}}),ie?Q(J,{dimColor:!0,wrap:"truncate",children:[" ",ho]}):null,w(kn,{status:C.status,model:r,sessionKey:t,elapsedMs:ft,last:pt,quiet:b,armed:ue,...C.pressure===void 0?{}:{pressure:C.pressure},...C.phase===void 0?{}:{phase:C.phase}})]})}export{qr as App};
|
|
9
|
+
|
|
10
|
+
//# debugId=F5B3369F1640538C64756E2164756E21
|
|
11
|
+
//# sourceMappingURL=App-dxqm39zx.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/components/App.tsx", "../src/components/CommandOutput.tsx", "../src/components/HistorySearch.tsx", "../src/components/Live.tsx", "../src/components/Palette.tsx", "../src/components/Prompt.tsx", "../src/components/StatusBar.tsx", "../src/components/Transcript.tsx", "../src/lib/scroll.ts", "../src/lib/text-selection.ts", "../src/hooks/useElapsed.ts", "../src/hooks/useTurn.ts", "../src/lib/chat-frame.ts", "../src/lib/clipboard.ts", "../src/lib/palette.ts", "../src/lib/subcommand.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * The chat surface — a full-screen session on the alternate buffer.\n *\n * Thin on purpose. Everything worth testing lives in pure modules — `keymap.ts` decides what a keystroke\n * means, `editor.ts` applies it to the line, `transcript.ts` turns bus events into rows, `lib/scroll.ts`\n * moves the window, `lib/chat-frame.ts` decides how many rows each part of the frame may have — so this\n * file is composition plus the decisions that need Ink itself: when to unmount, what to do about a\n * submission arriving mid-turn, and which surface currently owns the keyboard.\n *\n * ## What Phase 5.5 changed here\n *\n * The conversation is no longer in `<Static>`. It is a buffer of rows with a window over it, because\n * `<Static>` writes to the scrollback and the alternate screen discards its buffer on the way out — the\n * two cannot both be true. That has two consequences worth stating before editing:\n *\n * - **The frame has a hard height.** Everything visible must add up to at most the terminal's rows, or\n * Ink's own output scrolls the buffer and the layout comes apart. `chatFrame` owns that arithmetic; no\n * row count is invented in this file.\n * - **^C at an idle prompt takes two presses.** With the buffer discarded on exit, a single reflexive ^C\n * during a long reply would throw the visible conversation away. `keymap.ts` owns the decision; the\n * timer that expires it lives here, because a pure function cannot hold a clock.\n *\n * The Ctrl-C contract from Phase 1 is otherwise unchanged: during a turn it cancels the turn and the\n * prompt comes back.\n */\n\nimport { BRAND, VERSION } from \"@dispach/core\"\nimport { Box, Text, useApp, useInput } from \"ink\"\nimport { type ComponentType, useCallback, useEffect, useMemo, useRef, useState } from \"react\"\nimport { BRAND_INDENT, Brandmark } from \"#components/Brandmark\"\nimport { CommandOutput } from \"#components/CommandOutput\"\nimport type { ConfigEditorProps } from \"#components/ConfigEditor\"\nimport { HistorySearch } from \"#components/HistorySearch\"\nimport { Live } from \"#components/Live\"\nimport { Palette } from \"#components/Palette\"\nimport { Prompt } from \"#components/Prompt\"\nimport type { SessionPickerProps } from \"#components/SessionPicker\"\nimport type { SkillBrowserProps } from \"#components/SkillBrowser\"\nimport { Spinner } from \"#components/Spinner\"\nimport { StatusBar } from \"#components/StatusBar\"\nimport { Transcript } from \"#components/Transcript\"\nimport { applyIntent, EMPTY_EDITOR, selectionRange, submit } from \"#editor\"\nimport { useElapsed } from \"#hooks/useElapsed\"\nimport { useTerminalSize } from \"#hooks/useTerminalSize\"\nimport { useTurn } from \"#hooks/useTurn\"\nimport { keyContext, keyToIntent } from \"#keymap\"\nimport { chatFrame, composerHit, transcriptHit, transcriptRowsAfterBrand } from \"#lib/chat-frame\"\nimport { copyToClipboard } from \"#lib/clipboard\"\nimport type { EditorRow } from \"#lib/config-editor\"\nimport { applyEditorRow, editorRowsFor } from \"#lib/config-rows\"\nimport {\n EXIT_ARM_MS,\n FALLBACK_COLUMNS,\n LANDING_LIST_ROWS,\n MULTI_CLICK_MS,\n SEARCH_ROWS,\n SESSION_PICKER_ROWS,\n} from \"#lib/const\"\nimport { offeredCommands, paletteEntries, paletteFor, paletteSelection } from \"#lib/palette\"\nimport type { AppProps } from \"#lib/schema\"\nimport { screenColumns, titleLine } from \"#lib/screen\"\nimport { FOLLOWING, scroll, slice } from \"#lib/scroll\"\nimport {\n NEW_SESSION_HINT,\n resolveSessionCommand,\n sessionHelpText,\n type ToolsView,\n toolsReport,\n unknownCommandText,\n} from \"#lib/session-commands\"\nimport type { SessionRowSource } from \"#lib/sessions-view\"\nimport { runSubcommand } from \"#lib/subcommand\"\nimport {\n beginSelection,\n dragSelection,\n endSelection,\n extendSelection,\n lineAt,\n selectedText,\n type TextPoint,\n type TextSelection,\n wordAt,\n} from \"#lib/text-selection\"\nimport { THEME } from \"#lib/theme\"\nimport { wordmark } from \"#lib/wordmark\"\nimport { lastStats, transcriptRows } from \"#transcript\"\n\n/**\n * What is layered over the conversation.\n *\n * `output` is a command's captured text; `skills` is the one bespoke view a session hosts so far. Both\n * take the keyboard while open and both *replace* the transcript rather than sitting under it — sharing\n * the screen pushed the conversation off the top of a full-screen frame, which on a surface with no\n * scrollback means gone. Closing either returns to the prompt with the draft untouched, which is what\n * makes a pane an interlude rather than a detour.\n */\ntype Pane =\n | { readonly kind: \"none\" }\n | {\n readonly kind: \"output\"\n readonly label: string\n readonly lines: readonly string[] | undefined\n readonly code?: number\n readonly offset: number\n }\n | { readonly kind: \"skills\" }\n /**\n * The conversation switcher. `undefined` while the store is being read.\n *\n * Loaded when the pane opens rather than kept current, because the list changes only when a turn ends\n * and re-reading it on every frame would put a database query in the render path.\n */\n | { readonly kind: \"sessions\"; readonly stored: readonly SessionRowSource[] | undefined }\n /**\n * The settings editor. `rows` is read when the pane opens, not kept current.\n *\n * Read once because the editor re-reads after each write of its own — keeping it live here would put\n * a file read in the render path for a surface that already knows when it has changed something.\n */\n | { readonly kind: \"config\"; readonly rows: readonly EditorRow[] }\n\nexport function App({\n source,\n sessionKey,\n model,\n agentName,\n warnings,\n freshSession,\n initial,\n correctKeys,\n showReasoning,\n quiet,\n onRestart,\n onSwitch,\n onNew,\n sessions,\n initialDraft,\n manifestPath,\n catalogue,\n status,\n contextView,\n}: AppProps) {\n const { exit } = useApp()\n const size = useTerminalSize()\n const columns = screenColumns(size.columns, FALLBACK_COLUMNS)\n const { state, busy, send, cancel, note, trim } = useTurn({ source, sessionKey, initial })\n // A draft handed in by a `/restart` opens the prompt with the cursor at its end, which is where the\n // person left it. Only the initial value — a later prop change must not overwrite what is being\n // typed now, which is exactly what `useState`'s initialiser semantics give for free.\n const [editor, setEditor] = useState(() =>\n initialDraft === undefined || initialDraft === \"\"\n ? EMPTY_EDITOR\n : { ...EMPTY_EDITOR, value: initialDraft, cursor: [...initialDraft].length },\n )\n\n /**\n * What is on top of the conversation, if anything.\n *\n * A pane is *focused* while it is open, so the prompt's `useInput` stands down — Ink fires every\n * active hook, and two surfaces reading one keystroke is the bug the focus rule exists to prevent.\n */\n const [pane, setPane] = useState<Pane>({ kind: \"none\" })\n /**\n * The skills view's implementation, loaded when it is first opened.\n *\n * Dynamically, and that is not an optimisation. `browse.ts` also imports this component dynamically,\n * and bun's `--splitting` emits a module's exports **twice** when one importer is static and another is\n * dynamic — producing a bundle that dies at parse time with `Duplicate export of 'SkillBrowser'`, which\n * no test that imports source can see. The props come in as a type, which is erased and creates no\n * edge. `boundaries.test.ts` bans the mixing outright.\n */\n const [Browser, setBrowser] = useState<ComponentType<SkillBrowserProps> | undefined>(undefined)\n /**\n * The session switcher's implementation, loaded when the pane first opens.\n *\n * Dynamically for the same reason `Browser` is, and it was caught by the boundaries test rather than\n * remembered: `run.ts` mounts this component too, for a bare `--session` before any chat exists. One\n * static importer and one dynamic one makes bun's `--splitting` emit its exports **twice**, and the\n * built binary then dies at parse time with `Duplicate export of 'SessionPicker'` while every test —\n * which imports source — passes. Both edges dynamic, no duplicate.\n */\n const [Editor, setEditor_] = useState<ComponentType<ConfigEditorProps> | undefined>(undefined)\n const [Sessions, setSessions] = useState<ComponentType<SessionPickerProps> | undefined>(\n undefined,\n )\n /** Where the conversation window sits. Starts and returns to following the newest row. */\n const [view, setView] = useState(FOLLOWING)\n /** A first ^C has landed. Expires, which is why it is here and not in the keymap. */\n const [armed, setArmed] = useState(false)\n /** `/exit` asked; the next keystroke answers. `undefined` means nothing is being confirmed. */\n const [confirming, setConfirming] = useState(false)\n /**\n * Reasoning shown whole rather than folded to a count. Session-wide, and `⌥r` toggles it.\n *\n * Folded is the default because a real turn produced a twenty-three-row block for a one-sentence\n * answer, which filled the terminal and left the reply itself somewhere above the fold.\n */\n const [expandReasoning, setExpandReasoning] = useState(false)\n /**\n * The mouse selection over the transcript, in buffer coordinates.\n *\n * Cleared by eviction below rather than re-keyed: rows are addressed by position, so dropping any from\n * the front shifts every index — a selection kept across a trim would silently start covering different\n * text, which is the \"looks live and is not\" failure `pinned` exists to prevent. There is also nothing\n * to copy from rows that no longer exist.\n */\n const [selection, setSelection] = useState<TextSelection | undefined>(undefined)\n /**\n * The previous press, for counting clicks.\n *\n * A ref rather than state: nothing renders from it, and putting it in state would redraw the whole tree\n * on every press. Multi-click has to be inferred from time and position because a terminal reports\n * three presses and never a \"double click\" — the same reason the reference CLI keeps its own window.\n */\n const lastPress = useRef<{ at: TextPoint; when: number; clicks: number } | undefined>(undefined)\n // Derived from the buffer rather than stored, so the only palette state is where the cursor is.\n const palette = pane.kind === \"none\" ? paletteFor(editor.value) : undefined\n const [paletteIndex, setPaletteIndex] = useState(0)\n\n const elapsed = useElapsed(busy)\n const last = useMemo(() => lastStats(state.items), [state.items])\n\n /**\n * The conversation, wrapped to the width and flattened to rows.\n *\n * Memoised on the three things it depends on. Without that it would re-flatten and re-wrap the whole\n * history on every streamed token, which is the cost `<Static>` used to remove for free.\n */\n const rows = useMemo(\n () => transcriptRows(state.items, { showReasoning, quiet, columns, expandReasoning }),\n [state.items, showReasoning, quiet, columns, expandReasoning],\n )\n\n /**\n * The landing state: a new conversation with nothing sent into it yet.\n *\n * It is a *state of the one frame*, not a screen of its own, and that is the whole design. As a separate\n * screen it was swapped out the moment anything reached the transcript — which `/help`, `/tools` and\n * `/restart` all do — so the landing screen \"disappeared\" for almost every command. And anything added to\n * the other layout was silently missing from it: the palette drew nothing there for a day, and `/exit`'s\n * \"press y\" prompt was invisible, because both live in the layout that was not on screen. One frame\n * removes that class of bug rather than fixing instances of it.\n *\n * `freshSession` is the host's answer to \"is this conversation new\". It used to be load-bearing for a\n * second reason — the chat did not render stored messages, so an empty transcript was equally true of a\n * resumed session — and that is no longer the case: `seedHistory` paints the conversation, so the `user`\n * clause below is now true on its own for anything resumed. Both are kept because they answer different\n * questions, and the remaining job of `freshSession` is the genuinely new session, where there is no\n * history for the second clause to find. The second half is what the owner chose: slash commands, notes\n * and the banner all keep the brand mark, because they are setup rather than conversation. It goes when\n * you actually start talking, and does not come back.\n */\n const landing = freshSession === true && !state.items.some((item) => item.role === \"user\")\n\n // A longer list while landing: there is no conversation to hide behind it, and the screen somebody opens\n // before they know the commands should show all of them rather than six and a counter.\n const listRows = landing ? LANDING_LIST_ROWS : SEARCH_ROWS\n const frame = chatFrame({\n rows: size.rows,\n columns,\n editor,\n live: state.live,\n showReasoning,\n palette,\n paletteMaxRows: listRows,\n searchMaxRows: listRows,\n confirming,\n landing,\n hint: landing,\n })\n /**\n * The brand mark, rendered here so the conversation is charged what it actually draws.\n *\n * `frame.brand` is an allowance and `wordmark` usually takes far less of it — charging the allowance\n * wasted eleven rows on a thirty-row terminal, and the banner ended up scrolled to a mid-wrap fragment of\n * a store path with a third of the screen blank. Computed once and handed to `Brandmark` as lines, so\n * there is no second derivation that could disagree about how tall the frame is.\n */\n const mark =\n frame.brand > 0\n ? wordmark(BRAND.name, { columns: columns - BRAND_INDENT, rows: frame.brand })\n : undefined\n const window = slice(\n view,\n rows.length,\n transcriptRowsAfterBrand(frame, mark?.lines.length ?? 0),\n )\n\n /**\n * Bound the transcript, but only while following the tail.\n *\n * Every item is re-derived and re-wrapped on each frame now that the conversation is a windowed buffer\n * rather than `<Static>` output, so an unbounded one is unbounded work per keystroke. The gate is the\n * point: rows are addressed by position, so dropping any from the front shifts every offset below\n * them — evicting while somebody is parked twelve turns back would leave their offset untouched and\n * the text under it different, which is a session that looks live and is not. Deferring costs nothing,\n * because `esc` returns to the tail and the next append trims then.\n *\n * Called on every change with no check of its own: a buffer under the cap reduces to identical state,\n * so React bails out of the render.\n */\n // `state.items.length` below is a *trigger*, not a read: the body never looks at it, and it is there\n // so a growing conversation re-runs the check. The lint rule offers to remove it, and taking that\n // offer would leave the cap enforced once at mount and never again — a fix that lints clean and does\n // nothing, which is why the suppression carries a reason rather than the dependency being dropped.\n // biome-ignore lint/correctness/useExhaustiveDependencies: a deliberate trigger dependency; see above\n useEffect(() => {\n if (!view.pinned) return\n // Eviction shifts every row index, so a selection made before a trim would afterwards cover\n // different text — the same hazard `pinned` exists for, applied to a highlight. Cleared rather\n // than re-keyed: there is nothing to copy from rows that are gone, and a highlight that quietly\n // slid onto another reply is worse than one that disappeared.\n setSelection(undefined)\n trim()\n }, [view.pinned, state.items.length, trim])\n\n // The armed ^C expires on its own. A prompt that stayed armed indefinitely would turn a ^C pressed\n // minutes ago into the reason a later one ended the session.\n useEffect(() => {\n if (!armed) return\n const timer = setTimeout(() => setArmed(false), EXIT_ARM_MS)\n return () => clearTimeout(timer)\n }, [armed])\n\n /**\n * A submitted line: a slash command, or a message for the model.\n *\n * `draft` is what is *left in the buffer* afterwards, and it has to be passed in rather than read from\n * `editor` here. This closure captures the editor as it was when the frame rendered — before the submit\n * cleared it — so reading `editor.value` returned the command that was just consumed. `/restart` then\n * carried `/restart` across as the draft, which re-opened the palette on top of the new banner: the\n * screen came back identical to before enter was pressed, with the message hidden behind the list, and\n * the restart looked like it had done nothing at all.\n *\n * For a typed command the residual is always empty — `COMMAND_SHAPE` matches the whole trimmed line, so\n * a command cannot share the buffer with a draft. It stays a parameter because a restart offered by a\n * *pane* could, and that is what the carry-across exists for.\n */\n const onSubmit = (text: string, draft: string): void => {\n // Both renderers dispatch through the same table, so `--plain` and the rich path cannot\n // answer the same typed command differently.\n // `offered` is what turns a typed `/config get x` into a command rather than a message. Without\n // it the list defaults to empty, so **no** CLI command resolved when typed with arguments: the\n // palette ran them and typing the same thing sent it to the model as prose, which then answered\n // about it. Selecting `/config` from the list worked, and typing `/config get model.main.id` cost\n // a turn — the same command, two answers, which is exactly what `resolveSessionCommand` living in\n // one place is supposed to prevent.\n const command = resolveSessionCommand(text, offeredCommands())\n if (command !== undefined) {\n switch (command.kind) {\n case \"exit\":\n // Asked, not done. `/exit` is typed deliberately, but so is every other slash command,\n // and the one that discards the visible conversation is worth one keystroke of\n // confirmation on a surface where leaving takes the screen with it.\n setConfirming(true)\n return\n case \"restart\": {\n // The settings an agent booted with are fixed for its lifetime, so a\n // configuration change needs a new one. Nothing is lost either way: the\n // conversation lives in the store and the same session key resumes it.\n //\n // **Attached, the screen does not come down.** The host owns the agent, so this\n // is a request to replace it — and there is nothing in this process to rebuild,\n // so tearing the frame down would be a teardown for its own sake. Embedded,\n // `onRestart` unmounts and the loop builds a new runtime; the unsent draft\n // rides across, because throwing away a half-written message is a second,\n // unasked-for consequence of asking for the first.\n const reload = source.reload\n if (reload === undefined) {\n onRestart?.(draft)\n exit()\n return\n }\n note(\"asking the host to reload this agent…\")\n reload()\n .then((adopted: readonly string[]) =>\n note(\n // Named rather than counted: replacing a supervisor replaces its\n // team, and \"3 agents reloaded\" would leave somebody guessing which.\n `reloaded ${adopted.join(\", \")} — this conversation continues`,\n ),\n )\n .catch((error: unknown) =>\n note(\n `could not reload: ${error instanceof Error ? error.message : String(error)}`,\n ),\n )\n return\n }\n case \"new\":\n // The same unmount-and-reopen route `/restart` and `/sessions` take, for the same\n // reason: a transcript cannot be re-keyed in place. Nothing is destroyed — the\n // conversation being left keeps its key, and the next banner names it.\n onNew?.(draft)\n exit()\n return\n case \"help\":\n note(sessionHelpText())\n return\n case \"tools\":\n // Fire-and-report, like `/status` and `/context` beside it: a component cannot\n // block, so the note is the acknowledgement. Embedded this resolves off the\n // live registry with no await worth mentioning; attached it is a request, and\n // the two must not read differently to whoever typed it.\n source\n .tools()\n .then((view: ToolsView) => note(toolsReport(view)))\n .catch((error: unknown) =>\n note(\n `could not read the tools: ${error instanceof Error ? error.message : String(error)}`,\n ),\n )\n return\n case \"context\":\n // Same shape as `status` below: a component cannot block, so the note is the\n // acknowledgement. Absent means the surface is not offered rather than accepted\n // and silently billed to the model, which is what `/status` did for three phases.\n if (contextView === undefined) {\n note(\"context is unavailable in this session\")\n return\n }\n contextView()\n .then(note)\n .catch((error: unknown) =>\n note(\n `could not read the context: ${error instanceof Error ? error.message : String(error)}`,\n ),\n )\n return\n case \"status\":\n // Declared in `SESSION_COMMANDS`, advertised in `/help` and generated into the\n // palette — and unhandled here, so it fell out of this switch and was sent to the\n // model as prose. Not a type error: the union's first member is\n // `{kind: SessionCommandKind}` and this switch has no exhaustiveness guard, which\n // is why `boundaries.test.ts` now walks every kind. Seventh instance in this repo\n // of every layer being right and one not being connected.\n //\n // Awaited through `.then` rather than inline: a component cannot block, and the\n // note *is* the acknowledgement — the same shape `reset` below uses.\n if (status === undefined) {\n note(\"status is unavailable in this session\")\n return\n }\n status()\n .then(note)\n .catch((error: unknown) =>\n note(\n `could not read the status: ${error instanceof Error ? error.message : String(error)}`,\n ),\n )\n return\n case \"reset\":\n // Fire-and-report rather than awaited: a component cannot block, and the note is\n // the acknowledgement. A failure surfaces as a rejected promise, so it is caught.\n source\n .clearSession(sessionKey)\n .then(() => note(\"session cleared — memory files on disk are untouched\"))\n .catch((error: unknown) =>\n note(\n `could not clear the session: ${error instanceof Error ? error.message : String(error)}`,\n ),\n )\n return\n case \"command\":\n // Through `dispatch`, which is the palette's path too — its own comment says it is\n // shared \"so the two cannot diverge\", and until now only one of the two reached it.\n if (dispatch(`/${command.name}`, command.rest)) return\n note(unknownCommandText({ word: `/${command.name}` }))\n return\n case \"unknown\":\n note(unknownCommandText(command))\n return\n }\n }\n if (busy) {\n // Two turns on one session would interleave in the history the next turn is conditioned\n // on. Refusing is honest; queueing silently would make the reply order unpredictable.\n note(\"a turn is still running — ^C cancels it, then send again\")\n return\n }\n send(text)\n }\n\n /**\n * Run a command and show what it printed.\n *\n * The pane opens *before* the command starts, with a spinner, for the same reason the skills browser\n * mounts before it fetches: a command that takes a second with nothing on screen is indistinguishable\n * from a keystroke that did nothing.\n */\n const openCommand = useCallback(\n (name: string, rest: string) => {\n setPane({ kind: \"output\", label: `/${name}`, lines: undefined, offset: 0 })\n void runSubcommand({ name, rest, manifestPath: manifestPath ?? \"\" })\n .then((result) =>\n setPane({\n kind: \"output\",\n label: `/${name}`,\n lines: result.lines,\n code: result.code,\n offset: 0,\n }),\n )\n .catch((error: unknown) =>\n setPane({\n kind: \"output\",\n label: `/${name}`,\n lines: [error instanceof Error ? error.message : String(error)],\n code: 1,\n offset: 0,\n }),\n )\n },\n [manifestPath],\n )\n\n /** A slash command, from the palette or from a typed line. Shared so the two cannot diverge. */\n const dispatch = useCallback(\n (word: string, rest: string) => {\n const entry = paletteEntries().find((candidate) => candidate.word === word)\n if (entry === undefined) return false\n if (entry.kind === \"view\") {\n if (\n entry.word === \"/sessions\" &&\n sessions !== undefined &&\n onSwitch !== undefined\n ) {\n // Opened before the read finishes, with the spinner the pane draws for an undefined\n // list — the same reason the catalogue mounts before it fetches: a keystroke followed\n // by nothing is indistinguishable from a keystroke that did nothing.\n setPane({ kind: \"sessions\", stored: undefined })\n void import(\"#components/SessionPicker\").then((module) =>\n // Wrapped in a function, or `useState` would call the component as an updater.\n setSessions(() => module.SessionPicker),\n )\n void sessions()\n .then((stored) => setPane({ kind: \"sessions\", stored }))\n .catch((error: unknown) => {\n setPane({ kind: \"none\" })\n note(\n `could not read the stored conversations: ${error instanceof Error ? error.message : String(error)}`,\n )\n })\n return true\n }\n if (entry.word === \"/config\" && (rest.trim() === \"\" || rest.trim() === \"edit\")) {\n // Bare `/config` is the editor; `/config list` and the rest are still the plain\n // command in an output pane, which the fallthrough below handles.\n if (manifestPath === undefined) {\n note(\"this session has no manifest path, so there is nothing to edit\")\n return true\n }\n setPane({ kind: \"config\", rows: editorRowsFor(manifestPath) })\n void import(\"#components/ConfigEditor\").then((module) =>\n // Wrapped in a function, or `useState` would call the component as an updater.\n setEditor_(() => module.ConfigEditor),\n )\n return true\n }\n if (entry.word === \"/skills\" && catalogue !== undefined) {\n setPane({ kind: \"skills\" })\n void import(\"#components/SkillBrowser\").then((module) =>\n // Wrapped in a function, or `useState` would call the component as an updater.\n setBrowser(() => module.SkillBrowser),\n )\n return true\n }\n // A view named in the table with nothing built yet falls back to its own output, which is\n // still the command doing its job — better than a palette entry that does nothing.\n openCommand(entry.word.slice(1), rest)\n return true\n }\n if (entry.kind === \"output\") {\n openCommand(entry.word.slice(1), rest)\n return true\n }\n return false\n },\n // `manifestPath` is read by the `/config` branch. A prop that does not change in practice, and\n // listing it is what stops a later change from being captured stale — the same reason the rule\n // exists rather than a suppression here.\n [openCommand, catalogue, sessions, onSwitch, note, manifestPath],\n )\n\n // ── the pane has the keyboard while it is open ────────────────────────────────────────\n useInput(\n (input, key) => {\n if (pane.kind !== \"output\") return\n if (key.escape || input === \"q\") {\n setPane({ kind: \"none\" })\n return\n }\n const total = pane.lines?.length ?? 0\n const step = key.pageDown || key.pageUp ? frame.pane : 1\n const delta =\n key.downArrow || key.pageDown ? step : key.upArrow || key.pageUp ? -step : 0\n if (delta !== 0) {\n setPane({\n ...pane,\n offset: Math.max(0, Math.min(pane.offset + delta, Math.max(0, total - 1))),\n })\n }\n },\n { isActive: pane.kind === \"output\" },\n )\n\n useInput(\n (input, reported) => {\n // Modifiers off the wire where they can be had, before anything reads one.\n //\n // Ink folds the super bit into `meta` on its legacy path (`modifier & 10`), so `cmd+←` and\n // `⌥←` arrive as the same keystroke and both word-move — measured in a real Warp session.\n // First line of the handler rather than beside `keyToIntent`, because the palette branch below\n // reads `key.escape` and `key.upArrow` too, and a correction applied after it would be one\n // that two of the three branches never got.\n const key = correctKeys === undefined ? reported : correctKeys(reported, input)\n\n // A pending confirmation owns the keyboard for exactly one keystroke. Anything other than a\n // yes is a no — including a stray arrow, because the safe answer to an unclear one is to stay.\n if (confirming) {\n setConfirming(false)\n if (input.toLowerCase() === \"y\" || key.return) exit()\n return\n }\n\n // The palette owns the keys it needs while it is open, and hands everything else to the editor —\n // so typing continues to narrow the list rather than being swallowed by it.\n if (palette !== undefined) {\n if (key.escape) {\n setEditor((current) => applyIntent(current, { kind: \"killToStart\" }))\n setPaletteIndex(0)\n return\n }\n if (key.upArrow || key.downArrow) {\n setPaletteIndex((at) =>\n Math.max(\n 0,\n Math.min(at + (key.downArrow ? 1 : -1), palette.matches.length - 1),\n ),\n )\n return\n }\n if (key.tab) {\n const chosen = paletteSelection(palette, paletteIndex)\n if (chosen !== undefined) {\n setEditor((current) =>\n applyIntent(\n { ...current, value: \"\", cursor: 0 },\n {\n kind: \"insert\",\n text: chosen.word,\n },\n ),\n )\n }\n return\n }\n const selected = paletteSelection(palette, paletteIndex)\n // Only intercepted when something is selected. With no match, enter falls through to the\n // ordinary submit path, which reports `/skils is not a command` and suggests the nearest\n // one — swallowing it here made a mistyped command do nothing at all, which is worse.\n if (key.return && selected !== undefined) {\n const chosen = selected\n setPaletteIndex(0)\n setEditor((current) => ({ ...current, value: \"\", cursor: 0 }))\n // A session verb goes through the same submit path a typed line takes, so `/help` and\n // `/reset` behave identically whether they were completed or typed out.\n // The buffer was cleared in the same handler, so nothing is left behind.\n if (chosen.kind === \"session\") onSubmit(chosen.word, \"\")\n else dispatch(chosen.word, \"\")\n return\n }\n }\n\n const intent = keyToIntent(\n input,\n key,\n keyContext(editor, busy, { armed, scrolled: !view.pinned }),\n )\n\n // Any keystroke that is not the second ^C disarms. Without this the warning would stay true\n // while somebody typed a whole message, and the ^C they pressed at the end of it — meaning\n // \"cancel that\" — would end the session instead.\n if (armed && intent.kind !== \"exit\") setArmed(false)\n\n if (intent.kind === \"arm\") {\n setArmed(true)\n return\n }\n if (intent.kind === \"scroll\") {\n // `times` is the wheel: one chunk can carry several notches, and applying one of them makes\n // a flick of the wheel move a single row. Folded rather than given its own move, so the\n // clamping at both ends stays in one function.\n const times = Math.max(1, intent.times ?? 1)\n setView((current) => {\n let next = current\n for (let step = 0; step < times; step += 1) {\n next = scroll(next, intent.move, rows.length, frame.transcript)\n }\n return next\n })\n return\n }\n if (intent.kind === \"pointer\") {\n // Screen cell to buffer row, through the one function that owns the frame's vertical\n // arithmetic. `undefined` means the cell was chrome — the header, the composer, the status\n // line — and a click there clears the selection rather than selecting the nearest row,\n // because clamping would make clicking the status bar highlight the last reply.\n const hit = transcriptHit(\n { column: intent.column, row: intent.row },\n { brandLines: mark?.lines.length ?? 0, from: window.from, to: window.to },\n )\n if (hit === undefined) {\n // Not the transcript — try the composer. Selecting your own draft with the mouse is\n // the same gesture and a different target, so it is the same branch rather than a\n // second handler that would have to re-derive which cell belongs to whom.\n const offset = composerHit(\n { column: intent.column, row: intent.row },\n { editor, columns, rows: size.rows, hint: landing },\n )\n if (offset === undefined) {\n // Genuine chrome. A press clears both selections rather than clamping to whatever\n // is nearest, because a click on the status line that highlighted the last reply\n // would look deliberate.\n if (intent.gesture === \"press\") {\n setSelection(undefined)\n setEditor((current) => ({ ...current, anchor: undefined }))\n }\n return\n }\n setSelection(undefined)\n setEditor((current) =>\n intent.gesture === \"press\" && !intent.shift\n ? // A press places the caret and starts a possible selection from it; the\n // anchor is set now so the first drag report has something to extend from.\n { ...current, cursor: offset, anchor: offset }\n : // A drag, or a shift-click, moves the cursor and keeps the anchor — which is\n // exactly what `extend` does for a shifted motion, expressed directly\n // because there is no motion here, only a destination.\n {\n ...current,\n cursor: offset,\n anchor: current.anchor ?? current.cursor,\n },\n )\n return\n }\n if (intent.gesture === \"press\") {\n // Shift extends whatever is already there, which is the gesture for correcting a\n // selection that stopped a word short. Checked before the click count, because a\n // shift-click is a deliberate second gesture rather than a fast repeat of the first.\n if (intent.shift && selection !== undefined) {\n setSelection(extendSelection(selection, hit))\n lastPress.current = undefined\n return\n }\n const previous = lastPress.current\n const repeat =\n previous !== undefined &&\n Date.now() - previous.when <= MULTI_CLICK_MS &&\n previous.at.row === hit.row &&\n previous.at.column === hit.column\n // Third click wraps back to one, so a fourth starts a fresh drag rather than doing\n // nothing — a count that only grew would leave rapid clicking permanently stuck on\n // \"line\".\n const clicks = repeat ? (previous.clicks % 3) + 1 : 1\n lastPress.current = { at: hit, when: Date.now(), clicks }\n // One selection at a time. Two visible highlights with one clipboard between them is\n // a screen that cannot say what ⌘C would copy.\n setEditor((current) => ({ ...current, anchor: undefined }))\n setSelection(\n clicks === 3\n ? lineAt(rows, hit)\n : clicks === 2\n ? wordAt(rows, hit)\n : beginSelection(hit),\n )\n return\n }\n if (intent.gesture === \"drag\") {\n setSelection((current) =>\n current === undefined ? undefined : dragSelection(current, hit),\n )\n return\n }\n // Release. The clipboard is written here and nowhere else, because `cmd+c` cannot reach a\n // terminal app — the terminal claims it and finds no native selection, mouse tracking\n // having disabled the one it would have used. Copying on mouse-up is what makes `cmd+v`\n // work, and a copy that failed says so rather than leaving the previous clipboard in place\n // looking like the wrong text was selected.\n // Derived from *this* report rather than from the state in the closure. A release carries\n // its own final position, and `selection` here is whatever the last render saw — which on\n // a fast drag-and-release is one motion behind, so copying from it would drop the last few\n // characters somebody deliberately included.\n const finished =\n selection === undefined\n ? undefined\n : endSelection(dragSelection(selection, hit))\n setSelection(finished)\n const text = selectedText(rows, finished)\n if (text !== \"\") {\n void copyToClipboard(text).then((result) => {\n if (!result.copied && result.problem !== \"nothing selected\") {\n note(`could not copy: ${result.problem ?? \"unknown\"}`)\n }\n })\n }\n return\n }\n if (intent.kind === \"copySelection\" || intent.kind === \"cutSelection\") {\n const range = selectionRange(editor)\n if (range === undefined) {\n note(\"nothing selected — hold shift with a motion, or drag in the box\")\n return\n }\n const text = [...editor.value].slice(range.start, range.end).join(\"\")\n if (intent.kind === \"cutSelection\")\n setEditor((current) => applyIntent(current, intent))\n void copyToClipboard(text).then((result) => {\n if (!result.copied) note(`could not copy: ${result.problem ?? \"unknown\"}`)\n })\n return\n }\n if (intent.kind === \"reasoning\") {\n // A chord with nothing to act on has to say so.\n //\n // Reported as \"⌥r doesn't do anything\", and it was arriving and resolving correctly the\n // whole time: it toggles a fold, and a fold with nothing in it looks exactly like a dead\n // key. Two different reasons for that, and they need two different sentences — a model\n // that never streams reasoning is not the same as a turn that has not produced any yet,\n // and only the first is worth changing a flag over.\n // Visibility, not existence — and the order matters. `useTurn` appends a reasoning item\n // for every delta the model streams *regardless* of `showReasoning`, and `transcript.ts`\n // filters them out at render. So a session with reasoning hidden has items that cannot be\n // shown, and testing existence first fell through to a toggle whose rows were filtered\n // away: silently nothing, which is the failure this whole branch exists to prevent.\n if (!showReasoning) {\n note(\n \"reasoning is off: either this model does not stream it, or --no-reasoning is set\",\n )\n return\n }\n if (!state.items.some((item) => item.role === \"reasoning\")) {\n note(\"no reasoning to show yet — this expands it once a turn has streamed some\")\n return\n }\n // Unfolding changes how tall the conversation is, so the window has to be told to follow\n // the newest row again — leaving it parked would put the reader at a row that has moved.\n setExpandReasoning((current) => !current)\n setView(FOLLOWING)\n return\n }\n if (intent.kind === \"exit\") {\n exit()\n return\n }\n if (intent.kind === \"cancel\") {\n cancel()\n return\n }\n if (intent.kind === \"submit\") {\n const committed = submit(editor)\n setEditor(committed.state)\n // Sending is an implicit \"take me back to the newest row\": a reply arriving into a window\n // parked ten screens up would be generated where nobody can see it.\n setView(FOLLOWING)\n if (committed.text !== \"\") onSubmit(committed.text, committed.state.value)\n return\n }\n if (intent.kind === \"paste\") {\n // Inserted with its newlines intact, as one message.\n //\n // This used to submit every finished line in the chunk, and that was right when the buffer\n // could not hold a newline: the alternative then was silently running the words together.\n // Now that a message is composed rather than typed on one line, sending line-by-line is the\n // bug multi-line composition exists to remove — pasting a twelve-line code block produced\n // twelve messages, each conditioned on the last, and no way to edit any of them.\n setEditor((current) =>\n applyIntent(current, { kind: \"insert\", text: intent.lines.join(\"\\n\") }),\n )\n return\n }\n // The match list changes underneath the cursor on every keystroke, so keeping its position\n // would silently highlight a different entry than the one on screen — the same reason the\n // history search resets its index.\n if (palette !== undefined) setPaletteIndex(0)\n setEditor((current) => applyIntent(current, intent))\n },\n { isActive: pane.kind === \"none\" },\n )\n\n if (pane.kind === \"config\") {\n return (\n <Box flexDirection=\"column\" width={columns} height={size.rows}>\n <Text color={THEME.accent} bold wrap=\"truncate\">\n {titleLine({ title: `${BRAND.name} ${VERSION}`, summary: \"settings\" }, columns)}\n </Text>\n {Editor === undefined ? (\n <Box marginLeft={2}>\n <Spinner label=\"reading the settings\" />\n </Box>\n ) : (\n <Editor\n rows={pane.rows}\n apply={(row, raw) => applyEditorRow(manifestPath ?? \"\", row, raw)}\n reload={() => editorRowsFor(manifestPath ?? \"\")}\n columns={columns}\n window={SESSION_PICKER_ROWS}\n onDone={(changed) => {\n setPane({ kind: \"none\" })\n // An agent's settings are fixed for the lifetime of the process running it,\n // so a change that is not followed by a restart is a change that silently\n // did not apply — rule 8's shape. The draft rides across, for the reason\n // `/restart` carries it: throwing away a half-written message is a second,\n // unasked-for consequence of asking for the first.\n if (changed) {\n onRestart?.(editor.value)\n exit()\n }\n }}\n />\n )}\n {/*\n * The slack goes *below* a long list, not above it. Bottom-anchoring is right for the\n * conversation switcher — a dozen short rows that read as a menu — and wrong here: the\n * settings run past twenty rows, so a spacer above them started the list mid-screen with\n * eight blank rows over it and the rest running off the bottom.\n */}\n <Box flexGrow={1} />\n </Box>\n )\n }\n\n if (pane.kind === \"sessions\") {\n return (\n <Box flexDirection=\"column\" width={columns} height={size.rows}>\n <Text color={THEME.accent} bold wrap=\"truncate\">\n {titleLine(\n { title: `${BRAND.name} ${VERSION}`, summary: \"pick a conversation\" },\n columns,\n )}\n </Text>\n <Box flexGrow={1} />\n {pane.stored === undefined || Sessions === undefined ? (\n <Box marginLeft={2}>\n <Spinner label=\"reading the stored conversations\" />\n </Box>\n ) : (\n <Sessions\n sessions={pane.stored}\n now={Date.now()}\n columns={columns}\n maxRows={SESSION_PICKER_ROWS}\n current={sessionKey}\n onDone={(picked) => {\n if (picked === undefined || picked === sessionKey) {\n // Esc, or the one already open. Either way nothing is worth a rebuild.\n setPane({ kind: \"none\" })\n return\n }\n onSwitch?.(picked, editor.value)\n exit()\n }}\n />\n )}\n <Box flexGrow={1} />\n </Box>\n )\n }\n\n if (pane.kind === \"skills\" && catalogue !== undefined && Browser !== undefined) {\n return (\n <Browser\n title={`${BRAND.name} ${VERSION}`}\n agents={[]}\n target={manifestPath ?? \"\"}\n load={catalogue.load}\n install={catalogue.install}\n onDone={() => setPane({ kind: \"none\" })}\n />\n )\n }\n\n const header = titleLine(\n {\n title: `${BRAND.name} ${VERSION}`,\n summary: \"\",\n agent: { name: agentName, model },\n ...(warnings === undefined || warnings.length === 0 ? {} : { warnings }),\n },\n columns,\n )\n\n return (\n // Fixed height, because the alternate screen has no scrollback to absorb an overshoot: one row too\n // many and Ink's own output scrolls the buffer, which leaves the status line halfway up the display.\n <Box flexDirection=\"column\" width={columns} height={size.rows}>\n {/*\n * Above the one-line header, and only while landing. Nothing appears or disappears when it goes —\n * the line below it is the same line either way, which is what makes the collapse read as the same\n * screen with less on it rather than as a different screen.\n */}\n {mark === undefined ? null : (\n <>\n <Brandmark lines={mark.lines} />\n <Text> </Text>\n </>\n )}\n <Text color={THEME.accent} bold wrap=\"truncate\">\n {header}\n </Text>\n\n {pane.kind === \"output\" ? (\n <Box flexDirection=\"column\">\n <CommandOutput\n lines={pane.lines}\n label={pane.label}\n offset={pane.offset}\n maxRows={frame.pane}\n {...(pane.code === undefined ? {} : { code: pane.code })}\n />\n <Text dimColor wrap=\"truncate\">\n {\" \"}↑↓ scroll · esc back to the prompt\n </Text>\n </Box>\n ) : (\n <Transcript\n rows={rows}\n slice={window}\n {...(selection === undefined ? {} : { selection })}\n />\n )}\n\n {/*\n * Absorbs the slack, so the composer sits on the bottom edge of every frame.\n *\n * Unconditional, and that is the whole of decision 11.98's reversal. It used to stand down while\n * landing, on the grounds that twelve blank rows between the banner and the input read as a\n * half-empty screen — but a bottom-anchored input is where the eye already rests, so what those\n * rows read as is a prompt waiting. The reference CLI puts ~25 there and nobody reports it.\n *\n * The cost of the old arrangement was not the blank rows, it was that the composer *moved*: it\n * was drawn under whatever content existed, so it walked down the screen as the first few\n * messages arrived and only settled once the transcript filled the window. The place you type\n * should not move. A spacer costs nothing once the transcript is full, because by then there is\n * no slack left for it to take.\n */}\n <Box flexGrow={1} />\n\n {state.live === undefined ? null : (\n <Live live={state.live} showReasoning={showReasoning} columns={columns} />\n )}\n {palette === undefined ? null : (\n <Palette\n palette={palette}\n index={paletteIndex}\n width={columns}\n maxRows={listRows}\n />\n )}\n <HistorySearch editor={editor} width={columns} maxRows={listRows} />\n {/*\n * Rendered once, in the one frame, which is the fix rather than a feature: this lived only in the\n * transcript layout, so `/exit` typed on the landing screen asked for a confirmation nobody could\n * see — the session simply appeared to ignore the command until a second keystroke ended it.\n */}\n {confirming ? (\n <Text color={THEME.warning} wrap=\"truncate\">\n {\" leave this session? press y to confirm · any other key stays\"}\n </Text>\n ) : null}\n <Prompt\n editor={editor}\n busy={busy}\n columns={columns}\n {...(landing ? { placeholder: \"Ask anything…\" } : {})}\n />\n {/*\n * The keys worth knowing before there is a conversation to learn them from. It stands down once\n * one exists: the status line already carries `^C`, and a permanent hint is a row of conversation.\n */}\n {landing ? (\n <Text dimColor wrap=\"truncate\">\n {\" \"}\n {NEW_SESSION_HINT}\n </Text>\n ) : null}\n {/* The status line is the footer, under the input — where every reference CLI puts\n it, and where the eye rests between keystrokes. */}\n <StatusBar\n status={state.status}\n model={model}\n sessionKey={sessionKey}\n elapsedMs={elapsed}\n last={last}\n quiet={quiet}\n armed={armed}\n {...(state.pressure === undefined ? {} : { pressure: state.pressure })}\n {...(state.phase === undefined ? {} : { phase: state.phase })}\n />\n </Box>\n )\n}\n",
|
|
6
|
+
"/**\n * A command's output, in a scrollable pane inside the session.\n *\n * ## Why one pane rather than nine screens\n *\n * Every command in the table already produces good text — `keyValue` blocks, sections, the house\n * vocabulary in `lib/render.ts`. Nine bespoke screens for `/status`, `/policy`, `/config`, `/model` and\n * the rest would mostly reproduce those same tables in JSX, and several of them are read-only lists where\n * a generic pane and a hand-made one look identical.\n *\n * So this runs the command, captures what it printed, and shows it. That makes *every* non-hidden command\n * reachable from the palette the moment it exists, which is what \"all the CLI inside the TUI\" asks for,\n * and leaves a bespoke view as something a command earns by having a next action worth a keypress —\n * skills and sources have one, `/policy` does not.\n *\n * Controlled: the scroll offset lives in the screen root, and this owns no keyboard.\n */\n\nimport { Box, Text } from \"ink\"\nimport { Spinner } from \"#components/Spinner\"\nimport { viewport } from \"#lib/rows\"\nimport { GLYPH, THEME } from \"#lib/theme\"\n\nexport interface CommandOutputProps {\n /** `undefined` while it is still running. */\n readonly lines: readonly string[] | undefined\n readonly label: string\n /** First visible line. Clamped here, so a shrinking output cannot leave the view past its end. */\n readonly offset: number\n readonly maxRows: number\n /** Non-zero means the command reported a failure; shown, never hidden behind a clean-looking pane. */\n readonly code?: number\n}\n\nexport function CommandOutput({ lines, label, offset, maxRows, code }: CommandOutputProps) {\n if (lines === undefined) {\n return (\n <Box marginLeft={2}>\n <Spinner label={`running ${label}`} />\n </Box>\n )\n }\n\n if (lines.length === 0) {\n return (\n <Box marginLeft={2}>\n <Text color={THEME.muted}>{label} printed nothing</Text>\n </Box>\n )\n }\n\n // `viewport` centres on a cursor; here the cursor *is* the offset, so it is asked for the row at the\n // top of the window and clamped by the same arithmetic the lists use.\n const { from, to } = viewport(\n lines.length,\n Math.min(offset + Math.floor(maxRows / 2), lines.length - 1),\n maxRows,\n )\n\n const visible = lines.slice(from, to).map((text, at) => ({ row: from + at, text }))\n\n return (\n <Box flexDirection=\"column\">\n {code !== undefined && code !== 0 ? (\n <Text color={THEME.error} wrap=\"truncate\">\n {GLYPH.error}\n {label} exited {code}\n </Text>\n ) : null}\n {from > 0 ? (\n <Text dimColor wrap=\"truncate\">\n {\" \"}\n {GLYPH.ellipsis} {from} line{from === 1 ? \"\" : \"s\"} above\n </Text>\n ) : null}\n {visible.map((entry) => (\n // Keyed by the row's position in the whole output, computed before the map so the key is a\n // line number rather than a callback index. Position is the honest identity here: two\n // identical lines in a report are different lines, and a content key would collapse them.\n <Text key={entry.row} wrap=\"truncate\">\n {entry.text}\n </Text>\n ))}\n {to < lines.length ? (\n <Text dimColor wrap=\"truncate\">\n {\" \"}\n {GLYPH.ellipsis} {lines.length - to} line{lines.length - to === 1 ? \"\" : \"s\"}{\" \"}\n below\n </Text>\n ) : null}\n </Box>\n )\n}\n",
|
|
7
|
+
"/**\n * `^R` — what you have already sent, filtered as you type, above the prompt.\n *\n * A list rather than bash's in-place `(reverse-i-search)` line, and deliberately the same shape the\n * slash palette uses: matches above the input, narrowing as you type, ↑↓ to pick, ⏎ to use, esc to\n * cancel. One interaction learned once and used by both — a shell shows a single match at a time\n * because a shell has one line to work with, which is not a constraint here.\n *\n * Controlled and presentational: the query, the match list and the selected index all come from\n * `editor.ts`, and this component owns no keyboard. The line being composed is untouched until a match\n * is accepted, so the search costs nothing to cancel — which is why the draft can stay on screen\n * underneath.\n */\n\nimport { Box, Text } from \"ink\"\nimport { searchMatches } from \"#editor\"\nimport { clip, viewport } from \"#lib/rows\"\nimport { GLYPH, THEME } from \"#lib/theme\"\nimport type { EditorState } from \"#lib/types\"\n\nexport interface HistorySearchProps {\n readonly editor: EditorState\n /** Terminal columns, so a long message is clipped rather than wrapped into the list. */\n readonly width: number\n /** Visible matches. The list scrolls inside this rather than pushing the prompt off the screen. */\n readonly maxRows: number\n}\n\nexport function HistorySearch({ editor, width, maxRows }: HistorySearchProps) {\n const search = editor.search\n if (search === undefined) return null\n\n const matches = searchMatches(editor)\n const index = Math.min(search.index, Math.max(0, matches.length - 1))\n const { from, to } = viewport(matches.length, index, maxRows)\n // Two for the gutter, and the query line needs room for its own label.\n const room = Math.max(8, width - 4)\n\n return (\n <Box flexDirection=\"column\">\n {matches.length === 0 ? (\n <Text color={THEME.muted} wrap=\"truncate\">\n {\" \"}\n nothing you have sent matches that\n </Text>\n ) : (\n matches.slice(from, to).map((entry, offset) => {\n const at = from + offset\n const selected = at === index\n return (\n // Keyed by the entry, which is unique: `searchMatches` deduplicates, so the same\n // question asked twice appears once.\n <Text key={entry} wrap=\"truncate\">\n <Text color={THEME.accent}>{selected ? GLYPH.pointer : \" \"}</Text>\n <Text bold={selected} dimColor={!selected}>\n {/* Newlines collapsed: a multi-line message has to read as one row here,\n the same rule the catalogue list follows. */}\n {clip(entry.replace(/\\s+/g, \" \"), room)}\n </Text>\n </Text>\n )\n })\n )}\n <Text wrap=\"truncate\">\n <Text color={THEME.muted}>{\" search: \"}</Text>\n {search.query}\n <Text inverse> </Text>\n {matches.length > 1 ? (\n <Text color={THEME.muted}>{` ${index + 1} of ${matches.length}`}</Text>\n ) : null}\n </Text>\n </Box>\n )\n}\n",
|
|
8
|
+
"/**\n * The reply being generated — the only part of the conversation that redraws.\n *\n * Height-capped on purpose. Ink redraws this whole subtree per frame, so an uncapped pane means redrawing\n * the entire reply on every token: the cost grows with the length of the answer, precisely when the\n * terminal is busiest. `livePane` keeps the newest rows and drops the older ones, which is what the reader\n * is looking at anyway; the whole reply joins the transcript at `turn.end`, so nothing is lost — it just\n * arrives complete rather than in a redrawn window.\n *\n * It renders pre-wrapped rows rather than handing Ink a paragraph, for the reason `lib/wrap.ts` explains:\n * Ink breaks at spaces and a division does not, so a cap measured one way and drawn the other was always\n * a row or two short of the truth. The chat frame subtracts this pane's height from the terminal before it\n * renders, so being short by a row is a frame taller than the screen.\n */\n\nimport { Box, Text } from \"ink\"\nimport { LIVE_PANE_MAX_ROWS } from \"#lib/const\"\nimport type { LiveProps } from \"#lib/schema\"\nimport { livePane } from \"#lib/wrap\"\n\nexport function Live({ live, showReasoning, columns }: LiveProps) {\n const showing = showReasoning && live.reasoning !== \"\" && live.text === \"\"\n const text = showing ? live.reasoning : live.text\n if (text === \"\") return null\n\n // The reasoning label is a prefix on the first row, so the wrap has to account for its width or that\n // row is one longer than every other.\n const label = showing ? \"· reasoning · \" : \"\"\n const pane = livePane(text, columns - [...label].length, LIVE_PANE_MAX_ROWS)\n // Row numbers computed before the map, so the key is a position rather than a callback index. Position\n // is the honest identity here: two identical rows of a streamed reply are different rows, and a content\n // key would collapse them.\n const rows = pane.lines.map((text, at) => ({ at, text }))\n\n return (\n <Box flexDirection=\"column\">\n {pane.hidden > 0 ? (\n <Text dimColor wrap=\"truncate\">\n … {pane.hidden} earlier row(s) hidden while streaming\n </Text>\n ) : null}\n {rows.map((row) => (\n <Text key={`row-${row.at}`} dimColor={showing} wrap=\"truncate\">\n {row.at === 0 ? label : \"\"}\n {row.text}\n </Text>\n ))}\n </Box>\n )\n}\n",
|
|
9
|
+
"/**\n * The slash-command list, above the prompt.\n *\n * Opens as soon as `/` is typed and narrows as the word is completed, which is what makes the whole\n * command surface discoverable without a manual. Deliberately the same shape as `HistorySearch`: matches\n * above the input, ↑↓ to move, tab to complete, enter to run, esc to close. One interaction learned once\n * and used by both, because a terminal app that invents a second list idiom for its second list is the\n * inconsistency this phase set out to remove.\n *\n * Controlled and presentational. The entries come from `lib/palette.ts` — generated from the CLI's own\n * command table — and the cursor lives in the screen root; this owns no keyboard.\n */\n\nimport { Box, Text } from \"ink\"\nimport type { Palette as PaletteModel } from \"#lib/palette\"\nimport { clip, viewport } from \"#lib/rows\"\nimport { GLYPH, THEME } from \"#lib/theme\"\n\nexport interface PaletteProps {\n readonly palette: PaletteModel\n readonly index: number\n readonly width: number\n readonly maxRows: number\n}\n\n/** Widest word among the matches, so the summaries line up in a column. */\nfunction wordColumn(palette: PaletteModel): number {\n return palette.matches.reduce((widest, entry) => Math.max(widest, entry.word.length), 0)\n}\n\nexport function Palette({ palette, index, width, maxRows }: PaletteProps) {\n if (palette.matches.length === 0) {\n return (\n <Text color={THEME.muted} wrap=\"truncate\">\n {\" \"}\n no command starts with /{palette.query}\n </Text>\n )\n }\n\n const at = Math.min(index, palette.matches.length - 1)\n const { from, to } = viewport(palette.matches.length, at, maxRows)\n const column = wordColumn(palette)\n // Two for the pointer, the word column, two of gap.\n const room = Math.max(8, width - (2 + column + 2))\n\n return (\n <Box flexDirection=\"column\">\n {from > 0 ? (\n <Text dimColor wrap=\"truncate\">\n {\" \"}\n {GLYPH.ellipsis} {from} above\n </Text>\n ) : null}\n {palette.matches.slice(from, to).map((entry, offset) => {\n const selected = from + offset === at\n return (\n <Text key={entry.word} wrap=\"truncate\">\n <Text color={THEME.accent}>{selected ? GLYPH.pointer : \" \"}</Text>\n <Text bold={selected} {...(selected ? { color: THEME.accent } : {})}>\n {entry.word.padEnd(column)}\n </Text>\n {\" \"}\n <Text dimColor>{clip(entry.summary, room)}</Text>\n </Text>\n )\n })}\n {to < palette.matches.length ? (\n <Text dimColor wrap=\"truncate\">\n {\" \"}\n {GLYPH.ellipsis} {palette.matches.length - to} below\n </Text>\n ) : null}\n <Text dimColor wrap=\"truncate\">\n {\" \"}↑↓ move · tab complete · enter run · esc close\n </Text>\n </Box>\n )\n}\n",
|
|
10
|
+
"/**\n * The composer — a rounded box that grows with the message, accent-bordered when ready and muted while\n * a turn runs.\n *\n * Ink has no text field: it delivers keystrokes and nothing else, so the cursor is drawn rather than\n * positioned. `LineCursor` owns that rendering for this component and the wizard's fields alike, which\n * is why the prompt glyph is handed to it as a `gutter` rather than rendered here beside it — a glyph\n * drawn here would sit next to the *block* of lines, leaving the second line of a message starting one\n * column to its left and reading as a separate message.\n *\n * The box caps at `MAX_INPUT_ROWS` and scrolls to follow the cursor. Same reasoning as the live pane:\n * this is Ink's dynamic region, erased and redrawn every frame, so an unbounded box redraws a pasted\n * document on every keystroke — and a long paste would push the conversation off the screen.\n *\n * The border exists only where Ink renders: the plain path never mounts this, so plain parity is\n * untouched by definition.\n */\n\nimport { Box, Text } from \"ink\"\nimport { LineCursor } from \"#components/LineCursor\"\nimport { MAX_INPUT_ROWS, PROMPT } from \"#lib/const\"\nimport type { PromptProps } from \"#lib/schema\"\nimport { NEWLINE_HINT } from \"#lib/session-commands\"\nimport { BORDER_STYLE, THEME } from \"#lib/theme\"\n\nexport function Prompt({ editor, busy, placeholder, columns }: PromptProps) {\n const lines = editor.value.split(\"\\n\").length\n // Two border columns and `paddingX={1}` on each side. Subtracted here rather than inside the cursor,\n // because the box that spends them is this one.\n const inner = Math.max(1, columns - 4)\n return (\n <Box flexDirection=\"column\">\n <Box\n borderStyle={BORDER_STYLE}\n borderColor={busy ? THEME.border : THEME.borderActive}\n // Explicit, because a `<Box>` with no width takes its *content* width — which is how a long\n // message made the box wider than the terminal and left the wrapping to whichever terminal\n // was running it.\n width={columns}\n paddingX={1}\n >\n <LineCursor\n editor={editor}\n gutter={PROMPT}\n maxRows={MAX_INPUT_ROWS}\n columns={inner}\n {...(placeholder === undefined ? {} : { placeholder })}\n />\n </Box>\n {/*\n * Named only once the message has more than one line. Advertising it on every empty prompt\n * spends a row on something most messages never need.\n *\n * It names ⌥⏎ and the backslash and *not* shift+⏎, even after `terminal-setup` has run.\n * Whether shift+⏎ reaches this process cannot be detected from inside it — the terminal\n * either sends a distinguishable sequence or does not — and a hint that names a chord which\n * silently sends the message instead is worse than one that names only what always works.\n * `/help` and `terminal-setup` are where shift+⏎ is explained.\n */}\n {lines > 1 ? (\n <Text dimColor wrap=\"truncate\">\n {\" \"}\n {NEWLINE_HINT}\n </Text>\n ) : null}\n </Box>\n )\n}\n",
|
|
11
|
+
"/**\n * One line saying what the runtime is doing.\n *\n * It exists to answer a question the old REPL could not: is this slow or is it hung? A model that\n * takes twelve seconds before its first token and a model that will never answer look identical\n * without an elapsed counter, and \"nothing is happening\" is the least debuggable state a tool can\n * present.\n */\n\nimport { Text } from \"ink\"\nimport type { StatusBarProps } from \"#lib/schema\"\nimport { GLYPH, STATUS_COLOR, THEME } from \"#lib/theme\"\nimport type { TurnStatus } from \"#lib/types\"\nimport { formatStats } from \"#transcript\"\n\nconst LABEL: Record<TurnStatus, string> = {\n idle: \"ready\",\n thinking: \"thinking\",\n streaming: \"replying\",\n working: \"running a tool\",\n cancelling: \"cancelling\",\n}\n\nfunction seconds(ms: number): string {\n return `${(ms / 1000).toFixed(1)}s`\n}\n\n/**\n * What ^C will do, said in the place a reader is already looking.\n *\n * Three states rather than two, because the chord now has three meanings and the wrong hint is worse\n * than none: mid-turn it cancels, at an idle prompt it arms, and once armed it leaves. The armed line is\n * the one that has to be loud — it is the only moment when the next keystroke discards the screen.\n */\nfunction exitHint(status: TurnStatus, armed: boolean): string {\n if (status !== \"idle\") return \" · ^C cancels\"\n return armed ? \" · ^C again to leave\" : \" · ^C twice to leave · /exit\"\n}\n\nfunction reasoningHint(status: TurnStatus): string {\n if (status !== \"idle\") return \"\"\n return \" · ^O show reasoning\"\n}\n\n/**\n * Below this the gauge is hidden: the lowest shipped threshold is `trim` at 0.60, so anything under\n * half is a prompt with nothing to say about itself.\n */\nconst PRESSURE_VISIBLE_AT = 0.5\n\n/** Coloured from here — past the shipped `micro` threshold, where the stages start costing fidelity. */\nconst PRESSURE_WARN_AT = 0.8\n\nexport function StatusBar({\n status,\n model,\n sessionKey,\n elapsedMs,\n last,\n quiet,\n armed,\n pressure,\n phase,\n}: StatusBarProps) {\n return (\n // Truncated, never wrapped. Found live at 80 columns: `ready · deepseek-v4-pro · live:two · last\n // 2330 prompt · 80 output · 2681 ms · ^C twice to leave · /exit` is longer than the terminal, so Ink\n // wrapped it onto a second row — which made the frame one row taller than `chatFrame` had counted\n // and pushed the top of the display off the alternate buffer. A status line is the one thing that\n // must never change height: everything else is laid out against it.\n <Text dimColor wrap=\"truncate\">\n <Text color={STATUS_COLOR[status]}>\n {GLYPH.dot}\n {LABEL[status]}\n </Text>\n {status === \"idle\" ? \"\" : ` ${seconds(elapsedMs)}`}\n {` · ${model} · ${sessionKey}`}\n {/* Straight after the session key, because a phase is a property of the conversation. */}\n {phase === undefined || quiet ? \"\" : ` · ${phase}`}\n {/*\n * Ahead of the turn stats, and that is not cosmetic. This line is truncated rather than\n * wrapped, and a real 100-column capture cut it mid-figure at `2564…` — so anything\n * appended after the stats vanishes exactly when the session is busiest, which is when the\n * gauge is the one thing worth reading. What a person can act on comes first.\n *\n * Shown only once it is worth knowing: below the lowest shipped threshold the number is\n * noise, and a gauge that is always visible is a gauge nobody reads.\n */}\n {pressure === undefined || pressure < PRESSURE_VISIBLE_AT || quiet ? (\n \"\"\n ) : (\n // Spread, not `color={cond ? x : undefined}`: Ink declares `color?: string`, so under\n // `exactOptionalPropertyTypes` an explicit undefined is a type error — and omitting it\n // is what we want anyway, so the figure inherits the dim style of the line.\n <Text {...(pressure >= PRESSURE_WARN_AT ? { color: THEME.warning } : {})}>\n {` · ctx ${Math.round(pressure * 100)}%`}\n </Text>\n )}\n {last === undefined || quiet ? \"\" : ` · last ${formatStats(last)}`}\n {reasoningHint(status)}\n {armed === true ? (\n <Text color={THEME.warning}>{exitHint(status, true)}</Text>\n ) : (\n exitHint(status, false)\n )}\n </Text>\n )\n}\n",
|
|
12
|
+
"/**\n * The finished conversation, as a window over rows we own.\n *\n * ## What replaced `<Static>`, and why it had to\n *\n * Through Phase 5 this rendered inside Ink's `<Static>`, which writes a node to the terminal once and\n * never touches it again — so history cost nothing to keep and scrolling was the terminal's own\n * scrollback. Phase 5.5 puts the session on the alternate screen buffer, and the two are incompatible\n * rather than merely awkward: `<Static>` appends to the scrollback, and the alternate buffer is\n * discarded on the way out with a scrollbar that reaches nothing. Everything Static wrote would be\n * invisible from the moment it was written.\n *\n * So the conversation is a buffer this code owns and this component shows a slice of. That moves the\n * transcript into the tree Ink redraws every frame, which is exactly the cost `<Static>` existed to\n * avoid — and is why the window is bounded in rows. A frame redraws its window regardless of how long\n * the conversation is, so the per-token cost stops growing with the answer.\n *\n * Controlled, like every component in this kit: the offset lives in the screen root, the rows come from\n * `transcriptRows`, and this owns no keyboard and no state.\n */\n\nimport { Box, Text } from \"ink\"\nimport type { TranscriptProps } from \"#lib/schema\"\nimport { scrollHint } from \"#lib/scroll\"\nimport { rowSelection } from \"#lib/text-selection\"\nimport { ROLE_COLOR, THEME } from \"#lib/theme\"\n\nexport function Transcript({ rows, slice, selection }: TranscriptProps) {\n const visible = rows.slice(slice.from, slice.to)\n const hint = scrollHint(slice)\n\n return (\n <Box flexDirection=\"column\">\n {/*\n * Always drawn, blank included — the caller's window already excludes this row, so making it\n * conditional would hand the conversation one extra row on exactly the frames where it has\n * least to spare. Blank is one line nobody reads; a moving layout is one everybody notices.\n */}\n <Text color={THEME.muted} wrap=\"truncate\">\n {hint === \"\" ? \" \" : hint}\n </Text>\n {visible.map((row, offset) => {\n // Spread rather than `color={...}`: Ink declares `color?: string`, so under\n // `exactOptionalPropertyTypes` an explicit `undefined` is a type error — and omitting it\n // is also what we want, because an assistant reply should use the terminal's own\n // foreground rather than a colour we picked for it.\n const colour = row.dim === true ? THEME.muted : ROLE_COLOR[row.role]\n const cells = [...row.text]\n // `slice.from + offset` is the row's index in the *buffer*, which is the coordinate the\n // selection is stored in. Using the visible index would move the highlight every time the\n // window scrolled, which is the whole reason the selection is not kept in screen space.\n const range = rowSelection(selection, slice.from + offset, cells.length)\n if (range === undefined) {\n return (\n <Text\n key={row.key}\n // Truncate rather than wrap, and that is load-bearing. `transcriptRows` has\n // already broken the text to the width; letting Ink wrap it again would paint\n // more rows than the window counted, which puts the tail of a reply underneath\n // the composer.\n wrap=\"truncate\"\n bold={row.bold === true}\n {...(colour === undefined ? {} : { color: colour })}\n >\n {row.text === \"\" ? \" \" : row.text}\n </Text>\n )\n }\n // A background rather than `inverse`: inverse swaps foreground and background, so across\n // the transcript's coloured roles it would produce a different highlight per role and read\n // as several selections. Starting at `lead` excludes the role prefix — `› ` and ` · ` are\n // chrome this renderer added, and highlighting them would claim text is selected that\n // nobody wrote and no copy will contain.\n const from = Math.max(range.from, row.lead)\n return (\n <Text\n key={row.key}\n wrap=\"truncate\"\n bold={row.bold === true}\n {...(colour === undefined ? {} : { color: colour })}\n >\n {cells.slice(0, from).join(\"\")}\n <Text backgroundColor={THEME.selection}>\n {cells.slice(from, range.to).join(\"\")}\n </Text>\n {cells.slice(range.to).join(\"\")}\n </Text>\n )\n })}\n </Box>\n )\n}\n",
|
|
13
|
+
"/**\n * Where a window sits in a buffer taller than itself. Pure, so scrolling is testable as arithmetic.\n *\n * ## Why the transcript needs this at all\n *\n * Until Phase 5.5 the finished conversation lived in Ink's `<Static>`, which writes a node to the\n * terminal once and never touches it again — so scrolling was the *terminal's* scrollback and cost\n * this code nothing. The alternate screen removes that: the buffer it swaps in is discarded on the\n * way out and its scrollbar reaches nothing, so a screen that owns the terminal has to own scrolling\n * too. `<Static>` and the alternate screen are not two options; they are incompatible.\n *\n * ## `pinned` is a flag, not a comparison\n *\n * The property that matters is \"new output follows the tail only when the reader is already at the\n * tail\". Deriving that by comparing the offset to the bottom looks equivalent and is not: the moment\n * a row is appended the old offset *is* one short of the bottom, so a reader who had deliberately\n * scrolled up one row would be yanked back down. Holding the intent explicitly makes the two states\n * different things — following, or parked — and a parked window stays parked however much arrives.\n *\n * While pinned the offset is *derived* rather than stored, which is what makes appending free: no\n * state changes when a row arrives, so nothing re-renders because of the scroll layer.\n */\n\nimport { MIN_BODY_ROWS } from \"#lib/const\"\nimport type { ScrollMove } from \"#lib/types\"\n\nexport interface ScrollState {\n /** First visible row while parked. Ignored while `pinned`, and kept so unpinning is reversible. */\n readonly offset: number\n /** Following the newest row. The state a session starts and returns to. */\n readonly pinned: boolean\n}\n\n/** Where a conversation starts, and where `bottom` puts it back. */\nexport const FOLLOWING: ScrollState = { offset: 0, pinned: true }\n\n/** The furthest down a window may start: the last full screen of the buffer. */\nfunction floorOf(total: number, window: number): number {\n return Math.max(0, total - window)\n}\n\n/** The first visible row, resolved. One derivation, so no caller repeats the pinned case. */\nexport function topRow(state: ScrollState, total: number, window: number): number {\n const bottom = floorOf(total, window)\n return state.pinned ? bottom : Math.max(0, Math.min(state.offset, bottom))\n}\n\nexport function scroll(\n state: ScrollState,\n move: ScrollMove,\n total: number,\n window: number,\n): ScrollState {\n if (move === \"bottom\") return FOLLOWING\n const bottom = floorOf(total, window)\n // A buffer shorter than the window has nowhere to go, so every move is already at the bottom.\n // Returning `FOLLOWING` rather than `{offset: 0, pinned: false}` matters: parked-at-zero would\n // stop following as soon as the conversation grew past one screen, with nothing having asked it to.\n if (bottom === 0) return FOLLOWING\n if (move === \"top\") return { offset: 0, pinned: false }\n\n const step = move === \"pageUp\" || move === \"pageDown\" ? Math.max(1, window - 1) : 1\n const delta = move === \"down\" || move === \"pageDown\" ? step : -step\n const next = topRow(state, total, window) + delta\n // Reaching the bottom re-pins rather than parking there, so scrolling back down to the newest row\n // resumes following. Parking at the bottom would look identical and then quietly stop updating.\n if (next >= bottom) return FOLLOWING\n return { offset: Math.max(0, next), pinned: false }\n}\n\nexport interface Slice {\n readonly from: number\n readonly to: number\n readonly above: number\n readonly below: number\n}\n\n/** Which rows to draw, and how many are out of sight on each side. */\nexport function slice(state: ScrollState, total: number, window: number): Slice {\n if (window <= 0) return { from: 0, to: 0, above: total, below: 0 }\n const from = topRow(state, total, window)\n const to = Math.min(total, from + window)\n return { from, to, above: from, below: total - to }\n}\n\n/**\n * Rows a body may use, given the terminal's height and what the chrome around it takes.\n *\n * Biased low on purpose: one row short of the terminal leaves a blank line, and one row over makes the\n * frame taller than the screen — which on the alternate buffer scrolls the whole layout and leaves the\n * status line halfway up the display. An underestimate is invisible and an overestimate is corruption,\n * so the safety row is spent in the direction that cannot be seen.\n */\nexport function bodyRows(terminalRows: number, chrome: number): number {\n return Math.max(MIN_BODY_ROWS, terminalRows - chrome - 1)\n}\n\n/**\n * One line saying what is out of sight, or the empty string when nothing is.\n *\n * **Always rendered, blank included.** A counter that appears only when it has something to say takes a\n * row from the window on the frame it appears, which pushes the last row of the conversation under the\n * composer at exactly the moment somebody scrolls — so the fix for a jumping layout would be triggered\n * by scrolling, which is when it is least welcome. One row, reserved, forever: an empty line costs\n * nothing to look at and the geometry never moves.\n *\n * Both directions on one line for the same reason. Two conditional rows is two things that can move.\n */\nexport function scrollHint(view: Slice): string {\n const parts: string[] = []\n if (view.above > 0) parts.push(`\\u2191 ${view.above} row${view.above === 1 ? \"\" : \"s\"} above`)\n if (view.below > 0) {\n parts.push(`\\u2193 ${view.below} row${view.below === 1 ? \"\" : \"s\"} below`, \"esc returns\")\n }\n return parts.length === 0 ? \"\" : ` ${parts.join(\" \\u00b7 \")}`\n}\n",
|
|
14
|
+
"/**\n * Selecting text in the transcript with the mouse.\n *\n * ## Buffer coordinates, and why that is the whole design\n *\n * The reference CLI keeps its selection in *screen* coordinates against a viewport-sized cell grid, and\n * roughly forty per cent of its state exists to survive that choice: two accumulators for rows that\n * scrolled out of the grid mid-drag, two parallel soft-wrap bitmaps to go with them, a pre-clamp anchor\n * row, and a function to capture rows before they are overwritten. All of it because the text is gone once\n * it leaves the viewport, so the selection has to hoard it.\n *\n * We never lose the text. The transcript is `readonly TranscriptRow[]` for the whole conversation with a\n * window over it, so a selection stored as `{row, column}` into *that* array needs none of those fields: it\n * is stable while the view scrolls, because scrolling only moves the window, and a copy is a substring of\n * data still in hand. Drag-to-scroll is then free rather than the hardest case.\n *\n * ## What it deliberately does not do\n *\n * Rectangular selection. Terminals select linearly — from a point, through every intervening row, to\n * another point — and a block selection is a different gesture with no way to ask for it here.\n */\n\nimport type { TranscriptRow } from \"#lib/types\"\n\n/** A position in the row buffer. `column` indexes code points of that row's `text`. */\nexport interface TextPoint {\n readonly row: number\n readonly column: number\n}\n\nexport interface TextSelection {\n /** Where the press happened. */\n readonly anchor: TextPoint\n /** Where the pointer is now. Equal to `anchor` until the first motion. */\n readonly focus: TextPoint\n /** True between press and release, which is what tells a finished selection from a live drag. */\n readonly dragging: boolean\n}\n\n/** Begin a selection at a point. Focus starts equal to anchor, so a bare click selects nothing. */\nexport function beginSelection(at: TextPoint): TextSelection {\n return { anchor: at, focus: at, dragging: true }\n}\n\n/** Move the focus. A no-op once the drag has finished, so a stray motion report cannot resurrect it. */\nexport function dragSelection(selection: TextSelection, to: TextPoint): TextSelection {\n if (!selection.dragging) return selection\n return { ...selection, focus: to }\n}\n\n/** Keep the range and stop tracking, so the highlight stays up and the text can be copied. */\nexport function endSelection(selection: TextSelection): TextSelection {\n return { ...selection, dragging: false }\n}\n\n/** Extend an existing selection to a point, as shift-click does. */\nexport function extendSelection(selection: TextSelection, to: TextPoint): TextSelection {\n return { ...selection, focus: to, dragging: false }\n}\n\nfunction before(left: TextPoint, right: TextPoint): boolean {\n return left.row < right.row || (left.row === right.row && left.column <= right.column)\n}\n\n/** The range in reading order, or `undefined` when nothing is selected. */\nexport function textBounds(\n selection: TextSelection | undefined,\n): { readonly start: TextPoint; readonly end: TextPoint } | undefined {\n if (selection === undefined) return undefined\n const { anchor, focus } = selection\n if (anchor.row === focus.row && anchor.column === focus.column) return undefined\n return before(anchor, focus) ? { start: anchor, end: focus } : { start: focus, end: anchor }\n}\n\n/**\n * Which columns of one row are selected, or `undefined` if none are.\n *\n * Clamped to the row's own length by the caller's `cells`, because a drag that runs off the end of a short\n * row must select to its end rather than to the pointer's column — which is what makes dragging down\n * through ragged text feel like one continuous sweep.\n */\nexport function rowSelection(\n selection: TextSelection | undefined,\n row: number,\n cells: number,\n): { readonly from: number; readonly to: number } | undefined {\n const bounds = textBounds(selection)\n if (bounds === undefined) return undefined\n if (row < bounds.start.row || row > bounds.end.row) return undefined\n const from = row === bounds.start.row ? Math.min(bounds.start.column, cells) : 0\n const to = row === bounds.end.row ? Math.min(bounds.end.column, cells) : cells\n return to <= from ? undefined : { from, to }\n}\n\n/**\n * The selected text, with wrapped rows rejoined into the lines they came from.\n *\n * A row's `continuation` flag is what makes this a copy of the *source* rather than of the layout: without\n * it, pasting a wrapped paragraph would carry the newlines this renderer invented. The role prefix is\n * dropped for the same reason — `› ` and ` · ` are chrome nobody typed.\n *\n * Trailing whitespace goes per logical line, not per row, so a break that consumed a space does not leave\n * one behind in the middle of a rejoined sentence.\n */\nexport function selectedText(\n rows: readonly TranscriptRow[],\n selection: TextSelection | undefined,\n): string {\n const bounds = textBounds(selection)\n if (bounds === undefined) return \"\"\n const lines: string[] = []\n for (let row = bounds.start.row; row <= bounds.end.row; row += 1) {\n const current = rows[row]\n if (current === undefined) continue\n const cells = [...current.text]\n const range = rowSelection(selection, row, cells.length)\n // A row with nothing selected still counts as a line break when it is inside the range: a blank\n // row between two turns is a blank line in what gets pasted.\n const text =\n range === undefined\n ? \"\"\n : cells.slice(Math.max(range.from, current.lead), range.to).join(\"\")\n if (current.continuation && lines.length > 0) {\n lines[lines.length - 1] += text\n continue\n }\n lines.push(text)\n }\n return lines.map((line) => line.replace(/\\s+$/, \"\")).join(\"\\n\")\n}\n\n/** Word characters, matching the composer's own idea of a word so a double-click agrees with `⌥←`. */\nfunction isWordChar(char: string | undefined): boolean {\n return char !== undefined && !/\\s/.test(char)\n}\n\n/** The word under a point, as a selection. Falls back to the whole row when the point is whitespace. */\nexport function wordAt(rows: readonly TranscriptRow[], at: TextPoint): TextSelection {\n const row = rows[at.row]\n if (row === undefined) return { anchor: at, focus: at, dragging: false }\n const cells = [...row.text]\n if (!isWordChar(cells[at.column])) return lineAt(rows, at)\n let from = at.column\n let to = at.column\n while (from > row.lead && isWordChar(cells[from - 1])) from -= 1\n while (to < cells.length && isWordChar(cells[to])) to += 1\n return {\n anchor: { row: at.row, column: from },\n focus: { row: at.row, column: to },\n dragging: false,\n }\n}\n\n/** The whole row under a point, prefix excluded. */\nexport function lineAt(rows: readonly TranscriptRow[], at: TextPoint): TextSelection {\n const row = rows[at.row]\n const cells = row === undefined ? 0 : [...row.text].length\n return {\n anchor: { row: at.row, column: row?.lead ?? 0 },\n focus: { row: at.row, column: cells },\n dragging: false,\n }\n}\n",
|
|
15
|
+
"/**\n * Milliseconds since `active` became true, ticking while it stays true.\n *\n * This is the only clock in the CLI's view layer, and it is deliberately isolated: the transcript\n * reducer takes its durations from `turn.end`, so it needs no clock and stays deterministic. What\n * needs a clock is the \"thinking for 4s\" counter, whose entire job is to distinguish a slow model\n * from a hung one — the case where showing nothing is worst.\n */\n\nimport { useEffect, useState } from \"react\"\n\nconst TICK_MS = 100\n\nexport function useElapsed(active: boolean): number {\n const [elapsed, setElapsed] = useState(0)\n\n useEffect(() => {\n if (!active) {\n setElapsed(0)\n return\n }\n const startedAt = Date.now()\n setElapsed(0)\n const id = setInterval(() => setElapsed(Date.now() - startedAt), TICK_MS)\n return () => clearInterval(id)\n }, [active])\n\n return elapsed\n}\n",
|
|
16
|
+
"/**\n * The bridge between the event bus and React state.\n *\n * The CLI has always subscribed to `runtime.bus`; this makes it a reducer over that bus rather than\n * a set of callbacks writing to stdout. All the interesting logic lives in `transcript.ts`, which is\n * pure and tested — this hook only owns the subscription, the abort controller, and the promise.\n */\n\nimport type { AnyEvent } from \"@dispach/core\"\nimport { useCallback, useEffect, useReducer, useRef } from \"react\"\nimport type { AgentSource } from \"#lib/source\"\nimport type { TranscriptState } from \"#lib/types\"\nimport { reduce, type TranscriptAction } from \"#transcript\"\n\nexport interface UseTurn {\n readonly state: TranscriptState\n /** A turn is in flight. Drives the Ctrl-C contract and the status bar. */\n readonly busy: boolean\n send(text: string): void\n cancel(): void\n note(text: string): void\n /**\n * Drop the oldest items if the buffer is over its cap. Safe to call on every change — a buffer\n * under the cap returns identical state and React skips the render.\n *\n * Exposed rather than done inside the reducer because the caller owns the scroll state, and\n * eviction while somebody is parked in history would move rows under them. `App` calls this only\n * while following the tail.\n */\n trim(): void\n}\n\nexport function useTurn(options: {\n /**\n * Where the agent is, rather than which object it is.\n *\n * This took an `Agent` and an `EventBus` directly, which is what made the TUI a second *owner*\n * of a runtime rather than a view of one. Nothing in this hook changes between the two: it\n * subscribes, it sends, it aborts, and each of those is one call the source implements its own\n * way — attached, an abort becomes a request naming the turn, because a turn belongs to the\n * server and is never cancelled by a disconnect.\n */\n readonly source: AgentSource\n readonly sessionKey: string\n readonly initial: TranscriptState\n}): UseTurn {\n const { source, sessionKey, initial } = options\n const [state, dispatch] = useReducer(reduce, initial)\n const controller = useRef<AbortController | undefined>(undefined)\n\n // A stream filter is stateful and the reducer is pure, so filtering happens here, on the way in.\n // Without it the live pane shows `ACTION:` and `END` and then commits them as the reply: with a\n // line-oriented dialect the invocation *is* text, and only the dialect knows which text.\n const filter = useRef(source.streamFilter())\n\n useEffect(() => {\n // One wildcard subscription rather than six by name: the reducer already ignores what it\n // does not own, and a subscription list would silently miss any event a later phase adds.\n //\n // `{ chunks: true }` is not optional here and is the whole reason the TUI streams. A\n // wildcard subscriber receives no `model.chunk` unless it asks — because `/v1/events`, the\n // WebSocket bridge and every plugin watcher are also wildcard and must not be put on the\n // per-token path by accident. This is the one wildcard in the tree that genuinely wants\n // tokens; drop the flag and the TUI silently stops streaming, which is the same shape of\n // failure the per-subscriber opt-in was introduced to remove.\n return source.subscribe((event: AnyEvent) => {\n // Other sessions share this bus — from Phase 4, a channel can be delivering a turn for\n // a different peer while this prompt is open. An event with no session key is\n // runtime-wide and belongs to everyone.\n if (event.sessionKey !== undefined && event.sessionKey !== sessionKey) return\n\n // Reasoning is never parsed for tool calls, so it is never filtered for them either.\n if (event.type === \"model.chunk\") {\n const { delta, kind } = event.data\n if (kind === \"reasoning\") {\n dispatch({ kind: \"delta\", of: \"reasoning\", text: delta })\n return\n }\n dispatch({ kind: \"delta\", of: \"text\", text: filter.current.push(delta) })\n return\n }\n\n // The filter owns the paragraph break between one step's narration and the next's, which\n // is why it is told where a step ends rather than being replaced at each one.\n if (event.type === \"model.result\") {\n dispatch({ kind: \"delta\", of: \"text\", text: filter.current.endStep() })\n return\n }\n\n if (event.type === \"turn.end\") {\n // Flush before the reducer commits the reply, or the last line of it is lost.\n dispatch({ kind: \"delta\", of: \"text\", text: filter.current.end() })\n filter.current = source.streamFilter()\n }\n\n dispatch({ kind: \"event\", event })\n })\n }, [source, sessionKey])\n\n const send = useCallback(\n (text: string) => {\n dispatch({ kind: \"user\", text })\n const next = new AbortController()\n controller.current = next\n // `send` resolves rather than rejects on abort, so cancellation is not an error path.\n // Anything that does reject got past the loop's own handling, and swallowing it would be\n // the silent failure hard rule 8 forbids — so it is reported and the prompt returns.\n source\n .send(text, { sessionKey, signal: next.signal })\n .catch((error: unknown) => {\n dispatch({\n kind: \"event\",\n event: {\n v: 1,\n ts: new Date().toISOString(),\n runtimeId: \"cli\",\n sessionKey,\n type: \"error\",\n data: {\n code: \"cli_turn_failed\",\n message: error instanceof Error ? error.message : String(error),\n hint: \"This escaped the turn loop's own error handling. Re-run with DEBUG=1 for a stack trace.\",\n },\n },\n })\n })\n .finally(() => {\n if (controller.current === next) controller.current = undefined\n })\n },\n [source, sessionKey],\n )\n\n const cancel = useCallback(() => {\n const current = controller.current\n if (current === undefined || current.signal.aborted) return\n dispatch({ kind: \"cancelling\" })\n current.abort()\n }, [])\n\n const note = useCallback(\n (text: string) => dispatch({ kind: \"note\", text } as TranscriptAction),\n [],\n )\n\n const trim = useCallback(() => dispatch({ kind: \"trim\" }), [])\n\n return { state, busy: state.status !== \"idle\", send, cancel, note, trim }\n}\n",
|
|
17
|
+
"/**\n * How tall each piece of the chat frame is, so the conversation gets exactly the rows that are left.\n *\n * ## Why this has to be arithmetic and not flexbox\n *\n * On the alternate screen the layout has a hard ceiling: the terminal's height, with no scrollback to\n * absorb an overshoot. One row too many and Ink's own output scrolls the buffer, which leaves the status\n * line halfway up the display and the composer where the status line was — a corrupt frame rather than a\n * cramped one. Yoga will not save us here, because the thing that overflows is *our* choice of how many\n * transcript rows to hand it.\n *\n * So every piece of chrome reports its height, the sum is subtracted from the terminal, and the\n * conversation gets the remainder. `bodyRows` spends one further row as a margin, in the direction that\n * cannot be seen.\n *\n * ## The drift this invites, and how it is caught\n *\n * These functions restate each component's geometry, which means a component that grows a row without\n * changing its function here would make the frame one row too tall. That is a real hazard and it is\n * pinned by frame tests: each function is asserted against the line count of the actual render, so the\n * two cannot disagree for longer than one test run. Deriving the number *from* a render is not available\n * — the layout has to be decided before anything is drawn.\n *\n * Pure: editor state, palette matches and live text in, row counts out.\n */\n\nimport { searchMatches } from \"#editor\"\nimport { composerLayout } from \"#lib/composer\"\nimport {\n BRAND_GAP_ROWS,\n LIVE_PANE_MAX_ROWS,\n MAX_INPUT_ROWS,\n MIN_LANDING_TRANSCRIPT,\n} from \"#lib/const\"\nimport type { Palette } from \"#lib/palette\"\nimport { viewport } from \"#lib/rows\"\nimport { bodyRows } from \"#lib/scroll\"\nimport type { EditorState, LiveTurn } from \"#lib/types\"\nimport { livePane } from \"#lib/wrap\"\n\n/** The one-line header, the status line, and the row the transcript reserves for its scroll counter. */\nconst HEADER_ROWS = 1\nconst STATUS_ROWS = 1\nconst SCROLL_HINT_ROWS = 1\n/** `Prompt` wraps `LineCursor` in a bordered box: one row of border above and one below. */\nconst PROMPT_BORDER_ROWS = 2\n/** The same box's two border columns and its `paddingX={1}` on each side. */\nconst PROMPT_PADDING = 4\n/** `PROMPT` — the `\\u203a ` the composer draws before the first row and matches with a blank after it. */\nconst PROMPT_GUTTER = 2\n/** `\\u00b7 reasoning \\u00b7 ` — the prefix `Live` puts on its first row, which narrows the wrap. */\nconst LIVE_LABEL = 14\n\n/**\n * The composer, including its border and the newline hint it shows once a message has two lines.\n *\n * One form, both states. There used to be a `roomy` landing variant three rows taller, which existed\n * because the composer sat directly under the banner with the slack below it — the padding was what kept\n * its border off the text above. With the slack above it (decision 11.98, reversed) there is nothing to\n * separate it from, and 11.90's own argument now applies to both states rather than one: every row the\n * composer takes is a row of conversation, and this is the function that charges for them.\n */\nexport function promptRows(editor: EditorState, columns: number): number {\n // Visual rows, not logical lines. Counting lines was correct only while nothing wrapped, and it went\n // wrong in the direction that cannot be seen: a wrapped message drew more rows than the frame had\n // subtracted, so the bottom of the composer went under the status line.\n const { rows, caretRow } = composerLayout(\n editor,\n Math.max(1, columns - PROMPT_PADDING - PROMPT_GUTTER),\n )\n const total = rows.length\n // Through `viewport`, the function `LineCursor` itself calls, rather than a second guess at where the\n // window lands. Each side of it spends a row on a \"… n lines above/below\" notice when it hides\n // something, so the count has to come from the same arithmetic that decides whether it does.\n const { from, to } = viewport(total, caretRow, Math.max(1, Math.min(total, MAX_INPUT_ROWS)))\n return (\n PROMPT_BORDER_ROWS +\n (to - from) +\n (from > 0 ? 1 : 0) +\n (total - to > 0 ? 1 : 0) +\n // Logical lines, not rows: the newline hint answers \"how do I add another line\", and a message\n // that merely wrapped has not added one. Counting rows here made the frame one row taller than\n // the render for every message wide enough to wrap — the same disagreement, in the other\n // direction, as counting lines for the viewport.\n (editor.value.includes(\"\\n\") ? 1 : 0)\n )\n}\n\n/** The slash-command list: its matches, its overflow notices, and the line naming its keys. */\nexport function paletteRows(palette: Palette | undefined, maxRows: number): number {\n if (palette === undefined) return 0\n // The empty case renders one line saying nothing matched, and no key hint — there is nothing to do.\n if (palette.matches.length === 0) return 1\n const shown = Math.min(palette.matches.length, maxRows)\n const overflow = palette.matches.length > shown ? 1 : 0\n return shown + overflow + 1\n}\n\n/** `^R`'s match list plus its query line. Zero when the search is closed. */\nexport function searchRows(editor: EditorState, maxRows: number): number {\n if (editor.search === undefined) return 0\n const matches = searchMatches(editor)\n return (matches.length === 0 ? 1 : Math.min(matches.length, maxRows)) + 1\n}\n\nexport interface ChatFrame {\n /**\n * Rows the brand mark **may** use above the one-line header, or 0 once it has collapsed.\n *\n * An allowance, not a height, and the caller must charge the conversation for what the mark *actually*\n * draws — `wordmark` degrades through its tiers and usually takes far less. Charging the allowance was\n * the first version and it wasted eleven rows on a thirty-row terminal: the mark drew five, the\n * transcript was billed sixteen, and the banner ended up scrolled to a mid-wrap fragment of a store path\n * with a third of the screen blank.\n *\n * Floored so a landing screen always keeps enough transcript for the banner. That is where the boot notes\n * and every load warning are written, and a picture hiding them is the trimmed-catalogue failure with\n * better typography: true of what is on screen, false of what is the case.\n */\n readonly brand: number\n /**\n * Rows for the brand mark and the conversation together, before either is measured.\n *\n * Returned so the split happens once, in the caller that knows the mark's rendered height.\n */\n readonly body: number\n /** Rows the conversation may draw if the mark takes none — its scroll counter already deducted. */\n readonly transcript: number\n /** Rows a pane over the conversation may draw. It replaces the transcript rather than sharing. */\n readonly pane: number\n}\n\n/**\n * The row budget for one frame.\n *\n * A pane and the transcript are alternatives, not neighbours. Rendered together the pane took a fixed\n * sixteen rows and pushed the conversation off the top of a full screen — and on a surface with no\n * scrollback, \"off the top\" means gone. Whichever is in front gets the body.\n */\nexport function chatFrame(inputs: {\n readonly rows: number\n readonly columns: number\n readonly editor: EditorState\n readonly live: LiveTurn | undefined\n readonly showReasoning: boolean\n readonly palette: Palette | undefined\n readonly searchMaxRows: number\n readonly paletteMaxRows: number\n /** A confirmation question, which is one line above the composer. */\n readonly confirming: boolean\n /**\n * Nothing has been sent yet, so the brand mark is up.\n *\n * It used to mean a roomier composer as well, and no longer does: the composer is one form in both\n * states now that the slack sits above it. What is left is the wordmark's allowance, which is the only\n * thing on the frame that a landing screen still spends rows on.\n */\n readonly landing: boolean\n /** The one-line hint under the composer, shown only while landing. */\n readonly hint: boolean\n}): ChatFrame {\n const live = inputs.live\n // The live pane shows reasoning only until the reply itself starts, which is the component's rule and\n // therefore has to be this one too.\n const liveText =\n live === undefined\n ? \"\"\n : inputs.showReasoning && live.reasoning !== \"\" && live.text === \"\"\n ? live.reasoning\n : live.text\n\n const chrome =\n HEADER_ROWS +\n STATUS_ROWS +\n livePane(liveText, inputs.columns - LIVE_LABEL, LIVE_PANE_MAX_ROWS).rows +\n paletteRows(inputs.palette, inputs.paletteMaxRows) +\n searchRows(inputs.editor, inputs.searchMaxRows) +\n promptRows(inputs.editor, inputs.columns) +\n (inputs.confirming ? 1 : 0) +\n (inputs.hint ? 1 : 0)\n\n const body = bodyRows(inputs.rows, chrome)\n\n // What is left for the brand mark after the conversation keeps its floor and the blank row under the mark\n // is paid for. Zero once it has collapsed, and zero on a terminal too short to afford it — `wordmark`\n // degrades through its tiers on the way down and then to nothing, so a short screen loses the picture\n // rather than the banner.\n const brand = inputs.landing ? Math.max(0, body - MIN_LANDING_TRANSCRIPT - BRAND_GAP_ROWS) : 0\n\n // The pane draws its own two \"… n lines above/below\" notices and a key-hint line, which is why it\n // reports fewer rows than it is given rather than being handed the whole body.\n return {\n brand,\n body,\n transcript: Math.max(1, body - SCROLL_HINT_ROWS),\n pane: Math.max(1, body - 3),\n }\n}\n\n/**\n * The conversation's rows once the brand mark has taken what it actually needs.\n *\n * Separate from `chatFrame` because it needs the mark's *rendered* height, which only the caller has — and\n * one function rather than an inline subtraction at the call site, so there is no second idea of whether the\n * gap row is included.\n */\n/**\n * Which buffer row a screen cell is on, or `undefined` if the cell is not in the transcript.\n *\n * The one place the frame's vertical arithmetic is read backwards, and it belongs here because this module\n * is where that arithmetic already lives. A caller deriving it would restate the brand's height, the gap,\n * the header and the scroll-hint row — four numbers that are only correct together.\n *\n * Above the transcript, in order: the wordmark and its gap (landing only), the one-line header, and the\n * scroll-hint row `Transcript` always draws even when it is blank. Below it, everything is chrome. A cell\n * outside the window returns `undefined` rather than clamping, because clamping would make a click on the\n * status line select the last row of the conversation.\n */\nexport function transcriptHit(\n point: { readonly column: number; readonly row: number },\n layout: {\n readonly brandLines: number\n /** The window `Transcript` was handed: `from` inclusive, `to` exclusive. */\n readonly from: number\n readonly to: number\n },\n): { readonly row: number; readonly column: number } | undefined {\n const top =\n (layout.brandLines === 0 ? 0 : layout.brandLines + BRAND_GAP_ROWS) +\n HEADER_ROWS +\n SCROLL_HINT_ROWS\n const offset = point.row - top\n if (offset < 0) return undefined\n const row = layout.from + offset\n if (row >= layout.to) return undefined\n return { row, column: point.column }\n}\n\n/**\n * Which offset in the message a screen cell is on, or `undefined` if the cell is not in the composer.\n *\n * The composer's position is computable because the frame is bottom-anchored (decision 11.120): the status\n * line is the last row, the landing hint sits above it, and the composer occupies exactly `promptRows`\n * above that. Counting down from the top would mean knowing the height of every optional block in between\n * — the live pane, the palette, the history search, the confirm line — and being wrong about any one of\n * them would put the caret on the wrong row.\n *\n * Horizontally: one border column, one of `paddingX`, then the two-column prompt gutter. `PROMPT_PADDING`\n * is the pair of borders *and* the pair of paddings, so half of it is the left inset — which is why the\n * text does not start at `PROMPT_PADDING`.\n *\n * The returned offset is a code-point index into `editor.value`, which is what the reducer's `cursor` and\n * `anchor` are: a caller never has to know that rows were involved.\n */\nexport function composerHit(\n point: { readonly column: number; readonly row: number },\n inputs: {\n readonly editor: EditorState\n readonly columns: number\n /** The terminal's height, which is the frame's height. */\n readonly rows: number\n /** Whether the one-line landing hint is drawn under the composer. */\n readonly hint: boolean\n },\n): number | undefined {\n const layout = composerLayout(\n inputs.editor,\n Math.max(1, inputs.columns - PROMPT_PADDING - PROMPT_GUTTER),\n )\n const total = layout.rows.length\n const { from, to } = viewport(\n total,\n layout.caretRow,\n Math.max(1, Math.min(total, MAX_INPUT_ROWS)),\n )\n // Only the notice *above* shifts the text down. The one below sits under it and is already inside the\n // block height, so counting it here would move the first row twice.\n const above = from > 0 ? 1 : 0\n // The newline hint is inside `Prompt`'s own box, so it is part of what `promptRows` counts and needs\n // no separate term here.\n const block = promptRows(inputs.editor, inputs.columns)\n const top = inputs.rows - STATUS_ROWS - (inputs.hint ? 1 : 0) - block\n // One border row, then any \"… n lines above\" notice, then the visible rows.\n const firstText = top + PROMPT_BORDER_ROWS / 2 + above\n const offset = point.row - firstText\n if (offset < 0 || offset >= to - from) return undefined\n const row = layout.rows[from + offset]\n if (row === undefined) return undefined\n // Left inset: half of `PROMPT_PADDING` is the left border plus the left padding.\n const textColumn = point.column - PROMPT_PADDING / 2 - PROMPT_GUTTER\n if (textColumn < 0) return row.start\n // Past the end of the row's text means the end of that row, which is what clicking in the empty space\n // after a short line means everywhere else.\n return Math.min(row.end, row.start + Math.max(0, textColumn - row.lead))\n}\n\nexport function transcriptRowsAfterBrand(frame: ChatFrame, brandLines: number): number {\n const used = brandLines === 0 ? 0 : brandLines + BRAND_GAP_ROWS\n return Math.max(1, frame.body - used - SCROLL_HINT_ROWS)\n}\n",
|
|
18
|
+
"/**\n * Putting text on the system clipboard.\n *\n * ## Why this has to exist at all\n *\n * `cmd+c` cannot reach a terminal application. The terminal's own Edit > Copy claims it first, and finds no\n * native selection to copy because mouse tracking disabled the terminal's selection in order to deliver the\n * drag events. The reference CLI says the same thing in its own words and draws the same conclusion: copy\n * on mouse-up, so `cmd+v` then works and the chord nobody can intercept is the one that matters.\n *\n * ## Why not OSC 52\n *\n * There is an escape sequence for this — `OSC 52` asks the terminal to set the clipboard — and it is\n * refused, truncated, or silently ignored by enough terminals that a copy would sometimes do nothing with\n * no way to tell. A subprocess either runs or reports why. It is also the only form that works over ssh\n * *without* the remote terminal cooperating, which is a real advantage OSC 52 has; the trade is taken\n * knowingly, and a failure says which command was missing.\n */\n\nimport { spawnCaptureAsync } from \"#lib/spawn\"\n\n/** Candidates in order of preference, first one present wins. */\nconst WRITERS: readonly { readonly command: string; readonly args: readonly string[] }[] = [\n // macOS.\n { command: \"pbcopy\", args: [] },\n // Wayland, before X11: a Wayland session usually has `xclip` too, through Xwayland, and writing to the\n // X clipboard there puts the text somewhere the compositor's own paste will not find it.\n { command: \"wl-copy\", args: [] },\n { command: \"xclip\", args: [\"-selection\", \"clipboard\"] },\n { command: \"xsel\", args: [\"--clipboard\", \"--input\"] },\n]\n\nexport interface CopyResult {\n readonly copied: boolean\n /** Which command did it, for a message that names what happened rather than asserting success. */\n readonly using?: string\n readonly problem?: string\n}\n\n/**\n * Copy `text` to the clipboard, or say why not.\n *\n * Never throws and never reports success it did not have: a copy that silently failed leaves somebody\n * pasting the *previous* contents of their clipboard, which looks like the wrong text was selected.\n */\nexport async function copyToClipboard(text: string): Promise<CopyResult> {\n if (text === \"\") return { copied: false, problem: \"nothing selected\" }\n const missing: string[] = []\n for (const writer of WRITERS) {\n const result = await spawnCaptureAsync({\n command: writer.command,\n args: writer.args,\n input: text,\n // Generous but bounded: a clipboard helper that hangs must not hang the session with it.\n timeoutMs: 2_000,\n })\n if (result.notFound) {\n missing.push(writer.command)\n continue\n }\n if (result.code === 0) return { copied: true, using: writer.command }\n return {\n copied: false,\n using: writer.command,\n problem: result.stderr.trim() || `${writer.command} exited ${result.code}`,\n }\n }\n return { copied: false, problem: `no clipboard command found (tried ${missing.join(\", \")})` }\n}\n",
|
|
19
|
+
"/**\n * The slash-command palette: what a partially typed `/word` could mean.\n *\n * ## Generated, not listed\n *\n * The entries come from two tables that already exist. `SESSION_COMMANDS` holds the verbs that only make\n * sense inside a session — `/help`, `/reset`, `/exit` — and `COMMANDS` holds the whole CLI, with every\n * flag, every `choices` value and every summary already written down for `--help`.\n *\n * Reading `COMMANDS` rather than a second list is the load-bearing decision. A flag added to the CLI\n * appears in the TUI with nothing to remember, which is the discipline `session-commands.ts`'s own header\n * argues for after watching `/help` drift in both directions when it was a string in a component. A\n * command that should not be offered in a session declares `inSession: \"hidden\"` — hiding by omission\n * from a hand-written list is the same drift wearing a different hat, and a required field means a new\n * command cannot be silently absent instead.\n *\n * ## Pure\n *\n * Derived from the editor's value, so the only state the renderer adds is a cursor index. No filesystem,\n * no process, no renderer — PURE-listed, and the matching rules are asserted as data.\n */\n\nimport { COMMANDS } from \"#lib/commands\"\nimport type { CommandSpec } from \"#lib/schema\"\nimport { SESSION_COMMANDS } from \"#lib/session-commands\"\n\nexport interface PaletteEntry {\n /** With the slash, as it would be typed. */\n readonly word: string\n readonly summary: string\n /**\n * `session` — dispatched by `resolveSessionCommand`.\n * `view` — a bespoke screen.\n * `output` — run the command and show what it printed.\n */\n readonly kind: \"session\" | \"view\" | \"output\"\n /** Present for a CLI command, so a host can read its flags and actions. */\n readonly spec?: CommandSpec\n}\n\n/**\n * Every entry a session offers, session verbs first.\n *\n * Session verbs lead because they are the ones with no shell equivalent and the ones typed most: `/help`\n * and `/exit` at the top of an unfiltered list is what makes the palette answer \"what can I do here\"\n * rather than \"what commands exist\".\n */\nexport function paletteEntries(): readonly PaletteEntry[] {\n const session: PaletteEntry[] = SESSION_COMMANDS.map((spec) => ({\n word: spec.word,\n summary: spec.summary,\n kind: \"session\" as const,\n }))\n const own = new Set(session.map((entry) => entry.word))\n const commands: PaletteEntry[] = COMMANDS.filter((spec) => spec.inSession !== \"hidden\")\n // A CLI command whose name collides with a session verb loses: `/tools` inside a session means\n // the running agent's catalogue, not a fresh load of the manifest from disk.\n .filter((spec) => !own.has(`/${spec.name}`))\n .map((spec) => ({\n word: `/${spec.name}`,\n summary: spec.summary,\n kind: spec.inSession === \"view\" ? (\"view\" as const) : (\"output\" as const),\n spec,\n }))\n return [...session, ...commands]\n}\n\nexport interface Palette {\n /** What has been typed after the slash, lowercased. */\n readonly query: string\n readonly matches: readonly PaletteEntry[]\n}\n\n/**\n * The palette for a buffer, or `undefined` when the buffer is not a slash command being typed.\n *\n * Open only while the *whole* buffer is one `/word` under construction. Two consequences, both\n * deliberate: a message that merely mentions a path never opens it, and once arguments are being typed\n * the list closes, because there is nothing left to complete and a list covering the line would hide\n * what is being written.\n */\nexport function paletteFor(\n value: string,\n entries: readonly PaletteEntry[] = paletteEntries(),\n): Palette | undefined {\n if (!/^\\/[A-Za-z-]*$/.test(value)) return undefined\n const query = value.slice(1).toLowerCase()\n const matches = entries.filter((entry) => entry.word.slice(1).toLowerCase().startsWith(query))\n // Prefix, not fuzzy. A palette that offers `/sessions` for `/st` reads as noise, and the words are\n // short enough that a prefix always reaches them in two or three characters.\n return { query, matches }\n}\n\n/** The entry a cursor is on, clamped, or `undefined` when nothing matches. */\nexport function paletteSelection(palette: Palette, index: number): PaletteEntry | undefined {\n if (palette.matches.length === 0) return undefined\n return palette.matches[Math.max(0, Math.min(index, palette.matches.length - 1))]\n}\n\n/**\n * The command names a typed slash line may use, without the leading slash.\n *\n * `resolveSessionCommand` takes this list, and it defaulted to empty at the one call site that mattered\n * — so a typed `/config get x` was prose and the same command chosen from the palette ran. Derived from\n * the palette rather than from `COMMANDS` directly, because the palette is what the person was just\n * shown: anything offered there has to be typeable, and anything typeable has to be offered.\n */\nexport function offeredCommands(): readonly string[] {\n return paletteEntries()\n .filter((entry) => entry.kind !== \"session\")\n .map((entry) => entry.word.slice(1))\n}\n",
|
|
20
|
+
"/**\n * Running one of this binary's own commands, for a pane inside a session.\n *\n * ## Why a child process rather than calling the function\n *\n * The obvious implementation is to call `validateCommand()` and swap `process.stdout.write` for a\n * collector. It is also wrong here: Ink *owns* stdout while a session is mounted, and it writes a frame\n * whenever anything re-renders. A frame drawn during the capture window lands in the collector instead of\n * on the terminal — so the screen silently misses a repaint and the pane shows a frame of itself. Nothing\n * errors; the display is just wrong, intermittently, depending on timing.\n *\n * A child writes to its own pipe. Nothing is hijacked, the frame keeps rendering, and the pane shows\n * exactly what the command prints — which is also the honest thing to show, since \"run this command\" is\n * what the palette offered. The cost is process startup, which is the same ~100 ms every command in this\n * CLI already pays and is invisible next to reading the result.\n *\n * `--plain` is forced, for the reason it exists: a child that thought it had a terminal would return\n * escape sequences, and the pane would render them as text.\n */\n\nimport { findCommand } from \"#lib/commands\"\nimport { spawnCaptureAsync } from \"#lib/spawn\"\n\nexport interface SubcommandResult {\n readonly lines: readonly string[]\n readonly code: number\n}\n\nexport interface SubcommandRequest {\n readonly name: string\n /** Arguments as typed after the command word, split on whitespace. */\n readonly rest: string\n /** The agent this session is running, passed to any command that takes a manifest. */\n readonly manifestPath: string\n /** Injected by tests. `process.execPath` and `process.argv[1]` otherwise. */\n readonly interpreter?: string\n readonly script?: string\n readonly env?: Readonly<Record<string, string | undefined>>\n readonly timeoutMs?: number\n}\n\n/**\n * Where this command wants the manifest among its positionals, or `-1` for one that takes none.\n *\n * Read off the command's own spec rather than a hand-kept list, which was wrong in both directions at\n * once. `NO_MANIFEST` held four names: `soul` takes an *action* first and was not listed, so\n * `/soul distill` ran as `soul <manifestPath> distill` and the action became a path — broken in-session\n * for as long as it has been offered there; and `agents` takes a variadic manifest first and *was*\n * listed, so it ran with none at all.\n *\n * It also could not express the real shape. `config` and `memory` take an action and *then* a manifest,\n * so \"prepend or not\" has no right answer for them — the path belongs at index 1. `soul`'s second\n * positional is a `file` (a long-form identity document, not a manifest), which is why matching on the\n * name matters rather than on the position.\n *\n * The same drift `session-commands.ts` exists to end: a second list describing `COMMANDS` disagrees with\n * it on the first command either one grows. Derived, a new command is covered with nothing to remember.\n */\nfunction manifestIndex(name: string): number {\n return findCommand(name)?.args.findIndex((arg) => arg.name === \"manifest\") ?? -1\n}\n\n/**\n * The argv for a request.\n *\n * Pure and exported so the assembly is testable without starting anything — which matters because\n * getting it wrong means a command runs against the wrong agent, and that is not visible in the output.\n */\nexport function subcommandArgv(request: SubcommandRequest): readonly string[] {\n const rest = request.rest.trim() === \"\" ? [] : request.rest.trim().split(/\\s+/)\n const at = manifestIndex(request.name)\n // Inserted only when everything before it was typed. `/skills` bare would otherwise become\n // `skills <manifestPath>`, putting a path where the action goes — and a command that resolves the\n // agent from the cwd instead is the lesser wrong: it may pick a different agent, where this one\n // cannot run at all. `--plain` stays last, so it cannot be swallowed as a flag's value.\n const positionals =\n at === -1 || rest.length < at\n ? rest\n : [...rest.slice(0, at), request.manifestPath, ...rest.slice(at)]\n return [request.name, ...positionals, \"--plain\"]\n}\n\n/**\n * Why a pane must not run this request, if it must not.\n *\n * A pane captures a child to completion, so a command that never finishes is a pane that shows a spinner\n * until the timeout fires and then reports being killed — thirty seconds of a frozen surface for a flag\n * that worked perfectly at a shell. `daemon logs --follow` is the case: it exists precisely to keep\n * printing until interrupted, and there is nothing for it to be interrupted *by* in here.\n *\n * Refused rather than quietly dropped. Dropping the flag would hand back the tail, which looks like a\n * following command that stopped immediately — a wrong answer that reads as a right one. Keyed off the\n * command's own spec, so a second command that grows a `follow` flag is covered with nothing to remember.\n */\nexport function paneRefusal(request: SubcommandRequest): string | undefined {\n const spec = findCommand(request.name)\n if (spec === undefined) return undefined\n const follow = spec.flags.find((flag) => flag.name === \"follow\")\n if (follow === undefined) return undefined\n const tokens = request.rest.trim().split(/\\s+/)\n const asked = tokens.some(\n (token) =>\n token === \"--follow\" || (follow.short !== undefined && token === `-${follow.short}`),\n )\n if (!asked) return undefined\n return `--follow keeps printing until it is interrupted, and a pane has nothing to interrupt it with. Run it in its own terminal: ${request.name} ${request.rest.trim()}`\n}\n\nexport async function runSubcommand(request: SubcommandRequest): Promise<SubcommandResult> {\n const refusal = paneRefusal(request)\n // Non-zero, because it did not do what was asked. A refusal reported as success is the shape hard\n // rule 8 forbids, whatever the message says.\n if (refusal !== undefined) return { lines: [refusal], code: 1 }\n\n const interpreter = request.interpreter ?? process.execPath\n const script = request.script ?? process.argv[1] ?? \"\"\n const result = await spawnCaptureAsync({\n command: interpreter,\n args: [script, ...subcommandArgv(request)],\n ...(request.env === undefined ? {} : { env: request.env }),\n timeoutMs: request.timeoutMs ?? 30_000,\n })\n\n // stderr is shown, not dropped. A command that failed says why on stderr, and a pane that showed only\n // stdout would render an empty box for the case a person most needs to read.\n const body = [result.stdout, result.stderr].filter((part) => part.trim() !== \"\").join(\"\\n\")\n const lines = body === \"\" ? [] : body.replace(/\\n+$/, \"\").split(\"\\n\")\n if (result.notFound) {\n return { lines: [`could not run ${interpreter}`], code: 1 }\n }\n if (result.signalled) {\n return { lines: [...lines, `${request.name} was stopped before it finished`], code: 1 }\n }\n return { lines, code: result.code }\n}\n"
|
|
21
|
+
],
|
|
22
|
+
"mappings": ";0rBA2BA,cAAS,UAAK,YAAM,eAAQ,aAC5B,sBAA6B,gBAAa,cAAW,aAAS,eAAQ,cCVtE,cAAS,WAAK,iEAgBP,SAAS,EAAa,EAAG,QAAO,QAAO,SAAQ,UAAS,QAA4B,CACvF,GAAI,IAAU,OACV,OACI,GAEE,GAFF,CAAK,WAAY,EAAjB,SACI,GAAC,GAAD,CAAS,MAAO,WAAW,IAAS,EACtC,EAIV,GAAI,EAAM,SAAW,EACjB,OACI,GAEE,GAFF,CAAK,WAAY,EAAjB,SACI,GAAmD,GAAnD,CAAM,MAAO,EAAM,MAAnB,SAAmD,CAAxB,EAA3B,oBAAmD,EACrD,EAMV,IAAQ,OAAM,MAAO,EACjB,EAAM,OACN,KAAK,IAAI,EAAS,KAAK,MAAM,EAAU,CAAC,EAAG,EAAM,OAAS,CAAC,EAC3D,CACJ,EAEM,EAAU,EAAM,MAAM,EAAM,CAAE,EAAE,IAAI,CAAC,EAAM,KAAQ,CAAE,IAAK,EAAO,EAAI,MAAK,EAAE,EAElF,OACI,GA4BE,GA5BF,CAAK,cAAc,SAAnB,SA4BE,CA3BG,IAAS,QAAa,IAAS,EAC5B,GAGE,GAHF,CAAM,MAAO,EAAM,MAAO,KAAK,WAA/B,SAGE,CAFG,EAAM,MACN,EAFL,WAEoB,GAClB,EACF,KACH,EAAO,EACJ,GAGE,GAHF,CAAM,SAAQ,GAAC,KAAK,WAApB,SAGE,CAFG,KACA,EAAM,SAFX,IAEsB,EAFtB,QAEiC,IAAS,EAAI,GAAK,IAFnD,UAGE,EACF,KACH,EAAQ,IAAI,CAAC,IAIV,GAEE,GAFF,CAAsB,KAAK,WAA3B,SACK,EAAM,MADA,EAAM,GAEf,CACL,EACA,EAAK,EAAM,OACR,GAIE,GAJF,CAAM,SAAQ,G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,CAAM,SAAQ,GAAC,KAAK,WAApB,SAGE,CAFG,KACA,IACH,EACF,KAGJ,EAAC,GAAD,CACI,OAAQ,EAAM,OACd,MAAO,EACP,WAAY,EACZ,UAAW,GACX,KAAM,GACN,MAAO,EACP,MAAO,MACF,EAAM,WAAa,OAAY,CAAC,EAAI,CAAE,SAAU,EAAM,QAAS,KAC/D,EAAM,QAAU,OAAY,CAAC,EAAI,CAAE,MAAO,EAAM,KAAM,EAC/D,GACF",
|
|
23
|
+
"debugId": "F5B3369F1640538C64756E2164756E21",
|
|
24
|
+
"names": []
|
|
25
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import"./index-qc2vrq9z.js";import{o,S,R}from"./index-jk0def33.js";import"./index-h2yds678.js";import{Vt}from"./index-jym27m75.js";import{re}from"./index-rqbtm761.js";import{D,X,gn}from"./index-6z0yr17z.js";import{qe,Ze,_n}from"./index-my5cjx00.js";import{Box as H,Text as d,useInput as Y}from"ink";import{useState as z}from"react";function E(e){return e!==void 0&&e.kind!=="heading"}function T(e){switch(e.kind){case"setting":return`setting:${e.setting.path}`;case"allow":return`allow:${e.channelId}`;case"secret":return`secret:${e.name}`;case"heading":return`heading:${e.label}`}}function L(e){let t=e.findIndex((r)=>E(r));return t===-1?0:t}function M(e){return{rows:e,cursor:L(e),mode:"browse",editor:D,busy:!1}}function I(e,t){let r=e.rows.length;if(r===0)return e;let l=Math.max(0,Math.min(r-1,t)),h=l>=e.cursor?1:-1;for(let i=l;i>=0&&i<r;i+=h)if(E(e.rows[i]))return{...e,cursor:i};for(let i=l;i>=0&&i<r;i-=h)if(E(e.rows[i]))return{...e,cursor:i};return e}function w(e){return e.rows[e.cursor]}function G(e){switch(e.kind){case"setting":return e.value===void 0||e.value===null?"":typeof e.value==="string"?e.value:JSON.stringify(e.value);case"allow":return e.handles.join(" ");case"secret":case"heading":return""}}function O(e){let t=w(e);if(t===void 0||!E(t)||e.busy)return e;let r=G(t);return{...e,mode:"editing",editor:{...D,value:r,cursor:[...r].length},note:void 0}}function _(e){if(e.mode!=="editing")return e;return{...e,mode:"browse",editor:D,note:void 0}}function W(e,t){return{...e,editor:t,note:void 0}}function F(e){return{...e,busy:!0}}function N(e,t,r){return{...e,rows:t,cursor:Math.min(e.cursor,Math.max(0,t.length-1)),mode:"browse",editor:D,busy:!1,note:r}}function P(e,t){return{...e,busy:!1,note:t}}import{jsx as a,jsxs as x}from"react/jsx-runtime";function ge({rows:e,apply:t,reload:r,columns:l,window:m,focused:h=!0,onDone:i}){let K=re(),v=Math.max(qe,Math.min(m,K.rows-Ze)),[n,u]=z(()=>M(e)),[C,j]=z(!1),g=w(n);Y((f,c)=>{if(n.busy)return;let s=gn(f,c,{select:n.mode==="browse",empty:n.editor.value===""});if(s.kind==="abort"){i(C);return}if(s.kind==="back"){if(n.mode==="editing")u(_);else i(C);return}if(s.kind==="list"){if(s.intent.kind==="move"){let y=s.intent.move;u((k)=>I(k,Q(y,k)))}return}if(s.kind==="commit"){if(n.mode==="browse"){u(O);return}J();return}u((y)=>W(y,X(y.editor,s.intent)))},{isActive:h});async function J(){let f=w(n);if(f===void 0)return;u(F);try{let c=await t(f,n.editor.value);j(!0),u((s)=>N(s,r(),c))}catch(c){u((s)=>P(s,c instanceof Error?c.message:String(c)))}}if(n.mode==="editing"&&g!==void 0)return x(H,{flexDirection:"column",children:[a(d,{color:o.muted,wrap:"truncate",children:` ${Z(g)}`}),a(Vt,{label:A(g),editor:n.editor,secret:g.kind==="secret",columns:l,maxRows:Math.max(_n,v-2),...n.note===void 0?{}:{error:n.note}}),a(d,{dimColor:!0,wrap:"truncate",children:n.busy?" writing…":` enter writes it · ${U(g)} · ^C closes`})]});let{from:p,to:b}=R(n.rows.length,n.cursor,v);return x(H,{flexDirection:"column",children:[p>0?a(d,{dimColor:!0,wrap:"truncate",children:` ↑ ${p} above`}):void 0,n.rows.slice(p,b).map((f,c)=>a(q,{row:f,selected:p+c===n.cursor,columns:l},T(f))),b<n.rows.length?a(d,{dimColor:!0,wrap:"truncate",children:` ↓ ${n.rows.length-b} below`}):void 0,a(d,{color:n.note===void 0?o.muted:o.accent,wrap:"truncate",children:n.note===void 0?" ↑↓ move · enter changes it · esc closes":` ${n.note}`})]})}function q({row:e,selected:t,columns:r}){if(e.kind==="heading")return a(d,{color:o.muted,wrap:"truncate",children:`
|
|
3
|
+
${e.label}`});let l=S(A(e),Math.min(34,Math.max(12,Math.floor(r*0.34)))),m=S(B(e),Math.max(8,r-l.length-8));return x(d,{wrap:"truncate",children:[t?a(d,{color:o.accent,children:" ❯ "}):a(d,{children:" "}),a(d,{children:l.padEnd(Math.min(34,Math.max(12,Math.floor(r*0.34))))}),a(d,{color:o.muted,children:` ${m}`})]})}function Q(e,t){switch(e.kind){case"up":return t.cursor-1;case"down":return t.cursor+1;case"first":return 0;case"last":return t.rows.length-1;case"jump":return e.index}}function A(e){switch(e.kind){case"setting":return e.setting.path;case"allow":return`${e.channelId}.allowFrom`;case"secret":return e.name;case"heading":return e.label}}function B(e){switch(e.kind){case"setting":return e.value===void 0||e.value===null?"(not set)":typeof e.value==="string"?e.value:JSON.stringify(e.value);case"allow":return e.handles.length===0?"(nobody)":e.handles.join(" ");case"secret":return e.present?"(set)":"(not set)";case"heading":return""}}function U(e){let t=B(e);return t.length<=V?`esc keeps ${t}`:"esc cancels"}var V=24;function Z(e){switch(e.kind){case"setting":return e.setting.means;case"allow":return"handles this channel accepts messages from, separated by spaces. Empty refuses everyone";case"secret":return e.why;case"heading":return e.label}}export{ge as ConfigEditor};
|
|
4
|
+
|
|
5
|
+
//# debugId=D0C08C3E6307488B64756E2164756E21
|
|
6
|
+
//# sourceMappingURL=ConfigEditor-7v5nebvy.js.map
|