/** * @fileoverview Vault path resolution helpers. Two layered behaviors: * * 1. **Case-insensitive fallback.** If a path lookup 404s, list the parent * directory and look for a single case-insensitive filename match. If * found, retry against the canonical filesystem path (matches v2.x * behavior) and report the path that was asked for as `requestedPath`, so * the caller can disclose the substitution. The fallback is reachable on * every host: the plugin's `note+json` and document-map reads resolve * through Obsidian's case-sensitive vault index even on a case-insensitive * filesystem (macOS, Windows). Only the raw-markdown read case-folds there, * answering 200 for a wrong-case path before any fallback runs. * * 2. **"Did you mean" suggestions.** When no case match exists but the parent * directory has near-matches (e.g., extension-stripped variants), re-throw * NotFound enriched with the candidates in the message and * `error.data.suggestions[]`. * * 3. **Case-variant naming on writes.** A whole-file write never substitutes * a path, but on a case-insensitive filesystem a write to a case variant of * an existing note is refused (`case_variant_exists`); the same listing * names the note it collided with as `existingPath`. * * `obsidian_get_note` and `obsidian_open_in_ui` wrap their service calls with * `withCaseFallback`; writes and deletes match the exact path. * @module mcp-server/tools/definitions/_shared/suggest-paths */ import type { Context } from '@cyanheads/mcp-ts-core'; import { type ObsidianService } from '../../../../services/obsidian/obsidian-service.js'; import type { NoteTarget } from '../../../../services/obsidian/types.js'; /** Outcome of {@link withCaseFallback}; `requestedPath` is present only when another path was read. */ export type CaseFallback = { result: T; resolvedPath: string | undefined; requestedPath?: never; } | { result: T; resolvedPath: string; requestedPath: string; }; /** * Wrap a service call with case-insensitive path fallback and "did you mean" * enrichment. Non-path targets pass through — their paths are resolved * upstream, so neither layer applies. * * For path targets: * - **Exact match** → returns `{ result, resolvedPath: target.path }`. * - **Single case match** → retries with the canonical path and returns * `{ result, resolvedPath: , requestedPath: target.path }`. * - **Multiple case matches** → throws `Conflict` with the candidates so the * agent can disambiguate. * - **No case match, extension-stripped near-matches** → throws `NotFound` * enriched with a "did you mean" hint and `suggestions[]`. * - **No matches at all** → re-throws the original NotFound unchanged. * * `resolvedPath` is `undefined` for non-path targets — callers derive the * canonical path from the result itself (typically `NoteJson.path`). * `requestedPath` is present only on the single-case-match branch. */ export declare function withCaseFallback(ctx: Context, svc: ObsidianService, target: NoteTarget, fn: (target: NoteTarget) => Promise): Promise>; /** * A not-found `message` with `suggestions` appended as a "did you mean" * question. The message's trailing whitespace, and one `.`, `!`, or `?` before * it, are dropped first: what `/[.!?]?\s*$/` drops, in time linear in the * message, where the regex retries at every whitespace run inside it. */ export declare function didYouMean(message: string, suggestions: readonly string[]): string; /** * Disclose a `withCaseFallback` substitution on the caller's enrichment: the * `requestedPath` field plus a one-line notice naming both paths. `action` is * what the tool did with the canonical file. Returns the notice — `notice` is * last-wins, so a caller that sets another one must fold this text into it — * or `undefined` when nothing was substituted. */ export declare function discloseCaseSubstitution(ctx: Context, fallback: CaseFallback, action: 'read' | 'opened'): string | undefined; /** * List the parent directory of `path` and return up to {@link MAX_SUGGESTIONS} * close-match candidates. Match order: case-insensitive equality first, then * extension-stripped equality. Returns `[]` on listing failure or empty * basename. Used by callers that need suggestions without substituting a * match (e.g., `obsidian_delete_note`'s exact-case miss, which names the * candidates but never deletes one in place of the requested path). */ export declare function findSimilarPaths(ctx: Context, svc: ObsidianService, path: string): Promise; /** What the parent folder listing shows about the spelling of a path. */ export interface CaseVariants { /** The path itself is listed under exactly that name. */ exact: boolean; /** Listed files whose names equal the path's ignoring case, but not exactly (full vault paths). */ variants: string[]; } /** * Read the parent folder listing for files that differ from `path` only in * letter case. A listing that fails, or that the read scope withholds, reads * as empty, so no path outside the read scope is ever named; the caller's * cancellation propagates as itself. */ export declare function findCaseVariants(ctx: Context, svc: ObsidianService, path: string): Promise; /** * Message, error data, and `literals` for a `case_variant_exists` refusal. * `existingPath` is set only when exactly one variant is listed — never picked * from several, and never inferred when none is: a file Obsidian does not * index (a dot-file) refuses a write the same way and never appears in a * listing. It is the path the caller sends back, so it is the one literal. */ export declare function caseVariantError(path: string, variants: readonly string[]): { data: { path: string; existingPath?: string; }; literals: string[]; message: string; }; /** * Run a whole-file write to `path`, and when the service refuses it as * `case_variant_exists`, rethrow it naming the existing note from the parent * listing. The listing is read only on that failure, so a write that succeeds * costs no extra request. */ export declare function withCaseVariantNamed(ctx: Context, svc: ObsidianService, path: string, write: () => Promise): Promise; //# sourceMappingURL=suggest-paths.d.ts.map