@laitszkin/apollo-toolkit 3.1.4 → 3.1.6

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 CHANGED
@@ -7,6 +7,16 @@ All notable changes to this repository are documented in this file.
7
7
  ### Changed
8
8
  - None yet.
9
9
 
10
+ ## [v3.1.6] - 2026-04-23
11
+
12
+ ### Changed
13
+ - Rewrite `iterative-code-quality` around a strict three-step loop of full-codebase scan, per-round job selection/refactor, and final doc/constraint sync, while moving job-specific execution guidance into reference documents so the main skill no longer reads like a serial workflow.
14
+
15
+ ## [v3.1.5] - 2026-04-23
16
+
17
+ ### Changed
18
+ - Strengthen `iterative-code-quality` so large coupled or apparently core files trigger staged unlock work instead of passive stopping, and require a full-codebase stage-gate decision after every iteration to determine whether additional rounds are still needed.
19
+
10
20
  ## [v3.1.4] - 2026-04-23
11
21
 
12
22
  ### Changed
@@ -1,28 +1,33 @@
1
1
  # iterative-code-quality
2
2
 
3
- Improve an existing repository through repeated, evidence-backed full-iteration refactors while preserving intended business behavior and the system's top-level macro architecture.
3
+ Improve an existing repository through a strict three-step loop of full-codebase scan, job-based refactor, and final documentation/constraint sync while preserving intended business behavior and the system's top-level macro architecture.
4
4
 
5
5
  ## Core capabilities
6
6
 
7
- - Scans the full codebase and builds a prioritized quality backlog before editing.
8
- - Treats naming, abstraction, module boundaries, logging, and tests as selectable execution directions rather than a fixed sequence.
7
+ - Runs a repository-wide scan before every refactor round and refreshes a concrete quality backlog.
8
+ - Uses a strict three-step loop: scan the codebase, choose this round's jobs and refactor, then update docs/constraints only when no actionable gap remains.
9
+ - Keeps job execution guidance in focused reference documents instead of embedding every job as a workflow step in the main skill.
9
10
  - Clarifies ambiguous variable, parameter, field, helper, and test-data names.
10
11
  - Simplifies complex functions and extracts reusable helpers only when they centralize real behavior.
11
12
  - Splits mixed-responsibility code into narrower modules without changing macro architecture.
12
13
  - Repairs stale or missing logs and adds tests for important observability contracts.
13
14
  - Adds high-value unit, property-based, integration, or E2E tests based on risk.
15
+ - Does not require pre-existing tests before every refactor; for high-risk under-guarded areas, it treats test addition as the next unlock direction.
14
16
  - Uses those tests and other guardrails to justify more aggressive refactors, instead of leaving known issues in place for subjective confidence reasons.
15
17
  - Re-scans the full repository after every iteration and picks the next highest-confidence, highest-leverage directions.
16
18
  - Uses small safe refactors to prepare the ground for larger later refactors, progressing gradually from outside to inside.
19
+ - Treats large coupled or apparently core files as staged unlock problems, not as automatic stop signals.
20
+ - Uses explicit next-job selection conditions from references so the agent can decide more concretely whether naming, simplification, modularization, logging, testing, or unlock work should happen next.
21
+ - Runs a stage-gate full-codebase decision after every iteration to decide whether more rounds are still required.
17
22
  - Repeats the pass cycle while any known in-scope actionable quality issue remains, and forbids a completion report until the latest scan is clear or remaining items are explicitly deferred with a valid reason.
18
23
  - Targets as many inherited repository quality problems as can be solved safely, and expects the guarded test surface to remain green after the refactor.
19
24
  - Synchronizes project docs and `AGENTS.md` through `align-project-documents` and `maintain-project-constraints` after implementation.
20
25
 
21
26
  ## Repository structure
22
27
 
23
- - `SKILL.md`: Main iterative workflow, dependencies, guardrails, and output contract.
28
+ - `SKILL.md`: Main three-step loop, dependencies, guardrails, and output contract.
24
29
  - `agents/openai.yaml`: Agent interface metadata and default prompt.
25
- - `references/`: Focused guides for scanning, naming, simplification, module boundaries, logging, testing, and iteration gates.
30
+ - `references/`: Focused guides for scanning, job selection, naming, simplification, module boundaries, logging, testing, unlock work, and iteration gates.
26
31
 
27
32
  ## Typical usage
28
33
 
@@ -1,172 +1,100 @@
1
1
  ---
2
2
  name: iterative-code-quality
3
3
  description: >-
