@devframes/plugin-code-server 0.7.5 → 0.7.6

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,2 +1,2 @@
1
- import { a as SESSION_COOKIE_BASE, c as TERMINAL_SESSION_TITLE, i as PLUGIN_ID, l as getCookieSessionName, n as DEFAULT_PORT, o as STATE_KEY, r as DEFAULT_START_TIMEOUT, s as TERMINAL_SESSION_ICON, t as DEFAULT_CODE_SERVER_PORT } from "./constants-DZKOXnxd.mjs";
1
+ import { a as SESSION_COOKIE_BASE, c as TERMINAL_SESSION_TITLE, i as PLUGIN_ID, l as getCookieSessionName, n as DEFAULT_PORT, o as STATE_KEY, r as DEFAULT_START_TIMEOUT, s as TERMINAL_SESSION_ICON, t as DEFAULT_CODE_SERVER_PORT } from "./constants-DtQz38ex.mjs";
2
2
  export { DEFAULT_CODE_SERVER_PORT, DEFAULT_PORT, DEFAULT_START_TIMEOUT, PLUGIN_ID, SESSION_COOKIE_BASE, STATE_KEY, TERMINAL_SESSION_ICON, TERMINAL_SESSION_TITLE, getCookieSessionName };
@@ -3,16 +3,16 @@
3
3
  const PLUGIN_ID = "devframes_plugin_code-server";
4
4
  /**
5
5
  * Shared-state key holding the serializable, secret-free server status and
6
- * detection result. The authentication cookie is never published here — it
7
- * is returned only from the `start` / `status` RPCs to the already-authorized
8
- * client (see {@link CodeServerAuth}).
6
+ * detection result. Authentication material is never published here — it is
7
+ * returned only from the `start` / `status` RPCs to the already-authorized
8
+ * client (see {@link import('./types').CodeServerConnect}).
9
9
  */
10
10
  const STATE_KEY = "devframes:plugin:code-server:state";
11
11
  /** Default dev-server port for the plugin's own launcher SPA (standalone CLI). */
12
12
  const DEFAULT_PORT = 9013;
13
- /** Preferred port for the spawned code-server process (falls back if taken). */
13
+ /** Preferred port for the spawned editor process (falls back if taken). */
14
14
  const DEFAULT_CODE_SERVER_PORT = 8080;
15
- /** How long to wait for code-server to answer its `/healthz` probe. */
15
+ /** How long to wait for the editor to answer its readiness probe. */
16
16
  const DEFAULT_START_TIMEOUT = 3e4;
17
17
  /** code-server's session cookie base name (see `getCookieSessionName`). */
18
18
  const SESSION_COOKIE_BASE = "code-server-session";
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { CodeServerAuth, CodeServerDetection, CodeServerOptions, CodeServerServerInfo, CodeServerSharedState, CodeServerStartRequest, CodeServerStartResult, CodeServerStatus, CodeServerStatusResult } from "./types.mjs";
2
- import { i as PLUGIN_ID, l as getCookieSessionName, n as DEFAULT_PORT, o as STATE_KEY, t as DEFAULT_CODE_SERVER_PORT } from "./constants-DZKOXnxd.mjs";
1
+ import { CodeServerBackend, CodeServerConnect, CodeServerDetection, CodeServerLogin, CodeServerMode, CodeServerOptions, CodeServerServerInfo, CodeServerSharedState, CodeServerStartRequest, CodeServerStartResult, CodeServerStatus, CodeServerStatusResult, CodeServerTunnelOptions } from "./types.mjs";
2
+ import { i as PLUGIN_ID, l as getCookieSessionName, n as DEFAULT_PORT, o as STATE_KEY, t as DEFAULT_CODE_SERVER_PORT } from "./constants-DtQz38ex.mjs";
3
3
  import { DevframeDefinition } from "devframe/types";
4
4
  //#region src/index.d.ts
5
5
  /**
@@ -22,4 +22,4 @@ declare function createCodeServerDevframe(options?: CodeServerOptions): Devframe
22
22
  /** Default-configured code-server devframe. */
23
23
  declare const codeServer: DevframeDefinition;
24
24
  //#endregion
