diff --git a/.cursor-plugin/marketplace.json b/.cursor-plugin/marketplace.json new file mode 100644 index 0000000..96a65b7 --- /dev/null +++ b/.cursor-plugin/marketplace.json @@ -0,0 +1,16 @@ +{ + "name": "apolloknowledgebase", + "owner": { + "name": "Apollo Team" + }, + "metadata": { + "description": "ApolloKnowledgeBase for Cursor: the 68080, SAGA, ApolloOS, AmigaOS on V4, and ApolloCrossDev." + }, + "plugins": [ + { + "name": "akb", + "source": "akb", + "description": "Skills for Apollo V4 development: apollo-new-project, apollo-build, and akb-lesson." + } + ] +} diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json new file mode 100644 index 0000000..6fa7a9e --- /dev/null +++ b/.cursor-plugin/plugin.json @@ -0,0 +1,11 @@ +{ + "name": "akb", + "version": "1.0.0", + "description": "Skills for Apollo V4 development with ApolloKnowledgeBase: apollo-new-project, apollo-build, and akb-lesson. The knowledge base ships with the plugin.", + "author": { + "name": "Apollo Team" + }, + "homepage": "https://apolloknowledgebase.com", + "repository": "https://github.com/ApolloTeam-dev/ApolloKnowledgeBase", + "keywords": ["apollo", "vampire", "68080", "saga", "amiga", "apolloos"] +} diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1c0d5d2 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,44 @@ +# POSIX skill scripts must stay LF. A CR in the file is part of the command +# for /bin/sh, so core.autocrlf must not rewrite them on checkout. +*.sh text eol=lf + +# Generated package marker must stay LF. tools/package_cursor_plugin.py +# compares it byte-for-byte to MARKER.encode("ascii"). +akb/PACKAGE.txt text eol=lf + +# akb/sources/official/ is a byte copy of the official originals. Those HTML +# files already contain trailing spaces. Do not rewrite the copies to satisfy +# a whitespace check. tools/package_cursor_plugin.py +akb/sources/official/** -whitespace + +# These generated copies are stored with the same CRLF bytes as their +# canonical files. Git must not normalise them to LF. +akb/sources/official/saga-registers/audnvol.htm -text +akb/sources/official/saga-registers/audxvol.htm -text +akb/sources/official/saga-registers/beamcon0.htm -text +akb/sources/official/saga-registers/bltddat.htm -text +akb/sources/official/saga-registers/bplcon0.htm -text +akb/sources/official/saga-registers/bplcon1.htm -text +akb/sources/official/saga-registers/bplcon2.htm -text +akb/sources/official/saga-registers/bplcon3.htm -text +akb/sources/official/saga-registers/bplxdat.htm -text +akb/sources/official/saga-registers/bplxmod.htm -text +akb/sources/official/saga-registers/bplxpth.htm -text +akb/sources/official/saga-registers/colorx.htm -text +akb/sources/official/saga-registers/diwhigh.htm -text +akb/sources/official/saga-registers/dskdatr.htm -text +akb/sources/official/saga-registers/hbstrt.htm -text +akb/sources/official/saga-registers/hcenter.htm -text +akb/sources/official/saga-registers/hsstop.htm -text +akb/sources/official/saga-registers/hsstrt.htm -text +akb/sources/official/saga-registers/htotal.htm -text +akb/sources/official/saga-registers/joy0dat.htm -text +akb/sources/official/saga-registers/sprxctl.htm -text +akb/sources/official/saga-registers/sprxdata.htm -text +akb/sources/official/saga-registers/sprxpos.htm -text +akb/sources/official/saga-registers/sprxpth.htm -text +akb/sources/official/saga-registers/vbstrt.htm -text +akb/sources/official/saga-registers/vhposr.htm -text +akb/sources/official/saga-registers/vposr.htm -text +akb/sources/official/saga-registers/vsstrt.htm -text +akb/sources/official/saga-registers/vtotal.htm -text diff --git a/.github/workflows/kb-checks.yml b/.github/workflows/kb-checks.yml index 318c06c..826dab6 100644 --- a/.github/workflows/kb-checks.yml +++ b/.github/workflows/kb-checks.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-python@v7 with: python-version: "3.12" - - run: pip install pyyaml==6.0.2 + - run: pip install pyyaml==6.0.2 jsonschema==4.25.1 - name: Frontmatter, naming and placement run: python tools/check_frontmatter.py @@ -32,6 +32,12 @@ jobs: run: python tools/check_skills.py env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Shared skill workflows + run: python tools/check_shared_workflows.py + - name: Cursor plugin package + run: python tools/check_cursor_plugin.py + - name: Claude plugin manifests (static) + run: python tools/check_claude_plugin.py - name: Markdown lint uses: DavidAnson/markdownlint-cli2-action@v25 with: @@ -39,6 +45,7 @@ jobs: **/*.md !seed/** !templates/** + !akb/** compile-examples: # ApolloCrossDev supports Ubuntu 24.04 only. diff --git a/AGENTS.md b/AGENTS.md index e55c4e6..1614d9c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -229,14 +229,25 @@ knowledge base files it needs instead of repeating them. | `skills/apollo-build/` | Apollo V4 code is compiled, linked or assembled, flags come up, a build fails, or before presenting code | | `skills/akb-lesson/` | a project, release or milestone is done, the user asks for a summary, or an assumption from section 2 turned out wrong | -If your agent loads skills by itself (Claude Code with the `akb` plugin, -or an agent whose skills folder links to this `skills/` folder), it picks -them up from their descriptions. If it doesn't, read +If your agent loads skills by itself (Claude Code or Cursor with the `akb` +plugin, or an agent whose skills folder links to this `skills/` folder), it +picks them up from their descriptions. If it doesn't, read `skills//SKILL.md` when the task matches the table above, and follow it. Paths in a SKILL.md are relative to its own folder or, when marked `KB`, to the knowledge base root. +A project reads its own `ApolloKnowledgeBase/` submodule when that submodule +is initialized. That pin is authoritative. Otherwise the agent uses the +knowledge base bundled with the installed `akb` plugin (Claude Code or +Cursor). `tools/resolve_kb.py` prints which one, or the exact problem. The +Cursor rule `rules/apollo-v4.mdc` only points at this file and those skills. + Claude Code users install the skills once with `/plugin marketplace add ApolloTeam-dev/ApolloKnowledgeBase` and `/plugin install akb@apolloknowledgebase`; they are then called as -`/akb:apollo-build` and so on. +`/akb:apollo-build` and so on. Cursor users install the plugin as described +in [docs/cursor-plugin.md](docs/cursor-plugin.md) and call `/apollo-new-project`, +`/apollo-build`, and `/akb-lesson`. The Cursor marketplace package is the +generated directory `akb/`. The canonical skills and knowledge files stay +at this repository's root. `tools/package_cursor_plugin.py` writes `akb/`. +Do not edit that directory by hand. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2553550..5c9c12a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -78,6 +78,14 @@ Not content: `templates/` (file, repo and seed templates), `sources/` skills, step 2), `evals/` (AI benchmarks, step 5), `tools/` (CI scripts, and the V4 test runner in `tools/v4/`). +`docs/` is operational documentation: how to install or check an editor +plugin. It is not Apollo V4 knowledge, it is not written from +`templates/files/`, and it has no knowledge-base frontmatter. The Cursor +guide is `docs/cursor-plugin.md`. `rules/` holds editor rules that point +at `AGENTS.md`. Those rules are not knowledge-base content either. +`akb/` is not content either. It is the generated Cursor install tree. +`docs/cursor-plugin.md` says how it relates to these canonical files. + Each chip folder keeps its register map in `registers.md` inside that folder. The official SAGA register documentation is generated into `core/saga-registers/` (document intake, section 11); the chip folders link @@ -147,8 +155,10 @@ hardware programming during a takeover goes in `core/`. Both use ## 4. Frontmatter -Every file starts with YAML frontmatter. CI rejects files with missing -required fields or invalid values. +Every knowledge-base content file starts with YAML frontmatter. CI rejects +content files with missing required fields or invalid values. Operational +documentation does not use this frontmatter: `docs/`, `README.md`, +`AGENTS.md` and this file (section 2). ```yaml --- @@ -407,14 +417,27 @@ On every merge to `main`, `generate_codeowners.py` regenerates `.github/CODEOWNERS.base`. The `seed/`, `sources/` and `templates/` folders are excluded from content -checks. +checks. `docs/` and `rules/` are excluded from the content frontmatter +check only (`tools/kblib.py`). They are operational documentation and +editor rules, not knowledge-base files, so they do not take knowledge-base +frontmatter. `docs/*.md` stays in the internal-link check and in Markdown +lint. `tools/check_links.py` does not skip `docs/`. `akb/` is the generated +Cursor package. Content checks, the link check, and Markdown lint skip it. +`tools/check_cursor_plugin.py` checks that directory against +`tools/package_cursor_plugin.py` instead. Do not edit files under `akb/` +by hand. Run the checks locally before opening a pull request: ```sh -pip install pyyaml +pip install pyyaml jsonschema python tools/check_frontmatter.py python tools/check_links.py +python tools/check_skills.py +python tools/check_shared_workflows.py +python tools/package_cursor_plugin.py --check +python tools/check_cursor_plugin.py +python tools/check_claude_plugin.py ``` --- @@ -485,20 +508,41 @@ skill points to it. - **Format:** the open Agent Skills format. One folder per skill, `skills//SKILL.md`, with frontmatter `name` (equal to the folder name: lowercase letters, digits and single hyphens) and `description` - (what the skill does and when to use it, at most 1024 characters). No - other frontmatter fields, so every agent can read it. + (what the skill does and when to use it, at most 1024 characters, on one + line). No other frontmatter fields, so every agent can read it. - **Description:** the agent decides from it alone whether to use the skill. Name the tasks and the words developers use, and say "even when it looks like ordinary m68k or Amiga work" where AGENTS.md section 2 applies. - **Body:** at most 500 lines. Point to knowledge base files as `KB `; don't copy their content. Files of the skill itself (`scripts/`, `assets/`) are referenced relative to its folder. -- **Scripts:** POSIX `sh`, no Claude-specific variables. Code in `assets/` - must build with ApolloCrossDev without warnings. +- **Scripts:** POSIX `sh`, no Claude-specific variables. The file in + `skills//scripts/` is the entry point the skill runs. It may call + one shared program in `tools/` written with the Python standard library. + Both plugins use that same entry point. Do not put a second copy of the + program under `skills/`, and do not replace the `sh` entry point with a + Python script. Code in `assets/` must build with ApolloCrossDev without + warnings. - **New skills** are listed in AGENTS.md section 9 in the same pull request. -- Claude Code installs `skills/` as the plugin `akb` (`.claude-plugin/`); - other agents read it through AGENTS.md section 9. +- Claude Code installs the repository root as the plugin `akb` + (`.claude-plugin/`, marketplace source `./`). +- Cursor's GitHub marketplace installs the generated directory `akb/` + (`.cursor-plugin/marketplace.json`, source `akb`). The canonical skill + files stay in `skills/`. `tools/package_cursor_plugin.py` copies them, + with the knowledge base and the shared programs, into `akb/`. Do not + edit `akb/` by hand and do not keep a separate skill text for Cursor. + See `docs/cursor-plugin.md`. +- Other agents read the skills through AGENTS.md section 9. CI runs `tools/check_skills.py` on every pull request: frontmatter, name, -description length, body length, and that every `KB ` and file of -the skill exists. +description length, a single-line description, body length, and that every +`KB ` and file of the skill exists. It also runs +`tools/check_shared_workflows.py` (those entry points, in a temporary +directory), `tools/check_cursor_plugin.py` (manifests, the generated +`akb/` package, and a temporary copy of that package) and +`tools/check_claude_plugin.py` (plugin manifests). Those checks do not +load Cursor or Claude Code. The default workflow check is fixture-only and +does not run Make; it prints `RESULT guided-build SKIPPED`. Pass +`--run-toolchain` for an authorised real compile probe. That probe may +print `NOT VERIFIED` when ApolloCrossDev is absent, and that line is not +a successful compile. diff --git a/README.md b/README.md index 1411b4a..a56475c 100644 --- a/README.md +++ b/README.md @@ -66,11 +66,28 @@ execution mode (`os-friendly` or `os-takeover`) and V4 model it applies to. AI agents working in that repository then find and follow the knowledge base automatically. +Claude Code and Cursor load the same three skills as the plugin `akb`. +These are the entry points. The procedures stay in the skill files. + +- Claude Code: `/plugin marketplace add ApolloTeam-dev/ApolloKnowledgeBase`, + then `/plugin install akb@apolloknowledgebase`. The skills are + `/akb:apollo-new-project`, `/akb:apollo-build` and `/akb:akb-lesson`. + The marketplace name stays `apolloknowledgebase` (`AGENTS.md` section 9). + Point that marketplace at another clone only when the developer asks. +- Cursor: install the generated `akb/` directory as described in + [docs/cursor-plugin.md](docs/cursor-plugin.md), then + `/apollo-new-project`, `/apollo-build` and `/akb-lesson`. + The canonical skills and articles stay at the repository root. + +`apollo-new-project` tracks +`https://github.com/ApolloTeam-dev/ApolloKnowledgeBase` unless the develope +asks for another clone URL. + --- ## Contributing -Everyone in the Apollo community can contribute. Read `CONTRIBUTING.md` for +Everyone in the Apollo community can contribute. Read `CONTRIBUTING.md` fo the file format and review process. The most valuable contributions are: - Places where ApolloOS, the 68080 or SAGA differ from what developers (and diff --git a/akb/.cursor-plugin/plugin.json b/akb/.cursor-plugin/plugin.json new file mode 100644 index 0000000..6fa7a9e --- /dev/null +++ b/akb/.cursor-plugin/plugin.json @@ -0,0 +1,11 @@ +{ + "name": "akb", + "version": "1.0.0", + "description": "Skills for Apollo V4 development with ApolloKnowledgeBase: apollo-new-project, apollo-build, and akb-lesson. The knowledge base ships with the plugin.", + "author": { + "name": "Apollo Team" + }, + "homepage": "https://apolloknowledgebase.com", + "repository": "https://github.com/ApolloTeam-dev/ApolloKnowledgeBase", + "keywords": ["apollo", "vampire", "68080", "saga", "amiga", "apolloos"] +} diff --git a/akb/.github/CODEOWNERS.base b/akb/.github/CODEOWNERS.base new file mode 100644 index 0000000..5abdba0 --- /dev/null +++ b/akb/.github/CODEOWNERS.base @@ -0,0 +1,13 @@ +# Default reviewers for everything not matched below, including new files +# that are not yet in CODEOWNERS. Later lines take precedence. +* @WDrijver @TuKo1982 + +# Fixed owners for files without frontmatter. +/README.md @WDrijver @TuKo1982 +/AGENTS.md @WDrijver @TuKo1982 +/CONTRIBUTING.md @WDrijver @TuKo1982 +/templates/ @WDrijver @TuKo1982 +/tools/ @WDrijver @TuKo1982 +/sources/ @WDrijver @TuKo1982 +/.github/ @WDrijver @TuKo1982 +/.markdownlint.jsonc @WDrijver @TuKo1982 diff --git a/akb/AGENTS.md b/akb/AGENTS.md new file mode 100644 index 0000000..1614d9c --- /dev/null +++ b/akb/AGENTS.md @@ -0,0 +1,253 @@ +# AGENTS.md: ApolloKnowledgeBase + +You are working with ApolloKnowledgeBase, the curated knowledge base for +software development on the Apollo V4 platform. Read this file first. It tells +you what the platform is, what you probably assume wrongly, and which files to +read for your task. + +When this knowledge base is used from a code repository, that repository's +own AGENTS.md states where the knowledge base is located. All paths below are +relative to the knowledge base root. + +--- + +## 1. The platform in brief + +- **Apollo V4**: hardware platform built around the **68080** CPU, a successor + of the Motorola 68000 family, with the **AMMX** SIMD extension. +- **SAGA chipset**: `saga-video-isabelle` (video), `saga-audio-arne` (audio), + `saga-dma-anni` (DMA), `saga-3d-maggie` (3D). +- **V4 models**: V4 Standalone (SA), V4 UniCorn (UNI, A6000), V4 IceDrake + (ICE), V4 Manticore (MC) and V4 Firebird (FB). They share the FPGA core + (68080 and SAGA) but differ as boards. A core number has exactly the same + features and architecture on every model; the boards differ only in small + physical properties (for example, the V4 IceDrake has no second SPI + port). The project's own AGENTS.md states the target model(s), if it + depends on one. +- **Target OS**: Apollo V4 software runs on one or more of **ApolloOS R10** + (fork of AROS, optimized for Apollo V4), **AmigaOS 3.9** and + **AmigaOS 3.2**. The project's own AGENTS.md states which. Hardware + knowledge applies whatever the OS. +- **Execution mode**: the project's AGENTS.md also states one of two modes. + - `os-friendly`: use OS calls where available. Direct SAGA access only at + the developer's discretion and responsibility. + - `os-takeover`: `Forbid()` multitasking, use only basic OS calls + (`AllocMem()`/`FreeMem()`, `Open()`/`Close()`), program the 68080 and + SAGA directly, and restore multitasking and the Workbench screen on exit. + Typical for games and demos. +- **ApolloCrossDev**: the one and only toolchain + (github.com/WDrijver/ApolloCrossDev). + +--- + +## 2. Your knowledge is probably wrong here + +Your training data covers classic AmigaOS and the 68000–68060 well. Your +AmigaOS API knowledge is mostly right on Apollo V4. Your hardware and +compiler knowledge is where you will make confident mistakes. + +- DON'T assume 68060 behavior, timing or instruction availability applies to + the 68080. Check `core/cpu-68080/`. +- DON'T assume classic Amiga chipset behavior applies to SAGA. Check the + relevant `core/saga-*` folder. +- DON'T assume generic m68k GCC or vasm behavior. ApolloCrossDev is a patched + GCC 6.5 with 68080 support. Check `toolchain/`. +- DON'T write generic 68k code when an Apollo-specific technique exists. Check + `core/best-practices/` before writing performance-relevant code. +- DON'T use OS functions that are missing in one of the project's target + operating systems. Check `os/apolloos-and-amigaos-on-v4.md`. +- DON'T access SAGA registers directly in an `os-friendly` project unless the + developer asks for it. When you do, say so. +- DON'T call OS functions beyond the basic set in an `os-takeover` project, + and DON'T leave the machine without restoring multitasking and the + Workbench screen. Check `os/os-takeover.md`. +- DON'T assume a connector, header or memory layout is the same on every V4 + model. Check `hardware/v4-generic/` and the model's folder in `hardware/`. +- DON'T invent register addresses, bit meanings, function signatures or + compiler flags. If it is not in the knowledge base or in source code you + have read, say that you don't know. + +--- + +## 3. What to read for your task + +The knowledge base has four pillars: `core/` (68080 and SAGA), `hardware/` +(the V4 boards), `os/` (ApolloOS and AmigaOS on V4) and `toolchain/` +(ApolloCrossDev). Each has its +own `best-practices/` and `pitfalls/` subfolders. Read only what your task +needs, and always check the `best-practices/` and `pitfalls/` of every pillar +you read. + +| Task | Read | +|---|---| +| Any task | This file, `os/apolloos-and-amigaos-on-v4.md`, `os/best-practices/`, `os/pitfalls/` | +| Target OS is ApolloOS only, or working on ApolloOS itself (ApolloOS.R10) | `os/apolloos-specific-on-v4.md`, `os/` subfolders | +| Execution mode is `os-takeover` (games, demos) | `os/os-takeover.md`, `core/` | +| Writing code at all | `conventions/`, `toolchain/` | +| CPU-heavy or assembly code | `core/cpu-68080/`, `core/best-practices/`, `core/pitfalls/` | +| Graphics, screens, video modes | `core/saga-video-isabelle/`, `core/saga-registers/` | +| Sound | `core/saga-audio-arne/`, `core/saga-registers/` | +| Memory transfers, DMA | `core/saga-dma-anni/` | +| SAGA input, board ID, other SAGA registers | `core/saga-registers/` | +| 3D | `core/saga-3d-maggie/`, `core/saga-registers/` | +| Board connectors, headers, memory, model differences | `hardware/v4-generic/`, the model's folder in `hardware/` | +| Using or changing an ApolloOS library | `os/libraries/` | +| Device drivers | `os/devs/`, plus the `core/` or `hardware/` folder of the hardware involved | +| Filesystems | `os/filesys/` | +| Shell commands | `os/commands/` | +| Datatypes | `os/datatypes/` | +| Build problems, compiler flags, optimization settings | `toolchain/`, `toolchain/best-practices/`, `toolchain/pitfalls/` | +| A task with a matching how-to | `guides/` | +| Looking for working code to start from | `examples/` | +| Starting a project, building, writing a lesson | the matching skill, section 9 | + +Follow `related:` links in a file's frontmatter when they are relevant to the +task. + +DON'T read `lessons/` by default. Read it only when asked, or when writing a +new lesson or distilling lessons into other files. + +--- + +## 4. How to interpret file metadata + +Every file starts with YAML frontmatter (full spec in `CONTRIBUTING.md`). + +- **status** + - `verified`: tested on real hardware. Trust it. + - `reviewed`: checked by its owner. Trust it, but verify critical details + when possible. + - `draft`: unreviewed. Use with caution and tell the user when your answer + depends on a draft. + - `deprecated`: do not use. Follow `superseded_by`. +- **applies_to**: check that `core` covers the user's core (`any`, + `Core 12841`, a range `Core 12830-12840` or `Core 12841+`), that `os` is + `any` or covers every target OS of the project, and that `mode` and + `board` (if present) include the project's execution mode and V4 model. If + not, or the target is unknown, say so. +- **basis** and the tags after facts tell where a fact comes from: **(G)** + the core developer, **(M)** measured on V4 hardware, **(official)** official + Apollo documentation such as the 68080 PRM, **(SRC)** source code. +- **origin** + - `official`: converted from official Apollo documentation. Authoritative, + but conversion errors are possible while the status is `draft`. + - `ai-assisted`: drafted by an AI. Treat like `draft` unless the status + says otherwise. +- **generated_from**: the file is generated from an original document in + `sources/official/`. Never edit it. Propose the change to the maintainers + as a change to the original document. + +When two facts contradict each other, decide in this order, and always tell +the user about the conflict: + +1. The source rank: (G) core developer, then (M) measured, then (official) + documentation, then (SRC) source code, then anything else. +2. The newer core. +3. The higher status, then the more recent `last_verified`. + +So a measured fact in a pitfall beats the 68080 PRM, even when the PRM file +has a higher status. + +--- + +## 5. When the knowledge base is silent + +1. Say clearly that the knowledge base does not cover it. +2. If available, read the actual source code (ApolloOS repository, + ApolloCrossDev repository) and say that your answer is based on it. +3. Propose a new knowledge base file or addition so the gap gets closed. + +If something works on AmigaOS but fails on ApolloOS, that is an ApolloOS bug. +Propose an issue for github.com/ApolloTeam-dev/ApolloOS.R10, not a pitfall or +workaround in the knowledge base. + +--- + +## 6. Writing code + +- Apply the relevant best practices and avoid all relevant pitfalls of each + pillar. +- Build with ApolloCrossDev as described in `toolchain/` (step by step: the + apollo-build skill, section 9), and fix all errors and warnings before + presenting code. +- In pull request descriptions, list the knowledge base files you relied on. + This shows reviewers where wrong code came from if the knowledge base itself + was wrong. + +--- + +## 7. Writing to the knowledge base + +- Follow `CONTRIBUTING.md` exactly: folder, file name, frontmatter, template. +- Always set `origin: ai-assisted` and `status: draft`. Exception: during + document intake by a maintainer, set `origin: official` as described in + `CONTRIBUTING.md` section 11. +- Never edit a file that has `generated_from` in its frontmatter. +- Set `owner` to the person who asked you to make the change, unless they + name someone else. +- Never change the `status` of an existing file. Status changes are human + decisions. +- Never delete files. Deprecate them as described in `CONTRIBUTING.md`. +- All changes go through a pull request. + +--- + +## 8. Lessons: give back what the project learned + +Offer the developer a lesson when: + +- they say a project, a release or a milestone is done, or ask for a summary; +- you find that an assumption from section 2 was wrong (offer it right away, + while the details are fresh). + +Then: + +1. Draft `lessons/YYYY-MM-project-name.md` from + `templates/files/lesson.md`. Be specific and honest about what you got + wrong, especially wrong assumptions from section 2. Give the evidence + (source tag, core, method) for every measured claim. +2. Show the draft to the developer. Submit nothing without their approval. +3. Submit it as described in `CONTRIBUTING.md` section 7: preferably as a + pull request from the knowledge base clone (the `ApolloKnowledgeBase/` + submodule), on a branch `lesson/YYYY-MM-project-name`; otherwise give the + developer the text for the "Submit a lesson" issue form. +4. Return the submodule to the commit the project uses afterwards. + +The akb-lesson skill (section 9) has these steps in detail. + +--- + +## 9. Skills: step-by-step procedures + +`skills/` holds procedures for recurring tasks, in the open Agent Skills +format: one folder per skill with a `SKILL.md`. Each one points to the +knowledge base files it needs instead of repeating them. + +| Skill | Use it when | +|---|---| +| `skills/apollo-new-project/` | the user starts a new Apollo V4 project (also from the "Start Apollo V4 Project" prompt on apolloknowledgebase.com), or wants a folder of Apollo code set up for AI-assisted work | +| `skills/apollo-build/` | Apollo V4 code is compiled, linked or assembled, flags come up, a build fails, or before presenting code | +| `skills/akb-lesson/` | a project, release or milestone is done, the user asks for a summary, or an assumption from section 2 turned out wrong | + +If your agent loads skills by itself (Claude Code or Cursor with the `akb` +plugin, or an agent whose skills folder links to this `skills/` folder), it +picks them up from their descriptions. If it doesn't, read +`skills//SKILL.md` when the task matches the table above, and follow +it. Paths in a SKILL.md are relative to its own folder or, when marked +`KB`, to the knowledge base root. + +A project reads its own `ApolloKnowledgeBase/` submodule when that submodule +is initialized. That pin is authoritative. Otherwise the agent uses the +knowledge base bundled with the installed `akb` plugin (Claude Code or +Cursor). `tools/resolve_kb.py` prints which one, or the exact problem. The +Cursor rule `rules/apollo-v4.mdc` only points at this file and those skills. + +Claude Code users install the skills once with +`/plugin marketplace add ApolloTeam-dev/ApolloKnowledgeBase` and +`/plugin install akb@apolloknowledgebase`; they are then called as +`/akb:apollo-build` and so on. Cursor users install the plugin as described +in [docs/cursor-plugin.md](docs/cursor-plugin.md) and call `/apollo-new-project`, +`/apollo-build`, and `/akb-lesson`. The Cursor marketplace package is the +generated directory `akb/`. The canonical skills and knowledge files stay +at this repository's root. `tools/package_cursor_plugin.py` writes `akb/`. +Do not edit that directory by hand. diff --git a/akb/CONTRIBUTING.md b/akb/CONTRIBUTING.md new file mode 100644 index 0000000..5c9c12a --- /dev/null +++ b/akb/CONTRIBUTING.md @@ -0,0 +1,548 @@ +# Contributing to ApolloKnowledgeBase + +This file is the single source of truth for how ApolloKnowledgeBase files are +structured, written and reviewed. It applies to humans and AI agents alike. +AI agents creating or editing files in this repository MUST follow it. + +--- + +## 1. Golden rules + +1. **Document the differences.** Do not re-document classic AmigaOS or AROS + behavior that is unchanged. Focus on where ApolloOS, the 68080 and the SAGA + chipset differ, extend, or break expectations. Exception: official + documents (section 11) are converted in full. +2. **One topic per file.** If a file covers two things, split it. +3. **Be exact.** Give register offsets, bit meanings, cycle counts, return + values and version numbers. Never write "see the manual". +4. **Every file has an owner.** No owner, no merge. +5. **Claims need evidence.** Performance claims need measurements; hardware + facts need a source (spec, source code, or a test on real hardware). +6. **Code must compile.** Every code block marked as compilable is built in CI. + +--- + +## 2. Where things go + +The knowledge base has four pillars: **core** (the FPGA core: 68080 CPU and +SAGA chipset), **hardware** (the V4 boards), **os** (the operating systems) +and **toolchain** (ApolloCrossDev). Each pillar holds +reference files plus its own `best-practices/` and `pitfalls/`. Knowledge +that spans pillars goes in the cross-cutting folders. + +```text +core/ 68080 CPU and SAGA chipset +├── cpu-68080/ ISA, AMMX, pipeline, timing, 68060 differences +├── saga-video-isabelle/ video chip +├── saga-audio-arne/ audio chip +├── saga-dma-anni/ DMA chip +├── saga-3d-maggie/ 3D chip +├── best-practices/ +└── pitfalls/ +hardware/ the V4 boards +├── v4-generic/ shared by all V4 models: memory map, common connectors +├── v4-standalone/ V4 Standalone (SA) +├── v4-unicorn/ V4 UniCorn (UNI, A6000) +├── v4-icedrake/ V4 IceDrake (ICE) +├── v4-manticore/ V4 Manticore (MC) +├── v4-firebird/ V4 Firebird (FB) +├── best-practices/ +└── pitfalls/ +os/ ApolloOS R10, AmigaOS 3.9 and 3.2 on Apollo V4 +├── *.md running on V4, OS takeover, ApolloOS specifics +├── libraries/ devs/ filesys/ commands/ datatypes/ ApolloOS components +├── best-practices/ +└── pitfalls/ +toolchain/ ApolloCrossDev +├── *.md components, setup, options, syntax +├── best-practices/ +└── pitfalls/ +guides/ step-by-step how-tos +examples/ small, compiling, tested code +conventions/ team coding style and process +lessons/ project retrospectives +``` + +| Folder | `type` | +|---|---| +| `core/`, `hardware/`, `os/`, `toolchain/` and their subfolders | reference | +| `/best-practices/` | best-practice | +| `/pitfalls/` | pitfall | +| `guides/` | guide | +| `examples/` | example | +| `conventions/` | convention | +| `lessons/` | lesson | + +Not content: `templates/` (file, repo and seed templates), `sources/` +(original documents for document intake, section 11), `skills/` (AI agent +skills, step 2), `evals/` (AI benchmarks, step 5), `tools/` (CI scripts, +and the V4 test runner in `tools/v4/`). + +`docs/` is operational documentation: how to install or check an editor +plugin. It is not Apollo V4 knowledge, it is not written from +`templates/files/`, and it has no knowledge-base frontmatter. The Cursor +guide is `docs/cursor-plugin.md`. `rules/` holds editor rules that point +at `AGENTS.md`. Those rules are not knowledge-base content either. +`akb/` is not content either. It is the generated Cursor install tree. +`docs/cursor-plugin.md` says how it relates to these canonical files. + +Each chip folder keeps its register map in `registers.md` inside that folder. +The official SAGA register documentation is generated into +`core/saga-registers/` (document intake, section 11); the chip folders link +to it. + +`core/` is the FPGA core, the same on every V4 model. `hardware/` is the +board: connectors, headers, memory and what differs per model. Knowledge that +holds for all models goes in `hardware/v4-generic/`; a model folder holds +only what is specific to that model. Common abbreviations: SA (Standalone), +UNI or A6000 (UniCorn), ICE (IceDrake), MC (Manticore), FB (Firebird). + +A best practice or pitfall goes in the pillar it is about. One that spans +pillars goes in the pillar where a developer would look first, with +`related:` links to the others. + +Toolchain best practices still need evidence: show the compiler flags or +settings, and compare the generated code or measured speed against a baseline. + +### Target OS and OS bugs + +Apollo V4 software targets the V4 hardware, running ApolloOS R10, AmigaOS +3.9 or AmigaOS 3.2, often more than one. Hardware knowledge applies whatever +the OS. Guidelines for running well on V4 under each OS go in +`os/apolloos-and-amigaos-on-v4.md`. + +AmigaOS is the leading reference. When something works on AmigaOS but fails +on ApolloOS, that is an ApolloOS bug: report it as an issue in +github.com/ApolloTeam-dev/ApolloOS.R10 so it gets fixed in the source. Do not +document a workaround in this knowledge base. + +Everything else is welcome in `os/best-practices/` and `os/pitfalls/`, with +`applies_to.os` set accordingly: + +- valid on both ApolloOS and AmigaOS on V4: `os: [any]` +- a trap in AmigaOS 3.9 or 3.2 itself: for example `os: [amigaos-3.2]` +- about an ApolloOS-only feature: `os: [apolloos-r10]` + +### Execution mode + +Every Apollo V4 program starts from an OS and returns to it, in one of two +execution modes: + +- **os-friendly:** uses AmigaOS/ApolloOS calls where available. Direct SAGA + access is allowed at the discretion and responsibility of the developer. + Typical for applications, tools and OS components. +- **os-takeover:** disables multitasking with `Forbid()`, uses only basic OS + calls such as `AllocMem()`/`FreeMem()` and `Open()`/`Close()`, and focuses + on direct hardware access to the 68080 and the SAGA chipset. On exit it + restores multitasking and the Workbench screen. Typical for games and + demos. + +How to enter and leave a takeover goes in `os/os-takeover.md`, with its best +practices and pitfalls in `os/best-practices/` and `os/pitfalls/`. Direct +hardware programming during a takeover goes in `core/`. Both use +`mode: [os-takeover]` in their frontmatter. + +--- + +## 3. File naming + +- Lowercase kebab-case, `.md` extension: `ammx-pixel-blending.md` +- Name by topic, not by author or date (exception: `lessons/`, see section 7) +- Keep files under ~400 lines. Larger topics become a folder with an + `index.md` and one file per subtopic. + +--- + +## 4. Frontmatter + +Every knowledge-base content file starts with YAML frontmatter. CI rejects +content files with missing required fields or invalid values. Operational +documentation does not use this frontmatter: `docs/`, `README.md`, +`AGENTS.md` and this file (section 2). + +```yaml +--- +title: AMMX pixel blending # required, human-readable +type: best-practice # required, see allowed values +owner: github-handle # required, one GitHub handle +status: draft # required, see allowed values +origin: human # required, see allowed values +basis: [measured, core-developer] # optional, kinds of source used +components: [cpu-68080, saga-video-isabelle] # required, see allowed values +applies_to: # required + core: "Core 12841+" # required, see allowed values + os: [any] # see allowed values + mode: [os-takeover] # optional, see allowed values + board: [v4-standalone] # optional, see allowed values +last_verified: 2026-10-31 # required once status is verified +tags: [ammx, graphics, blitting] # optional, free keywords for search +related: # optional, paths to related files + - core/pitfalls/ammx-alignment.md +sources: # required for reference, best-practice + - "Apollo core spec, section X" +superseded_by: # only when status is deprecated +distilled_into: # lessons only, see section 7 +generated_from: # only for document intake, section 11 +--- +``` + +### Allowed values + +The machine-readable form of these rules is `tools/schema.json`: CI and the +ApolloKnowledgeBase-Manager wizard both read it. Change a rule there and here +together. + +- **type:** `reference`, `guide`, `convention`, `best-practice`, `pitfall`, + `example`, `lesson` +- **status:** + - `draft`: not yet reviewed; AI agents treat with caution + - `reviewed`: owner has reviewed content + - `verified`: tested on real Apollo V4 hardware on the stated core revision + - `deprecated`: no longer valid; must name `superseded_by` +- **origin:** + - `human`: written by a person + - `ai-assisted`: any AI-drafted content; can only move beyond `draft` + after a human review + - `official`: from official Apollo documentation through document intake + (section 11); maintainers only, CI checks that the owner is a maintainer +- **basis:** optional list of the kinds of source the file relies on, from + the highest rank to the lowest (see "Sources and their rank" below): + `core-developer`, `measured`, `official`, `source-code`, `other` +- **components:** `cpu-68080`, `saga-video-isabelle`, `saga-audio-arne`, + `saga-dma-anni`, `saga-3d-maggie`, `libraries`, `devs`, `filesys`, + `commands`, `datatypes`, `toolchain`, `hardware`, `general` +- **applies_to.core:** the core revisions the file is valid for: + - `any`: valid on every core + - `Core 12841`: one core + - `Core 12830-12840`: a range, both ends included + - `Core 12841+`: this core and later +- **applies_to.os:** a list of target operating systems the file is valid for: + - `any`: valid whatever the OS (all hardware facts); not combined with others + - `apolloos-r10`: ApolloOS R10, the current 10.x versions from ApolloTeam-dev + - `amigaos-3.9`: AmigaOS 3.9 (Haage & Partner) + - `amigaos-3.2`: AmigaOS 3.2, the current 3.2.x versions from Hyperion + + When a fact depends on a specific version (for example "fixed in 10.2"), + state that in the body. +- **applies_to.mode:** optional list of execution modes the file is valid + for (see section 2). Leaving it out means `any`. + - `any`: valid in both modes; not combined with others + - `os-friendly`: only for programs that keep the OS running + - `os-takeover`: only for programs that take over the machine +- **applies_to.board:** optional list of V4 models the file is valid for. + Leaving it out means `any`. + - `any`: all models; not combined with others + - `v4-standalone`, `v4-unicorn`, `v4-icedrake`, `v4-manticore`, + `v4-firebird` + +### Sources and their rank + +Mark where each fact comes from with a tag right after it, and list the kinds +in `basis`. When sources disagree, the higher rank wins: + +| Rank | Tag | `basis` | Source | +|---|---|---|---| +| 1 | **(G)** | `core-developer` | Gunnar, the core developer. Name the date: "(G, 2026-10-29)" | +| 2 | **(M)** | `measured` | Measured on real V4 hardware. State the core and the method (counters, test program) | +| 3 | **(official)** | `official` | The 68080 PRM and other official Apollo documents | +| 4 | **(SRC)** | `source-code` | Read from source code (ApolloOS, a library, ApolloCrossDev) | +| 5 | | `other` | Anything else, such as forum posts or apollo-core.com | + +Within the same rank, the newer core wins. Facts tied to a core say so in the +text ("on Core 12841") and in `applies_to.core`. A later core can change +them: measure again on yours. + +--- + +## 5. Templates per type + +Start every new file from a template in `templates/files/`. Each one has the +frontmatter and the required sections for its type: + +| Type | Template | +|---|---| +| reference | `templates/files/reference.md` | +| guide | `templates/files/guide.md` | +| convention | `templates/files/convention.md` | +| best-practice | `templates/files/best-practice.md` | +| pitfall | `templates/files/pitfall.md` | +| example | `templates/files/example.md` | +| lesson | `templates/files/lesson.md` | + +Keep the section headings exactly as in the template. AI agents and CI rely +on them. Remove placeholder text and any optional frontmatter field you +don't use. + +--- + +## 6. Writing style + +- Write for a reader who knows classic Amiga programming well but knows + nothing about Apollo V4. That describes most AI models. +- Short sentences. Exact numbers. Units always stated. +- Put the most important fact first. +- Use "DO" / "DON'T" for rules; AI agents follow these reliably. +- Code blocks always carry a language tag (`asm`, `c`, `cpp`, `sh`). The + assembler syntax and build settings are documented once in + `toolchain/`, not repeated in every file. +- Code blocks that should compile in CI are tagged with a comment on the + first line: `; kb:compile` (assembly) or `// kb:compile` (C, C++). + CI compiles each block on its own to an object file (no linking), so a + `kb:compile` block must be a complete source file with its own includes. +- A claim about the code the toolchain emits gets a check in its + `kb:compile` block: comment lines right after the first line, in the + block's comment style. + - `kb:expect ` / `kb:expect-not `: for C and C++ the text + must, or must not, occur in GCC's `-S` output (runs of spaces count as + one). For assembly the text is hex bytes (`71f1`, `7104 4a46`) that + must, or must not, occur in vasm's `-Fbin` output, so the block must not + reference outside symbols. + - `kb:opts `: build with these code-generation flags instead of + the standard ones (for example `-O2 -m68080` without `-m68881`). + - A check that fails means the text no longer matches the toolchain: + update the text, not only the check. +- CI also assembles every other `asm` block with vasm, as a fragment + (undefined labels are fine), so each instruction must exist and take its + operands. A block that must not assemble, such as an example of a vasm + error, starts with `; kb:no-assemble `. +- A SAGA address (`$DFExxx`, `$DFFxxx`) must be documented in + `core/saga-registers/`. A real address that is not documented there yet + goes in `tools/saga_addresses_allowed.yml`, with its source. + +--- + +## 7. Lessons lifecycle + +Lessons carry what a project learned back into the knowledge base. + +1. **Offer.** AI agents offer a lesson when the developer says a project, a + release or a milestone is done, or asks for a summary, and right away when + they find that an assumption from AGENTS.md section 2 was wrong. +2. **Draft.** The agent writes `lessons/YYYY-MM-project-name.md` from + `templates/files/lesson.md`, with the evidence (source, core, method) for + every measured claim, and shows it to the developer. Nothing is submitted + without the developer's approval. +3. **Submit.** Either way works: + - **Pull request (preferred):** in the knowledge base clone (the + `ApolloKnowledgeBase/` submodule of the project), on a new branch + `lesson/YYYY-MM-project-name`, commit the lesson and open a PR with + `gh pr create`. Without write access, `gh` offers to use a fork. Then + return the submodule to the commit the project uses + (`git submodule update ApolloKnowledgeBase` in the project). + - **Issue form:** open an issue with the "Submit a lesson" form on + github.com/ApolloTeam-dev/ApolloKnowledgeBase and paste the lesson. A + maintainer turns it into a file. +4. **Review.** CI checks the file; a maintainer merges it. Lessons stay + `draft` and are not read by AI agents by default: one project's experience + is not yet a rule. +5. **Distill.** The team turns the lesson's "Candidates for distillation" + into files in the pillars' `best-practices/` or `pitfalls/`, or into + `guides/`, and links the lesson in their `sources`. From then on every + agent finds it. The lesson lists those files in `distilled_into`; CI + checks that each one exists and names the lesson in its `sources`. A + lesson without `distilled_into` is not distilled yet. +6. Distilled lessons stay in place as history. + +--- + +## 8. Ownership and review + +- The `owner` field is the source of truth for ownership. +- `tools/` contains a script that generates `.github/CODEOWNERS` from all + `owner` fields, so GitHub requests the owner's review automatically. + Do not edit CODEOWNERS by hand. +- New files have no owner entry in CODEOWNERS until they are merged. Until + then, the repository maintainers are the default reviewers. +- All changes go through pull requests, including AI-drafted ones. +- Status changes (`draft` → `reviewed` → `verified`) require owner approval. +- To transfer ownership, change the `owner` field in a PR approved by both + the old and the new owner. + +--- + +## 9. Deprecation + +Do not delete outdated files. Set `status: deprecated`, fill in +`superseded_by`, and add one line at the top of the body explaining why. + +--- + +## 10. CI checks + +Every pull request runs (scripts in `tools/`): + +- `check_frontmatter.py`: required fields, allowed values (including the + `applies_to.core` notation and `basis`), file naming, + type matches folder, no leftover `` text, `related`, + `superseded_by` and `generated_from` paths exist, `official` files are + owned by a maintainer +- `check_links.py`: internal markdown links point to existing files +- `check_owners.py`: every owner is an existing GitHub account +- Markdown lint (rules in `.markdownlint.jsonc`) +- `intake/*.py --check`: files generated by document intake match their + original in `sources/official/` (section 11) +- Compilation of all `kb:compile` code blocks with ApolloCrossDev + (GCC-6.50-Dev, flags as in its Makefile template; see + `tools/compile-snippets.sh`) +- `check_emitted_code.py`: the `kb:expect` and `kb:expect-not` checks of + those blocks (section 6) +- Assembly of all other `asm` blocks with vasm, except in generated files + and blocks marked `; kb:no-assemble` (section 6) +- `check_saga_addresses.py`: every SAGA address is in + `core/saga-registers/` or `tools/saga_addresses_allowed.yml` + +- Build of the V4 hardware tests in `tools/v4/tests/` (see below) + +### Tests on V4 hardware + +`tools/v4/v4test.py` builds a test from `tools/v4/tests/` with +ApolloCrossDev, copies it to a V4 with ApolloExplorer (`acp`), runs it there +(`ash`), and stores the output, the serial log and optionally a screenshot +or video in `build/v4/`. A test prints `PASS`, `FAIL` and `VALUE` lines (see +`tools/v4/tests/akbtest.h`). Variants of one test (`v4:variant`) run +alternately, as `guides/benchmark-method.md` asks. The script's header lists +the environment variables for the V4's address, serial port, capture device +and power plug. + +```sh +AKB_V4_HOST=
python tools/v4/v4test.py run moviw --rounds 3 --shot +``` + +CI only builds the tests; running them needs a V4. A measured fact (M) that +rests on such a test names it in the Evidence table's Method column, with +the core and board it ran on. + +On every merge to `main`, `generate_codeowners.py` regenerates +`.github/CODEOWNERS`. Fixed owners for files without frontmatter go in +`.github/CODEOWNERS.base`. + +The `seed/`, `sources/` and `templates/` folders are excluded from content +checks. `docs/` and `rules/` are excluded from the content frontmatter +check only (`tools/kblib.py`). They are operational documentation and +editor rules, not knowledge-base files, so they do not take knowledge-base +frontmatter. `docs/*.md` stays in the internal-link check and in Markdown +lint. `tools/check_links.py` does not skip `docs/`. `akb/` is the generated +Cursor package. Content checks, the link check, and Markdown lint skip it. +`tools/check_cursor_plugin.py` checks that directory against +`tools/package_cursor_plugin.py` instead. Do not edit files under `akb/` +by hand. + +Run the checks locally before opening a pull request: + +```sh +pip install pyyaml jsonschema +python tools/check_frontmatter.py +python tools/check_links.py +python tools/check_skills.py +python tools/check_shared_workflows.py +python tools/package_cursor_plugin.py --check +python tools/check_cursor_plugin.py +python tools/check_claude_plugin.py +``` + +--- + +## 11. Document intake (maintainers only) + +Official Apollo documentation, such as the Apollo 68080 Programmer's +Reference Manual, enters the knowledge base through document intake. Only +the maintainers (WDrijver and TuKo1982, the default owners in +`.github/CODEOWNERS.base`) use this route. + +**The original document is leading**, unless the intake PR states otherwise. +Updates to the original are expected, and each one goes through the intake +steps again. Never edit generated files by hand: change the original and +regenerate. + +### Steps + +1. Add or update the original in `sources/official/`, in an editable format + such as ODT. PDF is a last resort. +2. Convert it with a converter script in `tools/intake/`, one per document + (for example `tools/intake/prm68080.py`). The script does the conversion, + the optimization for AI and the split, so an update of the original is + regenerated the same way. Use only the Python standard library. +3. The script splits the result into knowledge base files in the right + pillar (see "Optimized for AI" below). Every generated file gets: + - `origin: official` + - `owner`: a maintainer + - `status: draft` + - `generated_from: sources/official/` +4. Open a PR. The maintainer checks the conversion against the original and + sets `status: reviewed` in a generated file when it is correct. The + converter keeps that status as long as the file's content stays the same, + and generates the file as `draft` again when its content changes. +5. On an update of the original: replace it in `sources/official/`, run the + converter, and review the diff of the generated files in the PR. CI fails + when the generated files do not match the original + (`tools/intake/