forge-cw 0.1.20 → 0.1.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/dist/index.js +192 -59
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -469,25 +469,81 @@ var init_action_params = __esm({
|
|
|
469
469
|
});
|
|
470
470
|
|
|
471
471
|
// ../core/dist/auth.js
|
|
472
|
+
import { createHash, timingSafeEqual } from "node:crypto";
|
|
473
|
+
function sameToken(expected, provided) {
|
|
474
|
+
if (!provided)
|
|
475
|
+
return false;
|
|
476
|
+
const a = createHash("sha256").update(expected).digest();
|
|
477
|
+
const b = createHash("sha256").update(provided).digest();
|
|
478
|
+
return timingSafeEqual(a, b);
|
|
479
|
+
}
|
|
480
|
+
function cookieValue(cookieHeader, name) {
|
|
481
|
+
if (!cookieHeader)
|
|
482
|
+
return void 0;
|
|
483
|
+
for (const part of cookieHeader.split(";")) {
|
|
484
|
+
const eq = part.indexOf("=");
|
|
485
|
+
if (eq === -1)
|
|
486
|
+
continue;
|
|
487
|
+
if (part.slice(0, eq).trim() === name) {
|
|
488
|
+
try {
|
|
489
|
+
return decodeURIComponent(part.slice(eq + 1).trim());
|
|
490
|
+
} catch {
|
|
491
|
+
return void 0;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return void 0;
|
|
496
|
+
}
|
|
497
|
+
function isAuthorized(token, authorization, cookieHeader) {
|
|
498
|
+
if (authorization?.startsWith("Bearer ") && sameToken(token, authorization.slice(7)))
|
|
499
|
+
return true;
|
|
500
|
+
return sameToken(token, cookieValue(cookieHeader, AUTH_COOKIE));
|
|
501
|
+
}
|
|
472
502
|
function bearerAuth(token) {
|
|
473
503
|
return async (c, next) => {
|
|
474
504
|
if (c.req.path === "/api/health") {
|
|
475
505
|
return next();
|
|
476
506
|
}
|
|
477
|
-
|
|
478
|
-
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
479
|
-
return c.json({ error: "Unauthorized" }, 401);
|
|
480
|
-
}
|
|
481
|
-
const provided = authHeader.slice(7);
|
|
482
|
-
if (provided !== token) {
|
|
507
|
+
if (!isAuthorized(token, c.req.header("Authorization"), c.req.header("Cookie"))) {
|
|
483
508
|
return c.json({ error: "Unauthorized" }, 401);
|
|
484
509
|
}
|
|
485
510
|
return next();
|
|
486
511
|
};
|
|
487
512
|
}
|
|
513
|
+
function mountAuthRoute(app, token) {
|
|
514
|
+
app.get("/auth", (c) => {
|
|
515
|
+
if (!sameToken(token, c.req.query("token"))) {
|
|
516
|
+
return c.text("Wrong or missing token. Open the link Forge printed when it started.", 401);
|
|
517
|
+
}
|
|
518
|
+
const https = new URL(c.req.url).protocol === "https:" || c.req.header("X-Forwarded-Proto") === "https";
|
|
519
|
+
const cookie = [
|
|
520
|
+
`${AUTH_COOKIE}=${encodeURIComponent(token)}`,
|
|
521
|
+
"Path=/",
|
|
522
|
+
"HttpOnly",
|
|
523
|
+
"SameSite=Strict",
|
|
524
|
+
"Max-Age=2592000",
|
|
525
|
+
...https ? ["Secure"] : []
|
|
526
|
+
].join("; ");
|
|
527
|
+
c.header("Set-Cookie", cookie);
|
|
528
|
+
c.header("Cache-Control", "no-store");
|
|
529
|
+
return c.redirect("/", 302);
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
function remoteAuthProblem(localOnly, token) {
|
|
533
|
+
if (localOnly)
|
|
534
|
+
return null;
|
|
535
|
+
if (!token)
|
|
536
|
+
return "Forge would be reachable from other machines (FORGE_HOST or team mode) and needs FORGE_AUTH_TOKEN. Set one, for example: FORGE_AUTH_TOKEN=$(openssl rand -hex 24)";
|
|
537
|
+
if (token.length < MIN_TOKEN_LENGTH)
|
|
538
|
+
return `FORGE_AUTH_TOKEN must be at least ${MIN_TOKEN_LENGTH} characters, for example: FORGE_AUTH_TOKEN=$(openssl rand -hex 24)`;
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
541
|
+
var AUTH_COOKIE, MIN_TOKEN_LENGTH;
|
|
488
542
|
var init_auth = __esm({
|
|
489
543
|
"../core/dist/auth.js"() {
|
|
490
544
|
"use strict";
|
|
545
|
+
AUTH_COOKIE = "forge_token";
|
|
546
|
+
MIN_TOKEN_LENGTH = 16;
|
|
491
547
|
}
|
|
492
548
|
});
|
|
493
549
|
|
|
@@ -1354,7 +1410,7 @@ var init_usage_window = __esm({
|
|
|
1354
1410
|
|
|
1355
1411
|
// ../core/dist/usage-claude.js
|
|
1356
1412
|
import { execFile as execFile3 } from "node:child_process";
|
|
1357
|
-
import { createHash } from "node:crypto";
|
|
1413
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
1358
1414
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
1359
1415
|
import { homedir } from "node:os";
|
|
1360
1416
|
import { join as join5 } from "node:path";
|
|
@@ -1389,7 +1445,7 @@ function claudeKeychainService(configDir) {
|
|
|
1389
1445
|
const dir = configDir.replace(/\/+$/, "");
|
|
1390
1446
|
if (dir === join5(homedir(), ".claude"))
|
|
1391
1447
|
return KEYCHAIN_SERVICE;
|
|
1392
|
-
return `${KEYCHAIN_SERVICE}-${
|
|
1448
|
+
return `${KEYCHAIN_SERVICE}-${createHash2("sha256").update(dir).digest("hex").slice(0, 8)}`;
|
|
1393
1449
|
}
|
|
1394
1450
|
async function readFromKeychain(service) {
|
|
1395
1451
|
try {
|
|
@@ -3901,7 +3957,7 @@ function takeSession(reader, project, sessionDir, general) {
|
|
|
3901
3957
|
const known = general?.get(sessionId);
|
|
3902
3958
|
return known ? { session: known, isNew: true } : null;
|
|
3903
3959
|
}
|
|
3904
|
-
function createTerminalWss(manager, reader, { localOnly = true, general } = {}) {
|
|
3960
|
+
function createTerminalWss(manager, reader, { localOnly = true, authToken, general } = {}) {
|
|
3905
3961
|
const wss = new WebSocketServer({ noServer: true });
|
|
3906
3962
|
function wireWs(ws, sessionId, project, sessionDir) {
|
|
3907
3963
|
const client = {
|
|
@@ -3970,6 +4026,10 @@ function createTerminalWss(manager, reader, { localOnly = true, general } = {})
|
|
|
3970
4026
|
socket.destroy();
|
|
3971
4027
|
return;
|
|
3972
4028
|
}
|
|
4029
|
+
if (authToken && !isAuthorized(authToken, request.headers.authorization, request.headers.cookie)) {
|
|
4030
|
+
socket.end("HTTP/1.1 401 Unauthorized\r\nConnection: close\r\n\r\n");
|
|
4031
|
+
return;
|
|
4032
|
+
}
|
|
3973
4033
|
const url = new URL(request.url ?? "/", "http://localhost");
|
|
3974
4034
|
const parsed = parseTerminalUpgradeUrl(url.pathname);
|
|
3975
4035
|
if (parsed) {
|
|
@@ -4004,6 +4064,7 @@ var init_pty_routes = __esm({
|
|
|
4004
4064
|
"use strict";
|
|
4005
4065
|
init_cw_routes();
|
|
4006
4066
|
init_origin_guard();
|
|
4067
|
+
init_auth();
|
|
4007
4068
|
REFUSED_CLOSE_CODE = 4404;
|
|
4008
4069
|
}
|
|
4009
4070
|
});
|
|
@@ -4267,7 +4328,7 @@ var init_liveframe_routes = __esm({
|
|
|
4267
4328
|
|
|
4268
4329
|
// ../core/dist/cw-install.js
|
|
4269
4330
|
import { execFile as execFile5 } from "node:child_process";
|
|
4270
|
-
import { createHash as
|
|
4331
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
4271
4332
|
import { accessSync as accessSync2, constants as constants2, existsSync as existsSync11, readFileSync as readFileSync9, statSync as statSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
4272
4333
|
import { delimiter as delimiter2, join as join12 } from "node:path";
|
|
4273
4334
|
function readCwVersion(file) {
|
|
@@ -4384,7 +4445,7 @@ var init_cw_install = __esm({
|
|
|
4384
4445
|
MARKER_FILE = ".forge-cw.json";
|
|
4385
4446
|
INSTALL_TIMEOUT_MS2 = 12e4;
|
|
4386
4447
|
ANSI_RE3 = /\u001b\[[0-9;?]*[A-Za-z]/g;
|
|
4387
|
-
sha256Of = (file) =>
|
|
4448
|
+
sha256Of = (file) => createHash3("sha256").update(readFileSync9(file)).digest("hex");
|
|
4388
4449
|
runInstall = (script, args, env) => new Promise((resolve11) => {
|
|
4389
4450
|
execFile5("bash", [script, ...args], { env, timeout: INSTALL_TIMEOUT_MS2, maxBuffer: 1024 * 1024 }, (err, stdout, stderr) => {
|
|
4390
4451
|
const output = `${String(stdout)}${String(stderr)}`;
|
|
@@ -7819,9 +7880,9 @@ var init_module_host = __esm({
|
|
|
7819
7880
|
});
|
|
7820
7881
|
|
|
7821
7882
|
// ../core/dist/module-confirmations.js
|
|
7822
|
-
import { createHash as
|
|
7883
|
+
import { createHash as createHash4, randomBytes } from "node:crypto";
|
|
7823
7884
|
function inputHash(input) {
|
|
7824
|
-
return
|
|
7885
|
+
return createHash4("sha256").update(stable(input)).digest("hex");
|
|
7825
7886
|
}
|
|
7826
7887
|
function stable(value) {
|
|
7827
7888
|
if (Array.isArray(value))
|
|
@@ -8491,6 +8552,9 @@ import { join as join18, basename as basename5, resolve as resolve10 } from "nod
|
|
|
8491
8552
|
import { readdirSync as readdirSync8, existsSync as existsSync15 } from "node:fs";
|
|
8492
8553
|
function createForgeServer(options) {
|
|
8493
8554
|
const { dataDir, db: externalDb, authToken, localOnly = true } = options;
|
|
8555
|
+
const authProblem = remoteAuthProblem(localOnly, authToken);
|
|
8556
|
+
if (authProblem)
|
|
8557
|
+
throw new Error(authProblem);
|
|
8494
8558
|
const dbPath = join18(dataDir, "forge.db");
|
|
8495
8559
|
const modulesDir = join18(dataDir, "modules");
|
|
8496
8560
|
const db = externalDb ?? new ForgeDB(dbPath);
|
|
@@ -8506,6 +8570,7 @@ function createForgeServer(options) {
|
|
|
8506
8570
|
});
|
|
8507
8571
|
if (authToken) {
|
|
8508
8572
|
app.use("/api/*", bearerAuth(authToken));
|
|
8573
|
+
mountAuthRoute(app, authToken);
|
|
8509
8574
|
}
|
|
8510
8575
|
const cwReader = new CWReader(options.cwDir);
|
|
8511
8576
|
const loginManager = new LoginManager(resolveCwBin(cwReader.cwHome));
|
|
@@ -8531,7 +8596,7 @@ function createForgeServer(options) {
|
|
|
8531
8596
|
});
|
|
8532
8597
|
const ptyManager = new PTYManager(states);
|
|
8533
8598
|
const generalSessions = new GeneralSessions(join18(dataDir, "general-sessions.json"));
|
|
8534
|
-
const terminalWss = createTerminalWss(ptyManager, cwReader, { localOnly, general: generalSessions });
|
|
8599
|
+
const terminalWss = createTerminalWss(ptyManager, cwReader, { localOnly, authToken, general: generalSessions });
|
|
8535
8600
|
app.route("/api/liveframe", liveframeRoutes());
|
|
8536
8601
|
const kioku = new Kioku({ projects: () => cwReader.getProjects(), pluginInstalls: () => installsOf(cwReader, "kioku") });
|
|
8537
8602
|
app.route("/api/kioku", kiokuRoutes(kioku, {
|
|
@@ -8962,8 +9027,8 @@ async function createDatabase(opts) {
|
|
|
8962
9027
|
await db.migrate();
|
|
8963
9028
|
return db;
|
|
8964
9029
|
}
|
|
8965
|
-
const { join:
|
|
8966
|
-
return new ForgeDB(
|
|
9030
|
+
const { join: join22 } = await import("node:path");
|
|
9031
|
+
return new ForgeDB(join22(opts.dataDir, "forge.db"));
|
|
8967
9032
|
}
|
|
8968
9033
|
var init_db_factory = __esm({
|
|
8969
9034
|
"../core/dist/db-factory.js"() {
|
|
@@ -9050,10 +9115,87 @@ var init_port_in_use = __esm({
|
|
|
9050
9115
|
}
|
|
9051
9116
|
});
|
|
9052
9117
|
|
|
9118
|
+
// ../core/dist/start.js
|
|
9119
|
+
import { existsSync as existsSync17, readFileSync as readFileSync13 } from "node:fs";
|
|
9120
|
+
import { join as join20 } from "node:path";
|
|
9121
|
+
async function startForge(options) {
|
|
9122
|
+
const { port, version, consoleDist: consoleDist2, bundledModulesDir: bundledModulesDir2, databaseUrl, authToken, fallbackToFreePort = false } = options;
|
|
9123
|
+
const { forgeDir } = ensureForgeDir();
|
|
9124
|
+
const isTeam = !!databaseUrl;
|
|
9125
|
+
const { host, localOnly } = resolveListenOptions(isTeam);
|
|
9126
|
+
const authProblem = remoteAuthProblem(localOnly, authToken);
|
|
9127
|
+
if (authProblem)
|
|
9128
|
+
return { status: "refused", reason: authProblem };
|
|
9129
|
+
const remoteToken = localOnly ? void 0 : authToken;
|
|
9130
|
+
const db = await createDatabase({ mode: isTeam ? "team" : "local", dataDir: forgeDir, databaseUrl });
|
|
9131
|
+
const server = createForgeServer({
|
|
9132
|
+
dataDir: forgeDir,
|
|
9133
|
+
port,
|
|
9134
|
+
db,
|
|
9135
|
+
authToken: remoteToken,
|
|
9136
|
+
localOnly,
|
|
9137
|
+
bundledModulesDir: bundledModulesDir2,
|
|
9138
|
+
version
|
|
9139
|
+
});
|
|
9140
|
+
if (consoleDist2 && existsSync17(join20(consoleDist2, "index.html"))) {
|
|
9141
|
+
const { serveStatic } = await import("@hono/node-server/serve-static");
|
|
9142
|
+
server.app.use("/*", serveStatic({ root: consoleDist2 }));
|
|
9143
|
+
const indexHtml = readFileSync13(join20(consoleDist2, "index.html"), "utf-8");
|
|
9144
|
+
server.app.get("*", (c) => c.html(indexHtml));
|
|
9145
|
+
}
|
|
9146
|
+
const { serve } = await import("@hono/node-server");
|
|
9147
|
+
const listen = async (p) => {
|
|
9148
|
+
const s = serve({ fetch: server.app.fetch, port: p, hostname: host });
|
|
9149
|
+
await waitForListening(s);
|
|
9150
|
+
return s;
|
|
9151
|
+
};
|
|
9152
|
+
let httpServer;
|
|
9153
|
+
try {
|
|
9154
|
+
httpServer = await listen(port);
|
|
9155
|
+
} catch (err) {
|
|
9156
|
+
if (err.code !== "EADDRINUSE") {
|
|
9157
|
+
server.close();
|
|
9158
|
+
throw err;
|
|
9159
|
+
}
|
|
9160
|
+
const holder = await probePort(port);
|
|
9161
|
+
if (holder === "forge" || !fallbackToFreePort) {
|
|
9162
|
+
server.close();
|
|
9163
|
+
return { status: "in-use", port, holder };
|
|
9164
|
+
}
|
|
9165
|
+
httpServer = await listen(0);
|
|
9166
|
+
}
|
|
9167
|
+
server.attachTerminalWs(httpServer);
|
|
9168
|
+
const address = httpServer.address();
|
|
9169
|
+
const actualPort = typeof address === "object" && address ? address.port : port;
|
|
9170
|
+
return {
|
|
9171
|
+
status: "listening",
|
|
9172
|
+
url: `http://localhost:${actualPort}`,
|
|
9173
|
+
port: actualPort,
|
|
9174
|
+
isTeam,
|
|
9175
|
+
authRequired: !!remoteToken,
|
|
9176
|
+
close: () => {
|
|
9177
|
+
server.close();
|
|
9178
|
+
httpServer.close();
|
|
9179
|
+
}
|
|
9180
|
+
};
|
|
9181
|
+
}
|
|
9182
|
+
var init_start = __esm({
|
|
9183
|
+
"../core/dist/start.js"() {
|
|
9184
|
+
"use strict";
|
|
9185
|
+
init_server();
|
|
9186
|
+
init_db_factory();
|
|
9187
|
+
init_init();
|
|
9188
|
+
init_origin_guard();
|
|
9189
|
+
init_auth();
|
|
9190
|
+
init_port_in_use();
|
|
9191
|
+
}
|
|
9192
|
+
});
|
|
9193
|
+
|
|
9053
9194
|
// ../core/dist/index.js
|
|
9054
9195
|
var dist_exports = {};
|
|
9055
9196
|
__export(dist_exports, {
|
|
9056
9197
|
ACCOUNT_NAME_RE: () => ACCOUNT_NAME_RE,
|
|
9198
|
+
AUTH_COOKIE: () => AUTH_COOKIE,
|
|
9057
9199
|
ActionRunner: () => ActionRunner,
|
|
9058
9200
|
CWReader: () => CWReader,
|
|
9059
9201
|
ForgeDB: () => ForgeDB,
|
|
@@ -9079,6 +9221,7 @@ __export(dist_exports, {
|
|
|
9079
9221
|
ensureForgeDir: () => ensureForgeDir,
|
|
9080
9222
|
getForgeDir: () => getForgeDir,
|
|
9081
9223
|
installArgs: () => installArgs,
|
|
9224
|
+
isAuthorized: () => isAuthorized,
|
|
9082
9225
|
kiokuRoutes: () => kiokuRoutes,
|
|
9083
9226
|
liveframeRoutes: () => liveframeRoutes,
|
|
9084
9227
|
pathWithCw: () => pathWithCw,
|
|
@@ -9087,9 +9230,11 @@ __export(dist_exports, {
|
|
|
9087
9230
|
probePort: () => probePort,
|
|
9088
9231
|
quietSqliteWarning: () => quietSqliteWarning,
|
|
9089
9232
|
rememberPrompt: () => rememberPrompt,
|
|
9233
|
+
remoteAuthProblem: () => remoteAuthProblem,
|
|
9090
9234
|
resolveKiokuBin: () => resolveKiokuBin,
|
|
9091
9235
|
resolveListenOptions: () => resolveListenOptions,
|
|
9092
9236
|
skillRoutes: () => skillRoutes,
|
|
9237
|
+
startForge: () => startForge,
|
|
9093
9238
|
supports: () => supports,
|
|
9094
9239
|
validateParams: () => validateParams,
|
|
9095
9240
|
waitForListening: () => waitForListening
|
|
@@ -9119,15 +9264,16 @@ var init_dist2 = __esm({
|
|
|
9119
9264
|
init_kioku_routes();
|
|
9120
9265
|
init_kioku();
|
|
9121
9266
|
init_port_in_use();
|
|
9267
|
+
init_start();
|
|
9122
9268
|
init_module_install();
|
|
9123
9269
|
init_task_review();
|
|
9124
9270
|
}
|
|
9125
9271
|
});
|
|
9126
9272
|
|
|
9127
9273
|
// src/index.ts
|
|
9128
|
-
import { existsSync as
|
|
9274
|
+
import { existsSync as existsSync18, readFileSync as readFileSync14 } from "node:fs";
|
|
9129
9275
|
import { homedir as homedir9 } from "node:os";
|
|
9130
|
-
import { join as
|
|
9276
|
+
import { join as join21 } from "node:path";
|
|
9131
9277
|
function parseArgs(argv) {
|
|
9132
9278
|
const out = { open: true };
|
|
9133
9279
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -9138,74 +9284,61 @@ function parseArgs(argv) {
|
|
|
9138
9284
|
}
|
|
9139
9285
|
return out;
|
|
9140
9286
|
}
|
|
9141
|
-
var packageRoot =
|
|
9142
|
-
var isCheckout =
|
|
9143
|
-
var consoleDist = isCheckout ?
|
|
9144
|
-
var forgeVersion = JSON.parse(
|
|
9145
|
-
var bundledModulesDir = isCheckout ?
|
|
9287
|
+
var packageRoot = join21(import.meta.dirname, "..");
|
|
9288
|
+
var isCheckout = existsSync18(join21(packageRoot, "src"));
|
|
9289
|
+
var consoleDist = isCheckout ? join21(packageRoot, "../console/dist") : join21(packageRoot, "console");
|
|
9290
|
+
var forgeVersion = JSON.parse(readFileSync14(join21(packageRoot, "package.json"), "utf-8")).version;
|
|
9291
|
+
var bundledModulesDir = isCheckout ? join21(packageRoot, "../../modules") : join21(packageRoot, "modules");
|
|
9146
9292
|
async function main() {
|
|
9147
|
-
const { ensureForgeDir: ensureForgeDir2,
|
|
9293
|
+
const { ensureForgeDir: ensureForgeDir2, startForge: startForge2, ensureCw: ensureCw2, pathWithCw: pathWithCw2, quietSqliteWarning: quietSqliteWarning2, portInUseMessage: portInUseMessage2 } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
|
|
9148
9294
|
quietSqliteWarning2();
|
|
9149
9295
|
const args = parseArgs(process.argv.slice(2));
|
|
9150
|
-
const {
|
|
9296
|
+
const { created } = ensureForgeDir2();
|
|
9151
9297
|
if (created) {
|
|
9152
9298
|
console.log("First run \u2014 initialized Forge.");
|
|
9153
9299
|
}
|
|
9154
|
-
const cwHome =
|
|
9155
|
-
const cw = isCheckout ? { action: "skipped", message: "a checkout does not install CW" } : await ensureCw2({ cwHome, bundleDir:
|
|
9300
|
+
const cwHome = join21(process.env.HOME ?? homedir9(), ".cw");
|
|
9301
|
+
const cw = isCheckout ? { action: "skipped", message: "a checkout does not install CW" } : await ensureCw2({ cwHome, bundleDir: join21(packageRoot, "cw") });
|
|
9156
9302
|
if (cw.action === "installed") console.log(` Installed CW ${cw.version} in ${cwHome}`);
|
|
9157
9303
|
else if (cw.action === "updated") console.log(` Updated ${cw.message}`);
|
|
9158
9304
|
else if (cw.action === "failed") console.log(` Could not install CW: ${cw.message}`);
|
|
9159
9305
|
process.env.PATH = pathWithCw2(cwHome, process.env.PATH);
|
|
9160
9306
|
const port = parseInt(args.port ?? process.env.FORGE_PORT ?? "3000", 10);
|
|
9161
|
-
const dbUrl = process.env.FORGE_DB_URL;
|
|
9162
9307
|
const authToken = process.env.FORGE_AUTH_TOKEN;
|
|
9163
|
-
const
|
|
9164
|
-
const { host, localOnly } = resolveListenOptions2(isTeam);
|
|
9165
|
-
const db = await createDatabase2({
|
|
9166
|
-
mode: isTeam ? "team" : "local",
|
|
9167
|
-
dataDir: forgeDir,
|
|
9168
|
-
databaseUrl: dbUrl
|
|
9169
|
-
});
|
|
9170
|
-
const server = createForgeServer2({
|
|
9171
|
-
dataDir: forgeDir,
|
|
9308
|
+
const started = await startForge2({
|
|
9172
9309
|
port,
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
localOnly,
|
|
9310
|
+
version: forgeVersion,
|
|
9311
|
+
consoleDist,
|
|
9176
9312
|
bundledModulesDir,
|
|
9177
|
-
|
|
9313
|
+
databaseUrl: process.env.FORGE_DB_URL,
|
|
9314
|
+
authToken
|
|
9178
9315
|
});
|
|
9179
|
-
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9316
|
+
if (started.status === "refused") {
|
|
9317
|
+
console.log(`
|
|
9318
|
+
${started.reason}
|
|
9319
|
+
`);
|
|
9320
|
+
process.exit(1);
|
|
9184
9321
|
}
|
|
9185
|
-
|
|
9186
|
-
const httpServer = serve({ fetch: server.app.fetch, port, hostname: host });
|
|
9187
|
-
try {
|
|
9188
|
-
await waitForListening2(httpServer);
|
|
9189
|
-
} catch (err) {
|
|
9190
|
-
if (err.code !== "EADDRINUSE") throw err;
|
|
9191
|
-
const holder = await probePort2(port);
|
|
9322
|
+
if (started.status === "in-use") {
|
|
9192
9323
|
console.log(`
|
|
9193
|
-
${portInUseMessage2(port, holder)}
|
|
9324
|
+
${portInUseMessage2(port, started.holder)}
|
|
9194
9325
|
`);
|
|
9195
|
-
if (holder === "forge" && args.open && process.env.FORGE_NO_OPEN !== "1") {
|
|
9326
|
+
if (started.holder === "forge" && args.open && process.env.FORGE_NO_OPEN !== "1") {
|
|
9196
9327
|
try {
|
|
9197
9328
|
const open = (await import("open")).default;
|
|
9198
9329
|
await open(`http://localhost:${port}`);
|
|
9199
9330
|
} catch {
|
|
9200
9331
|
}
|
|
9201
9332
|
}
|
|
9202
|
-
process.exit(holder === "forge" ? 0 : 1);
|
|
9333
|
+
process.exit(started.holder === "forge" ? 0 : 1);
|
|
9203
9334
|
}
|
|
9204
|
-
|
|
9335
|
+
const { isTeam, authRequired } = started;
|
|
9205
9336
|
console.log(`
|
|
9206
9337
|
Forge Console running at http://localhost:${port}
|
|
9207
9338
|
Mode: ${isTeam ? "team (PostgreSQL)" : "local (SQLite)"}
|
|
9208
|
-
${
|
|
9339
|
+
${authRequired ? ` Auth: token required. Browsers sign in once at http://<this host>:${port}/auth?token=<FORGE_AUTH_TOKEN>;
|
|
9340
|
+
the CLI and scripts send Authorization: Bearer <FORGE_AUTH_TOKEN>
|
|
9341
|
+
` : ""}
|
|
9209
9342
|
Dashboard: http://localhost:${port}
|
|
9210
9343
|
API: http://localhost:${port}/api/health
|
|
9211
9344
|
|
|
@@ -9214,7 +9347,7 @@ ${authToken ? " Auth: bearer token required\n" : ""}
|
|
|
9214
9347
|
if (args.open && process.env.FORGE_NO_OPEN !== "1") {
|
|
9215
9348
|
try {
|
|
9216
9349
|
const open = (await import("open")).default;
|
|
9217
|
-
await open(`http://localhost:${port}`);
|
|
9350
|
+
await open(authRequired && authToken ? `http://localhost:${port}/auth?token=${encodeURIComponent(authToken)}` : `http://localhost:${port}`);
|
|
9218
9351
|
} catch {
|
|
9219
9352
|
}
|
|
9220
9353
|
}
|