krouter-memory 2.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. krouter/__init__.py +184 -0
  2. krouter/cli.py +102 -0
  3. krouter/demo.py +110 -0
  4. krouter/doctor.py +331 -0
  5. krouter/integrations/__init__.py +1 -0
  6. krouter/integrations/langgraph.py +883 -0
  7. krouter/integrations/langgraph_demo.py +82 -0
  8. krouter/integrations/llamaindex.py +44 -0
  9. krouter/sample.py +257 -0
  10. krouter/view.py +230 -0
  11. krouter/view_ui/app.css +123 -0
  12. krouter/view_ui/app.js +349 -0
  13. krouter/view_ui/index.html +31 -0
  14. krouter/viewdata.py +572 -0
  15. krouter/why.py +824 -0
  16. krouter_memory-2.2.1.dist-info/METADATA +378 -0
  17. krouter_memory-2.2.1.dist-info/RECORD +98 -0
  18. krouter_memory-2.2.1.dist-info/WHEEL +5 -0
  19. krouter_memory-2.2.1.dist-info/entry_points.txt +2 -0
  20. krouter_memory-2.2.1.dist-info/licenses/LICENSE +21 -0
  21. krouter_memory-2.2.1.dist-info/top_level.txt +4 -0
  22. krouter_router/answer_cards.py +297 -0
  23. krouter_router/ask_product.py +400 -0
  24. krouter_router/ask_reader.py +189 -0
  25. krouter_router/associate.py +506 -0
  26. krouter_router/backup.py +418 -0
  27. krouter_router/canonical_lookup.py +392 -0
  28. krouter_router/canonical_sources.psv +11 -0
  29. krouter_router/capture_ledger.py +168 -0
  30. krouter_router/checkup.py +223 -0
  31. krouter_router/cocite.py +91 -0
  32. krouter_router/compile_subconscious.py +513 -0
  33. krouter_router/consolidate_topics.py +242 -0
  34. krouter_router/corrections.py +455 -0
  35. krouter_router/evidence.py +601 -0
  36. krouter_router/experience.py +759 -0
  37. krouter_router/hot.py +246 -0
  38. krouter_router/import_claude_mem.py +419 -0
  39. krouter_router/import_sessions.py +1015 -0
  40. krouter_router/kb.py +955 -0
  41. krouter_router/krouter_home.py +85 -0
  42. krouter_router/krouter_redact.py +131 -0
  43. krouter_router/learn_mentions.py +273 -0
  44. krouter_router/lexicon_zh2.txt +23631 -0
  45. krouter_router/llm.py +871 -0
  46. krouter_router/mcp_server.py +1153 -0
  47. krouter_router/nightly.py +333 -0
  48. krouter_router/notify.py +70 -0
  49. krouter_router/propose_aliases.py +232 -0
  50. krouter_router/pyfind.sh +36 -0
  51. krouter_router/recall_index.py +1560 -0
  52. krouter_router/recollect.py +1142 -0
  53. krouter_router/reconsolidate.py +188 -0
  54. krouter_router/route_knowledge.py +684 -0
  55. krouter_router/route_knowledge.sh +336 -0
  56. krouter_router/route_worker.py +83 -0
  57. krouter_router/session_hook.py +676 -0
  58. krouter_router/skills.py +853 -0
  59. krouter_router/team.py +335 -0
  60. krouter_router/zones.py +199 -0
  61. krouter_router/zones_en.psv +40 -0
  62. krouter_template/01 /351/241/271/347/233/256//347/244/272/344/276/213/351/241/271/347/233/256//347/244/272/344/276/213/351/241/271/347/233/256.md" +8 -0
  63. krouter_template/01 /351/241/271/347/233/256//351/241/271/347/233/256.md" +10 -0
  64. krouter_template/02 /347/273/217/351/252/214/344/270/216/346/226/271/346/263/225/Agent//347/224/250/346/210/267/345/201/217/345/245/275/344/270/216/345/267/245/344/275/234/347/272/246/346/235/237.md" +10 -0
  65. krouter_template/02 /347/273/217/351/252/214/344/270/216/346/226/271/346/263/225/Automation/Seal the day from the log file.md" +28 -0
  66. krouter_template/02 /347/273/217/351/252/214/344/270/216/346/226/271/346/263/225//345/207/206/347/273/217/351/252/214/A timer that fired is not a product.md" +36 -0
  67. krouter_template/02 /347/273/217/351/252/214/344/270/216/346/226/271/346/263/225//345/207/206/347/273/217/351/252/214//345/207/206/347/273/217/351/252/214/345/205/245/345/217/243.md" +19 -0
  68. krouter_template/02 /347/273/217/351/252/214/344/270/216/346/226/271/346/263/225//347/273/217/351/252/214/344/270/216/346/226/271/346/263/225.md" +31 -0
  69. krouter_template/03 /350/265/204/346/226/231/344/270/216/350/257/201/346/215/256//350/265/204/346/226/231/344/270/216/350/257/201/346/215/256.md" +8 -0
  70. krouter_template/04 /345/267/262/345/256/214/346/210/220/344/270/216/345/244/215/347/233/230//345/267/262/345/256/214/346/210/220/344/270/216/345/244/215/347/233/230.md" +8 -0
  71. krouter_template/05 /346/227/266/351/227/264/346/227/245/345/277/227/2026-01/01/357/275/234/347/244/272/344/276/213/346/227/245.md" +9 -0
  72. krouter_template/05 /346/227/266/351/227/264/346/227/245/345/277/227//346/227/266/351/227/264/346/227/245/345/277/227/345/205/245/345/217/243.md" +8 -0
  73. krouter_template/90 /347/263/273/347/273/237/346/226/207/344/273/266/Agent/350/256/260/345/277/206//345/217/257/351/235/240/350/256/260/345/277/206/347/264/242/345/274/225.md" +8 -0
  74. krouter_template/90 /347/263/273/347/273/237/346/226/207/344/273/266/Agent/350/256/260/345/277/206//347/272/240/351/224/231/344/270/216/345/217/226/344/273/243/350/256/260/345/275/225.md" +8 -0
  75. krouter_template/90 /347/263/273/347/273/237/346/226/207/344/273/266/Clippings /346/225/264/347/220/206/350/256/260/345/275/225.json" +3 -0
  76. krouter_template/90 /347/263/273/347/273/237/346/226/207/344/273/266//347/212/266/346/200/201.md" +10 -0
  77. krouter_template/90 /347/263/273/347/273/237/346/226/207/344/273/266//350/207/252/345/212/250/345/214/226//346/227/245/346/233/264/345/201/245/345/272/267.md" +15 -0
  78. krouter_template/90 /347/263/273/347/273/237/346/226/207/344/273/266//350/207/252/345/212/250/345/214/226//350/207/252/350/277/233/345/214/226/351/222/245/345/214/231.md" +38 -0
  79. krouter_template/Agent/347/254/254/344/272/214/345/244/247/350/204/221.md +29 -0
  80. krouter_template_zh/01 /351/241/271/347/233/256//347/244/272/344/276/213/351/241/271/347/233/256//347/244/272/344/276/213/351/241/271/347/233/256.md" +8 -0
  81. krouter_template_zh/01 /351/241/271/347/233/256//351/241/271/347/233/256.md" +10 -0
  82. krouter_template_zh/02 /347/273/217/351/252/214/344/270/216/346/226/271/346/263/225/Agent//347/224/250/346/210/267/345/201/217/345/245/275/344/270/216/345/267/245/344/275/234/347/272/246/346/235/237.md" +10 -0
  83. krouter_template_zh/02 /347/273/217/351/252/214/344/270/216/346/226/271/346/263/225//345/207/206/347/273/217/351/252/214//345/207/206/347/273/217/351/252/214/345/205/245/345/217/243.md" +19 -0
  84. krouter_template_zh/02 /347/273/217/351/252/214/344/270/216/346/226/271/346/263/225//345/207/206/347/273/217/351/252/214//345/256/232/346/227/266/345/231/250/345/223/215/344/272/206/344/270/215/347/255/211/344/272/216/346/264/273/345/271/262/345/256/214/344/272/206.md" +36 -0
  85. krouter_template_zh/02 /347/273/217/351/252/214/344/270/216/346/226/271/346/263/225//347/273/217/351/252/214/344/270/216/346/226/271/346/263/225.md" +31 -0
  86. krouter_template_zh/02 /347/273/217/351/252/214/344/270/216/346/226/271/346/263/225//350/207/252/345/212/250/345/214/226//346/214/211/346/227/245/345/277/227/346/226/207/344/273/266/345/210/244/346/226/255/345/260/201/350/264/246.md" +28 -0
  87. krouter_template_zh/03 /350/265/204/346/226/231/344/270/216/350/257/201/346/215/256//350/265/204/346/226/231/344/270/216/350/257/201/346/215/256.md" +8 -0
  88. krouter_template_zh/04 /345/267/262/345/256/214/346/210/220/344/270/216/345/244/215/347/233/230//345/267/262/345/256/214/346/210/220/344/270/216/345/244/215/347/233/230.md" +8 -0
  89. krouter_template_zh/05 /346/227/266/351/227/264/346/227/245/345/277/227/2026-01/01/357/275/234/347/244/272/344/276/213/346/227/245.md" +9 -0
  90. krouter_template_zh/05 /346/227/266/351/227/264/346/227/245/345/277/227//346/227/266/351/227/264/346/227/245/345/277/227/345/205/245/345/217/243.md" +8 -0
  91. krouter_template_zh/90 /347/263/273/347/273/237/346/226/207/344/273/266/Agent/350/256/260/345/277/206//345/217/257/351/235/240/350/256/260/345/277/206/347/264/242/345/274/225.md" +8 -0
  92. krouter_template_zh/90 /347/263/273/347/273/237/346/226/207/344/273/266/Agent/350/256/260/345/277/206//347/272/240/351/224/231/344/270/216/345/217/226/344/273/243/350/256/260/345/275/225.md" +8 -0
  93. krouter_template_zh/90 /347/263/273/347/273/237/346/226/207/344/273/266/Clippings /346/225/264/347/220/206/350/256/260/345/275/225.json" +3 -0
  94. krouter_template_zh/90 /347/263/273/347/273/237/346/226/207/344/273/266/canonical_sources.psv" +11 -0
  95. krouter_template_zh/90 /347/263/273/347/273/237/346/226/207/344/273/266//347/212/266/346/200/201.md" +10 -0
  96. krouter_template_zh/90 /347/263/273/347/273/237/346/226/207/344/273/266//350/207/252/345/212/250/345/214/226//346/227/245/346/233/264/345/201/245/345/272/267.md" +15 -0
  97. krouter_template_zh/90 /347/263/273/347/273/237/346/226/207/344/273/266//350/207/252/345/212/250/345/214/226//350/207/252/350/277/233/345/214/226/351/222/245/345/214/231.md" +38 -0
  98. krouter_template_zh/Agent/347/254/254/344/272/214/345/244/247/350/204/221.md +29 -0
