Skip to content

Commit 717a50d

Browse files
committed
chore: checkpoint forensic fixes and docs alignment
1 parent 0251880 commit 717a50d

27 files changed

Lines changed: 348 additions & 160 deletions

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ knowcode context "MyClass.important_method"
4747
# 4. Export documentation
4848
knowcode export -o docs/
4949

50-
# 5. Build semantic search index
50+
# 5. (Optional) Build semantic search index explicitly
51+
# `analyze` also attempts indexing; this command is useful for rebuilds.
5152
knowcode index src/
5253

5354
# 6. Perform semantic search
@@ -101,12 +102,12 @@ knowcode query deps "PythonParser" --json
101102
Generate a context bundle for an entity (ready for AI consumption).
102103

103104
```bash
104-
knowcode context <entity> [--store <path>] [--max-chars <n>]
105+
knowcode context <entity> [--store <path>] [--max-tokens <n>]
105106
```
106107

107108
**Example:**
108109
```bash
109-
knowcode context "GraphBuilder.build_from_directory" --max-chars 4000
110+
knowcode context "GraphBuilder.build_from_directory" --max-tokens 4000
110111
```
111112

112113
### `export`
@@ -267,7 +268,7 @@ KnowCode enables token-efficient IDE agent workflows. When your IDE agent needs
267268

268269
## Supported Languages (MVP)
269270

270-
- **Python** (.py) - Full AST parsing (Supports Python 3.9 - 3.12)
271+
- **Python** (.py) - Full AST parsing (Supports Python 3.10 - 3.12)
271272
- **JavaScript / TypeScript** (.js, .ts) - Classes, functions, imports (via tree-sitter)
272273
- **Java** (.java) - Classes, methods, imports, inheritance (via tree-sitter)
273274
- **Markdown** (.md) - Document structure with heading hierarchy

README_MCP.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ KnowCode MCP Server returns:
4646
...
4747
}
4848
49-
Agent checks: sufficiency_score >= 0.88?
49+
Agent checks: sufficiency_score >= 0.8?
5050
5151
YES → Answer from context_text only (no external LLM)
5252
NO → Use external LLM (Claude Sonnet 4.5)
@@ -82,7 +82,7 @@ source .venv/bin/activate
8282
knowcode analyze . -o .
8383
```
8484

85-
**Note:** This automatically rebuilds both the knowledge store AND the semantic index!
85+
**Note:** This rebuilds the knowledge store and attempts semantic indexing. If indexing is skipped, run `knowcode index .` after configuring embeddings.
8686

8787
## 🐛 Troubleshooting
8888

@@ -107,9 +107,9 @@ knowcode analyze . -o .
107107
ls -la knowcode_index/
108108
```
109109

110-
2. If missing, re-run analyze (it will rebuild the index):
110+
2. If missing, run a dedicated index build:
111111
```bash
112-
knowcode analyze . -o .
112+
knowcode index . --output knowcode_index
113113
```
114114

115115
3. Increase token budget in `.agent/context.md`:
@@ -120,7 +120,7 @@ knowcode analyze . -o .
120120
## 📊 Success Metrics
121121

122122
After setup, you should see:
123-
- ✅ 70%+ queries with `sufficiency_score >= 0.88`
123+
- ✅ 70%+ queries with `sufficiency_score >= 0.8`
124124
- ✅ Faster responses for codebase questions
125125
- ✅ 50%+ reduction in external LLM token usage
126126
- ✅ Accurate answers from local context
@@ -134,8 +134,8 @@ After setup, you should see:
134134
## 🎓 Key Concepts
135135

136136
**Sufficiency Score**: Confidence that retrieved context is enough to answer the query
137-
- `>= 0.88` → Answer locally
138-
- `< 0.88` → Use external LLM
137+
- `>= 0.8` → Answer locally
138+
- `< 0.8` → Use external LLM
139139

140140
**Retrieval Modes**:
141141
- **Semantic**: Uses embeddings + vector search (better)

