@a2f0/agent-tool 0.1.83 → 0.1.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/deslopify-refactor/SKILL.md +213 -0
- package/skills/deslopify-refactor/agents/openai.yaml +4 -0
- package/skills/deslopify-refactor/references/lessons.md +73 -0
- package/skills/deslopify-refactor/references/pathology-catalog.md +105 -0
- package/src/cli.ts +4 -0
- package/src/deslop/command.ts +287 -0
- package/src/deslop/scan.ts +731 -0
- package/src/deslop/structural.ts +712 -0
- package/src/permissions/catalog.ts +1 -1
- package/src/skills/bundled.ts +6 -0
package/package.json
CHANGED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: deslopify-refactor
|
|
3
|
+
description: Behavior-preserving simplification and refactoring to remove agent-written slop, duplication, dead surface area, god-files, unnecessary wrappers, and test-fixture bloat while proving observable behavior is unchanged. Use when asked to de-slopify, simplify, reduce duplication, split oversized modules, prune dead code, or run a simplification sweep across repositories; not for converting boolean flags into state machines (explicit-state-machines), speeding up CI or tests (optimize-ci), page-load optimization (performance-pass), or greenfield contract redesigns.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# De-slopify Refactor
|
|
7
|
+
|
|
8
|
+
Treat every simplification as a proof obligation: the simpler program must be
|
|
9
|
+
observably equivalent to the original. Remove real complexity, duplication, dead
|
|
10
|
+
code, and misleading scaffolding, but never call a change a refactor unless
|
|
11
|
+
behavior preservation is established.
|
|
12
|
+
|
|
13
|
+
## Simplification bar
|
|
14
|
+
|
|
15
|
+
Prefer levers in this order:
|
|
16
|
+
|
|
17
|
+
1. **Delete**: dead code, unreachable internal branches, unused parameters,
|
|
18
|
+
stale shims, redundant wrappers, and stale task-plan comments.
|
|
19
|
+
2. **Flatten or split**: inline one-off non-architectural indirection, collapse
|
|
20
|
+
unnecessary nesting, and split oversized multi-concern files along acyclic
|
|
21
|
+
seams.
|
|
22
|
+
3. **Extract or unify**: share a helper or factory only when callers represent
|
|
23
|
+
the same concept, lifecycle, and error contract.
|
|
24
|
+
|
|
25
|
+
Never merge two code paths if the shared helper needs boolean mode flags,
|
|
26
|
+
caller-specific branches, or unsafe type casts (`as`) to paper over differences.
|
|
27
|
+
Net lines removed is a sanity check, not the goal: a shorter file that is harder
|
|
28
|
+
to trace or couples unrelated domains adds slop instead of removing it.
|
|
29
|
+
|
|
30
|
+
## Find candidates
|
|
31
|
+
|
|
32
|
+
Start with `agent-tool deslop` (read-only):
|
|
33
|
+
|
|
34
|
+
- `agent-tool deslop [path...] [--limit N] [--min-score N] [--include-tests] [--by-dir] [--json]`
|
|
35
|
+
ranks tracked source files in the repository holding the working directory, or
|
|
36
|
+
each named path's repository, by seven signals: duplicated multi-line code
|
|
37
|
+
blocks (`duplicate-block`), structurally identical blocks with renamed
|
|
38
|
+
identifiers/literals (`parametric-clone`), oversized files (`oversized-file`),
|
|
39
|
+
long functions (`long-function`), lint/type suppression clusters
|
|
40
|
+
(`suppressions`), exported pass-through wrapper cascades (`thin-wrapper`), and
|
|
41
|
+
single-caller micro-files or non-index re-export shims (`micro-file`).
|
|
42
|
+
- Run `agent-tool deslop --by-dir --include-tests` first on any large repository
|
|
43
|
+
or monorepo to see directory-level duplication hotspots, test-to-source ratios,
|
|
44
|
+
and micro-file clusters before choosing slices.
|
|
45
|
+
- Pass `--include-tests` as a first-class phase, not an afterthought: test
|
|
46
|
+
helpers, copy-pasted fixtures, and overlapping test files are often the
|
|
47
|
+
largest, lowest-production-risk simplification targets in agent-built codebases.
|
|
48
|
+
- If the repository's pinned agent-tool lacks the command or flags, run
|
|
49
|
+
`bunx --bun @a2f0/agent-tool@latest deslop`.
|
|
50
|
+
|
|
51
|
+
The scanner finds leads, not verdicts. Pair it with the repository's existing
|
|
52
|
+
static tools before reading by hand:
|
|
53
|
+
|
|
54
|
+
- Dead exports, files, and dependencies (`knip`, `ts-prune`, compiler unused
|
|
55
|
+
checks).
|
|
56
|
+
- Import cycles and layer leaks (`agent-tool graph check`, `dependency-cruiser`).
|
|
57
|
+
- File-size, complexity, and suppression baselines when the repository keeps one.
|
|
58
|
+
|
|
59
|
+
Read [references/pathology-catalog.md](references/pathology-catalog.md) for
|
|
60
|
+
common simplification opportunities, scoring, and false-positive traps, and
|
|
61
|
+
[references/lessons.md](references/lessons.md) for cross-repository lessons from
|
|
62
|
+
earlier passes.
|
|
63
|
+
|
|
64
|
+
## Decide what to simplify
|
|
65
|
+
|
|
66
|
+
Simplify a candidate only when all three hold:
|
|
67
|
+
|
|
68
|
+
1. It removes real complexity, duplication, dead surface area, or misleading
|
|
69
|
+
scaffolding under the simplification bar above.
|
|
70
|
+
2. Its equivalence boundary is explicit before editing.
|
|
71
|
+
3. Verification can prove observable behavior is unchanged (or pre-existing
|
|
72
|
+
failures are unchanged).
|
|
73
|
+
|
|
74
|
+
Leave a candidate alone when:
|
|
75
|
+
|
|
76
|
+
- Similarity is accidental: helpers share shape but differ in rounding,
|
|
77
|
+
thresholds, sort order near hashes, error-prefix classification, or key arity.
|
|
78
|
+
- The wrapper is an enforced architectural boundary (such as a route -> service
|
|
79
|
+
-> workflow facade) or a public API contract.
|
|
80
|
+
- A defensive guard, `ref` mirror, memoized identity, or lint/type idiom (such
|
|
81
|
+
as `Reflect.get` under `noPropertyAccessFromIndexSignature` + `useLiteralKeys`)
|
|
82
|
+
prevents a real bug or satisfies a repository rule.
|
|
83
|
+
- Equivalence cannot be proved at reasonable cost.
|
|
84
|
+
|
|
85
|
+
See [references/pathology-catalog.md#leave-alone-and-common-traps](references/pathology-catalog.md#leave-alone-and-common-traps)
|
|
86
|
+
before touching hash-adjacent code, error classifiers, React hooks, or
|
|
87
|
+
serialization paths. Record each non-obvious candidate you leave alone and why
|
|
88
|
+
in the PR body (or inline comment when the trap is subtle) so future passes do
|
|
89
|
+
not re-propose it.
|
|
90
|
+
|
|
91
|
+
## Execute and prove equivalence
|
|
92
|
+
|
|
93
|
+
1. **Establish the baseline**: inspect `git status`, read the repository's
|
|
94
|
+
`AGENTS.md` and scripts, and run the narrowest credible baseline (targeted
|
|
95
|
+
tests, typecheck, lint, graph/architecture checks). Do not edit before you
|
|
96
|
+
have a baseline or a documented reason one is unavailable.
|
|
97
|
+
2. **State the equivalence claim before editing**: in a few lines, name the
|
|
98
|
+
surface, what must stay unchanged (inputs/outputs, public exports, error
|
|
99
|
+
classes/messages/status codes, side effects and ordering, async/resource/React
|
|
100
|
+
lifecycle, serialization, security boundaries), and how you will verify it.
|
|
101
|
+
3. **Edit one lever at a time**: keep changes local and mechanical. Do not mix
|
|
102
|
+
simplifications with drive-by formatting, unrelated renames, or dependency
|
|
103
|
+
upgrades.
|
|
104
|
+
4. **Prove characterization tests against `<base>`**: when existing tests do not
|
|
105
|
+
cover risky behavior, add characterization tests first and run them against
|
|
106
|
+
the pre-refactor file (`git show <base>:<file>` in a temporary copy, or before
|
|
107
|
+
the refactor edit) to prove they lock in the original behavior rather than
|
|
108
|
+
circularly testing the new code.
|
|
109
|
+
5. **Split discovered bugs and divergences**: close reading often surfaces real
|
|
110
|
+
latent bugs (swallowed errors, unmapped status codes, stale closures) or
|
|
111
|
+
accidental behavioral drift between duplicated paths. Do not smuggle a
|
|
112
|
+
behavior change into a `refactor/` PR:
|
|
113
|
+
- Ship a clear bug fix as its own `fix/` PR with a regression test proven to
|
|
114
|
+
fail before the fix.
|
|
115
|
+
- Defer an ambiguous behavioral divergence and note it in the PR body or
|
|
116
|
+
tracking issue for an explicit decision.
|
|
117
|
+
6. **Verify after editing**: re-run the baseline checks plus targeted checks for
|
|
118
|
+
the touched surface. Confirm no unexpected build-output, schema, snapshot, or
|
|
119
|
+
warning changes appeared. Rebuild workspace packages (such as a client SDK's
|
|
120
|
+
`dist`) before trusting downstream tests. If behavior changed unintentionally,
|
|
121
|
+
revert the candidate.
|
|
122
|
+
|
|
123
|
+
## Test-suite and fixture consolidation phase
|
|
124
|
+
|
|
125
|
+
Treat `--include-tests` as a first-class simplification phase whenever a
|
|
126
|
+
repository has heavy test volume, high test-to-source ratios in `--by-dir`, or
|
|
127
|
+
large `test/helpers` directories:
|
|
128
|
+
|
|
129
|
+
1. Survey test hotspots with `agent-tool deslop --by-dir --include-tests --json`.
|
|
130
|
+
2. Target three high-yield, low-production-risk levers:
|
|
131
|
+
- **Shared builders and harness factories**: replace repeated multi-line
|
|
132
|
+
setup blocks across sibling test files (`duplicate-block` and
|
|
133
|
+
`parametric-clone`) with focused, explicit fixture builders.
|
|
134
|
+
- **Test-helper deduplication**: collapse parallel helper modules that build
|
|
135
|
+
the same domain graph with minor parameter differences.
|
|
136
|
+
- **Redundant case consolidation**: merge or delete demonstrably duplicate
|
|
137
|
+
test cases that exercise the exact same path and assertions without adding
|
|
138
|
+
unique coverage. Never drop security refusals, race/concurrency checks,
|
|
139
|
+
boundary-value cases, or dialect/adapter integration tests.
|
|
140
|
+
3. Prove coverage parity: run the affected test suite before and after, verify
|
|
141
|
+
the same edge cases and failure modes remain guarded, and ship cohesive test
|
|
142
|
+
cleanup slices through `ship-pr`.
|
|
143
|
+
|
|
144
|
+
## Campaign and multi-wave mode
|
|
145
|
+
|
|
146
|
+
Keep individual PRs reviewable (roughly 600–1,200 changed lines or one cohesive
|
|
147
|
+
module/theme per PR), because mega-PRs hide subtle lifecycle and closure
|
|
148
|
+
regressions. When asked to materially shrink a large repository or monorepo,
|
|
149
|
+
increase **wave throughput** rather than PR size:
|
|
150
|
+
|
|
151
|
+
1. **Rank the full backlog first**: run `agent-tool deslop --by-dir --include-tests --json`
|
|
152
|
+
alongside dead-code (`knip`) and architecture checks, and group leads into
|
|
153
|
+
disjoint directory or lens slices (test helpers, high-ratio test directories,
|
|
154
|
+
sibling parametric clones, over-fragmented micro-files, dead surface area).
|
|
155
|
+
Order slices by `estimated net LOC removed x safety`.
|
|
156
|
+
2. **Partition disjoint slices per wave**: assign non-overlapping directories or
|
|
157
|
+
modules to parallel workers (or run consecutive waves in one session) so
|
|
158
|
+
branches do not conflict and each PR stays cohesive and fast to review.
|
|
159
|
+
3. **Ship every slice independently**: each slice gets its own baseline,
|
|
160
|
+
equivalence claim, verification, independent `cross-agent-review`, and
|
|
161
|
+
`ship-pr` merge. Do not stop after one tiny slice when the user requested a
|
|
162
|
+
broad reduction — continue through planned waves until the target scope or
|
|
163
|
+
high-yield backlog is exhausted.
|
|
164
|
+
4. **Track cumulative progress**: keep per-PR accepted/deferred records in each
|
|
165
|
+
PR body and record remaining campaign slices in a tracking issue (when
|
|
166
|
+
authorized) or summary report. Do not commit a running ledger file into the
|
|
167
|
+
repository.
|
|
168
|
+
|
|
169
|
+
## Ship and self-improve
|
|
170
|
+
|
|
171
|
+
- Work on a `refactor/<topic>` branch (`fix/<topic>` for split bug fixes) and
|
|
172
|
+
ship with [ship-pr](../ship-pr/SKILL.md), including independent
|
|
173
|
+
[cross-agent-review](../cross-agent-review/SKILL.md). Independent review
|
|
174
|
+
catches subtle lifecycle, closure, and contract regressions that tests miss.
|
|
175
|
+
- Keep PRs reviewable: target roughly 600–1,200 changed lines or one cohesive
|
|
176
|
+
module or theme per PR rather than sweeping an entire package in one giant
|
|
177
|
+
diff. Use multi-wave campaigns for larger reductions.
|
|
178
|
+
- Do not commit a running ledger file (such as `.codex/deslopify-ledger.md`)
|
|
179
|
+
into the repository. Put the pass record directly in the PR body:
|
|
180
|
+
- Accepted simplifications (lever, equivalence claim, files, verification, net
|
|
181
|
+
LOC delta).
|
|
182
|
+
- Candidates inspected and left alone or deferred, with reasons.
|
|
183
|
+
- For multi-PR campaigns, track the remaining backlog in a GitHub issue via
|
|
184
|
+
[open-issue](../open-issue/SKILL.md) (when explicitly requested) or in the
|
|
185
|
+
campaign summary report.
|
|
186
|
+
- **Make the skill self-improving**:
|
|
187
|
+
- When a pass uncovers a repository-specific idiom, trap, or file-budget
|
|
188
|
+
constraint, record it in that repository's `AGENTS.md` or an inline comment
|
|
189
|
+
beside the code.
|
|
190
|
+
- When a pass learns a cross-repository trap, false positive, or scanner gap,
|
|
191
|
+
send a PR to `a2f0/agent-tool` updating
|
|
192
|
+
[references/lessons.md](references/lessons.md),
|
|
193
|
+
[references/pathology-catalog.md](references/pathology-catalog.md), or the
|
|
194
|
+
`agent-tool deslop` scanner and its tests.
|
|
195
|
+
|
|
196
|
+
## Across many repositories
|
|
197
|
+
|
|
198
|
+
A sweep across repositories follows the coordinating workspace's sweep rules
|
|
199
|
+
(status, sweep ledger, one delegate per repository, `ship-pr` each). Run
|
|
200
|
+
`agent-tool deslop --json` (or `bun run deslop --json` in a matrix workspace)
|
|
201
|
+
first and attach each repository's leads to its delegate brief. For a large
|
|
202
|
+
monorepo package, run parallel read-only surveys by lens (dead code,
|
|
203
|
+
duplication, oversized files, wrappers/scaffolding, test slop), then assign
|
|
204
|
+
disjoint directory slices with centralized verification. Repositories with no
|
|
205
|
+
worthwhile candidates close as `unchanged` quickly; record what was checked.
|
|
206
|
+
|
|
207
|
+
## Ownership
|
|
208
|
+
|
|
209
|
+
agent-tool (`a2f0/agent-tool`) owns this skill in `skills/deslopify-refactor/`
|
|
210
|
+
and the `deslop` scanner with its tests in `src/deslop/`. Repositories get it
|
|
211
|
+
from `agent-tool skills install --apply`; do not edit the installed copy.
|
|
212
|
+
Change it in `a2f0/agent-tool` by PR, and fold cross-repository lessons into
|
|
213
|
+
[references/lessons.md](references/lessons.md) and the scanner there.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# De-slopify Lessons
|
|
2
|
+
|
|
3
|
+
Cross-repository lessons from de-slopify passes, newest first. Add a lesson by
|
|
4
|
+
PR to `a2f0/agent-tool` when a pass discovers a trap, false positive, or scanner
|
|
5
|
+
improvement that future repositories need; keep repository-specific conventions
|
|
6
|
+
in that repository's `AGENTS.md`.
|
|
7
|
+
|
|
8
|
+
## Scale reduction with multi-wave campaigns and test-suite consolidation, not mega-PRs
|
|
9
|
+
|
|
10
|
+
In `tearleads`, keeping single PRs focused avoided regressions, but stopping
|
|
11
|
+
after one or two ~100-line source tweaks could not outrun feature growth in a
|
|
12
|
+
1.5M-line monorepo where nearly half the code lived in tests and `test/helpers`
|
|
13
|
+
and exact-line scanning missed parametric sibling clones. Separate PR size from
|
|
14
|
+
campaign throughput: survey with `agent-tool deslop --by-dir --include-tests`,
|
|
15
|
+
treat test-fixture consolidation as a first-class phase, and run multi-wave
|
|
16
|
+
campaigns over disjoint slices so each PR stays reviewable while cumulative
|
|
17
|
+
reductions scale.
|
|
18
|
+
|
|
19
|
+
## Skip multi-line import blocks when scanning for clones
|
|
20
|
+
|
|
21
|
+
Single-line `import` filters miss the inner identifier lines of multi-line
|
|
22
|
+
`import { ... } from ...` statements, creating noisy clone matches across
|
|
23
|
+
unrelated modules. `agent-tool deslop` skips complete multi-line import and
|
|
24
|
+
re-export blocks before computing both exact and parametric clone windows.
|
|
25
|
+
|
|
26
|
+
## Do not commit a running ledger into the target repository
|
|
27
|
+
|
|
28
|
+
Early passes in `tearleads` maintained `.codex/deslopify-ledger.md` inside the
|
|
29
|
+
repository. It grew to 918 lines of stale history, logged only accepted changes
|
|
30
|
+
(zero rejected or deferred entries), conflicted across parallel PRs, and was
|
|
31
|
+
later deleted in a docs cleanup. Keep per-PR accepted/deferred records in the PR
|
|
32
|
+
body and multi-PR backlogs in a GitHub issue instead.
|
|
33
|
+
|
|
34
|
+
## Small focused PRs beat mega-PRs
|
|
35
|
+
|
|
36
|
+
Splitting `tearleads` `packages/client-sdk` one module or lever per PR (20
|
|
37
|
+
file-split PRs, each cleanly reviewed) landed smoothly, whereas a 258-file
|
|
38
|
+
package-wide `packages/app` PR hid two infinite-render loops and two Major
|
|
39
|
+
closure/scoping regressions until independent cross-agent review caught them.
|
|
40
|
+
Aim for one theme or module (~600–1,200 lines) per PR.
|
|
41
|
+
|
|
42
|
+
## Independent review catches subtle lifecycle and closure regressions
|
|
43
|
+
|
|
44
|
+
Automated tests passed on both `withOverrides` closing over creation-time state
|
|
45
|
+
and billing loads that added `source` to effect dependencies without keying
|
|
46
|
+
stored state by `source`, and on a call-site wrapper that used object spread and
|
|
47
|
+
dropped prototype methods. Independent cross-agent review caught all three. Never
|
|
48
|
+
skip cross-agent review on "pure" refactors.
|
|
49
|
+
|
|
50
|
+
## Check error classifiers and hash comparators before unifying look-alike helpers
|
|
51
|
+
|
|
52
|
+
In `tearleads`, two `uniqueSortedStrings` helpers differed only in codepoint sort
|
|
53
|
+
vs `localeCompare`—unifying them would have changed committed manifest hashes.
|
|
54
|
+
Similarly, `collectContainerKeks` looked identical to the document-sync variant,
|
|
55
|
+
but its error-message prefix drove the upload stale-KEK retry classifier. Always
|
|
56
|
+
trace callers of error text and sort outputs before deduplicating.
|
|
57
|
+
|
|
58
|
+
## Watch build caches and git-tracked linters during file moves and splits
|
|
59
|
+
|
|
60
|
+
In monorepos, downstream packages often resolve sibling packages from built
|
|
61
|
+
`dist/` output: rebuild the edited package before trusting downstream tests.
|
|
62
|
+
When deleting or moving files, stage deletions before running linters that walk
|
|
63
|
+
`git ls-files`, and remember that `export { foo } from "./bar"` does not bring
|
|
64
|
+
`foo` into local scope of the re-exporting module.
|
|
65
|
+
|
|
66
|
+
## Keep the scanner focused on structural leads
|
|
67
|
+
|
|
68
|
+
Generated files (`// Generated by ...`, `@generated`), vendored code, and
|
|
69
|
+
comment/string literals that merely mention suppression tokens (such as
|
|
70
|
+
`"eslint-disable"` inside a linter or scanner) produce noise if scanned naively.
|
|
71
|
+
`agent-tool deslop` skips generated headers and counts suppressions only in
|
|
72
|
+
comments or attributes; add new noisy patterns to `src/deslop/` when sweeps hit
|
|
73
|
+
them.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Pathology Catalog
|
|
2
|
+
|
|
3
|
+
Use this catalog to identify high-value simplifications, score candidates, and
|
|
4
|
+
avoid false positives that introduce regressions.
|
|
5
|
+
|
|
6
|
+
## High-Confidence Candidates
|
|
7
|
+
|
|
8
|
+
| Pathology | Typical signal | Safe simplification |
|
|
9
|
+
| --- | --- | --- |
|
|
10
|
+
| Dead code and unreachable branches | Unused exports/files (`knip`), private branch unreachable by types and callers, dead SSR guards in browser-only code | Delete after verifying dynamic imports, routes, config, build scripts, reflection, and deployment entry points |
|
|
11
|
+
| Exact copy-paste blocks | Identical multi-line logic across files (`duplicate-block`) with matching inputs, error semantics, and side effects | Extract one shared helper once evaluation order, comparator semantics, and error messages match |
|
|
12
|
+
| Parametric and structural clones | Structurally identical blocks with renamed identifiers or literals (`parametric-clone`) across sibling modules, handlers, or tests | Extract a thin typed helper or data-driven spec where domain differences stay explicit parameters; never add mode flags to paper over divergence |
|
|
13
|
+
| Over-fragmented micro-files | Tiny production modules (`micro-file`) with only 1 relative JS/TS importer or non-index re-export shims adding import/file-count overhead without enforcing a layer boundary | Verify non-relative callers first (path aliases, workspace package imports, non-JS importers, generated/oversized files are outside the relative-import scan), then fold back into the sole caller or delete the re-export shim while respecting public exports, dependency-graph rules, and file-size budgets |
|
|
14
|
+
| Oversized multi-concern files | God-files (`oversized-file`, `long-function`) mixing validation, mapping, persistence, and orchestration | Split along acyclic seams: map call graph, home shared types to avoid cycles, keep public re-exports stable (and import locally if the parent still calls them), or use `Pick<Interface, ...>` part-objects for large object literals while keeping self-referencing methods in the parent |
|
|
15
|
+
| Non-architectural thin wrappers | Pass-through functions (`thin-wrapper`) adding no logging, metrics, error wrapping, binding, or layer boundary | Inline or remove after checking public imports, exports maps, and dependency-graph layer rules |
|
|
16
|
+
| Duplicate constants and config | Same literals repeated for one domain concept | Centralize when load order, tree shaking, environment overrides, and serialization stay identical |
|
|
17
|
+
| Test-fixture and harness slop | High test-to-source directories (`deslop --by-dir --include-tests`), copy-pasted fixture builders (`duplicate-block` / `parametric-clone`), overlapping test cases, or production fallback branches kept solely for test harnesses missing a provider | Extract focused shared test builders, collapse redundant helper modules and duplicate assertions while keeping every unique edge/security test, and fix test harnesses to provide required context explicitly |
|
|
18
|
+
| Stale task-plan comments and shims | Comments narrating past AI steps or obsolete compatibility aliases no longer referenced | Delete stale narration and dead shims while preserving rationale comments explaining non-obvious invariants |
|
|
19
|
+
|
|
20
|
+
## Medium-Risk Candidates
|
|
21
|
+
|
|
22
|
+
| Pathology | Risk | Guardrail |
|
|
23
|
+
| --- | --- | --- |
|
|
24
|
+
| Over-defensive branches | "Impossible" inputs may belong to a public or wire contract | Remove only in internal code or after proving every caller and documented contract excludes the case |
|
|
25
|
+
| Over-parameterized helpers | Optional knobs may serve hidden callers, tests, or generated code | Collapse only after auditing all callers, configs, tests, and external API boundaries |
|
|
26
|
+
| Blanket `try/catch` and string error matching | Catch blocks may normalize errors, metrics, retries, or cleanup; string classifiers may drive HTTP status or retry paths | Preserve thrown classes, messages, and side effects exactly; if a blanket catch hides real bugs (e.g., mapping every failure to 409), split the fix into a `fix/` PR |
|
|
27
|
+
| Parallel `v1`/`v2` or legacy files | Old-looking entry point may still be wired in CI, manifests, or deployment config | Verify imports, routes, package exports, build configs, and deployment manifests before deleting |
|
|
28
|
+
| Shallow happy-path tests | Existing suite passes even when edge behavior changes | Add characterization tests and prove them against `<base>` before simplifying |
|
|
29
|
+
|
|
30
|
+
## High-Risk Boundaries
|
|
31
|
+
|
|
32
|
+
Avoid simplifying these unless characterization coverage is strong and the
|
|
33
|
+
payoff clearly justifies the risk:
|
|
34
|
+
|
|
35
|
+
- Auth, authorization, permission checks, session handling, and secret handling
|
|
36
|
+
- Input validation, escaping, sanitization, and file/network/path boundaries
|
|
37
|
+
- Crypto, hashing, canonical ordering, signatures, tokens, and random IDs
|
|
38
|
+
- Transactions, savepoints, migrations, locking, concurrency, retries, and idempotency
|
|
39
|
+
- Async cancellation, streams, subscriptions, and resource cleanup lifecycles
|
|
40
|
+
- React hook order, effect dependencies, memoized identity, and controlled state
|
|
41
|
+
- External serialization formats, wire protocols, caches, databases, and snapshots
|
|
42
|
+
|
|
43
|
+
## Leave Alone and Common Traps
|
|
44
|
+
|
|
45
|
+
Skip these—each looks like slop on the surface but causes real regressions when
|
|
46
|
+
merged or removed naively:
|
|
47
|
+
|
|
48
|
+
- **Canonical ordering and hash traps**: two `uniqueSortedStrings` helpers where
|
|
49
|
+
one sorts by codepoint (`<` / `>`) for a manifest or content hash and another
|
|
50
|
+
uses `localeCompare`. Unifying them onto `localeCompare` silently changes
|
|
51
|
+
committed hashes.
|
|
52
|
+
- **Error-message and prefix classifiers**: two nearly identical helpers whose
|
|
53
|
+
thrown error text feeds a downstream retry or HTTP-status classifier (for
|
|
54
|
+
example, matching an error prefix to trigger stale-key retry). Changing the
|
|
55
|
+
message silently breaks recovery.
|
|
56
|
+
- **React identity and render-loop traps**:
|
|
57
|
+
- Removing a `useRef` mirror (`setCallbackRef`) when callers pass unstable
|
|
58
|
+
inline setters triggers infinite render loops.
|
|
59
|
+
- Moving a comparator or default object inside a hook/render body when
|
|
60
|
+
downstream effects key on it re-fires registration every render.
|
|
61
|
+
- Adding a runtime/source handle to effect dependencies without also scoping
|
|
62
|
+
stored state by that handle still serves stale in-flight state across
|
|
63
|
+
switches.
|
|
64
|
+
- Factory/override helpers that close over creation-time state instead of
|
|
65
|
+
reading from the current receiver serve stale values.
|
|
66
|
+
- **Enforced architectural layers**: pass-through services (`route -> service ->
|
|
67
|
+
workflow`) look like thin wrapper cascades but exist to satisfy dependency
|
|
68
|
+
direction rules. Check architecture config before flattening.
|
|
69
|
+
- **Type-system and linter idioms**:
|
|
70
|
+
- Hand-rolled `Reflect.get(record, "key")` helpers exist where
|
|
71
|
+
`noPropertyAccessFromIndexSignature` collides with `useLiteralKeys`.
|
|
72
|
+
- Generic `Object.fromEntries` builders often force `as` casts that fail
|
|
73
|
+
production type-assertion bans; per-type literals or callbacks stay type-safe.
|
|
74
|
+
- Under `exactOptionalPropertyTypes`, forwarding `{ prop: input.prop }` is not
|
|
75
|
+
equivalent to omitting `prop` when `undefined`.
|
|
76
|
+
- Spreading a class instance (`{ ...instance }`) silently drops prototype
|
|
77
|
+
methods and getters.
|
|
78
|
+
- Extracting helper files into a directory at its `ls-lint` file-count cap
|
|
79
|
+
fails lint; check directory budgets first.
|
|
80
|
+
- **Accidental resemblance**: helpers with different rounding or truncation
|
|
81
|
+
thresholds (`formatByteLength` vs `formatByteSize`, `compactId` vs
|
|
82
|
+
`compactFingerprint`), or structurally similar keys with different arity (a
|
|
83
|
+
4-part local sort key vs a 3-part deduplication key).
|
|
84
|
+
- **Implicit state machines disguised as flag clutter**: when a file has tangled
|
|
85
|
+
lifecycle booleans or scattered status writes, handle it with
|
|
86
|
+
[explicit-state-machines](../../explicit-state-machines/SKILL.md) rather than
|
|
87
|
+
ad-hoc boolean folding.
|
|
88
|
+
|
|
89
|
+
## Candidate Scoring
|
|
90
|
+
|
|
91
|
+
Score leads before editing to pick order:
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
value: 1 low, 2 medium, 3 high (real complexity/duplication removed)
|
|
95
|
+
confidence: 1 weak, 2 plausible, 3 proven
|
|
96
|
+
risk: 1 low, 2 medium, 3 high
|
|
97
|
+
|
|
98
|
+
take first: value + confidence >= 5 and risk <= 2
|
|
99
|
+
defer: confidence < 2 or risk == 3
|
|
100
|
+
reject: value == 1 and risk >= 2, or requires flags/casts to unify
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Scoring is a forcing function, not a substitute for judgment: a small, obvious
|
|
104
|
+
deletion with airtight proof is worth taking; a large deletion with unclear
|
|
105
|
+
contract boundaries should be deferred or rejected.
|
package/src/cli.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { doctor } from "./doctor";
|
|
|
5
5
|
import { checkTerraformPlan } from "./dependencies/terraformPlan";
|
|
6
6
|
import { dependencyDiff } from "./dependencies/diff";
|
|
7
7
|
import { checkGraph } from "./graph/check";
|
|
8
|
+
import { deslopCommand } from "./deslop/command";
|
|
8
9
|
import { stateMachinesCommand } from "./stateMachines/command";
|
|
9
10
|
import { seoCommand } from "./seo/probe";
|
|
10
11
|
import { buildScreenshots, describeScreenshots } from "./screenshots/build";
|
|
@@ -99,6 +100,8 @@ Usage: agent-tool [--repo <directory>] [--config <file>] <command>
|
|
|
99
100
|
screenshots link [repo...] [--all] [--apply] [--supersede] [--json] Point .screenshots at the shared store
|
|
100
101
|
screenshots capture [repo] [--apply] [--allow-dirty] [--json] [-- args...] Run the screenshots script under the store lock and record it
|
|
101
102
|
graph check Import cycles and layer violations per agent-tool.json
|
|
103
|
+
deslop [path...] [--limit N] [--min-score N] [--include-tests] [--by-dir] [--json]
|
|
104
|
+
Rank files and directories by simplification leads (duplicates, parametric clones, size, wrappers, micro-files, suppressions)
|
|
102
105
|
state-machines [path...] [--limit N] [--min-score N] [--json] Rank files that look like implicit state machines
|
|
103
106
|
seo probe [--page|--headers|--links|--sitemap] <host> [path...] Live search and preview metadata of a site
|
|
104
107
|
space [checkout-or-path...] [--builds] [--deps] [--machine] [--include-busy] [--apply] [--json]
|
|
@@ -208,6 +211,7 @@ export function main(argv = process.argv.slice(2)): number | Promise<number> {
|
|
|
208
211
|
const report = checkGraph(process.cwd(), loadConfig().graph);
|
|
209
212
|
output(report); return report.ok ? 0 : 1;
|
|
210
213
|
}
|
|
214
|
+
if (command === "deslop") return deslopCommand(args, process.cwd(), undefined, invoked);
|
|
211
215
|
if (command === "state-machines") return stateMachinesCommand(args, process.cwd(), undefined, invoked);
|
|
212
216
|
if (command === "seo") return seoCommand(args);
|
|
213
217
|
if (command === "space") return spaceCommand(args);
|