mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-05-12 07:37:24 +08:00
fix: port hook session and dashboard safety fixes
Ports suggest-compact session_id isolation and dashboard terminal/document launch safety onto current main.
This commit is contained in:
@@ -18,14 +18,30 @@ const path = require('path');
|
||||
const {
|
||||
getTempDir,
|
||||
writeFile,
|
||||
readStdinJson,
|
||||
log
|
||||
} = require('../lib/utils');
|
||||
|
||||
async function resolveSessionId() {
|
||||
// Claude Code passes hook input via stdin JSON; session_id is the
|
||||
// canonical field. Fall back to the legacy env var, then 'default'.
|
||||
try {
|
||||
const input = await readStdinJson({ timeoutMs: 1000 });
|
||||
if (input && typeof input.session_id === 'string' && input.session_id) {
|
||||
return input.session_id;
|
||||
}
|
||||
} catch {
|
||||
/* fall through to env */
|
||||
}
|
||||
return process.env.CLAUDE_SESSION_ID || 'default';
|
||||
}
|
||||
|
||||
async function main() {
|
||||
// Track tool call count (increment in a temp file)
|
||||
// Use a session-specific counter file based on session ID from environment
|
||||
// or parent PID as fallback
|
||||
const sessionId = (process.env.CLAUDE_SESSION_ID || 'default').replace(/[^a-zA-Z0-9_-]/g, '') || 'default';
|
||||
// Use a session-specific counter file based on session ID from stdin JSON,
|
||||
// legacy env var, or 'default' as fallback.
|
||||
const rawSessionId = await resolveSessionId();
|
||||
const sessionId = rawSessionId.replace(/[^a-zA-Z0-9_-]/g, '') || 'default';
|
||||
const counterFile = path.join(getTempDir(), `claude-tool-count-${sessionId}`);
|
||||
const rawThreshold = parseInt(process.env.COMPACT_THRESHOLD || '50', 10);
|
||||
const threshold = Number.isFinite(rawThreshold) && rawThreshold > 0 && rawThreshold <= 10000
|
||||
|
||||
Reference in New Issue
Block a user