forge-cw 0.1.18 → 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.
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" },
@@ -3141,6 +3169,19 @@ function skillRoutes(reader, options = {}) {
3141
3169
  const version = (await find())?.installs.find((i) => i.scope === install.scope && i.scopeRef === ref)?.version ?? install.version;
3142
3170
  return c.json({ ok: true, version });
3143
3171
  });
3172
+ app.post("/plugins/:id/uninstall", async (c) => {
3173
+ const id = c.req.param("id");
3174
+ const { scope, scopeRef } = await c.req.json().catch(() => ({}));
3175
+ const ref = scope === "global" ? "global" : scopeRef ?? "";
3176
+ const plugin = (await listPlugins(reader, remoteOf)).find((p) => p.id === id);
3177
+ const install = plugin?.installs.find((i) => i.scope === scope && i.scopeRef === ref);
3178
+ if (!plugin || !install)
3179
+ return c.json({ error: `${id} is not installed in ${ref || "that scope"}` }, 404);
3180
+ const failed = await runClaude(install.scope, ref, [["plugin", "uninstall", plugin.id, "--scope", "user"]], `Failed to uninstall ${plugin.name}`);
3181
+ if (failed)
3182
+ return c.json({ error: failed.error }, failed.status);
3183
+ return c.json({ ok: true });
3184
+ });
3144
3185
  app.get("/marketplaces", (c) => c.json(listMarketplaces(reader)));
