Skip to content

Commit 53cb6bf

Browse files
committed
bugfix
1 parent 30615e7 commit 53cb6bf

7 files changed

Lines changed: 210 additions & 23 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "_auto_8dc3144e030e401a942b5d77f8d4bfcb",
3+
"mainConversationId": "8dc3144e030e401a942b5d77f8d4bfcb",
4+
"workspacePath": "d:\\repos\\CodeWiki-CN",
5+
"createdAt": "2026-09-05T10:32:04.626Z",
6+
"options": {
7+
"workspacePath": "d:\\repos\\CodeWiki-CN",
8+
"isAutoTeam": true
9+
},
10+
"isAutoTeam": true,
11+
"members": [
12+
{
13+
"memberId": "distill-他山之石@_auto_8dc3144e030e401a942b5d77f8d4bfcb",
14+
"name": "distill-他山之石",
15+
"role": "补蒸馏他山之石任务",
16+
"sessionId": "4e77bbad99d446cd9ac307f548735c87"
17+
}
18+
]
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

‎codewiki/mcp/registry.py‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,11 +1361,18 @@ def _register(schema: Tool, handler_path: str, mode: str, takes_store: bool = Tr
13611361
"Import a third-party document (PDF, MD, DOCX, HTML) into the "
13621362
"knowledge base. The file is stored in raw/sources/ and registered "
13631363
"in source_registry.json for tracking and search indexing. "
1364-
"Name conflicts: if the requested 'name' is already registered to a "
1365-
"DIFFERENT file (different content), the tool returns status='conflict' "
1366-
"and stores nothing — ask the user how to proceed. Re-run with "
1367-
"overwrite=true only AFTER the user agrees to replace the existing "
1368-
"document (the old raw file is moved to .trash). "
1364+
"CONFIRMATION GATE — read first: when the import clashes with anything "
1365+
"already registered, the tool stores nothing and returns either "
1366+
"status='duplicate' (identical content already registered, under any "
1367+
"name) or status='conflict' (this 'name' already registered to a "
1368+
"DIFFERENT document). Both responses carry "
1369+
"requires_user_confirmation=true, the 'existing' entry and a "
1370+
"'user_options' list. You MUST stop and ask the user which option to "
1371+
"take, then re-run accordingly — never silently skip, rename or "
1372+
"overwrite on your own. overwrite=true is the user-consent token: pass "
1373+
"it only AFTER the user agrees to replace an existing source (the old "
1374+
"raw file is moved to .trash); it is accepted only against the SAME "
1375+
"name and returns status='error' otherwise. "
13691376
"IMPORTANT: This tool only stores and indexes the document. To extract "
13701377
"structured knowledge (entities, concepts) from it, follow this workflow: "
13711378
"1) Call get_prompt(prompt_type='extraction_scan') for extraction guidance. "
@@ -1398,9 +1405,13 @@ def _register(schema: Tool, handler_path: str, mode: str, takes_store: bool = Tr
13981405
"overwrite": {
13991406
"type": "boolean",
14001407
"description": (
1401-
"Set to true ONLY after user consent to replace an existing "
1402-
"source that already uses this name with different content. "
1403-
"The previously registered raw file is moved to .trash."
1408+
"User-consent token for re-ingesting an identifier that is "
1409+
"already registered. Set to true ONLY after the user has seen "
1410+
"the status='duplicate' / status='conflict' response and "
1411+
"explicitly agreed to replace it. The previously registered "
1412+
"raw file is moved to .trash. Accepted only against the SAME "
1413+
"name; passing it together with a NEW name for content that "
1414+
"is already registered elsewhere returns an error."
14041415
),
14051416
},
14061417
"source_type": {

‎codewiki/mcp/tools/source_ingest.py‎

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -323,22 +323,79 @@ def handle_ingest_source(
323323
registry = _load_registry(output_dir)
324324

325325
# 1) Content-level dedup: identical content anywhere → duplicate.
326+
# Mirrors the name-conflict guard below: the tool MUST NOT decide on the
327+
# caller's behalf. It stores nothing, reports the clash and surfaces the
328+
# paths the user can choose from; re-running with overwrite=true is the
329+
# explicit "user agreed" signal.
330+
overwrite = bool(arguments.get("overwrite", False))
331+
duplicate_of: Optional[str] = None
326332
if content_hash:
327333
for existing_name, info in registry.get("sources", {}).items():
328334
if isinstance(info, dict) and info.get("content_hash") == hash_key:
329335
if info.get("status") != "retracted":
330-
return json.dumps(
331-
{
332-
"status": "duplicate",
333-
"name": name,
334-
"existing_name": existing_name,
335-
"content_hash": f"sha256:{content_hash[:16]}...",
336-
"message": f"Content identical to existing source '{existing_name}'. "
337-
f"Use a different file or retract the existing source first.",
338-
},
339-
indent=2,
340-
ensure_ascii=False,
341-
)
336+
duplicate_of = existing_name
337+
break
338+
339+
if duplicate_of:
340+
dup_info = registry["sources"][duplicate_of]
341+
# A confirmed re-import is only meaningful when it targets the SAME
342+
# identifier. Overwriting under a *different* name would store a second
343+
# copy of byte-identical content and pollute retrieval with duplicates.
344+
if overwrite and duplicate_of != name:
345+
return json.dumps(
346+
{
347+
"status": "error",
348+
"name": name,
349+
"duplicate_of": duplicate_of,
350+
"message": (
351+
f"Content is already registered as '{duplicate_of}'; refusing to "
352+
f"store a second copy under '{name}'. Ask the user: reuse "
353+
f"'{duplicate_of}' as-is, or retract_source('{duplicate_of}') "
354+
"first and then import under the new name."
355+
),
356+
},
357+
indent=2,
358+
ensure_ascii=False,
359+
)
360+
if not overwrite:
361+
return json.dumps(
362+
{
363+
"status": "duplicate",
364+
"name": name,
365+
"existing_name": duplicate_of,
366+
"existing": {
367+
"name": duplicate_of,
368+
"path": dup_info.get("path", ""),
369+
"original_path": dup_info.get("original_path", ""),
370+
"imported_at": dup_info.get("imported_at", ""),
371+
"description": dup_info.get("description", ""),
372+
"content_hash": dup_info.get("content_hash", ""),
373+
},
374+
"content_hash": f"sha256:{content_hash[:16]}...",
375+
"requires_user_confirmation": True,
376+
"user_options": [
377+
f"reuse (recommended): skip this import and work with the already "
378+
f"registered source '{duplicate_of}' — the bytes are identical",
379+
f"overwrite: only after the user agrees, re-run with "
380+
f"overwrite=true and name='{duplicate_of}' to re-store the same "
381+
"document under its canonical name (the old raw file moves to .trash)",
382+
f"rename: only if the user wants a separate identifier — "
383+
f"retract_source('{duplicate_of}') first, then import under a new name",
384+
],
385+
"message": (
386+
f"Content is byte-identical to existing source '{duplicate_of}' "
387+
f"({dup_info.get('path') or dup_info.get('original_path')}, imported "
388+
f"{dup_info.get('imported_at', 'unknown')}). Nothing was stored. "
389+
"ASK THE USER which path to take before calling this tool again — "
390+
"do not silently skip, rename or overwrite on your own."
391+
),
392+
},
393+
indent=2,
394+
ensure_ascii=False,
395+
)
396+
# Confirmed overwrite of the same identifier: retire the old raw file so
397+
# the fresh copy takes the canonical path (handled further below).
398+
_retire_registered_file(output_dir, registry, duplicate_of)
342399

343400
# 2) Name-level conflict guard: the identifier is already registered to a
344401
# *different* document. Never overwrite silently — surface the conflict
@@ -349,7 +406,6 @@ def handle_ingest_source(
349406
and existing.get("status") != "retracted"
350407
and existing.get("content_hash") != hash_key
351408
)
352-
overwrite = bool(arguments.get("overwrite", False))
353409
if name_conflict and not overwrite:
354410
return json.dumps(
355411
{
@@ -362,12 +418,20 @@ def handle_ingest_source(
362418
"content_hash": existing.get("content_hash", ""),
363419
"description": existing.get("description", ""),
364420
},
421+
"requires_user_confirmation": True,
422+
"user_options": [
423+
"overwrite: only after the user agrees, re-run with overwrite=true to "
424+
"replace the existing document (the old raw file moves to .trash)",
425+
"rename: pass a different 'name' to keep both documents",
426+
"cancel: drop this import and keep the existing source untouched",
427+
],
365428
"message": (
366429
f"Source name '{name}' is already registered to a different document "
367430
f"({existing.get('path') or existing.get('original_path')}, imported "
368431
f"{existing.get('imported_at', 'unknown')}). The new file was NOT stored. "
369-
"After user confirmation, re-run ingest_source with overwrite=true to "
370-
"replace it (the existing raw file will be moved to .trash), or pass a "
432+
"ASK THE USER first — do not silently skip, rename or overwrite. After the "
433+
"user confirms a replacement, re-run ingest_source with overwrite=true "
434+
"(the existing raw file will be moved to .trash); otherwise pass a "
371435
"different 'name' to keep both documents."
372436
),
373437
},

‎repowiki/.meta/telemetry/iamwangbao-163-com.jsonl‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,24 @@
181181
{"t": "hit", "doc": "wiki/modules/WebApp.md", "at": "2026-09-04", "n": 1}
182182
{"t": "hit", "doc": "wiki/modules/KnowledgeStore.md", "at": "2026-09-04", "n": 1}
183183
{"t": "hit", "doc": "notes/2026-08-26-build-后端-setuptoolshatchling-迁移后-wheel-内容会变化需对比文件清单而非只看能否安装.md", "at": "2026-09-04", "n": 1}
184+
{"t": "adopted", "doc": "notes/2026-08-26-github-竞品分层调研tencentdb-agent-memory-为直接竞品llm-wiki-家族为理念源头.md", "at": "2026-09-05T18:18:50", "key": "iamwangbao-163-com/a70f83a01faf4c36b42b2819fd61bf45"}
185+
{"t": "adopted", "doc": "raw/sources/tam-team-memory-practice.md", "at": "2026-09-05T18:18:50", "key": "iamwangbao-163-com/a70f83a01faf4c36b42b2819fd61bf45"}
186+
{"t": "hit", "doc": "notes/2026-08-29-生成的-ps1-必须带-utf-8-bom否则-powershell-51-按-gbk-误读.md", "at": "2026-09-05", "n": 2}
187+
{"t": "hit", "doc": "notes/2026-08-03-mcp-工具-schema-不声明-session-idhandler-隐式读取.md", "at": "2026-09-05", "n": 8}
188+
{"t": "hit", "doc": "wiki/modules/KnowledgeStore.md", "at": "2026-09-05", "n": 2}
189+
{"t": "hit", "doc": "wiki/scenarios/MCP-Server薄壳架构与参数约定.md", "at": "2026-09-05", "n": 8}
190+
{"t": "hit", "doc": "wiki/modules/CLI_Adapter.md", "at": "2026-09-05", "n": 2}
191+
{"t": "hit", "doc": "notes/2026-08-26-load-project-checklist-对-yaml-损坏静默回退-none-无日志难排查.md", "at": "2026-09-05", "n": 2}
192+
{"t": "hit", "doc": "wiki/modules/CLI_Utils.md", "at": "2026-09-05", "n": 2}
193+
{"t": "hit", "doc": "wiki/scenarios/Wiki页面生成约定与数据结构.md", "at": "2026-09-05", "n": 2}
194+
{"t": "hit", "doc": "notes/2026-08-29-工作区痕迹齐备时跳过-init-workspace直接跑-bootstrap-脚本补-clone.md", "at": "2026-09-05", "n": 2}
195+
{"t": "hit", "doc": "notes/2026-08-29-subagent-定义的-frontmatter-按宿主家族分发同名文件不同-schema.md", "at": "2026-09-05", "n": 4}
196+
{"t": "hit", "doc": "notes/2026-08-23-distill-worker-subagent-定义随包发布hook-启用时自动拷贝到项目-codebuddyagent.md", "at": "2026-09-05", "n": 4}
197+
{"t": "hit", "doc": "wiki/modules/MCP_Prompts.md", "at": "2026-09-05", "n": 6}
198+
{"t": "hit", "doc": "notes/2026-08-25-mcp-参数长度受限时蒸馏-submit-走文件侧通道python-脚本直接调-handle-distill-conve.md", "at": "2026-09-05", "n": 2}
199+
{"t": "hit", "doc": "wiki/modules/MCP_Core.md", "at": "2026-09-05", "n": 6}
200+
{"t": "hit", "doc": "wiki/modules/MCP_Server.md", "at": "2026-09-05", "n": 6}
201+
{"t": "hit", "doc": "notes/2026-08-25-doctrine-不会自动注入-agent-上下文唯一通道是-query-wikimodeoverview.md", "at": "2026-09-05", "n": 2}
202+
{"t": "hit", "doc": "wiki/modules/MCP_Tools_Knowledge.md", "at": "2026-09-05", "n": 4}
203+
{"t": "hit", "doc": "wiki/modules/MCP_Tools_DocWriter.md", "at": "2026-09-05", "n": 4}
204+
{"t": "hit", "doc": "wiki/modules/MCP_Tools_Analysis.md", "at": "2026-09-05", "n": 2}

‎tests/okf_regression_test.py‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,76 @@ def main():
796796
str([f.name for f in trash_files]),
797797
)
798798

799+
# duplicate 确认闸门:内容已登记 → 不落盘,须询问用户后重跑
800+
ri_name = "ext-spec-ri"
801+
r = json.loads(
802+
handle_ingest_source(
803+
{"session_id": sid, "source_ref": str(src_file), "name": ri_name},
804+
store,
805+
)
806+
)
807+
check("ingest_source", "duplicate场景首次登记成功", r.get("status") == "ingested", str(r)[:200])
808+
809+
r = json.loads(
810+
handle_ingest_source(
811+
{"session_id": sid, "source_ref": str(src_file), "name": ri_name},
812+
store,
813+
)
814+
)
815+
check("ingest_source", "相同内容提示duplicate", r.get("status") == "duplicate", str(r)[:200])
816+
check(
817+
"ingest_source",
818+
"duplicate要求用户确认",
819+
r.get("requires_user_confirmation") is True,
820+
str(r)[:300],
821+
)
822+
check(
823+
"ingest_source",
824+
"duplicate返回既有来源信息",
825+
bool(r.get("existing", {}).get("path")) and r.get("existing", {}).get("name") == ri_name,
826+
str(r)[:300],
827+
)
828+
check("ingest_source", "duplicate给出用户选项", len(r.get("user_options", [])) >= 3, str(r)[:300])
829+
830+
# 异名 + overwrite → 拒绝,避免同一内容两份副本污染检索
831+
r = json.loads(
832+
handle_ingest_source(
833+
{
834+
"session_id": sid,
835+
"source_ref": str(src_file),
836+
"name": f"{ri_name}-copy",
837+
"overwrite": True,
838+
},
839+
store,
840+
)
841+
)
842+
check(
843+
"ingest_source",
844+
"duplicate异名overwrite被拒",
845+
r.get("status") == "error" and r.get("duplicate_of") == ri_name,
846+
str(r)[:300],
847+
)
848+
849+
# 同名 + overwrite(用户确认)→ 重新落盘,旧 raw 移入 .trash
850+
r = json.loads(
851+
handle_ingest_source(
852+
{"session_id": sid, "source_ref": str(src_file), "name": ri_name, "overwrite": True},
853+
store,
854+
)
855+
)
856+
check("ingest_source", "duplicate确认后重导成功", r.get("status") == "ingested", str(r)[:200])
857+
ri_trash = (
858+
list((output_dir / ".trash").glob(f"{ri_name}*.md"))
859+
if (output_dir / ".trash").is_dir()
860+
else []
861+
)
862+
check(
863+
"ingest_source",
864+
"duplicate重导后旧raw移入.trash",
865+
bool(ri_trash),
866+
str([f.name for f in ri_trash]),
867+
)
868+
799869
# ================================================================
800870
print("\n[8] retract_source — dry_run与引用清理")
801871
r = json.loads(

0 commit comments

Comments
 (0)