open-multi-agent-kit 0.90.4 → 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 +22 -0
- package/README.md +8 -8
- package/dist/core/adaptorch-bridge.d.ts +14 -21
- package/dist/core/adaptorch-bridge.d.ts.map +1 -1
- package/dist/core/adaptorch-bridge.js +11 -18
- package/dist/core/adaptorch-bridge.js.map +1 -1
- package/dist/core/agent-session.d.ts +6 -39
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +7 -99
- package/dist/core/agent-session.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/reasoning-router-bias.d.ts +11 -23
- package/dist/core/reasoning-router-bias.d.ts.map +1 -1
- package/dist/core/reasoning-router-bias.js +9 -18
- package/dist/core/reasoning-router-bias.js.map +1 -1
- 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 +28 -72
- package/dist/core/reasoning-router-v4-weights.d.ts.map +1 -1
- package/dist/core/reasoning-router-v4-weights.js +16 -60
- package/dist/core/reasoning-router-v4-weights.js.map +1 -1
- package/dist/core/reasoning-router-v4.d.ts +25 -70
- package/dist/core/reasoning-router-v4.d.ts.map +1 -1
- package/dist/core/reasoning-router-v4.js +46 -144
- package/dist/core/reasoning-router-v4.js.map +1 -1
- package/dist/core/router-feedback-collector.d.ts +13 -16
- package/dist/core/router-feedback-collector.d.ts.map +1 -1
- package/dist/core/router-feedback-collector.js +5 -8
- package/dist/core/router-feedback-collector.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +16 -98
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/usage.md +11 -12
- 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/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/reasoning-router-v2.d.ts +0 -94
- package/dist/core/reasoning-router-v2.d.ts.map +0 -1
- package/dist/core/reasoning-router-v2.js +0 -288
- package/dist/core/reasoning-router-v2.js.map +0 -1
- package/dist/core/reasoning-router-v3.d.ts +0 -15
- package/dist/core/reasoning-router-v3.d.ts.map +0 -1
- package/dist/core/reasoning-router-v3.js +0 -193
- package/dist/core/reasoning-router-v3.js.map +0 -1
- package/dist/core/reasoning-router-weights.d.ts +0 -155
- package/dist/core/reasoning-router-weights.d.ts.map +0 -1
- package/dist/core/reasoning-router-weights.js +0 -204
- package/dist/core/reasoning-router-weights.js.map +0 -1
- package/dist/core/reasoning-router.d.ts +0 -44
- package/dist/core/reasoning-router.d.ts.map +0 -1
- package/dist/core/reasoning-router.js +0 -138
- package/dist/core/reasoning-router.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
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reasoning-router v4 —
|
|
3
|
-
* specs/008-reasoning-router-advanced-accuracy Requirement 2).
|
|
4
|
-
*
|
|
5
|
-
* v4 is a NEW, OPT-IN, PURE sibling module. It does not import from, and is not
|
|
6
|
-
* imported by, reasoning-router.ts (v1), reasoning-router-v2.ts,
|
|
7
|
-
* reasoning-router-v3.ts, reasoning-router-weights.ts, or agent-session.ts.
|
|
8
|
-
* Activating v4 in the product (a `/think auto-v4` mode, settings wiring, etc.)
|
|
9
|
-
* is explicitly out of scope for this lane and is left to a later,
|
|
10
|
-
* single-writer integration lane (specs/008 plan.md Wave 3).
|
|
2
|
+
* Reasoning-router v4 — the sole `/think auto` classifier/resolver.
|
|
11
3
|
*
|
|
12
4
|
* Deterministic by construction: same (input, weights) -> same
|
|
13
5
|
* ClassifierVerdictV4; same (verdict, availableLevels, laneType, bias, hint) ->
|
|
@@ -15,60 +7,21 @@
|
|
|
15
7
|
* or state mutation anywhere in this file (ThinkingLevel is a type-only import
|
|
16
8
|
* and is erased).
|
|
17
9
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* enum, number, boolean, or a closed set of short diagnostic-id strings.
|
|
30
|
-
* 2. WEIGHTS TABLE, NOT LITERALS. Every score bump v3 hard-coded as an inline
|
|
31
|
-
* integer now reads from a `RouterWeightsV4` (see
|
|
32
|
-
* reasoning-router-v4-weights.ts). `DEFAULT_WEIGHTS_V4` reproduces v3's
|
|
33
|
-
* literals exactly, so classifyTaskV4(input, DEFAULT_WEIGHTS_V4).taskClass
|
|
34
|
-
* matches classifyTaskV3(input) on the full non-holdout GOLD_SET and every
|
|
35
|
-
* focused v3 sentinel (see the 013 regression test and this lane's
|
|
36
|
-
* evidence file). Passing a different `RouterWeightsV4` recalibrates
|
|
37
|
-
* without touching this file.
|
|
38
|
-
* 3. BOUNDED NEGATION. Every whole-prompt keyword/contextual pattern scan
|
|
39
|
-
* (the ones v3 ran as a bare `PATTERN.test(prompt)`) is now negation-aware:
|
|
40
|
-
* a match is only counted if no negation cue (don't/doesn't/isn't/never/
|
|
41
|
-
* avoid/skip/without/instead of/rather than/no need to|for/not a/...) appears within
|
|
42
|
-
* `weights.negationWindowChars` characters immediately before it, and the
|
|
43
|
-
* scan never crosses a `.,;!?` clause boundary. Patterns anchored to the
|
|
44
|
-
* START of the leading clause (hasLeadingDebugAction, hasLeadingReviewIntent,
|
|
45
|
-
* etc.) are untouched and need no negation handling: "don't refactor" can
|
|
46
|
-
* never match an anchored `^refactor` test in the first place. Concrete
|
|
47
|
-
* fix: "don't refactor this, just fix the crash" now classifies as debug
|
|
48
|
-
* (v3 misclassifies this as refactor; see the 013 test).
|
|
49
|
-
* 4. BOUNDED COMPOUND INTENT. A short-range conjunction split (bare "then",
|
|
50
|
-
* "and then", "and also", or ";", only within the first 300 characters)
|
|
51
|
-
* looks for a second, distinct leading-verb intent after the split point.
|
|
52
|
-
* When found and distinct from the primary leading intent, it contributes
|
|
53
|
-
* a bounded `secondClauseIntent` bump and sets `compoundIntent: true` on
|
|
54
|
-
* the verdict. This is proven inert on every current GOLD_SET row (no
|
|
55
|
-
* gold-set prompt produces a non-null, distinct second-clause intent), so
|
|
56
|
-
* it never changes an existing classification under DEFAULT_WEIGHTS_V4 —
|
|
57
|
-
* it only sharpens confidence/margin metadata for genuinely compound
|
|
58
|
-
* prompts and gives future calibration a lever.
|
|
59
|
-
* 5. CONFIDENCE NEVER LOWERS EFFORT. `resolveThinkingLevelV4WithUncertainty`
|
|
60
|
-
* computes the exact same base target as v2/v3's resolvers (rule table +
|
|
61
|
-
* lane step + bias + hint), then ONLY ADDS a bounded escalation step when
|
|
62
|
-
* confidence is low or the class came from the fallback cascade. A prompt
|
|
63
|
-
* like "don't think hard, just fix the crash" cannot use its own text to
|
|
64
|
-
* talk the resolver down: the escalation term is strictly non-negative, so
|
|
65
|
-
* the output is always >= what the same taskClass would resolve to via
|
|
66
|
-
* `resolveThinkingLevelV4ForAuto` (mirrors spec 008 Req 2 acceptance
|
|
67
|
-
* criterion "confidence cannot lower effort").
|
|
68
|
-
* ============================================================================
|
|
10
|
+
* `classifyTaskV4` returns a confidence-bearing verdict: task class, per-class
|
|
11
|
+
* scores, runner-up, margin, confidence band, tie-break flag, fallback reason,
|
|
12
|
+
* bounded-negation audit ids, and compound-intent metadata. None of this carries
|
|
13
|
+
* prompt text — every field is a bounded enum, number, boolean, or a closed set
|
|
14
|
+
* of short diagnostic-id strings.
|
|
15
|
+
*
|
|
16
|
+
* `resolveThinkingLevelV4WithUncertainty` starts from the canonical task-class
|
|
17
|
+
* rule table, applies lane/bias/hint adjustments, and only adds non-negative
|
|
18
|
+
* confidence escalation. A prompt cannot lower its own effort by asking the
|
|
19
|
+
* router to "think less"; low confidence or fallback routing can only hold or
|
|
20
|
+
* raise the resolved level.
|
|
69
21
|
*/
|
|
70
22
|
import { DEFAULT_WEIGHTS_V4, TASK_CLASSES_V4, } from "./reasoning-router-v4-weights.js";
|
|
71
23
|
export { DEFAULT_WEIGHTS_V4, TASK_CLASSES_V4 } from "./reasoning-router-v4-weights.js";
|
|
24
|
+
import { resolveThinkingLevelCore, TASK_CLASS_THINKING_LEVELS } from "./reasoning-router-resolver.js";
|
|
72
25
|
/** Prompts shorter than this (trimmed) fall back to trivial when no real signal scores > 0. */
|
|
73
26
|
const TRIVIAL_MAX_CHARS_V4 = 40;
|
|
74
27
|
/** Prompts at/above this length with no real signal fall back to plan (long prose brief). */
|
|
@@ -81,7 +34,7 @@ const COMPOUND_SPLIT_MAX_INDEX_V4 = 300;
|
|
|
81
34
|
const COMPOUND_SECOND_CLAUSE_MIN_CHARS_V4 = 3;
|
|
82
35
|
/** Bounded look-ahead cap when checking a second clause's leading intent (defense in depth; independent of regex cost). */
|
|
83
36
|
const COMPOUND_SECOND_CLAUSE_SCAN_CHARS_V4 = 200;
|
|
84
|
-
/** Lane fallback class, used only when every scored class is <= 0 (zero-score cascade).
|
|
37
|
+
/** Lane fallback class, used only when every scored class is <= 0 (zero-score cascade). */
|
|
85
38
|
const LANE_FALLBACK_CLASS_V4 = {
|
|
86
39
|
planner: "plan",
|
|
87
40
|
security: "review",
|
|
@@ -91,15 +44,13 @@ const LANE_FALLBACK_CLASS_V4 = {
|
|
|
91
44
|
tester: "code-gen",
|
|
92
45
|
};
|
|
93
46
|
// ============================================================================
|
|
94
|
-
// Whole-prompt / leading-clause patterns
|
|
95
|
-
// reasoning-router-v3.ts; identical regex source so DEFAULT_WEIGHTS_V4
|
|
96
|
-
// reproduces v3 exactly whenever no negation cue is present).
|
|
47
|
+
// Whole-prompt / leading-clause patterns used by the v4 scorer.
|
|
97
48
|
// ============================================================================
|
|
98
49
|
const LOCAL_EDIT_OBJECT_PATTERN = /\b(spelling|grammar|capitalization|date\s+format|author\s+e-?mail|copyright\s+year|headline|title|tooltip|placeholder|punctuation|comma|period|semicolon|closing\s+html\s+tag|closing\s+tag|double\s+space|whitespace|indentation|table\s+alignment|typos?|one-?liner?|single\s+line|sentence|stray|trailing)\b|오타|맞춤법|띄어쓰기|문구|제목/i;
|
|
99
50
|
const LOCAL_EDIT_ACTION_OBJECT_PATTERN = /\b(update|change|swap|remove|correct|fix|add|adjust|trim)\s+(?:the\s+|a\s+|an\s+)?(?:missing\s+|stray\s+|author\s+|two\s+)?(?:e-?mail|comma|period|semicolon|tag|word|words|headline|title|copyright|spelling|grammar)\b/i;
|
|
100
51
|
const IMPLEMENTATION_OBJECT_PATTERN = /\b(error\s+handling|input\s+validation|validation|auth(?:entication)?|retry|endpoint|migration|component|function|utility|helper|module|service|database|schema|column|middleware|rate\s+limiter|cache|caching|oauth|jwt|webhook)\b|에러\s*처리|오류\s*처리|입력\s*검증|인증|재시도|엔드포인트|마이그레이션|컴포넌트|함수|유틸|헬퍼|모듈|서비스|데이터베이스|스키마|미들웨어|레이트\s*리미터|캐시|웹훅|기능/i;
|
|
101
52
|
const HARD_DIAGNOSTIC_PATTERN = /\b(stack\s*trace|traceback|panic|segfault|crash(?:es|ing|ed)?|throws?|fails?|failing|flaky|hangs?|timeout|500|EADDRINUSE|silently\s+fails?)\b|\b(?:TypeError|ReferenceError|RangeError|Error):|크래시|스택\s*트레이스|세그폴트|먹통|멈춰|타임아웃/i;
|
|
102
|
-
const BUG_OBJECT_PATTERN = /\b(null\s+pointer|null\s+deref|race(?:\s+condition)?|heap(?:\s+overflow)?|use-after-free|memory\s+leak|deadlock|data\s+corruption|stale\s+data|off-by-one|encoding\s+bug|regression\s+(?:was\s+)?introduced|exceptions?|assertion\s+error|bugs?)\b|버그|예외|메모리\s*누수|데드락|무한\s*루프/i;
|
|
53
|
+
const BUG_OBJECT_PATTERN = /\b(null\s+pointer|null\s+deref|race(?:\s+condition)?|heap(?:\s+overflow)?|use-after-free|memory\s+leak|leaks?|deadlock|data\s+corruption|stale\s+data|off-by-one|encoding\s+bug|regression\s+(?:was\s+)?introduced|exceptions?|assertion\s+error|bugs?)\b|버그|예외|메모리\s*누수|데드락|무한\s*루프/i;
|
|
103
54
|
const NON_DIAGNOSTIC_DEBUG_CONTEXT_PATTERN = /\berror\s+(?:handling|messages?|budgets?)\b|에러\s*처리|오류\s*처리/i;
|
|
104
55
|
const GENERIC_DIAGNOSTIC_PATTERN = /\b(errors?|broken|wrong\s+results|rolls?\s+back|rollback)\b/i;
|
|
105
56
|
const PLAN_BRIEF_PATTERN = /\b(context\s+and\s+constraints|starting\s+state|target\s+state|cross-cutting|deliver:|deliverables?|roadmap|migration\s+wave|top\s+(?:ten\s+)?risks|component\s+diagram|data\s+model|architecture|go\/no-go|phased\s+(?:delivery|rollout)|bounded\s+contexts?|strangler\s+fig|event-driven|quarter-by-quarter|milestone)\b/i;
|
|
@@ -117,18 +68,18 @@ const OPERATIONAL_RUNBOOK_SIGNAL_PATTERNS = [
|
|
|
117
68
|
];
|
|
118
69
|
const EXPLICIT_RELEASE_RUNBOOK_PATTERN = /\bnpm\s+publish\b|\brelease\b[^\n]{0,80}\bv?\d+\.\d+\.\d+\b|릴리즈[^\n]{0,80}\d+\.\d+\.\d+/i;
|
|
119
70
|
const REVIEW_SCOPE_PATTERN = /\b(pr|pull\s+request|diff|codebase|strategy|plan|spec|schema|design|api|coverage|security\s+posture|licensing|risks?|edge\s+cases|clarity|consistency|dependencies|third-party|ci\s+pipeline|threat\s+model|retry\s+logic|error\s+handling\s+strategy|error\s+messages?)\b/i;
|
|
120
|
-
const REFACTOR_CUE_PATTERN = /\b(refactor(?:ing|ed)?|extract|rename|deduplicate|consolidate|modularize|reorganize|simplify|clean\s*up|restructure|split\s+module|move\s+logic|untangle|merge\s+duplicate)\b|리팩토링(?!하지\s*마|하지\s*말)|리팩터링(?!하지\s*마|하지\s*말)|구조\s*개선/i;
|
|
71
|
+
const REFACTOR_CUE_PATTERN = /\b(refactor(?:ing|ed)?|extract|rename|deduplicate|consolidate|modularize|reorganize|simplify|clean\s*up|tidy\s+up|restructure|split\s+module|move\s+logic|untangle|merge\s+duplicate)\b|리팩토링(?!하지\s*마|하지\s*말)|리팩터링(?!하지\s*마|하지\s*말)|구조\s*개선/i;
|
|
121
72
|
const ADD_KEYWORD_PATTERN = /\badd\b/i;
|
|
122
73
|
const LOW_RISK_EDIT_ACTION_PATTERN = /^(?:correct|update|swap|remove|reword|tweak|bump|trim)\b/i;
|
|
123
|
-
/** Whole-prompt keyword-family patterns
|
|
124
|
-
const DEBUG_KEYWORD_FAMILY_PATTERN = /^(?:debug|investigate\s+why|reproduce|trace\b)|\bfix\s+this\s+(?:traceback|panic|error)\b|디버깅|디버그|재현|원인\s*분석/i;
|
|
125
|
-
const REVIEW_KEYWORD_FAMILY_PATTERN = /\b(review|critique|assess|inspect|approve|lgtm|double-?check|audit(?!\s+log\b))\b|리뷰|검토|점검/i;
|
|
126
|
-
const PLAN_KEYWORD_FAMILY_PATTERN = /\b(plan|design|architect|architecture|roadmap|spec(?:ification)?|strategy|decompose|milestones?|write\s+a\s+(?:technical\s+)?spec|create\s+a\s+(?:roadmap|strategy|plan))\b
|
|
74
|
+
/** Whole-prompt keyword-family patterns; refactor/simple-edit reuse the patterns above. */
|
|
75
|
+
const DEBUG_KEYWORD_FAMILY_PATTERN = /^(?:debug|investigate\s+why|reproduce|trace\b)|\bfix\s+this\s+(?:traceback|panic|error)\b|\btrack\s+down\b|디버깅|디버그|재현|원인\s*분석/i;
|
|
76
|
+
const REVIEW_KEYWORD_FAMILY_PATTERN = /\b(review|critique|assess|inspect|approve|lgtm|double-?check|sanity[-\s]?check|once-?over|eyeball|tell\s+me\s+(?:if|whether)[^.!?;\n]{0,80}\bcorrect|audit(?!\s+log\b))\b|리뷰|검토|점검/i;
|
|
77
|
+
const PLAN_KEYWORD_FAMILY_PATTERN = /\b(plan|design|architect|architecture|roadmap|spec(?:ification)?|strategy|decompose|milestones?|map\s+out|phases|write\s+a\s+(?:technical\s+)?spec|create\s+a\s+(?:roadmap|strategy|plan))\b|설계|로드맵|아키텍처|계획.{0,6}세워|기획/i;
|
|
127
78
|
const CODE_GEN_KEYWORD_FAMILY_PATTERN = /\b(implement|write|create|build|generate|scaffold|prototype)\b|구현|만들어\s*줘|생성|작성|추가해/i;
|
|
128
79
|
const KO_SHORT_DEBUG_SIGNAL_PATTERN_V4 = /오류|에러|실패|안\s*돼|안\s*됨|깨졌|깨짐|고장|디버깅|디버그|재현|원인\s*(?:분석|파악)?/i;
|
|
129
80
|
const KO_SHORT_SIMPLE_EDIT_SIGNAL_PATTERN_V4 = /오타|맞춤법|띄어쓰기|문구|제목/i;
|
|
130
81
|
const KO_SHORT_REVIEW_SIGNAL_PATTERN_V4 = /리뷰|검토|점검/i;
|
|
131
|
-
const KO_SHORT_PLAN_SIGNAL_PATTERN_V4 =
|
|
82
|
+
const KO_SHORT_PLAN_SIGNAL_PATTERN_V4 = /설계|로드맵|아키텍처|계획.{0,6}세워|기획/i;
|
|
132
83
|
const KO_SHORT_REFACTOR_SIGNAL_PATTERN_V4 = /리팩토링|리팩터링|구조\s*개선/i;
|
|
133
84
|
const KO_SHORT_CODE_GEN_SIGNAL_PATTERN_V4 = /구현|만들|생성|작성|추가|테스트|삭제|지워|지우|제거|고쳐|고치|수정|변경|바꿔|바꾸|옮겨|옮기|넣어/i;
|
|
134
85
|
/** Short-range compound-clause conjunction boundary. Only bare/compound "then"/"and also"/";" — never bare "and". */
|
|
@@ -149,13 +100,13 @@ const CLAUSE_BOUNDARY_CHARS = [".", "!", "?", ";", ","];
|
|
|
149
100
|
function hasCodeFence(text) {
|
|
150
101
|
return text.includes("```");
|
|
151
102
|
}
|
|
152
|
-
/**
|
|
103
|
+
/** Explicit hunk headers or `diff --git` count alone; bare +/- only count together. */
|
|
153
104
|
function hasDiffMarkers(text) {
|
|
154
105
|
if (/^@@[^\n]*@@/m.test(text) || /^diff --git /m.test(text))
|
|
155
106
|
return true;
|
|
156
107
|
return /^\+(?!\+)/m.test(text) && /^-(?!-)/m.test(text);
|
|
157
108
|
}
|
|
158
|
-
/**
|
|
109
|
+
/** First line (after stripping one polite prefix), capped at 180 chars. */
|
|
159
110
|
function firstClause(prompt) {
|
|
160
111
|
const firstLine = prompt.replace(/^(?:please|pls|can you|could you|would you|help me|i need you to)\s+/i, "").split("\n")[0] ?? "";
|
|
161
112
|
return firstLine.slice(0, 180);
|
|
@@ -163,8 +114,7 @@ function firstClause(prompt) {
|
|
|
163
114
|
// --- Leading-clause intent tests. All are `^`-anchored against the LEADING
|
|
164
115
|
// clause text only, so a negation cue at the start ("don't refactor...") can
|
|
165
116
|
// never match one of these: none of the alternations include "don't"/"never"/
|
|
166
|
-
// etc, so they are negation-immune by construction
|
|
167
|
-
// from v3. ---
|
|
117
|
+
// etc, so they are negation-immune by construction.
|
|
168
118
|
function hasLeadingReviewIntent(text) {
|
|
169
119
|
return /^(?:review|audit(?!\s+log\b)|critique|inspect|assess|approve|double-?check|lgtm)\b/i.test(text);
|
|
170
120
|
}
|
|
@@ -203,8 +153,8 @@ function matchOperationalRunbookV4(prompt, windowChars) {
|
|
|
203
153
|
return { matched, suppressed: !matched && sawSuppressed };
|
|
204
154
|
}
|
|
205
155
|
/**
|
|
206
|
-
* Negation-aware
|
|
207
|
-
*
|
|
156
|
+
* Negation-aware whole-prompt pattern scan. Finds every occurrence of `pattern`
|
|
157
|
+
* in `prompt`; for each, looks back up to
|
|
208
158
|
* `windowChars` characters (never crossing a `.,;!?` boundary into a prior
|
|
209
159
|
* clause) for a `NEGATION_CUE_PATTERN` hit, and looks forward inside the same
|
|
210
160
|
* bounded window for Hangul-only post-positioned negation cues such as
|
|
@@ -312,7 +262,7 @@ function classifyShortKoreanZeroScoreTaskV4(prompt, windowChars) {
|
|
|
312
262
|
return "code-gen";
|
|
313
263
|
return null;
|
|
314
264
|
}
|
|
315
|
-
/**
|
|
265
|
+
/** Decision order for the leading intent classifier. */
|
|
316
266
|
function leadingIntentV4(input) {
|
|
317
267
|
if (input.diagnosticEvidence &&
|
|
318
268
|
(hasLeadingDebugAction(input.firstClause) || hasLeadingSimpleEditIntent(input.firstClause)))
|
|
@@ -329,7 +279,7 @@ function leadingIntentV4(input) {
|
|
|
329
279
|
return "code-gen";
|
|
330
280
|
return null;
|
|
331
281
|
}
|
|
332
|
-
/**
|
|
282
|
+
/** Diagnostic-evidence decision structure, parameterized over precomputed negation-aware matches. */
|
|
333
283
|
function hasDiagnosticEvidenceV4(leading, hardDiagnosticMatched, bugObjectMatched, genericDiagnosticMatched, nonDiagnosticContext) {
|
|
334
284
|
if (hasLeadingDebugAction(leading) || hardDiagnosticMatched)
|
|
335
285
|
return true;
|
|
@@ -482,7 +432,7 @@ function computeScoresV4(features, weights) {
|
|
|
482
432
|
* coefficient is 0 under DEFAULT_WEIGHTS_V4 (inert until calibrated by a
|
|
483
433
|
* future governance-backed lane); the mechanism exists so
|
|
484
434
|
* `TaskClassifierInputV4`'s optional fields are meaningfully wired rather than
|
|
485
|
-
* silently accepted-and-ignored
|
|
435
|
+
* silently accepted-and-ignored.
|
|
486
436
|
*/
|
|
487
437
|
function applyExtensionSignalsV4(scores, input, weights) {
|
|
488
438
|
const priorClass = input.history !== undefined && input.history.length > 0 ? input.history[0] : null;
|
|
@@ -509,10 +459,10 @@ function applyExtensionSignalsV4(scores, input, weights) {
|
|
|
509
459
|
* class from `weights` -> argmax with `TASK_CLASSES_V4` precedence tie-break,
|
|
510
460
|
* tracking the runner-up -> compute margin/confidence/confidenceBand/tieBreak
|
|
511
461
|
* from the RAW scores -> if `topScore <= 0`, replace `taskClass` (and record
|
|
512
|
-
* `fallbackReason`) via the
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
*
|
|
462
|
+
* `fallbackReason`) via the zero-score cascade (fence/diff -> code-gen;
|
|
463
|
+
* length < 40 -> trivial; length >= 2400 -> plan; lane fallback; default
|
|
464
|
+
* code-gen) — the raw scores/margin/runnerUp/tieBreak fields still reflect the
|
|
465
|
+
* pre-cascade computation, for audit purposes.
|
|
516
466
|
*
|
|
517
467
|
* Pure: same (input, weights) -> same ClassifierVerdictV4.
|
|
518
468
|
*/
|
|
@@ -592,28 +542,12 @@ export function classifyTaskV4(input, weights = DEFAULT_WEIGHTS_V4) {
|
|
|
592
542
|
// ============================================================================
|
|
593
543
|
// Resolver
|
|
594
544
|
// ============================================================================
|
|
595
|
-
/**
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
"code-gen": "medium",
|
|
602
|
-
debug: "high",
|
|
603
|
-
refactor: "high",
|
|
604
|
-
review: "high",
|
|
605
|
-
plan: "xhigh",
|
|
606
|
-
};
|
|
607
|
-
/** Lane ladder adjustment. Identical to v1/v2/v3: planner/security escalate one step, explorer de-escalates. */
|
|
608
|
-
const LANE_STEP_V4 = {
|
|
609
|
-
planner: 1,
|
|
610
|
-
security: 1,
|
|
611
|
-
explorer: -1,
|
|
612
|
-
};
|
|
613
|
-
/** Maximum magnitude of the learning/consult bias (ladder steps). Identical bound to v2/v3. */
|
|
614
|
-
const BIAS_MAX_V4 = 2;
|
|
615
|
-
/** Confidence floor at which an override hint is fused into the target. Identical to v2/v3. */
|
|
616
|
-
const HINT_CONFIDENCE_THRESHOLD_V4 = 0.7;
|
|
545
|
+
/**
|
|
546
|
+
* Static rule table: task class -> recommended ThinkingLevel. Re-exported
|
|
547
|
+
* from the shared resolver core (byte-identical values; previously a
|
|
548
|
+
* duplicated literal here — see reasoning-router-resolver.ts).
|
|
549
|
+
*/
|
|
550
|
+
export const TASK_CLASS_THINKING_LEVELS_V4 = TASK_CLASS_THINKING_LEVELS;
|
|
617
551
|
/**
|
|
618
552
|
* Bounded, strictly non-negative escalation applied when the verdict's own
|
|
619
553
|
* confidence is low or a fallback (not a real signal) decided the class. This
|
|
@@ -621,37 +555,19 @@ const HINT_CONFIDENCE_THRESHOLD_V4 = 0.7;
|
|
|
621
555
|
* confidence can never lower effort (spec 008 Req 2 acceptance criterion).
|
|
622
556
|
*/
|
|
623
557
|
const LOW_CONFIDENCE_ESCALATION_STEPS_V4 = 1;
|
|
624
|
-
function clampToLadderIndexV4(index) {
|
|
625
|
-
return Math.max(0, Math.min(index, REASONING_LADDER_V4.length - 1));
|
|
626
|
-
}
|
|
627
|
-
function clampToAvailableV4(targetIndex, availableLevels) {
|
|
628
|
-
const availableOnLadder = REASONING_LADDER_V4.filter((level) => availableLevels.includes(level));
|
|
629
|
-
if (availableOnLadder.length === 0)
|
|
630
|
-
return availableLevels[0] ?? "off";
|
|
631
|
-
for (let i = targetIndex; i >= 0; i--) {
|
|
632
|
-
const candidate = REASONING_LADDER_V4[i];
|
|
633
|
-
if (availableOnLadder.includes(candidate))
|
|
634
|
-
return candidate;
|
|
635
|
-
}
|
|
636
|
-
return availableOnLadder[0];
|
|
637
|
-
}
|
|
638
558
|
/**
|
|
639
559
|
* Thin auto-mode wrapper with no uncertainty adjustment: base rule table ->
|
|
640
|
-
* lane step -> clamp to availableLevels.
|
|
641
|
-
*
|
|
642
|
-
* same (taskClass, availableLevels, laneType) — i.e. v4's "confident" path.
|
|
560
|
+
* lane step -> clamp to availableLevels. This is v4's "confident" path and
|
|
561
|
+
* delegates to the shared resolver core with bias=0, hint=null, escalationSteps=0.
|
|
643
562
|
*/
|
|
644
563
|
export function resolveThinkingLevelV4ForAuto(taskClass, availableLevels, laneType) {
|
|
645
|
-
|
|
646
|
-
const laneStep = laneType ? (LANE_STEP_V4[laneType] ?? 0) : 0;
|
|
647
|
-
const targetIndex = clampToLadderIndexV4(baseIndex + laneStep);
|
|
648
|
-
return clampToAvailableV4(targetIndex, availableLevels);
|
|
564
|
+
return resolveThinkingLevelCore(taskClass, availableLevels, laneType, 0, null, 0);
|
|
649
565
|
}
|
|
650
566
|
/**
|
|
651
567
|
* Uncertainty-aware resolver (spec 008 Req 2 / plan.md step 5).
|
|
652
568
|
*
|
|
653
569
|
* Pipeline: base rule table for `verdict.taskClass` -> lane step -> bounded
|
|
654
|
-
* bias [-2,+2] -> optional hint fusion (±2 bounded
|
|
570
|
+
* bias [-2,+2] -> optional hint fusion (±2 bounded) -> bounded
|
|
655
571
|
* non-negative confidence escalation (+1 ladder step exactly when
|
|
656
572
|
* `verdict.confidenceBand === "low"` or `verdict.fallbackReason !== null`) ->
|
|
657
573
|
* clamp to `availableLevels`.
|
|
@@ -663,21 +579,7 @@ export function resolveThinkingLevelV4ForAuto(taskClass, availableLevels, laneTy
|
|
|
663
579
|
* hint=null) — text alone cannot talk the resolver down.
|
|
664
580
|
*/
|
|
665
581
|
export function resolveThinkingLevelV4WithUncertainty(verdict, availableLevels, laneType, bias = 0, hint = null) {
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
const biasClamped = Math.max(-BIAS_MAX_V4, Math.min(BIAS_MAX_V4, bias));
|
|
669
|
-
let targetIndex = clampToLadderIndexV4(baseIndex + laneStep + biasClamped);
|
|
670
|
-
if (hint !== null && hint.confidence >= HINT_CONFIDENCE_THRESHOLD_V4) {
|
|
671
|
-
const hintIndex = REASONING_LADDER_V4.indexOf(hint.level);
|
|
672
|
-
if (hintIndex >= 0) {
|
|
673
|
-
const delta = hintIndex - targetIndex;
|
|
674
|
-
const step = Math.max(-BIAS_MAX_V4, Math.min(BIAS_MAX_V4, delta));
|
|
675
|
-
targetIndex = clampToLadderIndexV4(targetIndex + step);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
if (verdict.confidenceBand === "low" || verdict.fallbackReason !== null) {
|
|
679
|
-
targetIndex = clampToLadderIndexV4(targetIndex + LOW_CONFIDENCE_ESCALATION_STEPS_V4);
|
|
680
|
-
}
|
|
681
|
-
return clampToAvailableV4(targetIndex, availableLevels);
|
|
582
|
+
const escalationSteps = verdict.confidenceBand === "low" || verdict.fallbackReason !== null ? LOW_CONFIDENCE_ESCALATION_STEPS_V4 : 0;
|
|
583
|
+
return resolveThinkingLevelCore(verdict.taskClass, availableLevels, laneType, bias, hint, escalationSteps);
|
|
682
584
|
}
|
|
683
585
|
//# sourceMappingURL=reasoning-router-v4.js.map
|