@solongate/proxy 0.83.57 → 0.83.58

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.
@@ -412,6 +412,9 @@ var ANTIGRAVITY_GROUP = "solongate-guard";
412
412
  function antigravityHookCommand(guardAbs) {
413
413
  return hookCommandFor(dirname(guardAbs), basename(guardAbs), "antigravity", "Antigravity");
414
414
  }
415
+ function antigravityConversationCommand(guardAbs) {
416
+ return hookCommandFor(dirname(guardAbs), "conversation.mjs", "antigravity", "Antigravity");
417
+ }
415
418
  function installAntigravityGuard(p, guardAbs) {
416
419
  mkdirSync(p.antigravityDir, { recursive: true });
417
420
  let existing = {};
@@ -427,7 +430,8 @@ function installAntigravityGuard(p, guardAbs) {
427
430
  const merged = {
428
431
  ...existing,
429
432
  [ANTIGRAVITY_GROUP]: {
430
- PreToolUse: [{ matcher: "", hooks: [{ type: "command", command: antigravityHookCommand(guardAbs) }] }]
433
+ PreToolUse: [{ matcher: "", hooks: [{ type: "command", command: antigravityHookCommand(guardAbs) }] }],
434
+ Stop: [{ matcher: "", hooks: [{ type: "command", command: antigravityConversationCommand(guardAbs) }] }]
431
435
  }
432
436
  };
433
437
  writeFileSync(p.antigravityHooksPath, JSON.stringify(merged, null, 2) + "\n");
package/dist/index.js CHANGED
@@ -6644,6 +6644,9 @@ function installGoBinaries(binDir) {
6644
6644
  function antigravityHookCommand(guardAbs) {
6645
6645
  return hookCommandFor(dirname(guardAbs), basename(guardAbs), "antigravity", "Antigravity");
6646
6646
  }
6647
+ function antigravityConversationCommand(guardAbs) {
6648
+ return hookCommandFor(dirname(guardAbs), "conversation.mjs", "antigravity", "Antigravity");
6649
+ }
6647
6650
  function installAntigravityGuard(p, guardAbs) {
6648
6651
  mkdirSync3(p.antigravityDir, { recursive: true });
6649
6652
  let existing = {};
@@ -6659,7 +6662,8 @@ function installAntigravityGuard(p, guardAbs) {
6659
6662
  const merged = {
6660
6663
  ...existing,
6661
6664
  [ANTIGRAVITY_GROUP]: {
6662
- PreToolUse: [{ matcher: "", hooks: [{ type: "command", command: antigravityHookCommand(guardAbs) }] }]
6665
+ PreToolUse: [{ matcher: "", hooks: [{ type: "command", command: antigravityHookCommand(guardAbs) }] }],
6666
+ Stop: [{ matcher: "", hooks: [{ type: "command", command: antigravityConversationCommand(guardAbs) }] }]
6663
6667
  }
6664
6668
  };
6665
6669
  writeFileSync3(p.antigravityHooksPath, JSON.stringify(merged, null, 2) + "\n");
package/dist/tui/index.js CHANGED
@@ -422,6 +422,9 @@ function installGoBinaries(binDir) {
422
422
  function antigravityHookCommand(guardAbs) {
423
423
  return hookCommandFor(dirname(guardAbs), basename(guardAbs), "antigravity", "Antigravity");
424
424
  }
425
+ function antigravityConversationCommand(guardAbs) {
426
+ return hookCommandFor(dirname(guardAbs), "conversation.mjs", "antigravity", "Antigravity");
427
+ }
425
428
  function installAntigravityGuard(p, guardAbs) {
426
429
  mkdirSync(p.antigravityDir, { recursive: true });
427
430
  let existing = {};
@@ -437,7 +440,8 @@ function installAntigravityGuard(p, guardAbs) {
437
440
  const merged = {
438
441
  ...existing,
439
442
  [ANTIGRAVITY_GROUP]: {
440
- PreToolUse: [{ matcher: "", hooks: [{ type: "command", command: antigravityHookCommand(guardAbs) }] }]
443
+ PreToolUse: [{ matcher: "", hooks: [{ type: "command", command: antigravityHookCommand(guardAbs) }] }],
444
+ Stop: [{ matcher: "", hooks: [{ type: "command", command: antigravityConversationCommand(guardAbs) }] }]
441
445
  }
442
446
  };
443
447
  writeFileSync2(p.antigravityHooksPath, JSON.stringify(merged, null, 2) + "\n");
@@ -43,7 +43,7 @@ import { resolve } from 'node:path';
43
43
  import { homedir } from 'node:os';
44
44
 
45
45
  // Bump on every change to this file, alongside the other hooks.
46
- const HOOK_VERSION = 1;
46
+ const HOOK_VERSION = 2;
47
47
 
48
48
  const AGENT_ID = (process.env.SOLONGATE_AGENT_ID || process.argv[2] || 'default').replace(/[^a-zA-Z0-9_-]/g, '_');
49
49
 
@@ -121,6 +121,59 @@ function readStdin() {
121
121
  try { return readFileSync(0, 'utf-8'); } catch { return ''; }
122
122
  }
123
123
 
124
+ // send is one turn, redacted, to the API. Both payload shapes end here.
125
+ async function send(sessionId, role, body, agentName) {
126
+ if (!sessionId || !String(body).trim()) return;
127
+
128
+ const cfg = loadGlobalCloudConfig();
129
+ const apiKey = process.env.SOLONGATE_API_KEY || cfg.apiKey || '';
130
+ const apiUrl = process.env.SOLONGATE_API_URL || cfg.apiUrl || 'https://api.solongate.com';
131
+ if (!apiKey) return;
132
+
133
+ const cache = loadPolicyCache();
134
+ if (localLogsOn(cache)) return;
135
+
136
+ const cleaned = redact(body, cache);
137
+ try {
138
+ await fetch(`${apiUrl}/api/v1/conversations`, {
139
+ method: 'POST',
140
+ headers: {
141
+ 'Authorization': `Bearer ${apiKey}`,
142
+ 'Content-Type': 'application/json',
143
+ },
144
+ body: JSON.stringify({
145
+ session_id: sessionId,
146
+ role,
147
+ body: cleaned.text,
148
+ redacted: cleaned.masked,
149
+ agent_id: AGENT_ID,
150
+ agent_name: agentName || '',
151
+ source: `${AGENT_ID}-hook`,
152
+ hook_version: HOOK_VERSION,
153
+ }),
154
+ });
155
+ } catch { /* silent: a record that could not be sent must not fail a turn */ }
156
+ }
157
+
158
+ // sendAntigravity writes both halves of the exchange from one Stop payload.
159
+ //
160
+ // The prompt goes first and the reply second, and they are sent in that order
161
+ // rather than concurrently: the rows are ordered by their timestamps, and two
162
+ // requests in flight at once can land in the other order on a fast link — which
163
+ // would draw the answer above the question.
164
+ async function sendAntigravity(common, stop) {
165
+ const sessionId = common.conversationId || common.conversation_id ||
166
+ common.sessionId || common.session_id || '';
167
+ if (!sessionId) return;
168
+ const name = common.agentName || common.agent_name || 'Antigravity';
169
+
170
+ const prompt = common.lastUserInput || common.last_user_input || '';
171
+ if (String(prompt).trim()) await send(sessionId, 'prompt', prompt, name);
172
+
173
+ const reply = stop ? (stop.finalModelOutput || stop.final_model_output || '') : '';
174
+ if (String(reply).trim()) await send(sessionId, 'reply', reply, name);
175
+ }
176
+
124
177
  (async () => {
125
178
  // Whatever happens below, this hook allows the turn. It has no opinion about
126
179
  // whether the work should proceed; it is a record of it.
@@ -130,6 +183,36 @@ function readStdin() {
130
183
  try { data = JSON.parse(readStdin() || '{}'); } catch { return; }
131
184
 
132
185
  const event = data.hook_event_name || data.hookEventName || '';
186
+
187
+ // ANTIGRAVITY sends a different shape, and one hook carries both halves.
188
+ //
189
+ // Its payload is `{common: {lastUserInput, conversationId, ...}, args: {...}}`
190
+ // — the person's last message rides on EVERY hook rather than on an event of
191
+ // its own, and the answer arrives as `stopHookArgs.finalModelOutput`. So one
192
+ // Stop registration records the whole exchange, where Claude Code and Codex
193
+ // need two events to do the same thing.
194
+ //
195
+ // It is detected by shape rather than by a flag, because the client name is
196
+ // an argv argument this hook is also given for the other three, and a payload
197
+ // is a fact while an argument is a claim.
198
+ // OPENCODE calls this hook directly from its plugin, which already knows
199
+ // which half it holds — its two halves arrive by different routes (a
200
+ // chat.message hook for the prompt, streamed text parts for the reply), so
201
+ // the plugin does the deciding and this file does the sending.
202
+ if (data.opencode === true) {
203
+ await send(data.session_id || '', data.role === 'reply' ? 'reply' : 'prompt',
204
+ data.body || '', 'OpenCode');
205
+ return;
206
+ }
207
+
208
+ const agCommon = data.common || (data.hookArgs && data.hookArgs.common) || null;
209
+ const agStop = data.stopHookArgs || (data.args && data.args.stopHookArgs) ||
210
+ (data.hookArgs && data.hookArgs.stopHookArgs) || null;
211
+ if (agCommon && (agStop || agCommon.lastUserInput)) {
212
+ await sendAntigravity(agCommon, agStop);
213
+ return;
214
+ }
215
+
133
216
  // The two halves. Nothing else is listened for: PreToolUse and PostToolUse
134
217
  // already have hooks and are about tool calls rather than about words.
135
218
  let role = '';
@@ -151,33 +234,5 @@ function readStdin() {
151
234
  const sessionId = data.session_id || data.sessionId || data.conversation_id || '';
152
235
  if (!sessionId) return;
153
236
 
154
- const cfg = loadGlobalCloudConfig();
155
- const apiKey = process.env.SOLONGATE_API_KEY || cfg.apiKey || '';
156
- const apiUrl = process.env.SOLONGATE_API_URL || cfg.apiUrl || 'https://api.solongate.com';
157
- if (!apiKey) return;
158
-
159
- const cache = loadPolicyCache();
160
- if (localLogsOn(cache)) return;
161
-
162
- const cleaned = redact(body, cache);
163
-
164
- try {
165
- await fetch(`${apiUrl}/api/v1/conversations`, {
166
- method: 'POST',
167
- headers: {
168
- 'Authorization': `Bearer ${apiKey}`,
169
- 'Content-Type': 'application/json',
170
- },
171
- body: JSON.stringify({
172
- session_id: sessionId,
173
- role,
174
- body: cleaned.text,
175
- redacted: cleaned.masked,
176
- agent_id: AGENT_ID,
177
- agent_name: data.agent_name || '',
178
- source: `${AGENT_ID}-hook`,
179
- hook_version: HOOK_VERSION,
180
- }),
181
- });
182
- } catch { /* silent: a record that could not be sent must not fail a turn */ }
237
+ await send(sessionId, role, body, data.agent_name || '');
183
238
  })();
@@ -36,6 +36,7 @@ import { join } from 'node:path';
36
36
  const HOOKS_DIR = join(homedir(), '.solongate', 'hooks');
37
37
  const GUARD = join(HOOKS_DIR, 'guard.mjs');
38
38
  const AUDIT = join(HOOKS_DIR, 'audit.mjs');
39
+ const CONVERSATION = join(HOOKS_DIR, 'conversation.mjs');
39
40
 
40
41
  // The node binary, written in by the installer.
41
42
  //
@@ -124,6 +125,26 @@ function rewritePatch(res) {
124
125
  return null;
125
126
  }
126
127
 
128
+ // The assistant text held between the part events and the message completing.
129
+ //
130
+ // Keyed by message id, cleared on flush, and dropped whole past a bound: a
131
+ // plugin that grows a buffer for the life of an editor session is a leak in
132
+ // somebody's editor, which is a worse bug than a missing transcript.
133
+ const pending = new Map();
134
+ const MAX_PENDING = 64;
135
+
136
+ // textOf joins the text parts of a message and ignores the rest — a file
137
+ // attachment or a tool call is not something a person said. A synthetic part
138
+ // is one OpenCode wrote itself, which is not either.
139
+ function textOf(parts) {
140
+ if (!Array.isArray(parts)) return '';
141
+ return parts
142
+ .filter((x) => x && x.type === 'text' && typeof x.text === 'string' && !x.synthetic)
143
+ .map((x) => x.text)
144
+ .join('\n')
145
+ .trim();
146
+ }
147
+
127
148
  export const SolonGate = async ({ directory, worktree } = {}) => {
128
149
  const cwd = directory || worktree || process.cwd();
129
150
 
@@ -155,6 +176,58 @@ export const SolonGate = async ({ directory, worktree } = {}) => {
155
176
  }
156
177
  },
157
178
 
179
+ // ── the conversation record ──────────────────────────────────────────
180
+ //
181
+ // OpenCode is the third client to record this and the only one that needs
182
+ // two different hooks to do it, because its halves arrive by different
183
+ // routes: `chat.message` carries what the person wrote, and the answer is
184
+ // streamed as text PARTS which are only final when the assistant message
185
+ // is.
186
+ //
187
+ // So the parts are held per message id and flushed when that message
188
+ // completes.
189
+ 'chat.message': async (input, output) => {
190
+ const text = textOf(output?.parts);
191
+ if (!text) return;
192
+ void runHook(CONVERSATION, {
193
+ opencode: true,
194
+ role: 'prompt',
195
+ body: text,
196
+ session_id: input?.sessionID ?? output?.message?.sessionID ?? '',
197
+ }, GUARD_TIMEOUT_MS);
198
+ },
199
+
200
+ event: async ({ event } = {}) => {
201
+ if (!event || typeof event !== 'object') return;
202
+
203
+ // A text part of a message. `text` is the WHOLE text so far rather than a
204
+ // delta, so the last one wins and nothing is concatenated.
205
+ if (event.type === 'message.part.updated') {
206
+ const part = event.properties?.part;
207
+ if (part?.type === 'text' && part.messageID && typeof part.text === 'string') {
208
+ if (pending.size > MAX_PENDING) pending.clear();
209
+ pending.set(part.messageID, { text: part.text, sessionID: part.sessionID ?? '' });
210
+ }
211
+ return;
212
+ }
213
+
214
+ // The message finished. Anything else — a user message, one still being
215
+ // written — is not a completed answer and is left alone.
216
+ if (event.type === 'message.updated') {
217
+ const info = event.properties?.info;
218
+ if (!info || info.role !== 'assistant' || !info.time?.completed) return;
219
+ const held = pending.get(info.id);
220
+ pending.delete(info.id);
221
+ if (!held || !held.text.trim()) return;
222
+ void runHook(CONVERSATION, {
223
+ opencode: true,
224
+ role: 'reply',
225
+ body: held.text,
226
+ session_id: info.sessionID || held.sessionID || '',
227
+ }, GUARD_TIMEOUT_MS);
228
+ }
229
+ },
230
+
158
231
  'tool.execute.after': async (input, output) => {
159
232
  // The ALLOW-path audit record. Fire and forget: it must never delay the
160
233
  // editor, and losing one line is better than a stalled tool.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solongate/proxy",
3
- "version": "0.83.57",
3
+ "version": "0.83.58",
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": {
@@ -61,12 +61,12 @@
61
61
  "node": ">=20.0.0"
62
62
  },
63
63
  "optionalDependencies": {
64
- "@solongate/guard-linux-x64": "0.83.57",
65
- "@solongate/guard-linux-arm64": "0.83.57",
66
- "@solongate/guard-darwin-x64": "0.83.57",
67
- "@solongate/guard-darwin-arm64": "0.83.57",
68
- "@solongate/guard-win32-x64": "0.83.57",
69
- "@solongate/guard-win32-arm64": "0.83.57"
64
+ "@solongate/guard-linux-x64": "0.83.58",
65
+ "@solongate/guard-linux-arm64": "0.83.58",
66
+ "@solongate/guard-darwin-x64": "0.83.58",
67
+ "@solongate/guard-darwin-arm64": "0.83.58",
68
+ "@solongate/guard-win32-x64": "0.83.58",
69
+ "@solongate/guard-win32-arm64": "0.83.58"
70
70
  },
71
71
  "dependencies": {
72
72
  "@modelcontextprotocol/sdk": "^1.26.0",