@pratik7368patil/anchor-core 0.1.5 → 0.1.7
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/dist/index.d.ts +120 -4
- package/dist/index.js +687 -47
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/db/schema.sql +44 -0
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,35 @@ type WisdomUnit = {
|
|
|
19
19
|
mergedAt?: string;
|
|
20
20
|
confidence: number;
|
|
21
21
|
};
|
|
22
|
+
type CodeFileRecord = {
|
|
23
|
+
repo: string;
|
|
24
|
+
path: string;
|
|
25
|
+
language?: string;
|
|
26
|
+
sizeBytes: number;
|
|
27
|
+
contentHash: string;
|
|
28
|
+
updatedAt: string;
|
|
29
|
+
};
|
|
30
|
+
type CodeChunk = {
|
|
31
|
+
id: string;
|
|
32
|
+
repo: string;
|
|
33
|
+
filePath: string;
|
|
34
|
+
language?: string;
|
|
35
|
+
startLine: number;
|
|
36
|
+
endLine: number;
|
|
37
|
+
sanitizedText: string;
|
|
38
|
+
symbols: string[];
|
|
39
|
+
contentHash: string;
|
|
40
|
+
updatedAt: string;
|
|
41
|
+
};
|
|
42
|
+
type RankedCodeChunk = CodeChunk & {
|
|
43
|
+
score: number;
|
|
44
|
+
scoreParts: {
|
|
45
|
+
filePathMatch: number;
|
|
46
|
+
symbolMatch: number;
|
|
47
|
+
textMatch: number;
|
|
48
|
+
recency: number;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
22
51
|
type PullRequestFile = {
|
|
23
52
|
filename: string;
|
|
24
53
|
patch?: string | null;
|
|
@@ -62,19 +91,37 @@ type PullRequestRecord = {
|
|
|
62
91
|
type FetchPullRequestsProgress = {
|
|
63
92
|
stage: "discovering_pull_requests";
|
|
64
93
|
repo: string;
|
|
65
|
-
|
|
94
|
+
all: boolean;
|
|
95
|
+
limit?: number;
|
|
66
96
|
since?: string;
|
|
97
|
+
} | {
|
|
98
|
+
stage: "scanned_pull_request_page";
|
|
99
|
+
repo: string;
|
|
100
|
+
all: boolean;
|
|
101
|
+
limit?: number;
|
|
102
|
+
scannedPullRequests: number;
|
|
103
|
+
matchedMergedPullRequests: number;
|
|
67
104
|
} | {
|
|
68
105
|
stage: "discovered_pull_requests";
|
|
69
106
|
repo: string;
|
|
107
|
+
all: boolean;
|
|
70
108
|
total: number;
|
|
71
|
-
limit
|
|
109
|
+
limit?: number;
|
|
110
|
+
detailConcurrency: number;
|
|
72
111
|
} | {
|
|
73
112
|
stage: "fetching_pull_request_details";
|
|
74
113
|
repo: string;
|
|
75
114
|
current: number;
|
|
76
115
|
total: number;
|
|
77
116
|
prNumber: number;
|
|
117
|
+
detailConcurrency: number;
|
|
118
|
+
} | {
|
|
119
|
+
stage: "fetched_pull_request_details";
|
|
120
|
+
repo: string;
|
|
121
|
+
current: number;
|
|
122
|
+
total: number;
|
|
123
|
+
prNumber: number;
|
|
124
|
+
detailConcurrency: number;
|
|
78
125
|
};
|
|
79
126
|
type IndexPullRequestsProgress = {
|
|
80
127
|
stage: "indexing_pull_request";
|
|
@@ -90,6 +137,28 @@ type IndexPullRequestsProgress = {
|
|
|
90
137
|
prNumber: number;
|
|
91
138
|
wisdomUnitsCreated: number;
|
|
92
139
|
};
|
|
140
|
+
type CodeIndexProgress = {
|
|
141
|
+
stage: "discovering_code_files";
|
|
142
|
+
repo: string;
|
|
143
|
+
} | {
|
|
144
|
+
stage: "discovered_code_files";
|
|
145
|
+
repo: string;
|
|
146
|
+
files: number;
|
|
147
|
+
skippedFiles: number;
|
|
148
|
+
} | {
|
|
149
|
+
stage: "indexing_code_file";
|
|
150
|
+
repo: string;
|
|
151
|
+
current: number;
|
|
152
|
+
total: number;
|
|
153
|
+
filePath: string;
|
|
154
|
+
} | {
|
|
155
|
+
stage: "indexed_code_file";
|
|
156
|
+
repo: string;
|
|
157
|
+
current: number;
|
|
158
|
+
total: number;
|
|
159
|
+
filePath: string;
|
|
160
|
+
chunks: number;
|
|
161
|
+
};
|
|
93
162
|
type IndexSummary = {
|
|
94
163
|
indexedPrs: number;
|
|
95
164
|
indexedFiles: number;
|
|
@@ -98,6 +167,12 @@ type IndexSummary = {
|
|
|
98
167
|
skippedItems: number;
|
|
99
168
|
databasePath: string;
|
|
100
169
|
};
|
|
170
|
+
type CodeIndexSummary = {
|
|
171
|
+
indexedFiles: number;
|
|
172
|
+
codeChunksCreated: number;
|
|
173
|
+
skippedFiles: number;
|
|
174
|
+
databasePath: string;
|
|
175
|
+
};
|
|
101
176
|
type AnchorContextInput = {
|
|
102
177
|
task: string;
|
|
103
178
|
files?: string[];
|
|
@@ -131,7 +206,10 @@ type IndexStatus = {
|
|
|
131
206
|
fileCount: number;
|
|
132
207
|
commentCount: number;
|
|
133
208
|
wisdomUnitCount: number;
|
|
209
|
+
codeFileCount: number;
|
|
210
|
+
codeChunkCount: number;
|
|
134
211
|
lastSyncTime?: string;
|
|
212
|
+
lastCodeIndexTime?: string;
|
|
135
213
|
githubTokenConfigured: boolean;
|
|
136
214
|
health: "ok" | "missing_database" | "schema_invalid" | "empty_index";
|
|
137
215
|
};
|
|
@@ -215,6 +293,7 @@ declare function upsertPullRequest(db: AnchorDatabase, pr: PullRequestRecord, wi
|
|
|
215
293
|
comments: number;
|
|
216
294
|
wisdom: number;
|
|
217
295
|
};
|
|
296
|
+
declare function replaceCodeIndex(db: AnchorDatabase, repo: string, codeFiles: CodeFileRecord[], codeChunks: CodeChunk[], skippedFiles: number, cwd: string): CodeIndexSummary;
|
|
218
297
|
declare function getIndexStatus(cwd: string, githubTokenConfigured?: boolean, databasePath?: string): IndexStatus;
|
|
219
298
|
|
|
220
299
|
declare const SCHEMA_SQL: string;
|
|
@@ -222,6 +301,37 @@ declare const SCHEMA_SQL: string;
|
|
|
222
301
|
declare function hasHighSignalLanguage(text: string): boolean;
|
|
223
302
|
declare function chunkHistoricalText(text: string, maxChunkLength?: number): string[];
|
|
224
303
|
|
|
304
|
+
type ChunkableCodeFile = CodeFileRecord & {
|
|
305
|
+
content: string;
|
|
306
|
+
};
|
|
307
|
+
declare function extractCodeSymbols(text: string, filePath: string): string[];
|
|
308
|
+
declare function chunkCodeFile(file: ChunkableCodeFile, options?: {
|
|
309
|
+
chunkLines?: number;
|
|
310
|
+
overlapLines?: number;
|
|
311
|
+
}): CodeChunk[];
|
|
312
|
+
|
|
313
|
+
declare const DEFAULT_MAX_CODE_FILE_BYTES: number;
|
|
314
|
+
type DiscoveredCodeFile = CodeFileRecord & {
|
|
315
|
+
absolutePath: string;
|
|
316
|
+
content: string;
|
|
317
|
+
};
|
|
318
|
+
type CodeFileDiscoveryResult = {
|
|
319
|
+
files: DiscoveredCodeFile[];
|
|
320
|
+
skippedFiles: number;
|
|
321
|
+
};
|
|
322
|
+
declare function isHardExcludedCodePath(filePath: string): boolean;
|
|
323
|
+
declare function discoverCodeFiles(cwd: string, repo: string, options?: {
|
|
324
|
+
maxFileBytes?: number;
|
|
325
|
+
}): CodeFileDiscoveryResult;
|
|
326
|
+
|
|
327
|
+
declare function indexCodebase(db: AnchorDatabase, options: {
|
|
328
|
+
cwd: string;
|
|
329
|
+
repo: string;
|
|
330
|
+
maxFileBytes?: number;
|
|
331
|
+
onProgress?: (progress: CodeIndexProgress) => void;
|
|
332
|
+
}): CodeIndexSummary;
|
|
333
|
+
declare function emptyCodeIndexSummary(cwd: string): CodeIndexSummary;
|
|
334
|
+
|
|
225
335
|
declare function categorizeWisdom(text: string): WisdomCategory;
|
|
226
336
|
declare function extractSymbols(text: string, filePaths: string[]): string[];
|
|
227
337
|
declare function extractWisdomUnits(pr: PullRequestRecord): WisdomUnit[];
|
|
@@ -242,11 +352,13 @@ declare function clampMaxResults(value: number | undefined, defaultValue: number
|
|
|
242
352
|
|
|
243
353
|
declare function rankWisdomUnits(db: AnchorDatabase, input: AnchorContextInput | SearchHistoryInput): RankedWisdomUnit[];
|
|
244
354
|
|
|
355
|
+
declare function rankCodeChunks(db: AnchorDatabase, input: AnchorContextInput): RankedCodeChunk[];
|
|
356
|
+
|
|
245
357
|
type FormattedResult = {
|
|
246
358
|
markdown: string;
|
|
247
359
|
metadata: Record<string, unknown>;
|
|
248
360
|
};
|
|
249
|
-
declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput): FormattedResult;
|
|
361
|
+
declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput, codeChunks?: RankedCodeChunk[]): FormattedResult;
|
|
250
362
|
declare function formatSearchHistory(units: RankedWisdomUnit[]): FormattedResult;
|
|
251
363
|
declare function formatIndexStatus(status: IndexStatus): FormattedResult;
|
|
252
364
|
|
|
@@ -256,9 +368,13 @@ type FetchPullRequestsOptions = {
|
|
|
256
368
|
token: string;
|
|
257
369
|
repo: string;
|
|
258
370
|
limit?: number;
|
|
371
|
+
all?: boolean;
|
|
372
|
+
detailConcurrency?: number;
|
|
259
373
|
since?: string;
|
|
260
374
|
onProgress?: (progress: FetchPullRequestsProgress) => void;
|
|
261
375
|
};
|
|
376
|
+
declare function resolvePullRequestFetchLimit(options: Pick<FetchPullRequestsOptions, "all" | "limit">): number | undefined;
|
|
377
|
+
declare function resolvePullRequestDetailConcurrency(options: Pick<FetchPullRequestsOptions, "detailConcurrency">): number;
|
|
262
378
|
declare function fetchMergedPullRequests(options: FetchPullRequestsOptions): Promise<PullRequestRecord[]>;
|
|
263
379
|
|
|
264
380
|
declare function fetchPullRequestDetails(octokit: Octokit, repoFullName: string, pullNumber: number): Promise<PullRequestRecord>;
|
|
@@ -271,4 +387,4 @@ type DoctorOptions = {
|
|
|
271
387
|
};
|
|
272
388
|
declare function runDoctor(options: DoctorOptions): Promise<DoctorReport>;
|
|
273
389
|
|
|
274
|
-
export { ANCHOR_CURSOR_RULE, type AnchorContextInput, type AnchorDatabase, type CursorMcpConfig, type DoctorCheck, type DoctorOptions, type DoctorReport, type FetchPullRequestsOptions, type FetchPullRequestsProgress, type FormattedResult, type GitHubRepo, type GitHubTokenResolution, type GitHubTokenResolverOptions, type GitHubTokenSource, type IndexPullRequestsProgress, type IndexStatus, type IndexSummary, type PullRequestComment, type PullRequestCommit, type PullRequestFile, type PullRequestPerson, type PullRequestRecord, type RankedWisdomUnit, SCHEMA_SQL, type SearchHistoryInput, type SourceType, type WisdomCategory, type WisdomUnit, anchorMcpEntry, buildFtsQuery, canonicalizeText, categorizeWisdom, checkSchema, chunkHistoricalText, clampMaxResults, clipSentence, createGitHubClient, defaultDatabasePath, detectGitHubRepo, detectGitRoot, ensureAnchorGitExclude, ensureCursorConfig, ensureCursorRule, ensureRepository, extractSymbols, extractWisdomUnits, fetchMergedPullRequests, fetchPullRequestDetails, formatAnchorContext, formatIndexStatus, formatSearchHistory, getIndexStatus, getLastSyncTime, githubAuthFixMessage, hasHighSignalLanguage, indexPullRequests, initializeSchema, mergeAnchorMcpConfig, normalizePullRequest, openAnchorDatabase, parseGitHubRemote, rankWisdomUnits, redactSecrets, redactedHistoricalText, resolveGitHubToken, runDoctor, sanitizeHistoricalText, shouldSyncSince, stripPromptInjection, tokenizeSearchText, truncateText, uniqueStrings, updateSyncState, upsertPullRequest };
|
|
390
|
+
export { ANCHOR_CURSOR_RULE, type AnchorContextInput, type AnchorDatabase, type ChunkableCodeFile, type CodeChunk, type CodeFileDiscoveryResult, type CodeFileRecord, type CodeIndexProgress, type CodeIndexSummary, type CursorMcpConfig, DEFAULT_MAX_CODE_FILE_BYTES, type DiscoveredCodeFile, type DoctorCheck, type DoctorOptions, type DoctorReport, type FetchPullRequestsOptions, type FetchPullRequestsProgress, type FormattedResult, type GitHubRepo, type GitHubTokenResolution, type GitHubTokenResolverOptions, type GitHubTokenSource, type IndexPullRequestsProgress, type IndexStatus, type IndexSummary, type PullRequestComment, type PullRequestCommit, type PullRequestFile, type PullRequestPerson, type PullRequestRecord, type RankedCodeChunk, type RankedWisdomUnit, SCHEMA_SQL, type SearchHistoryInput, type SourceType, type WisdomCategory, type WisdomUnit, anchorMcpEntry, buildFtsQuery, canonicalizeText, categorizeWisdom, checkSchema, chunkCodeFile, chunkHistoricalText, clampMaxResults, clipSentence, createGitHubClient, defaultDatabasePath, detectGitHubRepo, detectGitRoot, discoverCodeFiles, emptyCodeIndexSummary, ensureAnchorGitExclude, ensureCursorConfig, ensureCursorRule, ensureRepository, extractCodeSymbols, extractSymbols, extractWisdomUnits, fetchMergedPullRequests, fetchPullRequestDetails, formatAnchorContext, formatIndexStatus, formatSearchHistory, getIndexStatus, getLastSyncTime, githubAuthFixMessage, hasHighSignalLanguage, indexCodebase, indexPullRequests, initializeSchema, isHardExcludedCodePath, mergeAnchorMcpConfig, normalizePullRequest, openAnchorDatabase, parseGitHubRemote, rankCodeChunks, rankWisdomUnits, redactSecrets, redactedHistoricalText, replaceCodeIndex, resolveGitHubToken, resolvePullRequestDetailConcurrency, resolvePullRequestFetchLimit, runDoctor, sanitizeHistoricalText, shouldSyncSince, stripPromptInjection, tokenizeSearchText, truncateText, uniqueStrings, updateSyncState, upsertPullRequest };
|