cortex-identity 6.4.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 (67) hide show
  1. cortex_identity-6.4.0/LICENSE +21 -0
  2. cortex_identity-6.4.0/MANIFEST.in +3 -0
  3. cortex_identity-6.4.0/PKG-INFO +617 -0
  4. cortex_identity-6.4.0/README.md +586 -0
  5. cortex_identity-6.4.0/cortex/__init__.py +3 -0
  6. cortex_identity-6.4.0/cortex/__main__.py +4 -0
  7. cortex_identity-6.4.0/cortex/_hook.py +25 -0
  8. cortex_identity-6.4.0/cortex/adapters.py +281 -0
  9. cortex_identity-6.4.0/cortex/centrality.py +158 -0
  10. cortex_identity-6.4.0/cortex/cli.py +1633 -0
  11. cortex_identity-6.4.0/cortex/coding.py +868 -0
  12. cortex_identity-6.4.0/cortex/compat.py +255 -0
  13. cortex_identity-6.4.0/cortex/context.py +302 -0
  14. cortex_identity-6.4.0/cortex/continuous.py +384 -0
  15. cortex_identity-6.4.0/cortex/contradictions.py +243 -0
  16. cortex_identity-6.4.0/cortex/cooccurrence.py +238 -0
  17. cortex_identity-6.4.0/cortex/dashboard/__init__.py +1 -0
  18. cortex_identity-6.4.0/cortex/dashboard/server.py +328 -0
  19. cortex_identity-6.4.0/cortex/dedup.py +145 -0
  20. cortex_identity-6.4.0/cortex/edge_extraction.py +221 -0
  21. cortex_identity-6.4.0/cortex/extract_memory.py +1438 -0
  22. cortex_identity-6.4.0/cortex/graph.py +569 -0
  23. cortex_identity-6.4.0/cortex/hooks.py +397 -0
  24. cortex_identity-6.4.0/cortex/import_memory.py +1006 -0
  25. cortex_identity-6.4.0/cortex/intelligence.py +238 -0
  26. cortex_identity-6.4.0/cortex/query.py +328 -0
  27. cortex_identity-6.4.0/cortex/sync/__init__.py +1 -0
  28. cortex_identity-6.4.0/cortex/sync/monitor.py +206 -0
  29. cortex_identity-6.4.0/cortex/sync/scheduler.py +185 -0
  30. cortex_identity-6.4.0/cortex/temporal.py +183 -0
  31. cortex_identity-6.4.0/cortex/timeline.py +192 -0
  32. cortex_identity-6.4.0/cortex/upai/__init__.py +5 -0
  33. cortex_identity-6.4.0/cortex/upai/disclosure.py +149 -0
  34. cortex_identity-6.4.0/cortex/upai/identity.py +256 -0
  35. cortex_identity-6.4.0/cortex/upai/versioning.py +222 -0
  36. cortex_identity-6.4.0/cortex/viz/__init__.py +1 -0
  37. cortex_identity-6.4.0/cortex/viz/layout.py +284 -0
  38. cortex_identity-6.4.0/cortex/viz/renderer.py +326 -0
  39. cortex_identity-6.4.0/cortex_identity.egg-info/PKG-INFO +617 -0
  40. cortex_identity-6.4.0/cortex_identity.egg-info/SOURCES.txt +65 -0
  41. cortex_identity-6.4.0/cortex_identity.egg-info/dependency_links.txt +1 -0
  42. cortex_identity-6.4.0/cortex_identity.egg-info/entry_points.txt +3 -0
  43. cortex_identity-6.4.0/cortex_identity.egg-info/requires.txt +13 -0
  44. cortex_identity-6.4.0/cortex_identity.egg-info/top_level.txt +1 -0
  45. cortex_identity-6.4.0/pyproject.toml +44 -0
  46. cortex_identity-6.4.0/setup.cfg +4 -0
  47. cortex_identity-6.4.0/tests/test_adapters.py +198 -0
  48. cortex_identity-6.4.0/tests/test_coding.py +849 -0
  49. cortex_identity-6.4.0/tests/test_context.py +493 -0
  50. cortex_identity-6.4.0/tests/test_continuous.py +755 -0
  51. cortex_identity-6.4.0/tests/test_contradictions.py +343 -0
  52. cortex_identity-6.4.0/tests/test_cooccurrence.py +224 -0
  53. cortex_identity-6.4.0/tests/test_dashboard.py +145 -0
  54. cortex_identity-6.4.0/tests/test_dedup.py +219 -0
  55. cortex_identity-6.4.0/tests/test_edge_extraction.py +395 -0
  56. cortex_identity-6.4.0/tests/test_features.py +774 -0
  57. cortex_identity-6.4.0/tests/test_graph.py +879 -0
  58. cortex_identity-6.4.0/tests/test_hooks.py +451 -0
  59. cortex_identity-6.4.0/tests/test_intelligence.py +327 -0
  60. cortex_identity-6.4.0/tests/test_monitor.py +174 -0
  61. cortex_identity-6.4.0/tests/test_query.py +411 -0
  62. cortex_identity-6.4.0/tests/test_scheduler.py +190 -0
  63. cortex_identity-6.4.0/tests/test_temporal.py +375 -0
  64. cortex_identity-6.4.0/tests/test_timeline.py +274 -0
  65. cortex_identity-6.4.0/tests/test_upai.py +274 -0
  66. cortex_identity-6.4.0/tests/test_versioning.py +213 -0
  67. cortex_identity-6.4.0/tests/test_viz.py +335 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Junebugg1214
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,3 @@
1
+ include LICENSE
2
+ include README.md
3
+ recursive-include cortex *.py
@@ -0,0 +1,617 @@
1
+ Metadata-Version: 2.4
2
+ Name: cortex-identity
3
+ Version: 6.4.0
4
+ Summary: Own your AI memory. Take it everywhere.
5
+ Author: Junebugg1214
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Junebugg1214/Cortex-AI
8
+ Project-URL: Repository, https://github.com/Junebugg1214/Cortex-AI
9
+ Project-URL: Issues, https://github.com/Junebugg1214/Cortex-AI/issues
10
+ Keywords: ai-identity,knowledge-graph,chatgpt,claude,memory,portable
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Provides-Extra: crypto
22
+ Requires-Dist: pynacl>=1.5.0; extra == "crypto"
23
+ Provides-Extra: fast
24
+ Requires-Dist: numpy>=1.24.0; extra == "fast"
25
+ Provides-Extra: full
26
+ Requires-Dist: pynacl>=1.5.0; extra == "full"
27
+ Requires-Dist: numpy>=1.24.0; extra == "full"
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=7.0; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # Cortex — Your Portable AI Identity
33
+
34
+ **Own your AI memory. Take it everywhere.**
35
+
36
+ Cortex extracts your context from every AI platform you use — ChatGPT, Claude, Gemini, Perplexity — and every coding tool — Claude Code, Cursor, Copilot — merges it into a single knowledge graph, and lets you selectively push it back to any platform. Cryptographically signed. Version controlled. Zero external dependencies.
37
+
38
+ ```bash
39
+ pip install cortex-identity
40
+
41
+ # Extract from ChatGPT, export to Claude
42
+ cortex chatgpt-export.zip --to claude -o ./output
43
+
44
+ # Visualize your knowledge graph
45
+ cortex viz context.json --output graph.html
46
+
47
+ # Launch the dashboard
48
+ cortex dashboard context.json
49
+ ```
50
+
51
+ > **Nobody else builds user-owned portable AI identity.** Mem0, Letta, and built-in AI memories are agent memory — owned by the platform. Cortex is *your* memory, under *your* control.
52
+
53
+ ---
54
+
55
+ ## How It Works
56
+
57
+ ```
58
+ Chat Exports (ChatGPT, Claude, Gemini, Perplexity, API logs)
59
+ + Coding Sessions (Claude Code, Cursor, Copilot)
60
+ |
61
+ cortex.extract_memory Parse exports, extract entities (declarative)
62
+ cortex.coding Parse coding sessions (behavioral)
63
+ |
64
+ CortexGraph Nodes (entities) + Edges (relationships)
65
+ |
66
+ UPAI Protocol Sign, version, control disclosure
67
+ |
68
+ Platform Adapters Push selective views to Claude, Notion, etc.
69
+ |
70
+ Flywheel Auto-extract, auto-sync, dashboard
71
+ ```
72
+
73
+ **Nodes are entities, not category items.** "Python" is ONE node with tags `[technical_expertise, domain_knowledge]` — not duplicated across categories. Edges capture typed relationships: `Python --applied_in--> Healthcare`.
74
+
75
+ ---
76
+
77
+ ## Quick Start
78
+
79
+ ### Install
80
+
81
+ ```bash
82
+ pip install cortex-identity
83
+ ```
84
+
85
+ That's it. Zero dependencies — pure Python stdlib.
86
+
87
+ ### Use
88
+
89
+ ```bash
90
+ # Extract context from a chat export
91
+ cortex chatgpt-export.zip --to claude -o ./output
92
+
93
+ # Or extract to universal JSON first
94
+ cortex extract chatgpt-export.zip -o context.json
95
+
96
+ # Then export to any platform
97
+ cortex import context.json --to all -o ./output
98
+ ```
99
+
100
+ ### Optional Extras
101
+
102
+ ```bash
103
+ pip install cortex-identity[crypto] # Ed25519 signatures (PyNaCl)
104
+ pip install cortex-identity[fast] # 10x faster graph layout (numpy)
105
+ pip install cortex-identity[full] # Both
106
+ pip install cortex-identity[dev] # + pytest for running tests
107
+ ```
108
+
109
+ ### From Source
110
+
111
+ ```bash
112
+ git clone https://github.com/Junebugg1214/Cortex-AI.git
113
+ cd Cortex-AI
114
+ pip install -e .
115
+ ```
116
+
117
+ ### Requirements
118
+
119
+ - Python 3.10+ (macOS, Linux, Windows)
120
+ - No external packages required for core functionality
121
+
122
+ ### Production Ready
123
+
124
+ v6.4 has been hardened for cross-platform use: atomic file saves prevent data corruption, paths with spaces are properly quoted, `sys.executable` ensures Windows compatibility, and all extraction errors surface to stderr for debugging.
125
+
126
+ ---
127
+
128
+ ## The Ten Layers
129
+
130
+ ### 1. Graph Foundation
131
+
132
+ Everything is nodes and edges. Nodes have tags (not fixed categories), confidence scores, temporal metadata, and extensible properties. The graph is backward compatible — v4 flat-category JSON converts losslessly.
133
+
134
+ ```bash
135
+ cortex query context.json --node "Python"
136
+ cortex query context.json --neighbors "Python"
137
+ cortex stats context.json
138
+ ```
139
+
140
+ ### 2. Temporal Engine
141
+
142
+ Every extraction snapshots each node's state. Cortex tracks how your identity evolves, detects contradictions ("said X in January, not-X in March"), and computes drift scores across time windows.
143
+
144
+ ```bash
145
+ cortex timeline context.json --format html
146
+ cortex contradictions context.json --severity 0.5
147
+ cortex drift context.json --compare previous.json
148
+ ```
149
+
150
+ ### 3. UPAI Protocol (Universal Portable AI Identity)
151
+
152
+ The breakthrough layer. Three capabilities:
153
+
154
+ - **Cryptographic signing** — SHA-256 integrity (always). Ed25519 signatures (with `pynacl`). Proves the graph is yours and untampered.
155
+ - **Selective disclosure** — Policies control what each platform sees. "Professional" shows job/skills. "Technical" shows your tech stack. "Minimal" shows almost nothing.
156
+ - **Version control** — Git-like commits for your identity. Log, diff, checkout, rollback.
157
+
158
+ ```bash
159
+ # Initialize identity
160
+ cortex identity --init --name "Your Name"
161
+
162
+ # Commit a version
163
+ cortex commit context.json -m "Added June ChatGPT export"
164
+
165
+ # View history
166
+ cortex log
167
+
168
+ # Compare versions
169
+ cortex identity --show
170
+
171
+ # Push to Claude with professional disclosure policy
172
+ cortex sync context.json --to claude --policy professional -o ./output
173
+ ```
174
+
175
+ **Built-in disclosure policies:**
176
+
177
+ | Policy | What's Shared | Min Confidence |
178
+ |--------|---------------|----------------|
179
+ | `full` | Everything | 0.0 |
180
+ | `professional` | Identity, work, skills, priorities | 0.6 |
181
+ | `technical` | Tech stack, domain knowledge, priorities | 0.5 |
182
+ | `minimal` | Identity, communication preferences only | 0.8 |
183
+
184
+ ### 4. Smart Edges
185
+
186
+ Automatic relationship discovery:
187
+
188
+ - **Pattern rules** — `technical_expertise` + `active_priorities` = `used_in` edge
189
+ - **Co-occurrence** — entities appearing together in messages get linked (PMI for large datasets, frequency thresholds for small)
190
+ - **Centrality** — identifies your most important nodes (degree centrality, PageRank for 200+ nodes)
191
+ - **Graph-aware dedup** — merges near-duplicates using 70% text similarity + 30% neighbor overlap
192
+
193
+ ### 5. Query + Intelligence
194
+
195
+ Structured queries and proactive analysis:
196
+
197
+ ```bash
198
+ # Find by category, confidence, relationships
199
+ cortex query context.json --category technical_expertise
200
+ cortex query context.json --strongest 10
201
+ cortex query context.json --isolated
202
+
203
+ # Shortest path between two nodes
204
+ cortex query context.json --path "Python" "Mayo Clinic"
205
+
206
+ # Connected components
207
+ cortex query context.json --components
208
+
209
+ # Gap analysis — what's missing from your graph?
210
+ cortex gaps context.json
211
+
212
+ # Weekly digest — what changed?
213
+ cortex digest context.json --previous last_week.json
214
+ ```
215
+
216
+ ### 6. Visualization + Flywheel
217
+
218
+ See your graph, keep it alive:
219
+
220
+ ```bash
221
+ # Interactive HTML visualization (zoom, pan, hover, click)
222
+ cortex viz context.json --output graph.html
223
+
224
+ # Static SVG for documents
225
+ cortex viz context.json --output graph.svg --format svg
226
+
227
+ # Live dashboard with stats, gaps, components
228
+ cortex dashboard context.json --port 8420
229
+
230
+ # Auto-extract new exports dropped into a folder
231
+ cortex watch ~/exports/ --graph context.json
232
+
233
+ # Scheduled sync to platforms
234
+ cortex sync-schedule --config sync_config.json
235
+ ```
236
+
237
+ ### 7. Coding Tool Extraction
238
+
239
+ Extract identity from what you *actually do*, not just what you say. Coding sessions reveal your real tech stack, tools, and workflow through behavior:
240
+
241
+ ```bash
242
+ # Auto-discover and extract from Claude Code sessions
243
+ cortex extract-coding --discover -o coding_context.json
244
+
245
+ # Filter by project name
246
+ cortex extract-coding --discover --project chatbot-memory
247
+
248
+ # Merge coding extraction with chatbot extraction
249
+ cortex extract-coding --discover --merge context.json -o context.json
250
+
251
+ # Enrich with project files (README, manifests, license)
252
+ cortex extract-coding --discover --enrich --stats
253
+
254
+ # Extract from a specific session file
255
+ cortex extract-coding ~/.claude/projects/*/session.jsonl
256
+ ```
257
+
258
+ **What it extracts:**
259
+
260
+ | Signal | How | Example |
261
+ |--------|-----|---------|
262
+ | Languages | File extensions | Editing `.py` files -> Python |
263
+ | Frameworks | Config files | `package.json` -> Node.js |
264
+ | CLI tools | Bash commands | Running `pytest` -> Pytest |
265
+ | Projects | Working directory | `/home/user/myapp` -> myapp |
266
+ | Patterns | Tool sequence | Uses plan mode before coding |
267
+
268
+ **Project enrichment** (`--enrich`): Reads README, package manifests (package.json, pyproject.toml, Cargo.toml), and LICENSE files from project directories to extract project descriptions, metadata, and domain knowledge. Detects CI/CD and Docker presence.
269
+
270
+ Currently supports **Claude Code** (JSONL transcripts). Cursor and Copilot parsers planned.
271
+
272
+ ### 8. Auto-Inject Context
273
+
274
+ Every new Claude Code session automatically gets your Cortex identity injected. Install once, context flows forever:
275
+
276
+ ```bash
277
+ # Install the hook (one-time setup)
278
+ cortex context-hook install context.json
279
+
280
+ # Preview what gets injected
281
+ cortex context-hook test
282
+
283
+ # Export compact context manually
284
+ cortex context-export context.json --policy technical
285
+ ```
286
+
287
+ The hook loads your graph, applies disclosure filtering, and injects a compact markdown summary (~300-800 chars) as a system message. Your AI always knows your tech stack, projects, and preferences.
288
+
289
+ ### 9. Cross-Platform Context Writer
290
+
291
+ Write persistent Cortex identity to **every AI coding tool** with non-destructive section markers that preserve your existing rules:
292
+
293
+ ```bash
294
+ # Write to all 6 platforms at once
295
+ cortex context-write graph.json --platforms all --project ~/myproject
296
+
297
+ # Write to specific platforms
298
+ cortex context-write graph.json --platforms cursor copilot windsurf
299
+
300
+ # Preview without writing
301
+ cortex context-write graph.json --platforms all --dry-run
302
+
303
+ # Auto-refresh when your graph updates
304
+ cortex context-write graph.json --platforms all --watch
305
+ ```
306
+
307
+ **Supported platforms:**
308
+
309
+ | Platform | Config File | Scope |
310
+ |----------|------------|-------|
311
+ | Claude Code | `~/.claude/MEMORY.md` | Global |
312
+ | Claude Code (project) | `{project}/.claude/MEMORY.md` | Project |
313
+ | Cursor | `{project}/.cursor/rules/cortex.mdc` | Project |
314
+ | GitHub Copilot | `{project}/.github/copilot-instructions.md` | Project |
315
+ | Windsurf | `{project}/.windsurfrules` | Project |
316
+ | Gemini CLI | `{project}/GEMINI.md` | Project |
317
+
318
+ Uses `<!-- CORTEX:START -->` / `<!-- CORTEX:END -->` markers — your hand-written rules are never overwritten.
319
+
320
+ ### 10. Continuous Extraction
321
+
322
+ Watch Claude Code sessions in real-time. Auto-extract behavioral signals as you code, merge into your graph, and optionally chain to cross-platform context refresh:
323
+
324
+ ```bash
325
+ # Watch and auto-update graph
326
+ cortex extract-coding --watch -o coding_context.json
327
+
328
+ # Watch + auto-refresh context to all platforms
329
+ cortex extract-coding --watch -o ctx.json \
330
+ --context-refresh claude-code cursor copilot
331
+
332
+ # Watch specific project only
333
+ cortex extract-coding --watch --project chatbot-memory -o ctx.json
334
+
335
+ # Custom interval and debounce
336
+ cortex extract-coding --watch --interval 15 --settle 10 -o ctx.json
337
+ ```
338
+
339
+ **How it works:** Polls `~/.claude/projects/` for `*.jsonl` changes (mtime + size), debounces active writes (5s settle), extracts via the coding pipeline, and incrementally merges nodes by label (max confidence, sum mentions, union tags). Graph updates trigger an optional `on_update` callback for cross-platform refresh.
340
+
341
+ ---
342
+
343
+ ## Supported Platforms
344
+
345
+ ### Input (Extract From)
346
+
347
+ | Platform | File Type | Auto-Detected |
348
+ |----------|-----------|---------------|
349
+ | ChatGPT | `.zip` with `conversations.json` | Yes |
350
+ | Claude | `.json` with messages array | Yes |
351
+ | Claude Memories | `.json` array with `text` field | Yes |
352
+ | Gemini / AI Studio | `.json` with conversations/turns | Yes |
353
+ | Perplexity | `.json` with threads | Yes |
354
+ | API Logs | `.json` with requests array | Yes |
355
+ | JSONL | `.jsonl` (one message per line) | Yes |
356
+ | Claude Code | `.jsonl` session transcripts | Yes |
357
+ | Plain Text | `.txt`, `.md` | Yes |
358
+
359
+ ### Output (Export To)
360
+
361
+ | Format | Output | Use Case |
362
+ |--------|--------|----------|
363
+ | Claude Preferences | `claude_preferences.txt` | Settings > Profile |
364
+ | Claude Memories | `claude_memories.json` | memory_user_edits |
365
+ | System Prompt | `system_prompt.txt` | Any LLM API |
366
+ | Notion Page | `notion_page.md` | Notion import |
367
+ | Notion Database | `notion_database.json` | Notion DB rows |
368
+ | Google Docs | `google_docs.html` | Google Docs paste |
369
+ | Summary | `summary.md` | Human overview |
370
+ | Full JSON | `full_export.json` | Lossless backup |
371
+
372
+ ---
373
+
374
+ ## Extraction Categories
375
+
376
+ Cortex extracts entities into 17 tag categories:
377
+
378
+ | Category | Examples |
379
+ |----------|----------|
380
+ | Identity | Name, credentials (MD, PhD) |
381
+ | Professional Context | Role, title, company |
382
+ | Business Context | Company, products, metrics |
383
+ | Active Priorities | Current projects, goals |
384
+ | Relationships | Partners, clients, collaborators |
385
+ | Technical Expertise | Languages, frameworks, tools |
386
+ | Domain Knowledge | Healthcare, finance, AI/ML |
387
+ | Market Context | Competitors, industry trends |
388
+ | Metrics | Revenue, users, timelines |
389
+ | Constraints | Budget, timeline, team size |
390
+ | Values | Principles, beliefs |
391
+ | Negations | What you explicitly avoid |
392
+ | User Preferences | Style and tool preferences |
393
+ | Communication Preferences | Response style preferences |
394
+ | Correction History | Self-corrections |
395
+ | Mentions | Catch-all for other entities |
396
+
397
+ ---
398
+
399
+ ## Key Features
400
+
401
+ ### PII Redaction
402
+
403
+ Strip sensitive data before extraction:
404
+
405
+ ```bash
406
+ cortex chatgpt-export.zip --to claude --redact
407
+
408
+ # With custom patterns
409
+ cortex chatgpt-export.zip --to claude --redact --redact-patterns custom.json
410
+ ```
411
+
412
+ Redacts: emails, phones, SSNs, credit cards, API keys, IP addresses, street addresses.
413
+
414
+ ### Incremental Merge
415
+
416
+ Combine new exports without losing existing data:
417
+
418
+ ```bash
419
+ cortex extract export1.json -o context.json
420
+ cortex extract export2.json --merge context.json -o context.json
421
+ ```
422
+
423
+ ### Conflict Detection
424
+
425
+ Automatically flags contradictions:
426
+
427
+ ```
428
+ Input: "I use Python daily" + "I don't use Python anymore"
429
+ Result: negation_conflict detected, resolution: prefer_negation (more recent)
430
+ ```
431
+
432
+ ### Typed Relationships
433
+
434
+ ```
435
+ Input: "We partner with Mayo Clinic. Dr. Smith is my mentor."
436
+ Result: Mayo Clinic (partner), Dr. Smith (mentor)
437
+ ```
438
+
439
+ Supported types: `partner`, `mentor`, `advisor`, `investor`, `client`, `competitor`
440
+
441
+ ---
442
+
443
+ ## Architecture
444
+
445
+ ```
446
+ cortex-identity/ # pip install cortex-identity
447
+ ├── pyproject.toml # Package metadata + entry points
448
+ ├── cortex/
449
+ │ ├── cli.py # CLI entry point (23 subcommands)
450
+ │ ├── extract_memory.py # Extraction engine (~1400 LOC)
451
+ │ ├── import_memory.py # Import/export engine (~1000 LOC)
452
+ │ ├── graph.py # Node, Edge, CortexGraph (schema 6.0)
453
+ │ ├── compat.py # v4 <-> v5 conversion
454
+ │ ├── temporal.py # Snapshots, drift scoring
455
+ │ ├── contradictions.py # Contradiction detection
456
+ │ ├── timeline.py # Timeline views
457
+ │ ├── upai/
458
+ │ │ ├── identity.py # UPAI identity, DID, Ed25519/HMAC signing
459
+ │ │ ├── disclosure.py # Selective disclosure policies
460
+ │ │ └── versioning.py # Git-like version control
461
+ │ ├── adapters.py # Claude/SystemPrompt/Notion/GDocs adapters
462
+ │ ├── edge_extraction.py # Pattern-based + proximity edge discovery
463
+ │ ├── cooccurrence.py # PMI / frequency co-occurrence
464
+ │ ├── dedup.py # Graph-aware deduplication
465
+ │ ├── centrality.py # Degree centrality + PageRank
466
+ │ ├── query.py # QueryEngine + graph algorithms
467
+ │ ├── intelligence.py # Gap analysis + weekly digest
468
+ │ ├── coding.py # Coding session behavioral extraction
469
+ │ ├── hooks.py # Auto-inject context into Claude Code
470
+ │ ├── context.py # Cross-platform context writer (6 platforms)
471
+ │ ├── continuous.py # Real-time session watcher
472
+ │ ├── _hook.py # cortex-hook entry point
473
+ │ ├── __main__.py # python -m cortex support
474
+ │ ├── viz/ # Visualization
475
+ │ ├── dashboard/ # Local web dashboard
476
+ │ └── sync/ # File watcher + scheduled sync
477
+ ├── migrate.py # Backward-compat stub → cortex.cli
478
+ ├── cortex-hook.py # Backward-compat stub → cortex._hook
479
+ └── tests/ # 618 tests across 21 files
480
+ ```
481
+
482
+ ---
483
+
484
+ ## CLI Reference
485
+
486
+ ### Extract & Import
487
+
488
+ ```bash
489
+ cortex <export> --to <platform> -o ./output # One-step migrate
490
+ cortex extract <export> -o context.json # Extract only
491
+ cortex import context.json --to <platform> # Import only
492
+ cortex extract new.json --merge old.json -o merged.json # Merge contexts
493
+ ```
494
+
495
+ ### Query & Intelligence
496
+
497
+ ```bash
498
+ cortex query <graph> --node <label> # Find node
499
+ cortex query <graph> --neighbors <label> # Find neighbors
500
+ cortex query <graph> --category <tag> # Filter by tag
501
+ cortex query <graph> --path <from> <to> # Shortest path
502
+ cortex query <graph> --strongest <n> # Top N nodes
503
+ cortex query <graph> --weakest <n> # Bottom N nodes
504
+ cortex query <graph> --isolated # Unconnected nodes
505
+ cortex query <graph> --components # Connected clusters
506
+ cortex gaps <graph> # Gap analysis
507
+ cortex digest <graph> --previous <old> # Weekly digest
508
+ cortex stats <graph> # Graph statistics
509
+ ```
510
+
511
+ ### Identity & Sync
512
+
513
+ ```bash
514
+ cortex identity --init --name <name> # Create identity
515
+ cortex commit <graph> -m <message> # Version commit
516
+ cortex log # Version history
517
+ cortex identity --show # Show identity
518
+ cortex sync <graph> --to <platform> --policy <name> # Push to platform
519
+ ```
520
+
521
+ ### Visualization & Flywheel
522
+
523
+ ```bash
524
+ cortex viz <graph> --output graph.html # Interactive HTML
525
+ cortex viz <graph> --output graph.svg --format svg # Static SVG
526
+ cortex dashboard <graph> --port 8420 # Web dashboard
527
+ cortex watch <dir> --graph <graph> # Auto-extract
528
+ cortex sync-schedule --config <config.json> # Scheduled sync
529
+ ```
530
+
531
+ ### Coding Tool Extraction
532
+
533
+ ```bash
534
+ cortex extract-coding <session.jsonl> # From specific file
535
+ cortex extract-coding --discover # Auto-find sessions
536
+ cortex extract-coding --discover -p <project> # Filter by project
537
+ cortex extract-coding --discover -m <context> # Merge with existing
538
+ cortex extract-coding --discover --stats # Show session stats
539
+ cortex extract-coding --discover --enrich # Enrich with project files
540
+ cortex extract-coding --watch -o ctx.json # Watch mode (continuous)
541
+ cortex extract-coding --watch --context-refresh claude-code cursor # Watch + auto-refresh
542
+ ```
543
+
544
+ ### Context Hook (Auto-Inject)
545
+
546
+ ```bash
547
+ cortex context-hook install <graph> --policy technical # Install hook
548
+ cortex context-hook uninstall # Remove hook
549
+ cortex context-hook test # Preview injection
550
+ cortex context-hook status # Check status
551
+ cortex context-export <graph> --policy technical # One-shot export
552
+ ```
553
+
554
+ ### Cross-Platform Context Writer
555
+
556
+ ```bash
557
+ cortex context-write <graph> --platforms all --project <dir> # All platforms
558
+ cortex context-write <graph> --platforms cursor copilot # Specific platforms
559
+ cortex context-write <graph> --platforms all --dry-run # Preview
560
+ cortex context-write <graph> --platforms all --watch # Auto-refresh
561
+ cortex context-write <graph> --platforms all --policy professional # Policy override
562
+ ```
563
+
564
+ ### Temporal Analysis
565
+
566
+ ```bash
567
+ cortex timeline <graph> --format html # Timeline view
568
+ cortex contradictions <graph> --severity 0.5 # Find conflicts
569
+ cortex drift <graph> --window 90 # Identity drift
570
+ ```
571
+
572
+ ---
573
+
574
+ ## Competitive Landscape
575
+
576
+ | Capability | Cortex | Mem0 | Letta | ChatGPT Memory | Claude Memory |
577
+ |---|:-:|:-:|:-:|:-:|:-:|
578
+ | Knowledge Graph | Yes | Partial | No | No | No |
579
+ | **Portability (UPAI)** | **Yes** | No | No | No | No |
580
+ | **User-Owned** | **Yes** | No | No | No | No |
581
+ | **Temporal Tracking** | **Yes** | No | No | No | No |
582
+ | **Coding Tool Extraction** | **Yes** | No | No | No | No |
583
+ | **Auto-Inject Context** | **Yes** | No | No | No | No |
584
+ | **Cross-Platform Context** | **Yes (6)** | No | No | No | No |
585
+ | **Continuous Extraction** | **Yes** | No | No | No | No |
586
+ | Zero-Dep / Local-First | Yes | No | No | N/A | N/A |
587
+
588
+ ---
589
+
590
+ ## Version History
591
+
592
+ | Version | Milestone |
593
+ |---------|-----------|
594
+ | v6.4 | **pip packaging + continuous extraction + production hardening** — `pip install cortex-identity` with `cortex` CLI entry point; real-time session watching with debounce, incremental graph merge, cross-platform auto-refresh; hardened for production (atomic saves, path quoting, Windows compat, error visibility); 35 sys.path hacks eliminated |
595
+ | v6.3 | **Cross-platform context writer** — persistent context files for Claude Code, Cursor, Copilot, Windsurf, Gemini CLI with non-destructive section markers |
596
+ | v6.2 | **Auto-inject context** — SessionStart hook for Claude Code, compact context generation, install/uninstall CLI |
597
+ | v6.1 | **Coding tool extraction** — behavioral extraction from Claude Code sessions, project enrichment |
598
+ | v6.0 | Visualization, dashboard, file monitor, sync scheduler |
599
+ | v5.4 | Query engine, gap analysis, weekly digest |
600
+ | v5.3 | Smart edge extraction, co-occurrence, centrality, dedup |
601
+ | v5.2 | **UPAI Protocol** — cryptographic signing, selective disclosure, version control |
602
+ | v5.1 | Temporal snapshots, contradiction engine, drift scoring |
603
+ | v5.0 | Graph foundation — category-agnostic nodes, edges, v4 roundtrip |
604
+ | v4.3 | PII redaction |
605
+ | v4.2 | Typed relationships, conflict detection, incremental merge |
606
+ | v4.1 | Negation detection, preferences/constraints, Gemini/Perplexity support |
607
+ | v4.0 | Semantic dedup, time decay, Notion/Google Docs export |
608
+
609
+ ---
610
+
611
+ ## License
612
+
613
+ MIT License - See [LICENSE](LICENSE)
614
+
615
+ ## Author
616
+
617
+ Created by [@Junebugg1214](https://github.com/Junebugg1214)