feat(marginnote4): Phase 1 — connected KB type, read-only tools, and sync bridge - #836
Open
evan188199-tech wants to merge 3 commits into
Open
feat(marginnote4): Phase 1 — connected KB type, read-only tools, and sync bridge#836evan188199-tech wants to merge 3 commits into
evan188199-tech wants to merge 3 commits into
Conversation
evan188199-tech
marked this pull request as ready for review
August 14, 2026 23:03
…ridge
Add MarginNote 4 as a connected knowledge base type that syncs study data
(notes, excerpts, cards, mindmap nodes) from MN4 via the official Add-on API
into a dedicated SQLite store, then exposes it to the chat loop through seven
read-only tools.
New package: deeptutor/capabilities/marginnote4/
- models.py: MarginNoteObject, SyncBatch, PairedDevice, LearningEvent
- store.py: SQLite CRUD + search + device pairing with hashed tokens
- binding.py: per-turn resolution of the selected MN4 library
- tools.py: search, read, list, documents, links, tags, cards
- capability.py: KnowledgeCapability (exclusive turn ownership)
- prompts/{en,zh}/system.md
HTTP bridge: deeptutor/api/routers/marginnote4.py
- POST /pair (session auth) -- register a device, get one-time token
- POST /sync (device-token auth) -- incremental upsert + tombstones
- POST /heartbeat (device-token auth) -- liveness + object count
- GET /devices, DELETE /devices/{id}, GET /status (session auth)
Integration points:
- kb_types.py: MARGINNOTE4_KB_TYPE added to CONNECTED_KB_TYPES
- manager.py: db_path surfaced in get_metadata allowlist
- registry.py: MarginNoteCapability registered in LOOP_CAPABILITIES
- builtin/__init__.py: MARGINNOTE_TOOL_TYPES in BUILTIN_TOOL_TYPES
- api/main.py: router mounted at /api/v1/marginnote4
Phase 1 scope: device pairing, read-only sync, tool navigation.
Write-back (propose/apply/verify), learning events, and mastery bridge
are planned for Phase 2-3.
Refs: HKUDS#756 (Obsidian external knowledge source pattern), HKUDS#180
Testing and experience improvements: - Search now includes document_title in scope: searching for a textbook name returns results instead of zero hits - Store instances cached by db_path so schema init runs once, not per tool call within a turn - object_type parameters carry enum constraints so the LLM knows valid types without guessing - System prompts (en/zh) rewritten with domain context: explains the five object types, link traversal strategy, and citation guidance - KB registration: register_marginnote4_kb manager method + /connect-marginnote4 API endpoint, mirroring the Obsidian connect flow - Fix indentation inconsistencies in manager.py and main.py - New tests: document_title search scope, KB registration (create, default path, duplicate rejection) 65 tests pass, 0 regressions, ruff clean.
evan188199-tech
force-pushed
the
codex/feat-marginnote4-protocol
branch
from
August 15, 2026 00:00
6be7544 to
d23bbf2
Compare
Contributor
Author
Rebase and validation update
Phase 2 write-back and Phase 3 mastery bridging remain intentionally out of scope. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds MarginNote 4 as a connected knowledge base type that syncs study data from MN4 via the official Add-on API into a dedicated SQLite store, then exposes it to the chat loop through seven read-only tools.
This follows the same architectural pattern as the Obsidian integration (#756): a
KnowledgeCapabilitythat owns the turn exclusively when an MN4 library is selected, backed by a connected KB type that skips indexing.What's included (Phase 1)
New package
deeptutor/capabilities/marginnote4/:models.py—MarginNoteObject,SyncBatch,PairedDevice,LearningEventstore.py— SQLite CRUD + search + device pairing with SHA-256 hashed tokensbinding.py— per-turn resolution of the selected MN4 librarytools.py— 7 read-only tools:search,read,list,documents,links,tags,cardscapability.py—MarginNoteCapability(KnowledgeCapability, exclusive turn ownership)prompts/{en,zh}/system.md— bilingual system promptsHTTP bridge
deeptutor/api/routers/marginnote4.py:POST /pairPOST /syncPOST /heartbeatGET /devicesDELETE /devices/{id}GET /statusIntegration points:
kb_types.py:MARGINNOTE4_KB_TYPEadded toCONNECTED_KB_TYPESmanager.py:db_pathsurfaced inget_metadataallowlistregistry.py:MarginNoteCapabilityregistered inLOOP_CAPABILITIESbuiltin/__init__.py:MARGINNOTE_TOOL_TYPESinBUILTIN_TOOL_TYPESapi/main.py: router mounted at/api/v1/marginnote4Data sovereignty
Test coverage
40 new tests across:
All 73 tests pass (40 new + 33 existing capability/knowledge), 0 regressions. Ruff clean.
Roadmap
Refs: #756 (Obsidian pattern), #180 (multimodal learning)