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,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{t,ut,Pt,fe,ze,Be}from"./index-2cvtz0fy.js";import{hr}from"./index-bry9bzt3.js";import{Et,vo}from"./index-9f9pp2ef.js";import{l,m,d,c}from"./index-mgdgx22q.js";import{chmodSync as E,existsSync as _,readFileSync as b,statSync as R,writeFileSync as N}from"node:fs";import{dirname as j,join as F}from"node:path";function x(e){if(!(e===""||/^["']/.test(e)||/\s/.test(e)||e.includes("#")||e!==e.trim()))return e;return`"${e.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}"`}function w(e,n,o){let r=`${n}=${x(o)}`,i=e.split(`
|
|
3
|
+
`),s=new RegExp(`^\\s*(?:export\\s+)?${n}\\s*=`),a=i.findIndex((u)=>s.test(u));if(a!==-1){let u=i[a]??"",p=/^\s*export\s+/.exec(u)?.[0]??"";return{text:[...i.slice(0,a),`${p}${r}`,...i.slice(a+1)].join(`
|
|
4
|
+
`),replaced:!0}}let f=e.replace(/\n+$/,"");return{text:f===""?`${r}
|
|
5
|
+
`:`${f}
|
|
6
|
+
${r}
|
|
7
|
+
`,replaced:!1}}function T(e){return F(j(e),".env")}async function zn(e,n,o){let r=Pt(o),i=await ut({file:e,path:n.split("."),value:r});return{note:`${n} is now ${O(r)}`,reflowed:i.reflowed,before:i.before}}async function Bn(e,n,o){let r=b(e,"utf8"),i=fe(r,["channels"]);if(!Array.isArray(i))throw new t({code:"cli_config_no_channels",message:"This agent has no channels, so there is nobody to allow.",hint:"`config set <agent> channels '[{type: telegram, id: tg, tokenEnv: TELEGRAM_BOT_TOKEN, mode: longpoll}]'` declares one first."});let s=i.filter((g)=>typeof g==="object"&&g!==null&&!Array.isArray(g)),a=s.findIndex((g)=>String(g.id??"")===n);if(a===-1)throw new t({code:"cli_config_channel_unknown",message:`No channel with id "${n}".`,hint:`Declared: ${s.map((g)=>String(g.id??"")).join(", ")}.`,field:"channel"});let f=s[a],u=o.map((g)=>ur(g,String(f.type??""))),p=[...new Set(u)],y=Array.isArray(f.allowFrom)?f.allowFrom.map(String):[],A=await ut({file:e,path:["channels"],value:s.map((g,S)=>S===a?{...g,allowFrom:p}:g)});return{note:p.length===0?`${n} now allows nobody, which refuses every message`:`${n} now allows ${p.join(", ")}`,reflowed:A.reflowed,before:y}}function Kn(e,n,o){if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(n))throw new t({code:"cli_config_env_name_invalid",message:`"${n}" is not an environment variable name.`,hint:"Letters, digits and underscores, not starting with a digit — MODEL_API_KEY, TELEGRAM_BOT_TOKEN.",field:"name"});if(o==="")throw new t({code:"cli_config_env_empty",message:`An empty value for ${n} would not start the agent.`,hint:"A variable set to nothing fails the load exactly as a missing one does. Nothing was written."});let r=T(e),i=_(r)?b(r,"utf8"):"",s=w(i,n,o);N(r,s.text,{encoding:"utf8",mode:384});let a=(R(r).mode&63)!==0;if(a)E(r,384);return{note:`${n} ${s.replaced?"replaced":"written"} in ${r}${a?" (tightened to 0600)":""}`,reflowed:!1,before:void 0}}function ur(e,n){let o=e.trim();if(o==="")throw new t({code:"cli_config_handle_missing",message:"No handle given.",hint:"On Telegram that is the username, not the display name.",field:"handle"});if(n!=="telegram")return o;let r=hr(o);if(!r.ok)throw new t({code:"cli_config_handle_invalid",message:`"${o}" ${r.reason}`,hint:"A handle that cannot exist matches nobody, and the only symptom is the bot silently refusing every message from the person it was set up for.",field:"handle"});return r.value}function O(e){if(e==="")return"empty";if(typeof e==="string")return e;return JSON.stringify(e)}function kt(e){if(e===void 0||e===null)return"(not set)";if(typeof e==="string")return e===""?'""':e;if(typeof e==="boolean"||typeof e==="number")return String(e);return JSON.stringify(e)}function V(e){return e.split(/[.[]/)[0]??e}function io(e,n){let o=[`${n}`,""],r=new Map;for(let s of e){let a=V(s.setting.path);r.set(a,[...r.get(a)??[],s])}let i=!0;for(let[s,a]of r){o.push(m(s,i)),i=!1;for(let f of a){let u=f.setting.agentListed?"":" · yours only",p=f.setting.via===void 0?"":` · set with \`${f.setting.via}\``,y=f.setting.confirm===void 0?"":" · asks first";o.push(l([{label:f.setting.path,value:kt(f.value)}]),c(`${f.setting.means}${u}${p}${y}`,4))}}return o.push("","A change takes effect the next time the agent starts. `yours only` marks a field the agent is","refused: what it may do is its to ask for, where it writes and who may reach it are yours."),o.join(`
|
|
8
|
+
`)}function ao(e,n){return[l([{label:e.path,value:kt(n)}]),c(e.means,4),...e.toAgent===void 0?[]:[c(`to the agent: ${e.toAgent}`,4)]].join(`
|
|
9
|
+
`)}function lo(e,n){if(e.confirm===void 0)return;if(e.path==="tools.untrusted.onMutate"&&String(n).toLowerCase()!=="allow")return;return e.confirm}function co(e){let n=[l([{label:"set",value:`${e.path} = ${kt(e.after)}`},{label:"was",value:e.before===void 0?"(not set)":kt(e.before)},{label:"file",value:e.file}])];if(e.reflowed)n.push("",d("the block could not be edited in place, so the file was re-serialised — it is valid, and comments may have moved"));if(e.running!==void 0)n.push("",d(`this agent is running (pid ${e.running.pid}, ${e.running.mode}) and holds its settings for its lifetime — the change applies after ${e.restartHint}`));for(let o of e.pending)n.push(d(`${o.name} is not set — ${o.why}`)),n.push(d(`fill it in with \`config env <agent> ${o.name}\``));return n.join(`
|
|
10
|
+
`)}function uo(){return Be.filter((e)=>e.via===void 0&&!/[[<]/.test(e.path)).map((e)=>e.path)}function St(e){if(typeof e!=="object"||e===null)return[];let n=e,o=[],r=(f,u)=>{if(typeof f==="string"&&f!=="")o.push({name:f,why:u})},i=h(n.model);for(let f of["main","selector","compactor"]){let u=h(i?.[f]);r(u?.apiKeyEnv,"the manifest will not load until it is set")}if(Array.isArray(n.channels))for(let f of n.channels){let u=h(f);if(u===void 0||u.enabled===!1)continue;r(u.tokenEnv,`the ${String(u.id??u.type??"channel")} channel is read at boot, so the agent will not start until it is set`)}let s=h(n.server);if(s?.enabled===!0)r(s.tokenEnv,"the HTTP API would accept unauthenticated requests. This does not stop the agent starting");let a=h(h(n.tools)?.providers);for(let[f,u]of Object.entries(a??{}))r(h(u)?.apiKeyEnv,`the ${f} provider's tools will not work until it is set`);return o}function h(e){if(typeof e!=="object"||e===null||Array.isArray(e))return;return e}function Hn(e,n){return e.filter((o)=>n[o.name]===void 0||n[o.name]==="")}function k(e,n){let o=[],r=new Map;for(let i of e){if(i.setting.via!==void 0||/[[<]/.test(i.setting.path))continue;let s=i.setting.path.split(".")[0]??i.setting.path;r.set(s,[...r.get(s)??[],i])}for(let[i,s]of r){o.push({kind:"heading",label:i});for(let a of s)o.push({kind:"setting",setting:a.setting,value:a.value})}if(n.channels.length>0){o.push({kind:"heading",label:"who may reach it"});for(let i of n.channels)o.push({kind:"allow",channelId:i.id,channelType:i.type,handles:i.allowFrom})}if(n.secrets.length>0){o.push({kind:"heading",label:"secrets — written to the .env, never shown"});for(let i of n.secrets)o.push({kind:"secret",name:i.name,why:i.why,present:n.present(i.name)})}return o}import{readFileSync as v}from"node:fs";function Wn(e){let n=v(e,"utf8");return Be.map((o)=>{if(o.path==="channels[].allowFrom"){let r=fe(n,["channels"]);if(!Array.isArray(r))return{setting:o,value:void 0};let i={};for(let s of r){if(typeof s!=="object"||s===null)continue;let a=s;if(typeof a.id!=="string")continue;i[a.id]=a.allowFrom??[]}return{setting:o,value:Object.keys(i).length===0?void 0:i}}if(o.path==="tools.providers.<id>.writeRoots"){let r=fe(n,["tools","providers"]);if(typeof r!=="object"||r===null||Array.isArray(r))return{setting:o,value:void 0};let i={};for(let[s,a]of Object.entries(r)){if(typeof a!=="object"||a===null)continue;let f=a.writeRoots;if(f!==void 0)i[s]=f}return{setting:o,value:Object.keys(i).length===0?void 0:i}}return{setting:o,value:fe(n,o.path.split("."))}})}function ot(e){let n=v(e,"utf8"),o=ze(n),r=Et(e),i=fe(n,["channels"]);return k(Wn(e),{channels:(Array.isArray(i)?i:[]).filter((s)=>typeof s==="object"&&s!==null&&!Array.isArray(s)).map((s)=>({id:String(s.id??""),type:String(s.type??""),allowFrom:Array.isArray(s.allowFrom)?s.allowFrom.map(String):[]})).filter((s)=>s.id!==""),secrets:St(o),present:(s)=>vo(r,s)})}async function Yt(e,n,o){switch(n.kind){case"setting":{if(o.trim()==="")throw new t({code:"cli_config_value_missing",message:`No value given for ${n.setting.path}.`,hint:'A bare word, a number, a list as ["a", "b"], or a map as {k: v}.',field:"value"});return(await zn(e,n.setting.path,o)).note}case"allow":{let r=o.trim()===""?[]:o.trim().split(/\s+/);return(await Bn(e,n.channelId,r)).note}case"secret":return Kn(e,n.name,o).note;case"heading":return""}}
|
|
11
|
+
export{zn,Bn,Kn,ur,kt,io,ao,lo,co,uo,St,Hn,Wn,ot,Yt};
|
|
12
|
+
|
|
13
|
+
//# debugId=8D1CF32587D9259F64756E2164756E21
|
|
14
|
+
//# sourceMappingURL=index-gbnc99j8.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lib/config-apply.ts", "../src/lib/dotenv-edit.ts", "../src/lib/config-view.ts", "../src/lib/config-rows.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * The three writes `config` performs, separated from how any surface prints them.\n *\n * The plain actions and the editor both go through here, which is the same argument the phase made one\n * level down: `editManifest` is the only thing that writes `agent.yaml` because three writers meant the\n * guarantee depended on which caller you were. Two *callers* of that writer would have the same problem\n * one step up — the editor validating a handle differently from `config allow`, or writing a secret\n * without tightening the file's mode.\n *\n * Each function does the effect and returns a sentence. Refusals throw `HarnessError`, so a caller that\n * prints to a terminal and a caller that shows a line in a frame both get the same words.\n */\n\nimport { chmodSync, existsSync, readFileSync, statSync, writeFileSync } from \"node:fs\"\nimport { dirname, join } from \"node:path\"\nimport { editManifest, HarnessError, manifestValueAt, parseSettingValue } from \"@dispach/core\"\nimport { upsertEnv } from \"#lib/dotenv-edit\"\nimport { telegramHandle } from \"#lib/init-flow\"\n\nexport interface Applied {\n /** One line saying what happened, for whichever surface asked. */\n readonly note: string\n /** The source editor could not place the path, so the document was re-serialised. */\n readonly reflowed: boolean\n /** What was there before, so a caller can offer the undo. */\n readonly before: unknown\n}\n\n/** The `.env` beside a manifest. */\nexport function envPathOf(manifestPath: string): string {\n return join(dirname(manifestPath), \".env\")\n}\n\nexport async function applySet(manifestPath: string, path: string, raw: string): Promise<Applied> {\n const value = parseSettingValue(raw)\n const result = await editManifest({ file: manifestPath, path: path.split(\".\"), value })\n return {\n note: `${path} is now ${describe(value)}`,\n reflowed: result.reflowed,\n before: result.before,\n }\n}\n\n/**\n * Add, remove or replace a channel's inbound allowlist.\n *\n * `handles` is the whole list, because the whole list is what gets written: the field lives inside a\n * sequence entry and the source editor matches `key:` at an indent, so one entry's key is not\n * addressable. Every handle is checked against the service that issues it first — an impossible one\n * matches nobody, and the only symptom is a bot that is connected, healthy and silently refusing the\n * person it was set up for.\n */\nexport async function applyAllow(\n manifestPath: string,\n channelId: string,\n handles: readonly string[],\n): Promise<Applied> {\n const source = readFileSync(manifestPath, \"utf8\")\n const channels = manifestValueAt(source, [\"channels\"])\n if (!Array.isArray(channels)) {\n throw new HarnessError({\n code: \"cli_config_no_channels\",\n message: \"This agent has no channels, so there is nobody to allow.\",\n hint: \"`config set <agent> channels '[{type: telegram, id: tg, tokenEnv: TELEGRAM_BOT_TOKEN, mode: longpoll}]'` declares one first.\",\n })\n }\n\n const entries = channels.filter(\n (entry): entry is Record<string, unknown> =>\n typeof entry === \"object\" && entry !== null && !Array.isArray(entry),\n )\n const at = entries.findIndex((entry) => String(entry.id ?? \"\") === channelId)\n if (at === -1) {\n throw new HarnessError({\n code: \"cli_config_channel_unknown\",\n message: `No channel with id \"${channelId}\".`,\n hint: `Declared: ${entries.map((entry) => String(entry.id ?? \"\")).join(\", \")}.`,\n field: \"channel\",\n })\n }\n\n const target = entries[at] as Record<string, unknown>\n const checked = handles.map((handle) => checkedHandle(handle, String(target.type ?? \"\")))\n const unique = [...new Set(checked)]\n const before = Array.isArray(target.allowFrom) ? target.allowFrom.map(String) : []\n\n const result = await editManifest({\n file: manifestPath,\n path: [\"channels\"],\n value: entries.map((entry, index) =>\n index === at ? { ...entry, allowFrom: unique } : entry,\n ),\n })\n return {\n note:\n unique.length === 0\n ? `${channelId} now allows nobody, which refuses every message`\n : `${channelId} now allows ${unique.join(\", \")}`,\n reflowed: result.reflowed,\n before,\n }\n}\n\n/**\n * Put a value in the `.env` beside the manifest, at 0600.\n *\n * Written 0600 whichever way the file arrived: under a service manager this is the *only* path\n * credentials take — launchd hands a job almost no environment and a plist carries none on purpose — so\n * tightening it is right even when this command did not create it. `writeFileSync`'s mode applies only\n * when it creates the file, which is why the check afterwards is not redundant.\n */\nexport function applySecret(manifestPath: string, name: string, value: string): Applied {\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) {\n throw new HarnessError({\n code: \"cli_config_env_name_invalid\",\n message: `\"${name}\" is not an environment variable name.`,\n hint: \"Letters, digits and underscores, not starting with a digit — MODEL_API_KEY, TELEGRAM_BOT_TOKEN.\",\n field: \"name\",\n })\n }\n if (value === \"\") {\n throw new HarnessError({\n code: \"cli_config_env_empty\",\n message: `An empty value for ${name} would not start the agent.`,\n hint: \"A variable set to nothing fails the load exactly as a missing one does. Nothing was written.\",\n })\n }\n\n const path = envPathOf(manifestPath)\n const before = existsSync(path) ? readFileSync(path, \"utf8\") : \"\"\n const upsert = upsertEnv(before, name, value)\n writeFileSync(path, upsert.text, { encoding: \"utf8\", mode: 0o600 })\n const loose = (statSync(path).mode & 0o077) !== 0\n if (loose) chmodSync(path, 0o600)\n\n return {\n note: `${name} ${upsert.replaced ? \"replaced\" : \"written\"} in ${path}${loose ? \" (tightened to 0600)\" : \"\"}`,\n reflowed: false,\n before: undefined,\n }\n}\n\n/**\n * A handle, validated against the service that issues it.\n *\n * Telegram's rule is shared with `init` rather than restated, because a check only one surface performs\n * is a check the two disagree about. An unknown channel type passes through: guessing at another\n * service's identifier format would refuse handles that are perfectly valid.\n */\nexport function checkedHandle(raw: string, type: string): string {\n const given = raw.trim()\n if (given === \"\") {\n throw new HarnessError({\n code: \"cli_config_handle_missing\",\n message: \"No handle given.\",\n hint: \"On Telegram that is the username, not the display name.\",\n field: \"handle\",\n })\n }\n if (type !== \"telegram\") return given\n const checked = telegramHandle(given)\n if (!checked.ok) {\n throw new HarnessError({\n code: \"cli_config_handle_invalid\",\n message: `\"${given}\" ${checked.reason}`,\n hint: \"A handle that cannot exist matches nobody, and the only symptom is the bot silently refusing every message from the person it was set up for.\",\n field: \"handle\",\n })\n }\n return checked.value\n}\n\n/** A value as a short phrase, for a one-line note. */\nfunction describe(value: unknown): string {\n if (value === \"\") return \"empty\"\n if (typeof value === \"string\") return value\n return JSON.stringify(value)\n}\n",
|
|
6
|
+
"/**\n * Setting one variable in a `.env` without disturbing the rest of it. Pure: text in, text out.\n *\n * The same argument as `yaml-edit.ts`, for the same file's neighbour. A generated `.env` carries\n * comments naming what each variable is for and where to get it, and rewriting the file from a parsed\n * map would drop every one of them — which matters more here than in the manifest, because this is the\n * file somebody opens six months later wondering which dashboard a key came from.\n *\n * Deliberately not a `.env` *parser*: reading one is `parseDotEnv` in core, and a second implementation\n * of that would be two things that have to agree about quoting. This only ever finds a line and\n * replaces it, so the two meet at exactly one place — how a value is quoted on the way out, which is\n * written to be read back by that parser and asserted against it in the tests.\n */\n\n/** Whether a value needs quoting to survive `parseDotEnv`, and the quoted form if so. */\nexport function renderEnvValue(value: string): string {\n // Unquoted values stop at ` #`, and a leading quote character would be eaten as an opening quote.\n // Everything else round-trips bare, which keeps a generated file readable.\n const needsQuotes =\n value === \"\" ||\n /^[\"']/.test(value) ||\n /\\s/.test(value) ||\n value.includes(\"#\") ||\n value !== value.trim()\n if (!needsQuotes) return value\n const escaped = value\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, \"\\\\n\")\n .replace(/\\r/g, \"\\\\r\")\n .replace(/\\t/g, \"\\\\t\")\n return `\"${escaped}\"`\n}\n\nexport interface EnvUpsert {\n readonly text: string\n /** True when the variable was already there and its line was replaced. */\n readonly replaced: boolean\n}\n\n/**\n * Set `name` to `value`, replacing an existing assignment in place or appending a new one.\n *\n * Replacing **in place** rather than appending is what stops the file growing a second, shadowing\n * assignment on every edit — `parseDotEnv` takes the last one, so an append-only writer would leave a\n * file whose earlier lines are lies. A commented-out assignment is left alone: it is documentation,\n * and uncommenting it would resurrect a value somebody deliberately disabled.\n */\nexport function upsertEnv(source: string, name: string, value: string): EnvUpsert {\n const assignment = `${name}=${renderEnvValue(value)}`\n const lines = source.split(\"\\n\")\n // `export FOO=` counts, because `parseDotEnv` reads it. A `#` first does not.\n const pattern = new RegExp(`^\\\\s*(?:export\\\\s+)?${name}\\\\s*=`)\n const at = lines.findIndex((line) => pattern.test(line))\n\n if (at !== -1) {\n const existing = lines[at] ?? \"\"\n // The `export ` prefix is preserved: it is there because something sources this file rather\n // than reading it, and dropping it would break that quietly.\n const prefix = /^\\s*export\\s+/.exec(existing)?.[0] ?? \"\"\n return {\n text: [...lines.slice(0, at), `${prefix}${assignment}`, ...lines.slice(at + 1)].join(\n \"\\n\",\n ),\n replaced: true,\n }\n }\n\n // Appended with exactly one trailing newline, whatever the file ended with. A `.env` that gains a\n // blank line on every edit is a file that looks edited by a machine, which it is, but it should not\n // look careless about it.\n const body = source.replace(/\\n+$/, \"\")\n return { text: body === \"\" ? `${assignment}\\n` : `${body}\\n${assignment}\\n`, replaced: false }\n}\n",
|
|
7
|
+
"/**\n * What `config` prints, and what a person has to confirm. Pure, so both are asserted as strings.\n *\n * The policy lives here rather than in the command for the same reason `remove-plan.ts` does: this\n * surface can disable the write gate and open a bind address to the network, and \"which edits need a\n * confirmation\" is exactly the thing that must be checkable without performing one.\n *\n * ## Why the person's policy is not the agent's\n *\n * Decision 11.29: *enabling a capability answers \"what may I do\"; a write root, an allowlist and a\n * bind address answer \"who and where\", and those are the person's by definition.* The agent's floor\n * exists because an agent that could widen its own inbound gate could be **talked into** widening it\n * by the very message it is reading — `config_set` sits in `policy.allow` on a real manifest, so the\n * write gate would not stop that. A person typing at a terminal is not that threat, and refusing them\n * is what left the fields reserved for them with the worst ergonomics in the system.\n *\n * So nothing here is floored. Two edits are confirmed, both from decision 4.50, and only those two:\n * a confirmation that fires on `limits.maxSteps` is one nobody reads by the time it fires on the\n * write gate.\n */\n\nimport { SETTINGS, type Setting } from \"@dispach/core\"\nimport type { EditorRow } from \"#lib/config-editor\"\nimport { bullet, indent, keyValue, section } from \"#lib/render\"\n\n/** A setting with whatever the manifest currently has in it. */\nexport interface SettingValue {\n readonly setting: Setting\n /** Plain JS, or `undefined` when the field is absent from the file. */\n readonly value: unknown\n}\n\n/**\n * How a value appears in a listing.\n *\n * Lists and maps as JSON rather than flattened YAML, which is the lesson from `config_read`: collapsing\n * a block's newlines rendered `[type: telegram id: tg tokenEnv: …]`, one run-on string where the reader\n * needed fields. A sequence of maps went through `String(entry)` and wrote `[object Object]` — the same\n * defect, three times, in three renderers.\n */\nexport function showValue(value: unknown): string {\n if (value === undefined || value === null) return \"(not set)\"\n if (typeof value === \"string\") return value === \"\" ? '\"\"' : value\n if (typeof value === \"boolean\" || typeof value === \"number\") return String(value)\n return JSON.stringify(value)\n}\n\n/** The top-level key a path belongs under, for grouping. */\nfunction group(path: string): string {\n return path.split(/[.[]/)[0] ?? path\n}\n\n/**\n * The whole catalogue, grouped by the block it lives in, each row carrying who owns it.\n *\n * Grouped by manifest block rather than by owner, because the question a reader arrives with is \"what\n * can I change about tools\" far more often than \"what is mine versus the agent's\" — and the ownership\n * still shows on every row that is not the default.\n */\nexport function renderSettings(rows: readonly SettingValue[], file: string): string {\n const out: string[] = [`${file}`, \"\"]\n\n // Collected by block rather than emitted in catalogue order. Printing a heading whenever the block\n // *changes* looks equivalent and is not: the person-only rows sit at the end of the catalogue, so a\n // real listing came out with `server` and `tools` as two sections each, reading as though there\n // were two of them. Grouping here rather than reordering the catalogue keeps the render correct\n // whatever order the rows arrive in, which is the property worth having.\n const blocks = new Map<string, SettingValue[]>()\n for (const row of rows) {\n const block = group(row.setting.path)\n blocks.set(block, [...(blocks.get(block) ?? []), row])\n }\n\n let first = true\n for (const [block, members] of blocks) {\n out.push(section(block, first))\n first = false\n for (const row of members) {\n const owner = row.setting.agentListed ? \"\" : \" · yours only\"\n const via = row.setting.via === undefined ? \"\" : ` · set with \\`${row.setting.via}\\``\n const guard = row.setting.confirm === undefined ? \"\" : \" · asks first\"\n out.push(\n keyValue([{ label: row.setting.path, value: showValue(row.value) }]),\n indent(`${row.setting.means}${owner}${via}${guard}`, 4),\n )\n }\n }\n out.push(\n \"\",\n \"A change takes effect the next time the agent starts. `yours only` marks a field the agent is\",\n \"refused: what it may do is its to ask for, where it writes and who may reach it are yours.\",\n )\n return out.join(\"\\n\")\n}\n\n/** One field, for `config get`. */\nexport function renderOne(setting: Setting, value: unknown): string {\n return [\n keyValue([{ label: setting.path, value: showValue(value) }]),\n indent(setting.means, 4),\n ...(setting.toAgent === undefined ? [] : [indent(`to the agent: ${setting.toAgent}`, 4)]),\n ].join(\"\\n\")\n}\n\n/**\n * What a confirmation says before a guard-weakening edit, or `undefined` when none is needed.\n *\n * The value matters, not only the path: `onMutate: confirm` tightens the gate and `allow` removes it,\n * and asking about both would teach people to agree to the one that matters. Same asymmetry the agent's\n * floor has, where `confirm` is settable and `allow` is refused.\n */\nexport function confirmationFor(setting: Setting, value: unknown): string | undefined {\n if (setting.confirm === undefined) return undefined\n if (setting.path === \"tools.untrusted.onMutate\" && String(value).toLowerCase() !== \"allow\") {\n return undefined\n }\n return setting.confirm\n}\n\n/**\n * The report after a successful set.\n *\n * `reflowed` is surfaced rather than swallowed: the file is correct and its comments have moved, which\n * is a surprise better heard from the command than found later in a diff.\n */\nexport function renderChange(input: {\n readonly path: string\n readonly before: unknown\n readonly after: unknown\n readonly file: string\n readonly reflowed: boolean\n /** A live process holding this agent, if there is one. */\n readonly running?: { readonly pid: number; readonly mode: string }\n /**\n * Env variables this edit has *newly* made load-bearing and that are not set.\n *\n * Newly, not \"all of them\": a note about tokens printed on every `limits.maxSteps` change is a note\n * nobody reads by the time it matters — the same reasoning that makes `config_set` report a pending\n * secret only for a write that could have introduced one. What is already missing is `config list`'s\n * to report, because that is the command whose job is the overview.\n */\n readonly pending: readonly EnvNeed[]\n readonly restartHint: string\n}): string {\n const out: string[] = [\n keyValue([\n { label: \"set\", value: `${input.path} = ${showValue(input.after)}` },\n {\n label: \"was\",\n value: input.before === undefined ? \"(not set)\" : showValue(input.before),\n },\n { label: \"file\", value: input.file },\n ]),\n ]\n if (input.reflowed) {\n out.push(\n \"\",\n bullet(\n \"the block could not be edited in place, so the file was re-serialised — it is valid, and comments may have moved\",\n ),\n )\n }\n if (input.running !== undefined) {\n // Never a refusal. Fixing a misconfiguration while it is running and broken is the main use of\n // this command, so the state it would refuse in is the state somebody is trying to get out of.\n out.push(\n \"\",\n bullet(\n `this agent is running (pid ${input.running.pid}, ${input.running.mode}) and holds its settings for its lifetime — the change applies after ${input.restartHint}`,\n ),\n )\n }\n for (const need of input.pending) {\n out.push(bullet(`${need.name} is not set — ${need.why}`))\n out.push(bullet(`fill it in with \\`config env <agent> ${need.name}\\``))\n }\n return out.join(\"\\n\")\n}\n\n/** Every setting with a real dotted path, in catalogue order. `config set`'s accepted list. */\nexport function settablePaths(): readonly string[] {\n return SETTINGS.filter((entry) => entry.via === undefined && !/[[<]/.test(entry.path)).map(\n (entry) => entry.path,\n )\n}\n\n/** An env variable this manifest depends on, and what actually happens without it. */\nexport interface EnvNeed {\n readonly name: string\n /** The real consequence, which differs per source and is not interchangeable. */\n readonly why: string\n}\n\n/**\n * The env variables a manifest depends on, each with the consequence of it being unset.\n *\n * One message for all of them was wrong, and a live run showed it: the API token variable reported as\n * \"read at boot — the agent will refuse to start until it is filled in\", printed for an agent with\n * `server.enabled: false` that starts perfectly well. Three sources, three different outcomes:\n *\n * - `model.<role>.apiKeyEnv` — a **load failure**. `validateApiKeyEnv` refuses the manifest outright.\n * - an enabled channel's `tokenEnv` — a **boot failure**, because the factory reads it inside\n * `Runtime.create`. A channel with `enabled: false` is never constructed, so it needs nothing.\n * - `server.tokenEnv` — **no failure at all**. The API serves unauthenticated and the banner says so,\n * which is worth telling somebody and is not the same sentence as \"will not start\".\n * - a provider's `apiKeyEnv` — that provider's tools do not work; the agent runs.\n *\n * A disabled block contributes nothing. Claiming a dependency that does not exist is worse than\n * claiming none, because it is the kind of warning that teaches people to ignore this line.\n */\nexport function envNeeds(document: unknown): readonly EnvNeed[] {\n if (typeof document !== \"object\" || document === null) return []\n const doc = document as Record<string, unknown>\n const needs: EnvNeed[] = []\n const add = (name: unknown, why: string) => {\n if (typeof name === \"string\" && name !== \"\") needs.push({ name, why })\n }\n\n const model = asRecord(doc.model)\n for (const role of [\"main\", \"selector\", \"compactor\"]) {\n const config = asRecord(model?.[role])\n add(config?.apiKeyEnv, \"the manifest will not load until it is set\")\n }\n\n if (Array.isArray(doc.channels)) {\n for (const entry of doc.channels) {\n const channel = asRecord(entry)\n if (channel === undefined || channel.enabled === false) continue\n add(\n channel.tokenEnv,\n `the ${String(channel.id ?? channel.type ?? \"channel\")} channel is read at boot, so the agent will not start until it is set`,\n )\n }\n }\n\n const server = asRecord(doc.server)\n if (server?.enabled === true) {\n add(\n server.tokenEnv,\n \"the HTTP API would accept unauthenticated requests. This does not stop the agent starting\",\n )\n }\n\n const providers = asRecord(asRecord(doc.tools)?.providers)\n for (const [id, config] of Object.entries(providers ?? {})) {\n add(asRecord(config)?.apiKeyEnv, `the ${id} provider's tools will not work until it is set`)\n }\n\n return needs\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) return undefined\n return value as Record<string, unknown>\n}\n\n/** Those of `needs` the environment does not supply. */\nexport function unmet(\n needs: readonly EnvNeed[],\n env: Readonly<Record<string, string | undefined>>,\n): readonly EnvNeed[] {\n return needs.filter((need) => env[need.name] === undefined || env[need.name] === \"\")\n}\n\n/**\n * The editor's rows for a manifest: every setting, one `allowFrom` per channel, and every secret.\n *\n * Here rather than in the component because it is the whole shape of the surface and it is pure — what\n * appears, in what order, under which heading — and because both hosts build it the same way.\n *\n * The two catalogue rows that are not dotted paths are *replaced* by their expansions rather than shown\n * beside them: `channels[].allowFrom` becomes one row per declared channel, and\n * `tools.providers.<id>.writeRoots` is left as a listing-only row, because writing it means naming a\n * provider and the editor has no way to ask which. A row nobody can act on would be the dead end this\n * surface exists to remove, so it is not offered at all — `config list` still shows it.\n */\nexport function editorRows(\n settings: readonly SettingValue[],\n input: {\n readonly channels: readonly {\n readonly id: string\n readonly type: string\n readonly allowFrom: readonly string[]\n }[]\n readonly secrets: readonly EnvNeed[]\n readonly present: (name: string) => boolean\n },\n): readonly EditorRow[] {\n const out: EditorRow[] = []\n\n // Collected by block, not emitted when the block *changes* — the same distinction `renderSettings`\n // records above, which this renderer had never been given. The two are not equivalent: the\n // person-only rows sit at the end of the catalogue, so `server.host` and `server.tokenEnv` were\n // already a second `server` section here, and inserting any row between `server.port` and them\n // made it visible. `schedules` was that row. Grouping keeps the render correct whatever order the\n // catalogue arrives in, which is the property worth having and the reason not to fix it by\n // reordering the table.\n const blocks = new Map<string, SettingValue[]>()\n for (const row of settings) {\n if (row.setting.via !== undefined || /[[<]/.test(row.setting.path)) continue\n const key = row.setting.path.split(\".\")[0] ?? row.setting.path\n blocks.set(key, [...(blocks.get(key) ?? []), row])\n }\n for (const [label, members] of blocks) {\n out.push({ kind: \"heading\", label })\n for (const row of members) {\n out.push({ kind: \"setting\", setting: row.setting, value: row.value })\n }\n }\n\n if (input.channels.length > 0) {\n out.push({ kind: \"heading\", label: \"who may reach it\" })\n for (const channel of input.channels) {\n out.push({\n kind: \"allow\",\n channelId: channel.id,\n channelType: channel.type,\n handles: channel.allowFrom,\n })\n }\n }\n\n if (input.secrets.length > 0) {\n out.push({ kind: \"heading\", label: \"secrets — written to the .env, never shown\" })\n for (const need of input.secrets) {\n out.push({\n kind: \"secret\",\n name: need.name,\n why: need.why,\n present: input.present(need.name),\n })\n }\n }\n\n return out\n}\n",
|
|
8
|
+
"/**\n * What the config editor shows, and what one confirmed row does. Reads files; no Ink.\n *\n * Its own module because **both hosts import it statically** — `config.ts` for the standalone editor and\n * `App.tsx` for the pane — while `index.ts` imports `config.ts` *dynamically* to keep Ink off the\n * startup path. A module reached both ways makes `bun build --splitting` emit its exports twice and the\n * binary refuses to parse, and `bun test` sails straight through it because tests import source. So the\n * shared half lives where nothing has to be lazy about it.\n */\n\nimport { readFileSync } from \"node:fs\"\nimport { HarnessError, manifestDocument, manifestValueAt, SETTINGS } from \"@dispach/core\"\nimport { applyAllow, applySecret, applySet } from \"#lib/config-apply\"\nimport type { EditorRow } from \"#lib/config-editor\"\nimport { agentEnv, isSet } from \"#lib/config-env\"\nimport { editorRows, envNeeds, type SettingValue } from \"#lib/config-view\"\n\n/**\n * Every setting with whatever the file currently holds.\n *\n * Two rows do not have a readable dotted path — `allowFrom` lives inside a list entry and `writeRoots`\n * inside a provider — so they are gathered by walking the block instead. Shown rather than omitted: a\n * field missing from a listing reads as \"no such concept\", which is the same reasoning that puts a\n * `none` row in slot 2 instead of leaving the line out.\n */\nexport function currentValues(manifestPath: string): readonly SettingValue[] {\n const source = readFileSync(manifestPath, \"utf8\")\n return SETTINGS.map((setting) => {\n if (setting.path === \"channels[].allowFrom\") {\n const channels = manifestValueAt(source, [\"channels\"])\n if (!Array.isArray(channels)) return { setting, value: undefined }\n const byId: Record<string, unknown> = {}\n for (const entry of channels) {\n if (typeof entry !== \"object\" || entry === null) continue\n const row = entry as { id?: unknown; allowFrom?: unknown }\n if (typeof row.id !== \"string\") continue\n byId[row.id] = row.allowFrom ?? []\n }\n return { setting, value: Object.keys(byId).length === 0 ? undefined : byId }\n }\n if (setting.path === \"tools.providers.<id>.writeRoots\") {\n const providers = manifestValueAt(source, [\"tools\", \"providers\"])\n if (typeof providers !== \"object\" || providers === null || Array.isArray(providers)) {\n return { setting, value: undefined }\n }\n const roots: Record<string, unknown> = {}\n for (const [id, config] of Object.entries(providers as Record<string, unknown>)) {\n if (typeof config !== \"object\" || config === null) continue\n const found = (config as { writeRoots?: unknown }).writeRoots\n if (found !== undefined) roots[id] = found\n }\n return { setting, value: Object.keys(roots).length === 0 ? undefined : roots }\n }\n return { setting, value: manifestValueAt(source, setting.path.split(\".\")) }\n })\n}\n\n/**\n * The rows the editor shows, read fresh from the manifest and its `.env`.\n *\n * Exported because both hosts build them: this command mounts the editor standalone, and the chat opens\n * it as a pane. Two builders would drift on the first row either one grew.\n */\nexport function editorRowsFor(manifestPath: string): readonly EditorRow[] {\n const source = readFileSync(manifestPath, \"utf8\")\n const document = manifestDocument(source)\n const env = agentEnv(manifestPath)\n const channels = manifestValueAt(source, [\"channels\"])\n\n return editorRows(currentValues(manifestPath), {\n channels: (Array.isArray(channels) ? channels : [])\n .filter(\n (entry): entry is Record<string, unknown> =>\n typeof entry === \"object\" && entry !== null && !Array.isArray(entry),\n )\n .map((entry) => ({\n id: String(entry.id ?? \"\"),\n type: String(entry.type ?? \"\"),\n allowFrom: Array.isArray(entry.allowFrom) ? entry.allowFrom.map(String) : [],\n }))\n .filter((entry) => entry.id !== \"\"),\n secrets: envNeeds(document),\n // The agent's layered environment, not this process's — `ambientEnv` alone never adds the file\n // beside the manifest, which made a row read `(not set)` right after somebody set it.\n present: (name: string) => isSet(env, name),\n })\n}\n\n/**\n * Perform one row's edit. The editor's only asynchronous part, and the plain commands' path too.\n *\n * A blank buffer means different things per row and each is the useful reading: no handles is \"allow\n * nobody\", which is a real thing to want; an empty *setting* would be a value nobody typed on purpose;\n * and an empty secret is refused by `applySecret`, because a variable set to nothing fails the load\n * exactly as a missing one does.\n */\nexport async function applyEditorRow(\n manifestPath: string,\n row: EditorRow,\n raw: string,\n): Promise<string> {\n switch (row.kind) {\n case \"setting\": {\n if (raw.trim() === \"\") {\n throw new HarnessError({\n code: \"cli_config_value_missing\",\n message: `No value given for ${row.setting.path}.`,\n hint: 'A bare word, a number, a list as [\"a\", \"b\"], or a map as {k: v}.',\n field: \"value\",\n })\n }\n return (await applySet(manifestPath, row.setting.path, raw)).note\n }\n case \"allow\": {\n const handles = raw.trim() === \"\" ? [] : raw.trim().split(/\\s+/)\n return (await applyAllow(manifestPath, row.channelId, handles)).note\n }\n case \"secret\":\n return applySecret(manifestPath, row.name, raw).note\n case \"heading\":\n return \"\"\n }\n}\n"
|
|
9
|
+
],
|
|
10
|
+
"mappings": ";sKAaA,oBAAS,gBAAW,kBAAY,cAAc,mBAAU,gBACxD,kBAAS,UAAS,kBCCX,SAAS,CAAc,CAAC,EAAuB,CASlD,GAAI,EALA,IAAU,IACV,QAAQ,KAAK,CAAK,GAClB,KAAK,KAAK,CAAK,GACf,EAAM,SAAS,GAAG,GAClB,IAAU,EAAM,KAAK,GACP,OAAO,EAOzB,MAAO,IANS,EACX,QAAQ,MAAO,MAAM,EACrB,QAAQ,KAAM,MAAK,EACnB,QAAQ,MAAO,KAAK,EACpB,QAAQ,MAAO,KAAK,EACpB,QAAQ,MAAO,KAAK,KAkBtB,SAAS,CAAS,CAAC,EAAgB,EAAc,EAA0B,CAC9E,IAAM,EAAa,GAAG,KAAQ,EAAe,CAAK,IAC5C,EAAQ,EAAO,MAAM;AAAA,CAAI,EAEzB,EAAU,IAAI,OAAO,uBAAuB,QAAW,EACvD,EAAK,EAAM,UAAU,CAAC,IAAS,EAAQ,KAAK,CAAI,CAAC,EAEvD,GAAI,IAAO,GAAI,CACX,IAAM,EAAW,EAAM,IAAO,GAGxB,EAAS,gBAAgB,KAAK,CAAQ,IAAI,IAAM,GACtD,MAAO,CACH,KAAM,CAAC,GAAG,EAAM,MAAM,EAAG,CAAE,EAAG,GAAG,IAAS,IAAc,GAAG,EAAM,MAAM,EAAK,CAAC,CAAC,EAAE,KAC5E;AAAA,CACJ,EACA,SAAU,EACd,EAMJ,IAAM,EAAO,EAAO,QAAQ,OAAQ,EAAE,EACtC,MAAO,CAAE,KAAM,IAAS,GAAK,GAAG;AAAA,EAAiB,G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EAAI,EAAM,UAAU,IAAI,MAAM,EAAI,CAAC,CAC/E,EAAE,EACD,OAAO,CAAC,IAAU,EAAM,KAAO,EAAE,EACtC,QAAS,GAAS,CAAQ,EAG1B,QAAS,CAAC,IAAiB,GAAM,EAAK,CAAI,CAC9C,CAAC,EAWL,eAAsB,EAAc,CAChC,EACA,EACA,EACe,CACf,OAAQ,EAAI,UACH,UAAW,CACZ,GAAI,EAAI,KAAK,IAAM,GACf,MAAM,IAAI,EAAa,CACnB,KAAM,2BACN,QAAS,sBAAsB,EAAI,QAAQ,QAC3C,KAAM,mEACN,MAAO,OACX,CAAC,EAEL,OAAQ,MAAM,GAAS,EAAc,EAAI,QAAQ,KAAM,CAAG,GAAG,IACjE,KACK,QAAS,CACV,IAAM,EAAU,EAAI,KAAK,IAAM,GAAK,CAAC,EAAI,EAAI,KAAK,EAAE,MAAM,KAAK,EAC/D,OAAQ,MAAM,GAAW,EAAc,EAAI,UAAW,CAAO,GAAG,IACpE,KACK,SACD,OAAO,GAAY,EAAc,EAAI,KAAM,CAAG,EAAE,SAC/C,UACD,MAAO",
|
|
11
|
+
"debugId": "8D1CF32587D9259F64756E2164756E21",
|
|
12
|
+
"names": []
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{pn,Co}from"./index-qc2vrq9z.js";import{o,R}from"./index-jk0def33.js";import{nr,gt}from"./index-6z0yr17z.js";var _=1;function fn(t,l){let u=Math.max(1,l-_),r=t.value.split(`
|
|
3
|
+
`),i=nr(t),d=[],m=0,s=0;for(let[f,n]of r.entries()){let h=pn(n,u),b=f===i.line?Co(n,i.column):-1,c=-1;if(b>=0){c=h.length-1;for(let[p,e]of h.entries())if(b<=e.to){c=p;break}}for(let[p,e]of h.entries()){if(p===c)m=d.length;d.push({start:s+e.from,end:s+e.to,lead:e.lead,text:e.text,caret:p===c?e.lead+Math.max(0,Math.min(b-e.from,e.to-e.from)):void 0})}s+=[...n].length+1}return{rows:d,caretRow:m}}function v(t,l){let u=[...t.text],r=[];for(let[i,d]of u.entries()){let m=i<t.lead?-1:t.start+(i-t.lead),s=l!==void 0&&m>=l.start&&m<l.end,f=t.caret===i,n=r.at(-1);if(n!==void 0&&!f&&!n.caret&&n.selected===s){r[r.length-1]={...n,text:n.text+d};continue}r.push({text:d,selected:s,caret:f})}if(t.caret!==void 0&&t.caret>=u.length)r.push({text:" ",selected:!1,caret:!0});return r}import{Box as j,Text as a}from"ink";import{jsx as y,jsxs as w}from"react/jsx-runtime";function hn({editor:t,placeholder:l,secret:u,gutter:r="",maxRows:i,columns:d}){let m=[...r].length,s=" ".repeat(m);if(t.value===""&&l!==void 0&&l!==""){let x=[...l];return w(a,{dimColor:!0,wrap:"truncate",children:[y(a,{color:o.accent,children:r}),y(a,{inverse:!0,children:x[0]??" "}),x.slice(1).join("")]})}let f=gt(t),{rows:n,caretRow:h}=fn(t,Math.max(1,(d??Number.MAX_SAFE_INTEGER)-m)),b=i??n.length,{from:c,to:p}=R(n.length,h,Math.max(1,b)),e=c,T=n.length-p;return w(j,{flexDirection:"column",children:[e>0?w(a,{dimColor:!0,wrap:"truncate",children:[s,"… ",e," line",e===1?"":"s"," above"]}):null,n.slice(c,p).map((x,M)=>{let C=c+M,A=u===!0?[...x.text].map(()=>"•"):[...x.text],L=C===c&&e===0?r:s;if(x.caret===void 0&&f===void 0)return w(a,{wrap:"truncate",children:[y(a,{color:o.accent,children:L}),A.join("")]},`row-${C}`);let B=v(x,f),k=0;return w(a,{wrap:"truncate",children:[y(a,{color:o.accent,children:L}),B.map((g)=>{let E=`run-${C}-${k}`;k+=[...g.text].length;let S=u===!0?[...g.text].map(()=>"•").join(""):g.text;if(g.caret)return y(a,{inverse:!0,children:S},E);if(g.selected)return y(a,{backgroundColor:o.selection,children:S},E);return y(a,{children:S},E)})]},`row-${C}`)}),T>0?w(a,{dimColor:!0,wrap:"truncate",children:[s,"… ",T," line",T===1?"":"s"," below"]}):null]})}
|
|
4
|
+
export{fn,hn};
|
|
5
|
+
|
|
6
|
+
//# debugId=B06B4945C65FD3B864756E2164756E21
|
|
7
|
+
//# sourceMappingURL=index-h2yds678.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lib/composer.ts", "../src/components/LineCursor.tsx"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * The composer's visual rows and where the caret sits on them. Pure, so the layout is arithmetic.\n *\n * ## Why the input box needs its own wrapping at all\n *\n * It rendered each logical line with `wrap=\"truncate\"` and no wrapping of its own, which is half of the\n * rule `lib/wrap.ts` states and the half that does not work. Ink truncates to the width Yoga measured,\n * and a `<Box>` with no explicit width takes its *content* width — so a long message made the box wider\n * than the terminal, and what happened next was the terminal's decision rather than ours. Measured at 100\n * columns: VS Code cut the line at the border and took the caret with it, so you could not see what you\n * were typing; Warp wrapped the over-wide row and the tail landed on top of the right-hand border. One\n * cause, two symptoms, and neither reproducible in the other terminal.\n *\n * So the composer wraps its own text, exactly as the transcript and the live pane do, and every row is\n * drawn `wrap=\"truncate\"` as a backstop rather than as the layout.\n *\n * ## One column is reserved, deliberately\n *\n * The caret is drawn as an inverse cell, so it needs a cell — including when it sits at the end of a line\n * that exactly fills the row. Wrapping to `columns - 1` buys that cell once, for every row, with no\n * special case; the alternative is an extra visual row that appears and disappears as you type past the\n * edge, which moves the whole frame on a surface that has no room to move.\n *\n * ## One derivation, two callers\n *\n * `LineCursor` draws these rows and `chat-frame.promptRows` counts them. That is the pairing the repo has\n * been bitten by before — a component that grows a row without the frame arithmetic knowing is a frame\n * taller than the terminal, which on the alternate buffer is corruption rather than crowding. Here the\n * count is `layout.rows.length` plus the notices, by construction.\n */\n\nimport { lineInfo } from \"#editor\"\nimport type { EditorState } from \"#lib/types\"\nimport { expandColumn, wrapRows } from \"#lib/wrap\"\n\n/** A cell reserved so the caret has somewhere to sit at the end of a full row. */\nconst CARET_CELL = 1\n\nexport interface ComposerRow {\n /** What is painted, hanging indent included. Never wider than the window. */\n readonly text: string\n /** Where the caret sits in this row, or `undefined` when it is on another row. */\n readonly caret: number | undefined\n /**\n * Buffer-absolute code-point offsets of the source this row draws, `start` inclusive and `end` not.\n *\n * Absolute rather than line-relative, which is the only form a selection can use: `wrapRows` reports\n * offsets into a single *line*, and a selection is a range over the whole buffer. Adding the line's own\n * start here is the one place that translation belongs — a renderer recomputing it would need the\n * split, the tab expansion and the wrap all over again to get the same number.\n */\n readonly start: number\n readonly end: number\n /** Columns of `text` that are re-applied indent, which no selection may highlight. */\n readonly lead: number\n}\n\n/** A run of a row that is drawn the same way: selected or not, caret or not. */\nexport interface RowSegment {\n readonly text: string\n readonly selected: boolean\n /** The single cell the caret inverts. Never wider than one code point. */\n readonly caret: boolean\n}\n\nexport interface ComposerLayout {\n /** Every visual row of the buffer, in order. At least one, even for an empty buffer. */\n readonly rows: readonly ComposerRow[]\n /** Index into `rows` holding the caret. */\n readonly caretRow: number\n}\n\n/**\n * Every visual row of `editor`'s buffer at `columns`, and which one the caret is on.\n *\n * `columns` is the width available *inside* whatever draws it — a caller with a border and padding\n * subtracts those first, because this cannot see them.\n */\nexport function composerLayout(editor: EditorState, columns: number): ComposerLayout {\n const width = Math.max(1, columns - CARET_CELL)\n const lines = editor.value.split(\"\\n\")\n const cursor = lineInfo(editor)\n\n const rows: ComposerRow[] = []\n let caretRow = 0\n // Where each line starts in the buffer, in code points. The `+ 1` is the newline itself, which no row\n // draws and every offset after it has to account for.\n let base = 0\n for (const [at, line] of lines.entries()) {\n const wrapped = wrapRows(line, width)\n // The caret's column has to be translated into the same tab-expanded coordinates the rows are\n // measured in, or a line containing a tab puts it seven columns to the left of where it is.\n const column = at === cursor.line ? expandColumn(line, cursor.column) : -1\n // Walked backwards so a caret exactly on a break lands at the *end* of the earlier row rather\n // than the start of the later one, which is where a person expects it after pressing → .\n let on = -1\n if (column >= 0) {\n on = wrapped.length - 1\n for (const [n, row] of wrapped.entries()) {\n if (column <= row.to) {\n on = n\n break\n }\n }\n }\n for (const [n, row] of wrapped.entries()) {\n if (n === on) caretRow = rows.length\n rows.push({\n start: base + row.from,\n end: base + row.to,\n lead: row.lead,\n text: row.text,\n // Clamped into the row: a caret past `to` can only mean the source column sat in the\n // whitespace a break consumed, and the end of the row is the honest place for it.\n caret:\n n === on\n ? row.lead + Math.max(0, Math.min(column - row.from, row.to - row.from))\n : undefined,\n })\n }\n base += [...line].length + 1\n }\n return { rows, caretRow }\n}\n\n/**\n * One row, split into the runs a renderer can paint in one go.\n *\n * Built as runs rather than as three slices because the caret can sit anywhere — including inside the\n * selection — and slicing for both produces overlapping ranges that have to be reconciled. Walking the row\n * once and grouping adjacent code points by how they are drawn has no such case, and the caret staying\n * exactly one cell wide is a property of the walk rather than something to remember.\n *\n * The indent is never selected. Those columns are chrome the wrap re-applied; highlighting them would\n * suggest text is included that no offset in the buffer corresponds to.\n */\nexport function rowSegments(\n row: ComposerRow,\n selection: { readonly start: number; readonly end: number } | undefined,\n): readonly RowSegment[] {\n const cells = [...row.text]\n const segments: RowSegment[] = []\n for (const [column, cell] of cells.entries()) {\n // A column past the indent maps back to the source by the same arithmetic the caret uses; one\n // inside it maps to nothing, which is why it can never be selected.\n const offset = column < row.lead ? -1 : row.start + (column - row.lead)\n const isSelected =\n selection !== undefined && offset >= selection.start && offset < selection.end\n const isCaret = row.caret === column\n const last = segments.at(-1)\n // The caret is its own run always, so it stays one cell wide even in the middle of a selection.\n if (last !== undefined && !isCaret && !last.caret && last.selected === isSelected) {\n segments[segments.length - 1] = { ...last, text: last.text + cell }\n continue\n }\n segments.push({ text: cell, selected: isSelected, caret: isCaret })\n }\n // A caret past the last character has no cell to invert, so it needs one. Same reason `LineCursor`\n // inverts a trailing space today.\n if (row.caret !== undefined && row.caret >= cells.length) {\n segments.push({ text: \" \", selected: false, caret: true })\n }\n return segments\n}\n",
|
|
6
|
+
"/**\n * Editable text with an inverse-video cursor — the rendering half of `editor.ts`.\n *\n * Shared by the chat composer and the wizard's text fields, so there is one cursor implementation:\n * code-point split (never UTF-16 units), the character under the cursor drawn inverse, and a trailing\n * space inverted when the cursor sits at the end. When the buffer is empty and a placeholder is given,\n * the placeholder renders dim with the cursor on its first character — the affordance every modern CLI\n * uses for \"press enter to accept this\".\n *\n * ## Why it renders rows rather than lines\n *\n * The chat buffer became multi-line in Phase 5.5, and the alternative to generalising this was a second\n * component for the composer — which would be a second cursor implementation, the exact thing this file\n * was extracted to prevent. So it renders a column of rows with a caller-supplied `gutter`, and a\n * single-line field is the one-row case of that.\n *\n * A **row is not a line**, and conflating them was the defect. Nothing here wrapped: each logical line was\n * handed to Ink with `wrap=\"truncate\"`, so a message wider than the box was cut and the caret went with it\n * — you could not see what you were typing. `composerLayout` now decides the rows and where the caret sits\n * on them, `wrap=\"truncate\"` is a backstop rather than the layout, and `chat-frame.promptRows` counts the\n * same rows this draws.\n *\n * Two consequences worth stating. The cursor is never drawn *on* a newline: the line break is structure\n * rather than a character, so the caret sits at the end of one row or the start of the next, which is\n * where a person expects it. And the view scrolls to follow the caret through `viewport()` — the same\n * function the catalogue list uses, because \"keep the interesting row visible\" is one rule.\n */\n\nimport { Box, Text } from \"ink\"\nimport { selectionRange } from \"#editor\"\nimport { composerLayout, rowSegments } from \"#lib/composer\"\nimport { viewport } from \"#lib/rows\"\nimport { THEME } from \"#lib/theme\"\nimport type { EditorState } from \"#lib/types\"\n\nexport interface LineCursorProps {\n readonly editor: EditorState\n readonly placeholder?: string\n /**\n * Render every character as a dot. For a value that must not appear on screen, in scrollback, or\n * over a shoulder — the cursor still moves normally, because the editing model is unchanged and\n * only the rendering differs.\n */\n readonly secret?: boolean\n /**\n * Drawn before the first line. Continuation lines get an equal-width blank, so the text stays in\n * one column and a two-line message does not look like two messages.\n */\n readonly gutter?: string\n /** Visible rows before the view starts scrolling to follow the cursor. */\n readonly maxRows?: number\n /**\n * Columns available for the text, the gutter included.\n *\n * Required for anything that can hold a long message. Omitted, nothing wraps and a line wider than\n * whatever draws this is truncated by Ink at a width nobody chose — which is what this component did\n * everywhere until Phase 5.6.\n */\n readonly columns?: number\n}\n\nexport function LineCursor({\n editor,\n placeholder,\n secret,\n gutter = \"\",\n maxRows,\n columns,\n}: LineCursorProps) {\n const lead = [...gutter].length\n const pad = \" \".repeat(lead)\n\n if (editor.value === \"\" && placeholder !== undefined && placeholder !== \"\") {\n const chars = [...placeholder]\n return (\n <Text dimColor wrap=\"truncate\">\n <Text color={THEME.accent}>{gutter}</Text>\n <Text inverse>{chars[0] ?? \" \"}</Text>\n {chars.slice(1).join(\"\")}\n </Text>\n )\n }\n\n // The gutter is drawn on the first row and matched by a blank on every row after it, so the text\n // stays in one column — which means the text itself only ever gets what is left.\n // Derived here rather than passed in: it is a function of the editor state this component already\n // has, and a prop would let a caller draw a highlight the reducer does not believe in.\n const selection = selectionRange(editor)\n const { rows: all, caretRow } = composerLayout(\n editor,\n Math.max(1, (columns ?? Number.MAX_SAFE_INTEGER) - lead),\n )\n const window = maxRows ?? all.length\n const { from, to } = viewport(all.length, caretRow, Math.max(1, window))\n const hiddenAbove = from\n const hiddenBelow = all.length - to\n\n return (\n <Box flexDirection=\"column\">\n {hiddenAbove > 0 ? (\n <Text dimColor wrap=\"truncate\">\n {pad}… {hiddenAbove} line{hiddenAbove === 1 ? \"\" : \"s\"} above\n </Text>\n ) : null}\n {all.slice(from, to).map((row, offset) => {\n const at = from + offset\n // Masked per code point, so the dot count matches what was typed rather than its byte\n // length.\n const chars = secret === true ? [...row.text].map(() => \"•\") : [...row.text]\n const glyph = at === from && hiddenAbove === 0 ? gutter : pad\n if (row.caret === undefined && selection === undefined) {\n return (\n // Keyed by index: two identical rows in a message are not the same row, and a\n // content key would collapse them.\n <Text key={`row-${at}`} wrap=\"truncate\">\n <Text color={THEME.accent}>{glyph}</Text>\n {chars.join(\"\")}\n </Text>\n )\n }\n // Runs rather than slices. The caret can sit inside the selection, and slicing for both\n // produces overlapping ranges that have to be reconciled; `rowSegments` walks the row once\n // and the caret stays one cell wide by construction. Masking is applied after the split so\n // a secret field's dots line up with the runs rather than with the source.\n const runs = rowSegments(row, selection)\n let column = 0\n return (\n <Text key={`row-${at}`} wrap=\"truncate\">\n <Text color={THEME.accent}>{glyph}</Text>\n {runs.map((run) => {\n const key = `run-${at}-${column}`\n column += [...run.text].length\n const text =\n secret === true ? [...run.text].map(() => \"•\").join(\"\") : run.text\n // Inverting a trailing space is how the caret stays visible at end of line;\n // `rowSegments` supplies that space when the caret is past the last character.\n if (run.caret) {\n return (\n <Text key={key} inverse>\n {text}\n </Text>\n )\n }\n if (run.selected) {\n return (\n <Text key={key} backgroundColor={THEME.selection}>\n {text}\n </Text>\n )\n }\n return <Text key={key}>{text}</Text>\n })}\n </Text>\n )\n })}\n {hiddenBelow > 0 ? (\n <Text dimColor wrap=\"truncate\">\n {pad}… {hiddenBelow} line{hiddenBelow === 1 ? \"\" : \"s\"} below\n </Text>\n ) : null}\n </Box>\n )\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";mHAoCA,IAAM,EAAa,EA0CZ,SAAS,EAAc,CAAC,EAAqB,EAAiC,CACjF,IAAM,EAAQ,KAAK,IAAI,EAAG,EAAU,CAAU,EACxC,EAAQ,EAAO,MAAM,MAAM;AAAA,CAAI,EAC/B,EAAS,GAAS,CAAM,EAExB,EAAsB,CAAC,EACzB,EAAW,EAGX,EAAO,EACX,QAAY,EAAI,KAAS,EAAM,QAAQ,EAAG,CACtC,IAAM,EAAU,GAAS,EAAM,CAAK,EAG9B,EAAS,IAAO,EAAO,KAAO,GAAa,EAAM,EAAO,MAAM,EAAI,GAGpE,EAAK,GACT,GAAI,GAAU,EAAG,CACb,EAAK,EAAQ,OAAS,EACtB,QAAY,EAAG,KAAQ,EAAQ,QAAQ,EACnC,GAAI,GAAU,EAAI,GAAI,CAClB,EAAK,EACL,OAIZ,QAAY,EAAG,KAAQ,EAAQ,QAAQ,EAAG,CACtC,GAAI,IAAM,EAAI,EAAW,EAAK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,EACnC,EAAK,IAAI,CAAC,IAAQ,CACf,IAAM,EAAM,OAAO,KAAM,IACzB,GAAU,CAAC,GAAG,EAAI,IAAI,EAAE,OACxB,IAAM,EACF,IAAW,GAAO,CAAC,GAAG,EAAI,IAAI,EAAE,IAAI,IAAM,GAAG,EAAE,KAAK,EAAE,EAAI,EAAI,KAGlE,GAAI,EAAI,MACJ,OACI,EAEE,EAFF,CAAgB,QAAO,GAAvB,SACK,GADM,CAET,EAGV,GAAI,EAAI,SACJ,OACI,EAEE,EAFF,CAAgB,gBAAiB,EAAM,UAAvC,SACK,GADM,CAET,EAGV,OAAO,EAAwB,EAAxB,UAAiB,GAAN,CAAa,EAClC,IAxBM,OAAO,GAyBhB,EAET,EACA,EAAc,EACX,EAEE,EAFF,CAAM,SAAQ,GAAC,KAAK,WAApB,SAEE,CADG,EADL,KACY,EADZ,QAC8B,IAAgB,EAAI,GAAK,IADvD,UAEE,EACF,MACN",
|
|
9
|
+
"debugId": "B06B4945C65FD3B864756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createInterface as w}from"node:readline";async function Ve(u,o={}){let e=o.input??process.stdin,r=o.output??process.stdout;if(e.isTTY!==!0)return!1;let i=w({input:e,output:r});try{let s=await new Promise((t)=>{i.question(`
|
|
3
|
+
${u} [y/N] `,t)});return/^y(es)?$/i.test(s.trim())}finally{i.close()}}async function Rr(u,o,e={}){let r=e.input??process.stdin,i=e.output??process.stdout;if(r.isTTY!==!0)return!1;let s=w({input:r,output:i});try{return(await new Promise((a)=>{s.question(`
|
|
4
|
+
${u} `,a)})).trim()===o}finally{s.close()}}async function Ir(u,o={}){let e=o.input??process.stdin,r=o.output??process.stdout;if(e.isTTY!==!0)return;r.write(`
|
|
5
|
+
${u} `);let i=typeof e.setRawMode==="function";if(i)e.setRawMode?.(!0);e.resume?.();try{return await new Promise((s)=>{let t="",a=!1,d=!1,l=(f)=>{e.removeListener("data",p),r.write(`
|
|
6
|
+
`),s(f)},p=(f)=>{let m=typeof f==="string"?f:f.toString("utf8");for(let c of m){let n=c.charCodeAt(0);if(d){if(n>=64&&n<=126)d=!1;continue}if(a){if(a=!1,c==="["||c==="O")d=!0;continue}if(n===27){a=!0;continue}if(n===13||n===10)return l(t);if(n===3)return l(void 0);if(n===4)return l(t===""?void 0:t);if(n===127||n===8){if(t.length>0)t=t.slice(0,-1),r.write("\b \b");continue}if(n<32)continue;t+=c,r.write("*")}};e.on("data",p)})}finally{if(i)e.setRawMode?.(!1)}}
|
|
7
|
+
export{Ve,Rr,Ir};
|
|
8
|
+
|
|
9
|
+
//# debugId=1F209715A069879264756E2164756E21
|
|
10
|
+
//# sourceMappingURL=index-j97vttdt.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lib/confirm.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * A yes/no question on the plain path.\n *\n * One question, one place. The wizard has its own confirm *screen* under Ink and the picker has a\n * selection; what was missing was the shape a single command needs before doing something outside its\n * own workspace — and the only current caller, `terminal-setup`, is the only command that does that.\n *\n * **Not a TTY means no.** A piped or CI run cannot answer, so the safe answer is the one that changes\n * nothing — and the caller reports that nothing was written rather than treating it as a failure.\n * Defaulting to yes here would make a redirected invocation edit somebody's editor keybindings, which is\n * the kind of surprise that is only discovered later.\n *\n * Deliberately not a general prompt library. A second kind of question can have a second function; a\n * configurable one would grow options nobody needs and hide the TTY rule above inside them. There are\n * three now — `askExactly` is a different bar, and `askSecret` is a different *channel*, because a\n * value that must not be echoed cannot go through readline at all.\n */\n\nimport { createInterface } from \"node:readline\"\n\nexport interface ConfirmOptions {\n /** Injected by tests. The process streams otherwise. */\n readonly input?: NodeJS.ReadableStream & { isTTY?: boolean }\n readonly output?: NodeJS.WritableStream\n}\n\nexport async function askYesNo(question: string, options: ConfirmOptions = {}): Promise<boolean> {\n const input = options.input ?? process.stdin\n const output = options.output ?? process.stdout\n if (input.isTTY !== true) return false\n\n const rl = createInterface({ input, output })\n try {\n const answer = await new Promise<string>((resolve) => {\n rl.question(`\\n${question} [y/N] `, resolve)\n })\n return /^y(es)?$/i.test(answer.trim())\n } finally {\n // Always closed: a readline left open holds the event loop and the process never exits.\n rl.close()\n }\n}\n\n/**\n * A question answered only by typing something back exactly.\n *\n * The bar for an irreversible, multi-part deletion. `askYesNo` is one keypress, which is right for\n * \"shall I edit your keybindings\" and too cheap for \"delete this agent, its conversations and its\n * memory\" — a stray `y` against the wrong listing is a mistake with nothing to undo it, and the whole\n * point of showing the listing first is that somebody reads it. Typing the name is what proves they did.\n *\n * Compared after trimming and nothing else. Case is **not** folded: an agent's ref is the name of a\n * directory, so `Milo` and `milo` are two different agents on a case-sensitive filesystem, and\n * accepting either here would accept the wrong one somewhere else.\n *\n * Not a TTY means no, for the reason `askYesNo` has it: a piped or CI run cannot answer, and the safe\n * answer is the one that changes nothing. The caller reports that nothing was deleted, and `--yes` is\n * how a script says it meant it.\n */\nexport async function askExactly(\n question: string,\n expected: string,\n options: ConfirmOptions = {},\n): Promise<boolean> {\n const input = options.input ?? process.stdin\n const output = options.output ?? process.stdout\n if (input.isTTY !== true) return false\n\n const rl = createInterface({ input, output })\n try {\n const answer = await new Promise<string>((resolve) => {\n rl.question(`\\n${question} `, resolve)\n })\n return answer.trim() === expected\n } finally {\n rl.close()\n }\n}\n\n/**\n * A value typed at a prompt and never echoed. `undefined` means cancelled or unavailable.\n *\n * ## Why this is not readline\n *\n * readline echoes what it reads, and the documented way to stop it is to overwrite a private method on\n * the interface — which needs a cast this codebase does not allow. Reading the bytes is a dozen more\n * lines and it is the honest version: raw mode on, one `*` written per character, raw mode off in a\n * `finally` so a thrown error cannot leave the terminal unable to echo anything the person types next.\n *\n * ## Why a secret never comes from an argument\n *\n * The alternative was `--value`, and it puts the secret in two places nobody intends: the shell's\n * history file, and `ps` output, where every local process can read it for the lifetime of the call.\n * That is the same exposure `renderPlist` throws to prevent — launchd echoes a job's environment in\n * plaintext, so a plist carries no secret — and the reasoning does not change because the process is\n * short-lived. Not a TTY returns `undefined` rather than reading a pipe, so a CI run is *told* that\n * nothing was written instead of a secret arriving from somewhere the caller did not audit.\n *\n * ^C cancels and ^D on an empty line cancels; both return `undefined`, and the caller reports that\n * nothing changed. Backspace is honoured because a mistyped key in a value you cannot see is otherwise\n * unrecoverable without starting the command again.\n */\n/**\n * The narrow surface `askSecret` touches, rather than a widened `ConfirmOptions.input`.\n *\n * `process.stdin`'s declared `on` is a union of overloads, and intersecting that with an object type\n * makes it uncallable — the compiler cannot pick a signature. Declaring only what is used and asserting\n * the real stream against it once keeps the check where it is useful: anything else this function\n * reached for would be a type error here rather than a runtime surprise.\n */\nexport interface SecretInput {\n readonly isTTY?: boolean\n setRawMode?: (mode: boolean) => unknown\n resume?: () => unknown\n on(event: \"data\", listener: (chunk: Buffer | string) => void): unknown\n removeListener(event: \"data\", listener: (chunk: Buffer | string) => void): unknown\n}\n\nexport interface SecretOptions {\n readonly input?: SecretInput\n readonly output?: NodeJS.WritableStream\n}\n\nexport async function askSecret(\n question: string,\n options: SecretOptions = {},\n): Promise<string | undefined> {\n const input = options.input ?? (process.stdin as unknown as SecretInput)\n const output = options.output ?? process.stdout\n if (input.isTTY !== true) return undefined\n\n output.write(`\\n${question} `)\n const raw = typeof input.setRawMode === \"function\"\n if (raw) input.setRawMode?.(true)\n input.resume?.()\n\n try {\n return await new Promise<string | undefined>((resolve) => {\n let value = \"\"\n // Escape-sequence state. Dropping only the escape *byte* left `[A` in the value for an\n // arrow key — two characters of junk in a string nobody can see, which is worse than three\n // because it looks like nothing happened. CSI runs until a byte in 0x40–0x7e ends it.\n let escaped = false\n let csi = false\n const finish = (result: string | undefined) => {\n input.removeListener(\"data\", onData)\n output.write(\"\\n\")\n resolve(result)\n }\n const onData = (chunk: Buffer | string) => {\n const text = typeof chunk === \"string\" ? chunk : chunk.toString(\"utf8\")\n for (const char of text) {\n const code = char.charCodeAt(0)\n if (csi) {\n // The final byte of a CSI sequence, and the end of it.\n if (code >= 0x40 && code <= 0x7e) csi = false\n continue\n }\n if (escaped) {\n escaped = false\n // `[` opens CSI and `O` opens SS3, which is how some terminals send arrows.\n if (char === \"[\" || char === \"O\") csi = true\n continue\n }\n if (code === 27) {\n escaped = true\n continue\n }\n if (code === 13 || code === 10) return finish(value)\n // ^C always cancels; ^D cancels only an empty line, so it cannot silently\n // truncate a value somebody was halfway through typing.\n if (code === 3) return finish(undefined)\n if (code === 4) return finish(value === \"\" ? undefined : value)\n if (code === 127 || code === 8) {\n if (value.length > 0) {\n value = value.slice(0, -1)\n output.write(\"\\b \\b\")\n }\n continue\n }\n // Any remaining control byte is a chord, and a secret has none in it.\n if (code < 32) continue\n value += char\n output.write(\"*\")\n }\n }\n input.on(\"data\", onData)\n })\n } finally {\n // Always restored. A thrown error that left raw mode on would leave the shell that follows\n // unable to echo anything at all, which reads as a hung terminal rather than a failed command.\n if (raw) input.setRawMode?.(false)\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAkBA,0BAAS,sBAQT,eAAsB,EAAQ,CAAC,EAAkB,EAA0B,CAAC,EAAqB,CAC7F,IAAM,EAAQ,EAAQ,OAAS,QAAQ,MACjC,EAAS,EAAQ,QAAU,QAAQ,OACzC,GAAI,EAAM,QAAU,GAAM,MAAO,GAEjC,IAAM,EAAK,EAAgB,CAAE,QAAO,QAAO,CAAC,EAC5C,GAAI,CACA,IAAM,EAAS,MAAM,IAAI,QAAgB,CAAC,IAAY,CAClD,EAAG,SAAS;AAAA,EAAK,WAAmB,CAAO,EAC9C,EACD,MAAO,YAAY,KAAK,EAAO,KAAK,CAAC,SACvC,CAEE,EAAG,MAAM,GAoBjB,eAAsB,EAAU,CAC5B,EACA,EACA,EAA0B,CAAC,EACX,CAChB,IAAM,EAAQ,EAAQ,OAAS,QAAQ,MACjC,EAAS,EAAQ,QAAU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D,GAAI,IAAS,KAAO,IAAS,EAAG,CAC5B,GAAI,EAAM,OAAS,EACf,EAAQ,EAAM,MAAM,EAAG,EAAE,EACzB,EAAO,MAAM,OAAO,EAExB,SAGJ,GAAI,EAAO,GAAI,SACf,GAAS,EACT,EAAO,MAAM,GAAG,IAGxB,EAAM,GAAG,OAAQ,CAAM,EAC1B,SACH,CAGE,GAAI,EAAK,EAAM,aAAa,EAAK",
|
|
8
|
+
"debugId": "1F209715A069879264756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var o={accent:"magenta",muted:"gray",success:"green",warning:"yellow",error:"red",info:"blue",emphasis:"cyan",selection:"blue",border:"gray",borderActive:"magenta",brand:"magenta"},zo={idle:o.success,thinking:o.warning,streaming:o.accent,working:o.info,cancelling:o.emphasis},Bo={user:o.accent,assistant:void 0,reasoning:o.muted,note:o.muted,error:o.error,tool:o.info,banner:void 0},Ko={user:"› ",assistant:"",reasoning:" ",note:"· ",error:"✖ ",tool:" · ",banner:""},u={prompt:"› ",pointer:"❯ ",bullet:"· ",error:"✖ ",dot:"● ",check:"✓ ",ellipsis:"…",create:"+ ",checked:"◉ ",unchecked:"◯ "},$r=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],Ho=80,oe="round";function d(n){if(n<1000)return String(n);let e=n/1000;return e<10?`${e.toFixed(1)}k`:`${Math.round(e)}k`}function Wo(n,e,r){if(r)return"installed";let t=d(n);return e===0?t:`${t} · ${e} script${e===1?"":"s"}`}function S(n,e){if(e<=0)return"";let r=n.replace(/\s+/g," ").trim();if(r.length<=e)return r;if(e===1)return"…";return`${r.slice(0,e-1)}…`}function yn(n,e,r={}){let t=Math.max(18,Math.min(r.nameMax??34,e)),s=18,i=6;if(i+t+s>n)s=Math.max(6,n-i-t);if(i+t+s>n)t=Math.max(6,n-i-s);let a=n-(i+t+s+2);if(n<60||a<24)return{name:t,meta:s,description:0};return{name:t,meta:s,description:a}}function wn(n,e){return{name:S(n.name,e.name).padEnd(e.name),meta:S(n.meta,e.meta).padEnd(e.meta),description:e.description===0?"":S(n.description,e.description)}}function bn(n,e){let r=S(n,Math.max(0,e-8)),t=r.length+3;return`${r} ${"─".repeat(Math.max(0,Math.min(e,80)-t))}`}function R(n,e,r){if(n<=r)return{from:0,to:n};let t=Math.floor(r/2),s=Math.min(Math.max(0,e-t),n-r);return{from:s,to:s+r}}var Fo="\x1B[?1000h\x1B[?1002h\x1B[?1006h",Uo="\x1B[?1006l\x1B[?1002l\x1B[?1000l";var l=/(?:^|\u001B)\[<(\d+);(\d+);(\d+)([Mm])/g,m=/(?:^|\u001B)\[M[\s\S]{3}/g;function jo(n){if(!n.includes("[<")&&!n.includes("[M"))return;let e=0,r=!1,t,s,i=!1;for(let a of n.matchAll(l)){r=!0;let c=Number(a[1]);if(c===64){e-=3;continue}if(c===65){e+=3;continue}t={column:Math.max(0,Number(a[2])-1),row:Math.max(0,Number(a[3])-1)},s=a[4]==="m"?"release":(c&32)!==0?"drag":"press",i=(c&4)!==0}for(let a of n.matchAll(m)){r=!0;let c=(a[0].codePointAt(a[0].length-3)??32)-32;if(c===64)e-=3;else if(c===65)e+=3}if(!r)return;return{rows:e,...t===void 0?{}:{at:t},...s===void 0?{}:{kind:s},...i?{shift:i}:{}}}
|
|
3
|
+
export{Fo,Uo,jo,o,zo,Bo,Ko,u,$r,Ho,oe,Wo,S,yn,wn,bn,R};
|
|
4
|
+
|
|
5
|
+
//# debugId=976CA4379D869E5D64756E2164756E21
|
|
6
|
+
//# sourceMappingURL=index-jk0def33.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lib/theme.ts", "../src/lib/rows.ts", "../src/lib/mouse.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * The one home for appearance: colour tokens, glyphs, and the maps components render from.\n *\n * `lib/const.ts` keeps *behavioural* numbers (row caps, history limits, control sequences); this\n * module holds everything a person would touch to change how the CLI looks. Splitting the two\n * extends the \"no magic value inline\" rule rather than weakening it — one home each, and a\n * component containing a literal colour name is a review failure.\n *\n * Tokens are plain Ink colour names (16-colour safe; Ink's chalk layer maps them per terminal),\n * which keeps this module PURE-listable. `brand` is the single deliberate exception and says why. `NO_COLOR` needs no handling here: the mode resolution\n * forces plain output before Ink ever loads, and chalk independently honours it anyway.\n *\n * This is deliberately a single built-in token set, not a theming system — decision 11.12\n * reverses Phase 2.5's \"themes\" non-goal in the narrowest possible sense. User-configurable\n * themes stay a non-goal.\n */\n\nimport type { TranscriptRole, TurnStatus } from \"#lib/types\"\n\nexport interface Theme {\n /** The one accent, used sparingly: caret, selection cursor, user lines, banner border. */\n readonly accent: string\n /** Hints, notes, reasoning, breadcrumbs. */\n readonly muted: string\n readonly success: string\n readonly warning: string\n readonly error: string\n /** Tool rows and tool-running status. */\n readonly info: string\n /** Cancelling — the one transitional state worth its own colour. */\n readonly emphasis: string\n /**\n * The background a selected run is painted on.\n *\n * A background rather than `inverse`, which is what the caret uses. Inverse swaps foreground and\n * background, so on a coloured run it produces a different colour per role and reads as three\n * highlights rather than one selection — and where a selection contains the caret the two inversions\n * cancel and the caret disappears inside it. A solid background composes instead of fighting.\n */\n readonly selection: string\n /** Non-focal boxes: cards, frames. */\n readonly border: string\n /** The focused box: the input line, the banner. */\n readonly borderActive: string\n /**\n * The wordmark, and only the wordmark.\n *\n * The one token that is a hex triplet rather than an Ink colour name, chosen by the owner. Every other\n * token is 16-colour safe on purpose — a name lets chalk pick whatever the terminal actually has — and\n * this is the deliberate exception, because a brand mark is the one element whose *exact* colour is the\n * point. Chalk downsamples it per terminal rather than failing: on a 256-colour terminal it lands on the\n * nearest cube entry, on a 16-colour one on bright green, which is the right neighbour. `NO_COLOR` is\n * handled before Ink loads at all, by the mode resolution.\n *\n * Not reused anywhere else. A second consumer would make it an accent, and the accent already exists.\n */\n readonly brand: string\n}\n\nexport const THEME: Theme = {\n accent: \"magenta\",\n muted: \"gray\",\n success: \"green\",\n warning: \"yellow\",\n error: \"red\",\n info: \"blue\",\n emphasis: \"cyan\",\n // 16-colour safe like every token but `brand`: chalk maps it to whatever the terminal has, and a\n // named colour survives a 16-colour terminal where a hex triplet would be approximated.\n selection: \"blue\",\n border: \"gray\",\n borderActive: \"magenta\",\n brand: \"magenta\",\n}\n\n/** Status-dot colours, previously inlined in StatusBar. */\nexport const STATUS_COLOR: Record<TurnStatus, string> = {\n idle: THEME.success,\n thinking: THEME.warning,\n streaming: THEME.accent,\n working: THEME.info,\n cancelling: THEME.emphasis,\n}\n\n/** Transcript role colours, previously inlined in Transcript. `undefined` = terminal default. */\nexport const ROLE_COLOR: Record<TranscriptRole, string | undefined> = {\n user: THEME.accent,\n assistant: undefined,\n reasoning: THEME.muted,\n note: THEME.muted,\n error: THEME.error,\n tool: THEME.info,\n banner: undefined,\n}\n\n/**\n * What each role puts before its text, and re-applies as a hanging indent on every row after the first.\n *\n * That second half is why `reasoning` is **two columns** rather than the `\\u00b7 reasoning \\u00b7 ` it used to be.\n * A prefix is an indent, so the longest block in the transcript was also the narrowest — 86 columns of a\n * 100-column terminal, on the one item that is routinely forty rows long. The label moved to a header row\n * of its own, where it costs one row once instead of fourteen columns per row.\n */\nexport const ROLE_PREFIX: Record<TranscriptRole, string> = {\n user: \"› \",\n assistant: \"\",\n reasoning: \" \",\n note: \"· \",\n error: \"✖ \",\n tool: \" · \",\n banner: \"\",\n}\n\n/** The glyph vocabulary. Components compose these; none defines its own. */\nexport const GLYPH = {\n prompt: \"› \",\n pointer: \"❯ \",\n bullet: \"· \",\n error: \"✖ \",\n dot: \"● \",\n check: \"✓ \",\n ellipsis: \"…\",\n create: \"+ \",\n /** Multi-select boxes. Two glyphs so a ticked row reads as ticked without colour. */\n checked: \"◉ \",\n unchecked: \"◯ \",\n} as const\n\n/** Braille spinner. Ten glyphs in a const, not a dependency — decision 11.10 holds. */\nexport const SPINNER_FRAMES = [\"⠋\", \"⠙\", \"⠹\", \"⠸\", \"⠼\", \"⠴\", \"⠦\", \"⠧\", \"⠇\", \"⠏\"] as const\nexport const SPINNER_INTERVAL_MS = 80\n\n/** cli-boxes ships inside Ink 7; rounded is the house border. Zero new dependencies. */\nexport const BORDER_STYLE = \"round\" as const\n",
|
|
6
|
+
"/**\n * Laying a catalogue row out in a fixed number of columns. Pure, so the layout is testable as strings.\n *\n * ## Why this is not a component's problem\n *\n * The first version put the name, the size and the whole description in one `<Text>` and let Ink wrap.\n * Every row longer than the terminal became two or three lines, the checkbox column stopped lining up,\n * and a list of forty skills was unreadable. Wrapping is not a styling detail in a list — it destroys the\n * one property a list has, which is that a row is a row.\n *\n * So the width arithmetic lives here, in one place, as functions over numbers and strings: pad the name to\n * a column, pad the meta to a column, give the description whatever is left, and **truncate every field\n * before it can wrap**. `Text` also carries `wrap=\"truncate\"` as a backstop, but a backstop is not a\n * layout — the columns have to add up, or the description gets cut at a width nobody chose.\n */\n\n/** Terminal columns below which the description is dropped rather than shown as three characters. */\nconst NARROW = 60\n/** The name column, wide enough for `create-architectural-decision-record` to be recognisable. */\nconst NAME_MIN = 18\nconst NAME_MAX = 34\n/** `12.3k · 15 scripts` is the widest realistic meta string. */\nconst META = 18\n/** Checkbox plus pointer, both two characters. */\nconst GUTTER = 4\nconst GAP = 2\n\n/** `2284` → `2.3k`. A row is scanned, not audited, and five digits of precision cost a column. */\nexport function compactTokens(tokens: number): string {\n if (tokens < 1000) return String(tokens)\n const thousands = tokens / 1000\n return thousands < 10 ? `${thousands.toFixed(1)}k` : `${Math.round(thousands)}k`\n}\n\nexport function metaOf(tokens: number, scripts: number, installed: boolean): string {\n if (installed) return \"installed\"\n const size = compactTokens(tokens)\n return scripts === 0 ? size : `${size} · ${scripts} script${scripts === 1 ? \"\" : \"s\"}`\n}\n\n/** Cut to `width`, with an ellipsis when anything was lost. Never returns more than `width`. */\nexport function clip(text: string, width: number): string {\n if (width <= 0) return \"\"\n const flat = text.replace(/\\s+/g, \" \").trim()\n if (flat.length <= width) return flat\n if (width === 1) return \"…\"\n return `${flat.slice(0, width - 1)}…`\n}\n\nexport interface RowColumns {\n readonly name: number\n readonly meta: number\n readonly description: number\n}\n\n/**\n * How wide each column is at a given terminal width.\n *\n * The name column flexes with the longest name actually present rather than being fixed: a catalogue of\n * short names should not leave a third of the row empty, and one long name should not push the\n * description off the screen. Clamped at both ends for both reasons.\n */\nexport function columnsFor(\n width: number,\n longestName: number,\n options: { readonly nameMax?: number } = {},\n): RowColumns {\n // Overridden by the plain path, whose names carry a `source/` prefix and which has no cursor to keep\n // near them. Passing a wider name column *without* going through this function is what pushed every\n // piped row twelve characters over the width it was laid out for.\n let name = Math.max(NAME_MIN, Math.min(options.nameMax ?? NAME_MAX, longestName))\n let meta = META\n\n // The name and meta columns shrink before anything else does. Without this the *fixed* part of the row\n // could exceed the terminal on its own — at 40 columns with a 34-character name it came to 60, so every\n // row wrapped no matter what the description did, which is the bug this module exists to remove.\n const chrome = GUTTER + GAP\n if (chrome + name + meta > width) meta = Math.max(6, width - chrome - name)\n if (chrome + name + meta > width) name = Math.max(6, width - chrome - meta)\n\n const description = width - (chrome + name + meta + GAP)\n // Below the threshold the description is dropped entirely. Three characters of a sentence is worse than\n // none: it takes the same column and carries no information.\n if (width < NARROW || description < 24) return { name, meta, description: 0 }\n return { name, meta, description }\n}\n\n/**\n * One row, exactly `width` characters wide or less, in three aligned columns.\n *\n * Returned as one string rather than as fields, because alignment is the whole point and a caller that\n * assembled the parts could get the padding wrong. Colour is applied by the component *around* this — the\n * arithmetic must not know about escape codes, which do not occupy columns and would break every count.\n */\nexport function layoutRow(\n input: {\n readonly name: string\n readonly meta: string\n readonly description: string\n },\n columns: RowColumns,\n): { readonly name: string; readonly meta: string; readonly description: string } {\n return {\n name: clip(input.name, columns.name).padEnd(columns.name),\n meta: clip(input.meta, columns.meta).padEnd(columns.meta),\n description: columns.description === 0 ? \"\" : clip(input.description, columns.description),\n }\n}\n\n/** A heading, drawn as a rule so groups separate without costing a blank line each. */\nexport function headingRule(label: string, width: number): string {\n const text = clip(label, Math.max(0, width - 8))\n const filled = text.length + 3\n return `${text} ${\"─\".repeat(Math.max(0, Math.min(width, 80) - filled))}`\n}\n\n/**\n * Which slice of a longer list to show.\n *\n * Shared by the catalogue list and the input box, which want the same rule for the same reason: both\n * are taller than their allowance and both have a position that must stay visible. It lives here rather\n * than in either component because the second caller is what proved it was layout arithmetic and not a\n * detail of one screen.\n *\n * Originally: Keeps the cursor inside the window rather than paging, because a cursor that jumps a\n * whole viewport loses the reader's place.\n */\nexport function viewport(\n total: number,\n index: number,\n window: number,\n): { readonly from: number; readonly to: number } {\n if (total <= window) return { from: 0, to: total }\n const half = Math.floor(window / 2)\n const from = Math.min(Math.max(0, index - half), total - window)\n return { from, to: from + window }\n}\n",
|
|
7
|
+
"/**\n * Wheel scrolling on the alternate screen. Pure, so a mouse report is arithmetic rather than a guess.\n *\n * ## Why this needs a guard rather than only a parser\n *\n * Ink does not know about mouse reports. Measured against a real pty with tracking on: a wheel notch\n * arrived as the literal text `ESC[<64;10;5M`, fell through the keymap to the insert branch, and was typed\n * into the message — twice, because two notches are two reports. So recognising a report is not an\n * optimisation here; every report a terminal can send has to be claimed, wheel and click alike, or the\n * feature's cost is garbage in somebody's message.\n *\n * A chunk can carry several reports. A fast scroll sends one per notch and the runtime coalesces them, so\n * the count matters: honouring one report per chunk makes a flick of the wheel move a single row and reads\n * as the wheel not working.\n *\n * ## The trade this makes, stated\n *\n * Tracking is what stops the terminal handling the mouse itself, so **drag-selecting text with the mouse\n * stops working while a session is mounted**. Every terminal worth naming lets you hold shift to bypass\n * tracking and select natively, which is why the key list says so rather than leaving it to be discovered.\n *\n * Two encodings are recognised. SGR (`ESC [ < b ; x ; y M`) is what we ask for and what any terminal from\n * the last decade replies with; X10 (`ESC [ M` and three raw bytes) is the fallback a terminal that ignored\n * the SGR request will use, and its bytes are frequently above 127 — so leaving it unclaimed would put\n * unprintable characters into a message on exactly the terminals least able to say why.\n */\n\n/**\n * Button tracking, drag tracking, and SGR encoding.\n *\n * 1000 reports press and release and is the least that reports the wheel at all. **1002 adds motion while a\n * button is held**, and without it a drag is not reported — which is why selecting text was not merely\n * disabled but unreachable: the events never arrived. 1003 (motion with no button) is deliberately absent,\n * because it makes the terminal send a report for every pixel of idle pointer movement and nothing here\n * wants hover.\n *\n * Set low-to-high and reset high-to-low, so a terminal that only understands some of them is left in a\n * state we asked for rather than a partial one.\n */\nexport const ENABLE_MOUSE = \"\\u001B[?1000h\\u001B[?1002h\\u001B[?1006h\"\n/** Reversed on the way out, so a terminal is left handling its own mouse again. */\nexport const DISABLE_MOUSE = \"\\u001B[?1006l\\u001B[?1002l\\u001B[?1000l\"\n\n/**\n * Rows one notch of the wheel moves.\n *\n * Three, which is the line-scroll every desktop uses. One row per notch is technically a scroll and feels\n * like the wheel is broken; a whole page per notch overshoots what somebody is looking for.\n */\nexport const WHEEL_ROWS = 3\n\n/** Wheel-up and wheel-down in SGR's button numbering. 64 is the wheel bit plus button 0. */\nconst WHEEL_UP = 64\nconst WHEEL_DOWN = 65\n\n/** Motion bit — set on every report mode 1002 sends while a button is held. */\nconst MOTION = 32\n/** Shift bit, so shift-clicking can extend a selection rather than starting a new one. */\nconst SHIFT = 4\n\n/**\n * The escape prefix is **optional**, and that is not laxness.\n *\n * Ink strips one leading `ESC` from the chunk before a handler sees it (`use-input.js:97`), so the first\n * report in a chunk arrives bare and every one after it keeps its escape. Requiring the prefix therefore\n * matched none of them, which is exactly how the first version of this let a wheel notch through: measured\n * against a real pty, the composer read `abc[<64;10;5M[<64;10;5M`.\n *\n * Anchored rather than left floating: a bare report is only recognised at the very start of the chunk,\n * which is the one position Ink's stripping can produce. A message that happens to contain the same text\n * in the middle of a sentence is still a message.\n */\n// biome-ignore lint/suspicious/noControlCharactersInRegex: the escape byte is the thing being matched\nconst SGR = /(?:^|\\u001B)\\[<(\\d+);(\\d+);(\\d+)([Mm])/g\n// biome-ignore lint/suspicious/noControlCharactersInRegex: the escape byte is the thing being matched\nconst X10 = /(?:^|\\u001B)\\[M[\\s\\S]{3}/g\n\n/** Which gesture a report describes. */\nexport type MouseKind = \"wheel\" | \"press\" | \"drag\" | \"release\"\n\n/** Where a report happened, in **zero-based** screen cells. */\nexport interface MousePoint {\n readonly column: number\n readonly row: number\n}\n\nexport interface MouseInput {\n /**\n * Rows to move: negative up, positive down, zero for a report that is not the wheel.\n *\n * Zero is *not* \"no report\" — a click is a report with no scroll in it, and it still has to be\n * swallowed. The `undefined` return is what means \"no report\".\n */\n readonly rows: number\n /**\n * The last gesture in the chunk, and where it happened. `undefined` when nothing positional was in it.\n *\n * The *last* rather than every one, because a drag arrives as a stream of motion reports and only the\n * newest position matters — a selection follows the pointer, it does not retrace it. The wheel is the\n * exception and is summed instead, which is why `rows` is separate: a flick coalesces several notches\n * into one chunk and honouring only the last would move a single row.\n */\n readonly at?: MousePoint\n readonly kind?: MouseKind\n /** Held modifiers, from SGR's button bits. Shift is what extends a selection from a click. */\n readonly shift?: boolean\n}\n\n/**\n * What a chunk of input means to the mouse, or `undefined` if it holds no mouse report at all.\n *\n * Returning `undefined` rather than a zero is what keeps a keystroke a keystroke: every other branch of\n * the keymap runs only when this says nothing.\n */\nexport function mouseInput(input: string): MouseInput | undefined {\n // Cheap prefilter. Every report contains one of these two, and almost no keystroke does.\n if (!input.includes(\"[<\") && !input.includes(\"[M\")) return undefined\n let rows = 0\n let seen = false\n let at: MousePoint | undefined\n let kind: MouseKind | undefined\n let shift = false\n for (const match of input.matchAll(SGR)) {\n seen = true\n const button = Number(match[1])\n if (button === WHEEL_UP) {\n rows -= WHEEL_ROWS\n continue\n }\n if (button === WHEEL_DOWN) {\n rows += WHEEL_ROWS\n continue\n }\n // SGR reports 1-based cells; everything downstream indexes from zero, so the conversion happens\n // once, here, rather than at each of the callers that would each have to remember it.\n at = { column: Math.max(0, Number(match[2]) - 1), row: Math.max(0, Number(match[3]) - 1) }\n // `m` is a release whatever the button bits say. Motion is bit 5 (32); the low two bits are the\n // button, and only the left one starts a selection.\n kind = match[4] === \"m\" ? \"release\" : (button & MOTION) !== 0 ? \"drag\" : \"press\"\n shift = (button & SHIFT) !== 0\n }\n for (const match of input.matchAll(X10)) {\n seen = true\n // X10 offsets every field by 32, so the wheel's 64 and 65 arrive as 96 and 97.\n // Three fields follow `[M`, and the escape before it is optional — so the button is found\n // from the end of the match rather than at a fixed offset.\n const button = (match[0].codePointAt(match[0].length - 3) ?? 32) - 32\n if (button === WHEEL_UP) rows -= WHEEL_ROWS\n else if (button === WHEEL_DOWN) rows += WHEEL_ROWS\n }\n if (!seen) return undefined\n return {\n rows,\n ...(at === undefined ? {} : { at }),\n ...(kind === undefined ? {} : { kind }),\n ...(shift ? { shift } : {}),\n }\n}\n"
|
|
8
|
+
],
|
|
9
|
+
"mappings": ";AA2DO,IAAM,EAAe,CACxB,OAAQ,UACR,MAAO,OACP,QAAS,QACT,QAAS,SACT,MAAO,MACP,KAAM,OACN,SAAU,OAGV,UAAW,OACX,OAAQ,OACR,aAAc,UACd,MAAO,SACX,EAGa,GAA2C,CACpD,KAAM,EAAM,QACZ,SAAU,EAAM,QAChB,UAAW,EAAM,OACjB,QAAS,EAAM,KACf,WAAY,EAAM,QACtB,EAGa,GAAyD,CAClE,KAAM,EAAM,OACZ,UAAW,OACX,UAAW,EAAM,MACjB,KAAM,EAAM,MACZ,MAAO,EAAM,MACb,KAAM,EAAM,KACZ,OAAQ,MACZ,EAUa,GAA8C,CACvD,KAAM,KACN,UAAW,GACX,UAAW,KACX,KAAM,KACN,MAAO,KACP,KAAM,OACN,OAAQ,EACZ,EAGa,EAAQ,CACjB,OAAQ,KACR,QAAS,KACT,OAAQ,KACR,MAAO,KACP,IAAK,KACL,MAAO,KACP,SAAU,IACV,OAAQ,KAER,QAAS,KACT,UAAW,IACf,EAGa,GAAiB,CAAC,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAA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AAM,WAAa,EAlFhC,MAkFqD,EAAI,OAAS,QACzE,GAAS,EAjFH,KAiFuB,EAEjC,QAAW,KAAS,EAAM,SAAS,CAAG,EAAG,CACrC,EAAO,GAIP,IAAM,GAAU,EAAM,GAAG,YAAY,EAAM,GAAG,OAAS,CAAC,GAAK,IAAM,GACnE,GAAI,IA/FK,GA+FgB,GAlGP,EAmGb,QAAI,IA/FE,GA+FqB,GAnGd,EAqGtB,GAAI,CAAC,EAAM,OACX,MAAO,CACH,UACI,IAAO,OAAY,CAAC,EAAI,CAAE,IAAG,KAC7B,IAAS,OAAY,CAAC,EAAI,CAAE,MAAK,KACjC,EAAQ,CAAE,OAAM,EAAI,CAAC,CAC7B",
|
|
10
|
+
"debugId": "976CA4379D869E5D64756E2164756E21",
|
|
11
|
+
"names": []
|
|
12
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{o,u}from"./index-jk0def33.js";import{hn}from"./index-h2yds678.js";import{Box as m,Text as i}from"ink";import{jsx as d,jsxs as l}from"react/jsx-runtime";function Vt({label:p,editor:a,placeholder:e,error:r,secret:f,columns:t,maxRows:n}){return l(m,{flexDirection:"column",children:[d(i,{children:p}),d(hn,{editor:a,gutter:u.prompt,...e===void 0?{}:{placeholder:e},...f===!0?{secret:!0}:{},...t===void 0?{}:{columns:t},...n===void 0?{}:{maxRows:n}}),r===void 0?null:l(i,{color:o.error,children:[u.error,r]})]})}
|
|
3
|
+
export{Vt};
|
|
4
|
+
|
|
5
|
+
//# debugId=47A7D59412E5C11264756E2164756E21
|
|
6
|
+
//# sourceMappingURL=index-jym27m75.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/components/TextField.tsx"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * A labelled text input for wizard questions: label, caret, LineCursor, optional error line.\n *\n * The editing itself lives upstream — the screen root routes keys through `keyToIntent` into\n * `applyIntent` and hands the resulting `EditorState` down — so every editing nicety the chat\n * input has (^A/^E, ^W, code-point cursor) works here without a second implementation.\n */\n\nimport { Box, Text } from \"ink\"\nimport { LineCursor } from \"#components/LineCursor\"\nimport { GLYPH, THEME } from \"#lib/theme\"\nimport type { EditorState } from \"#lib/types\"\n\nexport interface TextFieldProps {\n readonly label: string\n readonly editor: EditorState\n /** The question's default, shown dim when the buffer is empty; enter accepts it. */\n readonly placeholder?: string\n /** A validation failure, rendered beneath in the error colour. Cleared upstream on edit. */\n readonly error?: string\n /** Mask the value as it is typed. Passed straight through to the cursor. */\n readonly secret?: boolean\n /**\n * Columns available for the value. **Not optional in practice.**\n *\n * `LineCursor`'s own docstring says it: omitted, nothing wraps and a line wider than whatever draws\n * this is truncated by Ink at a width nobody chose. This component never passed it, and in the\n * settings editor — which draws the field into an unbordered column — a value longer than the\n * terminal was clipped at the right edge with the caret *past* the clip. You could not see what you\n * were typing, and `tools.pinned` is 92 characters in a generated manifest, so it was the first long\n * value anybody opened.\n *\n * **The wizard was not affected, and checking that mattered**: its bordered frame gives the `<Text>`\n * a bounded width, so Ink wrapped it anyway. Measured, after the assumption that it must be broken\n * too — the guard that would have \"proved\" it passed with the fix reverted. It is passed there now\n * regardless, because whoever owns a bounded window should wrap the text itself rather than leave it\n * to whatever happens to enclose it, and because `maxRows` genuinely bounds the height.\n */\n readonly columns?: number\n /** Rows the value may take before the view scrolls to follow the cursor. */\n readonly maxRows?: number\n}\n\nexport function TextField({\n label,\n editor,\n placeholder,\n error,\n secret,\n columns,\n maxRows,\n}: TextFieldProps) {\n return (\n <Box flexDirection=\"column\">\n <Text>{label}</Text>\n {/*\n * The prompt glyph is the cursor's `gutter` rather than a sibling `<Text>`. Two reasons, and\n * the second is not optional: it keeps a wrapped or multi-line value in one column, and\n * `LineCursor` renders a `<Box>`, which inside a `<Text>` produces an empty frame — no error,\n * nothing on screen. A frame test caught that; nothing else would have.\n */}\n <LineCursor\n editor={editor}\n gutter={GLYPH.prompt}\n {...(placeholder === undefined ? {} : { placeholder })}\n {...(secret === true ? { secret: true } : {})}\n {...(columns === undefined ? {} : { columns })}\n {...(maxRows === undefined ? {} : { maxRows })}\n />\n {error === undefined ? null : (\n <Text color={THEME.error}>\n {GLYPH.error}\n {error}\n </Text>\n )}\n </Box>\n )\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";yEAQA,cAAS,UAAK,8DAmCP,SAAS,EAAS,EACrB,QACA,SACA,cACA,QACA,SACA,UACA,WACe,CACf,OACI,EAsBE,EAtBF,CAAK,cAAc,SAAnB,SAsBE,CArBE,EAAe,EAAf,UAAO,EAAQ,EAOf,EAAC,GAAD,CACI,OAAQ,EACR,OAAQ,EAAM,UACT,IAAgB,OAAY,CAAC,EAAI,CAAE,aAAY,KAC/C,IAAW,GAAO,CAAE,OAAQ,EAAK,EAAI,CAAC,KACtC,IAAY,OAAY,CAAC,EAAI,CAAE,SAAQ,KACvC,IAAY,OAAY,CAAC,EAAI,CAAE,SAAQ,EAChD,EACC,IAAU,OAAY,KACnB,EAGE,EAHF,CAAM,MAAO,EAAM,MAAnB,SAGE,CAFG,EAAM,MACN,GACH,GAER",
|
|
8
|
+
"debugId": "47A7D59412E5C11264756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{u}from"./index-jk0def33.js";var a=" ",i=2;function l(t){let r=t.filter((n)=>n.value!=="");if(r.length===0)return"";let e=Math.max(...r.map((n)=>n.label.length));return r.map((n)=>{let o=`${a}${n.label.padEnd(e)}${" ".repeat(i)}${n.value}`;return n.note===void 0?o:`${o}${" ".repeat(i)}${n.note}`}).join(`
|
|
3
|
+
`)}function m(t,r=!1){return r?t:`
|
|
4
|
+
${t}`}function d(t){return`${a}${u.bullet}${t}`}function c(t,r=2){let e=" ".repeat(r);return t.split(`
|
|
5
|
+
`).map((n)=>n===""?n:`${e}${n}`).join(`
|
|
6
|
+
`)}function pt(t){if(!Number.isFinite(t)||t<0)return"unknown";if(t<1024)return`${Math.round(t)} B`;let r=["KB","MB","GB","TB"],e=t/1024,n=0;while(e>=1024&&n<r.length-1)e/=1024,n+=1;return`${e<10?e.toFixed(1):Math.round(e)} ${r[n]}`}function Qn(t){if(!Number.isFinite(t)||t<0)return"unknown";let r=Math.floor(t/1000);if(r<60)return`${r}s`;let e=Math.floor(r/60);if(e<60)return`${e}m ${r%60}s`;let n=Math.floor(e/60);if(n<24)return`${n}h ${e%60}m`;return`${Math.floor(n/24)}d ${n%24}h`}function mt(t,r){if(r===""||!t.startsWith(r))return t;let e=t.slice(r.length);return e===""?"~":e.startsWith("/")?`~${e}`:t}var f=60000,s=24;function We(t,r){let e=r-Date.parse(t);if(Number.isNaN(e))return t;let n=Math.floor(e/f);if(n<1)return"just now";if(n<60)return`${n}m ago`;let o=Math.floor(n/60);if(o<s)return`${o}h ago`;return`${Math.floor(o/s)}d ago`}
|
|
7
|
+
export{l,m,d,c,pt,Qn,mt,We};
|
|
8
|
+
|
|
9
|
+
//# debugId=D389AFF869B1197D64756E2164756E21
|
|
10
|
+
//# sourceMappingURL=index-mgdgx22q.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lib/render.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * The plain path's shared vocabulary — the half of the house style that never had one.\n *\n * `theme.ts` serves the Ink path. The plain path is most of the binary, and until this file every\n * command that printed a labelled block invented its own: eight hand-rolled `padEnd` widths across\n * seven files (9, 14, `FLAG_COLUMN`, `ENV_COLUMN`, `COMMAND_COLUMN`, and three computed maxima),\n * with `agents.ts` emitting tab-separated columns while everything beside it emitted padded ones.\n * `agents` and `validate` genuinely looked like output from two different products.\n *\n * So this is not a new style — it is the existing one, written down once. A new surface that wants\n * a labelled block, a status word or a byte count reaches here rather than adding a ninth variant.\n *\n * **Pure.** No `node:*`, no `process`, no colour decision. Every function is text in, text out, so\n * it belongs on the boundaries test's `PURE` list and every rendering rule is unit-testable without\n * capturing stdout. Colour is deliberately *not* applied here: the plain path is read as often from\n * a log file as from a terminal, and a module that emitted escape codes would have to know which,\n * which is `resolveMode`'s job and nowhere near a formatter's.\n */\n\nimport { GLYPH } from \"#lib/theme\"\n\n/** Where a labelled block starts, and the space between the widest label and its value. */\nconst INDENT = \" \"\nconst GAP = 2\n\nexport interface Row {\n readonly label: string\n readonly value: string\n /**\n * Trailing text, aligned past the value.\n *\n * Its own field rather than something the caller concatenates, because the interesting rows\n * are the ones carrying a fact *and* its consequence — \"2463 · launchd has restarted this\n * 2463 times\" — and a caller building that by hand loses the alignment on the next row.\n */\n readonly note?: string\n}\n\n/**\n * A labelled block: two-space indent, labels padded to the widest, values aligned.\n *\n * Rows with an empty value are dropped rather than printed blank. A field that does not apply is\n * not the same as a field that is empty, and printing `logs` with nothing after it invites the\n * reader to wonder which one they are looking at.\n */\nexport function keyValue(rows: readonly Row[]): string {\n const shown = rows.filter((row) => row.value !== \"\")\n if (shown.length === 0) return \"\"\n const width = Math.max(...shown.map((row) => row.label.length))\n return shown\n .map((row) => {\n const head = `${INDENT}${row.label.padEnd(width)}${\" \".repeat(GAP)}${row.value}`\n return row.note === undefined ? head : `${head}${\" \".repeat(GAP)}${row.note}`\n })\n .join(\"\\n\")\n}\n\n/** A heading with its own blank line above, unless it opens the output. */\nexport function section(title: string, first = false): string {\n return first ? title : `\\n${title}`\n}\n\nexport function bullet(text: string): string {\n return `${INDENT}${GLYPH.bullet}${text}`\n}\n\n/** Indent a block that was rendered elsewhere — a log tail, a nested report. */\nexport function indent(text: string, depth = 2): string {\n const pad = \" \".repeat(depth)\n return text\n .split(\"\\n\")\n .map((line) => (line === \"\" ? line : `${pad}${line}`))\n .join(\"\\n\")\n}\n\n/**\n * Bytes as a person reads them.\n *\n * Binary units, and the decimal place only below 10 in each unit — `1.2 MB` is worth a digit,\n * `847 MB` is not, and the extra precision only makes a size harder to compare at a glance.\n */\nexport function bytes(count: number): string {\n if (!Number.isFinite(count) || count < 0) return \"unknown\"\n if (count < 1024) return `${Math.round(count)} B`\n const units = [\"KB\", \"MB\", \"GB\", \"TB\"]\n let value = count / 1024\n let unit = 0\n while (value >= 1024 && unit < units.length - 1) {\n value /= 1024\n unit += 1\n }\n return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[unit]}`\n}\n\n/**\n * A span, in the largest two units that carry information.\n *\n * \"3h 12m\" rather than \"3.2 hours\" or \"11520 seconds\": an uptime is read to answer \"since roughly\n * when\", and two units is where that question stops getting better answers.\n */\nexport function duration(ms: number): string {\n if (!Number.isFinite(ms) || ms < 0) return \"unknown\"\n const seconds = Math.floor(ms / 1000)\n if (seconds < 60) return `${seconds}s`\n const minutes = Math.floor(seconds / 60)\n if (minutes < 60) return `${minutes}m ${seconds % 60}s`\n const hours = Math.floor(minutes / 60)\n if (hours < 24) return `${hours}h ${minutes % 60}m`\n return `${Math.floor(hours / 24)}d ${hours % 24}h`\n}\n\n/**\n * `~/…` for a path under home, so a block of paths stays readable at a glance.\n *\n * Takes `home` rather than reading it, because this module is pure — and because the daemon's\n * output has to be able to render a path under a *different* home than the current process's when\n * it is describing a service definition it did not write.\n */\nexport function tildify(path: string, home: string): string {\n if (home === \"\" || !path.startsWith(home)) return path\n const rest = path.slice(home.length)\n return rest === \"\" ? \"~\" : rest.startsWith(\"/\") ? `~${rest}` : path\n}\n\nconst MINUTE_MS = 60_000\nconst HOURS_PER_DAY = 24\n\n/**\n * How long ago, in the shortest honest form.\n *\n * `now` is a parameter rather than a `Date.now()` call, which is what lets this live in a pure module and\n * be shared. It was previously private to `sessions.ts` and read the clock itself, so the session picker\n * would have had to reimplement it — and two renderings of \"how old is this conversation\" that disagree\n * is the drift this module exists to end.\n *\n * An unparseable timestamp is returned as itself. A store row with a bad date is a real thing to see, and\n * \"NaNm ago\" says nothing about it.\n */\nexport function ago(iso: string, now: number): string {\n const ms = now - Date.parse(iso)\n if (Number.isNaN(ms)) return iso\n const mins = Math.floor(ms / MINUTE_MS)\n if (mins < 1) return \"just now\"\n if (mins < 60) return `${mins}m ago`\n const hours = Math.floor(mins / 60)\n if (hours < HOURS_PER_DAY) return `${hours}h ago`\n return `${Math.floor(hours / HOURS_PER_DAY)}d ago`\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";mCAsBA,IAAM,EAAS,KACT,EAAM,EAsBL,SAAS,CAAQ,CAAC,EAA8B,CACnD,IAAM,EAAQ,EAAK,OAAO,CAAC,IAAQ,EAAI,QAAU,EAAE,EACnD,GAAI,EAAM,SAAW,EAAG,MAAO,GAC/B,IAAM,EAAQ,KAAK,IAAI,GAAG,EAAM,IAAI,CAAC,IAAQ,EAAI,MAAM,MAAM,CAAC,EAC9D,OAAO,EACF,IAAI,CAAC,IAAQ,CACV,IAAM,EAAO,GAAG,IAAS,EAAI,MAAM,OAAO,CAAK,IAAI,IAAI,OAAO,CAAG,IAAI,EAAI,QACzE,OAAO,EAAI,OAAS,OAAY,EAAO,GAAG,IAAO,IAAI,OAAO,CAAG,IAAI,EAAI,OAC1E,EACA,KAAK;AAAA,CAAI,EAIX,SAAS,CAAO,CAAC,EAAe,EAAQ,GAAe,CAC1D,OAAO,EAAQ,EAAQ;AAAA,EAAK,IAGzB,SAAS,CAAM,CAAC,EAAsB,CACzC,MAAO,GAAG,IAAS,EAAM,SAAS,IAI/B,SAAS,CAAM,CAAC,EAAc,EAAQ,EAAW,CACpD,IAAM,EAAM,IAAI,OAAO,CAAK,EAC5B,OAAO,EACF,MAAM;AAAA,CAAI,EACV,IAAI,CAAC,IAAU,IAAS,GAAK,EAAO,GAAG,IAAM,GAAO,EACpD,KAAK;AAAA,CAAI,EASX,SAAS,EAAK,CAAC,EAAuB,CACzC,GAAI,CAAC,OAAO,SAAS,CAAK,GAAK,EAAQ,EAAG,MAAO,UACjD,GAAI,EAAQ,KAAM,MAAO,GAAG,KAAK,M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,KAAK,MAAM,EAAQ,CAAa",
|
|
8
|
+
"debugId": "D389AFF869B1197D64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{o,u,R}from"./index-jk0def33.js";import{Box as f,Text as d}from"ink";import{jsxs as r}from"react/jsx-runtime";function ae({items:e,index:n,numbered:t,maxRows:p}){let m=p===void 0?e.length:Math.max(1,p),{from:c,to:x}=R(e.length,n,m),s=e.slice(c,x).map((l,i)=>({at:c+i,item:l}));return r(f,{flexDirection:"column",children:[c>0?r(d,{dimColor:!0,wrap:"truncate",children:[" ",u.ellipsis," ",c," above"]}):null,s.map(({at:l,item:i})=>{let a=l===n,y=t===!0?`${l+1}. `:"";return r(d,{wrap:"truncate",...a?{color:o.accent}:{},children:[a?u.pointer:" ",r(d,{bold:a,children:[y,i.label]}),i.hint===void 0?"":r(d,{dimColor:!0,...a?{color:o.muted}:{},children:[" ",i.hint]})]},`row-${l}`)}),x<e.length?r(d,{dimColor:!0,wrap:"truncate",children:[" ",u.ellipsis," ",e.length-x," below"]}):null]})}function G(e,n){if(e.count===0)return e;let t=e.count-1;switch(n.kind){case"up":return{...e,index:Math.max(0,e.index-1)};case"down":return{...e,index:Math.min(t,e.index+1)};case"first":return{...e,index:0};case"last":return{...e,index:t};case"jump":return n.index<0||n.index>t?e:{...e,index:n.index}}}
|
|
3
|
+
export{ae,G};
|
|
4
|
+
|
|
5
|
+
//# debugId=2E8E37B85694559F64756E2164756E21
|
|
6
|
+
//# sourceMappingURL=index-mrtb5y08.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/components/SelectList.tsx", "../src/lib/select.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * An arrow-key select list: ❯ on the selected row, hints dim, optional numbering.\n *\n * Controlled and presentational — `index` comes from the parent's reducer (`lib/select.ts`), and values\n * stay with the parent, which maps the index back to its own data. This component never listens to input;\n * the screen root owns the single `useInput`.\n *\n * ## Windowing\n *\n * `maxRows` is not decoration. This rendered every item it was given, which was fine for a sandbox of\n * three agents and is not fine for a store with fifty conversations: on the alternate screen a list taller\n * than the terminal pushes the frame apart, and there is no scrollback to recover it from. It windows\n * through `viewport` — the same function the composer and the catalogue use, because \"keep the selected\n * row visible\" is one rule and not three.\n *\n * Numbering stays **absolute** while windowed. A digit jumps the cursor by absolute index, so numbering\n * the visible rows 1..n would make `3` mean a different row depending on where the window sat. The\n * consequence, stated: digits reach the first nine rows and the arrows reach the rest.\n */\n\nimport { Box, Text } from \"ink\"\nimport { viewport } from \"#lib/rows\"\nimport { GLYPH, THEME } from \"#lib/theme\"\n\nexport interface SelectItem {\n readonly label: string\n /** Dim, after the label — a model id, a relative time, a one-line description. */\n readonly hint?: string\n}\n\nexport interface SelectListProps {\n readonly items: readonly SelectItem[]\n readonly index: number\n /** `1.`-style prefixes; digits then jump the cursor (they never choose). */\n readonly numbered?: boolean\n /** Visible rows before the list scrolls to follow the selection. Unbounded when omitted. */\n readonly maxRows?: number\n}\n\nexport function SelectList({ items, index, numbered, maxRows }: SelectListProps) {\n const window = maxRows === undefined ? items.length : Math.max(1, maxRows)\n const { from, to } = viewport(items.length, index, window)\n // Absolute row numbers computed before the map, so a React key is a position rather than a callback\n // index — and so the printed number does not change when the window moves.\n const visible = items.slice(from, to).map((item, offset) => ({ at: from + offset, item }))\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 {visible.map(({ at, item }) => {\n const selected = at === index\n const number = numbered === true ? `${at + 1}. ` : \"\"\n return (\n // `wrap=\"truncate\"` is the backstop, not the layout: a row wider than the frame\n // otherwise wraps onto a continuation line carrying no pointer and no number,\n // which reads as an extra list item. Label before hint, so what clips is the\n // reason rather than the thing being named.\n <Text\n key={`row-${at}`}\n wrap=\"truncate\"\n {...(selected ? { color: THEME.accent } : {})}\n >\n {selected ? GLYPH.pointer : \" \"}\n <Text bold={selected}>\n {number}\n {item.label}\n </Text>\n {item.hint === undefined ? (\n \"\"\n ) : (\n <Text dimColor {...(selected ? { color: THEME.muted } : {})}>\n {\" \"}\n {item.hint}\n </Text>\n )}\n </Text>\n )\n })}\n {to < items.length ? (\n <Text dimColor wrap=\"truncate\">\n {\" \"}\n {GLYPH.ellipsis} {items.length - to} below\n </Text>\n ) : null}\n </Box>\n )\n}\n",
|
|
6
|
+
"/**\n * List-cursor state: an index and the moves that change it. Pure, like every reducer here.\n */\n\nexport interface SelectState {\n readonly index: number\n readonly count: number\n}\n\nexport type SelectMove =\n | { readonly kind: \"up\" }\n | { readonly kind: \"down\" }\n | { readonly kind: \"first\" }\n | { readonly kind: \"last\" }\n /** 0-based. A digit key jumps the cursor — visibly and reversibly; it never chooses. */\n | { readonly kind: \"jump\"; readonly index: number }\n\nexport function moveSelect(state: SelectState, move: SelectMove): SelectState {\n if (state.count === 0) return state\n const last = state.count - 1\n switch (move.kind) {\n case \"up\":\n return { ...state, index: Math.max(0, state.index - 1) }\n case \"down\":\n return { ...state, index: Math.min(last, state.index + 1) }\n case \"first\":\n return { ...state, index: 0 }\n case \"last\":\n return { ...state, index: last }\n case \"jump\":\n return move.index < 0 || move.index > last ? state : { ...state, index: move.index }\n }\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";uCAoBA,cAAS,UAAK,qDAmBP,SAAS,EAAU,EAAG,QAAO,QAAO,WAAU,WAA4B,CAC7E,IAAM,EAAS,IAAY,OAAY,EAAM,OAAS,KAAK,IAAI,EAAG,CAAO,GACjE,OAAM,MAAO,EAAS,EAAM,OAAQ,EAAO,CAAM,EAGnD,EAAU,EAAM,MAAM,EAAM,CAAE,EAAE,IAAI,CAAC,EAAM,KAAY,CAAE,GAAI,EAAO,EAAQ,MAAK,EAAE,EAEzF,OACI,EA0CE,E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694559F64756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var qo="\x1B[?25h",vn="\x1B[0m",Go="\x1B[2m",we="\x1B[?1049h",Zo="\x1B[?1049l",Vo="\x1B[<u",U=80,kn=24,rr=12,Sn="› ",xn=40,En=140,qe=8,Ge=40,Ze=8,Yo=200,Ar=100,Tn=10,Xo=4,Jo=6,_n=3,Qo=2000,$n=50,es=1,n=0,s=1,ts=143;var ns=3,rs=22,os=8,ss=400,or=1,Ft=12,is=300,as=2000;
|
|
3
|
+
export{qo,vn,Go,we,Zo,Vo,U,kn,rr,Sn,xn,En,qe,Ge,Ze,Yo,Ar,Tn,Xo,Jo,_n,Qo,$n,es,n,s,ts,ns,rs,os,ss,or,Ft,is,as};
|
|
4
|
+
|
|
5
|
+
//# debugId=F0E3ABC713795DF964756E2164756E21
|
|
6
|
+
//# sourceMappingURL=index-my5cjx00.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lib/const.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Every constant the CLI uses, in one place.\n *\n * The rule is the one termheat follows: no magic number inline. A width, a limit, or a control\n * sequence buried in a component is invisible to anyone tuning behaviour later, and two copies of\n * the same number drift.\n */\n\n// ─── terminal ────────────────────────────────────────────────────────────────────────────\n\nexport const SHOW_CURSOR = \"\\u001B[?25h\"\nexport const RESET_STYLE = \"\\u001B[0m\"\n/**\n * Faint text, for the one thing written outside Ink that is not the point of the output.\n *\n * SGR 2 rather than a grey foreground: a fixed colour is wrong on half the terminals in existence,\n * and dim is the terminal's own opinion about what recedes on the theme in use. It persists across a\n * newline, so a multi-line note opens it once and resets once — and the reset lands before the final\n * newline, or the shell prompt that follows inherits it.\n */\nexport const DIM_STYLE = \"\\u001B[2m\"\n\n/**\n * The alternate screen buffer — a second, empty screen the terminal swaps in, discards on the way\n * out, and never adds to the scrollback.\n *\n * `1049` rather than the older `47`: it saves the cursor position and clears the new buffer in one\n * sequence, which is what lands the shell prompt back where it was rather than wherever the app left\n * the cursor.\n *\n * The order on the way out is easy to get backwards. A style reset applies to whichever buffer is\n * *current*, so it has to be written before the swap away — reset afterwards and any colour the app\n * left on lands on the shell's screen instead of the one being discarded. `restoreTerminal` does them\n * in that order and says so there too.\n */\nexport const ENTER_ALT_SCREEN = \"\\u001B[?1049h\"\nexport const LEAVE_ALT_SCREEN = \"\\u001B[?1049l\"\n\n/**\n * Pop the kitty keyboard protocol: `CSI < u`, the counterpart to the `CSI > flags u` Ink pushes.\n *\n * Here rather than in `lib/keyboard.ts` so the dependency runs one way — `lib/exit.ts` needs the\n * sequence and `lib/keyboard.ts` needs `markEnhancedKeys`, and only one of those two can import the\n * other. Terminal-mode sequences already live in this module, which makes this the side that moves.\n */\nexport const DISABLE_ENHANCED_KEYS = \"\\u001B[<u\"\n\n/**\n * Fallback width. A pty can genuinely report `columns === 0` — measured, under `script -q`, which\n * is how this repo drives a real TTY in a test harness. Any layout maths that divides by the\n * terminal width has to survive that.\n */\nexport const FALLBACK_COLUMNS = 80\nexport const FALLBACK_ROWS = 24\n\n/**\n * Rows the live pane may occupy before it starts showing only its tail.\n *\n * Ink erases and redraws its whole dynamic tree every frame, so an unbounded live region means\n * redrawing hundreds of lines per token. Finished messages move into `<Static>`, which is written\n * once and never touched again; this cap is what keeps the *unfinished* one cheap.\n */\nexport const LIVE_PANE_MAX_ROWS = 12\n\nexport const PROMPT = \"› \"\n\n/**\n * The width a screen is laid out for, clamped at both ends.\n *\n * The floor is where the row layout drops its description column rather than wrapping — below it\n * nothing sensible is possible, and a wrapped row is what made the first skills list unreadable. The\n * ceiling stops a 300-column window putting a description a screen away from the name it belongs to.\n *\n * Here rather than in the one command that first needed them, because every screen now shares a frame\n * and two screens clamping differently is the drift `render.ts` was written to end.\n */\nexport const MIN_SCREEN_COLUMNS = 40\nexport const MAX_SCREEN_COLUMNS = 140\n\n/** Rows a scrolling list may occupy, before and after the frame takes its share. */\nexport const MIN_SCREEN_ROWS = 8\nexport const MAX_SCREEN_ROWS = 40\n/** Header, footer, margins and the counter — what the frame costs a list. */\nexport const SCREEN_CHROME_ROWS = 8\n\n// ─── commands and input ──────────────────────────────────────────────────────────────────\n\n// The command words themselves live in `session-commands.ts`, beside the summary that documents\n// each one and the dispatch that honours it. Three bare string constants here is how the help text\n// and the parser came to disagree in the first place.\n\n/** Lines of input history kept for the up/down arrows. */\nexport const HISTORY_LIMIT = 200\n\n/**\n * Undo points kept for the input buffer.\n *\n * Bounded because a snapshot holds a whole copy of the text, and a long composing session with a\n * pasted document in it would otherwise keep every intermediate version alive for the life of the\n * process. A run of typing is one point, not one per keystroke, so this is deeper than it looks.\n */\nexport const UNDO_LIMIT = 100\n\n/**\n * Rows the input box may grow to before it scrolls internally.\n *\n * The same reasoning as `LIVE_PANE_MAX_ROWS`: the input is in Ink's dynamic region, which is erased and\n * redrawn every frame, so an unbounded box means redrawing a pasted document on every keystroke. It\n * also stops a long paste pushing the conversation off the screen.\n */\nexport const MAX_INPUT_ROWS = 10\n\n/**\n * Rows of a reasoning block shown before it folds to a count.\n *\n * Reasoning is secondary and routinely the longest item in a conversation — a real turn produced a\n * twenty-three-row block for a one-sentence answer, which filled a thirty-row terminal on its own and made\n * the reply itself something you had to scroll to find. Four rows is enough to see what it was thinking\n * about; `⌥r` shows the rest.\n *\n * Folding is a *view* decision, applied when items become rows. The whole text is always in the item, so\n * expanding needs no re-derivation and nothing is lost.\n */\nexport const REASONING_FOLD_ROWS = 4\n\n/** Matches `^R` shows at once. Enough to recognise one, few enough to leave the prompt on screen. */\nexport const SEARCH_ROWS = 6\n\n/**\n * Rows a single-value field may wrap to before it scrolls to follow the caret.\n *\n * Smaller than `MAX_INPUT_ROWS`, because a *value* is not a message: a wizard answer and a manifest\n * setting are one line of intent that happens to be long. Three is enough for the longest thing a\n * generated manifest holds — `tools.pinned` at 92 characters is two rows on an 80-column terminal — and\n * few enough that the field never pushes the rest of the screen around.\n *\n * There was no bound at all before, because the field passed no width: in the settings editor a long\n * value was clipped at the terminal's edge with the caret past the clip, and you could not see what you\n * were typing. The wizard escaped it — a bordered box bounds its text whatever the field passes.\n */\nexport const FIELD_ROWS = 3\n\n/**\n * Transcript items kept before the oldest are dropped.\n *\n * Load-bearing rather than prudent, and it was missing for three phases. While the conversation lived\n * in `<Static>` a finished item was written once and cost nothing afterwards; the alternate screen took\n * that away, so every item is now re-derived and re-wrapped on every frame — an unbounded buffer means\n * unbounded work per keystroke, and the case that reaches it is an agent looping tool calls overnight\n * rather than anybody typing.\n *\n * Counted in **items**, not rows, because the row count depends on the terminal width and the reducer\n * that owns the buffer is pure and has none. That does not contradict the scroll layer's rule that the\n * unit is a row: that rule is about addressing an *offset*, where paging by item steps over a forty-row\n * reply in one keystroke.\n *\n * Deliberately far past any session a person reads end to end — roughly four hundred turns — so the cap\n * is a backstop nobody meets rather than a limit that shapes ordinary use. Eviction is also gated on the\n * reader following the tail; see `TRIM` in `transcript.ts` for why that gate is not optional.\n */\nexport const MAX_TRANSCRIPT_ITEMS = 2000\n\n// ─── defaults ────────────────────────────────────────────────────────────────────────────\n\nexport const DEFAULT_ROW_LIMIT = 50\nexport const MIN_ROW_LIMIT = 1\n\n// ─── exit codes ──────────────────────────────────────────────────────────────────────────\n\nexport const EXIT_OK = 0\nexport const EXIT_FAILURE = 1\n/** 128 + SIGTERM, the shell convention. */\nexport const EXIT_SIGTERM = 143\n\n/** Rows a pane over the conversation may use — a command's output, or a hosted view. */\nexport const PANE_ROWS = 16\n\n/**\n * The fewest rows a scrolling body is ever given.\n *\n * A floor rather than a target. At eight terminal rows the chrome alone — header, composer, status —\n * accounts for most of the screen, and the alternative to a floor is a body of zero rows: a session\n * that shows the prompt and no conversation at all, which reads as a broken renderer rather than as a\n * window somebody should make taller.\n */\nexport const MIN_BODY_ROWS = 3\n\n/**\n * Rows a list may take while landing — before anything has been sent.\n *\n * Deliberately larger than `SEARCH_ROWS`, which is tuned for a live conversation where every row of list is a\n * row of conversation hidden. There is no conversation yet on the landing screen and its whole job is\n * discovery: showing six of fifteen commands behind a `… 9 below` is the wrong trade on the screen somebody\n * opens before they know what the commands are. The brand mark gives up a tier to pay for it, which the tier\n * ladder already knows how to do.\n *\n * **This tracks the size of the in-session command table**, so a phase that adds a command has to raise it —\n * which is why `commands.test.ts` asserts the relationship rather than leaving it to whoever notices the\n * `… 1 below`. It is not derived from `COMMANDS` directly because `commands.ts` reads this module, and the\n * cycle would cost more than the assertion does.\n */\nexport const LANDING_LIST_ROWS = 22\n\n/**\n * Rows of conversation the landing screen keeps, whatever the brand mark would like.\n *\n * The banner is written into the transcript, so a wordmark that squeezed it to nothing would hide the boot\n * notes and every load warning behind a picture — which is the trimmed-catalogue failure with better\n * typography: true of what is on screen, false of what is the case.\n *\n * Eight rather than four, measured against a real banner: four left the window showing the *tail* of it, so\n * the first thing on screen was the second half of a wrapped store path. The banner runs six to eight rows\n * depending on how many load warnings there are.\n */\nexport const MIN_LANDING_TRANSCRIPT = 8\n\n/**\n * How long after a press a second one still counts as a double-click.\n *\n * A terminal reports three presses and never a \"double click\", so the grouping is ours to infer — from time\n * *and* position, because two clicks 300 ms apart on different words are two clicks. 400 ms is the common\n * platform default; longer makes a deliberate second selection turn into a word-select, shorter makes a\n * real double-click fail on a slow hand.\n */\nexport const MULTI_CLICK_MS = 400\n\n/** The blank row between the brand mark and the one-line header under it. */\nexport const BRAND_GAP_ROWS = 1\n\n/** Conversations the session picker shows at once. The list scrolls inside this. */\nexport const SESSION_PICKER_ROWS = 12\n\n/**\n * How often `daemon logs --follow` checks a service log for new bytes.\n *\n * Polled rather than watched: `fs.watch` on macOS reports another process's appends unreliably, and a\n * follower that misses the line somebody is waiting for is worse than one that arrives a third of a\n * second late — the reason to watch a log live is not trusting what you have been told. Ctrl-C wakes the\n * pending sleep rather than waiting it out, so this interval never delays a stop.\n */\nexport const LOG_POLL_MS = 300\n\n/**\n * How long a ^C at an idle prompt stays armed.\n *\n * The chord is doubled rather than immediate because a single ^C means \"cancel the turn\" everywhere\n * else in this session, and the two are one keystroke apart. Long enough to be a deliberate second\n * press, short enough that an armed prompt left alone goes back to being safe.\n */\nexport const EXIT_ARM_MS = 2000\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAUO,IAAM,GAAc,YACd,GAAc,UASd,GAAY,UAeZ,GAAmB,cACnB,GAAmB,cASnB,GAAwB,UAOxB,EAAmB,GACnB,GAAgB,GAShB,GAAqB,GAErB,GAAS,KAYT,GAAqB,GACrB,GAAqB,IAGrB,GAAkB,EAClB,GAAkB,GAElB,GAAqB,EASrB,GAAgB,IAShB,GAAa,IASb,GAAiB,GAajB,GAAsB,EAGtB,GAAc,EAcd,GAAa,EAoBb,GAAuB,KAIvB,GAAoB,GACpB,GAAgB,EAIhB,EAAU,EACV,EAAe,EAEf,GAAe,IAarB,IAAM,GAAgB,EAgBhB,GAAoB,GAapB,GAAyB,EAUzB,GAAiB,IAGjB,GAAiB,EAGjB,GAAsB,GAUtB,GAAc,IASd,GAAc",
|
|
8
|
+
"debugId": "F0E3ABC713795DF964756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var y=[[4352,4447],[11904,12350],[12353,13311],[13312,19903],[19968,40959],[40960,42191],[43360,43391],[44032,55203],[63744,64255],[65040,65049],[65072,65135],[65280,65376],[65504,65510],[127744,128591],[128640,128767],[129280,129535],[129648,129791],[131072,196605],[196608,262141]],w=[[768,879],[1155,1161],[1425,1469],[1552,1562],[1611,1631],[1648,1648],[1750,1756],[2304,2307],[2362,2362],[3633,3633],[3636,3642],[6832,6911],[7616,7679],[8203,8207],[8400,8447],[65024,65039],[65056,65071],[65279,65279]];function m(n,t){for(let[f,e]of t){if(n<f)return!1;if(n<=e)return!0}return!1}function W(n){if(n<32||n>=127&&n<160)return 0;if(m(n,w))return 0;if(m(n,y))return 2;return 1}function g(n){return n.map((t)=>W(t.codePointAt(0)??0))}var T=" ".repeat(8);function pn(n,t){let f=n.replaceAll("\t",T),e=[...f],s=g(e),b=(x,u)=>{let r=0;for(let l=x;l<u;l+=1)r+=s[l]??0;return r};if(t<=0||b(0,e.length)<=t)return[{text:f,lead:0,from:0,to:e.length}];let o=0;while(o<e.length&&(e[o]===" "||e[o]===" "))o+=1;if(o>0){let x=e.slice(o).join("");if(o>=t)return pn(x,t).map((r)=>({...r,from:r.from+o,to:r.to+o}));let u=" ".repeat(o);return pn(x,t-o).map((r)=>({text:`${u}${r.text}`,lead:r.lead+o,from:r.from+o,to:r.to+o}))}let h=[],d=0,i=0,p=(x)=>{h.push({text:e.slice(d,x).join(""),lead:0,from:d,to:x})},a=0;while(a<=e.length){let x=a;while(x<e.length&&e[x]!==" ")x+=1;let u=b(a,x);if(u>t){if(i>0)p(a===d?a:a-1),d=a,i=0;let r=a;while(b(r,x)>t){let l=r,c=0;while(l<x&&c+(s[l]??0)<=t)c+=s[l]??0,l+=1;if(l===r)l=r+1;d=r,p(l),r=l,d=r}d=r,i=b(r,x)}else if(i>0&&i+1+u>t)p(a-1),d=a,i=u;else i=i===0?u:i+1+u;if(x>=e.length)break;a=x+1}return p(e.length),h}function A(n,t){return pn(n,t).map((f)=>f.text)}function Co(n,t){let f=0;for(let[e,s]of[...n].entries()){if(e>=t)break;f+=s==="\t"?8:1}return f}function er(n,t){return n.split(`
|
|
3
|
+
`).flatMap((f)=>A(f,t))}function tr(n,t,f){if(n===""||f<=0)return{lines:[],rows:0,hidden:0};let e=er(n,t);if(e.length<=f)return{lines:e,rows:e.length,hidden:0};return{lines:e.slice(e.length-f),rows:f+1,hidden:e.length-f}}
|
|
4
|
+
export{pn,Co,er,tr};
|
|
5
|
+
|
|
6
|
+
//# debugId=A499DA0C109C695064756E2164756E21
|
|
7
|
+
//# sourceMappingURL=index-qc2vrq9z.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lib/width.ts", "../src/lib/wrap.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * How many terminal columns a string occupies.\n *\n * ## Why this exists\n *\n * `lib/wrap.ts` measured in **code points** and there was no width function anywhere in the CLI. An emoji\n * is one code point and two columns, so `\"👍\".repeat(10)` measured 10 and drew 20 — and every cap built on\n * that measurement was short. Short by a row on the alternate screen is a frame taller than the terminal,\n * which scrolls the buffer and leaves the status line halfway up the display: the exact corruption\n * `lib/wrap.ts` was written to prevent, still reachable through the one input it could not measure.\n *\n * It became urgent with mouse selection, where a column has to map back to a character. A drag that grabs\n * the wrong text on any line containing an emoji is the \"looks right and isn't\" failure this repo avoids.\n *\n * ## What it is, and what it is not\n *\n * A range table, not a dependency — the same call `SPINNER_FRAMES` makes, and for the same reason: this is\n * a handful of comparisons against data that changes once a year, and a package would be a supply chain.\n *\n * It is **not** full UAX #11, and the gap is stated rather than discovered. Width is defined per code\n * point, so a grapheme cluster built from several — a ZWJ family emoji, a flag pair, a letter with two\n * combining marks — is measured by summing its parts. Zero-width joiners and variation selectors count as\n * zero, which makes the common cases right; a flag (two regional indicators, four columns by this count,\n * two on screen) is over-measured, and over-measuring wraps early rather than overflowing. That is the\n * direction to be wrong in, and it is why this rounds up rather than down.\n */\n\n/** Ranges whose code points occupy two columns: East Asian Wide and Fullwidth, plus emoji. */\nconst WIDE: readonly (readonly [number, number])[] = [\n [0x1100, 0x115f], // Hangul Jamo initial consonants\n [0x2e80, 0x303e], // CJK radicals, Kangxi, CJK symbols\n [0x3041, 0x33ff], // Hiragana, Katakana, Bopomofo, Hangul Compatibility Jamo, CJK compat\n [0x3400, 0x4dbf], // CJK Unified Extension A\n [0x4e00, 0x9fff], // CJK Unified\n [0xa000, 0xa4cf], // Yi\n [0xa960, 0xa97f], // Hangul Jamo Extended-A\n [0xac00, 0xd7a3], // Hangul syllables\n [0xf900, 0xfaff], // CJK compatibility ideographs\n [0xfe10, 0xfe19], // vertical forms\n [0xfe30, 0xfe6f], // CJK compatibility forms, small form variants\n [0xff00, 0xff60], // fullwidth forms\n [0xffe0, 0xffe6], // fullwidth signs\n [0x1f300, 0x1f64f], // pictographs and emoticons\n [0x1f680, 0x1f6ff], // transport and map symbols\n [0x1f900, 0x1f9ff], // supplemental symbols and pictographs\n [0x1fa70, 0x1faff], // symbols extended-A\n [0x20000, 0x2fffd], // CJK Unified Extension B and beyond\n [0x30000, 0x3fffd],\n]\n\n/** Ranges that occupy no columns of their own: combining marks, joiners, variation selectors. */\nconst ZERO: readonly (readonly [number, number])[] = [\n [0x0300, 0x036f], // combining diacritical marks\n [0x0483, 0x0489],\n [0x0591, 0x05bd],\n [0x0610, 0x061a],\n [0x064b, 0x065f],\n [0x0670, 0x0670],\n [0x06d6, 0x06dc],\n [0x0900, 0x0903],\n [0x093a, 0x093a],\n [0x0e31, 0x0e31],\n [0x0e34, 0x0e3a],\n [0x1ab0, 0x1aff], // combining diacritical marks extended\n [0x1dc0, 0x1dff], // combining diacritical marks supplement\n [0x200b, 0x200f], // zero-width space, ZWNJ, ZWJ, LRM, RLM\n [0x20d0, 0x20ff], // combining marks for symbols\n [0xfe00, 0xfe0f], // variation selectors\n [0xfe20, 0xfe2f], // combining half marks\n [0xfeff, 0xfeff], // byte-order mark\n]\n\nfunction within(code: number, ranges: readonly (readonly [number, number])[]): boolean {\n // Linear, because the tables are short and this runs per code point on the wrapping path. A binary\n // search over twenty entries is not measurably faster and is one more thing to get wrong.\n for (const [low, high] of ranges) {\n if (code < low) return false\n if (code <= high) return true\n }\n return false\n}\n\n/**\n * Columns one code point occupies: 0, 1, or 2.\n *\n * A C0 control counts as zero. They should never reach a measured string — `wrap.ts` expands tabs and\n * `printableOnly` strips the rest — so this is a floor rather than a feature: counting an escape byte as a\n * column would make every row containing one wrap early, which is harder to spot than it sounds.\n */\nexport function charWidth(code: number): number {\n if (code < 0x20 || (code >= 0x7f && code < 0xa0)) return 0\n if (within(code, ZERO)) return 0\n if (within(code, WIDE)) return 2\n return 1\n}\n\n/** Columns a string occupies, summed per code point. */\nexport function textWidth(text: string): number {\n let total = 0\n for (const char of text) total += charWidth(char.codePointAt(0) ?? 0)\n return total\n}\n\n/** Per-code-point widths of `cells`, for a caller that walks a line and needs each one. */\nexport function cellWidths(cells: readonly string[]): readonly number[] {\n return cells.map((cell) => charWidth(cell.codePointAt(0) ?? 0))\n}\n",
|
|
6
|
+
"/**\n * Breaking text into the rows a fixed-width window will draw.\n *\n * ## One wrapping, ours\n *\n * This module used to count rows the way a terminal does — divide the character count by the width — and\n * hand the text to Ink to wrap. Those are two different answers to one question, and the difference is not\n * academic: Ink breaks at spaces, so 240 characters at 80 columns is **four** rows to Ink and three to a\n * division. Every cap built on the division was therefore one row short of what appeared on screen, which\n * on the alternate buffer is a frame taller than the terminal.\n *\n * So the rule is that whoever owns a bounded window wraps the text itself and renders each row with\n * `wrap=\"truncate\"`. The count is then the count, by construction, and a frame test asserts it against a\n * real render rather than trusting the arithmetic.\n *\n * Tabs are expanded to spaces on the way through. A tab's width is the terminal's business and not ours,\n * so a row containing one cannot be measured — expanding it is the only way the number we counted is the\n * number drawn. It changes bytes, never meaning, which is the line decision 4.27 draws.\n */\n\nconst TAB_WIDTH = 8\nconst TAB = \" \".repeat(TAB_WIDTH)\n\nimport { cellWidths } from \"#lib/width\"\n\n/**\n * One drawn row, and which source characters it drew.\n *\n * The offsets exist because a row's text is **not** a slice of its line. Breaking at a space consumes\n * the space, a word longer than the window is cut, and a hanging indent is re-applied to rows that never\n * contained it — so \"which row is source offset 41 on, and at what column\" cannot be recovered from the\n * strings afterwards. Anything that draws a caret over wrapped text needs exactly that, and computing it\n * a second time from the finished rows is how a cursor ends up a column out on the lines that wrapped.\n */\nexport interface WrappedRow {\n /** Exactly what is painted, the re-applied indent included. */\n readonly text: string\n /** Columns of `text` that are indent. A caret never lands to the left of this. */\n readonly lead: number\n /** Source code-point offset of this row's first drawn character. */\n readonly from: number\n /** One past this row's last drawn character. A break at a space leaves a gap before the next `from`. */\n readonly to: number\n}\n\n/**\n * One logical line, broken at spaces to fit `columns`, with the source offsets kept.\n *\n * A word longer than the whole width is cut rather than allowed to overflow — a URL or a base64 blob is\n * the normal case for that, and there is nowhere better to break it. Returns one row for an empty line,\n * because a blank line in a reply is a blank row on screen and dropping it would close up paragraphs the\n * model deliberately separated.\n */\nexport function wrapRows(line: string, columns: number): readonly WrappedRow[] {\n // Tabs are expanded before anything is measured, so offsets are into the *expanded* line. A caller\n // placing a caret has to expand its own column the same way, which `expandColumn` is for.\n const flat = line.replaceAll(\"\\t\", TAB)\n const all = [...flat]\n // Widths per cell, computed once. Every measurement below is a sum over this rather than a count of\n // code points: an emoji is one code point and two columns, so counting made `\"👍\".repeat(10)` measure\n // ten and draw twenty. Offsets stay in code points, because that is what a caller slices with.\n const w = cellWidths(all)\n const span = (from: number, to: number): number => {\n let total = 0\n for (let at = from; at < to; at += 1) total += w[at] ?? 0\n return total\n }\n if (columns <= 0 || span(0, all.length) <= columns) {\n return [{ text: flat, lead: 0, from: 0, to: all.length }]\n }\n\n // Leading whitespace is structure, and splitting on spaces destroys it.\n //\n // Found live: `/help`'s output indents each entry by two spaces, and every line short enough to fit kept\n // them while every line that wrapped lost them — so one list came out at two different indents depending\n // on how long each summary happened to be. Held aside here and re-applied to every row, which also gives\n // a wrapped indented block a hanging indent rather than a ragged left edge.\n let indent = 0\n while (indent < all.length && (all[indent] === \" \" || all[indent] === \"\\u00a0\")) indent += 1\n if (indent > 0) {\n const body = all.slice(indent).join(\"\")\n // An indent as wide as the window is dropped rather than honoured: keeping it would leave no room\n // for the text, and shrinking the width to fit it recurses forever. The recursion terminates either\n // way, because `body` cannot begin with a space.\n if (indent >= columns) {\n return wrapRows(body, columns).map((row) => ({\n ...row,\n from: row.from + indent,\n to: row.to + indent,\n }))\n }\n const pad = \" \".repeat(indent)\n return wrapRows(body, columns - indent).map((row) => ({\n text: `${pad}${row.text}`,\n lead: row.lead + indent,\n from: row.from + indent,\n to: row.to + indent,\n }))\n }\n\n const rows: WrappedRow[] = []\n // `at` is where the pending row starts in the source; `width` is how much of it is drawn so far.\n let at = 0\n let width = 0\n const push = (to: number) => {\n rows.push({ text: all.slice(at, to).join(\"\"), lead: 0, from: at, to })\n }\n let cursor = 0\n while (cursor <= all.length) {\n // The next word, and the single space that introduced it. A run of spaces is not collapsed —\n // only the one space a break consumes is, which is what keeps the offsets honest.\n let end = cursor\n while (end < all.length && all[end] !== \" \") end += 1\n const word = span(cursor, end)\n\n if (word > columns) {\n // Longer than any row can hold. Flush what is pending, then cut it into full rows.\n if (width > 0) {\n push(cursor === at ? cursor : cursor - 1)\n at = cursor\n width = 0\n }\n let take = cursor\n while (span(take, end) > columns) {\n // Advance by *columns*, not by cells. A cut that would land inside a double-width\n // character stops before it, which is why the row can come out one column short: half an\n // emoji is not a thing a terminal can draw, and drawing it anyway is how a row overflows.\n let stop = take\n let filled = 0\n while (stop < end && filled + (w[stop] ?? 0) <= columns) {\n filled += w[stop] ?? 0\n stop += 1\n }\n // A single character wider than the whole window would otherwise loop forever taking\n // nothing. Emit it alone and overflow by one column, which is the only option left.\n if (stop === take) stop = take + 1\n at = take\n push(stop)\n take = stop\n at = take\n }\n at = take\n width = span(take, end)\n } else if (width > 0 && width + 1 + word > columns) {\n // Does not fit beside what is already on this row. The space before it is the break and is\n // drawn by neither row, which is why `to` and the next `from` are not the same number.\n push(cursor - 1)\n at = cursor\n width = word\n } else {\n width = width === 0 ? word : width + 1 + word\n }\n\n if (end >= all.length) break\n cursor = end + 1\n }\n push(all.length)\n return rows\n}\n\nfunction wrapLine(line: string, columns: number): readonly string[] {\n return wrapRows(line, columns).map((row) => row.text)\n}\n\n/** A code-point column in `line` translated into the tab-expanded coordinates `wrapRows` reports. */\nexport function expandColumn(line: string, column: number): number {\n let out = 0\n for (const [at, ch] of [...line].entries()) {\n if (at >= column) break\n out += ch === \"\\t\" ? TAB_WIDTH : 1\n }\n return out\n}\n\n/** Every row `text` occupies at `columns`, newlines respected and long lines broken. */\nexport function wrapText(text: string, columns: number): readonly string[] {\n return text.split(\"\\n\").flatMap((line) => wrapLine(line, columns))\n}\n\n/**\n * The live pane: the rows to draw, how tall that makes it, and how much was dropped.\n *\n * Height-capped on purpose. Ink erases and redraws its whole dynamic tree per frame, so an uncapped pane\n * means redrawing the entire reply on every token — a cost that grows with the length of the answer,\n * precisely when the terminal is busiest. The newest rows are the ones kept, because they are what the\n * reader is looking at, and nothing is lost: the finished reply joins the transcript at `turn.end`.\n *\n * All three numbers from one wrap, because they were computed separately and disagreed. The component\n * needs the rows and the dropped count; the chat frame needs the height to subtract from the terminal\n * *before* the pane renders. Deriving them apart meant the notice's own row was counted by one caller and\n * not the other, which is a layout one row taller than the screen.\n */\nexport interface LivePane {\n /** What to draw, newest last. Already wrapped, so each is one row. */\n readonly lines: readonly string[]\n /** Rows the pane occupies, the \"… n hidden\" notice included. Zero when there is nothing to show. */\n readonly rows: number\n /** Rows dropped off the top. Non-zero is exactly the condition for drawing the notice. */\n readonly hidden: number\n}\n\nexport function livePane(text: string, columns: number, maxRows: number): LivePane {\n if (text === \"\" || maxRows <= 0) return { lines: [], rows: 0, hidden: 0 }\n const all = wrapText(text, columns)\n if (all.length <= maxRows) return { lines: all, rows: all.length, hidden: 0 }\n // The extra row is the notice itself.\n return {\n lines: all.slice(all.length - maxRows),\n rows: maxRows + 1,\n hidden: all.length - maxRows,\n }\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";AA4BA,IAAM,EAA+C,CACjD,CAAC,KAAQ,IAAM,EACf,CAAC,MAAQ,KAAM,EACf,CAAC,MAAQ,KAAM,EACf,CAAC,MAAQ,KAAM,EACf,CAAC,MAAQ,KAAM,EACf,CAAC,MAAQ,KAAM,EACf,CAAC,MAAQ,KAAM,EACf,CAAC,MAAQ,KAAM,EACf,CAAC,MAAQ,KAAM,EACf,CAAC,MAAQ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