bdgscotland/c64-kb

Commodore 64 knowledge base for AI-assisted development — Qdrant vector search + FalkorDB knowledge graph, served over MCP

TypeScript

0

6 commits

updated Sep 17, 2026

See the code

README

c64-kb — Commodore 64 knowledge base for AI-assisted demo and game development

c64-kb — Commodore 64 knowledge base for AI-assisted demo and game development

A shared reference KB served via MCP. Combines Qdrant vector search with FalkorDB knowledge graph over C64 hardware, techniques, toolchains, and pitfalls. Designed to power AI agent loops that design and build C64 demos and games.


The pitch

LLMs trained on public C64 code suffer two compounding problems: their training data skews heavily toward cc65 patterns (which are common on GitHub but not idiomatic for demo-quality work), and timing claims are routinely wrong — raster splits at incorrect scanlines, sprite-multiplex cycle counts that do not fit in the badline window, SID filter cutoffs that differ between chip revisions. A model hallucinating cycle counts will produce code that assembles cleanly and crashes at runtime.

c64-kb counters this with a curated, structured reference. 70+ markdown docs are chunked and embedded into Qdrant for semantic retrieval, and the entities within them — registers, KERNAL routines, memory regions, techniques, recipes, pitfalls, and crash patterns — are materialized into a FalkorDB knowledge graph. The graph captures relationships that flat search misses: which registers a technique uses, which pitfalls it triggers, which recipes implement it, whether two techniques share a register in a conflicting way.

The intended consumers are two kinds: an autonomous agent loop (ingest a brief, synthesize a technique stack, generate code, iterate with vice-mcp and sim6502) and a human-in-the-loop developer using Claude Code who wants accurate, structured answers about C64 hardware and idioms rather than training-data guesses.


Current state

ItemValue
Phases complete0–6 + 7a
MCP tools24
FalkorDB nodes550
FalkorDB edges989
Qdrant chunks2413 (across 74 markdown files)
Technique nodes73 (10 categories)
Pitfall nodes41
CrashPattern nodes15
Recipe nodes17
KERNAL routines39
Tests121 passing
LicenseBSD-3-Clause

Quick start

You need Node.js 22+, Docker, and Ollama with mxbai-embed-large pulled. Ollama is optional: without it, search falls back to keyword-only and the graph is unaffected.

# Start backing services (Qdrant + FalkorDB)
docker compose up -d

# Install and build
npm install
npm run build

# Hydrate the KB (first time only; idempotent thereafter)
npm run ingest

# Verify services and content
npx c64-kb health

# Start the MCP server (for Claude Code or other MCP clients)
npm run dev:serve

The repo ships a .mcp.json at the root. When you open this repository in Claude Code it auto-discovers and connects to the MCP server without any manual wiring.


Connecting another project

To wire c64-kb as an MCP server from a different repository, add .mcp.json to that project's root:

{
  "mcpServers": {
    "c64-kb": {
      "type": "stdio",
      "command": "node",
      "args": ["/absolute/path/to/c64-kb/dist/cli.js", "serve"]
    }
  }
}

Substitute the real absolute path on your machine. The server must already be built (npm run build) before connecting.

A templates/ directory (scaffolded in parallel as templates/c64-demo-starter and templates/c64-game-starter) provides ready-to-clone starting points that already include the .mcp.json wiring.


MCP tools

ToolPurpose
c64_healthService health snapshot (Qdrant / FalkorDB / Ollama / analytics)
c64_searchHybrid semantic + keyword search across the KB
c64_ingest_docIngest a single markdown file at runtime (live add)

Hardware reference

ToolPurpose
c64_lookup_registerStructured register lookup by name (D011) or address
c64_lookup_kernalKERNAL routine lookup with paired-routine edges
c64_memory_mapMemory region lookup by address ($0400 or 1024)
c64_lookup_opcode6510 opcode lookup (legal + illegal)
c64_pal_ntsc_diffPAL vs NTSC differences scoped by topic

