unohee/cxt
GitHub: unohee/cxt
一款面向代码上下文的工具套件,通过实体注册与坏味道检测为 Claude Code 提供智能上下文注入。
Stars: 0 | Forks: 0
# cxt
**C**ode e**X**ploration **T**oolkit — 扫描代码库中的实体(函数、类、类型、常量),检测不良代码气味,并向 Claude Code 会话注入上下文。
## 安装
```
npm install @intrect/cxt
# 或
npm install && npm run build && npm link
```
## 用法
```
# 扫描代码库 → 注册实体到本地 SQLite 注册表
cxt scan
cxt scan -v # verbose output
# 查询注册表
cxt check --stats # overall statistics
cxt check # per-file entity listing
cxt check --search
# full-text search (FTS5) cxt check --untested # entities without tests cxt check --high-risk # high-risk entities cxt check --deprecated # deprecated entities cxt check --tag# filter by tag cxt check --tree # directory tree view cxt check --ci # CI/CD mode (JSON output, exit 1 on critical) # 不良气味检测 cxt bs # scan for BS patterns cxt bs -v # verbose per-file output # 实体注解 cxt annotate --deprecate "reason" cxt annotate --tag "team=backend" cxt annotate --status experimental cxt annotate --risk high cxt annotate --warn "error/security: SQL injection risk" cxt annotate --note "refactor planned" # Claude Code 上下文注入(用于 SessionStart 钩子) cxt inject # 语言覆盖(默认:从 LANG 环境自动检测) cxt --lang en scan cxt --lang ko bs ``` ## 支持的语言 | 语言 | 扩展名 | |------|--------| | TypeScript / JavaScript | `.ts` `.tsx` `.js` `.jsx` `.mjs` `.cjs` | | Python | `.py` `.pyw` | | Go | `.go` | | Rust | `.rs` | | Java | `.java` | | C | `.c` `.h` | | C++ | `.cpp` `.cxx` `.cc` `.hpp` | | C# | `.cs` | ## 忽略规则 默认情况下,cxt 会跳过常见的非项目目录(`node_modules`、`.git`、`dist`、`build`、`target`、`vendor`、`docker` 等)以及所有隐藏目录。 ### .cxtignore 在项目根目录创建 `.cxtignore` 文件,以排除 `scan` 和 `bs` 的额外路径: ``` # 目录 docker/ legacy/ subprojects/pykis/ # 前缀模式 build-* # 路径模式 tools/external/** ``` ### 自动检测 cxt 还会读取 `.gitignore` 中的目录模式,并自动检测依赖子项目(拥有自己的 `package.json`/`Cargo.toml` 等以及 `node_modules`/`.venv` 的目录)。 ## BS 检测器规则 | 严重性 | 模式 | 描述 | |--------|------|------| | CRITICAL | 空 catch/except | 异常静默 | | CRITICAL | 硬编码密钥 | password/api_key/secret/token | | CRITICAL | debugger | 残留的调试语句 | | CRITICAL | 虚假成功返回 | `return true // always` | | WARNING | eval() | 代码注入风险 | | WARNING | TODO/FIXME | 残留的 TODO | | WARNING | console.log | 生产环境中的调试输出 | | WARNING | `any` 类型 | TypeScript 类型安全绕过 | | WARNING | 示例网址 | 硬编码的假 URL | | MINOR | 魔法数字 | 不明确的硬编码值 | | MINOR | 200+ 字符行 | 可读性差 | ## 国际化 支持英文(`en`)和韩文(`ko`)。语言会自动从 `LANG` 环境变量中检测,也可通过 `--lang` 显式设置。 ## Claude Code 集成 在 `settings.json` 的 `SessionStart` 钩子中添加 `cxt inject`,以实现自动代码库上下文注入: ``` { "hooks": { "SessionStart": [ { "type": "command", "command": "cxt inject" } ] } } ``` ## 存储 注册表存储在 `~/.cxt/registry.db`(SQLite)中。每个项目通过项目 ID 隔离,因此可以同时跟踪多个代码库。 ## 编程 API ``` import { getRegistryStore, scanRepository, scanBs } from '@intrect/cxt'; // Scan const result = await scanRepository('/path/to/project', 'my-project'); // Query registry const store = getRegistryStore(); const stats = store.getStats('my-project'); const entities = store.searchEntities('handleCheck'); // BS detection const bsResult = await scanBs('/path/to/project'); ``` ## 许可证 Apache License 2.0
标签:AI 辅助编程, C/C++, CI/CD 集成, Claude Code, CMS安全, FTS5 全文检索, Go, Java RMI, JavaScript, JSON 输出, JS文件枚举, LNA, MITM代理, Python, Ruby工具, Rust, SQLite, TypeScript, 上下文注入, 事务性I/O, 云安全监控, 代码异味检测, 代码注解, 可视化界面, 坏味道检测, 安全插件, 安全风险, 实体注册, 实验性状态, 开发效率工具, 弃用检测, 无后门, 日志审计, 标签过滤, 目录树视图, 网络流量审计, 自动化攻击, 语言自动检测, 逆向工具, 静态分析, 项目代码管理, 风险实体, 高风险标识