@firstpick/pi-package-webui 0.11.0 → 0.11.2

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 (318) hide show
  1. package/DEVELOPMENT.md +181 -12
  2. package/README.md +41 -9
  3. package/TECHNICAL.md +91 -8
  4. package/bin/pi-webui.mjs +5432 -11428
  5. package/index.ts +10 -3
  6. package/lib/codex-cli-usage.mjs +232 -0
  7. package/lib/codex-usage-auth.mjs +39 -3
  8. package/lib/codex-usage-source.mjs +36 -0
  9. package/lib/component-update-state.mjs +2 -2
  10. package/lib/git-workflow-preference-values.mjs +122 -0
  11. package/lib/git-workflow-preferences.mjs +35 -563
  12. package/lib/package-updates.mjs +260 -0
  13. package/lib/rpc-supervisor-client.mjs +8 -4
  14. package/lib/server/app-runners.mjs +1667 -0
  15. package/lib/server/codex-fast-mode.mjs +161 -0
  16. package/lib/server/conversation-mode.mjs +218 -0
  17. package/lib/server/conversation-voice.mjs +318 -0
  18. package/lib/server/extension-ui-requests.mjs +114 -0
  19. package/lib/server/git-generation.mjs +459 -0
  20. package/lib/server/git-mutations.mjs +1827 -0
  21. package/lib/server/git-reads.mjs +608 -0
  22. package/lib/server/git-worktree-sessions.mjs +408 -0
  23. package/lib/server/helper-requests.mjs +82 -0
  24. package/lib/server/no-project-workspaces.mjs +103 -0
  25. package/lib/server/rpc-transports.mjs +394 -0
  26. package/lib/server/settings-store.mjs +544 -0
  27. package/lib/server/sse-delivery.mjs +138 -0
  28. package/lib/server/workspace-files.mjs +563 -0
  29. package/lib/update/supervisor.mjs +4 -0
  30. package/lib/webui-workspaces.mjs +2 -0
  31. package/package.json +5 -5
  32. package/public/activity-agents-controller.mjs +269 -0
  33. package/public/activity-events-controller.mjs +236 -0
  34. package/public/activity-intercom-controller.mjs +627 -0
  35. package/public/activity-queue-controller.mjs +534 -0
  36. package/public/activity-todo-view.mjs +89 -0
  37. package/public/activity-usage-controller.mjs +589 -0
  38. package/public/app.js +3761 -3878
  39. package/public/conversation-overview.css +84 -0
  40. package/public/conversation-overview.mjs +193 -0
  41. package/public/draft-conversations.mjs +135 -0
  42. package/public/focused-composer-controls.css +111 -0
  43. package/public/focused-composer-controls.mjs +143 -0
  44. package/public/focused-composer-disclosure.mjs +223 -0
  45. package/public/focused-shell-adapter.css +264 -0
  46. package/public/focused-shell-adapter.mjs +257 -0
  47. package/public/index.html +137 -80
  48. package/public/model-catalog-order.mjs +63 -0
  49. package/public/platform-event-stream.mjs +64 -0
  50. package/public/project-artifact-controller.mjs +218 -0
  51. package/public/project-file-viewer-controller.mjs +383 -0
  52. package/public/project-git-tools-controller.mjs +181 -0
  53. package/public/project-runners-controller.mjs +220 -0
  54. package/public/service-worker.js +52 -1
  55. package/public/session-attention-scheduler.mjs +182 -0
  56. package/public/session-composer-store.mjs +56 -0
  57. package/public/session-context.mjs +51 -0
  58. package/public/session-extension-requests.mjs +63 -0
  59. package/public/session-shelf-state.mjs +151 -0
  60. package/public/session-shelves.css +171 -0
  61. package/public/session-shelves.mjs +95 -0
  62. package/public/settings-navigation-controller.mjs +249 -0
  63. package/public/settings-navigation.css +61 -0
  64. package/public/settings-resource-controller.mjs +232 -0
  65. package/public/settings-workspace.css +19 -0
  66. package/public/settings-workspace.mjs +175 -0
  67. package/public/shell-actions.mjs +87 -0
  68. package/public/shell-attention-inbox.css +72 -0
  69. package/public/shell-attention-inbox.mjs +198 -0
  70. package/public/shell-context-actions.css +61 -0
  71. package/public/shell-context-actions.mjs +168 -0
  72. package/public/shell-inspector-resize.mjs +124 -0
  73. package/public/shell-navigation-resize.mjs +107 -0
  74. package/public/shell-navigation.mjs +127 -0
  75. package/public/shell-preferences.mjs +108 -0
  76. package/public/shell-surfaces.mjs +99 -0
  77. package/public/shell-tools-launcher.css +97 -0
  78. package/public/shell-tools-launcher.mjs +222 -0
  79. package/public/shell-view-host.mjs +115 -0
  80. package/public/shell-workspace.css +266 -0
  81. package/public/shell-workspace.mjs +402 -0
  82. package/public/sidebar-update-menu.css +190 -0
  83. package/public/sidebar-update-menu.mjs +512 -0
  84. package/public/styles.css +320 -169
  85. package/public/subagent-launch-slot-state.mjs +2 -2
  86. package/public/theme-contract.mjs +1 -1
  87. package/public/themed-selects.css +156 -0
  88. package/public/workspace-choices.mjs +104 -0
  89. package/tests/activity-agents-controller.test.mjs +652 -0
  90. package/tests/activity-events-controller.test.mjs +511 -0
  91. package/tests/app-runner-terminal-static.test.mjs +3 -3
  92. package/tests/append-system-http.test.mjs +7 -6
  93. package/tests/append-system-selector-static.test.mjs +6 -6
  94. package/tests/aur-review-widget-static.test.mjs +11 -3
  95. package/tests/boot-failure-diagnostics.test.mjs +8 -3
  96. package/tests/browser/activity-intercom-controller.spec.mjs +457 -0
  97. package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
  98. package/tests/browser/activity-owner-integration.spec.mjs +201 -0
  99. package/tests/browser/activity-queue-controller.spec.mjs +405 -0
  100. package/tests/browser/activity-section-picker.spec.mjs +294 -0
  101. package/tests/browser/activity-todo-view.spec.mjs +60 -0
  102. package/tests/browser/activity-usage-controller.spec.mjs +416 -0
  103. package/tests/browser/compact-layout-integration.spec.mjs +58 -0
  104. package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
  105. package/tests/browser/composer-disclosure.spec.mjs +389 -0
  106. package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
  107. package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
  108. package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
  109. package/tests/browser/control-visibility.spec.mjs +5 -0
  110. package/tests/browser/controls-layout.spec.mjs +21 -2
  111. package/tests/browser/conversation-overview.spec.mjs +251 -0
  112. package/tests/browser/draft-conversations.spec.mjs +276 -0
  113. package/tests/browser/empty-startup-fixture.mjs +135 -0
  114. package/tests/browser/empty-startup.spec.mjs +282 -0
  115. package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
  116. package/tests/browser/focused-composer-more.spec.mjs +127 -0
  117. package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
  118. package/tests/browser/focused-navigation-fixture.mjs +32 -0
  119. package/tests/browser/focused-project-activity.spec.mjs +111 -0
  120. package/tests/browser/focused-shell-integration.spec.mjs +208 -0
  121. package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
  122. package/tests/browser/folder-picker-layout.spec.mjs +302 -0
  123. package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
  124. package/tests/browser/git-setup-cancel.spec.mjs +251 -0
  125. package/tests/browser/guided-git-fallback.spec.mjs +40 -21
  126. package/tests/browser/inspector-header.spec.mjs +221 -0
  127. package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
  128. package/tests/browser/inspector-resize.spec.mjs +227 -0
  129. package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
  130. package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
  131. package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
  132. package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
  133. package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
  134. package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
  135. package/tests/browser/interaction-continuity.spec.mjs +50 -26
  136. package/tests/browser/interaction-model-picker.spec.mjs +86 -0
  137. package/tests/browser/last-terminal-close.spec.mjs +280 -0
  138. package/tests/browser/mobile-foundation.spec.mjs +172 -20
  139. package/tests/browser/model-catalog-groups.spec.mjs +104 -0
  140. package/tests/browser/more-row-menus.spec.mjs +258 -0
  141. package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
  142. package/tests/browser/no-project-conversation.spec.mjs +113 -0
  143. package/tests/browser/optimistic-prompt.spec.mjs +3 -0
  144. package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
  145. package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
  146. package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
  147. package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
  148. package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
  149. package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
  150. package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
  151. package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
  152. package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
  153. package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
  154. package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
  155. package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
  156. package/tests/browser/project-artifact-controller.spec.mjs +324 -0
  157. package/tests/browser/project-artifact-integration.spec.mjs +103 -0
  158. package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
  159. package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
  160. package/tests/browser/session-fixture.mjs +118 -0
  161. package/tests/browser/session-ownership.spec.mjs +175 -0
  162. package/tests/browser/session-shelves-integration.spec.mjs +219 -0
  163. package/tests/browser/session-shelves.spec.mjs +340 -0
  164. package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
  165. package/tests/browser/session-summary.spec.mjs +17 -12
  166. package/tests/browser/settings-complete-home.spec.mjs +463 -0
  167. package/tests/browser/settings-entrypoint.spec.mjs +104 -0
  168. package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
  169. package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
  170. package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
  171. package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
  172. package/tests/browser/shell-ownership.spec.mjs +398 -0
  173. package/tests/browser/shell-rollout-fixture.mjs +259 -0
  174. package/tests/browser/shell-rollout.spec.mjs +357 -0
  175. package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
  176. package/tests/browser/shell-workspace.spec.mjs +433 -0
  177. package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
  178. package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
  179. package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
  180. package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
  181. package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
  182. package/tests/browser/stream-output-isolation.spec.mjs +6 -3
  183. package/tests/browser/themed-selects.spec.mjs +297 -0
  184. package/tests/browser/thread-start-flow.spec.mjs +481 -0
  185. package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
  186. package/tests/browser/ui-polish-features.spec.mjs +85 -0
  187. package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
  188. package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
  189. package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
  190. package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
  191. package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
  192. package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
  193. package/tests/browser/windows-drive-parent.spec.mjs +4 -2
  194. package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
  195. package/tests/codex-cli-usage.test.mjs +189 -0
  196. package/tests/codex-fast-mode-static.test.mjs +16 -11
  197. package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
  198. package/tests/codex-usage-auth.test.mjs +168 -9
  199. package/tests/codex-usage-http.test.mjs +124 -0
  200. package/tests/codex-usage-source.test.mjs +146 -0
  201. package/tests/component-update-api-static.test.mjs +2 -2
  202. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  203. package/tests/control-deck-component-updates-static.test.mjs +9 -4
  204. package/tests/control-visibility-static.test.mjs +3 -3
  205. package/tests/controls-layout-static.test.mjs +5 -5
  206. package/tests/conversation-overview-adapter.test.mjs +100 -0
  207. package/tests/document-artifact-static.test.mjs +2 -1
  208. package/tests/draft-conversations.test.mjs +205 -0
  209. package/tests/empty-startup-launcher.test.mjs +197 -0
  210. package/tests/events-tree-context-menu-static.test.mjs +22 -18
  211. package/tests/fake-pi-session-ownership.test.mjs +302 -0
  212. package/tests/fast-mode-client-static.test.mjs +1 -1
  213. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  214. package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
  215. package/tests/file-viewer-image-static.test.mjs +15 -11
  216. package/tests/file-viewer-search-static.test.mjs +5 -5
  217. package/tests/fixtures/fake-codex-app-server.mjs +61 -0
  218. package/tests/fixtures/fake-pi.mjs +41 -9
  219. package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
  220. package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
  221. package/tests/git-footer-context-menu-static.test.mjs +1 -1
  222. package/tests/git-panel-file-preview-static.test.mjs +41 -48
  223. package/tests/git-panel-live-updates-static.test.mjs +2 -1
  224. package/tests/git-workflow-dispatch.test.mjs +66 -0
  225. package/tests/git-workflow-preferences.test.mjs +9 -1
  226. package/tests/guided-git-activation-static.test.mjs +14 -11
  227. package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
  228. package/tests/guided-git-message-reliability-static.test.mjs +10 -6
  229. package/tests/guided-git-publication-backend-static.test.mjs +16 -11
  230. package/tests/http-endpoints-harness.test.mjs +29 -9
  231. package/tests/interaction-state-stability-static.test.mjs +4 -3
  232. package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
  233. package/tests/intercom-tag-layout-static.test.mjs +13 -12
  234. package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
  235. package/tests/main-output-loading-static.test.mjs +4 -4
  236. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  237. package/tests/mobile-compact-layout.test.mjs +2 -2
  238. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  239. package/tests/mobile-foundation-static.test.mjs +10 -7
  240. package/tests/mobile-phone-experience-static.test.mjs +3 -2
  241. package/tests/mobile-static.test.mjs +173 -135
  242. package/tests/model-catalog-order.test.mjs +103 -0
  243. package/tests/native-parity.test.mjs +6 -4
  244. package/tests/native-session-choice-owner.test.mjs +102 -0
  245. package/tests/native-update-lifecycle.test.mjs +10 -5
  246. package/tests/no-project-http-harness.test.mjs +328 -0
  247. package/tests/no-project-navigation.test.mjs +54 -0
  248. package/tests/no-project-workspaces.test.mjs +77 -0
  249. package/tests/open-issue-wizard-static.test.mjs +1 -1
  250. package/tests/optional-feature-migration-frontend.test.mjs +4 -4
  251. package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
  252. package/tests/package-updates.test.mjs +630 -0
  253. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  254. package/tests/platform-event-stream.test.mjs +253 -0
  255. package/tests/project-file-viewer-controller.test.mjs +652 -0
  256. package/tests/project-git-tools-adapter.test.mjs +103 -0
  257. package/tests/project-git-tools-controller.test.mjs +577 -0
  258. package/tests/project-runners-controller.test.mjs +453 -0
  259. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  260. package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
  261. package/tests/questionnaire-dialog.test.mjs +6 -6
  262. package/tests/queue-edit-reorder-static.test.mjs +48 -51
  263. package/tests/rpc-supervisor-host.test.mjs +4 -1
  264. package/tests/safety-guard-auto-review-static.test.mjs +1 -1
  265. package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
  266. package/tests/server-app-runners.test.mjs +536 -0
  267. package/tests/server-codex-fast-mode.test.mjs +346 -0
  268. package/tests/server-conversation-mode.test.mjs +386 -0
  269. package/tests/server-conversation-voice.test.mjs +426 -0
  270. package/tests/server-extension-ui-requests.test.mjs +357 -0
  271. package/tests/server-git-generation.test.mjs +558 -0
  272. package/tests/server-git-mutations.test.mjs +729 -0
  273. package/tests/server-git-reads.test.mjs +381 -0
  274. package/tests/server-git-worktree-sessions.test.mjs +502 -0
  275. package/tests/server-helper-requests.test.mjs +364 -0
  276. package/tests/server-rpc-transports.test.mjs +553 -0
  277. package/tests/server-settings-store.test.mjs +132 -0
  278. package/tests/server-shell-rollout.test.mjs +478 -0
  279. package/tests/server-sse-delivery.test.mjs +410 -0
  280. package/tests/server-workspace-files.test.mjs +546 -0
  281. package/tests/session-attention-scheduler.test.mjs +514 -0
  282. package/tests/session-composer-store.test.mjs +153 -0
  283. package/tests/session-context.test.mjs +134 -0
  284. package/tests/session-extension-requests.test.mjs +193 -0
  285. package/tests/session-ownership-adapter.test.mjs +130 -0
  286. package/tests/session-sampling-ui-static.test.mjs +10 -4
  287. package/tests/session-send-lifetime.test.mjs +140 -0
  288. package/tests/session-shelf-state.test.mjs +348 -0
  289. package/tests/session-shelves-adapter.test.mjs +79 -0
  290. package/tests/session-summary-lifetime.test.mjs +54 -0
  291. package/tests/settings-resource-controller.test.mjs +548 -0
  292. package/tests/shell-action-adapter.test.mjs +169 -0
  293. package/tests/shell-actions.test.mjs +182 -0
  294. package/tests/shell-navigation.test.mjs +348 -0
  295. package/tests/shell-preferences.test.mjs +367 -0
  296. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  297. package/tests/stream-output-isolation-static.test.mjs +1 -1
  298. package/tests/subagent-gate-visibility.test.mjs +1 -1
  299. package/tests/subagent-launch-slot-state.test.mjs +2 -2
  300. package/tests/subagent-launch-slots-static.test.mjs +1 -1
  301. package/tests/subagent-observability-static.test.mjs +2 -2
  302. package/tests/subagent-reliability-integration.test.mjs +13 -30
  303. package/tests/syntax-highlighting-static.test.mjs +3 -3
  304. package/tests/tab-close-continuity-static.test.mjs +1 -1
  305. package/tests/tab-metadata-ordering.test.mjs +99 -0
  306. package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
  307. package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
  308. package/tests/terminal-tab-workspace-static.test.mjs +5 -4
  309. package/tests/terminal-tabs-resize-static.test.mjs +1 -1
  310. package/tests/theme-contract.test.mjs +10 -3
  311. package/tests/theme-customizer-static.test.mjs +1 -1
  312. package/tests/thread-display-title.test.mjs +44 -0
  313. package/tests/update-api-harness.test.mjs +15 -14
  314. package/tests/update-tab-restore-harness.test.mjs +3 -0
  315. package/tests/webui-settings-locking.test.mjs +2 -2
  316. package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
  317. package/tests/workspace-choices.test.mjs +114 -0
  318. package/tests/workspace-save-load-static.test.mjs +7 -4
