Skip to content

Add explain command to preview structure resolution#143

Closed
httpdss wants to merge 3 commits into
mainfrom
codex/implement-feature-from-issue-136
Closed

Add explain command to preview structure resolution#143
httpdss wants to merge 3 commits into
mainfrom
codex/implement-feature-from-issue-136

Conversation

@httpdss
Copy link
Copy Markdown
Owner

@httpdss httpdss commented May 8, 2026

Motivation

  • Provide a safe, no-side-effect way to inspect how a structure definition will resolve before generation, separate from generate --dry-run which simulates file operations and diffs.

Description

  • Add a new CLI command explain implemented in structkit/commands/explain.py that resolves structure definitions and reports files, folders, nested folders[].struct traversal, declared variables and resolved values, hooks (rendered but not executed), remote file references (detected but not fetched), and configured conflict behavior.
  • Register the command in the main CLI by adding ExplainCommand to get_parser() in structkit/main.py.
  • Support both text and JSON output via --json/-o json, accept --vars, --mappings-file, and --file-strategy, and use the same Jinja2 rendering environment/filters for variable resolution and with rendering.
  • Update documentation (docs/cli-reference.md, README.md) with explain usage, examples, and guidance on how it differs from generate --dry-run.
  • Add unit tests in tests/test_explain_command.py to cover CLI registration, nested structures, remote references, rendered hooks/variables, conflict behavior for existing files, text and JSON outputs, and ensure no side effects (no fetches, no subprocess runs).

Testing

  • Ran pytest tests/test_explain_command.py and the new tests passed.
  • Ran the full test suite with pytest, resulting in all tests passing (158 passed).
  • Performed static checks by compiling modules with python -m compileall structkit tests/test_explain_command.py which succeeded.
  • Exercised the CLI manually with python -m structkit.main explain project/python --json to verify JSON output, which produced the expected explanation output.

Codex Task

@httpdss httpdss added minor enhancement New feature or request labels May 9, 2026
@httpdss httpdss marked this pull request as ready for review May 9, 2026 11:40
…ucture resolution

- Provide a safe, side-effect-free way to inspect how a structure definition resolves (files, folders, variables, hooks, remote refs, and conflict behavior) before generation.
- Expose the capability both on the CLI and via MCP so automated/AI workflows can inspect structures prior to creating files or running hooks.

- Add a new CLI command implemented in `structkit/commands/explain.py` that resolves structure definitions and emits a human-friendly or JSON explanation without writing files, fetching remote content, or running hooks.
- Wire the command into the CLI by registering `ExplainCommand` in `structkit/main.py` and document `explain` usage in `README.md` and `docs/cli-reference.md`.
- Add MCP support by importing `ExplainCommand` into `structkit/mcp_server.py`, adding `_explain_structure_logic`, and registering the `explain_structure` tool for remote/AI clients.
- Implement variable resolution, Jinja2 rendering (with project-specific delimiters and filters), mappings file support, conflict behavior heuristics, and nested structure traversal in the explanation output.

- Added unit tests in `tests/test_explain_command.py` covering CLI registration, nested structures, remote file references, hooks, variable resolution, and conflict behavior; these tests were executed and passed.
- Extended `tests/test_mcp_integration.py` with `test_explain_structure_logic` and validation checks for inputs; these tests were executed and passed.
- Ran the test suite with `pytest` for the modified tests (`tests/test_explain_command.py` and updated MCP tests) and observed successful results.
@httpdss httpdss closed this May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant