@henols/c64-re-tools 2.3.0-rc.5 → 2.3.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 (61) hide show
  1. package/package.json +1 -1
  2. package/skills/c64-assembler/SKILL.md +149 -78
  3. package/skills/c64-assembler/scripts/assembler.ts +18 -11
  4. package/skills/c64-basic/SKILL.md +90 -52
  5. package/skills/c64-basic/scripts/basic.ts +15 -6
  6. package/skills/c64-development/SKILL.md +46 -73
  7. package/skills/c64-disk/SKILL.md +145 -73
  8. package/skills/c64-disk/scripts/disk.ts +11 -6
  9. package/skills/c64-docs/SKILL.md +199 -118
  10. package/skills/c64-docs/references/page-types.md +3 -3
  11. package/skills/c64-docs/references/style.md +9 -13
  12. package/skills/c64-docs/scripts/docs.ts +39 -15
  13. package/skills/c64-docs/scripts/lib/links.ts +1 -1
  14. package/skills/c64-docs/scripts/lib/reference.ts +2 -2
  15. package/skills/c64-docs/scripts/lib/source-map.ts +2 -2
  16. package/skills/c64-export/SKILL.md +21 -45
  17. package/skills/c64-knowledge/SKILL.md +489 -233
  18. package/skills/c64-knowledge/scripts/knowledge.ts +31 -26
  19. package/skills/c64-memory-map/SKILL.md +131 -65
  20. package/skills/c64-memory-map/scripts/memory-map.ts +19 -11
  21. package/skills/c64-packer/SKILL.md +120 -72
  22. package/skills/c64-packer/scripts/packer.ts +10 -3
  23. package/skills/c64-provenance/SKILL.md +301 -173
  24. package/skills/c64-provenance/scripts/lib/library.ts +6 -6
  25. package/skills/c64-provenance/scripts/provenance.ts +85 -36
  26. package/skills/c64-reverse-engineering/SKILL.md +55 -72
  27. package/skills/c64-source/SKILL.md +316 -224
  28. package/skills/c64-source/scripts/lib/export.ts +9 -14
  29. package/skills/c64-source/scripts/lib/loader.ts +5 -5
  30. package/skills/c64-source/scripts/lib/source.ts +5 -5
  31. package/skills/c64-source/scripts/source.ts +106 -21
  32. package/skills/c64-static-analysis/SKILL.md +188 -112
  33. package/skills/c64-static-analysis/scripts/static-analysis.ts +29 -9
  34. package/skills/c64-testing/SKILL.md +272 -166
  35. package/skills/c64-testing/references/recording-format.md +11 -12
  36. package/skills/c64-testing/references/scenario-format.md +20 -5
  37. package/skills/c64-testing/scripts/lib/diff-files.ts +8 -8
  38. package/skills/c64-testing/scripts/lib/recording.ts +7 -7
  39. package/skills/c64-testing/scripts/lib/replay.ts +7 -7
  40. package/skills/c64-testing/scripts/lib/runs.ts +6 -7
  41. package/skills/c64-testing/scripts/lib/scenario.ts +12 -6
  42. package/skills/c64-testing/scripts/testing.ts +35 -15
  43. package/skills/c64-unpacker/SKILL.md +273 -127
  44. package/skills/c64-unpacker/scripts/lib/loads.ts +3 -3
  45. package/skills/c64-unpacker/scripts/unpacker.ts +70 -11
  46. package/skills/emulator/SKILL.md +12 -12
  47. package/src/errors.ts +22 -2
  48. package/src/host/vice/session.ts +1 -1
  49. package/src/host-client/entry-state.ts +1 -1
  50. package/src/host-client/image.ts +3 -3
  51. package/src/host-client/steps.ts +1 -1
  52. package/src/knowledge/expression.ts +1 -1
  53. package/src/knowledge/names.ts +2 -3
  54. package/src/knowledge/program.ts +2 -3
  55. package/src/knowledge/write.ts +2 -2
  56. package/src/mcp/inputs.ts +1 -1
  57. package/src/mcp/tools/input.ts +1 -1
  58. package/src/mcp/tools/media.ts +1 -1
  59. package/src/native/exomizer.ts +2 -2
  60. package/src/project.ts +2 -2
  61. package/src/script.ts +164 -75
@@ -1,243 +1,371 @@
1
1
  ---
2
2
  name: c64-provenance
3
- description: Use this skill to compare two or more releases of a C64 program, for example cracked versions from different groups. It finds the bytes where the releases differ and shows which releases agree there. It can run each release and tell how the program uses each difference. It also gives evidence for each range of the program in the knowledge. The evidence is the unpack stage, the access, and the code that the entry does not reach. It also finds leftovers in one program: texts, assembler source, BASIC lines, fills, unused bytes, copies and dead code. It finds text of other computers, for example Apple II source. Leftovers tell about the development, the cracks and the recracks. Use the result to separate the content of the application from changes that a release added. It also keeps a library of routines that several programs share. It finds them in the program of the knowledge and writes their names as a batch for c64-knowledge. Do not use it to analyze the code.
3
+ description: Compares two or more releases of a C64 program byte by byte and tells which releases agree at each difference. It can run each release and tell how the program uses each difference. It gives evidence for each range of the program in the project knowledge. It finds the leftovers in the program, for example texts, assembler source, BASIC lines, unused bytes, copies and dead code. It keeps a library of routines that several programs share, and finds these routines in a program. Use it to separate the original application from the changes of a crack or of a release. Use it to find the history of a program in its leftovers. Use it to find known routines, for example a music driver, in a program. It does not disassemble or analyze the code, and it does not change the project knowledge.
4
4
  ---
5
5
 
6
- # c64-provenance
6
+ # C64 provenance
7
7
 
8
- ## Purpose
8
+ Use this script to compare releases of a C64 program, to find the leftovers in a program, and to keep a library of shared routines.
9
+ Use only the commands of the script. Do not compare releases or search for leftovers in another way.
9
10
 
10
- Compare releases of a C64 program. Find the bytes where they differ and which releases agree. Use this to find which bytes are probably the original application and which are changes of one release.
11
+ ```bash
12
+ node <skill>/scripts/provenance.ts <command>
13
+ ```
11
14
 
