agent-loop-ext
Crash-resilient external agent loop with state persistence and CI/CD integration
Audit codebase for dead code, unused exports, orphaned files, and stale manifests
$ npx -y skills add jmagly/aiwg --skill cleanup-audit --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/cleanup-auditContext preview
The summary Claude sees to decide when to auto-load this skill.
Audit codebase for dead code, unused exports, orphaned files, and stale manifests
namespace: aiwg name: cleanup-audit description: Audit codebase for dead code, unused exports, orphaned files, and stale manifests commandHint: argumentHint: "[--scope <path>] [--type <exports|files|deps|manifests>] [--json] [--fix] [--dry-run]" allowedTools: Bash, Read, Write, Glob, Grep category: utilities orchestration: false platforms: [all]
Audits the codebase for accumulated dead weight: unused TypeScript/JS exports, orphaned source files, npm dependencies that are declared but never imported, and manifest entries that point to files that do not exist. Every finding carries a confidence rating. Only HIGH confidence findings are safe to auto-fix.
Users may say:
Restrict analysis to a subtree. Default is the full repository root.
aiwg cleanup-audit --scope src/cli/ aiwg cleanup-audit --scope agentic/code/addons/
Run only the specified audit type. Omit to run all four.
| Value | Audits | |-------|--------| | `exports` | TypeScript/JS exports with no importers | | `files` | Source files not referenced by any import or manifest | | `deps` | npm dependencies declared in package.json but not used in code | | `manifests` | Manifest entries (skills, agents) whose source file does not exist |
Multiple types can be combined:
aiwg cleanup-audit --type exports --type deps
Emit findings as newline-delimited JSON to stdout instead of the formatted report. Useful for piping into other tools or CI scripts.
aiwg cleanup-audit --json | jq 'select(.confidence == "HIGH")'
Auto-apply removals for all HIGH confidence findings. Has no effect without confirmation when any HIGH finding involves a non-trivial deletion (more than 10 lines or a full file). Combine with `--dry-run` to preview what `--fix` would remove.
Show what `--fix` would remove without writing any changes. If used without `--fix`, behaves as the default read-only audit.
1. Parse `--scope` — default to repo root 2. Parse `--type` — default to all four types 3. Parse `--json`, `--fix`, `--dry-run` flags 4. Build file inventory for the scope:
5. Communicate scope before analysis begins
**Communicate**:
Cleanup Audit
Scope: {scope}
Types: {types}
Mode: {read-only | fix | dry-run fix}
Building file inventory...
Source files: {N}
Manifests: {N}Applies to `--type exports`. Identifies TypeScript and JavaScript named exports that are never imported anywhere in the scope.
**Detection approach**: 1. Glob all source files in scope: `**/*.ts`, `**/*.tsx`, `**/*.js`, `**/*.mjs` 2. Extract all export declarations: `export function`, `export class`, `export const`, `export type`, `export interface`, `export enum` 3. For each exported identifier, grep all source files for imports of that identifier 4. An export is unused if: zero import matches AND it is not referenced in a manifest entry AND it is not a re-export pattern (`export * from`)
**Confidence rules**:
| Signal | Confidence | |--------|-----------| | Zero imports found across entire scope | HIGH | | Zero imports but identifier is a common name (e.g., `index`, `default`) | MEDIUM | | Zero imports but file is an entry point (`index.ts`, `main.ts`) | LOW | | Export appears in a barrel file (`index.ts` re-export) | LOW — skip |
**Output per finding**:
[UNUSED-EXPORT] HIGH File: src/extensions/registry.ts:45 Export: registerExtension Declared: export function registerExtension(ext: Extension): void Importers found: 0 Safe to remove: yes
Applies to `--type files`. Identifies source files that are not imported by any other file and not listed in any manifest.
**Detection approach**: 1. Build full file list for scope 2. For each file, check whether its path appears in:
3. A file is orphaned if none of the above references exist
**Confidence rules**:
| Signal | Confidence | |--------|-----------| | No references found anywhere | HIGH | | No references but filename matches common entry point pattern | MEDIUM | | No references but file is in root of package (may be undiscovered entry) | LOW | | Test file with no corresponding source file | MEDIUM (orphaned test) |
**Output per finding**:
[ORPHANED-FILE] HIGH File: src/legacy/old-config-reader.ts References found: 0 (imports: 0, manifests: 0, package.json: 0) Last modified: 2025-11-02 Safe to remove: yes
Applies to `--type deps`. Finds npm packages declared in `package.json` that have no `import` or `require` usage anywhere in the codebase.
**Detection approach**: 1. Read `dependencies` and `devDependencies` from `package.json` 2. For each package name, grep source files for:
3. Also check config files for tool references: `.eslintrc`, `jest.config.*`, `tsconfig.json`
**Confidence rules**:
| Signal | Confidence | |--------|-----------| | No import/require in source, no config reference | HIGH | | No import in source but referenced in a config file | LOW — tool dependency, do not remove | | No import
Reusable project context and specialist workflows for the AI tools you already use. Plan software, coordinate specialist reviews, prepare campaigns, investigate incidents, organize research, curate media, and maintain operational knowledge.
Repo: jmagly/aiwg
Crash-resilient external agent loop with state persistence and CI/CD integration
Detect requests for iterative autonomous agent loops and route to the appropriate loop executor
Automatically execute tests when code-generating agents modify source files, enforcing the execute-before-return pattern
Enable agent loops to learn from similar past tasks and share patterns across loops
Query and manage the executable feedback debug memory
Execute tests on generated code and iterate until passing