/ query / deps.ts
deps.ts
 1  import { randomUUID } from 'crypto'
 2  import { queryModelWithStreaming } from '../services/api/claude.js'
 3  import { autoCompactIfNeeded } from '../services/compact/autoCompact.js'
 4  import { microcompactMessages } from '../services/compact/microCompact.js'
 5  
 6  // -- deps
 7  
 8  // I/O dependencies for query(). Passing a `deps` override into QueryParams
 9  // lets tests inject fakes directly instead of spyOn-per-module — the most
10  // common mocks (callModel, autocompact) are each spied in 6-8 test files
11  // today with module-import-and-spy boilerplate.
12  //
13  // Using `typeof fn` keeps signatures in sync with the real implementations
14  // automatically. This file imports the real functions for both typing and
15  // the production factory — tests that import this file for typing are
16  // already importing query.ts (which imports everything), so there's no
17  // new module-graph cost.
18  //
19  // Scope is intentionally narrow (4 deps) to prove the pattern. Followup
20  // PRs can add runTools, handleStopHooks, logEvent, queue ops, etc.
21  export type QueryDeps = {
22    // -- model
23    callModel: typeof queryModelWithStreaming
24  
25    // -- compaction
26    microcompact: typeof microcompactMessages
27    autocompact: typeof autoCompactIfNeeded
28  
29    // -- platform
30    uuid: () => string
31  }
32  
33  export function productionDeps(): QueryDeps {
34    return {
35      callModel: queryModelWithStreaming,
36      microcompact: microcompactMessages,
37      autocompact: autoCompactIfNeeded,
38      uuid: randomUUID,
39    }
40  }