@link-assistant/hive-mind 1.69.9 → 1.69.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/CHANGELOG.md +20 -0
- package/CLAUDE.md +5 -0
- package/package.json +1 -1
- package/src/github-rate-limit.lib.mjs +126 -1
- package/src/solve.config.lib.mjs +5 -0
- package/src/solve.mjs +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @link-assistant/hive-mind
|
|
2
2
|
|
|
3
|
+
## 1.69.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7d58938: feat: add opt-in GitHub API rate-limit usage logging
|
|
8
|
+
|
|
9
|
+
Adds optional logging of current GitHub API rate-limit usage through the centralized `gh` retry wrapper so every wrapped GitHub CLI call can report quota usage while debugging.
|
|
10
|
+
|
|
11
|
+
Features:
|
|
12
|
+
- Disabled by default for backward compatibility
|
|
13
|
+
- Enable with `--github-rate-limits-logging` when debugging API usage
|
|
14
|
+
- Logs current `core`, `graphql`, and `search` rate-limit buckets after each centralized wrapped `gh` attempt
|
|
15
|
+
- Keeps the logging probe non-fatal so quota logging cannot break solve workflows
|
|
16
|
+
|
|
17
|
+
Example output:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
📊 GitHub rate limits after $gh (gh api repos): core: 780/5000 used (+29 since last check), 4220 remaining, resets 2026-05-12T10:30:00.000Z; graphql: 10/5000 used (no change), 4990 remaining, resets 2026-05-12T10:30:00.000Z
|
|
21
|
+
```
|
|
22
|
+
|
|
3
23
|
## 1.69.9
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/CLAUDE.md
ADDED
package/package.json
CHANGED
|
@@ -24,8 +24,16 @@ import { limitReset, retryLimits } from './config.lib.mjs';
|
|
|
24
24
|
|
|
25
25
|
const exec = promisify(execCb);
|
|
26
26
|
|
|
27
|
+
const GITHUB_RATE_LIMIT_USAGE_RESOURCES = ['core', 'graphql', 'search'];
|
|
27
28
|
const RATE_LIMIT_PATTERNS = ['api rate limit exceeded', 'rate limit exceeded', 'you have exceeded a secondary rate limit', 'secondary rate limit', 'abuse detection', 'was submitted too quickly'];
|
|
28
29
|
|
|
30
|
+
const githubRateLimitLogging = {
|
|
31
|
+
enabled: false,
|
|
32
|
+
log: null,
|
|
33
|
+
fetchUsage: null,
|
|
34
|
+
lastUsageByResource: null,
|
|
35
|
+
};
|
|
36
|
+
|
|
29
37
|
/**
|
|
30
38
|
* Pull every plausible string out of a thrown error/result so pattern matches
|
|
31
39
|
* survive whatever shape the upstream caller gave us (Error, exec result with
|
|
@@ -120,6 +128,116 @@ export const fetchNextRateLimitReset = async () => {
|
|
|
120
128
|
}
|
|
121
129
|
};
|
|
122
130
|
|
|
131
|
+
const toFiniteNumber = value => {
|
|
132
|
+
const number = Number(value);
|
|
133
|
+
return Number.isFinite(number) ? number : null;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const normalizeRateLimitUsageEntry = (resource, entry) => {
|
|
137
|
+
if (!resource || !entry) return null;
|
|
138
|
+
const limit = toFiniteNumber(entry.limit);
|
|
139
|
+
const used = toFiniteNumber(entry.used);
|
|
140
|
+
const remaining = toFiniteNumber(entry.remaining);
|
|
141
|
+
const reset = toFiniteNumber(entry.reset);
|
|
142
|
+
if (limit === null || used === null || remaining === null) return null;
|
|
143
|
+
return {
|
|
144
|
+
resource,
|
|
145
|
+
limit,
|
|
146
|
+
used,
|
|
147
|
+
remaining,
|
|
148
|
+
reset,
|
|
149
|
+
resetDate: reset === null ? null : new Date(reset * 1000),
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Fetch the current GitHub API usage buckets we commonly exercise via `gh`.
|
|
155
|
+
* This intentionally calls `gh api rate_limit` directly so the logging probe
|
|
156
|
+
* does not recursively pass through the retry/logging wrapper it supports.
|
|
157
|
+
*
|
|
158
|
+
* @returns {Promise<Array<{resource: string, limit: number, used: number, remaining: number, reset: number|null, resetDate: Date|null}>>}
|
|
159
|
+
*/
|
|
160
|
+
export const fetchGitHubRateLimitUsage = async () => {
|
|
161
|
+
try {
|
|
162
|
+
// eslint-disable-next-line gh-rate-limit/no-direct-gh-exec -- this IS the centralized rate-limit helper; routing through itself would recurse.
|
|
163
|
+
const { stdout } = await exec('gh api rate_limit');
|
|
164
|
+
const data = JSON.parse(stdout);
|
|
165
|
+
const resources = data?.resources || {};
|
|
166
|
+
return GITHUB_RATE_LIMIT_USAGE_RESOURCES.map(resource => normalizeRateLimitUsageEntry(resource, resources[resource])).filter(Boolean);
|
|
167
|
+
} catch {
|
|
168
|
+
return [];
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Enable optional debug logging of actual GitHub API quota usage after each
|
|
174
|
+
* centralized `gh` wrapper attempt. Disabled by default for backward
|
|
175
|
+
* compatibility and to avoid extra `gh api rate_limit` probes in normal runs.
|
|
176
|
+
*
|
|
177
|
+
* @param {object} [options]
|
|
178
|
+
* @param {boolean} [options.enabled=false]
|
|
179
|
+
* @param {(msg: string, options?: object) => Promise<void>|void} [options.log]
|
|
180
|
+
* @param {() => Promise<Array<object>>} [options.fetchUsage] - injectable for tests.
|
|
181
|
+
*/
|
|
182
|
+
export const configureGitHubRateLimitLogging = ({ enabled = false, log = null, fetchUsage = null } = {}) => {
|
|
183
|
+
githubRateLimitLogging.enabled = enabled === true;
|
|
184
|
+
githubRateLimitLogging.log = typeof log === 'function' ? log : null;
|
|
185
|
+
githubRateLimitLogging.fetchUsage = typeof fetchUsage === 'function' ? fetchUsage : fetchGitHubRateLimitUsage;
|
|
186
|
+
githubRateLimitLogging.lastUsageByResource = null;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export const isGitHubRateLimitLoggingEnabled = () => githubRateLimitLogging.enabled;
|
|
190
|
+
|
|
191
|
+
const formatUsageReset = entry => {
|
|
192
|
+
if (!(entry.resetDate instanceof Date) || Number.isNaN(entry.resetDate.getTime())) return '';
|
|
193
|
+
return `, resets ${entry.resetDate.toISOString()}`;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const formatRateLimitUsageEntry = entry => {
|
|
197
|
+
const previous = githubRateLimitLogging.lastUsageByResource?.[entry.resource];
|
|
198
|
+
let deltaText = '';
|
|
199
|
+
if (previous && Number.isFinite(previous.used)) {
|
|
200
|
+
const delta = entry.used - previous.used;
|
|
201
|
+
if (delta > 0) {
|
|
202
|
+
deltaText = ` (+${delta} since last check)`;
|
|
203
|
+
} else if (delta === 0) {
|
|
204
|
+
deltaText = ' (no change)';
|
|
205
|
+
} else {
|
|
206
|
+
deltaText = ' (usage reset since last check)';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return `${entry.resource}: ${entry.used}/${entry.limit} used${deltaText}, ${entry.remaining} remaining${formatUsageReset(entry)}`;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const safelyLogRateLimitUsage = async (logger, message, options) => {
|
|
213
|
+
try {
|
|
214
|
+
await Promise.resolve(logger(message, options));
|
|
215
|
+
} catch {
|
|
216
|
+
// Debug logging must never replace the original gh result or error.
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export const logGitHubRateLimitUsage = async ({ label = 'gh' } = {}) => {
|
|
221
|
+
if (!githubRateLimitLogging.enabled) return [];
|
|
222
|
+
const logger = githubRateLimitLogging.log || (msg => console.warn(msg));
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
const rawUsage = await githubRateLimitLogging.fetchUsage();
|
|
226
|
+
const usage = (Array.isArray(rawUsage) ? rawUsage : []).map(entry => normalizeRateLimitUsageEntry(entry.resource || entry.name, entry)).filter(Boolean);
|
|
227
|
+
if (usage.length === 0) return [];
|
|
228
|
+
|
|
229
|
+
const details = usage.map(formatRateLimitUsageEntry).join('; ');
|
|
230
|
+
await safelyLogRateLimitUsage(logger, `📊 GitHub rate limits after ${label}: ${details}`);
|
|
231
|
+
githubRateLimitLogging.lastUsageByResource = Object.fromEntries(usage.map(entry => [entry.resource, entry]));
|
|
232
|
+
return usage;
|
|
233
|
+
} catch (error) {
|
|
234
|
+
if (global.verboseMode) {
|
|
235
|
+
await safelyLogRateLimitUsage(logger, `⚠️ GitHub rate-limit logging failed after ${label}: ${error.message}`, { verbose: true });
|
|
236
|
+
}
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
123
241
|
/**
|
|
124
242
|
* Compute the absolute wait deadline that satisfies issue #1726:
|
|
125
243
|
* reset + bufferMs (default 10 min) + random(0..jitterMs) (default 0-5 min)
|
|
@@ -226,8 +344,11 @@ export const ghWithRateLimitRetry = async (fn, options = {}) => {
|
|
|
226
344
|
|
|
227
345
|
for (let i = 0; i < hardCap; i++) {
|
|
228
346
|
try {
|
|
229
|
-
|
|
347
|
+
const result = await fn();
|
|
348
|
+
await logGitHubRateLimitUsage({ label });
|
|
349
|
+
return result;
|
|
230
350
|
} catch (error) {
|
|
351
|
+
await logGitHubRateLimitUsage({ label });
|
|
231
352
|
lastError = error;
|
|
232
353
|
|
|
233
354
|
if (isRateLimitError(error)) {
|
|
@@ -324,6 +445,10 @@ export default {
|
|
|
324
445
|
isTransientNetworkError,
|
|
325
446
|
parseRateLimitReset,
|
|
326
447
|
fetchNextRateLimitReset,
|
|
448
|
+
fetchGitHubRateLimitUsage,
|
|
449
|
+
configureGitHubRateLimitLogging,
|
|
450
|
+
isGitHubRateLimitLoggingEnabled,
|
|
451
|
+
logGitHubRateLimitUsage,
|
|
327
452
|
computeRateLimitWait,
|
|
328
453
|
ghWithRateLimitRetry,
|
|
329
454
|
execGhWithRetry,
|
package/src/solve.config.lib.mjs
CHANGED
|
@@ -461,6 +461,11 @@ export const SOLVE_OPTION_DEFINITIONS = {
|
|
|
461
461
|
description: 'Include prompt to check related/sibling pull requests when studying related work. Enabled by default, use --no-prompt-check-sibling-pull-requests to disable.',
|
|
462
462
|
default: true,
|
|
463
463
|
},
|
|
464
|
+
'github-rate-limits-logging': {
|
|
465
|
+
type: 'boolean',
|
|
466
|
+
description: 'Log GitHub API rate-limit usage after each centralized gh command retry wrapper call. Disabled by default; use --github-rate-limits-logging to enable.',
|
|
467
|
+
default: false,
|
|
468
|
+
},
|
|
464
469
|
'prompt-experiments-folder': {
|
|
465
470
|
type: 'string',
|
|
466
471
|
description: 'Path to experiments folder used in system prompt. Set to empty string to disable experiments folder prompt. Default: ./experiments',
|
package/src/solve.mjs
CHANGED
|
@@ -8,7 +8,7 @@ await handleSolveEarlyExit(earlyArgs);
|
|
|
8
8
|
const { use } = eval(await (await fetch('https://unpkg.com/use-m/use.js')).text());
|
|
9
9
|
globalThis.use = use;
|
|
10
10
|
const { $: __rawDollar$ } = await use('command-stream');
|
|
11
|
-
const { wrapDollarWithGhRetry } = await import('./github-rate-limit.lib.mjs');
|
|
11
|
+
const { configureGitHubRateLimitLogging, wrapDollarWithGhRetry } = await import('./github-rate-limit.lib.mjs');
|
|
12
12
|
const $ = wrapDollarWithGhRetry(__rawDollar$);
|
|
13
13
|
const config = await import('./solve.config.lib.mjs');
|
|
14
14
|
const { initializeConfig, parseArguments } = config;
|
|
@@ -86,6 +86,10 @@ global.verboseMode = argv.verbose;
|
|
|
86
86
|
|
|
87
87
|
setupVerboseLogInterceptor(); // Issue #1466: capture [VERBOSE] output in log files
|
|
88
88
|
setupStdioLogInterceptor(); // Issue #1549: capture ALL terminal output in log file
|
|
89
|
+
configureGitHubRateLimitLogging({
|
|
90
|
+
enabled: argv.githubRateLimitsLogging === true,
|
|
91
|
+
log,
|
|
92
|
+
});
|
|
89
93
|
|
|
90
94
|
// Early logs go to cwd; custom log dir takes effect after argv is parsed
|
|
91
95
|
// Conditionally import tool-specific functions after argv is parsed
|