12
- Find the leftovers in one program. A leftover is a part of the program that the program does not need. Examples are a crack text, an old copy of a routine and a piece of assembler source.
15
+ `<skill>` is the base directory of this skill. Run the script with `node`. You can run it from any directory.
16
+ Each command in this skill, for example `compare releases/a.prg releases/b.prg`, goes in the place of `<command>`.
17
+ Each command prints one JSON envelope on stdout. See the section "JSON output".
18
+ To get the command list, run the script with no arguments.
13
19
 
14
- Keep a library of routines that several programs share, for example a music driver or a decruncher. Find the routines of the library in a program, and get their names for that program.
20
+ ---
15
21
 
16
- This skill does not change project knowledge.
22
+ ## Select the command
17
23
 
18
- ## Inputs
24
+ | Goal | Command |
25
+ |---|---|
26
+ | Compare two or more releases | `compare releases/a.prg releases/b.prg releases/c.prg` |
27
+ | Compare a release that loads at a different address | `compare releases/a.prg releases/b.prg --shift 2:-256` |
28
+ | Compare only the bytes in a range | `compare releases/a.prg releases/b.prg --range '$0900-$09ff'` |
29
+ | Map two releases with moved code in blocks of equal bytes | `compare releases/a/image.json releases/b/image.json --align --range '$0400-$bfff'` |
30
+ | Find how each release uses each difference | `compare knowledge .c64-re-tools/local/b/image.json --frames 600 --steps .c64-re-tools/local/start-game.json` |
31
+ | Get the evidence for each range of the program in the project knowledge | `separate --out .c64-re-tools/local/separate.json` |
32
+ | Find the leftovers in the program | `leftovers --out .c64-re-tools/local/leftovers.json` |
33
+ | Find short texts, for example a group name | `leftovers --min-text 6` |
34
+ | Save a module of the program as a routine of the library | `routine '$1000' --library ../library` |
35
+ | Save a range of the program as a routine with a name | `routine '$1000-$1026' --name play --library ../library` |
36
+ | Find the routines of the library in the program | `match --library ../library` |
37
+ | Write the names of the found routines as a batch of changes | `match --library ../library --out .c64-re-tools/local/match.json` |
19
38
 
20
- - Two or more releases, relative to the project folder. A release is `knowledge` (the program in the knowledge), a PRG file, or an `image.json` from c64-unpacker capture with its `entry_state.json` beside it. Extract releases from disk images with the c64-disk skill. Unpack packed releases with the c64-unpacker skill first.
21
- - Optional: an address range to compare.
22
- - Optional: a shift for a release that loads at a different address.
23
- - Optional: `--align`, to map two releases with moved code in blocks of equal bytes.
24
- - Optional: a number of frames to run each release, and a steps file.
25
- - For one release: the program, the coverage and the other knowledge of the project. Put the program and the coverage in with `image` and `coverage` of the c64-knowledge skill.
26
- - For the library: the program and the other knowledge of its project, and the library folder.
39
+ ---
27
40
 
