fullcourtdefense-cli 1.21.4 → 1.21.5
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/dist/commands/desktopChatGuard.js +64 -27
- package/dist/version.json +1 -1
- package/package.json +1 -1
|
@@ -279,19 +279,28 @@ function ensureWatcherScript() {
|
|
|
279
279
|
fs.writeFileSync(WATCHER_PS1_PATH, desktopChatWatcherScript(), { encoding: 'utf8' });
|
|
280
280
|
return WATCHER_PS1_PATH;
|
|
281
281
|
}
|
|
282
|
-
function relaunchThrottleOk() {
|
|
282
|
+
function relaunchThrottleOk(currentClaudeCreated) {
|
|
283
283
|
try {
|
|
284
|
-
const
|
|
284
|
+
const marker = JSON.parse(fs.readFileSync(A11Y_RELAUNCH_MARKER, 'utf8'));
|
|
285
|
+
const last = marker.lastAttemptAt || 0;
|
|
286
|
+
// Claude was restarted (update, crash, user quit/reopen) since our last
|
|
287
|
+
// relaunch attempt — the old throttle must not leave the composer blind.
|
|
288
|
+
if (currentClaudeCreated && marker.claudeCreated && currentClaudeCreated !== marker.claudeCreated) {
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
285
291
|
return Date.now() - last > A11Y_RELAUNCH_THROTTLE_MS;
|
|
286
292
|
}
|
|
287
293
|
catch {
|
|
288
294
|
return true;
|
|
289
295
|
}
|
|
290
296
|
}
|
|
291
|
-
function stampRelaunch() {
|
|
297
|
+
function stampRelaunch(claudeCreated) {
|
|
292
298
|
try {
|
|
293
299
|
fs.mkdirSync(path.dirname(A11Y_RELAUNCH_MARKER), { recursive: true });
|
|
294
|
-
fs.writeFileSync(A11Y_RELAUNCH_MARKER, JSON.stringify({
|
|
300
|
+
fs.writeFileSync(A11Y_RELAUNCH_MARKER, JSON.stringify({
|
|
301
|
+
lastAttemptAt: Date.now(),
|
|
302
|
+
...(claudeCreated ? { claudeCreated } : {}),
|
|
303
|
+
}), { encoding: 'utf8', mode: 0o600 });
|
|
295
304
|
}
|
|
296
305
|
catch { /* best-effort */ }
|
|
297
306
|
}
|
|
@@ -319,50 +328,78 @@ function ensureAccessibilityScript(allowRelaunch) {
|
|
|
319
328
|
// The browser (main) process is the claude.exe with no --type= child switch.
|
|
320
329
|
"$main = $procs | Where-Object { $_.CommandLine -and ($_.CommandLine -notmatch '--type=') } | Select-Object -First 1",
|
|
321
330
|
"if (-not $main) { Write-Output 'STATE:not-running'; exit 0 }",
|
|
322
|
-
"
|
|
323
|
-
|
|
331
|
+
"$created = $main.CreationDate",
|
|
332
|
+
"if ($main.CommandLine -match '--force-renderer-accessibility') { Write-Output ('STATE:has-flag:' + $created); exit 0 }",
|
|
333
|
+
allowRelaunch ? '' : "Write-Output ('STATE:needs-flag:' + $created); exit 0",
|
|
324
334
|
"$exe = $main.ExecutablePath",
|
|
325
335
|
"if (-not $exe -or -not (Test-Path $exe)) { Write-Output 'STATE:error:no-exe'; exit 0 }",
|
|
326
336
|
'try {',
|
|
327
337
|
" $procs | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }",
|
|
328
338
|
' Start-Sleep -Milliseconds 1500',
|
|
329
339
|
" Start-Process -FilePath $exe -ArgumentList '--force-renderer-accessibility'",
|
|
330
|
-
" Write-Output 'STATE:relaunched'",
|
|
340
|
+
" Write-Output ('STATE:relaunched:' + $created)",
|
|
331
341
|
"} catch { Write-Output ('STATE:error:' + $_.Exception.Message) }",
|
|
332
342
|
].filter(Boolean).join('\n');
|
|
333
343
|
}
|
|
344
|
+
function parseAccessibilityState(out) {
|
|
345
|
+
const match = out.match(/STATE:([^:\r\n]+)(?::(.+))?/);
|
|
346
|
+
if (!match)
|
|
347
|
+
return { state: '' };
|
|
348
|
+
return { state: match[1].trim(), claudeCreated: match[2]?.trim() };
|
|
349
|
+
}
|
|
334
350
|
/**
|
|
335
351
|
* Ensure Claude Desktop is running with renderer accessibility so the composer
|
|
336
352
|
* is readable. Non-blocking best-effort; throttled to at most one relaunch per
|
|
337
|
-
* A11Y_RELAUNCH_THROTTLE_MS
|
|
353
|
+
* A11Y_RELAUNCH_THROTTLE_MS for the SAME Claude process instance. A fresh
|
|
354
|
+
* Claude restart (update, MSI, user reopen) bypasses the throttle.
|
|
338
355
|
*/
|
|
339
356
|
function ensureClaudeForceAccessibility(log) {
|
|
340
357
|
if (process.platform !== 'win32')
|
|
341
358
|
return;
|
|
342
|
-
|
|
343
|
-
|
|
359
|
+
// Probe first without committing to relaunch so we can compare process age
|
|
360
|
+
// against the throttle marker before deciding.
|
|
361
|
+
const probe = (0, child_process_1.spawn)('powershell', [
|
|
344
362
|
'-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden',
|
|
345
|
-
'-Command', ensureAccessibilityScript(
|
|
363
|
+
'-Command', ensureAccessibilityScript(false),
|
|
346
364
|
], { windowsHide: true, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
347
|
-
let
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
const state
|
|
352
|
-
if (state === '
|
|
353
|
-
|
|
354
|
-
|
|
365
|
+
let probeOut = '';
|
|
366
|
+
probe.stdout?.on('data', (d) => { probeOut += d.toString(); });
|
|
367
|
+
probe.on('error', () => { });
|
|
368
|
+
probe.on('exit', () => {
|
|
369
|
+
const { state, claudeCreated } = parseAccessibilityState(probeOut);
|
|
370
|
+
if (!state || state === 'not-running' || state.startsWith('has-flag'))
|
|
371
|
+
return;
|
|
372
|
+
if (!state.startsWith('needs-flag')) {
|
|
373
|
+
if (state.startsWith('error'))
|
|
374
|
+
log(`Claude Desktop guard: accessibility probe failed (${state}).`);
|
|
375
|
+
return;
|
|
355
376
|
}
|
|
356
|
-
|
|
377
|
+
const allow = relaunchThrottleOk(claudeCreated);
|
|
378
|
+
if (!allow) {
|
|
357
379
|
log('Claude Desktop guard: Claude is running without accessibility; relaunch throttled — composer stays unreadable until the next allowed relaunch.');
|
|
380
|
+
return;
|
|
358
381
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
382
|
+
const child = (0, child_process_1.spawn)('powershell', [
|
|
383
|
+
'-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden',
|
|
384
|
+
'-Command', ensureAccessibilityScript(true),
|
|
385
|
+
], { windowsHide: true, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
386
|
+
let out = '';
|
|
387
|
+
child.stdout?.on('data', (d) => { out += d.toString(); });
|
|
388
|
+
child.on('error', () => { });
|
|
389
|
+
child.on('exit', () => {
|
|
390
|
+
const result = parseAccessibilityState(out);
|
|
391
|
+
if (result.state === 'relaunched') {
|
|
392
|
+
stampRelaunch(result.claudeCreated || claudeCreated);
|
|
393
|
+
log('Claude Desktop guard: relaunched Claude with --force-renderer-accessibility so the chat composer is readable.');
|
|
394
|
+
}
|
|
395
|
+
else if (result.state.startsWith('error')) {
|
|
396
|
+
// An error can surface AFTER we already force-stopped Claude (Start-Process
|
|
397
|
+
// threw). Stamp the throttle regardless so a half-failed restart can never
|
|
398
|
+
// loop the kill every 5 minutes — wait the full window before retrying.
|
|
399
|
+
stampRelaunch(result.claudeCreated || claudeCreated);
|
|
400
|
+
log(`Claude Desktop guard: could not enable accessibility (${result.state}); backing off before retry.`);
|
|
401
|
+
}
|
|
402
|
+
});
|
|
366
403
|
});
|
|
367
404
|
}
|
|
368
405
|
/**
|
package/dist/version.json
CHANGED