diff --git a/BRIEF.md b/BRIEF.md index b614568..a9e0a90 100644 --- a/BRIEF.md +++ b/BRIEF.md @@ -8,6 +8,21 @@ what it taught. Issue numbers (#43, #45) refer to this repository's history. ## Morphogen in one page +**What it is now: the kit, with the judge at its core.** Morphogen maps a system, researches and catalogues the +options for each role, and optimises behind its judge, on files only, on any harness. The map, the options and +(in phase 2) the cells are all Backstage catalog entities, with Morphogen's own fields under one namespaced key, +`spec.morphogen`; documentation is fetched into markdown files. The judge stays the core and stays independent: +the skills that write the map and the catalog write what the judge reads from the base commit, and no candidate +may touch it. Everything below about the judge, the cell and the optimizers is unchanged. **Coming, phase 2:** the +cell format moves from `morphogen.yaml` onto the entities (draft: `schemas/morphogen-spec.v0.json`); until then +`morphogen.yaml` is what the judge reads. + +**Where it sits.** The Knowledge Kernel is an optional layer above the kit: it ingests the same Backstage files when +someone wants indexing, search or graph traversal, and the kit never requires it. Substrate is the default +distribution that installs Morphogen's plugin, like any user. MetaSoar's System 1 skills convention (MetaSoar pull +request #11: policies, observers and cases in a skill folder, each a Morphogen cell) is a planned consumer of the +judge. The way there is the kit section of [PLAN.md](PLAN.md). + **The core** is what nothing else provides: - a judge the improver cannot edit: the rules come from the base commit, the measurements are @@ -44,7 +59,7 @@ hold (`evaluate(candidate) -> score, diagnostics`, which is a probe), and one ve judge on their best. Grid, random, hill-climb, Optuna, GEPA, or a quorum of models used as a scorer all fit it. -**The family** around it, each judged the same way: the mapper (a skill that drafts the map), the +**The family** around it, each judged the same way: the mapper, cataloguer and researcher (skills that draft the map and the options for each role), the builder (ordinary Claude Code, making red tests green), domain modules (skills, an ontology, resolver settings and log parsers, bundled) around a shared knowledge base joined by the entity resolver, and deployment, whose canary stage is the online half of the gate. diff --git a/CLAUDE.md b/CLAUDE.md index c5daaf0..98413dd 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -11,8 +11,10 @@ docs/restart/LESSONS.md. `backstage.py` (catalog-info.yaml files as a source of cells), `status.py` (where a project stands and the next step), `documents.py` (morphogen.yaml's settings, and the target spec a cell compiles to), `request.py` (one document in, one verdict out), `intake.py` (the judge held by another user: a candidate arrives as a git bundle), `cli.py`, `mcp_server.py`, `ui.py` and `ui.html` (the read-only web UI). -- `.claude-plugin/`, `skills/`, `agents/`: the Claude Code plugin around the MCP server. Skills: - `morphogen` (improve a cell) and `map` (draft morphogen.yaml's cells). +- `.claude-plugin/`, `skills/`, `agents/`: the Claude Code plugin around the MCP server. Skills (the kit): + `morphogen` (improve a cell), `map` (take a system apart into Backstage entity files and draft cells), + `catalog` and `research` (options for a role, as `lifecycle: candidate` Components). `schemas/morphogen-spec.v0.json` + is the draft of the `spec.morphogen` fields; phase 2 loads them, morphogen.yaml still works until then. - `tests/`: the core's tests and red team; fixture projects in `tests/fixture*.py`, the timed sample's files in `tests/fixtures`. - `demos/`: projects Morphogen can build and drive. The core never imports from them. diff --git a/PLAN.md b/PLAN.md index e297e31..ef092cc 100644 --- a/PLAN.md +++ b/PLAN.md @@ -1,5 +1,38 @@ # Plan: Morphogen small, with everything above it plugged in +> **Since 2026-11-24 Morphogen is the kit** (Substrate's S-209): map a system, research and catalogue the options +> for each role, and optimise behind the judge, on files only, on any harness. The judge below is still the core. +> The kit's phases, K1 to K4, are the next section; phases 0 to 7 after it are the judge's, and stay as written. + +## The kit: the way there + +Everything committed becomes a Backstage catalog entity; Morphogen's own fields go under one key, +`spec.morphogen` ([schemas/morphogen-spec.v0.json](schemas/morphogen-spec.v0.json), a draft). An option for a role +is a `Component` with `spec.lifecycle: candidate`; a cell's rules go on the entity it judges; sub-grain cells are +`Component`s nested with `subcomponentOf`; an interface's tests go on its `API`; settings and shared defaults go on +the `System`. `morphogen.local.yaml` stays as it is. + +- **K1, skills and schema (this pull request, #102).** README, BRIEF and the skills say what Morphogen is now; the + `map` skill is merged with Substrate's and writes entity files; new `catalog` and `research` skills; the draft + schema. No code behaviour changes; `morphogen.yaml` still works. Open check before K2: that Backstage's `API` and + `System` kinds leave `spec` open the way `Component` does. +- **K2, cells into entities.** Load `spec.morphogen` from the catalog files; check a cell's settings against its + option's parameter schema; default deny covers every catalog file the judge reads (a red-team test across files + first); `morphogen.yaml` is removed with **no back-compatibility**, since only our own projects use it (Substrate, + the demos), and they are moved by hand. Decide whether `lifecycle: candidate` entities are skipped as cells. +- **K3, documentation as files.** A documentation MCP server that turns web documentation into markdown files, + chosen with the `research` skill (a local one first: a hosted one sends what is looked up off the machine). Its + output is a folder of markdown beside the catalog, named in each option's `docs.path`. +- **K4, packaging per harness.** The core Python package (schemas, judge, adapters, CLI, MCP server); the skills as + plain Agent Skills any harness that reads `SKILL.md` can load, naming MCP tools by the server's own names; and a + thin package per harness (the Claude Code plugin first, each other written when a user needs it). + +**Where it sits.** The kernel (the Knowledge Kernel) is an optional layer above the kit: when someone wants indexing, +search or graph traversal, the kernel ingests the same Backstage files. The kit never requires it. Substrate is the +default distribution (a configured harness, the kernel's modules and a default stack) and installs Morphogen's plugin +like any user. **A planned consumer of the judge:** MetaSoar's System 1 skills convention (MetaSoar pull request #11: +policies, observers and cases in a skill folder, each a Morphogen cell). + Morphogen keeps the part nothing else provides: a judge the improver cannot edit, the "still works" gate, the system guard and the evidence log. Everything else is a source it reads or a slot it fills: diff --git a/README.md b/README.md index df881cc..d790840 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,31 @@ # Morphogen -**A judge for self-improving systems.** Point any optimizer or coding agent at part of a system (a -prompt, a setting, a function, a skill, a service) and Morphogen decides whether the change is -really better: by rules taken from the last approved version, with measurements taken outside the -code, on cases the optimizer never saw, without breaking a neighbour or making the whole system -worse. Every verdict goes into a log that cannot be quietly edited. - -Morphogen does not propose changes. Optimizers do that, and they plug into it. Tools that describe -a system, such as Backstage, sit above it. [BRIEF.md](BRIEF.md) is the design (its first section is +**A kit for improving a system, with a judge at its core.** Morphogen **maps** a system (what it is made of, the +role each part plays, the interfaces that make parts interchangeable), **researches and catalogues** the options +for each role, and **optimises** behind a judge: point any optimizer or coding agent at part of the system (a +prompt, a setting, a function, a skill, a service) and the judge decides whether the change is really better, by +rules taken from the last approved version, with measurements taken outside the code, on cases the optimizer +never saw, without breaking a neighbour or making the whole system worse. Every verdict goes into a log that +cannot be quietly edited. + +It works on files only, on any harness that reads Agent Skills: the map and the catalog are Backstage catalog +entity files in your repository (no database, no server), the documentation of an option is markdown files, and +the judge is a Python package with an MCP server. The Claude Code plugin is the first packaging; other +harnesses get a thin manifest over the same core and skills. + +**The judge stays the core, and stays independent.** The mapping and cataloguing skills write the map and the +catalog, which the judge reads from the base commit and no candidate may touch: what an optimizer may edit is +still only what a cell's `change` names. Morphogen does not propose changes itself; optimizers do that, and they +plug into it. [BRIEF.md](BRIEF.md) is the design (its first section is the one-page version) and [PLAN.md](PLAN.md) the way there; this file is the case for Morphogen and how to use what is built. +**Where it sits.** The Knowledge Kernel is an optional layer above the kit: it ingests the same Backstage files for +indexing, search and graph traversal, and the kit never requires it. Substrate is the default distribution (a +configured harness, the kernel and a default stack) and installs Morphogen's plugin like any user. MetaSoar's +System 1 skills convention (policies, observers and cases in a skill folder, each a Morphogen cell) is a planned +consumer of the judge. The way there is [PLAN.md](PLAN.md). + ## Why a judge, on top of optimizers **An optimizer is only as honest as its evaluator.** It maximises whatever score it is given. Give a @@ -78,6 +93,14 @@ hole it closes. ## The cell format +> **Coming, phase 2.** The cell format below is today's. The kit moves every committed artifact into Backstage +> catalog entities: a cell's rules go on the entity it judges under one namespaced key, `spec.morphogen`; an +> option for a role is a `Component` with `spec.lifecycle: candidate`; sub-grain cells are `Component`s nested +> with `subcomponentOf`; an interface's tests go on its `API` entity; the project's settings and shared defaults go +> on the `System` entity. The fields are drafted in [`schemas/morphogen-spec.v0.json`](schemas/morphogen-spec.v0.json) +> and carried over unchanged from what a cell accepts below. `morphogen.local.yaml` stays as it is. Until phase 2 +> lands, `morphogen.yaml` is what the judge reads, and this reference is current. + One `morphogen.yaml` at the project's root: ```yaml @@ -193,8 +216,9 @@ described this way. Install it from GitHub, not from a local clone: a clone added as a marketplace runs the plugin from the clone itself, so the judge would be the candidate you are changing. To move to a newer version, `/plugin marketplace update morphogen`, then `/plugin update morphogen@morphogen`, and restart -Claude Code. The plugin brings the MCP server, the `morphogen` skill (improve a cell honestly), the -`map` skill (draft the cells), and the `worker` and `reviewer` agents. It needs +Claude Code. The plugin brings the MCP server, four skills (`map`: take a system apart into Backstage entity files with +evidence and draft its cells; `catalog`: find options for a role; `research`: choose one from the catalogs; +`morphogen`: improve a cell honestly), and the `worker` and `reviewer` agents. It needs [uv](https://docs.astral.sh/uv/) on the path. **Starting fresh.** In a git repository, ask Claude to start Morphogen here. The map skill calls @@ -279,7 +303,8 @@ directory, so it can only answer. The cell's `description` is its objective. | Observers | `observers.py` | `command` (a command after each run) and `otel` (an OpenTelemetry receiver in the judge that adds up each run's telemetry, such as Claude Code's cost, tokens and tool results) | | Optimizers | `optimize.py` | a catalog behind one contract: grid, random, hill-climb (with `restarts`) and simulated annealing (`anneal`), built in; Optuna and GEPA adapters (optional extras); and the `selector`, whose bandit policy (primed by earlier verdicts, with a stagnation signal) chooses which proposes next. A model-based policy is planned; packages add more through the `morphogen.optimizers` entry point. `tune` checks, writes and probes each proposal and judges the best | | Interfaces | `cli.py`, `mcp_server.py`, `ui.py` | the command line, an MCP server with 11 tools, and a local read-only web UI | -| Plugin | `.claude-plugin/`, `skills/`, `agents/` | the Claude Code plugin around the MCP server | +| Plugin | `.claude-plugin/`, `skills/`, `agents/` | the Claude Code plugin around the MCP server; the skills (`map`, `catalog`, `research`, `morphogen`) are plain Agent Skills any harness can load | +| Schemas | `schemas/` | the evidence record (v1); the `spec.morphogen` fields of the catalog entities (draft, phase 1; not read yet) | ### The system guard @@ -441,6 +466,7 @@ Details are from each project's own docs or source, read on 2026-11-04 and 2026- morphogen/ the core, its CLI, MCP server and web UI tests/ its tests and red team; fixture projects in tests/fixture*.py .claude-plugin/ the plugin and marketplace manifests - skills/, agents/ the Claude Code skills and agents + skills/, agents/ the skills (Agent Skills format) and Claude Code agents + schemas/ published JSON Schemas (evidence record; spec.morphogen, a draft) demos/ projects Morphogen can build and drive (the core never imports from them) BRIEF.md the design; PLAN.md the way there diff --git a/demos/README.md b/demos/README.md index 9993459..489296d 100644 --- a/demos/README.md +++ b/demos/README.md @@ -1,5 +1,7 @@ # Demos +> These projects describe themselves in `morphogen.yaml` and `catalog-info.yaml` today. In phase K2 of the kit ([PLAN.md](../PLAN.md)) their cells move onto Backstage entities under `spec.morphogen` and `morphogen.yaml` is removed, with no back-compatibility; the demos are moved by hand. + Projects a fresh Morphogen instance can start building, and that Morphogen can then drive. Each is a component that stands alone, or a larger system built from them. diff --git a/schemas/morphogen-spec.v0.json b/schemas/morphogen-spec.v0.json new file mode 100644 index 0000000..dc7ba4e --- /dev/null +++ b/schemas/morphogen-spec.v0.json @@ -0,0 +1,281 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/OpenReplicant/Morphogen/schemas/morphogen-spec.v0.json", + "title": "spec.morphogen (DRAFT, v0)", + "description": "DRAFT. Morphogen's own fields on a Backstage catalog entity, under the one key `spec.morphogen`. Phase 1 of the kit publishes this schema; nothing reads these fields yet (phase 2 loads them). The cell fields are those a cell in morphogen.yaml accepts today (morphogen/project.py, CellDoc), so a cell moves unchanged. What Backstage already holds is not repeated: a cell's `in` is the entity's subcomponentOf or system, `provides` and `consumes` are providesApis and consumesApis, `owner` and `lifecycle` are the entity's own. Use the Option fields on a Component with spec.lifecycle: candidate, the Cell fields on the entity a cell judges, the ApiTests fields on an API entity and the SystemSettings fields on the System entity. The fields are flat under `spec.morphogen`: the schema is the four definitions together, so one entity may carry the fields of more than one (a candidate that is also judged, say), and a field none of them defines is refused.", + "type": "object", + "$defs": { + "StringOrList": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "Option": { + "description": "An option for a role: carried by a Component with `spec.lifecycle: candidate`.", + "type": "object", + "properties": { + "fills": { + "$ref": "#/$defs/StringOrList", + "description": "Entity ref(s) of the part or role this could fill, as `[kind:][namespace/]name`." + }, + "parameters": { + "type": "object", + "description": "A JSON Schema of the option's adjustable settings (what a tuner may move, with its bounds)." + }, + "licence": { + "type": "string", + "description": "An SPDX identifier where there is one, else the licence's name." + }, + "docs": { + "type": "object", + "properties": { + "url": { + "type": "string", + "format": "uri" + }, + "path": { + "type": "string", + "description": "Where the fetched markdown docs are, relative to the project root. Absent until fetched." + } + }, + "additionalProperties": false + }, + "evaluation": { + "type": "object", + "description": "How it was measured against the need.", + "properties": { + "need": { + "type": "string" + }, + "method": { + "type": "string", + "description": "The trial: cases, command, where its output is kept." + }, + "result": { + "type": "string" + }, + "evidence": { + "$ref": "#/$defs/StringOrList" + } + }, + "additionalProperties": false + } + } + }, + "Cell": { + "description": "A cell's rules, on the entity it judges. The fields of CellDoc in morphogen/project.py, less those Backstage holds (in, provides, consumes, owner, lifecycle). Commands run in `dir`, relative to the project root.", + "type": "object", + "properties": { + "description": { + "type": "string", + "description": "The cell's objective in words; GEPA's reflection reads it." + }, + "dir": { + "type": "string", + "default": "." + }, + "change": { + "$ref": "#/$defs/StringOrList", + "description": "What may change: a path or glob, or a setting `path#NAME` / `path:dotted.key`, optionally `in lo..hi` or `in [a, b]`. Nothing else may." + }, + "keep": { + "$ref": "#/$defs/StringOrList", + "description": "Settings held fixed inside a file `change` opens." + }, + "run": { + "type": "string", + "description": "The workload." + }, + "better": { + "description": "`metric higher|lower`, comma-separated for constraints after the primary; or {metric: higher|lower|{higher|lower, min, max_regression, gain, aggregate, primary}}.", + "oneOf": [ + { + "type": "string" + }, + { + "type": "object" + } + ] + }, + "tests": { + "$ref": "#/$defs/StringOrList", + "description": "Commands that must pass; a failure refuses." + }, + "score": { + "type": "string", + "description": "Scores each run's output, from the base." + }, + "observe": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "object" + } + ], + "description": "`otel`, or a command or observer object collected outside the run." + }, + "same_as_base": { + "type": "object", + "properties": { + "gen": { + "type": "string" + }, + "run": { + "type": "string" + }, + "cases": { + "type": "integer" + } + }, + "required": [ + "gen", + "run" + ], + "additionalProperties": false + }, + "same_output": { + "type": "boolean" + }, + "guard": { + "description": "false turns the system guard off; {max_regression: 0.1} sets how much the enclosing system may get worse.", + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "object", + "additionalProperties": { + "type": "number" + } + } + ] + }, + "rounds": { + "type": "object", + "properties": { + "warmup": { + "type": "integer" + }, + "repeats": { + "type": "integer" + }, + "max_repeats": { + "type": "integer" + } + }, + "additionalProperties": false + }, + "timeout": { + "type": "integer", + "description": "Seconds." + }, + "simulates": { + "type": "string" + }, + "requires": { + "type": "array", + "items": { + "enum": [ + "network_isolated", + "read_only_tree", + "private_paths_hidden", + "fresh_state", + "resource_limits" + ] + }, + "description": "Guarantees the runner must provide for the cell to be judged at all." + } + } + }, + "ApiTests": { + "description": "On an API entity: the tests of the interface it names, run from the project root (InterfaceDoc in morphogen/project.py).", + "type": "object", + "properties": { + "tests": { + "$ref": "#/$defs/StringOrList" + }, + "external": { + "enum": [ + "consumes", + "provides" + ], + "description": "consumes: the system offers it; provides: the system relies on it." + } + } + }, + "SystemSettings": { + "description": "On the System entity: the judge's settings (Config in morphogen/documents.py, today the top level of morphogen.yaml) and defaults cells inherit, which replace YAML anchors.", + "type": "object", + "properties": { + "trunk": { + "type": "string", + "default": "main" + }, + "sandbox": { + "enum": [ + "auto", + "podman", + "docker", + "none" + ], + "default": "auto" + }, + "sandbox_image": { + "type": "string", + "default": "python:3.12-slim" + }, + "budget": { + "type": "object", + "properties": { + "trials_per_day": { + "type": "integer" + }, + "probes_per_day": { + "type": "integer" + } + }, + "additionalProperties": true + }, + "autonomy": { + "type": "object", + "description": "lifecycle -> what a pass allows (default review).", + "additionalProperties": { + "enum": [ + "merge", + "review" + ] + } + }, + "defaults": { + "$ref": "#/$defs/Cell", + "description": "Fields a cell in this system inherits where it does not set them." + } + } + } + }, + "allOf": [ + { + "$ref": "#/$defs/Option" + }, + { + "$ref": "#/$defs/Cell" + }, + { + "$ref": "#/$defs/ApiTests" + }, + { + "$ref": "#/$defs/SystemSettings" + } + ], + "unevaluatedProperties": false +} diff --git a/skills/catalog/SKILL.md b/skills/catalog/SKILL.md new file mode 100644 index 0000000..663087b --- /dev/null +++ b/skills/catalog/SKILL.md @@ -0,0 +1,90 @@ +--- +name: catalog +description: Find alternatives for a role a part plays - search the catalogs (package registries, vendors, parts lists, directories) for options that provide the interfaces the role requires, write each as a candidate entity file with its source, and set up how the options will be measured against the system's goals. Use when the user asks what else could do a part's job, whether something better exists, or what to replace a part with; after the map skill has named the role. +--- + +# Catalog: what else could fill a role + +Works on a role the `map` skill named, in files: no database, any harness. An option for a role is an ordinary +Backstage `Component` with `spec.lifecycle: candidate`; what Morphogen adds goes under the one key +`spec.morphogen` (draft schema: `schemas/morphogen-spec.v0.json`). An option is *an alternative* when it +provides every interface the role requires, which is why a loosely named interface makes everything look +interchangeable. + +## 1. Read the role + +Read the entity that plays the role and the `API` entities it consumes: those are the interfaces any option must +provide. If the role requires no named interface, that comes first (the `map` skill): without one, everything +and nothing is an alternative. Read the system's goals (its description, the cell's `better`): they say which +options are worth measuring. Write the need down before looking, so options are tested against it and the need is +not bent to fit a favourite. + +## 2. Search more than one catalog + +A catalog here is any place that lists options: a package registry (PyPI, npm, crates.io), a container registry, +GitHub, deps.dev, a vendor's range, a standards body's list, a directory of services or people. Search by need and +topic, not by the name you expect; what you remember is a lead, not evidence. Use whatever the harness reaches: a +web search, a registry's API, `gh api -X GET search/repositories -f q="topic:TOPIC" -f sort=stars`, deps.dev for a +package's versions and licence, `podman search --list-tags REGISTRY/NAME` for images, or an MCP server you are +given. Rule out early on hard limits the operator gave (a licence, a release age, where it runs) and say which, +with the source quoted. + +## 3. Write each option with what its source says + +One entity per option, in the project's catalog folder: + +```yaml +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: option-name + description: One line: what it is. + annotations: + morphogen.dev/evidence: | + stated | https://example.org/docs#interfaces | "quoted text of the source" +spec: + type: library + lifecycle: candidate + owner: group:default/team + providesApis: [the-api-the-role-requires] # only where a source says so + morphogen: + fills: component:default/the-part # the part or role it could fill + parameters: # JSON Schema of its adjustable settings + type: object + properties: + batch_size: {type: integer, minimum: 1, maximum: 512} + licence: MIT + docs: + url: https://example.org/docs + path: docs/option-name/index.md # only once fetched into markdown + evaluation: {} # filled in step 4 +``` + +- `providesApis` only where a source says the option provides it, with that source's words in the evidence. An + option that might provide an interface but no source says so: leave it out and note what would settle it. +- `parameters` is what a tuner may move, with its bounds from the docs; a cell that uses the option has its + settings checked against it. Leave it out when you do not know. +- `licence` and versions come from the registry's answer or the licence file, quoted as evidence, never written + from memory. +- `docs.url` is the documentation; when a documentation server is available (one that fetches web documentation + into markdown files), fetch the pages that matter into a folder beside the catalog and give `docs.path`. + Fetch only what the choice needs, and say which server you used. + +## 4. Measure, then judge + +Keep the options that fit. Measuring is a trial on the same cases for each option and for what fills the role +now, against real data where there is some: a script that prints one line per option and case, its output kept in +a file as the source. Record it on the option under `spec.morphogen.evaluation`: the need, the method (cases, +command, where the output is), the result and the evidence. + +Whether an option is *better* is a judge's verdict, not yours. When the role is a cell the judge can judge +(a `run`, a `better`, tests), use the `morphogen` skill: `measure` the incumbent, put the option on a branch, +`judge` it. Otherwise tell the operator the measurements and say what you would pick and why; the decision is +theirs. + +## 5. Report + +The options that fit, the ones ruled out and why, the measurements, and what you recommend. A change to the +system (a part replaced) is the operator's to approve: once they decide, change the entity for the part and set +the chosen option's `spec.lifecycle` to match, in a pull request. Never change a verdict or another person's +claim yourself. diff --git a/skills/map/SKILL.md b/skills/map/SKILL.md index 81b801d..82b2f56 100644 --- a/skills/map/SKILL.md +++ b/skills/map/SKILL.md @@ -1,16 +1,63 @@ --- name: map -description: Map a system into Morphogen's cell format (cells, interfaces, what may change, intent as tests) so it can be measured and improved, or start a project that has no map. Use when the user asks to map, model or inventory a system, asks what a system is made of, wants to start Morphogen on a project with no morphogen.yaml, or hands over a system for a builder agent to create or change. +description: Map a system - what it is made of, the role each part plays, the interfaces that make parts interchangeable and the cells a judge can measure - as Backstage catalog entity files with evidence, or start a project that has no map. Use when the user asks to map, model or inventory a system (software or not: a codebase, a team, a process), asks what something is made of or what could be swapped, wants to start Morphogen on a project with no map, hands over a system for a builder agent to create or change, or before cataloguing options for a part (the catalog skill). --- -# Mapping a system for Morphogen - -The map says what the system is made of and what it promises. The judge reads it from the base -commit, so a map counts only once the operator has approved it and it is on main. Your job is a -draft the operator can approve: small, checked, every claim traceable to where you found it. +# Mapping a system + +The map says what the system is made of, the role each part plays, what each part promises and what may be +changed and judged. It is **files**: Backstage catalog entities in the project, written by you, read by the +judge from the base commit. No database and no server are needed, and any Backstage UI can load the same files. +A map counts for a verdict only once the operator has approved it and it is on main. Your job is a draft the +operator can approve: small, checked, every claim traceable to where you found it. + +**Coming, phase 2:** the cell rules will move from `morphogen.yaml` into the entity they judge, under +`spec.morphogen` (draft schema: `schemas/morphogen-spec.v0.json`). Until phase 2 lands, the judge reads cells +from `morphogen.yaml` and the catalog files as section 1 says; write the rest of the map as entities now, and +the cell rules where the judge reads them today. + +## 0. How you work + +- **Interview a person** when there is one: what the map is for, what might change, what should get better. + Ask before searching for what only they know; ask last, with what you found in hand, for what the system + cannot tell you. +- **Hypothetical design work** when the thing does not exist yet, or a change to it is only proposed: map the + design as intended. Mark such an entity `spec.lifecycle: experimental` and say in its description that it is + not built; an intended part with no source is the intent, not a finding. +- **Find facts** through whatever the harness reaches: read files and run commands; call any MCP server you are + given (a documentation server, a ticket system, a repository host); search the web. Use the harness's own + tools by the names it gives them. +- **Build out iteratively.** Map the whole coarsely first, then take one part at a time and detail its + sub-structure when the operator's goal needs it (a part nobody would change needs no parts of its own). + Write after each pass, so the map is always valid and reviewable. +- **Evidence for each claim.** See section 3. ## 1. What a map is +The map is a **Backstage catalog**: entity files (`catalog-info.yaml`, or a `catalog/` folder of them, tied +together with `Location` entities), as many files as the project likes. Morphogen already reads them with no +Backstage server. + +| A thing in the map | The entity | +| --- | --- | +| a whole, a product, a process | `System` (nest with `Domain`, or `spec.system`) | +| a part | `Component`, with `spec.type`, `spec.lifecycle`, `spec.owner`, `spec.system` | +| a part inside a part (below Backstage's grain: a file, a prompt, a setting) | a `Component` with `spec.subcomponentOf` | +| an interface | `API`, joined with `providesApis` and `consumesApis`; its tests under `spec.morphogen.tests` | +| something the system relies on and does not own (a database, a model service) | `Resource`, joined with `dependsOn` | +| who owns or approves | `Group` or `User` | +| the role a part plays | a `Component` of `spec.type: role`, or the part's `spec.morphogen.fills` when it is an option; name the role so another part could do it ("the store's embedding model", "drivetrain") | +| an option for a role | a `Component` with `spec.lifecycle: candidate` (the catalog skill) | + +Morphogen's own fields go under **one key**, `spec.morphogen`, so they never clash with fields Backstage adds. +Annotation values must be strings. Fields are described in `schemas/morphogen-spec.v0.json` (a draft). + +A role is interchangeable when its interfaces are named exactly enough to check: an API and its version, a file +format, a protocol, a socket size, a skill set. An interface named loosely ("an API") makes everything look +interchangeable. + +The words, for the judge: + - **Cell:** a part that can be changed and judged on its own: a module, a prompt, a config key, a skill, a service, a model choice. Cells nest (`in`); a cell's **scope** is it and everything inside it. @@ -28,6 +75,25 @@ draft the operator can approve: small, checked, every claim traceable to where y (traces, imports, calls) is the observed structure, in the same format; laying one over the other shows convergence, absence (intended, not there) and divergence (there, not intended). +```yaml +# catalog/classify.yaml: the part, the interface it provides, and who consumes it +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: classify + annotations: + morphogen.dev/evidence: | + stated | targets/classify/classify.py:L1-12 | "THRESHOLD = 50 # cut-off for a label" +spec: {type: library, lifecycle: production, owner: group:default/team, system: app, providesApis: [labels]} +--- +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: {name: labels} +spec: {type: openapi, lifecycle: production, owner: group:default/team, definition: "see contracts/labels.md"} +``` + +Until phase 2, the cell's rules live in `morphogen.yaml`, naming the entity's ref where there is one: + ```yaml # morphogen.yaml, at the project root cells: @@ -65,9 +131,10 @@ Morphogen needs cells, not a complete map. Measure first; map what earns attenti - **Not a git repository, or no commit on `main`:** the judge reads its rules from a commit. Ask the operator before running `git init` or committing on their behalf. -- **A Backstage catalog, no `morphogen.yaml`:** do not translate the catalog. Write +- **A Backstage catalog, no `morphogen.yaml`:** do not rewrite the catalog. Write `morphogen.yaml` with `backstage: [catalog-info.yaml]` and add only what the catalog lacks, for the one part to improve, under its ref (`component:classify` is enough). +- **No catalog:** write the entities for the parts that matter (section 1), nothing more. - **Nothing here yet:** ask the operator what to improve and how they would know it improved. Draft one cell for that: `change` (as narrow as the job allows), `run`, `better` and `tests`. Stop there unless several parts are in play. @@ -82,10 +149,13 @@ exactly as the judge would refuse it. ## 3. Find what is there, cheapest first -Record each finding as you go with `evidence_note`: the claim, the source (file and line, URL, -command and its output, or "operator, interview"), and its trust (`stated` for what a document -or person says, `inferred` for what you concluded). The map then points at evidence instead of -asking to be believed. +Record each finding as you go: the claim, the source (file and line, URL, command and its output, or +"operator, interview"), the quoted text, and its trust (`stated` for what a document or person says, `inferred` +for what you concluded). Write it on the entity as the `morphogen.dev/evidence` annotation (one claim per line, +`trust | source | quote`) and, with Morphogen's MCP server, log it with `evidence_note`, so the map points at +evidence instead of asking to be believed. Copy a quote from the file (print the lines, do not retype them) and +quote one locator the same way each time. What a person tells you is theirs: quote the conversation as the +source and say so. What you cannot cite, leave out or ask about. 1. **Read descriptors the project already has,** Backstage's catalog first. Translate, do not copy wholesale: @@ -97,13 +167,13 @@ asking to be believed. | compose files, Kubernetes manifests, Helm values | containment; env and config keys as settings | | CycloneDX or package manifests | external `provides` interfaces (libraries, models, services) | | package layout, imports, entry points | code cells and who consumes whom | - | prompts, skills, hooks, MCP tools, model choices | text or alternatives cells; Backstage has no grain for these | + | prompts, skills, hooks, MCP tools, model choices | text or alternatives cells: `Component`s nested with `subcomponentOf`, below Backstage's grain | 2. **Read the code and the tests.** Existing tests are intent someone already wrote down; attach each to the interface it actually exercises. 3. **Run it.** Run the test suite and the workload, with a profiler or OpenTelemetry where the project has them. Hot spots by time, cost or errors are candidate cells; calls you see are the - observed structure. Save an observed structure alongside, in the same format, if you build one. + observed structure. Save an observed structure alongside, in the same entity format, if you build one. 4. **Interview the operator,** last and briefly, with what you found in hand. Ask only what the system cannot tell you: what must never change, which settings are theirs (owner `operator`), the acceptable ranges for the rest, what "better" means and what it may not cost, and any @@ -128,6 +198,7 @@ asking to be believed. report the intent coverage (tested interfaces out of all). - `structure_scope(cell)` for each cell you expect to be changed: is the boundary what you meant? - `structure_render` (Mermaid; with an observed structure, the comparison) for the operator. +- Name Morphogen's MCP tools by the server's own names (`status`, `structure_check`, ...), not by a harness prefix. - `morphogen.local.yaml` (held-out paths, the sandbox) goes in `.gitignore`; `status` warns if it is committed or not ignored. - Commit the draft on its own branch and give the operator: the rendered map, the coverage, the @@ -138,7 +209,8 @@ asking to be believed. ## What not to do - Do not map everything. A cell no one will change or guard is noise in every scope. -- Do not invent an ontology per project. The format above is what the judge reads; other +- Do not invent an ontology per project. Backstage's kinds are what the judge reads; other vocabularies are sources to translate from, and renders for people. +- Do not call a database or a kernel's tools: the map is files, whatever the harness. - Do not mark a setting `agent`-owned to make later tuning easier. When unsure, `operator`. - Do not record a guess as `stated`. Only a source states; you infer. diff --git a/skills/research/SKILL.md b/skills/research/SKILL.md new file mode 100644 index 0000000..d62ab5d --- /dev/null +++ b/skills/research/SKILL.md @@ -0,0 +1,50 @@ +--- +name: research +description: Choose a component, library, service, model or vocabulary from the catalogs instead of from memory - name the role on the map, find options with the catalog skill, test the shortlist against the need, and record the pick. Use when the user needs something picked ("which X should we use", "find a library for", "is there something that does"), or before adding any part, package or image to a system. +--- + +# Research: a choice made from catalogs, not memory + +The `catalog` skill applied to one decision, with the operator's rules on top. What you remember about a tool is a +lead, not evidence: every fact that decides the choice comes from a registry's answer, the tool's documentation +or a trial you ran. Everything is files, on any harness. + +## 1. The role and the need, first + +Find the role on the map (the `map` skill if the part you need is not mapped yet). Write the need before looking +at options, so options are tested against it rather than the need bent to fit a favourite: + +- the interfaces the role requires (the `API` entities it consumes), exactly enough to check; +- what is measured, as a goal with a metric and a target (the system's description, or the cell's `better`); +- the operator's rules for this choice, asked once if not given: licences allowed, how old a release must be, + where it must run, what it may cost, whether lookups may leave the machine. Treat them as part of the need. + +Put the need in one place the options will point at: the description of the role's entity, or a short note file +beside the catalog. + +## 2. Options + +The `catalog` skill, steps 2 and 3: at least three where there are that many, from more than one catalog, each +as a `Component` with `spec.lifecycle: candidate`, its source, licence and the interfaces its sources say it +provides. Licence, versions and dates come from the registry's answer (deps.dev, GitHub's API, the licence file +when the API says it cannot tell), quoted as evidence. Rule out on the operator's rules early and say which. + +## 3. Test the shortlist + +Write a trial script in the project (its own folder, e.g. `trials//`) that runs every shortlisted option on +the same cases, against real data where there is some, and prints one result line per option and case; keep the +output in a file. Pin every image, jar and package it uses, and fetch with checksums. Test each need, not what is +easy to measure. Record each result on the option's `spec.morphogen.evaluation` with the output file as evidence. + +When two or more meet the need and the question is which is better, that is a judge's question: use the +`morphogen` skill where the role is a cell it can judge; otherwise the measurements and your recommendation go to +the operator. + +## 4. Record the pick + +In a pull request, for the operator to approve: + +- the chosen option's `spec.lifecycle` moves from `candidate` to the project's own (and the part's entity points + at it); rejected options keep their entities as `candidate`, with a note on what would make one the pick; +- where the project keeps a decision log (a file of decisions, ADRs), a new entry: what was chosen and pinned, + where its docs were read, the options and why the others lost. diff --git a/tests/test_schema.py b/tests/test_schema.py index a9b730d..3f526c1 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -33,3 +33,14 @@ def test_verdicts_the_judge_writes_validate(self): if __name__ == "__main__": unittest.main() + + +class SpecSchema(unittest.TestCase): + """schemas/morphogen-spec.v0.json (a draft) carries the fields a cell accepts today, so phase 2 can load them.""" + + def test_the_cell_fields_are_those_morphogen_yaml_accepts(self): + from morphogen.project import CellDoc + spec = json.loads((HERE / "schemas/morphogen-spec.v0.json").read_text()) + held_by_backstage = {"in", "provides", "consumes", "owner", "lifecycle"} + accepted = {(f.alias or n) for n, f in CellDoc.model_fields.items()} - held_by_backstage + self.assertEqual(set(spec["$defs"]["Cell"]["properties"]), accepted)