28
- ## Tools
41
+ ## Releases and the library
42
+
43
+ - `compare` takes two or more releases. A release is one of these:
44
+ - `knowledge`: the program in the project knowledge.
45
+ - A PRG file. The script puts it at its load address.
46
+ - The `image.json` of a capture of the unpacked program. Put its `entry_state.json` beside it. Without that file, `--frames` cannot start the release.
47
+ - Get a PRG out of a disk image before you compare it. The script refuses a disk image, a tape image and a cartridge image.
48
+ - Unpack a packed release before you compare it.
49
+ - The first release on the command line is release 1. `--shift` uses these numbers.
50
+ - `separate`, `leftovers`, `routine` and `match` read the program in the project knowledge. Put the program, its coverage and its code regions into the project knowledge first.
51
+ - The steps file of `--steps` is a JSON list of action steps, for example a key press that starts the game. The steps run before the frames.
52
+ - A library is a folder of routine files. Each file holds one routine: its bytes and its knowledge.
53
+ - Keep one library beside the project folders, for example `library/` at the root of the workspace. A library is not a project folder. Commit the library with the projects.
54
+ - `--library` is relative to the project folder. For example, `../library` is the folder `library/` beside the project.
55
+ - The subject of `routine` is the start address of a module, or a range `<start>-<end>`. Get the start addresses from the modules in the project knowledge.
56
+
57
+ ### Paths and the project folder
58
+
59
+ - Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
60
+ - If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
61
+ - An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
62
+ - A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
63
+ - Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
64
+ - 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.
65
+ - The script refuses an `--out` path in `.c64-re-tools/knowledge/` and the index of the knowledge. Change the project knowledge only with the commands that change it.
66
+ - The script refuses a folder where the command writes a file. It refuses a file where the command writes a folder.
67
+ - When a file is the evidence for a finding in the project knowledge, move it out of `.c64-re-tools/local/` first. The project knowledge refuses evidence in that folder.
68
+ - Do not move a coverage map after you put it into the project knowledge. The knowledge refers to the map by its path at that time.
69
+ - 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.
70
+ - 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`.
29
71
 
30
- ```
31
- node <skill>/scripts/provenance.ts compare releases/a.prg releases/b.prg releases/c.prg
32
- node <skill>/scripts/provenance.ts compare releases/a.prg releases/b.prg --shift 2:-256 --range '$0900-$09ff'
33
- node <skill>/scripts/provenance.ts compare releases/a/image.json releases/b/image.json --align --range '$0400-$bfff'
34
- node <skill>/scripts/provenance.ts compare knowledge .c64-re-tools/local/b/image.json --frames 600 --steps .c64-re-tools/local/start-game.json
35
- node <skill>/scripts/provenance.ts separate --out .c64-re-tools/local/separate.json
36
- node <skill>/scripts/provenance.ts leftovers --out .c64-re-tools/local/leftovers.json
37
- ```
72
+ ---
38
73
 
39
- | Option | Meaning |
40
- |---|---|
41
- | `--shift 2:-256` | Move release 2 (the first release is 1) by -256 bytes. Use it again for more releases. Give one shift for each release. |
42
- | `--range '$0900-$09ff'` | Compare only the addresses in this range. |
43
- | `--align` | Map release 1 to release 2 in blocks of equal bytes. Each block has its own shift. Give two releases. Do not use it with `--shift` or `--frames`. |
44
- | `--min-block 24` | With `--align`: the minimum number of bytes in a block. The default is 16. |
45
- | `--frames 600` | Run each release for this many frames, and give each listed difference its runtime evidence. |
46
- | `--steps .c64-re-tools/local/start-game.json` | With `--frames`: a JSON list of action steps to run before the frames, for example a key to start the game. The steps are the steps of a c64-unpacker steps file. |
74
+ ## Flags
75
+
76
+ Each flag applies only to the commands in the table. On another command, the script refuses the flag.
77
+
78
+ | Flag | Command | Effect |
79
+ |---|---|---|
80
+ | `--shift <release>:<bytes>` | `compare` | Move a release by a number of bytes. For example, `2:-256` moves release 2 by -256 bytes. Give one shift for each release. The default is no shift. |
81
+ | `--range <start>-<end>` | `compare` | Compare only the addresses in this range. The default is all addresses. |
82
+ | `--align` | `compare` | Map release 1 to release 2 in blocks of equal bytes. Each block has its own shift. Give two releases. Do not use it with `--shift` or `--frames`. Off by default. |
83
+ | `--min-block <n>` | `compare` | With `--align`: the minimum number of bytes in a block, from 8. The default is 16. |
84
+ | `--frames <n>` | `compare` | Run each release for `n` frames, and give each listed difference its runtime evidence. The default is no run. |
85
+ | `--steps <file>` | `compare` | With `--frames`: run the action steps of this file before the frames. The default is no steps. |
86
+ | `--out <file>` | `separate`, `leftovers`, `match` | `separate` and `leftovers` write all items to this file. `match` writes the batch of changes to this file. The default is no file. |
87
+ | `--max-listed <n>` | `separate`, `leftovers`, `match` | List at most `n` items of each list. The default is 50. `count` always gives the full number. |
88
+ | `--min-text <n>` | `leftovers` | The minimum number of characters in a text, from 4. The default is 8. A short text, for example a group name, can need 6. |
89
+ | `--library <folder>` | `routine`, `match` | Required. The library folder. |
90
+ | `--name <name>` | `routine` | The name of the routine and of its file. The default is the user or LLM name at the start of the routine. |
91
+ | `--title <text>` | `routine` | The title of the routine. The default is the title of the module. |
92
+ | `--replace` | `routine` | Write over a routine of the library with the same name. Off by default. |
93
+
94
+ ---
95
+
96
+ ## Compare releases
97
+
98
+ ### `compare <release>...`
99
+
100
+ Compares the releases byte by byte at the addresses where all releases have bytes.
101
+
102
+ `body` holds:
103
+
104
+ - `releases`: the `name`, the `shift` and the `segments` of each release. An image has bytes only in its segments.
105
+ - `common`: the ranges where all releases have bytes. The script compares only these ranges.
106
+ - `identicalBytes` and `differingBytes`: the counts of the bytes.
107
+ - `identicalShare`: the share of identical bytes, with 3 decimals. It is 1 only when no byte differs.
108
+ - `differences`: each item has `start`, `end`, `values` and `groups`. `values` gives the bytes of each release, at most 32. `groups` gives the releases that have the same bytes there.
109
+ - `moreDifferences: true`: `differences` holds only the first differences.
110
+ - `suggestedShifts`: only when `identicalShare` is less than 0.5. Each item has `release`, `shift` and `matchingSequences`. Each release has at most 3 shifts, with the most `matchingSequences` first. `current: true` marks the shift of this run.
111
+ - `shiftsNotSuggested`: each item has a `reason`. The reason tells why a shift does not fit in `$0000-$ffff`.
112
+
113
+ With `--shift`, the addresses of `segments`, `common` and `differences` are the release addresses plus the `shift` of the release.
114
+
115
+ With `--frames`, the body also holds:
47
116
 
48
- The script puts each PRG at its load address. An image has bytes only in its segments. The script compares the addresses where all releases have bytes.
117
+ - `runtime` in each difference: one item for each release that started. `start` and `end` are the addresses in the release, without the shift.
118
+ - `first`: the first access in that release: `read`, `write`, `execute` or `none`. An instruction that reads and then writes the same byte, for example INC, counts as `read`. The operand bytes of an executed instruction count as `execute`, for example the `$03` of `LDA #$03`.
119
+ - `changed`: `true` when the bytes at the end of the run are not the bytes of the release.
120
+ - `run`: `frames`, `steps` and `releases`. `releases` tells for each release if it started, or the `reason` that it did not start. `skipped` tells that the releases have no differences, so no release ran.
49
121
 
50
- With `--shift`, the addresses of `segments`, `common` and `differences` are the release addresses plus the `shift` of the release. The `start` and `end` of `runtime` are the addresses in the release itself, without the shift.
122
+ A PRG starts with RUN after its load. An image starts at its entry, with the state of `entry_state.json`.
51
123
 
52
- Use `--align` for two releases with added code and moved data. One shift does not fit them, and the shift suggestions are not useful. The map tells what each block of one release is in the other release. With `--align`, the result has the map, not `differences` and not the shift suggestions:
124
+ With `--align`, the body holds a map in place of `differences` and the shift suggestions:
53
125
 
54
126
  - `blocks`: the blocks of equal bytes, in the order of their addresses in release 1. `a` is the range in release 1. `b` is the range in release 2. `bytes` is the length of the block.
55
- - `shift`: the address in `b` minus the address in `a`. The address of a byte in release 2 is its address in release 1 plus the `shift` of its block. The blocks can have a different order in release 2, because code moved.
127
+ - `shift` of a block: the address in `b` minus the address in `a`. The blocks can have a different order in release 2, because code moved.
56
128
  - `onlyInA`: the ranges of release 1 that no block holds. Release 2 does not have these bytes, or it has other bytes there.
57
129
  - `onlyInB`: the ranges of release 2 that no block holds. Release 2 added these bytes, or it changed them.
58
130
  - `alignedShare`: the share of the bytes of the two releases that a block holds, with 3 decimals.
59
- - Each list shows at most 64 items. `moreBlocks`, `moreOnlyInA` and `moreOnlyInB` give the number of the items that the list does not show. Use `--range` to see them.
131
+ - Each list holds at most 64 items. `moreBlocks`, `moreOnlyInA` and `moreOnlyInB` count the other items.
60
132
 