4
- Improve an existing codebase through repeated evidence-based code-quality
5
- passes: clarify poor variable names, simplify or extract reusable functions,
6
- split oversized code into single-responsibility modules, repair stale or
7
- missing logs, and add high-value tests while preserving business behavior and
8
- system-level macro architecture. Use when users ask for comprehensive refactoring, code
9
- cleanup, maintainability hardening, naming cleanup, log alignment, or test
10
- coverage improvement across a repository.
4
+ Improve an existing codebase through repeated evidence-based repository-wide
5
+ scans and behavior-safe refactors until no known in-scope actionable quality
6
+ issue remains: clarify poor names, simplify or extract reusable functions,
7
+ split mixed-responsibility code, repair stale or missing logs, and add
8
+ high-value tests where guardrails are missing, while preserving intended
9
+ business behavior and the system's macro architecture. Use when users ask for
10
+ comprehensive refactoring, code cleanup, maintainability hardening, naming
11
+ cleanup, log alignment, or test coverage improvement across a repository.
11
12
  ---
12
13
 
13
14
  # Iterative Code Quality
14
15
 
15
16
  ## Dependencies
16
17
 
17
- - Required: `align-project-documents` and `maintain-project-constraints` after implementation changes are complete.
18
- - Conditional: `systematic-debug` when a new or existing test reveals a real business-logic defect that must be fixed.
19
- - Optional: `discover-edge-cases` for high-risk boundary exploration before choosing missing tests; `improve-observability` for complex telemetry design.
20
- - Fallback: If required completion dependencies are unavailable, finish code and tests, then report exactly which documentation or constraint sync step could not run.
18
+ - Required: `align-project-documents` and `maintain-project-constraints` after the repository is truly iteration-complete.
19
+ - Conditional: `systematic-debug` when a newly added or existing test exposes a real business-logic defect that must be fixed at the true owner.
20
+ - Optional: `discover-edge-cases` for high-risk boundary exploration before adding tests; `improve-observability` for non-trivial telemetry design.
21
+ - Fallback: If required completion dependencies are unavailable, finish code and validation first, then report exactly which documentation or constraint-sync action could not run.
21
22
 
22
23
  ## Standards
23
24
 
24
- - Evidence: Read repository docs, project constraints, source, tests, logs, and entrypoints before editing; every rename, extraction, split, log update, or test must be backed by code context.
25
- - Execution: Continuously re-scan the full codebase, treat naming, abstraction, module boundaries, logging, and tests as selectable execution directions rather than a fixed sequence, choose the highest-confidence directions that can safely land now, and use those smaller refactors to prepare the ground for larger future refactors; validate after each iteration, then keep iterating while any known in-scope codebase quality issue remains unresolved; when tests or other reliable guardrails can prove equivalence, prefer taking the refactor instead of deferring it for subjective confidence reasons; do not produce the completion report while the scan still contains actionable gaps.
26
- - Quality: Solve as many inherited code-quality problems as safely possible without changing intended behavior or the system's macro architecture; avoid style-only churn, compatibility theater, broad rewrites, and unverified "cleanup", but do not reject a worthwhile refactor purely because it feels risky when existing or newly added guardrails can verify it safely.
27
- - Output: Deliver a concise pass-by-pass summary, changed behavior-neutral surfaces, test coverage added, validation results, and documentation/`AGENTS.md` sync status only after every known in-scope quality issue is resolved or explicitly classified as blocked, unsafe, low-value, speculative, or requiring user approval.
25
+ - Evidence: Read repository docs, project constraints, source, tests, logs, build scripts, entrypoints, and nearby abstractions before editing; every refactor and every new test must be justified by code context.
26
+ - Execution: Run a continuous three-step loop of full-codebase scan choose this round's jobs and refactor if and only if the latest full-codebase scan is clear, update docs and constraints; otherwise return to scanning immediately. Do not treat jobs as workflow steps. Do not produce a completion report while any known in-scope actionable issue remains.
27
+ - Quality: Resolve as many inherited quality problems as safely possible without changing intended behavior or the system's macro architecture. Do not require pre-existing tests before every safe refactor; if an area is high-risk and weakly guarded, add the missing guardrails as part of the work instead of treating the area as untouchable.
28
+ - Output: Return iteration-by-iteration decisions, selected jobs, changed files, behavior-preservation evidence, tests and guardrails added, validation results, and docs/constraint sync status only after the latest scan shows no remaining known actionable in-scope issue.
28
29
 
29
- ## Goal
30
+ ## Mission
30
31
 
31
- Resolve as many inherited repository quality problems as possible without breaking intended behavior, and use tests plus other reliable guardrails to prove that the refactor leaves the project in a fully green state.
32
+ Leave the repository materially cleaner by continuously scanning the whole codebase, landing the highest-value safe refactors available at each moment, and repeating until there is no known in-scope actionable quality gap left to fix.
32
33
 
