painapple-code 1.0.0__py3-none-any.whl

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 (436) hide show
  1. painapple_code/__init__.py +30 -0
  2. painapple_code/__main__.py +18 -0
  3. painapple_code/_version.py +24 -0
  4. painapple_code/auth_middleware.py +930 -0
  5. painapple_code/cli/__init__.py +204 -0
  6. painapple_code/cli/deploy/__init__.py +15 -0
  7. painapple_code/cli/deploy/claude_seed.py +41 -0
  8. painapple_code/cli/deploy/config.py +260 -0
  9. painapple_code/cli/deploy/container.py +715 -0
  10. painapple_code/cli/deploy/launch.py +163 -0
  11. painapple_code/cli/deploy/runtime.py +223 -0
  12. painapple_code/cli/lifecycle_cmd.py +443 -0
  13. painapple_code/cli/list_cmd.py +572 -0
  14. painapple_code/cli/manage_cmd.py +670 -0
  15. painapple_code/cli/netinfo.py +125 -0
  16. painapple_code/cli/profiles.py +390 -0
  17. painapple_code/cli/serve_args.py +163 -0
  18. painapple_code/cli/serve_config.py +256 -0
  19. painapple_code/cli/setup_cmd.py +664 -0
  20. painapple_code/cli/ui.py +438 -0
  21. painapple_code/cost_analytics.py +879 -0
  22. painapple_code/data/models.defaults.yaml +18 -0
  23. painapple_code/data/models.yaml +18 -0
  24. painapple_code/data/presets.defaults.json +32 -0
  25. painapple_code/data/strings.yaml +2269 -0
  26. painapple_code/helpers.py +406 -0
  27. painapple_code/paths.py +1514 -0
  28. painapple_code/prompt_explorer.py +984 -0
  29. painapple_code/providers/__init__.py +224 -0
  30. painapple_code/providers/base.py +710 -0
  31. painapple_code/providers/claude/__init__.py +74 -0
  32. painapple_code/providers/claude/capabilities.py +218 -0
  33. painapple_code/providers/claude/errors.py +79 -0
  34. painapple_code/providers/claude/launch.py +50 -0
  35. painapple_code/providers/claude/summary.py +89 -0
  36. painapple_code/providers/claude/translate.py +74 -0
  37. painapple_code/providers/claude_sdk/__init__.py +139 -0
  38. painapple_code/providers/claude_sdk/driver.py +412 -0
  39. painapple_code/providers/codex/__init__.py +87 -0
  40. painapple_code/providers/codex/capabilities.py +321 -0
  41. painapple_code/providers/codex/errors.py +70 -0
  42. painapple_code/providers/codex/launch.py +142 -0
  43. painapple_code/providers/codex/summary.py +196 -0
  44. painapple_code/providers/codex/translate.py +204 -0
  45. painapple_code/providers/codex_app_server/__init__.py +100 -0
  46. painapple_code/providers/codex_app_server/capabilities.py +41 -0
  47. painapple_code/providers/codex_app_server/launch.py +202 -0
  48. painapple_code/providers/codex_app_server/summary.py +291 -0
  49. painapple_code/providers/codex_app_server/translate.py +263 -0
  50. painapple_code/providers/codex_app_server/transport.py +238 -0
  51. painapple_code/routes/__init__.py +0 -0
  52. painapple_code/routes/api_agents.py +441 -0
  53. painapple_code/routes/api_app.py +368 -0
  54. painapple_code/routes/api_app_commit_sections.py +127 -0
  55. painapple_code/routes/api_app_config.py +997 -0
  56. painapple_code/routes/api_app_session_prefs.py +217 -0
  57. painapple_code/routes/api_browser.py +690 -0
  58. painapple_code/routes/api_commands.py +374 -0
  59. painapple_code/routes/api_costs.py +128 -0
  60. painapple_code/routes/api_drafts.py +139 -0
  61. painapple_code/routes/api_exec.py +149 -0
  62. painapple_code/routes/api_files.py +542 -0
  63. painapple_code/routes/api_git.py +657 -0
  64. painapple_code/routes/api_logs.py +649 -0
  65. painapple_code/routes/api_plugins.py +275 -0
  66. painapple_code/routes/api_project_config.py +418 -0
  67. painapple_code/routes/api_prompts.py +231 -0
  68. painapple_code/routes/api_providers.py +53 -0
  69. painapple_code/routes/api_search.py +411 -0
  70. painapple_code/routes/api_session_stash.py +234 -0
  71. painapple_code/routes/api_session_welcome.py +151 -0
  72. painapple_code/routes/api_sessions.py +742 -0
  73. painapple_code/routes/api_shadow.py +323 -0
  74. painapple_code/routes/api_shadow_db.py +512 -0
  75. painapple_code/routes/api_shadow_files.py +332 -0
  76. painapple_code/routes/api_shadow_search.py +476 -0
  77. painapple_code/routes/api_skills.py +610 -0
  78. painapple_code/routes/api_tasks.py +147 -0
  79. painapple_code/routes/api_terminal.py +540 -0
  80. painapple_code/routes/api_upload.py +293 -0
  81. painapple_code/routes/api_viewer.py +229 -0
  82. painapple_code/routes/dependencies.py +109 -0
  83. painapple_code/routes/ws_chat.py +837 -0
  84. painapple_code/server.py +2208 -0
  85. painapple_code/server_logging.py +263 -0
  86. painapple_code/services/__init__.py +0 -0
  87. painapple_code/services/agent_session.py +2738 -0
  88. painapple_code/session_store.py +253 -0
  89. painapple_code/session_store_core.py +879 -0
  90. painapple_code/shadow_db.py +830 -0
  91. painapple_code/shadow_db_plans.py +369 -0
  92. painapple_code/shadow_db_queries.py +595 -0
  93. painapple_code/shadow_db_schema.py +676 -0
  94. painapple_code/shadow_git.py +1296 -0
  95. painapple_code/shadow_git_frontmatter.py +314 -0
  96. painapple_code/shadow_git_sections.py +520 -0
  97. painapple_code/shadow_git_summary.py +462 -0
  98. painapple_code/shadow_parser.py +560 -0
  99. painapple_code/static/css/00-variables.css +276 -0
  100. painapple_code/static/css/01-base.css +245 -0
  101. painapple_code/static/css/02-tooltips.css +36 -0
  102. painapple_code/static/css/09-left-rail.css +448 -0
  103. painapple_code/static/css/10-header.css +777 -0
  104. painapple_code/static/css/11-connection-bar.css +120 -0
  105. painapple_code/static/css/20-messages.css +750 -0
  106. painapple_code/static/css/21-tool-blocks.css +2340 -0
  107. painapple_code/static/css/22-edit-diff.css +619 -0
  108. painapple_code/static/css/23-thinking.css +1584 -0
  109. painapple_code/static/css/24-background-tasks.css +359 -0
  110. painapple_code/static/css/25-context-block.css +252 -0
  111. painapple_code/static/css/26-session-setup.css +144 -0
  112. painapple_code/static/css/30-markdown.css +854 -0
  113. painapple_code/static/css/40-input.css +2418 -0
  114. painapple_code/static/css/41-autocomplete.css +127 -0
  115. painapple_code/static/css/42-activity-strip.css +97 -0
  116. painapple_code/static/css/43-file-autocomplete.css +121 -0
  117. painapple_code/static/css/44-snippets-autocomplete.css +224 -0
  118. painapple_code/static/css/45-selection-bar.css +433 -0
  119. painapple_code/static/css/46-keyboard-bar.css +119 -0
  120. painapple_code/static/css/47-keyboard-longpress.css +116 -0
  121. painapple_code/static/css/47-token-profile.css +106 -0
  122. painapple_code/static/css/50-welcome.css +3095 -0
  123. painapple_code/static/css/51-modals.css +301 -0
  124. painapple_code/static/css/52-utilities.css +77 -0
  125. painapple_code/static/css/53-image-upload.css +456 -0
  126. painapple_code/static/css/54-todo-list.css +102 -0
  127. painapple_code/static/css/55-file-upload.css +113 -0
  128. painapple_code/static/css/56-chat-navigator.css +218 -0
  129. painapple_code/static/css/56-permission-card.css +332 -0
  130. painapple_code/static/css/56-plan-approval.css +204 -0
  131. painapple_code/static/css/56-question-form.css +602 -0
  132. painapple_code/static/css/57-swipe-indicator.css +95 -0
  133. painapple_code/static/css/58-session-families.css +627 -0
  134. painapple_code/static/css/59-about.css +196 -0
  135. painapple_code/static/css/61-log-explorer.css +723 -0
  136. painapple_code/static/css/62-json-tree.css +489 -0
  137. painapple_code/static/css/62-skills-widget.css +650 -0
  138. painapple_code/static/css/63-commands-widget.css +30 -0
  139. painapple_code/static/css/63-plugins-widget.css +174 -0
  140. painapple_code/static/css/63-terminal.css +516 -0
  141. painapple_code/static/css/64-search-files-widget.css +448 -0
  142. painapple_code/static/css/65-snippets-widget.css +426 -0
  143. painapple_code/static/css/66-active-sessions.css +979 -0
  144. painapple_code/static/css/66-agents-widget.css +265 -0
  145. painapple_code/static/css/66-file-explorer-widget.css +855 -0
  146. painapple_code/static/css/66-git-panel.css +791 -0
  147. painapple_code/static/css/66-history-explorer.css +1496 -0
  148. painapple_code/static/css/67-diff-viewer.css +602 -0
  149. painapple_code/static/css/67-editor-view.css +748 -0
  150. painapple_code/static/css/67-file-preview-widget.css +1873 -0
  151. painapple_code/static/css/68-browser-widget.css +337 -0
  152. painapple_code/static/css/68-compare-wizard.css +355 -0
  153. painapple_code/static/css/68-csv-preview.css +106 -0
  154. painapple_code/static/css/68-diff-preview.css +103 -0
  155. painapple_code/static/css/68-helpers-install-widget.css +491 -0
  156. painapple_code/static/css/68-image-annotate.css +346 -0
  157. painapple_code/static/css/68-terminal-view.css +98 -0
  158. painapple_code/static/css/68-uploads-widget.css +229 -0
  159. painapple_code/static/css/69-cost-analytics.css +537 -0
  160. painapple_code/static/css/70-config-panel.css +3736 -0
  161. painapple_code/static/css/70-excalidraw.css +136 -0
  162. painapple_code/static/css/70-prompt-explorer.css +890 -0
  163. painapple_code/static/css/71-chart.css +111 -0
  164. painapple_code/static/css/72-discussion-sidebar.css +678 -0
  165. painapple_code/static/css/74-debug-logs.css +656 -0
  166. painapple_code/static/css/80-open-dialog.css +146 -0
  167. painapple_code/static/css/80-quick-switcher.css +383 -0
  168. painapple_code/static/css/80-widget-system.css +1763 -0
  169. painapple_code/static/css/81-quick-actions.css +1020 -0
  170. painapple_code/static/css/82-context-popover.css +1233 -0
  171. painapple_code/static/css/83-context-menu.css +339 -0
  172. painapple_code/static/css/85-lazy-loading.css +102 -0
  173. painapple_code/static/css/86-zen-mode.css +708 -0
  174. painapple_code/static/css/87-grid-switcher.css +346 -0
  175. painapple_code/static/css/login.css +198 -0
  176. painapple_code/static/dist/app.bundle.js +7177 -0
  177. painapple_code/static/feature-triage.html +446 -0
  178. painapple_code/static/icons/apple-touch-icon.png +0 -0
  179. painapple_code/static/icons/favicon-32.png +0 -0
  180. painapple_code/static/icons/favicon.ico +0 -0
  181. painapple_code/static/icons/icon-128.png +0 -0
  182. painapple_code/static/icons/icon-144.png +0 -0
  183. painapple_code/static/icons/icon-152.png +0 -0
  184. painapple_code/static/icons/icon-180.png +0 -0
  185. painapple_code/static/icons/icon-192.png +0 -0
  186. painapple_code/static/icons/icon-384.png +0 -0
  187. painapple_code/static/icons/icon-512.png +0 -0
  188. painapple_code/static/icons/icon-72.png +0 -0
  189. painapple_code/static/icons/icon-96.png +0 -0
  190. painapple_code/static/js/action-delegate.js +187 -0
  191. painapple_code/static/js/activity-strip.js +193 -0
  192. painapple_code/static/js/app/context-menus.js +619 -0
  193. painapple_code/static/js/app/file-preview.js +163 -0
  194. painapple_code/static/js/app/init-ui.js +574 -0
  195. painapple_code/static/js/app/input-events.js +561 -0
  196. painapple_code/static/js/app/input-resize.js +313 -0
  197. painapple_code/static/js/app/message-actions.js +419 -0
  198. painapple_code/static/js/app/panels.js +210 -0
  199. painapple_code/static/js/app/rendering-delegators.js +246 -0
  200. painapple_code/static/js/app/server-loading.js +365 -0
  201. painapple_code/static/js/app/session-ops.js +287 -0
  202. painapple_code/static/js/app/session-switch.js +443 -0
  203. painapple_code/static/js/app/settings-helpers.js +280 -0
  204. painapple_code/static/js/app/startup-welcome.js +290 -0
  205. painapple_code/static/js/app-context.js +157 -0
  206. painapple_code/static/js/app.js +2134 -0
  207. painapple_code/static/js/auth-fetch.js +46 -0
  208. painapple_code/static/js/background-tasks.js +274 -0
  209. painapple_code/static/js/boot.js +73 -0
  210. painapple_code/static/js/caret-position.js +171 -0
  211. painapple_code/static/js/chat-navigator.js +710 -0
  212. painapple_code/static/js/chat-search.js +323 -0
  213. painapple_code/static/js/command-executor.js +176 -0
  214. painapple_code/static/js/command-store.js +497 -0
  215. painapple_code/static/js/components.js +1414 -0
  216. painapple_code/static/js/config.js +218 -0
  217. painapple_code/static/js/context-menu.js +740 -0
  218. painapple_code/static/js/controllers/chat-controller.js +4252 -0
  219. painapple_code/static/js/controllers/dialog-controller.js +217 -0
  220. painapple_code/static/js/controllers/tab-controller.js +1828 -0
  221. painapple_code/static/js/controllers/thinking-controller.js +915 -0
  222. painapple_code/static/js/diff-utils.js +486 -0
  223. painapple_code/static/js/drafts-pill.js +95 -0
  224. painapple_code/static/js/editor-view.js +815 -0
  225. painapple_code/static/js/effort-settings.js +430 -0
  226. painapple_code/static/js/feature-triage.js +811 -0
  227. painapple_code/static/js/file-autocomplete.js +516 -0
  228. painapple_code/static/js/file-tabs.js +123 -0
  229. painapple_code/static/js/gestures.js +448 -0
  230. painapple_code/static/js/grid-switcher.js +334 -0
  231. painapple_code/static/js/input-handler.js +1472 -0
  232. painapple_code/static/js/keyboard-bar.js +495 -0
  233. painapple_code/static/js/layout-switcher.js +109 -0
  234. painapple_code/static/js/linkify-utils.js +200 -0
  235. painapple_code/static/js/login.js +141 -0
  236. painapple_code/static/js/open-dialog.js +879 -0
  237. painapple_code/static/js/orphan-terminals.js +373 -0
  238. painapple_code/static/js/path-utils.js +179 -0
  239. painapple_code/static/js/perf-marks.js +102 -0
  240. painapple_code/static/js/permission-settings.js +475 -0
  241. painapple_code/static/js/pointer-input.js +59 -0
  242. painapple_code/static/js/preview/json-tree-menu.js +226 -0
  243. painapple_code/static/js/preview/json-tree-toolbar.js +291 -0
  244. painapple_code/static/js/preview/json-tree.js +457 -0
  245. painapple_code/static/js/preview/preview-breadcrumb.js +387 -0
  246. painapple_code/static/js/preview/preview-edit.js +367 -0
  247. painapple_code/static/js/preview/preview-events.js +361 -0
  248. painapple_code/static/js/preview/preview-history.js +567 -0
  249. painapple_code/static/js/preview/preview-inline-edit.js +869 -0
  250. painapple_code/static/js/preview/preview-poll.js +108 -0
  251. painapple_code/static/js/preview/preview-render.js +572 -0
  252. painapple_code/static/js/preview/preview-search.js +421 -0
  253. painapple_code/static/js/preview/preview-state.js +256 -0
  254. painapple_code/static/js/preview/preview-utils.js +251 -0
  255. painapple_code/static/js/preview-plugins/chart-plugin.js +22 -0
  256. painapple_code/static/js/preview-plugins/csv-plugin.js +188 -0
  257. painapple_code/static/js/preview-plugins/diff-plugin.js +258 -0
  258. painapple_code/static/js/preview-plugins/excalidraw-plugin.js +25 -0
  259. painapple_code/static/js/preview-plugins/html-plugin.js +104 -0
  260. painapple_code/static/js/preview-plugins/image-plugin.js +20 -0
  261. painapple_code/static/js/preview-plugins/index.js +34 -0
  262. painapple_code/static/js/preview-plugins/json-plugin.js +99 -0
  263. painapple_code/static/js/preview-plugins/jsonl-plugin.js +152 -0
  264. painapple_code/static/js/preview-plugins/markdown-plugin.js +266 -0
  265. painapple_code/static/js/preview-plugins/panzoom-plugin.js +63 -0
  266. painapple_code/static/js/preview-plugins/plugin-helpers.js +282 -0
  267. painapple_code/static/js/project-color-picker.js +110 -0
  268. painapple_code/static/js/project-colors.js +163 -0
  269. painapple_code/static/js/prompt-favorites.js +187 -0
  270. painapple_code/static/js/quick-actions-menu.js +1736 -0
  271. painapple_code/static/js/quick-actions-registry.js +1239 -0
  272. painapple_code/static/js/quick-switcher/controller.js +294 -0
  273. painapple_code/static/js/quick-switcher/fuzzy-scorer.js +123 -0
  274. painapple_code/static/js/quick-switcher/index.js +30 -0
  275. painapple_code/static/js/quick-switcher/providers/base-provider.js +51 -0
  276. painapple_code/static/js/quick-switcher/providers/command-provider.js +56 -0
  277. painapple_code/static/js/quick-switcher/providers/file-provider.js +291 -0
  278. painapple_code/static/js/quick-switcher/providers/panel-provider.js +132 -0
  279. painapple_code/static/js/quick-switcher/providers/project-provider.js +361 -0
  280. painapple_code/static/js/quick-switcher/providers/read-files-provider.js +104 -0
  281. painapple_code/static/js/quick-switcher/providers/skills-provider.js +129 -0
  282. painapple_code/static/js/quick-switcher/registry.js +69 -0
  283. painapple_code/static/js/quick-switcher/ui/item.js +54 -0
  284. painapple_code/static/js/quick-switcher/ui/picker.js +464 -0
  285. painapple_code/static/js/recent-opens.js +40 -0
  286. painapple_code/static/js/scroll-manager.js +530 -0
  287. painapple_code/static/js/scroll-state-machine.js +359 -0
  288. painapple_code/static/js/selection/action-bar.js +793 -0
  289. painapple_code/static/js/selection/index.js +15 -0
  290. painapple_code/static/js/selection/selection-handler.js +877 -0
  291. painapple_code/static/js/selection/state.js +181 -0
  292. painapple_code/static/js/session/agent-progress.js +202 -0
  293. painapple_code/static/js/session/handle-agent-message.js +481 -0
  294. painapple_code/static/js/session/handle-message.js +550 -0
  295. painapple_code/static/js/session/interactive.js +587 -0
  296. painapple_code/static/js/session/message-store.js +271 -0
  297. painapple_code/static/js/session/messages.js +253 -0
  298. painapple_code/static/js/session/persistence.js +179 -0
  299. painapple_code/static/js/session/restore.js +136 -0
  300. painapple_code/static/js/session/sync.js +333 -0
  301. painapple_code/static/js/session-container-pool.js +371 -0
  302. painapple_code/static/js/session-setup-panel.js +274 -0
  303. painapple_code/static/js/session.js +1047 -0
  304. painapple_code/static/js/shortcut-hints.js +272 -0
  305. painapple_code/static/js/shortcuts.js +1146 -0
  306. painapple_code/static/js/skills-autocomplete.js +262 -0
  307. painapple_code/static/js/snippets-autocomplete.js +738 -0
  308. painapple_code/static/js/stash-refs-view.js +83 -0
  309. painapple_code/static/js/stash-ui.js +768 -0
  310. painapple_code/static/js/stash.js +785 -0
  311. painapple_code/static/js/status-bar.js +1184 -0
  312. painapple_code/static/js/token-profile.js +274 -0
  313. painapple_code/static/js/tool-renderer-blocks.js +1626 -0
  314. painapple_code/static/js/tool-renderer-thinking.js +813 -0
  315. painapple_code/static/js/tool-renderer.js +1500 -0
  316. painapple_code/static/js/tooltips.js +197 -0
  317. painapple_code/static/js/upload-manager.js +1019 -0
  318. painapple_code/static/js/utils.js +521 -0
  319. painapple_code/static/js/welcome/api.js +363 -0
  320. painapple_code/static/js/welcome/cards.js +626 -0
  321. painapple_code/static/js/welcome/context-menu.js +585 -0
  322. painapple_code/static/js/welcome/families.js +801 -0
  323. painapple_code/static/js/welcome/preview.js +234 -0
  324. painapple_code/static/js/welcome/state.js +129 -0
  325. painapple_code/static/js/welcome.js +1874 -0
  326. painapple_code/static/js/widget-system/base-widget.js +717 -0
  327. painapple_code/static/js/widget-system/device-manager.js +178 -0
  328. painapple_code/static/js/widget-system/event-bus.js +152 -0
  329. painapple_code/static/js/widget-system/icons.js +120 -0
  330. painapple_code/static/js/widget-system/index.js +49 -0
  331. painapple_code/static/js/widget-system/init.js +54 -0
  332. painapple_code/static/js/widget-system/types/bottom-sheet.js +307 -0
  333. painapple_code/static/js/widget-system/types/floating.js +915 -0
  334. painapple_code/static/js/widget-system/types/index.js +40 -0
  335. painapple_code/static/js/widget-system/types/modal.js +147 -0
  336. painapple_code/static/js/widget-system/types/sidebar.js +158 -0
  337. painapple_code/static/js/widget-system/types/tab.js +146 -0
  338. painapple_code/static/js/widget-system/types/top-sheet.js +203 -0
  339. painapple_code/static/js/widget-system/widget-manager.js +1187 -0
  340. painapple_code/static/js/widgets/about-widget.js +260 -0
  341. painapple_code/static/js/widgets/active-sessions-widget.js +760 -0
  342. painapple_code/static/js/widgets/agents-widget.js +897 -0
  343. painapple_code/static/js/widgets/browser-widget.js +579 -0
  344. painapple_code/static/js/widgets/commands-widget.js +694 -0
  345. painapple_code/static/js/widgets/config/commit-sections.js +449 -0
  346. painapple_code/static/js/widgets/config/dir-autocomplete.js +224 -0
  347. painapple_code/static/js/widgets/config/gestures.js +161 -0
  348. painapple_code/static/js/widgets/config/models-tab.js +988 -0
  349. painapple_code/static/js/widgets/config/quick-actions-tab.js +882 -0
  350. painapple_code/static/js/widgets/config/shortcut-editor.js +587 -0
  351. painapple_code/static/js/widgets/config/state.js +517 -0
  352. painapple_code/static/js/widgets/config/system-controls.js +90 -0
  353. painapple_code/static/js/widgets/config-widget.js +1535 -0
  354. painapple_code/static/js/widgets/cost-analytics-widget.js +621 -0
  355. painapple_code/static/js/widgets/debug-widget.js +693 -0
  356. painapple_code/static/js/widgets/diff-viewer-widget.js +1420 -0
  357. painapple_code/static/js/widgets/discussion-widget.js +1107 -0
  358. painapple_code/static/js/widgets/file-explorer-widget.js +2166 -0
  359. painapple_code/static/js/widgets/file-preview-widget.js +861 -0
  360. painapple_code/static/js/widgets/git-widget.js +794 -0
  361. painapple_code/static/js/widgets/helpers-install-widget.js +720 -0
  362. painapple_code/static/js/widgets/history-explorer-widget.js +1804 -0
  363. painapple_code/static/js/widgets/image-annotate-widget.js +951 -0
  364. painapple_code/static/js/widgets/image-preview-widget.js +692 -0
  365. painapple_code/static/js/widgets/index.js +176 -0
  366. painapple_code/static/js/widgets/log-explorer-widget.js +1057 -0
  367. painapple_code/static/js/widgets/plugins-widget.js +305 -0
  368. painapple_code/static/js/widgets/prompt-explorer-widget.js +1119 -0
  369. painapple_code/static/js/widgets/search-files-widget.js +529 -0
  370. painapple_code/static/js/widgets/skills-widget.js +843 -0
  371. painapple_code/static/js/widgets/snippets-widget.js +479 -0
  372. painapple_code/static/js/widgets/sub-agents-widget.js +333 -0
  373. painapple_code/static/js/widgets/tasks-widget.js +379 -0
  374. painapple_code/static/js/widgets/terminal/connection.js +283 -0
  375. painapple_code/static/js/widgets/terminal/gestures.js +357 -0
  376. painapple_code/static/js/widgets/terminal/init.js +642 -0
  377. painapple_code/static/js/widgets/terminal/link-providers.js +532 -0
  378. painapple_code/static/js/widgets/terminal/osc52.js +213 -0
  379. painapple_code/static/js/widgets/terminal/render.js +159 -0
  380. painapple_code/static/js/widgets/terminal/size.js +54 -0
  381. painapple_code/static/js/widgets/terminal/state.js +211 -0
  382. painapple_code/static/js/widgets/terminal/wrap-utils.js +101 -0
  383. painapple_code/static/js/widgets/terminal-widget.js +793 -0
  384. painapple_code/static/js/widgets/uploads-widget.js +461 -0
  385. painapple_code/static/js/widgets/zen-widget.js +1001 -0
  386. painapple_code/static/login.html +51 -0
  387. painapple_code/static/manifest.json +73 -0
  388. painapple_code/static/sw.js +293 -0
  389. painapple_code/static/vendor/LICENSES.txt +769 -0
  390. painapple_code/static/vendor/README.md +103 -0
  391. painapple_code/static/vendor/codemirror.js +35 -0
  392. painapple_code/static/vendor/codemirror.js.LEGAL.txt +304 -0
  393. painapple_code/static/vendor/github-markdown-dark.min.css +1124 -0
  394. painapple_code/static/vendor/highlight-github-dark.min.css +10 -0
  395. painapple_code/static/vendor/highlight-lang-dockerfile.min.js +8 -0
  396. painapple_code/static/vendor/highlight-lang-nginx.min.js +21 -0
  397. painapple_code/static/vendor/highlight-lang-properties.min.js +10 -0
  398. painapple_code/static/vendor/highlight-lang-scala.min.js +28 -0
  399. painapple_code/static/vendor/highlight.min.js +1213 -0
  400. painapple_code/static/vendor/marked.min.js +6 -0
  401. painapple_code/static/vendor/purify.min.js +3 -0
  402. painapple_code/static/vendor/xterm-addon-fit.js +2 -0
  403. painapple_code/static/vendor/xterm.css +209 -0
  404. painapple_code/static/vendor/xterm.js +2 -0
  405. painapple_code/static/web-client.html +635 -0
  406. painapple_code/subprocess_registry.py +535 -0
  407. painapple_code/tls_cert.py +79 -0
  408. painapple_code/tools/agents/shadow-git-helper.md +400 -0
  409. painapple_code/tools/excalidraw-to-svg.js +143 -0
  410. painapple_code/tools/install-helpers.sh +148 -0
  411. painapple_code/tools/shadow-git +320 -0
  412. painapple_code/tools/shadow-query +120 -0
  413. painapple_code/tools/vegalite-to-svg.js +79 -0
  414. painapple_code/turn_query.py +766 -0
  415. painapple_code/turn_tracker.py +221 -0
  416. painapple_code/utils/__init__.py +0 -0
  417. painapple_code/utils/agent_cli.py +306 -0
  418. painapple_code/utils/chart.py +103 -0
  419. painapple_code/utils/excalidraw.py +107 -0
  420. painapple_code/utils/file_lock.py +162 -0
  421. painapple_code/utils/file_paths.py +648 -0
  422. painapple_code/utils/generate_icons.py +251 -0
  423. painapple_code/utils/proc.py +205 -0
  424. painapple_code/utils/pty_backend.py +59 -0
  425. painapple_code/utils/pty_posix.py +160 -0
  426. painapple_code/utils/pty_windows.py +245 -0
  427. painapple_code/utils/token_profiles.py +91 -0
  428. painapple_code/viewer_templates.py +657 -0
  429. painapple_code/welcome_search.py +879 -0
  430. painapple_code-1.0.0.dist-info/METADATA +292 -0
  431. painapple_code-1.0.0.dist-info/RECORD +436 -0
  432. painapple_code-1.0.0.dist-info/WHEEL +5 -0
  433. painapple_code-1.0.0.dist-info/entry_points.txt +2 -0
  434. painapple_code-1.0.0.dist-info/licenses/LICENSE +661 -0
  435. painapple_code-1.0.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +261 -0
  436. painapple_code-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1535 @@