@@ -0,0 +1,181 @@
1
+ export const GIT_TOOLS_SECTIONS = Object.freeze([
2
+ { key: "stash", title: "Stash", detail: "List, apply, pop, drop, or create stashes." },
3
+ { key: "undo", title: "Undo & recovery", detail: "Undo the last unpushed commit, amend its message, review recent HEAD history." },
4
+ { key: "worktrees", title: "Worktrees", detail: "Health, removal, and pruning of git worktrees." },
5
+ { key: "submodules", title: "Submodules", detail: "Status and recursive update." },
6
+ { key: "tags", title: "Tags", detail: "Recent tags and annotated tag creation." },
7
+ { key: "signing", title: "Signing", detail: "Commit signing configuration and diagnostics." },
8
+ ].map(Object.freeze));
9
+
10
+ export const GIT_TOOLS_ENDPOINTS = Object.freeze({
11
+ stash: "/api/git-stash",
12
+ undo: "/api/git-undo",
13
+ worktrees: "/api/git-worktrees",
14
+ submodules: "/api/git-submodules",
15
+ tags: "/api/git-tags",
16
+ signing: "/api/git-signing",
17
+ });
18
+
19
+ function requireSection(key) {
20
+ if (!Object.hasOwn(GIT_TOOLS_ENDPOINTS, key)) throw new RangeError(`Unknown Git tools section: ${key}`);
21
+ }
22
+
23
+ function requireBusyKey(key) {
24
+ if (key === "operation" || key === "conflict-agent") return;
25
+ requireSection(typeof key === "string" && key.startsWith("load:") ? key.slice(5) : key);
26
+ }
27
+
28
+ function emptyState(tabId = null) {
29
+ return { tabId, openSections: new Set(), cache: {}, busy: new Set(), notice: {} };
30
+ }
31
+
32
+ /** Owns one Git tools view. Reset on dialog reopen or repository/session replacement. */
33
+ export function createProjectGitToolsController({
34
+ api, captureTarget, isTargetCurrent, confirm, addEvent, onChange,
35
+ onRefreshChanges, onRefreshFooter, onMessage,
36
+ }) {
37
+ let state = emptyState();
38
+ let owner = null;
39
+
40
+ function capture() {
41
+ return owner?.token;
42
+ }
43
+
44
+ function isCurrent(token) {
45
+ return !!owner && token === owner.token && !!owner.target?.tabId && isTargetCurrent(owner.target);
46
+ }
47
+
48
+ function reset(target = captureTarget()) {
49
+ state = emptyState(target?.tabId ?? null);
50
+ owner = { token: Symbol("Git tools owner"), target, pendingActions: new Set() };
51
+ if (isCurrent(owner.token)) onChange();
52
+ }
53
+
54
+ function getState() {
55
+ // API data is JSON; copying the projection also protects nested cached records.
56
+ return structuredClone(state);
57
+ }
58
+
59
+ function setSectionOpen(key, open, token = capture()) {
60
+ requireSection(key);
61
+ if (!isCurrent(token)) return false;
62
+ if (state.openSections.has(key) === !!open) return true;
63
+ if (open) state.openSections.add(key);
64
+ else state.openSections.delete(key);
65
+ onChange();
66
+ return true;
67
+ }
68
+
69
+ function setBusy(key, busy, token = capture()) {
70
+ requireBusyKey(key);
71
+ if (!isCurrent(token)) return false;
72
+ if (state.busy.has(key) === !!busy) return true;
73
+ if (busy) state.busy.add(key);
74
+ else state.busy.delete(key);
75
+ onChange();
76
+ return true;
77
+ }
78
+
79
+ function setNotice(key, text, token = capture()) {
80
+ requireSection(key);
81
+ if (!isCurrent(token)) return false;
82
+ if (state.notice[key] === text) return true;
83
+ state.notice[key] = text;
84
+ onChange();
85
+ return true;
86
+ }
87
+
88
+ async function loadSection(key, { force = false }, token) {
89
+ requireSection(key);
90
+ if (!isCurrent(token)) return false;
91
+ if (!force && state.cache[key]) return true;
92
+ const busyKey = `load:${key}`;
93
+ if (state.busy.has(busyKey)) return false;
94
+ const { target } = owner;
95
+ state.busy.add(busyKey);
96
+ try {
97
+ onChange();
98
+ if (!isCurrent(token)) return false;
99
+ const response = await api(GIT_TOOLS_ENDPOINTS[key], { tabId: target.tabId });
100
+ if (!isCurrent(token)) return false;
101
+ if (!response?.ok) throw new Error(response?.error || `Failed to load ${key}`);
102
+ state.cache[key] = response.data;
103
+ if (key === "undo") {
104
+ const reflog = await api("/api/git-reflog", { tabId: target.tabId }).catch(() => null);
105
+ if (!isCurrent(token)) return false;
106
+ state.cache.reflog = reflog?.ok ? reflog.data : null;
107
+ }
108
+ state.notice[key] = "";
109
+ return true;
110
+ } catch (error) {
111
+ if (!isCurrent(token)) return false;
112
+ state.notice[key] = error?.message || String(error);
113
+ return false;
114
+ } finally {
115
+ if (isCurrent(token)) {
116
+ state.busy.delete(busyKey);
117
+ onChange();
118
+ }
119
+ }
120
+ }
121
+
122
+ function load(key, options = {}) {
123
+ return loadSection(key, options, capture());
124
+ }
125
+
126
+ /** Returns false for declined, duplicate, failed or stale work; refresh errors remain visible. */
127
+ async function run(sectionKey, {
128
+ url, method = "POST", body, confirm: confirmation, confirmLabel, success, successMessage, refreshChanges = false,
129
+ }, token = capture()) {
130
+ requireSection(sectionKey);
131
+ if (!isCurrent(token) || state.busy.has(sectionKey) || owner.pendingActions.has(sectionKey)) return false;
132
+ const actionOwner = owner;
133
+ const { target } = actionOwner;
134
+ // Reserve before confirmation so repeated clicks cannot queue the same action.
135
+ actionOwner.pendingActions.add(sectionKey);
136
+ try {
137
+ if (confirmation) {
138
+ const accepted = await confirm(confirmation, {
139
+ affected: state.cache[sectionKey]?.root || target.root || "the current repository", confirmLabel: confirmLabel || success || "Continue",
140
+ });
141
+ if (!isCurrent(token) || !accepted) return false;
142
+ }
143
+ state.busy.add(sectionKey);
144
+ onChange();
145
+ if (!isCurrent(token)) return false;
146
+ const response = await api(url, { method, body, tabId: target.tabId });
147
+ if (!isCurrent(token)) return false;
148
+ if (!response?.ok) throw new Error([response?.error, response?.hint].filter(Boolean).join("\n") || "git action failed");
149
+ const finalMessage = (typeof successMessage === "function" ? successMessage(response) : "") || success;
150
+ if (!isCurrent(token)) return false;
151
+ state.notice[sectionKey] = "";
152
+ state.busy.delete(sectionKey);
153
+ addEvent(finalMessage, "success");
154
+ if (!isCurrent(token)) return false;
155
+ await loadSection(sectionKey, { force: true }, token);
156
+ if (!isCurrent(token)) return false;
157
+ if (refreshChanges) {
158
+ await onRefreshChanges(target);
159
+ if (!isCurrent(token)) return false;
160
+ }
161
+ onMessage(finalMessage, target);
162
+ if (!isCurrent(token)) return false;
163
+ onChange();
164
+ if (!isCurrent(token)) return false;
165
+ await onRefreshFooter(target);
166
+ return isCurrent(token);
167
+ } catch (error) {
168
+ if (!isCurrent(token)) return false;
169
+ state.notice[sectionKey] = error?.message || String(error);
170
+ return false;
171
+ } finally {
172
+ actionOwner.pendingActions.delete(sectionKey);
173
+ if (isCurrent(token)) {
174
+ state.busy.delete(sectionKey);
175
+ onChange();
176
+ }
177
+ }
178
+ }
179
+
180
+ return { reset, getState, capture, isCurrent, setSectionOpen, setBusy, setNotice, load, run };
181
+ }
@@ -0,0 +1,220 @@
1
+ export const APP_RUNNER_CONTEXT_DEFAULT_LINES = 80;
2
+ export const APP_RUNNER_CONTEXT_MAX_LINES = 1000;
3
+
4
+ export function normalizeAppRunnerContextLineCount(value) {
5
+ const number = Number.parseInt(String(value ?? ""), 10);
6
+ if (!Number.isFinite(number)) return APP_RUNNER_CONTEXT_DEFAULT_LINES;
7
+ return Math.max(1, Math.min(APP_RUNNER_CONTEXT_MAX_LINES, number));
8
+ }
9
+
10
+ function runIdentity(run) {
11
+ return run ? run.id || run.runnerId || "active" : null;
12
+ }
13
+
14
+ function isRunning(run) {
15
+ return run?.status === "running" || run?.stopping === true;
16
+ }
17
+
18
+ /**
19
+ * Owns runner snapshots, requests and tab/run drafts. Data projections are read-only.
20
+ * Draft accessors take (tabId, runId), setters add the value as their third argument.
21
+ * Requests return {success:true,data}, with inputDraftCleared on sendInput, or
22
+ * {success:false,reason,error?}. Reasons are target, run, runner, stale or error.
23
+ * A stale server action may have completed; this controller does not cancel it.
24
+ */
25
+ export function createProjectRunnersController({
26
+ api,
27
+ captureTarget,
28
+ isTargetCurrent,
29
+ cleanStatusText,
30
+ onData = () => {},
31
+ onRender = () => {},
32
+ addEvent = () => {},
33
+ onRefreshContext = () => {},
34
+ }) {
35
+ const owners = new Map();
36
+
37
+ function ensureOwner(tabId) {
38
+ let owner = owners.get(tabId);
39
+ if (!owner) {
40
+ owner = { data: { runners: [], activeRun: null }, request: null, input: new Map(), context: new Map() };
41
+ owners.set(tabId, owner);
42
+ }
43
+ return owner;
44
+ }
45
+
46
+ function getData(tabId) {
47
+ return owners.get(tabId)?.data || { runners: [], activeRun: null };
48
+ }
49
+
50
+ function mergeData(tabId, owner, data, token) {
51
+ const previous = owner.data;
52
+ const hasActiveRun = Object.prototype.hasOwnProperty.call(data, "activeRun");
53
+ const next = {
54
+ cwd: data.cwd || previous.cwd || "",
55
+ runners: Array.isArray(data.runners) ? data.runners : previous.runners || [],
56
+ customRunnerConfig: data.customRunnerConfig || previous.customRunnerConfig || null,
57
+ activeRun: hasActiveRun ? data.activeRun : previous.activeRun || null,
58
+ };
59
+ owner.data = next;
60
+ if (token) token.runId = runIdentity(next.activeRun);
61
+ onData(tabId, next, { hasActiveRun });
62
+ return next;
63
+ }
64
+
65
+ function applyData(tabId, data = {}) {
66
+ if (!tabId) return;
67
+ const owner = ensureOwner(tabId);
68
+ const nextRun = Object.hasOwn(data, "activeRun") ? data.activeRun : owner.data.activeRun;
69
+ // Output can arrive before the stdin POST acknowledgment. Retire its snapshot,
70
+ // but retain the acknowledgment while the original run and request still own it.
71
+ if (owner.request?.action === "input" && runIdentity(nextRun) === owner.request.runId) {
72
+ owner.request.snapshotSuperseded = true;
73
+ } else {
74
+ owner.request = null;
75
+ }
76
+ return mergeData(tabId, owner, data);
77
+ }
78
+
79
+ function getInputDraft(tabId, runId) {
80
+ return owners.get(tabId)?.input.get(runId)?.text ?? "";
81
+ }
82
+
83
+ function setInputDraft(tabId, runId, text) {
84
+ if (tabId && runId) ensureOwner(tabId).input.set(runId, { text: String(text ?? "") });
85
+ }
86
+
87
+ function getContextDraft(tabId, runId) {
88
+ return owners.get(tabId)?.context.get(runId) ?? String(APP_RUNNER_CONTEXT_DEFAULT_LINES);
89
+ }
90
+
91
+ function setContextDraft(tabId, runId, value) {
92
+ if (tabId && runId) ensureOwner(tabId).context.set(runId, String(normalizeAppRunnerContextLineCount(value)));
93
+ }
94
+
95
+ function isCurrent(token) {
96
+ return owners.get(token.target.tabId) === token.owner
97
+ && token.owner.request === token
98
+ && runIdentity(token.owner.data.activeRun) === token.runId
99
+ && isTargetCurrent(token.target);
100
+ }
101
+
102
+ function failureState(runnerId, error, data) {
103
+ const runner = data.runners.find((item) => item.id === runnerId) || {};
104
+ const message = cleanStatusText(error?.message || String(error) || "Unknown app runner error");
105
+ const command = runner.displayCommand || runner.shortDisplayCommand || runner.label || runnerId || "app runner";
106
+ const timestamp = new Date().toISOString();
107
+ return {
108
+ id: `start-error:${Date.now()}`,
109
+ runnerId,
110
+ kind: runner.kind || "custom",
111
+ label: runner.label || "App runner failed",
112
+ command: runner.command || "",
113
+ args: Array.isArray(runner.args) ? runner.args : [],
114
+ displayCommand: command,
115
+ cwd: data.cwd || "",
116
+ status: "error",
117
+ startedAt: timestamp,
118
+ endedAt: timestamp,
119
+ lineCount: 3,
120
+ lines: [`$ ${command}`, "# failed to start app runner", `# ${message}`],
121
+ };
122
+ }
123
+
124
+ async function request(action, target, { runnerId, runId, text, closeStdin = false, lineCount } = {}) {
125
+ if (!target?.tabId || !isTargetCurrent(target)) return { success: false, reason: "target" };
126
+ const owner = ensureOwner(target.tabId);
127
+ if (action === "start" && !runnerId) return { success: false, reason: "runner" };
128
+ if (["stop", "clear", "input", "context"].includes(action)
129
+ && (!runId || runIdentity(owner.data.activeRun) !== runId
130
+ || (action === "input" && !isRunning(owner.data.activeRun)))) {
131
+ return { success: false, reason: "run" };
132
+ }
133
+
134
+ const token = { owner, target, action, runId: runIdentity(owner.data.activeRun), snapshotSuperseded: false };
135
+ owner.request = token;
136
+ const submittedDraft = owner.input.get(runId);
137
+ let path = `/api/app-runner/${action}`;
138
+ let options = { method: "POST", body: {}, tabId: target.tabId };
139
+ if (action === "refresh") {
140
+ path = "/api/app-runners";
141
+ options = { tabId: target.tabId };
142
+ } else if (action === "start") {
143
+ path = "/api/app-runner";
144
+ options.body = { runnerId };
145
+ } else if (action === "input") {
146
+ text = String(text ?? "");
147
+ options.body = { text, newline: !closeStdin || Boolean(text), closeStdin };
148
+ } else if (action === "context") {
149
+ lineCount = normalizeAppRunnerContextLineCount(lineCount === undefined || lineCount === null || lineCount === ""
150
+ ? getContextDraft(target.tabId, runId) : lineCount);
151
+ setContextDraft(target.tabId, runId, lineCount);
152
+ options.body = { lineCount };
153
+ }
154
+
155
+ let response;
156
+ try {
157
+ response = await api(path, options);
158
+ } catch (error) {
159
+ if (!isCurrent(token)) return { success: false, reason: "stale" };
160
+ if (action === "start") {
161
+ mergeData(target.tabId, owner, { activeRun: failureState(runnerId, error, owner.data) }, token);
162
+ if (!isCurrent(token)) return { success: false, reason: "stale" };
163
+ onRender({ tabs: true });
164
+ if (isCurrent(token)) addEvent(`app runner failed: ${cleanStatusText(error?.message || String(error))}`, "error");
165
+ } else if (action !== "refresh") {
166
+ const prefix = action === "input" ? "app runner input failed: "
167
+ : action === "context" ? "app runner context transfer failed: " : "";
168
+ addEvent(`${prefix}${error?.message || String(error)}`, "error");
169
+ }
170
+ return { success: false, reason: "error", error };
171
+ }
172
+ if (!isCurrent(token)) return { success: false, reason: "stale" };
173
+
174
+ const data = response.data || {};
175
+ let inputDraftCleared = false;
176
+ if (action === "input" && owner.input.get(runId) === submittedDraft
177
+ && getInputDraft(target.tabId, runId) === text) {
178
+ setInputDraft(target.tabId, runId, "");
179
+ inputDraftCleared = true;
180
+ }
181
+ if (!token.snapshotSuperseded) {
182
+ if (action === "context") {
183
+ if (data.activeRun) mergeData(target.tabId, owner, { activeRun: data.activeRun }, token);
184
+ } else {
185
+ mergeData(target.tabId, owner, data, token);
186
+ }
187
+ }
188
+ if (!isCurrent(token)) return { success: false, reason: "stale" };
189
+
190
+ // Context transfer schedules message/state refresh, without rebuilding runner widgets.
191
+ if (action !== "context") onRender({ tabs: ["start", "stop", "clear"].includes(action) });
192
+ if (!isCurrent(token)) return { success: false, reason: "stale" };
193
+ if (action === "start") addEvent(`started ${data.activeRun?.displayCommand || "app runner"}`, "info");
194
+ else if (action === "stop") addEvent("app runner stop requested", "warn");
195
+ else if (action === "input") addEvent(closeStdin ? "sent app runner EOF" : text ? "sent app runner input" : "sent app runner Enter", "info");
196
+ else if (action === "context") {
197
+ addEvent(data.delivery === "steer"
198
+ ? `sent last ${data.lineCount || lineCount} app runner output lines as live steering context`
199
+ : `added last ${data.lineCount || lineCount} app runner output lines to agent context`, "info");
200
+ if (isCurrent(token)) onRefreshContext(target);
201
+ }
202
+ return action === "input" ? { success: true, data, inputDraftCleared } : { success: true, data };
203
+ }
204
+
205
+ return {
206
+ getData,
207
+ applyData,
208
+ forgetTab(tabId) { owners.delete(tabId); },
209
+ refresh(target = captureTarget()) { return request("refresh", target); },
210
+ start(runnerId, target = captureTarget()) { return request("start", target, { runnerId }); },
211
+ stop(runId, target = captureTarget()) { return request("stop", target, { runId }); },
212
+ clear(runId, target = captureTarget()) { return request("clear", target, { runId }); },
213
+ sendInput(options, target = captureTarget()) { return request("input", target, options); },
214
+ transferContext(options, target = captureTarget()) { return request("context", target, options); },
215
+ getInputDraft,
216
+ setInputDraft,
217
+ getContextDraft,
218
+ setContextDraft,
219
+ };
220
+ }
@@ -1,4 +1,4 @@
1
- const CACHE_NAME = "pi-webui-pwa-v156";
1
+ const CACHE_NAME = "pi-webui-pwa-v200";
2
2
  const APP_SHELL = [
3
3
  "/",
4
4
  "/index.html",
@@ -7,6 +7,57 @@ const APP_SHELL = [
7
7
  "/issue-wizard-state.mjs",
8
8
  "/issue-bot-client.mjs",
9
9
  "/mobile-shell-state.mjs",
10
+ "/activity-events-controller.mjs",
11
+ "/activity-usage-controller.mjs",
12
+ "/activity-intercom-controller.mjs",
13
+ "/activity-todo-view.mjs",
14
+ "/activity-agents-controller.mjs",
15
+ "/activity-queue-controller.mjs",
16
+ "/project-git-tools-controller.mjs",
17
+ "/project-runners-controller.mjs",
18
+ "/project-file-viewer-controller.mjs",
19
+ "/project-artifact-controller.mjs",
20
+ "/settings-resource-controller.mjs",
21
+ "/settings-navigation-controller.mjs",
22
+ "/settings-navigation.css",
23
+ "/settings-workspace.mjs",
24
+ "/settings-workspace.css",
25
+ "/sidebar-update-menu.mjs",
26
+ "/sidebar-update-menu.css",
27
+ "/shell-actions.mjs",
28
+ "/conversation-overview.mjs",
29
+ "/conversation-overview.css",
30
+ "/themed-selects.css",
31
+ "/shell-workspace.mjs",
32
+ "/shell-workspace.css",
33
+ "/shell-tools-launcher.mjs",
34
+ "/shell-tools-launcher.css",
35
+ "/shell-attention-inbox.mjs",
36
+ "/shell-attention-inbox.css",
37
+ "/shell-context-actions.mjs",
38
+ "/shell-context-actions.css",
39
+ "/focused-composer-controls.mjs",
40
+ "/focused-composer-disclosure.mjs",
41
+ "/focused-composer-controls.css",
42
+ "/focused-shell-adapter.mjs",
43
+ "/focused-shell-adapter.css",
44
+ "/shell-navigation.mjs",
45
+ "/shell-navigation-resize.mjs",
46
+ "/shell-inspector-resize.mjs",
47
+ "/model-catalog-order.mjs",
48
+ "/shell-preferences.mjs",
49
+ "/shell-view-host.mjs",
50
+ "/shell-surfaces.mjs",
51
+ "/session-context.mjs",
52
+ "/session-shelf-state.mjs",
53
+ "/session-shelves.mjs",
54
+ "/draft-conversations.mjs",
55
+ "/workspace-choices.mjs",
56
+ "/session-shelves.css",
57
+ "/session-composer-store.mjs",
58
+ "/session-attention-scheduler.mjs",
59
+ "/platform-event-stream.mjs",
60
+ "/session-extension-requests.mjs",
10
61
  "/aur-review-payload.mjs",
11
62
  "/guided-git-command-state.mjs",
12
63
  "/guided-git-review-state.mjs",
@@ -0,0 +1,182 @@
1
+ const WORKING_INTERVAL = 1500;
2
+ const IDLE_INTERVAL = 10000;
3
+ const HIDDEN_INTERVAL = 30000;
4
+ const MENU_DELAY = 600;
5
+ const REQUEST_TIMEOUT = 10000;
6
+ const MAX_BACKOFF = 30000;
7
+
8
+ /**
9
+ * Reconcile tab metadata with one timer and one abortable refresh at a time.
10
+ * stop() permits a later sync()/request(); dispose() permanently ends ownership.
11
+ * An aborted refresh retains its slot until settlement, so refresh must honor
12
+ * the signal. The caller owns applying results and must also respect abortion.
13
+ */
14
+ export function createAttentionScheduler({
15
+ refresh,
16
+ getState,
17
+ onError = () => {},
18
+ setTimeout = globalThis.setTimeout,
19
+ clearTimeout = globalThis.clearTimeout,
20
+ } = {}) {
21
+ for (const [name, value] of Object.entries({ refresh, getState, onError, setTimeout, clearTimeout })) {
22
+ if (typeof value !== "function") throw new TypeError(`${name} must be a function`);
23
+ }
24
+
25
+ let enabled = true;
26
+ let disposed = false;
27
+ let timer = null;
28
+ let inFlight = null;
29
+ let automaticAt = null;
30
+ let manualAt = null;
31
+ let menuUntil = 0;
32
+ let retryAt = 0;
33
+ let backoff = 0;
34
+
35
+ function intervalFor(state) {
36
+ if (state.tabCount <= 0 || (!state.working && state.tabCount <= 1)) return null;
37
+ if (!state.visible) return HIDDEN_INTERVAL;
38
+ return state.working ? WORKING_INTERVAL : IDLE_INTERVAL;
39
+ }
40
+
41
+ function clearTimer() {
42
+ if (timer !== null) clearTimeout(timer.handle);
43
+ timer = null;
44
+ }
45
+
46
+ function setTimer(callback, at) {
47
+ clearTimer();
48
+ const owned = { at, handle: null };
49
+ timer = owned;
50
+ owned.handle = setTimeout(() => {
51
+ if (timer !== owned) return;
52
+ timer = null;
53
+ callback();
54
+ }, Math.max(0, at - Date.now()));
55
+ }
56
+
57
+ function stop() {
58
+ enabled = false;
59
+ clearTimer();
60
+ automaticAt = manualAt = null;
61
+ menuUntil = retryAt = backoff = 0;
62
+ if (inFlight !== null) {
63
+ inFlight.cancelled = true;
64
+ inFlight.controller.abort();
65
+ }
66
+ }
67
+
68
+ function reconcile() {
69
+ if (!enabled || disposed) return;
70
+ const state = getState();
71
+ if (state.tabCount <= 0) {
72
+ stop();
73
+ return;
74
+ }
75
+ if (inFlight !== null) return;
76
+
77
+ const interval = intervalFor(state);
78
+ automaticAt = interval === null ? null : Math.min(automaticAt ?? Infinity, Date.now() + interval);
79
+ const wantedAt = Math.min(automaticAt ?? Infinity, manualAt ?? Infinity);
80
+ if (wantedAt === Infinity) {
81
+ clearTimer();
82
+ return;
83
+ }
84
+ const at = Math.max(wantedAt, menuUntil, retryAt);
85
+ if (timer?.at !== at) setTimer(run, at);
86
+ }
87
+
88
+ function settle(owned, error) {
89
+ if (inFlight !== owned) return;
90
+ inFlight = null;
91
+ clearTimer();
92
+ if (owned.cancelled || !enabled || disposed) {
93
+ reconcile();
94
+ return;
95
+ }
96
+ const state = getState();
97
+ if (state.tabCount <= 0) {
98
+ stop();
99
+ return;
100
+ }
101
+
102
+ if (error !== null) {
103
+ backoff = Math.min(MAX_BACKOFF, Math.max(intervalFor(state) ?? WORKING_INTERVAL, backoff * 2));
104
+ retryAt = Date.now() + backoff;
105
+ manualAt = Math.min(manualAt ?? Infinity, retryAt);
106
+ try {
107
+ onError(error);
108
+ } catch {
109
+ // Error presentation must not strand the scheduler's owned resources.
110
+ }
111
+ } else {
112
+ backoff = retryAt = 0;
113
+ }
114
+ reconcile();
115
+ }
116
+
117
+ function run() {
118
+ if (!enabled || disposed || inFlight !== null) return;
119
+ const state = getState();
120
+ if (state.tabCount <= 0) {
121
+ stop();
122
+ return;
123
+ }
124
+ if (intervalFor(state) === null) automaticAt = null;
125
+ if (automaticAt === null && manualAt === null) return;
126
+ if (Math.min(automaticAt ?? Infinity, manualAt ?? Infinity) > Date.now()) {
127
+ reconcile();
128
+ return;
129
+ }
130
+ if (state.menuOpen) {
131
+ menuUntil = Date.now() + MENU_DELAY;
132
+ reconcile();
133
+ return;
134
+ }
135
+
136
+ automaticAt = manualAt = null;
137
+ menuUntil = 0;
138
+ const owned = { controller: new AbortController(), cancelled: false, timeoutError: null };
139
+ inFlight = owned;
140
+ setTimer(() => {
141
+ owned.timeoutError = new Error("Tab metadata refresh timed out after 10000ms");
142
+ owned.timeoutError.name = "TimeoutError";
143
+ owned.controller.abort(owned.timeoutError);
144
+ }, Date.now() + REQUEST_TIMEOUT);
145
+
146
+ let result;
147
+ try {
148
+ result = refresh({ signal: owned.controller.signal });
149
+ } catch (error) {
150
+ settle(owned, error ?? new Error("Tab metadata refresh failed"));
151
+ return;
152
+ }
153
+ Promise.resolve(result).then(
154
+ () => settle(owned, owned.timeoutError),
155
+ (error) => settle(owned, owned.timeoutError ?? error ?? new Error("Tab metadata refresh failed")),
156
+ );
157
+ }
158
+
159
+ return Object.freeze({
160
+ sync() {
161
+ if (disposed) return;
162
+ enabled = true;
163
+ reconcile();
164
+ },
165
+ request(delay = 0) {
166
+ if (disposed) return;
167
+ if (!Number.isFinite(delay) || delay < 0) throw new RangeError("delay must be a finite nonnegative number");
168
+ enabled = true;
169
+ if (getState().tabCount <= 0) {
170
+ stop();
171
+ return;
172
+ }
173
+ manualAt = Math.min(manualAt ?? Infinity, Date.now() + delay);
174
+ reconcile();
175
+ },
176
+ stop,
177
+ dispose() {
178
+ disposed = true;
179
+ stop();
180
+ },
181
+ });
182
+ }