Skip to content

Commit f51fb9f

Browse files
committed
feat: add simplify built-in skill
1 parent 633b5d6 commit f51fb9f

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

packages/opencode/src/skill/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Glob } from "@opencode-ai/core/util/glob"
1515
import * as Log from "@opencode-ai/core/util/log"
1616
import { Discovery } from "./discovery"
1717
import CUSTOMIZE_OPENCODE_SKILL_BODY from "./prompt/customize-opencode.md" with { type: "text" }
18+
import SIMPLIFY_SKILL_BODY from "./prompt/simplify.md" with { type: "text" }
1819
import { isRecord } from "@/util/record"
1920

2021
const log = Log.create({ service: "skill" })
@@ -33,6 +34,10 @@ const CUSTOMIZE_OPENCODE_SKILL_NAME = "customize-opencode"
3334
const CUSTOMIZE_OPENCODE_SKILL_DESCRIPTION =
3435
"Use ONLY when the user is editing or creating opencode's own configuration: opencode.json, opencode.jsonc, files under .opencode/, or files under ~/.config/opencode/. Also use when creating or fixing opencode agents, subagents, skills, plugins, MCP servers, or permission rules. Do not use for the user's own application code, or for any project that is not configuring opencode itself."
3536

37+
const SIMPLIFY_SKILL_NAME = "simplify"
38+
const SIMPLIFY_SKILL_DESCRIPTION =
39+
"Review changed code for reuse, quality, and efficiency, then fix any issues found."
40+
3641
export const Info = Schema.Struct({
3742
name: Schema.String,
3843
description: Schema.optional(Schema.String),
@@ -277,6 +282,12 @@ export const layer = Layer.effect(
277282
location: "<built-in>",
278283
content: CUSTOMIZE_OPENCODE_SKILL_BODY,
279284
}
285+
s.skills[SIMPLIFY_SKILL_NAME] = {
286+
name: SIMPLIFY_SKILL_NAME,
287+
description: SIMPLIFY_SKILL_DESCRIPTION,
288+
location: "<built-in>",
289+
content: SIMPLIFY_SKILL_BODY,
290+
}
280291
yield* loadSkills(s, yield* InstanceState.get(discovered), bus)
281292
return s
282293
}),
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Simplify: Code Review and Cleanup
2+
3+
Review all changed files for reuse, quality, and efficiency. Fix any issues found.
4+
5+
## Phase 1: Identify Changes
6+
7+
Run `git diff` (or `git diff HEAD` if there are staged changes) to see what changed. If there are no git changes, review the most recently modified files that the user mentioned or that you edited earlier in this conversation.
8+
9+
## Phase 2: Launch Three Review Agents in Parallel
10+
11+
Use the Agent tool to launch all three agents concurrently in a single message. Pass each agent the full diff so it has the complete context.
12+
13+
### Agent 1: Code Reuse Review
14+
15+
For each change:
16+
17+
1. **Search for existing utilities and helpers** that could replace newly written code. Look for similar patterns elsewhere in the codebase — common locations are utility directories, shared modules, and files adjacent to the changed ones.
18+
2. **Flag any new function that duplicates existing functionality.** Suggest the existing function to use instead.
19+
3. **Flag any inline logic that could use an existing utility** — hand-rolled string manipulation, manual path handling, custom environment checks, ad-hoc type guards, and similar patterns are common candidates.
20+
21+
### Agent 2: Code Quality Review
22+
23+
Review the same changes for hacky patterns:
24+
25+
1. **Redundant state**: state that duplicates existing state, cached values that could be derived, observers/effects that could be direct calls
26+
2. **Parameter sprawl**: adding new parameters to a function instead of generalizing or restructuring existing ones
27+
3. **Copy-paste with slight variation**: near-duplicate code blocks that should be unified with a shared abstraction
28+
4. **Leaky abstractions**: exposing internal details that should be encapsulated, or breaking existing abstraction boundaries
29+
5. **Stringly-typed code**: using raw strings where constants, enums (string unions), or branded types already exist in the codebase
30+
6. **Unnecessary JSX nesting**: wrapper Boxes/elements that add no layout value — check if inner component props (flexShrink, alignItems, etc.) already provide the needed behavior
31+
7. **Unnecessary comments**: comments explaining WHAT the code does (well-named identifiers already do that), narrating the change, or referencing the task/caller — delete; keep only non-obvious WHY (hidden constraints, subtle invariants, workarounds)
32+
33+
### Agent 3: Efficiency Review
34+
35+
Review the same changes for efficiency:
36+
37+
1. **Unnecessary work**: redundant computations, repeated file reads, duplicate network/API calls, N+1 patterns
38+
2. **Missed concurrency**: independent operations run sequentially when they could run in parallel
39+
3. **Hot-path bloat**: new blocking work added to startup or per-request/per-render hot paths
40+
4. **Recurring no-op updates**: state/store updates inside polling loops, intervals, or event handlers that fire unconditionally — add a change-detection guard so downstream consumers aren't notified when nothing changed. Also: if a wrapper function takes an updater/reducer callback, verify it honors same-reference returns (or whatever the "no change" signal is) — otherwise callers' early-return no-ops are silently defeated
41+
5. **Unnecessary existence checks**: pre-checking file/resource existence before operating (TOCTOU anti-pattern) — operate directly and handle the error
42+
6. **Memory**: unbounded data structures, missing cleanup, event listener leaks
43+
7. **Overly broad operations**: reading entire files when only a portion is needed, loading all items when filtering for one
44+
45+
## Phase 3: Fix Issues
46+
47+
Wait for all three agents to complete. Aggregate their findings and fix each issue directly. If a finding is a false positive or not worth addressing, note it and move on — do not argue with the finding, just skip it.
48+
49+
When done, briefly summarize what was fixed (or confirm the code was already clean).

0 commit comments

Comments
 (0)