33
- This skill is intentionally implementation-oriented, not report-only. It should keep scanning the full codebase, choose the best available refactor directions at each moment, apply as much safe cleanup as the repository can support, add or strengthen tests to guard the refactor, and use incremental cleanup to unlock deeper improvements over time. If a post-iteration scan finds remaining actionable gaps, continue the next iteration instead of writing a completion report.
34
+ For this skill, `macro architecture` means the system's top-level runtime shape and overall operating logic: major subsystems, top-level execution model, deployment/runtime boundaries, persistence model, service boundaries, and the end-to-end way the whole system works. Ordinary module interactions, helper extraction, local responsibility moves, internal call-boundary cleanup, and local module splits do not count as macro-architecture changes by themselves.
34
35
 
35
- For this skill, `macro architecture` means the system's top-level runtime shape and overall operating logic: major subsystems, top-level execution model, deployment/runtime boundaries, persistence model, service boundaries, and the end-to-end way the whole system works. Ordinary module interactions, helper extraction, local responsibility moves, and internal call-boundary cleanup do not count as macro-architecture changes by themselves.
36
+ ## Three-Step Loop
36
37
 
37
- ## Required Reference Loading
38
+ ### 1) Scan the repository
38
39
 
39
- Load references only when they match the active pass:
40
+ - Read root guidance first: `AGENTS.md`, `README*`, package manifests, task runners, CI/test config, and major project docs.
41
+ - Map runtime entrypoints, domain modules, external integrations, logging utilities, and current test surfaces.
42
+ - Exclude generated, vendored, lock, build-output, fixture, or snapshot files unless evidence shows they are human-maintained source.
43
+ - Build or refresh a concrete repository-wide backlog of known actionable quality issues.
44
+ - Re-scan the full codebase after every landed iteration, not only the files just changed.
45
+ - Load `references/repository-scan.md` for the scan checklist and backlog shaping rules.
40
46
 
41
- - `references/repository-scan.md`: scope mapping, generated-file exclusions, and quality backlog selection.
42
- - `references/naming-and-simplification.md`: variable renames, function simplification, reusable extraction, and behavior-preservation checks.
43
- - `references/module-boundaries.md`: single-responsibility split heuristics and safe module extraction rules.
44
- - `references/logging-alignment.md`: stale log detection, missing log criteria, and behavior-neutral observability updates.
45
- - `references/testing-strategy.md`: risk-based unit, property, integration, and E2E coverage selection.
46
- - `references/iteration-gates.md`: multi-pass quality gates, stopping criteria, and validation cadence.
47
+ ### 2) Choose this round's jobs and refactor
47
48
 
48
- ## Workflow
49
+ - Choose jobs only after the latest full-codebase scan. Jobs are optional execution directions, not ordered workflow steps.
50
+ - Select the smallest set of jobs that can safely improve the repository right now under current guardrails.
51
+ - Prefer smaller, high-confidence refactors that reduce risk and prepare the ground for deeper later cleanup.
52
+ - If a desired refactor is high-risk and weakly guarded, make guardrail-building part of this round instead of stopping.
53
+ - If a file feels too coupled, too central, or too risky for a direct rewrite, do staged unlock work rather than declaring the area blocked.
54
+ - Read all directly affected callers, tests, interfaces, and logs before editing.
55
+ - Validate from narrow to broad after each bounded round, then perform a full-codebase stage-gate decision:
56
+ - if any known in-scope actionable issue still remains, return to Step 1;
57
+ - only continue to Step 3 when the latest scan is clear.
49
58
 
50
- ### 1) Establish the repository baseline
59
+ Load references for this step only as needed:
51
60
 
52
- - Read root guidance first: `AGENTS.md`, `README*`, major docs, package manifests, task runners, CI configs, and test setup.
53
- - Map runtime entrypoints, domain modules, external integrations, logging/telemetry utilities, and existing test suites.
54
- - Identify generated, vendored, lock, build-output, fixture, or snapshot files; exclude them from refactoring unless evidence shows they are human-maintained source.
55
- - Run or inspect the most relevant existing validation commands before editing when feasible, so pre-existing failures are distinguishable from new regressions.
56
- - Build an initial quality backlog with concrete file/function/test targets before changing code.
57
- - Use `references/repository-scan.md` for the scan checklist and backlog scoring.
61
+ - `references/job-selection.md` for next-job choice conditions and tie-breakers.
62
+ - `references/naming-and-simplification.md` for naming cleanup and function simplification/extraction.
63
+ - `references/module-boundaries.md` for single-responsibility module cleanup.
64
+ - `references/logging-alignment.md` for stale or missing log repair.
65
+ - `references/testing-strategy.md` for unit, property, integration, and E2E test strategy.
66
+ - `references/coupled-core-file-strategy.md` for staged unlock work on large coupled or apparently core files.
67
+ - `references/iteration-gates.md` for validation cadence, stage-gate rules, and stop criteria.
58
68
 
