Skip to content

Commit e41dfa2

Browse files
Herklosclaude
andcommitted
[CLAUDE.md] add code conventions from PR #3429 review
Patterns: enums in enums.py, constants in constants.py, typed error hierarchies, TypedDicts for structured dicts, filelock for cross-platform locking, tentacle import priority (tentacles-first), log level guidelines, shared filter helpers. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent aaf094f commit e41dfa2

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,49 @@ Use when: running tests, debugging test failures, or verifying changes after cod
3636

3737
Trigger: `@agent-test-runner` · Definition: `.claude/agents/test-runner.md`
3838

39+
## Code Conventions
40+
41+
### Enums
42+
Place enums in `<package_root>/enums.py` (e.g. `octobot/enums.py`, `packages/node/octobot_node/enums.py`). Never define enums inline in module files.
43+
44+
### Constants
45+
Place module-wide constants in `<package_root>/constants.py`. Private module constants (used only within one file) may stay in that file, prefixed with `_`.
46+
47+
### Typed errors
48+
Define a typed error hierarchy rather than raising bare `ValueError`/`KeyError`. Pattern:
49+
```python
50+
# errors.py (sibling to the feature module)
51+
class FeatureError(Exception): pass
52+
class SpecificError(FeatureError, ValueError): pass # multi-base preserves except ValueError compat
53+
```
54+
Re-export from the package `__init__.py`. Use typed catches in API routes — never inspect `str(err).lower()`.
55+
56+
### TypedDicts for structured dicts
57+
When a dict has a fixed schema (e.g. wallet info returned to callers), define a `typing.TypedDict`. Place it in the module that owns the data, before the class that produces it.
58+
59+
### File locking
60+
Use the `filelock` library (cross-platform, POSIX + Windows) instead of `fcntl`/`msvcrt` branching.
61+
62+
### Import priority in tentacle files
63+
Prefer the installed `tentacles.Services.Interfaces.*` path first; fall back to bare direct imports (build-time fallback). Pattern:
64+
```python
65+
try:
66+
from tentacles.Services.Interfaces.node_api_interface.api.deps import X
67+
except ImportError:
68+
from api.deps import X # type: ignore[no-redef]
69+
```
70+
All files within a tentacle package should use the same priority order.
71+
72+
### Log levels
73+
- `debug`: verbose diagnostics, expected no-ops.
74+
- `info`: normal operational events (startup, shutdown, config loaded).
75+
- `warning`: unexpected but recoverable (auto-unlock skipped, optional feature unavailable).
76+
- `error`: configuration/state errors that affect functionality (wallet missing, key wrong).
77+
- `exception`: unexpected exceptions — always re-raise after logging unless the function is a top-level "best-effort" path that must not crash the caller.
78+
79+
### Shared filter helpers
80+
Filtering logic used in multiple places belongs in a shared utility module (e.g. `workflows_util.py`), not duplicated inline. Name with a verb: `filter_by_wallet`, not `_filter`.
81+
3982
## Documentation
4083

4184
Documentation lives in `docs/content/` and is built with Docusaurus 3. Package docs go under `docs/content/developers/packages/<pkg-name>/`.

0 commit comments

Comments
 (0)