25
- export { type CodeServerAuth, type CodeServerDetection, type CodeServerOptions, type CodeServerServerInfo, type CodeServerSharedState, type CodeServerStartRequest, type CodeServerStartResult, type CodeServerStatus, type CodeServerStatusResult, DEFAULT_CODE_SERVER_PORT, DEFAULT_PORT, PLUGIN_ID, STATE_KEY, createCodeServerDevframe, codeServer as default, getCookieSessionName };
25
+ export { type CodeServerBackend, type CodeServerConnect, type CodeServerDetection, type CodeServerLogin, type CodeServerMode, type CodeServerOptions, type CodeServerServerInfo, type CodeServerSharedState, type CodeServerStartRequest, type CodeServerStartResult, type CodeServerStatus, type CodeServerStatusResult, type CodeServerTunnelOptions, DEFAULT_CODE_SERVER_PORT, DEFAULT_PORT, PLUGIN_ID, STATE_KEY, createCodeServerDevframe, codeServer as default, getCookieSessionName };
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { n as createCodeServerDevframe, t as codeServer } from "./src-CjjdHGFH.mjs";
1
+ import { n as createCodeServerDevframe, t as codeServer } from "./src-EUgoe7om.mjs";
2
2
  import { DEFAULT_CODE_SERVER_PORT, DEFAULT_PORT, PLUGIN_ID, STATE_KEY, getCookieSessionName } from "./constants.mjs";
3
3
  export { DEFAULT_CODE_SERVER_PORT, DEFAULT_PORT, PLUGIN_ID, STATE_KEY, createCodeServerDevframe, codeServer as default, getCookieSessionName };
@@ -1,34 +1,49 @@
1
- import { CodeServerDetection, CodeServerOptions, CodeServerStartRequest, CodeServerStartResult, CodeServerStatusResult } from "../types.mjs";
1
+ import { CodeServerBackend, CodeServerConnect, CodeServerDetection, CodeServerLogin, CodeServerMode, CodeServerOptions, CodeServerStartRequest, CodeServerStartResult, CodeServerStatusResult } from "../types.mjs";
2
2
  import { DevframeNodeContext } from "devframe/types";
3
3
  import { Diagnostic } from "nostics";
4
4
  //#region src/node/supervisor.d.ts
5
5
  /**
6
- * Owns the lifecycle of a single code-server child process: detects the
7
- * binary, launches it with a freshly generated password-auth token, probes
8
- * `/healthz` for readiness, and mirrors a secret-free status into shared
9
- * state. The auth cookie is handed back only through `start()` / `status()`
10
- * so the already-authorized client can sign the iframe in automatically.
6
+ * Owns the lifecycle of a single editor child process. Resolves a launch
7
+ * {@link CodeServerProfile} (Coder `code-server`, Microsoft `code serve-web`,
8
+ * or `code tunnel`), detects the binary, launches it with freshly generated
9
+ * auth material, waits for readiness, and mirrors a secret-free status into
10
+ * shared state. The connect descriptor (session cookie / connection token /
11
+ * tunnel URL) is handed back only through `start()` / `status()` so the
12
+ * already-authorized client can open the editor without a login page.
11
13
  *
12
14
  * Depends only on the core devframe context (shared state), not on the hub.
13
15
  */
