@henols/c64-re-tools 2.7.0 → 2.8.0-rc.1
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.
- package/package.json +1 -1
- package/skills/c64-assembler/SKILL.md +23 -38
- package/skills/c64-assembler/scripts/assembler.ts +114 -16
- package/skills/c64-basic/SKILL.md +11 -31
- package/skills/c64-basic/scripts/basic.ts +4 -1
- package/skills/c64-development/SKILL.md +2 -2
- package/skills/c64-disk/SKILL.md +11 -32
- package/skills/c64-docs/SKILL.md +27 -45
- package/skills/c64-docs/references/page-types.md +20 -18
- package/skills/c64-docs/references/style.md +10 -4
- package/skills/c64-docs/scripts/docs.ts +13 -2
- package/skills/c64-docs/scripts/lib/reference.ts +47 -5
- package/skills/c64-knowledge/SKILL.md +138 -267
- package/skills/c64-knowledge/references/batches.md +48 -0
- package/skills/c64-knowledge/references/coverage.md +29 -0
- package/skills/c64-knowledge/references/source-knowledge.md +72 -0
- package/skills/c64-knowledge/references/start-screen.md +44 -0
- package/skills/c64-knowledge/scripts/knowledge.ts +266 -61
- package/skills/c64-knowledge/scripts/lib/check.ts +133 -0
- package/skills/c64-knowledge/scripts/lib/listing.ts +72 -8
- package/skills/c64-memory-map/SKILL.md +11 -32
- package/skills/c64-packer/SKILL.md +11 -31
- package/skills/c64-provenance/SKILL.md +40 -62
- package/skills/c64-provenance/scripts/lib/leftovers.ts +8 -3
- package/skills/c64-provenance/scripts/provenance.ts +64 -55
- package/skills/c64-reverse-engineering/SKILL.md +20 -47
- package/skills/c64-reverse-engineering/references/comment-check.md +42 -0
- package/skills/c64-reverse-engineering/references/versions.md +47 -0
- package/skills/c64-source/SKILL.md +43 -235
- package/skills/c64-source/references/export.md +50 -0
- package/skills/c64-source/references/loader.md +78 -0
- package/skills/c64-source/references/source-format.md +46 -0
- package/skills/c64-source/scripts/lib/export.ts +20 -7
- package/skills/c64-source/scripts/lib/loader.ts +116 -104
- package/skills/c64-source/scripts/source.ts +62 -52
- package/skills/c64-static-analysis/SKILL.md +51 -52
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +55 -2
- package/skills/c64-static-analysis/scripts/lib/idioms.ts +28 -9
- package/skills/c64-static-analysis/scripts/static-analysis.ts +69 -15
- package/skills/c64-testing/SKILL.md +77 -59
- package/skills/c64-testing/references/recording-format.md +5 -79
- package/skills/c64-testing/references/scenario-format.md +4 -12
- package/skills/c64-testing/scripts/lib/play.ts +16 -8
- package/skills/c64-testing/scripts/lib/recording.ts +76 -9
- package/skills/c64-testing/scripts/lib/replay.ts +14 -0
- package/skills/c64-testing/scripts/lib/runs.ts +112 -1
- package/skills/c64-testing/scripts/lib/scenario.ts +12 -6
- package/skills/c64-testing/scripts/lib/start-screen.ts +27 -0
- package/skills/c64-testing/scripts/testing.ts +37 -15
- package/skills/c64-unpacker/SKILL.md +10 -30
- package/skills/emulator/SKILL.md +7 -36
- package/src/build-name.ts +12 -1
- package/src/knowledge/history.ts +8 -0
- package/src/knowledge/program.ts +73 -1
- package/src/knowledge/read.ts +46 -2
- package/src/knowledge/recording-files.ts +32 -0
- package/src/knowledge/schema.ts +3 -1
- package/src/knowledge/separate.ts +90 -3
- package/src/knowledge/start-screen.ts +99 -17
- package/src/knowledge/text.ts +2 -1
- package/src/knowledge/write.ts +15 -8
- package/src/loader.ts +167 -0
- package/src/native/c64run.ts +11 -0
- package/src/native/decompiler/analyze.ts +7 -6
- package/src/native/decompiler/walk.ts +32 -2
- package/src/native/dxa.ts +4 -4
- package/src/native/types.ts +32 -4
- package/src/script.ts +87 -17
- package/skills/c64-export/SKILL.md +0 -63
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// The c64-testing script. test runs a scenario on the reference and the
|
|
2
2
|
// rebuild in one emulator; run runs steps on one side and writes what they
|
|
3
|
-
// ask for;
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// ask for; keep copies a run into a folder that git keeps; record and replay
|
|
4
|
+
// play a session in the replay core (c64run) and compare the rebuild with it;
|
|
5
|
+
// show tells what a recording holds; diff shows what changed between two
|
|
6
|
+
// states; checklist gives the Markdown list for a human tester.
|
|
6
7
|
|
|
7
8
|
import { COVERAGE, formatC64Address } from "#src/c64.ts";
|
|
8
9
|
import { isRefusal, Refusal } from "#src/errors.ts";
|
|
@@ -20,9 +21,9 @@ import { LOCAL_DIRECTORY, PROJECT_DIRECTORY, projectRelative, projectRoot } from
|
|
|
20
21
|
import { OPTIONS, reply, runScript, UsageError, type Call, type CommandSpec, type Reply } from "#src/script.ts";
|
|
21
22
|
import { diffFiles } from "./lib/diff-files.ts";
|
|
22
23
|
import { CANCELLED, play } from "./lib/play.ts";
|
|
23
|
-
import { readRecordFile, record, RECORDING_FILES } from "./lib/recording.ts";
|
|
24
|
+
import { readRecordFile, record, RECORDING_FILES, showRecording } from "./lib/recording.ts";
|
|
24
25
|
import { replay } from "./lib/replay.ts";
|
|
25
|
-
import { runFile } from "./lib/runs.ts";
|
|
26
|
+
import { keepRun, runFile } from "./lib/runs.ts";
|
|
26
27
|
import { namesOf, readScenario, runScenario, scenarioNames, type Scenario, type ScenarioResult } from "./lib/scenario.ts";
|
|
27
28
|
|
|
28
29
|
/** The default port of the --play page: next to the Host Runtime's 6464. */
|
|
@@ -114,15 +115,15 @@ async function recordCommand(call: Call): Promise<Reply> {
|
|
|
114
115
|
const local = (path: string) => projectRelative(path).startsWith(`${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/`);
|
|
115
116
|
const keep = local(out)
|
|
116
117
|
? `Git ignores ${out}. To keep the recording as a test and to add its coverage to the project knowledge, record again with --out tests/recordings/<name>.`
|
|
117
|
-
: `Commit ${out} with the scenarios.
|
|
118
|
+
: `Commit ${out} with the scenarios. Put the coverage of the recording folder ${out} into the project knowledge.`;
|
|
118
119
|
const recordFile = local(call.subject(0)) ? ` Git also ignores the record file ${call.subject(0)}. To record again later, keep a copy in a folder that git keeps, for example tests/record/.` : "";
|
|
119
120
|
const written = new Set(Object.values(RECORDING_FILES).map((name) => projectRelative(`${out}/${name}`)));
|
|
120
121
|
const evidence = changedEvidence(db, projectRoot(), (file) => written.has(file));
|
|
121
122
|
const map = projectRelative(`${out}/${RECORDING_FILES.coverage}`);
|
|
122
123
|
const cited = [
|
|
123
124
|
...(evidence.length === 0 ? [] : [" The project knowledge gives the files in evidence as evidence of earlier revisions, and this record changed them."]),
|
|
124
|
-
...(evidence.some((change) => change.file === map) ? [` Put the
|
|
125
|
-
...(evidence.some((change) => change.file !== map) ? [
|
|
125
|
+
...(evidence.some((change) => change.file === map) ? [` Put the coverage of the recording folder ${out} into the project knowledge again: it replaces the map of the earlier recording.`] : []),
|
|
126
|
+
...(evidence.some((change) => change.file !== map) ? [" For each other file in evidence, examine the facts of its revisions against the new recording."] : []),
|
|
126
127
|
].join("");
|
|
127
128
|
return reply(
|
|
128
129
|
{ result: "PASS", recorded: true, out, ...summary, files, ...(evidence.length === 0 ? {} : { evidence }) },
|
|
@@ -155,7 +156,7 @@ const COMMANDS: CommandSpec[] = [
|
|
|
155
156
|
{
|
|
156
157
|
name: "test",
|
|
157
158
|
summary: "Runs a scenario on the reference and then on the rebuild in one emulator. result is PASS, FAIL with the differences, or INCONCLUSIVE with the reason.",
|
|
158
|
-
subjects: [{ name: "<scenario.json>", help: "a scenario file, relative to the project folder. See references/scenario-format.md" }],
|
|
159
|
+
subjects: [{ name: "<scenario.json>", help: "a scenario file, relative to the project folder. See <skill>/references/scenario-format.md" }],
|
|
159
160
|
options: {
|
|
160
161
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", help: "with a FAIL, write both screens, the difference image and memory.json into this folder: each differing memory item with all its bytes, and each byte that differs" },
|
|
161
162
|
"max-listed": { ...OPTIONS["max-listed"], help: "list at most n differing bytes of each memory item (default 50). The count is always given" },
|
|
@@ -165,20 +166,33 @@ const COMMANDS: CommandSpec[] = [
|
|
|
165
166
|
{
|
|
166
167
|
name: "run",
|
|
167
168
|
summary: "Runs the steps of a run file in its own emulator and writes what they ask for into --out: screens, coverage maps, snapshot files, traces, and results.json with the observations and the expectations. result is FAIL when a step did not run or an expect step found a value that differs.",
|
|
168
|
-
subjects: [{ name: "<run.json>", help: "a run file, relative to the project folder. See references/scenario-format.md, section Runs" }],
|
|
169
|
+
subjects: [{ name: "<run.json>", help: "a run file, relative to the project folder. See <skill>/references/scenario-format.md, section Runs" }],
|
|
169
170
|
options: { out: { ...OPTIONS.out, output: "folder", value: "<dir>", required: true, help: "the folder for the files of the steps and results.json" } },
|
|
170
171
|
notes: 'A run file is one JSON object. It must have name, start and steps. name is a non-empty string. start is { "program": "<file.prg>" }, { "program": "<file.prg>", "load": true } or { "snapshot": "<file.vsf>" }. steps is a list with at least one step. Optional: symbols ("knowledge", "none" (default) or a JSON file) and videoStandard ("pal" (default) or "ntsc"). The script refuses other keys.',
|
|
171
172
|
run: async (call) => {
|
|
172
173
|
const { output, failed } = await runFile(call.subject(0), call.string("out")!);
|
|
173
174
|
if (!failed) return { result: "PASS", ...output };
|
|
174
|
-
const hint = output.reason !== undefined ? "reason tells why a step did not run. Correct the step or the start, then run again." : "failedExpectations names the expect steps that failed. expectations
|
|
175
|
+
const hint = output.reason !== undefined ? "reason tells why a step did not run. Correct the step or the start, then run again." : "failedExpectations names the expect steps that failed. expectations gives the expected and the actual values.";
|
|
175
176
|
return reply({ result: "FAIL", ...output }, { hint });
|
|
176
177
|
},
|
|
177
178
|
},
|
|
179
|
+
{
|
|
180
|
+
name: "keep",
|
|
181
|
+
summary: "Keeps a run as evidence in a new folder that git keeps: the run file as run.json, its results, and the files in .c64-re-tools/local/ that the run file starts from. The run file in the folder gets the new paths of those files.",
|
|
182
|
+
subjects: [
|
|
183
|
+
{ name: "<run.json>", help: "the run file, relative to the project folder" },
|
|
184
|
+
{ name: "<out>", help: "the --out folder of the run" },
|
|
185
|
+
{ name: "<folder>", help: "the new folder, for example runs/<name>" },
|
|
186
|
+
],
|
|
187
|
+
run: (call) => {
|
|
188
|
+
const kept = keepRun(call.subject(0), call.subject(1), call.subject(2));
|
|
189
|
+
return reply(kept, { hint: `Commit ${kept.out}. Give its files as evidence, for example ${kept.out}/results.json.` });
|
|
190
|
+
},
|
|
191
|
+
},
|
|
178
192
|
{
|
|
179
193
|
name: "record",
|
|
180
|
-
summary: "Plays the steps of a record file on the reference, and writes the session
|
|
181
|
-
subjects: [{ name: "<record.json>", help: "a record file, relative to the project folder. See references/recording-format.md" }],
|
|
194
|
+
summary: "Plays the steps of a record file on the reference, and writes the session into the recording folder --out. result is FAIL when the session did not complete.",
|
|
195
|
+
subjects: [{ name: "<record.json>", help: "a record file, relative to the project folder. See <skill>/references/recording-format.md" }],
|
|
182
196
|
options: {
|
|
183
197
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", required: true, help: "the recording folder, for example tests/recordings/<name>" },
|
|
184
198
|
play: { kind: "flag", help: "a person plays after the steps: the script prints the address of a page on stderr. The page shows the start screen frozen until Start (Enter). End (F12) saves the recording, Cancel (F11) ends without one" },
|
|
@@ -187,6 +201,13 @@ const COMMANDS: CommandSpec[] = [
|
|
|
187
201
|
},
|
|
188
202
|
run: recordCommand,
|
|
189
203
|
},
|
|
204
|
+
{
|
|
205
|
+
name: "show",
|
|
206
|
+
summary: "What a recording holds, without a replay: the program, the frames, the events, the comparison of the record file, each input site with its reads and the changes of its value, and the counts of the coverage map.",
|
|
207
|
+
subjects: [{ name: "<recording>", help: "a folder that record wrote, relative to the project folder" }],
|
|
208
|
+
options: { "max-listed": { ...OPTIONS["max-listed"], help: "list at most n input sites (default 50). The count is always given" } },
|
|
209
|
+
run: (call) => showRecording(call.subject(0).replace(/\/+$/, ""), call.count("max-listed")!),
|
|
210
|
+
},
|
|
190
211
|
{
|
|
191
212
|
name: "replay",
|
|
192
213
|
summary: "Replays a recording on the reference, which must end with the recorded state, and with --rebuild on the rebuild, which must have the state of the reference at each checkpoint. result is PASS, FAIL or INCONCLUSIVE.",
|
|
@@ -198,11 +219,12 @@ const COMMANDS: CommandSpec[] = [
|
|
|
198
219
|
rebuild: { kind: "path", value: "<prg>", help: "the rebuild to compare with the reference" },
|
|
199
220
|
symbols: { ...OPTIONS.symbols, help: "the names of the rebuild: the symbol file of its build (default: the symbols of the recording)" },
|
|
200
221
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", help: "with a FAIL, write the RAM of both sides at the first different checkpoint into this folder" },
|
|
222
|
+
screen: { ...OPTIONS.out, output: "file", value: "<png>", help: "write the screen of the reference at the end of the session into this PNG file" },
|
|
201
223
|
},
|
|
202
224
|
notes: "A recording without names takes the names of the knowledge for the reference. A $ address is an address of the reference: on the rebuild it moves with the name before it.",
|
|
203
225
|
run: async (call) => {
|
|
204
|
-
const [checkpoint, rebuild, symbols, out] = [call.string("checkpoint"), call.string("rebuild"), call.string("symbols"), call.string("out")];
|
|
205
|
-
const result = await replay({ folder: call.subject(0), state: call.strings("state"), pin: call.strings("pin"), ...(checkpoint === undefined ? {} : { checkpoint }), ...(rebuild === undefined ? {} : { rebuild }), ...(symbols === undefined ? {} : { symbols }), ...(out === undefined ? {} : { out }) });
|
|
226
|
+
const [checkpoint, rebuild, symbols, out, screen] = [call.string("checkpoint"), call.string("rebuild"), call.string("symbols"), call.string("out"), call.string("screen")];
|
|
227
|
+
const result = await replay({ folder: call.subject(0), state: call.strings("state"), pin: call.strings("pin"), ...(checkpoint === undefined ? {} : { checkpoint }), ...(rebuild === undefined ? {} : { rebuild }), ...(symbols === undefined ? {} : { symbols }), ...(out === undefined ? {} : { out }), ...(screen === undefined ? {} : { screen }) });
|
|
206
228
|
if (result.result === "INCONCLUSIVE") return reply(result, { hint: INCONCLUSIVE_HINT });
|
|
207
229
|
if (result.result !== "FAIL") return result;
|
|
208
230
|
const [reference, rebuilt] = result.files ?? [];
|
|
@@ -80,12 +80,11 @@ The script refuses a step in an old form. The message gives the step to write.
|
|
|
80
80
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
81
81
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
82
82
|
- Write each file that you make for your work in `.c64-re-tools/local/` of the project. Git ignores that folder. Examples are results, batches, step files, runs, snapshots and memory dumps.
|
|
83
|
-
- The script refuses an `--out` path in `.c64-re-tools/knowledge
|
|
83
|
+
- The script refuses an `--out` path in `.c64-re-tools/knowledge/`. Change the project knowledge only with the commands that change it.
|
|
84
84
|
- The script refuses a folder where the command writes a file. It refuses a file where the command writes a folder.
|
|
85
85
|
- When a test or another file is the evidence for a finding in the project knowledge, move it out of `.c64-re-tools/local/` first. The project knowledge refuses that evidence in that folder.
|
|
86
|
-
- A coverage map can stay in `.c64-re-tools/local/`.
|
|
87
|
-
-
|
|
88
|
-
- Put a run that is evidence in `runs/<name>/`, with its run file, its results and its snapshot files. Change the paths in the run file to the new paths. Then git keeps them, and another person can do the run again.
|
|
86
|
+
- A coverage map can stay in `.c64-re-tools/local/`. Do not move a coverage map after you put it into the project knowledge.
|
|
87
|
+
- To keep a run as evidence, use the command that keeps a run. It copies the run, its results and its snapshot files into `runs/<name>/`, and it changes the paths in the copy. Then git keeps them, and another person can do the run again.
|
|
89
88
|
- A shell redirect (`>`) is relative to the working directory, not to the project folder. From the folder above the project, write `<folder>/.c64-re-tools/local/result.json`.
|
|
90
89
|
|
|
91
90
|
---
|
|
@@ -297,24 +296,15 @@ Do not record the unpacker in the project knowledge, unless the user asks you to
|
|
|
297
296
|
|
|
298
297
|
Each command prints one JSON envelope on one line on stdout. Notes go to stderr.
|
|
299
298
|
|
|
300
|
-
On success, the exit code is 0:
|
|
301
|
-
|
|
302
|
-
```json
|
|
303
|
-
{"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
On failure, the exit code is 2:
|
|
307
|
-
|
|
308
|
-
```json
|
|
309
|
-
{"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}
|
|
310
|
-
```
|
|
311
|
-
|
|
299
|
+
- On success, the exit code is 0: `{"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}`
|
|
300
|
+
- On failure, the exit code is 2: `{"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}`
|
|
312
301
|
- `body` holds the result. The section of each command gives the fields of its body.
|
|
313
302
|
- A check gives its verdict in `body.result`: `PASS`, `FAIL` or `INCONCLUSIVE`. The exit code is 0 for each verdict. Thus read `body.result`, not the exit code.
|
|
314
|
-
- `error` is one sentence. It tells what is wrong.
|
|
315
|
-
- `
|
|
316
|
-
- `
|
|
317
|
-
- `
|
|
303
|
+
- `error` is one sentence. It tells what is wrong. `hint` tells what to do or what to examine. Read it before your next step.
|
|
304
|
+
- `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task.
|
|
305
|
+
- A list has `count`, `listed` and `rest`. `listed` holds at most `--max-listed` items. `rest` tells how to get the other items. A file that the command wrote has `out`, `bytes` and `sha256`.
|
|
306
|
+
- To get only some fields of `body`, give `--fields <path>,<path>`, for example `--fields count,listed.start`. A path through a list gives that field of each item. Do not write code to filter an envelope.
|
|
307
|
+
- To get the command list, run the script with no arguments. To get the subjects and the flags of one command, run `<command> --help`.
|
|
318
308
|
|
|
319
309
|
| `code` | Action |
|
|
320
310
|
|---|---|
|
|
@@ -322,13 +312,3 @@ On failure, the exit code is 2:
|
|
|
322
312
|
| `invalid-input`, `not-found` | Correct the call as `hint` tells. Then run the command again. |
|
|
323
313
|
| `operation-failed` | Give `error` and `hint` to the user. |
|
|
324
314
|
| Another code | Do as `hint` tells. |
|
|
325
|
-
|
|
326
|
-
These fields have the same meaning in each body:
|
|
327
|
-
|
|
328
|
-
| Field | Meaning |
|
|
329
|
-
|---|---|
|
|
330
|
-
| `out`, `bytes`, `sha256` | A file that the command wrote: its path, its size and its SHA-256. |
|
|
331
|
-
| `count`, `listed`, `rest` | A list. `count` is the number of items. `listed` holds the first items, at most `--max-listed`. `rest` tells how to get the other items. |
|
|
332
|
-
|
|
333
|
-
To get the command list, run the script with no arguments. The envelope has `command: "help"`, and `body.commands` gives the name, the summary and the synopsis of each command.
|
|
334
|
-
To get the subjects and the flags of one command, run `<command> --help`. Then `body.subjects` and `body.options` give them.
|
package/skills/emulator/SKILL.md
CHANGED
|
@@ -13,18 +13,12 @@ This skill does not analyse code statically. It does not write project knowledge
|
|
|
13
13
|
|
|
14
14
|
The MCP server knows the machine and the emulator. Its instructions, its tool descriptions, its result fields and its error messages give the facts of the machine and the known flaws of the emulator. This skill tells how to use the tools for a task. If this skill and a tool description do not agree, obey the tool description.
|
|
15
15
|
|
|
16
|
-
## Inputs
|
|
17
|
-
|
|
18
|
-
- The machine action or the runtime question.
|
|
19
|
-
- The target address, state or condition, when the question needs one.
|
|
20
|
-
- The project path of the program or disk to load, when the question needs one.
|
|
21
|
-
|
|
22
|
-
A tool takes addresses, not names. The server instructions give the address format. Get the address of a name from the project knowledge.
|
|
23
|
-
|
|
24
16
|
## Tools
|
|
25
17
|
|
|
26
18
|
Use only the MCP tools. Each MCP session has its own machine. Nothing else can change that machine.
|
|
27
19
|
|
|
20
|
+
A tool takes addresses, not names. The server instructions give the address format. To get the address of a name, read the name in the project knowledge.
|
|
21
|
+
|
|
28
22
|
| Need | C64 tool |
|
|
29
23
|
|---|---|
|
|
30
24
|
| Reset, power cycle | `c64_reset` |
|
|
@@ -35,6 +29,7 @@ Use only the MCP tools. Each MCP session has its own machine. Nothing else can c
|
|
|
35
29
|
| Run to a place and read the machine there in one call | `c64_run_until` with `observe` and `history` |
|
|
36
30
|
| Each access or routine entry over many frames | `c64_trace` |
|
|
37
31
|
| Stop on an instruction address, stop on a memory access | `c64_breakpoint`, `c64_watchpoint` |
|
|
32
|
+
| Find the instruction that reads or writes an address, and when | `c64_watchpoint` with the access, then `c64_execution` or `c64_run_until`. The stop gives `pc`. |
|
|
38
33
|
| Memory | `c64_memory_read`, `c64_memory_write`, `c64_memory_search`, `c64_memory_compare` |
|
|
39
34
|
| CPU registers | `c64_registers` |
|
|
40
35
|
| Code as it is in memory now | `c64_disassemble` |
|
|
@@ -88,28 +83,11 @@ The emulator has no window. When the user must type, play or look at the machine
|
|
|
88
83
|
|
|
89
84
|
The result field `notCarried` names the data that the open or the close cleared.
|
|
90
85
|
|
|
91
|
-
## Knowledge
|
|
92
|
-
|
|
93
|
-
Read:
|
|
94
|
-
- the current knowledge for each address and range that the question touches.
|
|
95
|
-
|
|
96
|
-
Automatic write:
|
|
97
|
-
- none.
|
|
86
|
+
## Knowledge and result
|
|
98
87
|
|
|
99
|
-
|
|
100
|
-
-
|
|
101
|
-
|
|
102
|
-
Do not store:
|
|
103
|
-
- breakpoints or watchpoints
|
|
104
|
-
- memory reads
|
|
105
|
-
- temporary machine state
|
|
106
|
-
- a screen capture, unless the user asks for it as an artifact
|
|
107
|
-
|
|
108
|
-
## Result
|
|
109
|
-
|
|
110
|
-
The result is the runtime state or evidence that the question asks for.
|
|
111
|
-
|
|
112
|
-
If you cannot get the machine into the necessary state, say which state you could not get. Say what you tried.
|
|
88
|
+
- Record in the project knowledge only a symbol, a region or a comment that the runtime evidence justifies.
|
|
89
|
+
- Do not record breakpoints, watchpoints, memory reads or machine state. Record a screen capture only when the user asks for it.
|
|
90
|
+
- If you cannot get the machine into the necessary state, tell the user which state. Tell what you tried.
|
|
113
91
|
|
|
114
92
|
## Failure and conflicts
|
|
115
93
|
|
|
@@ -124,10 +102,3 @@ An error is `{"error": {"code": "...", "message": "..."}}`. The message tells wh
|
|
|
124
102
|
- A different code: the message names the cause. Change the call, or report the cause.
|
|
125
103
|
|
|
126
104
|
If the runtime evidence does not agree with the current knowledge, do not change the knowledge. Report the conflict with the runtime evidence. Then resolve the conflict in the project knowledge.
|
|
127
|
-
|
|
128
|
-
## Other tasks
|
|
129
|
-
|
|
130
|
-
- To explain code without a run, analyze the program statically.
|
|
131
|
-
- Record a durable conclusion in the project knowledge.
|
|
132
|
-
- To compare runs or to assert values in a run, write a test run file.
|
|
133
|
-
- To find the meaning of a C64 address or register, read the memory map of the C64.
|
package/src/build-name.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
// name when it is on, no_<name> when it is off. A build of an entry other
|
|
5
5
|
// than main.asm adds the entry, for example clean_loader. The loader of the
|
|
6
6
|
// packed form alone is only its copier, so its build is clean_copier: the loader
|
|
7
|
-
// program, which generate
|
|
7
|
+
// program, which generate or a build with switch values packs, keeps
|
|
8
|
+
// clean_loader. A source without
|
|
8
9
|
// config.asm and without a release keeps the name of its entry. The symbols
|
|
9
10
|
// of a build go into symbols/ next to the program, so the program folder
|
|
10
11
|
// holds only programs.
|
|
@@ -30,6 +31,16 @@ export function configValues(text: string): Map<string, 0 | 1> {
|
|
|
30
31
|
return values;
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
/**
|
|
35
|
+
* The config.asm text with other values for some switches: the value line of
|
|
36
|
+
* each given name gets the given value, and the other lines stay as they are.
|
|
37
|
+
* A build takes the switch values this way: ACME refuses a define of a symbol
|
|
38
|
+
* that config.asm also sets.
|
|
39
|
+
*/
|
|
40
|
+
export function withConfigValues(text: string, values: ReadonlyMap<string, 0 | 1>): string {
|
|
41
|
+
return text.replace(/^([ \t]*([A-Z][A-Z0-9_]*)[ \t]*=[ \t]*)[01](?=[ \t]*(?:;[^\r\n]*)?\r?$)/gm, (line: string, head: string, name: string) => (values.has(name) ? `${head}${values.get(name)}` : line));
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
/** What a build is made of: a release, or the values of config.asm with the default of each switch (0 when the defaults do not have it). */
|
|
34
45
|
export type BuildKind = { release: string } | { values: ReadonlyMap<string, number>; defaults: ReadonlyMap<string, number> };
|
|
35
46
|
|
package/src/knowledge/history.ts
CHANGED
|
@@ -251,6 +251,14 @@ export interface RevisionChanges {
|
|
|
251
251
|
closed: HistoryEntry[];
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
/** The rows that a revision added and closed, counted by kind of row: only the kinds that it changed. */
|
|
255
|
+
export function revisionCounts(changes: Pick<RevisionChanges, "added" | "closed">): Partial<Record<HistoryEntry["entity"], { added: number; closed: number }>> {
|
|
256
|
+
const counts: Partial<Record<HistoryEntry["entity"], { added: number; closed: number }>> = {};
|
|
257
|
+
for (const entry of changes.added) (counts[entry.entity] ??= { added: 0, closed: 0 }).added++;
|
|
258
|
+
for (const entry of changes.closed) (counts[entry.entity] ??= { added: 0, closed: 0 }).closed++;
|
|
259
|
+
return counts;
|
|
260
|
+
}
|
|
261
|
+
|
|
254
262
|
/** One revision and exactly what it changed. */
|
|
255
263
|
export function revision(db: DatabaseSync | undefined, text: string): RevisionChanges {
|
|
256
264
|
const id = resolveRevision(db, text);
|
package/src/knowledge/program.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { createHash } from "node:crypto";
|
|
|
7
7
|
import type { DatabaseSync } from "node:sqlite";
|
|
8
8
|
|
|
9
9
|
import { Refusal } from "../errors.ts";
|
|
10
|
-
import { type AddressRange, COVERAGE, formatC64Address } from "../c64.ts";
|
|
10
|
+
import { type AddressRange, COVERAGE, formatC64Address, formatC64Byte } from "../c64.ts";
|
|
11
11
|
|
|
12
12
|
import { COVERAGE_KINDS, DEFAULT_SPACE, MEMORY_ROW, type CoverageKind, type Space } from "./schema.ts";
|
|
13
13
|
import { coverageRuns } from "./read.ts";
|
|
@@ -241,6 +241,52 @@ export function addCoverage(
|
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
/** What the runs did at an address: executed (x wins), read and written (rw), read, written, or nothing (-). */
|
|
245
|
+
export type Access = "x" | "rw" | "r" | "w" | "-";
|
|
246
|
+
|
|
247
|
+
/** The kinds of coverage ranges that count as an execute, a read and a write: RAM, ROM and the I/O area. */
|
|
248
|
+
const EXECUTES: readonly CoverageKind[] = ["x", "rom-x", "io-x"];
|
|
249
|
+
const READS: readonly CoverageKind[] = ["r", "rom-r", "io-r"];
|
|
250
|
+
const WRITES: readonly CoverageKind[] = ["w", "io-w"];
|
|
251
|
+
|
|
252
|
+
/** The access of a set of coverage kinds: an execute wins, then a read and a write together. */
|
|
253
|
+
function accessOf(kinds: ReadonlySet<CoverageKind>): Access {
|
|
254
|
+
const has = (list: readonly CoverageKind[]) => list.some((kind) => kinds.has(kind));
|
|
255
|
+
if (has(EXECUTES)) return "x";
|
|
256
|
+
if (has(READS)) return has(WRITES) ? "rw" : "r";
|
|
257
|
+
return has(WRITES) ? "w" : "-";
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** True when an address is in ranges as text: "$1000-$1002 $1005". */
|
|
261
|
+
function inRanges(text: string, address: number): boolean {
|
|
262
|
+
for (const item of text.split(" ")) {
|
|
263
|
+
const [start, end] = item.split("-");
|
|
264
|
+
if (address >= Number.parseInt(start!.slice(1), 16) && address <= Number.parseInt((end ?? start)!.slice(1), 16)) return true;
|
|
265
|
+
}
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The access of the runs at an address in a space: the access of each coverage
|
|
271
|
+
* map that the space has (by its path, also a map without accesses), and the
|
|
272
|
+
* joined access of all maps. Undefined when the space has no coverage map.
|
|
273
|
+
*/
|
|
274
|
+
export function coverageAccess(db: DatabaseSync | undefined, space: Space = DEFAULT_SPACE): ((address: number) => { maps: Array<{ map: string; access: Access }>; access: Access }) | undefined {
|
|
275
|
+
if (db === undefined) return undefined;
|
|
276
|
+
const maps = [...new Set(coverageRuns(db).filter((run) => run.space === space).map((run) => run.name))];
|
|
277
|
+
if (maps.length === 0) return undefined;
|
|
278
|
+
const rows = db.prepare("SELECT map, kind, ranges FROM current_coverage WHERE space = ?").all(space) as Array<{ map: string; kind: CoverageKind; ranges: string }>;
|
|
279
|
+
return (address) => {
|
|
280
|
+
const all = new Set<CoverageKind>();
|
|
281
|
+
const each = maps.map((map) => {
|
|
282
|
+
const kinds = new Set(rows.filter((row) => row.map === map && inRanges(row.ranges, address)).map((row) => row.kind));
|
|
283
|
+
for (const kind of kinds) all.add(kind);
|
|
284
|
+
return { map, access: accessOf(kinds) };
|
|
285
|
+
});
|
|
286
|
+
return { maps: each, access: accessOf(all) };
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
244
290
|
/** The program of a space, or undefined when the knowledge has no bytes for it. */
|
|
245
291
|
export function programImage(db: DatabaseSync | undefined, space: Space = DEFAULT_SPACE): ProgramImage | undefined {
|
|
246
292
|
if (db === undefined) return undefined;
|
|
@@ -369,3 +415,29 @@ export function releaseImage(db: DatabaseSync | undefined, label: string, space:
|
|
|
369
415
|
}
|
|
370
416
|
return { segments, byteAt: (address) => memory[address]! };
|
|
371
417
|
}
|
|
418
|
+
|
|
419
|
+
/** The bytes of one !byte line of patch code. */
|
|
420
|
+
const PATCH_LINE_BYTES = 8;
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* The bytes of a release in [start, end] as patch code: !byte lines. The base
|
|
424
|
+
* release is refused: its bytes are the program, and a patch holds the other
|
|
425
|
+
* state. A release without a byte at each address of the range is refused.
|
|
426
|
+
*/
|
|
427
|
+
export function releaseCode(db: DatabaseSync | undefined, label: string, start: number, end: number, space: Space = DEFAULT_SPACE): string {
|
|
428
|
+
const range = `${formatC64Address(start)}-${formatC64Address(end)}`;
|
|
429
|
+
const release = db?.prepare("SELECT base FROM current_releases WHERE space = ? AND label = ?").get(space, label) as { base: number } | undefined;
|
|
430
|
+
if (release === undefined) throw new Refusal("not-found", `There is no release ${label}${space === DEFAULT_SPACE ? "" : ` in ${space}`}. Record it first with its file.`);
|
|
431
|
+
if (release.base === 1) throw new Refusal("invalid-input", `${label} is the base release: its bytes are the program, and a patch holds the bytes of the other state. Give the release that has the other bytes in ${range}.`);
|
|
432
|
+
const image = releaseImage(db, label, space)!;
|
|
433
|
+
const inside = (address: number) => image.segments.some((segment) => address >= segment.start && address <= segment.end);
|
|
434
|
+
for (let address = start; address <= end; address++) {
|
|
435
|
+
if (!inside(address)) throw new Refusal("invalid-input", `The release ${label} has no byte at ${formatC64Address(address)}, in the range ${range}. Give a range inside the bytes of the release.`);
|
|
436
|
+
}
|
|
437
|
+
const lines: string[] = [];
|
|
438
|
+
for (let at = start; at <= end; at += PATCH_LINE_BYTES) {
|
|
439
|
+
const bytes = Array.from({ length: Math.min(PATCH_LINE_BYTES, end - at + 1) }, (_, offset) => formatC64Byte(image.byteAt(at + offset)));
|
|
440
|
+
lines.push(`!byte ${bytes.join(",")}`);
|
|
441
|
+
}
|
|
442
|
+
return lines.join("\n");
|
|
443
|
+
}
|
package/src/knowledge/read.ts
CHANGED
|
@@ -114,11 +114,18 @@ export interface SwitchRow {
|
|
|
114
114
|
revision: string;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* A release of the program, and whether its bytes are the program of the
|
|
119
|
+
* knowledge. The bytes of another release are in release_memory. `file` and
|
|
120
|
+
* `sha256` are the file that recorded the release and its SHA-256; a release
|
|
121
|
+
* of an earlier toolkit version has neither.
|
|
122
|
+
*/
|
|
118
123
|
export interface ReleaseRow {
|
|
119
124
|
space: Space;
|
|
120
125
|
label: string;
|
|
121
126
|
base: boolean;
|
|
127
|
+
file?: string;
|
|
128
|
+
sha256?: string;
|
|
122
129
|
comment?: string;
|
|
123
130
|
origin: Extract<Origin, "user" | "llm">;
|
|
124
131
|
revision: string;
|
|
@@ -199,7 +206,7 @@ export const MODULE_COLUMNS = "space, start_address, file, title, origin, valid_
|
|
|
199
206
|
export const OPERAND_COLUMNS = "space, address, selector, symbol, offset, expression, origin, valid_from_revision";
|
|
200
207
|
export const PATCH_COLUMNS = "space, start_address, end_address, switch_name, code, comment, origin, valid_from_revision";
|
|
201
208
|
export const SWITCH_COLUMNS = "space, name, kind, default_value, releases, comment, origin, valid_from_revision";
|
|
202
|
-
export const RELEASE_COLUMNS = "space, label, base, comment, origin, valid_from_revision";
|
|
209
|
+
export const RELEASE_COLUMNS = "space, label, base, file, sha256, comment, origin, valid_from_revision";
|
|
203
210
|
export const MACRO_COLUMNS = "space, name, params, body, comment, origin, valid_from_revision";
|
|
204
211
|
export const MACRO_USE_COLUMNS = "space, start_address, end_address, macro, args, origin, valid_from_revision";
|
|
205
212
|
export const START_SCREEN_COLUMNS = "space, mode, screen, bitmap, charset, colours, colour, border, background, stage, call_address, colour_ram, comment, origin, valid_from_revision";
|
|
@@ -306,6 +313,8 @@ export function toRelease(row: Raw): ReleaseRow {
|
|
|
306
313
|
origin: row.origin as ReleaseRow["origin"],
|
|
307
314
|
revision: row.valid_from_revision as string,
|
|
308
315
|
};
|
|
316
|
+
if (row.file !== null && row.file !== undefined) release.file = row.file as string;
|
|
317
|
+
if (row.sha256 !== null && row.sha256 !== undefined) release.sha256 = row.sha256 as string;
|
|
309
318
|
if (row.comment !== null && row.comment !== undefined) release.comment = row.comment as string;
|
|
310
319
|
return release;
|
|
311
320
|
}
|
|
@@ -706,6 +715,41 @@ export function listReferences(db: DatabaseSync | undefined, range: AddressRange
|
|
|
706
715
|
.filter((reference) => (kind === undefined || reference.kind === kind) && kept(origins)(reference));
|
|
707
716
|
}
|
|
708
717
|
|
|
718
|
+
/** Where a reference goes, seen from a range: into it from outside, out of it, or with both ends inside it. */
|
|
719
|
+
export const REFERENCE_DIRECTIONS = ["in", "out", "inside"] as const;
|
|
720
|
+
export type ReferenceDirection = (typeof REFERENCE_DIRECTIONS)[number];
|
|
721
|
+
|
|
722
|
+
/** True for a reference that goes in the direction, seen from the range. */
|
|
723
|
+
export function goes(range: AddressRange, direction: ReferenceDirection): (row: Pick<ReferenceRow, "from" | "to">) => boolean {
|
|
724
|
+
const inside = (address: number) => address >= range.start && address <= range.end;
|
|
725
|
+
if (direction === "in") return (row) => inside(row.to) && !inside(row.from);
|
|
726
|
+
if (direction === "out") return (row) => inside(row.from) && !inside(row.to);
|
|
727
|
+
return (row) => inside(row.from) && inside(row.to);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
/** The references counted by kind, and by target with the target that most references go to first. */
|
|
731
|
+
export function referenceCounts(rows: readonly ReferenceRow[]): { byKind: Partial<Record<ReferenceKind, number>>; byTarget: Array<{ to: number; count: number }> } {
|
|
732
|
+
const byKind: Partial<Record<ReferenceKind, number>> = {};
|
|
733
|
+
const targets = new Map<number, number>();
|
|
734
|
+
for (const row of rows) {
|
|
735
|
+
byKind[row.kind] = (byKind[row.kind] ?? 0) + 1;
|
|
736
|
+
targets.set(row.to, (targets.get(row.to) ?? 0) + 1);
|
|
737
|
+
}
|
|
738
|
+
const byTarget = [...targets].map(([to, count]) => ({ to, count })).sort((a, b) => b.count - a.count || a.to - b.to);
|
|
739
|
+
return { byKind, byTarget };
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/** The regions counted by type, with their bytes in the range. */
|
|
743
|
+
export function regionCounts(rows: readonly RegionRow[], range: AddressRange = ALL): Partial<Record<RegionType, { count: number; bytes: number }>> {
|
|
744
|
+
const counts: Partial<Record<RegionType, { count: number; bytes: number }>> = {};
|
|
745
|
+
for (const row of rows) {
|
|
746
|
+
const item = (counts[row.type] ??= { count: 0, bytes: 0 });
|
|
747
|
+
item.count++;
|
|
748
|
+
item.bytes += Math.min(row.end, range.end) - Math.max(row.start, range.start) + 1;
|
|
749
|
+
}
|
|
750
|
+
return counts;
|
|
751
|
+
}
|
|
752
|
+
|
|
709
753
|
/** Current suppressions whose place lies in the range: a reference by its source or target. */
|
|
710
754
|
export function listSuppressions(db: DatabaseSync | undefined, range: AddressRange = ALL, space: Space = DEFAULT_SPACE): SuppressionRow[] {
|
|
711
755
|
if (db === undefined) return [];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// The files of a recording folder: the record of a session writes them, and the
|
|
2
|
+
// knowledge takes the coverage map of the folder. They are here, so the
|
|
3
|
+
// script that records and the script that keeps the knowledge share one list.
|
|
4
|
+
|
|
5
|
+
import { existsSync, statSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
|
|
8
|
+
import { Refusal } from "../errors.ts";
|
|
9
|
+
import { projectRoot, resolveReadFile } from "../project.ts";
|
|
10
|
+
|
|
11
|
+
export const RECORDING_FILES = { recording: "recording.json", reads: "reads.txt", coverage: "coverage.bin" } as const;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The coverage map that a path names: the path itself, or for a recording
|
|
15
|
+
* folder the coverage map in it (<folder>/coverage.bin). The knowledge names a
|
|
16
|
+
* map by this path, so a new recording into the same folder replaces the map.
|
|
17
|
+
* A path that is no folder, or that does not exist, is given back as it is:
|
|
18
|
+
* the read of the map refuses it.
|
|
19
|
+
*/
|
|
20
|
+
export function coverageMapOf(path: string, root = projectRoot()): string {
|
|
21
|
+
let real: string;
|
|
22
|
+
try {
|
|
23
|
+
real = resolveReadFile(path, root);
|
|
24
|
+
} catch {
|
|
25
|
+
return path;
|
|
26
|
+
}
|
|
27
|
+
if (!statSync(real).isDirectory()) return path;
|
|
28
|
+
if (!existsSync(join(real, RECORDING_FILES.coverage)) || !existsSync(join(real, RECORDING_FILES.recording))) {
|
|
29
|
+
throw new Refusal("not-found", `${path} is a folder that holds no recording. Give a coverage map, or a folder that a record of a session wrote.`);
|
|
30
|
+
}
|
|
31
|
+
return `${path.replace(/\/+$/, "")}/${RECORDING_FILES.coverage}`;
|
|
32
|
+
}
|
package/src/knowledge/schema.ts
CHANGED
|
@@ -302,6 +302,8 @@ function createSchema(db: DatabaseSync): void {
|
|
|
302
302
|
space TEXT NOT NULL DEFAULT 'c64' CHECK (${SPACE_CHECK}),
|
|
303
303
|
label TEXT NOT NULL CHECK (length(label) > 0),
|
|
304
304
|
base INTEGER NOT NULL CHECK (base IN (0, 1)),
|
|
305
|
+
file TEXT CHECK (file IS NULL OR length(file) > 0),
|
|
306
|
+
sha256 TEXT CHECK (sha256 IS NULL OR length(sha256) = 64),
|
|
305
307
|
comment TEXT CHECK (comment IS NULL OR length(comment) > 0),
|
|
306
308
|
origin TEXT NOT NULL CHECK (origin IN ('user', 'llm')),
|
|
307
309
|
valid_from_revision TEXT NOT NULL REFERENCES revisions (id),
|
|
@@ -423,7 +425,7 @@ function createSchema(db: DatabaseSync): void {
|
|
|
423
425
|
}
|
|
424
426
|
|
|
425
427
|
/** The version of the index this build makes. An index with another version is emptied and made again. */
|
|
426
|
-
export const INDEX_VERSION =
|
|
428
|
+
export const INDEX_VERSION = 16;
|
|
427
429
|
|
|
428
430
|
function indexVersion(db: DatabaseSync): number | undefined {
|
|
429
431
|
const hasMeta = db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'meta'").get();
|