From 0b0c10b3237895b4db9380aea61444a58ec934b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Mon, 30 Mar 2026 21:50:14 +0800 Subject: [PATCH] docs(agents): enforce constant reuse rules (#2348) --- .agents/skills/pr-creation-checker/SKILL.md | 3 +++ .../references/pr-readiness-checklist.md | 1 + AGENTS.md | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/.agents/skills/pr-creation-checker/SKILL.md b/.agents/skills/pr-creation-checker/SKILL.md index 05877b39f..0a269d05b 100644 --- a/.agents/skills/pr-creation-checker/SKILL.md +++ b/.agents/skills/pr-creation-checker/SKILL.md @@ -26,6 +26,8 @@ Use this skill before `gh pr create`, before `gh pr edit`, or when reviewing whe - Review the diff and summarize what changed. - Call out unrelated edits, generated artifacts, logs, or secrets as blockers. - Mark risky areas explicitly: auth, storage, config, network, migrations, breaking changes. +- Scan the diff for newly added string literals and confirm whether they duplicate values already defined as constants/enums/typed wrappers in the same module or shared modules. +- Treat introducing a new hardcoded literal where a project constant already exists as a likely regression risk; require either a refactor to reuse the constant or an explicit exception explanation in the PR body. 3. Verify readiness requirements - Require `make pre-commit` before marking the PR ready. @@ -82,6 +84,7 @@ Use this skill before `gh pr create`, before `gh pr edit`, or when reviewing whe - Return `BLOCKED` if required template sections are missing. - Return `BLOCKED` if the title/body is not in English. - Return `BLOCKED` if the title does not follow the repository's Conventional Commit rule. +- Return `BLOCKED` if the diff introduces string literals that should use existing constants but did not. ## Reference diff --git a/.agents/skills/pr-creation-checker/references/pr-readiness-checklist.md b/.agents/skills/pr-creation-checker/references/pr-readiness-checklist.md index e2cf448ae..61a9c65dd 100644 --- a/.agents/skills/pr-creation-checker/references/pr-readiness-checklist.md +++ b/.agents/skills/pr-creation-checker/references/pr-readiness-checklist.md @@ -12,3 +12,4 @@ - Confirm non-applicable sections are filled with `N/A`. - Confirm the PR body does not include local absolute paths unless explicitly required. - Confirm multiline GitHub CLI commands use `--body-file`. +- Confirm new hardcoded string literals were not introduced for values already represented by existing constants/enums (including protocol labels, error identifiers, headers, and metric names), or record a justified exception. diff --git a/AGENTS.md b/AGENTS.md index e9abdd3db..2a0dd0f1b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -23,6 +23,14 @@ If repo-level instructions conflict, follow the nearest file and keep behavior a - Preserve the existing control-flow and logic shape when fixing bugs or addressing review comments, especially in init, distributed coordination, locking, metadata, and concurrency paths. - Do not refactor existing code only to make it easier to unit test. - Keep fixes narrowly aligned with the requested behavior; avoid semantic-adjacent rewrites while touching sensitive paths. +- Keep code elegant, concise, and direct. Prefer minimal, readable implementations over over-engineering and excessive abstraction. Use comments to clarify non-obvious intent and invariants, not to compensate for unclear code. + +## Constant and String Usage + +- Before introducing new string literals, search for existing constants/enums that already represent the same semantic value. +- Reuse existing constants for protocol labels, error identifiers, header keys, event names, metric names, command tags, and similar fixed tokens. +- If a new string is truly unique, define a local constant near related logic and avoid scattering the literal across multiple sites. +- When changing existing behavior, keep naming and format consistency by aligning with established project constants. ## Sources of Truth