This is the project-level execution guide for Codex and other repository agents. Treat this file as the authority for build, verification, release, and repository workflow rules. [`GEMINI.md`](./GEMINI.md) remains as a background project overview and should not be rewritten to mirror this file.
## Project Overview
Notemd is an Obsidian plugin written in TypeScript. It enhances note workflows with LLM-powered processing, concept extraction, Mermaid generation/fixing, translation, web research, and custom one-click workflows.
## High-Risk Areas
These files and modules have the highest regression risk and should be treated as coupled surfaces during implementation:
-`src/main.ts`: plugin entrypoint, commands, settings loading, and task routing.
-`src/llmProviders.ts`: single source of truth for provider presets, metadata, ordering, and provider-side validation.
-`src/llmUtils.ts`: provider transport dispatch, request shaping, retry logic, and connection testing.
-`src/fileUtils.ts` and `src/searchUtils.ts`: task flows that depend on `callLLM()` behavior.
-`src/ui/NotemdSettingTab.ts`: provider settings, workflow builder, and test-connection UI.
-`src/workflowButtons.ts` and `src/ui/NotemdSidebarView.ts`: sidebar actions and custom workflow composition.
-`src/mermaidProcessor.ts`: Mermaid fix and error-detection logic.
When changing one of these areas, check whether a sibling module must also be updated.
## Build And Verification
Use these commands from repository root:
```bash
npm install
npm run build
npm test -- --runInBand
```
Verification requirements:
- Do not claim work is complete without fresh build and test output.
- Prefer `npm test -- --runInBand` for reliable local verification in this repository.
- Run targeted Jest tests first when doing TDD, then rerun the full suite before commit or release.
- Run `git diff --check` before committing to catch whitespace and patch-format issues.
### Obsidian CLI Checks
When release or integration verification is requested:
```bash
obsidian help
obsidian-cli help
```
Rules:
- Try both commands when the user asks for Obsidian CLI validation.
- If `obsidian-cli` is not installed or `obsidian` is blocked by desktop/X11 constraints, report that explicitly.
- Do not claim successful CLI validation unless the command actually executed and produced usable output.
## TDD Rules
For behavior changes, bug fixes, or new providers:
1. Write the failing test first.
2. Run the targeted test and confirm it fails for the expected reason.
3. Implement the minimal change.
4. Re-run the targeted test.
5. Re-run the full test suite.
New providers or provider-behavior changes must include tests in the relevant files:
-`src/tests/llmProviders.test.ts`
-`src/tests/llmUtilsProviderSupport.test.ts`
- Additional focused tests when adding local validation or UI-facing provider rules
## Provider Extension Rules
All new LLM providers must follow these rules:
- Add the preset to `src/llmProviders.ts`.
- Prefer transport-driven support in `src/llmUtils.ts`; do not add provider-name branching unless the transport genuinely differs.
- Set provider metadata for:
- transport
- category
- API key mode
- API test mode
- default base URL and model
- setup hint and description
- Update documentation in both `README.md` and `README_zh.md`.
- Add or update tests for provider registry coverage, runtime routing, and connection testing.
For OpenAI-compatible endpoints, default to the shared runtime unless the provider requires a dedicated protocol.
- Keep `scripts/diagnose-llm-provider.js` and `scripts/lib/llm-provider-diagnostic.js` aligned with runtime protocol behavior so real-endpoint diagnostics match plugin transport semantics.
- Keep the in-plugin settings action `Developer provider diagnostic (long request)` aligned with the same runtime protocol behavior so UI diagnostics and CLI diagnostics are comparable.
If you change any non-OpenAI-compatible LLM transport runtime (`anthropic`, `google`, `azure-openai`, or `ollama`):
- Preserve protocol-aware fallback parsing for long-running requests instead of regressing to buffered-only fallback reads.
- Keep partial parsed stream output in shared debug metadata when a fallback attempt is interrupted.
- Update `src/tests/llmUtilsProviderSupport.test.ts` to cover the affected transport on both success and interrupted-stream paths.
Every GitHub release body must be fully bilingual:
- Include one complete English section and one complete Chinese section.
- Each language section must be independently readable on its own.
- Do not publish release notes that are only Chinese, only English, or partially mixed with missing mirrored content.
- When using structured release notes, mirror the same core sections in both languages as applicable, such as Highlights, Breaking Changes, New Features, Bug Fixes, Refactors/Chores, and Contributors.
- Treat `.trellis/` as local workflow state, not as a repo-deliverable source of truth.
- Never delete, overwrite, or bulk-replace `.trellis/` during sync, merge, cleanup, release prep, or branch recovery work.
- If a mainline sync step could touch `.trellis/`, preserve the existing local copy first and keep the repo clean by ignoring it rather than removing it.
- Do not make committed tests, verification scripts, or release gates depend on `.trellis/` contents; if a workflow insight needs to affect CI or shipped documentation, mirror that truth into tracked files under the repository proper.
-`npm run chronicle:sync-repo-saga` and `npm run chronicle:update` share `.cache/repo-saga-*` state and must run serially. The script enforces `.cache/.repo-saga-execution.lock`; remove it only after verifying no repo-saga sync/update run is still active.
These instructions are for AI assistants working in this project.
This project is managed by Trellis. The working knowledge you need lives under `.trellis/`:
-`.trellis/workflow.md` — development phases, when to create tasks, skill routing
-`.trellis/spec/` — package- and layer-scoped coding guidelines (read before writing code in a given layer)
-`.trellis/workspace/` — per-developer journals and session traces
-`.trellis/tasks/` — active and archived tasks (PRDs, research, jsonl context)
If a Trellis command is available on your platform (e.g. `/trellis:finish-work`, `/trellis:continue`), prefer it over manual steps. Not every platform exposes every command.
If you're using Codex or another agent-capable tool, additional project-scoped helpers may live in:
-`.agents/skills/` — reusable Trellis skills
-`.codex/agents/` — optional custom subagents
## Subagents
- ALWAYS wait for every spawned subagent to reach a terminal status before yielding, acting on partial results, or spawning followups.
- On Codex, this means calling the `wait` tool with the subagent's thread id (requires `multi_agent_v2`). Do NOT infer completion from elapsed time.
- On Claude Code / OpenCode, this means awaiting the Task/agent tool result before continuing.
- NEVER cancel or re-spawn a subagent that hasn't finished. If a subagent appears stuck, raise the wait timeout (Codex default 30s, max 1h) before judging it broken.
- Spawn subagents automatically when:
- Parallelizable work (e.g., install + verify, npm test + typecheck, multiple tasks from plan)
- Long-running or blocking tasks where a worker can run independently
- Isolation for risky changes or checks
Managed by Trellis. Edits outside this block are preserved; edits inside may be overwritten by a future `trellis update`.