@gavin-hu/my-pi-agent 0.18.0 → 0.20.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 (324) hide show
  1. package/README.md +66 -52
  2. package/README.zh-CN.md +56 -46
  3. package/docs/extensions/README.md +34 -0
  4. package/docs/extensions/board.md +507 -0
  5. package/{extensions/bytefly/README.md → docs/extensions/bytefly.md} +774 -574
  6. package/{extensions/check/README.md → docs/extensions/check.md} +83 -68
  7. package/{extensions/context/README.md → docs/extensions/context.md} +40 -23
  8. package/docs/extensions/file-browse.md +561 -0
  9. package/{extensions/file-open/README.md → docs/extensions/file-open.md} +31 -23
  10. package/{extensions/file-read/README.md → docs/extensions/file-read.md} +47 -55
  11. package/{extensions/goal/README.md → docs/extensions/goal.md} +115 -131
  12. package/{extensions/job/README.md → docs/extensions/job.md} +62 -52
  13. package/{extensions/memory/README.md → docs/extensions/memory.md} +71 -60
  14. package/{extensions/plan/README.md → docs/extensions/plan.md} +440 -322
  15. package/{extensions/question/README.md → docs/extensions/question.md} +54 -31
  16. package/{extensions/rewind/README.md → docs/extensions/rewind.md} +115 -122
  17. package/docs/extensions/session-bus.md +298 -0
  18. package/{extensions/subagent/README.md → docs/extensions/subagent.md} +165 -118
  19. package/docs/extensions/team.md +254 -0
  20. package/{extensions/todo/README.md → docs/extensions/todo.md} +85 -88
  21. package/{extensions/watch/README.md → docs/extensions/watch.md} +54 -36
  22. package/{extensions/web-access/README.md → docs/extensions/web-access.md} +93 -50
  23. package/{extensions/wechat/README.md → docs/extensions/wechat.md} +260 -163
  24. package/{extensions/worktree/README.md → docs/extensions/worktree.md} +137 -79
  25. package/extensions/board/commands.ts +105 -0
  26. package/extensions/board/config.ts +36 -0
  27. package/extensions/board/format.ts +170 -0
  28. package/extensions/board/index.ts +40 -0
  29. package/extensions/board/input.ts +54 -0
  30. package/extensions/board/join.ts +42 -0
  31. package/extensions/board/page.ts +388 -0
  32. package/extensions/board/result.ts +108 -0
  33. package/extensions/board/rows.ts +48 -0
  34. package/extensions/board/schema.ts +90 -0
  35. package/extensions/board/seat.ts +28 -0
  36. package/extensions/board/snapshot.ts +42 -0
  37. package/extensions/board/tools.ts +444 -0
  38. package/extensions/board/transport/router.ts +91 -0
  39. package/extensions/board/transport/server.ts +138 -0
  40. package/extensions/board/types.ts +121 -0
  41. package/extensions/board/view/client.ts +51 -0
  42. package/extensions/board/view/dialog.ts +43 -0
  43. package/extensions/board/view/keys.ts +125 -0
  44. package/extensions/board/view/live.ts +231 -0
  45. package/extensions/board/view/names.ts +91 -0
  46. package/extensions/board/view/page.ts +118 -0
  47. package/extensions/board/view/render.ts +519 -0
  48. package/extensions/board/view/styles.ts +228 -0
  49. package/extensions/board/view/team.ts +327 -0
  50. package/extensions/bytefly/footer/budget.ts +6 -5
  51. package/extensions/bytefly/footer/collect/entries.ts +12 -4
  52. package/extensions/bytefly/footer/collect/snapshot.ts +8 -17
  53. package/extensions/bytefly/footer/config.ts +19 -8
  54. package/extensions/bytefly/footer/price/price.ts +30 -8
  55. package/extensions/bytefly/footer/register.ts +5 -5
  56. package/extensions/bytefly/footer/render/format.ts +18 -0
  57. package/extensions/bytefly/footer/render/lines.ts +23 -7
  58. package/extensions/bytefly/footer/render/segments.ts +117 -31
  59. package/extensions/bytefly/footer/types.ts +29 -5
  60. package/extensions/bytefly/footer/unpriced.ts +42 -17
  61. package/extensions/bytefly/panel/commands.ts +67 -7
  62. package/extensions/bytefly/panel/filter.ts +68 -0
  63. package/extensions/bytefly/panel/format.ts +16 -15
  64. package/extensions/bytefly/panel/join.ts +56 -13
  65. package/extensions/bytefly/panel/prices.ts +43 -0
  66. package/extensions/bytefly/panel/settings-runtime.ts +0 -6
  67. package/extensions/bytefly/panel/settings.ts +75 -43
  68. package/extensions/bytefly/panel/tui/entries.ts +26 -8
  69. package/extensions/bytefly/panel/tui/frame.ts +130 -93
  70. package/extensions/bytefly/panel/tui/keys.ts +352 -0
  71. package/extensions/bytefly/panel/tui/list-view.ts +25 -46
  72. package/extensions/bytefly/panel/tui/panes.ts +76 -0
  73. package/extensions/bytefly/panel/tui/section-view.ts +126 -0
  74. package/extensions/bytefly/panel/tui/settings-section.ts +54 -125
  75. package/extensions/bytefly/panel/tui/settings-view.ts +30 -131
  76. package/extensions/bytefly/panel/tui/side-pane.ts +224 -0
  77. package/extensions/bytefly/panel/tui.ts +306 -259
  78. package/extensions/bytefly/picker/discovery.ts +0 -2
  79. package/extensions/bytefly/picker/types.ts +0 -2
  80. package/extensions/bytefly/update/check.ts +39 -0
  81. package/extensions/bytefly/update/format.ts +15 -0
  82. package/extensions/bytefly/update/register.ts +73 -34
  83. package/extensions/bytefly/update/state.ts +6 -3
  84. package/extensions/check/commands.ts +2 -1
  85. package/extensions/context/tui.ts +1 -1
  86. package/extensions/file-browse/{config.ts → config/config.ts} +1 -1
  87. package/extensions/file-browse/files/classify.ts +136 -0
  88. package/extensions/file-browse/files/files.ts +12 -0
  89. package/extensions/file-browse/files/index.ts +90 -0
  90. package/extensions/file-browse/files/list.ts +261 -0
  91. package/extensions/file-browse/{paths.ts → files/paths.ts} +1 -1
  92. package/extensions/file-browse/files/tree.ts +101 -0
  93. package/extensions/file-browse/{git.ts → git/git.ts} +10 -3
  94. package/extensions/file-browse/index.ts +4 -4
  95. package/extensions/file-browse/{live.ts → live/live.ts} +20 -69
  96. package/extensions/file-browse/{router.ts → transport/router.ts} +21 -17
  97. package/extensions/file-browse/transport/server.ts +110 -0
  98. package/extensions/file-browse/{chrome.ts → view/chrome.ts} +4 -4
  99. package/extensions/file-browse/{client.ts → view/client.ts} +1 -1
  100. package/extensions/file-browse/{diff-html.ts → view/diff-html.ts} +3 -3
  101. package/extensions/file-browse/view/emit.ts +51 -0
  102. package/extensions/file-browse/{html.ts → view/html.ts} +19 -18
  103. package/extensions/file-browse/{icons.ts → view/icons.ts} +1 -1
  104. package/extensions/file-browse/{markdown.ts → view/markdown.ts} +18 -20
  105. package/extensions/file-browse/{raw-html.ts → view/raw-html.ts} +19 -14
  106. package/extensions/file-browse/{styles.ts → view/styles.ts} +29 -5
  107. package/extensions/file-browse/{tree.ts → view/tree.ts} +1 -1
  108. package/extensions/file-browse/{urls.ts → view/urls.ts} +1 -1
  109. package/extensions/file-read/schema.ts +2 -1
  110. package/extensions/job/runtime.ts +4 -4
  111. package/extensions/memory/store.ts +12 -5
  112. package/extensions/plan/blocks.ts +23 -2
  113. package/extensions/plan/commands.ts +21 -16
  114. package/extensions/plan/feedback.ts +185 -52
  115. package/extensions/plan/format.ts +10 -3
  116. package/extensions/plan/index.ts +23 -5
  117. package/extensions/plan/plan-files.ts +88 -0
  118. package/extensions/plan/plan-index.ts +43 -9
  119. package/extensions/plan/plan-text.ts +33 -23
  120. package/extensions/plan/plans.ts +27 -34
  121. package/extensions/plan/policy.ts +30 -17
  122. package/extensions/plan/review.ts +3 -27
  123. package/extensions/plan/runtime.ts +52 -11
  124. package/extensions/plan/sections.ts +112 -0
  125. package/extensions/plan/steps.ts +3 -22
  126. package/extensions/plan/todos.ts +51 -3
  127. package/extensions/plan/tools/exit.ts +20 -95
  128. package/extensions/plan/tools/todo-seed.ts +4 -2
  129. package/extensions/plan/tools/write.ts +12 -1
  130. package/extensions/plan/tui.ts +5 -34
  131. package/extensions/plan/types.ts +15 -8
  132. package/extensions/plan/web-blocks.ts +89 -0
  133. package/extensions/plan/web-chrome.ts +3 -5
  134. package/extensions/plan/web-client.ts +179 -330
  135. package/extensions/plan/web-collab.ts +3 -3
  136. package/extensions/plan/web-comments.ts +18 -8
  137. package/extensions/plan/web-composer.ts +80 -0
  138. package/extensions/plan/web-draft.ts +40 -0
  139. package/extensions/plan/web-keys.ts +134 -0
  140. package/extensions/plan/web-outline.ts +192 -0
  141. package/extensions/plan/web-page.ts +4 -8
  142. package/extensions/plan/web-plan.ts +150 -0
  143. package/extensions/plan/web-router.ts +3 -58
  144. package/extensions/plan/web-settle.ts +194 -0
  145. package/extensions/plan/web-share-session.ts +24 -30
  146. package/extensions/plan/web-streams.ts +14 -14
  147. package/extensions/plan/web-tokens.ts +2 -2
  148. package/extensions/plan/web.ts +66 -120
  149. package/extensions/rewind/{commands.ts → commands/commands.ts} +5 -5
  150. package/extensions/rewind/{review.ts → commands/review.ts} +15 -14
  151. package/extensions/rewind/{rewind.ts → commands/rewind.ts} +6 -6
  152. package/extensions/rewind/{config.ts → config/config.ts} +1 -1
  153. package/extensions/rewind/index.ts +3 -3
  154. package/extensions/rewind/{policy.ts → state/policy.ts} +4 -4
  155. package/extensions/rewind/{runtime.ts → state/runtime.ts} +11 -11
  156. package/extensions/rewind/{snapshot-run.ts → state/snapshot-run.ts} +1 -1
  157. package/extensions/rewind/{timeline.ts → state/timeline.ts} +2 -2
  158. package/extensions/rewind/{format.ts → text/format.ts} +3 -3
  159. package/extensions/rewind/{git.ts → transport/git.ts} +2 -2
  160. package/extensions/rewind/{restore.ts → transport/restore.ts} +2 -2
  161. package/extensions/rewind/{snapshot.ts → transport/snapshot.ts} +1 -1
  162. package/extensions/rewind/{store.ts → transport/store.ts} +1 -1
  163. package/extensions/rewind/{checklist.ts → view/checklist.ts} +6 -6
  164. package/extensions/rewind/{hunk-picker.ts → view/hunk-picker.ts} +8 -8
  165. package/extensions/rewind/{path-picker.ts → view/path-picker.ts} +7 -7
  166. package/extensions/rewind/{review-tui.ts → view/review-tui.ts} +11 -11
  167. package/extensions/rewind/{rewind-tui.ts → view/rewind-tui.ts} +17 -11
  168. package/extensions/rewind/{status.ts → view/status.ts} +4 -4
  169. package/extensions/session-bus/commands.ts +17 -69
  170. package/extensions/session-bus/format.ts +22 -45
  171. package/extensions/session-bus/index.ts +13 -7
  172. package/extensions/session-bus/join-request.ts +40 -0
  173. package/extensions/session-bus/mail-watch.ts +134 -0
  174. package/extensions/session-bus/notice.ts +32 -4
  175. package/{lib/claims → extensions/session-bus}/overlap.ts +11 -18
  176. package/extensions/session-bus/protocol.ts +19 -49
  177. package/extensions/session-bus/resolve.ts +67 -0
  178. package/extensions/session-bus/result.ts +16 -51
  179. package/extensions/session-bus/rows.ts +11 -5
  180. package/extensions/session-bus/runtime.ts +220 -267
  181. package/extensions/session-bus/store.ts +55 -7
  182. package/extensions/session-bus/tools.ts +31 -66
  183. package/extensions/session-bus/tui.ts +5 -5
  184. package/extensions/session-bus/types.ts +23 -14
  185. package/extensions/subagent/agents.ts +9 -8
  186. package/extensions/subagent/commands.ts +2 -1
  187. package/extensions/subagent/invocation.ts +4 -2
  188. package/extensions/team/commands.ts +145 -0
  189. package/extensions/team/dispatch.ts +133 -0
  190. package/extensions/team/format.ts +119 -0
  191. package/extensions/team/index.ts +34 -0
  192. package/extensions/team/schema.ts +29 -0
  193. package/extensions/team/tools.ts +267 -0
  194. package/extensions/team/types.ts +65 -0
  195. package/extensions/todo/index.ts +4 -1
  196. package/extensions/todo/nudge.ts +8 -2
  197. package/extensions/web-access/fetch/page.ts +4 -1
  198. package/extensions/web-access/fetch/structured.ts +447 -0
  199. package/extensions/web-access/fetch/tool.ts +2 -1
  200. package/extensions/web-access/search/tool.ts +2 -1
  201. package/extensions/wechat/bridge.ts +106 -251
  202. package/extensions/wechat/{commands.ts → commands/commands.ts} +26 -18
  203. package/extensions/wechat/{doctor.ts → commands/doctor.ts} +5 -5
  204. package/extensions/wechat/{history.ts → commands/history.ts} +1 -1
  205. package/extensions/wechat/{login.ts → commands/login.ts} +3 -3
  206. package/extensions/wechat/{slash.ts → commands/slash.ts} +38 -2
  207. package/extensions/wechat/dialog/channels.ts +136 -0
  208. package/extensions/wechat/{interaction.ts → dialog/interaction.ts} +37 -37
  209. package/extensions/wechat/{prompt.ts → dialog/prompt.ts} +2 -2
  210. package/extensions/wechat/{remote-ui.ts → dialog/remote-ui.ts} +1 -1
  211. package/extensions/wechat/index.ts +10 -10
  212. package/extensions/wechat/intake.ts +245 -0
  213. package/extensions/wechat/{admission.ts → peer/admission.ts} +2 -2
  214. package/extensions/wechat/{peer-session.ts → peer/peer-session.ts} +2 -2
  215. package/extensions/wechat/{peer-worker.ts → peer/peer-worker.ts} +100 -22
  216. package/extensions/wechat/{presence.ts → peer/presence.ts} +8 -7
  217. package/extensions/wechat/{reply-pipeline.ts → peer/reply-pipeline.ts} +1 -1
  218. package/extensions/wechat/{credentials.ts → state/credentials.ts} +2 -2
  219. package/extensions/wechat/{state.ts → state/state.ts} +14 -2
  220. package/extensions/wechat/{format.ts → text/format.ts} +3 -3
  221. package/extensions/wechat/{notices.ts → text/notices.ts} +8 -0
  222. package/extensions/wechat/tools.ts +29 -12
  223. package/extensions/wechat/{client.ts → transport/client.ts} +26 -2
  224. package/extensions/wechat/{deliver.ts → transport/deliver.ts} +72 -28
  225. package/extensions/wechat/{inbound.ts → transport/inbound.ts} +5 -5
  226. package/extensions/wechat/{media.ts → transport/media.ts} +11 -5
  227. package/extensions/wechat/transport/outbound.ts +142 -0
  228. package/extensions/wechat/{poll.ts → transport/poll.ts} +3 -3
  229. package/extensions/wechat/types.ts +10 -1
  230. package/extensions/wechat/{login-screen.ts → view/login-screen.ts} +4 -4
  231. package/extensions/wechat/{status-screen.ts → view/status-screen.ts} +31 -26
  232. package/extensions/worktree/commands.ts +24 -17
  233. package/extensions/worktree/exit.ts +12 -6
  234. package/extensions/worktree/git.ts +22 -14
  235. package/extensions/worktree/guard.ts +18 -290
  236. package/extensions/worktree/handoff.ts +10 -2
  237. package/extensions/worktree/index.ts +2 -1
  238. package/extensions/worktree/lifecycle.ts +2 -0
  239. package/extensions/worktree/registry.ts +20 -11
  240. package/extensions/worktree/root-tools.ts +13 -3
  241. package/extensions/worktree/runtime.ts +8 -2
  242. package/extensions/worktree/screen.ts +15 -8
  243. package/extensions/worktree/shell.ts +303 -0
  244. package/extensions/worktree/state.ts +1 -1
  245. package/extensions/worktree/status.ts +42 -9
  246. package/extensions/worktree/tools.ts +19 -13
  247. package/lib/README.md +11 -8
  248. package/lib/board/card.ts +479 -0
  249. package/lib/board/links.ts +141 -0
  250. package/lib/board/page-pointer.ts +310 -0
  251. package/lib/board/round-text.ts +81 -0
  252. package/lib/board/round.ts +94 -0
  253. package/lib/board/rules.ts +437 -0
  254. package/lib/board/session.ts +105 -0
  255. package/lib/board/store.ts +497 -0
  256. package/lib/board/view.ts +234 -0
  257. package/lib/errors.ts +12 -4
  258. package/lib/format.ts +35 -0
  259. package/lib/http/guard.ts +112 -0
  260. package/lib/http/index.ts +16 -5
  261. package/lib/http/serve.ts +237 -0
  262. package/lib/http/server.ts +12 -10
  263. package/lib/http/sink.ts +135 -0
  264. package/lib/http/token.ts +38 -0
  265. package/lib/plan-entry.ts +11 -0
  266. package/lib/policy.ts +25 -2
  267. package/lib/requirements.ts +6 -7
  268. package/lib/session-label.ts +64 -0
  269. package/lib/session-roster.ts +201 -0
  270. package/lib/session-tool.ts +184 -0
  271. package/lib/spawn.ts +37 -3
  272. package/lib/stray-fields.ts +45 -0
  273. package/lib/tool-names.ts +38 -2
  274. package/lib/tui/glyphs.ts +3 -2
  275. package/lib/web/README.md +57 -4
  276. package/lib/web/client-runtime.ts +123 -0
  277. package/lib/web/components.ts +5 -0
  278. package/lib/web/index.ts +4 -2
  279. package/lib/web/markup.ts +88 -1
  280. package/lib/web/names.ts +42 -0
  281. package/lib/web/runtime.ts +7 -1
  282. package/lib/web/tokens.ts +25 -2
  283. package/package.json +26 -14
  284. package/skills/next/SKILL.md +4 -3
  285. package/skills/project-docs/SKILL.md +133 -0
  286. package/skills/project-docs/references/audit.md +131 -0
  287. package/skills/project-docs/references/changelog.md +105 -0
  288. package/skills/project-docs/references/discovery.md +127 -0
  289. package/skills/project-docs/references/readme.md +80 -0
  290. package/skills/project-docs/references/release.md +84 -0
  291. package/skills/project-docs/references/roadmap.md +93 -0
  292. package/skills/project-docs/scripts/state.ts +316 -0
  293. package/skills/refactor/SKILL.md +100 -125
  294. package/skills/refactor/references/handoff.md +35 -0
  295. package/skills/refactor/references/signals.md +54 -0
  296. package/skills/refactor/scripts/inventory.ts +587 -0
  297. package/extensions/bytefly/panel/tui/extensions-view.ts +0 -40
  298. package/extensions/bytefly/panel/tui/skills-view.ts +0 -50
  299. package/extensions/file-browse/README.md +0 -506
  300. package/extensions/file-browse/files.ts +0 -564
  301. package/extensions/file-browse/server.ts +0 -141
  302. package/extensions/job/process.ts +0 -35
  303. package/extensions/plan/split.ts +0 -87
  304. package/extensions/session-bus/README.md +0 -247
  305. package/extensions/session-bus/team.ts +0 -102
  306. package/extensions/wechat/outbound.ts +0 -100
  307. package/lib/plans/sections.ts +0 -172
  308. package/lib/plans/setting.ts +0 -52
  309. package/lib/plans/split.ts +0 -215
  310. package/lib/plans/store.ts +0 -19
  311. package/lib/plans/team.ts +0 -151
  312. package/skills/changelog/SKILL.md +0 -148
  313. package/skills/parallel-dev/SKILL.md +0 -150
  314. /package/extensions/file-browse/{rev.ts → live/rev.ts} +0 -0
  315. /package/extensions/file-browse/{diff.ts → text/diff.ts} +0 -0
  316. /package/extensions/file-browse/{fuzzy.ts → text/fuzzy.ts} +0 -0
  317. /package/extensions/file-browse/{live-client.ts → view/live-client.ts} +0 -0
  318. /package/extensions/file-browse/{palette.ts → view/palette.ts} +0 -0
  319. /package/extensions/rewind/{patch.ts → text/patch.ts} +0 -0
  320. /package/extensions/rewind/{paths.ts → text/paths.ts} +0 -0
  321. /package/extensions/rewind/{queue.ts → transport/queue.ts} +0 -0
  322. /package/extensions/rewind/{temp-index.ts → transport/temp-index.ts} +0 -0
  323. /package/extensions/wechat/{lock.ts → state/lock.ts} +0 -0
  324. /package/extensions/wechat/{channel.ts → text/channel.ts} +0 -0
