@solongate/proxy 0.81.62 → 0.81.64

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.
@@ -53,3 +53,9 @@
53
53
  {"ms":2,"ts":1784367428790,"tool":"Bash","session":"f5933c65-c315-4440-9afb-7136fce6b695"}
54
54
  {"ms":3,"ts":1784369708978,"tool":"Write","session":"f5933c65-c315-4440-9afb-7136fce6b695"}
55
55
  {"ms":4,"ts":1784369720104,"tool":"Bash","session":"f5933c65-c315-4440-9afb-7136fce6b695"}
56
+ {"ms":4,"ts":1784374757475,"tool":"Bash","session":"f5933c65-c315-4440-9afb-7136fce6b695"}
57
+ {"ms":2,"ts":1784374762962,"tool":"Bash","session":"f5933c65-c315-4440-9afb-7136fce6b695"}
58
+ {"ms":4,"ts":1784374792946,"tool":"Write","session":"f5933c65-c315-4440-9afb-7136fce6b695"}
59
+ {"ms":4,"ts":1784374838495,"tool":"Write","session":"f5933c65-c315-4440-9afb-7136fce6b695"}
60
+ {"ms":3,"ts":1784374848281,"tool":"Bash","session":"f5933c65-c315-4440-9afb-7136fce6b695"}
61
+ {"ms":4,"ts":1784375224287,"tool":"Bash","session":"f5933c65-c315-4440-9afb-7136fce6b695"}
@@ -1 +1 @@
1
- {"ms":4,"ts":1784369720104,"tool":"Bash","session":"f5933c65-c315-4440-9afb-7136fce6b695"}
1
+ {"ms":4,"ts":1784375224287,"tool":"Bash","session":"f5933c65-c315-4440-9afb-7136fce6b695"}
@@ -1 +1 @@
1
- 1784369709035
1
+ 1784375211122
@@ -6536,7 +6536,7 @@ import { resolve, join, dirname, isAbsolute } from "node:path";
6536
6536
  import { homedir } from "node:os";
6537
6537
  import { gunzipSync } from "node:zlib";
6538
6538
  import { createHash } from "node:crypto";
6539
- var HOOK_VERSION = 36;
6539
+ var HOOK_VERSION = 38;
6540
6540
  function localLogsOnly(security) {
6541
6541
  if (security && typeof security === "object") {
6542
6542
  const l = security.localLogs;
@@ -6590,7 +6590,23 @@ function writeLocalLog(security, entry) {
6590
6590
  mkdirSync(dir, { recursive: true });
6591
6591
  } catch {
6592
6592
  }
6593
- appendFileSync(join(dir, "solongate-audit.jsonl"), JSON.stringify(entry) + "\n");
6593
+ const file = join(dir, "solongate-audit.jsonl");
6594
+ const line = JSON.stringify(entry) + "\n";
6595
+ for (let attempt = 0; attempt < 12; attempt++) {
6596
+ try {
6597
+ appendFileSync(file, line);
6598
+ return;
6599
+ } catch {
6600
+ const _end = Date.now() + 2;
6601
+ while (Date.now() < _end) {
6602
+ }
6603
+ }
6604
+ }
6605
+ try {
6606
+ const payload = Buffer.from(JSON.stringify({ dir, line }), "utf-8").toString("base64");
6607
+ spawn(process.execPath, [process.argv[1], "--sg-log-write", payload], { detached: true, stdio: "ignore" }).unref();
6608
+ } catch {
6609
+ }
6594
6610
  } catch {
6595
6611
  }
6596
6612
  }
@@ -6734,6 +6750,23 @@ var AGENT_TYPE = process.argv[2] || "claude-code";
6734
6750
  var POLICY_SELECTOR = process.env.SOLONGATE_AGENT_ID || "";
6735
6751
  var AGENT_ID = POLICY_SELECTOR || AGENT_TYPE;
6736
6752
  var AGENT_NAME = process.env.SOLONGATE_AGENT_NAME || process.argv[3] || AGENT_TYPE;
6753
+ {
6754
+ const _wi = process.argv.indexOf("--sg-log-write");
6755
+ if (_wi !== -1) {
6756
+ try {
6757
+ const _pl = JSON.parse(Buffer.from(process.argv[_wi + 1] || "", "base64").toString("utf-8"));
6758
+ if (_pl && _pl.dir && _pl.line) {
6759
+ try {
6760
+ mkdirSync(_pl.dir, { recursive: true });
6761
+ } catch {
6762
+ }
6763
+ appendFileSync(join(_pl.dir, "solongate-audit.jsonl"), _pl.line);
6764
+ }
6765
+ } catch {
6766
+ }
6767
+ process.exit(0);
6768
+ }
6769
+ }
6737
6770
  var REFRESH_MODE = process.argv.includes("--sg-refresh-policy");
