Add explain command to preview structure resolution#143
Closed
httpdss wants to merge 3 commits into
Closed
Conversation
…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.
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.
Motivation
generate --dry-runwhich simulates file operations and diffs.Description
explainimplemented instructkit/commands/explain.pythat resolves structure definitions and reports files, folders, nestedfolders[].structtraversal, declared variables and resolved values, hooks (rendered but not executed), remote file references (detected but not fetched), and configured conflict behavior.ExplainCommandtoget_parser()instructkit/main.py.--json/-o json, accept--vars,--mappings-file, and--file-strategy, and use the same Jinja2 rendering environment/filters for variable resolution andwithrendering.docs/cli-reference.md,README.md) withexplainusage, examples, and guidance on how it differs fromgenerate --dry-run.tests/test_explain_command.pyto 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
pytest tests/test_explain_command.pyand the new tests passed.pytest, resulting in all tests passing (158 passed).python -m compileall structkit tests/test_explain_command.pywhich succeeded.python -m structkit.main explain project/python --jsonto verify JSON output, which produced the expected explanation output.Codex Task