memgraph-context-graph 0.5.0__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 (62) hide show
  1. memgraph_context_graph-0.5.0/.gitignore +189 -0
  2. memgraph_context_graph-0.5.0/CONTEXT.md +113 -0
  3. memgraph_context_graph-0.5.0/LICENSE +21 -0
  4. memgraph_context_graph-0.5.0/PKG-INFO +718 -0
  5. memgraph_context_graph-0.5.0/README.md +693 -0
  6. memgraph_context_graph-0.5.0/docs/adr/0001-runtime-adapter-terminology.md +3 -0
  7. memgraph_context_graph-0.5.0/docs/adr/0002-config-file-only-hook-resolution.md +7 -0
  8. memgraph_context_graph-0.5.0/docs/adr/0003-config-path-override.md +26 -0
  9. memgraph_context_graph-0.5.0/docs/adr/0004-user-id-in-session-start-event.md +3 -0
  10. memgraph_context_graph-0.5.0/docs/adr/0005-config-file-covers-llm-key-and-subprocess-env.md +13 -0
  11. memgraph_context_graph-0.5.0/docs/adr/0006-memory-tool-writes-explicit-memory.md +28 -0
  12. memgraph_context_graph-0.5.0/docs/command-hooks.md +303 -0
  13. memgraph_context_graph-0.5.0/docs/research/2026-10-codex-memory.md +218 -0
  14. memgraph_context_graph-0.5.0/pyproject.toml +53 -0
  15. memgraph_context_graph-0.5.0/src/memgraph_context_graph/__init__.py +71 -0
  16. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/__init__.py +0 -0
  17. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/_identity.py +520 -0
  18. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/_opencode_plugin.js +112 -0
  19. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/_spec.py +441 -0
  20. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/antigravity_cli.py +152 -0
  21. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/claude.py +297 -0
  22. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/claude_code.py +216 -0
  23. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/claude_code_memory.py +181 -0
  24. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/codex.py +118 -0
  25. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/codex_memory.py +185 -0
  26. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/copilot_cli.py +236 -0
  27. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/cursor.py +189 -0
  28. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/grok.py +187 -0
  29. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/openai.py +240 -0
  30. memgraph_context_graph-0.5.0/src/memgraph_context_graph/adapters/opencode.py +168 -0
  31. memgraph_context_graph-0.5.0/src/memgraph_context_graph/cli.py +845 -0
  32. memgraph_context_graph-0.5.0/src/memgraph_context_graph/events.py +210 -0
  33. memgraph_context_graph-0.5.0/src/memgraph_context_graph/hooks/__init__.py +1 -0
  34. memgraph_context_graph-0.5.0/src/memgraph_context_graph/hooks/cli.py +184 -0
  35. memgraph_context_graph-0.5.0/src/memgraph_context_graph/hooks/runner.py +311 -0
  36. memgraph_context_graph-0.5.0/src/memgraph_context_graph/hooks/runtime_plugin.py +85 -0
  37. memgraph_context_graph-0.5.0/src/memgraph_context_graph/link.py +50 -0
  38. memgraph_context_graph-0.5.0/src/memgraph_context_graph/mcp_server.py +102 -0
  39. memgraph_context_graph-0.5.0/src/memgraph_context_graph/memory_backend.py +144 -0
  40. memgraph_context_graph-0.5.0/src/memgraph_context_graph/protocols.py +67 -0
  41. memgraph_context_graph-0.5.0/src/memgraph_context_graph/spaces.py +214 -0
  42. memgraph_context_graph-0.5.0/src/memgraph_context_graph/tools.py +130 -0
  43. memgraph_context_graph-0.5.0/tests/__init__.py +0 -0
  44. memgraph_context_graph-0.5.0/tests/test_antigravity_cli_adapter.py +125 -0
  45. memgraph_context_graph-0.5.0/tests/test_claude_code_adapter.py +307 -0
  46. memgraph_context_graph-0.5.0/tests/test_codex_adapter.py +195 -0
  47. memgraph_context_graph-0.5.0/tests/test_config_cli.py +153 -0
  48. memgraph_context_graph-0.5.0/tests/test_context_before_tool.py +81 -0
  49. memgraph_context_graph-0.5.0/tests/test_copilot_cli_adapter.py +169 -0
  50. memgraph_context_graph-0.5.0/tests/test_cursor_adapter.py +102 -0
  51. memgraph_context_graph-0.5.0/tests/test_dev_scripts.py +108 -0
  52. memgraph_context_graph-0.5.0/tests/test_events.py +149 -0
  53. memgraph_context_graph-0.5.0/tests/test_grok_adapter.py +154 -0
  54. memgraph_context_graph-0.5.0/tests/test_hook_cli.py +504 -0
  55. memgraph_context_graph-0.5.0/tests/test_identity.py +258 -0
  56. memgraph_context_graph-0.5.0/tests/test_link.py +291 -0
  57. memgraph_context_graph-0.5.0/tests/test_opencode_adapter.py +197 -0
  58. memgraph_context_graph-0.5.0/tests/test_plugin_hooks.py +31 -0
  59. memgraph_context_graph-0.5.0/tests/test_runner_sessions_graph_connector.py +81 -0
  60. memgraph_context_graph-0.5.0/tests/test_runtime_plugin.py +84 -0
  61. memgraph_context_graph-0.5.0/tests/test_spaces.py +160 -0
  62. memgraph_context_graph-0.5.0/tests/test_tools.py +207 -0
