wisdomgraph 0.3.1__tar.gz → 0.3.2__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.
Files changed (38) hide show
  1. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/PKG-INFO +1 -1
  2. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/pyproject.toml +1 -1
  3. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/tests/test_mcp.py +84 -3
  4. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/local.py +64 -9
  5. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/mcp.py +38 -6
  6. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdomgraph.egg-info/PKG-INFO +1 -1
  7. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/LICENSE +0 -0
  8. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/README.md +0 -0
  9. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/setup.cfg +0 -0
  10. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/tests/test_cache.py +0 -0
  11. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/tests/test_classify.py +0 -0
  12. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/tests/test_detect.py +0 -0
  13. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/tests/test_ingest.py +0 -0
  14. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/tests/test_reflect.py +0 -0
  15. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/tests/test_security.py +0 -0
  16. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/tests/test_validate.py +0 -0
  17. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/__init__.py +0 -0
  18. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/__main__.py +0 -0
  19. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/cache.py +0 -0
  20. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/classify.py +0 -0
  21. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/connect.py +0 -0
  22. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/detect.py +0 -0
  23. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/docker.py +0 -0
  24. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/export.py +0 -0
  25. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/ingest.py +0 -0
  26. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/merge.py +0 -0
  27. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/reflect.py +0 -0
  28. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/report.py +0 -0
  29. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/security.py +0 -0
  30. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/skill-claw.md +0 -0
  31. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/skill.md +0 -0
  32. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/traverse.py +0 -0
  33. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdom/validate.py +0 -0
  34. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdomgraph.egg-info/SOURCES.txt +0 -0
  35. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdomgraph.egg-info/dependency_links.txt +0 -0
  36. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdomgraph.egg-info/entry_points.txt +0 -0
  37. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdomgraph.egg-info/requires.txt +0 -0
  38. {wisdomgraph-0.3.1 → wisdomgraph-0.3.2}/wisdomgraph.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: wisdomgraph
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Graph-native persistent cognition for AI agents using Neo4j, DIKW, and MCP
5
5
  License: MIT
6
6
  Project-URL: Homepage, https://github.com/cklam12345/wisdomGraph
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "wisdomgraph"
7
- version = "0.3.1"
7
+ version = "0.3.2"
8
8
  description = "Graph-native persistent cognition for AI agents using Neo4j, DIKW, and MCP"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -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._wait_for_port", return_value=True), \
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
- monkeypatch.setattr(local, "PASSWORD_PATH", tmp_path / "local-password")
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
- save.assert_called_once_with(local.URI, local.USER, "test-password")
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,53 @@ 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)
@@ -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
- password = _resolve_password(password)
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 _container_id(all_containers=False):
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 _container_id(all_containers=True):
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], capture=True)
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(result.stderr.strip() or f"error: failed to pull {selected_image}", file=sys.stderr)
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
- if not _wait_for_port():
173
- print("warning: local backend started, but Bolt was not reachable before timeout.", file=sys.stderr)
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
- def _get_driver():
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
- raise RuntimeError(
335
- "Cannot connect to Neo4j. Make sure your configured Neo4j or DozerDB instance "
336
- "is running and credentials are configured (`wisdom connect`)."
337
- ) from e
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) ────────────────────────
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: wisdomgraph
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Graph-native persistent cognition for AI agents using Neo4j, DIKW, and MCP
5
5
  License: MIT
6
6
  Project-URL: Homepage, https://github.com/cklam12345/wisdomGraph
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes