Repository navigation
02 Layer Farol.Core
Farol.Core provides the foundational infrastructure for Farol. It has strictly zero dependencies on Roslyn or MSBuild, ensuring that path validation, process supervision, unified diff calculation, and telemetry execute with minimal memory overhead and complete isolation.
Farol.Core
├── Paths/
│ ├── PathSandbox.cs # Directory trust boundary & link resolution
│ ├── DisplayPath.cs # POSIX root-relative formatting & inline redaction
│ └── ArtifactDirectory.cs # Isolated temporary output folder management
├── Execution/
│ └── ProcessRunner.cs # Child process execution & entire tree termination
├── Files/
│ └── AtomicFile.cs # Temp-file write & atomic filesystem rename
├── Text/
│ ├── UnifiedDiff.cs # Myers diff algorithm (3-line context, git apply compatible)
│ ├── TokenBudget.cs # Token constraints & truncation tracking
│ └── ResponseBuilder.cs # Structured, token-budgeted text output builder
├── Usage/
│ ├── IUsageLog.cs # Local telemetry logging interface
│ ├── ToolCallOutcome.cs # Error code and truncation flag a tool call reports to the usage log
│ ├── UsageEvent.cs # Anonymized session, load, and tool call event models
│ ├── UsageLogFile.cs # Daily rotating JSON Lines file store with 30-day cleanup
│ └── UsageReport.cs # Aggregated performance & error summary generator
├── ServerPermissions.cs # Read-only mode enforcement (--read-only)
├── CallerContext.cs # Identity context (local process vs remote user)
├── ErrorCodes.cs # Machine-readable error codes
└── FarolException.cs # Structured exceptions with actionable guidance
Because loading a .NET solution triggers MSBuild target evaluation and code actions write files to disk, an AI agent must never be permitted to read, execute, or overwrite files outside designated directories.
A directory is considered trusted if it matches the server's root directory (Farol:RootDirectory) or is explicitly declared in Farol:TrustedPaths.
flowchart TD
InputPath["Input path (tool argument)"] --> Rooted{"Relative, and nothing at that path under the root?"}
Rooted -- No --> FromRoot["Path from the root (or the absolute path)"]
Rooted -- Yes --> Fallback{"Exists under the workspace's folder, inside a trusted directory?"}
Fallback -- Yes --> FromWorkspace["Path from the workspace's folder (AC-42)"]
Fallback -- No --> FromRoot
FromRoot --> Canonical["PathSandbox.Canonical() (resolve .., symlinks, junctions)"]
FromWorkspace --> Canonical
Canonical --> Check{"Inside the root or Farol:TrustedPaths?"}
Check -- Yes --> Allow["Allowed: full path"]
Check -- No --> Deny["FarolException (path_not_trusted)"]
-
Symbolic Link & Junction Traversal (
Canonical): Standard .NETPath.GetFullPathdoes not resolve Windows directory junctions or symbolic links. If an attacker or malicious repository contains a junction pointing toC:\WindowsorC:\Users\username\.ssh, simple path prefix checks would fail.PathSandboxiteratively traverses each segment usingFileSystemInfo.ResolveLinkTarget(returnFinalTarget: true), protected by a recursion guard (MaxLinkDepth = 32). -
Solution-Folder Fallback Resolution (AC-42):
AI agents frequently pass relative paths assuming the working directory is the solution folder (e.g.
src/MyProject/Class.cs), even when Farol was started at a repository root above it. When a relative path names nothing under the root,PathSandbox.Resolvetries the workspace's folder, and uses that path only when it exists and is itself inside the trusted directories. -
Actionable Remediation:
When access is denied, Farol throws a
FarolExceptionwith codepath_not_trusted, saying how to trust the directory:Farol:TrustedPaths, or starting Farol with--rootabove it. -
Paths the File System Rejects (
FullPath): A file path, aworkspaceor the path in apath:linesymbol with a null character, or too long for the file system, is aninvalid_argumenterror that quotes only the first 60 characters, since such an argument can be megabytes long or binary. -
Containment Test (
IsSameOrUnder): Public, so the engine can ask whether a path is a directory or below it, also when the directory is a drive root such asD:\. Workspace resolution uses it to find the workspace that holds a file (AC-44).
Farol invokes external tools (dotnet, MSBuild.exe, vswhere.exe, vstest.console.exe) through IProcessRunner.
When running over stdio, standard input and standard output carry JSON-RPC MCP messages. If a child process were to inherit stdout, any console output from MSBuild or a compiler would corrupt the JSON stream and crash the MCP connection.
LocalProcessRunner enforces strict isolation:
-
RedirectStandardInput = true,RedirectStandardOutput = true,RedirectStandardError = true. - Standard input is immediately closed (
process.StandardInput.Close()). - Standard output and standard error are captured asynchronously line-by-line via events into thread-safe string buffers.
Every spawned process is configured with specific environment variables:
startInfo.Environment["MSBUILDDISABLENODEREUSE"] = "1"; // Prevents MSBuild worker processes from hanging around and locking files
startInfo.Environment["DOTNET_CLI_TELEMETRY_OPTOUT"] = "1"; // Disables .NET CLI telemetry
startInfo.Environment["DOTNET_NOLOGO"] = "1"; // Suppresses banner text
startInfo.Environment["DOTNET_CLI_UI_LANGUAGE"] = "en"; // Enforces English output from dotnet
startInfo.Environment["VSLANG"] = "1033"; // Enforces English output from Visual Studio toolsIf a build or test exceeds its timeout (default: 15 minutes for builds, 20 minutes for tests) or if the agent cancels the operation, calling process.Kill() is insufficient on Windows because MSBuild spawns multiple child compiler nodes (csc.exe, vbc.exe).
LocalProcessRunner terminates the process tree completely using process.Kill(entireProcessTree: true).
When an agent applies a Roslyn code action, partial writes or in-place file overwrites introduce race conditions:
- File watchers might detect an empty or half-written file.
- A crash during writing would corrupt the user's source code.
- Compilers might read incomplete syntax trees.
AtomicFile.WriteAllTextAsync resolves this:
- Writes the content to a hidden temporary file in the same directory:
.{filename}.{guid}.tmp. - Uses the atomic OS filesystem operation
File.Move(temporary, path, overwrite: true). - If an exception occurs, the temporary file is deleted in a
catchblock.
Farol formats code modifications using the standard unified diff format (3 lines of context), making changes instantly readable by LLMs and fully compatible with git apply.
-
Myers Algorithm: Implements Myers'
$O(ND)$ difference algorithm with common prefix and suffix pruning. -
Large-File Safety Guard: If the edit distance exceeds
MaxEditDistance = 2000, Farol avoids expensive quadratic path searches and falls back to hunk-based chunk replacement. -
Line Ending & EOF Normalization: Reads
\r\n,\nand\rline endings; the diff itself is written with\n. It appends\ No newline at end of filewhen appropriate.
LLMs perform best when file paths are short, clean, and consistent.
-
Root-Relative Normalization: Paths are written relative to the root Farol runs in, with forward slashes (
/) even on Windows (src/Core/Order.cs:42); a path outside the root, underFarol:TrustedPaths, is written in full. -
Folded Location Summaries (
Places): When listing multiple occurrences of a symbol across files, Farol folds repeated files into concise lines:Folder/File.cs:14, :26, Other.cs:3, … 4 more -
In-Text Sanitization (
InText): When MSBuild or Roslyn outputs compiler messages containing raw Windows absolute paths (e.g.C:\repos\App\src\A.cs(12,5): error CS0103), Farol sanitizes the message in-place, rewriting paths to root-relative form.
Context windows are a finite, expensive resource. Farol enforces token budgets on all list-producing tools:
- Default budget: 1,500 tokens (configurable up to 8,000 tokens via
maxTokens). - Estimator: Fast character-to-token ratio approximation (
$1\text{ token} \approx 4\text{ chars}$ ). - Truncation marker: When a list exceeds the budget, the output terminates cleanly with
… N moreand instructions on how to page viaoffset.
When Farol starts with --read-only, the server blocks any operation that produces side effects:
-
dotnet_code_actionswithapply=trueis refused (preview diffs still work). -
dotnet_migration_planwithwrite=trueis refused (plan viewing still works). -
dotnet_buildanddotnet_testare refused.
When refused, the tool throws a FarolException (read_only) explaining that --read-only is active and detailing alternative non-destructive actions.
Farol contains zero network telemetry; no data is ever sent to external servers. To help developers and teams track usage, performance, and reliability, Farol includes an opt-in local usage logger (--usage-log).
-
Storage Location: Stored as daily rotating JSON Lines files under
%LOCALAPPDATA%\Farol\usage\. -
Complete Anonymization:
- Solution paths are never recorded; solutions are identified solely by an 8-character SHA-256 hash of their filename.
- No source code, symbols, method names, file paths, or arguments are logged.
- Records event kind (
start,session,load,warm,call,crash), elapsed time, outcome, error code, and token budget truncation flags. A call reports its error code and truncation throughToolCallOutcome; the hook'sworkspace_ambiguousandworkspace_not_foundanswers, which are not errors to the client, are recorded this way.
- Automatic Retention: Files older than 30 days are deleted when Farol opens the log.
-
Built-in Reporting: Running
farol --usage-report [--days N]parses the local logs and prints a plain-text summary: days with use, sessions and clients, each tool's calls, errors and p50/p95 durations, errors by code and loads per solution.
Welcome to the official technical documentation for Farol, an open-source Model Context Protocol (MCP) server that equips AI coding agents (Claude Code, GitHub Copilot, Google Antigravity, Cursor, Codex) with compiler-accurate understanding of C# and VB.NET solutions.
- Home — Project overview, value proposition, quickstart, and problem statement
- 01. Architecture & Design Philosophy — Layered architecture, snapshot isolation, BuildHost model, design rationale
- 02. Layer: Farol.Core — Zero-Roslyn foundation: path sandbox, process execution, diffing, atomic writes, privacy
- 03. Layer: Farol.Engine — Workspaces & Loading — MSBuildWorkspaceLoader, analyzer copies, Visual Studio toolchain probing, background warmup, file watcher
- 04. Layer: Farol.Engine — Navigation & Markup — Compiler-accurate navigation, symbol search, IOperation classification, WebForms & XAML indexers, decompilation
- 05. Layer: Farol.Engine — Verification & Testing — Diagnostic checks in about a second, baseline fingerprinting, edits during a load, edit impact analysis, Code Actions, build & test runners
- 06. Layer: Farol.Engine — Legacy Modernization & Packages — Legacy inventory, config inspector, target surface portability, migration planner, NuGet API inspector
- 07. Layer: Farol.Tools & MCP Contract — Comprehensive reference for all 23 MCP tools, 7 prompts, the skill resources and MCP tasks
- 08. Layer: Farol.Host & CLI — Stdio transport, stream isolation, configuration precedence, privacy-first usage telemetry
- 09. Integrations & Plugins — Claude Code plugin (hook & skill), Visual Studio 2026, Copilot, Antigravity, VS Code, NuGet distribution
- 10. Benchmarks & Evals — Performance benchmarks (Umbraco & DNN Platform), evaluation suite and Phase 2 round, compiler oracle
- 11. Phase 2: Refactorings, Analyzers, Loaders & Index — Refactoring write path, analyzers in checks, heuristic and binlog loaders, persistent index, structured output, MCP Registry
- 12. Phase 3: MCP Tasks & Skills — Build, test, load and convert as MCP tasks; the playbook as three skills served by the server; exit results