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.
Files changed (346) hide show
  1. package/README.md +596 -0
  2. package/dist/App-dxqm39zx.js +11 -0
  3. package/dist/App-dxqm39zx.js.map +25 -0
  4. package/dist/ConfigEditor-7v5nebvy.js +6 -0
  5. package/dist/ConfigEditor-7v5nebvy.js.map +11 -0
  6. package/dist/KeyProbe-vjhmdpx6.js +5 -0
  7. package/dist/KeyProbe-vjhmdpx6.js.map +11 -0
  8. package/dist/Picker-jxaesaxy.js +5 -0
  9. package/dist/Picker-jxaesaxy.js.map +10 -0
  10. package/dist/SessionPicker-z2t0p4b5.js +5 -0
  11. package/dist/SessionPicker-z2t0p4b5.js.map +11 -0
  12. package/dist/SkillBrowser-yyf2gy0q.js +5 -0
  13. package/dist/SkillBrowser-yyf2gy0q.js.map +11 -0
  14. package/dist/WizardApp-12ndxgqv.js +5 -0
  15. package/dist/WizardApp-12ndxgqv.js.map +13 -0
  16. package/dist/agents.d.ts +9 -0
  17. package/dist/agents.d.ts.map +1 -0
  18. package/dist/browse.d.ts +63 -0
  19. package/dist/browse.d.ts.map +1 -0
  20. package/dist/client.d.ts +25 -0
  21. package/dist/client.d.ts.map +1 -0
  22. package/dist/client.js +34 -0
  23. package/dist/client.js.map +11 -0
  24. package/dist/components/App.d.ts +28 -0
  25. package/dist/components/App.d.ts.map +1 -0
  26. package/dist/components/Banner.d.ts +16 -0
  27. package/dist/components/Banner.d.ts.map +1 -0
  28. package/dist/components/Brandmark.d.ts +31 -0
  29. package/dist/components/Brandmark.d.ts.map +1 -0
  30. package/dist/components/CheckList.d.ts +38 -0
  31. package/dist/components/CheckList.d.ts.map +1 -0
  32. package/dist/components/CommandOutput.d.ts +29 -0
  33. package/dist/components/CommandOutput.d.ts.map +1 -0
  34. package/dist/components/ConfigEditor.d.ts +64 -0
  35. package/dist/components/ConfigEditor.d.ts.map +1 -0
  36. package/dist/components/HistorySearch.d.ts +23 -0
  37. package/dist/components/HistorySearch.d.ts.map +1 -0
  38. package/dist/components/KeyProbe.d.ts +36 -0
  39. package/dist/components/KeyProbe.d.ts.map +1 -0
  40. package/dist/components/LineCursor.d.ts +55 -0
  41. package/dist/components/LineCursor.d.ts.map +1 -0
  42. package/dist/components/Live.d.ts +17 -0
  43. package/dist/components/Live.d.ts.map +1 -0
  44. package/dist/components/Palette.d.ts +21 -0
  45. package/dist/components/Palette.d.ts.map +1 -0
  46. package/dist/components/Picker.d.ts +23 -0
  47. package/dist/components/Picker.d.ts.map +1 -0
  48. package/dist/components/Prompt.d.ts +20 -0
  49. package/dist/components/Prompt.d.ts.map +1 -0
  50. package/dist/components/Screen.d.ts +39 -0
  51. package/dist/components/Screen.d.ts.map +1 -0
  52. package/dist/components/SelectList.d.ts +34 -0
  53. package/dist/components/SelectList.d.ts.map +1 -0
  54. package/dist/components/SessionPicker.d.ts +26 -0
  55. package/dist/components/SessionPicker.d.ts.map +1 -0
  56. package/dist/components/SkillBrowser.d.ts +39 -0
  57. package/dist/components/SkillBrowser.d.ts.map +1 -0
  58. package/dist/components/Spinner.d.ts +13 -0
  59. package/dist/components/Spinner.d.ts.map +1 -0
  60. package/dist/components/StatusBar.d.ts +11 -0
  61. package/dist/components/StatusBar.d.ts.map +1 -0
  62. package/dist/components/SummaryCard.d.ts +11 -0
  63. package/dist/components/SummaryCard.d.ts.map +1 -0
  64. package/dist/components/TextField.d.ts +39 -0
  65. package/dist/components/TextField.d.ts.map +1 -0
  66. package/dist/components/Transcript.d.ts +23 -0
  67. package/dist/components/Transcript.d.ts.map +1 -0
  68. package/dist/components/WizardApp.d.ts +18 -0
  69. package/dist/components/WizardApp.d.ts.map +1 -0
  70. package/dist/components/WizardFrame.d.ts +19 -0
  71. package/dist/components/WizardFrame.d.ts.map +1 -0
  72. package/dist/config-yz0nz51b.js +24 -0
  73. package/dist/config-yz0nz51b.js.map +10 -0
  74. package/dist/config.d.ts +71 -0
  75. package/dist/config.d.ts.map +1 -0
  76. package/dist/credential-wgt4gvcz.js +19 -0
  77. package/dist/credential-wgt4gvcz.js.map +10 -0
  78. package/dist/credential.d.ts +68 -0
  79. package/dist/credential.d.ts.map +1 -0
  80. package/dist/daemon.d.ts +47 -0
  81. package/dist/daemon.d.ts.map +1 -0
  82. package/dist/editor.d.ts +81 -0
  83. package/dist/editor.d.ts.map +1 -0
  84. package/dist/hooks/useElapsed.d.ts +10 -0
  85. package/dist/hooks/useElapsed.d.ts.map +1 -0
  86. package/dist/hooks/useTerminalSize.d.ts +14 -0
  87. package/dist/hooks/useTerminalSize.d.ts.map +1 -0
  88. package/dist/hooks/useTurn.d.ts +41 -0
  89. package/dist/hooks/useTurn.d.ts.map +1 -0
  90. package/dist/index-2cvtz0fy.js +903 -0
  91. package/dist/index-2cvtz0fy.js.map +194 -0
  92. package/dist/index-3nwfz9jq.js +12 -0
  93. package/dist/index-3nwfz9jq.js.map +11 -0
  94. package/dist/index-6b7qvh1x.js +6 -0
  95. package/dist/index-6b7qvh1x.js.map +10 -0
  96. package/dist/index-6z0yr17z.js +12 -0
  97. package/dist/index-6z0yr17z.js.map +11 -0
  98. package/dist/index-7da4fqcr.js +7 -0
  99. package/dist/index-7da4fqcr.js.map +11 -0
  100. package/dist/index-8bmhd2hj.js +6 -0
  101. package/dist/index-8bmhd2hj.js.map +10 -0
  102. package/dist/index-9d011p3q.js +6 -0
  103. package/dist/index-9d011p3q.js.map +10 -0
  104. package/dist/index-9f9pp2ef.js +6 -0
  105. package/dist/index-9f9pp2ef.js.map +10 -0
  106. package/dist/index-9nsfs0vy.js +6 -0
  107. package/dist/index-9nsfs0vy.js.map +10 -0
  108. package/dist/index-9pj1ws0p.js +77 -0
  109. package/dist/index-9pj1ws0p.js.map +12 -0
  110. package/dist/index-b5wwtxzk.js +66 -0
  111. package/dist/index-b5wwtxzk.js.map +12 -0
  112. package/dist/index-b8zwg8a3.js +6 -0
  113. package/dist/index-b8zwg8a3.js.map +10 -0
  114. package/dist/index-bry9bzt3.js +427 -0
  115. package/dist/index-bry9bzt3.js.map +11 -0
  116. package/dist/index-bwckzbf8.js +6 -0
  117. package/dist/index-bwckzbf8.js.map +10 -0
  118. package/dist/index-cx3vz7sf.js +6 -0
  119. package/dist/index-cx3vz7sf.js.map +11 -0
  120. package/dist/index-e8n70sgj.js +6 -0
  121. package/dist/index-e8n70sgj.js.map +11 -0
  122. package/dist/index-fvhg0xyd.js +167 -0
  123. package/dist/index-fvhg0xyd.js.map +19 -0
  124. package/dist/index-gbnc99j8.js +14 -0
  125. package/dist/index-gbnc99j8.js.map +13 -0
  126. package/dist/index-h2yds678.js +7 -0
  127. package/dist/index-h2yds678.js.map +11 -0
  128. package/dist/index-j97vttdt.js +10 -0
  129. package/dist/index-j97vttdt.js.map +10 -0
  130. package/dist/index-jk0def33.js +6 -0
  131. package/dist/index-jk0def33.js.map +12 -0
  132. package/dist/index-jym27m75.js +6 -0
  133. package/dist/index-jym27m75.js.map +10 -0
  134. package/dist/index-mgdgx22q.js +10 -0
  135. package/dist/index-mgdgx22q.js.map +10 -0
  136. package/dist/index-mrtb5y08.js +6 -0
  137. package/dist/index-mrtb5y08.js.map +11 -0
  138. package/dist/index-my5cjx00.js +6 -0
  139. package/dist/index-my5cjx00.js.map +10 -0
  140. package/dist/index-qc2vrq9z.js +7 -0
  141. package/dist/index-qc2vrq9z.js.map +11 -0
  142. package/dist/index-rqbtm761.js +6 -0
  143. package/dist/index-rqbtm761.js.map +10 -0
  144. package/dist/index-rqzg861g.js +6 -0
  145. package/dist/index-rqzg861g.js.map +10 -0
  146. package/dist/index-t1xvacym.js +6 -0
  147. package/dist/index-t1xvacym.js.map +11 -0
  148. package/dist/index-xgqzk5cq.js +9 -0
  149. package/dist/index-xgqzk5cq.js.map +12 -0
  150. package/dist/index-xqyms08r.js +6 -0
  151. package/dist/index-xqyms08r.js.map +10 -0
  152. package/dist/index-yr25dnf5.js +6 -0
  153. package/dist/index-yr25dnf5.js.map +10 -0
  154. package/dist/index.d.ts +23 -0
  155. package/dist/index.d.ts.map +1 -0
  156. package/dist/index.js +527 -0
  157. package/dist/index.js.map +48 -0
  158. package/dist/init.d.ts +34 -0
  159. package/dist/init.d.ts.map +1 -0
  160. package/dist/keymap.d.ts +126 -0
  161. package/dist/keymap.d.ts.map +1 -0
  162. package/dist/keys.d.ts +17 -0
  163. package/dist/keys.d.ts.map +1 -0
  164. package/dist/lib/ambient.d.ts +69 -0
  165. package/dist/lib/ambient.d.ts.map +1 -0
  166. package/dist/lib/args.d.ts +33 -0
  167. package/dist/lib/args.d.ts.map +1 -0
  168. package/dist/lib/bootstrap.d.ts +84 -0
  169. package/dist/lib/bootstrap.d.ts.map +1 -0
  170. package/dist/lib/browse.d.ts +89 -0
  171. package/dist/lib/browse.d.ts.map +1 -0
  172. package/dist/lib/browser.d.ts +55 -0
  173. package/dist/lib/browser.d.ts.map +1 -0
  174. package/dist/lib/chat-frame.d.ts +156 -0
  175. package/dist/lib/chat-frame.d.ts.map +1 -0
  176. package/dist/lib/clipboard.d.ts +32 -0
  177. package/dist/lib/clipboard.d.ts.map +1 -0
  178. package/dist/lib/commands.d.ts +26 -0
  179. package/dist/lib/commands.d.ts.map +1 -0
  180. package/dist/lib/composer.d.ts +85 -0
  181. package/dist/lib/composer.d.ts.map +1 -0
  182. package/dist/lib/config-apply.d.ts +51 -0
  183. package/dist/lib/config-apply.d.ts.map +1 -0
  184. package/dist/lib/config-editor.d.ts +113 -0
  185. package/dist/lib/config-editor.d.ts.map +1 -0
  186. package/dist/lib/config-env.d.ts +110 -0
  187. package/dist/lib/config-env.d.ts.map +1 -0
  188. package/dist/lib/config-rows.d.ts +37 -0
  189. package/dist/lib/config-rows.d.ts.map +1 -0
  190. package/dist/lib/config-view.d.ts +133 -0
  191. package/dist/lib/config-view.d.ts.map +1 -0
  192. package/dist/lib/confirm.d.ts +86 -0
  193. package/dist/lib/confirm.d.ts.map +1 -0
  194. package/dist/lib/const.d.ts +213 -0
  195. package/dist/lib/const.d.ts.map +1 -0
  196. package/dist/lib/csi.d.ts +70 -0
  197. package/dist/lib/csi.d.ts.map +1 -0
  198. package/dist/lib/curated.d.ts +44 -0
  199. package/dist/lib/curated.d.ts.map +1 -0
  200. package/dist/lib/daemon-plan.d.ts +151 -0
  201. package/dist/lib/daemon-plan.d.ts.map +1 -0
  202. package/dist/lib/dotenv-edit.d.ts +30 -0
  203. package/dist/lib/dotenv-edit.d.ts.map +1 -0
  204. package/dist/lib/env.d.ts +10 -0
  205. package/dist/lib/env.d.ts.map +1 -0
  206. package/dist/lib/exit.d.ts +170 -0
  207. package/dist/lib/exit.d.ts.map +1 -0
  208. package/dist/lib/help.d.ts +10 -0
  209. package/dist/lib/help.d.ts.map +1 -0
  210. package/dist/lib/init-flow.d.ts +539 -0
  211. package/dist/lib/init-flow.d.ts.map +1 -0
  212. package/dist/lib/init-skills.d.ts +46 -0
  213. package/dist/lib/init-skills.d.ts.map +1 -0
  214. package/dist/lib/keyboard.d.ts +76 -0
  215. package/dist/lib/keyboard.d.ts.map +1 -0
  216. package/dist/lib/keys-view.d.ts +57 -0
  217. package/dist/lib/keys-view.d.ts.map +1 -0
  218. package/dist/lib/launchd.d.ts +151 -0
  219. package/dist/lib/launchd.d.ts.map +1 -0
  220. package/dist/lib/lifecycle.d.ts +126 -0
  221. package/dist/lib/lifecycle.d.ts.map +1 -0
  222. package/dist/lib/log-follow.d.ts +71 -0
  223. package/dist/lib/log-follow.d.ts.map +1 -0
  224. package/dist/lib/mouse.d.ts +84 -0
  225. package/dist/lib/mouse.d.ts.map +1 -0
  226. package/dist/lib/multiselect.d.ts +37 -0
  227. package/dist/lib/multiselect.d.ts.map +1 -0
  228. package/dist/lib/origins.d.ts +40 -0
  229. package/dist/lib/origins.d.ts.map +1 -0
  230. package/dist/lib/output.d.ts +29 -0
  231. package/dist/lib/output.d.ts.map +1 -0
  232. package/dist/lib/palette.d.ts +69 -0
  233. package/dist/lib/palette.d.ts.map +1 -0
  234. package/dist/lib/probe.d.ts +158 -0
  235. package/dist/lib/probe.d.ts.map +1 -0
  236. package/dist/lib/providers.d.ts +63 -0
  237. package/dist/lib/providers.d.ts.map +1 -0
  238. package/dist/lib/provision.d.ts +163 -0
  239. package/dist/lib/provision.d.ts.map +1 -0
  240. package/dist/lib/remove-plan.d.ts +120 -0
  241. package/dist/lib/remove-plan.d.ts.map +1 -0
  242. package/dist/lib/render.d.ts +78 -0
  243. package/dist/lib/render.d.ts.map +1 -0
  244. package/dist/lib/resume.d.ts +69 -0
  245. package/dist/lib/resume.d.ts.map +1 -0
  246. package/dist/lib/rows.d.ts +69 -0
  247. package/dist/lib/rows.d.ts.map +1 -0
  248. package/dist/lib/sandbox.d.ts +101 -0
  249. package/dist/lib/sandbox.d.ts.map +1 -0
  250. package/dist/lib/schema.d.ts +491 -0
  251. package/dist/lib/schema.d.ts.map +1 -0
  252. package/dist/lib/screen.d.ts +102 -0
  253. package/dist/lib/screen.d.ts.map +1 -0
  254. package/dist/lib/scroll.d.ts +64 -0
  255. package/dist/lib/scroll.d.ts.map +1 -0
  256. package/dist/lib/select.d.ts +23 -0
  257. package/dist/lib/select.d.ts.map +1 -0
  258. package/dist/lib/service-env.d.ts +38 -0
  259. package/dist/lib/service-env.d.ts.map +1 -0
  260. package/dist/lib/service.d.ts +102 -0
  261. package/dist/lib/service.d.ts.map +1 -0
  262. package/dist/lib/session-commands.d.ts +229 -0
  263. package/dist/lib/session-commands.d.ts.map +1 -0
  264. package/dist/lib/session-key.d.ts +55 -0
  265. package/dist/lib/session-key.d.ts.map +1 -0
  266. package/dist/lib/sessions-view.d.ts +31 -0
  267. package/dist/lib/sessions-view.d.ts.map +1 -0
  268. package/dist/lib/source-cache.d.ts +105 -0
  269. package/dist/lib/source-cache.d.ts.map +1 -0
  270. package/dist/lib/source.d.ts +281 -0
  271. package/dist/lib/source.d.ts.map +1 -0
  272. package/dist/lib/sources.d.ts +107 -0
  273. package/dist/lib/sources.d.ts.map +1 -0
  274. package/dist/lib/spawn.d.ts +56 -0
  275. package/dist/lib/spawn.d.ts.map +1 -0
  276. package/dist/lib/stdin-tap.d.ts +41 -0
  277. package/dist/lib/stdin-tap.d.ts.map +1 -0
  278. package/dist/lib/subcommand.d.ts +57 -0
  279. package/dist/lib/subcommand.d.ts.map +1 -0
  280. package/dist/lib/systemd.d.ts +60 -0
  281. package/dist/lib/systemd.d.ts.map +1 -0
  282. package/dist/lib/templates.d.ts +35 -0
  283. package/dist/lib/templates.d.ts.map +1 -0
  284. package/dist/lib/terminal.d.ts +98 -0
  285. package/dist/lib/terminal.d.ts.map +1 -0
  286. package/dist/lib/text-selection.d.ts +75 -0
  287. package/dist/lib/text-selection.d.ts.map +1 -0
  288. package/dist/lib/theme.d.ts +90 -0
  289. package/dist/lib/theme.d.ts.map +1 -0
  290. package/dist/lib/types.d.ts +467 -0
  291. package/dist/lib/types.d.ts.map +1 -0
  292. package/dist/lib/warnings.d.ts +79 -0
  293. package/dist/lib/warnings.d.ts.map +1 -0
  294. package/dist/lib/width.d.ts +39 -0
  295. package/dist/lib/width.d.ts.map +1 -0
  296. package/dist/lib/wizard.d.ts +95 -0
  297. package/dist/lib/wizard.d.ts.map +1 -0
  298. package/dist/lib/wordmark.d.ts +60 -0
  299. package/dist/lib/wordmark.d.ts.map +1 -0
  300. package/dist/lib/wrap.d.ts +74 -0
  301. package/dist/lib/wrap.d.ts.map +1 -0
  302. package/dist/memory.d.ts +25 -0
  303. package/dist/memory.d.ts.map +1 -0
  304. package/dist/model.d.ts +47 -0
  305. package/dist/model.d.ts.map +1 -0
  306. package/dist/plugins.d.ts +15 -0
  307. package/dist/plugins.d.ts.map +1 -0
  308. package/dist/remove.d.ts +52 -0
  309. package/dist/remove.d.ts.map +1 -0
  310. package/dist/run.d.ts +42 -0
  311. package/dist/run.d.ts.map +1 -0
  312. package/dist/schedules.d.ts +41 -0
  313. package/dist/schedules.d.ts.map +1 -0
  314. package/dist/serve.d.ts +41 -0
  315. package/dist/serve.d.ts.map +1 -0
  316. package/dist/sessions.d.ts +13 -0
  317. package/dist/sessions.d.ts.map +1 -0
  318. package/dist/skills.d.ts +80 -0
  319. package/dist/skills.d.ts.map +1 -0
  320. package/dist/soul.d.ts +19 -0
  321. package/dist/soul.d.ts.map +1 -0
  322. package/dist/sources.d.ts +32 -0
  323. package/dist/sources.d.ts.map +1 -0
  324. package/dist/start.d.ts +26 -0
  325. package/dist/start.d.ts.map +1 -0
  326. package/dist/stop.d.ts +58 -0
  327. package/dist/stop.d.ts.map +1 -0
  328. package/dist/terminal-setup.d.ts +31 -0
  329. package/dist/terminal-setup.d.ts.map +1 -0
  330. package/dist/tools.d.ts +22 -0
  331. package/dist/tools.d.ts.map +1 -0
  332. package/dist/transcript.d.ts +124 -0
  333. package/dist/transcript.d.ts.map +1 -0
  334. package/dist/validate.d.ts +36 -0
  335. package/dist/validate.d.ts.map +1 -0
  336. package/dist/web-w7r68df1.js +14 -0
  337. package/dist/web-w7r68df1.js.map +11 -0
  338. package/dist/web.d.ts +36 -0
  339. package/dist/web.d.ts.map +1 -0
  340. package/dist/wire.d.ts +10 -0
  341. package/dist/wire.d.ts.map +1 -0
  342. package/dist/wire.js +33 -0
  343. package/dist/wire.js.map +10 -0
  344. package/dist/workspace.d.ts +19 -0
  345. package/dist/workspace.d.ts.map +1 -0
  346. package/package.json +78 -0
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/env.ts", "../src/lib/sandbox.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Every environment read the CLI makes.\n *\n * Centralised for the same reason termheat centralises it: an environment variable consulted deep\n * inside a component is untestable and invisible. Everything downstream takes an `EnvFacts` value,\n * so the interesting logic — `resolveMode` especially — is a pure function of its inputs.\n */\n\nimport { BRAND } from \"@dispach/core\"\nimport type { EnvFacts } from \"#lib/types\"\n\n/**\n * `NO_COLOR` is honoured when present and non-empty, per no-color.org. An exported-but-empty\n * variable is a container passing through something unset, not a stated preference.\n */\nfunction isSet(value: string | undefined): boolean {\n return value !== undefined && value !== \"\"\n}\n\nexport function readEnv(env: Readonly<Record<string, string | undefined>> = process.env): EnvFacts {\n return {\n noColor: isSet(env.NO_COLOR),\n dumbTerminal: env.TERM === \"dumb\",\n // `CI=false` is set by tooling that wants to say \"not CI\", and taking it literally would\n // strip interactivity from a terminal that has it.\n ci: isSet(env.CI) && env.CI !== \"false\",\n debug: isSet(env.DEBUG),\n // The sandbox root override, `<ENVPREFIX>HOME`. Brand-derived so a rename moves it.\n sandboxHome: isSet(env[`${BRAND.envPrefix}HOME`])\n ? env[`${BRAND.envPrefix}HOME`]\n : undefined,\n // Brand-derived like the sandbox root above, so a rename moves it.\n noEnhancedKeys: isSet(env[`${BRAND.envPrefix}NO_CSI_U`]),\n }\n}\n",
6
+ "/**\n * The home sandbox: where agents live when nobody says otherwise.\n *\n * `~/<stateDir>/` (brand-derived, so a rename moves it) holds `agents/<ref>/` for init-created\n * agents and `store.db` for their sessions. One root, one store: the store schema is already\n * keyed by agent id, and a cwd-relative default meant the same agent got a different session\n * history in every directory you happened to be in.\n *\n * Discovery reads manifest *headers*, never `loadManifest`: loading expands env references and\n * checks that key variables are set, so a picker built on it would fail exactly when it is\n * needed most — on a machine where the key is not exported yet. A broken manifest becomes a\n * listed entry with a `problem`, never a broken listing.\n *\n * Tests override the root with `<ENVPREFIX>HOME` pointed at a tmpdir; nothing here touches the\n * real home directory when that is set.\n */\n\nimport { existsSync, readdirSync, statSync } from \"node:fs\"\nimport { homedir } from \"node:os\"\nimport { isAbsolute, join, resolve, sep } from \"node:path\"\nimport { BRAND, HarnessError, nearest, readManifestHeader } from \"@dispach/core\"\nimport { readEnv } from \"#lib/env\"\n\nexport function sandboxRoot(\n env: Readonly<Record<string, string | undefined>> = process.env,\n): string {\n const override = readEnv(env).sandboxHome\n return override ?? join(homedir(), BRAND.stateDir)\n}\n\nexport function agentsDir(env?: Readonly<Record<string, string | undefined>>): string {\n return join(sandboxRoot(env), \"agents\")\n}\n\nexport function storePath(env?: Readonly<Record<string, string | undefined>>): string {\n return join(sandboxRoot(env), \"store.db\")\n}\n\n/**\n * Where a service writes its output, keyed by the agent's **manifest id**.\n *\n * Not by the directory name, which is what `run <ref>` takes — the same split as the store's\n * `agent_id` and the launchd label. Two directories with one manifest id therefore share these files,\n * which `listAgents` already warns about.\n *\n * Here rather than in `daemon.ts`, where it was private, because it is a fact about the sandbox layout\n * and `remove` needs it too. Moved rather than duplicated: a second copy of a path derivation is how\n * one command deletes a file another command is still writing to.\n */\n/**\n * Where the one server unit writes, in a **subdirectory** rather than beside the agent logs.\n *\n * `logs/<id>.err.log` is the per-agent shape, so a flat `logs/server.err.log` would collide with an\n * agent whose id happened to be `server` — and the collision would appear as a service and an agent\n * appending to one file, which is the kind of thing nobody diagnoses from a log.\n */\nexport function serverLogPaths(env?: Readonly<Record<string, string | undefined>>): {\n readonly out: string\n readonly err: string\n} {\n const dir = join(sandboxRoot(env), \"logs\", \"server\")\n return { out: join(dir, \"out.log\"), err: join(dir, \"err.log\") }\n}\n\nexport function logPaths(\n agentId: string,\n env?: Readonly<Record<string, string | undefined>>,\n): { readonly out: string; readonly err: string } {\n const dir = join(sandboxRoot(env), \"logs\")\n return { out: join(dir, `${agentId}.out.log`), err: join(dir, `${agentId}.err.log`) }\n}\n\n/**\n * Is this path inside the sandbox's agents directory?\n *\n * Both sides are resolved first, for the reason `root.ts` already records: an unresolved\n * `<base>/../../elsewhere` passes a prefix test while landing nowhere near the base. The `sep`\n * suffix is what stops `~/.brand/agents-backup` reading as inside `~/.brand/agents`.\n */\nexport function insideSandbox(\n targetDir: string,\n env?: Readonly<Record<string, string | undefined>>,\n): boolean {\n const base = resolve(agentsDir(env))\n const target = resolve(targetDir)\n return target === base || target.startsWith(base + sep)\n}\n\n/**\n * The one-line note an out-of-sandbox target earns, or `undefined` when it is inside.\n *\n * A note rather than a refusal: `init --dir ./examples/scout` is a legitimate thing to want, and a\n * command that refuses it would be one people work around with `mv`. What is *not* legitimate is\n * doing it silently — an agent outside the sandbox has no bare name, so every later `run`, `config`,\n * `daemon` and `schedules` call needs a path, and the reason for that is only obvious at the moment\n * the directory is chosen.\n *\n * Pure and separate from the write so the sentence can be asserted without a filesystem.\n */\nexport function outsideSandboxNote(\n targetDir: string,\n env?: Readonly<Record<string, string | undefined>>,\n): string | undefined {\n if (insideSandbox(targetDir, env)) return undefined\n return `note: ${resolve(targetDir)} is outside the sandbox (${agentsDir(env)}) — this agent has no bare name, so every later command needs its path. Omit --dir to put it in the sandbox.`\n}\n\nexport interface SandboxAgent {\n /** The directory name — what `run <ref>` takes. Filesystem-unique by construction. */\n readonly ref: string\n /** Absolute agent directory. */\n readonly dir: string\n /** Absolute path to its agent.yaml. */\n readonly manifestPath: string\n /** From the manifest header; may differ from `ref` for hand-copied directories. */\n readonly id?: string\n readonly name?: string\n /** Raw — may literally be an unexpanded `${MODEL_ID}` reference. */\n readonly modelId?: string\n /** Modification time of the manifest, for \"recently used\" ordering hints. */\n readonly mtimeMs: number\n /** Present when the manifest could not be read; the entry lists anyway, honestly. */\n readonly problem?: string\n}\n\n/**\n * Every agent directory in the sandbox, alphabetical by ref with broken entries last.\n *\n * Broken means the header could not be read — the entry still appears, carrying the problem,\n * because a listing that silently hides a corrupted agent turns \"why is my agent gone\" into a\n * filesystem investigation. Duplicate manifest ids are marked the same way: both run, but their\n * sessions share a store keyed by that id, which is worth a warning rather than a pretence.\n */\nexport function listAgents(\n env?: Readonly<Record<string, string | undefined>>,\n): readonly SandboxAgent[] {\n const dir = agentsDir(env)\n let entries: string[]\n try {\n entries = readdirSync(dir)\n } catch {\n // No sandbox yet is the normal first-run state, not an error.\n return []\n }\n\n const agents: SandboxAgent[] = []\n for (const ref of entries.sort()) {\n const agentDir = join(dir, ref)\n const manifestPath = join(agentDir, \"agent.yaml\")\n try {\n if (!statSync(agentDir).isDirectory()) continue\n } catch {\n continue\n }\n if (!existsSync(manifestPath)) continue\n\n let mtimeMs = 0\n try {\n mtimeMs = statSync(manifestPath).mtimeMs\n } catch {\n // Raced away between existsSync and statSync; list it with what we have.\n }\n\n try {\n const header = readManifestHeader(manifestPath)\n agents.push({\n ref,\n dir: agentDir,\n manifestPath,\n mtimeMs,\n ...(header.id === undefined ? {} : { id: header.id }),\n ...(header.name === undefined ? {} : { name: header.name }),\n ...(header.modelId === undefined ? {} : { modelId: header.modelId }),\n })\n } catch (error) {\n agents.push({\n ref,\n dir: agentDir,\n manifestPath,\n mtimeMs,\n problem: error instanceof Error ? error.message : String(error),\n })\n }\n }\n\n // Duplicate manifest ids share session history — say so rather than pretend it is fine.\n const byId = new Map<string, SandboxAgent[]>()\n for (const agent of agents) {\n if (agent.id === undefined) continue\n byId.set(agent.id, [...(byId.get(agent.id) ?? []), agent])\n }\n const marked = agents.map((agent) => {\n if (agent.id === undefined || (byId.get(agent.id)?.length ?? 0) < 2) return agent\n return {\n ...agent,\n problem: `manifest id \"${agent.id}\" is shared with another sandbox agent — their sessions share one history`,\n }\n })\n\n return [\n ...marked.filter((a) => a.problem === undefined),\n ...marked.filter((a) => a.problem !== undefined),\n ]\n}\n\n/**\n * Turn what the user typed into a manifest path.\n *\n * The filesystem wins: anything that looks like a path (a separator, a .yaml suffix, or a thing\n * that exists here) is a path, so `./milo` always forces the file even when a sandbox agent\n * `milo` exists — the same rule git applies to pathspec-versus-branch, with the same free escape\n * hatch. Only then is the ref tried as a sandbox agent name.\n */\nexport function resolveAgentRef(\n ref: string,\n env?: Readonly<Record<string, string | undefined>>,\n cwd: string = process.cwd(),\n): string {\n const looksLikePath =\n ref.includes(sep) || ref.includes(\"/\") || ref.endsWith(\".yaml\") || ref.endsWith(\".yml\")\n const asPath = isAbsolute(ref) ? ref : resolve(cwd, ref)\n\n // A bare name that happens to exist in the cwd wins as a path — but silently running the\n // wrong agent is worse than one stderr line. Only fires on genuine ambiguity.\n if (!looksLikePath && existsSync(asPath) && existsSync(join(agentsDir(env), ref))) {\n process.stderr.write(\n `note: using ./${ref} from the current directory; a sandbox agent \"${ref}\" also exists — run it from elsewhere, or as ${join(agentsDir(env), ref)}\\n`,\n )\n }\n\n if (looksLikePath || existsSync(asPath)) {\n if (existsSync(asPath)) {\n if (statSync(asPath).isDirectory()) {\n const inside = join(asPath, \"agent.yaml\")\n if (existsSync(inside)) return inside\n throw new HarnessError({\n code: \"cli_agent_dir_without_manifest\",\n message: `${ref} is a directory with no agent.yaml inside.`,\n hint: \"Point at the manifest itself, or at a directory that holds one. Sandbox agents are run by bare name, with no path separators.\",\n })\n }\n return asPath\n }\n throw new HarnessError({\n code: \"cli_agent_path_missing\",\n message: `${ref} looks like a path, and nothing is there.`,\n hint: `Paths resolve against the current directory. For an agent in the sandbox, use its bare name — \\`${BRAND.slug} run <name>\\` — which resolves under ${agentsDir(env)}.`,\n })\n }\n\n const sandboxManifest = join(agentsDir(env), ref, \"agent.yaml\")\n if (existsSync(sandboxManifest)) return sandboxManifest\n\n const known = listAgents(env).map((agent) => agent.ref)\n const suggestion = nearest(ref, known)\n throw new HarnessError({\n code: \"cli_agent_unknown\",\n message: `No agent named \"${ref}\" in the sandbox${known.length === 0 ? \", which is empty\" : \"\"}.`,\n hint:\n known.length === 0\n ? `Create one with \\`${BRAND.slug} init\\`, or pass a path to an agent.yaml.`\n : `Known agents: ${known.join(\", \")}.${suggestion === undefined ? \"\" : ` Did you mean ${suggestion}?`} A path (./dir or file.yaml) is also accepted.`,\n })\n}\n"
7
+ ],
8
+ "mappings": ";yCAeA,SAAS,CAAK,CAAC,EAAoC,CAC/C,OAAO,IAAU,QAAa,IAAU,GAGrC,SAAS,EAAO,CAAC,EAAoD,QAAQ,IAAe,CAC/F,MAAO,CACH,QAAS,EAAM,EAAI,QAAQ,EAC3B,aAAc,EAAI,OAAS,OAG3B,GAAI,EAAM,EAAI,EAAE,GAAK,EAAI,KAAO,QAChC,MAAO,EAAM,EAAI,KAAK,EAEtB,YAAa,EAAM,EAAI,GAAG,EAAM,gBAAgB,EAC1C,EAAI,GAAG,EAAM,iBACb,OAEN,eAAgB,EAAM,EAA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mnpqrstvwxyz"[o&31]??"0")}return`local:${e.join("")}`}function jn(n){return r(n(6))}function so(n){return new RegExp("^local:[0123456789abcdefghjkmnpqrstvwxyz]{6}$").test(n)}
3
+ export{jn,so};
4
+
5
+ //# debugId=C53A9B03C19CA2FC64756E2164756E21
6
+ //# sourceMappingURL=index-8bmhd2hj.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/session-key.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Naming a conversation.\n *\n * Every `run` used to land in `local:default`, which made the store one long transcript per agent:\n * yesterday's debugging session and this morning's question shared a history, so the model was\n * conditioned on both and neither could be resumed without the other. A key per run fixes that, and it\n * moves the cost — you now have to *say* which conversation you mean, which is what `--continue` and the\n * exit pointer are for.\n *\n * ## Why six random characters rather than a timestamp\n *\n * A timestamp sorts and reads well and is twenty characters somebody has to type. `sessions` already\n * sorts by `lastActivityAt`, so the ordering a timestamp would carry is information the *listing* has and\n * the key does not need — and the two things a person actually does with a key are read it off a pointer\n * line and type it back. Six symbols is one glance and one word.\n *\n * ## Why the prefix stays\n *\n * `local:` says which surface opened the conversation, and it is already load-bearing: Telegram writes\n * `tg:<chat>`, so the prefix is what stops a chat id colliding with a terminal session. A bare key would\n * work today and break the first time two surfaces agreed on a name.\n *\n * Pure: the randomness arrives as bytes, so a test gets the key it asked for.\n */\n\n/**\n * Base-32 without the symbols that look like each other.\n *\n * `i`, `l`, `o` and `u` are out — a key is read off a screen and typed back, and `local:1i0o` is one\n * nobody transcribes reliably. Exactly 32 symbols also divides a byte's low five bits, so there is no\n * modulo bias: an alphabet that does not divide evenly makes its first symbols more likely than its last,\n * which matters here not for secrecy but because it makes collisions more likely than the count below\n * claims.\n */\nconst ALPHABET = \"0123456789abcdefghjkmnpqrstvwxyz\"\n\n/** Symbols after the prefix. Six gives 32^6 ≈ 1.07 billion, so a 50% collision needs ~39,000 sessions. */\nexport const SESSION_KEY_LENGTH = 6\n\n/** The surface that opened the conversation. A terminal session; Telegram writes its own prefix. */\nexport const LOCAL_SESSION_PREFIX = \"local\"\n\n/**\n * A key from six bytes.\n *\n * Only the low five bits of each byte are read, which is why the alphabet is exactly 32 long.\n */\nexport function sessionKeyFrom(bytes: Uint8Array): string {\n const symbols: string[] = []\n for (let at = 0; at < SESSION_KEY_LENGTH; at += 1) {\n const byte = bytes[at] ?? 0\n symbols.push(ALPHABET[byte & 0x1f] ?? \"0\")\n }\n return `${LOCAL_SESSION_PREFIX}:${symbols.join(\"\")}`\n}\n\n/**\n * A freshly minted key, from an injected source of randomness.\n *\n * The one derivation. `resolveSession` computed `sessionKeyFrom(random(SESSION_KEY_LENGTH))` inline and\n * `/new` needed the same line — two copies of \"what a generated session is called\" is how two surfaces\n * come to disagree about it, the same reason `logPaths` moved into `lib/sandbox.ts` rather than being\n * copied into `remove`.\n *\n * `random` is a parameter rather than a `crypto` call so a test gets the key it asked for, and so the\n * component layer never has to reach for crypto to open a conversation.\n */\nexport function newSessionKey(random: (count: number) => Uint8Array): string {\n return sessionKeyFrom(random(SESSION_KEY_LENGTH))\n}\n\n/**\n * True for a key this module could have produced.\n *\n * Used to *explain* a key rather than to validate one — a hand-written `--session mine` is perfectly\n * valid and must stay so. It exists because a generated key is the one a person did not choose, and a\n * listing can say so.\n */\nexport function isGeneratedSessionKey(key: string): boolean {\n return new RegExp(`^${LOCAL_SESSION_PREFIX}:[${ALPHABET}]{${SESSION_KEY_LENGTH}}$`).test(key)\n}\n"
6
+ ],
7
+ "mappings": ";AA+CO,SAAS,CAAc,CAAC,EAA2B,CACtD,IAAM,EAAoB,CAAC,EAC3B,QAAS,EAAK,EAAG,EAZa,EAYY,GAAM,EAAG,CAC/C,IAAM,EAAO,EAAM,IAAO,EAC1B,EAAQ,KAjBC,mCAiBa,EAAO,KAAS,GAAG,EAE7C,MAAO,SAA2B,EAAQ,KAAK,EAAE,IAc9C,SAAS,EAAa,CAAC,EAA+C,CACzE,OAAO,EAAe,EA/BQ,CA+BiB,CAAC,EAU7C,SAAS,EAAqB,CAAC,EAAsB,CACxD,OAAO,IAAI,OAAO,+CAAgE,EAAE,KAAK,CAAG",
8
+ "debugId": "C53A9B03C19CA2FC64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ function Mo(t){let e=[],r=/\[(\d+);(\d+)(?::(\d+))?([A-Za-z~])/g;for(let s of t.matchAll(r)){let a=Number(s[1]),n=Number(s[2]),i=s[3],o=s[4]??"";if(!Number.isFinite(a)||!Number.isFinite(n)||n<1)continue;e.push({modifier:n,final:o,param:a,eventType:i===void 0?void 0:i==="3"?"release":i==="2"?"repeat":"press"})}return e}function Lo(t){let e=t.codePointAt(0)===27?t.slice(1):t;return/^\[\?\d*u$/.test(e)}function u(t,e,r){switch(t.final){case"A":return e.upArrow;case"B":return e.downArrow;case"C":return e.rightArrow;case"D":return e.leftArrow;case"H":return e.home;case"F":return e.end;case"~":switch(t.param){case 1:case 7:return e.home;case 3:return e.delete;case 4:case 8:return e.end;case 5:return e.pageUp;case 6:return e.pageDown;default:return!1}case"u":if(t.param===13)return e.return;if(t.param===127)return e.backspace;if(t.param===27)return e.escape;return r!==""&&r===String.fromCodePoint(t.param).toLowerCase();default:return!1}}function Do(t,e,r){let s=r.findIndex((i)=>u(i,t,e));if(s===-1)return t;let[a]=r.splice(s,1);if(a===void 0)return t;let n=a.modifier-1;return{...t,shift:(n&1)!==0,meta:(n&2)!==0,ctrl:(n&4)!==0,super:(n&8)!==0,...a.eventType===void 0?{}:{eventType:a.eventType}}}
3
+ export{Mo,Lo,Do};
4
+
5
+ //# debugId=1957B9B7F4DBC96964756E2164756E21
6
+ //# sourceMappingURL=index-9d011p3q.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/csi.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Reading a modifier off the bytes, because Ink's reading of it is lossy.\n *\n * ## The defect this exists for\n *\n * Warp sends `cmd+left` as `CSI 1;9D` — modifier 9, which decodes to the super bit — and **omits the\n * event-type field**. Ink's kitty branch for special keys requires that field (its regex demands a\n * `:<event>` group), so the sequence falls through to its legacy branch, which does:\n *\n * key.meta = key.meta || !!(modifier & 10)\n *\n * `10` is `alt | super`. With modifier 8 that is `8 & 10 === 8`, truthy — so **super arrives as meta**,\n * and `cmd+left` becomes indistinguishable from `option+left` before our keymap is called at all.\n * Reported from a real session: both chords navigated by word, which is the only symptom this can have.\n *\n * Negotiating `reportEventTypes` was supposed to avoid this by making Warp include the field. It does not\n * — measured by the symptom, not assumed — and a fix that depends on a terminal populating an optional\n * field is a fix that works on some terminals. So the modifier is decoded here, from the bytes, where it\n * is unambiguous: bit 8 is super whether or not an event type follows it.\n *\n * ## Why this is not a second parser\n *\n * It reads *one* field. Key identity still comes from Ink — `leftArrow`, `home`, `input` — and this only\n * overrides the four modifier flags, and only when a sequence was actually found and matched to the key\n * Ink reported. Anything unrecognised leaves the key exactly as it arrived, so the worst case is today's\n * behaviour rather than a new class of wrong.\n */\n\nimport type { KeyState } from \"#lib/types\"\n\n/** Modifier bits, per the xterm and kitty encodings: the wire value is `1 + these`. */\nconst SHIFT = 1\nconst ALT = 2\nconst CTRL = 4\nconst SUPER = 8\n\n/** One modified key found in a chunk. `final` identifies the key for CSI forms, `param` for `u`. */\nexport interface CsiKey {\n readonly modifier: number\n readonly final: string\n /** The first parameter: a key number for `~` forms, a codepoint for `u`, else 1. */\n readonly param: number\n readonly eventType: \"press\" | \"repeat\" | \"release\" | undefined\n}\n\n/**\n * Every modified key in a chunk, oldest first.\n *\n * Matches `CSI <param> ; <modifier> [: <event>] <final>`, which covers the arrows (`A`-`D`), Home and End\n * (`H`/`F`), the tilde forms (`1~` `3~` `4~` `5~` `6~` `7~` `8~`) and kitty's letter form (`u`) in one\n * expression, because they differ only in the final byte. A sequence with no modifier parameter is skipped\n * — there is nothing to correct on an unmodified key. The leading escape is not required: Ink strips one\n * from the front of a chunk before a handler sees it, the same reason `lib/mouse.ts` anchors instead.\n */\nexport function csiKeys(chunk: string): readonly CsiKey[] {\n const found: CsiKey[] = []\n const pattern = /\\[(\\d+);(\\d+)(?::(\\d+))?([A-Za-z~])/g\n for (const match of chunk.matchAll(pattern)) {\n const param = Number(match[1])\n const modifier = Number(match[2])\n const event = match[3]\n const final = match[4] ?? \"\"\n if (!Number.isFinite(param) || !Number.isFinite(modifier) || modifier < 1) continue\n found.push({\n modifier,\n final,\n param,\n eventType:\n event === undefined\n ? undefined\n : event === \"3\"\n ? \"release\"\n : event === \"2\"\n ? \"repeat\"\n : \"press\",\n })\n }\n return found\n}\n\n/**\n * A terminal *reply*, not a keystroke: `CSI ? <flags> u`.\n *\n * Ink asks the terminal for its kitty-keyboard flags at mount, waits 200 ms, and strips the answer out of\n * stdin if one arrives in time. Measured in a real Warp session: it arrived **late**, the window had\n * closed, and the bytes fell through to `useInput` as ordinary text — `input \"[?0u\"`, resolving to an\n * insert. Left unclaimed that types `[?0u` into somebody's first message, which is the same class of\n * defect as a mouse report reaching the buffer and is claimed here for the same reason.\n *\n * Deliberately narrow. Only this one reply is recognised, because it is the only one this runtime *asks*\n * for — and the finals it would be tempting to generalise to are dangerous: `CSI 1;2R` is a real modified\n * F3 key, so claiming `R` would swallow a keystroke to catch a reply nobody requested.\n */\nexport function isTerminalReply(input: string): boolean {\n // The optional escape is stripped by code point rather than matched in the pattern: a control\n // character written into a regex is invisible in the source, which is a lint error for good reason —\n // `lib/keys-view.ts` draws the same line for the same reason.\n const body = input.codePointAt(0) === 0x1b ? input.slice(1) : input\n return /^\\[\\?\\d*u$/.test(body)\n}\n\n/** Which Ink flag a CSI final byte identifies, so a record can be matched to the key Ink reported. */\nfunction identifies(record: CsiKey, key: KeyState, input: string): boolean {\n switch (record.final) {\n case \"A\":\n return key.upArrow\n case \"B\":\n return key.downArrow\n case \"C\":\n return key.rightArrow\n case \"D\":\n return key.leftArrow\n case \"H\":\n return key.home\n case \"F\":\n return key.end\n case \"~\":\n switch (record.param) {\n case 1:\n case 7:\n return key.home\n case 3:\n return key.delete\n case 4:\n case 8:\n return key.end\n case 5:\n return key.pageUp\n case 6:\n return key.pageDown\n default:\n return false\n }\n case \"u\":\n // Kitty's letter form. Ink already decodes these correctly, so matching them is only about\n // not consuming a record that belongs to a later keystroke.\n if (record.param === 13) return key.return\n if (record.param === 127) return key.backspace\n if (record.param === 27) return key.escape\n return input !== \"\" && input === String.fromCodePoint(record.param).toLowerCase()\n default:\n return false\n }\n}\n\n/**\n * The key Ink reported, with its modifiers taken from the bytes when they can be.\n *\n * `records` is consumed: the matched entry is removed, so two keys in one chunk stay in step. Matching by\n * identity rather than by position is what makes that safe — a record that does not correspond to the key\n * Ink is reporting is left in the queue for whichever keystroke it belongs to, instead of being applied to\n * this one.\n */\nexport function withRealModifiers(key: KeyState, input: string, records: CsiKey[]): KeyState {\n const at = records.findIndex((record) => identifies(record, key, input))\n if (at === -1) return key\n const [record] = records.splice(at, 1)\n if (record === undefined) return key\n const bits = record.modifier - 1\n return {\n ...key,\n shift: (bits & SHIFT) !== 0,\n // `meta` is Alt/Option only. This is the whole correction: Ink merges super into it and we do not.\n meta: (bits & ALT) !== 0,\n ctrl: (bits & CTRL) !== 0,\n super: (bits & SUPER) !== 0,\n ...(record.eventType === undefined ? {} : { eventType: record.eventType }),\n }\n}\n"
6
+ ],
7
+ "mappings": ";AAsDO,SAAS,EAAO,CAAC,EAAkC,CACtD,IAAM,EAAkB,CAAC,EACnB,EAAU,uCAChB,QAAW,KAAS,EAAM,SAAS,CAAO,EAAG,CACzC,IAAM,EAAQ,OAAO,EAAM,EAAE,EACvB,EAAW,OAAO,EAAM,EAAE,EAC1B,EAAQ,EAAM,GACd,EAAQ,EAAM,IAAM,GAC1B,GAAI,CAAC,OAAO,SAAS,CAAK,GAAK,CAAC,OAAO,SAAS,CAAQ,GAAK,EAAW,EAAG,SAC3E,EAAM,KAAK,CACP,WACA,QACA,QACA,UACI,IAAU,OACJ,OACA,IAAU,IACR,UAC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
+ "names": []
10
+ }
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import{ft,ln,_r,p}from"./index-2cvtz0fy.js";import{existsSync as E,readFileSync as h}from"node:fs";import{dirname as l,join as o,resolve as u}from"node:path";function Et(n){let e=o(l(n),".env"),r={};if(E(e))try{r=ft(h(e,"utf8"))}catch{}return ln(r,p([n]))}function vo(n,e){let r=n[e];return r!==void 0&&r!==""}function f(n,e,r={}){let i=l(n),t=u(r.cwd??process.cwd()),d=r.readDir??_r,v=r.env??process.env,g=p([n],r),m=d(i),y=d(t),a=g[e];if(a!==void 0&&a!==""){let b=u(i)===t,c=y[e];if(!b&&c!==void 0&&v[e]===c)return{kind:"ambiguous",path:o(t,".env")};return{kind:"export"}}let s=m[e];if(s!==void 0&&s!=="")return{kind:"agent",path:o(i,".env")};return{kind:"unset"}}function ko(n){switch(n.kind){case"export":return"from the environment, not a .env file";case"ambiguous":return"from the environment or ./.env — indistinguishable";case"agent":return;case"unset":return"not set"}}function So(n){let e=[],r=x(n.rawModelId);if(r!==void 0)e.push({field:"model.main.id",variable:r,origin:f(n.manifestPath,r,n.options??{})});if(n.apiKeyEnv!==void 0)e.push({field:"model.main.apiKeyEnv",variable:n.apiKeyEnv,origin:f(n.manifestPath,n.apiKeyEnv,n.options??{})});return e}function x(n){if(n===void 0)return;return/^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(n.trim())?.[1]}
3
+ export{Et,vo,ko,So};
4
+
5
+ //# debugId=7C800DAD520780CB64756E2164756E21
6
+ //# sourceMappingURL=index-9f9pp2ef.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/config-env.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Whether a variable an agent depends on is actually set, from that agent's point of view.\n *\n * `ambientEnv` is **not** this. It layers the *cwd*'s `.env` against an agent's — demoting a colliding\n * variable so a project checkout cannot silently change which model a sandbox agent runs on — and it\n * returns `process.env` unchanged whenever nothing is in tension. It never *adds* the agent's own file.\n *\n * The agent's `.env` is merged by `loadManifest`, through core's `layeredEnv`, and that is the answer a\n * question about this agent needs. Reading `process.env` alone reported a variable as unset while the\n * file beside the manifest plainly had it — the same class of mistake `serve` made once, reporting\n * \"unauthenticated\" for a token sitting next to the manifest. It showed up here as an editor row that\n * still read `(not set)` immediately after somebody set it, which is the \"did that work?\" failure this\n * whole surface exists to remove.\n *\n * Precedence is core's, unchanged: the real environment wins, because an operator's export has to beat\n * a file for a container to be able to configure the agent it runs.\n */\n\nimport { existsSync, readFileSync } from \"node:fs\"\nimport { dirname, join, resolve } from \"node:path\"\nimport { type EnvSource, layeredEnv, parseDotEnv } from \"@dispach/core\"\nimport { type AmbientOptions, ambientEnv, readDotEnv } from \"#lib/ambient\"\n\n/** The environment this agent will actually see: its own `.env` under the ambient one. */\nexport function agentEnv(manifestPath: string): EnvSource {\n const path = join(dirname(manifestPath), \".env\")\n let beside: Record<string, string> = {}\n if (existsSync(path)) {\n try {\n beside = parseDotEnv(readFileSync(path, \"utf8\"))\n } catch {\n // An unreadable `.env` is reported by the loader, in the words the loader uses. Here it\n // simply means nothing is known to be set, which is the safe reading for a \"is it set?\"\n // question — claiming a variable is present when the file cannot be read would be worse.\n }\n }\n return layeredEnv(beside, ambientEnv([manifestPath]))\n}\n\n/** Whether `name` has a non-empty value. Empty counts as unset: it fails a load exactly as absent does. */\nexport function isSet(env: EnvSource, name: string): boolean {\n const value = env[name]\n return value !== undefined && value !== \"\"\n}\n\n/**\n * Where a value came from, which is a different question from whether it is set.\n *\n * Three layers can supply one variable and the winner is not obvious from any of them:\n *\n * 1. the real environment — an operator's export, or a container's `environment:` block\n * 2. the `.env` beside the agent's manifest\n * 3. a `.env` in the directory the command was run from, demoted beneath (2) by `ambientEnv`\n *\n * Every one of those is correct on its own, and the composition is unreadable. It produced a real\n * confusion in a container: `docker compose` passes `MODEL_ID` and friends as process environment,\n * so an agent scaffolded inside that container silently ran on the *mounted*\n * agent's model, and the `0600` `.env` that `init` had just written was ignored for exactly those\n * keys — with nothing anywhere saying so.\n *\n * The precedence is not the bug and is not changed here. What was missing is a sentence, and the\n * recorded lesson from the last time this surfaced is that *a warning explained the surprise and\n * did not remove it* — so this reports rather than intervenes.\n */\nexport type EnvOrigin =\n /** The real environment won: an export, or a container's own configuration. */\n | { readonly kind: \"export\" }\n /** The `.env` beside the manifest won. */\n | { readonly kind: \"agent\"; readonly path: string }\n /**\n * Either an export or the cwd's `.env`, and **they cannot be told apart**.\n *\n * Bun auto-loads a `.env` from the current directory into `process.env` before any of this code\n * runs, so once the two agree on a string there is no evidence left distinguishing them. Said\n * rather than guessed: naming one would be a coin toss printed as a fact.\n */\n | { readonly kind: \"ambiguous\"; readonly path: string }\n | { readonly kind: \"unset\" }\n\n/**\n * Which layer supplies `name` for this agent.\n *\n * Mirrors `ambientEnv`'s precedence by *calling* it rather than by restating it — the demotion rule\n * is subtle (a cwd variable is demoted only when the agent's own file also sets it *and* the values\n * match), and a second implementation of that would drift on the first edit.\n */\nexport function sourceOf(\n manifestPath: string,\n name: string,\n options: AmbientOptions = {},\n): EnvOrigin {\n const agentDir = dirname(manifestPath)\n const cwd = resolve(options.cwd ?? process.cwd())\n const read = options.readDir ?? readDotEnv\n const raw = options.env ?? process.env\n\n const ambient = ambientEnv([manifestPath], options)\n const beside = read(agentDir)\n const inCwd = read(cwd)\n\n const fromAmbient = ambient[name]\n if (fromAmbient !== undefined && fromAmbient !== \"\") {\n // The cwd file is only a candidate when it is a *different* directory from the agent's: when\n // they are the same directory, that file **is** the agent's own and `ambientEnv` says so.\n const sameDir = resolve(agentDir) === cwd\n const cwdValue = inCwd[name]\n if (!sameDir && cwdValue !== undefined && raw[name] === cwdValue) {\n return { kind: \"ambiguous\", path: join(cwd, \".env\") }\n }\n return { kind: \"export\" }\n }\n\n const fromFile = beside[name]\n if (fromFile !== undefined && fromFile !== \"\") {\n return { kind: \"agent\", path: join(agentDir, \".env\") }\n }\n\n return { kind: \"unset\" }\n}\n\n/**\n * The phrase for a status line — short, because it rides after a value somebody is already reading.\n *\n * Returns `undefined` for the ordinary case, which is the whole point: a line that always carries a\n * provenance note is a line nobody reads it on. The agent's own `.env` winning is what an author\n * expects, so only the surprising sources say anything.\n */\nexport function describeOrigin(origin: EnvOrigin): string | undefined {\n switch (origin.kind) {\n case \"export\":\n return \"from the environment, not a .env file\"\n case \"ambiguous\":\n return \"from the environment or ./.env — indistinguishable\"\n case \"agent\":\n return undefined\n case \"unset\":\n return \"not set\"\n }\n}\n\n/** One env-backed field, the variable behind it, and where the value came from. */\nexport interface Provenance {\n readonly field: string\n readonly variable: string\n readonly origin: EnvOrigin\n}\n\n/**\n * The env-backed fields worth saying something about, and only when there is something to say.\n *\n * Two fields, chosen because they are the two that produced a real confusion in a container:\n * `docker compose` passes `MODEL_ID` and `MODEL_API_KEY` as process environment, and the ambient\n * environment deliberately beats the agent's own file so an operator can configure the agent their\n * container runs. So an agent scaffolded in that container ran on the *mounted*\n * agent's model and ignored the `0600` `.env` init had just written.\n *\n * The model id is included **only when the manifest writes it as a variable**. A generated manifest\n * carries it literally (which is why `readManifestHeader` can list agents without credentials), and\n * a literal has no provenance to report — printing \"from the environment\" about a value nothing read\n * from the environment would be worse than silence. `apiKeyEnv` is always a variable name by hard\n * rule 10, so it is always askable.\n */\nexport function envProvenance(input: {\n readonly manifestPath: string\n /** The raw, unexpanded `model.main.id` — `readManifestHeader().modelId`. */\n readonly rawModelId: string | undefined\n readonly apiKeyEnv: string | undefined\n readonly options?: AmbientOptions\n}): readonly Provenance[] {\n const rows: Provenance[] = []\n const variable = soleVariable(input.rawModelId)\n if (variable !== undefined) {\n rows.push({\n field: \"model.main.id\",\n variable,\n origin: sourceOf(input.manifestPath, variable, input.options ?? {}),\n })\n }\n if (input.apiKeyEnv !== undefined) {\n rows.push({\n field: \"model.main.apiKeyEnv\",\n variable: input.apiKeyEnv,\n origin: sourceOf(input.manifestPath, input.apiKeyEnv, input.options ?? {}),\n })\n }\n return rows\n}\n\n/**\n * The variable name when a value is exactly one `${VAR}` reference, and nothing otherwise.\n *\n * Deliberately narrow. `prefix-${VAR}` expands from the environment too, but its provenance is a\n * sentence about part of a string, and a half-true note on a compound value is the kind of detail\n * that gets believed whole.\n */\nfunction soleVariable(raw: string | undefined): string | undefined {\n if (raw === undefined) return undefined\n const match = /^\\$\\{([A-Za-z_][A-Za-z0-9_]*)\\}$/.exec(raw.trim())\n return match?.[1]\n}\n"
6
+ ],
7
+ "mappings": ";4CAkBA,qBAAS,kBAAY,gBACrB,kBAAS,UAAS,aAAM,kBAKjB,SAAS,EAAQ,CAAC,EAAiC,CACtD,IAAM,EAAO,EAAK,EAAQ,CAAY,EAAG,MAAM,EAC3C,EAAiC,CAAC,EACtC,GAAI,EAAW,CAAI,EACf,GAAI,CACA,EAAS,GAAY,EAAa,EAAM,MAAM,CAAC,EACjD,KAAM,EAMZ,OAAO,GAAW,EAAQ,EAAW,CAAC,CAAY,CAAC,CAAC,EAIjD,SAAS,EAAK,CAAC,EAAgB,EAAuB,CACzD,IAAM,EAAQ,EAAI,GAClB,OAAO,IAAU,QAAa,IAAU,GA4CrC,SAAS,CAAQ,CACpB,EACA,EACA,EAA0B,CAAC,EAClB,CACT,IAAM,EAAW,EAAQ,CAAY,EAC/B,EAAM,EAAQ,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAC1C,EAAO,EAAQ,SAAW,GAC1B,EAAM,EAAQ,KAAO,QAAQ,IAE7B,EAAU,EAAW,CAAC,CAAY,EAAG,CAAO,EAC5C,EAAS,EAAK,CAAQ,EACtB,EAAQ,EAAK,CAAG,EAEhB,EAAc,EAAQ,GAC5B,GAAI,IAAgB,QAAa,IAAgB,GAAI,CAGjD,IAAM,EAAU,EAAQ,CAAQ,IAAM,EAChC,EAAW,EAAM,GACvB,GAAI,CAAC,GAAW,IAAa,QAAa,EAAI,KAAU,EACpD,MAAO,CAAE,KAAM,YAAa,KAAM,EAAK,EAAK,MAAM,CAAE,EAExD,MAAO,CAAE,KAAM,QAAS,EAG5B,IAAM,EAAW,EAAO,GACxB,GAAI,IAAa,QAAa,IAAa,GACvC,MAAO,CAAE,KAAM,QAAS,KAAM,EAAK,EAAU,MAAM,CAAE,EAGzD,MAAO,CAAE,KAAM,OAAQ,EAUpB,SAAS,EAAc,CAAC,EAAuC,CAClE,OAAQ,EAAO,UACN,SACD,MAAO,4CACN,YACD,MAAO,yDACN,QACD,WACC,QACD,MAAO,WA0BZ,SAAS,EAAa,CAAC,EAMJ,CACtB,IAAM,EAAqB,CAAC,EACtB,EAAW,EAAa,EAAM,UAAU,EAC9C,GAAI,IAAa,OACb,EAAK,KAAK,CACN,MAAO,gBACP,WACA,OAAQ,EAAS,EAAM,aAAc,EAAU,EAAM,SAAW,CAAC,CAAC,CACtE,CAAC,EAEL,GAAI,EAAM,YAAc,OACpB,EAAK,KAAK,CACN,MAAO,uBACP,SAAU,EAAM,UAChB,OAAQ,EAAS,EAAM,aAAc,EAAM,UAAW,EAAM,SAAW,CAAC,CAAC,CAC7E,CAAC,EAEL,OAAO,EAUX,SAAS,CAAY,CAAC,EAA6C,CAC/D,GAAI,IAAQ,OAAW,OAEvB,MADc,mCAAmC,KAAK,EAAI,KAAK,CAAC,IACjD",
8
+ "debugId": "7C800DAD520780CB64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import{S}from"./index-jk0def33.js";import{xn,En,qe,Ge,Ze}from"./index-my5cjx00.js";var s=" · ",l=3;function Ro(n,e){let t=[{kind:"title",text:S(n.title,e)}],r=n.agent===void 0?n.summary:[`${n.agent.name}${s}${n.agent.model}`,n.summary].filter((a)=>a!=="").join(s);if(r!=="")t.push({kind:"summary",text:S(r,e)});let i=n.state??[];if(i.length>0)t.push({kind:"state",text:S(i.map((a)=>a.label).join(s),e)});let o=n.warnings??[];for(let a of o.slice(0,l))t.push({kind:"warning",text:S(`⚠ ${a}`,e)});if(o.length>l)t.push({kind:"warning",text:S(`⚠ and ${o.length-l} more`,e)});return t}function Io(n,e){let t=n.map((i)=>`${i.key} ${i.does}`),r="";for(let i of t){let o=r===""?i:`${r}${s}${i}`;if([...o].length>e)break;r=o}return r===""?S(t[0]??"",e):r}function Jn(n,e){let t=[n.title];if(n.summary!=="")t.push(n.summary);if(n.agent!==void 0)t.push(n.agent.name,n.agent.model);let r=n.warnings??[];if(r.length>0)t.push(`⚠ ${r.length} note${r.length===1?"":"s"} at the top`);return S(t.join(s),e)}var Oo={key:"q",does:"back"};function u(n,e){return n===void 0||n<=0?e:n}function Z(n,e){return Math.max(xn,Math.min(En,u(n,e)))}function No(n,e){return Math.max(qe,Math.min(Ge,u(n,e)-Ze))}
3
+ export{Ro,Io,Jn,Oo,Z,No};
4
+
5
+ //# debugId=E778705D26BA7DC464756E2164756E21
6
+ //# sourceMappingURL=index-9nsfs0vy.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/screen.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * What every screen has in common, as data: the header block and the footer's key hints.\n *\n * ## Why this is a module and not a component\n *\n * Three surfaces had a banner before this existed — chat, the wizard, the agent picker — and each\n * decided its own title, its own context lines and its own key hints, in JSX. So the *content* of a\n * header was only observable by mounting a renderer, and the one thing worth asserting about it is\n * exactly that content: whether the agent in scope is named, whether a session-wide warning is still\n * visible after the screen scrolls, whether the footer fits.\n *\n * Everything here is text in, text out. `Screen.tsx` is one consumer; a test asserting a header names\n * the right agent is another, and neither can drift from the other because there is one derivation.\n *\n * ## The rule the header exists to enforce\n *\n * CLAUDE.md: anything true for the whole session belongs where a person still sees it after\n * scrolling. On an inline surface that could be a line printed at the top; on the alternate screen\n * there *is* no scrolling past, so it has to be the header or nowhere. `warnings` is therefore part\n * of the header's shape rather than something each screen remembers to render.\n *\n * Colour is not decided here, for `render.ts`'s reason: this module has no idea whether it is being\n * read from a terminal or a log file, and that is `resolveMode`'s question.\n */\n\nimport {\n MAX_SCREEN_COLUMNS,\n MAX_SCREEN_ROWS,\n MIN_SCREEN_COLUMNS,\n MIN_SCREEN_ROWS,\n SCREEN_CHROME_ROWS,\n} from \"#lib/const\"\nimport { clip } from \"#lib/rows\"\n\n/**\n * A live fact about the runtime, shown as a word rather than a sentence.\n *\n * `tone` is a role, never a colour — the component maps it. A literal colour name here would put\n * appearance in a pure module and break the one-home rule `theme.ts` exists for.\n */\nexport interface StateChip {\n readonly label: string\n readonly tone: \"ok\" | \"warn\" | \"off\"\n}\n\nexport interface ScreenHeader {\n /** Product identity — `BRAND.name` and the version. The one line that is the same everywhere. */\n readonly title: string\n /** What this screen is, and the counts that make it worth looking at. */\n readonly summary: string\n /**\n * The agent this screen acts on, when it acts on one.\n *\n * Present so it is impossible to install a skill into, or stop, an agent you did not mean.\n * Absent — not blank — on the machine-level screens: `sources` is a registry shared by every\n * agent on the machine, and naming one there would be a lie about the scope of what you are\n * changing.\n */\n readonly agent?: { readonly name: string; readonly model: string }\n readonly state?: readonly StateChip[]\n /** True for the whole session, so it stays in the frame rather than scrolling away. */\n readonly warnings?: readonly string[]\n}\n\nexport interface KeyHint {\n /** As a reader sees it: `↑↓`, `enter`, `^C`, `⌥⏎`. */\n readonly key: string\n readonly does: string\n}\n\nconst SEPARATOR = \" · \"\n/** Warnings past this many are counted rather than listed — a header is not a log. */\nconst WARNINGS_SHOWN = 3\n\n/**\n * One rendered line, tagged with what it is.\n *\n * Tagged rather than returned as plain strings because the component styles each kind differently and\n * the alternative is worse in both directions: a flat list of strings forces the renderer to guess by\n * index (which broke the first time a header had no state row), and having the renderer rebuild the\n * summary from `header.agent` itself would be a second derivation of the one thing this module exists\n * to derive once. The kind travels with the text; appearance stays in `theme.ts`.\n */\nexport interface HeaderLine {\n readonly kind: \"title\" | \"summary\" | \"state\" | \"warning\"\n readonly text: string\n}\n\n/** The header, as tagged lines, each already clipped to the width. */\nexport function headerLines(header: ScreenHeader, width: number): readonly HeaderLine[] {\n const lines: HeaderLine[] = [{ kind: \"title\", text: clip(header.title, width) }]\n\n // The agent rides on the summary line rather than taking one of its own. It is the same fact —\n // \"what am I looking at, and whose\" — and a separate line for it pushes the body down on every\n // screen to say something the summary was already the place for.\n const scope =\n header.agent === undefined\n ? header.summary\n : [`${header.agent.name}${SEPARATOR}${header.agent.model}`, header.summary]\n .filter((part) => part !== \"\")\n .join(SEPARATOR)\n if (scope !== \"\") lines.push({ kind: \"summary\", text: clip(scope, width) })\n\n const chips = header.state ?? []\n if (chips.length > 0) {\n lines.push({\n kind: \"state\",\n text: clip(chips.map((chip) => chip.label).join(SEPARATOR), width),\n })\n }\n\n const warnings = header.warnings ?? []\n for (const warning of warnings.slice(0, WARNINGS_SHOWN)) {\n lines.push({ kind: \"warning\", text: clip(`⚠ ${warning}`, width) })\n }\n // Counted, not dropped. A header that silently showed three of five warnings would be the\n // trimmed-catalogue failure again: true of what is on screen, false of what is the case.\n if (warnings.length > WARNINGS_SHOWN) {\n lines.push({\n kind: \"warning\",\n text: clip(`⚠ and ${warnings.length - WARNINGS_SHOWN} more`, width),\n })\n }\n\n return lines\n}\n\n/**\n * The footer: what the keys do, on one line, clipped.\n *\n * One line and never two. A footer that wraps moves the body every time the hints change, and the\n * hints change per screen state — so a two-line footer means the list jumps as you use it. Hints are\n * dropped from the end when they do not fit, which is why the caller orders them by how likely\n * somebody is to need reminding: movement first, the destructive one last.\n */\nexport function hintLine(hints: readonly KeyHint[], width: number): string {\n const rendered = hints.map((hint) => `${hint.key} ${hint.does}`)\n // Longest prefix that fits. Built up rather than clipped down, so the line never ends in half a\n // hint — `enter inst…` reads as a different key than the one it is.\n let line = \"\"\n for (const hint of rendered) {\n const next = line === \"\" ? hint : `${line}${SEPARATOR}${hint}`\n if ([...next].length > width) break\n line = next\n }\n // Nothing fit: one clipped hint beats an empty footer, because a screen with no visible way out\n // is the worst thing a full-screen surface can be.\n return line === \"\" ? clip(rendered[0] ?? \"\", width) : line\n}\n\n/**\n * The whole header on one line, for a surface that cannot spare three.\n *\n * The chat is that surface. Its opening banner already says the version, the store, the session and every\n * load warning — and on the alternate screen that banner scrolls out of the window, taking the\n * session-wide facts with it. `headerLines`' three-to-six rows would fix that and cost a fifth of a short\n * terminal permanently, so this is the compromise the rule actually asks for: identity and scope always\n * visible, warnings reduced to a count that says where the detail is.\n *\n * A count rather than the text, deliberately. One warning wrapped over two lines is a header that changes\n * height, which is the one thing a fixed-height frame cannot have.\n */\nexport function titleLine(header: ScreenHeader, width: number): string {\n const parts = [header.title]\n // The summary was dropped here while `Screen` renders it on its own dim line, so a surface using the\n // one-line variant silently lost its label: the conversation switcher passed \"pick a conversation\"\n // and the settings editor \"settings\", and neither ever appeared. Empty adds nothing, which is what\n // the chat header passes.\n if (header.summary !== \"\") parts.push(header.summary)\n if (header.agent !== undefined) parts.push(header.agent.name, header.agent.model)\n const warnings = header.warnings ?? []\n if (warnings.length > 0) {\n parts.push(`\\u26a0 ${warnings.length} note${warnings.length === 1 ? \"\" : \"s\"} at the top`)\n }\n return clip(parts.join(SEPARATOR), width)\n}\n\n/** The hint every alternate-screen surface carries, so no screen invents its own word for leaving. */\nexport const QUIT_HINT: KeyHint = { key: \"q\", does: \"back\" }\n\n/**\n * Terminal columns and rows a screen may use, clamped.\n *\n * Here rather than beside the one command that first needed them. They were exported from `browse.ts`,\n * which is imported both statically (by the wizard) and dynamically (by the command) — and the bundler\n * emitted the export twice, producing a `Duplicate export of 'windowFor'` that every test passed straight\n * through because tests import source, not the bundle. Screen arithmetic belongs with the screen.\n */\n/**\n * Zero means unknown, not zero.\n *\n * A pty genuinely reports a width of 0 — recorded in `lib/const.ts` beside `FALLBACK_COLUMNS`, measured\n * under `script -q`, and handled correctly in `useTerminalSize` since it was written. It was *not* handled\n * here, so a caller passing the stream's own measurement clamped to the 40-column floor and laid its rows\n * out for half the terminal. Found in a real capture: the session picker's rows came out 43 characters wide\n * on an 80-column screen, uniformly — which reads as a design choice rather than as a bug.\n *\n * `?? fallback` alone does not cover it, because 0 is not nullish. The same trap, one operator away.\n */\nfunction known(measured: number | undefined, fallback: number): number {\n return measured === undefined || measured <= 0 ? fallback : measured\n}\n\nexport function screenColumns(columns: number | undefined, fallback: number): number {\n return Math.max(MIN_SCREEN_COLUMNS, Math.min(MAX_SCREEN_COLUMNS, known(columns, fallback)))\n}\n\nexport function screenRows(rows: number | undefined, fallback: number): number {\n return Math.max(\n MIN_SCREEN_ROWS,\n Math.min(MAX_SCREEN_ROWS, known(rows, fallback) - SCREEN_CHROME_ROWS),\n )\n}\n"
6
+ ],
7
+ "mappings": ";mFAsEA,IAAM,EAAY,MAEZ,EAAiB,EAiBhB,SAAS,EAAW,CAAC,EAAsB,EAAsC,CACpF,IAAM,EAAsB,CAAC,CAAE,KAAM,QAAS,KAAM,EAAK,EAAO,MAAO,CAAK,CAAE,CAAC,EAKzE,EACF,EAAO,QAAU,OACX,EAAO,QACP,CAAC,GAAG,EAAO,MAAM,OAAO,IAAY,EAAO,MAAM,QAAS,EAAO,OAAO,EACnE,OAAO,CAAC,IAAS,IAAS,EAAE,EAC5B,KAAK,CAAS,EAC7B,GAAI,IAAU,GAAI,EAAM,KAAK,CAAE,KAAM,UAAW,KAAM,EAAK,EAAO,CAAK,CAAE,CAAC,EAE1E,IAAM,EAAQ,EAAO,OAAS,CAAC,EAC/B,GAAI,EAAM,OAAS,EACf,EAAM,KAAK,CACP,KAAM,QACN,KAAM,EAAK,EAAM,IAAI,CAAC,IAAS,EAAK,KAAK,EAAE,KAAK,CAAS,EAAG,CAAK,CACrE,CAAC,EAGL,IAAM,EAAW,EAAO,UAAY,CAAC,EACrC,QAAW,KAAW,EAAS,MAAM,EAAG,CAAc,EAClD,EAAM,KAAK,CAAE,KAAM,UAAW,KAAM,EAAK,KAAK,IAAW,CAAK,CAAE,CAAC,EAIrE,GAAI,EAAS,OAAS,EAClB,EAAM,KAAK,CACP,KAAM,UACN,KAAM,EAAK,SAAS,EAAS,OAAS,SAAuB,CAAK,CACtE,CAAC,EAGL,OAAO,EAWJ,SAAS,EAAQ,CAA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