5.9 KiB
5.9 KiB
AGENTS.md — envsitter-guard
This repository is a minimal TypeScript plugin meant to run under OpenCode (@opencode-ai/plugin).
Repo layout
index.ts: main plugin implementation (EnvSitterGuard).tsconfig.json: TypeScript config (strict,noEmit)..opencode/: OpenCode packaging/runtime wrapper..opencode/plugin/envsitter-guard.tsre-exports the plugin fromindex.ts..opencode/bun.lockindicates Bun-managed deps inside.opencode/.
node_modules/: vendored deps (present locally; do not edit).
Commands (build / lint / test)
Install
-
Root install (lockfile:
package-lock.json):npm cinpm install(ok for local dev;npm cipreferred for reproducibility)
-
.opencode/install (Bun lockfile present):- If you need to refresh
.opencode/node_modules, use Bun from.opencode/:cd .opencode && bun install
- If Bun is unavailable, do not guess; ask before changing
.opencode/dependency management.
- If you need to refresh
Build / typecheck
This repo does not emit JS as part of its normal workflow.
- Typecheck (canonical):
npm run typecheck- Equivalent:
npx tsc -p tsconfig.json
Lint / format
- No linting or formatting commands are configured in the root project.
- No
.eslintrc*,eslint.config.*,biome.json, or Prettier config exists at repo root. - Do not introduce new linters/formatters unless explicitly requested.
Tests
Tests use Node’s built-in test runner, compiled via tsc into dist-test/.
- Run all tests (builds then runs):
npm test
- Build test output only:
npm run build:test
- Run a single test file:
npm run build:test && node --test dist-test/test/envsitter-guard.hook.test.js
Pre-commit checks are enforced via Husky:
npm installinstalls the git hook..husky/pre-commitrunsnpm run typecheckandnpm test.
TypeScript / module conventions
- ESM project:
package.jsonhas"type": "module". - TS config:
module: "NodeNext",moduleResolution: "NodeNext",target: "ES2022",strict: true,noEmit: true. - Prefer
import type { ... }for type-only imports (seeindex.ts). - Prefer
node:specifier for Node built-ins (e.g.import path from "node:path").
Formatting conventions (match existing code)
- Indentation: 4 spaces.
- Quotes: double quotes.
- Semicolons: required.
- Trailing commas: used in multiline objects/args.
- Keep functions small and single-purpose (see path validation helpers in
index.ts).
Naming conventions
camelCase: functions, locals, parameters.PascalCase: exported plugin symbol (EnvSitterGuard).- Booleans use
is*/has*prefixes (e.g.isSensitiveDotEnvPath).
Error handling & validation
This plugin is security-sensitive. Follow these patterns:
- Prefer early validation +
throw new Error("...")with a clear, user-facing message. - Avoid swallowing errors (no empty
catchblocks). - Avoid
anyand type suppression (as any,@ts-ignore,@ts-expect-error). - When parsing unknown inputs, narrow types explicitly (e.g.
typeof args === "object", then access viaRecord<string, unknown>).
Security & secrets
- Do not read or print
.envvalues. - Treat
.env.secureas sensitive; never commit secrets. - This repo’s plugin is designed to block sensitive
.env*and.envsitter/pepperaccess via tooling and to guide users toward safe inspection:envsitter_keys(lists keys only)envsitter_fingerprint(hash/fingerprint only)
Working with .opencode/
.opencode/is a packaging/runtime layer for OpenCode plugins; treat it as part of the deployment surface.- Keep
.opencode/plugin/envsitter-guard.tsas a thin re-export (do not add logic there). - Avoid editing
.opencode/node_modulesdirectly.
Change discipline
- Prefer minimal diffs; avoid refactors during bugfixes.
- Keep behavior consistent with
index.tspatterns:- normalize paths before regex matching
- ensure file paths stay within
worktree - throttle UI toasts (
lastToastAtpattern)
Plugin behavior notes
- OpenCode entrypoint is
EnvSitterGuardexported fromindex.ts. - Plugin registration file
.opencode/plugin/envsitter-guard.tsmust remain a thin re-export. - Tool surface area intentionally small:
envsitter_keys: lists keys only (no values)envsitter_fingerprint: deterministic fingerprint of a single key (no value)
- Blocking behavior is enforced in
"tool.execute.before":- Blocks reads of
.env*(except.env.example). - Blocks edits/writes/patching of
.env*and.envsitter/pepper. - Throttles UI toasts via
lastToastAt.
- Blocks reads of
Path handling rules
- Treat all incoming tool args as untrusted.
- Normalize path separators before matching (Windows
\\→/). - Validate allowed paths before resolving to absolute paths.
- Ensure resolved paths stay within
worktreeusingpath.relative()checks.
Output conventions
- Prefer returning structured JSON via
JSON.stringify(obj, null, 2). - Never include secret values in output strings, prompts, or toast messages.
- Errors should be user-facing and actionable (what was blocked + safe alternative).
Dependency & change policy
- Keep this repo minimalist: prefer existing dependencies over adding new ones.
- Do not change
.opencode/dependency management unless you know the OpenCode packaging constraints. - Never edit vendored
node_modules/or.opencode/node_modules/.
Repo hygiene
- When searching the codebase, exclude
node_modules/and.opencode/node_modules/unless you are explicitly auditing dependency behavior. - Do not add new config files (ESLint/Prettier/Biome/etc.) unless explicitly requested.
Verification checklist
npm run typecheckpasses.- No tool path allows reading raw
.env*values. .opencode/plugin/envsitter-guard.tsremains a re-export only.- Error messages remain clear and do not leak file contents.
Cursor / Copilot rules
- No
.cursor/rules/,.cursorrules, or.github/copilot-instructions.mdwere found in this repository.