summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-03-24 21:09:41 +0900
committerAdam Malczewski <[email protected]>2026-03-24 21:09:41 +0900
commit7ecd929a1d6dbfbf61accdf7d4236a7005ea25e4 (patch)
tree290e5d2681b4592249d881965d688b668ca1a7dc
parent4f9da71b227eefac366769c86a614ea1c0c442b1 (diff)
downloadai-pulse-obsidian-plugin-7ecd929a1d6dbfbf61accdf7d4236a7005ea25e4.tar.gz
ai-pulse-obsidian-plugin-7ecd929a1d6dbfbf61accdf7d4236a7005ea25e4.zip
fix error formatting
-rw-r--r--src/ollama-client.ts19
-rw-r--r--src/tools.ts21
2 files changed, 34 insertions, 6 deletions
diff --git a/src/ollama-client.ts b/src/ollama-client.ts
index 155df84..5cdea2b 100644
--- a/src/ollama-client.ts
+++ b/src/ollama-client.ts
@@ -82,12 +82,19 @@ const TOOL_SYSTEM_PROMPT =
"When you use the search_files tool, the results contain exact file paths. " +
"You MUST use these exact paths when calling read_file, edit_file, or referencing files. " +
"NEVER guess or modify file paths — always use the paths returned by search_files or get_current_note verbatim.\n\n" +
- "LINKING TO NOTES:\n" +
- "When you mention a note that exists in the vault, link to it using Obsidian's wiki-link syntax: [[Note Name]]. " +
- "Use the file's basename (without the .md extension and without folder prefixes) for simple links, e.g. [[My Note]]. " +
- "If you need to show different display text, use [[Note Name|display text]]. " +
- "Feel free to link to notes whenever it is helpful — for example when listing search results, suggesting related notes, or referencing files you have read or edited. " +
- "Links make your responses more useful because the user can click them to navigate directly to that note.\n\n" +
+ "LINKING TO NOTES — MANDATORY FORMAT:\n" +
+ "When referencing any note that exists in the vault, you MUST use Obsidian wiki-link syntax.\n" +
+ "FORMAT: [[exact file path without .md extension]]\n" +
+ "RULES:\n" +
+ "1. ALWAYS use the full vault-relative path minus the .md extension.\n" +
+ " Example: a file at 'projects/2024/my-note.md' MUST be linked as [[projects/2024/my-note]].\n" +
+ "2. NEVER use just the basename when the file is inside a subfolder.\n" +
+ " WRONG: [[my-note]] CORRECT: [[projects/2024/my-note]]\n" +
+ "3. For files in the vault root (no folder), use just the name: [[my-note]].\n" +
+ "4. NEVER include the .md extension in the link: WRONG: [[my-note.md]] CORRECT: [[my-note]]\n" +
+ "5. To show different display text, use a pipe: [[projects/2024/my-note|My Note]].\n" +
+ "6. Get the exact path from search_files, read_file, or get_current_note output, strip the .md extension, and use that as the link target.\n" +
+ "7. Link to notes whenever helpful — search results, related notes, files you read or edited. Links let the user click to navigate directly.\n\n" +
"EDITING FILES — MANDATORY WORKFLOW:\n" +
"The edit_file tool performs a find-and-replace. You provide old_text (the exact text currently in the file) and new_text (what to replace it with). " +
"If old_text does not match the file contents exactly, the edit WILL FAIL.\n" +
diff --git a/src/tools.ts b/src/tools.ts
index 9bc2f53..56236de 100644
--- a/src/tools.ts
+++ b/src/tools.ts
@@ -42,6 +42,10 @@ export interface ToolEntry {
async function executeSearchFiles(app: App, args: Record<string, unknown>): Promise<string> {
const query = typeof args.query === "string" ? args.query.toLowerCase() : "";
if (query === "") {
+ // Detect common misuse: model passed batch_search_files params to search_files
+ if (args.queries !== undefined) {
+ return "Error: query parameter is required. You passed 'queries' (plural) — use search_files with a single 'query' string, or use batch_search_files for multiple queries.";
+ }
return "Error: query parameter is required.";
}
@@ -138,6 +142,9 @@ async function executeDeleteFile(app: App, args: Record<string, unknown>): Promi
async function executeGrepSearch(app: App, args: Record<string, unknown>): Promise<string> {
const query = typeof args.query === "string" ? args.query : "";
if (query === "") {
+ if (args.queries !== undefined) {
+ return "Error: query parameter is required. You passed 'queries' (plural) — use grep_search with a single 'query' string, or use batch_grep_search for multiple queries.";
+ }
return "Error: query parameter is required.";
}
@@ -624,9 +631,15 @@ export const TOOL_REGISTRY: ToolEntry[] = [
requiresApproval: false,
summarize: (args) => {
const query = typeof args.query === "string" ? args.query : "";
+ if (query === "" && args.queries !== undefined) {
+ return "(wrong params: used 'queries' instead of 'query')";
+ }
return `"${query}"`;
},
summarizeResult: (result) => {
+ if (result.startsWith("Error")) {
+ return result;
+ }
if (result === "No files found matching the query.") {
return "No results found";
}
@@ -827,10 +840,16 @@ export const TOOL_REGISTRY: ToolEntry[] = [
summarize: (args) => {
const query = typeof args.query === "string" ? args.query : "";
const filePattern = typeof args.file_pattern === "string" ? args.file_pattern : "";
+ if (query === "" && args.queries !== undefined) {
+ return "(wrong params: used 'queries' instead of 'query')";
+ }
const suffix = filePattern !== "" ? ` in "${filePattern}"` : "";
return `"${query}"${suffix}`;
},
summarizeResult: (result) => {
+ if (result.startsWith("Error")) {
+ return result;
+ }
if (result === "No matches found.") {
return "No results found";
}
@@ -1031,6 +1050,7 @@ export const TOOL_REGISTRY: ToolEntry[] = [
return `${count} search quer${count === 1 ? "y" : "ies"}`;
},
summarizeResult: (result) => {
+ if (result.startsWith("Error")) return result;
const sections = result.split("--- Query").length - 1;
return `${sections} search${sections === 1 ? "" : "es"} completed`;
},
@@ -1066,6 +1086,7 @@ export const TOOL_REGISTRY: ToolEntry[] = [
return `${count} content search${count === 1 ? "" : "es"}`;
},
summarizeResult: (result) => {
+ if (result.startsWith("Error")) return result;
const sections = result.split("--- Query").length - 1;
return `${sections} search${sections === 1 ? "" : "es"} completed`;
},