solrouter 0.4.2 → 0.4.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solrouter",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Local privacy router for coding tools: pseudonymises every request before it leaves your machine, and sends work a frontier model would refuse to an uncensored open-weight model you control.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/route.js CHANGED
@@ -42,11 +42,35 @@ export function likelyRefused(text) {
42
42
  return false;
43
43
  }
44
44
 
45
+ // Softer decline signals — phrases refusals use even when they don't start with
46
+ // "I can't". Used only for SHORT, complete responses (a long substantive answer
47
+ // that happens to contain one of these is not a refusal).
48
+ const DECLINE_HINTS = [
49
+ /\bI (?:can(?:'|no)?t|won'?t|cannot|will not)\b/i,
50
+ /\bI'?m not (?:going to|able to|willing to|comfortable|going)\b/i,
51
+ /\bI (?:won'?t|don'?t|do not) (?:feel comfortable|think I should|be able)\b/i,
52
+ /\bI'?d (?:rather not|prefer not)\b/i,
53
+ /\b(?:not something I (?:can|will)|that'?s not something)\b/i,
54
+ /\bI'?m (?:sorry|afraid)\b/i,
55
+ /\b(?:against|violates?)\b.{0,30}\b(?:policy|policies|guidelines)\b/i,
56
+ /\bhappy to (?:help|pick|assist)\b.{0,40}\binstead\b/i,
57
+ /\b(?:instead|rather)\b.{0,30}\b(?:I'?m here|happy to|let me)\b/i,
58
+ /\bI (?:must|have to|need to) (?:decline|refuse|pass)\b/i,
59
+ /\bnot appropriate\b/i,
60
+ ];
61
+
45
62
  /** Did a model response come back as a refusal? Used for the reactive retry. */
46
63
  export function isRefusal(text) {
47
64
  const s = String(text ?? "").trim();
48
- if (!s || s.length > 1500) return false; // real refusals are short
49
- for (const re of REFUSAL_SIGNATURES) if (re.test(s)) return true;
65
+ if (!s) return false;
66
+ // Strong signatures fire at any length up to ~1500 (refusals are short).
67
+ if (s.length <= 1500) for (const re of REFUSAL_SIGNATURES) if (re.test(s)) return true;
68
+ // Short + soft decline hints → also a refusal. Short because a real coding answer
69
+ // is long / full of code; a brief prose reply that declines is a refusal.
70
+ if (s.length <= 600) {
71
+ const hasCode = /```|\bfunction\b|\bconst \b|\bimport \b|=>|\bdef \b|;\n/.test(s);
72
+ if (!hasCode) for (const re of DECLINE_HINTS) if (re.test(s)) return true;
73
+ }
50
74
  return false;
51
75
  }
52
76
 
package/src/server.js CHANGED
@@ -7,11 +7,21 @@
7
7
  // localhost only — nothing here should be reachable off the machine.
8
8
 
9
9
  import { createServer } from "node:http";
10
+ import { appendFileSync } from "node:fs";
11
+ import { join } from "node:path";
10
12
  import { handle, handleStream, createMasker, privateReply } from "./index.js";
11
13
  import { forward } from "./providers.js";
12
14
  import { dialect, rewriteText } from "./wire.js";
13
15
  import { isRefusal } from "./route.js";
14
16
  import { writeReceipt } from "./receipt.js";
17
+ import { HOME_DIR } from "./config.js";
18
+
19
+ // Ground-truth log of every streaming routing decision, so a real Claude Code run
20
+ // can be diagnosed from actual traffic instead of guesses. Never contains raw PII
21
+ // beyond the frontier response prefix (already sent to the provider).
22
+ function logDecision(o) {
23
+ try { appendFileSync(join(HOME_DIR, "debug.log"), JSON.stringify({ ts: new Date().toISOString(), ...o }) + "\n"); } catch {}
24
+ }
15
25
 
16
26
  /** Pull assistant text out of an Anthropic SSE chunk (text_delta events). */
17
27
  function extractSseText(chunk) {
@@ -117,9 +127,14 @@ export function startServer(cfg) {
117
127
  }
118
128
 
119
129
  let leg = s.leg, refused = false, model = s.model;
130
+ logDecision({ event: "stream-decision", reqModel: body.model, mode: s.mode,
131
+ committed, refusalLikely, isRefusalFinal: isRefusal(acc), respLen: acc.length,
132
+ respPrefix: acc.slice(0, 400) });
120
133
  if (!committed && s.mode === "auto" && refusalLikely) {
121
134
  // Streamed refusal → reroute to the uncensored private leg.
122
135
  const pr = await privateReply(cfg, s.maskedPrompt);
136
+ logDecision({ event: "reroute", privateOk: pr.ok, privateStatus: pr.status,
137
+ privateModel: cfg.private.model, replyLen: (pr.reply || "").length });
123
138
  if (pr.ok && pr.reply) {
124
139
  leg = "private"; refused = true; model = cfg.private.model;
125
140
  const restored = restorer ? s.masker.unmask(pr.reply) : pr.reply;