Files
opencode-primer/.opencode/plugins/protect-secrets.js
Wesam AbousaidandClaude Opus 4.8 29a69a35b0 docs: refresh for OpenCode v1.16.2 and fix correctness bugs
Update the guide to the current release (v1.16.2, 2026-06-05), verified
against opencode.ai/docs and github.com/anomalyco/opencode.

Correctness fixes:
- Plugins: tool.execute.before/after and shell.env are top-level hooks
  with an (input, output) signature, not event.type values. Rewrite both
  shipped example plugins plus the docs/migration examples so they fire.
- Permissions: bash glob maps resolve last-matching-rule-wins (catch-all
  "*" first), not most-specific-wins. Fix prose, reorder examples, and fix
  the shipped opencode.json (rm -rf* deny was shadowed by a later rm *).
- Drop non-existent permission keys repo_clone/repo_overview (15 keys, not
  17); fix steps (integer), deprecate maxSteps/tools, move reasoningEffort
  into model options; fix the `mise` install command.

Currency updates:
- v1.15.4 -> v1.16.2; add v1.16 highlights and a changelog section.
- Refresh OpenCode Zen lineup/pricing (Claude Opus 4.8, gpt-5.4,
  gemini-3.5-flash, qwen3.7, grok-build-0.1; correct free-tier IDs).
- Add `opencode mcp add`, run --replay, extra skill paths, shift+tab, and
  native GitHub commands; correct the specialist-prompt count; bump dates.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-08 19:00:39 +02:00

41 lines
1.4 KiB
JavaScript

// .opencode/plugins/protect-secrets.js
//
// Block any tool call that would read, write, or shell-touch a sensitive path
// (`.env*`, `secrets/`, `credentials*`, common SSH key files). Belt-and-braces
// on top of `external_directory: deny` and gitignore — never your only line
// of defense, but a useful one.
const SENSITIVE = /(^|\/)(\.env(\..*)?|secrets|credentials|id_rsa|id_ed25519|\.npmrc|\.pypirc)(\b|\/)/i;
// Pull the most likely path/command field out of a tool's arguments.
// `read`/`edit`/`write` use `filePath`; `bash` uses `command`; others vary.
function targetFromArgs(args) {
if (!args || typeof args !== "object") return "";
return (
args.filePath ??
args.path ??
args.file_path ??
args.target ??
args.command ?? // bash: scan the command line itself
""
);
}
export const ProtectSecrets = async () => {
return {
// `tool.execute.before` is a top-level hook with an (input, output) signature.
// `input.tool` is the tool name; `output.args` holds its (mutable) arguments.
// Throwing here aborts the tool call before it runs.
"tool.execute.before": async (input, output) => {
const candidate = targetFromArgs(output?.args);
if (candidate && SENSITIVE.test(String(candidate))) {
throw new Error(
`[protect-secrets] blocked ${input.tool} on sensitive path: ${candidate}`
);
}
},
};
};
export default ProtectSecrets;