openzoo 0.20.2 → 0.20.4

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/bin/openzoo.js CHANGED
@@ -12,11 +12,16 @@ usage:
12
12
  a missing dir is created)
13
13
  --profile use an isolated editor profile the
14
14
  vendor account cannot re-sync over
15
+ (also points cursor's own backend at 127.0.0.1 in
16
+ the hosts file so it cannot re-sync over your model
17
+ list or route inference around the proxy — asks for
18
+ your password; --no-block skips it)
15
19
  npx openzoo vscode [path] same, for VS Code
16
20
  npx openzoo editor [path] whichever is installed (Cursor wins if both)
17
21
  npx openzoo launch <cmd> [args] launch a TERMINAL Messages API client
18
22
  (claude, aider...) already pointed at the zoo
19
23
  npx openzoo mcp stdio MCP server (tools: zoo_ask, zoo_bind, zoo_models, zoo_wallet, zoo_contexts)
24
+ npx openzoo unblock restore the editor's own backend in the hosts file
20
25
  npx openzoo tunnel public-url-only mode (everything key-gated, no keyless localhost)
21
26
  npx openzoo demo ~1M-token needle demo: direct refuses, the zoo answers
22
27
  (run it twice — the second run reuses the bound corpus and is near-free)
@@ -70,6 +75,12 @@ async function main() {
70
75
  await (await import('../lib/launch.js')).launchHarness(harness, hargs);
71
76
  break;
72
77
  }
78
+ case 'unblock': {
79
+ const { unblockBackend, isBlocked } = await import('../lib/hosts.js');
80
+ const r = unblockBackend();
81
+ console.log(r.already ? 'not blocked — nothing to undo' : (isBlocked() ? 'still blocked (sudo declined?)' : 'restored: the editor can reach its own backend again'));
82
+ break;
83
+ }
73
84
  case 'tunnel':
74
85
  await (await import('../lib/tunnel.js')).runTunnel();
75
86
  break;