61
- With `--frames`, a PRG starts with autostart and RUN. An image starts at its entry, with the entry state from `entry_state.json`. The run records the first access to each difference.
133
+ `hint` and `nextAction`:
62
134
 
63
- ### Calling the script
135
+ - `identicalShare` is low, and a shift is in `suggestedShifts`: `nextAction` runs `compare` with the first shift that the run does not have. Try each shift. Data that did not move and code that moved give different shifts.
136
+ - `identicalShare` is low, and no shift is better: `nextAction` runs `compare` with `--align`. The code and the data can be at other addresses in each release.
137
+ - `moreDifferences` or a `more...` count is in the body: `hint` tells you to compare a smaller `--range`.
64
138
 
65
- - Call a script as `node <skill>/scripts/<script>.ts <command> [subjects] [options]`. The command comes first.
66
- - `<script>.ts --help` lists the commands. `<script>.ts <command> --help` gives the subjects and the options of one command. The help is JSON: `{"text": "..."}`.
67
- - An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Quote an address in a shell.
68
- - A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
69
- - Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
70
- - The script examines each `--out` path before it starts work. It refuses a path in `.c64-re-tools/knowledge/` and the index of the knowledge, because only c64-knowledge writes them. It refuses a folder where the command writes a file, and a file where the command writes a folder.
71
- - The result is one JSON object on one line. A file that the script writes shows as `{"out", "bytes", "sha256"}`. A list shows as `{"count", "listed"}`, and `rest` tells where to get the rest of a long list.
72
- - An error is `{"error": {"code": "...", "message": "..."}}`. The message tells what is wrong and what to do.
73
- - The exit status is 0 for done or PASS, 1 for FAIL, 2 for an error and 3 for INCONCLUSIVE.
139
+ Traps:
74
140
 
75
- ### Project folder
141
+ - `common` is empty: the releases do not have bytes at the same addresses. Give `--shift`, or a `--range` that all releases have.
142
+ - A release has `started: false`: the PRG has no BASIC start, or the image has no `entry_state.json`. The `reason` tells which. The other releases still give evidence.
143
+ - Each release writes a range before it reads it: the range is probably runtime state, not a difference of the releases.
144
+ - A range has `first: none` in each release: the run did not use it. Run more frames or other steps before you decide.
145
+ - The script refuses `--align` with `--shift` or `--frames`. It refuses `--min-block` without `--align`, and `--steps` without `--frames`.
146
+ - Error `not-found`: the project has no file at that path.
76
147
 
77
- - Paths are relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
78
- - If the working directory is not in a project and has projects below it, the script refuses and lists them. Then give `--project <folder>` to each script.
79
- - 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.
80
- - Move a file out of `.c64-re-tools/local/` only when it is the evidence for a finding. Move it before you give it to `--evidence test:<file>` or `--evidence file:<file>` of c64-knowledge. These two refuse a file in `.c64-re-tools/local/`.
81
- - Do not move a coverage map after `coverage` of c64-knowledge imported it. `--evidence coverage:<map>` names the map by its path at the import. The knowledge keeps the coverage and the SHA-256 of the map, so the evidence stays valid.
82
- - Put a run that is evidence in `runs/<name>/`, with its run file, its results and the snapshot files that it uses. Change the paths in the run file to the new paths. Then git keeps them, and another person can do the run again.
83
- - 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`.
148
+ ---
84
149
 
85
- ## Workflow
150
+ ## Evidence from one program
86
151
 
87
- 1. Run the script on the releases.
88
- 2. Read `identicalShare`. If it is low and `suggestedShifts` is present, the releases are at different addresses. Run the script again with a `--shift` of `suggestedShifts`. `shiftsNotSuggested` tells why a found shift does not fit in `$0000-$ffff`. If no shift gives a high `identicalShare`, the code and the data can be at other addresses in each release. Then run the script again with `--align`.
89
-
90
- `suggestedShifts` has at most 3 shifts for each release. The shift with the most `matchingSequences` is first. Data that did not move and code that moved give different shifts. Try each shift. `current: true` marks the shift of this run.
91
- 3. Read `differences`. Each one has an address range, the bytes of each release, and `groups`: the releases that have the same bytes there.
92
- 4. To know how the program uses the differences, run the script again with `--frames` and the frames that get the program to the part you examine. Read `runtime` of each difference:
93
- - `first`: the first access in that release: `read`, `write`, `execute` or `none`. An instruction that reads and then writes the same byte, for example INC, counts as `read`. The operand bytes of an executed instruction count as `execute`, for example the value of `LDA #$03`.
94
- - `changed`: `true` when the bytes at the end of the run are not the bytes of the release.
95
- - A range that each release writes before it reads is probably runtime state, not a difference of the releases.
96
- - A range with `none` in each release is not used in this run. Run more frames or other steps before you decide.
97
- - `run.skipped`: the releases have no differences, so no release ran.
98
- 5. Examine each important difference:
99
- - Disassemble the bytes of each release with the emulator skill, or analyze them with the c64-static-analysis skill.
100
- - Find what the change does, for example a trainer, a removed copy protection, or a changed text.
101
- 6. Decide which bytes are probably the original application. Use more than the byte comparison: the code, the text, and the history of the releases.
102
- 7. Record each release with `release` of the c64-knowledge skill. The base release is the program of the knowledge.
103
- 8. Record each difference as a switch and a patch with the c64-knowledge skill. Select the kind of the switch:
104
- - `protection`: a copy protection, or the code that a crack changed to remove it.
105
- - `trainer` or `cheat`: a trainer or a cheat.
106
- - `crack`: another change of a cracker in the program, for example a credit text.
107
- - `fix`: a correction of a bug. Make one switch for each correction, not one switch for each release.
108
- - `change`: another difference.
109
- 9. Give the switch the labels of the releases that have it on. The patch holds the bytes of the state that the base release does not have.
110
- 10. Record each other conclusion as a comment or a region with the c64-knowledge skill.
152
+ ### `separate`
153
+
154
+ Gives evidence from the program in the project knowledge, its stages and its coverage. It gives evidence, not a decision.
155
+
156
+ `body` holds:
111
157
 