59
- ### 2) Execute continuous full scans with selectable directions
69
+ ### 3) Update project documents and constraints
60
70
 
61
- Do not force one fixed order such as "finish naming first, then abstraction, then modules". Instead, keep re-scanning the whole codebase and select the execution directions that are highest-confidence and highest-leverage right now.
71
+ Only enter this step when the latest full-codebase scan confirms there is no remaining known actionable in-scope quality issue except items explicitly classified as blocked, unsafe, speculative, low-value, or approval-dependent.
62
72
 
63
- Treat these as multi-select execution directions, not mandatory sequential stages:
64
-
65
- 1. Naming clarity for variables, parameters, fields, local helpers, and test data.
66
- 2. Function simplification and reusable extraction for duplicated or hard-coded workflows.
67
- 3. Single-responsibility module splits for oversized or mixed-concern code.
68
- 4. Logging alignment for stale, misleading, missing, or low-context diagnostics.
69
- 5. Risk-based test coverage for high-value business logic and boundary cases.
70
-
71
- Direction-selection rules:
72
-
73
- - Prefer the directions with the strongest current evidence and best guardrails.
74
- - Prefer smaller, higher-confidence refactors that unlock or de-risk larger later refactors.
75
- - Prefer outside-in progress: stabilize boundaries, callers, naming, logs, and tests around a subsystem before attempting deeper internal rewrites.
76
- - Re-evaluate the whole backlog after every landed iteration; the next best direction may change because the previous cleanup improved the local safety or clarity.
77
-
78
- For each iteration:
79
-
80
- - Read all directly affected callers, tests, and public interfaces before editing.
81
- - Keep the scope small enough to validate and review, and select whichever directions are most justified for that scope instead of forcing every direction to appear in every iteration.
82
- - Prefer repository-native abstractions over new parallel frameworks.
83
- - Preserve public behavior, data contracts, side effects, error classes, and macro architecture.
84
- - Add or update tests in the same iteration when the change touches non-trivial logic, observability contracts, or extracted helpers.
85
- - If strong guardrails exist or can be added cheaply, prefer the clearer or more maintainable refactor instead of leaving a known issue in place due to subjective caution alone.
86
- - Validate the touched scope before starting another iteration.
87
-
88
- ### 3) Rename for clarity without churn
89
-
90
- - Rename only when the current name hides domain meaning, confuses ownership, conflicts with real units, or makes tests/logs misleading.
91
- - Prefer names that encode domain role, unit, lifecycle stage, or canonical owner.
92
- - Update all references, tests, fixtures, structured log fields, docs, and comments that describe the renamed concept.
93
- - Avoid renaming stable public API fields or persisted schema names unless the user explicitly requested a breaking migration.
94
- - Use `references/naming-and-simplification.md` before broad rename passes.
95
-
96
- ### 4) Simplify and extract reusable functions
97
-
98
- - Simplify functions when branches, temporary state, repeated transformations, or hard-coded workflows obscure the invariant.
99
- - Extract helpers only when they reduce duplication, centralize one business rule, clarify caller intent, or make a behavior testable.
100
- - Keep helper placement aligned with current module ownership.
101
- - Do not create abstractions for one-off code unless they isolate a meaningful domain rule or external contract.
102
- - If tests or equivalent guardrails can prove behavior preservation, do not let moderate implementation uncertainty block an otherwise valuable simplification or extraction.
103
- - Preserve observable behavior unless a test proves the current behavior is a defect.
104
-
105
- ### 5) Split modules by responsibility
106
-
107
- - Split code only when one file/module owns multiple change reasons, domain boundaries, external integrations, or lifecycle stages.
108
- - Define the new module's responsibility before moving code.
109
- - Keep interfaces narrow, explicit, and consistent with existing project style.
110
- - Avoid macro-architecture changes such as new top-level layers, new service boundaries, new persistence strategies, deployment/runtime model changes, or framework swaps unless the user explicitly expands scope.
111
- - When module boundaries are currently poor but can be protected by focused tests or other guardrails, choose the cleaner split instead of preserving a mixed-responsibility file out of caution alone.
112
- - Use `references/module-boundaries.md` for extraction rules and anti-patterns.
113
-
114
- ### 6) Repair logging and observability drift
115
-
116
- - Compare log messages, event names, structured fields, metrics, and trace names against the current code ownership model.
117
- - Fix stale terminology after renames or refactors so logs describe the live workflow.
118
- - Add logs only at high-value decision points: branch selection, skipped work, external dependency outcome, persistence side effect, retry/rollback, and final outcome.
119
- - Use structured fields already accepted by the project; never log secrets, tokens, full sensitive payloads, or personal data.
120
- - Add tests or assertions for important log fields when the project has log-capture helpers.
121
- - Use `references/logging-alignment.md` for detailed criteria.
122
-
123
- ### 7) Add high-value tests
124
-
125
- - Start from risk, not coverage percentage.
126
- - Prioritize tests for business rules, state transitions, error handling, extracted helpers, edge cases, observability contracts, and integration boundaries.
127
- - Use unit tests for local logic, property-based tests for invariants and generated input spaces, integration tests for cross-module chains, and E2E tests only when external services are stable or can be controlled reliably.
128
- - Mock or fake external services unless the real service contract is the subject under test.
129
- - If a new test exposes an existing business-logic bug, invoke `systematic-debug`, fix the true owner, and keep the regression test.
130
- - Use `references/testing-strategy.md` for coverage selection and required `N/A` reasoning.
131
-
132
- ### 8) Iterate gradually from outside to inside until the repository is clear of known actionable issues
133
-
134
- - After each iteration, run the narrowest relevant tests first, then broaden validation until the changed scope and final repository state are adequately guarded.
135
- - Re-scan the full codebase, not only the touched area, because the best next direction may have shifted after the last cleanup.
136
- - Re-rank the backlog after every iteration and choose the next highest-confidence, highest-leverage direction set.
137
- - Use small external or boundary-level cleanups to make later deeper refactors safer; treat that groundwork as progress toward a thorough long-horizon refactor, not as a distraction from it.
138
- - Repeat the full iteration whenever any known in-scope actionable gap remains and can be fixed safely without changing business behavior or macro architecture.
139
- - Do not write the completion report, summarize the task as done, or hand back as complete while the latest scan still contains known actionable quality issues.
140
- - Stop only when every known in-scope issue has been resolved, or each remaining candidate is explicitly classified as low-value, speculative, blocked, unsafe, or requiring product/architecture approval.
141
- - Use `references/iteration-gates.md` for stopping criteria.
142
-
143
- ### 9) Synchronize docs and constraints
144
-
145
- After code and tests are complete:
146
-
147
- - Invoke `align-project-documents` when README, docs, architecture notes, debugging docs, setup instructions, or test guidance may have drifted.
148
- - Invoke `maintain-project-constraints` to verify `AGENTS.md` still reflects architecture, business flow, common commands, macro purpose, and coding conventions.
149
- - Update only documentation that is affected by real code, command, logging, or test changes.
73
+ - Run `align-project-documents` when README, architecture notes, setup docs, debugging docs, or test guidance may have drifted.
74
+ - Run `maintain-project-constraints` to verify `AGENTS.md` still matches the repository's real architecture, business flow, commands, and conventions.
75
+ - Update only the documentation and constraints that changed in reality because of the refactor.
150
76
 
