Skip to content
Merged
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
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ jobs:
sysml:
runs-on: ubuntu-24.04
steps:
# track the fork main; key the cache on the commit it is at now, so a new commit rebuilds
- run: rev=$(git ls-remote "$SYSML_GIT" refs/heads/main | cut -f1) && test -n "$rev" && echo "SYSML_REV=$rev" >> "$GITHUB_ENV"
- uses: actions/checkout@v4
# build the tag the template pins, so CI tests what `make tools` installs
- run: tag=$(sed -n 's/^SYSML_TAG *= *//p' plugins/sysml-rflp/templates/project/Makefile) && test -n "$tag" && echo "SYSML_TAG=$tag" >> "$GITHUB_ENV"
- id: cache
uses: actions/cache@v4
with:
path: ~/.cargo/bin/sysml
key: sysml-${{ env.SYSML_REV }}-${{ runner.os }}
key: sysml-${{ env.SYSML_TAG }}-${{ runner.os }}
- if: steps.cache.outputs.cache-hit != 'true'
run: cargo install --locked --git "$SYSML_GIT" --rev "$SYSML_REV" sysmlv2-cli
run: cargo install --locked --git "$SYSML_GIT" --tag "$SYSML_TAG" sysmlv2-cli
- uses: actions/upload-artifact@v4
with: { name: sysml, path: ~/.cargo/bin/sysml }

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ The <code>.sysml</code> files are the model; sphinx-needs is where traceability

SysML v2 was adopted in 2025, so a language model asked to write it produces something that looks right and names things that do not exist. And a model on its own does not tell you whether every customer requirement ends up satisfied by a component and verified by a test. sysml2-kit closes both gaps. Agents write the model with a checker in the loop, a hook lints every `.sysml` file they edit, and the model is exported into sphinx-needs, where the RFLP rules (Requirements → Functional → Logical) fail the docs build when a link is missing.

The method is fixed and documented: customer requirements (CRS) → use cases and system requirements (UC/SR) → functions (F) → logical components (LC) → system and acceptance tests (STC/ATC) → test results. Each layer has its own agent, and the workflow stops for your approval between layers.
The method is fixed and documented: customer requirements (CRS) → use cases and system requirements (UC/SR) → functions (F) → logical components (LC) → system and acceptance tests (STC/ATC) → test results. Each layer has its own agent, and the workflow stops for your approval between layers. Terms and abbreviations are in the [glossary](glossary.md).

It is not a modeling GUI and it does not simulate. The physical layer (software, hardware, code) stays out of the SysML model; it lives in sphinx-needs next to the code. The toolchain is Python and Rust only, with no Java or Eclipse.

## What you get

- **Plugin `sysml-rflp`** ([`plugins/sysml-rflp/`](plugins/sysml-rflp)): skills to scaffold (`sysml-init`), author (`sysml-author`), lint (`sysml-lint`) and document (`sysml-docs`) a model, and to run the RFLP workflow (`rflp`, `rflp-method`). There is an agent per layer plus a reviewer, a hook that runs `sysml check` after every edit, the `sysml` MCP server, and a project template.
- **Plugin `sysml-rflp`** ([`plugins/sysml-rflp/`](plugins/sysml-rflp)): skills to scaffold (`sysml-init`), author (`sysml-author`), lint (`sysml-lint`) and document (`sysml-docs`) a model, and to run the RFLP workflow (`rflp`, `rflp-method`). There is an agent per layer plus a reviewer, a hook that runs `sysml check` after every edit, a session-start check for missing tools, the `sysml` MCP server, and a project template.
- **Python package `sysml2kit`** ([`src/`](src/sysml2kit)): turns `sysml export` JSON into sphinx-needs needs, and renders use case diagrams and the RFLP trace graph as SVG. Standard library only.
- **Example [`examples/vehicle/`](examples/vehicle)**: a complete chain from CRS to test results, and the acceptance fixture for the toolkit.

Expand All @@ -46,14 +46,14 @@ relations { "element": "SR-001" }

## Quick start

You need Rust (cargo) and Python 3.10+. In Claude Code:
You need Rust (cargo), Python 3.10+ and make. In Claude Code:

