tmux-ide 2.9.20 → 2.9.22

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 (145) hide show
  1. package/bin/cli.js +16998 -4283
  2. package/package.json +3 -2
  3. package/packages/contracts/src/command-catalog.ts +116 -0
  4. package/packages/contracts/src/commands.ts +5 -4
  5. package/packages/contracts/src/daemon-events.ts +2 -1
  6. package/packages/contracts/src/index.ts +3 -0
  7. package/packages/contracts/src/pane-reader.ts +121 -0
  8. package/packages/contracts/src/pane-stream.ts +18 -0
  9. package/packages/contracts/src/plain-text.ts +61 -0
  10. package/packages/contracts/src/visual-theme-presets.ts +58 -2
  11. package/packages/daemon/dist/command-center/command-catalog-routes.js +78 -0
  12. package/packages/daemon/dist/command-center/plugin-routes.js +84 -0
  13. package/packages/daemon/dist/command-center/server.js +13 -0
  14. package/packages/daemon/dist/command-center/tmux-server-reader.js +41 -0
  15. package/packages/daemon/dist/command-center/tmux-servers.js +6 -0
  16. package/packages/daemon/dist/doctor.js +106 -43
  17. package/packages/daemon/dist/lib/cli-action-bridge.js +15 -0
  18. package/packages/daemon/dist/lib/cli-command.js +13 -0
  19. package/packages/daemon/dist/lib/daemon-embed.js +39 -1
  20. package/packages/daemon/dist/lib/headless-daemon.js +1 -0
  21. package/packages/daemon/dist/lib/pane-reader-files.js +226 -0
  22. package/packages/daemon/dist/lib/remote-tmux-command.js +8 -5
  23. package/packages/daemon/dist/lib/tmux-client-execution.js +73 -7
  24. package/packages/daemon/dist/lib/tmux-pane-reader.js +105 -0
  25. package/packages/daemon/dist/lib/tmux-server-features.js +38 -0
  26. package/packages/daemon/dist/lib/tmux-server-owner.js +9 -0
  27. package/packages/daemon/dist/lib/worktree.js +18 -0
  28. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  29. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  30. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  31. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  32. package/packages/daemon/dist/open-browser.js +26 -12
  33. package/packages/daemon/dist/open-reader.js +84 -0
  34. package/packages/daemon/dist/plugins/action-catalog.js +129 -0
  35. package/packages/daemon/dist/plugins/action-cli.js +212 -0
  36. package/packages/daemon/dist/plugins/api-table.js +303 -0
  37. package/packages/daemon/dist/plugins/cli.js +556 -0
  38. package/packages/daemon/dist/plugins/consent.js +107 -0
  39. package/packages/daemon/dist/plugins/daemon-plugins.js +124 -0
  40. package/packages/daemon/dist/plugins/discovery.js +142 -0
  41. package/packages/daemon/dist/plugins/examples/worktree-tasks.js +115 -0
  42. package/packages/daemon/dist/plugins/exec-sandbox.js +202 -0
  43. package/packages/daemon/dist/plugins/host/actions-prelude.js +279 -0
  44. package/packages/daemon/dist/plugins/host/entry.js +4 -0
  45. package/packages/daemon/dist/plugins/host/host-api-prelude.js +232 -0
  46. package/packages/daemon/dist/plugins/host/lua-state.js +493 -0
  47. package/packages/daemon/dist/plugins/host/main.js +322 -0
  48. package/packages/daemon/dist/plugins/host/sandbox.js +299 -0
  49. package/packages/daemon/dist/plugins/host-calls.js +279 -0
  50. package/packages/daemon/dist/plugins/manifest.js +69 -0
  51. package/packages/daemon/dist/plugins/plugin-exec.js +261 -0
  52. package/packages/daemon/dist/plugins/plugin-log.js +54 -0
  53. package/packages/daemon/dist/plugins/plugin-store.js +74 -0
  54. package/packages/daemon/dist/plugins/protocol.js +252 -0
  55. package/packages/daemon/dist/plugins/safe-files.js +97 -0
  56. package/packages/daemon/dist/plugins/supervisor.js +790 -0
  57. package/packages/daemon/dist/plugins/worktree-calls.js +154 -0
  58. package/packages/daemon/dist/restore.js +57 -40
  59. package/packages/daemon/dist/terminal/mirror/session-channel.js +4 -1
  60. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +12 -3
  61. package/packages/daemon/dist/terminal/protocol/reader-option.js +66 -0
  62. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +7 -2
  63. package/packages/daemon/dist/tmux-upgrade/cli.js +106 -0
  64. package/packages/daemon/dist/tmux-upgrade/io.js +540 -0
  65. package/packages/daemon/dist/tmux-upgrade/plan.js +238 -0
  66. package/packages/daemon/dist/tmux-upgrade/run.js +199 -0
  67. package/packages/daemon/dist/tui/chrome/snapshot.js +3 -4
  68. package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +64 -4
  69. package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +62 -5
  70. package/packages/daemon/dist/tui/mirror/runtime/application-home-experience.js +2 -0
  71. package/packages/daemon/dist/tui/mirror/runtime/application-machine-agent-navigation.js +12 -8
  72. package/packages/daemon/dist/tui/mirror/runtime/application-palette-command-owner.js +30 -2
  73. package/packages/daemon/dist/tui/mirror/runtime/application-plugin-commands.js +152 -0
  74. package/packages/daemon/dist/tui/mirror/runtime/application-plugin-form.js +251 -0
  75. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +125 -111
  76. package/packages/daemon/dist/tui/mirror/workspace/application-command-description.js +14 -0
  77. package/packages/daemon/dist/tui/mirror/workspace/palette-list-layout.js +5 -0
  78. package/packages/daemon/src/command-center/command-catalog-routes.ts +116 -0
  79. package/packages/daemon/src/command-center/plugin-routes.ts +110 -0
  80. package/packages/daemon/src/command-center/server.ts +15 -0
  81. package/packages/daemon/src/command-center/tmux-server-reader.ts +62 -0
  82. package/packages/daemon/src/command-center/tmux-servers.ts +6 -0
  83. package/packages/daemon/src/doctor.ts +118 -45
  84. package/packages/daemon/src/lib/cli-action-bridge.ts +19 -0
  85. package/packages/daemon/src/lib/cli-command.ts +16 -0
  86. package/packages/daemon/src/lib/daemon-embed.ts +59 -0
  87. package/packages/daemon/src/lib/headless-daemon.ts +1 -0
  88. package/packages/daemon/src/lib/pane-reader-files.ts +294 -0
  89. package/packages/daemon/src/lib/remote-tmux-command.ts +13 -6
  90. package/packages/daemon/src/lib/tmux-client-execution.ts +79 -7
  91. package/packages/daemon/src/lib/tmux-pane-reader.ts +144 -0
  92. package/packages/daemon/src/lib/tmux-server-features.ts +43 -0
  93. package/packages/daemon/src/lib/tmux-server-owner.ts +9 -0
  94. package/packages/daemon/src/lib/worktree.ts +16 -0
  95. package/packages/daemon/src/open-browser.ts +59 -18
  96. package/packages/daemon/src/open-reader.ts +148 -0
  97. package/packages/daemon/src/plugins/action-catalog.ts +141 -0
  98. package/packages/daemon/src/plugins/action-cli.ts +248 -0
  99. package/packages/daemon/src/plugins/api-table.ts +346 -0
  100. package/packages/daemon/src/plugins/cli.ts +630 -0
  101. package/packages/daemon/src/plugins/consent.ts +125 -0
  102. package/packages/daemon/src/plugins/daemon-plugins.ts +172 -0
  103. package/packages/daemon/src/plugins/discovery.ts +176 -0
  104. package/packages/daemon/src/plugins/examples/worktree-tasks.ts +120 -0
  105. package/packages/daemon/src/plugins/exec-sandbox.ts +264 -0
  106. package/packages/daemon/src/plugins/host/actions-prelude.ts +280 -0
  107. package/packages/daemon/src/plugins/host/entry.ts +5 -0
  108. package/packages/daemon/src/plugins/host/host-api-prelude.ts +233 -0
  109. package/packages/daemon/src/plugins/host/lua-state.ts +557 -0
  110. package/packages/daemon/src/plugins/host/main.ts +359 -0
  111. package/packages/daemon/src/plugins/host/sandbox.ts +301 -0
  112. package/packages/daemon/src/plugins/host-calls.ts +343 -0
  113. package/packages/daemon/src/plugins/manifest.ts +74 -0
  114. package/packages/daemon/src/plugins/plugin-exec.ts +326 -0
  115. package/packages/daemon/src/plugins/plugin-log.ts +63 -0
  116. package/packages/daemon/src/plugins/plugin-store.ts +80 -0
  117. package/packages/daemon/src/plugins/protocol.ts +275 -0
  118. package/packages/daemon/src/plugins/safe-files.ts +105 -0
  119. package/packages/daemon/src/plugins/supervisor.ts +954 -0
  120. package/packages/daemon/src/plugins/worktree-calls.ts +183 -0
  121. package/packages/daemon/src/restore.ts +80 -44
  122. package/packages/daemon/src/terminal/mirror/events.ts +2 -0
  123. package/packages/daemon/src/terminal/mirror/session-channel.ts +6 -1
  124. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +15 -2
  125. package/packages/daemon/src/terminal/protocol/reader-option.ts +77 -0
  126. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +10 -1
  127. package/packages/daemon/src/tmux-upgrade/cli.ts +118 -0
  128. package/packages/daemon/src/tmux-upgrade/io.ts +596 -0
  129. package/packages/daemon/src/tmux-upgrade/plan.ts +353 -0
  130. package/packages/daemon/src/tmux-upgrade/run.ts +325 -0
  131. package/packages/daemon/src/tui/chrome/snapshot.ts +3 -4
  132. package/packages/daemon/src/tui/mirror/runtime/application-fleet-switcher.tsx +3 -1
  133. package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +110 -10
  134. package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +90 -6
  135. package/packages/daemon/src/tui/mirror/runtime/application-home-experience.ts +2 -0
  136. package/packages/daemon/src/tui/mirror/runtime/application-machine-agent-navigation.ts +20 -9
  137. package/packages/daemon/src/tui/mirror/runtime/application-palette-command-owner.ts +42 -2
  138. package/packages/daemon/src/tui/mirror/runtime/application-palette-preview.tsx +7 -1
  139. package/packages/daemon/src/tui/mirror/runtime/application-plugin-commands.ts +229 -0
  140. package/packages/daemon/src/tui/mirror/runtime/application-plugin-form.ts +312 -0
  141. package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +2 -2
  142. package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +149 -128
  143. package/packages/daemon/src/tui/mirror/workspace/application-command-description.ts +44 -2
  144. package/packages/daemon/src/tui/mirror/workspace/palette-list-layout.ts +4 -0
  145. package/packages/tmux-bridge/src/runner.ts +3 -1
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Plugin commands for the TUI palette: the plugin half of the daemon's
3
+ * command catalog, plus invoking a command and asking for a parameter's
4
+ * choices. Always the LOCAL canonical daemon, like the fleet preferences.
5
+ *
6
+ * The catalog is fetched when the palette opens, so a plugin reload shows up
7
+ * the next time the palette is opened.
8
+ */
9
+ import {
10
+ CommandCatalogResourceSchemaZ,
11
+ CommandInvokeResultSchemaZ,
12
+ CommandParamOptionsResultSchemaZ,
13
+ type CommandInvocationContext,
14
+ type CommandInvokeResult,
15
+ type CommandParamOptionsResult,
16
+ } from "@tmux-ide/contracts";
17
+ import { createSignal } from "solid-js";
18
+ import WebSocket from "ws";
19
+ import {
20
+ canonicalDaemonUrl,
21
+ readCanonicalDaemonInfo,
22
+ type CanonicalDaemonInfo,
23
+ } from "../../../lib/canonical-daemon.ts";
24
+ import type { ApplicationPluginPaletteCommand } from "../workspace/application-command-description.ts";
25
+
26
+ /** The bits of a WebSocket the catalog watch uses. */
27
+ export interface CatalogEventSocket {
28
+ addEventListener(type: "open" | "close" | "error", listener: () => void): void;
29
+ addEventListener(type: "message", listener: (event: { data: unknown }) => void): void;
30
+ send(data: string): void;
31
+ close(code?: number, reason?: string): void;
32
+ }
33
+
34
+ export interface PluginCommandTransport {
35
+ readonly daemon: () => CanonicalDaemonInfo | null;
36
+ readonly fetch: typeof fetch;
37
+ /** Opens the daemon's event socket; absent means no live updates. */
38
+ readonly socket?: (url: string, ownerToken: string) => CatalogEventSocket;
39
+ }
40
+
41
+ const defaultTransport: PluginCommandTransport = {
42
+ daemon: readCanonicalDaemonInfo,
43
+ fetch: (...args) => fetch(...args),
44
+ socket: (url, ownerToken) =>
45
+ new WebSocket(url, {
46
+ headers: { Authorization: `Bearer ${ownerToken}` },
47
+ }) as unknown as CatalogEventSocket,
48
+ };
49
+
50
+ async function request(
51
+ transport: PluginCommandTransport,
52
+ method: "GET" | "POST",
53
+ path: string,
54
+ body: unknown,
55
+ signal: AbortSignal,
56
+ ): Promise<unknown> {
57
+ const daemon = transport.daemon();
58
+ if (!daemon?.authToken) throw new Error("No local tmux-ide daemon is running.");
59
+ const response = await transport.fetch(
60
+ canonicalDaemonUrl("http", daemon.bindHostname, daemon.port) + path,
61
+ {
62
+ method,
63
+ redirect: "error",
64
+ signal,
65
+ headers: {
66
+ Authorization: `Bearer ${daemon.authToken}`,
67
+ ...(body === undefined ? {} : { "Content-Type": "application/json" }),
68
+ },
69
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
70
+ },
71
+ );
72
+ const payload: unknown = await response.json().catch(() => null);
73
+ if (!response.ok) {
74
+ const message =
75
+ payload && typeof payload === "object" && "error" in payload
76
+ ? String((payload as { error: unknown }).error)
77
+ : `The daemon answered ${response.status}.`;
78
+ throw new Error(message);
79
+ }
80
+ return payload;
81
+ }
82
+
83
+ export function createApplicationPluginCommands(
84
+ transport: PluginCommandTransport = defaultTransport,
85
+ ) {
86
+ const [commands, setCommands] = createSignal<readonly ApplicationPluginPaletteCommand[]>([]);
87
+ let inflight: AbortController | null = null;
88
+ const refresh = async (): Promise<void> => {
89
+ inflight?.abort();
90
+ const controller = new AbortController();
91
+ inflight = controller;
92
+ try {
93
+ const parsed = CommandCatalogResourceSchemaZ.safeParse(
94
+ await request(
95
+ transport,
96
+ "GET",
97
+ "/api/resources/command-catalog",
98
+ undefined,
99
+ AbortSignal.any([controller.signal, AbortSignal.timeout(3000)]),
100
+ ),
101
+ );
102
+ if (!parsed.success || controller.signal.aborted) return;
103
+ setCommands(
104
+ parsed.data.entries.flatMap((entry) =>
105
+ entry.plugin
106
+ ? [
107
+ {
108
+ kind: "plugin-command" as const,
109
+ id: entry.descriptor.id,
110
+ label: entry.descriptor.label,
111
+ category: entry.descriptor.category,
112
+ plugin: entry.plugin,
113
+ dangerous: entry.descriptor.dangerous,
114
+ params: entry.params,
115
+ },
116
+ ]
117
+ : [],
118
+ ),
119
+ );
120
+ } catch {
121
+ // No daemon, or plugins off: the palette simply shows no plugin commands.
122
+ } finally {
123
+ if (inflight === controller) inflight = null;
124
+ }
125
+ };
126
+ return {
127
+ commands,
128
+ /** Fetch the catalog again; keeps the last list if the daemon is unreachable. */
129
+ refresh,
130
+ /**
131
+ * Follow the daemon's command-catalog invalidations while the palette is
132
+ * open, so a plugin reload shows up without reopening it. Returns a stop
133
+ * function; does nothing without a daemon or a socket.
134
+ */
135
+ watch(): () => void {
136
+ const daemon = transport.daemon();
137
+ if (!daemon?.authToken || !transport.socket) return () => {};
138
+ let socket: CatalogEventSocket;
139
+ try {
140
+ socket = transport.socket(
141
+ canonicalDaemonUrl("ws", daemon.bindHostname, daemon.port, "/ws/events?mode=semantic"),
142
+ daemon.authToken,
143
+ );
144
+ } catch {
145
+ return () => {};
146
+ }
147
+ let stopped = false;
148
+ socket.addEventListener("error", () => {});
149
+ socket.addEventListener("open", () => {
150
+ socket.send(
151
+ JSON.stringify({
152
+ type: "subscribe",
153
+ sessions: [],
154
+ interests: [{ resource: "command-catalog", workspaceName: null }],
155
+ legacyEvents: false,
156
+ }),
157
+ );
158
+ });
159
+ socket.addEventListener("message", (event) => {
160
+ if (stopped || (typeof event.data !== "string" && !Buffer.isBuffer(event.data))) return;
161
+ let frame: unknown;
162
+ try {
163
+ frame = JSON.parse(String(event.data));
164
+ } catch {
165
+ return;
166
+ }
167
+ if (
168
+ frame &&
169
+ typeof frame === "object" &&
170
+ (frame as { type?: unknown }).type === "resource.changed" &&
171
+ (frame as { resource?: unknown }).resource === "command-catalog"
172
+ )
173
+ void refresh();
174
+ });
175
+ return () => {
176
+ if (stopped) return;
177
+ stopped = true;
178
+ socket.close(1000, "palette closed");
179
+ };
180
+ },
181
+ async invoke(
182
+ id: string,
183
+ args: Record<string, string | number | boolean>,
184
+ context: CommandInvocationContext,
185
+ confirmed: boolean,
186
+ ): Promise<CommandInvokeResult> {
187
+ try {
188
+ const parsed = CommandInvokeResultSchemaZ.safeParse(
189
+ await request(
190
+ transport,
191
+ "POST",
192
+ "/api/v2/commands/invoke",
193
+ { id, args, context, ...(confirmed ? { confirmed: true } : {}) },
194
+ AbortSignal.timeout(60_000),
195
+ ),
196
+ );
197
+ return parsed.success
198
+ ? parsed.data
199
+ : { ok: false, error: "The daemon sent an unexpected answer." };
200
+ } catch (error) {
201
+ return { ok: false, error: (error as Error).message };
202
+ }
203
+ },
204
+ async paramOptions(
205
+ id: string,
206
+ param: string,
207
+ context: CommandInvocationContext,
208
+ ): Promise<CommandParamOptionsResult> {
209
+ try {
210
+ const parsed = CommandParamOptionsResultSchemaZ.safeParse(
211
+ await request(
212
+ transport,
213
+ "POST",
214
+ "/api/v2/commands/param-options",
215
+ { id, param, context },
216
+ AbortSignal.timeout(30_000),
217
+ ),
218
+ );
219
+ return parsed.success
220
+ ? parsed.data
221
+ : { ok: false, error: "The daemon sent an unexpected answer." };
222
+ } catch (error) {
223
+ return { ok: false, error: (error as Error).message };
224
+ }
225
+ },
226
+ };
227
+ }
228
+
229
+ export type ApplicationPluginCommands = ReturnType<typeof createApplicationPluginCommands>;
@@ -0,0 +1,312 @@
1
+ /**
2
+ * The step-by-step form a plugin command with parameters opens inside the
3
+ * palette. Each step is one parameter: the palette's search line is the
4
+ * input, and its list holds the step's entries (a choice per option, or one
5
+ * "Use …" entry for free text). A dangerous command ends with a confirm step.
6
+ *
7
+ * Arguments are checked again by the plugin; this only collects them.
8
+ */
9
+ import {
10
+ terminalSafe,
11
+ type CommandInvocationContext,
12
+ type CommandInvokeResult,
13
+ type CommandParam,
14
+ type CommandParamOptionsResult,
15
+ } from "@tmux-ide/contracts";
16
+ import { createSignal } from "solid-js";
17
+ import type {
18
+ ApplicationPluginFormPaletteCommand,
19
+ ApplicationPluginPaletteCommand,
20
+ } from "../workspace/application-command-description.ts";
21
+
22
+ type ArgValue = string | number | boolean;
23
+
24
+ interface ParamOptionsState {
25
+ readonly phase: "loading" | "ready" | "error";
26
+ readonly choices?: readonly { value: string; label: string }[];
27
+ readonly default?: ArgValue;
28
+ readonly error?: string;
29
+ }
30
+
31
+ interface FormState {
32
+ readonly command: ApplicationPluginPaletteCommand;
33
+ readonly step: number;
34
+ readonly values: Readonly<Record<string, ArgValue>>;
35
+ readonly options: Readonly<Record<string, ParamOptionsState>>;
36
+ readonly generation: number;
37
+ }
38
+
39
+ export interface PluginFormService {
40
+ invoke(
41
+ id: string,
42
+ args: Record<string, ArgValue>,
43
+ context: CommandInvocationContext,
44
+ confirmed: boolean,
45
+ ): Promise<CommandInvokeResult>;
46
+ paramOptions(
47
+ id: string,
48
+ param: string,
49
+ context: CommandInvocationContext,
50
+ ): Promise<CommandParamOptionsResult>;
51
+ }
52
+
53
+ const quote = (value: ArgValue) => (typeof value === "string" ? `“${value}”` : String(value));
54
+
55
+ function resultNote(label: string, result: CommandInvokeResult): string {
56
+ if (!result.ok) return `${label}: ${result.error}`;
57
+ if (typeof result.value === "string" && result.value.trim()) return `${label}: ${result.value}`;
58
+ return `${label}: done`;
59
+ }
60
+
61
+ /**
62
+ * The context a palette invocation sends. The TUI's focused pane id is its
63
+ * own mirror id, not the tmux `%N` id plugins pass to ide.exec{context}, so
64
+ * only a real tmux pane id is sent as `pane`.
65
+ */
66
+ export function pluginPaletteContext(
67
+ session: string | null,
68
+ focusedPane: string | null,
69
+ ): CommandInvocationContext {
70
+ const pane = focusedPane && /^%\d{1,9}$/u.test(focusedPane) ? focusedPane : null;
71
+ return {
72
+ source: "palette",
73
+ ...(session ? { session } : {}),
74
+ ...(pane ? { pane } : {}),
75
+ };
76
+ }
77
+
78
+ export function createApplicationPluginForm(options: {
79
+ readonly service: PluginFormService;
80
+ readonly context: () => CommandInvocationContext;
81
+ readonly query: () => string;
82
+ readonly setNote: (note: string | null) => void;
83
+ /** Close the palette (the form finished or was cancelled). */
84
+ readonly close: () => void;
85
+ /** A new step started: clear the search line and selection. */
86
+ readonly stepChanged: () => void;
87
+ }) {
88
+ const [state, setState] = createSignal<FormState | null>(null);
89
+ let generation = 0;
90
+ // Notes carry plugin text (labels, results, errors) to the terminal.
91
+ const setNote = (note: string | null) =>
92
+ options.setNote(note === null ? null : terminalSafe(note, 500));
93
+
94
+ const run = (command: ApplicationPluginPaletteCommand, args: Record<string, ArgValue>) => {
95
+ setState(null);
96
+ options.close();
97
+ setNote(`${command.label}…`);
98
+ void options.service
99
+ .invoke(command.id, args, options.context(), command.dangerous)
100
+ .then((result) => setNote(resultNote(command.label, result)));
101
+ };
102
+
103
+ const loadOptions = (current: FormState, param: CommandParam) => {
104
+ if (!param.dynamicChoices && !param.dynamicDefault) return;
105
+ if (current.options[param.name]) return;
106
+ const marker = current.generation;
107
+ setState({ ...current, options: { ...current.options, [param.name]: { phase: "loading" } } });
108
+ void options.service
109
+ .paramOptions(current.command.id, param.name, options.context())
110
+ .then((result) => {
111
+ const latest = state();
112
+ if (!latest || latest.generation !== marker) return;
113
+ setState({
114
+ ...latest,
115
+ options: {
116
+ ...latest.options,
117
+ [param.name]: result.ok
118
+ ? {
119
+ phase: "ready",
120
+ ...(result.choices ? { choices: result.choices } : {}),
121
+ ...(result.default !== undefined ? { default: result.default } : {}),
122
+ }
123
+ : { phase: "error", error: result.error },
124
+ },
125
+ });
126
+ });
127
+ };
128
+
129
+ const enterStep = (next: FormState) => {
130
+ const { command } = next;
131
+ if (next.step >= command.params.length) {
132
+ // Past the last parameter: confirm a dangerous command, else run it.
133
+ if (command.dangerous && next.step === command.params.length) {
134
+ setState(next);
135
+ options.stepChanged();
136
+ return;
137
+ }
138
+ run(command, { ...next.values });
139
+ return;
140
+ }
141
+ setState(next);
142
+ options.stepChanged();
143
+ loadOptions(next, command.params[next.step]!);
144
+ };
145
+
146
+ const currentParam = (current: FormState): CommandParam | null =>
147
+ current.command.params[current.step] ?? null;
148
+
149
+ const defaultFor = (current: FormState, param: CommandParam): ArgValue | undefined =>
150
+ current.options[param.name]?.default ?? param.default;
151
+
152
+ const choicesFor = (current: FormState, param: CommandParam) =>
153
+ current.options[param.name]?.choices ?? param.choices ?? [];
154
+
155
+ const advance = (current: FormState, param: CommandParam, value: ArgValue | undefined) => {
156
+ const values = { ...current.values };
157
+ if (value === undefined) delete values[param.name];
158
+ else values[param.name] = value;
159
+ enterStep({ ...current, step: current.step + 1, values });
160
+ };
161
+
162
+ return {
163
+ active: () => state() !== null,
164
+
165
+ /**
166
+ * Start a plugin command. One without parameters and not dangerous runs
167
+ * at once; otherwise the palette turns into its form.
168
+ */
169
+ start(command: ApplicationPluginPaletteCommand): void {
170
+ generation += 1;
171
+ if (command.params.length === 0 && !command.dangerous) {
172
+ run(command, {});
173
+ return;
174
+ }
175
+ enterStep({ command, step: 0, values: {}, options: {}, generation });
176
+ },
177
+
178
+ cancel(): void {
179
+ if (!state()) return;
180
+ generation += 1;
181
+ setState(null);
182
+ },
183
+
184
+ entries(): ApplicationPluginFormPaletteCommand[] {
185
+ const current = state();
186
+ if (!current) return [];
187
+ const param = currentParam(current);
188
+ if (!param) {
189
+ return [
190
+ {
191
+ kind: "plugin-form",
192
+ key: "run",
193
+ label: `Run ${current.command.label}`,
194
+ detail: "This cannot be undone",
195
+ },
196
+ { kind: "plugin-form", key: "cancel", label: "Cancel", detail: "Do nothing" },
197
+ ];
198
+ }
199
+ const detail = param.description ?? param.label;
200
+ const loaded = current.options[param.name];
201
+ const out: ApplicationPluginFormPaletteCommand[] = [];
202
+ if (loaded?.phase === "loading") {
203
+ out.push({
204
+ kind: "plugin-form",
205
+ key: "loading",
206
+ label: "Loading choices…",
207
+ detail,
208
+ disabledReason: "Still loading choices",
209
+ });
210
+ return out;
211
+ }
212
+ if (loaded?.phase === "error") {
213
+ out.push({
214
+ kind: "plugin-form",
215
+ key: "error",
216
+ label: loaded.error ?? "Choices are unavailable",
217
+ detail,
218
+ disabledReason: "The plugin could not list choices",
219
+ });
220
+ }
221
+ const fallback = defaultFor(current, param);
222
+ if (param.type === "choice") {
223
+ for (const choice of choicesFor(current, param)) {
224
+ out.push({
225
+ kind: "plugin-form",
226
+ key: `choice:${choice.value}`,
227
+ label: choice.value === fallback ? `${choice.label} (default)` : choice.label,
228
+ detail,
229
+ });
230
+ }
231
+ } else if (param.type === "boolean") {
232
+ for (const value of [true, false]) {
233
+ out.push({
234
+ kind: "plugin-form",
235
+ key: `bool:${value}`,
236
+ label: `${value ? "Yes" : "No"}${fallback === value ? " (default)" : ""}`,
237
+ detail,
238
+ });
239
+ }
240
+ } else {
241
+ const typed = options.query();
242
+ out.push({
243
+ kind: "plugin-form",
244
+ key: "submit",
245
+ label: typed
246
+ ? `Use ${quote(typed)}`
247
+ : fallback !== undefined
248
+ ? `Use default ${quote(fallback)}`
249
+ : `Type the ${param.label.toLowerCase()}`,
250
+ detail,
251
+ ...(!typed && fallback === undefined && param.required
252
+ ? { disabledReason: `${param.label} is required` }
253
+ : {}),
254
+ });
255
+ }
256
+ if (!param.required)
257
+ out.push({ kind: "plugin-form", key: "skip", label: "Leave empty", detail });
258
+ return out;
259
+ },
260
+
261
+ /** The person activated one of the current step's entries. */
262
+ choose(entry: ApplicationPluginFormPaletteCommand): void {
263
+ const current = state();
264
+ if (!current) return;
265
+ const param = currentParam(current);
266
+ if (!param) {
267
+ if (entry.key === "run") run(current.command, { ...current.values });
268
+ else {
269
+ setState(null);
270
+ options.close();
271
+ setNote(`${current.command.label}: cancelled`);
272
+ }
273
+ return;
274
+ }
275
+ if (entry.key === "skip") return advance(current, param, undefined);
276
+ if (entry.key.startsWith("choice:")) return advance(current, param, entry.key.slice(7));
277
+ if (entry.key.startsWith("bool:")) return advance(current, param, entry.key === "bool:true");
278
+ if (entry.key !== "submit") return;
279
+ const typed = options.query();
280
+ const raw: ArgValue | undefined = typed || defaultFor(current, param);
281
+ if (raw === undefined || raw === "") {
282
+ setNote(`${param.label} is required`);
283
+ return;
284
+ }
285
+ if (param.type === "number") {
286
+ const number = typeof raw === "number" ? raw : Number(raw);
287
+ if (!Number.isFinite(number) || (typeof raw === "string" && raw.trim() === "")) {
288
+ setNote(`${param.label} must be a number`);
289
+ return;
290
+ }
291
+ return advance(current, param, number);
292
+ }
293
+ advance(current, param, String(raw));
294
+ },
295
+
296
+ /** Keyboard hint while the form is open. */
297
+ hint(): string {
298
+ const current = state();
299
+ if (!current) return "";
300
+ const param = currentParam(current);
301
+ const total = current.command.params.length;
302
+ return terminalSafe(
303
+ param
304
+ ? `${current.command.label} · ${param.label} (${current.step + 1}/${total}) · Enter to choose · Esc to cancel`
305
+ : `${current.command.label} · confirm · Enter to choose · Esc to cancel`,
306
+ 500,
307
+ );
308
+ },
309
+ };
310
+ }
311
+
312
+ export type ApplicationPluginForm = ReturnType<typeof createApplicationPluginForm>;
@@ -367,7 +367,7 @@ export async function startApplicationRoot(options: StartApplicationRootOptions
367
367
  generation,
368
368
  sessionName: () => sessionOwner?.sessionName() ?? null,
369
369
  startGeneration,
370
- selectPane: (paneId, source) => interaction.selectPane(paneId, source),
370
+ selectPane: interaction.selectPane,
371
371
  showTerminals: () => setSurface("terminals"),
372
372
  setNote: setTransientNote,
373
373
  });
@@ -484,7 +484,7 @@ export async function startApplicationRoot(options: StartApplicationRootOptions
484
484
  else paletteCommands.setOpen(chromeAction === "palette-open", "keyboard");
485
485
  return;
486
486
  }
487
- if (homeAgents?.opening() || machineAgentNavigator?.opening()) return;
487
+ if (homeAgents?.ownsKey(name) || machineAgentNavigator?.ownsKey(name)) return;
488
488
  if (
489
489
  activeSurface() === "terminals" &&
490
490
  shell().semantic === null &&