dsh-cot-anchor 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +183 -52
- package/package.json +53 -51
package/lib/index.js
CHANGED
|
@@ -883,19 +883,21 @@ function buildAnchorContext(text, summary) {
|
|
|
883
883
|
* 执行后单独堆叠一条 `cot-anchor: exec-discipline` 消息),而是经
|
|
884
884
|
* systemPrompt.context 注册为运行时上下文快照("Current runtime context…")
|
|
885
885
|
* 中的一个固定段:每轮只出现一次、位置在记忆规则之后、用户唠叨之前,且为
|
|
886
|
-
* 常量前缀,有利于 KV
|
|
887
|
-
*
|
|
886
|
+
* 常量前缀,有利于 KV 前缀缓存命中。
|
|
887
|
+
*
|
|
888
|
+
* 发布版为插件自带通用纪律(不引用任何用户本机路径);本机用户如需个人化
|
|
889
|
+
* 纪律,可自行修改本数组后重启,或在设置中关闭「随锚点注入命令执行纪律块」。
|
|
888
890
|
*/
|
|
889
891
|
const EXEC_DISCIPLINE_TEXT = [
|
|
890
|
-
"⓪ 命令执行纪律(最高优先,高于一切):跑任何命令(
|
|
891
|
-
"① 单次等待 ≤10
|
|
892
|
-
"②
|
|
892
|
+
"⓪ 命令执行纪律(最高优先,高于一切):跑任何命令(shell/构建/安装/下载/测试/长任务)都不许盲等,且必须核验结果。",
|
|
893
|
+
"① 单次等待 ≤10 秒;禁止超长阻塞等待、禁止长延时 sleep 后再检查。",
|
|
894
|
+
"② 每轮必须查并打印一个『增长型标量』——目标文件/目录是否出现、字节数是否变大、日志是否追加、输出行数是否增加。",
|
|
893
895
|
"③ 『进程还在』『任务 state=running』不算进展证据,禁止据此继续等;连续 2 轮零增长即判僵死,",
|
|
894
896
|
"用精确 PID 中断(禁止按命令名通配批量杀)并立刻换办法(换镜像源→换工具/协议→复用本机缓存→降级最小子集→报告用户)。",
|
|
895
897
|
"④ 起长任务前把精确 PID 落盘。⑤ 长任务按固定短间隔(≤10 秒)轮询等待,禁止盲等。",
|
|
896
898
|
"⑥ 命令结束必须核验:看退出码、看产物是否真的生成、看日志关键行,不以『命令跑了没报错』当成功。",
|
|
897
899
|
"⑦ 输出为空/被吞/返回 -1 时,第一动作是读该命令本应写出的报告或产物判成功,不要追加复查命令。",
|
|
898
|
-
"⑧ 同一命令同样参数失败最多重试 2
|
|
900
|
+
"⑧ 同一命令同样参数失败最多重试 2 次,之后换办法或上报。"
|
|
899
901
|
].join("");
|
|
900
902
|
|
|
901
903
|
/**
|
|
@@ -1534,12 +1536,16 @@ function renderNumberRunawayAnchor(nr) {
|
|
|
1534
1536
|
// 现有 findRepeatingTail 找字节级相同块,措辞漂移型循环(每句数字变、动词结构不变)
|
|
1535
1537
|
// 抓不到。本修复用数字归一 + n-gram 频率旁路,运行时零 LLM。
|
|
1536
1538
|
|
|
1537
|
-
/**
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1539
|
+
/**
|
|
1540
|
+
* 修复②:短语级重复的 n-gram 粒度下限(字符级滑窗粒度,默认 5)。
|
|
1541
|
+
* 运行时可经 DEFAULT_SETTINGS.ngramPhraseMin 覆盖(applyRuntimeSettings 写回本绑定;
|
|
1542
|
+
* 声明处保持字面量是因为 DEFAULT_SETTINGS 在本文件更靠后位置,模块加载期不可引用)。
|
|
1543
|
+
*/
|
|
1544
|
+
let NGram_PHRASE_MIN = 5;
|
|
1545
|
+
/** 修复②:高频短语最小出现次数(默认 5;运行时可经 ngramMinCount 覆盖)。 */
|
|
1546
|
+
let NGram_MIN_COUNT = 5;
|
|
1547
|
+
/** 修复②:最高频短语覆盖尾窗的占比下限(默认 0.05;运行时可经 ngramCoverageRatio 覆盖)。 */
|
|
1548
|
+
let NGram_COVERAGE_RATIO = 0.05;
|
|
1543
1549
|
/** 修复②:停用词集合,过滤普通高频词以防误报。 */
|
|
1544
1550
|
const NGram_STOPWORDS = new Set([
|
|
1545
1551
|
"的", "了", "是", "我", "你", "他", "她", "它", "们", "这", "那", "就", "也", "都",
|
|
@@ -1550,7 +1556,18 @@ const NGram_STOPWORDS = new Set([
|
|
|
1550
1556
|
// 运行状态标签(LISTENING=True / PID=xxx / exit code)——泄漏样本每段都重复,
|
|
1551
1557
|
// 但它本身不是循环证据,必须过滤让真正的循环短语(好+动词+工具名)浮出来
|
|
1552
1558
|
"listening", "true", "false", "pid", "digit", "DIGIT", "running", "exit", "code",
|
|
1553
|
-
"web_fetch", "curl", "fetch", "localhost"
|
|
1559
|
+
"web_fetch", "curl", "fetch", "web", "localhost",
|
|
1560
|
+
// 英文技术高频词(每个词只保留一次)——settings/entry/path 这类术语在技术文本
|
|
1561
|
+
// 尾窗内天然高频,本身不是循环证据;且其常见搭配("the settings" 等)两个词全在
|
|
1562
|
+
// 表内,stopCharRatio 守卫会一并过滤,让真正的动词结构循环浮出来
|
|
1563
|
+
"settings", "config", "path", "entry", "state", "field", "value", "file", "data",
|
|
1564
|
+
"plugin", "session", "context", "window", "token", "model", "result", "check", "call",
|
|
1565
|
+
"step", "text", "full", "visible", "use", "used", "need", "find", "found", "read",
|
|
1566
|
+
"write", "test", "line", "log",
|
|
1567
|
+
// 通用英文虚词
|
|
1568
|
+
"the", "and", "for", "with", "this", "that", "from", "have", "has", "was", "were",
|
|
1569
|
+
"will", "can", "could", "should", "would", "but", "not", "are", "is", "in", "on",
|
|
1570
|
+
"of", "to"
|
|
1554
1571
|
]);
|
|
1555
1572
|
|
|
1556
1573
|
/**
|
|
@@ -1566,42 +1583,140 @@ function normalizeForNGram(text) {
|
|
|
1566
1583
|
return text
|
|
1567
1584
|
.toLowerCase()
|
|
1568
1585
|
.replace(/\d+/g, "DIGIT")
|
|
1569
|
-
|
|
1586
|
+
// 下划线 `_` 与标点同样替换为空格:避免 web_fetch / settings_mutate 切出
|
|
1587
|
+
// "web_f"/"web fe" 之类伪子串虚高(下划线在字符类里按字面量处理)
|
|
1588
|
+
.replace(/[,,。.!!??;;::""''()()【】\[\]<>《》—–\-_]/g, " ")
|
|
1570
1589
|
.replace(/\s+/g, " ")
|
|
1571
1590
|
.trim();
|
|
1572
1591
|
}
|
|
1573
1592
|
|
|
1574
1593
|
/**
|
|
1575
|
-
*
|
|
1576
|
-
*
|
|
1577
|
-
* @param {
|
|
1578
|
-
* @
|
|
1594
|
+
* 修复②:从频次 Map 取最高频 gram(含总 gram 数),供字符轨 / 英文词轨共用。
|
|
1595
|
+
* @param {Map<string, number>} gramCount
|
|
1596
|
+
* @param {number} totalGrams
|
|
1597
|
+
* @returns {{maxCount:number, maxGram:string, totalGrams:number, gramCount:Map<string, number>}}
|
|
1598
|
+
*/
|
|
1599
|
+
function pickMaxFromCountMap(gramCount, totalGrams) {
|
|
1600
|
+
let maxCount = 0;
|
|
1601
|
+
let maxGram = "";
|
|
1602
|
+
for (const [g, c] of gramCount) {
|
|
1603
|
+
if (c > maxCount) { maxCount = c; maxGram = g; }
|
|
1604
|
+
}
|
|
1605
|
+
return { maxCount, maxGram, totalGrams, gramCount };
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
/**
|
|
1609
|
+
* 修复②:英文词级 2-gram 频率统计。相邻两个英文词([a-z]+ 抽取)为一个 gram,
|
|
1610
|
+
* 如 "settings path"。英文单词是原子 token:单词内部子串("setti"/"etting")
|
|
1611
|
+
* 永远不会成为 gram。词级 gram 允许含空格——两词之间的空白正是短语边界。
|
|
1612
|
+
* @param {string[]} words 英文词序列
|
|
1579
1613
|
* @returns {{maxCount:number, maxGram:string, totalGrams:number, gramCount:Map<string, number>}|null}
|
|
1580
1614
|
*/
|
|
1581
|
-
function
|
|
1582
|
-
if (typeof normText !== "string" || normText.length < nGramSize * 4) return null;
|
|
1615
|
+
function computeWordBigramFingerprint(words) {
|
|
1583
1616
|
const gramCount = new Map();
|
|
1584
1617
|
let totalGrams = 0;
|
|
1585
|
-
for (let i = 0; i
|
|
1586
|
-
const gram =
|
|
1587
|
-
// 跳过含空白的 gram(normalize 已把标点换成空格,避免跨标点短语虚高)
|
|
1588
|
-
if (gram.includes(" ") || gram.includes("\n") || gram.includes("\t")) continue;
|
|
1618
|
+
for (let i = 0; i < words.length - 1; i++) {
|
|
1619
|
+
const gram = words[i] + " " + words[i + 1];
|
|
1589
1620
|
let v = gramCount.get(gram) ?? 0;
|
|
1590
1621
|
gramCount.set(gram, ++v);
|
|
1591
1622
|
totalGrams++;
|
|
1592
1623
|
}
|
|
1593
1624
|
if (totalGrams === 0) return null;
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1625
|
+
return pickMaxFromCountMap(gramCount, totalGrams);
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
/**
|
|
1629
|
+
* 修复②:尾窗 n-gram 频率统计(双轨)。
|
|
1630
|
+
* 输入 normText(已过 normalizeForNGram),同时产出两套指纹:
|
|
1631
|
+
* - charFp:字符级 n-gram(原实现,保留中文/混合文本检测能力),gram 为无空白字符窗;
|
|
1632
|
+
* - wordFp:英文词级 2-gram(相邻两个英文词为一个 gram);
|
|
1633
|
+
* 以及英文主导判定(英文 token 数 / 全部 token 数 > 0.5),供 detectNGramLoop
|
|
1634
|
+
* 分支互斥选用。判定逻辑不在本函数内做——detectNGramLoop 是唯一决策入口。
|
|
1635
|
+
* @param {string} normText 已过 normalizeForNGram
|
|
1636
|
+
* @param {number} nGramSize 字符级短语粒度
|
|
1637
|
+
* @returns {{charFp:object|null, wordFp:object|null, englishTokenCount:number, totalTokenCount:number, englishDominant:boolean}|null}
|
|
1638
|
+
*/
|
|
1639
|
+
function computeNGramFingerprint(normText, nGramSize) {
|
|
1640
|
+
if (typeof normText !== "string" || normText.length < nGramSize * 4) return null;
|
|
1641
|
+
|
|
1642
|
+
// 轨 1:字符级 n-gram(原逻辑不变)
|
|
1643
|
+
const charGramCount = new Map();
|
|
1644
|
+
let charTotalGrams = 0;
|
|
1645
|
+
for (let i = 0; i <= normText.length - nGramSize; i++) {
|
|
1646
|
+
const gram = normText.slice(i, i + nGramSize);
|
|
1647
|
+
// 跳过含空白的 gram(normalize 已把标点换成空格,避免跨标点短语虚高)
|
|
1648
|
+
if (gram.includes(" ") || gram.includes("\n") || gram.includes("\t")) continue;
|
|
1649
|
+
let v = charGramCount.get(gram) ?? 0;
|
|
1650
|
+
charGramCount.set(gram, ++v);
|
|
1651
|
+
charTotalGrams++;
|
|
1598
1652
|
}
|
|
1599
|
-
|
|
1653
|
+
const charFp = charTotalGrams === 0 ? null : pickMaxFromCountMap(charGramCount, charTotalGrams);
|
|
1654
|
+
|
|
1655
|
+
// 轨 2:英文词级 2-gram——[a-z]+ 抽取英文词序列,相邻两词为一个 gram。
|
|
1656
|
+
const words = normText.match(/[a-z]+/g) || [];
|
|
1657
|
+
const wordFp = words.length >= 2 ? computeWordBigramFingerprint(words) : null;
|
|
1658
|
+
|
|
1659
|
+
// 英文主导判定:英文 token 数 / 全部 token 数 > 0.5。
|
|
1660
|
+
// 全部 token ≈ 英文词数 + CJK 单字数(其他符号已被 normalize 归并为空白)。
|
|
1661
|
+
const englishTokenCount = words.length;
|
|
1662
|
+
const cjkCount = (normText.match(/[\u4e00-\u9fff]/g) || []).length;
|
|
1663
|
+
const totalTokenCount = englishTokenCount + cjkCount;
|
|
1664
|
+
return {
|
|
1665
|
+
charFp,
|
|
1666
|
+
wordFp,
|
|
1667
|
+
englishTokenCount,
|
|
1668
|
+
totalTokenCount,
|
|
1669
|
+
englishDominant: totalTokenCount > 0 && englishTokenCount / totalTokenCount > 0.5
|
|
1670
|
+
};
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
/**
|
|
1674
|
+
* 修复②:按频次降序取第一个非停用词 gram(字符轨专用)。跳过命中停用词表的
|
|
1675
|
+
* gram;含停用词字符 ≥60% 的 gram 同样跳过(stopCharRatio 守卫——对中文单字
|
|
1676
|
+
* 停用词有效,gram 拆成字符逐个比对)。
|
|
1677
|
+
* @param {Map<string, number>} gramCount
|
|
1678
|
+
* @returns {{gram:string, count:number}|null}
|
|
1679
|
+
*/
|
|
1680
|
+
function pickHighestNonStopwordGram(gramCount) {
|
|
1681
|
+
const sorted = [...gramCount.entries()].sort((a, b) => b[1] - a[1]);
|
|
1682
|
+
for (const [gram, count] of sorted) {
|
|
1683
|
+
if (NGram_STOPWORDS.has(gram)) continue;
|
|
1684
|
+
// 停用词比例守卫:若 gram 中 ≥60% 字符在停用词表里,同样跳过
|
|
1685
|
+
const stopCharRatio = [...gram].filter((ch) => NGram_STOPWORDS.has(ch)).length / gram.length;
|
|
1686
|
+
if (stopCharRatio >= 0.6) continue;
|
|
1687
|
+
return { gram, count };
|
|
1688
|
+
}
|
|
1689
|
+
return null;
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
/**
|
|
1693
|
+
* 修复②:按频次降序取第一个非停用词 gram(英文词级 2-gram 专用)。
|
|
1694
|
+
* 词级 gram 形如 "settings path",停用过滤按「词」检查:两个英文词中任一个命中
|
|
1695
|
+
* 英文停用词表即跳过——"the settings" / "web fetch" 这类虚词+技术词/工具名搭配
|
|
1696
|
+
* 是英文技术文本的高频噪声,不是循环证据(stopCharRatio 按字符比对对英文整词
|
|
1697
|
+
* 无效,故词轨不能复用字符轨的守卫)。
|
|
1698
|
+
* @param {Map<string, number>} gramCount
|
|
1699
|
+
* @returns {{gram:string, count:number}|null}
|
|
1700
|
+
*/
|
|
1701
|
+
function pickHighestNonStopwordBigram(gramCount) {
|
|
1702
|
+
const sorted = [...gramCount.entries()].sort((a, b) => b[1] - a[1]);
|
|
1703
|
+
for (const [gram, count] of sorted) {
|
|
1704
|
+
const words = gram.split(" ");
|
|
1705
|
+
if (words.length !== 2) continue;
|
|
1706
|
+
if (words.some((w) => NGram_STOPWORDS.has(w))) continue;
|
|
1707
|
+
return { gram, count };
|
|
1708
|
+
}
|
|
1709
|
+
return null;
|
|
1600
1710
|
}
|
|
1601
1711
|
|
|
1602
1712
|
/**
|
|
1603
1713
|
* 修复②:判定是否为"语义漂移型循环"——跳过停用词 gram 后取最高频非停用 gram,
|
|
1604
1714
|
* 其出现次数 ≥ NGram_MIN_COUNT 且覆盖占尾窗比例 ≥ NGram_COVERAGE_RATIO。
|
|
1715
|
+
* 双轨分支(互斥,不许混合):
|
|
1716
|
+
* - 英文主导(英文 token 数 > 全部 token 数的一半):只走英文词级 2-gram 路径,
|
|
1717
|
+
* 绝不回退字符 5-gram——否则 "settings" 的任意 5 字符子串("setti" 等)会被
|
|
1718
|
+
* 独立计数而误报。词级覆盖率 = count × 2 / 英文 token 总数。
|
|
1719
|
+
* - 非英文主导(中文/混合):保持原字符 n-gram 路径,覆盖率 = count × n / 尾窗字符数。
|
|
1605
1720
|
* 与 findRepeatingTail 并行,不破坏原逻辑。
|
|
1606
1721
|
* @param {string} fullVisibleText
|
|
1607
1722
|
* @returns {{maxGram:string,count:number,coverage:number}|null}
|
|
@@ -1613,23 +1728,23 @@ function detectNGramLoop(fullVisibleText) {
|
|
|
1613
1728
|
const fp = computeNGramFingerprint(norm, NGram_PHRASE_MIN);
|
|
1614
1729
|
if (!fp) return null;
|
|
1615
1730
|
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
if (stopCharRatio >= 0.6) continue;
|
|
1625
|
-
chosenGram = gram;
|
|
1626
|
-
chosenCount = count;
|
|
1627
|
-
break;
|
|
1731
|
+
if (fp.englishDominant) {
|
|
1732
|
+
// 英文主导:只走英文词级 2-gram,禁止回退字符 5-gram
|
|
1733
|
+
if (!fp.wordFp) return null;
|
|
1734
|
+
const chosen = pickHighestNonStopwordBigram(fp.wordFp.gramCount);
|
|
1735
|
+
if (!chosen || chosen.count < NGram_MIN_COUNT) return null;
|
|
1736
|
+
const coverage = chosen.count * 2 / fp.englishTokenCount;
|
|
1737
|
+
if (coverage < NGram_COVERAGE_RATIO) return null;
|
|
1738
|
+
return { maxGram: chosen.gram, count: chosen.count, coverage };
|
|
1628
1739
|
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1740
|
+
|
|
1741
|
+
// 非英文主导(中文/混合):保持原字符 n-gram 路径
|
|
1742
|
+
if (!fp.charFp) return null;
|
|
1743
|
+
const chosen = pickHighestNonStopwordGram(fp.charFp.gramCount);
|
|
1744
|
+
if (!chosen || chosen.count < NGram_MIN_COUNT) return null;
|
|
1745
|
+
const coverage = chosen.count * NGram_PHRASE_MIN / tail.length;
|
|
1631
1746
|
if (coverage < NGram_COVERAGE_RATIO) return null;
|
|
1632
|
-
return { maxGram:
|
|
1747
|
+
return { maxGram: chosen.gram, count: chosen.count, coverage };
|
|
1633
1748
|
}
|
|
1634
1749
|
|
|
1635
1750
|
/** 修复②:n-gram 锚点。 */
|
|
@@ -2870,8 +2985,9 @@ const HARVEST_ANALYZE_SYSTEM_PROMPT = [
|
|
|
2870
2985
|
const DEFAULT_SETTINGS = { // Master switches
|
|
2871
2986
|
enableSoftCut: true,
|
|
2872
2987
|
// 外部插件(如 dsh-derive-watcher 二级语义停滞干预)经 cotAnchor 服务请求
|
|
2873
|
-
//
|
|
2874
|
-
|
|
2988
|
+
// 软切的总开关。发布默认 true:让 cot-anchor + derive-watcher 三插件联动
|
|
2989
|
+
// 开箱即用;外部请求只占用启发式额度,不会触发硬中止。
|
|
2990
|
+
enableExternalSoftCut: true,
|
|
2875
2991
|
// Per-detector switches
|
|
2876
2992
|
enablePseudoTool: true,
|
|
2877
2993
|
enableRepeat: true,
|
|
@@ -2906,6 +3022,11 @@ const DEFAULT_SETTINGS = { // Master switches
|
|
|
2906
3022
|
repeatMinCountShort: 5,
|
|
2907
3023
|
repeatUltraShortMinCount: 30,
|
|
2908
3024
|
repeatMinTextChars: 800,
|
|
3025
|
+
// NGram 语义指纹(修复②)参数:默认值与模块级 let 绑定字面量一致,
|
|
3026
|
+
// applyRuntimeSettings 写回对应绑定;schema 范围(见 SETTINGS_SCHEMA)覆盖默认值。
|
|
3027
|
+
ngramPhraseMin: 5,
|
|
3028
|
+
ngramMinCount: 5,
|
|
3029
|
+
ngramCoverageRatio: 0.05,
|
|
2909
3030
|
// Churn detector
|
|
2910
3031
|
churnWindowChars: 3000,
|
|
2911
3032
|
churnMinHits: 18,
|
|
@@ -2987,14 +3108,14 @@ const SETTINGS_SCHEMA = [
|
|
|
2987
3108
|
{ key: "enableSoftCut", label: "允许生成中途打断(软切断)", type: "boolean", group: "总开关",
|
|
2988
3109
|
hint: "关闭后只保留工具边界的注入,不再在生成过程中切断。" },
|
|
2989
3110
|
{ key: "enableExternalSoftCut", label: "允许外部插件请求软切", type: "boolean", group: "总开关",
|
|
2990
|
-
hint: "开启后允许其他插件(如 dsh-derive-watcher
|
|
3111
|
+
hint: "开启后允许其他插件(如 dsh-derive-watcher 检测到二级语义停滞时)请求本插件在生成边界软切。外部请求只占用启发式额度,不会触发硬中止;默认开启(开箱即用)。" },
|
|
2991
3112
|
|
|
2992
3113
|
{ key: "enablePseudoTool", label: "识别伪工具调用", type: "boolean", group: "打断判定",
|
|
2993
3114
|
hint: "模型把工具调用写成文本(如 <seed:tool_call>)时打断并纠正格式。" },
|
|
2994
|
-
{ key: "enableRepeat", label: "
|
|
2995
|
-
hint: "
|
|
3115
|
+
{ key: "enableRepeat", label: "识别重复/语义循环(n-gram 指纹)", type: "boolean", group: "打断判定",
|
|
3116
|
+
hint: "同一段内容被反复吐出,或尾窗内高频短语反复出现(注入提示「语义循环(n-gram 指纹)」)时打断,并裁掉落盘的重复部分。" },
|
|
2996
3117
|
{ key: "enableChurn", label: "识别语义空转", type: "boolean", group: "打断判定",
|
|
2997
|
-
hint: "措辞不同但反复\"重新分析\"
|
|
3118
|
+
hint: "措辞不同但反复\"重新分析\"时打断(注入提示「原地空转」);含只说不做的\"行动提议空转\"(注入提示「行动提议空转」)。属启发式判定,遇到未闭合代码块会自动让路。" },
|
|
2998
3119
|
{ key: "enableTransition", label: "识别转折句", type: "boolean", group: "打断判定",
|
|
2999
3120
|
hint: "\"接下来我要……\"这类转折句出现时打断,先注入结论锚点。" },
|
|
3000
3121
|
{ key: "enableNumberRunaway", label: "识别数字递增流退化", type: "boolean", group: "打断判定",
|
|
@@ -3034,6 +3155,12 @@ const SETTINGS_SCHEMA = [
|
|
|
3034
3155
|
hint: "只在文本尾部这段长度内做周期性预筛(性能保护)。" },
|
|
3035
3156
|
{ key: "repeatProbeChars", advanced: true, label: "周期探针长度", type: "number", min: 16, max: 2000, group: "重复循环参数" },
|
|
3036
3157
|
{ key: "repeatMinTextChars", advanced: true, label: "启用最小文本长度", type: "number", min: 500, max: 50000, group: "重复循环参数" },
|
|
3158
|
+
{ key: "ngramPhraseMin", advanced: true, label: "n-gram 短语最小长度(字符)", type: "number", min: 3, max: 20, group: "重复循环参数",
|
|
3159
|
+
hint: "字符级 n-gram 的滑窗粒度(中文路径)。默认 5;调高要求更长的短语才计数(更保守)。英文路径固定按相邻 2 词,不受此项影响。" },
|
|
3160
|
+
{ key: "ngramMinCount", advanced: true, label: "n-gram 最高频短语最小出现次数", type: "number", min: 2, max: 50, group: "重复循环参数",
|
|
3161
|
+
hint: "最高频短语至少出现这么多次才判定循环;调低更激进、调高更保守。" },
|
|
3162
|
+
{ key: "ngramCoverageRatio", advanced: true, label: "n-gram 短语覆盖占比下限", type: "number", min: 0.01, max: 0.5, group: "重复循环参数",
|
|
3163
|
+
hint: "最高频短语占用尾窗的最小比例,0.05=5%;调高则更保守。" },
|
|
3037
3164
|
|
|
3038
3165
|
{ key: "churnMinHits", advanced: true, label: "空转词命中阈值", type: "number", min: 5, max: 100, group: "语义空转参数",
|
|
3039
3166
|
hint: "窗口内出现这么多次\"让我想想/重新分析\"类用语即判定空转;调低则更激进。" },
|
|
@@ -3046,7 +3173,7 @@ const SETTINGS_SCHEMA = [
|
|
|
3046
3173
|
hint: "转折词(如\"我先\")之后至少输出这么多字才允许切断,防止在句子刚开头就切断思考、截出半句结论。" },
|
|
3047
3174
|
{ key: "softCutGapThreshold", advanced: true, label: "结论-转折最大间距", type: "number", min: 0, max: 400, group: "转折句参数",
|
|
3048
3175
|
hint: "Tier-1 结论标记(如\"所以\")与后续转折宣告(如\"接下来\")之间允许的最大字符距离。超过则认为是子阶段小结论而非阶段边界,拒绝软切。默认 80。" },
|
|
3049
|
-
{ key: "pseudoToolScanTail", advanced: true, label: "伪调用扫描窗口", type: "number", min: 200, max: 20000, group: "
|
|
3176
|
+
{ key: "pseudoToolScanTail", advanced: true, label: "伪调用扫描窗口", type: "number", min: 200, max: 20000, group: "伪工具调用参数" },
|
|
3050
3177
|
|
|
3051
3178
|
{ key: "enableLlmRefine", advanced: true, label: "启用 LLM 提炼结论", type: "boolean", group: "LLM 提炼",
|
|
3052
3179
|
hint: "用一次小模型调用把整段思考压成摘要式结论(比摘句更准)。开启后每个助手回合多一次小调用;失败会自动退回打分提取。provider/model 留空则沿用会话当前模型。" },
|
|
@@ -3169,6 +3296,10 @@ function applyRuntimeSettings(raw) {
|
|
|
3169
3296
|
REPEAT_MIN_COUNT_SHORT = merged.repeatMinCountShort;
|
|
3170
3297
|
REPEAT_ULTRA_SHORT_MIN_COUNT = merged.repeatUltraShortMinCount;
|
|
3171
3298
|
REPEAT_MIN_TEXT_CHARS = merged.repeatMinTextChars;
|
|
3299
|
+
// NGram 语义指纹(修复②)三参数发布(此前为 const 硬编码,设置不可调)
|
|
3300
|
+
NGram_PHRASE_MIN = merged.ngramPhraseMin;
|
|
3301
|
+
NGram_MIN_COUNT = merged.ngramMinCount;
|
|
3302
|
+
NGram_COVERAGE_RATIO = merged.ngramCoverageRatio;
|
|
3172
3303
|
CHURN_WINDOW_CHARS = merged.churnWindowChars;
|
|
3173
3304
|
CHURN_MIN_HITS = merged.churnMinHits;
|
|
3174
3305
|
CHURN_MIN_TEXT_CHARS = merged.churnMinTextChars;
|
|
@@ -3266,7 +3397,7 @@ function requestExternalSoftCut(payload) {
|
|
|
3266
3397
|
if (kernelSoftCutProbe === CAPABILITY_ABSENT) {
|
|
3267
3398
|
return { accepted: false, reason: "soft-cut-capability-absent" };
|
|
3268
3399
|
}
|
|
3269
|
-
//
|
|
3400
|
+
// 设置门:外部干预属跨插件动作,按开关放行;发布默认 true(开箱即用)。
|
|
3270
3401
|
if (settings.enableExternalSoftCut !== true) {
|
|
3271
3402
|
return { accepted: false, reason: "disabled" };
|
|
3272
3403
|
}
|
package/package.json
CHANGED
|
@@ -1,51 +1,53 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-cot-anchor",
|
|
3
|
-
"version": "0.
|
|
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
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-cot-anchor",
|
|
3
|
+
"version": "0.4.0",
|
|
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
|
+
|