docs/MCP_SETUP.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Knowledge Store + Semantic Index
2424
Context Bundle (with sufficiency_score)
2525
2626
Agent Decision:
27-
• If sufficiency_score >= 0.88 → Answer from context only
28-
• If sufficiency_score < 0.88 → Use external LLM
27+
• If sufficiency_score >= 0.8 → Answer from context only
28+
• If sufficiency_score < 0.8 → Use external LLM
2929
```
3030

3131
## Prerequisites
@@ -66,9 +66,9 @@ Agent Decision:
6666
```markdown
6767
Always call the tool retrieve_context_for_query before answering.
6868
Use task_type=auto, max_tokens=3000, limit_entities=3, expand_deps=true.
69-
If sufficiency_score >= 0.88 and context_text is non-empty, answer ONLY from context_text.
69+
If sufficiency_score >= 0.8 and context_text is non-empty, answer ONLY from context_text.
7070
Do not call other tools or request more context.
71-
If sufficiency_score < 0.88, then proceed with a full LLM answer.
71+
If sufficiency_score < 0.8, then proceed with a full LLM answer.
7272
```
7373

7474
This ensures the agent follows the local-first workflow.
@@ -83,13 +83,13 @@ source .venv/bin/activate
8383
knowcode analyze . -o .
8484
```
8585

86-
This **automatically**:
86+
This command:
8787
- ✅ Parses the codebase and builds the knowledge graph
8888
- ✅ Creates `knowcode_knowledge.json` with all entities and relationships
89-
-**Builds the semantic index** at `knowcode_index/` with vector embeddings
90-
- ✅ Reports statistics including indexed chunk count
89+
-Attempts to build the semantic index at `knowcode_index/`
90+
- ✅ Reports indexed chunk count (or indexing warning if embedding setup is unavailable)
9191

92-
**Note:** You do NOT need to run a separate `knowcode index` command - it's built-in!
92+
**Note:** If semantic indexing is skipped (e.g., missing embedding API credentials), run `knowcode index .` after configuring embeddings.
9393

9494
### Step 3: Configure MCP Server
9595

@@ -131,8 +131,8 @@ How does search work in KnowCode?
131131
**Expected behavior:**
132132
1. Agent calls `retrieve_context_for_query`
133133
2. Returns context with `sufficiency_score`
134-
3. If score >= 0.88, answers from context only
135-
4. If score < 0.88, uses external LLM
134+
3. If score >= 0.8, answers from context only
135+
4. If score < 0.8, uses external LLM
136136

137137
### Test 3: Verify All Tools
138138

@@ -179,7 +179,7 @@ Answering from local context only.
179179
### Issue 3: Low Sufficiency Scores
180180

181181
**Symptoms:**
182-
- `sufficiency_score` always < 0.88
182+
- `sufficiency_score` always < 0.8
183183
- Agent always uses external LLM
184184

185185
**Solutions:**
@@ -196,7 +196,7 @@ Answering from local context only.
196196

197197
**Solutions:**
198198
1. Verify `knowcode_index/` directory exists
199-
2. Check `knowcode_index/manifest.json` exists
199+
2. Check `knowcode_index/index_manifest.json` exists
200200
3. Verify embedding model is configured in `aimodels.yaml`
201201
4. Check API keys for embedding provider (VoyageAI, OpenAI, etc.)
202202

@@ -276,13 +276,13 @@ Use task_type=auto, max_tokens=3000, limit_entities=3, expand_deps=true.
276276
### Check Token Savings
277277

278278
The MCP server logs show:
279-
- Queries answered locally (sufficiency >= 0.88)
280-
- Queries sent to external LLM (sufficiency < 0.88)
279+
- Queries answered locally (sufficiency >= 0.8)
280+
- Queries sent to external LLM (sufficiency < 0.8)
281281
- Token counts for each response
282282

283283
### Metrics to Track
284284

285-
1. **Sufficiency Score Distribution**: Aim for >70% of queries with score >= 0.88
285+
1. **Sufficiency Score Distribution**: Aim for >70% of queries with score >= 0.8
286286
2. **Token Consumption**: Compare before/after MCP integration
287287
3. **Response Quality**: Verify local answers are accurate
288288

docs/index.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ knowcode context "MyClass.important_method"
4747
# 4. Export documentation
4848
knowcode export -o docs/
4949

50-
# 5. Build semantic search index
50+
# 5. (Optional) Build semantic search index explicitly
51+
# `analyze` also attempts indexing; this command is useful for rebuilds.
5152
knowcode index src/
5253

5354
# 6. Perform semantic search
@@ -98,12 +99,12 @@ knowcode query deps "PythonParser" --json
9899
Generate a context bundle for an entity (ready for AI consumption).
99100