151
77
  ## Hard Guardrails
152
78
 
153
- - Do not change intended business logic while refactoring.
154
- - Do not change the system's macro architecture—its top-level runtime shape, deployment/runtime model, persistence model, major service boundaries, or overall operating logic—unless the user explicitly approves that expanded scope.
79
+ - Do not change intended business logic while refactoring, except to fix a real defect exposed by tests and verified at the true owner.
80
+ - Do not change the system's macro architecture unless the user explicitly expands scope.
155
81
  - Do not use one-off scripts to rewrite product code.
156
- - Do not perform style-only churn that does not improve naming, reuse, modularity, observability, or test confidence.
157
- - Do not weaken tests to make refactors pass; update tests to stable invariants or fix the implementation defect.
158
- - Do not add E2E tests that depend on unreliable external services when a controlled integration test can prove the same business risk.
82
+ - Do not stop early just because a file is large, central, or historically fragile; if a safe unlock step exists, that is the next job.
83
+ - Do not weaken tests to make a refactor pass; fix the real defect or update stale expectations to stable invariants.
84
+ - Do not add style-only churn that does not improve naming, modularity, observability, reuse, or guardrail strength.
85
+ - Do not add unreliable E2E coverage when a controlled integration or characterization test can prove the same risk more safely.
159
86
 
