deslop(claude): role-router 简化 + regex 去重 + stderr 错误日志
按 critic + 3 reviewer agent 反馈:
- HIGH: bare catch {} 改 catch(e){console.error(...)} 暴露 bug
- MED: regex 去重复 (develop|develops? → develops?, fix|fixes → fixes?, requirement|requirements? → requirements?)
- MED: 4 处 {continue:true,suppressOutput:true} 抽 NOOP 常量
- MED: test JSON.stringify(.sort()) → 不可变的 sortKey helper
- skip: createHookOutput 抽 lib (违反"不改 OMC keyword-detector" 决策)
- skip: ROLES enum (3 值 over-engineering)
post-deslop 回归: 10/10 PASS
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -14,9 +14,11 @@
|
||||
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
export const DEV_RE = /(?:\b(?:dev|develop|develops?|implement|implements?|refactor|refactors?|fix|fixes|bug|bugs|hotfix|patch|patches|impl)\b|开发|实现|重构|修(?:复|bug)|写代码|编码|添加功能|新功能|改(?:bug|代码))/i;
|
||||
export const DEV_RE = /(?:\b(?:dev|develops?|implements?|refactors?|fixes?|bugs?|hotfix|patch(?:es)?|impl)\b|开发|实现|重构|修(?:复|bug)|写代码|编码|添加功能|新功能|改(?:bug|代码))/i;
|
||||
export const TEST_RE = /(?:\b(?:tests?|qa|unit\s?tests?|regression|e2e|integration\s?tests?|specs?)\b|测试|单测|单元测试|回归(?:测试)?|集成测试|端到端|质量保证|QA)/i;
|
||||
export const PM_RE = /(?:\b(?:pm|product|spec|requirement|roadmap|planning|backlog|user\s?story|prd)\b|产品(?:经理)?|需求|排期|规划|计划|调研|路线图|用户故事)/i;
|
||||
export const PM_RE = /(?:\b(?:pm|product|spec|requirements?|roadmap|planning|backlog|user\s?story|prd)\b|产品(?:经理)?|需求|排期|规划|计划|调研|路线图|用户故事)/i;
|
||||
|
||||
const NOOP = JSON.stringify({ continue: true, suppressOutput: true });
|
||||
|
||||
const ROLE_HINTS = {
|
||||
dev: `<role-routing role="dev">
|
||||
@@ -63,30 +65,21 @@ function readStdinSync() {
|
||||
function main() {
|
||||
try {
|
||||
const raw = readStdinSync();
|
||||
if (!raw) {
|
||||
console.log(JSON.stringify({ continue: true, suppressOutput: true }));
|
||||
return;
|
||||
}
|
||||
if (!raw) { console.log(NOOP); return; }
|
||||
const data = JSON.parse(raw);
|
||||
const prompt = data.prompt || data.user_prompt || '';
|
||||
if (!prompt) {
|
||||
console.log(JSON.stringify({ continue: true, suppressOutput: true }));
|
||||
return;
|
||||
}
|
||||
const roles = detectRoles(prompt);
|
||||
const ctx = buildContext(roles);
|
||||
if (!ctx) {
|
||||
console.log(JSON.stringify({ continue: true, suppressOutput: true }));
|
||||
return;
|
||||
}
|
||||
if (!prompt) { console.log(NOOP); return; }
|
||||
const ctx = buildContext(detectRoles(prompt));
|
||||
if (!ctx) { console.log(NOOP); return; }
|
||||
console.log(JSON.stringify({
|
||||
hookSpecificOutput: {
|
||||
hookEventName: 'UserPromptSubmit',
|
||||
additionalContext: ctx,
|
||||
},
|
||||
}));
|
||||
} catch {
|
||||
console.log(JSON.stringify({ continue: true, suppressOutput: true }));
|
||||
} catch (e) {
|
||||
console.error('[role-router]', e.message);
|
||||
console.log(NOOP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user