Identify and implement ONE small, safe refactoring in the kubeopencode codebase that improves code quality without changing behavior.
- CronTask: Every 3 days at 8:00 UTC (
deploy/crontask-tiny-refactor.yaml) - Manual:
run tiny refactor,find a refactoring opportunity
Use static analysis tools to discover refactoring opportunities:
cd kubeopencode
# Find unused code, shadowed variables, etc.
go vet ./...
# Find dead code, unused parameters (if available)
staticcheck ./... 2>/dev/null || true
# Check for inefficient code patterns
golangci-lint run --no-config --disable-all \
--enable=unused,deadcode,ineffassign,unconvert \
./... 2>/dev/null || trueIf tools report issues, prioritize fixing those first (they are verified safe).
Choose the FIRST applicable type:
- Dead Code Removal (safest) — unused imports, variables, unexported functions, commented-out code blocks
- Naming Improvements — single-letter vars in long functions, misleading names, inconsistent patterns
- Magic Values — numbers appearing 2+ times, repeated strings 3+ times, unexplained timeouts
- Code Simplification — complex booleans, deep nesting (>3 levels), long
if err != nilchains - Small Extractions — functions >50 lines, duplicate fragments >8 lines
Prefer (in order): internal/controller/, cmd/kubeopencode/, pkg/
Skip: api/ (public API), zz_generated*, vendor/, testdata/, e2e/, hack/, YAML/JSON/TOML, files modified in last 5 commits
- Create branch:
git checkout -b refactor/$(date +%Y%m%d)-<short-description>
- Make the minimal change required
- Self-check: Does this change behavior? Is this the smallest possible change?
Run in order — stop on first failure:
go build ./...
make lint
make testOn failure: rollback (git checkout -- . && git clean -fd), try a different refactoring or exit cleanly.
Do NOT attempt to fix failing tests — that changes behavior.
git add -A
git commit -s -m "refactor(<scope>): <what changed>
<why this improves the code - one line>
Type: <Priority N: Category Name>"
git push -u origin HEAD
gh pr create \
--title "refactor(<scope>): <what changed>" \
--body "**Type:** <Priority N: Category Name>
**Change:** <one sentence>
**Why:** <one sentence>
**Verified:** go build, make lint, make test all pass
---
_Automated by kubeopencode-agent_" \
--label "refactor" \
--label "automated"If no safe refactoring is found:
- Do not force a change
- Do not create an issue
- Exit cleanly — this is normal for a well-maintained codebase
Absolute Prohibitions:
- Never change exported function signatures or struct field names
- Never change error messages that callers might parse
- Never reorder struct fields or rename packages
- Never modify externally-referenced constants
Size Limits: max 3 files, 50 lines, 5 functions
Uncertainty = Stop: If unsure whether a change is safe, choose a different refactoring or exit.
Verification is mandatory: Never skip go build, make lint, or make test.