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,106 @@
1
+ # C64 REST API Reference
2
+
3
+ Authoritative source: [Ultimate 64 REST API](https://1541u-documentation.readthedocs.io/en/latest/api/api_calls.html) for devices such as Commodore 64 Ultimate and Ultimate 64.
4
+
5
+ ## Conventions
6
+
7
+ - Base path: `/v1`.
8
+ - URL format: `/v1/<route>/<path>:<command>?<arguments>`.
9
+ - Responses are JSON unless noted and **always** include an `errors` array.
10
+ - Attachments: `POST` variants accept binary payloads using `multipart/form-data` or `application/octet-stream`.
11
+ - Firmware ≥ 3.12 can require `X-Password: <network-password>` on every request; missing/incorrect passwords yield `403`.
12
+
13
+ ## About
14
+
15
+ | Method | Path | Parameters | Description |
16
+ | --- | --- | --- | --- |
17
+ | GET | `/v1/version` | – | Returns the REST API version, e.g. `{ "version": "0.1", "errors": [] }`. |
18
+ | GET | `/v1/info` | – | Basic device information (product, firmware/core versions, hostname, optional unique ID). |
19
+
20
+ ## Runners
21
+
22
+ | Method | Path | Parameters | Description |
23
+ | --- | --- | --- | --- |
24
+ | PUT | `/v1/runners:sidplay` | `file` (path), `songnr?` | Play a SID file from the device filesystem; optional song selection. |
25
+ | POST | `/v1/runners:sidplay` | `songnr?` | Play an uploaded SID attachment, optional second attachment for song lengths. |
26
+ | PUT | `/v1/runners:modplay` | `file` (path) | Play an Amiga MOD from the filesystem. |
27
+ | POST | `/v1/runners:modplay` | – | Play an uploaded MOD attachment. |
28
+ | PUT | `/v1/runners:load_prg` | `file` (path) | Reset, DMA-load PRG from disk into memory; does **not** run. |
29
+ | POST | `/v1/runners:load_prg` | – | Reset, DMA-load uploaded PRG attachment; does **not** run. |
30
+ | PUT | `/v1/runners:run_prg` | `file` (path) | Reset, DMA-load PRG from disk, then run. |
31
+ | POST | `/v1/runners:run_prg` | – | Reset, DMA-load uploaded PRG attachment, then run. |
32
+ | PUT | `/v1/runners:run_crt` | `file` (path) | Reset with cartridge image from filesystem active. |
33
+ | POST | `/v1/runners:run_crt` | – | Reset with uploaded cartridge attachment active. |
34
+
35
+ ## Configuration
36
+
37
+ | Method | Path | Parameters | Description |
38
+ | --- | --- | --- | --- |
39
+ | GET | `/v1/configs` | – | List configuration categories. Supports wildcards via query string. |
40
+ | GET | `/v1/configs/{category}` | – | List items within a category (wildcards allowed). |
41
+ | GET | `/v1/configs/{category}/{item}` | – | Inspect specific config entries (wildcards allowed). |
42
+ | PUT | `/v1/configs/{category}/{item}` | `value` | Update a single config item; full path or wildcard selectors accepted. |
43
+ | POST | `/v1/configs` | JSON body | Batch update config categories/items using returned JSON shape. |
44
+ | PUT | `/v1/configs:load_from_flash` | – | Load saved configuration from non-volatile storage. |
45
+ | PUT | `/v1/configs:save_to_flash` | – | Persist current configuration to non-volatile storage. |
46
+ | PUT | `/v1/configs:reset_to_default` | – | Restore factory defaults (does not touch saved flash values). |
47
+
48
+ ## Machine Control
49
+
50
+ | Method | Path | Parameters | Description |
51
+ | --- | --- | --- | --- |
52
+ | PUT | `/v1/machine:reset` | – | Soft reset; config unchanged. |
53
+ | PUT | `/v1/machine:reboot` | – | Restart cartridge + soft reset. |
54
+ | PUT | `/v1/machine:pause` | – | Assert DMA pause (halts CPU, timers continue). |
55
+ | PUT | `/v1/machine:resume` | – | Release DMA pause. |
56
+ | PUT | `/v1/machine:poweroff` | – | Power down (U64 only, response may be absent). |
57
+ | PUT | `/v1/machine:menu_button` | – | Toggle Ultimate menu as if pressing the hardware button. |
58
+ | PUT | `/v1/machine:writemem` | `address`, `data` (hex) | DMA-write ≤ 128 bytes supplied as hex string. |
59
+ | POST | `/v1/machine:writemem` | `address` (hex), binary body | DMA-write attachment beginning at `address`; must not wrap `$FFFF`. |
60
+ | GET | `/v1/machine:readmem` | `address` (hex), `length?` | DMA-read; firmware may return binary or base64/array payload. Default length 256 bytes. |
61
+ | GET | `/v1/machine:debugreg` | – | Read `$D7FF` debug register (U64 only). |
62
+ | PUT | `/v1/machine:debugreg` | `value` (hex) | Write then return the `$D7FF` debug register (U64 only). |
63
+
64
+ ## Floppy Drives
65
+
66
+ | Method | Path | Parameters | Description |
67
+ | --- | --- | --- | --- |
68
+ | GET | `/v1/drives` | – | Enumerate internal drives, mounted images, and SoftIEC partitions. |
69
+ | PUT | `/v1/drives/{drive}:mount` | `image` (path), `type?`, `mode?` | Mount existing image (`d64/g64/d71/g71/d81`) with mode `readwrite/readonly/unlinked`. |
70
+ | POST | `/v1/drives/{drive}:mount` | `type?`, `mode?`, attachment | Mount uploaded image attachment. |
71
+ | PUT | `/v1/drives/{drive}:reset` | – | Reset selected drive. |
72
+ | PUT | `/v1/drives/{drive}:remove` | – | Eject mounted image; when mounted in unlinked mode it simply drops the link so further writes are discarded. |
73
+ | PUT | `/v1/drives/{drive}:on` | – | Power on (or reset) the drive. |
74
+ | PUT | `/v1/drives/{drive}:off` | – | Power off the drive (removes it from IEC bus). |
75
+ | PUT | `/v1/drives/{drive}:load_rom` | `file` (path) | Temporarily load ROM image from filesystem (16 K/32 K). |
76
+ | POST | `/v1/drives/{drive}:load_rom` | attachment | Temporarily load ROM from uploaded binary. |
77
+ | PUT | `/v1/drives/{drive}:set_mode` | `mode` (`1541\|1571\|1581`) | Change drive mode; resets and reloads ROM. |
78
+
79
+ ## Data Streams (U64 only)
80
+
81
+ | Method | Path | Parameters | Description |
82
+ | --- | --- | --- | --- |
83
+ | PUT | `/v1/streams/{stream}:start` | `ip` (`addr[:port]`) | Start video/audio/debug stream to destination (`video`→11000, `audio`→11001, `debug`→11002 if port omitted). Starting video stops debug. |
84
+ | PUT | `/v1/streams/{stream}:stop` | – | Stop the specified stream (`video`, `audio`, or `debug`). |
85
+
86
+ ## File Manipulation
87
+
88
+ | Method | Path | Parameters | Description |
89
+ | --- | --- | --- | --- |
90
+ | GET | `/v1/files/{path}:info` | – | Return file metadata (size, extension). Wildcards allowed. *(Alpha status)* |
91
+ | PUT | `/v1/files/{path}:create_d64` | `tracks?` (35/40), `diskname?` | Create D64 image at specified filesystem path. |
92
+ | PUT | `/v1/files/{path}:create_d71` | `diskname?` | Create 70-track D71 image. |
93
+ | PUT | `/v1/files/{path}:create_d81` | `diskname?` | Create 160-track D81 image. |
94
+ | PUT | `/v1/files/{path}:create_dnp` | `tracks` (≤255), `diskname?` | Create DNP image; each track has 256 sectors (≤ ~16 MB). |
95
+
96
+ ## Error Handling
97
+
98
+ - `400`: malformed request (invalid parameters, body, or file attachment).
99
+ - `403`: missing or incorrect `X-Password` when network password enforced.
100
+ - `404`: route not present on current hardware/firmware.
101
+ - `500`: device reported internal failure—inspect `errors` array for details.
102
+
103
+ ## Assets in Repository
104
+
105
+ - `doc/rest/c64-openapi.yaml` captures the full API surface in OpenAPI 3.1 format for mock generation and tooling.
106
+ - Firmware change log: <https://1541u-documentation.readthedocs.io/en/latest/api/changelog.html>
@@ -0,0 +1,177 @@
1
+ # MCP Troubleshooting Guide
2
+
3
+ Field notes for the stdio-based Model Context Protocol server. Use these checks when the C64 Bridge surface does not respond or CI fails the connectivity probe.
4
+
5
+ ## Quick Diagnosis Checklist
6
+
7
+ ```bash
8
+ # 1. Is the MCP server running?
9
+ ps -ef | grep "c64bridge" | grep -v grep
10
+
11
+ # 2. Do startup logs show the connectivity probe?
12
+ tail -n20 ~/.c64bridge.log # or the terminal running npm start
13
+
14
+ # 3. Can we reach the configured REST endpoint directly?
15
+ curl -s http://<your-c64-host>/v1/info | jq .version
16
+
17
+ # 4. When using the mock server
18
+ npm test -- --mock
19
+ ```
20
+
21
+ ## Common Issues & Fixes
22
+
23
+ ### 1. Server Starts Without Connectivity Logs
24
+
25
+ **Symptoms:**
26
+
27
+ - `npm start` prints the banner but omits `Connectivity check succeeded`.
28
+ - CI job `Validate MCP server logs` fails.
29
+
30
+ **Resolution:**
31
+
32
+ 1. Confirm the REST base URL in `.c64bridge.json` or `C64BRIDGE_CONFIG` matches a reachable device.
33
+ 2. Run `curl -I http://<host>/v1/info` to confirm HTTP reachability.
34
+ 3. Review `src/mcp-server.ts` connectivity logging; ensure no local edits suppressed `logConnectivity`.
35
+ 4. If hardware is offline, expect `Skipping direct REST connectivity probe` in the logs—CI treats this as success.
36
+
37
+ ### 2. VS Code (Copilot Chat) Cannot See Tools
38
+
39
+ **Symptoms:**
40
+
41
+ - Copilot Chat shows "No MCP server" messages.
42
+ - Tool invocations fail silently.
43
+
44
+ **Resolution:**
45
+
46
+ 1. Restart VS Code after changing MCP settings.
47
+ 2. Verify the settings JSON matches the snippet in `doc/MCP_SETUP.md` (`command`, `args`, `type: "stdio"`).
48
+ 3. Keep `npm start` (or `npx c64bridge`) running; Copilot terminates the stdio process when the chat closes.
49
+ 4. Inspect the Copilot output channel for connection errors and ensure the stdio server entry is configured and running.
50
+
51
+ ### 3. Tests Fail Because Mock Server Is Missing
52
+
53
+ **Symptoms:**
54
+
55
+ - `npm test` exits with ENOENT for `test/mockC64Server.mjs` or cannot bind to port 18064.
56
+
57
+ **Resolution:**
58
+
59
+ 1. Ensure dev dependencies are installed (`npm install`).
60
+ 2. Verify nothing else occupies the mock server port: `lsof -i :18064`.
61
+ 3. Run `npm test -- --verbose` to see which suite fails; the harness spins up the mock server automatically.
62
+
63
+ ### 4. C64 Hardware Connection Issues
64
+
65
+ **Check C64 Configuration:**
66
+
67
+ ```bash
68
+ # Verify config file exists and has correct IP
69
+ cat .c64bridge.json
70
+ ```
71
+
72
+ Expected structure:
73
+
74
+ ```json
75
+ {
76
+ "c64u": {
77
+ "host": "c64u",
78
+ "port": 80
79
+ }
80
+ }
81
+ ```
82
+
83
+ Example with explicit host:
84
+
85
+ ```json
86
+ {
87
+ "c64u": {
88
+ "host": "192.168.1.13",
89
+ "port": 80
90
+ }
91
+ }
92
+ ```
93
+
94
+ **Test C64 Connectivity:**
95
+
96
+ Please note that the following IP address is just given as an example.
97
+
98
+ ```bash
99
+ # Test Ultimate 64 REST API directly
100
+ curl -s http://192.168.1.13/v1/info
101
+ curl -s http://c64u/v1/info
102
+
103
+ # If both fail, check network/Ultimate 64 power
104
+ ping 192.168.1.13
105
+ ```
106
+
107
+ ### 5. Missing Dependencies
108
+
109
+ **Symptoms:**
110
+
111
+ - Server fails to start
112
+ - TypeScript compilation errors
113
+ - Missing modules
114
+
115
+ **Solutions:**
116
+
117
+ ```bash
118
+ # Reinstall dependencies
119
+ npm install
120
+
121
+ # Verify TypeScript can compile (optional check)
122
+ npx tsc --noEmit src/index.ts
123
+ ```
124
+
125
+ ### 6. Transport
126
+
127
+ Only stdio transport is supported for MCP. HTTP transport is not supported.
128
+
129
+ ## Working Test Sequence
130
+
131
+ Use these checks to validate the full stack:
132
+
133
+ 1. `npm test` — run the mock suite end-to-end via stdio MCP.
134
+ 2. `npm test -- --real --base-url=$C64_BASE` — exercise real hardware (override `C64_BASE` to match your device).
135
+ 3. `curl -s "$C64_BASE"/v1/info | jq .version` — confirm the Ultimate 64 REST endpoint responds (hardware connectivity; unrelated to MCP transport).
136
+ 4. `npm run start-mock` — optional mock C64 server for local experiments.
137
+
138
+ ## VS Code MCP Setup Checklist
139
+
140
+ - [ ] GitHub Copilot extension installed and active
141
+ - [ ] MCP experimental feature enabled (Copilot Chat ≥ v1.214)
142
+ - [ ] Settings JSON matches `doc/MCP_SETUP.md`
143
+ - [ ] `npm start` (or packaged CLI) running in a terminal
144
+ - [ ] Connectivity logs confirm the REST endpoint is reachable
145
+ - [ ] Hardware (or mock server) is online and accessible
146
+
147
+ ## Key Lessons Learned
148
+
149
+ 1. Connectivity logs are the fastest signal—watch the console during startup.
150
+ 2. Keep configuration files small and explicit; mismatched hosts cause silent timeouts.
151
+ 3. Automated tests cover most workflows; run `npm test` before suspecting hardware.
152
+ 4. Copilot Chat terminates the stdio server when the session ends—restart `npm start` as needed.
153
+
154
+ ## Emergency Recovery
155
+
156
+ If nothing works:
157
+
158
+ ```bash
159
+ # Nuclear option: kill everything and restart
160
+ pkill -f npm
161
+ pkill -f node
162
+ pkill -f c64bridge
163
+
164
+ # Wait a few seconds
165
+ sleep 3
166
+
167
+ # Clean restart
168
+ cd /path/to/c64bridge
169
+ npm start
170
+
171
+ # If using HTTP mode, test immediately
172
+ curl -s http://localhost:8000/tools/info
173
+ ```
174
+
175
+ ---
176
+
177
+ *Keep this guide updated whenever new MCP workflows or diagnostics land in the project.*