mixdog 0.9.147 → 0.9.148

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 (255) hide show
  1. package/package.json +23 -3
  2. package/scripts/build-voice-runtime-unix.sh +101 -0
  3. package/scripts/embedding-quality-probe.mjs +96 -0
  4. package/scripts/generate-voice-runtime-manifest.mjs +300 -0
  5. package/scripts/generate-voice-runtime-manifest.test.mjs +135 -0
  6. package/scripts/native-binary-arch.mjs +30 -13
  7. package/scripts/native-binary-arch.test.mjs +40 -4
  8. package/scripts/plan-voice-runtime-release.mjs +73 -0
  9. package/scripts/prepare-native-assets.mjs +50 -9
  10. package/scripts/prune-embedding-runtime.mjs +3 -3
  11. package/scripts/sync-voice-runtime-manifest.mjs +46 -0
  12. package/scripts/verify-release-assets.mjs +106 -6
  13. package/scripts/verify-voice-runtime-release.mjs +89 -0
  14. package/scripts/voice-runtime-config.json +52 -0
  15. package/src/app.mjs +42 -5
  16. package/src/headless-exec.mjs +58 -32
  17. package/src/headless-exec.test.mjs +74 -13
  18. package/src/rules/lead/01-general.md +2 -0
  19. package/src/rules/shared/10-tool-workflow.md +7 -4
  20. package/src/rules/shared/30-exploration.md +2 -1
  21. package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +28 -9
  22. package/src/runtime/agent/orchestrator/agent-trace-format.mjs +6 -1
  23. package/src/runtime/agent/orchestrator/config.mjs +53 -18
  24. package/src/runtime/agent/orchestrator/mcp/cancellation.test.mjs +139 -0
  25. package/src/runtime/agent/orchestrator/mcp/child-tree.mjs +34 -5
  26. package/src/runtime/agent/orchestrator/mcp/client.mjs +94 -10
  27. package/src/runtime/agent/orchestrator/providers/anthropic-betas.mjs +5 -0
  28. package/src/runtime/agent/orchestrator/providers/anthropic-fast-mode.mjs +98 -0
  29. package/src/runtime/agent/orchestrator/providers/anthropic-fast-mode.test.mjs +90 -0
  30. package/src/runtime/agent/orchestrator/providers/anthropic-leaked-toolcall.mjs +67 -16
  31. package/src/runtime/agent/orchestrator/providers/anthropic-messages.mjs +4 -82
  32. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-credentials.mjs +0 -5
  33. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +62 -121
  34. package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.mjs +48 -0
  35. package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.test.mjs +215 -0
  36. package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +44 -48
  37. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +54 -31
  38. package/src/runtime/agent/orchestrator/providers/antigravity-oauth.mjs +56 -2
  39. package/src/runtime/agent/orchestrator/providers/cursor-auth.mjs +34 -2
  40. package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +61 -1
  41. package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +6 -1
  42. package/src/runtime/agent/orchestrator/providers/gemini.mjs +61 -15
  43. package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +120 -1
  44. package/src/runtime/agent/orchestrator/providers/lib/env-utils.mjs +9 -0
  45. package/src/runtime/agent/orchestrator/providers/lib/stream-outcome.mjs +0 -3
  46. package/src/runtime/agent/orchestrator/providers/oauth-credential-probes.mjs +187 -84
  47. package/src/runtime/agent/orchestrator/providers/openai-compat-stream.mjs +36 -36
  48. package/src/runtime/agent/orchestrator/providers/openai-compat-wire.mjs +16 -6
  49. package/src/runtime/agent/orchestrator/providers/openai-compat-xai.mjs +50 -213
  50. package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +135 -126
  51. package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +17 -11
  52. package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +20 -7
  53. package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +11 -0
  54. package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +132 -42
  55. package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +2 -2
  56. package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +28 -10
  57. package/src/runtime/agent/orchestrator/providers/registry.mjs +122 -95
  58. package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +58 -3
  59. package/src/runtime/agent/orchestrator/providers/tool-stream-state.mjs +4 -22
  60. package/src/runtime/agent/orchestrator/session/agent-loop.mjs +7 -14
  61. package/src/runtime/agent/orchestrator/session/compact-policy.test.mjs +128 -0
  62. package/src/runtime/agent/orchestrator/session/context-compaction-policy.mjs +5 -0
  63. package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +27 -48
  64. package/src/runtime/agent/orchestrator/session/loop/steering.mjs +19 -14
  65. package/src/runtime/agent/orchestrator/session/loop/stored-tool-args.mjs +9 -43
  66. package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +5 -1
  67. package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +15 -2
  68. package/src/runtime/agent/orchestrator/session/manager/pending-messages-persistence.test.mjs +325 -0
  69. package/src/runtime/agent/orchestrator/session/manager/pending-messages.mjs +599 -195
  70. package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +22 -0
  71. package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +9 -2
  72. package/src/runtime/agent/orchestrator/session/manager.mjs +3 -0
  73. package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +26 -16
  74. package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +23 -11
  75. package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +118 -3
  76. package/src/runtime/agent/orchestrator/session/store-summary-reader.test.mjs +332 -0
  77. package/src/runtime/agent/orchestrator/session/store.mjs +38 -1
  78. package/src/runtime/agent/orchestrator/tools/builtin/advisory-lock.mjs +27 -6
  79. package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +12 -20
  80. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +291 -128
  81. package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +45 -8
  82. package/src/runtime/agent/orchestrator/tools/builtin/edit-encoding-eol.test.mjs +224 -0
  83. package/src/runtime/agent/orchestrator/tools/builtin/edit-sequential-occupation.test.mjs +53 -3
  84. package/src/runtime/agent/orchestrator/tools/builtin/external-tool-adapters.mjs +255 -25
  85. package/src/runtime/agent/orchestrator/tools/builtin/find-search-budget.test.mjs +87 -0
  86. package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.mjs +1 -1
  87. package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.mjs +132 -9
  88. package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.test.mjs +10 -0
  89. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-pattern-fanout.mjs +29 -3
  90. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-job-records.mjs +1 -1
  91. package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +178 -29
  92. package/src/runtime/agent/orchestrator/tools/builtin/local-search-telemetry.mjs +4 -1
  93. package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +32 -5
  94. package/src/runtime/agent/orchestrator/tools/builtin/native-search-health.test.mjs +5 -2
  95. package/src/runtime/agent/orchestrator/tools/builtin/native-search-runner.mjs +10 -1
  96. package/src/runtime/agent/orchestrator/tools/builtin/read-batch.mjs +38 -10
  97. package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +12 -0
  98. package/src/runtime/agent/orchestrator/tools/builtin/read-snapshot-runtime.mjs +31 -1
  99. package/src/runtime/agent/orchestrator/tools/builtin/read-tool.mjs +11 -1
  100. package/src/runtime/agent/orchestrator/tools/builtin/read-windows.mjs +22 -4
  101. package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.mjs +6 -8
  102. package/src/runtime/agent/orchestrator/tools/builtin/shell-analysis.mjs +25 -24
  103. package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +152 -133
  104. package/src/runtime/agent/orchestrator/tools/builtin/task-tool.mjs +114 -42
  105. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +129 -15
  106. package/src/runtime/agent/orchestrator/tools/code-graph/loose-file-target.test.mjs +72 -0
  107. package/src/runtime/agent/orchestrator/tools/code-graph/project-root.mjs +7 -8
  108. package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +4 -4
  109. package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +201 -19
  110. package/src/runtime/agent/orchestrator/tools/code-graph/span.mjs +26 -3
  111. package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +10 -1
  112. package/src/runtime/agent/orchestrator/tools/code-graph/symbol-search-scope.test.mjs +55 -0
  113. package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +115 -25
  114. package/src/runtime/agent/orchestrator/tools/code-graph/text-span-mask.test.mjs +268 -0
  115. package/src/runtime/agent/orchestrator/tools/code-graph-tool-defs.mjs +3 -3
  116. package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.mjs +296 -46
  117. package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.test.mjs +104 -0
  118. package/src/runtime/agent/orchestrator/tools/lib/shell-descendants.mjs +136 -0
  119. package/src/runtime/agent/orchestrator/tools/patch/dispatch.mjs +127 -38
  120. package/src/runtime/agent/orchestrator/tools/patch/engine-contract-gate.test.mjs +661 -0
  121. package/src/runtime/agent/orchestrator/tools/patch/matcher.mjs +350 -9
  122. package/src/runtime/agent/orchestrator/tools/patch/native-server.mjs +418 -44
  123. package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +27 -3
  124. package/src/runtime/agent/orchestrator/tools/patch/patch-codec-eol.test.mjs +552 -0
  125. package/src/runtime/agent/orchestrator/tools/patch/v4a-convert.mjs +65 -15
  126. package/src/runtime/agent/orchestrator/tools/patch-manifest.json +11 -11
  127. package/src/runtime/agent/orchestrator/tools/shell-command.mjs +284 -109
  128. package/src/runtime/agent/orchestrator/tools/shell-exec-output.mjs +51 -21
  129. package/src/runtime/agent/orchestrator/tools/shell-exec-policy.mjs +44 -27
  130. package/src/runtime/agent/orchestrator/tools/shell-policy.mjs +6 -1
  131. package/src/runtime/agent/orchestrator/tools/spawn-manifest.json +11 -11
  132. package/src/runtime/attachments/store.mjs +11 -3
  133. package/src/runtime/channels/data/voice-runtime-manifest.json +46 -70
  134. package/src/runtime/channels/lib/event-queue.mjs +51 -41
  135. package/src/runtime/channels/lib/scheduler.mjs +23 -28
  136. package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +6 -17
  137. package/src/runtime/channels/lib/voice-runtime-fetcher.test.mjs +17 -0
  138. package/src/runtime/channels/lib/webhook.mjs +39 -20
  139. package/src/runtime/channels/lib/whisper-server.mjs +46 -1
  140. package/src/runtime/channels/lib/worker-main.mjs +3 -1
  141. package/src/runtime/media/adapters/gemini-video.mjs +20 -4
  142. package/src/runtime/media/jobs.mjs +13 -0
  143. package/src/runtime/media/renditions.mjs +7 -1
  144. package/src/runtime/media/store.mjs +42 -22
  145. package/src/runtime/memory/index.mjs +4 -9
  146. package/src/runtime/memory/lib/agent-ipc.mjs +1 -6
  147. package/src/runtime/memory/lib/archive-security.test.mjs +21 -1
  148. package/src/runtime/memory/lib/core-memory-store.mjs +28 -50
  149. package/src/runtime/memory/lib/embedding-model-config.mjs +37 -1
  150. package/src/runtime/memory/lib/embedding-model-config.test.mjs +33 -0
  151. package/src/runtime/memory/lib/embedding-provider.mjs +34 -12
  152. package/src/runtime/memory/lib/embedding-worker.mjs +37 -5
  153. package/src/runtime/memory/lib/ko-morph.mjs +46 -15
  154. package/src/runtime/memory/lib/memory-action-handlers.mjs +18 -1
  155. package/src/runtime/memory/lib/memory-cycle1.mjs +1 -18
  156. package/src/runtime/memory/lib/memory-cycle2-gate.mjs +1 -18
  157. package/src/runtime/memory/lib/memory-cycle2-mutations.mjs +98 -45
  158. package/src/runtime/memory/lib/memory-cycle2-shared.mjs +71 -0
  159. package/src/runtime/memory/lib/memory-cycle2-shared.test.mjs +78 -0
  160. package/src/runtime/memory/lib/memory-cycle2.mjs +37 -3
  161. package/src/runtime/memory/lib/memory-cycle3.mjs +1 -1
  162. package/src/runtime/memory/lib/memory-embedding-migration.test.mjs +50 -0
  163. package/src/runtime/memory/lib/memory-recall-store.mjs +9 -24
  164. package/src/runtime/memory/lib/memory.mjs +50 -12
  165. package/src/runtime/memory/lib/pg/process.mjs +1 -10
  166. package/src/runtime/memory/lib/pg/supervisor.mjs +1 -9
  167. package/src/runtime/memory/lib/query-handlers.mjs +2 -4
  168. package/src/runtime/memory/lib/session-ingest-runtime.mjs +2 -2
  169. package/src/runtime/shared/background-tasks.mjs +15 -0
  170. package/src/runtime/shared/background-tasks.test.mjs +78 -0
  171. package/src/runtime/shared/child-guardian.mjs +2 -10
  172. package/src/runtime/shared/pid-liveness.mjs +27 -0
  173. package/src/runtime/shared/runtime-root.mjs +1 -11
  174. package/src/runtime/shared/service-discovery.mjs +1 -17
  175. package/src/runtime/shared/singleton-owner.mjs +1 -11
  176. package/src/runtime/shared/staged-update.mjs +2 -12
  177. package/src/runtime/shared/tool-status.mjs +5 -1
  178. package/src/runtime/shared/tool-surface.mjs +15 -7
  179. package/src/runtime/shared/turn-snapshot-store.mjs +168 -0
  180. package/src/runtime/shared/turn-snapshot.mjs +137 -13
  181. package/src/runtime/shared/turn-worktree-snapshot.mjs +110 -18
  182. package/src/runtime/shared/webhook-session-run.mjs +16 -2
  183. package/src/runtime/web-search/lib/http-fetch.mjs +34 -4
  184. package/src/runtime/web-search/lib/state.mjs +15 -15
  185. package/src/runtime/web-search/lib/web-tools.mjs +46 -5
  186. package/src/session-runtime/context-status.mjs +4 -12
  187. package/src/session-runtime/runtime-core.mjs +20 -1
  188. package/src/standalone/agent-dispatch-broker.mjs +33 -2
  189. package/src/standalone/agent-tool/job-task-reconcile.mjs +78 -0
  190. package/src/standalone/agent-tool/notify.mjs +3 -1
  191. package/src/standalone/agent-tool/spawn-flow.mjs +48 -66
  192. package/src/standalone/agent-tool/tag-registry.mjs +116 -33
  193. package/src/standalone/agent-tool/tool-def.mjs +2 -2
  194. package/src/standalone/agent-tool/worker-index.mjs +8 -11
  195. package/src/standalone/agent-tool/worker-rows.mjs +4 -1
  196. package/src/standalone/agent-tool.mjs +20 -55
  197. package/src/standalone/agent-watchdog-registry.mjs +28 -4
  198. package/src/standalone/channel-client.mjs +47 -15
  199. package/src/standalone/channel-transport.mjs +44 -25
  200. package/src/standalone/daemon.mjs +31 -2
  201. package/src/standalone/hook-bus/config.mjs +25 -9
  202. package/src/standalone/hook-bus/handlers.mjs +16 -52
  203. package/src/standalone/hook-bus.mjs +29 -23
  204. package/src/standalone/memory-runtime-proxy.mjs +1 -16
  205. package/src/standalone/session-client.mjs +86 -23
  206. package/src/standalone/session-protocol.mjs +0 -2
  207. package/src/standalone/session-runtime-host-health.test.mjs +5 -4
  208. package/src/standalone/session-runtime-host.mjs +101 -6
  209. package/src/standalone/session-runtime-record.mjs +1 -5
  210. package/src/standalone/session-runtime-worker.mjs +52 -57
  211. package/src/standalone/session-service.mjs +4 -1
  212. package/src/standalone/session-transport.mjs +56 -25
  213. package/src/tui/App.jsx +40 -49
  214. package/src/tui/app/app-view.jsx +14 -21
  215. package/src/tui/app/core-memory-picker.mjs +29 -16
  216. package/src/tui/app/create-app-pickers.mjs +15 -36
  217. package/src/tui/app/extension-pickers.mjs +60 -49
  218. package/src/tui/app/maintenance-pickers.mjs +100 -57
  219. package/src/tui/app/message-selector.mjs +6 -5
  220. package/src/tui/app/model-picker.mjs +30 -13
  221. package/src/tui/app/onboarding-steps.mjs +21 -12
  222. package/src/tui/app/panel-epoch.mjs +56 -0
  223. package/src/tui/app/panel-epoch.test.mjs +1009 -0
  224. package/src/tui/app/panel-surface.mjs +98 -0
  225. package/src/tui/app/project-picker.mjs +30 -29
  226. package/src/tui/app/prompt-submit.mjs +192 -97
  227. package/src/tui/app/prompt-submit.test.mjs +206 -0
  228. package/src/tui/app/provider-setup-picker.mjs +74 -43
  229. package/src/tui/app/resume-picker.mjs +11 -8
  230. package/src/tui/app/route-pickers.mjs +45 -28
  231. package/src/tui/app/settings-picker.mjs +69 -18
  232. package/src/tui/app/shell-layout.mjs +1 -3
  233. package/src/tui/app/slash-commands.mjs +0 -2
  234. package/src/tui/app/slash-dispatch.mjs +4 -2
  235. package/src/tui/app/text-entry-policy.mjs +25 -0
  236. package/src/tui/app/theme-effort-pickers.mjs +11 -16
  237. package/src/tui/app/usage-context-panels.mjs +21 -25
  238. package/src/tui/app/use-global-key-input.mjs +3 -2
  239. package/src/tui/app/use-prompt-draft-flow.mjs +6 -18
  240. package/src/tui/app/use-prompt-handlers.mjs +3 -2
  241. package/src/tui/app/use-welcome-prompt-hint.mjs +17 -3
  242. package/src/tui/components/Picker.jsx +1 -1
  243. package/src/tui/components/TextEntryPanel.jsx +7 -2
  244. package/src/tui/dist/index.mjs +652 -561
  245. package/src/tui/lib/voice-setup.mjs +1 -2
  246. package/src/tui/session/agent-job-feed.mjs +73 -11
  247. package/src/tui/session/session-api-ext.mjs +5 -6
  248. package/src/tui/session/session-api.mjs +1 -0
  249. package/src/tui/session/tool-approval.mjs +15 -5
  250. package/src/tui/session/tui-steering-persist.mjs +33 -19
  251. package/src/tui/session/tui-steering-persist.test.mjs +104 -0
  252. package/src/tui/session-local.mjs +0 -22
  253. package/scripts/.tmp-coverage-report.mjs +0 -96
  254. package/src/runtime/agent/orchestrator/tools/builtin/shell-monitor.mjs +0 -57
  255. package/src/runtime/agent/orchestrator/tools/builtin/shell-monitor.test.mjs +0 -57
