c64bridge 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/.github/prompts/README.md +6 -0
  2. package/.github/prompts/assembly-routine-session.prompt.md +13 -0
  3. package/.github/prompts/basic-program-session.prompt.md +13 -0
  4. package/.github/prompts/drive-management-session.prompt.md +13 -0
  5. package/.github/prompts/petscii-art-session.prompt.md +13 -0
  6. package/.github/prompts/play-classic-game.prompt.md +13 -0
  7. package/.github/prompts/sid-music-session.prompt.md +13 -0
  8. package/AGENTS.md +173 -0
  9. package/LICENSE +339 -0
  10. package/README.md +582 -0
  11. package/data/README.md +16 -0
  12. package/data/api/basic-api-spec.md +154 -0
  13. package/data/api/kernal-api-spec.md +68 -0
  14. package/data/assembly/assembly-spec.md +196 -0
  15. package/data/assembly/examples/effects/sinewave.asm +5 -0
  16. package/data/assembly/examples/graphics/sprite/mover.asm +15 -0
  17. package/data/assembly/examples/sid-file-structure.md +8 -0
  18. package/data/assembly/examples/sid-overview.md +11 -0
  19. package/data/audio/examples/Biosphere.sid +0 -0
  20. package/data/audio/sid-file-structure.md +91 -0
  21. package/data/audio/sid-programming-best-practices.md +198 -0
  22. package/data/audio/sid-spec.md +166 -0
  23. package/data/audio/sidwave.md +131 -0
  24. package/data/audio/sidwave.schema.json +64 -0
  25. package/data/basic/basic-spec.md +230 -0
  26. package/data/basic/examples/audio/alle-meine-entchen-expressive.bas +41 -0
  27. package/data/basic/examples/audio/c-major-scale-pleasant.bas +29 -0
  28. package/data/basic/examples/io/joystick.bas +5 -0
  29. package/data/basic/examples/video/bounce.bas +8 -0
  30. package/data/basic/examples/video/entchen-petscii.bas +16 -0
  31. package/data/basic/examples/video/hello-world.bas +4 -0
  32. package/data/basic/examples/video/wave.bas +7 -0
  33. package/data/context/bootstrap.md +148 -0
  34. package/data/context/chat.md +36 -0
  35. package/data/drive/drive-spec.md +215 -0
  36. package/data/embeddings_asm.json +1 -0
  37. package/data/embeddings_basic.json +1 -0
  38. package/data/embeddings_hardware.json +1 -0
  39. package/data/embeddings_mixed.json +1 -0
  40. package/data/embeddings_other.json +1 -0
  41. package/data/io/cia-spec.md +115 -0
  42. package/data/io/io-spec.md +124 -0
  43. package/data/memory/kernal-memory-map.md +227 -0
  44. package/data/memory/low-memory-map.md +133 -0
  45. package/data/memory/memory-map.md +186 -0
  46. package/data/printer/printer-commodore-bitmap.md +31 -0
  47. package/data/printer/printer-commodore.md +28 -0
  48. package/data/printer/printer-epson-bitmap.md +29 -0
  49. package/data/printer/printer-epson.md +30 -0
  50. package/data/printer/printer-prompts.md +29 -0
  51. package/data/printer/printer-spec.md +180 -0
  52. package/data/video/character-set.csv +257 -0
  53. package/data/video/vic-spec.md +276 -0
  54. package/dist/assemblyConverter.js +1299 -0
  55. package/dist/audio/record_and_analyze_audio.js +292 -0
  56. package/dist/basicConverter.js +193 -0
  57. package/dist/bootstrap/stdio-logger.js +32 -0
  58. package/dist/c64Client.js +1052 -0
  59. package/dist/chargen.js +197 -0
  60. package/dist/config.js +142 -0
  61. package/dist/context.js +157 -0
  62. package/dist/device.js +413 -0
  63. package/dist/index.js +7 -0
  64. package/dist/knowledge.js +454 -0
  65. package/dist/logger.js +182 -0
  66. package/dist/loggingHttpClient.js +88 -0
  67. package/dist/mcp-server.js +426 -0
  68. package/dist/petscii.js +135 -0
  69. package/dist/petsciiArt.js +356 -0
  70. package/dist/platform.js +82 -0
  71. package/dist/prompts/registry.js +560 -0
  72. package/dist/rag/discover.config.json +41 -0
  73. package/dist/rag/discover.js +401 -0
  74. package/dist/rag/embeddings.js +60 -0
  75. package/dist/rag/externalFetcher.js +934 -0
  76. package/dist/rag/indexer.js +770 -0
  77. package/dist/rag/init.js +139 -0
  78. package/dist/rag/knowledgeIndex.js +361 -0
  79. package/dist/rag/loggingRetriever.js +46 -0
  80. package/dist/rag/rateLimiter.js +127 -0
  81. package/dist/rag/retriever.js +74 -0
  82. package/dist/rag/sources.csv +31 -0
  83. package/dist/rag/types.js +5 -0
  84. package/dist/rag/urlUtils.js +38 -0
  85. package/dist/sidplayRunner.js +240 -0
  86. package/dist/sidwave.js +101 -0
  87. package/dist/sidwaveCompiler.js +329 -0
  88. package/dist/tools/audio.js +944 -0
  89. package/dist/tools/developer.js +515 -0
  90. package/dist/tools/errors.js +59 -0
  91. package/dist/tools/graphics.js +469 -0
  92. package/dist/tools/machineControl.js +267 -0
  93. package/dist/tools/memory.js +224 -0
  94. package/dist/tools/printer.js +482 -0
  95. package/dist/tools/programRunners.js +315 -0
  96. package/dist/tools/rag.js +153 -0
  97. package/dist/tools/registry.js +58 -0
  98. package/dist/tools/responses.js +36 -0
  99. package/dist/tools/schema.js +304 -0
  100. package/dist/tools/storage.js +740 -0
  101. package/dist/tools/streaming.js +132 -0
  102. package/dist/tools/types.js +99 -0
  103. package/dist/viceRunner.js +239 -0
  104. package/doc/MCP_SETUP.md +153 -0
  105. package/doc/README.md +7 -0
  106. package/doc/developer.md +312 -0
  107. package/doc/img/logo.png +0 -0
  108. package/doc/img/prompts/duck_petscii.png +0 -0
  109. package/doc/img/prompts/duck_song.png +0 -0
  110. package/doc/img/vscode/vscode-copilot-c64-chat-mode.png +0 -0
  111. package/doc/img/vscode/vscode-copilot-hello-world.png +0 -0
  112. package/doc/prompts/README.md +96 -0
  113. package/doc/prompts/user-prompt-ideas.md +147 -0
  114. package/doc/rest/c64-openapi.yaml +979 -0
  115. package/doc/rest/c64-rest-api.md +106 -0
  116. package/doc/troubleshooting-mcp.md +177 -0
  117. package/generated/c64/index.js +857 -0
  118. package/mcp.json +106 -0
  119. package/package.json +79 -0
  120. package/scripts/c64-cli.mjs +142 -0
  121. package/scripts/c64-tool.sh +83 -0
  122. package/scripts/check-package.mjs +89 -0
  123. package/scripts/cli.js +61 -0
  124. package/scripts/fetch-external-sources.mjs +67 -0
  125. package/scripts/generate-changelog.mjs +131 -0
  126. package/scripts/postbuild.mjs +101 -0
  127. package/scripts/prepare-release.mjs +58 -0
  128. package/scripts/rag-rebuild.mjs +53 -0
  129. package/scripts/register-ts-node.mjs +6 -0
  130. package/scripts/run-mcp-check.sh +104 -0
  131. package/scripts/run-tests.mjs +195 -0
  132. package/scripts/sid2wav.sh +94 -0
  133. package/scripts/smoke-run.sh +65 -0
  134. package/scripts/start-mock-c64.mjs +51 -0
  135. package/scripts/start-mock.mjs +31 -0
  136. package/scripts/start.mjs +72 -0
  137. package/scripts/update-readme.ts +164 -0
  138. package/scripts/verify-package.mjs +147 -0
