Foam Knowledge Base Tools
repository·main·Indexed 12 days ago
https://github.com/foambubble/foamA set of tools for managing personal knowledge bases, including @foam/cli for note and tag management, @foam/core for platform-agnostic business logic, @foam/graph-view for interactive visualization, and @foam/mcp for exposing knowledge graphs to AI agents via the Model Context Protocol.
What's inside Foam
- Foam is a personal knowledge management system designed to work within Visual Studio Code and GitHub. It is built on standard Markdown files, ensuring data ownership and avoiding vendor lock-in. It is primarily used for organizing research, creating discoverable notes, and publishing knowledge via Git-based workflows.
Core components of @foam/core
mainThe
@foam/corelibrary provides several key functional areas:- Workspace & graph: Managed via
FoamWorkspaceandFoamGraphto handle resources and their connections. - Markdown parsing: Tools to parse notes and extract links, tags, frontmatter, and blocks.
- Resource providers: Pluggable support for file types via
MarkdownResourceProviderandAttachmentResourceProvider. - Note creation: Includes a template engine, variable resolution, and support for daily notes.
- Query engine: Supports DQL and JS-based queries for embedding dynamic content.
- Link integrity: Computes rename edits for wikilinks and markdown links.
- Utilities: Includes logging, slugs, hashtags, and path helpers.
- Workspace & graph: Managed via
Implement or extend the Foam publishing layer
mainThe publishing layer is responsible for turning a workspace into artifacts without depending on VS Code APIs. It should be implemented as a framework-agnostic module.
Core Responsibilities:
- Discover and load publishable notes.
- Resolve wikilinks, aliases, and anchors using Foam's workspace/graph logic.
- Evaluate publish visibility rules.
- Rewrite links and expand/rewrite embeds for the target site.
- Compute backlinks and graph/search metadata.
- Render or precompute
foam-queryoutput.
Required Inputs:
- Workspace root
- Publish target configuration
- Output mode and path
Required Outputs:
- Transformed Markdown files.
- JSON indexes (for search, backlinks, graph, and route metadata).
- Copied static assets and attachments.
Core concepts of Foam knowledge management
mainFoam facilitates knowledge management through several key abstractions and syntax patterns:
- Atomic notes: Writing focused Markdown documents centered on single topics.
- Wikilinks: Connecting ideas using
[[double bracket]]syntax. This supports autocomplete and navigation within VS Code. - Embeds: Including content from other notes using
![[note]]syntax. - Backlinks: Automatically discovering connections between notes via a dedicated Backlinks panel.
- Graph visualization: A visual representation of your knowledge network.
- Daily notes: Capturing timestamped thoughts, often using templates and snippets.
- Tags: Organizing and filtering content using a tag system.
How @foam/cli workspace resolution works
mainThe CLI needs to know the root directory of your Foam workspace to resolve notes and tags. It determines the workspace root using the following priority order:
- The
--workspace <dir>global flag. - The
FOAM_WORKSPACEenvironment variable. - The current working directory (cwd).
You can set
FOAM_WORKSPACEin your shell profile to avoid passing the flag or changing directories constantly.- The
Manage Foam telemetry and data collection
mainFoam collects anonymous usage data (e.g., which commands are used, feature configurations) to prioritize development. It never collects note content, file names, or personal information.
Respecting VS Code Settings
Foam respects the global VS Code telemetry setting:
telemetry.telemetryLevel. If you have disabled telemetry in VS Code, Foam will not send any data.Inspecting Telemetry
To see what data is being sent, you can inspect the Foam output channel:
- Open the Command Palette.
- Run
Foam: Set log leveland selectDebug. - Check the Foam output channel for telemetry events.
For a full list of collected data and opt-out instructions, see the [[telemetry]] documentation.
Explore Foam panels and views
mainFoam integrates with VS Code panels to provide different perspectives on your knowledge base:
Foam: links: Displays incoming and outgoing links for the active note.Foam: Orphaned Notes: Lists notes with no incoming or outgoing links.Tag Explorer: Provides a hierarchical view of all tags in the workspace.Foam: Graph: A visual representation of note connections.Outline View: Shows the heading hierarchy of the current Markdown note for quick navigation.Timeline View: Located in the Explorer panel, it shows the history of file changes (Git commits and file saves).
Handle `@foam/core` dependency bumps for `foam-vscode` and `@foam/cli`
mainBecause
foam-vscodeand@foam/clibundle@foam/coreat build time (using esbuild) and declare it as adevDependency, Changesets' automatic internal-dependency bumping (updateInternalDependencies) will not automatically cascade a@foam/coreversion bump to them.Crucial Rule: If a change affects
packages/foam-core, your changeset fragment must explicitly includefoam-vscodeand@foam/cli(typically aspatchbumps). If you only bump@foam/core, the extension and CLI will publish updated code under stale version numbers.Manage broken links and placeholders
mainIn Foam, links to non-existent notes are treated as placeholders.
- Visual Cues: Placeholders are highlighted with a different color in the editor and styled specially in preview mode.
- Creation: Clicking a placeholder in the editor automatically creates the corresponding note.
- Discovery: You can find all existing placeholders by looking at the
Placeholderstreeview in the sidebar.
What data is collected by Foam telemetry
mainFoam collects anonymous usage data to prioritize improvements. The data collected varies by component:
Collected Data
- Common to all: Component name (
vscode,cli,mcp), component version,@foam/coreversion, OS family, and an anonymous identifier (CLI/MCP use a local installation UUID; VS Code uses a pseudonymous machine ID). - VS Code extension: Session events (loading, commands run, enum/boolean settings) and bucketed workspace size.
- CLI: One event per invocation including the command run, execution duration (bucketed), and bucketed workspace size.
- MCP: One event per tool call including the tool name, duration, and success status.
Data Privacy (What is NEVER collected)
Foam strictly avoids collecting any user-specific or content-specific data, including:
- Note content, titles, file names, or tag names.
- Wikilink targets, search queries, or any typed text.
- Folder paths or user-defined strings.
- Free-text configuration values.
- Command arguments, CLI flag values, or MCP tool arguments.
- Stack traces or error messages (only the error class name is sent).
- Anything that could identify you personally.
- Common to all: Component name (
How note targeting works
mainCommands that operate on specific notes (like
show,move, ordelete) accept a positional<identifier>. This identifier is resolved using the same logic as wikilinks (supporting short names or aliases).Alternatively, you can use the
--path <path>flag to target a note by its exact file path.Note: If an identifier matches more than one note, the command will exit with code
1and list the matching candidates.Use Foam Queries for dynamic content
mainYou can embed dynamic, auto-updating lists, tables, and counts of notes directly in your Markdown preview. This is achieved using
foam-queryandfoam-query-jscode blocks. For a full reference of query capabilities, consult the official Foam Queries documentation.# Example placeholder for a foam-query block