tmux-ide 2.9.25 → 2.9.27
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.
- package/README.md +1 -1
- package/bin/cli.js +1577 -559
- package/package.json +3 -2
- package/packages/contracts/src/pane-stream.ts +28 -0
- package/packages/contracts/src/terminal-delivery.ts +122 -5
- package/packages/contracts/src/terminal-runtime-inventory.ts +61 -1
- package/packages/contracts/src/tmux-server-scope.ts +18 -0
- package/packages/core/src/index.ts +1 -0
- package/packages/core/src/terminal-delivery-binary.ts +8 -7
- package/packages/core/src/terminal-delivery.ts +174 -3
- package/packages/core/src/terminal-partial-history.ts +152 -0
- package/packages/core/src/terminal-replica.ts +70 -1
- package/packages/daemon/dist/command-center/owner-keep-alive.js +30 -0
- package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +42 -2
- package/packages/daemon/dist/command-center/server.js +3 -0
- package/packages/daemon/dist/command-center/tmux-server-attach.js +51 -0
- package/packages/daemon/dist/command-center/tmux-servers.js +95 -7
- package/packages/daemon/dist/doctor.js +4 -4
- package/packages/daemon/dist/lib/app-config.js +7 -0
- package/packages/daemon/dist/lib/node-requirement.js +20 -0
- package/packages/daemon/dist/lib/require-supported-node.js +8 -0
- package/packages/daemon/dist/lib/tmux-server-owner.js +4 -2
- package/packages/daemon/dist/lib/tmux-server-session-open.js +38 -12
- package/packages/daemon/dist/lib/workspace-promotion.js +4 -4
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
- package/packages/daemon/dist/server/pane-stream-upgrade.js +39 -1
- package/packages/daemon/dist/terminal/mirror/session-channel.js +6 -1
- package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +1 -0
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +112 -22
- package/packages/daemon/dist/terminal/protocol/browser-icon.js +1 -1
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +26 -3
- package/packages/daemon/dist/terminal/session-runtime/registry.js +2 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.js +571 -33
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +2 -0
- package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +51 -4
- package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +76 -2
- package/packages/daemon/dist/tui/mirror/theme.js +8 -1
- package/packages/daemon/src/command-center/attach-window-rule.cases.json +84 -0
- package/packages/daemon/src/command-center/owner-keep-alive.ts +38 -0
- package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +48 -1
- package/packages/daemon/src/command-center/server.ts +3 -0
- package/packages/daemon/src/command-center/tmux-server-attach.ts +75 -0
- package/packages/daemon/src/command-center/tmux-servers.ts +103 -6
- package/packages/daemon/src/doctor.ts +4 -4
- package/packages/daemon/src/lib/app-config.ts +15 -0
- package/packages/daemon/src/lib/node-requirement.ts +22 -0
- package/packages/daemon/src/lib/require-supported-node.ts +9 -0
- package/packages/daemon/src/lib/tmux-server-owner.ts +6 -3
- package/packages/daemon/src/lib/tmux-server-session-open.ts +53 -15
- package/packages/daemon/src/lib/workspace-promotion.ts +4 -4
- package/packages/daemon/src/server/pane-stream-upgrade.ts +41 -1
- package/packages/daemon/src/terminal/mirror/events.ts +2 -0
- package/packages/daemon/src/terminal/mirror/session-channel.ts +8 -1
- package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +3 -0
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +136 -20
- package/packages/daemon/src/terminal/protocol/browser-icon.ts +1 -1
- package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +32 -2
- package/packages/daemon/src/terminal/session-runtime/registry.ts +2 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-delivery-hub.ts +696 -30
- package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +6 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +2 -0
- package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +67 -3
- package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +82 -2
- package/packages/daemon/src/tui/mirror/theme.ts +13 -1
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
TmuxServersResourceSchemaZ,
|
|
25
25
|
TmuxServerSessionsResourceSchemaZ,
|
|
26
26
|
TmuxServerSessionsResourceV2SchemaZ,
|
|
27
|
+
TmuxServerSessionsResourceV3SchemaZ,
|
|
27
28
|
WorkspaceMultiplexerMutationRequestSchemaZ,
|
|
28
29
|
WorkspacePaneCreateMutationRequestSchemaZ,
|
|
29
30
|
WorkspaceSessionCreateArgumentsSchemaZ,
|
|
@@ -40,7 +41,11 @@ import { WorkspacePaneCreationError } from "../lib/workspace-pane-creation.ts";
|
|
|
40
41
|
import { ownerBearerMatches } from "./owner-authority.ts";
|
|
41
42
|
import { logger } from "../lib/log.ts";
|
|
42
43
|
import { mountPaneStreamIssueRoute } from "./pane-stream-issue.ts";
|
|
43
|
-
import {
|
|
44
|
+
import { chooseAttachSelection, TmuxServerAttachRequestSchemaZ } from "./tmux-server-attach.ts";
|
|
45
|
+
import {
|
|
46
|
+
projectTerminalRuntimeInventory,
|
|
47
|
+
projectTerminalRuntimeInventoryV2,
|
|
48
|
+
} from "./resources/terminal-runtime-inventory.ts";
|
|
44
49
|
|
|
45
50
|
export interface TmuxServerRoutesOptions {
|
|
46
51
|
readonly ownerToken: string | null;
|
|
@@ -291,11 +296,96 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
|
|
|
291
296
|
return c.json({ version: 1, server, ...result });
|
|
292
297
|
}),
|
|
293
298
|
);
|
|
299
|
+
// attach-rtt: open, inventory and issue in one round trip. The stream is
|
|
300
|
+
// issued through the ordinary issue route with this request's headers, so
|
|
301
|
+
// it is checked exactly as a separate issue request would be.
|
|
302
|
+
app.post(
|
|
303
|
+
`${scoped}/sessions/:liveSessionId/attach`,
|
|
304
|
+
route(async (c) => {
|
|
305
|
+
const server = scope(c);
|
|
306
|
+
const liveSessionId = workspaceSchema.parse(c.req.param("liveSessionId"));
|
|
307
|
+
const request = TmuxServerAttachRequestSchemaZ.parse(await boundedJson(c.req.raw));
|
|
308
|
+
// The issue below checks the same, but only after the open: refuse a
|
|
309
|
+
// request for another generation before it can promote anything.
|
|
310
|
+
if (
|
|
311
|
+
request.issue.expectedDaemonInstanceId !== server.generation ||
|
|
312
|
+
c.req.header("X-Tmux-Ide-Expected-Daemon-Instance-Id") !== server.generation
|
|
313
|
+
)
|
|
314
|
+
throw new TmuxServerScopeError("stale-generation");
|
|
315
|
+
const result = await options.owners.withOwner(server, async (owner) => {
|
|
316
|
+
const opened = await owner.openSession(liveSessionId);
|
|
317
|
+
const workspace = owner.workspaceRegistry.get(opened.workspaceName);
|
|
318
|
+
if (!workspace || opened.liveSessionId !== liveSessionId)
|
|
319
|
+
throw new TmuxServerScopeError("stale-generation");
|
|
320
|
+
const snapshot = await owner.terminalInventoryRuntime.discoverTerminalRuntimeSession(
|
|
321
|
+
workspace.sessionName,
|
|
322
|
+
c.req.raw.signal,
|
|
323
|
+
);
|
|
324
|
+
if (!snapshot) return null;
|
|
325
|
+
const inventory = projectTerminalRuntimeInventoryV2(snapshot, 0);
|
|
326
|
+
const selection = chooseAttachSelection(inventory, request.preferredPane, request.maxPanes);
|
|
327
|
+
if (!selection)
|
|
328
|
+
return { kind: "attached" as const, opened, inventory, selection, issue: null };
|
|
329
|
+
// The window is the daemon's to choose, never the client's.
|
|
330
|
+
const stream = { ...request.issue.stream };
|
|
331
|
+
delete stream.semanticWindowId;
|
|
332
|
+
const body = {
|
|
333
|
+
...request.issue,
|
|
334
|
+
stream: {
|
|
335
|
+
...stream,
|
|
336
|
+
workspaceName: opened.workspaceName,
|
|
337
|
+
panes: selection.panes,
|
|
338
|
+
...(selection.semanticWindowId ? { semanticWindowId: selection.semanticWindowId } : {}),
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
const issueApp = new Hono();
|
|
342
|
+
mountPaneStreamIssueRoute(issueApp, {
|
|
343
|
+
daemonInstanceId: server.generation,
|
|
344
|
+
ownerToken: options.ownerToken,
|
|
345
|
+
workspaceRegistry: owner.workspaceRegistry,
|
|
346
|
+
backend: owner.paneStreamRuntime.coordinator,
|
|
347
|
+
});
|
|
348
|
+
const url = new URL(c.req.url);
|
|
349
|
+
url.pathname = PANE_STREAM_ISSUE_PATH;
|
|
350
|
+
url.search = "";
|
|
351
|
+
const headers = new Headers(c.req.raw.headers);
|
|
352
|
+
headers.delete("Content-Length");
|
|
353
|
+
headers.set("Content-Type", "application/json");
|
|
354
|
+
const issued = await issueApp.request(
|
|
355
|
+
new Request(url, { method: "POST", headers, body: JSON.stringify(body) }),
|
|
356
|
+
);
|
|
357
|
+
// The issue route answers a refused issue as 200 with an error
|
|
358
|
+
// envelope, which goes back in `issue` with the open and inventory
|
|
359
|
+
// (the app then issues again). A non-200 is an auth or body refusal.
|
|
360
|
+
if (issued.status !== 200) return { kind: "refused" as const, refused: issued };
|
|
361
|
+
return {
|
|
362
|
+
kind: "attached" as const,
|
|
363
|
+
opened,
|
|
364
|
+
inventory,
|
|
365
|
+
selection,
|
|
366
|
+
issue: (await issued.json()) as unknown,
|
|
367
|
+
};
|
|
368
|
+
});
|
|
369
|
+
if (!result) return c.json({ error: { code: "workspace-not-found" } }, 404);
|
|
370
|
+
if (result.kind === "refused") return result.refused;
|
|
371
|
+
return c.json({
|
|
372
|
+
version: 1,
|
|
373
|
+
server,
|
|
374
|
+
workspaceName: result.opened.workspaceName,
|
|
375
|
+
liveSessionId,
|
|
376
|
+
inventory: result.inventory,
|
|
377
|
+
selection: result.selection,
|
|
378
|
+
issue: result.issue,
|
|
379
|
+
});
|
|
380
|
+
}),
|
|
381
|
+
);
|
|
294
382
|
app.get(
|
|
295
383
|
`${scoped}/sessions`,
|
|
296
384
|
route(async (c) => {
|
|
297
385
|
const server = scope(c);
|
|
298
|
-
|
|
386
|
+
// #806: version 3 is version 2 plus the largest window's pane count.
|
|
387
|
+
const v3 = c.req.query("version") === "3";
|
|
388
|
+
const v2 = v3 || c.req.query("version") === "2";
|
|
299
389
|
const { rows, favicons } = await options.owners.withOwner(server, async (owner) => {
|
|
300
390
|
const sessions = await owner.catalog();
|
|
301
391
|
const workspaces = owner.workspaceRegistry.list();
|
|
@@ -328,9 +418,10 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
|
|
|
328
418
|
}),
|
|
329
419
|
);
|
|
330
420
|
let budget = SESSIONS_RESOURCE_FAVICON_BUDGET_BYTES;
|
|
421
|
+
const schema = v3 ? TmuxServerSessionsResourceV3SchemaZ : TmuxServerSessionsResourceV2SchemaZ;
|
|
331
422
|
return c.json(
|
|
332
|
-
|
|
333
|
-
version: 2,
|
|
423
|
+
schema.parse({
|
|
424
|
+
version: v3 ? 3 : 2,
|
|
334
425
|
server,
|
|
335
426
|
sessions: rows.map(({ session, workspaceName }, index) => {
|
|
336
427
|
const found = favicons[index] ?? null;
|
|
@@ -342,6 +433,7 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
|
|
|
342
433
|
workspaceName,
|
|
343
434
|
paneCount: session.paneCount,
|
|
344
435
|
windowCount: session.windowCount,
|
|
436
|
+
...(v3 ? { largestWindowPaneCount: session.largestWindowPaneCount } : {}),
|
|
345
437
|
lastActivity: session.lastActivity,
|
|
346
438
|
favicon: favicon ? { mime: favicon.mime, data: favicon.data } : null,
|
|
347
439
|
};
|
|
@@ -368,6 +460,8 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
|
|
|
368
460
|
route(async (c) => {
|
|
369
461
|
const server = scope(c);
|
|
370
462
|
const workspaceName = workspaceSchema.parse(c.req.param("workspaceName"));
|
|
463
|
+
// #806: version 2 also names each window and its panes.
|
|
464
|
+
const v2 = c.req.query("version") === "2";
|
|
371
465
|
const resource = await options.owners.withOwner(server, async (owner) => {
|
|
372
466
|
const sessions = await owner.catalog();
|
|
373
467
|
const workspace = owner.workspaceRegistry.get(workspaceName);
|
|
@@ -384,10 +478,13 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
|
|
|
384
478
|
workspace.sessionName,
|
|
385
479
|
c.req.raw.signal,
|
|
386
480
|
);
|
|
387
|
-
|
|
481
|
+
if (!snapshot) return null;
|
|
482
|
+
return v2
|
|
483
|
+
? projectTerminalRuntimeInventoryV2(snapshot, 0)
|
|
484
|
+
: projectTerminalRuntimeInventory(snapshot, 0);
|
|
388
485
|
});
|
|
389
486
|
return resource
|
|
390
|
-
? c.json({ version: 1, server, resource })
|
|
487
|
+
? c.json({ version: v2 ? 2 : 1, server, resource })
|
|
391
488
|
: c.json({ error: { code: "workspace-not-found" } }, 404);
|
|
392
489
|
}),
|
|
393
490
|
);
|
|
@@ -17,6 +17,7 @@ import { findCompiledTui, hasDevelopmentTuiSource, isBunAvailable } from "./tui/
|
|
|
17
17
|
import { claudeSettingsPath } from "./tui/integrations/claude.ts";
|
|
18
18
|
import { readNotificationPrefs, resolveNativeMacosNotifierPath } from "./tui/chrome/notify.ts";
|
|
19
19
|
import { resolveConfig } from "./lib/resolved-config.ts";
|
|
20
|
+
import { MINIMUM_NODE_MAJOR, isSupportedNodeVersion } from "./lib/node-requirement.ts";
|
|
20
21
|
import {
|
|
21
22
|
collectDaemonProvenanceReport,
|
|
22
23
|
type DaemonProvenanceReport,
|
|
@@ -436,12 +437,11 @@ export function tmuxServerSocketRow(environment: NodeJS.ProcessEnv, uid: number)
|
|
|
436
437
|
}
|
|
437
438
|
|
|
438
439
|
export function nodeVersionRow(version: string): CheckResult {
|
|
439
|
-
const
|
|
440
|
-
const pass = Number.isInteger(major) && major >= 20;
|
|
440
|
+
const pass = isSupportedNodeVersion(version);
|
|
441
441
|
return {
|
|
442
|
-
label:
|
|
442
|
+
label: `Node.js ≥ ${MINIMUM_NODE_MAJOR}`,
|
|
443
443
|
pass,
|
|
444
|
-
detail: pass ? `v${version}` : `Node ${version} (need ≥
|
|
444
|
+
detail: pass ? `v${version}` : `Node ${version} (need ≥ ${MINIMUM_NODE_MAJOR})`,
|
|
445
445
|
optional: false,
|
|
446
446
|
};
|
|
447
447
|
}
|
|
@@ -89,6 +89,13 @@ export interface AppTheme {
|
|
|
89
89
|
/** Explicit palette mode or terminal-following mode. Defaults to following the terminal. */
|
|
90
90
|
mode: ThemeModeSetting;
|
|
91
91
|
preset?: string;
|
|
92
|
+
/**
|
|
93
|
+
* The presets `mode: "system"` uses when the terminal (or macOS, in the
|
|
94
|
+
* Mac app) is light or dark. Kept only when each names a preset of that
|
|
95
|
+
* appearance; unset, system mode follows the host palette as before.
|
|
96
|
+
*/
|
|
97
|
+
light?: string;
|
|
98
|
+
dark?: string;
|
|
92
99
|
/** Primary/brand accent (default `colour75`). */
|
|
93
100
|
accent: string;
|
|
94
101
|
/** Muted/secondary foreground for dim text (default `colour240`). */
|
|
@@ -368,6 +375,12 @@ function appThemeOverrideProvenance(
|
|
|
368
375
|
* back to its default, so partial and garbage configs both resolve to a complete,
|
|
369
376
|
* well-typed {@link AppConfig}. Never throws.
|
|
370
377
|
*/
|
|
378
|
+
/** `theme.light` / `theme.dark`, when the id names a preset of that appearance. */
|
|
379
|
+
function systemSide(value: unknown, appearance: "light" | "dark"): Partial<AppTheme> {
|
|
380
|
+
const preset = findVisualThemePreset(value);
|
|
381
|
+
return preset?.appearance === appearance ? { [appearance]: preset.id } : {};
|
|
382
|
+
}
|
|
383
|
+
|
|
371
384
|
export function parseAppConfig(input: unknown): AppConfig {
|
|
372
385
|
const D = DEFAULT_APP_CONFIG;
|
|
373
386
|
const root = asObject(input);
|
|
@@ -405,6 +418,8 @@ export function parseAppConfig(input: unknown): AppConfig {
|
|
|
405
418
|
findVisualThemePreset(theme.preset)?.appearance ?? D.theme.mode,
|
|
406
419
|
),
|
|
407
420
|
...(findVisualThemePreset(theme.preset) ? { preset: String(theme.preset) } : {}),
|
|
421
|
+
...systemSide(theme.light, "light"),
|
|
422
|
+
...systemSide(theme.dark, "dark"),
|
|
408
423
|
accent: pickString(theme.accent, D.theme.accent),
|
|
409
424
|
muted: pickString(theme.muted, D.theme.muted),
|
|
410
425
|
fg: pickString(theme.fg, D.theme.fg),
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The oldest Node.js major an npm install of tmux-ide supports (package.json `engines`). */
|
|
2
|
+
export const MINIMUM_NODE_MAJOR = 24;
|
|
3
|
+
|
|
4
|
+
/** True when `version` (as in `process.versions.node`) is new enough. */
|
|
5
|
+
export function isSupportedNodeVersion(version: string): boolean {
|
|
6
|
+
const major = Number(version.split(".")[0]);
|
|
7
|
+
return Number.isInteger(major) && major >= MINIMUM_NODE_MAJOR;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The message the CLI prints before exiting on an unsupported Node.js, or null
|
|
12
|
+
* when the runtime is supported. Bun (dev runs, compiled surfaces) is exempt.
|
|
13
|
+
*/
|
|
14
|
+
export function unsupportedNodeMessage(versions: { node?: string; bun?: string }): string | null {
|
|
15
|
+
if (versions.bun !== undefined || versions.node === undefined) return null;
|
|
16
|
+
if (isSupportedNodeVersion(versions.node)) return null;
|
|
17
|
+
return (
|
|
18
|
+
`tmux-ide needs Node.js ${MINIMUM_NODE_MAJOR} or newer; this is Node.js ${versions.node}.\n` +
|
|
19
|
+
`Upgrade Node.js, or use the installer, which brings its own runtime:\n` +
|
|
20
|
+
` curl -fsSL https://tmux-ide.com/install.sh | sh\n`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Imported first by bin/cli.ts so an unsupported Node.js stops with a clear
|
|
2
|
+
// message before any command code runs.
|
|
3
|
+
import { unsupportedNodeMessage } from "./node-requirement.ts";
|
|
4
|
+
|
|
5
|
+
const message = unsupportedNodeMessage(process.versions);
|
|
6
|
+
if (message !== null) {
|
|
7
|
+
process.stderr.write(message);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
@@ -108,6 +108,8 @@ function discoveredWorkspaceName(registry: WorkspaceRegistry, sessionName: strin
|
|
|
108
108
|
export interface NativeLiveSessionSummary extends LiveSessionSummary {
|
|
109
109
|
/** Distinct tmux windows of the session (at least one). */
|
|
110
110
|
readonly windowCount: number;
|
|
111
|
+
/** Panes of the session's largest window (#806: streams open window by window). */
|
|
112
|
+
readonly largestWindowPaneCount: number;
|
|
111
113
|
/** tmux `#{session_activity}` in epoch seconds, or null when tmux reports none. */
|
|
112
114
|
readonly lastActivity: number | null;
|
|
113
115
|
/** tmux `#{session_path}`, the session's working directory. */
|
|
@@ -159,7 +161,7 @@ export function createNativeTmuxServerCatalog(
|
|
|
159
161
|
{
|
|
160
162
|
summary: LiveSessionSummary;
|
|
161
163
|
panes: Set<string>;
|
|
162
|
-
windows:
|
|
164
|
+
windows: Map<string, number>;
|
|
163
165
|
dir: string;
|
|
164
166
|
activity: number | null;
|
|
165
167
|
}
|
|
@@ -192,12 +194,12 @@ export function createNativeTmuxServerCatalog(
|
|
|
192
194
|
const row = rows.get(liveSessionId) ?? {
|
|
193
195
|
summary: { liveSessionId, sessionName: name, paneCount: 0 },
|
|
194
196
|
panes: new Set<string>(),
|
|
195
|
-
windows: new
|
|
197
|
+
windows: new Map<string, number>(),
|
|
196
198
|
dir,
|
|
197
199
|
activity: activity && /^\d+$/.test(activity) ? Number(activity) : null,
|
|
198
200
|
};
|
|
201
|
+
if (!row.panes.has(pane)) row.windows.set(window, (row.windows.get(window) ?? 0) + 1);
|
|
199
202
|
row.panes.add(pane);
|
|
200
|
-
row.windows.add(window);
|
|
201
203
|
rows.set(liveSessionId, row);
|
|
202
204
|
}
|
|
203
205
|
const names = new Set([...rows.values()].map(({ summary }) => summary.sessionName));
|
|
@@ -218,6 +220,7 @@ export function createNativeTmuxServerCatalog(
|
|
|
218
220
|
...summary,
|
|
219
221
|
paneCount: panes.size,
|
|
220
222
|
windowCount: windows.size,
|
|
223
|
+
largestWindowPaneCount: Math.max(...windows.values()),
|
|
221
224
|
lastActivity: activity,
|
|
222
225
|
sessionPath: dir,
|
|
223
226
|
}));
|
|
@@ -8,7 +8,13 @@ import { WorkspaceCatalogLiveSessionIdSchemaZ } from "@tmux-ide/contracts";
|
|
|
8
8
|
import { liveSessionIdForNativeIdentity } from "../terminal/protocol/live-session-identity.ts";
|
|
9
9
|
import { fleetSessionIdForName } from "../command-center/resources/fleet-catalog.ts";
|
|
10
10
|
import { isVisibleFleetSession } from "../command-center/discovery.ts";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
ADOPTED_OPTION,
|
|
13
|
+
hasValidPaneStamp,
|
|
14
|
+
SEMANTIC_PANE_OPTION,
|
|
15
|
+
SEMANTIC_WINDOW_OPTION,
|
|
16
|
+
WorkspacePromotionAuthority,
|
|
17
|
+
} from "./workspace-promotion.ts";
|
|
12
18
|
import type { WorkspaceRegistry } from "./workspace-registry.ts";
|
|
13
19
|
import { shellEscape } from "./shell.ts";
|
|
14
20
|
|
|
@@ -28,30 +34,62 @@ export function createNativeTmuxSessionOpener(options: {
|
|
|
28
34
|
};
|
|
29
35
|
const open = async (liveSessionId: string, observed?: ObservedAgent) => {
|
|
30
36
|
assertOpen();
|
|
37
|
+
// One row per pane: the session's identity, whether it is adopted, and
|
|
38
|
+
// each window's and pane's stamp. tmux rejects tabs in session names, so
|
|
39
|
+
// the name is the last field; a pane stamp with a tab is invalid anyway.
|
|
31
40
|
const records = await options.run([
|
|
32
|
-
"list-
|
|
41
|
+
"list-panes",
|
|
42
|
+
"-a",
|
|
33
43
|
"-F",
|
|
34
|
-
|
|
44
|
+
`#{pid}\t#{session_id}\t#{session_created}\t#{${ADOPTED_OPTION}}\t#{${SEMANTIC_WINDOW_OPTION}}\t#{${SEMANTIC_PANE_OPTION}}\t#{session_name}`,
|
|
35
45
|
]);
|
|
36
|
-
|
|
37
|
-
const matches = records
|
|
46
|
+
const rows = records
|
|
38
47
|
.replace(/\n+$/u, "")
|
|
39
48
|
.split("\n")
|
|
40
49
|
.map((line) => line.split("\t"))
|
|
50
|
+
.filter((fields) => fields.length >= 7)
|
|
51
|
+
.map((fields) => ({
|
|
52
|
+
// A tab can only come from a window or pane stamp: such a row never
|
|
53
|
+
// takes the fast path below.
|
|
54
|
+
exact: fields.length === 7,
|
|
55
|
+
pid: fields[0]!,
|
|
56
|
+
id: fields[1]!,
|
|
57
|
+
created: fields[2]!,
|
|
58
|
+
adopted: fields[3]!,
|
|
59
|
+
window: fields.slice(4, -2).join("\t"),
|
|
60
|
+
pane: fields.at(-2)!,
|
|
61
|
+
name: fields.at(-1)!,
|
|
62
|
+
}))
|
|
41
63
|
.filter(
|
|
42
|
-
(
|
|
43
|
-
pid &&
|
|
64
|
+
({ pid, id, created, name }) =>
|
|
44
65
|
/^\d+$/.test(pid) &&
|
|
45
|
-
id &&
|
|
46
66
|
/^\$\d+$/.test(id) &&
|
|
47
|
-
created &&
|
|
48
67
|
/^\d+$/.test(created) &&
|
|
49
68
|
name &&
|
|
50
69
|
isVisibleFleetSession(name) &&
|
|
51
70
|
liveSessionIdForNativeIdentity(pid, id, created) === liveSessionId,
|
|
52
71
|
);
|
|
53
|
-
if (
|
|
54
|
-
|
|
72
|
+
if (new Set(rows.map((row) => row.id)).size !== 1)
|
|
73
|
+
throw new Error("Selected live tmux session is no longer available");
|
|
74
|
+
const { id: nativeSessionId, created, name } = rows[0]!;
|
|
75
|
+
// Re-opening a session that an earlier open already finished changes
|
|
76
|
+
// nothing: it is adopted, has exactly one durable alias, and every window
|
|
77
|
+
// and pane already carries a stamp. Promotion would only read it again
|
|
78
|
+
// (seven tmux commands), so skip it. Anything else promotes as before,
|
|
79
|
+
// which also stamps panes split since the last open.
|
|
80
|
+
const aliases = options.registry.list().filter((entry) => entry.sessionName === name);
|
|
81
|
+
if (
|
|
82
|
+
!observed &&
|
|
83
|
+
aliases.length === 1 &&
|
|
84
|
+
!options.registry.isVolatile(aliases[0]!.name) &&
|
|
85
|
+
rows.every(
|
|
86
|
+
(row) =>
|
|
87
|
+
row.exact && row.adopted === "1" && row.window.length > 0 && hasValidPaneStamp(row.pane),
|
|
88
|
+
)
|
|
89
|
+
) {
|
|
90
|
+
assertOpen();
|
|
91
|
+
return { workspaceName: aliases[0]!.name, liveSessionId };
|
|
92
|
+
}
|
|
55
93
|
// Each command checks the exact native session on the server accepting it.
|
|
56
94
|
// A name-only validation followed by stamping would cross a session replacement.
|
|
57
95
|
const run = async (args: readonly string[]) => {
|
|
@@ -62,7 +100,7 @@ export function createNativeTmuxSessionOpener(options: {
|
|
|
62
100
|
const output = await options.run([
|
|
63
101
|
"if-shell",
|
|
64
102
|
"-t",
|
|
65
|
-
nativeSessionId
|
|
103
|
+
nativeSessionId,
|
|
66
104
|
"-F",
|
|
67
105
|
condition,
|
|
68
106
|
command,
|
|
@@ -74,7 +112,7 @@ export function createNativeTmuxSessionOpener(options: {
|
|
|
74
112
|
return output;
|
|
75
113
|
};
|
|
76
114
|
const agent = observed
|
|
77
|
-
? await captureAgentAdmission(run, { id: nativeSessionId
|
|
115
|
+
? await captureAgentAdmission(run, { id: nativeSessionId, name }, observed)
|
|
78
116
|
: null;
|
|
79
117
|
await agent?.verify(false);
|
|
80
118
|
const promotion = new WorkspacePromotionAuthority({
|
|
@@ -86,9 +124,9 @@ export function createNativeTmuxSessionOpener(options: {
|
|
|
86
124
|
const result = await promotion.promote({
|
|
87
125
|
operationId: randomUUID(),
|
|
88
126
|
expectedDaemonInstanceId: options.generation,
|
|
89
|
-
intent: { sessionId: fleetSessionIdForName(name
|
|
127
|
+
intent: { sessionId: fleetSessionIdForName(name) },
|
|
90
128
|
});
|
|
91
|
-
await run(["display-message", "-p", "-t", nativeSessionId
|
|
129
|
+
await run(["display-message", "-p", "-t", nativeSessionId, "#{session_id}"]);
|
|
92
130
|
const semanticPaneId = await agent?.verify(true);
|
|
93
131
|
return {
|
|
94
132
|
workspaceName: result.resource.workspaceName,
|
|
@@ -69,12 +69,12 @@ const MAX_TMUX_OUTPUT_BYTES = 128 * 1024;
|
|
|
69
69
|
// is proven, immediately before registry admission. The promotion marker is
|
|
70
70
|
// DELIBERATELY distinct from the m32 open marker so a promoted session is a
|
|
71
71
|
// separate provenance.
|
|
72
|
-
const ADOPTED_OPTION = "@tmux_ide_adopted";
|
|
72
|
+
export const ADOPTED_OPTION = "@tmux_ide_adopted";
|
|
73
73
|
const SESSION_PROMOTED_MARKER_OPTION = "@tmux_ide_workspace_promoted_v1";
|
|
74
74
|
const SESSION_WORKSPACE_OPTION = "@tmux_ide_workspace_name";
|
|
75
75
|
const SESSION_OPERATION_OPTION = "@tmux_ide_workspace_promote_operation";
|
|
76
|
-
const SEMANTIC_PANE_OPTION = "@tmux_ide_pane_id";
|
|
77
|
-
const SEMANTIC_WINDOW_OPTION = "@tmux_ide_window_id";
|
|
76
|
+
export const SEMANTIC_PANE_OPTION = "@tmux_ide_pane_id";
|
|
77
|
+
export const SEMANTIC_WINDOW_OPTION = "@tmux_ide_window_id";
|
|
78
78
|
|
|
79
79
|
// Distinctive multi-char field/line delimiters — collision-resistant against
|
|
80
80
|
// arbitrary pane paths, window names and user-controlled `@agent_*` values,
|
|
@@ -301,7 +301,7 @@ function isInternalSession(name: string): boolean {
|
|
|
301
301
|
const VALID_SEMANTIC_PANE_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/u;
|
|
302
302
|
const RESERVED_DISCOVERED_PREFIX = "terminal.discovered.";
|
|
303
303
|
|
|
304
|
-
function hasValidPaneStamp(value: string): boolean {
|
|
304
|
+
export function hasValidPaneStamp(value: string): boolean {
|
|
305
305
|
return (
|
|
306
306
|
value.length > 0 &&
|
|
307
307
|
value.length <= 128 &&
|
|
@@ -28,6 +28,35 @@ function rawHeaderValues(
|
|
|
28
28
|
return values;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* attach-rtt: the client may carry its redeem frame in the upgrade request
|
|
33
|
+
* (base64url of the frame's JSON text), so the daemon answers the 101 and the
|
|
34
|
+
* seed without waiting a round trip for the frame. The 101 says so with
|
|
35
|
+
* `X-Tmux-Ide-Redeem: accepted`; a client that sees no such header sends the
|
|
36
|
+
* frame as before. Absent, the upgrade is exactly as it was.
|
|
37
|
+
*/
|
|
38
|
+
export const PANE_STREAM_REDEEM_HEADER = "x-tmux-ide-redeem";
|
|
39
|
+
|
|
40
|
+
/** The frame a redeem header carries, `null` for none, or "invalid". */
|
|
41
|
+
function upgradeRedeemFrame(
|
|
42
|
+
request: import("node:http").IncomingMessage,
|
|
43
|
+
): Buffer | null | "invalid" {
|
|
44
|
+
const values = rawHeaderValues(request, PANE_STREAM_REDEEM_HEADER);
|
|
45
|
+
if (values.length === 0) return null;
|
|
46
|
+
const value = values[0]!;
|
|
47
|
+
if (
|
|
48
|
+
values.length > 1 ||
|
|
49
|
+
value.length === 0 ||
|
|
50
|
+
value.length > Math.ceil((PANE_STREAM_MAX_REDEMPTION_BYTES * 4) / 3) ||
|
|
51
|
+
!/^[A-Za-z0-9_-]+$/u.test(value)
|
|
52
|
+
)
|
|
53
|
+
return "invalid";
|
|
54
|
+
const frame = Buffer.from(value, "base64url");
|
|
55
|
+
return frame.byteLength === 0 || frame.byteLength > PANE_STREAM_MAX_REDEMPTION_BYTES
|
|
56
|
+
? "invalid"
|
|
57
|
+
: frame;
|
|
58
|
+
}
|
|
59
|
+
|
|
31
60
|
function rejectUpgrade(socket: Socket, status: number): void {
|
|
32
61
|
const phrase =
|
|
33
62
|
status === 403
|
|
@@ -77,7 +106,11 @@ export function attachPaneStreamWebSocket(
|
|
|
77
106
|
});
|
|
78
107
|
|
|
79
108
|
// Old clients ignore the header and answer the pings by protocol.
|
|
80
|
-
|
|
109
|
+
const redeemed = new WeakSet<import("node:http").IncomingMessage>();
|
|
110
|
+
wss.on("headers", (headers, request) => {
|
|
111
|
+
heartbeat.advertise(headers);
|
|
112
|
+
if (redeemed.has(request)) headers.push("X-Tmux-Ide-Redeem: accepted");
|
|
113
|
+
});
|
|
81
114
|
|
|
82
115
|
const upgrade = (
|
|
83
116
|
request: import("node:http").IncomingMessage,
|
|
@@ -123,6 +156,11 @@ export function attachPaneStreamWebSocket(
|
|
|
123
156
|
rejectUpgrade(socket, 403);
|
|
124
157
|
return;
|
|
125
158
|
}
|
|
159
|
+
const redeemFrame = upgradeRedeemFrame(request);
|
|
160
|
+
if (redeemFrame === "invalid") {
|
|
161
|
+
rejectUpgrade(socket, 403);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
126
164
|
if (!isCurrent()) {
|
|
127
165
|
rejectUpgrade(socket, 410);
|
|
128
166
|
return;
|
|
@@ -141,12 +179,14 @@ export function attachPaneStreamWebSocket(
|
|
|
141
179
|
const cancelUnbound = (): void => decision.admission.cancelBeforeBind();
|
|
142
180
|
socket.once("close", cancelUnbound);
|
|
143
181
|
socket.once("error", cancelUnbound);
|
|
182
|
+
if (redeemFrame) redeemed.add(request);
|
|
144
183
|
try {
|
|
145
184
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
146
185
|
socket.off("close", cancelUnbound);
|
|
147
186
|
socket.off("error", cancelUnbound);
|
|
148
187
|
heartbeat.watch(ws, `pane-stream ${redemptionPath}`);
|
|
149
188
|
decision.admission.bind(ws as unknown as DirectTerminalSocket);
|
|
189
|
+
if (redeemFrame) decision.admission.redeemFromUpgrade(redeemFrame);
|
|
150
190
|
});
|
|
151
191
|
} catch {
|
|
152
192
|
socket.off("close", cancelUnbound);
|
|
@@ -92,6 +92,8 @@ export type MirrorPaneEvent =
|
|
|
92
92
|
/** One visible pane rectangle inside a layout event, in window cells. */
|
|
93
93
|
export interface MirrorLayoutPane {
|
|
94
94
|
browserIcon?: string | null;
|
|
95
|
+
/** #718: a terminal browser with native controls, a plain one, or null. */
|
|
96
|
+
browserKind?: "native" | "plain" | null;
|
|
95
97
|
/** A live Markdown reader pane; the path is daemon-only and never framed. */
|
|
96
98
|
reader?: { name: string; path: string } | null;
|
|
97
99
|
/** Null while the pane's semantic identity join is still unverified. */
|
|
@@ -755,6 +755,10 @@ export class SessionChannel {
|
|
|
755
755
|
await this.captureAttachedSessionIdentity();
|
|
756
756
|
this.io.send("refresh-client -B 'tmux-ide-browser-icon:%*:#{@tmux_ide_browser_icon}'");
|
|
757
757
|
this.io.send("refresh-client -B 'tmux-ide-reader:%*:#{@tmux_ide_reader}'");
|
|
758
|
+
// #718: a browser's controls appear, or a plain terminal browser starts or exits.
|
|
759
|
+
this.io.send(
|
|
760
|
+
"refresh-client -B 'tmux-ide-browser-kind:%*:#{@tmux_ide_browser_control}#{m:terminal-browse*,#{pane_current_command}}'",
|
|
761
|
+
);
|
|
758
762
|
// Changing border placement can resize PTYs without changing the layout
|
|
759
763
|
// string, so tmux emits no layout-change. Subscribe to this window option.
|
|
760
764
|
this.io.send("refresh-client -B 'tmux-ide-pane-borders:@*:#{pane-border-status}'");
|
|
@@ -2937,7 +2941,9 @@ export class SessionChannel {
|
|
|
2937
2941
|
this.opts.onWindowTopologyChanged?.();
|
|
2938
2942
|
if (
|
|
2939
2943
|
name === "subscription-changed" &&
|
|
2940
|
-
(rest.startsWith("tmux-ide-browser-icon ") ||
|
|
2944
|
+
(rest.startsWith("tmux-ide-browser-icon ") ||
|
|
2945
|
+
rest.startsWith("tmux-ide-reader ") ||
|
|
2946
|
+
rest.startsWith("tmux-ide-browser-kind "))
|
|
2941
2947
|
) {
|
|
2942
2948
|
this.scheduleSync();
|
|
2943
2949
|
return;
|
|
@@ -3355,6 +3361,7 @@ export class SessionChannel {
|
|
|
3355
3361
|
displayName: display?.name ?? null,
|
|
3356
3362
|
displayNameSource: display?.source ?? null,
|
|
3357
3363
|
browserIcon: pane?.descriptor?.browserIcon ?? null,
|
|
3364
|
+
browserKind: pane?.descriptor?.browserKind ?? null,
|
|
3358
3365
|
reader: pane?.descriptor?.reader ?? null,
|
|
3359
3366
|
left: leaf.left,
|
|
3360
3367
|
top: leaf.top,
|
|
@@ -65,6 +65,8 @@ export interface PaneStreamLeaseDescriptor {
|
|
|
65
65
|
readonly sessionName: string;
|
|
66
66
|
readonly runtimeSessionId: string | null;
|
|
67
67
|
readonly panes: readonly string[];
|
|
68
|
+
/** #806: the one window this stream was issued for, or null for a pane set of the session. */
|
|
69
|
+
readonly semanticWindowId: string | null;
|
|
68
70
|
readonly viewerMode: PaneStreamViewerMode;
|
|
69
71
|
readonly terminalDelivery: TerminalDeliveryOffer | null;
|
|
70
72
|
readonly status: PaneStreamLeaseStatus;
|
|
@@ -365,6 +367,7 @@ export class PaneStreamLeaseManager {
|
|
|
365
367
|
sessionName: state.sessionName,
|
|
366
368
|
runtimeSessionId: state.runtimeSessionId,
|
|
367
369
|
panes: [...state.request.panes],
|
|
370
|
+
semanticWindowId: state.request.semanticWindowId ?? null,
|
|
368
371
|
viewerMode: state.request.viewerMode,
|
|
369
372
|
terminalDelivery: state.request.terminalDelivery ?? null,
|
|
370
373
|
status: state.status,
|