wisdomgraph 0.3.1__tar.gz → 0.3.3__tar.gz
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.
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/PKG-INFO +1 -1
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/pyproject.toml +1 -1
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/tests/test_mcp.py +137 -3
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/__main__.py +51 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/local.py +64 -9
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/mcp.py +38 -6
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdomgraph.egg-info/PKG-INFO +1 -1
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/LICENSE +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/README.md +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/setup.cfg +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/tests/test_cache.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/tests/test_classify.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/tests/test_detect.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/tests/test_ingest.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/tests/test_reflect.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/tests/test_security.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/tests/test_validate.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/__init__.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/cache.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/classify.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/connect.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/detect.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/docker.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/export.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/ingest.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/merge.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/reflect.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/report.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/security.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/skill-claw.md +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/skill.md +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/traverse.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdom/validate.py +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdomgraph.egg-info/SOURCES.txt +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdomgraph.egg-info/dependency_links.txt +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdomgraph.egg-info/entry_points.txt +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdomgraph.egg-info/requires.txt +0 -0
- {wisdomgraph-0.3.1 → wisdomgraph-0.3.3}/wisdomgraph.egg-info/top_level.txt +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
4
|
import hashlib
|
|
5
|
+
import sys
|
|
5
6
|
from types import SimpleNamespace
|
|
6
7
|
from unittest.mock import MagicMock, patch
|
|
7
8
|
|
|
@@ -711,7 +712,7 @@ def test_local_up_starts_managed_backend_without_existing_container(tmp_path, mo
|
|
|
711
712
|
|
|
712
713
|
with patch("wisdom.local.shutil.which", return_value="/usr/bin/docker"), \
|
|
713
714
|
patch("wisdom.local._run", side_effect=fake_run), \
|
|
714
|
-
patch("wisdom.local.
|
|
715
|
+
patch("wisdom.local._wait_until_ready", return_value=True), \
|
|
715
716
|
patch("wisdom.local.save_connection") as save:
|
|
716
717
|
local.up(password="test-password")
|
|
717
718
|
|
|
@@ -729,14 +730,44 @@ def test_local_up_reuses_existing_running_backend(tmp_path, monkeypatch):
|
|
|
729
730
|
return SimpleNamespace(returncode=0, stdout="abc123\n", stderr="")
|
|
730
731
|
return SimpleNamespace(returncode=0, stdout="", stderr="")
|
|
731
732
|
|
|
732
|
-
|
|
733
|
+
pw_path = tmp_path / "local-password"
|
|
734
|
+
pw_path.write_text("stored-secret\n", encoding="utf-8")
|
|
735
|
+
monkeypatch.setattr(local, "PASSWORD_PATH", pw_path)
|
|
733
736
|
|
|
734
737
|
with patch("wisdom.local.shutil.which", return_value="/usr/bin/docker"), \
|
|
735
738
|
patch("wisdom.local._run", side_effect=fake_run), \
|
|
736
739
|
patch("wisdom.local.save_connection") as save:
|
|
737
740
|
local.up(password="test-password")
|
|
738
741
|
|
|
739
|
-
|
|
742
|
+
# An existing container keeps its baked-in password; --password is ignored.
|
|
743
|
+
save.assert_called_once_with(local.URI, local.USER, "stored-secret")
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
def test_wait_until_ready_fails_when_port_never_opens():
|
|
747
|
+
import wisdom.local as local
|
|
748
|
+
|
|
749
|
+
with patch("wisdom.local._wait_for_port", return_value=False), \
|
|
750
|
+
patch("wisdom.local._probe_cypher") as probe:
|
|
751
|
+
assert local._wait_until_ready("password", timeout_s=1) is False
|
|
752
|
+
probe.assert_not_called()
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
def test_wait_until_ready_waits_for_cypher_after_port_opens():
|
|
756
|
+
import wisdom.local as local
|
|
757
|
+
|
|
758
|
+
# Port is open immediately, but Cypher is only ready on the 2nd probe.
|
|
759
|
+
with patch("wisdom.local._wait_for_port", return_value=True), \
|
|
760
|
+
patch("wisdom.local._probe_cypher", side_effect=[False, True]), \
|
|
761
|
+
patch("wisdom.local.time.sleep"):
|
|
762
|
+
assert local._wait_until_ready("password", timeout_s=5) is True
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
def test_probe_cypher_is_graceful_without_neo4j_driver(monkeypatch):
|
|
766
|
+
import wisdom.local as local
|
|
767
|
+
|
|
768
|
+
# Simulate the neo4j driver not being importable in this environment.
|
|
769
|
+
monkeypatch.setitem(sys.modules, "neo4j", None)
|
|
770
|
+
assert local._probe_cypher("password") is True
|
|
740
771
|
|
|
741
772
|
|
|
742
773
|
def test_quickstart_local_registers_requested_host(monkeypatch):
|
|
@@ -763,3 +794,106 @@ def test_quickstart_existing_requires_uri(monkeypatch):
|
|
|
763
794
|
|
|
764
795
|
with pytest.raises(SystemExit):
|
|
765
796
|
_run_quickstart()
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
# ── MCP driver auto-start ──────────────────────────────────────────────────────
|
|
800
|
+
|
|
801
|
+
def test_get_driver_autostarts_local_backend_on_first_failure():
|
|
802
|
+
import wisdom.mcp as mcp
|
|
803
|
+
|
|
804
|
+
good_driver = object()
|
|
805
|
+
# First get_driver() fails (nothing running); after autostart, it succeeds.
|
|
806
|
+
get_driver = MagicMock(side_effect=[SystemExit(1), good_driver])
|
|
807
|
+
|
|
808
|
+
with patch("wisdom.connect.get_driver", get_driver), \
|
|
809
|
+
patch("wisdom.mcp._try_autostart_local", return_value=True) as autostart:
|
|
810
|
+
assert mcp._get_driver() is good_driver
|
|
811
|
+
|
|
812
|
+
autostart.assert_called_once()
|
|
813
|
+
assert get_driver.call_count == 2
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
def test_get_driver_raises_helpful_error_when_autostart_unavailable():
|
|
817
|
+
import wisdom.mcp as mcp
|
|
818
|
+
|
|
819
|
+
get_driver = MagicMock(side_effect=SystemExit(1))
|
|
820
|
+
|
|
821
|
+
with patch("wisdom.connect.get_driver", get_driver), \
|
|
822
|
+
patch("wisdom.mcp._try_autostart_local", return_value=False):
|
|
823
|
+
with pytest.raises(RuntimeError) as exc:
|
|
824
|
+
mcp._get_driver()
|
|
825
|
+
|
|
826
|
+
assert "quickstart" in str(exc.value)
|
|
827
|
+
# Only the initial attempt — no retry when autostart could not run.
|
|
828
|
+
assert get_driver.call_count == 1
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
def test_try_autostart_local_skips_when_docker_absent():
|
|
832
|
+
import wisdom.mcp as mcp
|
|
833
|
+
|
|
834
|
+
with patch("wisdom.local.docker_daemon_available", return_value=False), \
|
|
835
|
+
patch("wisdom.local.up") as up:
|
|
836
|
+
assert mcp._try_autostart_local() is False
|
|
837
|
+
up.assert_not_called()
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
def test_try_autostart_local_starts_backend_when_docker_present():
|
|
841
|
+
import wisdom.mcp as mcp
|
|
842
|
+
|
|
843
|
+
with patch("wisdom.local.docker_daemon_available", return_value=True), \
|
|
844
|
+
patch("wisdom.local.up") as up:
|
|
845
|
+
assert mcp._try_autostart_local() is True
|
|
846
|
+
up.assert_called_once_with(connect=True)
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
# ── version / stale-install self-check ─────────────────────────────────────────
|
|
850
|
+
|
|
851
|
+
def test_version_command_prints_code_version(monkeypatch, capsys):
|
|
852
|
+
import wisdom.__main__ as m
|
|
853
|
+
|
|
854
|
+
monkeypatch.setattr(sys, "argv", ["wisdom", "--version"])
|
|
855
|
+
m.main()
|
|
856
|
+
assert f"wisdomgraph {m._CODE_VERSION}" in capsys.readouterr().out
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
def test_code_version_matches_pyproject():
|
|
860
|
+
import re
|
|
861
|
+
from pathlib import Path
|
|
862
|
+
import wisdom.__main__ as m
|
|
863
|
+
|
|
864
|
+
root = Path(__file__).resolve().parent.parent
|
|
865
|
+
text = (root / "pyproject.toml").read_text(encoding="utf-8")
|
|
866
|
+
match = re.search(r'(?m)^version\s*=\s*"([^"]+)"', text)
|
|
867
|
+
assert match, "version not found in pyproject.toml"
|
|
868
|
+
assert match.group(1) == m._CODE_VERSION, "bump _CODE_VERSION to match pyproject.toml"
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
def test_warn_if_stale_warns_on_version_mismatch(capsys):
|
|
872
|
+
import wisdom.__main__ as m
|
|
873
|
+
|
|
874
|
+
with patch.object(m, "_dist_version", return_value="0.2.0"):
|
|
875
|
+
m._warn_if_stale()
|
|
876
|
+
err = capsys.readouterr().err
|
|
877
|
+
assert "0.2.0" in err
|
|
878
|
+
assert "pip install -U wisdomgraph" in err
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
def test_warn_if_stale_silent_when_matching_or_unknown(capsys):
|
|
882
|
+
import wisdom.__main__ as m
|
|
883
|
+
|
|
884
|
+
with patch.object(m, "_dist_version", return_value=m._CODE_VERSION):
|
|
885
|
+
m._warn_if_stale()
|
|
886
|
+
with patch.object(m, "_dist_version", return_value="unknown"):
|
|
887
|
+
m._warn_if_stale()
|
|
888
|
+
assert capsys.readouterr().err == ""
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
def test_main_skips_stale_check_for_mcp(monkeypatch):
|
|
892
|
+
import wisdom.__main__ as m
|
|
893
|
+
|
|
894
|
+
monkeypatch.setattr(sys, "argv", ["wisdom", "mcp"])
|
|
895
|
+
with patch.object(m, "_warn_if_stale") as warn, \
|
|
896
|
+
patch("wisdom.mcp.run_mcp_server") as run:
|
|
897
|
+
m.main()
|
|
898
|
+
warn.assert_not_called()
|
|
899
|
+
run.assert_called_once()
|
|
@@ -8,6 +8,11 @@ import shutil
|
|
|
8
8
|
import sys
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
|
|
11
|
+
# Baked into the source so it identifies the code actually running, independent
|
|
12
|
+
# of whatever distribution metadata happens to resolve on sys.path. Keep in sync
|
|
13
|
+
# with pyproject.toml (guarded by test_code_version_matches_pyproject).
|
|
14
|
+
_CODE_VERSION = "0.3.3"
|
|
15
|
+
|
|
11
16
|
try:
|
|
12
17
|
from importlib.metadata import version as _pkg_version
|
|
13
18
|
__version__ = _pkg_version("wisdomgraph")
|
|
@@ -15,6 +20,41 @@ except Exception:
|
|
|
15
20
|
__version__ = "unknown"
|
|
16
21
|
|
|
17
22
|
|
|
23
|
+
def _dist_version() -> str:
|
|
24
|
+
"""Version of the installed `wisdomgraph` distribution metadata (may differ
|
|
25
|
+
from the running code if more than one install is on PATH)."""
|
|
26
|
+
try:
|
|
27
|
+
from importlib.metadata import version
|
|
28
|
+
return version("wisdomgraph")
|
|
29
|
+
except Exception:
|
|
30
|
+
return "unknown"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _print_version() -> None:
|
|
34
|
+
print(f"wisdomgraph {_CODE_VERSION}")
|
|
35
|
+
dist = _dist_version()
|
|
36
|
+
if dist not in (_CODE_VERSION, "unknown"):
|
|
37
|
+
print(
|
|
38
|
+
f" note: installed distribution metadata reports {dist} — "
|
|
39
|
+
"more than one wisdomgraph install is on PATH.",
|
|
40
|
+
file=sys.stderr,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _warn_if_stale() -> None:
|
|
45
|
+
"""Warn when the running code and the installed distribution disagree — the
|
|
46
|
+
classic 'wisdom on PATH is an old shim' trap."""
|
|
47
|
+
dist = _dist_version()
|
|
48
|
+
if dist not in (_CODE_VERSION, "unknown"):
|
|
49
|
+
print(
|
|
50
|
+
f"warning: this 'wisdom' runs code v{_CODE_VERSION} but the installed "
|
|
51
|
+
f"wisdomgraph distribution is v{dist} — you likely have more than one "
|
|
52
|
+
"install on PATH.",
|
|
53
|
+
file=sys.stderr,
|
|
54
|
+
)
|
|
55
|
+
print(" Fix: pip install -U wisdomgraph (check with: which -a wisdom)", file=sys.stderr)
|
|
56
|
+
|
|
57
|
+
|
|
18
58
|
# ── Hook / registration strings ──────────────────────────────────────────────
|
|
19
59
|
|
|
20
60
|
_SETTINGS_HOOK = {
|
|
@@ -380,6 +420,15 @@ def main() -> None:
|
|
|
380
420
|
|
|
381
421
|
cmd = sys.argv[1]
|
|
382
422
|
|
|
423
|
+
if cmd in ("--version", "-V", "version"):
|
|
424
|
+
_print_version()
|
|
425
|
+
return
|
|
426
|
+
|
|
427
|
+
# Surface stale-install mismatches, but never on `mcp` — that speaks JSON-RPC
|
|
428
|
+
# over stdio and its stderr is reserved for the host's logs.
|
|
429
|
+
if cmd != "mcp":
|
|
430
|
+
_warn_if_stale()
|
|
431
|
+
|
|
383
432
|
if cmd == "install":
|
|
384
433
|
default_p = "windows" if _platform_mod.system() == "Windows" else "claude"
|
|
385
434
|
chosen = default_p
|
|
@@ -635,6 +684,8 @@ def _print_explain(result: dict) -> None:
|
|
|
635
684
|
def _print_help() -> None:
|
|
636
685
|
print("Usage: wisdom <command>")
|
|
637
686
|
print()
|
|
687
|
+
print(" --version print the running wisdomgraph version")
|
|
688
|
+
print()
|
|
638
689
|
print("Setup:")
|
|
639
690
|
print(" quickstart [--storage local|aura|existing] [--host claude|codex|all|none]")
|
|
640
691
|
print(" doctor check Neo4j, local backend, and MCP host readiness")
|
|
@@ -115,6 +115,43 @@ def _wait_for_port(timeout_s: int = 45) -> bool:
|
|
|
115
115
|
return False
|
|
116
116
|
|
|
117
117
|
|
|
118
|
+
def _probe_cypher(password: str) -> bool:
|
|
119
|
+
"""One-shot: can we run an authenticated `RETURN 1` yet?
|
|
120
|
+
|
|
121
|
+
Neo4j opens the Bolt port several seconds before it accepts
|
|
122
|
+
authenticated queries, so a TCP connect is not proof of readiness.
|
|
123
|
+
"""
|
|
124
|
+
try:
|
|
125
|
+
from neo4j import GraphDatabase
|
|
126
|
+
except ImportError:
|
|
127
|
+
# Driver not installed here; the TCP probe is the best we can do.
|
|
128
|
+
return True
|
|
129
|
+
driver = None
|
|
130
|
+
try:
|
|
131
|
+
driver = GraphDatabase.driver(URI, auth=(USER, password))
|
|
132
|
+
driver.verify_connectivity()
|
|
133
|
+
with driver.session() as session:
|
|
134
|
+
session.run("RETURN 1").consume()
|
|
135
|
+
return True
|
|
136
|
+
except Exception:
|
|
137
|
+
return False
|
|
138
|
+
finally:
|
|
139
|
+
if driver is not None:
|
|
140
|
+
driver.close()
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _wait_until_ready(password: str, timeout_s: int = 90) -> bool:
|
|
144
|
+
"""Wait until Neo4j accepts an authenticated query, not just a TCP socket."""
|
|
145
|
+
if not _wait_for_port(timeout_s=min(timeout_s, 45)):
|
|
146
|
+
return False
|
|
147
|
+
deadline = time.time() + timeout_s
|
|
148
|
+
while time.time() < deadline:
|
|
149
|
+
if _probe_cypher(password):
|
|
150
|
+
return True
|
|
151
|
+
time.sleep(1)
|
|
152
|
+
return False
|
|
153
|
+
|
|
154
|
+
|
|
118
155
|
def up(
|
|
119
156
|
password: str | None = None,
|
|
120
157
|
connect: bool = True,
|
|
@@ -134,21 +171,34 @@ def up(
|
|
|
134
171
|
print("Start Docker Desktop/Engine, then run: wisdom local up", file=sys.stderr)
|
|
135
172
|
sys.exit(1)
|
|
136
173
|
|
|
137
|
-
|
|
174
|
+
running = _container_id(all_containers=False)
|
|
175
|
+
exists = bool(running) or bool(_container_id(all_containers=True))
|
|
176
|
+
|
|
177
|
+
if exists:
|
|
178
|
+
# A container's NEO4J_AUTH is fixed at creation time; a new --password
|
|
179
|
+
# cannot change it, so reuse the saved one and warn on a mismatch.
|
|
180
|
+
saved = _read_or_create_password()
|
|
181
|
+
if password and password != saved:
|
|
182
|
+
print(" note: a local backend already exists — keeping its existing password.", file=sys.stderr)
|
|
183
|
+
print(f" To reset it: wisdom local down && docker rm {CONTAINER_NAME}, then rerun.", file=sys.stderr)
|
|
184
|
+
password = saved
|
|
185
|
+
else:
|
|
186
|
+
password = _resolve_password(password)
|
|
138
187
|
|
|
139
|
-
if
|
|
188
|
+
if running:
|
|
140
189
|
print(f" Local wisdomGraph backend already running ({CONTAINER_NAME})")
|
|
141
190
|
if connect:
|
|
142
191
|
save_connection(URI, USER, password)
|
|
143
192
|
_print_ready(password, selected_image)
|
|
144
193
|
return
|
|
145
194
|
|
|
146
|
-
if
|
|
195
|
+
if exists:
|
|
147
196
|
print(f" Starting existing local backend ({CONTAINER_NAME})...")
|
|
148
197
|
result = _run(["docker", "start", CONTAINER_NAME], capture=True)
|
|
149
198
|
if result.returncode != 0:
|
|
150
199
|
print(result.stderr.strip() or "error: failed to start local backend", file=sys.stderr)
|
|
151
200
|
sys.exit(result.returncode)
|
|
201
|
+
_report_if_not_ready(password)
|
|
152
202
|
if connect:
|
|
153
203
|
save_connection(URI, USER, password)
|
|
154
204
|
_print_ready(password, selected_image)
|
|
@@ -156,10 +206,10 @@ def up(
|
|
|
156
206
|
|
|
157
207
|
_ensure_dirs()
|
|
158
208
|
|
|
159
|
-
print(f" Pulling {selected_image}...")
|
|
160
|
-
result = _run(["docker", "pull", selected_image]
|
|
209
|
+
print(f" Pulling {selected_image} (first run may take a minute)...")
|
|
210
|
+
result = _run(["docker", "pull", selected_image]) # stream progress to the user
|
|
161
211
|
if result.returncode != 0:
|
|
162
|
-
print(
|
|
212
|
+
print(f"error: failed to pull {selected_image}", file=sys.stderr)
|
|
163
213
|
print("Check Docker Hub access/proxy settings, then retry: wisdom local up", file=sys.stderr)
|
|
164
214
|
sys.exit(result.returncode)
|
|
165
215
|
|
|
@@ -169,15 +219,20 @@ def up(
|
|
|
169
219
|
print(result.stderr.strip() or "error: failed to start local backend", file=sys.stderr)
|
|
170
220
|
sys.exit(result.returncode)
|
|
171
221
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
print("Run `wisdom local logs` or `wisdom doctor` if connection fails.", file=sys.stderr)
|
|
222
|
+
print(" Waiting for Neo4j to accept connections...")
|
|
223
|
+
_report_if_not_ready(password)
|
|
175
224
|
|
|
176
225
|
if connect:
|
|
177
226
|
save_connection(URI, USER, password)
|
|
178
227
|
_print_ready(password, selected_image)
|
|
179
228
|
|
|
180
229
|
|
|
230
|
+
def _report_if_not_ready(password: str) -> None:
|
|
231
|
+
if not _wait_until_ready(password):
|
|
232
|
+
print("warning: local backend started, but Neo4j was not ready before timeout.", file=sys.stderr)
|
|
233
|
+
print("Run `wisdom local logs` or `wisdom doctor` if connection fails.", file=sys.stderr)
|
|
234
|
+
|
|
235
|
+
|
|
181
236
|
def down() -> None:
|
|
182
237
|
if not docker_available():
|
|
183
238
|
print("error: Docker is not installed or not on PATH.", file=sys.stderr)
|
|
@@ -325,16 +325,48 @@ _TOOL_DEFS: list[dict] = [
|
|
|
325
325
|
|
|
326
326
|
# ── Handler helpers ───────────────────────────────────────────────────────────
|
|
327
327
|
|
|
328
|
-
|
|
328
|
+
_CONNECT_HELP = (
|
|
329
|
+
"Cannot connect to Neo4j, and a managed local backend could not be started "
|
|
330
|
+
"automatically (Docker not available). Run `wisdom quickstart` to provision a "
|
|
331
|
+
"local backend, or `wisdom connect <uri> --user <u> --password <p>` to point at "
|
|
332
|
+
"an existing Neo4j/DozerDB/Aura instance."
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _try_autostart_local() -> bool:
|
|
337
|
+
"""Best-effort: bring up the managed local backend when Docker is available.
|
|
338
|
+
|
|
339
|
+
Runs silently — stdout is redirected to stderr so `local.up`'s progress output
|
|
340
|
+
never corrupts the MCP stdio (JSON-RPC) stream. Returns True if it started.
|
|
341
|
+
"""
|
|
342
|
+
import contextlib
|
|
343
|
+
|
|
344
|
+
try:
|
|
345
|
+
from . import local
|
|
346
|
+
except Exception:
|
|
347
|
+
return False
|
|
348
|
+
if not local.docker_daemon_available():
|
|
349
|
+
return False
|
|
350
|
+
try:
|
|
351
|
+
with contextlib.redirect_stdout(sys.stderr):
|
|
352
|
+
local.up(connect=True)
|
|
353
|
+
return True
|
|
354
|
+
except SystemExit:
|
|
355
|
+
return False
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def _get_driver(_allow_autostart: bool = True):
|
|
329
359
|
"""Return a live Neo4j driver (or raise RuntimeError with a helpful message)."""
|
|
360
|
+
from .connect import get_driver
|
|
330
361
|
try:
|
|
331
|
-
from .connect import get_driver
|
|
332
362
|
return get_driver()
|
|
333
363
|
except SystemExit as e:
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
364
|
+
if _allow_autostart and _try_autostart_local():
|
|
365
|
+
try:
|
|
366
|
+
return get_driver()
|
|
367
|
+
except SystemExit as e2:
|
|
368
|
+
raise RuntimeError(_CONNECT_HELP) from e2
|
|
369
|
+
raise RuntimeError(_CONNECT_HELP) from e
|
|
338
370
|
|
|
339
371
|
|
|
340
372
|
# ── Tool handlers (pure Python — no mcp types needed) ────────────────────────
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|