Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- **🛡️ Smart File Handling** - Multiple strategies for managing existing files (overwrite, skip, backup, etc.)
- **🪝 Automation Hooks** - Pre and post-generation shell commands
- **🎯 Dry Run Mode** - Preview changes before applying them
- **🔎 Structure Explanations** - Inspect nested structures, variables, hooks, remote references, and conflict behavior before generation
- **✅ Validation & Schema** - Built-in YAML validation and IDE support
- **🤖 MCP Integration** - Model Context Protocol support for AI-assisted development workflows

Expand Down Expand Up @@ -73,6 +74,9 @@ docker run -v $(pwd):/workdir ghcr.io/httpdss/structkit:main generate my-config.
### Basic Usage

```bash
# Explain a Terraform module structure without writing files
structkit explain terraform/modules/generic

# Generate a Terraform module structure
structkit generate terraform-module ./my-terraform-module

Expand Down
43 changes: 42 additions & 1 deletion docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The `struct` CLI allows you to generate project structures from YAML configurati
**Basic Usage:**

```sh
structkit {info,validate,generate,list,generate-schema,mcp,completion,init} ...
structkit {info,validate,generate,explain,list,generate-schema,mcp,completion,init} ...
```

## Global Options
Expand Down Expand Up @@ -115,6 +115,37 @@ structkit generate
- `--mappings-file MAPPINGS_FILE`: Path to a YAML file containing mappings to be used in templates (can be specified multiple times).
- `-o {console,file}, --output {console,file}`: Output mode.

### `explain`

Explain how a structure definition resolves before generation. This is structure-focused: it lists the files and folders that would be generated, nested structures referenced by `folders[].struct`, remote file references, declared variables and resolved values, hooks that would be present, and the configured conflict behavior. It does not create files or folders, fetch remote content, generate prompt-based content, or execute hooks.

Use `generate --dry-run` when you want a generation-style preview of file operations and diffs. Use `explain` when you want to inspect the structure graph and metadata before any generation work happens.

**Usage:**

```sh
structkit explain [-h] [-l LOG] [-c CONFIG_FILE] [-i LOG_FILE] [-s STRUCTURES_PATH] [-v VARS] [--json] [-o {text,json}] [-f {overwrite,skip,append,rename,backup}] [--mappings-file MAPPINGS_FILE] [structure_definition] [base_path]
```

**Arguments:**

- `structure_definition` (optional): Built-in structure name or path to a YAML structure file (default: `.struct.yaml`).
- `base_path` (optional): Base path used to resolve generated paths (default: `.`).
- `-s STRUCTURES_PATH, --structures-path STRUCTURES_PATH`: Path to structure definitions.
- `-v VARS, --vars VARS`: Template variables in the format KEY1=value1,KEY2=value2; shown in the explanation with resolved defaults.
- `--json`: Output the explanation as JSON.
- `-o {text,json}, --output {text,json}`: Output format (default: `text`).
- `-f {overwrite,skip,append,rename,backup}, --file-strategy {overwrite,skip,append,rename,backup}`: File conflict strategy to explain.
- `--mappings-file MAPPINGS_FILE`: Path to a YAML mappings file for resolving `with` values and templates (can be specified multiple times).

**Examples:**

```sh
structkit explain terraform/modules/generic
structkit explain ./my-struct.yaml --vars project_name=demo
structkit explain project/python --json
```

### `list`

List available structures.
Expand Down Expand Up @@ -214,6 +245,16 @@ Pass template variables to the structure:
structkit generate -v "project_name=MyApp,author=John Doe" file://structure.yaml ./output
```

### Explaining Structure Resolution

Preview the structure graph, variables, hooks, remote file references, and conflict behavior without writing files or executing hooks:

```sh
structkit explain project/python --json
```

`explain` is different from `generate --dry-run`: `explain` focuses on resolving and describing the structure definition, while `generate --dry-run` follows the generation path to preview file operations.

### Dry Run

Test structure generation without creating files:
Expand Down
71 changes: 68 additions & 3 deletions docs/mcp-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,38 @@ Generate a project structure using specified definition and options.
- `mappings` (optional): Variable mappings for template substitution
- `structures_path` (optional): Custom path to structure definitions

### 4. validate_structure
### 4. explain_structure
Explain how a structure resolves without creating files, fetching remote content, generating prompt-based content, or executing hooks. This is useful when an AI assistant needs to inspect the structure graph before deciding whether to generate it.

```json
{
"name": "explain_structure",
"arguments": {
"structure_definition": "project/python",
"base_path": "/tmp/myproject",
"output": "json",
"variables": {
"project_name": "MyProject"
},
"mappings": {
"team": "platform"
},
"file_strategy": "overwrite",
"structures_path": "/path/to/custom/structures"
}
}
```

**Parameters:**
- `structure_definition` (required): Name or path to the structure definition
- `base_path` (optional): Base path used to resolve generated paths (default: `.`)
- `output` (optional): Output mode - `"text"` or `"json"` (default: `"text"`)
- `variables` (optional): Template variables to resolve structure names, paths, hooks, and nested `with` values
- `mappings` (optional): Additional mappings exposed to templates as `mappings`
- `file_strategy` (optional): Conflict strategy to explain: `overwrite`, `skip`, `append`, `rename`, or `backup` (default: `overwrite`)
- `structures_path` (optional): Custom path to structure definitions

### 5. validate_structure
Validate a structure configuration YAML file.

```json
Expand Down Expand Up @@ -204,6 +235,12 @@ async def main():
# FastMCP tools return plain text content
print(result.content[0].text)

explanation = await session.call_tool("explain_structure", {
"structure_definition": "project/python",
"output": "json"
})
print(explanation.content[0].text)

if __name__ == "__main__":
asyncio.run(main())
```
Expand All @@ -225,8 +262,9 @@ The MCP tools can be chained together for complex workflows:

1. List available structures
2. Get detailed info about a specific structure
3. Generate the structure with custom mappings
4. Validate any custom configurations
3. Explain the structure to preview files, folders, variables, hooks, and remote references
4. Generate the structure with custom mappings
5. Validate any custom configurations

### Integration Examples

Expand Down Expand Up @@ -265,6 +303,32 @@ The MCP tools can be chained together for complex workflows:
}
```


**Example 3: Explain Before Generate**
```json
// 1. Explain structure resolution without side effects
{
"name": "explain_structure",
"arguments": {
"structure_definition": "project/python",
"base_path": "/tmp/review",
"output": "json",
"variables": {
"project_name": "ReviewProject"
}
}
}

// 2. If the explanation looks correct, generate the structure
{
"name": "generate_structure",
"arguments": {
"structure_definition": "project/python",
"base_path": "/tmp/review"
}
}
```

## Configuration

### Environment Variables
Expand Down Expand Up @@ -353,6 +417,7 @@ Once connected, you can use these tools:
- `list_structures` - Get all available structures
- `get_structure_info` - Get details about a specific structure
- `generate_structure` - Generate project structures
- `explain_structure` - Explain structure resolution without side effects
- `validate_structure` - Validate YAML configuration files

## Troubleshooting
Expand Down
Loading
Loading