aaronsb_obsidian-mcp-plugin/src/semantic/operations/shared.ts
Aaron Bockelie c2d6f8b325 refactor(router): extract vault operation into operations/ module (ADR-202, #199 stage 1)
router.ts was a 2,228-line monolith (~2.8x the 800-line threshold). Extract
the largest unit — executeVaultOperation + its helpers — into
src/semantic/operations/vault.ts behind a RouterContext interface.

- operations/router-context.ts: RouterContext (api/app/fragmentRetriever/
  validator); SemanticRouter implements it and passes itself, so shared
  state propagates with no indirection
- operations/shared.ts: Params, SearchResultItem, paramStr/Num/Bool
  (router-private → shared by all handlers)
- operations/vault.ts: executeVaultOperation + splitContent/sortFiles/
  copyFile/copyDirectoryRecursive; mechanical this.→ctx. (tsc is the
  safety net — a missed rewrite fails compile)
- router fields api/app/fragmentRetriever/validator → public readonly
- removed a fully unreachable pre-existing dead subtree (combineSearchResults,
  isDirectory, performFileBasedSearch, indexVaultFiles, getSearchWorkflowHints,
  extractContext, getFileType — zero call sites anywhere; eslint doesn't flag
  unused class methods, which hid them). ~290 dead lines gone.

router.ts 2228→988; vault.ts 948. Behaviour-preserving: tsc clean, lint at
the exact pre-existing baseline (0 errors, 5 unrelated warnings), 235/235
tests unchanged.

Staged per the issue's "extract vault first in isolation" guidance: #199
stays open for the remaining handlers (edit/view/graph/system/bases →
router thin dispatcher <300 lines). ADR-202.
2026-05-18 23:07:40 -05:00

34 lines
1 KiB
TypeScript

/**
* Shared types and param helpers for the semantic operation modules
* (extracted from router.ts — ADR-202).
*/
/** Type alias for operation parameters passed through the semantic router */
export type Params = Record<string, unknown>;
/** Search result item from vault search */
export interface SearchResultItem {
path: string;
title?: string;
score?: number;
type?: string;
context?: string;
}
/** Helper to safely extract a string from params */
export function paramStr(params: Params, key: string): string | undefined {
const val = params[key];
return typeof val === 'string' ? val : undefined;
}
/** Helper to safely extract a number from params */
export function paramNum(params: Params, key: string): number | undefined {
const val = params[key];
return typeof val === 'number' ? val : undefined;
}
/** Helper to safely extract a boolean from params */
export function paramBool(params: Params, key: string): boolean | undefined {
const val = params[key];
return typeof val === 'boolean' ? val : undefined;
}