-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsp-session-reset.js
More file actions
54 lines (46 loc) · 1.57 KB
/
lsp-session-reset.js
File metadata and controls
54 lines (46 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env node
'use strict';
/**
* lsp-session-reset.js — SessionStart hook
*
* Wipes stale LSP navigation state for the current cwd at session start.
*
* Without this, `nav_count` persists for 24h across sessions (see
* lsp-first-read-guard.js FLAG_EXPIRY_MS). A new session can inherit
* "surgical mode" (nav_count >= 2) from previous work and freely Read
* code files without ever calling LSP — a full bypass of the LSP-first
* enforcement chain.
*
* After reset:
* - Gate 1 (warmup): first code Read BLOCKED until mcp__cclsp__get_diagnostics
* - Gate 4: read #4 BLOCKED unless nav_count >= 1
* - Gate 5: read #6 BLOCKED unless nav_count >= 2
*
* Side-effect: first session call forces one warmup (~1 LSP call). Cheap.
*/
const fs = require('fs');
const path = require('path');
const os = require('os');
const crypto = require('crypto');
const STATE_DIR = path.join(os.homedir(), '.claude', 'state');
function getFlagPath(cwd) {
const hash = crypto.createHash('md5').update(cwd).digest('hex').slice(0, 12);
return path.join(STATE_DIR, `lsp-ready-${hash}`);
}
let raw = '';
process.stdin.setEncoding('utf8');
process.stdin.on('data', d => { raw += d; });
process.stdin.on('end', () => {
let cwd = process.cwd();
try {
const data = JSON.parse(raw || '{}');
if (data.cwd && typeof data.cwd === 'string') cwd = data.cwd;
} catch { /* ignore */ }
const flagPath = getFlagPath(cwd);
try {
if (fs.existsSync(flagPath)) {
fs.unlinkSync(flagPath);
}
} catch { /* silent: hook must never block session start */ }
process.exit(0);
});