diff options
Diffstat (limited to '.rules')
| -rw-r--r-- | .rules/changelog/2026-03/28/03.md | 32 | ||||
| -rw-r--r-- | .rules/changelog/2026-03/28/04.md | 37 | ||||
| -rw-r--r-- | .rules/default/project_conventions.md | 100 |
3 files changed, 169 insertions, 0 deletions
diff --git a/.rules/changelog/2026-03/28/03.md b/.rules/changelog/2026-03/28/03.md new file mode 100644 index 0000000..ed76953 --- /dev/null +++ b/.rules/changelog/2026-03/28/03.md @@ -0,0 +1,32 @@ +# Changelog — 2026-03-28 — 03 + +## Context Separation: Extract all AI context into JSON files + +### Summary +Extracted all hardcoded AI prompts, tool definitions, tool metadata, and vault context templates from TypeScript source code into standalone JSON files under `src/context/`. This makes all AI-facing context easily discoverable and editable without needing to understand TypeScript. + +### New Files +- `src/context/system-prompt.json` — structured system prompt (tool instructions, linking rules, editing workflow, batch tools, etc.) +- `src/context/vault-context-template.json` — template for formatting vault context into the system prompt +- `src/context/tools/search-files.json` — search_files tool definition + metadata +- `src/context/tools/read-file.json` — read_file tool definition + metadata +- `src/context/tools/delete-file.json` — delete_file tool definition + metadata +- `src/context/tools/get-current-note.json` — get_current_note tool definition + metadata +- `src/context/tools/edit-file.json` — edit_file tool definition + metadata +- `src/context/tools/grep-search.json` — grep_search tool definition + metadata +- `src/context/tools/create-file.json` — create_file tool definition + metadata +- `src/context/tools/move-file.json` — move_file tool definition + metadata +- `src/context/tools/set-frontmatter.json` — set_frontmatter tool definition + metadata +- `src/context/tools/batch-search-files.json` — batch_search_files tool definition + metadata +- `src/context/tools/batch-grep-search.json` — batch_grep_search tool definition + metadata +- `src/context/tools/batch-delete-file.json` — batch_delete_file tool definition + metadata +- `src/context/tools/batch-move-file.json` — batch_move_file tool definition + metadata +- `src/context/tools/batch-set-frontmatter.json` — batch_set_frontmatter tool definition + metadata +- `src/context/tools/batch-edit-file.json` — batch_edit_file tool definition + metadata +- `.rules/default/project_conventions.md` — new project conventions doc (context separation is rule #1) + +### Modified Files +- `tsconfig.json` — added `resolveJsonModule: true` +- `src/ollama-client.ts` — imports system-prompt.json, builds TOOL_SYSTEM_PROMPT from structured JSON via `buildToolSystemPrompt()` +- `src/vault-context.ts` — imports vault-context-template.json, uses template to format vault context +- `src/tools.ts` — imports all 15 tool JSON files, TOOL_REGISTRY spreads JSON context and only defines runtime callbacks inline diff --git a/.rules/changelog/2026-03/28/04.md b/.rules/changelog/2026-03/28/04.md new file mode 100644 index 0000000..075e6eb --- /dev/null +++ b/.rules/changelog/2026-03/28/04.md @@ -0,0 +1,37 @@ +# Changelog — 2026-03-28 #04 + +## Summary + +Added Obsidian Markdown rules context, strengthened system prompt to improve AI tool usage behavior, and fixed "search first" bias. + +## New Files + +- **`src/context/obsidian-markdown-rules.json`** — Obsidian-specific Markdown syntax reference (wikilinks, embeds, block identifiers, frontmatter/properties, tags, callouts, highlights, comments, task lists, numbered list rules). Trimmed to only Obsidian-unique features to minimize token usage. + +## Modified Files + +### `src/context/system-prompt.json` + +- **Intro rewritten**: Strongly instructs the AI to USE tools proactively. Explicitly says "do NOT call search_files first" and "Never say 'I don't have access'". Vault context paths should be used directly. +- **Added `confirmationLinks` section**: Requires AI to include wiki-links to affected files in task completion messages (e.g., "Created [[path/to/note]]" not just "Done"). +- **Added `embedVsCopy` section**: Clarifies that "embed" means `![[Note Name]]` syntax (Obsidian live preview), NOT reading and copying note text. "Copy" means duplicate the literal content. +- **Removed `search_files` references** from `linkingToNotes`, `editingFiles`, and `searchingContents` sections to prevent the model from searching before reading. + +### `src/ollama-client.ts` + +- Imported `obsidian-markdown-rules.json`. +- Added `buildMarkdownRulesPrompt()` function that formats the Obsidian Markdown rules JSON into a compact system prompt section. +- Added rendering for `confirmationLinks` and `embedVsCopy` sections in `buildToolSystemPrompt()`. + +### Tool JSON files (7 files) + +Removed "as returned by search_files" / "from search_files" from tool descriptions in: +- `read-file.json` +- `delete-file.json` +- `move-file.json` +- `edit-file.json` +- `set-frontmatter.json` +- `batch-delete-file.json` +- `batch-move-file.json` + +All now say "from the vault context or get_current_note" — no search prerequisite. diff --git a/.rules/default/project_conventions.md b/.rules/default/project_conventions.md new file mode 100644 index 0000000..c14b56c --- /dev/null +++ b/.rules/default/project_conventions.md @@ -0,0 +1,100 @@ +# Project Conventions — AI Pulse + +--- + +## 1. Context Separation (JSON Context Files) + +**All AI/LLM context, prompts, tool descriptions, and display text that is injected into prompts or shown to users MUST be stored in JSON files, not hardcoded in TypeScript source code.** + +This is the **most important convention** in this project. It ensures that anyone — including non-developers — can review and improve the context the AI receives without needing to understand TypeScript. + +### Directory Structure + +``` +src/context/ +├── system-prompt.json # The system prompt injected when tools are available +├── vault-context-template.json # Template for formatting vault context into the system prompt +└── tools/ # One file per tool — metadata + Ollama definition + ├── search-files.json + ├── read-file.json + ├── delete-file.json + ├── get-current-note.json + ├── edit-file.json + ├── grep-search.json + ├── create-file.json + ├── move-file.json + ├── set-frontmatter.json + ├── batch-search-files.json + ├── batch-grep-search.json + ├── batch-delete-file.json + ├── batch-move-file.json + ├── batch-set-frontmatter.json + └── batch-edit-file.json +``` + +### What Goes in JSON + +- Tool definitions sent to Ollama (name, description, parameters, parameter descriptions) +- Tool metadata shown in the UI (label, friendlyName, description) +- Tool configuration (id, requiresApproval, batchOf) +- System prompt text and structure +- Vault context formatting templates + +### What Stays in TypeScript + +- Runtime logic: `execute` functions, `summarize` callbacks, `approvalMessage` builders +- Type definitions and interfaces +- Business logic (agent loop, streaming, approval flow) + +### How to Add a New Tool + +1. Create `src/context/tools/<tool-name>.json` with id, label, description, friendlyName, requiresApproval, and the full Ollama tool definition. +2. Import the JSON in `src/tools.ts`. +3. Add a `TOOL_REGISTRY` entry that spreads the JSON context and adds only the runtime callbacks (`summarize`, `summarizeResult`, `execute`, and optionally `approvalMessage`). + +### How to Edit Context + +To change what the AI "knows" or how it behaves: +1. Edit the relevant JSON file in `src/context/`. +2. Rebuild. The changes are picked up automatically since JSON files are imported at build time. + +--- + +## 2. TypeScript Standards + +- **Strict mode** is enabled. See `tsconfig.json` for the full list of strict flags. +- **Never use `any`.** Use `unknown` and narrow with type guards. +- **`resolveJsonModule`** is enabled so JSON files can be imported with type safety. +- Follow the rules in `.rules/default/typescript.md` (if present) or the project's `.cursorrules`. + +--- + +## 3. File Organization + +| Directory | Purpose | +|-----------|---------| +| `src/` | All TypeScript source code | +| `src/context/` | JSON context files (prompts, tool definitions, templates) | +| `src/context/tools/` | One JSON file per tool | +| `.rules/` | Project rules, docs, and changelog | +| `.rules/default/` | Convention documents | +| `.rules/docs/` | API reference documentation | +| `.rules/changelog/` | Change history | + +--- + +## 4. Build System + +- **esbuild** bundles everything (including JSON imports) into `main.js`. +- JSON imports are resolved at build time — no runtime file reads needed. +- Run `npm run dev` for watch mode, `npm run build` for production. + +--- + +## 5. Naming Conventions + +- Tool JSON files: `kebab-case.json` matching the tool id with underscores replaced by hyphens (e.g. `search_files` → `search-files.json`). +- TypeScript files: `kebab-case.ts`. +- Interfaces: `PascalCase`. +- Functions and variables: `camelCase`. +- Constants: `UPPER_SNAKE_CASE` for true module-level constants. |
