vmsan 0.1.0-alpha.13 → 0.1.0-alpha.15

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.
@@ -1,13 +1,57 @@
1
- import { l as agentTimeoutError } from "./errors.mjs";
2
- async function waitForAgent(guestIp, port, timeoutMs = 6e4) {
3
- const start = Date.now();
4
- const url = `http://${guestIp}:${port}/health`;
5
- while (Date.now() - start < timeoutMs) {
1
+ import { n as vmsanPaths } from "./paths.mjs";
2
+ import { t as handleCommandError } from "./errors.mjs";
3
+ import { t as createCommandLogger } from "./logger.mjs";
4
+ import "./vm-state.mjs";
5
+ import { n as waitForAgent, t as resolveVmState } from "./vm-context.mjs";
6
+ import { t as ShellSession } from "./shell.mjs";
7
+ import { consola } from "consola";
8
+ import { defineCommand } from "citty";
9
+ const connectCommand = defineCommand({
10
+ meta: {
11
+ name: "connect",
12
+ description: "Connect to a running VM"
13
+ },
14
+ args: {
15
+ vmId: {
16
+ type: "positional",
17
+ description: "VM ID to connect to",
18
+ required: true
19
+ },
20
+ session: {
21
+ type: "string",
22
+ alias: "s",
23
+ description: "Attach to an existing shell session ID",
24
+ required: false
25
+ }
26
+ },
27
+ async run({ args }) {
28
+ const cmdLog = createCommandLogger("connect");
29
+ const paths = vmsanPaths();
6
30
  try {
7
- if ((await fetch(url, { signal: AbortSignal.timeout(2e3) })).ok) return;
8
- } catch {}
9
- await new Promise((r) => setTimeout(r, 500));
31
+ const { state, guestIp, port } = resolveVmState(args.vmId, paths);
32
+ const log = consola.withTag(args.vmId);
33
+ consola.debug(`Agent endpoint: ${guestIp}:${port}`);
34
+ log.start("Waiting for agent to become ready...");
35
+ await waitForAgent(guestIp, port);
36
+ log.success("Agent is ready. Connecting via PTY shell...");
37
+ const shell = new ShellSession({
38
+ host: guestIp,
39
+ port,
40
+ token: state.agentToken,
41
+ sessionId: args.session
42
+ });
43
+ const closeInfo = await shell.connect();
44
+ cmdLog.set({
45
+ vmId: args.vmId,
46
+ method: "pty"
47
+ });
48
+ cmdLog.emit();
49
+ if (!closeInfo.sessionDestroyed && shell.sessionId) process.stderr.write(`\nResume this session with:\n vmsan connect ${args.vmId} --session ${shell.sessionId}\n`);
50
+ process.exit(0);
51
+ } catch (error) {
52
+ handleCommandError(error, cmdLog);
53
+ process.exit(1);
54
+ }
10
55
  }
11
- throw agentTimeoutError(guestIp, timeoutMs);
12
- }
13
- export { waitForAgent as t };
56
+ });
57
+ export { connectCommand as default };