.claude/skills/path-alias-validator/SKILL.md
路径别名系统检查与修复
npx skillsauth add shenjingnan/xiaozhi-client path-alias-validatorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
我是路径别名系统检查与修复技能,专门针对 xiaozhi-client 项目的路径别名系统进行检查、验证和优化,同时遵循务实开发理念。
核心能力:检测项目中相对路径的使用情况,并提供别名替换建议。
../ 格式的导入语句./ 格式的导入语句// ✅ 推荐的别名使用
import { LightService } from "@/services";
import type { HassState } from "@/types";
import { formatDate } from "@/utils";
// ❌ 需要修复的相对路径
import { LightService } from "../services";
import type { HassState } from "../types";
import { formatDate } from "./utils";
检查项目配置文件中的路径别名设置是否正确和一致。
// xiaozhi-client 项目完整别名映射
{
"@/*": ["apps/backend/*"], // 后端根目录快速访问
"@cli/*": ["apps/backend/cli/*"], // CLI 相关代码
"@cli/commands/*": ["apps/backend/cli/commands/*"], // CLI 命令
"@cli/services/*": ["apps/backend/cli/services/*"], // CLI 服务
"@cli/utils/*": ["apps/backend/cli/utils/*"], // CLI 工具
"@cli/errors/*": ["apps/backend/cli/errors/*"], // CLI 错误处理
"@cli/interfaces/*": ["apps/backend/cli/interfaces/*"], // CLI 接口
"@handlers/*": ["apps/backend/handlers/*"], // 请求处理器
"@services/*": ["apps/backend/services/*"], // 业务服务
"@errors/*": ["apps/backend/errors/*"], // 错误定义
"@utils/*": ["apps/backend/utils/*"], // 工具函数
"@core/*": ["apps/backend/core/*"], // 核心 MCP 功能
"@transports/*": ["apps/backend/transports/*"], // 传输层适配器
"@adapters/*": ["apps/backend/adapters/*"], // 适配器模式
"@managers/*": ["apps/backend/managers/*"], // 管理器服务
"@types/*": ["apps/backend/types/*"] // 类型定义
}
为检测到的问题提供具体的修复建议和代码示例。
// ❌ 原始代码(相对路径)
import { UserService } from "../services/user";
import type { APIResponse } from "../types/api";
import { formatDate } from "./utils/date";
import { Command } from "./commands/help";
import { WebSocketAdapter } from "../transports/websocket";
import { ConnectionManager } from "../../managers/connection";
// ✅ 修复后(xiaozhi-client 别名)
import { UserService } from "@/services/user";
import type { APIResponse } from "@/types/api";
import { formatDate } from "@/utils/date";
import { Command } from "@cli/commands/help";
import { WebSocketAdapter } from "@transports/websocket";
import { ConnectionManager } from "@managers/connection";
请检查当前项目的路径别名使用情况,识别所有需要修复的相对路径。
请验证项目中所有配置文件的路径别名设置是否一致和正确。
请帮我修复检测到的路径别名问题,自动替换相对路径为 @/xxx 格式的别名。
请检查 apps/backend/services/ 目录下的所有文件,确保它们正确使用路径别名。
请检查 apps/backend/cli/ 目录下的所有文件,确保CLI命令正确使用 @cli/* 别名。
请检查 apps/backend/core/ 目录下的所有文件,确保核心MCP功能正确使用路径别名。
请检查 apps/backend/transports/ 目录下的所有文件,确保传输适配器使用 @transports/* 别名。
请检查 docs/ 目录下的所有 MDX 文件,确保文档中的代码示例使用正确的 xiaozhi-client 路径别名。
请批量修复文档中的路径别名问题,重点关注代码示例中的 import 语句。
请验证文档更新后的正确性,确保修复后的代码示例语法正确且符合项目规范。
以下情况下相对路径是可以接受的:
// light.test.ts 可以使用相对路径导入 light.ts
import { LightService } from "./light";
// 同一目录下的工具函数
import { helperFunction } from "./helpers";
// 运行时动态导入
const module = await import(`../modules/${moduleName}`);
文档中的代码示例有特殊的例外规则:
// 当文档需要解释相对路径概念时
import { utils } from "../shared/utils"; // 这是相对路径的示例
// 对比展示:相对路径 vs 别名路径
// 相对路径写法:
import { Service } from "./service";
// 别名路径写法:
import { Service } from "@/services/service";
// 展示其他项目或框架的代码示例
import { Component } from "../components/Button";
{
"paths": {
"./*": ["./src/*"] // 配置文件中的相对路径
}
}
可以作为 CI 流程的一部分,自动检查新代码是否遵循路径别名规范。
// 1. Node.js 内置模块
import { fs } from "node:fs";
import { path } from "node:path";
// 2. 外部依赖
import express from "express";
import { Command } from "commander";
// 3. xiaozhi-client 路径别名导入(按分组排序)
// 核心模块
import { UnifiedMCPServer } from "@core";
import type { MCPMessage } from "@types";
// 传输和适配器
import { WebSocketAdapter } from "@transports";
import { HTTPAdapter } from "@adapters";
// 管理器和服务
import { ConnectionManager } from "@managers";
import { ConfigService } from "@/services";
// CLI相关
import { StartCommand } from "@cli/commands";
import { Container } from "@cli";
// 工具和错误
import { formatConfig } from "@/utils";
import { ConfigError } from "@errors";
// 4. 相对路径(仅在必要时)
import { helperFunction } from "./helpers";
// ✅ 推荐
import type { HassState } from "@/types";
// ❌ 避免
import { HassState } from "@/types";
同一文件中对同一目录的模块使用一致的导入方式。
import type 语法通过这个技能的帮助,可以确保项目始终遵循路径别名最佳实践,提高代码质量和可维护性。
development
TypeScript严格模式检查
tools
Todo 管理技能,用于管理架构演进过程中的待办事项
testing
测试修复技能,用于分析和修复失败的测试用例
testing
测试创建技能,用于生成符合项目标准的测试用例