Skip to content

feat: detect and reconcile docs created outside the API#32

Open
wormuz wants to merge 6 commits into
0xranx:mainfrom
wormuz:feat/manifest-drift-detection
Open

feat: detect and reconcile docs created outside the API#32
wormuz wants to merge 6 commits into
0xranx:mainfrom
wormuz:feat/manifest-drift-detection

Conversation

@wormuz
Copy link
Copy Markdown
Contributor

@wormuz wormuz commented May 6, 2026

Files written under ~/.opencontext/contexts/ via Write/Edit (bypassing oc_create_doc) used to silently disappear from oc_manifest and oc_search because the manifest was a pure SELECT from SQLite. Agents thought the folder was empty and proposed re-creating it.

Three changes that make the drift impossible to miss:

  1. oc_manifest now scans the filesystem after the SELECT and returns { items, unindexed_files }. When unindexed_files is non-empty, MCP surfaces a warning field naming each file. Manifest stays read-only

    • no auto-insert.
  2. New oc index reconcile [folder] CLI command and oc_reconcile_folder MCP tool. They INSERT a docs row for every *.md present on disk but missing from SQLite, without recomputing embeddings (run oc index build separately for that). Fast path for picking up orphans after a Write or git pull.

  3. oc_create_doc / oc_set_doc_desc descriptions now open with a hard "REQUIRED for any file under ~/.opencontext/contexts/" notice that explicitly calls out Write/Edit as a bug, so MCP-aware agents stop reaching for them.

Rust core gains generate_manifest_full() and reconcile_folder() (the old generate_manifest is preserved for Tauri/UI/CLI callers). NAPI binding switches generateManifest to the wrapped form; existing JS callers updated. Three new core tests cover orphan detection, nested-folder scan, and reconcile idempotency. Tested end-to-end on a real folder with 6 orphans - manifest reported drift, reconcile registered all 6, follow-up manifest came back clean.

Konstantin Cheremisov added 6 commits May 6, 2026 11:50
Files written under ~/.opencontext/contexts/ via Write/Edit (bypassing
oc_create_doc) used to silently disappear from oc_manifest and oc_search
because the manifest was a pure SELECT from SQLite. Agents thought the
folder was empty and proposed re-creating it.

Three changes that make the drift impossible to miss:

1. oc_manifest now scans the filesystem after the SELECT and returns
   { items, unindexed_files }. When unindexed_files is non-empty, MCP
   surfaces a `warning` field naming each file. Manifest stays read-only
   - no auto-insert.

2. New `oc index reconcile [folder]` CLI command and `oc_reconcile_folder`
   MCP tool. They INSERT a docs row for every *.md present on disk but
   missing from SQLite, without recomputing embeddings (run
   `oc index build` separately for that). Fast path for picking up
   orphans after a Write or `git pull`.

3. oc_create_doc / oc_set_doc_desc descriptions now open with a hard
   "REQUIRED for any file under ~/.opencontext/contexts/" notice that
   explicitly calls out Write/Edit as a bug, so MCP-aware agents stop
   reaching for them.

Rust core gains generate_manifest_full() and reconcile_folder() (the
old generate_manifest is preserved for Tauri/UI/CLI callers). NAPI
binding switches generateManifest to the wrapped form; existing JS
callers updated. Three new core tests cover orphan detection,
nested-folder scan, and reconcile idempotency. Tested end-to-end on a
real folder with 6 orphans - manifest reported drift, reconcile
registered all 6, follow-up manifest came back clean.
The previous commit's oc_create_doc / oc_set_doc_desc descriptions told
agents to call `oc_save_doc` for body edits, but that tool was never
registered in src/mcp/server.js — only the Rust core / NAPI / JS layers
had it. Agents had to fall back to Edit on the absolute path, which is
safe but contradicts our own "REQUIRED — never use Write/Edit" guidance
and skips the updated_at bump + search-sync event.

Register oc_save_doc as a thin wrapper over store.saveDocContent so the
description's promise is actually fulfillable. Tighten neighbouring
descriptions to mention only tools that exist (drop the phantom
`oc_update_doc` and the JS-internal `saveDocContent`).
clippy::ptr_arg with -D warnings treats &PathBuf args as errors.
Replace with &Path — callers pass &path (PathBuf) which coerces automatically.
oc_search matches document body only — not folder/file names.
Agents searching by project name got 0 results and wrongly concluded
the project doesn't exist.

Add explicit routing hint to both descriptions:
- oc_search: 'Does NOT match folder/file names — use oc_manifest for known projects'
- oc_manifest: 'Use this when you know the project/folder name — oc_search matches content only'
- cargo fmt: fix unindexed_files formatting and use std import style
  to match CI rustfmt version
- cargo fmt: split multi-line name chain and condense write calls in tests
- test-js: uninstall published @aicontextlab/core-native before running
  tests so the locally built binary is loaded instead of stale npm package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant