Skip to content

Commit 7d78020

Browse files
committed
CLI exit fix: close graph store in finally, process.exit(0) after success
- cmdAnalyze: try/finally with store.close() so Kuzu DB is released - analyze command: process.exit(0) after success to avoid Windows teardown crash - index-and-map now completes with exit 0 and writes graph-map.md - PLAN: document fix and verification Made-with: Cursor
1 parent c06b1da commit 7d78020

3 files changed

Lines changed: 33 additions & 54 deletions

File tree

bin/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ program
3535
}
3636
const n = result.filesProcessed ?? 0;
3737
process.stderr.write(`Indexed ${n} file(s).\n`);
38+
process.exit(0);
3839
});
3940

4041
program

docs/PLAN.md

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Plan: LSP Client Fixes & Indexing
22

3+
**Released:** v0.4.3 (2026-03-19) — see `release-notes-v0.4.3.md`.
4+
35
## Current Status
46

57
**Completed:**
@@ -11,45 +13,22 @@
1113
- Added LSP SymbolKind fallback: map numeric `kind` to label when `detail` is missing
1214
- Enhanced symbol mapping: added MCP-style kind strings ("Part Definition", etc.) with normalized lookup
1315
- Analyzed MCP client template patterns
14-
- **✅ Phase 1 Complete:** LSP client now returns symbols correctly; graph has symbol nodes (Package, PartDef) and edges (IN_DOCUMENT, IN_PACKAGE)
15-
16-
⚠️ **Minor Issue:**
17-
- CLI may exit non-zero after successful indexing (cleanup/close issue), but data is written correctly
16+
- **✅ Phase 1 Complete:** LSP client returns symbols; graph has symbol nodes and edges (IN_DOCUMENT, IN_PACKAGE)
17+
- **✅ Phase 2 Complete:** LSP notification handler (e.g. `window/logMessage` when `DEBUG_LSP_NOTIFICATIONS=1`); indexed `modelbase-development/models/`; `graph-map.md` generated with full nodes and interconnection table
18+
- **✅ CLI exit fix:** (1) Explicit graph store close in `cmdAnalyze` (try/finally). (2) After successful analyze, CLI calls `process.exit(0)` so the process exits before Node/Kuzu teardown (avoids Windows access violation). Verified: `node scripts/index-and-map.mjs test/fixtures/sysml` completes with exit 0 and writes `graph-map.md`.
1819

1920
## Plan
2021

21-
### Phase 1: Test & Verify (Immediate)
22-
23-
1. **Rebuild and test LSP client**
24-
```bash
25-
npm run build
26-
node lsp/test-server.mjs # Should work (already tested)
27-
```
28-
29-
2. **Test index-and-map with fixed client**
30-
```bash
31-
npm run index-and-map
32-
```
33-
- Check if LSP now returns symbols (with `--stdio`, proper cwd, timeouts)
34-
- If LSP still returns empty, MCP fallback should kick in
35-
- Verify `graph-map.md` has symbol nodes and edges
36-
37-
3. **If still no edges:**
38-
- Run `node scripts/debug-lsp-symbols.mjs` to see raw LSP response
39-
- Check if MCP fallback is being called (add logging)
40-
- Verify MCP client init succeeds (may need longer timeout or different approach)
22+
### Phase 1: Test & Verify — ✅ Done
4123

42-
### Phase 2: Notification Handlers (From Template Analysis)
24+
1. Rebuild and test LSP client; run index-and-map.
25+
2. Verify `graph-map.md` has symbol nodes and edges.
26+
3. Debug LSP/MCP via `scripts/debug-lsp-symbols.mjs` if needed.
4327

44-
4. **Add LSP notification handlers**
45-
- If server sends `window/logMessage`, register handler instead of ignoring
46-
- Log notifications for debugging
47-
- Pattern from template: `client.setNotificationHandler(schema, handler)`
28+
### Phase 2: Notification Handlers & Larger Models — ✅ Done
4829

