@henols/c64-re-tools 2.0.0-rc.11 → 2.0.0-rc.13

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 (54) hide show
  1. package/README.md +7 -5
  2. package/package.json +1 -1
  3. package/skills/c64-assembler/SKILL.md +11 -2
  4. package/skills/c64-assembler/scripts/assemble.ts +4 -4
  5. package/skills/c64-basic/SKILL.md +8 -1
  6. package/skills/c64-basic/scripts/basic.ts +3 -3
  7. package/skills/c64-disk/SKILL.md +10 -3
  8. package/skills/c64-disk/scripts/disk.ts +4 -4
  9. package/skills/c64-emulator/SKILL.md +4 -0
  10. package/skills/c64-knowledge/SKILL.md +62 -12
  11. package/skills/c64-knowledge/scripts/knowledge.ts +352 -102
  12. package/skills/c64-memory-map/SKILL.md +7 -0
  13. package/skills/c64-memory-map/scripts/memmap.ts +1 -1
  14. package/skills/c64-provenance/SKILL.md +56 -3
  15. package/skills/c64-provenance/scripts/library.ts +584 -0
  16. package/skills/c64-provenance/scripts/provenance.ts +201 -9
  17. package/skills/c64-reverse-engineering/SKILL.md +16 -2
  18. package/skills/c64-source/SKILL.md +38 -7
  19. package/skills/c64-source/scripts/generate.ts +213 -29
  20. package/skills/c64-source/scripts/loader.ts +3 -1
  21. package/skills/c64-source/scripts/opcodes.ts +19 -0
  22. package/skills/c64-source/scripts/source.ts +387 -35
  23. package/skills/c64-static-analysis/SKILL.md +11 -2
  24. package/skills/c64-static-analysis/scripts/analyze.ts +95 -8
  25. package/skills/c64-static-analysis/scripts/macros.ts +233 -0
  26. package/skills/c64-testing/SKILL.md +8 -1
  27. package/skills/c64-testing/references/scenario-format.md +1 -1
  28. package/skills/c64-testing/scripts/checklist.ts +2 -2
  29. package/skills/c64-testing/scripts/run.ts +4 -4
  30. package/skills/c64-testing/scripts/scenario.ts +1 -1
  31. package/skills/c64-testing/scripts/test.ts +4 -4
  32. package/skills/c64-unpacker/SKILL.md +11 -4
  33. package/skills/c64-unpacker/scripts/unpack.ts +4 -4
  34. package/src/cli/main.ts +5 -3
  35. package/src/host-client/image.ts +1 -1
  36. package/src/host-client/transfer.ts +34 -10
  37. package/src/host-client/vice-session.ts +9 -9
  38. package/src/knowledge/conflicts.ts +157 -0
  39. package/src/knowledge/database.ts +150 -38
  40. package/src/knowledge/history.ts +54 -20
  41. package/src/knowledge/import.ts +3 -2
  42. package/src/knowledge/read.ts +169 -20
  43. package/src/knowledge/schema.ts +115 -72
  44. package/src/knowledge/text.ts +391 -0
  45. package/src/knowledge/write.ts +508 -51
  46. package/src/mcp/output.ts +14 -7
  47. package/src/mcp/tools/debug.ts +8 -6
  48. package/src/mcp/tools/media.ts +17 -13
  49. package/src/mcp/tools/memory.ts +9 -5
  50. package/src/mcp/tools/video.ts +6 -5
  51. package/src/platform.ts +28 -5
  52. package/src/project.ts +166 -3
  53. package/src/protocol/tools.ts +1 -1
  54. package/src/script.ts +46 -7
