@solongate/proxy 0.51.0 → 0.53.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,83 @@ 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
+ if (process.platform === "win32") {
142
+ const low = (s) => s.toLowerCase();
143
+ return out.find((l) => low(l).endsWith(".cmd")) || out.find((l) => low(l).endsWith(".exe")) || out.find((l) => low(l).endsWith(".bat")) || out[0] || null;
144
+ }
145
+ return out[0] || null;
146
+ } catch {
147
+ return null;
148
+ }
149
+ }
150
+ function shimTargets() {
151
+ if (process.platform === "win32") {
152
+ try {
153
+ const prof = execFileSync("powershell", ["-NoProfile", "-Command", "$PROFILE.CurrentUserAllHosts"], { encoding: "utf-8" }).trim();
154
+ return prof ? [prof] : [];
155
+ } catch {
156
+ return [];
157
+ }
158
+ }
159
+ return [".bashrc", ".zshrc", ".profile"].map((f) => join(homedir(), f)).filter((f) => existsSync(f));
160
+ }
161
+ function writeShimBlock(file, block) {
162
+ const re = new RegExp(escapeRe(SHIM_BEGIN) + "[\\s\\S]*?" + escapeRe(SHIM_END) + "\\r?\\n?", "g");
163
+ let content = existsSync(file) ? readFileSync(file, "utf-8") : "";
164
+ content = content.replace(re, "");
165
+ if (block) {
166
+ if (content.length && !content.endsWith("\n")) content += "\n";
167
+ content += block + "\n";
168
+ }
169
+ mkdirSync(dirname(file), { recursive: true });
170
+ writeFileSync(file, content);
171
+ }
172
+ function installClaudeShim(shieldPath) {
173
+ const real = resolveRealClaude();
174
+ if (!real) {
175
+ console.log(" (Claude Code not found on PATH \u2014 skipped auto-shield. Install it, then re-run `login`.)");
176
+ return;
177
+ }
178
+ const node = process.execPath.replace(/\\/g, "/");
179
+ const shield = shieldPath.replace(/\\/g, "/");
180
+ const win = process.platform === "win32";
181
+ const block = win ? `${SHIM_BEGIN}
182
+ function claude { & "${node}" "${shield}" -- "${real}" @args }
183
+ ${SHIM_END}` : `${SHIM_BEGIN}
184
+ claude() { "${node}" "${shield}" -- "${real}" "$@"; }
185
+ ${SHIM_END}`;
186
+ const targets = shimTargets();
187
+ if (targets.length === 0) {
188
+ console.log(" (No shell profile found for auto-shield; run `claude` via `solongate shield -- claude` manually.)");
189
+ return;
190
+ }
191
+ for (const file of targets) {
192
+ try {
193
+ writeShimBlock(file, block);
194
+ console.log(` Auto-shield on: \`claude\` now masks secrets (${file})`);
195
+ } catch (e) {
196
+ console.log(` (Could not enable auto-shield in ${file}: ${e.message})`);
197
+ }
198
+ }
199
+ console.log(" Open a NEW terminal for it to take effect.");
200
+ }
201
+ function removeClaudeShim() {
202
+ for (const file of shimTargets()) {
203
+ try {
204
+ writeShimBlock(file, null);
205
+ } catch {
206
+ }
207
+ }
208
+ }
130
209
  async function runGlobalInstall(opts = {}) {
131
210
  const p = globalPaths();
132
211
  let apiKey = opts.apiKey || process.env["SOLONGATE_API_KEY"] || "";
@@ -151,7 +230,9 @@ async function runGlobalInstall(opts = {}) {
151
230
  writeFileSync(join(p.hooksDir, "guard.mjs"), readGuard());
152
231
  writeFileSync(join(p.hooksDir, "audit.mjs"), readHook("audit.mjs"));
153
232
  writeFileSync(join(p.hooksDir, "stop.mjs"), readHook("stop.mjs"));
233
+ writeFileSync(join(p.hooksDir, "shield.mjs"), readHook("shield.mjs"));
154
234
  console.log(` Installed hooks \u2192 ${p.hooksDir}`);
235
+ installClaudeShim(join(p.hooksDir, "shield.mjs"));
155
236
  writeFileSync(p.configPath, JSON.stringify({ apiKey, apiUrl }, null, 2) + "\n");
156
237
  console.log(` Wrote ${p.configPath}`);
157
238
  let existing = {};
@@ -191,8 +272,10 @@ async function installGlobalWithKey(apiKey, apiUrl) {
191
272
  }
192
273
  export {
193
274
  globalPaths,
275
+ installClaudeShim,
194
276
  installGlobalWithKey,
195
277
  lockProtected,
278
+ removeClaudeShim,
196
279
  runGlobalInstall,
197
280
  runGlobalRestore,
198
281
  unlockProtected