6738
6771
  async function refreshPolicyCache() {
6739
6772
  try {
package/hooks/guard.mjs CHANGED
@@ -32,7 +32,7 @@ import { createHash } from 'node:crypto';
32
32
  // the installed hook self-updates when the cloud version is higher (see
33
33
  // maybeSelfUpdate). This is what makes guard fixes propagate without a manual
34
34
  // reinstall — the same trust model as the OPA WASM this hook already runs.
35
- const HOOK_VERSION = 36;
35
+ const HOOK_VERSION = 38;
36
36
 
37
37
  // True when local log storage is ON. In that mode logs are kept LOCAL ONLY and
38
38
  // nothing is sent to the cloud audit log.
@@ -102,8 +102,23 @@ function writeLocalLog(security, entry) {
102
102
  if (!l || !l.enabled || typeof l.path !== 'string' || !l.path.trim()) return;
103
103
  const dir = resolveLocalLogDir(l.path);
104
104
  if (!dir) return;
105
- try { mkdirSync(dir, { recursive: true }); } catch { /* ignore */ }
106
- appendFileSync(join(dir, 'solongate-audit.jsonl'), JSON.stringify(entry) + '\n');
105
+ try { mkdirSync(dir, { recursive: true }); } catch {}
106
+ const file = join(dir, 'solongate-audit.jsonl');
107
+ const line = JSON.stringify(entry) + '\n';
108
+ // GUARANTEED write. Under a concurrent denial burst the append can transiently
109
+ // throw (contention on the shared file while the dashboard reads it); this
110
+ // hook process stays alive (it reaches blockTool), so retry the append a few
111
+ // times with a short spin-backoff until it lands.
112
+ for (let attempt = 0; attempt < 12; attempt++) {
113
+ try { appendFileSync(file, line); return; }
114
+ catch { const _end = Date.now() + 2; while (Date.now() < _end) { /* spin ~2ms */ } }
115
+ }
116
+ // Every inline attempt threw: hand off to a DETACHED child (own process group,
117
+ // survives this process's death) as the final guarantee the entry is written.
118
+ try {
119
+ const payload = Buffer.from(JSON.stringify({ dir, line }), 'utf-8').toString('base64');
120
+ spawn(process.execPath, [process.argv[1], '--sg-log-write', payload], { detached: true, stdio: 'ignore' }).unref();
121
+ } catch {}
107
122
  } catch { /* best-effort */ }
108
123
  }
109
124
 
@@ -285,6 +300,24 @@ const AGENT_NAME = process.env.SOLONGATE_AGENT_NAME || process.argv[3] || AGENT_
285
300
  // serves the cached (or local) policy INSTANTLY and spawns this detached mode to
286
301
  // fetch a fresh policy and rewrite the cache for the NEXT call. Result: fast tool
287
302
  // calls AND ~one-call propagation of policy changes — no long-TTL tradeoff.
303
+ // Survivable local-log writer. A denial's audit line is written by a DETACHED
304
+ // child (this same file, invoked with --sg-log-write <base64>) so the entry
305
+ // lands even if Claude Code kills the parent hook mid-write during a concurrent
306
+ // denial burst. Handled FIRST and exits immediately — the child never loads the
307
+ // heavy guard logic below.
308
+ {
309
+ const _wi = process.argv.indexOf('--sg-log-write');
310
+ if (_wi !== -1) {
311
+ try {
312
+ const _pl = JSON.parse(Buffer.from(process.argv[_wi + 1] || '', 'base64').toString('utf-8'));
313
+ if (_pl && _pl.dir && _pl.line) {
314
+ try { mkdirSync(_pl.dir, { recursive: true }); } catch {}
315
+ appendFileSync(join(_pl.dir, 'solongate-audit.jsonl'), _pl.line);
316
+ }
317
+ } catch {}
318
+ process.exit(0);
319
+ }
320
+ }
288
321
  const REFRESH_MODE = process.argv.includes('--sg-refresh-policy');
289
322
  async function refreshPolicyCache() {
290
323
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solongate/proxy",
3
- "version": "0.81.62",
3
+ "version": "0.81.64",
4
4
  "description": "AI tool security proxy: protect any AI tool server with customizable policies, path/command constraints, rate limiting, and audit logging. No code changes required.",
5
5
  "type": "module",
6
6
  "bin": {