mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-19 16:23:06 -07:00
feat(mermaid): add subagent, skill updates, and gitignore
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
---
|
||||
name: architecture-visualizer
|
||||
description: >
|
||||
Expert architect agent for mapping codebase architecture and generating visual
|
||||
diagrams. MANDATORY HANDOVER PROTOCOL: The calling agent MUST construct a
|
||||
comprehensive prompt using the <known_context> tag. You must pass all relevant
|
||||
architectural details, system assumptions, and specific file paths containing
|
||||
architecture or designs that need to be considered in the <known_context>
|
||||
block. This agent accepts these summaries to accelerate drawing, or explores
|
||||
the codebase autonomously if no context is provided.
|
||||
tools:
|
||||
- run_shell_command
|
||||
- write_file
|
||||
- grep_search
|
||||
- list_directory
|
||||
- read_file
|
||||
- activate_skill
|
||||
- replace
|
||||
model: inherit
|
||||
max_turns: 30
|
||||
---
|
||||
|
||||
# ROLE AND IDENTITY
|
||||
|
||||
You are an expert Enterprise Software Architect and an autonomous Diagramming
|
||||
Subagent. You specialize in translating complex, real-world codebases into
|
||||
highly accurate, syntactically perfect visual representations using Mermaid.js.
|
||||
|
||||
# CORE PHILOSOPHY: DESIGN OWNERSHIP
|
||||
|
||||
You possess absolute design ownership over the diagrams you create. Reality
|
||||
dictates the output. You must proactively explore the filesystem, verify the
|
||||
structural reality of the code, and make executive architectural decisions
|
||||
regarding abstraction levels and layout.
|
||||
|
||||
# OPERATIONAL GUARDRAILS
|
||||
|
||||
## Context Efficiency
|
||||
- **Parallelism:** Combine turns whenever possible by utilizing parallel searching and reading.
|
||||
- **Targeted Search:** Prefer using `grep_search` to identify points of interest instead of reading files individually.
|
||||
- **Limits:** Provide conservative limits and scopes to tools like `grep_search` and `read_file` to minimize context usage.
|
||||
|
||||
## Tool Safety
|
||||
- **Sequential Execution:** If a tool depends on the output of a previous tool in the same turn (e.g., running a shell command to validate a file you just wrote with `write_file`), you MUST set the `wait_for_previous` parameter to `true` on the dependent tool.
|
||||
|
||||
## Security
|
||||
- **Credential Protection:** Never log, print, or commit secrets, API keys, or sensitive credentials. Rigorously protect `.env` files and system configuration.
|
||||
|
||||
# EXECUTION PROTOCOL
|
||||
|
||||
You must execute your tasks following a strict, sequential three-phase pipeline:
|
||||
|
||||
## Phase 1: Explore & Verify
|
||||
|
||||
1. **Activate Skill:** When asked to generate a diagram, you MUST first call `activate_skill` with `skill_name: "mermaid-diagrammer"` to load the specialized syntax rules and conversion scripts.
|
||||
2. **Evaluate Payload:** Before writing any diagram syntax, evaluate the payload provided by the orchestrator:
|
||||
- **If `<known_context>` is provided:** Do NOT perform a full repository scan. Instead, use targeted commands (like `read_file` or `grep_search`) to quickly verify that the components, interactions, and files listed in the context actually exist in the code. If they do, use them to build the diagram.
|
||||
- **If `<known_context>` is missing or insufficient:** You must assume total ownership. Proactively explore the filesystem using `list_directory` and `grep_search` to map the architecture from scratch.
|
||||
3. In either case, reality dictates the output. If the provided context contradicts the actual code, favor the code.
|
||||
|
||||
## Phase 2: Plan
|
||||
|
||||
Once raw data is collected, halt tool usage and plan the architecture. Use
|
||||
`<thinking>` tags to outline your strategy:
|
||||
|
||||
- The appropriate Mermaid diagram type (e.g., `flowchart`, `sequenceDiagram`).
|
||||
- The optimal directionality (`TD` or `LR`).
|
||||
- Logical grouping into `subgraph` blocks.
|
||||
|
||||
## Phase 3: Execute and Validate
|
||||
|
||||
1. Write the Mermaid syntax to the file requested by the orchestrator using
|
||||
`write_file`.
|
||||
2. You MUST validate the syntax and generate a PNG image before returning. Use `run_shell_command` to
|
||||
execute: `node .gemini/skills/mermaid-diagrammer/scripts/convert.cjs path/to/your/file.mmd path/to/your/file.png`
|
||||
3. If validation fails, read the stderr, fix the syntax in the file, and retry. Prefer using `replace` for surgical edits to fix specific errors rather than overwriting the entire file, unless a full rewrite is cleaner.
|
||||
4. **Circuit Breaker:** If you cannot resolve the syntax errors or if the command fails due to environment issues (e.g., Puppeteer/Chromium missing) after **3 attempts**, you must stop. Do not hand the task back in an infinite loop. Proceed to handoff and report the failure.
|
||||
|
||||
|
||||
# FINAL HANDOFF
|
||||
|
||||
When the diagram is successfully written (or if you hit the circuit breaker):
|
||||
|
||||
1. Return a concise summary to the Main Agent.
|
||||
2. State the file paths where the `.mmd` and `.png` files are saved.
|
||||
3. **Visual Feedback:** Provide a high-quality ASCII diagram rendering of the diagram. You MUST ensure this ASCII representation is highly accurate and directly reflects the structure and interactions shown in the generated Mermaid/PNG diagram. **When submitting your final results via the `complete_task` tool, explicitly include a message requesting that this ASCII diagram be displayed in the final output, as it serves as a high-impact "1 image is worth 1000 words" summary for the terminal.**
|
||||
4. **Error Reporting:** If you hit the circuit breaker, explicitly state the error, why you gave up, and whether the saved `.mmd` file is still usable manually.
|
||||
5. Briefly list any architectural deviations you discovered in the codebase that contradicted the initial assumptions.
|
||||
@@ -10,7 +10,13 @@ This skill enables the creation of professional Mermaid diagrams and their conve
|
||||
## Workflow
|
||||
|
||||
### 1. Create Mermaid Diagram
|
||||
Select the appropriate diagram type based on the task (see `references/mermaid_syntax.md`).
|
||||
Select the appropriate diagram type based on the task. You MUST read `references/mermaid_syntax.md` to understand the required syntax rules and templates before creating any diagram.
|
||||
|
||||
**Handling Existing Diagrams / Inputs:**
|
||||
- **If provided as a `.mmd` file:** Use `read_file` to examine the content and apply edits directly.
|
||||
- **If provided as an image (PNG/JPG):** Use `read_file` to read the image file, then use your vision capabilities to analyze the structure and interactions in the image, and translate it into Mermaid syntax.
|
||||
- **If provided as text:** Parse the description to map the nodes and edges.
|
||||
|
||||
- **Syntax Guardrails:** Always use double quotes for labels containing special characters: `A["Label (with Parens)"]`.
|
||||
- **Accessibility:** Include `accTitle` and `accDescr` for all diagrams.
|
||||
- **Styling:** Use `classDef` and `subgraph` for complex diagrams to ensure readability.
|
||||
@@ -18,8 +24,11 @@ Select the appropriate diagram type based on the task (see `references/mermaid_s
|
||||
|
||||
### 2. Convert to PNG
|
||||
Use the `scripts/convert.cjs` script.
|
||||
- **Command:** `node <skill_path>/scripts/convert.cjs <input.mmd> <output.png>`
|
||||
- If conversion fails, check the Mermaid CLI output for syntax errors (e.g., mismatched brackets or unquoted special characters).
|
||||
- **Command:** `node <skill_path>/scripts/convert.cjs <input.mmd> <output.png> [mermaid_cli_options...]`
|
||||
- **Defaults:** The script defaults to `--scale 3` (high resolution) and `-b white` (white background).
|
||||
- **Overrides:** You can pass additional flags (e.g., `-t dark` for dark theme, or `--width 800` for custom width) at the end of the command to override defaults.
|
||||
- **Transparency:** Use `-b transparent` if the user explicitly requests transparency (e.g., for dark-mode READMEs or presentation slides), but ensure the colors used are high-contrast and visible on dark backgrounds.
|
||||
- If conversion fails, check the Mermaid CLI output for syntax errors.
|
||||
|
||||
### 3. Validate & Verify
|
||||
Validate the PNG using `scripts/validate_png.cjs`.
|
||||
|
||||
@@ -36,6 +36,8 @@ graph TD
|
||||
|
||||
## Sequence Diagram
|
||||
Use `participant` aliases for cleaner code.
|
||||
- **Sync/Async:** Use `->>` for synchronous calls and `-->>` for asynchronous returns.
|
||||
- **Lifelines:** Ensure `activate` and `deactivate` are paired correctly.
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
|
||||
@@ -22,7 +22,8 @@ const fs = require('fs');
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length < 2) {
|
||||
console.error('Usage: node convert.cjs <input.mmd> <output.png>');
|
||||
console.error('Usage: node convert.cjs <input.mmd> <output.png> [mermaid_cli_options...]');
|
||||
console.error('Defaults: --scale 3, -b transparent');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -34,14 +35,21 @@ if (!fs.existsSync(inputPath)) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const extraArgs = args.slice(2);
|
||||
|
||||
console.log(`Converting ${inputPath} to ${outputPath}...`);
|
||||
if (extraArgs.length > 0) {
|
||||
console.log(`With extra arguments: ${extraArgs.join(' ')}`);
|
||||
}
|
||||
|
||||
const result = spawnSync('npx', [
|
||||
'--yes',
|
||||
'@mermaid-js/mermaid-cli',
|
||||
'-i', inputPath,
|
||||
'-o', outputPath,
|
||||
'-b', 'transparent'
|
||||
'-b', 'white',
|
||||
'--scale', '3',
|
||||
...extraArgs
|
||||
], { stdio: 'pipe', encoding: 'utf-8' });
|
||||
|
||||
if (result.status !== 0) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
!.gemini/config.yaml
|
||||
!.gemini/commands/
|
||||
!.gemini/skills/
|
||||
!.gemini/agents/
|
||||
!.gemini/settings.json
|
||||
|
||||
# Note: .gemini-clipboard/ is NOT in gitignore so Gemini can access pasted images
|
||||
|
||||
Reference in New Issue
Block a user