Repository navigation
Conversation
Add code-shape-kit v0.3.0 as a dev dependency (Python 3.11.4+ only, as the kit needs it), the [tool.shape] and import-linter config from code-shape init, the CI gate, CODEOWNERS for the rule files and the agent rules in AGENTS.md. Changes to init's guesses: __main__ is the top layer (it is the entry point), and adapters are declared for claude_agent_sdk, httpx, telegram, PIL, pillow_heif and dotenv. ruff now treats loguru's logger like the kit does, so a catch-all that logs the traceback passes BLE001.
- Split bot.py into the hometabs.bot package: app (handlers, turn queue), chats (per-chat agents and sessions), model_menu (/model, /effort), media (images and albums), replies (sending), stores (JSON state). - Only config.py reads the environment: LOG_LEVEL, ANTHROPIC_BASE_URL and the credential scrub go through it, and options.env now carries only the chosen credential (the SDK merges it over the scrubbed process env). - Telegram's InvalidToken is handled in the bot package. - Break up summarize_tool_input and BrowsingAgent.ask; narrow the broad excepts, or log the traceback where a catch-all is deliberate. - Fix type errors (effort level, image source, optional Telegram fields) without type: ignore; make boolean flags keyword-only. - Remove dead code (REPL_TOOL, init_info, connected) and the optional pillow-heif import, which is a required dependency; use CACHE_FILENAME.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sets up code-shape-kit v0.3.0 and fixes everything it found.
code-shape checkpasses with no baseline file.Setup
code-shape-kit[tools] @ git+…@v0.3.0is in thedevgroup, with the marker; python_full_version >= '3.11.4'. The kit needs 3.11.4+ and the project still supports 3.10, so on 3.10uv syncskips the kit (the 3.10 test job still passes).code-shape initadded[tool.shape]and[tool.importlinter]topyproject.toml, plus.github/workflows/code-shape.yml(on Python 3.11) and.github/CODEOWNERS(owner:@emanuilo).AGENTS.md(new) has the "Code shape" rules for agents.Rules: init's guesses and what I changed
packageshometabs(src layout)config_modulessrc/hometabs/config.py__init__.pyandauth.pyalso read the environment; that code now goes through configbot -> images -> agent | models -> __main__ | auth | config | formatting | skills__main__moved to the top (see below). Now__main__ -> bot -> images -> agent | models -> auth | config | formatting | skillsignore_importsbanned_apios.environrulesclaude_agent_sdk(agent.py, models.py),httpx(models.py),telegram(bot/*),PILandpillow_heif(images.py),dotenv(config.py)output_modulescli.py,__main__.py)logger_objectsWhy:
__main__moved up. init put it at the bottom because it only imports the package root. It's the entry point, though, andhometabs/__init__.pyimportsbot, so__main__ -> hometabs -> botbroke the contract. Per designing-the-shape.md, entry points go on top. Noignore_importswere needed.claude_agent_sdkis allowed inmodels.pyas well asagent.py.models.pyreads the SDK'sEffortLevelliteral. Moving that intoagent.pywould makemodelsimportagent, which breaks theagent | modelsindependence, so I left both allowed.[tool.ruff.lint]I addedlogger-objects = ["loguru.logger"]. With it, ruff acceptsexcept Exception: logger.exception(...)(BLE001) the same way the kit does. Without it, the existing CI lint job would neednoqacomments again.Worth a look (not changed):
imagessits aboveagentonly becauseimages.pyimports theImagedataclass fromagent.py.Imageis plain domain data inside the SDK adapter, so it could move to a small domain module.Findings
Before: 56 (all NEW, no baseline). After: 0.
The 56, by check:
Code changes
bot.py(853 lines, class 616) is now thehometabs.botpackage:app.py: handlers and the turn queue. ATurnRequestreplaces the 6-argument calls.chats.py: per-chat agents, locks and saved sessions.model_menu.py: /model and /effort texts, buttons and the choice itself.media.py: image refs, album collection, downloads.replies.py: sending text and images, typing, the "Working… step N" message.stores.py:sessions.jsonandsettings.json, with one shared JSON read/write.config.pytouches it now (log_level(),unset_env_vars(),Settings.anthropic_base_url).build_cli_envputs only the chosen credential inoptions.env. Before, it also copied the whole scrubbedos.environ, which added nothing: the SDK mergesoptions.envoveros.environanyway. Telegram'sInvalidTokenis now handled inHometabsBot.run(), which raisesConfigError.summarize_tool_inputuses a dispatch table and small helpers.BrowsingAgent.askhands each message to a_Turncollector.EffortLeveltype instead of usingtype: ignore. An unknown level is dropped with a warning./stop, a failed turn), it now logs the traceback withlogger.exception. Allnoqacomments and the onetype: ignoreare gone.effective_message/effective_chatare guarded.extract_imagesnarrowing and theexif_transposevariable.refresh(force=)andbusy=are now keyword-only.REPL_TOOL(used only in tests),BrowsingAgent.init_infoand.connected(nothing reads them, including at runtime), and the "optional"pillow_heifimport. pillow-heif is a required dependency, soHEIF_SUPPORTEDand itspragma: no coverwent too.models_cache.jsonnow usesCACHE_FILENAME.unset_env_varsandanthropic_base_url. Thebuild_cli_envtests now check that the env holds exactly the credential.Tests: 141 passed on Python 3.12 and on 3.10.
ruff checkandruff format --checkare clean, anduv lock --checkis OK.Needs a decision
Nothing is escalated: every finding was fixed in the code.
code-shape check --base origin/mainreports one "rule loosened":config.py may now use os.environ. That's expected, sincemainhad no config.Before merging
main, turn on "Require review from Code Owners".🤖 Generated with Claude Code