Toolchain

ToolPurpose
c64_toolchain_hintIdiomatic snippet for a (toolchain, intent) pair. Defaults to Oscar64 when toolchain is omitted (bias enforcer).

Recipes and techniques

ToolPurpose
c64_recipe_lookupStructured Recipe lookup by canonical name (e.g. oscar64-stable-raster-irq)
c64_recipes_forList recipes filtered by toolchain / region / technique / file format
c64_technique_lookupTechnique lookup with USES Registers/KernalRoutines + implementing recipes + REQUIRES_REGION
c64_techniques_forList techniques filtered by category / chip / region / register / recipe

Compatibility and timing

ToolPurpose
c64_check_compatibilityGraph-traversal conflict detection across a list of techniques (shared register / KERNAL / region mismatch)
c64_timing_budgetPer-scanline + per-frame cycle math for a technique on PAL or NTSC

Pitfalls and failure analysis

ToolPurpose
c64_pitfalls_forPitfalls triggered by a register, KERNAL routine, or technique name
c64_failure_diagnoseMatch a symptom description against CrashPattern nodes (relevance ranked)

Synthesis and briefings

ToolPurpose
c64_demo_briefingSynthesise techniques + pitfalls + toolchain split + build order for a demo brief
c64_game_briefingSame synthesis for a game brief; genre hint selects archetype recipe as scaffold

Self-improvement (Phase 7a)

ToolPurpose
c64_coverageReport coverage across technique categories, flag under-documented areas
c64_suggest_linksSuggest missing graph edges for a named node
c64_report_gapRecord a knowledge gap for triage

Resources and prompts

11 Resources are exposed at c64:// URIs:

c64://memory-map          c64://kernal-jumptable      c64://vic-registers
c64://sid-registers       c64://cia-registers          c64://6510-opcodes
c64://illegal-opcodes     c64://techniques-index       c64://recipes-index
c64://pitfalls-index      c64://crash-patterns

2 Prompts: c64_demo_brief and c64_game_brief.


Architecture

Full system diagrams and data-flow documentation: docs/ARCHITECTURE.md. Graph schema (11 node types, 12 edge types): docs/ONTOLOGY.md.

Components

