@rexvane/piweb 0.3.1

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 (535) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +128 -0
  3. package/assets/showcase.png +0 -0
  4. package/bin/pi.js +50 -0
  5. package/bin/piweb.js +12 -0
  6. package/next.config.ts +21 -0
  7. package/package.json +88 -0
  8. package/postcss.config.mjs +7 -0
  9. package/public/file-icons/3d.svg +1 -0
  10. package/public/file-icons/LICENSE +8 -0
  11. package/public/file-icons/adobe-illustrator.svg +1 -0
  12. package/public/file-icons/adobe-photoshop.svg +1 -0
  13. package/public/file-icons/agent.svg +1 -0
  14. package/public/file-icons/asciidoc.svg +1 -0
  15. package/public/file-icons/assembly.svg +1 -0
  16. package/public/file-icons/astro.svg +1 -0
  17. package/public/file-icons/audio.svg +1 -0
  18. package/public/file-icons/authors.svg +1 -0
  19. package/public/file-icons/babel.svg +1 -0
  20. package/public/file-icons/bibliography.svg +1 -0
  21. package/public/file-icons/bicep.svg +1 -0
  22. package/public/file-icons/blender.svg +1 -0
  23. package/public/file-icons/bun.svg +1 -0
  24. package/public/file-icons/c.svg +1 -0
  25. package/public/file-icons/certificate.svg +1 -0
  26. package/public/file-icons/changelog.svg +1 -0
  27. package/public/file-icons/clojure.svg +1 -0
  28. package/public/file-icons/cmake.svg +1 -0
  29. package/public/file-icons/codeowners.svg +1 -0
  30. package/public/file-icons/commitlint.svg +1 -0
  31. package/public/file-icons/conduct.svg +1 -0
  32. package/public/file-icons/console.svg +1 -0
  33. package/public/file-icons/contributing.svg +1 -0
  34. package/public/file-icons/cpp.svg +1 -0
  35. package/public/file-icons/csharp.svg +1 -0
  36. package/public/file-icons/css.svg +1 -0
  37. package/public/file-icons/cursor.svg +1 -0
  38. package/public/file-icons/dart.svg +1 -0
  39. package/public/file-icons/database.svg +1 -0
  40. package/public/file-icons/deno.svg +1 -0
  41. package/public/file-icons/diff.svg +1 -0
  42. package/public/file-icons/docker.svg +1 -0
  43. package/public/file-icons/document.svg +1 -0
  44. package/public/file-icons/editorconfig.svg +1 -0
  45. package/public/file-icons/ejs.svg +1 -0
  46. package/public/file-icons/elixir.svg +1 -0
  47. package/public/file-icons/elm.svg +1 -0
  48. package/public/file-icons/email.svg +1 -0
  49. package/public/file-icons/erlang.svg +1 -0
  50. package/public/file-icons/eslint.svg +1 -0
  51. package/public/file-icons/favicon.svg +1 -0
  52. package/public/file-icons/file.svg +1 -0
  53. package/public/file-icons/folder-admin-open.svg +1 -0
  54. package/public/file-icons/folder-admin.svg +1 -0
  55. package/public/file-icons/folder-android-open.svg +1 -0
  56. package/public/file-icons/folder-android.svg +1 -0
  57. package/public/file-icons/folder-api-open.svg +1 -0
  58. package/public/file-icons/folder-api.svg +1 -0
  59. package/public/file-icons/folder-app-open.svg +1 -0
  60. package/public/file-icons/folder-app.svg +1 -0
  61. package/public/file-icons/folder-archive-open.svg +1 -0
  62. package/public/file-icons/folder-archive.svg +1 -0
  63. package/public/file-icons/folder-atom-open.svg +1 -0
  64. package/public/file-icons/folder-atom.svg +1 -0
  65. package/public/file-icons/folder-audio-open.svg +1 -0
  66. package/public/file-icons/folder-audio.svg +1 -0
  67. package/public/file-icons/folder-aws-open.svg +1 -0
  68. package/public/file-icons/folder-aws.svg +1 -0
  69. package/public/file-icons/folder-backup-open.svg +1 -0
  70. package/public/file-icons/folder-backup.svg +1 -0
  71. package/public/file-icons/folder-benchmark-open.svg +1 -0
  72. package/public/file-icons/folder-benchmark.svg +1 -0
  73. package/public/file-icons/folder-cart-open.svg +1 -0
  74. package/public/file-icons/folder-cart.svg +1 -0
  75. package/public/file-icons/folder-ci-open.svg +1 -0
  76. package/public/file-icons/folder-ci.svg +1 -0
  77. package/public/file-icons/folder-circleci-open.svg +1 -0
  78. package/public/file-icons/folder-circleci.svg +1 -0
  79. package/public/file-icons/folder-class-open.svg +1 -0
  80. package/public/file-icons/folder-class.svg +1 -0
  81. package/public/file-icons/folder-client-open.svg +1 -0
  82. package/public/file-icons/folder-client.svg +1 -0
  83. package/public/file-icons/folder-command-open.svg +1 -0
  84. package/public/file-icons/folder-command.svg +1 -0
  85. package/public/file-icons/folder-components-open.svg +1 -0
  86. package/public/file-icons/folder-components.svg +1 -0
  87. package/public/file-icons/folder-config-open.svg +1 -0
  88. package/public/file-icons/folder-config.svg +1 -0
  89. package/public/file-icons/folder-console-open.svg +1 -0
  90. package/public/file-icons/folder-console.svg +1 -0
  91. package/public/file-icons/folder-content-open.svg +1 -0
  92. package/public/file-icons/folder-content.svg +1 -0
  93. package/public/file-icons/folder-context-open.svg +1 -0
  94. package/public/file-icons/folder-context.svg +1 -0
  95. package/public/file-icons/folder-contract-open.svg +1 -0
  96. package/public/file-icons/folder-contract.svg +1 -0
  97. package/public/file-icons/folder-controller-open.svg +1 -0
  98. package/public/file-icons/folder-controller.svg +1 -0
  99. package/public/file-icons/folder-core-open.svg +1 -0
  100. package/public/file-icons/folder-core.svg +1 -0
  101. package/public/file-icons/folder-coverage-open.svg +1 -0
  102. package/public/file-icons/folder-coverage.svg +1 -0
  103. package/public/file-icons/folder-css-open.svg +1 -0
  104. package/public/file-icons/folder-css.svg +1 -0
  105. package/public/file-icons/folder-database-open.svg +1 -0
  106. package/public/file-icons/folder-database.svg +1 -0
  107. package/public/file-icons/folder-debug-open.svg +1 -0
  108. package/public/file-icons/folder-debug.svg +1 -0
  109. package/public/file-icons/folder-deprecated-open.svg +1 -0
  110. package/public/file-icons/folder-deprecated.svg +1 -0
  111. package/public/file-icons/folder-desktop-open.svg +1 -0
  112. package/public/file-icons/folder-desktop.svg +1 -0
  113. package/public/file-icons/folder-dist-open.svg +1 -0
  114. package/public/file-icons/folder-dist.svg +1 -0
  115. package/public/file-icons/folder-docker-open.svg +1 -0
  116. package/public/file-icons/folder-docker.svg +1 -0
  117. package/public/file-icons/folder-docs-open.svg +1 -0
  118. package/public/file-icons/folder-docs.svg +1 -0
  119. package/public/file-icons/folder-element-open.svg +1 -0
  120. package/public/file-icons/folder-element.svg +1 -0
  121. package/public/file-icons/folder-environment-open.svg +1 -0
  122. package/public/file-icons/folder-environment.svg +1 -0
  123. package/public/file-icons/folder-event-open.svg +1 -0
  124. package/public/file-icons/folder-event.svg +1 -0
  125. package/public/file-icons/folder-examples-open.svg +1 -0
  126. package/public/file-icons/folder-examples.svg +1 -0
  127. package/public/file-icons/folder-features-open.svg +1 -0
  128. package/public/file-icons/folder-features.svg +1 -0
  129. package/public/file-icons/folder-font-open.svg +1 -0
  130. package/public/file-icons/folder-font.svg +1 -0
  131. package/public/file-icons/folder-functions-open.svg +1 -0
  132. package/public/file-icons/folder-functions.svg +1 -0
  133. package/public/file-icons/folder-generator-open.svg +1 -0
  134. package/public/file-icons/folder-generator.svg +1 -0
  135. package/public/file-icons/folder-git-open.svg +1 -0
  136. package/public/file-icons/folder-git.svg +1 -0
  137. package/public/file-icons/folder-github-open.svg +1 -0
  138. package/public/file-icons/folder-github.svg +1 -0
  139. package/public/file-icons/folder-gitlab-open.svg +1 -0
  140. package/public/file-icons/folder-gitlab.svg +1 -0
  141. package/public/file-icons/folder-graphql-open.svg +1 -0
  142. package/public/file-icons/folder-graphql.svg +1 -0
  143. package/public/file-icons/folder-helper-open.svg +1 -0
  144. package/public/file-icons/folder-helper.svg +1 -0
  145. package/public/file-icons/folder-hook-open.svg +1 -0
  146. package/public/file-icons/folder-hook.svg +1 -0
  147. package/public/file-icons/folder-husky-open.svg +1 -0
  148. package/public/file-icons/folder-husky.svg +1 -0
  149. package/public/file-icons/folder-i18n-open.svg +1 -0
  150. package/public/file-icons/folder-i18n.svg +1 -0
  151. package/public/file-icons/folder-images-open.svg +1 -0
  152. package/public/file-icons/folder-images.svg +1 -0
  153. package/public/file-icons/folder-include-open.svg +1 -0
  154. package/public/file-icons/folder-include.svg +1 -0
  155. package/public/file-icons/folder-intellij-open.svg +1 -0
  156. package/public/file-icons/folder-intellij.svg +1 -0
  157. package/public/file-icons/folder-interface-open.svg +1 -0
  158. package/public/file-icons/folder-interface.svg +1 -0
  159. package/public/file-icons/folder-ios-open.svg +1 -0
  160. package/public/file-icons/folder-ios.svg +1 -0
  161. package/public/file-icons/folder-java-open.svg +1 -0
  162. package/public/file-icons/folder-java.svg +1 -0
  163. package/public/file-icons/folder-job-open.svg +1 -0
  164. package/public/file-icons/folder-job.svg +1 -0
  165. package/public/file-icons/folder-jupyter-open.svg +1 -0
  166. package/public/file-icons/folder-jupyter.svg +1 -0
  167. package/public/file-icons/folder-keys-open.svg +1 -0
  168. package/public/file-icons/folder-keys.svg +1 -0
  169. package/public/file-icons/folder-kubernetes-open.svg +1 -0
  170. package/public/file-icons/folder-kubernetes.svg +1 -0
  171. package/public/file-icons/folder-layout-open.svg +1 -0
  172. package/public/file-icons/folder-layout.svg +1 -0
  173. package/public/file-icons/folder-less-open.svg +1 -0
  174. package/public/file-icons/folder-less.svg +1 -0
  175. package/public/file-icons/folder-lib-open.svg +1 -0
  176. package/public/file-icons/folder-lib.svg +1 -0
  177. package/public/file-icons/folder-log-open.svg +1 -0
  178. package/public/file-icons/folder-log.svg +1 -0
  179. package/public/file-icons/folder-messages-open.svg +1 -0
  180. package/public/file-icons/folder-messages.svg +1 -0
  181. package/public/file-icons/folder-meta-open.svg +1 -0
  182. package/public/file-icons/folder-meta.svg +1 -0
  183. package/public/file-icons/folder-middleware-open.svg +1 -0
  184. package/public/file-icons/folder-middleware.svg +1 -0
  185. package/public/file-icons/folder-migrations-open.svg +1 -0
  186. package/public/file-icons/folder-migrations.svg +1 -0
  187. package/public/file-icons/folder-mobile-open.svg +1 -0
  188. package/public/file-icons/folder-mobile.svg +1 -0
  189. package/public/file-icons/folder-mock-open.svg +1 -0
  190. package/public/file-icons/folder-mock.svg +1 -0
  191. package/public/file-icons/folder-molecule-open.svg +1 -0
  192. package/public/file-icons/folder-molecule.svg +1 -0
  193. package/public/file-icons/folder-next-open.svg +1 -0
  194. package/public/file-icons/folder-next.svg +1 -0
  195. package/public/file-icons/folder-node-open.svg +1 -0
  196. package/public/file-icons/folder-node.svg +1 -0
  197. package/public/file-icons/folder-nuxt-open.svg +1 -0
  198. package/public/file-icons/folder-nuxt.svg +1 -0
  199. package/public/file-icons/folder-open.svg +1 -0
  200. package/public/file-icons/folder-organism-open.svg +1 -0
  201. package/public/file-icons/folder-organism.svg +1 -0
  202. package/public/file-icons/folder-packages-open.svg +1 -0
  203. package/public/file-icons/folder-packages.svg +1 -0
  204. package/public/file-icons/folder-plugin-open.svg +1 -0
  205. package/public/file-icons/folder-plugin.svg +1 -0
  206. package/public/file-icons/folder-prisma-open.svg +1 -0
  207. package/public/file-icons/folder-prisma.svg +1 -0
  208. package/public/file-icons/folder-prompts-open.svg +1 -0
  209. package/public/file-icons/folder-prompts.svg +1 -0
  210. package/public/file-icons/folder-proto-open.svg +1 -0
  211. package/public/file-icons/folder-proto.svg +1 -0
  212. package/public/file-icons/folder-public-open.svg +1 -0
  213. package/public/file-icons/folder-public.svg +1 -0
  214. package/public/file-icons/folder-python-open.svg +1 -0
  215. package/public/file-icons/folder-python.svg +1 -0
  216. package/public/file-icons/folder-queue-open.svg +1 -0
  217. package/public/file-icons/folder-queue.svg +1 -0
  218. package/public/file-icons/folder-resource-open.svg +1 -0
  219. package/public/file-icons/folder-resource.svg +1 -0
  220. package/public/file-icons/folder-review-open.svg +1 -0
  221. package/public/file-icons/folder-review.svg +1 -0
  222. package/public/file-icons/folder-robot-open.svg +1 -0
  223. package/public/file-icons/folder-robot.svg +1 -0
  224. package/public/file-icons/folder-routes-open.svg +1 -0
  225. package/public/file-icons/folder-routes.svg +1 -0
  226. package/public/file-icons/folder-rust-open.svg +1 -0
  227. package/public/file-icons/folder-rust.svg +1 -0
  228. package/public/file-icons/folder-sass-open.svg +1 -0
  229. package/public/file-icons/folder-sass.svg +1 -0
  230. package/public/file-icons/folder-scripts-open.svg +1 -0
  231. package/public/file-icons/folder-scripts.svg +1 -0
  232. package/public/file-icons/folder-secure-open.svg +1 -0
  233. package/public/file-icons/folder-secure.svg +1 -0
  234. package/public/file-icons/folder-seeders-open.svg +1 -0
  235. package/public/file-icons/folder-seeders.svg +1 -0
  236. package/public/file-icons/folder-server-open.svg +1 -0
  237. package/public/file-icons/folder-server.svg +1 -0
  238. package/public/file-icons/folder-shared-open.svg +1 -0
  239. package/public/file-icons/folder-shared.svg +1 -0
  240. package/public/file-icons/folder-skills-open.svg +1 -0
  241. package/public/file-icons/folder-skills.svg +1 -0
  242. package/public/file-icons/folder-src-open.svg +1 -0
  243. package/public/file-icons/folder-src.svg +1 -0
  244. package/public/file-icons/folder-store-open.svg +1 -0
  245. package/public/file-icons/folder-store.svg +1 -0
  246. package/public/file-icons/folder-storybook-open.svg +1 -0
  247. package/public/file-icons/folder-storybook.svg +1 -0
  248. package/public/file-icons/folder-supabase-open.svg +1 -0
  249. package/public/file-icons/folder-supabase.svg +1 -0
  250. package/public/file-icons/folder-svelte-open.svg +1 -0
  251. package/public/file-icons/folder-svelte.svg +1 -0
  252. package/public/file-icons/folder-target-open.svg +1 -0
  253. package/public/file-icons/folder-target.svg +1 -0
  254. package/public/file-icons/folder-tasks-open.svg +1 -0
  255. package/public/file-icons/folder-tasks.svg +1 -0
  256. package/public/file-icons/folder-temp-open.svg +1 -0
  257. package/public/file-icons/folder-temp.svg +1 -0
  258. package/public/file-icons/folder-template-open.svg +1 -0
  259. package/public/file-icons/folder-template.svg +1 -0
  260. package/public/file-icons/folder-terraform-open.svg +1 -0
  261. package/public/file-icons/folder-terraform.svg +1 -0
  262. package/public/file-icons/folder-test-open.svg +1 -0
  263. package/public/file-icons/folder-test.svg +1 -0
  264. package/public/file-icons/folder-theme-open.svg +1 -0
  265. package/public/file-icons/folder-theme.svg +1 -0
  266. package/public/file-icons/folder-tools-open.svg +1 -0
  267. package/public/file-icons/folder-tools.svg +1 -0
  268. package/public/file-icons/folder-turborepo-open.svg +1 -0
  269. package/public/file-icons/folder-turborepo.svg +1 -0
  270. package/public/file-icons/folder-typescript-open.svg +1 -0
  271. package/public/file-icons/folder-typescript.svg +1 -0
  272. package/public/file-icons/folder-ui-open.svg +1 -0
  273. package/public/file-icons/folder-ui.svg +1 -0
  274. package/public/file-icons/folder-utils-open.svg +1 -0
  275. package/public/file-icons/folder-utils.svg +1 -0
  276. package/public/file-icons/folder-video-open.svg +1 -0
  277. package/public/file-icons/folder-video.svg +1 -0
  278. package/public/file-icons/folder-views-open.svg +1 -0
  279. package/public/file-icons/folder-views.svg +1 -0
  280. package/public/file-icons/folder-vscode-open.svg +1 -0
  281. package/public/file-icons/folder-vscode.svg +1 -0
  282. package/public/file-icons/folder.svg +1 -0
  283. package/public/file-icons/font.svg +1 -0
  284. package/public/file-icons/fsharp.svg +1 -0
  285. package/public/file-icons/gemfile.svg +1 -0
  286. package/public/file-icons/git.svg +1 -0
  287. package/public/file-icons/go-mod.svg +1 -0
  288. package/public/file-icons/go.svg +1 -0
  289. package/public/file-icons/gradle.svg +1 -0
  290. package/public/file-icons/graphql.svg +1 -0
  291. package/public/file-icons/groovy.svg +1 -0
  292. package/public/file-icons/h.svg +1 -0
  293. package/public/file-icons/handlebars.svg +1 -0
  294. package/public/file-icons/haskell.svg +1 -0
  295. package/public/file-icons/hcl.svg +1 -0
  296. package/public/file-icons/heroku.svg +1 -0
  297. package/public/file-icons/hpp.svg +1 -0
  298. package/public/file-icons/html.svg +1 -0
  299. package/public/file-icons/husky.svg +1 -0
  300. package/public/file-icons/i18n.svg +1 -0
  301. package/public/file-icons/image.svg +1 -0
  302. package/public/file-icons/java.svg +1 -0
  303. package/public/file-icons/javascript.svg +1 -0
  304. package/public/file-icons/jenkins.svg +1 -0
  305. package/public/file-icons/jest.svg +1 -0
  306. package/public/file-icons/jsconfig.svg +1 -0
  307. package/public/file-icons/json.svg +1 -0
  308. package/public/file-icons/julia.svg +1 -0
  309. package/public/file-icons/jupyter.svg +1 -0
  310. package/public/file-icons/just.svg +1 -0
  311. package/public/file-icons/key.svg +1 -0
  312. package/public/file-icons/kotlin.svg +1 -0
  313. package/public/file-icons/lerna.svg +1 -0
  314. package/public/file-icons/less.svg +1 -0
  315. package/public/file-icons/license.svg +1 -0
  316. package/public/file-icons/lintstaged.svg +1 -0
  317. package/public/file-icons/liquid.svg +1 -0
  318. package/public/file-icons/lock.svg +1 -0
  319. package/public/file-icons/log.svg +1 -0
  320. package/public/file-icons/lua.svg +1 -0
  321. package/public/file-icons/makefile.svg +1 -0
  322. package/public/file-icons/markdown.svg +1 -0
  323. package/public/file-icons/maven.svg +1 -0
  324. package/public/file-icons/mdx.svg +1 -0
  325. package/public/file-icons/netlify.svg +1 -0
  326. package/public/file-icons/next.svg +1 -0
  327. package/public/file-icons/nim.svg +1 -0
  328. package/public/file-icons/nix.svg +1 -0
  329. package/public/file-icons/nodejs.svg +1 -0
  330. package/public/file-icons/nodemon.svg +1 -0
  331. package/public/file-icons/npm.svg +1 -0
  332. package/public/file-icons/nx.svg +1 -0
  333. package/public/file-icons/objective-c.svg +1 -0
  334. package/public/file-icons/objective-cpp.svg +1 -0
  335. package/public/file-icons/ocaml.svg +1 -0
  336. package/public/file-icons/pdf.svg +1 -0
  337. package/public/file-icons/php.svg +1 -0
  338. package/public/file-icons/pm2-ecosystem.svg +1 -0
  339. package/public/file-icons/pnpm.svg +1 -0
  340. package/public/file-icons/poetry.svg +1 -0
  341. package/public/file-icons/postcss.svg +1 -0
  342. package/public/file-icons/powerpoint.svg +1 -0
  343. package/public/file-icons/powershell.svg +1 -0
  344. package/public/file-icons/prettier.svg +1 -0
  345. package/public/file-icons/prisma.svg +1 -0
  346. package/public/file-icons/prolog.svg +1 -0
  347. package/public/file-icons/proto.svg +1 -0
  348. package/public/file-icons/pug.svg +1 -0
  349. package/public/file-icons/python-misc.svg +1 -0
  350. package/public/file-icons/python.svg +1 -0
  351. package/public/file-icons/r.svg +1 -0
  352. package/public/file-icons/razor.svg +1 -0
  353. package/public/file-icons/react.svg +1 -0
  354. package/public/file-icons/react_ts.svg +1 -0
  355. package/public/file-icons/readme.svg +1 -0
  356. package/public/file-icons/renovate.svg +1 -0
  357. package/public/file-icons/robots.svg +1 -0
  358. package/public/file-icons/rollup.svg +1 -0
  359. package/public/file-icons/ruby.svg +1 -0
  360. package/public/file-icons/rust.svg +1 -0
  361. package/public/file-icons/sass.svg +1 -0
  362. package/public/file-icons/scala.svg +1 -0
  363. package/public/file-icons/semantic-release.svg +1 -0
  364. package/public/file-icons/settings.svg +1 -0
  365. package/public/file-icons/shader.svg +1 -0
  366. package/public/file-icons/sml.svg +1 -0
  367. package/public/file-icons/solidity.svg +1 -0
  368. package/public/file-icons/stylus.svg +1 -0
  369. package/public/file-icons/svelte.svg +1 -0
  370. package/public/file-icons/svg.svg +1 -0
  371. package/public/file-icons/swift.svg +1 -0
  372. package/public/file-icons/table.svg +1 -0
  373. package/public/file-icons/tailwindcss.svg +1 -0
  374. package/public/file-icons/taskfile.svg +1 -0
  375. package/public/file-icons/terraform.svg +1 -0
  376. package/public/file-icons/test-js.svg +1 -0
  377. package/public/file-icons/test-jsx.svg +1 -0
  378. package/public/file-icons/test-ts.svg +1 -0
  379. package/public/file-icons/tex.svg +1 -0
  380. package/public/file-icons/toml.svg +1 -0
  381. package/public/file-icons/travis.svg +1 -0
  382. package/public/file-icons/tsconfig.svg +1 -0
  383. package/public/file-icons/tune.svg +1 -0
  384. package/public/file-icons/turborepo.svg +1 -0
  385. package/public/file-icons/typescript-def.svg +1 -0
  386. package/public/file-icons/typescript.svg +1 -0
  387. package/public/file-icons/unity.svg +1 -0
  388. package/public/file-icons/uv.svg +1 -0
  389. package/public/file-icons/vala.svg +1 -0
  390. package/public/file-icons/vercel.svg +1 -0
  391. package/public/file-icons/video.svg +1 -0
  392. package/public/file-icons/vim.svg +1 -0
  393. package/public/file-icons/vite.svg +1 -0
  394. package/public/file-icons/vitest.svg +1 -0
  395. package/public/file-icons/vlang.svg +1 -0
  396. package/public/file-icons/vue.svg +1 -0
  397. package/public/file-icons/webassembly.svg +1 -0
  398. package/public/file-icons/webpack.svg +1 -0
  399. package/public/file-icons/word.svg +1 -0
  400. package/public/file-icons/xml.svg +1 -0
  401. package/public/file-icons/yaml.svg +1 -0
  402. package/public/file-icons/yarn.svg +1 -0
  403. package/public/file-icons/zig.svg +1 -0
  404. package/public/file-icons/zip.svg +1 -0
  405. package/public/provider-icons/antgroup-color.svg +1 -0
  406. package/public/provider-icons/anthropic.svg +1 -0
  407. package/public/provider-icons/azure-color.svg +1 -0
  408. package/public/provider-icons/baseten.svg +1 -0
  409. package/public/provider-icons/bedrock-color.svg +1 -0
  410. package/public/provider-icons/cerebras-color.svg +1 -0
  411. package/public/provider-icons/cloudflare-color.svg +1 -0
  412. package/public/provider-icons/deepseek-color.svg +1 -0
  413. package/public/provider-icons/fireworks-color.svg +1 -0
  414. package/public/provider-icons/githubcopilot.svg +1 -0
  415. package/public/provider-icons/google-color.svg +1 -0
  416. package/public/provider-icons/googlecloud-color.svg +1 -0
  417. package/public/provider-icons/groq.svg +1 -0
  418. package/public/provider-icons/huggingface-color.svg +1 -0
  419. package/public/provider-icons/kimi-color.svg +1 -0
  420. package/public/provider-icons/minimax-color.svg +1 -0
  421. package/public/provider-icons/mistral-color.svg +1 -0
  422. package/public/provider-icons/moonshot.svg +1 -0
  423. package/public/provider-icons/nvidia-color.svg +1 -0
  424. package/public/provider-icons/openai.svg +1 -0
  425. package/public/provider-icons/opencode.svg +1 -0
  426. package/public/provider-icons/openrouter-color.svg +1 -0
  427. package/public/provider-icons/qwen-color.svg +1 -0
  428. package/public/provider-icons/together-color.svg +1 -0
  429. package/public/provider-icons/vercel.svg +1 -0
  430. package/public/provider-icons/xai.svg +1 -0
  431. package/public/provider-icons/xiaomimimo.svg +1 -0
  432. package/public/provider-icons/zai.svg +1 -0
  433. package/scripts/build-output.mjs +131 -0
  434. package/scripts/dev.mjs +18 -0
  435. package/scripts/entrypoint.mjs +8 -0
  436. package/scripts/install-build.mjs +134 -0
  437. package/scripts/launcher.mjs +249 -0
  438. package/scripts/pick-folder.ps1 +110 -0
  439. package/scripts/postinstall.mjs +12 -0
  440. package/scripts/process-runner.mjs +60 -0
  441. package/scripts/release.mjs +172 -0
  442. package/scripts/sync-file-icons.mjs +118 -0
  443. package/scripts/sync-provider-icons.mjs +41 -0
  444. package/src/app/api/agent/[id]/events/route.ts +81 -0
  445. package/src/app/api/agent/[id]/route.ts +24 -0
  446. package/src/app/api/agent/[id]/tree/route.ts +49 -0
  447. package/src/app/api/agent/new/route.ts +19 -0
  448. package/src/app/api/config/route.ts +22 -0
  449. package/src/app/api/files/route.ts +63 -0
  450. package/src/app/api/git/route.ts +32 -0
  451. package/src/app/api/growth/route.ts +50 -0
  452. package/src/app/api/health/route.ts +7 -0
  453. package/src/app/api/models/route.ts +129 -0
  454. package/src/app/api/pi-settings/route.ts +22 -0
  455. package/src/app/api/plugins/route.ts +79 -0
  456. package/src/app/api/security/route.ts +41 -0
  457. package/src/app/api/sessions/[id]/export/route.ts +25 -0
  458. package/src/app/api/sessions/[id]/route.ts +37 -0
  459. package/src/app/api/sessions/route.ts +23 -0
  460. package/src/app/api/skills/route.ts +39 -0
  461. package/src/app/api/update/route.ts +33 -0
  462. package/src/app/api/version/route.ts +8 -0
  463. package/src/app/api/web-auth/route.ts +80 -0
  464. package/src/app/api/workspaces/route.ts +78 -0
  465. package/src/app/globals.css +2039 -0
  466. package/src/app/icon.svg +21 -0
  467. package/src/app/layout.tsx +29 -0
  468. package/src/app/login/page.tsx +111 -0
  469. package/src/app/page.tsx +10 -0
  470. package/src/components/AppShell.tsx +1171 -0
  471. package/src/components/ChatInput.tsx +729 -0
  472. package/src/components/ChatWindow.tsx +1320 -0
  473. package/src/components/ContextMeter.tsx +131 -0
  474. package/src/components/DiffView.tsx +139 -0
  475. package/src/components/ExtensionUI.tsx +181 -0
  476. package/src/components/FileViewer.tsx +555 -0
  477. package/src/components/FullDiff.tsx +220 -0
  478. package/src/components/GitPanel.tsx +357 -0
  479. package/src/components/GrowthTree.tsx +317 -0
  480. package/src/components/ModelSelector.tsx +286 -0
  481. package/src/components/OutlineRail.tsx +166 -0
  482. package/src/components/PiMark.tsx +79 -0
  483. package/src/components/ProjectPanel.tsx +309 -0
  484. package/src/components/ProviderBrand.tsx +28 -0
  485. package/src/components/ProviderSetupModal.module.css +560 -0
  486. package/src/components/ProviderSetupModal.tsx +559 -0
  487. package/src/components/SessionSidebar.tsx +1066 -0
  488. package/src/components/SettingsPanel.tsx +2216 -0
  489. package/src/components/TrajectoryAnalyzer.module.css +225 -0
  490. package/src/components/TrajectoryView.tsx +289 -0
  491. package/src/components/icons.tsx +443 -0
  492. package/src/hooks/useFileViewer.ts +58 -0
  493. package/src/hooks/useGrowth.ts +635 -0
  494. package/src/hooks/usePiWeb.ts +900 -0
  495. package/src/i18n.tsx +1043 -0
  496. package/src/lib/agent-manager.ts +1348 -0
  497. package/src/lib/app-root.ts +4 -0
  498. package/src/lib/auth.ts +51 -0
  499. package/src/lib/command-validation.ts +116 -0
  500. package/src/lib/enter-behavior.ts +40 -0
  501. package/src/lib/extension-ui.ts +134 -0
  502. package/src/lib/file-icons.json +557 -0
  503. package/src/lib/file-icons.ts +39 -0
  504. package/src/lib/files-service.ts +280 -0
  505. package/src/lib/git-service.ts +255 -0
  506. package/src/lib/growth-rounds.ts +84 -0
  507. package/src/lib/growth-service.ts +586 -0
  508. package/src/lib/growth-tracker.ts +328 -0
  509. package/src/lib/growth-tree.ts +245 -0
  510. package/src/lib/growth-turns.ts +23 -0
  511. package/src/lib/highlight.ts +59 -0
  512. package/src/lib/model-draft.ts +103 -0
  513. package/src/lib/models-service.ts +852 -0
  514. package/src/lib/path-security.ts +101 -0
  515. package/src/lib/pi-settings.ts +115 -0
  516. package/src/lib/pi.ts +367 -0
  517. package/src/lib/plugins-service.ts +312 -0
  518. package/src/lib/process-format.ts +261 -0
  519. package/src/lib/provider-display.ts +57 -0
  520. package/src/lib/security-service.ts +52 -0
  521. package/src/lib/semver.ts +39 -0
  522. package/src/lib/session-reader.ts +204 -0
  523. package/src/lib/settings-write-lock.ts +45 -0
  524. package/src/lib/skills-service.ts +97 -0
  525. package/src/lib/text-sanitize.ts +20 -0
  526. package/src/lib/theme.ts +137 -0
  527. package/src/lib/trajectory.ts +294 -0
  528. package/src/lib/types.ts +300 -0
  529. package/src/lib/update-service.ts +129 -0
  530. package/src/lib/version.ts +6 -0
  531. package/src/lib/web-auth-shared.ts +35 -0
  532. package/src/lib/web-auth.ts +53 -0
  533. package/src/lib/workspace-store.ts +261 -0
  534. package/src/proxy.ts +53 -0
  535. package/tsconfig.json +49 -0
