From 9f82479ec964b63d7b197dbe49f2fb4c3fa12cde Mon Sep 17 00:00:00 2001 From: Michael Dold Date: Sat, 7 Nov 2026 18:18:41 +0100 Subject: [PATCH] Pin the sysml fork to a tag and fix audit findings - Build sysml from the fork tag SYSML_TAG (v0.1.4-kit.1) in both Makefiles; CI reads the tag from the template Makefile. - SessionStart check only treats a project as RFLP when model/trace.sysml exists, not any model/ directory. - Source lookup skips string literals, so "http://x" or "/*" no longer hides the declarations after it. - render.py reuses needs.refs and tolerates null membership lists. - README review; add glossary.md. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 9 +- README.md | 14 +-- examples/vehicle/Makefile | 5 +- glossary.md | 89 +++++++++++++++++++ plugins/sysml-rflp/scripts/check_tools.py | 2 +- plugins/sysml-rflp/skills/sysml-init/SKILL.md | 4 +- plugins/sysml-rflp/templates/project/Makefile | 5 +- src/sysml2kit/needs.py | 11 ++- src/sysml2kit/render.py | 17 ++-- tests/test_check_tools.py | 7 ++ tests/test_needs.py | 9 ++ tests/test_render.py | 6 ++ 12 files changed, 147 insertions(+), 31 deletions(-) create mode 100644 glossary.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f36642f..e3aeccb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 } diff --git a/README.md b/README.md index 25013f0..84e5e9e 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ The .sysml 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. @@ -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 @@ -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 | @@ -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 diff --git a/examples/vehicle/Makefile b/examples/vehicle/Makefile index 3971c53..c5798e2 100644 --- a/examples/vehicle/Makefile +++ b/examples/vehicle/Makefile @@ -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 @@ -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: diff --git a/glossary.md b/glossary.md new file mode 100644 index 0000000..8019d2a --- /dev/null +++ b/glossary.md @@ -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. diff --git a/plugins/sysml-rflp/scripts/check_tools.py b/plugins/sysml-rflp/scripts/check_tools.py index 9d86867..681c548 100644 --- a/plugins/sysml-rflp/scripts/check_tools.py +++ b/plugins/sysml-rflp/scripts/check_tools.py @@ -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 diff --git a/plugins/sysml-rflp/skills/sysml-init/SKILL.md b/plugins/sysml-rflp/skills/sysml-init/SKILL.md index a11e6aa..3138ff9 100644 --- a/plugins/sysml-rflp/skills/sysml-init/SKILL.md +++ b/plugins/sysml-rflp/skills/sysml-init/SKILL.md @@ -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/." /`. 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 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. diff --git a/plugins/sysml-rflp/templates/project/Makefile b/plugins/sysml-rflp/templates/project/Makefile index fbeb01c..8b9afe1 100644 --- a/plugins/sysml-rflp/templates/project/Makefile +++ b/plugins/sysml-rflp/templates/project/Makefile @@ -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 @@ -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: diff --git a/src/sysml2kit/needs.py b/src/sysml2kit/needs.py index a30c987..e7c999f 100644 --- a/src/sysml2kit/needs.py +++ b/src/sysml2kit/needs.py @@ -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"([\\*`_|])") @@ -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): diff --git a/src/sysml2kit/render.py b/src/sysml2kit/render.py index 45bbe04..8c8ebb1 100644 --- a/src/sysml2kit/render.py +++ b/src/sysml2kit/render.py @@ -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 = """