open-multi-agent-kit 0.90.3 → 0.90.4

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.
Files changed (171) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +16 -14
  3. package/dist/config.d.ts +3 -6
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/config.js +27 -19
  6. package/dist/config.js.map +1 -1
  7. package/dist/core/adaptorch-bridge.d.ts +257 -0
  8. package/dist/core/adaptorch-bridge.d.ts.map +1 -0
  9. package/dist/core/adaptorch-bridge.js +473 -0
  10. package/dist/core/adaptorch-bridge.js.map +1 -0
  11. package/dist/core/agent-session.d.ts +130 -0
  12. package/dist/core/agent-session.d.ts.map +1 -1
  13. package/dist/core/agent-session.js +286 -0
  14. package/dist/core/agent-session.js.map +1 -1
  15. package/dist/core/bang-skill-invocation.d.ts.map +1 -1
  16. package/dist/core/bang-skill-invocation.js +149 -0
  17. package/dist/core/bang-skill-invocation.js.map +1 -1
  18. package/dist/core/compaction/utils.d.ts.map +1 -1
  19. package/dist/core/compaction/utils.js +15 -2
  20. package/dist/core/compaction/utils.js.map +1 -1
  21. package/dist/core/domain-loadouts.d.ts.map +1 -1
  22. package/dist/core/domain-loadouts.js +1 -1
  23. package/dist/core/domain-loadouts.js.map +1 -1
  24. package/dist/core/reasoning-router-bias.d.ts +119 -0
  25. package/dist/core/reasoning-router-bias.d.ts.map +1 -0
  26. package/dist/core/reasoning-router-bias.js +287 -0
  27. package/dist/core/reasoning-router-bias.js.map +1 -0
  28. package/dist/core/reasoning-router-v2.d.ts +94 -0
  29. package/dist/core/reasoning-router-v2.d.ts.map +1 -0
  30. package/dist/core/reasoning-router-v2.js +288 -0
  31. package/dist/core/reasoning-router-v2.js.map +1 -0
  32. package/dist/core/reasoning-router-v3.d.ts +15 -0
  33. package/dist/core/reasoning-router-v3.d.ts.map +1 -0
  34. package/dist/core/reasoning-router-v3.js +193 -0
  35. package/dist/core/reasoning-router-v3.js.map +1 -0
  36. package/dist/core/reasoning-router-v4-weights.d.ts +124 -0
  37. package/dist/core/reasoning-router-v4-weights.d.ts.map +1 -0
  38. package/dist/core/reasoning-router-v4-weights.js +112 -0
  39. package/dist/core/reasoning-router-v4-weights.js.map +1 -0
  40. package/dist/core/reasoning-router-v4.d.ts +163 -0
  41. package/dist/core/reasoning-router-v4.d.ts.map +1 -0
  42. package/dist/core/reasoning-router-v4.js +683 -0
  43. package/dist/core/reasoning-router-v4.js.map +1 -0
  44. package/dist/core/reasoning-router-weights.d.ts +155 -0
  45. package/dist/core/reasoning-router-weights.d.ts.map +1 -0
  46. package/dist/core/reasoning-router-weights.js +204 -0
  47. package/dist/core/reasoning-router-weights.js.map +1 -0
  48. package/dist/core/reasoning-router.d.ts +44 -0
  49. package/dist/core/reasoning-router.d.ts.map +1 -0
  50. package/dist/core/reasoning-router.js +138 -0
  51. package/dist/core/reasoning-router.js.map +1 -0
  52. package/dist/core/router-feedback-collector.d.ts +101 -0
  53. package/dist/core/router-feedback-collector.d.ts.map +1 -0
  54. package/dist/core/router-feedback-collector.js +239 -0
  55. package/dist/core/router-feedback-collector.js.map +1 -0
  56. package/dist/core/settings-manager.d.ts +28 -0
  57. package/dist/core/settings-manager.d.ts.map +1 -1
  58. package/dist/core/settings-manager.js +16 -0
  59. package/dist/core/settings-manager.js.map +1 -1
  60. package/dist/core/slash-commands.d.ts.map +1 -1
  61. package/dist/core/slash-commands.js +4 -1
  62. package/dist/core/slash-commands.js.map +1 -1
  63. package/dist/modes/interactive/components/control-panel-runtime-status.d.ts +15 -0
  64. package/dist/modes/interactive/components/control-panel-runtime-status.d.ts.map +1 -1
  65. package/dist/modes/interactive/components/control-panel-runtime-status.js +95 -5
  66. package/dist/modes/interactive/components/control-panel-runtime-status.js.map +1 -1
  67. package/dist/modes/interactive/interactive-mode.d.ts +4 -0
  68. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  69. package/dist/modes/interactive/interactive-mode.js +143 -18
  70. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  71. package/docs/loadout-domains/README.md +8 -6
  72. package/docs/loadout-domains/ai-agent-ops.md +3 -2
  73. package/docs/loadout-domains/backend-api.md +3 -2
  74. package/docs/loadout-domains/data-science.md +3 -2
  75. package/docs/loadout-domains/devops-infra.md +2 -1
  76. package/docs/loadout-domains/docs-writing.md +7 -2
  77. package/docs/loadout-domains/frontend-ui.md +42 -11
  78. package/docs/loadout-domains/korean-document.md +83 -0
  79. package/docs/loadout-domains/mobile.md +1 -1
  80. package/docs/loadout-domains/qa-testing.md +4 -2
  81. package/docs/loadout-domains/security-audit.md +2 -1
  82. package/docs/loadout-domains/visual-qa.md +94 -0
  83. package/docs/skills.md +4 -1
  84. package/docs/usage.md +37 -3
  85. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  86. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  87. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  88. package/examples/extensions/gondolin/package-lock.json +2 -2
  89. package/examples/extensions/gondolin/package.json +1 -1
  90. package/examples/extensions/sandbox/package-lock.json +2 -2
  91. package/examples/extensions/sandbox/package.json +1 -1
  92. package/examples/extensions/with-deps/package-lock.json +2 -2
  93. package/examples/extensions/with-deps/package.json +1 -1
  94. package/npm-shrinkwrap.json +12 -12
  95. package/package.json +4 -4
  96. package/dist/agents/jailbreak/index.d.ts +0 -7
  97. package/dist/agents/jailbreak/index.d.ts.map +0 -1
  98. package/dist/agents/jailbreak/index.js +0 -7
  99. package/dist/agents/jailbreak/index.js.map +0 -1
  100. package/dist/agents/jailbreak/subagent-f.d.ts +0 -44
  101. package/dist/agents/jailbreak/subagent-f.d.ts.map +0 -1
  102. package/dist/agents/jailbreak/subagent-f.js +0 -60
  103. package/dist/agents/jailbreak/subagent-f.js.map +0 -1
  104. package/dist/cli/jailbreak-args.d.ts +0 -26
  105. package/dist/cli/jailbreak-args.d.ts.map +0 -1
  106. package/dist/cli/jailbreak-args.js +0 -86
  107. package/dist/cli/jailbreak-args.js.map +0 -1
  108. package/dist/commands/jailbreak.d.ts +0 -49
  109. package/dist/commands/jailbreak.d.ts.map +0 -1
  110. package/dist/commands/jailbreak.js +0 -201
  111. package/dist/commands/jailbreak.js.map +0 -1
  112. package/dist/encoding/index.d.ts +0 -6
  113. package/dist/encoding/index.d.ts.map +0 -1
  114. package/dist/encoding/index.js +0 -6
  115. package/dist/encoding/index.js.map +0 -1
  116. package/dist/encoding/l4-encoder.d.ts +0 -96
  117. package/dist/encoding/l4-encoder.d.ts.map +0 -1
  118. package/dist/encoding/l4-encoder.js +0 -474
  119. package/dist/encoding/l4-encoder.js.map +0 -1
  120. package/dist/fuzzing/index.d.ts +0 -6
  121. package/dist/fuzzing/index.d.ts.map +0 -1
  122. package/dist/fuzzing/index.js +0 -6
  123. package/dist/fuzzing/index.js.map +0 -1
  124. package/dist/fuzzing/mutation-engine.d.ts +0 -93
  125. package/dist/fuzzing/mutation-engine.d.ts.map +0 -1
  126. package/dist/fuzzing/mutation-engine.js +0 -244
  127. package/dist/fuzzing/mutation-engine.js.map +0 -1
  128. package/dist/jailbreak-extension.d.ts +0 -48
  129. package/dist/jailbreak-extension.d.ts.map +0 -1
  130. package/dist/jailbreak-extension.js +0 -47
  131. package/dist/jailbreak-extension.js.map +0 -1
  132. package/dist/modules/index.d.ts +0 -8
  133. package/dist/modules/index.d.ts.map +0 -1
  134. package/dist/modules/index.js +0 -7
  135. package/dist/modules/index.js.map +0 -1
  136. package/dist/modules/lrl-bypass.d.ts +0 -40
  137. package/dist/modules/lrl-bypass.d.ts.map +0 -1
  138. package/dist/modules/lrl-bypass.js +0 -84
  139. package/dist/modules/lrl-bypass.js.map +0 -1
  140. package/dist/modules/lrl-deps.d.ts +0 -38
  141. package/dist/modules/lrl-deps.d.ts.map +0 -1
  142. package/dist/modules/lrl-deps.js +0 -128
  143. package/dist/modules/lrl-deps.js.map +0 -1
  144. package/dist/multiturn/easl-chain.d.ts +0 -113
  145. package/dist/multiturn/easl-chain.d.ts.map +0 -1
  146. package/dist/multiturn/easl-chain.js +0 -351
  147. package/dist/multiturn/easl-chain.js.map +0 -1
  148. package/dist/multiturn/index.d.ts +0 -6
  149. package/dist/multiturn/index.d.ts.map +0 -1
  150. package/dist/multiturn/index.js +0 -6
  151. package/dist/multiturn/index.js.map +0 -1
  152. package/dist/routing/fallback-router.d.ts +0 -123
  153. package/dist/routing/fallback-router.d.ts.map +0 -1
  154. package/dist/routing/fallback-router.js +0 -355
  155. package/dist/routing/fallback-router.js.map +0 -1
  156. package/dist/routing/index.d.ts +0 -6
  157. package/dist/routing/index.d.ts.map +0 -1
  158. package/dist/routing/index.js +0 -6
  159. package/dist/routing/index.js.map +0 -1
  160. package/dist/types/jailbreak.d.ts +0 -246
  161. package/dist/types/jailbreak.d.ts.map +0 -1
  162. package/dist/types/jailbreak.js +0 -8
  163. package/dist/types/jailbreak.js.map +0 -1
  164. package/dist/utils/jailbreak/common.d.ts +0 -63
  165. package/dist/utils/jailbreak/common.d.ts.map +0 -1
  166. package/dist/utils/jailbreak/common.js +0 -130
  167. package/dist/utils/jailbreak/common.js.map +0 -1
  168. package/dist/utils/jailbreak/index.d.ts +0 -7
  169. package/dist/utils/jailbreak/index.d.ts.map +0 -1
  170. package/dist/utils/jailbreak/index.js +0 -7
  171. package/dist/utils/jailbreak/index.js.map +0 -1
