obsidian-sdk-patterns
Production-ready Obsidian plugin patterns: typed settings with migration, safe vault operations, event auto-cleanup, workspace layout, metadata cache, and debounced file handlers. Use when hardening a plugin for release, refactoring for reliability, or learning idiomatic Obsidian TypeScript. Trigger with "obsidian patterns", "obsidian best practices", "obsidian production code", "idiomatic obsidian plugin".
What this skill does
# Obsidian SDK Patterns
## Overview
Six production patterns that prevent the most common Obsidian plugin bugs: lost
settings on upgrade, null-reference crashes on deleted files, memory leaks from
unregistered events, stale metadata, and UI jank from rapid file changes. Each
pattern is self-contained and copy-pasteable.
## Prerequisites
- A working Obsidian plugin (see `obsidian-core-workflow-a`)
- TypeScript strict mode enabled (`"strictNullChecks": true` in tsconfig)
- Familiarity with `Plugin.onload()` / `onunload()` lifecycle
## Instructions
### Step 1: Typed settings with versioned migration
Settings break when you add or rename fields between releases. Version the
settings object and migrate on load so existing users keep their data.
```typescript
// src/settings.ts
interface PluginSettingsV1 {
apiKey: string;
interval: number;
}
interface PluginSettingsV2 {
version: 2;
apiKey: string;
syncInterval: number; // renamed from "interval"
excludedFolders: string[]; // new field
theme: "default" | "minimal";
}
// Current version is always the latest
type PluginSettings = PluginSettingsV2;
const DEFAULTS: PluginSettings = {
version: 2,
apiKey: "",
syncInterval: 300,
excludedFolders: [],
theme: "default",
};
export async function loadSettings(plugin: Plugin): Promise<PluginSettings> {
const raw = (await plugin.loadData()) as any;
if (!raw) return { ...DEFAULTS };
// Migrate v1 -> v2
if (!raw.version || raw.version < 2) {
raw.version = 2;
if (raw.interval !== undefined) {
raw.syncInterval = raw.interval;
delete raw.interval;
}
raw.excludedFolders = raw.excludedFolders ?? [];
raw.theme = raw.theme ?? "default";
await plugin.saveData(raw);
}
// Merge with defaults to pick up any newly added fields
return { ...DEFAULTS, ...raw };
}
```
Why: `Object.assign({}, DEFAULTS, raw)` handles new fields added in patch
releases. The explicit migration block handles renames and type changes between
major versions.
### Step 2: Safe vault operations (check-before-act)
The Vault API throws if you create a file that exists or read one that was
deleted between your check and your call. Wrap every operation.
```typescript
// src/vault-helpers.ts
import { App, TFile, TFolder, TAbstractFile, normalizePath } from "obsidian";
export class VaultHelper {
constructor(private app: App) {}
/** Read file content, return null if file doesn't exist */
async safeRead(path: string): Promise<string | null> {
const file = this.app.vault.getAbstractFileByPath(normalizePath(path));
if (!(file instanceof TFile)) return null;
return this.app.vault.read(file);
}
/** Create or overwrite a file. Creates parent folders as needed. */
async safeWrite(path: string, content: string): Promise<TFile> {
const normalized = normalizePath(path);
await this.ensureParentFolder(normalized);
const existing = this.app.vault.getAbstractFileByPath(normalized);
if (existing instanceof TFile) {
await this.app.vault.modify(existing, content);
return existing;
}
return this.app.vault.create(normalized, content);
}
/** Append content to a file. Creates the file if it doesn't exist. */
async safeAppend(path: string, content: string): Promise<void> {
const normalized = normalizePath(path);
const existing = this.app.vault.getAbstractFileByPath(normalized);
if (existing instanceof TFile) {
const current = await this.app.vault.read(existing);
await this.app.vault.modify(existing, current + content);
} else {
await this.ensureParentFolder(normalized);
await this.app.vault.create(normalized, content);
}
}
/** Delete a file if it exists, moving to trash by default. */
async safeDelete(path: string, useTrash = true): Promise<boolean> {
const file = this.app.vault.getAbstractFileByPath(normalizePath(path));
if (!(file instanceof TFile)) return false;
if (useTrash) {
await this.app.vault.trash(file, false);
} else {
await this.app.vault.delete(file);
}
return true;
}
/** Ensure a folder (and all parents) exist. */
private async ensureParentFolder(filePath: string): Promise<void> {
const parts = filePath.split("/");
parts.pop(); // remove filename
let current = "";
for (const part of parts) {
current = current ? `${current}/${part}` : part;
const existing = this.app.vault.getAbstractFileByPath(current);
if (!existing) {
await this.app.vault.createFolder(current);
}
}
}
}
```
### Step 3: Event management with automatic cleanup
Every `this.registerEvent(...)` call in `onload()` is automatically cleaned up
when the plugin unloads. Never use raw `addEventListener` or `app.vault.on()`
without registering -- those leak.
```typescript
export default class MyPlugin extends Plugin {
async onload() {
// File events -- auto-cleaned on unload
this.registerEvent(
this.app.vault.on("create", (file) => {
if (file instanceof TFile) this.onFileCreated(file);
})
);
this.registerEvent(
this.app.vault.on("delete", (file) => {
if (file instanceof TFile) this.onFileDeleted(file);
})
);
this.registerEvent(
this.app.vault.on("rename", (file, oldPath) => {
if (file instanceof TFile) this.onFileRenamed(file, oldPath);
})
);
// Workspace events
this.registerEvent(
this.app.workspace.on("active-leaf-change", (leaf) => {
this.onActiveLeafChange(leaf);
})
);
this.registerEvent(
this.app.workspace.on("layout-change", () => {
this.onLayoutChange();
})
);
// Periodic tasks -- also auto-cleaned
this.registerInterval(
window.setInterval(() => this.periodicSync(), 60_000)
);
// DOM events -- use registerDomEvent for auto-cleanup
this.registerDomEvent(document, "keydown", (evt: KeyboardEvent) => {
if (evt.key === "F5") this.refreshData();
});
}
// No cleanup code needed in onunload() -- all registered events
// are automatically removed by the Plugin base class.
}
```
Anti-pattern to avoid:
```typescript
// BAD: leaks on plugin unload
this.app.vault.on("modify", handler);
document.addEventListener("click", handler);
// GOOD: auto-cleaned
this.registerEvent(this.app.vault.on("modify", handler));
this.registerDomEvent(document, "click", handler);
```
### Step 4: Workspace layout manipulation
Open files in specific panes, split views, and restore layout state.
```typescript
import { MarkdownView, WorkspaceLeaf } from "obsidian";
export class WorkspaceHelper {
constructor(private app: App) {}
/** Open a file in a new tab */
async openInNewTab(path: string): Promise<void> {
const file = this.app.vault.getAbstractFileByPath(path);
if (!(file instanceof TFile)) return;
const leaf = this.app.workspace.getLeaf("tab");
await leaf.openFile(file);
}
/** Open a file in a vertical split to the right */
async openInSplit(path: string): Promise<void> {
const file = this.app.vault.getAbstractFileByPath(path);
if (!(file instanceof TFile)) return;
const leaf = this.app.workspace.getLeaf("split", "vertical");
await leaf.openFile(file);
}
/** Get the currently active markdown file (or null) */
getActiveFile(): TFile | null {
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
return view?.file ?? null;
}
/** Iterate all open markdown leaves */
forEachOpenNote(callback: (file: TFile, leaf: WorkspaceLeaf) => void): void {
this.app.workspace.iterateAllLeaves((leaf) => {
if (leaf.view instanceof MarkdownView && leaf.view.file) {
callback(leaf.view.file, leaf);
}
});
}
/** Pin/unpin the active tab */
togglePin(): void {
const leaf = this.app.workspace.getLeaf();
if (leaf) {
const pinned = (leaf as any).pinned;
(leaf as any).setPinned(!pinneRelated in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.