@node9/proxy 1.1.2 → 1.1.4

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 (3) hide show
  1. package/dist/cli.js +63 -23
  2. package/dist/cli.mjs +63 -23
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -4297,6 +4297,19 @@ data: ${JSON.stringify({
4297
4297
  data: ${JSON.stringify(readPersistentDecisions())}
4298
4298
 
4299
4299
  `);
4300
+ const activeShields = readActiveShields();
4301
+ res.write(
4302
+ `event: shields-status
4303
+ data: ${JSON.stringify({
4304
+ shields: Object.values(SHIELDS).map((s) => ({
4305
+ name: s.name,
4306
+ description: s.description,
4307
+ active: activeShields.includes(s.name)
4308
+ }))
4309
+ })}
4310
+
4311
+ `
4312
+ );
4300
4313
  for (const item of activityRing) {
4301
4314
  res.write(`event: ${item.event}
4302
4315
  data: ${JSON.stringify(item.data)}
@@ -4502,9 +4515,15 @@ data: ${JSON.stringify(item.data)}
4502
4515
  }
4503
4516
  }
4504
4517
  if (req.method === "GET" && pathname === "/settings") {
4505
- const s = getGlobalSettings();
4506
- res.writeHead(200, { "Content-Type": "application/json" });
4507
- return res.end(JSON.stringify({ ...s, autoStarted }));
4518
+ try {
4519
+ const s = getGlobalSettings();
4520
+ res.writeHead(200, { "Content-Type": "application/json" });
4521
+ return res.end(JSON.stringify({ ...s, autoStarted }));
4522
+ } catch (err) {
4523
+ console.error(import_chalk4.default.red("[node9 daemon] GET /settings failed:"), err);
4524
+ res.writeHead(500, { "Content-Type": "application/json" });
4525
+ return res.end(JSON.stringify({ error: "internal" }));
4526
+ }
4508
4527
  }
4509
4528
  if (req.method === "POST" && pathname === "/settings") {
4510
4529
  if (!validToken(req)) return res.writeHead(403).end();
@@ -4527,9 +4546,15 @@ data: ${JSON.stringify(item.data)}
4527
4546
  }
4528
4547
  }
4529
4548
  if (req.method === "GET" && pathname === "/slack-status") {
4530
- const s = getGlobalSettings();
4531
- res.writeHead(200, { "Content-Type": "application/json" });
4532
- return res.end(JSON.stringify({ hasKey: hasStoredSlackKey(), enabled: s.slackEnabled }));
4549
+ try {
4550
+ const s = getGlobalSettings();
4551
+ res.writeHead(200, { "Content-Type": "application/json" });
4552
+ return res.end(JSON.stringify({ hasKey: hasStoredSlackKey(), enabled: s.slackEnabled }));
4553
+ } catch (err) {
4554
+ console.error(import_chalk4.default.red("[node9 daemon] GET /slack-status failed:"), err);
4555
+ res.writeHead(500, { "Content-Type": "application/json" });
4556
+ return res.end(JSON.stringify({ error: "internal" }));
4557
+ }
4533
4558
  }
4534
4559
  if (req.method === "POST" && pathname === "/slack-key") {
4535
4560
  if (!validToken(req)) return res.writeHead(403).end();
@@ -4678,6 +4703,13 @@ data: ${JSON.stringify(item.data)}
4678
4703
  console.error(import_chalk4.default.red("\n\u{1F6D1} Node9 Daemon Error:"), e.message);
4679
4704
  process.exit(1);
4680
4705
  });