112
- ## One release
158
+ - `entry`: the entry of the program.
159
+ - `stages` and `bytesByStage`: the number of unpack stages, and the bytes of each stage. `none` counts the bytes that no stage wrote.
160
+ - `noStages`: the program has no stage log. Only a capture of the unpack stages has one.
161
+ - `bytesByAccess`: the bytes of each access in the coverage.
162
+ - `ranges`: the program in ranges with the same stage and access.
163
+ - `stage` is the last unpack stage that wrote the range. The last stage is the program. An earlier stage is a depacker, an intro or a loader.
164
+ - `access` is `executed`, `read`, `written`, `read-written` or `untouched`. `untouched` bytes did not take part in the runs.
165
+ - A `read` byte right after executed code, or at a return address, can be a dummy read of the 6502. The program does not use it.
166
+ - `roots`: the addresses where the reachability starts, each with `address` and `from`. The roots are the entry, and the NMI, RESET and IRQ vectors at `$fffa`-`$ffff` when the program holds them. A text in place of the list tells why no code region is reachable.
167
+ - `codeRegions.total`: the number of code regions in the project knowledge.
168
+ - `codeRegions.unreachable`: the code regions that no chain of call and jump references reaches from a root. The CPU also continues into the next code region when the last instruction of a region is not RTS, RTI, JMP, BRK or JAM.
169
+ - `outside`: only with coverage. `read` and `executed` give the RAM outside the program that the program used but did not write. A loader or an earlier stage put these bytes there. `generated` gives the code that the program wrote outside its segments. A `generated` range can have gaps of two bytes or less: these are operand bytes.
170
+ - `out`, `bytes` and `sha256`: the file of `--out`. It holds the roots, and all ranges, code regions and outside ranges.
113
171
 
114
- Use `separate` when you have only one release. It reads the program, its stages and the coverage from the knowledge. It gives evidence, not a decision:
172
+ `hint`: a list is cut. Without `--out`, give a larger `--max-listed`, or give `--out`. With `--out`, read the file.
115
173
 
116
- - `ranges`: the program in ranges with the same stage and access. `stage` is the last unpack stage that wrote the range. The last stage is the program. An earlier stage is a depacker, an intro or a loader. Only a capture of c64-unpacker `capture` has stages. For a program from `loads` or a PRG, `noStages` tells this.
117
- - `access`: from the coverage of the knowledge: `executed`, `read`, `written`, `read-written` or `untouched`. `untouched` bytes did not take part in the runs. A `read` byte right after executed code, or at a return address, can be a dummy read of the 6502 that the program does not use.
118
- - `codeRegions.total`: the number of code regions in the knowledge.
119
- - `roots`: the addresses where the reachability starts. They are the entry, and the NMI, RESET and IRQ vectors at `$FFFA`-`$FFFF` when the image holds them. An interrupt handler starts from its vector, because no call or jump goes to it. `from` tells the source of each root.
120
- - `codeRegions.unreachable`: code regions of the knowledge that no chain of call and jump references reaches from a root. A region also reaches the code after it when its last instruction is not RTS, RTI, JMP, BRK or JAM: the CPU continues there. Run c64-static-analysis first, so that the knowledge has the code regions and the references.
121
- - `outside`: RAM outside the program that the program `read` or `executed` but did not write, and code it `generated`. A loader or an earlier stage put the bytes that the program did not write. A `generated` range can have gaps of two bytes or less: these are operand bytes.
174
+ Traps:
122
175
 
123
- Each list has `count` and `listed`. `listed` has the first ranges, at most `--max-listed` (default 50). `--out` writes all of them and the result shows the file as `{out, bytes, sha256}`. Run more coverage runs for parts that are `untouched`, and add them with `coverage` of the c64-knowledge skill, before you decide.
176
+ - No code regions in the project knowledge: `codeRegions` is empty. Analyze the program for its code regions and its references first.
177
+ - Many `untouched` ranges: do more coverage runs for these parts. Put the coverage into the project knowledge before you decide.
178
+ - Error `not-found`: the project knowledge has no program. Put the program into the project knowledge.
124
179
 
125
- ## Leftovers
180
+ ### `leftovers`
126
181
 
127
- Use `leftovers` to find what the program holds in addition to its working code. It reads the program, its stages, the coverage and the code regions from the knowledge, as `separate` does. It gives evidence, not a decision. Each list has `count` and `listed`, as in `separate`. `--out` writes all findings.
182
+ Finds what the program in the project knowledge holds in addition to its working code. It gives evidence, not a decision.
183
+
184
+ `body` holds `entry`, `roots`, and `stages` or `noStages`, as `separate` gives them. `noCoverage` tells that the project knowledge has no coverage. Then `residue` is empty and no finding has `access`. The body also holds these lists:
128
185
 
129
186
  | List | What it holds |
130
187
  |---|---|
131
- | `text` | Text, and lines of assembler source. `encoding` is `petscii`, `screen`, `ascii` or `high-bit`. `reversed: true` marks screen codes with bit 7 set. `source: true` marks lines of assembler source. A line end in `text` is a new line. `mnemonics` counts 6502 instructions in the text. |
132
- | `basic` | Two or more BASIC lines away from the BASIC start. `linkedAt` is the address where BASIC linked the lines. It can be another address than the address of the bytes now. |
133
- | `fill` | One byte that repeats, at least 16 times, or a pattern of two to four bytes that repeats, at least 32 bytes in total. `pattern` is the repeated bytes. |
134
- | `residue` | Bytes that no run touched and that are no text, BASIC, fill or code region. `bytes` shows the first 16 bytes. |
135
- | `copies` | Bytes that are the same as earlier bytes of the program, at least 32 bytes. `copyOf` is the address of the earlier bytes. |
136
- | `deadCode` | Code regions of the knowledge that no root reaches, as in `codeRegions.unreachable` of `separate`, and that no run executed. |
137
-
138
- Text from another computer can show the tools of the developer:
188
+ | `text` | Text, and lines of assembler source. `encoding` is `petscii`, `screen`, `ascii` or `high-bit`. `reversed: true` marks screen codes with bit 7 set. `source: true` marks lines of assembler source. A line end in `text` is a new line. `mnemonics` counts 6502 instructions in the text. A text of more than 120 characters is cut, and `length` gives its full length. |
189
+ | `basic` | Two or more BASIC lines away from the BASIC start. `linkedAt` is the address where BASIC linked the lines. It can be a different address from the address of the bytes now. |
190
+ | `fill` | One byte that repeats at least 16 times, or a pattern of two to four bytes that repeats for at least 32 bytes. `pattern` is the repeated bytes. |
191
+ | `residue` | Bytes that no run touched, and that are not text, BASIC, fill or a code region. `bytes` shows the first 16 bytes. |
192
+ | `copies` | At least 32 bytes that are the same as earlier bytes of the program. `copyOf` is the address of the earlier bytes. |
193
+ | `deadCode` | Code regions that no root reaches, as in `codeRegions.unreachable` of `separate`, and that no run executed. |
139
194
 
