open-multi-agent-kit 0.90.3 → 0.90.5
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/CHANGELOG.md +38 -0
- package/README.md +16 -14
- package/dist/config.d.ts +3 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +27 -19
- package/dist/config.js.map +1 -1
- package/dist/core/adaptorch-bridge.d.ts +250 -0
- package/dist/core/adaptorch-bridge.d.ts.map +1 -0
- package/dist/core/adaptorch-bridge.js +466 -0
- package/dist/core/adaptorch-bridge.js.map +1 -0
- package/dist/core/agent-session.d.ts +97 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +194 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bang-skill-invocation.d.ts.map +1 -1
- package/dist/core/bang-skill-invocation.js +149 -0
- package/dist/core/bang-skill-invocation.js.map +1 -1
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js +15 -2
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/context-budget-v2-planner.d.ts.map +1 -1
- package/dist/core/context-budget-v2-planner.js +10 -2
- package/dist/core/context-budget-v2-planner.js.map +1 -1
- package/dist/core/context-budget-v2-types.d.ts +7 -1
- package/dist/core/context-budget-v2-types.d.ts.map +1 -1
- package/dist/core/context-budget-v2-types.js.map +1 -1
- package/dist/core/domain-loadouts.d.ts.map +1 -1
- package/dist/core/domain-loadouts.js +1 -1
- package/dist/core/domain-loadouts.js.map +1 -1
- package/dist/core/reasoning-router-bias.d.ts +107 -0
- package/dist/core/reasoning-router-bias.d.ts.map +1 -0
- package/dist/core/reasoning-router-bias.js +278 -0
- package/dist/core/reasoning-router-bias.js.map +1 -0
- package/dist/core/reasoning-router-resolver.d.ts +44 -0
- package/dist/core/reasoning-router-resolver.d.ts.map +1 -0
- package/dist/core/reasoning-router-resolver.js +79 -0
- package/dist/core/reasoning-router-resolver.js.map +1 -0
- package/dist/core/reasoning-router-v4-weights.d.ts +80 -0
- package/dist/core/reasoning-router-v4-weights.d.ts.map +1 -0
- package/dist/core/reasoning-router-v4-weights.js +68 -0
- package/dist/core/reasoning-router-v4-weights.js.map +1 -0
- package/dist/core/reasoning-router-v4.d.ts +118 -0
- package/dist/core/reasoning-router-v4.d.ts.map +1 -0
- package/dist/core/reasoning-router-v4.js +585 -0
- package/dist/core/reasoning-router-v4.js.map +1 -0
- package/dist/core/router-feedback-collector.d.ts +98 -0
- package/dist/core/router-feedback-collector.d.ts.map +1 -0
- package/dist/core/router-feedback-collector.js +236 -0
- package/dist/core/router-feedback-collector.js.map +1 -0
- package/dist/core/settings-manager.d.ts +28 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +16 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +4 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/modes/interactive/components/control-panel-runtime-status.d.ts +15 -0
- package/dist/modes/interactive/components/control-panel-runtime-status.d.ts.map +1 -1
- package/dist/modes/interactive/components/control-panel-runtime-status.js +95 -5
- package/dist/modes/interactive/components/control-panel-runtime-status.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +4 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +60 -17
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/loadout-domains/README.md +8 -6
- package/docs/loadout-domains/ai-agent-ops.md +3 -2
- package/docs/loadout-domains/backend-api.md +3 -2
- package/docs/loadout-domains/data-science.md +3 -2
- package/docs/loadout-domains/devops-infra.md +2 -1
- package/docs/loadout-domains/docs-writing.md +7 -2
- package/docs/loadout-domains/frontend-ui.md +42 -11
- package/docs/loadout-domains/korean-document.md +83 -0
- package/docs/loadout-domains/mobile.md +1 -1
- package/docs/loadout-domains/qa-testing.md +4 -2
- package/docs/loadout-domains/security-audit.md +2 -1
- package/docs/loadout-domains/visual-qa.md +94 -0
- package/docs/skills.md +4 -1
- package/docs/usage.md +36 -3
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/subagent/agent-capability-router.test.ts +123 -0
- package/examples/extensions/subagent/agent-capability-router.ts +274 -0
- package/examples/extensions/subagent/agents/planner.md +3 -0
- package/examples/extensions/subagent/agents/reviewer.md +3 -0
- package/examples/extensions/subagent/agents/scout.md +3 -0
- package/examples/extensions/subagent/agents/worker.md +2 -0
- package/examples/extensions/subagent/agents.ts +14 -0
- package/examples/extensions/subagent/capabilities.ts +368 -0
- package/examples/extensions/subagent/domain-profiles.ts +1089 -0
- package/examples/extensions/subagent/index.ts +71 -3
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/12-full-control.ts +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
- package/dist/agents/jailbreak/index.d.ts +0 -7
- package/dist/agents/jailbreak/index.d.ts.map +0 -1
- package/dist/agents/jailbreak/index.js +0 -7
- package/dist/agents/jailbreak/index.js.map +0 -1
- package/dist/agents/jailbreak/subagent-f.d.ts +0 -44
- package/dist/agents/jailbreak/subagent-f.d.ts.map +0 -1
- package/dist/agents/jailbreak/subagent-f.js +0 -60
- package/dist/agents/jailbreak/subagent-f.js.map +0 -1
- package/dist/cli/jailbreak-args.d.ts +0 -26
- package/dist/cli/jailbreak-args.d.ts.map +0 -1
- package/dist/cli/jailbreak-args.js +0 -86
- package/dist/cli/jailbreak-args.js.map +0 -1
- package/dist/commands/jailbreak.d.ts +0 -49
- package/dist/commands/jailbreak.d.ts.map +0 -1
- package/dist/commands/jailbreak.js +0 -201
- package/dist/commands/jailbreak.js.map +0 -1
- package/dist/core/compactor.d.ts +0 -42
- package/dist/core/compactor.d.ts.map +0 -1
- package/dist/core/compactor.js +0 -128
- package/dist/core/compactor.js.map +0 -1
- package/dist/core/token-optimizer.d.ts +0 -58
- package/dist/core/token-optimizer.d.ts.map +0 -1
- package/dist/core/token-optimizer.js +0 -179
- package/dist/core/token-optimizer.js.map +0 -1
- package/dist/encoding/index.d.ts +0 -6
- package/dist/encoding/index.d.ts.map +0 -1
- package/dist/encoding/index.js +0 -6
- package/dist/encoding/index.js.map +0 -1
- package/dist/encoding/l4-encoder.d.ts +0 -96
- package/dist/encoding/l4-encoder.d.ts.map +0 -1
- package/dist/encoding/l4-encoder.js +0 -474
- package/dist/encoding/l4-encoder.js.map +0 -1
- package/dist/fuzzing/index.d.ts +0 -6
- package/dist/fuzzing/index.d.ts.map +0 -1
- package/dist/fuzzing/index.js +0 -6
- package/dist/fuzzing/index.js.map +0 -1
- package/dist/fuzzing/mutation-engine.d.ts +0 -93
- package/dist/fuzzing/mutation-engine.d.ts.map +0 -1
- package/dist/fuzzing/mutation-engine.js +0 -244
- package/dist/fuzzing/mutation-engine.js.map +0 -1
- package/dist/jailbreak-extension.d.ts +0 -48
- package/dist/jailbreak-extension.d.ts.map +0 -1
- package/dist/jailbreak-extension.js +0 -47
- package/dist/jailbreak-extension.js.map +0 -1
- package/dist/modules/index.d.ts +0 -8
- package/dist/modules/index.d.ts.map +0 -1
- package/dist/modules/index.js +0 -7
- package/dist/modules/index.js.map +0 -1
- package/dist/modules/lrl-bypass.d.ts +0 -40
- package/dist/modules/lrl-bypass.d.ts.map +0 -1
- package/dist/modules/lrl-bypass.js +0 -84
- package/dist/modules/lrl-bypass.js.map +0 -1
- package/dist/modules/lrl-deps.d.ts +0 -38
- package/dist/modules/lrl-deps.d.ts.map +0 -1
- package/dist/modules/lrl-deps.js +0 -128
- package/dist/modules/lrl-deps.js.map +0 -1
- package/dist/multiturn/easl-chain.d.ts +0 -113
- package/dist/multiturn/easl-chain.d.ts.map +0 -1
- package/dist/multiturn/easl-chain.js +0 -351
- package/dist/multiturn/easl-chain.js.map +0 -1
- package/dist/multiturn/index.d.ts +0 -6
- package/dist/multiturn/index.d.ts.map +0 -1
- package/dist/multiturn/index.js +0 -6
- package/dist/multiturn/index.js.map +0 -1
- package/dist/routing/fallback-router.d.ts +0 -123
- package/dist/routing/fallback-router.d.ts.map +0 -1
- package/dist/routing/fallback-router.js +0 -355
- package/dist/routing/fallback-router.js.map +0 -1
- package/dist/routing/index.d.ts +0 -6
- package/dist/routing/index.d.ts.map +0 -1
- package/dist/routing/index.js +0 -6
- package/dist/routing/index.js.map +0 -1
- package/dist/types/jailbreak.d.ts +0 -246
- package/dist/types/jailbreak.d.ts.map +0 -1
- package/dist/types/jailbreak.js +0 -8
- package/dist/types/jailbreak.js.map +0 -1
- package/dist/utils/jailbreak/common.d.ts +0 -63
- package/dist/utils/jailbreak/common.d.ts.map +0 -1
- package/dist/utils/jailbreak/common.js +0 -130
- package/dist/utils/jailbreak/common.js.map +0 -1
- package/dist/utils/jailbreak/index.d.ts +0 -7
- package/dist/utils/jailbreak/index.d.ts.map +0 -1
- package/dist/utils/jailbreak/index.js +0 -7
- package/dist/utils/jailbreak/index.js.map +0 -1
|
@@ -32,6 +32,9 @@ import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
|
32
32
|
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
33
33
|
import { assertLoadoutAccess, decideLoadoutAccess } from "./loadout-access-policy.js";
|
|
34
34
|
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
35
|
+
import { getBiasStepsForCell, getDefaultRouterBiasSnapshotPath, parseRouterBiasSnapshot, } from "./reasoning-router-bias.js";
|
|
36
|
+
import { classifyTaskV4, resolveThinkingLevelV4WithUncertainty } from "./reasoning-router-v4.js";
|
|
37
|
+
import { appendRouterFeedbackRecord, } from "./router-feedback-collector.js";
|
|
35
38
|
import { detectSandboxBackend } from "./sandbox/backend.js";
|
|
36
39
|
import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
|
|
37
40
|
import { createSyntheticSourceInfo } from "./source-info.js";
|
|
@@ -98,6 +101,27 @@ export class AgentSession {
|
|
|
98
101
|
sessionManager;
|
|
99
102
|
settingsManager;
|
|
100
103
|
_scopedModels;
|
|
104
|
+
/**
|
|
105
|
+
* Thinking mode (default "manual"). Persists across turns within the session;
|
|
106
|
+
* auto-resolved levels are never written to the user's persisted settings.
|
|
107
|
+
*/
|
|
108
|
+
_thinkingMode = "manual";
|
|
109
|
+
/**
|
|
110
|
+
* N=8 ring buffer of recent auto-turn task classes (newest first), feeding
|
|
111
|
+
* v4's multi-turn prior feature. Never persisted to settings.
|
|
112
|
+
*/
|
|
113
|
+
_taskClassHistory = [];
|
|
114
|
+
/**
|
|
115
|
+
* Compiled reasoning-router bias snapshot for the opt-in v4 learning path
|
|
116
|
+
* (Goal 010 Lane I). Loaded at most once per session and pinned thereafter:
|
|
117
|
+
* `_reasoningRouterBiasSnapshotLoaded` flips to `true` on the first v4
|
|
118
|
+
* auto-turn that has learning enabled, and `_reasoningRouterBiasSnapshot`
|
|
119
|
+
* then stays fixed for the rest of the session (even across later settings
|
|
120
|
+
* reloads, and even if the on-disk file changes or the load failed/was
|
|
121
|
+
* invalid, in which case it stays `null`). See `_getReasoningRouterBiasSnapshot`.
|
|
122
|
+
*/
|
|
123
|
+
_reasoningRouterBiasSnapshot = null;
|
|
124
|
+
_reasoningRouterBiasSnapshotLoaded = false;
|
|
101
125
|
// Event subscription state
|
|
102
126
|
_unsubscribeAgent;
|
|
103
127
|
_eventListeners = [];
|
|
@@ -552,6 +576,10 @@ export class AgentSession {
|
|
|
552
576
|
get thinkingLevel() {
|
|
553
577
|
return this.agent.state.thinkingLevel;
|
|
554
578
|
}
|
|
579
|
+
/** Current thinking mode ("manual" = user-selected level, "auto" = per-turn router) */
|
|
580
|
+
get thinkingMode() {
|
|
581
|
+
return this._thinkingMode;
|
|
582
|
+
}
|
|
555
583
|
/** Whether agent is currently streaming a response */
|
|
556
584
|
get isStreaming() {
|
|
557
585
|
return this.agent.state.isStreaming;
|
|
@@ -954,6 +982,9 @@ export class AgentSession {
|
|
|
954
982
|
this._flushPendingBashMessages();
|
|
955
983
|
}
|
|
956
984
|
}
|
|
985
|
+
// Auto thinking mode: resolve this turn's level from the prompt content.
|
|
986
|
+
// Manual mode never enters the router, so /think <level> always wins.
|
|
987
|
+
this._applyAutoThinkingLevelForTurn(expandedText);
|
|
957
988
|
// Build messages array (custom message if any, then user message)
|
|
958
989
|
messages = [];
|
|
959
990
|
// Add user message
|
|
@@ -1380,6 +1411,169 @@ export class AgentSession {
|
|
|
1380
1411
|
});
|
|
1381
1412
|
}
|
|
1382
1413
|
}
|
|
1414
|
+
/**
|
|
1415
|
+
* Set the thinking mode. "auto" resolves a level per turn via the reasoning
|
|
1416
|
+
* router; "manual" keeps the explicitly selected level. The mode persists for
|
|
1417
|
+
* the session lifetime and is never written to user settings.
|
|
1418
|
+
*/
|
|
1419
|
+
setThinkingMode(mode) {
|
|
1420
|
+
this._thinkingMode = mode;
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* In auto thinking mode, resolve and apply this turn's thinking level from the
|
|
1424
|
+
* prompt content. Updates agent state, records the change in the session, and
|
|
1425
|
+
* notifies observers - but never overwrites the user's persisted default
|
|
1426
|
+
* thinking level in settings. Models without reasoning support bypass the
|
|
1427
|
+
* router entirely (level stays "off").
|
|
1428
|
+
*/
|
|
1429
|
+
_applyAutoThinkingLevelForTurn(promptText) {
|
|
1430
|
+
if (this._thinkingMode !== "auto")
|
|
1431
|
+
return;
|
|
1432
|
+
if (!this.supportsThinking())
|
|
1433
|
+
return;
|
|
1434
|
+
this._applyAutoThinkingLevelV4(promptText);
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Auto-mode resolver. Reuses the N=8 recent-class history and
|
|
1438
|
+
* context-pressure bucket, routed through the confidence-bearing v4 classifier
|
|
1439
|
+
* and its uncertainty-aware resolver. No
|
|
1440
|
+
* `laneType` applies to the main session (always "none"/`undefined`);
|
|
1441
|
+
* `hint` is permanently `null` -- the Adaptorch advisory bridge has no
|
|
1442
|
+
* transport wired into the session (out of this lane's scope; see
|
|
1443
|
+
* adaptorch-bridge.ts). `bias` stays `0` unless BOTH hold: (a) the global,
|
|
1444
|
+
* owner-only `reasoningRouterLearning.enabled` setting is `true` (default
|
|
1445
|
+
* off; a project-scope `.omk/settings.json` value for this key is never
|
|
1446
|
+
* consulted -- see settings-manager.ts), and (b) a compiled
|
|
1447
|
+
* `RouterBiasSnapshot` was found and passed strict validation at the
|
|
1448
|
+
* configured/default path, loaded and cached ("pinned") at most once per
|
|
1449
|
+
* session (see `_getReasoningRouterBiasSnapshot`). When learning is
|
|
1450
|
+
* enabled, exactly one bounded "accepted" feedback record (no raw prompt/
|
|
1451
|
+
* path/diff/session/model/provider/tool/hook content; see
|
|
1452
|
+
* router-feedback-collector.ts's exact ten-key schema) is appended to the
|
|
1453
|
+
* local ledger after every v4 auto-turn resolution, for a future, separate
|
|
1454
|
+
* offline compile step to learn from -- this lane never records an
|
|
1455
|
+
* override/fail/hook-outcome signal, only the neutral "accepted" one. The
|
|
1456
|
+
* resolver's own confidence-band/fallback-reason escalation (see
|
|
1457
|
+
* reasoning-router-v4.ts) still applies on top of the base+lane+bias
|
|
1458
|
+
* target, so a low-confidence or fallback-decided verdict can still only
|
|
1459
|
+
* match or exceed the confident-path level.
|
|
1460
|
+
*/
|
|
1461
|
+
_applyAutoThinkingLevelV4(promptText) {
|
|
1462
|
+
const availableLevels = this.getAvailableThinkingLevels();
|
|
1463
|
+
const verdict = classifyTaskV4({
|
|
1464
|
+
prompt: promptText,
|
|
1465
|
+
history: this._taskClassHistory,
|
|
1466
|
+
pressureBucket: this._computePressureBucket(),
|
|
1467
|
+
});
|
|
1468
|
+
this._taskClassHistory.unshift(verdict.taskClass);
|
|
1469
|
+
if (this._taskClassHistory.length > 8)
|
|
1470
|
+
this._taskClassHistory.length = 8;
|
|
1471
|
+
const learningEnabled = this.settingsManager.getReasoningRouterLearningEnabled();
|
|
1472
|
+
const snapshot = learningEnabled ? this._getReasoningRouterBiasSnapshot() : null;
|
|
1473
|
+
const features = this._deriveRouterFeedbackFeatures(promptText);
|
|
1474
|
+
const bias = snapshot === null
|
|
1475
|
+
? 0
|
|
1476
|
+
: getBiasStepsForCell(snapshot, {
|
|
1477
|
+
predictedClass: verdict.taskClass,
|
|
1478
|
+
laneType: "none",
|
|
1479
|
+
lenBucket: features.lenBucket,
|
|
1480
|
+
hadFence: features.hadFence,
|
|
1481
|
+
hadDiff: features.hadDiff,
|
|
1482
|
+
});
|
|
1483
|
+
const resolved = resolveThinkingLevelV4WithUncertainty(verdict, availableLevels, undefined, bias, null);
|
|
1484
|
+
if (learningEnabled && resolved !== "off") {
|
|
1485
|
+
const record = {
|
|
1486
|
+
routerVersion: "v4",
|
|
1487
|
+
laneType: "none",
|
|
1488
|
+
predictedClass: verdict.taskClass,
|
|
1489
|
+
resolvedLevel: resolved,
|
|
1490
|
+
acceptedLevel: resolved,
|
|
1491
|
+
signal: "s2-accept",
|
|
1492
|
+
outcome: "accepted",
|
|
1493
|
+
lenBucket: features.lenBucket,
|
|
1494
|
+
hadFence: features.hadFence,
|
|
1495
|
+
hadDiff: features.hadDiff,
|
|
1496
|
+
};
|
|
1497
|
+
appendRouterFeedbackRecord(record, {
|
|
1498
|
+
enabled: true,
|
|
1499
|
+
ledgerPath: this.settingsManager.getReasoningRouterLearningFeedbackLedgerPath(),
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
const previousLevel = this.agent.state.thinkingLevel;
|
|
1503
|
+
if (resolved === previousLevel)
|
|
1504
|
+
return;
|
|
1505
|
+
this.agent.state.thinkingLevel = resolved;
|
|
1506
|
+
this.sessionManager.appendThinkingLevelChange(resolved);
|
|
1507
|
+
this._emit({ type: "thinking_level_changed", level: resolved });
|
|
1508
|
+
}
|
|
1509
|
+
/**
|
|
1510
|
+
* Loads and strictly validates the compiled reasoning-router bias snapshot
|
|
1511
|
+
* for the opt-in v4 learning path (Goal 010 Lane I), at most once per
|
|
1512
|
+
* session ("pinned"): the first call attempts the read and caches whatever
|
|
1513
|
+
* it finds (including a `null` miss/failure); every later call in the same
|
|
1514
|
+
* session reuses that cached result without touching disk again. Returns
|
|
1515
|
+
* `null` when no file exists at the configured/default path, the file
|
|
1516
|
+
* cannot be read, or its contents fail `parseRouterBiasSnapshot`'s schema
|
|
1517
|
+
* validation -- never throws.
|
|
1518
|
+
*/
|
|
1519
|
+
_getReasoningRouterBiasSnapshot() {
|
|
1520
|
+
if (this._reasoningRouterBiasSnapshotLoaded)
|
|
1521
|
+
return this._reasoningRouterBiasSnapshot;
|
|
1522
|
+
this._reasoningRouterBiasSnapshotLoaded = true;
|
|
1523
|
+
const path = this.settingsManager.getReasoningRouterLearningBiasSnapshotPath() ?? getDefaultRouterBiasSnapshotPath();
|
|
1524
|
+
try {
|
|
1525
|
+
if (existsSync(path)) {
|
|
1526
|
+
this._reasoningRouterBiasSnapshot = parseRouterBiasSnapshot(readFileSync(path, "utf-8"));
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
catch {
|
|
1530
|
+
this._reasoningRouterBiasSnapshot = null;
|
|
1531
|
+
}
|
|
1532
|
+
return this._reasoningRouterBiasSnapshot;
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Locally derives the same three bounded, privacy-safe feedback-ledger
|
|
1536
|
+
* features (`lenBucket`, `hadFence`, `hadDiff`) the v4 classifier computes
|
|
1537
|
+
* internally (reasoning-router-v4.ts keeps those helpers file-private, so
|
|
1538
|
+
* they cannot be imported here). Mirrors reasoning-router-v4.ts's
|
|
1539
|
+
* length-bucket, `hasCodeFence`, and `hasDiffMarkers` helpers. Operates on the same trimmed prompt text
|
|
1540
|
+
* the classifier scores; never returns raw prompt content or its exact
|
|
1541
|
+
* length, only the clamped [0,7] bucket and two booleans.
|
|
1542
|
+
*/
|
|
1543
|
+
_deriveRouterFeedbackFeatures(promptText) {
|
|
1544
|
+
const trimmed = promptText.trim();
|
|
1545
|
+
let lenBucket = 0;
|
|
1546
|
+
let remaining = trimmed.length + 1;
|
|
1547
|
+
while (remaining > 1 && lenBucket < 7) {
|
|
1548
|
+
remaining >>= 1;
|
|
1549
|
+
lenBucket++;
|
|
1550
|
+
}
|
|
1551
|
+
const hadFence = trimmed.includes("```");
|
|
1552
|
+
const hadDiff = /^@@[^\n]*@@/m.test(trimmed) ||
|
|
1553
|
+
/^diff --git /m.test(trimmed) ||
|
|
1554
|
+
(/^\+(?!\+)/m.test(trimmed) && /^-(?!-)/m.test(trimmed));
|
|
1555
|
+
return { lenBucket: lenBucket, hadFence, hadDiff };
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Context-pressure band 0..3 from the projected token estimate over the
|
|
1559
|
+
* model context window (reuses estimateProjectedContextTokens). 0..<0.5,
|
|
1560
|
+
* 1..<0.75, 2..<0.9, 3..>=0.9. Inert under DEFAULT_WEIGHTS (no pressure
|
|
1561
|
+
* coefficient); computed for future calibrated weight presets.
|
|
1562
|
+
*/
|
|
1563
|
+
_computePressureBucket() {
|
|
1564
|
+
const contextWindow = this.model?.contextWindow ?? 0;
|
|
1565
|
+
if (contextWindow <= 0)
|
|
1566
|
+
return 0;
|
|
1567
|
+
const estimate = estimateProjectedContextTokens(this.agent.state.messages, []);
|
|
1568
|
+
const pressure = estimate.tokens / contextWindow;
|
|
1569
|
+
if (pressure >= 0.9)
|
|
1570
|
+
return 3;
|
|
1571
|
+
if (pressure >= 0.75)
|
|
1572
|
+
return 2;
|
|
1573
|
+
if (pressure >= 0.5)
|
|
1574
|
+
return 1;
|
|
1575
|
+
return 0;
|
|
1576
|
+
}
|
|
1383
1577
|
/**
|
|
1384
1578
|
* Cycle to next thinking level.
|
|
1385
1579
|
* @returns New level, or undefined if model doesn't support thinking
|