160
87
  ## Completion Report
161
88
 
162
- Only write this report after the latest scan confirms there are no known actionable in-scope quality issues remaining and the relevant test/guardrail suite is green. If any such issue remains, continue iterating instead of reporting completion.
89
+ Only report completion after Step 3 is done and the latest Step 1 scan is clear.
163
90
 
164
91
  Return:
165
92
 
166
- 1. Iterations completed and which execution directions were selected in each one.
167
- 2. Key files changed and the quality issue each change resolved.
168
- 3. Business behavior preservation evidence.
169
- 4. Tests added or updated, including property/integration/E2E `N/A` reasons where relevant.
170
- 5. Validation commands and results.
171
- 6. Documentation and `AGENTS.md` synchronization status.
172
- 7. Remaining quality gaps, blockers, or deferred architecture/product decisions.
93
+ 1. Iterations completed and the jobs selected in each iteration.
94
+ 2. Stage-gate verdict after each full-codebase re-scan.
95
+ 3. Key files changed and the quality issue each change resolved.
96
+ 4. Business behavior preservation evidence.
97
+ 5. Tests or other guardrails added or updated, including property/integration/E2E `N/A` reasons where relevant.
98
+ 6. Validation commands and results.
99
+ 7. Documentation and `AGENTS.md` synchronization status.
100
+ 8. Remaining blocked or approval-dependent items, if any.
@@ -1,4 +1,4 @@
1
1
  interface:
2
2
  display_name: "Iterative Code Quality"
3
3
  short_description: "Refactor names, functions, modules, logs, and tests in repeated behavior-safe passes"
4
- default_prompt: "Use $iterative-code-quality to keep scanning the full repository, treat naming, simplification, reusable extraction, module-boundary cleanup, logging alignment, and testing as selectable execution directions rather than a fixed sequence, and choose the highest-confidence, highest-leverage directions available at each moment; use small safe refactors to prepare the ground for larger later refactors, progress gradually from outside to inside, use tests or other reliable guardrails to justify aggressive cleanup without breaking intended behavior or the system's top-level runtime architecture, and do not write a completion report while any known in-scope actionable issue remains; only finish after the latest full-codebase scan is clear or remaining items are explicitly classified as blocked, unsafe, low-value, speculative, or approval-dependent, and the guarded test surface is green; then run $align-project-documents and $maintain-project-constraints to synchronize docs and AGENTS.md."
4
+ default_prompt: "Use $iterative-code-quality as a strict three-step loop. Step 1: scan the full repository and refresh the actionable quality backlog. Step 2: choose this round's jobs from the reference documents and land the highest-value safe refactors now; jobs are selectable directions, not workflow steps, and if a high-risk area is weakly guarded add the missing tests or other guardrails instead of stopping. If a file is too coupled or too central for direct cleanup, switch to staged unlock work and keep progressing. After validation, run a full-codebase stage-gate; if any known in-scope actionable issue still remains, go back to Step 1 immediately. Step 3: only when the latest full-codebase scan is clear, run $align-project-documents and $maintain-project-constraints to synchronize docs and AGENTS.md. Preserve intended business behavior and the system's macro architecture, keep the guarded test surface green, and do not write a completion report while actionable gaps still exist."
@@ -0,0 +1,73 @@
1
+ # Staged Strategy For Large Coupled Or Apparently Core Files
2
+
3
+ ## Purpose
4
+
5
+ Teach the agent how to keep making progress when a file feels too central, too coupled, or too risky to refactor directly.
6
+
7
+ The correct response is usually not "stop". The correct response is "find the next unlock step".
8
+
9
+ ## Core rule
10
+
11
+ A large coupled file is a **decomposition signal**, not a **completion blocker**.
12
+
13
+ If a safe, behavior-preserving unlock step exists under current guardrails, take that step now instead of deferring the whole area.
14
+
15
+ If guardrails are too weak for direct cleanup, strengthening them is itself the next unlock step.
16
+
17
+ ## First questions to ask
18
+
19
+ When a file feels untouchable, ask:
20
+
21
+ - Which parts are pure logic and which parts are side effects?
22
+ - Which names or local concepts are blocking understanding?
23
+ - Which behavior can be locked down with characterization tests?
24
+ - Which dependency seams can be introduced without changing behavior?
25
+ - Which caller groups or workflow slices can be isolated first?
26
+ - Which refactor would most reduce the cost of the next refactor?
27
+
28
+ ## Typical unlock sequence
29
+
30
+ Pick one or more of these, in the order justified by current evidence:
31
+
32
+ 1. Add characterization or regression tests around current behavior.
33
+ 2. Rename confusing variables, flags, intermediate states, and helper names.
34
+ 3. Extract constants, schemas, types, and small pure transformations.
35
+ 4. Separate read path from write path, or decision logic from side effects.
36
+ 5. Isolate external calls, persistence, and logging behind clearer seams.
37
+ 6. Group callers by responsibility and split one slice at a time.
38
+ 7. Move one coherent responsibility into a new internal module.
39
+ 8. Re-scan and decide whether a deeper split is now safer.
40
+
41
+ ## What not to do
42
+
43
+ Avoid these anti-patterns:
44
+
45
+ - declaring the area blocked just because it is important,
46
+ - attempting a full rewrite before guardrails exist,
47
+ - preserving obvious local design debt only because the file is central,
48
+ - escalating ordinary internal decomposition into a fake macro-architecture concern,
49
+ - mixing unlock work with unrelated style churn.
50
+
51
+ ## Choosing the next step
52
+
53
+ Prefer the next step that maximizes:
54
+
55
+ 1. confidence under existing tests or quickly addable tests,
56
+ 2. leverage for future deeper cleanup,
57
+ 3. reduction in coupling or cognitive load,
58
+ 4. low risk to current business behavior.
59
+
60
+ If two steps are both safe, choose the one that makes the next iteration easier.
61
+
62
+ If the file is high-risk and under-tested, prefer adding the smallest useful characterization tests before attempting deeper structural edits.
63
+
64
+ ## Completion rule for coupled files
65
+
66
+ Do not ask "Can I solve the whole file now?"
67
+
68
+ Ask:
69
+
70
+ - "Can I make this file meaningfully easier to change in the next iteration?"
71
+ - "Can I reduce coupling, clarify ownership, or improve guardrails right now?"
72
+
73
+ If the answer is yes, continue iterating.
@@ -52,6 +52,20 @@ Then choose the next execution directions with these priorities:
52
52
  2. strongest leverage for later deeper cleanup,