140
- - `ascii` is text in ASCII, with small letters. A cross assembler on another computer can leave it.
141
- - `high-bit` is text with bit 7 set. The Apple II keeps text in this form, with `$8d` at the end of a line. Apple II assembler source, for example from Merlin, has `DFB` lines and `*` comments. A C64 text in shifted letters with `$a0` spaces is also `high-bit`.
142
- - Data of another computer, for example a table of Atari key codes, is not text. The script does not find it. Examine `residue` and the data that no code reads, and use your knowledge of the other computers.
195
+ Each finding has `stages`: the unpack stages that wrote its bytes. A stage before the last stage is a depacker, an intro or a loader. Each finding also has `access`: the accesses of its bytes in the coverage.
143
196
 
144
- Each finding has `stages`: the unpack stages that wrote its bytes. Each finding also has `access`: the accesses of its bytes in the coverage. A stage before the last stage is a depacker, an intro or a loader.
197
+ `out`, `bytes` and `sha256` give the file of `--out`. It holds all findings with the full texts.
145
198
 
146
- | Option | Meaning |
147
- |---|---|
148
- | `--min-text 6` | The minimum number of characters in a text. The default is 8. A short text, for example a group name, can need 6. |
199
+ `hint`: a list is cut. Without `--out`, give a larger `--max-listed`, or give `--out`. With `--out`, read the file.
149
200
 
150
- Do these steps:
201
+ Text from another computer can show the tools of the developer:
151
202
 
152
- 1. Unpack the program with `stages` or `capture` of the c64-unpacker skill. Put the capture into the knowledge.
153
- 2. Add the coverage of runs that use many parts of the program. Without coverage, `residue` is empty and no finding has `access`. `noCoverage` tells this.
154
- 3. Run c64-static-analysis. Without code regions, `deadCode` is empty, and `residue` can include code.
155
- 4. Run `leftovers`. When you have two or more releases, also compare them.
156
- 5. Read `text` first: names, dates, greetings and credits. Then read `copies`, `residue`, `basic` and `deadCode`.
157
- 6. Examine each important finding with the emulator skill or the c64-static-analysis skill.
158
- 7. Record each confirmed finding with the c64-knowledge skill. Do not remove a leftover from the program: a rebuild keeps it. Only the data of a cracktro goes out, with `capture --exclude` of the c64-unpacker skill. Classify a confirmed PETSCII text as a `petscii` region, and a screen code text as a `screen` region. Classify other text as `bytes`. Write a comment that tells what the leftover is.
203
+ - `ascii` is text in ASCII, with small letters. A cross assembler on another computer can leave it.
204
+ - `high-bit` is text with bit 7 set. The Apple II keeps text in this form, with `$8d` at the end of a line. Apple II assembler source, for example from Merlin, has `DFB` lines and `*` comments. A C64 text in shifted letters with `$a0` spaces is also `high-bit`.
205
+ - The script does not find data of another computer, for example a table of Atari key codes. Examine `residue` and the data that no code reads. Use your knowledge of the other computers.
159
206
 
160
207
  Read the findings with care:
161
208
 
162
- - A text is a run of bytes that looks like text. Some runs are data, for example a character map. A text can include one byte before it or after it that is not part of the text.
209
+ - A text is a sequence of bytes that looks like text. Some of them are data, for example a character map. A text can include one byte before it or after it that is not part of the text.
163
210
  - A copy is not always a leftover. A program can copy its code to another address before it runs the code.
164
211
  - A text in an early stage is often a crack intro. A text that no run read can be an old text of an earlier release.
165
212
  - Keep the fact apart from the conclusion. "Text at $4770" is a fact. "A recrack by group X" is a conclusion.
166
213
 
214
+ Traps:
215
+
216
+ - No coverage: `residue` is empty. Put the coverage of runs that use many parts of the program into the project knowledge.
217
+ - No code regions: `deadCode` is empty, and `residue` can include code. Analyze the program for its code regions first.
218
+ - Error `not-found`: the project knowledge has no program. Put the program into the project knowledge.
219
+
220
+ ---
221
+
167
222
  ## Library of routines
168
223
 
169
- A library is a folder of routine files. Each file holds one routine: its bytes and its knowledge. Keep one library beside the project folders, for example `library/` at the root of the workspace. A library is not a project folder. Commit it with the projects.
224
+ ### `routine <module|range>`
170
225
 
171
- `--library` is relative to the project folder, as all other paths. For example, `../library` is the folder `library/` beside the project.
226
+ Saves a routine of the program in the project knowledge to the library. The file keeps the user and LLM names, comments, regions, references and operand expressions in the range. It also keeps the code regions of each origin.
172
227
 
