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,84 @@
1
+ import { bodyLimit } from "hono/body-limit";
2
+ import { z } from "zod";
3
+ import { ownerAuthorityGate } from "./owner-authority.js";
4
+ const ReloadRequestZ = z.strictObject({ name: z.string().min(1).max(64).optional() });
5
+ const RunRequestZ = z.strictObject({
6
+ code: z.string().max(1024 * 1024),
7
+ chunkName: z
8
+ .string()
9
+ .min(1)
10
+ .max(200)
11
+ .regex(/^[=@][^\0\n]*$/u)
12
+ .optional(),
13
+ budgetMs: z.number().int().min(10).max(600_000).optional(),
14
+ });
15
+ /**
16
+ * The gate every plugin and command-catalog route uses: refuse anything a
17
+ * browser sent, then require the owner capability.
18
+ */
19
+ export function ownerOnlyNonBrowserGuard(ownerToken) {
20
+ const authorize = ownerAuthorityGate(ownerToken, {
21
+ whenOwnerless: "unavailable",
22
+ unavailableMessage: "Plugins are unavailable",
23
+ mismatchMessage: "Plugins require owner authority",
24
+ });
25
+ const refuseBrowser = (c) => {
26
+ const headers = c.req.header();
27
+ const fromBrowser = Object.keys(headers).some((name) => name === "origin" || name.startsWith("sec-fetch-"));
28
+ return fromBrowser ? c.json({ error: "Plugins cannot be used from a browser" }, 403) : null;
29
+ };
30
+ return (c) => refuseBrowser(c) ?? authorize(c);
31
+ }
32
+ export function mountPluginRoutes(app, options) {
33
+ const guard = ownerOnlyNonBrowserGuard(options.ownerToken);
34
+ const unavailable = { error: "Plugins are not enabled in this daemon" };
35
+ app.get("/api/v2/plugins", (c) => {
36
+ const gate = guard(c);
37
+ if (gate)
38
+ return gate;
39
+ c.header("Cache-Control", "no-store");
40
+ if (!options.backend)
41
+ return c.json(unavailable, 503);
42
+ return c.json({ ok: true, ...options.backend.status() });
43
+ });
44
+ app.post("/api/v2/plugins/reload", bodyLimit({ maxSize: 4 * 1024 }), async (c) => {
45
+ const gate = guard(c);
46
+ if (gate)
47
+ return gate;
48
+ c.header("Cache-Control", "no-store");
49
+ if (!options.backend)
50
+ return c.json(unavailable, 503);
51
+ let body;
52
+ try {
53
+ const text = await c.req.text();
54
+ body = text ? JSON.parse(text) : {};
55
+ }
56
+ catch {
57
+ return c.json({ error: "Invalid reload request" }, 400);
58
+ }
59
+ const parsed = ReloadRequestZ.safeParse(body);
60
+ if (!parsed.success)
61
+ return c.json({ error: "Invalid reload request" }, 400);
62
+ return c.json({ ok: true, ...(await options.backend.reload(parsed.data.name)) });
63
+ });
64
+ app.post("/api/v2/lua/run", bodyLimit({ maxSize: 1024 * 1024 + 4096 }), async (c) => {
65
+ const gate = guard(c);
66
+ if (gate)
67
+ return gate;
68
+ c.header("Cache-Control", "no-store");
69
+ if (!options.backend)
70
+ return c.json(unavailable, 503);
71
+ let body;
72
+ try {
73
+ body = await c.req.json();
74
+ }
75
+ catch {
76
+ return c.json({ error: "Invalid run request" }, 400);
77
+ }
78
+ const parsed = RunRequestZ.safeParse(body);
79
+ if (!parsed.success)
80
+ return c.json({ error: "Invalid run request" }, 400);
81
+ const { code, ...runOptions } = parsed.data;
82
+ return c.json({ result: await options.backend.run(code, runOptions) });
83
+ });
84
+ }
@@ -58,6 +58,8 @@ import { FilesAuthority } from "./resources/workspace-files-authority.js";
58
58
  import { ChangesAuthority } from "./resources/workspace-changes-authority.js";
59
59
  import { loadApplicationShellAppWindows } from "../lib/application-shell-app-windows.js";