@@ -32,6 +32,12 @@ 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 { classifyTask, resolveThinkingLevel } from "./reasoning-router.js";
36
+ import { getBiasStepsForCell, getDefaultRouterBiasSnapshotPath, parseRouterBiasSnapshot, } from "./reasoning-router-bias.js";
37
+ import { classifyTaskV2, DEFAULT_WEIGHTS, resolveThinkingLevelV2ForAuto, } from "./reasoning-router-v2.js";
38
+ import { classifyTaskV3, resolveThinkingLevelV3ForAuto } from "./reasoning-router-v3.js";
39
+ import { classifyTaskV4, resolveThinkingLevelV4WithUncertainty } from "./reasoning-router-v4.js";
40
+ import { appendRouterFeedbackRecord, } from "./router-feedback-collector.js";
35
41
  import { detectSandboxBackend } from "./sandbox/backend.js";
36
42
  import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
37
43
  import { createSyntheticSourceInfo } from "./source-info.js";
@@ -98,6 +104,36 @@ export class AgentSession {
98
104
  sessionManager;
99
105
  settingsManager;
100
106
  _scopedModels;
107
+ /**
108
+ * Thinking mode (default "manual"). Persists across turns within the session;
109
+ * auto-resolved levels are never written to the user's persisted settings.
110
+ */
111
+ _thinkingMode = "manual";
112
+ /**
113
+ * Reasoning router version used by auto thinking mode. "v1" (default) keeps
114
+ * the frozen v1 classifyTask/resolveThinkingLevel; "v2" uses the Goal 004
115
+ * weighted router; "v3" uses the Goal 007 calibrated classifier; "v4" uses
116
+ * the Goal 009 confidence-bearing classifier (classifyTaskV4 +
117
+ * resolveThinkingLevelV4WithUncertainty). Default "v1" so behavior is
118
+ * unchanged until explicitly opted in.
119
+ */
120
+ _thinkingRouterVersion = "v1";
121
+ /**
122
+ * N=8 ring buffer of recent auto-turn task classes (newest first), feeding
123
+ * the v2/v3 classifiers' multi-turn prior feature. Never persisted to settings.
124
+ */
125
+ _taskClassHistory = [];
126
+ /**
127
+ * Compiled reasoning-router bias snapshot for the opt-in v4 learning path
128
+ * (Goal 010 Lane I). Loaded at most once per session and pinned thereafter:
129
+ * `_reasoningRouterBiasSnapshotLoaded` flips to `true` on the first v4
130
+ * auto-turn that has learning enabled, and `_reasoningRouterBiasSnapshot`
131
+ * then stays fixed for the rest of the session (even across later settings
132
+ * reloads, and even if the on-disk file changes or the load failed/was
133
+ * invalid, in which case it stays `null`). See `_getReasoningRouterBiasSnapshot`.
134
+ */
135
+ _reasoningRouterBiasSnapshot = null;
136
+ _reasoningRouterBiasSnapshotLoaded = false;
101
137
  // Event subscription state
102
138
  _unsubscribeAgent;
103
139
  _eventListeners = [];
@@ -552,6 +588,10 @@ export class AgentSession {
552
588
  get thinkingLevel() {
553
589
  return this.agent.state.thinkingLevel;
554
590
  }
591
+ /** Current thinking mode ("manual" = user-selected level, "auto" = per-turn router) */
592
+ get thinkingMode() {
593
+ return this._thinkingMode;
594
+ }
555
595
  /** Whether agent is currently streaming a response */
556
596
  get isStreaming() {
557
597
  return this.agent.state.isStreaming;
@@ -954,6 +994,9 @@ export class AgentSession {
954
994
  this._flushPendingBashMessages();
955
995
  }
956
996
  }
997
+ // Auto thinking mode: resolve this turn's level from the prompt content.
998
+ // Manual mode never enters the router, so /think <level> always wins.
999
+ this._applyAutoThinkingLevelForTurn(expandedText);
957
1000
  // Build messages array (custom message if any, then user message)
958
1001
  messages = [];
959
1002
  // Add user message
@@ -1380,6 +1423,249 @@ export class AgentSession {
1380
1423
  });
1381
1424
  }
