code-refinement
Improves code quality across duplication, efficiency, and architectural fit Skill: code-refinement Owner: athola Summary: Improves code quality across duplication, efficiency, and architectural fit Tags: latest:1.9.19 Version history: v1.9.19 | 2026-08-26T13:18:38.608Z | user Release v1.9.19 v1.9.17 | 2026-07-30T05:38:54.857Z | user Release v1.9.17 v1.9.16 | 2026-07-14T19:55:36.934Z | user Release v1.9.16 v1.9.14 | 2026-06-30T18:03:58.782Z | user Release v1.9.14 v1.9.13 | 2026-06-27T16:22:02
Rank
62
Safety
84
Downloads
1.5k
Updated
Oct 10, 2026
Version
1.9.19
Source
CLAWHUB
About
What it does, and when to use it.
Capability contract not published. No trust telemetry is available yet. 1.5K downloads reported by the source. Last updated 10/10/2026.
Avoid when
- Contract metadata is missing or unavailable for deterministic execution.
Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing
Public facts
Every fact links back to the source it came from.
- Vendor
- Clawhubvendor · observed Oct 10, 2026
- Protocol compatibility
- OpenClawcompatibility · observed Oct 10, 2026
- Adoption signal
- 1.5K downloadsadoption · observed Oct 10, 2026
- Latest release
- 1.9.19release · observed Aug 26, 2026
- Handshake status
- UNKNOWNsecurity
Install and run
Setup complexity: low.
clawhub skill install s17emme0e2m3cpf7k2jvp3a84984b8z9:nm-pensive-code-refinement- Setup complexity is classified as HIGH. You must provision dedicated cloud infrastructure or an isolated VM. Do not run this directly on your local workstation.
- Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data.
Contract: missing
curl -s "https://www.xpersona.co/api/v1/agents/clawhub-athola-nm-pensive-code-refinement/snapshot"
Documentation
CLAWHUB
146,011 characters of source documentation, loaded on request.
Extracted files
5 files captured from the source.
SKILL.md
---
name: code-refinement
description: Improves code quality across duplication, efficiency, and architectural fit
version: 1.9.8
triggers:
- refactoring
- clean-code
- algorithms
- duplication
- anti-slop
- craft
- code passes tests but quality is poor or before a major release
metadata: {"openclaw": {"homepage": "https://github.com/athola/claude-night-market/tree/master/plugins/pensive", "emoji": "\ud83e\udd9e", "requires": {"config": ["night-market.pensive:shared", "night-market.pensive:safety-critical-patterns", "night-market.imbue:proof-of-work", "night-market.imbue:justify"]}}}
source: claude-night-market
source_plugin: pensive
---
> **Night Market Skill** — ported from [claude-night-market/pensive](https://github.com/athola/claude-night-market/tree/master/plugins/pensive). For the full experience with agents, hooks, and commands, install the Claude Code plugin.
## Table of Contents
- [Quick Start](#quick-start)
- [When to Use](#when-to-use)
- [Analysis Dimensions](#analysis-dimensions)
- [Progressive Loading](#progressive-loading)
- [Required TodoWrite Items](#required-todowrite-items)
- [Workflow](#workflow)
- [Tiered Analysis](#tiered-analysis)
- [Cross-Plugin Dependencies](#cross-plugin-dependencies)
# Code Refinement Workflow
Analyze and improve living code quality across six dimensions.
## Quick Start
```bash
/refine-code
/refine-code --level 2 --focus duplication
/refine-code --level 3 --report refinement-plan.md
```
## When To Use
- After rapid AI-assisted development sprints
- Before major releases (quality gate)
- When code "works but smells"
- Refactoring existing modules for clarity
- Reducing technical debt in living code
## When NOT To Use
- Removing
dead/unused code (use conserve:bloat-detector)
## Analysis Dimensions
| # | Dimension | Module | What It Catches |
|---|-----------|--------|----------------|
| 1 | Duplication & Redundancy | `duplication-analysis` | Near-identical blocks, similar functions, copy-paste |
| 2 | Algorithmic Efficiency | `algorithm-efficiency` | O(n^2) where O(n) works, unnecessary iterations |
| 3 | Clean Code Violations | `clean-code-checks` | Long methods, deep nesting, poor naming, magic values |
| 4 | Architectural Fit | `architectural-fit` | Paradigm mismatches, coupling violations, leaky abstractions |
| 5 | Anti-Slop Patterns | `clean-code-checks` | Premature abstraction, enterprise cosplay, hollow patterns |
| 6 | Error Handling | `clean-code-checks` | Bare excepts, swallowed errors, happy-path-only |
| 7 | Additive Bias | `imbue:justify` | Workarounds over root fixes, test tampering, unnecessary additions |
## Plugin-Specific Patterns
Detection patterns for plugin and skill codebases where
standard code quality heuristics miss structural issues.
### Delegation Stub Bodies
A skill that declares "delegates to X" but still carries the
full template body is doing double duty. The delegating skill
should be a thin wrapper (under 30 lines) that routes to the
targ_meta.json
{
"ownerId": "kn7d107jg9jv602h9ytsegydq184a42s",
"slug": "nm-pensive-code-refinement",
"version": "1.9.19",
"publishedAt": 1787750318608
}modules/algorithm-efficiency.md
---
module: algorithm-efficiency
description: Detect algorithmic inefficiencies and suggest improvements
parent_skill: pensive:code-refinement
category: code-quality
tags: [algorithms, complexity, performance, optimization]
dependencies: [Read, Grep, Glob]
estimated_tokens: 400
---
# Algorithm Efficiency Module
Identify time and space complexity inefficiencies at the code block level.
## Scope
This module focuses on **code-block-level** optimizations — not system architecture or database query optimization. It catches patterns where a better algorithm or data structure eliminates unnecessary work.
## Detection Patterns
### 1. Nested Loop on Same Collection (O(n^2) -> O(n) or O(n log n))
```python
# Anti-pattern: O(n^2) lookup
for item in items:
for other in items:
if item.id == other.parent_id:
...
# Better: O(n) with index
index = {item.id: item for item in items}
for item in items:
parent = index.get(item.parent_id)
```
**Detection:**
```bash
# Find nested for-loops on same variable (Python)
grep -n "for .* in " --include="*.py" -r . | \
awk -F: '{file=$1; line=$2; var=$0; gsub(/.*in /,"",var); gsub(/:.*/,"",var); print file, line, var}' | \
sort | uniq -f2 -d
```
### 2. Repeated Sort / Search
```python
# Anti-pattern: sorting inside a loop
for query in queries:
sorted_data = sorted(data) # O(n log n) per query = O(m * n log n)
result = bisect.bisect(sorted_data, query)
# Better: sort once
sorted_data = sorted(data) # O(n log n) once
for query in queries:
result = bisect.bisect(sorted_data, query) # O(m * log n)
```
**Detection:**
```bash
# Find sort/sorted inside loops
grep -n "sorted\|\.sort()" --include="*.py" -r . | while read line; do
file=$(echo "$line" | cut -d: -f1)
num=$(echo "$line" | cut -d: -f2)
# Check if inside a for/while loop
sed -n "$((num-5)),$((num))p" "$file" | grep -q "for \|while " && echo "SORT_IN_LOOP: $line"
done
```
### 3. List Where Set/Dict Suffices
```python
# Anti-pattern: O(n) membership test
if item in large_list: # O(n)
...
# Better: O(1) membership test
large_set = set(large_list)
if item in large_set: # O(1)
...
```
**Detection:**
```bash
# Find "in list_var" patterns (heuristic)
grep -n " in \[" --include="*.py" -r .
grep -n " not in " --include="*.py" -r . | grep -v "not in {" | grep -v "not in set("
```
### 4. String Concatenation in Loop
```python
# Anti-pattern: O(n^2) string building
result = ""
for item in items:
result += str(item) + ", "
# Better: O(n) with join
result = ", ".join(str(item) for item in items)
```
### 5. Unnecessary Intermediate Collections
```python
# Anti-pattern: builds full list just to iterate
all_items = [transform(x) for x in data] # allocates full list
for item in all_items:
process(item)
# Better: generator (lazy evaluation)
for item in (transform(x) for x in data):
process(item)
```
### 6. Repeated Computation (Missing Memoization)
```python
# Anti-pattern: recomputes expensmodules/architectural-fit.md
---
module: architectural-fit
description: Assess code alignment with architectural paradigm and coupling principles
parent_skill: pensive:code-refinement
category: code-quality
tags: [architecture, coupling, cohesion, paradigm, alignment]
dependencies: [Read, Grep, Glob]
estimated_tokens: 400
---
# Architectural Fit Module
Evaluate whether code structure aligns with the project's architectural paradigm and coupling/cohesion principles.
## Two-Mode Operation
### Mode 1: Paradigm-Aware (archetypes plugin installed)
When `archetypes` is available, detect the project's paradigm and check alignment:
```
Skill(archetypes:architecture-paradigms) -> detect paradigm -> check violations
```
Supported paradigms from archetypes:
- Functional Core / Imperative Shell
- Hexagonal (Ports & Adapters)
- Layered Architecture
- Pipeline / Data Flow
- Modular Monolith
- Event-Driven
- Client-Server
- Microkernel
- CQRS/ES
### Mode 2: Principle-Based (fallback, no archetypes)
Check universal coupling/cohesion principles without paradigm detection:
- Dependency direction (no circular deps)
- Layer violations (UI calling DB directly)
- Cohesion (related code grouped together)
- Encapsulation (no leaking internals)
## Detection: Coupling Violations
### 1. Circular Dependencies
```bash
# Python: Find circular imports (heuristic)
grep -rn "^from \|^import " --include="*.py" . | \
awk -F: '{file=$1; gsub(/.*from /,"",$3); gsub(/ import.*/,"",$3); print file, $3}' | \
sort | while read a b; do
grep -q "from.*$(basename $a .py)" "$b.py" 2>/dev/null && \
echo "CIRCULAR: $a <-> $b"
done
```
### 2. Layer Violations
Common layer boundaries to check:
- Presentation should not import from data/persistence
- Domain/business logic should not depend on framework
- Utilities should not depend on domain
```bash
# Find cross-layer imports (convention: src/{layer}/)
# Customize layer names per project
for violation in \
"handlers.*import.*models\." \
"views.*import.*database" \
"api.*import.*sql\|cursor\|query"; do
grep -rn "$violation" --include="*.py" . 2>/dev/null && echo "LAYER_VIOLATION: $violation"
done
```
### 3. Feature Envy
A method that uses more features of another class than its own:
```bash
# Heuristic: methods with many external references
# Look for methods where self.X appears less than other_obj.Y
grep -A20 "def " --include="*.py" -r . | \
awk '/def /{fn=$0; self=0; other=0} /self\./{self++} /[a-z]+\./{other++} /^$/{if(other>self*2 && other>3) print "FEATURE_ENVY:", fn}'
```
### 4. Inappropriate Intimacy
Classes that access each other's private members:
```bash
# Find access to _private members from outside class
grep -rn "\._[a-z]" --include="*.py" . | grep -v "self\._\|cls\._\|__init__\|test_" | head -20
```
### 5. Shotgun Surgery Indicators
Changes to one concept require touching many files:
```bash
# Heuristic: functions/classes with same name prefix across many files
grep -rn "^def " --include="*.py" . | sed 's/def modules/clean-code-checks.md
---
module: clean-code-checks
description: Clean code violations, anti-slop patterns, and error handling checks
parent_skill: pensive:code-refinement
category: code-quality
tags: [clean-code, anti-slop, naming, error-handling, complexity]
dependencies: [Read, Grep, Glob, Bash]
estimated_tokens: 450
---
# Clean Code Checks Module
Detect violations of clean code principles, AI slop patterns, and error handling gaps.
Covers three dimensions: Clean Code, Anti-Slop, and Error Handling.
## Clean Code Violations
### 1. Long Methods (>30 lines)
```bash
# Python: Find long functions
grep -n "^def \|^ def " --include="*.py" -r . | while read line; do
file=$(echo "$line" | cut -d: -f1)
num=$(echo "$line" | cut -d: -f2)
# Count lines until next def or end
length=$(sed -n "${num},\$p" "$file" | awk '/^def |^ def /{if(NR>1)exit}END{print NR}')
[ "$length" -gt 30 ] && echo "LONG_METHOD ($length lines): $line"
done
```
**Refactoring**: Extract method, compose method pattern.
### 2. Deep Nesting (>3 levels)
```bash
# Find deeply nested code (4+ indent levels = 16+ spaces or 4+ tabs)
grep -rn "^ " --include="*.py" . | head -20
grep -rn "^\t\t\t\t" --include="*.js" --include="*.ts" . | head -20
```
**Refactoring**: Guard clauses, extract method, strategy pattern.
### 3. Magic Numbers and Strings
```bash
# Find magic numbers (excluding 0, 1, common constants)
grep -rn "[^a-zA-Z_][2-9][0-9]\{1,\}[^a-zA-Z_0-9\"']" --include="*.py" . | \
grep -v "range\|port\|version\|#\|test_\|assert" | head -20
```
**Refactoring**: Extract to named constants.
### 4. Poor Naming
Indicators of AI-generated generic names:
```bash
# Find generic function names
grep -rn "def process\|def handle\|def manage\|def do_\|def run_" --include="*.py" . | \
grep -v "test_\|__" | head -20
# Find single-letter variables (outside loops/lambdas)
grep -rn " [a-z] = " --include="*.py" . | grep -v "for [a-z] in\|lambda [a-z]" | head -20
```
### 5. God Classes (>300 lines or >10 methods)
```bash
# Python: Large classes
grep -c "def " --include="*.py" -r . | awk -F: '$2>10{print "GOD_CLASS:", $0}'
```
## Anti-Slop Patterns
AI-specific code smells that traditional linters miss.
### 1. Premature Abstraction
Base classes/interfaces with only 1 implementation.
```bash
# Python: ABC with single inheritor
grep -rn "class.*ABC\|@abstractmethod" --include="*.py" . | cut -d: -f1 | sort -u | while read f; do
class=$(grep -oP "class \K\w+" "$f" | head -1)
[ -n "$class" ] && {
inheritors=$(grep -rn "($class)" --include="*.py" . | wc -l)
[ "$inheritors" -lt 2 ] && echo "PREMATURE_ABSTRACTION: $class in $f ($inheritors inheritors)"
}
done
```
### 2. Enterprise Cosplay
Over-engineered patterns for simple problems:
- Factory for a single type
- Strategy pattern with one strategy
- Observer with one subscriber
- Middleware chain for single operation
```bash
# Find *Factory, *Builder, *Strategy with few usages
for pattern in Factory Builder Strategy AionUi
Free, local, open-source 24/7 Cowork app and OpenClaw for Gemini CLI, Claude Code, Codex, OpenCode, Qwen Code, Goose CLI, Auggie, and more | 🌟 Star if you like it!
activepieces
AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
cherry-studio
AI productivity studio with smart chat, autonomous agents, and 300+ assistants.
CopilotKit
The Frontend for Agents & Generative UI. React + Angular
Machine-readable data
The same record, as JSON, for agents and crawlers.
{
"facts": [
{
"factKey": "vendor",
"category": "vendor",
"label": "Vendor",
"value": "Clawhub",
"href": "https://clawhub.ai/athola/skills/nm-pensive-code-refinement",
"sourceUrl": "https://clawhub.ai/athola/skills/nm-pensive-code-refinement",
"sourceType": "profile",
"confidence": "medium",
"observedAt": "2026-10-10T10:33:08.134Z",
"isPublic": true
},
{
"factKey": "protocols",
"category": "compatibility",
"label": "Protocol compatibility",
"value": "OpenClaw",
"href": "https://www.xpersona.co/api/v1/agents/clawhub-athola-nm-pensive-code-refinement/contract",
"sourceUrl": "https://www.xpersona.co/api/v1/agents/clawhub-athola-nm-pensive-code-refinement/contract",
"sourceType": "contract",
"confidence": "medium",
"observedAt": "2026-10-10T10:33:08.134Z",
"isPublic": true
},
{
"factKey": "traction",
"category": "adoption",
"label": "Adoption signal",
"value": "1.5K downloads",
"href": "https://clawhub.ai/athola/nm-pensive-code-refinement",
"sourceUrl": "https://clawhub.ai/athola/nm-pensive-code-refinement",
"sourceType": "profile",
"confidence": "medium",
"observedAt": "2026-10-10T10:33:08.134Z",
"isPublic": true
},
{
"factKey": "latest_release",
"category": "release",
"label": "Latest release",
"value": "1.9.19",
"href": "https://clawhub.ai/athola/nm-pensive-code-refinement",
"sourceUrl": "https://clawhub.ai/athola/nm-pensive-code-refinement",
"sourceType": "release",
"confidence": "medium",
"observedAt": "2026-08-26T13:18:38.608Z",
"isPublic": true
},
{
"factKey": "handshake_status",
"category": "security",
"label": "Handshake status",
"value": "UNKNOWN",
"href": "https://www.xpersona.co/api/v1/agents/clawhub-athola-nm-pensive-code-refinement/trust",
"sourceUrl": "https://www.xpersona.co/api/v1/agents/clawhub-athola-nm-pensive-code-refinement/trust",
"sourceType": "trust",
"confidence": "medium",
"observedAt": null,
"isPublic": true
}
],
"events": [
{
"eventType": "release",
"title": "Release 1.9.19",
"description": "Release v1.9.19",
"href": "https://clawhub.ai/athola/nm-pensive-code-refinement",
"sourceUrl": "https://clawhub.ai/athola/nm-pensive-code-refinement",
"sourceType": "release",
"confidence": "medium",
"observedAt": "2026-08-26T13:18:38.608Z",
"isPublic": true
}
]
}Record generated Oct 10, 2026.
