@pratik7368patil/anchor-core 0.1.8 → 0.1.10

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
@@ -5,6 +5,7 @@ type SourceType = "pr_body" | "review_comment" | "issue_comment" | "review_summa
5
5
  type WisdomCategory = "architecture_decision" | "constraint" | "rejected_approach" | "bug_regression" | "testing_rule" | "api_contract" | "performance_note" | "security_note" | "style_convention" | "unknown";
6
6
  type ConfidenceLevel = "strong" | "moderate" | "weak";
7
7
  type FreshnessStatus = "current" | "possibly_stale" | "stale";
8
+ type CoverageGrade = "empty" | "poor" | "fair" | "good" | "excellent";
8
9
  type EvidenceRef = {
9
10
  prNumber: number;
10
11
  prUrl: string;
@@ -57,6 +58,8 @@ type RankedCodeChunk = CodeChunk & {
57
58
  textMatch: number;
58
59
  recency: number;
59
60
  };
61
+ matchReasons: string[];
62
+ rankSignals: Record<string, number>;
60
63
  };
61
64
  type TeamRule = {
62
65
  id: string;
@@ -68,11 +71,17 @@ type TeamRule = {
68
71
  evidence: EvidenceRef[];
69
72
  confidenceLevel: ConfidenceLevel;
70
73
  };
74
+ type TeamRuleSuggestion = TeamRule & {
75
+ repeatedEvidenceCount: number;
76
+ reason: string;
77
+ };
71
78
  type RankedTeamRule = TeamRule & {
72
79
  score: number;
73
80
  freshnessStatus: FreshnessStatus;
74
81
  freshnessReason: string;
75
82
  confidenceReasons: string[];
83
+ matchReasons: string[];
84
+ rankSignals: Record<string, number>;
76
85
  };
77
86
  type PullRequestFile = {
78
87
  filename: string;
@@ -114,6 +123,49 @@ type PullRequestRecord = {
114
123
  issueComments?: PullRequestComment[];
115
124
  commits?: PullRequestCommit[];
116
125
  };
126
+ type TestFileRecord = {
127
+ repo: string;
128
+ path: string;
129
+ language?: string;
130
+ sizeBytes: number;
131
+ contentHash: string;
132
+ updatedAt: string;
133
+ };
134
+ type TestLink = {
135
+ repo: string;
136
+ sourcePath: string;
137
+ testPath: string;
138
+ reason: string;
139
+ strength: number;
140
+ };
141
+ type RankedTestFile = TestFileRecord & {
142
+ sourcePath?: string;
143
+ reason: string;
144
+ strength: number;
145
+ score: number;
146
+ matchedSymbols: string[];
147
+ };
148
+ type RegressionEvent = {
149
+ id: string;
150
+ repo: string;
151
+ prNumber: number;
152
+ prUrl: string;
153
+ summary: string;
154
+ filePaths: string[];
155
+ symbols: string[];
156
+ testPaths: string[];
157
+ authors: string[];
158
+ labels: string[];
159
+ signals: string[];
160
+ createdAt: string;
161
+ mergedAt?: string;
162
+ confidence: number;
163
+ };
164
+ type RankedRegressionEvent = RegressionEvent & {
165
+ score: number;
166
+ matchReasons: string[];
167
+ rankSignals: Record<string, number>;
168
+ };
117
169
  type FetchPullRequestsProgress = {
118
170
  stage: "discovering_pull_requests";
119
171
  repo: string;
@@ -190,12 +242,15 @@ type IndexSummary = {
190
242
  indexedFiles: number;
191
243
  indexedComments: number;
192
244
  wisdomUnitsCreated: number;
245
+ regressionEventsCreated: number;
193
246
  skippedItems: number;
194
247
  databasePath: string;
195
248
  };
196
249
  type CodeIndexSummary = {
197
250
  indexedFiles: number;
198
251
  codeChunksCreated: number;
252
+ testFilesIndexed: number;
253
+ testLinksCreated: number;
199
254
  skippedFiles: number;
200
255
  databasePath: string;
201
256
  };
@@ -213,6 +268,7 @@ type SearchHistoryInput = {
213
268
  query: string;
214
269
  files?: string[];
215
270
  categories?: WisdomCategory[];
271
+ regressionsOnly?: boolean;
216
272
  maxResults?: number;
217
273
  };
218
274
  type RankedWisdomUnit = WisdomUnit & {
@@ -233,6 +289,57 @@ type RankedWisdomUnit = WisdomUnit & {
233
289
  freshnessStatus: FreshnessStatus;
234
290
  freshnessReason: string;
235
291
  evidence: EvidenceRef;
292
+ matchReasons: string[];
293
+ rankSignals: Record<string, number>;
294
+ };
295
+ type AnchorExplainFileInput = {
296
+ file: string;
297
+ symbols?: string[];
298
+ strict?: boolean;
299
+ maxResults?: number;
300
+ share?: boolean;
301
+ };
302
+ type AnchorReviewDiffInput = {
303
+ diff: string;
304
+ files?: string[];
305
+ strict?: boolean;
306
+ maxResults?: number;
307
+ share?: boolean;
308
+ };
309
+ type IndexRunRecord = {
310
+ id?: number;
311
+ command: string;
312
+ repo?: string;
313
+ startedAt: string;
314
+ finishedAt?: string;
315
+ historyCoverage?: "limited" | "all" | "unknown";
316
+ historyLimit?: number;
317
+ prsFetched?: number;
318
+ prsSkipped?: number;
319
+ commentsIndexed?: number;
320
+ codeFilesIndexed?: number;
321
+ testFilesIndexed?: number;
322
+ failures?: string[];
323
+ status: "success" | "failed";
324
+ };
325
+ type AnchorIndexHealth = {
326
+ status: "ok" | "warning" | "error";
327
+ warnings: string[];
328
+ suggestedNextCommand?: string;
329
+ historyCoverage: "limited" | "all" | "unknown";
330
+ staleCodeIndex: boolean;
331
+ lastSuccessfulRun?: string;
332
+ lastFailedRun?: string;
333
+ coverageScore: number;
334
+ coverageGrade: CoverageGrade;
335
+ coverageReasons: string[];
336
+ suggestedPrompts: string[];
337
+ };
338
+ type SemanticStatus = {
339
+ enabled: boolean;
340
+ mode: "disabled" | "local";
341
+ available: boolean;
342
+ reason: string;
236
343
  };
237
344
  type IndexStatus = {
238
345
  repo?: string;
@@ -243,6 +350,9 @@ type IndexStatus = {
243
350
  wisdomUnitCount: number;
244
351
  codeFileCount: number;
245
352
  codeChunkCount: number;
353
+ testFileCount: number;
354
+ testLinkCount: number;
355
+ regressionEventCount: number;
246
356
  historyCoverage?: "limited" | "all" | "unknown";
247
357
  historyLimit?: number;
248
358
  staleEvidenceCount: number;
@@ -250,6 +360,14 @@ type IndexStatus = {
250
360
  lastSyncTime?: string;
251
361
  lastCodeIndexTime?: string;
252
362
  lastRuleIndexTime?: string;
363
+ lastSuccessfulRun?: string;
364
+ lastFailedRun?: string;
365
+ staleCodeIndex?: boolean;
366
+ suggestedNextCommand?: string;
367
+ coverageScore: number;
368
+ coverageGrade: CoverageGrade;
369
+ coverageReasons: string[];
370
+ suggestedPrompts: string[];
253
371
  githubTokenConfigured: boolean;
254
372
  health: "ok" | "missing_database" | "schema_invalid" | "empty_index";
255
373
  };
@@ -332,13 +450,16 @@ declare function updateSyncState(db: AnchorDatabase, repo: string, lastIndexedPr
332
450
  historyLimit?: number;
333
451
  historySince?: string;
334
452
  }): void;
335
- declare function upsertPullRequest(db: AnchorDatabase, pr: PullRequestRecord, wisdomUnits: WisdomUnit[]): {
453
+ declare function upsertPullRequest(db: AnchorDatabase, pr: PullRequestRecord, wisdomUnits: WisdomUnit[], regressionEvents?: RegressionEvent[]): {
336
454
  files: number;
337
455
  comments: number;
338
456
  wisdom: number;
457
+ regressions: number;
339
458
  };
340
459
  declare function replaceCodeIndex(db: AnchorDatabase, repo: string, codeFiles: CodeFileRecord[], codeChunks: CodeChunk[], skippedFiles: number, cwd: string): CodeIndexSummary;
460
+ declare function recordIndexRun(db: AnchorDatabase, run: IndexRunRecord): void;
341
461
  declare function getIndexStatus(cwd: string, githubTokenConfigured?: boolean, databasePath?: string): IndexStatus;
462
+ declare function getWisdomCategoryCounts(db: AnchorDatabase): Record<WisdomCategory, number>;
342
463
 
343
464
  declare const SCHEMA_SQL: string;
344
465
 
@@ -376,6 +497,14 @@ declare function indexCodebase(db: AnchorDatabase, options: {
376
497
  }): CodeIndexSummary;
377
498
  declare function emptyCodeIndexSummary(cwd: string): CodeIndexSummary;
378
499
 
500
+ declare function isTestFilePath(filePath: string): boolean;
501
+ declare function inferTestAwareness(repo: string, codeFiles: CodeFileRecord[], codeChunks: CodeChunk[]): {
502
+ testFiles: TestFileRecord[];
503
+ testLinks: TestLink[];
504
+ };
505
+
506
+ declare function extractRegressionEvents(pr: PullRequestRecord): RegressionEvent[];
507
+
379
508
  declare function categorizeWisdom(text: string): WisdomCategory;
380
509
  declare function extractSymbols(text: string, filePaths: string[]): string[];
381
510
  declare function extractWisdomUnits(pr: PullRequestRecord): WisdomUnit[];
@@ -394,6 +523,7 @@ declare function indexPullRequests(db: AnchorDatabase, pullRequests: PullRequest
394
523
 
395
524
  declare function shouldSyncSince(db: AnchorDatabase, repo: string, fallbackSince?: string): string | undefined;
396
525
 
526
+ declare function buildQueryTerms(input: AnchorContextInput | SearchHistoryInput): string[];
397
527
  declare function buildFtsQuery(input: AnchorContextInput | SearchHistoryInput): string;
398
528
  declare function clampMaxResults(value: number | undefined, defaultValue: number): number;
399
529
 
@@ -401,6 +531,32 @@ declare function rankWisdomUnits(db: AnchorDatabase, input: AnchorContextInput |
401
531
 
402
532
  declare function rankCodeChunks(db: AnchorDatabase, input: AnchorContextInput): RankedCodeChunk[];
403
533
 
534
+ declare function rankRelevantTests(db: AnchorDatabase, input: AnchorContextInput): RankedTestFile[];
535
+
536
+ declare function rankRegressionEvents(db: AnchorDatabase, input: AnchorContextInput | SearchHistoryInput): RankedRegressionEvent[];
537
+
538
+ type FormattedResult = {
539
+ markdown: string;
540
+ metadata: Record<string, unknown>;
541
+ };
542
+ declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput, codeChunks?: RankedCodeChunk[], teamRules?: RankedTeamRule[], warnings?: string[], relevantTests?: RankedTestFile[], regressionEvents?: RankedRegressionEvent[], extraMetadata?: Record<string, unknown>): FormattedResult;
543
+ declare function formatSearchHistory(units: RankedWisdomUnit[]): FormattedResult;
544
+ declare function formatIndexStatus(status: IndexStatus): FormattedResult;
545
+
546
+ declare function buildAnchorContextResult(db: AnchorDatabase, cwd: string, input: AnchorContextInput, warnings?: string[]): FormattedResult;
547
+
548
+ declare function explainFile(db: AnchorDatabase, cwd: string, input: AnchorExplainFileInput): FormattedResult;
549
+
550
+ declare function filesFromDiff(diff: string): string[];
551
+ declare function reviewDiff(db: AnchorDatabase, cwd: string, input: AnchorReviewDiffInput): FormattedResult;
552
+
553
+ type LocalEmbeddingProvider = {
554
+ name: string;
555
+ isAvailable(): boolean;
556
+ embed(texts: string[]): Promise<number[][]>;
557
+ };
558
+ declare function getSemanticStatus(env?: NodeJS.ProcessEnv, provider?: LocalEmbeddingProvider): SemanticStatus;
559
+
404
560
  type CurrentCodeSnapshot = {
405
561
  hasCodeIndex: boolean;
406
562
  filePaths: Set<string>;
@@ -424,14 +580,6 @@ declare function evaluateFreshness(subject: {
424
580
  symbols: string[];
425
581
  }, snapshot: CurrentCodeSnapshot): FreshnessResult;
426
582
 
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
583
  declare const TEAM_RULES_FILE = "anchor.rules.json";
436
584
  type TeamRulesValidationResult = {
437
585
  ok: boolean;
@@ -443,17 +591,70 @@ type RulesInitResult = {
443
591
  path: string;
444
592
  created: boolean;
445
593
  };
594
+ type RulesAddInput = {
595
+ id: string;
596
+ category: WisdomCategory;
597
+ text: string;
598
+ filePaths?: string[];
599
+ symbols?: string[];
600
+ prNumber: number;
601
+ prUrl: string;
602
+ sourceType?: SourceType;
603
+ };
604
+ type RulesAddResult = {
605
+ path: string;
606
+ rule: TeamRule;
607
+ };
608
+ type RulesEvidenceCheckResult = {
609
+ ok: boolean;
610
+ path: string;
611
+ checked: number;
612
+ missing: Array<{
613
+ ruleId: string;
614
+ prNumber: number;
615
+ }>;
616
+ errors: string[];
617
+ };
618
+ type RulesSuggestOptions = {
619
+ category?: WisdomCategory;
620
+ minConfidence?: ConfidenceLevel;
621
+ maxResults?: number;
622
+ };
446
623
  declare function ensureTeamRulesFile(cwd: string): RulesInitResult;
447
624
  declare function loadTeamRulesFile(cwd: string): TeamRulesValidationResult & {
448
625
  exists: boolean;
449
626
  };
450
627
  declare function validateTeamRulesFile(cwd: string): TeamRulesValidationResult;
628
+ declare function addTeamRule(cwd: string, input: RulesAddInput): RulesAddResult;
629
+ declare function checkTeamRuleEvidence(cwd: string): RulesEvidenceCheckResult;
451
630
  declare function rankTeamRules(db: AnchorDatabase, cwd: string, input: AnchorContextInput): RankedTeamRule[];
631
+ declare function suggestTeamRules(db: AnchorDatabase, cwd: string, options?: RulesSuggestOptions): TeamRuleSuggestion[];
452
632
  declare function countValidTeamRules(cwd: string): {
453
633
  count: number;
454
634
  lastRuleIndexTime?: string;
455
635
  };
456
636
 
637
+ type CoverageInput = Pick<IndexStatus, "prCount" | "wisdomUnitCount" | "codeFileCount" | "codeChunkCount" | "testLinkCount" | "regressionEventCount" | "teamRuleCount" | "historyCoverage" | "staleEvidenceCount" | "staleCodeIndex">;
638
+ type CoverageReport = {
639
+ coverageScore: number;
640
+ coverageGrade: CoverageGrade;
641
+ coverageReasons: string[];
642
+ suggestedPrompts: string[];
643
+ };
644
+ declare function calculateCoverage(input: CoverageInput): CoverageReport;
645
+
646
+ type SuggestedPrompt = {
647
+ id: "before_edit" | "explain_file" | "strict_mode" | "review_diff";
648
+ title: string;
649
+ prompt: string;
650
+ };
651
+ declare function getSuggestedPrompts(): SuggestedPrompt[];
652
+ declare function getSuggestedPromptTexts(): string[];
653
+
654
+ declare const DEMO_REPO = "anchor/demo";
655
+ declare const DEMO_PULL_REQUESTS: PullRequestRecord[];
656
+ declare const DEMO_CODE_FILES: Record<string, string>;
657
+
457
658
  declare function createGitHubClient(token: string): Octokit;
458
659
 
459
660
  type FetchPullRequestsOptions = {
@@ -479,4 +680,9 @@ type DoctorOptions = {
479
680
  };
480
681
  declare function runDoctor(options: DoctorOptions): Promise<DoctorReport>;
481
682
 
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 };
683
+ declare function evaluateIndexHealth(status: IndexStatus, rulesOk: boolean): AnchorIndexHealth;
684
+ declare function getAnchorIndexHealth(cwd: string): AnchorIndexHealth & {
685
+ indexStatus: IndexStatus;
686
+ };
687
+
688
+ 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 CoverageGrade, type CoverageInput, type CoverageReport, type CurrentCodeSnapshot, type CursorMcpConfig, DEFAULT_MAX_CODE_FILE_BYTES, DEMO_CODE_FILES, DEMO_PULL_REQUESTS, DEMO_REPO, 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, type RulesSuggestOptions, SCHEMA_SQL, type SearchHistoryInput, type SemanticStatus, type SourceType, type SuggestedPrompt, TEAM_RULES_FILE, type TeamRule, type TeamRuleSuggestion, type TeamRulesValidationResult, type TestFileRecord, type TestLink, type WisdomCategory, type WisdomUnit, addTeamRule, anchorMcpEntry, buildAnchorContextResult, buildFtsQuery, buildQueryTerms, calculateCoverage, 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, getSuggestedPromptTexts, getSuggestedPrompts, getWisdomCategoryCounts, 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, suggestTeamRules, tokenizeSearchText, truncateText, uniqueStrings, updateSyncState, upsertPullRequest, validateTeamRulesFile };