@@ -0,0 +1,561 @@
1
+ # file-browse — view the working directory in a browser
2
+
3
+ `/browse` starts a **read-only** HTTP server rooted at the effective working
4
+ directory, opens the default browser at it, and prints the URL. The page is a
5
+ two-pane file browser: a collapsible path tree on the left, directory listings
6
+ and file views on the right, with image thumbnails, rendered Markdown,
7
+ highlighted code, per-language icons, a fuzzy quick-open palette, and a
8
+ read-only git diff view. It is bound to `127.0.0.1` and ships no dependencies —
9
+ the shared loopback layer plus one small vanilla script.
10
+
11
+ <img src="../../assets/screens/file-browse.png" alt="The loopback file browser, showing the path filter, the file tree, and a rendered Markdown preview" width="100%">
12
+
13
+ ## Capabilities
14
+
15
+ Status records what a reader can rely on: **Shipped** is in a tagged release, **Unreleased** is complete in the current tree but not yet tagged, and **Partial** has one released part and one unreleased part. Rows are ordered by user value, highest first.
16
+
17
+ | Capability | How | What you get | Status |
18
+ |---|---|---|---|
19
+ | One-command browsing | `/browse` | The server starts at the effective working directory, prints its URL, and opens the browser. | Shipped |
20
+ | Read-only serving | `/browse` | Nothing is edited or written, and the server binds `127.0.0.1` only. | Shipped |
21
+ | Two-pane page | `/`, `/browse[/<rel>]` | A collapsible tree beside the current folder's listing, with the tree, filter, and quick-open trigger pinned in their own pane. | Shipped |
22
+ | File previews | `/view/<rel>` | Text, rendered Markdown, image thumbnails, and download cards for binary or over-size files, each with a per-language icon. | Shipped |
23
+ | Quick open | `/`, `Ctrl/Cmd+K`, `/api/files` | A fuzzy path finder over the tree opens a file without walking the tree. | Shipped |
24
+ | Git diff view | `/diff`, `/diff/<rel>` | A change overview and one file's unified diff, scoped to `head`, `staged`, or `worktree`. | Shipped |
25
+ | Live status | `/events`, the `◉ live` chip | An open page keeps its branch, change markers, and footer up to date without a reload. | Shipped |
26
+ | Reload hint | `/api/dir-rev`, `⟳ reload` | A page whose folder gained or lost a file offers a reload control instead of changing its rows. | Shipped |
27
+ | Terminal session chip | `browse` status key | The terminal footer shows `◉ <port>` while the page is served, so the session names its live server. | Shipped |
28
+ | Listing controls | the `Name`, `Size`, and `Modified` headers | The current folder sorts by name, size, or modified time, directories first, and the choice is remembered per browser. | Shipped |
29
+ | Keyboard navigation | the tree's keymap, `?` | The tree is one tab stop with arrow, fold, and open keys; a shortcut sheet lists the page's own keys. | Shipped |
30
+ | Diff hunk navigation | `n`/`p` in `/diff` | Jump between changed hunks without scrolling the whole file. | Shipped |
31
+ | Fold and expand all | the `fold all` control | Collapse or expand the whole tree in one click. | Shipped |
32
+ | Reading progress | `browse-progress` hairline | A long directory or diff read shows how much has loaded, and printing hides the indicator. | Shipped |
33
+ | Printing | `@media print` styles | The page prints without the toolbar, progress hairline, or other screen-only chrome. | Shipped |
34
+ | Syntax highlighting | `/view/<rel>`, `/view/<rel>?raw=1` | Supported code files show keywords, strings, numbers, and comments in colour in both themes; other text stays plain. | Shipped |
35
+ | Markdown preview | `/view/<rel>`, `/view/<rel>?raw=1` | A README renders as headings, lists, tables, code, and links, with a one-click raw view. | Shipped |
36
+ | Copy and wrap | the page toolbar, `y`, `u` | Copy a file's path or contents or a `path:12-30` line reference, and toggle line wrapping for text and raw views. | Shipped |
37
+ | Theme toggle | the header button, `/theme.js` | Dark and light palettes, following the system until an explicit choice is remembered per browser. | Shipped |
38
+ | Idle stop and port reuse | `/browse stop`, the session port | The server stops when idle and reuses its port for the next session instead of leaking listeners. | Shipped |
39
+
40
+ ## Quickstart
41
+
42
+ ```bash
43
+ pi --extension ./extensions/file-browse # load just this extension
44
+ pi -e . # load the whole @gavin-hu/my-pi-agent package
45
+ pi install ./ # install the package for a user
46
+ ```
47
+
48
+ ```text
49
+ /browse # start at the working directory and open the browser
50
+ /browse status # print the root and URL, or "not running"
51
+ ```
52
+
53
+ `/browse <path>` starts the same server with a subdirectory as its root.
54
+
55
+ ## Commands
56
+
57
+ `/browse` is the only command: it starts, reports, or stops the server, and
58
+ selects the root.
59
+
60
+ ```bash
61
+ /browse start at the working directory, open the browser, print the URL
62
+ /browse <path> start with a subdirectory of the working directory as the root
63
+ /browse status print the root and URL, or "not running"
64
+ /browse stop stop the server
65
+ ```
66
+
67
+ - The root is the effective cwd, so an active `worktree` session serves the
68
+ worktree. `<path>` must resolve inside it.
69
+ - The port is fixed for the session: the first `/browse` picks a random port
70
+ in `4780`–`5779` and every later `/browse` in that session reuses it, so the
71
+ URL stays stable across roots and restarts. Set `"port"` to pin an explicit
72
+ port; a busy port is reported, not silently changed.
73
+ - Starting while already running with the same root reprints the URL without
74
+ restarting; a different root (or a changed pinned port) restarts the server.
75
+ - The server is closed when its last page has been gone for ten seconds, so
76
+ closing the browser window ends the session's browse server and `/browse`
77
+ starts it again on the same port. A reload or a new tab inside that grace keeps
78
+ it. `session_shutdown` closes it too, and `/browse stop` closes it at once.
79
+
80
+ ## Routes
81
+
82
+ | Route | Result |
83
+ |---|---|
84
+ | `/`, `/browse[/<rel>]` | tree + directory listing |
85
+ | `/view/<rel>` | tree + file page (text, Markdown, image, binary, or over-size) |
86
+ | `/view/<rel>?raw=1` | raw Markdown/text source instead of the rendered view |
87
+ | `/raw/<rel>` | raw bytes, streamed; downloads and image sources |
88
+ | `/diff[?mode=head\|staged\|worktree]` | changed-file overview with `--stat` |
89
+ | `/diff/<rel>[?mode=…]` | one file's unified diff |
90
+ | `/api/tree?path=<rel>` | JSON children for lazy tree expansion |
91
+ | `/api/files?q=<query>` | JSON fuzzy path matches for the quick-open palette |
92
+ | `/api/dir-rev?path=<rel>` | JSON listing revision for the reload check |
93
+ | `/events` | Server-Sent Events stream of `status` frames for the open page |
94
+ | `/app.js` | the first-party client script |
95
+ | `/theme.js` | the pre-paint theme bootstrap |
96
+
97
+ ## Configuration
98
+
99
+ The `file-browse` section of the shared `bytefly.json`. Resolution rules —
100
+ global document then project document, project wins — are in
101
+ [`../configuration.md`](../configuration.md#file-browse--the-local-file-server).
102
+
103
+ | Key | Default | Meaning |
104
+ |---|---|---|
105
+ | `port` | `0` | `0` picks one random port fixed for the session; a positive value pins it. |
106
+ | `autoOpen` | `true` | Open the browser on start; `false` for headless. |
107
+ | `maxFileBytes` | `1048576` | Larger files show a download card only. |
108
+ | `maxThumbBytes` | `5242880` | Larger images get an icon, not a thumbnail. |
109
+ | `maxTextLines` | `5000` | Rendered lines before truncation. |
110
+ | `maxDirEntries` | `2000` | Listed entries before truncation. |
111
+ | `thumbnails` | `true` | Render inline image thumbnails in listings. |
112
+ | `markdown` | `true` | Render Markdown files as formatted HTML. |
113
+ | `markdownHtml` | `true` | Re-emit sanitized raw HTML in rendered Markdown. |
114
+ | `maxIndexEntries` | `20000` | Files collected for quick open before truncation. |
115
+ | `gitDiff` | `true` | Offer the read-only diff view; `false` also drops the changes chip. |
116
+ | `diffContext` | `3` | Unified diff context lines. |
117
+ | `maxDiffLines` | `4000` | Diff lines rendered before truncation. |
118
+ | `live` | `true` | Stream live status to open pages. |
119
+ | `liveIntervalMs` | `5000` | Milliseconds between status frames while a page is connected. |
120
+
121
+ ## Security
122
+
123
+ - **Loopback only.** Binds `127.0.0.1`; no auth and no LAN exposure.
124
+ - **Method and Host.** Only `GET`/`HEAD` are served (else `405`); a `Host`
125
+ header that is not `127.0.0.1[:port]`, `localhost[:port]`, or `[::1][:port]`
126
+ is rejected (else `403`, DNS-rebinding defense), and no CORS headers are sent.
127
+ - **Path guard.** Every path is decoded once, NUL and absolute paths are
128
+ rejected, the path is resolved under the root, and the target (or nearest
129
+ existing ancestor) is `realpath`-checked for containment. This blocks `../`,
130
+ encoded traversal, and symlink escapes. Symlinks are listed but only followed
131
+ when their real path stays inside the root.
132
+ - **CSP.** Pages allow only same-origin scripts and inline styles, and refuse to
133
+ be framed (`frame-ancestors 'none'`, `X-Frame-Options: DENY`), so a local page
134
+ cannot clickjack the controls or re-point relative URLs through an injected
135
+ `<base>`; the policy comes from `lib/http/headers.ts`, shared with `plan`, so
136
+ the two surfaces cannot drift. `/raw` uses
137
+ `default-src 'none'; script-src 'none'; sandbox` plus `nosniff`, so a served
138
+ SVG/HTML file cannot execute.
139
+ - **Markdown safety.** Rendered Markdown is escape-first, and raw HTML passes an
140
+ allowlist (`raw-html.ts`): only known elements and attributes are re-emitted,
141
+ rebuilt from the parsed names rather than copied, so `script`, `style`,
142
+ `iframe`, `svg`, event handlers, `style=` and `class=` never reach the page.
143
+ Link schemes are allowlisted (`javascript:`/`data:` dropped), an external
144
+ image renders as a link instead of loading, and open elements are balanced at
145
+ the end of the document so an unclosed `<div>` cannot swallow the page chrome.
146
+ A suppressed element (`script`, `style`, `svg`, …) is dropped with its body;
147
+ any other unknown tag is escaped and stays visible. `markdownHtml: false`
148
+ restores escape-only rendering. The page CSP keeps the rest inert.
149
+ - **Highlighting safety.** The highlighter escapes every literal before it
150
+ wraps it in a token span, so a code file's content cannot inject markup or
151
+ attributes; only the fixed `tok-*` class names reach the page.
152
+ - **Event stream.** `/events` is a `GET` on the same loopback server, behind
153
+ the same method and `Host` checks, and it only reads: the frame is the branch,
154
+ the change paths and their revision, an uptime, and a request count, all of
155
+ which the page it feeds already renders. It carries no page policy
156
+ (`text/event-stream` is not a document), sends `Cache-Control: no-store`, and
157
+ cannot be cached or replayed. A tick runs only while a page is attached, and
158
+ the timer is `unref`ed, so an idle server does no work and a forgotten tab
159
+ cannot hold the process open. At most eight pages may attach; a ninth is
160
+ answered `204`, the one status an event source never reconnects after.
161
+ - **Caps.** `maxFileBytes` (inline rendering), `maxTextLines` (rendered lines),
162
+ `maxThumbBytes` (thumbnails), and `maxDirEntries` (listings) bound every read.
163
+ - **Git reads.** The header chip and the diff view run read-only git
164
+ (`rev-parse`, `status --porcelain=v1 -z`, `diff --stat`, `diff -U<n>`) with a
165
+ timeout and a short cache; any failure simply omits the chip or the diff. A
166
+ per-file diff sets `GIT_LITERAL_PATHSPECS=1`, so a filename containing glob
167
+ characters is matched literally.
168
+ - **Read-only.** Nothing is ever written.
169
+
170
+ ## The page
171
+
172
+ The page is server-rendered HTML with an inline style block and inline SVG
173
+ icons, progressively enhanced by one first-party script (`client.ts`). Each page
174
+ names its own subject in the tab — `browse · <folder>`, `browse · <rel>` for a file, the
175
+ `<page> · <subject>` shape the kit's `tabTitle` gives every served page — and links the
176
+ brand mark as an SVG data URI, in the appearance the system is in. A folder
177
+ folds from its twisty, and a `fold all` / `expand all` button beside the filter
178
+ folds the whole tree at once. The tree scrolls in its own pane with quick open
179
+ and the filter pinned above it; below 860px it collapses into a `Files`
180
+ disclosure above the listing. Below 820px the served folder's path takes a row of
181
+ its own and keeps its last segments, an ellipsis cutting the leading directories;
182
+ below 520px the card's controls hold one scrolling row above the file instead of
183
+ stacking. A hairline progress bar tracks whichever column is scrolling (the card
184
+ body for a file or diff, the main column otherwise), and the served folder names
185
+ the root page. The sidebar is a `<details>` whose content wrapper has no definite
186
+ height, so the panel fills it absolutely and the tree flexes inside.
187
+
188
+ The filter hides non-matching rows while keeping ancestors, and disclosure
189
+ triangles lazily fetch `/api/tree`. Without JavaScript the page still browses and
190
+ renders Markdown, and the JS-only controls (filter, disclosure, actions, quick
191
+ open) are hidden; the sort buttons lose their pointer so they do not look live.
192
+
193
+ The page palette is the shared Bytefly web theme (`lib/web/tokens.ts`), derived
194
+ from the `bytefly-dark`/`bytefly-light` terminal themes. It follows
195
+ `prefers-color-scheme` until an explicit choice sets `data-theme` on the root:
196
+ `/theme.js` applies the saved choice in the head before first paint, and the
197
+ header toggle flips and stores it (`pi-web-theme` in `localStorage`, the key
198
+ shared with plan's review page).
199
+
200
+ The page is keyboard-first, and the tree is one tab stop rather than two per
201
+ folder:
202
+
203
+ | Key | What it does in the tree |
204
+ |---|---|
205
+ | `↑` / `↓` | Move between the rows on screen |
206
+ | `→` | Open a folder (reading its children first if needed), or enter it |
207
+ | `←` | Close the folder, or step out to its parent |
208
+ | `Space` | Open or close the focused folder |
209
+ | `Enter` | Follow the focused row's link |
210
+ | `Home` / `End` | First or last row on screen |
211
+
212
+ The folder's own link carries `aria-expanded`, so a screen reader hears its
213
+ state once; the twisty beside it is a pointer control kept out of the tab order.
214
+ A mouse click moves the tab stop to that row, so `Tab` comes back to where you
215
+ were. Elsewhere the page keeps its own keys: `/` or `Ctrl`/`Cmd`+`K` for quick
216
+ open, `-` to fold, `u` to wrap, `r` for raw Markdown, `y` to copy a line
217
+ reference, `n`/`p` between diff hunks, and `?` for the sheet, whose dialog traps
218
+ `Tab` and returns focus to its button.
219
+
220
+ Printing is supported: the paper gets the light palette whatever the screen is
221
+ showing, the chrome and the tree are dropped, and a file or diff prints whole
222
+ instead of inside its scroll box.
223
+
224
+ ## Previews
225
+
226
+ Text, rendered Markdown, images (thumbnails), and binary/over-size download
227
+ cards, with per-language icons. Broken thumbnails fall back to the category
228
+ icon.
229
+
230
+ Code files render with keywords, strings, numbers, and comments coloured, in the
231
+ dark and light palettes: JavaScript/TypeScript (`js`, `mjs`, `cjs`, `jsx`, `ts`,
232
+ `mts`, `cts`, `tsx`), JSON, CSS (`css`, `scss`, `sass`, `less`), HTML/XML and
233
+ template components (`html`, `htm`, `xml`, `vue`, `svelte`), shell (`sh`,
234
+ `bash`, `zsh`), Python (`py`, `pyw`, `pyi`), Java, YAML (`yaml`, `yml`), and
235
+ SQL. Other text types stay plain.
236
+
237
+ `lib/highlight.ts` is a first-party, escape-first tokenizer for those file
238
+ types. `detectLanguage` maps a filename to a tokenizer and an unmapped type
239
+ stays plain. `highlightLines` walks the whole file, so block comments, template
240
+ literals, open HTML tags, CSS brace depth, and Python triple-quoted strings
241
+ carry across lines; every literal is escaped with the same `escapeHtml` the
242
+ plain view uses, and a line's markup is only the fixed `tok-*` classes the
243
+ stylesheet colours. It backs both the plain text view and fenced code blocks in
244
+ the rendered Markdown view.
245
+
246
+ The Name / Size / Modified headers sort the current directory, directories
247
+ first, and the choice is remembered per browser. Below 520px the Modified column
248
+ is dropped, so the name keeps the row instead of truncating to the first few
249
+ characters. Copy a file's root-relative path or its contents, copy a
250
+ `path:12-30` reference for the lines you selected, and toggle line wrapping for
251
+ text and raw views.
252
+
253
+ ## Markdown preview
254
+
255
+ `.md`, `.markdown`, `.mdown`, `.mkd`, and `.mkdn` files render as headings,
256
+ lists, tables, code, inline and reference links, bare-URL autolinks, and images,
257
+ with a one-click **raw** view (`?raw=1`). The page fills the card, so the scroll
258
+ bar sits at the card edge; headings, prose, and images keep a centred reading
259
+ measure of at most 1012px. Code blocks stay inside that column; tables start at
260
+ it and are never wider than it, so every table in a document ends on the same
261
+ line as the prose above it, and one wider than the pane scrolls, its right edge
262
+ fading until the last column is reached. Columns size to
263
+ the content, and in a pane narrower than 600px they stop shrinking: each cell
264
+ keeps a readable width, so the table scrolls instead of stacking one word per
265
+ line. A task list's checkbox is drawn by the page, so a done item carries the
266
+ success colour in both themes. Named and numeric character references are
267
+ decoded. Headings get stable anchor ids, so in-document `#anchor` links work.
268
+ Fenced code blocks are syntax-highlighted when the fence names a supported
269
+ language.
270
+
271
+ A README's raw HTML is re-emitted through an allowlist (`<details>`,
272
+ `<summary>`, tables, `<kbd>`, images), so it renders without becoming an
273
+ injection path. Raw HTML in the source is escaped, never executed, and external
274
+ images are shown as links rather than fetched. `markdownHtml: false` restores
275
+ escape-only rendering; `markdown: false` falls back to the plain-text view.
276
+
277
+ `markdown.ts` is a first-party, escape-first renderer for the constructs that
278
+ show up in repository READMEs. It emits only a known tag set, escapes every
279
+ literal character, allowlists URL schemes (dropping `javascript:`/`data:`),
280
+ rewrites local links and images to `/view`/`/raw`, and renders an external image
281
+ as a link instead of loading it (the page CSP is `img-src 'self' data:`). Link
282
+ reference definitions (`[id]: url`), including the full `[text][id]`, collapsed
283
+ `[text][]`, and shortcut `[text]` forms, and numeric and common named character
284
+ references are resolved. The Rendered/Raw switch is a server-side `?raw=1` link,
285
+ so it works without JavaScript. Headings are demoted one level so the card title
286
+ stays the page's only `h1`, and each gets a slug `id` (unique in the document). A
287
+ fenced code block whose info string names a supported language is highlighted
288
+ through `lib/highlight.ts` (either an extension or a long-form alias,
289
+ `fenceLanguage`); an absent or unknown language stays plain.
290
+
291
+ A line that starts with an allowed block tag (`<details>`, `<table>`, `<div>`,
292
+ `<pre>`, …), a comment, or a closing tag opens an HTML block that runs to the
293
+ next blank line; text inside it stays text, and a suppressed tag (`<script>`,
294
+ `<style>`, `<svg>`) drops its body through the matching close tag. `raw-html.ts`
295
+ re-emits only allowlisted elements and attributes: `a`/`img` go through the same
296
+ `/view`/`/raw` resolution as Markdown, an external image becomes a link, and
297
+ `class`/`style`/handlers are dropped. Phrasing tags are also accepted inside a
298
+ line, while a block tag mid-paragraph stays escaped. Open elements are balanced
299
+ across blocks, which is how a `<details>` can wrap Markdown paragraphs.
300
+
301
+ ## Quick open
302
+
303
+ `/` (or `Ctrl/Cmd+K`, or the sidebar button) opens a fuzzy path finder over a
304
+ capped index of the tree, with keyboard navigation and a highlighted match;
305
+ Enter opens the file. `/api/files` ranks the cached index with `fuzzy.ts` and
306
+ returns the matched character positions; the client fetches on an 80 ms debounce
307
+ and builds rows with `textContent`, so a file name cannot inject markup. The
308
+ index skips `.git`, `node_modules`, and symlinks, is capped by
309
+ `maxIndexEntries`, and is cached per server for 10 s by `createFileIndex`. The
310
+ palette is a `dialog`/`combobox`/`listbox` with `aria-activedescendant` and
311
+ `Esc` / arrow / `Enter` handling.
312
+
313
+ ## Git context and diff view
314
+
315
+ A read-only header chip shows the checked-out branch (or detached head) and
316
+ reflows on narrow screens. Uncommitted changes are stated once, by the changes
317
+ chip below; turn the diff view off (`gitDiff: false`) and the header reports no
318
+ changes at all.
319
+
320
+ A `● N changes +A −D` chip links to `/diff`, a change overview with
321
+ `git diff --stat` and a per-file status table, and `/diff/<rel>` renders one
322
+ file's unified diff, whose head carries its own `+A −D` and hunk count. Below
323
+ 520px that table's change word is dropped, where the badge already carries the
324
+ same letter and the path needs the room. Changed lines are syntax-highlighted
325
+ with the file's language, and dirty files and their directories carry a marker
326
+ in the listing and the tree. The scope is switchable between `head` / `staged` /
327
+ `worktree`; untracked files show as all-add, an unborn `HEAD` falls back to the
328
+ index, and a non-repository is a plain empty
329
+ state. Read-only, capped, and rendered with the shared diff colours. A diff's
330
+ hunk headers pin to the top of the code viewport while its body scrolls.
331
+
332
+ `git.ts` extends the read-only provider set with a TTL-cached
333
+ `git status --porcelain=v1 -z` and a per-mode `git diff`; `diff.ts` parses the
334
+ unified diff and the porcelain records into plain view models, so `router.ts`
335
+ and `html.ts` stay pure. `head` compares against `HEAD` (falling back to
336
+ `--cached` before the first commit), `staged` against the index, and `worktree`
337
+ against the index from the other side. An untracked file renders as all-add
338
+ through `readFileView`, so binary and over-size handling is shared with the file
339
+ view. `git diff --stat` supplies the chip totals and `changeDirs` derives the
340
+ directory markers; the changed lines are highlighted per hunk by rebuilding the
341
+ old and new sides for `lib/highlight`.
342
+
343
+ ## Live status
344
+
345
+ While a server is running, the extension publishes a two-tone `◉ <port>` chip
346
+ (a green circle-dot and a blue port) under the shared `browse` status key. The
347
+ [`bytefly`](./bytefly.md) extension routes it to line 1's right zone, after
348
+ `⎇ branch` and `⑂ worktree` and in the same run as the board page's port chip;
349
+ it is cleared on stop and on `session_shutdown`. The chip is session-local: it
350
+ reflects only this session's server, with no cross-session sharing.
351
+
352
+ The page has its own live status, which is what a left-open tab reads. A `◉ live`
353
+ chip beside `read-only` says whether status is flowing (green), still
354
+ connecting (accent), stalled (amber, after three missed frames), or offline
355
+ (red); the branch chip, the `● N changes +A −D` chip, and the change markers in
356
+ the tree and the listing update in place; and the footer line reports `up 2m
357
+ 14s · 37 requests`. The chip names its state and never counts, and a frame whose
358
+ change set did not move repaints nothing at all. One Server-Sent Events stream
359
+ per page carries it, on the same loopback server, so nothing extra is opened and
360
+ nothing is written; that stream is also how the server notices the last page
361
+ closing its window, after which it stops listening.
362
+
363
+ The header chip starts hidden and is painted by the client from `/events`:
364
+ `◉ live` in the success colour while frames arrive, `◉ connecting` before the
365
+ first one, `◉ stale` in the warning colour when three intervals pass without a
366
+ frame on an open connection, and `◉ offline` in the danger colour once the
367
+ stream errors. The chip names its state rather than counting, so it is repainted
368
+ only when that state changes. The same frame carries the branch (or detached
369
+ head), the uncommitted-change totals and paths, the server's uptime, and the
370
+ requests it has answered, so the branch chip, the changes chip, the markers, and
371
+ the footer line are painted from one snapshot rather than four requests. Each
372
+ change set also carries a short revision, and a frame whose revision the page
373
+ already painted does no work at all — so an idle tree costs no DOM, however many
374
+ rows the page drew. Losing the stream leaves everything the page last showed in
375
+ place: it is read-only, so a stale label is never a stale action. `"live": false`
376
+ turns the whole surface off — no chip, no stream, no `/events` route — and so
377
+ does JavaScript off.
378
+
379
+ At most eight pages may hold the stream at once: a ninth is refused and its chip
380
+ reads `offline`, which keeps one local page from pinning the server — and the
381
+ git read behind each frame — alive. The stream is also how the server knows a
382
+ page is still there: when the last one leaves, the port is released after ten
383
+ seconds and the chip is cleared, because nothing is left to serve. That is why a
384
+ page with JavaScript off — or with live status off — never counts as a reader,
385
+ and the server then waits for `/browse stop` or the end of the session.
386
+
387
+ `live.ts` builds one snapshot per tick — the git status, the `head` change
388
+ index, the server's uptime, and its request count — and `frameOf` serializes it
389
+ as one `status` event. `createLiveChannel` holds the attached pages and starts
390
+ the ticker on the first attach, so an idle server does no work; it shares a
391
+ single in-flight snapshot between pages and stops the ticker on the last detach
392
+ and on `close()`, which `server.ts` calls before closing the socket. The idle
393
+ stop is one layer down: `lib/http` arms a single timer when a server's last
394
+ stream ends, a reload re-attaches and cancels it, and `server.ts` turns that into
395
+ the extension's `close()` and a cleared chip. Both providers are already
396
+ TTL-cached, so a tick
397
+ re-reads at most one `git status`, and every read failure degrades to `null`
398
+ rather than a failed frame. The event-stream headers and the `retry:` preamble
399
+ live in `lib/http` with the rest of the loopback policy, shared with plan's
400
+ review page. The client half is `live-client.ts`: one `EventSource`, one
401
+ snapshot paint (`textContent` only, never markup), one staleness timeout armed
402
+ per frame, and a `pagehide` cleanup.
403
+
404
+ ## Reload hint
405
+
406
+ A page that lists a folder carries the revision of the names it drew, and asks
407
+ `/api/dir-rev` for the folder's current one on the frame cadence — one directory
408
+ read every five seconds by default, skipped while the tab is hidden and stopped
409
+ for good once it has an answer. A difference reveals `⟳ reload` beside the live
410
+ chip, which reloads the page; the rows themselves are never touched, because a
411
+ page that could grow a row is a page that writes. A folder whose listing was
412
+ truncated, and a file, `/diff`, or error page, has nothing to compare and shows
413
+ no control.
414
+
415
+ `/api/dir-rev` answers one folder's listing revision, so the page can tell
416
+ whether its rows are stale. It goes through the same path guard as every other
417
+ route and reads one directory; its answer is a hash of the names, not the names
418
+ themselves, so it discloses nothing the page above it does not already show. The
419
+ check compares names, so it is a directory read rather than a stat pass, and it
420
+ stops at the first difference because the control, not the checker, is the fix.
421
+
422
+ ## Limitations
423
+
424
+ - Syntax highlighting covers the built-in language set above; any other text
425
+ type renders exactly as before. State that the tokenizer does not carry
426
+ across lines (shell heredocs, interpolation inside a template literal) is
427
+ approximated rather than parsed.
428
+ - Live status updates what the page already contains: the header chips, the
429
+ markers on the rows it rendered, and the footer line. A file that appears on
430
+ disk does not join the listing by itself — the page offers `⟳ reload` instead —
431
+ and the check covers the folder the page lists, by name, not the folders inside
432
+ it, a listed file's contents, the `/diff` table, or a file page's `changes`
433
+ action, which stay page-load snapshots. The branch chip is only patched when
434
+ the page was served inside a repository.
435
+ - `/browse` has no auth; a malicious local page could probe the port. The `Host`
436
+ allowlist and the absence of CORS headers mitigate reads, and the server is
437
+ read-only.
438
+ - Serving the root exposes whatever is on disk to the local user who started it;
439
+ this is intentional and scoped to loopback.
440
+
441
+ ## Non-goals
442
+
443
+ - No editing or writing from the browser.
444
+ - No third-party assets: the Markdown renderer, its raw-HTML sanitizer, and the
445
+ syntax highlighter are first-party, so raw HTML in a Markdown file is
446
+ allowlisted and never executed.
447
+ - No auth and no LAN exposure: loopback only.
448
+ - Not a general static-file server: the root is confined to the effective cwd.
449
+
450
+ ## Pi integration
451
+
452
+ | Integration point | How |
453
+ |---|---|
454
+ | Command | `/browse` registers a single command from the factory; no tools are exposed. |
455
+ | State | The running server, its root, and the session port live in a module-local closure; nothing is persisted and no session entries are written. |
456
+ | Lifecycle | The factory opens no socket; the server is created on `/browse` and closed idempotently by `/browse stop`, by `session_shutdown`, and once its last page has been gone for the idle grace, which also ends every attached status stream. |
457
+
458
+ ## Design notes
459
+
460
+ - **Lifecycle.** `/browse` resolves `resolveEffectiveCwd(ctx.cwd)`, loads config,
461
+ selects the port, parses args, and `await createFileServer(...)`: `realpath`
462
+ the root, bind `127.0.0.1`, await `listening`, return `{ url, port, root,
463
+ close }`. The port is chosen once for the session: a pinned config `port`
464
+ wins, otherwise a random port is drawn and cached after the first successful
465
+ bind, so later starts reuse it (a conflict is reported and the next `/browse`
466
+ rolls another). `/browse stop` and `session_shutdown` await the idempotent
467
+ `close()`; `session_shutdown` also clears the cached port. The page is the
468
+ server's only reader, so the channel reports the last page's departure after
469
+ `IDLE_STOP_MS` and the command closes the server and clears the chip — the
470
+ cached port survives, so the next `/browse` binds the same one.
471
+ - **Pure routing.** `handleRequest(context, method, rawUrl, headers)` validates
472
+ method and `Host`, parses the URL, matches a route, and runs every path
473
+ through `paths.ts`. It returns a plain `ServeResponse`, so routing is tested
474
+ without a socket; `server.ts` is the only part that hands those routes to
475
+ `lib/http`'s loopback server.
476
+ - **One snapshot, one frame.** The status source is shared by every attached
477
+ page, so a tick costs one `git status`, one `git diff --stat`, and one
478
+ serialization however many tabs are open. The frame carries a revision of the
479
+ change set, and the client compares it before painting, which is why an idle
480
+ page does no DOM work. The cadence is what bounds those reads, so the default
481
+ is five seconds rather than matching the providers' two-second render cache.
482
+ - **A poll, not a watcher.** The folder check is one request from the page to
483
+ `/api/dir-rev`, not an `fs.watch`: recursive watching is the one part of
484
+ `node:fs` whose availability and event semantics differ per platform, and it
485
+ would add a long-lived resource to start and release around `close()`. The
486
+ check compares names, so it is a directory read rather than a stat pass, and it
487
+ stops at the first difference because the control, not the checker, is the fix.
488
+ - **Progressive enhancement.** The page is server-rendered first, so it browses
489
+ and renders Markdown without JavaScript; the client only adds the filter, lazy
490
+ disclosure, sorting, wrap, copy, and quick open.
491
+ - **Streaming responses.** The server streams `filePath` responses and
492
+ suppresses bodies for `HEAD`, so large `/raw` files are not buffered.
493
+ - **Root confinement over feature breadth.** The root is deliberately confined
494
+ to the effective cwd rather than serving an arbitrary directory, so a
495
+ worktree session serves the worktree and nothing above it.
496
+
497
+ ## Files
498
+
499
+ | File | Purpose |
500
+ |---|---|
501
+ | `index.ts` | `/browse` command, running-server closure, shutdown cleanup |
502
+ | `config/config.ts` | Config defaults, validation, global/project merge |
503
+ | `files/paths.ts` | Decode/encode, resolve, and `realpath`-containment guard |
504
+ | [`../../lib/escape.ts`](../../lib/escape.ts) | `escapeHtml`, the shared HTML escaping used by every renderer |
505
+ | [`../../lib/highlight.ts`](../../lib/highlight.ts) | First-party escape-first syntax tokenizer for the code view (shared with `plan`) |
506
+ | [`../../lib/web/index.ts`](../../lib/web/index.ts) | The shared Bytefly web brand system: tokens, base, components, layout, runtime, and markup |
507
+ | `files/files.ts` | The barrel over the four reads: one surface for the callers, four modules behind it |
508
+ | `files/classify.ts` | What a name is: kind, Markdown, image, MIME type, and the text sample |
509
+ | `files/list.ts` | Capped directory listings and one file's bytes, over injected filesystem reads |
510
+ | `files/tree.ts` | The sidebar tree and the page-level walk (`directoryView`) that returns it with the listing |
511
+ | `files/index.ts` | The quick-open file index, walked once per root up to a cap |
512
+ | `text/diff.ts` | Pure unified-diff and porcelain-status parsing for the diff view |
513
+ | `text/fuzzy.ts` | Fuzzy path matching and ranking for the quick-open palette |
514
+ | `view/markdown.ts` | First-party escape-first Markdown-to-HTML renderer (fenced code highlighted; raw HTML through `raw-html.ts`) |
515
+ | `view/raw-html.ts` | Allowlisted raw-HTML sanitizer: element/attribute policy, suppressed bodies, and cross-block balancing |
516
+ | `view/urls.ts` | Shared link/image URL policy: scheme allowlist and `/view`/`/raw` rewriting |
517
+ | `view/emit.ts` | The anchor and image elements both renderers emit, so a link written in Markdown and the same one written as HTML are one element |
518
+ | `git/git.ts` | Read-only branch/dirty provider for the header chip |
519
+ | `view/icons.ts` | Inline SVG sprite and the per-language mapping |
520
+ | `view/client.ts` | The `/app.js` source: sort, wrap, copy, hunk navigation, reading progress, and the page keymap |
521
+ | `view/tree.ts` | The sidebar block: path filter, fold-all, lazy tree loading, and the tree's keyboard model (interpolated into `client.ts`) |
522
+ | `view/palette.ts` | The quick-open palette: fuzzy search, the combobox wiring, and the `window.bfPalette` contract (interpolated into `client.ts`) |
523
+ | `view/live-client.ts` | The client's live status block: the event stream, the chips, the markers, and the footer line (interpolated into `client.ts`) |
524
+ | `live/live.ts` | The live status snapshot, its frame, and the fan-out channel that ticks it |
525
+ | `live/rev.ts` | Short digests of the change set and a folder's listing names, so an unchanged frame is skipped |
526
+ | `view/chrome.ts` | Header chrome: the git and changes chips, the live chip, the reload control, and the footer line |
527
+ | `view/styles.ts` | The page-only `browse-*` stylesheet (the `bf-*` kit comes from `lib/web`) |
528
+ | `view/html.ts` | Page renderers: the shared shell, the two-pane layout, the listing, and the cards |
529
+ | `view/diff-html.ts` | The unified-diff body: the gutter, the sign, the hunk sections, and per-hunk highlighting |
530
+ | `transport/router.ts` | Pure request handler: routes, the `/raw` sandbox policy, and the error page |
531
+ | `transport/server.ts` | This extension's routes over `lib/http`'s loopback server: the request count, the stream cap, and the idle policy |
532
+ | [`../../lib/http/index.ts`](../../lib/http/index.ts) | Loopback HTTP layer shared with `plan`: one server entry (`serveLoopback`), page/script/JSON/event-stream headers, `ServeResponse`, the request-envelope helpers, the event-stream sink and its idle grace |
533
+ | [`../../lib/browser.ts`](../../lib/browser.ts) | Cross-platform browser opener (shared with `plan`) |
534
+
535
+ ## Testing
536
+
537
+ `extensions/file-browse/` covers the path guard (traversal, encoded, NUL, malformed,
538
+ absolute, symlink escape and in-root symlink), file classification/listings/
539
+ reads/tree and the quick-open file index, listing revisions, the fuzzy matcher,
540
+ the syntax highlighter (language detection, fence aliases, token classes,
541
+ cross-line state, and escaping), the Markdown renderer (blocks, inline,
542
+ fenced-code highlighting, safety, raw HTML, and path resolution), the raw-HTML
543
+ sanitizer (allowlist, suppressed bodies, attribute policy, balancing, and a
544
+ seeded invariant test over fragment soup),
545
+ the icon mapping and sprite, the page chrome and page renderers, HTML
546
+ escaping/encoding, the client script and its serving, the platform browser
547
+ commands with an injected spawn, the router (routes, `/api/tree`, `/api/files`,
548
+ `/api/dir-rev`, `?raw=1`, status codes, `Host`, `HEAD`, `/raw` headers, and the
549
+ `/diff` view routes and mode validation) without a socket, a real
550
+ `127.0.0.1:0` server, the session-port lifecycle (fixed on first start, reused,
551
+ and re-rolled after a conflict), config normalization and clamping, the git
552
+ status provider (branch, dirty, detached, non-repo, failure, and TTL cache), the
553
+ git diff parser and provider (line kinds, line numbers, status and rename
554
+ parsing, mode filtering, untracked all-add, unborn-HEAD fallback, literal
555
+ pathspec, and TTL cache), the diff renderers (highlighted changed lines, marker
556
+ sets, and chip totals), the live status feed (snapshot fields, degraded
557
+ providers, the frame, and the channel's ticker driven by an injected timer, plus
558
+ the ticker parking on the last detach and on `close()`), the `/events` route and its 404 when the channel is off, a real
559
+ socket that reads a page's first frame and the ticker's next one and sees the
560
+ stream end when the server closes, the live chrome a page renders when on and
561
+ not when off, and the command lifecycle with injected seams.