Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add commands/doobidoo/mcp-memory-service/refactor-functiongit clone --depth 1 https://github.com/doobidoo/mcp-memory-serviceWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00000 | $0.01588 |
| Opus 5 | $0.00000 | $0.00794 |
| Sonnet 5 | $0.00000 | $0.00318 |
| Haiku 4.5 | $0.00000 | $0.00159 |
Grade A, and why
refactor-function scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 273 lines — stays where its author put it; the contents beside it link to each section on GitHub.
/refactor-function Command
Automated function complexity reduction using multi-agent workflow.
Usage
# In editor, select a function and run:
/refactor-function
# With options:
/refactor-function --target-complexity 6 --max-helpers 3
/refactor-function --pattern extract-method
/refactor-function --dry-run # Show plan without applying
Workflow
1. Context Extraction
- Detect selected function or function at cursor
- Extract function signature, body, surrounding context
- Parse imports and dependencies
2. Baseline Analysis (code-quality-guard)
- Measure current complexity
- Identify nesting depth
- Count boolean operators
- Calculate maintainability index
- Generate refactoring targets
3. Refactoring (amp-bridge)
- Apply Extract Method pattern
- Create helper functions
- Reduce nesting with early returns
- Replace if-elif chains with dictionaries
- Extract magic strings to constants
4. Validation (code-quality-guard)
- Measure new complexity
- Verify targets met
- Check for regressions
- Generate diff report
5. User Review
Before:
Function: parse_output
Complexity: 12 (C-grade)
Nesting: 5 levels
After:
Main: parse_output (C=6, B-grade)
Helpers:
- _parse_field (C=4, A-grade)
- _validate_output (C=3, A-grade)
Apply changes? [y/n]
6. Optional Commit
If applied, offer to commit:
"refactor: Reduce complexity in <function_name>
- Complexity: C=12→6 (-50%)
- Extracted N helpers (avg C=X)
- Pattern: Extract Method"
Options
| Option | Description | Default |
|---|---|---|
--target-complexity |
Target cyclomatic complexity | 6 |
--max-helpers |
Max helper functions to create | 5 |
--pattern |
Refactoring pattern | extract-method |
--dry-run |
Show plan without applying | false |
--auto-commit |
Commit if successful | false |
--scope |
Scope (function|class|file) | function |
Patterns Supported
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 273 lines · 0 tokens per session scan A 3b66847514b5
refactor-function is a command published in the GitHub repository doobidoo/mcp-memory-service (1,919 stars, last pushed 4d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 1,588 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other commands, from other repositories
chunkhound-release-notes
Generate release notes for a ChunkHound production release.
review-pr
Review Github Pull Request.
search
Semantic, lexical, hybrid, and edge search across indexed markdown files.
graph
Show visualization-ready graph data with nodes, edges, and clusters for the indexed markdown files.
links
Show outgoing and incoming links originating from a specific markdown file, with optional multi-hop neighborhood traversal.
backlinks
Show files that link TO a specific markdown file (incoming links / backlinks).