Skip to content

Commit 3e1cc68

Browse files
committed
feat: gate routing hints with search config
1 parent 2023703 commit 3e1cc68

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/config/schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface SearchConfig {
4747
rrfK: number;
4848
rerankTopN: number;
4949
contextLines: number;
50+
routingHints: boolean;
5051
}
5152

5253
export type RerankerProvider = "cohere" | "jina" | "custom";
@@ -161,6 +162,7 @@ function getDefaultSearchConfig(): SearchConfig {
161162
rrfK: 60,
162163
rerankTopN: 20,
163164
contextLines: 0,
165+
routingHints: true,
164166
};
165167
}
166168

@@ -277,6 +279,7 @@ export function parseConfig(raw: unknown): ParsedCodebaseIndexConfig {
277279
rrfK: typeof rawSearch.rrfK === "number" ? Math.max(1, Math.floor(rawSearch.rrfK)) : defaultSearch.rrfK,
278280
rerankTopN: typeof rawSearch.rerankTopN === "number" ? Math.min(200, Math.max(0, Math.floor(rawSearch.rerankTopN))) : defaultSearch.rerankTopN,
279281
contextLines: typeof rawSearch.contextLines === "number" ? Math.min(50, Math.max(0, rawSearch.contextLines)) : defaultSearch.contextLines,
282+
routingHints: typeof rawSearch.routingHints === "boolean" ? rawSearch.routingHints : defaultSearch.routingHints,
280283
};
281284

282285
const rawDebug = (input.debug && typeof input.debug === "object" ? input.debug : {}) as Record<string, unknown>;

src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
initializeTools,
2424
} from "./tools/index.js";
2525
import { loadCommandsFromDirectory } from "./commands/loader.js";
26+
import { RoutingHintController } from "./routing-hints.js";
2627
import { hasProjectMarker } from "./utils/files.js";
2728

2829
function getCommandsDir(): string {
@@ -44,6 +45,9 @@ const plugin: Plugin = async ({ directory }) => {
4445
initializeTools(projectRoot, config);
4546

4647
const indexer = new Indexer(projectRoot, config);
48+
const routingHints = config.search.routingHints
49+
? new RoutingHintController(() => indexer.getStatus())
50+
: null;
4751

4852
const isValidProject = !config.indexing.requireProjectMarker || hasProjectMarker(projectRoot);
4953

@@ -81,6 +85,19 @@ const plugin: Plugin = async ({ directory }) => {
8185
remove_knowledge_base,
8286
},
8387

88+
async "chat.message"(input, output) {
89+
routingHints?.observeUserMessage(input.sessionID, output.parts);
90+
},
91+
92+
async "experimental.chat.system.transform"(input, output) {
93+
const hints = await routingHints?.getSystemHints(input.sessionID) ?? [];
94+
output.system.push(...hints);
95+
},
96+
97+
async "tool.execute.after"(input) {
98+
routingHints?.markToolUsed(input.sessionID, input.tool);
99+
},
100+
84101
async config(cfg) {
85102
cfg.command = cfg.command ?? {};
86103

tests/config.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,16 @@ describe("config schema", () => {
289289
expect(config.search.fusionStrategy).toBe("rrf");
290290
expect(config.search.rrfK).toBe(60);
291291
expect(config.search.rerankTopN).toBe(20);
292+
expect(config.search.routingHints).toBe(true);
293+
});
294+
295+
it("should parse routingHints boolean", () => {
296+
expect(parseConfig({ search: { routingHints: false } }).search.routingHints).toBe(false);
297+
expect(parseConfig({ search: { routingHints: true } }).search.routingHints).toBe(true);
298+
});
299+
300+
it("should fallback routingHints to default for invalid values", () => {
301+
expect(parseConfig({ search: { routingHints: "nope" } }).search.routingHints).toBe(true);
292302
});
293303

294304
it("should fallback fusionStrategy to default for invalid values", () => {

0 commit comments

Comments
 (0)