krouter/doctor.py ADDED
@@ -0,0 +1,331 @@
1
+ """`krouter doctor`: one verdict on this machine's KRouter — OK, or what is missing and the command that fixes it.
2
+
3
+ Reads only: the recorded vault, its health page, the apps' settings files, the nightly job's file. Runs one local
4
+ lookup to prove the router answers. Calls no model and nothing on the network. Exit 0 when lookup works (notes are
5
+ things that are off by choice or need a model), 1 when something is broken.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import os
12
+ import re
13
+ import shutil
14
+ import subprocess
15
+ import sys
16
+ import time
17
+ from pathlib import Path
18
+
19
+ from . import ask, router_dir
20
+
21
+
22
+ def _vault(explicit: str | None) -> Path | None:
23
+ raw = explicit or os.environ.get("KROUTER_VAULT") or os.environ.get("OBSIDIAN_VAULT", "")
24
+ if not raw:
25
+ vf = Path(os.environ.get("KROUTER_VAULT_FILE") or Path(os.environ.get("XDG_CONFIG_HOME") or Path.home() / ".config")
26
+ / "krouter" / "vault")
27
+ try:
28
+ raw = vf.read_text(encoding="utf-8").splitlines()[0].strip()
29
+ except (OSError, IndexError):
30
+ raw = ""
31
+ return Path(raw).expanduser() if raw else None
32
+
33
+
34
+ def _frontmatter(page: Path) -> dict:
35
+ try:
36
+ text = page.read_text(encoding="utf-8")
37
+ except OSError:
38
+ return {}
39
+ if not text.startswith("---"):
40
+ return {}
41
+ out = {}
42
+ for line in text.split("---", 2)[1].splitlines():
43
+ key, sep, val = line.partition(":")
44
+ if sep:
45
+ out[key.strip()] = val.strip().strip('"')
46
+ return out
47
+
48
+
49
+ def _json(path: Path) -> dict:
50
+ try:
51
+ data = json.loads(path.read_text(encoding="utf-8"))
52
+ return data if isinstance(data, dict) else {}
53
+ except (OSError, ValueError):
54
+ return {}
55
+
56
+
57
+ def _apps() -> list[str]:
58
+ """Where KRouter is connected: MCP entries the installer writes, and the Claude Code plugin."""
59
+ home = Path.home()
60
+ found = []
61
+ if "krouter" in (_json(home / ".claude.json").get("mcpServers") or {}):
62
+ found.append("Claude Code (MCP)")
63
+ if (_json(home / ".claude/settings.json").get("enabledPlugins") or {}).get("krouter@krouter"):
64
+ found.append("Claude Code plugin")
65
+ codex = Path(os.environ.get("CODEX_HOME") or home / ".codex") / "config.toml"
66
+ try:
67
+ if "[mcp_servers.krouter]" in codex.read_text(encoding="utf-8"):
68
+ found.append("Codex (MCP)")
69
+ except OSError:
70
+ pass
71
+ if sys.platform == "darwin":
72
+ desktop = home / "Library/Application Support/Claude/claude_desktop_config.json"
73
+ elif os.name == "nt":
74
+ desktop = Path(os.environ.get("APPDATA", "")) / "Claude/claude_desktop_config.json"
75
+ else:
76
+ desktop = Path(os.environ.get("XDG_CONFIG_HOME") or home / ".config") / "Claude/claude_desktop_config.json"
77
+ for name, path, key in (("Claude Desktop", desktop, "mcpServers"), ("Cursor", home / ".cursor/mcp.json", "mcpServers"),
78
+ ("Gemini CLI", home / ".gemini/settings.json", "mcpServers")):
79
+ if "krouter" in (_json(path).get(key) or {}):
80
+ found.append(name)
81
+ return found
82
+
83
+
84
+ LEGACY = "krouter-obsidian" # 2.0 以前的目录名:~/.agents/skills/krouter-obsidian,仓库里的 skill/krouter-obsidian
85
+
86
+
87
+ def _legacy_configs() -> list[str]:
88
+ """Settings files that still start KRouter from the pre-2.0 path."""
89
+ home = Path.home()
90
+ if sys.platform == "darwin":
91
+ desktop = home / "Library/Application Support/Claude/claude_desktop_config.json"
92
+ elif os.name == "nt":
93
+ desktop = Path(os.environ.get("APPDATA", "")) / "Claude/claude_desktop_config.json"
94
+ else:
95
+ desktop = Path(os.environ.get("XDG_CONFIG_HOME") or home / ".config") / "Claude/claude_desktop_config.json"
96
+ codex = Path(os.environ.get("CODEX_HOME") or home / ".codex")
97
+ files = [home / ".claude.json", codex / "config.toml", codex / "hooks.json", home / ".cursor/mcp.json",
98
+ home / ".cursor/hooks.json", home / ".gemini/settings.json", desktop,
99
+ home / "Library/LaunchAgents/local.dsh-krouter.daily-evolution.plist",
100
+ home / ".config/systemd/user/dsh-krouter-daily.service"]
101
+ out = []
102
+ for f in files:
103
+ try:
104
+ text = f.read_text(encoding="utf-8", errors="replace")
105
+ except OSError:
106
+ continue
107
+ if f"skills/{LEGACY}/" in text or f"skills\\{LEGACY}\\" in text or f"skill/{LEGACY}/" in text:
108
+ out.append(str(f).replace(str(home), "~", 1))
109
+ return out
110
+
111
+
112
+ def _nightly_installed() -> bool:
113
+ home = Path.home()
114
+ if (home / "Library/LaunchAgents/local.dsh-krouter.daily-evolution.plist").is_file():
115
+ return True
116
+ if (home / ".config/systemd/user/dsh-krouter-daily.timer").is_file():
117
+ return True
118
+ if os.name == "nt":
119
+ try:
120
+ res = subprocess.run(["schtasks", "/Query", "/TN", "KRouter daily evolution"], capture_output=True, text=True,
121
+ timeout=30)
122
+ except (OSError, subprocess.SubprocessError):
123
+ return False
124
+ return res.returncode == 0
125
+ if sys.platform.startswith("linux") and shutil.which("crontab"): # install.sh 只在 Linux 上用 crontab
126
+ try: # 能找到却不能执行(沙箱)也当没有
127
+ res = subprocess.run(["crontab", "-l"], capture_output=True, text=True, timeout=30)
128
+ except (OSError, subprocess.SubprocessError):
129
+ return False
130
+ return "# dsh-krouter-daily" in (res.stdout or "")
131
+ return False
132
+
133
+
134
+ def _desktop_dir() -> Path:
135
+ home = Path.home()
136
+ if sys.platform == "darwin":
137
+ return home / "Library/Application Support/Claude"
138
+ if os.name == "nt":
139
+ return Path(os.environ.get("APPDATA", "")) / "Claude"
140
+ return Path(os.environ.get("XDG_CONFIG_HOME") or home / ".config") / "Claude"
141
+
142
+
143
+ def _desktop_note(boot: str) -> tuple[str, str] | None:
144
+ """Claude Desktop is installed but KRouter is in neither its settings file nor its extensions. The usual cause:
145
+ the entry was written while the app was open, and the app wrote its old settings back when it quit."""
146
+ d = _desktop_dir()
147
+ cfg = Path(os.environ.get("KROUTER_CLAUDE_DESKTOP_CONFIG") or d / "claude_desktop_config.json")
148
+ if not d.is_dir() and not cfg.exists():
149
+ return None
150
+ if "krouter" in (_json(cfg).get("mcpServers") or {}):
151
+ return ("ok", f"Claude Desktop: connected through {cfg}")
152
+ for man in (d / "Claude Extensions").glob("*/manifest.json"):
153
+ if _json(man).get("name") == "krouter":
154
+ return ("ok", f"Claude Desktop: connected as an extension ({man.parent})")
155
+ vf = Path(os.environ.get("KROUTER_VAULT_FILE") or Path(os.environ.get("XDG_CONFIG_HOME") or Path.home() / ".config")
156
+ / "krouter" / "vault")
157
+ mcpb = vf.parent / "KRouter.mcpb"
158
+ return ("note", "Claude Desktop: installed, but KRouter is in neither its settings file nor its extensions (an "
159
+ "entry written while the app is open is lost when it quits). Fix: quit Claude Desktop, then "
160
+ f"{boot} --connect claude-desktop; or double-click "
161
+ + (str(mcpb) if mcpb.is_file() else "KRouter.mcpb from the release") + " and press Install")
162
+
163
+
164
+ def _bootstrap() -> str:
165
+ """The installer to name in a fix: the downloaded release's, else this repository's."""
166
+ for cand in (Path(os.environ.get("KROUTER_HOME") or Path.home() / ".dsh-krouter") / "current/scripts/bootstrap.py",
167
+ Path(__file__).resolve().parents[2] / "scripts/bootstrap.py"):
168
+ if cand.is_file():
169
+ return f'python3 "{cand}"'
170
+ return "the one-line install in the README"
171
+
172
+
173
+ def run(vault_arg: str | None = None) -> int:
174
+ rows: list[tuple[str, str]] = [] # (ok | note | FAIL, text)
175
+ if sys.version_info < (3, 9):
176
+ rows.append(("FAIL", f"python: {sys.version.split()[0]}; KRouter needs 3.9 or newer"))
177
+ sys.path.insert(0, str(router_dir()))
178
+ import zones
179
+
180
+ vault = _vault(vault_arg)
181
+ boot = _bootstrap()
182
+ if vault is None:
183
+ rows.append(("FAIL", f"memory folder: none recorded. Fix: {boot} (or pass --vault, or set KROUTER_VAULT)"))
184
+ elif not vault.is_dir():
185
+ rows.append(("FAIL", f"memory folder: {vault} does not exist. Fix: {boot} --vault <your folder>"))
186
+ else:
187
+ layout = "English names" if zones.lang(vault) == "en" else "default names"
188
+ rows.append(("ok", f"memory folder: {vault} ({layout})"))
189
+ home = zones.path(vault, "Agent第二大脑.md")
190
+ if not home.is_file():
191
+ rows.append(("FAIL", f"home page missing: {home}. Fix: {boot} --vault \"{vault}\" (adds only missing files)"))
192
+ start = time.time()
193
+ os.environ["KROUTER_NO_QUERY_LOG"] = "1" # 自检不是真问题:不进夜间学习读的查询日志
194
+ try:
195
+ a = ask("home", vault=vault)
196
+ took = time.time() - start
197
+ if a.page or a.refused:
198
+ rows.append(("ok", f"lookup: answered in {took:.2f} s" + (f" from {a.page}" if a.page else " (said: not in the memory)")))
199
+ else:
200
+ rows.append(("FAIL", "lookup: no receipt came back. Fix: reinstall with " + boot))
201
+ except Exception as exc: # noqa: BLE001 - 查询失败本身就是要报的结论
202
+ rows.append(("FAIL", f"lookup failed: {exc}. Fix: reinstall with {boot}"))
203
+ table = zones.path(vault, "90 系统文件/canonical_sources.psv")
204
+ rows.append(("ok", f"alias table: {table}") if table.is_file() else
205
+ ("note", f"alias table: none in the memory folder; the sample one is used. Fix: {boot} --vault \"{vault}\""))
206
+ meta = _frontmatter(zones.path(vault, "90 系统文件/自动化/日更健康.md"))
207
+ key = meta.get("self_evolution_key", "missing")
208
+ if key == "present": # install.sh 探过:登录了的 CLI 或能用的 key(只装了 CLI、没登录不算)
209
+ rows.append(("ok", "model: connected (distilling and the nightly upkeep can run)"))
210
+ else:
211
+ keys = os.environ.get("KROUTER_KEYS_ENV") or str(Path.home() / ".dsh-krouter-keys.env")
212
+ rows.append(("note", "model: none. Lookup, sources, refusals and the local import work, and a change of "
213
+ "mind still wins when the newer page says so (listed first, flagged) or the agent "
214
+ "records it with krouter_correct; distilling, the nightly upkeep and settling correction "
215
+ "candidates do not run, so a change worded another way can leave the old answer first. "
216
+ f"Fix: log in to claude / codex / grok once, or put an API key in {keys}"))
217
+ try: # 知识库(kb.py):声明了哪些;没声明、但看起来像外来资料的文件夹只作建议,不自动生效
218
+ import kb
219
+
220
+ folders = kb.declared(vault)
221
+ if folders:
222
+ rows.append(("ok", "knowledge base: " + ", ".join(folders) + f" ({kb.KB_FILE})"))
223
+ for sug in kb.suggest(vault, limit=3):
224
+ rows.append(("note", f"knowledge base: {sug['folder']} looks like reference material ({sug['pages']} "
225
+ f"pages, {sug['url']} with a source address, {sug['long']} long) and is not "
226
+ f"declared. To declare: krouter kb add \"{sug['folder']}\""))
227
+ except Exception: # noqa: BLE001 - 建议算不出来不影响结论
228
+ pass
229
+ installed = _nightly_installed()
230
+ lamp = meta.get("lamp", "")
231
+ if installed:
232
+ rows.append(("ok", "nightly job: installed"))
233
+ elif lamp == "running":
234
+ rows.append(("FAIL", "nightly job: the health page says running, but no job is installed. Fix: "
235
+ f"{boot} --timer --vault \"{vault}\", or set lamp: unused on the health page"))
236
+ else:
237
+ rows.append(("note", f"nightly job: not installed (off by default). Turn on: {boot} --timer --vault \"{vault}\""))
238
+ desk = _desktop_note(boot)
239
+ if desk:
240
+ rows.append(desk)
241
+ old = _legacy_configs()
242
+ if old:
243
+ link = Path.home() / ".agents/skills" / LEGACY
244
+ works = link.is_symlink() and link.exists()
245
+ rows.append(("note" if works else "FAIL",
246
+ "old path: " + ", ".join(old) + f": KRouter still starts from ~/.agents/skills/{LEGACY} (renamed to "
247
+ "~/.agents/skills/krouter in 2.0" + ("; the old path is a link to it, so it works for now" if works
248
+ else ", and nothing is there any more") +
249
+ f"). Fix: {boot} (registers MCP, hooks and the nightly job at the new path)"))
250
+ apps = _apps()
251
+ rows.append(("ok", "connected: " + ", ".join(apps)) if apps else
252
+ ("note", f"connected: no app found. Fix: {boot} --apps claude,codex,cursor (or the MCP block in the README)"))
253
+ if not shutil.which("rg"):
254
+ rows.append(("note", "ripgrep: not found; literal search uses the built-in fallback (same answers, slower on "
255
+ "large vaults)"))
256
+ zh = vault is not None and vault.is_dir() and zones.lang(vault) == "zh" # 中文名字的库:结论用中文说
257
+ width = max(len(s) for s, _ in rows)
258
+ print("krouter doctor")
259
+ for state, text in rows:
260
+ print(f" {state.ljust(width)} {to_zh(text) if zh else text}")
261
+ fails = [t for s, t in rows if s == "FAIL"]
262
+ notes = sum(1 for s, _ in rows if s == "note")
263
+ if fails:
264
+ print(f"结论:有问题,{len(fails)} 处(FAIL 那几行写了怎么修)" if zh else
265
+ f"verdict: NOT OK, {len(fails)} problem{'s' if len(fails) > 1 else ''} (the FAIL lines say how to fix each)")
266
+ return 1
267
+ if zh:
268
+ print("结论:OK" + (f"(上面 {notes} 条提示:有意关着的,或者要模型才行的)" if notes else ""))
269
+ else:
270
+ print("verdict: OK" + (f" ({notes} note{'s' if notes > 1 else ''} above: off by choice, or needs a model)" if notes else ""))
271
+ return 0
272
+
273
+
274
+ # 中文名字的库里,每一行按同一个意思换成中文;路径、命令原样保留。新加一行英文,记得在这里加一条
275
+ ZH = [
276
+ (r"^python: (.+); KRouter needs 3\.9 or newer$", r"Python:\1;KRouter 需要 3.9 或更新版本"),
277
+ (r"^memory folder: none recorded\. Fix: (.+) \(or pass --vault, or set KROUTER_VAULT\)$",
278
+ r"记忆文件夹:没有记录。修复:\1(或者传 --vault,或者设 KROUTER_VAULT)"),
279
+ (r"^memory folder: (.+) does not exist\. Fix: (.+)$", r"记忆文件夹:\1 不存在。修复:\2"),
280
+ (r"^memory folder: (.+) \(default names\)$", r"记忆文件夹:\1(默认的中文名字)"),
281
+ (r"^memory folder: (.+) \(English names\)$", r"记忆文件夹:\1(英文名字)"),
282
+ (r"^home page missing: (.+)\. Fix: (.+) \(adds only missing files\)$", r"首页不见了:\1。修复:\2(只补缺的文件)"),
283
+ (r"^lookup: answered in ([\d.]+) s from (.+)$", r"查询:\1 秒答出,出处 \2"),
284
+ (r"^lookup: answered in ([\d.]+) s \(said: not in the memory\)$", r"查询:\1 秒答出(答的是:库里没有)"),
285
+ (r"^lookup: no receipt came back\. Fix: reinstall with (.+)$", r"查询:没有拿到回执。修复:用 \1 重装"),
286
+ (r"^lookup failed: (.+)\. Fix: reinstall with (.+)$", r"查询出错:\1。修复:用 \2 重装"),
287
+ (r"^alias table: none in the memory folder; the sample one is used\. Fix: (.+)$",
288
+ r"别名表:库里没有,用的是样例那份。修复:\1"),
289
+ (r"^alias table: (.+)$", r"别名表:\1"),
290
+ (r"^model: connected \(distilling and the nightly upkeep can run\)$", r"模型:已接上(提炼和夜间整理能跑)"),
291
+ (r"^model: none\. .*Fix: log in to claude / codex / grok once, or put an API key in (.+)$",
292
+ r"模型:没有。查询、出处、拒答、本地导入都照常;新页写明改了主意时会排在前面并标出来,agent 用 krouter_correct "
293
+ r"当轮落实纠正也照常;提炼、夜间整理和纠正候选的判定不跑,所以换了别的说法的改主意,旧答案仍可能排第一。"
294
+ r"修复:登录一次 claude / codex / grok,或者把 API key 写进 \1"),
295
+ (r"^knowledge base: (.+) looks like reference material \((\d+) pages, (\d+) with a source address, (\d+) long\) and "
296
+ r"is not declared\. To declare: (.+)$",
297
+ r"知识库:\1 看起来是外来的参考资料(\2 页,\3 页带来源网址,\4 页是长文),还没声明。要声明:\5"),
298
+ (r"^knowledge base: (.+) \((krouter-kb\.txt)\)$", r"知识库:\1(\2)"),
299
+ (r"^nightly job: installed$", r"夜间任务:已装"),
300
+ (r"^nightly job: the health page says running, but no job is installed\. Fix: (.+), or set lamp: unused on the health page$",
301
+ r"夜间任务:健康页说在跑,但本机没装任何任务。修复:\1,或者把健康页的 lamp 改成 unused"),
302
+ (r"^nightly job: not installed \(off by default\)\. Turn on: (.+)$", r"夜间任务:没装(默认不装)。要开:\1"),
303
+ (r"^Claude Desktop: connected through (.+)$", r"Claude Desktop:已通过 \1 接上"),
304
+ (r"^Claude Desktop: connected as an extension \((.+)\)$", r"Claude Desktop:已作为扩展接上(\1)"),
305
+ (r"^Claude Desktop: installed, but KRouter is in neither .*Fix: quit Claude Desktop, then (.+) --connect "
306
+ r"claude-desktop; or double-click (.+) and press Install$",
307
+ r"Claude Desktop:装了,但它的设置文件和扩展里都没有 KRouter(应用开着时写进去的条目,退出时会被它冲掉)。"
308
+ r"修复:退出 Claude Desktop,再运行 \1 --connect claude-desktop;或者双击 \2,点一次安装"),
309
+ (r"^old path: (.+): KRouter still starts from (\S+) \(renamed to ~/\.agents/skills/krouter in 2\.0; the old path "
310
+ r"is a link to it, so it works for now\)\. Fix: (.+) \(registers MCP, hooks and the nightly job at the new path\)$",
311
+ r"旧路径:\1 还在从 \2 启动 KRouter(2.0 改名为 ~/.agents/skills/krouter;旧路径是指向它的链接,暂时还能用)。"
312
+ r"修复:\3(把 MCP、钩子、夜间任务登记到新路径)"),
313
+ (r"^old path: (.+): KRouter still starts from (\S+) \(renamed to ~/\.agents/skills/krouter in 2\.0, and nothing "
314
+ r"is there any more\)\. Fix: (.+) \(registers MCP, hooks and the nightly job at the new path\)$",
315
+ r"旧路径:\1 还在从 \2 启动 KRouter(2.0 改名为 ~/.agents/skills/krouter,旧路径那里已经什么都没有了)。"
316
+ r"修复:\3(把 MCP、钩子、夜间任务登记到新路径)"),
317
+ (r"^connected: no app found\. Fix: (.+) \(or the MCP block in the README\)$",
318
+ r"已接上:没找到任何应用。修复:\1(或者照 README 里的 MCP 配置手动加)"),
319
+ (r"^connected: (.+)$", r"已接上:\1"),
320
+ (r"^ripgrep: not found; literal search uses the built-in fallback \(same answers, slower on large vaults\)$",
321
+ r"ripgrep:没找到;字面搜索用内置的替代(答案一样,大库上慢一些)"),
322
+ ]
323
+
324
+
325
+ def to_zh(text: str) -> str:
326
+ """One doctor line in Chinese; a line with no rule stays as it is (so nothing is lost)."""
327
+ for pat, rep in ZH:
328
+ out, n = re.subn(pat, rep, text, flags=re.S)
329
+ if n:
330
+ return out
331
+ return text
@@ -0,0 +1 @@
1
+ """Adapters that put KRouter where an agent framework expects memory. Each imports its framework only when used."""