mirror of
https://github.com/mssoftjp/obsidian-voice-input.git
synced 2026-07-22 06:44:48 +00:00
9.5 KiB
9.5 KiB
Repository Guidelines
Project Structure & Module Organization
- Source:
src/(TypeScript). Key areas:plugin/(entry/commands/ribbon),views/(VoiceInputViewand other UI/Actions),core/(audio/VAD/transcription),config/,utils/,interfaces/,settings/,security/. - Assets:
src/lib/fvad-wasm/{fvad.wasm,fvad.js}(copied during build). Keep generated binaries insidebuild/<version>/. - Build output:
build/latest/andbuild/YYYYMMDD_HHMMSS/(snapshots). Release bundles includemain.js,manifest.json, optionalstyles.css, and wasm/binary assets. - Root holds
manifest.json,package.json; usetmp/only for short-lived review artifacts and clean it up. - Tests:
tests/(Jest + jsdom). Mirrors thesrc/layout.
Build, Test, and Development Commands
npm ci: clean install dependencies.npm run dev: local development with esbuild watch.npm run build:tsc -noEmit -skipLibCheck+ esbuild, outputs tobuild/.npm run build-plugin: runnpm run buildthen post-build steps to populatebuild/latest/and snapshot.npm run check:npm run lintthennpm run build.npm run deploy-local: after build, deploy to detected Obsidian vaults.npm test: run Jest tests. Optional:npm test -- --runTestsByPath <file>.npm run analyze:unused: output unused file list from the esbuild dependency graph.npm run lint/npm run lint:fix: lint TypeScript sources.
Coding Style & Naming Conventions
- Language: TypeScript (ES2018), 2-space indent. Prefer explicit types and interfaces. Avoid
anyand non-null!. - Do not mutate shared config constants; derive overrides via helpers (e.g.,
getModelConfig). - Lint: ESLint (
@typescript-eslint). Example:npm run lint. - Modules: barrel-export per folder via
index.ts. - Naming: classes
PascalCase; functions/variablescamelCase. Files follow existing pattern (class filesPascalCase.ts; folders lowercase). - Comments only for non-obvious logic.
Lint & Static Analysis
- Pin
eslint-plugin-obsidianmdto the CI version and ensureeslint.config.mjsloads it; update the plugin and config together. - After
npm run build-plugin, runnpm run check:artifactsto sanity-checkbuild/latest/(required files, manifest JSON, and high-risk patterns) instead of linting minifiedmain.js. - Keep TS strict flags:
noImplicitAny,noFallthroughCasesInSwitch,noImplicitOverride(considernoUncheckedIndexedAccesswhen helpful). - Prefer a single enum in comparisons/switch; use
assertUnreachablefor exhaustiveness. - Track Obsidian API changes and replace deprecated APIs (e.g.,
getFilename). - Lint imported templates/generated code immediately and clear warnings before merging.
- Prefer CSS files over inline styles; class names/IDs must be plugin-prefixed to avoid clashes.
- Use
getLanguage()for locale; avoid browser-only globals in mobile builds.
Testing Guidelines
- Framework: Jest (
jest-environment-jsdom). - Location:
tests/**mirrorssrc/**. Naming uses*.test.ts; keep each suite focused. - Execution:
npm test. Add tests focused on audio/VAD/transcription, controller/storage paths, and settings migration logic.
Commit & Pull Request Guidelines
- Commits: Conventional Commits; short and imperative (e.g.,
fix: ...,chore(css): ...,refactor(http): centralize requestUrl,style(lint): add EOF newlines). - PRs: include summary/background; attach screenshots or GIFs for UI changes; link related issues; add manual-test notes (e.g., deploy path) and relevant logs for UI/build changes. Ensure
npm run lint,npm test, andnpm run build-pluginpass. - Do not run
git push; the user will push at their discretion.
Pre-PR Checklist
npm run lint(witheslint-plugin-obsidianmd).npm testpasses.npm run build-plugin.npm run check:artifacts(ornpm run check:prepr).- Re-check
obsidian-developer-docs/en/Obsidian October plugin self-critique checklist.md. - Any allowed
anyis justified in code comments or PR notes. - Confirm new/changed commands avoid default hotkeys and commandId/name duplication.
Security & Configuration Tips
- Never commit API keys; store them encrypted in plugin settings. Obsidian fetches only
main.js,manifest.json,styles.css; bundle wasm/binary assets (e.g.,fvad.wasm) with releases. - For network requests, use Obsidian
requestUrlviaObsidianHttpClient. - Do not commit
build/output. For local verification usenpm run deploy-local.
Agent Workflow & Issue Hygiene
- Align with
.gitignore; do not expose ignored artifacts. - When creating issues, specify steps, target files/modules, settings/i18n keys, acceptance criteria.
- No branch-naming instructions needed; clarify scope with labels and tasks.
Obsidian Plugin Compliance (obsidian-developer-docs/en/Plugins)
- Submission/naming/distribution: remove placeholders; avoid extra "Obsidian" in the plugin name. Do not include plugin name or ID in command names/IDs.
main.jsonly in release assets, not in the repo.fundingUrlmust point to donation services (set if possible).minAppVersionshould be minimal. Description must be ≤250 chars, end with., no emoji, proper capitalization, start with an action verb. If using Node/Electron setisDesktopOnly: true. - General/style: use
this.app, avoid globalapp. Remove unnecessaryconsole.log. No default hotkeys. Do not override core styles (use custom classes + CSS variables). No inline styles in JS/HTML. Replace deprecated APIs flagged by IDE strikeouts. Split largemain.ts. Namespace selectors with a plugin prefix; prefer CSS over JS styling; use Lucide icons viasetIcon/addIcon(≤ v0.446.0) with custom SVG viewBox0 0 100 100when needed. - Security/disclosure: In README disclose payments/accounts/network/external files/ads/telemetry/closed source, etc. Keep dependencies minimal (less is safer). No client-side telemetry. Commit package manager lock file.
- UI/settings text: enforce sentence case. Only add setting headings when multiple sections; do not include words like "settings/option". Use
Setting#setHeadinginstead of<h1>. No default hotkeys. Choose command callback type appropriately (callback/checkCallback/editorCallback/editorCheckCallback). - DOM/resources: do not use
innerHTML/outerHTML/insertAdjacentHTML; assemble withcreateEletc. Register events/intervals withregisterEvent/registerIntervaland release on unload. Classnames/IDs in DOM must be plugin-prefixed. - Workspace/view: register custom views with
registerView; do not hold references (usegetLeavesOfTypeas needed). Avoid directworkspace.activeLeaf; usegetActiveViewOfType/activeEditor. Do not manually detach leaves inonunload. - Vault/editor/API: resolve paths via
plugin.manifest.dir; avoid hardcoded.obsidian. Use Editor API for active edits,Vault.processfor background; useFileManager.processFrontMatterfor frontmatter. UsetrashFileto respect user settings when deleting. Store plugin data withloadData/saveData. Prefer Vault API over Adapter API; locate withgetFileByPathetc., avoid full scans. AlwaysnormalizePath. Bundle images/icons locally; avoid remote CDNs. - Mobile compatibility: if
isDesktopOnly: false, do not require Node modules at top level (guard withPlatform.isDesktopAppand dynamic require). Avoidprocess.platform; usePlatform. DetermineVault.adapterviainstanceof FileSystemAdapter(mobile usesCapacitorAdapter). UserequestUrlinstead offetch/axios.get. Beware iOS <16.4 lacking regex lookbehind support. Avoid browser-only globals; status bar items are not available on mobile. - Performance: initialize startup code with
workspace.onLayoutReady()when possible. Avoid repo-wide path scans. Minifymain.jsfor release. Useimport { moment } from 'obsidian'. Add DeferredViews support if needed for 1.7.2+ compatibility. Continually optimize load times. - Data/sync: keep user data in
saveData()/data.jsonunless intentionally unsynced; document any external files written. Do not store secrets. - TypeScript/coding: use
const/let; forbidvar. Preferasync/awaitover promise chains. Avoid globals; avoidas anywith proper typing. Before casting, check withinstanceof.
Development Workflow Guardrails
- Before coding: skim
obsidian-developer-docs/en/Home.mdand.../Developer policies.mdto align with current Obsidian plugin rules. - Keep
obsidian-developer-docs/en/Obsidian October plugin self-critique checklist.mdopen during implementation; use it mid-task (CSS namespacing, API choices, path handling, lifecycle cleanup, etc.) and consult on every change. - Re-check the checklist before opening a PR to avoid reviewer reminders; if a rule must be bent, note the rationale in the PR description.
- Treat this section and
obsidian-developer-docs/as the single source of truth; update both when guidelines change so they never diverge.
Communication Preference
- Respond to the user in Japanese for all interactions; internal reasoning language is unrestricted.
Attitude & Quality Bar
- Default to reviewer mindset: proactively surface issues, edge cases, and guideline gaps before they are reported back to us.
- Treat guideline compliance (Obsidian docs, repo rules) as part of “done”; don’t weaken lint/rules to fit code—fix code instead.
- Favor minimal noise: concise status, clear next steps, and verify with lint/tests/builds after impactful changes.
- Assume logs and console noise matter: prevent recurring warnings/errors rather than muting them.