replit-tools 1.1.6 → 1.1.7
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 +78 -68
package/package.json
CHANGED
|
@@ -240,85 +240,95 @@ 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
|
-
const
|
|
261
|
-
const
|
|
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
|
+
|
|
247
|
+
# Prevent infinite refresh loops - only try once per shell session
|
|
248
|
+
if [ -z "${_REPLIT_TOOLS_AUTH_CHECKED}" ]; then
|
|
249
|
+
export _REPLIT_TOOLS_AUTH_CHECKED=1
|
|
250
|
+
|
|
251
|
+
if [ -f "${CREDENTIALS_FILE}" ] && [ -f "${AUTH_REFRESH_SCRIPT}" ]; then
|
|
252
|
+
# Source the auth refresh script to get the function
|
|
253
|
+
source "${AUTH_REFRESH_SCRIPT}"
|
|
254
|
+
|
|
255
|
+
# Check and refresh if needed (this handles all the logic)
|
|
256
|
+
if command -v node &> /dev/null; then
|
|
257
|
+
AUTH_INFO=$(node -e "
|
|
258
|
+
try {
|
|
259
|
+
const creds = require('${CREDENTIALS_FILE}');
|
|
260
|
+
const oauth = creds.claudeAiOauth;
|
|
261
|
+
const apiKey = creds.primaryApiKey;
|
|
262
|
+
if (apiKey) {
|
|
263
|
+
console.log('apikey:permanent');
|
|
264
|
+
} else if (oauth && oauth.expiresAt) {
|
|
265
|
+
const now = Date.now();
|
|
266
|
+
const remaining = Math.floor((oauth.expiresAt - now) / 1000 / 60 / 60);
|
|
267
|
+
const hasRefresh = oauth.refreshToken ? 'yes' : 'no';
|
|
268
|
+
console.log('oauth:' + remaining + ':' + hasRefresh);
|
|
269
|
+
} else {
|
|
270
|
+
console.log('none');
|
|
271
|
+
}
|
|
272
|
+
} catch(e) { console.log('error'); }
|
|
273
|
+
" 2>/dev/null)
|
|
274
|
+
|
|
275
|
+
IFS=':' read -r auth_type remaining has_refresh <<< "${AUTH_INFO}"
|
|
276
|
+
|
|
277
|
+
if [ "${auth_type}" = "apikey" ]; then
|
|
278
|
+
log "✅ Claude authentication: API key (permanent)"
|
|
279
|
+
elif [ "${auth_type}" = "oauth" ]; then
|
|
280
|
+
if [ "${remaining}" -le 0 ]; then
|
|
281
|
+
# Token expired - try to refresh once
|
|
282
|
+
if [ "${has_refresh}" = "yes" ]; then
|
|
283
|
+
log "⚠️ Token expired, attempting refresh..."
|
|
284
|
+
if refresh_token 2>/dev/null; then
|
|
285
|
+
NEW_REMAINING=$(node -e "
|
|
286
|
+
try {
|
|
287
|
+
const creds = require('${CREDENTIALS_FILE}');
|
|
288
|
+
const remaining = Math.floor((creds.claudeAiOauth.expiresAt - Date.now()) / 1000 / 60 / 60);
|
|
289
|
+
console.log(remaining);
|
|
290
|
+
} catch(e) { console.log('0'); }
|
|
291
|
+
" 2>/dev/null)
|
|
292
|
+
log "✅ Claude authentication: refreshed (${NEW_REMAINING}h remaining)"
|
|
293
|
+
else
|
|
294
|
+
log "❌ Token refresh failed - will use --dangerously-skip-permissions"
|
|
295
|
+
export CLAUDE_SKIP_AUTH=1
|
|
296
|
+
fi
|
|
287
297
|
else
|
|
288
|
-
log "❌ Token refresh
|
|
298
|
+
log "❌ Token expired (no refresh token) - will use --dangerously-skip-permissions"
|
|
299
|
+
export CLAUDE_SKIP_AUTH=1
|
|
289
300
|
fi
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
301
|
+
elif [ "${remaining}" -lt 2 ]; then
|
|
302
|
+
# Less than 2 hours - refresh proactively
|
|
303
|
+
if [ "${has_refresh}" = "yes" ]; then
|
|
304
|
+
log "🔄 Token expires in ${remaining}h, refreshing..."
|
|
305
|
+
if refresh_token 2>/dev/null; then
|
|
306
|
+
NEW_REMAINING=$(node -e "
|
|
307
|
+
try {
|
|
308
|
+
const creds = require('${CREDENTIALS_FILE}');
|
|
309
|
+
const remaining = Math.floor((creds.claudeAiOauth.expiresAt - Date.now()) / 1000 / 60 / 60);
|
|
310
|
+
console.log(remaining);
|
|
311
|
+
} catch(e) { console.log('0'); }
|
|
312
|
+
" 2>/dev/null)
|
|
313
|
+
log "✅ Claude authentication: refreshed (${NEW_REMAINING}h remaining)"
|
|
314
|
+
else
|
|
315
|
+
log "⚠️ Refresh failed, ${remaining}h remaining"
|
|
316
|
+
fi
|
|
306
317
|
else
|
|
307
|
-
log "⚠️
|
|
318
|
+
log "⚠️ Claude authentication: ${remaining}h remaining (no refresh token)"
|
|
308
319
|
fi
|
|
309
320
|
else
|
|
310
|
-
log "
|
|
321
|
+
log "✅ Claude authentication: valid (${remaining}h remaining)"
|
|
311
322
|
fi
|
|
312
|
-
|
|
313
|
-
log "
|
|
323
|
+
elif [ "${auth_type}" = "none" ] || [ "${auth_type}" = "error" ]; then
|
|
324
|
+
log "⚠️ No valid auth found - will use --dangerously-skip-permissions"
|
|
325
|
+
export CLAUDE_SKIP_AUTH=1
|
|
314
326
|
fi
|
|
315
|
-
elif [ "${auth_type}" = "error" ]; then
|
|
316
|
-
log "⚠️ Could not read credentials"
|
|
317
327
|
fi
|
|
328
|
+
elif [ ! -f "${CREDENTIALS_FILE}" ]; then
|
|
329
|
+
log "⚠️ No credentials - will use --dangerously-skip-permissions"
|
|
330
|
+
export CLAUDE_SKIP_AUTH=1
|
|
318
331
|
fi
|
|
319
|
-
elif [ ! -f "${CREDENTIALS_FILE}" ]; then
|
|
320
|
-
log "⚠️ No Claude credentials found. Run 'claude login' to authenticate"
|
|
321
|
-
log " 💡 Tip: Run 'claude setup-token' for a long-lived token"
|
|
322
332
|
fi
|
|
323
333
|
|
|
324
334
|
# =============================================================================
|