UNPKG

knowhub

Version:

Synchronize AI coding–agent knowledge files (rules, templates, guidelines) across your project.

68 lines • 2.55 kB
import { stat } from "node:fs/promises"; import { resolve } from "node:path"; import { handleNodeError } from "../../errors.js"; import { PluginConfigurationError, PluginError } from "../errors.js"; /** * Plugin for handling local filesystem resources * This maintains backward compatibility with existing `path` resources */ export class LocalPlugin { name = "local"; version = "1.0.0"; description = "Fetch files and directories from local filesystem"; schema = { type: "object", properties: { path: { type: "string", description: "Local filesystem path (file or directory)", }, symlink: { type: "boolean", description: "Whether to create symlinks instead of copying", default: false, }, }, required: ["path"], additionalProperties: false, }; async validate(config) { if (!config || typeof config !== "object") { throw new PluginConfigurationError(this.name, "config", "must be an object"); } const localConfig = config; if (typeof localConfig.path !== "string" || localConfig.path.length === 0) { throw new PluginConfigurationError(this.name, "path", "must be a non-empty string"); } } async fetch(config, context) { await this.validate(config); const localConfig = config; const absolutePath = resolve(context.projectRoot, localConfig.path); try { const stats = await stat(absolutePath); const isDirectory = stats.isDirectory(); return { localPath: absolutePath, isDirectory, metadata: { lastModified: stats.mtime, version: stats.mtime.toISOString(), symlink: localConfig.symlink || false, }, }; } catch (error) { try { handleNodeError(error, localConfig.path, "access local path"); } catch (handledError) { const errorMessage = handledError instanceof Error ? handledError.message : String(handledError); throw new PluginError(`Failed to access local path "${localConfig.path}": ${errorMessage}`, this.name, handledError instanceof Error ? handledError : undefined); } } } } //# sourceMappingURL=local.js.map