@eduardo-afonso/codebase-intelligence 0.1.0 → 2.0.1
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 +86 -11
- package/README.pt-BR.md +88 -12
- package/dist/ai/CodebaseWithAI.d.ts +91 -0
- package/dist/ai/CodebaseWithAI.d.ts.map +1 -0
- package/dist/ai/CodebaseWithAI.js +149 -0
- package/dist/ai/CodebaseWithAI.js.map +1 -0
- package/dist/ai/RAGPipeline.d.ts +66 -0
- package/dist/ai/RAGPipeline.d.ts.map +1 -0
- package/dist/ai/RAGPipeline.js +102 -0
- package/dist/ai/RAGPipeline.js.map +1 -0
- package/dist/ai/index.d.ts +6 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +5 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/providers/NoopAIProvider.d.ts +23 -0
- package/dist/ai/providers/NoopAIProvider.d.ts.map +1 -0
- package/dist/ai/providers/NoopAIProvider.js +24 -0
- package/dist/ai/providers/NoopAIProvider.js.map +1 -0
- package/dist/cli/index.js +168 -8
- package/dist/cli/index.js.map +1 -1
- package/dist/context/ContextEngine.d.ts +54 -0
- package/dist/context/ContextEngine.d.ts.map +1 -0
- package/dist/context/ContextEngine.js +179 -0
- package/dist/context/ContextEngine.js.map +1 -0
- package/dist/context/FileContextBuilder.d.ts +49 -0
- package/dist/context/FileContextBuilder.d.ts.map +1 -0
- package/dist/context/FileContextBuilder.js +124 -0
- package/dist/context/FileContextBuilder.js.map +1 -0
- package/dist/context/SemanticChunker.d.ts +105 -0
- package/dist/context/SemanticChunker.d.ts.map +1 -0
- package/dist/context/SemanticChunker.js +293 -0
- package/dist/context/SemanticChunker.js.map +1 -0
- package/dist/context/SignatureExtractor.d.ts +49 -0
- package/dist/context/SignatureExtractor.d.ts.map +1 -0
- package/dist/context/SignatureExtractor.js +167 -0
- package/dist/context/SignatureExtractor.js.map +1 -0
- package/dist/context/interfaces.d.ts +149 -0
- package/dist/context/interfaces.d.ts.map +1 -0
- package/dist/context/interfaces.js +13 -0
- package/dist/context/interfaces.js.map +1 -0
- package/dist/context/strategies/ContextBuildStrategy.d.ts +25 -0
- package/dist/context/strategies/ContextBuildStrategy.d.ts.map +1 -0
- package/dist/context/strategies/ContextBuildStrategy.js +3 -0
- package/dist/context/strategies/ContextBuildStrategy.js.map +1 -0
- package/dist/context/strategies/DeepStrategy.d.ts +18 -0
- package/dist/context/strategies/DeepStrategy.d.ts.map +1 -0
- package/dist/context/strategies/DeepStrategy.js +19 -0
- package/dist/context/strategies/DeepStrategy.js.map +1 -0
- package/dist/context/strategies/ShallowStrategy.d.ts +15 -0
- package/dist/context/strategies/ShallowStrategy.d.ts.map +1 -0
- package/dist/context/strategies/ShallowStrategy.js +15 -0
- package/dist/context/strategies/ShallowStrategy.js.map +1 -0
- package/dist/context/strategies/SignatureStrategy.d.ts +20 -0
- package/dist/context/strategies/SignatureStrategy.d.ts.map +1 -0
- package/dist/context/strategies/SignatureStrategy.js +59 -0
- package/dist/context/strategies/SignatureStrategy.js.map +1 -0
- package/dist/context/strategies/index.d.ts +5 -0
- package/dist/context/strategies/index.d.ts.map +1 -0
- package/dist/context/strategies/index.js +4 -0
- package/dist/context/strategies/index.js.map +1 -0
- package/dist/context/types.d.ts +136 -0
- package/dist/context/types.d.ts.map +1 -0
- package/dist/context/types.js +8 -0
- package/dist/context/types.js.map +1 -0
- package/dist/core/Codebase.d.ts +50 -0
- package/dist/core/Codebase.d.ts.map +1 -1
- package/dist/core/Codebase.js +104 -0
- package/dist/core/Codebase.js.map +1 -1
- package/dist/diff/ChangeSetImpactAnalyzer.d.ts +19 -0
- package/dist/diff/ChangeSetImpactAnalyzer.d.ts.map +1 -0
- package/dist/diff/ChangeSetImpactAnalyzer.js +121 -0
- package/dist/diff/ChangeSetImpactAnalyzer.js.map +1 -0
- package/dist/diff/GitChangeSetProvider.d.ts +86 -0
- package/dist/diff/GitChangeSetProvider.d.ts.map +1 -0
- package/dist/diff/GitChangeSetProvider.js +297 -0
- package/dist/diff/GitChangeSetProvider.js.map +1 -0
- package/dist/diff/errors.d.ts +48 -0
- package/dist/diff/errors.d.ts.map +1 -0
- package/dist/diff/errors.js +70 -0
- package/dist/diff/errors.js.map +1 -0
- package/dist/diff/types.d.ts +159 -0
- package/dist/diff/types.d.ts.map +1 -0
- package/dist/diff/types.js +8 -0
- package/dist/diff/types.js.map +1 -0
- package/dist/explorer/SnapshotBuilder.d.ts +22 -0
- package/dist/explorer/SnapshotBuilder.d.ts.map +1 -0
- package/dist/explorer/SnapshotBuilder.js +225 -0
- package/dist/explorer/SnapshotBuilder.js.map +1 -0
- package/dist/explorer/types.d.ts +88 -0
- package/dist/explorer/types.d.ts.map +1 -0
- package/dist/explorer/types.js +12 -0
- package/dist/explorer/types.js.map +1 -0
- package/dist/explorer/ui/App.d.ts +3 -0
- package/dist/explorer/ui/App.d.ts.map +1 -0
- package/dist/explorer/ui/App.js +43 -0
- package/dist/explorer/ui/App.js.map +1 -0
- package/dist/explorer/ui/main.d.ts +2 -0
- package/dist/explorer/ui/main.d.ts.map +1 -0
- package/dist/explorer/ui/main.js +8 -0
- package/dist/explorer/ui/main.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -1
- package/dist/ui/assets/index-D4w3JVrv.css +1 -0
- package/dist/ui/assets/index-DBRKE5qL.js +52 -0
- package/dist/ui/index.html +13 -0
- package/package.json +50 -50
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Engine — Core Interfaces
|
|
3
|
+
*
|
|
4
|
+
* Defines the contracts for the Context Engine and for future AI/embedding
|
|
5
|
+
* adapters. None of these interfaces are coupled to a specific LLM SDK or
|
|
6
|
+
* vector-store implementation.
|
|
7
|
+
*
|
|
8
|
+
* Implementations of AIProvider, EmbeddingProvider and VectorStore are
|
|
9
|
+
* intentionally excluded from the core library and must be provided by
|
|
10
|
+
* downstream packages (e.g. `codebase-intelligence-openai`).
|
|
11
|
+
*/
|
|
12
|
+
import type { LLMContextPayload, ContextOptions } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* The primary contract for building LLM-ready context payloads from a
|
|
15
|
+
* codebase that has already been loaded and analysed.
|
|
16
|
+
*
|
|
17
|
+
* Consumers should obtain an instance via `codebase.context()` rather than
|
|
18
|
+
* constructing one directly.
|
|
19
|
+
*/
|
|
20
|
+
export interface IContextEngine {
|
|
21
|
+
/**
|
|
22
|
+
* Builds a context payload centred on a specific source file.
|
|
23
|
+
*
|
|
24
|
+
* @param file - Absolute or relative path to the target file.
|
|
25
|
+
* @param options - Strategy, token budget, and inclusion flags.
|
|
26
|
+
*/
|
|
27
|
+
forFile(file: string, options?: ContextOptions): Promise<LLMContextPayload>;
|
|
28
|
+
/**
|
|
29
|
+
* Builds a context payload centred on a named symbol (class, function, etc.).
|
|
30
|
+
* The file that declares the symbol is treated as the target.
|
|
31
|
+
*
|
|
32
|
+
* @param symbolName - The exact name of the symbol (e.g. `AuthService`).
|
|
33
|
+
* @param options - Strategy, token budget, and inclusion flags.
|
|
34
|
+
*/
|
|
35
|
+
forSymbol(symbolName: string, options?: ContextOptions): Promise<LLMContextPayload>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Minimal adapter contract for any text-completion LLM.
|
|
39
|
+
*
|
|
40
|
+
* Implementations should be thin wrappers around their respective SDKs
|
|
41
|
+
* and must NOT be part of the `codebase-intelligence` core package.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* class OpenAIProvider implements AIProvider {
|
|
46
|
+
* readonly name = 'openai';
|
|
47
|
+
* async complete(prompt, systemPrompt) {
|
|
48
|
+
* const res = await openai.chat.completions.create({ ... });
|
|
49
|
+
* return res.choices[0].message.content ?? '';
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export interface AIProvider {
|
|
55
|
+
/** Human-readable identifier, e.g. `'openai'`, `'ollama'`, `'anthropic'`. */
|
|
56
|
+
readonly name: string;
|
|
57
|
+
/**
|
|
58
|
+
* Sends a prompt and returns the model's response as a plain string.
|
|
59
|
+
*
|
|
60
|
+
* @param prompt - The user/human turn of the conversation.
|
|
61
|
+
* @param systemPrompt - Optional system/instruction turn.
|
|
62
|
+
*/
|
|
63
|
+
complete(prompt: string, systemPrompt?: string): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Optional streaming variant.
|
|
66
|
+
* When implemented, callers can iterate over partial response chunks.
|
|
67
|
+
*
|
|
68
|
+
* @param prompt - The user/human turn of the conversation.
|
|
69
|
+
* @param systemPrompt - Optional system/instruction turn.
|
|
70
|
+
*/
|
|
71
|
+
stream?(prompt: string, systemPrompt?: string): AsyncIterable<string>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Adapter contract for text-embedding models.
|
|
75
|
+
*
|
|
76
|
+
* Used by the RAG pipeline to convert `SemanticChunk` content into dense
|
|
77
|
+
* vectors for similarity search.
|
|
78
|
+
*
|
|
79
|
+
* Implementations must NOT live in the core package.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* class OllamaEmbeddingProvider implements EmbeddingProvider {
|
|
84
|
+
* readonly dimensions = 768;
|
|
85
|
+
* async embed(texts) { ... }
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export interface EmbeddingProvider {
|
|
90
|
+
/** Dimensionality of the vectors produced by this provider. */
|
|
91
|
+
readonly dimensions: number;
|
|
92
|
+
/**
|
|
93
|
+
* Converts an array of text strings into an array of embedding vectors.
|
|
94
|
+
* The output array has the same length as the input.
|
|
95
|
+
*
|
|
96
|
+
* @param texts - Raw text strings to embed.
|
|
97
|
+
* @returns A parallel array of numeric vectors.
|
|
98
|
+
*/
|
|
99
|
+
embed(texts: string[]): Promise<number[][]>;
|
|
100
|
+
}
|
|
101
|
+
/** A single result returned by a vector similarity search. */
|
|
102
|
+
export interface VectorSearchResult {
|
|
103
|
+
/** The ID that was passed to `upsert`. */
|
|
104
|
+
id: string;
|
|
105
|
+
/** Similarity score (higher = more similar; exact range is provider-specific). */
|
|
106
|
+
score: number;
|
|
107
|
+
/** Any metadata that was stored alongside the vector. */
|
|
108
|
+
metadata: Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Adapter contract for a vector database / similarity store.
|
|
112
|
+
*
|
|
113
|
+
* Implementations (Qdrant, pgvector, Chroma, Pinecone, etc.) must NOT live
|
|
114
|
+
* in the core package.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* class QdrantVectorStore implements VectorStore {
|
|
119
|
+
* async upsert(id, vector, metadata) { ... }
|
|
120
|
+
* async search(vector, topK) { ... }
|
|
121
|
+
* async delete(id) { ... }
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export interface VectorStore {
|
|
126
|
+
/**
|
|
127
|
+
* Inserts or updates a vector entry.
|
|
128
|
+
*
|
|
129
|
+
* @param id - Stable unique identifier for this entry (e.g. chunk ID).
|
|
130
|
+
* @param vector - Dense embedding vector.
|
|
131
|
+
* @param metadata - Arbitrary key-value metadata to store alongside the vector.
|
|
132
|
+
*/
|
|
133
|
+
upsert(id: string, vector: number[], metadata: Record<string, unknown>): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Returns the `topK` nearest entries to the query vector.
|
|
136
|
+
*
|
|
137
|
+
* @param vector - Query embedding vector.
|
|
138
|
+
* @param topK - Maximum number of results to return.
|
|
139
|
+
*/
|
|
140
|
+
search(vector: number[], topK: number): Promise<VectorSearchResult[]>;
|
|
141
|
+
/**
|
|
142
|
+
* Removes a single entry by ID.
|
|
143
|
+
* Implementations should be idempotent (no error if the ID does not exist).
|
|
144
|
+
*
|
|
145
|
+
* @param id - The ID that was passed to `upsert`.
|
|
146
|
+
*/
|
|
147
|
+
delete(id: string): Promise<void>;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/context/interfaces.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAMpE;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE5E;;;;;;OAMG;IACH,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACrF;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,UAAU;IACzB,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjE;;;;;;OAMG;IACH,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;CACvE;AAMD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,iBAAiB;IAChC,+DAA+D;IAC/D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;CAC7C;AAMD,8DAA8D;AAC9D,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvF;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAEtE;;;;;OAKG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Engine — Core Interfaces
|
|
3
|
+
*
|
|
4
|
+
* Defines the contracts for the Context Engine and for future AI/embedding
|
|
5
|
+
* adapters. None of these interfaces are coupled to a specific LLM SDK or
|
|
6
|
+
* vector-store implementation.
|
|
7
|
+
*
|
|
8
|
+
* Implementations of AIProvider, EmbeddingProvider and VectorStore are
|
|
9
|
+
* intentionally excluded from the core library and must be provided by
|
|
10
|
+
* downstream packages (e.g. `codebase-intelligence-openai`).
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=interfaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/context/interfaces.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ContextNode } from '../types.js';
|
|
2
|
+
import type { CodebaseFile } from '../../core/types.js';
|
|
3
|
+
import type { SymbolIndex } from '../../index/SymbolIndex.js';
|
|
4
|
+
import { FileContextBuilder } from '../FileContextBuilder.js';
|
|
5
|
+
/**
|
|
6
|
+
* Contract that each context-build strategy must fulfil.
|
|
7
|
+
*
|
|
8
|
+
* A strategy is responsible for converting a target file + its dependency
|
|
9
|
+
* files into an ordered list of `ContextNode`s. The `ContextEngine` owns
|
|
10
|
+
* the budget enforcement and metadata collection; the strategy only decides
|
|
11
|
+
* *how* each file is represented.
|
|
12
|
+
*/
|
|
13
|
+
export interface ContextBuildStrategy {
|
|
14
|
+
/**
|
|
15
|
+
* Builds the ordered list of `ContextNode`s for the payload.
|
|
16
|
+
*
|
|
17
|
+
* @param targetFile - The file the user asked about (always first).
|
|
18
|
+
* @param dependencyFiles - Files directly imported by the target.
|
|
19
|
+
* @param symbolIndex - Symbol index for signature extraction.
|
|
20
|
+
* @param codebaseRoot - Absolute path used for `relativePath` normalisation.
|
|
21
|
+
*/
|
|
22
|
+
buildNodes(targetFile: CodebaseFile, dependencyFiles: CodebaseFile[], symbolIndex: SymbolIndex, codebaseRoot: string): Promise<ContextNode[]>;
|
|
23
|
+
}
|
|
24
|
+
export { FileContextBuilder };
|
|
25
|
+
//# sourceMappingURL=ContextBuildStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextBuildStrategy.d.ts","sourceRoot":"","sources":["../../../src/context/strategies/ContextBuildStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;;;OAOG;IACH,UAAU,CACR,UAAU,EAAE,YAAY,EACxB,eAAe,EAAE,YAAY,EAAE,EAC/B,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;CAC3B;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextBuildStrategy.js","sourceRoot":"","sources":["../../../src/context/strategies/ContextBuildStrategy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AA2B9D,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ContextBuildStrategy } from './ContextBuildStrategy.js';
|
|
2
|
+
import type { ContextNode } from '../types.js';
|
|
3
|
+
import type { CodebaseFile } from '../../core/types.js';
|
|
4
|
+
import type { SymbolIndex } from '../../index/SymbolIndex.js';
|
|
5
|
+
/**
|
|
6
|
+
* `deep` strategy — target file + all dependencies with full source content.
|
|
7
|
+
*
|
|
8
|
+
* Use when the LLM needs the complete implementation context, for example
|
|
9
|
+
* when debugging subtle runtime behaviour or when generating code that must
|
|
10
|
+
* match a specific implementation detail.
|
|
11
|
+
*
|
|
12
|
+
* Token usage is high; pair with a generous `maxTokens` budget.
|
|
13
|
+
*/
|
|
14
|
+
export declare class DeepStrategy implements ContextBuildStrategy {
|
|
15
|
+
private readonly builder;
|
|
16
|
+
buildNodes(targetFile: CodebaseFile, dependencyFiles: CodebaseFile[], _symbolIndex: SymbolIndex, codebaseRoot: string): Promise<ContextNode[]>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=DeepStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeepStrategy.d.ts","sourceRoot":"","sources":["../../../src/context/strategies/DeepStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAG9D;;;;;;;;GAQG;AACH,qBAAa,YAAa,YAAW,oBAAoB;IACvD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;IAEvC,UAAU,CACrB,UAAU,EAAE,YAAY,EACxB,eAAe,EAAE,YAAY,EAAE,EAC/B,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,WAAW,EAAE,CAAC,CAQxB;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FileContextBuilder } from '../FileContextBuilder.js';
|
|
2
|
+
/**
|
|
3
|
+
* `deep` strategy — target file + all dependencies with full source content.
|
|
4
|
+
*
|
|
5
|
+
* Use when the LLM needs the complete implementation context, for example
|
|
6
|
+
* when debugging subtle runtime behaviour or when generating code that must
|
|
7
|
+
* match a specific implementation detail.
|
|
8
|
+
*
|
|
9
|
+
* Token usage is high; pair with a generous `maxTokens` budget.
|
|
10
|
+
*/
|
|
11
|
+
export class DeepStrategy {
|
|
12
|
+
builder = new FileContextBuilder();
|
|
13
|
+
async buildNodes(targetFile, dependencyFiles, _symbolIndex, codebaseRoot) {
|
|
14
|
+
const targetNode = await this.builder.buildFileNode(targetFile, codebaseRoot);
|
|
15
|
+
const depNodes = await Promise.all(dependencyFiles.map(dep => this.builder.buildFileNode(dep, codebaseRoot)));
|
|
16
|
+
return [targetNode, ...depNodes];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=DeepStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeepStrategy.js","sourceRoot":"","sources":["../../../src/context/strategies/DeepStrategy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,OAAO,YAAY;IACN,OAAO,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAE7C,KAAK,CAAC,UAAU,CACrB,UAAwB,EACxB,eAA+B,EAC/B,YAAyB,EACzB,YAAoB;QAEpB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QAE9E,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAChC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAC1E,CAAC;QAEF,OAAO,CAAC,UAAU,EAAE,GAAG,QAAQ,CAAC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ContextBuildStrategy } from './ContextBuildStrategy.js';
|
|
2
|
+
import type { ContextNode } from '../types.js';
|
|
3
|
+
import type { CodebaseFile } from '../../core/types.js';
|
|
4
|
+
import type { SymbolIndex } from '../../index/SymbolIndex.js';
|
|
5
|
+
/**
|
|
6
|
+
* `shallow` strategy — target file only, full content, no dependencies.
|
|
7
|
+
*
|
|
8
|
+
* Use when you want the minimum possible context. Ideal for large files
|
|
9
|
+
* where the LLM should focus exclusively on the file itself.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ShallowStrategy implements ContextBuildStrategy {
|
|
12
|
+
private readonly builder;
|
|
13
|
+
buildNodes(targetFile: CodebaseFile, _dependencyFiles: CodebaseFile[], _symbolIndex: SymbolIndex, codebaseRoot: string): Promise<ContextNode[]>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=ShallowStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShallowStrategy.d.ts","sourceRoot":"","sources":["../../../src/context/strategies/ShallowStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAG9D;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,oBAAoB;IAC1D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;IAEvC,UAAU,CACrB,UAAU,EAAE,YAAY,EACxB,gBAAgB,EAAE,YAAY,EAAE,EAChC,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,WAAW,EAAE,CAAC,CAGxB;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FileContextBuilder } from '../FileContextBuilder.js';
|
|
2
|
+
/**
|
|
3
|
+
* `shallow` strategy — target file only, full content, no dependencies.
|
|
4
|
+
*
|
|
5
|
+
* Use when you want the minimum possible context. Ideal for large files
|
|
6
|
+
* where the LLM should focus exclusively on the file itself.
|
|
7
|
+
*/
|
|
8
|
+
export class ShallowStrategy {
|
|
9
|
+
builder = new FileContextBuilder();
|
|
10
|
+
async buildNodes(targetFile, _dependencyFiles, _symbolIndex, codebaseRoot) {
|
|
11
|
+
const targetNode = await this.builder.buildFileNode(targetFile, codebaseRoot);
|
|
12
|
+
return [targetNode];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=ShallowStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShallowStrategy.js","sourceRoot":"","sources":["../../../src/context/strategies/ShallowStrategy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IACT,OAAO,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAE7C,KAAK,CAAC,UAAU,CACrB,UAAwB,EACxB,gBAAgC,EAChC,YAAyB,EACzB,YAAoB;QAEpB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QAC9E,OAAO,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ContextBuildStrategy } from './ContextBuildStrategy.js';
|
|
2
|
+
import type { ContextNode } from '../types.js';
|
|
3
|
+
import type { CodebaseFile } from '../../core/types.js';
|
|
4
|
+
import type { SymbolIndex } from '../../index/SymbolIndex.js';
|
|
5
|
+
/**
|
|
6
|
+
* `signature` strategy — target file as full content; dependencies as
|
|
7
|
+
* AST-extracted signatures (no implementation bodies).
|
|
8
|
+
*
|
|
9
|
+
* This is the recommended default. It gives the LLM complete type information
|
|
10
|
+
* (parameter types, return types, generics, modifiers) for every dependency
|
|
11
|
+
* without including their implementation details. Typically 60–80 % fewer
|
|
12
|
+
* tokens than `deep` for the same informational value.
|
|
13
|
+
*/
|
|
14
|
+
export declare class SignatureStrategy implements ContextBuildStrategy {
|
|
15
|
+
private readonly builder;
|
|
16
|
+
private readonly extractor;
|
|
17
|
+
buildNodes(targetFile: CodebaseFile, dependencyFiles: CodebaseFile[], _symbolIndex: SymbolIndex, codebaseRoot: string): Promise<ContextNode[]>;
|
|
18
|
+
private buildAstSignatureNode;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=SignatureStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignatureStrategy.d.ts","sourceRoot":"","sources":["../../../src/context/strategies/SignatureStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAI9D;;;;;;;;GAQG;AACH,qBAAa,iBAAkB,YAAW,oBAAoB;IAC5D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;IACpD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4B;IAEzC,UAAU,CACrB,UAAU,EAAE,YAAY,EACxB,eAAe,EAAE,YAAY,EAAE,EAC/B,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,WAAW,EAAE,CAAC,CAgBxB;YAIa,qBAAqB;CAgCpC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { FileContextBuilder, buildNodeId } from '../FileContextBuilder.js';
|
|
2
|
+
import { SignatureExtractor } from '../SignatureExtractor.js';
|
|
3
|
+
/**
|
|
4
|
+
* `signature` strategy — target file as full content; dependencies as
|
|
5
|
+
* AST-extracted signatures (no implementation bodies).
|
|
6
|
+
*
|
|
7
|
+
* This is the recommended default. It gives the LLM complete type information
|
|
8
|
+
* (parameter types, return types, generics, modifiers) for every dependency
|
|
9
|
+
* without including their implementation details. Typically 60–80 % fewer
|
|
10
|
+
* tokens than `deep` for the same informational value.
|
|
11
|
+
*/
|
|
12
|
+
export class SignatureStrategy {
|
|
13
|
+
builder = new FileContextBuilder();
|
|
14
|
+
extractor = new SignatureExtractor();
|
|
15
|
+
async buildNodes(targetFile, dependencyFiles, _symbolIndex, codebaseRoot) {
|
|
16
|
+
const targetNode = await this.builder.buildFileNode(targetFile, codebaseRoot);
|
|
17
|
+
const depNodes = [];
|
|
18
|
+
for (const dep of dependencyFiles) {
|
|
19
|
+
// Only TypeScript/JavaScript files can be processed by ts-morph.
|
|
20
|
+
// JSON and other files fall back to the full-file node.
|
|
21
|
+
if (dep.language === 'typescript' || dep.language === 'javascript') {
|
|
22
|
+
const node = await this.buildAstSignatureNode(dep, codebaseRoot);
|
|
23
|
+
depNodes.push(node);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
depNodes.push(await this.builder.buildFileNode(dep, codebaseRoot));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return [targetNode, ...depNodes];
|
|
30
|
+
}
|
|
31
|
+
// ---- Private helpers -----------------------------------------------------
|
|
32
|
+
async buildAstSignatureNode(file, codebaseRoot) {
|
|
33
|
+
const relativePath = this.builder.resolveRelativePath(file, codebaseRoot);
|
|
34
|
+
let signatureContent;
|
|
35
|
+
try {
|
|
36
|
+
signatureContent = this.extractor.extract(file.path);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// If ts-morph fails (e.g. unsupported syntax), fall back to the full file.
|
|
40
|
+
const fallback = await this.builder.buildFileNode(file, codebaseRoot);
|
|
41
|
+
return fallback;
|
|
42
|
+
}
|
|
43
|
+
// Never produce an empty node — fall back to the full file.
|
|
44
|
+
if (!signatureContent.trim()) {
|
|
45
|
+
return this.builder.buildFileNode(file, codebaseRoot);
|
|
46
|
+
}
|
|
47
|
+
const totalLines = signatureContent.split('\n').length;
|
|
48
|
+
return {
|
|
49
|
+
id: buildNodeId(relativePath, 1, totalLines),
|
|
50
|
+
file: file.path,
|
|
51
|
+
relativePath,
|
|
52
|
+
content: signatureContent,
|
|
53
|
+
kind: 'signature',
|
|
54
|
+
startLine: 1,
|
|
55
|
+
endLine: totalLines,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=SignatureStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignatureStrategy.js","sourceRoot":"","sources":["../../../src/context/strategies/SignatureStrategy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,OAAO,iBAAiB;IACX,OAAO,GAAG,IAAI,kBAAkB,EAAE,CAAC;IACnC,SAAS,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAE/C,KAAK,CAAC,UAAU,CACrB,UAAwB,EACxB,eAA+B,EAC/B,YAAyB,EACzB,YAAoB;QAEpB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QAE9E,MAAM,QAAQ,GAAkB,EAAE,CAAC;QACnC,KAAK,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;YAClC,iEAAiE;YACjE,wDAAwD;YACxD,IAAI,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;gBACnE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;gBACjE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;QAED,OAAO,CAAC,UAAU,EAAE,GAAG,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED,6EAA6E;IAErE,KAAK,CAAC,qBAAqB,CACjC,IAAkB,EAClB,YAAoB;QAEpB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAE1E,IAAI,gBAAwB,CAAC;QAC7B,IAAI,CAAC;YACH,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvD,CAAC;QAAC,MAAM,CAAC;YACP,2EAA2E;YAC3E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;YACtE,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,4DAA4D;QAC5D,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QACxD,CAAC;QAED,MAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;QAEvD,OAAO;YACL,EAAE,EAAE,WAAW,CAAC,YAAY,EAAE,CAAC,EAAE,UAAU,CAAC;YAC5C,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY;YACZ,OAAO,EAAE,gBAAgB;YACzB,IAAI,EAAE,WAAW;YACjB,SAAS,EAAE,CAAC;YACZ,OAAO,EAAE,UAAU;SACpB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ShallowStrategy } from './ShallowStrategy.js';
|
|
2
|
+
export { SignatureStrategy } from './SignatureStrategy.js';
|
|
3
|
+
export { DeepStrategy } from './DeepStrategy.js';
|
|
4
|
+
export type { ContextBuildStrategy } from './ContextBuildStrategy.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/strategies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/context/strategies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Engine — Public Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the data structures produced by the Context Engine. These types are
|
|
5
|
+
* intentionally decoupled from any specific AI provider or LLM SDK.
|
|
6
|
+
*/
|
|
7
|
+
import type { SymbolKind } from '../core/types.js';
|
|
8
|
+
/**
|
|
9
|
+
* The granularity of a single context node.
|
|
10
|
+
*
|
|
11
|
+
* - `file` — the full content of a source file
|
|
12
|
+
* - `class` — a complete class declaration (body included)
|
|
13
|
+
* - `function` — a complete function/arrow-function declaration
|
|
14
|
+
* - `symbol` — any other named declaration (variable, type alias, etc.)
|
|
15
|
+
* - `signature` — the declaration *without* its implementation body;
|
|
16
|
+
* used by the `signature` strategy to save tokens while
|
|
17
|
+
* still conveying type information
|
|
18
|
+
*/
|
|
19
|
+
export type ContextNodeKind = 'file' | 'class' | 'function' | 'symbol' | 'signature';
|
|
20
|
+
/**
|
|
21
|
+
* A self-contained fragment of code with enough metadata for a LLM to reason
|
|
22
|
+
* about its location, role, and relationships inside the codebase.
|
|
23
|
+
*/
|
|
24
|
+
export interface ContextNode {
|
|
25
|
+
/** Unique identifier: `<relativePath>:<startLine>-<endLine>` */
|
|
26
|
+
id: string;
|
|
27
|
+
/** Absolute path to the source file. */
|
|
28
|
+
file: string;
|
|
29
|
+
/** Path relative to the codebase root (preferred for display). */
|
|
30
|
+
relativePath: string;
|
|
31
|
+
/** The raw source code of this fragment. */
|
|
32
|
+
content: string;
|
|
33
|
+
/** Granularity of this node. */
|
|
34
|
+
kind: ContextNodeKind;
|
|
35
|
+
/** 1-based start line in the source file. */
|
|
36
|
+
startLine: number;
|
|
37
|
+
/** 1-based end line in the source file. */
|
|
38
|
+
endLine: number;
|
|
39
|
+
/**
|
|
40
|
+
* Name of the symbol this node represents (when kind ≠ 'file').
|
|
41
|
+
* Matches the name stored in `SymbolIndex`.
|
|
42
|
+
*/
|
|
43
|
+
symbolName?: string;
|
|
44
|
+
/**
|
|
45
|
+
* `SymbolKind` of the symbol this node represents.
|
|
46
|
+
* Omitted when kind === 'file'.
|
|
47
|
+
*/
|
|
48
|
+
symbolKind?: SymbolKind;
|
|
49
|
+
/**
|
|
50
|
+
* ID of the parent `ContextNode` when this node is a method or nested
|
|
51
|
+
* member of a larger declaration (e.g. a method inside a class node).
|
|
52
|
+
*/
|
|
53
|
+
parentId?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The three context-resolution strategies control the trade-off between
|
|
57
|
+
* token usage and information richness.
|
|
58
|
+
*
|
|
59
|
+
* | Strategy | Target file | Dependency content | Tokens |
|
|
60
|
+
* |-------------|-------------|---------------------------------|--------|
|
|
61
|
+
* | `shallow` | full | none | low |
|
|
62
|
+
* | `signature` | full | declaration only (no body, AST) | medium |
|
|
63
|
+
* | `deep` | full | full source | high |
|
|
64
|
+
*
|
|
65
|
+
* `signature` is the recommended default: it preserves all type information
|
|
66
|
+
* (parameter types, return types, generics) without bloating the prompt with
|
|
67
|
+
* implementation details the LLM does not need.
|
|
68
|
+
*/
|
|
69
|
+
export type ContextStrategy = 'shallow' | 'signature' | 'deep';
|
|
70
|
+
/**
|
|
71
|
+
* Options accepted by `ContextEngine.forFile()` and `ContextEngine.forSymbol()`.
|
|
72
|
+
*/
|
|
73
|
+
export interface ContextOptions {
|
|
74
|
+
/**
|
|
75
|
+
* How dependency content is included in the payload.
|
|
76
|
+
* @default 'signature'
|
|
77
|
+
*/
|
|
78
|
+
strategy?: ContextStrategy;
|
|
79
|
+
/**
|
|
80
|
+
* Soft upper bound on the total token estimate of the payload.
|
|
81
|
+
* When the estimate would exceed this value, lower-priority nodes
|
|
82
|
+
* (transitive / indirect dependencies) are dropped first.
|
|
83
|
+
* The target file itself is *never* truncated.
|
|
84
|
+
* @default 8000
|
|
85
|
+
*/
|
|
86
|
+
maxTokens?: number;
|
|
87
|
+
/**
|
|
88
|
+
* Whether to include related test files in the payload.
|
|
89
|
+
* @default false
|
|
90
|
+
*/
|
|
91
|
+
includeTests?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Whether to include files that depend *on* the target (dependents) in
|
|
94
|
+
* addition to the files the target depends *on* (dependencies).
|
|
95
|
+
* Useful when the question is "will my change break callers?".
|
|
96
|
+
* @default false
|
|
97
|
+
*/
|
|
98
|
+
includeDependents?: boolean;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The final structured object delivered to a LLM (or to the caller when
|
|
102
|
+
* used programmatically).
|
|
103
|
+
*
|
|
104
|
+
* `nodes` is ordered: the target node is always first, followed by direct
|
|
105
|
+
* dependencies, then indirect ones, then dependents (if requested).
|
|
106
|
+
*/
|
|
107
|
+
export interface LLMContextPayload {
|
|
108
|
+
/** The file or symbol that was the focus of the context request. */
|
|
109
|
+
target: string;
|
|
110
|
+
/** The strategy used to build this payload. */
|
|
111
|
+
strategy: ContextStrategy;
|
|
112
|
+
/** Ordered list of code fragments to include in the LLM prompt. */
|
|
113
|
+
nodes: ContextNode[];
|
|
114
|
+
/**
|
|
115
|
+
* Rough estimate of the total token count (`totalChars / 4`).
|
|
116
|
+
* This avoids a hard dependency on tokeniser libraries while being
|
|
117
|
+
* accurate enough for budget planning.
|
|
118
|
+
*/
|
|
119
|
+
totalTokenEstimate: number;
|
|
120
|
+
/** Relational metadata derived from the Dependency Graph. */
|
|
121
|
+
metadata: ContextPayloadMetadata;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Relational metadata attached to every `LLMContextPayload`.
|
|
125
|
+
* Gives the LLM (or the caller) a high-level map of how the target
|
|
126
|
+
* fits into the broader codebase without requiring it to read all nodes.
|
|
127
|
+
*/
|
|
128
|
+
export interface ContextPayloadMetadata {
|
|
129
|
+
/** Files directly imported by the target. */
|
|
130
|
+
directDependencies: string[];
|
|
131
|
+
/** Files that directly import the target. */
|
|
132
|
+
directDependents: string[];
|
|
133
|
+
/** Test files related to the target (by naming convention). */
|
|
134
|
+
relatedTests: string[];
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/context/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAMnD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,CAAC;AAErF;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,gEAAgE;IAChE,EAAE,EAAE,MAAM,CAAC;IACX,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,YAAY,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,IAAI,EAAE,eAAe,CAAC;IACtB,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAMD;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,CAAC;AAM/D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAMD;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,QAAQ,EAAE,eAAe,CAAC;IAC1B,mEAAmE;IACnE,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB;;;;OAIG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B,6DAA6D;IAC7D,QAAQ,EAAE,sBAAsB,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,6CAA6C;IAC7C,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,6CAA6C;IAC7C,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,+DAA+D;IAC/D,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/context/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/dist/core/Codebase.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ import type { CodebaseFile, CodeSymbol } from './types.js';
|
|
|
3
3
|
import type { ProjectInfo } from '../discovery/ProjectDetector.js';
|
|
4
4
|
import type { SearchResult, SearchOptions } from '../search/CodeSearch.js';
|
|
5
5
|
import type { ImpactResult } from '../analysis/ImpactAnalyzer.js';
|
|
6
|
+
import { ContextEngine } from '../context/ContextEngine.js';
|
|
7
|
+
import type { SemanticChunk, ChunkerOptions } from '../context/SemanticChunker.js';
|
|
8
|
+
import { CodebaseWithAI } from '../ai/CodebaseWithAI.js';
|
|
9
|
+
import type { AIProvider } from '../context/interfaces.js';
|
|
10
|
+
import type { ChangeSetOptions, ChangeSetProvider, ChangeSetImpact } from '../diff/types.js';
|
|
6
11
|
export interface CodebaseOptions {
|
|
7
12
|
ignore?: string[];
|
|
8
13
|
/** Enable on-disk caching of parse results. Defaults to true. */
|
|
@@ -29,7 +34,52 @@ export declare class Codebase {
|
|
|
29
34
|
dependencies(file: string): string[];
|
|
30
35
|
dependents(file: string): string[];
|
|
31
36
|
impact(file: string): ImpactResult;
|
|
37
|
+
/**
|
|
38
|
+
* Analyzes the impact of a specific list of files without querying a VCS.
|
|
39
|
+
* Treats all given files as 'modified'.
|
|
40
|
+
*
|
|
41
|
+
* @throws if called before `analyze()`.
|
|
42
|
+
*/
|
|
43
|
+
impactOfFiles(paths: string[]): ChangeSetImpact;
|
|
44
|
+
/**
|
|
45
|
+
* Analyzes the impact of a set of changes obtained from a `ChangeSetProvider`.
|
|
46
|
+
* Defaults to querying the local Git repository for changes.
|
|
47
|
+
*
|
|
48
|
+
* @throws if called before `analyze()`.
|
|
49
|
+
*/
|
|
50
|
+
impactOfChanges(options?: ChangeSetOptions, provider?: ChangeSetProvider): Promise<ChangeSetImpact>;
|
|
32
51
|
isAnalyzed(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Returns a `ContextEngine` pre-configured with this codebase's graph,
|
|
54
|
+
* symbol index, and file index.
|
|
55
|
+
*
|
|
56
|
+
* Use the returned engine to build LLM-ready context payloads:
|
|
57
|
+
* ```ts
|
|
58
|
+
* const payload = await codebase.context().forFile('src/auth/AuthService.ts');
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @throws if called before `analyze()`.
|
|
62
|
+
*/
|
|
63
|
+
context(): ContextEngine;
|
|
64
|
+
/**
|
|
65
|
+
* Returns a `CodebaseWithAI` instance that pairs this codebase with the
|
|
66
|
+
* given AI provider, exposing the `explain` and `ask` high-level APIs.
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* const answer = await codebase
|
|
70
|
+
* .withAI(new OpenAIProvider())
|
|
71
|
+
* .ask('Como funciona a autenticação?');
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @throws if called before `analyze()`.
|
|
75
|
+
*/
|
|
76
|
+
withAI(provider: AIProvider): CodebaseWithAI;
|
|
77
|
+
/**
|
|
78
|
+
* Dividir ficheiros em chunks semânticos (baseados em AST, não em caracteres).
|
|
79
|
+
*
|
|
80
|
+
* @throws se chamado antes de `analyze()`.
|
|
81
|
+
*/
|
|
82
|
+
chunks(options?: ChunkerOptions): Promise<SemanticChunk[]>;
|
|
33
83
|
/**
|
|
34
84
|
* Deletes the on-disk cache for this codebase.
|
|
35
85
|
* Subsequent calls to analyze() will re-parse all files.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Codebase.d.ts","sourceRoot":"","sources":["../../src/core/Codebase.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAkB,MAAM,YAAY,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAEnE,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAG3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"Codebase.d.ts","sourceRoot":"","sources":["../../src/core/Codebase.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAkB,MAAM,YAAY,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAEnE,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAG3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAG3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAc,MAAM,kBAAkB,CAAC;AAEzG,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,iEAAiE;IACjE,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,YAAY,CAA4B;IAChD,OAAO,CAAC,UAAU,CAAmB;IACrC,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAA8B;IAE5C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAE1C,OAAO,eAGN;IAID,OAAoB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqBtF;IAIY,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CA2CpC;IAIM,KAAK,IAAI,YAAY,EAAE,CAE7B;IAEM,OAAO,IAAI,UAAU,EAAE,CAE7B;IAEM,WAAW,IAAI,WAAW,GAAG,IAAI,CAEvC;IAEM,KAAK,IAAI,eAAe,CAE9B;IAEM,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,YAAY,EAAE,CAGxE;IAEM,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAE1C;IAEM,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAExC;IAEM,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAExC;IAED;;;;;OAKG;IACI,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,eAAe,CAkBrD;IAED;;;;;OAKG;IACU,eAAe,CAC1B,OAAO,CAAC,EAAE,gBAAgB,EAC1B,QAAQ,CAAC,EAAE,iBAAiB,GAC3B,OAAO,CAAC,eAAe,CAAC,CAuB1B;IAEM,UAAU,IAAI,OAAO,CAE3B;IAED;;;;;;;;;;OAUG;IACI,OAAO,IAAI,aAAa,CAa9B;IAED;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,QAAQ,EAAE,UAAU,GAAG,cAAc,CAQlD;IAED;;;;OAIG;IACU,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAStE;IAED;;;OAGG;IACI,eAAe,IAAI,IAAI,CAG7B;CACF"}
|