ceulen 0.5.1 → 0.8.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 (367) hide show
  1. package/CHANGELOG.md +365 -12
  2. package/README.md +87 -91
  3. package/extensions/lib/advisor-marker.ts +33 -0
  4. package/extensions/lib/panel.ts +25 -2
  5. package/extensions/lib/rate.ts +24 -0
  6. package/extensions/lib/registry.test.ts +67 -0
  7. package/extensions/lib/registry.ts +104 -8
  8. package/extensions/lib/tools.ts +47 -0
  9. package/extensions/lib/usage-store.ts +33 -0
  10. package/extensions/modules/advisor/commands/advisor.ts +244 -0
  11. package/extensions/modules/advisor/configPanel.ts +194 -0
  12. package/extensions/modules/advisor/index.ts +235 -0
  13. package/extensions/modules/advisor/lib/config.ts +248 -0
  14. package/extensions/modules/advisor/lib/emission-guard.ts +153 -0
  15. package/extensions/modules/advisor/lib/isolated-model.ts +160 -0
  16. package/extensions/modules/advisor/lib/model-picker.ts +47 -0
  17. package/extensions/modules/advisor/lib/watcher.ts +288 -0
  18. package/extensions/modules/advisor/test/compliance.test.ts +125 -0
  19. package/extensions/modules/advisor/test/config.test.ts +202 -0
  20. package/extensions/modules/advisor/test/configPanel.test.ts +223 -0
  21. package/extensions/modules/advisor/test/emission-guard.test.ts +201 -0
  22. package/extensions/modules/advisor/test/isolated-model.test.ts +311 -0
  23. package/extensions/modules/advisor/test/model-picker.test.ts +32 -0
  24. package/extensions/modules/advisor/test/module.test.ts +649 -0
  25. package/extensions/modules/advisor/test/watcher.test.ts +478 -0
  26. package/extensions/modules/classifier/configPanel.ts +104 -0
  27. package/extensions/modules/classifier/index.ts +297 -0
  28. package/extensions/modules/classifier/lib/settings.ts +95 -0
  29. package/extensions/modules/classifier/test/classifier.test.ts +475 -0
  30. package/extensions/modules/composer/index.ts +152 -3
  31. package/extensions/modules/composer/lib/footer.ts +119 -0
  32. package/extensions/modules/composer/lib/shapes.ts +265 -26
  33. package/extensions/modules/composer/test/editor.test.ts +1 -1
  34. package/extensions/modules/composer/test/footer.test.ts +96 -0
  35. package/extensions/modules/composer/test/module.test.ts +113 -11
  36. package/extensions/modules/composer/test/screen.test.ts +29 -1
  37. package/extensions/modules/composer/test/shapes.test.ts +224 -8
  38. package/extensions/modules/config/defaultTools.ts +96 -0
  39. package/extensions/modules/config/index.ts +147 -7
  40. package/extensions/modules/config/piSettings.ts +254 -69
  41. package/extensions/modules/config/test/defaultTools.test.ts +122 -0
  42. package/extensions/modules/config/test/menu.test.ts +64 -0
  43. package/extensions/modules/config/test/panel.test.ts +38 -23
  44. package/extensions/modules/config/test/piSettings.test.ts +130 -3
  45. package/extensions/modules/config/test/renderTools.test.ts +71 -0
  46. package/extensions/modules/config/test/tools.test.ts +146 -0
  47. package/extensions/modules/fff/index.ts +2094 -0
  48. package/extensions/modules/fff/lib/query.ts +129 -0
  49. package/extensions/modules/fff/test/index.test.ts +607 -0
  50. package/extensions/modules/fff/test/query.test.ts +71 -0
  51. package/extensions/modules/munin/configPanel.ts +108 -0
  52. package/extensions/modules/munin/index.ts +641 -0
  53. package/extensions/modules/munin/lib/helpers.ts +471 -0
  54. package/extensions/modules/munin/lib/retry.ts +20 -0
  55. package/extensions/modules/munin/lib/sdk.ts +218 -0
  56. package/extensions/modules/munin/test/config.test.ts +168 -0
  57. package/extensions/modules/munin/test/configPanel.test.ts +186 -0
  58. package/extensions/modules/munin/test/extension.test.ts +224 -0
  59. package/extensions/modules/munin/test/helpers.test.ts +523 -0
  60. package/extensions/modules/munin/test/retry.test.ts +145 -0
  61. package/extensions/modules/munin/test/stale-protocol.test.ts +554 -0
  62. package/extensions/modules/plan/configPanel.ts +152 -0
  63. package/extensions/modules/plan/index.ts +917 -0
  64. package/extensions/modules/plan/lib/plan-tools.ts +72 -0
  65. package/extensions/modules/plan/lib/prompt.ts +65 -0
  66. package/extensions/modules/plan/lib/settings.ts +166 -0
  67. package/extensions/modules/plan/lib/shell-gate.ts +200 -0
  68. package/extensions/modules/plan/test/configPanel.test.ts +96 -0
  69. package/extensions/modules/plan/test/harness.ts +133 -0
  70. package/extensions/modules/plan/test/module.test.ts +305 -0
  71. package/extensions/modules/plan/test/settings.test.ts +114 -0
  72. package/extensions/modules/plan/test/shell-gate.test.ts +103 -0
  73. package/extensions/modules/ponytail/index.ts +23 -73
  74. package/extensions/modules/ponytail/lib/config.ts +1 -6
  75. package/extensions/modules/ponytail/test/extension.test.ts +1 -85
  76. package/extensions/modules/repair/configPanel.ts +96 -0
  77. package/extensions/modules/repair/index.ts +414 -0
  78. package/extensions/modules/repair/lib/auto-bg.ts +333 -0
  79. package/extensions/modules/repair/lib/edit-repair.ts +155 -0
  80. package/extensions/modules/repair/lib/editor.ts +251 -0
  81. package/extensions/modules/repair/lib/guards.ts +34 -0
  82. package/extensions/modules/repair/lib/input-repair.ts +324 -0
  83. package/extensions/modules/repair/lib/patch.ts +481 -0
  84. package/extensions/modules/repair/lib/settings.ts +114 -0
  85. package/extensions/modules/repair/test/auto-bg.test.ts +405 -0
  86. package/extensions/modules/repair/test/edit-repair.test.ts +224 -0
  87. package/extensions/modules/repair/test/editor.test.ts +141 -0
  88. package/extensions/modules/repair/test/guards.test.ts +64 -0
  89. package/extensions/modules/repair/test/input-repair.test.ts +231 -0
  90. package/extensions/modules/repair/test/patch.test.ts +563 -0
  91. package/extensions/modules/repair/test/settings.test.ts +167 -0
  92. package/extensions/modules/repair/test/wrapper.test.ts +210 -0
  93. package/extensions/modules/router/commands/commands.ts +4 -0
  94. package/extensions/modules/router/configPanel.ts +24 -10
  95. package/extensions/modules/router/lib/client.ts +63 -0
  96. package/extensions/modules/router/lib/provider.ts +34 -13
  97. package/extensions/modules/router/lib/systemone.ts +152 -0
  98. package/extensions/modules/router/test/unit.test.ts +260 -0
  99. package/extensions/modules/rtk/findFallback.js +68 -0
  100. package/extensions/modules/rtk/index.ts +248 -0
  101. package/extensions/modules/rtk/safe-rewrite.js +74 -0
  102. package/extensions/modules/rtk/test/findFallback.test.js +66 -0
  103. package/extensions/modules/rtk/test/index.test.js +131 -0
  104. package/extensions/modules/rtk/test/safe-rewrite.test.js +96 -0
  105. package/extensions/modules/rtk/version-gate.js +34 -0
  106. package/extensions/modules/rules/index.ts +120 -0
  107. package/extensions/modules/rules/lib/rules.ts +348 -0
  108. package/extensions/modules/rules/test/lib.test.ts +263 -0
  109. package/extensions/modules/rules/test/module.test.ts +222 -0
  110. package/extensions/modules/serena/index.ts +629 -0
  111. package/extensions/modules/serena/lib/detect.ts +73 -0
  112. package/extensions/modules/serena/lib/env.ts +76 -0
  113. package/extensions/modules/serena/lib/guidance.ts +26 -0
  114. package/extensions/modules/serena/lib/normalize.ts +27 -0
  115. package/extensions/modules/serena/lib/symbol-key.ts +20 -0
  116. package/extensions/modules/serena/lib/truncate.ts +20 -0
  117. package/extensions/modules/serena/test/env.test.ts +122 -0
  118. package/extensions/modules/serena/test/index.test.ts +347 -0
  119. package/extensions/modules/serena/test/worker.test.ts +562 -0
  120. package/extensions/modules/serena/worker.ts +858 -0
  121. package/extensions/modules/steering/configPanel.ts +122 -0
  122. package/extensions/modules/steering/index.ts +616 -0
  123. package/extensions/modules/steering/lib/anchor.ts +175 -0
  124. package/extensions/modules/steering/lib/errors.ts +253 -0
  125. package/extensions/modules/steering/lib/family.ts +33 -0
  126. package/extensions/modules/steering/lib/guidance.ts +172 -0
  127. package/extensions/modules/steering/lib/history.ts +170 -0
  128. package/extensions/modules/steering/lib/settings.ts +127 -0
  129. package/extensions/modules/steering/test/anchor-regressions.test.ts +93 -0
  130. package/extensions/modules/steering/test/anchor-wiring.test.ts +99 -0
  131. package/extensions/modules/steering/test/anchor.test.ts +160 -0
  132. package/extensions/modules/steering/test/cache-stats.test.ts +43 -0
  133. package/extensions/modules/steering/test/errors.test.ts +309 -0
  134. package/extensions/modules/steering/test/family.test.ts +43 -0
  135. package/extensions/modules/steering/test/guidance.test.ts +357 -0
  136. package/extensions/modules/steering/test/harness.ts +93 -0
  137. package/extensions/modules/steering/test/history.test.ts +118 -0
  138. package/extensions/modules/steering/test/settings.test.ts +182 -0
  139. package/extensions/modules/steering/test/status.test.ts +71 -0
  140. package/extensions/modules/steering/test/toolCall.test.ts +99 -0
  141. package/extensions/modules/subagent/agents/planner.md +14 -0
  142. package/extensions/modules/subagent/agents/reviewer.md +42 -0
  143. package/extensions/modules/subagent/agents/scout.md +47 -0
  144. package/extensions/modules/subagent/agents/tester.md +12 -0
  145. package/extensions/modules/subagent/agents/worker.md +18 -0
  146. package/extensions/modules/subagent/configPanel.ts +219 -0
  147. package/extensions/modules/subagent/index.ts +2464 -0
  148. package/extensions/modules/subagent/lib/agents.ts +408 -0
  149. package/extensions/modules/subagent/lib/background.ts +383 -0
  150. package/extensions/modules/subagent/lib/herdr.ts +1019 -0
  151. package/extensions/modules/subagent/lib/history.ts +126 -0
  152. package/extensions/modules/subagent/lib/model.ts +156 -0
  153. package/extensions/modules/subagent/lib/render.ts +335 -0
  154. package/extensions/modules/subagent/lib/result.ts +110 -0
  155. package/extensions/modules/subagent/lib/roles.ts +296 -0
  156. package/extensions/modules/subagent/lib/routing.ts +228 -0
  157. package/extensions/modules/subagent/lib/runner.ts +559 -0
  158. package/extensions/modules/subagent/lib/schema.ts +21 -0
  159. package/extensions/modules/subagent/lib/security.ts +763 -0
  160. package/extensions/modules/subagent/lib/settings.ts +159 -0
  161. package/extensions/modules/subagent/lib/thread-viewer.ts +319 -0
  162. package/extensions/modules/subagent/lib/threads.ts +135 -0
  163. package/extensions/modules/subagent/lib/types.ts +18 -0
  164. package/extensions/modules/subagent/lib/widget.ts +475 -0
  165. package/extensions/modules/subagent/test/configPanel.test.ts +132 -0
  166. package/extensions/modules/subagent/test/herdr-advisor.test.ts +40 -0
  167. package/extensions/modules/subagent/test/routing.test.ts +524 -0
  168. package/extensions/modules/subagent/test/widget.test.ts +208 -0
  169. package/extensions/modules/todo/index.ts +478 -0
  170. package/extensions/modules/todo/test/todo.test.ts +252 -0
  171. package/extensions/modules/usage/index.ts +70 -16
  172. package/extensions/modules/usage/test/genrate.test.ts +70 -0
  173. package/extensions/modules/usage/test/parsers.test.ts +13 -0
  174. package/extensions/modules/usage/test/session-accumulators.test.ts +85 -0
  175. package/extensions/modules/ux/UPSTREAM +24 -0
  176. package/extensions/modules/ux/index.ts +393 -0
  177. package/extensions/modules/ux/lib/audit.ts +562 -0
  178. package/extensions/modules/ux/lib/config.ts +136 -0
  179. package/extensions/modules/ux/lib/instructions.ts +77 -0
  180. package/extensions/modules/ux/test/audit.test.ts +756 -0
  181. package/extensions/modules/ux/test/extension.test.ts +394 -0
  182. package/extensions/modules/ux/test/instructions.test.ts +19 -0
  183. package/extensions/modules/web/configPanel.ts +218 -0
  184. package/extensions/modules/web/index.ts +978 -0
  185. package/extensions/modules/web/lib/agy.ts +209 -0
  186. package/extensions/modules/web/lib/brave.ts +42 -0
  187. package/extensions/modules/web/lib/cdp.ts +686 -0
  188. package/extensions/modules/web/lib/chatapi.ts +101 -0
  189. package/extensions/modules/web/lib/chatgpt.ts +796 -0
  190. package/extensions/modules/web/lib/chrome.ts +328 -0
  191. package/extensions/modules/web/lib/config.ts +136 -0
  192. package/extensions/modules/web/lib/content.ts +99 -0
  193. package/extensions/modules/web/lib/crawl4ai.ts +172 -0
  194. package/extensions/modules/web/lib/extract.ts +235 -0
  195. package/extensions/modules/web/lib/firecrawl.ts +56 -0
  196. package/extensions/modules/web/lib/format.ts +197 -0
  197. package/extensions/modules/web/lib/gemini-auth.ts +286 -0
  198. package/extensions/modules/web/lib/gemini-dr.ts +338 -0
  199. package/extensions/modules/web/lib/gemini.ts +551 -0
  200. package/extensions/modules/web/lib/imageapi.ts +559 -0
  201. package/extensions/modules/web/lib/retry.ts +71 -0
  202. package/extensions/modules/web/lib/search.ts +237 -0
  203. package/extensions/modules/web/lib/searxng.ts +69 -0
  204. package/extensions/modules/web/lib/settings.ts +157 -0
  205. package/extensions/modules/web/scripts/cdp-smoke.ts +77 -0
  206. package/extensions/modules/web/scripts/gemini-smoke.ts +107 -0
  207. package/extensions/modules/web/test/agy.test.ts +383 -0
  208. package/extensions/modules/web/test/cdp.test.ts +717 -0
  209. package/extensions/modules/web/test/chat.test.ts +171 -0
  210. package/extensions/modules/web/test/chatgpt.test.ts +633 -0
  211. package/extensions/modules/web/test/chrome.test.ts +282 -0
  212. package/extensions/modules/web/test/config.test.ts +218 -0
  213. package/extensions/modules/web/test/configPanel.test.ts +198 -0
  214. package/extensions/modules/web/test/crawl.test.ts +134 -0
  215. package/extensions/modules/web/test/crawl4ai.test.ts +105 -0
  216. package/extensions/modules/web/test/extension.test.ts +118 -0
  217. package/extensions/modules/web/test/extract.test.ts +436 -0
  218. package/extensions/modules/web/test/fixtures/dr-confirm.bin +12 -0
  219. package/extensions/modules/web/test/fixtures/dr-plan.bin +20 -0
  220. package/extensions/modules/web/test/fixtures/interaction.html +31 -0
  221. package/extensions/modules/web/test/format.test.ts +230 -0
  222. package/extensions/modules/web/test/gemini-auth.test.ts +465 -0
  223. package/extensions/modules/web/test/gemini-dr.test.ts +249 -0
  224. package/extensions/modules/web/test/gemini.test.ts +472 -0
  225. package/extensions/modules/web/test/hook.test.ts +101 -0
  226. package/extensions/modules/web/test/image.test.ts +1089 -0
  227. package/extensions/modules/web/test/retry.test.ts +119 -0
  228. package/extensions/modules/web/test/screenshot.test.ts +109 -0
  229. package/extensions/modules/web/test/search.test.ts +210 -0
  230. package/extensions/modules/web/test/settings.test.ts +165 -0
  231. package/extensions/modules/web/test/skill.test.ts +72 -0
  232. package/extensions/modules/web/types.d.ts +3 -0
  233. package/extensions/modules/web/vendor/package.json +1 -0
  234. package/extensions/modules/web/vendor/readability/LICENSE.md +13 -0
  235. package/extensions/modules/web/vendor/readability/Readability-readerable.js +123 -0
  236. package/extensions/modules/web/vendor/readability/Readability.js +2787 -0
  237. package/extensions/modules/web/vendor/readability/index.d.ts +64 -0
  238. package/extensions/modules/web/vendor/readability/index.js +9 -0
  239. package/extensions/modules/web/vendor/turndown/LICENSE +21 -0
  240. package/extensions/modules/web/vendor/turndown/turndown.cjs.js +784 -0
  241. package/extensions/modules/web/vendor/turndown-plugin-gfm/LICENSE +21 -0
  242. package/extensions/modules/web/vendor/turndown-plugin-gfm/turndown-plugin-gfm.cjs.js +163 -0
  243. package/extensions/modules/zai/configPanel.ts +154 -0
  244. package/extensions/modules/zai/index.ts +186 -0
  245. package/extensions/modules/zai/lib/anthropic.ts +159 -0
  246. package/extensions/modules/zai/lib/settings.ts +198 -0
  247. package/extensions/modules/zai/lib/signing.ts +721 -0
  248. package/extensions/modules/zai/lib/throttle.ts +198 -0
  249. package/extensions/modules/zai/test/anthropic.test.ts +132 -0
  250. package/extensions/modules/zai/test/configPanel.test.ts +230 -0
  251. package/extensions/modules/zai/test/extension.test.ts +249 -0
  252. package/extensions/modules/zai/test/settings.test.ts +183 -0
  253. package/extensions/modules/zai/test/signing-wiring.test.ts +108 -0
  254. package/extensions/modules/zai/test/signing.test.ts +364 -0
  255. package/extensions/modules/zai/test/throttle.test.ts +329 -0
  256. package/package.json +19 -4
  257. package/scripts/validate-themes.mjs +75 -0
  258. package/skills/munin/SKILL.md +117 -0
  259. package/skills/ux-capture/SKILL.md +202 -0
  260. package/skills/ux-design/SKILL.md +279 -0
  261. package/skills/ux-presets/SKILL.md +484 -0
  262. package/skills/ux-routing/SKILL.md +46 -0
  263. package/skills/web/SKILL.md +153 -0
  264. package/themes/alabaster.json +93 -0
  265. package/themes/amethyst.json +96 -0
  266. package/themes/anthracite.json +93 -0
  267. package/themes/basalt.json +91 -0
  268. package/themes/birch.json +95 -0
  269. package/themes/catppuccin-mocha.json +91 -0
  270. package/themes/dark-abyss.json +91 -0
  271. package/themes/dark-arctic.json +104 -0
  272. package/themes/dark-aurora.json +95 -0
  273. package/themes/dark-catppuccin.json +107 -0
  274. package/themes/dark-cavern.json +91 -0
  275. package/themes/dark-celestial.json +106 -0
  276. package/themes/dark-copper.json +95 -0
  277. package/themes/dark-cosmos.json +90 -0
  278. package/themes/dark-cyberpunk.json +102 -0
  279. package/themes/dark-dracula.json +98 -0
  280. package/themes/dark-eclipse.json +91 -0
  281. package/themes/dark-ember.json +95 -0
  282. package/themes/dark-equinox.json +90 -0
  283. package/themes/dark-forest.json +96 -0
  284. package/themes/dark-github.json +105 -0
  285. package/themes/dark-gruvbox.json +112 -0
  286. package/themes/dark-lavender.json +95 -0
  287. package/themes/dark-lunar.json +89 -0
  288. package/themes/dark-midnight.json +95 -0
  289. package/themes/dark-monochrome.json +94 -0
  290. package/themes/dark-monokai.json +98 -0
  291. package/themes/dark-nebula.json +90 -0
  292. package/themes/dark-neon-noir.json +100 -0
  293. package/themes/dark-nord.json +98 -0
  294. package/themes/dark-ocean.json +101 -0
  295. package/themes/dark-one.json +100 -0
  296. package/themes/dark-poimandres.json +115 -0
  297. package/themes/dark-rainforest.json +91 -0
  298. package/themes/dark-reef.json +91 -0
  299. package/themes/dark-retro.json +92 -0
  300. package/themes/dark-rose-pine.json +96 -0
  301. package/themes/dark-sakura.json +95 -0
  302. package/themes/dark-slate.json +95 -0
  303. package/themes/dark-solarized.json +97 -0
  304. package/themes/dark-solstice.json +90 -0
  305. package/themes/dark-starfall.json +91 -0
  306. package/themes/dark-sunset.json +99 -0
  307. package/themes/dark-swamp.json +90 -0
  308. package/themes/dark-synthwave.json +103 -0
  309. package/themes/dark-taiga.json +91 -0
  310. package/themes/dark-terminal.json +95 -0
  311. package/themes/dark-tokyo-night.json +101 -0
  312. package/themes/dark-tundra.json +91 -0
  313. package/themes/dark-twilight.json +91 -0
  314. package/themes/dark-volcanic.json +91 -0
  315. package/themes/dark.json +80 -0
  316. package/themes/graphite.json +92 -0
  317. package/themes/light-arctic.json +107 -0
  318. package/themes/light-aurora-day.json +91 -0
  319. package/themes/light-canyon.json +91 -0
  320. package/themes/light-catppuccin.json +106 -0
  321. package/themes/light-cirrus.json +90 -0
  322. package/themes/light-coral.json +95 -0
  323. package/themes/light-cyberpunk.json +96 -0
  324. package/themes/light-dawn.json +90 -0
  325. package/themes/light-dunes.json +91 -0
  326. package/themes/light-eucalyptus.json +95 -0
  327. package/themes/light-forest.json +100 -0
  328. package/themes/light-frost.json +95 -0
  329. package/themes/light-github.json +115 -0
  330. package/themes/light-glacier.json +91 -0
  331. package/themes/light-gruvbox.json +108 -0
  332. package/themes/light-haze.json +90 -0
  333. package/themes/light-honeycomb.json +95 -0
  334. package/themes/light-lagoon.json +91 -0
  335. package/themes/light-lavender.json +95 -0
  336. package/themes/light-meadow.json +91 -0
  337. package/themes/light-mint.json +95 -0
  338. package/themes/light-monochrome.json +101 -0
  339. package/themes/light-ocean.json +99 -0
  340. package/themes/light-one.json +99 -0
  341. package/themes/light-opal.json +91 -0
  342. package/themes/light-orchard.json +91 -0
  343. package/themes/light-paper.json +95 -0
  344. package/themes/light-poimandres.json +115 -0
  345. package/themes/light-prism.json +90 -0
  346. package/themes/light-retro.json +98 -0
  347. package/themes/light-sand.json +95 -0
  348. package/themes/light-savanna.json +91 -0
  349. package/themes/light-solarized.json +102 -0
  350. package/themes/light-soleil.json +90 -0
  351. package/themes/light-sunset.json +99 -0
  352. package/themes/light-synthwave.json +98 -0
  353. package/themes/light-tokyo-night.json +111 -0
  354. package/themes/light-wetland.json +91 -0
  355. package/themes/light-zenith.json +89 -0
  356. package/themes/light.json +80 -0
  357. package/themes/limestone.json +94 -0
  358. package/themes/mahogany.json +97 -0
  359. package/themes/marble.json +93 -0
  360. package/themes/mirage.json +79 -0
  361. package/themes/obsidian.json +91 -0
  362. package/themes/onyx.json +91 -0
  363. package/themes/pearl.json +93 -0
  364. package/themes/porcelain.json +91 -0
  365. package/themes/quartz.json +96 -0
  366. package/themes/sandstone.json +95 -0
  367. package/themes/titanium.json +90 -0
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Composer footer — replaces pi's built-in footer WHERE the composer's status
3
+ * band already carries the stock info. The band owns identity + context + the
4
+ * session token stats + provider quota windows; this footer keeps only what
5
+ * the band does NOT show: every other extension's `setStatus` items (plan
6
+ * mode, rtk, serena, ux, accordion — kept for the later port).
7
+ *
8
+ * Shapes WITHOUT an embedded band (pi · borderless · field · rail) keep pi's
9
+ * NATIVE footer — there the footer is the only place that info appears.
10
+ *
11
+ * Lifecycle: pi's `resetExtensionUI()` calls `setExtensionFooter(undefined)` on
12
+ * session replacement (new/resume/fork/reload), so this re-arms on
13
+ * `session_start` — the same contract the shape editor relies on.
14
+ */
15
+
16
+ import { truncateToWidth, type Component } from "@earendil-works/pi-tui";
17
+ import { formatCompact, type ShapeTheme } from "./shapes.ts";
18
+
19
+ /** Usage fields the totals read (structural — pi's Usage satisfies it). */
20
+ interface UsageLike {
21
+ input?: number;
22
+ output?: number;
23
+ cacheRead?: number;
24
+ cacheWrite?: number;
25
+ }
26
+
27
+ /** Session-entry slice the totals read (structural — pi's SessionEntry fits). */
28
+ interface EntryLike {
29
+ type?: string;
30
+ usage?: UsageLike | null;
31
+ message?: { role?: string; usage?: UsageLike | null };
32
+ }
33
+
34
+ export interface SessionTotals {
35
+ input: number;
36
+ output: number;
37
+ cacheRead: number;
38
+ cacheWrite: number;
39
+ /** Cache-read share of the latest assistant prompt, when computable. */
40
+ cacheHitRate?: number;
41
+ }
42
+
43
+ export const EMPTY_TOTALS: SessionTotals = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
44
+
45
+ const num = (v: unknown): number => {
46
+ const n = Number(v);
47
+ return Number.isFinite(n) ? n : 0;
48
+ };
49
+
50
+ /** Sum session usage exactly like pi's own footer: `usage` entries, assistant
51
+ * and toolResult messages, compaction/branch summaries. */
52
+ export function sessionTotals(entries: readonly EntryLike[]): SessionTotals {
53
+ const t: SessionTotals = { ...EMPTY_TOTALS };
54
+ for (const e of entries) {
55
+ let u: UsageLike | null | undefined;
56
+ if (e.type === "usage") u = e.usage;
57
+ else if (e.type === "message" && (e.message?.role === "assistant" || e.message?.role === "toolResult")) u = e.message.usage;
58
+ else if (e.type === "compaction" || e.type === "branch_summary") u = e.usage;
59
+ if (!u) continue;
60
+ t.input += num(u.input);
61
+ t.output += num(u.output);
62
+ t.cacheRead += num(u.cacheRead);
63
+ t.cacheWrite += num(u.cacheWrite);
64
+ if (e.type === "message" && e.message?.role === "assistant") {
65
+ const prompt = num(u.input) + num(u.cacheRead) + num(u.cacheWrite);
66
+ if (prompt > 0) t.cacheHitRate = (num(u.cacheRead) / prompt) * 100;
67
+ }
68
+ }
69
+ return t;
70
+ }
71
+
72
+ /** Band token stats for line 1 (`↑1.9M ↓377k R69M CH99.7%` — cost stays
73
+ * /usage-only; "" before any usage). */
74
+ export function statsLine(t: SessionTotals): string {
75
+ const parts: string[] = [];
76
+ if (t.input) parts.push(`↑${formatCompact(t.input)}`);
77
+ if (t.output) parts.push(`↓${formatCompact(t.output)}`);
78
+ if (t.cacheRead) parts.push(`R${formatCompact(t.cacheRead)}`);
79
+ if (t.cacheWrite) parts.push(`W${formatCompact(t.cacheWrite)}`);
80
+ if (t.cacheHitRate !== undefined) parts.push(`CH${t.cacheHitRate.toFixed(1)}%`);
81
+ return parts.join(" ");
82
+ }
83
+
84
+ /** One status string per line: control chars out, runs of spaces collapsed
85
+ * (pi's own sanitizeStatusText). */
86
+ const sanitize = (s: string) => s.replace(/[\r\n\t]/g, " ").replace(/ +/g, " ").trim();
87
+
88
+ export interface ComposerFooterDeps {
89
+ /** Extension status texts, already key-sorted by the caller. */
90
+ statuses: () => readonly string[];
91
+ }
92
+
93
+ /** The replacement footer component: one line of extension statuses. */
94
+ export class ComposerFooter implements Component {
95
+ private deps: ComposerFooterDeps;
96
+
97
+ constructor(deps: ComposerFooterDeps) {
98
+ this.deps = deps;
99
+ }
100
+
101
+ render(width: number): string[] {
102
+ const lines: string[] = [];
103
+ try {
104
+ const statuses = this.deps.statuses().map(sanitize).filter(Boolean).join(" ");
105
+ if (statuses) lines.push(truncateToWidth(statuses, width, "…"));
106
+ } catch {
107
+ // A core surface must never take the frame down.
108
+ }
109
+ return lines;
110
+ }
111
+
112
+ invalidate(): void {
113
+ // Reads live closures per render — nothing cached here.
114
+ }
115
+
116
+ dispose(): void {
117
+ // No timers or subscriptions.
118
+ }
119
+ }
@@ -10,20 +10,52 @@
10
10
  * fill) without touching text, wrapping, or cursor placement.
