Skip to content

Commit 1826606

Browse files
committed
docs(logging[AGENTS]): add output channels section to AGENTS.md
why: Developers need guidance on the 2-channel output architecture (logger for diagnostics, tmuxp_echo/OutputFormatter for user output). what: - Add "Output channels" section with diagnostics vs user-facing rules - Document print() prohibition in command/business logic - Expand "Avoid" entry for print() with structured extra guidance
1 parent fd390b6 commit 1826606

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

AGENTS.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,24 @@ Assert on `caplog.records` attributes, not string matching on `caplog.text`:
206206
- Assert on schema: `record.tmux_exit_code == 0` not `"exit code 0" in caplog.text`
207207
- `caplog.record_tuples` cannot access extra fields — always use `caplog.records`
208208

209+
### Output channels
210+
211+
Two output channels serve different audiences:
212+
213+
1. **Diagnostics** (`logger.*()` with `extra`): System events for log files, `caplog`, and aggregators. Never styled.
214+
2. **User-facing output**: What the human sees. Styled via `Colors` class.
215+
- Commands with output modes (`--json`/`--ndjson`): prefer `OutputFormatter.emit_text()` from `tmuxp.cli._output` — silenced in non-human modes.
216+
- Human-only commands: use `tmuxp_echo()` from `tmuxp.log` (re-exported via `tmuxp.cli.utils`) for user-facing messages.
217+
- **Undefined contracts:** Machine-output behavior for error and empty-result paths (e.g., `search` with no matches) is not yet defined. These paths currently emit styled text through `formatter.emit_text()`, which is a no-op in machine modes.
218+
219+
Raw `print()` is forbidden in command/business logic. The `print()` call lives only inside the presenter layer (`_output.py`) or `tmuxp_echo`.
220+
209221
### Avoid
210222

211223
- f-strings/`.format()` in log calls
212224
- Unguarded logging in hot loops (guard with `isEnabledFor()`)
213225
- Catch-log-reraise without adding new context
214-
- `print()` for diagnostics
226+
- `print()` for debugging or internal diagnostics — use `logger.debug()` with structured `extra` instead
215227
- Logging secret env var values (log key names only)
216228
- Non-scalar ad-hoc objects in `extra`
217229
- Requiring custom `extra` fields in format strings without safe defaults (missing keys raise `KeyError`)

0 commit comments

Comments
 (0)