60
60
  import { daemonActionCommandRegistry } from "./actions/command-definitions.js";
61
+ import { mountPluginRoutes } from "./plugin-routes.js";
62
+ import { mountCommandCatalogRoutes } from "./command-catalog-routes.js";
61
63
  import { MissionRepository } from "../lib/mission-repository.js";
62
64
  import { projectDesktopMissionWorkspace } from "./resources/desktop-missions.js";
63
65
  import { mountTerminalAttachmentIssueRoute, } from "./terminal-attachment-issue.js";
@@ -239,6 +241,8 @@ function matchLogChannel(channel) {
239
241
  return (entry) => entry.component.startsWith("hq") || entry.component.startsWith("remote");
240
242
  case "watchdog":
241
243
  return (entry) => entry.component.startsWith("watchdog");
244
+ case "plugins":
245
+ return (entry) => entry.component.startsWith("plugin.");
242
246
  default:
243
247
  return null;
244
248
  }
@@ -375,6 +379,15 @@ export function createApp(options = {}) {
375
379
  daemon: daemonInstanceIdentity,
376
380
  ownerToken: options.remoteAccess?.ownerToken ?? null,
377
381
  });
382
+ mountPluginRoutes(app, {
383
+ ownerToken: options.remoteAccess?.ownerToken ?? null,
384
+ backend: options.pluginBackend ?? null,
385
+ });
386
+ mountCommandCatalogRoutes(app, {
387
+ ownerToken: options.remoteAccess?.ownerToken ?? null,
388
+ builtins: () => daemonActionCommandRegistry.descriptors(),
389
+ backend: options.pluginBackend ?? null,
390
+ });
378
391
  // --- Auth routes (always available, bypassed by middleware) ---