11
11
  *
12
12
  * Status: shapes that embed a status line in their chrome (band · box ·
13
- * claude · rule) render model · dir · context% from live session data.
14
- * OMP's standalone BOTTOM status bar has no twin here — pi's own footer
15
- * already sits under the editor for every shape.
13
+ * claude · rule) render OMP's stock info split — left group (model · dir
14
+ * (branch) · Generation Rate) flush-left, right group (`0.0%/1.0M` context
15
+ * window) justified right on the band, docked on the rule chip. OMP's
16
+ * standalone BOTTOM status bar has no twin here — pi's own footer already
17
+ * sits under the editor for every shape.
16
18
  */
17
19
 
18
20
  import { CustomEditor } from "@earendil-works/pi-coding-agent";
19
21
  import { sliceByColumn, truncateToWidth, visibleWidth, type EditorTheme, type KeybindingsManager, type TUI } from "@earendil-works/pi-tui";
22
+ import { existsSync, readFileSync, statSync } from "node:fs";
23
+ import { dirname, isAbsolute, join, resolve } from "node:path";
20
24
 
21
25
  /** Live data the status line shows (fail-soft to blanks). */
22
26
  export interface BandData {
23
27
  model?: string;
28
+ /** Router/provider prefix of the model id, shown before the model. */
29
+ provider?: string;
30
+ /** Current thinking level (pi's ThinkingLevel, rendered after the model). */
31
+ thinkingLevel?: string;
32
+ /** Display cwd (`~/…`-relative, pi-footer parity). */
24
33
  cwd?: string;
34
+ /** Current git branch, "detached", or null outside a repo. */
35
+ branch?: string | null;
36
+ /** Working-tree counts (`*` unstaged, `+` staged, `?` untracked). */
37
+ git?: GitStats | null;
25
38
  /** Context-window usage percent, when known. */
26
39
  pct?: number | null;
40
+ /** Context window size in tokens, when known. */
41
+ window?: number;
42
+ /** Auto-compaction armed (pi's footer `(auto)` marker). */
43
+ autoCompact?: boolean;
44
+ /** Generation Rate: last response's tok/s. */
45
+ rate?: number;
46
+ /** Provider quota windows from the usage module (e.g. `(router) R:59%/2H3M`). */
47
+ usage?: string;
48
+ /** Usage tone — warning/error when quota runs low, dim otherwise. */
49
+ usageTone?: "dim" | "warning" | "error";
50
+ /** Session token stats, pi-footer format (e.g. `↑1.9M ↓377k R69M CH99.7%`). */
51
+ stats?: string;
52
+ }
53
+
54
+ /** Working-tree change counts (OMP's git segment indicators). */
55
+ export interface GitStats {
56
+ staged: number;
57
+ unstaged: number;
58
+ untracked: number;
27
59
  }
28
60
 
29
61
  /** Styling hooks — the live editor and the /config preview both build these
@@ -34,6 +66,7 @@ export interface ShapeTheme {
34
66
  text: (s: string) => string;
35
67
  dim: (s: string) => string;
36
68
  warn: (s: string) => string;
69
+ error: (s: string) => string;
37
70
  /** Filled surface (background + on-surface foreground), robust to nested
38
71
  * SGR resets — the cursor glyph emits one, which would otherwise drop the
39
72
  * fill from that point on (OMP's bgFill). */
@@ -47,6 +80,7 @@ export const IDENTITY_THEME: ShapeTheme = {
47
80
  text: (s) => s,
48
81
  dim: (s) => s,
49
82
  warn: (s) => s,
83
+ error: (s) => s,
50
84
  fill: (s) => s,
51
85
  inverse: (s) => s,
52
86
  };
@@ -69,6 +103,7 @@ export function shapeTheme(t: ThemeLike): ShapeTheme {
69
103
  text: (s) => t.fg("text" as never, s),
70
104
  dim: (s) => t.fg("dim" as never, s),
71
105
  warn: (s) => t.fg("warning" as never, s),
106
+ error: (s) => t.fg("error" as never, s),
72
107
  fill: surfacePainter(bg + onBg),
73
108
  inverse: (s) => t.inverse?.(s) ?? s,
74
109
  };
