@henols/c64-re-tools 2.5.1-rc.2 → 2.6.0-rc.10

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 (87) hide show
  1. package/package.json +2 -2
  2. package/skills/c64-assembler/SKILL.md +26 -12
  3. package/skills/c64-assembler/scripts/assembler.ts +25 -13
  4. package/skills/c64-development/SKILL.md +2 -2
  5. package/skills/c64-docs/SKILL.md +4 -4
  6. package/skills/c64-docs/scripts/docs.ts +7 -7
  7. package/skills/c64-docs/scripts/lib/reference.ts +3 -3
  8. package/skills/c64-docs/scripts/lib/source-map.ts +9 -4
  9. package/skills/c64-knowledge/SKILL.md +29 -20
  10. package/skills/c64-knowledge/scripts/knowledge.ts +33 -39
  11. package/skills/c64-knowledge/scripts/lib/listing.ts +18 -3
  12. package/skills/c64-packer/SKILL.md +1 -1
  13. package/skills/c64-provenance/SKILL.md +11 -10
  14. package/skills/c64-provenance/scripts/lib/library.ts +16 -16
  15. package/skills/c64-provenance/scripts/provenance.ts +33 -23
  16. package/skills/c64-reverse-engineering/SKILL.md +16 -10
  17. package/skills/c64-source/SKILL.md +60 -42
  18. package/skills/c64-source/scripts/lib/export.ts +76 -32
  19. package/skills/c64-source/scripts/lib/loader.ts +26 -7
  20. package/skills/c64-source/scripts/lib/source.ts +21 -24
  21. package/skills/c64-source/scripts/lib/stage.ts +6 -5
  22. package/skills/c64-source/scripts/source.ts +213 -106
  23. package/skills/c64-static-analysis/SKILL.md +7 -5
  24. package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
  25. package/skills/c64-static-analysis/scripts/lib/instructions.ts +22 -20
  26. package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -43
  27. package/skills/c64-testing/SKILL.md +5 -2
  28. package/skills/c64-testing/references/recording-format.md +18 -3
  29. package/skills/c64-testing/references/scenario-format.md +7 -6
  30. package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
  31. package/skills/c64-testing/scripts/lib/play.ts +39 -41
  32. package/skills/c64-testing/scripts/lib/recording.ts +46 -37
  33. package/skills/c64-testing/scripts/lib/replay.ts +1 -1
  34. package/skills/c64-testing/scripts/lib/runs.ts +2 -2
  35. package/skills/c64-testing/scripts/lib/scenario.ts +17 -10
  36. package/skills/c64-unpacker/SKILL.md +4 -1
  37. package/skills/c64-unpacker/scripts/lib/loads.ts +34 -13
  38. package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
  39. package/skills/emulator/SKILL.md +7 -12
  40. package/src/build-name.ts +50 -0
  41. package/src/c64-keys.ts +98 -0
  42. package/src/c64.ts +20 -0
  43. package/src/cli/main.ts +3 -29
  44. package/src/host/main.ts +1 -1
  45. package/src/host/tools/index.ts +1 -6
  46. package/src/host/vice/session.ts +88 -9
  47. package/src/host-client/steps.ts +17 -17
  48. package/src/host-client/tools.ts +2 -7
  49. package/src/host-client/vice-session.ts +7 -1
  50. package/src/knowledge/program.ts +44 -1
  51. package/src/knowledge/read.ts +28 -8
  52. package/src/knowledge/schema.ts +33 -9
  53. package/src/knowledge/start-screen.ts +4 -0
  54. package/src/knowledge/text.ts +4 -2
  55. package/src/knowledge/write.ts +59 -25
  56. package/src/mcp/inputs.ts +12 -0
  57. package/src/mcp/server.ts +1 -1
  58. package/src/mcp/tools/input.ts +38 -5
  59. package/src/mcp/tools/machine.ts +3 -42
  60. package/src/mcp/tools/media.ts +1 -1
  61. package/src/native/acme.ts +1 -1
  62. package/src/native/c64run.ts +1 -1
  63. package/src/native/discover.ts +3 -3
  64. package/src/native/dxa.ts +12 -1
  65. package/src/native/ghidra/analyze.ts +74 -63
  66. package/src/native/ghidra/c64rt-wasm.ts +4 -0
  67. package/src/native/ghidra/language/c64rt_6510.sla +0 -0
  68. package/src/native/ghidra/pcode.ts +222 -0
  69. package/src/native/ghidra/walk.ts +205 -0
  70. package/src/native/ghidra/wasm.ts +98 -0
  71. package/src/native/processes.ts +4 -4
  72. package/src/native/types.ts +2 -2
  73. package/src/platform.ts +30 -1
  74. package/src/project.ts +17 -4
  75. package/src/protocol/tools.ts +1 -45
  76. package/src/protocol/vice.ts +47 -0
  77. package/src/script.ts +1 -1
  78. package/src/vsf.ts +98 -0
  79. package/tools/c64run.c +9 -12
  80. package/tools/install-container.sh +1 -2
  81. package/src/cli/status.ts +0 -127
  82. package/src/host/tools/status.ts +0 -47
  83. package/src/native/ghidra/index.ts +0 -170
  84. package/src/native/ghidra/scripts/C64Export.java +0 -274
  85. package/src/native/ghidra/scripts/C64Prepare.java +0 -66
  86. package/src/native/status.ts +0 -135
  87. package/tools/install-ghidra.sh +0 -40
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henols/c64-re-tools",
3
- "version": "2.5.1-rc.2",
3
+ "version": "2.6.0-rc.10",
4
4
  "description": "Agent-friendly Commodore 64 engineering toolkit for reverse engineering, debugging, development and testing.",
5
5
  "license": "MIT",
6
6
  "author": "Henrik Olsson",