100101
```bash
101-
knowcode context <entity> [--store <path>] [--max-chars <n>]
102+
knowcode context <entity> [--store <path>] [--max-tokens <n>]
102103
```
103104

104105
**Example:**
105106
```bash
106-
knowcode context "GraphBuilder.build_from_directory" --max-chars 4000
107+
knowcode context "GraphBuilder.build_from_directory" --max-tokens 4000
107108
```
108109

109110
### `export`
@@ -210,17 +211,18 @@ knowcode ask "How does the graph builder work?"
210211
Start an MCP (Model Context Protocol) server for IDE agent integration.
211212

212213
```bash
213-
knowcode mcp-server [--store <path>]
214+
knowcode mcp-server [--store <path>] [--config <path>]
214215
```
215216

216217
**Tools Exposed:**
217218
- `search_codebase` - Search for code entities by name
218219
- `get_entity_context` - Get detailed context for an entity
219220
- `trace_calls` - Trace call graph (callers/callees) with depth
221+
- `retrieve_context_for_query` - Unified query→retrieval→context bundle
220222

221223
## Supported Languages (MVP)
222224

223-
- **Python** (.py) - Full AST parsing (Supports Python 3.9 - 3.12)
225+
- **Python** (.py) - Full AST parsing (Supports Python 3.10 - 3.12)
224226
- **JavaScript / TypeScript** (.js, .ts) - Classes, functions, imports (via tree-sitter)
225227
- **Java** (.java) - Classes, methods, imports, inheritance (via tree-sitter)
226228
- **Markdown** (.md) - Document structure with heading hierarchy

scripts/mypy_autofix/fix_colons.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from pathlib import Path
32

43
def main():

scripts/mypy_autofix/fix_last_mypy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import re
21
from collections import defaultdict
32
from pathlib import Path
43

@@ -16,7 +15,8 @@ def main():
1615
errors_by_file[filepath].append((lineno, msg))
1716

1817
for filepath, file_errors in errors_by_file.items():
19-
if not Path(filepath).exists(): continue
18+
if not Path(filepath).exists():
19+
continue
2020

2121
file_lines = Path(filepath).read_text().splitlines()
2222

@@ -27,7 +27,8 @@ def main():
2727

2828
for lineno in sorted(line_actions.keys(), reverse=True):
2929
idx = lineno - 1
30-
if idx < 0 or idx >= len(file_lines): continue
30+
if idx < 0 or idx >= len(file_lines):
31+
continue
3132

3233
line = file_lines[idx]
3334
msgs = line_actions[lineno]

scripts/mypy_autofix/fix_mypy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import re
2-
import sys
31
from collections import defaultdict
42
from pathlib import Path
53

@@ -34,15 +32,17 @@ def main():
3432
Path(fn).write_text(content)
3533

3634
for filepath, file_errors in errors_by_file.items():
37-
if not Path(filepath).exists(): continue
35+
if not Path(filepath).exists():
36+
continue
3837

3938
file_lines = Path(filepath).read_text().splitlines()
4039

4140
# Sort in reverse to apply changes from bottom up (if inserting lines, though we are mostly appending or modifying lines)
4241
# For appending # type: ignore, order doesn't impact line numbers
4342
for lineno, msg in sorted(file_errors, key=lambda x: x[0], reverse=True):
4443
idx = lineno - 1
45-
if idx < 0 or idx >= len(file_lines): continue
44+
if idx < 0 or idx >= len(file_lines):
45+
continue
4646

4747
line = file_lines[idx]
4848

scripts/mypy_autofix/fix_mypy2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import re
21
from collections import defaultdict
32
from pathlib import Path
43

@@ -16,14 +15,16 @@ def main():
1615
errors_by_file[filepath].append((lineno, msg))
1716

1817
for filepath, file_errors in errors_by_file.items():
19-
if not Path(filepath).exists(): continue
18+
if not Path(filepath).exists():
19+
continue
2020

2121
file_lines = Path(filepath).read_text().splitlines()
2222

2323
# apply changes bottom-up
2424
for lineno, msg in sorted(file_errors, key=lambda x: x[0], reverse=True):
2525
idx = lineno - 1
26-
if idx < 0 or idx >= len(file_lines): continue
26+
if idx < 0 or idx >= len(file_lines):
27+
continue
2728

2829
line = file_lines[idx]
2930

scripts/mypy_autofix/fix_syntax.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from pathlib import Path
32

43
def main():

0 commit comments

Comments
 (0)