@pratik7368patil/anchor-core 0.1.7 → 0.1.9

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 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;
@@ -47,6 +57,26 @@ type RankedCodeChunk = CodeChunk & {
47
57
  textMatch: number;
48
58
  recency: number;
49
59
  };
60
+ matchReasons: string[];
61
+ rankSignals: Record<string, number>;
62
+ };
63
+ type TeamRule = {
64
+ id: string;
65
+ category: WisdomCategory;
66
+ text: string;
67
+ sanitizedText: string;
68
+ filePaths: string[];
69
+ symbols: string[];
70
+ evidence: EvidenceRef[];
71
+ confidenceLevel: ConfidenceLevel;
72
+ };
73
+ type RankedTeamRule = TeamRule & {
74
+ score: number;
75
+ freshnessStatus: FreshnessStatus;
76
+ freshnessReason: string;
77
+ confidenceReasons: string[];
78
+ matchReasons: string[];
79
+ rankSignals: Record<string, number>;
50
80
  };
51
81
  type PullRequestFile = {
52
82
  filename: string;
@@ -88,6 +118,49 @@ type PullRequestRecord = {
88
118
  issueComments?: PullRequestComment[];
89
119
  commits?: PullRequestCommit[];
90
120
  };
121
+ type TestFileRecord = {
122
+ repo: string;
123
+ path: string;
124
+ language?: string;
125
+ sizeBytes: number;
126
+ contentHash: string;
127
+ updatedAt: string;
128
+ };
129
+ type TestLink = {
130
+ repo: string;
131
+ sourcePath: string;
132
+ testPath: string;
133
+ reason: string;
134
+ strength: number;
135
+ };
136
+ type RankedTestFile = TestFileRecord & {
137
+ sourcePath?: string;
138
+ reason: string;
139
+ strength: number;
140
+ score: number;
141
+ matchedSymbols: string[];
142
+ };
143
+ type RegressionEvent = {
144
+ id: string;
145
+ repo: string;
146
+ prNumber: number;
147
+ prUrl: string;
148
+ summary: string;
149
+ filePaths: string[];
150
+ symbols: string[];
151
+ testPaths: string[];
152
+ authors: string[];
153
+ labels: string[];
154
+ signals: string[];
155
+ createdAt: string;
156
+ mergedAt?: string;
157
+ confidence: number;
158
+ };
159
+ type RankedRegressionEvent = RegressionEvent & {
160
+ score: number;
161
+ matchReasons: string[];
162
+ rankSignals: Record<string, number>;
163
+ };
91
164
  type FetchPullRequestsProgress = {
92
165
  stage: "discovering_pull_requests";
93
166
  repo: string;
@@ -164,12 +237,15 @@ type IndexSummary = {
164
237
  indexedFiles: number;
165
238
  indexedComments: number;
166
239
  wisdomUnitsCreated: number;
240
+ regressionEventsCreated: number;
167
241
  skippedItems: number;
168
242
  databasePath: string;
169
243
  };
170
244
  type CodeIndexSummary = {
171
245
  indexedFiles: number;
172
246
  codeChunksCreated: number;
247
+ testFilesIndexed: number;
248
+ testLinksCreated: number;
173
249
  skippedFiles: number;
174
250
  databasePath: string;
175
251
  };
@@ -180,11 +256,14 @@ type AnchorContextInput = {
180
256
  diff?: string;
181
257
  currentCode?: string;
182
258
  maxResults?: number;
259
+ strict?: boolean;
260
+ minConfidence?: ConfidenceLevel;
183
261
  };
184
262
  type SearchHistoryInput = {
185
263
  query: string;
186
264
  files?: string[];
187
265
  categories?: WisdomCategory[];
266
+ regressionsOnly?: boolean;
188
267
  maxResults?: number;
189
268
  };
190
269
  type RankedWisdomUnit = WisdomUnit & {
@@ -198,6 +277,58 @@ type RankedWisdomUnit = WisdomUnit & {
198
277
  categoryPriority: number;
199
278
  };
200
279
  duplicateCount: number;
280
+ claimKey: string;
281
+ repeatedEvidenceCount: number;
282
+ confidenceLevel: ConfidenceLevel;
283
+ confidenceReasons: string[];
284
+ freshnessStatus: FreshnessStatus;
285
+ freshnessReason: string;
286
+ evidence: EvidenceRef;
287
+ matchReasons: string[];
288
+ rankSignals: Record<string, number>;
289
+ };
290
+ type AnchorExplainFileInput = {
291
+ file: string;
292
+ symbols?: string[];
293
+ strict?: boolean;
294
+ maxResults?: number;
295
+ };
296
+ type AnchorReviewDiffInput = {
297
+ diff: string;
298
+ files?: string[];
299
+ strict?: boolean;
300
+ maxResults?: number;
301
+ };
302
+ type IndexRunRecord = {
303
+ id?: number;
304
+ command: string;
305
+ repo?: string;
306
+ startedAt: string;
307
+ finishedAt?: string;
308
+ historyCoverage?: "limited" | "all" | "unknown";
309
+ historyLimit?: number;
310
+ prsFetched?: number;
311
+ prsSkipped?: number;
312
+ commentsIndexed?: number;
313
+ codeFilesIndexed?: number;
314
+ testFilesIndexed?: number;
315
+ failures?: string[];
316
+ status: "success" | "failed";
317
+ };
318
+ type AnchorIndexHealth = {
319
+ status: "ok" | "warning" | "error";
320
+ warnings: string[];
321
+ suggestedNextCommand?: string;
322
+ historyCoverage: "limited" | "all" | "unknown";
323
+ staleCodeIndex: boolean;
324
+ lastSuccessfulRun?: string;
325
+ lastFailedRun?: string;
326
+ };
327
+ type SemanticStatus = {
328
+ enabled: boolean;
329
+ mode: "disabled" | "local";
330
+ available: boolean;
331
+ reason: string;
201
332
  };
202
333
  type IndexStatus = {
203
334
  repo?: string;
@@ -208,8 +339,20 @@ type IndexStatus = {
208
339
  wisdomUnitCount: number;
209
340
  codeFileCount: number;
210
341
  codeChunkCount: number;
342
+ testFileCount: number;
343
+ testLinkCount: number;
344
+ regressionEventCount: number;
345
+ historyCoverage?: "limited" | "all" | "unknown";
346
+ historyLimit?: number;
347
+ staleEvidenceCount: number;
348
+ teamRuleCount: number;
211
349
  lastSyncTime?: string;
212
350
  lastCodeIndexTime?: string;
351
+ lastRuleIndexTime?: string;
352
+ lastSuccessfulRun?: string;
353
+ lastFailedRun?: string;
354
+ staleCodeIndex?: boolean;
355
+ suggestedNextCommand?: string;
213
356
  githubTokenConfigured: boolean;
214
357
  health: "ok" | "missing_database" | "schema_invalid" | "empty_index";
215
358
  };
@@ -287,13 +430,19 @@ declare function initializeSchema(db: AnchorDatabase): void;
287
430
  declare function checkSchema(db: AnchorDatabase): boolean;
288
431
  declare function ensureRepository(db: AnchorDatabase, fullName: string): number;
289
432
  declare function getLastSyncTime(db: AnchorDatabase, repo: string): string | undefined;
290
- declare function updateSyncState(db: AnchorDatabase, repo: string, lastIndexedPr?: number): void;
291
- declare function upsertPullRequest(db: AnchorDatabase, pr: PullRequestRecord, wisdomUnits: WisdomUnit[]): {
433
+ declare function updateSyncState(db: AnchorDatabase, repo: string, lastIndexedPr?: number, metadata?: {
434
+ historyCoverage?: "limited" | "all" | "unknown";
435
+ historyLimit?: number;
436
+ historySince?: string;
437
+ }): void;
438
+ declare function upsertPullRequest(db: AnchorDatabase, pr: PullRequestRecord, wisdomUnits: WisdomUnit[], regressionEvents?: RegressionEvent[]): {
292
439
  files: number;
293
440
  comments: number;
294
441
  wisdom: number;
442
+ regressions: number;
295
443
  };
296
444
  declare function replaceCodeIndex(db: AnchorDatabase, repo: string, codeFiles: CodeFileRecord[], codeChunks: CodeChunk[], skippedFiles: number, cwd: string): CodeIndexSummary;
445
+ declare function recordIndexRun(db: AnchorDatabase, run: IndexRunRecord): void;
297
446
  declare function getIndexStatus(cwd: string, githubTokenConfigured?: boolean, databasePath?: string): IndexStatus;
298
447
 
299
448
  declare const SCHEMA_SQL: string;
@@ -332,6 +481,14 @@ declare function indexCodebase(db: AnchorDatabase, options: {
332
481
  }): CodeIndexSummary;
333
482
  declare function emptyCodeIndexSummary(cwd: string): CodeIndexSummary;
334
483
 
484
+ declare function isTestFilePath(filePath: string): boolean;
485
+ declare function inferTestAwareness(repo: string, codeFiles: CodeFileRecord[], codeChunks: CodeChunk[]): {
486
+ testFiles: TestFileRecord[];
487
+ testLinks: TestLink[];
488
+ };
489
+
490
+ declare function extractRegressionEvents(pr: PullRequestRecord): RegressionEvent[];
491
+
335
492
  declare function categorizeWisdom(text: string): WisdomCategory;
336
493
  declare function extractSymbols(text: string, filePaths: string[]): string[];
337
494
  declare function extractWisdomUnits(pr: PullRequestRecord): WisdomUnit[];
@@ -342,11 +499,15 @@ declare function indexPullRequests(db: AnchorDatabase, pullRequests: PullRequest
342
499
  cwd: string;
343
500
  repo: string;
344
501
  updateSyncStateAfter?: boolean;
502
+ historyCoverage?: "limited" | "all" | "unknown";
503
+ historyLimit?: number;
504
+ historySince?: string;
345
505
  onProgress?: (progress: IndexPullRequestsProgress) => void;
346
506
  }): IndexSummary;
347
507
 
348
508
  declare function shouldSyncSince(db: AnchorDatabase, repo: string, fallbackSince?: string): string | undefined;
349
509
 
510
+ declare function buildQueryTerms(input: AnchorContextInput | SearchHistoryInput): string[];
350
511
  declare function buildFtsQuery(input: AnchorContextInput | SearchHistoryInput): string;
351
512
  declare function clampMaxResults(value: number | undefined, defaultValue: number): number;
352
513
 
@@ -354,14 +515,103 @@ declare function rankWisdomUnits(db: AnchorDatabase, input: AnchorContextInput |
354
515
 
355
516
  declare function rankCodeChunks(db: AnchorDatabase, input: AnchorContextInput): RankedCodeChunk[];
356
517
 
518
+ declare function rankRelevantTests(db: AnchorDatabase, input: AnchorContextInput): RankedTestFile[];
519
+
520
+ declare function rankRegressionEvents(db: AnchorDatabase, input: AnchorContextInput | SearchHistoryInput): RankedRegressionEvent[];
521
+
357
522
  type FormattedResult = {
358
523
  markdown: string;
359
524
  metadata: Record<string, unknown>;
360
525
  };
361
- declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput, codeChunks?: RankedCodeChunk[]): FormattedResult;
526
+ declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput, codeChunks?: RankedCodeChunk[], teamRules?: RankedTeamRule[], warnings?: string[], relevantTests?: RankedTestFile[], regressionEvents?: RankedRegressionEvent[], extraMetadata?: Record<string, unknown>): FormattedResult;
362
527
  declare function formatSearchHistory(units: RankedWisdomUnit[]): FormattedResult;
363
528
  declare function formatIndexStatus(status: IndexStatus): FormattedResult;
364
529
 
530
+ declare function buildAnchorContextResult(db: AnchorDatabase, cwd: string, input: AnchorContextInput, warnings?: string[]): FormattedResult;
531
+
532
+ declare function explainFile(db: AnchorDatabase, cwd: string, input: AnchorExplainFileInput): FormattedResult;
533
+
534
+ declare function filesFromDiff(diff: string): string[];
535
+ declare function reviewDiff(db: AnchorDatabase, cwd: string, input: AnchorReviewDiffInput): FormattedResult;
536
+
537
+ type LocalEmbeddingProvider = {
538
+ name: string;
539
+ isAvailable(): boolean;
540
+ embed(texts: string[]): Promise<number[][]>;
541
+ };
542
+ declare function getSemanticStatus(env?: NodeJS.ProcessEnv, provider?: LocalEmbeddingProvider): SemanticStatus;
543
+
544
+ type CurrentCodeSnapshot = {
545
+ hasCodeIndex: boolean;
546
+ filePaths: Set<string>;
547
+ symbolsByFile: Map<string, Set<string>>;
548
+ allSymbols: Set<string>;
549
+ };
550
+ type FreshnessResult = {
551
+ status: FreshnessStatus;
552
+ reason: string;
553
+ };
554
+ declare function claimKeyFor(category: WisdomCategory, sanitizedText: string): string;
555
+ declare function confidenceLevelFor(confidence: number): ConfidenceLevel;
556
+ declare function confidenceRank(level: ConfidenceLevel): number;
557
+ declare function confidenceAtLeast(level: ConfidenceLevel, minimum: ConfidenceLevel): boolean;
558
+ declare function evidenceForWisdom(unit: WisdomUnit): EvidenceRef;
559
+ declare function confidenceReasonsFor(unit: WisdomUnit, repeatedEvidenceCount: number): string[];
560
+ declare function sourceTypeLabel(sourceType: SourceType): string;
561
+ declare function loadCurrentCodeSnapshot(db: AnchorDatabase): CurrentCodeSnapshot;
562
+ declare function evaluateFreshness(subject: {
563
+ filePaths: string[];
564
+ symbols: string[];
565
+ }, snapshot: CurrentCodeSnapshot): FreshnessResult;
566
+
567
+ declare const TEAM_RULES_FILE = "anchor.rules.json";
568
+ type TeamRulesValidationResult = {
569
+ ok: boolean;
570
+ path: string;
571
+ errors: string[];
572
+ rules: TeamRule[];
573
+ };
574
+ type RulesInitResult = {
575
+ path: string;
576
+ created: boolean;
577
+ };
578
+ type RulesAddInput = {
579
+ id: string;
580
+ category: WisdomCategory;
581
+ text: string;
582
+ filePaths?: string[];
583
+ symbols?: string[];
584
+ prNumber: number;
585
+ prUrl: string;
586
+ sourceType?: SourceType;
587
+ };
588
+ type RulesAddResult = {
589
+ path: string;
590
+ rule: TeamRule;
591
+ };
592
+ type RulesEvidenceCheckResult = {
593
+ ok: boolean;
594
+ path: string;
595
+ checked: number;
596
+ missing: Array<{
597
+ ruleId: string;
598
+ prNumber: number;
599
+ }>;
600
+ errors: string[];
601
+ };
602
+ declare function ensureTeamRulesFile(cwd: string): RulesInitResult;
603
+ declare function loadTeamRulesFile(cwd: string): TeamRulesValidationResult & {
604
+ exists: boolean;
605
+ };
606
+ declare function validateTeamRulesFile(cwd: string): TeamRulesValidationResult;
607
+ declare function addTeamRule(cwd: string, input: RulesAddInput): RulesAddResult;
608
+ declare function checkTeamRuleEvidence(cwd: string): RulesEvidenceCheckResult;
609
+ declare function rankTeamRules(db: AnchorDatabase, cwd: string, input: AnchorContextInput): RankedTeamRule[];
610
+ declare function countValidTeamRules(cwd: string): {
611
+ count: number;
612
+ lastRuleIndexTime?: string;
613
+ };
614
+
365
615
  declare function createGitHubClient(token: string): Octokit;
366
616
 
367
617
  type FetchPullRequestsOptions = {
@@ -387,4 +637,9 @@ type DoctorOptions = {
387
637
  };
388
638
  declare function runDoctor(options: DoctorOptions): Promise<DoctorReport>;
389
639
 
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 };
640
+ declare function evaluateIndexHealth(status: IndexStatus, rulesOk: boolean): AnchorIndexHealth;
641
+ declare function getAnchorIndexHealth(cwd: string): AnchorIndexHealth & {
642
+ indexStatus: IndexStatus;
643
+ };
644
+
645
+ export { ANCHOR_CURSOR_RULE, type AnchorContextInput, type AnchorDatabase, type AnchorExplainFileInput, type AnchorIndexHealth, type AnchorReviewDiffInput, 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 IndexRunRecord, type IndexStatus, type IndexSummary, type LocalEmbeddingProvider, type PullRequestComment, type PullRequestCommit, type PullRequestFile, type PullRequestPerson, type PullRequestRecord, type RankedCodeChunk, type RankedRegressionEvent, type RankedTeamRule, type RankedTestFile, type RankedWisdomUnit, type RegressionEvent, type RulesAddInput, type RulesAddResult, type RulesEvidenceCheckResult, type RulesInitResult, SCHEMA_SQL, type SearchHistoryInput, type SemanticStatus, type SourceType, TEAM_RULES_FILE, type TeamRule, type TeamRulesValidationResult, type TestFileRecord, type TestLink, type WisdomCategory, type WisdomUnit, addTeamRule, anchorMcpEntry, buildAnchorContextResult, buildFtsQuery, buildQueryTerms, canonicalizeText, categorizeWisdom, checkSchema, checkTeamRuleEvidence, chunkCodeFile, chunkHistoricalText, claimKeyFor, clampMaxResults, clipSentence, confidenceAtLeast, confidenceLevelFor, confidenceRank, confidenceReasonsFor, countValidTeamRules, createGitHubClient, defaultDatabasePath, detectGitHubRepo, detectGitRoot, discoverCodeFiles, emptyCodeIndexSummary, ensureAnchorGitExclude, ensureCursorConfig, ensureCursorRule, ensureRepository, ensureTeamRulesFile, evaluateFreshness, evaluateIndexHealth, evidenceForWisdom, explainFile, extractCodeSymbols, extractRegressionEvents, extractSymbols, extractWisdomUnits, fetchMergedPullRequests, fetchPullRequestDetails, filesFromDiff, formatAnchorContext, formatIndexStatus, formatSearchHistory, getAnchorIndexHealth, getIndexStatus, getLastSyncTime, getSemanticStatus, githubAuthFixMessage, hasHighSignalLanguage, indexCodebase, indexPullRequests, inferTestAwareness, initializeSchema, isHardExcludedCodePath, isTestFilePath, loadCurrentCodeSnapshot, loadTeamRulesFile, mergeAnchorMcpConfig, normalizePullRequest, openAnchorDatabase, parseGitHubRemote, rankCodeChunks, rankRegressionEvents, rankRelevantTests, rankTeamRules, rankWisdomUnits, recordIndexRun, redactSecrets, redactedHistoricalText, replaceCodeIndex, resolveGitHubToken, resolvePullRequestDetailConcurrency, resolvePullRequestFetchLimit, reviewDiff, runDoctor, sanitizeHistoricalText, shouldSyncSince, sourceTypeLabel, stripPromptInjection, tokenizeSearchText, truncateText, uniqueStrings, updateSyncState, upsertPullRequest, validateTeamRulesFile };