Files
hose-use/src/core
gitea 1cd8901f7a feat(cli): add corps search command and intuitive aliases
- Implement hose-use corps search <keyword> with case-insensitive fuzzy matching across id, name, corpId, staffId, staffName, and accountId
- Format terminal table output with matched cell brackets, hit labels, active corp markers, and friendly no-match fallback
- Support --json structured output conforming to CliResult specification
- Add intuitive aliases for frequently guessed commands: auth list -> auth accounts, corps find -> corps search, config show -> config paths
- Enhance CorpSummary and CorpContext with corpId, staffName, and getAllCorps
- Add comprehensive unit tests in corps.test.ts, auth.test.ts, and config.test.ts
2026-09-09 14:42:58 +08:00
..

Core 层说明

Core 层负责基础设施:企业配置管理、认证 Token 获取与缓存、统一数据库与版本迁移、多级协同缓存、HTTP 客户端工厂、统一异常语义。

代码结构

src/core/
├── auth/        # 登录认证与 Token 获取、刷新、缓存
│   ├── login.ts         # 登录四矩阵(RSA账密登录、短信验证码、F12/cURL凭证导入、浏览器同步)
│   ├── account-store.ts # 多账号持久化存储 (~/.cache/ekb-mcp/accounts.json)
│   ├── tools.ts         # MCP Auth Tools 注册与调度
│   ├── ekb.ts           # 快报主站三 Header 认证
│   ├── easo.ts          # EASO(unity.ekuaibao.com)四步认证
│   ├── piper.ts         # Piper(piper.ekuaibao.com)三步认证
│   ├── token-store.ts   # 动态 Token 缓存(兼容 ~/.config/hose-use/tokens.json 与历史路径)
│   └── types.ts
├── cache/       # 统一多级协同缓存
│   ├── memory.ts        # L1 内存缓存(TTL、容量限制、按命名空间清理)
│   ├── sqlite.ts        # L2 SQLite 持久化缓存(跨 CLI 进程复用)
│   ├── multi-level.ts   # 多级联动门面与 withCache 透明包装器
│   └── types.ts
├── db/          # 统一 SQLite 数据库与结构化版本迁移
│   ├── connection.ts    # SQLite 单例、WAL 模式、文件权限 0o600 保护
│   ├── migrations.ts    # 结构化增量迁移运行器(_schema_migrations)
│   └── types.ts
├── config/      # 企业配置管理
│   ├── loader.ts
│   ├── manager.ts
│   └── types.ts
├── http/        # HTTP 客户端工厂
│   └── factory.ts
└── errors.ts    # 统一异常语义(EkbError 子类)

分层约束

  • domains/*/api.ts 只通过 core/http/factory.ts 或 core/auth/* 获取客户端
  • domains/* 层只抛 EkbError 子类
  • server.ts 负责把 EkbError 映射为 MCP error
  • 业务域如果需要缓存,统一使用 core/cache/ 提供的多级缓存门面
  • 业务域如果需要持久化数据,统一接入 core/db/ 并注册版本迁移