@alexeiled/claude-router 1.21.2 → 1.22.1
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 +1 -1
- package/CHANGELOG.md +30 -0
- package/README.md +7 -7
- package/docs/activity-routing.md +56 -24
- package/docs/architecture.md +32 -20
- package/docs/configuration.md +4 -4
- package/docs/evaluation.md +21 -6
- package/docs/native-router.md +1 -1
- package/docs/user-guide.md +17 -15
- package/hooks/native-router.mjs +113 -8
- package/lib/activity-stats.mjs +5 -3
- package/lib/activity.mjs +29 -3
- package/lib/band.mjs +7 -2
- package/lib/classifier-apis.mjs +79 -24
- package/lib/classifier-client.mjs +16 -5
- package/lib/classifier-contract.mjs +47 -11
- package/lib/config.mjs +1 -1
- package/lib/decisions.mjs +51 -4
- package/lib/display.mjs +10 -6
- package/lib/facts.mjs +32 -1
- package/lib/panel.mjs +5 -3
- package/lib/route.mjs +32 -8
- package/lib/view.mjs +11 -1
- package/package.json +1 -1
package/lib/route.mjs
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
acceptActivity,
|
|
3
|
+
acceptPhase,
|
|
4
|
+
chooseActivity,
|
|
5
|
+
compareRoutes,
|
|
6
|
+
lateralMove,
|
|
7
|
+
routingActivity,
|
|
8
|
+
sameRequest,
|
|
9
|
+
} from './activity.mjs';
|
|
2
10
|
import { ACTIVITIES, rank, resolveRoute, routeSpec, sameRoute, TIERS } from './config.mjs';
|
|
3
11
|
import * as costs from './cost.mjs';
|
|
4
|
-
import { clip, completedSince, extractFacts } from './facts.mjs';
|
|
12
|
+
import { clip, completedSince, extractFacts, stripReminders } from './facts.mjs';
|
|
5
13
|
import { CONTEXT_FILL, decide, fitTier, initialState, sameTaskOf } from './policy.mjs';
|
|
6
14
|
import { canonicalModel } from './providers.mjs';
|
|
7
15
|
|
|
@@ -40,14 +48,24 @@ export function cellForModel(config, id) {
|
|
|
40
48
|
return null;
|
|
41
49
|
}
|
|
42
50
|
|
|
51
|
+
// The route a session model runs when no route names it: that model at the session's effort. Null for a model with a
|
|
52
|
+
// cell, and for one the config does not list.
|
|
53
|
+
export function ownRoute(config, model) {
|
|
54
|
+
if (cellForModel(config, model)) return null;
|
|
55
|
+
const key = Object.keys(config.models).find((k) => isSameModel(config.models[k].id, model));
|
|
56
|
+
return key ? { model: key, effort: null } : null;
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
export function emptyLoop(config, model) {
|
|
44
60
|
const cell = cellForModel(config, model);
|
|
45
61
|
return {
|
|
46
62
|
lastRoute: cell?.tier ?? config.baselineTier,
|
|
47
63
|
lastActivity: cell?.activity ?? null,
|
|
48
64
|
// The route (models key, effort) the last routed decision ran for `lastRoute`, kept as it ran: a routing mode or
|
|
49
|
-
// a route edit changes the config, never the route in use. Null until the first decision
|
|
50
|
-
route:
|
|
65
|
+
// a route edit changes the config, never the route in use. Null until the first decision, except on a session
|
|
66
|
+
// model no route names (ownRoute): it starts at the baseline tier but keeps running until a decision moves it.
|
|
67
|
+
// Taken as the baseline's route, repeated failures on it "escalated" to a weaker model.
|
|
68
|
+
route: ownRoute(config, model),
|
|
51
69
|
state: initialState(),
|
|
52
70
|
models: {},
|
|
53
71
|
resolutions: {},
|
|
@@ -103,19 +121,21 @@ export function prepareLoop(loop, messageCount) {
|
|
|
103
121
|
};
|
|
104
122
|
}
|
|
105
123
|
|
|
106
|
-
export function nativeFacts(config, loop, { messages, prompt, effort, turnId, contextTokens }) {
|
|
124
|
+
export function nativeFacts(config, loop, { messages, prompt, effort, turnId, contextTokens, progress = false }) {
|
|
107
125
|
const facts = extractFacts({ messages, output_config: { effort } }, loop, config.context);
|
|
108
|
-
if (typeof prompt === 'string') facts.prompt = clip(prompt, config.context.maxTextChars);
|
|
126
|
+
if (typeof prompt === 'string') facts.prompt = clip(stripReminders(prompt), config.context.maxTextChars);
|
|
109
127
|
// A move down on the same task waits out the dwell and for a checkpoint since the last model change: a passed check,
|
|
110
128
|
// or the success the running route's activity can show (completedSince).
|
|
111
129
|
const since = loop.switchedAt ?? { requests: 0, messageCount: 0 };
|
|
112
130
|
const downAllowed =
|
|
131
|
+
!progress &&
|
|
113
132
|
(loop.requests ?? 0) - since.requests >= config.policy.minDwellRequests &&
|
|
114
133
|
completedSince(messages, since.messageCount, activityOf(config, loop));
|
|
115
134
|
// A loop saved without the field counts as measured, keeping the vote streak.
|
|
116
135
|
return {
|
|
117
136
|
...facts,
|
|
118
137
|
downAllowed,
|
|
138
|
+
...(progress ? { progress: true } : {}),
|
|
119
139
|
pin: null,
|
|
120
140
|
contextTokens,
|
|
121
141
|
turnKey: turnId,
|
|
@@ -160,7 +180,11 @@ export function chooseRoute(config, loop, input) {
|
|
|
160
180
|
lastActivity: kept ? activityOf(config, loop) : applied.activity,
|
|
161
181
|
route: kept ? (loop.route ?? null) : applied.route,
|
|
162
182
|
turnId: facts.turnKey,
|
|
163
|
-
decision:
|
|
183
|
+
decision: {
|
|
184
|
+
...applied,
|
|
185
|
+
goal: !pin && config.activityRouting === 'on' ? acceptActivity(config, input.advice) : null,
|
|
186
|
+
taskPhase: !pin && config.activityRouting === 'on' ? acceptPhase(config, input.advice) : null,
|
|
187
|
+
},
|
|
164
188
|
suspended: false,
|
|
165
189
|
reviewedAt: loop.requests ?? 0,
|
|
166
190
|
};
|
|
@@ -305,7 +329,7 @@ function decideCell({ config, projected, facts, advice, state, now, incumbent, a
|
|
|
305
329
|
to: route,
|
|
306
330
|
// Returning to the base route needs no evidence, nor does the incumbent's own cell whose configured route changed
|
|
307
331
|
// (a routing mode, a route edit): the label is not what moves.
|
|
308
|
-
mass: activity === null || activity === incumbent.activity ? 1 : (advice?.
|
|
332
|
+
mass: activity === null || activity === incumbent.activity ? 1 : (routingActivity(config, advice)?.mass ?? 0),
|
|
309
333
|
hold: step.reason === 'hold',
|
|
310
334
|
sameTask: sameTaskOf(config, advice, facts),
|
|
311
335
|
facts,
|
package/lib/view.mjs
CHANGED
|
@@ -36,6 +36,10 @@ export function initialView(model) {
|
|
|
36
36
|
comparison: null,
|
|
37
37
|
probabilities: null,
|
|
38
38
|
activity: null,
|
|
39
|
+
goal: null,
|
|
40
|
+
taskPhase: null,
|
|
41
|
+
phaseChoice: null,
|
|
42
|
+
phaseProbabilities: null,
|
|
39
43
|
activityChoice: null,
|
|
40
44
|
activityProbabilities: null,
|
|
41
45
|
history: [],
|
|
@@ -87,6 +91,10 @@ export const CLEARED_READINGS = {
|
|
|
87
91
|
estimate: null,
|
|
88
92
|
activityChoice: null,
|
|
89
93
|
activityProbabilities: null,
|
|
94
|
+
goal: null,
|
|
95
|
+
taskPhase: null,
|
|
96
|
+
phaseChoice: null,
|
|
97
|
+
phaseProbabilities: null,
|
|
90
98
|
};
|
|
91
99
|
|
|
92
100
|
// The view patch for a tool continuation's route. In `on` the activity label is the route's, which a fallback to the
|
|
@@ -99,7 +107,9 @@ export function continuationView(config, decision, context) {
|
|
|
99
107
|
reason: decision.reason,
|
|
100
108
|
contextTokens: context.tokens,
|
|
101
109
|
contextKnown: context.known,
|
|
102
|
-
...(config.activityRouting === 'on'
|
|
110
|
+
...(config.activityRouting === 'on'
|
|
111
|
+
? { activity: decision.activity ?? null, goal: decision.goal ?? null, taskPhase: decision.taskPhase ?? null }
|
|
112
|
+
: {}),
|
|
103
113
|
};
|
|
104
114
|
}
|
|
105
115
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexeiled/claude-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.1",
|
|
4
4
|
"description": "Native Claude Code model and effort routing with Anthropic, DeepSeek, z.ai, MiniMax, MiMo and Kimi defaults, custom provider profiles, and classifier advice.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alexei Ledenev",
|