173
- ```
174
- node <skill>/scripts/provenance.ts routine '$1000' --library ../library --project game-a
175
- node <skill>/scripts/provenance.ts routine '$1000-$1026' --name play --library ../library --project game-a
176
- node <skill>/scripts/provenance.ts match --library ../library --out .c64-re-tools/local/match.json --project game-b
177
- ```
228
+ - A module ends at the next module, or at the end of its segment.
229
+ - A routine has at least 16 bytes. Its last instruction must end in the range.
230
+ - Name the routine in the project knowledge before you save it, or give `--name`.
231
+
232
+ `body` holds:
233
+
234
+ - `routine`: the name of the routine.
235
+ - `out`, `bytes` and `sha256`: the routine file. `out` is relative to the project folder.
236
+ - `start`, `end` and `length`: the range of the routine in the program.
237
+ - `instructions`: the count of the instructions.
238
+ - `relocations`: the count of the addresses into the routine.
239
+ - `variable`: the count of the operand bytes that address something outside the routine.
240
+ - `counts`: the number of symbols, regions, comments, references and operands that the file keeps.
241
+ - `leftOut`: the rows that the file does not keep, and why. For example, the file does not keep an operand expression that uses a name outside the routine.
242
+
243
+ Traps:
244
+
245
+ - Error `not-found` with "No module starts at": list the modules of the project knowledge, or give a range.
246
+ - Error `invalid-input` with "no code region": analyze the program for its code regions first, or classify the code in the project knowledge.
247
+ - Error `invalid-input` with "no user or LLM name": give `--name`.
248
+ - Error `conflict`: the library has a routine with that name. Give another `--name`, or give `--replace` to write over it.
249
+ - Error `invalid-input` with "is a project folder": the library folder is a project. Give a folder beside the projects.
250
+
251
+ ### `match`
252
+
253
+ Finds each routine of the library in the program of the project knowledge.
254
+
255
+ - The opcodes and the other bytes must be equal.
256
+ - An address into the routine must point into the routine at its new address.
257
+ - An operand that addresses something outside the routine can be different.
258
+
259
+ `body` holds:
260
+
261
+ - `library` and `routines`: the library folder and the number of routines in it.
262
+ - `matches`: each item has `routine`, `start`, `end` and `shift`. `shift` is the address in the program minus the address in the library.
263
+ - `differing` in each match: each operand that addresses something outside the routine and that is different. It gives the value in the `library` and in the `program`. Examine each one. For example, the program can use other variables or another SID voice.
264
+ - `batch`: only with `--out`. `out`, `bytes` and `sha256` give the batch file. `writes` counts its writes. `known` counts the writes that the project knowledge has already. `leftOut` lists the writes that the script left out, and why.
265
+
266
+ The batch has the names, regions, comments, references and operand expressions of each routine at its address in the program. The script leaves out a write in these conditions:
267
+
268
+ - The program has a user or LLM row at that place.
269
+ - The program uses the name at another address.
270
+ - A removal holds at that place.
271
+ - The routine occurs two times. Only the first copy gets the names.
272
+ - The script left out the name that an operand expression uses, or the expression does not give the operand in the program.
273
+
274
+ `hint` and `nextAction`:
178
275
 
179
- To save a routine:
276
+ - Without `--out`, with matches: `nextAction` runs `match` with `--out`. Examine `differing` of each match first.
277
+ - With `--out`, with writes: `hint` tells you to apply the changes in the batch file to the project knowledge. Read `batch.leftOut` first. Apply the changes as one revision of the LLM.
278
+ - No match: `hint` tells that a packed program can hold a routine in a packed form. Unpack the program, put it into the project knowledge, and run `match` again.
180
279
 
181
- 1. Put the program into the knowledge, and name the routine there first. The file keeps the user and LLM names, comments, regions, references and operand expressions in the range. It also keeps the code regions of each origin.
182
- 2. Run `routine` with the start address of a module, or with a range `<start>-<end>`. A module ends at the next module or at the end of its segment.
183
- - `--name` is the name of the routine and of its file. When you do not give it, the script uses the user or LLM name at the start.
184
- - `--title` is the title of the routine. When you do not give it, the script uses the module title.
185
- - A routine has at least 16 bytes. Its last instruction must end in the range.
186
- 3. The result shows the routine file as `{out, bytes, sha256}`. `out` is relative to the project folder.
187
- 4. Read `leftOut`. It lists the rows that the file does not keep, and why. For example, the file does not keep an operand expression that uses a name outside the routine.
280
+ Traps:
188
281
 
189
- To find the routines in a program:
282
+ - `match` does not change the project knowledge.
283
+ - Error `not-found`: the library folder does not exist, or it has no routine files. Save a routine with `routine` first.
284
+ - Error `invalid-input` with "is a project folder": the library folder is a project. Give a folder beside the projects.
190
285
 
191
- 1. Put the program into the knowledge. Then run `match`. The script examines each routine of the library at each address of the program.
192
- - The opcodes and the other bytes must be equal.
193
- - An address into the routine must point into the routine at its new address. `shift` is the address in the program minus the address in the library.
194
- - An operand that addresses something outside the routine can be different. `differing` lists each one with its value in the library and in the program. Examine them. For example, the program can use other variables or another SID voice.
195
- 2. Give `--out` to get a batch for `knowledge.ts apply`. `batch` shows the file as `{out, bytes, sha256}`. The batch has the names, regions, comments, references and operand expressions of each routine at its addresses in the program. `match` does not change the knowledge.
196
- 3. Read `batch.leftOut` before you apply the batch. The script leaves out a write in these conditions:
197
- - The program has a user or LLM row at that place.
198
- - The program uses the name at another address.
199
- - A removal holds at that place.
200
- - The routine occurs two times. Only the first copy gets the names.
201
- - The script leaves out the name that an operand expression uses, or the expression does not give the operand in the program.
202
- 4. Apply the batch with the command in `apply`. Add `--project` when you are not in the project folder. The batch is one revision of the LLM. `batch.known` counts the writes that the program has already.
286
+ ---
203
287
 
204
- ## Knowledge
288
+ ## Workflow
205
289
 
206
- Automatic write:
207
- - none.
290
+ ### Compare releases
208
291
 
209
- Record a confirmed conclusion as a normal comment, region, symbol, release, switch or patch with the c64-knowledge skill. Do not record the full comparison or the full list of leftovers.
292
+ 1. Run `compare` on the releases.
293
+ 2. Read `identicalShare`. If it is low, run the `nextAction`. Try each shift in `suggestedShifts`. If no shift gives a high `identicalShare`, run `compare` with `--align`.
294
+ 3. Read `differences`.
295
+ 4. To find how the program uses the differences, run `compare` again with `--frames`. Give the frames and the steps that get the program to the part that you examine. Read `runtime` of each difference.
296
+ 5. Examine each important difference. Disassemble or analyze the bytes of each release. Find what the change does, for example a trainer, a removed copy protection, or a changed text.
297
+ 6. Decide which bytes are probably the original application. Use more than the byte comparison: the code, the text, and the history of the releases.
298
+ - Do not call releases independent when you do not know their relation. Two cracks can come from the same source.
299
+ - Do not call a byte original only because one release has it. A majority of releases is also not proof.
300
+ 7. Record each release in the project knowledge. The base release is the program in the project knowledge.
301
+ 8. Record each difference in the project knowledge as a switch and a patch. Select the kind of the switch:
302
+ - `protection`: a copy protection, or the code that a crack changed to remove it.
303
+ - `trainer` or `cheat`: a trainer or a cheat.
304
+ - `crack`: another change of a cracker in the program, for example a credit text.
305
+ - `fix`: a correction of a bug. Make one switch for each correction, not one switch for each release.
306
+ - `change`: another difference.
307
+ 9. Give the switch the labels of the releases that have it on. The patch holds the bytes that the base release does not have.
308
+ 10. Record each other conclusion in the project knowledge as a comment or a region. Do not record the full comparison.
210
309
 
