Skip to content

Commit 2ffeff8

Browse files
authored
Publish the Stack diagram agent skill alongside the CLI (#29)
1 parent 4beab2a commit 2ffeff8

3 files changed

Lines changed: 104 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,25 @@ The CLI links `stack-engine` and the protocol-neutral `stack-compiler` language-
9191

9292
The bundled engine resolves 30 provider-neutral core icons: `api`, `web`, `mobile`, `desktop`, `server`, `container`, `cluster`, `cloud`, `scheduler`, `webhook`, `identity`, `observability`, `gateway`, `load-balancer`, `dns`, `cdn`, `firewall`, `network`, `event`, `stream`, `search`, `analytics`, `repository`, `pipeline`, `secret`, `document`, `task`, `chat`, `email`, and `ai`. User-managed provider packs preserve upstream artwork and attach source, archive hash, transformation, terms, and notice metadata. Rendering resolves namespaced IDs such as `aws:s3`, preserves the authored semantic `kind`, embeds the selected local asset, and writes its provenance into SVG metadata and the optional notice sidecar.
9393

94+
## Coding agent skill
95+
96+
Install the optional `stack-diagrams` Agent Skill into your project:
97+
98+
```sh
99+
npx skills add stack-sh/cli
100+
```
101+
102+
The skill guides agents through creating and editing `.stack` diagrams, checking
103+
the installed CLI's capabilities, validating source, and rendering and inspecting
104+
SVG. It does not install the CLI or upload your source. Add `-g` only when you
105+
want a user-wide skill installation. See the [coding agent guide](https://stack-diagram.com/docs/guide/coding-agents)
106+
for usage and the [skill source](./skills/stack-diagrams/SKILL.md) for review.
107+
To pin reviewed instructions, check out a specific commit of this repository and
108+
run `npx skills add /absolute/path/to/cli --skill stack-diagrams`.
109+
110+
The CLI repository owns these instructions; the website owns the usage guides.
111+
Process-level tests execute the skill's command examples against the built CLI.
112+
94113
## Development
95114

96115
The CLI requires Rust 1.85 or newer.

‎skills/stack-diagrams/SKILL.md‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
name: stack-diagrams
3+
description: Create or edit Stack (.stack) software architecture diagrams, validate them with the Stack CLI, and render SVG. Use for Stack diagrams or when a user chooses Stack for architecture documentation; not for infrastructure provisioning or unrelated programming stacks.
4+
license: Apache-2.0
5+
---
6+
7+
# Stack diagrams
8+
9+
Deliver editable `.stack` source and, when rendering is available, an SVG. Preserve the requested architecture and existing unrelated content. Stack describes architecture; it does not provision resources or execute application code.
10+
11+
## Start with the available tools
12+
13+
Run `stack --version` and `stack help` before selecting commands. Use the installed binary's help, not unreleased repository instructions. The published CLI 0.4.0 supports `check`, `fmt`, and `render`; it does not support their `--json` flags. A newer version may support additional options: verify them using `stack help <command>`.
14+
15+
If the CLI is missing, consult the [installation guide](https://stack-diagram.com/docs/guide/getting-started.md) and [release distribution contract](https://github.com/stack-sh/cli/blob/v0.4.0/docs/distribution.md). Install only when the user's authorization allows it. Otherwise provide source with an explicit validation gap; do not report it as checked. No remote source upload is required.
16+
17+
## Read only the relevant reference
18+
19+
Start with [syntax](https://stack-diagram.com/docs/language/syntax.md), [nodes and groups](https://stack-diagram.com/docs/language/nodes-and-groups.md), and [edges and layout](https://stack-diagram.com/docs/language/edges-and-layout.md) when the grammar is unfamiliar. Find complete examples in the [gallery](https://stack-diagram.com/docs/examples/index.md). The [documentation index](https://stack-diagram.com/docs/llms.txt) links the remaining references. If the client cannot fetch one resource, try its Markdown page or report the missing information rather than inventing syntax.
20+
21+
Non-obvious constraints:
22+
23+
- One `stack 1.0` declaration and one named `diagram`; node/group IDs are globally unique.
24+
- Declare edges at diagram scope. Endpoints are node IDs, not labels or groups.
25+
- Model technologies using labels and `detail`; choose semantic `kind` values from the reference. Do not invent properties such as coordinates, colors, or ports.
26+
- Prefer automatic layout or `direction` initially. `order` controls relative cross-axis ordering, not execution sequence; add `rank` or `order` only when the user needs that constraint. References must be direct children of that layout scope.
27+
- Do not guess vendor icon IDs. Consult [provider icons](https://stack-diagram.com/docs/guide/provider-icons.md), query `stack icons list`, and verify the required pack is installed. Import downloads and terms acceptance need appropriate user authorization. If no pack is available, use the semantic kind fallback and explain that branded artwork is absent.
28+
29+
## Generate, validate, and render
30+
31+
For a new diagram, start with the smallest complete source that preserves the requested components and relationships. For an edit, inspect the existing source first and retain unrelated nodes, edges, labels, and comments.
32+
33+
Using the user's actual filenames:
34+
35+
```sh
36+
stack check architecture.stack
37+
stack fmt architecture.stack
38+
stack check architecture.stack
39+
stack render architecture.stack -o architecture.svg
40+
```
41+
42+
`fmt` changes the source in place; avoid unrelated formatting when it would obscure a narrowly requested edit. Rendering to a file may replace it, so honor existing artifact ownership.
43+
44+
Read both the exit status and diagnostics. An exit code of zero can still carry warnings. Fix unknown references or invalid syntax from the diagnostic ranges; never remove requested architecture merely to make validation pass. Investigate layout warnings without treating an optional visual hint as a required semantic relationship. Missing-icon warnings mean the image rendered with a fallback, not that provider artwork was found. Bound repeated repair attempts and report a remaining blocker rather than silently weakening the task.
45+
46+
After rendering, inspect the SVG visually when a suitable viewer is available. Compiler success does not prove readable layout. Confirm the requested nodes, boundaries, relationships, and labels remain present. Report the source/SVG paths, CLI version, validation result, and any unresolved warnings or unverified visual behavior.

‎tests/cli.rs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,45 @@ use serde_json::{Value, json};
1212

1313
static CASE_ID: AtomicU64 = AtomicU64::new(0);
1414

15+
#[test]
16+
fn agent_skill_commands_validate_and_render_source() -> Result<(), Box<dyn Error>> {
17+
let directory = TestDirectory::new("agent-skill")?;
18+
directory.file(
19+
"architecture.stack",
20+
include_bytes!("fixtures/render.stack"),
21+
)?;
22+
let skill = include_str!("../skills/stack-diagrams/SKILL.md");
23+
let mut in_shell = false;
24+
let mut command_count = 0;
25+
for line in skill.lines() {
26+
if line == "```sh" {
27+
in_shell = true;
28+
} else if line == "```" {
29+
in_shell = false;
30+
} else if in_shell && !line.trim().is_empty() {
31+
let mut words = line.split_whitespace();
32+
assert_eq!(words.next(), Some("stack"));
33+
let output = stack_in(&directory.path, words)?;
34+
assert!(
35+
output.status.success(),
36+
"{line}: {}",
37+
String::from_utf8_lossy(&output.stderr)
38+
);
39+
command_count += 1;
40+
}
41+
}
42+
assert!(
43+
command_count >= 4,
44+
"The skill must exercise its validation loop"
45+
);
46+
let svg = fs::read_to_string(directory.path.join("architecture.svg"))?;
47+
let document = roxmltree::Document::parse(&svg)?;
48+
assert_eq!(document.root_element().tag_name().name(), "svg");
49+
let output = stack_in(&directory.path, ["fmt", "--check", "architecture.stack"])?;
50+
assert!(output.status.success());
51+
Ok(())
52+
}
53+
1554
struct TestDirectory {
1655
path: PathBuf,
1756
}

0 commit comments

Comments
 (0)