```text
/plugin marketplace add MichaelD-42/sysml2-kit
/plugin install sysml-rflp@sysml2-kit
```

Then ask Claude to set up a SysML project. `sysml-init` scaffolds the pipeline, and `make tools` installs the `sysml` CLI (built with cargo from the fork's `main`) and the Python requirements (Sphinx, sphinx-needs, ub-test-reports, sysml2kit). Add customer requirements and ask for the RFLP workflow; `make all` builds the docs and checks the rules.
Then ask Claude to set up a SysML project. `sysml-init` scaffolds the pipeline, and `make tools` installs the `sysml` CLI (built with cargo from the fork at the tag the Makefile pins) and the Python requirements (Sphinx, sphinx-needs, ub-test-reports, sysml2kit). Add customer requirements and ask for the RFLP workflow; `make all` builds the docs and checks the rules.

## Pipeline

Expand All @@ -71,13 +71,13 @@ Need types, link types, fields and the RFLP rules live in `docs/ubproject.toml`

### What `sysml export` gives the bridge

A flat JSON array of elements with `@type`, `@id` and every metamodel property; references are `{"@id": ...}`. `sysml2kit needs` reads `declaredShortName` (not `shortName`, which implicit features inherit), `name`, `qualifiedName`, `owner`, `documentation`; `SatisfyRequirementUsage.satisfyingFeature/satisfiedRequirement`; `Verification*.verifiedRequirement`; `AllocationUsage.relatedFeature` (`[source, target]`); `PerformActionUsage` → `ReferenceSubsetting.referencedFeature`; `MetadataUsage` typed by `Trace::Realizes/Satisfies/Verifies` and the string literals under it. The export has no source positions; the bridge finds `<'ID'>` in the model text.
A flat JSON array of elements with `@type`, `@id` and every metamodel property; references are `{"@id": ...}`. `sysml2kit needs` reads `declaredShortName` (not `shortName`, which implicit features inherit), `name`, `qualifiedName`, `owner`, `documentation`; `SatisfyRequirementUsage.satisfyingFeature/satisfiedRequirement`; `Verification*.verifiedRequirement`; `AllocationUsage.relatedFeature` (`[source, target]`); `PerformActionUsage` → `ReferenceSubsetting.referencedFeature`; `MetadataUsage` typed by `Trace::Realizes/Satisfies/Verifies` and the string literals under it. The export has no source positions; the bridge finds `<'ID'>` in the model text, skipping comments and string literals.

## Tools and versions

| Tool | Version | Role |
|---|---|---|
| `sysml` (sysmlv2-cli) | fork [MichaelD-42/sysml-v2-rs](https://github.com/MichaelD-42/sysml-v2-rs) `main` (0.1.4 + fixes, `find`/`relations` MCP tools) | parse, resolve, validate, export, internal diagrams, MCP server |
| `sysml` (sysmlv2-cli) | fork [MichaelD-42/sysml-v2-rs](https://github.com/MichaelD-42/sysml-v2-rs) tag `v0.1.4-kit.1` (0.1.4 + fixes, `find`/`relations` MCP tools) | parse, resolve, validate, export, internal diagrams, MCP server |
| sphinx-needs | 9.2.0 | needs, links, schema rules |
| ub-test-reports | 2.0.0 | JUnit → needs |
| sysml2kit | this repo | export → needs, use case and trace diagrams |
Expand All @@ -101,7 +101,7 @@ There is no OMG Pilot Implementation gate (Java/Eclipse is out); the corpus run
- Its built-in standard library is 2026-05, not the 2026-09.1 release.
- No derive/refine mapping: SysML v2 has no `refine` keyword.
- ubCode support for `network_back` schema rules is untested here.
- `make tools` and CI follow the fork's `main`, so a push there changes what every build installs.
- `make tools` and CI build the fork tag in `SYSML_TAG`. To take a newer fork commit, tag it, change `SYSML_TAG` in both Makefiles and release; CI reads the tag from the template Makefile.

## Development

Expand Down
5 changes: 3 additions & 2 deletions examples/vehicle/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ TEST_REPORTS ?= test-reports
SPHINXBUILD ?= sphinx-build
# `make docs STRICT=` reports RFLP rule violations without failing (layer-by-layer work)
STRICT ?= -W --keep-going
# sysmlv2-cli fork (sequence-expression fix, find/relations MCP tools); `make tools` installs its main
# sysmlv2-cli fork (sequence-expression fix, find/relations MCP tools), pinned to a tag so every install gets the same checker
SYSML_GIT = https://github.com/MichaelD-42/sysml-v2-rs
SYSML_TAG = v0.1.4-kit.1

MODEL := $(shell find model -name '*.sysml' | sort)
# make splits file names on spaces, so `my part.sysml` would become two missing files
Expand All @@ -24,7 +25,7 @@ DIAGRAMS := VehicleLogical::vehicle VehicleFunctions::operateVehicle
all: lint docs

tools:
cargo install --locked --git $(SYSML_GIT) --branch main sysmlv2-cli
cargo install --locked --git $(SYSML_GIT) --tag $(SYSML_TAG) sysmlv2-cli
pip install -r requirements.txt

lint:
Expand Down
89 changes: 89 additions & 0 deletions glossary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Glossary

Terms used in this repository, the plugin and the generated docs. Which layer owns which artifact, and the rules between them, are in [`structure.md`](plugins/sysml-rflp/skills/rflp-method/references/structure.md).

## Method

**RFLP**: Requirements → Functional → Logical → Physical. The layers a system is described in, from what the customer wants down to what gets built. This kit models R, F and L in SysML; P lives in sphinx-needs next to the code.

**V model**: the left side of the V goes down through the RFLP layers; the right side goes up through tests that verify each layer. Here: system tests verify system requirements, acceptance tests verify customer requirements and use cases.

**Layer gate**: the point in the `rflp` workflow where one layer is finished, its rules pass, and the user approves before the next layer starts.

**Traceability**: being able to follow every customer requirement through use cases, system requirements, functions and components to the tests and results that verify it, and back.

**Leaf**: a function or component with no child of the same type. Allocation rules apply to leaves only. A component that owns only ports is still a leaf.

## Artifacts and ids

**CRS** (customer requirement, `CRS-nnn`): the customer's own words, written in RST. Not part of the SysML model.

**UC** (use case, `UC-nnn`): what an actor does with the system, as a SysML `use case` with a subject and actors.

**SR** (system requirement, `SR-nnn`): one verifiable, solution-free `shall`, as a SysML `requirement`.

**F** (function, `F-nnn`): what the system does, as a tree of SysML `action` usages.

**LC** (logical component, `LC-nnn`): a technology-neutral part of the system, as a tree of SysML `part` usages.

**LI** (logical interface, `LI-nnn`): a SysML `port` on a component.

**STC** (system test case, `STC-nnn`): a SysML `verification` that verifies system requirements.

**ATC** (acceptance test case, `ATC-nnn`): an RST test that verifies customer requirements or use cases.

**Test result** (`testresult_…`): a need generated from JUnit XML by ub-test-reports, linked to its STC or ATC.

**SWR** (software requirement, `SWR-nnn`): physical layer, written in RST. No rules yet.

## Links

**satisfies**: a requirement or component fulfils a requirement one layer up (SR → CRS, LC → SR).

**realizes**: a use case or function implements the layer above (UC → CRS, F → UC).

**verifies**: a test case checks a requirement (STC → SR, ATC → CRS or UC).

**allocated_to**: a function is carried out by a component (F → LC).

**owned_by**: the nearest owning element that is also a need; generated by the bridge.

**tests**: a test result belongs to a test case.

## SysML v2

**Definition / usage**: a definition (`part def Engine`) is a type; a usage (`part engine : Engine`) is an occurrence of it in a structure. Traced elements are modelled as usages.

**Short name**: the id in angle brackets, `requirement <'SR-001'> range;`. Every element with a declared short name becomes a need with that id. `declaredShortName` is the one written in the model; `shortName` is also set on implicit features that inherit it, so the bridge ignores it.

**Qualified name**: the full path of an element, `VehicleRequirements::range`.

**`satisfy`, `verify`, `allocate`, `perform`**: native SysML relations the bridge turns into `satisfies`, `verifies`, `allocated_to` and `realizes` links.

**Subject / actor**: the system a use case is about, and who takes part in it. One use case diagram is drawn per subject.

**Trace metadata**: `@Realizes`, `@Satisfies`, `@Verifies` from `model/trace.sysml`. Links from a model element to a need written outside the model, such as a CRS: `@Realizes { need = "CRS-001"; }`.

**Interchange JSON**: the output of `sysml export`, a flat array of elements with `@id`, `@type` and every metamodel property.

**OMG corpus**: the SysML-v2-Release repository from OMG, the standard's own example models. Used here as the conformance test for the toolchain.

## Tools

**`sysml`**: the sysmlv2-cli command line tool, built from the fork at the tag `SYSML_TAG` in the Makefile. Checks, exports and draws the model and runs the MCP server.

**MCP server**: `sysml mcp`, which lets Claude query the model and the SysML standard library (`check`, `find`, `relations`, `outline`, and others) instead of guessing.

**Bridge**: `sysml2kit needs`, which turns interchange JSON into sphinx-needs needs.

**sphinx-needs**: the Sphinx extension that holds needs, their links and the rules. The docs build is the traceability check.

**Need**: one tracked item in sphinx-needs, with an id, a type, fields and links.

**needimport**: the sphinx-needs directive that loads a generated needs JSON file into the docs.

**Schema rules**: the RFLP rules in `docs/schemas.json`, such as `sysreq-verified`. `sphinx-build -W` fails when one is broken.

**ubproject.toml**: need types, link types and fields, read by both Sphinx and ubCode.

**ubCode**: the editor extension for sphinx-needs projects that reads the same configuration and rules.
2 changes: 1 addition & 1 deletion plugins/sysml-rflp/scripts/check_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

project = Path(os.environ.get("CLAUDE_PROJECT_DIR", "."))
nested = [trace.parent.parent for trace in project.glob("*/model/trace.sysml")]
if not (project / "model").is_dir():
if not (project / "model/trace.sysml").is_file():
if not nested:
sys.exit(0)
# the plugin starts `sysml mcp --project model`, relative to where Claude was started
Expand Down
4 changes: 2 additions & 2 deletions plugins/sysml-rflp/skills/sysml-init/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: Scaffold a SysML v2 + sphinx-needs RFLP project (Makefile, model/tr
2. Copy the template: `cp -rn "${CLAUDE_PLUGIN_ROOT}/templates/project/." <target>/`.
3. Set `project` in `docs/conf.py` to the system name. Create the layer files from `rflp-method` → `references/structure.md` (model layout) with system-prefixed package names, e.g. `package CoolerUseCases { private import Trace::*; }`.
4. Add `docs/customer/requirements.rst` with the customer requirements (`.. crs::` with `:id: CRS-001`), and add it to the toctree in `docs/index.rst`.
5. Tools: `make tools` installs the `sysml` CLI (cargo, from the main branch of the fork in the Makefile) and the Python requirements. Needs Rust and Python 3.10+.
5. Tools: `make tools` installs the `sysml` CLI (cargo, from the fork tag `SYSML_TAG` in the Makefile) and the Python requirements. Needs Rust and Python 3.10+.
6. Run `make all`. With customer requirements and no model yet, the RFLP rules fail on `crs-satisfied` and `crs-verified`; that is expected and is the starting point for the `rflp` skill.

CI: any runner with Rust and Python runs `make tools && make all`; cache `~/.cargo/bin/sysml` keyed on the commit `git ls-remote <fork> refs/heads/main` reports, so a new commit on the fork rebuilds it.
CI: any runner with Rust and Python runs `make tools && make all`; cache `~/.cargo/bin/sysml` keyed on `SYSML_TAG`, so changing the tag rebuilds it.
5 changes: 3 additions & 2 deletions plugins/sysml-rflp/templates/project/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ TEST_REPORTS ?= test-reports
SPHINXBUILD ?= sphinx-build
# `make docs STRICT=` reports RFLP rule violations without failing (layer-by-layer work)
STRICT ?= -W --keep-going
# sysmlv2-cli fork (sequence-expression fix, find/relations MCP tools); `make tools` installs its main
# sysmlv2-cli fork (sequence-expression fix, find/relations MCP tools), pinned to a tag so every install gets the same checker
SYSML_GIT = https://github.com/MichaelD-42/sysml-v2-rs
SYSML_TAG = v0.1.4-kit.1

MODEL := $(shell find model -name '*.sysml' | sort)
# make splits file names on spaces, so `my part.sysml` would become two missing files
Expand All @@ -24,7 +25,7 @@ DIAGRAMS :=
all: lint docs

tools:
cargo install --locked --git $(SYSML_GIT) --branch main sysmlv2-cli
cargo install --locked --git $(SYSML_GIT) --tag $(SYSML_TAG) sysmlv2-cli
pip install -r requirements.txt

lint:
Expand Down
11 changes: 8 additions & 3 deletions src/sysml2kit/needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"Trace::Realizes": "realizes",
"Trace::Verifies": "verifies",
}
# multi-line note `//* */` first, or `//` would take only its first line
COMMENT = re.compile(r"//\*.*?\*/|/\*.*?\*/|//[^\n]*", re.DOTALL)
# strings first, so `"http://x"` is not a comment; multi-line note `//* */` before `//`, or `//` would take only its first line
COMMENT = re.compile(r'"(?:\\.|[^"\\])*"|//\*.*?\*/|/\*.*?\*/|//[^\n]*', re.DOTALL)
# reStructuredText inline markup; doc text is plain text, so these are escaped
RST_INLINE = re.compile(r"([\\*`_|])")

Expand All @@ -60,7 +60,12 @@ def source_locations(model_files):
for path in model_files:
# blank out comments (keeping newlines, so line numbers hold): a short name mentioned in a comment is not its declaration
text = COMMENT.sub(
lambda m: re.sub(r"[^\n]", " ", m.group()), Path(path).read_text()
lambda m: (
m.group()
if m.group().startswith('"')
else re.sub(r"[^\n]", " ", m.group())
),
Path(path).read_text(),
)
for lineno, line in enumerate(text.splitlines(), 1):
for quoted, plain in re.findall(r"<'([^']+)'>|<([A-Za-z_][\w-]*)>", line):
Expand Down
17 changes: 7 additions & 10 deletions src/sysml2kit/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from xml.sax.saxutils import escape

from .needs import refs

FONT = 'font-family="Arial, Helvetica, sans-serif" font-size="12"'
CHAR_W = 7 # approximate width of one 12px Arial character
STYLE = """<style>
Expand Down Expand Up @@ -41,20 +43,17 @@ def use_cases(elements):
by_id = {e["@id"]: e for e in elements}

def member(membership):
target = membership.get("ownedMemberElement") or membership.get(
"ownedRelatedElement"
targets = refs(membership, "ownedMemberElement") or refs(
membership, "ownedRelatedElement"
)
target = target[0] if isinstance(target, list) and target else target
return by_id.get(target["@id"], {}) if target else {}
return by_id.get(targets[0], {}) if targets else {}

def member_name(membership):
return member(membership).get("name")

def subject_key(membership):
subject = member(membership)
types = subject.get("type") or []
types = types if isinstance(types, list) else [types]
typed = [by_id[t["@id"]] for t in types if t["@id"] in by_id]
typed = [by_id[t] for t in refs(subject, "type") if t in by_id]
return subject.get("name"), (
typed[0].get("qualifiedName") or typed[0].get("name") if typed else None
)
Expand All @@ -63,9 +62,7 @@ def subject_key(membership):
for e in elements:
if e["@type"] not in ("UseCaseUsage", "UseCaseDefinition"):
continue
memberships = [
by_id[m["@id"]] for m in e.get("ownedMembership", []) if m["@id"] in by_id
]
memberships = [by_id[m] for m in refs(e, "ownedMembership") if m in by_id]
name, type_ = next(
(subject_key(m) for m in memberships if m["@type"] == "SubjectMembership"),
(None, None),
Expand Down
Loading
Loading