@link-assistant/hive-mind 1.35.0 ā 1.35.1
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 +8 -0
- package/package.json +1 -1
- package/src/github.lib.mjs +16 -11
- package/src/limits.lib.mjs +100 -12
- package/src/model-info.lib.mjs +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @link-assistant/hive-mind
|
|
2
2
|
|
|
3
|
+
## 1.35.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix misleading "Retry after: 0s" message in /limits command when Claude Usage API returns 429. Now shows "Try again later." for zero/missing retry-after values, or proper reset time format (e.g., "Resets in 5m (Mar 19, 8:00pm UTC)") for meaningful values. Also caches 429 errors to prevent repeated requests to rate-limited endpoint, and adds full request/response verbose logging for debugging.
|
|
8
|
+
|
|
9
|
+
improve Solution Draft Log comment formatting for better readability (issue #1448)
|
|
10
|
+
|
|
3
11
|
## 1.35.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/package.json
CHANGED
package/src/github.lib.mjs
CHANGED
|
@@ -22,7 +22,7 @@ const buildCostInfoString = (totalCostUSD, anthropicTotalCostUSD, pricingInfo) =
|
|
|
22
22
|
const hasPricing = pricingInfo && (pricingInfo.modelName || pricingInfo.tokenUsage || pricingInfo.isFreeModel || pricingInfo.isOpencodeFreeModel);
|
|
23
23
|
const hasOpencodeCost = pricingInfo?.opencodeCost !== null && pricingInfo?.opencodeCost !== undefined;
|
|
24
24
|
if (!hasPublic && !hasAnthropic && !hasPricing && !hasOpencodeCost) return '';
|
|
25
|
-
let costInfo = '\n\nš° **Cost estimation:**';
|
|
25
|
+
let costInfo = '\n\n### š° **Cost estimation:**';
|
|
26
26
|
if (pricingInfo?.modelName) {
|
|
27
27
|
costInfo += `\n- Model: ${pricingInfo.modelName}`;
|
|
28
28
|
if (pricingInfo.provider) costInfo += `\n- Provider: ${pricingInfo.provider}`;
|
|
@@ -557,7 +557,7 @@ ${logContent}
|
|
|
557
557
|
logComment = `## ā ļø Solution Draft Finished with Errors
|
|
558
558
|
This log file contains the complete execution trace of the AI ${targetType === 'pr' ? 'solution draft' : 'analysis'} process.${costInfo}${modelInfoString}
|
|
559
559
|
|
|
560
|
-
**Note**: The session encountered errors during execution, but some work may have been completed. Please review the changes carefully.
|
|
560
|
+
> **Note**: The session encountered errors during execution, but some work may have been completed. Please review the changes carefully.
|
|
561
561
|
|
|
562
562
|
<details>
|
|
563
563
|
<summary>Click to expand solution draft log (${Math.round(logStats.size / 1024)}KB)</summary>
|
|
@@ -714,8 +714,8 @@ ${resumeCommand}
|
|
|
714
714
|
|
|
715
715
|
logUploadComment += `${modelInfoString}
|
|
716
716
|
|
|
717
|
-
š **Execution log uploaded as ${uploadTypeLabel}${chunkInfo}** (${Math.round(logStats.size / 1024)}KB)
|
|
718
|
-
|
|
717
|
+
### š **Execution log uploaded as ${uploadTypeLabel}${chunkInfo}** (${Math.round(logStats.size / 1024)}KB)
|
|
718
|
+
- [View complete execution log](${logUrl})
|
|
719
719
|
|
|
720
720
|
---
|
|
721
721
|
*This session was interrupted due to usage limits. You can resume once the limit resets.*`;
|
|
@@ -726,8 +726,10 @@ The automated solution draft encountered an error:
|
|
|
726
726
|
\`\`\`
|
|
727
727
|
${errorMessage}
|
|
728
728
|
\`\`\`${modelInfoString}
|
|
729
|
-
|
|
730
|
-
|
|
729
|
+
|
|
730
|
+
### š **Failure log uploaded as ${uploadTypeLabel}${chunkInfo}** (${Math.round(logStats.size / 1024)}KB)
|
|
731
|
+
- [View complete failure log](${logUrl})
|
|
732
|
+
|
|
731
733
|
---
|
|
732
734
|
*Now working session is ended, feel free to review and add any feedback on the solution draft.*`;
|
|
733
735
|
} else if (errorDuringExecution) {
|
|
@@ -736,10 +738,11 @@ ${errorMessage}
|
|
|
736
738
|
logUploadComment = `## ā ļø Solution Draft Finished with Errors
|
|
737
739
|
This log file contains the complete execution trace of the AI ${targetType === 'pr' ? 'solution draft' : 'analysis'} process.${costInfo}${modelInfoString}
|
|
738
740
|
|
|
739
|
-
**Note**: The session encountered errors during execution, but some work may have been completed. Please review the changes carefully.
|
|
741
|
+
> **Note**: The session encountered errors during execution, but some work may have been completed. Please review the changes carefully.
|
|
742
|
+
|
|
743
|
+
### š **Log file uploaded as ${uploadTypeLabel}${chunkInfo}** (${Math.round(logStats.size / 1024)}KB)
|
|
744
|
+
- [View complete solution draft log](${logUrl})
|
|
740
745
|
|
|
741
|
-
š **Log file uploaded as ${uploadTypeLabel}${chunkInfo}** (${Math.round(logStats.size / 1024)}KB)
|
|
742
|
-
š [View complete solution draft log](${logUrl})
|
|
743
746
|
---
|
|
744
747
|
*Now working session is ended, feel free to review and add any feedback on the solution draft.*`;
|
|
745
748
|
} else {
|
|
@@ -761,8 +764,10 @@ This log file contains the complete execution trace of the AI ${targetType === '
|
|
|
761
764
|
}
|
|
762
765
|
logUploadComment = `## ${title}
|
|
763
766
|
This log file contains the complete execution trace of the AI ${targetType === 'pr' ? 'solution draft' : 'analysis'} process.${costInfo}${modelInfoString}
|
|
764
|
-
${sessionNote}
|
|
765
|
-
|
|
767
|
+
${sessionNote}
|
|
768
|
+
### š **Log file uploaded as ${uploadTypeLabel}${chunkInfo}** (${Math.round(logStats.size / 1024)}KB)
|
|
769
|
+
- [View complete solution draft log](${logUrl})
|
|
770
|
+
|
|
766
771
|
---
|
|
767
772
|
*Now working session is ended, feel free to review and add any feedback on the solution draft.*`;
|
|
768
773
|
}
|
package/src/limits.lib.mjs
CHANGED
|
@@ -61,6 +61,63 @@ async function readCredentials(credentialsPath = DEFAULT_CREDENTIALS_PATH, verbo
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Format a retry-after value into a user-friendly message.
|
|
66
|
+
* The retry-after header can be either a number of seconds or an HTTP-date.
|
|
67
|
+
* Handles edge cases like 0, missing, or negative values gracefully.
|
|
68
|
+
*
|
|
69
|
+
* @param {string|null} retryAfter - Value of the retry-after header
|
|
70
|
+
* @returns {string} Formatted message part (e.g., " Resets in 2m 30s (Mar 19, 8:00pm UTC)" or " Try again later.")
|
|
71
|
+
* @see https://github.com/link-assistant/hive-mind/issues/1446
|
|
72
|
+
*/
|
|
73
|
+
export function formatRetryAfterMessage(retryAfter) {
|
|
74
|
+
if (retryAfter === null || retryAfter === undefined) {
|
|
75
|
+
return ' Try again later.';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Try to parse as number of seconds first
|
|
79
|
+
const seconds = Number(retryAfter);
|
|
80
|
+
if (!Number.isNaN(seconds) && seconds > 0) {
|
|
81
|
+
// Calculate reset time from now + seconds
|
|
82
|
+
const resetAt = dayjs().add(seconds, 'second').utc();
|
|
83
|
+
const resetTimeStr = resetAt.format('MMM D, h:mma');
|
|
84
|
+
|
|
85
|
+
// Format relative time
|
|
86
|
+
const totalMinutes = Math.floor(seconds / 60);
|
|
87
|
+
const remainingSeconds = Math.round(seconds % 60);
|
|
88
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
89
|
+
const minutes = totalMinutes % 60;
|
|
90
|
+
|
|
91
|
+
let relativeStr;
|
|
92
|
+
if (hours > 0) {
|
|
93
|
+
relativeStr = `${hours}h ${minutes}m`;
|
|
94
|
+
} else if (minutes > 0) {
|
|
95
|
+
relativeStr = remainingSeconds > 0 ? `${minutes}m ${remainingSeconds}s` : `${minutes}m`;
|
|
96
|
+
} else {
|
|
97
|
+
relativeStr = `${remainingSeconds}s`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return ` Resets in ${relativeStr} (${resetTimeStr} UTC)`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Try to parse as HTTP-date (e.g., "Wed, 21 Oct 2015 07:28:00 GMT")
|
|
104
|
+
const retryDate = dayjs(retryAfter);
|
|
105
|
+
if (retryDate.isValid()) {
|
|
106
|
+
const diffMs = retryDate.diff(dayjs());
|
|
107
|
+
if (diffMs > 0) {
|
|
108
|
+
const totalMinutes = Math.floor(diffMs / (1000 * 60));
|
|
109
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
110
|
+
const minutes = totalMinutes % 60;
|
|
111
|
+
const relativeStr = hours > 0 ? `${hours}h ${minutes}m` : `${minutes}m`;
|
|
112
|
+
const resetTimeStr = retryDate.utc().format('MMM D, h:mma');
|
|
113
|
+
return ` Resets in ${relativeStr} (${resetTimeStr} UTC)`;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Fallback for 0, negative, or unparseable values - don't show misleading info
|
|
118
|
+
return ' Try again later.';
|
|
119
|
+
}
|
|
120
|
+
|
|
64
121
|
/**
|
|
65
122
|
* Format an ISO date string to a human-readable reset time using dayjs
|
|
66
123
|
*
|
|
@@ -534,31 +591,47 @@ export async function getClaudeUsageLimits(verbose = false, credentialsPath = DE
|
|
|
534
591
|
};
|
|
535
592
|
}
|
|
536
593
|
|
|
594
|
+
const requestHeaders = {
|
|
595
|
+
Accept: 'application/json',
|
|
596
|
+
'Content-Type': 'application/json',
|
|
597
|
+
'User-Agent': 'claude-code/2.0.55',
|
|
598
|
+
Authorization: `Bearer ${accessToken}`,
|
|
599
|
+
'anthropic-beta': 'oauth-2025-04-20',
|
|
600
|
+
};
|
|
601
|
+
|
|
537
602
|
if (verbose) {
|
|
538
603
|
console.log('[VERBOSE] /limits fetching usage from API...');
|
|
604
|
+
console.log(`[VERBOSE] /limits API request: GET ${USAGE_API_ENDPOINT}`);
|
|
605
|
+
// Log request headers with sanitized Authorization (show only last 8 chars)
|
|
606
|
+
const sanitizedHeaders = { ...requestHeaders };
|
|
607
|
+
if (sanitizedHeaders.Authorization) {
|
|
608
|
+
const token = sanitizedHeaders.Authorization;
|
|
609
|
+
sanitizedHeaders.Authorization = `Bearer ...${token.slice(-8)}`;
|
|
610
|
+
}
|
|
611
|
+
console.log('[VERBOSE] /limits API request headers:', JSON.stringify(sanitizedHeaders, null, 2));
|
|
539
612
|
}
|
|
540
613
|
|
|
541
614
|
// Call the Anthropic OAuth usage API
|
|
542
615
|
const response = await fetch(USAGE_API_ENDPOINT, {
|
|
543
616
|
method: 'GET',
|
|
544
|
-
headers:
|
|
545
|
-
Accept: 'application/json',
|
|
546
|
-
'Content-Type': 'application/json',
|
|
547
|
-
'User-Agent': 'claude-code/2.0.55',
|
|
548
|
-
Authorization: `Bearer ${accessToken}`,
|
|
549
|
-
'anthropic-beta': 'oauth-2025-04-20',
|
|
550
|
-
},
|
|
617
|
+
headers: requestHeaders,
|
|
551
618
|
});
|
|
552
619
|
|
|
553
|
-
// Log HTTP response status for debugging (always, not just on error)
|
|
620
|
+
// Log HTTP response status and headers for debugging (always in verbose mode, not just on error)
|
|
554
621
|
if (verbose) {
|
|
555
622
|
console.log(`[VERBOSE] /limits API HTTP status: ${response.status} ${response.statusText}`);
|
|
623
|
+
// Log all response headers for debugging
|
|
624
|
+
const responseHeaders = {};
|
|
625
|
+
response.headers.forEach((value, key) => {
|
|
626
|
+
responseHeaders[key] = value;
|
|
627
|
+
});
|
|
628
|
+
console.log('[VERBOSE] /limits API response headers:', JSON.stringify(responseHeaders, null, 2));
|
|
556
629
|
}
|
|
557
630
|
|
|
558
631
|
if (!response.ok) {
|
|
559
632
|
const errorText = await response.text();
|
|
560
633
|
if (verbose) {
|
|
561
|
-
console.error('[VERBOSE] /limits API error:',
|
|
634
|
+
console.error('[VERBOSE] /limits API error body:', errorText);
|
|
562
635
|
}
|
|
563
636
|
|
|
564
637
|
// Check for specific error conditions
|
|
@@ -574,7 +647,7 @@ export async function getClaudeUsageLimits(verbose = false, credentialsPath = DE
|
|
|
574
647
|
const retryAfter = response.headers.get('retry-after');
|
|
575
648
|
return {
|
|
576
649
|
success: false,
|
|
577
|
-
error: `
|
|
650
|
+
error: `Claude Usage API access has reached rate limit.${formatRetryAfterMessage(retryAfter)}`,
|
|
578
651
|
};
|
|
579
652
|
}
|
|
580
653
|
|
|
@@ -587,7 +660,7 @@ export async function getClaudeUsageLimits(verbose = false, credentialsPath = DE
|
|
|
587
660
|
const data = await response.json();
|
|
588
661
|
|
|
589
662
|
if (verbose) {
|
|
590
|
-
console.log('[VERBOSE] /limits API response:', JSON.stringify(data, null, 2));
|
|
663
|
+
console.log('[VERBOSE] /limits API response body:', JSON.stringify(data, null, 2));
|
|
591
664
|
}
|
|
592
665
|
|
|
593
666
|
// Parse the API response
|
|
@@ -971,9 +1044,23 @@ export async function getCachedClaudeLimits(verbose = false) {
|
|
|
971
1044
|
if (verbose) console.log('[VERBOSE] /limits-cache: Using cached Claude limits (TTL: ' + Math.round(CACHE_TTL.USAGE_API / 60000) + ' minutes)');
|
|
972
1045
|
return cached;
|
|
973
1046
|
}
|
|
1047
|
+
// Also check if we have a cached rate-limit error to avoid hammering a 429'd endpoint
|
|
1048
|
+
const cachedError = cache.get('claude-rate-limited', CACHE_TTL.USAGE_API);
|
|
1049
|
+
if (cachedError) {
|
|
1050
|
+
if (verbose) console.log('[VERBOSE] /limits-cache: Using cached rate-limit error (avoiding repeated 429 requests)');
|
|
1051
|
+
return cachedError;
|
|
1052
|
+
}
|
|
974
1053
|
if (verbose) console.log('[VERBOSE] /limits-cache: Cache miss for Claude limits, fetching from API...');
|
|
975
1054
|
const result = await getClaudeUsageLimits(verbose);
|
|
976
|
-
if (result.success)
|
|
1055
|
+
if (result.success) {
|
|
1056
|
+
cache.set('claude', result, CACHE_TTL.USAGE_API);
|
|
1057
|
+
} else if (result.error && result.error.includes('Rate limited')) {
|
|
1058
|
+
// Cache rate-limit errors to prevent hammering the API
|
|
1059
|
+
// Use the same 20-minute TTL as successful responses
|
|
1060
|
+
// See: https://github.com/link-assistant/hive-mind/issues/1446
|
|
1061
|
+
cache.set('claude-rate-limited', result, CACHE_TTL.USAGE_API);
|
|
1062
|
+
if (verbose) console.log('[VERBOSE] /limits-cache: Cached rate-limit error for ' + Math.round(CACHE_TTL.USAGE_API / 60000) + ' minutes');
|
|
1063
|
+
}
|
|
977
1064
|
return result;
|
|
978
1065
|
}
|
|
979
1066
|
|
|
@@ -1040,6 +1127,7 @@ export default {
|
|
|
1040
1127
|
getProgressBar,
|
|
1041
1128
|
calculateTimePassedPercentage,
|
|
1042
1129
|
formatUsageMessage,
|
|
1130
|
+
formatRetryAfterMessage,
|
|
1043
1131
|
// Threshold constants for progress bar visualization
|
|
1044
1132
|
DISPLAY_THRESHOLDS,
|
|
1045
1133
|
// Cache management
|
package/src/model-info.lib.mjs
CHANGED
|
@@ -179,7 +179,7 @@ export const buildModelInfoString = ({ requestedModel = null, tool = null, prici
|
|
|
179
179
|
|
|
180
180
|
if (!hasRequested && !hasModelsUsed && !hasModelInfo && !hasPricingModel) return '';
|
|
181
181
|
|
|
182
|
-
let info = '\n\nš¤ **Models used:**';
|
|
182
|
+
let info = '\n\n### š¤ **Models used:**';
|
|
183
183
|
|
|
184
184
|
// Display tool name
|
|
185
185
|
if (tool) {
|
|
@@ -201,26 +201,26 @@ export const buildModelInfoString = ({ requestedModel = null, tool = null, prici
|
|
|
201
201
|
|
|
202
202
|
// Build main model line
|
|
203
203
|
const mainModelName = mainModelMeta?.name || mainModelId;
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
|
|
205
|
+
// Use "Model" label when only one model, "Main model" when multiple
|
|
206
|
+
const modelLabel = supportingEntries.length > 0 ? 'Main model' : 'Model';
|
|
206
207
|
|
|
207
208
|
if (mainMatches) {
|
|
208
|
-
info += `\n-
|
|
209
|
+
info += `\n- **${modelLabel}: ${mainModelName}** (\`${mainModelId}\`)`;
|
|
209
210
|
} else {
|
|
210
211
|
// Main model doesn't match requested - show warning
|
|
211
|
-
info += `\n-
|
|
212
|
+
info += `\n- **${modelLabel}: ${mainModelName}** (\`${mainModelId}\`)`;
|
|
212
213
|
if (hasRequested) {
|
|
213
214
|
info += `\n- ā ļø **Warning**: Main model \`${mainModelId}\` does not match requested model \`${requestedModel}\``;
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
|
|
217
|
-
// Display
|
|
218
|
+
// Display additional models
|
|
218
219
|
if (supportingEntries.length > 0) {
|
|
219
|
-
info += '\n-
|
|
220
|
+
info += '\n- **Additional models:**';
|
|
220
221
|
for (const entry of supportingEntries) {
|
|
221
222
|
const name = entry.modelInfo?.name || entry.modelId;
|
|
222
|
-
|
|
223
|
-
info += `\n - ${name} (\`${entry.modelId}\`${provider ? `, ${provider}` : ''})`;
|
|
223
|
+
info += `\n * **${name}** (\`${entry.modelId}\`)`;
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
} else if (hasModelInfo) {
|