Skip to content
This repository was archived by the owner on Jun 4, 2026. It is now read-only.

Commit 91eee65

Browse files
christseclaude
andcommitted
Fix critical PR review issues
- Fix JWT expiration in watch.ts: Store RealmAuthClient instead of cached JWT string, call getJWT() before each request for auto-refresh - Fix Linux fs.watch: Add platform check to avoid recursive option on Linux where it throws ERR_FEATURE_UNAVAILABLE_ON_PLATFORM - Remove .claude/settings.local.json from repo and add to .gitignore (user-specific settings should not be committed) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0ec1ee3 commit 91eee65

4 files changed

Lines changed: 33 additions & 59 deletions

File tree

.claude/settings.local.json

Lines changed: 0 additions & 48 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Thumbs.db
2222
*.swp
2323
*.swo
2424

25+
# Claude Code (user-specific settings)
26+
.claude/settings.local.json
27+
2528
# Test workspaces
2629
test-workspace/
2730
*-workspace/

src/commands/track.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,20 @@ export async function trackCommand(
332332
};
333333

334334
// Use fs.watch for efficient file watching
335+
// Note: recursive: true is not reliably supported on Linux
336+
const isLinux = process.platform === 'linux';
335337
const watchers: fs.FSWatcher[] = [];
336338

339+
if (isLinux && !options.quiet) {
340+
console.log('Note: Recursive file watching is limited on Linux. Using polling as primary method.');
341+
}
342+
337343
const watchDir = (dir: string) => {
338344
try {
339-
const watcher = fs.watch(dir, { recursive: true }, (eventType, filename) => {
345+
// On Linux, don't use recursive option as it may throw ERR_FEATURE_UNAVAILABLE_ON_PLATFORM
346+
const watchOptions: fs.WatchOptions = isLinux ? {} : { recursive: true };
347+
348+
const watcher = fs.watch(dir, watchOptions, (eventType, filename) => {
340349
if (!filename) return;
341350

342351
// Skip internal files
@@ -355,7 +364,10 @@ export async function trackCommand(
355364

356365
watchers.push(watcher);
357366
} catch (error) {
358-
console.error(`Failed to watch directory:`, error);
367+
// On platforms where fs.watch fails, we rely on polling
368+
if (!options.quiet) {
369+
console.log('File system watching unavailable, using polling only.');
370+
}
359371
}
360372
};
361373

src/commands/watch.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface WatchedRealm {
2222
name: string;
2323
localDir: string;
2424
workspaceUrl: string;
25-
jwt: string;
25+
realmAuthClient: RealmAuthClient; // Store client for JWT refresh support
2626
checkpointManager: CheckpointManager;
2727
lastKnownState: Record<string, number>;
2828
pendingChanges: Map<string, { status: 'added' | 'modified' | 'deleted'; mtime: number }>;
@@ -87,14 +87,15 @@ export async function watchCommand(
8787

8888
const normalizedUrl = workspaceUrl.endsWith('/') ? workspaceUrl : workspaceUrl + '/';
8989

90-
// Get JWT for this realm
90+
// Create realm auth client (handles JWT caching and refresh internally)
9191
if (options.verbose) {
92-
console.log(`[VERBOSE] Getting JWT for ${normalizedUrl}...`);
92+
console.log(`[VERBOSE] Creating RealmAuthClient for ${normalizedUrl}...`);
9393
}
94-
const realmAuth = new RealmAuthClient(new URL(normalizedUrl), matrixClient);
95-
const jwt = await realmAuth.getJWT();
94+
const realmAuthClient = new RealmAuthClient(new URL(normalizedUrl), matrixClient);
95+
// Verify we can get a JWT (this also caches it)
96+
const initialJwt = await realmAuthClient.getJWT();
9697
if (options.verbose) {
97-
console.log(`[VERBOSE] JWT acquired (${jwt.length} chars)`);
98+
console.log(`[VERBOSE] Initial JWT acquired (${initialJwt.length} chars)`);
9899
}
99100

100101
// Initialize checkpoint manager
@@ -123,7 +124,7 @@ export async function watchCommand(
123124
name,
124125
localDir,
125126
workspaceUrl: normalizedUrl,
126-
jwt,
127+
realmAuthClient,
127128
checkpointManager,
128129
lastKnownState,
129130
pendingChanges: new Map(),
@@ -184,11 +185,14 @@ export async function watchCommand(
184185

185186
console.log(` Pulling changes...`);
186187

188+
// Get fresh JWT (handles refresh if expired)
189+
const jwt = await realm.realmAuthClient.getJWT();
190+
187191
for (const file of [...newFiles, ...modifiedFiles]) {
188192
const fileUrl = `${realm.workspaceUrl}${file}`;
189193
const fileResponse = await fetch(fileUrl, {
190194
headers: {
191-
'Authorization': realm.jwt,
195+
'Authorization': jwt,
192196
'Accept': file.endsWith('.json')
193197
? 'application/vnd.card+json'
194198
: file.endsWith('.gts')
@@ -247,10 +251,13 @@ export async function watchCommand(
247251

248252
const checkRealmForChanges = async (realm: WatchedRealm) => {
249253
try {
254+
// Get fresh JWT (handles refresh if expired)
255+
const jwt = await realm.realmAuthClient.getJWT();
256+
250257
const mtimesUrl = `${realm.workspaceUrl}_mtimes`;
251258
const response = await fetch(mtimesUrl, {
252259
headers: {
253-
'Authorization': realm.jwt,
260+
'Authorization': jwt,
254261
'Accept': 'application/vnd.api+json',
255262
},
256263
});

0 commit comments

Comments
 (0)