@dreamlake/dreamlake-cli 0.115.0 → 0.116.0

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.
@@ -76,6 +76,8 @@ export const helpExamples = {
76
76
  "hosts ssh": "dl hosts ssh geyang/dev/worker --duration 1800",
77
77
  "exec": "dl exec geyang/dev/worker -- uname -a\ndl exec geyang/dev/worker --timeout 30 -- sh -c 'printf \"%s\\n\" \"$HOME\"'",
78
78
  "hosts exec": "dl hosts exec geyang/dev/worker -- python3 -c 'print(\"hello\")'",
79
+ "tmux": "# Create or return to dl-session on this host\ndl tmux geyang/dev/worker\n# A separate named terminal; --sess and --session are interchangeable\ndl tmux geyang/dev/worker --sess work",
80
+ "hosts tmux": "dl hosts tmux geyang/dev/worker --session work",
79
81
  "hosts upgrade": "dl hosts upgrade geyang/dev/worker --nymph-version 0.1.32 --dry-run\ndl hosts upgrade geyang/dev/worker --nymph-version 0.1.32\ndl hosts upgrade 'geyang/lab/*' --nymph-version 0.1.32 --concurrency 4 --max-failures 2\ndl hosts upgrade --all --namespace geyang --nymph-version 0.1.32 --json",
80
82
  "hosts rollback": "dl hosts rollback geyang/dev/worker\ndl hosts rollback geyang/dev/worker --upgrade-id 20261029-001 --json",
81
83
  "hosts move": "dl hosts move HOST_ID --namespace alice --to acme --dry-run --json",
@@ -100,4 +100,4 @@ export declare const HOST_MATCH_LIMIT = 20;
100
100
  /** The `hosts list` columns for a set of hosts: header row first. */
101
101
  export declare function hostRows(hosts: HostSummary[]): string[][];
102
102
  /** The `hosts list` table restricted to keyword matches, for a terminal reader; `color` adds the highlight. */
103
- export declare function formatHostMatches(result: HostInventory, matches: HostMatches, color: boolean, command?: string, limit?: number): string;
103
+ export declare function formatHostMatches(result: HostInventory, matches: HostMatches, color: boolean, command?: string, limit?: number, suffix?: string): string;
@@ -172,7 +172,7 @@ export function hostRows(hosts) {
172
172
  return [["ID", "NAME", "CATALOG", "CONNECTION"], ...hosts.map(host => [cell(host.id), cell(host.name), cell(host.catalog?.catalogState), hostConnection(host.enrollments)])];
173
173
  }
174
174
  /** The `hosts list` table restricted to keyword matches, for a terminal reader; `color` adds the highlight. */
175
- export function formatHostMatches(result, matches, color, command = "ssh", limit = HOST_MATCH_LIMIT) {
175
+ export function formatHostMatches(result, matches, color, command = "ssh", limit = HOST_MATCH_LIMIT, suffix = "") {
176
176
  const quoted = JSON.stringify(matches.keyword);
177
177
  if (!matches.hosts.length)
178
178
  return `No hosts match ${quoted} in namespace ${result.namespace}. Run dl hosts list --all to see every host.`;
@@ -180,7 +180,7 @@ export function formatHostMatches(result, matches, color, command = "ssh", limit
180
180
  const rows = hostRows(shown);
181
181
  const decorate = (value, row, column) => color && row > 0 && column < 2 ? highlightMatches(value, matches.keyword) : value;
182
182
  const more = matches.hosts.length > shown.length ? ` Showing ${shown.length}; narrow the keyword to see the rest.` : "";
183
- const next = matches.hosts.length === 1 ? `Connect with: dl ${command} ${cell(matches.hosts[0].name)}` : "Connect with the full NAME or ID.";
183
+ const next = matches.hosts.length === 1 ? `Connect with: dl ${command} ${cell(matches.hosts[0].name)}${suffix}` : "Connect with the full NAME or ID.";
184
184
  return [`Hosts matching ${quoted} in namespace ${result.namespace}:`, table(rows, decorate),
185
185
  `${matches.hosts.length} of ${result.total} hosts match.${more} ${next}`].join("\n");
186
186
  }
@@ -10,6 +10,7 @@ export interface PickerIO {
10
10
  columns?: number;
11
11
  };
12
12
  color: boolean;
13
+ suffix?: string;
13
14
  }
14
15
  export interface PickerState {
15
16
  query: string;
@@ -18,7 +19,7 @@ export interface PickerState {
18
19
  /** Matches for what is typed so far; an empty query lists the whole inventory. */
19
20
  export declare function pickerMatches(inventory: HostInventory, query: string): HostMatches;
20
21
  /** One frame of the picker: the command being built, the match table with the cursor row marked, and a count. */
21
- export declare function renderPicker(inventory: HostInventory, selector: string, command: "ssh" | "exec", state: PickerState, color: boolean, limit?: number): string;
22
+ export declare function renderPicker(inventory: HostInventory, selector: string, command: "ssh" | "exec" | "tmux", state: PickerState, color: boolean, limit?: number): string;
22
23
  /** Pure key handling, so the loop and the tests share one definition. */
23
24
  export declare function reducePicker(inventory: HostInventory, state: PickerState, key: string): {
24
25
  state: PickerState;
@@ -31,4 +32,4 @@ export declare function splitKeys(chunk: string): string[];
31
32
  * highlighted; typing filters, Tab completes toward the highlighted host one segment at a time, Enter
32
33
  * resolves to that host's full name, and Esc or Ctrl-C resolves to undefined. Draws on `io.output`.
33
34
  */
34
- export declare function pickHost(inventory: HostInventory, selector: string, command: "ssh" | "exec", io: PickerIO): Promise<string | undefined>;
35
+ export declare function pickHost(inventory: HostInventory, selector: string, command: "ssh" | "exec" | "tmux", io: PickerIO): Promise<string | undefined>;
@@ -92,7 +92,7 @@ export function pickHost(inventory, selector, command, io) {
92
92
  io.input.pause();
93
93
  clear();
94
94
  if (picked !== undefined)
95
- io.output.write(`dl ${command} ${picked}\n`);
95
+ io.output.write(`dl ${command} ${picked}${io.suffix ?? ""}\n`);
96
96
  resolve(picked);
97
97
  };
98
98
  const onData = (chunk) => {
@@ -40,6 +40,7 @@ export interface SshOptions {
40
40
  enrollment?: string;
41
41
  duration?: string;
42
42
  timeout?: string;
43
+ tmuxSession?: string;
43
44
  }
44
45
  export interface SshIO {
45
46
  request: typeof hostRequest;
@@ -51,8 +52,10 @@ export interface SshIO {
51
52
  terminal?: () => boolean;
52
53
  /** Whether a person can also type (stdin is a terminal); only then does the picker replace the static list. */
53
54
  interactive?: () => boolean;
55
+ /** tmux requires terminal input and output, independently of picker availability. */
56
+ tty?: () => boolean;
54
57
  /** The interactive picker: resolves to a full host name, or undefined when the person cancels. */
55
- pick?: (inventory: HostInventory, selector: string, command: 'ssh' | 'exec') => Promise<string | undefined>;
58
+ pick?: (inventory: HostInventory, selector: string, command: 'ssh' | 'exec' | 'tmux', suffix?: string) => Promise<string | undefined>;
56
59
  }
57
60
  export declare const defaultSshIO: SshIO;
58
61
  /** Only a selector that named no host earns suggestions; auth, namespace and transport errors pass through unchanged. */
@@ -63,13 +66,18 @@ export declare function isHostLookupMiss(error: unknown): boolean;
63
66
  */
64
67
  export declare function suggestionInventory(selector: string, opts: SshOptions, io?: SshIO): Promise<HostInventory>;
65
68
  /** The `hosts list` table filtered to the selector's keyword, with every match highlighted, for a terminal reader who cannot type back. */
66
- export declare function suggestHosts(selector: string, opts: SshOptions, command: 'ssh' | 'exec', io?: SshIO): Promise<string>;
69
+ export declare function suggestHosts(selector: string, opts: SshOptions, command: 'ssh' | 'exec' | 'tmux', io?: SshIO): Promise<string>;
67
70
  export declare function chooseSshTarget(targets: SshTarget[], selector: string, opts: SshOptions, argv: string[] | undefined, choose?: SshIO['chooseTarget']): Promise<SshTarget>;
68
71
  export declare function sshPublicKey(value: string): string;
69
72
  export declare function validateSshTarget(t: SshTarget, hostId: string, namespace: string): void;
70
73
  export declare function validateSshSession(s: SshSession, t: SshTarget, previous?: string): string;
71
74
  /** Arguments are quoted individually for the enrolled account's POSIX shell. No implicit shell expansion. */
72
75
  export declare function remoteCommand(argv: string[]): string;
76
+ /** Use the remote login PATH and the same optional systemd scope as browser terminals. */
77
+ export declare function remoteTmuxCommand(session: string): string;
78
+ export declare function runHostTmux(selector: string, opts: SshOptions & {
79
+ session?: string;
80
+ }, io?: SshIO): Promise<number>;
73
81
  /** Bounded nymph-ssh.v1 data/FIN stream. Terminal bytes are never logged or persisted. */
74
82
  export declare class SshRelay extends Duplex {
75
83
  private ws;
@@ -24,7 +24,8 @@ export function busyRetryDelay(attempt, retryAt, now = Date.now()) {
24
24
  export const defaultSshIO = {
25
25
  request: hostRequest, fetch: (...args) => fetch(...args), terminal: () => Boolean(process.stderr.isTTY),
26
26
  interactive: () => Boolean(process.stdin.isTTY && process.stderr.isTTY),
27
- pick: (inventory, selector, command) => pickHost(inventory, selector, command, { input: process.stdin, output: process.stderr, color: !process.env.NO_COLOR }),
27
+ tty: () => Boolean(process.stdin.isTTY && process.stdout.isTTY),
28
+ pick: (inventory, selector, command, suffix) => pickHost(inventory, selector, command, { input: process.stdin, output: process.stderr, color: !process.env.NO_COLOR, suffix }),
28
29
  socket: sshSocket,
29
30
  spawn: args => spawn('ssh', args, { stdio: 'inherit' }),
30
31
  };
@@ -63,7 +64,8 @@ export async function chooseSshTarget(targets, selector, opts, argv, choose) {
63
64
  const options = [opts.namespace ? ['--namespace', opts.namespace] : [],
64
65
  opts.duration ? ['--duration', opts.duration] : [], opts.timeout ? ['--timeout', opts.timeout] : []].flat();
65
66
  const rows = targets.map(t => {
66
- const command = ['dl', argv === undefined ? 'ssh' : 'exec', selector, ...options,
67
+ const command = ['dl', opts.tmuxSession !== undefined ? 'tmux' : argv === undefined ? 'ssh' : 'exec', selector, ...options,
68
+ ...(opts.tmuxSession === undefined ? [] : ['--session', opts.tmuxSession]),
67
69
  '--enrollment', t.enrollmentId, ...(argv === undefined ? [] : ['--', ...argv])];
68
70
  return ` ${label(t)}\n ${command.map(quote).join(' ')}`;
69
71
  });
@@ -115,6 +117,26 @@ export function remoteCommand(argv) {
115
117
  throw new Error('exec requires a bounded command and arguments');
116
118
  return 'exec ' + argv.map(a => "'" + a.replace(/'/g, "'\\''") + "'").join(' ');
117
119
  }
120
+ /** Use the remote login PATH and the same optional systemd scope as browser terminals. */
121
+ export function remoteTmuxCommand(session) {
122
+ if (!/^[A-Za-z0-9_-]{1,64}$/.test(session))
123
+ throw new Error('--session/--sess must be 1–64 letters, digits, underscores or hyphens (a tmux name, not a saved session ID)');
124
+ const script = `s="\${SHELL:-/bin/sh}"
125
+ if ! "$s" -lc 'command -v tmux' >/dev/null 2>&1; then
126
+ printf '%s\\n' 'tmux was not found in the remote login PATH. Install tmux, or use dl ssh with the same host for a plain shell.' >&2
127
+ exit 127
128
+ fi
129
+ r="/run/user/$(id -u)"
130
+ [ -n "$XDG_RUNTIME_DIR" ] || { [ -S "$r/bus" ] && export XDG_RUNTIME_DIR="$r"; }
131
+ if command -v systemd-run >/dev/null 2>&1 && systemd-run --user --scope --quiet --collect true >/dev/null 2>&1; then
132
+ exec systemd-run --user --scope --quiet --collect "$s" -lc 'exec tmux -u new-session -A -s "$1"' dl-tmux "$1"
133
+ fi
134
+ exec "$s" -lc 'exec tmux -u new-session -A -s "$1"' dl-tmux "$1"`;
135
+ return remoteCommand(['/bin/sh', '-c', script, 'dl-tmux', session]);
136
+ }
137
+ export function runHostTmux(selector, opts, io = defaultSshIO) {
138
+ return runHostSsh(selector, { ...opts, tmuxSession: opts.session ?? 'dl-session' }, undefined, io);
139
+ }
118
140
  /** Bounded nymph-ssh.v1 data/FIN stream. Terminal bytes are never logged or persisted. */
119
141
  export class SshRelay extends Duplex {
120
142
  ws;
@@ -161,7 +183,12 @@ export async function runHostSsh(selector, opts, argv, io = defaultSshIO) {
161
183
  throw new Error('Host SSH currently requires Linux or macOS and OpenSSH');
162
184
  if (selector.includes('*'))
163
185
  throw new Error('Select one host, not a wildcard');
164
- const command = argv === undefined ? undefined : remoteCommand(argv);
186
+ const tmux = opts.tmuxSession !== undefined;
187
+ if (tmux && argv !== undefined)
188
+ throw new Error('tmux does not accept a remote command');
189
+ const command = tmux ? remoteTmuxCommand(opts.tmuxSession) : argv === undefined ? undefined : remoteCommand(argv);
190
+ if (tmux && !io.tty?.())
191
+ throw new Error('dl tmux requires an interactive terminal on stdin and stdout; run it in a terminal, or use dl exec for non-interactive commands');
165
192
  const duration = Number(opts.duration ?? 1800), timeout = opts.timeout === undefined ? undefined : Number(opts.timeout);
166
193
  if (!Number.isInteger(duration) || duration < 120 || duration > 1800)
167
194
  throw new Error('--duration must be 120–1800 seconds');
@@ -176,15 +203,16 @@ export async function runHostSsh(selector, opts, argv, io = defaultSshIO) {
176
203
  catch (error) {
177
204
  if (!isHostLookupMiss(error) || !io.terminal?.())
178
205
  throw error;
179
- const command = argv === undefined ? 'ssh' : 'exec';
206
+ const command = tmux ? 'tmux' : argv === undefined ? 'ssh' : 'exec';
207
+ const suffix = tmux ? ` --session ${opts.tmuxSession}` : '';
180
208
  const inventory = await suggestionInventory(selector, opts, io).catch(() => undefined);
181
209
  if (!inventory)
182
210
  throw error;
183
211
  if (!io.interactive?.() || !io.pick) {
184
- throw new Error(`${error instanceof Error ? error.message : 'Host lookup failed'}\n${formatHostMatches(inventory, matchHosts(inventory.hosts, selector), !process.env.NO_COLOR, command)}`);
212
+ throw new Error(`${error instanceof Error ? error.message : 'Host lookup failed'}\n${formatHostMatches(inventory, matchHosts(inventory.hosts, selector), !process.env.NO_COLOR, command, undefined, suffix)}`);
185
213
  }
186
214
  // A person is typing: let them pick the host they meant. Cancelling keeps the original error and exit code.
187
- const picked = await io.pick(inventory, selector, command);
215
+ const picked = await io.pick(inventory, selector, command, suffix);
188
216
  if (picked === undefined)
189
217
  throw error;
190
218
  selector = picked;
@@ -313,7 +341,7 @@ export async function runHostSsh(selector, opts, argv, io = defaultSshIO) {
313
341
  '-o', 'StrictHostKeyChecking=yes', '-o', `UserKnownHostsFile=${knownHosts}`, '-o', 'GlobalKnownHostsFile=/dev/null',
314
342
  '-o', `HostKeyAlias=${alias}`, '-o', 'CheckHostIP=no', '-o', 'ForwardAgent=no', '-o', 'ClearAllForwardings=yes',
315
343
  '-o', 'ControlMaster=no', '-o', 'ProxyCommand=none', '-o', 'ConnectTimeout=15', '-o', 'LogLevel=ERROR',
316
- '-i', key, '-p', String(address.port), '-l', target.username, command === undefined ? '-tt' : '-T', '127.0.0.1', ...(command === undefined ? [] : [command])];
344
+ '-i', key, '-p', String(address.port), '-l', target.username, command === undefined || tmux ? '-tt' : '-T', '127.0.0.1', ...(command === undefined ? [] : [command])];
317
345
  child = io.spawn(args);
318
346
  const result = new Promise((resolve, reject) => {
319
347
  child.once('error', () => reject(new Error('Could not start OpenSSH; install ssh and ssh-keygen')));
@@ -348,15 +376,17 @@ export async function runHostSsh(selector, opts, argv, io = defaultSshIO) {
348
376
  }
349
377
  export function registerHostSshCommands(hosts, program) {
350
378
  for (const parent of [hosts, program])
351
- for (const name of ['ssh', 'exec']) {
352
- const c = parent.command(name).description(name === 'ssh' ? 'open a pinned SSH shell through the enrolled Nymph relay' : 'run a command over SSH; stream output and return its exit code')
379
+ for (const name of ['ssh', 'exec', 'tmux']) {
380
+ const c = parent.command(name).description(name === 'tmux' ? 'create or attach to a named remote tmux session through the enrolled SSH relay' : name === 'ssh' ? 'open a pinned SSH shell through the enrolled Nymph relay' : 'run a command over SSH; stream output and return its exit code')
353
381
  .argument('<host>', 'host ID or namespace/group/host[/user]').option('--namespace <slug>').option('--enrollment <id>', 'select an exact SSH enrollment')
354
382
  .option('--duration <seconds>', 'maximum session lifetime (120–1800)', '1800').option('--timeout <seconds>', 'close after this many seconds; does not guarantee detached process termination');
383
+ if (name === 'tmux')
384
+ c.option('--sess, --session <name>', 'remote tmux name; separate from host and saved agent sessions', 'dl-session');
355
385
  if (name === 'exec')
356
386
  c.argument('<command...>', 'command and literal arguments after --');
357
387
  const action = async (selector, opts, args) => {
358
388
  try {
359
- process.exitCode = await runHostSsh(selector, opts, args);
389
+ process.exitCode = await (name === 'tmux' ? runHostTmux(selector, opts) : runHostSsh(selector, opts, args));
360
390
  }
361
391
  catch (e) {
362
392
  console.error(e instanceof Error ? e.message : 'SSH failed');
@@ -1 +1 @@
1
- export declare const VERSION = "0.115.0";
1
+ export declare const VERSION = "0.116.0";
@@ -6,4 +6,4 @@
6
6
  // value means a binary that re-installs the same version forever.
7
7
  //
8
8
  // Editing this by hand does nothing for a release; bump package.json.
9
- export const VERSION = "0.115.0";
9
+ export const VERSION = "0.116.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamlake/dreamlake-cli",
3
- "version": "0.115.0",
3
+ "version": "0.116.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dreamlake-ai/dreamlake-cli.git"
@@ -37,13 +37,13 @@
37
37
  "node": ">=18"
38
38
  },
39
39
  "optionalDependencies": {
40
- "@dreamlake/dreamlake-cli-darwin-arm64": "0.115.0",
41
- "@dreamlake/dreamlake-cli-darwin-x64": "0.115.0",
42
- "@dreamlake/dreamlake-cli-linux-x64": "0.115.0",
43
- "@dreamlake/dreamlake-cli-linux-arm64": "0.115.0",
44
- "@dreamlake/dreamlake-cli-linux-x64-musl": "0.115.0",
45
- "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.115.0",
46
- "@dreamlake/dreamlake-cli-win32-x64": "0.115.0",
47
- "@dreamlake/dreamlake-cli-win32-arm64": "0.115.0"
40
+ "@dreamlake/dreamlake-cli-darwin-arm64": "0.116.0",
41
+ "@dreamlake/dreamlake-cli-darwin-x64": "0.116.0",
42
+ "@dreamlake/dreamlake-cli-linux-x64": "0.116.0",
43
+ "@dreamlake/dreamlake-cli-linux-arm64": "0.116.0",
44
+ "@dreamlake/dreamlake-cli-linux-x64-musl": "0.116.0",
45
+ "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.116.0",
46
+ "@dreamlake/dreamlake-cli-win32-x64": "0.116.0",
47
+ "@dreamlake/dreamlake-cli-win32-arm64": "0.116.0"
48
48
  }
49
49
  }