@oss-autopilot/core 1.17.3 → 2.0.0

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.
Files changed (48) hide show
  1. package/dist/cli-registry.js +417 -326
  2. package/dist/cli.bundle.cjs +99 -96
  3. package/dist/commands/daily-render.d.ts +39 -0
  4. package/dist/commands/daily-render.js +189 -0
  5. package/dist/commands/dashboard-data.js +9 -3
  6. package/dist/commands/index.d.ts +4 -8
  7. package/dist/commands/index.js +3 -5
  8. package/dist/commands/list-move-tier.d.ts +46 -0
  9. package/dist/commands/list-move-tier.js +192 -0
  10. package/dist/commands/pr-template.js +2 -1
  11. package/dist/commands/state-cmd.d.ts +10 -1
  12. package/dist/commands/state-cmd.js +22 -3
  13. package/dist/commands/track.d.ts +7 -28
  14. package/dist/commands/track.js +8 -30
  15. package/dist/core/auth.d.ts +50 -0
  16. package/dist/core/auth.js +160 -0
  17. package/dist/core/concurrency.d.ts +7 -0
  18. package/dist/core/concurrency.js +9 -0
  19. package/dist/core/daily-logic.d.ts +10 -42
  20. package/dist/core/daily-logic.js +14 -201
  21. package/dist/core/dates.d.ts +37 -0
  22. package/dist/core/dates.js +60 -0
  23. package/dist/core/errors.d.ts +14 -0
  24. package/dist/core/errors.js +22 -0
  25. package/dist/core/gist-state-store.d.ts +48 -2
  26. package/dist/core/gist-state-store.js +120 -24
  27. package/dist/core/github-stats.js +1 -1
  28. package/dist/core/http-cache.js +1 -1
  29. package/dist/core/index.d.ts +5 -1
  30. package/dist/core/index.js +5 -1
  31. package/dist/core/issue-conversation.js +3 -2
  32. package/dist/core/paths.d.ts +68 -0
  33. package/dist/core/paths.js +106 -0
  34. package/dist/core/pr-monitor.js +3 -1
  35. package/dist/core/repo-score-manager.js +1 -1
  36. package/dist/core/state-persistence.js +1 -1
  37. package/dist/core/state.d.ts +16 -2
  38. package/dist/core/state.js +42 -7
  39. package/dist/core/types.d.ts +57 -0
  40. package/dist/core/urls.d.ts +63 -0
  41. package/dist/core/urls.js +101 -0
  42. package/dist/formatters/json.d.ts +464 -74
  43. package/dist/formatters/json.js +380 -0
  44. package/package.json +1 -1
  45. package/dist/commands/read.d.ts +0 -18
  46. package/dist/commands/read.js +0 -20
  47. package/dist/core/utils.d.ts +0 -303
  48. package/dist/core/utils.js +0 -529
