@pratik7368patil/anchor-core 0.1.11 → 0.1.13

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
@@ -6,6 +6,7 @@ type WisdomCategory = "architecture_decision" | "constraint" | "rejected_approac
6
6
  type ConfidenceLevel = "strong" | "moderate" | "weak";
7
7
  type FreshnessStatus = "current" | "possibly_stale" | "stale";
8
8
  type CoverageGrade = "empty" | "poor" | "fair" | "good" | "excellent";
9
+ type ArchitectureArea = "api" | "service" | "component" | "hook" | "route" | "store" | "test" | "schema" | "type" | "config" | "util" | "unknown";
9
10
  type EvidenceRef = {
10
11
  prNumber: number;
11
12
  prUrl: string;
@@ -50,6 +51,49 @@ type CodeChunk = {
50
51
  contentHash: string;
51
52
  updatedAt: string;
52
53
  };
54
+ type CodeImport = {
55
+ repo: string;
56
+ sourcePath: string;
57
+ specifier: string;
58
+ importedPath?: string;
59
+ importedSymbols: string[];
60
+ kind: "static" | "dynamic" | "require";
61
+ };
62
+ type ArchitectureComponent = {
63
+ repo: string;
64
+ path: string;
65
+ area: ArchitectureArea;
66
+ kind: string;
67
+ language?: string;
68
+ symbols: string[];
69
+ imports: string[];
70
+ relatedTests: string[];
71
+ confidence: number;
72
+ updatedAt: string;
73
+ };
74
+ type ArchitecturePattern = {
75
+ id: string;
76
+ repo: string;
77
+ area: ArchitectureArea;
78
+ name: string;
79
+ summary: string;
80
+ sanitizedSummary: string;
81
+ sourceFiles: string[];
82
+ symbols: string[];
83
+ evidence: EvidenceRef[];
84
+ confidence: number;
85
+ createdAt: string;
86
+ };
87
+ type RankedArchitecturePattern = ArchitecturePattern & {
88
+ score: number;
89
+ matchReasons: string[];
90
+ rankSignals: Record<string, number>;
91
+ };
92
+ type ArchitectureIndexData = {
93
+ components: ArchitectureComponent[];
94
+ patterns: ArchitecturePattern[];
95
+ imports: CodeImport[];
96
+ };
53
97
  type RankedCodeChunk = CodeChunk & {
54
98
  score: number;
55
99
  scoreParts: {
@@ -200,6 +244,14 @@ type FetchPullRequestsProgress = {
200
244
  total: number;
201
245
  prNumber: number;
202
246
  detailConcurrency: number;
247
+ } | {
248
+ stage: "github_rate_limited";
249
+ repo: string;
250
+ waitSeconds: number;
251
+ retryAt: string;
252
+ reason: string;
253
+ request: string;
254
+ attempt: number;
203
255
  };
204
256
  type IndexPullRequestsProgress = {
205
257
  stage: "indexing_pull_request";
@@ -236,6 +288,12 @@ type CodeIndexProgress = {
236
288
  total: number;
237
289
  filePath: string;
238
290
  chunks: number;
291
+ } | {
292
+ stage: "indexed_architecture";
293
+ repo: string;
294
+ components: number;
295
+ patterns: number;
296
+ imports: number;
239
297
  };
240
298
  type IndexSummary = {
241
299
  indexedPrs: number;
@@ -251,6 +309,9 @@ type CodeIndexSummary = {
251
309
  codeChunksCreated: number;
252
310
  testFilesIndexed: number;
253
311
  testLinksCreated: number;
312
+ architectureComponentsIndexed: number;
313
+ architecturePatternsIndexed: number;
314
+ architectureImportsIndexed: number;
254
315
  skippedFiles: number;
255
316
  databasePath: string;
256
317
  };
@@ -353,12 +414,16 @@ type IndexStatus = {
353
414
  testFileCount: number;
354
415
  testLinkCount: number;
355
416
  regressionEventCount: number;
417
+ architectureComponentCount: number;
418
+ architecturePatternCount: number;
419
+ architectureImportCount: number;
356
420
  historyCoverage?: "limited" | "all" | "unknown";
357
421
  historyLimit?: number;
358
422
  staleEvidenceCount: number;
359
423
  teamRuleCount: number;
360
424
  lastSyncTime?: string;
361
425
  lastCodeIndexTime?: string;
426
+ lastArchitectureIndexTime?: string;
362
427
  lastRuleIndexTime?: string;
363
428
  lastSuccessfulRun?: string;
364
429
  lastFailedRun?: string;
@@ -456,7 +521,7 @@ declare function upsertPullRequest(db: AnchorDatabase, pr: PullRequestRecord, wi
456
521
  wisdom: number;
457
522
  regressions: number;
458
523
  };
459
- declare function replaceCodeIndex(db: AnchorDatabase, repo: string, codeFiles: CodeFileRecord[], codeChunks: CodeChunk[], skippedFiles: number, cwd: string): CodeIndexSummary;
524
+ declare function replaceCodeIndex(db: AnchorDatabase, repo: string, codeFiles: CodeFileRecord[], codeChunks: CodeChunk[], skippedFiles: number, cwd: string, architecture?: ArchitectureIndexData): CodeIndexSummary;
460
525
  declare function recordIndexRun(db: AnchorDatabase, run: IndexRunRecord): void;
461
526
  declare function getIndexStatus(cwd: string, githubTokenConfigured?: boolean, databasePath?: string): IndexStatus;
462
527
  declare function getWisdomCategoryCounts(db: AnchorDatabase): Record<WisdomCategory, number>;
@@ -475,6 +540,10 @@ declare function chunkCodeFile(file: ChunkableCodeFile, options?: {
475
540
  overlapLines?: number;
476
541
  }): CodeChunk[];
477
542
 
543
+ declare function classifyArchitectureArea(filePath: string, language?: string, content?: string): ArchitectureArea;
544
+ declare function extractCodeImports(sourcePath: string, content: string, codePaths: Set<string>, repo?: string): CodeImport[];
545
+ declare function buildArchitectureIndex(repo: string, files: ChunkableCodeFile[], chunks: CodeChunk[]): ArchitectureIndexData;
546
+
478
547
  declare const DEFAULT_MAX_CODE_FILE_BYTES: number;
479
548
  type DiscoveredCodeFile = CodeFileRecord & {
480
549
  absolutePath: string;
@@ -531,6 +600,11 @@ declare function rankWisdomUnits(db: AnchorDatabase, input: AnchorContextInput |
531
600
 
532
601
  declare function rankCodeChunks(db: AnchorDatabase, input: AnchorContextInput): RankedCodeChunk[];
533
602
 
603
+ type ArchitectureQueryInput = AnchorContextInput & {
604
+ area?: ArchitectureArea;
605
+ };
606
+ declare function rankArchitecturePatterns(db: AnchorDatabase, input: ArchitectureQueryInput): RankedArchitecturePattern[];
607
+
534
608
  declare function rankRelevantTests(db: AnchorDatabase, input: AnchorContextInput): RankedTestFile[];
535
609
 
536
610
  declare function rankRegressionEvents(db: AnchorDatabase, input: AnchorContextInput | SearchHistoryInput): RankedRegressionEvent[];
@@ -539,7 +613,7 @@ type FormattedResult = {
539
613
  markdown: string;
540
614
  metadata: Record<string, unknown>;
541
615
  };
542
- declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput, codeChunks?: RankedCodeChunk[], teamRules?: RankedTeamRule[], warnings?: string[], relevantTests?: RankedTestFile[], regressionEvents?: RankedRegressionEvent[], extraMetadata?: Record<string, unknown>): FormattedResult;
616
+ declare function formatAnchorContext(units: RankedWisdomUnit[], input: AnchorContextInput, codeChunks?: RankedCodeChunk[], teamRules?: RankedTeamRule[], warnings?: string[], relevantTests?: RankedTestFile[], regressionEvents?: RankedRegressionEvent[], architecturePatterns?: RankedArchitecturePattern[], extraMetadata?: Record<string, unknown>): FormattedResult;
543
617
  declare function formatSearchHistory(units: RankedWisdomUnit[]): FormattedResult;
544
618
  declare function formatIndexStatus(status: IndexStatus): FormattedResult;
545
619
 
@@ -547,6 +621,21 @@ declare function buildAnchorContextResult(db: AnchorDatabase, cwd: string, input
547
621
 
548
622
  declare function explainFile(db: AnchorDatabase, cwd: string, input: AnchorExplainFileInput): FormattedResult;
549
623
 
624
+ type ArchitectureContextInput = {
625
+ file?: string;
626
+ area?: ArchitectureArea;
627
+ query?: string;
628
+ maxResults?: number;
629
+ };
630
+ type ArchitectureCheckInput = {
631
+ diff: string;
632
+ files?: string[];
633
+ maxResults?: number;
634
+ };
635
+ declare function architectureFilesFromDiff(diff: string): string[];
636
+ declare function getArchitectureContext(db: AnchorDatabase, _cwd: string, input?: ArchitectureContextInput): FormattedResult;
637
+ declare function checkArchitecture(db: AnchorDatabase, _cwd: string, input: ArchitectureCheckInput): FormattedResult;
638
+
550
639
  declare function filesFromDiff(diff: string): string[];
551
640
  declare function reviewDiff(db: AnchorDatabase, cwd: string, input: AnchorReviewDiffInput): FormattedResult;
552
641
 
@@ -634,7 +723,7 @@ declare function countValidTeamRules(cwd: string): {
634
723
  lastRuleIndexTime?: string;
635
724
  };
636
725
 
637
- type CoverageInput = Pick<IndexStatus, "prCount" | "wisdomUnitCount" | "codeFileCount" | "codeChunkCount" | "testLinkCount" | "regressionEventCount" | "teamRuleCount" | "historyCoverage" | "staleEvidenceCount" | "staleCodeIndex">;
726
+ type CoverageInput = Pick<IndexStatus, "prCount" | "wisdomUnitCount" | "codeFileCount" | "codeChunkCount" | "testLinkCount" | "regressionEventCount" | "architecturePatternCount" | "teamRuleCount" | "historyCoverage" | "staleEvidenceCount" | "staleCodeIndex">;
638
727
  type CoverageReport = {
639
728
  coverageScore: number;
640
729
  coverageGrade: CoverageGrade;
@@ -657,6 +746,45 @@ declare const DEMO_CODE_FILES: Record<string, string>;
657
746
 
658
747
  declare function createGitHubClient(token: string): Octokit;
659
748
 
749
+ type GitHubRateLimitProgress = {
750
+ waitSeconds: number;
751
+ retryAt: string;
752
+ reason: string;
753
+ request: string;
754
+ attempt: number;
755
+ };
756
+ type GitHubRateLimitController = {
757
+ onRateLimit?: (progress: GitHubRateLimitProgress) => void;
758
+ sleep?: (milliseconds: number) => Promise<void>;
759
+ now?: () => number;
760
+ blockedUntilMs?: number;
761
+ };
762
+ type GitHubRateLimitErrorLike = {
763
+ status?: number;
764
+ message?: string;
765
+ response?: {
766
+ headers?: Record<string, string | number | undefined>;
767
+ };
768
+ };
769
+ type GitHubResponse<T> = {
770
+ data: T;
771
+ headers: Record<string, string | number | undefined>;
772
+ };
773
+ declare function isGitHubRateLimitError(error: unknown): error is GitHubRateLimitErrorLike;
774
+ declare function getGitHubRateLimitDelayMs(error: GitHubRateLimitErrorLike, attempt: number, now?: number): {
775
+ delayMs: number;
776
+ reason: string;
777
+ };
778
+ declare function requestWithGitHubRateLimit<T>(request: () => Promise<T>, options: {
779
+ controller: GitHubRateLimitController;
780
+ requestName: string;
781
+ maxRetries?: number;
782
+ }): Promise<T>;
783
+ declare function paginateWithGitHubRateLimit<T>(requestPage: (page: number) => Promise<GitHubResponse<T[]>>, options: {
784
+ controller: GitHubRateLimitController;
785
+ requestName: string;
786
+ }): Promise<T[]>;
787
+
660
788
  type FetchPullRequestsOptions = {
661
789
  token: string;
662
790
  repo: string;
@@ -670,7 +798,7 @@ declare function resolvePullRequestFetchLimit(options: Pick<FetchPullRequestsOpt
670
798
  declare function resolvePullRequestDetailConcurrency(options: Pick<FetchPullRequestsOptions, "detailConcurrency">): number;
671
799
  declare function fetchMergedPullRequests(options: FetchPullRequestsOptions): Promise<PullRequestRecord[]>;
672
800
 
673
- declare function fetchPullRequestDetails(octokit: Octokit, repoFullName: string, pullNumber: number): Promise<PullRequestRecord>;
801
+ declare function fetchPullRequestDetails(octokit: Octokit, repoFullName: string, pullNumber: number, controller?: GitHubRateLimitController): Promise<PullRequestRecord>;
674
802
 
675
803
  type DoctorOptions = {
676
804
  cwd: string;
@@ -685,4 +813,4 @@ declare function getAnchorIndexHealth(cwd: string): AnchorIndexHealth & {
685
813
  indexStatus: IndexStatus;
686
814
  };
687
815
 
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 };
816
+ export { ANCHOR_CURSOR_RULE, type AnchorContextInput, type AnchorDatabase, type AnchorExplainFileInput, type AnchorIndexHealth, type AnchorReviewDiffInput, type ArchitectureArea, type ArchitectureCheckInput, type ArchitectureComponent, type ArchitectureContextInput, type ArchitectureIndexData, type ArchitecturePattern, type ArchitectureQueryInput, type ChunkableCodeFile, type CodeChunk, type CodeFileDiscoveryResult, type CodeFileRecord, type CodeImport, 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 GitHubRateLimitController, type GitHubRateLimitErrorLike, type GitHubRateLimitProgress, 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 RankedArchitecturePattern, 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, architectureFilesFromDiff, buildAnchorContextResult, buildArchitectureIndex, buildFtsQuery, buildQueryTerms, calculateCoverage, canonicalizeText, categorizeWisdom, checkArchitecture, checkSchema, checkTeamRuleEvidence, chunkCodeFile, chunkHistoricalText, claimKeyFor, clampMaxResults, classifyArchitectureArea, clipSentence, confidenceAtLeast, confidenceLevelFor, confidenceRank, confidenceReasonsFor, countValidTeamRules, createGitHubClient, defaultDatabasePath, detectGitHubRepo, detectGitRoot, discoverCodeFiles, emptyCodeIndexSummary, ensureAnchorGitExclude, ensureCursorConfig, ensureCursorRule, ensureRepository, ensureTeamRulesFile, evaluateFreshness, evaluateIndexHealth, evidenceForWisdom, explainFile, extractCodeImports, extractCodeSymbols, extractRegressionEvents, extractSymbols, extractWisdomUnits, fetchMergedPullRequests, fetchPullRequestDetails, filesFromDiff, formatAnchorContext, formatIndexStatus, formatSearchHistory, getAnchorIndexHealth, getArchitectureContext, getGitHubRateLimitDelayMs, getIndexStatus, getLastSyncTime, getSemanticStatus, getSuggestedPromptTexts, getSuggestedPrompts, getWisdomCategoryCounts, githubAuthFixMessage, hasHighSignalLanguage, indexCodebase, indexPullRequests, inferTestAwareness, initializeSchema, isGitHubRateLimitError, isHardExcludedCodePath, isTestFilePath, loadCurrentCodeSnapshot, loadTeamRulesFile, mergeAnchorMcpConfig, normalizePullRequest, openAnchorDatabase, paginateWithGitHubRateLimit, parseGitHubRemote, rankArchitecturePatterns, rankCodeChunks, rankRegressionEvents, rankRelevantTests, rankTeamRules, rankWisdomUnits, recordIndexRun, redactSecrets, redactedHistoricalText, replaceCodeIndex, requestWithGitHubRateLimit, resolveGitHubToken, resolvePullRequestDetailConcurrency, resolvePullRequestFetchLimit, reviewDiff, runDoctor, sanitizeHistoricalText, shouldSyncSince, sourceTypeLabel, stripPromptInjection, suggestTeamRules, tokenizeSearchText, truncateText, uniqueStrings, updateSyncState, upsertPullRequest, validateTeamRulesFile };