Skip to content

Commit 58314c2

Browse files
committed
fix: correct snippet line-number labels and add utf-8 encoding
- Fix edit_doc_file snippet labels: `i + start + 1` double-counted the start offset; changed to `i + 1` in both str_replace and insert branches - Add encoding="utf-8" to _write_generation_metadata write_text call - Document that metadata.json is written only on close_session in IDE_DRIVEN_GUIDE.md and SKILL.md
1 parent 4278e93 commit 58314c2

4 files changed

Lines changed: 8 additions & 3 deletions

File tree

IDE_DRIVEN_GUIDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ Subsequent call to analyze_repo after code changes:
245245
1. **Git strategy**: Read `commit_id` from `metadata.json`, run `git diff` against current HEAD, also check `git status` to capture uncommitted changes (modified + untracked files)
246246
2. **Mtime strategy** (fallback for non-git repos): Walk source files and compare modification times against `timestamp` in `metadata.json`
247247

248+
> **Note**: `metadata.json` is written only when `close_session` is called. If a session ends without calling `close_session`, no baseline exists and the next `analyze_repo` silently falls back to full analysis. Always call `close_session` at the end of the workflow to ensure incremental updates work.
249+
248250
**Return structure**:
249251

250252
```json

codewiki/mcp/server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,8 @@ def _write_generation_metadata(session: SessionState) -> None:
570570
},
571571
}
572572
(output_dir / "metadata.json").write_text(
573-
json.dumps(metadata, indent=2, ensure_ascii=False)
573+
json.dumps(metadata, indent=2, ensure_ascii=False),
574+
encoding="utf-8",
574575
)
575576
except Exception as e:
576577
logger.warning("Failed to write metadata.json: %s", e)

codewiki/mcp/tools/doc_writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ async def handle_edit_doc_file(
173173
lines = new_content.split("\n")
174174
start = max(0, replacement_line - 4)
175175
end = min(len(lines), start + new_str.count("\n") + 9)
176-
snippet = "\n".join(f"{i + start + 1:6}\t{lines[i]}" for i in range(start, end))
176+
snippet = "\n".join(f"{i + 1:6}\t{lines[i]}" for i in range(start, end))
177177

178178
elif command == "insert":
179179
insert_line = arguments.get("insert_line", 0)
@@ -190,7 +190,7 @@ async def handle_edit_doc_file(
190190

191191
start = max(0, insert_line - 4)
192192
end = min(len(lines), start + len(new_str_lines) + 8)
193-
snippet = "\n".join(f"{i + start + 1:6}\t{lines[i]}" for i in range(start, end))
193+
snippet = "\n".join(f"{i + 1:6}\t{lines[i]}" for i in range(start, end))
194194

195195
else:
196196
return json.dumps({"error": f"Unknown command: {command}. Use str_replace, insert, or undo."})

skills/codewiki-wiki-generator/SKILL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ When documentation has already been generated for a repository (`metadata.json`
127127

128128
**Change detection strategy**: Prefers `git diff` (comparing commit SHA + checking for uncommitted workspace changes); falls back to comparing file modification times for non-git repositories.
129129

130+
> **Note**: `metadata.json` is written only when `close_session` is called. Sessions that end without `close_session` leave no baseline, so the next `analyze_repo` falls back to full analysis. Always call `close_session` at the end of the workflow.
131+
130132
**Incremental update workflow**:
131133

132134
1. Call `analyze_repo` and check the returned `changes` field or read the `changes.json` file

0 commit comments

Comments
 (0)