|
| 1 | +--- |
| 2 | +phase: 02-enum-refactor |
| 3 | +plan: 01 |
| 4 | +type: execute |
| 5 | +wave: 1 |
| 6 | +depends_on: [] |
| 7 | +files_modified: |
| 8 | + - engine/src/Enums/Types/EventType.ts |
| 9 | + - engine/src/Enums/Modes/OutMode.ts |
| 10 | + - engine/src/Enums/Types/StartValueType.ts |
| 11 | + - .planning/phases/02-enum-refactor/enum-inventory.md |
| 12 | +autonomous: true |
| 13 | +requirements: |
| 14 | + - CORE-02 |
| 15 | + - TEST-01 |
| 16 | +user_setup: [] |
| 17 | +must_haves: |
| 18 | + truths: |
| 19 | + - "Replacing small string enums with as-const objects does not change runtime behavior for consumers" |
| 20 | + - "Build and tests pass after enum conversions" |
| 21 | + - "Public typings remain explicit (no use of `any`) and imports keep the same exported names" |
| 22 | + artifacts: |
| 23 | + - path: "engine/src/Enums/Types/EventType.ts" |
| 24 | + provides: "Event type values available at runtime and a TypeScript type for EventType" |
| 25 | + - path: "engine/src/Enums/Modes/OutMode.ts" |
| 26 | + provides: "Out mode values exposed as a runtime object and a type alias OutMode" |
| 27 | + - path: "engine/src/Enums/Types/StartValueType.ts" |
| 28 | + provides: "StartValueType values available as const + Type alias" |
| 29 | + - path: ".planning/phases/02-enum-refactor/enum-inventory.md" |
| 30 | + provides: "Inventory of all enum files and a conversion recommendation (keep/convert/manual)" |
| 31 | + key_links: |
| 32 | + - from: "engine/src/Enums/Types/EventType.ts" |
| 33 | + to: "engine code that imports EventType" |
| 34 | + via: "named import -> use EventType.X pattern" |
| 35 | + pattern: "import .*EventType.*" |
| 36 | + - from: "engine/src/Enums/Modes/OutMode.ts" |
| 37 | + to: "updaters/outModes implementations" |
| 38 | + via: "imports and string comparison/switch" |
| 39 | + pattern: "OutMode\.|OutMode =" |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +<objective> |
| 44 | +Replace a small, low-risk set of string-valued TypeScript enums with type-safe `as const` objects + derived union types to reduce emitted JS and improve tree-shaking. Start with a narrow, auditable pilot (3 files) and produce an inventory for follow-ups. |
| 45 | + |
| 46 | +Purpose: reduce unnecessary enum runtime objects (bundle size risk) while preserving API/typing and keeping changes small and reversible. |
| 47 | +Output: inventory file and converted implementations for EventType, OutMode, StartValueType plus verification steps. |
| 48 | +</objective> |
| 49 | + |
| 50 | +<context> |
| 51 | +Repository conventions (from .planning and AGENTS.md): TypeScript monorepo, prefer explicit types for public APIs, run tests with Vitest and builds with pnpm scripts. Keep changes small and include tests. |
| 52 | + |
| 53 | +Key enum files (pilot): |
| 54 | + |
| 55 | +- engine/src/Enums/Types/EventType.ts |
| 56 | +- engine/src/Enums/Modes/OutMode.ts |
| 57 | +- engine/src/Enums/Types/StartValueType.ts |
| 58 | + |
| 59 | +The codebase contains many string enums across engine and plugins. This plan audits and converts a small, low-risk subset first. |
| 60 | +</context> |
| 61 | + |
| 62 | +<tasks> |
| 63 | + |
| 64 | +<task type="auto"> |
| 65 | + <name>Task 1: Audit — enumerate all TypeScript enums and classify</name> |
| 66 | + <files>.planning/phases/02-enum-refactor/enum-inventory.md</files> |
| 67 | + <action> |
| 68 | + Run a repo-wide scan for `export enum` and produce a markdown inventory listing: file path, number of members, member names, and a quick recommendation: `convert` (small string enum, used only as values/types), `keep` (numeric enum or bit-flags or large enums with reverse mapping), or `manual` (large enums with many cross-package usages). Save output to `.planning/phases/02-enum-refactor/enum-inventory.md`. |
| 69 | + |
| 70 | + Implementation notes for executor (automated): prefer ripgrep (rg) or git-grep. Include a short grep command and summary header. Don't modify source files in this task. |
| 71 | + |
| 72 | + </action> |
| 73 | + <verify> |
| 74 | + <automated>rg --hidden "export enum" --glob '!node_modules' --glob '!.git' -n || true |
| 75 | + rg --hidden "export enum" --glob '!node_modules' --glob '!.git' -n > .planning/phases/02-enum-refactor/enum-inventory.md && test -s .planning/phases/02-enum-refactor/enum-inventory.md</automated> |
| 76 | + </verify> |
| 77 | + <done>The file `.planning/phases/02-enum-refactor/enum-inventory.md` exists and contains a line per enum with path, member count and an initial recommendation (convert/keep/manual).</done> |
| 78 | +</task> |
| 79 | + |
| 80 | +<task type="auto"> |
| 81 | + <name>Task 2: Convert pilot enums to `as const` + derived type</name> |
| 82 | + <files> |
| 83 | + engine/src/Enums/Types/EventType.ts, |
| 84 | + engine/src/Enums/Modes/OutMode.ts, |
| 85 | + engine/src/Enums/Types/StartValueType.ts |
| 86 | + </files> |
| 87 | + <action> |
| 88 | + For each listed file, replace the `export enum X { a = "a", ... }` pattern with an exported const object and a derived union type. Example transform: |
| 89 | + |
| 90 | + Before: |
| 91 | + export enum EventType { configAdded = "configAdded", ... } |
| 92 | + |
| 93 | + After: |
| 94 | + export const EventType = { |
| 95 | + configAdded: "configAdded", |
| 96 | + ... |
| 97 | + } as const; |
| 98 | + |
| 99 | + export type EventType = typeof EventType[keyof typeof EventType]; |
| 100 | + |
| 101 | + Implementation details: |
| 102 | + - Keep the named export `EventType` so existing `import { EventType } from "..."` still works at runtime for consumers that relied on the object. (Note: this changes the runtime shape from enum object to plain object — property access `EventType.configAdded` remains.) |
| 103 | + - Run a repo-wide typecheck/build after changes to catch uses that assume numeric reverse-mapping or enum-specific operations. If code relies on numeric enum behavior or reverse mapping, mark the enum in the inventory as `keep` and revert changes for that file. |
| 104 | + - Put a small comment above the converted object explaining the reason and linking to the inventory entry (for reviewers). |
| 105 | + - Commit changes in a single atomic change per file (executor will create commits). Do not push. |
| 106 | + |
| 107 | + </action> |
| 108 | + <verify> |
| 109 | + <automated>pnpm -s run -w build || pnpm -s run build |
| 110 | + </automated> |
| 111 | + </verify> |
| 112 | + <done>Each pilot file now exports a const object + derived type; `pnpm run build` completes without type errors. If any file caused type errors due to enum-specific usage, it has been reverted and noted in inventory.</done> |
| 113 | +</task> |
| 114 | + |
| 115 | +<task type="auto"> |
| 116 | + <name>Task 3: Sanity checks — run tests, run a minimal bundle check</name> |
| 117 | + <files>package.json</files> |
| 118 | + <action> |
| 119 | + Run the test suite and a slim build to ensure there are no runtime regressions. Commands to run: |
| 120 | + - `pnpm exec vitest run` (run test suites) |
| 121 | + - `pnpm run slimbuild` (build slim bundles) |
| 122 | + |
| 123 | + If tests fail, capture failing test names and revert the specific enum changes that caused regressions (one-by-one) and document in the inventory. |
| 124 | + |
| 125 | + </action> |
| 126 | + <verify> |
| 127 | + <automated>pnpm exec vitest run --reporter dot && pnpm run slimbuild</automated> |
| 128 | + </verify> |
| 129 | + <done>All tests pass (Vitest exit 0) and `pnpm run slimbuild` completes. If failures occurred, they are documented in `.planning/phases/02-enum-refactor/enum-inventory.md` with per-file revert notes.</done> |
| 130 | +</task> |
| 131 | + |
| 132 | +</tasks> |
| 133 | + |
| 134 | +<verification> |
| 135 | +Overall checks: |
| 136 | +- `.planning/phases/02-enum-refactor/enum-inventory.md` exists and lists all enums found with a recommendation column. |
| 137 | +- The three pilot files have been replaced with `as const` objects + derived types OR explicitly marked `keep` in the inventory with rationale. |
| 138 | +- `pnpm run build` and `pnpm exec vitest run` both succeed after changes, or failing conversions were reverted and recorded. |
| 139 | +</verification> |
| 140 | + |
| 141 | +<success_criteria> |
| 142 | + |
| 143 | +- Inventory created and reviewed: `.planning/phases/02-enum-refactor/enum-inventory.md` present. |
| 144 | +- At least the three pilot enums converted with passing build and tests. |
| 145 | +- No public API behavior regressions for consumers of the converted enums (property access preserved). |
| 146 | + </success_criteria> |
| 147 | + |
| 148 | +<output> |
| 149 | +After completion, create `.planning/phases/02-enum-refactor/01-PLAN-SUMMARY.md` summarizing converted enums and any reverts. |
| 150 | +</output> |
0 commit comments