@@ -0,0 +1,1171 @@
1
+ "use client";
2
+
3
+ /**
4
+ * AppShell:三栏网格(对齐 dsh ui-layout 几何)+ 拖拽调宽 + 侧栏窄条 +
5
+ * 头部(对话/轨迹标签 + Session log)+ Hero 新会话页 + 设置弹窗。
6
+ */
7
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8
+ import { PiMark } from "@/components/PiMark";
9
+ import { ChatInput, EMPTY_CHAT_DRAFT, type ChatDraft, type ChatDraftUpdate } from "@/components/ChatInput";
10
+ import { ChatWindow, SessionStatsBar } from "@/components/ChatWindow";
11
+ import { ExtensionDialogHost, ExtensionNotices } from "@/components/ExtensionUI";
12
+ import dynamic from "next/dynamic";
13
+ import { SessionSidebar } from "@/components/SessionSidebar";
14
+
15
+ // 首屏不需要的重组件按需加载(设置面板含供应商配置与代码高亮,轨迹/文件只在打开时才用)
16
+ const SettingsPanel = dynamic(() => import("@/components/SettingsPanel").then((m) => m.SettingsPanel), { ssr: false });
17
+ const TrajectoryView = dynamic(() => import("@/components/TrajectoryView").then((m) => m.TrajectoryView), { ssr: false });
18
+ const TrajInspector = dynamic(() => import("@/components/TrajectoryView").then((m) => m.TrajInspector), { ssr: false });
19
+ const ProjectPanel = dynamic(() => import("@/components/ProjectPanel").then((m) => m.ProjectPanel), { ssr: false });
20
+ const FileViewer = dynamic(() => import("@/components/FileViewer").then((m) => m.FileViewer), { ssr: false });
21
+ const GitPanel = dynamic(() => import("@/components/GitPanel").then((m) => m.GitPanel), { ssr: false });
22
+ import {
23
+ IconCheckOutline14,
24
+ IconChevronDown14,
25
+ IconFolderClose16,
26
+ IconFolderOpenOutline16,
27
+ IconPanelLeftOutline16,
28
+ IconProjectAddOutline16,
29
+ } from "@/components/icons";
30
+ import { useI18n } from "@/i18n";
31
+ import { usePiWeb } from "@/hooks/usePiWeb";
32
+ import { useGrowth } from "@/hooks/useGrowth";
33
+ import { useFileViewer } from "@/hooks/useFileViewer";
34
+ import type { TreeNode } from "@/lib/growth-tree";
35
+ import { syncPebrelTheme } from "@/lib/theme";
36
+ import type { ModelChoice } from "@/components/ModelSelector";
37
+ import type { ImageAttachment, TrajEntry } from "@/lib/types";
38
+
39
+ // dsh ui-layout columns.ts 几何常量
40
+ const SIDEBAR_MIN = 264;
41
+ const SIDEBAR_MAX = 420;
42
+ const SIDEBAR_DEFAULT = 280;
43
+ const SIDEBAR_COLLAPSED = 56;
44
+ const DETAILS_MIN = 300;
45
+ const DETAILS_MAX = 760;
46
+ const DETAILS_DEFAULT = 360;
47
+ const PROJECT_MIN = 280;
48
+ const PROJECT_MAX = 640;
49
+ const PROJECT_DEFAULT = 380;
50
+ function persist(key: string, value: number) {
51
+ localStorage.setItem(key, String(value));
52
+ }
53
+ function restore(key: string, fallback: number): number {
54
+ const v = parseInt(localStorage.getItem(key) ?? "", 10);
55
+ return Number.isNaN(v) ? fallback : v;
56
+ }
57
+
58
+ export function AppShell() {
59
+ const { t } = useI18n();
60
+ const {
61
+ sessions,
62
+ sessionListError,
63
+ retrySessionList,
64
+ archivedSessions,
65
+ archivedSessionPaths,
66
+ currentId,
67
+ currentPath,
68
+ state,
69
+ models,
70
+ addedWorkspaces,
71
+ removedWorkspaces,
72
+ workspaceAliases,
73
+ getWorkspaceName,
74
+ renameWorkspace,
75
+ patchSessionName,
76
+ archiveSession,
77
+ unarchiveSession,
78
+ resync,
79
+ groupBy,
80
+ orderBy,
81
+ setGroupBy,
82
+ setOrderBy,
83
+ addWorkspaceByPicker,
84
+ removeWorkspace,
85
+ refreshModels,
86
+ sendCommand,
87
+ newSession,
88
+ openSession,
89
+ closeSession,
90
+ setToolPreset,
91
+ clearError,
92
+ clearCompaction,
93
+ setError,
94
+ answerExtensionDialog,
95
+ dismissExtensionNotice,
96
+ } = usePiWeb();
97
+
98
+ const [sidebarWidth, setSidebarWidth] = useState(SIDEBAR_DEFAULT);
99
+ const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
100
+ const [detailsWidth, setDetailsWidth] = useState(DETAILS_DEFAULT);
101
+ /** 项目栏(侧栏与对话之间的第四列:项目生长可视化) */
102
+ const [projectOpen, setProjectOpen] = useState(false);
103
+ const [projectWidth, setProjectWidth] = useState(PROJECT_DEFAULT);
104
+ // Drafts are parent-owned data, never a replayable last insertion/upload event.
105
+ // A hero draft keeps its identity when newSession switches the rendered composer.
106
+ const composerDrafts = useRef(new Map<string, ChatDraft>());
107
+ const sessionDraftKeys = useRef(new Map<string, string>());
108
+ const draftSequence = useRef(0);
109
+ const [heroDraftKey, setHeroDraftKey] = useState("__hero__:0");
110
+ const [draftVersion, setDraftVersion] = useState(0);
111
+ void draftVersion;
112
+ const draftKey = currentPath ? sessionDraftKeys.current.get(currentPath) ?? currentPath : heroDraftKey;
113
+ const [uploadCounts, setUploadCounts] = useState<Record<string, number>>({});
114
+ const [uploadFailures, setUploadFailures] = useState<Record<string, string>>({});
115
+ const [pendingSends, setPendingSends] = useState<Record<string, boolean>>({});
116
+ const updateDraft = useCallback((key: string, update: ChatDraftUpdate) => {
117
+ const previous = composerDrafts.current.get(key) ?? EMPTY_CHAT_DRAFT;
118
+ composerDrafts.current.set(key, typeof update === "function" ? update(previous) : update);
119
+ setDraftVersion((version) => version + 1);
120
+ }, []);
121
+ const trackUpload = useCallback((key: string, delta: 1 | -1) => {
122
+ if (delta === 1) setUploadFailures((current) => ({ ...current, [key]: "" }));
123
+ setUploadCounts((current) => ({ ...current, [key]: Math.max(0, (current[key] ?? 0) + delta) }));
124
+ }, []);
125
+ const failUpload = useCallback((key: string, message: string) => {
126
+ setUploadFailures((current) => ({ ...current, [key]: message }));
127
+ }, []);
128
+ const trackSend = useCallback((key: string, pending: boolean) => {
129
+ setPendingSends((current) => ({ ...current, [key]: pending }));
130
+ }, []);
131
+ const saveSessionDraft = useCallback((update: ChatDraftUpdate) => updateDraft(draftKey, update), [draftKey, updateDraft]);
132
+ const saveHeroDraft = useCallback((update: ChatDraftUpdate) => updateDraft(heroDraftKey, update), [heroDraftKey, updateDraft]);
133
+ const [dragging, setDragging] = useState<"sidebar" | "details" | "project" | null>(null);
134
+ const [settingsOpen, setSettingsOpen] = useState(false);
135
+ const [tab, setTab] = useState<"chat" | "traj">("chat");
136
+ const [selected, setSelected] = useState<TrajEntry | null>(null);
137
+ const [gitDetailsOpen, setGitDetailsOpen] = useState(false);
138
+ const [heroCwd, setHeroCwd] = useState("");
139
+ const [heroModel, setHeroModel] = useState<{ provider: string; id: string } | null>(null);
140
+ const [heroThinking, setHeroThinking] = useState("");
141
+ const [isNarrow, setIsNarrow] = useState(false);
142
+ const [mobileSidebarOpen, setMobileSidebarOpen] = useState(false);
143
+ useEffect(() => {
144
+ setSidebarWidth(restore("piweb.sidebarW", SIDEBAR_DEFAULT));
145
+ setDetailsWidth(restore("piweb.detailsW", DETAILS_DEFAULT));
146
+ setProjectWidth(restore("piweb.projectW", PROJECT_DEFAULT));
147
+ setSidebarCollapsed(localStorage.getItem("piweb.sidebarCollapsed") === "1");
148
+ setProjectOpen(localStorage.getItem("piweb.projectOpen") === "1");
149
+ }, []);
150
+ const toggleProject = useCallback((next?: boolean) => {
151
+ setProjectOpen((cur) => {
152
+ const v = next ?? !cur;
153
+ localStorage.setItem("piweb.projectOpen", v ? "1" : "0");
154
+ return v;
155
+ });
156
+ }, []);
157
+ // Ctrl/⌘+Shift+E:切换项目栏(与 VS Code 资源管理器同键)
158
+ useEffect(() => {
159
+ const h = (e: KeyboardEvent) => {
160
+ if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key.toLowerCase() === "e") {
161
+ e.preventDefault();
162
+ toggleProject();
163
+ }
164
+ };
165
+ document.addEventListener("keydown", h);
166
+ return () => document.removeEventListener("keydown", h);
167
+ }, [toggleProject]);
168
+
169
+ useEffect(() => {
170
+ const query = window.matchMedia("(max-width: 840px)");
171
+ const sync = () => {
172
+ setIsNarrow(query.matches);
173
+ if (!query.matches) setMobileSidebarOpen(false);
174
+ };
175
+ sync();
176
+ query.addEventListener("change", sync);
177
+ return () => query.removeEventListener("change", sync);
178
+ }, []);
179
+
180
+ // 全局 Pebrel 主题初始化与系统亮暗/跨标签动态监听
181
+ useEffect(() => {
182
+ const sync = () => syncPebrelTheme();
183
+ sync();
184
+ const mq = window.matchMedia("(prefers-color-scheme: dark)");
185
+ mq.addEventListener("change", sync);
186
+ const onStorage = (e: StorageEvent) => {
187
+ // 配色或亮暗任一变化都重放(跨标签同步)
188
+ if (e.key === "piweb.pebrelTheme" || e.key === "piweb.theme") sync();
189
+ };
190
+ window.addEventListener("storage", onStorage);
191
+ return () => {
192
+ mq.removeEventListener("change", sync);
193
+ window.removeEventListener("storage", onStorage);
194
+ };
195
+ }, []);
196
+
197
+ // 切换会话时清掉轨迹页的选中态并收起详情栏
198
+ useEffect(() => {
199
+ setSelected(null);
200
+ setGitDetailsOpen(false);
201
+ }, [currentPath]);
202
+
203
+ // 已知工作区列表(给 Hero 建议);启动不预选任何工作区,
204
+ // 未选择时输入框仍可用,发送会提示先选择工作区
205
+ const knownCwds = useMemo(
206
+ () => Array.from(new Set([...addedWorkspaces, ...sessions.map((s) => s.cwd)])).filter(Boolean),
207
+ [addedWorkspaces, sessions],
208
+ );
209
+
210
+ // 模型目录派生值:数百个模型对象的映射只在目录变化时重算,
211
+ // 不能跟着每次 token 增量 / 3 秒轮询重跑(usePiWeb 的 setState 都会触发本组件渲染)
212
+ const { authByProvider, providerNames } = useMemo(() => {
213
+ const auth: Record<string, boolean> = {};
214
+ const names: Record<string, string> = {};
215
+ for (const p of models?.providers ?? []) {
216
+ auth[p.id] = p.authReady === true;
217
+ names[p.id] = p.name;
218
+ }
219
+ return { authByProvider: auth, providerNames: names };
220
+ }, [models]);
221
+ const modelChoices: ModelChoice[] = useMemo(
222
+ () =>
223
+ (models?.models ?? []).map((m: any) => ({
224
+ provider: m.provider,
225
+ id: m.id,
226
+ name: m.name,
227
+ reasoning: m.reasoning,
228
+ thinkingLevels: m.thinkingLevels,
229
+ contextWindow: m.contextWindow,
230
+ })),
231
+ [models],
232
+ );
233
+ const defaultModel = useMemo(() => modelChoices.find((m) => authByProvider[m.provider]), [modelChoices, authByProvider]);
234
+ const heroModelLevels = useMemo(
235
+ () => (heroModel ? modelChoices.find((m) => m.provider === heroModel.provider && m.id === heroModel.id) : defaultModel)?.thinkingLevels ?? ["off", "minimal", "low", "medium", "high", "xhigh", "max"],
236
+ [heroModel, modelChoices, defaultModel],
237
+ );
238
+
239
+
240
+ // ---------- 拖拽 ----------
241
+ const onDrag = useCallback(
242
+ (side: "sidebar" | "details" | "project") => (e: React.PointerEvent) => {
243
+ e.preventDefault();
244
+ setDragging(side);
245
+ const startX = e.clientX;
246
+ const startW = side === "sidebar" ? sidebarWidth : side === "project" ? projectWidth : detailsWidth;
247
+ const move = (ev: PointerEvent) => {
248
+ if (side === "sidebar") {
249
+ const w = Math.max(SIDEBAR_MIN, Math.min(SIDEBAR_MAX, startW + (ev.clientX - startX)));
250
+ setSidebarWidth(w);
251
+ } else if (side === "project") {
252
+ const w = Math.max(PROJECT_MIN, Math.min(PROJECT_MAX, startW + (ev.clientX - startX)));
253
+ setProjectWidth(w);
254
+ } else {
255
+ const w = Math.max(DETAILS_MIN, Math.min(DETAILS_MAX, startW - (ev.clientX - startX)));
256
+ setDetailsWidth(w);
257
+ }
258
+ };
259
+ const up = () => {
260
+ setDragging(null);
261
+ window.removeEventListener("pointermove", move);
262
+ window.removeEventListener("pointerup", up);
263
+ window.removeEventListener("pointercancel", up);
264
+ };
265
+ window.addEventListener("pointermove", move);
266
+ window.addEventListener("pointerup", up);
267
+ // 触摸/笔输入被系统手势打断时只触发 pointercancel,不处理会永久泄漏监听器
268
+ window.addEventListener("pointercancel", up);
269
+ },
270
+ [sidebarWidth, detailsWidth, projectWidth],
271
+ );
272
+
273
+ useEffect(() => {
274
+ if (dragging === "sidebar") persist("piweb.sidebarW", sidebarWidth);
275
+ if (dragging === "details") persist("piweb.detailsW", detailsWidth);
276
+ if (dragging === "project") persist("piweb.projectW", projectWidth);
277
+ }, [dragging, sidebarWidth, detailsWidth, projectWidth]);
278
+
279
+ const toggleSidebar = () => {
280
+ const next = !sidebarCollapsed;
281
+ setSidebarCollapsed(next);
282
+ localStorage.setItem("piweb.sidebarCollapsed", next ? "1" : "0");
283
+ };
284
+
285
+ // ---------- 会话操作 ----------
286
+ const snapshot = state.snapshot;
287
+ const trajectoryRef = useRef(snapshot?.trajectory ?? []);
288
+ useEffect(() => {
289
+ trajectoryRef.current = snapshot?.trajectory ?? [];
290
+ }, [snapshot?.trajectory]);
291
+ const openToolTrajectory = useCallback((toolCallId: string) => {
292
+ const entry = trajectoryRef.current.find((item) => item.toolCallId === toolCallId);
293
+ if (!entry) return;
294
+ setGitDetailsOpen(false);
295
+ setSelected(entry);
296
+ }, []);
297
+
298
+ // 上下文分段的数据源:系统提示词按注入资源字符数(很便宜);
299
+ // 消息字符统计交给 ContextMeter 弹窗打开时再算,避免每次 token 增量全量扫描
300
+ const contextSystemChars = useMemo(
301
+ () => (snapshot?.contextResources ?? []).reduce((sum, r) => sum + (r.content?.length ?? 0), 0),
302
+ [snapshot?.contextResources],
303
+ );
304
+ const isStreaming = snapshot?.isStreaming ?? false;
305
+
306
+ useEffect(() => {
307
+ if (!state.error) return;
308
+ const timer = setTimeout(clearError, 6000);
309
+ return () => clearTimeout(timer);
310
+ }, [state.error, clearError]);
311
+
312
+ const doRename = async (path: string, newName: string) => {
313
+ if (!newName.trim()) return;
314
+ const result = path === currentPath
315
+ ? await sendCommand({ cmd: "rename", text: newName.trim() })
316
+ : await sendCommand({ cmd: "rename", text: newName.trim() }, encodeURIComponent(b64url(path)));
317
+ if (!result?.success) {
318
+ throw new Error(result?.error || "failed to rename session");
319
+ }
320
+ patchSessionName(path, newName.trim());
321
+ if (path !== currentPath) {
322
+ // 冷会话:临时走命令路由(会按需打开,不启动 agent 的 rename 走 appendSessionInfo)
323
+ resync();
324
+ }
325
+ };
326
+
327
+ const doForkSession = useCallback(
328
+ async (path: string, _cwd: string) => {
329
+ const targetId = path === currentPath && currentId ? currentId : encodeURIComponent(b64url(path));
330
+ const r = await sendCommand({ cmd: "fork" }, targetId);
331
+ if (r?.success && r.data?.sessionPath) {
332
+ openSession(r.data.sessionPath);
333
+ resync();
334
+ }
335
+ },
336
+ [currentPath, currentId, sendCommand, openSession, resync],
337
+ );
338
+
339
+ const doArchiveSession = useCallback(
340
+ async (path: string) => {
341
+ try {
342
+ // dsh 合同:归档不关会话——当前会话被归档后保持打开且在主列表可见
343
+ // (usePiWeb 的可见性规则对 currentPath 豁免),继续可聊。
344
+ await archiveSession(path);
345
+ } catch {
346
+ // usePiWeb exposes the request failure in the shared error banner.
347
+ }
348
+ },
349
+ [archiveSession],
350
+ );
351
+ const doUnarchiveSession = useCallback(
352
+ async (path: string) => {
353
+ try {
354
+ await unarchiveSession(path);
355
+ resync();
356
+ } catch {
357
+ // usePiWeb exposes the request failure in the shared error banner.
358
+ }
359
+ },
360
+ [unarchiveSession, resync],
361
+ );
362
+
363
+ const doRenameWorkspace = useCallback(
364
+ async (cwd: string, newName: string) => {
365
+ await renameWorkspace(cwd, newName);
366
+ },
367
+ [renameWorkspace],
368
+ );
369
+
370
+ const doDeleteWorkspace = useCallback(
371
+ async (cwd: string) => {
372
+ await removeWorkspace(cwd);
373
+ if (heroCwd === cwd) {
374
+ setHeroCwd("");
375
+ }
376
+ resync();
377
+ },
378
+ [removeWorkspace, heroCwd, resync],
379
+ );
380
+
381
+ // Hero 发送:先完整应用新会话预设,再发第一条消息。
382
+ const heroSend = async (text: string, images: ImageAttachment[]) => {
383
+ // 启动不预选工作区:未选择就发送时明确提示,而不是静默落到第一个工作区
384
+ const cwd = heroCwd.trim();
385
+ if (!cwd) {
386
+ setError(t.pickWorkspaceFirst);
387
+ return { success: false };
388
+ }
389
+ // 用户没手动选过模型时也要把界面显示的默认模型显式下发,
390
+ // 否则后端不 setModel、SDK 自选的默认与界面显示不一致。
391
+ const effective = heroModel ?? (defaultModel ? { provider: defaultModel.provider, id: defaultModel.id } : null);
392
+ const p = await newSession(cwd, {
393
+ provider: effective?.provider,
394
+ modelId: effective?.id,
395
+ thinking: heroThinking || undefined,
396
+ });
397
+ if (!p) return { success: false };
398
+ // Bind before the new-session render. In-flight ChatInput callbacks still own
399
+ // this same key; a failed acceptance keeps the original text and attachments.
400
+ sessionDraftKeys.current.set(p, heroDraftKey);
401
+ setHeroDraftKey(`__hero__:${++draftSequence.current}`);
402
+ return sendCommand({ cmd: "prompt", text, images }, encodeURIComponent(b64url(p)));
403
+ };
404
+
405
+ const sendPrompt = (text: string, images: ImageAttachment[]) => sendCommand({ cmd: "prompt", text, images });
406
+
407
+ // 稳定引用:ChatWindow 行级 memo 依赖它,内联箭头函数会让 memo 全部失效
408
+ const handleFork = useCallback(
409
+ (entryId: string) =>
410
+ sendCommand({ cmd: "fork", entryId }).then((result) => {
411
+ if (result.success && result.data?.sessionPath) {
412
+ openSession(result.data.sessionPath);
413
+ resync();
414
+ }
415
+ return result;
416
+ }),
417
+ [sendCommand, openSession, resync],
418
+ );
419
+
420
+ // 斜杠命令:Web 内置 + pi 的技能 / 提示模板 / 扩展命令(后三类原样交给 SDK 展开或执行)
421
+ const slashCommands = useMemo(() => {
422
+ const list: { name: string; desc: string; kind: "builtin" | "skill" | "template" | "extension"; argumentHint?: string }[] = [
423
+ { name: "compact", desc: t.cmdCompact, kind: "builtin" },
424
+ { name: "export", desc: t.cmdExport, kind: "builtin" },
425
+ { name: "model", desc: t.cmdModel, kind: "builtin" },
426
+ { name: "new", desc: t.cmdNew, kind: "builtin" },
427
+ { name: "fork", desc: t.cmdFork, kind: "builtin" },
428
+ { name: "reload", desc: t.cmdReload, kind: "builtin" },
429
+ ...(snapshot?.promptTemplates ?? []).map((p) => ({ name: p.name, desc: p.description, kind: "template" as const, argumentHint: p.argumentHint })),
430
+ ...(snapshot?.extensionCommands ?? []).map((c) => ({ name: c.name, desc: c.description || c.source, kind: "extension" as const })),
431
+ ...(snapshot?.skills ?? []).map((s) => ({ name: `skill:${s.name}`, desc: s.description, kind: "skill" as const })),
432
+ ];
433
+ return list.sort((a, b) => a.name.localeCompare(b.name));
434
+ }, [snapshot, t]);
435
+
436
+ const runSlashCommand = useCallback(
437
+ (name: string, args: string) => {
438
+ if (name === "compact") void sendCommand({ cmd: "compact", instructions: args || undefined });
439
+ else if (name === "export" && currentId) window.open(`/api/sessions/${currentId}/export?format=jsonl`, "_blank");
440
+ else if (name === "new") {
441
+ setTab("chat");
442
+ closeSession();
443
+ } else if (name === "fork" && currentId) {
444
+ void sendCommand({ cmd: "fork" }).then((r) => {
445
+ if (r.success && r.data?.sessionPath) openSession(r.data.sessionPath);
446
+ });
447
+ } else if (name === "reload") void sendCommand({ cmd: "reload" });
448
+ else setError(t.cmdUnknown.replace("{name}", name));
449
+ },
450
+ [sendCommand, currentId, closeSession, openSession, setError, t],
451
+ );
452
+
453
+ const projectTrust = snapshot?.projectTrust;
454
+ const setProjectTrust = useCallback(
455
+ async (decision: boolean | null) => {
456
+ const cwd = snapshot?.cwd;
457
+ if (!cwd) return;
458
+ try {
459
+ const r = await fetch("/api/security", { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ projectTrust: { cwd, decision } }) });
460
+ const j = await r.json();
461
+ if (!j.success) throw new Error(j.error || "failed");
462
+ } catch (e) {
463
+ setError(e instanceof Error ? e.message : "failed");
464
+ }
465
+ },
466
+ [snapshot?.cwd, setError],
467
+ );
468
+
469
+ // 当前会话名 / 工作区标题
470
+ const currentSession = sessions.find((s) => s.path === currentPath);
471
+ const firstUserMsgText = (
472
+ state.messages
473
+ .find((m) => m.role === "user")
474
+ ?.content?.find((c: any) => c.type === "text" && c.text?.trim()) as any
475
+ )?.text?.trim();
476
+ const title =
477
+ snapshot?.name ||
478
+ currentSession?.name ||
479
+ currentSession?.firstMessage ||
480
+ firstUserMsgText ||
481
+ currentPath?.split(/[\\/]/).pop() ||
482
+ "pi";
483
+
484
+ // 项目栏/文件查看器的工作区:当前会话的工作区优先,快照未到时回落到会话列表里的 cwd
485
+ const panelCwd = snapshot?.cwd || currentSession?.cwd || heroCwd || knownCwds[0] || "";
486
+
487
+ // Git 面板自动刷新:pi 每完成一个会改动文件的工具,或一轮结束时,静默重拉
488
+ const mutatingDone = useMemo(
489
+ () => Object.values(state.tools).filter((tool) => tool.state === "done" && ["edit", "write", "bash", "powershell", "pwsh"].includes(tool.name.toLowerCase())).length,
490
+ [state.tools],
491
+ );
492
+ const [panelRefreshKey, setPanelRefreshKey] = useState(0);
493
+ const prevMutatingRef = useRef(mutatingDone);
494
+ const prevStreamingRef = useRef(isStreaming);
495
+ useEffect(() => {
496
+ if (prevMutatingRef.current !== mutatingDone) {
497
+ prevMutatingRef.current = mutatingDone;
498
+ setPanelRefreshKey((k) => k + 1);
499
+ }
500
+ }, [mutatingDone]);
501
+ useEffect(() => {
502
+ if (prevStreamingRef.current && !isStreaming) setPanelRefreshKey((k) => k + 1);
503
+ prevStreamingRef.current = isStreaming;
504
+ }, [isStreaming]);
505
+
506
+ const insertIntoComposer = useCallback((text: string) => {
507
+ const textarea = document.querySelector<HTMLTextAreaElement>('[data-testid="composer"] textarea');
508
+ const cursor = textarea?.selectionStart;
509
+ updateDraft(draftKey, (previous) => {
510
+ const position = Math.min(cursor ?? previous.text.length, previous.text.length);
511
+ const before = previous.text.slice(0, position);
512
+ const after = previous.text.slice(position);
513
+ return { ...previous, text: `${before}${before && !/\s$/.test(before) ? " " : ""}${text}${after}` };
514
+ });
515
+ requestAnimationFrame(() => textarea?.focus());
516
+ }, [draftKey, updateDraft]);
517
+ const openInEditor = useCallback(
518
+ async (filePath: string) => {
519
+ try {
520
+ const r = await fetch("/api/files", {
521
+ method: "POST",
522
+ headers: { "Content-Type": "application/json" },
523
+ body: JSON.stringify({ action: "open", cwd: panelCwd, path: filePath }),
524
+ });
525
+ const j = await r.json();
526
+ if (!j.success) throw new Error(j.error || "failed to open file");
527
+ } catch (e) {
528
+ setError(e instanceof Error ? e.message : "failed to open file");
529
+ }
530
+ },
531
+ [panelCwd, setError],
532
+ );
533
+ // ---------- 项目生长 ----------
534
+ const viewer = useFileViewer();
535
+ const resetViewer = viewer.reset;
536
+ useEffect(() => {
537
+ resetViewer();
538
+ }, [panelCwd, resetViewer]);
539
+ const growthTurnStarts = useMemo(
540
+ () => {
541
+ const persisted = state.snapshot?.userTurns ?? [];
542
+ const ids = new Set(persisted.map((turn) => turn.id));
543
+ const lastTs = persisted[persisted.length - 1]?.ts ?? -Infinity;
544
+ const live = state.messages
545
+ .filter((message) => message.role === "user" && (!message.id || !ids.has(message.id)) && (message.timestamp ?? Date.now()) >= lastTs - 1000)
546
+ .map((message) => message.timestamp ?? Date.now());
547
+ return [...persisted.map((turn) => turn.ts), ...live];
548
+ },
549
+ [state.snapshot?.userTurns, state.messages],
550
+ );
551
+ const growth = useGrowth({
552
+ cwd: panelCwd,
553
+ sessionPath: currentPath,
554
+ liveSteps: state.growth.steps,
555
+ pending: state.growth.pending,
556
+ runtimeError: state.growth.error,
557
+ active: projectOpen || viewer.state.open,
558
+ connected: state.connected,
559
+ turnStarts: growthTurnStarts,
560
+ });
561
+ const openFileNode = useCallback((node: TreeNode) => viewer.open(node.path, { from: node.from, lazy: node.lazy }), [viewer]);
562
+
563
+ useEffect(() => {
564
+ document.title = currentId && title && title !== "pi" ? `${title} · pi` : "pi";
565
+ }, [currentId, title]);
566
+
567
+ // 三栏网格
568
+ const gridCols = isNarrow ? "minmax(0,1fr)" : `${sidebarCollapsed ? SIDEBAR_COLLAPSED : sidebarWidth}px ${projectOpen ? `${projectWidth}px` : "0px"} minmax(0,1fr) ${
569
+ selected || gitDetailsOpen ? `${detailsWidth}px` : "0px"
570
+ }`;
571
+ const projectColumn = projectOpen && (
572
+ <div
573
+ className="min-h-0 overflow-hidden"
574
+ style={isNarrow ? {
575
+ position: "fixed",
576
+ inset: "0 auto 0 0",
577
+ width: "min(88vw, 420px)",
578
+ zIndex: 88,
579
+ boxShadow: "var(--dsw-elevation-prominent)",
580
+ } : undefined}
581
+ >
582
+ <ProjectPanel
583
+ growth={growth}
584
+ workspaceName={panelCwd ? getWorkspaceName(panelCwd) : ""}
585
+ cwd={panelCwd}
586
+ hasSession={Boolean(currentPath)}
587
+ onOpenFile={openFileNode}
588
+ onReference={insertIntoComposer}
589
+ onOpenEditor={openInEditor}
590
+ gitRefreshKey={panelRefreshKey}
591
+ onAskCommit={() => insertIntoComposer(t.gitAskCommitPrompt)}
592
+ onOpenGit={() => { setSelected(null); setGitDetailsOpen(true); }}
593
+ onClose={() => toggleProject(false)}
594
+ onError={setError}
595
+ />
596
+ </div>
597
+ );
598
+
599
+ return (
600
+ <div
601
+ className="grid h-screen w-screen overflow-hidden"
602
+ style={{
603
+ gridTemplateColumns: gridCols,
604
+ transition: dragging ? "none" : "grid-template-columns var(--ds-duration-slow) var(--ds-ease-in-out)",
605
+ background: "var(--dsw-bg-base)",
606
+ }}
607
+ >
608
+ {/* 侧栏 */}
609
+ <div
610
+ className="min-h-0 overflow-hidden"
611
+ style={isNarrow ? {
612
+ position: "fixed",
613
+ inset: "0 auto 0 0",
614
+ width: "min(86vw, 340px)",
615
+ zIndex: 90,
616
+ background: "var(--dsw-sidebar-fill)",
617
+ transform: mobileSidebarOpen ? "translateX(0)" : "translateX(-105%)",
618
+ transition: "transform var(--ds-duration-normal) var(--ds-ease-in-out)",
619
+ boxShadow: mobileSidebarOpen ? "var(--dsw-elevation-prominent)" : "none",
620
+ } : { background: "var(--dsw-sidebar-fill)" }}
621
+ >
622
+ <SessionSidebar
623
+ sessions={sessions}
624
+ sessionListError={sessionListError}
625
+ onRetrySessionList={retrySessionList}
626
+ archivedSessions={archivedSessions}
627
+ archivedPaths={archivedSessionPaths}
628
+ addedWorkspaces={addedWorkspaces}
629
+ removedWorkspaces={removedWorkspaces}
630
+ currentPath={currentPath}
631
+ groupBy={groupBy}
632
+ orderBy={orderBy}
633
+ setGroupBy={setGroupBy}
634
+ setOrderBy={setOrderBy}
635
+ collapsed={isNarrow ? false : sidebarCollapsed}
636
+ onToggleCollapse={isNarrow ? () => setMobileSidebarOpen(false) : toggleSidebar}
637
+ onOpen={(path) => {
638
+ openSession(path);
639
+ setMobileSidebarOpen(false);
640
+ }}
641
+ onNew={() => {
642
+ // 对齐 dsh startSession:新会话默认落在当前会话的工作区(无则取最近工作区)
643
+ setTab("chat");
644
+ const cur = sessions.find((s) => s.path === currentPath)?.cwd;
645
+ setHeroCwd(cur || heroCwd || knownCwds[0] || "");
646
+ closeSession();
647
+ }}
648
+ onNewInWorkspace={(cwd) => {
649
+ // dsh 惰性新建:只预选工作区进草稿态,发送第一条消息才真正创建会话
650
+ setTab("chat");
651
+ setHeroCwd(cwd);
652
+ closeSession();
653
+ }}
654
+ onRename={doRename}
655
+ onFork={doForkSession}
656
+ onArchive={doArchiveSession}
657
+ onUnarchive={doUnarchiveSession}
658
+ onExport={(path) => window.open(`/api/sessions/${encodeURIComponent(b64url(path))}/export?format=jsonl`, "_blank")}
659
+ getWorkspaceName={getWorkspaceName}
660
+ onRenameWorkspace={doRenameWorkspace}
661
+ onDeleteWorkspace={doDeleteWorkspace}
662
+ onOpenSettings={() => {
663
+ setSettingsOpen(true);
664
+ setMobileSidebarOpen(false);
665
+ }}
666
+ onAddWorkspace={() => void addWorkspaceByPicker()}
667
+ draftCwd={!currentId ? heroCwd || null : null}
668
+ />
669
+ </div>
670
+
671
+ {/* 四列网格中始终保留项目列,否则关闭项目栏时会话区会落进 0px 列。 */}
672
+ {!isNarrow && (projectColumn || <div aria-hidden="true" />)}
673
+
674
+ {/* 会话区 */}
675
+ <div className="pi-main flex min-h-0 min-w-0 flex-col">
676
+ {!currentId ? (
677
+ <div className="flex min-h-0 flex-1 flex-col">
678
+ <Hero
679
+ draft={composerDrafts.current.get(heroDraftKey) ?? EMPTY_CHAT_DRAFT}
680
+ onDraftChange={saveHeroDraft}
681
+ onUploadError={(message) => failUpload(heroDraftKey, message)}
682
+ onUploadProgress={(delta) => trackUpload(heroDraftKey, delta)}
683
+ uploadFailure={uploadFailures[heroDraftKey]}
684
+ pendingUploadCount={uploadCounts[heroDraftKey] ?? 0}
685
+ pendingSend={pendingSends[heroDraftKey] ?? false}
686
+ onSendPendingChange={(pending) => trackSend(heroDraftKey, pending)}
687
+ commands={slashCommands}
688
+ onCommand={runSlashCommand}
689
+ cwd={heroCwd}
690
+ setCwd={setHeroCwd}
691
+ knownCwds={knownCwds}
692
+ getWorkspaceName={getWorkspaceName}
693
+ onSend={heroSend}
694
+ models={modelChoices}
695
+ providerNames={providerNames}
696
+ authByProvider={authByProvider}
697
+ addWorkspaceByPicker={addWorkspaceByPicker}
698
+ heroModel={heroModel}
699
+ onSelectHeroModel={(provider, id) => {
700
+ setHeroModel({ provider, id });
701
+ const levels = modelChoices.find((model) => model.provider === provider && model.id === id)?.thinkingLevels ?? [];
702
+ if (heroThinking && !levels.includes(heroThinking)) setHeroThinking("");
703
+ }}
704
+ defaultModel={defaultModel}
705
+ heroModelLevels={heroModelLevels}
706
+ heroThinking={heroThinking}
707
+ onSelectHeroThinking={setHeroThinking}
708
+ />
709
+ {/* 草稿阶段的错误行内显示(不再弹右下角) */}
710
+ {state.error && (
711
+ <div className="px-4 pb-3">
712
+ <button
713
+ className="mx-auto block w-full max-w-md rounded-xl px-3 py-2 text-left"
714
+ style={{ fontSize: 12.5, background: "var(--dsw-danger)", color: "white" }}
715
+ onClick={clearError}
716
+ role="alert"
717
+ >
718
+ {state.error}
719
+ </button>
720
+ </div>
721
+ )}
722
+ </div>
723
+ ) : (
724
+ <>
725
+ {/* 头部:标题行 + 页签行(dsh 两行式) */}
726
+ <div className="hairline-b px-5 pb-0 pt-3">
727
+ <div className="flex items-center gap-3">
728
+ <span className="min-w-0 flex-1 truncate" style={{ fontSize: 14.5, fontWeight: 600 }}>
729
+ {title}
730
+ </span>
731
+ {/* 项目生长入口;轨迹详情由对话内工具行点击唤起 */}
732
+ <button
733
+ type="button"
734
+ className="icon-btn"
735
+ style={{ width: 30, height: 30, background: projectOpen ? "var(--dsw-active)" : undefined }}
736
+ title={`${t.projectPanel} (Ctrl/⌘+Shift+E)`}
737
+ aria-label={t.projectPanel}
738
+ data-testid="project-toggle"
739
+ onClick={() => toggleProject()}
740
+ >
741
+ <IconFolderOpenOutline16 size={15} />
742
+ </button>
743
+ </div>
744
+ {projectTrust?.required && !projectTrust.trusted && (
745
+ <div className="mt-2 flex flex-wrap items-center gap-2 rounded-xl px-3 py-2" style={{ fontSize: 12.5, background: "var(--dsw-hover)", border: "0.5px solid var(--dsw-border-l2)" }} role="status">
746
+ <span style={{ color: "var(--dsw-warn)", fontWeight: 600 }}>⚠</span>
747
+ <span className="min-w-0 flex-1">{projectTrust.source === "default-never" || projectTrust.source === "remembered" ? t.projectTrustBannerNever : t.projectTrustBanner}</span>
748
+ <button className="btn-primary-white" style={{ height: 26, padding: "0 10px", fontSize: 12 }} onClick={() => void setProjectTrust(true)}>{t.projectTrustAllow}</button>
749
+ {projectTrust.source === "undecided" && (
750
+ <button className="btn-outline" style={{ height: 26, padding: "0 10px", fontSize: 12 }} onClick={() => void setProjectTrust(false)}>{t.projectTrustDeny}</button>
751
+ )}
752
+ </div>
753
+ )}
754
+ <div className="mt-1.5 flex items-center gap-5">
755
+ <button className="tab-underline" data-active={tab === "chat"} onClick={() => setTab("chat")}>
756
+ {t.tabChat}
757
+ </button>
758
+ <button
759
+ className="tab-underline"
760
+ data-active={tab === "traj"}
761
+ onClick={() => {
762
+ setTab("traj");
763
+ void sendCommand({ cmd: "prepare" });
764
+ }}
765
+ >
766
+ {t.tabTrajectory}
767
+ </button>
768
+ </div>
769
+ </div>
770
+
771
+ {/* 内容 */}
772
+ {tab === "chat" ? (
773
+ !snapshot ? (
774
+ // 切换会话时快照未到:居中加载指示,避免空白/占位符闪现
775
+ <div className="flex min-h-0 flex-1 items-center justify-center">
776
+ <span
777
+ className="piweb-spin"
778
+ style={{
779
+ width: 18,
780
+ height: 18,
781
+ borderRadius: "50%",
782
+ border: "2px solid var(--dsw-border-l3)",
783
+ borderTopColor: "var(--dsw-accent)",
784
+ display: "inline-block",
785
+ }}
786
+ aria-label="loading"
787
+ />
788
+ </div>
789
+ ) : (
790
+ <div className="flex min-h-0 flex-1 flex-col justify-end">
791
+ <ChatWindow
792
+ key={currentId ?? "none"}
793
+ messages={state.messages}
794
+ tools={state.tools}
795
+ contextFiles={snapshot?.contextResources ?? snapshot?.contextFiles ?? []}
796
+ isStreaming={isStreaming}
797
+ error={state.error}
798
+ connected={state.connected}
799
+ onClearError={clearError}
800
+ retryNotice={state.retryNotice}
801
+ compaction={state.compaction}
802
+ onClearCompaction={clearCompaction}
803
+ workingMessage={state.workingMessage}
804
+ stats={snapshot?.stats ?? null}
805
+ trajectory={snapshot?.trajectory ?? []}
806
+ cwd={panelCwd}
807
+ onOpenTrajectory={openToolTrajectory}
808
+ onOpenFile={openInEditor}
809
+ onFork={handleFork}
810
+ />
811
+ <div className="px-4 pb-3 pt-2">
812
+ <div className="mx-auto w-full" style={{ maxWidth: "var(--dsh-composer-card-max-width)" }}>
813
+ {/* 运行状态指示由 ChatWindow 内的 WorkingIndicator 承担(含工具/输出 token 信息) */}
814
+ <ChatInput
815
+ key={draftKey}
816
+ draft={composerDrafts.current.get(draftKey) ?? EMPTY_CHAT_DRAFT}
817
+ onDraftChange={saveSessionDraft}
818
+ onUploadError={(message) => failUpload(draftKey, message)}
819
+ onUploadProgress={(delta) => trackUpload(draftKey, delta)}
820
+ uploadFailure={uploadFailures[draftKey]}
821
+ pendingUploadCount={uploadCounts[draftKey] ?? 0}
822
+ pendingSend={pendingSends[draftKey] ?? false}
823
+ onSendPendingChange={(pending) => trackSend(draftKey, pending)}
824
+ isStreaming={isStreaming}
825
+ contextPercent={snapshot?.contextUsage?.percent ?? null}
826
+ contextTokens={snapshot?.contextUsage?.tokens ?? null}
827
+ contextWindow={snapshot?.contextUsage?.contextWindow ?? null}
828
+ contextSource={{ systemChars: contextSystemChars, messages: state.messages }}
829
+ contextVisible={(snapshot?.messages?.length ?? 0) > 0}
830
+ model={snapshot?.model}
831
+ thinkingLevel={snapshot?.thinkingLevel}
832
+ thinkingLevels={snapshot?.thinkingLevels ?? ["off", "minimal", "low", "medium", "high", "xhigh", "max"]}
833
+ models={modelChoices}
834
+ providerNames={providerNames}
835
+ authByProvider={authByProvider}
836
+ queue={snapshot?.queue ?? { steering: [], followUp: [] }}
837
+ commands={slashCommands}
838
+ onCommand={runSlashCommand}
839
+ onSend={sendPrompt}
840
+ onSteer={(text, images) => sendCommand({ cmd: "prompt", text, images, behavior: "steer" })}
841
+ onFollowUp={(text, images) => sendCommand({ cmd: "prompt", text, images, behavior: "followUp" })}
842
+ onAbort={() => sendCommand({ cmd: "abort" })}
843
+ onSelectModel={(provider, id) => void sendCommand({ cmd: "setModel", provider, modelId: id })}
844
+ onSelectLevel={(level) =>
845
+ void sendCommand({ cmd: "setThinkingLevel", level }).then((r) => {
846
+ // 后端按 pi 规则就近钳制;被调整时明确告知,不再“选了没反应”
847
+ if (r?.success && r.data?.clamped) setError(t.thinkingClamped.replace("{requested}", level).replace("{level}", String(r.data.thinkingLevel)));
848
+ })
849
+ }
850
+ onClearQueue={() => sendCommand({ cmd: "clearQueue" })}
851
+ />
852
+ <SessionStatsBar stats={snapshot?.stats ?? null} />
853
+ {Object.keys(state.extensionStatuses).length > 0 && (
854
+ <div className="mx-auto mt-0.5 flex w-full flex-wrap justify-center gap-x-3 px-4" style={{ fontSize: 12, color: "var(--dsw-label-caption)" }} title={t.extensionStatus}>
855
+ {Object.entries(state.extensionStatuses).map(([k, v]) => <span key={k}>{v}</span>)}
856
+ </div>
857
+ )}
858
+ </div>
859
+ </div>
860
+ </div>
861
+ )
862
+ ) : (
863
+ <div className="min-h-0 flex-1">
864
+ <TrajectoryView
865
+ entries={snapshot?.trajectory ?? []}
866
+ selected={selected}
867
+ onSelect={(entry) => {
868
+ setSelected(entry);
869
+ setGitDetailsOpen(false);
870
+ }}
871
+ />
872
+ </div>
873
+ )}
874
+ </>
875
+ )}
876
+ </div>
877
+
878
+ {/* 轨迹或 Git 详情栏 */}
879
+ {(selected || gitDetailsOpen) && (
880
+ <div
881
+ className="flex min-h-0 flex-col overflow-hidden"
882
+ style={isNarrow ? {
883
+ position: "fixed",
884
+ inset: "0 0 0 auto",
885
+ width: "min(92vw, 640px)",
886
+ zIndex: 90,
887
+ background: "var(--dsw-sidebar-fill)",
888
+ boxShadow: "var(--dsw-elevation-prominent)",
889
+ } : { background: "var(--dsw-sidebar-fill)", borderLeft: "0.5px solid var(--dsw-border-l2)" }}
890
+ >
891
+ <div className="min-h-0 flex-1">
892
+ {selected ? (
893
+ <TrajInspector entry={selected} onClose={() => setSelected(null)} />
894
+ ) : (
895
+ <GitPanel cwd={panelCwd} refreshKey={panelRefreshKey} onClose={() => setGitDetailsOpen(false)} onAskCommit={() => insertIntoComposer(t.gitAskCommitPrompt)} onOpenFile={openInEditor} />
896
+ )}
897
+ </div>
898
+ </div>
899
+ )}
900
+
901
+ {/* 拖拽手柄 */}
902
+ {!isNarrow && !sidebarCollapsed && (
903
+ <div
904
+ className="fixed top-0 h-full w-2 cursor-col-resize"
905
+ style={{ left: sidebarWidth - 4, zIndex: 40 }}
906
+ onPointerDown={onDrag("sidebar")}
907
+ />
908
+ )}
909
+ {!isNarrow && (selected || gitDetailsOpen) && (
910
+ <div
911
+ className="fixed top-0 h-full w-2 cursor-col-resize"
912
+ style={{ left: `calc(100vw - ${detailsWidth}px - 4px)`, zIndex: 40 }}
913
+ onPointerDown={onDrag("details")}
914
+ />
915
+ )}
916
+ {!isNarrow && projectOpen && (
917
+ <div
918
+ className="fixed top-0 h-full w-2 cursor-col-resize"
919
+ style={{ left: (sidebarCollapsed ? SIDEBAR_COLLAPSED : sidebarWidth) + projectWidth - 4, zIndex: 40 }}
920
+ onPointerDown={onDrag("project")}
921
+ />
922
+ )}
923
+ {isNarrow && projectOpen && (
924
+ <>
925
+ <button className="fixed inset-0 z-[85]" style={{ background: "var(--dsw-mask)" }} onClick={() => toggleProject(false)} aria-label={t.close} />
926
+ {projectColumn}
927
+ </>
928
+ )}
929
+ {viewer.state.open && (
930
+ <FileViewer
931
+ state={viewer.state}
932
+ growth={growth}
933
+ cwd={panelCwd}
934
+ onClose={viewer.close}
935
+ onSelectTab={viewer.select}
936
+ onCloseTab={viewer.closeTab}
937
+ onOpen={viewer.open}
938
+ onReference={insertIntoComposer}
939
+ onOpenEditor={openInEditor}
940
+ />
941
+ )}
942
+
943
+ <ExtensionDialogHost dialog={state.extensionDialogs[0] ?? null} onAnswer={(id, response) => void answerExtensionDialog(id, response)} />
944
+ <ExtensionNotices notices={state.extensionNotices} onDismiss={dismissExtensionNotice} />
945
+ <SettingsPanel
946
+ open={settingsOpen}
947
+ onClose={() => {
948
+ setSettingsOpen(false);
949
+ // 模型配置可能在设置里被改动(API key / OAuth / 自定义 provider):
950
+ // 关闭时刷新全局模型目录,否则输入卡/新会话页的模型菜单停留在旧目录。
951
+ void refreshModels();
952
+ }}
953
+ onOpenFileContent={(p, content) => viewer.openStatic(p, content)}
954
+ cwd={snapshot?.cwd || heroCwd || knownCwds[0] || ""}
955
+ toolPreset={state.toolPreset}
956
+ onToolPresetChange={setToolPreset}
957
+ tools={snapshot?.tools ?? null}
958
+ onSetTools={(names) => {
959
+ void sendCommand({ cmd: "setActiveTools", names });
960
+ }}
961
+ />
962
+ {isNarrow && (
963
+ <button
964
+ className="pi-mobile-menu icon-btn fixed left-3 top-3 z-[70]"
965
+ style={{ width: 34, height: 34, background: "var(--dsw-bg-elevated)", boxShadow: "var(--dsw-elevation-soft)" }}
966
+ onClick={() => setMobileSidebarOpen(true)}
967
+ aria-label={t.workspaces}
968
+ >
969
+ <IconPanelLeftOutline16 size={17} />
970
+ </button>
971
+ )}
972
+ {isNarrow && mobileSidebarOpen && (
973
+ <button
974
+ className="fixed inset-0 z-[80]"
975
+ style={{ background: "var(--dsw-mask)" }}
976
+ onClick={() => setMobileSidebarOpen(false)}
977
+ aria-label={t.close}
978
+ />
979
+ )}
980
+ </div>
981
+ );
982
+ }
983
+
984
+ function b64url(path: string): string {
985
+ const bytes = new TextEncoder().encode(path);
986
+ let bin = "";
987
+ for (const b of bytes) bin += String.fromCharCode(b);
988
+ return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
989
+ }
990
+
991
+ function basename(p: string): string {
992
+ const norm = p.replace(/\\/g, "/");
993
+ return norm.split("/").filter(Boolean).pop() ?? norm;
994
+ }
995
+
996
+ function Hero({
997
+ draft,
998
+ onDraftChange,
999
+ onUploadError,
1000
+ onUploadProgress,
1001
+ uploadFailure,
1002
+ pendingUploadCount,
1003
+ pendingSend,
1004
+ onSendPendingChange,
1005
+ commands,
1006
+ onCommand,
1007
+ cwd,
1008
+ setCwd,
1009
+ knownCwds,
1010
+ getWorkspaceName,
1011
+ onSend,
1012
+ models,
1013
+ providerNames,
1014
+ authByProvider,
1015
+ addWorkspaceByPicker,
1016
+ heroModel,
1017
+ onSelectHeroModel,
1018
+ defaultModel,
1019
+ heroModelLevels,
1020
+ heroThinking,
1021
+ onSelectHeroThinking,
1022
+ }: {
1023
+ draft: ChatDraft;
1024
+ onDraftChange: (update: ChatDraftUpdate) => void;
1025
+ onUploadError: (message: string) => void;
1026
+ onUploadProgress: (delta: 1 | -1) => void;
1027
+ uploadFailure?: string;
1028
+ pendingUploadCount: number;
1029
+ pendingSend: boolean;
1030
+ onSendPendingChange: (pending: boolean) => void;
1031
+ commands: Array<{ name: string; desc: string; kind: "builtin" | "skill" | "template" | "extension"; argumentHint?: string }>;
1032
+ onCommand: (name: string, args: string) => void;
1033
+ cwd: string;
1034
+ setCwd: (v: string) => void;
1035
+ knownCwds: string[];
1036
+ getWorkspaceName?: (cwd: string) => string;
1037
+ onSend: (text: string, images: ImageAttachment[]) => Promise<{ success: boolean }>;
1038
+ models: ModelChoice[];
1039
+ providerNames: Record<string, string>;
1040
+ authByProvider: Record<string, boolean>;
1041
+ addWorkspaceByPicker: () => Promise<string | null>;
1042
+ heroModel: { provider: string; id: string } | null;
1043
+ onSelectHeroModel: (provider: string, id: string) => void;
1044
+ defaultModel?: ModelChoice;
1045
+ heroModelLevels: string[];
1046
+ heroThinking: string;
1047
+ onSelectHeroThinking: (level: string) => void;
1048
+ }) {
1049
+ const { t } = useI18n();
1050
+ const [wsMenu, setWsMenu] = useState(false);
1051
+ const menuRef = useRef<HTMLDivElement>(null);
1052
+
1053
+ useEffect(() => {
1054
+ if (!wsMenu) return;
1055
+ const h = (e: MouseEvent) => {
1056
+ if (!menuRef.current?.contains(e.target as Node)) {
1057
+ setWsMenu(false);
1058
+ }
1059
+ };
1060
+ document.addEventListener("mousedown", h);
1061
+ return () => document.removeEventListener("mousedown", h);
1062
+ }, [wsMenu]);
1063
+
1064
+ const pickWorkspace = async () => {
1065
+ const p = await addWorkspaceByPicker();
1066
+ if (p) {
1067
+ setCwd(p);
1068
+ setWsMenu(false);
1069
+ }
1070
+ };
1071
+
1072
+ const currentLabel = cwd ? (getWorkspaceName ? getWorkspaceName(cwd) : basename(cwd)) : t.startWith;
1073
+
1074
+ return (
1075
+ <div className="flex h-full min-h-0 flex-col items-center justify-center px-6">
1076
+ {/* 品牌行:仅 π 标 */}
1077
+ <div className="mb-5 flex items-center justify-center gap-3">
1078
+ <PiMark size={40} />
1079
+ </div>
1080
+
1081
+ {/* 工作区芯片行 + 输入卡 同宽容器(芯片行与卡片左对齐) */}
1082
+ <div className="w-full flex flex-col items-stretch mx-auto" style={{ maxWidth: "var(--dsh-composer-card-max-width)" }}>
1083
+ <div ref={menuRef} className="mb-3 flex items-center gap-3" style={{ paddingLeft: 7 }}>
1084
+ <div className="relative">
1085
+ <button className="hero-chip" data-open={wsMenu} onClick={() => setWsMenu((v) => !v)}>
1086
+ <IconFolderClose16 className="hero-chip-icon" size={16} />
1087
+ <span className="max-w-[220px] truncate" suppressHydrationWarning>{currentLabel}</span>
1088
+ <span className="chevron">
1089
+ <IconChevronDown14 size={14} />
1090
+ </span>
1091
+ </button>
1092
+ {wsMenu && (
1093
+ <div className="popover absolute bottom-9 left-0 z-50 w-56 py-1">
1094
+ {knownCwds.map((c) => {
1095
+ const itemLabel = getWorkspaceName ? getWorkspaceName(c) : basename(c);
1096
+ return (
1097
+ <button
1098
+ key={c}
1099
+ className="flex w-full items-center gap-2.5 px-3.5 py-2 text-left transition-colors"
1100
+ style={{
1101
+ fontSize: 13,
1102
+ background: cwd === c ? "var(--dsw-accent-soft)" : "transparent",
1103
+ color: cwd === c ? "var(--dsw-accent)" : "inherit",
1104
+ }}
1105
+ onMouseEnter={(e) => {
1106
+ if (cwd !== c) e.currentTarget.style.background = "var(--dsw-hover)";
1107
+ }}
1108
+ onMouseLeave={(e) => {
1109
+ if (cwd !== c) e.currentTarget.style.background = "transparent";
1110
+ }}
1111
+ onClick={() => {
1112
+ setCwd(c);
1113
+ setWsMenu(false);
1114
+ }}
1115
+ >
1116
+ <IconFolderClose16 size={14} style={{ flex: "none", color: cwd === c ? "var(--dsw-accent)" : "var(--dsw-label-tertiary)" }} />
1117
+ <span className="min-w-0 flex-1 truncate">{itemLabel}</span>
1118
+ {cwd === c && <IconCheckOutline14 size={13} style={{ flex: "none" }} />}
1119
+ </button>
1120
+ );
1121
+ })}
1122
+ <div className="my-1" style={{ borderTop: "0.5px solid var(--dsw-border-l2)" }} />
1123
+ <button
1124
+ className="flex w-full items-center gap-2.5 px-3.5 py-2 text-left transition-colors"
1125
+ style={{ fontSize: 13 }}
1126
+ onMouseEnter={(e) => (e.currentTarget.style.background = "var(--dsw-hover)")}
1127
+ onMouseLeave={(e) => (e.currentTarget.style.background = "transparent")}
1128
+ onClick={pickWorkspace}
1129
+ >
1130
+ <IconProjectAddOutline16 size={14} style={{ flex: "none", color: "var(--dsw-label-tertiary)" }} />
1131
+ {t.addWorkspace}
1132
+ </button>
1133
+ </div>
1134
+ )}
1135
+ </div>
1136
+ </div>
1137
+
1138
+ {/* 输入卡 */}
1139
+ <ChatInput
1140
+ draft={draft}
1141
+ onDraftChange={onDraftChange}
1142
+ onUploadError={onUploadError}
1143
+ onUploadProgress={onUploadProgress}
1144
+ uploadFailure={uploadFailure}
1145
+ pendingUploadCount={pendingUploadCount}
1146
+ pendingSend={pendingSend}
1147
+ onSendPendingChange={onSendPendingChange}
1148
+ commands={commands}
1149
+ onCommand={onCommand}
1150
+ isStreaming={false}
1151
+ contextPercent={null}
1152
+ contextTokens={null}
1153
+ contextWindow={null}
1154
+ contextVisible={false}
1155
+ model={heroModel ? models.find((m) => m.provider === heroModel.provider && m.id === heroModel.id) ?? { provider: heroModel.provider, id: heroModel.id, name: heroModel.id, reasoning: false, contextWindow: 0 } : defaultModel}
1156
+ thinkingLevel={heroThinking || undefined}
1157
+ thinkingLevels={heroModelLevels}
1158
+ models={models}
1159
+ providerNames={providerNames}
1160
+ authByProvider={authByProvider}
1161
+ queue={{ steering: [], followUp: [] }}
1162
+ onSend={onSend}
1163
+ onSteer={() => ({ success: false })}
1164
+ onAbort={() => {}}
1165
+ onSelectModel={onSelectHeroModel}
1166
+ onSelectLevel={onSelectHeroThinking}
1167
+ />
1168
+ </div>
1169
+ </div>
1170
+ );
1171
+ }