1382
1425
  }
1426
+ /**
1427
+ * Set the thinking mode. "auto" resolves a level per turn via the reasoning
1428
+ * router; "manual" keeps the explicitly selected level. The mode persists for
1429
+ * the session lifetime and is never written to user settings.
1430
+ */
1431
+ setThinkingMode(mode) {
1432
+ this._thinkingMode = mode;
1433
+ }
1434
+ /**
1435
+ * Reasoning router version selection for auto thinking mode.
1436
+ * Default "v1". Switching to "v2", "v3", or "v4" activates the
1437
+ * corresponding opt-in router; the multi-turn history buffer is only
1438
+ * consulted there.
1439
+ */
1440
+ get thinkingRouterVersion() {
1441
+ return this._thinkingRouterVersion;
1442
+ }
1443
+ setThinkingRouterVersion(version) {
1444
+ this._thinkingRouterVersion = version;
1445
+ }
1446
+ /**
1447
+ * In auto thinking mode, resolve and apply this turn's thinking level from the
1448
+ * prompt content. Updates agent state, records the change in the session, and
1449
+ * notifies observers - but never overwrites the user's persisted default
1450
+ * thinking level in settings. Models without reasoning support bypass the
1451
+ * router entirely (level stays "off").
1452
+ */
1453
+ _applyAutoThinkingLevelForTurn(promptText) {
1454
+ if (this._thinkingMode !== "auto")
1455
+ return;
1456
+ if (!this.supportsThinking())
1457
+ return;
1458
+ if (this._thinkingRouterVersion === "v4") {
1459
+ this._applyAutoThinkingLevelV4(promptText);
1460
+ return;
1461
+ }
1462
+ if (this._thinkingRouterVersion === "v3") {
1463
+ this._applyAutoThinkingLevelV3(promptText);
1464
+ return;
1465
+ }
1466
+ if (this._thinkingRouterVersion === "v2") {
1467
+ this._applyAutoThinkingLevelV2(promptText);
1468
+ return;
1469
+ }
1470
+ const taskClass = classifyTask({ prompt: promptText });
1471
+ const resolved = resolveThinkingLevel(taskClass, this.getAvailableThinkingLevels());
1472
+ const previousLevel = this.agent.state.thinkingLevel;
1473
+ if (resolved === previousLevel)
1474
+ return;
1475
+ this.agent.state.thinkingLevel = resolved;
1476
+ this.sessionManager.appendThinkingLevelChange(resolved);
1477
+ this._emit({ type: "thinking_level_changed", level: resolved });
1478
+ }
1479
+ /**
1480
+ * v2 auto-mode resolver (Goal 004). Builds the caller-side features the pure
1481
+ * classifier cannot reach on its own (multi-turn ring buffer, context-pressure
1482
+ * bucket), then applies classifyTaskV2 + resolveThinkingLevelV2ForAuto. The
1483
+ * resolved class is pushed to the N=8 history for the NEXT turn's prior.
1484
+ */
1485
+ _applyAutoThinkingLevelV2(promptText) {
1486
+ const availableLevels = this.getAvailableThinkingLevels();
1487
+ const taskClass = classifyTaskV2({
1488
+ prompt: promptText,
1489
+ history: this._taskClassHistory,
1490
+ pressureBucket: this._computePressureBucket(),
1491
+ }, DEFAULT_WEIGHTS);
1492
+ this._taskClassHistory.unshift(taskClass);
1493
+ if (this._taskClassHistory.length > 8)
1494
+ this._taskClassHistory.length = 8;
1495
+ const resolved = resolveThinkingLevelV2ForAuto(taskClass, availableLevels, undefined);
1496
+ const previousLevel = this.agent.state.thinkingLevel;
1497
+ if (resolved === previousLevel)
1498
+ return;
1499
+ this.agent.state.thinkingLevel = resolved;
1500
+ this.sessionManager.appendThinkingLevelChange(resolved);
1501
+ this._emit({ type: "thinking_level_changed", level: resolved });
1502
+ }
1503
+ /**
1504
+ * v3 auto-mode resolver (Goal 007). Reuses the same N=8 recent-class history
1505
+ * and context-pressure bucket as v2, but routes through the v3 classifier and
1506
+ * resolver pair.
1507
+ */
1508
+ _applyAutoThinkingLevelV3(promptText) {
1509
+ const availableLevels = this.getAvailableThinkingLevels();
1510
+ const taskClass = classifyTaskV3({
1511
+ prompt: promptText,
1512
+ history: this._taskClassHistory,
1513
+ pressureBucket: this._computePressureBucket(),
1514
+ });
1515
+ this._taskClassHistory.unshift(taskClass);
1516
+ if (this._taskClassHistory.length > 8)
1517
+ this._taskClassHistory.length = 8;
1518
+ const resolved = resolveThinkingLevelV3ForAuto(taskClass, availableLevels, undefined);
1519
+ const previousLevel = this.agent.state.thinkingLevel;
1520
+ if (resolved === previousLevel)
1521
+ return;
1522
+ this.agent.state.thinkingLevel = resolved;
1523
+ this.sessionManager.appendThinkingLevelChange(resolved);
1524
+ this._emit({ type: "thinking_level_changed", level: resolved });
1525
+ }
1526
+ /**
1527
+ * v4 auto-mode resolver (Goal 009 Wave 3 Lane V1; wired to the opt-in
1528
+ * learning bias by Goal 010 Lane I). Reuses the same N=8 recent-class
1529
+ * history and context-pressure bucket as v2/v3, routed through the
1530
+ * confidence-bearing v4 classifier and its uncertainty-aware resolver. No
1531
+ * `laneType` applies to the main session (always "none"/`undefined`);
1532
+ * `hint` is permanently `null` -- the Adaptorch advisory bridge has no
1533
+ * transport wired into the session (out of this lane's scope; see
1534
+ * adaptorch-bridge.ts). `bias` stays `0` unless BOTH hold: (a) the global,
1535
+ * owner-only `reasoningRouterLearning.enabled` setting is `true` (default
1536
+ * off; a project-scope `.omk/settings.json` value for this key is never
1537
+ * consulted -- see settings-manager.ts), and (b) a compiled
1538
+ * `RouterBiasSnapshot` was found and passed strict validation at the
1539
+ * configured/default path, loaded and cached ("pinned") at most once per
1540
+ * session (see `_getReasoningRouterBiasSnapshot`). When learning is
1541
+ * enabled, exactly one bounded "accepted" feedback record (no raw prompt/
1542
+ * path/diff/session/model/provider/tool/hook content; see
1543
+ * router-feedback-collector.ts's exact ten-key schema) is appended to the
1544
+ * local ledger after every v4 auto-turn resolution, for a future, separate
1545
+ * offline compile step to learn from -- this lane never records an
1546
+ * override/fail/hook-outcome signal, only the neutral "accepted" one. The
1547
+ * resolver's own confidence-band/fallback-reason escalation (see
1548
+ * reasoning-router-v4.ts) still applies on top of the base+lane+bias
1549
+ * target, so a low-confidence or fallback-decided verdict can still only
1550
+ * match or exceed the confident-path level.
1551
+ */
1552
+ _applyAutoThinkingLevelV4(promptText) {
1553
+ const availableLevels = this.getAvailableThinkingLevels();
1554
+ const verdict = classifyTaskV4({
1555
+ prompt: promptText,
1556
+ history: this._taskClassHistory,
1557
+ pressureBucket: this._computePressureBucket(),
1558
+ });
1559
+ this._taskClassHistory.unshift(verdict.taskClass);
1560
+ if (this._taskClassHistory.length > 8)
1561
+ this._taskClassHistory.length = 8;
1562
+ const learningEnabled = this.settingsManager.getReasoningRouterLearningEnabled();
1563
+ const snapshot = learningEnabled ? this._getReasoningRouterBiasSnapshot() : null;
1564
+ const features = this._deriveRouterFeedbackFeatures(promptText);
1565
+ const bias = snapshot === null
1566
+ ? 0
1567
+ : getBiasStepsForCell(snapshot, {
1568
+ predictedClass: verdict.taskClass,
1569
+ laneType: "none",
1570
+ lenBucket: features.lenBucket,
1571
+ hadFence: features.hadFence,
1572
+ hadDiff: features.hadDiff,
1573
+ });
1574
+ const resolved = resolveThinkingLevelV4WithUncertainty(verdict, availableLevels, undefined, bias, null);
1575
+ if (learningEnabled && resolved !== "off") {
1576
+ const record = {
1577
+ routerVersion: "v4",
1578
+ laneType: "none",
1579
+ predictedClass: verdict.taskClass,
1580
+ resolvedLevel: resolved,
1581
+ acceptedLevel: resolved,
1582
+ signal: "s2-accept",
1583
+ outcome: "accepted",
1584
+ lenBucket: features.lenBucket,
1585
+ hadFence: features.hadFence,
1586
+ hadDiff: features.hadDiff,
1587
+ };
1588
+ appendRouterFeedbackRecord(record, {
1589
+ enabled: true,
1590
+ ledgerPath: this.settingsManager.getReasoningRouterLearningFeedbackLedgerPath(),
1591
+ });
1592
+ }
1593
+ const previousLevel = this.agent.state.thinkingLevel;
1594
+ if (resolved === previousLevel)
1595
+ return;
1596
+ this.agent.state.thinkingLevel = resolved;
1597
+ this.sessionManager.appendThinkingLevelChange(resolved);
1598
+ this._emit({ type: "thinking_level_changed", level: resolved });
1599
+ }
1600
+ /**
1601
+ * Loads and strictly validates the compiled reasoning-router bias snapshot
1602
+ * for the opt-in v4 learning path (Goal 010 Lane I), at most once per
1603
+ * session ("pinned"): the first call attempts the read and caches whatever
1604
+ * it finds (including a `null` miss/failure); every later call in the same
1605
+ * session reuses that cached result without touching disk again. Returns
1606
+ * `null` when no file exists at the configured/default path, the file
1607
+ * cannot be read, or its contents fail `parseRouterBiasSnapshot`'s schema
1608
+ * validation -- never throws.
1609
+ */
1610
+ _getReasoningRouterBiasSnapshot() {
1611
+ if (this._reasoningRouterBiasSnapshotLoaded)
1612
+ return this._reasoningRouterBiasSnapshot;
1613
+ this._reasoningRouterBiasSnapshotLoaded = true;
1614
+ const path = this.settingsManager.getReasoningRouterLearningBiasSnapshotPath() ?? getDefaultRouterBiasSnapshotPath();
1615
+ try {
1616
+ if (existsSync(path)) {
1617
+ this._reasoningRouterBiasSnapshot = parseRouterBiasSnapshot(readFileSync(path, "utf-8"));
1618
+ }
1619
+ }
1620
+ catch {
1621
+ this._reasoningRouterBiasSnapshot = null;
1622
+ }
1623
+ return this._reasoningRouterBiasSnapshot;
1624
+ }
1625
+ /**
1626
+ * Locally derives the same three bounded, privacy-safe feedback-ledger
1627
+ * features (`lenBucket`, `hadFence`, `hadDiff`) the v4 classifier computes
1628
+ * internally (reasoning-router-v4.ts keeps those helpers file-private, so
1629
+ * they cannot be imported here). Mirrors reasoning-router-v2.ts's
1630
+ * `clampLenBucket` and reasoning-router-v4.ts's `hasCodeFence`/
1631
+ * `hasDiffMarkers` byte-for-byte. Operates on the same trimmed prompt text
1632
+ * the classifier scores; never returns raw prompt content or its exact
1633
+ * length, only the clamped [0,7] bucket and two booleans.
1634
+ */
1635
+ _deriveRouterFeedbackFeatures(promptText) {
1636
+ const trimmed = promptText.trim();
1637
+ let lenBucket = 0;
1638
+ let remaining = trimmed.length + 1;
1639
+ while (remaining > 1 && lenBucket < 7) {
1640
+ remaining >>= 1;
1641
+ lenBucket++;
1642
+ }
1643
+ const hadFence = trimmed.includes("```");
1644
+ const hadDiff = /^@@[^\n]*@@/m.test(trimmed) ||
1645
+ /^diff --git /m.test(trimmed) ||
1646
+ (/^\+(?!\+)/m.test(trimmed) && /^-(?!-)/m.test(trimmed));
1647
+ return { lenBucket: lenBucket, hadFence, hadDiff };
1648
+ }
1649
+ /**
1650
+ * Context-pressure band 0..3 from the projected token estimate over the
1651
+ * model context window (reuses estimateProjectedContextTokens). 0..<0.5,
1652
+ * 1..<0.75, 2..<0.9, 3..>=0.9. Inert under DEFAULT_WEIGHTS (no pressure
1653
+ * coefficient); computed for future calibrated weight presets.
1654
+ */
1655
+ _computePressureBucket() {
1656
+ const contextWindow = this.model?.contextWindow ?? 0;
1657
+ if (contextWindow <= 0)
1658
+ return 0;
1659
+ const estimate = estimateProjectedContextTokens(this.agent.state.messages, []);
1660
+ const pressure = estimate.tokens / contextWindow;
1661
+ if (pressure >= 0.9)
1662
+ return 3;
1663
+ if (pressure >= 0.75)
1664
+ return 2;
1665
+ if (pressure >= 0.5)
1666
+ return 1;
1667
+ return 0;
1668
+ }
1383
1669
  /**
1384
1670
  * Cycle to next thinking level.
1385
1671
  * @returns New level, or undefined if model doesn't support thinking