forge-cw 0.1.19 → 0.1.20

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.
Files changed (2) hide show
  1. package/dist/index.js +133 -87
  2. 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((resolve10) => {
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
- resolve10({
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
- resolve10({ exitCode: 1, output, timedOut });
422
+ resolve11({ exitCode: 1, output, timedOut });
423
423
  });
424
424
  });
425
425
  }
@@ -509,7 +509,12 @@ function isLocalRequest(host, origin) {
509
509
  if (origin === void 0)
510
510
  return true;
511
511
  try {
512
- return LOOPBACK_HOSTNAMES.has(new URL(origin).hostname);
512
+ const url = new URL(origin);
513
+ if (!LOOPBACK_HOSTNAMES.has(url.hostname))
514
+ return false;
515
+ if (DEV_ORIGINS.has(url.origin))
516
+ return true;
517
+ return url.host === new URL(`http://${host}`).host;
513
518
  } catch {
514
519
  return false;
515
520
  }
@@ -526,17 +531,30 @@ function localOriginGuard() {
526
531
  return next();
527
532
  };
528
533
  }
529
- var LOOPBACK_HOSTNAMES;
534
+ var LOOPBACK_HOSTNAMES, DEV_ORIGINS;
530
535
  var init_origin_guard = __esm({
531
536
  "../core/dist/origin-guard.js"() {
532
537
  "use strict";
533
538
  LOOPBACK_HOSTNAMES = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
539
+ DEV_ORIGINS = /* @__PURE__ */ new Set(["http://localhost:5173", "http://127.0.0.1:5173"]);
534
540
  }
535
541
  });
536
542
 
537
543
  // ../core/dist/cw-reader.js
538
544
  import { readdirSync as readdirSync2, readFileSync as readFileSync2, existsSync as existsSync2 } from "node:fs";
