Project Files
src / tools / read.ts
/**
* read — return the full content of a playbook document by filename.
*/
import { tool, type Tool, type ToolsProviderController } from "@lmstudio/sdk";
// @ts-ignore — zod/lib re-export chain breaks with NodeNext; runtime is fine
import { z } from "zod";
import path from "node:path";
import type { IndexManager } from "../indexManager.js";
import { formatToolMetaBlock } from "../helpers/pluginMeta.js";
export function createReadTool(
_ctl: ToolsProviderController,
index: IndexManager
): Tool {
return tool({
name: "read",
description: `Read the full content of a playbook document.
Use this tool after recall has returned a relevant hit.
Use this tool when:
- recall returned one or more matching documents and you need the actual text
- The user asks you to quote or expand on something from the playbook
Returns:
- The complete Markdown source including YAML frontmatter (title, tags, timestamps)
- Full body text without any truncation
Example:
- filename: "api-auth-notes.md" — returns the entire file
${formatToolMetaBlock()}`,
parameters: {
filename: z
.string()
.describe(
"The filename of the document to read (e.g. 'my-note.md'). Use the filename returned by recall."
),
},
implementation: async (args) => {
const filePath = path.join(index.getPlaybookDirectory(), args.filename);
let content: string;
try {
content = index.readSource(filePath);
} catch {
return `Error: File not found — "${args.filename}". Use recall to find available documents.`;
}
return content;
},
});
}