@solongate/proxy 0.50.0 → 0.52.0

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.
@@ -10,6 +10,8 @@ export declare function globalPaths(): {
10
10
  configPath: string;
11
11
  };
12
12
  export declare function runGlobalRestore(): void;
13
+ export declare function installClaudeShim(shieldPath: string): void;
14
+ export declare function removeClaudeShim(): void;
13
15
  export declare function runGlobalInstall(opts?: {
14
16
  apiKey?: string;
15
17
  apiUrl?: string;
@@ -69,6 +69,7 @@ function protectedTargets() {
69
69
  join(p.hooksDir, "guard.mjs"),
70
70
  join(p.hooksDir, "audit.mjs"),
71
71
  join(p.hooksDir, "stop.mjs"),
72
+ join(p.hooksDir, "shield.mjs"),
72
73
  p.configPath,
73
74
  p.settingsPath
74
75
  ];
@@ -111,6 +112,7 @@ function ask(question) {
111
112
  function runGlobalRestore() {
112
113
  const p = globalPaths();
113
114
  unlockProtected();
115
+ removeClaudeShim();
114
116
  if (existsSync(p.backupPath)) {
115
117
  writeFileSync(p.settingsPath, readFileSync(p.backupPath, "utf-8"));
116
118
  console.log(` Restored ${p.settingsPath} from backup.`);
@@ -127,6 +129,79 @@ function runGlobalRestore() {
127
129
  }
128
130
  console.log(" Global SolonGate enforcement uninstalled. Restart Claude Code.");
129
131
  }
132
+ var SHIM_BEGIN = "# >>> SolonGate shield (auto secret redaction) >>>";
133
+ var SHIM_END = "# <<< SolonGate shield <<<";
134
+ function escapeRe(s) {
135
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
136
+ }
137
+ function resolveRealClaude() {
138
+ try {
139
+ const finder = process.platform === "win32" ? "where" : "which";
140
+ const out = execFileSync(finder, ["claude"], { encoding: "utf-8" }).split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
141
+ return out[0] || null;
142
+ } catch {
143
+ return null;
144
+ }
145
+ }
146
+ function shimTargets() {
147
+ if (process.platform === "win32") {
148
+ try {
149
+ const prof = execFileSync("powershell", ["-NoProfile", "-Command", "$PROFILE.CurrentUserAllHosts"], { encoding: "utf-8" }).trim();
150
+ return prof ? [prof] : [];
151
+ } catch {
152
+ return [];
153
+ }
154
+ }
155
+ return [".bashrc", ".zshrc", ".profile"].map((f) => join(homedir(), f)).filter((f) => existsSync(f));
156
+ }
157
+ function writeShimBlock(file, block) {
158
+ const re = new RegExp(escapeRe(SHIM_BEGIN) + "[\\s\\S]*?" + escapeRe(SHIM_END) + "\\r?\\n?", "g");
159
+ let content = existsSync(file) ? readFileSync(file, "utf-8") : "";
160
+ content = content.replace(re, "");
161
+ if (block) {
162
+ if (content.length && !content.endsWith("\n")) content += "\n";
163
+ content += block + "\n";
164
+ }
165
+ mkdirSync(dirname(file), { recursive: true });
166
+ writeFileSync(file, content);
167
+ }
168
+ function installClaudeShim(shieldPath) {
169
+ const real = resolveRealClaude();
170
+ if (!real) {
171
+ console.log(" (Claude Code not found on PATH \u2014 skipped auto-shield. Install it, then re-run `login`.)");
172
+ return;
173
+ }
174
+ const node = process.execPath.replace(/\\/g, "/");
175
+ const shield = shieldPath.replace(/\\/g, "/");
176
+ const win = process.platform === "win32";
177
+ const block = win ? `${SHIM_BEGIN}
178
+ function claude { & "${node}" "${shield}" -- "${real}" @args }
179
+ ${SHIM_END}` : `${SHIM_BEGIN}
180
+ claude() { "${node}" "${shield}" -- "${real}" "$@"; }
181
+ ${SHIM_END}`;
182
+ const targets = shimTargets();
183
+ if (targets.length === 0) {
184
+ console.log(" (No shell profile found for auto-shield; run `claude` via `solongate shield -- claude` manually.)");
185
+ return;
186
+ }
187
+ for (const file of targets) {
188
+ try {
189
+ writeShimBlock(file, block);
190
+ console.log(` Auto-shield on: \`claude\` now masks secrets (${file})`);
191
+ } catch (e) {
192
+ console.log(` (Could not enable auto-shield in ${file}: ${e.message})`);
193
+ }
194
+ }
195
+ console.log(" Open a NEW terminal for it to take effect.");
196
+ }
197
+ function removeClaudeShim() {
198
+ for (const file of shimTargets()) {
199
+ try {
200
+ writeShimBlock(file, null);
201
+ } catch {
202
+ }
203
+ }
204
+ }
130
205
  async function runGlobalInstall(opts = {}) {
131
206
  const p = globalPaths();
132
207
  let apiKey = opts.apiKey || process.env["SOLONGATE_API_KEY"] || "";
@@ -151,7 +226,9 @@ async function runGlobalInstall(opts = {}) {
151
226
  writeFileSync(join(p.hooksDir, "guard.mjs"), readGuard());
152
227
  writeFileSync(join(p.hooksDir, "audit.mjs"), readHook("audit.mjs"));
153
228
  writeFileSync(join(p.hooksDir, "stop.mjs"), readHook("stop.mjs"));
229
+ writeFileSync(join(p.hooksDir, "shield.mjs"), readHook("shield.mjs"));
154
230
  console.log(` Installed hooks \u2192 ${p.hooksDir}`);
231
+ installClaudeShim(join(p.hooksDir, "shield.mjs"));
155
232
  writeFileSync(p.configPath, JSON.stringify({ apiKey, apiUrl }, null, 2) + "\n");
156
233
  console.log(` Wrote ${p.configPath}`);
157
234
  let existing = {};
@@ -191,8 +268,10 @@ async function installGlobalWithKey(apiKey, apiUrl) {
191
268
  }
192
269
  export {
193
270
  globalPaths,
271
+ installClaudeShim,
194
272
  installGlobalWithKey,
195
273
  lockProtected,
274
+ removeClaudeShim,
196
275
  runGlobalInstall,
197
276
  runGlobalRestore,
198
277
  unlockProtected