{"id":51307660,"url":"https://github.com/block/madrigal","last_synced_at":"2026-07-01T01:03:08.609Z","repository":{"id":347416720,"uuid":"1183601647","full_name":"block/madrigal","owner":"block","description":"design x ai orchestration","archived":false,"fork":false,"pushed_at":"2026-06-05T15:21:48.000Z","size":387,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-13T06:30:19.823Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/block.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":"GOVERNANCE.md","roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-16T19:17:10.000Z","updated_at":"2026-06-05T15:21:53.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/block/madrigal","commit_stats":null,"previous_names":["block/madrigal"],"tags_count":0,"template":false,"template_full_name":"block/oss-project-template","purl":"pkg:github/block/madrigal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block%2Fmadrigal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block%2Fmadrigal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block%2Fmadrigal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block%2Fmadrigal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/block","download_url":"https://codeload.github.com/block/madrigal/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block%2Fmadrigal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34917594,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-29T02:00:05.398Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-07-01T01:03:07.876Z","updated_at":"2026-07-01T01:03:08.591Z","avatar_url":"https://github.com/block.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Madrigal\n\nA config-driven, pluggable knowledge compiler. Madrigal transforms structured knowledge (markdown files with frontmatter) into normalized, schema-aware output formats - JSON bundles, AI skill files, rule sets, and more.\n\nInspired by [Style Dictionary](https://amzn.github.io/style-dictionary/), Madrigal applies the same \"define once, compile everywhere\" philosophy to knowledge bases, research repositories, coding guidelines, design systems, and organizational rules. Consumers own the domain vocabulary; Madrigal owns reliable parsing, normalization, linting, and compilation.\n\n## Quick Start\n\n```bash\nnpm install @anarchitecture/madrigal\n```\n\nCreate a `madrigal.config.yaml`:\n\n```yaml\nsources:\n  - \"knowledge/**/*.md\"\n\nschema:\n  preserveUnknownFrontmatter: true\n  id:\n    field: id\n    strategy: path\n  kind:\n    field: type\n    default: record\n    byPath:\n      \"knowledge/studies/**\": study\n  title:\n    field: title\n  relationships:\n    wikilinks: true\n\nkinds:\n  study:\n    required: [title, methodology, research_period, source_url]\n  theme: {}\n\nvocabularies:\n  durability:\n    values: [evergreen, timebound]\n\nplatforms:\n  json-export:\n    format: json-bundle\n```\n\nCreate a knowledge file at `knowledge/studies/checkout-trust.md`:\n\n```markdown\n---\ntitle: Checkout Trust Study\ntype: study\nmethodology: Interviews\nresearch_period: Q1\nsource_url: https://example.com/research\ndurability: evergreen\ntags:\n  - onboarding\n---\n\nParticipants connected onboarding clarity to [[Trust Signals]].\n```\n\nBuild programmatically:\n\n```typescript\nimport { build } from '@anarchitecture/madrigal';\n\nconst result = await build();\n\nfor (const output of result.results) {\n  console.log(`${output.platform}: ${output.unitCount} units`);\n  console.log(output.output);\n}\n```\n\n## Concepts\n\n### Knowledge Units\n\nThe atomic unit. Each `.md` file with frontmatter becomes a normalized `KnowledgeUnit` with an id, title, body, kind, tags, source path, raw `frontmatter`, normalized `attributes`, extracted `relationships`, and provenance tracking. Optional rule-oriented fields such as `domain`, `brand`, `system`, and `enforcement` are preserved when present.\n\n### Schema\n\nConsumer-owned mapping rules that tell Madrigal how to read a knowledge base: where IDs, titles, kinds, and relationships come from, how path-based fallback should work, and whether unknown frontmatter should be preserved.\n\n### Kinds\n\nConsumer-defined structural types (for example `study`, `theme`, `competitor`, or `rule`). Kinds can declare required fields for linting and strict validation.\n\n### Vocabularies\n\nConsumer-owned controlled terms and aliases. Madrigal can canonicalize configured fields in `attributes` while preserving the raw parsed value in `frontmatter`.\n\n### Domains\n\nOptional logical groupings of knowledge (e.g., `accessibility`, `typography`, `layout`). Defined in config and validated at load time when present.\n\n### Brands\n\nOrganizational units that can inherit from each other. A brand can `include` other brands/groups, and brand-specific knowledge overrides globals with the same id.\n\n### Enforcement\n\nOptional rule-oriented strength: `must`, `should`, `may`, `context`, or `deprecated`. Existing `severity` frontmatter is still accepted as a legacy alias for rule-focused workflows.\n\n### Formats\n\nOutput compilers that transform knowledge units into specific formats. Four built-in formats are included:\n\n| Format | Description |\n|--------|-------------|\n| `json-bundle` | Searchable JSON with metadata |\n| `skill-md` | Markdown skill file for AI agents |\n| `ai-rules-md` | Rule file for AI coding assistants |\n| `mesh-domain` | AI app-info mesh domain format |\n\n### Platforms\n\nNamed build targets in config. Each platform specifies a format and optional grouping (`brand`, `domain`, or `system`).\n\n## Configuration Reference\n\n```yaml\n# Glob patterns for knowledge source files\nsources:\n  - \"knowledge/**/*.md\"\n\n# Schema mapping and normalization\nschema:\n  preserveUnknownFrontmatter: true\n  id:\n    field: id              # Explicit frontmatter ID field\n    strategy: path         # path | filename\n  kind:\n    field: type            # Frontmatter field used as the unit kind\n    default: record\n    byPath:\n      \"knowledge/studies/**\": study\n  title:\n    field: title\n  relationships:\n    wikilinks: true        # Extract [[Target]] and [[Target|Label]]\n\n# Kind definitions and required fields\nkinds:\n  \u003cname\u003e:\n    required:\n      - title\n\n# Controlled vocabularies and aliases\nvocabularies:\n  \u003cfield\u003e:\n    values:\n      - canonical-value\n    aliases:\n      old-value: canonical-value\n\n# Domain definitions\ndomains:\n  \u003cname\u003e:\n    description: \"...\"\n\n# Brand definitions\nbrands:\n  \u003cname\u003e:\n    systems:        # Optional: associated design systems\n      - web\n    include:        # Optional: inherit from other brands\n      - global\n\n# Build targets\nplatforms:\n  \u003cname\u003e:\n    format: json-bundle    # Required: registered format name\n    groupBy: brand         # Optional: brand | domain | system\n    destination: out/      # Optional: output path\n```\n\n## Knowledge File Format\n\n```markdown\n---\ntitle: Record Title          # Field name is configurable\nid: custom-id                # Optional, generated from path by default\ntype: study                  # Field name is configurable\nsource_url: https://example.com/source\ndurability: evergreen        # Consumer-owned attribute\nenforcement: should          # Optional for rule-oriented records\ntags:\n  - research\n---\n\nMarkdown body content here, including optional [[Wiki Links]].\n```\n\n## Plugin System\n\n### Custom Formats\n\n```typescript\nimport { defaultRegistry, type Format } from '@anarchitecture/madrigal';\n\nconst myFormat: Format = {\n  name: 'custom-html',\n  extension: '.html',\n  compile(units, options) {\n    return `\u003chtml\u003e...\u003c/html\u003e`;\n  },\n};\n\ndefaultRegistry.register(myFormat);\n```\n\n### Custom Preprocessors\n\nPreprocessors transform knowledge units after loading but before compilation:\n\n```typescript\nimport { defaultPreprocessorRegistry, type Preprocessor } from '@anarchitecture/madrigal';\n\nconst enricher: Preprocessor = {\n  name: 'tag-enricher',\n  async process(units, config) {\n    return units.map(u =\u003e ({\n      ...u,\n      tags: [...u.tags, 'enriched'],\n    }));\n  },\n};\n\ndefaultPreprocessorRegistry.register(enricher);\n```\n\n### Adapter Interfaces\n\nMadrigal exports `StorageAdapter` and `SearchAdapter` interfaces for implementing custom backends (databases, vector stores, etc.).\n\n## API\n\n### `build(options?)`\n\nRun the full pipeline: load config, load knowledge, run preprocessors, compile all platforms.\n\n### `loadConfig(path?)`\n\nLoad and parse a `madrigal.config.yaml` file.\n\n### `loadKnowledge(options)`\n\nLoad knowledge units from markdown files matching source globs.\n\n### `resolveForBrand(options)`\n\nResolve knowledge units for a specific brand, applying inheritance and severity overrides.\n\n### `validateConfig(config, formatNames?)`\n\nValidate a configuration object.\n\n### `serveMcp(options?)`\n\nStart a stdio MCP server that exposes five tools for querying the knowledge base:\n`search_knowledge`, `get_knowledge_unit`, `list_knowledge_units`, `get_brand_rules`, `review_content`.\n\n```typescript\nimport { serveMcp } from '@anarchitecture/madrigal';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst baseDir = dirname(fileURLToPath(import.meta.url));\n\n// Single bundle\nawait serveMcp({ baseDir, bundlePath: 'publish/to-artifactory/knowledge.json' });\n\n// Multiple bundles merged into one index (for aggregator repos)\nawait serveMcp({\n  baseDir,\n  bundlePath: 'publish/to-artifactory/knowledge.json',\n  bundlePaths: [\n    resolve(baseDir, '../other-repo/publish/to-artifactory/knowledge.json'),\n  ],\n});\n```\n\nSave this as `mcp-server.js` at the repo root and register it in your MCP client config.\n\n## Skills Convention\n\nRepos that use Madrigal should own their agent skills alongside their knowledge. Skills live in `skills/{skill-name}/SKILL.md` — always a named subdirectory, never at the repo root. This mirrors the local install path (`~/.claude/skills/{name}/SKILL.md`) so publishing is mechanical.\n\n**Single-skill repo:**\n```\nskills/\n  my-knowledge-base/\n    SKILL.md\n```\n\n**Multi-skill repo** (e.g. one skill per brand or design system):\n```\nskills/\n  arcade/\n    SKILL.md\n  market/\n    SKILL.md\n```\n\nSkill files reference the MCP tools (`search_knowledge`, etc.) with domain-specific routing instructions. The repo team owns the skill — it is not generated by Madrigal.\n\nTo install a skill locally for development:\n```bash\nmkdir -p ~/.claude/skills/{skill-name}/\nln -sf \"$(pwd)/skills/{skill-name}/SKILL.md\" ~/.claude/skills/{skill-name}/SKILL.md\n```\n\n## Release Workflow\n\nMadrigal uses [Changesets](https://github.com/changesets/changesets) for\nversioning.\n\nFor a release-bearing change, run:\n\n```bash\npnpm changeset\n```\n\nAfter the change lands on `main`, the `Version Packages` GitHub Actions\nworkflow creates a version PR when changesets are pending. Merging to `main`\ndoes not publish Madrigal.\n\nTo publish a GitHub Release tarball, merge the version PR and push a matching\ntag:\n\n```bash\nVERSION=$(node -e \"console.log(JSON.parse(require('fs').readFileSync('package.json', 'utf8')).version)\")\ngit tag \"anarchitecture-madrigal@$VERSION\"\ngit push origin \"anarchitecture-madrigal@$VERSION\"\n```\n\nThe `Publish tarball to GitHub Release` workflow can also be run manually with\nthe package version from `package.json`.\n\nManual release commands are also available:\n\n```bash\npnpm version-packages\npnpm release\n```\n\n## Project Resources\n\n| Resource | Description |\n|----------|-------------|\n| [CODEOWNERS](./CODEOWNERS) | Project lead(s) |\n| [GOVERNANCE.md](./GOVERNANCE.md) | Project governance |\n| [LICENSE](./LICENSE) | Apache License, Version 2.0 |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblock%2Fmadrigal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblock%2Fmadrigal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblock%2Fmadrigal/lists"}