@baique/pi-web-sky 0.1.35 → 0.1.37

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 (483) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +11 -11
  3. package/.next/build-manifest.json +4 -4
  4. package/.next/next-server.js.nft.json +1 -1
  5. package/.next/prerender-manifest.json +3 -3
  6. package/.next/react-loadable-manifest.json +2 -2
  7. package/.next/required-server-files.js +6 -6
  8. package/.next/required-server-files.json +6 -6
  9. package/.next/server/app/_global-error/page.js +2 -2
  10. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  11. package/.next/server/app/_global-error.html +1 -1
  12. package/.next/server/app/_global-error.rsc +1 -1
  13. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  14. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  15. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  16. package/.next/server/app/_not-found/page.js +1 -1
  17. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  18. package/.next/server/app/_not-found.html +1 -1
  19. package/.next/server/app/_not-found.rsc +3 -3
  20. package/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
  21. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +3 -3
  22. package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  23. package/.next/server/app/api/agent/[id]/bash-output/route.js +2 -2
  24. package/.next/server/app/api/agent/[id]/bash-output/route_client-reference-manifest.js +1 -1
  25. package/.next/server/app/api/agent/[id]/events/route.js +3 -3
  26. package/.next/server/app/api/agent/[id]/events/route_client-reference-manifest.js +1 -1
  27. package/.next/server/app/api/agent/[id]/route.js +2 -2
  28. package/.next/server/app/api/agent/[id]/route_client-reference-manifest.js +1 -1
  29. package/.next/server/app/api/agent/new/route.js +1 -1
  30. package/.next/server/app/api/agent/new/route_client-reference-manifest.js +1 -1
  31. package/.next/server/app/api/agent/running/route.js +1 -1
  32. package/.next/server/app/api/agent/running/route_client-reference-manifest.js +1 -1
  33. package/.next/server/app/api/app-update/route.js +1 -1
  34. package/.next/server/app/api/app-update/route_client-reference-manifest.js +1 -1
  35. package/.next/server/app/api/auth/all-providers/route.js +1 -1
  36. package/.next/server/app/api/auth/all-providers/route_client-reference-manifest.js +1 -1
  37. package/.next/server/app/api/auth/api-key/[provider]/route.js +1 -1
  38. package/.next/server/app/api/auth/api-key/[provider]/route_client-reference-manifest.js +1 -1
  39. package/.next/server/app/api/auth/login/[provider]/route.js +3 -3
  40. package/.next/server/app/api/auth/login/[provider]/route_client-reference-manifest.js +1 -1
  41. package/.next/server/app/api/auth/logout/[provider]/route.js +1 -1
  42. package/.next/server/app/api/auth/logout/[provider]/route_client-reference-manifest.js +1 -1
  43. package/.next/server/app/api/auth/providers/route.js +1 -1
  44. package/.next/server/app/api/auth/providers/route_client-reference-manifest.js +1 -1
  45. package/.next/server/app/api/boards/[id]/canvas/route.js +1 -1
  46. package/.next/server/app/api/boards/[id]/canvas/route_client-reference-manifest.js +1 -1
  47. package/.next/server/app/api/boards/[id]/edges/[eid]/route.js +1 -1
  48. package/.next/server/app/api/boards/[id]/edges/[eid]/route_client-reference-manifest.js +1 -1
  49. package/.next/server/app/api/boards/[id]/edges/route.js +1 -1
  50. package/.next/server/app/api/boards/[id]/edges/route_client-reference-manifest.js +1 -1
  51. package/.next/server/app/api/boards/[id]/nodes/[nid]/route.js +1 -1
  52. package/.next/server/app/api/boards/[id]/nodes/[nid]/route_client-reference-manifest.js +1 -1
  53. package/.next/server/app/api/boards/[id]/nodes/route.js +1 -1
  54. package/.next/server/app/api/boards/[id]/nodes/route_client-reference-manifest.js +1 -1
  55. package/.next/server/app/api/boards/[id]/reconcile-task-edges/route.js +1 -1
  56. package/.next/server/app/api/boards/[id]/reconcile-task-edges/route_client-reference-manifest.js +1 -1
  57. package/.next/server/app/api/boards/[id]/route.js +1 -1
  58. package/.next/server/app/api/boards/[id]/route_client-reference-manifest.js +1 -1
  59. package/.next/server/app/api/boards/purge-orphans/route.js +1 -1
  60. package/.next/server/app/api/boards/purge-orphans/route_client-reference-manifest.js +1 -1
  61. package/.next/server/app/api/boards/reorder/route.js +1 -1
  62. package/.next/server/app/api/boards/reorder/route_client-reference-manifest.js +1 -1
  63. package/.next/server/app/api/boards/route.js +1 -1
  64. package/.next/server/app/api/boards/route_client-reference-manifest.js +1 -1
  65. package/.next/server/app/api/cwd/browse/route.js +1 -1
  66. package/.next/server/app/api/cwd/browse/route_client-reference-manifest.js +1 -1
  67. package/.next/server/app/api/cwd/validate/route.js +2 -2
  68. package/.next/server/app/api/cwd/validate/route_client-reference-manifest.js +1 -1
  69. package/.next/server/app/api/default-cwd/route.js +2 -2
  70. package/.next/server/app/api/default-cwd/route_client-reference-manifest.js +1 -1
  71. package/.next/server/app/api/file-index/route.js +2 -2
  72. package/.next/server/app/api/file-index/route_client-reference-manifest.js +1 -1
  73. package/.next/server/app/api/files/[...path]/route.js +2 -2
  74. package/.next/server/app/api/files/[...path]/route_client-reference-manifest.js +1 -1
  75. package/.next/server/app/api/git/diff/route.js +1 -1
  76. package/.next/server/app/api/git/diff/route_client-reference-manifest.js +1 -1
  77. package/.next/server/app/api/git/status/route.js +1 -1
  78. package/.next/server/app/api/git/status/route_client-reference-manifest.js +1 -1
  79. package/.next/server/app/api/home/route.js +1 -1
  80. package/.next/server/app/api/home/route_client-reference-manifest.js +1 -1
  81. package/.next/server/app/api/mcp/route.js +2 -2
  82. package/.next/server/app/api/mcp/route_client-reference-manifest.js +1 -1
  83. package/.next/server/app/api/models/route.js +2 -2
  84. package/.next/server/app/api/models/route_client-reference-manifest.js +1 -1
  85. package/.next/server/app/api/models-config/catalog/route.js +1 -1
  86. package/.next/server/app/api/models-config/catalog/route_client-reference-manifest.js +1 -1
  87. package/.next/server/app/api/models-config/discover/route.js +1 -1
  88. package/.next/server/app/api/models-config/discover/route_client-reference-manifest.js +1 -1
  89. package/.next/server/app/api/models-config/route.js +1 -1
  90. package/.next/server/app/api/models-config/route_client-reference-manifest.js +1 -1
  91. package/.next/server/app/api/models-config/test/route.js +1 -1
  92. package/.next/server/app/api/models-config/test/route_client-reference-manifest.js +1 -1
  93. package/.next/server/app/api/plugins/route.js +2 -2
  94. package/.next/server/app/api/plugins/route_client-reference-manifest.js +1 -1
  95. package/.next/server/app/api/project-trust/route.js +2 -2
  96. package/.next/server/app/api/project-trust/route_client-reference-manifest.js +1 -1
  97. package/.next/server/app/api/quota/route.js +1 -1
  98. package/.next/server/app/api/quota/route_client-reference-manifest.js +1 -1
  99. package/.next/server/app/api/search/route.js +2 -2
  100. package/.next/server/app/api/search/route_client-reference-manifest.js +1 -1
  101. package/.next/server/app/api/sessions/[id]/auto-name/route.js +3 -3
  102. package/.next/server/app/api/sessions/[id]/auto-name/route_client-reference-manifest.js +1 -1
  103. package/.next/server/app/api/sessions/[id]/context/route.js +2 -2
  104. package/.next/server/app/api/sessions/[id]/context/route_client-reference-manifest.js +1 -1
  105. package/.next/server/app/api/sessions/[id]/entries/[entryId]/thinking/route.js +2 -2
  106. package/.next/server/app/api/sessions/[id]/entries/[entryId]/thinking/route_client-reference-manifest.js +1 -1
  107. package/.next/server/app/api/sessions/[id]/export/route.js +2 -2
  108. package/.next/server/app/api/sessions/[id]/export/route_client-reference-manifest.js +1 -1
  109. package/.next/server/app/api/sessions/[id]/route.js +1 -1
  110. package/.next/server/app/api/sessions/[id]/route_client-reference-manifest.js +1 -1
  111. package/.next/server/app/api/sessions/[id]/state/route.js +2 -2
  112. package/.next/server/app/api/sessions/[id]/state/route_client-reference-manifest.js +1 -1
  113. package/.next/server/app/api/sessions/[id]/todos/route.js +2 -2
  114. package/.next/server/app/api/sessions/[id]/todos/route_client-reference-manifest.js +1 -1
  115. package/.next/server/app/api/sessions/route.js +2 -2
  116. package/.next/server/app/api/sessions/route_client-reference-manifest.js +1 -1
  117. package/.next/server/app/api/skills/check/route.js +1 -1
  118. package/.next/server/app/api/skills/check/route.js.nft.json +1 -1
  119. package/.next/server/app/api/skills/check/route_client-reference-manifest.js +1 -1
  120. package/.next/server/app/api/skills/install/route.js +2 -2
  121. package/.next/server/app/api/skills/install/route_client-reference-manifest.js +1 -1
  122. package/.next/server/app/api/skills/route.js +2 -31
  123. package/.next/server/app/api/skills/route.js.nft.json +1 -1
  124. package/.next/server/app/api/skills/route_client-reference-manifest.js +1 -1
  125. package/.next/server/app/api/skills/search/route.js +1 -1
  126. package/.next/server/app/api/skills/search/route_client-reference-manifest.js +1 -1
  127. package/.next/server/app/api/skills/update/route.js +1 -1
  128. package/.next/server/app/api/skills/update/route.js.nft.json +1 -1
  129. package/.next/server/app/api/skills/update/route_client-reference-manifest.js +1 -1
  130. package/.next/server/app/api/task-card-questions/[id]/answer/route.js +1 -1
  131. package/.next/server/app/api/task-card-questions/[id]/answer/route_client-reference-manifest.js +1 -1
  132. package/.next/server/app/api/task-card-questions/route.js +1 -1
  133. package/.next/server/app/api/task-card-questions/route_client-reference-manifest.js +1 -1
  134. package/.next/server/app/api/task-cards/[id]/route.js +1 -1
  135. package/.next/server/app/api/task-cards/[id]/route_client-reference-manifest.js +1 -1
  136. package/.next/server/app/api/task-cards/route.js +1 -1
  137. package/.next/server/app/api/task-cards/route_client-reference-manifest.js +1 -1
  138. package/.next/server/app/api/task-scheduler/status/route.js +1 -1
  139. package/.next/server/app/api/task-scheduler/status/route_client-reference-manifest.js +1 -1
  140. package/.next/server/app/api/tasks/[id]/board/route.js +1 -1
  141. package/.next/server/app/api/tasks/[id]/board/route_client-reference-manifest.js +1 -1
  142. package/.next/server/app/api/tasks/[id]/route.js +1 -1
  143. package/.next/server/app/api/tasks/[id]/route_client-reference-manifest.js +1 -1
  144. package/.next/server/app/api/tasks/reorder/route.js +1 -1
  145. package/.next/server/app/api/tasks/reorder/route_client-reference-manifest.js +1 -1
  146. package/.next/server/app/api/tasks/route.js +1 -1
  147. package/.next/server/app/api/tasks/route_client-reference-manifest.js +1 -1
  148. package/.next/server/app/api/terminal/[id]/events/route.js +3 -3
  149. package/.next/server/app/api/terminal/[id]/events/route_client-reference-manifest.js +1 -1
  150. package/.next/server/app/api/terminal/[id]/route.js +2 -2
  151. package/.next/server/app/api/terminal/[id]/route_client-reference-manifest.js +1 -1
  152. package/.next/server/app/api/terminal/route.js +2 -2
  153. package/.next/server/app/api/terminal/route_client-reference-manifest.js +1 -1
  154. package/.next/server/app/api/worktrees/route.js +2 -2
  155. package/.next/server/app/api/worktrees/route_client-reference-manifest.js +1 -1
  156. package/.next/server/app/favicon.ico/route.js +1 -1
  157. package/.next/server/app/index.html +1 -1
  158. package/.next/server/app/index.rsc +5 -5
  159. package/.next/server/app/index.segments/__PAGE__.segment.rsc +5 -5
  160. package/.next/server/app/index.segments/_full.segment.rsc +5 -5
  161. package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  162. package/.next/server/app/manifest.webmanifest/route.js +2 -2
  163. package/.next/server/app/manifest.webmanifest/route_client-reference-manifest.js +1 -1
  164. package/.next/server/app/page.js +3 -3
  165. package/.next/server/app/page_client-reference-manifest.js +1 -1
  166. package/.next/server/app-paths-manifest.json +11 -11
  167. package/.next/server/chunks/2404.js +2 -2
  168. package/.next/server/chunks/2430.js +4 -4
  169. package/.next/server/chunks/3500.js +30 -0
  170. package/.next/server/chunks/4226.js +2 -2
  171. package/.next/server/chunks/542.js +11 -6
  172. package/.next/server/chunks/5794.js +2 -2
  173. package/.next/server/chunks/6429.js +1 -1
  174. package/.next/server/chunks/898.js +2 -2
  175. package/.next/server/instrumentation.js +1 -1
  176. package/.next/server/middleware-build-manifest.js +1 -1
  177. package/.next/server/middleware-react-loadable-manifest.js +1 -1
  178. package/.next/server/middleware.js +3 -3
  179. package/.next/server/next-font-manifest.js +1 -1
  180. package/.next/server/next-font-manifest.json +1 -1
  181. package/.next/server/pages/404.html +1 -1
  182. package/.next/server/pages/500.html +1 -1
  183. package/.next/server/server-reference-manifest.json +1 -1
  184. package/.next/static/chunks/5315.dba7515ae6e139ae.js +4 -0
  185. package/.next/static/chunks/{7999.f4ab221861378788.js → 7999.879d5a20e8641752.js} +1 -1
  186. package/.next/static/chunks/app/_not-found/{page-af4fe23994cb3d66.js → page-8cea8d8de35f4da4.js} +1 -1
  187. package/.next/static/chunks/app/{layout-1d9a7a44fbc92d2e.js → layout-c4ca28ccc08bc975.js} +1 -1
  188. package/.next/static/chunks/app/{page-6d6779a81a0a7639.js → page-c9ead38525a85686.js} +3 -3
  189. package/.next/static/chunks/{main-app-b3e8a8d15d83e1f0.js → main-app-dd2385a1a5a588df.js} +1 -1
  190. package/.next/static/chunks/next/dist/client/components/builtin/global-error-be943dcb89867ab9.js +1 -0
  191. package/.next/static/chunks/{webpack-fa4f40085b1ec1ac.js → webpack-4bbf04891e910713.js} +1 -1
  192. package/.next/static/css/422c7dc0faa04d89.css +1 -0
  193. package/.next/trace +8 -9
  194. package/.next/trace-build +1 -1
  195. package/.next/types/app/api/agent/[id]/bash-output/route.ts +1 -1
  196. package/.next/types/app/api/agent/[id]/events/route.ts +1 -1
  197. package/.next/types/app/api/agent/[id]/route.ts +1 -1
  198. package/.next/types/app/api/agent/new/route.ts +1 -1
  199. package/.next/types/app/api/agent/running/route.ts +1 -1
  200. package/.next/types/app/api/app-update/route.ts +1 -1
  201. package/.next/types/app/api/auth/all-providers/route.ts +1 -1
  202. package/.next/types/app/api/auth/api-key/[provider]/route.ts +1 -1
  203. package/.next/types/app/api/auth/login/[provider]/route.ts +1 -1
  204. package/.next/types/app/api/auth/logout/[provider]/route.ts +1 -1
  205. package/.next/types/app/api/auth/providers/route.ts +1 -1
  206. package/.next/types/app/api/boards/[id]/canvas/route.ts +1 -1
  207. package/.next/types/app/api/boards/[id]/edges/[eid]/route.ts +1 -1
  208. package/.next/types/app/api/boards/[id]/edges/route.ts +1 -1
  209. package/.next/types/app/api/boards/[id]/nodes/[nid]/route.ts +1 -1
  210. package/.next/types/app/api/boards/[id]/nodes/route.ts +1 -1
  211. package/.next/types/app/api/boards/[id]/reconcile-task-edges/route.ts +1 -1
  212. package/.next/types/app/api/boards/[id]/route.ts +1 -1
  213. package/.next/types/app/api/boards/purge-orphans/route.ts +1 -1
  214. package/.next/types/app/api/boards/reorder/route.ts +1 -1
  215. package/.next/types/app/api/boards/route.ts +1 -1
  216. package/.next/types/app/api/cwd/browse/route.ts +1 -1
  217. package/.next/types/app/api/cwd/validate/route.ts +1 -1
  218. package/.next/types/app/api/default-cwd/route.ts +1 -1
  219. package/.next/types/app/api/file-index/route.ts +1 -1
  220. package/.next/types/app/api/files/[...path]/route.ts +1 -1
  221. package/.next/types/app/api/git/diff/route.ts +1 -1
  222. package/.next/types/app/api/git/status/route.ts +1 -1
  223. package/.next/types/app/api/home/route.ts +1 -1
  224. package/.next/types/app/api/mcp/route.ts +1 -1
  225. package/.next/types/app/api/models/route.ts +1 -1
  226. package/.next/types/app/api/models-config/catalog/route.ts +1 -1
  227. package/.next/types/app/api/models-config/discover/route.ts +1 -1
  228. package/.next/types/app/api/models-config/route.ts +1 -1
  229. package/.next/types/app/api/models-config/test/route.ts +1 -1
  230. package/.next/types/app/api/plugins/route.ts +1 -1
  231. package/.next/types/app/api/project-trust/route.ts +1 -1
  232. package/.next/types/app/api/quota/route.ts +1 -1
  233. package/.next/types/app/api/search/route.ts +1 -1
  234. package/.next/types/app/api/sessions/[id]/auto-name/route.ts +1 -1
  235. package/.next/types/app/api/sessions/[id]/context/route.ts +1 -1
  236. package/.next/types/app/api/sessions/[id]/entries/[entryId]/thinking/route.ts +1 -1
  237. package/.next/types/app/api/sessions/[id]/export/route.ts +1 -1
  238. package/.next/types/app/api/sessions/[id]/route.ts +1 -1
  239. package/.next/types/app/api/sessions/[id]/state/route.ts +1 -1
  240. package/.next/types/app/api/sessions/[id]/todos/route.ts +1 -1
  241. package/.next/types/app/api/sessions/route.ts +1 -1
  242. package/.next/types/app/api/skills/check/route.ts +1 -1
  243. package/.next/types/app/api/skills/install/route.ts +1 -1
  244. package/.next/types/app/api/skills/route.ts +1 -1
  245. package/.next/types/app/api/skills/search/route.ts +1 -1
  246. package/.next/types/app/api/skills/update/route.ts +1 -1
  247. package/.next/types/app/api/task-card-questions/[id]/answer/route.ts +1 -1
  248. package/.next/types/app/api/task-card-questions/route.ts +1 -1
  249. package/.next/types/app/api/task-cards/[id]/route.ts +1 -1
  250. package/.next/types/app/api/task-cards/route.ts +1 -1
  251. package/.next/types/app/api/task-scheduler/status/route.ts +1 -1
  252. package/.next/types/app/api/tasks/[id]/board/route.ts +1 -1
  253. package/.next/types/app/api/tasks/[id]/route.ts +1 -1
  254. package/.next/types/app/api/tasks/reorder/route.ts +1 -1
  255. package/.next/types/app/api/tasks/route.ts +1 -1
  256. package/.next/types/app/api/terminal/[id]/events/route.ts +1 -1
  257. package/.next/types/app/api/terminal/[id]/route.ts +1 -1
  258. package/.next/types/app/api/terminal/route.ts +1 -1
  259. package/.next/types/app/api/worktrees/route.ts +1 -1
  260. package/.next/types/app/layout.ts +1 -1
  261. package/.next/types/app/page.ts +1 -1
  262. package/bin/pi-web-sky.js +15 -20
  263. package/lib/agent-client.test.mjs +64 -0
  264. package/lib/agent-client.ts +53 -0
  265. package/lib/agent-event-connection.test.mjs +193 -0
  266. package/lib/agent-event-connection.ts +202 -0
  267. package/lib/agent-event-stream.test.mjs +155 -0
  268. package/lib/agent-event-stream.ts +132 -0
  269. package/lib/agent-event-wire.test.mjs +278 -0
  270. package/lib/agent-event-wire.ts +107 -0
  271. package/lib/agent-phase.ts +24 -0
  272. package/lib/allowed-roots.ts +31 -0
  273. package/lib/ansi.test.mjs +52 -0
  274. package/lib/ansi.ts +211 -0
  275. package/lib/api-types.ts +139 -0
  276. package/lib/app-update.test.mjs +27 -0
  277. package/lib/app-update.ts +28 -0
  278. package/lib/atomic-file.test.mjs +37 -0
  279. package/lib/atomic-file.ts +34 -0
  280. package/lib/audit-session.ts +235 -0
  281. package/lib/bash-output.test.mjs +63 -0
  282. package/lib/bash-output.ts +53 -0
  283. package/lib/bg-image.ts +129 -0
  284. package/lib/board-events.ts +83 -0
  285. package/lib/board-purge.test.mjs +66 -0
  286. package/lib/board-purge.ts +65 -0
  287. package/lib/board-search.test.mjs +110 -0
  288. package/lib/board-search.ts +63 -0
  289. package/lib/board-store.test.mjs +542 -0
  290. package/lib/board-store.ts +794 -0
  291. package/lib/board-types.ts +96 -0
  292. package/lib/board-utils.ts +17 -0
  293. package/lib/bounded-form-data.test.mjs +54 -0
  294. package/lib/bounded-form-data.ts +49 -0
  295. package/lib/browser-notifications.test.mjs +167 -0
  296. package/lib/browser-notifications.ts +104 -0
  297. package/lib/chat-lazy-load.test.mjs +140 -0
  298. package/lib/chat-lazy-load.ts +64 -0
  299. package/lib/clipboard-paths.test.mjs +140 -0
  300. package/lib/clipboard-paths.ts +192 -0
  301. package/lib/clipboard.ts +18 -0
  302. package/lib/compaction-summary.test.mjs +44 -0
  303. package/lib/compaction-summary.ts +34 -0
  304. package/lib/custom-ui-terminal.test.mjs +32 -0
  305. package/lib/custom-ui-terminal.ts +27 -0
  306. package/lib/deepseek-pricing.test.mjs +120 -0
  307. package/lib/deepseek-pricing.ts +71 -0
  308. package/lib/directory-browser.test.mjs +60 -0
  309. package/lib/directory-browser.ts +83 -0
  310. package/lib/draft-stash.test.mjs +91 -0
  311. package/lib/draft-stash.ts +102 -0
  312. package/lib/draft-store.ts +105 -0
  313. package/lib/dropdown-direction.ts +27 -0
  314. package/lib/extension-command.test.mjs +63 -0
  315. package/lib/extension-command.ts +81 -0
  316. package/lib/file-access.test.mjs +31 -0
  317. package/lib/file-access.ts +59 -0
  318. package/lib/file-dirent.test.mjs +56 -0
  319. package/lib/file-dirent.ts +17 -0
  320. package/lib/file-explorer-state.test.mjs +63 -0
  321. package/lib/file-explorer-state.ts +36 -0
  322. package/lib/file-fuzzy.test.mjs +29 -0
  323. package/lib/file-fuzzy.ts +189 -0
  324. package/lib/file-links.test.mjs +92 -0
  325. package/lib/file-links.ts +148 -0
  326. package/lib/file-paths.ts +43 -0
  327. package/lib/file-types.test.mjs +34 -0
  328. package/lib/file-types.ts +73 -0
  329. package/lib/file-upload.test.mjs +70 -0
  330. package/lib/file-upload.ts +59 -0
  331. package/lib/file-viewer-state.test.mjs +20 -0
  332. package/lib/file-viewer-state.ts +15 -0
  333. package/lib/frontmatter.test.mjs +55 -0
  334. package/lib/frontmatter.ts +87 -0
  335. package/lib/git-changes.test.mjs +52 -0
  336. package/lib/git-changes.ts +232 -0
  337. package/lib/git-status.ts +47 -0
  338. package/lib/git-types.ts +29 -0
  339. package/lib/http-dispatcher.test.mjs +83 -0
  340. package/lib/http-dispatcher.ts +86 -0
  341. package/lib/i18n/format.test.mjs +19 -0
  342. package/lib/i18n/format.ts +60 -0
  343. package/lib/i18n/messages/en.ts +662 -0
  344. package/lib/i18n/messages/zh-CN.ts +661 -0
  345. package/lib/i18n/registry.test.mjs +32 -0
  346. package/lib/i18n/registry.ts +43 -0
  347. package/lib/i18n/types.ts +15 -0
  348. package/lib/image-attachments.test.mjs +27 -0
  349. package/lib/image-attachments.ts +56 -0
  350. package/lib/initial-navigation.test.mjs +65 -0
  351. package/lib/initial-navigation.ts +15 -0
  352. package/lib/markdown.test.mjs +104 -0
  353. package/lib/markdown.ts +347 -0
  354. package/lib/message-display.test.mjs +130 -0
  355. package/lib/message-display.ts +47 -0
  356. package/lib/model-catalog.test.mjs +327 -0
  357. package/lib/model-catalog.ts +414 -0
  358. package/lib/model-discovery-auth.ts +58 -0
  359. package/lib/model-discovery.test.mjs +50 -0
  360. package/lib/model-discovery.ts +75 -0
  361. package/lib/model-id-preference.ts +46 -0
  362. package/lib/model-scope.test.mjs +193 -0
  363. package/lib/model-scope.ts +198 -0
  364. package/lib/models-cache.test.mjs +122 -0
  365. package/lib/models-cache.ts +90 -0
  366. package/lib/models-config-store.test.mjs +200 -0
  367. package/lib/models-config-store.ts +84 -0
  368. package/lib/next-config-esm.test.mjs +14 -0
  369. package/lib/next-config.test.mjs +13 -0
  370. package/lib/node-version.test.mjs +33 -0
  371. package/lib/normalize.test.mjs +54 -0
  372. package/lib/normalize.ts +63 -0
  373. package/lib/npx.ts +62 -0
  374. package/lib/panel-layout.test.mjs +56 -0
  375. package/lib/panel-layout.ts +52 -0
  376. package/lib/patch.test.mjs +110 -0
  377. package/lib/patch.ts +134 -0
  378. package/lib/path-security.ts +42 -0
  379. package/lib/paths.test.mjs +58 -0
  380. package/lib/paths.ts +71 -0
  381. package/lib/pi-types.ts +183 -0
  382. package/lib/pi-web-options.test.mjs +63 -0
  383. package/lib/process-lifecycle.test.mjs +83 -0
  384. package/lib/project-command-env.test.mjs +298 -0
  385. package/lib/project-command-env.ts +129 -0
  386. package/lib/project-groups.test.mjs +60 -0
  387. package/lib/project-groups.ts +53 -0
  388. package/lib/project-identity.test.mjs +37 -0
  389. package/lib/project-identity.ts +26 -0
  390. package/lib/project-tree.test.mjs +115 -0
  391. package/lib/project-tree.ts +176 -0
  392. package/lib/project-trust.test.mjs +117 -0
  393. package/lib/project-trust.ts +48 -0
  394. package/lib/prompt-recovery.test.mjs +33 -0
  395. package/lib/prompt-recovery.ts +47 -0
  396. package/lib/provider-api-key-route.test.mjs +12 -0
  397. package/lib/provider-credential-store.test.mjs +126 -0
  398. package/lib/provider-credential-store.ts +114 -0
  399. package/lib/provider-listing-runtime.ts +37 -0
  400. package/lib/provider-listing.test.mjs +114 -0
  401. package/lib/provider-listing.ts +118 -0
  402. package/lib/provider-services.ts +64 -0
  403. package/lib/request-security.test.mjs +256 -0
  404. package/lib/request-security.ts +136 -0
  405. package/lib/rpc-manager-shutdown.test.mjs +372 -0
  406. package/lib/rpc-manager-widgets.test.mjs +342 -0
  407. package/lib/rpc-manager.test.mjs +139 -0
  408. package/lib/rpc-manager.ts +1703 -0
  409. package/lib/rpc-session-info.test.mjs +93 -0
  410. package/lib/session-delete.test.mjs +53 -0
  411. package/lib/session-delete.ts +86 -0
  412. package/lib/session-file-references-core.ts +82 -0
  413. package/lib/session-file-references.test.mjs +91 -0
  414. package/lib/session-file-references.ts +29 -0
  415. package/lib/session-path.test.mjs +24 -0
  416. package/lib/session-path.ts +11 -0
  417. package/lib/session-reader.pagination.test.mjs +115 -0
  418. package/lib/session-reader.test.mjs +446 -0
  419. package/lib/session-reader.ts +548 -0
  420. package/lib/session-resolve.test.mjs +65 -0
  421. package/lib/session-row-context-menu.test.mjs +46 -0
  422. package/lib/session-row-context-menu.ts +29 -0
  423. package/lib/session-scanner.test.mjs +151 -0
  424. package/lib/session-scanner.ts +238 -0
  425. package/lib/session-search.test.mjs +173 -0
  426. package/lib/session-search.ts +284 -0
  427. package/lib/session-stats.ts +26 -0
  428. package/lib/session-timing.test.mjs +107 -0
  429. package/lib/session-timing.ts +45 -0
  430. package/lib/session-title.test.mjs +284 -0
  431. package/lib/session-title.ts +255 -0
  432. package/lib/skill-frontmatter.test.mjs +75 -0
  433. package/lib/skill-frontmatter.ts +40 -0
  434. package/lib/skill-lock.test.mjs +182 -0
  435. package/lib/skill-lock.ts +146 -0
  436. package/lib/skill-updates.test.mjs +182 -0
  437. package/lib/skill-updates.ts +263 -0
  438. package/lib/skills-service.ts +16 -0
  439. package/lib/slash-display.test.mjs +122 -0
  440. package/lib/slash-display.ts +30 -0
  441. package/lib/sqlite-db.test.mjs +140 -0
  442. package/lib/sqlite-db.ts +205 -0
  443. package/lib/startup-preferences.test.mjs +130 -0
  444. package/lib/startup-preferences.ts +65 -0
  445. package/lib/streaming-message.test.mjs +212 -0
  446. package/lib/streaming-message.ts +151 -0
  447. package/lib/subagent-widget.test.mjs +87 -0
  448. package/lib/subagent-widget.ts +109 -0
  449. package/lib/sync-room-server.mjs +137 -0
  450. package/lib/task-card-store.test.mjs +309 -0
  451. package/lib/task-card-store.ts +559 -0
  452. package/lib/task-scheduler.ts +498 -0
  453. package/lib/task-store.test.mjs +216 -0
  454. package/lib/task-store.ts +271 -0
  455. package/lib/terminal-input.test.mjs +46 -0
  456. package/lib/terminal-input.ts +63 -0
  457. package/lib/terminal-manager.test.mjs +71 -0
  458. package/lib/terminal-manager.ts +245 -0
  459. package/lib/tool-execution-progress.test.mjs +32 -0
  460. package/lib/tool-execution-progress.ts +29 -0
  461. package/lib/tool-names.ts +25 -0
  462. package/lib/tool-preset-preference.test.mjs +72 -0
  463. package/lib/tool-preset-preference.ts +41 -0
  464. package/lib/tool-presets.test.mjs +56 -0
  465. package/lib/tool-presets.ts +42 -0
  466. package/lib/turn-written-files.test.mjs +137 -0
  467. package/lib/turn-written-files.ts +60 -0
  468. package/lib/types.ts +349 -0
  469. package/lib/wallpaper-settings.ts +191 -0
  470. package/lib/web-auth.test.mjs +50 -0
  471. package/lib/web-auth.ts +45 -0
  472. package/lib/workspace-memory.test.mjs +129 -0
  473. package/lib/workspace-memory.ts +98 -0
  474. package/lib/worktree.test.mjs +50 -0
  475. package/lib/worktree.ts +250 -0
  476. package/package.json +3 -1
  477. package/server.mjs +34 -0
  478. package/.next/server/chunks/7513.js +0 -30
  479. package/.next/static/chunks/5315.03de3c6abd8b283e.js +0 -4
  480. package/.next/static/chunks/next/dist/client/components/builtin/global-error-00a4badaccb388e6.js +0 -1
  481. package/.next/static/css/cf25164cb7c04d95.css +0 -1
  482. /package/.next/static/{Ud6Y2ONkGuPVFbo1xZQvk → 7sDSz-wW-RWYnxh1l6-fD}/_buildManifest.js +0 -0
  483. /package/.next/static/{Ud6Y2ONkGuPVFbo1xZQvk → 7sDSz-wW-RWYnxh1l6-fD}/_ssgManifest.js +0 -0
