agentleFS
jovd83jovd83/principal-audit-refactor/SKILL.md

principal-audit-refactor

Skill0 starsChanged 8 months agoMITView on GitHub

Audit a local software project, produce a severity-ranked engineering review, and execute an approval-gated refactor plan. Use when the agent needs to assess prototype-quality or inconsistent codebases, run stack-aware checks, write timestamped audit artifacts, and then implement production-grade improvements with explicit safety boundaries, report contracts, and refactoring discipline.

We split this skill into the rules it gives an agent

22 rules. About 0 are common, 19 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈19

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill to turn an unstable or inconsistent repository into a better-structured, safer, more maintainable codebase without …

    line 24
  2. Very specific:

    Keep the workflow grounded in the target repository, not the skill repository.

    line 32
  3. Distinctive:

    Do not require a perfectly clean tree to perform an audit.

    line 39
  4. Distinctive:

    Never invent linter commands.

    line 40
  5. Distinctive:

    Stop after writing the audit report and ask for approval.

    line 41
  6. Distinctive:

    Treat audit plus refactor as a two-step workflow with a hard approval gate between them.

    line 49
  7. Distinctive:

    Prefer deterministic tooling when available: lint, typecheck, unit tests, static analysis, or build validation.

    line 55
  8. Distinctive:

    Read references/rubric.md once discovery is complete.

    line 57
  9. Distinctive:

    Use references/report-contract.md and assets/audit-report-template.md.

    line 60
  10. Very specific:

    Write a timestamped audit file in Technical_Reviews/ at the target project root.

    line 61
  11. Distinctive:

    If evidence is incomplete, state the limitation rather than over-claiming.

    line 64
  12. Distinctive:

    After saving the audit report:

    line 67
  13. Distinctive:

    ask for explicit approval before editing code.

    line 70
  14. Distinctive:

    Prefer in-place repository edits over chat-only "full file output" unless the user explicitly asks for copy-paste output.

    line 76
  15. Distinctive:

    Add or update tests when the repository already has a testing story and the change materially benefits from coverage.

    line 78
  16. Distinctive:

    Write a timestamped execution summary using assets/refactor-report-template.md.

    line 79
  17. Distinctive:

    follow-up work intentionally left out of scope,

    line 99
  18. Distinctive:

    Do not automatically promote runtime observations into persistent artifacts unless they are useful to the user or needed for traceability.

    line 126
  19. Distinctive:

    If the workflow becomes unreliable, degrade gracefully:

    line 130
  20. Very specific:

    Generated Artifacts: Ensure you are auditing source code and not generated files (e.g., dist/, build/, node_modules/).

    line 142
  21. Distinctive:

    Tooling Hallucination: If native test/lint scripts are missing, strictly report the gap rather than inventing commands to simulate a …

    line 143
  22. Distinctive:

    State Drift: If the user makes manual edits after an audit but before a refactor, the audit results may become stale.

    line 144

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Principal Audit & Refactor

Author: jovd83 | Version: 1.4.1

Use this skill to turn an unstable or inconsistent repository into a better-structured, safer, more maintainable codebase without collapsing discovery, audit, and mutation into one uncontrolled pass.

Operating Model

Work in two explicit modes:

  1. Audit mode: inspect the target project, run safe deterministic checks, and write an audit report.
  2. Refactor mode: only begin after the user explicitly approves the audit findings.

Keep the workflow grounded in the target repository, not the skill repository. Write generated reports into the target project's Technical_Reviews/ directory.

Safety Gates

Enforce these gates before mutating code:

  • Confirm the target path the user wants audited. Default to the current working directory only when the intent is unambiguous.
  • Detect whether the target is inside a git repository. If it is, inspect status before editing. If it is not, continue but explicitly note the lack of version-control safety.
  • Do not require a perfectly clean tree to perform an audit. For refactoring, pause if unrelated changes create a real risk of overwriting user work.
  • Never invent linter commands. Prefer project-native commands discovered from manifests, scripts, or tool configs. If no reliable deterministic check is available, say so and continue with manual review.
  • Stop after writing the audit report and ask for approval. Do not begin implementation in the same phase unless the user has already authorized both audit and refactor work.
  • Scope edits to the agreed target. Do not "boil the ocean" unless the user asked for a full-repository pass.

Workflow

1. Establish Scope

  • Identify the target repository or subpath.
  • Determine whether the user wants an audit only or audit plus refactor.
  • Treat audit plus refactor as a two-step workflow with a hard approval gate between them.

2. Discover the Environment

  • Inspect manifests and build files such as package.json, pyproject.toml, Cargo.toml, go.mod, pom.xml, build.gradle, .csproj, Dockerfile, and CI configs.
  • Identify the main languages, frameworks, runtime, package manager, test stack, data layer, and entry points.
  • Identify likely high-risk areas: core orchestration, auth, persistence, state management, heavy utility modules, or files already producing warnings.
  • Prefer deterministic tooling when available: lint, typecheck, unit tests, static analysis, or build validation.