379
392
  app.post("/api/auth/challenge", async (c) => {
380
393
  const body = await c.req.json();
@@ -0,0 +1,41 @@
1
+ import { PaneReaderAssetRequestSchemaZ, PaneReaderRequestSchemaZ, TmuxServerScopeSchemaZ, } from "@tmux-ide/contracts";
2
+ import { TmuxServerScopeError } from "../lib/tmux-server-owners.js";
3
+ /**
4
+ * The native Markdown reader's routes (card #756). Mount only below the
5
+ * owner-authenticated, no-store scoped router. Responses never carry a path,
6
+ * a file-system error or validation detail.
7
+ */
8
+ export function mountTmuxServerReaderRoutes(app, options) {
9
+ const handle = (schema, kind) => async (c) => {
10
+ const scope = TmuxServerScopeSchemaZ.safeParse({
11
+ serverId: c.req.param("serverId"),
12
+ generation: c.req.param("generation"),
13
+ });
14
+ if (!scope.success)
15
+ return c.json({ error: { code: "invalid-request" } }, 400);
16
+ let request;
17
+ try {
18
+ request = schema.parse(await options.readBody(c.req.raw));
19
+ }
20
+ catch {
21
+ return c.json({ error: { code: "invalid-request" } }, 400);
22
+ }
23
+ if (request.target.generation !== scope.data.generation)
24
+ return c.json({ error: { code: "stale-generation" } }, 409);
25
+ try {
26
+ c.req.raw.signal.throwIfAborted();
27
+ const response = await options.owners.withOwner(scope.data, (owner) => kind === "read"
28
+ ? owner.paneReader.read(request, c.req.raw.signal)
29
+ : owner.paneReader.asset(request, c.req.raw.signal));
30
+ c.req.raw.signal.throwIfAborted();
31
+ return c.json(response);
32
+ }
33
+ catch (error) {
34
+ if (error instanceof TmuxServerScopeError)
35
+ return c.json({ error: { code: "scope-unavailable" } }, error.code === "not-found" ? 404 : 409);
36
+ return c.json({ error: { code: "reader-unavailable" } }, 503);
37
+ }
38
+ };
39
+ app.post(`${options.scopedPath}/reader`, handle(PaneReaderRequestSchemaZ, "read"));
40
+ app.post(`${options.scopedPath}/reader/asset`, handle(PaneReaderAssetRequestSchemaZ, "asset"));
41
+ }
@@ -5,6 +5,7 @@ import { WindowSplitLayoutUnavailable } from "../terminal/mirror/window-split-au
5
5
  import { streamTmuxInteractions } from "./tmux-server-interaction-events.js";
6
6
  import { mountTmuxServerNativeBackingRoute } from "./tmux-server-native-backing.js";
7
7
  import { mountTmuxServerEditorContextRoute } from "./tmux-server-editor-context.js";
8
+ import { mountTmuxServerReaderRoutes } from "./tmux-server-reader.js";
8
9
  import { Hono } from "hono";
9
10
  import { streamSSE } from "hono/streaming";
10
11
  import { projectApplicationShellResource } from "./resources/application-shell.js";
@@ -111,6 +112,11 @@ export function mountTmuxServerRoutes(app, options) {
111
112
  owners: options.owners,
112
113
  readBody: (request) => boundedJson(request, 8 * 1024),
113
114
  });
115
+ mountTmuxServerReaderRoutes(app, {
116
+ scopedPath: scoped,
117
+ owners: options.owners,
118
+ readBody: (request) => boundedJson(request, 8 * 1024),
119
+ });
114
120
  app.post(`${scoped}/native-browser`, route(async (c) => {
115
121
  const server = scope(c);
116
122
  const input = await boundedJson(c.req.raw, 24 * 1024);
@@ -2,10 +2,13 @@ import { requireSupportedTmuxVersion } from "./lib/tmux-version.js";
2
2
  import { resolveTmuxExecutable } from "./lib/tmux-client-execution.js";
3
3
  import { TMUX_SOCKET_PATH_ENV } from "./lib/runtime-namespace.js";
4
4
  import { execSync, execFileSync } from "node:child_process";
5
- import { accessSync, constants, existsSync, mkdtempSync, rmSync } from "node:fs";
5
+ import { accessSync, constants, existsSync, mkdtempSync, realpathSync, rmSync } from "node:fs";
6
6
  import { tmpdir } from "node:os";
7
- import { resolve, dirname, join } from "node:path";
8
- import { nativeSplitCapability } from "./terminal/protocol/native-split-resize.js";
7
+ import { delimiter, resolve, dirname, join } from "node:path";
8
+ import { resolveBundledTmux } from "./lib/bundled-tmux.js";
9
+ import { readSnapshot } from "./tui/chrome/snapshot.js";
10
+ import { isListableSession } from "./tui/team/sessions.js";
11
+ import { nativeCommands } from "./lib/tmux-server-features.js";
9
12
  import { fileURLToPath } from "node:url";
10
13
  import { getCurrentVersion, getUpdateStatus } from "./lib/update-check.js";
11
14
  import { installedSkillVersion } from "./lib/skill-sync.js";
@@ -152,53 +155,21 @@ function check(label, fn, { optional = false } = {}) {
152
155
  return { label, pass: false, detail: e.message, optional };
153
156
  }
154
157
  }
155
- const UNKNOWN = (command) => new RegExp(`^unknown command: ${command}$`, "mu");
156
- /** The same reading of the server as the mirror's: the stock resize when it refuses
157
- * the split command by name, and full only with the split capability it requires. */
158
- function nativeCommands(probe) {
159
- const ask = (command) => {
160
- try {
161
- return { output: probe([command, "-V"]) };
162
- }
163
- catch (error) {
164
- const failure = error;
165
- return { failure: String(failure.stderr ?? failure.message ?? "") };
166
- }
167
- };
168
- const split = ask("tmux-ide-resize-split");
169
- const events = ask("tmux-ide-events");
170
- const failures = [split.failure, events.failure].filter((text) => text !== undefined);
171
- if (failures.some((text) => /no server running|error connecting/u.test(text)))
172
- return "no-server";
173
- const refused = (answer, command) => answer.failure !== undefined && UNKNOWN(command).test(answer.failure);
174
- if (refused(split, "tmux-ide-resize-split")) {
175
- if (refused(events, "tmux-ide-events"))
176
- return "stock";
177
- // The journal answers: a tmux-ide tmux built before the split command.
178
- if (events.output !== undefined)
179
- return "older";
180
- return "unknown";
181
- }
182
- if (split.output !== undefined && events.output !== undefined) {
183
- try {
184
- return nativeSplitCapability(split.output) ? "full" : "partial";
185
- }
186
- catch {
187
- return "partial";
188
- }
189
- }
190
- return failures.length === 2 ? "unknown" : "partial";
191
- }
192
158
  /** Reads the server a session would use. With none running, a throwaway private
193
159
  * server shows what the resolved binary would start. */
194
160
  export function tmuxFeaturesRow(probeServer, probeBinary) {
195
161
  let answer = nativeCommands(probeServer);
196
- if (answer === "no-server")
162
+ const running = answer !== "no-server";
163
+ if (!running)
197
164
  answer = nativeCommands(probeBinary);
165
+ // Only a running server can be moved; the command restarts it and restores its sessions.
166
+ const upgrade = running
167
+ ? "; run `tmux-ide servers upgrade` to move it to tmux-ide's own tmux"
168
+ : "";
198
169
  const details = {
199
170
  full: "bundled tmux: full features",
200
- stock: "stock tmux: reduced features",
201
- older: "older tmux-ide tmux: reduced features (restart it with tmux-ide's own tmux for every feature; that ends its sessions)",
171
+ stock: `stock tmux: reduced features${upgrade}`,
172
+ older: `older tmux-ide tmux: reduced features${upgrade}`,
202
173
  partial: "this tmux has only some tmux-ide commands: no pane dividers",
203
174
  "no-server": "could not read the tmux server's features",
204
175
  unknown: "could not read the tmux server's features",
@@ -210,6 +181,96 @@ export function tmuxFeaturesRow(probeServer, probeBinary) {
210
181
  optional: true,
211
182
  };
212
183
  }
184
+ /**
185
+ * PURE — what a plain `tmux` typed in a shell runs. Informational: when it is
186
+ * not tmux-ide's own tmux and it starts the server, features drop (#766).
187
+ */
188
+ export function plainTmuxRow(pathTmux, bundled) {
189
+ const label = "plain `tmux` in your shell";
190
+ if (!pathTmux)
191
+ return {
192
+ label,
193
+ pass: true,
194
+ detail: "not on PATH (tmux-ide uses its own tmux)",
195
+ optional: true,
196
+ };
197
+ if (bundled && pathTmux === bundled)
198
+ return { label, pass: true, detail: `tmux-ide's own tmux (${pathTmux})`, optional: true };
199
+ return {
200
+ label,
201
+ pass: true,
202
+ detail: `${pathTmux}; if it starts the server, features drop (see docs: tmux upgrade)`,
203
+ optional: true,
204
+ };
205
+ }
206
+ const DAY_MS = 24 * 60 * 60 * 1000;
207
+ /**
208
+ * PURE — is the crash snapshot fresh enough to restore from? It fails when it
209
+ * is missing a live session, or is over a day old while sessions run. Only the
210
+ * chrome updater writes it, and that runs only while a session is adopted.
211
+ */
212
+ export function snapshotRow(snapshot, liveSessions, nowMs) {
213
+ const label = "crash snapshot (restore)";
214
+ const hint = "Only the chrome updater writes it, while a session is adopted: `tmux-ide adopt --all` starts it";
215
+ if (!snapshot) {
216
+ return liveSessions?.length
217
+ ? { label, pass: false, detail: `none yet. ${hint}`, optional: true }
218
+ : { label, pass: true, detail: "none yet (no sessions running)", optional: true };
219
+ }
220
+ const ageMs = nowMs - Date.parse(snapshot.savedAt);
221
+ const age = ageMs >= DAY_MS
222
+ ? `${Math.floor(ageMs / DAY_MS)} days old`
223
+ : `${Math.max(0, Math.round(ageMs / 60_000))} min old`;
224
+ const saved = new Set(snapshot.sessions.map((session) => session.name));
225
+ const missing = (liveSessions ?? []).filter((name) => !saved.has(name));
226
+ if (missing.length)
227
+ return {
228
+ label,
229
+ pass: false,
230
+ detail: `${age}; misses ${missing.length} running session${missing.length === 1 ? "" : "s"} (${missing.slice(0, 5).join(", ")}${missing.length > 5 ? ", …" : ""}). ${hint}`,
231
+ optional: true,
232
+ };
233
+ return { label, pass: true, detail: `${age}, covers every running session`, optional: true };
234
+ }
235
+ function firstOnPath(name) {
236
+ for (const directory of (process.env.PATH ?? "").split(delimiter)) {
237
+ if (!directory)
238
+ continue;
239
+ const candidate = join(directory, name);
240
+ try {
241
+ accessSync(candidate, constants.X_OK);
242
+ return realpathSync(candidate);
243
+ }
244
+ catch {
245
+ // Try the next PATH entry.
246
+ }
247
+ }
248
+ return null;
249
+ }
250
+ function safeBundledTmux() {
251
+ try {
252
+ const bundled = resolveBundledTmux();
253
+ return bundled ? realpathSync(bundled) : null;
254
+ }
255
+ catch {
256
+ return null;
257
+ }
258
+ }
259
+ /** The sessions the snapshot should hold, on the server doctor reads; null when unreadable. */
260
+ function liveListableSessions() {
261
+ try {
262
+ const socketPath = process.env[TMUX_SOCKET_PATH_ENV];
263
+ const socketName = process.env.TMUX_IDE_TMUX_SOCKET_NAME;
264
+ const server = socketPath ? ["-S", socketPath] : socketName ? ["-L", socketName] : [];
265
+ return execFileSync(resolveTmuxExecutable(), [...server, "list-sessions", "-F", "#{session_name}"], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 3000 })
266
+ .split("\n")
267
+ .filter((name) => name && isListableSession(name));
268
+ }
269
+ catch (error) {
270
+ const text = String(error.stderr ?? "");
271
+ return /no server running|error connecting/u.test(text) ? [] : null;
272
+ }
273
+ }
213
274
  function runTmuxFeatureProbes(executable) {
214
275
  const run = (prefix) => (args) => execFileSync(executable, [...prefix, ...args], {
215
276
  encoding: "utf8",
@@ -296,6 +357,8 @@ export async function doctor({ json, } = {}) {
296
357
  catch {
297
358
  // The tmux version row above already reports a missing executable.
298
359
  }
360
+ checks.push(plainTmuxRow(firstOnPath("tmux"), safeBundledTmux()));
361
+ checks.push(snapshotRow(readSnapshot(), liveListableSessions(), Date.now()));
299
362
  checks.push(nodeVersionRow(process.versions.node));
300
363
  checks.push(check("256-color terminal", () => {
301
364
  const term = process.env.TERM ?? "";
@@ -194,3 +194,18 @@ export async function tryDispatchAction(name, input, options = {}) {
194
194
  }
195
195
  return null;
196
196
  }
197
+ /**
198
+ * The running canonical daemon's base URL and owner token, for CLI commands
199
+ * that call daemon routes other than the action dispatcher.
200
+ */
201
+ export async function resolveCanonicalDaemonEndpoint(options = {}) {
202
+ const bridgeDeps = deps;
203
+ return resolveCanonicalDaemon(bridgeDeps, {
204
+ autostart: options.autostart ?? true,
205
+ cwd: options.cwd ?? bridgeDeps.cwd(),
206
+ });
207
+ }
208
+ /** `fetch`, replaceable in tests through {@link __setCliActionBridgeDepsForTests}. */
209
+ export function cliBridgeFetch() {
210
+ return deps.fetch;
211
+ }
@@ -0,0 +1,13 @@
1
+ import { basename, dirname, extname, join } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ /**
4
+ * The argv prefix that runs this tmux-ide's CLI: the bundled `bin/cli.js`,
5
+ * or `bin/cli.ts` under the runtime's loader flags when run from source.
6
+ * `here` must sit two directories below `packages/daemon/src`'s parent.
7
+ */
8
+ export function resolveCliCommand(here = fileURLToPath(import.meta.url), runtime = process) {
9
+ if (basename(here) === "cli.js")
10
+ return [runtime.execPath, here];
11
+ const cli = join(dirname(here), "..", "..", "..", "..", "bin", `cli${extname(here)}`);
12
+ return [runtime.execPath, ...runtime.execArgv, cli];
13
+ }
@@ -6,6 +6,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
6
6
  }
7
7
  return path;
8
8
  };
9
+ import { createPaneReaderResolver } from "./tmux-pane-reader.js";
9
10
  import { createNativeBrowserResolver } from "./tmux-native-browser.js";
10
11
  import { createNativeSurfaceContextResolver } from "./native-surface-context.js";
11
12
  import { NativeSurfaceProviderRegistry } from "../terminal/graphics/native-surface-provider.js";
@@ -95,6 +96,7 @@ import { setActivationBackend } from "./active-projects.js";
95
96
  import { readOrMintEnvironmentId } from "./environment-identity.js";
96
97
  import { captureDaemonProvenance } from "./daemon-provenance.js";
97
98
  import { registerLogSecret, setLogIdentity } from "./log.js";
99
+ import { createDaemonPluginSupervisor, pluginsEnabled } from "../plugins/daemon-plugins.js";
98
100
  import { canonicalDaemonUrl, getCanonicalDaemonInfoPath, clearCanonicalDaemonInfoIfOwned, clearCanonicalDaemonInfoIfUnchanged, inspectCanonicalDaemonInfo, isCanonicalDaemonAlive, isCanonicalDaemonRecordOwnerProvenDead, probeCanonicalDaemonHealth, probeCanonicalDaemonIdentity, releaseCanonicalDaemonClaim, tryAcquireCanonicalDaemonClaim, writeCanonicalDaemonInfo, matchesCanonicalDaemonPredecessor, } from "./canonical-daemon.js";
99
101
  const requireFromHere = createRequire(import.meta.url);
100
102
  const DEFAULT_HOSTNAME = "127.0.0.1";
@@ -502,7 +504,7 @@ function closeWsGoingAway(ws) {
502
504
  }
503
505
  ws.close(1001, reason);
504
506
  }
505
- async function startHttpServer({ sessionName, requestedPort, bindHostname, dir, authToken, localBypassToken, silent, readProjectAuth, tmuxServerProof, daemonIdentity, workspacePaneCreationBackend, workspaceOpenBackend, workspaceOpenHandoffBackend, fleetLifecycleBackend, workspacePromotionBackend, appWindowMutationBackend, workspaceMultiplexerBackend, workspaceRegistry, terminalInventoryRuntime, getTerminalAttachmentRuntime, peekTerminalAttachmentRuntime, paneStreamRuntime, catalogLiveSessions, catalogFleet, fleetPreviewCapture, sessionRuntimeRegistry, serverOwners, }) {
507
+ async function startHttpServer({ sessionName, requestedPort, bindHostname, dir, authToken, localBypassToken, silent, readProjectAuth, tmuxServerProof, daemonIdentity, workspacePaneCreationBackend, workspaceOpenBackend, workspaceOpenHandoffBackend, fleetLifecycleBackend, workspacePromotionBackend, appWindowMutationBackend, workspaceMultiplexerBackend, workspaceRegistry, terminalInventoryRuntime, getTerminalAttachmentRuntime, peekTerminalAttachmentRuntime, paneStreamRuntime, catalogLiveSessions, catalogFleet, fleetPreviewCapture, sessionRuntimeRegistry, serverOwners, pluginBackend, }) {
506
508
  const { createApp } = await import("../command-center/server.js");
507
509
  const { getRequestListener } = await import(__rewriteRelativeImportExtension(requireFromHere.resolve("@hono/node-server"), true));
508
510
  const { AuthService } = await import("./auth/auth-service.js");
@@ -555,6 +557,7 @@ async function startHttpServer({ sessionName, requestedPort, bindHostname, dir,
555
557
  catalogLiveSessions,
556
558
  catalogFleet,
557
559
  fleetPreviewCapture,
560
+ pluginBackend,
558
561
  });
559
562
  mountTerminalNativeBackingRoute(app, {
560
563
  ownerToken: localBypassToken ?? null,
@@ -1000,6 +1003,19 @@ async function startEmbeddedDaemonGeneration(opts) {
1000
1003
  setFleetFactsObserverDiagnostics(null);
1001
1004
  await runtimeTraceWriter?.close(incomplete);
1002
1005
  };
1006
+ // Plugins reach the daemon's own routes over loopback with the owner token.
1007
+ const pluginEndpoint = canonicalDaemonUrl("http", bindHostname === "0.0.0.0" || bindHostname === "::" ? "127.0.0.1" : bindHostname, port);
1008
+ // Created now so its routes mount with the server; it spawns nothing until
1009
+ // start(), which runs once this generation is published.
1010
+ const pluginSupervisor = opts.plugins && pluginsEnabled()
1011
+ ? createDaemonPluginSupervisor({
1012
+ productVersion,
1013
+ secrets: [localBypassToken, authToken ?? null],
1014
+ endpoint: () => pluginEndpoint ? { baseUrl: pluginEndpoint, ownerToken: localBypassToken } : null,
1015
+ tmux: (args) => fleetFactsTmuxRunner(args, AbortSignal.timeout(5000)),
1016
+ onCatalogChange: () => broadcastResourceChanged({ workspaceName: null, resource: "command-catalog" }, instanceId),
1017
+ })
1018
+ : null;
1003
1019
  let startedServer;
1004
1020
  try {
1005
1021
  const selector = tmuxAuthority.socketSelector;
@@ -1416,6 +1432,20 @@ async function startEmbeddedDaemonGeneration(opts) {
1416
1432
  throw new Error("Default native browser owner is unavailable");
1417
1433
  },
1418
1434
  }),
1435
+ paneReader: createPaneReaderResolver({
1436
+ generation: instanceId,
1437
+ run: fleetFactsTmuxRunner,
1438
+ registry: workspaceRegistry,
1439
+ catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner),
1440
+ inventory: terminalInventoryRuntime,
1441
+ assertOpen: () => {
1442
+ if (defaultEditorContextRetired ||
1443
+ serverOwners?.defaultRetired ||
1444
+ !initialNativeServerIdentity ||
1445
+ terminalInventoryRuntime?.lifecycleState() !== "ready")
1446
+ throw new Error("Default reader owner is unavailable");
1447
+ },
1448
+ }),
1419
1449
  catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner),
1420
1450
  readWindowSplitLayout: async (workspaceName, input) => {
1421
1451
  const target = WindowLinkTargetSchemaZ.parse(input);
@@ -1516,6 +1546,7 @@ async function startEmbeddedDaemonGeneration(opts) {
1516
1546
  setFleetFactsTmuxRunner(fleetFactsTmuxRunner);
1517
1547
  startedServer = await startHttpServer({
1518
1548
  serverOwners,
1549
+ pluginBackend: pluginSupervisor,
1519
1550
  sessionName,
1520
1551
  requestedPort: port,
1521
1552
  bindHostname,
@@ -1623,6 +1654,7 @@ async function startEmbeddedDaemonGeneration(opts) {
1623
1654
  return [...transportResults, ...runtimeResults].flatMap((result) => result.status === "rejected" ? [result.reason] : []);
1624
1655
  };
1625
1656
  const abortStartedServer = async () => {
1657
+ await pluginSupervisor?.stop().catch(() => { });
1626
1658
  await serverOwners?.dispose();
1627
1659
  setFleetFactsTmuxRunner(null);
1628
1660
  const terminalFailures = [
@@ -1708,6 +1740,11 @@ async function startEmbeddedDaemonGeneration(opts) {
1708
1740
  await abortStartedServer();
1709
1741
  throw error;
1710
1742
  }
1743
+ // Plugins load after publication, in the background: a slow or broken
1744
+ // plugin never delays or fails daemon startup.
1745
+ void pluginSupervisor?.start().catch((error) => {
1746
+ console.warn(`[daemon] plugins failed to start: ${error.message}`);
1747
+ });
1711
1748
  let stopped = false;
1712
1749
  let stopping = null;
1713
1750
  let stopSelf = null;
@@ -1872,6 +1909,7 @@ async function startEmbeddedDaemonGeneration(opts) {
1872
1909
  };
1873
1910
  try {
1874
1911
  stopped = true;
1912
+ await capture(() => pluginSupervisor?.stop());
1875
1913
  await capture(() => setActivationBackend(null));
1876
1914
  await capture(() => sessionMonitor?.stop());
1877
1915
  paneSourceCredentials.dispose();
@@ -241,6 +241,7 @@ async function runHeadlessDaemonGeneration(options, deps, restoreTmuxWorkspaces,
241
241
  try {
242
242
  handle = await deps.startEmbeddedDaemon({
243
243
  launcher: "headless",
244
+ plugins: true,
244
245
  ...(options.supervisionId
245
246
  ? { supervisionId: options.supervisionId, predecessor: lifecycle.predecessor }
246
247
  : {}),