dsh-cot-anchor 0.3.1 → 0.3.3
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/lib/index.js +286 -1
- package/package.json +51 -53
package/lib/index.js
CHANGED
|
@@ -1030,7 +1030,15 @@ function wantsSoftCut(fullVisibleText, minReasoningChars) {
|
|
|
1030
1030
|
// execution announcement (write/edit/refactor/run/…) is the phase-B cut
|
|
1031
1031
|
// this detector targets. The matched verb is prepended so the gate judges
|
|
1032
1032
|
// the announced action itself, not the object that follows it.
|
|
1033
|
-
|
|
1033
|
+
//
|
|
1034
|
+
// 修复④:保留单次调查前缀放行(设计初衷:放走一次性的"我先看看配置"),
|
|
1035
|
+
// 但若最近尾窗内同一调查前缀重复 ≥ INVESTIGATIVE_PREFIX_REPEAT_MAX 次
|
|
1036
|
+
// 且动作动词远多于执行动词(典型空转特征),则收紧为可切。
|
|
1037
|
+
const tightenInfo = shouldTightenInvestigativePrefix(fullVisibleText);
|
|
1038
|
+
if (transitionLeadsToInvestigation(transitionVerb + tail.slice(transitionEnd))) {
|
|
1039
|
+
if (!tightenInfo.triggered) return false;
|
|
1040
|
+
// 触发收紧:跳过 investigation gate,让 transition 判定继续通过
|
|
1041
|
+
}
|
|
1034
1042
|
|
|
1035
1043
|
// The transition must be in the LAST sentence-ish chunk, not buried mid-answer.
|
|
1036
1044
|
const lastBreak = Math.max(tail.lastIndexOf("。"), tail.lastIndexOf("!"), tail.lastIndexOf("?"), tail.lastIndexOf("\n"), tail.lastIndexOf("."), tail.lastIndexOf(";"), tail.lastIndexOf(";"));
|
|
@@ -1167,6 +1175,85 @@ const CASCADING_PATTERNS = [
|
|
|
1167
1175
|
*/
|
|
1168
1176
|
const INVESTIGATIVE_TRANSITION_PREFIXES = ["我先", "接下来我", "接下来", "下一步我", "下一步", "下面我", "下面", "现在开始", "现在就", "然后我", "然后", "我接下来", "那就先", "先将"];
|
|
1169
1177
|
|
|
1178
|
+
// ── 修复④:transition 调查前缀分组复核 ──
|
|
1179
|
+
// INVESTIGATIVE_TRANSITION_PREFIXES 单次放行(放走"我先看看配置"),但"让我 curl 一下"
|
|
1180
|
+
// 被它被动放行后若反复出现(≥ 前缀重复上限)且无执行动词,就收紧为可切。
|
|
1181
|
+
// 这些前缀在泄漏样本 tail3000 里出现 25 次("我先"15 + "然后"8 + 其他 2),动作动词
|
|
1182
|
+
// 计数 53,执行动词计数仅 1,明显失衡。
|
|
1183
|
+
const INVESTIGATIVE_PREFIX_REPEAT_MAX = 6; // 最近尾窗内同一前缀命中 ≥ 此值触发收紧
|
|
1184
|
+
const INVESTIGATIVE_PREFIX_WINDOW_CHARS = 8000; // 计数窗口与 REPEAT_WINDOW_CHARS 同阶
|
|
1185
|
+
const INVESTIGATIVE_EXEC_VERBS = new Set([
|
|
1186
|
+
"write", "edit", "rewrite", "refactor", "delete", "replace", "deploy",
|
|
1187
|
+
"implement", "update", "build", "run", "create", "add", "make", "fix",
|
|
1188
|
+
"move", "open", "创建", "写", "改", "执行", "调用", "生成", "删除",
|
|
1189
|
+
"替换", "重构", "部署", "更新", "编译", "跑"
|
|
1190
|
+
]);
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* 修复④:最近尾窗内 INVESTIGATIVE_TRANSITION_PREFIXES 各前缀的分组命中计数。
|
|
1194
|
+
* @param {string} fullVisibleText
|
|
1195
|
+
* @returns {{prefix:string, count:number}[]} 按 count 降序
|
|
1196
|
+
*/
|
|
1197
|
+
function countInvestigativePrefixes(fullVisibleText) {
|
|
1198
|
+
if (typeof fullVisibleText !== "string") return [];
|
|
1199
|
+
const tail = fullVisibleText.slice(-INVESTIGATIVE_PREFIX_WINDOW_CHARS);
|
|
1200
|
+
const counts = new Map();
|
|
1201
|
+
for (const p of INVESTIGATIVE_TRANSITION_PREFIXES) {
|
|
1202
|
+
const re = new RegExp(p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g');
|
|
1203
|
+
re.lastIndex = 0;
|
|
1204
|
+
const m = tail.match(re);
|
|
1205
|
+
if (m && m.length > 0) counts.set(p, m.length);
|
|
1206
|
+
}
|
|
1207
|
+
return [...counts.entries()]
|
|
1208
|
+
.map(([prefix, count]) => ({ prefix, count }))
|
|
1209
|
+
.sort((a, b) => b.count - a.count);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* 修复④:动作动词(tool verb)与执行动词(exec verb)计数对比。
|
|
1214
|
+
* 动作动词 = curl/fetch/web_fetch/访问/打开/探/查/验证/试一下;执行动词 = 写/改/创建/执行...
|
|
1215
|
+
* 动作动词走正则(中英文混合,带边界),执行动词同样走正则字面量覆盖 CJK + Latin。
|
|
1216
|
+
* @param {string} text
|
|
1217
|
+
* @returns {{actionCount:number, execCount:number}}
|
|
1218
|
+
*/
|
|
1219
|
+
function countActionVsExecVerbs(text) {
|
|
1220
|
+
if (typeof text !== "string") return { actionCount: 0, execCount: 0 };
|
|
1221
|
+
const tail = text.slice(-CHURN_WINDOW_CHARS);
|
|
1222
|
+
// 动作动词:工具名(curl/fetch/web_fetch) + 执行类单字(访问/打开) + 探/查 的独立形式
|
|
1223
|
+
// 探/查 排除合成词中的裸字(检查/查看/探查/查核/查寻/确认/探察/探测 里的"探/查"不算独立动作动词)
|
|
1224
|
+
// 负向后视 排除前字 + 负向前瞻 排除后字(两边都防)
|
|
1225
|
+
const actionRe = /(?:\bcurl\b|\bfetch\b|\bweb[-_ ]?fetch\b|访问|打开|验证|试一下|看看|探一下|查一下|(?<![检确勘观])探(?!察|测|查|究)|(?<![检查核询])查(?!查|找|核|询|看|实))/gi;
|
|
1226
|
+
actionRe.lastIndex = 0;
|
|
1227
|
+
const actionCount = (tail.match(actionRe) || []).length;
|
|
1228
|
+
const execRe = /(?:\bwrite\b|\bedit\b|\brewrite\b|\brefactor\b|\bdelete\b|\breplace\b|\bdeploy\b|\bimplement\b|\bupdate\b|\bbuild\b|\brun\b|\bcreate\b|\badd\b|\bmake\b|\bfix\b|\bmove\b|创建|写|改|执行|调用|生成|删除|替换|重构|部署|更新|编译|跑)/gi;
|
|
1229
|
+
execRe.lastIndex = 0;
|
|
1230
|
+
const execCount = (tail.match(execRe) || []).length;
|
|
1231
|
+
return { actionCount, execCount };
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
/**
|
|
1235
|
+
* 修复④:是否触发"调查前缀收紧"。
|
|
1236
|
+
* 条件:① 某调查前缀在最近窗口内重复 ≥ INVESTIGATIVE_PREFIX_REPEAT_MAX 次;
|
|
1237
|
+
* ② 动作动词计数 ≥ 执行动词计数 × 5(动作远多于执行,典型空转特征)。
|
|
1238
|
+
* 触发时 wantsSoftCut 里不再被 transitionLeadsToInvestigation 放行。
|
|
1239
|
+
* @param {string} fullVisibleText
|
|
1240
|
+
* @returns {{triggered:boolean, topPrefix:string|null, repeatCount:number, actionCount:number, execCount:number}}
|
|
1241
|
+
*/
|
|
1242
|
+
function shouldTightenInvestigativePrefix(fullVisibleText) {
|
|
1243
|
+
const prefixCounts = countInvestigativePrefixes(fullVisibleText);
|
|
1244
|
+
const top = prefixCounts[0];
|
|
1245
|
+
const { actionCount, execCount } = countActionVsExecVerbs(fullVisibleText);
|
|
1246
|
+
const repeatOK = top && top.count >= INVESTIGATIVE_PREFIX_REPEAT_MAX;
|
|
1247
|
+
const actionDom = actionCount >= execCount * 5 && actionCount > 0;
|
|
1248
|
+
return {
|
|
1249
|
+
triggered: repeatOK && actionDom,
|
|
1250
|
+
topPrefix: top?.prefix ?? null,
|
|
1251
|
+
repeatCount: top?.count ?? 0,
|
|
1252
|
+
actionCount,
|
|
1253
|
+
execCount
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1170
1257
|
/**
|
|
1171
1258
|
* Single-character investigative verbs (Chinese) and their 2-char look-ahead
|
|
1172
1259
|
* steps. A transition whose leading action is one of these ("我先读…", "下一步我看…")
|
|
@@ -1443,6 +1530,118 @@ function renderNumberRunawayAnchor(nr) {
|
|
|
1443
1530
|
].join("\n");
|
|
1444
1531
|
}
|
|
1445
1532
|
|
|
1533
|
+
// ── 修复②:n-gram 语义指纹循环检测 ──
|
|
1534
|
+
// 现有 findRepeatingTail 找字节级相同块,措辞漂移型循环(每句数字变、动词结构不变)
|
|
1535
|
+
// 抓不到。本修复用数字归一 + n-gram 频率旁路,运行时零 LLM。
|
|
1536
|
+
|
|
1537
|
+
/** 修复②:短语级重复的 n-gram 粒度下限(设计文档中文 n=5,允许英文/中文混合下最小 4)。 */
|
|
1538
|
+
const NGram_PHRASE_MIN = 5;
|
|
1539
|
+
/** 修复②:高频短语最小出现次数。 */
|
|
1540
|
+
const NGram_MIN_COUNT = 5;
|
|
1541
|
+
/** 修复②:最高频短语覆盖尾窗的占比下限(≥15% 字符被同短语反复占用即判漂移循环)。 */
|
|
1542
|
+
const NGram_COVERAGE_RATIO = 0.05;
|
|
1543
|
+
/** 修复②:停用词集合,过滤普通高频词以防误报。 */
|
|
1544
|
+
const NGram_STOPWORDS = new Set([
|
|
1545
|
+
"的", "了", "是", "我", "你", "他", "她", "它", "们", "这", "那", "就", "也", "都",
|
|
1546
|
+
"要", "会", "能", "可以", "让", "把", "给", "对", "从", "用", "到", "在", "和", "与",
|
|
1547
|
+
"为", "于", "以", "及", "或", "不", "没", "有", "一", "一个", "一些", "什么", "怎么",
|
|
1548
|
+
"怎样", "为什么", "因为", "所以", "但是", "然而", "不过", "而且", "然后", "现在",
|
|
1549
|
+
"好,", "好。", "好", "那么", "接下来", "现在就",
|
|
1550
|
+
// 运行状态标签(LISTENING=True / PID=xxx / exit code)——泄漏样本每段都重复,
|
|
1551
|
+
// 但它本身不是循环证据,必须过滤让真正的循环短语(好+动词+工具名)浮出来
|
|
1552
|
+
"listening", "true", "false", "pid", "digit", "DIGIT", "running", "exit", "code",
|
|
1553
|
+
"web_fetch", "curl", "fetch", "localhost"
|
|
1554
|
+
]);
|
|
1555
|
+
|
|
1556
|
+
/**
|
|
1557
|
+
* 修复②:数字归一 + 小写 + 去标点空白,为 n-gram 指纹做准备。
|
|
1558
|
+
* PID=31760 → PID=DIGIT、端口号 / 路径里的数字同样处理。
|
|
1559
|
+
* 用字面量 DIGIT 而不是 <D>:尖括号属于要被 strip 的标点,归一符不能被自毁。
|
|
1560
|
+
* 先替换数字再 strip 标点——顺序关键。
|
|
1561
|
+
* @param {string} text
|
|
1562
|
+
* @returns {string}
|
|
1563
|
+
*/
|
|
1564
|
+
function normalizeForNGram(text) {
|
|
1565
|
+
if (typeof text !== "string") return "";
|
|
1566
|
+
return text
|
|
1567
|
+
.toLowerCase()
|
|
1568
|
+
.replace(/\d+/g, "DIGIT")
|
|
1569
|
+
.replace(/[,,。.!!??;;::""''()()【】\[\]<>《》—–\-]/g, " ")
|
|
1570
|
+
.replace(/\s+/g, " ")
|
|
1571
|
+
.trim();
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
/**
|
|
1575
|
+
* 修复②:尾窗 n-gram 频率统计。中文按单字符滑动(n=5),英文按词滑动(n=2)。
|
|
1576
|
+
* 混合文本场景退化为"以字符为单位 n=5"——够用且实现简单。
|
|
1577
|
+
* @param {string} normText 已过 normalizeForNGram
|
|
1578
|
+
* @param {number} nGramSize 短语粒度
|
|
1579
|
+
* @returns {{maxCount:number, maxGram:string, totalGrams:number, gramCount:Map<string, number>}|null}
|
|
1580
|
+
*/
|
|
1581
|
+
function computeNGramFingerprint(normText, nGramSize) {
|
|
1582
|
+
if (typeof normText !== "string" || normText.length < nGramSize * 4) return null;
|
|
1583
|
+
const gramCount = new Map();
|
|
1584
|
+
let totalGrams = 0;
|
|
1585
|
+
for (let i = 0; i <= normText.length - nGramSize; i++) {
|
|
1586
|
+
const gram = normText.slice(i, i + nGramSize);
|
|
1587
|
+
// 跳过含空白的 gram(normalize 已把标点换成空格,避免跨标点短语虚高)
|
|
1588
|
+
if (gram.includes(" ") || gram.includes("\n") || gram.includes("\t")) continue;
|
|
1589
|
+
let v = gramCount.get(gram) ?? 0;
|
|
1590
|
+
gramCount.set(gram, ++v);
|
|
1591
|
+
totalGrams++;
|
|
1592
|
+
}
|
|
1593
|
+
if (totalGrams === 0) return null;
|
|
1594
|
+
let maxCount = 0;
|
|
1595
|
+
let maxGram = "";
|
|
1596
|
+
for (const [g, c] of gramCount) {
|
|
1597
|
+
if (c > maxCount) { maxCount = c; maxGram = g; }
|
|
1598
|
+
}
|
|
1599
|
+
return { maxCount, maxGram, totalGrams, gramCount };
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* 修复②:判定是否为"语义漂移型循环"——跳过停用词 gram 后取最高频非停用 gram,
|
|
1604
|
+
* 其出现次数 ≥ NGram_MIN_COUNT 且覆盖占尾窗比例 ≥ NGram_COVERAGE_RATIO。
|
|
1605
|
+
* 与 findRepeatingTail 并行,不破坏原逻辑。
|
|
1606
|
+
* @param {string} fullVisibleText
|
|
1607
|
+
* @returns {{maxGram:string,count:number,coverage:number}|null}
|
|
1608
|
+
*/
|
|
1609
|
+
function detectNGramLoop(fullVisibleText) {
|
|
1610
|
+
if (typeof fullVisibleText !== "string" || fullVisibleText.length < REPEAT_MIN_TEXT_CHARS) return null;
|
|
1611
|
+
const tail = fullVisibleText.slice(-REPEAT_WINDOW_CHARS);
|
|
1612
|
+
const norm = normalizeForNGram(tail);
|
|
1613
|
+
const fp = computeNGramFingerprint(norm, NGram_PHRASE_MIN);
|
|
1614
|
+
if (!fp) return null;
|
|
1615
|
+
|
|
1616
|
+
// 取最高频非停用词 gram:先排序再跳过停用词条目
|
|
1617
|
+
const sorted = [...fp.gramCount.entries()].sort((a, b) => b[1] - a[1]);
|
|
1618
|
+
let chosenGram = "";
|
|
1619
|
+
let chosenCount = 0;
|
|
1620
|
+
for (const [gram, count] of sorted) {
|
|
1621
|
+
if (NGram_STOPWORDS.has(gram)) continue;
|
|
1622
|
+
// 停用词比例守卫:若 gram 中 ≥60% 字符在停用词表里,同样跳过
|
|
1623
|
+
const stopCharRatio = [...gram].filter((ch) => NGram_STOPWORDS.has(ch)).length / gram.length;
|
|
1624
|
+
if (stopCharRatio >= 0.6) continue;
|
|
1625
|
+
chosenGram = gram;
|
|
1626
|
+
chosenCount = count;
|
|
1627
|
+
break;
|
|
1628
|
+
}
|
|
1629
|
+
if (!chosenGram || chosenCount < NGram_MIN_COUNT) return null;
|
|
1630
|
+
const coverage = chosenCount * NGram_PHRASE_MIN / tail.length;
|
|
1631
|
+
if (coverage < NGram_COVERAGE_RATIO) return null;
|
|
1632
|
+
return { maxGram: chosenGram, count: chosenCount, coverage };
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
/** 修复②:n-gram 锚点。 */
|
|
1636
|
+
function renderNGramLoopAnchor(info) {
|
|
1637
|
+
return [
|
|
1638
|
+
`COT anchor — 语义循环(n-gram 指纹):最近尾窗里高频短语「${info.maxGram}」重复出现 ${info.count} 次(覆盖占比约 ${(info.coverage * 100).toFixed(1)}%)。`,
|
|
1639
|
+
"数字每轮都在变但动词结构每轮相同,说明你在同一个行动提议上打转。",
|
|
1640
|
+
"立即停止。要么真的发出 tool_call,要么直接跳到结果。",
|
|
1641
|
+
`(NGram loop: phrase "${info.maxGram}" x${info.count}, coverage ${(info.coverage * 100).toFixed(1)}%. Stop cycling.)`
|
|
1642
|
+
].join("\n");
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1446
1645
|
/**
|
|
1447
1646
|
* Text spellings that a model invents for tool calls. DSH has no parser for
|
|
1448
1647
|
* any of these: a tool call only exists as a structured tool-call block
|
|
@@ -1712,6 +1911,20 @@ let CHURN_MIN_HITS = 18;
|
|
|
1712
1911
|
/** Churn is only meaningful in an already long generation (lowered to fire sooner). */
|
|
1713
1912
|
let CHURN_MIN_TEXT_CHARS = 800;
|
|
1714
1913
|
|
|
1914
|
+
// ── 修复①:churn 行动提议分支 ──
|
|
1915
|
+
// 现有 CHURN_PHRASES 全是"思维重启"(让我想想 / re-read / reconsider),
|
|
1916
|
+
// 漏了"行动提议"——工具动词反复出现但零 tool_call 的异常形态。
|
|
1917
|
+
// 阈值沿用 CHURN_MIN_HITS=18,普通技术文本行动动词命中 0-3/3000 字,泄漏样本约 75/3000。
|
|
1918
|
+
const CHURN_ACTION_PHRASES = [
|
|
1919
|
+
/让我.{0,10}?(?:curl|fetch|web[-_ ]?fetch|试一下|访问|看看|探|查|验证|打开)/g,
|
|
1920
|
+
/我先.{0,10}?(?:curl|fetch|web[-_ ]?fetch|试一下|访问|看看|探|查)/g,
|
|
1921
|
+
/现在.{0,10}?(?:curl|fetch|试一下|访问|看看)/g,
|
|
1922
|
+
/直接.{0,6}?(?:curl|fetch|web[-_ ]?fetch|访问|打开)/g,
|
|
1923
|
+
/先.{0,6}?(?:curl|fetch|web[-_ ]?fetch|试一下|看看|访问|探|查)/g,
|
|
1924
|
+
/(?:curl|fetch|web[-_ ]?fetch).{0,3}?(?:一下|看看|试试)/g
|
|
1925
|
+
];
|
|
1926
|
+
const CHURN_ACTION_MIN_HITS = 18;
|
|
1927
|
+
|
|
1715
1928
|
/**
|
|
1716
1929
|
* Count restart-phrase hits in the trailing window.
|
|
1717
1930
|
* @param {string} fullVisibleText
|
|
@@ -1742,6 +1955,19 @@ function detectChurn(fullVisibleText) {
|
|
|
1742
1955
|
return { hits };
|
|
1743
1956
|
}
|
|
1744
1957
|
|
|
1958
|
+
/**
|
|
1959
|
+
* 修复①:检测"行动提议型空转"——尾窗内工具动词前缀 / 后缀形态的正则计数 ≥ 阈值。
|
|
1960
|
+
* 与 detectChurn 并行:CHURN_PHRASES 抓思维重启,CHURN_ACTION_PHRASES 抓行动提议。
|
|
1961
|
+
* @param {string} fullVisibleText
|
|
1962
|
+
* @returns {{hits:number}|null}
|
|
1963
|
+
*/
|
|
1964
|
+
function detectActionChurn(fullVisibleText) {
|
|
1965
|
+
if (typeof fullVisibleText !== "string" || fullVisibleText.length < CHURN_MIN_TEXT_CHARS) return null;
|
|
1966
|
+
const hits = countChurnHits(fullVisibleText, CHURN_ACTION_PHRASES);
|
|
1967
|
+
if (hits < CHURN_ACTION_MIN_HITS) return null;
|
|
1968
|
+
return { hits };
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1745
1971
|
/**
|
|
1746
1972
|
* Render the anchor that breaks a churn loop.
|
|
1747
1973
|
* @param {{hits:number}} churn
|
|
@@ -1756,6 +1982,20 @@ function renderChurnAnchor(churn) {
|
|
|
1756
1982
|
].join("\n");
|
|
1757
1983
|
}
|
|
1758
1984
|
|
|
1985
|
+
/**
|
|
1986
|
+
* 修复①:行动提议型空转锚点。与 renderChurnAnchor 并列,用语明确指向"说了要调用但从未调用"。
|
|
1987
|
+
* @param {{hits:number}} churn
|
|
1988
|
+
* @returns {string}
|
|
1989
|
+
*/
|
|
1990
|
+
function renderActionChurnAnchor(churn) {
|
|
1991
|
+
return [
|
|
1992
|
+
`COT anchor — 行动提议空转:最近约 ${CHURN_WINDOW_CHARS} 字里出现了 ${churn.hits} 次"让我 curl / web_fetch"这类行动提议,但全程没有实际工具调用。`,
|
|
1993
|
+
"立即停止空喊工具名。不要再说\"让我 curl 一下\"、\"先试试 web_fetch\"这类没有执行的提议。",
|
|
1994
|
+
"要么真的发出 tool_call(带完整参数),要么直接跳到结果;不要再重复同一个行动提议。",
|
|
1995
|
+
`(Action-proposal stall: ${churn.hits} tool-verb proposals in the last ~${CHURN_WINDOW_CHARS} chars with zero real tool_call. Stop proposing — either emit the tool_call or give the result.)`
|
|
1996
|
+
].join("\n");
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1759
1999
|
/**
|
|
1760
2000
|
* 缺陷 3 修复(2026-10-07 升级版):churn 每 turn 命中计数。键 = sessionId,值为
|
|
1761
2001
|
* { lastTurn, count }:count 是本 turn handler 返回 churn cut 决策的次数。计数口径
|
|
@@ -4358,6 +4598,26 @@ function apply(ctx, config) {
|
|
|
4358
4598
|
};
|
|
4359
4599
|
}
|
|
4360
4600
|
|
|
4601
|
+
// (2a) 修复②:n-gram 语义指纹循环。与 findRepeatingTail 并行,措辞漂移型
|
|
4602
|
+
// 循环(每句数字变、动词结构不变)字节级抓不到,但数字归一 + n-gram 频率
|
|
4603
|
+
// 能稳定定位。运行时零 LLM:哈希分窗 + HashMap 计数。
|
|
4604
|
+
const ngramLoop = settings.enableRepeat ? detectNGramLoop(fullText) : null;
|
|
4605
|
+
if (ngramLoop) {
|
|
4606
|
+
noteSoftCutFired();
|
|
4607
|
+
emitCotAnchorEvent(ctx, EVENT_SOFTCUT_TAKEN, {
|
|
4608
|
+
...evidenceBase(payload?.sessionId, payload?.turn, payload?.step),
|
|
4609
|
+
cutClass: "heuristic",
|
|
4610
|
+
detector: "ngram-loop"
|
|
4611
|
+
});
|
|
4612
|
+
return {
|
|
4613
|
+
kind: "cut",
|
|
4614
|
+
budgetClass: "heuristic",
|
|
4615
|
+
cutClass: "heuristic",
|
|
4616
|
+
contexts: [buildAnchorContext(renderNGramLoopAnchor(ngramLoop),
|
|
4617
|
+
`cot-anchor: ngram-loop "${ngramLoop.maxGram}" x${ngramLoop.count}`)]
|
|
4618
|
+
};
|
|
4619
|
+
}
|
|
4620
|
+
|
|
4361
4621
|
// Number runaway: a monotone-increasing run of bare numbers. Distinct
|
|
4362
4622
|
// from byte-repetition (findRepeatingTail above) and churn (below);
|
|
4363
4623
|
// cut to the run start so the runaway copies never reach the session.
|
|
@@ -4408,6 +4668,31 @@ function apply(ctx, config) {
|
|
|
4408
4668
|
};
|
|
4409
4669
|
}
|
|
4410
4670
|
|
|
4671
|
+
// (3a) 修复①:行动提议型空转并行分支。CHURN_ACTION_PHRASES 抓"让我 curl"这类
|
|
4672
|
+
// 无实际 tool_call 的动词反复出现。阈值 CHURN_ACTION_MIN_HITS=18,普通技术文本
|
|
4673
|
+
// 行动动词命中 0-3/3000 字,泄漏样本 ~75/3000 字,余量充足。
|
|
4674
|
+
// 独立于 enableChurn,默认与 enableChurn 同开关语义——通过 enableChurn 统一门禁,
|
|
4675
|
+
// 无需新增 settings key;如需独立控制可后续扩展 enableActionChurn。
|
|
4676
|
+
const actionChurn = !settings.enableChurn || insideUnclosedCodeFence(fullText) ? null : detectActionChurn(fullText);
|
|
4677
|
+
if (actionChurn) {
|
|
4678
|
+
noteSoftCutFired();
|
|
4679
|
+
const churnKey = typeof payload?.sessionId === "string" ? payload.sessionId : "";
|
|
4680
|
+
const churnOccurrence = recordChurnCut(churnKey, payload?.turn);
|
|
4681
|
+
const anchorText = renderActionChurnAnchor(actionChurn)
|
|
4682
|
+
+ (churnOccurrence >= 2 ? renderChurnEscalation(churnOccurrence) : "");
|
|
4683
|
+
emitCotAnchorEvent(ctx, EVENT_SOFTCUT_TAKEN, {
|
|
4684
|
+
...evidenceBase(payload?.sessionId, payload?.turn, payload?.step),
|
|
4685
|
+
cutClass: "heuristic",
|
|
4686
|
+
detector: "action-churn"
|
|
4687
|
+
});
|
|
4688
|
+
return {
|
|
4689
|
+
kind: "cut",
|
|
4690
|
+
budgetClass: "heuristic",
|
|
4691
|
+
cutClass: "heuristic",
|
|
4692
|
+
contexts: [buildAnchorContext(anchorText, `cot-anchor: action-churn x${actionChurn.hits}`)]
|
|
4693
|
+
};
|
|
4694
|
+
}
|
|
4695
|
+
|
|
4411
4696
|
// (4) A→"接下来我要…"→B transition inside one generation.
|
|
4412
4697
|
// The cut is destructive, so it requires an EXPLICIT conclusion
|
|
4413
4698
|
// ("所以/因此/综上/therefore …") already present — a density-only
|
package/package.json
CHANGED
|
@@ -1,53 +1,51 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-cot-anchor",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "思考锚点:从模型上一段思考中提取已确立结论,在工具结果后注入,减少重复推导;并可识别打转与伪工具调用",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"dsh",
|
|
7
|
-
"deepseek-harness",
|
|
8
|
-
"dsh-plugin",
|
|
9
|
-
"cot",
|
|
10
|
-
"context",
|
|
11
|
-
"agent"
|
|
12
|
-
],
|
|
13
|
-
"type": "module",
|
|
14
|
-
"main": "lib/index.js",
|
|
15
|
-
"exports": {
|
|
16
|
-
".": "./lib/index.js",
|
|
17
|
-
"./client": "./lib/client.js",
|
|
18
|
-
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
19
|
-
"./package.json": "./package.json"
|
|
20
|
-
},
|
|
21
|
-
"files": [
|
|
22
|
-
"lib/",
|
|
23
|
-
"!lib/**/*.bak*",
|
|
24
|
-
"tools/",
|
|
25
|
-
"docs/softcut-kernel-port.md",
|
|
26
|
-
"cordis.patch.yml",
|
|
27
|
-
"README.md",
|
|
28
|
-
"LICENSE"
|
|
29
|
-
],
|
|
30
|
-
"dsh": {
|
|
31
|
-
"bundle": {
|
|
32
|
-
"patch": "./cordis.patch.yml"
|
|
33
|
-
},
|
|
34
|
-
"client": {
|
|
35
|
-
"platform": "web",
|
|
36
|
-
"inject": []
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
"peerDependencies": {
|
|
40
|
-
"@deepseek-ai/dsh": ">=0.1.5-rc.1 <0.2.0 || >=0.2.0-rc.1 <0.3.0-0"
|
|
41
|
-
},
|
|
42
|
-
"repository": {
|
|
43
|
-
"type": "git",
|
|
44
|
-
"url": "git+https://github.com/JiewiW/dsh-cot-anchor.git"
|
|
45
|
-
},
|
|
46
|
-
"homepage": "https://github.com/JiewiW/dsh-cot-anchor#readme",
|
|
47
|
-
"bugs": {
|
|
48
|
-
"url": "https://github.com/JiewiW/dsh-cot-anchor/issues"
|
|
49
|
-
},
|
|
50
|
-
"license": "MIT"
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-cot-anchor",
|
|
3
|
+
"version": "0.3.3",
|
|
4
|
+
"description": "思考锚点:从模型上一段思考中提取已确立结论,在工具结果后注入,减少重复推导;并可识别打转与伪工具调用",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dsh",
|
|
7
|
+
"deepseek-harness",
|
|
8
|
+
"dsh-plugin",
|
|
9
|
+
"cot",
|
|
10
|
+
"context",
|
|
11
|
+
"agent"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./lib/index.js",
|
|
17
|
+
"./client": "./lib/client.js",
|
|
18
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"lib/",
|
|
23
|
+
"!lib/**/*.bak*",
|
|
24
|
+
"tools/",
|
|
25
|
+
"docs/softcut-kernel-port.md",
|
|
26
|
+
"cordis.patch.yml",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"dsh": {
|
|
31
|
+
"bundle": {
|
|
32
|
+
"patch": "./cordis.patch.yml"
|
|
33
|
+
},
|
|
34
|
+
"client": {
|
|
35
|
+
"platform": "web",
|
|
36
|
+
"inject": []
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@deepseek-ai/dsh": ">=0.1.5-rc.1 <0.2.0 || >=0.2.0-rc.1 <0.3.0-0"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/JiewiW/dsh-cot-anchor.git"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/JiewiW/dsh-cot-anchor#readme",
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/JiewiW/dsh-cot-anchor/issues"
|
|
49
|
+
},
|
|
50
|
+
"license": "MIT"
|
|
51
|
+
}
|