toolroll 0.9.134 → 0.9.136

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 (277) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/acp-check-repo-schema.js +52 -0
  3. package/dist/acp-check.js +1 -1
  4. package/dist/acp-client.js +3 -3
  5. package/dist/acp-inspect.js +2 -1
  6. package/dist/agent-detect.js +1 -1
  7. package/dist/agent-fence.js +4 -4
  8. package/dist/agent-thread/chat-turn.js +2 -2
  9. package/dist/agent-thread/direct-host.js +2 -2
  10. package/dist/agent-thread/fence.js +2 -2
  11. package/dist/agent-thread/git-workspace.js +2 -2
  12. package/dist/agent-thread/guards.js +1 -1
  13. package/dist/agent-thread/providers.js +1 -1
  14. package/dist/agent-thread/ship.js +2 -2
  15. package/dist/approval-decision.js +1 -0
  16. package/dist/approval-password.js +1 -1
  17. package/dist/approval-summary.js +1 -1
  18. package/dist/attest.js +1 -1
  19. package/dist/batch-checks.js +2 -2
  20. package/dist/boot-identity.js +1 -1
  21. package/dist/bounded-spawn.js +2 -2
  22. package/dist/browser/{chunk-agents-live-view.e97fbf607cb8075aad7a48664556d11ea41469785f82384b5171b76c524f71e2.js → chunk-agents-live-view.9f4367c89c6366769a567e729ac9181ccaa898bf3a168d3dc618f3cface887c7.js} +4 -4
  23. package/dist/browser/chunk-agents-live-view.9f4367c89c6366769a567e729ac9181ccaa898bf3a168d3dc618f3cface887c7.js.br +0 -0
  24. package/dist/browser/chunk-agents-live-view.9f4367c89c6366769a567e729ac9181ccaa898bf3a168d3dc618f3cface887c7.js.gz +0 -0
  25. package/dist/browser/chunk-bundle.ac5952c82c76e2efcdcf5a097c4fa235d6f1045dcc36d02ee921ff4be976a46a.js +2 -0
  26. package/dist/browser/chunk-bundle.ac5952c82c76e2efcdcf5a097c4fa235d6f1045dcc36d02ee921ff4be976a46a.js.br +0 -0
  27. package/dist/browser/chunk-bundle.ac5952c82c76e2efcdcf5a097c4fa235d6f1045dcc36d02ee921ff4be976a46a.js.gz +0 -0
  28. package/dist/browser/chunk-chat-parts.2a0b0b723508c5c48379f6a3d441f07a18c8b91ed64fd018962931c5ae43331e.js +4 -0
  29. package/dist/browser/chunk-chat-parts.2a0b0b723508c5c48379f6a3d441f07a18c8b91ed64fd018962931c5ae43331e.js.br +0 -0
  30. package/dist/browser/chunk-chat-parts.2a0b0b723508c5c48379f6a3d441f07a18c8b91ed64fd018962931c5ae43331e.js.gz +0 -0
  31. package/dist/browser/{chunk-core.64343d638685133eb96578bfb35bf560f329d0743ac5deda720ae27f5699c9d9.js → chunk-core.5490609e81c3a5f78da3e06b9795d71c287016ebc7fd02794b1122b474ebb07f.js} +12 -12
  32. package/dist/browser/chunk-core.5490609e81c3a5f78da3e06b9795d71c287016ebc7fd02794b1122b474ebb07f.js.br +0 -0
  33. package/dist/browser/chunk-core.5490609e81c3a5f78da3e06b9795d71c287016ebc7fd02794b1122b474ebb07f.js.gz +0 -0
  34. package/dist/browser/{chunk-flow-view.264e801af330461985aadcab42bc4ac4e036ba124394a7b5a100f2cd1edf89f0.js → chunk-flow-view.f5d74c7f072b739a7a0ed86ff35cafa7b8a041233372d1eeaab9eb941ddfc11e.js} +7 -7
  35. package/dist/browser/chunk-flow-view.f5d74c7f072b739a7a0ed86ff35cafa7b8a041233372d1eeaab9eb941ddfc11e.js.br +0 -0
  36. package/dist/browser/chunk-flow-view.f5d74c7f072b739a7a0ed86ff35cafa7b8a041233372d1eeaab9eb941ddfc11e.js.gz +0 -0
  37. package/dist/browser/chunk-flows-extra-view.01ebf93780b729363eda11ba21c764fe593bcd3e684aa833c9b86147f780fd41.js +4 -0
  38. package/dist/browser/chunk-flows-extra-view.01ebf93780b729363eda11ba21c764fe593bcd3e684aa833c9b86147f780fd41.js.br +0 -0
  39. package/dist/browser/chunk-flows-extra-view.01ebf93780b729363eda11ba21c764fe593bcd3e684aa833c9b86147f780fd41.js.gz +0 -0
  40. package/dist/browser/chunk-pages-bundle.e18059f0cb4fbb63e3698971d4c1830ad0945c3645235babc93010cd0b725c1d.js +6 -0
  41. package/dist/browser/chunk-pages-bundle.e18059f0cb4fbb63e3698971d4c1830ad0945c3645235babc93010cd0b725c1d.js.br +0 -0
  42. package/dist/browser/chunk-pages-bundle.e18059f0cb4fbb63e3698971d4c1830ad0945c3645235babc93010cd0b725c1d.js.gz +0 -0
  43. package/dist/browser/chunk-result-view.fc6a6494b316aa786807b7d17035c59defae1bfb0c03bf9c3795679b3a35dd77.js +2 -0
  44. package/dist/browser/chunk-result-view.fc6a6494b316aa786807b7d17035c59defae1bfb0c03bf9c3795679b3a35dd77.js.br +0 -0
  45. package/dist/browser/chunk-result-view.fc6a6494b316aa786807b7d17035c59defae1bfb0c03bf9c3795679b3a35dd77.js.gz +0 -0
  46. package/dist/browser/chunk-settings-view.6dd3a64ded7bd8c047650270918dfb455c9a514a5a40b84c7eb5f443f76fe66f.js +20 -0
  47. package/dist/browser/chunk-settings-view.6dd3a64ded7bd8c047650270918dfb455c9a514a5a40b84c7eb5f443f76fe66f.js.br +0 -0
  48. package/dist/browser/chunk-settings-view.6dd3a64ded7bd8c047650270918dfb455c9a514a5a40b84c7eb5f443f76fe66f.js.gz +0 -0
  49. package/dist/browser/{chunk-shared.85e1b9e0838ccc819e7b8368f80dd5240dda90f53ea2974a256a8fa4122ba2fb.js → chunk-shared.02c0b692de21a9bb80d1761aa887d8532431171945c02e663884c9f45b796753.js} +2 -2
  50. package/dist/browser/chunk-shared.02c0b692de21a9bb80d1761aa887d8532431171945c02e663884c9f45b796753.js.br +0 -0
  51. package/dist/browser/chunk-shared.02c0b692de21a9bb80d1761aa887d8532431171945c02e663884c9f45b796753.js.gz +0 -0
  52. package/dist/browser/chunk-shared.0874336833f8101a63b169d8c2e55ca0f281e43e65d4bd6604555c791ea9dd87.js +2 -0
  53. package/dist/browser/chunk-shared.0874336833f8101a63b169d8c2e55ca0f281e43e65d4bd6604555c791ea9dd87.js.br +0 -0
  54. package/dist/browser/chunk-shared.0874336833f8101a63b169d8c2e55ca0f281e43e65d4bd6604555c791ea9dd87.js.gz +0 -0
  55. package/dist/browser/chunk-shared.2413dd78f32995fbca67f51ac8c21baf4727cd64f185ea739aa2a058e569b0ed.js +2 -0
  56. package/dist/browser/chunk-shared.2413dd78f32995fbca67f51ac8c21baf4727cd64f185ea739aa2a058e569b0ed.js.br +0 -0
  57. package/dist/browser/chunk-shared.2413dd78f32995fbca67f51ac8c21baf4727cd64f185ea739aa2a058e569b0ed.js.gz +0 -0
  58. package/dist/browser/{chunk-shared.26f6cbfdeb9bcd63231f23dbf96cacb39b78324aeed2503e86109efa89fa27db.js → chunk-shared.26bb0114998968cccb7bae5f6ffa8979ddecfafd8bc18bb6985760f6bcc030e6.js} +3 -3
  59. package/dist/browser/chunk-shared.26bb0114998968cccb7bae5f6ffa8979ddecfafd8bc18bb6985760f6bcc030e6.js.br +0 -0
  60. package/dist/browser/chunk-shared.26bb0114998968cccb7bae5f6ffa8979ddecfafd8bc18bb6985760f6bcc030e6.js.gz +0 -0
  61. package/dist/browser/chunk-shared.6d0b8728b3e309886cfb6eaf596d3f20592939e521bb60bb090824f34da6b086.js +2 -0
  62. package/dist/browser/chunk-shared.6d0b8728b3e309886cfb6eaf596d3f20592939e521bb60bb090824f34da6b086.js.br +0 -0
  63. package/dist/browser/chunk-shared.6d0b8728b3e309886cfb6eaf596d3f20592939e521bb60bb090824f34da6b086.js.gz +0 -0
  64. package/dist/browser/chunk-shared.c3e5be1c5f441e94905a4bc2005d816d2a0b0e4108bae43e37ec274a911c6847.js +2 -0
  65. package/dist/browser/chunk-shared.c3e5be1c5f441e94905a4bc2005d816d2a0b0e4108bae43e37ec274a911c6847.js.br +0 -0
  66. package/dist/browser/chunk-shared.c3e5be1c5f441e94905a4bc2005d816d2a0b0e4108bae43e37ec274a911c6847.js.gz +0 -0
  67. package/dist/browser/chunk-shared.d1f25785c8c168cc75aa99c4be8ca56abfc5eafa3490f8817ff15e61cb901915.js +2 -0
  68. package/dist/browser/chunk-shared.d1f25785c8c168cc75aa99c4be8ca56abfc5eafa3490f8817ff15e61cb901915.js.br +0 -0
  69. package/dist/browser/chunk-shared.d1f25785c8c168cc75aa99c4be8ca56abfc5eafa3490f8817ff15e61cb901915.js.gz +0 -0
  70. package/dist/browser/{chunk-shared.5b47ca221b8b77b26ce8006f0569c981df2b905005cebe9fc54444d4906d436e.js → chunk-shared.fd5f2699d3b0017797e5b5e1e1d92eb98818740ebf20a95364bbb7deea0c8242.js} +3 -3
  71. package/dist/browser/chunk-shared.fd5f2699d3b0017797e5b5e1e1d92eb98818740ebf20a95364bbb7deea0c8242.js.br +0 -0
  72. package/dist/browser/chunk-shared.fd5f2699d3b0017797e5b5e1e1d92eb98818740ebf20a95364bbb7deea0c8242.js.gz +0 -0
  73. package/dist/browser/{chunk-sonner.160372eb4f9455847ca83e8ff5d983c6b3010ef0dc2eaf541e2eaceaac3b994c.js → chunk-sonner.2472e1da55de10b11dc002c80a840966061e817c47793f5e216f1af6c6dbedff.js} +1 -1
  74. package/dist/browser/chunk-sonner.2472e1da55de10b11dc002c80a840966061e817c47793f5e216f1af6c6dbedff.js.br +0 -0
  75. package/dist/browser/chunk-sonner.2472e1da55de10b11dc002c80a840966061e817c47793f5e216f1af6c6dbedff.js.gz +0 -0
  76. package/dist/browser/chunk-task-view.bbeddc793a5e8a6d1f66b6cc5f0ce1da18414137e85c49ccd07be0e20f61ac12.js +2 -0
  77. package/dist/browser/chunk-task-view.bbeddc793a5e8a6d1f66b6cc5f0ce1da18414137e85c49ccd07be0e20f61ac12.js.br +0 -0
  78. package/dist/browser/chunk-task-view.bbeddc793a5e8a6d1f66b6cc5f0ce1da18414137e85c49ccd07be0e20f61ac12.js.gz +0 -0
  79. package/dist/browser/chunk-team-chat.c3255a5a1d94e39d559c07438c4690543602b1552b2c2bf57b8791d7f989141d.js +2 -0
  80. package/dist/browser/chunk-team-chat.c3255a5a1d94e39d559c07438c4690543602b1552b2c2bf57b8791d7f989141d.js.br +0 -0
  81. package/dist/browser/chunk-team-chat.c3255a5a1d94e39d559c07438c4690543602b1552b2c2bf57b8791d7f989141d.js.gz +0 -0
  82. package/dist/browser/manifest.json +194 -194
  83. package/dist/browser/workspace.3043c4a6df23ed1c0c8be3fb816fa9410a2ab99053eb54476f22a1735c03ca97.css +4 -0
  84. package/dist/browser/workspace.3043c4a6df23ed1c0c8be3fb816fa9410a2ab99053eb54476f22a1735c03ca97.css.br +0 -0
  85. package/dist/browser/workspace.3043c4a6df23ed1c0c8be3fb816fa9410a2ab99053eb54476f22a1735c03ca97.css.gz +0 -0
  86. package/dist/browser/{workspace.efd01c3aaf8e07c4a64194e2bfbd7aee4f7fa515f2acebdfdd90af1badba8ce7.js → workspace.aebb60d4e5ef4509a80cfaccf0af5f7246867ec7531a1734dd8e28c59594950e.js} +4 -4
  87. package/dist/browser/workspace.aebb60d4e5ef4509a80cfaccf0af5f7246867ec7531a1734dd8e28c59594950e.js.br +0 -0
  88. package/dist/browser/workspace.aebb60d4e5ef4509a80cfaccf0af5f7246867ec7531a1734dd8e28c59594950e.js.gz +0 -0
  89. package/dist/browser-open.js +1 -1
  90. package/dist/build-review.js +2 -2
  91. package/dist/builder.js +21 -14
  92. package/dist/canvas-capture.js +2 -2
  93. package/dist/canvas-freshness.js +1 -1
  94. package/dist/central-recovery-stage.js +1 -1
  95. package/dist/chat-actions.js +3 -3
  96. package/dist/chat-decide.js +8 -4
  97. package/dist/cli-help.js +8 -7
  98. package/dist/cli.js +2 -2
  99. package/dist/companion/bonjour.js +1 -1
  100. package/dist/companion/daemon.js +1 -1
  101. package/dist/companion/passkey-gate.js +1 -1
  102. package/dist/companion/reads.js +1 -1
  103. package/dist/companion/store.js +1 -1
  104. package/dist/companion/webauthn.js +1 -1
  105. package/dist/companion/work.js +1 -1
  106. package/dist/container-state.js +2 -2
  107. package/dist/containment.js +2 -2
  108. package/dist/contracts/chat-actions.js +1 -1
  109. package/dist/contracts/console-api.js +1 -1
  110. package/dist/contracts/engine-api.js +1 -1
  111. package/dist/controller-supervisor.js +2 -2
  112. package/dist/credential-broker.js +1 -1
  113. package/dist/demo.js +2 -2
  114. package/dist/easy-start.js +1 -1
  115. package/dist/egress.js +1 -1
  116. package/dist/engine-handoff.js +1 -1
  117. package/dist/engine-reads.js +1 -1
  118. package/dist/evals.js +2 -2
  119. package/dist/exec.js +4 -4
  120. package/dist/fast-owner-schema.js +33 -0
  121. package/dist/fast-start.js +1 -1
  122. package/dist/flow-unattended.js +2 -2
  123. package/dist/github-import.js +1 -1
  124. package/dist/github-read.js +1 -1
  125. package/dist/install-mode.js +2 -3
  126. package/dist/invoke.js +9 -7
  127. package/dist/laptop-background.js +1 -1
  128. package/dist/lead-capabilities.js +1 -1
  129. package/dist/live-backup-change.js +2 -2
  130. package/dist/live-backup.js +2 -2
  131. package/dist/live-terminal.js +3 -3
  132. package/dist/local-checks.js +1 -1
  133. package/dist/local-landing.js +22 -3
  134. package/dist/local-owner.js +1 -1
  135. package/dist/machine-identity.js +1 -1
  136. package/dist/model-catalog.js +8 -5
  137. package/dist/model-choices.js +3 -3
  138. package/dist/model-routing.js +1 -1
  139. package/dist/models-cli.js +2 -2
  140. package/dist/names.js +1 -1
  141. package/dist/onboard.js +1 -1
  142. package/dist/operate-remote-arguments.js +1 -1
  143. package/dist/operate.js +33 -16
  144. package/dist/orphan-sweep.js +1 -1
  145. package/dist/owner-mode.js +4 -0
  146. package/dist/peek-cli.js +2 -2
  147. package/dist/phase-routing.js +1 -1
  148. package/dist/pi-build.js +1 -1
  149. package/dist/plane-review.js +1 -1
  150. package/dist/planner-source.js +2 -2
  151. package/dist/planner.js +1 -1
  152. package/dist/pre-run-phase.js +1 -1
  153. package/dist/presence-hold.js +1 -1
  154. package/dist/process-liveness.js +1 -1
  155. package/dist/process-tree.js +1 -1
  156. package/dist/project-tools.js +2 -2
  157. package/dist/prompt.js +1 -1
  158. package/dist/proposal.js +1 -1
  159. package/dist/protected-storage.js +2 -2
  160. package/dist/provider-home.js +1 -1
  161. package/dist/provider-limits.js +1 -1
  162. package/dist/provider.js +2 -2
  163. package/dist/public-access.js +1 -1
  164. package/dist/pull-request-flow.js +2 -2
  165. package/dist/read-executor.js +1 -1
  166. package/dist/release-adapters.js +2 -2
  167. package/dist/release-carry.js +3 -3
  168. package/dist/release-resume.js +2 -2
  169. package/dist/release-start.js +1 -0
  170. package/dist/result-follow-ups.js +2 -2
  171. package/dist/review-switch.js +1 -1
  172. package/dist/route-change.js +25 -3
  173. package/dist/run-closeout.js +2 -2
  174. package/dist/runner.js +1 -1
  175. package/dist/sandbox-launch.js +2 -2
  176. package/dist/sandbox-runtime.js +1 -1
  177. package/dist/scope.js +1 -1
  178. package/dist/scout-browser.js +1 -1
  179. package/dist/serve.js +3 -3
  180. package/dist/server/chat.js +1 -1
  181. package/dist/server/direct-chat.js +1 -1
  182. package/dist/server/engine-api.js +1 -1
  183. package/dist/server/http.js +1 -1
  184. package/dist/server/one-time-secret.js +1 -1
  185. package/dist/server/route-table.js +1 -1
  186. package/dist/server/runtime.js +1 -1
  187. package/dist/server/settings-phone.js +1 -1
  188. package/dist/server/settings-section-table.js +1 -1
  189. package/dist/server/settings-sections.js +1 -1
  190. package/dist/server/settings.js +2 -1
  191. package/dist/server/task-view-data.js +3 -3
  192. package/dist/server/task-views.js +1 -1
  193. package/dist/server/tasks.js +5 -5
  194. package/dist/server/terminals.js +1 -1
  195. package/dist/settings-data.js +1 -1
  196. package/dist/settings-proofs.js +1 -1
  197. package/dist/shared-deps.js +4 -4
  198. package/dist/sign-in-page.js +2 -2
  199. package/dist/ssr-workspace.js +88 -88
  200. package/dist/staged-runtimes.js +1 -1
  201. package/dist/status-probe.js +2 -2
  202. package/dist/stop-proof.js +2 -2
  203. package/dist/storage-sweep-child.js +2 -2
  204. package/dist/storage-sweep-process.js +1 -1
  205. package/dist/storage.js +2 -2
  206. package/dist/store-baseline.js +5 -33
  207. package/dist/store.js +19 -14
  208. package/dist/subscription-usage.js +3 -3
  209. package/dist/surface.js +1 -1
  210. package/dist/test-temp.js +1 -1
  211. package/dist/tool-broker.js +1 -1
  212. package/dist/toolroll-update.js +3 -3
  213. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  214. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  215. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  216. package/dist/tui/linux-x64/toolroll-tui +0 -0
  217. package/dist/tui-launch.js +1 -1
  218. package/dist/welcome-facts.js +1 -1
  219. package/package.json +1 -1
  220. package/dist/browser/chunk-agents-live-view.e97fbf607cb8075aad7a48664556d11ea41469785f82384b5171b76c524f71e2.js.br +0 -0
  221. package/dist/browser/chunk-agents-live-view.e97fbf607cb8075aad7a48664556d11ea41469785f82384b5171b76c524f71e2.js.gz +0 -0
  222. package/dist/browser/chunk-bundle.48f442a2868e9b77e9f54c5b77f1bba629ccd1615de8a2f62619b811783314f6.js +0 -2
  223. package/dist/browser/chunk-bundle.48f442a2868e9b77e9f54c5b77f1bba629ccd1615de8a2f62619b811783314f6.js.br +0 -0
  224. package/dist/browser/chunk-bundle.48f442a2868e9b77e9f54c5b77f1bba629ccd1615de8a2f62619b811783314f6.js.gz +0 -0
  225. package/dist/browser/chunk-chat-parts.1669e6985c5c0c11eea6792ea177ea4c9f7e7ebf27bd3b31742feb6a26d5b2a5.js +0 -4
  226. package/dist/browser/chunk-chat-parts.1669e6985c5c0c11eea6792ea177ea4c9f7e7ebf27bd3b31742feb6a26d5b2a5.js.br +0 -0
  227. package/dist/browser/chunk-chat-parts.1669e6985c5c0c11eea6792ea177ea4c9f7e7ebf27bd3b31742feb6a26d5b2a5.js.gz +0 -0
  228. package/dist/browser/chunk-core.64343d638685133eb96578bfb35bf560f329d0743ac5deda720ae27f5699c9d9.js.br +0 -0
  229. package/dist/browser/chunk-core.64343d638685133eb96578bfb35bf560f329d0743ac5deda720ae27f5699c9d9.js.gz +0 -0
  230. package/dist/browser/chunk-flow-view.264e801af330461985aadcab42bc4ac4e036ba124394a7b5a100f2cd1edf89f0.js.br +0 -0
  231. package/dist/browser/chunk-flow-view.264e801af330461985aadcab42bc4ac4e036ba124394a7b5a100f2cd1edf89f0.js.gz +0 -0
  232. package/dist/browser/chunk-flows-extra-view.6761503a97e1f17b474703ff5687a8682c54f9db1715e0a9762a979030a1b036.js +0 -4
  233. package/dist/browser/chunk-flows-extra-view.6761503a97e1f17b474703ff5687a8682c54f9db1715e0a9762a979030a1b036.js.br +0 -0
  234. package/dist/browser/chunk-flows-extra-view.6761503a97e1f17b474703ff5687a8682c54f9db1715e0a9762a979030a1b036.js.gz +0 -0
  235. package/dist/browser/chunk-pages-bundle.365da73d009e3ced30b55bca7107f548dc832f7a9f52926d3dcd68aa5596da11.js +0 -6
  236. package/dist/browser/chunk-pages-bundle.365da73d009e3ced30b55bca7107f548dc832f7a9f52926d3dcd68aa5596da11.js.br +0 -0
  237. package/dist/browser/chunk-pages-bundle.365da73d009e3ced30b55bca7107f548dc832f7a9f52926d3dcd68aa5596da11.js.gz +0 -0
  238. package/dist/browser/chunk-result-view.d4dc562a1a6a52a1497e25300d5f80c220952ceb5bb719ca32ef8dc1e74a4124.js +0 -2
  239. package/dist/browser/chunk-result-view.d4dc562a1a6a52a1497e25300d5f80c220952ceb5bb719ca32ef8dc1e74a4124.js.br +0 -0
  240. package/dist/browser/chunk-result-view.d4dc562a1a6a52a1497e25300d5f80c220952ceb5bb719ca32ef8dc1e74a4124.js.gz +0 -0
  241. package/dist/browser/chunk-settings-view.ff302e1c5faf5486c96e5fc96fa32492da4153e6e19997ce7b718adab21bf3b7.js +0 -20
  242. package/dist/browser/chunk-settings-view.ff302e1c5faf5486c96e5fc96fa32492da4153e6e19997ce7b718adab21bf3b7.js.br +0 -0
  243. package/dist/browser/chunk-settings-view.ff302e1c5faf5486c96e5fc96fa32492da4153e6e19997ce7b718adab21bf3b7.js.gz +0 -0
  244. package/dist/browser/chunk-shared.152678a803cfb6dee935162fbbbdb38d031d80f1d32ce48610f37bc1c8621e49.js +0 -2
  245. package/dist/browser/chunk-shared.152678a803cfb6dee935162fbbbdb38d031d80f1d32ce48610f37bc1c8621e49.js.br +0 -0
  246. package/dist/browser/chunk-shared.152678a803cfb6dee935162fbbbdb38d031d80f1d32ce48610f37bc1c8621e49.js.gz +0 -0
  247. package/dist/browser/chunk-shared.26f6cbfdeb9bcd63231f23dbf96cacb39b78324aeed2503e86109efa89fa27db.js.br +0 -0
  248. package/dist/browser/chunk-shared.26f6cbfdeb9bcd63231f23dbf96cacb39b78324aeed2503e86109efa89fa27db.js.gz +0 -0
  249. package/dist/browser/chunk-shared.4e21c6b33b9a525e63c360d20a1830f1a26c5021f5d218f2300f21ff840af27e.js +0 -2
  250. package/dist/browser/chunk-shared.4e21c6b33b9a525e63c360d20a1830f1a26c5021f5d218f2300f21ff840af27e.js.br +0 -0
  251. package/dist/browser/chunk-shared.4e21c6b33b9a525e63c360d20a1830f1a26c5021f5d218f2300f21ff840af27e.js.gz +0 -0
  252. package/dist/browser/chunk-shared.5b47ca221b8b77b26ce8006f0569c981df2b905005cebe9fc54444d4906d436e.js.br +0 -0
  253. package/dist/browser/chunk-shared.5b47ca221b8b77b26ce8006f0569c981df2b905005cebe9fc54444d4906d436e.js.gz +0 -0
  254. package/dist/browser/chunk-shared.85e1b9e0838ccc819e7b8368f80dd5240dda90f53ea2974a256a8fa4122ba2fb.js.br +0 -0
  255. package/dist/browser/chunk-shared.85e1b9e0838ccc819e7b8368f80dd5240dda90f53ea2974a256a8fa4122ba2fb.js.gz +0 -0
  256. package/dist/browser/chunk-shared.a326d625dea5cda744678a73b38c0cb2688721c9228e26d262279ecd5c2d7d11.js +0 -2
  257. package/dist/browser/chunk-shared.a326d625dea5cda744678a73b38c0cb2688721c9228e26d262279ecd5c2d7d11.js.br +0 -0
  258. package/dist/browser/chunk-shared.a326d625dea5cda744678a73b38c0cb2688721c9228e26d262279ecd5c2d7d11.js.gz +0 -0
  259. package/dist/browser/chunk-shared.e906e9c8c0859e000616dbc382f88597447f30205c92b7cb9a8e2351f3ef2722.js +0 -2
  260. package/dist/browser/chunk-shared.e906e9c8c0859e000616dbc382f88597447f30205c92b7cb9a8e2351f3ef2722.js.br +0 -0
  261. package/dist/browser/chunk-shared.e906e9c8c0859e000616dbc382f88597447f30205c92b7cb9a8e2351f3ef2722.js.gz +0 -0
  262. package/dist/browser/chunk-shared.f6354151d62439f2d78f5d17cf9bc44f35b4da37685beb77467d98dd9cc6f1e4.js +0 -2
  263. package/dist/browser/chunk-shared.f6354151d62439f2d78f5d17cf9bc44f35b4da37685beb77467d98dd9cc6f1e4.js.br +0 -0
  264. package/dist/browser/chunk-shared.f6354151d62439f2d78f5d17cf9bc44f35b4da37685beb77467d98dd9cc6f1e4.js.gz +0 -0
  265. package/dist/browser/chunk-sonner.160372eb4f9455847ca83e8ff5d983c6b3010ef0dc2eaf541e2eaceaac3b994c.js.br +0 -0
  266. package/dist/browser/chunk-sonner.160372eb4f9455847ca83e8ff5d983c6b3010ef0dc2eaf541e2eaceaac3b994c.js.gz +0 -0
  267. package/dist/browser/chunk-task-view.325b506afc26b25147b2e90cec5ad1392d50e6150a7fb33c81a996daa99bb05a.js +0 -2
  268. package/dist/browser/chunk-task-view.325b506afc26b25147b2e90cec5ad1392d50e6150a7fb33c81a996daa99bb05a.js.br +0 -0
  269. package/dist/browser/chunk-task-view.325b506afc26b25147b2e90cec5ad1392d50e6150a7fb33c81a996daa99bb05a.js.gz +0 -0
  270. package/dist/browser/chunk-team-chat.d560bcc5d819e63133d377b8a6f10f901356e680771f19d4fe1af044adfffb22.js +0 -2
  271. package/dist/browser/chunk-team-chat.d560bcc5d819e63133d377b8a6f10f901356e680771f19d4fe1af044adfffb22.js.br +0 -0
  272. package/dist/browser/chunk-team-chat.d560bcc5d819e63133d377b8a6f10f901356e680771f19d4fe1af044adfffb22.js.gz +0 -0
  273. package/dist/browser/workspace.ac1270b58f672fa920535348cc582f5fc68247b341d6fc8ec733b25336f2b9cc.css +0 -4
  274. package/dist/browser/workspace.ac1270b58f672fa920535348cc582f5fc68247b341d6fc8ec733b25336f2b9cc.css.br +0 -0
  275. package/dist/browser/workspace.ac1270b58f672fa920535348cc582f5fc68247b341d6fc8ec733b25336f2b9cc.css.gz +0 -0
  276. package/dist/browser/workspace.efd01c3aaf8e07c4a64194e2bfbd7aee4f7fa515f2acebdfdd90af1badba8ce7.js.br +0 -0
  277. package/dist/browser/workspace.efd01c3aaf8e07c4a64194e2bfbd7aee4f7fa515f2acebdfdd90af1badba8ce7.js.gz +0 -0
