build-discipline
User build rule: plan tasks, tests required, modular files.
- License 许可
- MIT
- 最近更新
- 2026-10-14
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- build-discipline
- tags
- [ "coding-standards", "testing", "planning", "modular", "workflow", "process" ]
- author
- Hermes Agent (captured from user correction)
- license
- MIT
- version
- 1.0.0
- platforms
- [ "linux", "macos", "windows" ]
- description
- User build rule: plan tasks, tests required, modular files.
- related_skills
- [ "writing-plans", "test-driven-development", "ponytail", "code-refactoring", "verification-loop" ]
02 资源文件 3
- 参考文档references/cli-module-split-template.md5.4 KB
- 参考文档references/hatchling-empty-wheel.md1.5 KB
- 参考文档references/telegram-tg-cli-user-session.md2.1 KB
03 SKILL.md 正文
Build Discipline (dbillion — explicit, non-negotiable mandate)
Captured from a direct user correction. These rules apply to EVERY software build, refactor, or coding task for this user. They are process-level, not language-specific.
The Four Rules
-
Plan, then tasks, then TICK.
- Write a plan. Convert it into a task list (use the
todotool or a written checklist). Mark each taskcompletedthe moment its work is done and verified — not in bulk at the end. An un-ticked task list where you did the work anyway is a miss; tick as you go.
- Write a plan. Convert it into a task list (use the
-
Unit tests are MANDATORY. No tests = FAILURE.
- "If you can't test what you just built, you have failed — do not claim success."
- Plan the test for each task up front. Prefer offline / pure-logic tests; mock
network, Telegram, filesystem where needed. Run the language's test runner
(
pytest,cargo test,gradle test) and confirm GREEN before reporting done. - A build that cannot be exercised by a test is, by this user's rule, a failed build.
-
Break large files into modules. NEVER leave a 400-line monolithic file that could be modular.
- This user detests long unmodularized files. Split by responsibility (e.g. client / cache / forward / score / cli). Each unit importable and testable.
- Before writing a file, ask: "could this be 3 smaller files?" — if yes, do it.
- The refactor IS the build; don't write an 800-line script and "refactor later."
-
For refactoring / code-structure work, load the
ponytailand/orcode-refactoringskills. Write plans and rules out EXPLICITLY — never imply them.
Workflow (concrete)
- Write the plan (see
writing-plansfor bite-sized structure). - Create the task list mirroring the plan.
- Implement + write the unit test for each task.
- Run the test runner; confirm green. Show the pass output.
- Tick the task
completed. - Repeat until all tasks done. Only then report success.
Pitfalls (this user's triggers — avoid)
- Monolithic file — rejected. Modularize as you build.
- "It works" without a green test run — never claim done unless the runner actually passed in this session. Paste/summarize the pass output.
- Un-ticked tasks — a plan with N items where you did some and said "done" is a miss.
- Implied rules — state the plan and the testing approach plainly.
The "creeping monolith" trap (learned the hard way)
A monolith rarely appears in one edit — it creeps. Across several small
add this function / add this command edits, a module that started at 200
lines quietly grew to 600+ before anyone noticed. The user's actual words when
it surfaced: "why are you creating a god file of over 500 lines? cant you
modularize and import them using some of the template in python tricks."
Active guardrail — check LOC after every edit that adds lines to a module:
- If a source file exceeds ~200 lines, STOP and split BEFORE the next edit.
- Do not wait for the user to flag it. A 694-line
cli.pyis a failure of this rule, not a one-time slip. - The codebase's own layout is the template (the user pointed at it as "the
template in python tricks"): one concern per module —
client.py,cache.py,forward.py,score.py,state.py,report.py. Follow that, don't invent a new structure.
Test files are god files too
The rule applies to the tests/ tree, not just source. A 353-line
test_offline.py covering 6 unrelated modules is a god test file and was
rejected the same way. Mirror the source layout: one tests/test_<module>.py
per source module (test_cache.py, test_score.py, test_forward.py,
test_peer.py, test_client.py, test_state.py, test_report.py, …). Keep
each test file focused and small; relocate shared fixtures/helpers into the
matching test module (or a tiny tests/conftest.py if truly cross-cutting).
Delete the god file once split.
Click / Telegram CLI modularization template (reusable split)
When a CLI module (e.g. a Click cli.py driving Telegram/Telethon) balloons:
<pkg>/peer.py(pure primitives): dataclasses, retry/timer helpers, lazyiter_*generators, content-hash + peer-matching helpers, batched-op functions. Importable + unit-testable with NO network/Telegram.<pkg>/commands.py(async command bodies): theforward_run,dedupe_run,login_run,score_run,test_ocr_run,interactive_menuimplementations. No@click.optiondecorators here.<pkg>/cli.py(thin layer, ~100-150 lines):@click.command()decorators with options, each calling the matching*_runbody viaasyncio.run(...). Behavior is preserved; only the import graph changes. After splitting, update any test imports that referenced symbols moved out ofcli(e.g.tgforwarder.cli._is_from_source→tgforwarder.peer._is_from_source).
Near-parallel pipeline branch → its own module
A function is a hidden god function when it embeds TWO similar pipelines. In
forward_run, the COPY-mode (download→upload→delete) loop was a ~67-line
near-parallel pipeline living inside the native-forward function, inflating the
file to 358 lines. Extract it into <pkg>/copy_mode.py as run_copy_mode(...)
with a clean RETURN tuple (count, max_id, run_forwarded) so the orchestrator
can still persist resume state. Pass all shared collaborators (client, src, tgts,
done_by_target, cache, logger) as args. Then commands.py stays a thin
orchestrator (~220 lines) and copy_mode.py is independently unit-testable.
Async unit tests WITHOUT adding pytest-asyncio
If the repo has no pytest-asyncio dependency, do NOT introduce one just to
test coroutines. Write the test as a plain sync function and drive the coroutine
with asyncio.run(...):
import asyncio
def test_copy_mode_dedups_by_content_hash_within_target(tmp_path):
client = _StubClient(msgs)
_, _, run_forwarded = asyncio.run(run_copy_mode(client, ...))
assert run_forwarded == 1
This keeps the suite dependency-free while giving the async module real
coverage. Stub the async client with a class whose iter_messages returns a
real async def gen() and whose send_message/download_media are async def.
See references/cli-module-split-template.md for the full worked example.
Verification
- Test runner exit code 0 with passing tests = proof of done.
todolist shows all itemscompleted= proof of tracking.- File sizes reasonable (no single source file sprawling past ~200 lines when it could be split) = proof of modularity. Check LOC after every line-adding edit, not just at the end — the creeping-monolith trap is the common failure mode.
Reference files (session-specific detail)
references/cli-module-split-template.md— worked example of all three splits:cli.py694→116 (peer/commands/cli),commands.py358→224 (extractcopy_mode,login,dedupe), and thetest_offline.py353 god-test split into per-module test files. Includes the async-without-pytest-asyncio stub pattern and the post-split verification checklist.references/telegram-tg-cli-user-session.md— fix fortg chatsfailing as a bot session; point kabi-tg-cli at a real user.session+ own API creds.references/hatchling-empty-wheel.md— whyuv buildemits an empty wheel when modules sit at project root instead of inside<pkg>/, and how to verify/fix.
Remember
Plan -> tasks -> TICK each as completed
Unit tests mandatory (no tests = failure; show green run)
Modular files only (no 400-line monoliths)
Load ponytail / code-refactoring for structure work
Write rules explicitly
Reference files (session-specific detail)
references/telegram-tg-cli-user-session.md— fix fortg chatsfailing as a bot session; point kabi-tg-cli at a real user.session+ own API creds.references/hatchling-empty-wheel.md— whyuv buildemits an empty wheel when modules sit at project root instead of inside<pkg>/, and how to verify/fix.
04 同仓库更多 Skills
blocked-page-recovery
Use when a fetch fails: 403/429, paywall, WAF, bot wall.
gemini-vision-fallback
Vision fallback: Gemini REST API if vision_analyze blocked.
twitter-cli
Use twitter-cli for ALL Twitter/X operations — reading tweets, posting, replying, quoting, liking, retweeting, following, searching, user lookups. Invoke whenever user requests any Twitter interaction.
prism-scan
Structural analysis through dynamically generated cognitive lenses. Generates the optimal analytical lens for the specific code/artifact, then executes it. Finds conservation laws, structural invariants, and concrete bugs that vanilla analysis misses. Use on any code file, system design, or text artifact.
prism-reflect
Constraint transparency: analyzes an artifact structurally, then analyzes what its own analysis concealed. Produces a conservation law AND a constraint report showing what was maximized, what was sacrificed, and what to investigate next. The only AI skill that knows what it can't see.
prism-full
Full Prism: multi-pass structural analysis with mandatory adversarial self-correction. Designs custom analytical passes, executes them with chaining, then attacks its own findings before synthesizing. Use for maximum depth on important code or artifacts.