@blockrun/franklin 3.49.21 → 3.49.22

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.
@@ -2,6 +2,7 @@ import { spawn, execFileSync, execSync } from 'node:child_process';
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import chalk from 'chalk';
5
+ import { proxyBaseUrl } from '../proxy/claude-settings.js';
5
6
  import { BLOCKRUN_DIR, DEFAULT_PROXY_PORT } from '../config.js';
6
7
  const PID_FILE = path.join(BLOCKRUN_DIR, 'franklin.pid');
7
8
  const LOG_FILE = path.join(BLOCKRUN_DIR, 'franklin-debug.log');
@@ -64,7 +65,7 @@ export async function daemonCommand(action, options) {
64
65
  const existing = readPid();
65
66
  if (existing && isRunning(existing)) {
66
67
  console.log(chalk.yellow(`franklin daemon already running (PID ${existing})`));
67
- console.log(chalk.dim(` Proxy: http://localhost:${port}/api`));
68
+ console.log(chalk.dim(` Proxy: ${proxyBaseUrl(port)}`));
68
69
  return;
69
70
  }
70
71
  const daemonBin = findDaemonBinary();
@@ -81,7 +82,7 @@ export async function daemonCommand(action, options) {
81
82
  child.unref();
82
83
  fs.writeFileSync(PID_FILE, String(child.pid));
83
84
  console.log(chalk.green(`✓ franklin daemon started (PID ${child.pid})`));
84
- console.log(chalk.dim(` Proxy: http://localhost:${port}/api`));
85
+ console.log(chalk.dim(` Proxy: ${proxyBaseUrl(port)}`));
85
86
  console.log(chalk.dim(` Logs: ${LOG_FILE}`));
86
87
  break;
87
88
  }
@@ -127,7 +128,7 @@ export async function daemonCommand(action, options) {
127
128
  if (isRunning(pid)) {
128
129
  console.log(chalk.green(`✓ franklin daemon running`));
129
130
  console.log(` PID: ${chalk.bold(pid)}`);
130
- console.log(` Proxy: ${chalk.cyan(`http://localhost:${port}/api`)}`);
131
+ console.log(` Proxy: ${chalk.cyan(proxyBaseUrl(port))}`);
131
132
  console.log(chalk.dim(` Logs: ${LOG_FILE}`));
132
133
  }
133
134
  else {
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
  import os from 'node:os';
4
4
  import chalk from 'chalk';
5
5
  import { DEFAULT_PROXY_PORT } from '../config.js';
6
- const CLAUDE_SETTINGS_FILE = path.join(os.homedir(), '.claude', 'settings.json');
6
+ import { CLAUDE_SETTINGS_FILE, PROXY_AUTH_PLACEHOLDER, proxyBaseUrl } from '../proxy/claude-settings.js';
7
7
  const LAUNCH_AGENT_DIR = path.join(os.homedir(), 'Library', 'LaunchAgents');
8
8
  const LAUNCH_AGENT_PLIST = path.join(LAUNCH_AGENT_DIR, 'ai.blockrun.franklin.plist');
9
9
  const LEGACY_LAUNCH_AGENT_PLIST = path.join(LAUNCH_AGENT_DIR, 'ai.blockrun.runcode.plist');
@@ -25,8 +25,9 @@ export async function initCommand(options) {
25
25
  }
26
26
  settings.env = {
27
27
  ...(settings.env ?? {}),
28
- ANTHROPIC_BASE_URL: `http://localhost:${port}/api`,
29
- ANTHROPIC_AUTH_TOKEN: 'x402-proxy-handles-auth',
28
+ // 127.0.0.1, never localhost: see proxy/claude-settings.ts.
29
+ ANTHROPIC_BASE_URL: proxyBaseUrl(port),
30
+ ANTHROPIC_AUTH_TOKEN: PROXY_AUTH_PLACEHOLDER,
30
31
  ANTHROPIC_MODEL: 'blockrun/auto',
31
32
  ANTHROPIC_DEFAULT_SONNET_MODEL: 'anthropic/claude-sonnet-4.6',
32
33
  ANTHROPIC_DEFAULT_OPUS_MODEL: 'anthropic/claude-opus-5',
@@ -9,6 +9,7 @@ import { loadChain, CHAIN_LABELS, DEFAULT_PROXY_PORT } from '../config.js';
9
9
  import { gatewayBase } from '../payments/auth-mode.js';
10
10
  import { loadConfig } from './config.js';
11
11
  import { printBanner } from '../banner.js';
12
+ import { proxyBaseUrl, migrateClaudeSettingsBaseUrl, CLAUDE_SETTINGS_FILE } from '../proxy/claude-settings.js';
12
13
  export async function proxyCommand(options) {
13
14
  const version = options.version ?? '1.0.0';
14
15
  const chain = loadChain();
@@ -36,7 +37,7 @@ export async function proxyCommand(options) {
36
37
  if (model)
37
38
  console.log(`Model: ${chalk.green(model)}`);
38
39
  console.log(`Fallback: ${fallbackEnabled ? chalk.green('enabled') : chalk.yellow('disabled')}`);
39
- console.log(`Proxy: ${chalk.cyan(`http://localhost:${port}`)}`);
40
+ console.log(`Proxy: ${chalk.cyan(proxyBaseUrl(port))}`);
40
41
  console.log(`Backend: ${chalk.dim(apiUrl)}\n`);
41
42
  const server = createProxy({
42
43
  port,
@@ -63,7 +64,7 @@ export async function proxyCommand(options) {
63
64
  if (model)
64
65
  console.log(`Model: ${chalk.green(model)}`);
65
66
  console.log(`Fallback: ${fallbackEnabled ? chalk.green('enabled') : chalk.yellow('disabled')}`);
66
- console.log(`Proxy: ${chalk.cyan(`http://localhost:${port}`)}`);
67
+ console.log(`Proxy: ${chalk.cyan(proxyBaseUrl(port))}`);
67
68
  console.log(`Backend: ${chalk.dim(apiUrl)}\n`);
68
69
  const server = createProxy({
69
70
  port,
@@ -88,15 +89,21 @@ function launchProxy(server, port, debug) {
88
89
  });
89
90
  // Bind to loopback ONLY — this proxy signs x402 USDC payments from the local
90
91
  // wallet on every request, so it must never be reachable from the LAN. Every
91
- // other Franklin server binds 127.0.0.1; the banner below says "localhost".
92
+ // other Franklin server binds 127.0.0.1, and every URL we print or write
93
+ // says 127.0.0.1 too (see proxy/claude-settings.ts for why not localhost).
92
94
  server.listen(port, '127.0.0.1', () => {
93
95
  console.log(chalk.green(`✓ Proxy running on port ${port}`));
96
+ // `franklin daemon` and the LaunchAgent both start here, so this one call
97
+ // fixes a localhost base URL that an older `franklin init` wrote.
98
+ if (migrateClaudeSettingsBaseUrl()) {
99
+ console.log(chalk.yellow(` Updated ANTHROPIC_BASE_URL in ${CLAUDE_SETTINGS_FILE} to 127.0.0.1. Restart Claude Code to pick it up.`));
100
+ }
94
101
  console.log(chalk.dim(` Usage tracking: ~/.blockrun/franklin-stats.json`));
95
102
  if (debug)
96
103
  console.log(chalk.dim(` Debug log: ~/.blockrun/franklin-debug.log`));
97
104
  console.log(chalk.dim(` Run 'franklin stats' to view statistics\n`));
98
105
  console.log('Set these in your shell to route Anthropic-compatible CLI agents through franklin:\n');
99
- console.log(chalk.bold(` export ANTHROPIC_BASE_URL=http://localhost:${port}/api`));
106
+ console.log(chalk.bold(` export ANTHROPIC_BASE_URL=${proxyBaseUrl(port)}`));
100
107
  console.log(chalk.bold(` export ANTHROPIC_AUTH_TOKEN=x402-proxy-handles-auth`));
101
108
  console.log(`\nThen run ${chalk.bold('claude')} in another terminal.`);
102
109
  });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Where Anthropic-compatible CLI agents (Claude Code) are pointed at the
3
+ * Franklin proxy, and the one-time fix for links written by older releases.
4
+ *
5
+ * The proxy binds 127.0.0.1 only. `localhost` resolves to ::1 first in Node
6
+ * and most clients, and another account on the machine can listen on
7
+ * [::1]:<port> beside our 127.0.0.1:<port> without a bind conflict. A
8
+ * `localhost` base URL would send that listener every prompt, and its
9
+ * replies would reach the agent as model output, tool calls included.
10
+ */
11
+ export declare const CLAUDE_SETTINGS_FILE: string;
12
+ /** The auth token `franklin init` writes; marks the env block as ours. */
13
+ export declare const PROXY_AUTH_PLACEHOLDER = "x402-proxy-handles-auth";
14
+ export declare function proxyBaseUrl(port: number): string;
15
+ /**
16
+ * Rewrite a `localhost` ANTHROPIC_BASE_URL written by `franklin init` to
17
+ * 127.0.0.1. Only touches an env block that is Franklin's (our placeholder
18
+ * auth token) and a URL in exactly the form init wrote, so a user's own
19
+ * settings are left alone. Returns true when it changed the file.
20
+ */
21
+ export declare function migrateClaudeSettingsBaseUrl(file?: string): boolean;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Where Anthropic-compatible CLI agents (Claude Code) are pointed at the
3
+ * Franklin proxy, and the one-time fix for links written by older releases.
4
+ *
5
+ * The proxy binds 127.0.0.1 only. `localhost` resolves to ::1 first in Node
6
+ * and most clients, and another account on the machine can listen on
7
+ * [::1]:<port> beside our 127.0.0.1:<port> without a bind conflict. A
8
+ * `localhost` base URL would send that listener every prompt, and its
9
+ * replies would reach the agent as model output, tool calls included.
10
+ */
11
+ import fs from 'node:fs';
12
+ import os from 'node:os';
13
+ import path from 'node:path';
14
+ export const CLAUDE_SETTINGS_FILE = path.join(os.homedir(), '.claude', 'settings.json');
15
+ /** The auth token `franklin init` writes; marks the env block as ours. */
16
+ export const PROXY_AUTH_PLACEHOLDER = 'x402-proxy-handles-auth';
17
+ export function proxyBaseUrl(port) {
18
+ return `http://127.0.0.1:${port}/api`;
19
+ }
20
+ const LEGACY_BASE_URL = /^http:\/\/localhost:(\d{1,5})\/api\/?$/;
21
+ /**
22
+ * Rewrite a `localhost` ANTHROPIC_BASE_URL written by `franklin init` to
23
+ * 127.0.0.1. Only touches an env block that is Franklin's (our placeholder
24
+ * auth token) and a URL in exactly the form init wrote, so a user's own
25
+ * settings are left alone. Returns true when it changed the file.
26
+ */
27
+ export function migrateClaudeSettingsBaseUrl(file = CLAUDE_SETTINGS_FILE) {
28
+ let raw;
29
+ try {
30
+ raw = fs.readFileSync(file, 'utf-8');
31
+ }
32
+ catch {
33
+ return false;
34
+ }
35
+ let settings;
36
+ try {
37
+ settings = JSON.parse(raw);
38
+ }
39
+ catch {
40
+ return false; // never rewrite a file we cannot parse
41
+ }
42
+ const env = settings.env;
43
+ if (!env || env.ANTHROPIC_AUTH_TOKEN !== PROXY_AUTH_PLACEHOLDER)
44
+ return false;
45
+ const current = env.ANTHROPIC_BASE_URL;
46
+ if (typeof current !== 'string')
47
+ return false;
48
+ const m = LEGACY_BASE_URL.exec(current);
49
+ if (!m)
50
+ return false;
51
+ env.ANTHROPIC_BASE_URL = proxyBaseUrl(Number(m[1]));
52
+ try {
53
+ fs.writeFileSync(file, JSON.stringify(settings, null, 2) + (raw.endsWith('\n') ? '\n' : ''));
54
+ return true;
55
+ }
56
+ catch {
57
+ return false;
58
+ }
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/franklin",
3
- "version": "3.49.21",
3
+ "version": "3.49.22",
4
4
  "description": "Franklin Agent — The AI agent with a wallet. Spends USDC autonomously to get real work done. Pay per action, no subscriptions.",
5
5
  "type": "module",
6
6
  "exports": {