- VERSION file as authoritative version source - export.mjs reads VERSION with package.json fallback - bw-ota.ps1 DryRun mode for safe testing - auto-setup.ps1 bumped to v3.2.0 (Phase 8 OTA)
144 lines
6.2 KiB
JavaScript
144 lines
6.2 KiB
JavaScript
#!/usr/bin/env node
|
||
/**
|
||
* R84-R88 消歧规则补丁 — Bookworm 元词路由修复 (2026-04-25)
|
||
*
|
||
* 解决 04-24 路由日志暴露的 5 类误判:
|
||
* - "booworm路由和消歧模块技术梳理" → vue-expert (100%) 应 → self-auditor/explain
|
||
* - "bookworm系统记忆文件路径在哪里" → project-audit-expert 应 → developer-expert
|
||
* - "skill 矩阵...瘦身提质计划" → canary (100%) 应 → self-auditor
|
||
* - "bookworm 工作流文件全量梳理和体检" → project-audit-expert 应 → self-auditor
|
||
* - "冲刺 3...生产 hook" → api-integration-specialist 应 → full-stack-builder
|
||
*
|
||
* 设计要点:
|
||
* - 所有规则锚定 "bookworm/booworm" 品牌词,不会误伤通用场景
|
||
* - R84 覆盖路由/消歧/钩子/管线/注入器等系统内部技术词
|
||
* - R85 处理 skill 矩阵/瘦身/提质场景
|
||
* - R86 修复"梳理/全量梳理"被 project-audit-expert 抢的问题
|
||
* - R87 处理纯查询性 (路径在哪里/是什么/如何) → developer-expert
|
||
* - R88 通用"提质"短语 penalty canary
|
||
*
|
||
* 幂等: 若 R84 已存在则跳过整个补丁。
|
||
* 原子: tmp + rename。
|
||
* 备份: .bak.r84-r88-bookworm-meta.<ISO>
|
||
*/
|
||
'use strict';
|
||
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
|
||
const TARGET = path.join(__dirname, '..', 'disambiguation-rules.json');
|
||
|
||
const NEW_RULES = [
|
||
{
|
||
id: 'R84',
|
||
note: 'Bookworm 系统元词查询 (路由/消歧/钩子/管线/注入器/分类器/引擎/遥测) → self-auditor',
|
||
trigger: '(?:bookworm|booworm).{0,20}(?:路由|消歧|钩子|hook|管线|注入器|分类器|引擎|遥测|盲点|融合权重|意图分类|消歧规则|路由引擎|权重学习器|状态文件|state\\s*file|追踪|trace|telemetry)|(?:路由|消歧|钩子).{0,10}(?:bookworm|booworm)',
|
||
boost: 'self-auditor',
|
||
agent: 'self-auditor',
|
||
penalty: ['vue-expert', 'angular-architect', 'api-integration-specialist', 'workflow-automation-expert'],
|
||
weight: 0.55,
|
||
description: 'Bookworm 系统内部技术词锚定 self-auditor,penalty vue-expert 防 vue-router 误触',
|
||
},
|
||
{
|
||
id: 'R85',
|
||
note: 'Bookworm skill 矩阵/瘦身/提质/裁剪/精简 → self-auditor',
|
||
trigger: '(?:bookworm|booworm).{0,15}(?:skill\\s*矩阵|skill\\s*列表|瘦身|提质|裁剪|精简|剪枝|净减|淘汰)|(?:skill\\s*矩阵|skill\\s*瘦身|skill\\s*提质|skill\\s*精简|0\\s*调用\\s*skill)',
|
||
boost: 'self-auditor',
|
||
agent: 'self-auditor',
|
||
penalty: ['canary', 'review', 'reviewer-expert', 'browse'],
|
||
weight: 0.55,
|
||
description: 'skill 矩阵分析/瘦身决策 → self-auditor,penalty canary 防"提质"误触',
|
||
},
|
||
{
|
||
id: 'R86',
|
||
note: 'Bookworm 系统梳理/全量梳理/工作流梳理 → self-auditor',
|
||
trigger: '(?:bookworm|booworm).{0,15}(?:全量梳理|工作流梳理|系统梳理|文件梳理|模块梳理|架构梳理|hook\\s*梳理|技术梳理)',
|
||
boost: 'self-auditor',
|
||
agent: 'self-auditor',
|
||
penalty: ['project-audit-expert', 'reviewer-expert', 'review'],
|
||
weight: 0.55,
|
||
description: '"梳理"短语 → self-auditor,penalty project-audit (业务化解读)',
|
||
},
|
||
{
|
||
id: 'R87',
|
||
note: 'Bookworm 查询性问题 (路径在哪里/是什么/如何配置) → developer-expert (explain)',
|
||
trigger: '(?:bookworm|booworm).{0,30}(?:在哪|哪里|是什么|什么是|怎么用|如何配置|如何使用|怎么看|怎么找|路径|位置)',
|
||
boost: 'developer-expert',
|
||
penalty: ['project-audit-expert', 'self-auditor', 'reviewer-expert'],
|
||
weight: 0.45,
|
||
description: '查询性问题走 explain 路径,penalty 重型审计 agent',
|
||
},
|
||
{
|
||
id: 'R88',
|
||
note: '通用 "提质/质量提升" 短语 penalty canary (canary 仅监控用途)',
|
||
trigger: '提质|质量提升|质量优化|品质提升',
|
||
penalty: ['canary'],
|
||
weight: 0.30,
|
||
description: '防 "提质" → canary monitoring 误触',
|
||
},
|
||
];
|
||
|
||
const NEW_CHANGELOG = [
|
||
'R84: 新增 — Bookworm 元词 (路由/消歧/钩子/管线/注入器/分类器/引擎/遥测) → self-auditor (penalty vue-expert)',
|
||
'R85: 新增 — skill 矩阵/瘦身/提质/裁剪 → self-auditor (penalty canary)',
|
||
'R86: 新增 — Bookworm 系统梳理/全量梳理 → self-auditor (penalty project-audit-expert)',
|
||
'R87: 新增 — Bookworm 查询性问题 (在哪/什么是/如何) → developer-expert',
|
||
'R88: 新增 — 通用"提质" penalty canary 防 monitoring 误触',
|
||
];
|
||
|
||
function main() {
|
||
const raw = fs.readFileSync(TARGET, 'utf8');
|
||
const json = JSON.parse(raw);
|
||
|
||
// 幂等检查
|
||
if (json.rules.some(r => r.id === 'R84')) {
|
||
console.log('[patch-r84-r88] R84 already present, skipping');
|
||
process.exit(0);
|
||
}
|
||
|
||
// 备份
|
||
const bakSuffix = '.bak.r84-r88-bookworm-meta.' + new Date().toISOString().replace(/[:.]/g, '-');
|
||
fs.writeFileSync(TARGET + bakSuffix, raw, 'utf8');
|
||
console.log('[patch-r84-r88] backup → ' + path.basename(TARGET + bakSuffix));
|
||
|
||
// 追加规则
|
||
json.rules.push(...NEW_RULES);
|
||
|
||
// 更新 _meta
|
||
if (!json._meta) json._meta = {};
|
||
const oldCount = json._meta.ruleCount || (json.rules.length - NEW_RULES.length);
|
||
json._meta.version = '1.5.0';
|
||
json._meta.ruleCount = json.rules.length;
|
||
json._meta.description = (json._meta.description || '') +
|
||
' | v1.5 (' + new Date().toISOString().slice(0, 10) + '): R84-R88 Bookworm 元词路由修复';
|
||
if (!Array.isArray(json._meta.changelog)) json._meta.changelog = [];
|
||
json._meta.changelog.push(...NEW_CHANGELOG);
|
||
|
||
// 原子写入
|
||
const tmpPath = TARGET + '.tmp.' + process.pid;
|
||
fs.writeFileSync(tmpPath, JSON.stringify(json, null, 2) + '\n', 'utf8');
|
||
fs.renameSync(tmpPath, TARGET);
|
||
|
||
console.log('[patch-r84-r88] applied: ' + oldCount + ' → ' + json.rules.length + ' rules');
|
||
|
||
// 清除 disambiguation-tree 缓存 (供 hooks 下次重建)
|
||
try {
|
||
const treePath = path.join(__dirname, '..', 'disambiguation-tree.js');
|
||
const tree = require(treePath);
|
||
if (tree.clearCache) {
|
||
tree.clearCache();
|
||
console.log('[patch-r84-r88] disambiguation-tree cache cleared');
|
||
}
|
||
} catch (e) {
|
||
console.log('[patch-r84-r88] cache clear skipped: ' + e.message);
|
||
}
|
||
}
|
||
|
||
if (require.main === module) {
|
||
try { main(); }
|
||
catch (e) {
|
||
console.error('[patch-r84-r88] FAIL:', e.message);
|
||
process.exit(1);
|
||
}
|
||
}
|