knowledge-worker 0.6.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 (37) hide show
  1. knowledge_worker-0.6.0/LICENSE +21 -0
  2. knowledge_worker-0.6.0/PKG-INFO +365 -0
  3. knowledge_worker-0.6.0/README.md +317 -0
  4. knowledge_worker-0.6.0/knowledge_worker.egg-info/PKG-INFO +365 -0
  5. knowledge_worker-0.6.0/knowledge_worker.egg-info/SOURCES.txt +35 -0
  6. knowledge_worker-0.6.0/knowledge_worker.egg-info/dependency_links.txt +1 -0
  7. knowledge_worker-0.6.0/knowledge_worker.egg-info/entry_points.txt +3 -0
  8. knowledge_worker-0.6.0/knowledge_worker.egg-info/requires.txt +32 -0
  9. knowledge_worker-0.6.0/knowledge_worker.egg-info/top_level.txt +2 -0
  10. knowledge_worker-0.6.0/mygraph/__init__.py +23 -0
  11. knowledge_worker-0.6.0/mygraph/anthropic_client.py +199 -0
  12. knowledge_worker-0.6.0/mygraph/audit.py +137 -0
  13. knowledge_worker-0.6.0/mygraph/check.py +273 -0
  14. knowledge_worker-0.6.0/mygraph/discover.py +654 -0
  15. knowledge_worker-0.6.0/mygraph/eval_log.py +36 -0
  16. knowledge_worker-0.6.0/mygraph/export_context.py +124 -0
  17. knowledge_worker-0.6.0/mygraph/extractor.py +243 -0
  18. knowledge_worker-0.6.0/mygraph/extractor_openai.py +165 -0
  19. knowledge_worker-0.6.0/mygraph/ingest.py +170 -0
  20. knowledge_worker-0.6.0/mygraph/memory_audit.py +1094 -0
  21. knowledge_worker-0.6.0/mygraph/merge.py +133 -0
  22. knowledge_worker-0.6.0/mygraph/mygraph.py +773 -0
  23. knowledge_worker-0.6.0/mygraph/owl_io.py +202 -0
  24. knowledge_worker-0.6.0/mygraph/review.py +151 -0
  25. knowledge_worker-0.6.0/mygraph/validator.py +149 -0
  26. knowledge_worker-0.6.0/mygraph/viz.py +409 -0
  27. knowledge_worker-0.6.0/ollama_proxy/eval_compare.py +185 -0
  28. knowledge_worker-0.6.0/ollama_proxy/extractor_adapter.py +168 -0
  29. knowledge_worker-0.6.0/ollama_proxy/proxy.py +143 -0
  30. knowledge_worker-0.6.0/ollama_proxy/server.py +194 -0
  31. knowledge_worker-0.6.0/pyproject.toml +57 -0
  32. knowledge_worker-0.6.0/setup.cfg +4 -0
  33. knowledge_worker-0.6.0/tests/test_anthropic_client.py +111 -0
  34. knowledge_worker-0.6.0/tests/test_benchmarks.py +205 -0
  35. knowledge_worker-0.6.0/tests/test_cli_smoke.py +144 -0
  36. knowledge_worker-0.6.0/tests/test_discover.py +101 -0
  37. knowledge_worker-0.6.0/tests/test_extractor_provenance.py +97 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rahul Rangarao
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.
@@ -0,0 +1,365 @@
1
+ Metadata-Version: 2.4
2
+ Name: knowledge-worker
3
+ Version: 0.6.0
4
+ Summary: Provenance-backed personal knowledge graph for local AI workflows
5
+ Author-email: Rahul Rangarao <rahulmranga@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/rahulmranga/knowledge-worker
8
+ Project-URL: Repository, https://github.com/rahulmranga/knowledge-worker
9
+ Project-URL: Issues, https://github.com/rahulmranga/knowledge-worker/issues
10
+ Keywords: knowledge-graph,llm-memory,local-first,provenance,personal-knowledge-management,ai,claude
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Provides-Extra: rdf
23
+ Requires-Dist: rdflib>=7.0.0; extra == "rdf"
24
+ Provides-Extra: anthropic
25
+ Requires-Dist: anthropic>=0.39.0; extra == "anthropic"
26
+ Requires-Dist: rdflib>=7.0.0; extra == "anthropic"
27
+ Provides-Extra: openai
28
+ Requires-Dist: openai>=1.68.0; extra == "openai"
29
+ Requires-Dist: rdflib>=7.0.0; extra == "openai"
30
+ Provides-Extra: llm
31
+ Requires-Dist: anthropic>=0.39.0; extra == "llm"
32
+ Requires-Dist: openai>=1.68.0; extra == "llm"
33
+ Requires-Dist: rdflib>=7.0.0; extra == "llm"
34
+ Provides-Extra: ollama
35
+ Requires-Dist: httpx>=0.27.0; extra == "ollama"
36
+ Requires-Dist: rdflib>=7.0.0; extra == "ollama"
37
+ Provides-Extra: proxy
38
+ Requires-Dist: fastapi>=0.110.0; extra == "proxy"
39
+ Requires-Dist: httpx>=0.27.0; extra == "proxy"
40
+ Requires-Dist: mcp[cli]>=1.0.0; extra == "proxy"
41
+ Requires-Dist: uvicorn[standard]>=0.27.0; extra == "proxy"
42
+ Provides-Extra: all
43
+ Requires-Dist: anthropic>=0.39.0; extra == "all"
44
+ Requires-Dist: openai>=1.68.0; extra == "all"
45
+ Requires-Dist: httpx>=0.27.0; extra == "all"
46
+ Requires-Dist: rdflib>=7.0.0; extra == "all"
47
+ Dynamic: license-file
48
+
49
+ # knowledge-worker
50
+
51
+ [![PyPI](https://img.shields.io/pypi/v/knowledge-worker.svg)](https://pypi.org/project/knowledge-worker/)
52
+
53
+ **A personal knowledge graph that survives between AI conversations.**
54
+ User-centered (not conversation-centered). Provenance-or-bust. Built on boring infrastructure.
55
+
56
+ > *Your AI is only as smart as what it remembers about you.*
57
+
58
+ <p align="center">
59
+ <img src="docs/assets/knowledge-worker-demo.gif" alt="knowledge-worker graph visualizer demo" width="900">
60
+ </p>
61
+
62
+ `knowledge-worker` is a local-first personal knowledge graph for carrying context across AI sessions. It turns notes into reviewable concepts, decisions, goals, and relationships, keeps source excerpts attached, and exports compact context you can paste into Claude, GPT, Ollama, or any other LLM workflow.
63
+
64
+ Your private graph stays on your machine, enabling you to preserve the thread of your own reasoning across AI sessions.
65
+
66
+ ## Why
67
+
68
+ AI conversations usually start from zero. You clarify a decision, name a constraint, sketch a goal, and then the next session forgets it. RAG can be heavy, full-note prompts are noisy, and most note apps do not plug cleanly into chat workflows.
69
+
70
+ Stop dumping context. Build memory. `knowledge-worker` turns chats, notes, decisions, and sources into a local provenance-backed knowledge graph, then uses graph analytics to show what matters, what connects, what is weak, and what context an AI should see.
71
+
72
+ `knowledge-worker` keeps the useful parts: cited claims, explicit relationships, human review, and a small context snapshot when you need continuity.
73
+
74
+ ## How It Compares
75
+
76
+ `knowledge-worker` is personal AI memory with source-backed claims, not a team
77
+ chat-to-wiki system. It keeps reasoning local, reviewable, and tied to literal
78
+ provenance excerpts before claims become durable graph knowledge.
79
+
80
+ See [Competitive Analysis](docs/COMPETITIVE_ANALYSIS.md) for the category
81
+ matrix and [Benchmarks](docs/BENCHMARKS.md) for the offline demo-graph checks.
82
+
83
+ ## What It Does
84
+
85
+ - Ingests markdown notes into candidate graph nodes and edges.
86
+ - Requires provenance excerpts before claims become durable memory.
87
+ - Lets you review, accept, reject, or edit LLM proposals before merge.
88
+ - Searches by term, lists nodes by type, and finds paths between ideas.
89
+ - Exports an LLM-ready context snapshot for a fresh chat session.
90
+ - Audits memory shape with PageRank, betweenness, k-core, communities, weak
91
+ claims, and provenance coverage.
92
+ - Generates an offline HTML graph viewer for exploration and demos.
93
+
94
+ ## Design Principles
95
+
96
+ **Provenance first.** Every durable claim points back to a source document and literal excerpt.
97
+
98
+ **Local first.** The graph is a file on your machine. No cloud sync, accounts, or telemetry.
99
+
100
+ **Review before merge.** The LLM proposes. You decide. Deterministic validation runs before anything enters the graph.
101
+
102
+ **Boring persistence.** Plain JSON until it becomes the limiting factor. The schema stays stable across storage backends.
103
+
104
+ ## Quick Start
105
+
106
+ Requirements: Python 3.10+ on macOS, Linux, or Windows.
107
+
108
+ ### Install from PyPI
109
+
110
+ The core CLI has no runtime dependencies beyond the standard library. Optional
111
+ extras pull in LLM backends and RDF export only when you need them:
112
+
113
+ ```bash
114
+ python -m pip install knowledge-worker # core CLI, stdlib only (mykg / mygraph)
115
+ python -m pip install "knowledge-worker[rdf]" # + Turtle/RDF export (rdflib)
116
+ python -m pip install "knowledge-worker[anthropic]" # + Claude-backed ingest
117
+ python -m pip install "knowledge-worker[openai]" # + OpenAI-backed ingest
118
+ python -m pip install "knowledge-worker[ollama]" # + local Ollama ingest
119
+ python -m pip install "knowledge-worker[all]" # all ingest backends + RDF
120
+ ```
121
+
122
+ Verify the install (no clone needed — `seed` generates its own demo graph):
123
+
124
+ ```bash
125
+ mykg --help
126
+ MYGRAPH_PATH=/tmp/knowledge-worker-demo.json mykg seed
127
+ MYGRAPH_PATH=/tmp/knowledge-worker-demo.json mykg summary
128
+ ```
129
+
130
+ Using a virtual environment avoids Homebrew/system Python's externally-managed
131
+ install errors:
132
+
133
+ ```bash
134
+ python3 -m venv .venv
135
+ source .venv/bin/activate
136
+ python -m pip install knowledge-worker
137
+ ```
138
+
139
+ ### Run from a clone (no install)
140
+
141
+ The core demo CLI uses only the standard library, so you can run it straight
142
+ from a checkout without installing anything:
143
+
144
+ ```bash
145
+ git clone https://github.com/rahulmranga/knowledge-worker
146
+ cd knowledge-worker
147
+
148
+ # Run the public demo graph, no API key needed
149
+ MYGRAPH_PATH=examples/demo_graph.json python3 mygraph/mygraph.py summary
150
+ MYGRAPH_PATH=examples/demo_graph.json python3 mygraph/mygraph.py query "provenance"
151
+
152
+ # Generate an LLM-ready context snapshot
153
+ MYGRAPH_PATH=examples/demo_graph.json python3 mygraph/mygraph.py context
154
+
155
+ # Audit memory structure and proof coverage
156
+ MYGRAPH_PATH=examples/demo_graph.json python3 mygraph/mygraph.py audit --out /tmp/analytics.json --html /tmp/memory_audit.html
157
+
158
+ # Visualize the graph as a self-contained HTML file
159
+ python3 mygraph/mygraph.py viz --graph examples/demo_graph.json --out /tmp/demo.html
160
+ ```
161
+
162
+ For the shorter `mykg` command from a clone, install it editable inside a
163
+ virtual environment:
164
+
165
+ ```bash
166
+ python3 -m venv .venv
167
+ source .venv/bin/activate
168
+ python -m pip install -e .
169
+ MYGRAPH_PATH=examples/demo_graph.json mykg query provenance
170
+ ```
171
+
172
+ On Windows PowerShell:
173
+
174
+ ```powershell
175
+ py -3 -m venv .venv
176
+ .\.venv\Scripts\Activate.ps1
177
+ python -m pip install knowledge-worker
178
+
179
+ $env:MYGRAPH_PATH = "$env:TEMP\knowledge-worker-demo.json"
180
+ mykg seed
181
+ mykg summary
182
+ ```
183
+
184
+ From a clone, install editable instead:
185
+
186
+ ```powershell
187
+ python -m pip install -e .
188
+
189
+ $env:MYGRAPH_PATH = "examples\demo_graph.json"
190
+ mykg query provenance
191
+ mykg audit --out "$env:TEMP\analytics.json" --html "$env:TEMP\memory_audit.html"
192
+ ```
193
+
194
+ If PowerShell blocks activation scripts, run this for the current terminal
195
+ session and activate again:
196
+
197
+ ```powershell
198
+ Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
199
+ ```
200
+
201
+
202
+ ## Commands
203
+
204
+ | Command | What it does |
205
+ |---|---|
206
+ | `seed` | Populate a fictional demo graph |
207
+ | `summary` | Show node and edge counts by type |
208
+ | `query <term>` | Search nodes, neighbors, and provenance |
209
+ | `list <type>` | List nodes of a given type |
210
+ | `path <a> <b>` | Find the shortest path between two nodes |
211
+ | `ingest <file.md>` | Extract, validate, review, merge, and eval candidates |
212
+ | `check --provenance` | Flag nodes with missing source citations |
213
+ | `export --ttl` | Emit Turtle/RDF |
214
+ | `context` | Print a compact LLM-ready context snapshot |
215
+ | `viz` | Generate an offline single-file HTML viewer |
216
+ | `audit` | Emit graph analytics, directed idea-flow queues, and optional Memory Audit HTML |
217
+ | `discover` | Propose derived edges and second-order insights (read-only, promotion queue) |
218
+ | `state "<entry>"` | Append a mood/state sidecar entry |
219
+ | `dump` | Print the raw graph JSON |
220
+ | `reset` | Delete the active graph file |
221
+
222
+
223
+ ## Use Your Own Notes
224
+
225
+ You can ingest your notes with or without an API key.
226
+
227
+ ### Claude or Codex App, No API Key
228
+
229
+ If you are already working with Claude, Codex, or ChatGPT in an app session, you do **not** need an API key. Ask the assistant to produce a `*.candidates.json` file that follows the schema in `mygraph/extractor.py`, then let the local CLI validate, review, and merge it. In Claude Code, the bundled [`/ingest-notes`](.claude/skills/ingest-notes/SKILL.md) skill runs this flow for you:
230
+
231
+ ```bash
232
+ python3 -m venv .venv
233
+ source .venv/bin/activate
234
+ python -m pip install -e .
235
+
236
+ mykg ingest path/to/your/notes.md --candidates-file path/to/your/notes.candidates.json
237
+ ```
238
+
239
+ The app subscription helps you create the candidates file. The repo still keeps graph validation and merge local.
240
+
241
+ ### Automated API-Backed Ingest
242
+
243
+ If you want the CLI to call an LLM directly, use a provider API key or local Ollama.
244
+
245
+ For Anthropic API:
246
+
247
+ ```bash
248
+ python3 -m venv .venv
249
+ source .venv/bin/activate
250
+ python -m pip install -e ".[anthropic]"
251
+ export ANTHROPIC_API_KEY=...
252
+
253
+ mykg ingest path/to/your/notes.md
254
+ ```
255
+
256
+ The Claude backend also auto-detects Anthropic-compatible provider env:
257
+
258
+ - Anthropic API: `ANTHROPIC_API_KEY` or `ANTHROPIC_AUTH_TOKEN`
259
+ - Foundry: `ANTHROPIC_FOUNDRY_API_KEY` plus `ANTHROPIC_FOUNDRY_RESOURCE` or `ANTHROPIC_FOUNDRY_BASE_URL`
260
+ - Bedrock: `AWS_BEARER_TOKEN_BEDROCK`, or AWS credentials plus `AWS_REGION`/`AWS_DEFAULT_REGION`
261
+
262
+ For OpenAI API:
263
+
264
+ ```bash
265
+ python3 -m venv .venv
266
+ source .venv/bin/activate
267
+ python -m pip install -e ".[openai]"
268
+ export OPENAI_API_KEY=...
269
+
270
+ mykg ingest path/to/your/notes.md --backend openai --model gpt-5.2
271
+ ```
272
+ ## Graph Workflow
273
+
274
+ The public repo ships code, docs, and a fictional demo graph. Your real graph should live outside the repo or in the ignored default path, then be loaded explicitly:
275
+
276
+ ```bash
277
+ MYGRAPH_PATH=~/my-private-graph/mygraph.json mykg summary
278
+ MYGRAPH_PATH=~/my-private-graph/mygraph.json mykg query "architecture"
279
+ MYGRAPH_PATH=~/my-private-graph/mygraph.json mykg context
280
+ ```
281
+
282
+ Your private `mygraph.json`, generated private viewers, TTL exports, eval logs, state logs, and local env files are ignored by default.
283
+
284
+
285
+ ## Memory Audit
286
+
287
+ `mykg audit` is a read-only layer over the graph. It ranks important concepts
288
+ with PageRank, bridge ideas with betweenness, structural strength with k-core,
289
+ communities with deterministic graph splitting, and weak claims from confidence
290
+ and provenance gaps. It also includes directed idea-flow queues:
291
+ `idea_attractors` for concepts that many edges point into, `idea_generators`
292
+ for ideas that branch outward, and a `weak_claim_queue` that asks for human
293
+ review actions instead of auto-promoting conclusions.
294
+
295
+ ```bash
296
+ MYGRAPH_PATH=examples/demo_graph.json mykg audit \
297
+ --out /tmp/analytics.json \
298
+ --html /tmp/memory_audit.html
299
+ ```
300
+
301
+ The generated HTML puts ranked panels and legwork queues first, with the graph
302
+ canvas second. This keeps the feature focused on memory governance instead of
303
+ making the raw graph view the product.
304
+
305
+ ## Discovery Layer
306
+
307
+ Where `audit` ranks what the graph already says, `mykg discover` infers what it
308
+ implies but does not yet say — and turns every inference into a reviewable
309
+ proposal:
310
+
311
+ - **Staleness radar**: important nodes whose evidence trail has gone cold,
312
+ scored by importance × days since the graph last touched them.
313
+ - **Co-mention candidates**: pairs that recur together across multiple sources
314
+ but were never linked (`CO_MENTIONED_WITH`).
315
+ - **Goal-alignment candidates**: ideas and decisions structurally entangled
316
+ with a goal they have no contribution path to (`SERVES_CANDIDATE`).
317
+ - **Link prediction**: Adamic-Adar over the semantic graph (`RELATES_TO`).
318
+ - **Question debt**: open questions ranked by age, centrality, and missing
319
+ evidence; answered questions are detected via decision `ABOUT` edges.
320
+ - **Corroboration**: claims that hang on a single source (`SINGLE_SOURCE`).
321
+ - **Bridge finder**: cross-community connectors that remain after removing
322
+ dominant hub "spines" that mask real bridges (`BRIDGES`).
323
+ - **Tension detector**: claims that are both supported and challenged, and
324
+ goal contributions that inherit a challenge to the goal (`TENSION_WITH`).
325
+
326
+ ```bash
327
+ MYGRAPH_PATH=examples/demo_graph.json mykg discover \
328
+ --out /tmp/discovery.json \
329
+ --candidates /tmp/discovery.candidates.json
330
+ ```
331
+
332
+ Discover never mutates the graph. Derived edges land in a candidates file — a
333
+ promotion queue for human review. AI proposes, provenance verifies, the owner
334
+ promotes. Committed sample output: [`examples/demo_discovery.json`](examples/demo_discovery.json).
335
+
336
+ ## Local LLM Support
337
+
338
+ The `ollama_proxy/` package adds three local-model surfaces:
339
+
340
+ - `server.py`: MCP wrapper for Claude/Cowork-style tool use.
341
+ - `proxy.py`: Ollama-compatible logging passthrough for HTTP clients.
342
+ - `extractor_adapter.py`: drop-in extraction backend for `mykg ingest --backend ollama`.
343
+
344
+ See [ollama_proxy/README.md](ollama_proxy/README.md) for setup.
345
+
346
+
347
+ ## Repository Layout
348
+
349
+ ```text
350
+ mygraph/ Core CLI and pipeline modules
351
+ examples/ Fictional demo graph, TTL, and HTML viewer
352
+ docs/ Roadmap and public assets
353
+ ollama_proxy/ Adapter, MCP server, and proxy for local Ollama workflows
354
+ tests/ CLI smoke tests
355
+ SPEC.md Graph model specification
356
+ DESIGN.md Pipeline design notes
357
+ ```
358
+
359
+ ## Contributing
360
+
361
+ See [CONTRIBUTING.md](CONTRIBUTING.md). The core graph model is intentionally minimal; contributions that preserve that shape are preferred.
362
+
363
+ ## License
364
+
365
+ MIT