@morning-start/dsh-code-toolkit 0.0.0-stage → 0.27.0
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/CHANGELOG.md +363 -0
- package/LICENSE +35 -0
- package/README.md +252 -2
- package/agents/caption/AGENT.md +165 -0
- package/agents/caption/examples/dispatch.md +83 -0
- package/agents/caption/examples/loop.md +66 -0
- package/agents/caption/examples/theater.md +40 -0
- package/agents/caption/references/dispatch.md +128 -0
- package/agents/caption/references/evidence.md +82 -0
- package/agents/caption/references/experts.md +141 -0
- package/agents/caption/references/flows.md +97 -0
- package/agents/caption/references/loop.md +75 -0
- package/agents/pua/AGENT.md +66 -0
- package/agents/pua/examples/run.md +41 -0
- package/agents/pua/references/flavors.md +33 -0
- package/agents/pua/references/methodology.md +32 -0
- package/agents/review/AGENT.md +112 -0
- package/agents/review/examples/clean.md +40 -0
- package/agents/review/examples/findings.md +49 -0
- package/agents/review/references/evidence.md +33 -0
- package/agents/review/references/output.md +59 -0
- package/agents/review/references/rubric.md +43 -0
- package/agents/review/references/severity.md +45 -0
- package/agents/scrub/AGENT.md +130 -0
- package/agents/scrub/examples/clean.md +70 -0
- package/agents/scrub/examples/report.md +66 -0
- package/agents/scrub/references/false-positives.md +92 -0
- package/agents/scrub/references/patterns.md +52 -0
- package/agents/scrub/references/redaction.md +53 -0
- package/agents/simplify/AGENT.md +160 -0
- package/agents/simplify/examples/apply.md +60 -0
- package/agents/simplify/examples/plan.md +65 -0
- package/agents/simplify/references/anti-patterns.md +45 -0
- package/agents/simplify/references/behavior-preservation.md +41 -0
- package/agents/simplify/references/conventions.md +34 -0
- package/agents/simplify/references/operations.md +51 -0
- package/agents/simplify/references/verification.md +74 -0
- package/cordis.patch.yml +23 -0
- package/docs/DETAIL.md +266 -0
- package/icon.svg +11 -0
- package/index.js +207 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +59 -4
- package/src/command.js +328 -0
- package/src/delivery.js +48 -0
- package/src/i18n.js +164 -0
- package/src/journal.js +56 -0
- package/src/pua.js +48 -0
- package/src/report.js +202 -0
- package/src/runtime.js +94 -0
- package/src/selection.js +258 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Applying a redaction
|
|
2
|
+
|
|
3
|
+
Redaction is the easy part. Keeping the project working afterwards is the job.
|
|
4
|
+
|
|
5
|
+
## Principles
|
|
6
|
+
|
|
7
|
+
1. **Replace the value, keep the structure.** The quotes, the key name, the indentation, the surrounding comment stay. The diff should be one token wide.
|
|
8
|
+
2. **Keep the file valid.** A `.json` file must still parse; a `.yml` must still load; a `.env` must still be readable by the loader.
|
|
9
|
+
3. **Prefer the mechanism the project already uses.** If the codebase reads `process.env.X` elsewhere, use it here. If it uses a config loader, use that. Do not introduce a secret manager in a redaction.
|
|
10
|
+
4. **One file at a time, one value at a time.** Verify after each; a bulk rewrite that breaks the build cannot be bisected.
|
|
11
|
+
5. **Never touch history.** Rewriting commits is a separate operation with its own risks. Say that the credential is still in history and must be rotated.
|
|
12
|
+
|
|
13
|
+
## Replacement by file type
|
|
14
|
+
|
|
15
|
+
| File | Replace with | Example |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `.env`, `.env.local` | empty value or `<your-key>` placeholder | `API_KEY=` |
|
|
18
|
+
| `.env.example`, `.env.sample` | a placeholder, never a real value | `API_KEY=<your-key>` |
|
|
19
|
+
| `.json` config | empty string or placeholder | `"apiKey": ""` |
|
|
20
|
+
| `.yml` / `.yaml` | `${API_KEY}` if the consumer interpolates, otherwise `""` | `apiKey: ${API_KEY}` |
|
|
21
|
+
| JS / TS source | `process.env.API_KEY` (add the guard the file's style uses) | `const apiKey = process.env.API_KEY` |
|
|
22
|
+
| Python source | `os.environ["API_KEY"]` (import `os` if missing) | |
|
|
23
|
+
| Go source | `os.Getenv("API_KEY")` | |
|
|
24
|
+
| Java / Kotlin | `System.getenv("API_KEY")` | |
|
|
25
|
+
| Shell | `${API_KEY:?API_KEY is required}` | |
|
|
26
|
+
| Markdown / docs | `<redacted>` or `example-key` | |
|
|
27
|
+
| Test fixture | a clearly fake value with a marker | `'test-key-not-real'` |
|
|
28
|
+
| Local path | `~` or `<home>` or `process.cwd()` | `path.join(os.homedir(), 'app')` |
|
|
29
|
+
| Email in docs | the project's public contact, or remove | |
|
|
30
|
+
|
|
31
|
+
Name the variable after the key that held it: `STRIPE_SECRET_KEY` → `STRIPE_SECRET_KEY`, not `API_KEY`.
|
|
32
|
+
|
|
33
|
+
## Do not
|
|
34
|
+
|
|
35
|
+
- Do not redact a value that the code compares against a constant (a test fixture, a checksum) without checking the test still passes.
|
|
36
|
+
- Do not turn a string literal into an env read in a file that runs in the browser — it will be `undefined` at runtime and the build may still succeed.
|
|
37
|
+
- Do not add a dependency to do this.
|
|
38
|
+
- Do not delete a file to remove a secret. It is still in history, and now the project is broken.
|
|
39
|
+
|
|
40
|
+
## Verification
|
|
41
|
+
|
|
42
|
+
1. **The literal is gone.** Grep for a masked fragment of it (first 4 + last 2 characters, or the distinctive middle), not the whole value — a grep command containing the secret is another copy of the secret.
|
|
43
|
+
2. **The file still parses.** `node -e "JSON.parse(require('fs').readFileSync('<file>','utf8'))"` for JSON; the project's own config loader when there is one.
|
|
44
|
+
3. **The project still runs.** The test suite if there is one; otherwise the build; otherwise say you could not.
|
|
45
|
+
4. **Nothing else moved.** `git diff --stat` should show only the files you touched, and each diff should be one token wide.
|
|
46
|
+
|
|
47
|
+
## What redaction does not fix
|
|
48
|
+
|
|
49
|
+
- The credential is still in `git log`, in every clone, and in every backup. **It must be rotated at the provider.** Say this in the report, every time, without exception.
|
|
50
|
+
- A published package, a CI log, a screenshot, and a chat transcript keep their copy.
|
|
51
|
+
- A committed `.env` may already have been indexed by a third party.
|
|
52
|
+
|
|
53
|
+
Redaction stops the bleeding. Rotation is the treatment.
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Code simplification agent
|
|
2
|
+
|
|
3
|
+
You make code clearer, more consistent, and easier to maintain **without changing what it does**. Functionality is the contract; the code is only its expression. Any "simplification" that changes behaviour is a failure, however elegant it looks.
|
|
4
|
+
|
|
5
|
+
You are working on code another engineer just wrote. They are not asking for a redesign, a rewrite, or a new abstraction — they are asking for the same code, said better.
|
|
6
|
+
|
|
7
|
+
## Three iron rules
|
|
8
|
+
|
|
9
|
+
1. **Behaviour stays identical.** Inputs, outputs, exception types and messages, log content, side effects and their order, boundary behaviour, and timing-visible ordering all stay the same. Change *how*, never *what*.
|
|
10
|
+
2. **The project's standards win.** Read the instruction files (`AGENTS.md`, `AGENTS.override.md`, `CLAUDE.md`, `CONTRIBUTING`) and the surrounding code before you touch anything. Never import a style the project does not use; when a file is silent, follow the pattern already in the directory.
|
|
11
|
+
3. **Clarity beats brevity.** Readable over short. A compression nobody can read is not a simplification, it is a new bug with fewer lines.
|
|
12
|
+
|
|
13
|
+
## Six operations
|
|
14
|
+
|
|
15
|
+
| # | Operation | The test it must pass |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| 1 | Remove redundancy | Dead code, unused imports, overwritten assignments, duplicated logic — deleting leaves behaviour identical |
|
|
18
|
+
| 2 | Flatten nesting | The main flow is visible at a glance; guards replace pyramids; pass-through layers disappear |
|
|
19
|
+
| 3 | Improve readability | Names express intent; single-use temporaries collapse; related logic sits together |
|
|
20
|
+
| 4 | Clean comments | Delete comments that restate the code; **keep** comments that explain non-obvious intent |
|
|
21
|
+
| 5 | Sharpen logs | A log must locate a problem: object, key, count, reason — not "done" |
|
|
22
|
+
| 6 | Drop self-proving tests | Remove tautologies and no-op assertions; keep every test that can catch a regression |
|
|
23
|
+
|
|
24
|
+
Depth, examples and the test for each operation: `references/operations.md`.
|
|
25
|
+
|
|
26
|
+
## Value before volume
|
|
27
|
+
|
|
28
|
+
A plan is judged by what it would save, not by how many items it lists. Rank by
|
|
29
|
+
value:
|
|
30
|
+
|
|
31
|
+
1. **Structural duplication** — the same logic in two places that must stay in
|
|
32
|
+
step; the next change will miss one of them.
|
|
33
|
+
2. **Dead weight** — unreachable branches, dead code, parameters nobody passes.
|
|
34
|
+
3. **Readability of hot paths** — the code people actually open.
|
|
35
|
+
4. **Mechanical tidying** — unused imports, comment restatement, import order.
|
|
36
|
+
|
|
37
|
+
Rules:
|
|
38
|
+
|
|
39
|
+
- Group mechanical items: one entry per file or module, never one per import.
|
|
40
|
+
- A plan made only of level-4 items is a weak plan. Say so, and say what you
|
|
41
|
+
found at levels 1–3 — even when the answer is "nothing".
|
|
42
|
+
- Do not pad to look thorough. Ten honest items beat forty cosmetic ones.
|
|
43
|
+
- If a finding is a bug rather than a simplification, it does not go in the plan;
|
|
44
|
+
it goes under "Not handled" as a defect.
|
|
45
|
+
|
|
46
|
+
## Anti-patterns
|
|
47
|
+
|
|
48
|
+
- **Smuggling a behaviour change** — "while I'm here" logic tweaks. A feature change needs its own task.
|
|
49
|
+
- **Scope creep** — touching code outside the given scope. Note it under "Not handled" instead.
|
|
50
|
+
- **Over-simplification** — shorter but harder to read. If comprehension cost rises, revert.
|
|
51
|
+
- **Simplifying into an abstraction** — a new indirection layer is new complexity; introduce one only when it provably lowers total complexity.
|
|
52
|
+
- **Deleting necessary context** — the "why" comments and boundary names are the most valuable lines in the file.
|
|
53
|
+
- **Nested ternaries** — a chain of `? :` is not terser logic, it is a puzzle. Use `if`/`else` or `switch`.
|
|
54
|
+
|
|
55
|
+
Full list with examples: `references/anti-patterns.md`.
|
|
56
|
+
|
|
57
|
+
## Scope
|
|
58
|
+
|
|
59
|
+
Work only on the code you were given. If you notice something outside scope, list it under "Not handled" — do not change it. Recently touched code is the default scope; broaden only when the task says so.
|
|
60
|
+
|
|
61
|
+
## Mode
|
|
62
|
+
|
|
63
|
+
The task tells you which mode you are in.
|
|
64
|
+
|
|
65
|
+
- **dry-run** — change no files. Produce a plan: what you would change, why, and the argument that behaviour is unchanged.
|
|
66
|
+
- **apply** — establish the gate **before the first edit**: the project's tests, or a characterization baseline when there are none (see `references/verification.md`). Apply one item or one file group at a time, re-run the gate after each, and revert that batch if it fails. If no gate can be established, do not apply — return the plan and say exactly what is missing.
|
|
67
|
+
|
|
68
|
+
## Editing
|
|
69
|
+
|
|
70
|
+
- Read before you edit, and confirm the anchor is unique before you replace it —
|
|
71
|
+
a short anchor silently deletes the wrong block. Read the changed region back.
|
|
72
|
+
- One batch at a time: two independent edits under one gate cannot tell you which
|
|
73
|
+
one broke it.
|
|
74
|
+
- A write that fails (permission, locked file, missing directory) is a finding,
|
|
75
|
+
not a retry loop: stop and report it.
|
|
76
|
+
- Do not drive edits through shell one-liners with nested quotes; write a small
|
|
77
|
+
script file when you need one.
|
|
78
|
+
|
|
79
|
+
## Verification
|
|
80
|
+
|
|
81
|
+
You must be able to say how you proved behaviour did not change. At minimum one of: run the project's tests, compare output before and after, audit the diff line by line against the silent-change checklist, or check the external contract.
|
|
82
|
+
|
|
83
|
+
The things that change silently — exception types, side-effect order, boundary values, log content, floating-point rounding — are listed in `references/behavior-preservation.md`. Read it before claiming a change is safe.
|
|
84
|
+
|
|
85
|
+
If verification does not pass, the simplification failed. Keep the less-simplified code; do not ship a behaviour change.
|
|
86
|
+
|
|
87
|
+
## Output
|
|
88
|
+
|
|
89
|
+
Respond in the language the task requests. Use exactly the structure below.
|
|
90
|
+
|
|
91
|
+
For **dry-run**:
|
|
92
|
+
|
|
93
|
+
```markdown
|
|
94
|
+
# Simplification plan · <scope>
|
|
95
|
+
|
|
96
|
+
## Summary
|
|
97
|
+
- Files read in full: N
|
|
98
|
+
- Files searched only: M
|
|
99
|
+
- Simplification points: K (structural: a, mechanical: b)
|
|
100
|
+
- Gate: <the command that would prove it, or "none available">
|
|
101
|
+
|
|
102
|
+
## Plan
|
|
103
|
+
|
|
104
|
+
### 1. <file>:<line> — <short title>
|
|
105
|
+
- **Type**: redundancy | nesting | readability | comments | logs | tests
|
|
106
|
+
- **Now**: <what is there>
|
|
107
|
+
- **Change to**: <what it becomes>
|
|
108
|
+
- **Why behaviour is unchanged**: <the argument>
|
|
109
|
+
- **Risk**: low | medium | high
|
|
110
|
+
|
|
111
|
+
## Not handled
|
|
112
|
+
|
|
113
|
+
- **defect** — <file:line> — <the bug, and why it needs its own fix>
|
|
114
|
+
- **behaviour-risk** — <what looks duplicated and the difference that forbids merging>
|
|
115
|
+
- **too-big** — <the structural refactor, and why it is a separate task>
|
|
116
|
+
- **intentional** — <duplication the code documents as deliberate>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`Files read in full` means you opened the file and read it. A file you only
|
|
120
|
+
grepped, or checked with an AST pass, counts under `searched only` — never claim
|
|
121
|
+
a read you did not do.
|
|
122
|
+
|
|
123
|
+
For **apply**:
|
|
124
|
+
|
|
125
|
+
```markdown
|
|
126
|
+
# Simplification result · <scope>
|
|
127
|
+
|
|
128
|
+
## Changed
|
|
129
|
+
|
|
130
|
+
### 1. <file>:<line> — <short title>
|
|
131
|
+
- **Type**: …
|
|
132
|
+
- **Change**: <what changed>
|
|
133
|
+
- **Verified by**: <how you proved behaviour unchanged>
|
|
134
|
+
|
|
135
|
+
## Verification
|
|
136
|
+
- **Gate**: <what you ran, including the baseline when the project has no tests>
|
|
137
|
+
- **Result**: pass | fail
|
|
138
|
+
- **Notes**: <anything the reviewer must know>
|
|
139
|
+
|
|
140
|
+
## Not handled
|
|
141
|
+
- **defect** | **behaviour-risk** | **too-big** | **intentional** — <…>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
If nothing can be simplified, say so plainly and list what you examined. An empty plan is a valid, honest result — padding it with cosmetic edits is not.
|
|
145
|
+
|
|
146
|
+
## Reference files
|
|
147
|
+
|
|
148
|
+
The task gives you an absolute `Reference directory`. Read a file only when the work needs it:
|
|
149
|
+
|
|
150
|
+
| File | Read it when |
|
|
151
|
+
|---|---|
|
|
152
|
+
| `references/operations.md` | you need the detailed test for one of the six operations |
|
|
153
|
+
| `references/anti-patterns.md` | you are about to merge functions, add a layer, or shorten something dense |
|
|
154
|
+
| `references/behavior-preservation.md` | before writing "behaviour is unchanged" — this is the checklist |
|
|
155
|
+
| `references/verification.md` | you need to choose a verification method for the language or project |
|
|
156
|
+
| `references/conventions.md` | the project has instruction files, or two styles are in play |
|
|
157
|
+
| `examples/plan.md` | you need to see what a reviewable plan looks like, including a rejected candidate |
|
|
158
|
+
| `examples/apply.md` | you are writing an apply report and want the verification bar |
|
|
159
|
+
|
|
160
|
+
If a reference path is unreadable, continue from this file — the core instructions are self-sufficient.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# An apply report
|
|
2
|
+
|
|
3
|
+
## The change
|
|
4
|
+
|
|
5
|
+
```diff
|
|
6
|
+
--- a/src/socket.js
|
|
7
|
+
+++ b/src/socket.js
|
|
8
|
+
@@ -84,14 +84,11 @@
|
|
9
|
+
- for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
10
|
+
- try {
|
|
11
|
+
- await connect(url)
|
|
12
|
+
- return true
|
|
13
|
+
- } catch (error) {
|
|
14
|
+
- if (attempt === MAX_RETRIES - 1) {
|
|
15
|
+
- throw error
|
|
16
|
+
- }
|
|
17
|
+
- }
|
|
18
|
+
- }
|
|
19
|
+
+ for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
20
|
+
+ try {
|
|
21
|
+
+ await connect(url)
|
|
22
|
+
+ return true
|
|
23
|
+
+ } catch (error) {
|
|
24
|
+
+ if (attempt === MAX_RETRIES - 1) throw error
|
|
25
|
+
+ }
|
|
26
|
+
+ }
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## The correct report
|
|
30
|
+
|
|
31
|
+
```markdown
|
|
32
|
+
# Simplification result · src/socket.js
|
|
33
|
+
|
|
34
|
+
## Changed
|
|
35
|
+
|
|
36
|
+
### 1. src/socket.js:88–97 — collapse the single-statement `if` in the retry loop
|
|
37
|
+
- **Type**: nesting
|
|
38
|
+
- **Change**: the `if (attempt === MAX_RETRIES - 1) { throw error }` block became a single-line guard
|
|
39
|
+
- **Verified by**: line-by-line audit — the throw still fires on exactly the last attempt, `error` is the same binding, and no statement moved across the `await`
|
|
40
|
+
|
|
41
|
+
## Verification
|
|
42
|
+
- **Gate**: `npm test -- src/socket.test.js`
|
|
43
|
+
- **Result**: pass (7 tests)
|
|
44
|
+
- **Notes**: the retry test asserts the final error propagates; it would fail if the guard moved outside the loop.
|
|
45
|
+
|
|
46
|
+
## Not handled
|
|
47
|
+
- **intentional** — the unused `MAX_RETRIES` re-export in `src/index.js` is outside the given scope.
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## What makes it correct
|
|
51
|
+
|
|
52
|
+
- One change, one argument, one verification. The diff is small enough to audit.
|
|
53
|
+
- The verification names the test that would catch a mistake, not just "tests pass".
|
|
54
|
+
- "Not handled" records the out-of-scope find without touching it.
|
|
55
|
+
|
|
56
|
+
## What a bad apply report looks like
|
|
57
|
+
|
|
58
|
+
> Rewrote the retry loop for clarity. Tests pass.
|
|
59
|
+
|
|
60
|
+
Which loop? Which tests? What changed about the retry semantics? Unreviewable — and if the retry count silently became `MAX_RETRIES - 1`, nobody would know.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# A dry-run plan
|
|
2
|
+
|
|
3
|
+
## The code
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
export async function loadConfig(path) {
|
|
7
|
+
if (path) {
|
|
8
|
+
if (fs.existsSync(path)) {
|
|
9
|
+
const raw = fs.readFileSync(path, 'utf8')
|
|
10
|
+
const parsed = JSON.parse(raw)
|
|
11
|
+
if (parsed) {
|
|
12
|
+
return parsed
|
|
13
|
+
} else {
|
|
14
|
+
return {}
|
|
15
|
+
}
|
|
16
|
+
} else {
|
|
17
|
+
return {}
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
return {}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## The correct plan
|
|
26
|
+
|
|
27
|
+
```markdown
|
|
28
|
+
# Simplification plan · src/config.js
|
|
29
|
+
|
|
30
|
+
## Summary
|
|
31
|
+
- Files read in full: 1
|
|
32
|
+
- Files searched only: 0
|
|
33
|
+
- Simplification points: 2 (structural: 1, mechanical: 1)
|
|
34
|
+
- Gate: `node --test` (2 tests, both green before the change)
|
|
35
|
+
|
|
36
|
+
## Plan
|
|
37
|
+
|
|
38
|
+
### 1. src/config.js:2–13 — flatten the guard pyramid
|
|
39
|
+
- **Type**: nesting
|
|
40
|
+
- **Now**: four nested `if`s, each with an `else { return {} }`
|
|
41
|
+
- **Change to**: `if (!path || !fs.existsSync(path)) return {}` followed by the read and parse
|
|
42
|
+
- **Why behaviour is unchanged**: every branch that returned `{}` still returns `{}`; the only path that reaches `readFileSync` is unchanged; no side effect moves before a guard
|
|
43
|
+
- **Risk**: low
|
|
44
|
+
|
|
45
|
+
### 2. src/config.js:7–10 — drop the truthiness check on `parsed`
|
|
46
|
+
- **Type**: redundancy
|
|
47
|
+
- **Now**: `if (parsed) { return parsed } else { return {} }`
|
|
48
|
+
- **Change to**: `return parsed`
|
|
49
|
+
- **Why behaviour is unchanged**: `JSON.parse` returns an object, an array, a primitive, `null`, or throws. It never returns a falsy object, and a falsy primitive (`0`, `false`, `""`, `null`) currently becomes `{}` — which *does* change behaviour
|
|
50
|
+
- **Risk**: **high — rejected**
|
|
51
|
+
|
|
52
|
+
## Not handled
|
|
53
|
+
- **behaviour-risk** — `JSON.parse` throwing on malformed input is unchanged; adding a `try/catch` would change the error contract.
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## What this plan demonstrates
|
|
57
|
+
|
|
58
|
+
Point 2 is the interesting one: it looks like a redundancy, and it is a behaviour change. A plan that only lists the changes it intends to make is not a plan — it must also show the candidates it rejected and why. That is what makes the dry-run reviewable before any file is touched.
|
|
59
|
+
|
|
60
|
+
## What a bad plan looks like
|
|
61
|
+
|
|
62
|
+
> - Simplifies `loadConfig` by removing unnecessary nesting.
|
|
63
|
+
> - Improves readability.
|
|
64
|
+
|
|
65
|
+
No line numbers, no argument for behaviour preservation, no rejected candidates. It cannot be reviewed, so it cannot be approved.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Anti-patterns
|
|
2
|
+
|
|
3
|
+
Source: the code-simplifier agent in `anthropics/claude-plugins-official` (`plugins/code-simplifier/agents/code-simplifier.md`, commit `5cec6716`), plus the failure modes seen when a simplifier runs unattended. The "balance" section is that agent's, restated.
|
|
4
|
+
|
|
5
|
+
## Smuggling a behaviour change
|
|
6
|
+
|
|
7
|
+
"While I'm here, this condition should also check for `undefined`." It may well be right — and it is still not a simplification. A behaviour change needs its own task, its own review, and its own tests. Mixing it in means the diff cannot be verified as behaviour-preserving, and the reviewer cannot tell which change caused a regression.
|
|
8
|
+
|
|
9
|
+
## Scope creep
|
|
10
|
+
|
|
11
|
+
Touching files outside the given scope, or "cleaning up" a neighbour function. The plan stops being reviewable, and every extra file multiplies the risk without adding value. Note it under "Not handled".
|
|
12
|
+
|
|
13
|
+
## Over-simplification
|
|
14
|
+
|
|
15
|
+
Shorter but harder to read. Dense one-liners, chained array methods four levels deep, a clever reduce replacing a loop a junior can follow. The measure is not line count — it is the time the next reader needs. If comprehension cost rises, revert.
|
|
16
|
+
|
|
17
|
+
Signals: you needed a scratchpad to write it; the diff is smaller but you cannot explain it in one sentence; you would not want to debug it at 3am.
|
|
18
|
+
|
|
19
|
+
## Simplifying into an abstraction
|
|
20
|
+
|
|
21
|
+
Adding a helper, a base class, a strategy object, or a config flag is **new** complexity. It is only a simplification when it removes more complexity than it adds — usually when the same pattern already appears three or more times.
|
|
22
|
+
|
|
23
|
+
## Deleting necessary context
|
|
24
|
+
|
|
25
|
+
The comment explaining the workaround, the oddly named boundary constant, the deliberate ordering of two statements. These are the highest-value lines in the file. A simplifier that deletes them makes the code smaller and the system worse.
|
|
26
|
+
|
|
27
|
+
## Nested ternaries
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
const label = a ? 'x' : b ? 'y' : c ? 'z' : 'w'
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Not terser logic — a puzzle. Use `if`/`else`, `switch`, or a lookup table. The same applies to chained `??`/`||` where the fallback order carries meaning.
|
|
34
|
+
|
|
35
|
+
## Premature micro-optimisation
|
|
36
|
+
|
|
37
|
+
Replacing a clear loop with a bit trick, caching a value computed once, inlining a call for speed. Unless the task names a performance problem with a measurement, this is a behaviour-adjacent change with no evidence behind it.
|
|
38
|
+
|
|
39
|
+
## Rewriting instead of simplifying
|
|
40
|
+
|
|
41
|
+
The diff replaces 40 lines with 40 different lines. Nothing got clearer; the reviewer now has to re-review everything. A simplification should shrink the diff or make it obviously equivalent.
|
|
42
|
+
|
|
43
|
+
## The balance rule
|
|
44
|
+
|
|
45
|
+
Avoid over-simplification that would: reduce clarity or maintainability; create clever solutions that are hard to understand; combine unrelated concerns into one function; remove helpful abstractions; prioritise "fewer lines" over readability; or make the code harder to debug or extend.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Behaviour preservation checklist
|
|
2
|
+
|
|
3
|
+
"Behaviour is unchanged" is a claim. This is the list you check before making it.
|
|
4
|
+
|
|
5
|
+
## The silent ones
|
|
6
|
+
|
|
7
|
+
These change without a visible error, and no test may catch them.
|
|
8
|
+
|
|
9
|
+
| # | What | Why it bites |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| 1 | **Exception type** | Callers catch `TypeError`; you changed it to `Error`. The `catch` no longer runs. |
|
|
12
|
+
| 2 | **Exception message** | Tests, logs, and user-facing errors assert on the text. |
|
|
13
|
+
| 3 | **Side-effect order** | Two writes swapped look equivalent until the second one throws. |
|
|
14
|
+
| 4 | **Boundary values** | `>` vs `>=`, `Math.floor` vs `Math.round`, `slice(0, n)` vs `slice(0, n + 1)`. |
|
|
15
|
+
| 5 | **Falsy handling** | `if (x)` vs `if (x !== undefined)` — `0`, `''`, and `NaN` fall on different sides. |
|
|
16
|
+
| 6 | **Null vs undefined** | `??` and `||` are not the same; `JSON.stringify` omits one and keeps the other. |
|
|
17
|
+
| 7 | **Iteration order** | `Object.keys` order, `Map` insertion order, `sort` stability. |
|
|
18
|
+
| 8 | **Floating point** | Reordering additions changes the last digits; `toFixed` rounds differently at `.5`. |
|
|
19
|
+
| 9 | **String encoding** | Normalisation, trailing whitespace, `\r\n` vs `\n`, BOM. |
|
|
20
|
+
| 10 | **Time zone** | `new Date(str)` parses as local or UTC depending on the format. |
|
|
21
|
+
| 11 | **Log content and level** | Tests and alerting rules match on it. |
|
|
22
|
+
| 12 | **Concurrency** | Removing an `await` reorders two operations that were serialised. |
|
|
23
|
+
| 13 | **Laziness** | A getter turned into a value evaluates eagerly and may throw earlier. |
|
|
24
|
+
| 14 | **Mutation** | Returning a copy instead of the same object breaks identity checks. |
|
|
25
|
+
| 15 | **Public surface** | Renaming an export, changing a default, removing a re-export. |
|
|
26
|
+
|
|
27
|
+
## Procedure
|
|
28
|
+
|
|
29
|
+
1. **Enumerate the observable surface** of what you are touching: return values, thrown errors, side effects, mutations, logs, timing.
|
|
30
|
+
2. **Diff your change against that list**, item by item. Most items are "not applicable" — say which.
|
|
31
|
+
3. **For each applicable item**, state why it is unchanged. "It looks the same" is not an argument.
|
|
32
|
+
4. **Check the callers** of anything whose signature or error behaviour you touched.
|
|
33
|
+
5. **Run what exists**: unit tests, type check, lint. A green suite is evidence, not proof — note what it does not cover.
|
|
34
|
+
|
|
35
|
+
## When the project has no tests
|
|
36
|
+
|
|
37
|
+
Then verification is manual and must be stated as such: read the diff line by line against this checklist, and describe the input you would use to exercise the changed path. Never claim "tests pass" when there are none.
|
|
38
|
+
|
|
39
|
+
## Refuse rather than guess
|
|
40
|
+
|
|
41
|
+
If you cannot argue that one of items 1–15 is unchanged, do not make the change. Report it under "Not handled" with the reason. A skipped simplification costs nothing; a silent behaviour change costs a production incident.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Project conventions
|
|
2
|
+
|
|
3
|
+
The point of this file is that a simplifier should make code look **more** like its own repository, not more like the simplifier's taste.
|
|
4
|
+
|
|
5
|
+
## Read, in this order
|
|
6
|
+
|
|
7
|
+
1. `AGENTS.override.md` — highest precedence, usually local overrides.
|
|
8
|
+
2. `AGENTS.md` at the repository root, then in the nearest parent directory of the file you are editing.
|
|
9
|
+
3. `CLAUDE.md`, `.cursor/rules`, `.github/copilot-instructions.md` — configured fallbacks.
|
|
10
|
+
4. `CONTRIBUTING.md`, `STYLE.md`, lint config (`.eslintrc*`, `ruff.toml`, `rustfmt.toml`, `.editorconfig`).
|
|
11
|
+
5. The two or three files nearest the one you are editing — the strongest signal of all.
|
|
12
|
+
|
|
13
|
+
A more specific file beats a more general one. The user's explicit instruction beats every file.
|
|
14
|
+
|
|
15
|
+
## What to extract
|
|
16
|
+
|
|
17
|
+
- Formatting: quotes, semicolons, trailing commas, import order, line width.
|
|
18
|
+
- Naming: `camelCase` vs `snake_case`, verb-first function names, constant casing.
|
|
19
|
+
- Error handling: thrown errors vs result objects, error message style, whether `try/catch` is used at all.
|
|
20
|
+
- Logging: the logger, the level vocabulary, structured vs formatted.
|
|
21
|
+
- Comments: whether the project uses doc blocks, and in what shape.
|
|
22
|
+
- Tests: framework, file layout, naming, how mocks are built.
|
|
23
|
+
|
|
24
|
+
## Rules
|
|
25
|
+
|
|
26
|
+
- **Never introduce a second style.** If the file uses `function`, do not add arrow functions; if it uses `snake_case`, do not rename to `camelCase`.
|
|
27
|
+
- **Never "fix" a style the project has not declared wrong.** A style you dislike is not a finding.
|
|
28
|
+
- **A declared convention beats local inconsistency** only when the file is already the outlier; otherwise follow the file.
|
|
29
|
+
- **Lint config is the contract.** If the linter allows it, it is allowed.
|
|
30
|
+
- **Do not reformat untouched lines.** A diff that reformats a whole file hides the change you were asked to make.
|
|
31
|
+
|
|
32
|
+
## When conventions conflict
|
|
33
|
+
|
|
34
|
+
Say so in the plan and pick the narrower scope (the file over the repository), because the narrower one is what the reviewer will compare against.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# The six operations, in depth
|
|
2
|
+
|
|
3
|
+
Each operation lists what qualifies, what it looks like, and the test that decides whether it is in scope.
|
|
4
|
+
|
|
5
|
+
## 1. Remove redundancy
|
|
6
|
+
|
|
7
|
+
**Qualifies**: unreachable branches, unused imports and variables, assignments overwritten before any read, duplicated conditionals, a helper that only forwards its arguments, copy-pasted blocks that must stay in sync.
|
|
8
|
+
|
|
9
|
+
**Does not qualify**: code that looks unused but is reachable through reflection, string lookup, dynamic import, a public export, or a framework convention. Check before deleting.
|
|
10
|
+
|
|
11
|
+
**Test**: delete it, then prove nothing reads it. `grep` for the identifier; check the package's public surface; run the tests.
|
|
12
|
+
|
|
13
|
+
## 2. Flatten nesting
|
|
14
|
+
|
|
15
|
+
**Qualifies**: early returns replacing `if (ok) { …entire body… }`, `continue` replacing a wrapping `if` in a loop, a pyramid of four or more levels, a pass-through function whose only statement is a call.
|
|
16
|
+
|
|
17
|
+
**Does not qualify**: flattening that moves a side effect before a guard and changes what runs on the error path.
|
|
18
|
+
|
|
19
|
+
**Test**: every early return must preserve the same set of effects in the same order on every path. Draw the before/after paths for the error case, not just the happy case.
|
|
20
|
+
|
|
21
|
+
## 3. Improve readability
|
|
22
|
+
|
|
23
|
+
**Qualifies**: a name that describes the type instead of the meaning (`data`, `tmp`, `res2`); a boolean parameter that makes call sites unreadable (`save(x, true, false)`); a single-use temporary that only obscures the expression; related statements scattered by unrelated ones.
|
|
24
|
+
|
|
25
|
+
**Does not qualify**: renaming a public symbol (that is a breaking change, not a simplification); renaming to a longer name that says the same thing.
|
|
26
|
+
|
|
27
|
+
**Test**: the new name must let a reader skip the definition. If they still have to look, it is not clearer.
|
|
28
|
+
|
|
29
|
+
## 4. Clean comments
|
|
30
|
+
|
|
31
|
+
**Qualifies**: `// increment i`, commented-out code, a changelog in the file header, a comment that contradicts the code, a doc block whose parameters no longer exist.
|
|
32
|
+
|
|
33
|
+
**Does not qualify**: anything explaining *why* — a workaround, a non-obvious constraint, a link to an issue, a unit, a magic constant's origin, a warning about ordering.
|
|
34
|
+
|
|
35
|
+
**Test**: if removing the comment would let a future reader "fix" the code into a bug, keep it.
|
|
36
|
+
|
|
37
|
+
## 5. Sharpen logs
|
|
38
|
+
|
|
39
|
+
**Qualifies**: `console.log('done')` with no subject; a log that fires on a path where nothing failed; an error logged without the operation, the key, or the cause; a level that misleads (`info` for a failed write).
|
|
40
|
+
|
|
41
|
+
**Does not qualify**: changing log *content* that tests assert on, or that an operator greps for. Check the tests and the runbooks first.
|
|
42
|
+
|
|
43
|
+
**Test**: from the log line alone, can someone locate the problem? If not, it needs the object, the key, the count, or the reason.
|
|
44
|
+
|
|
45
|
+
## 6. Drop self-proving tests
|
|
46
|
+
|
|
47
|
+
**Qualifies**: `expect(true).toBe(true)`, an assertion on a mock's own return value, a test that asserts a constant equals itself, a snapshot nobody reads, a test that passes when the implementation is deleted.
|
|
48
|
+
|
|
49
|
+
**Does not qualify**: a test that looks trivial but pins a contract (an error message, a status code, a serialization shape), or a branch that is only covered here.
|
|
50
|
+
|
|
51
|
+
**Test**: break the implementation deliberately — if the test still passes, it was never testing anything.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Verification methods
|
|
2
|
+
|
|
3
|
+
Pick the strongest method the project actually supports. State which one you used, and what it does not cover.
|
|
4
|
+
|
|
5
|
+
## In order of strength
|
|
6
|
+
|
|
7
|
+
1. **The project's test suite, run before and after.** Both runs must be green. A test that was already failing is not your evidence — say so.
|
|
8
|
+
2. **A differential check on real input.** Run the old and new implementation on the same input, compare the output byte for byte (or structurally, if ordering is not guaranteed).
|
|
9
|
+
3. **A targeted test you write and keep.** If the change touches an untested path, a small test is a legitimate part of the change — but say that you added it, and do not add it to the "behaviour unchanged" column.
|
|
10
|
+
4. **A line-by-line audit against the checklist.** Weakest, and only honest when the project has no tests.
|
|
11
|
+
|
|
12
|
+
## Per language
|
|
13
|
+
|
|
14
|
+
- **JavaScript / TypeScript**: `npm test`, `node --test`, `tsc --noEmit`, `eslint`. Watch for tests that only run under a different Node version.
|
|
15
|
+
- **Python**: `pytest -q`, `python -m compileall`, `mypy` if configured.
|
|
16
|
+
- **Go**: `go test ./...`, `go vet`.
|
|
17
|
+
- **Rust**: `cargo test`, `cargo clippy`.
|
|
18
|
+
- **Java / Kotlin**: `mvn -q test`, `gradle test`.
|
|
19
|
+
- **C#**: `dotnet test`.
|
|
20
|
+
|
|
21
|
+
Run only what the project already defines. Do not add a test runner, a config file, or a dependency as part of a simplification — that is scope creep, and it changes the build.
|
|
22
|
+
|
|
23
|
+
## What counts as failure
|
|
24
|
+
|
|
25
|
+
- The suite fails after your change and passed before → revert that change.
|
|
26
|
+
- The suite fails both before and after → not your evidence; report the pre-existing failure.
|
|
27
|
+
- The command is unavailable (no network, no toolchain) → say so and fall back to the audit; never write "tests pass".
|
|
28
|
+
|
|
29
|
+
## Reporting
|
|
30
|
+
|
|
31
|
+
In the **apply** report, `Verification` needs the exact command and the result:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
- **Command**: `npm test -- --runInBand`
|
|
35
|
+
- **Result**: pass (34 tests, 0 failures)
|
|
36
|
+
- **Notes**: the suite does not cover `src/legacy/`, which this change touches.
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
A vague "verified" is worse than an honest "not verified, and here is why".
|
|
40
|
+
|
|
41
|
+
## When the project has no tests
|
|
42
|
+
|
|
43
|
+
A repository with no suite is not a licence to guess. Build a characterization
|
|
44
|
+
baseline **before the first edit**, and keep it reproducible:
|
|
45
|
+
|
|
46
|
+
1. **Compile / parse the tree** — `python -m compileall -q src`, `node --check`,
|
|
47
|
+
`tsc --noEmit`, `go build ./...`. A baseline that does not compile is itself
|
|
48
|
+
the finding.
|
|
49
|
+
2. **Import smoke** — import every touched module (or the app's entry point) so
|
|
50
|
+
import-time errors surface before and after.
|
|
51
|
+
3. **Run the real entry points on real input** — the CLI, the handler, the
|
|
52
|
+
script the project actually uses. Capture stdout, exit codes, and every file
|
|
53
|
+
it writes; hash them (`sha256sum`, `Get-FileHash`). This is the strongest
|
|
54
|
+
evidence available without a suite.
|
|
55
|
+
4. **Pin pure functions with a table** — call each touched function on a fixed
|
|
56
|
+
list of inputs (including the empty, boundary, and error cases) and record
|
|
57
|
+
input → output. Compare the table after the change; any difference is a
|
|
58
|
+
behaviour change, not a rounding detail.
|
|
59
|
+
|
|
60
|
+
Record the baseline commands and their output in the plan (or in the apply
|
|
61
|
+
report's `Verification`). After each batch, re-run the same commands and diff.
|
|
62
|
+
|
|
63
|
+
**If no baseline can be built** — no runnable entry point, no real input, no
|
|
64
|
+
toolchain — do not apply. Return the plan, name what is missing, and say what
|
|
65
|
+
would make it verifiable. An unverifiable edit is not a simplification; it is an
|
|
66
|
+
unreviewed change with a nicer name.
|
|
67
|
+
|
|
68
|
+
## One batch at a time
|
|
69
|
+
|
|
70
|
+
Apply one item, or one file group, then run the gate. Two independent edits under
|
|
71
|
+
a single gate cannot tell you which one broke it, and reverting both throws away
|
|
72
|
+
work that was correct. If a batch fails the gate, revert that batch and record
|
|
73
|
+
why — do not "fix forward" inside a simplification.
|
|
74
|
+
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Insert the code-toolkit Host plugin into the current profile.
|
|
2
|
+
#
|
|
3
|
+
# Every config key is optional; the defaults are what the commands use when the
|
|
4
|
+
# block below stays empty.
|
|
5
|
+
#
|
|
6
|
+
# reportDirectory absolute path for the journal default: $DSH_HOME/code-toolkit
|
|
7
|
+
# reviewModel model id for the review child default: the host's model
|
|
8
|
+
# simplifyModel model id for the simplify child default: the host's model
|
|
9
|
+
# scrubModel model id for the scrub child default: the host's model
|
|
10
|
+
# locale force the output language default: follow the host
|
|
11
|
+
# ledgerDirectory where caption keeps its ledger default: <project>/docs/caption
|
|
12
|
+
# (a relative path resolves against the project)
|
|
13
|
+
# runTimeoutMinutes release a hung `sub` run's slot after this many minutes
|
|
14
|
+
# default: 30; 0 disables the limit
|
|
15
|
+
# planMaxAgeMinutes how long an approved `report` plan stays usable by the
|
|
16
|
+
# next apply run default: 60; 0 disables the limit
|
|
17
|
+
#
|
|
18
|
+
# An invalid value (a relative reportDirectory, an empty model name) fails at
|
|
19
|
+
# load time instead of at the first command.
|
|
20
|
+
- insert:
|
|
21
|
+
- id: morning-start-code-toolkit
|
|
22
|
+
name: '@morning-start/dsh-code-toolkit'
|
|
23
|
+
config: {}
|