@@ -0,0 +1,98 @@
1
+ /**
2
+ * panel-surface.mjs — the OWNING LAYER for the panel sinks.
3
+ *
4
+ * App.jsx hands the three React setters (picker / context panel / usage panel)
5
+ * to createPanelSurface ONCE; they never leave this module. Every panel module
6
+ * receives `surface` instead, and the only way to reach a sink is a CLAIM taken
7
+ * at the user action that is allowed to own the screen:
8
+ *
9
+ * const own = surface.claim(); // this action takes the surface
10
+ * own.paint(panel); // guarded write; null clears but keeps the flow
11
+ * own.close(); // Esc: clear and hand ownership back for good
12
+ * own.defer(fn); // callback that may settle much later
13
+ *
14
+ * The claim carries the panel epoch (panel-epoch.mjs) it was taken at and EVERY
15
+ * write re-validates it, so "paint without proving ownership" is not
16
+ * expressible: an alias of own.paint, a member call, a callback handed to
17
+ * another module, a class field, a stored or reassigned binding, a generator
18
+ * resuming after yield — all of them funnel through the same check, because the
19
+ * proof lives inside the capability, not next to the call site.
20
+ *
21
+ * Two rules make it behave like the hand-written guards it replaces:
22
+ * - a paint can itself BE the handover (panel identity change), so a
23
+ * successful write re-arms the claim on the surface it just took;
24
+ * - close() drops ownership permanently, which is what stops a late ack from
25
+ * re-opening a panel the user dismissed. Use paint(null) — not close() —
26
+ * when the same flow clears the picker and keeps going (Enter → prompt).
27
+ */
28
+ import { currentPanelEpoch, isPanelEpochCurrent, supersedePanelEpoch } from './panel-epoch.mjs';
29
+
30
+ export function createPanelSurface({ setPicker, setContextPanel, setUsagePanel } = {}) {
31
+ // The usage dashboard is not a picker: a streaming update is not a handover,
32
+ // so the picker epoch cannot express its ownership. It gets its own
33
+ // generation, bumped by closeUsage() (Esc / a newer /usage).
34
+ let usageGeneration = 0;
35
+
36
+ const claim = () => {
37
+ let token = currentPanelEpoch();
38
+ let released = false;
39
+ const owns = () => !released && isPanelEpochCurrent(token);
40
+ const write = (sink, value) => {
41
+ if (!owns()) return false;
42
+ sink?.(value);
43
+ token = currentPanelEpoch();
44
+ return true;
45
+ };
46
+ return {
47
+ owns,
48
+ paint: (panel) => write(setPicker, panel),
49
+ // Clearing the context panel hands the surface back exactly as closing a
50
+ // picker does. setPicker's caller supersedes the epoch on a close (see
51
+ // shouldSupersedePanelEpoch); this sink has no such step, so a context
52
+ // open still in flight stayed valid and repainted "Context Usage" after
53
+ // the user had already pressed Esc. Superseding here is what makes the
54
+ // dismissal final, and re-reading the token keeps THIS flow (Esc inside a
55
+ // settings picker, which clears context and carries on) working.
56
+ context: (panel) => {
57
+ if (!owns()) return false;
58
+ setContextPanel?.(panel);
59
+ if (panel == null) supersedePanelEpoch();
60
+ token = currentPanelEpoch();
61
+ return true;
62
+ },
63
+ close: () => {
64
+ if (!owns()) return false;
65
+ setPicker?.(null);
66
+ released = true;
67
+ return true;
68
+ },
69
+ defer: (run) => {
70
+ const deferredToken = token;
71
+ return (...args) => (
72
+ !released && isPanelEpochCurrent(deferredToken) ? run(...args) : undefined
73
+ );
74
+ },
75
+ };
76
+ };
77
+
78
+ const claimUsage = () => {
79
+ const generation = (usageGeneration += 1);
80
+ const owns = () => generation === usageGeneration;
81
+ return {
82
+ owns,
83
+ paint: (dashboard) => {
84
+ if (!owns()) return false;
85
+ setUsagePanel?.(dashboard);
86
+ return true;
87
+ },
88
+ };
89
+ };
90
+
91
+ // Closing the usage overlay invalidates every dashboard update in flight.
92
+ const closeUsage = () => {
93
+ usageGeneration += 1;
94
+ setUsagePanel?.(null);
95
+ };
96
+
97
+ return { claim, claimUsage, closeUsage };
98
+ }
@@ -2,20 +2,17 @@
2
2
  * project-picker.mjs — the project selector / create / rename / enter cluster.