@@ -34,7 +34,7 @@
34
34
  "scripts": {
35
35
  "host": "node src/host/main.ts",
36
36
  "typecheck": "tsc -p tsconfig.json",
37
- "test": "node --test \"src/**/*.test.ts\" \"test/**/*.test.ts\""
37
+ "test": "node test/run.ts"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "24.13.3",
@@ -27,10 +27,11 @@ To get the command list, run the script with no arguments.
27
27
  | Build a source that includes files from a folder | `build src main.a --out build/game.prg --include lib` |
28
28
  | Build a source that includes a file that you generated into a folder next to the source root | `build src boot.asm --out build/boot.prg --include ../build` |
29
29
  | Build a source that sets no start address | `build src main.a --out build/game.prg --set-pc '$0801'` |
30
- | Check that the rebuild is identical to the program in the project knowledge | `build src main.asm --out build/game.prg --compare` |
31
- | Build a release and check it against the file of that release | `build src main.asm --out build/original.prg --release ORIGINAL --compare` |
30
+ | Build a generated source with the values of `config.asm` | `build src main.asm` |
31
+ | Build the loader of a generated source | `build src loader.asm` |
32
+ | Check that the rebuild is identical to the program in the project knowledge | `build src main.asm --compare` |
33
+ | Build a release and check it against the bytes of that release | `build src main.asm --release ORIGINAL --compare` |
32
34
  | Check the rebuild of a program in another space, for example the drive | `build src main.asm --out build/drive.prg --compare --space drive8` |
33
- | Write the symbols of the rebuild to a file for a test run | `build src main.asm --out build/game.prg --out-symbols build/game.json` |
34
35
  | List all symbols, also the constants that the source does not use | `build src main.a --out build/game.prg --all-symbols --max-listed 500` |
35
36
  | Write only the bytes of the program, without the load address | `build src main.a --out build/game.bin --plain` |
36
37
 
@@ -42,7 +43,8 @@ To get the command list, run the script with no arguments.
42
43
  - An include folder is a path relative to the source root, inside the project folder. It can be outside the source root, for example `--include ../build`.
43
44
  - `<entry>` is the main source file, relative to the source root. It normally sets its start address, for example `* = $0801`. If it does not, give `--set-pc`.
44
45
  - For a source that you generated from the project knowledge, the source root is the folder of that source. The entry is `main.asm`.
45
- - `--out` is the path of the program, relative to the project folder.
46
+ - `--out` is the path of the program, relative to the project folder. Without `--out`, the script writes `build/<name>.prg`. See "Build names".
47
+ - The script writes the symbols of the program to `symbols/<name>.json` in the folder of the program, for example `build/symbols/clean.json`. Give this file to a test run as the symbols of the rebuild.
46
48
  - Get the label of a release from the releases in the project knowledge. Record a release in the project knowledge before you build it.
47
49
  - Before you use `--compare`, put the program bytes into the project knowledge.
48
50
  - The target CPU is the 6510. The program is a C64 PRG, or the bytes only with `--plain`.
@@ -55,6 +57,19 @@ A source that you generated from the project knowledge has switches in `config.a
55
57
  - To turn a switch on, change its value in `config.asm`, for example `TRAINER = 1`. Do not use `--define` for a switch. ACME then stops with `Symbol already defined`.
56
58
  - With `--release <label>`, each switch has the value of that release. A release build does not read `config.asm`.
57
59
 
60
+ ### Build names
61
+
62
+ Without `--out`, the name of the program tells what the build is:
63
+
64
+ | Build | Name |
65
+ |---|---|
66
+ | `--release <label>` | `release_<label>.prg`, for example `release_ORIGINAL.prg` |
67
+ | Each value of `config.asm` is its default | `clean.prg` |
68
+ | A value of `config.asm` is not its default | `custom_<switches>.prg`, for example `custom_trainer.prg`. A switch that is off has `no_` before its name, for example `custom_no_start_screen.prg`. |
69
+ | A source without `config.asm` | the name of the entry, for example `main.prg` |
70
+
71
+ An entry other than `main.asm` adds its name, for example `clean_loader.prg` for `loader.asm`. With `--plain`, the extension is `.bin`. Do not give `--out` for a build of a generated source. Then the name always tells the build.
72
+
58
73
  ### Paths and the project folder
59
74
 
60
75
  - 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/`.
@@ -81,17 +96,16 @@ Each flag applies only to the commands in the table. On another command, the scr
81
96
 
82
97
  | Flag | Command | Effect |
83
98
  |---|---|---|
84
- | `--out <file.prg>` | `build` | Required. The path of the program, relative to the project folder. |
85
- | `--include <dir>` | `build` | An include folder: a path relative to the source root, inside the project folder. Give the flag again for each folder. The default is no include folder. |
99
+ | `--out <file.prg>` | `build` | The path of the program, relative to the project folder. The default is `build/<name>.prg`. See "Build names". |
100
+ | `--include <folder>` | `build` | An include folder: a path relative to the source root, inside the project folder. Give the flag again for each folder. The default is no include folder. |
86
101
  | `--define NAME=VALUE` | `build` | An assembler symbol: an integer, also `$` and hex digits, or `true` or `false`. Give the flag again for each symbol. Do not use it for a switch. |
87
102
  | `--set-pc <address>` | `build` | The start address when the source does not set one, for example `'$0801'`. |
88
- | `--release <label>` | `build` | Build a release of the project knowledge. Each switch gets the value of that release. With `--compare`, the reference is the file of the release. |
103
+ | `--release <label>` | `build` | Build a release of the project knowledge. Each switch gets the value of that release. With `--compare`, the reference is the bytes of the release in the project knowledge. |
89
104
  | `--compare` | `build` | Compare the program byte by byte with the program in the project knowledge, or with the file of `--release`, segment by segment. Off by default. |
90
105
  | `--space <space>` | `build` | The space of the program in the project knowledge: `c64`, `drive8`, `loading`, or `bank0` to `bank255`. The default is `c64`. Give it only with `--compare` or `--release`. |
91
106
  | `--plain` | `build` | Write only the bytes of the program, without the 2-byte load address. Off by default. |
92
107
  | `--all-symbols` | `build` | List also the constants that the source does not use. Off by default. |
93
108
  | `--max-listed <n>` | `build` | List at most `n` symbols. The default is 50. `symbols.count` always gives the count of all symbols. |
94
- | `--out-symbols <file.json>` | `build` | Write the listed symbols to this file as `{"symbols": [...]}`. Without `--all-symbols`, the file does not have the constants that the source does not use. |
95
109
 
96
110
  ---
97
111
 
@@ -99,7 +113,7 @@ Each flag applies only to the commands in the table. On another command, the scr
99
113
 
100
114
  ### `build <source-root> <entry>`
101
115
 
102
- Assembles the source and writes the program to `--out`.
116
+ Assembles the source and writes the program to `--out`, or to `build/<name>.prg`. It also writes the symbols to `symbols/<name>.json` in the folder of the program. Without `--all-symbols`, that file does not have the constants that the source does not use.
103
117
 
104
118
  `body` holds:
105
119
 
@@ -112,7 +126,7 @@ Assembles the source and writes the program to `--out`.
112
126
  - Kind `address` has a value in `loadRange`. It gives `address`.
113
127
  - Kind `constant` has a value outside `loadRange`. It gives `value` as `$` and four or more hex digits. A label in a `!pseudopc` block can be a constant, because its value is the run address, not the load address.
114
128
  - `used` is `false` when the source does not use the symbol.
115
- - `symbolsFile`: the file of `--out-symbols`, with `out`, `bytes` and `sha256`.
129
+ - `symbolsFile`: the symbols file, with `out`, `bytes` and `sha256`.
116
130
  - `unusedConstants`: the count of the constants that the list does not include. It is not in the body with `--all-symbols`.
117
131
  - `diagnostics`: each item has `severity` (`error`, `warning` or `note`), `file`, `line` and `message`. `file` is relative to the source root. A file in an include folder outside the source root starts with `../`. `file` and `line` are not in an item without a location in the source.
118
132
  - `compare`: only with `--compare`. `identical` is `true` when each segment is identical. `segments` has one item for each segment of the reference program, with `start`, `end` and `result`:
@@ -125,7 +139,7 @@ Do as the result tells:
125
139
  - `result` is `PASS`: the program is at `out`. To run or debug the program, load the file at `out` into the emulator.
126
140
  - `result` is `FAIL` and `assembled` is `false`: the source has errors, and the script wrote no program. `hint` tells you to correct the source. Correct the source at the file and the line of each diagnostic. Then run `build` again.
127
141
  - `result` is `FAIL` and `assembled` is `true`: the program is not identical to the reference. The script wrote the program. Read the first difference of each segment in `compare.segments`. Without `--release`, read the section "Switches" first.
128
- - `hint` tells that `symbols` is cut: give a larger `--max-listed`, or `--out-symbols <file.json>` for the full list.
142
+ - `hint` tells that `symbols` is cut: give a larger `--max-listed`, or read the symbols file for the full list.
129
143
  - Error `not-found` names the entry: give the main source file relative to the source root.
130
144
  - Error `not-found` names an include folder: give `--include` a folder with files, relative to the source root.
131
145
  - Error `invalid-input` names an include folder: the folder is outside the project folder. Give `--include` a folder inside the project folder.
@@ -135,7 +149,7 @@ Do as the result tells:
135
149
 
136
150
  The script does not keep the diagnostics or the program in the project knowledge.
137
151
 
138
- To compare runs of the rebuild with runs of the original, give the file of `--out-symbols` to the test run as the symbols of the rebuild. A symbol of the rebuild gives the address of a routine in the rebuild.
152
+ To compare runs of the rebuild with runs of the original, give the symbols file to the test run as the symbols of the rebuild. A symbol of the rebuild gives the address of a routine in the rebuild.
139
153
 
140
154
  ---
141
155
 
@@ -1,15 +1,15 @@
1
1
  // The c64-assembler script: assembles project source with ACME, which it runs
2
2
  // itself, and writes the program into the project.
3
3
 
4
+ import { BUILD_DIRECTORY, type BuildKind, buildName, CONFIG_FILE, configValues, symbolsPath } from "#src/build-name.ts";
4
5
  import { formatC64Address } from "#src/c64.ts";
5
6
  import { Refusal } from "#src/errors.ts";
6
- import { readImage } from "#src/host-client/image.ts";
7
7
  import { readSourceTree, writeReported } from "#src/host-client/transfer.ts";
8
8
  import { openForRead } from "#src/knowledge/database.ts";
9
9
  import { knowledgeNames } from "#src/knowledge/names.ts";
10
- import { requireProgram } from "#src/knowledge/program.ts";
11
- import { releaseLabeled } from "#src/knowledge/read.ts";
12
- import { RELEASE_DEFINE } from "#src/knowledge/schema.ts";
10
+ import { releaseImage, requireProgram } from "#src/knowledge/program.ts";
11
+ import { listSwitches, releaseLabeled } from "#src/knowledge/read.ts";
12
+ import { LEFTOVERS_SWITCH, RELEASE_DEFINE, START_SCREEN_SWITCH, type Space } from "#src/knowledge/schema.ts";
13
13
  import { assemble, showSymbol, symbolsFileText } from "#src/native/acme.ts";
14
14
  import { localToolContext } from "#src/native/local.ts";
15
15
  import type { AcmeParams, AssembledSymbol } from "#src/native/types.ts";
@@ -26,6 +26,16 @@ function parseDefine(text: string): [string, number | boolean] {
26
26
  throw new UsageError(`--define ${match[1]} needs an integer or true/false, not ${value}`);
27
27
  }
28
28
 
29
+ /** The default of each switch of a generated source: the knowledge gives them, the start screen is in and the leftovers are out. */
30
+ function switchDefaults(space: Space): Map<string, number> {
31
+ const db = openForRead();
32
+ try {
33
+ return new Map([[START_SCREEN_SWITCH, 1], [LEFTOVERS_SWITCH, 0], ...listSwitches(db, undefined, space).map((row) => [row.name, row.default] as const)]);
34
+ } finally {
35
+ db?.close();
36
+ }
37
+ }
38
+
29
39
  await runScript({
30
40
  name: "assembler",
31
41
  summary: "Assembles project source with ACME and writes the program into the project.",
@@ -39,8 +49,8 @@ await runScript({
39
49
  { name: "<entry>", help: "the main source file, relative to the source root" },
40
50
  ],
41
51
  options: {
42
- out: { ...OPTIONS.out, output: "file", value: "<file.prg>", help: "where to write the program, relative to the project folder", required: true },
43
- include: { kind: "text", value: "<dir>", multiple: true, help: "an include folder: a path relative to the source root, inside the project folder" },
52
+ out: { ...OPTIONS.out, output: "file", value: "<file.prg>", help: "where to write the program, relative to the project folder. The default is build/<build>.prg: release_<label> with --release, else clean or custom_<switches> from config.asm, with _<entry> for an entry other than main.asm" },
53
+ include: { kind: "text", value: "<folder>", multiple: true, help: "an include folder: a path relative to the source root, inside the project folder" },
44
54
  define: { kind: "text", value: "NAME=VALUE", multiple: true, help: "an assembler symbol: an integer ($hex allowed) or true/false" },
45
55
  "set-pc": { kind: "address", value: "<address>", help: "the start address when the source sets none, for example '$0801'" },
46
56
  release: { kind: "text", value: "<label>", help: `build a release of the knowledge: defines ${RELEASE_DEFINE}<label>=1, so each switch has the value of that release. With --compare, the reference is the file of the release` },
@@ -49,12 +59,10 @@ await runScript({
49
59
  plain: { kind: "flag", help: "write the bytes only, without the 2-byte load address of a PRG" },
50
60
  "all-symbols": { kind: "flag", help: "list also the constants that the source does not use" },
51
61
  "max-listed": { ...OPTIONS["max-listed"], help: "list at most n symbols (default 50). The count is always given" },
52
- "out-symbols": { kind: "path", output: "file", value: "<file.json>", help: "write the listed symbols to this project file as {\"symbols\": [...]}: the names of the rebuild for a test run. Without --all-symbols, the file does not have the constants that the source does not use" },
53
62
  },
54
63
  notes: "Symbol values are $ and at least four hex digits. Before --compare, put the program bytes into the project knowledge. Without --release, the build has the switch values of config.asm. With the defaults, this is the clean program, which is not the bytes of a release when a switch has a default that the base release does not have. Set a switch in config.asm, not with --define: ACME stops with Symbol already defined.",
55
64
  run: async (call) => {
56
65
  const [sourceRoot, entry] = [call.subject(0), call.subject(1)];
57
- const out = call.string("out")!;
58
66
  // Read the reference before ACME runs, so a project without it stops at once.
59
67
  let program: Reference | undefined;
60
68
  const label = call.string("release");
@@ -68,7 +76,7 @@ await runScript({
68
76
  const release = releaseLabeled(db, label, call.space);
69
77
  if (release === undefined) throw new Refusal("not-found", `There is no release ${label} in the knowledge. Record the release in the project knowledge first, or give the label of a recorded release.`);
70
78
  releaseDefine = { [`${RELEASE_DEFINE}${label}`]: 1 };
71
- if (call.flag("compare")) program = release.base ? requireProgram(db, call.space) : readImage(release.file);
79
+ if (call.flag("compare")) program = releaseImage(db, label, call.space);
72
80
  }
73
81
  } finally {
74
82
  db?.close();
@@ -77,19 +85,22 @@ await runScript({
77
85
  const setPc = call.address("set-pc");
78
86
  const { contents, ...tree } = readSourceTree(sourceRoot, call.strings("include"));
79
87
  if (!tree.files.some((file) => file.path === (tree.sourceDir === "" ? entry : `${tree.sourceDir}/${entry}`))) throw new Refusal("not-found", `${entry} is not a file in ${sourceRoot}. Give the main source file relative to the source root.`);
88
+ // The name of the build tells what it is: the release, or the switch values of config.asm.
89
+ const config = tree.files.findIndex((file) => file.path === (tree.sourceDir === "" ? CONFIG_FILE : `${tree.sourceDir}/${CONFIG_FILE}`));
90
+ const kind: BuildKind | undefined = label !== undefined ? { release: label } : config < 0 ? undefined : { values: configValues(contents[config]!.toString("utf8")), defaults: switchDefaults(call.space) };
91
+ const plain = call.flag("plain");
92
+ const out = call.string("out") ?? `${BUILD_DIRECTORY}/${buildName(entry, kind)}.${plain ? "bin" : "prg"}`;
80
93
  const params: AcmeParams = { ...tree, entrySource: entry, defines: { ...releaseDefine, ...Object.fromEntries(call.strings("define").map(parseDefine)) }, ...(setPc === undefined ? {} : { setPc }) };
81
94
 
82
95
  const { result, attachments } = await assemble(params, contents, localToolContext());
83
96
  if (!result.assembled) return reply({ result: "FAIL", assembled: false, diagnostics: result.diagnostics }, { hint: "The source has errors, and no program was written. Correct the source at the file and the line of each diagnostic. Then run build again." });
84
- const plain = call.flag("plain");
85
97
  const written = writeReported(out, plain ? attachments![0]!.subarray(2) : attachments![0]!, { what: "--out" });
86
98
  const range = result.loadRange!;
87
99
  const compared = program === undefined ? undefined : compareBuild(attachments![0]!, program);
88
100
  // An include file of platform names gives many constants that the program does not use.
89
101
  const all = call.flag("all-symbols");
90
102
  const shown = result.symbols!.filter((symbol) => all || symbol.kind === "address" || symbol.used);
91
- const symbolsPath = call.string("out-symbols");
92
- const symbols = listedItems(shown, call.count("max-listed")!, showSymbol, "a larger --max-listed, or --out-symbols <file.json> for the whole list");
103
+ const symbols = listedItems(shown, call.count("max-listed")!, showSymbol, `a larger --max-listed, or read ${symbolsPath(out)}`);
93
104
  // A build that differs from its reference is a failed check.
94
105
  const different = compared !== undefined && !compared.identical;
95
106
  const hints = [
@@ -104,7 +115,8 @@ await runScript({
104
115
  ...(plain ? { plain: true } : {}),
105
116
  loadRange: { start: formatC64Address(range.start), end: formatC64Address(range.end), bytes: range.bytes },
106
117
  symbols,
107
- ...(symbolsPath === undefined ? {} : { symbolsFile: writeReported(symbolsPath, symbolsFileText(shown), { what: "--out-symbols" }) }),
118
+ // The symbols of the program for a test run, in symbols/ next to it.
119
+ symbolsFile: writeReported(symbolsPath(out), symbolsFileText(shown), { what: "--out" }),
108
120
  ...(all ? {} : { unusedConstants: result.symbols!.length - shown.length }),
109
121
  diagnostics: result.diagnostics,
110
122
  ...(compared === undefined ? {} : { compare: compared }),
@@ -29,7 +29,7 @@ First select the path:
29
29
 
30
30
  - The project has no program yet: path A.
31
31
  - The program has source that a person wrote: path B. A project that an export of a rebuilt program made also takes path B.
32
- - The source comes from a generation from the project knowledge: path C. Such a source has `main.asm` and `source-map.json`. Do not edit this source. The next generation of the source writes over it.
32
+ - The source comes from a generation from the project knowledge: path C. Such a source has `main.asm`, and the first line of each generated file tells that it is generated. Do not edit this source. The next generation of the source writes over it.
33
33
 
34
34
  ### Acceptance checks
35
35
 
@@ -110,7 +110,7 @@ A rebuilt program gets its source from the project knowledge. A change is a swit
110
110
  - Build the default build.
111
111
  - When the default build does not have the switch, set the switch to 1 in `src/config.asm`. Then build the default build. After the test, set the value back to the default if the user did not ask for the change.
112
112
  8. Test the build that has the switch:
113
- - Run the test scenarios in `tests/` where the behavior must stay the same as the original.
113
+ - When the behavior must stay the same as the original, replay a recording that executes the changed code. Run a test scenario in `tests/` only when no recording executes that code.
114
114
  - Run a run file with `expect` steps that show the feature or the fix.
115
115
 
116
116
  ### The answer
@@ -41,7 +41,7 @@ The documentation is Markdown in the project. It has two parts:
41
41
 
42
42
  Get the values for the commands from these places:
43
43
 
44
- - `<source-dir>` and `--source`: the folder of the source that you generated from the project knowledge, for example `src`. It must hold `source-map.json`. The source must be from the current revision of the project knowledge.
44
+ - `<source-dir>` and `--source`: the folder of the source that you generated from the project knowledge, for example `src`. The source must be from the current revision of the project knowledge in its space. A change in another space does not make the source old.
45
45
  - `--out`: a folder that holds only the reference, for example `docs/reference`. Keep the pages that you write outside it.
46
46
  - `<page>`: the entry page `README.md` and the folder of the other pages, for example `docs`.
47
47
  - The program bytes: put them into the project knowledge before `generate`. Then the reference decodes the tables and shows the graphics.
@@ -84,7 +84,7 @@ Each flag applies only to the commands in the table. On another command, the scr
84
84
  | Flag | Command | Effect |
85
85
  |---|---|---|
86
86
  | `--out <dir>` | `generate` | Required. The folder of the reference, relative to the project folder. `generate` writes only there. It refuses to start when the folder holds a page that it did not write. |
87
- | `--source <dir>` | `link` | Required. The folder of the generated source, with its `source-map.json`, relative to the project folder. In a group folder, each project has its source in this folder. |
87
+ | `--source <dir>` | `link` | Required. The folder of the generated source, relative to the project folder. In a group folder, each project has its source in this folder. |
88
88
  | `--reference <dir>` | `link` | The folder of the reference, relative to the project folder. In a group folder, each project has its reference in this folder. The default is the first `reference` folder in a given folder or beside a given page, for example `docs/reference`. |
89
89
  | `--check` | `link` | Write nothing. `result` is `FAIL` when a link is not up to date or a page has a problem. Off by default. |
90
90
  | `--max-listed <n>` | `generate`, `link` | List at most `n` items in each list. The default is 50. The count is always in the body. |
@@ -121,7 +121,7 @@ In a call graph, a solid arrow is a call, a thick arrow is a table entry, and a
121
121
 
122
122
  Errors and their actions:
123
123
 
124
- - `not-found` for `source-map.json` or for the source folder: generate the source from the project knowledge. Then run `generate` again.
124
+ - `not-found` for the source map or for the source folder: generate the source from the project knowledge. Then run `generate` again.
125
125
  - `invalid-input` that names an old revision: the project knowledge changed after you generated the source. Generate the source again, then run `generate` again.
126
126
  - `invalid-input` that names a page in `--out`: `generate` did not write that page. Move the page out of the folder.
127
127
  - `conflict`: the project knowledge has conflicts from a git merge. Resolve the merge conflicts of the project knowledge. Then generate the source again, and run `generate` again.
@@ -208,7 +208,7 @@ Errors:
208
208
  ## Workflow
209
209
 
210
210
  1. Read the project knowledge. The documentation can only be as good as the knowledge. Each routine needs a name and a comment. Each table needs a region and a name. Each file of the source needs a module with a title. Record what is missing in the project knowledge.
211
- 2. Generate the source from the project knowledge. Make sure that the check of the source gives identical bytes. This also writes `source-map.json`.
211
+ 2. Generate the source from the project knowledge. Make sure that the check of the source gives identical bytes. This also writes the source map.
212
212
  3. Run `generate`. Read `index.md` of the reference. A module with no routines, or a routine with no comment, shows what the knowledge does not have yet.
213
213
  4. Make the plan of the pages. Start from the modules and the call graphs. Find the main loop, the interrupt chain, the dispatch tables, the state machines and the data formats. Each subsystem gets one page in `docs/`. The entry page `README.md` lists the pages. Use the page types in `<skill>/references/page-types.md`.
214
214
  5. Collect the facts about the development and the copy protection. These facts are the most interesting parts for a reader, so look for them carefully.
@@ -14,7 +14,7 @@ import { writeProjectFile, writeReported } from "#src/host-client/transfer.ts";
14
14
  import { conflicts } from "#src/knowledge/conflicts.ts";
15
15
  import { openForRead } from "#src/knowledge/database.ts";
16
16
  import { programImage, type ProgramImage } from "#src/knowledge/program.ts";
17
- import { currentRevision, listComments, listModules, listReferences, listRegions, listSymbols } from "#src/knowledge/read.ts";
17
+ import { listComments, listModules, listReferences, listRegions, listSymbols, sourceRevision } from "#src/knowledge/read.ts";
18
18
  import { groupOf, namedGroup, projectRoot, resolveProjectFile, resolveProjectPath, type ProjectGroup } from "#src/project.ts";
19
19
  import { listed, OPTIONS, reply, runScript, UsageError, type Call, type Reply } from "#src/script.ts";
20
20
  import { checkLinks, linkPage, type Files, type LinkContext, type Names, type Problem } from "./lib/links.ts";
@@ -64,10 +64,10 @@ function generate(call: Call): Reply {
64
64
  image = programImage(db, map.space);
65
65
  const found = conflicts(db).length;
66
66
  if (found > 0) throw new Refusal("conflict", `The knowledge has ${found} conflict${found === 1 ? "" : "s"} from a git merge. Nothing was written. Resolve the merge conflicts of the project knowledge. Then generate the source again from the knowledge, and run generate again.`);
67
- const revision = currentRevision(db);
68
- // A source of another revision has other lines: the links would point to the wrong code.
67
+ // A source of another revision has other lines: the links would point to the wrong code. A change in another space does not change the source.
68
+ const revision = sourceRevision(db, map.space);
69
69
  if (map.revision !== revision) {
70
- throw new WireFailure("invalid-input", `${map.pathOf("source-map.json")} is from knowledge revision ${map.revision}, and the knowledge is at revision ${revision}. Nothing was written. Generate the source again from the knowledge. Then run generate again.`);
70
+ throw new WireFailure("invalid-input", `${map.mapPath} is from knowledge revision ${map.revision}, and the knowledge of the source is at revision ${revision}. Nothing was written. Generate the source again from the knowledge. Then run generate again.`);
71
71
  }
72
72
  knowledge = {
73
73
  revision,
@@ -266,13 +266,13 @@ function link(call: Call): Reply {
266
266
  let symbols;
267
267
  let revision;
268
268
  try {
269
- revision = currentRevision(db);
269
+ revision = sourceRevision(db, map.space);
270
270
  symbols = listSymbols(db, undefined, undefined, undefined, map.space);
271
271
  } finally {
272
272
  db?.close();
273
273
  }
274
274
  if (map.revision !== revision) {
275
- problems.push({ page: inProject(map.pathOf("source-map.json")), line: 1, kind: "stale-reference", message: `The source${of} is from knowledge revision ${map.revision}, and the knowledge is at ${revision}. Generate the source and the reference again, then run docs.ts link.` });
275
+ problems.push({ page: inProject(map.mapPath), line: 1, kind: "stale-reference", message: `The source${of} is from knowledge revision ${map.revision}, and the knowledge of the source is at ${revision}. Generate the source and the reference again, then run docs.ts link.` });
276
276
  }
277
277
  const addresses = new Map<string, number>();
278
278
  for (const label of map.labels) addresses.set(label.name, label.address);
@@ -411,7 +411,7 @@ function link(call: Call): Reply {
411
411
  return reply({ result: problems.length > 0 || (check && links > 0) ? "FAIL" : "PASS", ...output }, { ...(hints.length === 0 ? {} : { hint: hints.join(" ") }), nextAction });
412
412
  }
413
413
 
414
- const SOURCE = { kind: "path", value: "<dir>", help: "the folder of the source that was generated from the knowledge, with its source-map.json, relative to the project folder" } as const;
414
+ const SOURCE = { kind: "path", value: "<dir>", help: "the folder of the source that was generated from the knowledge, relative to the project folder" } as const;
415
415
 
416
416
  await runScript({
417
417
  name: "docs",
@@ -34,8 +34,8 @@ export interface ReferenceFile {
34
34
  bytes: Buffer;
35
35
  }
36
36
 
37
- /** Files that the source map lists but that hold no code of the program. */
38
- const NOT_PIECES = new Set(["main.asm", "constants.asm", "macros.asm", "loader.asm"]);
37
+ /** Files that the source map lists but that hold no code of the program: they get no module page. */
38
+ const NOT_PIECES = new Set(["main.asm", "constants.asm", "macros.asm", "loader.asm", "config.asm", "switches.asm", "start_screen.asm", "start_screen_stage.asm"]);
39
39
  const TABLE_TYPES: readonly RegionType[] = [...POINTER_TABLE_TYPES, "jumps", "words"];
40
40
  const GRAPHICS_TYPES: readonly RegionType[] = ["sprite", "bitmap", "charset", "screen"];
41
41
  /** A list longer than this ends with the number of the rest. */
@@ -194,7 +194,7 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
194
194
  }
195
195
  const titleOf = (file: string) => input.modules.find((module) => module.file === file)?.title;
196
196
 
197
- const header = `${GENERATED_MARK} from knowledge revision ${input.revision} and ${map.pathOf("source-map.json")}. Do not edit: change the knowledge, generate the source again, then run docs.ts generate. -->`;
197
+ const header = `${GENERATED_MARK} from knowledge revision ${input.revision} and ${map.mapPath}. Do not edit: change the knowledge, generate the source again, then run docs.ts generate. -->`;
198
198
  const files: ReferenceFile[] = [];
199
199
  const write = (path: string, lines: string[]) => files.push({ path, bytes: Buffer.from(`${[header, ...lines].join("\n").replace(/\n{3,}/g, "\n\n")}\n`, "utf8") });
200
200
 
@@ -1,5 +1,6 @@
1
- // The source map that c64-source writes next to the source: the line of
2
- // each name and of each address. The documentation links to these lines.
1
+ // The source map of a generated source: the line of each name and of each
2
+ // address. The generation writes it to the local folder of the project, not
3
+ // next to the source. The documentation links to these lines.
3
4
 
4
5
  import { posix } from "node:path";
5
6
 
@@ -7,6 +8,7 @@ import { parseC64Address } from "#src/c64.ts";
7
8
  import { WireFailure } from "#src/host-client/tools.ts";
8
9
  import { readProjectFile } from "#src/host-client/transfer.ts";
9
10
  import type { Space } from "#src/knowledge/schema.ts";
11
+ import { generatedDirectory } from "#src/project.ts";
10
12
 
11
13
  export const SOURCE_MAP_FILE = "source-map.json";
12
14
 
@@ -18,6 +20,8 @@ export interface SourceLine {
18
20
  export interface SourceMap {
19
21
  /** The source directory, relative to the project folder. */
20
22
  directory: string;
23
+ /** The source map file, relative to the project folder. */
24
+ mapPath: string;
21
25
  space: Space;
22
26
  revision: string;
23
27
  files: string[];
@@ -30,9 +34,9 @@ export interface SourceMap {
30
34
  pathOf: (file: string) => string;
31
35
  }
32
36
 
33
- /** Reads <directory>/source-map.json of the project `root`. A missing map is a refusal with the remedy. */
37
+ /** Reads the source map of the source in `directory` of the project `root`. A missing map is a refusal with the remedy. */
34
38
  export function readSourceMap(directory: string, root?: string): SourceMap {
35
- const path = posix.join(directory, SOURCE_MAP_FILE);
39
+ const path = posix.join(generatedDirectory(directory), SOURCE_MAP_FILE);
36
40
  let text: string;
37
41
  try {
38
42
  text = readProjectFile(path, root === undefined ? {} : { root }).bytes.toString("utf8");
@@ -59,6 +63,7 @@ export function readSourceMap(directory: string, root?: string): SourceMap {
59
63
  const byName = new Map(labels.map((label) => [label.name, label]));
60
64
  return {
61
65
  directory,
66
+ mapPath: path,
62
67
  space: String(raw.space ?? "c64") as Space,
63
68
  revision: String(raw.revision),
64
69
  files: (raw.files as unknown[]).map(String),
@@ -46,7 +46,7 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
46
46
  | Write a comment | `comment '$2100' line Reads joystick 2.` |
47
47
  | Add a reference | `reference '$2000' '$2100' call` |
48
48
  | Find the places that a removal blocks | `suppressions --range '$2000-$2fff'` |
49
- | Start a file of the generated source | `module '$2000' player.asm --title 'Player movement'` |
49
+ | Start a file of the generated source | `module '$2000' game/player.asm --title 'Player movement'` |
50
50
  | Write the operand of an instruction as an expression | `operand '$8079' --lo irq_handler` |
51
51
  | Record a release of the program | `release ORIGINAL --file original/game.prg --base` |
52
52
  | Write a switch | `switch PROTECTION --kind protection --releases ORIGINAL` |
@@ -58,7 +58,8 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
58
58
  | Write a macro | `macro inc16 --params dst --body-file inc16.asm` |
59
59
  | Write instructions as one use of a macro | `use '$1005-$100a' inc16 --args ptr` |
60
60
  | Do many writes as one revision | `apply .c64-re-tools/local/batch.json` |
61
- | Make one batch from the batches of parallel agents | `join a.json b.json --out .c64-re-tools/local/joined.json` |
61
+ | Show the batches of parallel agents as one list of writes | `join a.json b.json` |
62
+ | Write the batches of parallel agents as one revision | `join a.json b.json --apply` |
62
63
  | Read the history of an address or a name | `history '$2100'` |
63
64
  | Read the last revisions | `revisions` |
64
65
  | Go back to an earlier state | `revert 20261015T2145` |
@@ -72,9 +73,9 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
72
73
  - An analyzer name is a second name from DXA, Ghidra or an idiom search, for example `FUN_17e2`. Each analyzer keeps its own name at an address. Get them from `at`, `search` or `symbols --analyzer`.
73
74
  - The generated source uses only the symbols. To use an analyzer name in the source, give the address that name with `rename`.
74
75
  - A symbol name is a label for ACME: a letter or an underscore, then letters, digits or underscores. The knowledge refuses the name of a 6502 instruction, for example `lda`, in upper or lower case.
75
- - A space is `c64` (the default), `drive8` for code in the 1541 drive, `loading` or `bank0` to `bank255`. `loading` is the captured stage of the loading that shows the start screen. `bank0` to `bank255` are cartridge banks. Drive code, the stage and banks use the same addresses as the C64. Thus each space has its own knowledge. A name is unique in one space.
76
+ - A space is `c64` (the default), `drive8` for code in the 1541 drive, `loading` or `bank0` to `bank255`. `loading` is the captured stage of the loading that shows the start screen. `bank0` to `bank255` are cartridge banks, or other memory images of the program, for example a file that the program loads later. Drive code, the stage and banks use the same addresses as the C64. Thus each space has its own knowledge. A name is unique in one space.
76
77
  - A revision id has the form `20261015T214501.123-k3f9qz`. It starts with the date and the time. Give the full id, or a start of the id that only one revision has. Get the ids from `revisions`, or from the `revision` field of a result. The revision `0` is the knowledge before the first revision.
77
- - A file of a capture is the `image.json` that the capture of a packed program wrote. Keep the other files of the capture next to it.
78
+ - A file of a capture is the `image.json` that the capture of a packed program wrote. The other files of the capture must be next to it.
78
79
 
79
80
  ### Paths and the project folder
80
81
 
@@ -107,9 +108,13 @@ Each flag applies only to the commands in the table. On another command, the scr
107
108
  | `--reason <text>` | All commands in "Change the knowledge" | Why you make the change. The revision keeps it, and `history` shows it. |
108
109
  | `--evidence <kind:ref>` | All commands in "Change the knowledge" | One thing that the change rests on: `coverage:<map>`, `test:<file>`, `file:<file>` or `note:<text>`. You can give it more than one time. |
109
110
  | `--expect-revision <revision>` | All commands in "Change the knowledge" | Refuse the change when the knowledge changed after this revision. Give the `revision` of your last read. |
111
+ | `--by <user\|llm>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
112
+ | `--reason <text>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
113
+ | `--evidence <kind:ref>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
114
+ | `--expect-revision <revision>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
110
115
  | `--range <start>-<end>` | `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `uses`, `export` | Only the rows in this range. The default is all addresses. |
111
116
  | `--origin <origin>` | `search`, `symbols`, `regions`, `comments`, `references`, `modules`, `operands`, `patches`, `macros`, `uses`, `export` | Only the rows of these origins: `user`, `llm`, `dxa`, `ghidra`, `heuristic`, `semantic` (user and llm), `analyzer` (dxa, ghidra and heuristic), or a comma list. The default is all origins. |
112
- | `--max-listed <n>` | `search`, `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `switches`, `releases`, `macros`, `uses`, `spaces`, `history`, `revisions`, `revision`, `listing` | The most items in each list of the body. The default is 50. The counts are always complete. |
117
+ | `--max-listed <n>` | `search`, `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `switches`, `releases`, `macros`, `uses`, `spaces`, `history`, `revisions`, `revision`, `listing`, `join` | The most items in each list of the body. The default is 50. The counts are always complete. |
113
118
  | `--kind <kind>` | `symbols`, `rename` | The symbol kind: `label`, `routine`, `variable`, `data` or `vector`. A read gives all kinds by default. A new symbol without `--kind` is a `label`. A `rename` without `--kind` keeps the kind of the symbol. |
114
119
  | `--kind <kind>` | `references` | Only references of this kind: `call`, `jump`, `read`, `write`, `reference` or `pointer`. |
115
120
  | `--kind <kind>` | `switch` | Necessary. The switch kind: `protection`, `trainer`, `cheat`, `crack`, `fix` or `change`. |
@@ -121,7 +126,8 @@ Each flag applies only to the commands in the table. On another command, the scr
121
126
  | `--macro <name>` | `history` | The history of a macro in place of an address. |
122
127
  | `--name <name>` | `history` | The history of a name in place of an address. |
123
128
  | `--before <revision>` | `revisions` | Only the revisions before this one. |
124
- | `--out <file>` | `export`, `join` | Necessary. The JSON file to write. |
129
+ | `--out <file>` | `export` | Necessary. The JSON file to write. |
130
+ | `--apply` | `join` | Write the joined writes to the project knowledge as one revision. Without it, `join` writes nothing. |
125
131
  | `--out <file>` | `listing` | Write the listing as text to this file in place of the lines in the body. |
126
132
  | `--element <n>` | `classify` | The bytes of one element of a table. The length of the range must be a multiple of it. |
127
133
  | `--title <text>` | `module` | The title of the file. A `module` write without a title keeps the title that the module has. |
@@ -218,7 +224,7 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
218
224
 
219
225
  ### `releases`
220
226
 
221
- - `body.releases` lists the releases, the base release first. Each item has `label`, `file`, `sha256`, `base` and `define`.
227
+ - `body.releases` lists the releases, the base release first. Each item has `label`, `base` and `define`.
222
228
  - `define` is the assembler define that builds the release.
223
229
 
224
230
  ### `macros`
@@ -242,8 +248,8 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
242
248
 
243
249
  ### `listing <range>`
244
250
 
245
- - `body.lines` lists one line for each instruction of a code region, and one `!byte` line for other bytes.
246
- - Each line has `address`, `bytes`, `text`, `referencesIn` and `referencesOut`. It can also have `label`, `analyzerNames` and `comment`.
251
+ - `body.lines` has `count` and `listed`. `listed` holds one line for each instruction of a code region, and one `!byte` line for other bytes.
252
+ - Each line has `address`, `bytes`, `text`, `referencesIn` and `referencesOut`. It can also have `label`, `analyzerNames`, `lineComments` and `comment`. `lineComments` are the line comments before the line. `comment` is the side comment.
247
253
  - `text` is the instruction with the names of its target. An operand expression of the knowledge replaces the operand.
248
254
  - When the knowledge has coverage, `access` tells if a run executed (`x`), read (`r`) or wrote (`w`) the bytes of the line, or `-` for none.
249
255
  - With `--out`, the body has `lines` as a number, and `out`, `bytes` and `sha256` of the text file.
@@ -347,8 +353,10 @@ Errors of this group:
347
353
 
348
354
  - A module tells where a file of the generated source starts. The file runs to the next module or to the end of its segment.
349
355
  - Each address has one module, and each file name has one module.
350
- - A file name has letters, digits, underscores or hyphens, and ends in `.asm`. It has no folder.
351
- - The generated source has the files `main.asm`, `loader.asm`, `switches.asm`, `config.asm`, `constants.asm` and `macros.asm` already. Thus a module cannot have one of these names, in upper or lower case.
356
+ - A file name has letters, digits, underscores or hyphens, and ends in `.asm`. It can have one folder, for example `music/driver.asm`. A folder name has lower-case letters, digits, underscores or hyphens.
357
+ - Put the modules of one part of the program in one folder, for example `music/`, `irq/` or `graphics/`.
358
+ - The generated source has the files `main.asm`, `loader.asm`, `switches.asm`, `config.asm`, `constants.asm`, `macros.asm` and `start_screen.asm` already. It also has the folders `leftovers/` and `segments/`. Thus a module cannot have one of these files, also in a folder, or one of these folders, in upper or lower case.
359
+ - Two modules cannot have file names that are different only in upper or lower case.
352
360
  - The title becomes the first line of the file.
353
361
  - `body.module` gives the module after the write.
354
362
 
@@ -387,12 +395,13 @@ A rebuild keeps all of the program in the source: unused bytes, dead code, old c
387
395
 
388
396
  Do not write a file of the rebuild by hand, for example a boot file, a packed picture or a script that changes bytes. Record each change in the knowledge, and generate the source.
389
397
 
390
- - A release is a PRG or the `image.json` of a capture, in a folder that git keeps, for example `original/`. The script refuses a file in `.c64-re-tools/local/`.
398
+ - `--file` is a PRG or the `image.json` of a capture. The project knowledge keeps the bytes of the release. After the write, the project does not need the file. A capture can stay in `.c64-re-tools/local/`.
391
399
  - A label is upper case, for example `ORIGINAL`, `FIRESTAR` or `V2`.
392
400
  - The base release is the release whose bytes are the program of the knowledge. Record it with `--base`. The script refuses `--base` when the segments or the bytes of the file are not the program.
393
401
  - A space has one base release. Record the base release before the first switch.
394
- - The build of a release gives each switch the value of that release. The check of the generated source compares that build with the bytes of the file.
395
- - `body.release` gives the release, with its `sha256` and its `define`.
402
+ - The build of a release gives each switch the value of that release. The check of the generated source compares that build with the bytes of the release in the project knowledge.
403
+ - To change the bytes of a release, record the release again with its new file.
404
+ - `body.release` gives the release, with its `define`. `body.bytes` gives the number of bytes of the file.
396
405
 
397
406
  ### `unrelease <label>`
398
407
 
@@ -539,7 +548,7 @@ A macro writes a run of instructions as one line of the source, for example `+in
539
548
  ### `apply <file>`
540
549
 
541
550
  - `<file>` is a JSON list of writes. Give `-` to read the list from standard input.
542
- - `body` holds `revision`, `writes` and `replaced`. Each item of `replaced` has the number of the `write`, its `op` and its `previous`.
551
+ - `body` holds `revision`, `writes` and `replaced`. `replaced` lists each write that replaced a row of a different origin, for example an `llm` write over a `user` row. Each item has the number of the `write`, its `op` and its `previous`. A write over a row of the same origin is not in `replaced`.
543
552
  - All writes become one revision. If the knowledge refuses one write, the script writes nothing, and the `error` names the write.
544
553
  - Each write has `op` and the fields of the command with the same name. Each write can also have `space`. For example:
545
554
 
@@ -572,7 +581,6 @@ A macro writes a run of instructions as one line of the source, for example `+in
572
581
  | `unuse` | `start` |
573
582
 
574
583
  - The script checks an `operand`, `patch` or `use` write against the program of its space.
575
- - Apply a batch from a library match or an idiom search in the same way. Read the notes of the result that wrote the batch first.
576
584
 
577
585
  ### `revert <revision>`
578
586
 
@@ -590,19 +598,20 @@ A macro writes a run of instructions as one line of the source, for example `+in
590
598
 
591
599
  ## Batches of parallel agents
592
600
 
593
- When more agents name the program at the same time, give each agent one range of addresses. Each agent writes one batch file and does not apply it. A batch has the form `{"owner": {"start": "$1000", "end": "$1fff"}, "ops": [...]}`. `ops` holds the writes, as for `apply`. The owner ranges must not overlap.
601
+ When more agents name the program at the same time, give each agent one range of addresses. Each agent writes one batch file in `.c64-re-tools/local/` and does not apply it. A batch has the form `{"owner": {"start": "$1000", "end": "$1fff"}, "ops": [...]}`. `ops` holds the writes, as for `apply`. The owner ranges must not overlap.
594
602
 
595
603
  ### `join <batch>...`
596
604
 
597
- - `join` makes one batch from two or more batch files. It writes no knowledge.
598
- - `body` holds `writes`, `repeated`, `choices`, `out`, `bytes` and `sha256`.
605
+ - `join` makes one list of writes from two or more batch files. Without `--apply`, it writes no knowledge.
606
+ - Without `--apply`, `body` holds `writes`, `repeated` and `choices`. `writes` lists the joined writes.
607
+ - With `--apply`, `join` writes the joined writes as one revision, or nothing when the knowledge refuses one write. Then `body` holds `revision`, `writes`, `replaced`, `repeated` and `choices`, as for `apply`.
599
608
  - `choices` lists each place where the batches gave different values, with the value that stays.
600
609
  - At an address in the owner range of a batch, the name, the comment, the operand and the module of that batch stay. At an address that no batch owns, the first batch in the command stays.
601
610
  - A batch can give an address a name that `join` replaces. Then `join` also replaces that name in the operand expressions and macro arguments of that batch.
602
611
  - The regions of the owner come after the regions of the other batches. Thus the regions of the owner stay where they overlap.
603
612
  - A name from a batch stays when another batch removes the symbol at that address.
604
613
  - When one name or one module file is at two addresses, `join` writes nothing and gives the error `conflict`. The `error` names the addresses and the batches. Correct the batches. Then do `join` again.
605
- - The `hint` tells you to examine `choices`. `nextAction` is the `apply` command for the joined batch. Run it when the choices agree with your task.
614
+ - Without `--apply`, the `hint` tells you to examine `choices` and `writes`. `nextAction` is the same `join` with `--apply`. Run it when the choices agree with your task.
606
615
 
607
616
  ---
608
617