omnicell-router 0.1.0 → 0.2.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/RELEASING.md +238 -238
- package/RELEASING.zh-CN.md +230 -230
- package/backend/dist/capture/recorder.js +2 -1
- package/backend/dist/cli/clients/base.js +8 -16
- package/backend/dist/cli/clients/dsh.js +8 -16
- package/backend/dist/cli/clients/pi.js +16 -9
- package/backend/dist/cli/types.d.ts +5 -0
- package/backend/dist/config/env.js +2 -1
- package/backend/dist/config/index.js +2 -0
- package/backend/dist/config/types.d.ts +23 -0
- package/backend/dist/harness/adapters/amp.d.ts +2 -0
- package/backend/dist/harness/adapters/amp.js +7 -0
- package/backend/dist/harness/adapters/claude.d.ts +2 -0
- package/backend/dist/harness/adapters/claude.js +7 -0
- package/backend/dist/harness/adapters/cline.d.ts +2 -0
- package/backend/dist/harness/adapters/cline.js +6 -0
- package/backend/dist/harness/adapters/codex.d.ts +2 -0
- package/backend/dist/harness/adapters/codex.js +6 -0
- package/backend/dist/harness/adapters/cursor.d.ts +5 -0
- package/backend/dist/harness/adapters/cursor.js +10 -0
- package/backend/dist/harness/adapters/declarative.d.ts +62 -0
- package/backend/dist/harness/adapters/declarative.js +202 -0
- package/backend/dist/harness/adapters/dsh.d.ts +5 -0
- package/backend/dist/harness/adapters/dsh.js +6 -0
- package/backend/dist/harness/adapters/gemini-cli.d.ts +2 -0
- package/backend/dist/harness/adapters/gemini-cli.js +7 -0
- package/backend/dist/harness/adapters/github-copilot.d.ts +5 -0
- package/backend/dist/harness/adapters/github-copilot.js +10 -0
- package/backend/dist/harness/adapters/index.d.ts +44 -0
- package/backend/dist/harness/adapters/index.js +99 -0
- package/backend/dist/harness/adapters/opencode.d.ts +2 -0
- package/backend/dist/harness/adapters/opencode.js +55 -0
- package/backend/dist/harness/adapters/pi.d.ts +1 -0
- package/backend/dist/harness/adapters/pi.js +22 -0
- package/backend/dist/harness/adapters/skills-paths.d.ts +15 -0
- package/backend/dist/harness/adapters/skills-paths.js +17 -0
- package/backend/dist/harness/adapters/types.d.ts +174 -0
- package/backend/dist/harness/adapters/types.js +12 -0
- package/backend/dist/harness/adapters/universal.d.ts +6 -0
- package/backend/dist/harness/adapters/universal.js +10 -0
- package/backend/dist/harness/adapters/windsurf.d.ts +2 -0
- package/backend/dist/harness/adapters/windsurf.js +10 -0
- package/backend/dist/harness/adapters/zed.d.ts +2 -0
- package/backend/dist/harness/adapters/zed.js +6 -0
- package/backend/dist/harness/awesome-opencode.d.ts +40 -0
- package/backend/dist/harness/awesome-opencode.js +75 -0
- package/backend/dist/harness/browse.d.ts +202 -0
- package/backend/dist/harness/browse.js +1214 -0
- package/backend/dist/harness/catalog-npm.d.ts +59 -0
- package/backend/dist/harness/catalog-npm.js +145 -0
- package/backend/dist/harness/clawhub.d.ts +212 -0
- package/backend/dist/harness/clawhub.js +426 -0
- package/backend/dist/harness/config-file.d.ts +29 -0
- package/backend/dist/harness/config-file.js +35 -0
- package/backend/dist/harness/detail.d.ts +74 -0
- package/backend/dist/harness/detail.js +330 -0
- package/backend/dist/harness/discover.d.ts +118 -0
- package/backend/dist/harness/discover.js +507 -0
- package/backend/dist/harness/drift.d.ts +21 -0
- package/backend/dist/harness/drift.js +25 -0
- package/backend/dist/harness/hash.d.ts +10 -0
- package/backend/dist/harness/hash.js +63 -0
- package/backend/dist/harness/hosts.d.ts +18 -0
- package/backend/dist/harness/hosts.js +15 -0
- package/backend/dist/harness/install.d.ts +88 -0
- package/backend/dist/harness/install.js +301 -0
- package/backend/dist/harness/inventory.d.ts +10 -0
- package/backend/dist/harness/inventory.js +198 -0
- package/backend/dist/harness/ledger.d.ts +39 -0
- package/backend/dist/harness/ledger.js +83 -0
- package/backend/dist/harness/maintenance.d.ts +115 -0
- package/backend/dist/harness/maintenance.js +603 -0
- package/backend/dist/harness/manifest.d.ts +31 -0
- package/backend/dist/harness/manifest.js +234 -0
- package/backend/dist/harness/net.d.ts +86 -0
- package/backend/dist/harness/net.js +113 -0
- package/backend/dist/harness/opencode-cafe.d.ts +40 -0
- package/backend/dist/harness/opencode-cafe.js +85 -0
- package/backend/dist/harness/opencode-ecosystem.d.ts +34 -0
- package/backend/dist/harness/opencode-ecosystem.js +246 -0
- package/backend/dist/harness/pi-dev.d.ts +81 -0
- package/backend/dist/harness/pi-dev.js +187 -0
- package/backend/dist/harness/probe.d.ts +33 -0
- package/backend/dist/harness/probe.js +85 -0
- package/backend/dist/harness/registry.d.ts +2 -0
- package/backend/dist/harness/registry.js +26 -0
- package/backend/dist/harness/scopes.d.ts +21 -0
- package/backend/dist/harness/scopes.js +22 -0
- package/backend/dist/harness/skill-md.d.ts +18 -0
- package/backend/dist/harness/skill-md.js +71 -0
- package/backend/dist/harness/skills-sh.d.ts +109 -0
- package/backend/dist/harness/skills-sh.js +178 -0
- package/backend/dist/harness/smithery.d.ts +64 -0
- package/backend/dist/harness/smithery.js +146 -0
- package/backend/dist/harness/sources/awesome-opencode.d.ts +11 -0
- package/backend/dist/harness/sources/awesome-opencode.js +39 -0
- package/backend/dist/harness/sources/clawhub.d.ts +2 -0
- package/backend/dist/harness/sources/clawhub.js +83 -0
- package/backend/dist/harness/sources/github.d.ts +9 -0
- package/backend/dist/harness/sources/github.js +202 -0
- package/backend/dist/harness/sources/mcp-official.d.ts +2 -0
- package/backend/dist/harness/sources/mcp-official.js +110 -0
- package/backend/dist/harness/sources/npm.d.ts +2 -0
- package/backend/dist/harness/sources/npm.js +152 -0
- package/backend/dist/harness/sources/opencode-cafe.d.ts +11 -0
- package/backend/dist/harness/sources/opencode-cafe.js +41 -0
- package/backend/dist/harness/sources/smithery.d.ts +2 -0
- package/backend/dist/harness/sources/smithery.js +81 -0
- package/backend/dist/harness/spi.d.ts +98 -0
- package/backend/dist/harness/spi.js +8 -0
- package/backend/dist/harness/stars.d.ts +70 -0
- package/backend/dist/harness/stars.js +202 -0
- package/backend/dist/harness/translation.d.ts +142 -0
- package/backend/dist/harness/translation.js +567 -0
- package/backend/dist/harness/tree.d.ts +13 -0
- package/backend/dist/harness/tree.js +19 -0
- package/backend/dist/harness/types.d.ts +286 -0
- package/backend/dist/harness/types.js +8 -0
- package/backend/dist/harness/writers/extension.d.ts +116 -0
- package/backend/dist/harness/writers/extension.js +219 -0
- package/backend/dist/harness/writers/mcp.d.ts +72 -0
- package/backend/dist/harness/writers/mcp.js +195 -0
- package/backend/dist/harness/writers/skill.d.ts +60 -0
- package/backend/dist/harness/writers/skill.js +146 -0
- package/backend/dist/opencode/agents.d.ts +5 -0
- package/backend/dist/opencode/agents.js +10 -1
- package/backend/dist/opencode/catalog/cache.js +2 -1
- package/backend/dist/opencode/catalog/logos.js +2 -1
- package/backend/dist/opencode/catalog/ocr-store.js +2 -1
- package/backend/dist/opencode/catalog/overrides-store.js +2 -1
- package/backend/dist/opencode/credentials/factory.js +10 -27
- package/backend/dist/opencode/credentials/ocr-store.js +2 -1
- package/backend/dist/opencode/provider-defs.js +2 -1
- package/backend/dist/opencode/user-config.js +8 -16
- package/backend/dist/providers/registry.d.ts +15 -4
- package/backend/dist/providers/registry.js +29 -5
- package/backend/dist/providers/virtual-meta.d.ts +13 -0
- package/backend/dist/providers/virtual-meta.js +18 -0
- package/backend/dist/quota/store.js +2 -1
- package/backend/dist/resilience/breaker-state.js +2 -1
- package/backend/dist/resilience/credential-state.js +2 -1
- package/backend/dist/routes/console.js +137 -15
- package/backend/dist/routes/harness.d.ts +2 -0
- package/backend/dist/routes/harness.js +622 -0
- package/backend/dist/server.js +4 -0
- package/backend/dist/session/session-manager.js +2 -1
- package/backend/dist/surfaces/systemone-probe.d.ts +25 -0
- package/backend/dist/surfaces/systemone-probe.js +74 -0
- package/backend/dist/utils/atomic-write.d.ts +12 -0
- package/backend/dist/utils/atomic-write.js +29 -0
- package/bin/ocr.js +2 -2
- package/frontend/dist/assets/{index-DEo2iAT7.css → index-1o7qI-KJ.css} +1 -1
- package/frontend/dist/assets/index-DvXKvNxl.js +962 -0
- package/frontend/dist/index.html +2 -2
- package/package.json +87 -87
- package/backend/dist/budget/budget-manager.d.ts +0 -25
- package/backend/dist/budget/budget-manager.js +0 -54
- package/backend/dist/config/governance-limits.d.ts +0 -68
- package/backend/dist/config/governance-limits.js +0 -261
- package/backend/dist/flywheel/collector.d.ts +0 -74
- package/backend/dist/flywheel/collector.js +0 -235
- package/backend/dist/flywheel/dataset.d.ts +0 -130
- package/backend/dist/flywheel/dataset.js +0 -638
- package/backend/dist/flywheel/decision-capture.d.ts +0 -68
- package/backend/dist/flywheel/decision-capture.js +0 -85
- package/backend/dist/flywheel/prune.d.ts +0 -133
- package/backend/dist/flywheel/prune.js +0 -495
- package/backend/dist/flywheel/schema.d.ts +0 -108
- package/backend/dist/flywheel/schema.js +0 -117
- package/backend/dist/flywheel/trainer.d.ts +0 -84
- package/backend/dist/flywheel/trainer.js +0 -198
- package/backend/dist/opencode/catalog/custom-store.d.ts +0 -50
- package/backend/dist/opencode/catalog/custom-store.js +0 -144
- package/backend/dist/opencode/credentials/push.d.ts +0 -38
- package/backend/dist/opencode/credentials/push.js +0 -116
- package/backend/dist/opencode/credentials/reconcile.d.ts +0 -49
- package/backend/dist/opencode/credentials/reconcile.js +0 -216
- package/backend/dist/opencode/sync.d.ts +0 -29
- package/backend/dist/opencode/sync.js +0 -186
- package/backend/dist/pipeline/account-selection.d.ts +0 -101
- package/backend/dist/pipeline/account-selection.js +0 -112
- package/backend/dist/providers/systemone.d.ts +0 -29
- package/backend/dist/providers/systemone.js +0 -170
- package/backend/dist/ratelimit/duration.d.ts +0 -24
- package/backend/dist/ratelimit/duration.js +0 -43
- package/backend/dist/ratelimit/governance-runtime.d.ts +0 -121
- package/backend/dist/ratelimit/governance-runtime.js +0 -183
- package/backend/dist/ratelimit/index.d.ts +0 -4
- package/backend/dist/ratelimit/index.js +0 -4
- package/backend/dist/ratelimit/limiter.d.ts +0 -157
- package/backend/dist/ratelimit/limiter.js +0 -244
- package/backend/dist/ratelimit/sliding-window-counter.d.ts +0 -63
- package/backend/dist/ratelimit/sliding-window-counter.js +0 -103
- package/backend/dist/ratelimit/subject.d.ts +0 -26
- package/backend/dist/ratelimit/subject.js +0 -28
- package/backend/dist/resilience/account-state.d.ts +0 -84
- package/backend/dist/resilience/account-state.js +0 -228
- package/backend/dist/router/layer1-classifier.d.ts +0 -111
- package/backend/dist/router/layer1-classifier.js +0 -467
- package/backend/dist/router/layer2-judge.d.ts +0 -111
- package/backend/dist/router/layer2-judge.js +0 -373
- package/backend/dist/router/retry-escalation.d.ts +0 -89
- package/backend/dist/router/retry-escalation.js +0 -99
- package/backend/dist/routes/flywheel.d.ts +0 -3
- package/backend/dist/routes/flywheel.js +0 -268
- package/backend/dist/routes/systemone.d.ts +0 -3
- package/backend/dist/routes/systemone.js +0 -90
- package/backend/dist/surfaces/governance-envelope.d.ts +0 -34
- package/backend/dist/surfaces/governance-envelope.js +0 -47
- package/backend/dist/utils/token-estimator.d.ts +0 -7
- package/backend/dist/utils/token-estimator.js +0 -20
- package/frontend/dist/assets/index-nwgWkmU1.js +0 -840
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
import { EFFORT_LADDER } from '../types/router.js';
|
|
2
|
-
import { RoutingDecisionCache } from './decision-cache.js';
|
|
3
|
-
import { runSystemoneDecision } from '../protocols/systemone/decide.js';
|
|
4
|
-
import { captureDecision } from '../capture/decision-capture.js';
|
|
5
|
-
import { ErrorClassifier } from '../resilience/index.js';
|
|
6
|
-
import { recordFailureEvent } from '../observability/failure-events.js';
|
|
7
|
-
import { getWarnThrottle } from '../observability/warn-throttle.js';
|
|
8
|
-
const TIERS = ['lite', 'plus', 'pro', 'ultra'];
|
|
9
|
-
export class Layer2Judge {
|
|
10
|
-
static TIER_INSTRUCTIONS = 'Classify the computational task difficulty tier. NEVER judge difficulty by character length: ' +
|
|
11
|
-
'short prompts like "P=NP?" or "Prove Fermat\'s Last Theorem" are high-difficulty.';
|
|
12
|
-
/**
|
|
13
|
-
* Outcome of the LAST real wire attempt (console /auto surface). Cache
|
|
14
|
-
* hits never touch it: a cached serve is not a wire attempt and must not
|
|
15
|
-
* hide a persisting wire problem. In-memory only — a gateway restart
|
|
16
|
-
* starts blank, and the first attempt after boot re-records it.
|
|
17
|
-
*/
|
|
18
|
-
static lastOutcome = null;
|
|
19
|
-
/** Console read accessor (GET /api/admin/judge/outcome). */
|
|
20
|
-
static getLastOutcome() {
|
|
21
|
-
return Layer2Judge.lastOutcome;
|
|
22
|
-
}
|
|
23
|
-
static TIER_CRITERIA = {
|
|
24
|
-
lite: 'trivial QA, simple calculation, basic translation, shallow extraction, casual greetings',
|
|
25
|
-
plus: 'system architecture, complex software engineering, refactoring, creative generation, nuanced thinking — the default workhorse',
|
|
26
|
-
pro: 'deep mathematical proof, formal symbolic logic, NP-hard algorithmic complexity, hard research',
|
|
27
|
-
ultra: 'frontier-tier, hour-long autonomous agent tasks, hardest open-ended thinking',
|
|
28
|
-
};
|
|
29
|
-
static EFFORT_INSTRUCTIONS = 'Pick the thinking depth this task actually needs. Deeper thinking costs more time and tokens — ' +
|
|
30
|
-
'choose the LOWEST level that can produce a correct, complete answer.';
|
|
31
|
-
static EFFORT_CRITERIA = {
|
|
32
|
-
none: 'no thinking needed — direct answer suffices (greeting, lookup, trivial rewrite)',
|
|
33
|
-
low: 'light reasoning — simple Q&A, basic translation, shallow extraction',
|
|
34
|
-
medium: 'moderate reasoning — typical coding, summarization with judgment calls',
|
|
35
|
-
high: 'deep reasoning — system design, multi-step debugging, nuanced analysis',
|
|
36
|
-
xhigh: 'very deep reasoning — hard algorithmic work, formal proofs, research-grade problems',
|
|
37
|
-
max: 'maximum effort — frontier open-ended tasks where cost is no object',
|
|
38
|
-
};
|
|
39
|
-
/** Stable label for the decision-cache key namespace. */
|
|
40
|
-
static CACHE_SOURCE = 'systemone';
|
|
41
|
-
/**
|
|
42
|
-
* Cache-namespace split on the effortDecision gate (ADR-0012 §3): entries
|
|
43
|
-
* recorded with the effort question in play must never be served to a
|
|
44
|
-
* caller running with it off (or vice versa) — the stored answer set
|
|
45
|
-
* differs, so the namespace differs.
|
|
46
|
-
*/
|
|
47
|
-
static cacheSource(askEffort) {
|
|
48
|
-
return askEffort ? `${this.CACHE_SOURCE}+effort` : this.CACHE_SOURCE;
|
|
49
|
-
}
|
|
50
|
-
/** One-shot warnings: a misconfigured judge is a per-REQUEST condition, so
|
|
51
|
-
* a plain console.warn would flood the log once per uncached request. */
|
|
52
|
-
static warned = new Set();
|
|
53
|
-
static warnOnce(key, message) {
|
|
54
|
-
if (this.warned.has(key))
|
|
55
|
-
return;
|
|
56
|
-
this.warned.add(key);
|
|
57
|
-
console.warn(message);
|
|
58
|
-
}
|
|
59
|
-
// routing decision cache (LRU+TTL over judge results)
|
|
60
|
-
static decisionCache = null;
|
|
61
|
-
static getDecisionCache(config) {
|
|
62
|
-
// Singleton instance; the console's knob changes (enabled/ttl/maxEntries)
|
|
63
|
-
// hot-apply through applyConfig on every evaluate — no restart needed.
|
|
64
|
-
if (!this.decisionCache) {
|
|
65
|
-
this.decisionCache = new RoutingDecisionCache(config?.decisionCache);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
this.decisionCache.applyConfig(config?.decisionCache);
|
|
69
|
-
}
|
|
70
|
-
return this.decisionCache;
|
|
71
|
-
}
|
|
72
|
-
static getDecisionCacheStats() {
|
|
73
|
-
return (this.decisionCache || new RoutingDecisionCache({ enabled: false })).getStats();
|
|
74
|
-
}
|
|
75
|
-
static clearDecisionCache() {
|
|
76
|
-
this.decisionCache?.clear();
|
|
77
|
-
}
|
|
78
|
-
/** Build the System One request that asks for a difficulty tier. */
|
|
79
|
-
static buildRequest(state, modelId, askEffort) {
|
|
80
|
-
const criteria = {};
|
|
81
|
-
for (const tier of TIERS)
|
|
82
|
-
criteria[tier] = this.TIER_CRITERIA[tier];
|
|
83
|
-
const questions = {
|
|
84
|
-
tier: {
|
|
85
|
-
type: 'choice',
|
|
86
|
-
instructions: this.TIER_INSTRUCTIONS,
|
|
87
|
-
criteria,
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
if (askEffort) {
|
|
91
|
-
// ADR-0012 §1: the SAME call also judges the thinking depth — a
|
|
92
|
-
// choice over the full 6-level ladder, 'none' included (a legitimate
|
|
93
|
-
// "do not think" judgment). Asked only for client-omitted requests.
|
|
94
|
-
questions.effort = {
|
|
95
|
-
type: 'choice',
|
|
96
|
-
instructions: this.EFFORT_INSTRUCTIONS,
|
|
97
|
-
criteria: { ...this.EFFORT_CRITERIA },
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
model: modelId,
|
|
102
|
-
state,
|
|
103
|
-
questions,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
static toTier(answer) {
|
|
107
|
-
const choice = typeof answer?.choice === 'string' ? answer.choice.trim().toLowerCase() : '';
|
|
108
|
-
return TIERS.includes(choice) ? choice : null;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Tolerant effort-answer parse: anything outside the 6-level ladder
|
|
112
|
-
* (garbled choice, missing answer object) yields undefined — never an
|
|
113
|
-
* error. A bad effort answer must not sink a good tier decision.
|
|
114
|
-
*/
|
|
115
|
-
static toEffort(answer) {
|
|
116
|
-
const choice = typeof answer?.choice === 'string' ? answer.choice.trim().toLowerCase() : '';
|
|
117
|
-
if (!EFFORT_LADDER.includes(choice))
|
|
118
|
-
return undefined;
|
|
119
|
-
const raw = answer?.confidence;
|
|
120
|
-
const confidence = typeof raw === 'number' && Number.isFinite(raw)
|
|
121
|
-
? Math.min(1, Math.max(0, raw))
|
|
122
|
-
: 0.9;
|
|
123
|
-
return { effort: choice, confidence };
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Evaluate request using the Layer 2 decision model over the System One
|
|
127
|
-
* protocol. Returns null on any miss — a disabled judge, an unresolvable
|
|
128
|
-
* model, an upstream failure or a blown deadline all degrade gracefully to
|
|
129
|
-
* the caller's default (plus baseline) rather than throwing.
|
|
130
|
-
*
|
|
131
|
-
* `judgeCapture` is the OUTER request's capture identity (the orchestrator
|
|
132
|
-
* hands it through routeAsync when the capture master is on; undefined
|
|
133
|
-
* otherwise). The JUDGE-CALL gate is checked HERE, at judge entry, via the
|
|
134
|
-
* recorder accessor — three-tier master/sub chain (requestCapture.enabled
|
|
135
|
-
* master × systemone.enabled surface master × systemone.l2DecisionEnabled
|
|
136
|
-
* sub):
|
|
137
|
-
* a false verdict passes undefined down the whole chain — today's silence,
|
|
138
|
-
* zero behavior change when the flags are off.
|
|
139
|
-
*/
|
|
140
|
-
static async evaluate(request, config, registry, defaultModel, judgeCapture,
|
|
141
|
-
/** Owning turn's conversation session — threaded by the orchestrator so
|
|
142
|
-
* judge failures attribute to the conversation that suffered them. */
|
|
143
|
-
sessionId) {
|
|
144
|
-
if (!config?.enabled)
|
|
145
|
-
return null;
|
|
146
|
-
const requested = (config.model || '').trim();
|
|
147
|
-
const modelId = requested && requested !== 'auto' && requested !== 'default'
|
|
148
|
-
? requested
|
|
149
|
-
: (defaultModel || '').trim();
|
|
150
|
-
// An enabled judge that names nothing can never answer. Say so ONCE
|
|
151
|
-
// instead of degrading silently forever — this is exactly the upgrade
|
|
152
|
-
// path where a legacy `model: 'typesafe/jev'` (never a registered id)
|
|
153
|
-
// leaves Layer 2 permanently inert with no trace anywhere.
|
|
154
|
-
if (!modelId) {
|
|
155
|
-
this.warnOnce('unconfigured', '[Layer2Judge] enabled but no decision model resolves (classifier.layer2.model and ' +
|
|
156
|
-
'systemone.defaultModel are both unset) — every judgment falls back to the plus baseline.');
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
const model = registry.getModel(modelId);
|
|
160
|
-
if (!model) {
|
|
161
|
-
this.warnOnce(`missing:${modelId}`, `[Layer2Judge] decision model '${modelId}' is not a registered model — every judgment ` +
|
|
162
|
-
'falls back to the plus baseline. Register it, or point classifier.layer2.model at ' +
|
|
163
|
-
'systemone.defaultModel.');
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
// ADR-0012: the effort question rides the same call only when the gate
|
|
167
|
-
// is on AND the client omitted `reasoning_effort` (an explicit client
|
|
168
|
-
// value is never second-guessed — asking would be a wasted answer).
|
|
169
|
-
const askEffort = config.effortDecision === true && request.reasoning_effort === undefined;
|
|
170
|
-
// Extract recent conversational context for multi-turn awareness (last 4 turns)
|
|
171
|
-
const messages = request.messages || [];
|
|
172
|
-
const recentMessages = messages.length > 4 ? messages.slice(-4) : messages;
|
|
173
|
-
const userText = recentMessages
|
|
174
|
-
.map((m) => {
|
|
175
|
-
const role = m.role || 'user';
|
|
176
|
-
const content = typeof m.content === 'string'
|
|
177
|
-
? m.content
|
|
178
|
-
: Array.isArray(m.content)
|
|
179
|
-
? m.content.map((p) => p.text || '').join(' ')
|
|
180
|
-
: '';
|
|
181
|
-
return `${role}: ${content}`;
|
|
182
|
-
})
|
|
183
|
-
.join('\n');
|
|
184
|
-
// The cache key must describe EXACTLY what the model will see, otherwise two
|
|
185
|
-
// requests that differ only past the cut-off collide in the model but not
|
|
186
|
-
// in the cache (pointless upstream calls).
|
|
187
|
-
const state = userText.slice(0, 4000);
|
|
188
|
-
// reuse a prior identical-context decision before calling out
|
|
189
|
-
const decisionCache = this.getDecisionCache(config);
|
|
190
|
-
const cacheKey = RoutingDecisionCache.buildCacheKey(this.cacheSource(askEffort), model.id, state);
|
|
191
|
-
const cached = decisionCache.get(cacheKey);
|
|
192
|
-
if (cached) {
|
|
193
|
-
// Propagate the cached decision's code+params untouched; the cache hit
|
|
194
|
-
// itself is only a flag in params (no separate cache-hit code). Copy the
|
|
195
|
-
// params — never mutate the stored entry.
|
|
196
|
-
return {
|
|
197
|
-
targetTier: cached.targetTier,
|
|
198
|
-
confidence: cached.confidence,
|
|
199
|
-
reason: `[Decision Cache] ${cached.reason}`,
|
|
200
|
-
reasonCode: cached.reasonCode,
|
|
201
|
-
reasonParams: { ...cached.reasonParams, cached: true },
|
|
202
|
-
provider: model.provider,
|
|
203
|
-
model: model.id,
|
|
204
|
-
effort: cached.effort,
|
|
205
|
-
effortConfidence: cached.effortConfidence,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
const timeoutMs = config.timeoutMs || 5000;
|
|
209
|
-
const startedAt = Date.now();
|
|
210
|
-
// The judge's own deadline wins over the upstream's: System One is a fast
|
|
211
|
-
// decision surface, and a stale answer is worthless to a routing cascade.
|
|
212
|
-
// Aborting at the deadline stops the work for real where the transport
|
|
213
|
-
// allows it (native upstream) and at minimum suppresses the follow-up
|
|
214
|
-
// repair call we would otherwise fire AFTER we stopped waiting.
|
|
215
|
-
const controller = new AbortController();
|
|
216
|
-
let timer;
|
|
217
|
-
// An abandoned late result (the converted path cannot be cancelled
|
|
218
|
-
// mid-flight) must never reach the capture sink — the deadline flag is
|
|
219
|
-
// the only reliable "this answer was consumed" signal.
|
|
220
|
-
let timedOut = false;
|
|
221
|
-
// Wire-attempt failure reason (console /auto surface): cache hits never
|
|
222
|
-
// reach this path and never overwrite the record — a cached serve does
|
|
223
|
-
// not heal the underlying wire problem, so the warning must stay.
|
|
224
|
-
let failureReason;
|
|
225
|
-
const deadline = new Promise((resolve) => {
|
|
226
|
-
timer = setTimeout(() => {
|
|
227
|
-
timedOut = true;
|
|
228
|
-
controller.abort();
|
|
229
|
-
resolve(null);
|
|
230
|
-
}, timeoutMs);
|
|
231
|
-
});
|
|
232
|
-
// JUDGE-CALL CAPTURE gate (three-tier chain: requestCapture.enabled
|
|
233
|
-
// master × systemone.enabled surface master × systemone.l2DecisionEnabled
|
|
234
|
-
// sub — checked HERE via the recorder carried by the outer
|
|
235
|
-
// identity; master off means the orchestrator never even passes a ctx).
|
|
236
|
-
// ON: reuse the OUTER request's trace/session so the judge's wire call
|
|
237
|
-
// joins the routed turn's archive, labeled purpose 'l2-judge' to tell it
|
|
238
|
-
// from candidate-execution events. OFF: undefined = silence, the exact
|
|
239
|
-
// call shape as today.
|
|
240
|
-
const judgeCaptureCtx = judgeCapture && judgeCapture.recorder.isSystemoneJudgeCaptureEnabled()
|
|
241
|
-
? { ...judgeCapture, purpose: 'l2-judge' }
|
|
242
|
-
: undefined;
|
|
243
|
-
const pending = runSystemoneDecision(registry, this.buildRequest(state, model.id, askEffort), model, { signal: controller.signal, upstreamEventContext: judgeCaptureCtx })
|
|
244
|
-
.then((decision) => {
|
|
245
|
-
const answer = decision.response?.answers?.tier;
|
|
246
|
-
const tier = this.toTier(answer);
|
|
247
|
-
if (!tier) {
|
|
248
|
-
failureReason = 'unparseable decision payload';
|
|
249
|
-
return null;
|
|
250
|
-
}
|
|
251
|
-
// Partial success (ADR-0012 §1): the effort answer parses
|
|
252
|
-
// tolerantly — a garbled/missing one never sinks a good tier.
|
|
253
|
-
const effortAnswer = askEffort
|
|
254
|
-
? this.toEffort(decision.response?.answers?.effort)
|
|
255
|
-
: undefined;
|
|
256
|
-
// A native upstream's confidence is taken at face value, so a NaN or
|
|
257
|
-
// out-of-range value would flow verbatim into RoutingDecision (where
|
|
258
|
-
// JSON.stringify(NaN) silently becomes null on any serialized sink).
|
|
259
|
-
// The converted path is already clamped by convert.ts.
|
|
260
|
-
const raw = answer?.confidence;
|
|
261
|
-
const confidence = typeof raw === 'number' && Number.isFinite(raw)
|
|
262
|
-
? Math.min(1, Math.max(0, raw))
|
|
263
|
-
: 0.9;
|
|
264
|
-
const reason = decision.upstreamKind === 'native'
|
|
265
|
-
? `System One model ${model.id} classified this as ${tier}`
|
|
266
|
-
: `System One model ${model.id} classified this as ${tier} (self-reported, not yet calibrated)`;
|
|
267
|
-
const reasonCode = decision.upstreamKind === 'native' ? 'l2.system_one' : 'l2.system_one_uncalibrated';
|
|
268
|
-
// Opt-in dataset sink (classifier.layer2.collectEnabled, gated inside
|
|
269
|
-
// decision-capture): the judged pair is the raw material for distilling
|
|
270
|
-
// a native decision model. Recorded ONLY on the race-winner path — an
|
|
271
|
-
// abandoned late result must not pollute the dataset with an answer
|
|
272
|
-
// nobody consumed.
|
|
273
|
-
if (!timedOut) {
|
|
274
|
-
captureDecision({
|
|
275
|
-
model: model.id,
|
|
276
|
-
provider: model.provider,
|
|
277
|
-
upstreamKind: decision.upstreamKind,
|
|
278
|
-
state,
|
|
279
|
-
tier,
|
|
280
|
-
confidence,
|
|
281
|
-
latencyMs: Date.now() - startedAt,
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
targetTier: tier,
|
|
286
|
-
confidence,
|
|
287
|
-
reason,
|
|
288
|
-
reasonCode,
|
|
289
|
-
reasonParams: { model: model.id, tier, ...(effortAnswer ? { effort: effortAnswer.effort } : {}) },
|
|
290
|
-
provider: model.provider,
|
|
291
|
-
model: model.id,
|
|
292
|
-
effort: effortAnswer?.effort,
|
|
293
|
-
effortConfidence: effortAnswer?.confidence,
|
|
294
|
-
rawResponse: decision.response,
|
|
295
|
-
};
|
|
296
|
-
})
|
|
297
|
-
.catch((err) => {
|
|
298
|
-
failureReason = err instanceof Error ? err.message : String(err);
|
|
299
|
-
// Failure-ledger emission (judge role): the wire call itself failed.
|
|
300
|
-
// A rejection landing after the deadline already fired the race is
|
|
301
|
-
// skipped — the timeout branch owns that observation; recording both
|
|
302
|
-
// would double-count one abandoned call.
|
|
303
|
-
if (!timedOut) {
|
|
304
|
-
const diagnosis = ErrorClassifier.classify(err, model.id, model.provider);
|
|
305
|
-
recordFailureEvent({
|
|
306
|
-
model: model.id,
|
|
307
|
-
provider: model.provider,
|
|
308
|
-
errorClass: diagnosis.category,
|
|
309
|
-
status: diagnosis.statusCode,
|
|
310
|
-
message: failureReason,
|
|
311
|
-
role: 'judge',
|
|
312
|
-
sessionId,
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
return null;
|
|
316
|
-
});
|
|
317
|
-
try {
|
|
318
|
-
const outcome = await Promise.race([pending, deadline]);
|
|
319
|
-
if (!outcome) {
|
|
320
|
-
const error = timedOut ? `timeout after ${timeoutMs}ms` : failureReason || 'decision failed';
|
|
321
|
-
// Console-visible last-wire-attempt record (ADR-0011 observability):
|
|
322
|
-
// the /auto page shows the failure until a later attempt succeeds.
|
|
323
|
-
Layer2Judge.lastOutcome = {
|
|
324
|
-
ts: Date.now(),
|
|
325
|
-
modelId: model.id,
|
|
326
|
-
ok: false,
|
|
327
|
-
error,
|
|
328
|
-
};
|
|
329
|
-
// Failure-ledger emission for the deadline case: an abandoned wire
|
|
330
|
-
// request has no error object to classify, so it records as TIMEOUT
|
|
331
|
-
// (the catch handler skips its own row when this branch already
|
|
332
|
-
// fired — one abandoned call, one row).
|
|
333
|
-
if (timedOut) {
|
|
334
|
-
recordFailureEvent({
|
|
335
|
-
model: model.id,
|
|
336
|
-
provider: model.provider,
|
|
337
|
-
errorClass: 'TIMEOUT',
|
|
338
|
-
message: error,
|
|
339
|
-
role: 'judge',
|
|
340
|
-
sessionId,
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
// Throttled warn over the formerly silent failure modes: a dead
|
|
344
|
-
// judge used to produce nothing but a missing tier decision. One
|
|
345
|
-
// throttled line per failing model keeps the log honest without a
|
|
346
|
-
// QPS flood; the /auto last-outcome record above still carries the
|
|
347
|
-
// always-fresh single verdict.
|
|
348
|
-
getWarnThrottle().warn(`judge-wire:${model.id}`, `[ocr] judge wire call failed on ${model.id}: ${error}`);
|
|
349
|
-
return null;
|
|
350
|
-
}
|
|
351
|
-
Layer2Judge.lastOutcome = {
|
|
352
|
-
ts: Date.now(),
|
|
353
|
-
modelId: model.id,
|
|
354
|
-
ok: true,
|
|
355
|
-
latencyMs: Date.now() - startedAt,
|
|
356
|
-
};
|
|
357
|
-
decisionCache.set(cacheKey, {
|
|
358
|
-
targetTier: outcome.targetTier,
|
|
359
|
-
confidence: outcome.confidence,
|
|
360
|
-
reason: outcome.reason,
|
|
361
|
-
reasonCode: outcome.reasonCode,
|
|
362
|
-
reasonParams: outcome.reasonParams,
|
|
363
|
-
effort: outcome.effort,
|
|
364
|
-
effortConfidence: outcome.effortConfidence,
|
|
365
|
-
});
|
|
366
|
-
return outcome;
|
|
367
|
-
}
|
|
368
|
-
finally {
|
|
369
|
-
if (timer)
|
|
370
|
-
clearTimeout(timer);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { ReasoningEffort, TierLevel } from '../types/router.js';
|
|
2
|
-
import { ReasonParams } from '../types/router.js';
|
|
3
|
-
/**
|
|
4
|
-
* Retry detection + escalation planning (ADR-0011). A repeated prompt is the
|
|
5
|
-
* user's "this answer wasn't good enough" signal; the planner turns it into a
|
|
6
|
-
* monotonic quality step. Pure functions — all state lives on the
|
|
7
|
-
* ConversationSession (`retry` block), all effects flow through the normal
|
|
8
|
-
* ratchet/effort machinery. Nothing here touches a model or the network.
|
|
9
|
-
*
|
|
10
|
-
* Detection — ALL THREE conditions must hold (any miss = fresh question):
|
|
11
|
-
* 1. the previous completed turn's response SUCCEEDED (a failed turn leaves
|
|
12
|
-
* no retry-state trace, so a technical resend never counts),
|
|
13
|
-
* 2. the prompt is ≥ 20 normalized chars (single-word re-sends are noise),
|
|
14
|
-
* 3. the normalized prompt hash equals the previous turn's.
|
|
15
|
-
*
|
|
16
|
-
* Ladder (frozen design; counts from what ACTUALLY served last turn):
|
|
17
|
-
* attempt 1 → same tier, effort + 1 (written into the request's
|
|
18
|
-
* reasoning_effort; the existing effort machinery translates
|
|
19
|
-
* and clamps it — never above what the model can serve);
|
|
20
|
-
* attempt 2+ → tier + 1, effort falls back to default;
|
|
21
|
-
* ceiling → ultra tier, then no further proposals.
|
|
22
|
-
*
|
|
23
|
-
* Capability ceiling (decision A3): when a pinned model cannot serve the
|
|
24
|
-
* next effort level, the +1 step would clamp to a no-op — so the planner
|
|
25
|
-
* JUMPS STRAIGHT to tier + 1 ("if thinking harder is impossible, get a
|
|
26
|
-
* stronger thinker"). The pin itself is never broken for an effort step.
|
|
27
|
-
*/
|
|
28
|
-
/** Minimum normalized prompt length for the repeat to count as a retry. */
|
|
29
|
-
export declare const RETRY_MIN_PROMPT_CHARS = 20;
|
|
30
|
-
/** Per-session retry bookkeeping (stored on ConversationSession.retry). */
|
|
31
|
-
export interface SessionRetryState {
|
|
32
|
-
/** Normalized-prompt hash of the last COMPLETED turn. */
|
|
33
|
-
lastPromptHash?: string;
|
|
34
|
-
/** Whether that turn's response completed successfully. */
|
|
35
|
-
lastOutcomeOk?: boolean;
|
|
36
|
-
/** What actually served: tier (post-failover truth) and effective effort. */
|
|
37
|
-
lastTierUsed?: TierLevel;
|
|
38
|
-
lastEffortUsed?: ReasoningEffort;
|
|
39
|
-
/**
|
|
40
|
-
* Display snippet of the last turn's prompt (ADR-0011): carried solely so a
|
|
41
|
-
* later `correction` write-back can produce a READABLE route-entry row —
|
|
42
|
-
* without it the entry is a bare 16-hex hash nobody can identify on the
|
|
43
|
-
* console. Same privacy stance as the store's snippet: written only when
|
|
44
|
-
* `routeEntries.snippetEnabled` is on.
|
|
45
|
-
*/
|
|
46
|
-
lastSnippet?: string;
|
|
47
|
-
/** Consecutive same-prompt attempts observed so far (0 = not a retry). */
|
|
48
|
-
retryCount?: number;
|
|
49
|
-
/** Whether THAT turn applied an escalation (feeds correction write-back). */
|
|
50
|
-
escalated?: boolean;
|
|
51
|
-
}
|
|
52
|
-
export interface RetryDetection {
|
|
53
|
-
isRetry: boolean;
|
|
54
|
-
/** 1-based attempt number when isRetry, else 0. */
|
|
55
|
-
attempt: number;
|
|
56
|
-
}
|
|
57
|
-
/** Pure three-condition check against the previous turn's recorded state. */
|
|
58
|
-
export declare function detectRetry(prev: SessionRetryState | undefined, currentHash: string | undefined): RetryDetection;
|
|
59
|
-
/** Next rung up the effort ladder; undefined at the ceiling ('max'). */
|
|
60
|
-
export declare function nextEffort(effort: ReasoningEffort | undefined): ReasoningEffort | undefined;
|
|
61
|
-
/** Next tier up; undefined at the 'ultra' ceiling. */
|
|
62
|
-
export declare function nextTier(tier: TierLevel): TierLevel | undefined;
|
|
63
|
-
export interface EscalationPlan {
|
|
64
|
-
action: 'none' | 'effort' | 'tier';
|
|
65
|
-
/** action='tier': the proposed (already ceiling-capped) tier. */
|
|
66
|
-
tier?: TierLevel;
|
|
67
|
-
/** action='effort': the requested effort to write into the request. */
|
|
68
|
-
effort?: ReasoningEffort;
|
|
69
|
-
reason: string;
|
|
70
|
-
reasonCode: 'retry.effort' | 'retry.tier';
|
|
71
|
-
reasonParams: ReasonParams;
|
|
72
|
-
}
|
|
73
|
-
export interface PlanInput {
|
|
74
|
-
attempt: number;
|
|
75
|
-
/** What actually served last turn (post-failover truth). */
|
|
76
|
-
lastTierUsed: TierLevel;
|
|
77
|
-
lastEffortUsed?: ReasoningEffort;
|
|
78
|
-
/**
|
|
79
|
-
* Effort levels the pinned model can serve (undefined = unknown — the
|
|
80
|
-
* planner then assumes servable and lets the executor's clamp decide).
|
|
81
|
-
*/
|
|
82
|
-
pinnedSupportedEfforts?: readonly ReasoningEffort[];
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* One escalation step for the given attempt. Never proposes below the last
|
|
86
|
-
* served tier, never past 'ultra'. The A3 capability jump lives here: an
|
|
87
|
-
* effort level the pin cannot serve becomes a tier step instead.
|
|
88
|
-
*/
|
|
89
|
-
export declare function planEscalation(input: PlanInput): EscalationPlan;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { EFFORT_LADDER, TIER_RANK } from '../types/router.js';
|
|
2
|
-
/**
|
|
3
|
-
* Retry detection + escalation planning (ADR-0011). A repeated prompt is the
|
|
4
|
-
* user's "this answer wasn't good enough" signal; the planner turns it into a
|
|
5
|
-
* monotonic quality step. Pure functions — all state lives on the
|
|
6
|
-
* ConversationSession (`retry` block), all effects flow through the normal
|
|
7
|
-
* ratchet/effort machinery. Nothing here touches a model or the network.
|
|
8
|
-
*
|
|
9
|
-
* Detection — ALL THREE conditions must hold (any miss = fresh question):
|
|
10
|
-
* 1. the previous completed turn's response SUCCEEDED (a failed turn leaves
|
|
11
|
-
* no retry-state trace, so a technical resend never counts),
|
|
12
|
-
* 2. the prompt is ≥ 20 normalized chars (single-word re-sends are noise),
|
|
13
|
-
* 3. the normalized prompt hash equals the previous turn's.
|
|
14
|
-
*
|
|
15
|
-
* Ladder (frozen design; counts from what ACTUALLY served last turn):
|
|
16
|
-
* attempt 1 → same tier, effort + 1 (written into the request's
|
|
17
|
-
* reasoning_effort; the existing effort machinery translates
|
|
18
|
-
* and clamps it — never above what the model can serve);
|
|
19
|
-
* attempt 2+ → tier + 1, effort falls back to default;
|
|
20
|
-
* ceiling → ultra tier, then no further proposals.
|
|
21
|
-
*
|
|
22
|
-
* Capability ceiling (decision A3): when a pinned model cannot serve the
|
|
23
|
-
* next effort level, the +1 step would clamp to a no-op — so the planner
|
|
24
|
-
* JUMPS STRAIGHT to tier + 1 ("if thinking harder is impossible, get a
|
|
25
|
-
* stronger thinker"). The pin itself is never broken for an effort step.
|
|
26
|
-
*/
|
|
27
|
-
/** Minimum normalized prompt length for the repeat to count as a retry. */
|
|
28
|
-
export const RETRY_MIN_PROMPT_CHARS = 20;
|
|
29
|
-
/** Pure three-condition check against the previous turn's recorded state. */
|
|
30
|
-
export function detectRetry(prev, currentHash) {
|
|
31
|
-
if (!currentHash || !prev?.lastPromptHash || prev.lastOutcomeOk !== true) {
|
|
32
|
-
return { isRetry: false, attempt: 0 };
|
|
33
|
-
}
|
|
34
|
-
if (currentHash !== prev.lastPromptHash) {
|
|
35
|
-
return { isRetry: false, attempt: 0 };
|
|
36
|
-
}
|
|
37
|
-
const attempt = (prev.retryCount ?? 0) + 1;
|
|
38
|
-
return { isRetry: true, attempt };
|
|
39
|
-
}
|
|
40
|
-
/** Next rung up the effort ladder; undefined at the ceiling ('max'). */
|
|
41
|
-
export function nextEffort(effort) {
|
|
42
|
-
const idx = EFFORT_LADDER.indexOf(effort ?? 'none');
|
|
43
|
-
if (idx < 0 || idx >= EFFORT_LADDER.length - 1)
|
|
44
|
-
return undefined;
|
|
45
|
-
return EFFORT_LADDER[idx + 1];
|
|
46
|
-
}
|
|
47
|
-
/** Next tier up; undefined at the 'ultra' ceiling. */
|
|
48
|
-
export function nextTier(tier) {
|
|
49
|
-
const rank = TIER_RANK[tier] ?? 2;
|
|
50
|
-
const next = Object.keys(TIER_RANK).find((t) => (TIER_RANK[t] ?? 2) === rank + 1);
|
|
51
|
-
return next;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* One escalation step for the given attempt. Never proposes below the last
|
|
55
|
-
* served tier, never past 'ultra'. The A3 capability jump lives here: an
|
|
56
|
-
* effort level the pin cannot serve becomes a tier step instead.
|
|
57
|
-
*/
|
|
58
|
-
export function planEscalation(input) {
|
|
59
|
-
const { attempt, lastTierUsed, lastEffortUsed } = input;
|
|
60
|
-
const params = { attempt };
|
|
61
|
-
if (attempt <= 1) {
|
|
62
|
-
const candidate = nextEffort(lastEffortUsed);
|
|
63
|
-
const servable = candidate !== undefined &&
|
|
64
|
-
(!input.pinnedSupportedEfforts || input.pinnedSupportedEfforts.includes(candidate));
|
|
65
|
-
if (servable && candidate) {
|
|
66
|
-
return {
|
|
67
|
-
action: 'effort',
|
|
68
|
-
effort: candidate,
|
|
69
|
-
reason: `Repeated prompt — raising reasoning effort to '${candidate}' on ${lastTierUsed}`,
|
|
70
|
-
reasonCode: 'retry.effort',
|
|
71
|
-
reasonParams: { ...params, tier: lastTierUsed, effort: candidate },
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
// No next effort (ceiling) or the pin cannot serve it (A3 jump).
|
|
75
|
-
const tier = nextTier(lastTierUsed);
|
|
76
|
-
if (!tier) {
|
|
77
|
-
return { action: 'none', reason: 'Repeated prompt — already at the ultra ceiling', reasonCode: 'retry.tier', reasonParams: params };
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
action: 'tier',
|
|
81
|
-
tier,
|
|
82
|
-
reason: `Repeated prompt — effort ceiling reached on ${lastTierUsed}, escalating tier to ${tier}`,
|
|
83
|
-
reasonCode: 'retry.tier',
|
|
84
|
-
reasonParams: { ...params, from: lastTierUsed, to: tier, cause: 'effort_ceiling' },
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
// attempt >= 2: tier + 1, effort falls back to default.
|
|
88
|
-
const tier = nextTier(lastTierUsed);
|
|
89
|
-
if (!tier) {
|
|
90
|
-
return { action: 'none', reason: 'Repeated prompt — already at the ultra ceiling', reasonCode: 'retry.tier', reasonParams: params };
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
action: 'tier',
|
|
94
|
-
tier,
|
|
95
|
-
reason: `Repeated prompt (attempt ${attempt}) — escalating tier ${lastTierUsed} → ${tier}`,
|
|
96
|
-
reasonCode: 'retry.tier',
|
|
97
|
-
reasonParams: { ...params, from: lastTierUsed, to: tier },
|
|
98
|
-
};
|
|
99
|
-
}
|