package/lib/hosts.js ADDED
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Force the editor off its own backend by blackholing it in /etc/hosts.
3
+ *
4
+ * WHY THIS IS NEEDED: Cursor renders its model picker from IN-MEMORY state that
5
+ * it re-syncs from `api2.cursor.sh` on window focus. Writing the database is not
6
+ * enough — measured, the DB held 413 openzoo models and the correct selection
7
+ * while the UI showed none, because the sync repainted memory a moment later.
8
+ * The same host is `bcProxyUrl`, the route Cursor's own inference takes, so
9
+ * while it is reachable the editor will always prefer it over a custom endpoint.
10
+ *
11
+ * Pointing it at 127.0.0.1 makes that path fail, leaving the configured OpenAI
12
+ * base URL as the only way out.
13
+ *
14
+ * COLLATERAL, STATED PLAINLY: that host also carries auth and usage reporting.
15
+ * The editor may report being signed out or degraded. This is a system-wide
16
+ * change needing a password, so it always backs up the hosts file first and
17
+ * `npx openzoo unblock` restores it. `--no-block` skips it entirely.
18
+ */
19
+ import fs from 'node:fs';
20
+ import { execFileSync, spawnSync } from 'node:child_process';
21
+
22
+ /**
23
+ * Hosts-file location and the privilege/flush mechanics differ per platform:
24
+ * macOS /etc/hosts sudo + dscacheutil/mDNSResponder
25
+ * Linux /etc/hosts sudo + systemd-resolve or nscd (best effort)
26
+ * Windows %SystemRoot%\\System32\\drivers\\etc\\hosts, needs an ELEVATED shell
27
+ * Everything below branches on that rather than assuming macOS.
28
+ */
29
+ const WIN = process.platform === 'win32';
30
+ const HOSTS = WIN
31
+ ? `${process.env.SystemRoot || 'C:\\Windows'}\\System32\\drivers\\etc\\hosts`
32
+ : '/etc/hosts';
33
+ const BACKUP = `${HOSTS}.openzoo-backup`;
34
+ const MARK = '# openzoo: force the editor onto the local proxy';
35
+
36
+ /** Hosts the editor uses for model sync + its own inference proxy. */
37
+ export const BACKEND_HOSTS = ['api2.cursor.sh'];
38
+
39
+ export function isBlocked() {
40
+ try {
41
+ const txt = fs.readFileSync(HOSTS, 'utf8');
42
+ return BACKEND_HOSTS.every((h) => new RegExp(`^\\s*127\\.0\\.0\\.1\\s+${h.replace('.', '\\.')}`, 'm').test(txt));
43
+ } catch { return false; }
44
+ }
45
+
46
+ /**
47
+ * Run a privileged command. On unix sudo prompts in the user's own terminal;
48
+ * on Windows we cannot elevate from here, so we return false and the caller
49
+ * prints the line to run in an Administrator shell.
50
+ */
51
+ function privileged(unixLine) {
52
+ if (WIN) return false;
53
+ const r = spawnSync('sudo', ['sh', '-c', unixLine], { stdio: 'inherit' });
54
+ return r.status === 0;
55
+ }
56
+
57
+ /** Flush the OS resolver cache, best effort, per platform. */
58
+ function flushDnsCmd() {
59
+ if (process.platform === 'darwin') {
60
+ return 'dscacheutil -flushcache 2>/dev/null; killall -HUP mDNSResponder 2>/dev/null; true';
61
+ }
62
+ // Linux: whichever of these exists; none is fatal.
63
+ return 'resolvectl flush-caches 2>/dev/null || systemd-resolve --flush-caches 2>/dev/null'
64
+ + ' || service nscd restart 2>/dev/null; true';
65
+ }
66
+
67
+ export function blockBackend() {
68
+ if (isBlocked()) return { already: true };
69
+ const entries = BACKEND_HOSTS.map((h) => `127.0.0.1 ${h}`).join('\\n');
70
+ console.log('');
71
+ console.log('blocking the editor\'s backend so it cannot re-sync over your model list.');
72
+ console.log(` hosts : ${BACKEND_HOSTS.join(', ')} -> 127.0.0.1`);
73
+ console.log(` backup : ${BACKUP}`);
74
+ console.log(' NOTE : that host also carries the editor\'s auth/usage — it may report');
75
+ console.log(' being signed out. Undo any time with: npx openzoo unblock');
76
+ console.log(' skip this next time with: --no-block');
77
+ console.log(' sudo will ask for your password now.');
78
+ if (WIN) {
79
+ console.log(' windows: run this in an ADMINISTRATOR PowerShell, then relaunch:');
80
+ console.log(` Copy-Item "${HOSTS}" "${BACKUP}" -ErrorAction SilentlyContinue`);
81
+ for (const h of BACKEND_HOSTS) console.log(` Add-Content "${HOSTS}" "127.0.0.1 ${h}"`);
82
+ console.log(' ipconfig /flushdns');
83
+ return { ok: false, manual: true, blocked: false };
84
+ }
85
+ const ok = privileged(
86
+ `cp -n ${HOSTS} ${BACKUP} 2>/dev/null; `
87
+ + `printf '\\n${MARK}\\n${entries}\\n' >> ${HOSTS}; `
88
+ + flushDnsCmd(),
89
+ );
90
+ return { ok, blocked: isBlocked() };
91
+ }
92
+
93
+ export function unblockBackend() {
94
+ if (!isBlocked()) return { already: true };
95
+ // Remove only OUR lines, never restore wholesale — the user may have edited
96
+ // /etc/hosts for unrelated reasons since the backup was taken.
97
+ const pattern = BACKEND_HOSTS.map((h) => h.replace('.', '\\.')).join('|');
98
+ if (WIN) {
99
+ console.log('windows: run in an ADMINISTRATOR PowerShell:');
100
+ console.log(` Copy-Item "${BACKUP}" "${HOSTS}" -Force; ipconfig /flushdns`);
101
+ return { ok: false, manual: true };
102
+ }
103
+ // BSD sed (macOS) needs -i ''; GNU sed (linux) must NOT have it. Use a temp
104
+ // file instead so one command is correct on both.
105
+ const re = `/^[[:space:]]*127\\.0\\.0\\.1[[:space:]]+(${pattern})[[:space:]]*$/d; /openzoo: force the editor/d`;
106
+ const ok = privileged(
107
+ `sed -E '${re}' ${HOSTS} > ${HOSTS}.oztmp && cat ${HOSTS}.oztmp > ${HOSTS} && rm -f ${HOSTS}.oztmp; `
108
+ + flushDnsCmd(),
109
+ );
110
+ return { ok, blocked: isBlocked() };
111
+ }
package/lib/setup.js CHANGED
@@ -246,6 +246,19 @@ export async function setupEditor(which, target) {
246
246
  console.log(' verify: send one message, watch for "paid $0.0… · rail solana · tx …" here.');
247
247
  }
248
248
 
249
+ // 2b. THE BACKEND BLOCK. Pinning the database is not sufficient on its own:
250
+ // the editor re-syncs its model list from its own backend into MEMORY on
251
+ // window focus and repaints the picker empty, and that same host is the
252
+ // route its own inference takes. Blackholing it in the hosts file is what
253
+ // leaves the configured base URL as the only way out. System-wide and
254
+ // needs a password, so it is opt-in and reversible.
255
+ if (target0 === 'cursor' && !process.argv.includes('--no-block')) {
256
+ const { blockBackend, isBlocked } = await import('./hosts.js');
257
+ const r = blockBackend();
258
+ if (r.already) console.log('backend: already blocked (npx openzoo unblock to restore)');
259
+ else console.log(`backend: ${isBlocked() ? 'blocked -> 127.0.0.1' : 'NOT blocked — the editor will re-sync over your model list'}`);
260
+ }
261
+
249
262
  // 3. LAUNCH with that env. Editor resolved platform-agnostically; Cursor
250
263
  // wins when both are installed.
251
264
  // Open the directory you ran this from, or the one you named. The earlier
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openzoo",
3
- "version": "0.20.2",
3
+ "version": "0.20.4",
4
4
  "description": "Local x402-paying proxy + MCP server for openzoo.fun — point any OpenAI-compatible harness (Cursor, Claude Code, aider, SDKs) at localhost and it pays per call from a local burner wallet. Solana and Base rails live; Robinhood experimental.",
5
5
  "license": "MIT",
6
6
  "type": "module",