codesift-mcp 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -25
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +8 -6
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/platform.d.ts.map +1 -1
- package/dist/cli/platform.js +12 -14
- package/dist/cli/platform.js.map +1 -1
- package/dist/cli/setup.d.ts +1 -1
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js +10 -1
- package/dist/cli/setup.js.map +1 -1
- package/dist/formatters.d.ts +2 -2
- package/dist/formatters.d.ts.map +1 -1
- package/dist/formatters.js +23 -0
- package/dist/formatters.js.map +1 -1
- package/dist/instructions.d.ts +1 -1
- package/dist/instructions.d.ts.map +1 -1
- package/dist/instructions.js +21 -21
- package/dist/parser/extractors/php.d.ts.map +1 -1
- package/dist/parser/extractors/php.js +37 -29
- package/dist/parser/extractors/php.js.map +1 -1
- package/dist/parser/extractors/typescript.d.ts.map +1 -1
- package/dist/parser/extractors/typescript.js +43 -0
- package/dist/parser/extractors/typescript.js.map +1 -1
- package/dist/parser/parse-cache.d.ts +39 -0
- package/dist/parser/parse-cache.d.ts.map +1 -0
- package/dist/parser/parse-cache.js +87 -0
- package/dist/parser/parse-cache.js.map +1 -0
- package/dist/parser/parser-manager.d.ts.map +1 -1
- package/dist/parser/parser-manager.js +12 -1
- package/dist/parser/parser-manager.js.map +1 -1
- package/dist/register-tools.d.ts +2 -2
- package/dist/register-tools.d.ts.map +1 -1
- package/dist/register-tools.js +353 -570
- package/dist/register-tools.js.map +1 -1
- package/dist/search/tool-ranker.d.ts +90 -0
- package/dist/search/tool-ranker.d.ts.map +1 -0
- package/dist/search/tool-ranker.js +420 -0
- package/dist/search/tool-ranker.js.map +1 -0
- package/dist/server.js +19 -13
- package/dist/server.js.map +1 -1
- package/dist/storage/usage-tracker.d.ts.map +1 -1
- package/dist/storage/usage-tracker.js +4 -1
- package/dist/storage/usage-tracker.js.map +1 -1
- package/dist/tools/astro-actions.d.ts +54 -0
- package/dist/tools/astro-actions.d.ts.map +1 -0
- package/dist/tools/astro-actions.js +561 -0
- package/dist/tools/astro-actions.js.map +1 -0
- package/dist/tools/astro-audit.d.ts +87 -0
- package/dist/tools/astro-audit.d.ts.map +1 -0
- package/dist/tools/astro-audit.js +345 -0
- package/dist/tools/astro-audit.js.map +1 -0
- package/dist/tools/astro-content-collections.d.ts +44 -0
- package/dist/tools/astro-content-collections.d.ts.map +1 -0
- package/dist/tools/astro-content-collections.js +630 -0
- package/dist/tools/astro-content-collections.js.map +1 -0
- package/dist/tools/astro-islands.d.ts +3 -1
- package/dist/tools/astro-islands.d.ts.map +1 -1
- package/dist/tools/astro-islands.js +19 -4
- package/dist/tools/astro-islands.js.map +1 -1
- package/dist/tools/astro-migration.d.ts +31 -0
- package/dist/tools/astro-migration.d.ts.map +1 -0
- package/dist/tools/astro-migration.js +378 -0
- package/dist/tools/astro-migration.js.map +1 -0
- package/dist/tools/async-correctness.d.ts +26 -0
- package/dist/tools/async-correctness.d.ts.map +1 -0
- package/dist/tools/async-correctness.js +166 -0
- package/dist/tools/async-correctness.js.map +1 -0
- package/dist/tools/django-view-security-tools.d.ts +32 -0
- package/dist/tools/django-view-security-tools.d.ts.map +1 -0
- package/dist/tools/django-view-security-tools.js +184 -0
- package/dist/tools/django-view-security-tools.js.map +1 -0
- package/dist/tools/fastapi-depends.d.ts +63 -0
- package/dist/tools/fastapi-depends.d.ts.map +1 -0
- package/dist/tools/fastapi-depends.js +191 -0
- package/dist/tools/fastapi-depends.js.map +1 -0
- package/dist/tools/hono-analyze-app.js +1 -9
- package/dist/tools/hono-analyze-app.js.map +1 -1
- package/dist/tools/hono-api-contract.d.ts.map +1 -1
- package/dist/tools/hono-api-contract.js +41 -9
- package/dist/tools/hono-api-contract.js.map +1 -1
- package/dist/tools/hono-context-flow.js +1 -9
- package/dist/tools/hono-context-flow.js.map +1 -1
- package/dist/tools/hono-dead-routes.d.ts.map +1 -1
- package/dist/tools/hono-dead-routes.js +2 -9
- package/dist/tools/hono-dead-routes.js.map +1 -1
- package/dist/tools/hono-entry-resolver.d.ts +27 -0
- package/dist/tools/hono-entry-resolver.d.ts.map +1 -0
- package/dist/tools/hono-entry-resolver.js +31 -0
- package/dist/tools/hono-entry-resolver.js.map +1 -0
- package/dist/tools/hono-inline-analyze.js +1 -9
- package/dist/tools/hono-inline-analyze.js.map +1 -1
- package/dist/tools/hono-middleware-chain.d.ts +24 -6
- package/dist/tools/hono-middleware-chain.d.ts.map +1 -1
- package/dist/tools/hono-middleware-chain.js +77 -40
- package/dist/tools/hono-middleware-chain.js.map +1 -1
- package/dist/tools/hono-modules.js +1 -9
- package/dist/tools/hono-modules.js.map +1 -1
- package/dist/tools/hono-response-types.js +1 -9
- package/dist/tools/hono-response-types.js.map +1 -1
- package/dist/tools/hono-rpc-types.js +1 -9
- package/dist/tools/hono-rpc-types.js.map +1 -1
- package/dist/tools/hono-security.d.ts +14 -4
- package/dist/tools/hono-security.d.ts.map +1 -1
- package/dist/tools/hono-security.js +185 -14
- package/dist/tools/hono-security.js.map +1 -1
- package/dist/tools/hono-visualize.js +1 -9
- package/dist/tools/hono-visualize.js.map +1 -1
- package/dist/tools/nest-ext-tools.d.ts +115 -0
- package/dist/tools/nest-ext-tools.d.ts.map +1 -1
- package/dist/tools/nest-ext-tools.js +393 -0
- package/dist/tools/nest-ext-tools.js.map +1 -1
- package/dist/tools/nest-tools.d.ts +27 -0
- package/dist/tools/nest-tools.d.ts.map +1 -1
- package/dist/tools/nest-tools.js +137 -37
- package/dist/tools/nest-tools.js.map +1 -1
- package/dist/tools/nextjs-component-readers.d.ts +101 -0
- package/dist/tools/nextjs-component-readers.d.ts.map +1 -0
- package/dist/tools/nextjs-component-readers.js +287 -0
- package/dist/tools/nextjs-component-readers.js.map +1 -0
- package/dist/tools/nextjs-component-tools.d.ts +8 -78
- package/dist/tools/nextjs-component-tools.d.ts.map +1 -1
- package/dist/tools/nextjs-component-tools.js +9 -257
- package/dist/tools/nextjs-component-tools.js.map +1 -1
- package/dist/tools/nextjs-framework-audit-tools.d.ts +24 -1
- package/dist/tools/nextjs-framework-audit-tools.d.ts.map +1 -1
- package/dist/tools/nextjs-framework-audit-tools.js +184 -1
- package/dist/tools/nextjs-framework-audit-tools.js.map +1 -1
- package/dist/tools/nextjs-route-readers.d.ts +81 -0
- package/dist/tools/nextjs-route-readers.d.ts.map +1 -0
- package/dist/tools/nextjs-route-readers.js +340 -0
- package/dist/tools/nextjs-route-readers.js.map +1 -0
- package/dist/tools/nextjs-route-tools.d.ts +7 -71
- package/dist/tools/nextjs-route-tools.d.ts.map +1 -1
- package/dist/tools/nextjs-route-tools.js +9 -327
- package/dist/tools/nextjs-route-tools.js.map +1 -1
- package/dist/tools/pattern-tools.d.ts.map +1 -1
- package/dist/tools/pattern-tools.js +92 -2
- package/dist/tools/pattern-tools.js.map +1 -1
- package/dist/tools/php-tools.d.ts +14 -5
- package/dist/tools/php-tools.d.ts.map +1 -1
- package/dist/tools/php-tools.js +166 -64
- package/dist/tools/php-tools.js.map +1 -1
- package/dist/tools/plan-turn-tools.d.ts +89 -0
- package/dist/tools/plan-turn-tools.d.ts.map +1 -0
- package/dist/tools/plan-turn-tools.js +508 -0
- package/dist/tools/plan-turn-tools.js.map +1 -0
- package/dist/tools/project-tools.d.ts +1 -1
- package/dist/tools/project-tools.js +1 -1
- package/dist/tools/project-tools.js.map +1 -1
- package/dist/tools/pydantic-models.d.ts +46 -0
- package/dist/tools/pydantic-models.d.ts.map +1 -0
- package/dist/tools/pydantic-models.js +249 -0
- package/dist/tools/pydantic-models.js.map +1 -0
- package/dist/tools/python-audit.d.ts +40 -0
- package/dist/tools/python-audit.d.ts.map +1 -0
- package/dist/tools/python-audit.js +244 -0
- package/dist/tools/python-audit.js.map +1 -0
- package/dist/tools/python-constants-tools.d.ts +44 -0
- package/dist/tools/python-constants-tools.d.ts.map +1 -0
- package/dist/tools/python-constants-tools.js +525 -0
- package/dist/tools/python-constants-tools.js.map +1 -0
- package/dist/tools/react-tools.d.ts +46 -1
- package/dist/tools/react-tools.d.ts.map +1 -1
- package/dist/tools/react-tools.js +126 -1
- package/dist/tools/react-tools.js.map +1 -1
- package/dist/tools/review-diff-tools.d.ts +5 -0
- package/dist/tools/review-diff-tools.d.ts.map +1 -1
- package/dist/tools/review-diff-tools.js +109 -3
- package/dist/tools/review-diff-tools.js.map +1 -1
- package/dist/tools/search-tools.d.ts +3 -2
- package/dist/tools/search-tools.d.ts.map +1 -1
- package/dist/tools/search-tools.js +16 -3
- package/dist/tools/search-tools.js.map +1 -1
- package/dist/tools/sql-tools.d.ts +40 -0
- package/dist/tools/sql-tools.d.ts.map +1 -1
- package/dist/tools/sql-tools.js +123 -0
- package/dist/tools/sql-tools.js.map +1 -1
- package/dist/tools/symbol-tools.d.ts.map +1 -1
- package/dist/tools/symbol-tools.js +7 -10
- package/dist/tools/symbol-tools.js.map +1 -1
- package/dist/tools/taint-tools.d.ts +43 -0
- package/dist/tools/taint-tools.d.ts.map +1 -0
- package/dist/tools/taint-tools.js +922 -0
- package/dist/tools/taint-tools.js.map +1 -0
- package/dist/utils/import-graph.d.ts +6 -0
- package/dist/utils/import-graph.d.ts.map +1 -1
- package/dist/utils/import-graph.js +43 -7
- package/dist/utils/import-graph.js.map +1 -1
- package/package.json +2 -2
- package/rules/codesift.md +51 -13
- package/rules/codesift.mdc +51 -13
- package/rules/codex.md +51 -13
- package/rules/gemini.md +51 -13
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-ranker — ranks MCP tool definitions against a natural-language query
|
|
3
|
+
* using BM25 (lexical), exact-name (identity), embedding cosine (semantic),
|
|
4
|
+
* usage frequency (structural), and framework-match (framework) signals.
|
|
5
|
+
*
|
|
6
|
+
* Used by the `plan_turn` / tool-recommendation meta tools to surface the
|
|
7
|
+
* most relevant tools for an agent's current intent.
|
|
8
|
+
*
|
|
9
|
+
* All signals are optional — semantic and structural gracefully degrade to
|
|
10
|
+
* zero when the corresponding input is unavailable (e.g. no embedding API
|
|
11
|
+
* key, fresh session with no usage history).
|
|
12
|
+
*/
|
|
13
|
+
import { type BM25Index } from "./bm25.js";
|
|
14
|
+
import type { ToolDefinition } from "../register-tools.js";
|
|
15
|
+
export interface ToolRecommendation {
|
|
16
|
+
name: string;
|
|
17
|
+
confidence: number;
|
|
18
|
+
reasoning: string;
|
|
19
|
+
suggested_params?: Record<string, string>;
|
|
20
|
+
is_hidden: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ToolRankerContext {
|
|
23
|
+
query: string;
|
|
24
|
+
toolDefs: ToolDefinition[];
|
|
25
|
+
embeddings: Map<string, number[]> | null;
|
|
26
|
+
queryEmbedding: number[] | null;
|
|
27
|
+
usageFrequency: Map<string, number>;
|
|
28
|
+
frameworkTools: string[];
|
|
29
|
+
/**
|
|
30
|
+
* Names of tools visible in ListTools (core tools). When provided, tools
|
|
31
|
+
* outside this set are flagged as `is_hidden=true` in the recommendation.
|
|
32
|
+
* Defaults to an empty set → every tool is reported as hidden.
|
|
33
|
+
*/
|
|
34
|
+
coreToolNames?: Set<string>;
|
|
35
|
+
}
|
|
36
|
+
/** Per-signal contributions for a single tool — used for reasoning + debugging. */
|
|
37
|
+
interface SignalBreakdown {
|
|
38
|
+
lexical: number;
|
|
39
|
+
identity: number;
|
|
40
|
+
semantic: number;
|
|
41
|
+
structural: number;
|
|
42
|
+
framework: number;
|
|
43
|
+
lexicalTokens: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Compute a stable fingerprint for a list of tool definitions. Used to
|
|
47
|
+
* invalidate the BM25 cache when the tool catalog is modified (tests,
|
|
48
|
+
* hot-reload, new deployments).
|
|
49
|
+
*
|
|
50
|
+
* Exported for tests that need to predict cache-hit behaviour.
|
|
51
|
+
*/
|
|
52
|
+
export declare function toolDefsFingerprint(toolDefs: ToolDefinition[]): string;
|
|
53
|
+
/**
|
|
54
|
+
* Build (or return cached) BM25 index for a tool catalog. Cache is keyed
|
|
55
|
+
* by fingerprint — subsequent calls with the same shape return instantly.
|
|
56
|
+
*/
|
|
57
|
+
export declare function buildToolBM25Index(toolDefs: ToolDefinition[]): BM25Index;
|
|
58
|
+
/** Clear the BM25 cache — for tests and hot-reload. */
|
|
59
|
+
export declare function clearToolBM25Cache(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Render a one-line, human-readable reason explaining why this tool was
|
|
62
|
+
* picked. Falls back to a generic "general match" when no signal dominates.
|
|
63
|
+
*/
|
|
64
|
+
export declare function generateReasoning(id: string, query: string, signals: SignalBreakdown): string;
|
|
65
|
+
/**
|
|
66
|
+
* Rank tools against a natural-language query by combining lexical, identity,
|
|
67
|
+
* semantic, structural, and framework signals. Returns up to 10 `ToolRecommendation`
|
|
68
|
+
* entries sorted by raw weighted score, with calibrated confidence values.
|
|
69
|
+
*
|
|
70
|
+
* Gracefully handles missing inputs:
|
|
71
|
+
* - no embeddings → semantic contribution is 0
|
|
72
|
+
* - empty usageFrequency → structural contribution is 0
|
|
73
|
+
* - empty frameworkTools → framework contribution is 0
|
|
74
|
+
*/
|
|
75
|
+
export declare function rankTools(ctx: ToolRankerContext): ToolRecommendation[];
|
|
76
|
+
/** Absolute path to the on-disk tool-embedding cache. */
|
|
77
|
+
export declare function getToolEmbeddingCachePath(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Fetch (or compute) embeddings for every tool in `defs`. Uses the on-disk
|
|
80
|
+
* cache when the fingerprint matches; otherwise regenerates via the configured
|
|
81
|
+
* embedding provider and persists the result.
|
|
82
|
+
*
|
|
83
|
+
* Returns:
|
|
84
|
+
* - `Map<toolName, number[]>` on success
|
|
85
|
+
* - `null` when no embedding provider is configured (no API key) or the
|
|
86
|
+
* provider call fails — callers should degrade to non-semantic ranking.
|
|
87
|
+
*/
|
|
88
|
+
export declare function getToolEmbeddings(defs: ToolDefinition[]): Promise<Map<string, number[]> | null>;
|
|
89
|
+
export {};
|
|
90
|
+
//# sourceMappingURL=tool-ranker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-ranker.d.ts","sourceRoot":"","sources":["../../src/search/tool-ranker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,OAAO,EAA4C,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAMrF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IACzC,cAAc,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB;;;;OAIG;IACH,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC7B;AAED,mFAAmF;AACnF,UAAU,eAAe;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAqCD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,MAAM,CAatE;AA0BD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,SAAS,CAUxE;AAED,uDAAuD;AACvD,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAuFD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,eAAe,GACvB,MAAM,CA+BR;AAgDD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,iBAAiB,GAAG,kBAAkB,EAAE,CA2FtE;AAaD,yDAAyD;AACzD,wBAAgB,yBAAyB,IAAI,MAAM,CAElD;AAiCD;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,cAAc,EAAE,GACrB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAuDvC"}
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-ranker — ranks MCP tool definitions against a natural-language query
|
|
3
|
+
* using BM25 (lexical), exact-name (identity), embedding cosine (semantic),
|
|
4
|
+
* usage frequency (structural), and framework-match (framework) signals.
|
|
5
|
+
*
|
|
6
|
+
* Used by the `plan_turn` / tool-recommendation meta tools to surface the
|
|
7
|
+
* most relevant tools for an agent's current intent.
|
|
8
|
+
*
|
|
9
|
+
* All signals are optional — semantic and structural gracefully degrade to
|
|
10
|
+
* zero when the corresponding input is unavailable (e.g. no embedding API
|
|
11
|
+
* key, fresh session with no usage history).
|
|
12
|
+
*/
|
|
13
|
+
import { createHash } from "node:crypto";
|
|
14
|
+
import { readFile } from "node:fs/promises";
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { buildBM25Index, searchBM25, tokenizeText } from "./bm25.js";
|
|
18
|
+
import { batchEmbed } from "../storage/embedding-store.js";
|
|
19
|
+
import { createEmbeddingProvider } from "./semantic.js";
|
|
20
|
+
import { loadConfig } from "../config.js";
|
|
21
|
+
import { atomicWriteFile } from "../storage/_shared.js";
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Signal weights
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
const W_LEXICAL = 1.0;
|
|
26
|
+
const W_IDENTITY = 2.0;
|
|
27
|
+
const W_SEMANTIC = 0.8;
|
|
28
|
+
const W_STRUCTURAL = 0.4;
|
|
29
|
+
const W_FRAMEWORK = 0.6;
|
|
30
|
+
const BM25_TOP_K = 50;
|
|
31
|
+
const MAX_RECOMMENDATIONS = 10;
|
|
32
|
+
// Field weights for the synthetic tool BM25 index. We keep this separate from
|
|
33
|
+
// the global code-symbol weights because for tools, `signature` holds the
|
|
34
|
+
// description and `docstring` holds the searchHint — name is still king.
|
|
35
|
+
const TOOL_FIELD_WEIGHTS = {
|
|
36
|
+
name: 5.0,
|
|
37
|
+
signature: 2.5,
|
|
38
|
+
docstring: 2.0,
|
|
39
|
+
body: 0.0,
|
|
40
|
+
comments: 0.0,
|
|
41
|
+
};
|
|
42
|
+
let bm25Cache = null;
|
|
43
|
+
/**
|
|
44
|
+
* Compute a stable fingerprint for a list of tool definitions. Used to
|
|
45
|
+
* invalidate the BM25 cache when the tool catalog is modified (tests,
|
|
46
|
+
* hot-reload, new deployments).
|
|
47
|
+
*
|
|
48
|
+
* Exported for tests that need to predict cache-hit behaviour.
|
|
49
|
+
*/
|
|
50
|
+
export function toolDefsFingerprint(toolDefs) {
|
|
51
|
+
// Stable subset: name, description, searchHint, category. Schema handler
|
|
52
|
+
// is not stringifiable and not relevant to ranking.
|
|
53
|
+
const subset = toolDefs.map((d) => [
|
|
54
|
+
d.name,
|
|
55
|
+
d.description,
|
|
56
|
+
d.searchHint ?? "",
|
|
57
|
+
d.category ?? "",
|
|
58
|
+
]);
|
|
59
|
+
return createHash("sha1")
|
|
60
|
+
.update(JSON.stringify(subset))
|
|
61
|
+
.digest("hex")
|
|
62
|
+
.slice(0, 16);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Map a `ToolDefinition` to a synthetic `CodeSymbol` so we can reuse the
|
|
66
|
+
* existing BM25 index and scoring pipeline.
|
|
67
|
+
*
|
|
68
|
+
* - id / name → tool name
|
|
69
|
+
* - signature → description (BM25 will tokenise it)
|
|
70
|
+
* - docstring → searchHint keywords
|
|
71
|
+
* - file → "__tools__/{category}.tool"
|
|
72
|
+
*/
|
|
73
|
+
function toolToSymbol(def) {
|
|
74
|
+
const category = def.category ?? "uncategorized";
|
|
75
|
+
return {
|
|
76
|
+
id: def.name,
|
|
77
|
+
repo: "__tools__",
|
|
78
|
+
name: def.name,
|
|
79
|
+
kind: "function",
|
|
80
|
+
file: `__tools__/${category}.tool`,
|
|
81
|
+
start_line: 1,
|
|
82
|
+
end_line: 1,
|
|
83
|
+
signature: def.description,
|
|
84
|
+
docstring: def.searchHint ?? "",
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Build (or return cached) BM25 index for a tool catalog. Cache is keyed
|
|
89
|
+
* by fingerprint — subsequent calls with the same shape return instantly.
|
|
90
|
+
*/
|
|
91
|
+
export function buildToolBM25Index(toolDefs) {
|
|
92
|
+
const fingerprint = toolDefsFingerprint(toolDefs);
|
|
93
|
+
if (bm25Cache && bm25Cache.fingerprint === fingerprint) {
|
|
94
|
+
return bm25Cache.index;
|
|
95
|
+
}
|
|
96
|
+
const symbols = toolDefs.map(toolToSymbol);
|
|
97
|
+
const index = buildBM25Index(symbols);
|
|
98
|
+
bm25Cache = { fingerprint, index };
|
|
99
|
+
return index;
|
|
100
|
+
}
|
|
101
|
+
/** Clear the BM25 cache — for tests and hot-reload. */
|
|
102
|
+
export function clearToolBM25Cache() {
|
|
103
|
+
bm25Cache = null;
|
|
104
|
+
}
|
|
105
|
+
// ---------------------------------------------------------------------------
|
|
106
|
+
// Helpers — signal computation
|
|
107
|
+
// ---------------------------------------------------------------------------
|
|
108
|
+
/**
|
|
109
|
+
* Compute BM25 lexical score and matched tokens for each tool.
|
|
110
|
+
* Returns a map from tool name → { score (normalised 0..1), matches }.
|
|
111
|
+
*/
|
|
112
|
+
function computeLexical(query, index) {
|
|
113
|
+
const results = searchBM25(index, query, BM25_TOP_K, TOOL_FIELD_WEIGHTS);
|
|
114
|
+
const out = new Map();
|
|
115
|
+
if (results.length === 0)
|
|
116
|
+
return out;
|
|
117
|
+
const top = results[0]?.score ?? 0;
|
|
118
|
+
if (top <= 0)
|
|
119
|
+
return out;
|
|
120
|
+
for (const r of results) {
|
|
121
|
+
const normalised = r.score / top;
|
|
122
|
+
out.set(r.symbol.id, {
|
|
123
|
+
score: normalised,
|
|
124
|
+
matches: r.matches ?? [],
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Identity signal — tool name appears verbatim in the query (case-insensitive).
|
|
131
|
+
* Returns 1.0 for an exact substring match, else 0.
|
|
132
|
+
*/
|
|
133
|
+
function computeIdentity(query, toolName) {
|
|
134
|
+
const q = query.toLowerCase();
|
|
135
|
+
const n = toolName.toLowerCase();
|
|
136
|
+
if (!n)
|
|
137
|
+
return 0;
|
|
138
|
+
// Whole-name appearance
|
|
139
|
+
if (q.includes(n))
|
|
140
|
+
return 1;
|
|
141
|
+
// snake_case → space-separated variant (e.g. "find dead code" vs "find_dead_code")
|
|
142
|
+
const spaced = n.replace(/_/g, " ");
|
|
143
|
+
if (q.includes(spaced))
|
|
144
|
+
return 1;
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Cosine similarity between two equal-length vectors.
|
|
149
|
+
* Returns 0 when lengths differ (defensive — caller guarantees equality).
|
|
150
|
+
*/
|
|
151
|
+
function cosine(a, b) {
|
|
152
|
+
if (a.length !== b.length || a.length === 0)
|
|
153
|
+
return 0;
|
|
154
|
+
let dot = 0;
|
|
155
|
+
let nA = 0;
|
|
156
|
+
let nB = 0;
|
|
157
|
+
for (let i = 0; i < a.length; i++) {
|
|
158
|
+
const ai = a[i] ?? 0;
|
|
159
|
+
const bi = b[i] ?? 0;
|
|
160
|
+
dot += ai * bi;
|
|
161
|
+
nA += ai * ai;
|
|
162
|
+
nB += bi * bi;
|
|
163
|
+
}
|
|
164
|
+
const denom = Math.sqrt(nA) * Math.sqrt(nB);
|
|
165
|
+
return denom > 0 ? dot / denom : 0;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Structural signal — normalised usage frequency.
|
|
169
|
+
* Returns value / max(values), clamped to [0..1].
|
|
170
|
+
*/
|
|
171
|
+
function normaliseUsage(usage, toolName) {
|
|
172
|
+
if (usage.size === 0)
|
|
173
|
+
return 0;
|
|
174
|
+
const value = usage.get(toolName) ?? 0;
|
|
175
|
+
if (value <= 0)
|
|
176
|
+
return 0;
|
|
177
|
+
let max = 0;
|
|
178
|
+
for (const v of usage.values())
|
|
179
|
+
if (v > max)
|
|
180
|
+
max = v;
|
|
181
|
+
return max > 0 ? Math.min(1, value / max) : 0;
|
|
182
|
+
}
|
|
183
|
+
// ---------------------------------------------------------------------------
|
|
184
|
+
// Task 4 — Reasoning template
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
/**
|
|
187
|
+
* Render a one-line, human-readable reason explaining why this tool was
|
|
188
|
+
* picked. Falls back to a generic "general match" when no signal dominates.
|
|
189
|
+
*/
|
|
190
|
+
export function generateReasoning(id, query, signals) {
|
|
191
|
+
const reasons = [];
|
|
192
|
+
if (signals.identity > 0) {
|
|
193
|
+
reasons.push("exact name match");
|
|
194
|
+
}
|
|
195
|
+
if (signals.lexical > 0.01 && signals.lexicalTokens.length > 0) {
|
|
196
|
+
const top = signals.lexicalTokens.slice(0, 3).join(", ");
|
|
197
|
+
reasons.push(`keywords: ${top}`);
|
|
198
|
+
}
|
|
199
|
+
if (signals.semantic >= 0.55) {
|
|
200
|
+
reasons.push("semantic similarity");
|
|
201
|
+
}
|
|
202
|
+
if (signals.structural >= 0.5) {
|
|
203
|
+
reasons.push("high usage frequency");
|
|
204
|
+
}
|
|
205
|
+
if (signals.framework > 0) {
|
|
206
|
+
reasons.push("relevant to project stack");
|
|
207
|
+
}
|
|
208
|
+
if (reasons.length === 0) {
|
|
209
|
+
// Fall back — still mention what was attempted.
|
|
210
|
+
const stem = query.trim().slice(0, 30) || id;
|
|
211
|
+
return `general match for "${stem}"`;
|
|
212
|
+
}
|
|
213
|
+
return reasons.join("; ");
|
|
214
|
+
}
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
// Confidence calibration
|
|
217
|
+
// ---------------------------------------------------------------------------
|
|
218
|
+
const VAGUE_WORDS = new Set([
|
|
219
|
+
"help", "code", "find", "search", "what", "how", "show", "look",
|
|
220
|
+
]);
|
|
221
|
+
/**
|
|
222
|
+
* Apply calibration rules that cap confidence for vague or ambiguous queries.
|
|
223
|
+
* Returns the (possibly reduced) confidence for the top recommendation and
|
|
224
|
+
* by extension all downstream confidences (scaled proportionally).
|
|
225
|
+
*/
|
|
226
|
+
function calibrationCap(query, tokens, topScore, secondScore) {
|
|
227
|
+
const trimmed = query.trim();
|
|
228
|
+
const wordCount = trimmed.split(/\s+/).filter(Boolean).length;
|
|
229
|
+
// Rule 1 — vague query (all tokens in VAGUE_WORDS, or very short)
|
|
230
|
+
const allVague = tokens.length > 0 && tokens.every((t) => VAGUE_WORDS.has(t));
|
|
231
|
+
if (trimmed.length < 10 || allVague) {
|
|
232
|
+
return 0.5;
|
|
233
|
+
}
|
|
234
|
+
// Rule 2 — single-keyword query
|
|
235
|
+
if (wordCount === 1 || tokens.length <= 1) {
|
|
236
|
+
return 0.6;
|
|
237
|
+
}
|
|
238
|
+
// Rule 3 — low discrimination: top and runner-up are indistinguishable
|
|
239
|
+
if (topScore > 0 && topScore - secondScore < 0.1) {
|
|
240
|
+
return 0.4;
|
|
241
|
+
}
|
|
242
|
+
return 1.0; // no cap
|
|
243
|
+
}
|
|
244
|
+
// ---------------------------------------------------------------------------
|
|
245
|
+
// Task 2 + 3 — rankTools
|
|
246
|
+
// ---------------------------------------------------------------------------
|
|
247
|
+
/**
|
|
248
|
+
* Rank tools against a natural-language query by combining lexical, identity,
|
|
249
|
+
* semantic, structural, and framework signals. Returns up to 10 `ToolRecommendation`
|
|
250
|
+
* entries sorted by raw weighted score, with calibrated confidence values.
|
|
251
|
+
*
|
|
252
|
+
* Gracefully handles missing inputs:
|
|
253
|
+
* - no embeddings → semantic contribution is 0
|
|
254
|
+
* - empty usageFrequency → structural contribution is 0
|
|
255
|
+
* - empty frameworkTools → framework contribution is 0
|
|
256
|
+
*/
|
|
257
|
+
export function rankTools(ctx) {
|
|
258
|
+
const { query, toolDefs, embeddings, queryEmbedding, usageFrequency, frameworkTools } = ctx;
|
|
259
|
+
const coreToolNames = ctx.coreToolNames ?? new Set();
|
|
260
|
+
if (toolDefs.length === 0 || !query.trim())
|
|
261
|
+
return [];
|
|
262
|
+
const queryTokens = tokenizeText(query);
|
|
263
|
+
const frameworkSet = new Set(frameworkTools);
|
|
264
|
+
// --- Lexical (BM25) -------------------------------------------------
|
|
265
|
+
const index = buildToolBM25Index(toolDefs);
|
|
266
|
+
const lexical = computeLexical(query, index);
|
|
267
|
+
// --- Semantic (iterate ALL tools, not just BM25 candidates) --------
|
|
268
|
+
const semantic = new Map();
|
|
269
|
+
if (embeddings && queryEmbedding && queryEmbedding.length > 0) {
|
|
270
|
+
for (const def of toolDefs) {
|
|
271
|
+
const vec = embeddings.get(def.name);
|
|
272
|
+
if (!vec || vec.length === 0)
|
|
273
|
+
continue;
|
|
274
|
+
const sim = cosine(queryEmbedding, vec);
|
|
275
|
+
if (sim > 0)
|
|
276
|
+
semantic.set(def.name, sim);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const scored = [];
|
|
280
|
+
for (const def of toolDefs) {
|
|
281
|
+
const lex = lexical.get(def.name);
|
|
282
|
+
const lexScore = lex?.score ?? 0;
|
|
283
|
+
const lexTokens = lex?.matches ?? [];
|
|
284
|
+
const idScore = computeIdentity(query, def.name);
|
|
285
|
+
const semScore = semantic.get(def.name) ?? 0;
|
|
286
|
+
const strScore = normaliseUsage(usageFrequency, def.name);
|
|
287
|
+
const frameworkScore = frameworkSet.has(def.name) ? 1 : 0;
|
|
288
|
+
const raw = W_LEXICAL * lexScore +
|
|
289
|
+
W_IDENTITY * idScore +
|
|
290
|
+
W_SEMANTIC * semScore +
|
|
291
|
+
W_STRUCTURAL * strScore +
|
|
292
|
+
W_FRAMEWORK * frameworkScore;
|
|
293
|
+
if (raw <= 0)
|
|
294
|
+
continue;
|
|
295
|
+
scored.push({
|
|
296
|
+
def,
|
|
297
|
+
raw,
|
|
298
|
+
signals: {
|
|
299
|
+
lexical: lexScore,
|
|
300
|
+
identity: idScore,
|
|
301
|
+
semantic: semScore,
|
|
302
|
+
structural: strScore,
|
|
303
|
+
framework: frameworkScore,
|
|
304
|
+
lexicalTokens: lexTokens,
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
scored.sort((a, b) => b.raw - a.raw);
|
|
309
|
+
const top = scored.slice(0, MAX_RECOMMENDATIONS);
|
|
310
|
+
if (top.length === 0)
|
|
311
|
+
return [];
|
|
312
|
+
// --- Confidence normalisation + calibration ------------------------
|
|
313
|
+
const topRaw = top[0]?.raw ?? 0;
|
|
314
|
+
const secondRaw = top[1]?.raw ?? 0;
|
|
315
|
+
const cap = calibrationCap(query, queryTokens, topRaw, secondRaw);
|
|
316
|
+
const recommendations = top.map((s) => {
|
|
317
|
+
// Normalise raw → 0..1 via division by topRaw, then apply cap.
|
|
318
|
+
const normalised = topRaw > 0 ? s.raw / topRaw : 0;
|
|
319
|
+
const confidence = Math.max(0, Math.min(cap, normalised * cap));
|
|
320
|
+
const reasoning = generateReasoning(s.def.name, query, s.signals);
|
|
321
|
+
const isHidden = !coreToolNames.has(s.def.name);
|
|
322
|
+
const rec = {
|
|
323
|
+
name: s.def.name,
|
|
324
|
+
confidence: Math.round(confidence * 1000) / 1000,
|
|
325
|
+
reasoning,
|
|
326
|
+
is_hidden: isHidden,
|
|
327
|
+
};
|
|
328
|
+
return rec;
|
|
329
|
+
});
|
|
330
|
+
return recommendations;
|
|
331
|
+
}
|
|
332
|
+
// ---------------------------------------------------------------------------
|
|
333
|
+
// Task 5 — Tool-embedding cache
|
|
334
|
+
// ---------------------------------------------------------------------------
|
|
335
|
+
const TOOL_EMBEDDING_CACHE_KEY = "__tool_descriptions__";
|
|
336
|
+
/** Absolute path to the on-disk tool-embedding cache. */
|
|
337
|
+
export function getToolEmbeddingCachePath() {
|
|
338
|
+
return join(homedir(), ".codesift", "tool-embeddings.ndjson");
|
|
339
|
+
}
|
|
340
|
+
async function readToolEmbeddingCache(path) {
|
|
341
|
+
try {
|
|
342
|
+
const raw = await readFile(path, "utf-8");
|
|
343
|
+
const parsed = JSON.parse(raw);
|
|
344
|
+
if (typeof parsed === "object" &&
|
|
345
|
+
parsed !== null &&
|
|
346
|
+
typeof parsed["fingerprint"] === "string" &&
|
|
347
|
+
typeof parsed["embeddings"] === "object") {
|
|
348
|
+
return parsed;
|
|
349
|
+
}
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
async function writeToolEmbeddingCache(path, cache) {
|
|
357
|
+
try {
|
|
358
|
+
await atomicWriteFile(path, JSON.stringify(cache));
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
// Cache write failures are non-fatal — ranker still works, just slower next call.
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Fetch (or compute) embeddings for every tool in `defs`. Uses the on-disk
|
|
366
|
+
* cache when the fingerprint matches; otherwise regenerates via the configured
|
|
367
|
+
* embedding provider and persists the result.
|
|
368
|
+
*
|
|
369
|
+
* Returns:
|
|
370
|
+
* - `Map<toolName, number[]>` on success
|
|
371
|
+
* - `null` when no embedding provider is configured (no API key) or the
|
|
372
|
+
* provider call fails — callers should degrade to non-semantic ranking.
|
|
373
|
+
*/
|
|
374
|
+
export async function getToolEmbeddings(defs) {
|
|
375
|
+
if (defs.length === 0)
|
|
376
|
+
return new Map();
|
|
377
|
+
const config = loadConfig();
|
|
378
|
+
if (!config.embeddingProvider)
|
|
379
|
+
return null;
|
|
380
|
+
const fingerprint = toolDefsFingerprint(defs);
|
|
381
|
+
const cachePath = getToolEmbeddingCachePath();
|
|
382
|
+
const cached = await readToolEmbeddingCache(cachePath);
|
|
383
|
+
if (cached && cached.fingerprint === fingerprint) {
|
|
384
|
+
const m = new Map();
|
|
385
|
+
for (const [k, v] of Object.entries(cached.embeddings)) {
|
|
386
|
+
if (Array.isArray(v))
|
|
387
|
+
m.set(k, v);
|
|
388
|
+
}
|
|
389
|
+
return m;
|
|
390
|
+
}
|
|
391
|
+
// Regenerate via provider
|
|
392
|
+
try {
|
|
393
|
+
const provider = createEmbeddingProvider(config.embeddingProvider, config);
|
|
394
|
+
const texts = new Map();
|
|
395
|
+
for (const d of defs) {
|
|
396
|
+
const text = [d.name, d.description, d.searchHint ?? ""]
|
|
397
|
+
.filter(Boolean)
|
|
398
|
+
.join("\n");
|
|
399
|
+
texts.set(d.name, text);
|
|
400
|
+
}
|
|
401
|
+
const existing = new Map();
|
|
402
|
+
const result = await batchEmbed(texts, existing, provider.embed.bind(provider), config.embeddingBatchSize, TOOL_EMBEDDING_CACHE_KEY);
|
|
403
|
+
const out = new Map();
|
|
404
|
+
const recordForDisk = {};
|
|
405
|
+
for (const [name, vec] of result) {
|
|
406
|
+
const asArray = Array.from(vec);
|
|
407
|
+
out.set(name, asArray);
|
|
408
|
+
recordForDisk[name] = asArray;
|
|
409
|
+
}
|
|
410
|
+
await writeToolEmbeddingCache(cachePath, {
|
|
411
|
+
fingerprint,
|
|
412
|
+
embeddings: recordForDisk,
|
|
413
|
+
});
|
|
414
|
+
return out;
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
//# sourceMappingURL=tool-ranker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-ranker.js","sourceRoot":"","sources":["../../src/search/tool-ranker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAkB,MAAM,WAAW,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAyCxD,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,8EAA8E;AAC9E,0EAA0E;AAC1E,yEAAyE;AACzE,MAAM,kBAAkB,GAAG;IACzB,IAAI,EAAE,GAAG;IACT,SAAS,EAAE,GAAG;IACd,SAAS,EAAE,GAAG;IACd,IAAI,EAAE,GAAG;IACT,QAAQ,EAAE,GAAG;CACd,CAA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AC;QAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;QACjD,MAAM,MAAM,GAAG,MAAM,UAAU,CAC7B,KAAK,EACL,QAAQ,EACR,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAC7B,MAAM,CAAC,kBAAkB,EACzB,wBAAwB,CACzB,CAAC;QAEF,MAAM,GAAG,GAAG,IAAI,GAAG,EAAoB,CAAC;QACxC,MAAM,aAAa,GAA6B,EAAE,CAAC;QACnD,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,EAAE,CAAC;YACjC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAChC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACvB,aAAa,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;QAChC,CAAC;QAED,MAAM,uBAAuB,CAAC,SAAS,EAAE;YACvC,WAAW;YACX,UAAU,EAAE,aAAa;SAC1B,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/server.js
CHANGED
|
@@ -7,7 +7,7 @@ import { autoDiscoverConversations } from "./tools/conversation-tools.js";
|
|
|
7
7
|
import { autoIndexCurrentRepo } from "./tools/index-tools.js";
|
|
8
8
|
import { CODESIFT_INSTRUCTIONS } from "./instructions.js";
|
|
9
9
|
import { setupHooksForPlatform } from "./cli/setup.js";
|
|
10
|
-
import { detectPlatform } from "./cli/platform.js";
|
|
10
|
+
import { detectPlatform, detectPlatformFromClientInfo } from "./cli/platform.js";
|
|
11
11
|
// Re-export for test compatibility
|
|
12
12
|
export { buildResponseHint, resetSessionState } from "./server-helpers.js";
|
|
13
13
|
export { resetSession } from "./storage/session-state.js";
|
|
@@ -48,6 +48,23 @@ async function autoEnableFrameworkToolsFromPackageJson(cwd) {
|
|
|
48
48
|
}
|
|
49
49
|
async function main() {
|
|
50
50
|
const transport = new StdioServerTransport();
|
|
51
|
+
const envPlatform = detectPlatform();
|
|
52
|
+
let hooksInstalledFor = null;
|
|
53
|
+
const installHooks = (platform, reason) => {
|
|
54
|
+
if (platform === "unknown" || hooksInstalledFor !== null)
|
|
55
|
+
return;
|
|
56
|
+
hooksInstalledFor = platform;
|
|
57
|
+
setupHooksForPlatform(platform).catch((err) => {
|
|
58
|
+
console.error(`[codesift] hook auto-install failed (${reason}:${platform}):`, err);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
server.server.oninitialized = () => {
|
|
62
|
+
if (hooksInstalledFor !== null || envPlatform !== "unknown")
|
|
63
|
+
return;
|
|
64
|
+
const clientName = server.server.getClientVersion()?.name ?? "";
|
|
65
|
+
const clientPlatform = detectPlatformFromClientInfo(clientName);
|
|
66
|
+
installHooks(clientPlatform === "unknown" ? "claude" : clientPlatform, clientName || "fallback");
|
|
67
|
+
};
|
|
51
68
|
await server.connect(transport);
|
|
52
69
|
console.error("CodeSift MCP server started");
|
|
53
70
|
// Synchronous framework detection from package.json (runs before transport messages flow)
|
|
@@ -61,19 +78,8 @@ async function main() {
|
|
|
61
78
|
console.error("[codesift] conversation auto-discovery failed:", err);
|
|
62
79
|
});
|
|
63
80
|
// Auto-install hooks for the detected platform (idempotent)
|
|
64
|
-
const envPlatform = detectPlatform();
|
|
65
81
|
if (envPlatform !== "unknown") {
|
|
66
|
-
|
|
67
|
-
console.error(`[codesift] hook auto-install failed (${envPlatform}):`, err);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
// Env detection failed — try clientInfo after MCP initialize.
|
|
72
|
-
// The transport emits an internal event, but we can also just try
|
|
73
|
-
// all safe platforms (Claude is the most common, always install).
|
|
74
|
-
setupHooksForPlatform("claude").catch((err) => {
|
|
75
|
-
console.error("[codesift] hook auto-install failed (claude fallback):", err);
|
|
76
|
-
});
|
|
82
|
+
installHooks(envPlatform, "env");
|
|
77
83
|
}
|
|
78
84
|
}
|
|
79
85
|
main().catch((err) => {
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,4BAA4B,EAAqB,MAAM,mBAAmB,C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AAO,CAAC,EAC7B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,OAAO,EACnB,SAAS,EAAE,MAAM,GAChB,IAAI,CAcN;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
|
|
@@ -18,7 +18,7 @@ export function getUsagePath() {
|
|
|
18
18
|
// ---------------------------------------------------------------------------
|
|
19
19
|
/** Per-tool field extraction schema: [key, expectedType] pairs */
|
|
20
20
|
const TOOL_ARG_FIELDS = {
|
|
21
|
-
search_symbols: [["kind", "string"], ["top_k", "number"], ["file_pattern", "string"], ["include_source", "boolean"]],
|
|
21
|
+
search_symbols: [["kind", "string"], ["top_k", "number"], ["file_pattern", "string"], ["decorator", "string"], ["include_source", "boolean"]],
|
|
22
22
|
search_text: [["regex", "boolean"], ["context_lines", "number"], ["file_pattern", "string"], ["max_results", "number"], ["group_by_file", "boolean"], ["auto_group", "boolean"]],
|
|
23
23
|
get_file_tree: [["path_prefix", "string"], ["name_pattern", "string"], ["depth", "number"]],
|
|
24
24
|
get_file_outline: [["file_path", "string"]],
|
|
@@ -31,6 +31,9 @@ const TOOL_ARG_FIELDS = {
|
|
|
31
31
|
get_knowledge_map: [["focus", "string"], ["depth", "number"]],
|
|
32
32
|
diff_outline: [["since", "string"], ["until", "string"]],
|
|
33
33
|
changed_symbols: [["since", "string"], ["until", "string"]],
|
|
34
|
+
resolve_constant_value: [["symbol_name", "string"], ["file_pattern", "string"], ["max_depth", "number"]],
|
|
35
|
+
effective_django_view_security: [["path", "string"], ["symbol_name", "string"], ["file_pattern", "string"], ["settings_file", "string"]],
|
|
36
|
+
taint_trace: [["framework", "string"], ["file_pattern", "string"], ["max_depth", "number"], ["max_traces", "number"]],
|
|
34
37
|
index_folder: [["path", "string"], ["incremental", "boolean"]],
|
|
35
38
|
index_repo: [["url", "string"], ["branch", "string"]],
|
|
36
39
|
generate_claude_md: [["output_path", "string"]],
|