@alexeiled/claude-router 0.7.2 → 1.0.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.
- package/.claude-plugin/plugin.json +10 -6
- package/CHANGELOG.md +43 -0
- package/README.md +51 -100
- package/docs/architecture.md +55 -414
- package/docs/configuration.md +86 -182
- package/docs/evaluation.md +62 -81
- package/docs/native-router.md +79 -0
- package/docs/user-guide.md +103 -172
- package/hooks/hooks.json +1 -26
- package/hooks/native-router.mjs +635 -0
- package/lib/config.mjs +24 -60
- package/lib/{facts.mjs → facts-pure.mjs} +2 -23
- package/lib/{jev.mjs → jev-contract.mjs} +17 -38
- package/lib/native-cost.mjs +88 -0
- package/lib/native-display.mjs +75 -0
- package/lib/native-jev.mjs +125 -0
- package/lib/native-panel.mjs +150 -0
- package/lib/native-router.mjs +216 -0
- package/lib/policy.mjs +17 -21
- package/package.json +9 -8
- package/scripts/migrate-config.mjs +57 -0
- package/types/index.d.ts +95 -0
- package/lib/cost.mjs +0 -93
- package/lib/gateway.mjs +0 -221
- package/lib/idle.mjs +0 -41
- package/lib/rewrite.mjs +0 -130
- package/lib/router.mjs +0 -276
- package/lib/runtime.mjs +0 -78
- package/lib/sse.mjs +0 -57
- package/lib/status.mjs +0 -152
- package/lib/store.mjs +0 -76
- package/scripts/ensure-gateway.mjs +0 -143
- package/scripts/gateway.mjs +0 -81
- package/scripts/git-hooks/pre-commit +0 -27
- package/scripts/git-hooks/pre-push +0 -34
- package/scripts/status.mjs +0 -20
- package/scripts/statusline.mjs +0 -45
- package/scripts/transcript-models.sh +0 -4
- package/skills/high/SKILL.md +0 -9
- package/skills/low/SKILL.md +0 -7
- package/skills/medium/SKILL.md +0 -8
- package/skills/micro/SKILL.md +0 -7
- package/skills/setup/SKILL.md +0 -31
- package/skills/status/SKILL.md +0 -12
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Hook entry (SessionStart, UserPromptSubmit): make sure a gateway of this plugin version or newer answers on the port.
|
|
3
|
-
// Starts one on a free port and replaces an older one; leaves a newer one alone, so a session that still runs an older
|
|
4
|
-
// plugin never downgrades it. Detached, so the gateway outlives the session. After a crash, the next prompt restarts it.
|
|
5
|
-
// `--quiet` prints nothing: UserPromptSubmit output goes into the model's context.
|
|
6
|
-
import { spawn } from 'node:child_process';
|
|
7
|
-
import { mkdirSync, openSync } from 'node:fs';
|
|
8
|
-
import { connect } from 'node:net';
|
|
9
|
-
import { dirname, join } from 'node:path';
|
|
10
|
-
import { fileURLToPath } from 'node:url';
|
|
11
|
-
import { cliArg, configArgs, isRouterGateway, loadRuntime } from '../lib/runtime.mjs';
|
|
12
|
-
import { isOlderVersion, ROUTER_VERSION, STATUS_PATH } from '../lib/status.mjs';
|
|
13
|
-
import { rotate } from '../lib/store.mjs';
|
|
14
|
-
|
|
15
|
-
const WAIT_STEP_MS = 100;
|
|
16
|
-
const WAIT_STEPS = 20;
|
|
17
|
-
const STATUS_TIMEOUT_MS = 500;
|
|
18
|
-
|
|
19
|
-
const env = process.env;
|
|
20
|
-
const quiet = process.argv.includes('--quiet');
|
|
21
|
-
|
|
22
|
-
function say(message) {
|
|
23
|
-
if (!quiet) process.stdout.write(`router: ${message}\n`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let config;
|
|
27
|
-
let dataDir;
|
|
28
|
-
let configPath;
|
|
29
|
-
let configWarning;
|
|
30
|
-
try {
|
|
31
|
-
({
|
|
32
|
-
config,
|
|
33
|
-
dataDir,
|
|
34
|
-
configPath,
|
|
35
|
-
warning: configWarning,
|
|
36
|
-
} = loadRuntime(env, {
|
|
37
|
-
configPath: cliArg(process.argv, '--config'),
|
|
38
|
-
}));
|
|
39
|
-
} catch (error) {
|
|
40
|
-
say(`invalid configuration (${error.message}); the next prompt tries again`);
|
|
41
|
-
process.exit(0);
|
|
42
|
-
}
|
|
43
|
-
if (configWarning) say(configWarning);
|
|
44
|
-
const port = config.gateway.port;
|
|
45
|
-
|
|
46
|
-
function probe() {
|
|
47
|
-
return new Promise((resolve) => {
|
|
48
|
-
const socket = connect({ host: '127.0.0.1', port });
|
|
49
|
-
socket.once('connect', () => {
|
|
50
|
-
socket.destroy();
|
|
51
|
-
resolve(true);
|
|
52
|
-
});
|
|
53
|
-
socket.once('error', () => resolve(false));
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Waits until the port answers (`true`) or is free (`false`).
|
|
58
|
-
async function waitFor(answering) {
|
|
59
|
-
for (let i = 0; i < WAIT_STEPS; i += 1) {
|
|
60
|
-
if ((await probe()) === answering) return true;
|
|
61
|
-
await new Promise((resolve) => setTimeout(resolve, WAIT_STEP_MS));
|
|
62
|
-
}
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function runningGateway() {
|
|
67
|
-
try {
|
|
68
|
-
const res = await fetch(`http://127.0.0.1:${port}${STATUS_PATH}`, {
|
|
69
|
-
signal: AbortSignal.timeout(STATUS_TIMEOUT_MS),
|
|
70
|
-
});
|
|
71
|
-
return res.ok ? await res.json() : null;
|
|
72
|
-
} catch {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// SIGTERM: the old gateway releases the port at once and finishes its open streams. Gateways from 0.4.0 on report
|
|
78
|
-
// their pid; older ones cannot be retired from here.
|
|
79
|
-
async function retire(running) {
|
|
80
|
-
const from = running.version ?? 'before 0.3.0';
|
|
81
|
-
if (!running.pid) {
|
|
82
|
-
say(
|
|
83
|
-
`gateway ${from} runs on port ${port}. Stop it once with \`pkill -f scripts/gateway.mjs\`; the next prompt starts ${ROUTER_VERSION}.`,
|
|
84
|
-
);
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
if (!isRouterGateway(running.pid)) {
|
|
88
|
-
say(`port ${port} answers as gateway ${from}, but pid ${running.pid} is not a router gateway: left alone`);
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
process.kill(running.pid, 'SIGTERM');
|
|
93
|
-
} catch (error) {
|
|
94
|
-
say(`cannot stop gateway ${from} (pid ${running.pid}): ${error.message}`);
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
if (await waitFor(false)) return true;
|
|
98
|
-
say(`gateway ${from} (pid ${running.pid}) did not release port ${port}`);
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async function start() {
|
|
103
|
-
mkdirSync(dataDir, { recursive: true });
|
|
104
|
-
const logPath = join(dataDir, 'gateway.log');
|
|
105
|
-
try {
|
|
106
|
-
rotate(logPath);
|
|
107
|
-
} catch {
|
|
108
|
-
// Rotation is housekeeping; a gateway that starts matters more.
|
|
109
|
-
}
|
|
110
|
-
const log = openSync(logPath, 'a');
|
|
111
|
-
// Claude Code exports the plugin option as CLAUDE_PLUGIN_OPTION_<KEY>; the gateway reads one name only.
|
|
112
|
-
const childEnv = {
|
|
113
|
-
...env,
|
|
114
|
-
TYPESAFE_API_KEY: env.TYPESAFE_API_KEY || env.CLAUDE_PLUGIN_OPTION_TYPESAFE_API_KEY || '',
|
|
115
|
-
};
|
|
116
|
-
const child = spawn(
|
|
117
|
-
process.execPath,
|
|
118
|
-
[join(dirname(fileURLToPath(import.meta.url)), 'gateway.mjs'), ...configArgs(configPath)],
|
|
119
|
-
{
|
|
120
|
-
detached: true,
|
|
121
|
-
stdio: ['ignore', log, log],
|
|
122
|
-
env: childEnv,
|
|
123
|
-
},
|
|
124
|
-
);
|
|
125
|
-
child.unref();
|
|
126
|
-
// Wait for the listener so the session's first request finds it.
|
|
127
|
-
return { pid: child.pid, up: await waitFor(true) };
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (!(env.ANTHROPIC_BASE_URL ?? '').includes(`127.0.0.1:${port}`))
|
|
131
|
-
say('Claude Code does not use the gateway yet. Run /router:setup, then restart Claude Code.');
|
|
132
|
-
|
|
133
|
-
const running = await runningGateway();
|
|
134
|
-
if (running && !isOlderVersion(running.version, ROUTER_VERSION)) process.exit(0);
|
|
135
|
-
if (running && !(await retire(running))) process.exit(0);
|
|
136
|
-
if (!running && (await probe())) {
|
|
137
|
-
say(`port ${port} answers, but not as the router gateway`);
|
|
138
|
-
process.exit(0);
|
|
139
|
-
}
|
|
140
|
-
const { pid, up } = await start();
|
|
141
|
-
const verb = running ? `replaced ${running.version ?? 'an older gateway'} on` : 'started on';
|
|
142
|
-
say(`gateway ${ROUTER_VERSION} ${up ? verb : 'not answering yet on'} 127.0.0.1:${port} (pid ${pid})`);
|
|
143
|
-
process.exit(0);
|
package/scripts/gateway.mjs
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Daemon entry: local gateway on 127.0.0.1:<gateway.port>. Started by the plugin hooks or by hand.
|
|
3
|
-
import { createGateway } from '../lib/gateway.mjs';
|
|
4
|
-
import { IdleTracker } from '../lib/idle.mjs';
|
|
5
|
-
import { Router } from '../lib/router.mjs';
|
|
6
|
-
import { cliArg, loadRuntime } from '../lib/runtime.mjs';
|
|
7
|
-
import { ROUTER_VERSION } from '../lib/status.mjs';
|
|
8
|
-
import { housekeeping } from '../lib/store.mjs';
|
|
9
|
-
|
|
10
|
-
// On stop the port is released at once; open streams get this long to finish (Claude Code's request timeout).
|
|
11
|
-
const DRAIN_MS = 600_000;
|
|
12
|
-
const HOUSEKEEPING_MS = 3_600_000;
|
|
13
|
-
const IDLE_CHECK_MS = 60_000;
|
|
14
|
-
|
|
15
|
-
process.stderr.on('error', () => {}); // a full disk must not turn a log line into a crash
|
|
16
|
-
const log = (message) => process.stderr.write(`${new Date().toISOString()} router: ${message}\n`);
|
|
17
|
-
const onError = (error) => log(error.message);
|
|
18
|
-
|
|
19
|
-
// Every Claude Code session on the machine goes through this process, so a stray exception is logged, not fatal.
|
|
20
|
-
// Request state is per request and per session; the worst case after such an error is one misrouted turn.
|
|
21
|
-
process.on('uncaughtException', (error) => log(`uncaught exception: ${error.stack ?? error.message}`));
|
|
22
|
-
process.on('unhandledRejection', (reason) => log(`unhandled rejection: ${reason?.stack ?? reason}`));
|
|
23
|
-
|
|
24
|
-
let config;
|
|
25
|
-
let dataDir;
|
|
26
|
-
try {
|
|
27
|
-
({ config, dataDir } = loadRuntime(process.env, {
|
|
28
|
-
configPath: cliArg(process.argv, '--config'),
|
|
29
|
-
forceTier: cliArg(process.argv, '--force-tier'),
|
|
30
|
-
}));
|
|
31
|
-
} catch (error) {
|
|
32
|
-
log(`invalid configuration: ${error.message}`);
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
const { port, alias, idleShutdownMs } = config.gateway;
|
|
36
|
-
const router = new Router({ config, fetchFn: globalThis.fetch, dataDir, onError });
|
|
37
|
-
const activity = new IdleTracker();
|
|
38
|
-
const server = createGateway({ router, onError, activity });
|
|
39
|
-
|
|
40
|
-
server.on('error', (error) => {
|
|
41
|
-
if (error.code === 'EADDRINUSE') {
|
|
42
|
-
log(`port ${port} is in use, another gateway serves it: exiting`);
|
|
43
|
-
process.exit(0);
|
|
44
|
-
}
|
|
45
|
-
log(`server error: ${error.message}`);
|
|
46
|
-
process.exit(1);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
let stopping = false;
|
|
50
|
-
function stop(reason) {
|
|
51
|
-
if (stopping) return;
|
|
52
|
-
stopping = true;
|
|
53
|
-
log(`${reason}: no new connections, finishing open streams`);
|
|
54
|
-
server.close(() => process.exit(0));
|
|
55
|
-
server.closeIdleConnections();
|
|
56
|
-
setTimeout(() => process.exit(0), DRAIN_MS).unref();
|
|
57
|
-
}
|
|
58
|
-
process.once('SIGTERM', () => stop('SIGTERM'));
|
|
59
|
-
process.once('SIGINT', () => stop('SIGINT'));
|
|
60
|
-
|
|
61
|
-
if (idleShutdownMs > 0) {
|
|
62
|
-
const minutes = Math.round(idleShutdownMs / 60_000);
|
|
63
|
-
const check = () => {
|
|
64
|
-
if (activity.idle(idleShutdownMs)) stop(`idle for ${minutes} min, no turn waits for a tool`);
|
|
65
|
-
};
|
|
66
|
-
setInterval(check, Math.min(idleShutdownMs, IDLE_CHECK_MS)).unref();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function tidy() {
|
|
70
|
-
try {
|
|
71
|
-
housekeeping(dataDir);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
onError(error);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
tidy();
|
|
77
|
-
setInterval(tidy, HOUSEKEEPING_MS).unref();
|
|
78
|
-
|
|
79
|
-
server.listen(port, '127.0.0.1', () =>
|
|
80
|
-
log(`${ROUTER_VERSION} listening on http://127.0.0.1:${port} as ${alias} (pid ${process.pid})`),
|
|
81
|
-
);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Staged-only checks: Biome on staged .mjs/.json, Gitleaks on the staged diff.
|
|
3
|
-
# Full check/test/pack runs in pre-push.
|
|
4
|
-
set -euo pipefail
|
|
5
|
-
|
|
6
|
-
cd "$(git rev-parse --show-toplevel)"
|
|
7
|
-
|
|
8
|
-
biome=node_modules/.bin/biome
|
|
9
|
-
[ -x "$biome" ] || {
|
|
10
|
-
echo "pre-commit: $biome missing; run 'npm ci'" >&2
|
|
11
|
-
exit 1
|
|
12
|
-
}
|
|
13
|
-
command -v gitleaks >/dev/null || {
|
|
14
|
-
echo "pre-commit: gitleaks missing; run 'brew install gitleaks'" >&2
|
|
15
|
-
exit 1
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
files=()
|
|
19
|
-
while IFS= read -r -d '' f; do
|
|
20
|
-
case "$f" in *.mjs | *.json) files+=("$f") ;; esac
|
|
21
|
-
done < <(git diff --cached --name-only -z --diff-filter=ACMR)
|
|
22
|
-
|
|
23
|
-
if [ "${#files[@]}" -gt 0 ]; then
|
|
24
|
-
"$biome" check --no-errors-on-unmatched -- "${files[@]}"
|
|
25
|
-
fi
|
|
26
|
-
|
|
27
|
-
gitleaks git --pre-commit --staged --redact --verbose --no-banner
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# CI-equivalent validation before code leaves the machine (mirrors .github/workflows/ci.yml).
|
|
3
|
-
set -euo pipefail
|
|
4
|
-
|
|
5
|
-
cd "$(git rev-parse --show-toplevel)"
|
|
6
|
-
zero=0000000000000000000000000000000000000000
|
|
7
|
-
|
|
8
|
-
[ -x node_modules/.bin/biome ] || {
|
|
9
|
-
echo "pre-push: node_modules/.bin/biome missing; run 'npm ci'" >&2
|
|
10
|
-
exit 1
|
|
11
|
-
}
|
|
12
|
-
command -v gitleaks >/dev/null || {
|
|
13
|
-
echo "pre-push: gitleaks missing; run 'brew install gitleaks'" >&2
|
|
14
|
-
exit 1
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
ranges=()
|
|
18
|
-
while read -r _local_ref local_sha _remote_ref remote_sha; do
|
|
19
|
-
[ "$local_sha" = "$zero" ] && continue
|
|
20
|
-
if [ "$remote_sha" = "$zero" ]; then
|
|
21
|
-
ranges+=("$local_sha") # new remote branch: scan all reachable history
|
|
22
|
-
else
|
|
23
|
-
ranges+=("$remote_sha..$local_sha")
|
|
24
|
-
fi
|
|
25
|
-
done
|
|
26
|
-
|
|
27
|
-
[ "${#ranges[@]}" -eq 0 ] && exit 0 # deletion-only push
|
|
28
|
-
|
|
29
|
-
npm run check
|
|
30
|
-
npm test
|
|
31
|
-
npm run pack:dry
|
|
32
|
-
for range in "${ranges[@]}"; do
|
|
33
|
-
gitleaks git --redact --no-banner --log-opts="$range"
|
|
34
|
-
done
|
package/scripts/status.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// /router:status: routes, key state and the last routed turn of a session, as markdown.
|
|
3
|
-
// Usage: status.mjs [session id] [--config <path>]. It reads the configuration and starts nothing, so it is also
|
|
4
|
-
// the way to see why a router.json does not load.
|
|
5
|
-
import { cliArg, loadRuntime } from '../lib/runtime.mjs';
|
|
6
|
-
import { fetchStatus, statusReport } from '../lib/status.mjs';
|
|
7
|
-
|
|
8
|
-
const argv = process.argv.slice(2);
|
|
9
|
-
const configPath = cliArg(argv, '--config');
|
|
10
|
-
const session = argv.find((arg, i) => !arg.startsWith('--') && argv[i - 1] !== '--config');
|
|
11
|
-
|
|
12
|
-
let config;
|
|
13
|
-
try {
|
|
14
|
-
({ config } = loadRuntime(process.env, { configPath }));
|
|
15
|
-
} catch (error) {
|
|
16
|
-
// Exit 0: /router:status injects this output into a skill, and Claude Code drops a skill whose command fails.
|
|
17
|
-
process.stdout.write(`router: invalid configuration: ${error.message}\n`);
|
|
18
|
-
process.exit(0);
|
|
19
|
-
}
|
|
20
|
-
process.stdout.write(`${statusReport(await fetchStatus(config.gateway.port, session))}\n`);
|
package/scripts/statusline.mjs
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Status line: prints the model and effort that served the last routed turn.
|
|
3
|
-
// Usage in settings.json: "statusLine": { "command": "node <plugin>/scripts/statusline.mjs [wrapped command ...]" }.
|
|
4
|
-
// A wrapped command (for example claude-powerline) gets the same stdin; its output comes first.
|
|
5
|
-
import { spawn } from 'node:child_process';
|
|
6
|
-
import { text } from 'node:stream/consumers';
|
|
7
|
-
import { LEGACY_ALIAS } from '../lib/config.mjs';
|
|
8
|
-
import { loadRuntime } from '../lib/runtime.mjs';
|
|
9
|
-
import { fetchStatus, ROUTER_DISPLAY_NAME, statusSegment } from '../lib/status.mjs';
|
|
10
|
-
|
|
11
|
-
const input = await text(process.stdin);
|
|
12
|
-
const [command, ...args] = process.argv.slice(2);
|
|
13
|
-
// A broken router.json must not break the status line: skip the router segment, still run a wrapped command.
|
|
14
|
-
let config = null;
|
|
15
|
-
try {
|
|
16
|
-
({ config } = loadRuntime(process.env));
|
|
17
|
-
} catch {}
|
|
18
|
-
let payload = {};
|
|
19
|
-
try {
|
|
20
|
-
payload = JSON.parse(input);
|
|
21
|
-
} catch {}
|
|
22
|
-
|
|
23
|
-
const names = config ? [config.gateway.alias, LEGACY_ALIAS, ROUTER_DISPLAY_NAME] : [];
|
|
24
|
-
// `jev-router[1m]`: the suffix only tells Claude Code the window size.
|
|
25
|
-
const routed = [payload.model?.id, payload.model?.display_name].some((name) =>
|
|
26
|
-
names.includes(name?.replace(/\[1m\]$/, '')),
|
|
27
|
-
);
|
|
28
|
-
const [status] = await Promise.all([
|
|
29
|
-
routed ? fetchStatus(config.gateway.port, payload.session_id) : null,
|
|
30
|
-
command ? runWrapped(command, args, input) : null,
|
|
31
|
-
]);
|
|
32
|
-
if (routed) process.stdout.write(`${statusSegment(status)}\n`);
|
|
33
|
-
|
|
34
|
-
function runWrapped(cmd, argv, stdin) {
|
|
35
|
-
return new Promise((resolve) => {
|
|
36
|
-
const child = spawn(cmd, argv, { stdio: ['pipe', 'inherit', 'inherit'] });
|
|
37
|
-
child.on('error', (error) => {
|
|
38
|
-
process.stdout.write(`statusline: ${cmd}: ${error.message}\n`);
|
|
39
|
-
resolve();
|
|
40
|
-
});
|
|
41
|
-
child.on('close', resolve);
|
|
42
|
-
child.stdin.on('error', () => {}); // the wrapped command may exit without reading stdin
|
|
43
|
-
child.stdin.end(stdin);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
# Print model, session effort, per-turn effort, active skill and block types per assistant line.
|
|
3
|
-
# Usage: spike-check.sh ~/.claude/projects/<project>/<session>.jsonl
|
|
4
|
-
jq -r 'select(.type=="assistant") | [.timestamp[11:19], .message.model, (.effort // "-"), (.perTurnEffort // "-"), (.attributionSkill // "-"), ([.message.content[]?.type] | join(","))] | @tsv' "$1"
|
package/skills/high/SKILL.md
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: high
|
|
3
|
-
disable-model-invocation: true
|
|
4
|
-
description: Manual pin: run this turn on opus at xhigh effort. Use as /router:high <prompt>.
|
|
5
|
-
model: opus
|
|
6
|
-
effort: xhigh
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
Routing tier applied. Continue with the user's request as written. Do not mention the router.
|
package/skills/low/SKILL.md
DELETED
package/skills/medium/SKILL.md
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: medium
|
|
3
|
-
disable-model-invocation: true
|
|
4
|
-
description: Manual pin: run this turn on opus at high effort. Use as /router:medium <prompt>.
|
|
5
|
-
model: opus
|
|
6
|
-
effort: high
|
|
7
|
-
---
|
|
8
|
-
Routing tier applied. Continue with the user's request as written. Do not mention the router.
|
package/skills/micro/SKILL.md
DELETED
package/skills/setup/SKILL.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: setup
|
|
3
|
-
description: Point Claude Code at the router gateway. Adds `model` with the 1M window, `ANTHROPIC_BASE_URL`, tool search and the `/model` picker row to the user settings, and offers the status line.
|
|
4
|
-
disable-model-invocation: true
|
|
5
|
-
allowed-tools: Read, Edit, Write
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
Configure Claude Code for the router gateway. This session does not use the gateway until Claude Code restarts. When the file has `model: "jev-router[1m]"`, this session can fail its next request. So ask all questions first, write the file once, and write it last.
|
|
9
|
-
|
|
10
|
-
1. Read `~/.claude/settings.json`. If the file does not exist, start from `{}`. Read `~/.claude/router.json` if it exists.
|
|
11
|
-
2. The status line can show the model and effort of the last routed turn. The command is `node ${CLAUDE_PLUGIN_ROOT}/scripts/statusline.mjs`, followed by the current status line command if there is one (for example `node ${CLAUDE_PLUGIN_ROOT}/scripts/statusline.mjs claude-powerline`). Show the user the current `statusLine` value and the new one, and ask. Change `statusLine.command` only if the user agrees. Keep the other `statusLine` keys.
|
|
12
|
-
3. Prepare the new settings object in memory:
|
|
13
|
-
- `model`: `"jev-router[1m]"`. Claude Code does not know the model `jev-router` and assumes a 200K window; the `[1m]` suffix declares 1M. Claude Code strips the suffix before it sends the request. If `router.json` routes no model with a 1M `contextWindow`, use `"jev-router"`.
|
|
14
|
-
- `env.ANTHROPIC_BASE_URL`: `"http://127.0.0.1:43170"`. If `router.json` sets `gateway.port`, use that port.
|
|
15
|
-
- `env.ENABLE_TOOL_SEARCH`: `"true"`. With a custom `ANTHROPIC_BASE_URL`, Claude Code turns tool search off and loads every MCP tool schema into each request (about 50K tokens with the claude.ai connectors). This key keeps the schemas deferred, as with the Anthropic API.
|
|
16
|
-
- `env.CLAUDE_CODE_GATEWAY_HINT_HEADERS`: `"1"`. Claude Code then tells the gateway the class of each request (main turn, subagent, side request, compaction) instead of the gateway guessing it from the body.
|
|
17
|
-
- Remove `env.CLAUDE_CODE_MAX_CONTEXT_TOKENS`. Older versions of this setup wrote it; Claude Code ignores it for `jev-router`. The gateway sends a turn only to a model whose window holds the context, and drops the 1M beta header for a model with a smaller window.
|
|
18
|
-
- The `/model` picker row. In `modelPicker.options`, replace the row whose `model` is `"jev-router[1m]"`, `"jev-router"` or `"router"` (the name before 0.4.2), or append it if there is none:
|
|
19
|
-
`{ "model": "jev-router[1m]", "label": "Jev Router (auto)", "description": "Auto-selects the model and effort for each turn", "behavesAs": "claude-opus-5-5" }`.
|
|
20
|
-
If `modelPicker` does not exist, set it to `{ "options": [<the row>] }`. Keep the other rows and `replaceBuiltInOptions`. `behavesAs` names a model that Claude Code knows; without it, Claude Code rejects `jev-router` as a model that is not in its catalog. If `router.json` changes the `high` route, use the `id` of its model.
|
|
21
|
-
- Remove `env.ANTHROPIC_CUSTOM_MODEL_OPTION`, `env.ANTHROPIC_CUSTOM_MODEL_OPTION_NAME` and `env.ANTHROPIC_CUSTOM_MODEL_OPTION_DESCRIPTION`. Older versions of this setup wrote them; the `modelPicker` row replaces them.
|
|
22
|
-
- The `statusLine` change from step 2, if the user agreed.
|
|
23
|
-
- Keep every other key unchanged.
|
|
24
|
-
4. Tell the user, before you write the file:
|
|
25
|
-
- Restart Claude Code now. Until the restart, this session can show "There's an issue with the selected model (jev-router[1m])", because it still sends requests to Anthropic and not to the gateway.
|
|
26
|
-
- After the restart, the router serves each turn, and `/router:status` shows the routes and the last turn.
|
|
27
|
-
- The status line path contains the plugin version. After a plugin update, run `/router:setup` again.
|
|
28
|
-
- To stop the routing, remove `model`, `env.ANTHROPIC_BASE_URL`, `env.ENABLE_TOOL_SEARCH`, `env.CLAUDE_CODE_GATEWAY_HINT_HEADERS` and the `jev-router[1m]` row of `modelPicker.options`, and restore the status line command.
|
|
29
|
-
5. Write the whole object to `~/.claude/settings.json` with one Write call. Do not use a sequence of edits. Do nothing after this step.
|
|
30
|
-
|
|
31
|
-
Do not change any other file.
|
package/skills/status/SKILL.md
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: status
|
|
3
|
-
description: Show which model served the last turn, whether Jev routing is active, and the routing config.
|
|
4
|
-
disable-model-invocation: true
|
|
5
|
-
allowed-tools: Bash(node ${CLAUDE_PLUGIN_ROOT}/scripts/status.mjs *)
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
Router status:
|
|
9
|
-
|
|
10
|
-
!`node ${CLAUDE_PLUGIN_ROOT}/scripts/status.mjs ${CLAUDE_SESSION_ID}`
|
|
11
|
-
|
|
12
|
-
Show this status to the user as written. Do not add commentary.
|