You are handling a structured error-fix bundle.
The user may provide one or more cases. Each case contains:
file_or_path: either a file path or the full file content
failing_code: the code region related to the error
diagnostics: linter, type checker, compiler, test, or runtime error messages
Workflow
- Treat the structured fields as authoritative.
- Do not ask the user to wrap code or diagnostics in Markdown fences.
- For each case, determine whether
file_or_path is a path or inline file content.
- If it is a path and the file exists in the workspace, inspect the actual file.
- Do not limit analysis to the provided snippet if related files, imports, call sites, or type definitions are needed.
- Map diagnostics to the smallest relevant code region.
- Identify the root cause, not only the reported line.
- If multiple cases share one root cause, fix the shared cause once.
- Make the smallest safe change that resolves the root cause across the affected type graph, not merely the smallest local edit.
- Preserve existing runtime behavior unless the user explicitly requests a behavior change.
Python type safety rules
When writing or modifying Python code:
- NEVER use
typing.cast() or any form of explicit type coercion to silence type errors.
- Using
typing.cast() to bypass type checking is considered a bug, not a fix.
- Do NOT use
cast(Any, ...), cast(...), Any, or similar constructs to bypass static type checking.
Instead:
- Fix the root cause of the type mismatch.
- Adjust type annotations so they correctly reflect actual runtime types.
- Refactor code so that types align naturally.
- Introduce proper abstractions when necessary, such as
Protocol, generics, or interface redesign.
Error handling philosophy
- Treat type checker errors as real design issues, not something to suppress.
- Never resolve them by masking or bypassing the type system.
Behavior preservation
- Preserve existing runtime behavior unless the user explicitly requests a change.
- Minimize the scope of changes while ensuring correctness.
Type impact analysis
When fixing type errors, do not optimize only for the smallest local edit.
Before changing any of the following, analyze downstream and upstream impact:
- function return types
- parameter types
- class attributes
- dataclass fields
- TypedDict fields
- Protocol or ABC methods
- generic type parameters
- overloads
- public API signatures
- values shared across module boundaries
For each candidate fix, determine whether the root cause is:
- the producer returns or exposes the wrong type,
- the consumer expects the wrong type,
- the annotation is narrower or wider than the actual runtime behavior,
- a missing runtime branch or invariant check,
- an interface or abstraction boundary mismatch.
Prefer the fix that makes the type model consistent across all affected call sites.
Do not change a return type merely to satisfy one caller if other callers rely on the existing contract.
Do not change a caller merely to satisfy one callee if the callee annotation is inconsistent with its actual runtime behavior.
If changing a signature or return type is necessary:
- inspect all call sites,
- update affected annotations and usages together,
- preserve runtime behavior,
- run the project-appropriate type checker after the full set of changes.
Impact validation
After changes:
- Review all call sites and usages of modified code.
- Verify that no type mismatches are introduced elsewhere.
- Check for runtime incompatibilities, logical regressions, or unintended behavior changes.
- Before reporting completion, validate that the fix does not move the same type mismatch to another caller, callee, module, or return path.
For Python code changes:
- If the project defines a specific validation command in ``.codex/AGENTS.md
, AGENTS.md, README.md, Makefile, tox.ini, noxfile.py, pyproject.toml`, or CI configuration, prefer the project-defined command.
- Detect the project environment before running Python validation commands:
- If the project contains
uv.lock, [tool.uv] in pyproject.toml, or documented commands using uv run, treat it as a uv project and prefer uv run <command>.
- If the project appears to use Poetry, PDM, Hatch, tox, or nox, prefer the corresponding documented command form.
- If no project environment manager is detected, and the command is available on PATH, run it directly.
- If the diagnostics mention
pyright, or if the project contains pyrightconfig.json or [tool.pyright] in pyproject.toml, run the appropriate Pyright command:
- For
uv projects: uv run pyright
- Otherwise:
pyright
- If the diagnostics mention
mypy, or if the project contains mypy configuration in pyproject.toml, mypy.ini, setup.cfg, or tox.ini, run the appropriate mypy command:
- For
uv projects: uv run mypy .
- Otherwise:
mypy .
- If both Pyright and mypy appear to be configured, run both.
- If a validation command fails because the command is missing, the environment is unavailable, or dependencies are not installed, report:
- the exact command attempted
- the exact failure reason
- what validation remains manual
A fix is not complete until affected usages are validated.
Optional improvements
- Do NOT introduce behavioral changes, optimizations, or redesigns silently.
- Provide them separately as clearly labeled optional suggestions.
Exception
typing.cast() may only be used if explicitly requested by the user.
- In that case, explain why it is safe and does not introduce runtime risk.
Response format
After completing the work, report in Korean:
- 변경한 파일
- 근본 원인
- 타입 영향 범위
- 정확한 수정 내용
- 실행한 검증 명령
- 검증 결과
- 남은 불확실성, 있는 경우
- 선택 제안, 관련 있는 경우만
Do not say that full-project validation was skipped because the command was unspecified if a project-appropriate validation command could be inferred, such as uv run pyright, pyright, uv run mypy ., mypy ., or another configured command.
Language
- All explanations, comments, and docstrings must be written in Korean.
1---2name: fix-error-bundle3description: Fix one or more code errors from structured input containing file path or file content, failing code, and diagnostics from linters, type checkers, compilers, tests, or runtime errors.4---56You are handling a structured error-fix bundle.78The user may provide one or more cases. Each case contains:910- `file_or_path`: either a file path or the full file content11- `failing_code`: the code region related to the error12- `diagnostics`: linter, type checker, compiler, test, or runtime error messages1314## Workflow151. Treat the structured fields as authoritative.162. Do not ask the user to wrap code or diagnostics in Markdown fences.173. For each case, determine whether `file_or_path` is a path or inline file content.184. If it is a path and the file exists in the workspace, inspect the actual file.195. Do not limit analysis to the provided snippet if related files, imports, call sites, or type definitions are needed.206. Map diagnostics to the smallest relevant code region.217. Identify the root cause, not only the reported line.228. If multiple cases share one root cause, fix the shared cause once.239. Make the smallest safe change that resolves the root cause across the affected type graph, not merely the smallest local edit.2410. Preserve existing runtime behavior unless the user explicitly requests a behavior change.2526## Python type safety rules27When writing or modifying Python code:2829- NEVER use `typing.cast()` or any form of explicit type coercion to silence type errors.30- Using `typing.cast()` to bypass type checking is considered a bug, not a fix.31- Do NOT use `cast(Any, ...)`, `cast(...)`, `Any`, or similar constructs to bypass static type checking.3233Instead:3435- Fix the root cause of the type mismatch.36- Adjust type annotations so they correctly reflect actual runtime types.37- Refactor code so that types align naturally.38- Introduce proper abstractions when necessary, such as `Protocol`, generics, or interface redesign.3940## Error handling philosophy41- Treat type checker errors as real design issues, not something to suppress.42- Never resolve them by masking or bypassing the type system.4344## Behavior preservation45- Preserve existing runtime behavior unless the user explicitly requests a change.46- Minimize the scope of changes while ensuring correctness.4748## Type impact analysis49When fixing type errors, do not optimize only for the smallest local edit.5051Before changing any of the following, analyze downstream and upstream impact:5253- function return types54- parameter types55- class attributes56- dataclass fields57- TypedDict fields58- Protocol or ABC methods59- generic type parameters60- overloads61- public API signatures62- values shared across module boundaries6364For each candidate fix, determine whether the root cause is:65661. the producer returns or exposes the wrong type,672. the consumer expects the wrong type,683. the annotation is narrower or wider than the actual runtime behavior,694. a missing runtime branch or invariant check,705. an interface or abstraction boundary mismatch.7172Prefer the fix that makes the type model consistent across all affected call sites.7374Do not change a return type merely to satisfy one caller if other callers rely on the existing contract.7576Do not change a caller merely to satisfy one callee if the callee annotation is inconsistent with its actual runtime behavior.7778If changing a signature or return type is necessary:79801. inspect all call sites,812. update affected annotations and usages together,823. preserve runtime behavior,834. run the project-appropriate type checker after the full set of changes.8485## Impact validation86After changes:87881. Review all call sites and usages of modified code.892. Verify that no type mismatches are introduced elsewhere.903. Check for runtime incompatibilities, logical regressions, or unintended behavior changes.914. Before reporting completion, validate that the fix does not move the same type mismatch to another caller, callee, module, or return path.9293For Python code changes:94951. If the project defines a specific validation command in ``.codex/AGENTS.md`, `AGENTS.md`, `README.md`, `Makefile`, `tox.ini`, `noxfile.py`, `pyproject.toml`, or CI configuration, prefer the project-defined command.962. Detect the project environment before running Python validation commands:97 - If the project contains `uv.lock`, `[tool.uv]` in `pyproject.toml`, or documented commands using `uv run`, treat it as a `uv` project and prefer `uv run <command>`.98 - If the project appears to use Poetry, PDM, Hatch, tox, or nox, prefer the corresponding documented command form.99 - If no project environment manager is detected, and the command is available on PATH, run it directly.1003. If the diagnostics mention `pyright`, or if the project contains `pyrightconfig.json` or `[tool.pyright]` in `pyproject.toml`, run the appropriate Pyright command:101 - For `uv` projects: `uv run pyright`102 - Otherwise: `pyright`1034. If the diagnostics mention `mypy`, or if the project contains mypy configuration in `pyproject.toml`, `mypy.ini`, `setup.cfg`, or `tox.ini`, run the appropriate mypy command:104 - For `uv` projects: `uv run mypy .`105 - Otherwise: `mypy .`1065. If both Pyright and mypy appear to be configured, run both.1076. If a validation command fails because the command is missing, the environment is unavailable, or dependencies are not installed, report:108 - the exact command attempted109 - the exact failure reason110 - what validation remains manual111112A fix is not complete until affected usages are validated.113114## Optional improvements115- Do NOT introduce behavioral changes, optimizations, or redesigns silently.116- Provide them separately as clearly labeled optional suggestions.117118## Exception119- `typing.cast()` may only be used if explicitly requested by the user.120- In that case, explain why it is safe and does not introduce runtime risk.121122## Response format123After completing the work, report in Korean:124125- 변경한 파일126- 근본 원인127- 타입 영향 범위128- 정확한 수정 내용129- 실행한 검증 명령130- 검증 결과131- 남은 불확실성, 있는 경우132- 선택 제안, 관련 있는 경우만133134Do not say that full-project validation was skipped because the command was unspecified if a project-appropriate validation command could be inferred, such as `uv run pyright`, `pyright`, `uv run mypy .`, `mypy .`, or another configured command.135136## Language137- All explanations, comments, and docstrings must be written in Korean.