TypeScript MCP server (Node 24+, ES2022 modules). Tool logic lives in src/tools/*.ts as pure functions returning strings. Both the CLI and the MCP server call the same functions — the CLI for terminal use and hooks, the MCP server as a thin wrapper mapping MCP calls to those functions.

Qdrant (Docker, host port 7333): dense + sparse (BM25) hybrid vector store. Collection c64_docs. Embeddings are 768-dimensional via mxbai-embed-large on Ollama. Falls back to keyword-only search when Ollama is unavailable.

FalkorDB (Docker, host port 7379): Redis-compatible knowledge graph. Graph name c64. 11 node types (Chip, Register, KernalRoutine, MemoryRegion, Opcode, Technique, Recipe, Pitfall, CrashPattern, ToolRecipe, Region) and 12 edge types. Range indexes on all primary keys. Two-pass ingest: node creation in pass 1, edge linking in pass 2, so walk order does not affect edge correctness.

Ollama (host, port 11434): mxbai-embed-large for embeddings. Shared with amiga-kb if both are running.

SQLite (data/analytics.db): query analytics and gap detection. Records every tool call; surfaces queries with no results as gap candidates.

70+ markdown reference docs under docs/: the human-readable corpus that drives both vector chunks and graph entity extraction.

Ports

ServiceHost port
Qdrant REST7333
Qdrant gRPC7334
FalkorDB7379
Ollama (shared)11434
Dashboard3939 (Phase 7b, pending)

Ports are shifted from amiga-kb (6333/6334/6379) so both KBs can run in parallel.


Toolchain ranking

The toolchain ranking is locked as of 2026-05-16 and reflected throughout the KB content and the c64_toolchain_hint bias enforcer.

Primary: Oscar64. Modern C/C++ compiler targeting 6502. Most recipes in the KB are written for Oscar64. The c64_toolchain_hint tool defaults to Oscar64 when no toolchain is specified. This is deliberate: LLM training data is saturated with cc65 patterns, which are workable but not idiomatic for demo-quality code. c64-kb exists in part to push models toward Oscar64 idioms.

Secondary: KickAssembler. Cycle-tight escape hatch for work where C-level abstraction costs too many cycles: stable raster IRQs, sprite multiplexers, FLI, scene-quality timing routines. Called from Oscar64 via external asm linking. Deep KickAssembler recipes are present alongside their Oscar64 equivalents.

Tertiary: cc65. Light coverage. Text-mode utilities and niche cases where cc65's large training-data corpus is the path of least resistance. Do not reach for cc65 for techniques requiring cycle precision.


Hardware target

Stock Commodore 64, PAL and NTSC.

The following are explicitly out of scope: C128, Mega65, SuperCPU, REU, Ultimate II+. The KB documents PAL/NTSC differences thoroughly (raster line counts, cycle budgets, timer values) but does not cover expanded hardware.


Boundaries with sibling tools

c64-kb is pure reference — it describes what code should be. It has no runtime or emulator access.

NeedTool
Memory inspection, screenshots, breakpoints, cycle countsvice-mcp
Unit testing C64 code without a full emulatorsim6502
Reference: what code should be, hardware semantics, pitfallsc64-kb (this repo)

The intended agent loop: c64-kb generates the brief and code scaffold; vice-mcp inspects runtime behaviour; sim6502 runs unit tests on hot paths.


Phase roadmap

PhaseDescriptionState
0Infrastructure (services, CLI, MCP server, ingest pipeline)complete
1Hardware foundation (VIC-II, SID, CIA, 6510, KERNAL, memory map, opcodes, PAL/NTSC)complete
2Toolchain reference + runtime docs + file formats + core recipescomplete
3Core techniques (raster, sprite, scroll, bitmap, memory banking)complete
4Advanced techniques + deep recipes (effects, SID music, CPU tricks, loaders/packers)complete
5Pitfalls + failure patterns + briefing toolscomplete
6Art/music production + design patternscomplete
7aAnalytics + self-improvement tools (coverage, suggest-links, report-gap)complete
7bDashboard UI (C64-native design, port 3939)pending
FutureDream/consolidation cycle, autonomous agent loop integration

Development

CommandDescription
npm run buildCompile TypeScript (tsc)
npm run devRun CLI via tsx (no build needed)
npm run dev:serveRun MCP server via tsx
npm run ingestHydrate KB from docs/ (idempotent)
npm run ingest -- --forceRe-ingest all docs, forcing hash refresh
npm testRun vitest (121 tests)
npx tsc --noEmitType check without emitting
./scripts/backup.shSnapshot all stateful data

Prerequisites

  • Node.js 22+
  • Docker (for Qdrant + FalkorDB)
  • Ollama with mxbai-embed-large pulled (optional — falls back to keyword-only search without it)

Contributing

Add new reference material by dropping a markdown file into docs/ and running:

npm run ingest -- --force

The ingest pipeline will chunk the file, embed it, upsert into Qdrant, and extract graph entities (registers, KERNAL routines, techniques, pitfalls, recipes) into FalkorDB.

For doc structure, follow the conventions files:

  • docs/CONVENTIONS-pitfalls.md — pitfall doc format
  • docs/CONVENTIONS-failures.md — failure pattern doc format
  • Other docs/CONVENTIONS-*.md — hardware, toolchain, recipe, technique conventions

Tests live in test/. Run npm test before committing. Run npx tsc --noEmit to catch type errors.


License

BSD-3-Clause.

Contributors

bdgscotland

6 commits

bdgscotland/c64-kb

Commodore 64 knowledge base for AI-assisted development — Qdrant vector search + FalkorDB knowledge graph, served over MCP

TypeScript

0

6 commits

updated Sep 17, 2026

See the code

README

c64-kb — Commodore 64 knowledge base for AI-assisted demo and game development

c64-kb — Commodore 64 knowledge base for AI-assisted demo and game development

A shared reference KB served via MCP. Combines Qdrant vector search with FalkorDB knowledge graph over C64 hardware, techniques, toolchains, and pitfalls. Designed to power AI agent loops that design and build C64 demos and games.


The pitch

LLMs trained on public C64 code suffer two compounding problems: their training data skews heavily toward cc65 patterns (which are common on GitHub but not idiomatic for demo-quality work), and timing claims are routinely wrong — raster splits at incorrect scanlines, sprite-multiplex cycle counts that do not fit in the badline window, SID filter cutoffs that differ between chip revisions. A model hallucinating cycle counts will produce code that assembles cleanly and crashes at runtime.

c64-kb counters this with a curated, structured reference. 70+ markdown docs are chunked and embedded into Qdrant for semantic retrieval, and the entities within them — registers, KERNAL routines, memory regions, techniques, recipes, pitfalls, and crash patterns — are materialized into a FalkorDB knowledge graph. The graph captures relationships that flat search misses: which registers a technique uses, which pitfalls it triggers, which recipes implement it, whether two techniques share a register in a conflicting way.

The intended consumers are two kinds: an autonomous agent loop (ingest a brief, synthesize a technique stack, generate code, iterate with vice-mcp and sim6502) and a human-in-the-loop developer using Claude Code who wants accurate, structured answers about C64 hardware and idioms rather than training-data guesses.


Current state

ItemValue
Phases complete0–6 + 7a
MCP tools24
FalkorDB nodes550
FalkorDB edges989
Qdrant chunks2413 (across 74 markdown files)
Technique nodes73 (10 categories)
Pitfall nodes41
CrashPattern nodes15
Recipe nodes17
KERNAL routines39
Tests121 passing
LicenseBSD-3-Clause

Quick start

You need Node.js 22+, Docker, and Ollama with mxbai-embed-large pulled. Ollama is optional: without it, search falls back to keyword-only and the graph is unaffected.

# Start backing services (Qdrant + FalkorDB)
docker compose up -d

# Install and build
npm install
npm run build

# Hydrate the KB (first time only; idempotent thereafter)
npm run ingest

# Verify services and content
npx c64-kb health

# Start the MCP server (for Claude Code or other MCP clients)
npm run dev:serve

The repo ships a .mcp.json at the root. When you open this repository in Claude Code it auto-discovers and connects to the MCP server without any manual wiring.


Connecting another project

To wire c64-kb as an MCP server from a different repository, add .mcp.json to that project's root:

{
  "mcpServers": {
    "c64-kb": {
      "type": "stdio",
      "command": "node",
      "args": ["/absolute/path/to/c64-kb/dist/cli.js", "serve"]
    }
  }
}

Substitute the real absolute path on your machine. The server must already be built (npm run build) before connecting.

A templates/ directory (scaffolded in parallel as templates/c64-demo-starter and templates/c64-game-starter) provides ready-to-clone starting points that already include the .mcp.json wiring.


MCP tools

ToolPurpose
c64_healthService health snapshot (Qdrant / FalkorDB / Ollama / analytics)
c64_searchHybrid semantic + keyword search across the KB
c64_ingest_docIngest a single markdown file at runtime (live add)

Hardware reference

ToolPurpose
c64_lookup_registerStructured register lookup by name (D011) or address
c64_lookup_kernalKERNAL routine lookup with paired-routine edges
c64_memory_mapMemory region lookup by address ($0400 or 1024)
c64_lookup_opcode6510 opcode lookup (legal + illegal)
c64_pal_ntsc_diffPAL vs NTSC differences scoped by topic

Toolchain

ToolPurpose
c64_toolchain_hintIdiomatic snippet for a (toolchain, intent) pair. Defaults to Oscar64 when toolchain is omitted (bias enforcer).

Recipes and techniques

ToolPurpose
c64_recipe_lookupStructured Recipe lookup by canonical name (e.g. oscar64-stable-raster-irq)
c64_recipes_forList recipes filtered by toolchain / region / technique / file format
c64_technique_lookupTechnique lookup with USES Registers/KernalRoutines + implementing recipes + REQUIRES_REGION
c64_techniques_forList techniques filtered by category / chip / region / register / recipe

Compatibility and timing

ToolPurpose
c64_check_compatibilityGraph-traversal conflict detection across a list of techniques (shared register / KERNAL / region mismatch)
c64_timing_budgetPer-scanline + per-frame cycle math for a technique on PAL or NTSC

Pitfalls and failure analysis

ToolPurpose
c64_pitfalls_forPitfalls triggered by a register, KERNAL routine, or technique name
c64_failure_diagnoseMatch a symptom description against CrashPattern nodes (relevance ranked)

Synthesis and briefings

ToolPurpose
c64_demo_briefingSynthesise techniques + pitfalls + toolchain split + build order for a demo brief
c64_game_briefingSame synthesis for a game brief; genre hint selects archetype recipe as scaffold

Self-improvement (Phase 7a)

ToolPurpose
c64_coverageReport coverage across technique categories, flag under-documented areas
c64_suggest_linksSuggest missing graph edges for a named node
c64_report_gapRecord a knowledge gap for triage

Resources and prompts

11 Resources are exposed at c64:// URIs:

c64://memory-map          c64://kernal-jumptable      c64://vic-registers
c64://sid-registers       c64://cia-registers          c64://6510-opcodes
c64://illegal-opcodes     c64://techniques-index       c64://recipes-index
c64://pitfalls-index      c64://crash-patterns

2 Prompts: c64_demo_brief and c64_game_brief.


Architecture

Full system diagrams and data-flow documentation: docs/ARCHITECTURE.md. Graph schema (11 node types, 12 edge types): docs/ONTOLOGY.md.

Components

TypeScript MCP server (Node 24+, ES2022 modules). Tool logic lives in src/tools/*.ts as pure functions returning strings. Both the CLI and the MCP server call the same functions — the CLI for terminal use and hooks, the MCP server as a thin wrapper mapping MCP calls to those functions.

Qdrant (Docker, host port 7333): dense + sparse (BM25) hybrid vector store. Collection c64_docs. Embeddings are 768-dimensional via mxbai-embed-large on Ollama. Falls back to keyword-only search when Ollama is unavailable.

FalkorDB (Docker, host port 7379): Redis-compatible knowledge graph. Graph name c64. 11 node types (Chip, Register, KernalRoutine, MemoryRegion, Opcode, Technique, Recipe, Pitfall, CrashPattern, ToolRecipe, Region) and 12 edge types. Range indexes on all primary keys. Two-pass ingest: node creation in pass 1, edge linking in pass 2, so walk order does not affect edge correctness.

Ollama (host, port 11434): mxbai-embed-large for embeddings. Shared with amiga-kb if both are running.

SQLite (data/analytics.db): query analytics and gap detection. Records every tool call; surfaces queries with no results as gap candidates.

70+ markdown reference docs under docs/: the human-readable corpus that drives both vector chunks and graph entity extraction.

Ports

ServiceHost port
Qdrant REST7333
Qdrant gRPC7334
FalkorDB7379
Ollama (shared)11434
Dashboard3939 (Phase 7b, pending)

Ports are shifted from amiga-kb (6333/6334/6379) so both KBs can run in parallel.


Toolchain ranking

The toolchain ranking is locked as of 2026-05-16 and reflected throughout the KB content and the c64_toolchain_hint bias enforcer.

Primary: Oscar64. Modern C/C++ compiler targeting 6502. Most recipes in the KB are written for Oscar64. The c64_toolchain_hint tool defaults to Oscar64 when no toolchain is specified. This is deliberate: LLM training data is saturated with cc65 patterns, which are workable but not idiomatic for demo-quality code. c64-kb exists in part to push models toward Oscar64 idioms.

Secondary: KickAssembler. Cycle-tight escape hatch for work where C-level abstraction costs too many cycles: stable raster IRQs, sprite multiplexers, FLI, scene-quality timing routines. Called from Oscar64 via external asm linking. Deep KickAssembler recipes are present alongside their Oscar64 equivalents.

Tertiary: cc65. Light coverage. Text-mode utilities and niche cases where cc65's large training-data corpus is the path of least resistance. Do not reach for cc65 for techniques requiring cycle precision.


Hardware target

Stock Commodore 64, PAL and NTSC.

The following are explicitly out of scope: C128, Mega65, SuperCPU, REU, Ultimate II+. The KB documents PAL/NTSC differences thoroughly (raster line counts, cycle budgets, timer values) but does not cover expanded hardware.


Boundaries with sibling tools

c64-kb is pure reference — it describes what code should be. It has no runtime or emulator access.

NeedTool
Memory inspection, screenshots, breakpoints, cycle countsvice-mcp
Unit testing C64 code without a full emulatorsim6502
Reference: what code should be, hardware semantics, pitfallsc64-kb (this repo)

The intended agent loop: c64-kb generates the brief and code scaffold; vice-mcp inspects runtime behaviour; sim6502 runs unit tests on hot paths.


Phase roadmap

PhaseDescriptionState
0Infrastructure (services, CLI, MCP server, ingest pipeline)complete
1Hardware foundation (VIC-II, SID, CIA, 6510, KERNAL, memory map, opcodes, PAL/NTSC)complete
2Toolchain reference + runtime docs + file formats + core recipescomplete
3Core techniques (raster, sprite, scroll, bitmap, memory banking)complete
4Advanced techniques + deep recipes (effects, SID music, CPU tricks, loaders/packers)complete
5Pitfalls + failure patterns + briefing toolscomplete
6Art/music production + design patternscomplete
7aAnalytics + self-improvement tools (coverage, suggest-links, report-gap)complete
7bDashboard UI (C64-native design, port 3939)pending
FutureDream/consolidation cycle, autonomous agent loop integration

Development

CommandDescription
npm run buildCompile TypeScript (tsc)
npm run devRun CLI via tsx (no build needed)
npm run dev:serveRun MCP server via tsx
npm run ingestHydrate KB from docs/ (idempotent)
npm run ingest -- --forceRe-ingest all docs, forcing hash refresh
npm testRun vitest (121 tests)
npx tsc --noEmitType check without emitting
./scripts/backup.shSnapshot all stateful data

Prerequisites

  • Node.js 22+
  • Docker (for Qdrant + FalkorDB)
  • Ollama with mxbai-embed-large pulled (optional — falls back to keyword-only search without it)

Contributing

Add new reference material by dropping a markdown file into docs/ and running:

npm run ingest -- --force

The ingest pipeline will chunk the file, embed it, upsert into Qdrant, and extract graph entities (registers, KERNAL routines, techniques, pitfalls, recipes) into FalkorDB.

For doc structure, follow the conventions files:

  • docs/CONVENTIONS-pitfalls.md — pitfall doc format
  • docs/CONVENTIONS-failures.md — failure pattern doc format
  • Other docs/CONVENTIONS-*.md — hardware, toolchain, recipe, technique conventions

Tests live in test/. Run npm test before committing. Run npx tsc --noEmit to catch type errors.


License

BSD-3-Clause.

Contributors

bdgscotland

6 commits

Languages

TypeScript

91.4%

C

2.8%

Assembly

2.4%

Shell

1.7%

Makefile

1.6%