@pratik7368patil/anchor-core 0.1.8 → 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
@@ -57,6 +57,8 @@ type RankedCodeChunk = CodeChunk & {
57
57
  textMatch: number;
58
58
  recency: number;
59
59
  };
60
+ matchReasons: string[];
61
+ rankSignals: Record<string, number>;
60
62
  };
61
63
  type TeamRule = {
62
64
  id: string;
@@ -73,6 +75,8 @@ type RankedTeamRule = TeamRule & {
73
75
  freshnessStatus: FreshnessStatus;
74
76
  freshnessReason: string;
75
77
  confidenceReasons: string[];
78
+ matchReasons: string[];
79
+ rankSignals: Record<string, number>;
76
80
  };
77
81
  type PullRequestFile = {
78
82
  filename: string;
@@ -114,6 +118,49 @@ type PullRequestRecord = {
114
118
  issueComments?: PullRequestComment[];
115
119
  commits?: PullRequestCommit[];
116
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
+ };
117
164
  type FetchPullRequestsProgress = {
118
165
  stage: "discovering_pull_requests";
119
166
  repo: string;
@@ -190,12 +237,15 @@ type IndexSummary = {
190
237
  indexedFiles: number;
191
238
  indexedComments: number;
192
239
  wisdomUnitsCreated: number;
240
+ regressionEventsCreated: number;
193
241
  skippedItems: number;
194
242
  databasePath: string;
195
243
  };
196
244
  type CodeIndexSummary = {
197
245
  indexedFiles: number;
198
246
  codeChunksCreated: number;
247
+ testFilesIndexed: number;
248
+ testLinksCreated: number;
199
249
  skippedFiles: number;
200
250
  databasePath: string;
201
251
  };
@@ -213,6 +263,7 @@ type SearchHistoryInput = {
213
263
  query: string;
214
264
  files?: string[];
215
265
  categories?: WisdomCategory[];
266
+ regressionsOnly?: boolean;
216
267
  maxResults?: number;
217
268
  };
218
269
  type RankedWisdomUnit = WisdomUnit & {
@@ -233,6 +284,51 @@ type RankedWisdomUnit = WisdomUnit & {
233
284
  freshnessStatus: FreshnessStatus;
234
285
  freshnessReason: string;
235
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;
236
332
  };
237
333
  type IndexStatus = {
238
334
  repo?: string;
@@ -243,6 +339,9 @@ type IndexStatus = {
243
339
  wisdomUnitCount: number;
244
340
  codeFileCount: number;
245
341
  codeChunkCount: number;
342
+ testFileCount: number;
343
+ testLinkCount: number;
344
+ regressionEventCount: number;
246
345
  historyCoverage?: "limited" | "all" | "unknown";
247
346
  historyLimit?: number;
248
347
  staleEvidenceCount: number;
@@ -250,6 +349,10 @@ type IndexStatus = {
250
349
  lastSyncTime?: string;
251
350
  lastCodeIndexTime?: string;
252
351
  lastRuleIndexTime?: string;
352
+ lastSuccessfulRun?: string;
353
+ lastFailedRun?: string;
354
+ staleCodeIndex?: boolean;
355
+ suggestedNextCommand?: string;
253
356
  githubTokenConfigured: boolean;
254
357
  health: "ok" | "missing_database" | "schema_invalid" | "empty_index";
255
358
  };
@@ -332,12 +435,14 @@ declare function updateSyncState(db: AnchorDatabase, repo: string, lastIndexedPr
332
435
  historyLimit?: number;
333
436
  historySince?: string;
334
437
  }): void;
335
- declare function upsertPullRequest(db: AnchorDatabase, pr: PullRequestRecord, wisdomUnits: WisdomUnit[]): {
438
+ declare function upsertPullRequest(db: AnchorDatabase, pr: PullRequestRecord, wisdomUnits: WisdomUnit[], regressionEvents?: RegressionEvent[]): {
336
439
  files: number;
337
440
  comments: number;
338
441
  wisdom: number;
442
+ regressions: number;
339
443
  };
340
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;
341
446
  declare function getIndexStatus(cwd: string, githubTokenConfigured?: boolean, databasePath?: string): IndexStatus;
342
447
 
343
448
  declare const SCHEMA_SQL: string;
@@ -376,6 +481,14 @@ declare function indexCodebase(db: AnchorDatabase, options: {
376
481
  }): CodeIndexSummary;
377
482
  declare function emptyCodeIndexSummary(cwd: string): CodeIndexSummary;
378
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
+
379
492
  declare function categorizeWisdom(text: string): WisdomCategory;
380
493
  declare function extractSymbols(text: string, filePaths: string[]): string[];
381
494
  declare function extractWisdomUnits(pr: PullRequestRecord): WisdomUnit[];
@@ -394,6 +507,7 @@ declare function indexPullRequests(db: AnchorDatabase, pullRequests: PullRequest
394
507
 
395
508
  declare function shouldSyncSince(db: AnchorDatabase, repo: string, fallbackSince?: string): string | undefined;
396
509
 
510
+ declare function buildQueryTerms(input: AnchorContextInput | SearchHistoryInput): string[];
397
511
  declare function buildFtsQuery(input: AnchorContextInput | SearchHistoryInput): string;
398
512
  declare function clampMaxResults(value: number | undefined, defaultValue: number): number;
399
513
 
@@ -401,6 +515,32 @@ declare function rankWisdomUnits(db: AnchorDatabase, input: AnchorContextInput |
401
515
 
402
516
  declare function rankCodeChunks(db: AnchorDatabase, input: AnchorContextInput): RankedCodeChunk[];
403
517
 
518
+ declare function rankRelevantTests(db: AnchorDatabase, input: AnchorContextInput): RankedTestFile[];
519
+
520
+ declare function rankRegressionEvents(db: AnchorDatabase, input: AnchorContextInput | SearchHistoryInput): RankedRegressionEvent[];
521
+
522
+ type FormattedResult = {
523
+ markdown: string;
524
+ metadata: Record<string, unknown>;
525
+ };
526
+ declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput, codeChunks?: RankedCodeChunk[], teamRules?: RankedTeamRule[], warnings?: string[], relevantTests?: RankedTestFile[], regressionEvents?: RankedRegressionEvent[], extraMetadata?: Record<string, unknown>): FormattedResult;
527
+ declare function formatSearchHistory(units: RankedWisdomUnit[]): FormattedResult;
528
+ declare function formatIndexStatus(status: IndexStatus): FormattedResult;
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
+
404
544
  type CurrentCodeSnapshot = {
405
545
  hasCodeIndex: boolean;
406
546
  filePaths: Set<string>;
@@ -424,14 +564,6 @@ declare function evaluateFreshness(subject: {
424
564
  symbols: string[];
425
565
  }, snapshot: CurrentCodeSnapshot): FreshnessResult;
426
566
 
427
- type FormattedResult = {
428
- markdown: string;
429
- metadata: Record<string, unknown>;
430
- };
431
- declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput, codeChunks?: RankedCodeChunk[], teamRules?: RankedTeamRule[], warnings?: string[]): FormattedResult;
432
- declare function formatSearchHistory(units: RankedWisdomUnit[]): FormattedResult;
433
- declare function formatIndexStatus(status: IndexStatus): FormattedResult;
434
-
435
567
  declare const TEAM_RULES_FILE = "anchor.rules.json";
436
568
  type TeamRulesValidationResult = {
437
569
  ok: boolean;
@@ -443,11 +575,37 @@ type RulesInitResult = {
443
575
  path: string;
444
576
  created: boolean;
445
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
+ };
446
602
  declare function ensureTeamRulesFile(cwd: string): RulesInitResult;
447
603
  declare function loadTeamRulesFile(cwd: string): TeamRulesValidationResult & {
448
604
  exists: boolean;
449
605
  };
450
606
  declare function validateTeamRulesFile(cwd: string): TeamRulesValidationResult;
607
+ declare function addTeamRule(cwd: string, input: RulesAddInput): RulesAddResult;
608
+ declare function checkTeamRuleEvidence(cwd: string): RulesEvidenceCheckResult;
451
609
  declare function rankTeamRules(db: AnchorDatabase, cwd: string, input: AnchorContextInput): RankedTeamRule[];
452
610
  declare function countValidTeamRules(cwd: string): {
453
611
  count: number;
@@ -479,4 +637,9 @@ type DoctorOptions = {
479
637
  };
480
638
  declare function runDoctor(options: DoctorOptions): Promise<DoctorReport>;
481
639
 
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 };
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 };