@@ -0,0 +1,312 @@
1
+ # Developer Guide
2
+
3
+ Concise reference for contributors working on the MCP server that bridges LLM workflows with Commodore 64 Ultimate hardware.
4
+
5
+ ## Project Layout
6
+
7
+ - `src/` β€” core TypeScript sources for the MCP server.
8
+ - `mcp-server.ts` wires tools, resources, and prompts into the stdio server entry point imported by `index.ts`.
9
+ - Support modules such as `c64Client.ts`, `device.ts`, `viceRunner.ts`, `sidplayRunner.ts`, `loggingHttpClient.ts`, and `logger.ts` isolate hardware access and observability.
10
+ - Domain folders include:
11
+ - `audio/` for MCP-driven audio capture and analysis.
12
+ - `rag/` for indexing, retrieval, and external source discovery.
13
+ - `tools/` for individual MCP tool implementations plus decorators.
14
+ - `prompts/` for authored prompt definitions surfaced to clients.
15
+ - `types/` and `context.ts` for shared type definitions and session context helpers.
16
+ - `petscii*.ts`, `basicConverter.ts`, `assemblyConverter.ts`, and `chargen.ts` for Commodore-specific encoders and assets.
17
+ - `knowledge.ts` for resource wiring and `config.ts` for environment resolution.
18
+ - `scripts/` β€” Node/TypeScript utilities for starting the server, rebuilding docs, running tests, regenerating embeddings, packaging releases, and providing the CLI shim used by `c64bridge`.
19
+ - `doc/` β€” documentation set (developer guide, REST references, troubleshooting, task notes).
20
+ - `data/` β€” knowledge corpus, embeddings, and example programs consumed by the RAG pipeline.
21
+ - `test/` β€” Node test suites plus mock server helpers; includes real-hardware toggles.
22
+ - `generated/` β€” OpenAPI-derived REST client (`npm run api:generate`).
23
+ - `scripts/cli.js` and `dist/` β€” compiled CLI faΓ§ade and build artifacts produced by `npm run build` / npm packaging.
24
+ - `artifacts/` β€” gitignored output for PRG conversions, test embeddings, and other scratch products.
25
+ - `external/` β€” optional fetched corpora included in the RAG index.
26
+
27
+ Key documentation:
28
+
29
+ - `data/basic/basic-spec.md` β€” BASIC tokenisation rules used by the converter.
30
+ - `doc/rest/c64-rest-api.md` β€” Summary of the Ultimate REST API.
31
+ - `doc/rest/c64-openapi.yaml` β€” Machine-readable API schema for mocking and generators.
32
+ - `doc/tasks/use-mcp-sdk.md` β€” Step-by-step migration log with requirements.
33
+
34
+ ## Prerequisites
35
+
36
+ - Node.js 18+ (20+ recommended); ESM TypeScript via `ts-node`.
37
+ - npm for dependency management.
38
+ - Optional: Ultimate 64 hardware (or compatible REST device) for real tests.
39
+
40
+ ## Setup
41
+
42
+ ```bash
43
+ npm install
44
+ ```
45
+
46
+ Configuration resolution (first match wins):
47
+
48
+ 1. Load the file referenced by `C64BRIDGE_CONFIG` (when set); if unset, use `~/.c64bridge.json`.
49
+ 2. If missing, fall back to `.c64bridge.json` at the repo root.
50
+ 3. Otherwise, default to `host=c64u`, `port=80`.
51
+
52
+ `loadConfig()` normalises IPv6 literals, coerces legacy keys (`c64_host`, `c64_ip`), and caches the resolved structure for subsequent calls.
53
+
54
+ ## Useful npm Scripts
55
+
56
+ **Core server flows**
57
+
58
+ - `npm start` launches the stdio MCP server with hot TypeScript support (`scripts/start.mjs`).
59
+ - `npm run mcp` runs the TypeScript entry point directly via `ts-node`; `npm run mcp:build` compiles to `dist/` first, then executes the bundled server for parity testing.
60
+ - `npm run build` compiles TypeScript, runs post-build normalization, and regenerates `README.md` tool/resource tables via `scripts/update-readme.ts`.
61
+ - `npm run lint` maps to `npm run check` for quick consistency with CI.
62
+
63
+ **Quality gates**
64
+
65
+ - `npm test` drives `scripts/run-tests.mjs` against the mock C64 server; pass `-- --real [--base-url=http://host]` to exercise actual hardware.
66
+ - `npm run check` executes `npm run build` followed by the mock test suite; `npm run coverage` wraps the same runner with c8.
67
+ - `npm run check:package` validates packaging metadata, while `npm run check:run-local` / `npm run check:run-npm` execute `scripts/run-mcp-check.sh` against local and packaged installs.
68
+
69
+ **RAG workflows**
70
+
71
+ - `npm run rag:rebuild` (alias `npm run build:rag`) rebuilds embeddings; `npm run rag:fetch` pulls external corpora declared in `src/rag/sources.csv`.
72
+ - `npm run rag:discover` performs experimental GitHub discovery using `src/rag/discover.ts` (requires credentials in `.env`).
73
+
74
+ **Tooling and release**
75
+
76
+ - `npm run c64:tool` opens the interactive helper for PRG conversion and upload; `npm run api:generate` refreshes the generated REST client.
77
+ - `npm run changelog:generate` distills Conventional Commit history, and `npm run release:prepare -- <semver>` orchestrates version bumps plus manifest regeneration.
78
+
79
+ Invoke `node --import ./scripts/register-ts-node.mjs scripts/update-readme.ts` directly when you need to refresh documentation tables without a full rebuild.
80
+
81
+ The test driver in `scripts/run-tests.mjs` accepts additional flags: `--mock` (default) to use `test/mockC64Server.mjs`, `--real` to target hardware (`C64_TEST_TARGET=real`), and `--base-url` to override the REST endpoint during real runs.
82
+
83
+ ## MCP Architecture
84
+
85
+ The server is organised around three core surfaces exposed through the MCP SDK: **tools**, **resources**, and **prompts**. `src/mcp-server.ts` wires these registries together, loads configuration, and enforces platform compatibility.
86
+
87
+ ```text
88
+ src/mcp-server.ts
89
+ β”œβ”€β”€ toolRegistry (src/tools/registry.ts)
90
+ β”‚ └── Domain modules (audio, graphics, memory, printer, rag, etc.)
91
+ β”œβ”€β”€ knowledge resources (src/rag/knowledgeIndex.ts)
92
+ β”‚ └── data/ and doc/ references surfaced via c64:// URIs
93
+ β”œβ”€β”€ prompt registry (src/prompts/registry.ts)
94
+ β”‚ └── Authored prompt definitions under .github/prompts and doc/prompts
95
+ └── platform awareness (src/platform.ts)
96
+ └── Evaluates backend compatibility (C64U vs VICE) for each tool
97
+ ```
98
+
99
+ `scripts/start.mjs` detects whether TypeScript sources are available and launches `src/mcp-server.ts` (via `src/index.ts`), ensuring both local development and packaged CLI usage share the same entry point.
100
+
101
+ ```mermaid
102
+ flowchart TD
103
+ subgraph "MCP Server (stdio)"
104
+ Stdio["src/mcp-server.ts"]
105
+ ToolRegistry["Tool metadata (src/tools/*)"]
106
+ PromptRegistry["Prompt registry (src/prompts/*)"]
107
+ Resources["Knowledge resources (src/rag/knowledgeIndex.ts)"]
108
+ end
109
+
110
+ subgraph "Generated SDK"
111
+ Api["generated/c64/index.ts"]
112
+ end
113
+
114
+ Stdio --> ToolRegistry
115
+ Stdio --> PromptRegistry
116
+ Stdio --> Resources
117
+ ToolRegistry --> Client["C64Client (src/c64Client.ts)"]
118
+ ToolRegistry --> BasicConverter["basicConverter.ts"]
119
+ ToolRegistry --> Rag["RAG helpers (src/rag/*)"]
120
+ Client --> Api
121
+ Api -->|HTTP| UltimateAPI["Ultimate 64 REST API"]
122
+ ```
123
+
124
+ ```mermaid
125
+ flowchart LR
126
+ OpenAPI["doc/rest/c64-openapi.yaml"]
127
+ Generator["npm run api:generate"]
128
+ Generated["generated/c64/index.ts"]
129
+ Facade["src/c64Client.ts"]
130
+
131
+ OpenAPI --> Generator --> Generated --> Facade
132
+ ```
133
+
134
+ ## MCP Server Tips
135
+
136
+ - Preferred transport is stdio (`src/mcp-server.ts`); `src/index.ts` simply imports this module so CLI and npm consumers share the same entry point.
137
+ - The legacy Fastify HTTP server now lives in `src/http-server.ts.backup`. Keep it untouched unless you need to resurrect HTTP compatibility for debugging.
138
+ - MCP tools enforce platform compatibility via `src/platform.ts`; run `npm test` to cover both metadata and runtime enforcement.
139
+ - Keep REST interactions isolated in `src/c64Client.ts` for easy mocking.
140
+
141
+ ## Testing Notes
142
+
143
+ - Node’s built-in test runner (`node --test`) is wrapped by `scripts/run-tests.mjs`.
144
+ - Use `npm run coverage` (c8) to capture coverage without double-running tests.
145
+ - `test/basicConverter.test.mjs`: byte-level PRG output validation.
146
+ - `test/c64Client.test.mjs`: REST client and mock-server integration; `--real` toggles hardware.
147
+ - `test/suites/mcpServer*.mjs`: End-to-end MCP surface coverage (tools, resources, prompts).
148
+
149
+ ## Fast Development Workflow
150
+
151
+ 1. `npm run build` to validate types.
152
+ 2. `npm test` against the mock server.
153
+ 3. `npm test -- --real` when hardware is available.
154
+ 4. Update `doc/` and keep `doc/rest/c64-openapi.yaml` in sync with code.
155
+
156
+ ## Release Workflow
157
+
158
+ 1. Create a short-lived branch (for example `release/X.Y.Z`) from the target commit.
159
+ 2. Run `npm run release:prepare -- <semver>` to bump versions (`major`, `minor`, `patch`, or explicit like `0.2.0`). This updates `package.json`, `package-lock.json`, `mcp.json`, and prepends a new section to `CHANGELOG.md` from commit messages since the last tag.
160
+ 3. Review and commit the changes, then open a pull request.
161
+ 4. After the PR merges, create and push the tag (`git tag X.Y.Z && git push origin X.Y.Z`) or use the GitHub release UI; CI will now see matching versions.
162
+ 5. Perform the publish/release steps that rely on the tag (npm publish, GitHub release, etc.).
163
+
164
+ ### Commit Messages and CHANGELOG Generation
165
+
166
+ This repository uses a light [Conventional Commits](https://www.conventionalcommits.org) style to generate [`CHANGELOG.md`](https://github.com/chrisgleissner/c64bridge/blob/main/CHANGELOG.md) entries (aligned with [Keep a Changelog](https://keepachangelog.com/)) during `release:prepare`:
167
+
168
+ - Format: `type(scope)?: subject`.
169
+ - Examples:
170
+ - `feat: add SID triangle-wave example`
171
+ - `fix(petscii): correct chargen mapping for inverted glyphs`
172
+ - `docs: clarify health checks (/health vs /tools/version)`
173
+ - `refactor: extract audio analyzer helpers`
174
+ - `perf: speed up RAG embedding load`
175
+ - `chore(ci): pin setup-node to v4`
176
+ - Breaking changes: add a `!` after the type, e.g., `feat!: remove deprecated /tools/info fallback`.
177
+
178
+ During a release prep, the script groups commits since the previous tag into sections:
179
+
180
+ - Features (`feat`)
181
+ - Bug Fixes (`fix`)
182
+ - Performance (`perf`)
183
+ - Refactoring (`refactor`)
184
+ - Documentation (`docs`)
185
+ - Tests (`test`)
186
+ - Chores (`build`, `ci`, `chore`)
187
+ - Other (non-conforming subjects)
188
+
189
+ Tips:
190
+
191
+ - Prefer concise subjects; the changelog lists the subject plus the short SHA.
192
+ - Skip β€œMerge …” subjects; they are filtered automatically.
193
+ - Run `npm run changelog:generate` to regenerate locally; it prepends a new section for the current `package.json` version using commits since the last tag.
194
+
195
+
196
+ ## Local RAG
197
+
198
+ ### Overview
199
+
200
+ - The retrieval-augmented generation subsystem ingests C64-related BASIC, assembly, and Markdown files under `data/` plus a curated subset of docs.
201
+ - Embeddings are written as deterministic JSON payloads (`embeddings_*.json`) inside `data/` unless you override the target with `RAG_EMBEDDINGS_DIR`.
202
+ - The server consumes these indices at startup to enrich MCP tool prompts; if indices are missing it simply serves empty results until you build them.
203
+
204
+ ### Indexed Content
205
+
206
+ - Drop additional snippets, notes, or source code anywhere under `data/` and the indexer will pick them up recursively.
207
+ - Include documentation that lives outside `data/` by exporting `RAG_DOC_FILES=path/to/doc1.md,path/to/doc2.md` before rebuilding; the defaults already cover `data/assembly/assembly-spec.md`.
208
+
209
+ ### Configuration Flags
210
+
211
+ - `RAG_EMBEDDINGS_DIR`: relocate the generated JSON files (the test suite points this at `artifacts/test-embeddings`).
212
+ - `RAG_REINDEX_INTERVAL_MS`: set to `0` (default) to disable background polling; raise it to opt into periodic rebuilds.
213
+ - `RAG_BUILD_ON_START`: unset by default so the server reuses existing indices; set to `1` for a one-time rebuild during startup.
214
+
215
+ The indexer only touches files when content changes to avoid noisy diffs.
216
+
217
+ ### Maintenance Commands
218
+
219
+ - `npm run rag:rebuild` β€” rebuild embeddings immediately.
220
+ - `npm run rag:fetch` β€” refresh external source material defined in `src/rag/sources.csv` before rebuilding.
221
+
222
+ ### Using the Retriever
223
+
224
+ - Tools: call `rag_retrieve_basic` or `rag_retrieve_asm` over the MCP stdio session with `{ "q": "query", "k": 3 }` to pull BASIC or assembly references.
225
+ - Optional HTTP probe: only if you manually launch the legacy Fastify server (see "Optional HTTP Compatibility" in `doc/troubleshooting-mcp.md`), you can `GET /rag/retrieve?q=<text>&k=3&lang=basic|asm` for quick inspection.
226
+
227
+ ```bash
228
+ # Example legacy probe once the optional HTTP server is running
229
+ curl -s "http://localhost:8000/rag/retrieve?q=draw%20a%20sine%20wave&k=3&lang=basic" | jq
230
+ ```
231
+
232
+ ### Index Hygiene
233
+
234
+ - Keep `RAG_REINDEX_INTERVAL_MS=0` in CI and local development unless you are actively modifying the corpus.
235
+ - Run `npm run rag:rebuild` after significant documentation imports so teammates receive the updated indices in version control.
236
+ - When experimentation requires rapid iteration, point `RAG_EMBEDDINGS_DIR` at a temporary folder and skip committing the generated files.
237
+
238
+ ### External Sources
239
+
240
+ Extending the RAG from external sources is a three-step process: discover sources, fetch content from them, and add the content to the index.
241
+
242
+ #### Discover
243
+
244
+ > [!NOTE]
245
+ > This feature is experimental.
246
+
247
+ To discover new C64 sources on GitHub, first create a `.env` file with GitHub credentials with these contents:
248
+
249
+ ```env
250
+ GITHUB_TOKEN=<personalAccessToken>
251
+ ```
252
+
253
+ The `<personalAccessToken>` can be issued at [GitHub Personal Access Tokens](https://github.com/settings/personal-access-tokens) with these values:
254
+
255
+ - Expiration: 90 days
256
+ - Resource owner: Your GitHub user account
257
+ - Repository access: All repositories
258
+ - Access type: Public repositories
259
+ - Permissions: Metadata (Read-only), Contents (Read-only)
260
+
261
+ Then run:
262
+
263
+ ```bash
264
+ npm install --save-dev dotenv-cli
265
+ npx dotenv -e .env -- npm run rag:discover
266
+ ```
267
+
268
+ This will extend the file `src/rag/sources.csv`.
269
+
270
+ #### Fetch
271
+
272
+ To download sources available at locations defined in `src/rag/sources.csv`:
273
+
274
+ 1. (Optional) Extend `src/rag/sources.csv` (columns: `type,description,link,depth`) with new sources.
275
+ 1. Fetch sources (opt-in, no network on builds/tests):
276
+
277
+ ```bash
278
+ npm run rag:fetch
279
+ ```
280
+
281
+ #### Rebuild
282
+
283
+ 1. Rebuild the RAG index to incorporate new or changed sources:
284
+
285
+ ```bash
286
+ # either rely on the running server's auto-reindexer (default ~15s), or
287
+ npm run rag:rebuild
288
+ ```
289
+
290
+ #### Notes
291
+
292
+ - Downloads are stored under `external/` (gitignored) and included in the index alongside `data/*`.
293
+ - If you delete files from `external/` and rebuild, their content will be removed from the RAG. To β€œfreeze” current embeddings, avoid rebuilding (e.g., set `RAG_REINDEX_INTERVAL_MS=0`) until you want to refresh.
294
+
295
+ For advanced options (depth semantics, throttling/limits, adaptive rate limiting, retries, logs, and environment overrides), see the dedicated section in `doc/developer.md`.
296
+
297
+ ## Utility Scripts πŸ› οΈ
298
+
299
+ - `npm run c64:tool` β€” interactive helper that can:
300
+ - convert a BASIC file to a PRG and store it under `artifacts/` (or a path you choose),
301
+ - convert and immediately run the generated PRG on the configured c64 device,
302
+ - upload an existing PRG and run it on the c64 device.
303
+ - `npm run api:generate` β€” regenerate the typed REST client under `generated/c64/` from [`doc/rest/c64-openapi.yaml`](doc/rest/c64-openapi.yaml).
304
+ - Advanced users can call the underlying CLI directly:
305
+
306
+ ```bash
307
+ node --import ./scripts/register-ts-node.mjs scripts/c64-cli.mjs convert-basic --input path/to/program.bas
308
+ node --import ./scripts/register-ts-node.mjs scripts/c64-cli.mjs run-basic --input path/to/program.bas
309
+ node --import ./scripts/register-ts-node.mjs scripts/c64-cli.mjs run-prg --input artifacts/program.prg
310
+ ```
311
+
312
+ Generated binaries are written to the `artifacts/` directory by default (ignored by git) so you can transfer them to real hardware or flash media. Make sure your `~/.c64bridge.json` (or `C64BRIDGE_CONFIG`) points at your c64 device before using the run options.
Binary file
Binary file
Binary file
@@ -0,0 +1,96 @@
1
+ # Prompt Taxonomy and Context Plan
2
+
3
+ This document captures the design work for **Phase 5 / Step 4.1** of the MCP migration: defining the prompt
4
+ families, required context, and reusable prompt segments. These notes do **not** contain the final prompt
5
+ strings; they specify the structure so that `promptRegistry` can assemble concrete prompts and the test
6
+ suite can assert expectations in upcoming steps.
7
+
8
+ ---
9
+
10
+ ## 1. Prompt Families & Goals
11
+
12
+ | Family ID | Mission | Primary Users | Core Outputs |
13
+ | --- | --- | --- | --- |
14
+ | `basic-program` | Generate, run, and verify Commodore BASIC programs. | BASIC Agent / general workflows | Tokenised BASIC source, post-run verification steps, tool invocation hints. |
15
+ | `assembly-program` | Author 6502/6510 assembly for VIC/SID/CIA tasks with safety checks. | ASM Agent / low-level workflows | Assembly source blocks, load/execute instructions, IRQ or memory safety reminders. |
16
+ | `sid-music` | Compose SID music with expressive timing and iterative audio checks. | SID Composer | Melody plans, SID register recipes, guidance to analyse playback. |
17
+ | `graphics-demo` | Produce graphics routines (sprites, PETSCII art, bitmap/raster effects). | VIC Painter | Mode setup instructions, colour guidance, verification routines. |
18
+ | `printer-job` | Send formatted output to Commodore or Epson printers safely. | Printer Operator | Device selection, character-set notes, print/eject workflow. |
19
+ | `memory-debug` | Inspect or patch memory without destabilising the system. | Memory Debugger | Safe read/write plans, freeze/resume advice, logging expectations. |
20
+ | `drive-manager` | Mount/create disk images and manage drives carefully. | Drive Manager | Pre-flight checks, mount/remove sequences, follow-up validation. |
21
+
22
+ > These families mirror the MCP tool domains so that prompt guidance matches available capabilities.
23
+
24
+ ---
25
+
26
+ ## 2. Required Resource Context per Family
27
+
28
+ | Family | Baseline Resources (URIs) | Rationale |
29
+ | --- | --- | --- |
30
+ | `basic-program` | `c64://specs/basic`, `c64://context/bootstrap`, `c64://docs/index` | Reinforce BASIC token rules, PETSCII gotchas, workflow expectations. |
31
+ | `assembly-program` | `c64://specs/assembly`, `c64://context/bootstrap`, `c64://specs/vic`, `c64://specs/sid` | Provide opcode tables, IRQ setup, VIC/SID register references. |
32
+ | `sid-music` | `c64://specs/sid`, `c64://specs/sidwave`, `c64://docs/sid/file-structure` | Supply register map, SIDWAVE format, SID file metadata. |
33
+ | `graphics-demo` | `c64://specs/vic`, `c64://context/bootstrap` | Cover VIC mode bits, raster constraints, general workflow guidance. |
34
+ | `printer-job` | `c64://specs/printer`, `c64://docs/printer/guide`, `c64://docs/printer/prompts` | Document PETSCII vs ESC/P workflows, sample templates, and safety checks. |
35
+ | `memory-debug` | `c64://context/bootstrap`, `c64://specs/assembly`, `c64://docs/index` | Highlight addressing safeguards, workflow rules, and knowledge map summaries. |
36
+ | `drive-manager` | `c64://context/bootstrap` | Ensure awareness of system-wide safety rules before altering drives. |
37
+
38
+ Notes:
39
+
40
+ - Resource URIs reflect existing knowledge catalog entries; verify actual IDs during prompt implementation.
41
+ - `drive-manager` currently relies on orientation material only; plan to author a dedicated storage/drive guide resource.
42
+ - Additional resources (memory map, VIC character set, SID best practices) remain desirableβ€”tracked in follow-ups below.
43
+
44
+ ---
45
+
46
+ ## 3. Default Tool Suggestions per Family
47
+
48
+ | Family | Must-Suggest Tools | Optional Tools | Warnings |
49
+ | --- | --- | --- | --- |
50
+ | `basic-program` | `upload_and_run_basic`, `read_screen`, `read_memory` | `write_memory`, `reset_c64` | Remind to reset only if user confirms; highlight PETSCII newline handling. |
51
+ | `assembly-program` | `upload_and_run_asm`, `write_memory`, `read_memory` | `read_screen`, `reset_c64`, `pause`, `resume` | Require IRQ acknowledgement steps for raster code; caution on zero-page writes. |
52
+ | `sid-music` | `music_generate`, `analyze_audio`, `sid_note_on` *(for manual passages)* | `music_compile_and_play`, `sidplay_file`, `sid_volume` | Warn about volume resets (`$D418`) and making backups before overwriting SID memory. |
53
+ | `graphics-demo` | `upload_and_run_basic` or `upload_and_run_asm`, `render_petscii_screen`, `generate_sprite_prg` | `create_petscii_image`, `read_memory`, `pause` | Emphasise safe colour RAM usage; mention border side-effects for raster tricks. |
54
+ | `printer-job` | `print_text`, `print_bitmap_commodore`, `print_bitmap_epson` | `define_printer_chars`, `read_memory` | Remind users to send `CHR$(12)` before closing; confirm `target` (`commodore` vs `epson`) before printing. |
55
+ | `memory-debug` | `read_memory`, `write_memory`, `pause`, `resume` | `reset_c64`, `read_screen` | Advise capturing snapshots before writes; include address validation heuristics. |
56
+ | `drive-manager` | `drives_list`, `drive_mount`, `drive_remove` | `drive_reset`, `drive_on`, `drive_off`, `create_d64`, `create_d71`, `create_d81`, `create_dnp`, `file_info`, `drive_load_rom` | Highlight risk of interrupting running programs; recommend verifying mounts after actions. |
57
+
58
+ ---
59
+
60
+ ## 4. Reusable Prompt Segments (`promptSegments`)
61
+
62
+ | Segment ID | Purpose | Content Summary |
63
+ | --- | --- | --- |
64
+ | `intro/core` | Universal introduction | Remind user the MCP runs against Ultimate 64 REST, mention tool invocation expectation. |
65
+ | `safety/reset` | Caution about disruptive actions | Ask for confirmation before resets/writes that halt the machine. |
66
+ | `workflow/basic-verify` | Post-run checklist for BASIC | Suggest `read_screen` capture, optional `read_memory` for program area, note PETSCII output quirks. |
67
+ | `workflow/asm-irq` | IRQ safety guidance | Outline `SEI`, vector setup, `$D01A` mask, `$D019` acknowledge, `CLI`. |
68
+ | `workflow/sid-iterate` | Audio feedback loop | Steps: compose β†’ play β†’ run `analyze_audio` β†’ adjust ADSR/frequency. |
69
+ | `workflow/graphics-verify` | Visual validation | Encourage screenshot or `read_screen`, mention border/background toggles. |
70
+ | `workflow/printer` | Print job completion | Ensure `CHR$(12)` for page eject, close channel, suggest checking printer status. |
71
+ | `workflow/memory-snapshot` | Safe memory editing | Recommend pausing, reading range before write, resuming afterwards. |
72
+ | `workflow/drive` | Drive changes | Pre-check currently mounted images, confirm after action, note potential interference with running programs. |
73
+
74
+ Segments should be composable so prompts can include `intro/core` + family-specific workflow + optional `safety/reset` depending on requested action.
75
+
76
+ ---
77
+
78
+ ## 5. Arguments & Variations (Preliminary)
79
+
80
+ - `assembly-program` may accept a `hardware` argument (`sid`, `vic`, `cia`, `multi`) to pull in targeted resource snippets.
81
+ - `graphics-demo` may accept `mode` (`text`, `multicolour`, `bitmap`, `sprite`) to tailor register setup.
82
+ - `printer-job` may accept `printerType` (`commodore`, `epson`) to adjust command examples and character-set notes.
83
+ - Future prompts should validate arguments and provide descriptive errors if unsupported values are provided.
84
+
85
+ Argument handling will be implemented in `promptRegistry.resolve` during Step 4.3; this section informs schema design.
86
+
87
+ ---
88
+
89
+ ## 6. Open Questions & Follow-Ups
90
+
91
+ - Extend the knowledge index with dedicated memory-map, drive-management, and character-set resources so prompts can cite them directly.
92
+ - Add SID best-practices material (triangle wave workflow) to the knowledge catalog or link from prompts explicitly.
93
+ - Adjust `storageModule.prompts` to include `drive-manager` once the prompt is authored, keeping tool metadata consistent.
94
+ - Ensure prompt tests assert for resource/tool mentions and safety callouts per family.
95
+
96
+ Document owner: Prompts migration effort (Phase 5).
@@ -0,0 +1,147 @@
1
+ # Example LLM Prompts for C64 Bridge Server
2
+
3
+ These example prompts illustrate what a user can ask the MCP server to perform on a real or emulated Commodore 64.
4
+ The MCP bridges the user’s intent with direct program generation, execution, or device control.
5
+
6
+ >[!NOTE] This is meant as a brainstorm collection of prompts. Some of the prompts mentioned below are not yet supported by the current MCP tools.
7
+
8
+ ---
9
+
10
+ ## 🧠 General Interaction
11
+
12
+ - "Show me the current C64 system state."
13
+ - "Reset the C64 and verify that BASIC is ready."
14
+ - "List all mounted disk images."
15
+ - "Mount the disk `games.d64` and list its directory."
16
+ - "Save the current memory to `snapshot.bin`."
17
+ - "Restore RAM from `snapshot.bin` and continue execution."
18
+ - "Transfer and run the program `demo.prg`."
19
+ - "Print the current screen output as text."
20
+ - "Show me the registers of CIA 1 and CIA 2."
21
+ - "Pause execution and dump memory from `$0800` to `$0FFF`."
22
+
23
+ ---
24
+
25
+ ## πŸ’Ύ Memory and System Control
26
+
27
+ - "Read 32 bytes starting at `$C000`."
28
+ - "Write the value `$A9` to address `$C000`."
29
+ - "Fill memory from `$0400` to `$07E7` with `$20` (space)."
30
+ - "Dump the zero page as a hex table."
31
+ - "Freeze the CPU, modify `$D020` to `$06`, and resume."
32
+ - "Trigger a soft reset."
33
+ - "Hard reset the C64 and reload `boot.prg`."
34
+
35
+ ---
36
+
37
+ ## πŸ’‘ BASIC Programming
38
+
39
+ - "Create a BASIC program that prints 'HELLO WORLD' in the center of the screen."
40
+ - "Generate a BASIC listing for a bouncing ball animation."
41
+ - "Convert this text into a valid BASIC tokenized PRG:"
42
+
43
+ ```basic
44
+ 10 PRINT "READY."
45
+ 20 GOTO 10
46
+ ```
47
+
48
+ - "List all BASIC variables after program execution."
49
+ - "Run the currently loaded BASIC program and capture its output."
50
+ - "Save the BASIC program as `HELLO.PRG` to disk."
51
+ - "Show the BASIC memory map and string descriptors."
52
+
53
+ ---
54
+
55
+ ## βš™οΈ Assembly Programming
56
+
57
+ - "Assemble a short 6502 routine that changes the border colour every frame."
58
+ - "Inject this code into RAM at `$C000` and execute:"
59
+
60
+ ```assembly
61
+ LDA #$06
62
+ STA $D020
63
+ RTS
64
+ ```
65
+
66
+ - "Assemble and run a raster interrupt that flashes the screen every 50 Hz."
67
+ - "Disassemble memory from `$C000` to `$C050`."
68
+ - "Step through 10 instructions and show registers after each step."
69
+ - "Assemble a SID music player routine at `$1000`."
70
+ - "Assemble and export a `.prg` file from this source."
71
+
72
+ ---
73
+
74
+ ## 🎡 SID Music Composition
75
+
76
+ - "Compose a short SID tune in the style of early Rob Hubbard."
77
+ - "Generate a 3-voice arpeggio sequence in C major, lasting 8 seconds."
78
+ - "Export this tune as `demo.sid`."
79
+ - "Play the current SID file through the C64 SID chip."
80
+ - "Visualize the waveform and envelope data for each voice."
81
+ - "Show which SID registers are used for filter modulation."
82
+
83
+ ---
84
+
85
+ ## 🎨 PETSCII Art and Graphics
86
+
87
+ - "Create a PETSCII logo reading 'C64 Bridge' with rainbow gradient."
88
+ - "Generate a PETSCII image of a spaceship using block characters."
89
+ - "Convert this PNG into PETSCII art compatible with C64 screen memory."
90
+ - "Preview the PETSCII output as text."
91
+ - "Export the artwork to `logo.seq` and `logo.prg`."
92
+ - "Display the PETSCII artwork on the screen."
93
+
94
+ ---
95
+
96
+ ## πŸ–¨οΈ Printing and Document Generation
97
+
98
+ - "Print the current BASIC listing to a virtual printer."
99
+ - "Render a document header: 'Commodore 64 Report – 1984 Edition'."
100
+ - "Generate a formatted report of all memory changes in the last session."
101
+ - "Print the PETSCII artwork as a text file."
102
+ - "Export screen contents to PDF via MCP printer adapter."
103
+
104
+ ---
105
+
106
+ ## 🧩 Disk and File Management
107
+
108
+ - "Create a new disk image called `workbench.d64`."
109
+ - "Mount `music.d64` as drive 8."
110
+ - "List files on drive 8."
111
+ - "Delete the file `OLDGAME.PRG` from drive 8."
112
+ - "Copy `HELLO.PRG` to drive 9 as `HELLO2.PRG`."
113
+ - "Transfer file `game.prg` from local PC to drive 8."
114
+ - "Unmount all drives."
115
+
116
+ ---
117
+
118
+ ## πŸ§ͺ Testing and Diagnostics
119
+
120
+ - "Run a video sync test pattern."
121
+ - "Play a POP audio + frame sync signal for calibration."
122
+ - "Measure frame delay between video and audio."
123
+ - "Report VIC-II raster timing and SID voice status."
124
+ - "Check if the system is running at PAL or NTSC frequency."
125
+ - "Benchmark CPU speed using a short 1000-iteration loop."
126
+
127
+ ---
128
+
129
+ ## πŸ€– Integrated AI Tasks
130
+
131
+ - "Generate a new BASIC game idea and create its program automatically."
132
+ - "Write assembly code that plays a melody while showing scrolling text."
133
+ - "Convert a SID file into BASIC DATA statements."
134
+ - "Explain what the program at `$0801` does."
135
+ - "Translate this assembly snippet into commented pseudocode."
136
+ - "Optimize this BASIC program for speed and memory."
137
+ - "Summarize the PETSCII image currently displayed."
138
+
139
+ ---
140
+
141
+ ## πŸ“š Meta Commands
142
+
143
+ - "Describe all capabilities of this MCP server."
144
+ - "List all available agents (BASIC, Assembly, SID, PETSCII, Disk)."
145
+ - "Explain how to connect an external tool (like VICE or Ultimate 64)."
146
+ - "Show examples of valid API calls for writing to memory."
147
+ - "Show recent system logs."