Read references/rubric.md once discovery is complete.

3. Produce the Audit

  • Use references/report-contract.md and assets/audit-report-template.md.
  • Write a timestamped audit file in Technical_Reviews/ at the target project root.
  • Include concrete file paths, severity, risk, and recommended action.
  • Base severity on evidence from code inspection and any deterministic tool output you were able to run.
  • If evidence is incomplete, state the limitation rather than over-claiming.

4. Pause for Approval

After saving the audit report:

  • summarize the top risks,
  • name the report path, and
  • ask for explicit approval before editing code.

5. Execute the Refactor

Only after approval:

  • Read references/refactor-execution.md.
  • Refactor by file or bounded subsystem, not by isolated smell.
  • Prefer in-place repository edits over chat-only "full file output" unless the user explicitly asks for copy-paste output.
  • Preserve behavior unless the audit explicitly calls for a behavioral fix.
  • Add or update tests when the repository already has a testing story and the change materially benefits from coverage.
  • Write a timestamped execution summary using assets/refactor-report-template.md.

Output Contracts

Audit report

Must include:

  • project name or scoped target,
  • timestamp,
  • detected stack,
  • deterministic checks run and their outcomes,
  • prioritized findings with severity,
  • maintainability score with a clear scoring rule,
  • recommended refactor sequence,
  • explicit open questions or blocked areas.

Refactor report

Must include:

  • audit report reference,
  • files changed,
  • resolved findings,
  • follow-up work intentionally left out of scope,
  • validation performed after edits.

Chain Phases

config/chain_definition.json is the executable contract: 10 phases, run by skill-orchestrator/scripts/next_phase.py. In Claude Code, run the whole chain with the principal-audit-refactor agent (~/.claude/agents/principal-audit-refactor.md). It stops at each approval gate and returns, and the main conversation resumes it. This SKILL.md stays the reference for the phases and for manual runs in other harnesses.

#PhaseSkillGateWorkflow step above
1scopeagent-handled1. Establish Scope
2repo_contextcodebase-context2. Discover the Environment
3dependency_reviewmodern-dependency-guard3. Produce the Audit
4security_reviewdefensive-appsec-review-skill3. Produce the Audit
5testability_reviewstack-aware-unit-testing-skill3. Produce the Audit
6audit_reportagent-handledapproval gate after3-4. Audit report; pause for approval
7approved_refactoragent-handled5. Execute the Refactor
8validationstack-aware-unit-testing-skill5. Execute the Refactor
9automation_reviewautomated-test-reviewer5. Execute the Refactor
10summaryagent-handledOutput Contracts: refactor report

Memory Model

Use memory deliberately:

  • Runtime memory: current findings, tool output, and the active refactor plan for this run only.
  • Project-local memory: persisted audit and refactor reports written into Technical_Reviews/ in the target repository.
  • Shared memory: out of scope for this skill. If cross-project reuse is needed, use the agent's own memory (for example CLAUDE.md or AGENTS.md) instead of storing shared memory here.

Do not automatically promote runtime observations into persistent artifacts unless they are useful to the user or needed for traceability.

Failure Handling

If the workflow becomes unreliable, degrade gracefully:

  • Missing repo metadata: continue with manual discovery and note the limitation.
  • Missing or broken tooling: capture the failure, avoid guessing commands, continue with review.
  • Large or tangled files: split work into bounded extractions before deeper cleanup.
  • Unsafe ambiguity about intent or target path: pause and confirm before editing.
  • Conflicts with user changes: stop and ask before overwriting.

Gotchas

Watch out for these common friction points:

  • Root Ambiguity: In monorepos, the skill might default to the root. Always clarify if the audit should be scoped to a specific package or directory.
  • Context Window Limits: For very large repositories or files, the agent may not see the full context in a single pass. Consider splitting large audits into subsystems.
  • Generated Artifacts: Ensure you are auditing source code and not generated files (e.g., dist/, build/, node_modules/).
  • Tooling Hallucination: If native test/lint scripts are missing, strictly report the gap rather than inventing commands to simulate a "deterministic" check.
  • State Drift: If the user makes manual edits after an audit but before a refactor, the audit results may become stale. Briefly re-verify critical files before mutating.

Resource Map

  • Rubric: references/rubric.md
  • Report contract: references/report-contract.md
  • Refactor execution rules: references/refactor-execution.md
  • Evaluation guidance: references/evaluation.md
  • Audit template: assets/audit-report-template.md
  • Refactor template: assets/refactor-report-template.md
  • Example prompts and sandbox: examples/

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.