3145
3186
  app.post("/marketplaces", async (c) => {
3146
3187
  const body2 = await c.req.json().catch(() => ({}));
@@ -3593,7 +3634,7 @@ var init_terminal_screen = __esm({
3593
3634
  }
3594
3635
  // rows oldest first, scrollback included, without the blank rows under the last one written
3595
3636
  read() {
3596
- return new Promise((resolve10) => this.term.write("", () => {
3637
+ return new Promise((resolve11) => this.term.write("", () => {
3597
3638
  const buffer = this.term.buffer.active;
3598
3639
  const rows = [];
3599
3640
  for (let y = 0; y < buffer.length; y++) {
@@ -3609,7 +3650,7 @@ var init_terminal_screen = __esm({
3609
3650
  const trimmed = rows.map((r) => r.trimEnd());
3610
3651
  while (trimmed.length && !trimmed[trimmed.length - 1])
3611
3652
  trimmed.pop();
3612
- resolve10(trimmed.join("\n"));
3653
+ resolve11(trimmed.join("\n"));
3613
3654
  }));
3614
3655
  }
3615
3656
  dispose() {
@@ -3809,7 +3850,7 @@ var init_session_state = __esm({
3809
3850
  import { mkdirSync as mkdirSync3 } from "node:fs";
3810
3851
  import { appendFile } from "node:fs/promises";
3811
3852
  import { homedir as homedir3 } from "node:os";
3812
- import { dirname as dirname4, resolve as resolve3 } from "node:path";
3853
+ import { dirname as dirname4, resolve as resolve4 } from "node:path";
3813
3854
  function expandHome(path) {
3814
3855
  return path === "~" || path.startsWith("~/") ? homedir3() + path.slice(1) : path;
3815
3856
  }
@@ -3828,7 +3869,7 @@ function stateLogLine(call) {
3828
3869
  }
3829
3870
  function createStateLog(path, onError = () => {
3830
3871
  }) {
3831
- const file = resolve3(expandHome(path));
3872
+ const file = resolve4(expandHome(path));
3832
3873
  mkdirSync3(dirname4(file), { recursive: true });
3833
3874
  let queue = Promise.resolve();
3834
3875
  return (call) => {
@@ -3891,6 +3932,10 @@ function createTerminalWss(manager, reader, { localOnly = true, general } = {})
3891
3932
  });
3892
3933
  }
3893
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
+ });
3894
3939
  console.log(`[pty-ws] Connected: ${project}/${sessionDir}`);
3895
3940
  const sessionId = `${project}::${sessionDir}`;
3896
3941
  if (manager.has(sessionId)) {
@@ -3904,7 +3949,12 @@ function createTerminalWss(manager, reader, { localOnly = true, general } = {})
3904
3949
  ws.close(REFUSED_CLOSE_CODE);
3905
3950
  return;
3906
3951
  }
3907
- 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
+ }
3908
3958
  if (!ptySession) {
3909
3959
  console.error(`[pty-ws] Failed to spawn terminal for: ${project}/${sessionDir}`);
3910
3960
  ws.send(JSON.stringify({ type: "error", message: `Failed to start terminal for ${project}/${sessionDir}` }));
@@ -3915,19 +3965,23 @@ function createTerminalWss(manager, reader, { localOnly = true, general } = {})
3915
3965
  });
3916
3966
  function attachToServer(server) {
3917
3967
  server.on("upgrade", (request, socket, head) => {
3918
- if (localOnly && !isLocalRequest(request.headers.host, request.headers.origin)) {
3919
- socket.destroy();
3920
- return;
3921
- }
3922
- const url = new URL(request.url ?? "/", "http://localhost");
3923
- const parsed = parseTerminalUpgradeUrl(url.pathname);
3924
- if (parsed) {
3925
- const { project, sessionDir } = parsed;
3926
- console.log(`[pty-ws] Upgrade request: ${project}/${sessionDir}`);
3927
- wss.handleUpgrade(request, socket, head, (ws) => {
3928
- wss.emit("connection", ws, project, sessionDir);
3929
- });
3930
- } 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 {
3931
3985
  socket.destroy();
3932
3986
  }
3933
3987
  });
@@ -4331,13 +4385,13 @@ var init_cw_install = __esm({
4331
4385
  INSTALL_TIMEOUT_MS2 = 12e4;
4332
4386
  ANSI_RE3 = /\u001b\[[0-9;?]*[A-Za-z]/g;
4333
4387
  sha256Of = (file) => createHash2("sha256").update(readFileSync9(file)).digest("hex");
4334
- runInstall = (script, args, env) => new Promise((resolve10) => {
4388
+ runInstall = (script, args, env) => new Promise((resolve11) => {
4335
4389
  execFile5("bash", [script, ...args], { env, timeout: INSTALL_TIMEOUT_MS2, maxBuffer: 1024 * 1024 }, (err, stdout, stderr) => {
4336
4390
  const output = `${String(stdout)}${String(stderr)}`;
4337
4391
  if (!err)
4338
- return resolve10({ code: 0, output });
4392
+ return resolve11({ code: 0, output });
4339
4393
  const code = err.code;
4340
- resolve10({ code: typeof code === "number" ? code : 1, output: output || err.message });
4394
+ resolve11({ code: typeof code === "number" ? code : 1, output: output || err.message });
4341
4395
  });
4342
4396
  });
4343
4397
  }
@@ -6455,12 +6509,12 @@ function rememberPrompt(text2) {
6455
6509
  return `Remember this with kioku: ${text2.replace(/\s+/g, " ").trim()}`;
6456
6510
  }
6457
6511
  function createTerminalRunner(env, timeoutMs) {
6458
- return (bin, args, cwd) => new Promise((resolve10) => {
6512
+ return (bin, args, cwd) => new Promise((resolve11) => {
6459
6513
  let proc;
6460
6514
  try {
6461
6515
  proc = pty3.spawn(bin, args, { name: "xterm-256color", cols: 400, rows: 40, cwd, env });
6462
6516
  } catch {
6463
- return resolve10({ code: 127, stdout: "", stderr: "ENOENT" });
6517
+ return resolve11({ code: 127, stdout: "", stderr: "ENOENT" });
6464
6518
  }
6465
6519
  let output = "";
6466
6520
  const timer = setTimeout(() => proc.kill(), timeoutMs);
@@ -6470,7 +6524,7 @@ function createTerminalRunner(env, timeoutMs) {
6470
6524
  proc.onExit(({ exitCode }) => {
6471
6525
  clearTimeout(timer);
6472
6526
  const json = stripAnsi(output).split(/\r?\n/).reverse().map((line) => line.slice(line.indexOf("{")).trim()).find((line) => parseJson(line) !== null);
6473
- resolve10({ code: exitCode, stdout: json ?? "", stderr: output });
6527
+ resolve11({ code: exitCode, stdout: json ?? "", stderr: output });
6474
6528
  });
6475
6529
  });
6476
6530
  }
@@ -6818,7 +6872,7 @@ var init_kioku = __esm({
6818
6872
  return (await this.viewer).address;
6819
6873
  }
6820
6874
  startViewer() {
6821
- const started = new Promise((resolve10, reject) => {
6875
+ const started = new Promise((resolve11, reject) => {
6822
6876
  const child = spawn7(this.bin, ["web", "--json", "--no-open"], { cwd: homedir5(), stdio: ["ignore", "pipe", "pipe"] });
6823
6877
  const lines2 = createInterface({ input: child.stdout });
6824
6878
  let stderr = "";
@@ -6845,7 +6899,7 @@ var init_kioku = __esm({
6845
6899
  if (settled || event?.event !== "listening" || !event.address?.startsWith("http://127.0.0.1:"))
6846
6900
  return;
6847
6901
  finish();
6848
- resolve10({ child, address: event.address });
6902
+ resolve11({ child, address: event.address });
6849
6903
  });
6850
6904
  child.on("error", (err) => {
6851
6905
  const missing = err.code === "ENOENT";
@@ -6996,7 +7050,7 @@ var init_dist = __esm({
6996
7050
 
6997
7051
  // ../core/dist/module-permissions.js
6998
7052
  import { realpathSync } from "node:fs";
6999
- 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";
7000
7054
  function expandGrants(permissions, settings) {
7001
7055
  const p = permissions ?? {};
7002
7056
  return {
@@ -7062,11 +7116,11 @@ function allowsCommand(grants, command) {
7062
7116
  return grants.shell.includes(expandHome(command));
7063
7117
  }
7064
7118
  async function allowsPath(grants, target) {
7065
- const real = realOrParent(resolve4(expandHome(target)));
7119
+ const real = realOrParent(resolve5(expandHome(target)));
7066
7120
  for (const grant of grants) {
7067
7121
  const folder = grant.endsWith("/");
7068
- const base = realOrParent(resolve4(expandHome(grant)));
7069
- 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)
7070
7124
  return true;
7071
7125
  }
7072
7126
  return false;
@@ -7090,7 +7144,7 @@ var init_module_permissions = __esm({
7090
7144
 
7091
7145
  // ../core/dist/module-manifest.js
7092
7146
  import { readFileSync as readFileSync10 } from "node:fs";
7093
- 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";
7094
7148
  function checkSdk(range, version = SDK_VERSION) {
7095
7149
  if (!import_semver2.default.validRange(range))
7096
7150
  return `sdk range "${range}" is not valid semver`;
@@ -7192,9 +7246,9 @@ function checkSettingDef(def, path, allowList, err) {
7192
7246
  }
7193
7247
  }
7194
7248
  function insideFolder(dir, relative) {
7195
- const root = realOrParent(resolve5(dir));
7196
- const target = realOrParent(resolve5(dir, relative));
7197
- 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);
7198
7252
  }
7199
7253
  function manifestFileFor(dir) {
7200
7254
  try {
@@ -7430,7 +7484,7 @@ var init_module_context = __esm({
7430
7484
 
7431
7485
  // ../core/dist/module-host.js
7432
7486
  import { existsSync as existsSync13, readdirSync as readdirSync7, readFileSync as readFileSync11, statSync as statSync4, writeFileSync as writeFileSync5 } from "node:fs";
7433
- 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";
7434
7488
  import { pathToFileURL } from "node:url";
7435
7489
  function disabled(id, c, reason, m) {
7436
7490
  const text2 = (v, fallback) => typeof v === "string" && v ? v : fallback;
@@ -7543,7 +7597,7 @@ var init_module_host = __esm({
7543
7597
  // only what was installed into the modules folder; bundled, dev and Forge's own packages stay
7544
7598
  removable(c) {
7545
7599
  const { modulesDir } = this.opts;
7546
- 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);
7547
7601
  }
7548
7602
  // scans, reloads and dev changes run one at a time: each one awaits imports midway
7549
7603
  queue = Promise.resolve();
@@ -7594,7 +7648,7 @@ var init_module_host = __esm({
7594
7648
  }
7595
7649
  async addDevNow(path) {
7596
7650
  const dirs = this.devDirs();
7597
- const dir = resolve6(path);
7651
+ const dir = resolve7(path);
7598
7652
  if (!dirs.includes(dir))
7599
7653
  writeFileSync5(this.opts.devFile, JSON.stringify([...dirs, dir], null, 2));
7600
7654
  await this.scanNow();
@@ -7602,7 +7656,7 @@ var init_module_host = __esm({
7602
7656
  }
7603
7657
  removeDev(path) {
7604
7658
  return this.serial(async () => {
7605
- const dir = resolve6(path);
7659
+ const dir = resolve7(path);
7606
7660
  writeFileSync5(this.opts.devFile, JSON.stringify(this.devDirs().filter((d) => d !== dir), null, 2));
7607
7661
  await this.scanNow();
7608
7662
  });
@@ -7701,7 +7755,7 @@ var init_module_host = __esm({
7701
7755
  return disabled(m.id, c, "modules run only in local mode", m);
7702
7756
  let server;
7703
7757
  if (m.server) {
7704
- const file = resolve6(c.dir, m.server);
7758
+ const file = resolve7(c.dir, m.server);
7705
7759
  const owner = file.endsWith(".js") ? nearestPackage(dirname7(file)) : null;
7706
7760
  if (owner?.type === "commonjs")
7707
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);
@@ -7729,7 +7783,7 @@ var init_module_host = __esm({
7729
7783
  actions: server?.actions?.map((a) => ({ id: a.id, label: a.label, effect: a.effect }))
7730
7784
  };
7731
7785
  if (m.view) {
7732
- const entry = resolve6(c.dir, m.view.entry);
7786
+ const entry = resolve7(c.dir, m.view.entry);
7733
7787
  const mtime = existsSync13(entry) ? Math.floor(statSync4(entry).mtimeMs) : 0;
7734
7788
  status.view = { url: `/api/modules/${m.id}/view.js`, title: m.view.title ?? m.displayName, version: `${m.version}-${mtime}` };
7735
7789
  }
@@ -7817,7 +7871,7 @@ var init_module_confirmations = __esm({
7817
7871
  import { randomBytes as randomBytes2 } from "node:crypto";
7818
7872
  import { existsSync as existsSync14, mkdirSync as mkdirSync5, mkdtempSync, readFileSync as readFileSync12, rmSync as rmSync3 } from "node:fs";
7819
7873
  import { homedir as homedir7, tmpdir } from "node:os";
7820
- 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";
7821
7875
  async function previewManifest(spec, opts) {
7822
7876
  if (isPathSpec(spec, opts.cwd))
7823
7877
  return readFolder(expand(spec, opts.cwd));
@@ -7892,8 +7946,8 @@ var init_module_install = __esm({
7892
7946
  init_output();
7893
7947
  init_state_log();
7894
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.";
7895
- isPathSpec = (spec, cwd) => spec.startsWith(".") || spec.startsWith("~") || isAbsolute2(spec) || existsSync14(resolve7(cwd, spec)) && !spec.startsWith("@");
7896
- 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));
7897
7951
  InstallError = class extends Error {
7898
7952
  code;
7899
7953
  constructor(code, message2) {
@@ -7964,7 +8018,7 @@ var init_module_install = __esm({
7964
8018
  throw new InstallError("not_found", `No module ${id}`);
7965
8019
  if (!found.removable)
7966
8020
  throw new InstallError("bad_request", `${id} was not installed into Forge's modules folder; a dev folder unloads when forge module dev stops`);
7967
- const packages2 = join17(this.opts.modulesDir, "node_modules") + sep5;
8021
+ const packages2 = join17(this.opts.modulesDir, "node_modules") + sep6;
7968
8022
  if (found.dir.startsWith(packages2)) {
7969
8023
  const name = packageName(found.dir) ?? found.dir.slice(packages2.length);
7970
8024
  const res = await this.opts.run("npm", ["uninstall", "--prefix", this.opts.modulesDir, name], this.opts.modulesDir);
@@ -7992,7 +8046,7 @@ var init_module_install = __esm({
7992
8046
 
7993
8047
  // ../core/dist/module-routes.js
7994
8048
  import { readFile as readFile2 } from "node:fs/promises";
7995
- import { resolve as resolve8 } from "node:path";
8049
+ import { resolve as resolve9 } from "node:path";
7996
8050
  import { Hono as Hono5 } from "hono";
7997
8051
  function moduleRoutes(host, opts) {
7998
8052
  const { db } = opts;
@@ -8085,7 +8139,7 @@ function moduleRoutes(host, opts) {
8085
8139
  if (!mod?.manifest.view)
8086
8140
  return c.json(removed(c.req.param("id")), 404);
8087
8141
  try {
8088
- 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");
8089
8143
  return c.body(code, 200, { "Content-Type": "text/javascript; charset=utf-8", "Cache-Control": "no-cache" });
8090
8144
  } catch (err) {
8091
8145
  return c.json({ code: "not_found", message: `view bundle missing: ${err.message}` }, 404);
@@ -8433,7 +8487,7 @@ var init_module_events = __esm({
8433
8487
  // ../core/dist/server.js
8434
8488
  import { Hono as Hono6 } from "hono";
8435
8489
  import { cors } from "hono/cors";
8436
- 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";
8437
8491
  import { readdirSync as readdirSync8, existsSync as existsSync15 } from "node:fs";
8438
8492
  function createForgeServer(options) {
8439
8493
  const { dataDir, db: externalDb, authToken, localOnly = true } = options;
@@ -8445,6 +8499,11 @@ function createForgeServer(options) {
8445
8499
  loader.discover();
8446
8500
  const app = new Hono6();
8447
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
+ });
8448
8507
  if (authToken) {
8449
8508
  app.use("/api/*", bearerAuth(authToken));
8450
8509
  }
@@ -8680,7 +8739,7 @@ data: ${JSON.stringify(data)}
8680
8739
  });
8681
8740
  app.get("/api/filesystem/browse", (c) => {
8682
8741
  const home = process.env.HOME ?? "/tmp";
8683
- const dir = resolve9(c.req.query("path") ?? process.cwd());
8742
+ const dir = resolve10(c.req.query("path") ?? process.cwd());
8684
8743
  if (!dir.startsWith(home)) {
8685
8744
  return c.json({ error: "Access denied: path must be within home directory" }, 403);
8686
8745
  }
@@ -8949,14 +9008,14 @@ var init_init = __esm({
8949
9008
  function waitForListening(server) {
8950
9009
  if (server.listening)
8951
9010
  return Promise.resolve();
8952
- return new Promise((resolve10, reject) => {
9011
+ return new Promise((resolve11, reject) => {
8953
9012
  const onError = (err) => {
8954
9013
  server.off("listening", onListening);
8955
9014
  reject(err);
8956
9015
  };
8957
9016
  const onListening = () => {
8958
9017
  server.off("error", onError);
8959
- resolve10();
9018
+ resolve11();
8960
9019
  };
8961
9020
  server.once("error", onError);
8962
9021
  server.once("listening", onListening);