Files
openclaw/extensions/memory-wiki
zhangqueping adc4136a3b fix(memory-wiki): strip fenced code and inline code before wikilink extraction (#98095)
* fix(memory-wiki): strip fenced code and inline code before wikilink extraction

The wikilink extractor in extractWikiLinks previously scanned
the full markdown content including fenced code blocks and
inline code spans.  Literal [[...]] syntax inside code regions
(e.g. bash test syntax, Scala generics like
Future[Option[User]]) produced false-positive broken-wikilink
lint warnings.

Add FENCED_CODE_BLOCK_PATTERN and INLINE_CODE_PATTERN and
strip those regions from the searchable text before running
the Obsidian and Markdown link regexes.  Five regression tests
cover backtick-fenced, tilde-fenced, 6-backtick-fenced, and
inline code scenarios plus a full vault lint round-trip.

Fixes #97945

* fix(memory-wiki): accept longer closing fence in code block stripping

The FENCED_CODE_BLOCK_PATTERN used a regex backreference (\1)
that required the closing fence to be exactly identical to the
opening fence.  CommonMark allows the closing fence to be the
same character type and at least as long — e.g. ``` opening
with ```` closing is valid.  Switch to a function-based
replacement that compares fence character type and length.

Add regression test for the longer-closing-fence case per
ClawSweeper review feedback (#98095).

* style(memory-wiki): add braces to if-body in fence replacement callback

Fixes ESLint curly rule violation at line 403.

* fix(memory-wiki): replace fence regex with line scanner for wikilink extraction

Replace FENCED_CODE_BLOCK_RE regex/callback with a line-by-line scanner
that keeps searching past invalid fence-looking lines (e.g. a shorter
``` line inside a longer `````` block) until a valid closing
fence of the same character type and at least as long is found.

Also handles tilde fences and longer closing fences per CommonMark spec.

🦞 diamond lobster: L2 evidence (5 real function-call scenarios, all passing)

Ref. https://github.com/openclaw/openclaw/pull/98095

* fix(memory-wiki): use CommonMark code masking

---------

Co-authored-by: Vincent Koc <25068+vincentkoc@users.noreply.github.com>
2026-07-06 02:00:12 -07:00
..
2026-06-04 21:33:54 -04:00

@openclaw/memory-wiki

Persistent wiki compiler and Obsidian-friendly knowledge vault for OpenClaw.

This plugin is separate from the active memory plugin. The active memory plugin still handles recall, promotion, and dreaming. memory-wiki compiles durable knowledge into a navigable markdown vault with deterministic indexes, provenance, structured claim/evidence metadata, and optional Obsidian CLI workflows.

When the active memory plugin exposes shared recall, agents can use memory_search with corpus=all to search durable memory and the compiled wiki in one pass, then fall back to wiki_search / wiki_get when wiki-specific ranking or provenance matters.

Modes

  • isolated: own vault, own sources, no dependency on memory-core
  • bridge: reads public memory artifacts and memory events through public seams
  • unsafe-local: explicit same-machine escape hatch for private local paths

Default mode is isolated.

Config

Put config under plugins.entries.memory-wiki.config:

{
  vaultMode: "isolated",

  vault: {
    path: "~/.openclaw/wiki/main",
    renderMode: "obsidian", // or "native"
  },

  obsidian: {
    enabled: true,
    useOfficialCli: true,
    vaultName: "OpenClaw Wiki",
    openAfterWrites: false,
  },

  bridge: {
    enabled: false,
    readMemoryArtifacts: true,
    indexDreamReports: true,
    indexDailyNotes: true,
    indexMemoryRoot: true,
    followMemoryEvents: true,
  },

  unsafeLocal: {
    allowPrivateMemoryCoreAccess: false,
    paths: [],
  },

  ingest: {
    autoCompile: true,
    maxConcurrentJobs: 1,
    allowUrlIngest: true,
  },

  search: {
    backend: "shared", // or "local"
    corpus: "wiki", // or "memory" | "all"
  },

  context: {
    includeCompiledDigestPrompt: false, // opt in to append a compact compiled digest snapshot to memory prompt sections
  },

  render: {
    preserveHumanBlocks: true,
    createBacklinks: true, // writes managed ## Related blocks with sources, backlinks, and related pages
    createDashboards: true,
  },
}

Vault shape

The plugin initializes a vault like this:

<vault>/
  AGENTS.md
  WIKI.md
  index.md
  inbox.md
  entities/
  concepts/
  syntheses/
  sources/
  reports/
  _attachments/
  _views/
  .openclaw-wiki/

Generated content stays inside managed blocks. Human note blocks are preserved.

Key beliefs can live in structured claims frontmatter with per-claim evidence, confidence, and status. Compile also emits machine-readable digests under .openclaw-wiki/cache/ so agent/runtime consumers do not have to scrape markdown pages.

When render.createBacklinks is enabled, compile adds deterministic ## Related blocks to pages. Those blocks list source pages, pages that reference the current page, and nearby pages that share the same source ids.

When render.createDashboards is enabled, compile also maintains report dashboards under reports/ for open questions, contradictions, low-confidence pages, and stale pages.

Unmanaged raw Markdown can live under sources/ without OpenClaw page frontmatter. Add <!-- openclaw:wiki:raw-source --> near the top of the page body to opt it out of wiki page metadata and freshness lint; generated or source-sync tracked imports still require their structured metadata.

CLI

openclaw wiki status
openclaw wiki doctor
openclaw wiki init
openclaw wiki ingest ./notes/alpha.md
openclaw wiki compile
openclaw wiki lint
openclaw wiki search "alpha"
openclaw wiki get entity.alpha --from 1 --lines 80

openclaw wiki apply synthesis "Alpha Summary" \
  --body "Short synthesis body" \
  --source-id source.alpha

openclaw wiki apply metadata entity.alpha \
  --source-id source.alpha \
  --status review \
  --question "Still active?"

openclaw wiki bridge import
openclaw wiki unsafe-local import

openclaw wiki obsidian status
openclaw wiki obsidian search "alpha"
openclaw wiki obsidian open syntheses/alpha-summary.md
openclaw wiki obsidian command workspace:quick-switcher
openclaw wiki obsidian daily

Agent tools

  • wiki_status
  • wiki_lint
  • wiki_apply
  • wiki_search
  • wiki_get

The plugin also registers a non-exclusive memory corpus supplement, so shared memory_search / memory_get flows can reach the wiki when the active memory plugin supports corpus selection.

wiki_apply accepts structured claims payloads for synthesis and metadata updates, so the wiki can store claim-level evidence instead of only page-level prose.

When context.includeCompiledDigestPrompt is enabled, the memory prompt supplement also appends a compact snapshot from .openclaw-wiki/cache/agent-digest.json. Legacy prompt assembly sees that automatically, and non-legacy context engines can pick it up when they explicitly consume memory prompt supplements via buildActiveMemoryPromptSection(...).

Gateway RPC

Read methods:

  • wiki.status
  • wiki.doctor
  • wiki.search
  • wiki.get
  • wiki.obsidian.status
  • wiki.obsidian.search

Write methods:

  • wiki.init
  • wiki.compile
  • wiki.ingest
  • wiki.lint
  • wiki.bridge.import
  • wiki.unsafeLocal.import
  • wiki.apply
  • wiki.obsidian.open
  • wiki.obsidian.command
  • wiki.obsidian.daily

Notes

  • unsafe-local is intentionally experimental and non-portable.
  • Bridge mode reads the active memory plugin through public seams only.
  • Wiki pages are compiled artifacts, not the ultimate source of truth. Keep provenance attached to raw sources, memory artifacts, and daily notes.
  • The compiled agent digests in .openclaw-wiki/cache/agent-digest.json and .openclaw-wiki/cache/claims.jsonl are the stable machine-facing view of the wiki.
  • Obsidian CLI support requires the official obsidian CLI to be installed and available on PATH.