3
3
  *
4
4
  * Extracted from App.jsx behavior-preservingly. This cluster is ref/state
5
- * coupled (it drives setPicker + a fan of prompt setters), so it's delivered as
6
- * a dependency-injection factory rather than pure functions. Project registry
7
- * and path operations are daemon calls on `store`; the TUI retains only the
8
- * OS-native folder chooser.
5
+ * coupled (it drives the panel surface + a fan of prompt setters), so it's
6
+ * delivered as a dependency-injection factory rather than pure functions.
7
+ * Project registry and path operations are daemon calls on `store`; the TUI
8
+ * retains only the OS-native folder chooser.
9
9
  */
10
10
  export function createProjectPicker({
11
11
  state,
12
12
  store,
13
- setPicker,
13
+ surface,
14
14
  setProviderPrompt,
15
- setChannelPrompt,
16
- setHookPrompt,
17
15
  setSettingsPrompt,
18
- setContextPanel,
19
16
  closeUsagePanel,
20
17
  projectNameFromPath,
21
18
  pickFolder,
@@ -94,7 +91,8 @@ export function createProjectPicker({
94
91
  }
95
92
  },
96
93
  onCancel: () => {
97
- setPicker(null);
94
+ // Esc on the list: this keypress owns the surface it clears.
95
+ surface.claim().close();
98
96
  },
99
97
  };
100
98
  };
@@ -103,11 +101,10 @@ export function createProjectPicker({
103
101
  // we register it (and offer to create it if missing). Used as a
104
102
  // fallback when no native folder dialog is available.
105
103
  const beginNewProjectManual = () => {
106
- setPicker(null);
104
+ const own = surface.claim();
105
+ own.context(null);
106
+ own.close();
107
107
  setProviderPrompt(null);
108
- setChannelPrompt(null);
109
- setHookPrompt(null);
110
- setContextPanel(null);
111
108
  closeUsagePanel();
112
109
  setSettingsPrompt({
113
110
  kind: 'project-new',
@@ -123,14 +120,15 @@ export function createProjectPicker({
123
120
  // folder we register; on cancel we return to the project picker;
124
121
  // when no dialog tool exists we fall back to manual path typing.
125
122
  const beginNewProject = () => {
123
+ // The folder dialog can stay open for minutes: the claim taken here is what
124
+ // every branch below proves ownership with.
125
+ const own = surface.claim();
126
126
  setProviderPrompt(null);
127
- setChannelPrompt(null);
128
- setHookPrompt(null);
129
- setContextPanel(null);
127
+ own.context(null);
130
128
  closeUsagePanel();
131
129
  // Keep an overlay up (kind:'project' so the banner/height stay reserved) but
132
130
  // make it inert: no selectable items, navigation is a no-op until resolve.
133
- setPicker({
131
+ own.paint({
134
132
  kind: 'project',
135
133
  title: 'Project',
136
134
  description: 'Opening folder picker… choose a folder in the dialog window.',
@@ -145,6 +143,7 @@ export function createProjectPicker({
145
143
  initialPath: String(state.cwd || process.cwd() || ''),
146
144
  })
147
145
  .then((result) => {
146
+ if (!own.owns()) return;
148
147
  if (!result || result.available === false) {
149
148
  // No native dialog on this system → manual typing.
150
149
  beginNewProjectManual();
@@ -158,7 +157,7 @@ export function createProjectPicker({
158
157
  void registerProject(result.path);
159
158
  })
160
159
  .catch(() => {
161
- beginNewProjectManual();
160
+ if (own.owns()) beginNewProjectManual();
162
161
  });
163
162
  };
164
163
 
@@ -169,9 +168,13 @@ export function createProjectPicker({
169
168
  store.pushNotice('project path is required', 'warn');
170
169
  return false;
171
170
  }
171
+ // Post-write delegation: the project list reopen must still own the surface
172
+ // (the add can ack long after an Esc).
173
+ const own = surface.claim();
172
174
  try {
173
175
  const project = await serviceCall('addProject', path);
174
176
  if (project?.name) store.pushNotice(`project added: ${project.name}`, 'info');
177
+ if (!own.owns()) return true;
175
178
  await openProjectPicker();
176
179
  return true;
177
180
  } catch (e) {
@@ -187,7 +190,7 @@ export function createProjectPicker({
187
190
  store.pushNotice('project path is required', 'warn');
188
191
  return false;
189
192
  }
190
- setPicker(null);
193
+ surface.claim().close();
191
194
  try {
192
195
  // Switch cwd first; only persist the project once the runtime accepts it,
193
196
  // so an invalid/missing path can never be written to projects.json.
@@ -208,11 +211,10 @@ export function createProjectPicker({
208
211
  // returns to the project picker. The path is never changed.
209
212
  const beginRenameProject = (project) => {
210
213
  if (!project?.path) return;
211
- setPicker(null);
214
+ const own = surface.claim();
215
+ own.context(null);
216
+ own.close();
212
217
  setProviderPrompt(null);
213
- setChannelPrompt(null);
214
- setHookPrompt(null);
215
- setContextPanel(null);
216
218
  closeUsagePanel();
217
219
  setSettingsPrompt({
218
220
  kind: 'project-rename',
@@ -228,21 +230,20 @@ export function createProjectPicker({
228
230
  // lists registered projects first, then a trailing "Current Path" shortcut.
229
231
  // Creating a new project is available via the picker-level c shortcut.
230
232
  const openProjectPicker = async ({ initialEntry = false } = {}) => {
233
+ const own = surface.claim();
231
234
  setProviderPrompt(null);
232
- setChannelPrompt(null);
233
- setHookPrompt(null);
234
235
  setSettingsPrompt(null);
235
- setContextPanel(null);
236
+ own.context(null);
236
237
  closeUsagePanel();
237
238
  const requestId = Symbol('project-picker-request');
238
- setPicker(buildProjectPickerState({
239
+ own.paint(buildProjectPickerState({
239
240
  initialEntry,
240
241
  loading: true,
241
242
  requestId,
242
243
  }));
243
244
  try {
244
245
  const projects = await serviceCall('listProjects');
245
- setPicker((current) => current?._projectRequestId === requestId
246
+ own.paint((current) => current?._projectRequestId === requestId
246
247
  ? buildProjectPickerState({
247
248
  initialEntry,
248
249
  projects: Array.isArray(projects) ? projects : [],
@@ -251,7 +252,7 @@ export function createProjectPicker({
251
252
  : current);
252
253
  return projects;
253
254
  } catch (error) {
254
- setPicker((current) => current?._projectRequestId === requestId
255
+ own.paint((current) => current?._projectRequestId === requestId
255
256
  ? buildProjectPickerState({ initialEntry, projects: [], requestId })
256
257
  : current);
257
258
  store.pushNotice(`project list failed: ${error?.message || error}`, 'error');