@@ -0,0 +1,189 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Ruff stuff:
171
+ .ruff_cache/
172
+
173
+ # PyPI configuration file
174
+ .pypirc
175
+
176
+
177
+ # VS Code
178
+ .vscode/
179
+
180
+
181
+ # Local agent hook configuration
182
+ /.codex/
183
+ /.claude/settings.local.json
184
+
185
+ # Project specific files
186
+ /enterprise-context/sic-agent/sic-scrapper/output/*
187
+
188
+ # deepeval writes run caches and telemetry here; build artifacts, not source.
189
+ .deepeval/
@@ -0,0 +1,113 @@
1
+ # Memgraph Context Graph
2
+
3
+ Adapter layer for Context Graph components. Normalizes agent SDK + runtime activity into events, routes to graph connectors.
4
+
5
+ ## Language
6
+
7
+ **Memgraph Context Graph**:
8
+ Adapter layer normalizing agent SDK + runtime activity into events, routing to graph connectors.
9
+ _Avoid_: Graph storage, skills graph, memory store
10
+
11
+ **Graph Connector**:
12
+ Integration point, owned by a graph component, deciding which normalized events matter to it + persisting their meaning.
13
+ _Avoid_: Adapter, hook, writer
14
+
15
+ **Agent Development SDK**:
16
+ Framework for building agent apps; integrations usually attach via in-process callbacks/hook objects.
17
+ _Avoid_: Runtime hook, command hook
18
+
19
+ **Runtime Hook**:
20
+ Hook emitted by an agent runtime around an already-running session, often via external command + JSON payload.
21
+ _Avoid_: Agent development SDK
22
+
23
+ **Runtime Adapter**:
24
+ Integration point translating one SDK/runtime-hook shape into shared event protocol.
25
+ _Avoid_: Graph connector, storage adapter
26
+
27
+ **Runtime Plugin**:
28
+ Host-specific distribution package installing runtime hooks, skills, commands, setup helpers, other host-native integration files.
29
+ _Avoid_: Graph component, graph connector, storage layer
30
+
31
+ **Codex Plugin**:
32
+ Runtime Plugin for OpenAI Codex; wires Codex lifecycle hooks to an Memgraph Context Graph runtime adapter entrypoint.
33
+ _Avoid_: Codex graph, skills graph plugin
34
+
35
+ **Claude Code Plugin**:
36
+ Runtime Plugin for Claude Code; wires Claude Code lifecycle hooks to an Memgraph Context Graph runtime adapter entrypoint.
37
+ _Avoid_: Claude graph, skills graph plugin
38
+
39
+ **Event Protocol**:
40
+ Runtime-agnostic set of agent activity events, emitted by runtime adapters, consumed by graph connectors.
41
+ _Avoid_: Graph event, graph protocol, hook payload, callback data
42
+
43
+ **Agent Session**:
44
+ Runtime-side unit of agent activity grouping related events under shared session identifier.
45
+ _Avoid_: Session node
46
+
47
+ **Turn End**:
48
+ Agent finished one turn (one prompt's work) inside a still-open **Agent Session**. Distinct from session end: most runtimes fire a stop hook after every turn, and several (Codex, Antigravity, `opencode run`) fire nothing at session end. Graph Connectors mark the session for later reconciliation on a Turn End but only start it on session end.
49
+ _Avoid_: Stop (a runtime's hook name, not a protocol term), session end
50
+
51
+ **Hook Configuration**:
52
+ Persistent TOML file supplying identity + connection settings to hook subprocesses. Default path `~/.config/context-graph/config.toml`; `CONTEXT_GRAPH_CONFIG` may select another file. At hook runtime, config values come only from selected file. Env var selects file; never supplies a value from it.
53
+ _Avoid_: env config, runtime config, shell config
54
+
55
+ **Edition**:
56
+ Which multi-user model the **Hook Configuration** selects, by its top-level `edition` key. **Community** (the default): one user, one Memgraph database. **Enterprise**: many users on a shared Memgraph, isolation enforced by Memgraph Enterprise access control, implemented by the separate `context-graph-spaces` package. Chosen explicitly, never detected from the server's licence (map #501).
57
+ _Avoid_: tier, plan, licence (commercial terms, not behaviour)
58
+
59
+ **Space**:
60
+ A place memory lives. Each user has one **Personal Space**, where hooks write all their activity. Enterprise adds **Shared Spaces** that a set of members can read. A space is one Memgraph database: Memgraph can't query across databases, so reading several spaces means one query per space.
61
+ _Avoid_: tenant (admin vocabulary), workspace, team (a team is just one kind of Shared Space)
62
+
63
+ **Space Resolver**:
64
+ `SpaceResolver` (`spaces.py`). The one place a component asks who the user is, which space to write to (`personal()`), and which spaces to read (`readable()`). `spaces_for(config)` returns the configured **Edition**'s resolver. Components never read `[identity]` or `[memgraph]` themselves.
65
+ _Avoid_: reading `HookConfig.user_id` / `memgraph_*` directly
66
+
67
+ **Runtime Registration**:
68
+ Python object implementing `RuntimeCLIPlugin`. Package publishes it via `memgraph_context_graph.runtimes` entry-point group. CLI resolves runtime name through it to find adapter, hook response, hook config, optional initializer.
69
+
70
+ Not a **Runtime Plugin**: plugin installs host-facing files; registration lets Memgraph Context Graph discover runtime support via `importlib.metadata.entry_points()`. Adding one needs no central registry change.
71
+ _Avoid_: Runtime Plugin (already means distribution package), Runtime Adapter (a Runtime Registration *references* one via `adapter_class`, isn't one)
72
+
73
+ **Tool Registration**:
74
+ Object implementing `Tool` (`tools.py`): a name, a description the model reads, an input schema, the connector whose graph it reads, an optional session-start hint, and `call(arguments, config)`. A graph component publishes it via the `memgraph_context_graph.tools` entry-point group; `memgraph-context-graph mcp` serves every registered tool, and the CLI runs one by name. Identity + connection come from the **Space Resolver** over **Hook Configuration**, never from tool arguments.
75
+ _Avoid_: MCP tool (the protocol it is served over, not the thing), Graph Connector (writes events; a tool reads)
76
+
77
+ ## Relationships
78
+
79
+ - **Memgraph Context Graph** belongs to broader **Context Graph** family.
80
+ - **Memgraph Context Graph** routes events to graph connectors owned by graph components.
81
+ - **Graph Connector** consumes normalized events emitted by **Memgraph Context Graph**.
82
+ - **Agent Development SDK** integration + **Runtime Hook** integration both use a **Runtime Adapter** to emit same event protocol.
83
+ - **Runtime Plugin** = deployment surface for runtime hooks/setup helpers; not a graph component.
84
+ - **Codex Plugin** installs Codex hook wiring invoking the Codex runtime adapter command.
85
+ - **Claude Code Plugin** installs Claude Code hook wiring invoking the Claude Code runtime adapter command.
86
+ - **Event Protocol** carries agent activity, not graph semantics.
87
+ - **Agent Session** may be persisted as a session node by a graph component; **Event Protocol** only carries the session identifier.
88
+ - Tool/message events carry `agent_name` when runtime identifies a subagent. Memgraph Context Graph only transports this id; Graph Connectors decide how to use it. Codex adapter doesn't yet handle subagent lifecycle/ids ([#275](https://github.com/memgraph/ai-toolkit/issues/275)).
89
+ - Runtime Plugin's generated command calls `hook run <name>`. CLI resolves name via Runtime Registration; plugin never names an adapter class directly.
90
+ - Built-in Runtime Registrations: `codex`, `claude-code`, `copilot-cli`, `cursor`, `opencode`, `antigravity-cli`, and `grok`. Other packages may publish more.
91
+
92
+ ## Example dialogue
93
+
94
+ > **Dev:** "Should Memgraph Context Graph write the skill usage edge?"
95
+ > **Domain expert:** "No. Memgraph Context Graph emits the tool event; Skills Graph decides whether that event represents skill usage."
96
+
97
+ > **Dev:** "Are OpenAI Agents SDK and Codex hooks the same kind of integration?"
98
+ > **Domain expert:** "No. OpenAI Agents SDK is for agent development; Codex hooks are runtime hooks. Both become normalized events before graph connectors see them."
99
+
100
+ > **Dev:** "Should the Codex plugin know how to write skill usage?"
101
+ > **Domain expert:** "No. Plugin installs hook wiring. Codex runtime adapter emits events. Skills Graph decides if those events mean skill usage."
102
+
103
+ ## Flagged ambiguities
104
+
105
+ - "graph" = umbrella **Context Graph** family or specific component? Resolved: **Memgraph Context Graph** = adapter layer only, never persistence.
106
+ - "connector" can sound like generic transport plumbing. Resolved: **Graph Connector** owns graph-specific event interpretation.
107
+ - "adapter" can mean SDK integrations or runtime hooks. Resolved: **Runtime Adapter** = anything translating agent activity into shared event protocol.
108
+ - "SDK adapter" too narrow: Codex command hooks are runtime hooks, not SDK callbacks. Resolved: code/docs use **Runtime Adapter**.
109
+ - "event" shouldn't carry graph nomenclature. Resolved: graph meaning assigned by **Graph Connectors**, not **Event Protocol**.
110
+ - "Session" = activity or graph state? Use **Agent Session** for activity, "session node" for persisted state.
111
+ - "Plugin" can sound like a graph extension. Use **Runtime Plugin** for host-specific distribution; Graph Connectors own graph interpretation.
112
+ - Entry-point discovery = **Runtime Registration**, not a runtime/CLI plugin ([#269](https://github.com/memgraph/ai-toolkit/issues/269)).
113
+ - Code hasn't fully caught up to **Runtime Adapter** terminology: Event Protocol's `source_sdk` field (`events.py`, set by all 4 adapters, read by Actions Graph's connector) still names the rejected term (ADR 0001). Rename to e.g. `source_adapter` tracked, not done.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Memgraph
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.