replit-tools 1.1.6 → 1.1.8
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/package.json +1 -1
- package/scripts/setup-claude-code.sh +83 -68
package/package.json
CHANGED
|
@@ -240,85 +240,100 @@ if [[ ":$PATH:" != *":${LOCAL_BIN}:"* ]]; then
|
|
|
240
240
|
fi
|
|
241
241
|
|
|
242
242
|
# =============================================================================
|
|
243
|
-
# Step 6: Auto-refresh OAuth token if needed
|
|
243
|
+
# Step 6: Auto-refresh OAuth token if needed (with loop prevention)
|
|
244
244
|
# =============================================================================
|
|
245
245
|
CREDENTIALS_FILE="${CLAUDE_PERSISTENT}/.credentials.json"
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
246
|
+
AUTH_FAILED_MARKER="${REPLIT_TOOLS}/.auth-refresh-failed"
|
|
247
|
+
|
|
248
|
+
# Clear failed marker if it's more than 1 hour old (allow retry after cooldown)
|
|
249
|
+
if [ -f "${AUTH_FAILED_MARKER}" ]; then
|
|
250
|
+
marker_age=$(( $(date +%s) - $(stat -c %Y "${AUTH_FAILED_MARKER}" 2>/dev/null || echo "0") ))
|
|
251
|
+
if [ "${marker_age}" -gt 3600 ]; then
|
|
252
|
+
rm -f "${AUTH_FAILED_MARKER}" 2>/dev/null
|
|
253
|
+
fi
|
|
254
|
+
fi
|
|
255
|
+
|
|
256
|
+
# Skip auth refresh if we already failed recently (file-based lock prevents loops)
|
|
257
|
+
if [ ! -f "${AUTH_FAILED_MARKER}" ] && [ -f "${CREDENTIALS_FILE}" ] && [ -f "${AUTH_REFRESH_SCRIPT}" ]; then
|
|
258
|
+
# Source the auth refresh script to get the function
|
|
259
|
+
source "${AUTH_REFRESH_SCRIPT}"
|
|
260
|
+
|
|
261
|
+
# Check and refresh if needed (this handles all the logic)
|
|
262
|
+
if command -v node &> /dev/null; then
|
|
263
|
+
AUTH_INFO=$(node -e "
|
|
264
|
+
try {
|
|
265
|
+
const creds = require('${CREDENTIALS_FILE}');
|
|
266
|
+
const oauth = creds.claudeAiOauth;
|
|
267
|
+
const apiKey = creds.primaryApiKey;
|
|
268
|
+
if (apiKey) {
|
|
269
|
+
console.log('apikey:permanent');
|
|
270
|
+
} else if (oauth && oauth.expiresAt) {
|
|
271
|
+
const now = Date.now();
|
|
272
|
+
const remaining = Math.floor((oauth.expiresAt - now) / 1000 / 60 / 60);
|
|
273
|
+
const hasRefresh = oauth.refreshToken ? 'yes' : 'no';
|
|
274
|
+
console.log('oauth:' + remaining + ':' + hasRefresh);
|
|
275
|
+
} else {
|
|
276
|
+
console.log('none');
|
|
277
|
+
}
|
|
278
|
+
} catch(e) { console.log('error'); }
|
|
279
|
+
" 2>/dev/null)
|
|
280
|
+
|
|
281
|
+
IFS=':' read -r auth_type remaining has_refresh <<< "${AUTH_INFO}"
|
|
282
|
+
|
|
283
|
+
if [ "${auth_type}" = "apikey" ]; then
|
|
284
|
+
log "✅ Claude authentication: API key (permanent)"
|
|
285
|
+
elif [ "${auth_type}" = "oauth" ]; then
|
|
286
|
+
if [ "${remaining}" -le 0 ]; then
|
|
287
|
+
# Token expired - try to refresh once
|
|
288
|
+
if [ "${has_refresh}" = "yes" ]; then
|
|
289
|
+
log "⚠️ Token expired, attempting refresh..."
|
|
290
|
+
if refresh_token 2>/dev/null; then
|
|
291
|
+
NEW_REMAINING=$(node -e "
|
|
292
|
+
try {
|
|
293
|
+
const creds = require('${CREDENTIALS_FILE}');
|
|
294
|
+
const remaining = Math.floor((creds.claudeAiOauth.expiresAt - Date.now()) / 1000 / 60 / 60);
|
|
295
|
+
console.log(remaining);
|
|
296
|
+
} catch(e) { console.log('0'); }
|
|
297
|
+
" 2>/dev/null)
|
|
298
|
+
log "✅ Claude authentication: refreshed (${NEW_REMAINING}h remaining)"
|
|
299
|
+
else
|
|
300
|
+
log "❌ Token refresh failed - run 'claude login' when ready"
|
|
301
|
+
touch "${AUTH_FAILED_MARKER}"
|
|
302
|
+
fi
|
|
287
303
|
else
|
|
288
|
-
log "❌ Token refresh
|
|
304
|
+
log "❌ Token expired (no refresh token) - run 'claude login' when ready"
|
|
305
|
+
touch "${AUTH_FAILED_MARKER}"
|
|
289
306
|
fi
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
307
|
+
elif [ "${remaining}" -lt 2 ]; then
|
|
308
|
+
# Less than 2 hours - refresh proactively
|
|
309
|
+
if [ "${has_refresh}" = "yes" ]; then
|
|
310
|
+
log "🔄 Token expires in ${remaining}h, refreshing..."
|
|
311
|
+
if refresh_token 2>/dev/null; then
|
|
312
|
+
NEW_REMAINING=$(node -e "
|
|
313
|
+
try {
|
|
314
|
+
const creds = require('${CREDENTIALS_FILE}');
|
|
315
|
+
const remaining = Math.floor((creds.claudeAiOauth.expiresAt - Date.now()) / 1000 / 60 / 60);
|
|
316
|
+
console.log(remaining);
|
|
317
|
+
} catch(e) { console.log('0'); }
|
|
318
|
+
" 2>/dev/null)
|
|
319
|
+
log "✅ Claude authentication: refreshed (${NEW_REMAINING}h remaining)"
|
|
320
|
+
else
|
|
321
|
+
log "⚠️ Refresh failed, ${remaining}h remaining"
|
|
322
|
+
fi
|
|
306
323
|
else
|
|
307
|
-
log "⚠️
|
|
324
|
+
log "⚠️ Claude authentication: ${remaining}h remaining (no refresh token)"
|
|
308
325
|
fi
|
|
309
326
|
else
|
|
310
|
-
log "
|
|
327
|
+
log "✅ Claude authentication: valid (${remaining}h remaining)"
|
|
311
328
|
fi
|
|
312
|
-
|
|
313
|
-
log "
|
|
329
|
+
elif [ "${auth_type}" = "none" ] || [ "${auth_type}" = "error" ]; then
|
|
330
|
+
log "⚠️ No valid auth - run 'claude login' when ready"
|
|
314
331
|
fi
|
|
315
|
-
elif [ "${auth_type}" = "error" ]; then
|
|
316
|
-
log "⚠️ Could not read credentials"
|
|
317
332
|
fi
|
|
318
|
-
|
|
333
|
+
elif [ -f "${AUTH_FAILED_MARKER}" ]; then
|
|
334
|
+
log "⏭️ Skipping auth check (refresh failed recently, retry in 1h or run 'claude login')"
|
|
319
335
|
elif [ ! -f "${CREDENTIALS_FILE}" ]; then
|
|
320
|
-
log "⚠️ No
|
|
321
|
-
log " 💡 Tip: Run 'claude setup-token' for a long-lived token"
|
|
336
|
+
log "⚠️ No credentials - run 'claude login' when ready"
|
|
322
337
|
fi
|
|
323
338
|
|
|
324
339
|
# =============================================================================
|