211
- `match --out` writes a batch file and does not change the knowledge. Apply the batch with the c64-knowledge skill.
310
+ ### Find the leftovers
212
311
 
213
- ## Result
312
+ 1. Capture the unpack stages of the program, and put the capture into the project knowledge.
313
+ 2. Put the coverage of runs that use many parts of the program into the project knowledge.
314
+ 3. Analyze the program for its code regions.
315
+ 4. Run `leftovers`. When you have two or more releases, also run `compare`.
316
+ 5. Read `text` first: names, dates, greetings and credits. Then read `copies`, `residue`, `basic` and `deadCode`.
317
+ 6. Examine each important finding. Disassemble or analyze its bytes, or examine them in the emulator.
318
+ 7. Record each finding that you proved in the project knowledge. Do not record the full list of leftovers.
319
+ - Do not remove a leftover from the program. A rebuild keeps it. Only the data of a cracktro goes out: leave it out of the capture of the program.
320
+ - Classify a PETSCII text that you proved as a `petscii` region, and a screen code text as a `screen` region. Classify other text as `bytes`.
321
+ - Write a comment that tells what the leftover is.
214
322
 
215
- The differing ranges with the bytes of each release and the groups that agree, and the share of identical bytes. `identicalShare` has 3 decimals. It is 1 only when no byte differs. `identicalBytes` and `differingBytes` give the counts. `common` gives the ranges where all releases have bytes. `releases` gives the segments and the `shift` of each release. With `--frames`, each difference also has `runtime`, and `run` tells if each release started, or why not. With `--align`, the result has `blocks`, `onlyInA`, `onlyInB` and `alignedShare` in place of `differences`.
323
+ ### Share routines
216
324
 
217
- For `leftovers`: the lists of findings, with `entry`, `roots` and the number of `stages`. `noStages` and `noCoverage` tell which knowledge is missing. Without a root, `roots` tells why `deadCode` is empty.
325
+ 1. Put the program into the project knowledge, and name the routine there.
326
+ 2. Run `routine`. Read `leftOut`.
327
+ 3. In another project, put the program into the project knowledge. Run `match`.
328
+ 4. Run `match` with `--out`. Read `batch.leftOut`.
329
+ 5. Apply the changes in the batch file to the project knowledge.
330
+
331
+ ---
218
332
 
219
- The runtime evidence and the leftovers are evidence only. The script does not decide which bytes are original.
333
+ ## JSON output
220
334
 
221
- ## Failure and conflicts
335
+ Each command prints one JSON envelope on one line on stdout. Notes go to stderr.
222
336
 
223
- - Do not call releases independent when you do not know their relation. Two cracks can come from the same source.
224
- - Do not call a byte original only because one release has it. A majority of releases is also not proof.
225
- - `common` is empty: the releases do not cover the same addresses. Use `--shift`, or compare a range that all releases cover.
226
- - `run.releases` shows `started: false`: a PRG without a BASIC start, or an image without `entry_state.json`. The reason tells which. The other releases still give evidence.
227
- - `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own emulator script.
228
- - `moreDifferences: true`: the script shows only the first differences. Use `--range` to see the others.
229
- - `not-found`: the project has no file at that path.
230
- - `not-found` from `match`: the library folder does not exist, or it has no routine files. Save a routine with `routine` first.
231
- - `conflict` from `routine`: the library has a routine with that name. Give another `--name`, or give `--replace` to save over it.
232
- - `invalid-input` with "is a project folder": the library folder is a project. Give a folder beside the projects.
233
- - `match` gives `count: 0`: the routine is not in the program. A packed program can hold the routine in a packed form. Unpack the program with c64-unpacker first.
234
- - `invalid-input`: a file, an address or a shift is wrong. A path that goes out of the project folder is also wrong, also through a link. Read the message.
337
+ On success, the exit code is 0:
235
338
 
236
- ## Handoffs
339
+ ```json
340
+ {"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}
341
+ ```
342
+
343
+ On failure, the exit code is 2:
344
+
345
+ ```json
346
+ {"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}
347
+ ```
348
+
349
+ - `body` holds the result. The section of each command gives the fields of its body.
350
+ - 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.
351
+ - `error` is one sentence. It tells what is wrong.
352
+ - `hint` tells what to do or what to examine. Read it before your next step. Some envelopes have no `hint`.
353
+ - `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task. Some envelopes have no `nextAction`.
354
+ - `code` does not change between versions. Do the action for the code:
355
+
356
+ | `code` | Action |
357
+ |---|---|
358
+ | `installation-incomplete`, `machine-unavailable` | Stop the task. Give `error` and `hint` to the user and wait for the user. Do not install, start or change a tool. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script. |
359
+ | `invalid-input`, `not-found` | Correct the call as `hint` tells. Then run the command again. |
360
+ | `operation-failed` | Give `error` and `hint` to the user. |
361
+ | Another code | Do as `hint` tells. |
362
+
363
+ These fields have the same meaning in each body:
364
+
365
+ | Field | Meaning |
366
+ |---|---|
367
+ | `out`, `bytes`, `sha256` | A file that the command wrote: its path, its size and its SHA-256. |
368
+ | `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. |
237
369
 
238
- - Get releases from disk images → c64-disk
239
- - Unpack a packed release → c64-unpacker
240
- - Run or examine the different code → emulator
241
- - Analyze the different code → c64-static-analysis
242
- - Record a conclusion → c64-knowledge
243
- - Apply the batch of `match` → c64-knowledge
370
+ 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.
371
+ To get the subjects and the flags of one command, run `<command> --help`. Then `body.subjects` and `body.options` give them.