@@ -38,6 +38,13 @@ Write an address or a value as `$` and hex digits, as a decimal number, or as `%
38
38
 
39
39
  The script prints one JSON object.
40
40
 
41
+ ### Project folder
42
+
43
+ - 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/`.
44
+ - 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.
45
+ - Keep the results, batches and step files that you save for yourself in `.c64-re-tools/local/` of the project. Git ignores that folder.
46
+ - 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`.
47
+
41
48
  ## Workflow
42
49
 
43
50
  1. Run `at` for the addresses in the code or the question.
@@ -89,4 +89,4 @@ function run(argv: string[]): unknown {
89
89
  }
90
90
  }
91
91
 
92
- await runScript(() => run(process.argv.slice(2)), { usage: USAGE });
92
+ await runScript((argv) => run(argv), { usage: USAGE });
@@ -1,6 +1,6 @@
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. With one release, it gives evidence for each range: the unpack stage, the access, and the code that the entry does not reach. Use the result to separate the content of the application from changes that a release added. Do not use it to analyze the code.
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. With one release, it gives evidence for each range: the unpack stage, the access, and the code that the entry does not reach. 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 a program and writes their names as a batch for c64-knowledge. Do not use it to analyze the code.
4
4
  ---
5
5
 
6
6
  # c64-provenance
@@ -9,15 +9,18 @@ description: Use this skill to compare two or more releases of a C64 program, fo
9
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
11
 
12
+ 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.
13
+
12
14
  This skill does not change project knowledge.
13
15
 
14
16
  ## Inputs
15
17
 
16
- - Two or more releases, relative to the project directory. A release is a PRG file or an `image.json` from c64-unpacker capture. Extract releases from disk images with the c64-disk skill. Unpack packed releases with the c64-unpacker skill first.
18
+ - Two or more releases, relative to the project folder. A release is a PRG file or an `image.json` from c64-unpacker capture. Extract releases from disk images with the c64-disk skill. Unpack packed releases with the c64-unpacker skill first.
17
19
  - Optional: an address range to compare.
18
20
  - Optional: a shift for a release that loads at a different address.
19
21
  - Optional: a number of frames to run each release, and a steps file.
20
22
  - For one release: the release, coverage files, and the knowledge of the project.
23
+ - For the library: the image of a program, the knowledge of its project, and the library folder.
21
24
 
22
25
  ## Tools / execution path
23
26
 
@@ -44,6 +47,13 @@ With `--shift`, the addresses of `segments`, `common` and `differences` are the
44
47
 
45
48
  With `--run`, a PRG starts with autostart and RUN. An image starts from its bytes: the script writes the segments and the entry state from `entry_state.json` into the emulator, and starts at the entry. Watchpoints on each difference stop the run at its first access.
46
49
 
50
+ ### Project folder
51
+
52
+ - 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/`.
53
+ - 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.
54
+ - Keep the results, batches and step files that you save for yourself in `.c64-re-tools/local/` of the project. Git ignores that folder.
55
+ - 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`.
56
+
47
57
  ## Workflow
48
58
 
49
59
  1. Run the script on the releases.
@@ -75,6 +85,42 @@ Use `separate` when you have only one release. It gives evidence, not a decision
75
85
 
76
86
  Each list has `count` and `listed`. `listed` has the first ranges, at most `--max-listed`. `--out` writes all of them. Run more coverage runs for parts that are `untouched` before you decide.
77
87
 
88
+ ## Library of routines
89
+
90
+ 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.
91
+
92
+ `--library` is relative to the working directory, as `--project`. All other paths are relative to the project folder.
93
+
94
+ ```
95
+ node <skill>/scripts/provenance.ts routine unpacked/image.json --module '$1000' --library library --project game-a
96
+ node <skill>/scripts/provenance.ts routine game.prg --start '$1000' --end '$1026' --name play --library library --project game-a
97
+ node <skill>/scripts/provenance.ts match unpacked/image.json --library library --out .c64-re-tools/local/match.json --project game-b
98
+ ```
99
+
100
+ To save a routine:
101
+
102
+ 1. Name the routine in the knowledge of its program 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.
103
+ 2. Run `routine` with the start of a module (`--module`), or with `--start` and `--end`. A module ends at the next module or at the end of its segment.
104
+ - `--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.
105
+ - `--title` is the title of the routine. When you do not give it, the script uses the module title.
106
+ - A routine has at least 16 bytes. Its last instruction must end in the range.
107
+ 3. 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.
108
+
109
+ To find the routines in a program:
110
+
111
+ 1. Run `match` on the image of the program. The script examines each routine of the library at each address of the image.
112
+ - The opcodes and the other bytes must be equal.
113
+ - 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.
114
+ - 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.
115
+ 2. Give `--out` to get a batch for `knowledge.ts apply`. 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.
116
+ 3. Read `batch.leftOut` before you apply the batch. The script leaves out a write in these conditions:
117
+ - The program has a user or LLM row at that place.
118
+ - The program uses the name at another address.
119
+ - A removal holds at that place.
120
+ - The routine occurs two times. Only the first copy gets the names.
121
+ - The script leaves out the name that an operand expression uses, or the expression does not give the operand in the image.
122
+ 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.
123
+
78
124
  ## Knowledge
79
125
 
80
126
  Automatic write:
@@ -82,6 +128,8 @@ Automatic write:
82
128
 
83
129
  Record a confirmed conclusion as a normal comment, region or symbol with the c64-knowledge skill. Do not record the full comparison.
84
130
 
131
+ `match --out` writes a batch file and does not change the knowledge. Apply the batch with the c64-knowledge skill.
132
+
85
133
  ## Result
86
134
 
87
135
  The differing ranges with the bytes of each release and the groups that agree, and the share of identical bytes. `common` gives the ranges where all releases have bytes. `releases` gives the segments and the `shift` of each release. With `--run`, each difference also has `runtime`, and `run` tells if each release started, or why not.
@@ -99,7 +147,11 @@ The exit status is 0 for a result. The exit status is 1 for an error. The exit s
99
147
  - `installation-incomplete`, or `machine-unavailable` with a message that the host runtime does not run: stop the task. Give the message to the user and wait for the user. The message gives the remedy. Do not make a replacement for the tool or the host runtime, for example your own emulator script.
100
148
  - `moreDifferences: true`: the script shows only the first differences. Use `--from` and `--to` to see the others.
101
149
  - `not-found`: the project has no file at that path.
102
- - `invalid-input`: a file, an address or a shift is wrong. A path that goes out of the project directory is also wrong, also through a link. Read the message.
150
+ - `not-found` from `match`: the library folder does not exist, or it has no routine files. Save a routine with `routine` first.
151
+ - `conflict` from `routine`: the library has a routine with that name. Give another `--name`, or give `--replace` to save over it.
152
+ - `invalid-input` with "is a project folder": the library folder is a project. Give a folder beside the projects.
153
+ - `match` gives `count: 0`: the routine is not in the image. A packed program can hold the routine in a packed form. Unpack the program with c64-unpacker first.
154
+ - `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.
103
155
 
104
156
  ## Handoffs
105
157
 
@@ -108,3 +160,4 @@ The exit status is 0 for a result. The exit status is 1 for an error. The exit s
108
160
  - Run or examine the different code → c64-emulator
109
161
  - Analyze the different code → c64-static-analysis
110
162
  - Record a conclusion → c64-knowledge
163
+ - Apply the batch of `match` → c64-knowledge