@pratik7368patil/anchor-core 0.1.6 → 0.1.8
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 +189 -3
- package/dist/index.js +1195 -65
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/db/schema.sql +47 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,16 @@ import { Octokit } from '@octokit/rest';
|
|
|
3
3
|
|
|
4
4
|
type SourceType = "pr_body" | "review_comment" | "issue_comment" | "review_summary" | "commit_message" | "diff_context";
|
|
5
5
|
type WisdomCategory = "architecture_decision" | "constraint" | "rejected_approach" | "bug_regression" | "testing_rule" | "api_contract" | "performance_note" | "security_note" | "style_convention" | "unknown";
|
|
6
|
+
type ConfidenceLevel = "strong" | "moderate" | "weak";
|
|
7
|
+
type FreshnessStatus = "current" | "possibly_stale" | "stale";
|
|
8
|
+
type EvidenceRef = {
|
|
9
|
+
prNumber: number;
|
|
10
|
+
prUrl: string;
|
|
11
|
+
sourceType: SourceType;
|
|
12
|
+
author?: string;
|
|
13
|
+
filePath?: string;
|
|
14
|
+
note?: string;
|
|
15
|
+
};
|
|
6
16
|
type WisdomUnit = {
|
|
7
17
|
id: string;
|
|
8
18
|
repo: string;
|
|
@@ -19,6 +29,51 @@ type WisdomUnit = {
|
|
|
19
29
|
mergedAt?: string;
|
|
20
30
|
confidence: number;
|
|
21
31
|
};
|
|
32
|
+
type CodeFileRecord = {
|
|
33
|
+
repo: string;
|
|
34
|
+
path: string;
|
|
35
|
+
language?: string;
|
|
36
|
+
sizeBytes: number;
|
|
37
|
+
contentHash: string;
|
|
38
|
+
updatedAt: string;
|
|
39
|
+
};
|
|
40
|
+
type CodeChunk = {
|
|
41
|
+
id: string;
|
|
42
|
+
repo: string;
|
|
43
|
+
filePath: string;
|
|
44
|
+
language?: string;
|
|
45
|
+
startLine: number;
|
|
46
|
+
endLine: number;
|
|
47
|
+
sanitizedText: string;
|
|
48
|
+
symbols: string[];
|
|
49
|
+
contentHash: string;
|
|
50
|
+
updatedAt: string;
|
|
51
|
+
};
|
|
52
|
+
type RankedCodeChunk = CodeChunk & {
|
|
53
|
+
score: number;
|
|
54
|
+
scoreParts: {
|
|
55
|
+
filePathMatch: number;
|
|
56
|
+
symbolMatch: number;
|
|
57
|
+
textMatch: number;
|
|
58
|
+
recency: number;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
type TeamRule = {
|
|
62
|
+
id: string;
|
|
63
|
+
category: WisdomCategory;
|
|
64
|
+
text: string;
|
|
65
|
+
sanitizedText: string;
|
|
66
|
+
filePaths: string[];
|
|
67
|
+
symbols: string[];
|
|
68
|
+
evidence: EvidenceRef[];
|
|
69
|
+
confidenceLevel: ConfidenceLevel;
|
|
70
|
+
};
|
|
71
|
+
type RankedTeamRule = TeamRule & {
|
|
72
|
+
score: number;
|
|
73
|
+
freshnessStatus: FreshnessStatus;
|
|
74
|
+
freshnessReason: string;
|
|
75
|
+
confidenceReasons: string[];
|
|
76
|
+
};
|
|
22
77
|
type PullRequestFile = {
|
|
23
78
|
filename: string;
|
|
24
79
|
patch?: string | null;
|
|
@@ -108,6 +163,28 @@ type IndexPullRequestsProgress = {
|
|
|
108
163
|
prNumber: number;
|
|
109
164
|
wisdomUnitsCreated: number;
|
|
110
165
|
};
|
|
166
|
+
type CodeIndexProgress = {
|
|
167
|
+
stage: "discovering_code_files";
|
|
168
|
+
repo: string;
|
|
169
|
+
} | {
|
|
170
|
+
stage: "discovered_code_files";
|
|
171
|
+
repo: string;
|
|
172
|
+
files: number;
|
|
173
|
+
skippedFiles: number;
|
|
174
|
+
} | {
|
|
175
|
+
stage: "indexing_code_file";
|
|
176
|
+
repo: string;
|
|
177
|
+
current: number;
|
|
178
|
+
total: number;
|
|
179
|
+
filePath: string;
|
|
180
|
+
} | {
|
|
181
|
+
stage: "indexed_code_file";
|
|
182
|
+
repo: string;
|
|
183
|
+
current: number;
|
|
184
|
+
total: number;
|
|
185
|
+
filePath: string;
|
|
186
|
+
chunks: number;
|
|
187
|
+
};
|
|
111
188
|
type IndexSummary = {
|
|
112
189
|
indexedPrs: number;
|
|
113
190
|
indexedFiles: number;
|
|
@@ -116,6 +193,12 @@ type IndexSummary = {
|
|
|
116
193
|
skippedItems: number;
|
|
117
194
|
databasePath: string;
|
|
118
195
|
};
|
|
196
|
+
type CodeIndexSummary = {
|
|
197
|
+
indexedFiles: number;
|
|
198
|
+
codeChunksCreated: number;
|
|
199
|
+
skippedFiles: number;
|
|
200
|
+
databasePath: string;
|
|
201
|
+
};
|
|
119
202
|
type AnchorContextInput = {
|
|
120
203
|
task: string;
|
|
121
204
|
files?: string[];
|
|
@@ -123,6 +206,8 @@ type AnchorContextInput = {
|
|
|
123
206
|
diff?: string;
|
|
124
207
|
currentCode?: string;
|
|
125
208
|
maxResults?: number;
|
|
209
|
+
strict?: boolean;
|
|
210
|
+
minConfidence?: ConfidenceLevel;
|
|
126
211
|
};
|
|
127
212
|
type SearchHistoryInput = {
|
|
128
213
|
query: string;
|
|
@@ -141,6 +226,13 @@ type RankedWisdomUnit = WisdomUnit & {
|
|
|
141
226
|
categoryPriority: number;
|
|
142
227
|
};
|
|
143
228
|
duplicateCount: number;
|
|
229
|
+
claimKey: string;
|
|
230
|
+
repeatedEvidenceCount: number;
|
|
231
|
+
confidenceLevel: ConfidenceLevel;
|
|
232
|
+
confidenceReasons: string[];
|
|
233
|
+
freshnessStatus: FreshnessStatus;
|
|
234
|
+
freshnessReason: string;
|
|
235
|
+
evidence: EvidenceRef;
|
|
144
236
|
};
|
|
145
237
|
type IndexStatus = {
|
|
146
238
|
repo?: string;
|
|
@@ -149,7 +241,15 @@ type IndexStatus = {
|
|
|
149
241
|
fileCount: number;
|
|
150
242
|
commentCount: number;
|
|
151
243
|
wisdomUnitCount: number;
|
|
244
|
+
codeFileCount: number;
|
|
245
|
+
codeChunkCount: number;
|
|
246
|
+
historyCoverage?: "limited" | "all" | "unknown";
|
|
247
|
+
historyLimit?: number;
|
|
248
|
+
staleEvidenceCount: number;
|
|
249
|
+
teamRuleCount: number;
|
|
152
250
|
lastSyncTime?: string;
|
|
251
|
+
lastCodeIndexTime?: string;
|
|
252
|
+
lastRuleIndexTime?: string;
|
|
153
253
|
githubTokenConfigured: boolean;
|
|
154
254
|
health: "ok" | "missing_database" | "schema_invalid" | "empty_index";
|
|
155
255
|
};
|
|
@@ -227,12 +327,17 @@ declare function initializeSchema(db: AnchorDatabase): void;
|
|
|
227
327
|
declare function checkSchema(db: AnchorDatabase): boolean;
|
|
228
328
|
declare function ensureRepository(db: AnchorDatabase, fullName: string): number;
|
|
229
329
|
declare function getLastSyncTime(db: AnchorDatabase, repo: string): string | undefined;
|
|
230
|
-
declare function updateSyncState(db: AnchorDatabase, repo: string, lastIndexedPr?: number
|
|
330
|
+
declare function updateSyncState(db: AnchorDatabase, repo: string, lastIndexedPr?: number, metadata?: {
|
|
331
|
+
historyCoverage?: "limited" | "all" | "unknown";
|
|
332
|
+
historyLimit?: number;
|
|
333
|
+
historySince?: string;
|
|
334
|
+
}): void;
|
|
231
335
|
declare function upsertPullRequest(db: AnchorDatabase, pr: PullRequestRecord, wisdomUnits: WisdomUnit[]): {
|
|
232
336
|
files: number;
|
|
233
337
|
comments: number;
|
|
234
338
|
wisdom: number;
|
|
235
339
|
};
|
|
340
|
+
declare function replaceCodeIndex(db: AnchorDatabase, repo: string, codeFiles: CodeFileRecord[], codeChunks: CodeChunk[], skippedFiles: number, cwd: string): CodeIndexSummary;
|
|
236
341
|
declare function getIndexStatus(cwd: string, githubTokenConfigured?: boolean, databasePath?: string): IndexStatus;
|
|
237
342
|
|
|
238
343
|
declare const SCHEMA_SQL: string;
|
|
@@ -240,6 +345,37 @@ declare const SCHEMA_SQL: string;
|
|
|
240
345
|
declare function hasHighSignalLanguage(text: string): boolean;
|
|
241
346
|
declare function chunkHistoricalText(text: string, maxChunkLength?: number): string[];
|
|
242
347
|
|
|
348
|
+
type ChunkableCodeFile = CodeFileRecord & {
|
|
349
|
+
content: string;
|
|
350
|
+
};
|
|
351
|
+
declare function extractCodeSymbols(text: string, filePath: string): string[];
|
|
352
|
+
declare function chunkCodeFile(file: ChunkableCodeFile, options?: {
|
|
353
|
+
chunkLines?: number;
|
|
354
|
+
overlapLines?: number;
|
|
355
|
+
}): CodeChunk[];
|
|
356
|
+
|
|
357
|
+
declare const DEFAULT_MAX_CODE_FILE_BYTES: number;
|
|
358
|
+
type DiscoveredCodeFile = CodeFileRecord & {
|
|
359
|
+
absolutePath: string;
|
|
360
|
+
content: string;
|
|
361
|
+
};
|
|
362
|
+
type CodeFileDiscoveryResult = {
|
|
363
|
+
files: DiscoveredCodeFile[];
|
|
364
|
+
skippedFiles: number;
|
|
365
|
+
};
|
|
366
|
+
declare function isHardExcludedCodePath(filePath: string): boolean;
|
|
367
|
+
declare function discoverCodeFiles(cwd: string, repo: string, options?: {
|
|
368
|
+
maxFileBytes?: number;
|
|
369
|
+
}): CodeFileDiscoveryResult;
|
|
370
|
+
|
|
371
|
+
declare function indexCodebase(db: AnchorDatabase, options: {
|
|
372
|
+
cwd: string;
|
|
373
|
+
repo: string;
|
|
374
|
+
maxFileBytes?: number;
|
|
375
|
+
onProgress?: (progress: CodeIndexProgress) => void;
|
|
376
|
+
}): CodeIndexSummary;
|
|
377
|
+
declare function emptyCodeIndexSummary(cwd: string): CodeIndexSummary;
|
|
378
|
+
|
|
243
379
|
declare function categorizeWisdom(text: string): WisdomCategory;
|
|
244
380
|
declare function extractSymbols(text: string, filePaths: string[]): string[];
|
|
245
381
|
declare function extractWisdomUnits(pr: PullRequestRecord): WisdomUnit[];
|
|
@@ -250,6 +386,9 @@ declare function indexPullRequests(db: AnchorDatabase, pullRequests: PullRequest
|
|
|
250
386
|
cwd: string;
|
|
251
387
|
repo: string;
|
|
252
388
|
updateSyncStateAfter?: boolean;
|
|
389
|
+
historyCoverage?: "limited" | "all" | "unknown";
|
|
390
|
+
historyLimit?: number;
|
|
391
|
+
historySince?: string;
|
|
253
392
|
onProgress?: (progress: IndexPullRequestsProgress) => void;
|
|
254
393
|
}): IndexSummary;
|
|
255
394
|
|
|
@@ -260,14 +399,61 @@ declare function clampMaxResults(value: number | undefined, defaultValue: number
|
|
|
260
399
|
|
|
261
400
|
declare function rankWisdomUnits(db: AnchorDatabase, input: AnchorContextInput | SearchHistoryInput): RankedWisdomUnit[];
|
|
262
401
|
|
|
402
|
+
declare function rankCodeChunks(db: AnchorDatabase, input: AnchorContextInput): RankedCodeChunk[];
|
|
403
|
+
|
|
404
|
+
type CurrentCodeSnapshot = {
|
|
405
|
+
hasCodeIndex: boolean;
|
|
406
|
+
filePaths: Set<string>;
|
|
407
|
+
symbolsByFile: Map<string, Set<string>>;
|
|
408
|
+
allSymbols: Set<string>;
|
|
409
|
+
};
|
|
410
|
+
type FreshnessResult = {
|
|
411
|
+
status: FreshnessStatus;
|
|
412
|
+
reason: string;
|
|
413
|
+
};
|
|
414
|
+
declare function claimKeyFor(category: WisdomCategory, sanitizedText: string): string;
|
|
415
|
+
declare function confidenceLevelFor(confidence: number): ConfidenceLevel;
|
|
416
|
+
declare function confidenceRank(level: ConfidenceLevel): number;
|
|
417
|
+
declare function confidenceAtLeast(level: ConfidenceLevel, minimum: ConfidenceLevel): boolean;
|
|
418
|
+
declare function evidenceForWisdom(unit: WisdomUnit): EvidenceRef;
|
|
419
|
+
declare function confidenceReasonsFor(unit: WisdomUnit, repeatedEvidenceCount: number): string[];
|
|
420
|
+
declare function sourceTypeLabel(sourceType: SourceType): string;
|
|
421
|
+
declare function loadCurrentCodeSnapshot(db: AnchorDatabase): CurrentCodeSnapshot;
|
|
422
|
+
declare function evaluateFreshness(subject: {
|
|
423
|
+
filePaths: string[];
|
|
424
|
+
symbols: string[];
|
|
425
|
+
}, snapshot: CurrentCodeSnapshot): FreshnessResult;
|
|
426
|
+
|
|
263
427
|
type FormattedResult = {
|
|
264
428
|
markdown: string;
|
|
265
429
|
metadata: Record<string, unknown>;
|
|
266
430
|
};
|
|
267
|
-
declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput): FormattedResult;
|
|
431
|
+
declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput, codeChunks?: RankedCodeChunk[], teamRules?: RankedTeamRule[], warnings?: string[]): FormattedResult;
|
|
268
432
|
declare function formatSearchHistory(units: RankedWisdomUnit[]): FormattedResult;
|
|
269
433
|
declare function formatIndexStatus(status: IndexStatus): FormattedResult;
|
|
270
434
|
|
|
435
|
+
declare const TEAM_RULES_FILE = "anchor.rules.json";
|
|
436
|
+
type TeamRulesValidationResult = {
|
|
437
|
+
ok: boolean;
|
|
438
|
+
path: string;
|
|
439
|
+
errors: string[];
|
|
440
|
+
rules: TeamRule[];
|
|
441
|
+
};
|
|
442
|
+
type RulesInitResult = {
|
|
443
|
+
path: string;
|
|
444
|
+
created: boolean;
|
|
445
|
+
};
|
|
446
|
+
declare function ensureTeamRulesFile(cwd: string): RulesInitResult;
|
|
447
|
+
declare function loadTeamRulesFile(cwd: string): TeamRulesValidationResult & {
|
|
448
|
+
exists: boolean;
|
|
449
|
+
};
|
|
450
|
+
declare function validateTeamRulesFile(cwd: string): TeamRulesValidationResult;
|
|
451
|
+
declare function rankTeamRules(db: AnchorDatabase, cwd: string, input: AnchorContextInput): RankedTeamRule[];
|
|
452
|
+
declare function countValidTeamRules(cwd: string): {
|
|
453
|
+
count: number;
|
|
454
|
+
lastRuleIndexTime?: string;
|
|
455
|
+
};
|
|
456
|
+
|
|
271
457
|
declare function createGitHubClient(token: string): Octokit;
|
|
272
458
|
|
|
273
459
|
type FetchPullRequestsOptions = {
|
|
@@ -293,4 +479,4 @@ type DoctorOptions = {
|
|
|
293
479
|
};
|
|
294
480
|
declare function runDoctor(options: DoctorOptions): Promise<DoctorReport>;
|
|
295
481
|
|
|
296
|
-
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, resolvePullRequestDetailConcurrency, resolvePullRequestFetchLimit, runDoctor, sanitizeHistoricalText, shouldSyncSince, stripPromptInjection, tokenizeSearchText, truncateText, uniqueStrings, updateSyncState, upsertPullRequest };
|
|
482
|
+
export { ANCHOR_CURSOR_RULE, type AnchorContextInput, type AnchorDatabase, type ChunkableCodeFile, type CodeChunk, type CodeFileDiscoveryResult, type CodeFileRecord, type CodeIndexProgress, type CodeIndexSummary, type ConfidenceLevel, type CurrentCodeSnapshot, type CursorMcpConfig, DEFAULT_MAX_CODE_FILE_BYTES, type DiscoveredCodeFile, type DoctorCheck, type DoctorOptions, type DoctorReport, type EvidenceRef, type FetchPullRequestsOptions, type FetchPullRequestsProgress, type FormattedResult, type FreshnessResult, type FreshnessStatus, 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 RankedTeamRule, type RankedWisdomUnit, type RulesInitResult, SCHEMA_SQL, type SearchHistoryInput, type SourceType, TEAM_RULES_FILE, type TeamRule, type TeamRulesValidationResult, type WisdomCategory, type WisdomUnit, anchorMcpEntry, buildFtsQuery, canonicalizeText, categorizeWisdom, checkSchema, chunkCodeFile, chunkHistoricalText, claimKeyFor, clampMaxResults, clipSentence, confidenceAtLeast, confidenceLevelFor, confidenceRank, confidenceReasonsFor, countValidTeamRules, createGitHubClient, defaultDatabasePath, detectGitHubRepo, detectGitRoot, discoverCodeFiles, emptyCodeIndexSummary, ensureAnchorGitExclude, ensureCursorConfig, ensureCursorRule, ensureRepository, ensureTeamRulesFile, evaluateFreshness, evidenceForWisdom, extractCodeSymbols, extractSymbols, extractWisdomUnits, fetchMergedPullRequests, fetchPullRequestDetails, formatAnchorContext, formatIndexStatus, formatSearchHistory, getIndexStatus, getLastSyncTime, githubAuthFixMessage, hasHighSignalLanguage, indexCodebase, indexPullRequests, initializeSchema, isHardExcludedCodePath, loadCurrentCodeSnapshot, loadTeamRulesFile, mergeAnchorMcpConfig, normalizePullRequest, openAnchorDatabase, parseGitHubRemote, rankCodeChunks, rankTeamRules, rankWisdomUnits, redactSecrets, redactedHistoricalText, replaceCodeIndex, resolveGitHubToken, resolvePullRequestDetailConcurrency, resolvePullRequestFetchLimit, runDoctor, sanitizeHistoricalText, shouldSyncSince, sourceTypeLabel, stripPromptInjection, tokenizeSearchText, truncateText, uniqueStrings, updateSyncState, upsertPullRequest, validateTeamRulesFile };
|