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.
- package/bin/cli.js +16998 -4283
- package/package.json +3 -2
- package/packages/contracts/src/command-catalog.ts +116 -0
- package/packages/contracts/src/commands.ts +5 -4
- package/packages/contracts/src/daemon-events.ts +2 -1
- package/packages/contracts/src/index.ts +3 -0
- package/packages/contracts/src/pane-reader.ts +121 -0
- package/packages/contracts/src/pane-stream.ts +18 -0
- package/packages/contracts/src/plain-text.ts +61 -0
- package/packages/contracts/src/visual-theme-presets.ts +58 -2
- package/packages/daemon/dist/command-center/command-catalog-routes.js +78 -0
- package/packages/daemon/dist/command-center/plugin-routes.js +84 -0
- package/packages/daemon/dist/command-center/server.js +13 -0
- package/packages/daemon/dist/command-center/tmux-server-reader.js +41 -0
- package/packages/daemon/dist/command-center/tmux-servers.js +6 -0
- package/packages/daemon/dist/doctor.js +106 -43
- package/packages/daemon/dist/lib/cli-action-bridge.js +15 -0
- package/packages/daemon/dist/lib/cli-command.js +13 -0
- package/packages/daemon/dist/lib/daemon-embed.js +39 -1
- package/packages/daemon/dist/lib/headless-daemon.js +1 -0
- package/packages/daemon/dist/lib/pane-reader-files.js +226 -0
- package/packages/daemon/dist/lib/remote-tmux-command.js +8 -5
- package/packages/daemon/dist/lib/tmux-client-execution.js +73 -7
- package/packages/daemon/dist/lib/tmux-pane-reader.js +105 -0
- package/packages/daemon/dist/lib/tmux-server-features.js +38 -0
- package/packages/daemon/dist/lib/tmux-server-owner.js +9 -0
- package/packages/daemon/dist/lib/worktree.js +18 -0
- 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/open-browser.js +26 -12
- package/packages/daemon/dist/open-reader.js +84 -0
- package/packages/daemon/dist/plugins/action-catalog.js +129 -0
- package/packages/daemon/dist/plugins/action-cli.js +212 -0
- package/packages/daemon/dist/plugins/api-table.js +303 -0
- package/packages/daemon/dist/plugins/cli.js +556 -0
- package/packages/daemon/dist/plugins/consent.js +107 -0
- package/packages/daemon/dist/plugins/daemon-plugins.js +124 -0
- package/packages/daemon/dist/plugins/discovery.js +142 -0
- package/packages/daemon/dist/plugins/examples/worktree-tasks.js +115 -0
- package/packages/daemon/dist/plugins/exec-sandbox.js +202 -0
- package/packages/daemon/dist/plugins/host/actions-prelude.js +279 -0
- package/packages/daemon/dist/plugins/host/entry.js +4 -0
- package/packages/daemon/dist/plugins/host/host-api-prelude.js +232 -0
- package/packages/daemon/dist/plugins/host/lua-state.js +493 -0
- package/packages/daemon/dist/plugins/host/main.js +322 -0
- package/packages/daemon/dist/plugins/host/sandbox.js +299 -0
- package/packages/daemon/dist/plugins/host-calls.js +279 -0
- package/packages/daemon/dist/plugins/manifest.js +69 -0
- package/packages/daemon/dist/plugins/plugin-exec.js +261 -0
- package/packages/daemon/dist/plugins/plugin-log.js +54 -0
- package/packages/daemon/dist/plugins/plugin-store.js +74 -0
- package/packages/daemon/dist/plugins/protocol.js +252 -0
- package/packages/daemon/dist/plugins/safe-files.js +97 -0
- package/packages/daemon/dist/plugins/supervisor.js +790 -0
- package/packages/daemon/dist/plugins/worktree-calls.js +154 -0
- package/packages/daemon/dist/restore.js +57 -40
- package/packages/daemon/dist/terminal/mirror/session-channel.js +4 -1
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +12 -3
- package/packages/daemon/dist/terminal/protocol/reader-option.js +66 -0
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +7 -2
- package/packages/daemon/dist/tmux-upgrade/cli.js +106 -0
- package/packages/daemon/dist/tmux-upgrade/io.js +540 -0
- package/packages/daemon/dist/tmux-upgrade/plan.js +238 -0
- package/packages/daemon/dist/tmux-upgrade/run.js +199 -0
- package/packages/daemon/dist/tui/chrome/snapshot.js +3 -4
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +64 -4
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +62 -5
- package/packages/daemon/dist/tui/mirror/runtime/application-home-experience.js +2 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-agent-navigation.js +12 -8
- package/packages/daemon/dist/tui/mirror/runtime/application-palette-command-owner.js +30 -2
- package/packages/daemon/dist/tui/mirror/runtime/application-plugin-commands.js +152 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-plugin-form.js +251 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +125 -111
- package/packages/daemon/dist/tui/mirror/workspace/application-command-description.js +14 -0
- package/packages/daemon/dist/tui/mirror/workspace/palette-list-layout.js +5 -0
- package/packages/daemon/src/command-center/command-catalog-routes.ts +116 -0
- package/packages/daemon/src/command-center/plugin-routes.ts +110 -0
- package/packages/daemon/src/command-center/server.ts +15 -0
- package/packages/daemon/src/command-center/tmux-server-reader.ts +62 -0
- package/packages/daemon/src/command-center/tmux-servers.ts +6 -0
- package/packages/daemon/src/doctor.ts +118 -45
- package/packages/daemon/src/lib/cli-action-bridge.ts +19 -0
- package/packages/daemon/src/lib/cli-command.ts +16 -0
- package/packages/daemon/src/lib/daemon-embed.ts +59 -0
- package/packages/daemon/src/lib/headless-daemon.ts +1 -0
- package/packages/daemon/src/lib/pane-reader-files.ts +294 -0
- package/packages/daemon/src/lib/remote-tmux-command.ts +13 -6
- package/packages/daemon/src/lib/tmux-client-execution.ts +79 -7
- package/packages/daemon/src/lib/tmux-pane-reader.ts +144 -0
- package/packages/daemon/src/lib/tmux-server-features.ts +43 -0
- package/packages/daemon/src/lib/tmux-server-owner.ts +9 -0
- package/packages/daemon/src/lib/worktree.ts +16 -0
- package/packages/daemon/src/open-browser.ts +59 -18
- package/packages/daemon/src/open-reader.ts +148 -0
- package/packages/daemon/src/plugins/action-catalog.ts +141 -0
- package/packages/daemon/src/plugins/action-cli.ts +248 -0
- package/packages/daemon/src/plugins/api-table.ts +346 -0
- package/packages/daemon/src/plugins/cli.ts +630 -0
- package/packages/daemon/src/plugins/consent.ts +125 -0
- package/packages/daemon/src/plugins/daemon-plugins.ts +172 -0
- package/packages/daemon/src/plugins/discovery.ts +176 -0
- package/packages/daemon/src/plugins/examples/worktree-tasks.ts +120 -0
- package/packages/daemon/src/plugins/exec-sandbox.ts +264 -0
- package/packages/daemon/src/plugins/host/actions-prelude.ts +280 -0
- package/packages/daemon/src/plugins/host/entry.ts +5 -0
- package/packages/daemon/src/plugins/host/host-api-prelude.ts +233 -0
- package/packages/daemon/src/plugins/host/lua-state.ts +557 -0
- package/packages/daemon/src/plugins/host/main.ts +359 -0
- package/packages/daemon/src/plugins/host/sandbox.ts +301 -0
- package/packages/daemon/src/plugins/host-calls.ts +343 -0
- package/packages/daemon/src/plugins/manifest.ts +74 -0
- package/packages/daemon/src/plugins/plugin-exec.ts +326 -0
- package/packages/daemon/src/plugins/plugin-log.ts +63 -0
- package/packages/daemon/src/plugins/plugin-store.ts +80 -0
- package/packages/daemon/src/plugins/protocol.ts +275 -0
- package/packages/daemon/src/plugins/safe-files.ts +105 -0
- package/packages/daemon/src/plugins/supervisor.ts +954 -0
- package/packages/daemon/src/plugins/worktree-calls.ts +183 -0
- package/packages/daemon/src/restore.ts +80 -44
- package/packages/daemon/src/terminal/mirror/events.ts +2 -0
- package/packages/daemon/src/terminal/mirror/session-channel.ts +6 -1
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +15 -2
- package/packages/daemon/src/terminal/protocol/reader-option.ts +77 -0
- package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +10 -1
- package/packages/daemon/src/tmux-upgrade/cli.ts +118 -0
- package/packages/daemon/src/tmux-upgrade/io.ts +596 -0
- package/packages/daemon/src/tmux-upgrade/plan.ts +353 -0
- package/packages/daemon/src/tmux-upgrade/run.ts +325 -0
- package/packages/daemon/src/tui/chrome/snapshot.ts +3 -4
- package/packages/daemon/src/tui/mirror/runtime/application-fleet-switcher.tsx +3 -1
- package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +110 -10
- package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +90 -6
- package/packages/daemon/src/tui/mirror/runtime/application-home-experience.ts +2 -0
- package/packages/daemon/src/tui/mirror/runtime/application-machine-agent-navigation.ts +20 -9
- package/packages/daemon/src/tui/mirror/runtime/application-palette-command-owner.ts +42 -2
- package/packages/daemon/src/tui/mirror/runtime/application-palette-preview.tsx +7 -1
- package/packages/daemon/src/tui/mirror/runtime/application-plugin-commands.ts +229 -0
- package/packages/daemon/src/tui/mirror/runtime/application-plugin-form.ts +312 -0
- package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +2 -2
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +149 -128
- package/packages/daemon/src/tui/mirror/workspace/application-command-description.ts +44 -2
- package/packages/daemon/src/tui/mirror/workspace/palette-list-layout.ts +4 -0
- package/packages/tmux-bridge/src/runner.ts +3 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ide.worktree.list|create|open|remove`: git worktrees and their sessions,
|
|
3
|
+
* for plugins granted the `worktree` capability.
|
|
4
|
+
*
|
|
5
|
+
* The daemon runs its own `tmux-ide worktree … --json` (the same code and
|
|
6
|
+
* gates as the CLI), outside the plugin sandbox, with arguments it checked:
|
|
7
|
+
* a branch or ref that git would accept and cannot pass for an option, and
|
|
8
|
+
* a session that exists, by exact name, on the daemon's tmux server. The
|
|
9
|
+
* plugin never gets a program it could aim elsewhere. Sessions it opens are
|
|
10
|
+
* plain: the worktree's own tmux-ide layout (commands from that branch)
|
|
11
|
+
* never runs. `remove` never passes `--force`, so a worktree with changes
|
|
12
|
+
* is refused; plugins mark actions that remove as dangerous so a person
|
|
13
|
+
* confirms them.
|
|
14
|
+
*/
|
|
15
|
+
import { spawn } from "node:child_process";
|
|
16
|
+
import { homedir } from "node:os";
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
export const WORKTREE_OPERATIONS = ["list", "create", "open", "remove"];
|
|
19
|
+
/** A branch or ref: git-valid, and never something argv parsing reads as an option. */
|
|
20
|
+
const REF = z
|
|
21
|
+
.string()
|
|
22
|
+
.min(1)
|
|
23
|
+
.max(200)
|
|
24
|
+
.regex(/^[A-Za-z0-9_][A-Za-z0-9._/-]*$/u, "must be letters, digits and . _ / - only")
|
|
25
|
+
.refine((ref) => !ref.includes("..") &&
|
|
26
|
+
!ref.includes("//") &&
|
|
27
|
+
!ref.endsWith("/") &&
|
|
28
|
+
!ref.endsWith(".") &&
|
|
29
|
+
!ref.endsWith(".lock") &&
|
|
30
|
+
!ref.split("/").some((part) => part.startsWith(".")), "is not a valid git branch name");
|
|
31
|
+
/**
|
|
32
|
+
* A tmux session name tmux reads literally: letters, digits, space and
|
|
33
|
+
* `_ - @ + ,` only. Nothing tmux takes as a pattern (`* ? [`), a format
|
|
34
|
+
* (`#{`), target syntax (`: . = ~ $ %`) or an option (a leading `-`).
|
|
35
|
+
*/
|
|
36
|
+
const SESSION = z
|
|
37
|
+
.string()
|
|
38
|
+
.min(1)
|
|
39
|
+
.max(200)
|
|
40
|
+
.regex(/^[\p{L}\p{N}_@+][\p{L}\p{N} _@+,-]*$/u, "is not a plain tmux session name");
|
|
41
|
+
const RequestSchemaZ = z
|
|
42
|
+
.object({
|
|
43
|
+
session: SESSION,
|
|
44
|
+
branch: REF.optional(),
|
|
45
|
+
from: REF.optional(),
|
|
46
|
+
})
|
|
47
|
+
.strict();
|
|
48
|
+
export class WorktreeCallError extends Error {
|
|
49
|
+
}
|
|
50
|
+
function fail(message) {
|
|
51
|
+
throw new WorktreeCallError(message);
|
|
52
|
+
}
|
|
53
|
+
/** Check a request and run the worktree operation; resolves with tmux-ide's JSON answer. */
|
|
54
|
+
export async function worktreeCall(operation, raw, deps) {
|
|
55
|
+
if (!WORKTREE_OPERATIONS.includes(operation))
|
|
56
|
+
fail("E_INVALID: ide.worktree supports list, create, open and remove");
|
|
57
|
+
const op = operation;
|
|
58
|
+
const parsed = RequestSchemaZ.safeParse(raw);
|
|
59
|
+
if (!parsed.success) {
|
|
60
|
+
const issue = parsed.error.issues[0];
|
|
61
|
+
fail(`E_INVALID: ide.worktree.${op} ${issue?.path.join(".") || "request"} ${issue?.message ?? "is invalid"}`);
|
|
62
|
+
}
|
|
63
|
+
const { session, branch, from } = parsed.data;
|
|
64
|
+
if (op !== "list" && !branch)
|
|
65
|
+
fail(`E_INVALID: ide.worktree.${op} needs a branch`);
|
|
66
|
+
if (from && op !== "create")
|
|
67
|
+
fail(`E_INVALID: only ide.worktree.create takes from`);
|
|
68
|
+
// The session must exist on the daemon's tmux server, by exact name
|
|
69
|
+
// (`=name`; display-message alone answers even for an unknown session).
|
|
70
|
+
// The CLI then talks to that same server (TMUX names its socket), finds
|
|
71
|
+
// the repository from that session's directory, and fails rather than
|
|
72
|
+
// fall back to its own directory.
|
|
73
|
+
let where;
|
|
74
|
+
try {
|
|
75
|
+
await deps.tmux(["has-session", "-t", `=${session}`]);
|
|
76
|
+
// "|" cannot be in a session name (see SESSION), so the first one splits.
|
|
77
|
+
// (Not a tab: tmux prints control characters as "_" under LANG=C.)
|
|
78
|
+
const line = (await deps.tmux([
|
|
79
|
+
"display-message",
|
|
80
|
+
"-p",
|
|
81
|
+
"-t",
|
|
82
|
+
`=${session}:`,
|
|
83
|
+
"#{session_name}|#{socket_path},#{pid}",
|
|
84
|
+
])).trim();
|
|
85
|
+
const split = line.indexOf("|");
|
|
86
|
+
const name = split < 0 ? line : line.slice(0, split);
|
|
87
|
+
const socket = split < 0 ? "" : line.slice(split + 1);
|
|
88
|
+
if (name !== session || !socket || !/^\/.+,\d+$/u.test(socket))
|
|
89
|
+
throw new Error("mismatch");
|
|
90
|
+
where = socket;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
fail(`E_NOT_FOUND: no tmux session '${session}'`);
|
|
94
|
+
}
|
|
95
|
+
if (deps.stillActive && !deps.stillActive())
|
|
96
|
+
fail("E_UNAVAILABLE: the plugin was stopped before this finished");
|
|
97
|
+
const args = ["worktree", op];
|
|
98
|
+
if (branch)
|
|
99
|
+
args.push(branch);
|
|
100
|
+
if (from)
|
|
101
|
+
args.push("--from", from);
|
|
102
|
+
// --plain: a plugin never starts the worktree's own layout, whose commands
|
|
103
|
+
// come from that branch (which `from` may name).
|
|
104
|
+
if (op === "create" || op === "open")
|
|
105
|
+
args.push("--plain");
|
|
106
|
+
// `=name:`: the exact session (a bare `=name` names no pane for tmux).
|
|
107
|
+
// No git hook runs either: `git worktree add` would run post-checkout, and
|
|
108
|
+
// a relative core.hooksPath takes the hook from the new worktree's branch.
|
|
109
|
+
args.push("--session", `=${session}:`, "--require-session", "--no-git-hooks", "--json");
|
|
110
|
+
const env = { ...process.env, TMUX: `${where},0` };
|
|
111
|
+
delete env.TMUX_PANE;
|
|
112
|
+
const result = await deps.runCli(args, env);
|
|
113
|
+
if (result.code !== 0) {
|
|
114
|
+
const message = (result.stderr.trim() || result.stdout.trim()).split("\n").slice(-3).join(" ");
|
|
115
|
+
fail(`E_FAILED: ${message || `tmux-ide worktree ${op} failed`}`.slice(0, 2000));
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
return JSON.parse(result.stdout);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
fail("E_FAILED: tmux-ide worktree sent an unexpected answer");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const OUTPUT_CAP = 1024 * 1024;
|
|
125
|
+
/** Run `command` (the tmux-ide CLI argv prefix) with `args`, for up to `timeoutMs`. */
|
|
126
|
+
export function cliRunner(command, timeoutMs = 60_000) {
|
|
127
|
+
return (args, env) => new Promise((resolve, reject) => {
|
|
128
|
+
const [file, ...prefix] = command;
|
|
129
|
+
const child = spawn(file, [...prefix, ...args], {
|
|
130
|
+
cwd: homedir(),
|
|
131
|
+
env,
|
|
132
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
133
|
+
});
|
|
134
|
+
let stdout = "";
|
|
135
|
+
let stderr = "";
|
|
136
|
+
child.stdout.on("data", (chunk) => {
|
|
137
|
+
if (stdout.length < OUTPUT_CAP)
|
|
138
|
+
stdout += chunk.toString("utf8");
|
|
139
|
+
});
|
|
140
|
+
child.stderr.on("data", (chunk) => {
|
|
141
|
+
if (stderr.length < OUTPUT_CAP)
|
|
142
|
+
stderr += chunk.toString("utf8");
|
|
143
|
+
});
|
|
144
|
+
const timer = setTimeout(() => child.kill("SIGKILL"), timeoutMs);
|
|
145
|
+
child.on("error", (error) => {
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
reject(new WorktreeCallError(`E_UNAVAILABLE: could not run tmux-ide: ${error.message}`));
|
|
148
|
+
});
|
|
149
|
+
child.on("close", (code) => {
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
resolve({ code, stdout, stderr });
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
@@ -301,31 +301,57 @@ function liveSessions() {
|
|
|
301
301
|
* (flag ORed with the `~/.tmux-ide/config.json` default) revives agent
|
|
302
302
|
* conversations via `claude --resume <id>`.
|
|
303
303
|
*/
|
|
304
|
-
export async function restore(
|
|
305
|
-
const
|
|
304
|
+
export async function restore(options = {}) {
|
|
305
|
+
const { json = false, dryRun = false } = options;
|
|
306
|
+
const outcome = await restoreFleet(options);
|
|
307
|
+
reportPlan(outcome.plan, outcome.snapshot, { ...outcome, json, dryRun });
|
|
308
|
+
if (outcome.failed.length) {
|
|
309
|
+
throw new IdeError(`could not rebuild ${outcome.failed.join(", ")}`, {
|
|
310
|
+
code: "RESTORE_FAILED",
|
|
311
|
+
exitCode: 1,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Rebuild the fleet without printing. One session failing to rebuild does not
|
|
317
|
+
* stop the rest; it is listed in `failed`.
|
|
318
|
+
*/
|
|
319
|
+
export async function restoreFleet({ json = false, dryRun = false, runCommands = false, resumeAgents = false, from, snapshotOnly = false, resumeFromConfig = true, } = {}) {
|
|
320
|
+
const snapshot = readSnapshot(from);
|
|
306
321
|
if (!snapshot) {
|
|
307
|
-
throw new IdeError(
|
|
322
|
+
throw new IdeError(from
|
|
323
|
+
? `no readable snapshot at ${from}`
|
|
324
|
+
: "no snapshot yet — the updater writes one every ~30s while any session is adopted", { code: "NO_SNAPSHOT", exitCode: 1 });
|
|
308
325
|
}
|
|
309
326
|
// The flag forces resume on; config makes it the default. No negative flag.
|
|
310
|
-
const resume = resumeAgents || readRestorePrefs().resumeAgents;
|
|
311
|
-
const plan = buildRestorePlan(snapshot, liveSessions(), ideBackedProjects());
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const restored = [];
|
|
324
|
-
const launched = [];
|
|
325
|
-
const resumed = [];
|
|
327
|
+
const resume = resumeAgents || (resumeFromConfig && readRestorePrefs().resumeAgents);
|
|
328
|
+
const plan = buildRestorePlan(snapshot, liveSessions(), snapshotOnly ? new Map() : ideBackedProjects());
|
|
329
|
+
const outcome = {
|
|
330
|
+
snapshot,
|
|
331
|
+
plan,
|
|
332
|
+
restored: [],
|
|
333
|
+
launched: [],
|
|
334
|
+
resumed: [],
|
|
335
|
+
failed: [],
|
|
336
|
+
resumeAgents: resume,
|
|
337
|
+
};
|
|
338
|
+
if (dryRun)
|
|
339
|
+
return outcome;
|
|
326
340
|
const recordResumed = (session, panes) => {
|
|
327
341
|
if (panes.length)
|
|
328
|
-
resumed.push({ session, panes });
|
|
342
|
+
outcome.resumed.push({ session, panes });
|
|
343
|
+
};
|
|
344
|
+
const rebuild = (session) => {
|
|
345
|
+
try {
|
|
346
|
+
recordResumed(session.name, rebuildSession(session, { runCommands, resumeAgents: resume }));
|
|
347
|
+
}
|
|
348
|
+
catch {
|
|
349
|
+
outcome.failed.push(session.name);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (session.adopted)
|
|
353
|
+
safeAdopt(session.name);
|
|
354
|
+
outcome.restored.push(session.name);
|
|
329
355
|
};
|
|
330
356
|
for (const action of plan.actions) {
|
|
331
357
|
if (action.kind === "skip")
|
|
@@ -333,33 +359,19 @@ export async function restore({ json = false, dryRun = false, runCommands = fals
|
|
|
333
359
|
if (action.kind === "launch") {
|
|
334
360
|
const ok = await launchProject(action.dir, json);
|
|
335
361
|
if (ok)
|
|
336
|
-
launched.push(action.session);
|
|
362
|
+
outcome.launched.push(action.session);
|
|
337
363
|
else {
|
|
338
364
|
// Launch failed — fall back to a raw rebuild from the snapshot so the
|
|
339
365
|
// session still comes back.
|
|
340
366
|
const snap = snapshot.sessions.find((s) => s.name === action.session);
|
|
341
|
-
if (snap)
|
|
342
|
-
|
|
343
|
-
if (snap.adopted)
|
|
344
|
-
safeAdopt(snap.name);
|
|
345
|
-
restored.push(action.session);
|
|
346
|
-
}
|
|
367
|
+
if (snap)
|
|
368
|
+
rebuild(snap);
|
|
347
369
|
}
|
|
348
370
|
continue;
|
|
349
371
|
}
|
|
350
|
-
|
|
351
|
-
if (action.session.adopted)
|
|
352
|
-
safeAdopt(action.session.name);
|
|
353
|
-
restored.push(action.session.name);
|
|
372
|
+
rebuild(action.session);
|
|
354
373
|
}
|
|
355
|
-
|
|
356
|
-
json,
|
|
357
|
-
dryRun: false,
|
|
358
|
-
restored,
|
|
359
|
-
launched,
|
|
360
|
-
resumed,
|
|
361
|
-
resumeAgents: resume,
|
|
362
|
-
});
|
|
374
|
+
return outcome;
|
|
363
375
|
}
|
|
364
376
|
/** Adopt a restored session into the chrome; never let a chrome failure abort restore. */
|
|
365
377
|
function safeAdopt(session) {
|
|
@@ -391,7 +403,7 @@ async function launchProject(dir, json) {
|
|
|
391
403
|
console.log = restoreLog;
|
|
392
404
|
}
|
|
393
405
|
}
|
|
394
|
-
function reportPlan(plan, snapshot, { json, dryRun, restored, launched, resumed, resumeAgents }) {
|
|
406
|
+
function reportPlan(plan, snapshot, { json, dryRun, restored, launched, resumed, resumeAgents, failed }) {
|
|
395
407
|
const skipped = plan.actions.filter((a) => a.kind === "skip").map((a) => a.session);
|
|
396
408
|
const willLaunch = plan.actions.filter((a) => a.kind === "launch").map((a) => a.session);
|
|
397
409
|
const willRebuild = plan.actions.filter((a) => a.kind === "rebuild").map((a) => a.session.name);
|
|
@@ -407,6 +419,7 @@ function reportPlan(plan, snapshot, { json, dryRun, restored, launched, resumed,
|
|
|
407
419
|
resumeAgents,
|
|
408
420
|
resumedPanes,
|
|
409
421
|
resumed,
|
|
422
|
+
failed,
|
|
410
423
|
}, null, 2));
|
|
411
424
|
return;
|
|
412
425
|
}
|
|
@@ -443,5 +456,9 @@ function reportPlan(plan, snapshot, { json, dryRun, restored, launched, resumed,
|
|
|
443
456
|
parts.push(`launched ${launched.join(", ")}`);
|
|
444
457
|
if (skipped.length)
|
|
445
458
|
parts.push(`skipped ${skipped.join(", ")} (already running)`);
|
|
459
|
+
if (failed.length)
|
|
460
|
+
parts.push(`failed to rebuild ${failed.join(", ")}`);
|
|
461
|
+
// Name the snapshot's age: an old snapshot brings back an old fleet (#766).
|
|
462
|
+
console.log(`Snapshot saved ${snapshot.savedAt}.`);
|
|
446
463
|
console.log(parts.length ? `Restored: ${parts.join("; ")}` : "Nothing to restore.");
|
|
447
464
|
}
|
|
@@ -365,6 +365,7 @@ export class SessionChannel {
|
|
|
365
365
|
await this.io.start();
|
|
366
366
|
await this.captureAttachedSessionIdentity();
|
|
367
367
|
this.io.send("refresh-client -B 'tmux-ide-browser-icon:%*:#{@tmux_ide_browser_icon}'");
|
|
368
|
+
this.io.send("refresh-client -B 'tmux-ide-reader:%*:#{@tmux_ide_reader}'");
|
|
368
369
|
// Changing border placement can resize PTYs without changing the layout
|
|
369
370
|
// string, so tmux emits no layout-change. Subscribe to this window option.
|
|
370
371
|
this.io.send("refresh-client -B 'tmux-ide-pane-borders:@*:#{pane-border-status}'");
|
|
@@ -2266,7 +2267,8 @@ export class SessionChannel {
|
|
|
2266
2267
|
name === "session-renamed" ||
|
|
2267
2268
|
name === "sessions-changed")
|
|
2268
2269
|
this.opts.onWindowTopologyChanged?.();
|
|
2269
|
-
if (name === "subscription-changed" &&
|
|
2270
|
+
if (name === "subscription-changed" &&
|
|
2271
|
+
(rest.startsWith("tmux-ide-browser-icon ") || rest.startsWith("tmux-ide-reader "))) {
|
|
2270
2272
|
this.scheduleSync();
|
|
2271
2273
|
return;
|
|
2272
2274
|
}
|
|
@@ -2672,6 +2674,7 @@ export class SessionChannel {
|
|
|
2672
2674
|
displayName: display?.name ?? null,
|
|
2673
2675
|
displayNameSource: display?.source ?? null,
|
|
2674
2676
|
browserIcon: pane?.descriptor?.browserIcon ?? null,
|
|
2677
|
+
reader: pane?.descriptor?.reader ?? null,
|
|
2675
2678
|
left: leaf.left,
|
|
2676
2679
|
top: leaf.top,
|
|
2677
2680
|
width: leaf.width,
|
|
@@ -2,7 +2,7 @@ import { TERMINAL_SURFACE_MAX_CONTROL_BYTES, TERMINAL_SURFACE_CAPABILITY_VERSION
|
|
|
2
2
|
import { NativeSurfaceViewer } from "../graphics/native-surface-viewer.js";
|
|
3
3
|
import { compressGraphicsChunk } from "../graphics/compress-chunk.js";
|
|
4
4
|
import { TERMINAL_GRAPHICS_COMPRESSED_CAPABILITY_VERSION, TERMINAL_GRAPHICS_COMPRESSED_LOCAL_CAPABILITY_VERSION, TERMINAL_PROJECTION_CAPABILITY_VERSION, TERMINAL_PROJECTION_LOCAL_CAPABILITY_VERSION, } from "@tmux-ide/contracts";
|
|
5
|
-
import { PANE_STREAM_INPUT_LIFETIME_CAPABILITY_VERSION, PANE_STREAM_INPUT_BYTES_CAPABILITY_VERSION, } from "@tmux-ide/contracts";
|
|
5
|
+
import { PANE_STREAM_INPUT_LIFETIME_CAPABILITY_VERSION, PANE_STREAM_INPUT_BYTES_CAPABILITY_VERSION, PANE_STREAM_BROWSER_ICON_CAPABILITY_VERSION, PANE_STREAM_READER_CAPABILITY_VERSION, } from "@tmux-ide/contracts";
|
|
6
6
|
import { inflateSync } from "node:zlib";
|
|
7
7
|
import { PaneStreamLayoutSnapshotFrameSchemaZ } from "@tmux-ide/contracts";
|
|
8
8
|
import { z } from "zod";
|
|
@@ -1332,7 +1332,9 @@ export class PaneStreamLiveConnection {
|
|
|
1332
1332
|
this.#observeSurfaceDemand([channel.semanticPaneId]);
|
|
1333
1333
|
// Renderers that cannot inflate see raw formats; their bytes are inflated
|
|
1334
1334
|
// when served.
|
|
1335
|
-
const zlib = this.#descriptor.terminalDelivery?.protocolVersions.some((version) => version === TERMINAL_GRAPHICS_ZLIB_CAPABILITY_VERSION ||
|
|
1335
|
+
const zlib = this.#descriptor.terminalDelivery?.protocolVersions.some((version) => version === TERMINAL_GRAPHICS_ZLIB_CAPABILITY_VERSION ||
|
|
1336
|
+
version === PANE_STREAM_BROWSER_ICON_CAPABILITY_VERSION ||
|
|
1337
|
+
version === PANE_STREAM_READER_CAPABILITY_VERSION) === true;
|
|
1336
1338
|
channel.graphicsZlib = zlib;
|
|
1337
1339
|
channel.graphicsLocal =
|
|
1338
1340
|
!!this.#localImages &&
|
|
@@ -1793,6 +1795,9 @@ export class PaneStreamLiveConnection {
|
|
|
1793
1795
|
}
|
|
1794
1796
|
this.#sendFrame(null, frame);
|
|
1795
1797
|
}
|
|
1798
|
+
#offers(version) {
|
|
1799
|
+
return this.#descriptor.terminalDelivery?.protocolVersions.includes(version) === true;
|
|
1800
|
+
}
|
|
1796
1801
|
#layoutFrame(event) {
|
|
1797
1802
|
const frame = {
|
|
1798
1803
|
type: "layout",
|
|
@@ -1808,9 +1813,13 @@ export class PaneStreamLiveConnection {
|
|
|
1808
1813
|
pane: pane.semanticPaneId,
|
|
1809
1814
|
displayName: pane.displayName,
|
|
1810
1815
|
displayNameSource: pane.displayNameSource,
|
|
1811
|
-
...(this.#
|
|
1816
|
+
...(this.#offers(PANE_STREAM_BROWSER_ICON_CAPABILITY_VERSION) ||
|
|
1817
|
+
this.#offers(PANE_STREAM_READER_CAPABILITY_VERSION)
|
|
1812
1818
|
? { browserIcon: pane.browserIcon ?? null }
|
|
1813
1819
|
: {}),
|
|
1820
|
+
...(this.#offers(PANE_STREAM_READER_CAPABILITY_VERSION)
|
|
1821
|
+
? { reader: pane.reader ? { name: pane.reader.name } : null }
|
|
1822
|
+
: {}),
|
|
1814
1823
|
left: pane.left,
|
|
1815
1824
|
top: pane.top,
|
|
1816
1825
|
width: pane.width,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { basename, isAbsolute } from "node:path";
|
|
2
|
+
import { hasControlCharacter } from "@tmux-ide/contracts";
|
|
3
|
+
const MARKDOWN = /\.(?:md|markdown)$/iu;
|
|
4
|
+
export function isMarkdownPath(path) {
|
|
5
|
+
const name = basename(path);
|
|
6
|
+
return MARKDOWN.test(name) && !/^\.(?:md|markdown)$/iu.test(name);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Parse `@tmux_ide_reader`: `{"version":1,"pid":N,"path":"/abs/notes.md"}`.
|
|
10
|
+
* A reader exists only while the process that set the option is alive, and
|
|
11
|
+
* only on the pane whose own process it is: `panePid` is that pane's
|
|
12
|
+
* `#{pane_pid}`. The CLI starts `tmux-ide show` with tmux's direct exec (no
|
|
13
|
+
* shell), so the pane's process is the reader itself and records exactly that
|
|
14
|
+
* pid. Equality rather than "a descendant of" needs no process-tree walk.
|
|
15
|
+
*
|
|
16
|
+
* What the tie rules out: an option left behind by a reader that has exited,
|
|
17
|
+
* and a later process that happens to reuse its pid. What it does not: the
|
|
18
|
+
* option is not proof that `tmux-ide show` set it. In a shell pane the shell
|
|
19
|
+
* is the pane's process, so the shell can set an option naming its own pid,
|
|
20
|
+
* and any process that can talk to the tmux server can read another pane's
|
|
21
|
+
* pid and set that pane's option. Both are the same user, who can already
|
|
22
|
+
* read the file; the reader grants no access they do not have.
|
|
23
|
+
*/
|
|
24
|
+
export function readerOption(value, panePid, alive = processAlive) {
|
|
25
|
+
if (!value || value.length > 8192)
|
|
26
|
+
return null;
|
|
27
|
+
let parsed;
|
|
28
|
+
try {
|
|
29
|
+
parsed = JSON.parse(value);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
35
|
+
return null;
|
|
36
|
+
const record = parsed;
|
|
37
|
+
if (Object.keys(record).sort().join(",") !== "path,pid,version")
|
|
38
|
+
return null;
|
|
39
|
+
const { version, pid, path } = record;
|
|
40
|
+
if (version !== 1 || typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 0)
|
|
41
|
+
return null;
|
|
42
|
+
if (!/^[1-9][0-9]*$/u.test(panePid) || String(pid) !== panePid)
|
|
43
|
+
return null;
|
|
44
|
+
if (typeof path !== "string" ||
|
|
45
|
+
path.length > 4096 ||
|
|
46
|
+
!isAbsolute(path) ||
|
|
47
|
+
hasControlCharacter(path) ||
|
|
48
|
+
!isMarkdownPath(path))
|
|
49
|
+
return null;
|
|
50
|
+
const name = basename(path);
|
|
51
|
+
if (name.length > 255)
|
|
52
|
+
return null;
|
|
53
|
+
if (!alive(pid))
|
|
54
|
+
return null;
|
|
55
|
+
return { name, path, pid };
|
|
56
|
+
}
|
|
57
|
+
function processAlive(pid) {
|
|
58
|
+
try {
|
|
59
|
+
process.kill(pid, 0);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// Including EPERM: a pid now owned by another user is not our reader.
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { browserIcon } from "./browser-icon.js";
|
|
2
|
+
import { readerOption } from "./reader-option.js";
|
|
2
3
|
/**
|
|
3
4
|
* `qa` asks tmux to escape each value as a command argument. In particular,
|
|
4
5
|
* embedded tabs/newlines/backslashes become escapes, leaving our record tabs
|
|
@@ -29,6 +30,9 @@ export const SESSION_PANE_DESCRIPTOR_FORMAT = [
|
|
|
29
30
|
"#{pane_birth_id}",
|
|
30
31
|
"#{qa:@tmux_ide_name_source}",
|
|
31
32
|
"#{qa:@tmux_ide_browser_icon}",
|
|
33
|
+
"#{qa:@tmux_ide_reader}",
|
|
34
|
+
// The reader option belongs to the pane only when its own process set it.
|
|
35
|
+
"#{pane_pid}",
|
|
32
36
|
].join("\t");
|
|
33
37
|
/** Decode the escapes emitted by tmux's `qa` format modifier. */
|
|
34
38
|
export function decodeTmuxArgument(value) {
|
|
@@ -102,9 +106,9 @@ export function parseSessionPaneDescriptorReply(lines) {
|
|
|
102
106
|
continue;
|
|
103
107
|
}
|
|
104
108
|
const encoded = utf8Line.split("\t");
|
|
105
|
-
if (encoded.length
|
|
109
|
+
if (encoded.length < 21 || encoded.length > 25)
|
|
106
110
|
continue;
|
|
107
|
-
const [runtimePaneId = "", semanticPaneId = "", role = "", type = "", currentCommand = "", cwd = "", windowIndexRaw = "", windowName = "", windowId = "", title = "", runtimeSessionId = "", paneIndexRaw = "", name = "", missionStamp = "", paneActiveRaw = "", windowActiveRaw = "", semanticWindowId = "", sessionName = "", windowPaneCountRaw = "", sessionWindowCountRaw = "", nativePaneBirthId = "", nameSource = "", browserIconRaw = "",] = encoded.map(decodeTmuxArgument);
|
|
111
|
+
const [runtimePaneId = "", semanticPaneId = "", role = "", type = "", currentCommand = "", cwd = "", windowIndexRaw = "", windowName = "", windowId = "", title = "", runtimeSessionId = "", paneIndexRaw = "", name = "", missionStamp = "", paneActiveRaw = "", windowActiveRaw = "", semanticWindowId = "", sessionName = "", windowPaneCountRaw = "", sessionWindowCountRaw = "", nativePaneBirthId = "", nameSource = "", browserIconRaw = "", readerRaw = "", panePidRaw = "",] = encoded.map(decodeTmuxArgument);
|
|
108
112
|
if (!/^%(?:0|[1-9][0-9]*)$/u.test(runtimePaneId) || runtimePaneId.length > 32)
|
|
109
113
|
continue;
|
|
110
114
|
if (!/^\$(?:0|[1-9][0-9]*)$/u.test(runtimeSessionId) || runtimeSessionId.length > 32)
|
|
@@ -142,6 +146,7 @@ export function parseSessionPaneDescriptorReply(lines) {
|
|
|
142
146
|
}
|
|
143
147
|
descriptors.push({
|
|
144
148
|
browserIcon: browserIcon(browserIconRaw),
|
|
149
|
+
reader: readerOption(readerRaw, panePidRaw),
|
|
145
150
|
sessionName,
|
|
146
151
|
runtimePaneId,
|
|
147
152
|
runtimeSessionId,
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tmux-ide servers upgrade` (#766): flags, the `--ssh` hand-off, the detached
|
|
3
|
+
* worker's `--continue`, and the exit code. The steps are in ./run.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { SavedMachineSchema } from "@tmux-ide/contracts";
|
|
9
|
+
import { IdeError } from "../lib/errors.js";
|
|
10
|
+
import { remoteTmuxIdeArgsCommand } from "../lib/remote-tmux-command.js";
|
|
11
|
+
import { createUpgradeIo, parseWorkerState, writeWorkerResult } from "./io.js";
|
|
12
|
+
import { finishUpgrade, retryCommand, upgradeServer, } from "./run.js";
|
|
13
|
+
/** The flags a remote run gets: the same choices, never the local socket defaults. */
|
|
14
|
+
export function forwardedUpgradeArgs(options) {
|
|
15
|
+
const args = [];
|
|
16
|
+
if (options.yes)
|
|
17
|
+
args.push("--yes");
|
|
18
|
+
if (options.endRunningAgents)
|
|
19
|
+
args.push("--end-running-agents");
|
|
20
|
+
if (!options.resumeAgents)
|
|
21
|
+
args.push("--no-resume-agents");
|
|
22
|
+
if (options.dryRun)
|
|
23
|
+
args.push("--dry-run");
|
|
24
|
+
if (options.json)
|
|
25
|
+
args.push("--json");
|
|
26
|
+
if (options.socketPath)
|
|
27
|
+
args.push("--socket-path", options.socketPath);
|
|
28
|
+
if (options.socketName)
|
|
29
|
+
args.push("--socket-name", options.socketName);
|
|
30
|
+
return args;
|
|
31
|
+
}
|
|
32
|
+
const EXIT = {
|
|
33
|
+
"already-full": 0,
|
|
34
|
+
preview: 0,
|
|
35
|
+
declined: 0,
|
|
36
|
+
"handed-off": 0,
|
|
37
|
+
upgraded: 0,
|
|
38
|
+
refused: 1,
|
|
39
|
+
failed: 1,
|
|
40
|
+
};
|
|
41
|
+
function report(result, json) {
|
|
42
|
+
if (json) {
|
|
43
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// The plan was already printed before the question; print it here only for a preview.
|
|
47
|
+
console.log(result.status === "preview"
|
|
48
|
+
? `${result.message}\n\nDry run: nothing was stopped.`
|
|
49
|
+
: result.message);
|
|
50
|
+
}
|
|
51
|
+
export async function runUpgradeCli(options) {
|
|
52
|
+
if (options.socketPath && options.socketName)
|
|
53
|
+
throw new IdeError("Pass --socket-path or --socket-name, not both.", {
|
|
54
|
+
code: "USAGE",
|
|
55
|
+
exitCode: 2,
|
|
56
|
+
});
|
|
57
|
+
if (options.ssh !== undefined) {
|
|
58
|
+
SavedMachineSchema.shape.sshTarget.parse(options.ssh);
|
|
59
|
+
// The remote runs the same command against its own server, bundle and
|
|
60
|
+
// hostname; its prompt answers here through the terminal.
|
|
61
|
+
const child = spawnSync("ssh", [
|
|
62
|
+
...(options.json ? ["-T"] : ["-t"]),
|
|
63
|
+
"--",
|
|
64
|
+
options.ssh,
|
|
65
|
+
remoteTmuxIdeArgsCommand(["servers", "upgrade", ...forwardedUpgradeArgs(options)]),
|
|
66
|
+
], { stdio: "inherit" });
|
|
67
|
+
if (child.error)
|
|
68
|
+
throw new IdeError("Could not start ssh.", { code: "SSH", exitCode: 1 });
|
|
69
|
+
if (child.status !== 0)
|
|
70
|
+
process.exitCode = child.status ?? 1;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (options.continueFrom !== undefined) {
|
|
74
|
+
const work = parseWorkerState(readFileSync(options.continueFrom, "utf8"));
|
|
75
|
+
const io = createUpgradeIo({
|
|
76
|
+
target: { socketPath: work.server.socketPath },
|
|
77
|
+
cliEntry: options.cliEntry,
|
|
78
|
+
json: false,
|
|
79
|
+
});
|
|
80
|
+
// Nothing the foreground's terminal does may stop the worker mid-restore.
|
|
81
|
+
for (const signal of ["SIGHUP", "SIGINT", "SIGPIPE"])
|
|
82
|
+
process.on(signal, () => { });
|
|
83
|
+
let result;
|
|
84
|
+
try {
|
|
85
|
+
result = await finishUpgrade(io, work);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
result = {
|
|
89
|
+
status: "failed",
|
|
90
|
+
message: `${error.message} If the sessions are missing, run: ${retryCommand(work.snapshotPath, work.resumeAgents)}`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
console.log(`${new Date().toISOString()} ${result.status}: ${result.message}`);
|
|
94
|
+
writeWorkerResult(join(dirname(options.continueFrom), "result.json"), result);
|
|
95
|
+
process.exitCode = EXIT[result.status];
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const io = createUpgradeIo({
|
|
99
|
+
target: { socketPath: options.socketPath, socketName: options.socketName },
|
|
100
|
+
cliEntry: options.cliEntry,
|
|
101
|
+
json: options.json,
|
|
102
|
+
});
|
|
103
|
+
const result = await upgradeServer(io, options);
|
|
104
|
+
report(result, options.json);
|
|
105
|
+
process.exitCode = EXIT[result.status];
|
|
106
|
+
}
|