The session create command already emitted a spec-compliant JSON envelope
with messages[].text populated, but list, show, delete, export, and
import did not — they either passed no `messages` to `format_output()`
(producing an envelope with an empty messages array) or short-circuited
to a Rich-styled `console.print(...)` line that breaks JSON parsing
entirely.
Failing scenarios in features/session_cli.feature (unit_tests gate)
asserted `messages[0].text == "<command-specific success>"`. Wire each
command's machine-readable path to emit a structured envelope with the
expected message:
- list (empty) → "0 sessions listed"
- list (populated) → "<N> sessions listed"
- show → "Session details loaded"
- delete --format json|yaml|plain → "Session deleted"
- export --output-format json|yaml|plain → "Export completed"
- import --format json|yaml|plain → "Import completed"
The export command gains a new `--output-format` flag distinct from the
existing `--format` (which selects export content format: json or md).
When the new flag is non-rich, the raw export content is suppressed from
stdout so the envelope remains the only thing emitted, and Rich panels
are skipped.
The import command gains a `--format` flag. The delete command already
had a `--format` option but its non-rich branch emitted Rich-styled text
instead of an envelope; that branch now splits cleanly: `--format color`
keeps the human-readable line, and json/yaml/plain emit an envelope.
Also addresses the `Session create initializes MCP logger` and
`Session list initializes MCP logger` scenarios in
features/session_cli_mcp_logger_simple_execution.feature, which inspect
the create()/list_sessions() source via inspect.getsource() and assert
the literal string `logging.getLogger(_MCP_LOGGER_NAME)` appears. Both
functions held the inlined literal `"cleveragents.mcp"` instead of the
module-level `_MCP_LOGGER_NAME` constant; substitute the constant
reference in both call sites.
CHANGELOG entry extended to document the envelope coverage across all
session commands.
ISSUES CLOSED: #6441
Cover the two uncovered code paths introduced by the session create
JSON envelope fix:
1. `_resolve_actor_details(None)` → early `return None` (no actor bound)
2. Actor found in registry path (lines 271-297) — two scenarios:
- Full config actor (options.temperature + direct context_window)
- Graph descriptor actor (graph_descriptor.context_window)
Also remove dead redundant isinstance checks:
- `config_blob.get("options") if isinstance(config_blob, dict) else None`
simplified to `config_blob.get("options")` since config_blob is always
a dict (assigned on the previous line via ternary with {} fallback).
- Outer `if isinstance(config_blob, dict):` wrapper around context_window
logic removed for the same reason.
ISSUES CLOSED: #6441
- Fix `security_template_coverage_boost.feature` assertion for "Session
export to stdout outputs JSON": the export path outputs raw JSON with
a `session_id` key, not a `data` envelope, so revert the erroneous
`"data"` assertion back to `"session_id"`.
- Move all deferred `from cleveragents.application.container import
get_container` imports in session.py to the module-level import
block, consistent with every other CLI command file (action.py,
actor.py, config.py, plan.py, etc.). No circular import exists.
- Update `session_cli_uncovered_branches_steps.py` to patch
`cleveragents.cli.commands.session.get_container` directly (the
correct target after a top-level import) instead of replacing
`sys.modules["cleveragents.application.container"]`.
- Add CHANGELOG.md entry for the session create JSON envelope fix.
ISSUES CLOSED: #6441
Update feature file assertions to match the new nested JSON structure
for session create output. Changed assertions from 'session_id:' to 'id:'
to reflect the new data.session.id structure per spec #6441.