mirror of
https://github.com/wesammustafa/opencode-primer.git
synced 2026-11-20 12:23:15 +00:00
This repo doubles as a fully-configured OpenCode project so readers can see real files instead of abstract format docs. Agents (.opencode/agents/, OpenCode YAML + markdown body): - code-reviewer.md — read-only subagent, glob-gated bash perms, Severity/Where/Why/Fix output format. Rewrites the pre-refactor file which used incorrect frontmatter shape (no YAML, claude-sonnet-4.6 as bare ID, made-up tool keys). - security-auditor.md — OWASP-focused review subagent, deny edit, ask bash, CWE-aware output template. Commands (.opencode/commands/): - review.md, pr.md, test.md, optimize.md — uses real placeholders ($ARGUMENTS, @file, !shell), points the right agent at each task. Plugins (.opencode/plugins/): - protect-secrets.js — blocks tool calls touching .env*, secrets/, credentials*, SSH keys, .npmrc, .pypirc. Pure JS, no deps. - audit-log.js — appends one JSON line per successful tool call to .opencode/audit.jsonl (also added to .gitignore). - README.md — how to install/disable, sample audit-log line, link to docs/plugins.md. Skills (.opencode/skills/git-release/SKILL.md): - Proper folder-with-SKILL.md format. Trigger-shaped description so the model actually loads it when the conversation touches release prep.
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
// .opencode/plugins/audit-log.js
|
|
//
|
|
// Append a JSONL record of every successful tool call to .opencode/audit.jsonl.
|
|
// Useful as an after-the-fact paper trail of what the agent did this session.
|
|
//
|
|
// Toggle off by deleting this file or by gating with an env var:
|
|
// if (process.env.OPENCODE_DISABLE_AUDIT_LOG) return {};
|
|
|
|
import { appendFile, mkdir } from "node:fs/promises";
|
|
import { dirname, join } from "node:path";
|
|
|
|
export const AuditLog = async ({ directory }) => {
|
|
const logPath = join(directory, ".opencode", "audit.jsonl");
|
|
// Make sure .opencode/ exists in case this plugin runs in a fresh project
|
|
await mkdir(dirname(logPath), { recursive: true });
|
|
|
|
return {
|
|
event: async ({ event }) => {
|
|
if (event?.type !== "tool.execute.after") return;
|
|
|
|
const record = {
|
|
ts: new Date().toISOString(),
|
|
tool: event.tool,
|
|
ok: !event.error,
|
|
// Capture small inputs only — full inputs can be huge (file content, diffs)
|
|
input_keys: event.input ? Object.keys(event.input) : [],
|
|
// Truncate long error messages
|
|
error: event.error
|
|
? String(event.error).slice(0, 240)
|
|
: undefined,
|
|
};
|
|
|
|
await appendFile(logPath, JSON.stringify(record) + "\n");
|
|
},
|
|
};
|
|
};
|
|
|
|
export default AuditLog;
|