539
- import { join as join2 } from "node:path";
545
+ import { join as join2, resolve, sep } from "node:path";
546
+ function sessionFolder(cwDir, project, sessionDir = "") {
547
+ if (typeof project !== "string" || typeof sessionDir !== "string")
548
+ return null;
549
+ if (!project || project === "." || project === ".." || /[\\/\0]/.test(project))
550
+ return null;
551
+ const segments = sessionDir ? sessionDir.split("/") : [];
552
+ if (segments.some((s) => s === "" || s === "." || s === ".." || /[\\\0]/.test(s)))
553
+ return null;
554
+ const root = resolve(cwDir, "sessions");
555
+ const dir = resolve(root, project, ...segments);
556
+ return dir.startsWith(root + sep) ? dir : null;
557
+ }
540
558
  function* walkSessionDirs(baseDir, rel = "", depth = 0) {
541
559
  if (depth >= MAX_SESSION_DEPTH)
542
560
  return;
@@ -600,7 +618,10 @@ var init_cw_reader = __esm({
600
618
  return sessions.sort((a, b) => new Date(b.last_opened).getTime() - new Date(a.last_opened).getTime());
601
619
  }
602
620
  getSession(project, sessionDir) {
603
- const path = join2(this.cwDir, "sessions", project, sessionDir, "session.json");
621
+ const dir = sessionFolder(this.cwDir, project, sessionDir);
622
+ if (!dir)
623
+ return null;
624
+ const path = join2(dir, "session.json");
604
625
  if (!existsSync2(path))
605
626
  return null;
606
627
  try {
@@ -612,7 +633,9 @@ var init_cw_reader = __esm({
612
633
  }
613
634
  }
614
635
  getNotes(project, sessionDir) {
615
- const baseDir = join2(this.cwDir, "sessions", project, sessionDir);
636
+ const baseDir = sessionFolder(this.cwDir, project, sessionDir);
637
+ if (!baseDir)
638
+ return "";
616
639
  const sessionPath = join2(baseDir, "session.json");
617
640
  if (existsSync2(sessionPath)) {
618
641
  try {
@@ -936,19 +959,19 @@ function envWithoutHarness(env = process.env) {
936
959
  return out;
937
960
  }
938
961
  function runDoctor(cwBin) {
939
- return new Promise((resolve10) => {
962
+ return new Promise((resolve11) => {
940
963
  execFile(cwBin, ["doctor", "--json"], { timeout: TIMEOUT_MS, env: envWithoutHarness(), maxBuffer: 10 * 1024 * 1024 }, (err, stdout) => {
941
964
  if (err)
942
- return resolve10({ available: false, reason: err.message });
965
+ return resolve11({ available: false, reason: err.message });
943
966
  let parsed;
944
967
  try {
945
968
  parsed = JSON.parse(stdout);
946
969
  } catch {
947
- return resolve10({ available: false, reason: "cw doctor --json did not print JSON" });
970
+ return resolve11({ available: false, reason: "cw doctor --json did not print JSON" });
948
971
  }
949
972
  if (parsed.schema !== 1)
950
- return resolve10({ available: false, reason: `unsupported doctor schema ${String(parsed.schema)}` });
951
- resolve10({ available: true, doctor: parsed });
973
+ return resolve11({ available: false, reason: `unsupported doctor schema ${String(parsed.schema)}` });
974
+ resolve11({ available: true, doctor: parsed });
952
975
  });
953
976
  });
954
977
  }
@@ -1053,14 +1076,14 @@ function closeWarningsFor(input) {
1053
1076
  return warnings;
1054
1077
  }
1055
1078
  function createRunner(env, timeoutMs = COMMAND_TIMEOUT_MS) {
1056
- return (bin, args, cwd, input) => new Promise((resolve10) => {
1079
+ return (bin, args, cwd, input) => new Promise((resolve11) => {
1057
1080
  const child = execFile2(bin, args, { cwd, env, timeout: timeoutMs, maxBuffer: 5 * 1024 * 1024 }, (err, stdout, stderr) => {
1058
1081
  if (!err)
1059
- return resolve10({ code: 0, stdout: String(stdout), stderr: String(stderr) });
1082
+ return resolve11({ code: 0, stdout: String(stdout), stderr: String(stderr) });
1060
1083
  const { code } = err;
1061
1084
  if (code === "ENOENT")
1062
- return resolve10({ code: 127, stdout: "", stderr: "ENOENT" });
1063
- resolve10({ code: typeof code === "number" ? code : 1, stdout: String(stdout), stderr: String(stderr) || err.message });
1085
+ return resolve11({ code: 127, stdout: "", stderr: "ENOENT" });
1086
+ resolve11({ code: typeof code === "number" ? code : 1, stdout: String(stdout), stderr: String(stderr) || err.message });
1064
1087
  });
1065
1088
  if (input !== void 0) {
1066
1089
  child.stdin?.on("error", () => {
@@ -1260,7 +1283,7 @@ function createLimiter(max) {
1260
1283
  const waiting = [];
1261
1284
  return async (fn) => {
1262
1285
  if (active >= max)
1263
- await new Promise((resolve10) => waiting.push(resolve10));
1286
+ await new Promise((resolve11) => waiting.push(resolve11));
1264
1287
  else
1265
1288
  active++;
1266
1289
  try {
@@ -1460,7 +1483,7 @@ function mapCodexUsage(payload) {
1460
1483
  });
1461
1484
  }
1462
1485
  function callCodexAppServer(bin, codexHome, timeoutMs = TIMEOUT_MS3) {
1463
- return new Promise((resolve10, reject) => {
1486
+ return new Promise((resolve11, reject) => {
1464
1487
  const child = spawn2(bin, ["app-server"], { env: { ...CHILD_ENV, CODEX_HOME: codexHome }, stdio: ["pipe", "pipe", "ignore"] });
1465
1488
  let buffer = "";
1466
1489
  let settled = false;
@@ -1480,7 +1503,7 @@ function callCodexAppServer(bin, codexHome, timeoutMs = TIMEOUT_MS3) {
1480
1503
  const done = (value) => {
1481
1504
  if (!settled) {
1482
1505
  stop();
1483
- resolve10(value);
1506
+ resolve11(value);
1484
1507
  }
1485
1508
  };
1486
1509
  const timer = setTimeout(() => fail(new Error(`codex app-server did not answer in ${timeoutMs / 1e3} s`)), timeoutMs);
@@ -1747,7 +1770,7 @@ var init_login_manager = __esm({
1747
1770
  // ../core/dist/api-key-login.js
1748
1771
  import { spawn as spawn4 } from "node:child_process";
1749
1772
  function importApiKey(cwBin, account, harness, apiKey) {
1750
- return new Promise((resolve10) => {
1773
+ return new Promise((resolve11) => {
1751
1774
  const redact = (text2) => text2.split(apiKey).join("***").trim();
1752
1775
  const child = spawn4(cwBin, ["account", "login", account, "--harness", harness, "--with-api-key", "-"], {
1753
1776
  env: envWithoutHarness(),
@@ -1764,11 +1787,11 @@ function importApiKey(cwBin, account, harness, apiKey) {
1764
1787
  const timer = setTimeout(() => child.kill(), TIMEOUT_MS4);
1765
1788
  child.on("error", (err) => {
1766
1789
  clearTimeout(timer);
1767
- resolve10({ ok: false, error: redact(err.message) });
1790
+ resolve11({ ok: false, error: redact(err.message) });
1768
1791
  });
1769
1792
  child.on("close", (code) => {
1770
1793
  clearTimeout(timer);
1771
- resolve10(code === 0 ? { ok: true } : { ok: false, error: redact(output) || `cw exited with ${String(code)}` });
1794
+ resolve11(code === 0 ? { ok: true } : { ok: false, error: redact(output) || `cw exited with ${String(code)}` });
1772
1795
  });
1773
1796
  child.stdin.end(`${apiKey}
1774
1797
  `);
@@ -1800,12 +1823,12 @@ function detectEditors(probe) {
1800
1823
  return found;
1801
1824
  }
1802
1825
  function openInEditor(editor, dir) {
1803
- return new Promise((resolve10, reject) => {
1826
+ return new Promise((resolve11, reject) => {
1804
1827
  const child = spawn5(editor.bin, [...editor.args, dir], { detached: true, stdio: "ignore" });
1805
1828
  child.once("error", reject);
1806
1829
  child.once("spawn", () => {
1807
1830
  child.unref();
1808
- resolve10();
1831
+ resolve11();
1809
1832
  });
1810
1833
  });
1811
1834
  }
@@ -1857,7 +1880,7 @@ import { Hono } from "hono";
1857
1880
  import { execFileSync, execFile as execFile4 } from "node:child_process";
1858
1881
  import { promisify as promisify2 } from "node:util";
1859
1882
  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";
1883
+ import { join as join7, resolve as resolve2, dirname, basename, isAbsolute } from "node:path";
1861
1884
  import { homedir as homedir2 } from "node:os";
1862
1885
  function resolveCwBin(cwHome) {
1863
1886
  const candidate = join7(cwHome, "bin", "cw");
@@ -2312,7 +2335,9 @@ function cwRoutes(reader, options = {}) {
2312
2335
  }
2313
2336
  }
2314
2337
  const dirPrefix = type === "review" ? "review-pr-" : "task-";
2315
- const sessionDir = join7(cwHome, "sessions", project, `${dirPrefix}${taskSlug}`);
2338
+ const sessionDir = sessionFolder(cwHome, project, `${dirPrefix}${taskSlug}`);
2339
+ if (!sessionDir)
2340
+ return c.json({ ok: false, error: "Invalid project or task name" }, 400);
2316
2341
  const sessionFile = join7(sessionDir, "session.json");
2317
2342
  if (existsSync5(sessionFile)) {
2318
2343
  try {
@@ -2344,7 +2369,7 @@ function cwRoutes(reader, options = {}) {
2344
2369
  if (harness)
2345
2370
  args.push("--harness", harness);
2346
2371
  if (description) {
2347
- const notesDir = join7(cwHome, "sessions", project, `${dirPrefix}${taskSlug}`);
2372
+ const notesDir = sessionDir;
2348
2373
  mkdirSync(notesDir, { recursive: true });
2349
2374
  const notesFile = join7(notesDir, type === "review" ? "REVIEW_NOTES.md" : "TASK_NOTES.md");
2350
2375
  if (!existsSync5(notesFile)) {
@@ -2451,13 +2476,15 @@ ${result2.stderr}`);
2451
2476
  });
2452
2477
  app.post("/delete-project", async (c) => {
2453
2478
  const { project, deleteFiles } = await c.req.json();
2479
+ const sessionsDir = sessionFolder(reader.cwHome, project);
2480
+ if (!sessionsDir)
2481
+ return c.json({ ok: false, error: "Invalid project name" }, 400);
2454
2482
  const projects = reader.getProjects();
2455
2483
  const projPath = projects[project]?.path;
2456
2484
  try {
2457
2485
  execFileSync(cwBin, ["project", "remove", project, "--yes"], { encoding: "utf-8", timeout: 1e4, stdio: "pipe", env: envWithoutHarness() });
2458
2486
  } catch {
2459
2487
  }
2460
- const sessionsDir = join7(reader.cwHome, "sessions", project);
2461
2488
  if (existsSync5(sessionsDir)) {
2462
2489
  try {
2463
2490
  rmSync(sessionsDir, { recursive: true, force: true });
@@ -2482,7 +2509,7 @@ ${result2.stderr}`);
2482
2509
  p = join7(home, p.slice(1).replace(/^\//, ""));
2483
2510
  if (!isAbsolute(p))
2484
2511
  return null;
2485
- return resolve(p);
2512
+ return resolve2(p);
2486
2513
  };
2487
2514
  app.get("/browse-dirs", (c) => {
2488
2515
  const requested = c.req.query("path") ?? "~";
@@ -2568,6 +2595,7 @@ var execFileAsync2, GENERAL_PROJECT, CREATING_PROJECT, ACCOUNTS_PROJECT, pending
2568
2595
  var init_cw_routes = __esm({
2569
2596
  "../core/dist/cw-routes.js"() {
2570
2597
  "use strict";
2598
+ init_cw_reader();
2571
2599
  init_cw_types();
2572
2600
  init_cw_doctor();
2573
2601
  init_usage();
@@ -2588,7 +2616,7 @@ var init_cw_routes = __esm({
2588
2616
 
2589
2617
  // ../core/dist/plugins.js
2590
2618
  import { existsSync as existsSync6, readFileSync as readFileSync6, readdirSync as readdirSync4 } from "node:fs";
2591
- import { basename as basename2, join as join8, resolve as resolve2, sep } from "node:path";
2619
+ import { basename as basename2, join as join8, resolve as resolve3, sep as sep2 } from "node:path";
2592
2620
  function readJson(path) {
2593
2621
  try {
2594
2622
  const value = JSON.parse(readFileSync6(path, "utf-8"));
@@ -2622,10 +2650,10 @@ function scanDirs(root) {
2622
2650
  function skillDirs(installPath, manifest) {
2623
2651
  const listed = manifest["skills"];
2624
2652
  if (Array.isArray(listed)) {
2625
- return listed.filter((p) => typeof p === "string").map((p) => resolve2(installPath, p)).filter((p) => inside(installPath, p));
2653
+ return listed.filter((p) => typeof p === "string").map((p) => resolve3(installPath, p)).filter((p) => inside(installPath, p));
2626
2654
  }
2627
2655
  if (typeof listed === "string") {
2628
- const root = resolve2(installPath, listed);
2656
+ const root = resolve3(installPath, listed);
2629
2657
  return inside(installPath, root) ? scanDirs(root) : [];
2630
2658
  }
2631
2659
  return scanDirs(join8(installPath, "skills"));
@@ -2694,7 +2722,7 @@ function catalogVersion(configDir, marketplaces, marketplace, name) {
2694
2722
  const source = entry["source"];
2695
2723
  if (typeof source !== "string")
2696
2724
  return void 0;
2697
- const dir = resolve2(location, source);
2725
+ const dir = resolve3(location, source);
2698
2726
  if (!inside(location, dir))
2699
2727
  return void 0;
2700
2728
  const version = readJson(join8(dir, ".claude-plugin", "plugin.json"))["version"];
@@ -2840,9 +2868,9 @@ var init_plugins = __esm({
2840
2868
  "use strict";
2841
2869
  isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2842
2870
  inside = (root, path) => {
2843
- const r = resolve2(root);
2844
- const p = resolve2(path);
2845
- return p === r || p.startsWith(r + sep);
2871
+ const r = resolve3(root);
2872
+ const p = resolve3(path);
2873
+ return p === r || p.startsWith(r + sep2);
2846
2874
  };
2847
2875
  pluginScopes = (reader) => [
2848
2876
  { scope: "global", scopeRef: "global" },
@@ -3606,7 +3634,7 @@ var init_terminal_screen = __esm({
3606
3634
  }
3607
3635
  // rows oldest first, scrollback included, without the blank rows under the last one written
3608
3636
  read() {
3609
- return new Promise((resolve10) => this.term.write("", () => {
3637
+ return new Promise((resolve11) => this.term.write("", () => {
3610
3638
  const buffer = this.term.buffer.active;
3611
3639
  const rows = [];
3612
3640
  for (let y = 0; y < buffer.length; y++) {
@@ -3622,7 +3650,7 @@ var init_terminal_screen = __esm({
3622
3650
  const trimmed = rows.map((r) => r.trimEnd());
3623
3651
  while (trimmed.length && !trimmed[trimmed.length - 1])
3624
3652
  trimmed.pop();
3625
- resolve10(trimmed.join("\n"));
3653
+ resolve11(trimmed.join("\n"));
3626
3654
  }));
3627
3655
  }
3628
3656
  dispose() {
@@ -3822,7 +3850,7 @@ var init_session_state = __esm({
3822
3850
  import { mkdirSync as mkdirSync3 } from "node:fs";
3823
3851
  import { appendFile } from "node:fs/promises";
3824
3852
  import { homedir as homedir3 } from "node:os";
3825
- import { dirname as dirname4, resolve as resolve3 } from "node:path";
3853
+ import { dirname as dirname4, resolve as resolve4 } from "node:path";
3826
3854
  function expandHome(path) {
3827
3855
  return path === "~" || path.startsWith("~/") ? homedir3() + path.slice(1) : path;
3828
3856
  }
@@ -3841,7 +3869,7 @@ function stateLogLine(call) {
3841
3869
  }
3842
3870
  function createStateLog(path, onError = () => {
3843
3871
  }) {
3844
- const file = resolve3(expandHome(path));
3872
+ const file = resolve4(expandHome(path));
3845
3873
  mkdirSync3(dirname4(file), { recursive: true });
3846
3874
  let queue = Promise.resolve();
3847
3875
  return (call) => {
@@ -3904,6 +3932,10 @@ function createTerminalWss(manager, reader, { localOnly = true, general } = {})
3904
3932
  });
3905
3933
  }
3906
3934
  wss.on("connection", (ws, project, sessionDir) => {
3935
+ ws.on("error", (err) => {
3936
+ console.error(`[pty-ws] Socket error on ${project}/${sessionDir}: ${err.message}`);
3937
+ ws.terminate();
3938
+ });
3907
3939
  console.log(`[pty-ws] Connected: ${project}/${sessionDir}`);
3908
3940
  const sessionId = `${project}::${sessionDir}`;
3909
3941
  if (manager.has(sessionId)) {
@@ -3917,7 +3949,12 @@ function createTerminalWss(manager, reader, { localOnly = true, general } = {})
3917
3949
  ws.close(REFUSED_CLOSE_CODE);
3918
3950
  return;
3919
3951
  }
3920
- const ptySession = manager.getOrCreate(project, sessionDir, taken.session, { isNew: taken.isNew });
3952
+ let ptySession = null;
3953
+ try {
3954
+ ptySession = manager.getOrCreate(project, sessionDir, taken.session, { isNew: taken.isNew });
3955
+ } catch (err) {
3956
+ console.error(`[pty-ws] Could not launch ${project}/${sessionDir}: ${err.message}`);
3957
+ }
3921
3958
  if (!ptySession) {
3922
3959
  console.error(`[pty-ws] Failed to spawn terminal for: ${project}/${sessionDir}`);
3923
3960
  ws.send(JSON.stringify({ type: "error", message: `Failed to start terminal for ${project}/${sessionDir}` }));
@@ -3928,19 +3965,23 @@ function createTerminalWss(manager, reader, { localOnly = true, general } = {})
3928
3965
  });
3929
3966
  function attachToServer(server) {
3930
3967
  server.on("upgrade", (request, socket, head) => {
3931
- if (localOnly && !isLocalRequest(request.headers.host, request.headers.origin)) {
3932
- socket.destroy();
3933
- return;
3934
- }
3935
- const url = new URL(request.url ?? "/", "http://localhost");
3936
- const parsed = parseTerminalUpgradeUrl(url.pathname);
3937
- if (parsed) {
3938
- const { project, sessionDir } = parsed;
3939
- console.log(`[pty-ws] Upgrade request: ${project}/${sessionDir}`);
3940
- wss.handleUpgrade(request, socket, head, (ws) => {
3941
- wss.emit("connection", ws, project, sessionDir);
3942
- });
3943
- } else {
3968
+ try {
3969
+ if (localOnly && !isLocalRequest(request.headers.host, request.headers.origin)) {
3970
+ socket.destroy();
3971
+ return;
3972
+ }
3973
+ const url = new URL(request.url ?? "/", "http://localhost");
3974
+ const parsed = parseTerminalUpgradeUrl(url.pathname);
3975
+ if (parsed) {
3976
+ const { project, sessionDir } = parsed;
3977
+ console.log(`[pty-ws] Upgrade request: ${JSON.stringify(project)}/${JSON.stringify(sessionDir)}`);
3978
+ wss.handleUpgrade(request, socket, head, (ws) => {
3979
+ wss.emit("connection", ws, project, sessionDir);
3980
+ });
3981
+ } else {
3982
+ socket.destroy();
3983
+ }
3984
+ } catch {
3944
3985
  socket.destroy();
3945
3986
  }
3946
3987
  });
@@ -4344,13 +4385,13 @@ var init_cw_install = __esm({
4344
4385
  INSTALL_TIMEOUT_MS2 = 12e4;
4345
4386
  ANSI_RE3 = /\u001b\[[0-9;?]*[A-Za-z]/g;
4346
4387
  sha256Of = (file) => createHash2("sha256").update(readFileSync9(file)).digest("hex");
4347
- runInstall = (script, args, env) => new Promise((resolve10) => {
4388
+ runInstall = (script, args, env) => new Promise((resolve11) => {
4348
4389
  execFile5("bash", [script, ...args], { env, timeout: INSTALL_TIMEOUT_MS2, maxBuffer: 1024 * 1024 }, (err, stdout, stderr) => {
4349
4390
  const output = `${String(stdout)}${String(stderr)}`;
4350
4391
  if (!err)
4351
- return resolve10({ code: 0, output });
4392
+ return resolve11({ code: 0, output });
4352
4393
  const code = err.code;
4353
- resolve10({ code: typeof code === "number" ? code : 1, output: output || err.message });
4394
+ resolve11({ code: typeof code === "number" ? code : 1, output: output || err.message });
4354
4395
  });
4355
4396
  });
4356
4397
  }
@@ -6468,12 +6509,12 @@ function rememberPrompt(text2) {
6468
6509
  return `Remember this with kioku: ${text2.replace(/\s+/g, " ").trim()}`;
6469
6510
  }
6470
6511
  function createTerminalRunner(env, timeoutMs) {
6471
- return (bin, args, cwd) => new Promise((resolve10) => {
6512
+ return (bin, args, cwd) => new Promise((resolve11) => {
6472
6513
  let proc;
6473
6514
  try {
6474
6515
  proc = pty3.spawn(bin, args, { name: "xterm-256color", cols: 400, rows: 40, cwd, env });
6475
6516
  } catch {
6476
- return resolve10({ code: 127, stdout: "", stderr: "ENOENT" });
6517
+ return resolve11({ code: 127, stdout: "", stderr: "ENOENT" });
6477
6518
  }
6478
6519
  let output = "";
6479
6520
  const timer = setTimeout(() => proc.kill(), timeoutMs);
@@ -6483,7 +6524,7 @@ function createTerminalRunner(env, timeoutMs) {
6483
6524
  proc.onExit(({ exitCode }) => {
6484
6525
  clearTimeout(timer);
6485
6526
  const json = stripAnsi(output).split(/\r?\n/).reverse().map((line) => line.slice(line.indexOf("{")).trim()).find((line) => parseJson(line) !== null);
6486
- resolve10({ code: exitCode, stdout: json ?? "", stderr: output });
6527
+ resolve11({ code: exitCode, stdout: json ?? "", stderr: output });
6487
6528
  });
6488
6529
  });
6489
6530
  }
@@ -6831,7 +6872,7 @@ var init_kioku = __esm({
6831
6872
  return (await this.viewer).address;
6832
6873
  }
6833
6874
  startViewer() {
6834
- const started = new Promise((resolve10, reject) => {
6875
+ const started = new Promise((resolve11, reject) => {
6835
6876
  const child = spawn7(this.bin, ["web", "--json", "--no-open"], { cwd: homedir5(), stdio: ["ignore", "pipe", "pipe"] });
6836
6877
  const lines2 = createInterface({ input: child.stdout });
6837
6878
  let stderr = "";
@@ -6858,7 +6899,7 @@ var init_kioku = __esm({
6858
6899
  if (settled || event?.event !== "listening" || !event.address?.startsWith("http://127.0.0.1:"))
6859
6900
  return;
6860
6901
  finish();
6861
- resolve10({ child, address: event.address });
6902
+ resolve11({ child, address: event.address });
6862
6903
  });
6863
6904
  child.on("error", (err) => {
6864
6905
  const missing = err.code === "ENOENT";
@@ -7009,7 +7050,7 @@ var init_dist = __esm({
7009
7050
 
7010
7051
  // ../core/dist/module-permissions.js
7011
7052
  import { realpathSync } from "node:fs";
7012
- import { basename as basename3, dirname as dirname6, join as join14, resolve as resolve4, sep as sep2 } from "node:path";
7053
+ import { basename as basename3, dirname as dirname6, join as join14, resolve as resolve5, sep as sep3 } from "node:path";
7013
7054
  function expandGrants(permissions, settings) {
7014
7055
  const p = permissions ?? {};
7015
7056
  return {
@@ -7075,11 +7116,11 @@ function allowsCommand(grants, command) {
7075
7116
  return grants.shell.includes(expandHome(command));
7076
7117
  }
7077
7118
  async function allowsPath(grants, target) {
7078
- const real = realOrParent(resolve4(expandHome(target)));
7119
+ const real = realOrParent(resolve5(expandHome(target)));
7079
7120
  for (const grant of grants) {
7080
7121
  const folder = grant.endsWith("/");
7081
- const base = realOrParent(resolve4(expandHome(grant)));
7082
- if (folder ? real === base || real.startsWith(base + sep2) : real === base)
7122
+ const base = realOrParent(resolve5(expandHome(grant)));
7123
+ if (folder ? real === base || real.startsWith(base + sep3) : real === base)
7083
7124
  return true;
7084
7125
  }
7085
7126
  return false;
@@ -7103,7 +7144,7 @@ var init_module_permissions = __esm({
7103
7144
 
7104
7145
  // ../core/dist/module-manifest.js
7105
7146
  import { readFileSync as readFileSync10 } from "node:fs";
7106
- import { join as join15, resolve as resolve5, sep as sep3 } from "node:path";
7147
+ import { join as join15, resolve as resolve6, sep as sep4 } from "node:path";
7107
7148
  function checkSdk(range, version = SDK_VERSION) {
7108
7149
  if (!import_semver2.default.validRange(range))
7109
7150
  return `sdk range "${range}" is not valid semver`;
@@ -7205,9 +7246,9 @@ function checkSettingDef(def, path, allowList, err) {
7205
7246
  }
7206
7247
  }
7207
7248
  function insideFolder(dir, relative) {
7208
- const root = realOrParent(resolve5(dir));
7209
- const target = realOrParent(resolve5(dir, relative));
7210
- return target === root || target.startsWith(root + sep3);
7249
+ const root = realOrParent(resolve6(dir));
7250
+ const target = realOrParent(resolve6(dir, relative));
7251
+ return target === root || target.startsWith(root + sep4);
7211
7252
  }
7212
7253
  function manifestFileFor(dir) {
7213
7254
  try {
@@ -7443,7 +7484,7 @@ var init_module_context = __esm({
7443
7484
 
7444
7485
  // ../core/dist/module-host.js
7445
7486
  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 resolve6, sep as sep4 } from "node:path";
7487
+ import { basename as basename4, dirname as dirname7, join as join16, resolve as resolve7, sep as sep5 } from "node:path";
7447
7488
  import { pathToFileURL } from "node:url";
7448
7489
  function disabled(id, c, reason, m) {
7449
7490
  const text2 = (v, fallback) => typeof v === "string" && v ? v : fallback;
@@ -7556,7 +7597,7 @@ var init_module_host = __esm({
7556
7597
  // only what was installed into the modules folder; bundled, dev and Forge's own packages stay
7557
7598
  removable(c) {
7558
7599
  const { modulesDir } = this.opts;
7559
- return c.source === "installed" && dirname7(c.dir) === modulesDir || c.dir.startsWith(join16(modulesDir, "node_modules") + sep4);
7600
+ return c.source === "installed" && dirname7(c.dir) === modulesDir || c.dir.startsWith(join16(modulesDir, "node_modules") + sep5);
7560
7601
  }
7561
7602
  // scans, reloads and dev changes run one at a time: each one awaits imports midway
7562
7603
  queue = Promise.resolve();
@@ -7607,7 +7648,7 @@ var init_module_host = __esm({
7607
7648
  }
7608
7649
  async addDevNow(path) {
7609
7650
  const dirs = this.devDirs();
7610
- const dir = resolve6(path);
7651
+ const dir = resolve7(path);
7611
7652
  if (!dirs.includes(dir))
7612
7653
  writeFileSync5(this.opts.devFile, JSON.stringify([...dirs, dir], null, 2));
7613
7654
  await this.scanNow();
@@ -7615,7 +7656,7 @@ var init_module_host = __esm({
7615
7656
  }
7616
7657
  removeDev(path) {
7617
7658
  return this.serial(async () => {
7618
- const dir = resolve6(path);
7659
+ const dir = resolve7(path);
7619
7660
  writeFileSync5(this.opts.devFile, JSON.stringify(this.devDirs().filter((d) => d !== dir), null, 2));
7620
7661
  await this.scanNow();
7621
7662
  });
@@ -7714,7 +7755,7 @@ var init_module_host = __esm({
7714
7755
  return disabled(m.id, c, "modules run only in local mode", m);
7715
7756
  let server;
7716
7757
  if (m.server) {
7717
- const file = resolve6(c.dir, m.server);
7758
+ const file = resolve7(c.dir, m.server);
7718
7759
  const owner = file.endsWith(".js") ? nearestPackage(dirname7(file)) : null;
7719
7760
  if (owner?.type === "commonjs")
7720
7761
  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 +7783,7 @@ var init_module_host = __esm({
7742
7783
  actions: server?.actions?.map((a) => ({ id: a.id, label: a.label, effect: a.effect }))
7743
7784
  };
7744
7785
  if (m.view) {
7745
- const entry = resolve6(c.dir, m.view.entry);
7786
+ const entry = resolve7(c.dir, m.view.entry);
7746
7787
  const mtime = existsSync13(entry) ? Math.floor(statSync4(entry).mtimeMs) : 0;
7747
7788
  status.view = { url: `/api/modules/${m.id}/view.js`, title: m.view.title ?? m.displayName, version: `${m.version}-${mtime}` };
7748
7789
  }
@@ -7830,7 +7871,7 @@ var init_module_confirmations = __esm({
7830
7871
  import { randomBytes as randomBytes2 } from "node:crypto";
7831
7872
  import { existsSync as existsSync14, mkdirSync as mkdirSync5, mkdtempSync, readFileSync as readFileSync12, rmSync as rmSync3 } from "node:fs";
7832
7873
  import { homedir as homedir7, tmpdir } from "node:os";
7833
- import { isAbsolute as isAbsolute2, join as join17, resolve as resolve7, sep as sep5 } from "node:path";
7874
+ import { isAbsolute as isAbsolute2, join as join17, resolve as resolve8, sep as sep6 } from "node:path";
7834
7875
  async function previewManifest(spec, opts) {
7835
7876
  if (isPathSpec(spec, opts.cwd))
7836
7877
  return readFolder(expand(spec, opts.cwd));
@@ -7905,8 +7946,8 @@ var init_module_install = __esm({
7905
7946
  init_output();
7906
7947
  init_state_log();
7907
7948
  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(resolve7(cwd, spec)) && !spec.startsWith("@");
7909
- expand = (spec, cwd) => resolve7(cwd, expandHome(spec));
7949
+ isPathSpec = (spec, cwd) => spec.startsWith(".") || spec.startsWith("~") || isAbsolute2(spec) || existsSync14(resolve8(cwd, spec)) && !spec.startsWith("@");
7950
+ expand = (spec, cwd) => resolve8(cwd, expandHome(spec));
7910
7951
  InstallError = class extends Error {
7911
7952
  code;
7912
7953
  constructor(code, message2) {
@@ -7977,7 +8018,7 @@ var init_module_install = __esm({
7977
8018
  throw new InstallError("not_found", `No module ${id}`);
7978
8019
  if (!found.removable)
7979
8020
  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") + sep5;
8021
+ const packages2 = join17(this.opts.modulesDir, "node_modules") + sep6;
7981
8022
  if (found.dir.startsWith(packages2)) {
7982
8023
  const name = packageName(found.dir) ?? found.dir.slice(packages2.length);
7983
8024
  const res = await this.opts.run("npm", ["uninstall", "--prefix", this.opts.modulesDir, name], this.opts.modulesDir);
@@ -8005,7 +8046,7 @@ var init_module_install = __esm({
8005
8046
 
8006
8047
  // ../core/dist/module-routes.js
8007
8048
  import { readFile as readFile2 } from "node:fs/promises";
8008
- import { resolve as resolve8 } from "node:path";
8049
+ import { resolve as resolve9 } from "node:path";
8009
8050
  import { Hono as Hono5 } from "hono";
8010
8051
  function moduleRoutes(host, opts) {
8011
8052
  const { db } = opts;
@@ -8098,7 +8139,7 @@ function moduleRoutes(host, opts) {
8098
8139
  if (!mod?.manifest.view)
8099
8140
  return c.json(removed(c.req.param("id")), 404);
8100
8141
  try {
8101
- const code = await readFile2(resolve8(mod.dir, mod.manifest.view.entry), "utf-8");
8142
+ const code = await readFile2(resolve9(mod.dir, mod.manifest.view.entry), "utf-8");
8102
8143
  return c.body(code, 200, { "Content-Type": "text/javascript; charset=utf-8", "Cache-Control": "no-cache" });
8103
8144
  } catch (err) {
8104
8145
  return c.json({ code: "not_found", message: `view bundle missing: ${err.message}` }, 404);
@@ -8446,7 +8487,7 @@ var init_module_events = __esm({
8446
8487
  // ../core/dist/server.js
8447
8488
  import { Hono as Hono6 } from "hono";
8448
8489
  import { cors } from "hono/cors";
8449
- import { join as join18, basename as basename5, resolve as resolve9 } from "node:path";
8490
+ import { join as join18, basename as basename5, resolve as resolve10 } from "node:path";
8450
8491
  import { readdirSync as readdirSync8, existsSync as existsSync15 } from "node:fs";
8451
8492
  function createForgeServer(options) {
8452
8493
  const { dataDir, db: externalDb, authToken, localOnly = true } = options;
@@ -8458,6 +8499,11 @@ function createForgeServer(options) {
8458
8499
  loader.discover();
8459
8500
  const app = new Hono6();
8460
8501
  app.use("*", localOnly ? localOriginGuard() : cors());
8502
+ app.use("*", async (c, next) => {
8503
+ await next();
8504
+ c.header("X-Frame-Options", "DENY");
8505
+ c.header("Content-Security-Policy", "frame-ancestors 'none'");
8506
+ });
8461
8507
  if (authToken) {
8462
8508
  app.use("/api/*", bearerAuth(authToken));
8463
8509
  }
@@ -8693,7 +8739,7 @@ data: ${JSON.stringify(data)}
8693
8739
  });
8694
8740
  app.get("/api/filesystem/browse", (c) => {
8695
8741
  const home = process.env.HOME ?? "/tmp";
8696
- const dir = resolve9(c.req.query("path") ?? process.cwd());
8742
+ const dir = resolve10(c.req.query("path") ?? process.cwd());
8697
8743
  if (!dir.startsWith(home)) {
8698
8744
  return c.json({ error: "Access denied: path must be within home directory" }, 403);
8699
8745
  }
@@ -8962,14 +9008,14 @@ var init_init = __esm({
8962
9008
  function waitForListening(server) {
8963
9009
  if (server.listening)
8964
9010
  return Promise.resolve();
8965
- return new Promise((resolve10, reject) => {
9011
+ return new Promise((resolve11, reject) => {
8966
9012
  const onError = (err) => {
8967
9013
  server.off("listening", onListening);
8968
9014
  reject(err);
8969
9015
  };
8970
9016
  const onListening = () => {
8971
9017
  server.off("error", onError);
8972
- resolve10();
9018
+ resolve11();
8973
9019
  };
8974
9020
  server.once("error", onError);
8975
9021
  server.once("listening", onListening);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forge-cw",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "A visual dashboard for your coding agents on Claude Code, Codex, Pi or OpenCode. Installs CW for you.",
5
5
  "license": "MIT",
6
6
  "type": "module",