Files
claude-code/src/query/deps.ts
T
Serendipity ed91e47107 feat: 初始化项目结构与核心文件
- 添加项目配置文件(tsconfig.json、bunfig.toml、.gitignore、.env.example)
- 创建文档架构图(00runtime.png 至 08-state-data-flow.png)
- 添加核心工具常量定义(FileEditTool、AgentTool、BashTool 等)
- 实现基础命令框架(help、exit、config、model 等)
- 添加 Ink TUI 组件库和布局引擎
- 包含内存管理、沙箱、shell 工具等基础工具类
- 设置预加载脚本和版本信息
2026-04-02 17:13:04 +08:00

41 lines
1.4 KiB
TypeScript

import { randomUUID } from 'crypto'
import { queryModelWithStreaming } from '../services/api/claude.js'
import { autoCompactIfNeeded } from '../services/compact/autoCompact.js'
import { microcompactMessages } from '../services/compact/microCompact.js'
// -- deps
// I/O dependencies for query(). Passing a `deps` override into QueryParams
// lets tests inject fakes directly instead of spyOn-per-module — the most
// common mocks (callModel, autocompact) are each spied in 6-8 test files
// today with module-import-and-spy boilerplate.
//
// Using `typeof fn` keeps signatures in sync with the real implementations
// automatically. This file imports the real functions for both typing and
// the production factory — tests that import this file for typing are
// already importing query.ts (which imports everything), so there's no
// new module-graph cost.
//
// Scope is intentionally narrow (4 deps) to prove the pattern. Followup
// PRs can add runTools, handleStopHooks, logEvent, queue ops, etc.
export type QueryDeps = {
// -- model
callModel: typeof queryModelWithStreaming
// -- compaction
microcompact: typeof microcompactMessages
autocompact: typeof autoCompactIfNeeded
// -- platform
uuid: () => string
}
export function productionDeps(): QueryDeps {
return {
callModel: queryModelWithStreaming,
microcompact: microcompactMessages,
autocompact: autoCompactIfNeeded,
uuid: randomUUID,
}
}