@@ -0,0 +1,30 @@
1
+ exports.id=3500,exports.ids=[3500],exports.modules={21278:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.d(b,{y:()=>i});var e=c(75430),f=c(75805),g=c(72498),h=a([e,g]);async function i(a){let b=(0,e.getAgentDir)(),c=new e.DefaultResourceLoader({cwd:a,agentDir:b});await c.reload((0,g.Fk)(a,b));let{skills:d,diagnostics:h}=c.getSkills();return{skills:(0,f._)(d,{cwd:a,agentDir:b}),diagnostics:h,projectResourcesLoaded:(0,g.Y1)(a,b).trusted}}[e,g]=h.then?(await h)():h,d()}catch(a){d(a)}})},66737:(a,b,c)=>{"use strict";c.d(b,{Lf:()=>g});var d=c(79868),e=c(21820),f=c(33873);function g(){var a;if(globalThis.__piWebDb)return globalThis.__piWebDb;let b=new d.DatabaseSync((0,f.join)(function(){let a=process.env.PI_CODING_AGENT_DIR;if(a){let b=a.startsWith("~")?(0,f.join)((0,e.homedir)(),a.slice(1)):a;return(0,f.normalize)(b)}return(0,f.join)((0,e.homedir)(),".pi","agent")}(),"pi-web.db"));return b.exec("PRAGMA journal_mode = WAL;"),b.exec("PRAGMA foreign_keys = ON;"),(a=b).exec(`
2
+ CREATE TABLE IF NOT EXISTS tasks (
3
+ id TEXT PRIMARY KEY,
4
+ project_key TEXT NOT NULL,
5
+ name TEXT NOT NULL,
6
+ created INTEGER NOT NULL,
7
+ updated INTEGER NOT NULL
8
+ );
9
+ CREATE INDEX IF NOT EXISTS idx_tasks_project ON tasks(project_key);
10
+
11
+ CREATE TABLE IF NOT EXISTS session_meta (
12
+ session_id TEXT PRIMARY KEY,
13
+ task_id TEXT,
14
+ updated INTEGER NOT NULL
15
+ );
16
+ CREATE INDEX IF NOT EXISTS idx_meta_task ON session_meta(task_id);
17
+
18
+ CREATE TABLE IF NOT EXISTS search_state (
19
+ session_id TEXT PRIMARY KEY,
20
+ mtime TEXT NOT NULL,
21
+ title TEXT NOT NULL
22
+ );
23
+
24
+ CREATE VIRTUAL TABLE IF NOT EXISTS session_search USING fts5(
25
+ session_id UNINDEXED,
26
+ title,
27
+ body,
28
+ tokenize = 'trigram'
29
+ );
30
+ `),function(a){let b=a.prepare("PRAGMA user_version").get().user_version;for(let c of h)if(!(c.version<=b)){a.exec("BEGIN");try{for(let b of c.statements)try{a.exec(b)}catch(b){let a=b instanceof Error?b.message:String(b);if(!/duplicate column name/i.test(a))throw b}a.exec(`PRAGMA user_version = ${c.version}`),a.exec("COMMIT"),b=c.version}catch(b){throw a.exec("ROLLBACK"),b}}}(a),globalThis.__piWebDb=b,b}let h=[{version:1,name:"pinned columns",statements:["ALTER TABLE tasks ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;","ALTER TABLE session_meta ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;"]},{version:2,name:"tasks.sort_order",statements:["ALTER TABLE tasks ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:3,name:"session boards",statements:["CREATE TABLE IF NOT EXISTS boards (\n id TEXT PRIMARY KEY,\n project_key TEXT NOT NULL,\n name TEXT NOT NULL,\n is_system INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_boards_project ON boards(project_key);","CREATE TABLE IF NOT EXISTS board_nodes (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n ref_id TEXT,\n x REAL NOT NULL,\n y REAL NOT NULL,\n w REAL NOT NULL DEFAULT 0,\n h REAL NOT NULL DEFAULT 0,\n expanded INTEGER NOT NULL DEFAULT 0,\n props TEXT NOT NULL DEFAULT '{}',\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_nodes_board ON board_nodes(board_id);","CREATE TABLE IF NOT EXISTS board_edges (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n from_id TEXT NOT NULL,\n to_id TEXT NOT NULL,\n label TEXT,\n color TEXT,\n dashed INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_edges_board ON board_edges(board_id);","CREATE TABLE IF NOT EXISTS board_view (\n board_id TEXT PRIMARY KEY,\n camera_x REAL NOT NULL DEFAULT 0,\n camera_y REAL NOT NULL DEFAULT 0,\n camera_z REAL NOT NULL DEFAULT 1,\n updated INTEGER NOT NULL\n);"]},{version:4,name:"boards.sort_order",statements:["ALTER TABLE boards ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:5,name:"boards.task_id",statements:["ALTER TABLE boards ADD COLUMN task_id TEXT NULL;","CREATE INDEX IF NOT EXISTS idx_boards_task ON boards(task_id);"]},{version:6,name:"boards.task_id unique (防并发重复创建任务看板)",statements:["CREATE UNIQUE INDEX IF NOT EXISTS idx_boards_task_unique ON boards(task_id);"]},{version:7,name:"task cards",statements:["CREATE TABLE IF NOT EXISTS task_cards (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n project_key TEXT NOT NULL,\n number INTEGER NOT NULL,\n name TEXT NOT NULL,\n description TEXT NOT NULL DEFAULT '',\n ready_status TEXT NOT NULL DEFAULT 'draft',\n exec_status TEXT NOT NULL DEFAULT 'not_started',\n priority INTEGER NOT NULL DEFAULT 0,\n due INTEGER,\n attachments TEXT NOT NULL DEFAULT '[]',\n cwd TEXT,\n use_worktree INTEGER NOT NULL DEFAULT 0,\n max_retries INTEGER NOT NULL DEFAULT 3,\n retry_count INTEGER NOT NULL DEFAULT 0,\n session_id TEXT,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_task_cards_board ON task_cards(board_id);","CREATE INDEX IF NOT EXISTS idx_task_cards_project ON task_cards(project_key);","CREATE UNIQUE INDEX IF NOT EXISTS idx_task_cards_number ON task_cards(project_key, number);","CREATE INDEX IF NOT EXISTS idx_task_cards_status ON task_cards(ready_status, exec_status);","CREATE TABLE IF NOT EXISTS task_card_links (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n target_card_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n created INTEGER NOT NULL,\n UNIQUE(card_id, target_card_id, kind)\n);","CREATE INDEX IF NOT EXISTS idx_task_links_card ON task_card_links(card_id);","CREATE TABLE IF NOT EXISTS task_card_questions (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n question TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'pending',\n answer TEXT,\n created INTEGER NOT NULL,\n answered INTEGER\n);","CREATE INDEX IF NOT EXISTS idx_task_questions_status ON task_card_questions(status);"]},{version:8,name:"task_cards.dispatch_token (跨进程派发互斥锁)",statements:["ALTER TABLE task_cards ADD COLUMN dispatch_token TEXT NULL;"]}]},72498:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.d(b,{Fk:()=>i,Y1:()=>g,er:()=>h});var e=c(75430),f=a([e]);function g(a,b){if(!(a&&(0,e.hasTrustRequiringProjectResources)(a)))return{requiresTrust:!1,trusted:!0};let c=new e.ProjectTrustStore(b);return{requiresTrust:!0,trusted:!0===c.get(a)}}function h(a,b){let c=g(a,b);return c.requiresTrust?(new e.ProjectTrustStore(b).set(a,!0),{requiresTrust:!0,trusted:!0}):c}function i(a,b){if(!g(a,b).requiresTrust)return;let c=new e.ProjectTrustStore(b);return{resolveProjectTrust:async()=>!0===c.get(a)}}e=(f.then?(await f)():f)[0],d()}catch(a){d(a)}})},75805:(a,b,c)=>{"use strict";c.d(b,{_:()=>j});var d=c(29021),e=c(21820),f=c(33873);function g(a){try{let b=JSON.parse((0,d.readFileSync)(a,"utf8"));return b.skills&&"object"==typeof b.skills?b.skills:{}}catch{return{}}}function h(a,b){let c=(0,f.relative)((0,f.resolve)(b),(0,f.resolve)(a));return""!==c&&".."!==c&&!c.startsWith(`..${f.sep}`)&&!(0,f.isAbsolute)(c)}function i(a,b,c){var d;let e=function(a,b){if(a[b])return a[b];let c=b.toLowerCase(),d=Object.keys(a).find(a=>a.toLowerCase()===c);return d?a[d]:void 0}(a,b);if(!e||"string"!=typeof e.source||!e.source.trim())return;let f="string"==typeof e.sourceType?e.sourceType:void 0,g=(d=e.source.trim(),"github"!==f?d.replace(/\/$/,""):d.replace(/^git\+/,"").replace(/^https?:\/\/github\.com\//,"").replace(/^git@github\.com:/,"").replace(/\.git$/,"").replace(/\/$/,""));if(!g)return;let h="string"==typeof e.skillPath?e.skillPath:void 0,i="string"==typeof e.ref?e.ref:void 0,j="global"===c?e.skillFolderHash:e.computedHash,k="string"==typeof j&&j?j:void 0,l="github"===f&&/^[\w.-]+\/[\w.-]+$/.test(g);return{package:`${g}@${b}`,scope:c,source:g,sourceType:f,skillsShUrl:"local"===f?void 0:function(a,b){if(!a||a.includes("://")||a.startsWith("git@"))return;let c=a.split("/").filter(Boolean).map(encodeURIComponent).join("/");if(c)return`https://skills.sh/${c}/${encodeURIComponent(b)}`}(g,b),...h&&{skillPath:h},...i&&{ref:i},...k&&{versionHash:k},canCheckForUpdates:!!(l&&h&&k&&("global"===c||!i))}}function j(a,{cwd:b,agentDir:c,globalLockPath:k=function({homeDir:a=(0,e.homedir)(),xdgStateHome:b=process.env.XDG_STATE_HOME}={}){return b?(0,f.join)(b,"skills",".skill-lock.json"):(0,f.join)(a,".agents",".skill-lock.json")}(),projectLockPath:l=(0,f.join)(b,"skills-lock.json")}){let m=g(k),n=g(l),o=(0,f.join)(c,"skills"),p=(0,f.join)(b,".pi","skills");return a.map(a=>{if(!(0,d.existsSync)(a.filePath))return a;let b=h(a.filePath,o)?i(m,a.name,"global"):h(a.filePath,p)?i(n,a.name,"project"):void 0;return b?{...a,install:b}:a})}},78335:()=>{},80547:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.d(b,{A$:()=>o,B7:()=>p,Nw:()=>i.Nw,mc:()=>n,uK:()=>l.uK,wz:()=>i.wz});var e=c(29021),f=c(21820),g=c(33873),h=c.n(g),i=c(25252),j=c(82536),k=c(40402),l=c(58864),m=a([k]);async function n(){let a=Date.now(),b=globalThis.__piAllowedRootsCache;if(b&&b.expiresAt>a)return b.roots;let c=await (0,k.listAllSessions)(),d=new Set;for(let a of c)a.cwd&&d.add((0,i.Nw)(a.cwd)),a.projectRoot&&d.add((0,i.Nw)(a.projectRoot));try{for(let a of(0,e.readdirSync)((0,f.homedir)()))/^pi-cwd-\d{8}$/.test(a)&&d.add((0,i.Nw)(h().join((0,f.homedir)(),a)))}catch{}for(let a of(0,i.HM)())d.add(a);return globalThis.__piAllowedRootsCache={roots:d,expiresAt:a+5e3},d}function o(a,b){return(0,j.o)(a,b)}function p(a,b){return(0,j.x)(a,b)}k=(m.then?(await m)():m)[0],d()}catch(a){d(a)}})},82536:(a,b,c)=>{"use strict";c.d(b,{o:()=>h,x:()=>i});var d=c(29021),e=c(33873),f=c.n(e),g=c(58864);function h(a,b){for(let c of b){let b=(0,g.uK)(a)||(0,g.uK)(c),d=b?f().win32:f(),e=b?"\\":f().sep,h=d.resolve(a),i=d.resolve(c),j=b?h.toLowerCase():h,k=b?i.toLowerCase():i,l=k.endsWith(e)?k:k+e;if(j===k||j.startsWith(l))return!0}return!1}function i(a,b){let c;try{c=(0,d.realpathSync)(a)}catch{return!1}let e=new Set;for(let a of b)try{e.add((0,d.realpathSync)(a))}catch{}return h(c,e)}},96487:()=>{}};
@@ -1,4 +1,4 @@
1
- exports.id=4226,exports.ids=[4226],exports.modules={29742:(a,b,c)=>{"use strict";c.d(b,{BH:()=>w,GO:()=>r,Lc:()=>u,O7:()=>x,QA:()=>t,XJ:()=>n,gN:()=>o,iQ:()=>v,mL:()=>A,mY:()=>B,pt:()=>C,w0:()=>q,zY:()=>p});var d=c(55511),e=c(66737),f=c(71856);let g=()=>Date.now(),h=new Set(["draft","todo"]),i=new Set(["not_started","running","review","done","failed","abandoned","waiting_reply"]);function j(a){if(void 0!==a&&!h.has(a))throw Error(`invalid readyStatus: ${String(a)}`)}function k(a){return{...a,useWorktree:1===a.useWorktree,attachments:JSON.parse(a.attachments)}}let l="id, board_id AS boardId, project_key AS projectKey, number, name, description, ready_status AS readyStatus, exec_status AS execStatus, priority, due, attachments, cwd, use_worktree AS useWorktree, max_retries AS maxRetries, retry_count AS retryCount, session_id AS sessionId, created, updated";function m(a){return(0,e.Lf)().prepare(`SELECT ${l} FROM task_cards WHERE id = ?`).get(a)}function n(a){let b=m(a);return b?k(b):void 0}function o(a){return(0,e.Lf)().prepare(`SELECT ${l} FROM task_cards WHERE board_id = ? ORDER BY number`).all(a).map(k)}function p(a){var b;let c=a.name.trim();if(!a.projectKey)throw Error("projectKey is required");if(!a.boardId)throw Error("boardId is required");if(!c)throw Error("name must not be empty");j(a.readyStatus);let f=(0,d.randomUUID)(),h=g(),i=(b=a.projectKey,(0,e.Lf)().prepare("SELECT COALESCE(MAX(number), 0) AS maxNumber FROM task_cards WHERE project_key = ?").get(b).maxNumber+1);return(0,e.Lf)().prepare("INSERT INTO task_cards (id, board_id, project_key, number, name, description, ready_status, exec_status, priority, due, attachments, cwd, use_worktree, max_retries, retry_count, created, updated) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").run(f,a.boardId,a.projectKey,i,c,a.description??"",a.readyStatus??"todo","not_started",a.priority??0,a.due??null,JSON.stringify(a.attachments??[]),a.cwd??null,+!!a.useWorktree,a.maxRetries??3,0,h,h),k(m(f))}function q(a,b){let c=(0,e.Lf)(),d=m(a);if(!d)return null;let f=[],h=[],l=(a,b)=>{f.push(`${a} = ?`),h.push(b)};if(void 0!==b.name){let a=b.name.trim();if(!a)throw Error("name must not be empty");l("name",a)}if(void 0!==b.description&&l("description",b.description),void 0!==b.readyStatus&&(j(b.readyStatus),l("ready_status",b.readyStatus)),void 0!==b.execStatus){var n=b.execStatus;if(void 0!==n&&!i.has(n))throw Error(`invalid execStatus: ${String(n)}`);l("exec_status",b.execStatus)}return(void 0!==b.priority&&l("priority",b.priority),void 0!==b.due&&l("due",b.due),void 0!==b.attachments&&l("attachments",JSON.stringify(b.attachments)),void 0!==b.cwd&&l("cwd",b.cwd),void 0!==b.useWorktree&&l("use_worktree",+!!b.useWorktree),void 0!==b.maxRetries&&l("max_retries",b.maxRetries),void 0!==b.sessionId&&l("session_id",b.sessionId),void 0!==b.retryCount&&l("retry_count",b.retryCount),0===f.length)?k(d):(l("updated",g()),c.prepare(`UPDATE task_cards SET ${f.join(", ")} WHERE id = ?`).run(...h,a),k(m(a)))}function r(a){let b=(0,e.Lf)();if(m(a)){b.exec("BEGIN");try{for(let c of(b.prepare("DELETE FROM task_card_links WHERE card_id = ? OR target_card_id = ?").run(a,a),b.prepare("DELETE FROM task_card_questions WHERE card_id = ?").run(a),b.prepare("SELECT id, board_id AS boardId FROM board_nodes WHERE kind = 'taskcard' AND ref_id = ? AND board_id != ?").all(a,f.p)))b.prepare("DELETE FROM board_edges WHERE board_id = ? AND (from_id = ? OR to_id = ?)").run(c.boardId,c.id,c.id),b.prepare("DELETE FROM board_nodes WHERE id = ?").run(c.id),b.prepare("UPDATE boards SET updated = ? WHERE id = ?").run(g(),c.boardId);b.prepare("DELETE FROM task_cards WHERE id = ?").run(a),b.exec("COMMIT")}catch(a){throw b.exec("ROLLBACK"),a}}}let s="id, card_id AS cardId, target_card_id AS targetCardId, kind, created";function t(a){return(0,e.Lf)().prepare(`SELECT ${s} FROM task_card_links WHERE card_id = ? ORDER BY created, rowid`).all(a)}function u(a){return(0,e.Lf)().prepare(`SELECT ${s} FROM task_card_links WHERE target_card_id = ? ORDER BY created, rowid`).all(a)}function v(a,b,c){let f=(0,e.Lf)(),h=n(a);if(!h)throw Error(`task card not found: ${a}`);let i=(b,c)=>{if(b===a)throw Error(`${c} target 不能是自身`);let d=n(b);if(!d)throw Error(`${c} target not found: ${b}`);if(d.boardId!==h.boardId)throw Error(`${c} target 不允许跨看板: ${b}`)};for(let a of b)i(a,"prerequisite");for(let a of c)i(a,"related");let j=g();f.exec("BEGIN");try{f.prepare("DELETE FROM task_card_links WHERE card_id = ?").run(a);let e=f.prepare("INSERT OR IGNORE INTO task_card_links (id, card_id, target_card_id, kind, created) VALUES (?, ?, ?, ?, ?)");for(let c of b)e.run((0,d.randomUUID)(),a,c,"prerequisite",j);for(let b of c)e.run((0,d.randomUUID)(),a,b,"related",j);f.exec("COMMIT")}catch(a){throw f.exec("ROLLBACK"),a}}function w(){return(0,e.Lf)().prepare(`SELECT ${l} FROM task_cards WHERE exec_status = 'running' ORDER BY number`).all().map(k)}function x(a){let b=a.map(()=>"?").join(",");return(0,e.Lf)().prepare(`SELECT ${l} FROM task_cards WHERE exec_status IN (${b}) ORDER BY number`).all(...a).map(k)}let y="id, card_id AS cardId, session_id AS sessionId, question, status, answer, created, answered";function z(a){return{...a}}function A(a){let b=a&&"all"!==a?"WHERE status = ?":"";return(0,e.Lf)().prepare(`SELECT ${y} FROM task_card_questions ${b} ORDER BY created`).all(...a&&"all"!==a?[a]:[]).map(z)}function B(){return(0,e.Lf)().prepare("SELECT COUNT(*) AS n FROM task_card_questions WHERE status = 'pending'").get().n}function C(a,b){let c=(0,e.Lf)(),d=(0,e.Lf)().prepare(`SELECT ${y} FROM task_card_questions WHERE id = ?`).get(a);if(!d)return null;if("answered"===d.status)return z(d);let f=Date.now();return c.prepare("UPDATE task_card_questions SET status = 'answered', answer = ?, answered = ? WHERE id = ?").run(b,f,a),z((0,e.Lf)().prepare(`SELECT ${y} FROM task_card_questions WHERE id = ?`).get(a))}},66737:(a,b,c)=>{"use strict";c.d(b,{Lf:()=>g});var d=c(80099),e=c(21820),f=c(33873);function g(){var a;if(globalThis.__piWebDb)return globalThis.__piWebDb;let b=new d.DatabaseSync((0,f.join)(function(){let a=process.env.PI_CODING_AGENT_DIR;if(a){let b=a.startsWith("~")?(0,f.join)((0,e.homedir)(),a.slice(1)):a;return(0,f.normalize)(b)}return(0,f.join)((0,e.homedir)(),".pi","agent")}(),"pi-web.db"));return b.exec("PRAGMA journal_mode = WAL;"),b.exec("PRAGMA foreign_keys = ON;"),(a=b).exec(`
1
+ exports.id=4226,exports.ids=[4226],exports.modules={29742:(a,b,c)=>{"use strict";c.d(b,{BH:()=>w,GO:()=>r,Lc:()=>u,O7:()=>x,QA:()=>t,XJ:()=>n,gN:()=>o,iQ:()=>v,mL:()=>A,mY:()=>B,pt:()=>C,w0:()=>q,zY:()=>p});var d=c(55511),e=c(66737),f=c(71856);let g=()=>Date.now(),h=new Set(["draft","todo"]),i=new Set(["not_started","running","review","done","failed","abandoned","waiting_reply"]);function j(a){if(void 0!==a&&!h.has(a))throw Error(`invalid readyStatus: ${String(a)}`)}function k(a){return{...a,useWorktree:1===a.useWorktree,attachments:JSON.parse(a.attachments)}}let l="id, board_id AS boardId, project_key AS projectKey, number, name, description, ready_status AS readyStatus, exec_status AS execStatus, priority, due, attachments, cwd, use_worktree AS useWorktree, max_retries AS maxRetries, retry_count AS retryCount, session_id AS sessionId, dispatch_token AS dispatchToken, created, updated";function m(a){return(0,e.Lf)().prepare(`SELECT ${l} FROM task_cards WHERE id = ?`).get(a)}function n(a){let b=m(a);return b?k(b):void 0}function o(a){return(0,e.Lf)().prepare(`SELECT ${l} FROM task_cards WHERE board_id = ? ORDER BY number`).all(a).map(k)}function p(a){var b;let c=a.name.trim();if(!a.projectKey)throw Error("projectKey is required");if(!a.boardId)throw Error("boardId is required");if(!c)throw Error("name must not be empty");j(a.readyStatus);let f=(0,d.randomUUID)(),h=g(),i=(b=a.projectKey,(0,e.Lf)().prepare("SELECT COALESCE(MAX(number), 0) AS maxNumber FROM task_cards WHERE project_key = ?").get(b).maxNumber+1);return(0,e.Lf)().prepare("INSERT INTO task_cards (id, board_id, project_key, number, name, description, ready_status, exec_status, priority, due, attachments, cwd, use_worktree, max_retries, retry_count, created, updated) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").run(f,a.boardId,a.projectKey,i,c,a.description??"",a.readyStatus??"todo","not_started",a.priority??0,a.due??null,JSON.stringify(a.attachments??[]),a.cwd??null,+!!a.useWorktree,a.maxRetries??3,0,h,h),k(m(f))}function q(a,b){let c=(0,e.Lf)(),d=m(a);if(!d)return null;let f=[],h=[],l=(a,b)=>{f.push(`${a} = ?`),h.push(b)};if(void 0!==b.name){let a=b.name.trim();if(!a)throw Error("name must not be empty");l("name",a)}if(void 0!==b.description&&l("description",b.description),void 0!==b.readyStatus&&(j(b.readyStatus),l("ready_status",b.readyStatus)),void 0!==b.execStatus){var n=b.execStatus;if(void 0!==n&&!i.has(n))throw Error(`invalid execStatus: ${String(n)}`);l("exec_status",b.execStatus)}return(void 0!==b.priority&&l("priority",b.priority),void 0!==b.due&&l("due",b.due),void 0!==b.attachments&&l("attachments",JSON.stringify(b.attachments)),void 0!==b.cwd&&l("cwd",b.cwd),void 0!==b.useWorktree&&l("use_worktree",+!!b.useWorktree),void 0!==b.maxRetries&&l("max_retries",b.maxRetries),void 0!==b.sessionId&&l("session_id",b.sessionId),void 0!==b.retryCount&&l("retry_count",b.retryCount),0===f.length)?k(d):(l("updated",g()),c.prepare(`UPDATE task_cards SET ${f.join(", ")} WHERE id = ?`).run(...h,a),k(m(a)))}function r(a){let b=(0,e.Lf)();if(m(a)){b.exec("BEGIN");try{for(let c of(b.prepare("DELETE FROM task_card_links WHERE card_id = ? OR target_card_id = ?").run(a,a),b.prepare("DELETE FROM task_card_questions WHERE card_id = ?").run(a),b.prepare("SELECT id, board_id AS boardId FROM board_nodes WHERE kind = 'taskcard' AND ref_id = ? AND board_id != ?").all(a,f.p)))b.prepare("DELETE FROM board_edges WHERE board_id = ? AND (from_id = ? OR to_id = ?)").run(c.boardId,c.id,c.id),b.prepare("DELETE FROM board_nodes WHERE id = ?").run(c.id),b.prepare("UPDATE boards SET updated = ? WHERE id = ?").run(g(),c.boardId);b.prepare("DELETE FROM task_cards WHERE id = ?").run(a),b.exec("COMMIT")}catch(a){throw b.exec("ROLLBACK"),a}}}let s="id, card_id AS cardId, target_card_id AS targetCardId, kind, created";function t(a){return(0,e.Lf)().prepare(`SELECT ${s} FROM task_card_links WHERE card_id = ? ORDER BY created, rowid`).all(a)}function u(a){return(0,e.Lf)().prepare(`SELECT ${s} FROM task_card_links WHERE target_card_id = ? ORDER BY created, rowid`).all(a)}function v(a,b,c){let f=(0,e.Lf)(),h=n(a);if(!h)throw Error(`task card not found: ${a}`);let i=(b,c)=>{if(b===a)throw Error(`${c} target 不能是自身`);let d=n(b);if(!d)throw Error(`${c} target not found: ${b}`);if(d.boardId!==h.boardId)throw Error(`${c} target 不允许跨看板: ${b}`)};for(let a of b)i(a,"prerequisite");for(let a of c)i(a,"related");let j=g();f.exec("BEGIN");try{f.prepare("DELETE FROM task_card_links WHERE card_id = ?").run(a);let e=f.prepare("INSERT OR IGNORE INTO task_card_links (id, card_id, target_card_id, kind, created) VALUES (?, ?, ?, ?, ?)");for(let c of b)e.run((0,d.randomUUID)(),a,c,"prerequisite",j);for(let b of c)e.run((0,d.randomUUID)(),a,b,"related",j);f.exec("COMMIT")}catch(a){throw f.exec("ROLLBACK"),a}}function w(){return(0,e.Lf)().prepare(`SELECT ${l} FROM task_cards WHERE exec_status = 'running' ORDER BY number`).all().map(k)}function x(a){let b=a.map(()=>"?").join(",");return(0,e.Lf)().prepare(`SELECT ${l} FROM task_cards WHERE exec_status IN (${b}) ORDER BY number`).all(...a).map(k)}let y="id, card_id AS cardId, session_id AS sessionId, question, status, answer, created, answered";function z(a){return{...a}}function A(a){let b=a&&"all"!==a?"WHERE status = ?":"";return(0,e.Lf)().prepare(`SELECT ${y} FROM task_card_questions ${b} ORDER BY created`).all(...a&&"all"!==a?[a]:[]).map(z)}function B(){return(0,e.Lf)().prepare("SELECT COUNT(*) AS n FROM task_card_questions WHERE status = 'pending'").get().n}function C(a,b){let c=(0,e.Lf)(),d=(0,e.Lf)().prepare(`SELECT ${y} FROM task_card_questions WHERE id = ?`).get(a);if(!d)return null;if("answered"===d.status)return z(d);let f=Date.now();return c.prepare("UPDATE task_card_questions SET status = 'answered', answer = ?, answered = ? WHERE id = ?").run(b,f,a),z((0,e.Lf)().prepare(`SELECT ${y} FROM task_card_questions WHERE id = ?`).get(a))}},66737:(a,b,c)=>{"use strict";c.d(b,{Lf:()=>g});var d=c(79868),e=c(21820),f=c(33873);function g(){var a;if(globalThis.__piWebDb)return globalThis.__piWebDb;let b=new d.DatabaseSync((0,f.join)(function(){let a=process.env.PI_CODING_AGENT_DIR;if(a){let b=a.startsWith("~")?(0,f.join)((0,e.homedir)(),a.slice(1)):a;return(0,f.normalize)(b)}return(0,f.join)((0,e.homedir)(),".pi","agent")}(),"pi-web.db"));return b.exec("PRAGMA journal_mode = WAL;"),b.exec("PRAGMA foreign_keys = ON;"),(a=b).exec(`
2
2
  CREATE TABLE IF NOT EXISTS tasks (
3
3
  id TEXT PRIMARY KEY,
4
4
  project_key TEXT NOT NULL,
@@ -27,4 +27,4 @@ exports.id=4226,exports.ids=[4226],exports.modules={29742:(a,b,c)=>{"use strict"
27
27
  body,
28
28
  tokenize = 'trigram'
29
29
  );
30
- `),function(a){let b=a.prepare("PRAGMA user_version").get().user_version;for(let c of h)if(!(c.version<=b)){a.exec("BEGIN");try{for(let b of c.statements)try{a.exec(b)}catch(b){let a=b instanceof Error?b.message:String(b);if(!/duplicate column name/i.test(a))throw b}a.exec(`PRAGMA user_version = ${c.version}`),a.exec("COMMIT"),b=c.version}catch(b){throw a.exec("ROLLBACK"),b}}}(a),globalThis.__piWebDb=b,b}let h=[{version:1,name:"pinned columns",statements:["ALTER TABLE tasks ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;","ALTER TABLE session_meta ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;"]},{version:2,name:"tasks.sort_order",statements:["ALTER TABLE tasks ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:3,name:"session boards",statements:["CREATE TABLE IF NOT EXISTS boards (\n id TEXT PRIMARY KEY,\n project_key TEXT NOT NULL,\n name TEXT NOT NULL,\n is_system INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_boards_project ON boards(project_key);","CREATE TABLE IF NOT EXISTS board_nodes (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n ref_id TEXT,\n x REAL NOT NULL,\n y REAL NOT NULL,\n w REAL NOT NULL DEFAULT 0,\n h REAL NOT NULL DEFAULT 0,\n expanded INTEGER NOT NULL DEFAULT 0,\n props TEXT NOT NULL DEFAULT '{}',\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_nodes_board ON board_nodes(board_id);","CREATE TABLE IF NOT EXISTS board_edges (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n from_id TEXT NOT NULL,\n to_id TEXT NOT NULL,\n label TEXT,\n color TEXT,\n dashed INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_edges_board ON board_edges(board_id);","CREATE TABLE IF NOT EXISTS board_view (\n board_id TEXT PRIMARY KEY,\n camera_x REAL NOT NULL DEFAULT 0,\n camera_y REAL NOT NULL DEFAULT 0,\n camera_z REAL NOT NULL DEFAULT 1,\n updated INTEGER NOT NULL\n);"]},{version:4,name:"boards.sort_order",statements:["ALTER TABLE boards ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:5,name:"boards.task_id",statements:["ALTER TABLE boards ADD COLUMN task_id TEXT NULL;","CREATE INDEX IF NOT EXISTS idx_boards_task ON boards(task_id);"]},{version:6,name:"boards.task_id unique (防并发重复创建任务看板)",statements:["CREATE UNIQUE INDEX IF NOT EXISTS idx_boards_task_unique ON boards(task_id);"]},{version:7,name:"task cards",statements:["CREATE TABLE IF NOT EXISTS task_cards (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n project_key TEXT NOT NULL,\n number INTEGER NOT NULL,\n name TEXT NOT NULL,\n description TEXT NOT NULL DEFAULT '',\n ready_status TEXT NOT NULL DEFAULT 'draft',\n exec_status TEXT NOT NULL DEFAULT 'not_started',\n priority INTEGER NOT NULL DEFAULT 0,\n due INTEGER,\n attachments TEXT NOT NULL DEFAULT '[]',\n cwd TEXT,\n use_worktree INTEGER NOT NULL DEFAULT 0,\n max_retries INTEGER NOT NULL DEFAULT 3,\n retry_count INTEGER NOT NULL DEFAULT 0,\n session_id TEXT,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_task_cards_board ON task_cards(board_id);","CREATE INDEX IF NOT EXISTS idx_task_cards_project ON task_cards(project_key);","CREATE UNIQUE INDEX IF NOT EXISTS idx_task_cards_number ON task_cards(project_key, number);","CREATE INDEX IF NOT EXISTS idx_task_cards_status ON task_cards(ready_status, exec_status);","CREATE TABLE IF NOT EXISTS task_card_links (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n target_card_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n created INTEGER NOT NULL,\n UNIQUE(card_id, target_card_id, kind)\n);","CREATE INDEX IF NOT EXISTS idx_task_links_card ON task_card_links(card_id);","CREATE TABLE IF NOT EXISTS task_card_questions (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n question TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'pending',\n answer TEXT,\n created INTEGER NOT NULL,\n answered INTEGER\n);","CREATE INDEX IF NOT EXISTS idx_task_questions_status ON task_card_questions(status);"]}]},71856:(a,b,c)=>{"use strict";c.d(b,{p:()=>d});let d="__running__"},78335:()=>{},96487:()=>{}};
30
+ `),function(a){let b=a.prepare("PRAGMA user_version").get().user_version;for(let c of h)if(!(c.version<=b)){a.exec("BEGIN");try{for(let b of c.statements)try{a.exec(b)}catch(b){let a=b instanceof Error?b.message:String(b);if(!/duplicate column name/i.test(a))throw b}a.exec(`PRAGMA user_version = ${c.version}`),a.exec("COMMIT"),b=c.version}catch(b){throw a.exec("ROLLBACK"),b}}}(a),globalThis.__piWebDb=b,b}let h=[{version:1,name:"pinned columns",statements:["ALTER TABLE tasks ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;","ALTER TABLE session_meta ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;"]},{version:2,name:"tasks.sort_order",statements:["ALTER TABLE tasks ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:3,name:"session boards",statements:["CREATE TABLE IF NOT EXISTS boards (\n id TEXT PRIMARY KEY,\n project_key TEXT NOT NULL,\n name TEXT NOT NULL,\n is_system INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_boards_project ON boards(project_key);","CREATE TABLE IF NOT EXISTS board_nodes (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n ref_id TEXT,\n x REAL NOT NULL,\n y REAL NOT NULL,\n w REAL NOT NULL DEFAULT 0,\n h REAL NOT NULL DEFAULT 0,\n expanded INTEGER NOT NULL DEFAULT 0,\n props TEXT NOT NULL DEFAULT '{}',\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_nodes_board ON board_nodes(board_id);","CREATE TABLE IF NOT EXISTS board_edges (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n from_id TEXT NOT NULL,\n to_id TEXT NOT NULL,\n label TEXT,\n color TEXT,\n dashed INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_edges_board ON board_edges(board_id);","CREATE TABLE IF NOT EXISTS board_view (\n board_id TEXT PRIMARY KEY,\n camera_x REAL NOT NULL DEFAULT 0,\n camera_y REAL NOT NULL DEFAULT 0,\n camera_z REAL NOT NULL DEFAULT 1,\n updated INTEGER NOT NULL\n);"]},{version:4,name:"boards.sort_order",statements:["ALTER TABLE boards ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:5,name:"boards.task_id",statements:["ALTER TABLE boards ADD COLUMN task_id TEXT NULL;","CREATE INDEX IF NOT EXISTS idx_boards_task ON boards(task_id);"]},{version:6,name:"boards.task_id unique (防并发重复创建任务看板)",statements:["CREATE UNIQUE INDEX IF NOT EXISTS idx_boards_task_unique ON boards(task_id);"]},{version:7,name:"task cards",statements:["CREATE TABLE IF NOT EXISTS task_cards (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n project_key TEXT NOT NULL,\n number INTEGER NOT NULL,\n name TEXT NOT NULL,\n description TEXT NOT NULL DEFAULT '',\n ready_status TEXT NOT NULL DEFAULT 'draft',\n exec_status TEXT NOT NULL DEFAULT 'not_started',\n priority INTEGER NOT NULL DEFAULT 0,\n due INTEGER,\n attachments TEXT NOT NULL DEFAULT '[]',\n cwd TEXT,\n use_worktree INTEGER NOT NULL DEFAULT 0,\n max_retries INTEGER NOT NULL DEFAULT 3,\n retry_count INTEGER NOT NULL DEFAULT 0,\n session_id TEXT,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_task_cards_board ON task_cards(board_id);","CREATE INDEX IF NOT EXISTS idx_task_cards_project ON task_cards(project_key);","CREATE UNIQUE INDEX IF NOT EXISTS idx_task_cards_number ON task_cards(project_key, number);","CREATE INDEX IF NOT EXISTS idx_task_cards_status ON task_cards(ready_status, exec_status);","CREATE TABLE IF NOT EXISTS task_card_links (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n target_card_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n created INTEGER NOT NULL,\n UNIQUE(card_id, target_card_id, kind)\n);","CREATE INDEX IF NOT EXISTS idx_task_links_card ON task_card_links(card_id);","CREATE TABLE IF NOT EXISTS task_card_questions (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n question TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'pending',\n answer TEXT,\n created INTEGER NOT NULL,\n answered INTEGER\n);","CREATE INDEX IF NOT EXISTS idx_task_questions_status ON task_card_questions(status);"]},{version:8,name:"task_cards.dispatch_token (跨进程派发互斥锁)",statements:["ALTER TABLE task_cards ADD COLUMN dispatch_token TEXT NULL;"]}]},71856:(a,b,c)=>{"use strict";c.d(b,{p:()=>d});let d="__running__"},78335:()=>{},96487:()=>{}};
@@ -1,4 +1,4 @@
1
- "use strict";exports.id=542,exports.ids=[542],exports.modules={7535:(a,b,c)=>{c.d(b,{z:()=>f});var d=c(76760),e=c.n(d);function f(a,b=process.platform){if(!a)return a;let c="win32"===b?e().win32:e().posix,d=c.normalize(a),g=c.parse(d).root.length,h=d.length;for(;h>g&&d[h-1]===c.sep;)h--;let i=d.slice(0,h);return"win32"===b?i.toLowerCase():i}},7561:(a,b,c)=>{c.d(b,{$:()=>f});var d=c(76760),e=c.n(d);function f(a,b=process.platform){let c="win32"===b?e().win32.normalize(a):e().posix.normalize(a);return"win32"===b?c.toLowerCase():c}},9210:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{X:()=>l});var e=c(29021),f=c(79748),g=c(33873),h=c(75430),i=a([h]);function j(a){if(!a.trim())return null;try{return JSON.parse(a)}catch{return null}}function k(a){let b=a.content;return"string"==typeof b?b:Array.isArray(b)?b.filter(a=>a&&"text"===a.type&&"string"==typeof a.text).map(a=>a.text).join(" "):""}h=(i.then?(await i)():i)[0];let l={scan:async function(a){let b,c=a??(0,g.join)((0,h.getAgentDir)(),"sessions");try{b=(await (0,f.readdir)(c,{withFileTypes:!0})).filter(a=>a.isDirectory()||a.isSymbolicLink()).map(a=>(0,g.join)(c,a.name))}catch{return[]}let d=[];for(let a of b)try{for(let b of(await (0,f.readdir)(a)))b.endsWith(".jsonl")&&d.push((0,g.join)(a,b))}catch{}let i=[];for(let a of d){let b=function(a){let b;try{b=(0,e.statSync)(a)}catch{return null}if(!b.isFile()||0===b.size)return null;let c=function(a,b){let c=Math.min(4096,b),d="",f=(0,e.openSync)(a,"r");try{let a=null,g="";for(;;){let h=Buffer.alloc(c);(0,e.readSync)(f,h,0,c,0);let i=h.toString("utf8"),l=i.lastIndexOf("\n"),m=-1===l?i.length:l+1;for(let b of(d+=i.slice(0,m)).split("\n")){let c=j(b);if(c){if(!a){if("session"!==c.type)return null;a=c;continue}if("message"===c.type&&c.message?.role==="user"){let a=k(c.message).trim();if(a){g=a.slice(0,300);break}}}}if(!a)return null;if(g||c>=49152||c>=b||(c=Math.min(2*c,49152,b))<=0)break}return{header:a,firstMessage:g}}finally{(0,e.closeSync)(f)}}(a,b.size);if(!c)return null;let{header:d,firstMessage:f}=c,g="string"==typeof d.id?d.id:"";if(!g)return null;let h=new Date("string"==typeof d.timestamp?d.timestamp:"");Number.isNaN(h.getTime())&&h.setTime(b.mtime.getTime());let i=function(a,b){let c={name:void 0,lastReply:""};if(b<=0)return c;let d=(0,e.openSync)(a,"r");try{let a=b;for(let b=0;b<256&&a>0;b++){let b=Math.max(0,a-65536),f=a-b,g=Buffer.alloc(f);(0,e.readSync)(d,g,0,f,b);let h=g.toString("utf8").split("\n");for(let a=h.length-1;a>=1;a--){if(void 0!==c.name&&c.lastReply)continue;let b=j(h[a]);if(b){if(void 0===c.name&&"session_info"===b.type&&"string"==typeof b.name){let a=b.name.trim();a&&(c.name=a)}else if(!c.lastReply&&"message"===b.type&&b.message?.role==="assistant"){let a=k(b.message).trim();a&&(c.lastReply=a)}if(void 0!==c.name&&c.lastReply)break}}a=b}return c}finally{(0,e.closeSync)(d)}}(a,b.size);return{path:a,id:g,cwd:"string"==typeof d.cwd?d.cwd:"",name:i.name,created:h,modified:b.mtime,firstMessage:f||"(no messages)",lastReply:i.lastReply,parentSessionPath:"string"==typeof d.parentSession?d.parentSession:void 0}}(a);b&&i.push(b)}return i.sort((a,b)=>b.modified.getTime()-a.modified.getTime()),i}};d()}catch(a){d(a)}})},12144:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{HG:()=>u,OF:()=>v});var e=c(75430),f=c(29862),g=c(55511),h=c(29021),i=c(33873),j=c(18437),k=c(88250),l=c(96515),m=c(81186),n=c(69453),o=c(15253),p=c(61577),q=c(57856),r=a([e,f,l,m,n,o]);[e,f,l,m,n,o]=r.then?(await r)():r;let w=new Set(["agent_end","agent_settled","auto_compaction_end","compaction_end"]),x=["read","bash","edit","write","grep","find","ls"];class y extends e.Theme{constructor(){super({thinkingXhigh:"",searchMatchText:""},{selectedBg:""},"truecolor")}fg(...[,a]){return a}bg(...[,a]){return a}bold(a){return a}italic(a){return a}underline(a){return a}inverse(a){return a}strikethrough(a){return a}getFgAnsi(){return""}getBgAnsi(){return""}getThinkingBorderColor(){return a=>a}getBashModeBorderColor(){return a=>a}}let z=new y,A=new f.KeybindingsManager(f.TUI_KEYBINDINGS);function s(a,b){if(0===b.length)return[];let c=new Set(x),d=a.getAllTools().map(a=>a.name).filter(a=>!c.has(a));return[...new Set([...b,...d])]}class B{constructor(a){this.inner=a,this.listeners=[],this.pendingUiResponses=new Map,this.pendingUiRequests=new Map,this.activeCustomUis=new Map,this.extensionStatuses=new Map,this.extensionWidgets=new Map,this.activeExtensionWidgets=new Map,this.extensionWidgetGenerations=new Map,this.extensionWidgetsResetting=!1,this.pendingPromptCount=0,this.promptAdmissionTail=Promise.resolve(),this.extensionsBound=!1,this.extensionBindingPromise=null,this.extensionBindingError=null,this.forceEmptySystemPrompt=!1,this.unsubscribe=null,this.idleTimer=null,this.onDestroyCallback=null,this.shutdownPromise=null,this._alive=!0,this.lastAgentStart=0}hasPendingUiRequest(){return this.pendingUiRequests.size>0}lastAgentStartAt(){return this.lastAgentStart}get sessionId(){return this.inner.sessionId}get sessionFile(){return this.inner.sessionFile??""}get cwd(){return this.inner.sessionManager.getCwd()}get streamingMessage(){return this.inner.agent.state?.streamingMessage}get isStreaming(){return this.inner.isStreaming}isAlive(){return this._alive}isRunning(){return this._alive&&(this.pendingPromptCount>0||this.inner.isStreaming||this.inner.isCompacting||this.inner.isBashRunning)}start(){this.unsubscribe=this.inner.subscribe(a=>{"agent_start"===a.type&&(this.lastAgentStart=Date.now()),"agent_end"===a.type&&(0,n.mD)(),w.has(a.type)&&this.resetIdleTimer(),this.emit(a)}),this.resetIdleTimer()}setForceEmptySystemPrompt(a){this.forceEmptySystemPrompt=a,this.applyForcedEmptySystemPrompt()}beginExtensionBinding(a={}){this.ensureExtensionsBound(a).catch(a=>{console.error("[pi-web] failed to dispatch session_start to extensions:",a instanceof Error?a.message:a)})}async waitUntilReady(){await this.waitForExtensionsBound()}ensureExtensionsBound(a={}){return(a.forceEmptySystemPrompt&&(this.forceEmptySystemPrompt=!0),this.extensionsBound)?(this.applyForcedEmptySystemPrompt(),Promise.resolve()):(this.extensionBindingPromise||(this.extensionBindingError=null,this.extensionBindingPromise=(async()=>{if(!this._alive)return;let a=this.createExtensionUiContext();if("function"==typeof this.inner.bindExtensions){let b=this.inner.bindExtensions;await b.call(this.inner,{uiContext:a,mode:"rpc",commandContextActions:this.createExtensionCommandContextActions(),shutdownHandler:()=>this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"notify",notifyType:"warning",message:"Extension requested shutdown, but shutdown is not supported in Pi Web."}),onError:a=>this.emit({type:"extension_error",extensionPath:a.extensionPath,event:a.event,error:a.error})})}else this.inner.extensionRunner.setUIContext?.(a,"rpc");this.extensionsBound=!0,this.applyForcedEmptySystemPrompt(),console.log(`[pi-web] session_start dispatched to extensions for session ${this.inner.sessionId}`)})().catch(a=>{throw this.extensionBindingError=a,a})),this.extensionBindingPromise)}async waitForExtensionsBound(){try{this.extensionBindingPromise&&await this.extensionBindingPromise}catch(a){throw a instanceof Error?a:Error(String(a))}if(this.extensionBindingError)throw this.extensionBindingError instanceof Error?this.extensionBindingError:Error(String(this.extensionBindingError))}shouldWaitForExtensions(a){return"prompt"===a||"steer"===a||"follow_up"===a||"get_commands"===a||"get_state"===a}async withFinalRunningNotification(a){try{return await a()}finally{this.resetIdleTimer()}}applyForcedEmptySystemPrompt(){this.forceEmptySystemPrompt&&this.inner.agent.state&&(this.inner.agent.state.systemPrompt="")}emit(a){for(let b of this.listeners)try{b(a)}catch(b){console.error(`[pi-web] failed to deliver ${a.type} event:`,b instanceof Error?b.message:b)}}async acquirePromptAdmission(){let a,b=this.promptAdmissionTail;return this.promptAdmissionTail=new Promise(b=>{a=b}),await b,a}resetIdleTimer(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.isRunning()?this.resetIdleTimer():this.shutdown().catch(a=>{console.error("[pi-web] failed to shut down idle session:",a instanceof Error?a.message:a)})},6e5)}onEvent(a){for(let b of(this.listeners.push(a),this.pendingUiRequests.values()))a(b);return()=>{let b=this.listeners.indexOf(a);-1!==b&&this.listeners.splice(b,1)}}onDestroy(a){this.onDestroyCallback=a}async send(a){this.resetIdleTimer();let b=a.type;if(this.shouldWaitForExtensions(b)&&await this.waitForExtensionsBound(),"prompt"===b||"steer"===b||"follow_up"===b){let b=(0,j.kc)(a.images);if(b)throw Error(b)}switch(b){case"prompt":{let b=await this.acquirePromptAdmission();try{let b,c,d;if(this.inner.isBashRunning)throw Error("Cannot send a prompt while a shell command is running");let e=a.images,f=a.streamingBehavior,g=!1,h=!1,i=!1,j=new Promise((a,d)=>{b=()=>{g=!0,h||(h=!0,a())},c=a=>{h||(h=!0,d(a))}}),k=()=>{i||(i=!0,this.pendingPromptCount=Math.max(0,this.pendingPromptCount-1),this.resetIdleTimer())};this.pendingPromptCount+=1;try{d=this.inner.prompt(a.message,{...e?.length?{images:e}:{},...f?{streamingBehavior:f}:{},source:"rpc",preflightResult:a=>{a&&b()}})}catch(a){throw k(),a}return d.then(()=>{b(),k(),f||this.emit({type:"prompt_done"})},a=>{c(a),k(),(0,n.mD)(),g&&(this.emit({type:"prompt_error",errorMessage:a instanceof Error?a.message:String(a)}),f||this.emit({type:"prompt_done"}))}).catch(a=>{console.error("[pi-web] prompt completion handler failed:",a instanceof Error?a.message:a)}),await j,null}finally{b()}}case"abort":return await this.withFinalRunningNotification(()=>this.inner.abort()),null;case"get_state":{let a=this.inner.model,b=this.inner.getContextUsage();return{sessionId:this.inner.sessionId,sessionFile:this.inner.sessionFile??"",isStreaming:this.inner.isStreaming,isPromptRunning:this.pendingPromptCount>0,isBashRunning:this.inner.isBashRunning,isCompacting:this.inner.isCompacting,autoCompactionEnabled:this.inner.autoCompactionEnabled,autoRetryEnabled:this.inner.autoRetryEnabled,model:a?{id:a.id,provider:a.provider}:void 0,messageCount:0,pendingMessageCount:this.inner.pendingMessageCount,queuedMessages:{steering:[...this.inner.getSteeringMessages()],followUp:[...this.inner.getFollowUpMessages()]},contextUsage:b?{percent:b.percent,contextWindow:b.contextWindow,tokens:b.tokens}:null,systemPrompt:this.inner.agent.state?.systemPrompt??"",thinkingLevel:this.inner.agent.state?.thinkingLevel??"off",extensionStatuses:this.getExtensionStatuses(),extensionWidgets:this.getExtensionWidgets()}}case"set_model":{let{provider:b,modelId:c}=a,d=this.inner.modelRuntime.getModel(b,c);if(d||(await this.inner.modelRuntime.refresh({allowNetwork:!1}),d=this.inner.modelRuntime.getModel(b,c)),!d)throw Error(`Model not found: ${b}/${c}`);return await this.inner.setModel(d),(0,k.kn)(),(0,n.mD)(),{id:d.id,provider:d.provider}}case"fork":{let b;if(this.inner.isBashRunning)throw Error("Cannot fork while a shell command is running");let c=a.entryId,d=this.inner.sessionManager,f=this.inner.sessionFile;if(!d.isPersisted())return{cancelled:!0};if(!f)throw Error("Persisted session is missing a session file");let g=d.getEntry(c);if(!g)throw Error("Invalid entry ID for forking");let h=d.getSessionDir();if(g.parentId){let a=e.SessionManager.open(f,h).createBranchedSession(g.parentId);if(!a)throw Error("Failed to create forked session");b=a}else{let a=e.SessionManager.create(d.getCwd(),h);a.newSession({parentSession:f}),a.getSessionFile()&&a._rewriteFile(),b=a.getSessionFile()}let i=e.SessionManager.open(b,h).getSessionId();return(0,n.O8)(i,b),(0,n.mD)(),await this.shutdown(),{cancelled:!1,newSessionId:i}}case"navigate_tree":if(this.inner.isBashRunning)throw Error("Cannot navigate while a shell command is running");return{cancelled:(await this.inner.navigateTree(a.targetId,{})).cancelled};case"set_thinking_level":{let b=a.level;return this.inner.setThinkingLevel(b),"xhigh"===b&&this.inner.model?.compat?.thinkingFormat==="deepseek"&&this.inner.agent?.state&&(this.inner.agent.state.thinkingLevel="xhigh"),(0,n.mD)(),null}case"compact":try{return await this.withFinalRunningNotification(()=>this.inner.compact(a.customInstructions))}finally{(0,n.mD)()}case"set_session_name":{let b=a.name?.trim();if(!b)throw Error("Session name cannot be empty");return this.inner.setSessionName(b),(0,n.mD)(),null}case"get_session_stats":return{...this.inner.getSessionStats(),sessionName:this.inner.sessionManager.getSessionName()};case"get_last_assistant_text":return{text:this.inner.getLastAssistantText()??""};case"set_auto_compaction":return this.inner.setAutoCompactionEnabled(a.enabled),null;case"clear_queue":return this.inner.clearQueue();case"steer":{let b=a.images;return await this.inner.steer(a.message,b?.length?b:void 0),null}case"follow_up":{let b=a.images;return await this.inner.followUp(a.message,b?.length?b:void 0),null}case"get_tools":{let a=this.inner.getAllTools(),b=new Set(this.inner.getActiveToolNames());return a.map(a=>({name:a.name,description:a.description,active:b.has(a.name)}))}case"get_commands":{let a=[];for(let b of this.inner.extensionRunner.getRegisteredCommands())a.push({name:b.invocationName,description:b.description,source:"extension",sourceInfo:b.sourceInfo});for(let b of this.inner.promptTemplates)a.push({name:b.name,description:b.description,source:"prompt",sourceInfo:b.sourceInfo});for(let b of this.inner.resourceLoader.getSkills().skills)a.push({name:`skill:${b.name}`,description:b.description,source:"skill",sourceInfo:b.sourceInfo});return{commands:a}}case"set_tools":{let b=a.toolNames;return this.setForceEmptySystemPrompt(0===b.length),this.inner.setActiveToolsByName(s(this.inner,b)),this.applyForcedEmptySystemPrompt(),null}case"reload":return await this.waitForExtensionsBound(),this.extensionStatuses.clear(),this.resetExtensionWidgetsForReload(),this.syncProjectTrust(),await this.inner.reload(),"function"!=typeof this.inner.bindExtensions&&this.inner.extensionRunner.setUIContext?.(this.createExtensionUiContext(),"rpc"),this.applyForcedEmptySystemPrompt(),(0,k.kn)(),{success:!0};case"abort_compaction":return this.inner.abortCompaction(),null;case"extension_ui_response":return this.resolveExtensionUiResponse(a),null;case"extension_ui_input":return this.handleExtensionUiInput(a.id,a.data),null;case"set_auto_retry":return this.inner.setAutoRetryEnabled(a.enabled),null;case"bash":{if(this.pendingPromptCount>0||this.inner.isStreaming||this.inner.isCompacting||this.inner.isBashRunning)throw Error("Cannot run a shell command while the session is busy");let b=this.inner.executeBash(a.command,void 0,{excludeFromContext:a.excludeFromContext,operations:(0,m.J1)({shellPath:this.inner.settingsManager.getShellPath()})});try{return await b}finally{this.resetIdleTimer(),(0,n.mD)()}}case"abort_bash":return this.inner.abortBash(),null;default:throw Error(`Unsupported command: ${b}`)}}destroy(){if(this._alive){for(let a of(this._alive=!1,this.idleTimer&&clearTimeout(this.idleTimer),this.inner.isBashRunning&&this.inner.abortBash(),this.unsubscribe?.(),this.pendingUiResponses.values()))a.cancel();for(let a of Array.from(this.activeCustomUis.keys()))this.closeCustomUi(a,void 0);this.pendingUiResponses.clear(),this.pendingUiRequests.clear(),this.clearExtensionWidgets(!1);try{this.inner.dispose()}finally{this.onDestroyCallback?.()}}}async shutdown(){return this.shutdownPromise?this.shutdownPromise:this._alive?(this.shutdownPromise=(async()=>{try{try{await this.waitForExtensionsBound()}catch(a){console.error("[pi-web] extension binding failed before session shutdown:",a instanceof Error?a.message:a)}await this.inner.extensionRunner.emit?.({type:"session_shutdown",reason:"quit"})}finally{this.destroy()}})(),this.shutdownPromise):void 0}resolveExtensionUiResponse(a){let b=this.pendingUiResponses.get(a.id);b&&b.resolve(a)}getExtensionStatuses(){return Array.from(this.extensionStatuses,([a,b])=>({key:a,text:b}))}getExtensionWidgets(){return Array.from(this.extensionWidgets.values())}nextExtensionWidgetGeneration(a){let b=(this.extensionWidgetGenerations.get(a)??0)+1;return this.extensionWidgetGenerations.set(a,b),b}disposeExtensionWidgetComponent(a){if(!a||"object"!=typeof a&&"function"!=typeof a)return;let b=a.dispose;if("function"==typeof b)try{b.call(a)}catch{}}emitExtensionWidgetClear(a){this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"setWidget",widgetKey:a,widgetLines:void 0,widgetPlacement:void 0})}clearExtensionWidget(a,b=!0){let c=this.nextExtensionWidgetGeneration(a),d=this.activeExtensionWidgets.get(a);return this.activeExtensionWidgets.delete(a),this.extensionWidgets.delete(a),d&&this.disposeExtensionWidgetComponent(d.component),this.extensionWidgetGenerations.get(a)!==c||b&&this.emitExtensionWidgetClear(a),c}clearExtensionWidgets(a){for(let b of new Set([...this.extensionWidgets.keys(),...this.activeExtensionWidgets.keys()]))this.clearExtensionWidget(b,a)}resetExtensionWidgetsForReload(){this.extensionWidgetsResetting=!0;try{for(let a of[...this.activeExtensionWidgets.keys()])this.clearExtensionWidget(a);this.extensionWidgets.clear()}finally{this.extensionWidgetsResetting=!1}}emitExtensionWidgetError(a,b){this.emit({type:"extension_error",extensionPath:`extension-widget:${a}`,event:"setWidget",error:b instanceof Error?b.message:String(b)})}failExtensionWidget(a,b,c,d,e){if(this.extensionWidgetGenerations.get(a)!==b)return void this.disposeExtensionWidgetComponent(e);let f=this.activeExtensionWidgets.get(a),g=!d;f?.generation===b?(g=f.rendered||!f.clearEmitted,this.activeExtensionWidgets.delete(a),this.disposeExtensionWidgetComponent(f.component)):this.disposeExtensionWidgetComponent(e),this.extensionWidgetGenerations.get(a)!==b||(this.extensionWidgets.delete(a),g&&this.emitExtensionWidgetClear(a)),this.emitExtensionWidgetError(a,c)}renderExtensionWidget(a){let b;if(this.activeExtensionWidgets.get(a.key)!==a||this.extensionWidgetGenerations.get(a.key)!==a.generation)return;try{b=a.component.render(q.p1)}catch(b){this.failExtensionWidget(a.key,a.generation,b,a.clearEmitted);return}if(!Array.isArray(b)||!b.every(a=>"string"==typeof a))return void this.failExtensionWidget(a.key,a.generation,Error("Extension widget render must return string[]"),a.clearEmitted);if(this.activeExtensionWidgets.get(a.key)!==a||this.extensionWidgetGenerations.get(a.key)!==a.generation)return;let c=b;this.extensionWidgets.set(a.key,{key:a.key,lines:c,placement:a.placement}),a.rendered=!0,this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"setWidget",widgetKey:a.key,widgetLines:c,widgetPlacement:a.placement})}setExtensionWidgetFactory(a,b,c){let d,e=this.extensionWidgets.has(a)||this.activeExtensionWidgets.has(a),f=this.clearExtensionWidget(a,e);if(this.extensionWidgetGenerations.get(a)!==f)return;let g=(0,q.TQ)(()=>{let b=this.activeExtensionWidgets.get(a);b?.generation===f&&this.renderExtensionWidget(b)},q.p1);try{d=b(g,z)}catch(b){this.failExtensionWidget(a,f,b,e);return}if(this.extensionWidgetGenerations.get(a)!==f)return void this.disposeExtensionWidgetComponent(d);if(!d||"object"!=typeof d&&"function"!=typeof d||"function"!=typeof d.render)return void this.failExtensionWidget(a,f,Error("Extension widget factory must return a component with render(width)"),e,d);let h={key:a,component:d,placement:c?.placement??"aboveEditor",generation:f,clearEmitted:e,rendered:!1};this.activeExtensionWidgets.set(a,h),this.renderExtensionWidget(h)}getCustomUiWidth(a){if(!a||"object"!=typeof a)return q.p1;let b=a.overlayOptions,c="function"==typeof b?b():b;if(!c||"object"!=typeof c)return q.p1;let d=c.width;return"number"==typeof d&&Number.isFinite(d)?Math.max(40,Math.min(140,Math.round(d))):92}emitCustomUiRender(a,b){let c;try{c=b.component.render(b.width)}catch(a){c=[`Extension custom UI render failed: ${a instanceof Error?a.message:String(a)}`]}let d={type:"extension_ui_request",id:a,method:"custom",lines:c};this.pendingUiRequests.set(a,d),this.emit(d)}closeCustomUi(a,b){let c=this.activeCustomUis.get(a);if(c&&!c.settled){c.settled=!0,this.activeCustomUis.delete(a),this.pendingUiRequests.delete(a);try{c.component.dispose?.()}catch{}this.emit({type:"extension_ui_request",id:a,method:"custom",lines:[],closed:!0}),c.resolve(b)}}handleExtensionUiInput(a,b){let c=this.activeCustomUis.get(a);if(c&&"string"==typeof b)try{c.component.handleInput?.(b),this.activeCustomUis.has(a)&&this.emitCustomUiRender(a,c)}catch(b){this.closeCustomUi(a,void 0),this.emit({type:"extension_error",extensionPath:`custom-ui:${a}`,event:"custom_ui_input",error:b instanceof Error?b.message:String(b)})}}requestExtensionCustomUi(a,b){if("function"!=typeof a)return Promise.resolve(void 0);let c=(0,g.randomUUID)(),d=this.getCustomUiWidth(b);return new Promise(b=>{let e=!1,f=(0,q.TQ)(()=>{let a=this.activeCustomUis.get(c);a&&this.emitCustomUiRender(c,a)},d),g=a=>{e||(e=!0,b(a))},h=a=>{this.activeCustomUis.has(c)?this.closeCustomUi(c,a):g(a)};Promise.resolve().then(()=>a(f,z,A,h)).then(a=>{if(e){try{a?.dispose?.()}catch{}return}if(!a||"object"!=typeof a||"function"!=typeof a.render)return void g(void 0);let b={component:a,width:d,resolve:a=>g(a),settled:!1};this.activeCustomUis.set(c,b),this.emitCustomUiRender(c,b)}).catch(a=>{e||(this.emit({type:"extension_error",extensionPath:`custom-ui:${c}`,event:"custom_ui",error:a instanceof Error?a.message:String(a)}),g(void 0))})})}requestExtensionUi(a,b,c,d,e){if(e?.aborted)return Promise.resolve(b);let f=(0,g.randomUUID)(),h={type:"extension_ui_request",id:f,...a,...d?{timeout:d,expiresAt:Date.now()+d}:{}};return new Promise(a=>{let g,i=()=>{g&&clearTimeout(g),e?.removeEventListener("abort",k),this.pendingUiRequests.delete(f),this.pendingUiResponses.delete(f)},j=b=>{i(),a(b)},k=()=>j(b);d&&(g=setTimeout(()=>j(b),d)),e?.addEventListener("abort",k,{once:!0}),this.pendingUiRequests.set(f,h),this.pendingUiResponses.set(f,{resolve:a=>j(c(a)),cancel:()=>j(b)}),this.emit(h)})}createExtensionUiContext(){return{select:(a,b,c)=>this.requestExtensionUi({method:"select",title:a,options:b,...c?.timeout?{timeout:c.timeout}:{}},void 0,a=>"value"in a?a.value:void 0,c?.timeout,c?.signal),confirm:(a,b,c)=>this.requestExtensionUi({method:"confirm",title:a,message:b,...c?.timeout?{timeout:c.timeout}:{}},!1,a=>"confirmed"in a&&a.confirmed,c?.timeout,c?.signal),input:(a,b,c)=>this.requestExtensionUi({method:"input",title:a,...void 0!==b?{placeholder:b}:{},...c?.timeout?{timeout:c.timeout}:{}},void 0,a=>"value"in a?a.value:void 0,c?.timeout,c?.signal),editor:(a,b,c)=>this.requestExtensionUi({method:"editor",title:a,...void 0!==b?{prefill:b}:{},...c?.timeout?{timeout:c.timeout}:{}},void 0,a=>"value"in a?a.value:void 0,c?.timeout,c?.signal),notify:(a,b)=>{this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"notify",message:a,notifyType:b})},onTerminalInput:()=>()=>{},setStatus:(a,b)=>{void 0===b?this.extensionStatuses.delete(a):this.extensionStatuses.set(a,b),this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"setStatus",statusKey:a,statusText:b})},setWorkingMessage:()=>{},setWorkingVisible:()=>{},setWorkingIndicator:()=>{},setHiddenThinkingLabel:()=>{},setWidget:(a,b,c)=>{if(!this._alive||this.extensionWidgetsResetting)return;if("function"==typeof b)return void this.setExtensionWidgetFactory(a,b,c);if(void 0!==b&&!Array.isArray(b))return;if(void 0===b)return void this.clearExtensionWidget(a);let d=this.activeExtensionWidgets.has(a)?this.clearExtensionWidget(a):this.nextExtensionWidgetGeneration(a);this.extensionWidgetGenerations.get(a)===d&&(this.extensionWidgets.set(a,{key:a,lines:b,placement:c?.placement??"aboveEditor"}),this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"setWidget",widgetKey:a,widgetLines:b,widgetPlacement:c?.placement}))},setFooter:()=>{},setHeader:()=>{},setTitle:a=>{this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"setTitle",title:a})},custom:(a,b)=>this.requestExtensionCustomUi(a,b),pasteToEditor:a=>{this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"set_editor_text",text:a})},setEditorText:a=>{this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"set_editor_text",text:a})},getEditorText:()=>"",addAutocompleteProvider:()=>{},setEditorComponent:()=>{},getEditorComponent:()=>void 0,get theme(){return z},getAllThemes:()=>[],getTheme:()=>void 0,setTheme:()=>({success:!1,error:"Theme switching is not supported in Pi Web extension UI yet"}),getToolsExpanded:()=>!1,setToolsExpanded:()=>{}}}createExtensionCommandContextActions(){return{waitForIdle:async()=>{let a=this.inner.agent;await a.waitForIdle?.()},newSession:async()=>({cancelled:!0}),fork:async()=>({cancelled:!0}),navigateTree:async(a,b)=>({cancelled:(await this.inner.navigateTree(a,{summarize:b?.summarize})).cancelled}),switchSession:async()=>({cancelled:!0}),reload:async()=>{this.extensionStatuses.clear(),this.resetExtensionWidgetsForReload(),this.syncProjectTrust(),await this.inner.reload({beforeSessionStart:()=>{this.inner.extensionRunner.setUIContext?.(this.createExtensionUiContext(),"rpc")}}),this.applyForcedEmptySystemPrompt()}}}syncProjectTrust(){let a=(0,o.Y1)(this.cwd,(0,e.getAgentDir)());this.inner.settingsManager.setProjectTrusted(a.trusted)}}function t(){if(!globalThis.__piSessions){globalThis.__piSessions=new Map;let a=()=>globalThis.__piSessions?.forEach(a=>a.destroy());process.once("exit",a),process.once("SIGINT",a),process.once("SIGTERM",a)}return globalThis.__piSessions}function u(){let a=new Set;for(let[b,c]of t())c.isRunning()&&a.add(c.sessionId||b);return[...a]}async function v(a,b,c,d={}){let f,g,j,{toolNames:q,initialModel:r,thinkingLevel:u}=d,w=t(),x=(globalThis.__piStartLocks||(globalThis.__piStartLocks=new Map),globalThis.__piStartLocks),y=w.get(a);if(y?.isAlive())return{session:y,realSessionId:a};let z=x.get(a);if(z)return z;if(b)f=e.SessionManager.open(b,void 0);else{if(!c)throw Error("cwd is required for a new session");let b=a.length>0&&!a.startsWith("__");f=e.SessionManager.create(c,void 0,b?{id:a}:void 0),b&&function(a,b){let c=a.getSessionFile();if(!c||(0,h.existsSync)(c))return;let d=a.getHeader();if(!d)return;let e=[d,...a.getEntries()].map(a=>JSON.stringify(a)).join("\n")+"\n";(0,h.writeFileSync)(c,e,{encoding:"utf8",flag:"wx"}),a.flushed=!0,(0,n.O8)(b,c)}(f,a)}let A=f.getCwd(),C=(globalThis.__piStartingSessionCwds||(globalThis.__piStartingSessionCwds=new Map),g=globalThis.__piStartingSessionCwds,j=function(a){let b=(0,i.resolve)(a);try{return(0,h.realpathSync)(b)}catch{return b}}(A),g.set(j,(g.get(j)??0)+1),()=>{let a=(g.get(j)??1)-1;a>0?g.set(j,a):g.delete(j)}),D=(async()=>{let a;(0,e.initTheme)();let b=(0,e.getAgentDir)();void 0!==q&&(a=0===q.length?[]:void 0);let c=(0,o.Fk)(A,b),d=e.SettingsManager.create(A,b),g=await (0,e.createAgentSessionServices)({cwd:A,agentDir:b,settingsManager:d,resourceLoaderOptions:{extensionFactories:[(0,m.eD)({cwd:A,settings:d})],extensionsOverride:m.Ds},...c?{resourceLoaderReloadOptions:c}:{}}),h=await (0,l.p)(g.modelRuntime,g.settingsManager.getEnabledModels()),i=g.settingsManager.getDefaultProvider(),j=g.settingsManager.getDefaultModel(),t=f.getBranch().some(a=>"message"===a.type)?{scopedModels:[...h.scopedModels]}:(0,l.I)(h,{...r?{requestedModel:r}:{},...i&&j?{defaultModel:{provider:i,modelId:j}}:{},...u?{thinkingLevel:u}:{}}),{session:v}=await (0,e.createAgentSessionFromServices)({services:g,sessionManager:f,...t.model?{model:t.model}:{},...t.thinkingLevel?{thinkingLevel:t.thinkingLevel}:{},...t.scopedModels.length>0?{scopedModels:t.scopedModels}:{},...void 0!==a?{tools:a}:{}});(await (0,p.o)(g.settingsManager,{...r?{model:r}:{},...u?{thinkingLevel:u}:{}},{...v.model?{model:{provider:v.model.provider,modelId:v.model.id}}:{},thinkingLevel:v.thinkingLevel,supportsThinking:v.supportsThinking()})).modelDefaultChanged&&(0,k.kn)(),q&&q.length>0&&v.setActiveToolsByName(s(v,q));let x=new B(v);q?.length===0&&x.setForceEmptySystemPrompt(!0),x.start();let y=v.sessionId,z=v.sessionFile;return z&&(0,n.O8)(y,z),x.onDestroy(()=>w.delete(y)),w.set(y,x),x.beginExtensionBinding({forceEmptySystemPrompt:q?.length===0}),{session:x,realSessionId:y}})().finally(()=>{x.delete(a),C()});return x.set(a,D),D}d()}catch(a){d(a)}})},14916:(a,b,c)=>{c.d(b,{C1:()=>d});let d=["bash","read","edit","write","grep","find","ls"]},15253:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{Fk:()=>h,Y1:()=>g});var e=c(75430),f=a([e]);function g(a,b){if(!(a&&(0,e.hasTrustRequiringProjectResources)(a)))return{requiresTrust:!1,trusted:!0};let c=new e.ProjectTrustStore(b);return{requiresTrust:!0,trusted:!0===c.get(a)}}function h(a,b){if(!g(a,b).requiresTrust)return;let c=new e.ProjectTrustStore(b);return{resolveProjectTrust:async()=>!0===c.get(a)}}e=(f.then?(await f)():f)[0],d()}catch(a){d(a)}})},18437:(a,b,c)=>{c.d(b,{kc:()=>d});function d(a){if(void 0===a)return null;if(!Array.isArray(a))return"images must be an array";if(a.length>10)return"A message can include at most 10 images";for(let b of a){if(!b||"object"!=typeof b||"image"!==b.type)return"Each attachment must be an image";if(!function(a){if(!a||"object"!=typeof a||"string"!=typeof a.data||"string"!=typeof a.mimeType||!a.mimeType.startsWith("image/"))return!1;let b=function(a){if(!a||a.length%4!=0)return null;let b=a.endsWith("==")?2:+!!a.endsWith("="),c=a.length-b;for(let b=0;b<c;b+=1){var d;if(!((d=a.charCodeAt(b))>=65&&d<=90||d>=97&&d<=122||d>=48&&d<=57||43===d||47===d))return null}for(let b=c;b<a.length;b+=1)if("="!==a[b])return null;return a.length/4*3-b}(a.data);return null!==b&&b<=0xa00000}(b))return"Each image must be valid base64 image data of 10MB or smaller"}return null}},32105:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{Wz:()=>i,bJ:()=>l,s4:()=>k});var e=c(75430),f=c(69453),g=a([e,f]);function h(a){return"string"==typeof a?a:Array.isArray(a)?a.filter(a=>!!a&&"object"==typeof a&&"text"in a).map(a=>a.text).join("\n"):""}async function i(a){try{let b=await (0,f.os)(a);if(!b)return null;let c=e.SessionManager.open(b).getEntries().filter(a=>"message"===a.type),d=!1,g=0,i=[];for(let a of c.slice(-4)){let b=a.message,c="number"==typeof b.timestamp?b.timestamp:new Date(a.timestamp).getTime();if(Number.isNaN(c)||(g=Math.max(g,c)),"assistant"===b.role){b.errorMessage&&(d=!0);let a=h(b.content);a&&i.push(`AI: ${a.slice(0,400)}`)}else if("toolResult"===b.role){b.isError&&(d=!0);let a=b.details;a&&"number"==typeof a.exitCode&&0!==a.exitCode&&(d=!0);let c=h(b.content);c&&i.push(`工具 ${b.toolName}: ${c.slice(0,300)}`)}else if("user"===b.role){let a=h(b.content);a&&i.push(`用户: ${a.slice(0,300)}`)}}return{failure:d,recentText:i.join("\n").slice(0,4e3),lastActivityMs:g}}catch(b){return console.error(`[task-scheduler] 读会话快照失败 ${a}:`,b instanceof Error?b.message:b),null}}async function j(a,b,c){let d=null,f=setTimeout(()=>{if(d&&"function"==typeof d.dispose)try{d.dispose()}catch{}},9e4);try{(0,e.initTheme)();let f=(0,e.getAgentDir)(),g=e.SettingsManager.create(a,f),h=await (0,e.createAgentSessionServices)({cwd:a,agentDir:f,settingsManager:g,resourceLoaderOptions:{extensionFactories:[]}}),i=e.SessionManager.inMemory(a);d=(await (0,e.createAgentSessionFromServices)({services:h,sessionManager:i,noTools:"all"})).session,await d.prompt(`${b}
1
+ "use strict";exports.id=542,exports.ids=[542],exports.modules={7535:(a,b,c)=>{c.d(b,{z:()=>f});var d=c(76760),e=c.n(d);function f(a,b=process.platform){if(!a)return a;let c="win32"===b?e().win32:e().posix,d=c.normalize(a),g=c.parse(d).root.length,h=d.length;for(;h>g&&d[h-1]===c.sep;)h--;let i=d.slice(0,h);return"win32"===b?i.toLowerCase():i}},7561:(a,b,c)=>{c.d(b,{$:()=>f});var d=c(76760),e=c.n(d);function f(a,b=process.platform){let c="win32"===b?e().win32.normalize(a):e().posix.normalize(a);return"win32"===b?c.toLowerCase():c}},9210:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{X:()=>l});var e=c(29021),f=c(79748),g=c(33873),h=c(75430),i=a([h]);function j(a){if(!a.trim())return null;try{return JSON.parse(a)}catch{return null}}function k(a){let b=a.content;return"string"==typeof b?b:Array.isArray(b)?b.filter(a=>a&&"text"===a.type&&"string"==typeof a.text).map(a=>a.text).join(" "):""}h=(i.then?(await i)():i)[0];let l={scan:async function(a){let b,c=a??(0,g.join)((0,h.getAgentDir)(),"sessions");try{b=(await (0,f.readdir)(c,{withFileTypes:!0})).filter(a=>a.isDirectory()||a.isSymbolicLink()).map(a=>(0,g.join)(c,a.name))}catch{return[]}let d=[];for(let a of b)try{for(let b of(await (0,f.readdir)(a)))b.endsWith(".jsonl")&&d.push((0,g.join)(a,b))}catch{}let i=[];for(let a of d){let b=function(a){let b;try{b=(0,e.statSync)(a)}catch{return null}if(!b.isFile()||0===b.size)return null;let c=function(a,b){let c=Math.min(4096,b),d="",f=(0,e.openSync)(a,"r");try{let a=null,g="";for(;;){let h=Buffer.alloc(c);(0,e.readSync)(f,h,0,c,0);let i=h.toString("utf8"),l=i.lastIndexOf("\n"),m=-1===l?i.length:l+1;for(let b of(d+=i.slice(0,m)).split("\n")){let c=j(b);if(c){if(!a){if("session"!==c.type)return null;a=c;continue}if("message"===c.type&&c.message?.role==="user"){let a=k(c.message).trim();if(a){g=a.slice(0,300);break}}}}if(!a)return null;if(g||c>=49152||c>=b||(c=Math.min(2*c,49152,b))<=0)break}return{header:a,firstMessage:g}}finally{(0,e.closeSync)(f)}}(a,b.size);if(!c)return null;let{header:d,firstMessage:f}=c,g="string"==typeof d.id?d.id:"";if(!g)return null;let h=new Date("string"==typeof d.timestamp?d.timestamp:"");Number.isNaN(h.getTime())&&h.setTime(b.mtime.getTime());let i=function(a,b){let c={name:void 0,lastReply:""};if(b<=0)return c;let d=(0,e.openSync)(a,"r");try{let a=b;for(let b=0;b<256&&a>0;b++){let b=Math.max(0,a-65536),f=a-b,g=Buffer.alloc(f);(0,e.readSync)(d,g,0,f,b);let h=g.toString("utf8").split("\n");for(let a=h.length-1;a>=1;a--){if(void 0!==c.name&&c.lastReply)continue;let b=j(h[a]);if(b){if(void 0===c.name&&"session_info"===b.type&&"string"==typeof b.name){let a=b.name.trim();a&&(c.name=a)}else if(!c.lastReply&&"message"===b.type&&b.message?.role==="assistant"){let a=k(b.message).trim();a&&(c.lastReply=a)}if(void 0!==c.name&&c.lastReply)break}}a=b}return c}finally{(0,e.closeSync)(d)}}(a,b.size);return{path:a,id:g,cwd:"string"==typeof d.cwd?d.cwd:"",name:i.name,created:h,modified:b.mtime,firstMessage:f||"(no messages)",lastReply:i.lastReply,parentSessionPath:"string"==typeof d.parentSession?d.parentSession:void 0}}(a);b&&i.push(b)}return i.sort((a,b)=>b.modified.getTime()-a.modified.getTime()),i}};d()}catch(a){d(a)}})},14916:(a,b,c)=>{c.d(b,{C1:()=>d});let d=["bash","read","edit","write","grep","find","ls"]},15253:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{Fk:()=>h,Y1:()=>g});var e=c(75430),f=a([e]);function g(a,b){if(!(a&&(0,e.hasTrustRequiringProjectResources)(a)))return{requiresTrust:!1,trusted:!0};let c=new e.ProjectTrustStore(b);return{requiresTrust:!0,trusted:!0===c.get(a)}}function h(a,b){if(!g(a,b).requiresTrust)return;let c=new e.ProjectTrustStore(b);return{resolveProjectTrust:async()=>!0===c.get(a)}}e=(f.then?(await f)():f)[0],d()}catch(a){d(a)}})},18437:(a,b,c)=>{c.d(b,{kc:()=>d});function d(a){if(void 0===a)return null;if(!Array.isArray(a))return"images must be an array";if(a.length>10)return"A message can include at most 10 images";for(let b of a){if(!b||"object"!=typeof b||"image"!==b.type)return"Each attachment must be an image";if(!function(a){if(!a||"object"!=typeof a||"string"!=typeof a.data||"string"!=typeof a.mimeType||!a.mimeType.startsWith("image/"))return!1;let b=function(a){if(!a||a.length%4!=0)return null;let b=a.endsWith("==")?2:+!!a.endsWith("="),c=a.length-b;for(let b=0;b<c;b+=1){var d;if(!((d=a.charCodeAt(b))>=65&&d<=90||d>=97&&d<=122||d>=48&&d<=57||43===d||47===d))return null}for(let b=c;b<a.length;b+=1)if("="!==a[b])return null;return a.length/4*3-b}(a.data);return null!==b&&b<=0xa00000}(b))return"Each image must be valid base64 image data of 10MB or smaller"}return null}},32105:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{Wz:()=>i,bJ:()=>l,s4:()=>k});var e=c(75430),f=c(69453),g=a([e,f]);function h(a){return"string"==typeof a?a:Array.isArray(a)?a.filter(a=>!!a&&"object"==typeof a&&"text"in a).map(a=>a.text).join("\n"):""}async function i(a){try{let b=await (0,f.os)(a);if(!b)return null;let c=e.SessionManager.open(b).getEntries().filter(a=>"message"===a.type),d=!1,g=0,i=[];for(let a of c.slice(-4)){let b=a.message,c="number"==typeof b.timestamp?b.timestamp:new Date(a.timestamp).getTime();if(Number.isNaN(c)||(g=Math.max(g,c)),"assistant"===b.role){b.errorMessage&&(d=!0);let a=h(b.content);a&&i.push(`AI: ${a.slice(0,400)}`)}else if("toolResult"===b.role){b.isError&&(d=!0);let a=b.details;a&&"number"==typeof a.exitCode&&0!==a.exitCode&&(d=!0);let c=h(b.content);c&&i.push(`工具 ${b.toolName}: ${c.slice(0,300)}`)}else if("user"===b.role){let a=h(b.content);a&&i.push(`用户: ${a.slice(0,300)}`)}}return{failure:d,recentText:i.join("\n").slice(0,4e3),lastActivityMs:g}}catch(b){return console.error(`[task-scheduler] 读会话快照失败 ${a}:`,b instanceof Error?b.message:b),null}}async function j(a,b,c){let d=null,f=setTimeout(()=>{if(d&&"function"==typeof d.dispose)try{d.dispose()}catch{}},9e4);try{(0,e.initTheme)();let f=(0,e.getAgentDir)(),g=e.SettingsManager.create(a,f),h=await (0,e.createAgentSessionServices)({cwd:a,agentDir:f,settingsManager:g,resourceLoaderOptions:{extensionFactories:[]}}),i=e.SessionManager.inMemory(a);d=(await (0,e.createAgentSessionFromServices)({services:h,sessionManager:i,noTools:"all"})).session,await d.prompt(`${b}
2
2
 
3
3
  ${c}`,{expandPromptTemplates:!1,source:"rpc"}),await d.waitForIdle();let j=d.getLastAssistantText()??"";return function(a){let b=a.indexOf("{");if(-1===b)return null;let c=0;for(let d=b;d<a.length;d++)if("{"===a[d])c+=1;else if("}"===a[d]&&(c-=1,0===c))try{return JSON.parse(a.slice(b,d+1))}catch{break}return null}(j)??null}catch(a){return console.error("[audit-session] 判定失败:",a instanceof Error?a.message:a),null}finally{if(clearTimeout(f),d)try{d.dispose()}catch{}}}[e,f]=g.then?(await g)():g;let m=`你是任务卡审核员。下面给出任务卡信息与执行会话最后几条消息,判断任务执行结果:
4
4
  - done: 任务已正确完成
@@ -14,18 +14,23 @@ ${c}`,{expandPromptTemplates:!1,source:"rpc"}),await d.waitForIdle();let j=d.get
14
14
  - asking: AI 在提问等待用户输入
15
15
  - normal: 正常运行中(长任务)
16
16
 
17
- 只输出一行 JSON(不要输出其他文字):{"kind":"sync_server|infinite_loop|rate_limit|error|asking|normal","detail":"简短说明"}`;async function l(a){let b=[`【任务卡 #${a.cardNumber}】${a.cardName}`,`任务描述:${a.taskDescription||"(空)"}`,"\n执行会话最后几条消息:",a.recentMessages||"(无消息)"].join("\n"),c=await j(a.cwd,n,b);return c&&["sync_server","infinite_loop","rate_limit","error","asking","normal"].includes(c.kind)?{kind:c.kind,detail:c.detail??""}:null}d()}catch(a){d(a)}})},48817:(a,b,c)=>{c.d(b,{BH:()=>p,CU:()=>o,Kg:()=>t,O7:()=>q,XJ:()=>k,hG:()=>s,uZ:()=>n,w0:()=>l});var d=c(55511),e=c(90596);let f=new Set(["draft","todo"]),g=new Set(["not_started","running","review","done","failed","abandoned","waiting_reply"]);function h(a){return{...a,useWorktree:1===a.useWorktree,attachments:JSON.parse(a.attachments)}}let i="id, board_id AS boardId, project_key AS projectKey, number, name, description, ready_status AS readyStatus, exec_status AS execStatus, priority, due, attachments, cwd, use_worktree AS useWorktree, max_retries AS maxRetries, retry_count AS retryCount, session_id AS sessionId, created, updated";function j(a){return(0,e.Lf)().prepare(`SELECT ${i} FROM task_cards WHERE id = ?`).get(a)}function k(a){let b=j(a);return b?h(b):void 0}function l(a,b){let c=(0,e.Lf)(),d=j(a);if(!d)return null;let i=[],k=[],l=(a,b)=>{i.push(`${a} = ?`),k.push(b)};if(void 0!==b.name){let a=b.name.trim();if(!a)throw Error("name must not be empty");l("name",a)}if(void 0!==b.description&&l("description",b.description),void 0!==b.readyStatus){var m=b.readyStatus;if(void 0!==m&&!f.has(m))throw Error(`invalid readyStatus: ${String(m)}`);l("ready_status",b.readyStatus)}if(void 0!==b.execStatus){var n=b.execStatus;if(void 0!==n&&!g.has(n))throw Error(`invalid execStatus: ${String(n)}`);l("exec_status",b.execStatus)}return(void 0!==b.priority&&l("priority",b.priority),void 0!==b.due&&l("due",b.due),void 0!==b.attachments&&l("attachments",JSON.stringify(b.attachments)),void 0!==b.cwd&&l("cwd",b.cwd),void 0!==b.useWorktree&&l("use_worktree",+!!b.useWorktree),void 0!==b.maxRetries&&l("max_retries",b.maxRetries),void 0!==b.sessionId&&l("session_id",b.sessionId),void 0!==b.retryCount&&l("retry_count",b.retryCount),0===i.length)?h(d):(l("updated",Date.now()),c.prepare(`UPDATE task_cards SET ${i.join(", ")} WHERE id = ?`).run(...k,a),h(j(a)))}function m(a){var b;for(let c of(b=a.id,(0,e.Lf)().prepare("SELECT id, card_id AS cardId, target_card_id AS targetCardId, kind, created FROM task_card_links WHERE card_id = ? ORDER BY created, rowid").all(b))){if("prerequisite"!==c.kind)continue;let a=k(c.targetCardId);if(a&&"done"!==a.execStatus)return!1}return!0}function n(){return(0,e.Lf)().prepare(`SELECT ${i} FROM task_cards
17
+ 只输出一行 JSON(不要输出其他文字):{"kind":"sync_server|infinite_loop|rate_limit|error|asking|normal","detail":"简短说明"}`;async function l(a){let b=[`【任务卡 #${a.cardNumber}】${a.cardName}`,`任务描述:${a.taskDescription||"(空)"}`,"\n执行会话最后几条消息:",a.recentMessages||"(无消息)"].join("\n"),c=await j(a.cwd,n,b);return c&&["sync_server","infinite_loop","rate_limit","error","asking","normal"].includes(c.kind)?{kind:c.kind,detail:c.detail??""}:null}d()}catch(a){d(a)}})},48817:(a,b,c)=>{c.d(b,{$j:()=>p,BH:()=>r,CU:()=>q,Im:()=>o,Kg:()=>v,O7:()=>s,XJ:()=>k,hG:()=>u,uZ:()=>n,w0:()=>l});var d=c(55511),e=c(90596);let f=new Set(["draft","todo"]),g=new Set(["not_started","running","review","done","failed","abandoned","waiting_reply"]);function h(a){return{...a,useWorktree:1===a.useWorktree,attachments:JSON.parse(a.attachments)}}let i="id, board_id AS boardId, project_key AS projectKey, number, name, description, ready_status AS readyStatus, exec_status AS execStatus, priority, due, attachments, cwd, use_worktree AS useWorktree, max_retries AS maxRetries, retry_count AS retryCount, session_id AS sessionId, dispatch_token AS dispatchToken, created, updated";function j(a){return(0,e.Lf)().prepare(`SELECT ${i} FROM task_cards WHERE id = ?`).get(a)}function k(a){let b=j(a);return b?h(b):void 0}function l(a,b){let c=(0,e.Lf)(),d=j(a);if(!d)return null;let i=[],k=[],l=(a,b)=>{i.push(`${a} = ?`),k.push(b)};if(void 0!==b.name){let a=b.name.trim();if(!a)throw Error("name must not be empty");l("name",a)}if(void 0!==b.description&&l("description",b.description),void 0!==b.readyStatus){var m=b.readyStatus;if(void 0!==m&&!f.has(m))throw Error(`invalid readyStatus: ${String(m)}`);l("ready_status",b.readyStatus)}if(void 0!==b.execStatus){var n=b.execStatus;if(void 0!==n&&!g.has(n))throw Error(`invalid execStatus: ${String(n)}`);l("exec_status",b.execStatus)}return(void 0!==b.priority&&l("priority",b.priority),void 0!==b.due&&l("due",b.due),void 0!==b.attachments&&l("attachments",JSON.stringify(b.attachments)),void 0!==b.cwd&&l("cwd",b.cwd),void 0!==b.useWorktree&&l("use_worktree",+!!b.useWorktree),void 0!==b.maxRetries&&l("max_retries",b.maxRetries),void 0!==b.sessionId&&l("session_id",b.sessionId),void 0!==b.retryCount&&l("retry_count",b.retryCount),0===i.length)?h(d):(l("updated",Date.now()),c.prepare(`UPDATE task_cards SET ${i.join(", ")} WHERE id = ?`).run(...k,a),h(j(a)))}function m(a){var b;for(let c of(b=a.id,(0,e.Lf)().prepare("SELECT id, card_id AS cardId, target_card_id AS targetCardId, kind, created FROM task_card_links WHERE card_id = ? ORDER BY created, rowid").all(b))){if("prerequisite"!==c.kind)continue;let a=k(c.targetCardId);if(a&&"done"!==a.execStatus)return!1}return!0}function n(){return(0,e.Lf)().prepare(`SELECT ${i} FROM task_cards
18
18
  WHERE ready_status = 'todo' AND (exec_status = 'not_started' OR (exec_status = 'failed' AND retry_count < max_retries))
19
- ORDER BY priority DESC, number`).all().map(h).filter(m)}function o(){return(0,e.Lf)().prepare("SELECT COUNT(*) AS n FROM task_cards WHERE exec_status = 'running'").get().n}function p(){return(0,e.Lf)().prepare(`SELECT ${i} FROM task_cards WHERE exec_status = 'running' ORDER BY number`).all().map(h)}function q(a){let b=a.map(()=>"?").join(",");return(0,e.Lf)().prepare(`SELECT ${i} FROM task_cards WHERE exec_status IN (${b}) ORDER BY number`).all(...a).map(h)}function r(a){return{...a}}function s(a,b,c){let f=(0,d.randomUUID)(),g=Date.now();return(0,e.Lf)().prepare("INSERT INTO task_card_questions (id, card_id, session_id, question, status, created) VALUES (?, ?, ?, ?, 'pending', ?)").run(f,a,b,c,g),r((0,e.Lf)().prepare("SELECT id, card_id AS cardId, session_id AS sessionId, question, status, answer, created, answered FROM task_card_questions WHERE id = ?").get(f))}function t(){return(0,e.Lf)().prepare(`SELECT q.id, q.card_id AS cardId, q.session_id AS sessionId, q.question, q.status, q.answer, q.created, q.answered
19
+ AND dispatch_token IS NULL
20
+ ORDER BY priority DESC, number`).all().map(h).filter(m)}function o(a,b){return Number((0,e.Lf)().prepare(`UPDATE task_cards SET dispatch_token = ?1, updated = ?2
21
+ WHERE id = ?3
22
+ AND ready_status = 'todo'
23
+ AND (exec_status = 'not_started' OR (exec_status = 'failed' AND retry_count < max_retries))
24
+ AND dispatch_token IS NULL`).run(b,Date.now(),a).changes)>0}function p(a,b){(0,e.Lf)().prepare("UPDATE task_cards SET dispatch_token = NULL, updated = ?2 WHERE id = ?1 AND dispatch_token = ?3").run(a,Date.now(),b)}function q(){return(0,e.Lf)().prepare("SELECT COUNT(*) AS n FROM task_cards WHERE exec_status = 'running'").get().n}function r(){return(0,e.Lf)().prepare(`SELECT ${i} FROM task_cards WHERE exec_status = 'running' ORDER BY number`).all().map(h)}function s(a){let b=a.map(()=>"?").join(",");return(0,e.Lf)().prepare(`SELECT ${i} FROM task_cards WHERE exec_status IN (${b}) ORDER BY number`).all(...a).map(h)}function t(a){return{...a}}function u(a,b,c){let f=(0,d.randomUUID)(),g=Date.now();return(0,e.Lf)().prepare("INSERT INTO task_card_questions (id, card_id, session_id, question, status, created) VALUES (?, ?, ?, ?, 'pending', ?)").run(f,a,b,c,g),t((0,e.Lf)().prepare("SELECT id, card_id AS cardId, session_id AS sessionId, question, status, answer, created, answered FROM task_card_questions WHERE id = ?").get(f))}function v(){return(0,e.Lf)().prepare(`SELECT q.id, q.card_id AS cardId, q.session_id AS sessionId, q.question, q.status, q.answer, q.created, q.answered
20
25
  FROM task_card_questions q
21
26
  JOIN task_cards c ON c.id = q.card_id
22
27
  WHERE q.status = 'answered' AND c.exec_status = 'waiting_reply'
23
28
  AND q.id = (SELECT q2.id FROM task_card_questions q2 WHERE q2.card_id = q.card_id AND q2.status='answered' ORDER BY q2.answered DESC, q2.created DESC LIMIT 1)
24
- ORDER BY q.answered`).all().map(r)}},57856:(a,b,c)=>{c.d(b,{TQ:()=>e,p1:()=>d});let d=92;function e(a,b=d,c=40){return Object.freeze({terminal:Object.freeze({columns:b,rows:c,kittyProtocolActive:!1}),requestRender:a})}},60542:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{startTaskScheduler:()=>B});var e=c(29021),f=c(55511),g=c(75384),h=c(12144),i=c(69453),j=c(65562),k=c(14916),l=c(48817),m=c(32105),n=a([h,i,m]);[h,i,m]=n.then?(await n)():n;let D=new Map,E=new Map;function o(a){if(a.cwd)return a.cwd;let b=(0,g.v$)(a.boardId);return b&&(0,e.existsSync)(b.projectKey)?b.projectKey:null}async function p(a){if(a.sessionId)try{let b=await (0,i.os)(a.sessionId);if(b)return{...await (0,h.OF)(a.sessionId,b,void 0),created:!1}}catch{}let b=o(a);return b?{...await (0,h.OF)((0,f.randomUUID)(),"",b,{toolNames:k.C1}),created:!0}:null}async function q(a){let b=null;try{if(!(b=await p(a)))return console.warn(`[task-scheduler] #${a.number} ${a.name} 无可用 cwd,跳过派发`),!1;let c=b;await c.session.send({type:"set_session_name",name:`#${a.number} ${a.name}`});let d=(0,g.v$)(a.boardId);if(d?.taskId&&(0,j.mE)(c.realSessionId,d.taskId),c.session.isRunning())return(0,l.w0)(a.id,{sessionId:c.realSessionId,execStatus:"running"}),r(a,c.session),console.log(`[task-scheduler] #${a.number} ${a.name} 会话忙(复用中),标 running 不重发`),!0;return await c.session.send({type:"prompt",message:function(a){let b=[`【任务卡 #${a.number}】${a.name}`];if(a.description.trim()&&b.push("",a.description.trim()),a.attachments.length>0)for(let c of(b.push("","附件:"),a.attachments))b.push(`- ${c}`);return b.join("\n")}(a)}),(0,l.w0)(a.id,{sessionId:c.realSessionId,execStatus:"running"}),r(a,c.session),console.log(`[task-scheduler] 派发 #${a.number} ${a.name} → session ${c.realSessionId.slice(0,8)}`),!0}catch(c){if(b?.created)try{b.session.destroy()}catch{}return console.error(`[task-scheduler] 派发 #${a.number} ${a.name} 失败:`,c instanceof Error?c.message:c),!1}}function r(a,b){if("function"!=typeof b.onEvent)return;let c=b.onEvent(b=>{if("agent_end"!==b.type)return;c();let d=(0,l.XJ)(a.id);d&&"running"===d.execStatus&&((0,l.w0)(a.id,{execStatus:"review"}),console.log(`[task-scheduler] #${a.number} ${a.name} 执行会话结束(agent_end) → review(待审核)`))})}async function s(){let a=new Set((0,h.HG)()),b=Date.now(),c=0;for(let d of(0,l.BH)()){if(!d.sessionId||a.has(d.sessionId))continue;let e=await (0,m.Wz)(d.sessionId);e&&0!==e.lastActivityMs&&(b-e.lastActivityMs<5e3||((0,l.w0)(d.id,{execStatus:"review"}),console.log(`[task-scheduler] #${d.number} ${d.name} 执行会话已结束 → review(待审核)`),c+=1))}return c}async function t(){await s(),await u(),await y(),await z();let a=0,b=(0,l.CU)(),c=Math.max(0,1-b);if(c<=0)return C({type:"skipped_gate",at:Date.now()}),0;for(let b of(0,l.uZ)().slice(0,c)){if((0,l.CU)()>=1)break;await q(b)&&(a+=1,C({type:"dispatch",cardNumber:b.number,cardName:b.name,at:Date.now()}))}return a}async function u(){let a=0;for(let b of(0,l.Kg)()){let c=(0,l.XJ)(b.cardId);if(c&&"waiting_reply"===c.execStatus&&c.sessionId){if((0,l.CU)()>=1)break;await v(c,b)&&(a+=1,C({type:"resume",cardNumber:c.number,cardName:c.name,at:Date.now()}))}}return a}async function v(a,b){try{let c=await (0,i.os)(a.sessionId);if(!c)return!1;let{session:d}=await (0,h.OF)(a.sessionId,c,void 0);return await d.send({type:"prompt",message:`【用户回答了你的提问】
29
+ ORDER BY q.answered`).all().map(t)}},57856:(a,b,c)=>{c.d(b,{TQ:()=>e,p1:()=>d});let d=92;function e(a,b=d,c=40){return Object.freeze({terminal:Object.freeze({columns:b,rows:c,kittyProtocolActive:!1}),requestRender:a})}},60542:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{startTaskScheduler:()=>B});var e=c(29021),f=c(55511),g=c(75384),h=c(89763),i=c(69453),j=c(65562),k=c(14916),l=c(48817),m=c(32105),n=a([h,i,m]);[h,i,m]=n.then?(await n)():n;let D=new Map,E=new Map;function o(a){if(a.cwd)return a.cwd;let b=(0,g.v$)(a.boardId);return b&&(0,e.existsSync)(b.projectKey)?b.projectKey:null}async function p(a){if(a.sessionId)try{let b=await (0,i.os)(a.sessionId);if(b)return{...await (0,h.OF)(a.sessionId,b,void 0),created:!1}}catch{}let b=o(a);return b?{...await (0,h.OF)((0,f.randomUUID)(),"",b,{toolNames:k.C1}),created:!0}:null}async function q(a){let b=(0,f.randomUUID)();if(!(0,l.Im)(a.id,b))return console.log(`[task-scheduler] #${a.number} ${a.name} 派发锁被占用,跳过`),!1;let c=null;try{if(!(c=await p(a)))return console.warn(`[task-scheduler] #${a.number} ${a.name} 无可用 cwd,跳过派发`),(0,l.$j)(a.id,b),!1;let d=c;await d.session.send({type:"set_session_name",name:`#${a.number} ${a.name}`});let e=(0,g.v$)(a.boardId);if(e?.taskId&&(0,j.mE)(d.realSessionId,e.taskId),d.session.isRunning())return(0,l.w0)(a.id,{sessionId:d.realSessionId,execStatus:"running"}),r(a,d.session),(0,l.$j)(a.id,b),console.log(`[task-scheduler] #${a.number} ${a.name} 会话忙(复用中),标 running 不重发`),!0;return await d.session.send({type:"prompt",message:function(a){let b=[`【任务卡 #${a.number}】${a.name}`];if(a.description.trim()&&b.push("",a.description.trim()),a.attachments.length>0)for(let c of(b.push("","附件:"),a.attachments))b.push(`- ${c}`);return b.join("\n")}(a)}),(0,l.w0)(a.id,{sessionId:d.realSessionId,execStatus:"running"}),r(a,d.session),(0,l.$j)(a.id,b),console.log(`[task-scheduler] 派发 #${a.number} ${a.name} → session ${d.realSessionId.slice(0,8)}`),!0}catch(d){if(c?.created)try{c.session.destroy()}catch{}return(0,l.$j)(a.id,b),console.error(`[task-scheduler] 派发 #${a.number} ${a.name} 失败:`,d instanceof Error?d.message:d),!1}}function r(a,b){if("function"!=typeof b.onEvent)return;let c=b.onEvent(b=>{if("agent_end"!==b.type)return;c();let d=(0,l.XJ)(a.id);d&&"running"===d.execStatus&&((0,l.w0)(a.id,{execStatus:"review"}),console.log(`[task-scheduler] #${a.number} ${a.name} 执行会话结束(agent_end) → review(待审核)`))})}async function s(){let a=new Set((0,h.HG)()),b=Date.now(),c=0;for(let d of(0,l.BH)()){if(!d.sessionId||a.has(d.sessionId))continue;let e=await (0,m.Wz)(d.sessionId);e&&0!==e.lastActivityMs&&(b-e.lastActivityMs<5e3||((0,l.w0)(d.id,{execStatus:"review"}),console.log(`[task-scheduler] #${d.number} ${d.name} 执行会话已结束 → review(待审核)`),c+=1))}return c}async function t(){await s(),await u(),await y(),await z();let a=0,b=(0,l.CU)(),c=Math.max(0,1-b);if(c<=0)return C({type:"skipped_gate",at:Date.now()}),0;for(let b of(0,l.uZ)().slice(0,c)){if((0,l.CU)()>=1)break;await q(b)&&(a+=1,C({type:"dispatch",cardNumber:b.number,cardName:b.name,at:Date.now()}))}return a}async function u(){let a=0;for(let b of(0,l.Kg)()){let c=(0,l.XJ)(b.cardId);if(c&&"waiting_reply"===c.execStatus&&c.sessionId){if((0,l.CU)()>=1)break;await v(c,b)&&(a+=1,C({type:"resume",cardNumber:c.number,cardName:c.name,at:Date.now()}))}}return a}async function v(a,b){try{let c=await (0,i.os)(a.sessionId);if(!c)return!1;let{session:d}=await (0,h.OF)(a.sessionId,c,void 0);return await d.send({type:"prompt",message:`【用户回答了你的提问】
25
30
  ${b.answer}
26
31
 
27
32
  请据此继续完成任务。`}),(0,l.w0)(a.id,{execStatus:"running"}),console.log(`[task-scheduler] 回复续会话 #${a.number} ${a.name}`),!0}catch(b){return console.error(`[task-scheduler] 回复续会话失败 #${a.number}:`,b instanceof Error?b.message:b),!1}}function w(a){let b=a.retryCount+1;b<a.maxRetries?((0,l.w0)(a.id,{execStatus:"not_started",retryCount:b}),console.log(`[task-scheduler] #${a.number} 失败(${b}/${a.maxRetries})→ 待重试`)):((0,l.w0)(a.id,{execStatus:"failed",retryCount:b}),console.log(`[task-scheduler] #${a.number} 失败(${b}/${a.maxRetries})→ failed`))}function x(a,b){(0,l.w0)(a.id,{execStatus:"waiting_reply"}),a.sessionId&&(0,l.hG)(a.id,a.sessionId,`AI 需要你回答后继续任务。
28
- ${b.slice(0,500)}`),console.log(`[task-scheduler] #${a.number} → waiting_reply(提问入队)`)}async function y(){let a=Date.now(),b=0;for(let c of(0,l.O7)(["review"])){let d=c.sessionId?await (0,m.Wz)(c.sessionId):null;if(d?.failure){w(c),b+=1;continue}if(!c.sessionId||!d){(0,l.w0)(c.id,{execStatus:"done"}),console.log(`[task-scheduler] #${c.number} 无执行内容 → done`),b+=1;continue}let e=E.get(c.id)??0;if(a-e<3e5)continue;E.set(c.id,a);let f=o(c);if(!f)continue;let g=await (0,m.s4)({cwd:f,cardNumber:c.number,cardName:c.name,taskDescription:c.description,recentMessages:d.recentText});g?.verdict==="done"?((0,l.w0)(c.id,{execStatus:"done"}),console.log(`[task-scheduler] #${c.number} 审核通过 → done(${g.reason})`),b+=1):g?.verdict==="failed"?(w(c),b+=1):g?.verdict==="waiting_reply"?(x(c,d.recentText),b+=1):console.log(`[task-scheduler] #${c.number} 审核未决:${g?g.reason:"AI 判定失败"}(保持 review)`)}return b}async function z(){let a=Date.now(),b=0;for(let c of(0,l.O7)(["running"])){if(!c.sessionId)continue;let d=D.get(c.id)??0;if(a-d<6e5)continue;let e=await (0,m.Wz)(c.sessionId);if(!e||0===e.lastActivityMs||a-e.lastActivityMs<3e5)continue;D.set(c.id,a);let f=o(c);if(!f)continue;let g=await (0,m.bJ)({cwd:f,cardNumber:c.number,cardName:c.name,taskDescription:c.description,recentMessages:e.recentText});if(g)switch(g.kind){case"sync_server":case"infinite_loop":await A(c),b+=1;break;case"rate_limit":console.log(`[task-scheduler] #${c.number} 限流退避,继续观察`);break;case"asking":x(c,e.recentText),b+=1;break;case"error":(0,l.w0)(c.id,{execStatus:"review"}),b+=1}}return b}async function A(a){try{if(a.sessionId){let b=await (0,i.os)(a.sessionId);if(b){let{session:c}=await (0,h.OF)(a.sessionId,b,void 0);await c.send({type:"abort"}),await c.send({type:"prompt",message:"检测到任务卡执行异常(可能是同步开启服务或死循环)。\n请改用 tmux 后台启动服务:tmux new-session -d '命令',不要在前台阻塞等待日志;如为死循环请重新规划步骤后继续。"}),r(a,c)}}(0,l.w0)(a.id,{execStatus:"running"}),console.log(`[task-scheduler] #${a.number} 阻塞处置:abort+tmux 引导,继续运行`)}catch(b){console.error(`[task-scheduler] 阻塞处置失败 #${a.number}:`,b instanceof Error?b.message:b)}}function B(){if(globalThis.__piTaskScheduler)return;let a=!1,b=setInterval(()=>{a||(a=!0,t().catch(a=>{console.error("[task-scheduler] tick error:",a instanceof Error?a.message:a)}).finally(()=>{a=!1}))},1e4);b.unref?.();let c={timer:b,startedAt:Date.now(),lastAction:{type:"none",at:0}};globalThis.__piTaskScheduler=c,console.log("[pi-web] task scheduler started (interval 10000ms, max 1)")}function C(a){globalThis.__piTaskScheduler&&(globalThis.__piTaskScheduler.lastAction=a)}d()}catch(a){d(a)}})},61577:(a,b,c)=>{c.d(b,{o:()=>d});async function d(a,b,c){if(!b.model&&!b.thinkingLevel)return{modelDefaultChanged:!1};let d=!1;return b.model&&c.model&&b.model.provider===c.model.provider&&b.model.modelId===c.model.modelId&&(a.setDefaultModelAndProvider(c.model.provider,c.model.modelId),d=!0),b.thinkingLevel&&(c.supportsThinking||"off"!==c.thinkingLevel)&&a.setDefaultThinkingLevel(c.thinkingLevel),await a.flush(),{modelDefaultChanged:d}}},62391:(a,b,c)=>{c.d(b,{KI:()=>m});var d=c(79646),e=c(29021),f=c(33873);function g(a){return a&&"win32"===process.platform?(0,f.normalize)(a):a}function h(a){let b=(0,f.normalize)(g(a)),c=(0,f.parse)(b).root.length,d=b.length;for(;d>c&&b[d-1]===f.sep;)d--;return b.slice(0,d)}function i(a,b){if(a===b)return!0;if(!a||!b)return!1;let c=h(a),d=h(b);return"win32"===process.platform?c.toLowerCase()===d.toLowerCase():c===d}let j=(0,c(28354).promisify)(d.execFile);async function k(a,b){let{stdout:c}=await j("git",["-C",a,...b],{timeout:1e4,maxBuffer:1048576,env:{...process.env,LC_ALL:"C"}});return c.trim()}function l(a){try{return(0,e.realpathSync)(a)}catch{return a}}async function m(a){let b,c=(globalThis.__piProjectCache||(globalThis.__piProjectCache=new Map),globalThis.__piProjectCache),d=c.get(a);if(d&&d.expiresAt>Date.now())return d.info;try{if(!(0,e.existsSync)(a))return b=function(a){let b=(0,f.dirname)(a);if(!b.endsWith("-worktrees"))return null;let c=b.slice(0,-10);return c&&(0,e.existsSync)((0,f.join)(c,".git"))?{projectRoot:l(c),branch:(0,f.basename)(a),isWorktree:!0,isTopLevel:!0}:null}(a)??{projectRoot:a,branch:null,isWorktree:!1,isTopLevel:!1},c.set(a,{info:b,expiresAt:Date.now()+6e4}),b;let[d,h,j,m]=(await k(a,["rev-parse","--path-format=absolute","--git-common-dir","--git-dir","--show-toplevel","--abbrev-ref","HEAD"])).split("\n").map(a=>a.trim()),[n,o,p]=[d,h,j].map(g),q=l(a),r=i(p,q),s=!i(o,n)&&r,t=s?(0,f.dirname)(n):p;b={projectRoot:r?l(t):a,branch:m&&"HEAD"!==m?m:null,isWorktree:s,isTopLevel:r}}catch{b={projectRoot:a,branch:null,isWorktree:!1,isTopLevel:!1}}return c.set(a,{info:b,expiresAt:Date.now()+6e4}),b}},65562:(a,b,c)=>{c.d(b,{mE:()=>e}),c(55511);var d=c(90596);function e(a,b){let c=(0,d.Lf)();if(!(0,d.Lf)().prepare("SELECT id, project_key AS projectKey, name, created, updated, pinned, sort_order AS sortOrder FROM tasks WHERE id = ?").get(b))return!1;let e=Date.now();c.exec("BEGIN");try{c.prepare("INSERT INTO session_meta (session_id, task_id, updated) VALUES (?, ?, ?) ON CONFLICT(session_id) DO UPDATE SET task_id = excluded.task_id, updated = excluded.updated").run(a,b,e),c.prepare("UPDATE tasks SET updated = ? WHERE id = ?").run(e,b),c.exec("COMMIT")}catch(a){throw c.exec("ROLLBACK"),a}return!0}c(75384)},69453:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{O8:()=>v,mD:()=>r,os:()=>u});var e=c(75430),f=c(29021),g=c(79748),h=c(33873),i=c(90596),j=c(7535),k=c(7561),l=c(62391),m=c(9210),n=a([e,m]);async function o(a){let b=[...new Set(a.map(a=>a.cwd).filter(Boolean))],c=new Map;await Promise.all(b.map(async a=>{c.set(a,await (0,l.KI)(a))}));let d=new Set;try{let a=(0,i.Lf)().prepare("SELECT session_id FROM session_meta WHERE pinned = 1").all();d=new Set(a.map(a=>a.session_id))}catch{}return a.map(a=>{let b=a.cwd?c.get(a.cwd):void 0,e=b?.projectRoot??a.cwd;return{...a,projectRoot:e,projectKey:(0,j.z)(e),...b?.branch?{branch:b.branch}:{},...b?.isWorktree?{isWorktree:!0}:{},...b?.isWorktree&&b.branch?{worktreeBranch:b.branch}:{},...d.has(a.id)?{pinned:!0}:{}}})}async function p(){let a=await m.X.scan(),b=new Map;for(let c of a)b.set((0,k.$)(c.path),c.id);let c=a.map(a=>(v(a.id,a.path),{path:a.path,id:a.id,cwd:a.cwd,name:a.name,created:a.created.toISOString(),modified:a.modified.toISOString(),messageCount:0,firstMessage:a.firstMessage||"(no messages)",lastReply:a.lastReply||"",parentSessionId:a.parentSessionPath?b.get((0,k.$)(a.parentSessionPath)):void 0,transient:!1}));return o(c)}async function q(a={}){a.force&&r();let b=globalThis.__piSessionListGeneration??0;if(globalThis.__piSessionListCache&&Date.now()-globalThis.__piSessionListCache.ts<w)return globalThis.__piSessionListCache.data;if(globalThis.__piSessionListPromise&&globalThis.__piSessionListPromiseGeneration===b)return globalThis.__piSessionListPromise;let c=p().then(a=>(globalThis.__piSessionListGeneration??0)!==b?q():(globalThis.__piSessionListCache={data:a,ts:Date.now()},a)).finally(()=>{globalThis.__piSessionListPromise===c&&(globalThis.__piSessionListPromise=void 0,globalThis.__piSessionListPromiseGeneration=void 0)});return globalThis.__piSessionListPromise=c,globalThis.__piSessionListPromiseGeneration=b,c}[e,m]=n.then?(await n)():n;let w=3e5;function r(){globalThis.__piSessionListGeneration=(globalThis.__piSessionListGeneration??0)+1,globalThis.__piSessionListCache=void 0}function s(){return globalThis.__piSessionPathCache||(globalThis.__piSessionPathCache=new Map),globalThis.__piSessionPathCache}async function t(a){let b,c=(0,h.join)((0,e.getAgentDir)(),"sessions");if(!a||!(0,f.existsSync)(c))return null;let d=`_${a}.jsonl`;try{b=await (0,g.readdir)(c,{withFileTypes:!0})}catch{return null}for(let e of b){let b;if(!e.isDirectory()&&!e.isSymbolicLink())continue;let i=(0,h.join)(c,e.name);try{b=await (0,g.readdir)(i)}catch{continue}let j=b.find(a=>a.endsWith(d));if(!j)continue;let k=(0,h.join)(i,j);try{if(function(a){let b=(0,f.openSync)(a,"r");try{let a=[],c=0,d=!1;for(;c<65536&&!d;){let e=Buffer.allocUnsafe(Math.min(4096,65536-c)),g=(0,f.readSync)(b,e,0,e.length,c);if(0===g)break;let h=e.subarray(0,g),i=h.indexOf(10);a.push(-1===i?h:h.subarray(0,i)),c+=g,d=-1!==i}if(!d&&c>=65536)return null;let e=Buffer.concat(a).toString("utf8").trimEnd();if(!e)return null;try{let a=JSON.parse(e);return"session"===a.type?a:null}catch{return null}}finally{(0,f.closeSync)(b)}}(k)?.id===a)return k}catch{}}return null}async function u(a){let b=s().get(a);if(b)return b;let c=await t(a);return c?(v(a,c),c):(await q(),s().get(a)??null)}function v(a,b){let c=(0,h.normalize)(b),d=(0,k.$)(c),e=s(),f=(globalThis.__piPathToSessionIdCache||(globalThis.__piPathToSessionIdCache=new Map),globalThis.__piPathToSessionIdCache),g=e.get(a),i=g?(0,k.$)(g):void 0,j=f.get(d),l=j?e.get(j):void 0;i&&i!==d&&f.get(i)===a&&f.delete(i),j&&j!==a&&l&&(0,k.$)(l)===d&&e.delete(j),e.set(a,c),f.set(d,a)}d()}catch(a){d(a)}})},75384:(a,b,c)=>{c.d(b,{v$:()=>f}),c(55511);var d=c(90596);c(48817);let e="__running__";function f(a){var b,c;if(a===e)return{id:e,projectKey:"",name:"running",isSystem:!0,taskId:null,sortOrder:0,created:0,updated:0,nodeCount:0};let f=(0,d.Lf)().prepare("SELECT id, project_key AS projectKey, name, is_system AS isSystem, task_id AS taskId, sort_order AS sortOrder, created, updated FROM boards WHERE id = ?").get(a);return f?(b=f.id,c=(0,d.Lf)().prepare("SELECT COUNT(*) AS n FROM board_nodes WHERE board_id = ?").get(b).n,{id:f.id,projectKey:f.projectKey,name:f.name,isSystem:1===f.isSystem,taskId:f.taskId,sortOrder:f.sortOrder,created:f.created,updated:f.updated,nodeCount:c}):void 0}},81186:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{Ds:()=>j,J1:()=>h,eD:()=>i});var e=c(75430),f=c(76760),g=a([e]);e=(g.then?(await g)():g)[0];let k="pi-web-project-command-environment",l=`<inline:${k}>`;function h(a={}){let{agentBinDir:b=(0,f.join)((0,e.getAgentDir)(),"bin"),baseEnvironment:c=process.env,localOperations:d=(0,e.createLocalBashOperations)({shellPath:a.shellPath}),platform:g=process.platform}=a;return{exec(a,e,f){var h;let i,j,k,l=(h=function(a,b=process.platform){let c={...a};for(let a of Object.keys(c))(function(a,b){let c="win32"===b?a.toUpperCase():a;return"PORT"===c||"NODE_ENV"===c||c.startsWith("NEXT_")})(a,b)&&delete c[a];return c}(f.env??c,g),i="win32"===g?Object.keys(h).find(a=>"PATH"===a.toUpperCase())??"PATH":"PATH",j="win32"===g?";":":",(k=h[i]??"").split(j).filter(Boolean).includes(b)||(h[i]=[b,k].filter(Boolean).join(j)),h);return d.exec(a,e,{...f,env:l})}}}function i(a){return{name:k,hidden:!0,factory:b=>{let c=(0,e.createBashToolDefinition)(a.cwd);b.registerTool({...c,execute:(b,c,d,f,g)=>(0,e.createBashToolDefinition)(a.cwd,{commandPrefix:a.settings.getShellCommandPrefix(),operations:h({shellPath:a.settings.getShellPath()})}).execute(b,c,d,f,g)})}}}function j(a){let b=a.extensions.findIndex(a=>a.path===l);if(b<0)return a;let c=a.extensions.slice(0,b).find(a=>a.tools.has("bash"));return c?{...a,extensions:a.extensions.filter((a,c)=>c!==b),errors:a.errors.filter(a=>a.path!==l||a.error!==`Tool "bash" conflicts with ${c.path}`)}:a}d()}catch(a){d(a)}})},88250:(a,b,c)=>{c.d(b,{kn:()=>d});function d(){let a=(globalThis.__piModelsCacheState||(globalThis.__piModelsCacheState={entries:new Map,inFlight:new Map,generation:0}),globalThis.__piModelsCacheState);a.generation+=1,a.entries.clear(),a.inFlight.clear()}},90596:(a,b,c)=>{c.d(b,{Lf:()=>g});var d=c(80099),e=c(21820),f=c(33873);function g(){var a;if(globalThis.__piWebDb)return globalThis.__piWebDb;let b=new d.DatabaseSync((0,f.join)(function(){let a=process.env.PI_CODING_AGENT_DIR;if(a){let b=a.startsWith("~")?(0,f.join)((0,e.homedir)(),a.slice(1)):a;return(0,f.normalize)(b)}return(0,f.join)((0,e.homedir)(),".pi","agent")}(),"pi-web.db"));return b.exec("PRAGMA journal_mode = WAL;"),b.exec("PRAGMA foreign_keys = ON;"),(a=b).exec(`
33
+ ${b.slice(0,500)}`),console.log(`[task-scheduler] #${a.number} → waiting_reply(提问入队)`)}async function y(){let a=Date.now(),b=0;for(let c of(0,l.O7)(["review"])){let d=c.sessionId?await (0,m.Wz)(c.sessionId):null;if(d?.failure){w(c),b+=1;continue}if(!c.sessionId||!d){(0,l.w0)(c.id,{execStatus:"done"}),console.log(`[task-scheduler] #${c.number} 无执行内容 → done`),b+=1;continue}let e=E.get(c.id)??0;if(a-e<3e5)continue;E.set(c.id,a);let f=o(c);if(!f)continue;let g=await (0,m.s4)({cwd:f,cardNumber:c.number,cardName:c.name,taskDescription:c.description,recentMessages:d.recentText});g?.verdict==="done"?((0,l.w0)(c.id,{execStatus:"done"}),console.log(`[task-scheduler] #${c.number} 审核通过 → done(${g.reason})`),b+=1):g?.verdict==="failed"?(w(c),b+=1):g?.verdict==="waiting_reply"?(x(c,d.recentText),b+=1):console.log(`[task-scheduler] #${c.number} 审核未决:${g?g.reason:"AI 判定失败"}(保持 review)`)}return b}async function z(){let a=Date.now(),b=0;for(let c of(0,l.O7)(["running"])){if(!c.sessionId)continue;let d=D.get(c.id)??0;if(a-d<6e5)continue;let e=await (0,m.Wz)(c.sessionId);if(!e||0===e.lastActivityMs||a-e.lastActivityMs<3e5)continue;D.set(c.id,a);let f=o(c);if(!f)continue;let g=await (0,m.bJ)({cwd:f,cardNumber:c.number,cardName:c.name,taskDescription:c.description,recentMessages:e.recentText});if(g)switch(g.kind){case"sync_server":case"infinite_loop":await A(c),b+=1;break;case"rate_limit":console.log(`[task-scheduler] #${c.number} 限流退避,继续观察`);break;case"asking":x(c,e.recentText),b+=1;break;case"error":(0,l.w0)(c.id,{execStatus:"review"}),b+=1}}return b}async function A(a){try{if(a.sessionId){let b=await (0,i.os)(a.sessionId);if(b){let{session:c}=await (0,h.OF)(a.sessionId,b,void 0);await c.send({type:"abort"}),await c.send({type:"prompt",message:"检测到任务卡执行异常(可能是同步开启服务或死循环)。\n请改用 tmux 后台启动服务:tmux new-session -d '命令',不要在前台阻塞等待日志;如为死循环请重新规划步骤后继续。"}),r(a,c)}}(0,l.w0)(a.id,{execStatus:"running"}),console.log(`[task-scheduler] #${a.number} 阻塞处置:abort+tmux 引导,继续运行`)}catch(b){console.error(`[task-scheduler] 阻塞处置失败 #${a.number}:`,b instanceof Error?b.message:b)}}function B(){if(globalThis.__piTaskScheduler)return;let a=!1,b=setInterval(()=>{a||(a=!0,t().catch(a=>{console.error("[task-scheduler] tick error:",a instanceof Error?a.message:a)}).finally(()=>{a=!1}))},1e4);b.unref?.();let c={timer:b,startedAt:Date.now(),lastAction:{type:"none",at:0}};globalThis.__piTaskScheduler=c,console.log("[pi-web] task scheduler started (interval 10000ms, max 1)")}function C(a){globalThis.__piTaskScheduler&&(globalThis.__piTaskScheduler.lastAction=a)}d()}catch(a){d(a)}})},61577:(a,b,c)=>{c.d(b,{o:()=>e});let d=new Set(["off","minimal","low","medium","high","xhigh","max"]);async function e(a,b,c){if(!b.model&&!b.thinkingLevel)return{modelDefaultChanged:!1};let e=!1;if(b.model&&c.model&&b.model.provider===c.model.provider&&b.model.modelId===c.model.modelId&&(a.setDefaultModelAndProvider(c.model.provider,c.model.modelId),e=!0),b.thinkingLevel&&(c.supportsThinking||"off"!==c.thinkingLevel)){var f;let b=(f=c.thinkingLevel,d.has(f))?c.thinkingLevel:void 0;a.setDefaultThinkingLevel(b)}return await a.flush(),{modelDefaultChanged:e}}},62391:(a,b,c)=>{c.d(b,{KI:()=>m});var d=c(79646),e=c(29021),f=c(33873);function g(a){return a&&"win32"===process.platform?(0,f.normalize)(a):a}function h(a){let b=(0,f.normalize)(g(a)),c=(0,f.parse)(b).root.length,d=b.length;for(;d>c&&b[d-1]===f.sep;)d--;return b.slice(0,d)}function i(a,b){if(a===b)return!0;if(!a||!b)return!1;let c=h(a),d=h(b);return"win32"===process.platform?c.toLowerCase()===d.toLowerCase():c===d}let j=(0,c(28354).promisify)(d.execFile);async function k(a,b){let{stdout:c}=await j("git",["-C",a,...b],{timeout:1e4,maxBuffer:1048576,env:{...process.env,LC_ALL:"C"}});return c.trim()}function l(a){try{return(0,e.realpathSync)(a)}catch{return a}}async function m(a){let b,c=(globalThis.__piProjectCache||(globalThis.__piProjectCache=new Map),globalThis.__piProjectCache),d=c.get(a);if(d&&d.expiresAt>Date.now())return d.info;try{if(!(0,e.existsSync)(a))return b=function(a){let b=(0,f.dirname)(a);if(!b.endsWith("-worktrees"))return null;let c=b.slice(0,-10);return c&&(0,e.existsSync)((0,f.join)(c,".git"))?{projectRoot:l(c),branch:(0,f.basename)(a),isWorktree:!0,isTopLevel:!0}:null}(a)??{projectRoot:a,branch:null,isWorktree:!1,isTopLevel:!1},c.set(a,{info:b,expiresAt:Date.now()+6e4}),b;let[d,h,j,m]=(await k(a,["rev-parse","--path-format=absolute","--git-common-dir","--git-dir","--show-toplevel","--abbrev-ref","HEAD"])).split("\n").map(a=>a.trim()),[n,o,p]=[d,h,j].map(g),q=l(a),r=i(p,q),s=!i(o,n)&&r,t=s?(0,f.dirname)(n):p;b={projectRoot:r?l(t):a,branch:m&&"HEAD"!==m?m:null,isWorktree:s,isTopLevel:r}}catch{b={projectRoot:a,branch:null,isWorktree:!1,isTopLevel:!1}}return c.set(a,{info:b,expiresAt:Date.now()+6e4}),b}},65562:(a,b,c)=>{c.d(b,{mE:()=>e}),c(55511);var d=c(90596);function e(a,b){let c=(0,d.Lf)();if(!(0,d.Lf)().prepare("SELECT id, project_key AS projectKey, name, created, updated, pinned, sort_order AS sortOrder FROM tasks WHERE id = ?").get(b))return!1;let e=Date.now();c.exec("BEGIN");try{c.prepare("INSERT INTO session_meta (session_id, task_id, updated) VALUES (?, ?, ?) ON CONFLICT(session_id) DO UPDATE SET task_id = excluded.task_id, updated = excluded.updated").run(a,b,e),c.prepare("UPDATE tasks SET updated = ? WHERE id = ?").run(e,b),c.exec("COMMIT")}catch(a){throw c.exec("ROLLBACK"),a}return!0}c(75384)},69453:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{O8:()=>v,mD:()=>r,os:()=>u});var e=c(75430),f=c(29021),g=c(79748),h=c(33873),i=c(90596),j=c(7535),k=c(7561),l=c(62391),m=c(9210),n=a([e,m]);async function o(a){let b=[...new Set(a.map(a=>a.cwd).filter(Boolean))],c=new Map;await Promise.all(b.map(async a=>{c.set(a,await (0,l.KI)(a))}));let d=new Set;try{let a=(0,i.Lf)().prepare("SELECT session_id FROM session_meta WHERE pinned = 1").all();d=new Set(a.map(a=>a.session_id))}catch{}return a.map(a=>{let b=a.cwd?c.get(a.cwd):void 0,e=b?.projectRoot??a.cwd;return{...a,projectRoot:e,projectKey:(0,j.z)(e),...b?.branch?{branch:b.branch}:{},...b?.isWorktree?{isWorktree:!0}:{},...b?.isWorktree&&b.branch?{worktreeBranch:b.branch}:{},...d.has(a.id)?{pinned:!0}:{}}})}async function p(){let a=await m.X.scan(),b=new Map;for(let c of a)b.set((0,k.$)(c.path),c.id);let c=a.map(a=>(v(a.id,a.path),{path:a.path,id:a.id,cwd:a.cwd,name:a.name,created:a.created.toISOString(),modified:a.modified.toISOString(),messageCount:0,firstMessage:a.firstMessage||"(no messages)",lastReply:a.lastReply||"",parentSessionId:a.parentSessionPath?b.get((0,k.$)(a.parentSessionPath)):void 0,transient:!1}));return o(c)}async function q(a={}){a.force&&r();let b=globalThis.__piSessionListGeneration??0;if(globalThis.__piSessionListCache&&Date.now()-globalThis.__piSessionListCache.ts<w)return globalThis.__piSessionListCache.data;if(globalThis.__piSessionListPromise&&globalThis.__piSessionListPromiseGeneration===b)return globalThis.__piSessionListPromise;let c=p().then(a=>(globalThis.__piSessionListGeneration??0)!==b?q():(globalThis.__piSessionListCache={data:a,ts:Date.now()},a)).finally(()=>{globalThis.__piSessionListPromise===c&&(globalThis.__piSessionListPromise=void 0,globalThis.__piSessionListPromiseGeneration=void 0)});return globalThis.__piSessionListPromise=c,globalThis.__piSessionListPromiseGeneration=b,c}[e,m]=n.then?(await n)():n;let w=3e5;function r(){globalThis.__piSessionListGeneration=(globalThis.__piSessionListGeneration??0)+1,globalThis.__piSessionListCache=void 0}function s(){return globalThis.__piSessionPathCache||(globalThis.__piSessionPathCache=new Map),globalThis.__piSessionPathCache}async function t(a){let b,c=(0,h.join)((0,e.getAgentDir)(),"sessions");if(!a||!(0,f.existsSync)(c))return null;let d=`_${a}.jsonl`;try{b=await (0,g.readdir)(c,{withFileTypes:!0})}catch{return null}for(let e of b){let b;if(!e.isDirectory()&&!e.isSymbolicLink())continue;let i=(0,h.join)(c,e.name);try{b=await (0,g.readdir)(i)}catch{continue}let j=b.find(a=>a.endsWith(d));if(!j)continue;let k=(0,h.join)(i,j);try{if(function(a){let b=(0,f.openSync)(a,"r");try{let a=[],c=0,d=!1;for(;c<65536&&!d;){let e=Buffer.allocUnsafe(Math.min(4096,65536-c)),g=(0,f.readSync)(b,e,0,e.length,c);if(0===g)break;let h=e.subarray(0,g),i=h.indexOf(10);a.push(-1===i?h:h.subarray(0,i)),c+=g,d=-1!==i}if(!d&&c>=65536)return null;let e=Buffer.concat(a).toString("utf8").trimEnd();if(!e)return null;try{let a=JSON.parse(e);return"session"===a.type?a:null}catch{return null}}finally{(0,f.closeSync)(b)}}(k)?.id===a)return k}catch{}}return null}async function u(a){let b=s().get(a);if(b)return b;let c=await t(a);return c?(v(a,c),c):(await q(),s().get(a)??null)}function v(a,b){let c=(0,h.normalize)(b),d=(0,k.$)(c),e=s(),f=(globalThis.__piPathToSessionIdCache||(globalThis.__piPathToSessionIdCache=new Map),globalThis.__piPathToSessionIdCache),g=e.get(a),i=g?(0,k.$)(g):void 0,j=f.get(d),l=j?e.get(j):void 0;i&&i!==d&&f.get(i)===a&&f.delete(i),j&&j!==a&&l&&(0,k.$)(l)===d&&e.delete(j),e.set(a,c),f.set(d,a)}d()}catch(a){d(a)}})},75384:(a,b,c)=>{c.d(b,{v$:()=>f}),c(55511);var d=c(90596);c(48817);let e="__running__";function f(a){var b,c;if(a===e)return{id:e,projectKey:"",name:"running",isSystem:!0,taskId:null,sortOrder:0,created:0,updated:0,nodeCount:0};let f=(0,d.Lf)().prepare("SELECT id, project_key AS projectKey, name, is_system AS isSystem, task_id AS taskId, sort_order AS sortOrder, created, updated FROM boards WHERE id = ?").get(a);return f?(b=f.id,c=(0,d.Lf)().prepare("SELECT COUNT(*) AS n FROM board_nodes WHERE board_id = ?").get(b).n,{id:f.id,projectKey:f.projectKey,name:f.name,isSystem:1===f.isSystem,taskId:f.taskId,sortOrder:f.sortOrder,created:f.created,updated:f.updated,nodeCount:c}):void 0}},81186:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{Ds:()=>j,J1:()=>h,eD:()=>i});var e=c(75430),f=c(76760),g=a([e]);e=(g.then?(await g)():g)[0];let k="pi-web-project-command-environment",l=`<inline:${k}>`;function h(a={}){let{agentBinDir:b=(0,f.join)((0,e.getAgentDir)(),"bin"),baseEnvironment:c=process.env,localOperations:d=(0,e.createLocalBashOperations)({shellPath:a.shellPath}),platform:g=process.platform}=a;return{exec(a,e,f){var h;let i,j,k,l=(h=function(a,b=process.platform){let c={...a};for(let a of Object.keys(c))(function(a,b){let c="win32"===b?a.toUpperCase():a;return"PORT"===c||"NODE_ENV"===c||c.startsWith("NEXT_")})(a,b)&&delete c[a];return c}(f.env??c,g),i="win32"===g?Object.keys(h).find(a=>"PATH"===a.toUpperCase())??"PATH":"PATH",j="win32"===g?";":":",(k=h[i]??"").split(j).filter(Boolean).includes(b)||(h[i]=[b,k].filter(Boolean).join(j)),h);return d.exec(a,e,{...f,env:l})}}}function i(a){return{name:k,hidden:!0,factory:b=>{let c=(0,e.createBashToolDefinition)(a.cwd);b.registerTool({...c,execute:(b,c,d,f,g)=>(0,e.createBashToolDefinition)(a.cwd,{commandPrefix:a.settings.getShellCommandPrefix(),operations:h({shellPath:a.settings.getShellPath()})}).execute(b,c,d,f,g)})}}}function j(a){let b=a.extensions.findIndex(a=>a.path===l);if(b<0)return a;let c=a.extensions.slice(0,b).find(a=>a.tools.has("bash"));return c?{...a,extensions:a.extensions.filter((a,c)=>c!==b),errors:a.errors.filter(a=>a.path!==l||a.error!==`Tool "bash" conflicts with ${c.path}`)}:a}d()}catch(a){d(a)}})},88250:(a,b,c)=>{c.d(b,{kn:()=>d});function d(){let a=(globalThis.__piModelsCacheState||(globalThis.__piModelsCacheState={entries:new Map,inFlight:new Map,generation:0}),globalThis.__piModelsCacheState);a.generation+=1,a.entries.clear(),a.inFlight.clear()}},89763:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{HG:()=>u,OF:()=>v});var e=c(75430),f=c(29862),g=c(55511),h=c(29021),i=c(33873),j=c(18437),k=c(88250),l=c(96515),m=c(81186),n=c(69453),o=c(15253),p=c(61577),q=c(57856),r=a([e,f,l,m,n,o]);[e,f,l,m,n,o]=r.then?(await r)():r;let w=new Set(["agent_end","agent_settled","auto_compaction_end","compaction_end"]),x=["read","bash","edit","write","grep","find","ls"];class y extends e.Theme{constructor(){super({thinkingXhigh:"",searchMatchText:""},{selectedBg:""},"truecolor")}fg(...[,a]){return a}bg(...[,a]){return a}bold(a){return a}italic(a){return a}underline(a){return a}inverse(a){return a}strikethrough(a){return a}getFgAnsi(){return""}getBgAnsi(){return""}getThinkingBorderColor(){return a=>a}getBashModeBorderColor(){return a=>a}}let z=new y,A=new f.KeybindingsManager(f.TUI_KEYBINDINGS);function s(a,b){if(0===b.length)return[];let c=new Set(x),d=a.getAllTools().map(a=>a.name).filter(a=>!c.has(a));return[...new Set([...b,...d])]}class B{constructor(a){this.inner=a,this.listeners=[],this.pendingUiResponses=new Map,this.pendingUiRequests=new Map,this.activeCustomUis=new Map,this.extensionStatuses=new Map,this.extensionWidgets=new Map,this.activeExtensionWidgets=new Map,this.extensionWidgetGenerations=new Map,this.extensionWidgetsResetting=!1,this.pendingPromptCount=0,this.promptAdmissionTail=Promise.resolve(),this.extensionsBound=!1,this.extensionBindingPromise=null,this.extensionBindingError=null,this.forceEmptySystemPrompt=!1,this.unsubscribe=null,this.idleTimer=null,this.onDestroyCallback=null,this.shutdownPromise=null,this._alive=!0,this.lastAgentStart=0}hasPendingUiRequest(){return this.pendingUiRequests.size>0}lastAgentStartAt(){return this.lastAgentStart}get sessionId(){return this.inner.sessionId}get sessionFile(){return this.inner.sessionFile??""}get cwd(){return this.inner.sessionManager.getCwd()}get streamingMessage(){return this.inner.agent.state?.streamingMessage}get isStreaming(){return this.inner.isStreaming}isAlive(){return this._alive}isRunning(){return this._alive&&(this.pendingPromptCount>0||this.inner.isStreaming||this.inner.isCompacting||this.inner.isBashRunning)}start(){this.unsubscribe=this.inner.subscribe(a=>{"agent_start"===a.type&&(this.lastAgentStart=Date.now()),"agent_end"===a.type&&(0,n.mD)(),w.has(a.type)&&this.resetIdleTimer(),this.emit(a)}),this.resetIdleTimer()}setForceEmptySystemPrompt(a){this.forceEmptySystemPrompt=a,this.applyForcedEmptySystemPrompt()}beginExtensionBinding(a={}){this.ensureExtensionsBound(a).catch(a=>{console.error("[pi-web] failed to dispatch session_start to extensions:",a instanceof Error?a.message:a)})}async waitUntilReady(){await this.waitForExtensionsBound()}ensureExtensionsBound(a={}){return(a.forceEmptySystemPrompt&&(this.forceEmptySystemPrompt=!0),this.extensionsBound)?(this.applyForcedEmptySystemPrompt(),Promise.resolve()):(this.extensionBindingPromise||(this.extensionBindingError=null,this.extensionBindingPromise=(async()=>{if(!this._alive)return;let a=this.createExtensionUiContext();if("function"==typeof this.inner.bindExtensions){let b=this.inner.bindExtensions;await b.call(this.inner,{uiContext:a,mode:"rpc",commandContextActions:this.createExtensionCommandContextActions(),shutdownHandler:()=>this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"notify",notifyType:"warning",message:"Extension requested shutdown, but shutdown is not supported in Pi Web."}),onError:a=>this.emit({type:"extension_error",extensionPath:a.extensionPath,event:a.event,error:a.error})})}else this.inner.extensionRunner.setUIContext?.(a,"rpc");this.extensionsBound=!0,this.applyForcedEmptySystemPrompt(),console.log(`[pi-web] session_start dispatched to extensions for session ${this.inner.sessionId}`)})().catch(a=>{throw this.extensionBindingError=a,a})),this.extensionBindingPromise)}async waitForExtensionsBound(){try{this.extensionBindingPromise&&await this.extensionBindingPromise}catch(a){throw a instanceof Error?a:Error(String(a))}if(this.extensionBindingError)throw this.extensionBindingError instanceof Error?this.extensionBindingError:Error(String(this.extensionBindingError))}shouldWaitForExtensions(a){return"prompt"===a||"steer"===a||"follow_up"===a||"get_commands"===a||"get_state"===a}async withFinalRunningNotification(a){try{return await a()}finally{this.resetIdleTimer()}}applyForcedEmptySystemPrompt(){this.forceEmptySystemPrompt&&this.inner.agent.state&&(this.inner.agent.state.systemPrompt="")}emit(a){for(let b of this.listeners)try{b(a)}catch(b){console.error(`[pi-web] failed to deliver ${a.type} event:`,b instanceof Error?b.message:b)}}async acquirePromptAdmission(){let a,b=this.promptAdmissionTail;return this.promptAdmissionTail=new Promise(b=>{a=b}),await b,a}resetIdleTimer(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.isRunning()?this.resetIdleTimer():this.shutdown().catch(a=>{console.error("[pi-web] failed to shut down idle session:",a instanceof Error?a.message:a)})},6e5)}onEvent(a){for(let b of(this.listeners.push(a),this.pendingUiRequests.values()))a(b);return()=>{let b=this.listeners.indexOf(a);-1!==b&&this.listeners.splice(b,1)}}onDestroy(a){this.onDestroyCallback=a}async send(a){this.resetIdleTimer();let b=a.type;if(this.shouldWaitForExtensions(b)&&await this.waitForExtensionsBound(),"prompt"===b||"steer"===b||"follow_up"===b){let b=(0,j.kc)(a.images);if(b)throw Error(b)}switch(b){case"prompt":{let b=await this.acquirePromptAdmission();try{let b,c,d;if(this.inner.isBashRunning)throw Error("Cannot send a prompt while a shell command is running");let e=a.images,f=a.streamingBehavior,g=!1,h=!1,i=!1,j=new Promise((a,d)=>{b=()=>{g=!0,h||(h=!0,a())},c=a=>{h||(h=!0,d(a))}}),k=()=>{i||(i=!0,this.pendingPromptCount=Math.max(0,this.pendingPromptCount-1),this.resetIdleTimer())};this.pendingPromptCount+=1;try{d=this.inner.prompt(a.message,{...e?.length?{images:e}:{},...f?{streamingBehavior:f}:{},source:"rpc",preflightResult:a=>{a&&b()}})}catch(a){throw k(),a}return d.then(()=>{b(),k(),f||this.emit({type:"prompt_done"})},a=>{c(a),k(),(0,n.mD)(),g&&(this.emit({type:"prompt_error",errorMessage:a instanceof Error?a.message:String(a)}),f||this.emit({type:"prompt_done"}))}).catch(a=>{console.error("[pi-web] prompt completion handler failed:",a instanceof Error?a.message:a)}),await j,null}finally{b()}}case"abort":return await this.withFinalRunningNotification(()=>this.inner.abort()),null;case"get_state":{let a=this.inner.model,b=this.inner.getContextUsage();return{sessionId:this.inner.sessionId,sessionFile:this.inner.sessionFile??"",isStreaming:this.inner.isStreaming,isPromptRunning:this.pendingPromptCount>0,isBashRunning:this.inner.isBashRunning,isCompacting:this.inner.isCompacting,autoCompactionEnabled:this.inner.autoCompactionEnabled,autoRetryEnabled:this.inner.autoRetryEnabled,model:a?{id:a.id,provider:a.provider}:void 0,messageCount:0,pendingMessageCount:this.inner.pendingMessageCount,queuedMessages:{steering:[...this.inner.getSteeringMessages()],followUp:[...this.inner.getFollowUpMessages()]},contextUsage:b?{percent:b.percent,contextWindow:b.contextWindow,tokens:b.tokens}:null,systemPrompt:this.inner.agent.state?.systemPrompt??"",thinkingLevel:this.inner.agent.state?.thinkingLevel??"off",extensionStatuses:this.getExtensionStatuses(),extensionWidgets:this.getExtensionWidgets()}}case"set_model":{let{provider:b,modelId:c}=a,d=this.inner.modelRuntime.getModel(b,c);if(d||(await this.inner.modelRuntime.refresh({allowNetwork:!1}),d=this.inner.modelRuntime.getModel(b,c)),!d)throw Error(`Model not found: ${b}/${c}`);return await this.inner.setModel(d),(0,k.kn)(),(0,n.mD)(),{id:d.id,provider:d.provider}}case"fork":{let b;if(this.inner.isBashRunning)throw Error("Cannot fork while a shell command is running");let c=a.entryId,d=this.inner.sessionManager,f=this.inner.sessionFile;if(!d.isPersisted())return{cancelled:!0};if(!f)throw Error("Persisted session is missing a session file");let g=d.getEntry(c);if(!g)throw Error("Invalid entry ID for forking");let h=d.getSessionDir();if(g.parentId){let a=e.SessionManager.open(f,h).createBranchedSession(g.parentId);if(!a)throw Error("Failed to create forked session");b=a}else{let a=e.SessionManager.create(d.getCwd(),h);a.newSession({parentSession:f}),a.getSessionFile()&&a._rewriteFile(),b=a.getSessionFile()}let i=e.SessionManager.open(b,h).getSessionId();return(0,n.O8)(i,b),(0,n.mD)(),await this.shutdown(),{cancelled:!1,newSessionId:i}}case"navigate_tree":if(this.inner.isBashRunning)throw Error("Cannot navigate while a shell command is running");return{cancelled:(await this.inner.navigateTree(a.targetId,{})).cancelled};case"set_thinking_level":{let b=a.level;return this.inner.setThinkingLevel(b),"xhigh"===b&&this.inner.model?.compat?.thinkingFormat==="deepseek"&&this.inner.agent?.state&&(this.inner.agent.state.thinkingLevel="xhigh"),(0,n.mD)(),null}case"compact":try{return await this.withFinalRunningNotification(()=>this.inner.compact(a.customInstructions))}finally{(0,n.mD)()}case"set_session_name":{let b=a.name?.trim();if(!b)throw Error("Session name cannot be empty");return this.inner.setSessionName(b),(0,n.mD)(),null}case"get_session_stats":return{...this.inner.getSessionStats(),sessionName:this.inner.sessionManager.getSessionName()};case"get_last_assistant_text":return{text:this.inner.getLastAssistantText()??""};case"set_auto_compaction":return this.inner.setAutoCompactionEnabled(a.enabled),null;case"clear_queue":return this.inner.clearQueue();case"steer":{let b=a.images;return await this.inner.steer(a.message,b?.length?b:void 0),null}case"follow_up":{let b=a.images;return await this.inner.followUp(a.message,b?.length?b:void 0),null}case"get_tools":{let a=this.inner.getAllTools(),b=new Set(this.inner.getActiveToolNames());return a.map(a=>({name:a.name,description:a.description,active:b.has(a.name)}))}case"get_commands":{let a=[];for(let b of this.inner.extensionRunner.getRegisteredCommands())a.push({name:b.invocationName,description:b.description,source:"extension",sourceInfo:b.sourceInfo});for(let b of this.inner.promptTemplates)a.push({name:b.name,description:b.description,source:"prompt",sourceInfo:b.sourceInfo});for(let b of this.inner.resourceLoader.getSkills().skills)a.push({name:`skill:${b.name}`,description:b.description,source:"skill",sourceInfo:b.sourceInfo});return{commands:a}}case"set_tools":{let b=a.toolNames;return this.setForceEmptySystemPrompt(0===b.length),this.inner.setActiveToolsByName(s(this.inner,b)),this.applyForcedEmptySystemPrompt(),null}case"reload":return await this.waitForExtensionsBound(),this.extensionStatuses.clear(),this.resetExtensionWidgetsForReload(),this.syncProjectTrust(),await this.inner.reload(),"function"!=typeof this.inner.bindExtensions&&this.inner.extensionRunner.setUIContext?.(this.createExtensionUiContext(),"rpc"),this.applyForcedEmptySystemPrompt(),(0,k.kn)(),{success:!0};case"abort_compaction":return this.inner.abortCompaction(),null;case"extension_ui_response":return this.resolveExtensionUiResponse(a),null;case"extension_ui_input":return this.handleExtensionUiInput(a.id,a.data),null;case"set_auto_retry":return this.inner.setAutoRetryEnabled(a.enabled),null;case"bash":{if(this.pendingPromptCount>0||this.inner.isStreaming||this.inner.isCompacting||this.inner.isBashRunning)throw Error("Cannot run a shell command while the session is busy");let b=this.inner.executeBash(a.command,void 0,{excludeFromContext:a.excludeFromContext,operations:(0,m.J1)({shellPath:this.inner.settingsManager.getShellPath()})});try{return await b}finally{this.resetIdleTimer(),(0,n.mD)()}}case"abort_bash":return this.inner.abortBash(),null;default:throw Error(`Unsupported command: ${b}`)}}destroy(){if(this._alive){for(let a of(this._alive=!1,this.idleTimer&&clearTimeout(this.idleTimer),this.inner.isBashRunning&&this.inner.abortBash(),this.unsubscribe?.(),this.pendingUiResponses.values()))a.cancel();for(let a of Array.from(this.activeCustomUis.keys()))this.closeCustomUi(a,void 0);this.pendingUiResponses.clear(),this.pendingUiRequests.clear(),this.clearExtensionWidgets(!1);try{this.inner.dispose()}finally{this.onDestroyCallback?.()}}}async shutdown(){return this.shutdownPromise?this.shutdownPromise:this._alive?(this.shutdownPromise=(async()=>{try{try{await this.waitForExtensionsBound()}catch(a){console.error("[pi-web] extension binding failed before session shutdown:",a instanceof Error?a.message:a)}await this.inner.extensionRunner.emit?.({type:"session_shutdown",reason:"quit"})}finally{this.destroy()}})(),this.shutdownPromise):void 0}resolveExtensionUiResponse(a){let b=this.pendingUiResponses.get(a.id);b&&b.resolve(a)}getExtensionStatuses(){return Array.from(this.extensionStatuses,([a,b])=>({key:a,text:b}))}getExtensionWidgets(){return Array.from(this.extensionWidgets.values())}nextExtensionWidgetGeneration(a){let b=(this.extensionWidgetGenerations.get(a)??0)+1;return this.extensionWidgetGenerations.set(a,b),b}disposeExtensionWidgetComponent(a){if(!a||"object"!=typeof a&&"function"!=typeof a)return;let b=a.dispose;if("function"==typeof b)try{b.call(a)}catch{}}emitExtensionWidgetClear(a){this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"setWidget",widgetKey:a,widgetLines:void 0,widgetPlacement:void 0})}clearExtensionWidget(a,b=!0){let c=this.nextExtensionWidgetGeneration(a),d=this.activeExtensionWidgets.get(a);return this.activeExtensionWidgets.delete(a),this.extensionWidgets.delete(a),d&&this.disposeExtensionWidgetComponent(d.component),this.extensionWidgetGenerations.get(a)!==c||b&&this.emitExtensionWidgetClear(a),c}clearExtensionWidgets(a){for(let b of new Set([...this.extensionWidgets.keys(),...this.activeExtensionWidgets.keys()]))this.clearExtensionWidget(b,a)}resetExtensionWidgetsForReload(){this.extensionWidgetsResetting=!0;try{for(let a of[...this.activeExtensionWidgets.keys()])this.clearExtensionWidget(a);this.extensionWidgets.clear()}finally{this.extensionWidgetsResetting=!1}}emitExtensionWidgetError(a,b){this.emit({type:"extension_error",extensionPath:`extension-widget:${a}`,event:"setWidget",error:b instanceof Error?b.message:String(b)})}failExtensionWidget(a,b,c,d,e){if(this.extensionWidgetGenerations.get(a)!==b)return void this.disposeExtensionWidgetComponent(e);let f=this.activeExtensionWidgets.get(a),g=!d;f?.generation===b?(g=f.rendered||!f.clearEmitted,this.activeExtensionWidgets.delete(a),this.disposeExtensionWidgetComponent(f.component)):this.disposeExtensionWidgetComponent(e),this.extensionWidgetGenerations.get(a)!==b||(this.extensionWidgets.delete(a),g&&this.emitExtensionWidgetClear(a)),this.emitExtensionWidgetError(a,c)}renderExtensionWidget(a){let b;if(this.activeExtensionWidgets.get(a.key)!==a||this.extensionWidgetGenerations.get(a.key)!==a.generation)return;try{b=a.component.render(q.p1)}catch(b){this.failExtensionWidget(a.key,a.generation,b,a.clearEmitted);return}if(!Array.isArray(b)||!b.every(a=>"string"==typeof a))return void this.failExtensionWidget(a.key,a.generation,Error("Extension widget render must return string[]"),a.clearEmitted);if(this.activeExtensionWidgets.get(a.key)!==a||this.extensionWidgetGenerations.get(a.key)!==a.generation)return;let c=b;this.extensionWidgets.set(a.key,{key:a.key,lines:c,placement:a.placement}),a.rendered=!0,this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"setWidget",widgetKey:a.key,widgetLines:c,widgetPlacement:a.placement})}setExtensionWidgetFactory(a,b,c){let d,e=this.extensionWidgets.has(a)||this.activeExtensionWidgets.has(a),f=this.clearExtensionWidget(a,e);if(this.extensionWidgetGenerations.get(a)!==f)return;let g=(0,q.TQ)(()=>{let b=this.activeExtensionWidgets.get(a);b?.generation===f&&this.renderExtensionWidget(b)},q.p1);try{d=b(g,z)}catch(b){this.failExtensionWidget(a,f,b,e);return}if(this.extensionWidgetGenerations.get(a)!==f)return void this.disposeExtensionWidgetComponent(d);if(!d||"object"!=typeof d&&"function"!=typeof d||"function"!=typeof d.render)return void this.failExtensionWidget(a,f,Error("Extension widget factory must return a component with render(width)"),e,d);let h={key:a,component:d,placement:c?.placement??"aboveEditor",generation:f,clearEmitted:e,rendered:!1};this.activeExtensionWidgets.set(a,h),this.renderExtensionWidget(h)}getCustomUiWidth(a){if(!a||"object"!=typeof a)return q.p1;let b=a.overlayOptions,c="function"==typeof b?b():b;if(!c||"object"!=typeof c)return q.p1;let d=c.width;return"number"==typeof d&&Number.isFinite(d)?Math.max(40,Math.min(140,Math.round(d))):92}emitCustomUiRender(a,b){let c;try{c=b.component.render(b.width)}catch(a){c=[`Extension custom UI render failed: ${a instanceof Error?a.message:String(a)}`]}let d={type:"extension_ui_request",id:a,method:"custom",lines:c};this.pendingUiRequests.set(a,d),this.emit(d)}closeCustomUi(a,b){let c=this.activeCustomUis.get(a);if(c&&!c.settled){c.settled=!0,this.activeCustomUis.delete(a),this.pendingUiRequests.delete(a);try{c.component.dispose?.()}catch{}this.emit({type:"extension_ui_request",id:a,method:"custom",lines:[],closed:!0}),c.resolve(b)}}handleExtensionUiInput(a,b){let c=this.activeCustomUis.get(a);if(c&&"string"==typeof b)try{c.component.handleInput?.(b),this.activeCustomUis.has(a)&&this.emitCustomUiRender(a,c)}catch(b){this.closeCustomUi(a,void 0),this.emit({type:"extension_error",extensionPath:`custom-ui:${a}`,event:"custom_ui_input",error:b instanceof Error?b.message:String(b)})}}requestExtensionCustomUi(a,b){if("function"!=typeof a)return Promise.resolve(void 0);let c=(0,g.randomUUID)(),d=this.getCustomUiWidth(b);return new Promise(b=>{let e=!1,f=(0,q.TQ)(()=>{let a=this.activeCustomUis.get(c);a&&this.emitCustomUiRender(c,a)},d),g=a=>{e||(e=!0,b(a))},h=a=>{this.activeCustomUis.has(c)?this.closeCustomUi(c,a):g(a)};Promise.resolve().then(()=>a(f,z,A,h)).then(a=>{if(e){try{a?.dispose?.()}catch{}return}if(!a||"object"!=typeof a||"function"!=typeof a.render)return void g(void 0);let b={component:a,width:d,resolve:a=>g(a),settled:!1};this.activeCustomUis.set(c,b),this.emitCustomUiRender(c,b)}).catch(a=>{e||(this.emit({type:"extension_error",extensionPath:`custom-ui:${c}`,event:"custom_ui",error:a instanceof Error?a.message:String(a)}),g(void 0))})})}requestExtensionUi(a,b,c,d,e){if(e?.aborted)return Promise.resolve(b);let f=(0,g.randomUUID)(),h={type:"extension_ui_request",id:f,...a,...d?{timeout:d,expiresAt:Date.now()+d}:{}};return new Promise(a=>{let g,i=()=>{g&&clearTimeout(g),e?.removeEventListener("abort",k),this.pendingUiRequests.delete(f),this.pendingUiResponses.delete(f)},j=b=>{i(),a(b)},k=()=>j(b);d&&(g=setTimeout(()=>j(b),d)),e?.addEventListener("abort",k,{once:!0}),this.pendingUiRequests.set(f,h),this.pendingUiResponses.set(f,{resolve:a=>j(c(a)),cancel:()=>j(b)}),this.emit(h)})}createExtensionUiContext(){return{select:(a,b,c)=>this.requestExtensionUi({method:"select",title:a,options:b,...c?.timeout?{timeout:c.timeout}:{}},void 0,a=>"value"in a?a.value:void 0,c?.timeout,c?.signal),confirm:(a,b,c)=>this.requestExtensionUi({method:"confirm",title:a,message:b,...c?.timeout?{timeout:c.timeout}:{}},!1,a=>"confirmed"in a&&a.confirmed,c?.timeout,c?.signal),input:(a,b,c)=>this.requestExtensionUi({method:"input",title:a,...void 0!==b?{placeholder:b}:{},...c?.timeout?{timeout:c.timeout}:{}},void 0,a=>"value"in a?a.value:void 0,c?.timeout,c?.signal),editor:(a,b,c)=>this.requestExtensionUi({method:"editor",title:a,...void 0!==b?{prefill:b}:{},...c?.timeout?{timeout:c.timeout}:{}},void 0,a=>"value"in a?a.value:void 0,c?.timeout,c?.signal),notify:(a,b)=>{this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"notify",message:a,notifyType:b})},onTerminalInput:()=>()=>{},setStatus:(a,b)=>{void 0===b?this.extensionStatuses.delete(a):this.extensionStatuses.set(a,b),this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"setStatus",statusKey:a,statusText:b})},setWorkingMessage:()=>{},setWorkingVisible:()=>{},setWorkingIndicator:()=>{},setHiddenThinkingLabel:()=>{},setWidget:(a,b,c)=>{if(!this._alive||this.extensionWidgetsResetting)return;if("function"==typeof b)return void this.setExtensionWidgetFactory(a,b,c);if(void 0!==b&&!Array.isArray(b))return;if(void 0===b)return void this.clearExtensionWidget(a);let d=this.activeExtensionWidgets.has(a)?this.clearExtensionWidget(a):this.nextExtensionWidgetGeneration(a);this.extensionWidgetGenerations.get(a)===d&&(this.extensionWidgets.set(a,{key:a,lines:b,placement:c?.placement??"aboveEditor"}),this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"setWidget",widgetKey:a,widgetLines:b,widgetPlacement:c?.placement}))},setFooter:()=>{},setHeader:()=>{},setTitle:a=>{this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"setTitle",title:a})},custom:(a,b)=>this.requestExtensionCustomUi(a,b),pasteToEditor:a=>{this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"set_editor_text",text:a})},setEditorText:a=>{this.emit({type:"extension_ui_request",id:(0,g.randomUUID)(),method:"set_editor_text",text:a})},getEditorText:()=>"",addAutocompleteProvider:()=>{},setEditorComponent:()=>{},getEditorComponent:()=>void 0,get theme(){return z},getAllThemes:()=>[],getTheme:()=>void 0,setTheme:()=>({success:!1,error:"Theme switching is not supported in Pi Web extension UI yet"}),getToolsExpanded:()=>!1,setToolsExpanded:()=>{}}}createExtensionCommandContextActions(){return{waitForIdle:async()=>{let a=this.inner.agent;await a.waitForIdle?.()},newSession:async()=>({cancelled:!0}),fork:async()=>({cancelled:!0}),navigateTree:async(a,b)=>({cancelled:(await this.inner.navigateTree(a,{summarize:b?.summarize})).cancelled}),switchSession:async()=>({cancelled:!0}),reload:async()=>{this.extensionStatuses.clear(),this.resetExtensionWidgetsForReload(),this.syncProjectTrust(),await this.inner.reload({beforeSessionStart:()=>{this.inner.extensionRunner.setUIContext?.(this.createExtensionUiContext(),"rpc")}}),this.applyForcedEmptySystemPrompt()}}}syncProjectTrust(){let a=(0,o.Y1)(this.cwd,(0,e.getAgentDir)());this.inner.settingsManager.setProjectTrusted(a.trusted)}}function t(){if(!globalThis.__piSessions){globalThis.__piSessions=new Map;let a=()=>globalThis.__piSessions?.forEach(a=>a.destroy());process.once("exit",a),process.once("SIGINT",a),process.once("SIGTERM",a)}return globalThis.__piSessions}function u(){let a=new Set;for(let[b,c]of t())c.isRunning()&&a.add(c.sessionId||b);return[...a]}async function v(a,b,c,d={}){let f,g,j,{toolNames:q,initialModel:r,thinkingLevel:u}=d,w=t(),x=(globalThis.__piStartLocks||(globalThis.__piStartLocks=new Map),globalThis.__piStartLocks),y=w.get(a);if(y?.isAlive())return{session:y,realSessionId:a};let z=x.get(a);if(z)return z;if(b)f=e.SessionManager.open(b,void 0);else{if(!c)throw Error("cwd is required for a new session");let b=a.length>0&&!a.startsWith("__");f=e.SessionManager.create(c,void 0,b?{id:a}:void 0),b&&function(a,b){let c=a.getSessionFile();if(!c||(0,h.existsSync)(c))return;let d=a.getHeader();if(!d)return;let e=[d,...a.getEntries()].map(a=>JSON.stringify(a)).join("\n")+"\n";(0,h.writeFileSync)(c,e,{encoding:"utf8",flag:"wx"}),a.flushed=!0,(0,n.O8)(b,c)}(f,a)}let A=f.getCwd(),C=(globalThis.__piStartingSessionCwds||(globalThis.__piStartingSessionCwds=new Map),g=globalThis.__piStartingSessionCwds,j=function(a){let b=(0,i.resolve)(a);try{return(0,h.realpathSync)(b)}catch{return b}}(A),g.set(j,(g.get(j)??0)+1),()=>{let a=(g.get(j)??1)-1;a>0?g.set(j,a):g.delete(j)}),D=(async()=>{let a;(0,e.initTheme)();let b=(0,e.getAgentDir)();void 0!==q&&(a=0===q.length?[]:void 0);let c=(0,o.Fk)(A,b),d=e.SettingsManager.create(A,b),g=await (0,e.createAgentSessionServices)({cwd:A,agentDir:b,settingsManager:d,resourceLoaderOptions:{extensionFactories:[(0,m.eD)({cwd:A,settings:d})],extensionsOverride:m.Ds},...c?{resourceLoaderReloadOptions:c}:{}}),h=await (0,l.p)(g.modelRuntime,g.settingsManager.getEnabledModels()),i=g.settingsManager.getDefaultProvider(),j=g.settingsManager.getDefaultModel(),t=f.getBranch().some(a=>"message"===a.type)?{scopedModels:[...h.scopedModels]}:(0,l.I)(h,{...r?{requestedModel:r}:{},...i&&j?{defaultModel:{provider:i,modelId:j}}:{},...u?{thinkingLevel:u}:{}}),{session:v}=await (0,e.createAgentSessionFromServices)({services:g,sessionManager:f,...t.model?{model:t.model}:{},...t.thinkingLevel?{thinkingLevel:t.thinkingLevel}:{},...t.scopedModels.length>0?{scopedModels:t.scopedModels}:{},...void 0!==a?{tools:a}:{}});(await (0,p.o)(g.settingsManager,{...r?{model:r}:{},...u?{thinkingLevel:u}:{}},{...v.model?{model:{provider:v.model.provider,modelId:v.model.id}}:{},thinkingLevel:v.thinkingLevel,supportsThinking:v.supportsThinking()})).modelDefaultChanged&&(0,k.kn)(),q&&q.length>0&&v.setActiveToolsByName(s(v,q));let x=new B(v);q?.length===0&&x.setForceEmptySystemPrompt(!0),x.start();let y=v.sessionId,z=v.sessionFile;return z&&(0,n.O8)(y,z),x.onDestroy(()=>w.delete(y)),w.set(y,x),x.beginExtensionBinding({forceEmptySystemPrompt:q?.length===0}),{session:x,realSessionId:y}})().finally(()=>{x.delete(a),C()});return x.set(a,D),D}d()}catch(a){d(a)}})},90596:(a,b,c)=>{c.d(b,{Lf:()=>g});var d=c(79868),e=c(21820),f=c(33873);function g(){var a;if(globalThis.__piWebDb)return globalThis.__piWebDb;let b=new d.DatabaseSync((0,f.join)(function(){let a=process.env.PI_CODING_AGENT_DIR;if(a){let b=a.startsWith("~")?(0,f.join)((0,e.homedir)(),a.slice(1)):a;return(0,f.normalize)(b)}return(0,f.join)((0,e.homedir)(),".pi","agent")}(),"pi-web.db"));return b.exec("PRAGMA journal_mode = WAL;"),b.exec("PRAGMA foreign_keys = ON;"),(a=b).exec(`
29
34
  CREATE TABLE IF NOT EXISTS tasks (
30
35
  id TEXT PRIMARY KEY,
31
36
  project_key TEXT NOT NULL,
@@ -54,4 +59,4 @@ ${b.slice(0,500)}`),console.log(`[task-scheduler] #${a.number} → waiting_reply
54
59
  body,
55
60
  tokenize = 'trigram'
56
61
  );
57
- `),function(a){let b=a.prepare("PRAGMA user_version").get().user_version;for(let c of h)if(!(c.version<=b)){a.exec("BEGIN");try{for(let b of c.statements)try{a.exec(b)}catch(b){let a=b instanceof Error?b.message:String(b);if(!/duplicate column name/i.test(a))throw b}a.exec(`PRAGMA user_version = ${c.version}`),a.exec("COMMIT"),b=c.version}catch(b){throw a.exec("ROLLBACK"),b}}}(a),globalThis.__piWebDb=b,b}let h=[{version:1,name:"pinned columns",statements:["ALTER TABLE tasks ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;","ALTER TABLE session_meta ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;"]},{version:2,name:"tasks.sort_order",statements:["ALTER TABLE tasks ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:3,name:"session boards",statements:["CREATE TABLE IF NOT EXISTS boards (\n id TEXT PRIMARY KEY,\n project_key TEXT NOT NULL,\n name TEXT NOT NULL,\n is_system INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_boards_project ON boards(project_key);","CREATE TABLE IF NOT EXISTS board_nodes (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n ref_id TEXT,\n x REAL NOT NULL,\n y REAL NOT NULL,\n w REAL NOT NULL DEFAULT 0,\n h REAL NOT NULL DEFAULT 0,\n expanded INTEGER NOT NULL DEFAULT 0,\n props TEXT NOT NULL DEFAULT '{}',\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_nodes_board ON board_nodes(board_id);","CREATE TABLE IF NOT EXISTS board_edges (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n from_id TEXT NOT NULL,\n to_id TEXT NOT NULL,\n label TEXT,\n color TEXT,\n dashed INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_edges_board ON board_edges(board_id);","CREATE TABLE IF NOT EXISTS board_view (\n board_id TEXT PRIMARY KEY,\n camera_x REAL NOT NULL DEFAULT 0,\n camera_y REAL NOT NULL DEFAULT 0,\n camera_z REAL NOT NULL DEFAULT 1,\n updated INTEGER NOT NULL\n);"]},{version:4,name:"boards.sort_order",statements:["ALTER TABLE boards ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:5,name:"boards.task_id",statements:["ALTER TABLE boards ADD COLUMN task_id TEXT NULL;","CREATE INDEX IF NOT EXISTS idx_boards_task ON boards(task_id);"]},{version:6,name:"boards.task_id unique (防并发重复创建任务看板)",statements:["CREATE UNIQUE INDEX IF NOT EXISTS idx_boards_task_unique ON boards(task_id);"]},{version:7,name:"task cards",statements:["CREATE TABLE IF NOT EXISTS task_cards (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n project_key TEXT NOT NULL,\n number INTEGER NOT NULL,\n name TEXT NOT NULL,\n description TEXT NOT NULL DEFAULT '',\n ready_status TEXT NOT NULL DEFAULT 'draft',\n exec_status TEXT NOT NULL DEFAULT 'not_started',\n priority INTEGER NOT NULL DEFAULT 0,\n due INTEGER,\n attachments TEXT NOT NULL DEFAULT '[]',\n cwd TEXT,\n use_worktree INTEGER NOT NULL DEFAULT 0,\n max_retries INTEGER NOT NULL DEFAULT 3,\n retry_count INTEGER NOT NULL DEFAULT 0,\n session_id TEXT,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_task_cards_board ON task_cards(board_id);","CREATE INDEX IF NOT EXISTS idx_task_cards_project ON task_cards(project_key);","CREATE UNIQUE INDEX IF NOT EXISTS idx_task_cards_number ON task_cards(project_key, number);","CREATE INDEX IF NOT EXISTS idx_task_cards_status ON task_cards(ready_status, exec_status);","CREATE TABLE IF NOT EXISTS task_card_links (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n target_card_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n created INTEGER NOT NULL,\n UNIQUE(card_id, target_card_id, kind)\n);","CREATE INDEX IF NOT EXISTS idx_task_links_card ON task_card_links(card_id);","CREATE TABLE IF NOT EXISTS task_card_questions (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n question TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'pending',\n answer TEXT,\n created INTEGER NOT NULL,\n answered INTEGER\n);","CREATE INDEX IF NOT EXISTS idx_task_questions_status ON task_card_questions(status);"]}]},96515:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{I:()=>j,p:()=>i});var e=c(75430),f=a([e]);e=(f.then?(await f)():f)[0];let k=new Set(["off","minimal","low","medium","high","xhigh","max"]);function g(a,b){return a.provider===b.provider&&a.id===b.modelId}function h(a,b){let c=a.toLowerCase(),d=b.filter(a=>`${a.provider}/${a.id}`.toLowerCase()===c);return d.length>0?d:b.filter(a=>a.id.toLowerCase()===c)}async function i(a,b){let c=(b??[]).map(a=>a.trim()).filter(Boolean);if(0===c.length)return{visible:await a.getAvailable(),scopedModels:[],thinkingLevelPins:{},warnings:[]};let d=await a.getAvailable();!function(a,b){for(let c of a){if(c.includes("*")||c.includes("?")||c.includes("["))continue;let a=h(c,b);if(0===a.length){let d=c.lastIndexOf(":"),e=d>=0?c.slice(d+1):"";k.has(e)&&(a=h(c.slice(0,d),b))}if(a.length>1){let b=a.map(a=>`${a.provider}/${a.id}`).sort().join(", ");throw Error(`Ambiguous enabledModels entry "${c}" matches multiple models: ${b}. Use provider/modelId.`)}}}(c,d);let{scopedModels:f,diagnostics:g}=await (0,e.resolveModelScopeWithDiagnostics)(c,{getAvailable:async()=>d}),i=g.map(a=>a.message);if(0===f.length)return{visible:d,scopedModels:[],thinkingLevelPins:{},warnings:i};let j={};for(let a of f)a.thinkingLevel&&(j[`${a.model.provider}/${a.model.id}`]=a.thinkingLevel);return{visible:f.map(a=>a.model),scopedModels:f,thinkingLevelPins:j,warnings:i}}function j(a,b={}){let c=b.requestedModel,d=b.defaultModel,e=c?a.visible.find(a=>g(a,c)):void 0;if(c&&!e)throw Error(`Model is not available in the enabled scope: ${c.provider}/${c.modelId}`);let f=e?a.scopedModels.find(a=>a.model===e||g(a.model,{provider:e.provider,modelId:e.id})):void 0,h=!e&&d?a.scopedModels.find(a=>g(a.model,d)):void 0,i=e?void 0:h??a.scopedModels[0],k=e||i||!d?void 0:a.visible.find(a=>g(a,d)),l=e??i?.model??k,m=f??i,n=b.thinkingLevel??m?.thinkingLevel;return{...l?{model:l}:{},...n?{thinkingLevel:n}:{},scopedModels:[...a.scopedModels]}}d()}catch(a){d(a)}})}};
62
+ `),function(a){let b=a.prepare("PRAGMA user_version").get().user_version;for(let c of h)if(!(c.version<=b)){a.exec("BEGIN");try{for(let b of c.statements)try{a.exec(b)}catch(b){let a=b instanceof Error?b.message:String(b);if(!/duplicate column name/i.test(a))throw b}a.exec(`PRAGMA user_version = ${c.version}`),a.exec("COMMIT"),b=c.version}catch(b){throw a.exec("ROLLBACK"),b}}}(a),globalThis.__piWebDb=b,b}let h=[{version:1,name:"pinned columns",statements:["ALTER TABLE tasks ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;","ALTER TABLE session_meta ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;"]},{version:2,name:"tasks.sort_order",statements:["ALTER TABLE tasks ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:3,name:"session boards",statements:["CREATE TABLE IF NOT EXISTS boards (\n id TEXT PRIMARY KEY,\n project_key TEXT NOT NULL,\n name TEXT NOT NULL,\n is_system INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_boards_project ON boards(project_key);","CREATE TABLE IF NOT EXISTS board_nodes (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n ref_id TEXT,\n x REAL NOT NULL,\n y REAL NOT NULL,\n w REAL NOT NULL DEFAULT 0,\n h REAL NOT NULL DEFAULT 0,\n expanded INTEGER NOT NULL DEFAULT 0,\n props TEXT NOT NULL DEFAULT '{}',\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_nodes_board ON board_nodes(board_id);","CREATE TABLE IF NOT EXISTS board_edges (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n from_id TEXT NOT NULL,\n to_id TEXT NOT NULL,\n label TEXT,\n color TEXT,\n dashed INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_edges_board ON board_edges(board_id);","CREATE TABLE IF NOT EXISTS board_view (\n board_id TEXT PRIMARY KEY,\n camera_x REAL NOT NULL DEFAULT 0,\n camera_y REAL NOT NULL DEFAULT 0,\n camera_z REAL NOT NULL DEFAULT 1,\n updated INTEGER NOT NULL\n);"]},{version:4,name:"boards.sort_order",statements:["ALTER TABLE boards ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:5,name:"boards.task_id",statements:["ALTER TABLE boards ADD COLUMN task_id TEXT NULL;","CREATE INDEX IF NOT EXISTS idx_boards_task ON boards(task_id);"]},{version:6,name:"boards.task_id unique (防并发重复创建任务看板)",statements:["CREATE UNIQUE INDEX IF NOT EXISTS idx_boards_task_unique ON boards(task_id);"]},{version:7,name:"task cards",statements:["CREATE TABLE IF NOT EXISTS task_cards (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n project_key TEXT NOT NULL,\n number INTEGER NOT NULL,\n name TEXT NOT NULL,\n description TEXT NOT NULL DEFAULT '',\n ready_status TEXT NOT NULL DEFAULT 'draft',\n exec_status TEXT NOT NULL DEFAULT 'not_started',\n priority INTEGER NOT NULL DEFAULT 0,\n due INTEGER,\n attachments TEXT NOT NULL DEFAULT '[]',\n cwd TEXT,\n use_worktree INTEGER NOT NULL DEFAULT 0,\n max_retries INTEGER NOT NULL DEFAULT 3,\n retry_count INTEGER NOT NULL DEFAULT 0,\n session_id TEXT,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_task_cards_board ON task_cards(board_id);","CREATE INDEX IF NOT EXISTS idx_task_cards_project ON task_cards(project_key);","CREATE UNIQUE INDEX IF NOT EXISTS idx_task_cards_number ON task_cards(project_key, number);","CREATE INDEX IF NOT EXISTS idx_task_cards_status ON task_cards(ready_status, exec_status);","CREATE TABLE IF NOT EXISTS task_card_links (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n target_card_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n created INTEGER NOT NULL,\n UNIQUE(card_id, target_card_id, kind)\n);","CREATE INDEX IF NOT EXISTS idx_task_links_card ON task_card_links(card_id);","CREATE TABLE IF NOT EXISTS task_card_questions (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n question TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'pending',\n answer TEXT,\n created INTEGER NOT NULL,\n answered INTEGER\n);","CREATE INDEX IF NOT EXISTS idx_task_questions_status ON task_card_questions(status);"]},{version:8,name:"task_cards.dispatch_token (跨进程派发互斥锁)",statements:["ALTER TABLE task_cards ADD COLUMN dispatch_token TEXT NULL;"]}]},96515:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{I:()=>j,p:()=>i});var e=c(75430),f=a([e]);e=(f.then?(await f)():f)[0];let k=new Set(["off","minimal","low","medium","high","xhigh","max"]);function g(a,b){return a.provider===b.provider&&a.id===b.modelId}function h(a,b){let c=a.toLowerCase(),d=b.filter(a=>`${a.provider}/${a.id}`.toLowerCase()===c);return d.length>0?d:b.filter(a=>a.id.toLowerCase()===c)}async function i(a,b){let c=(b??[]).map(a=>a.trim()).filter(Boolean);if(0===c.length)return{visible:await a.getAvailable(),scopedModels:[],thinkingLevelPins:{},warnings:[]};let d=await a.getAvailable();!function(a,b){for(let c of a){if(c.includes("*")||c.includes("?")||c.includes("["))continue;let a=h(c,b);if(0===a.length){let d=c.lastIndexOf(":"),e=d>=0?c.slice(d+1):"";k.has(e)&&(a=h(c.slice(0,d),b))}if(a.length>1){let b=a.map(a=>`${a.provider}/${a.id}`).sort().join(", ");throw Error(`Ambiguous enabledModels entry "${c}" matches multiple models: ${b}. Use provider/modelId.`)}}}(c,d);let{scopedModels:f,diagnostics:g}=await (0,e.resolveModelScopeWithDiagnostics)(c,{getAvailable:async()=>d}),i=g.map(a=>a.message);if(0===f.length)return{visible:d,scopedModels:[],thinkingLevelPins:{},warnings:i};let j={};for(let a of f)a.thinkingLevel&&(j[`${a.model.provider}/${a.model.id}`]=a.thinkingLevel);return{visible:f.map(a=>a.model),scopedModels:f,thinkingLevelPins:j,warnings:i}}function j(a,b={}){let c=b.requestedModel,d=b.defaultModel,e=c?a.visible.find(a=>g(a,c)):void 0;if(c&&!e)throw Error(`Model is not available in the enabled scope: ${c.provider}/${c.modelId}`);let f=e?a.scopedModels.find(a=>a.model===e||g(a.model,{provider:e.provider,modelId:e.id})):void 0,h=!e&&d?a.scopedModels.find(a=>g(a.model,d)):void 0,i=e?void 0:h??a.scopedModels[0],k=e||i||!d?void 0:a.visible.find(a=>g(a,d)),l=e??i?.model??k,m=f??i,n=b.thinkingLevel??m?.thinkingLevel;return{...l?{model:l}:{},...n?{thinkingLevel:n}:{},scopedModels:[...a.scopedModels]}}d()}catch(a){d(a)}})}};
@@ -3,7 +3,7 @@ new file mode 100644
3
3
  --- /dev/null
4
4
  +++ b/${a}
5
5
  @@ -0,0 +1,${d.length} @@
6
- ${e}${f}`}async function w(a,b,c){try{return await n(a,["diff","--no-color","--no-ext-diff","--unified=3","HEAD","--",...c&&c!==b?[c,b]:[b]],4*j._4)}catch{return null}}async function x(a,b){let c,d,e=await o(a);if(!e||!p(e,b))return{supported:!1};let g=h().resolve(b),i=q(h().relative(e,g)),k=(await r(e)).find(a=>a.path===i);if(!k)return{supported:!1};let{status:m}=l(k);if("deleted"===m){let a=await w(e,i,k.originalPath);return a?.includes("\n@@ ")?{supported:!0,status:m,patch:a}:{supported:!1}}try{c=f().lstatSync(g)}catch{return{supported:!1}}if(!c.isFile()||c.size>j._4)return{supported:!1};let n=f().readFileSync(g);if(u(n))return{supported:!1};let s=n.toString("utf8");if("untracked"===m)d=v(i,s);else{let a=await w(e,i,k.originalPath);if(null===a){if("added"!==m)return{supported:!1};d=v(i,s)}else d=a}return d.includes("\n@@ ")?{supported:!0,status:m,patch:d}:{supported:!1}}},66737:(a,b,c)=>{"use strict";c.d(b,{Lf:()=>g});var d=c(80099),e=c(21820),f=c(33873);function g(){var a;if(globalThis.__piWebDb)return globalThis.__piWebDb;let b=new d.DatabaseSync((0,f.join)(function(){let a=process.env.PI_CODING_AGENT_DIR;if(a){let b=a.startsWith("~")?(0,f.join)((0,e.homedir)(),a.slice(1)):a;return(0,f.normalize)(b)}return(0,f.join)((0,e.homedir)(),".pi","agent")}(),"pi-web.db"));return b.exec("PRAGMA journal_mode = WAL;"),b.exec("PRAGMA foreign_keys = ON;"),(a=b).exec(`
6
+ ${e}${f}`}async function w(a,b,c){try{return await n(a,["diff","--no-color","--no-ext-diff","--unified=3","HEAD","--",...c&&c!==b?[c,b]:[b]],4*j._4)}catch{return null}}async function x(a,b){let c,d,e=await o(a);if(!e||!p(e,b))return{supported:!1};let g=h().resolve(b),i=q(h().relative(e,g)),k=(await r(e)).find(a=>a.path===i);if(!k)return{supported:!1};let{status:m}=l(k);if("deleted"===m){let a=await w(e,i,k.originalPath);return a?.includes("\n@@ ")?{supported:!0,status:m,patch:a}:{supported:!1}}try{c=f().lstatSync(g)}catch{return{supported:!1}}if(!c.isFile()||c.size>j._4)return{supported:!1};let n=f().readFileSync(g);if(u(n))return{supported:!1};let s=n.toString("utf8");if("untracked"===m)d=v(i,s);else{let a=await w(e,i,k.originalPath);if(null===a){if("added"!==m)return{supported:!1};d=v(i,s)}else d=a}return d.includes("\n@@ ")?{supported:!0,status:m,patch:d}:{supported:!1}}},66737:(a,b,c)=>{"use strict";c.d(b,{Lf:()=>g});var d=c(79868),e=c(21820),f=c(33873);function g(){var a;if(globalThis.__piWebDb)return globalThis.__piWebDb;let b=new d.DatabaseSync((0,f.join)(function(){let a=process.env.PI_CODING_AGENT_DIR;if(a){let b=a.startsWith("~")?(0,f.join)((0,e.homedir)(),a.slice(1)):a;return(0,f.normalize)(b)}return(0,f.join)((0,e.homedir)(),".pi","agent")}(),"pi-web.db"));return b.exec("PRAGMA journal_mode = WAL;"),b.exec("PRAGMA foreign_keys = ON;"),(a=b).exec(`
7
7
  CREATE TABLE IF NOT EXISTS tasks (
8
8
  id TEXT PRIMARY KEY,
9
9
  project_key TEXT NOT NULL,
@@ -32,4 +32,4 @@ ${e}${f}`}async function w(a,b,c){try{return await n(a,["diff","--no-color","--n
32
32
  body,
33
33
  tokenize = 'trigram'
34
34
  );
35
- `),function(a){let b=a.prepare("PRAGMA user_version").get().user_version;for(let c of h)if(!(c.version<=b)){a.exec("BEGIN");try{for(let b of c.statements)try{a.exec(b)}catch(b){let a=b instanceof Error?b.message:String(b);if(!/duplicate column name/i.test(a))throw b}a.exec(`PRAGMA user_version = ${c.version}`),a.exec("COMMIT"),b=c.version}catch(b){throw a.exec("ROLLBACK"),b}}}(a),globalThis.__piWebDb=b,b}let h=[{version:1,name:"pinned columns",statements:["ALTER TABLE tasks ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;","ALTER TABLE session_meta ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;"]},{version:2,name:"tasks.sort_order",statements:["ALTER TABLE tasks ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:3,name:"session boards",statements:["CREATE TABLE IF NOT EXISTS boards (\n id TEXT PRIMARY KEY,\n project_key TEXT NOT NULL,\n name TEXT NOT NULL,\n is_system INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_boards_project ON boards(project_key);","CREATE TABLE IF NOT EXISTS board_nodes (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n ref_id TEXT,\n x REAL NOT NULL,\n y REAL NOT NULL,\n w REAL NOT NULL DEFAULT 0,\n h REAL NOT NULL DEFAULT 0,\n expanded INTEGER NOT NULL DEFAULT 0,\n props TEXT NOT NULL DEFAULT '{}',\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_nodes_board ON board_nodes(board_id);","CREATE TABLE IF NOT EXISTS board_edges (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n from_id TEXT NOT NULL,\n to_id TEXT NOT NULL,\n label TEXT,\n color TEXT,\n dashed INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_edges_board ON board_edges(board_id);","CREATE TABLE IF NOT EXISTS board_view (\n board_id TEXT PRIMARY KEY,\n camera_x REAL NOT NULL DEFAULT 0,\n camera_y REAL NOT NULL DEFAULT 0,\n camera_z REAL NOT NULL DEFAULT 1,\n updated INTEGER NOT NULL\n);"]},{version:4,name:"boards.sort_order",statements:["ALTER TABLE boards ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:5,name:"boards.task_id",statements:["ALTER TABLE boards ADD COLUMN task_id TEXT NULL;","CREATE INDEX IF NOT EXISTS idx_boards_task ON boards(task_id);"]},{version:6,name:"boards.task_id unique (防并发重复创建任务看板)",statements:["CREATE UNIQUE INDEX IF NOT EXISTS idx_boards_task_unique ON boards(task_id);"]},{version:7,name:"task cards",statements:["CREATE TABLE IF NOT EXISTS task_cards (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n project_key TEXT NOT NULL,\n number INTEGER NOT NULL,\n name TEXT NOT NULL,\n description TEXT NOT NULL DEFAULT '',\n ready_status TEXT NOT NULL DEFAULT 'draft',\n exec_status TEXT NOT NULL DEFAULT 'not_started',\n priority INTEGER NOT NULL DEFAULT 0,\n due INTEGER,\n attachments TEXT NOT NULL DEFAULT '[]',\n cwd TEXT,\n use_worktree INTEGER NOT NULL DEFAULT 0,\n max_retries INTEGER NOT NULL DEFAULT 3,\n retry_count INTEGER NOT NULL DEFAULT 0,\n session_id TEXT,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_task_cards_board ON task_cards(board_id);","CREATE INDEX IF NOT EXISTS idx_task_cards_project ON task_cards(project_key);","CREATE UNIQUE INDEX IF NOT EXISTS idx_task_cards_number ON task_cards(project_key, number);","CREATE INDEX IF NOT EXISTS idx_task_cards_status ON task_cards(ready_status, exec_status);","CREATE TABLE IF NOT EXISTS task_card_links (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n target_card_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n created INTEGER NOT NULL,\n UNIQUE(card_id, target_card_id, kind)\n);","CREATE INDEX IF NOT EXISTS idx_task_links_card ON task_card_links(card_id);","CREATE TABLE IF NOT EXISTS task_card_questions (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n question TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'pending',\n answer TEXT,\n created INTEGER NOT NULL,\n answered INTEGER\n);","CREATE INDEX IF NOT EXISTS idx_task_questions_status ON task_card_questions(status);"]}]},78335:()=>{},80547:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.d(b,{A$:()=>o,B7:()=>p,Nw:()=>i.Nw,mc:()=>n,uK:()=>l.uK,wz:()=>i.wz});var e=c(29021),f=c(21820),g=c(33873),h=c.n(g),i=c(25252),j=c(82536),k=c(40402),l=c(58864),m=a([k]);async function n(){let a=Date.now(),b=globalThis.__piAllowedRootsCache;if(b&&b.expiresAt>a)return b.roots;let c=await (0,k.listAllSessions)(),d=new Set;for(let a of c)a.cwd&&d.add((0,i.Nw)(a.cwd)),a.projectRoot&&d.add((0,i.Nw)(a.projectRoot));try{for(let a of(0,e.readdirSync)((0,f.homedir)()))/^pi-cwd-\d{8}$/.test(a)&&d.add((0,i.Nw)(h().join((0,f.homedir)(),a)))}catch{}for(let a of(0,i.HM)())d.add(a);return globalThis.__piAllowedRootsCache={roots:d,expiresAt:a+5e3},d}function o(a,b){return(0,j.o)(a,b)}function p(a,b){return(0,j.x)(a,b)}k=(m.then?(await m)():m)[0],d()}catch(a){d(a)}})},82536:(a,b,c)=>{"use strict";c.d(b,{o:()=>h,x:()=>i});var d=c(29021),e=c(33873),f=c.n(e),g=c(58864);function h(a,b){for(let c of b){let b=(0,g.uK)(a)||(0,g.uK)(c),d=b?f().win32:f(),e=b?"\\":f().sep,h=d.resolve(a),i=d.resolve(c),j=b?h.toLowerCase():h,k=b?i.toLowerCase():i,l=k.endsWith(e)?k:k+e;if(j===k||j.startsWith(l))return!0}return!1}function i(a,b){let c;try{c=(0,d.realpathSync)(a)}catch{return!1}let e=new Set;for(let a of b)try{e.add((0,d.realpathSync)(a))}catch{}return h(c,e)}},96487:()=>{}};
35
+ `),function(a){let b=a.prepare("PRAGMA user_version").get().user_version;for(let c of h)if(!(c.version<=b)){a.exec("BEGIN");try{for(let b of c.statements)try{a.exec(b)}catch(b){let a=b instanceof Error?b.message:String(b);if(!/duplicate column name/i.test(a))throw b}a.exec(`PRAGMA user_version = ${c.version}`),a.exec("COMMIT"),b=c.version}catch(b){throw a.exec("ROLLBACK"),b}}}(a),globalThis.__piWebDb=b,b}let h=[{version:1,name:"pinned columns",statements:["ALTER TABLE tasks ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;","ALTER TABLE session_meta ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;"]},{version:2,name:"tasks.sort_order",statements:["ALTER TABLE tasks ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:3,name:"session boards",statements:["CREATE TABLE IF NOT EXISTS boards (\n id TEXT PRIMARY KEY,\n project_key TEXT NOT NULL,\n name TEXT NOT NULL,\n is_system INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_boards_project ON boards(project_key);","CREATE TABLE IF NOT EXISTS board_nodes (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n ref_id TEXT,\n x REAL NOT NULL,\n y REAL NOT NULL,\n w REAL NOT NULL DEFAULT 0,\n h REAL NOT NULL DEFAULT 0,\n expanded INTEGER NOT NULL DEFAULT 0,\n props TEXT NOT NULL DEFAULT '{}',\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_nodes_board ON board_nodes(board_id);","CREATE TABLE IF NOT EXISTS board_edges (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n from_id TEXT NOT NULL,\n to_id TEXT NOT NULL,\n label TEXT,\n color TEXT,\n dashed INTEGER NOT NULL DEFAULT 0,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_board_edges_board ON board_edges(board_id);","CREATE TABLE IF NOT EXISTS board_view (\n board_id TEXT PRIMARY KEY,\n camera_x REAL NOT NULL DEFAULT 0,\n camera_y REAL NOT NULL DEFAULT 0,\n camera_z REAL NOT NULL DEFAULT 1,\n updated INTEGER NOT NULL\n);"]},{version:4,name:"boards.sort_order",statements:["ALTER TABLE boards ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0;"]},{version:5,name:"boards.task_id",statements:["ALTER TABLE boards ADD COLUMN task_id TEXT NULL;","CREATE INDEX IF NOT EXISTS idx_boards_task ON boards(task_id);"]},{version:6,name:"boards.task_id unique (防并发重复创建任务看板)",statements:["CREATE UNIQUE INDEX IF NOT EXISTS idx_boards_task_unique ON boards(task_id);"]},{version:7,name:"task cards",statements:["CREATE TABLE IF NOT EXISTS task_cards (\n id TEXT PRIMARY KEY,\n board_id TEXT NOT NULL,\n project_key TEXT NOT NULL,\n number INTEGER NOT NULL,\n name TEXT NOT NULL,\n description TEXT NOT NULL DEFAULT '',\n ready_status TEXT NOT NULL DEFAULT 'draft',\n exec_status TEXT NOT NULL DEFAULT 'not_started',\n priority INTEGER NOT NULL DEFAULT 0,\n due INTEGER,\n attachments TEXT NOT NULL DEFAULT '[]',\n cwd TEXT,\n use_worktree INTEGER NOT NULL DEFAULT 0,\n max_retries INTEGER NOT NULL DEFAULT 3,\n retry_count INTEGER NOT NULL DEFAULT 0,\n session_id TEXT,\n created INTEGER NOT NULL,\n updated INTEGER NOT NULL\n);","CREATE INDEX IF NOT EXISTS idx_task_cards_board ON task_cards(board_id);","CREATE INDEX IF NOT EXISTS idx_task_cards_project ON task_cards(project_key);","CREATE UNIQUE INDEX IF NOT EXISTS idx_task_cards_number ON task_cards(project_key, number);","CREATE INDEX IF NOT EXISTS idx_task_cards_status ON task_cards(ready_status, exec_status);","CREATE TABLE IF NOT EXISTS task_card_links (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n target_card_id TEXT NOT NULL,\n kind TEXT NOT NULL,\n created INTEGER NOT NULL,\n UNIQUE(card_id, target_card_id, kind)\n);","CREATE INDEX IF NOT EXISTS idx_task_links_card ON task_card_links(card_id);","CREATE TABLE IF NOT EXISTS task_card_questions (\n id TEXT PRIMARY KEY,\n card_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n question TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'pending',\n answer TEXT,\n created INTEGER NOT NULL,\n answered INTEGER\n);","CREATE INDEX IF NOT EXISTS idx_task_questions_status ON task_card_questions(status);"]},{version:8,name:"task_cards.dispatch_token (跨进程派发互斥锁)",statements:["ALTER TABLE task_cards ADD COLUMN dispatch_token TEXT NULL;"]}]},78335:()=>{},80547:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.d(b,{A$:()=>o,B7:()=>p,Nw:()=>i.Nw,mc:()=>n,uK:()=>l.uK,wz:()=>i.wz});var e=c(29021),f=c(21820),g=c(33873),h=c.n(g),i=c(25252),j=c(82536),k=c(40402),l=c(58864),m=a([k]);async function n(){let a=Date.now(),b=globalThis.__piAllowedRootsCache;if(b&&b.expiresAt>a)return b.roots;let c=await (0,k.listAllSessions)(),d=new Set;for(let a of c)a.cwd&&d.add((0,i.Nw)(a.cwd)),a.projectRoot&&d.add((0,i.Nw)(a.projectRoot));try{for(let a of(0,e.readdirSync)((0,f.homedir)()))/^pi-cwd-\d{8}$/.test(a)&&d.add((0,i.Nw)(h().join((0,f.homedir)(),a)))}catch{}for(let a of(0,i.HM)())d.add(a);return globalThis.__piAllowedRootsCache={roots:d,expiresAt:a+5e3},d}function o(a,b){return(0,j.o)(a,b)}function p(a,b){return(0,j.x)(a,b)}k=(m.then?(await m)():m)[0],d()}catch(a){d(a)}})},82536:(a,b,c)=>{"use strict";c.d(b,{o:()=>h,x:()=>i});var d=c(29021),e=c(33873),f=c.n(e),g=c(58864);function h(a,b){for(let c of b){let b=(0,g.uK)(a)||(0,g.uK)(c),d=b?f().win32:f(),e=b?"\\":f().sep,h=d.resolve(a),i=d.resolve(c),j=b?h.toLowerCase():h,k=b?i.toLowerCase():i,l=k.endsWith(e)?k:k+e;if(j===k||j.startsWith(l))return!0}return!1}function i(a,b){let c;try{c=(0,d.realpathSync)(a)}catch{return!1}let e=new Set;for(let a of b)try{e.add((0,d.realpathSync)(a))}catch{}return h(c,e)}},96487:()=>{}};