/**
 * 意图信号提取器 — 从用户意图文本中提取结构化信号。
 *
 * 信号类型：动作词、产物词、否定词、约束词、上下文引用。
 * 所有别名结构化定义，支持中文/英文别名和乱序表达。
 */
export const ACTION_ALIASES = [
    {
        category: "extract",
        patterns: [
            /提取/, /抽取/, /抓取/, /读取(?=.*(?:生成|输出|提取|原型|接口|说明))/, /解析/, /扫描/,
            /识别/, /反推/, /还原/, /扒/, /弄出来/, /整理出来/,
            /extract/i, /parse/i, /read(?=.*(?:from|out|extract))/i, /scan/i,
        ],
    },
    {
        category: "generate",
        patterns: [
            /生成/, /输出/, /写一份/, /形成/, /制作/, /做成/, /整理成/, /梳理.*(?:成|为|出)/,
            /导出/, /输出为/, /保存为/, /产出到/, /做一份/, /生成一份/,
            /做成/, /拆(?:成|分为)/,
            /generate/i, /create/i, /produce/i,
        ],
    },
    {
        category: "code_change",
        patterns: [
            /修复/, /fix/i, /bug/i, /错误修复/, /异常处理/,
            /报错.*(?:修复|解决|处理)/,
            /新增(?:功能|接口|页面|模块|字段|按钮|服务|路由|组件|一个|一个后台)/,
            /加(?:一个|个|上|载)\s*(?:接口|功能|模块|页面|字段|按钮|服务|路由|组件)/,
            /加(?:一个|个)?\s*(?:导出|查询|校验|权限|配置|逻辑|规则|支持|特性)/,
            /新增用户/, /新增一个/,
            /重构/, /优化结构/, /实现/, /开发/, /补(?:单元)?测试/, /写测试/,
            /删除/, /添加/, /修改/, /变更/, /移除/, /替换/,
            /脚手架/, /scaffold/i, /新建模块/,
            /implement/i, /refactor/i, /modify/i, /delete/i, /add/i,
        ],
    },
    {
        category: "analyze",
        patterns: [
            /分析/, /评估/, /梳理/, /看看/, /看下/,
            /analyze/i, /assess/i, /evaluate/i,
        ],
    },
    {
        category: "review",
        patterns: [
            /审查/, /\breview\b/i, /检查代码/, /代码质量/,
        ],
    },
    {
        category: "acceptance",
        patterns: [
            /(?:检查|确认|验证).{0,12}(?:就绪|完成|通过|状态|条件|可用)/,
            /(?:是否|有没有).{0,12}(?:就绪|完成|通过|满足|可用)/,
            /(?:验收|acceptance|ready|readiness)/i,
        ],
    },
    {
        category: "plan",
        patterns: [
            /拆(?:成|分为)\s*(?:任务|阶段|步骤|模块)/,
            /(?:实施|开发|发布)\s*计划/,
            /排期/, /里程碑/,
        ],
    },
    {
        category: "operate",
        patterns: [
            /运行测试/, /执行构建/, /\bbuild\b/i, /\bci\b/i, /\bcd\b/i,
            /跑测试/,
            /准备.*(?:发布前|检查清单)/,
            /发布前(?:检查|准备)/,
        ],
    },
];
export const ARTIFACT_ALIASES = [
    { kind: "prototype_spec", patterns: [/原型(?:说明|规约|描述|文档|报告|spec)/, /prototype\s*spec/i, /prototype\s*doc/i, /页面说明/, /页面流程/, /交互说明/], defaultName: "原型说明", template: "原型说明模版.md" },
    { kind: "api_spec", patterns: [/接口(?:设计|清单|文档|spec)/], defaultName: "接口设计", template: "API接口规格文档模版.md" },
    { kind: "design_doc", patterns: [/(?:架构设计|详细设计)/], defaultName: "设计文档", template: "架构设计模版.md" },
    { kind: "test_plan", patterns: [/测试计划/], defaultName: "测试计划", template: "测试计划模版.md" },
    { kind: "migration_plan", patterns: [/迁移(?:方案|评估|计划)/], defaultName: "迁移方案", template: "迁移评估模版.md" },
    { kind: "review_report", patterns: [/审查报告|代码审查/], defaultName: "审查报告", template: "代码审查报告模版.md" },
    { kind: "task_breakdown", patterns: [/(?:任务拆解|开发任务|拆.*任务)/], defaultName: "任务拆解", template: "切片计划模版.md" },
    { kind: "root_cause", patterns: [/根因(?:分析|报告)/], defaultName: "根因分析", template: "Bug分析模版.md" },
    { kind: "incident_review", patterns: [/故障复盘|故障分析|复盘报告/], defaultName: "故障复盘", template: "故障复盘模版.md" },
    { kind: "acceptance_checklist", patterns: [/验收(?:清单|标准|checklist)/], defaultName: "验收清单", template: "通用质量验收清单.md" },
    { kind: "interaction_spec", patterns: [/交互(?:规约|规范|说明)/], defaultName: "交互规约", template: "原型说明模版.md" },
    { kind: "domain_model", patterns: [/领域(?:模型|图)/], defaultName: "领域模型", template: "OOD设计摘要模版.md" },
];
// ── 跳过模式 ──
export const SKIP_RULES = [
    { pattern: /^(你好|hi|hello|hey|嗨|早上好|下午好|晚上好)[\s!！.。]*$/i, reason: "greeting" },
    { pattern: /^(今天|现在|几号|什么时候|什么时候了)/, reason: "casual_question" },
    { pattern: /不用\s*(soloForge|solo\s*forge)/i, reason: "explicit_skip" },
    { pattern: /直接(告诉|说|回答|给)/, reason: "explicit_skip" },
];
export const GENERAL_QA_RULES = [
    /(?:什么(?:是|叫|意思))\s*(?:REST|API|DTO|DAO|SOA|DDD|TDD|BDD|CI\/CD|SQL|NoSQL|TypeScript|JavaScript|Java|Python|Go|Docker|K8s|Kubernetes|React|Vue|Spring|Node|Nginx|Redis|MySQL|MongoDB|GraphQL|gRPC|WebSocket|OAuth|JWT|SOLID|DRY|KISS|YAGNI)/i,
    /^(?:TypeScript|Java|Python|Go|React|Vue|Spring)\s*(?:union type|泛型|接口|类|装饰器|闭包|协程|通道|组件|生命周期|状态管理|中间件)/i,
];
export const PURE_EXPLAIN_RULES = [
    /(?:解释|说明)(?:一下|下)?\s*(?:这个|这|这模块|这代码|这段|这个模块)\s*(?:怎么|如何|是什么|是什么意思|的|了)/,
    /^(?:解释|说明)(?:一下|下)?\s/,
    /^(?:这个|这)\s*(?:是|什么)/,
];
// ── 否定/约束模式 ──
const NEGATION_RULES = [
    { pattern: /不要(?:修改|改|变更|动)/, negates: "mutation" },
    { pattern: /不(?:需要|要)?(?:修改|改|变更|动)代码/, negates: "mutation" },
    { pattern: /千万?不要(?:动|修改|改)/, negates: "mutation" },
    { pattern: /只是?(?:检查|确认|验证|看看)/, negates: "mutation" },
    { pattern: /只(?:读|看|检查|验证)/, negates: "mutation" },
    { pattern: /不(?:跑|执行?|走)(?:全流程|流水线|完整流程)/, negates: "pipeline" },
];
const CONSTRAINT_RULES = [
    { pattern: /不要?(?:修改|改|变更|动)(?:代码|源码|项目)/, type: "no_mutation" },
    { pattern: /(?:检查|确认|验证).{0,12}(?:就绪|完成|通过|状态|条件|可用)/, type: "no_mutation" },
    { pattern: /只(?:需要|需|要)?(?:提取|读取|分析|看)/, type: "scope_limit" },
];
// ── 源材料信号 ──
export const SOURCE_MATERIAL_RULES = [
    { pattern: /\.(zip|tar|gz|rar|7z|jar|war)/i, kind: "archive" },
    { pattern: /源码包|压缩包|zip包|包文件/, kind: "archive" },
    { pattern: /从\s*(?:源码包|压缩包|源码|代码包)/, kind: "archive" },
    { pattern: /(?:logs?\/|\.log|日志(?:文件|目录|路径))/i, kind: "log" },
    { pattern: /从报错日志/, kind: "log" },
];
export const EXTRACTION_STRUCTURE = [
    /从\s*.*(?:提取|抽取)/,
    /从\s*.*(?:生成|输出)/,
    /读取\s*.*生成/,
    /抓取.*(?:源码|源代码|原型)/,
];
export const FULL_PIPELINE_RULES = [
    /从.*(?:到|至).*(?:交付|完成|上线|部署)/,
    /全流程/, /端到端/, /完整流水/, /整套完成/,
    /从设计到交付/, /从头到尾/,
];
// ── 工作流意图规则 ──
const WORKFLOW_INTENT_RULES = [
    {
        intent: "architecture_design",
        patterns: [
            /架构设计/,
            /进行架构/,
            /架构.*设计/,
            /根据.*(?:原型说明|需求文档|需求).*架构/,
        ],
    },
    {
        intent: "existing_system_gap_analysis",
        patterns: [
            /在(?:现有|已有)项目(?:中|里)?(?:开发|实现|新增)/,
            /现有系统.*(?:分析|差距|gap)/,
            /gap\s*analysis/i,
            /现有项目.*(?:新需求|新功能|新特性)/,
        ],
    },
    {
        intent: "test_first_coding",
        patterns: [
            /实现(?:某|一个|新).*需求/,
            /实现.*(?:新需求|新功能|新特性)/,
            /开发.*(?:新需求|新功能|新特性)/,
            /编码.*(?:实现|开发)/,
        ],
    },
    {
        intent: "local_browser_acceptance",
        patterns: [
            /本地.*(?:浏览器|browser).*验收/,
            /(?:浏览器|browser).*验收/,
            /docker.*(?:验收|测试|验证)/,
            /本地.*(?:docker|容器).*验收/,
            /执行本地.*验收/,
        ],
    },
];
// ── 主提取函数 ──
export function extractSignals(intent) {
    const actions = [];
    const artifacts = [];
    const negations = [];
    const constraints = [];
    const sourceMaterialKinds = new Set();
    let hasExtractionStructure = false;
    let hasFullPipeline = false;
    let isSkip = false;
    let skipReason;
    let isGeneralQa = false;
    let isPureExplain = false;
    let grayZone;
    // 跳过检测
    for (const rule of SKIP_RULES) {
        if (rule.pattern.test(intent)) {
            isSkip = true;
            skipReason = rule.reason;
        }
    }
    // 通用问答检测
    isGeneralQa = GENERAL_QA_RULES.some((r) => r.test(intent));
    // 纯解释检测
    isPureExplain = PURE_EXPLAIN_RULES.some((r) => r.test(intent));
    // 动作提取
    for (const alias of ACTION_ALIASES) {
        for (const pat of alias.patterns) {
            const m = intent.match(pat);
            if (m) {
                actions.push({
                    category: alias.category,
                    match: m[0],
                    index: m.index ?? 0,
                    confidence: 0.9,
                });
            }
        }
    }
    // 产物提取
    for (const alias of ARTIFACT_ALIASES) {
        for (const pat of alias.patterns) {
            const m = intent.match(pat);
            if (m) {
                artifacts.push({
                    kind: alias.kind,
                    match: m[0],
                    index: m.index ?? 0,
                    confidence: 0.95,
                });
            }
        }
    }
    // 否定信号
    for (const rule of NEGATION_RULES) {
        const m = intent.match(rule.pattern);
        if (m) {
            negations.push({ match: m[0], index: m.index ?? 0, negates: rule.negates });
        }
    }
    // 约束信号
    for (const rule of CONSTRAINT_RULES) {
        const m = intent.match(rule.pattern);
        if (m) {
            constraints.push({ match: m[0], index: m.index ?? 0, type: rule.type });
        }
    }
    // 源材料类型
    for (const rule of SOURCE_MATERIAL_RULES) {
        if (rule.pattern.test(intent)) {
            sourceMaterialKinds.add(rule.kind);
        }
    }
    // 提取结构
    hasExtractionStructure = EXTRACTION_STRUCTURE.some((r) => r.test(intent));
    // 全流程
    hasFullPipeline = FULL_PIPELINE_RULES.some((r) => r.test(intent));
    // 灰区
    if (/整理(?:一下|下)?/.test(intent))
        grayZone = "organize";
    if (/看看|看下/.test(intent))
        grayZone = "look";
    // 工作流意图检测
    let workflowIntent = undefined;
    for (const rule of WORKFLOW_INTENT_RULES) {
        if (rule.patterns.some((p) => p.test(intent))) {
            workflowIntent = rule.intent;
            break;
        }
    }
    return {
        actions,
        artifacts,
        negations,
        constraints,
        source_material_kinds: [...sourceMaterialKinds],
        has_extraction_structure: hasExtractionStructure,
        has_full_pipeline: hasFullPipeline,
        is_skip: isSkip,
        skip_reason: skipReason,
        is_general_qa: isGeneralQa,
        is_pure_explain: isPureExplain,
        gray_zone: grayZone,
        workflow_intent: workflowIntent,
    };
}
/** 产物别名表查找（供路由器使用） */
export function findArtifactAlias(kind) {
    return ARTIFACT_ALIASES.find((a) => a.kind === kind);
}
/** 获取所有产物别名表（供 detectArtifact 使用） */
export function getArtifactAliases() {
    return ARTIFACT_ALIASES;
}
//# sourceMappingURL=intent_signal_extractor.js.map