@pratik7368patil/anchor-core 0.1.7 → 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 +95 -3
- package/dist/index.js +631 -81
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/db/schema.sql +3 -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;
|
|
@@ -48,6 +58,22 @@ type RankedCodeChunk = CodeChunk & {
|
|
|
48
58
|
recency: number;
|
|
49
59
|
};
|
|
50
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
|
+
};
|
|
51
77
|
type PullRequestFile = {
|
|
52
78
|
filename: string;
|
|
53
79
|
patch?: string | null;
|
|
@@ -180,6 +206,8 @@ type AnchorContextInput = {
|
|
|
180
206
|
diff?: string;
|
|
181
207
|
currentCode?: string;
|
|
182
208
|
maxResults?: number;
|
|
209
|
+
strict?: boolean;
|
|
210
|
+
minConfidence?: ConfidenceLevel;
|
|
183
211
|
};
|
|
184
212
|
type SearchHistoryInput = {
|
|
185
213
|
query: string;
|
|
@@ -198,6 +226,13 @@ type RankedWisdomUnit = WisdomUnit & {
|
|
|
198
226
|
categoryPriority: number;
|
|
199
227
|
};
|
|
200
228
|
duplicateCount: number;
|
|
229
|
+
claimKey: string;
|
|
230
|
+
repeatedEvidenceCount: number;
|
|
231
|
+
confidenceLevel: ConfidenceLevel;
|
|
232
|
+
confidenceReasons: string[];
|
|
233
|
+
freshnessStatus: FreshnessStatus;
|
|
234
|
+
freshnessReason: string;
|
|
235
|
+
evidence: EvidenceRef;
|
|
201
236
|
};
|
|
202
237
|
type IndexStatus = {
|
|
203
238
|
repo?: string;
|
|
@@ -208,8 +243,13 @@ type IndexStatus = {
|
|
|
208
243
|
wisdomUnitCount: number;
|
|
209
244
|
codeFileCount: number;
|
|
210
245
|
codeChunkCount: number;
|
|
246
|
+
historyCoverage?: "limited" | "all" | "unknown";
|
|
247
|
+
historyLimit?: number;
|
|
248
|
+
staleEvidenceCount: number;
|
|
249
|
+
teamRuleCount: number;
|
|
211
250
|
lastSyncTime?: string;
|
|
212
251
|
lastCodeIndexTime?: string;
|
|
252
|
+
lastRuleIndexTime?: string;
|
|
213
253
|
githubTokenConfigured: boolean;
|
|
214
254
|
health: "ok" | "missing_database" | "schema_invalid" | "empty_index";
|
|
215
255
|
};
|
|
@@ -287,7 +327,11 @@ declare function initializeSchema(db: AnchorDatabase): void;
|
|
|
287
327
|
declare function checkSchema(db: AnchorDatabase): boolean;
|
|
288
328
|
declare function ensureRepository(db: AnchorDatabase, fullName: string): number;
|
|
289
329
|
declare function getLastSyncTime(db: AnchorDatabase, repo: string): string | undefined;
|
|
290
|
-
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;
|
|
291
335
|
declare function upsertPullRequest(db: AnchorDatabase, pr: PullRequestRecord, wisdomUnits: WisdomUnit[]): {
|
|
292
336
|
files: number;
|
|
293
337
|
comments: number;
|
|
@@ -342,6 +386,9 @@ declare function indexPullRequests(db: AnchorDatabase, pullRequests: PullRequest
|
|
|
342
386
|
cwd: string;
|
|
343
387
|
repo: string;
|
|
344
388
|
updateSyncStateAfter?: boolean;
|
|
389
|
+
historyCoverage?: "limited" | "all" | "unknown";
|
|
390
|
+
historyLimit?: number;
|
|
391
|
+
historySince?: string;
|
|
345
392
|
onProgress?: (progress: IndexPullRequestsProgress) => void;
|
|
346
393
|
}): IndexSummary;
|
|
347
394
|
|
|
@@ -354,14 +401,59 @@ declare function rankWisdomUnits(db: AnchorDatabase, input: AnchorContextInput |
|
|
|
354
401
|
|
|
355
402
|
declare function rankCodeChunks(db: AnchorDatabase, input: AnchorContextInput): RankedCodeChunk[];
|
|
356
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
|
+
|
|
357
427
|
type FormattedResult = {
|
|
358
428
|
markdown: string;
|
|
359
429
|
metadata: Record<string, unknown>;
|
|
360
430
|
};
|
|
361
|
-
declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput, codeChunks?: RankedCodeChunk[]): FormattedResult;
|
|
431
|
+
declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput, codeChunks?: RankedCodeChunk[], teamRules?: RankedTeamRule[], warnings?: string[]): FormattedResult;
|
|
362
432
|
declare function formatSearchHistory(units: RankedWisdomUnit[]): FormattedResult;
|
|
363
433
|
declare function formatIndexStatus(status: IndexStatus): FormattedResult;
|
|
364
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
|
+
|
|
365
457
|
declare function createGitHubClient(token: string): Octokit;
|
|
366
458
|
|
|
367
459
|
type FetchPullRequestsOptions = {
|
|
@@ -387,4 +479,4 @@ type DoctorOptions = {
|
|
|
387
479
|
};
|
|
388
480
|
declare function runDoctor(options: DoctorOptions): Promise<DoctorReport>;
|
|
389
481
|
|
|
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 };
|
|
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 };
|