replit-tools 1.1.5 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replit-tools",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "DATA Tools - One command to set up Claude Code and Codex CLI on Replit with full persistence",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -73,7 +73,8 @@ auto_update_scripts() {
73
73
  return 1
74
74
  }
75
75
 
76
- if [[ $- == *i* ]]; then
76
+ # Skip update check if we just re-sourced after an update
77
+ if [[ $- == *i* ]] && [ -z "${_REPLIT_TOOLS_UPDATED}" ]; then
77
78
  CURRENT_VERSION=""
78
79
  if [ -f "${VERSION_FILE}" ]; then
79
80
  CURRENT_VERSION=$(cat "${VERSION_FILE}" 2>/dev/null)
@@ -89,6 +90,11 @@ if [[ $- == *i* ]]; then
89
90
 
90
91
  if auto_update_scripts "${LATEST_VERSION}"; then
91
92
  echo " ✅ Updated to v${LATEST_VERSION}"
93
+ # Re-source the updated script so new code runs
94
+ export _REPLIT_TOOLS_UPDATED=1
95
+ source "${SCRIPTS_DIR}/setup-claude-code.sh"
96
+ unset _REPLIT_TOOLS_UPDATED
97
+ return 0 2>/dev/null || exit 0
92
98
  else
93
99
  echo " ⚠️ Auto-update failed, continuing with v${CURRENT_VERSION}"
94
100
  fi
@@ -96,6 +102,11 @@ if [[ $- == *i* ]]; then
96
102
  echo "📦 DATA Tools v${CURRENT_VERSION}"
97
103
  fi
98
104
  fi
105
+ elif [[ $- == *i* ]] && [ -n "${_REPLIT_TOOLS_UPDATED}" ]; then
106
+ # Show version after re-source
107
+ if [ -f "${VERSION_FILE}" ]; then
108
+ echo "📦 DATA Tools v$(cat "${VERSION_FILE}" 2>/dev/null)"
109
+ fi
99
110
  fi
100
111
 
101
112
  # =============================================================================
@@ -229,85 +240,95 @@ if [[ ":$PATH:" != *":${LOCAL_BIN}:"* ]]; then
229
240
  fi
230
241
 
231
242
  # =============================================================================
232
- # Step 6: Auto-refresh OAuth token if needed
243
+ # Step 6: Auto-refresh OAuth token if needed (with loop prevention)
233
244
  # =============================================================================
234
245
  CREDENTIALS_FILE="${CLAUDE_PERSISTENT}/.credentials.json"
235
- if [ -f "${CREDENTIALS_FILE}" ] && [ -f "${AUTH_REFRESH_SCRIPT}" ]; then
236
- # Source the auth refresh script to get the function
237
- source "${AUTH_REFRESH_SCRIPT}"
238
-
239
- # Check and refresh if needed (this handles all the logic)
240
- if command -v node &> /dev/null; then
241
- AUTH_INFO=$(node -e "
242
- try {
243
- const creds = require('${CREDENTIALS_FILE}');
244
- const oauth = creds.claudeAiOauth;
245
- const apiKey = creds.primaryApiKey;
246
- if (apiKey) {
247
- console.log('apikey:permanent');
248
- } else if (oauth && oauth.expiresAt) {
249
- const now = Date.now();
250
- const remaining = Math.floor((oauth.expiresAt - now) / 1000 / 60 / 60);
251
- const hasRefresh = oauth.refreshToken ? 'yes' : 'no';
252
- console.log('oauth:' + remaining + ':' + hasRefresh);
253
- }
254
- } catch(e) { console.log('error'); }
255
- " 2>/dev/null)
256
-
257
- IFS=':' read -r auth_type remaining has_refresh <<< "${AUTH_INFO}"
258
-
259
- if [ "${auth_type}" = "apikey" ]; then
260
- log "✅ Claude authentication: API key (permanent)"
261
- elif [ "${auth_type}" = "oauth" ]; then
262
- if [ "${remaining}" -le 0 ]; then
263
- # Token expired - try to refresh
264
- if [ "${has_refresh}" = "yes" ]; then
265
- log "⚠️ Token expired, attempting refresh..."
266
- if refresh_token 2>/dev/null; then
267
- # Re-check the new expiry
268
- NEW_REMAINING=$(node -e "
269
- try {
270
- const creds = require('${CREDENTIALS_FILE}');
271
- const remaining = Math.floor((creds.claudeAiOauth.expiresAt - Date.now()) / 1000 / 60 / 60);
272
- console.log(remaining);
273
- } catch(e) { console.log('0'); }
274
- " 2>/dev/null)
275
- log "✅ Claude authentication: refreshed (${NEW_REMAINING}h remaining)"
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
276
297
  else
277
- log "❌ Token refresh failed - run: claude login"
298
+ log "❌ Token expired (no refresh token) - will use --dangerously-skip-permissions"
299
+ export CLAUDE_SKIP_AUTH=1
278
300
  fi
279
- else
280
- log "❌ Token expired (no refresh token) - run: claude login"
281
- fi
282
- elif [ "${remaining}" -lt 2 ]; then
283
- # Less than 2 hours - refresh proactively
284
- if [ "${has_refresh}" = "yes" ]; then
285
- log "🔄 Token expires in ${remaining}h, refreshing..."
286
- if refresh_token 2>/dev/null; then
287
- NEW_REMAINING=$(node -e "
288
- try {
289
- const creds = require('${CREDENTIALS_FILE}');
290
- const remaining = Math.floor((creds.claudeAiOauth.expiresAt - Date.now()) / 1000 / 60 / 60);
291
- console.log(remaining);
292
- } catch(e) { console.log('0'); }
293
- " 2>/dev/null)
294
- log "✅ Claude authentication: refreshed (${NEW_REMAINING}h remaining)"
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
295
317
  else
296
- log "⚠️ Refresh failed, ${remaining}h remaining"
318
+ log "⚠️ Claude authentication: ${remaining}h remaining (no refresh token)"
297
319
  fi
298
320
  else
299
- log "⚠️ Claude authentication: ${remaining}h remaining (no refresh token)"
321
+ log "Claude authentication: valid (${remaining}h remaining)"
300
322
  fi
301
- else
302
- log " Claude authentication: valid (${remaining}h remaining)"
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
303
326
  fi
304
- elif [ "${auth_type}" = "error" ]; then
305
- log "⚠️ Could not read credentials"
306
327
  fi
328
+ elif [ ! -f "${CREDENTIALS_FILE}" ]; then
329
+ log "⚠️ No credentials - will use --dangerously-skip-permissions"
330
+ export CLAUDE_SKIP_AUTH=1
307
331
  fi
308
- elif [ ! -f "${CREDENTIALS_FILE}" ]; then
309
- log "⚠️ No Claude credentials found. Run 'claude login' to authenticate"
310
- log " 💡 Tip: Run 'claude setup-token' for a long-lived token"
311
332
  fi
312
333
 
313
334
  # =============================================================================