mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-05-14 08:28:39 +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
|
||||
|
||||
@@ -45,7 +45,7 @@ def build_terminal_launch(
|
||||
if resolved_os_name == 'nt':
|
||||
creationflags = getattr(subprocess, 'CREATE_NEW_CONSOLE', 0)
|
||||
return (
|
||||
['cmd.exe', '/k', 'cd', '/d', path],
|
||||
['cmd.exe'],
|
||||
{
|
||||
'cwd': path,
|
||||
'creationflags': creationflags,
|
||||
@@ -59,3 +59,12 @@ def build_terminal_launch(
|
||||
['x-terminal-emulator', '-e', 'bash', '-lc', 'cd -- "$1"; exec bash', 'bash', path],
|
||||
{},
|
||||
)
|
||||
|
||||
|
||||
def launch_terminal(path: str) -> None:
|
||||
"""Open a terminal at the given path after validating the target directory."""
|
||||
canonical = os.path.realpath(path)
|
||||
if not os.path.isdir(canonical):
|
||||
raise ValueError(f"Path is not a valid directory: {canonical!r}")
|
||||
argv, kwargs = build_terminal_launch(canonical)
|
||||
subprocess.Popen(argv, **kwargs) # noqa: S603 - list argv, no shell=True, path validated above
|
||||
|
||||
Reference in New Issue
Block a user