49-
5. **Test with real SysML files**
50-
- Index `modelbase-development/models/` (larger, more symbols)
51-
- Validate specific file: `deploy-modelbase-development.sysml`
52-
- Check if edges appear with more complex models
30+
4. **LSP notification handler** — Handler added in `lsp-client.ts`; `window/logMessage` and `window/showMessage` logged when `DEBUG_LSP_NOTIFICATIONS=1`.
31+
5. **Real SysML files** — Indexed `modelbase-development/models/` (4 files); map shows Action, Block, Package, PartDef, PartUsage, RequirementDef and IN_DOCUMENT/IN_PACKAGE edges.
5332

5433
### Phase 3: Robustness (If Needed)
5534

@@ -63,25 +42,20 @@
6342

6443
### Phase 4: Validation & Documentation
6544

66-
8. **Validate the requested file**
45+
8. **Validate the requested file** (optional)
6746
- Use MCP `validate` tool on `deploy-modelbase-development.sysml`
6847
- Report syntax errors, semantic issues
6948

70-
9. **Update documentation**
71-
- Document the fixes in `MCP_INTERACTION_GUIDE.md`
72-
- Add troubleshooting section for "no edges" issue
73-
- Document `lsp/` folder usage
49+
9. **Documentation** — Done in v0.4.3: fixes in `MCP_INTERACTION_GUIDE.md`, "no edges" and troubleshooting, `lsp/` usage in README and release notes. Further troubleshooting can be added as needed.
7450

75-
## Immediate Next Steps
51+
## Next Steps (Phase 3 / 4)
7652

77-
1. **Rebuild TypeScript**
78-
2. **Run index-and-map** to see if fixes work
79-
3. **Check graph-map.md** for symbol nodes and edges
80-
4. **If still empty:** Debug LSP response and MCP fallback
53+
1. **Optional:** Connection retry and clearer error reporting (Phase 3).
54+
2. **Optional:** MCP `validate` on a SysML file; expand troubleshooting in docs (Phase 4).
8155

8256
## Success Criteria
8357

84-
-`graph-map.md` shows symbol nodes (Package, PartDef, etc.) not just Document
58+
-`graph-map.md` shows symbol nodes (Package, PartDef, Action, etc.) not just Document
8559
- ✅ Interconnection table has edges (IN_DOCUMENT, IN_PACKAGE)
86-
- ✅ Indexing completes without timeouts
87-
- Validation script works for SysML files
60+
- ✅ Indexing writes data correctly (LSP + optional MCP fallback)
61+
- Validation script for SysML files (script exists; MCP validate integration optional)

src/cli/commands.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,19 @@ export async function cmdAnalyze(paths: string[]): Promise<{ ok: boolean; filesP
3131
}
3232
const dbPath = getDbPathForIndexedPath(resolved[0]);
3333
const store = await openGraphStore(dbPath);
34-
let totalProcessed = 0;
35-
for (const p of resolved) {
36-
if (store.deleteNodesForRoot) await store.deleteNodesForRoot(p);
37-
const result = await runIndexer(store, { roots: [p] });
38-
if (!result.ok) return { ok: false, filesProcessed: totalProcessed, error: result.error };
39-
totalProcessed += result.filesProcessed;
40-
await addToRegistry(p, new Date().toISOString());
34+
try {
35+
let totalProcessed = 0;
36+
for (const p of resolved) {
37+
if (store.deleteNodesForRoot) await store.deleteNodesForRoot(p);
38+
const result = await runIndexer(store, { roots: [p] });
39+
if (!result.ok) return { ok: false, filesProcessed: totalProcessed, error: result.error };
40+
totalProcessed += result.filesProcessed;
41+
await addToRegistry(p, new Date().toISOString());
42+
}
43+
return { ok: true, filesProcessed: totalProcessed };
44+
} finally {
45+
if (store.close) await store.close();
4146
}
42-
return { ok: true, filesProcessed: totalProcessed };
4347
}
4448

4549
export async function cmdList(): Promise<{ ok: boolean; paths: string[]; error?: string }> {

0 commit comments

Comments
 (0)