@@ -80,8 +115,10 @@ export interface ShapeCtx {
80
115
  /** Content lines scrolled out of view. */
81
116
  hidden: number;
82
117
  theme: ShapeTheme;
83
- /** Pre-styled status line, when the shape embeds one. */
84
- status?: string;
118
+ /** Live session data for the embedded status line. */
119
+ data?: BandData;
120
+ /** Working-spinner glyph, joined into the status left group. */
121
+ spinner?: string;
85
122
  /** The active shape's prompt gutter (wired in at render time so row
86
123
  * builders can align continuation rows without a second parameter). */
87
124
  gutter?: string;
@@ -127,18 +164,116 @@ export function surfacePainter(prefix: string): (s: string) => string {
127
164
  return (s) => (prefix === "" ? s : prefix + s.replace(/\x1b\[0m/g, `\x1b[0m${prefix}`) + "\x1b[39m\x1b[49m");
128
165
  }
129
166
 
130
- /** One styled status line: model · dir · context% (segments drop out when the
131
- * session hasn't provided them — never wrong, just shorter). */
132
- export function statusLine(data: BandData | undefined, theme: ShapeTheme): string {
133
- const sep = theme.dim(" · ");
167
+ /** Compact token counts for the context window — pi-footer/OMP parity
168
+ * (`200k`, `1.0M`). */
169
+ export function formatCompact(n: number): string {
170
+ if (!Number.isFinite(n) || n < 0) return "0";
171
+ if (n < 1000) return `${Math.round(n)}`;
172
+ if (n < 1_000_000) return `${(n / 1000).toFixed(n < 10_000 ? 1 : 0)}k`;
173
+ return `${(n / 1_000_000).toFixed(n < 10_000_000 ? 1 : 0)}M`;
174
+ }
175
+
176
+ /** Composer status icons — OMP's unicode glyph set, so every shape speaks the
177
+ * same visual language: brand mark before the model, folder on the working
178
+ * dir, branch glyph on the git segment, throughput on the Generation Rate. */
179
+ export const ICONS = {
180
+ brand: "π",
181
+ folder: "📁",
182
+ branch: "⑂",
183
+ throughput: "⚡",
184
+ } as const;
185
+
186
+ /** Context-window segment: `0.0%/1.0M` (one-decimal pct + compact window),
187
+ * color-stepped like pi's footer (>70 warning, >90 error). */
188
+ function contextSegment(data: BandData, theme: ShapeTheme): string {
189
+ const pct = typeof data.pct === "number" && Number.isFinite(data.pct) ? data.pct : undefined;
190
+ const win = typeof data.window === "number" && data.window > 0 ? formatCompact(data.window) : undefined;
191
+ if (pct === undefined && win === undefined) return "";
192
+ const text = (pct !== undefined ? `${pct.toFixed(1)}%${win ? `/${win}` : ""}` : `${win}/?`) + (data.autoCompact ? " (auto)" : "");
193
+ if (pct !== undefined && pct > 90) return theme.error(text);
194
+ if (pct !== undefined && pct > 70) return theme.warn(text);
195
+ return theme.dim(text);
196
+ }
197
+
198
+ /** Git segment: `⑂ main *3 +1 ?2` — branch + OMP's working-tree indicators
199
+ * (`*` unstaged, `+` staged, `?` untracked). A dirty tree renders `warning`. */
200
+ function gitSegment(data: BandData, theme: ShapeTheme): string {
201
+ const branch = typeof data.branch === "string" && data.branch.trim() ? data.branch.trim() : "";
202
+ const g = data.git;
203
+ const dirty = !!g && g.staged + g.unstaged + g.untracked > 0;
134
204
  const parts: string[] = [];
135
- if (data?.model?.trim()) parts.push(theme.accent(data.model.trim()));
136
- if (data?.cwd?.trim()) parts.push(theme.dim(data.cwd.trim()));
137
- if (typeof data?.pct === "number" && Number.isFinite(data.pct)) {
138
- const pct = Math.round(data.pct);
139
- parts.push(pct > 80 ? theme.warn(`${pct}%`) : theme.dim(`${pct}%`));
205
+ if (branch) parts.push(`${ICONS.branch} ${branch}`);
206
+ if (dirty && g) {
207
+ if (g.unstaged > 0) parts.push(`*${g.unstaged}`);
208
+ if (g.staged > 0) parts.push(`+${g.staged}`);
209
+ if (g.untracked > 0) parts.push(`?${g.untracked}`);
140
210
  }
141
- return parts.join(sep);
211
+ if (parts.length === 0) return "";
212
+ return dirty ? theme.warn(parts.join(" ")) : theme.dim(parts.join(" "));
213
+ }
214
+
215
+ /** The status line's stock groups (OMP's segment split): left = identity
216
+ * (model · dir · git · Generation Rate), right = context window.
217
+ * Segments drop out when the session hasn't provided them — never wrong,
218
+ * just shorter. Every segment carries its icon. */
219
+ export function statusSegments(
220
+ data: BandData | undefined,
221
+ theme: ShapeTheme,
222
+ spinner?: string,
223
+ ): { left: string; right: string } {
224
+ return { left: identitySegments(data, theme, spinner).join(theme.dim(" · ")), right: data ? contextSegment(data, theme) : "" };
225
+ }
226
+
227
+ /** The identity group as separate styled segments, brand first — callers that
228
+ * must fit a fixed width shed WHOLE trailing segments (stats → rate → usage
229
+ * → git → dir) rather than cutting one in half (OMP's overflow behavior). */
230
+ export function identitySegments(data: BandData | undefined, theme: ShapeTheme, spinner?: string): string[] {
231
+ const identity: string[] = [];
232
+ // Model cluster — model info only for now: usage windows + token stats are
233
+ // dropped from the band at the user's request (restore = push usageSegment
234
+ // + stats back into this cluster, see git history).
235
+ const cluster: string[] = [];
236
+ // Model segment: `(provider) model (level)` — provider prefix from the model
237
+ // id (a router model's upstream slug), thinking level in parens, OMP's
238
+ // model-segment shape (its `showThinkingLevel` option).
239
+ const model = data?.model?.trim();
240
+ if (model) {
241
+ const provider = data?.provider?.trim();
242
+ const level = data?.thinkingLevel?.trim();
243
+ // Skip the prefix when the display name already carries it (direct
244
+ // providers register names like `zai/glm-5.3-flash` under provider `zai`).
245
+ const prefix = provider && !model.toLowerCase().startsWith(provider.toLowerCase() + "/") ? `(${provider}) ` : "";
246
+ let label = prefix + model;
247
+ if (level && level !== "off") label += ` (${level})`;
248
+ cluster.push(theme.accent(label));
249
+ }
250
+ if (cluster.length > 0) identity.push(cluster.join(theme.dim(" | ")));
251
+ const cwd = data?.cwd?.trim();
252
+ if (cwd) identity.push(theme.dim(`${ICONS.folder} ${cwd}`));
253
+ const git = data ? gitSegment(data, theme) : "";
254
+ if (git) identity.push(git);
255
+ // Generation rate renders as its own right-justified line ABOVE the band
256
+ // (OMP's throughline placement) — not a band segment.
257
+ // The brand leads ONLY a group that exists (OMP's pi segment): with nothing
258
+ // to identify, the band stays blank so the layout never shifts on startup.
259
+ // While a turn runs the working spinner takes the brand slot.
260
+ const lead = identity.length > 0 || spinner ? spinner ?? theme.accent(ICONS.brand) : undefined;
261
+ return lead ? [lead, ...identity] : identity;
262
+ }
263
+
264
+ /** One composed status line: left flush-left, right justified right. Over-
265
+ * budget, the LEFT group yields first (OMP's priority — the context window
266
+ * stays); the right group is truncated only when it alone overflows. */
267
+ export function composeStatus(left: string, right: string, w: number): string {
268
+ const rw = visibleWidth(right);
269
+ if (!right) return left;
270
+ if (!left) return rw > w ? truncateToWidth(right, Math.max(1, w), "…") : right;
271
+ const lw = visibleWidth(left);
272
+ const gap = w - lw - rw;
273
+ if (gap >= 1) return left + spaces(gap) + right;
274
+ const room = w - rw - 1;
275
+ if (room <= 0) return truncateToWidth(right, Math.max(1, w), "…");
276
+ return truncateToWidth(left, room, "…") + " " + right;
142
277
  }
143
278
 
144
279
  function rule(w: number, th: ShapeTheme): string {
@@ -161,8 +296,12 @@ function ruleWithScroll(w: number, hidden: number, th: ShapeTheme): string {
161
296
  /** Right-docked status chip on a rule (OMP's renderTopRule: left fill, status
162
297
  * at the right edge, one rule cell after it). */
163
298
  function topRuleChip(c: ShapeCtx): string {
164
- const { w, theme, status } = c;
165
- if (status && visibleWidth(status) > 0 && w > 2) {
299
+ const { w, theme } = c;
300
+ const { left, right } = statusSegments(c.data, theme, c.spinner);
301
+ // The chip is the compact `left · right` join — full-width justification is
302
+ // the band's job, not a right-docked chip's.
303
+ const status = [left, right].filter(Boolean).join(theme.dim(" · "));
304
+ if (visibleWidth(status) > 0 && w > 2) {
166
305
  const content = visibleWidth(status) > w - 2 ? truncateToWidth(status, w - 2, "…") : status;
167
306
  return theme.border("─".repeat(Math.max(0, w - visibleWidth(content) - 1))) + content + theme.border("─");
168
307
  }
@@ -172,19 +311,68 @@ function topRuleChip(c: ShapeCtx): string {
172
311
  /** Flush soft-capped status band (no frame). Reserved row: blank when the
173
312
  * status has nothing to show yet, so the layout never shifts. */
174
313
  function bandTop(c: ShapeCtx): string {
175
- const { w, theme, status } = c;
176
- if (!status || visibleWidth(status) === 0) return "";
314
+ const { w, theme } = c;
315
+ const segs = identitySegments(c.data, theme, c.spinner);
316
+ const right = c.data ? contextSegment(c.data, theme) : "";
177
317
  const cap = theme.accent("╭─");
178
318
  const scroll = c.hidden > 0 ? theme.border(` ↑${c.hidden} `) : "";
179
319
  const budget = Math.max(1, w - visibleWidth(cap) - visibleWidth(scroll));
180
- const body = truncateToWidth(` ${status} `, budget);
181
- return cap + theme.fill(body + spaces(budget - visibleWidth(body))) + scroll;
320
+ if (segmentsWidth(segs, theme) === 0 && right === "") return ""; // reserved blank row until data arrives
321
+ // The fill covers the STATUS CHIP only (OMP's band: the chip ends where the
322
+ // identity does; the context figure floats right on the bare prompt
323
+ // surface). A full-width fill reads as a title bar, not a status band.
324
+ const rw = visibleWidth(right);
325
+ const maxLeft = Math.max(0, budget - rw);
326
+ // Fit by shedding WHOLE trailing segments (stats → rate → usage → git →
327
+ // dir) — never half a segment. The context figure is reserved in full: it is
328
+ // the one
329
+ // figure worth keeping whole, and clipping it defeats the window display.
330
+ let keep = segs.length;
331
+ while (keep > 1 && segmentsWidth(segs.slice(0, keep), theme) + 2 > maxLeft) keep--;
332
+ const left = segmentsWidth(segs.slice(0, keep), theme) + 2 > maxLeft ? "" : segs.slice(0, keep).join(theme.dim(" · "));
333
+ if (left === "" && right === "") return "";
334
+ // ` text ` — the padding IS the separation from the context figure.
335
+ const chip = left === "" ? "" : theme.fill(` ${left} `);
336
+ return cap + chip + spaces(Math.max(0, maxLeft - visibleWidth(chip))) + right + scroll;
182
337
  }
183
338
 
184
- /** Rounded box top: `╭─ status ─────╮` (status left-embedded, OMP's box). */
339
+ /** Line 1 (OMP's Generation Rate placement): the numeric block split by the
340
+ * composer's stock left/right groups — token stats + quota windows flush
341
+ * LEFT, tok/s justified RIGHT — so the band stays identity-only. Blank (no
342
+ * row) while there is nothing to show. Narrow widths shed whole trailing
343
+ * left segments (usage → stats) before the rate yields anything. */
344
+ export function rateLine(data: BandData | undefined, theme: ShapeTheme, w: number): string {
345
+ const left: string[] = [];
346
+ const stats = data?.stats?.trim();
347
+ if (stats) left.push(theme.dim(stats));
348
+ const usage = data?.usage?.trim();
349
+ const paint = data?.usageTone === "error" ? theme.error : data?.usageTone === "warning" ? theme.warn : theme.dim;
350
+ if (usage) left.push(paint(usage));
351
+ const rate = data?.rate;
352
+ const right = typeof rate === "number" && Number.isFinite(rate) && rate > 0 ? theme.dim(`${ICONS.throughput} ${Math.round(rate)} tok/s`) : "";
353
+ if (left.length === 0 && !right) return "";
354
+ const sep = theme.dim(" · ");
355
+ let keep = left.length;
356
+ while (keep > 0 && visibleWidth(left.slice(0, keep).join(sep)) + (right ? visibleWidth(right) + 1 : 0) > w) keep--;
357
+ const leftText = left.slice(0, keep).join(sep);
358
+ if (!right) return leftText;
359
+ if (!leftText) return spaces(Math.max(0, w - visibleWidth(right))) + right;
360
+ return composeStatus(leftText, right, w);
361
+ }
362
+
363
+ /** Width of a joined segment group (separators included). */
364
+ function segmentsWidth(segs: readonly string[], theme: ShapeTheme): number {
365
+ if (segs.length === 0) return 0;
366
+ const sep = visibleWidth(theme.dim(" · "));
367
+ return segs.reduce((n, s) => n + visibleWidth(s), 0) + sep * (segs.length - 1);
368
+ }
369
+
370
+ /** Rounded box top: `╭─ left …fill… right ─╮` (status embedded, OMP's box). */
185
371
  function boxTop(c: ShapeCtx): string {
186
- const { w, theme, status } = c;
372
+ const { w, theme } = c;
187
373
  const inner = Math.max(0, w - 2);
374
+ const { left, right } = statusSegments(c.data, theme, c.spinner);
375
+ const status = composeStatus(left, right, Math.max(0, inner - 4));
188
376
  if (!status || visibleWidth(status) === 0) return theme.border("╭" + "─".repeat(inner) + "╮");
189
377
  const content = truncateToWidth(status, Math.max(1, inner - 4), "…");
190
378
  // `╭─ ` (3) + content + ` ` (1) + fill + `─` (1) + `╮` (1) = w ⇒ fill = inner - content - 4.
@@ -192,6 +380,54 @@ function boxTop(c: ShapeCtx): string {
192
380
  return theme.border("╭─ ") + content + theme.border(" " + fill + "─" + "╮");
193
381
  }
194
382
 
383
+ /** Current git branch for a cwd — reads `.git/HEAD` (walk-up; a `.git` FILE
384
+ * is a linked worktree pointing at `gitdir:`), `"detached"` on a raw SHA,
385
+ * null outside a repo. Sync by design: callers cache; never watches. */
386
+ export function readGitBranch(cwd: string): string | null {
387
+ try {
388
+ let dir = resolve(cwd);
389
+ for (let up = 0; up < 64; up++) {
390
+ const dotGit = join(dir, ".git");
391
+ if (existsSync(dotGit)) {
392
+ let gitDir = dotGit;
393
+ if (statSync(dotGit).isFile()) {
394
+ const m = /^gitdir:\s*(.+)\s*$/m.exec(readFileSync(dotGit, "utf8"));
395
+ if (!m) return null;
396
+ gitDir = isAbsolute(m[1]!) ? m[1]! : resolve(dir, m[1]!);
397
+ }
398
+ const head = readFileSync(join(gitDir, "HEAD"), "utf8").trim();
399
+ const ref = /^ref:\s*refs\/heads\/(.+)$/.exec(head);
400
+ return ref ? ref[1]!.trim() : head.length > 0 ? "detached" : null;
401
+ }
402
+ const parent = dirname(dir);
403
+ if (parent === dir) return null;
404
+ dir = parent;
405
+ }
406
+ return null;
407
+ } catch {
408
+ return null;
409
+ }
410
+ }
411
+
412
+ /** Parse `git status --porcelain` output into OMP's indicator counts. Each
413
+ * line starts with XY: X = staged state, Y = worktree state; `??` = untracked.
414
+ * Pure — the caller owns the (cached) subprocess. */
415
+ export function parseGitStats(porcelain: string): GitStats {
416
+ const stats: GitStats = { staged: 0, unstaged: 0, untracked: 0 };
417
+ for (const line of porcelain.split("\n")) {
418
+ if (line.length < 2) continue;
419
+ const x = line[0]!;
420
+ const y = line[1]!;
421
+ if (x === "?" && y === "?") {
422
+ stats.untracked++;
423
+ continue;
424
+ }
425
+ if (x !== " " && x !== "?") stats.staged++;
426
+ if (y !== " " && y !== "?") stats.unstaged++;
427
+ }
428
+ return stats;
429
+ }
430
+
195
431
  /** Prompt gutter on the first row, aligned blanks on continuation rows. */
196
432
  const gutterRow = (c: ShapeCtx, text: string, o: RowOpts) => {
197
433
  const gw = visibleWidth(c.gutter ?? "");
@@ -321,7 +557,7 @@ export function contentWidth(shape: ComposerShapeDef, w: number): number {
321
557
  export function previewShape(id: string, w: number, theme: ShapeTheme, data?: BandData): string[] {
322
558
  const shape = shapeById(id);
323
559
  const inner = contentWidth(shape, w);
324
- const c: ShapeCtx = { w, hidden: 0, theme, gutter: shape.gutter, status: statusLine(data, theme) || undefined };
560
+ const c: ShapeCtx = { w, hidden: 0, theme, gutter: shape.gutter, data };
325
561
  const prompt = theme.text(truncateToWidth("Ask anything, edit files, run tools", Math.max(1, inner - shape.padX * 2 - 1), "…"));
326
562
  const text = padRow(inner, spaces(shape.padX) + prompt + theme.inverse(" "));
327
563
  const lines: string[] = [];
@@ -374,10 +610,13 @@ export class ShapeEditor extends CustomEditor {
374
610
  const acRows = raw.slice(bottomIdx + 1);
375
611
 
376
612
  const spinner = this.spinnerText();
377
- const status = [spinner, statusLine(this.safeData(), theme)].filter(Boolean).join(" ");
378
- const c: ShapeCtx = { w: width, hidden: this.hiddenLines(), theme, gutter: shape.gutter, status: status || undefined };
613
+ const c: ShapeCtx = { w: width, hidden: this.hiddenLines(), theme, gutter: shape.gutter, data: this.safeData(), spinner };
379
614
 
380
615
  const out: string[] = [];
616
+ // OMP's Generation Rate placement: right-justified line above the shape's
617
+ // own chrome (blank until the first response, so the layout never shifts).
618
+ const rate = rateLine(c.data, theme, width);
619
+ if (rate) out.push(rate);
381
620
  const top = shape.top?.(c);
382
621
  if (spinner !== undefined && !shape.embedsStatus) {
383
622
  // No status-bearing chrome on this shape — the spinner rides pi's
@@ -83,7 +83,7 @@ describe("ShapeEditor rendering", () => {
83
83
 
84
84
  it("status-bearing shapes show the live status; band shows a blank reserved row without data", () => {
85
85
  const withData = rendered(editor("box", "hi", { model: "GLM-5.3", cwd: "ceulen", pct: 42 }), 50).map(plain);
86
- assert.ok(withData[0]!.includes("GLM-5.3") && withData[0]!.includes("42%"), withData[0]);
86
+ assert.ok(withData[0]!.includes("GLM-5.3") && withData[0]!.includes("42.0%"), withData[0]);
87
87
  const empty = rendered(editor("band"), 50).map(plain);
88
88
  assert.equal(empty[0]!.trim(), "", "band reserves its row (blank, full width)");
89
89
  });
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Composer footer: the narrowed replacement for pi's built-in footer on
3
+ * status-bearing shapes. The band carries identity · context · token stats ·
4
+ * quota windows; the footer keeps only the other extensions' statuses.
5
+ */
6
+
7
+ import { describe, it } from "node:test";
8
+ import assert from "node:assert/strict";
9
+ import { ComposerFooter, EMPTY_TOTALS, sessionTotals, statsLine, type SessionTotals } from "../lib/footer.ts";
10
+
11
+ const plain = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, "");
12
+
13
+ const assistant = (usage: unknown) => ({ type: "message", message: { role: "assistant", usage: usage as never } });
14
+
15
+ describe("session totals (band stats source)", () => {
16
+ it("sums usage entries, assistant/toolResult messages and summaries (pi parity)", () => {
17
+ const entries = [
18
+ { type: "message", message: { role: "user" } },
19
+ assistant({ input: 100, output: 50, cacheRead: 1000, cacheWrite: 200 }),
20
+ { type: "message", message: { role: "toolResult", usage: { input: 10, output: 5 } } },
21
+ { type: "usage", usage: { input: 1, output: 2 } },
22
+ { type: "compaction", usage: { input: 7, output: 8 } },
23
+ { type: "branch_summary", usage: { input: 3, output: 4 } },
24
+ ];
25
+ const t = sessionTotals(entries as never);
26
+ assert.equal(t.input, 121);
27
+ assert.equal(t.output, 69);
28
+ assert.equal(t.cacheRead, 1000);
29
+ assert.equal(t.cacheWrite, 200);
30
+ // CH = cacheRead / (input + cacheRead + cacheWrite) of the LATEST assistant prompt.
31
+ assert.ok(Math.abs((t.cacheHitRate ?? 0) - (1000 / 1300) * 100) < 1e-9, `cacheHitRate ${t.cacheHitRate}`);
32
+ });
33
+
34
+ it("tolerates garbage usage and an empty session", () => {
35
+ const entries = [
36
+ assistant({ input: "x", output: Number.NaN }),
37
+ assistant(undefined as never),
38
+ { type: "message", message: { role: "assistant" } },
39
+ ];
40
+ const t = sessionTotals(entries as never);
41
+ assert.equal(t.input, 0);
42
+ assert.equal(t.output, 0);
43
+ assert.deepEqual(sessionTotals([]), EMPTY_TOTALS);
44
+ });
45
+
46
+ it("statsLine formats the band's token figures and is empty before any usage", () => {
47
+ assert.equal(statsLine(EMPTY_TOTALS), "");
48
+ const line = statsLine({ input: 12_000, output: 4_000, cacheRead: 100_000, cacheWrite: 2_000, cacheHitRate: 97.1 });
49
+ assert.equal(line, "↑12k ↓4.0k R100k W2.0k CH97.1%");
50
+ // Cost is NOT a line-1 figure (/usage only); cache-hit only when computed.
51
+ const noCost: SessionTotals = { input: 1, output: 1, cacheRead: 0, cacheWrite: 0 };
52
+ assert.equal(statsLine(noCost), "↑1 ↓1");
53
+ });
54
+ });
55
+
56
+ describe("ComposerFooter render", () => {
57
+ const footer = (over: Partial<ConstructorParameters<typeof ComposerFooter>[0]> = {}) =>
58
+ new ComposerFooter({
59
+ statuses: () => [],
60
+ ...over,
61
+ });
62
+
63
+ it("prints ONLY the other extensions' statuses — no band info", () => {
64
+ const f = footer({ statuses: () => ["rtk ✓", "serena ✓", "🎨 ux: STRICT"] });
65
+ const lines = f.render(80).map(plain);
66
+ assert.equal(lines.length, 1);
67
+ assert.equal(lines[0], "rtk ✓ serena ✓ 🎨 ux: STRICT");
68
+ // Nothing the band owns leaks in here.
69
+ for (const l of lines) {
70
+ assert.ok(!/\d+\.\d%\/|\bmain\b|glm|↑|R\d|CH/i.test(l), `no duplicated band info: ${l}`);
71
+ }
72
+ });
73
+
74
+ it("drops blank statuses, sanitizes control chars, truncates to width", () => {
75
+ const f = footer({
76
+ statuses: () => [" ", "a\tb\nc", "x".repeat(200)],
77
+ });
78
+ const lines = f.render(30).map(plain);
79
+ assert.equal(lines.length, 1);
80
+ assert.ok(lines[0]!.startsWith("a b c"), lines[0]);
81
+ assert.ok(lines[0]!.length <= 31, `truncated: ${lines[0]!.length}`);
82
+ });
83
+
84
+ it("renders nothing at all for a fresh session with no statuses", () => {
85
+ assert.deepEqual(footer().render(80), []);
86
+ });
87
+
88
+ it("never throws when a data getter throws", () => {
89
+ const f = footer({
90
+ statuses: () => {
91
+ throw new Error("boom");
92
+ },
93
+ });
94
+ assert.deepEqual(f.render(80), []);
95
+ });
96
+ });