1
+ /**
2
+ * Config Widget — Settings UI orchestrator.
3
+ *
4
+ * Tabbed Settings panel (Project / Shortcuts / Appearance / Quick Actions
5
+ * / Claude / System). The heavy logic for each section lives under
6
+ * `./config/*`:
7
+ *
8
+ * state.js — config storage helpers + ConfigState singleton
9
+ * shortcut-editor.js — Shortcuts tab capture/edit class
10
+ * quick-actions-tab.js — Quick Actions FAB editor
11
+ * commit-sections.js — Commit Sections editor inside Project tab
12
+ * dir-autocomplete.js — Extra-dirs lists (project + global)
13
+ * system-controls.js — Claude path / effort / API retry / token profile
14
+ * models-tab.js — Models tab CRUD
15
+ * gestures.js — Wheel + touch swipe handlers for tab cycling
16
+ *
17
+ * What stays here: the main `renderConfigPanel` template, the master
18
+ * `attachConfigEventHandlers` wiring, tab navigation (switch/cycle/
19
+ * jump-by-index + Escape/Ctrl+[/]/Ctrl+1-9 keybindings), and the
20
+ * `registerConfigWidget` modal-widget registration. Public exports are
21
+ * re-exported from the state module so external importers
22
+ * (`app.js`, `welcome.js`, `chat-controller.js`, `thinking-controller.js`,
23
+ * `preview/preview-events.js`, `tool-renderer.js`, `discussion-widget.js`,
24
+ * `log-explorer-widget.js`) need no changes.
25
+ */
26
+
27
+ import S from '../strings.js';
28
+ import { escapeHtml } from '../utils.js';
29
+ import { SHORTCUTS } from '../shortcuts.js';
30
+ import { ShortcutHints, HINT_CANDIDATE_IDS, DEFAULT_HINT_IDS, getHintsConfig, setHintsEnabled, setHintIds } from '../shortcut-hints.js';
31
+ import { debug, CONFIG } from '../config.js';
32
+ import { WidgetManager } from '../widget-system/index.js';
33
+ import { MarkdownRenderer } from '../components.js';
34
+ import { showToast } from '../context-menu.js';
35
+
36
+ import { FilePreviewWidget } from './file-preview-widget.js';
37
+ import { TerminalWidget } from './terminal-widget.js';
38
+
39
+ import {
40
+ state,
41
+ subModel,
42
+ LAYOUT_MODES,
43
+ DEFAULT_COLLAPSE_MODES,
44
+ applyLayout,
45
+ applyFloatingButtonsOpacity,
46
+ } from './config/state.js';
47
+ import { ShortcutEditor } from './config/shortcut-editor.js';
48
+ import { renderQuickActionsTab, setupQuickActionsEvents } from './config/quick-actions-tab.js';
49
+ import {
50
+ renderCommitSectionsEditor,
51
+ setupCommitSectionsHandlers,
52
+ setupCommitSectionItemHandlers,
53
+ updateSectionsCount,
54
+ } from './config/commit-sections.js';
55
+ import {
56
+ renderExtraDirsListHTML,
57
+ setupExtraDirAddHandler,
58
+ updateExtraDirsInPlace,
59
+ } from './config/dir-autocomplete.js';
60
+ import {
61
+ setupApiRetryControls,
62
+ setupSigintOnAskControls,
63
+ } from './config/system-controls.js';
64
+ import { setupModelsTab } from './config/models-tab.js';
65
+ import { setupConfigGestures, cleanupConfigGestures } from './config/gestures.js';
66
+
67
+ // Re-exports preserve the public API at './widgets/config-widget.js' so
68
+ // every external importer keeps working without changes.
69
+ export {
70
+ LAYOUT_MODES,
71
+ loadUserConfig,
72
+ saveUserConfig,
73
+ applyLayout,
74
+ applyFloatingButtonsOpacity,
75
+ isThinkingKeywordsHighlightingEnabled,
76
+ isSelectionInPreviewEnabled,
77
+ isAnnotateOnPasteEnabled,
78
+ getToolCategory,
79
+ getToolCollapseMode,
80
+ applyAutocorrectSetting,
81
+ } from './config/state.js';
82
+
83
+ // ═══════════════════════════════════════════════════════════════════════════
84
+ // Helper Functions
85
+ // ═══════════════════════════════════════════════════════════════════════════
86
+
87
+ /**
88
+ * Get human-readable description of current preview size
89
+ */
90
+ function getPreviewSizeDescription() {
91
+ const settings = FilePreviewWidget.getSizeSettings();
92
+ if (settings.isCustom) {
93
+ return `Custom: ${settings.width}×${settings.height}px (default: ${settings.defaultWidth}×${settings.defaultHeight})`;
94
+ }
95
+ return `Default: ${settings.defaultWidth}×${settings.defaultHeight}px`;
96
+ }
97
+
98
+ /**
99
+ * Update the preview size description in the UI
100
+ */
101
+ function updatePreviewSizeUI(container) {
102
+ const desc = container.querySelector('#preview-size-desc');
103
+ const btn = container.querySelector('#reset-preview-size');
104
+ if (desc) {
105
+ desc.textContent = getPreviewSizeDescription();
106
+ }
107
+ if (btn) {
108
+ btn.disabled = !FilePreviewWidget.getSizeSettings().isCustom;
109
+ }
110
+ }
111
+
112
+ // ═══════════════════════════════════════════════════════════════════════════
113
+ // Collapse Mode Grid
114
+ // ═══════════════════════════════════════════════════════════════════════════
115
+
116
+ function _permissionOptions() {
117
+ return S.permissions.order.map(key => {
118
+ const lvl = S.permissions.levels[key];
119
+ return `<option value="${key}">${lvl.popup_label}</option>`;
120
+ }).join('\n');
121
+ }
122
+
123
+ function _collapseModeSelect(context, toolType, currentModes) {
124
+ const modes = currentModes || DEFAULT_COLLAPSE_MODES;
125
+ const val = modes[context]?.[toolType] || DEFAULT_COLLAPSE_MODES[context][toolType];
126
+ return `<select class="system-select collapse-mode-select" data-context="${context}" data-type="${toolType}">
127
+ <option value="expanded" ${val === 'expanded' ? 'selected' : ''}>${S.settings.collapse_modes.expanded}</option>
128
+ <option value="compact" ${val === 'compact' ? 'selected' : ''}>${S.settings.collapse_modes.compact}</option>
129
+ <option value="collapsed" ${val === 'collapsed' ? 'selected' : ''}>${S.settings.collapse_modes.collapsed}</option>
130
+ </select>`;
131
+ }
132
+
133
+ function renderCollapseGrid(config) {
134
+ const modes = config.toolCollapseModes || DEFAULT_COLLAPSE_MODES;
135
+ const contexts = Object.entries(S.settings.thinking_modes).map(([key, label]) => ({ key, label }));
136
+ const types = ['read', 'write', 'execute'];
137
+
138
+ const rows = contexts.map(ctx =>
139
+ `<span class="collapse-grid-label">${ctx.label}</span>` +
140
+ types.map(t => _collapseModeSelect(ctx.key, t, modes)).join('')
141
+ ).join('');
142
+
143
+ return `<div class="collapse-mode-grid">
144
+ <span></span><span class="collapse-grid-header">Read</span><span class="collapse-grid-header">Write</span><span class="collapse-grid-header">Execute</span>
145
+ ${rows}
146
+ </div>`;
147
+ }
148
+
149
+ // ═══════════════════════════════════════════════════════════════════════════
150
+ // Render Functions
151
+ // ═══════════════════════════════════════════════════════════════════════════
152
+
153
+ function renderConfigPanel(container, context) {
154
+ debug.log('[Config] renderConfigPanel called, projectConfig:', state.projectConfig?.shadow_git);
155
+ state.container = container;
156
+
157
+ // Handle tab requested via WidgetManager.open context (avoids dynamic import module mismatch)
158
+ if (context?.tab) {
159
+ state.activeTab = context.tab;
160
+ state._tabSelected = true;
161
+ }
162
+
163
+ // The 'snippets' and 'agents' tabs have moved into standalone widgets.
164
+ // Honour legacy tab requests by routing them to the widget instead.
165
+ if (state.activeTab === 'favorites' || state.activeTab === 'snippets') {
166
+ state.activeTab = 'shortcuts';
167
+ setTimeout(() => {
168
+ WidgetManager.close('config');
169
+ WidgetManager.open('snippets');
170
+ }, 0);
171
+ } else if (state.activeTab === 'agents') {
172
+ state.activeTab = 'shortcuts';
173
+ setTimeout(() => {
174
+ WidgetManager.close('config');
175
+ WidgetManager.open('agents');
176
+ }, 0);
177
+ }
178
+
179
+ // Check if we have an active project
180
+ const hasProject = state.hasActiveProject();
181
+ debug.log('[Config] hasProject:', hasProject, 'cwd:', window.app?.activeSession?.cwd);
182
+ const projectName = hasProject ? (state.projectInfo?.name || 'Project') : '';
183
+
184
+ // Default to project tab if available and no explicit tab selected
185
+ if (hasProject && state.activeTab === 'shortcuts' && !state._tabSelected) {
186
+ state.activeTab = 'project';
187
+ }
188
+ state._tabSelected = true;
189
+
190
+ container.innerHTML = `
191
+ <div class="config-tabs">
192
+ ${hasProject ? `
193
+ <button class="config-tab ${state.activeTab === 'project' ? 'active' : ''}" data-tab="project">
194
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
195
+ <path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/>
196
+ </svg>
197
+ ${escapeHtml(projectName)}
198
+ </button>
199
+ ` : ''}
200
+ <button class="config-tab ${state.activeTab === 'shortcuts' ? 'active' : ''}" data-tab="shortcuts">
201
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
202
+ <rect x="2" y="4" width="20" height="16" rx="2"/>
203
+ <path d="M6 8h4M14 8h4M6 12h2M10 12h4M16 12h2M6 16h12"/>
204
+ </svg>
205
+ Shortcuts
206
+ </button>
207
+ <button class="config-tab ${state.activeTab === 'appearance' ? 'active' : ''}" data-tab="appearance">
208
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
209
+ <circle cx="12" cy="12" r="3"/>
210
+ <path d="M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"/>
211
+ </svg>
212
+ Appearance
213
+ </button>
214
+ <button class="config-tab ${state.activeTab === 'terminal' ? 'active' : ''}" data-tab="terminal">
215
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
216
+ <polyline points="4 17 10 11 4 5"/>
217
+ <line x1="12" y1="19" x2="20" y2="19"/>
218
+ </svg>
219
+ ${S.settings.tabs.terminal}
220
+ </button>
221
+ <button class="config-tab ${state.activeTab === 'quickactions' ? 'active' : ''}" data-tab="quickactions">
222
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
223
+ <polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/>
224
+ </svg>
225
+ Quick Actions
226
+ </button>
227
+ <button class="config-tab ${state.activeTab === 'models' ? 'active' : ''}" data-tab="models">
228
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
229
+ <path d="M12 2L2 7l10 5 10-5-10-5z"/>
230
+ <path d="M2 17l10 5 10-5"/>
231
+ <path d="M2 12l10 5 10-5"/>
232
+ </svg>
233
+ ${S.settings.sections.engines}
234
+ </button>
235
+ <button class="config-tab ${state.activeTab === 'system' ? 'active' : ''}" data-tab="system">
236
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
237
+ <circle cx="12" cy="12" r="3"/>
238
+ <path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>
239
+ </svg>
240
+ System
241
+ </button>
242
+ </div>
243
+
244
+ <div class="config-body">
245
+ ${hasProject ? `
246
+ <!-- Project tab -->
247
+ <div class="config-section" data-section="project" ${state.activeTab !== 'project' ? 'hidden' : ''}>
248
+ <div class="project-settings">
249
+ <div class="project-info">
250
+ <div class="project-info-path">
251
+ <span class="project-info-label">Path</span>
252
+ <span class="project-info-value">${escapeHtml(state.projectInfo?.path || state.getProjectCwd() || '')}</span>
253
+ </div>
254
+ <div class="project-info-hash">
255
+ <span class="project-info-label">Hash</span>
256
+ <span class="project-info-value">${escapeHtml(state.projectInfo?.hash || '')}</span>
257
+ </div>
258
+ </div>
259
+
260
+ <div class="project-section">
261
+ <h3 class="project-section-title">${S.settings.sections.extra_dirs_project}</h3>
262
+ <p class="config-hint">${S.settings.hints.extra_dirs_project_desc}</p>
263
+
264
+ <div class="extra-dirs-list" id="extra-dirs-list">
265
+ ${renderExtraDirsListHTML(state.projectConfig?.extra_dirs || [], 'extra-dir-remove')}
266
+ </div>
267
+
268
+ <div class="extra-dir-add-row">
269
+ <input type="text" id="extra-dir-input" class="extra-dir-input"
270
+ placeholder="/path/to/directory" spellcheck="false" autocomplete="off">
271
+ <button class="extra-dir-add-btn" id="extra-dir-add-btn">Add</button>
272
+ </div>
273
+ </div>
274
+
275
+ <div class="project-section">
276
+ <h3 class="project-section-title">${S.settings.sections.shadow_git}</h3>
277
+ <p class="config-hint">${S.settings.hints.shadow_git_desc}</p>
278
+
279
+ <label class="project-toggle">
280
+ <input type="checkbox" id="shadow-git-enabled"
281
+ ${state.projectConfig?.shadow_git?.enabled !== false ? 'checked' : ''}>
282
+ <span class="project-toggle-label">${S.settings.toggles.enable_shadow_git}</span>
283
+ </label>
284
+
285
+ <label class="project-toggle">
286
+ <input type="checkbox" id="shadow-git-rich-commits"
287
+ ${state.projectConfig?.shadow_git?.rich_commits !== false ? 'checked' : ''}>
288
+ <span class="project-toggle-label">${subModel(S.settings.toggles.rich_commits)}</span>
289
+ <span class="project-toggle-hint">${S.settings.toggles.rich_commits_hint}</span>
290
+ </label>
291
+
292
+ <div class="commit-sections-container ${state.projectConfig?.shadow_git?.rich_commits !== false ? '' : 'disabled'}">
293
+ <button class="commit-sections-toggle" id="toggle-commit-sections">
294
+ <svg class="chevron-icon ${state.commitSectionsExpanded ? 'expanded' : ''}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
295
+ <path d="M9 18l6-6-6-6"/>
296
+ </svg>
297
+ <span>${S.settings.section_editor.configure}</span>
298
+ <span class="sections-count">${state.commitSections?.sections?.filter(s => s.enabled).length || 0} enabled</span>
299
+ </button>
300
+ <div class="commit-sections-editor ${state.commitSectionsExpanded ? 'expanded' : ''}" id="commit-sections-editor">
301
+ ${renderCommitSectionsEditor(state)}
302
+ </div>
303
+ </div>
304
+ </div>
305
+ </div>
306
+ </div>
307
+ ` : ''}
308
+
309
+ <!-- Shortcuts tab -->
310
+ <div class="config-section" data-section="shortcuts" ${state.activeTab !== 'shortcuts' ? 'hidden' : ''}>
311
+ <div class="shortcuts-header">
312
+ <p class="shortcuts-hint">${S.settings.shortcuts_tab.hint}</p>
313
+ <button class="shortcuts-reset-all" data-tooltip="Reset all to defaults">
314
+ ${S.settings.shortcuts_tab.reset_all}
315
+ </button>
316
+ </div>
317
+ <div class="shortcuts-list"></div>
318
+ </div>
319
+
320
+ <!-- Appearance tab -->
321
+ <div class="config-section" data-section="appearance" ${state.activeTab !== 'appearance' ? 'hidden' : ''}>
322
+ <div class="appearance-section">
323
+ <h3 class="appearance-section-title">${S.settings.sections.layout_density}</h3>
324
+ <div class="layout-options">
325
+ <label class="layout-option">
326
+ <input type="radio" name="layout" value="compact" ${state.config.layout === 'compact' ? 'checked' : ''}>
327
+ <span class="layout-option-content">
328
+ <span class="layout-option-label">Compact</span>
329
+ <span class="layout-option-desc">Minimal spacing, more content visible</span>
330
+ </span>
331
+ </label>
332
+ <label class="layout-option">
333
+ <input type="radio" name="layout" value="normal" ${state.config.layout === 'normal' || !state.config.layout ? 'checked' : ''}>
334
+ <span class="layout-option-content">
335
+ <span class="layout-option-label">Normal</span>
336
+ <span class="layout-option-desc">Balanced spacing (default)</span>
337
+ </span>
338
+ </label>
339
+ <label class="layout-option">
340
+ <input type="radio" name="layout" value="spacious" ${state.config.layout === 'spacious' ? 'checked' : ''}>
341
+ <span class="layout-option-content">
342
+ <span class="layout-option-label">Spacious</span>
343
+ <span class="layout-option-desc">More breathing room, larger elements</span>
344
+ </span>
345
+ </label>
346
+ </div>
347
+ </div>
348
+ <div class="appearance-section">
349
+ <h3 class="appearance-section-title">${S.settings.sections.font_size}</h3>
350
+ <p class="config-hint">${S.settings.hints.font_desc}</p>
351
+ <div class="font-scale-control">
352
+ <button class="font-scale-btn" id="font-decrease" data-tooltip="Decrease (70% min)">
353
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
354
+ <path d="M5 12h14"/>
355
+ </svg>
356
+ </button>
357
+ <span class="font-scale-label" id="font-size-label">${Math.round((window.app?.fontScale || 1) * 100)}%</span>
358
+ <button class="font-scale-btn" id="font-increase" data-tooltip="Increase (150% max)">
359
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
360
+ <path d="M12 5v14M5 12h14"/>
361
+ </svg>
362
+ </button>
363
+ </div>
364
+ </div>
365
+ <div class="appearance-section">
366
+ <h3 class="appearance-section-title">${S.settings.sections.floating_buttons}</h3>
367
+ <p class="config-hint">${S.settings.hints.floating_desc}</p>
368
+ <div class="opacity-slider-control">
369
+ <input type="range" id="floating-opacity-slider" min="10" max="100" step="5"
370
+ value="${Math.round((state.config.floatingButtonsOpacity ?? 0.7) * 100)}"
371
+ class="opacity-slider">
372
+ <span class="opacity-slider-label" id="floating-opacity-label">${Math.round((state.config.floatingButtonsOpacity ?? 0.7) * 100)}%</span>
373
+ </div>
374
+ </div>
375
+ <div class="appearance-section">
376
+ <h3 class="appearance-section-title">${S.settings.sections.tool_blocks}</h3>
377
+ <div class="system-setting">
378
+ <label class="project-toggle">
379
+ <input type="checkbox" id="code-block-wrap"
380
+ ${MarkdownRenderer.getCodeWrapPref() ? 'checked' : ''}>
381
+ <span class="project-toggle-label">${S.settings.toggles.code_block_wrap}</span>
382
+ <span class="project-toggle-hint">${S.settings.toggles.code_block_wrap_hint}</span>
383
+ </label>
384
+ </div>
385
+ <p class="config-hint">${S.settings.hints.tool_blocks_desc}</p>
386
+ ${renderCollapseGrid(state.config)}
387
+ </div>
388
+ <div class="appearance-section">
389
+ <h3 class="appearance-section-title">${S.settings.sections.widgets}</h3>
390
+ <div class="system-setting">
391
+ <label class="project-toggle">
392
+ <input type="checkbox" id="selection-in-preview"
393
+ ${state.config.selectionInPreview ? 'checked' : ''}>
394
+ <span class="project-toggle-label">${S.settings.toggles.selection_in_preview}</span>
395
+ <span class="project-toggle-hint">${S.settings.toggles.selection_in_preview_hint}</span>
396
+ </label>
397
+ </div>
398
+ <p class="config-hint">${S.settings.hints.widget_sizes_desc}</p>
399
+ <div class="system-setting">
400
+ <label class="system-setting-label">
401
+ <span class="system-setting-name">File Preview</span>
402
+ <span class="system-setting-desc" id="preview-size-desc">
403
+ ${getPreviewSizeDescription()}
404
+ </span>
405
+ </label>
406
+ <div class="system-setting-control">
407
+ <button class="system-reset-btn" id="reset-preview-size"
408
+ ${!FilePreviewWidget.getSizeSettings().isCustom ? 'disabled' : ''}>
409
+ Reset
410
+ </button>
411
+ </div>
412
+ </div>
413
+ </div>
414
+ <div class="appearance-section">
415
+ <h3 class="appearance-section-title">${S.settings.sections.input}</h3>
416
+ <div class="system-setting">
417
+ <label class="project-toggle">
418
+ <input type="checkbox" id="disable-autocorrect"
419
+ ${state.config.disableAutocorrect ? 'checked' : ''}>
420
+ <span class="project-toggle-label">${S.settings.system.autocorrect.label}</span>
421
+ <span class="project-toggle-hint">${S.settings.system.autocorrect.desc}</span>
422
+ </label>
423
+ </div>
424
+ <div class="system-setting">
425
+ <label class="project-toggle">
426
+ <input type="checkbox" id="highlight-thinking-keywords"
427
+ ${state.config.highlightThinkingKeywords ? 'checked' : ''}>
428
+ <span class="project-toggle-label">${S.settings.toggles.highlight_thinking}</span>
429
+ <span class="project-toggle-hint">${S.settings.toggles.highlight_thinking_hint}</span>
430
+ </label>
431
+ </div>
432
+ <div class="system-setting">
433
+ <label class="project-toggle">
434
+ <input type="checkbox" id="annotate-on-paste"
435
+ ${state.config.annotateOnPaste ? 'checked' : ''}>
436
+ <span class="project-toggle-label">${S.settings.toggles.annotate_on_paste}</span>
437
+ <span class="project-toggle-hint">${S.settings.toggles.annotate_on_paste_hint}</span>
438
+ </label>
439
+ </div>
440
+ <div class="system-setting">
441
+ <label class="project-toggle">
442
+ <input type="checkbox" id="shortcut-hints-enabled"
443
+ ${getHintsConfig().enabled ? 'checked' : ''}>
444
+ <span class="project-toggle-label">${S.settings.toggles.shortcut_hints}</span>
445
+ <span class="project-toggle-hint">${S.settings.toggles.shortcut_hints_hint}</span>
446
+ </label>
447
+ </div>
448
+ <div class="shortcut-hints-picker" id="shortcut-hints-picker">
449
+ <div class="shortcut-hints-picker-header">
450
+ <span>${S.shortcut_hints.customize}</span>
451
+ <button class="system-reset-btn" id="shortcut-hints-reset" type="button">
452
+ ${S.shortcut_hints.reset}
453
+ </button>
454
+ </div>
455
+ <div class="shortcut-hints-picker-list">
456
+ ${renderShortcutHintsPicker()}
457
+ </div>
458
+ </div>
459
+ </div>
460
+ </div>
461
+
462
+ <!-- Terminal tab — settings for the embedded PTY terminal. The
463
+ control IDs (#terminal-clipboard-write, #terminal-size-w/h,
464
+ #reset-terminal-size) are queried on the whole container in
465
+ attachConfigEventHandlers, so the wiring is location-agnostic. -->
466
+ <div class="config-section" data-section="terminal" ${state.activeTab !== 'terminal' ? 'hidden' : ''}>
467
+ <div class="appearance-section">
468
+ <h3 class="appearance-section-title">${S.settings.sections.terminal_clipboard}</h3>
469
+ <div class="system-setting">
470
+ <label class="project-toggle">
471
+ <input type="checkbox" id="terminal-clipboard-write"
472
+ ${state.config.terminalClipboardWrite === true ? 'checked' : ''}>
473
+ <span class="project-toggle-label">${S.settings.toggles.terminal_clipboard}</span>
474
+ <span class="project-toggle-hint">${S.settings.toggles.terminal_clipboard_hint}</span>
475
+ </label>
476
+ </div>
477
+ </div>
478
+ <div class="appearance-section">
479
+ <h3 class="appearance-section-title">${S.settings.sections.terminal_floating}</h3>
480
+ <p class="config-hint">${S.settings.hints.terminal_size_desc}</p>
481
+ <div class="system-setting">
482
+ <div class="system-setting-control widget-size-inputs">
483
+ <input type="number" id="terminal-size-w" class="size-input" min="400" max="2000" step="50"
484
+ value="${TerminalWidget.getConfiguredSize().width}">
485
+ <span class="size-separator">&times;</span>
486
+ <input type="number" id="terminal-size-h" class="size-input" min="200" max="1200" step="50"
487
+ value="${TerminalWidget.getConfiguredSize().height}">
488
+ <button class="system-reset-btn" id="reset-terminal-size">Reset</button>
489
+ </div>
490
+ </div>
491
+ </div>
492
+ </div>
493
+
494
+ <!-- Quick Actions tab -->
495
+ <div class="config-section" data-section="quickactions" ${state.activeTab !== 'quickactions' ? 'hidden' : ''}>
496
+ ${renderQuickActionsTab()}
497
+ </div>
498
+
499
+ <!-- Engines tab (internally data-tab="models") — everything
500
+ provider-centric renders dynamically from the registry via
501
+ setupModelsTab; nothing here is hardcoded per engine. -->
502
+ <div class="config-section" data-section="models" ${state.activeTab !== 'models' ? 'hidden' : ''}>
503
+ <div class="system-section">
504
+ <h3 class="system-section-title">${S.settings.sections.engines}</h3>
505
+ <div class="engines-list" id="engines-list">
506
+ <!-- populated by setupModelsTab -->
507
+ </div>
508
+ <p class="config-hint" id="engines-hint">${S.settings.hints.engines_hint}</p>
509
+ </div>
510
+ <div class="system-section">
511
+ <h3 class="system-section-title">${S.settings.sections.engine_settings}</h3>
512
+ <div class="engine-subtabs" id="engine-subtabs">
513
+ <!-- one sub-tab per enabled engine, populated by setupModelsTab -->
514
+ </div>
515
+ <div class="engine-panel" id="engine-panel">
516
+ <!-- the selected engine's CLI path, login, catalog, defaults, journal -->
517
+ </div>
518
+ <p class="config-hint">${S.settings.hints.models_summary_hint}</p>
519
+ <button type="button" class="config-action-btn" id="open-auto-journal-from-models">${S.settings.hints.models_summary_link}</button>
520
+ </div>
521
+ </div>
522
+
523
+ <!-- System tab -->
524
+ <div class="config-section" data-section="system" ${state.activeTab !== 'system' ? 'hidden' : ''}>
525
+ <div class="system-section" id="account-section">
526
+ <h3 class="system-section-title">${S.settings.sections.account}</h3>
527
+ <div class="system-setting">
528
+ <label class="system-setting-label">
529
+ <span class="system-setting-name">${S.settings.account.logout_name}</span>
530
+ <span class="system-setting-desc">${S.settings.account.logout_desc}</span>
531
+ </label>
532
+ <div class="system-setting-control">
533
+ <button class="system-btn" id="account-logout">${S.settings.account.logout_btn}</button>
534
+ </div>
535
+ </div>
536
+ <div class="system-setting">
537
+ <label class="system-setting-label">
538
+ <span class="system-setting-name">${S.settings.account.revoke_browsers_name}</span>
539
+ <span class="system-setting-desc">${S.settings.account.revoke_browsers_desc}</span>
540
+ </label>
541
+ <div class="system-setting-control">
542
+ <button class="system-btn danger" id="account-revoke-browsers"
543
+ data-confirm="${S.settings.account.revoke_browsers_confirm}">${S.settings.account.revoke_browsers_btn}</button>
544
+ </div>
545
+ </div>
546
+ <div class="system-setting">
547
+ <label class="system-setting-label">
548
+ <span class="system-setting-name">${S.settings.account.revoke_scripts_name}</span>
549
+ <span class="system-setting-desc">${S.settings.account.revoke_scripts_desc}</span>
550
+ </label>
551
+ <div class="system-setting-control">
552
+ <button class="system-btn danger" id="account-revoke-scripts"
553
+ data-confirm="${S.settings.account.revoke_scripts_confirm}">${S.settings.account.revoke_scripts_btn}</button>
554
+ </div>
555
+ </div>
556
+ <p class="config-hint">${S.settings.account.hint}</p>
557
+ </div>
558
+ <div class="system-section">
559
+ <h3 class="system-section-title">${S.settings.sections.sessions}</h3>
560
+ <div class="system-setting">
561
+ <label class="system-setting-label">
562
+ <span class="system-setting-name">${S.settings.system_labels.session_list_limit}</span>
563
+ <span class="system-setting-desc">${S.settings.system_labels.session_list_limit_desc}</span>
564
+ </label>
565
+ <div class="system-setting-control">
566
+ <input type="number" id="session-list-limit-input" min="10" max="500" step="10"
567
+ value="${state.config.sessionListLimit || CONFIG.DEFAULT_SESSION_LIST_LIMIT}"
568
+ class="system-number-input">
569
+ </div>
570
+ </div>
571
+ <div class="system-setting">
572
+ <label class="system-setting-label">
573
+ <span class="system-setting-name">${S.settings.system_labels.api_retry_max}</span>
574
+ <span class="system-setting-desc">${S.settings.system_labels.api_retry_max_desc}</span>
575
+ </label>
576
+ <div class="system-setting-control">
577
+ <input type="number" id="api-retry-max-input" min="0" max="10"
578
+ value="3"
579
+ class="system-number-input">
580
+ </div>
581
+ </div>
582
+ <div class="system-setting">
583
+ <label class="project-toggle">
584
+ <input type="checkbox" id="sigint-on-ask">
585
+ <span class="project-toggle-label">${S.settings.system_labels.sigint_on_ask}</span>
586
+ <span class="project-toggle-hint">${S.settings.system_labels.sigint_on_ask_desc}</span>
587
+ </label>
588
+ </div>
589
+ </div>
590
+ <div class="system-section">
591
+ <h3 class="system-section-title">${S.settings.sections.permissions}</h3>
592
+ <div class="system-setting">
593
+ <label class="system-setting-label">
594
+ <span class="system-setting-name">${S.settings.permissions.default_label}</span>
595
+ <span class="system-setting-desc">${S.settings.system_labels.perm_normal_desc}</span>
596
+ </label>
597
+ <div class="system-setting-control">
598
+ <select id="default-permission-level" class="system-select">
599
+ ${_permissionOptions()}
600
+ </select>
601
+ </div>
602
+ </div>
603
+ <p class="config-hint">${S.settings.hints.perm_hint}</p>
604
+ </div>
605
+ <div class="system-section">
606
+ <h3 class="system-section-title">${S.settings.sections.file_downloads}</h3>
607
+ <div class="system-setting">
608
+ <div class="system-setting-label">
609
+ <span class="system-setting-name">${S.settings.system_labels.download_behavior}</span>
610
+ <span class="system-setting-desc">${S.settings.system_labels.download_behavior_desc}</span>
611
+ </div>
612
+ <div class="system-radio-group" id="download-mode-group">
613
+ <label class="system-radio-label">
614
+ <input type="radio" name="downloadMode" value="auto"
615
+ ${(state.config.downloadMode || 'auto') === 'auto' ? 'checked' : ''}>
616
+ <span>${S.settings.download_mode.auto}</span>
617
+ <span class="system-radio-hint">${S.settings.download_mode.auto_desc}</span>
618
+ </label>
619
+ <label class="system-radio-label">
620
+ <input type="radio" name="downloadMode" value="download"
621
+ ${state.config.downloadMode === 'download' ? 'checked' : ''}>
622
+ <span>${S.settings.download_mode.download}</span>
623
+ <span class="system-radio-hint">${S.settings.download_mode.download_desc}</span>
624
+ </label>
625
+ <label class="system-radio-label">
626
+ <input type="radio" name="downloadMode" value="copy"
627
+ ${state.config.downloadMode === 'copy' ? 'checked' : ''}>
628
+ <span>${S.settings.download_mode.copy}</span>
629
+ <span class="system-radio-hint">${S.settings.download_mode.copy_desc}</span>
630
+ </label>
631
+ </div>
632
+ </div>
633
+ </div>
634
+ <div class="system-section">
635
+ <h3 class="system-section-title">${S.settings.sections.extra_dirs_global}</h3>
636
+ <p class="config-hint">${S.settings.hints.extra_dirs_global_desc}</p>
637
+
638
+ <div class="extra-dirs-list" id="global-extra-dirs-list">
639
+ ${renderExtraDirsListHTML(state.globalExtraDirs || [], 'global-extra-dir-remove')}
640
+ </div>
641
+
642
+ <div class="extra-dir-add-row">
643
+ <input type="text" id="global-extra-dir-input" class="extra-dir-input"
644
+ placeholder="/path/to/directory" spellcheck="false" autocomplete="off">
645
+ <button class="extra-dir-add-btn" id="global-extra-dir-add-btn">Add</button>
646
+ </div>
647
+ </div>
648
+ <div class="system-section" id="shadow-git-defaults-section">
649
+ <h3 class="system-section-title">${S.settings.sections.shadow_git_defaults}</h3>
650
+ <p class="config-hint">${S.settings.hints.shadow_defaults_hint}</p>
651
+ <div class="system-setting">
652
+ <label class="project-toggle">
653
+ <!-- !== false, matching every other read of these
654
+ flags: auto-journal is ON by default and is a
655
+ core feature, so an unknown state reads as on.
656
+ (The server always sends explicit booleans, so
657
+ this only differs while loading or after a
658
+ failed fetch.) Resynced in onOpen. -->
659
+ <input type="checkbox" id="shadow-git-default-enabled"
660
+ ${state.shadowGitDefaults?.enabled !== false ? 'checked' : ''}>
661
+ <span class="project-toggle-label">${S.settings.toggles.shadow_git_default}</span>
662
+ </label>
663
+ </div>
664
+ <div class="system-setting">
665
+ <label class="project-toggle">
666
+ <input type="checkbox" id="shadow-git-default-rich-commits"
667
+ ${state.shadowGitDefaults?.rich_commits !== false ? 'checked' : ''}>
668
+ <span class="project-toggle-label">${S.settings.toggles.rich_commits_default}</span>
669
+ <span class="project-toggle-hint">${subModel(S.settings.toggles.rich_commits_default_hint)}</span>
670
+ </label>
671
+ </div>
672
+ </div>
673
+ </div>
674
+ </div>
675
+ `;
676
+
677
+ attachConfigEventHandlers(container);
678
+ renderShortcutsTab(container);
679
+ }
680
+
681
+ function renderShortcutsTab(container) {
682
+ const shortcutsList = container.querySelector('.shortcuts-list');
683
+ if (shortcutsList && state.shortcutEditor) {
684
+ state.shortcutEditor.render(shortcutsList);
685
+ }
686
+ }
687
+
688
+ /**
689
+ * Render checkbox list for each candidate hint shortcut.
690
+ * Uses the user's current selection from localStorage.
691
+ */
692
+ function renderShortcutHintsPicker() {
693
+ const { ids } = getHintsConfig();
694
+ const selected = new Set(ids);
695
+ return HINT_CANDIDATE_IDS.map(id => {
696
+ const sc = SHORTCUTS.find(s => s.id === id);
697
+ if (!sc) return '';
698
+ const keyLabel = (sc.keys && sc.keys[0]) || '';
699
+ const isChecked = selected.has(id);
700
+ return `
701
+ <label class="shortcut-hints-picker-item">
702
+ <input type="checkbox" data-hint-id="${id}" ${isChecked ? 'checked' : ''}>
703
+ <span class="shortcut-hints-picker-key">${escapeHtml(keyLabel)}</span>
704
+ <span class="shortcut-hints-picker-label">${escapeHtml(sc.label || id)}</span>
705
+ </label>
706
+ `;
707
+ }).join('');
708
+ }
709
+
710
+
711
+ function attachConfigEventHandlers(container) {
712
+ debug.log('[Config] attachConfigEventHandlers called, container:', container);
713
+ debug.log('[Config] All checkboxes in container:', container.querySelectorAll('input[type="checkbox"]'));
714
+ // Tab switching
715
+ container.querySelectorAll('.config-tab').forEach(tab => {
716
+ tab.addEventListener('click', () => {
717
+ const tabName = tab.dataset.tab;
718
+ switchTab(container, tabName);
719
+ });
720
+ });
721
+
722
+ // Reset all shortcuts — two-click inline confirm (iPad PWA can't
723
+ // be trusted with window.confirm: in standalone mode it sometimes
724
+ // silently no-ops, leaving the button feeling broken).
725
+ const resetAllBtn = container.querySelector('.shortcuts-reset-all');
726
+ if (resetAllBtn) {
727
+ const defaultLabel = S.settings.shortcuts_tab.reset_all;
728
+ const confirmLabel = S.settings.shortcuts_tab.reset_all_confirm;
729
+ let armed = false;
730
+ let armTimer = null;
731
+ const disarm = () => {
732
+ armed = false;
733
+ resetAllBtn.classList.remove('armed');
734
+ resetAllBtn.textContent = defaultLabel;
735
+ if (armTimer) { clearTimeout(armTimer); armTimer = null; }
736
+ };
737
+ resetAllBtn.addEventListener('click', () => {
738
+ if (!armed) {
739
+ armed = true;
740
+ resetAllBtn.classList.add('armed');
741
+ resetAllBtn.textContent = confirmLabel;
742
+ armTimer = setTimeout(disarm, 4000);
743
+ return;
744
+ }
745
+ disarm();
746
+ const shortcutsList = container.querySelector('.shortcuts-list');
747
+ state.shortcutEditor?.resetAll(shortcutsList);
748
+ showToast(S.toast.shortcuts_reset);
749
+ });
750
+ resetAllBtn.addEventListener('blur', disarm);
751
+ }
752
+
753
+ // ── Account & credentials ───────────────────────────────────────────
754
+ // Same two-click confirm as above, for the same reason (window.confirm
755
+ // silently no-ops in the iPad PWA). Factored because there are two
756
+ // destructive buttons here; the label swap lives in data-confirm so the
757
+ // strings stay in strings.yaml.
758
+ const armConfirm = (btn, commit) => {
759
+ if (!btn) return;
760
+ const defaultLabel = btn.textContent;
761
+ const confirmLabel = btn.dataset.confirm || defaultLabel;
762
+ let armed = false;
763
+ let timer = null;
764
+ const disarm = () => {
765
+ armed = false;
766
+ btn.classList.remove('armed');
767
+ btn.textContent = defaultLabel;
768
+ if (timer) { clearTimeout(timer); timer = null; }
769
+ };
770
+ btn.addEventListener('click', async () => {
771
+ if (!armed) {
772
+ armed = true;
773
+ btn.classList.add('armed');
774
+ btn.textContent = confirmLabel;
775
+ timer = setTimeout(disarm, 4000);
776
+ return;
777
+ }
778
+ disarm();
779
+ btn.disabled = true;
780
+ try {
781
+ await commit();
782
+ } finally {
783
+ btn.disabled = false;
784
+ }
785
+ });
786
+ btn.addEventListener('blur', disarm);
787
+ };
788
+
789
+ const revoke = async (scope) => {
790
+ const resp = await fetch(`${CONFIG.API_BASE || ''}/api/auth/revoke`, {
791
+ method: 'POST',
792
+ headers: { 'Content-Type': 'application/json' },
793
+ body: JSON.stringify({ scope }),
794
+ });
795
+ if (!resp.ok) throw new Error(`revoke ${scope} failed: ${resp.status}`);
796
+ return resp.json();
797
+ };
798
+
799
+ // Drop the service worker's offline caches on the way out.
800
+ //
801
+ // Clearing the cookie ends the SESSION; it does nothing to bytes already
802
+ // written to disk by the SW, which survive logout, browser restart and
803
+ // going offline. The fetch handler no longer caches project content, but
804
+ // that only governs new writes — a client that ran an older SW still has
805
+ // `/view` responses on disk, and this is what actually removes them.
806
+ //
807
+ // Deliberately best-effort: logging out must succeed even if CacheStorage
808
+ // is unavailable (older WebViews, private modes) or a delete rejects.
809
+ // Failing the logout to report a cache-eviction problem would be a worse
810
+ // outcome than a stale cache.
811
+ const purgeOfflineCaches = async () => {
812
+ try {
813
+ if (!self.caches) return;
814
+ const names = await caches.keys();
815
+ await Promise.all(names.map((n) => caches.delete(n)));
816
+ } catch (e) {
817
+ console.warn('[auth] offline cache purge failed', e);
818
+ }
819
+ };
820
+
821
+ // Local logout is NOT armed: it's cheap and reversible (log back in), and
822
+ // arming it would imply a blast radius it doesn't have.
823
+ const logoutBtn = container.querySelector('#account-logout');
824
+ if (logoutBtn) {
825
+ logoutBtn.addEventListener('click', async () => {
826
+ logoutBtn.disabled = true;
827
+ try {
828
+ await fetch(`${CONFIG.API_BASE || ''}/api/logout`, { method: 'POST' });
829
+ await purgeOfflineCaches();
830
+ showToast(S.toast.logged_out);
831
+ // The cookie is gone; every later request would 401 into the
832
+ // same redirect. Go there directly instead of letting the app
833
+ // discover it mid-flight.
834
+ window.location.replace('/login');
835
+ } catch (e) {
836
+ logoutBtn.disabled = false;
837
+ showToast(S.toast.revoke_failed);
838
+ }
839
+ });
840
+ }
841
+
842
+ armConfirm(container.querySelector('#account-revoke-browsers'), async () => {
843
+ try {
844
+ await revoke('browsers');
845
+ // This browser is one of the browsers being logged out, so its
846
+ // own on-disk cache goes too. Skipping this would leave the
847
+ // device that ran "log out everywhere" holding cached content.
848
+ await purgeOfflineCaches();
849
+ showToast(S.toast.revoked_browsers);
850
+ // This browser was included in "everywhere" — that's the honest
851
+ // semantic, so land on /login rather than pretending otherwise.
852
+ window.location.replace('/login');
853
+ } catch (e) {
854
+ showToast(S.toast.revoke_failed);
855
+ }
856
+ });
857
+
858
+ armConfirm(container.querySelector('#account-revoke-scripts'), async () => {
859
+ try {
860
+ await revoke('scripts');
861
+ showToast(S.toast.revoked_scripts); // cookie survives; stay put
862
+ } catch (e) {
863
+ showToast(S.toast.revoke_failed);
864
+ }
865
+ });
866
+
867
+ // Layout radio buttons
868
+ container.querySelectorAll('input[name="layout"]').forEach(radio => {
869
+ radio.addEventListener('change', (e) => {
870
+ state.setLayout(e.target.value);
871
+ });
872
+ });
873
+
874
+ // Session list limit input
875
+ const sessionListLimitInput = container.querySelector('#session-list-limit-input');
876
+ if (sessionListLimitInput) {
877
+ sessionListLimitInput.addEventListener('change', (e) => {
878
+ const value = parseInt(e.target.value, 10);
879
+ if (value >= 10 && value <= 500) {
880
+ state.setSessionListLimit(value);
881
+ } else {
882
+ e.target.value = state.config.sessionListLimit || CONFIG.DEFAULT_SESSION_LIST_LIMIT;
883
+ }
884
+ });
885
+ }
886
+
887
+ // Disable autocorrect toggle
888
+ const disableAutocorrect = container.querySelector('#disable-autocorrect');
889
+ if (disableAutocorrect) {
890
+ disableAutocorrect.addEventListener('change', (e) => {
891
+ state.setDisableAutocorrect(e.target.checked);
892
+ });
893
+ }
894
+
895
+ // Thinking keywords highlighting toggle
896
+ const highlightThinkingKeywords = container.querySelector('#highlight-thinking-keywords');
897
+ if (highlightThinkingKeywords) {
898
+ highlightThinkingKeywords.addEventListener('change', (e) => {
899
+ state.setHighlightThinkingKeywords(e.target.checked);
900
+ });
901
+ }
902
+
903
+ // Annotate-images-on-paste toggle
904
+ const annotateOnPaste = container.querySelector('#annotate-on-paste');
905
+ if (annotateOnPaste) {
906
+ annotateOnPaste.addEventListener('change', (e) => {
907
+ state.setAnnotateOnPaste(e.target.checked);
908
+ });
909
+ }
910
+
911
+ // Terminal OSC 52 clipboard-write toggle
912
+ const terminalClipboard = container.querySelector('#terminal-clipboard-write');
913
+ if (terminalClipboard) {
914
+ terminalClipboard.addEventListener('change', (e) => {
915
+ state.setTerminalClipboardWrite(e.target.checked);
916
+ });
917
+ }
918
+
919
+ // Shortcut hints master toggle
920
+ const hintsEnabled = container.querySelector('#shortcut-hints-enabled');
921
+ const hintsPicker = container.querySelector('#shortcut-hints-picker');
922
+ if (hintsEnabled) {
923
+ hintsEnabled.addEventListener('change', (e) => {
924
+ setHintsEnabled(e.target.checked);
925
+ ShortcutHints.refresh();
926
+ if (hintsPicker) {
927
+ hintsPicker.classList.toggle('disabled', !e.target.checked);
928
+ }
929
+ });
930
+ // Reflect initial state
931
+ if (hintsPicker) {
932
+ hintsPicker.classList.toggle('disabled', !hintsEnabled.checked);
933
+ }
934
+ }
935
+
936
+ // Shortcut hints checkboxes — write full ordered list on every change
937
+ container.querySelectorAll('#shortcut-hints-picker input[type="checkbox"][data-hint-id]').forEach(cb => {
938
+ cb.addEventListener('change', () => {
939
+ const checked = Array.from(
940
+ container.querySelectorAll('#shortcut-hints-picker input[type="checkbox"][data-hint-id]:checked')
941
+ ).map(el => el.dataset.hintId);
942
+ // Preserve HINT_CANDIDATE_IDS order (iterate the canonical list, keep only checked)
943
+ const ordered = HINT_CANDIDATE_IDS.filter(id => checked.includes(id));
944
+ setHintIds(ordered);
945
+ ShortcutHints.refresh();
946
+ });
947
+ });
948
+
949
+ // Reset shortcut hints to defaults
950
+ const hintsReset = container.querySelector('#shortcut-hints-reset');
951
+ if (hintsReset) {
952
+ hintsReset.addEventListener('click', () => {
953
+ setHintIds(DEFAULT_HINT_IDS.slice());
954
+ // Re-render checkboxes to reflect defaults
955
+ const picker = container.querySelector('.shortcut-hints-picker-list');
956
+ if (picker) picker.innerHTML = renderShortcutHintsPicker();
957
+ // Re-bind checkbox handlers (innerHTML wiped them)
958
+ container.querySelectorAll('#shortcut-hints-picker input[type="checkbox"][data-hint-id]').forEach(cb => {
959
+ cb.addEventListener('change', () => {
960
+ const checked = Array.from(
961
+ container.querySelectorAll('#shortcut-hints-picker input[type="checkbox"][data-hint-id]:checked')
962
+ ).map(el => el.dataset.hintId);
963
+ const ordered = HINT_CANDIDATE_IDS.filter(id => checked.includes(id));
964
+ setHintIds(ordered);
965
+ ShortcutHints.refresh();
966
+ });
967
+ });
968
+ ShortcutHints.refresh();
969
+ });
970
+ }
971
+
972
+ // Permission level select (loaded from server API)
973
+ const permSelect = container.querySelector('#default-permission-level');
974
+ if (permSelect) {
975
+ fetch(`${CONFIG.API_BASE || ''}/api/app/default-permissions`)
976
+ .then(r => r.ok ? r.json() : null)
977
+ .then(data => {
978
+ if (!data) return;
979
+ // The default engine self-describes its modes (e.g. claude-sdk
980
+ // adds "Ask"); rebuild the options from that vocabulary.
981
+ if (Array.isArray(data.modes) && data.modes.length) {
982
+ permSelect.innerHTML = data.modes.map(m =>
983
+ `<option value="${m.value}">${m.label}</option>`).join('\n');
984
+ }
985
+ permSelect.value = data.default_level || 'dontAsk';
986
+ })
987
+ .catch(() => {});
988
+ permSelect.addEventListener('change', (e) => {
989
+ fetch(`${CONFIG.API_BASE || ''}/api/app/default-permissions`, {
990
+ method: 'PUT',
991
+ headers: { 'Content-Type': 'application/json' },
992
+ body: JSON.stringify({ permission_level: e.target.value })
993
+ });
994
+ if (window.permissionSettings) {
995
+ window.permissionSettings.globalDefault = e.target.value;
996
+ }
997
+ });
998
+ }
999
+
1000
+ // Download mode radios
1001
+ container.querySelectorAll('input[name="downloadMode"]').forEach(radio => {
1002
+ radio.addEventListener('change', (e) => {
1003
+ state.setDownloadMode(e.target.value);
1004
+ });
1005
+ });
1006
+
1007
+ // Terminal size inputs
1008
+ const termW = container.querySelector('#terminal-size-w');
1009
+ const termH = container.querySelector('#terminal-size-h');
1010
+ const saveTermSize = () => {
1011
+ const w = parseInt(termW?.value) || TerminalWidget.DEFAULT_WIDTH;
1012
+ const h = parseInt(termH?.value) || TerminalWidget.DEFAULT_HEIGHT;
1013
+ TerminalWidget.setConfiguredSize(w, h);
1014
+ };
1015
+ if (termW) termW.addEventListener('change', saveTermSize);
1016
+ if (termH) termH.addEventListener('change', saveTermSize);
1017
+
1018
+ const resetTermBtn = container.querySelector('#reset-terminal-size');
1019
+ if (resetTermBtn) {
1020
+ resetTermBtn.addEventListener('click', () => {
1021
+ TerminalWidget.resetConfiguredSize();
1022
+ if (termW) termW.value = TerminalWidget.DEFAULT_WIDTH;
1023
+ if (termH) termH.value = TerminalWidget.DEFAULT_HEIGHT;
1024
+ });
1025
+ }
1026
+
1027
+ // Reset preview size button
1028
+ const resetPreviewBtn = container.querySelector('#reset-preview-size');
1029
+ if (resetPreviewBtn) {
1030
+ resetPreviewBtn.addEventListener('click', () => {
1031
+ FilePreviewWidget.resetSize();
1032
+ updatePreviewSizeUI(container);
1033
+ });
1034
+ }
1035
+
1036
+
1037
+ // Line-wrap toggle — shares the one chat-wide preference with the per-block
1038
+ // wrap buttons, so flipping it here restyles every rendered block instantly.
1039
+ const codeBlockWrap = container.querySelector('#code-block-wrap');
1040
+ if (codeBlockWrap) {
1041
+ codeBlockWrap.addEventListener('change', (e) => {
1042
+ MarkdownRenderer.setCodeWrap(e.target.checked);
1043
+ });
1044
+ }
1045
+
1046
+ // Selection in preview toggle
1047
+ const selectionInPreview = container.querySelector('#selection-in-preview');
1048
+ if (selectionInPreview) {
1049
+ selectionInPreview.addEventListener('change', (e) => {
1050
+ state.setSelectionInPreview(e.target.checked);
1051
+ });
1052
+ }
1053
+
1054
+ // Tool collapse mode grid selects
1055
+ container.querySelectorAll('.collapse-mode-select').forEach(sel => {
1056
+ sel.addEventListener('change', () => {
1057
+ state.setCollapseMode(sel.dataset.context, sel.dataset.type, sel.value);
1058
+ });
1059
+ });
1060
+
1061
+ // Quick Actions tab event handlers
1062
+ setupQuickActionsEvents(container);
1063
+
1064
+ // Font scale controls
1065
+ const fontDecrease = container.querySelector('#font-decrease');
1066
+ const fontIncrease = container.querySelector('#font-increase');
1067
+ const fontSizeLabel = container.querySelector('#font-size-label');
1068
+
1069
+ if (fontDecrease) {
1070
+ fontDecrease.addEventListener('click', () => {
1071
+ window.app?.adjustFontSize(-0.1);
1072
+ if (fontSizeLabel && window.app?.fontScale) {
1073
+ fontSizeLabel.textContent = `${Math.round(window.app.fontScale * 100)}%`;
1074
+ }
1075
+ });
1076
+ }
1077
+
1078
+ if (fontIncrease) {
1079
+ fontIncrease.addEventListener('click', () => {
1080
+ window.app?.adjustFontSize(0.1);
1081
+ if (fontSizeLabel && window.app?.fontScale) {
1082
+ fontSizeLabel.textContent = `${Math.round(window.app.fontScale * 100)}%`;
1083
+ }
1084
+ });
1085
+ }
1086
+
1087
+ // Floating buttons opacity slider
1088
+ const floatingOpacitySlider = container.querySelector('#floating-opacity-slider');
1089
+ const floatingOpacityLabel = container.querySelector('#floating-opacity-label');
1090
+
1091
+ if (floatingOpacitySlider) {
1092
+ floatingOpacitySlider.addEventListener('input', (e) => {
1093
+ const value = parseInt(e.target.value, 10);
1094
+ const opacity = value / 100;
1095
+ // Update label immediately for feedback
1096
+ if (floatingOpacityLabel) {
1097
+ floatingOpacityLabel.textContent = `${value}%`;
1098
+ }
1099
+ // Apply the opacity
1100
+ applyFloatingButtonsOpacity(opacity);
1101
+ // Save to config
1102
+ state.config.floatingButtonsOpacity = opacity;
1103
+ state.save();
1104
+ });
1105
+ }
1106
+
1107
+ // Engines tab (list, sub-tabs, per-engine panel incl. session defaults)
1108
+ setupModelsTab(container);
1109
+
1110
+ // API retry max controls
1111
+ setupApiRetryControls(container);
1112
+
1113
+ // Stop-on-AskUserQuestion toggle
1114
+ setupSigintOnAskControls(container);
1115
+
1116
+ // Project settings handlers
1117
+ const shadowGitEnabled = container.querySelector('#shadow-git-enabled');
1118
+ debug.log('[Config] shadowGitEnabled element:', shadowGitEnabled);
1119
+ if (shadowGitEnabled) {
1120
+ shadowGitEnabled.addEventListener('change', async (e) => {
1121
+ debug.log('[Config] shadowGitEnabled changed:', e.target.checked);
1122
+ await state.saveProjectConfig({
1123
+ shadow_git: {
1124
+ ...state.projectConfig?.shadow_git,
1125
+ enabled: e.target.checked
1126
+ }
1127
+ });
1128
+ });
1129
+ }
1130
+
1131
+ const shadowGitRichCommits = container.querySelector('#shadow-git-rich-commits');
1132
+ if (shadowGitRichCommits) {
1133
+ shadowGitRichCommits.addEventListener('change', async (e) => {
1134
+ await state.saveProjectConfig({
1135
+ shadow_git: {
1136
+ ...state.projectConfig?.shadow_git,
1137
+ rich_commits: e.target.checked
1138
+ }
1139
+ });
1140
+ });
1141
+ }
1142
+
1143
+ // Extra directories handlers (project) - in-place update, no full re-render
1144
+ const projectDirOpts = {
1145
+ inputId: 'extra-dir-input',
1146
+ btnId: 'extra-dir-add-btn',
1147
+ listId: 'extra-dirs-list',
1148
+ removeClass: 'extra-dir-remove',
1149
+ getDirsFn: () => state.projectConfig?.extra_dirs || [],
1150
+ saveFn: async (dirs) => { await state.saveProjectConfig({ extra_dirs: dirs }); },
1151
+ };
1152
+ setupExtraDirAddHandler(container, projectDirOpts);
1153
+ // Attach initial remove handlers
1154
+ updateExtraDirsInPlace(container, { ...projectDirOpts, dirs: projectDirOpts.getDirsFn() });
1155
+
1156
+ // Global shadow git defaults handlers
1157
+ const shadowGitDefaultEnabled = container.querySelector('#shadow-git-default-enabled');
1158
+ if (shadowGitDefaultEnabled) {
1159
+ shadowGitDefaultEnabled.addEventListener('change', async (e) => {
1160
+ await state.saveShadowGitDefaults({
1161
+ ...state.shadowGitDefaults,
1162
+ enabled: e.target.checked
1163
+ });
1164
+ });
1165
+ }
1166
+
1167
+ const shadowGitDefaultRichCommits = container.querySelector('#shadow-git-default-rich-commits');
1168
+ if (shadowGitDefaultRichCommits) {
1169
+ shadowGitDefaultRichCommits.addEventListener('change', async (e) => {
1170
+ await state.saveShadowGitDefaults({
1171
+ ...state.shadowGitDefaults,
1172
+ rich_commits: e.target.checked
1173
+ });
1174
+ });
1175
+ }
1176
+
1177
+ // Global extra directories handlers - in-place update, no full re-render
1178
+ const globalDirOpts = {
1179
+ inputId: 'global-extra-dir-input',
1180
+ btnId: 'global-extra-dir-add-btn',
1181
+ listId: 'global-extra-dirs-list',
1182
+ removeClass: 'global-extra-dir-remove',
1183
+ getDirsFn: () => state.globalExtraDirs || [],
1184
+ saveFn: async (dirs) => { await state.saveGlobalExtraDirs(dirs); },
1185
+ };
1186
+ setupExtraDirAddHandler(container, globalDirOpts);
1187
+ updateExtraDirsInPlace(container, { ...globalDirOpts, dirs: globalDirOpts.getDirsFn() });
1188
+
1189
+ // Commit sections handlers
1190
+ setupCommitSectionsHandlers(container);
1191
+ }
1192
+
1193
+ function switchTab(container, tabName) {
1194
+ state.activeTab = tabName;
1195
+
1196
+ // Update tab buttons
1197
+ container.querySelectorAll('.config-tab').forEach(tab => {
1198
+ tab.classList.toggle('active', tab.dataset.tab === tabName);
1199
+ });
1200
+
1201
+ // Update sections
1202
+ container.querySelectorAll('.config-section').forEach(section => {
1203
+ section.hidden = section.dataset.section !== tabName;
1204
+ });
1205
+
1206
+ // Auto-focus search input when switching to shortcuts tab
1207
+ if (tabName === 'shortcuts') {
1208
+ setTimeout(() => {
1209
+ const searchInput = container.querySelector('.shortcuts-search-input');
1210
+ if (searchInput) {
1211
+ searchInput.focus();
1212
+ debug.log('[Config] switchTab: Focused shortcuts search input');
1213
+ }
1214
+ }, 50);
1215
+ }
1216
+ }
1217
+
1218
+ /**
1219
+ * Cycle through settings tabs (for Ctrl+[/] navigation)
1220
+ * @param {HTMLElement} container - The config widget container
1221
+ * @param {number} direction - -1 for previous, 1 for next
1222
+ */
1223
+ function cycleSettingsTab(container, direction) {
1224
+ // Get visible tabs in DOM order
1225
+ const tabs = Array.from(container.querySelectorAll('.config-tab'));
1226
+ if (tabs.length === 0) return;
1227
+
1228
+ // Find current active tab index
1229
+ const currentIndex = tabs.findIndex(tab => tab.classList.contains('active'));
1230
+ if (currentIndex === -1) return;
1231
+
1232
+ // Calculate new index with wrap-around
1233
+ const newIndex = (currentIndex + direction + tabs.length) % tabs.length;
1234
+ const newTabName = tabs[newIndex].dataset.tab;
1235
+
1236
+ switchTab(container, newTabName);
1237
+ }
1238
+
1239
+ /**
1240
+ * Switch to settings tab by index (for Ctrl+1-9 navigation)
1241
+ * @param {HTMLElement} container - The config widget container
1242
+ * @param {number} index - 0-based tab index
1243
+ */
1244
+ function switchToSettingsTabByIndex(container, index) {
1245
+ const tabs = Array.from(container.querySelectorAll('.config-tab'));
1246
+ if (index >= 0 && index < tabs.length) {
1247
+ const tabName = tabs[index].dataset.tab;
1248
+ switchTab(container, tabName);
1249
+ }
1250
+ }
1251
+
1252
+ // ═══════════════════════════════════════════════════════════════════════════
1253
+ // Custom Keyboard Handler
1254
+ // ═══════════════════════════════════════════════════════════════════════════
1255
+
1256
+ let keydownHandler = null;
1257
+
1258
+ function handleConfigKeydown(e) {
1259
+ const widget = WidgetManager.widgets.get('config');
1260
+ if (!widget?.isVisible) return;
1261
+
1262
+ // While capturing a shortcut, hand every key (including Escape) to the
1263
+ // editor so users can bind Cmd+[, Cmd+1-9, Escape, etc. without this
1264
+ // handler stealing them for settings-tab navigation.
1265
+ if (state.shortcutEditor?.capturing) return;
1266
+
1267
+ // Handle Escape (close panel)
1268
+ if (e.key === 'Escape') {
1269
+ e.preventDefault();
1270
+ e.stopImmediatePropagation();
1271
+ widget.close();
1272
+ return;
1273
+ }
1274
+
1275
+ // Handle Ctrl/Cmd + key combinations
1276
+ const hasModifier = e.ctrlKey || e.metaKey;
1277
+ if (hasModifier && !e.altKey && !e.shiftKey) {
1278
+ // Ctrl+[ / Cmd+[ (previous tab)
1279
+ if (e.key === '[') {
1280
+ e.preventDefault();
1281
+ e.stopImmediatePropagation();
1282
+ cycleSettingsTab(state.container, -1);
1283
+ return;
1284
+ }
1285
+ // Ctrl+] / Cmd+] (next tab)
1286
+ if (e.key === ']') {
1287
+ e.preventDefault();
1288
+ e.stopImmediatePropagation();
1289
+ cycleSettingsTab(state.container, 1);
1290
+ return;
1291
+ }
1292
+ // Ctrl+1-9 / Cmd+1-9 (jump to tab by index)
1293
+ const num = parseInt(e.key, 10);
1294
+ if (num >= 1 && num <= 9) {
1295
+ e.preventDefault();
1296
+ e.stopImmediatePropagation();
1297
+ switchToSettingsTabByIndex(state.container, num - 1);
1298
+ return;
1299
+ }
1300
+ }
1301
+ }
1302
+
1303
+ // ═══════════════════════════════════════════════════════════════════════════
1304
+ // Widget Registration
1305
+ // ═══════════════════════════════════════════════════════════════════════════
1306
+
1307
+ export function registerConfigWidget() {
1308
+ state.shortcutEditor = new ShortcutEditor();
1309
+
1310
+ WidgetManager.register('config', {
1311
+ // type: 'modal' is load-bearing — the inline `position: fixed` overlays
1312
+ // below (`.config-modal-overlay`, `.qa-add-dialog`, `.section-edit-modal`)
1313
+ // are appended to this widget's container, not document.body. Floating
1314
+ // widgets apply `transform: scale(1)`, which would create a containing
1315
+ // block and trap those overlays inside the widget bounds. If converting
1316
+ // to 'floating', append those overlays to document.body instead.
1317
+ type: 'modal',
1318
+ title: S.widgets.titles.settings,
1319
+ icon: 'settings',
1320
+ scope: 'global',
1321
+
1322
+ // Modal options
1323
+ closeOnBackdrop: true,
1324
+ closeOnEscape: false, // We handle escape manually for capture mode
1325
+ width: '500px',
1326
+ maxWidth: '95vw',
1327
+ maxHeight: '85vh',
1328
+
1329
+ // No transform for modal
1330
+ allowTransform: false,
1331
+
1332
+ render: renderConfigPanel,
1333
+
1334
+ onOpen: async () => {
1335
+ // Check for tab requested via WidgetManager.open context (works across module instances)
1336
+ const widget = WidgetManager.get('config');
1337
+ const contextTab = widget?._openContext?.tab;
1338
+ // Captured HERE, next to the tab, not where it is used at the end
1339
+ // of onOpen: base-widget clears _openContext after the first render,
1340
+ // and onOpen may trigger a full re-render in between — reading it
1341
+ // later gets null. Same reason contextTab is read up here.
1342
+ const contextSection = widget?._openContext?.section;
1343
+ const requestedTab = contextTab || (state._tabSelected ? state.activeTab : null);
1344
+ state._tabSelected = false;
1345
+
1346
+ // Switch to requested tab IMMEDIATELY (before async loading)
1347
+ if (requestedTab && state.container) {
1348
+ switchTab(state.container, requestedTab);
1349
+ }
1350
+
1351
+ // Load configs in parallel
1352
+ const promises = [state.loadShadowGitDefaults(), state.loadGlobalExtraDirs()];
1353
+ if (state.hasActiveProject()) {
1354
+ promises.push(state.loadProjectConfig());
1355
+ }
1356
+ await Promise.all(promises);
1357
+
1358
+ // Load commit sections after project config (needs project hash)
1359
+ if (state.hasActiveProject() && state.projectInfo?.hash) {
1360
+ await state.loadCommitSections();
1361
+ // Update sections count badge and refresh editor if expanded
1362
+ if (state.container) {
1363
+ updateSectionsCount(state.container);
1364
+ // Refresh editor content if sections are expanded (fixes loading state stuck)
1365
+ if (state.commitSectionsExpanded && state.commitSections) {
1366
+ const editor = state.container.querySelector('#commit-sections-editor');
1367
+ if (editor) {
1368
+ editor.innerHTML = renderCommitSectionsEditor(state);
1369
+ setupCommitSectionItemHandlers(state.container);
1370
+ }
1371
+ }
1372
+ }
1373
+ }
1374
+
1375
+ // Check if widget was rendered (has content with checkboxes)
1376
+ // If not, render now. This handles the case where:
1377
+ // 1. Widget was created without a session (no setSession render trigger)
1378
+ // 2. Widget is reopened and sessionId hasn't changed
1379
+ const container = state.container;
1380
+ const hasCheckboxes = container?.querySelector('#shadow-git-enabled') ||
1381
+ container?.querySelector('#shadow-git-default-enabled');
1382
+
1383
+ if (!hasCheckboxes) {
1384
+ // Need full render - widget content is empty
1385
+ debug.log('[Config] onOpen: no checkboxes found, triggering full render');
1386
+ WidgetManager.update('config');
1387
+ } else {
1388
+ // Widget already rendered - just sync checkbox states
1389
+ // WITHOUT full re-render (which would destroy event handlers)
1390
+ if (state.projectConfig) {
1391
+ const sgEnabled = container.querySelector('#shadow-git-enabled');
1392
+ const sgRich = container.querySelector('#shadow-git-rich-commits');
1393
+
1394
+ if (sgEnabled) sgEnabled.checked = state.projectConfig.shadow_git?.enabled !== false;
1395
+ if (sgRich) sgRich.checked = state.projectConfig.shadow_git?.rich_commits !== false;
1396
+ }
1397
+
1398
+ if (state.shadowGitDefaults) {
1399
+ const defEnabled = container.querySelector('#shadow-git-default-enabled');
1400
+ const defRich = container.querySelector('#shadow-git-default-rich-commits');
1401
+
1402
+ if (defEnabled) defEnabled.checked = state.shadowGitDefaults.enabled !== false;
1403
+ if (defRich) defRich.checked = state.shadowGitDefaults.rich_commits !== false;
1404
+ }
1405
+
1406
+ // Sync extra dirs lists (they may have loaded after initial render)
1407
+ if (state.projectConfig) {
1408
+ updateExtraDirsInPlace(container, {
1409
+ listId: 'extra-dirs-list',
1410
+ dirs: state.projectConfig.extra_dirs || [],
1411
+ removeClass: 'extra-dir-remove',
1412
+ getDirsFn: () => state.projectConfig?.extra_dirs || [],
1413
+ saveFn: async (dirs) => { await state.saveProjectConfig({ extra_dirs: dirs }); },
1414
+ });
1415
+ }
1416
+ updateExtraDirsInPlace(container, {
1417
+ listId: 'global-extra-dirs-list',
1418
+ dirs: state.globalExtraDirs || [],
1419
+ removeClass: 'global-extra-dir-remove',
1420
+ getDirsFn: () => state.globalExtraDirs || [],
1421
+ saveFn: async (dirs) => { await state.saveGlobalExtraDirs(dirs); },
1422
+ });
1423
+ debug.log('[Config] onOpen: synced checkbox states and extra dirs from loaded config');
1424
+ }
1425
+
1426
+ // Add custom keyboard handler (Escape, Ctrl+[/] for tab navigation)
1427
+ keydownHandler = handleConfigKeydown;
1428
+ document.addEventListener('keydown', keydownHandler, true);
1429
+
1430
+ // Setup swipe gestures for settings tabs
1431
+ if (state.container) {
1432
+ setupConfigGestures(state.container, (direction) => cycleSettingsTab(state.container, direction));
1433
+ }
1434
+
1435
+ // Disable main shortcut handler while config is open
1436
+ if (window.app?.shortcutManager) {
1437
+ window.app.shortcutManager.enabled = false;
1438
+ }
1439
+
1440
+ // Sync font scale label
1441
+ const fontSizeLabel = state.container?.querySelector('#font-size-label');
1442
+ if (fontSizeLabel && window.app?.fontScale) {
1443
+ fontSizeLabel.textContent = `${Math.round(window.app.fontScale * 100)}%`;
1444
+ }
1445
+
1446
+ // Switch to requested tab (e.g. "Customize..." → quickactions)
1447
+ if (requestedTab && state.container) {
1448
+ switchTab(state.container, requestedTab);
1449
+ }
1450
+
1451
+ // Deep-link to a section within the tab. Without this, a caller
1452
+ // like the Auto-journal panel's "Configure defaults for new
1453
+ // projects →" lands the user at the TOP of the System tab while
1454
+ // the section it promised is the last block down the page — the
1455
+ // link appears to do nothing. Runs after the tab switch (a hidden
1456
+ // section has no scrollable geometry) and after the render/resync
1457
+ // above, so the target exists.
1458
+ // Re-queried on each attempt rather than captured once: onOpen may
1459
+ // have triggered a full WidgetManager.update() above, which swaps
1460
+ // the whole subtree — scrolling the node we found before that
1461
+ // replacement moves a detached element and looks like a no-op.
1462
+ // Scrolling is idempotent, so a few spaced attempts is the cheapest
1463
+ // way to be correct regardless of when the re-render lands.
1464
+ if (contextSection) {
1465
+ let flashed = false;
1466
+ [0, 60, 200, 500].forEach((delay) => setTimeout(() => {
1467
+ const target = state.container?.querySelector(`#${contextSection}`);
1468
+ if (!target) return;
1469
+ target.scrollIntoView({ block: 'center', behavior: 'smooth' });
1470
+ if (flashed) return;
1471
+ flashed = true;
1472
+ // The scroll alone is easy to miss on a dense page.
1473
+ target.classList.add('config-section-flash');
1474
+ setTimeout(() => target.classList.remove('config-section-flash'), 1600);
1475
+ }, delay));
1476
+ }
1477
+
1478
+ // Auto-focus search input if on shortcuts tab
1479
+ if (state.activeTab === 'shortcuts' && state.container) {
1480
+ setTimeout(() => {
1481
+ const searchInput = state.container.querySelector('.shortcuts-search-input');
1482
+ if (searchInput) {
1483
+ searchInput.focus();
1484
+ debug.log('[Config] onOpen: Focused shortcuts search input');
1485
+ }
1486
+ }, 100);
1487
+ }
1488
+ },
1489
+
1490
+ onClose: () => {
1491
+ // Remove custom keyboard handler
1492
+ if (keydownHandler) {
1493
+ document.removeEventListener('keydown', keydownHandler, true);
1494
+ keydownHandler = null;
1495
+ }
1496
+
1497
+ // Cleanup swipe gestures
1498
+ if (state.container) {
1499
+ cleanupConfigGestures(state.container);
1500
+ }
1501
+
1502
+ // Cancel any active capture
1503
+ state.shortcutEditor?.cancelCapture();
1504
+
1505
+ // Re-enable main shortcut handler
1506
+ if (window.app?.shortcutManager) {
1507
+ window.app.shortcutManager.enabled = true;
1508
+ }
1509
+ },
1510
+ });
1511
+ }
1512
+
1513
+ // ═══════════════════════════════════════════════════════════════════════════
1514
+ // Exports for app.js compatibility
1515
+ // ═══════════════════════════════════════════════════════════════════════════
1516
+
1517
+ export function getConfigState() {
1518
+ return state;
1519
+ }
1520
+
1521
+ export function toggleConfigPanel() {
1522
+ WidgetManager.toggle('config');
1523
+ }
1524
+
1525
+ export function showConfigPanel(tab = null) {
1526
+ if (tab) {
1527
+ state.activeTab = tab;
1528
+ state._tabSelected = true; // Prevent auto-switch to project tab
1529
+ }
1530
+ WidgetManager.open('config', tab ? { tab } : undefined);
1531
+ }
1532
+
1533
+ export function hideConfigPanel() {
1534
+ WidgetManager.close('config');
1535
+ }