@pratik7368patil/anchor-core 0.1.22 → 0.1.23
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 +19 -1
- package/dist/index.js +60 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -560,6 +560,10 @@ type FetchPullRequestsProgress = {
|
|
|
560
560
|
reason: string;
|
|
561
561
|
request: string;
|
|
562
562
|
attempt: number;
|
|
563
|
+
} | {
|
|
564
|
+
stage: "skipped_pull_request_fetch";
|
|
565
|
+
repo: string;
|
|
566
|
+
reason: string;
|
|
563
567
|
};
|
|
564
568
|
type IndexPullRequestsProgress = {
|
|
565
569
|
stage: "indexing_pull_request";
|
|
@@ -1303,6 +1307,16 @@ declare function removeOrgRepoConfig(org: string, repoFullName: string, baseDir?
|
|
|
1303
1307
|
declare function listOrgNames(baseDir?: string): string[];
|
|
1304
1308
|
declare function resolveOrgForTool(org?: string, baseDir?: string): string;
|
|
1305
1309
|
|
|
1310
|
+
type OrgGraphState = {
|
|
1311
|
+
org: string;
|
|
1312
|
+
lastBuiltAt?: string;
|
|
1313
|
+
lastStatus?: "success" | "failed" | "skipped" | "unknown";
|
|
1314
|
+
lastDurationMs?: number;
|
|
1315
|
+
edgeCount?: number;
|
|
1316
|
+
apiContractCount?: number;
|
|
1317
|
+
apiConsumerCount?: number;
|
|
1318
|
+
lastError?: string;
|
|
1319
|
+
};
|
|
1306
1320
|
declare function openOrgDatabase(org: string, baseDir?: string): AnchorDatabase;
|
|
1307
1321
|
declare function syncOrgConfigToDatabase(db: AnchorDatabase, config: AnchorOrgConfig, baseDir?: string): void;
|
|
1308
1322
|
declare function updateOrgRepoState(db: AnchorDatabase, state: OrgRepoCloneState): void;
|
|
@@ -1328,6 +1342,7 @@ declare function recordOrgGraphState(db: AnchorDatabase, input: {
|
|
|
1328
1342
|
apiConsumerCount?: number;
|
|
1329
1343
|
error?: string;
|
|
1330
1344
|
}): void;
|
|
1345
|
+
declare function getOrgGraphState(db: AnchorDatabase, org: string): OrgGraphState | undefined;
|
|
1331
1346
|
declare function getOrgGraphCounts(db: AnchorDatabase, org: string): {
|
|
1332
1347
|
edges: number;
|
|
1333
1348
|
apiContracts: number;
|
|
@@ -1409,6 +1424,8 @@ declare function rebuildOrgGraph(db: AnchorDatabase, config: AnchorOrgConfig, ba
|
|
|
1409
1424
|
type OrgRepoIndexResult = {
|
|
1410
1425
|
repo: string;
|
|
1411
1426
|
skippedCode: boolean;
|
|
1427
|
+
skippedHistory?: boolean;
|
|
1428
|
+
historySkippedReason?: string;
|
|
1412
1429
|
currentCommit?: string;
|
|
1413
1430
|
history?: IndexSummary;
|
|
1414
1431
|
code?: CodeIndexSummary;
|
|
@@ -1437,6 +1454,7 @@ type OrgIndexOptions = {
|
|
|
1437
1454
|
command?: "org index" | "org sync";
|
|
1438
1455
|
baseDir?: string;
|
|
1439
1456
|
runner?: GitCommandRunner;
|
|
1457
|
+
fetchPullRequests?: typeof fetchMergedPullRequests;
|
|
1440
1458
|
onFetchProgress?: (progress: FetchPullRequestsProgress) => void;
|
|
1441
1459
|
onPrIndexProgress?: (progress: IndexPullRequestsProgress) => void;
|
|
1442
1460
|
onCodeProgress?: (progress: CodeIndexProgress) => void;
|
|
@@ -1503,4 +1521,4 @@ declare function getAnchorIndexHealth(cwd: string): AnchorIndexHealth & {
|
|
|
1503
1521
|
indexStatus: IndexStatus;
|
|
1504
1522
|
};
|
|
1505
1523
|
|
|
1506
|
-
export { ANCHOR_CURSOR_RULE, ANCHOR_EVALS_FILE, ANCHOR_PLAYBOOKS_FILE, type AnchorCiInput, type AnchorContextInput, type AnchorDatabase, type AnchorExplainFileInput, type AnchorIndexHealth, type AnchorOrgConfig, type AnchorOrgRepoConfig, type AnchorReviewDiffInput, type ArchitectureArea, type ArchitectureCheckInput, type ArchitectureComponent, type ArchitectureContextInput, type ArchitectureIndexData, type ArchitectureMap, type ArchitectureMapEdge, type ArchitectureMapFormat, type ArchitectureMapInput, type ArchitectureMapNode, 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 FeedbackEvent, type FeedbackRating, type FetchMergedPullRequestsGraphQLOptions, type FetchPullRequestsOptions, type FetchPullRequestsProgress, type FormattedResult, type FreshnessResult, type FreshnessStatus, type GitCommandRunner, type GitHubFetchBackend, GitHubGraphQLError, type GitHubGraphQLFetch, type GitHubGraphQLFetchCheckpoint, type GitHubGraphQLRateLimitState, type GitHubGraphQLResponse, 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 OnboardingInput, type OnboardingPack, type OrgAnomaly, type OrgAnomalyCategory, type OrgApiConsumer, type OrgCloneProgress, type OrgCloneResult, type OrgCrossRepoEdge, type OrgCrossRepoRelationship, type OrgFormattedResult, type OrgGraphProgress, type OrgGraphResult, type OrgImpactResult, type OrgIndexOptions, type OrgIndexResult, type OrgRepoCloneState, type OrgRepoGroup, type OrgRepoIndexResult, type OrgStatus, type Playbook, type PullRequestComment, type PullRequestCommit, type PullRequestFile, type PullRequestPerson, type PullRequestRecord, type RankedArchitecturePattern, type RankedCodeChunk, type RankedRegressionEvent, type RankedTeamRule, type RankedTestFile, type RankedWisdomUnit, type RebuildOrgGraphOptions, type RegressionEvent, type ReliabilityGate, type ReliabilityGateRejection, type ReliabilityGateResult, type ReliabilityGateStatus, type RetrievalEvalCase, type RetrievalEvalResult, type RetrievalEvalRunResult, type RulesAddInput, type RulesAddResult, type RulesEvidenceCheckResult, type RulesInitResult, type RulesSuggestOptions, SCHEMA_SQL, type SearchHistoryInput, type SemanticStatus, type SourceType, type SuggestedPrompt, TEAM_RULES_FILE, type TaskPlan, type TeamRule, type TeamRuleSuggestion, type TeamRulesValidationResult, type TestCommand, type TestFileRecord, type TestLink, type WatchRefreshInput, type WisdomCategory, type WisdomUnit, addOrgRepoConfig, addRetrievalEval, addTeamRule, anchorMcpEntry, architectureFilesFromDiff, buildAnchorContextResult, buildArchitectureIndex, buildArchitectureMap, buildFtsQuery, buildOnboardingPack, buildOrgContextResult, buildQueryTerms, calculateCoverage, canonicalizeText, categorizeWisdom, checkArchitecture, checkOrgImpact, checkSchema, checkTeamRuleEvidence, chunkCodeFile, chunkHistoricalText, claimKeyFor, clampMaxResults, classifyArchitectureArea, clearGraphQLFetchCheckpoint, clipSentence, cloneOrPullOrgRepo, cloneOrgRepos, confidenceAtLeast, confidenceLevelFor, confidenceRank, confidenceReasonsFor, countValidTeamRules, createGitHubClient, createGitHubGraphQLRequester, defaultDatabasePath, defaultGitCommandRunner, defaultOrgBaseDir, defaultOrgCloneUrl, detectGitHubRepo, detectGitRoot, detectTestCommands, detectTestCommandsForFile, discoverCodeFiles, emptyCodeIndexSummary, ensureAnchorGitExclude, ensureCursorConfig, ensureCursorRule, ensureRepository, ensureTeamRulesFile, evaluateFreshness, evaluateIndexHealth, evaluateReliabilityGate, evidenceForWisdom, explainFile, extractCodeImports, extractCodeSymbols, extractRegressionEvents, extractSymbols, extractWisdomUnits, feedbackAdjustedScore, fetchMergedPullRequests, fetchMergedPullRequestsWithGraphQL, fetchPullRequestDetails, filesFromDiff, findOrgApiConsumers, formatAnchorContext, formatIndexStatus, formatSearchHistory, getAnchorIndexHealth, getArchitectureContext, getArchitectureMapContext, getGitHubRateLimitDelayMs, getGraphQLFetchCheckpoint, getIndexStatus, getLastSyncTime, getOrgArchitectureMap, getOrgGraphCounts, getOrgRepoState, getOrgStatus, getPlaybook, getSemanticStatus, getSuggestedPromptTexts, getSuggestedPrompts, getWisdomCategoryCounts, githubAuthFixMessage, graphQLFetchCheckpointScope, hasHighSignalLanguage, indexCodebase, indexOrgRepos, indexPullRequests, inferTestAwareness, initOrgConfig, initPlaybooks, initRetrievalEvals, initializeSchema, isGitHubGraphQLResourceLimitError, isGitHubRateLimitError, isHardExcludedCodePath, isTestFilePath, listFeedbackEvents, listOrgNames, listPlaybooks, loadCurrentCodeSnapshot, loadOrgConfig, loadTeamRulesFile, maybeLoadOrgConfig, mergeAnchorMcpConfig, normalizePullRequest, openAnchorDatabase, openOrgDatabase, orgCloneStateFromResult, orgConfigPath, orgDatabasePath, orgRepoLocalPath, orgReposRoot, orgRoot, paginateWithGitHubRateLimit, parseGitHubRemote, planTask, plannedOrgCloneCommands, rankArchitecturePatterns, rankCodeChunks, rankRegressionEvents, rankRelevantTests, rankTeamRules, rankWisdomUnits, rebuildOrgGraph, recordFeedback, recordIndexRun, recordOrgGraphState, recordOrgIndexRun, redactSecrets, redactedHistoricalText, refreshTestCommands, refreshWatchIndex, removeOrgRepoConfig, replaceCodeIndex, repoAliasFromFullName, requestWithGitHubRateLimit, resolveGitHubToken, resolveOrgForTool, resolvePullRequestDetailConcurrency, resolvePullRequestFetchLimit, reviewDiff, runAnchorCi, runDoctor, runRetrievalEvals, sanitizeHistoricalText, saveGraphQLFetchCheckpoint, saveOrgConfig, shouldFallbackToRestAfterGraphQLError, shouldSyncSince, sourceTypeLabel, stripPromptInjection, suggestPlaybooks, suggestTeamRules, syncOrgConfigToDatabase, syncPlaybooksToDatabase, tokenizeSearchText, truncateText, uniqueStrings, updateGitHubGraphQLRateLimitState, updateOrgRepoState, updateSyncState, upsertPullRequest, validateOrgName, validateOrgRepoFullName, validateOrgRepoGroup, validateTeamRulesFile, watchCodebase };
|
|
1524
|
+
export { ANCHOR_CURSOR_RULE, ANCHOR_EVALS_FILE, ANCHOR_PLAYBOOKS_FILE, type AnchorCiInput, type AnchorContextInput, type AnchorDatabase, type AnchorExplainFileInput, type AnchorIndexHealth, type AnchorOrgConfig, type AnchorOrgRepoConfig, type AnchorReviewDiffInput, type ArchitectureArea, type ArchitectureCheckInput, type ArchitectureComponent, type ArchitectureContextInput, type ArchitectureIndexData, type ArchitectureMap, type ArchitectureMapEdge, type ArchitectureMapFormat, type ArchitectureMapInput, type ArchitectureMapNode, 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 FeedbackEvent, type FeedbackRating, type FetchMergedPullRequestsGraphQLOptions, type FetchPullRequestsOptions, type FetchPullRequestsProgress, type FormattedResult, type FreshnessResult, type FreshnessStatus, type GitCommandRunner, type GitHubFetchBackend, GitHubGraphQLError, type GitHubGraphQLFetch, type GitHubGraphQLFetchCheckpoint, type GitHubGraphQLRateLimitState, type GitHubGraphQLResponse, 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 OnboardingInput, type OnboardingPack, type OrgAnomaly, type OrgAnomalyCategory, type OrgApiConsumer, type OrgCloneProgress, type OrgCloneResult, type OrgCrossRepoEdge, type OrgCrossRepoRelationship, type OrgFormattedResult, type OrgGraphProgress, type OrgGraphResult, type OrgGraphState, type OrgImpactResult, type OrgIndexOptions, type OrgIndexResult, type OrgRepoCloneState, type OrgRepoGroup, type OrgRepoIndexResult, type OrgStatus, type Playbook, type PullRequestComment, type PullRequestCommit, type PullRequestFile, type PullRequestPerson, type PullRequestRecord, type RankedArchitecturePattern, type RankedCodeChunk, type RankedRegressionEvent, type RankedTeamRule, type RankedTestFile, type RankedWisdomUnit, type RebuildOrgGraphOptions, type RegressionEvent, type ReliabilityGate, type ReliabilityGateRejection, type ReliabilityGateResult, type ReliabilityGateStatus, type RetrievalEvalCase, type RetrievalEvalResult, type RetrievalEvalRunResult, type RulesAddInput, type RulesAddResult, type RulesEvidenceCheckResult, type RulesInitResult, type RulesSuggestOptions, SCHEMA_SQL, type SearchHistoryInput, type SemanticStatus, type SourceType, type SuggestedPrompt, TEAM_RULES_FILE, type TaskPlan, type TeamRule, type TeamRuleSuggestion, type TeamRulesValidationResult, type TestCommand, type TestFileRecord, type TestLink, type WatchRefreshInput, type WisdomCategory, type WisdomUnit, addOrgRepoConfig, addRetrievalEval, addTeamRule, anchorMcpEntry, architectureFilesFromDiff, buildAnchorContextResult, buildArchitectureIndex, buildArchitectureMap, buildFtsQuery, buildOnboardingPack, buildOrgContextResult, buildQueryTerms, calculateCoverage, canonicalizeText, categorizeWisdom, checkArchitecture, checkOrgImpact, checkSchema, checkTeamRuleEvidence, chunkCodeFile, chunkHistoricalText, claimKeyFor, clampMaxResults, classifyArchitectureArea, clearGraphQLFetchCheckpoint, clipSentence, cloneOrPullOrgRepo, cloneOrgRepos, confidenceAtLeast, confidenceLevelFor, confidenceRank, confidenceReasonsFor, countValidTeamRules, createGitHubClient, createGitHubGraphQLRequester, defaultDatabasePath, defaultGitCommandRunner, defaultOrgBaseDir, defaultOrgCloneUrl, detectGitHubRepo, detectGitRoot, detectTestCommands, detectTestCommandsForFile, discoverCodeFiles, emptyCodeIndexSummary, ensureAnchorGitExclude, ensureCursorConfig, ensureCursorRule, ensureRepository, ensureTeamRulesFile, evaluateFreshness, evaluateIndexHealth, evaluateReliabilityGate, evidenceForWisdom, explainFile, extractCodeImports, extractCodeSymbols, extractRegressionEvents, extractSymbols, extractWisdomUnits, feedbackAdjustedScore, fetchMergedPullRequests, fetchMergedPullRequestsWithGraphQL, fetchPullRequestDetails, filesFromDiff, findOrgApiConsumers, formatAnchorContext, formatIndexStatus, formatSearchHistory, getAnchorIndexHealth, getArchitectureContext, getArchitectureMapContext, getGitHubRateLimitDelayMs, getGraphQLFetchCheckpoint, getIndexStatus, getLastSyncTime, getOrgArchitectureMap, getOrgGraphCounts, getOrgGraphState, getOrgRepoState, getOrgStatus, getPlaybook, getSemanticStatus, getSuggestedPromptTexts, getSuggestedPrompts, getWisdomCategoryCounts, githubAuthFixMessage, graphQLFetchCheckpointScope, hasHighSignalLanguage, indexCodebase, indexOrgRepos, indexPullRequests, inferTestAwareness, initOrgConfig, initPlaybooks, initRetrievalEvals, initializeSchema, isGitHubGraphQLResourceLimitError, isGitHubRateLimitError, isHardExcludedCodePath, isTestFilePath, listFeedbackEvents, listOrgNames, listPlaybooks, loadCurrentCodeSnapshot, loadOrgConfig, loadTeamRulesFile, maybeLoadOrgConfig, mergeAnchorMcpConfig, normalizePullRequest, openAnchorDatabase, openOrgDatabase, orgCloneStateFromResult, orgConfigPath, orgDatabasePath, orgRepoLocalPath, orgReposRoot, orgRoot, paginateWithGitHubRateLimit, parseGitHubRemote, planTask, plannedOrgCloneCommands, rankArchitecturePatterns, rankCodeChunks, rankRegressionEvents, rankRelevantTests, rankTeamRules, rankWisdomUnits, rebuildOrgGraph, recordFeedback, recordIndexRun, recordOrgGraphState, recordOrgIndexRun, redactSecrets, redactedHistoricalText, refreshTestCommands, refreshWatchIndex, removeOrgRepoConfig, replaceCodeIndex, repoAliasFromFullName, requestWithGitHubRateLimit, resolveGitHubToken, resolveOrgForTool, resolvePullRequestDetailConcurrency, resolvePullRequestFetchLimit, reviewDiff, runAnchorCi, runDoctor, runRetrievalEvals, sanitizeHistoricalText, saveGraphQLFetchCheckpoint, saveOrgConfig, shouldFallbackToRestAfterGraphQLError, shouldSyncSince, sourceTypeLabel, stripPromptInjection, suggestPlaybooks, suggestTeamRules, syncOrgConfigToDatabase, syncPlaybooksToDatabase, tokenizeSearchText, truncateText, uniqueStrings, updateGitHubGraphQLRateLimitState, updateOrgRepoState, updateSyncState, upsertPullRequest, validateOrgName, validateOrgRepoFullName, validateOrgRepoGroup, validateTeamRulesFile, watchCodebase };
|
package/dist/index.js
CHANGED
|
@@ -7696,6 +7696,21 @@ function recordOrgGraphState(db, input) {
|
|
|
7696
7696
|
now
|
|
7697
7697
|
);
|
|
7698
7698
|
}
|
|
7699
|
+
function getOrgGraphState(db, org) {
|
|
7700
|
+
initializeSchema(db);
|
|
7701
|
+
const row = db.prepare("SELECT * FROM org_graph_state WHERE org = ?").get(org);
|
|
7702
|
+
if (!row) return void 0;
|
|
7703
|
+
return {
|
|
7704
|
+
org: row.org,
|
|
7705
|
+
lastBuiltAt: row.last_built_at ?? void 0,
|
|
7706
|
+
lastStatus: row.last_status ?? void 0,
|
|
7707
|
+
lastDurationMs: row.last_duration_ms ?? void 0,
|
|
7708
|
+
edgeCount: row.edge_count ?? void 0,
|
|
7709
|
+
apiContractCount: row.api_contract_count ?? void 0,
|
|
7710
|
+
apiConsumerCount: row.api_consumer_count ?? void 0,
|
|
7711
|
+
lastError: row.last_error ?? void 0
|
|
7712
|
+
};
|
|
7713
|
+
}
|
|
7699
7714
|
function count(db, table, where = "", params = []) {
|
|
7700
7715
|
const row = db.prepare(`SELECT COUNT(*) AS count FROM ${table} ${where}`).get(...params);
|
|
7701
7716
|
return row.count;
|
|
@@ -8359,6 +8374,7 @@ function rebuildOrgGraph(db, config, baseDirOrOptions) {
|
|
|
8359
8374
|
|
|
8360
8375
|
// src/org/index.ts
|
|
8361
8376
|
import fs13 from "fs";
|
|
8377
|
+
var ORG_SYNC_RESUME_WINDOW_MS = 12 * 60 * 60 * 1e3;
|
|
8362
8378
|
function readCommit(runner, cwd) {
|
|
8363
8379
|
try {
|
|
8364
8380
|
return runner("git", ["rev-parse", "HEAD"], { cwd });
|
|
@@ -8369,6 +8385,27 @@ function readCommit(runner, cwd) {
|
|
|
8369
8385
|
function missingCloneError(repo, localPath) {
|
|
8370
8386
|
return `Repo ${repo} is not cloned at ${localPath}. Run anchor org clone --repo ${repo} --org <org>.`;
|
|
8371
8387
|
}
|
|
8388
|
+
function latestIsoDate(dates) {
|
|
8389
|
+
return dates.filter((date) => Boolean(date)).sort().at(-1);
|
|
8390
|
+
}
|
|
8391
|
+
function graphIsFreshForState(input) {
|
|
8392
|
+
const latestRepoIndexAt = latestIsoDate([input.lastPrSyncAt, input.lastCodeIndexedAt]);
|
|
8393
|
+
return Boolean(
|
|
8394
|
+
latestRepoIndexAt && input.graphStatus === "success" && input.graphBuiltAt && input.graphBuiltAt >= latestRepoIndexAt
|
|
8395
|
+
);
|
|
8396
|
+
}
|
|
8397
|
+
function isWithinResumeWindow(date) {
|
|
8398
|
+
const parsed = Date.parse(date);
|
|
8399
|
+
return Number.isFinite(parsed) && Date.now() - parsed <= ORG_SYNC_RESUME_WINDOW_MS;
|
|
8400
|
+
}
|
|
8401
|
+
function shouldSkipPrFetchForResume(input) {
|
|
8402
|
+
if (input.options.command !== "org sync") return false;
|
|
8403
|
+
if (input.options.force || input.options.since || input.options.noGraph) return false;
|
|
8404
|
+
if (input.options.codeOnly || input.options.prsOnly) return false;
|
|
8405
|
+
if (!input.lastPrSyncAt) return false;
|
|
8406
|
+
if (!isWithinResumeWindow(input.lastPrSyncAt)) return false;
|
|
8407
|
+
return !graphIsFreshForState(input);
|
|
8408
|
+
}
|
|
8372
8409
|
async function indexOrgRepos(db, config, options = {}) {
|
|
8373
8410
|
initializeSchema(db);
|
|
8374
8411
|
syncOrgConfigToDatabase(db, config, options.baseDir);
|
|
@@ -8376,9 +8413,11 @@ async function indexOrgRepos(db, config, options = {}) {
|
|
|
8376
8413
|
(repo) => repo.enabled && (!options.repo || repo.fullName === options.repo)
|
|
8377
8414
|
);
|
|
8378
8415
|
const runner = options.runner ?? defaultGitCommandRunner;
|
|
8416
|
+
const fetchPullRequests = options.fetchPullRequests ?? fetchMergedPullRequests;
|
|
8379
8417
|
const auth = options.token ? { token: options.token } : resolveGitHubToken();
|
|
8380
8418
|
const results = [];
|
|
8381
8419
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
8420
|
+
const graphState = getOrgGraphState(db, config.org);
|
|
8382
8421
|
for (const repo of repos) {
|
|
8383
8422
|
const localPath = orgRepoLocalPath(config.org, repo, options.baseDir);
|
|
8384
8423
|
const repoStartedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -8390,16 +8429,32 @@ async function indexOrgRepos(db, config, options = {}) {
|
|
|
8390
8429
|
const state = getOrgRepoState(db, config.org, repo.fullName);
|
|
8391
8430
|
let history;
|
|
8392
8431
|
let code;
|
|
8432
|
+
let skippedHistory = false;
|
|
8433
|
+
let historySkippedReason;
|
|
8393
8434
|
const repoFailures = [];
|
|
8394
8435
|
if (!options.codeOnly) {
|
|
8395
|
-
if (
|
|
8436
|
+
if (shouldSkipPrFetchForResume({
|
|
8437
|
+
options,
|
|
8438
|
+
lastPrSyncAt: state?.lastPrSyncAt,
|
|
8439
|
+
lastCodeIndexedAt: state?.lastCodeIndexedAt,
|
|
8440
|
+
graphBuiltAt: graphState?.lastBuiltAt,
|
|
8441
|
+
graphStatus: graphState?.lastStatus
|
|
8442
|
+
})) {
|
|
8443
|
+
skippedHistory = true;
|
|
8444
|
+
historySkippedReason = "PR history already synced; resuming unfinished org graph/index work.";
|
|
8445
|
+
options.onFetchProgress?.({
|
|
8446
|
+
stage: "skipped_pull_request_fetch",
|
|
8447
|
+
repo: repo.fullName,
|
|
8448
|
+
reason: historySkippedReason
|
|
8449
|
+
});
|
|
8450
|
+
} else if (!auth.token) {
|
|
8396
8451
|
repoFailures.push(
|
|
8397
8452
|
"GitHub authentication is required for org PR indexing. Run gh auth login, or export GITHUB_TOKEN/GH_TOKEN with read-only access."
|
|
8398
8453
|
);
|
|
8399
8454
|
} else {
|
|
8400
8455
|
try {
|
|
8401
8456
|
const since = options.since ?? (options.command === "org sync" ? state?.lastPrSyncAt ?? getLastSyncTime(db, repo.fullName) : void 0);
|
|
8402
|
-
const pullRequests = await
|
|
8457
|
+
const pullRequests = await fetchPullRequests({
|
|
8403
8458
|
token: auth.token,
|
|
8404
8459
|
repo: repo.fullName,
|
|
8405
8460
|
limit: 200,
|
|
@@ -8460,6 +8515,8 @@ async function indexOrgRepos(db, config, options = {}) {
|
|
|
8460
8515
|
results.push({
|
|
8461
8516
|
repo: repo.fullName,
|
|
8462
8517
|
skippedCode: Boolean(codeUnchanged || options.prsOnly),
|
|
8518
|
+
skippedHistory,
|
|
8519
|
+
historySkippedReason,
|
|
8463
8520
|
currentCommit: currentCommit2,
|
|
8464
8521
|
history,
|
|
8465
8522
|
code,
|
|
@@ -9478,6 +9535,7 @@ export {
|
|
|
9478
9535
|
getLastSyncTime,
|
|
9479
9536
|
getOrgArchitectureMap,
|
|
9480
9537
|
getOrgGraphCounts,
|
|
9538
|
+
getOrgGraphState,
|
|
9481
9539
|
getOrgRepoState,
|
|
9482
9540
|
getOrgStatus,
|
|
9483
9541
|
getPlaybook,
|