fdk-refactor

A code-refactoring command for Freshworks apps that makes complicated functions easier to follow while keeping their behavior unchanged. It targets a maximum cyclomatic complexity of 7, a measure of how many independent decision paths code has.

In plain words
What is it for?
Use it to find complex functions in a Freshworks app and split, simplify, or reorganize them without changing what the app does.
Why use it?
It reduces deeply nested logic, long functions, and large chains of conditions that make code harder to test and maintain.

Command

Install

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.

agentmods
npx agentmods add commands/freshworks-developers/fw-dev-tools/fdk-refactor
Clone the repo
git clone --depth 1 https://github.com/freshworks-developers/fw-dev-tools
Per session 41 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 539 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What 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.

ModelPer sessionOnce invoked
Fable 5 $0.00041 $0.00539
Opus 5 $0.00020 $0.00269
Sonnet 5 $0.00008 $0.00108
Haiku 4.5 $0.00004 $0.00054

Measured 2d ago against content hash b138c20ff52d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

fdk-refactor 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.

skills/fw-app-dev/commands/fdk-refactor.md · 54 lines

What it actually says

FDK Refactor Command

Usage: /fdk-refactor

You are reducing function complexity in a Freshworks app. Target: cyclomatic complexity ≤ 7 per function. Follow these steps exactly.

Step 1: Determine app directory

  1. Search the workspace for manifest.json files.
  2. If multiple folders contain manifest.json: Ask the user which app to refactor.
  3. If one folder: Use that directory.
  4. If none: Inform the user and stop.

Step 2: Identify high-complexity functions

Scan server/server.js and app/scripts/*.js for functions with:

  • Deep nesting (multiple if/for/while levels)
  • Many conditional branches
  • Long functions (> 50 lines)

Reference: Code complexity threshold is 7 (max cyclomatic complexity per function).

Step 3: Refactoring techniques

Apply these patterns:

  1. Extract helper functions: Move nested logic into separate, well-named functions.
  2. Early returns: Replace nested ifs with guard clauses.
  3. Extract loops: Move loop bodies into separate functions.
  4. Simplify conditionals: Use lookup tables or strategy pattern instead of long if-else chains.

Step 4: Preserve behavior

  • Do NOT change app behavior or logic.
  • Keep helper functions after the exports block (FDK parser requirement).
  • Ensure all exports still work correctly.

Step 5: Validate

First: SKILL.mdManifest + toolchain gate before any fdk validate (same as /fdk-fix: fw-setup / /fdk-migrate / raise engines — no toolchain downgrade).

Toolchain: If fdk validate cannot run, fw-app-dev does not install the CLI — use fw-setup or prompt the user to add it (SKILL.mdFDK / Node.js toolchain — not provided by fw-app-dev).

Run: cd <app-directory> && fdk validate

Ensure no new errors were introduced. Report the refactored functions and validation status.

Changes

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.

  1. 2d ago First seen · 54 lines · 41 tokens per session scan A b138c20ff52d

Subscribe to this mod's changes

fdk-refactor is a command published in the GitHub repository freshworks-developers/fw-dev-tools (5 stars, last pushed 8d ago), licensed MIT. It adds 41 tokens to every session and 539 once invoked, about $0.0002 per session on Opus 5. 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-31.