@oss-autopilot/core 3.14.4 → 3.14.5

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.
@@ -6,6 +6,7 @@ import { adaptScoutLinkedPR, buildCandidateLinkedPR, createAutopilotScout, SEARC
6
6
  import { classifyLinkedPR, getStateManager } from '../core/index.js';
7
7
  import { gradeFromCandidate } from '../core/issue-grading.js';
8
8
  import { computeStrategy } from '../core/strategy.js';
9
+ import { refreshStarredReposIfStale } from '../core/starred-repos.js';
9
10
  import { debug, warn } from '../core/logger.js';
10
11
  const MODULE = 'search';
11
12
  /**
@@ -83,8 +84,15 @@ export async function runSearch(options) {
83
84
  // means scout searched with an empty skip list, so explicitly-skipped
84
85
  // issues may resurface — the envelope must say so, not just stderr.
85
86
  const bridgeDiagnostics = {};
86
- const scout = await createAutopilotScout(bridgeDiagnostics);
87
87
  const stateManager = getStateManager();
88
+ // Populate the starred-repo cache before the scout is created. Scout's
89
+ // discovery runs a starred-repo search phase, but it only fires when
90
+ // config.starredRepos is non-empty, and createAutopilotScout snapshots that
91
+ // config into the ScoutState. Without this refresh the starred phase is a
92
+ // silent no-op and discovery recycles the merged-PR repos every run. Fails
93
+ // soft, so a GitHub hiccup never blocks the search.
94
+ await refreshStarredReposIfStale(stateManager);
95
+ const scout = await createAutopilotScout(bridgeDiagnostics);
88
96
  // Derive personalization from local history (#1244). `computeStrategy`
89
97
  // returns null below the merged-PR floor — in that case we pass nothing
90
98
  // and scout falls back to the bridge-built preferences, which derive the
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Starred-repo cache refresh.
3
+ *
4
+ * Scout's discovery runs a starred-repo search phase (Phase 1), but it only
5
+ * fires when `config.starredRepos` is non-empty. The autopilot never populated
6
+ * that cache — `init` imports PR history only — so the starred phase was a
7
+ * silent no-op for every user and discovery kept recycling the merged-PR repos.
8
+ * This module fetches the user's stars from GitHub and fills the cache so the
9
+ * phase has input.
10
+ */
11
+ /** Minimal state surface this refresh needs — keeps it unit-testable. */
12
+ export interface StarredReposState {
13
+ isStarredReposStale(): boolean;
14
+ getStarredRepos(): string[];
15
+ setStarredRepos(repos: string[]): void;
16
+ }
17
+ /**
18
+ * Refresh the cached starred-repo list from GitHub when the cache is stale
19
+ * (>24h) or empty, so scout's starred-repo search phase has repos to query.
20
+ *
21
+ * Fails soft: a fetch error logs a warning and leaves the existing cache
22
+ * untouched, so a transient GitHub failure never blocks a search. Returns the
23
+ * number of repos cached after the call (freshly fetched, or the existing list
24
+ * when fresh / on error).
25
+ */
26
+ export declare function refreshStarredReposIfStale(state: StarredReposState): Promise<number>;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Starred-repo cache refresh.
3
+ *
4
+ * Scout's discovery runs a starred-repo search phase (Phase 1), but it only
5
+ * fires when `config.starredRepos` is non-empty. The autopilot never populated
6
+ * that cache — `init` imports PR history only — so the starred phase was a
7
+ * silent no-op for every user and discovery kept recycling the merged-PR repos.
8
+ * This module fetches the user's stars from GitHub and fills the cache so the
9
+ * phase has input.
10
+ */
11
+ import { getOctokit } from './github.js';
12
+ import { requireGitHubToken } from './auth.js';
13
+ import { debug, warn } from './logger.js';
14
+ const MODULE = 'starred-repos';
15
+ /** Page size for the starred-repos listing (GitHub max is 100). */
16
+ const PER_PAGE = 100;
17
+ /** Cap pages so an account that starred thousands of repos can't stall discovery. */
18
+ const MAX_PAGES = 5;
19
+ /** Page through the authenticated user's stars, collecting `owner/repo` names. */
20
+ async function collectStarredRepoNames(octokit) {
21
+ const repos = [];
22
+ let page = 0;
23
+ for await (const response of octokit.paginate.iterator(octokit.activity.listReposStarredByAuthenticatedUser, {
24
+ per_page: PER_PAGE,
25
+ // Default media type returns the repo object directly (with full_name);
26
+ // the star+timestamp media type would wrap it in { repo, starred_at }.
27
+ headers: { accept: 'application/vnd.github.v3+json' },
28
+ })) {
29
+ for (const repo of response.data) {
30
+ if (repo.full_name)
31
+ repos.push(repo.full_name);
32
+ }
33
+ page += 1;
34
+ if (page >= MAX_PAGES)
35
+ break;
36
+ }
37
+ return repos;
38
+ }
39
+ /**
40
+ * Refresh the cached starred-repo list from GitHub when the cache is stale
41
+ * (>24h) or empty, so scout's starred-repo search phase has repos to query.
42
+ *
43
+ * Fails soft: a fetch error logs a warning and leaves the existing cache
44
+ * untouched, so a transient GitHub failure never blocks a search. Returns the
45
+ * number of repos cached after the call (freshly fetched, or the existing list
46
+ * when fresh / on error).
47
+ */
48
+ export async function refreshStarredReposIfStale(state) {
49
+ if (!state.isStarredReposStale()) {
50
+ return state.getStarredRepos().length;
51
+ }
52
+ // A missing token is a configuration error, not a transient fetch failure —
53
+ // let it propagate so the caller surfaces the actionable auth message rather
54
+ // than silently degrading to an empty starred phase.
55
+ const token = requireGitHubToken();
56
+ // Only the network fetch is fail-soft: a transient GitHub error must not block
57
+ // the search. Token resolution (above) and the state write (below) stay
58
+ // outside the catch so genuine config/persistence faults aren't masked.
59
+ let repos;
60
+ try {
61
+ repos = await collectStarredRepoNames(getOctokit(token));
62
+ }
63
+ catch (err) {
64
+ warn(MODULE, `Failed to refresh starred repos; continuing with cached list (${state.getStarredRepos().length}): ${err instanceof Error ? err.message : String(err)}`);
65
+ return state.getStarredRepos().length;
66
+ }
67
+ // A successful-but-empty response (transient/partial API result) must not wipe
68
+ // a populated cache and then stamp it fresh for 24h — that would silently
69
+ // re-disable the very phase this refresh exists to feed. Keep the old list.
70
+ if (repos.length === 0) {
71
+ debug(MODULE, 'Starred-repo fetch returned 0; keeping existing cache');
72
+ return state.getStarredRepos().length;
73
+ }
74
+ state.setStarredRepos(repos);
75
+ debug(MODULE, `Refreshed starred repos from GitHub: ${repos.length} cached`);
76
+ return repos.length;
77
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oss-autopilot/core",
3
- "version": "3.14.4",
3
+ "version": "3.14.5",
4
4
  "description": "CLI and core library for managing open source contributions",
5
5
  "type": "module",
6
6
  "bin": {