@@ -1 +1 @@
1
- import{createHash}from"node:crypto";import{loosens,phoneApprovalPolicyOf,phoneApprovalWords,setPhoneApprovalPolicy}from"../companion/passkey-gate.js";import{getPairedDevice}from"../companion/store.js";import{CONSOLE_FORMS,checkResponse,readForm}from"../contracts/console-api.js";import{isPhoneApprovalWindow,PHONE_APPROVAL_WINDOWS}from"../phone-approvals-schema.js";import{encodeQr}from"../qr.js";import{authenticateAccount}from"../scope.js";import{relativeAge}from"./chrome-helpers.js";import{handlersOf}from"./handler-registry.js";import{redirect,respond}from"./http.js";import{oneTimePhonePairScreen,settingsViewScreen}from"./one-time-secret.js";import{cancelPairing,confirmPairing,isPasskeyEnrollmentOpen,listPasskeys,listPhones,openPasskeyEnrollment,pairingView,parsePasskeyWindowMinutes,passkeyWindowMinutes,pathStates,removePhone,renamePhone,revokePasskey,savePasskeyWindow,endPasskeyWindows,startPairing,openPasskeySetupForPairedPhone,closePasskeySetup}from"./phone-engine-api.js";import{refuse}from"./refuse.js";import{browserCaller}from"./session.js";const COMPANION_DOCS_URL="https://github.com/ap9000/toolroll/blob/main/docs/companion-app.md",DEFAULT_RELAY_HOST="relay.toolroll.dev",PHONE_NAME_MAX=48,PASSKEY_PROMPTS=[0,15,60],promptLabel=minutes=>minutes===0?"Every approval":minutes===15?"Once per 15 minutes":"Once per hour";function bindingOf(who){return`${who.name}:${who.session.generation}:${createHash("sha256").update(who.session.csrf).digest("base64url").slice(0,22)}`}function qrSvgData(text){const code=encodeQr(text,"M"),border=4,dim=code.size+border*2;let path="";for(let y=0;y<code.size;y++)for(let x=0;x<code.size;x++)code.dark(x,y)&&(path+=`M${x+border},${y+border}h1v1h-1z`);return{dim,path}}export function spokenCode(code){return code.split("-").map(half=>half.split("").join(" ")).join(", ")}function pairedOn(iso){const at=new Date(iso);return Number.isNaN(at.getTime())?iso:at.toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hourCycle:"h23"})}const RETIRED_WORDS={removed:"Removed",password_changed:"Signed out when your password changed",access_changed:"Signed out when your access changed",restored:"Signed out when this workspace was restored",migration:"Signed out by a Toolroll update",contested:"Not paired: another device used the code",pairing_failed:"Pairing didn't finish"};export const PHONE_PAIRING_SCRIPT=`(function(){var first=document.getElementById("phone-pairing");if(!first)return;var id=first.getAttribute("data-pairing")||"";var deadline=Date.now()+Number(first.getAttribute("data-left-ms")||0);var done=false,misses=0;function root(){return document.getElementById("phone-pairing");}function each(sel,fn){var r=root();if(r)Array.prototype.forEach.call(r.querySelectorAll(sel),fn);}function show(name){var r=root();if(!r)return;if(name==="scan"&&!r.querySelector('[data-view="scan"]'))name="waiting";each("[data-view]",function(v){v.hidden=v.getAttribute("data-view")!==name;});r.setAttribute("data-shown",name);}function leave(){if(done)return;done=true;if(location.pathname==="/settings/phone"){history.replaceState(null,"","/settings/phone#phone-pair");location.reload();}else location.replace("/settings/phone#phone-pair");}function clock(){if(done)return;var left=Math.max(0,Math.ceil((deadline-Date.now())/1000));var m=Math.floor(left/60),s=left%60;var words=left>0?"Expires in "+m+":"+(s<10?"0":"")+s:"This code expired.";each("[data-phone-expires]",function(e){e.textContent=words;});setTimeout(clock,1000);}function spell(c){return c.split("-").map(function(h){return h.split("").join(" ");}).join(", ");}function lead(n){return n&&n.trim()!==""&&n!=="iPhone"?"\\u201c"+n+"\\u201d should be showing this code:":"Your iPhone should be showing this code:";}function apply(v){var s=v&&v.status;if(s==="awaiting_scan"||s==="awaiting_ready")return show("scan");if(s==="awaiting_confirm"){var c=String(v.confirmCode||"");each("[data-phone-code]",function(e){e.textContent=c;});each("[data-phone-code-spoken]",function(e){e.textContent=spell(c);});each("[data-phone-device]",function(e){e.textContent=lead(v.deviceName);});return show("code");}if(s==="confirming")return show("confirming");if(s==="finishing")return show("finishing");leave();}function poll(){if(done)return;if(document.hidden){setTimeout(poll,1000);return;}fetch("/settings/phone/pairings/"+encodeURIComponent(id),{credentials:"same-origin",cache:"no-store",redirect:"manual",headers:{accept:"application/json"}}).then(function(r){if(r.status===404||r.type==="opaqueredirect"){leave();return null;}if(!r.ok)throw 0;return r.json();}).then(function(v){if(v===null)return;misses=0;apply(v);if(!done)setTimeout(poll,1000);}).catch(function(){misses++;if(misses>20)return leave();setTimeout(poll,Math.min(10000,1000*misses));});}clock();setTimeout(poll,1000);})();(function(){if(!document.getElementById("phone-passkey-wait")||document.getElementById("phone-pairing"))return;var done=false,misses=0;function check(){if(done)return;if(document.hidden){setTimeout(check,3000);return;}fetch("/settings/phone",{credentials:"same-origin",cache:"no-store",redirect:"manual",headers:{accept:"text/html"}}).then(function(r){if(r.type==="opaqueredirect"||!r.ok)throw 0;return r.text();}).then(function(t){misses=0;if(t.indexOf('id="phone-passkey-wait"')<0){done=true;location.reload();return;}setTimeout(check,3000);}).catch(function(){misses++;if(misses>20)return;setTimeout(check,Math.min(15000,3000*misses));});}setTimeout(check,3000);})();`;export function createPhoneSettingsHandlers(runtime,deps){const{store}=runtime,mac=(deps.platform??process.platform)==="darwin",thisMac=mac?"this Mac":"this computer",ThisMac=mac?"This Mac":"This computer",openPairings=new Map,passwordHolds=(who,password)=>{const proved=authenticateAccount(store,who.name,password);return proved.ok&&proved.role==="approver"&&proved.generation===who.session.generation},hasPassword=who=>store.accountOf(who.name)?.passwordSet===!0,passwordProblem=who=>hasPassword(who)?"Enter your Toolroll password.":"Set a password to pair a phone.",runBy=host=>host===DEFAULT_RELAY_HOST?"run by Toolroll":"the relay this Toolroll is set up to use (TOOLROLL_RELAY_URL)",outcomeInfo=view=>{switch(view.status){case"paired":return{tone:"info",text:"Your iPhone is paired. Open the Toolroll app to see your work."};case"cancelled":return{tone:"info",text:"Pairing cancelled."};case"expired":return{tone:"notice",text:"That pairing code expired. Pair again."};case"contested":return{tone:"notice",text:"Another device used this code, so pairing stopped. Pair again and keep the code to yourself."};case"failed":return{tone:"notice",text:view.error===null?"Pairing didn't finish. Pair again.":`Pairing didn't finish: ${view.error} Pair again.`};default:return null}};function buildPhoneView(who,options={}){const access=deps.access,on=access.enabled(),service=access.service(),now=runtime.clock(),operator=store.isInstanceOperator(who.name),passworded=hasPassword(who),hostedChoice=access.hostedChoice(),hostedHost=hostedChoice.ok?new URL(hostedChoice.url).host:null,paths=service===null?null:pathStates(service),direct=paths?.direct??null,hosted=paths?.hosted??{state:"off",superseded:!1},directWorks=direct!==null&&direct.state==="listening"&&direct.addresses.length>0,hostedWorks=hosted.state==="connected",reachable=on&&(directWorks||hostedWorks),hostedApprovalStaleText=on&&access.hostedApprovalStale()?hostedHost===null?`Connecting from anywhere is off on ${thisMac} now (TOOLROLL_RELAY_URL=off).`:`This Toolroll's relay setting changed to ${hostedHost}. Phones connect only on ${thisMac}'s network until you approve the new relay below.`:null,directSummary=!passworded||!on||direct===null||direct.state==="off"?null:direct.state==="failed"?{title:`On ${thisMac}'s network`,failed:{what:direct.port===null?"Toolroll couldn't start listening for phones":`Toolroll couldn't open port ${direct.port}`,error:(direct.error??"unknown error").replace(/\.+$/,""),portCommand:direct.port===null?null:"TOOLROLL_PHONE_PORT=4300 toolroll",hostedWorks},firewallText:""}:{title:`On ${thisMac}'s network`,...direct.addresses.length===0?{noAddressText:`${ThisMac} isn't on a network a phone can reach right now. Join Wi-Fi.`}:{addresses:direct.addresses.map(one=>({label:one.kind==="tailnet"?"Tailscale":"Wi-Fi / Ethernet",address:direct.port===null||one.address.includes(":")?one.address:`${one.address}:${direct.port}`}))},tailscaleNotFound:direct.tailscale==="not_found",firewallText:`${mac?"If macOS asks whether Toolroll may accept incoming connections, click Allow. ":"If a firewall asks whether Toolroll may accept incoming connections, allow it. "}Phones can't reach ${thisMac} while it's asleep.`},hostedHostUrl=hosted.state!=="off"?new URL(hosted.relay).host:"",hostedSummary=!passworded||!on||direct===null?null:hosted.state==="off"?{offText:hostedHost!==null?`Off. Your phone connects only on ${thisMac}'s network.`:`Off (TOOLROLL_RELAY_URL=off). Your phone connects only on ${thisMac}'s network.`,host:"",runBy:"",statusWords:"",superseded:!1}:{offText:null,host:hostedHostUrl,runBy:runBy(hostedHostUrl),statusWords:hosted.state==="connected"?"Connected.":hosted.state==="unreachable"?`Can't reach it right now (${hosted.error}); Toolroll keeps trying.`:"Connecting…",superseded:hosted.superseded===!0},activePasskeys=(passworded?listPasskeys(store,who.name):[]).filter(k=>k.revokedAt===null);let lastStepSaid=!1;const lastStepOpen=()=>passworded&&activePasskeys.length===0&&isPasskeyEnrollmentOpen(service,who.name),binding=bindingOf(who);let pair=null;if(passworded){const opened=openPairings.get(binding);let open=null,restarted=!1;opened!==void 0&&(open=opened.service===service&&service!==null?pairingView(service,opened.id,binding):null,open===null&&(restarted=opened.service!==service,openPairings.delete(binding)));const live=open!==null&&["awaiting_scan","awaiting_ready","awaiting_confirm","confirming","finishing"].includes(open.status);if(open!==null&&live)pair={live:{pairSessionId:open.pairSessionId,status:open.status,confirmCode:open.confirmCode??null,deviceName:open.deviceName??null,leftMs:Math.max(0,open.expiresAtMs-now.getTime()),setsUpApprovals:activePasskeys.length===0},outcome:null,lastStepWait:!1,reachable,whyNotReachable:null};else{open!==null&&openPairings.delete(binding),open!==null&&open.status!=="paired"&&opened?.passkeyWindow!==void 0&&closePasskeySetup(service,who.name,opened.passkeyWindow);const paired=options.problem===void 0&&open!==null&&open.status==="paired";let outcome=null,lastStepWait=!1;options.problem===void 0&&(paired&&lastStepOpen()?(outcome={tone:"info",text:"Your iPhone is paired."},lastStepWait=!0,lastStepSaid=!0):open!==null?outcome=outcomeInfo(open):restarted&&(outcome={tone:"notice",text:"Pairing stopped because phone access restarted. Pair again."}));const whyNotReachable=reachable?null:on?hosted.state==="starting"&&!directWorks?`Connecting to ${new URL(hosted.relay).host}… Reload this page in a moment.`:direct!==null&&direct.state==="failed"&&!hostedWorks?hostedHost!==null&&!access.hostedEnabled()?"Direct connections aren't working (see above). Turn on connecting from anywhere to pair now.":`Direct connections aren't working (see above), so a phone can't reach ${thisMac} yet.`:`A phone has no way to reach ${thisMac} yet. Join Wi-Fi${hostedHost!==null?", or connect from anywhere":""}.`:operator?"Turn on phone access first.":"Ask whoever runs this Toolroll to turn on phone access.";pair={live:null,outcome,lastStepWait,reachable,whyNotReachable}}}const phones=listPhones(store,{accountName:who.name},now),currentPhones=phones.filter(one=>one.state!=="retired"),retiredPhones=phones.filter(one=>one.state==="retired"),enrollmentOpen=isPasskeyEnrollmentOpen(service,who.name),windowMins=passkeyWindowMinutes(store);return{thisMac,ThisMac,on,operator,passworded,notOnStoreUrl:COMPANION_DOCS_URL,accessProblems:passworded?access.problems():[],hostedApprovalStaleText,directSummary,hostedSummary,hostedHost,hostedEnabled:access.hostedEnabled(),pair,devices:{showSection:phones.length>0||passworded,current:currentPhones.map(phone=>{const seen=phone.lastSeenAt===null?"never connected":`last connected ${relativeAge(phone.lastSeenAt,now)}`,policy=phoneApprovalPolicyOf(store,phone.deviceId);return{deviceId:phone.deviceId,name:phone.name,sub:phone.state==="finishing"?`Finishing on the iPhone… · paired ${pairedOn(phone.pairedAt)}`:`Paired ${pairedOn(phone.pairedAt)} · ${seen} · Approvals: ${phoneApprovalWords(policy.minutes).toLowerCase()}`,state:phone.state,minutes:policy.minutes,minuteChoices:PHONE_APPROVAL_WINDOWS.map(m=>[String(m),phoneApprovalWords(m)])}}),retired:retiredPhones.map(phone=>({deviceId:phone.deviceId,name:phone.name,sub:`${RETIRED_WORDS[phone.retiredReason??"removed"]} · paired ${pairedOn(phone.pairedAt)}`}))},passkeys:{showSection:passworded&&(currentPhones.length>0||activePasskeys.length>0),enrollmentOpen,lastStepSaid,stateText:activePasskeys.length===0?"Not set up":`${activePasskeys.length} active · ${promptLabel(windowMins)}`,canEnable:!enrollmentOpen&&on&&currentPhones.length>0,enableLabel:activePasskeys.length===0?"Set up a passkey on iPhone":"Add another passkey",active:activePasskeys.map(k=>({credentialId:k.credentialId,label:k.label,sub:k.lastUsedAt===null?`Registered ${pairedOn(k.createdAt)} · not used yet`:`Registered ${pairedOn(k.createdAt)} · last used ${relativeAge(k.lastUsedAt,now)}`})),promptText:promptLabel(windowMins),windowMinutes:windowMins,windowChoices:PASSKEY_PROMPTS.map(m=>[String(m),promptLabel(m)])}}}const render=(response,status,who,options={})=>{const data=buildPhoneView(who,options),followPairing=data.pair?.live!==null||data.pair?.lastStepWait===!0||data.passkeys.enrollmentOpen&&data.passkeys.active.length===0;return runtime.sendScreen(response,status,settingsViewScreen("Phone",{kind:"settings-phone",data,said:null,problem:options.problem??null},{chrome:runtime.chromeFor(null,"settings"),sensitive:!0,...followPairing?{functional:{script:PHONE_PAIRING_SCRIPT,fetches:!0}}:{}}))};async function phonePage(ctx){return render(ctx.response,200,browserCaller(ctx.who))}async function pairingJson(ctx){const who=browserCaller(ctx.who),id=ctx.url.pathname.slice(25),service=deps.access.service(),view=service===null?null:pairingView(service,id,bindingOf(who));return view===null?respond(ctx.response,404,"application/json; charset=utf-8",JSON.stringify({error:"not_found"})):respond(ctx.response,200,"application/json; charset=utf-8",JSON.stringify(checkResponse("phonePairingView",view)))}async function accessAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phoneAccess);if(body.getAll("password").length>1||body.getAll("act").length!==1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});const act=body.get("act");if(act!=="on"&&act!=="off"&&act!=="hosted-on"&&act!=="hosted-off")return render(ctx.response,400,who,{problem:"Choose on or off."});if(body.getAll("hosted").length>1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});if(!store.isInstanceOperator(who.name))return render(ctx.response,403,who,{problem:"An instance operator turns phone access on or off."});if(!passwordHolds(who,body.get("password")??""))return render(ctx.response,403,who,{problem:passwordProblem(who)});const change=act==="on"?{act,hosted:body.get("hosted")==="1"}:{act},applied=await deps.access.change(change,who.name,runtime.clock(),()=>store.isInstanceOperator(who.name)&&store.accountOf(who.name)?.generation===who.session.generation);return applied==="not_on"?render(ctx.response,409,who,{problem:"Phone access is off now. Turn it on first."}):applied==="not_allowed"?render(ctx.response,403,who,{problem:"An instance operator turns phone access on or off."}):redirect(ctx.response,"/settings/phone")}async function pairAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phonePair);if(body.getAll("password").length>1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});if(!passwordHolds(who,body.get("password")??""))return render(ctx.response,403,who,{problem:passwordProblem(who)});const service=deps.access.service();if(service===null)return render(ctx.response,409,who,{problem:"Turn on phone access first."});const binding=bindingOf(who),started=startPairing(service,who.name,binding,who.session.generation);if(!started.ok)return render(ctx.response,409,who,{problem:started.error});openPairings.set(binding,{id:started.qr.pairSessionId,service});const qrPayload=JSON.stringify(started.qr),activePasskeys=listPasskeys(store,who.name).filter(k=>k.revokedAt===null);return runtime.sendScreen(ctx.response,200,oneTimePhonePairScreen({chrome:runtime.chromeFor(null,"settings"),pairSessionId:started.qr.pairSessionId,thisMac,ThisMac,leftMs:Math.max(0,started.expiresAtMs-runtime.clock().getTime()),qrSvg:qrSvgData(qrPayload),qrPayload,setsUpApprovals:activePasskeys.length===0,script:PHONE_PAIRING_SCRIPT}))}const pairingAct=op=>async ctx=>{const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phonePairing),pairing=body.getAll("pairing").length===1?body.get("pairing")??"":"",binding=bindingOf(who),service=deps.access.service(),opened=openPairings.get(binding);if(service===null||pairing===""||opened===void 0||opened.id!==pairing||opened.service!==service)return refuse(ctx.response,who,409,"That pairing isn't open any more. Pair again.","/settings/phone");if(op==="cancel")return cancelPairing(service,pairing,binding),redirect(ctx.response,"/settings/phone#phone-pair");const confirmed=await confirmPairing(service,pairing,binding);if(!confirmed.ok)return render(ctx.response,409,who,{problem:confirmed.error});const setup=body.getAll("setup").length===1&&body.get("setup")==="1"?openPasskeySetupForPairedPhone(service,store,who.name,who.session.generation,confirmed.deviceId):null;return setup!==null&&openPairings.set(binding,{...opened,passkeyWindow:setup.windowId}),redirect(ctx.response,"/settings/phone#phone-pair")};async function renameAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phoneRename);if(body.getAll("device").length!==1||body.getAll("name").length!==1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});const name=(body.get("name")??"").trim();return name.length===0||name.length>PHONE_NAME_MAX?render(ctx.response,400,who,{problem:`Name the phone in 1 to ${PHONE_NAME_MAX} characters.`}):renamePhone(store,body.get("device")??"",name,who.name)?redirect(ctx.response,"/settings/phone#phone-devices"):render(ctx.response,404,who,{problem:"That phone isn't paired."})}async function approvalsAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phoneApprovals);if(body.getAll("password").length>1||body.getAll("device").length!==1||body.getAll("minutes").length!==1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});const minutes=Number(body.get("minutes"));if(!isPhoneApprovalWindow(minutes))return render(ctx.response,400,who,{problem:"Choose Ask every time, or once every 15 minutes, hour or 8 hours."});const deviceId=body.get("device")??"",now=runtime.clock(),saved=store.transact(()=>{const phone=getPairedDevice(store.handle,deviceId);if(phone===null||phone.accountName!==who.name||phone.revokedAt!==null)return"missing";const before=phoneApprovalPolicyOf(store,deviceId);return before.minutes===minutes&&before.source==="phone"?"same":loosens(before,minutes)&&!passwordHolds(who,body.get("password")??"")?"password":(setPhoneApprovalPolicy(store,{deviceId,minutes,by:who.name,via:"mac",now}),"changed")});return saved==="missing"?render(ctx.response,404,who,{problem:"That phone isn't paired."}):saved==="password"?render(ctx.response,403,who,{problem:passwordProblem(who)}):(saved==="changed"&&endPasskeyWindows(deps.access.service()),redirect(ctx.response,"/settings/phone#phone-devices"))}async function removeAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phoneRemove);return body.getAll("password").length>1||body.getAll("device").length!==1?render(ctx.response,400,who,{problem:"Submit one value for each field."}):passwordHolds(who,body.get("password")??"")?removePhone(deps.access.service(),store,body.get("device")??"",who.name,runtime.clock())?redirect(ctx.response,"/settings/phone#phone-devices"):render(ctx.response,404,who,{problem:"That phone isn't paired."}):render(ctx.response,403,who,{problem:passwordProblem(who)})}async function passkeyEnableAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phonePasskeyEnable);if(body.getAll("password").length>1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});if(!passwordHolds(who,body.get("password")??""))return render(ctx.response,403,who,{problem:passwordProblem(who)});const service=deps.access.service();return service===null?render(ctx.response,409,who,{problem:"Turn on phone access first."}):openPasskeyEnrollment(service,who.name)===null?render(ctx.response,409,who,{problem:"Passkey enrollment isn't available right now."}):redirect(ctx.response,"/settings/phone#phone-passkeys")}async function passkeyRevokeAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phonePasskeyRevoke);return body.getAll("password").length>1||body.getAll("credential").length!==1?render(ctx.response,400,who,{problem:"Submit one value for each field."}):passwordHolds(who,body.get("password")??"")?revokePasskey(store,body.get("credential")??"",who.name,runtime.clock(),deps.access.service())?redirect(ctx.response,"/settings/phone#phone-passkeys"):render(ctx.response,404,who,{problem:"That passkey isn't active."}):render(ctx.response,403,who,{problem:passwordProblem(who)})}async function passkeyWindowAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phonePasskeyWindow);if(body.getAll("password").length>1||body.getAll("window").length!==1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});const wanted=parsePasskeyWindowMinutes(body.get("window"));if(wanted===null)return render(ctx.response,400,who,{problem:"Choose Every approval, Once per 15 minutes, or Once per hour."});const now=runtime.clock(),saved=store.transact(()=>{if(!store.isInstanceOperator(who.name))return"operator";if(!passwordHolds(who,body.get("password")??""))return"password";const before=passkeyWindowMinutes(store);return before===wanted?"same":(savePasskeyWindow(store,wanted),store.recordAction({at:now.toISOString(),actor:who.name,repo:null,taskId:null,runId:null,action:"passkey prompt changed",outcome:"changed",source:"policy",detail:`${promptLabel(before)} → ${promptLabel(wanted)}`}),"changed")});return saved==="operator"?render(ctx.response,403,who,{problem:"An instance operator sets the passkey prompt."}):saved==="password"?render(ctx.response,403,who,{problem:passwordProblem(who)}):(saved==="changed"&&endPasskeyWindows(deps.access.service()),redirect(ctx.response,"/settings/phone#phone-passkeys"))}return{registrations:handlersOf("settings",{"settings.phone":phonePage,"settings.phone-pairing":pairingJson,"settings.phone-access":accessAct,"settings.phone-pair":pairAct,"settings.phone-confirm":pairingAct("confirm"),"settings.phone-cancel":pairingAct("cancel"),"settings.phone-rename":renameAct,"settings.phone-approvals":approvalsAct,"settings.phone-remove":removeAct,"settings.phone-passkey-enable":passkeyEnableAct,"settings.phone-passkey-revoke":passkeyRevokeAct,"settings.phone-passkey-window":passkeyWindowAct})}}
1
+ import{createHash}from"node:crypto";import{loosens,phoneApprovalPolicyOf,phoneApprovalWords,setPhoneApprovalPolicy}from"../companion/passkey-gate.js";import{getPairedDevice}from"../companion/store.js";import{CONSOLE_FORMS,checkResponse,readForm}from"../contracts/console-api.js";import{isPhoneApprovalWindow,PHONE_APPROVAL_WINDOWS}from"../phone-approvals-schema.js";import{encodeQr}from"../qr.js";import{authenticateAccount}from"../scope.js";import{fastOwnerMay}from"../owner-mode.js";import{relativeAge}from"./chrome-helpers.js";import{handlersOf}from"./handler-registry.js";import{redirect,respond}from"./http.js";import{oneTimePhonePairScreen,settingsViewScreen}from"./one-time-secret.js";import{cancelPairing,confirmPairing,isPasskeyEnrollmentOpen,listPasskeys,listPhones,openPasskeyEnrollment,pairingView,parsePasskeyWindowMinutes,passkeyWindowMinutes,pathStates,removePhone,renamePhone,revokePasskey,savePasskeyWindow,endPasskeyWindows,startPairing,openPasskeySetupForPairedPhone,closePasskeySetup}from"./phone-engine-api.js";import{refuse}from"./refuse.js";import{browserCaller}from"./session.js";const COMPANION_DOCS_URL="https://github.com/ap9000/toolroll/blob/main/docs/companion-app.md",DEFAULT_RELAY_HOST="relay.toolroll.dev",PHONE_NAME_MAX=48,PASSKEY_PROMPTS=[0,15,60],promptLabel=minutes=>minutes===0?"Every approval":minutes===15?"Once per 15 minutes":"Once per hour";function bindingOf(who){return`${who.name}:${who.session.generation}:${createHash("sha256").update(who.session.csrf).digest("base64url").slice(0,22)}`}function qrSvgData(text){const code=encodeQr(text,"M"),border=4,dim=code.size+border*2;let path="";for(let y=0;y<code.size;y++)for(let x=0;x<code.size;x++)code.dark(x,y)&&(path+=`M${x+border},${y+border}h1v1h-1z`);return{dim,path}}export function spokenCode(code){return code.split("-").map(half=>half.split("").join(" ")).join(", ")}function pairedOn(iso){const at=new Date(iso);return Number.isNaN(at.getTime())?iso:at.toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hourCycle:"h23"})}const RETIRED_WORDS={removed:"Removed",password_changed:"Signed out when your password changed",access_changed:"Signed out when your access changed",restored:"Signed out when this workspace was restored",migration:"Signed out by a Toolroll update",contested:"Not paired: another device used the code",pairing_failed:"Pairing didn't finish"};export const PHONE_PAIRING_SCRIPT=`(function(){var first=document.getElementById("phone-pairing");if(!first)return;var id=first.getAttribute("data-pairing")||"";var deadline=Date.now()+Number(first.getAttribute("data-left-ms")||0);var done=false,misses=0;function root(){return document.getElementById("phone-pairing");}function each(sel,fn){var r=root();if(r)Array.prototype.forEach.call(r.querySelectorAll(sel),fn);}function show(name){var r=root();if(!r)return;if(name==="scan"&&!r.querySelector('[data-view="scan"]'))name="waiting";each("[data-view]",function(v){v.hidden=v.getAttribute("data-view")!==name;});r.setAttribute("data-shown",name);}function leave(){if(done)return;done=true;if(location.pathname==="/settings/phone"){history.replaceState(null,"","/settings/phone#phone-pair");location.reload();}else location.replace("/settings/phone#phone-pair");}function clock(){if(done)return;var left=Math.max(0,Math.ceil((deadline-Date.now())/1000));var m=Math.floor(left/60),s=left%60;var words=left>0?"Expires in "+m+":"+(s<10?"0":"")+s:"This code expired.";each("[data-phone-expires]",function(e){e.textContent=words;});setTimeout(clock,1000);}function spell(c){return c.split("-").map(function(h){return h.split("").join(" ");}).join(", ");}function lead(n){return n&&n.trim()!==""&&n!=="iPhone"?"\\u201c"+n+"\\u201d should be showing this code:":"Your iPhone should be showing this code:";}function apply(v){var s=v&&v.status;if(s==="awaiting_scan"||s==="awaiting_ready")return show("scan");if(s==="awaiting_confirm"){var c=String(v.confirmCode||"");each("[data-phone-code]",function(e){e.textContent=c;});each("[data-phone-code-spoken]",function(e){e.textContent=spell(c);});each("[data-phone-device]",function(e){e.textContent=lead(v.deviceName);});return show("code");}if(s==="confirming")return show("confirming");if(s==="finishing")return show("finishing");leave();}function poll(){if(done)return;if(document.hidden){setTimeout(poll,1000);return;}fetch("/settings/phone/pairings/"+encodeURIComponent(id),{credentials:"same-origin",cache:"no-store",redirect:"manual",headers:{accept:"application/json"}}).then(function(r){if(r.status===404||r.type==="opaqueredirect"){leave();return null;}if(!r.ok)throw 0;return r.json();}).then(function(v){if(v===null)return;misses=0;apply(v);if(!done)setTimeout(poll,1000);}).catch(function(){misses++;if(misses>20)return leave();setTimeout(poll,Math.min(10000,1000*misses));});}clock();setTimeout(poll,1000);})();(function(){if(!document.getElementById("phone-passkey-wait")||document.getElementById("phone-pairing"))return;var done=false,misses=0;function check(){if(done)return;if(document.hidden){setTimeout(check,3000);return;}fetch("/settings/phone",{credentials:"same-origin",cache:"no-store",redirect:"manual",headers:{accept:"text/html"}}).then(function(r){if(r.type==="opaqueredirect"||!r.ok)throw 0;return r.text();}).then(function(t){misses=0;if(t.indexOf('id="phone-passkey-wait"')<0){done=true;location.reload();return;}setTimeout(check,3000);}).catch(function(){misses++;if(misses>20)return;setTimeout(check,Math.min(15000,3000*misses));});}setTimeout(check,3000);})();`;export function createPhoneSettingsHandlers(runtime,deps){const{store}=runtime,mac=(deps.platform??process.platform)==="darwin",thisMac=mac?"this Mac":"this computer",ThisMac=mac?"This Mac":"This computer",openPairings=new Map,passwordHolds=(who,password)=>{const proved=authenticateAccount(store,who.name,password);return proved.ok&&proved.role==="approver"&&proved.generation===who.session.generation},hasPassword=who=>store.accountOf(who.name)?.passwordSet===!0,passwordProblem=who=>hasPassword(who)?"Enter your Toolroll password.":"Set a password to pair a phone.",runBy=host=>host===DEFAULT_RELAY_HOST?"run by Toolroll":"the relay this Toolroll is set up to use (TOOLROLL_RELAY_URL)",outcomeInfo=view=>{switch(view.status){case"paired":return{tone:"info",text:"Your iPhone is paired. Open the Toolroll app to see your work."};case"cancelled":return{tone:"info",text:"Pairing cancelled."};case"expired":return{tone:"notice",text:"That pairing code expired. Pair again."};case"contested":return{tone:"notice",text:"Another device used this code, so pairing stopped. Pair again and keep the code to yourself."};case"failed":return{tone:"notice",text:view.error===null?"Pairing didn't finish. Pair again.":`Pairing didn't finish: ${view.error} Pair again.`};default:return null}};function buildPhoneView(who,options={}){const access=deps.access,on=access.enabled(),service=access.service(),now=runtime.clock(),operator=store.isInstanceOperator(who.name),passworded=hasPassword(who),hostedChoice=access.hostedChoice(),hostedHost=hostedChoice.ok?new URL(hostedChoice.url).host:null,paths=service===null?null:pathStates(service),direct=paths?.direct??null,hosted=paths?.hosted??{state:"off",superseded:!1},directWorks=direct!==null&&direct.state==="listening"&&direct.addresses.length>0,hostedWorks=hosted.state==="connected",reachable=on&&(directWorks||hostedWorks),hostedApprovalStaleText=on&&access.hostedApprovalStale()?hostedHost===null?`Connecting from anywhere is off on ${thisMac} now (TOOLROLL_RELAY_URL=off).`:`This Toolroll's relay setting changed to ${hostedHost}. Phones connect only on ${thisMac}'s network until you approve the new relay below.`:null,directSummary=!passworded||!on||direct===null||direct.state==="off"?null:direct.state==="failed"?{title:`On ${thisMac}'s network`,failed:{what:direct.port===null?"Toolroll couldn't start listening for phones":`Toolroll couldn't open port ${direct.port}`,error:(direct.error??"unknown error").replace(/\.+$/,""),portCommand:direct.port===null?null:"TOOLROLL_PHONE_PORT=4300 toolroll",hostedWorks},firewallText:""}:{title:`On ${thisMac}'s network`,...direct.addresses.length===0?{noAddressText:`${ThisMac} isn't on a network a phone can reach right now. Join Wi-Fi.`}:{addresses:direct.addresses.map(one=>({label:one.kind==="tailnet"?"Tailscale":"Wi-Fi / Ethernet",address:direct.port===null||one.address.includes(":")?one.address:`${one.address}:${direct.port}`}))},tailscaleNotFound:direct.tailscale==="not_found",firewallText:`${mac?"If macOS asks whether Toolroll may accept incoming connections, click Allow. ":"If a firewall asks whether Toolroll may accept incoming connections, allow it. "}Phones can't reach ${thisMac} while it's asleep.`},hostedHostUrl=hosted.state!=="off"?new URL(hosted.relay).host:"",hostedSummary=!passworded||!on||direct===null?null:hosted.state==="off"?{offText:hostedHost!==null?`Off. Your phone connects only on ${thisMac}'s network.`:`Off (TOOLROLL_RELAY_URL=off). Your phone connects only on ${thisMac}'s network.`,host:"",runBy:"",statusWords:"",superseded:!1}:{offText:null,host:hostedHostUrl,runBy:runBy(hostedHostUrl),statusWords:hosted.state==="connected"?"Connected.":hosted.state==="unreachable"?`Can't reach it right now (${hosted.error}); Toolroll keeps trying.`:"Connecting…",superseded:hosted.superseded===!0},activePasskeys=(passworded?listPasskeys(store,who.name):[]).filter(k=>k.revokedAt===null);let lastStepSaid=!1;const lastStepOpen=()=>passworded&&activePasskeys.length===0&&isPasskeyEnrollmentOpen(service,who.name),binding=bindingOf(who);let pair=null;if(passworded){const opened=openPairings.get(binding);let open=null,restarted=!1;opened!==void 0&&(open=opened.service===service&&service!==null?pairingView(service,opened.id,binding):null,open===null&&(restarted=opened.service!==service,openPairings.delete(binding)));const live=open!==null&&["awaiting_scan","awaiting_ready","awaiting_confirm","confirming","finishing"].includes(open.status);if(open!==null&&live)pair={live:{pairSessionId:open.pairSessionId,status:open.status,confirmCode:open.confirmCode??null,deviceName:open.deviceName??null,leftMs:Math.max(0,open.expiresAtMs-now.getTime()),setsUpApprovals:activePasskeys.length===0},outcome:null,lastStepWait:!1,reachable,whyNotReachable:null};else{open!==null&&openPairings.delete(binding),open!==null&&open.status!=="paired"&&opened?.passkeyWindow!==void 0&&closePasskeySetup(service,who.name,opened.passkeyWindow);const paired=options.problem===void 0&&open!==null&&open.status==="paired";let outcome=null,lastStepWait=!1;options.problem===void 0&&(paired&&lastStepOpen()?(outcome={tone:"info",text:"Your iPhone is paired."},lastStepWait=!0,lastStepSaid=!0):open!==null?outcome=outcomeInfo(open):restarted&&(outcome={tone:"notice",text:"Pairing stopped because phone access restarted. Pair again."}));const whyNotReachable=reachable?null:on?hosted.state==="starting"&&!directWorks?`Connecting to ${new URL(hosted.relay).host}… Reload this page in a moment.`:direct!==null&&direct.state==="failed"&&!hostedWorks?hostedHost!==null&&!access.hostedEnabled()?"Direct connections aren't working (see above). Turn on connecting from anywhere to pair now.":`Direct connections aren't working (see above), so a phone can't reach ${thisMac} yet.`:`A phone has no way to reach ${thisMac} yet. Join Wi-Fi${hostedHost!==null?", or connect from anywhere":""}.`:operator?"Turn on phone access first.":"Ask whoever runs this Toolroll to turn on phone access.";pair={live:null,outcome,lastStepWait,reachable,whyNotReachable}}}const phones=listPhones(store,{accountName:who.name},now),currentPhones=phones.filter(one=>one.state!=="retired"),retiredPhones=phones.filter(one=>one.state==="retired"),enrollmentOpen=isPasskeyEnrollmentOpen(service,who.name),windowMins=passkeyWindowMinutes(store);return{thisMac,ThisMac,on,operator,passworded,notOnStoreUrl:COMPANION_DOCS_URL,accessProblems:passworded?access.problems():[],hostedApprovalStaleText,directSummary,hostedSummary,hostedHost,hostedEnabled:access.hostedEnabled(),pair,devices:{showSection:phones.length>0||passworded,current:currentPhones.map(phone=>{const seen=phone.lastSeenAt===null?"never connected":`last connected ${relativeAge(phone.lastSeenAt,now)}`,policy=phoneApprovalPolicyOf(store,phone.deviceId);return{deviceId:phone.deviceId,name:phone.name,sub:phone.state==="finishing"?`Finishing on the iPhone… · paired ${pairedOn(phone.pairedAt)}`:`Paired ${pairedOn(phone.pairedAt)} · ${seen} · Approvals: ${phoneApprovalWords(policy.minutes).toLowerCase()}`,state:phone.state,minutes:policy.minutes,minuteChoices:PHONE_APPROVAL_WINDOWS.map(m=>[String(m),phoneApprovalWords(m)])}}),retired:retiredPhones.map(phone=>({deviceId:phone.deviceId,name:phone.name,sub:`${RETIRED_WORDS[phone.retiredReason??"removed"]} · paired ${pairedOn(phone.pairedAt)}`}))},passkeys:{showSection:passworded&&(currentPhones.length>0||activePasskeys.length>0),enrollmentOpen,lastStepSaid,stateText:activePasskeys.length===0?"Not set up":`${activePasskeys.length} active · ${promptLabel(windowMins)}`,canEnable:!enrollmentOpen&&on&&currentPhones.length>0,enableLabel:activePasskeys.length===0?"Set up a passkey on iPhone":"Add another passkey",active:activePasskeys.map(k=>({credentialId:k.credentialId,label:k.label,sub:k.lastUsedAt===null?`Registered ${pairedOn(k.createdAt)} · not used yet`:`Registered ${pairedOn(k.createdAt)} · last used ${relativeAge(k.lastUsedAt,now)}`})),promptText:promptLabel(windowMins),windowMinutes:windowMins,windowChoices:PASSKEY_PROMPTS.map(m=>[String(m),promptLabel(m)])}}}const render=(response,status,who,options={})=>{const data=buildPhoneView(who,options),followPairing=data.pair?.live!==null||data.pair?.lastStepWait===!0||data.passkeys.enrollmentOpen&&data.passkeys.active.length===0;return runtime.sendScreen(response,status,settingsViewScreen("Phone",{kind:"settings-phone",data,said:null,problem:options.problem??null},{chrome:runtime.chromeFor(null,"settings"),sensitive:!0,...followPairing?{functional:{script:PHONE_PAIRING_SCRIPT,fetches:!0}}:{}}))};async function phonePage(ctx){return render(ctx.response,200,browserCaller(ctx.who))}async function pairingJson(ctx){const who=browserCaller(ctx.who),id=ctx.url.pathname.slice(25),service=deps.access.service(),view=service===null?null:pairingView(service,id,bindingOf(who));return view===null?respond(ctx.response,404,"application/json; charset=utf-8",JSON.stringify({error:"not_found"})):respond(ctx.response,200,"application/json; charset=utf-8",JSON.stringify(checkResponse("phonePairingView",view)))}async function accessAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phoneAccess);if(body.getAll("password").length>1||body.getAll("act").length!==1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});const act=body.get("act");if(act!=="on"&&act!=="off"&&act!=="hosted-on"&&act!=="hosted-off")return render(ctx.response,400,who,{problem:"Choose on or off."});if(body.getAll("hosted").length>1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});if(!store.isInstanceOperator(who.name))return render(ctx.response,403,who,{problem:"An instance operator turns phone access on or off."});if(!(!(act==="hosted-on"||act==="on"&&body.get("hosted")==="1")&&fastOwnerMay("phone-settings",fastPrincipal(who,ctx.request),runtime.clock()))&&!passwordHolds(who,body.get("password")??""))return render(ctx.response,403,who,{problem:passwordProblem(who)});const change=act==="on"?{act,hosted:body.get("hosted")==="1"}:{act},applied=await deps.access.change(change,who.name,runtime.clock(),()=>store.isInstanceOperator(who.name)&&store.accountOf(who.name)?.generation===who.session.generation);return applied==="not_on"?render(ctx.response,409,who,{problem:"Phone access is off now. Turn it on first."}):applied==="not_allowed"?render(ctx.response,403,who,{problem:"An instance operator turns phone access on or off."}):redirect(ctx.response,"/settings/phone")}async function pairAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phonePair);if(body.getAll("password").length>1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});if(!fastOwnerMay("phone-settings",fastPrincipal(who,ctx.request),runtime.clock())&&!passwordHolds(who,body.get("password")??""))return render(ctx.response,403,who,{problem:passwordProblem(who)});const service=deps.access.service();if(service===null)return render(ctx.response,409,who,{problem:"Turn on phone access first."});const binding=bindingOf(who),started=startPairing(service,who.name,binding,who.session.generation);if(!started.ok)return render(ctx.response,409,who,{problem:started.error});openPairings.set(binding,{id:started.qr.pairSessionId,service});const qrPayload=JSON.stringify(started.qr),activePasskeys=listPasskeys(store,who.name).filter(k=>k.revokedAt===null);return runtime.sendScreen(ctx.response,200,oneTimePhonePairScreen({chrome:runtime.chromeFor(null,"settings"),pairSessionId:started.qr.pairSessionId,thisMac,ThisMac,leftMs:Math.max(0,started.expiresAtMs-runtime.clock().getTime()),qrSvg:qrSvgData(qrPayload),qrPayload,setsUpApprovals:activePasskeys.length===0,script:PHONE_PAIRING_SCRIPT}))}const pairingAct=op=>async ctx=>{const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phonePairing),pairing=body.getAll("pairing").length===1?body.get("pairing")??"":"",binding=bindingOf(who),service=deps.access.service(),opened=openPairings.get(binding);if(service===null||pairing===""||opened===void 0||opened.id!==pairing||opened.service!==service)return refuse(ctx.response,who,409,"That pairing isn't open any more. Pair again.","/settings/phone");if(op==="cancel")return cancelPairing(service,pairing,binding),redirect(ctx.response,"/settings/phone#phone-pair");const confirmed=await confirmPairing(service,pairing,binding);if(!confirmed.ok)return render(ctx.response,409,who,{problem:confirmed.error});const setup=body.getAll("setup").length===1&&body.get("setup")==="1"?openPasskeySetupForPairedPhone(service,store,who.name,who.session.generation,confirmed.deviceId):null;return setup!==null&&openPairings.set(binding,{...opened,passkeyWindow:setup.windowId}),redirect(ctx.response,"/settings/phone#phone-pair")};async function renameAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phoneRename);if(body.getAll("device").length!==1||body.getAll("name").length!==1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});const name=(body.get("name")??"").trim();return name.length===0||name.length>PHONE_NAME_MAX?render(ctx.response,400,who,{problem:`Name the phone in 1 to ${PHONE_NAME_MAX} characters.`}):renamePhone(store,body.get("device")??"",name,who.name)?redirect(ctx.response,"/settings/phone#phone-devices"):render(ctx.response,404,who,{problem:"That phone isn't paired."})}async function approvalsAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phoneApprovals);if(body.getAll("password").length>1||body.getAll("device").length!==1||body.getAll("minutes").length!==1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});const minutes=Number(body.get("minutes"));if(!isPhoneApprovalWindow(minutes))return render(ctx.response,400,who,{problem:"Choose Ask every time, or once every 15 minutes, hour or 8 hours."});const deviceId=body.get("device")??"",now=runtime.clock(),saved=store.transact(()=>{const phone=getPairedDevice(store.handle,deviceId);if(phone===null||phone.accountName!==who.name||phone.revokedAt!==null)return"missing";const before=phoneApprovalPolicyOf(store,deviceId);return before.minutes===minutes&&before.source==="phone"?"same":loosens(before,minutes)&&!fastOwnerMay("phone-settings",fastPrincipal(who,ctx.request),now)&&!passwordHolds(who,body.get("password")??"")?"password":(setPhoneApprovalPolicy(store,{deviceId,minutes,by:who.name,via:"mac",now}),"changed")});return saved==="missing"?render(ctx.response,404,who,{problem:"That phone isn't paired."}):saved==="password"?render(ctx.response,403,who,{problem:passwordProblem(who)}):(saved==="changed"&&endPasskeyWindows(deps.access.service()),redirect(ctx.response,"/settings/phone#phone-devices"))}async function removeAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phoneRemove);return body.getAll("password").length>1||body.getAll("device").length!==1?render(ctx.response,400,who,{problem:"Submit one value for each field."}):!fastOwnerMay("phone-settings",fastPrincipal(who,ctx.request),runtime.clock())&&!passwordHolds(who,body.get("password")??"")?render(ctx.response,403,who,{problem:passwordProblem(who)}):removePhone(deps.access.service(),store,body.get("device")??"",who.name,runtime.clock())?redirect(ctx.response,"/settings/phone#phone-devices"):render(ctx.response,404,who,{problem:"That phone isn't paired."})}async function passkeyEnableAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phonePasskeyEnable);if(body.getAll("password").length>1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});if(!fastOwnerMay("phone-settings",fastPrincipal(who,ctx.request),runtime.clock())&&!passwordHolds(who,body.get("password")??""))return render(ctx.response,403,who,{problem:passwordProblem(who)});const service=deps.access.service();return service===null?render(ctx.response,409,who,{problem:"Turn on phone access first."}):openPasskeyEnrollment(service,who.name)===null?render(ctx.response,409,who,{problem:"Passkey enrollment isn't available right now."}):redirect(ctx.response,"/settings/phone#phone-passkeys")}async function passkeyRevokeAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phonePasskeyRevoke);return body.getAll("password").length>1||body.getAll("credential").length!==1?render(ctx.response,400,who,{problem:"Submit one value for each field."}):!fastOwnerMay("phone-settings",fastPrincipal(who,ctx.request),runtime.clock())&&!passwordHolds(who,body.get("password")??"")?render(ctx.response,403,who,{problem:passwordProblem(who)}):revokePasskey(store,body.get("credential")??"",who.name,runtime.clock(),deps.access.service())?redirect(ctx.response,"/settings/phone#phone-passkeys"):render(ctx.response,404,who,{problem:"That passkey isn't active."})}async function passkeyWindowAct(ctx){const who=browserCaller(ctx.who),body=readForm(ctx.posted,CONSOLE_FORMS.phonePasskeyWindow);if(body.getAll("password").length>1||body.getAll("window").length!==1)return render(ctx.response,400,who,{problem:"Submit one value for each field."});const wanted=parsePasskeyWindowMinutes(body.get("window"));if(wanted===null)return render(ctx.response,400,who,{problem:"Choose Every approval, Once per 15 minutes, or Once per hour."});const now=runtime.clock(),saved=store.transact(()=>{if(!store.isInstanceOperator(who.name))return"operator";if(!fastOwnerMay("phone-settings",fastPrincipal(who,ctx.request),now)&&!passwordHolds(who,body.get("password")??""))return"password";const before=passkeyWindowMinutes(store);return before===wanted?"same":(savePasskeyWindow(store,wanted),store.recordAction({at:now.toISOString(),actor:who.name,repo:null,taskId:null,runId:null,action:"passkey prompt changed",outcome:"changed",source:"policy",detail:`${promptLabel(before)} → ${promptLabel(wanted)}`}),"changed")});return saved==="operator"?render(ctx.response,403,who,{problem:"An instance operator sets the passkey prompt."}):saved==="password"?render(ctx.response,403,who,{problem:passwordProblem(who)}):(saved==="changed"&&endPasskeyWindows(deps.access.service()),redirect(ctx.response,"/settings/phone#phone-passkeys"))}function fastPrincipal(who,request){return typeof runtime.fastPrincipalOf=="function"?runtime.fastPrincipalOf(who,request):null}return{registrations:handlersOf("settings",{"settings.phone":phonePage,"settings.phone-pairing":pairingJson,"settings.phone-access":accessAct,"settings.phone-pair":pairAct,"settings.phone-confirm":pairingAct("confirm"),"settings.phone-cancel":pairingAct("cancel"),"settings.phone-rename":renameAct,"settings.phone-approvals":approvalsAct,"settings.phone-remove":removeAct,"settings.phone-passkey-enable":passkeyEnableAct,"settings.phone-passkey-revoke":passkeyRevokeAct,"settings.phone-passkey-window":passkeyWindowAct})}}
@@ -1 +1 @@
1
- const GROUP_PAGE=Object.freeze({callers:Object.freeze(["cookie","bearer"]),scope:"read",project:"session",limited:"unscoped",needsProject:!1,role:"any",roleBrowser:!1,viewer:!1,local:"allow"}),START_BUILDER=Object.freeze({...GROUP_PAGE}),FLEET=Object.freeze({...GROUP_PAGE,limited:"deny"}),MANAGE_COMPUTERS=["full-session","approver","whole-installation","not-demo"];export const SETTINGS_SECTIONS=Object.freeze([{id:"appearance",area:"general",title:"Appearance",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:[],scope:{},act:{},changes:[],opens:!1,scripts:[],oldIds:["accent","accent-own"]},{id:"this-browser",area:"general",title:"This browser",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:["password-holder"],scope:{},act:{forget:["cookie-session"]},changes:[],opens:!1,scripts:[],oldIds:[]},{id:"your-password",area:"general",title:"Your password",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:["password-holder"],scope:{passwordless:["installation"]},act:{},changes:[],opens:!1,scripts:[],oldIds:[]},{id:"version",area:"general",title:"Version",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:[],scope:{"updates-version":["installation"],"package-version":["operator"]},act:{updates:["operator"]},changes:[],opens:!1,scripts:[],oldIds:[]},{id:"install-mode",area:"general",title:"Solo or team",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:[],scope:{},act:{"just-me":["full-session","operator"]},changes:[{id:"just-me",act:"just-me",proof:"install-solo"}],opens:!1,scripts:[],oldIds:[]},{id:"task-sizing",area:"general",title:"Size tasks with a quick model call (Claude Haiku, on your plan)",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:["installation"],scope:{},act:{switch:["cookie-session","operator"]},changes:[{id:"task-sizing",act:"switch",proof:"task-sizing"}],opens:!1,scripts:[],oldIds:[]},{id:"flexible",area:"general",title:"Interactive agent threads (beta)",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:["installation"],scope:{},act:{switch:["cookie-session","operator"]},changes:[{id:"flexible",act:"switch",proof:"flexible-switch"}],opens:!1,scripts:[],oldIds:[]},{id:"flexible-sign-in",area:"general",title:"Your Claude sign-in for threads",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:["approver"],scope:{},act:{save:["cookie-session","approver"],check:["cookie-session","approver"],remove:["cookie-session"]},changes:[{id:"flexible-sign-in",act:"save",proof:"flexible-sign-in"},{id:"flexible-sign-in-check",act:"check",proof:"flexible-sign-in-check"},{id:"flexible-sign-in-clear",act:"remove",proof:"flexible-sign-in-clear"}],opens:!1,scripts:[],oldIds:[]},{id:"advanced",area:"general",title:"Show advanced features",pinnedFrom:"settings.group-advanced",policy:GROUP_PAGE,read:[],scope:{"operator-pages":["operator"]},act:{switch:["cookie-session"]},changes:[],opens:!0,scripts:[],oldIds:["show-advanced"]},{id:"local-mode",area:"general",title:"Local mode",pinnedFrom:"settings.group-access",policy:GROUP_PAGE,read:["cookie-session"],scope:{},act:{"turn-off":["full-session","operator"]},changes:[{id:"local-mode",act:"turn-off",proof:"local-mode-off"}],opens:!1,scripts:[],oldIds:[]},{id:"start",area:"computers",title:"Connect a builder",pinnedFrom:"start-builder",policy:START_BUILDER,read:[],scope:{},act:{register:MANAGE_COMPUTERS},changes:[{id:"register-computer",act:"register",proof:"runner-register"}],opens:!1,scripts:[],oldIds:["builder"]},{id:"builders",area:"computers",title:"Computers that build",pinnedFrom:"fleet",policy:FLEET,read:[],scope:{},act:{manage:MANAGE_COMPUTERS},changes:[{id:"retire-computer",act:"manage",proof:"runner-retire"}],opens:!0,scripts:[],oldIds:["workers"]}]),CHANGE_DOCUMENTS=SETTINGS_SECTIONS.flatMap(section=>section.changes.map(change=>({...change,section})));export function changeDocumentOf(id){return CHANGE_DOCUMENTS.find(one=>one.id===id)}const AREA_PATHS=Object.freeze({general:"/settings/general",computers:"/settings/computers"});export function sectionHref(declaration,options={}){const path=AREA_PATHS[declaration.area]??"/settings",query=new URLSearchParams;options.project!=null&&query.set("repo",options.project),query.set("section",declaration.id),options.open===!0&&query.set("open","1");for(const[key,value]of Object.entries(options.extra??{}))query.set(key,value);return`${path}?${query}`}export function changeHref(document,project=null,extra={}){const query=new URLSearchParams;project!==null&&query.set("repo",project);for(const[key,value]of Object.entries(extra))query.set(key,value);return`/settings/change/${document.id}${query.size===0?"":`?${query}`}`}
1
+ const GROUP_PAGE=Object.freeze({callers:Object.freeze(["cookie","bearer"]),scope:"read",project:"session",limited:"unscoped",needsProject:!1,role:"any",roleBrowser:!1,viewer:!1,local:"allow"}),START_BUILDER=Object.freeze({...GROUP_PAGE}),FLEET=Object.freeze({...GROUP_PAGE,limited:"deny"}),MANAGE_COMPUTERS=["full-session","approver","whole-installation","not-demo"];export const SETTINGS_SECTIONS=Object.freeze([{id:"appearance",area:"general",title:"Appearance",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:[],scope:{},act:{},changes:[],opens:!1,scripts:[],oldIds:["accent","accent-own"]},{id:"this-browser",area:"general",title:"This browser",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:["password-holder"],scope:{},act:{forget:["cookie-session"]},changes:[],opens:!1,scripts:[],oldIds:[]},{id:"your-password",area:"general",title:"Your password",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:["password-holder"],scope:{passwordless:["installation"]},act:{},changes:[],opens:!1,scripts:[],oldIds:[]},{id:"version",area:"general",title:"Version",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:[],scope:{"updates-version":["installation"],"package-version":["operator"]},act:{updates:["operator"]},changes:[],opens:!1,scripts:[],oldIds:[]},{id:"install-mode",area:"general",title:"Solo or team",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:[],scope:{},act:{"just-me":["full-session","operator"]},changes:[{id:"just-me",act:"just-me",proof:"install-solo"}],opens:!1,scripts:[],oldIds:[]},{id:"owner-mode",area:"general",title:"Fast or Secure mode",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:[],scope:{},act:{switch:["full-session","operator"]},changes:[{id:"owner-mode",act:"switch",proof:"owner-mode-fast"}],opens:!1,scripts:[],oldIds:[]},{id:"task-sizing",area:"general",title:"Size tasks with a quick model call (Claude Haiku, on your plan)",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:["installation"],scope:{},act:{switch:["cookie-session","operator"]},changes:[{id:"task-sizing",act:"switch",proof:"task-sizing"}],opens:!1,scripts:[],oldIds:[]},{id:"flexible",area:"general",title:"Interactive agent threads (beta)",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:["installation"],scope:{},act:{switch:["cookie-session","operator"]},changes:[{id:"flexible",act:"switch",proof:"flexible-switch"}],opens:!1,scripts:[],oldIds:[]},{id:"flexible-sign-in",area:"general",title:"Your Claude sign-in for threads",pinnedFrom:"settings.group-general",policy:GROUP_PAGE,read:["approver"],scope:{},act:{save:["cookie-session","approver"],check:["cookie-session","approver"],remove:["cookie-session"]},changes:[{id:"flexible-sign-in",act:"save",proof:"flexible-sign-in"},{id:"flexible-sign-in-check",act:"check",proof:"flexible-sign-in-check"},{id:"flexible-sign-in-clear",act:"remove",proof:"flexible-sign-in-clear"}],opens:!1,scripts:[],oldIds:[]},{id:"advanced",area:"general",title:"Show advanced features",pinnedFrom:"settings.group-advanced",policy:GROUP_PAGE,read:[],scope:{"operator-pages":["operator"]},act:{switch:["cookie-session"]},changes:[],opens:!0,scripts:[],oldIds:["show-advanced"]},{id:"local-mode",area:"general",title:"Local mode",pinnedFrom:"settings.group-access",policy:GROUP_PAGE,read:["cookie-session"],scope:{},act:{"turn-off":["full-session","operator"]},changes:[{id:"local-mode",act:"turn-off",proof:"local-mode-off"}],opens:!1,scripts:[],oldIds:[]},{id:"start",area:"computers",title:"Connect a builder",pinnedFrom:"start-builder",policy:START_BUILDER,read:[],scope:{},act:{register:MANAGE_COMPUTERS},changes:[{id:"register-computer",act:"register",proof:"runner-register"}],opens:!1,scripts:[],oldIds:["builder"]},{id:"builders",area:"computers",title:"Computers that build",pinnedFrom:"fleet",policy:FLEET,read:[],scope:{},act:{manage:MANAGE_COMPUTERS},changes:[{id:"retire-computer",act:"manage",proof:"runner-retire"}],opens:!0,scripts:[],oldIds:["workers"]}]),CHANGE_DOCUMENTS=SETTINGS_SECTIONS.flatMap(section=>section.changes.map(change=>({...change,section})));export function changeDocumentOf(id){return CHANGE_DOCUMENTS.find(one=>one.id===id)}const AREA_PATHS=Object.freeze({general:"/settings/general",computers:"/settings/computers"});export function sectionHref(declaration,options={}){const path=AREA_PATHS[declaration.area]??"/settings",query=new URLSearchParams;options.project!=null&&query.set("repo",options.project),query.set("section",declaration.id),options.open===!0&&query.set("open","1");for(const[key,value]of Object.entries(options.extra??{}))query.set(key,value);return`${path}?${query}`}export function changeHref(document,project=null,extra={}){const query=new URLSearchParams;project!==null&&query.set("repo",project);for(const[key,value]of Object.entries(extra))query.set(key,value);return`/settings/change/${document.id}${query.size===0?"":`?${query}`}`}
@@ -1 +1 @@
1
- import{ADVANCED_PAGES}from"../advanced-view.js";import{accentNote,ACCENT_PRESETS}from"../accent-colors.js";import{installModeLine,justMeAllowed,TEAM_FACT_WORDS}from"../install-mode.js";import{signInCheckWords,statusCheck}from"../agent-thread/sign-in.js";import{evaluateRoutePolicy,holdsRole}from"./route-policy.js";import{changeDocumentOf,changeHref,sectionHref,SETTINGS_SECTIONS}from"./settings-section-table.js";function gateHolds(gate,person){switch(gate){case"installation":return person.installation&&!person.restricted;case"cookie-session":return person.via==="cookie";case"full-session":return person.via==="cookie"&&person.authority==="full";case"operator":return person.via==="cookie"&&person.operator;case"approver":return person.role==="approver";case"password-holder":return!(person.via==="cookie"&&person.authority!=="full"&&!person.passwordSet);case"whole-installation":return!person.restricted;case"not-demo":return!person.demo}}const SECTION_RESOLVERS=new Set(["none","session","form","form-path"]),SECTION_LIMITED=new Set(["deny","collection","unscoped","self","conversation"]);export function admitSection(declaration,person,project=null){const policy=declaration.policy;if(person.via==="cookie"&&person.authority!=="full"&&policy.local!=="allow")return{ok:!1,why:"local"};let why=null;const projectAdmits=source=>!SECTION_RESOLVERS.has(source)||!SECTION_LIMITED.has(policy.limited)?(why="project",!1):person.restricted&&(policy.limited==="deny"||policy.limited==="conversation")||person.restricted&&policy.limited!=="unscoped"&&policy.limited!=="self"&&project===null?(why="limited",!1):policy.needsProject&&person.via==="cookie"&&project===null&&!person.unscopedConsole?(why="project",!1):!0,checked=evaluateRoutePolicy(policy,person.principal,projectAdmits);if(!checked.ok)return{ok:!1,why:checked.reason==="project"?why??"project":checked.reason};if(!holdsRole(policy,person,name=>name===person.name&&person.operator))return{ok:!1,why:"role"};for(const gate of declaration.read)if(!gateHolds(gate,person))return{ok:!1,why:`read:${gate}`};const scopes=new Set(Object.entries(declaration.scope).filter(([,gates])=>gates.every(gate=>gateHolds(gate,person))).map(([name])=>name)),can=Object.fromEntries(Object.entries(declaration.act).map(([act,gates])=>[act,gates.every(gate=>gateHolds(gate,person))]));return{ok:!0,scopes,can}}export const PROJECT_NOT_AVAILABLE="That project is not available in this workspace.";export function resolveSettingsProject(url,session,deps){const named=url.searchParams.getAll("repo");if(named.length>1)return{ok:!1,status:400,message:"Name one project."};if(named.length===1){const repo=named[0];return repo===""||!deps.projects().includes(repo)||!deps.canOpen(repo)?{ok:!1,status:404,message:PROJECT_NOT_AVAILABLE}:{ok:!0,project:repo,requested:!0}}return{ok:!0,project:session,requested:!1}}export function sessionProjectCheck(posted,session,projectName){if(posted.length!==1||posted[0]==="")return{ok:!1,rendered:null,session,message:"This form names no project. Open the project and try again."};const rendered=posted[0];return session===null||rendered!==session?{ok:!1,rendered,session,message:`${projectName(rendered)} is no longer the open project${session===null?"":` (${projectName(session)} is)`}. Nothing changed.`}:{ok:!0,project:rendered}}export function askedSection(url){const sections=url.searchParams.getAll("section"),section=sections.length===1&&/^[a-z][a-z-]{0,39}$/.test(sections[0])?sections[0]:null;return{section,open:section!==null&&url.searchParams.getAll("open").length===1&&url.searchParams.get("open")==="1"}}export function renderAreaData(area,impls,base,asked,declarations=SETTINGS_SECTIONS){const sections=[],jump=[],shown=[];for(const declaration of declarations.filter(one=>one.area===area)){const impl=impls[declaration.id];if(impl===void 0)throw new Error(`settings section ${declaration.id} has no implementation`);const admitted=admitSection(declaration,base.person,base.project);if(!admitted.ok)continue;const ctx={...base,scopes:admitted.scopes,can:admitted.can},summary=impl.loadSummary(ctx);if(summary===null)continue;const isAsked=asked.section===declaration.id,detail=isAsked&&asked.open&&declaration.opens&&impl.loadDetail!==void 0?impl.loadDetail(ctx):null;sections.push(impl.renderBlock({declaration,ctx,summary,detail,asked:isAsked,attrs:{"data-section":declaration.id,tabindex:isAsked?"-1":null}})),jump.push({id:declaration.id,title:declaration.title}),shown.push(declaration.id)}return{sections,jump,shown}}export function changeDocumentData(id,impls,base,problem){const change=changeDocumentOf(id),declaration=change?.section,impl=declaration===void 0?void 0:impls[declaration.id];if(change===void 0||declaration===void 0||impl?.renderChangeData===void 0)return{ok:!1,status:404,message:"There's no page at this address."};const admitted=admitSection(declaration,base.person,base.project);if(!admitted.ok||admitted.can[change.act]!==!0)return{ok:!1,status:403,message:impl.refusal??"You can't change this here."};const ctx={...base,scopes:admitted.scopes,can:admitted.can},docData=impl.renderChangeData({declaration,ctx,summary:impl.loadSummary(ctx),detail:null,asked:!0,attrs:{},problem,document:change.id});return{ok:!0,title:docData.title,doc:docData}}const ACCENT_CHOICES=ACCENT_PRESETS.slice(0,6),back="/settings/general";function appearanceSection(){return{loadSummary:ctx=>ctx.prefs,renderBlock:({summary:prefs})=>{const custom=ACCENT_CHOICES.some(one=>one.hex===prefs.accent)?null:prefs.accent,accentNoteWords=accentNote(prefs.accent);return{id:"appearance",title:"Appearance",state:" · saved for this browser",items:[{type:"form",form:{action:"/settings/appearance",hidden:{return:back},fields:[{kind:"segment",name:"theme",label:"Theme",hint:"Light, dark, or whatever this device uses.",current:prefs.theme,items:[["system","Match device"],["light","Light"],["dark","Dark"]]}],save:null}},{type:"form",form:{id:"accent",proof:"appearance",action:"/settings/appearance",gate:!0,hidden:{return:back},fields:[{kind:"select",name:"accent",label:"Accent",hint:"Buttons, focus and what needs you.",current:prefs.accent,items:[...ACCENT_CHOICES.map(one=>[one.hex,one.id==="ink"?"Ink (default)":one.name]),...custom===null?[]:[[custom,`Your own colour (${custom})`]]]},...accentNoteWords===null?[]:[{kind:"note",text:accentNoteWords}]]}},{type:"disclose",label:"Use your own colour",open:custom!==null,items:[{type:"form",form:{id:"accent-picker",proof:"appearance",action:"/settings/appearance",gate:!0,hidden:{return:back},fields:[{kind:"color",name:"accent",label:"Colour picker",hint:"Pick any swatch for buttons, focus and what needs you.",value:prefs.accent,ariaLabel:"Pick a colour"}]}},{type:"form",form:{id:"accent-own",proof:"appearance",action:"/settings/appearance",gate:!0,hidden:{return:back},fields:[{kind:"input",id:"accent-hex",name:"accent",label:"Hex code",hint:"Six hex digits, like #3b82f6.",value:custom??"",placeholder:"#3b82f6",required:!0,pattern:"#?[0-9a-fA-F]{6}",spellCheck:!1,autoComplete:"off",ariaLabel:"Your own colour"}]}}]}]}}}}function thisBrowserSection(){return{loadSummary:ctx=>({forget:ctx.can.forget===!0}),renderBlock:({summary})=>({id:"this-browser",title:"This browser",items:[{type:"note",text:"Remembered password: after you type your password, standard approvals skip it on this computer for 15 minutes."},...summary.forget?[{type:"form",form:{action:"/session/forget-password",hidden:{return:back},save:{label:"Forget now",sm:!0},fields:[]}}]:[]]})}}function yourPasswordSection(deps){return{loadSummary:ctx=>({passwordless:ctx.scopes.has("passwordless")?deps.passwordless():null}),renderBlock:({summary})=>{const saved=deps.savedLogin?.()??null,items=[saved===null?{type:"note",text:"Forgot it? On the computer running Toolroll, run",code:"toolroll password reset"}:{type:"note",text:"Your first password is saved on the computer running Toolroll. To read it, run",code:`cat ${saved}`}];return summary.passwordless!==null&&items.push({type:"actions",actions:[{label:`Passwordless: ${summary.passwordless?"On":"Off"} · Change`,href:"/settings/passwordless",sm:!0}]}),{id:"your-password",title:"Your password",items}}}}function versionSection(deps){return{loadSummary:ctx=>{const version=(ctx.scopes.has("updates-version")?deps.updatesVersion(ctx.person.name):null)??(ctx.scopes.has("package-version")?deps.packageVersion:null),drift=ctx.scopes.has("updates-version")?deps.runtimeDrift?.()??null:null;return version===null?null:{version,firstResult:deps.firstResult(ctx.now),updates:ctx.can.updates===!0,drift}},renderBlock:({summary})=>({id:"version",title:"Version",items:[{type:"facts",rows:[{label:"Toolroll",value:summary.version,mono:!0}]},...summary.firstResult?[{type:"note",text:summary.firstResult}]:[],...summary.drift?[{type:"info",text:summary.drift}]:[],...summary.updates?[{type:"actions",actions:[{label:"Open updates",href:"/settings/updates",variant:"ghost",sm:!0}]}]:[]]})}}function advancedSection(){return{loadSummary:ctx=>({on:ctx.prefs.advanced,canSwitch:ctx.can.switch===!0}),loadDetail:ctx=>ADVANCED_PAGES.filter(one=>one.operator!==!0||ctx.scopes.has("operator-pages")),renderBlock:({declaration,summary,detail})=>({id:"advanced",title:"Show advanced features",state:summary.on?" · on":" · off",lead:"Flows, other computers, spend limits, operating modes and the rest, in your menus. They keep working either way.",right:{id:"show-advanced",items:summary.canSwitch?[{type:"form",form:{action:"/settings/advanced",hidden:{advanced:summary.on?"off":"on"},save:{label:summary.on?"Turn off":"Turn on",sm:!0},fields:[]}}]:[]},items:[detail===null?{type:"actions",actions:[{label:"See advanced pages",href:`${sectionHref(declaration,{open:!0})}#advanced`,variant:"ghost",sm:!0}]}:{type:"links",links:detail.map(one=>({label:one.title,href:one.href,sub:one.words}))}]})}}function localModeSection(deps){return{loadSummary:ctx=>{if(!deps.localModeOn())return null;const owner=ctx.person.authority!=="full";return owner?ctx.person.passwordSet?null:{owner,turnOff:!1}:ctx.can["turn-off"]===!0?{owner,turnOff:!0}:null},renderBlock:({declaration,summary})=>summary.owner?{id:"local-mode",title:"Let agents work on their own",lead:"Agents can work on their own, merge and release only after you set a password.",items:[{type:"actions",actions:[{label:"Set a password",href:"/password/set?next=%2Fsettings%2Fgeneral",sm:!0}]}]}:{id:"local-mode",title:"Local mode",state:" · on",lead:"A browser on this computer can file tasks, approve plans and add projects without your password.",items:[{type:"actions",actions:[{label:"Turn off local mode",href:changeHref(declaration.changes[0]),sm:!0}]}]},refusal:"An instance operator signed in with a password turns off local mode.",renderChangeData:({declaration,summary,problem})=>{const home=sectionHref(declaration),title="Turn off local mode";return summary===null||!summary.turnOff?{group:"general",title,sectionId:"local-mode-off",backHref:home,paragraphs:["Local mode is off. This computer's browser signs in with a password."],cancelHref:home,cancelLabel:"Back to General"}:{group:"general",title,sectionId:"local-mode-off",backHref:home,problem,paragraphs:["Local mode lets a browser on this computer file tasks, approve plans and add projects without a password. Turned off, every browser signs in with a password, and the local owner's sessions and links stop working. You can't turn it back on here."],form:{id:"local-mode-form",proof:"local-mode-off",action:"/settings/local-mode/off",native:!0,save:{label:"Turn off"},confirm:title,fields:[]},cancelHref:home}}}}function installModeSection(deps){return{loadSummary:ctx=>{const read=deps.installMode(),canSwitch=ctx.can["just-me"]===!0;return{mode:read.mode,facts:read.facts,canSwitch,offered:canSwitch&&justMeAllowed(read)}},renderBlock:({declaration,summary})=>{const line=installModeLine(summary.mode);return{id:"install-mode",title:line.label,lead:line.words,items:summary.offered?[{type:"actions",actions:[{label:"It's just me",href:changeHref(declaration.changes[0]),sm:!0}]}]:[]}},refusal:"An instance operator signed in with a password says it's just them.",renderChangeData:({declaration,summary,problem})=>{const home=sectionHref(declaration),title="It's just me",blocked=summary===null?[]:summary.facts.filter(fact=>fact!=="existing-install"&&!fact.endsWith("-added"));return summary===null||summary.mode==="solo"?{group:"general",title,sectionId:"install-mode",backHref:home,paragraphs:["This install is solo."],cancelHref:home,cancelLabel:"Back to General"}:summary.offered?{group:"general",title,sectionId:"install-mode",backHref:home,problem,paragraphs:["Approvals and Accept then need only you signed in. Signing in, tokens and connecting things still ask for your password. If anyone joins, this install switches back to Team."],form:{id:"just-me-form",proof:"install-solo",action:"/settings/install-mode/solo",native:!0,save:{label:title},confirm:title,fields:[]},cancelHref:home}:{group:"general",title,sectionId:"install-mode",backHref:home,problem:blocked.map(fact=>TEAM_FACT_WORDS[fact]).join(" "),cancelHref:home,cancelLabel:"Back to General"}}}}const TASK_SIZING_OFF_WORDS="Off: no model call before you approve; uncertain tasks get a plan first.",SIZER_NAME={claude:"Claude Haiku, on your plan",jev:"Jev via OpenRouter, your credit"},SIZER_SHORT={claude:"Claude Haiku",jev:"Jev via OpenRouter"};function taskSizingSection(deps){return{loadSummary:ctx=>{const read=deps.taskSizing();return{on:read.on&&!read.byEnv,byEnv:read.byEnv,canSwitch:ctx.can.switch===!0,sizer:read.sizer,available:read.available,moved:read.chosen&&!read.on}},renderBlock:({summary})=>({id:"task-sizing",title:`Size tasks with a quick model call (${SIZER_NAME[summary.on&&summary.sizer!==null?summary.sizer:summary.available]})`,state:summary.on?" · on":" · off",lead:summary.byEnv?"Off: TOOLROLL_NO_TASK_CLASSIFIER is set on this computer, so no model call happens before you approve; uncertain tasks get a plan first.":summary.on?`On: before you approve, a quick call to ${SIZER_SHORT[summary.sizer]} sizes each new task, and the plan names it.`:summary.moved&&summary.sizer!==null?`Off: you turned it on for ${SIZER_SHORT[summary.sizer]}, but ${SIZER_SHORT[summary.available]} is the one available now, so nothing is sent. Turn it on again to choose it. Uncertain tasks get a plan first.`:TASK_SIZING_OFF_WORDS,items:summary.canSwitch&&!summary.byEnv?[{type:"actions",actions:[{label:summary.on?"Turn off":"Turn on",href:"/settings/change/task-sizing",sm:!0}]}]:[]}),refusal:"An instance operator changes how tasks are sized.",renderChangeData:({declaration,summary,problem})=>{const home=sectionHref(declaration),on=summary?.on===!0,choice=summary===null?"claude":on&&summary.sizer!==null?summary.sizer:summary.available,title=`Size tasks with a quick model call (${SIZER_NAME[choice]})`;if(summary===null||summary.byEnv)return{group:"general",title,sectionId:"task-sizing",backHref:home,paragraphs:["TOOLROLL_NO_TASK_CLASSIFIER is set on this computer, so task sizing stays off."],cancelHref:home,cancelLabel:"Back to General"};const desc=on?`Turn it off. ${TASK_SIZING_OFF_WORDS}`:choice==="jev"?"Turn it on. Before you approve, each new task's words go to Jev through your OpenRouter key (your credit) to size it: small ones build at once on a fast model, risky ones plan first, and the plan names the model that sized it. Only Jev is asked; if the key goes, sizing turns itself off.":"Turn it on. Before you approve, a quick call to Claude Haiku on your own plan sizes each new task: small ones build at once on a fast model, risky ones plan first, and the plan names the model that sized it. Only Claude is asked; if an OpenRouter key is saved later, sizing turns itself off until you choose again.";return{group:"general",title,sectionId:"task-sizing",backHref:home,problem,paragraphs:[desc],form:{id:"task-sizing-form",proof:"task-sizing",action:"/settings/task-sizing",native:!0,save:{label:on?"Turn off":"Turn on"},confirm:on?"Turn off task sizing":"Turn on task sizing",hidden:{enabled:on?"off":"on",sizer:choice},fields:[]},cancelHref:home}}}}export const FLEXIBLE_SETTING_WORDS="Claude Code only for now. Runs inside Toolroll's sandbox with your Claude sign-in relayed; Toolroll never gives the agent your key.";function flexibleSection(deps){return{loadSummary:ctx=>({on:deps.flexible().on,canSwitch:ctx.can.switch===!0}),renderBlock:({summary})=>({id:"flexible",title:"Interactive agent threads (beta)",state:summary.on?" · on":" · off",lead:`${summary.on?"On":"Off"}. ${FLEXIBLE_SETTING_WORDS}`,items:summary.canSwitch?[{type:"actions",actions:[{label:summary.on?"Turn off":"Turn on",href:"/settings/change/flexible",sm:!0}]}]:[]}),refusal:"An instance operator turns interactive agent threads on or off.",renderChangeData:({declaration,summary,problem})=>{const home=sectionHref(declaration),on=summary?.on===!0,title="Interactive agent threads (beta)";return!on&&deps.passwordFree()?{group:"general",title,sectionId:"flexible",backHref:home,notes:["This needs a Toolroll password, and you haven't set one. Run toolroll password set in a terminal, then sign in here with it."],cancelHref:home,cancelLabel:"Back"}:{group:"general",title,sectionId:"flexible",backHref:home,problem,paragraphs:[on?"Turn them off. No new thread or turn starts, and any thread running now is stopped.":`Turn them on. Press T in the workbench to work with Claude Code in a thread. ${FLEXIBLE_SETTING_WORDS} Each project still needs its own Flexible terms, and each thread shows its terms before it starts.`],form:{id:"flexible-form",proof:on?"flexible-switch":"flexible-switch-on",action:"/settings/flexible",native:!0,save:{label:on?"Turn off":"Turn on"},confirm:on?"Turn off interactive agent threads":"Turn on interactive agent threads",hidden:{enabled:on?"off":"on"},fields:[]},cancelHref:home}}}}function flexibleSignInSection(deps){const title="Your Claude sign-in for threads";return{loadSummary:ctx=>({status:deps.flexibleSignIn(ctx.person.name),threadsOn:deps.flexible().on,canSave:ctx.can.save===!0,canCheck:ctx.can.check===!0,canRemove:ctx.can.remove===!0,passwordFree:deps.passwordFree()}),renderBlock:({summary})=>{const status=summary.status,lead=status.state==="none"?"None. Threads use your own Claude sign-in: run claude setup-token in a terminal, then add the token here. It powers only threads you start.":status.state==="refused"?"Claude didn't accept it. Run claude setup-token again and replace it.":`Saved ${status.savedAt.slice(0,10)}. ${signInCheckWords(statusCheck(status))} It powers only threads you start; a password reset ends it.`,actions=[];return summary.canSave&&actions.push({label:status.state==="none"?"Add":"Replace",href:"/settings/change/flexible-sign-in",sm:!0}),status.state!=="none"&&summary.canCheck&&actions.push({label:"Check again",href:"/settings/change/flexible-sign-in-check",variant:"ghost",sm:!0}),status.state!=="none"&&summary.canRemove&&actions.push({label:"Remove",href:"/settings/change/flexible-sign-in-clear",variant:"ghost",sm:!0}),{id:"flexible-sign-in",title,state:status.state==="none"?" · none":status.state==="refused"?" · not accepted":" · saved",lead,items:[...summary.threadsOn?[]:[{type:"info",text:"Interactive agent threads are off. An instance operator turns them on above."}],...actions.length>0?[{type:"actions",actions}]:[]]}},refusal:"Only you change your own Claude sign-in for threads.",renderChangeData:({declaration,summary,problem,document})=>{const home=sectionHref(declaration),status=summary?.status??{state:"none"};if(document==="flexible-sign-in-clear")return status.state==="none"?{group:"general",title:"Remove your Claude sign-in",sectionId:"flexible-sign-in-clear",backHref:home,paragraphs:["You have no Claude sign-in for threads saved."]}:{group:"general",title:"Remove your Claude sign-in",sectionId:"flexible-sign-in-clear",backHref:home,problem,paragraphs:["Your threads can't reach Claude until you add one again. The token still works at Claude until you revoke it in your Claude account."],form:{id:"flexible-sign-in-clear-form",proof:"flexible-sign-in-clear",action:"/settings/flexible-sign-in-clear",native:!0,save:{label:"Remove",variant:"danger"},confirm:"Remove your Claude sign-in for threads",fields:[]},cancelHref:home};if(document==="flexible-sign-in-check")return status.state==="none"?{group:"general",title:"Check your Claude sign-in",sectionId:"flexible-sign-in-check",backHref:home,paragraphs:["You have no Claude sign-in for threads saved."]}:{group:"general",title:"Check your Claude sign-in",sectionId:"flexible-sign-in-check",backHref:home,problem,paragraphs:["Toolroll asks Claude to count the tokens of one word with your sign-in. It's only a check: it changes nothing, and it never clears a sign-in Claude didn't accept."],form:{id:"flexible-sign-in-check-form",proof:"flexible-sign-in-check",action:"/settings/flexible-sign-in-check",native:!0,save:{label:"Check again"},confirm:"Check your Claude sign-in for threads",fields:[]},cancelHref:home};const heading=status.state==="none"?"Add your Claude sign-in":"Replace your Claude sign-in";return summary?.passwordFree===!0?{group:"general",title:heading,sectionId:"flexible-sign-in",backHref:home,notes:["This needs a Toolroll password, and you haven't set one. Run toolroll password set in a terminal, then sign in here with it."],cancelHref:home,cancelLabel:"Back"}:{group:"general",title:heading,sectionId:"flexible-sign-in",backHref:home,problem,paragraphs:["Threads you start run on your own Claude plan, through this sign-in. Toolroll keeps it for you alone and never shows it again."],form:{id:"flexible-sign-in-form",proof:"flexible-sign-in",action:"/settings/flexible-sign-in",native:!0,save:{label:"Save"},confirm:heading,fields:[{kind:"secret",id:"flexible-sign-in-token",name:"token",label:"Your Claude sign-in",required:!0,hint:"In a terminal, run claude setup-token, finish signing in, and paste the token it prints."}]},cancelHref:home}}}}export function generalSections(deps){return{appearance:appearanceSection(),"this-browser":thisBrowserSection(),"your-password":yourPasswordSection(deps),version:versionSection(deps),"install-mode":installModeSection(deps),"task-sizing":taskSizingSection(deps),flexible:flexibleSection(deps),"flexible-sign-in":flexibleSignInSection(deps),advanced:advancedSection(),"local-mode":localModeSection(deps)}}
1
+ import{ADVANCED_PAGES}from"../advanced-view.js";import{accentNote,ACCENT_PRESETS}from"../accent-colors.js";import{installModeLine,justMeAllowed,TEAM_FACT_WORDS}from"../install-mode.js";import{OWNER_MODE_OTHER_ACCESS_WORDS,OWNER_MODE_WARNING}from"../owner-mode.js";import{signInCheckWords,statusCheck}from"../agent-thread/sign-in.js";import{evaluateRoutePolicy,holdsRole}from"./route-policy.js";import{changeDocumentOf,changeHref,sectionHref,SETTINGS_SECTIONS}from"./settings-section-table.js";function gateHolds(gate,person){switch(gate){case"installation":return person.installation&&!person.restricted;case"cookie-session":return person.via==="cookie";case"full-session":return person.via==="cookie"&&person.authority==="full";case"operator":return person.via==="cookie"&&person.operator;case"approver":return person.role==="approver";case"password-holder":return!(person.via==="cookie"&&person.authority!=="full"&&!person.passwordSet);case"whole-installation":return!person.restricted;case"not-demo":return!person.demo}}const SECTION_RESOLVERS=new Set(["none","session","form","form-path"]),SECTION_LIMITED=new Set(["deny","collection","unscoped","self","conversation"]);export function admitSection(declaration,person,project=null){const policy=declaration.policy;if(person.via==="cookie"&&person.authority!=="full"&&policy.local!=="allow")return{ok:!1,why:"local"};let why=null;const projectAdmits=source=>!SECTION_RESOLVERS.has(source)||!SECTION_LIMITED.has(policy.limited)?(why="project",!1):person.restricted&&(policy.limited==="deny"||policy.limited==="conversation")||person.restricted&&policy.limited!=="unscoped"&&policy.limited!=="self"&&project===null?(why="limited",!1):policy.needsProject&&person.via==="cookie"&&project===null&&!person.unscopedConsole?(why="project",!1):!0,checked=evaluateRoutePolicy(policy,person.principal,projectAdmits);if(!checked.ok)return{ok:!1,why:checked.reason==="project"?why??"project":checked.reason};if(!holdsRole(policy,person,name=>name===person.name&&person.operator))return{ok:!1,why:"role"};for(const gate of declaration.read)if(!gateHolds(gate,person))return{ok:!1,why:`read:${gate}`};const scopes=new Set(Object.entries(declaration.scope).filter(([,gates])=>gates.every(gate=>gateHolds(gate,person))).map(([name])=>name)),can=Object.fromEntries(Object.entries(declaration.act).map(([act,gates])=>[act,gates.every(gate=>gateHolds(gate,person))]));return{ok:!0,scopes,can}}export const PROJECT_NOT_AVAILABLE="That project is not available in this workspace.";export function resolveSettingsProject(url,session,deps){const named=url.searchParams.getAll("repo");if(named.length>1)return{ok:!1,status:400,message:"Name one project."};if(named.length===1){const repo=named[0];return repo===""||!deps.projects().includes(repo)||!deps.canOpen(repo)?{ok:!1,status:404,message:PROJECT_NOT_AVAILABLE}:{ok:!0,project:repo,requested:!0}}return{ok:!0,project:session,requested:!1}}export function sessionProjectCheck(posted,session,projectName){if(posted.length!==1||posted[0]==="")return{ok:!1,rendered:null,session,message:"This form names no project. Open the project and try again."};const rendered=posted[0];return session===null||rendered!==session?{ok:!1,rendered,session,message:`${projectName(rendered)} is no longer the open project${session===null?"":` (${projectName(session)} is)`}. Nothing changed.`}:{ok:!0,project:rendered}}export function askedSection(url){const sections=url.searchParams.getAll("section"),section=sections.length===1&&/^[a-z][a-z-]{0,39}$/.test(sections[0])?sections[0]:null;return{section,open:section!==null&&url.searchParams.getAll("open").length===1&&url.searchParams.get("open")==="1"}}export function renderAreaData(area,impls,base,asked,declarations=SETTINGS_SECTIONS){const sections=[],jump=[],shown=[];for(const declaration of declarations.filter(one=>one.area===area)){const impl=impls[declaration.id];if(impl===void 0)throw new Error(`settings section ${declaration.id} has no implementation`);const admitted=admitSection(declaration,base.person,base.project);if(!admitted.ok)continue;const ctx={...base,scopes:admitted.scopes,can:admitted.can},summary=impl.loadSummary(ctx);if(summary===null)continue;const isAsked=asked.section===declaration.id,detail=isAsked&&asked.open&&declaration.opens&&impl.loadDetail!==void 0?impl.loadDetail(ctx):null;sections.push(impl.renderBlock({declaration,ctx,summary,detail,asked:isAsked,attrs:{"data-section":declaration.id,tabindex:isAsked?"-1":null}})),jump.push({id:declaration.id,title:declaration.title}),shown.push(declaration.id)}return{sections,jump,shown}}export function changeDocumentData(id,impls,base,problem){const change=changeDocumentOf(id),declaration=change?.section,impl=declaration===void 0?void 0:impls[declaration.id];if(change===void 0||declaration===void 0||impl?.renderChangeData===void 0)return{ok:!1,status:404,message:"There's no page at this address."};const admitted=admitSection(declaration,base.person,base.project);if(!admitted.ok||admitted.can[change.act]!==!0)return{ok:!1,status:403,message:impl.refusal??"You can't change this here."};const ctx={...base,scopes:admitted.scopes,can:admitted.can},docData=impl.renderChangeData({declaration,ctx,summary:impl.loadSummary(ctx),detail:null,asked:!0,attrs:{},problem,document:change.id});return{ok:!0,title:docData.title,doc:docData}}const ACCENT_CHOICES=ACCENT_PRESETS.slice(0,6),back="/settings/general";function appearanceSection(){return{loadSummary:ctx=>ctx.prefs,renderBlock:({summary:prefs})=>{const custom=ACCENT_CHOICES.some(one=>one.hex===prefs.accent)?null:prefs.accent,accentNoteWords=accentNote(prefs.accent);return{id:"appearance",title:"Appearance",state:" · saved for this browser",items:[{type:"form",form:{action:"/settings/appearance",hidden:{return:back},fields:[{kind:"segment",name:"theme",label:"Theme",hint:"Light, dark, or whatever this device uses.",current:prefs.theme,items:[["system","Match device"],["light","Light"],["dark","Dark"]]}],save:null}},{type:"form",form:{id:"accent",proof:"appearance",action:"/settings/appearance",gate:!0,hidden:{return:back},fields:[{kind:"select",name:"accent",label:"Accent",hint:"Buttons, focus and what needs you.",current:prefs.accent,items:[...ACCENT_CHOICES.map(one=>[one.hex,one.id==="ink"?"Ink (default)":one.name]),...custom===null?[]:[[custom,`Your own colour (${custom})`]]]},...accentNoteWords===null?[]:[{kind:"note",text:accentNoteWords}]]}},{type:"disclose",label:"Use your own colour",open:custom!==null,items:[{type:"form",form:{id:"accent-picker",proof:"appearance",action:"/settings/appearance",gate:!0,hidden:{return:back},fields:[{kind:"color",name:"accent",label:"Colour picker",hint:"Pick any swatch for buttons, focus and what needs you.",value:prefs.accent,ariaLabel:"Pick a colour"}]}},{type:"form",form:{id:"accent-own",proof:"appearance",action:"/settings/appearance",gate:!0,hidden:{return:back},fields:[{kind:"input",id:"accent-hex",name:"accent",label:"Hex code",hint:"Six hex digits, like #3b82f6.",value:custom??"",placeholder:"#3b82f6",required:!0,pattern:"#?[0-9a-fA-F]{6}",spellCheck:!1,autoComplete:"off",ariaLabel:"Your own colour"}]}}]}]}}}}function thisBrowserSection(){return{loadSummary:ctx=>({forget:ctx.can.forget===!0}),renderBlock:({summary})=>({id:"this-browser",title:"This browser",items:[{type:"note",text:"Remembered password: after you type your password, standard approvals skip it on this computer for 15 minutes."},...summary.forget?[{type:"form",form:{action:"/session/forget-password",hidden:{return:back},save:{label:"Forget now",sm:!0},fields:[]}}]:[]]})}}function yourPasswordSection(deps){return{loadSummary:ctx=>({passwordless:ctx.scopes.has("passwordless")?deps.passwordless():null}),renderBlock:({summary})=>{const saved=deps.savedLogin?.()??null,items=[saved===null?{type:"note",text:"Forgot it? On the computer running Toolroll, run",code:"toolroll password reset"}:{type:"note",text:"Your first password is saved on the computer running Toolroll. To read it, run",code:`cat ${saved}`}];return summary.passwordless!==null&&items.push({type:"actions",actions:[{label:`Passwordless: ${summary.passwordless?"On":"Off"} · Change`,href:"/settings/passwordless",sm:!0}]}),{id:"your-password",title:"Your password",items}}}}function versionSection(deps){return{loadSummary:ctx=>{const version=(ctx.scopes.has("updates-version")?deps.updatesVersion(ctx.person.name):null)??(ctx.scopes.has("package-version")?deps.packageVersion:null),drift=ctx.scopes.has("updates-version")?deps.runtimeDrift?.()??null:null;return version===null?null:{version,firstResult:deps.firstResult(ctx.now),updates:ctx.can.updates===!0,drift}},renderBlock:({summary})=>({id:"version",title:"Version",items:[{type:"facts",rows:[{label:"Toolroll",value:summary.version,mono:!0}]},...summary.firstResult?[{type:"note",text:summary.firstResult}]:[],...summary.drift?[{type:"info",text:summary.drift}]:[],...summary.updates?[{type:"actions",actions:[{label:"Open updates",href:"/settings/updates",variant:"ghost",sm:!0}]}]:[]]})}}function advancedSection(){return{loadSummary:ctx=>({on:ctx.prefs.advanced,canSwitch:ctx.can.switch===!0}),loadDetail:ctx=>ADVANCED_PAGES.filter(one=>one.operator!==!0||ctx.scopes.has("operator-pages")),renderBlock:({declaration,summary,detail})=>({id:"advanced",title:"Show advanced features",state:summary.on?" · on":" · off",lead:"Flows, other computers, spend limits, operating modes and the rest, in your menus. They keep working either way.",right:{id:"show-advanced",items:summary.canSwitch?[{type:"form",form:{action:"/settings/advanced",hidden:{advanced:summary.on?"off":"on"},save:{label:summary.on?"Turn off":"Turn on",sm:!0},fields:[]}}]:[]},items:[detail===null?{type:"actions",actions:[{label:"See advanced pages",href:`${sectionHref(declaration,{open:!0})}#advanced`,variant:"ghost",sm:!0}]}:{type:"links",links:detail.map(one=>({label:one.title,href:one.href,sub:one.words}))}]})}}function localModeSection(deps){return{loadSummary:ctx=>{if(!deps.localModeOn())return null;const owner=ctx.person.authority!=="full";return owner?ctx.person.passwordSet?null:{owner,turnOff:!1}:ctx.can["turn-off"]===!0?{owner,turnOff:!0}:null},renderBlock:({declaration,summary})=>summary.owner?{id:"local-mode",title:"Let agents work on their own",lead:"Agents can work on their own, merge and release only after you set a password.",items:[{type:"actions",actions:[{label:"Set a password",href:"/password/set?next=%2Fsettings%2Fgeneral",sm:!0}]}]}:{id:"local-mode",title:"Local mode",state:" · on",lead:"A browser on this computer can file tasks, approve plans and add projects without your password.",items:[{type:"actions",actions:[{label:"Turn off local mode",href:changeHref(declaration.changes[0]),sm:!0}]}]},refusal:"An instance operator signed in with a password turns off local mode.",renderChangeData:({declaration,summary,problem})=>{const home=sectionHref(declaration),title="Turn off local mode";return summary===null||!summary.turnOff?{group:"general",title,sectionId:"local-mode-off",backHref:home,paragraphs:["Local mode is off. This computer's browser signs in with a password."],cancelHref:home,cancelLabel:"Back to General"}:{group:"general",title,sectionId:"local-mode-off",backHref:home,problem,paragraphs:["Local mode lets a browser on this computer file tasks, approve plans and add projects without a password. Turned off, every browser signs in with a password, and the local owner's sessions and links stop working. You can't turn it back on here."],form:{id:"local-mode-form",proof:"local-mode-off",action:"/settings/local-mode/off",native:!0,save:{label:"Turn off"},confirm:title,fields:[]},cancelHref:home}}}}function installModeSection(deps){return{loadSummary:ctx=>{const read=deps.installMode(),canSwitch=ctx.can["just-me"]===!0;return{mode:read.mode,facts:read.facts,canSwitch,offered:canSwitch&&justMeAllowed(read)}},renderBlock:({declaration,summary})=>{const line=installModeLine(summary.mode);return{id:"install-mode",title:line.label,lead:line.words,items:summary.offered?[{type:"actions",actions:[{label:"It's just me",href:changeHref(declaration.changes[0]),sm:!0}]}]:[]}},refusal:"An instance operator signed in with a password says it's just them.",renderChangeData:({declaration,summary,problem})=>{const home=sectionHref(declaration),title="It's just me",blocked=summary===null?[]:summary.facts.filter(fact=>fact!=="existing-install"&&!fact.endsWith("-added"));return summary===null||summary.mode==="solo"?{group:"general",title,sectionId:"install-mode",backHref:home,paragraphs:["This install is solo."],cancelHref:home,cancelLabel:"Back to General"}:summary.offered?{group:"general",title,sectionId:"install-mode",backHref:home,problem,paragraphs:["Approvals and Accept then need only you signed in. Signing in, tokens and connecting things still ask for your password. If anyone joins, this install switches back to Team."],form:{id:"just-me-form",proof:"install-solo",action:"/settings/install-mode/solo",native:!0,save:{label:title},confirm:title,fields:[]},cancelHref:home}:{group:"general",title,sectionId:"install-mode",backHref:home,problem:blocked.map(fact=>TEAM_FACT_WORDS[fact]).join(" "),cancelHref:home,cancelLabel:"Back to General"}}}}function ownerModeSection(deps){return{loadSummary:ctx=>{const read=deps.ownerMode?.()??{mode:"secure",explicit:!1,updatedBy:null,updatedAt:null,reason:"other-access",owner:null,otherAccess:!0};return{mode:read.mode,explicit:read.explicit,otherAccess:read.otherAccess===!0,canSwitch:ctx.can.switch===!0}},renderBlock:({declaration,summary})=>({id:"owner-mode",title:"Fast or Secure mode",state:summary.mode==="fast"?" · Fast":" · Secure",lead:summary.mode==="fast"?`Fast (no passwords for you). ${OWNER_MODE_WARNING}`:summary.otherAccess?`${OWNER_MODE_OTHER_ACCESS_WORDS}. ${OWNER_MODE_WARNING}`:`Secure (password for setup and approvals). ${OWNER_MODE_WARNING}`,items:!summary.canSwitch||summary.otherAccess?[]:summary.mode==="fast"?[{type:"form",form:{action:"/settings/owner-mode",hidden:{mode:"secure"},save:{label:"Switch to Secure",sm:!0},fields:[]}}]:[{type:"actions",actions:[{label:"Switch to Fast",href:changeHref(declaration.changes[0]),sm:!0}]}]}),refusal:"An instance operator signed in with a password changes Fast or Secure mode.",renderChangeData:({declaration,summary,problem})=>{const home=sectionHref(declaration),isFast=summary?.mode==="fast",title=isFast?"Switch to Secure mode":"Switch to Fast mode";return summary===null?{group:"general",title,sectionId:"owner-mode",backHref:home,paragraphs:[OWNER_MODE_WARNING],cancelHref:home,cancelLabel:"Back to General"}:summary.otherAccess?{group:"general",title,sectionId:"owner-mode",backHref:home,problem,paragraphs:[`${OWNER_MODE_OTHER_ACCESS_WORDS}.`,OWNER_MODE_WARNING],cancelHref:home,cancelLabel:"Back to General"}:isFast?{group:"general",title,sectionId:"owner-mode",backHref:home,problem,paragraphs:["Secure (password for setup and approvals). Builds stay restricted and setup changes ask for your password."],form:{id:"owner-mode-form",action:"/settings/owner-mode",native:!0,save:{label:"Switch to Secure"},hidden:{mode:"secure"},fields:[]},cancelHref:home}:{group:"general",title,sectionId:"owner-mode",backHref:home,problem,paragraphs:["Fast (no passwords for you). Everyday setup, routing, network, checks and landings need no password from your browser session.",OWNER_MODE_WARNING],form:{id:"owner-mode-form",proof:"owner-mode-fast",action:"/settings/owner-mode",native:!0,save:{label:"Switch to Fast"},confirm:title,hidden:{mode:"fast"},fields:[]},cancelHref:home}}}}const TASK_SIZING_OFF_WORDS="Off: no model call before you approve; uncertain tasks get a plan first.",SIZER_NAME={claude:"Claude Haiku, on your plan",jev:"Jev via OpenRouter, your credit"},SIZER_SHORT={claude:"Claude Haiku",jev:"Jev via OpenRouter"};function taskSizingSection(deps){return{loadSummary:ctx=>{const read=deps.taskSizing();return{on:read.on&&!read.byEnv,byEnv:read.byEnv,canSwitch:ctx.can.switch===!0,sizer:read.sizer,available:read.available,moved:read.chosen&&!read.on}},renderBlock:({summary})=>({id:"task-sizing",title:`Size tasks with a quick model call (${SIZER_NAME[summary.on&&summary.sizer!==null?summary.sizer:summary.available]})`,state:summary.on?" · on":" · off",lead:summary.byEnv?"Off: TOOLROLL_NO_TASK_CLASSIFIER is set on this computer, so no model call happens before you approve; uncertain tasks get a plan first.":summary.on?`On: before you approve, a quick call to ${SIZER_SHORT[summary.sizer]} sizes each new task, and the plan names it.`:summary.moved&&summary.sizer!==null?`Off: you turned it on for ${SIZER_SHORT[summary.sizer]}, but ${SIZER_SHORT[summary.available]} is the one available now, so nothing is sent. Turn it on again to choose it. Uncertain tasks get a plan first.`:TASK_SIZING_OFF_WORDS,items:summary.canSwitch&&!summary.byEnv?[{type:"actions",actions:[{label:summary.on?"Turn off":"Turn on",href:"/settings/change/task-sizing",sm:!0}]}]:[]}),refusal:"An instance operator changes how tasks are sized.",renderChangeData:({declaration,summary,problem})=>{const home=sectionHref(declaration),on=summary?.on===!0,choice=summary===null?"claude":on&&summary.sizer!==null?summary.sizer:summary.available,title=`Size tasks with a quick model call (${SIZER_NAME[choice]})`;if(summary===null||summary.byEnv)return{group:"general",title,sectionId:"task-sizing",backHref:home,paragraphs:["TOOLROLL_NO_TASK_CLASSIFIER is set on this computer, so task sizing stays off."],cancelHref:home,cancelLabel:"Back to General"};const desc=on?`Turn it off. ${TASK_SIZING_OFF_WORDS}`:choice==="jev"?"Turn it on. Before you approve, each new task's words go to Jev through your OpenRouter key (your credit) to size it: small ones build at once on a fast model, risky ones plan first, and the plan names the model that sized it. Only Jev is asked; if the key goes, sizing turns itself off.":"Turn it on. Before you approve, a quick call to Claude Haiku on your own plan sizes each new task: small ones build at once on a fast model, risky ones plan first, and the plan names the model that sized it. Only Claude is asked; if an OpenRouter key is saved later, sizing turns itself off until you choose again.";return{group:"general",title,sectionId:"task-sizing",backHref:home,problem,paragraphs:[desc],form:{id:"task-sizing-form",proof:"task-sizing",action:"/settings/task-sizing",native:!0,save:{label:on?"Turn off":"Turn on"},confirm:on?"Turn off task sizing":"Turn on task sizing",hidden:{enabled:on?"off":"on",sizer:choice},fields:[]},cancelHref:home}}}}export const FLEXIBLE_SETTING_WORDS="Claude Code only for now. Runs inside Toolroll's sandbox with your Claude sign-in relayed; Toolroll never gives the agent your key.";function flexibleSection(deps){return{loadSummary:ctx=>({on:deps.flexible().on,canSwitch:ctx.can.switch===!0}),renderBlock:({summary})=>({id:"flexible",title:"Interactive agent threads (beta)",state:summary.on?" · on":" · off",lead:`${summary.on?"On":"Off"}. ${FLEXIBLE_SETTING_WORDS}`,items:summary.canSwitch?[{type:"actions",actions:[{label:summary.on?"Turn off":"Turn on",href:"/settings/change/flexible",sm:!0}]}]:[]}),refusal:"An instance operator turns interactive agent threads on or off.",renderChangeData:({declaration,summary,problem})=>{const home=sectionHref(declaration),on=summary?.on===!0,title="Interactive agent threads (beta)";return!on&&deps.passwordFree()?{group:"general",title,sectionId:"flexible",backHref:home,notes:["This needs a Toolroll password, and you haven't set one. Run toolroll password set in a terminal, then sign in here with it."],cancelHref:home,cancelLabel:"Back"}:{group:"general",title,sectionId:"flexible",backHref:home,problem,paragraphs:[on?"Turn them off. No new thread or turn starts, and any thread running now is stopped.":`Turn them on. Press T in the workbench to work with Claude Code in a thread. ${FLEXIBLE_SETTING_WORDS} Each project still needs its own Flexible terms, and each thread shows its terms before it starts.`],form:{id:"flexible-form",proof:on?"flexible-switch":"flexible-switch-on",action:"/settings/flexible",native:!0,save:{label:on?"Turn off":"Turn on"},confirm:on?"Turn off interactive agent threads":"Turn on interactive agent threads",hidden:{enabled:on?"off":"on"},fields:[]},cancelHref:home}}}}function flexibleSignInSection(deps){const title="Your Claude sign-in for threads";return{loadSummary:ctx=>({status:deps.flexibleSignIn(ctx.person.name),threadsOn:deps.flexible().on,canSave:ctx.can.save===!0,canCheck:ctx.can.check===!0,canRemove:ctx.can.remove===!0,passwordFree:deps.passwordFree()}),renderBlock:({summary})=>{const status=summary.status,lead=status.state==="none"?"None. Threads use your own Claude sign-in: run claude setup-token in a terminal, then add the token here. It powers only threads you start.":status.state==="refused"?"Claude didn't accept it. Run claude setup-token again and replace it.":`Saved ${status.savedAt.slice(0,10)}. ${signInCheckWords(statusCheck(status))} It powers only threads you start; a password reset ends it.`,actions=[];return summary.canSave&&actions.push({label:status.state==="none"?"Add":"Replace",href:"/settings/change/flexible-sign-in",sm:!0}),status.state!=="none"&&summary.canCheck&&actions.push({label:"Check again",href:"/settings/change/flexible-sign-in-check",variant:"ghost",sm:!0}),status.state!=="none"&&summary.canRemove&&actions.push({label:"Remove",href:"/settings/change/flexible-sign-in-clear",variant:"ghost",sm:!0}),{id:"flexible-sign-in",title,state:status.state==="none"?" · none":status.state==="refused"?" · not accepted":" · saved",lead,items:[...summary.threadsOn?[]:[{type:"info",text:"Interactive agent threads are off. An instance operator turns them on above."}],...actions.length>0?[{type:"actions",actions}]:[]]}},refusal:"Only you change your own Claude sign-in for threads.",renderChangeData:({declaration,summary,problem,document})=>{const home=sectionHref(declaration),status=summary?.status??{state:"none"};if(document==="flexible-sign-in-clear")return status.state==="none"?{group:"general",title:"Remove your Claude sign-in",sectionId:"flexible-sign-in-clear",backHref:home,paragraphs:["You have no Claude sign-in for threads saved."]}:{group:"general",title:"Remove your Claude sign-in",sectionId:"flexible-sign-in-clear",backHref:home,problem,paragraphs:["Your threads can't reach Claude until you add one again. The token still works at Claude until you revoke it in your Claude account."],form:{id:"flexible-sign-in-clear-form",proof:"flexible-sign-in-clear",action:"/settings/flexible-sign-in-clear",native:!0,save:{label:"Remove",variant:"danger"},confirm:"Remove your Claude sign-in for threads",fields:[]},cancelHref:home};if(document==="flexible-sign-in-check")return status.state==="none"?{group:"general",title:"Check your Claude sign-in",sectionId:"flexible-sign-in-check",backHref:home,paragraphs:["You have no Claude sign-in for threads saved."]}:{group:"general",title:"Check your Claude sign-in",sectionId:"flexible-sign-in-check",backHref:home,problem,paragraphs:["Toolroll asks Claude to count the tokens of one word with your sign-in. It's only a check: it changes nothing, and it never clears a sign-in Claude didn't accept."],form:{id:"flexible-sign-in-check-form",proof:"flexible-sign-in-check",action:"/settings/flexible-sign-in-check",native:!0,save:{label:"Check again"},confirm:"Check your Claude sign-in for threads",fields:[]},cancelHref:home};const heading=status.state==="none"?"Add your Claude sign-in":"Replace your Claude sign-in";return summary?.passwordFree===!0?{group:"general",title:heading,sectionId:"flexible-sign-in",backHref:home,notes:["This needs a Toolroll password, and you haven't set one. Run toolroll password set in a terminal, then sign in here with it."],cancelHref:home,cancelLabel:"Back"}:{group:"general",title:heading,sectionId:"flexible-sign-in",backHref:home,problem,paragraphs:["Threads you start run on your own Claude plan, through this sign-in. Toolroll keeps it for you alone and never shows it again."],form:{id:"flexible-sign-in-form",proof:"flexible-sign-in",action:"/settings/flexible-sign-in",native:!0,save:{label:"Save"},confirm:heading,fields:[{kind:"secret",id:"flexible-sign-in-token",name:"token",label:"Your Claude sign-in",required:!0,hint:"In a terminal, run claude setup-token, finish signing in, and paste the token it prints."}]},cancelHref:home}}}}export function generalSections(deps){return{appearance:appearanceSection(),"this-browser":thisBrowserSection(),"your-password":yourPasswordSection(deps),version:versionSection(deps),"install-mode":installModeSection(deps),"owner-mode":ownerModeSection(deps),"task-sizing":taskSizingSection(deps),flexible:flexibleSection(deps),"flexible-sign-in":flexibleSignInSection(deps),advanced:advancedSection(),"local-mode":localModeSection(deps)}}