forge-cw 0.1.30 → 0.1.32

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 +425 -146
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -502,7 +502,7 @@ function isAuthorized(token, authorization, cookieHeader) {
502
502
  }
503
503
  function bearerAuth(token) {
504
504
  return async (c, next) => {
505
- if (c.req.path === "/api/health") {
505
+ if (c.req.path === "/api/health" || c.req.path === "/api/cw/hook-events") {
506
506
  return next();
507
507
  }
508
508
  if (!isAuthorized(token, c.req.header("Authorization"), c.req.header("Cookie"))) {
@@ -1007,6 +1007,12 @@ function envWithoutHost(env = process.env) {
1007
1007
  }
1008
1008
  return out;
1009
1009
  }
1010
+ function envForAgent(env = process.env) {
1011
+ const out = envWithoutHarness(env);
1012
+ for (const name of FORGE_SECRETS)
1013
+ delete out[name];
1014
+ return out;
1015
+ }
1010
1016
  function envWithoutHarness(env = process.env) {
1011
1017
  const out = {};
1012
1018
  for (const [key, value] of Object.entries(env)) {
@@ -1056,12 +1062,13 @@ function readContextTokens(cwHome, env = process.env) {
1056
1062
  const has = (name) => Boolean(env[name]?.trim()) || new RegExp(`^\\s*(export\\s+)?${name}\\s*=\\s*\\S`, "m").test(text2);
1057
1063
  return { linear: has("LINEAR_API_KEY"), notion: has("NOTION_TOKEN") };
1058
1064
  }
1059
- var CACHE_MS, TIMEOUT_MS;
1065
+ var CACHE_MS, TIMEOUT_MS, FORGE_SECRETS;
1060
1066
  var init_cw_doctor = __esm({
1061
1067
  "../core/dist/cw-doctor.js"() {
1062
1068
  "use strict";
1063
1069
  CACHE_MS = 2e3;
1064
1070
  TIMEOUT_MS = 15e3;
1071
+ FORGE_SECRETS = ["FORGE_AUTH_TOKEN", "FORGE_DB_URL", "TYPESAFE_API_KEY"];
1065
1072
  }
1066
1073
  });
1067
1074
 
@@ -3338,17 +3345,144 @@ var init_skill_routes = __esm({
3338
3345
  }
3339
3346
  });
3340
3347
 
3348
+ // ../core/dist/claude-hooks.js
3349
+ import { createHash as createHash3, randomBytes, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
3350
+ import { existsSync as existsSync9, mkdirSync as mkdirSync3, readFileSync as readFileSync7, writeFileSync as writeFileSync4 } from "node:fs";
3351
+ import { join as join11 } from "node:path";
3352
+ function hookUrl(port, address) {
3353
+ const bare = address?.replace(/^\[|\]$/g, "");
3354
+ let name;
3355
+ if (!bare || WILDCARD_HOSTS.has(bare))
3356
+ name = "127.0.0.1";
3357
+ else if (bare === "::1")
3358
+ name = "[::1]";
3359
+ else if (isLoopbackHost(bare))
3360
+ name = bare === "localhost" ? "127.0.0.1" : bare;
3361
+ else
3362
+ name = bare.includes(":") ? `[${bare}]` : bare;
3363
+ return `http://${name}:${port}${HOOK_PATH}`;
3364
+ }
3365
+ function hookSettings(url) {
3366
+ const httpHook = {
3367
+ type: "http",
3368
+ url,
3369
+ timeout: TIMEOUT_S,
3370
+ headers: { [TOKEN_HEADER]: `$${TOKEN_ENV}`, [SESSION_HEADER]: `$${SESSION_ENV}` },
3371
+ allowedEnvVars: [TOKEN_ENV, SESSION_ENV]
3372
+ };
3373
+ const curl = `test -z "$${TOKEN_ENV}" || curl -s -m ${TIMEOUT_S} -o /dev/null -X POST -H 'Content-Type: application/json' -H "${TOKEN_HEADER}: $${TOKEN_ENV}" -H "${SESSION_HEADER}: $${SESSION_ENV}" --data-binary @- '${url}' >/dev/null 2>&1; exit 0`;
3374
+ const hooks = {
3375
+ SessionStart: [{ hooks: [{ type: "command", command: curl, timeout: TIMEOUT_S + 1 }] }]
3376
+ };
3377
+ for (const event of HOOK_EVENTS_HTTP)
3378
+ hooks[event] = [{ hooks: [httpHook] }];
3379
+ return { hooks };
3380
+ }
3381
+ function cwSkipPermissionsDefault(cwHome) {
3382
+ try {
3383
+ const text2 = readFileSync7(join11(cwHome, "config.yaml"), "utf-8");
3384
+ return /^skip_permissions:\s*true\b/m.test(text2);
3385
+ } catch {
3386
+ return false;
3387
+ }
3388
+ }
3389
+ function sameToken2(expected, provided) {
3390
+ const a = createHash3("sha256").update(expected).digest();
3391
+ const b = createHash3("sha256").update(provided).digest();
3392
+ return timingSafeEqual2(a, b);
3393
+ }
3394
+ var HOOK_PATH, TOKEN_HEADER, SESSION_HEADER, TOKEN_ENV, SESSION_ENV, HOOK_EVENTS_HTTP, TIMEOUT_S, WILDCARD_HOSTS, ClaudeHooks;
3395
+ var init_claude_hooks = __esm({
3396
+ "../core/dist/claude-hooks.js"() {
3397
+ "use strict";
3398
+ init_origin_guard();
3399
+ HOOK_PATH = "/api/cw/hook-events";
3400
+ TOKEN_HEADER = "X-Forge-Hook-Token";
3401
+ SESSION_HEADER = "X-Forge-Hook-Session";
3402
+ TOKEN_ENV = "FORGE_HOOK_TOKEN";
3403
+ SESSION_ENV = "FORGE_HOOK_SESSION";
3404
+ HOOK_EVENTS_HTTP = [
3405
+ "UserPromptSubmit",
3406
+ "PreToolUse",
3407
+ "PostToolUse",
3408
+ "PostToolUseFailure",
3409
+ "PermissionRequest",
3410
+ "PermissionDenied",
3411
+ "Notification",
3412
+ "Stop",
3413
+ "StopFailure",
3414
+ "SubagentStart",
3415
+ "SubagentStop",
3416
+ "PreCompact",
3417
+ "SessionEnd"
3418
+ ];
3419
+ TIMEOUT_S = 2;
3420
+ WILDCARD_HOSTS = /* @__PURE__ */ new Set(["0.0.0.0", "::", "[::]"]);
3421
+ ClaudeHooks = class {
3422
+ opts;
3423
+ tokens = /* @__PURE__ */ new Map();
3424
+ settingsPath = null;
3425
+ warned = false;
3426
+ constructor(opts) {
3427
+ this.opts = opts;
3428
+ }
3429
+ get enabled() {
3430
+ return this.settingsPath !== null;
3431
+ }
3432
+ // the URL carries the port, so the file is written once Forge listens, one per port
3433
+ listen(port, host) {
3434
+ const path = join11(this.opts.dir, `claude-${port}.json`);
3435
+ if (/\s/.test(path)) {
3436
+ this.opts.warn?.(`[hooks] ${path} has whitespace; Claude Code sessions keep the screen-read state`);
3437
+ return null;
3438
+ }
3439
+ try {
3440
+ if (!existsSync9(this.opts.dir))
3441
+ mkdirSync3(this.opts.dir, { recursive: true });
3442
+ writeFileSync4(path, JSON.stringify(hookSettings(hookUrl(port, host)), null, 2) + "\n", { mode: 420 });
3443
+ } catch (err) {
3444
+ this.opts.warn?.(`[hooks] could not write ${path}: ${err.message}`);
3445
+ return null;
3446
+ }
3447
+ this.settingsPath = path;
3448
+ return path;
3449
+ }
3450
+ // a relaunch of the same key replaces its token, so the previous process can no longer report
3451
+ launch(key) {
3452
+ if (!this.settingsPath) {
3453
+ if (!this.warned)
3454
+ this.opts.warn?.("[hooks] not listening yet; Claude Code sessions keep the screen-read state");
3455
+ this.warned = true;
3456
+ return null;
3457
+ }
3458
+ const token = randomBytes(24).toString("hex");
3459
+ this.tokens.set(key, token);
3460
+ return { settingsPath: this.settingsPath, token, skipPermissionsDefault: cwSkipPermissionsDefault(this.opts.cwHome) };
3461
+ }
3462
+ verify(key, token) {
3463
+ const expected = this.tokens.get(key);
3464
+ if (!expected || !token)
3465
+ return false;
3466
+ return sameToken2(expected, token);
3467
+ }
3468
+ revoke(key) {
3469
+ this.tokens.delete(key);
3470
+ }
3471
+ };
3472
+ }
3473
+ });
3474
+
3341
3475
  // ../core/dist/pty-manager.js
3342
3476
  import * as pty2 from "node-pty";
3343
- import { existsSync as existsSync9, chmodSync, statSync as statSync2 } from "node:fs";
3344
- import { join as join11, dirname as dirname3 } from "node:path";
3477
+ import { existsSync as existsSync10, chmodSync, statSync as statSync2 } from "node:fs";
3478
+ import { join as join12, dirname as dirname3 } from "node:path";
3345
3479
  import { createRequire as createRequire2 } from "node:module";
3346
3480
  function ensureSpawnHelperPermissions() {
3347
3481
  try {
3348
3482
  const require2 = createRequire2(import.meta.url);
3349
3483
  const ptyPath = dirname3(require2.resolve("node-pty/package.json"));
3350
- const helper = join11(ptyPath, "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper");
3351
- if (existsSync9(helper)) {
3484
+ const helper = join12(ptyPath, "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper");
3485
+ if (existsSync10(helper)) {
3352
3486
  const mode = statSync2(helper).mode;
3353
3487
  if (!(mode & 73)) {
3354
3488
  chmodSync(helper, mode | 493);
@@ -3361,8 +3495,29 @@ function slashLine(text2) {
3361
3495
  const line = typeof text2 === "string" ? text2.trim() : "";
3362
3496
  return line.length <= SLASH_MAX && /^\/[A-Za-z0-9][\w:.-]*( [^\x00-\x1f\x7f]*)?$/.test(line) ? line : null;
3363
3497
  }
3364
- function buildLaunch(session, isNew) {
3498
+ function withHook(env, session, hook) {
3499
+ for (const name of FORGE_SECRETS)
3500
+ delete env[name];
3501
+ delete env[TOKEN_ENV];
3502
+ delete env[SESSION_ENV];
3503
+ const inherited = (env.CW_CLAUDE_FLAGS ?? "").replace(INHERITED_HOOK_SETTINGS, " ").trim();
3504
+ if (inherited)
3505
+ env.CW_CLAUDE_FLAGS = inherited;
3506
+ else
3507
+ delete env.CW_CLAUDE_FLAGS;
3508
+ if (!hook || (session.harness ?? "claude") !== "claude" || session.type === "login")
3509
+ return false;
3510
+ env[TOKEN_ENV] = hook.token;
3511
+ env[SESSION_ENV] = encodeURIComponent(hook.key);
3512
+ if (session.type === "general")
3513
+ return true;
3514
+ const flags = inherited || (hook.skipPermissionsDefault && !session.skipPermissions ? "--dangerously-skip-permissions" : "");
3515
+ env.CW_CLAUDE_FLAGS = `${flags ? `${flags} ` : ""}--settings ${hook.settingsPath}`;
3516
+ return true;
3517
+ }
3518
+ function buildLaunch(session, isNew, hook) {
3365
3519
  const env = envWithoutHarness();
3520
+ const hooked = withHook(env, session, hook);
3366
3521
  const harness = session.harness ?? "claude";
3367
3522
  const harnessFlag = isNew && session.harness ? ` --harness ${shellQuote(harness)}` : "";
3368
3523
  const prefix = session.skipPermissions ? "cw --skip-permissions" : "cw";
@@ -3375,6 +3530,8 @@ function buildLaunch(session, isNew) {
3375
3530
  cmd2 += ` --model ${shellQuote(session.model)}`;
3376
3531
  if (session.skipPermissions)
3377
3532
  cmd2 += " --dangerously-skip-permissions";
3533
+ if (hooked && hook)
3534
+ cmd2 += ` --settings ${shellQuote(hook.settingsPath)}`;
3378
3535
  }
3379
3536
  if (isNew && session.harness)
3380
3537
  env.CW_HARNESS = harness;
@@ -3429,12 +3586,13 @@ function buildLaunch(session, isNew) {
3429
3586
  cmd += ` --model ${shellQuote(session.model)}`;
3430
3587
  return { command: cmd + harnessFlag, env };
3431
3588
  }
3432
- var SCROLLBACK_LIMIT, IDLE_TIMEOUT_MS, CLEANUP_INTERVAL_MS, shellQuote, SLASH_MAX, oneLine, PTYManager;
3589
+ var SCROLLBACK_LIMIT, IDLE_TIMEOUT_MS, CLEANUP_INTERVAL_MS, shellQuote, SLASH_MAX, oneLine, INHERITED_HOOK_SETTINGS, PTYManager;
3433
3590
  var init_pty_manager = __esm({
3434
3591
  "../core/dist/pty-manager.js"() {
3435
3592
  "use strict";
3436
3593
  init_cw_doctor();
3437
3594
  init_harness_capabilities();
3595
+ init_claude_hooks();
3438
3596
  SCROLLBACK_LIMIT = 5e3;
3439
3597
  IDLE_TIMEOUT_MS = 30 * 60 * 1e3;
3440
3598
  CLEANUP_INTERVAL_MS = 5 * 60 * 1e3;
@@ -3442,14 +3600,17 @@ var init_pty_manager = __esm({
3442
3600
  ensureSpawnHelperPermissions();
3443
3601
  SLASH_MAX = 300;
3444
3602
  oneLine = (text2) => text2.replace(/[\x00-\x1f\x7f]+/g, " ").replace(/\s+/g, " ").trim();
3603
+ INHERITED_HOOK_SETTINGS = /(^|\s)--settings\s+\S*\/claude-\d+\.json(?=\s|$)/g;
3445
3604
  PTYManager = class {
3446
3605
  states;
3606
+ hooks;
3447
3607
  sessions = /* @__PURE__ */ new Map();
3448
3608
  cleanupTimer = null;
3449
3609
  // told when a session's agent starts and when its process exits
3450
3610
  onLifecycle;
3451
- constructor(states = null) {
3611
+ constructor(states = null, hooks = null) {
3452
3612
  this.states = states;
3613
+ this.hooks = hooks;
3453
3614
  this.cleanupTimer = setInterval(() => this.cleanup(), CLEANUP_INTERVAL_MS);
3454
3615
  }
3455
3616
  makeKey(project, sessionDir) {
@@ -3461,8 +3622,10 @@ var init_pty_manager = __esm({
3461
3622
  if (existing)
3462
3623
  return existing;
3463
3624
  const shell2 = process.env.SHELL || "/bin/zsh";
3464
- const { command, env } = buildLaunch(session, options.isNew ?? false);
3465
- const cwd = session.worktree && existsSync9(session.worktree) ? session.worktree : session.type === "general" || session.type === "create" || session.type === "login" ? process.env.HOME ?? process.cwd() : process.cwd();
3625
+ const wantsHook = (session.harness ?? "claude") === "claude" && session.type !== "login";
3626
+ const hookLaunch = wantsHook ? this.hooks?.launch(key) ?? null : null;
3627
+ const { command, env } = buildLaunch(session, options.isNew ?? false, hookLaunch ? { ...hookLaunch, key } : void 0);
3628
+ const cwd = session.worktree && existsSync10(session.worktree) ? session.worktree : session.type === "general" || session.type === "create" || session.type === "login" ? process.env.HOME ?? process.cwd() : process.cwd();
3466
3629
  let ptyProcess;
3467
3630
  try {
3468
3631
  ptyProcess = pty2.spawn(shell2, ["-c", command], {
@@ -3474,6 +3637,7 @@ var init_pty_manager = __esm({
3474
3637
  });
3475
3638
  } catch (err) {
3476
3639
  console.error(`[pty] Failed to spawn for ${key}: ${err}`);
3640
+ this.hooks?.revoke(key);
3477
3641
  return null;
3478
3642
  }
3479
3643
  const ptySession = {
@@ -3506,6 +3670,7 @@ var init_pty_manager = __esm({
3506
3670
  });
3507
3671
  ptySession.onExitDisposable = ptyProcess.onExit(({ exitCode }) => {
3508
3672
  this.states?.exit(key, exitCode);
3673
+ this.hooks?.revoke(key);
3509
3674
  const message2 = JSON.stringify({ type: "exit", code: exitCode });
3510
3675
  for (const client of ptySession.clients) {
3511
3676
  try {
@@ -3554,6 +3719,7 @@ var init_pty_manager = __esm({
3554
3719
  } catch {
3555
3720
  }
3556
3721
  this.states?.forget(sessionId);
3722
+ this.hooks?.revoke(sessionId);
3557
3723
  this.sessions.delete(sessionId);
3558
3724
  }
3559
3725
  has(sessionId) {
@@ -3768,6 +3934,32 @@ var init_terminal_screen = __esm({
3768
3934
  });
3769
3935
 
3770
3936
  // ../core/dist/session-state.js
3937
+ function hookState(event) {
3938
+ switch (event.name) {
3939
+ case "SessionStart":
3940
+ case "Stop":
3941
+ return "waiting";
3942
+ case "UserPromptSubmit":
3943
+ case "PreToolUse":
3944
+ case "PostToolUse":
3945
+ case "PostToolUseFailure":
3946
+ case "PermissionDenied":
3947
+ case "PreCompact":
3948
+ return "working";
3949
+ case "PermissionRequest":
3950
+ return "permission";
3951
+ case "StopFailure":
3952
+ return "error";
3953
+ case "Notification":
3954
+ if (event.notificationType === "permission_prompt" || event.notificationType === "elicitation_dialog")
3955
+ return "permission";
3956
+ if (event.notificationType === "idle_prompt")
3957
+ return "waiting";
3958
+ return null;
3959
+ default:
3960
+ return null;
3961
+ }
3962
+ }
3771
3963
  function remoteClassifierFromEnv(env = process.env) {
3772
3964
  const shadow = env.FORGE_JEV_SHADOW === "1";
3773
3965
  if (env.FORGE_STATE_CLASSIFIER !== "jev")
@@ -3828,6 +4020,7 @@ var init_session_state = __esm({
3828
4020
  screen: new TerminalScreen(),
3829
4021
  askedScreen: null,
3830
4022
  exitedAt: null,
4023
+ hook: null,
3831
4024
  entry: { state: "working", confidence: 0.6, since: now, source: "local" }
3832
4025
  };
3833
4026
  this.sessions.set(key, tracked);
@@ -3845,7 +4038,8 @@ var init_session_state = __esm({
3845
4038
  tracked.lastOutputAt = now;
3846
4039
  tracked.version++;
3847
4040
  tracked.burstStart ??= now;
3848
- if (now - tracked.burstStart >= this.burstMs && tracked.entry.state !== "working") {
4041
+ const burstMayApply = tracked.hook ? tracked.entry.state === "permission" : tracked.entry.state !== "working";
4042
+ if (now - tracked.burstStart >= this.burstMs && burstMayApply) {
3849
4043
  this.apply(tracked, { state: "working", confidence: 0.95, source: "local" });
3850
4044
  }
3851
4045
  this.schedule(key, tracked);
@@ -3862,6 +4056,36 @@ var init_session_state = __esm({
3862
4056
  this.apply(tracked, { state: "exited", confidence: 1, source: "local" });
3863
4057
  tracked.entry.exitCode = exitCode;
3864
4058
  }
4059
+ hookEvent(key, event) {
4060
+ const tracked = this.sessions.get(key);
4061
+ if (!tracked || tracked.exitedAt !== null)
4062
+ return;
4063
+ const id = event.sessionId ?? null;
4064
+ if (event.name === "SessionStart") {
4065
+ const switches = event.source === "clear" || event.source === "resume";
4066
+ if (tracked.hook?.sessionId && id !== tracked.hook.sessionId && !switches)
4067
+ return;
4068
+ tracked.hook = { sessionId: id };
4069
+ } else if (!tracked.hook) {
4070
+ if (event.name === "SessionEnd")
4071
+ return;
4072
+ tracked.hook = { sessionId: id };
4073
+ } else if (tracked.hook.sessionId && id && id !== tracked.hook.sessionId) {
4074
+ return;
4075
+ } else if (!tracked.hook.sessionId) {
4076
+ tracked.hook.sessionId = id;
4077
+ }
4078
+ if (event.name === "SessionEnd") {
4079
+ tracked.hook = null;
4080
+ return;
4081
+ }
4082
+ const state = hookState(event);
4083
+ if (!state)
4084
+ return;
4085
+ tracked.version++;
4086
+ tracked.burstStart = null;
4087
+ this.apply(tracked, { state, confidence: 1, source: "hook" });
4088
+ }
3865
4089
  resize(key, cols, rows) {
3866
4090
  this.sessions.get(key)?.screen.resize(cols, rows);
3867
4091
  }
@@ -3912,6 +4136,12 @@ var init_session_state = __esm({
3912
4136
  const quietMs = Math.max(Date.now() - tracked.lastOutputAt, this.settleMs);
3913
4137
  const input = { text: terminalText(tracked.raw), quietMs, harness: tracked.harness, exitCode: null };
3914
4138
  const local = classifyLocal(input);
4139
+ if (tracked.hook) {
4140
+ const settledWaiting = (tracked.entry.state === "working" || tracked.entry.state === "permission") && local.state === "waiting" && local.confidence >= this.localTrust;
4141
+ if (local.state === "error" || settledWaiting)
4142
+ this.apply(tracked, local);
4143
+ return;
4144
+ }
3915
4145
  this.apply(tracked, local);
3916
4146
  if (!this.remote)
3917
4147
  return;
@@ -3958,7 +4188,7 @@ var init_session_state = __esm({
3958
4188
  });
3959
4189
 
3960
4190
  // ../core/dist/state-log.js
3961
- import { mkdirSync as mkdirSync3 } from "node:fs";
4191
+ import { mkdirSync as mkdirSync4 } from "node:fs";
3962
4192
  import { appendFile } from "node:fs/promises";
3963
4193
  import { homedir as homedir3 } from "node:os";
3964
4194
  import { dirname as dirname4, resolve as resolve4 } from "node:path";
@@ -3981,7 +4211,7 @@ function stateLogLine(call) {
3981
4211
  function createStateLog(path, onError = () => {
3982
4212
  }) {
3983
4213
  const file = resolve4(expandHome(path));
3984
- mkdirSync3(dirname4(file), { recursive: true });
4214
+ mkdirSync4(dirname4(file), { recursive: true });
3985
4215
  let queue = Promise.resolve();
3986
4216
  return (call) => {
3987
4217
  const line = stateLogLine(call);
@@ -4110,7 +4340,7 @@ var init_pty_routes = __esm({
4110
4340
  });
4111
4341
 
4112
4342
  // ../core/dist/general-sessions.js
4113
- import { existsSync as existsSync10, readFileSync as readFileSync7, writeFileSync as writeFileSync4, mkdirSync as mkdirSync4 } from "node:fs";
4343
+ import { existsSync as existsSync11, readFileSync as readFileSync8, writeFileSync as writeFileSync5, mkdirSync as mkdirSync5 } from "node:fs";
4114
4344
  import { dirname as dirname5 } from "node:path";
4115
4345
  var MAX_AGE_MS, GeneralSessions;
4116
4346
  var init_general_sessions = __esm({
@@ -4122,10 +4352,10 @@ var init_general_sessions = __esm({
4122
4352
  sessions = /* @__PURE__ */ new Map();
4123
4353
  constructor(file = null, now = Date.now()) {
4124
4354
  this.file = file;
4125
- if (!file || !existsSync10(file))
4355
+ if (!file || !existsSync11(file))
4126
4356
  return;
4127
4357
  try {
4128
- const saved = JSON.parse(readFileSync7(file, "utf-8"));
4358
+ const saved = JSON.parse(readFileSync8(file, "utf-8"));
4129
4359
  for (const [key, session] of Object.entries(saved)) {
4130
4360
  if (now - Date.parse(session.created) < MAX_AGE_MS)
4131
4361
  this.sessions.set(key, session);
@@ -4151,8 +4381,8 @@ var init_general_sessions = __esm({
4151
4381
  if (!this.file)
4152
4382
  return;
4153
4383
  try {
4154
- mkdirSync4(dirname5(this.file), { recursive: true });
4155
- writeFileSync4(this.file, JSON.stringify(Object.fromEntries(this.sessions), null, 2));
4384
+ mkdirSync5(dirname5(this.file), { recursive: true });
4385
+ writeFileSync5(this.file, JSON.stringify(Object.fromEntries(this.sessions), null, 2));
4156
4386
  } catch (err) {
4157
4387
  console.warn(`[pty] could not save general sessions: ${err.message}`);
4158
4388
  }
@@ -4162,10 +4392,10 @@ var init_general_sessions = __esm({
4162
4392
  });
4163
4393
 
4164
4394
  // ../core/dist/liveframe.js
4165
- import { existsSync as existsSync11, readFileSync as readFileSync8, readdirSync as readdirSync6 } from "node:fs";
4395
+ import { existsSync as existsSync12, readFileSync as readFileSync9, readdirSync as readdirSync6 } from "node:fs";
4166
4396
  import { mkdir, rm } from "node:fs/promises";
4167
4397
  import { homedir as homedir4 } from "node:os";
4168
- import { join as join12 } from "node:path";
4398
+ import { join as join13 } from "node:path";
4169
4399
  function slugify(name) {
4170
4400
  const slug = name.toLowerCase().normalize("NFKD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48);
4171
4401
  return slug || "untitled";
@@ -4181,7 +4411,7 @@ function parseFrameUrl(stdout) {
4181
4411
  }
4182
4412
  function readJson2(path) {
4183
4413
  try {
4184
- return JSON.parse(readFileSync8(path, "utf8"));
4414
+ return JSON.parse(readFileSync9(path, "utf8"));
4185
4415
  } catch {
4186
4416
  return null;
4187
4417
  }
@@ -4214,13 +4444,13 @@ var init_liveframe = __esm({
4214
4444
  busy = /* @__PURE__ */ new Set();
4215
4445
  constructor(options = {}) {
4216
4446
  this.account = options.account ?? process.env.FORGE_LIVEFRAME_ACCOUNT ?? DEFAULT_ACCOUNT;
4217
- this.root = options.root ?? join12(homedir4(), "liveframe");
4218
- this.home = options.home ?? process.env.LIVEFRAME_HOME ?? join12(homedir4(), ".liveframe");
4447
+ this.root = options.root ?? join13(homedir4(), "liveframe");
4448
+ this.home = options.home ?? process.env.LIVEFRAME_HOME ?? join13(homedir4(), ".liveframe");
4219
4449
  this.run = options.run ?? createRunner(void 0, LF_TIMEOUT_MS);
4220
4450
  }
4221
4451
  // reads only the API base and whether a credential exists, never the credential itself
4222
4452
  config() {
4223
- const file = readJson2(join12(this.home, "config.json")) ?? {};
4453
+ const file = readJson2(join13(this.home, "config.json")) ?? {};
4224
4454
  const api = process.env.LIVEFRAME_API ?? (typeof file.api === "string" ? file.api : DEFAULT_API);
4225
4455
  return { api: api.replace(/\/+$/, ""), signedIn: Boolean(process.env.LIVEFRAME_TOKEN || file.oauth || file.token) };
4226
4456
  }
@@ -4230,11 +4460,11 @@ var init_liveframe = __esm({
4230
4460
  return { account: this.account, installed: version.code === 0, signedIn, api, root: this.root };
4231
4461
  }
4232
4462
  frameDir(project, frame) {
4233
- return join12(this.root, project, frame);
4463
+ return join13(this.root, project, frame);
4234
4464
  }
4235
4465
  readFrame(project, frame, api) {
4236
4466
  const dir = this.frameDir(project, frame);
4237
- const json = readJson2(join12(dir, "liveframe.json"));
4467
+ const json = readJson2(join13(dir, "liveframe.json"));
4238
4468
  if (!json || typeof json.key !== "string")
4239
4469
  return null;
4240
4470
  const branch = typeof json.branch === "string" ? json.branch : "main";
@@ -4254,14 +4484,14 @@ var init_liveframe = __esm({
4254
4484
  return this.readFrame(project, frame, this.config().api);
4255
4485
  }
4256
4486
  listFrames() {
4257
- if (!existsSync11(this.root))
4487
+ if (!existsSync12(this.root))
4258
4488
  return [];
4259
4489
  const { api } = this.config();
4260
4490
  const frames = [];
4261
4491
  for (const project of readdirSync6(this.root, { withFileTypes: true })) {
4262
4492
  if (!project.isDirectory() || !isFrameSegment(project.name))
4263
4493
  continue;
4264
- for (const frame of readdirSync6(join12(this.root, project.name), { withFileTypes: true })) {
4494
+ for (const frame of readdirSync6(join13(this.root, project.name), { withFileTypes: true })) {
4265
4495
  if (!frame.isDirectory() || !isFrameSegment(frame.name))
4266
4496
  continue;
4267
4497
  const found = this.readFrame(project.name, frame.name, api);
@@ -4292,9 +4522,9 @@ var init_liveframe = __esm({
4292
4522
  // runs lf into a fresh frame folder, removing whatever it left if it fails
4293
4523
  intoNewDir(project, frame, args) {
4294
4524
  return this.exclusive(project, frame, async () => {
4295
- const projectDir = join12(this.root, project);
4525
+ const projectDir = join13(this.root, project);
4296
4526
  const dir = this.frameDir(project, frame);
4297
- if (existsSync11(dir))
4527
+ if (existsSync12(dir))
4298
4528
  throw new LiveframeError(`${project}/${frame} already exists in ${this.root}`, 409);
4299
4529
  await mkdir(projectDir, { recursive: true });
4300
4530
  try {
@@ -4371,12 +4601,12 @@ var init_liveframe_routes = __esm({
4371
4601
 
4372
4602
  // ../core/dist/cw-install.js
4373
4603
  import { execFile as execFile5 } from "node:child_process";
4374
- import { createHash as createHash3 } from "node:crypto";
4375
- import { accessSync as accessSync2, constants as constants2, existsSync as existsSync12, readFileSync as readFileSync9, statSync as statSync3, writeFileSync as writeFileSync5 } from "node:fs";
4376
- import { delimiter as delimiter2, join as join13 } from "node:path";
4604
+ import { createHash as createHash4 } from "node:crypto";
4605
+ import { accessSync as accessSync2, constants as constants2, existsSync as existsSync13, readFileSync as readFileSync10, statSync as statSync3, writeFileSync as writeFileSync6 } from "node:fs";
4606
+ import { delimiter as delimiter2, join as join14 } from "node:path";
4377
4607
  function readCwVersion(file) {
4378
4608
  try {
4379
- const match = /^CW_VERSION="([^"]+)"/m.exec(readFileSync9(file, "utf-8"));
4609
+ const match = /^CW_VERSION="([^"]+)"/m.exec(readFileSync10(file, "utf-8"));
4380
4610
  return match ? match[1] : null;
4381
4611
  } catch {
4382
4612
  return null;
@@ -4394,9 +4624,9 @@ function compareVersions(a, b) {
4394
4624
  }
4395
4625
  function readCwBundle(dir) {
4396
4626
  try {
4397
- const { ref } = JSON.parse(readFileSync9(join13(dir, ".bundle.json"), "utf-8"));
4398
- const version = readCwVersion(join13(dir, "cw"));
4399
- if (!ref || !version || !existsSync12(join13(dir, "install.sh")))
4627
+ const { ref } = JSON.parse(readFileSync10(join14(dir, ".bundle.json"), "utf-8"));
4628
+ const version = readCwVersion(join14(dir, "cw"));
4629
+ if (!ref || !version || !existsSync13(join14(dir, "install.sh")))
4400
4630
  return null;
4401
4631
  return { dir, version, ref };
4402
4632
  } catch {
@@ -4426,7 +4656,7 @@ function findOnPath(name, pathVar, excludeDir) {
4426
4656
  for (const dir of (pathVar ?? "").split(delimiter2)) {
4427
4657
  if (!dir || dir === excludeDir)
4428
4658
  continue;
4429
- const candidate = join13(dir, name);
4659
+ const candidate = join14(dir, name);
4430
4660
  try {
4431
4661
  if (!statSync3(candidate).isFile())
4432
4662
  continue;
@@ -4438,13 +4668,13 @@ function findOnPath(name, pathVar, excludeDir) {
4438
4668
  return null;
4439
4669
  }
4440
4670
  function pathWithCw(cwHome, pathVar) {
4441
- const bin = join13(cwHome, "bin");
4671
+ const bin = join14(cwHome, "bin");
4442
4672
  const rest = (pathVar ?? "").split(delimiter2).filter((dir) => dir && dir !== bin);
4443
4673
  return [bin, ...rest].join(delimiter2);
4444
4674
  }
4445
4675
  function readMarker(cwHome) {
4446
4676
  try {
4447
- return JSON.parse(readFileSync9(join13(cwHome, MARKER_FILE), "utf-8"));
4677
+ return JSON.parse(readFileSync10(join14(cwHome, MARKER_FILE), "utf-8"));
4448
4678
  } catch {
4449
4679
  return null;
4450
4680
  }
@@ -4458,23 +4688,23 @@ async function ensureCw(options) {
4458
4688
  const { cwHome, bundleDir } = options;
4459
4689
  const env = options.env ?? process.env;
4460
4690
  const run2 = options.run ?? runInstall;
4461
- const bin = join13(cwHome, "bin", "cw");
4691
+ const bin = join14(cwHome, "bin", "cw");
4462
4692
  const bundle = readCwBundle(bundleDir);
4463
- const installed = existsSync12(bin) ? { version: readCwVersion(bin), sha256: sha256Of(bin) } : null;
4693
+ const installed = existsSync13(bin) ? { version: readCwVersion(bin), sha256: sha256Of(bin) } : null;
4464
4694
  const decision = decideCwInstall({
4465
4695
  bundle,
4466
4696
  installed,
4467
4697
  marker: readMarker(cwHome),
4468
- cwOnPath: findOnPath("cw", env.PATH, join13(cwHome, "bin")) !== null,
4698
+ cwOnPath: findOnPath("cw", env.PATH, join14(cwHome, "bin")) !== null,
4469
4699
  skip: env.FORGE_SKIP_CW_INSTALL === "1"
4470
4700
  });
4471
4701
  if (decision.action === "skip" || !bundle)
4472
4702
  return { action: "skipped", message: decision.reason };
4473
- const { code, output } = await run2(join13(bundle.dir, "install.sh"), ["--no-shell"], { ...env, CW_HOME: cwHome });
4474
- if (code !== 0 || !existsSync12(bin))
4703
+ const { code, output } = await run2(join14(bundle.dir, "install.sh"), ["--no-shell"], { ...env, CW_HOME: cwHome });
4704
+ if (code !== 0 || !existsSync13(bin))
4475
4705
  return { action: "failed", message: failureMessage2(output) };
4476
4706
  const marker = { version: bundle.version, ref: bundle.ref, sha256: sha256Of(bin) };
4477
- writeFileSync5(join13(cwHome, MARKER_FILE), JSON.stringify(marker, null, 2) + "\n");
4707
+ writeFileSync6(join14(cwHome, MARKER_FILE), JSON.stringify(marker, null, 2) + "\n");
4478
4708
  return {
4479
4709
  action: decision.action === "install" ? "installed" : "updated",
4480
4710
  version: bundle.version,
@@ -4488,7 +4718,7 @@ var init_cw_install = __esm({
4488
4718
  MARKER_FILE = ".forge-cw.json";
4489
4719
  INSTALL_TIMEOUT_MS2 = 12e4;
4490
4720
  ANSI_RE3 = /\u001b\[[0-9;?]*[A-Za-z]/g;
4491
- sha256Of = (file) => createHash3("sha256").update(readFileSync9(file)).digest("hex");
4721
+ sha256Of = (file) => createHash4("sha256").update(readFileSync10(file)).digest("hex");
4492
4722
  runInstall = (script, args, env) => new Promise((resolve11) => {
4493
4723
  execFile5("bash", [script, ...args], { env, timeout: INSTALL_TIMEOUT_MS2, maxBuffer: 1024 * 1024 }, (err, stdout, stderr) => {
4494
4724
  const output = `${String(stdout)}${String(stderr)}`;
@@ -6592,9 +6822,9 @@ var init_kioku_versions = __esm({
6592
6822
 
6593
6823
  // ../core/dist/kioku.js
6594
6824
  import { spawn as spawn7 } from "node:child_process";
6595
- import { existsSync as existsSync13 } from "node:fs";
6825
+ import { existsSync as existsSync14 } from "node:fs";
6596
6826
  import { homedir as homedir5 } from "node:os";
6597
- import { join as join14 } from "node:path";
6827
+ import { join as join15 } from "node:path";
6598
6828
  import { createInterface } from "node:readline";
6599
6829
  import * as pty3 from "node-pty";
6600
6830
  function assertVersion(version) {
@@ -6606,8 +6836,8 @@ function assertRepo(repo, what) {
6606
6836
  throw new KiokuError(`${what} is named as owner/repo, not "${repo}"`, 400);
6607
6837
  }
6608
6838
  function resolveKiokuBin(pathVar = process.env.PATH, home = homedir5()) {
6609
- const fallback = join14(home, ".local", "bin", "kioku");
6610
- return findOnPath("kioku", pathVar) ?? (existsSync13(fallback) ? fallback : "kioku");
6839
+ const fallback = join15(home, ".local", "bin", "kioku");
6840
+ return findOnPath("kioku", pathVar) ?? (existsSync14(fallback) ? fallback : "kioku");
6611
6841
  }
6612
6842
  function rememberPrompt(text2) {
6613
6843
  return `Remember this with kioku: ${text2.replace(/\s+/g, " ").trim()}`;
@@ -6743,7 +6973,7 @@ var init_kioku = __esm({
6743
6973
  if (version.code !== 0)
6744
6974
  return MISSING;
6745
6975
  const listed = list?.brains ?? [];
6746
- const entries = Object.entries(this.projects()).filter(([, p]) => existsSync13(p.path));
6976
+ const entries = Object.entries(this.projects()).filter(([, p]) => existsSync14(p.path));
6747
6977
  const readBrain = async (b) => {
6748
6978
  if (!b.onDisk)
6749
6979
  return { kinds: {}, namespaces: [], writes: [] };
@@ -6885,7 +7115,7 @@ var init_kioku = __esm({
6885
7115
  if (!input.brain && !input.team)
6886
7116
  throw new KiokuError("name a project brain, a team brain, or both", 400);
6887
7117
  const path = this.projects()[input.project]?.path;
6888
- if (!path || !existsSync13(path))
7118
+ if (!path || !existsSync14(path))
6889
7119
  throw new KiokuError(`no CW project ${input.project} on this machine`, 404);
6890
7120
  if (input.brain)
6891
7121
  assertRepo(input.brain, "the project brain");
@@ -7162,7 +7392,7 @@ var init_dist = __esm({
7162
7392
 
7163
7393
  // ../core/dist/module-permissions.js
7164
7394
  import { realpathSync } from "node:fs";
7165
- import { basename as basename3, dirname as dirname6, join as join15, resolve as resolve5, sep as sep3 } from "node:path";
7395
+ import { basename as basename3, dirname as dirname6, join as join16, resolve as resolve5, sep as sep3 } from "node:path";
7166
7396
  function expandGrants(permissions, settings) {
7167
7397
  const p = permissions ?? {};
7168
7398
  return {
@@ -7244,7 +7474,7 @@ function realOrParent(path) {
7244
7474
  return realpathSync(path);
7245
7475
  } catch {
7246
7476
  const parent = dirname6(path);
7247
- return parent === path ? path : join15(realOrParent(parent), basename3(path));
7477
+ return parent === path ? path : join16(realOrParent(parent), basename3(path));
7248
7478
  }
7249
7479
  }
7250
7480
  var TEMPLATE_RE;
@@ -7257,8 +7487,8 @@ var init_module_permissions = __esm({
7257
7487
  });
7258
7488
 
7259
7489
  // ../core/dist/module-manifest.js
7260
- import { readFileSync as readFileSync10 } from "node:fs";
7261
- import { join as join16, resolve as resolve6, sep as sep4 } from "node:path";
7490
+ import { readFileSync as readFileSync11 } from "node:fs";
7491
+ import { join as join17, resolve as resolve6, sep as sep4 } from "node:path";
7262
7492
  function checkSdk(range, version = SDK_VERSION) {
7263
7493
  if (!import_semver2.default.validRange(range))
7264
7494
  return `sdk range "${range}" is not valid semver`;
@@ -7373,11 +7603,11 @@ function insideFolder(dir, relative) {
7373
7603
  }
7374
7604
  function manifestFileFor(dir) {
7375
7605
  try {
7376
- const pkg = JSON.parse(readFileSync10(join16(dir, "package.json"), "utf-8"));
7606
+ const pkg = JSON.parse(readFileSync11(join17(dir, "package.json"), "utf-8"));
7377
7607
  const manifest = typeof pkg.forge?.manifest === "string" ? pkg.forge.manifest : "forge-module.json";
7378
- return { file: join16(dir, manifest), hasForgeField: pkg.forge !== void 0 };
7608
+ return { file: join17(dir, manifest), hasForgeField: pkg.forge !== void 0 };
7379
7609
  } catch {
7380
- return { file: join16(dir, "forge-module.json"), hasForgeField: false };
7610
+ return { file: join17(dir, "forge-module.json"), hasForgeField: false };
7381
7611
  }
7382
7612
  }
7383
7613
  function validateSettings(schema, values) {
@@ -7631,15 +7861,15 @@ var init_module_context = __esm({
7631
7861
  });
7632
7862
 
7633
7863
  // ../core/dist/module-host.js
7634
- import { existsSync as existsSync14, mkdirSync as mkdirSync5, readdirSync as readdirSync7, readFileSync as readFileSync11, statSync as statSync4, writeFileSync as writeFileSync6 } from "node:fs";
7635
- import { basename as basename4, dirname as dirname7, join as join17, resolve as resolve7, sep as sep5 } from "node:path";
7864
+ import { existsSync as existsSync15, mkdirSync as mkdirSync6, readdirSync as readdirSync7, readFileSync as readFileSync12, statSync as statSync4, writeFileSync as writeFileSync7 } from "node:fs";
7865
+ import { basename as basename4, dirname as dirname7, join as join18, resolve as resolve7, sep as sep5 } from "node:path";
7636
7866
  import { pathToFileURL } from "node:url";
7637
7867
  function disabled(id, c, reason, m) {
7638
7868
  const text2 = (v, fallback) => typeof v === "string" && v ? v : fallback;
7639
7869
  return { id, name: text2(m?.name, id), version: text2(m?.version, ""), displayName: text2(m?.displayName, id), source: c.source, state: "disabled", reason };
7640
7870
  }
7641
7871
  function packages(root, source, packaged) {
7642
- if (!existsSync14(root))
7872
+ if (!existsSync15(root))
7643
7873
  return [];
7644
7874
  const out = [];
7645
7875
  const consider = (dir, name) => {
@@ -7652,22 +7882,22 @@ function packages(root, source, packaged) {
7652
7882
  if (!isDir(root, entry) || entry.name.startsWith("."))
7653
7883
  continue;
7654
7884
  if (entry.name.startsWith("@")) {
7655
- for (const sub of readdirSync7(join17(root, entry.name), { withFileTypes: true })) {
7656
- if (isDir(join17(root, entry.name), sub))
7657
- consider(join17(root, entry.name, sub.name), `${entry.name}/${sub.name}`);
7885
+ for (const sub of readdirSync7(join18(root, entry.name), { withFileTypes: true })) {
7886
+ if (isDir(join18(root, entry.name), sub))
7887
+ consider(join18(root, entry.name, sub.name), `${entry.name}/${sub.name}`);
7658
7888
  }
7659
7889
  } else {
7660
- consider(join17(root, entry.name), entry.name);
7890
+ consider(join18(root, entry.name), entry.name);
7661
7891
  }
7662
7892
  }
7663
7893
  return out;
7664
7894
  }
7665
7895
  function nearestPackage(dir) {
7666
7896
  for (let d = dir; ; d = dirname7(d)) {
7667
- const path = join17(d, "package.json");
7668
- if (existsSync14(path)) {
7897
+ const path = join18(d, "package.json");
7898
+ if (existsSync15(path)) {
7669
7899
  try {
7670
- return { path, type: JSON.parse(readFileSync11(path, "utf-8")).type };
7900
+ return { path, type: JSON.parse(readFileSync12(path, "utf-8")).type };
7671
7901
  } catch {
7672
7902
  return { path };
7673
7903
  }
@@ -7682,7 +7912,7 @@ function isDir(parent, entry) {
7682
7912
  if (!entry.isSymbolicLink())
7683
7913
  return false;
7684
7914
  try {
7685
- return statSync4(join17(parent, entry.name)).isDirectory();
7915
+ return statSync4(join18(parent, entry.name)).isDirectory();
7686
7916
  } catch {
7687
7917
  return false;
7688
7918
  }
@@ -7731,7 +7961,7 @@ var init_module_host = __esm({
7731
7961
  bannersFile;
7732
7962
  constructor(opts) {
7733
7963
  this.opts = opts;
7734
- this.bannersFile = join17(dirname7(opts.devFile), "module-banners.json");
7964
+ this.bannersFile = join18(dirname7(opts.devFile), "module-banners.json");
7735
7965
  }
7736
7966
  list() {
7737
7967
  return this.statuses;
@@ -7747,7 +7977,7 @@ var init_module_host = __esm({
7747
7977
  // only what was installed into the modules folder; bundled, dev and Forge's own packages stay
7748
7978
  removable(c) {
7749
7979
  const { modulesDir } = this.opts;
7750
- return c.source === "installed" && dirname7(c.dir) === modulesDir || c.dir.startsWith(join17(modulesDir, "node_modules") + sep5);
7980
+ return c.source === "installed" && dirname7(c.dir) === modulesDir || c.dir.startsWith(join18(modulesDir, "node_modules") + sep5);
7751
7981
  }
7752
7982
  // scans, reloads and dev changes run one at a time: each one awaits imports midway
7753
7983
  queue = Promise.resolve();
@@ -7800,14 +8030,14 @@ var init_module_host = __esm({
7800
8030
  const dirs = this.devDirs();
7801
8031
  const dir = resolve7(path);
7802
8032
  if (!dirs.includes(dir))
7803
- writeFileSync6(this.opts.devFile, JSON.stringify([...dirs, dir], null, 2));
8033
+ writeFileSync7(this.opts.devFile, JSON.stringify([...dirs, dir], null, 2));
7804
8034
  await this.scanNow();
7805
8035
  return this.statuses.find((s) => this.loaded.get(s.id)?.dir === dir) ?? this.statuses.find((s) => s.state !== "enabled" && s.id === basename4(dir));
7806
8036
  }
7807
8037
  removeDev(path) {
7808
8038
  return this.serial(async () => {
7809
8039
  const dir = resolve7(path);
7810
- writeFileSync6(this.opts.devFile, JSON.stringify(this.devDirs().filter((d) => d !== dir), null, 2));
8040
+ writeFileSync7(this.opts.devFile, JSON.stringify(this.devDirs().filter((d) => d !== dir), null, 2));
7811
8041
  await this.scanNow();
7812
8042
  });
7813
8043
  }
@@ -7846,7 +8076,7 @@ var init_module_host = __esm({
7846
8076
  }
7847
8077
  readBanners() {
7848
8078
  try {
7849
- const raw = JSON.parse(readFileSync11(this.bannersFile, "utf-8"));
8079
+ const raw = JSON.parse(readFileSync12(this.bannersFile, "utf-8"));
7850
8080
  if (!raw || typeof raw !== "object" || Array.isArray(raw))
7851
8081
  return {};
7852
8082
  return Object.fromEntries(Object.entries(raw).filter((e) => typeof e[1] === "boolean"));
@@ -7858,13 +8088,13 @@ var init_module_host = __esm({
7858
8088
  const banner = this.loaded.get(id)?.status.banner;
7859
8089
  if (!banner)
7860
8090
  return;
7861
- mkdirSync5(dirname7(this.bannersFile), { recursive: true });
7862
- writeFileSync6(this.bannersFile, JSON.stringify({ ...this.readBanners(), [id]: enabled }, null, 2));
8091
+ mkdirSync6(dirname7(this.bannersFile), { recursive: true });
8092
+ writeFileSync7(this.bannersFile, JSON.stringify({ ...this.readBanners(), [id]: enabled }, null, 2));
7863
8093
  banner.enabled = enabled;
7864
8094
  }
7865
8095
  devDirs() {
7866
8096
  try {
7867
- const raw = JSON.parse(readFileSync11(this.opts.devFile, "utf-8"));
8097
+ const raw = JSON.parse(readFileSync12(this.opts.devFile, "utf-8"));
7868
8098
  return Array.isArray(raw) ? raw.filter((d) => typeof d === "string") : [];
7869
8099
  } catch {
7870
8100
  return [];
@@ -7872,18 +8102,18 @@ var init_module_host = __esm({
7872
8102
  }
7873
8103
  candidates() {
7874
8104
  const out = [];
7875
- const folder = (dir, source) => out.push({ dir, source, manifestFile: join17(dir, "forge-module.json"), packaged: false });
8105
+ const folder = (dir, source) => out.push({ dir, source, manifestFile: join18(dir, "forge-module.json"), packaged: false });
7876
8106
  if (this.opts.bundledDir)
7877
8107
  for (const name of [...BUNDLED_MODULES, ...BUNDLED_V1_MODULES])
7878
- folder(join17(this.opts.bundledDir, name), "bundled");
8108
+ folder(join18(this.opts.bundledDir, name), "bundled");
7879
8109
  for (const dir of this.devDirs())
7880
8110
  folder(dir, "dev");
7881
- if (existsSync14(this.opts.modulesDir)) {
8111
+ if (existsSync15(this.opts.modulesDir)) {
7882
8112
  for (const entry of readdirSync7(this.opts.modulesDir, { withFileTypes: true })) {
7883
8113
  if (entry.isDirectory() && entry.name !== "node_modules" && !entry.name.startsWith("."))
7884
- folder(join17(this.opts.modulesDir, entry.name), "installed");
8114
+ folder(join18(this.opts.modulesDir, entry.name), "installed");
7885
8115
  }
7886
- out.push(...packages(join17(this.opts.modulesDir, "node_modules"), "node_modules", true));
8116
+ out.push(...packages(join18(this.opts.modulesDir, "node_modules"), "node_modules", true));
7887
8117
  }
7888
8118
  if (this.opts.forgeNodeModules)
7889
8119
  out.push(...packages(this.opts.forgeNodeModules, "node_modules", false));
@@ -7897,12 +8127,12 @@ var init_module_host = __esm({
7897
8127
  }
7898
8128
  async loadCandidate(c, seen) {
7899
8129
  const fallbackId = basename4(c.dir);
7900
- if (!existsSync14(c.manifestFile)) {
8130
+ if (!existsSync15(c.manifestFile)) {
7901
8131
  return c.packaged ? disabled(fallbackId, c, `no manifest at ${c.manifestFile}`) : void 0;
7902
8132
  }
7903
8133
  let raw;
7904
8134
  try {
7905
- raw = JSON.parse(readFileSync11(c.manifestFile, "utf-8"));
8135
+ raw = JSON.parse(readFileSync12(c.manifestFile, "utf-8"));
7906
8136
  } catch (err) {
7907
8137
  return disabled(fallbackId, c, `forge-module.json is not valid JSON: ${err.message}`);
7908
8138
  }
@@ -7952,12 +8182,12 @@ var init_module_host = __esm({
7952
8182
  };
7953
8183
  if (m.view) {
7954
8184
  const entry = resolve7(c.dir, m.view.entry);
7955
- const mtime = existsSync14(entry) ? Math.floor(statSync4(entry).mtimeMs) : 0;
8185
+ const mtime = existsSync15(entry) ? Math.floor(statSync4(entry).mtimeMs) : 0;
7956
8186
  status.view = { url: `/api/modules/${m.id}/view.js`, title: m.view.title ?? m.displayName, version: `${m.version}-${mtime}` };
7957
8187
  }
7958
8188
  if (m.view?.banner) {
7959
8189
  const file = resolve7(c.dir, m.view.banner);
7960
- const mtime = existsSync14(file) ? Math.floor(statSync4(file).mtimeMs) : 0;
8190
+ const mtime = existsSync15(file) ? Math.floor(statSync4(file).mtimeMs) : 0;
7961
8191
  status.banner = { url: `/api/modules/${m.id}/banner.js`, version: mtime, enabled: this.readBanners()[m.id] ?? c.source === "bundled" };
7962
8192
  }
7963
8193
  const settings = this.readSettings(m);
@@ -7992,9 +8222,9 @@ var init_module_host = __esm({
7992
8222
  });
7993
8223
 
7994
8224
  // ../core/dist/module-confirmations.js
7995
- import { createHash as createHash4, randomBytes } from "node:crypto";
8225
+ import { createHash as createHash5, randomBytes as randomBytes2 } from "node:crypto";
7996
8226
  function inputHash(input) {
7997
- return createHash4("sha256").update(stable(input)).digest("hex");
8227
+ return createHash5("sha256").update(stable(input)).digest("hex");
7998
8228
  }
7999
8229
  function stable(value) {
8000
8230
  if (Array.isArray(value))
@@ -8017,7 +8247,7 @@ var init_module_confirmations = __esm({
8017
8247
  }
8018
8248
  issue(moduleId, actionId, hash, confirmation) {
8019
8249
  this.sweep();
8020
- const token = randomBytes(24).toString("base64url");
8250
+ const token = randomBytes2(24).toString("base64url");
8021
8251
  this.pending.set(token, { moduleId, actionId, hash, confirmation, expires: this.now() + TTL_MS2 });
8022
8252
  return token;
8023
8253
  }
@@ -8041,14 +8271,14 @@ var init_module_confirmations = __esm({
8041
8271
  });
8042
8272
 
8043
8273
  // ../core/dist/module-install.js
8044
- import { randomBytes as randomBytes2 } from "node:crypto";
8045
- import { existsSync as existsSync15, mkdirSync as mkdirSync6, mkdtempSync, readFileSync as readFileSync12, rmSync as rmSync3 } from "node:fs";
8274
+ import { randomBytes as randomBytes3 } from "node:crypto";
8275
+ import { existsSync as existsSync16, mkdirSync as mkdirSync7, mkdtempSync, readFileSync as readFileSync13, rmSync as rmSync3 } from "node:fs";
8046
8276
  import { homedir as homedir7, tmpdir } from "node:os";
8047
- import { isAbsolute as isAbsolute2, join as join18, resolve as resolve8, sep as sep6 } from "node:path";
8277
+ import { isAbsolute as isAbsolute2, join as join19, resolve as resolve8, sep as sep6 } from "node:path";
8048
8278
  async function previewManifest(spec, opts) {
8049
8279
  if (isPathSpec(spec, opts.cwd))
8050
8280
  return readFolder(expand(spec, opts.cwd));
8051
- const tmp = mkdtempSync(join18(tmpdir(), "forge-module-pack-"));
8281
+ const tmp = mkdtempSync(join19(tmpdir(), "forge-module-pack-"));
8052
8282
  try {
8053
8283
  const packed = await opts.run("npm", ["pack", spec, "--pack-destination", tmp, "--ignore-scripts", "--json"], opts.cwd);
8054
8284
  if (packed.code !== 0)
@@ -8057,10 +8287,10 @@ async function previewManifest(spec, opts) {
8057
8287
  const filename = info?.filename;
8058
8288
  if (!filename)
8059
8289
  throw new Error(`npm pack ${spec} produced no tarball`);
8060
- const untar = await opts.run("tar", ["-xzf", join18(tmp, filename), "-C", tmp], opts.cwd);
8290
+ const untar = await opts.run("tar", ["-xzf", join19(tmp, filename), "-C", tmp], opts.cwd);
8061
8291
  if (untar.code !== 0)
8062
8292
  throw new Error(`could not unpack ${filename}: ${untar.stderr.trim()}`);
8063
- const preview = readFolder(join18(tmp, "package"));
8293
+ const preview = readFolder(join19(tmp, "package"));
8064
8294
  return info.name && info.version ? { ...preview, packed: { name: info.name, version: info.version } } : preview;
8065
8295
  } finally {
8066
8296
  rmSync3(tmp, { recursive: true, force: true });
@@ -8074,9 +8304,9 @@ function npmPackError(spec, output) {
8074
8304
  }
8075
8305
  function readFolder(dir) {
8076
8306
  const manifestFile = manifestFileFor(dir).file;
8077
- if (!existsSync15(manifestFile))
8307
+ if (!existsSync16(manifestFile))
8078
8308
  throw new Error(`${dir} has no forge-module.json`);
8079
- const raw = JSON.parse(readFileSync12(manifestFile, "utf-8"));
8309
+ const raw = JSON.parse(readFileSync13(manifestFile, "utf-8"));
8080
8310
  const check = checkManifest(raw, dir);
8081
8311
  if (check.kind === "invalid")
8082
8312
  throw new Error(`invalid manifest: ${check.reason}`);
@@ -8109,7 +8339,7 @@ function installArgs(spec, prefix) {
8109
8339
  }
8110
8340
  function packageName(dir) {
8111
8341
  try {
8112
- const name = JSON.parse(readFileSync12(join18(dir, "package.json"), "utf-8")).name;
8342
+ const name = JSON.parse(readFileSync13(join19(dir, "package.json"), "utf-8")).name;
8113
8343
  return typeof name === "string" ? name : void 0;
8114
8344
  } catch {
8115
8345
  return void 0;
@@ -8123,7 +8353,7 @@ var init_module_install = __esm({
8123
8353
  init_output();
8124
8354
  init_state_log();
8125
8355
  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.";
8126
- isPathSpec = (spec, cwd) => spec.startsWith(".") || spec.startsWith("~") || isAbsolute2(spec) || existsSync15(resolve8(cwd, spec)) && !spec.startsWith("@");
8356
+ isPathSpec = (spec, cwd) => spec.startsWith(".") || spec.startsWith("~") || isAbsolute2(spec) || existsSync16(resolve8(cwd, spec)) && !spec.startsWith("@");
8127
8357
  expand = (spec, cwd) => resolve8(cwd, expandHome(spec));
8128
8358
  InstallError = class extends Error {
8129
8359
  code;
@@ -8160,7 +8390,7 @@ var init_module_install = __esm({
8160
8390
  for (const [t, p] of this.previews)
8161
8391
  if (p.expires < this.now)
8162
8392
  this.previews.delete(t);
8163
- const token = randomBytes2(24).toString("base64url");
8393
+ const token = randomBytes3(24).toString("base64url");
8164
8394
  this.previews.set(token, { spec: pinned, name: m.name, expires: this.now + PREVIEW_TTL_MS });
8165
8395
  return {
8166
8396
  token,
@@ -8181,7 +8411,7 @@ var init_module_install = __esm({
8181
8411
  if (!p || p.expires < this.now)
8182
8412
  throw new InstallError("confirmation_required", "Preview the module again before installing it");
8183
8413
  return this.exclusive(async () => {
8184
- mkdirSync6(this.opts.modulesDir, { recursive: true });
8414
+ mkdirSync7(this.opts.modulesDir, { recursive: true });
8185
8415
  const res = await this.opts.run("npm", installArgs(p.spec, this.opts.modulesDir), this.opts.modulesDir);
8186
8416
  if (res.code !== 0)
8187
8417
  throw new InstallError("install_failed", `npm install failed: ${tailOutput(res.stderr || res.stdout, 6)}`);
@@ -8196,7 +8426,7 @@ var init_module_install = __esm({
8196
8426
  throw new InstallError("not_found", `No module ${id}`);
8197
8427
  if (!found.removable)
8198
8428
  throw new InstallError("bad_request", `${id} was not installed into Forge's modules folder; a dev folder unloads when forge module dev stops`);
8199
- const packages2 = join18(this.opts.modulesDir, "node_modules") + sep6;
8429
+ const packages2 = join19(this.opts.modulesDir, "node_modules") + sep6;
8200
8430
  if (found.dir.startsWith(packages2)) {
8201
8431
  const name = packageName(found.dir) ?? found.dir.slice(packages2.length);
8202
8432
  const res = await this.opts.run("npm", ["uninstall", "--prefix", this.opts.modulesDir, name], this.opts.modulesDir);
@@ -8634,14 +8864,14 @@ var init_module_cw = __esm({
8634
8864
 
8635
8865
  // ../core/dist/agent-runner.js
8636
8866
  import { spawn as nodeSpawn } from "node:child_process";
8637
- import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync4 } from "node:fs";
8867
+ import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync4 } from "node:fs";
8638
8868
  import { tmpdir as tmpdir2 } from "node:os";
8639
- import { join as join19 } from "node:path";
8869
+ import { join as join20 } from "node:path";
8640
8870
  function runAgent(input, o) {
8641
8871
  if (!ACCOUNT_NAME_RE.test(input.account))
8642
8872
  return Promise.reject(new ModuleError("bad_request", "Invalid account"));
8643
- const configDir = join19(o.cwHome, "accounts", input.account);
8644
- if (!existsSync16(configDir))
8873
+ const configDir = join20(o.cwHome, "accounts", input.account);
8874
+ if (!existsSync17(configDir))
8645
8875
  return Promise.reject(new ModuleError("not_found", `Unknown account ${input.account}`));
8646
8876
  const bad = input.allowedTools.find((tool) => !tool.startsWith("mcp__"));
8647
8877
  if (bad !== void 0)
@@ -8653,10 +8883,10 @@ function runAgent(input, o) {
8653
8883
  args.push("--allowedTools", input.allowedTools.join(","), "--output-format", "json");
8654
8884
  const spawn9 = o.spawn ?? nodeSpawn;
8655
8885
  const timeoutMs = input.timeoutMs ?? DEFAULT_TIMEOUT_MS;
8656
- const cwd = mkdtempSync2(join19(tmpdir2(), "forge-agent-"));
8886
+ const cwd = mkdtempSync2(join20(tmpdir2(), "forge-agent-"));
8657
8887
  const cleanup = () => rmSync4(cwd, { recursive: true, force: true });
8658
8888
  return new Promise((resolve11, reject) => {
8659
- const child = spawn9("claude", args, { cwd, env: { ...envWithoutHarness(), CLAUDE_CONFIG_DIR: configDir, ...CONNECTOR_ENV }, stdio: ["pipe", "pipe", "pipe"] });
8889
+ const child = spawn9("claude", args, { cwd, env: { ...envForAgent(), CLAUDE_CONFIG_DIR: configDir, ...CONNECTOR_ENV }, stdio: ["pipe", "pipe", "pipe"] });
8660
8890
  child.stdin?.on("error", () => {
8661
8891
  });
8662
8892
  child.stdin?.end(input.prompt);
@@ -8843,15 +9073,40 @@ var init_module_events = __esm({
8843
9073
  // ../core/dist/server.js
8844
9074
  import { Hono as Hono6 } from "hono";
8845
9075
  import { cors } from "hono/cors";
8846
- import { join as join20, basename as basename5, resolve as resolve10 } from "node:path";
8847
- import { readdirSync as readdirSync8, existsSync as existsSync17 } from "node:fs";
9076
+ import { join as join21, basename as basename5, resolve as resolve10 } from "node:path";
9077
+ import { readdirSync as readdirSync8, existsSync as existsSync18 } from "node:fs";
9078
+ function parseHookEvent(raw) {
9079
+ let body2 = {};
9080
+ if (raw.length <= HOOK_BODY_MAX) {
9081
+ try {
9082
+ const parsed = JSON.parse(raw);
9083
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
9084
+ return null;
9085
+ body2 = parsed;
9086
+ } catch {
9087
+ return null;
9088
+ }
9089
+ } else {
9090
+ const head = raw.slice(0, 8192);
9091
+ for (const field of ["hook_event_name", "session_id", "source", "notification_type"]) {
9092
+ const m = new RegExp(`"${field}"\\s*:\\s*"([^"\\\\]{1,${HOOK_FIELD_MAX}})"`).exec(head);
9093
+ if (m)
9094
+ body2[field] = m[1];
9095
+ }
9096
+ }
9097
+ const text2 = (value) => typeof value === "string" && value.length > 0 && value.length <= HOOK_FIELD_MAX ? value : void 0;
9098
+ const name = text2(body2.hook_event_name);
9099
+ if (!name)
9100
+ return null;
9101
+ return { name, sessionId: text2(body2.session_id), source: text2(body2.source), notificationType: text2(body2.notification_type) };
9102
+ }
8848
9103
  function createForgeServer(options) {
8849
9104
  const { dataDir, db: externalDb, authToken, localOnly = true } = options;
8850
9105
  const authProblem = remoteAuthProblem(localOnly, authToken);
8851
9106
  if (authProblem)
8852
9107
  throw new Error(authProblem);
8853
- const dbPath = join20(dataDir, "forge.db");
8854
- const modulesDir = join20(dataDir, "modules");
9108
+ const dbPath = join21(dataDir, "forge.db");
9109
+ const modulesDir = join21(dataDir, "modules");
8855
9110
  const db = externalDb ?? new ForgeDB(dbPath);
8856
9111
  const loader = new ModuleLoader(modulesDir, options.bundledModulesDir);
8857
9112
  const runner = new ActionRunner();
@@ -8868,10 +9123,10 @@ function createForgeServer(options) {
8868
9123
  mountAuthRoute(app, authToken);
8869
9124
  }
8870
9125
  const cwReader = new CWReader(options.cwDir);
8871
- const generalSessions = new GeneralSessions(join20(dataDir, "general-sessions.json"));
9126
+ const generalSessions = new GeneralSessions(join21(dataDir, "general-sessions.json"));
8872
9127
  const loginManager = new LoginManager(resolveCwBin(cwReader.cwHome));
8873
9128
  app.route("/api/cw", cwRoutes(cwReader, { loginManager, localOnly, general: generalSessions, killSession: (key) => ptyManager.kill(key), events: { emit: (name, payload) => moduleEvents.emit(name, payload) } }));
8874
- app.route("/api/skills", skillRoutes(cwReader, { backupDir: join20(dataDir, "skill-backups") }));
9129
+ app.route("/api/skills", skillRoutes(cwReader, { backupDir: join21(dataDir, "skill-backups") }));
8875
9130
  const { remote, shadow, warning } = remoteClassifierFromEnv();
8876
9131
  if (warning)
8877
9132
  console.warn(`[state] ${warning}`);
@@ -8890,7 +9145,8 @@ function createForgeServer(options) {
8890
9145
  lastStateError = err.message;
8891
9146
  }
8892
9147
  });
8893
- const ptyManager = new PTYManager(states);
9148
+ const hooks = new ClaudeHooks({ dir: join21(dataDir, "hooks"), cwHome: cwReader.cwHome, warn: (message2) => console.warn(message2) });
9149
+ const ptyManager = new PTYManager(states, hooks);
8894
9150
  const terminalWss = createTerminalWss(ptyManager, cwReader, { localOnly, authToken, general: generalSessions });
8895
9151
  app.route("/api/liveframe", liveframeRoutes());
8896
9152
  const kioku = new Kioku({ projects: () => cwReader.getProjects(), pluginInstalls: () => installsOf(cwReader, "kioku") });
@@ -8924,7 +9180,7 @@ function createForgeServer(options) {
8924
9180
  modulesDir,
8925
9181
  bundledDir: options.bundledModulesDir,
8926
9182
  forgeNodeModules: options.forgeNodeModules,
8927
- devFile: join20(dataDir, "dev-modules.json"),
9183
+ devFile: join21(dataDir, "dev-modules.json"),
8928
9184
  localOnly,
8929
9185
  deps: {
8930
9186
  db,
@@ -8964,6 +9220,21 @@ function createForgeServer(options) {
8964
9220
  const installer = localOnly ? new ModuleInstaller({ modulesDir, host: moduleHost, run: createRunner(void 0, 5 * 6e4) }) : void 0;
8965
9221
  app.route("/api/modules", moduleRoutes(moduleHost, { db, ready: modulesReady, installer }));
8966
9222
  app.get("/api/cw/session-states", (c) => c.json({ classifier: states.remoteName ?? "local", shadow: states.isShadow, states: states.snapshot() }));
9223
+ app.post(HOOK_PATH, async (c) => {
9224
+ let key = "";
9225
+ try {
9226
+ key = decodeURIComponent(c.req.header(SESSION_HEADER) ?? "");
9227
+ } catch {
9228
+ }
9229
+ if (!hooks.verify(key, c.req.header(TOKEN_HEADER)))
9230
+ return c.json({ error: "Unauthorized" }, 401);
9231
+ const raw = await c.req.text();
9232
+ const event = parseHookEvent(raw);
9233
+ if (!event)
9234
+ return c.json({ error: "A JSON object with hook_event_name is required" }, 400);
9235
+ states.hookEvent(key, event);
9236
+ return c.body(null, 204);
9237
+ });
8967
9238
  app.post("/api/cw/terminal/kill", async (c) => {
8968
9239
  const { project, sessionDir } = await c.req.json();
8969
9240
  const sessionId = `${project}::${sessionDir}`;
@@ -9109,21 +9380,21 @@ data: ${JSON.stringify(data)}
9109
9380
  if (!dir.startsWith(home)) {
9110
9381
  return c.json({ error: "Access denied: path must be within home directory" }, 403);
9111
9382
  }
9112
- if (!existsSync17(dir)) {
9383
+ if (!existsSync18(dir)) {
9113
9384
  return c.json({ error: "Directory not found" }, 404);
9114
9385
  }
9115
9386
  try {
9116
9387
  const entries = readdirSync8(dir, { withFileTypes: true });
9117
9388
  const dirs = entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => ({
9118
9389
  name: e.name,
9119
- path: join20(dir, e.name),
9120
- hasPackageJson: existsSync17(join20(dir, e.name, "package.json")),
9121
- hasGit: existsSync17(join20(dir, e.name, ".git"))
9390
+ path: join21(dir, e.name),
9391
+ hasPackageJson: existsSync18(join21(dir, e.name, "package.json")),
9392
+ hasGit: existsSync18(join21(dir, e.name, ".git"))
9122
9393
  })).sort((a, b) => a.name.localeCompare(b.name));
9123
9394
  return c.json({
9124
9395
  current: dir,
9125
9396
  name: basename5(dir),
9126
- parent: join20(dir, ".."),
9397
+ parent: join21(dir, ".."),
9127
9398
  directories: dirs
9128
9399
  });
9129
9400
  } catch {
@@ -9137,6 +9408,9 @@ data: ${JSON.stringify(data)}
9137
9408
  app,
9138
9409
  fetch: fetch2,
9139
9410
  attachTerminalWs: (server) => terminalWss.attachToServer(server),
9411
+ // the hook settings carry the port, so they are written once the server listens
9412
+ listening: (port, host) => hooks.listen(port, host),
9413
+ hooks,
9140
9414
  modulesReady,
9141
9415
  close: () => {
9142
9416
  moduleHost.close();
@@ -9148,6 +9422,7 @@ data: ${JSON.stringify(data)}
9148
9422
  }
9149
9423
  };
9150
9424
  }
9425
+ var HOOK_BODY_MAX, HOOK_FIELD_MAX;
9151
9426
  var init_server = __esm({
9152
9427
  "../core/dist/server.js"() {
9153
9428
  "use strict";
@@ -9163,6 +9438,7 @@ var init_server = __esm({
9163
9438
  init_pty_manager();
9164
9439
  init_session_state();
9165
9440
  init_state_log();
9441
+ init_claude_hooks();
9166
9442
  init_pty_routes();
9167
9443
  init_login_manager();
9168
9444
  init_general_sessions();
@@ -9178,6 +9454,8 @@ var init_server = __esm({
9178
9454
  init_module_events();
9179
9455
  init_kioku();
9180
9456
  init_plugins();
9457
+ HOOK_BODY_MAX = 256 * 1024;
9458
+ HOOK_FIELD_MAX = 200;
9181
9459
  }
9182
9460
  });
9183
9461
 
@@ -9330,8 +9608,8 @@ async function createDatabase(opts) {
9330
9608
  await db.migrate();
9331
9609
  return db;
9332
9610
  }
9333
- const { join: join24 } = await import("node:path");
9334
- return new ForgeDB(join24(opts.dataDir, "forge.db"));
9611
+ const { join: join25 } = await import("node:path");
9612
+ return new ForgeDB(join25(opts.dataDir, "forge.db"));
9335
9613
  }
9336
9614
  var init_db_factory = __esm({
9337
9615
  "../core/dist/db-factory.js"() {
@@ -9341,22 +9619,22 @@ var init_db_factory = __esm({
9341
9619
  });
9342
9620
 
9343
9621
  // ../core/dist/init.js
9344
- import { existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync7 } from "node:fs";
9345
- import { join as join21 } from "node:path";
9622
+ import { existsSync as existsSync19, mkdirSync as mkdirSync8, writeFileSync as writeFileSync8 } from "node:fs";
9623
+ import { join as join22 } from "node:path";
9346
9624
  import { homedir as homedir8 } from "node:os";
9347
9625
  function getForgeDir() {
9348
- return join21(homedir8(), ".forge");
9626
+ return join22(homedir8(), ".forge");
9349
9627
  }
9350
9628
  function ensureForgeDir() {
9351
9629
  const forgeDir = getForgeDir();
9352
- if (existsSync18(forgeDir)) {
9630
+ if (existsSync19(forgeDir)) {
9353
9631
  return { forgeDir, created: false };
9354
9632
  }
9355
- mkdirSync7(forgeDir, { recursive: true });
9633
+ mkdirSync8(forgeDir, { recursive: true });
9356
9634
  for (const d of FORGE_SUBDIRS) {
9357
- mkdirSync7(join21(forgeDir, d), { recursive: true });
9635
+ mkdirSync8(join22(forgeDir, d), { recursive: true });
9358
9636
  }
9359
- writeFileSync7(join21(forgeDir, "config.json"), JSON.stringify({
9637
+ writeFileSync8(join22(forgeDir, "config.json"), JSON.stringify({
9360
9638
  port: 3e3,
9361
9639
  theme: "dark",
9362
9640
  openBrowser: true,
@@ -9419,8 +9697,8 @@ var init_port_in_use = __esm({
9419
9697
  });
9420
9698
 
9421
9699
  // ../core/dist/start.js
9422
- import { existsSync as existsSync19, readFileSync as readFileSync13 } from "node:fs";
9423
- import { join as join22 } from "node:path";
9700
+ import { existsSync as existsSync20, readFileSync as readFileSync14 } from "node:fs";
9701
+ import { join as join23 } from "node:path";
9424
9702
  async function startForge(options) {
9425
9703
  const { port, version, consoleDist: consoleDist2, bundledModulesDir: bundledModulesDir2, databaseUrl, authToken, fallbackToFreePort = false } = options;
9426
9704
  const { forgeDir } = ensureForgeDir();
@@ -9440,10 +9718,10 @@ async function startForge(options) {
9440
9718
  bundledModulesDir: bundledModulesDir2,
9441
9719
  version
9442
9720
  });
9443
- if (consoleDist2 && existsSync19(join22(consoleDist2, "index.html"))) {
9721
+ if (consoleDist2 && existsSync20(join23(consoleDist2, "index.html"))) {
9444
9722
  const { serveStatic } = await import("@hono/node-server/serve-static");
9445
9723
  server.app.use("/*", serveStatic({ root: consoleDist2 }));
9446
- const indexHtml = readFileSync13(join22(consoleDist2, "index.html"), "utf-8");
9724
+ const indexHtml = readFileSync14(join23(consoleDist2, "index.html"), "utf-8");
9447
9725
  server.app.get("*", (c) => c.html(indexHtml));
9448
9726
  }
9449
9727
  const { serve } = await import("@hono/node-server");
@@ -9470,6 +9748,7 @@ async function startForge(options) {
9470
9748
  server.attachTerminalWs(httpServer);
9471
9749
  const address = httpServer.address();
9472
9750
  const actualPort = typeof address === "object" && address ? address.port : port;
9751
+ server.listening(actualPort, typeof address === "object" && address ? address.address : host);
9473
9752
  return {
9474
9753
  status: "listening",
9475
9754
  url: `http://localhost:${actualPort}`,
@@ -9574,9 +9853,9 @@ var init_dist2 = __esm({
9574
9853
  });
9575
9854
 
9576
9855
  // src/index.ts
9577
- import { existsSync as existsSync20, readFileSync as readFileSync14 } from "node:fs";
9856
+ import { existsSync as existsSync21, readFileSync as readFileSync15 } from "node:fs";
9578
9857
  import { homedir as homedir9 } from "node:os";
9579
- import { join as join23 } from "node:path";
9858
+ import { join as join24 } from "node:path";
9580
9859
  function parseArgs(argv) {
9581
9860
  const out = { open: true };
9582
9861
  for (let i = 0; i < argv.length; i++) {
@@ -9587,11 +9866,11 @@ function parseArgs(argv) {
9587
9866
  }
9588
9867
  return out;
9589
9868
  }
9590
- var packageRoot = join23(import.meta.dirname, "..");
9591
- var isCheckout = existsSync20(join23(packageRoot, "src"));
9592
- var consoleDist = isCheckout ? join23(packageRoot, "../console/dist") : join23(packageRoot, "console");
9593
- var forgeVersion = JSON.parse(readFileSync14(join23(packageRoot, "package.json"), "utf-8")).version;
9594
- var bundledModulesDir = isCheckout ? join23(packageRoot, "../../modules") : join23(packageRoot, "modules");
9869
+ var packageRoot = join24(import.meta.dirname, "..");
9870
+ var isCheckout = existsSync21(join24(packageRoot, "src"));
9871
+ var consoleDist = isCheckout ? join24(packageRoot, "../console/dist") : join24(packageRoot, "console");
9872
+ var forgeVersion = JSON.parse(readFileSync15(join24(packageRoot, "package.json"), "utf-8")).version;
9873
+ var bundledModulesDir = isCheckout ? join24(packageRoot, "../../modules") : join24(packageRoot, "modules");
9595
9874
  async function main() {
9596
9875
  const { ensureForgeDir: ensureForgeDir2, startForge: startForge2, ensureCw: ensureCw2, pathWithCw: pathWithCw2, quietSqliteWarning: quietSqliteWarning2, portInUseMessage: portInUseMessage2 } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
9597
9876
  quietSqliteWarning2();
@@ -9600,8 +9879,8 @@ async function main() {
9600
9879
  if (created) {
9601
9880
  console.log("First run \u2014 initialized Forge.");
9602
9881
  }
9603
- const cwHome = join23(process.env.HOME ?? homedir9(), ".cw");
9604
- const cw = isCheckout ? { action: "skipped", message: "a checkout does not install CW" } : await ensureCw2({ cwHome, bundleDir: join23(packageRoot, "cw") });
9882
+ const cwHome = join24(process.env.HOME ?? homedir9(), ".cw");
9883
+ const cw = isCheckout ? { action: "skipped", message: "a checkout does not install CW" } : await ensureCw2({ cwHome, bundleDir: join24(packageRoot, "cw") });
9605
9884
  if (cw.action === "installed") console.log(` Installed CW ${cw.version} in ${cwHome}`);
9606
9885
  else if (cw.action === "updated") console.log(` Updated ${cw.message}`);
9607
9886
  else if (cw.action === "failed") console.log(` Could not install CW: ${cw.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forge-cw",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
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",
@@ -40,8 +40,8 @@
40
40
  "@types/node": "^22.0.0",
41
41
  "esbuild": "^0.25.0",
42
42
  "typescript": "^5.8.0",
43
- "@forge-dev/console": "0.1.0",
44
- "@forge-dev/core": "0.1.0"
43
+ "@forge-dev/core": "0.1.0",
44
+ "@forge-dev/console": "0.1.0"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "tsc",