forge-cw 0.1.19 → 0.1.21
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 +229 -105
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -373,7 +373,7 @@ var init_runner = __esm({
|
|
|
373
373
|
return this.run(command, args, options);
|
|
374
374
|
}
|
|
375
375
|
run(file, args, options) {
|
|
376
|
-
return new Promise((
|
|
376
|
+
return new Promise((resolve11) => {
|
|
377
377
|
let output = "";
|
|
378
378
|
let timedOut = false;
|
|
379
379
|
let timeoutId;
|
|
@@ -410,7 +410,7 @@ var init_runner = __esm({
|
|
|
410
410
|
proc.on("close", (code) => {
|
|
411
411
|
if (timeoutId)
|
|
412
412
|
clearTimeout(timeoutId);
|
|
413
|
-
|
|
413
|
+
resolve11({
|
|
414
414
|
exitCode: code ?? 1,
|
|
415
415
|
output,
|
|
416
416
|
timedOut
|
|
@@ -419,7 +419,7 @@ var init_runner = __esm({
|
|
|
419
419
|
proc.on("error", () => {
|
|
420
420
|
if (timeoutId)
|
|
421
421
|
clearTimeout(timeoutId);
|
|
422
|
-
|
|
422
|
+
resolve11({ exitCode: 1, output, timedOut });
|
|
423
423
|
});
|
|
424
424
|
});
|
|
425
425
|
}
|
|
@@ -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
|
|
|
@@ -509,7 +565,12 @@ function isLocalRequest(host, origin) {
|
|
|
509
565
|
if (origin === void 0)
|
|
510
566
|
return true;
|
|
511
567
|
try {
|
|
512
|
-
|
|
568
|
+
const url = new URL(origin);
|
|
569
|
+
if (!LOOPBACK_HOSTNAMES.has(url.hostname))
|
|
570
|
+
return false;
|
|
571
|
+
if (DEV_ORIGINS.has(url.origin))
|
|
572
|
+
return true;
|
|
573
|
+
return url.host === new URL(`http://${host}`).host;
|
|
513
574
|
} catch {
|
|
514
575
|
return false;
|
|
515
576
|
}
|
|
@@ -526,17 +587,30 @@ function localOriginGuard() {
|
|
|
526
587
|
return next();
|
|
527
588
|
};
|
|
528
589
|
}
|
|
529
|
-
var LOOPBACK_HOSTNAMES;
|
|
590
|
+
var LOOPBACK_HOSTNAMES, DEV_ORIGINS;
|
|
530
591
|
var init_origin_guard = __esm({
|
|
531
592
|
"../core/dist/origin-guard.js"() {
|
|
532
593
|
"use strict";
|
|
533
594
|
LOOPBACK_HOSTNAMES = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
595
|
+
DEV_ORIGINS = /* @__PURE__ */ new Set(["http://localhost:5173", "http://127.0.0.1:5173"]);
|
|
534
596
|
}
|
|
535
597
|
});
|
|
536
598
|
|
|
537
599
|
// ../core/dist/cw-reader.js
|
|
538
600
|
import { readdirSync as readdirSync2, readFileSync as readFileSync2, existsSync as existsSync2 } from "node:fs";
|
|
539
|
-
import { join as join2 } from "node:path";
|
|
601
|
+
import { join as join2, resolve, sep } from "node:path";
|
|
602
|
+
function sessionFolder(cwDir, project, sessionDir = "") {
|
|
603
|
+
if (typeof project !== "string" || typeof sessionDir !== "string")
|
|
604
|
+
return null;
|
|
605
|
+
if (!project || project === "." || project === ".." || /[\\/\0]/.test(project))
|
|
606
|
+
return null;
|
|
607
|
+
const segments = sessionDir ? sessionDir.split("/") : [];
|
|
608
|
+
if (segments.some((s) => s === "" || s === "." || s === ".." || /[\\\0]/.test(s)))
|
|
609
|
+
return null;
|
|
610
|
+
const root = resolve(cwDir, "sessions");
|
|
611
|
+
const dir = resolve(root, project, ...segments);
|
|
612
|
+
return dir.startsWith(root + sep) ? dir : null;
|
|
613
|
+
}
|
|
540
614
|
function* walkSessionDirs(baseDir, rel = "", depth = 0) {
|
|
541
615
|
if (depth >= MAX_SESSION_DEPTH)
|
|
542
616
|
return;
|
|
@@ -600,7 +674,10 @@ var init_cw_reader = __esm({
|
|
|
600
674
|
return sessions.sort((a, b) => new Date(b.last_opened).getTime() - new Date(a.last_opened).getTime());
|
|
601
675
|
}
|
|
602
676
|
getSession(project, sessionDir) {
|
|
603
|
-
const
|
|
677
|
+
const dir = sessionFolder(this.cwDir, project, sessionDir);
|
|
678
|
+
if (!dir)
|
|
679
|
+
return null;
|
|
680
|
+
const path = join2(dir, "session.json");
|
|
604
681
|
if (!existsSync2(path))
|
|
605
682
|
return null;
|
|
606
683
|
try {
|
|
@@ -612,7 +689,9 @@ var init_cw_reader = __esm({
|
|
|
612
689
|
}
|
|
613
690
|
}
|
|
614
691
|
getNotes(project, sessionDir) {
|
|
615
|
-
const baseDir =
|
|
692
|
+
const baseDir = sessionFolder(this.cwDir, project, sessionDir);
|
|
693
|
+
if (!baseDir)
|
|
694
|
+
return "";
|
|
616
695
|
const sessionPath = join2(baseDir, "session.json");
|
|
617
696
|
if (existsSync2(sessionPath)) {
|
|
618
697
|
try {
|
|
@@ -936,19 +1015,19 @@ function envWithoutHarness(env = process.env) {
|
|
|
936
1015
|
return out;
|
|
937
1016
|
}
|
|
938
1017
|
function runDoctor(cwBin) {
|
|
939
|
-
return new Promise((
|
|
1018
|
+
return new Promise((resolve11) => {
|
|
940
1019
|
execFile(cwBin, ["doctor", "--json"], { timeout: TIMEOUT_MS, env: envWithoutHarness(), maxBuffer: 10 * 1024 * 1024 }, (err, stdout) => {
|
|
941
1020
|
if (err)
|
|
942
|
-
return
|
|
1021
|
+
return resolve11({ available: false, reason: err.message });
|
|
943
1022
|
let parsed;
|
|
944
1023
|
try {
|
|
945
1024
|
parsed = JSON.parse(stdout);
|
|
946
1025
|
} catch {
|
|
947
|
-
return
|
|
1026
|
+
return resolve11({ available: false, reason: "cw doctor --json did not print JSON" });
|
|
948
1027
|
}
|
|
949
1028
|
if (parsed.schema !== 1)
|
|
950
|
-
return
|
|
951
|
-
|
|
1029
|
+
return resolve11({ available: false, reason: `unsupported doctor schema ${String(parsed.schema)}` });
|
|
1030
|
+
resolve11({ available: true, doctor: parsed });
|
|
952
1031
|
});
|
|
953
1032
|
});
|
|
954
1033
|
}
|
|
@@ -1053,14 +1132,14 @@ function closeWarningsFor(input) {
|
|
|
1053
1132
|
return warnings;
|
|
1054
1133
|
}
|
|
1055
1134
|
function createRunner(env, timeoutMs = COMMAND_TIMEOUT_MS) {
|
|
1056
|
-
return (bin, args, cwd, input) => new Promise((
|
|
1135
|
+
return (bin, args, cwd, input) => new Promise((resolve11) => {
|
|
1057
1136
|
const child = execFile2(bin, args, { cwd, env, timeout: timeoutMs, maxBuffer: 5 * 1024 * 1024 }, (err, stdout, stderr) => {
|
|
1058
1137
|
if (!err)
|
|
1059
|
-
return
|
|
1138
|
+
return resolve11({ code: 0, stdout: String(stdout), stderr: String(stderr) });
|
|
1060
1139
|
const { code } = err;
|
|
1061
1140
|
if (code === "ENOENT")
|
|
1062
|
-
return
|
|
1063
|
-
|
|
1141
|
+
return resolve11({ code: 127, stdout: "", stderr: "ENOENT" });
|
|
1142
|
+
resolve11({ code: typeof code === "number" ? code : 1, stdout: String(stdout), stderr: String(stderr) || err.message });
|
|
1064
1143
|
});
|
|
1065
1144
|
if (input !== void 0) {
|
|
1066
1145
|
child.stdin?.on("error", () => {
|
|
@@ -1260,7 +1339,7 @@ function createLimiter(max) {
|
|
|
1260
1339
|
const waiting = [];
|
|
1261
1340
|
return async (fn) => {
|
|
1262
1341
|
if (active >= max)
|
|
1263
|
-
await new Promise((
|
|
1342
|
+
await new Promise((resolve11) => waiting.push(resolve11));
|
|
1264
1343
|
else
|
|
1265
1344
|
active++;
|
|
1266
1345
|
try {
|
|
@@ -1331,7 +1410,7 @@ var init_usage_window = __esm({
|
|
|
1331
1410
|
|
|
1332
1411
|
// ../core/dist/usage-claude.js
|
|
1333
1412
|
import { execFile as execFile3 } from "node:child_process";
|
|
1334
|
-
import { createHash } from "node:crypto";
|
|
1413
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
1335
1414
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
1336
1415
|
import { homedir } from "node:os";
|
|
1337
1416
|
import { join as join5 } from "node:path";
|
|
@@ -1366,7 +1445,7 @@ function claudeKeychainService(configDir) {
|
|
|
1366
1445
|
const dir = configDir.replace(/\/+$/, "");
|
|
1367
1446
|
if (dir === join5(homedir(), ".claude"))
|
|
1368
1447
|
return KEYCHAIN_SERVICE;
|
|
1369
|
-
return `${KEYCHAIN_SERVICE}-${
|
|
1448
|
+
return `${KEYCHAIN_SERVICE}-${createHash2("sha256").update(dir).digest("hex").slice(0, 8)}`;
|
|
1370
1449
|
}
|
|
1371
1450
|
async function readFromKeychain(service) {
|
|
1372
1451
|
try {
|
|
@@ -1460,7 +1539,7 @@ function mapCodexUsage(payload) {
|
|
|
1460
1539
|
});
|
|
1461
1540
|
}
|
|
1462
1541
|
function callCodexAppServer(bin, codexHome, timeoutMs = TIMEOUT_MS3) {
|
|
1463
|
-
return new Promise((
|
|
1542
|
+
return new Promise((resolve11, reject) => {
|
|
1464
1543
|
const child = spawn2(bin, ["app-server"], { env: { ...CHILD_ENV, CODEX_HOME: codexHome }, stdio: ["pipe", "pipe", "ignore"] });
|
|
1465
1544
|
let buffer = "";
|
|
1466
1545
|
let settled = false;
|
|
@@ -1480,7 +1559,7 @@ function callCodexAppServer(bin, codexHome, timeoutMs = TIMEOUT_MS3) {
|
|
|
1480
1559
|
const done = (value) => {
|
|
1481
1560
|
if (!settled) {
|
|
1482
1561
|
stop();
|
|
1483
|
-
|
|
1562
|
+
resolve11(value);
|
|
1484
1563
|
}
|
|
1485
1564
|
};
|
|
1486
1565
|
const timer = setTimeout(() => fail(new Error(`codex app-server did not answer in ${timeoutMs / 1e3} s`)), timeoutMs);
|
|
@@ -1747,7 +1826,7 @@ var init_login_manager = __esm({
|
|
|
1747
1826
|
// ../core/dist/api-key-login.js
|
|
1748
1827
|
import { spawn as spawn4 } from "node:child_process";
|
|
1749
1828
|
function importApiKey(cwBin, account, harness, apiKey) {
|
|
1750
|
-
return new Promise((
|
|
1829
|
+
return new Promise((resolve11) => {
|
|
1751
1830
|
const redact = (text2) => text2.split(apiKey).join("***").trim();
|
|
1752
1831
|
const child = spawn4(cwBin, ["account", "login", account, "--harness", harness, "--with-api-key", "-"], {
|
|
1753
1832
|
env: envWithoutHarness(),
|
|
@@ -1764,11 +1843,11 @@ function importApiKey(cwBin, account, harness, apiKey) {
|
|
|
1764
1843
|
const timer = setTimeout(() => child.kill(), TIMEOUT_MS4);
|
|
1765
1844
|
child.on("error", (err) => {
|
|
1766
1845
|
clearTimeout(timer);
|
|
1767
|
-
|
|
1846
|
+
resolve11({ ok: false, error: redact(err.message) });
|
|
1768
1847
|
});
|
|
1769
1848
|
child.on("close", (code) => {
|
|
1770
1849
|
clearTimeout(timer);
|
|
1771
|
-
|
|
1850
|
+
resolve11(code === 0 ? { ok: true } : { ok: false, error: redact(output) || `cw exited with ${String(code)}` });
|
|
1772
1851
|
});
|
|
1773
1852
|
child.stdin.end(`${apiKey}
|
|
1774
1853
|
`);
|
|
@@ -1800,12 +1879,12 @@ function detectEditors(probe) {
|
|
|
1800
1879
|
return found;
|
|
1801
1880
|
}
|
|
1802
1881
|
function openInEditor(editor, dir) {
|
|
1803
|
-
return new Promise((
|
|
1882
|
+
return new Promise((resolve11, reject) => {
|
|
1804
1883
|
const child = spawn5(editor.bin, [...editor.args, dir], { detached: true, stdio: "ignore" });
|
|
1805
1884
|
child.once("error", reject);
|
|
1806
1885
|
child.once("spawn", () => {
|
|
1807
1886
|
child.unref();
|
|
1808
|
-
|
|
1887
|
+
resolve11();
|
|
1809
1888
|
});
|
|
1810
1889
|
});
|
|
1811
1890
|
}
|
|
@@ -1857,7 +1936,7 @@ import { Hono } from "hono";
|
|
|
1857
1936
|
import { execFileSync, execFile as execFile4 } from "node:child_process";
|
|
1858
1937
|
import { promisify as promisify2 } from "node:util";
|
|
1859
1938
|
import { readFileSync as readFileSync5, writeFileSync, existsSync as existsSync5, mkdirSync, rmSync, readdirSync as readdirSync3, statSync } from "node:fs";
|
|
1860
|
-
import { join as join7, resolve, dirname, basename, isAbsolute } from "node:path";
|
|
1939
|
+
import { join as join7, resolve as resolve2, dirname, basename, isAbsolute } from "node:path";
|
|
1861
1940
|
import { homedir as homedir2 } from "node:os";
|
|
1862
1941
|
function resolveCwBin(cwHome) {
|
|
1863
1942
|
const candidate = join7(cwHome, "bin", "cw");
|
|
@@ -2312,7 +2391,9 @@ function cwRoutes(reader, options = {}) {
|
|
|
2312
2391
|
}
|
|
2313
2392
|
}
|
|
2314
2393
|
const dirPrefix = type === "review" ? "review-pr-" : "task-";
|
|
2315
|
-
const sessionDir =
|
|
2394
|
+
const sessionDir = sessionFolder(cwHome, project, `${dirPrefix}${taskSlug}`);
|
|
2395
|
+
if (!sessionDir)
|
|
2396
|
+
return c.json({ ok: false, error: "Invalid project or task name" }, 400);
|
|
2316
2397
|
const sessionFile = join7(sessionDir, "session.json");
|
|
2317
2398
|
if (existsSync5(sessionFile)) {
|
|
2318
2399
|
try {
|
|
@@ -2344,7 +2425,7 @@ function cwRoutes(reader, options = {}) {
|
|
|
2344
2425
|
if (harness)
|
|
2345
2426
|
args.push("--harness", harness);
|
|
2346
2427
|
if (description) {
|
|
2347
|
-
const notesDir =
|
|
2428
|
+
const notesDir = sessionDir;
|
|
2348
2429
|
mkdirSync(notesDir, { recursive: true });
|
|
2349
2430
|
const notesFile = join7(notesDir, type === "review" ? "REVIEW_NOTES.md" : "TASK_NOTES.md");
|
|
2350
2431
|
if (!existsSync5(notesFile)) {
|
|
@@ -2451,13 +2532,15 @@ ${result2.stderr}`);
|
|
|
2451
2532
|
});
|
|
2452
2533
|
app.post("/delete-project", async (c) => {
|
|
2453
2534
|
const { project, deleteFiles } = await c.req.json();
|
|
2535
|
+
const sessionsDir = sessionFolder(reader.cwHome, project);
|
|
2536
|
+
if (!sessionsDir)
|
|
2537
|
+
return c.json({ ok: false, error: "Invalid project name" }, 400);
|
|
2454
2538
|
const projects = reader.getProjects();
|
|
2455
2539
|
const projPath = projects[project]?.path;
|
|
2456
2540
|
try {
|
|
2457
2541
|
execFileSync(cwBin, ["project", "remove", project, "--yes"], { encoding: "utf-8", timeout: 1e4, stdio: "pipe", env: envWithoutHarness() });
|
|
2458
2542
|
} catch {
|
|
2459
2543
|
}
|
|
2460
|
-
const sessionsDir = join7(reader.cwHome, "sessions", project);
|
|
2461
2544
|
if (existsSync5(sessionsDir)) {
|
|
2462
2545
|
try {
|
|
2463
2546
|
rmSync(sessionsDir, { recursive: true, force: true });
|
|
@@ -2482,7 +2565,7 @@ ${result2.stderr}`);
|
|
|
2482
2565
|
p = join7(home, p.slice(1).replace(/^\//, ""));
|
|
2483
2566
|
if (!isAbsolute(p))
|
|
2484
2567
|
return null;
|
|
2485
|
-
return
|
|
2568
|
+
return resolve2(p);
|
|
2486
2569
|
};
|
|
2487
2570
|
app.get("/browse-dirs", (c) => {
|
|
2488
2571
|
const requested = c.req.query("path") ?? "~";
|
|
@@ -2568,6 +2651,7 @@ var execFileAsync2, GENERAL_PROJECT, CREATING_PROJECT, ACCOUNTS_PROJECT, pending
|
|
|
2568
2651
|
var init_cw_routes = __esm({
|
|
2569
2652
|
"../core/dist/cw-routes.js"() {
|
|
2570
2653
|
"use strict";
|
|
2654
|
+
init_cw_reader();
|
|
2571
2655
|
init_cw_types();
|
|
2572
2656
|
init_cw_doctor();
|
|
2573
2657
|
init_usage();
|
|
@@ -2588,7 +2672,7 @@ var init_cw_routes = __esm({
|
|
|
2588
2672
|
|
|
2589
2673
|
// ../core/dist/plugins.js
|
|
2590
2674
|
import { existsSync as existsSync6, readFileSync as readFileSync6, readdirSync as readdirSync4 } from "node:fs";
|
|
2591
|
-
import { basename as basename2, join as join8, resolve as
|
|
2675
|
+
import { basename as basename2, join as join8, resolve as resolve3, sep as sep2 } from "node:path";
|
|
2592
2676
|
function readJson(path) {
|
|
2593
2677
|
try {
|
|
2594
2678
|
const value = JSON.parse(readFileSync6(path, "utf-8"));
|
|
@@ -2622,10 +2706,10 @@ function scanDirs(root) {
|
|
|
2622
2706
|
function skillDirs(installPath, manifest) {
|
|
2623
2707
|
const listed = manifest["skills"];
|
|
2624
2708
|
if (Array.isArray(listed)) {
|
|
2625
|
-
return listed.filter((p) => typeof p === "string").map((p) =>
|
|
2709
|
+
return listed.filter((p) => typeof p === "string").map((p) => resolve3(installPath, p)).filter((p) => inside(installPath, p));
|
|
2626
2710
|
}
|
|
2627
2711
|
if (typeof listed === "string") {
|
|
2628
|
-
const root =
|
|
2712
|
+
const root = resolve3(installPath, listed);
|
|
2629
2713
|
return inside(installPath, root) ? scanDirs(root) : [];
|
|
2630
2714
|
}
|
|
2631
2715
|
return scanDirs(join8(installPath, "skills"));
|
|
@@ -2694,7 +2778,7 @@ function catalogVersion(configDir, marketplaces, marketplace, name) {
|
|
|
2694
2778
|
const source = entry["source"];
|
|
2695
2779
|
if (typeof source !== "string")
|
|
2696
2780
|
return void 0;
|
|
2697
|
-
const dir =
|
|
2781
|
+
const dir = resolve3(location, source);
|
|
2698
2782
|
if (!inside(location, dir))
|
|
2699
2783
|
return void 0;
|
|
2700
2784
|
const version = readJson(join8(dir, ".claude-plugin", "plugin.json"))["version"];
|
|
@@ -2840,9 +2924,9 @@ var init_plugins = __esm({
|
|
|
2840
2924
|
"use strict";
|
|
2841
2925
|
isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
2842
2926
|
inside = (root, path) => {
|
|
2843
|
-
const r =
|
|
2844
|
-
const p =
|
|
2845
|
-
return p === r || p.startsWith(r +
|
|
2927
|
+
const r = resolve3(root);
|
|
2928
|
+
const p = resolve3(path);
|
|
2929
|
+
return p === r || p.startsWith(r + sep2);
|
|
2846
2930
|
};
|
|
2847
2931
|
pluginScopes = (reader) => [
|
|
2848
2932
|
{ scope: "global", scopeRef: "global" },
|
|
@@ -3606,7 +3690,7 @@ var init_terminal_screen = __esm({
|
|
|
3606
3690
|
}
|
|
3607
3691
|
// rows oldest first, scrollback included, without the blank rows under the last one written
|
|
3608
3692
|
read() {
|
|
3609
|
-
return new Promise((
|
|
3693
|
+
return new Promise((resolve11) => this.term.write("", () => {
|
|
3610
3694
|
const buffer = this.term.buffer.active;
|
|
3611
3695
|
const rows = [];
|
|
3612
3696
|
for (let y = 0; y < buffer.length; y++) {
|
|
@@ -3622,7 +3706,7 @@ var init_terminal_screen = __esm({
|
|
|
3622
3706
|
const trimmed = rows.map((r) => r.trimEnd());
|
|
3623
3707
|
while (trimmed.length && !trimmed[trimmed.length - 1])
|
|
3624
3708
|
trimmed.pop();
|
|
3625
|
-
|
|
3709
|
+
resolve11(trimmed.join("\n"));
|
|
3626
3710
|
}));
|
|
3627
3711
|
}
|
|
3628
3712
|
dispose() {
|
|
@@ -3822,7 +3906,7 @@ var init_session_state = __esm({
|
|
|
3822
3906
|
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
3823
3907
|
import { appendFile } from "node:fs/promises";
|
|
3824
3908
|
import { homedir as homedir3 } from "node:os";
|
|
3825
|
-
import { dirname as dirname4, resolve as
|
|
3909
|
+
import { dirname as dirname4, resolve as resolve4 } from "node:path";
|
|
3826
3910
|
function expandHome(path) {
|
|
3827
3911
|
return path === "~" || path.startsWith("~/") ? homedir3() + path.slice(1) : path;
|
|
3828
3912
|
}
|
|
@@ -3841,7 +3925,7 @@ function stateLogLine(call) {
|
|
|
3841
3925
|
}
|
|
3842
3926
|
function createStateLog(path, onError = () => {
|
|
3843
3927
|
}) {
|
|
3844
|
-
const file =
|
|
3928
|
+
const file = resolve4(expandHome(path));
|
|
3845
3929
|
mkdirSync3(dirname4(file), { recursive: true });
|
|
3846
3930
|
let queue = Promise.resolve();
|
|
3847
3931
|
return (call) => {
|
|
@@ -3873,7 +3957,7 @@ function takeSession(reader, project, sessionDir, general) {
|
|
|
3873
3957
|
const known = general?.get(sessionId);
|
|
3874
3958
|
return known ? { session: known, isNew: true } : null;
|
|
3875
3959
|
}
|
|
3876
|
-
function createTerminalWss(manager, reader, { localOnly = true, general } = {}) {
|
|
3960
|
+
function createTerminalWss(manager, reader, { localOnly = true, authToken, general } = {}) {
|
|
3877
3961
|
const wss = new WebSocketServer({ noServer: true });
|
|
3878
3962
|
function wireWs(ws, sessionId, project, sessionDir) {
|
|
3879
3963
|
const client = {
|
|
@@ -3904,6 +3988,10 @@ function createTerminalWss(manager, reader, { localOnly = true, general } = {})
|
|
|
3904
3988
|
});
|
|
3905
3989
|
}
|
|
3906
3990
|
wss.on("connection", (ws, project, sessionDir) => {
|
|
3991
|
+
ws.on("error", (err) => {
|
|
3992
|
+
console.error(`[pty-ws] Socket error on ${project}/${sessionDir}: ${err.message}`);
|
|
3993
|
+
ws.terminate();
|
|
3994
|
+
});
|
|
3907
3995
|
console.log(`[pty-ws] Connected: ${project}/${sessionDir}`);
|
|
3908
3996
|
const sessionId = `${project}::${sessionDir}`;
|
|
3909
3997
|
if (manager.has(sessionId)) {
|
|
@@ -3917,7 +4005,12 @@ function createTerminalWss(manager, reader, { localOnly = true, general } = {})
|
|
|
3917
4005
|
ws.close(REFUSED_CLOSE_CODE);
|
|
3918
4006
|
return;
|
|
3919
4007
|
}
|
|
3920
|
-
|
|
4008
|
+
let ptySession = null;
|
|
4009
|
+
try {
|
|
4010
|
+
ptySession = manager.getOrCreate(project, sessionDir, taken.session, { isNew: taken.isNew });
|
|
4011
|
+
} catch (err) {
|
|
4012
|
+
console.error(`[pty-ws] Could not launch ${project}/${sessionDir}: ${err.message}`);
|
|
4013
|
+
}
|
|
3921
4014
|
if (!ptySession) {
|
|
3922
4015
|
console.error(`[pty-ws] Failed to spawn terminal for: ${project}/${sessionDir}`);
|
|
3923
4016
|
ws.send(JSON.stringify({ type: "error", message: `Failed to start terminal for ${project}/${sessionDir}` }));
|
|
@@ -3928,19 +4021,27 @@ function createTerminalWss(manager, reader, { localOnly = true, general } = {})
|
|
|
3928
4021
|
});
|
|
3929
4022
|
function attachToServer(server) {
|
|
3930
4023
|
server.on("upgrade", (request, socket, head) => {
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
4024
|
+
try {
|
|
4025
|
+
if (localOnly && !isLocalRequest(request.headers.host, request.headers.origin)) {
|
|
4026
|
+
socket.destroy();
|
|
4027
|
+
return;
|
|
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
|
+
}
|
|
4033
|
+
const url = new URL(request.url ?? "/", "http://localhost");
|
|
4034
|
+
const parsed = parseTerminalUpgradeUrl(url.pathname);
|
|
4035
|
+
if (parsed) {
|
|
4036
|
+
const { project, sessionDir } = parsed;
|
|
4037
|
+
console.log(`[pty-ws] Upgrade request: ${JSON.stringify(project)}/${JSON.stringify(sessionDir)}`);
|
|
4038
|
+
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
4039
|
+
wss.emit("connection", ws, project, sessionDir);
|
|
4040
|
+
});
|
|
4041
|
+
} else {
|
|
4042
|
+
socket.destroy();
|
|
4043
|
+
}
|
|
4044
|
+
} catch {
|
|
3944
4045
|
socket.destroy();
|
|
3945
4046
|
}
|
|
3946
4047
|
});
|
|
@@ -3963,6 +4064,7 @@ var init_pty_routes = __esm({
|
|
|
3963
4064
|
"use strict";
|
|
3964
4065
|
init_cw_routes();
|
|
3965
4066
|
init_origin_guard();
|
|
4067
|
+
init_auth();
|
|
3966
4068
|
REFUSED_CLOSE_CODE = 4404;
|
|
3967
4069
|
}
|
|
3968
4070
|
});
|
|
@@ -4226,7 +4328,7 @@ var init_liveframe_routes = __esm({
|
|
|
4226
4328
|
|
|
4227
4329
|
// ../core/dist/cw-install.js
|
|
4228
4330
|
import { execFile as execFile5 } from "node:child_process";
|
|
4229
|
-
import { createHash as
|
|
4331
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
4230
4332
|
import { accessSync as accessSync2, constants as constants2, existsSync as existsSync11, readFileSync as readFileSync9, statSync as statSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
4231
4333
|
import { delimiter as delimiter2, join as join12 } from "node:path";
|
|
4232
4334
|
function readCwVersion(file) {
|
|
@@ -4343,14 +4445,14 @@ var init_cw_install = __esm({
|
|
|
4343
4445
|
MARKER_FILE = ".forge-cw.json";
|
|
4344
4446
|
INSTALL_TIMEOUT_MS2 = 12e4;
|
|
4345
4447
|
ANSI_RE3 = /\u001b\[[0-9;?]*[A-Za-z]/g;
|
|
4346
|
-
sha256Of = (file) =>
|
|
4347
|
-
runInstall = (script, args, env) => new Promise((
|
|
4448
|
+
sha256Of = (file) => createHash3("sha256").update(readFileSync9(file)).digest("hex");
|
|
4449
|
+
runInstall = (script, args, env) => new Promise((resolve11) => {
|
|
4348
4450
|
execFile5("bash", [script, ...args], { env, timeout: INSTALL_TIMEOUT_MS2, maxBuffer: 1024 * 1024 }, (err, stdout, stderr) => {
|
|
4349
4451
|
const output = `${String(stdout)}${String(stderr)}`;
|
|
4350
4452
|
if (!err)
|
|
4351
|
-
return
|
|
4453
|
+
return resolve11({ code: 0, output });
|
|
4352
4454
|
const code = err.code;
|
|
4353
|
-
|
|
4455
|
+
resolve11({ code: typeof code === "number" ? code : 1, output: output || err.message });
|
|
4354
4456
|
});
|
|
4355
4457
|
});
|
|
4356
4458
|
}
|
|
@@ -6468,12 +6570,12 @@ function rememberPrompt(text2) {
|
|
|
6468
6570
|
return `Remember this with kioku: ${text2.replace(/\s+/g, " ").trim()}`;
|
|
6469
6571
|
}
|
|
6470
6572
|
function createTerminalRunner(env, timeoutMs) {
|
|
6471
|
-
return (bin, args, cwd) => new Promise((
|
|
6573
|
+
return (bin, args, cwd) => new Promise((resolve11) => {
|
|
6472
6574
|
let proc;
|
|
6473
6575
|
try {
|
|
6474
6576
|
proc = pty3.spawn(bin, args, { name: "xterm-256color", cols: 400, rows: 40, cwd, env });
|
|
6475
6577
|
} catch {
|
|
6476
|
-
return
|
|
6578
|
+
return resolve11({ code: 127, stdout: "", stderr: "ENOENT" });
|
|
6477
6579
|
}
|
|
6478
6580
|
let output = "";
|
|
6479
6581
|
const timer = setTimeout(() => proc.kill(), timeoutMs);
|
|
@@ -6483,7 +6585,7 @@ function createTerminalRunner(env, timeoutMs) {
|
|
|
6483
6585
|
proc.onExit(({ exitCode }) => {
|
|
6484
6586
|
clearTimeout(timer);
|
|
6485
6587
|
const json = stripAnsi(output).split(/\r?\n/).reverse().map((line) => line.slice(line.indexOf("{")).trim()).find((line) => parseJson(line) !== null);
|
|
6486
|
-
|
|
6588
|
+
resolve11({ code: exitCode, stdout: json ?? "", stderr: output });
|
|
6487
6589
|
});
|
|
6488
6590
|
});
|
|
6489
6591
|
}
|
|
@@ -6831,7 +6933,7 @@ var init_kioku = __esm({
|
|
|
6831
6933
|
return (await this.viewer).address;
|
|
6832
6934
|
}
|
|
6833
6935
|
startViewer() {
|
|
6834
|
-
const started = new Promise((
|
|
6936
|
+
const started = new Promise((resolve11, reject) => {
|
|
6835
6937
|
const child = spawn7(this.bin, ["web", "--json", "--no-open"], { cwd: homedir5(), stdio: ["ignore", "pipe", "pipe"] });
|
|
6836
6938
|
const lines2 = createInterface({ input: child.stdout });
|
|
6837
6939
|
let stderr = "";
|
|
@@ -6858,7 +6960,7 @@ var init_kioku = __esm({
|
|
|
6858
6960
|
if (settled || event?.event !== "listening" || !event.address?.startsWith("http://127.0.0.1:"))
|
|
6859
6961
|
return;
|
|
6860
6962
|
finish();
|
|
6861
|
-
|
|
6963
|
+
resolve11({ child, address: event.address });
|
|
6862
6964
|
});
|
|
6863
6965
|
child.on("error", (err) => {
|
|
6864
6966
|
const missing = err.code === "ENOENT";
|
|
@@ -7009,7 +7111,7 @@ var init_dist = __esm({
|
|
|
7009
7111
|
|
|
7010
7112
|
// ../core/dist/module-permissions.js
|
|
7011
7113
|
import { realpathSync } from "node:fs";
|
|
7012
|
-
import { basename as basename3, dirname as dirname6, join as join14, resolve as
|
|
7114
|
+
import { basename as basename3, dirname as dirname6, join as join14, resolve as resolve5, sep as sep3 } from "node:path";
|
|
7013
7115
|
function expandGrants(permissions, settings) {
|
|
7014
7116
|
const p = permissions ?? {};
|
|
7015
7117
|
return {
|
|
@@ -7075,11 +7177,11 @@ function allowsCommand(grants, command) {
|
|
|
7075
7177
|
return grants.shell.includes(expandHome(command));
|
|
7076
7178
|
}
|
|
7077
7179
|
async function allowsPath(grants, target) {
|
|
7078
|
-
const real = realOrParent(
|
|
7180
|
+
const real = realOrParent(resolve5(expandHome(target)));
|
|
7079
7181
|
for (const grant of grants) {
|
|
7080
7182
|
const folder = grant.endsWith("/");
|
|
7081
|
-
const base = realOrParent(
|
|
7082
|
-
if (folder ? real === base || real.startsWith(base +
|
|
7183
|
+
const base = realOrParent(resolve5(expandHome(grant)));
|
|
7184
|
+
if (folder ? real === base || real.startsWith(base + sep3) : real === base)
|
|
7083
7185
|
return true;
|
|
7084
7186
|
}
|
|
7085
7187
|
return false;
|
|
@@ -7103,7 +7205,7 @@ var init_module_permissions = __esm({
|
|
|
7103
7205
|
|
|
7104
7206
|
// ../core/dist/module-manifest.js
|
|
7105
7207
|
import { readFileSync as readFileSync10 } from "node:fs";
|
|
7106
|
-
import { join as join15, resolve as
|
|
7208
|
+
import { join as join15, resolve as resolve6, sep as sep4 } from "node:path";
|
|
7107
7209
|
function checkSdk(range, version = SDK_VERSION) {
|
|
7108
7210
|
if (!import_semver2.default.validRange(range))
|
|
7109
7211
|
return `sdk range "${range}" is not valid semver`;
|
|
@@ -7205,9 +7307,9 @@ function checkSettingDef(def, path, allowList, err) {
|
|
|
7205
7307
|
}
|
|
7206
7308
|
}
|
|
7207
7309
|
function insideFolder(dir, relative) {
|
|
7208
|
-
const root = realOrParent(
|
|
7209
|
-
const target = realOrParent(
|
|
7210
|
-
return target === root || target.startsWith(root +
|
|
7310
|
+
const root = realOrParent(resolve6(dir));
|
|
7311
|
+
const target = realOrParent(resolve6(dir, relative));
|
|
7312
|
+
return target === root || target.startsWith(root + sep4);
|
|
7211
7313
|
}
|
|
7212
7314
|
function manifestFileFor(dir) {
|
|
7213
7315
|
try {
|
|
@@ -7443,7 +7545,7 @@ var init_module_context = __esm({
|
|
|
7443
7545
|
|
|
7444
7546
|
// ../core/dist/module-host.js
|
|
7445
7547
|
import { existsSync as existsSync13, readdirSync as readdirSync7, readFileSync as readFileSync11, statSync as statSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
7446
|
-
import { basename as basename4, dirname as dirname7, join as join16, resolve as
|
|
7548
|
+
import { basename as basename4, dirname as dirname7, join as join16, resolve as resolve7, sep as sep5 } from "node:path";
|
|
7447
7549
|
import { pathToFileURL } from "node:url";
|
|
7448
7550
|
function disabled(id, c, reason, m) {
|
|
7449
7551
|
const text2 = (v, fallback) => typeof v === "string" && v ? v : fallback;
|
|
@@ -7556,7 +7658,7 @@ var init_module_host = __esm({
|
|
|
7556
7658
|
// only what was installed into the modules folder; bundled, dev and Forge's own packages stay
|
|
7557
7659
|
removable(c) {
|
|
7558
7660
|
const { modulesDir } = this.opts;
|
|
7559
|
-
return c.source === "installed" && dirname7(c.dir) === modulesDir || c.dir.startsWith(join16(modulesDir, "node_modules") +
|
|
7661
|
+
return c.source === "installed" && dirname7(c.dir) === modulesDir || c.dir.startsWith(join16(modulesDir, "node_modules") + sep5);
|
|
7560
7662
|
}
|
|
7561
7663
|
// scans, reloads and dev changes run one at a time: each one awaits imports midway
|
|
7562
7664
|
queue = Promise.resolve();
|
|
@@ -7607,7 +7709,7 @@ var init_module_host = __esm({
|
|
|
7607
7709
|
}
|
|
7608
7710
|
async addDevNow(path) {
|
|
7609
7711
|
const dirs = this.devDirs();
|
|
7610
|
-
const dir =
|
|
7712
|
+
const dir = resolve7(path);
|
|
7611
7713
|
if (!dirs.includes(dir))
|
|
7612
7714
|
writeFileSync5(this.opts.devFile, JSON.stringify([...dirs, dir], null, 2));
|
|
7613
7715
|
await this.scanNow();
|
|
@@ -7615,7 +7717,7 @@ var init_module_host = __esm({
|
|
|
7615
7717
|
}
|
|
7616
7718
|
removeDev(path) {
|
|
7617
7719
|
return this.serial(async () => {
|
|
7618
|
-
const dir =
|
|
7720
|
+
const dir = resolve7(path);
|
|
7619
7721
|
writeFileSync5(this.opts.devFile, JSON.stringify(this.devDirs().filter((d) => d !== dir), null, 2));
|
|
7620
7722
|
await this.scanNow();
|
|
7621
7723
|
});
|
|
@@ -7714,7 +7816,7 @@ var init_module_host = __esm({
|
|
|
7714
7816
|
return disabled(m.id, c, "modules run only in local mode", m);
|
|
7715
7817
|
let server;
|
|
7716
7818
|
if (m.server) {
|
|
7717
|
-
const file =
|
|
7819
|
+
const file = resolve7(c.dir, m.server);
|
|
7718
7820
|
const owner = file.endsWith(".js") ? nearestPackage(dirname7(file)) : null;
|
|
7719
7821
|
if (owner?.type === "commonjs")
|
|
7720
7822
|
return disabled(m.id, c, `${m.server} is an ES module but ${owner.path} says "type": "commonjs"; add "type": "module" to the module's package.json`, m);
|
|
@@ -7742,7 +7844,7 @@ var init_module_host = __esm({
|
|
|
7742
7844
|
actions: server?.actions?.map((a) => ({ id: a.id, label: a.label, effect: a.effect }))
|
|
7743
7845
|
};
|
|
7744
7846
|
if (m.view) {
|
|
7745
|
-
const entry =
|
|
7847
|
+
const entry = resolve7(c.dir, m.view.entry);
|
|
7746
7848
|
const mtime = existsSync13(entry) ? Math.floor(statSync4(entry).mtimeMs) : 0;
|
|
7747
7849
|
status.view = { url: `/api/modules/${m.id}/view.js`, title: m.view.title ?? m.displayName, version: `${m.version}-${mtime}` };
|
|
7748
7850
|
}
|
|
@@ -7778,9 +7880,9 @@ var init_module_host = __esm({
|
|
|
7778
7880
|
});
|
|
7779
7881
|
|
|
7780
7882
|
// ../core/dist/module-confirmations.js
|
|
7781
|
-
import { createHash as
|
|
7883
|
+
import { createHash as createHash4, randomBytes } from "node:crypto";
|
|
7782
7884
|
function inputHash(input) {
|
|
7783
|
-
return
|
|
7885
|
+
return createHash4("sha256").update(stable(input)).digest("hex");
|
|
7784
7886
|
}
|
|
7785
7887
|
function stable(value) {
|
|
7786
7888
|
if (Array.isArray(value))
|
|
@@ -7830,7 +7932,7 @@ var init_module_confirmations = __esm({
|
|
|
7830
7932
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
7831
7933
|
import { existsSync as existsSync14, mkdirSync as mkdirSync5, mkdtempSync, readFileSync as readFileSync12, rmSync as rmSync3 } from "node:fs";
|
|
7832
7934
|
import { homedir as homedir7, tmpdir } from "node:os";
|
|
7833
|
-
import { isAbsolute as isAbsolute2, join as join17, resolve as
|
|
7935
|
+
import { isAbsolute as isAbsolute2, join as join17, resolve as resolve8, sep as sep6 } from "node:path";
|
|
7834
7936
|
async function previewManifest(spec, opts) {
|
|
7835
7937
|
if (isPathSpec(spec, opts.cwd))
|
|
7836
7938
|
return readFolder(expand(spec, opts.cwd));
|
|
@@ -7905,8 +8007,8 @@ var init_module_install = __esm({
|
|
|
7905
8007
|
init_output();
|
|
7906
8008
|
init_state_log();
|
|
7907
8009
|
TRUST_NOTE = "Modules run inside Forge with your access. Forge checks every call against these permissions, but it is not a sandbox: install only modules you trust.";
|
|
7908
|
-
isPathSpec = (spec, cwd) => spec.startsWith(".") || spec.startsWith("~") || isAbsolute2(spec) || existsSync14(
|
|
7909
|
-
expand = (spec, cwd) =>
|
|
8010
|
+
isPathSpec = (spec, cwd) => spec.startsWith(".") || spec.startsWith("~") || isAbsolute2(spec) || existsSync14(resolve8(cwd, spec)) && !spec.startsWith("@");
|
|
8011
|
+
expand = (spec, cwd) => resolve8(cwd, expandHome(spec));
|
|
7910
8012
|
InstallError = class extends Error {
|
|
7911
8013
|
code;
|
|
7912
8014
|
constructor(code, message2) {
|
|
@@ -7977,7 +8079,7 @@ var init_module_install = __esm({
|
|
|
7977
8079
|
throw new InstallError("not_found", `No module ${id}`);
|
|
7978
8080
|
if (!found.removable)
|
|
7979
8081
|
throw new InstallError("bad_request", `${id} was not installed into Forge's modules folder; a dev folder unloads when forge module dev stops`);
|
|
7980
|
-
const packages2 = join17(this.opts.modulesDir, "node_modules") +
|
|
8082
|
+
const packages2 = join17(this.opts.modulesDir, "node_modules") + sep6;
|
|
7981
8083
|
if (found.dir.startsWith(packages2)) {
|
|
7982
8084
|
const name = packageName(found.dir) ?? found.dir.slice(packages2.length);
|
|
7983
8085
|
const res = await this.opts.run("npm", ["uninstall", "--prefix", this.opts.modulesDir, name], this.opts.modulesDir);
|
|
@@ -8005,7 +8107,7 @@ var init_module_install = __esm({
|
|
|
8005
8107
|
|
|
8006
8108
|
// ../core/dist/module-routes.js
|
|
8007
8109
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
8008
|
-
import { resolve as
|
|
8110
|
+
import { resolve as resolve9 } from "node:path";
|
|
8009
8111
|
import { Hono as Hono5 } from "hono";
|
|
8010
8112
|
function moduleRoutes(host, opts) {
|
|
8011
8113
|
const { db } = opts;
|
|
@@ -8098,7 +8200,7 @@ function moduleRoutes(host, opts) {
|
|
|
8098
8200
|
if (!mod?.manifest.view)
|
|
8099
8201
|
return c.json(removed(c.req.param("id")), 404);
|
|
8100
8202
|
try {
|
|
8101
|
-
const code = await readFile2(
|
|
8203
|
+
const code = await readFile2(resolve9(mod.dir, mod.manifest.view.entry), "utf-8");
|
|
8102
8204
|
return c.body(code, 200, { "Content-Type": "text/javascript; charset=utf-8", "Cache-Control": "no-cache" });
|
|
8103
8205
|
} catch (err) {
|
|
8104
8206
|
return c.json({ code: "not_found", message: `view bundle missing: ${err.message}` }, 404);
|
|
@@ -8446,10 +8548,13 @@ var init_module_events = __esm({
|
|
|
8446
8548
|
// ../core/dist/server.js
|
|
8447
8549
|
import { Hono as Hono6 } from "hono";
|
|
8448
8550
|
import { cors } from "hono/cors";
|
|
8449
|
-
import { join as join18, basename as basename5, resolve as
|
|
8551
|
+
import { join as join18, basename as basename5, resolve as resolve10 } from "node:path";
|
|
8450
8552
|
import { readdirSync as readdirSync8, existsSync as existsSync15 } from "node:fs";
|
|
8451
8553
|
function createForgeServer(options) {
|
|
8452
8554
|
const { dataDir, db: externalDb, authToken, localOnly = true } = options;
|
|
8555
|
+
const authProblem = remoteAuthProblem(localOnly, authToken);
|
|
8556
|
+
if (authProblem)
|
|
8557
|
+
throw new Error(authProblem);
|
|
8453
8558
|
const dbPath = join18(dataDir, "forge.db");
|
|
8454
8559
|
const modulesDir = join18(dataDir, "modules");
|
|
8455
8560
|
const db = externalDb ?? new ForgeDB(dbPath);
|
|
@@ -8458,8 +8563,14 @@ function createForgeServer(options) {
|
|
|
8458
8563
|
loader.discover();
|
|
8459
8564
|
const app = new Hono6();
|
|
8460
8565
|
app.use("*", localOnly ? localOriginGuard() : cors());
|
|
8566
|
+
app.use("*", async (c, next) => {
|
|
8567
|
+
await next();
|
|
8568
|
+
c.header("X-Frame-Options", "DENY");
|
|
8569
|
+
c.header("Content-Security-Policy", "frame-ancestors 'none'");
|
|
8570
|
+
});
|
|
8461
8571
|
if (authToken) {
|
|
8462
8572
|
app.use("/api/*", bearerAuth(authToken));
|
|
8573
|
+
mountAuthRoute(app, authToken);
|
|
8463
8574
|
}
|
|
8464
8575
|
const cwReader = new CWReader(options.cwDir);
|
|
8465
8576
|
const loginManager = new LoginManager(resolveCwBin(cwReader.cwHome));
|
|
@@ -8485,7 +8596,7 @@ function createForgeServer(options) {
|
|
|
8485
8596
|
});
|
|
8486
8597
|
const ptyManager = new PTYManager(states);
|
|
8487
8598
|
const generalSessions = new GeneralSessions(join18(dataDir, "general-sessions.json"));
|
|
8488
|
-
const terminalWss = createTerminalWss(ptyManager, cwReader, { localOnly, general: generalSessions });
|
|
8599
|
+
const terminalWss = createTerminalWss(ptyManager, cwReader, { localOnly, authToken, general: generalSessions });
|
|
8489
8600
|
app.route("/api/liveframe", liveframeRoutes());
|
|
8490
8601
|
const kioku = new Kioku({ projects: () => cwReader.getProjects(), pluginInstalls: () => installsOf(cwReader, "kioku") });
|
|
8491
8602
|
app.route("/api/kioku", kiokuRoutes(kioku, {
|
|
@@ -8693,7 +8804,7 @@ data: ${JSON.stringify(data)}
|
|
|
8693
8804
|
});
|
|
8694
8805
|
app.get("/api/filesystem/browse", (c) => {
|
|
8695
8806
|
const home = process.env.HOME ?? "/tmp";
|
|
8696
|
-
const dir =
|
|
8807
|
+
const dir = resolve10(c.req.query("path") ?? process.cwd());
|
|
8697
8808
|
if (!dir.startsWith(home)) {
|
|
8698
8809
|
return c.json({ error: "Access denied: path must be within home directory" }, 403);
|
|
8699
8810
|
}
|
|
@@ -8962,14 +9073,14 @@ var init_init = __esm({
|
|
|
8962
9073
|
function waitForListening(server) {
|
|
8963
9074
|
if (server.listening)
|
|
8964
9075
|
return Promise.resolve();
|
|
8965
|
-
return new Promise((
|
|
9076
|
+
return new Promise((resolve11, reject) => {
|
|
8966
9077
|
const onError = (err) => {
|
|
8967
9078
|
server.off("listening", onListening);
|
|
8968
9079
|
reject(err);
|
|
8969
9080
|
};
|
|
8970
9081
|
const onListening = () => {
|
|
8971
9082
|
server.off("error", onError);
|
|
8972
|
-
|
|
9083
|
+
resolve11();
|
|
8973
9084
|
};
|
|
8974
9085
|
server.once("error", onError);
|
|
8975
9086
|
server.once("listening", onListening);
|
|
@@ -9008,6 +9119,7 @@ var init_port_in_use = __esm({
|
|
|
9008
9119
|
var dist_exports = {};
|
|
9009
9120
|
__export(dist_exports, {
|
|
9010
9121
|
ACCOUNT_NAME_RE: () => ACCOUNT_NAME_RE,
|
|
9122
|
+
AUTH_COOKIE: () => AUTH_COOKIE,
|
|
9011
9123
|
ActionRunner: () => ActionRunner,
|
|
9012
9124
|
CWReader: () => CWReader,
|
|
9013
9125
|
ForgeDB: () => ForgeDB,
|
|
@@ -9033,6 +9145,7 @@ __export(dist_exports, {
|
|
|
9033
9145
|
ensureForgeDir: () => ensureForgeDir,
|
|
9034
9146
|
getForgeDir: () => getForgeDir,
|
|
9035
9147
|
installArgs: () => installArgs,
|
|
9148
|
+
isAuthorized: () => isAuthorized,
|
|
9036
9149
|
kiokuRoutes: () => kiokuRoutes,
|
|
9037
9150
|
liveframeRoutes: () => liveframeRoutes,
|
|
9038
9151
|
pathWithCw: () => pathWithCw,
|
|
@@ -9041,6 +9154,7 @@ __export(dist_exports, {
|
|
|
9041
9154
|
probePort: () => probePort,
|
|
9042
9155
|
quietSqliteWarning: () => quietSqliteWarning,
|
|
9043
9156
|
rememberPrompt: () => rememberPrompt,
|
|
9157
|
+
remoteAuthProblem: () => remoteAuthProblem,
|
|
9044
9158
|
resolveKiokuBin: () => resolveKiokuBin,
|
|
9045
9159
|
resolveListenOptions: () => resolveListenOptions,
|
|
9046
9160
|
skillRoutes: () => skillRoutes,
|
|
@@ -9098,7 +9212,7 @@ var consoleDist = isCheckout ? join20(packageRoot, "../console/dist") : join20(p
|
|
|
9098
9212
|
var forgeVersion = JSON.parse(readFileSync13(join20(packageRoot, "package.json"), "utf-8")).version;
|
|
9099
9213
|
var bundledModulesDir = isCheckout ? join20(packageRoot, "../../modules") : join20(packageRoot, "modules");
|
|
9100
9214
|
async function main() {
|
|
9101
|
-
const { ensureForgeDir: ensureForgeDir2, createForgeServer: createForgeServer2, createDatabase: createDatabase2, resolveListenOptions: resolveListenOptions2, ensureCw: ensureCw2, pathWithCw: pathWithCw2, quietSqliteWarning: quietSqliteWarning2, waitForListening: waitForListening2, probePort: probePort2, portInUseMessage: portInUseMessage2 } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
|
|
9215
|
+
const { ensureForgeDir: ensureForgeDir2, createForgeServer: createForgeServer2, createDatabase: createDatabase2, resolveListenOptions: resolveListenOptions2, remoteAuthProblem: remoteAuthProblem2, ensureCw: ensureCw2, pathWithCw: pathWithCw2, quietSqliteWarning: quietSqliteWarning2, waitForListening: waitForListening2, probePort: probePort2, portInUseMessage: portInUseMessage2 } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
|
|
9102
9216
|
quietSqliteWarning2();
|
|
9103
9217
|
const args = parseArgs(process.argv.slice(2));
|
|
9104
9218
|
const { forgeDir, created } = ensureForgeDir2();
|
|
@@ -9116,6 +9230,14 @@ async function main() {
|
|
|
9116
9230
|
const authToken = process.env.FORGE_AUTH_TOKEN;
|
|
9117
9231
|
const isTeam = !!dbUrl;
|
|
9118
9232
|
const { host, localOnly } = resolveListenOptions2(isTeam);
|
|
9233
|
+
const authProblem = remoteAuthProblem2(localOnly, authToken);
|
|
9234
|
+
if (authProblem) {
|
|
9235
|
+
console.log(`
|
|
9236
|
+
${authProblem}
|
|
9237
|
+
`);
|
|
9238
|
+
process.exit(1);
|
|
9239
|
+
}
|
|
9240
|
+
const remoteToken = localOnly ? void 0 : authToken;
|
|
9119
9241
|
const db = await createDatabase2({
|
|
9120
9242
|
mode: isTeam ? "team" : "local",
|
|
9121
9243
|
dataDir: forgeDir,
|
|
@@ -9125,7 +9247,7 @@ async function main() {
|
|
|
9125
9247
|
dataDir: forgeDir,
|
|
9126
9248
|
port,
|
|
9127
9249
|
db,
|
|
9128
|
-
authToken:
|
|
9250
|
+
authToken: remoteToken,
|
|
9129
9251
|
localOnly,
|
|
9130
9252
|
bundledModulesDir,
|
|
9131
9253
|
version: forgeVersion
|
|
@@ -9159,7 +9281,9 @@ async function main() {
|
|
|
9159
9281
|
console.log(`
|
|
9160
9282
|
Forge Console running at http://localhost:${port}
|
|
9161
9283
|
Mode: ${isTeam ? "team (PostgreSQL)" : "local (SQLite)"}
|
|
9162
|
-
${
|
|
9284
|
+
${remoteToken ? ` Auth: token required. Browsers sign in once at http://<this host>:${port}/auth?token=<FORGE_AUTH_TOKEN>;
|
|
9285
|
+
the CLI and scripts send Authorization: Bearer <FORGE_AUTH_TOKEN>
|
|
9286
|
+
` : ""}
|
|
9163
9287
|
Dashboard: http://localhost:${port}
|
|
9164
9288
|
API: http://localhost:${port}/api/health
|
|
9165
9289
|
|
|
@@ -9168,7 +9292,7 @@ ${authToken ? " Auth: bearer token required\n" : ""}
|
|
|
9168
9292
|
if (args.open && process.env.FORGE_NO_OPEN !== "1") {
|
|
9169
9293
|
try {
|
|
9170
9294
|
const open = (await import("open")).default;
|
|
9171
|
-
await open(`http://localhost:${port}`);
|
|
9295
|
+
await open(remoteToken ? `http://localhost:${port}/auth?token=${encodeURIComponent(remoteToken)}` : `http://localhost:${port}`);
|
|
9172
9296
|
} catch {
|
|
9173
9297
|
}
|
|
9174
9298
|
}
|