53
53
  3. lowest business-risk path toward broader system improvement.
54
54
 
55
+ Use `references/job-selection.md` to convert those priorities into a concrete next-job choice.
56
+
57
+ ## Stage-gate after each iteration
58
+
59
+ After every validated iteration, run a deliberate full-codebase decision pass:
60
+
61
+ 1. Re-scan the repository and refresh the known quality backlog.
62
+ 2. Ask whether any known in-scope actionable issue still remains.
63
+ 3. If yes, decide whether it should be addressed in the very next iteration or whether first-step unlock work is needed.
64
+ 4. If the obstacle is a large, coupled, or central file, do not stop there; switch to staged unlock work and continue.
65
+ 5. Only declare the repository iteration-complete when the re-scan shows no remaining actionable in-scope issue except items that are explicitly deferred under the allowed stop categories.
66
+
67
+ This stage-gate is mandatory. A validated local change does not by itself mean the repository is done.
68
+
55
69
  ## Continue when
56
70
 
57
71
  Repeat the cycle when:
@@ -87,6 +101,7 @@ The final report should make the stopping point auditable:
87
101
 
88
102
  - passes completed,
89
103
  - execution directions selected per iteration,
104
+ - stage-gate verdict after each full-codebase re-scan,
90
105
  - validation commands and outcomes,
91
106
  - confirmation that the guarded test surface is green after the refactor,
92
107
  - tests added by risk category,
