You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add security checklist for module-loading and dynamic execution.
Provide guidance for inspecting build metafiles when bundle or
dependency changes increase bundle size.
- Add security checklist to `AGENTS.md` and instruction files.
- Add metafile / bundle-size guidance for production builds.
- Clarify localization notes and slow/flaky test guidance.
- Update TypeScript and commit-message instructions with examples.
Keeps agent and contributor guidance up to date.
Copy file name to clipboardExpand all lines: .github/instructions/agents.instructions.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,12 +16,14 @@ This short guide contains focused rules and examples to help AI coding agents ma
16
16
- Reuse `PluginLocales` (`assets/locales.ts`) for translation resources and formatters.
17
17
- Build & scripts:
18
18
-`scripts/build.mjs` uses esbuild `context()`; production builds write `metafile.json`. Use `process.argv[2] === 'dev'` to enable watch mode (tests mock this behavior in `tests/scripts/build.test.mjs`).
19
+
- Metafile guidance: production builds emit `metafile.json`. After dependency or bundle changes, inspect `metafile.json` for large/new imports, attach it to the PR when relevant, and add a short rationale if the bundle grows significantly.
19
20
-`scripts/obsidian-install.mjs` reads `manifest.json` for `id` and copies `manifest`, `main`, and `styles` to `<dest>/.obsidian/plugins/<id>`; it exits non-zero with a concise message when the manifest is missing—mirror these behaviors in integration tests (`tests/scripts/obsidian-install.test.mjs`).
20
21
- Tests & naming:
21
22
- Unit tests: `*.spec.*` — fast, hermetic, BDD-style.
22
23
- Integration tests: `*.test.*` — TDD-style; may use tmp dirs, child processes, or spawn/exec like `obsidian-install` tests.
23
24
- Put tests under `tests/` mirroring `src/` layout. Follow the **one test file per source file** convention.
24
25
-**Agent note:** the `vitest` CLI defaults to interactive/watch mode when invoked without a subcommand. Agents must use `vitest run <options>` or append `--run` so tests run non-interactively.
26
+
- Flaky / slow-test policy: Avoid adding slow or flaky tests to the default suite. Mark slow or long-running tests clearly (place under `tests/slow/`, add a `.slow` suffix, or document in the test header), include a justification in the PR description, and add a separate integration-only run where appropriate. CI maintainers may request you to split, mock, or move tests out of the default fast suite.
25
27
- Localization:
26
28
- Add keys by editing `assets/locales/en/translation.json` first. Keep `{{...}}` and `$t(...)` intact and **do not** translate placeholders.
27
29
- Add a test when adding user-facing strings (or a localization note) so translators and CI can detect missing or bad keys.
@@ -30,6 +32,14 @@ This short guide contains focused rules and examples to help AI coding agents ma
30
32
- Add a changeset for public API or release-impacting changes.
31
33
- When changing infra (build, tests, versioning), update `AGENTS.md` with concise rationale and local verification steps (include the exact commands you ran).
32
34
35
+
**Security note (short checklist):** edits that affect module-loading or dynamic execution (for example `src/require/**`, `eval`, or dynamic imports) are high-risk and require extra review. Quick PR checklist for these changes:
36
+
37
+
- Add unit and integration tests that validate sanitization, failure modes, and sandboxing assumptions.
38
+
- Include a short threat-model note in the PR describing attacker capabilities and mitigations.
39
+
- Tag the PR with `security` and request at least one reviewer with security expertise.
40
+
- Avoid `eval`/untrusted dynamic execution; if unavoidable, provide input validation/whitelisting and tests.
41
+
- Add manual verification steps or CI checks if loader behavior or resolution rules changed.
42
+
33
43
If anything here is unclear or incomplete, open a short issue or suggest a direct edit to `AGENTS.md` so agents that follow can stay up to date.
-**Header should be ≤ 72 characters (use 72 as a human-friendly buffer; tooling still accepts up to 100).**
44
44
-**Body lines must be hard-wrapped at 100 characters or less.** Prefer 72 for body lines intended for human readers.
45
45
- All agents and contributors must comply; see `AGENTS.md` for enforcement policy.
46
+
- Example changeset workflow (releases / public API): run `pnpm changeset` to create a changeset, choose the appropriate release type, then run `pnpm version` or `pnpm build` to verify the change.
Copy file name to clipboardExpand all lines: .github/instructions/localization.instructions.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ description: Rules for translation and localization files
15
15
16
16
## Practical guidance
17
17
18
-
- When adding a new user-facing string, add an entry in `assets/locales/en/translation.json` and add/adjust tests that reference `language.value.t('your.key')` to help detect regressions.
18
+
- When adding a new user-facing string, add an entry in `assets/locales/en/translation.json` and add/adjust tests that reference `language.value.t('your.key')` to help detect regressions. Also include a short "localization note" in the PR when adding or removing keys so translators can easily track changes and reviewers can verify intent.
19
19
- Avoid changing interpolation tokens or `$t()` usage inside translation values—these are runtime references and translators should not modify structural tokens.
20
20
- If you add a new translation key, add a short test or documentation note so CI and reviewers can validate the change.
Copy file name to clipboardExpand all lines: .github/instructions/typescript.instructions.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ description: Guidelines for TypeScript files in obsidian-plugin-template
10
10
11
11
- Use the strictest TypeScript configuration (`tsconfig.json`).
12
12
- Validate and normalize all settings and local settings via `.fix()` functions (see `src/settings-data.ts`).
13
+
- When using dynamic imports (`await import(...)`) or editing module-loading code (for example `src/require/**`), include tests and document the security rationale — see `AGENTS.md` for the Security checklist.
13
14
- Prefer type-safe patterns; **never** use the `any` type. **Prefer `unknown` over `any`.** When accepting unknown inputs, validate or narrow `unknown` with type guards or runtime validators before use. If `any` is truly unavoidable, document the reason and add a test asserting safety.
14
15
- Reference translation keys via `language.value.t(...)` or `$t(key)` in UI code. Avoid hardcoding user-facing strings.
15
16
- Use the project managers (`LanguageManager`, `SettingsManager`, `StorageSettingsManager`) as in `src/main.ts` to ensure consistent lifecycle and persistence behaviour.
@@ -19,6 +20,7 @@ description: Guidelines for TypeScript files in obsidian-plugin-template
19
20
- When creating new settings, add a `fix()` entry and default in `Settings.DEFAULT` / `LocalSettings` and add a test that validates malformed data is corrected by `fix()`.
20
21
- When writing UI code, prefer the i18n accessor from `context.language.value.t(...)` rather than importing `i18next` directly.
21
22
- For lifecycle-sensitive managers, call `.load()` and ensure `.unload()` tasks are registered (see `PLACEHOLDERPlugin.onload()` pattern in `src/main.ts`).
23
+
- Bundle / dependency changes: if a change introduces new runtime dependencies or increases bundle size, run a production build, inspect `metafile.json`, and add a short justification in the PR (attach the `metafile.json` when useful).
Copy file name to clipboardExpand all lines: AGENTS.md
+14-1Lines changed: 14 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,7 @@ This guide provides clear, actionable instructions for AI coding agents working
35
35
36
36
-**Versioning**
37
37
- Use `changesets` for PRs; version lifecycle scripts are configured (`version` / `postversion`).
38
+
- Example changeset workflow: run `pnpm changeset` to add a changeset, choose the appropriate release type, then run `pnpm version` or `pnpm build` to verify the change. Add a changeset whenever you change public APIs or prepare a release.
38
39
39
40
-**Localization**
40
41
- Add locales by copying `assets/locales/en/translation.json` and updating `assets/locales/*/language.json` as needed. See `assets/locales/README.md` for conventions.
@@ -64,6 +65,8 @@ Quick reference for scripts in `package.json`. Use `pnpm` (preferred).
64
65
65
66
> CI tip: Use `pnpm install --frozen-lockfile` in CI for deterministic installs.
66
67
68
+
- Metafile guidance: production builds write a `metafile.json` (see `scripts/build.mjs`). After significant bundle or dependency changes, inspect `metafile.json` for large/new imports and consider adding a size‑budget note or rationale in the PR if the bundle grows.
If you need help designing a test or mocking a dependency, ask for a short example to be added to `tests/fixtures/`.
121
124
125
+
### Security checklist — changes to module-loading or dynamic execution 🔐
126
+
127
+
- Scope: applies when editing `src/require/**`, dynamic loaders, `eval`, or any code that alters runtime module resolution.
128
+
- Required for PRs touching these areas:
129
+
- Add unit and integration tests that validate input sanitization, failure modes, and sandboxing assumptions.
130
+
- Provide a short threat-model note in the PR describing possible attack vectors and mitigations.
131
+
- Tag the PR with `security` and request at least one reviewer with security expertise.
132
+
- Avoid `eval`/untrusted dynamic execution; if unavoidable, document justification and show input validation/whitelisting.
133
+
- Add manual verification steps or CI checks if loader behavior or resolution rules changed.
134
+
122
135
## 3. Coding Conventions
123
136
124
137
**TypeScript Types:**
@@ -267,7 +280,7 @@ This section contains concise, actionable rules and project-specific examples to
267
280
- Start by inspecting `src/main.ts`, `src/settings-data.ts`, and `assets/locales.ts` to learn core patterns: Manager classes (LanguageManager, SettingsManager), `.fix()` validators, and `PluginLocales` usage.
268
281
- Settings pattern: always prefer `.fix()` functions (see `Settings.fix`/`LocalSettings.fix`) to validate/normalize external inputs before persisting or mutating settings.
269
282
- I18n: use `createI18n(PluginLocales.RESOURCES, ...)` and `language.value.t(...)` for translations. Never hardcode translatable strings—use existing translation keys in `assets/locales/`.
270
-
- Build/Dev pattern: `scripts/build.mjs` uses esbuild `context()`; pass `dev` as argv[2] to enable watch mode. Tests mock `esbuild` in `tests/scripts/build.test.mjs`—use those tests as canonical examples for safe refactors.
283
+
- Build/Dev pattern: `scripts/build.mjs` uses esbuild `context()`; pass `dev` as `argv[2]` to enable watch mode. Tests mock `esbuild` in `tests/scripts/build.test.mjs`—use those tests as canonical examples for safe refactors.
271
284
- Script behavior: `scripts/obsidian-install.mjs` exits 1 with a short error message when `manifest.json` is missing. Make changes in scripts with tests mirroring error conditions (see `tests/scripts/obsidian-install.test.mjs`).
272
285
- Test conventions: `*.spec.*` = unit (fast, isolated); `*.test.*` = integration (may use filesystem or child processes). Follow the one-test-file-per-source-file convention and place tests under `tests/` mirroring `src/`.
273
286
- Formatting & linting: run `pnpm run format` and `pnpm run check` before committing. CI uses `pnpm install --frozen-lockfile`.
0 commit comments