@@ -1,303 +0,0 @@
1
- /**
2
- * Shared utility functions
3
- */
4
- /** Default concurrency limit for parallel GitHub API requests. */
5
- export declare const DEFAULT_CONCURRENCY = 5;
6
- /** Async sleep — exported for mockability in tests. */
7
- export declare function sleep(ms: number): Promise<void>;
8
- /**
9
- * Returns the oss-autopilot data directory path, creating it if it does not exist.
10
- *
11
- * The directory is located at `~/.oss-autopilot/` and serves as the root for
12
- * all persisted user data (state, backups, cache).
13
- *
14
- * @returns Absolute path to the data directory (e.g., `/Users/you/.oss-autopilot`)
15
- *
16
- * @example
17
- * const dir = getDataDir();
18
- * // "/Users/you/.oss-autopilot"
19
- */
20
- export declare function getDataDir(): string;
21
- /**
22
- * Returns the path to the state file (`~/.oss-autopilot/state.json`).
23
- *
24
- * Implicitly creates the data directory via {@link getDataDir} if it does not exist.
25
- *
26
- * @returns Absolute path to `state.json`
27
- *
28
- * @example
29
- * const statePath = getStatePath();
30
- * // "/Users/you/.oss-autopilot/state.json"
31
- */
32
- export declare function getStatePath(): string;
33
- /**
34
- * Returns the backup directory path, creating it if it does not exist.
35
- *
36
- * Located at `~/.oss-autopilot/backups/`. Used for automatic state backups
37
- * before each write operation.
38
- *
39
- * @returns Absolute path to the backups directory
40
- *
41
- * @example
42
- * const backupDir = getBackupDir();
43
- * // "/Users/you/.oss-autopilot/backups"
44
- */
45
- export declare function getBackupDir(): string;
46
- /**
47
- * Returns the HTTP cache directory path, creating it if it does not exist.
48
- *
49
- * Located at `~/.oss-autopilot/cache/`. Used by {@link HttpCache} to store
50
- * ETag-based response caches for GitHub API endpoints.
51
- *
52
- * @returns Absolute path to the cache directory
53
- *
54
- * @example
55
- * const cacheDir = getCacheDir();
56
- * // "/Users/you/.oss-autopilot/cache"
57
- */
58
- export declare function getCacheDir(): string;
59
- /**
60
- * Returns the path to the local Gist ID file (`~/.oss-autopilot/gist-id`).
61
- *
62
- * This file stores the GitHub Gist ID used by the Gist-based persistence layer,
63
- * avoiding a search-by-description API call on every session.
64
- *
65
- * Implicitly creates the data directory via {@link getDataDir} if it does not exist.
66
- *
67
- * @returns Absolute path to `gist-id`
68
- *
69
- * @example
70
- * const gistIdPath = getGistIdPath();
71
- * // "/Users/you/.oss-autopilot/gist-id"
72
- */
73
- export declare function getGistIdPath(): string;
74
- /**
75
- * Returns the path to the local state cache file (`~/.oss-autopilot/state-cache.json`).
76
- *
77
- * This file is a write-through cache of the Gist-hosted state, used as a fallback
78
- * when the GitHub API is unreachable (degraded mode).
79
- *
80
- * Implicitly creates the data directory via {@link getDataDir} if it does not exist.
81
- *
82
- * @returns Absolute path to `state-cache.json`
83
- *
84
- * @example
85
- * const cachePath = getStateCachePath();
86
- * // "/Users/you/.oss-autopilot/state-cache.json"
87
- */
88
- export declare function getStateCachePath(): string;
89
- /**
90
- * Represents a parsed GitHub pull request or issue URL.
91
- *
92
- * @property owner - The repository owner (e.g., `"facebook"`)
93
- * @property repo - The repository name (e.g., `"react"`)
94
- * @property number - The PR or issue number
95
- * @property type - Whether the URL points to a pull request or an issue
96
- */
97
- interface ParsedGitHubUrl {
98
- owner: string;
99
- repo: string;
100
- number: number;
101
- type: 'pull' | 'issues';
102
- }
103
- /**
104
- * Parses a GitHub pull request or issue URL into its components.
105
- *
106
- * Only accepts HTTPS GitHub URLs (`https://github.com/...`). Returns `null` for
107
- * invalid URLs, non-GitHub URLs, or URLs with invalid owner/repo characters.
108
- *
109
- * @param url - Full GitHub URL (e.g., `"https://github.com/owner/repo/pull/42"`)
110
- * @returns Parsed URL components, or `null` if the URL is invalid or not a recognized GitHub PR/issue URL
111
- *
112
- * @example
113
- * parseGitHubUrl('https://github.com/facebook/react/pull/123')
114
- * // { owner: "facebook", repo: "react", number: 123, type: "pull" }
115
- *
116
- * @example
117
- * parseGitHubUrl('https://github.com/vercel/next.js/issues/456')
118
- * // { owner: "vercel", repo: "next.js", number: 456, type: "issues" }
119
- *
120
- * @example
121
- * parseGitHubUrl('https://example.com/not-github')
122
- * // null
123
- */
124
- export declare function parseGitHubUrl(url: string): ParsedGitHubUrl | null;
125
- /**
126
- * Extracts the owner and repo from a GitHub web URL
127
- * (e.g. `https://github.com/owner/repo/pull/42`, `https://github.com/owner/repo/`).
128
- *
129
- * Unlike {@link parseGitHubUrl}, this does **not** require a PR or issue number in the URL.
130
- * Like `parseGitHubUrl`, it enforces an `https://github.com/` prefix.
131
- *
132
- * @param url - An HTTPS GitHub URL containing at least `github.com/owner/repo`
133
- * @returns `{ owner, repo }` or `null` if the URL cannot be parsed or contains invalid owner/repo characters
134
- *
135
- * @example
136
- * extractOwnerRepo('https://github.com/facebook/react/pull/123')
137
- * // { owner: "facebook", repo: "react" }
138
- *
139
- * @example
140
- * extractOwnerRepo('https://github.com/vercel/next.js/')
141
- * // { owner: "vercel", repo: "next.js" }
142
- */
143
- export declare function extractOwnerRepo(url: string): {
144
- owner: string;
145
- repo: string;
146
- } | null;
147
- /**
148
- * Calculates the number of whole days between two dates, clamped to zero.
149
- *
150
- * Returns `0` if `from` is after `to` — reversed ranges and clock-skew do not
151
- * produce negative values. Partial days are truncated (e.g., 1.9 days -> 1).
152
- *
153
- * @param from - The start date
154
- * @param to - The end date (defaults to the current date/time)
155
- * @returns Number of whole days between the two dates, minimum `0`
156
- *
157
- * @example
158
- * daysBetween(new Date('2024-01-01'), new Date('2024-01-10'))
159
- * // 9
160
- *
161
- * @example
162
- * daysBetween(new Date('2024-01-10'), new Date('2024-01-01'))
163
- * // 0 (clamped; reversed ranges are not signed)
164
- */
165
- export declare function daysBetween(from: Date, to?: Date): number;
166
- /**
167
- * Splits an `"owner/repo"` string into its owner and repo components.
168
- *
169
- * @param repoFullName - Full repository name in `"owner/repo"` format
170
- * @returns Object with `owner` and `repo` string properties
171
- * @throws {Error} If the input does not contain both an owner and repo separated by `/`
172
- *
173
- * @example
174
- * splitRepo('facebook/react')
175
- * // { owner: "facebook", repo: "react" }
176
- */
177
- export declare function splitRepo(repoFullName: string): {
178
- owner: string;
179
- repo: string;
180
- };
181
- /**
182
- * Case-insensitive check whether a repo owner matches the given GitHub username.
183
- * Used to skip a user's own repos (PRs to your own repos aren't OSS contributions).
184
- */
185
- export declare function isOwnRepo(owner: string, username: string): boolean;
186
- /**
187
- * Read the CLI package version from package.json relative to the running CLI bundle.
188
- * Resolves `../package.json` from `process.argv[1]` (the bundle entry point).
189
- * Falls back to '0.0.0' if the file is unreadable.
190
- */
191
- export declare function getCLIVersion(): string;
192
- /**
193
- * Formats a timestamp as a human-readable relative time string.
194
- *
195
- * Returns minutes for < 1 hour, hours for < 1 day, days for < 30 days,
196
- * and a locale-formatted date string for anything older.
197
- *
198
- * @param dateStr - ISO 8601 date string
199
- * @returns Relative time like `"5m ago"`, `"3h ago"`, `"12d ago"`, or a formatted date
200
- *
201
- * @example
202
- * formatRelativeTime('2024-01-20T10:00:00Z')
203
- * // "5d ago" (if called on Jan 25)
204
- *
205
- * @example
206
- * formatRelativeTime(new Date(Date.now() - 120000).toISOString())
207
- * // "2m ago"
208
- */
209
- export declare function formatRelativeTime(dateStr: string): string;
210
- /**
211
- * Creates a descending date comparator function for use with `Array.prototype.sort()`.
212
- *
213
- * Items with `null` or `undefined` dates are treated as epoch (sorted last).
214
- *
215
- * @param getDate - Accessor function that extracts a date value from each item
216
- * @returns A comparator function that sorts items from newest to oldest
217
- *
218
- * @example
219
- * const prs = [{ createdAt: '2024-01-01' }, { createdAt: '2024-06-15' }];
220
- * prs.sort(byDateDescending(pr => pr.createdAt));
221
- * // [{ createdAt: '2024-06-15' }, { createdAt: '2024-01-01' }]
222
- */
223
- export declare function byDateDescending<T>(getDate: (item: T) => string | number | null | undefined): (a: T, b: T) => number;
224
- /**
225
- * Retrieves a GitHub authentication token, checking sources in priority order.
226
- *
227
- * Checks `GITHUB_TOKEN` environment variable first, then falls back to `gh auth token`
228
- * from the GitHub CLI. The result is cached after the first successful lookup (or first
229
- * failed attempt), so subsequent calls are instant and do not spawn subprocesses.
230
- *
231
- * @returns The GitHub token string, or `null` if no token is available
232
- *
233
- * @example
234
- * const token = getGitHubToken();
235
- * if (token) {
236
- * // use token for API calls
237
- * }
238
- */
239
- export declare function getGitHubToken(): string | null;
240
- /**
241
- * Returns a GitHub token or throws an error with setup instructions.
242
- *
243
- * Delegates to {@link getGitHubToken} and throws if no token is found. Use this
244
- * in commands that cannot proceed without authentication.
245
- *
246
- * @returns The GitHub token string (guaranteed non-null)
247
- * @throws {ConfigurationError} If no token is available, with instructions for `gh auth login` or setting `GITHUB_TOKEN`
248
- *
249
- * @example
250
- * const token = requireGitHubToken(); // throws if not authenticated
251
- */
252
- export declare function requireGitHubToken(): string;
253
- /**
254
- * Resets the cached GitHub token and fetch-attempted flag.
255
- *
256
- * Intended for use in tests to ensure a clean state between test cases.
257
- * After calling this, the next call to {@link getGitHubToken} will re-fetch the token.
258
- *
259
- * @example
260
- * afterEach(() => {
261
- * resetGitHubTokenCache();
262
- * });
263
- */
264
- export declare function resetGitHubTokenCache(): void;
265
- /**
266
- * Asynchronous version of {@link getGitHubToken}.
267
- *
268
- * Uses `execFile` (non-blocking) instead of `execFileSync` to avoid blocking
269
- * the event loop during CLI cold start. Shares the same cache as the synchronous
270
- * version, so a successful async fetch makes subsequent sync calls instant.
271
- *
272
- * @returns The GitHub token string, or `null` if no token is available
273
- *
274
- * @example
275
- * const token = await getGitHubTokenAsync();
276
- * if (token) {
277
- * // use token for API calls
278
- * }
279
- */
280
- export declare function getGitHubTokenAsync(): Promise<string | null>;
281
- /**
282
- * Check whether the state file exists without creating the data directory.
283
- * Used for first-run detection in the CLI — we don't want to create
284
- * `~/.oss-autopilot/` just to check if the user has ever run the tool.
285
- */
286
- export declare function stateFileExists(): boolean;
287
- /**
288
- * Detect the authenticated GitHub username via the `gh` CLI.
289
- *
290
- * Runs `gh api user --jq '.login'` asynchronously and validates the result
291
- * against GitHub's username rules. Never throws — returns `null` on any failure
292
- * (gh not installed, not authenticated, invalid output, etc.).
293
- *
294
- * @returns The GitHub username string, or `null` if detection fails
295
- *
296
- * @example
297
- * const username = await detectGitHubUsername();
298
- * if (username) {
299
- * console.log(`Logged in as ${username}`);
300
- * }
301
- */
302
- export declare function detectGitHubUsername(): Promise<string | null>;
303
- export {};