4706
+ if (!daemonRejectionHandlerRegistered) {
4707
+ daemonRejectionHandlerRegistered = true;
4708
+ process.on("unhandledRejection", (reason) => {
4709
+ const stack = reason instanceof Error ? reason.stack : String(reason);
4710
+ console.error(import_chalk4.default.red("[node9 daemon] unhandled rejection \u2014 keeping daemon alive:"), stack);
4711
+ });
4712
+ }
4681
4713
  server.listen(DAEMON_PORT2, DAEMON_HOST2, () => {
4682
4714
  atomicWriteSync2(
4683
4715
  DAEMON_PID_FILE,
@@ -4774,7 +4806,7 @@ function daemonStatus() {
4774
4806
  console.log(import_chalk4.default.yellow("Node9 daemon: not running"));
4775
4807
  }
4776
4808
  }
4777
- var import_http, import_net2, import_fs5, import_path7, import_os4, import_child_process3, import_crypto3, import_chalk4, ACTIVITY_SOCKET_PATH2, DAEMON_PORT2, DAEMON_HOST2, homeDir, DAEMON_PID_FILE, DECISIONS_FILE, GLOBAL_CONFIG_FILE, CREDENTIALS_FILE, AUDIT_LOG_FILE, TRUST_FILE2, TRUST_DURATIONS, SECRET_KEY_RE, AUTO_DENY_MS, autoStarted, pending, sseClients, abandonTimer, daemonServer, hadBrowserClient, ACTIVITY_RING_SIZE, activityRing;
4809
+ var import_http, import_net2, import_fs5, import_path7, import_os4, import_child_process3, import_crypto3, import_chalk4, daemonRejectionHandlerRegistered, ACTIVITY_SOCKET_PATH2, DAEMON_PORT2, DAEMON_HOST2, homeDir, DAEMON_PID_FILE, DECISIONS_FILE, GLOBAL_CONFIG_FILE, CREDENTIALS_FILE, AUDIT_LOG_FILE, TRUST_FILE2, TRUST_DURATIONS, SECRET_KEY_RE, AUTO_DENY_MS, autoStarted, pending, sseClients, abandonTimer, daemonServer, hadBrowserClient, ACTIVITY_RING_SIZE, activityRing;
4778
4810
  var init_daemon = __esm({
4779
4811
  "src/daemon/index.ts"() {
4780
4812
  "use strict";
@@ -4789,6 +4821,7 @@ var init_daemon = __esm({
4789
4821
  import_chalk4 = __toESM(require("chalk"));
4790
4822
  init_core();
4791
4823
  init_shields();
4824
+ daemonRejectionHandlerRegistered = false;
4792
4825
  ACTIVITY_SOCKET_PATH2 = process.platform === "win32" ? "\\\\.\\pipe\\node9-activity" : import_path7.default.join(import_os4.default.tmpdir(), "node9-activity.sock");
4793
4826
  DAEMON_PORT2 = 7391;
4794
4827
  DAEMON_HOST2 = "127.0.0.1";
@@ -6696,9 +6729,9 @@ var HOOK_BASED_AGENTS = {
6696
6729
  };
6697
6730
  program.argument("[command...]", "The agent command to run (e.g., gemini)").action(async (commandArgs) => {
6698
6731
  if (commandArgs && commandArgs.length > 0) {
6699
- const firstArg = commandArgs[0].toLowerCase();
6700
- if (HOOK_BASED_AGENTS[firstArg] !== void 0) {
6701
- const target = HOOK_BASED_AGENTS[firstArg];
6732
+ const firstArg2 = commandArgs[0].toLowerCase();
6733
+ if (HOOK_BASED_AGENTS[firstArg2] !== void 0) {
6734
+ const target = HOOK_BASED_AGENTS[firstArg2];
6702
6735
  console.error(
6703
6736
  import_chalk6.default.yellow(`
6704
6737
  \u26A0\uFE0F Node9 proxy mode does not support "${target}" directly.`)
@@ -6911,19 +6944,26 @@ shieldCmd.command("status").description("Show which shields are currently active
6911
6944
  }
6912
6945
  console.log("");
6913
6946
  });
6914
- process.on("unhandledRejection", (reason) => {
6915
- const isCheckHook = process.argv[2] === "check";
6916
- if (isCheckHook) {
6917
- if (process.env.NODE9_DEBUG === "1" || getConfig().settings.enableHookLogDebug) {
6918
- const logPath = import_path10.default.join(import_os7.default.homedir(), ".node9", "hook-debug.log");
6919
- const msg = reason instanceof Error ? reason.message : String(reason);
6920
- import_fs8.default.appendFileSync(logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] UNHANDLED: ${msg}
6947
+ if (process.argv[2] !== "daemon") {
6948
+ process.on("unhandledRejection", (reason) => {
6949
+ const isCheckHook = process.argv[2] === "check";
6950
+ if (isCheckHook) {
6951
+ if (process.env.NODE9_DEBUG === "1" || getConfig().settings.enableHookLogDebug) {
6952
+ const logPath = import_path10.default.join(import_os7.default.homedir(), ".node9", "hook-debug.log");
6953
+ const msg = reason instanceof Error ? reason.message : String(reason);
6954
+ import_fs8.default.appendFileSync(logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] UNHANDLED: ${msg}
6921
6955
  `);
6956
+ }
6957
+ process.exit(0);
6958
+ } else {
6959
+ console.error("[Node9] Unhandled error:", reason);
6960
+ process.exit(1);
6922
6961
  }
6923
- process.exit(0);
6924
- } else {
6925
- console.error("[Node9] Unhandled error:", reason);
6926
- process.exit(1);
6927
- }
6928
- });
6962
+ });
6963
+ }
6964
+ var knownSubcommands = new Set(program.commands.map((c) => c.name()));
6965
+ var firstArg = process.argv[2];
6966
+ if (firstArg && firstArg !== "--" && !firstArg.startsWith("-") && !knownSubcommands.has(firstArg)) {
6967
+ process.argv.splice(2, 0, "--");
6968
+ }
6929
6969
  program.parse();
package/dist/cli.mjs CHANGED
@@ -4284,6 +4284,19 @@ data: ${JSON.stringify({
4284
4284
  data: ${JSON.stringify(readPersistentDecisions())}
4285
4285
 
4286
4286
  `);
4287
+ const activeShields = readActiveShields();
4288
+ res.write(
4289
+ `event: shields-status
4290
+ data: ${JSON.stringify({
4291
+ shields: Object.values(SHIELDS).map((s) => ({
4292
+ name: s.name,
4293
+ description: s.description,
4294
+ active: activeShields.includes(s.name)
4295
+ }))
4296
+ })}
4297
+
4298
+ `
4299
+ );
4287
4300
  for (const item of activityRing) {
4288
4301
  res.write(`event: ${item.event}
4289
4302
  data: ${JSON.stringify(item.data)}
@@ -4489,9 +4502,15 @@ data: ${JSON.stringify(item.data)}
4489
4502
  }
4490
4503
  }
4491
4504
  if (req.method === "GET" && pathname === "/settings") {
4492
- const s = getGlobalSettings();
4493
- res.writeHead(200, { "Content-Type": "application/json" });
4494
- return res.end(JSON.stringify({ ...s, autoStarted }));
4505
+ try {
4506
+ const s = getGlobalSettings();
4507
+ res.writeHead(200, { "Content-Type": "application/json" });
4508
+ return res.end(JSON.stringify({ ...s, autoStarted }));
4509
+ } catch (err) {
4510
+ console.error(chalk4.red("[node9 daemon] GET /settings failed:"), err);
4511
+ res.writeHead(500, { "Content-Type": "application/json" });
4512
+ return res.end(JSON.stringify({ error: "internal" }));
4513
+ }
4495
4514
  }
4496
4515
  if (req.method === "POST" && pathname === "/settings") {
4497
4516
  if (!validToken(req)) return res.writeHead(403).end();
@@ -4514,9 +4533,15 @@ data: ${JSON.stringify(item.data)}
4514
4533
  }
4515
4534
  }
4516
4535
  if (req.method === "GET" && pathname === "/slack-status") {
4517
- const s = getGlobalSettings();
4518
- res.writeHead(200, { "Content-Type": "application/json" });
4519
- return res.end(JSON.stringify({ hasKey: hasStoredSlackKey(), enabled: s.slackEnabled }));
4536
+ try {
4537
+ const s = getGlobalSettings();
4538
+ res.writeHead(200, { "Content-Type": "application/json" });
4539
+ return res.end(JSON.stringify({ hasKey: hasStoredSlackKey(), enabled: s.slackEnabled }));
4540
+ } catch (err) {
4541
+ console.error(chalk4.red("[node9 daemon] GET /slack-status failed:"), err);
4542
+ res.writeHead(500, { "Content-Type": "application/json" });
4543
+ return res.end(JSON.stringify({ error: "internal" }));
4544
+ }
4520
4545
  }
4521
4546
  if (req.method === "POST" && pathname === "/slack-key") {
4522
4547
  if (!validToken(req)) return res.writeHead(403).end();
@@ -4665,6 +4690,13 @@ data: ${JSON.stringify(item.data)}
4665
4690
  console.error(chalk4.red("\n\u{1F6D1} Node9 Daemon Error:"), e.message);
4666
4691
  process.exit(1);
4667
4692
  });
4693
+ if (!daemonRejectionHandlerRegistered) {
4694
+ daemonRejectionHandlerRegistered = true;
4695
+ process.on("unhandledRejection", (reason) => {
4696
+ const stack = reason instanceof Error ? reason.stack : String(reason);
4697
+ console.error(chalk4.red("[node9 daemon] unhandled rejection \u2014 keeping daemon alive:"), stack);
4698
+ });
4699
+ }
4668
4700
  server.listen(DAEMON_PORT2, DAEMON_HOST2, () => {
4669
4701
  atomicWriteSync2(
4670
4702
  DAEMON_PID_FILE,
@@ -4761,13 +4793,14 @@ function daemonStatus() {
4761
4793
  console.log(chalk4.yellow("Node9 daemon: not running"));
4762
4794
  }
4763
4795
  }
4764
- var ACTIVITY_SOCKET_PATH2, DAEMON_PORT2, DAEMON_HOST2, homeDir, DAEMON_PID_FILE, DECISIONS_FILE, GLOBAL_CONFIG_FILE, CREDENTIALS_FILE, AUDIT_LOG_FILE, TRUST_FILE2, TRUST_DURATIONS, SECRET_KEY_RE, AUTO_DENY_MS, autoStarted, pending, sseClients, abandonTimer, daemonServer, hadBrowserClient, ACTIVITY_RING_SIZE, activityRing;
4796
+ var daemonRejectionHandlerRegistered, ACTIVITY_SOCKET_PATH2, DAEMON_PORT2, DAEMON_HOST2, homeDir, DAEMON_PID_FILE, DECISIONS_FILE, GLOBAL_CONFIG_FILE, CREDENTIALS_FILE, AUDIT_LOG_FILE, TRUST_FILE2, TRUST_DURATIONS, SECRET_KEY_RE, AUTO_DENY_MS, autoStarted, pending, sseClients, abandonTimer, daemonServer, hadBrowserClient, ACTIVITY_RING_SIZE, activityRing;
4765
4797
  var init_daemon = __esm({
4766
4798
  "src/daemon/index.ts"() {
4767
4799
  "use strict";
4768
4800
  init_ui2();
4769
4801
  init_core();
4770
4802
  init_shields();
4803
+ daemonRejectionHandlerRegistered = false;
4771
4804
  ACTIVITY_SOCKET_PATH2 = process.platform === "win32" ? "\\\\.\\pipe\\node9-activity" : path7.join(os4.tmpdir(), "node9-activity.sock");
4772
4805
  DAEMON_PORT2 = 7391;
4773
4806
  DAEMON_HOST2 = "127.0.0.1";
@@ -6675,9 +6708,9 @@ var HOOK_BASED_AGENTS = {
6675
6708
  };
6676
6709
  program.argument("[command...]", "The agent command to run (e.g., gemini)").action(async (commandArgs) => {
6677
6710
  if (commandArgs && commandArgs.length > 0) {
6678
- const firstArg = commandArgs[0].toLowerCase();
6679
- if (HOOK_BASED_AGENTS[firstArg] !== void 0) {
6680
- const target = HOOK_BASED_AGENTS[firstArg];
6711
+ const firstArg2 = commandArgs[0].toLowerCase();
6712
+ if (HOOK_BASED_AGENTS[firstArg2] !== void 0) {
6713
+ const target = HOOK_BASED_AGENTS[firstArg2];
6681
6714
  console.error(
6682
6715
  chalk6.yellow(`
6683
6716
  \u26A0\uFE0F Node9 proxy mode does not support "${target}" directly.`)
@@ -6890,19 +6923,26 @@ shieldCmd.command("status").description("Show which shields are currently active
6890
6923
  }
6891
6924
  console.log("");
6892
6925
  });
6893
- process.on("unhandledRejection", (reason) => {
6894
- const isCheckHook = process.argv[2] === "check";
6895
- if (isCheckHook) {
6896
- if (process.env.NODE9_DEBUG === "1" || getConfig().settings.enableHookLogDebug) {
6897
- const logPath = path10.join(os7.homedir(), ".node9", "hook-debug.log");
6898
- const msg = reason instanceof Error ? reason.message : String(reason);
6899
- fs8.appendFileSync(logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] UNHANDLED: ${msg}
6926
+ if (process.argv[2] !== "daemon") {
6927
+ process.on("unhandledRejection", (reason) => {
6928
+ const isCheckHook = process.argv[2] === "check";
6929
+ if (isCheckHook) {
6930
+ if (process.env.NODE9_DEBUG === "1" || getConfig().settings.enableHookLogDebug) {
6931
+ const logPath = path10.join(os7.homedir(), ".node9", "hook-debug.log");
6932
+ const msg = reason instanceof Error ? reason.message : String(reason);
6933
+ fs8.appendFileSync(logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] UNHANDLED: ${msg}
6900
6934
  `);
6935
+ }
6936
+ process.exit(0);
6937
+ } else {
6938
+ console.error("[Node9] Unhandled error:", reason);
6939
+ process.exit(1);
6901
6940
  }
6902
- process.exit(0);
6903
- } else {
6904
- console.error("[Node9] Unhandled error:", reason);
6905
- process.exit(1);
6906
- }
6907
- });
6941
+ });
6942
+ }
6943
+ var knownSubcommands = new Set(program.commands.map((c) => c.name()));
6944
+ var firstArg = process.argv[2];
6945
+ if (firstArg && firstArg !== "--" && !firstArg.startsWith("-") && !knownSubcommands.has(firstArg)) {
6946
+ process.argv.splice(2, 0, "--");
6947
+ }
6908
6948
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node9/proxy",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "The Sudo Command for AI Agents. Execution Security for Claude Code & MCP.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",