14
16
  declare class CodeServerSupervisor {
15
17
  private readonly ctx;
16
- private readonly bin;
18
+ private readonly mode;
19
+ private readonly explicitBackend?;
20
+ private readonly explicitBin?;
17
21
  private readonly workspace;
18
22
  private readonly host;
19
23
  private readonly forcedPort?;
20
24
  private readonly extraArgs;
21
25
  private readonly extraEnv;
22
- private readonly cookieName;
23
26
  private readonly cookieSuffix?;
27
+ private readonly cookieName;
24
28
  private readonly startTimeout;
29
+ private readonly reuseExistingServer;
30
+ private readonly tunnelName;
31
+ /** Resolved after the first detection. */
32
+ private backend;
33
+ private bin;
34
+ private profile;
25
35
  private state?;
26
36
  private detection;
27
37
  private server;
28
38
  private proc?;
29
- private cookieValue?;
39
+ /** Context of the live launch, used to compute the client connect descriptor. */
40
+ private launchCtx?;
41
+ /** Whether the running server was adopted (reused) rather than launched. */
42
+ private adopted;
43
+ /** Captured `vscode.dev` URL for a running tunnel. */
44
+ private readyUrl?;
30
45
  private logBuffer;
31
- private cleanupRegistered;
46
+ private exitHandler?;
32
47
  /** Stable id of the hub terminal session, reused across start/stop. */
33
48
  private readonly sessionId;
34
49
  /** The live hub terminal session when launched through `ctx.terminals`. */
@@ -36,21 +51,41 @@ declare class CodeServerSupervisor {
36
51
  constructor(ctx: DevframeNodeContext, options?: CodeServerOptions);
37
52
  /** Resolve shared state, register process-exit cleanup, run first detection. */
38
53
  init(): Promise<void>;
39
- /** Re-probe for the code-server binary and publish the result. */
54
+ /**
55
+ * Probe for a usable editor binary and publish the result. Resolves the
56
+ * backend + binary when the caller left them implicit: tunnel mode always
57
+ * uses `code`; an explicit backend or `bin` is honored as-is; otherwise the
58
+ * plugin tries each {@link AUTO_DETECT_ORDER} candidate and keeps the first
59
+ * that is installed.
60
+ */
40
61
  detect(): Promise<CodeServerDetection>;
41
- /** Current status (+ auth when running) for the launcher UI. */
62
+ /** Current status (+ connect info when running) for the launcher UI. */
42
63
  status(): CodeServerStatusResult;
43
64
  /**
44
- * Launch code-server (if not already up) and resolve once it answers its
45
- * readiness probe. Idempotent while starting/running — returns the live
46
- * status instead of spawning a second process.
65
+ * Launch the editor (if not already up) and resolve once it is reachable.
66
+ * Idempotent while starting/running — returns the live status instead of
67
+ * spawning a second process. In tunnel mode it resolves as soon as either
68
+ * the `vscode.dev` URL or a device-login prompt is seen, so the action never
69
+ * blocks on interactive authentication.
47
70
  */
48
71
  start(req?: CodeServerStartRequest): Promise<CodeServerStartResult>;
49
- /** Stop the code-server process and reset to `stopped`. */
72
+ /** Stop the editor process and reset to `stopped`. */
50
73
  stop(): CodeServerStatusResult;
51
74
  /** Kill the process on host shutdown / test teardown. */
52
75
  dispose(): void;
53
- private authInfo;
76
+ /** Resolved backend for tests / callers. */
77
+ get resolvedBackend(): CodeServerBackend;
78
+ private setResolved;
79
+ private baseCtx;
80
+ /** Clear per-launch process state (keeps `server`/`detection`). */
81
+ private reset;
82
+ /**
83
+ * Resolve start() for a tunnel: succeed as soon as the `vscode.dev` URL
84
+ * appears (→ running) or a device-login prompt is seen (→ starting, so the
85
+ * user can authenticate while the log stream continues to a running URL).
86
+ */
87
+ private awaitTunnel;
88
+ private connectInfo;
54
89
  private terminate;
55
90
  /**
56
91
  * Resolve the hub's terminals subsystem when this devframe is mounted in a
@@ -62,24 +97,78 @@ declare class CodeServerSupervisor {
62
97
  /** Update the mirrored hub terminal session's status, when one exists. */
63
98
  private reflectHub;
64
99
  /**
65
- * Launch code-server. In a hub, spawn it through `ctx.terminals` so it shows
66
- * up as a read-only terminal session (proper icon + name) whose output the
67
- * hub streams to its terminals panel; standalone, spawn it directly. Either
68
- * way, return the underlying {@link ChildProcess} so the shared readiness /
69
- * port / log wiring in `start()` is identical.
100
+ * Launch the editor binary. In a hub, spawn it through `ctx.terminals` so it
101
+ * shows up as a read-only terminal session (proper icon + name) whose output
102
+ * the hub streams to its terminals panel; standalone, spawn it directly.
103
+ * Either way, return the underlying {@link ChildProcess} so the shared
104
+ * readiness / port / log wiring in `start()` is identical.
70
105
  */
71
106
  private launchProcess;
72
107
  private appendLog;
73
108
  private lastLog;
74
109
  private publish;
75
110
  /**
76
- * Poll code-server's unauthenticated `/healthz` endpoint until it responds
77
- * or the timeout elapses. Returns false if the process exits first.
111
+ * Poll the server's readiness path until it responds or the timeout elapses.
112
+ * Returns false if the process exits first.
78
113
  */
79
114
  private waitForReady;
80
115
  private registerCleanup;
81
116
  }
82
117
  //#endregion
118
+ //#region src/node/backends.d.ts
119
+ /**
120
+ * The internal launch profile the supervisor drives. One of three "kinds":
121
+ * the two local {@link CodeServerBackend}s plus the `code tunnel` profile
122
+ * selected by `mode: 'tunnel'`. Each profile owns the backend-specific pieces
123
+ * — binary, arguments, auth env, readiness detection, and how the client
124
+ * ultimately reaches the editor — while the supervisor owns the shared
125
+ * spawn / log / publish lifecycle.
126
+ */
127
+ type CodeServerProfileKind = 'code-server' | 'serve-web' | 'tunnel';
128
+ /** Everything a profile needs to build a launch and the client's connect info. */
129
+ interface ProfileContext {
130
+ host: string;
131
+ /** Resolved local port (0 until dynamically allocated). Unused by tunnel. */
132
+ port: number;
133
+ folder: string;
134
+ /** Fresh per-launch secret (session token / connection token). */
135
+ secret: string;
136
+ /** Session cookie name for the `code-server` backend. */
137
+ cookieName: string;
138
+ extraArgs: string[];
139
+ /** Machine name for the tunnel profile. */
140
+ tunnelName: string;
141
+ }
142
+ interface CodeServerProfile {
143
+ kind: CodeServerProfileKind;
144
+ /** Public backend id (tunnel reports `ms-code-serve-web`'s sibling `code` binary). */
145
+ backend: CodeServerBackend;
146
+ /** Default binary when the caller doesn't override `bin`. */
147
+ defaultBin: string;
148
+ /** Build the argv passed to the binary. */
149
+ buildArgs: (c: ProfileContext) => string[];
150
+ /** Merge auth material into the child environment. */
151
+ buildEnv: (c: ProfileContext, base: Record<string, string>) => Record<string, string>;
152
+ /** Local readiness path polled over HTTP, or `null` for log-driven (tunnel). */
153
+ healthPath: string | null;
154
+ /** Parse a log line for a dynamically-bound local port. */
155
+ matchPort?: (line: string) => number | undefined;
156
+ /** Parse a log line for the tunnel's `vscode.dev` URL (marks it ready). */
157
+ matchReadyUrl?: (line: string) => string | undefined;
158
+ /** Parse a log line for a device-login prompt. */
159
+ matchLogin?: (line: string) => CodeServerLogin | undefined;
160
+ /** Compute the client connect descriptor for a freshly launched server. */
161
+ connect: (c: ProfileContext & {
162
+ readyUrl?: string;
163
+ }) => CodeServerConnect;
164
+ /** Connect descriptor for an adopted (reused) server we didn't launch. */
165
+ connectReused: (c: {
166
+ port: number;
167
+ }) => CodeServerConnect;
168
+ }
169
+ /** Resolve the launch profile for a mode + backend. */
170
+ declare function resolveProfile(mode: CodeServerMode, backend: CodeServerBackend): CodeServerProfile;
171
+ //#endregion
83
172
  //#region src/node/context.d.ts
84
173
  declare function setCodeServerSupervisor(ctx: DevframeNodeContext, supervisor: CodeServerSupervisor): void;
85
174
  declare function getCodeServerSupervisor(ctx: DevframeNodeContext): CodeServerSupervisor;
@@ -119,14 +208,14 @@ declare const diagnostics: import("nostics").Diagnostics<{
119
208
  readonly why: (p: {
120
209
  bin: string;
121
210
  }) => string;
122
- readonly fix: "Install code-server — e.g. `curl -fsSL https://code-server.dev/install.sh | sh` — or set the `bin` option to its path. See https://coder.com/docs/code-server/latest/install";
211
+ readonly fix: "Install Coder code-server (`curl -fsSL https://code-server.dev/install.sh | sh`) or the Microsoft `code` CLI, or set the `bin` option to its path. See https://coder.com/docs/code-server/latest/install";
123
212
  };
124
213
  readonly DP_CODE_SERVER_0002: {
125
214
  readonly why: (p: {
126
215
  port: number;
127
216
  timeout: number;
128
217
  }) => string;
129
- readonly fix: "Check the code-server logs for startup errors, raise `startTimeout`, or free the port.";
218
+ readonly fix: "Check the editor logs for startup errors, raise `startTimeout`, or free the port.";
130
219
  };
131
220
  readonly DP_CODE_SERVER_0003: {
132
221
  readonly why: (p: {
@@ -144,6 +233,12 @@ declare const diagnostics: import("nostics").Diagnostics<{
144
233
  }) => string;
145
234
  readonly fix: "Inspect the captured output in the launcher and re-launch.";
146
235
  };
236
+ readonly DP_CODE_SERVER_0006: {
237
+ readonly why: (p: {
238
+ timeout: number;
239
+ }) => string;
240
+ readonly fix: "Check the tunnel logs, ensure the `code` CLI is signed in, or raise `startTimeout`.";
241
+ };
147
242
  }, readonly [typeof reporter]>;
148
243
  //#endregion
149
244
  //#region src/node/index.d.ts
@@ -158,4 +253,4 @@ declare const diagnostics: import("nostics").Diagnostics<{
158
253
  */
159
254
  declare function setupCodeServer(ctx: DevframeNodeContext, options?: CodeServerOptions): Promise<CodeServerSupervisor>;
160
255
  //#endregion
161
- export { CodeServerSupervisor, detectCodeServer, diagnostics, getCodeServerSupervisor, setCodeServerSupervisor, setupCodeServer };
256
+ export { type CodeServerProfile, type CodeServerProfileKind, CodeServerSupervisor, detectCodeServer, diagnostics, getCodeServerSupervisor, resolveProfile, setCodeServerSupervisor, setupCodeServer };