@@ -0,0 +1,70 @@
1
+ # Job Selection Guide
2
+
3
+ ## Purpose
4
+
5
+ Help the agent choose the next execution direction after each full-codebase re-scan.
6
+
7
+ These are job-selection rules for Step 2 of the main skill loop. They are not workflow steps.
8
+
9
+ The goal is not to force one permanent order. The goal is to choose the next job that most safely improves the codebase and unlocks later work.
10
+
11
+ ## Available jobs
12
+
13
+ - naming cleanup
14
+ - function simplification / extraction
15
+ - module-boundary cleanup
16
+ - logging alignment
17
+ - test addition
18
+ - staged unlock work
19
+
20
+ ## Choose `naming cleanup` when
21
+
22
+ - confusing names are the main thing blocking understanding,
23
+ - flags, units, lifecycle states, or ownership terms are misleading,
24
+ - better naming would clearly reduce the risk of a later deeper refactor.
25
+
26
+ ## Choose `function simplification / extraction` when
27
+
28
+ - duplicated logic exists across multiple call sites,
29
+ - one function mixes too many concerns,
30
+ - control flow is currently the main complexity bottleneck,
31
+ - extracting a helper would make the next test or split easier.
32
+
33
+ ## Choose `module-boundary cleanup` when
34
+
35
+ - one file or module clearly has multiple reasons to change,
36
+ - local responsibilities are already visible enough to separate,
37
+ - a safe split would reduce repeated touching of unrelated concerns.
38
+
39
+ ## Choose `logging alignment` when
40
+
41
+ - stale or missing diagnostics are the main blocker to safe validation,
42
+ - later refactors would be safer if branch decisions and outcomes were easier to observe,
43
+ - observability drift is currently hiding the real ownership model.
44
+
45
+ ## Choose `test addition` when
46
+
47
+ - the target area is high-risk and weakly guarded,
48
+ - desired cleanup is blocked mainly by missing behavior locks,
49
+ - coupling spans multiple modules and needs characterization before change,
50
+ - regression risk is too high to justify deeper refactors without stronger coverage.
51
+
52
+ ## Choose `staged unlock work` when
53
+
54
+ - the file feels too central or too coupled for direct cleanup,
55
+ - no safe full refactor exists yet, but a preparatory step does,
56
+ - you can reduce risk through naming, seam extraction, type extraction, side-effect isolation, or caller grouping,
57
+ - the best next move is to make a future refactor cheaper rather than solve the whole area now.
58
+
59
+ ## Tie-breakers
60
+
61
+ If multiple jobs are plausible, prefer the one that:
62
+
63
+ 1. increases safety for the next iteration,
64
+ 2. reduces cognitive load fastest,
65
+ 3. removes the strongest blocker to a deeper future refactor,
66
+ 4. preserves behavior with the clearest available guardrails.
67
+
68
+ ## Hard rule
69
+
70
+ If a high-risk area lacks enough guardrails, `test addition` or another guardrail-building job should usually win before a deeper structural refactor.
@@ -41,6 +41,8 @@ The following do **not** count as macro-architecture changes by themselves:
41
41
 
42
42
  Treat those changes as ordinary refactoring work unless they also alter the top-level system model above.
43
43
 
44
+ Large coupled or central files should therefore be treated as decomposition problems, not as automatic macro-architecture blockers. If the top-level system model remains intact, prefer staged internal cleanup over stopping.
45
+
44
46
  ## Safe split patterns
45
47
 
46
48
  - Move pure domain logic into a domain-owned helper module.
@@ -8,6 +8,11 @@ For every non-trivial pass, ask what could regress silently if the cleanup were
8
8
 
9
9
  Use the resulting guardrails aggressively: when tests or equivalent verification can prove behavior preservation, they should unlock bolder refactors rather than merely justify small cosmetic edits.
10
10
 
11
+ Do not require pre-existing tests before every refactor. Instead:
12
+
13
+ - if existing guardrails are already sufficient, proceed;
14
+ - if the area is high-risk and guardrails are weak, add the smallest high-value tests first and treat that as progress toward the refactor.
15
+
11
16
  The intended end state is not merely "some tests passed for touched files". The refactor is complete only when the relevant guarded test surface for the repository remains green after the cleanup.
12
17
 
13
18
  ## Unit tests
@@ -27,6 +32,8 @@ Good oracles:
27
32
  - exact error class or reason code,
28
33
  - emitted side effect or explicit lack of side effect.
29
34
 
35
+ For high-risk legacy code with weak coverage, characterization-style unit tests are often the first unlock step even before the larger cleanup happens.
36
+
30
37
  ## Property-based tests
31
38
 
32
39
  Use when logic has invariants or broad input space:
@@ -51,6 +58,8 @@ Use when the risk spans modules:
51
58
 
52
59
  For external services, prefer mocks, fakes, local emulators, or recorded stable fixtures unless the real contract is explicitly under test.
53
60
 
61
+ When risk comes from multi-module coupling rather than one local function, integration coverage is often the best guardrail to add before refactoring.
62
+
54
63
  ## E2E tests
55
64
 
56
65
  Use only when:
@@ -81,3 +90,4 @@ Consider:
81
90
  - Do not weaken existing tests to fit the refactor.
82
91
  - If old tests asserted implementation details, rewrite them around stable behavior while preserving the business invariant.
83
92
  - Once stable guardrails exist, do not refuse a maintainability-improving refactor purely because confidence feels lower than ideal; let the guardrails decide.
93
+ - If stable guardrails do not yet exist for a high-risk area, create them as the next execution direction instead of treating the refactor as blocked forever.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laitszkin/apollo-toolkit",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "description": "Apollo Toolkit npm installer for managed skill copying across Codex, OpenClaw, and Trae.",
5
5
  "license": "MIT",
6
6
  "author": "LaiTszKin",