@henols/c64-re-tools 2.3.0-rc.5 → 2.3.0-rc.6

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
@@ -121,7 +121,7 @@ export function routineFrom(source: RoutineSource): { routine: Routine; leftOut:
121
121
  instructions.push(at - start);
122
122
  }
123
123
  }
124
- if (instructions.length === 0) throw new Refusal("invalid-input", `The knowledge has no code region in ${where(start)}-${where(end)}. Run c64-static-analysis first, or classify the code.`);
124
+ if (instructions.length === 0) throw new Refusal("invalid-input", `The knowledge has no code region in ${where(start)}-${where(end)}. Analyze the program for its code regions first, or classify the code in the project knowledge.`);
125
125
 
126
126
  // The operands: an address inside the routine moves with it; one outside may differ.
127
127
  const relocations = new Map<number, Relocation>();
@@ -238,7 +238,7 @@ export function routineText(routine: Routine): string {
238
238
  /** Reads the text of a routine file. Throws LibraryError for a file that is no routine. */
239
239
  export function parseRoutine(text: string, file: string): Routine {
240
240
  const fail = (what: string): never => {
241
- throw new Refusal("invalid-input", `${file} is not a routine file of the library: ${what}.`);
241
+ throw new Refusal("invalid-input", `${file} is not a routine file of the library: ${what}.`, { hint: "Remove the file from the library folder, or save the routine again with routine --replace." });
242
242
  };
243
243
  let value: Record<string, unknown>;
244
244
  try {
@@ -308,7 +308,7 @@ function checkLibraryOutput(path: string, root: string): void {
308
308
  const shown = relative(base, target).split(sep).join("/") || ".";
309
309
  const part = knowledgePart(shown);
310
310
  if (part !== undefined) {
311
- throw new Refusal("invalid-input", `--library: ${shown} is in ${part}, the knowledge of the project. Only the c64-knowledge skill writes it: a write there destroys the knowledge. Give a library folder beside the projects, for example ../library.`);
311
+ throw new Refusal("invalid-input", `--library: ${shown} is in ${part}, the knowledge of the project. Only the commands that change the project knowledge write it: a write there destroys the knowledge. Give a library folder beside the projects, for example ../library.`);
312
312
  }
313
313
  checkOutputPath(shown, "folder", { root: base, what: "--library" });
314
314
  return;
@@ -323,15 +323,15 @@ function checkLibraryOutput(path: string, root: string): void {
323
323
  * the output check of every script, which refuses the knowledge.
324
324
  */
325
325
  export function libraryFolder(folder: string, options: { create: boolean; cwd?: string }): string {
326
- if (folder.length === 0) throw new Refusal("invalid-input", "The library folder must not be empty.");
326
+ if (folder.length === 0) throw new Refusal("invalid-input", "The library folder must not be empty.", { hint: "Give a library folder beside the projects, for example ../library." });
327
327
  const root = options.cwd ?? process.cwd();
328
328
  const path = resolve(root, folder);
329
329
  if (options.create) checkLibraryOutput(path, root);
330
330
  const stat = statSync(path, { throwIfNoEntry: false });
331
331
  if (stat === undefined) {
332
- if (!options.create) throw new Refusal("not-found", `There is no library folder ${folder}. Save a routine to it first with routine.`);
332
+ if (!options.create) throw new Refusal("not-found", `There is no library folder ${folder}. Save a routine to it with routine first.`);
333
333
  mkdirSync(path, { recursive: true });
334
- } else if (!stat.isDirectory()) throw new Refusal("invalid-input", `${folder} is not a folder.`);
334
+ } else if (!stat.isDirectory()) throw new Refusal("invalid-input", `${folder} is not a folder.`, { hint: "Give a library folder beside the projects, for example ../library." });
335
335
  if (statSync(join(path, PROJECT_DIRECTORY), { throwIfNoEntry: false }) !== undefined) {
336
336
  throw new Refusal("invalid-input", `${folder} is a project folder. A library is a plain folder beside the projects, for example library/ at the workspace root.`);
337
337
  }
@@ -42,7 +42,7 @@ import { CODE_REGION_TYPES, SEMANTIC_ORIGINS } from "#src/knowledge/schema.ts";
42
42
  import { platformNames } from "#src/platform.ts";
43
43
  import { projectRoot } from "#src/project.ts";
44
44
  import { knowledgeAt, knowledgeNames } from "#src/knowledge/names.ts";
45
- import { listed, OPTIONS, runScript, UsageError, type Call, type CommandSpec } from "#src/script.ts";
45
+ import { listed, OPTIONS, reply, runScript, UsageError, type Call, type CommandSpec } from "#src/script.ts";
46
46
  import { align, compareReleases, identicalShare, shiftSuggestion, suggestShifts, type Release } from "./lib/compare.ts";
47
47
  import { findRoutine, libraryFolder, readLibrary, routineFrom, saveRoutine, suggest } from "./lib/library.ts";
48
48
  import { watchRelease, type Start } from "./lib/runtime.ts";
@@ -63,8 +63,8 @@ interface LoadedRelease {
63
63
 
64
64
  /**
65
65
  * A release to compare: "knowledge" (the program of the knowledge, with its
66
- * entry state and stages), a PRG at its load address, or an image.json of the
67
- * c64-unpacker skill with the entry_state.json beside it.
66
+ * entry state and stages), a PRG at its load address, or an image.json of an
67
+ * unpacked program (a capture) with the entry_state.json beside it.
68
68
  */
69
69
  function readRelease(name: string, shift: number): LoadedRelease {
70
70
  const moved = (range: AddressRange) => ({ start: range.start + shift, end: range.end + shift });
@@ -79,13 +79,13 @@ function readRelease(name: string, shift: number): LoadedRelease {
79
79
  } finally {
80
80
  db?.close();
81
81
  }
82
- noState = "The knowledge has no entry state: put a c64-unpacker capture in with knowledge.ts image <image.json>.";
82
+ noState = "The knowledge has no entry state. Put a capture of the unpacked program, with its entry state, into the project knowledge.";
83
83
  } else {
84
84
  image = readImage(name);
85
- noState = `It has no entry_state.json beside it; capture it with c64-unpacker.`;
85
+ noState = "It has no entry_state.json beside it. Capture the unpacked program again, with its entry state.";
86
86
  }
87
87
  const segments = image.segments.map(moved);
88
- if (!segments.every(inside)) throw new UsageError(`the shift moves ${name} outside $0000-$ffff`);
88
+ if (!segments.every(inside)) throw new UsageError(`The shift moves ${name} outside $0000-$ffff.`, { hint: "Give a shift that keeps each segment of the release in $0000-$ffff." });
89
89
  const memory = image.memory ?? new Uint8Array(0x10000);
90
90
  if (image.memory === undefined) for (const segment of image.segments) for (let at = segment.start; at <= segment.end; at++) memory[at] = image.byteAt(at);
91
91
  const prg = name !== "knowledge" && !name.endsWith(".json");
@@ -106,27 +106,27 @@ const MAX_ALIGNED = 64;
106
106
  /** compare: the releases byte by byte, with --align a map of two releases in blocks, and with --frames the first access of each difference in each release. */
107
107
  async function compare(call: Call): Promise<unknown> {
108
108
  const positionals = call.subjects;
109
- if (positionals.length < 2) throw new UsageError("compare needs two or more releases");
109
+ if (positionals.length < 2) throw new UsageError("compare needs two or more releases.", { hint: "Give the paths of two or more releases, or knowledge for the program in the knowledge." });
110
110
  const shifts = new Map<number, number>();
111
111
  for (const text of call.strings("shift")) {
112
112
  const match = /^(\d+):([+-]?\d+)$/.exec(text);
113
- if (match === null) throw new UsageError(`--shift must be <release>:<bytes>, for example 2:-256, not ${text}`);
113
+ if (match === null) throw new UsageError(`--shift must be <release>:<bytes>, for example 2:-256, not ${text}.`);
114
114
  if (Number(match[1]) < 1 || Number(match[1]) > positionals.length) {
115
- throw new UsageError(`--shift ${text}: there is no release ${match[1]}. This compare has ${positionals.length} releases: give a release number from 1 to ${positionals.length}`);
115
+ throw new UsageError(`--shift ${text}: there is no release ${match[1]}. This compare has ${positionals.length} releases: give a release number from 1 to ${positionals.length}.`);
116
116
  }
117
- if (shifts.has(Number(match[1]))) throw new UsageError(`--shift gives release ${match[1]} more than one shift (${shifts.get(Number(match[1]))} and ${match[2]}). Give one --shift for each release`);
117
+ if (shifts.has(Number(match[1]))) throw new UsageError(`--shift gives release ${match[1]} more than one shift (${shifts.get(Number(match[1]))} and ${match[2]}). Give one --shift for each release.`);
118
118
  shifts.set(Number(match[1]), Number(match[2]));
119
119
  }
120
120
  const frames = call.count("frames");
121
121
  const stepsFile = call.string("steps");
122
- if (stepsFile !== undefined && frames === undefined) throw new UsageError("--steps works only with --frames");
122
+ if (stepsFile !== undefined && frames === undefined) throw new UsageError("--steps works only with --frames.", { hint: "Add --frames <n>, or remove --steps." });
123
123
  const aligned = call.flag("align");
124
124
  const minBlock = call.count("min-block");
125
- if (minBlock !== undefined && !aligned) throw new UsageError("--min-block works only with --align");
125
+ if (minBlock !== undefined && !aligned) throw new UsageError("--min-block works only with --align.", { hint: "Add --align, or remove --min-block." });
126
126
  if (aligned) {
127
- if (shifts.size > 0) throw new UsageError("--align does not work with --shift: --align finds the shift of each block itself. Remove --shift");
128
- if (frames !== undefined) throw new UsageError("--align does not work with --frames: --align gives no differences to run. Run --frames without --align");
129
- if (positionals.length !== 2) throw new UsageError(`--align maps two releases, not ${positionals.length}. Give two releases`);
127
+ if (shifts.size > 0) throw new UsageError("--align does not work with --shift: --align finds the shift of each block itself.", { hint: "Remove --shift." });
128
+ if (frames !== undefined) throw new UsageError("--align does not work with --frames: --align gives no differences to run.", { hint: "Run --frames without --align." });
129
+ if (positionals.length !== 2) throw new UsageError(`--align maps two releases, not ${positionals.length}.`, { hint: "Give two releases." });
130
130
  }
131
131
  const steps: ActionStep[] = stepsFile === undefined ? [] : readActionSteps(stepsFile, "--steps", knowledgeAt());
132
132
  const loaded = positionals.map((path, index) => readRelease(path, shifts.get(index + 1) ?? 0));
@@ -146,13 +146,15 @@ async function compare(call: Call): Promise<unknown> {
146
146
  // Code added and data moved: one shift for the release cannot fit, so each block of equal bytes gets its own.
147
147
  const alignment = align(releases[0]!, releases[1]!, range ?? { start: 0x0000, end: 0xffff }, minBlock ?? 16);
148
148
  const capped = <T>(name: string, items: T[]) => ({ [name]: items.slice(0, MAX_ALIGNED), ...(items.length > MAX_ALIGNED ? { [`more${name[0]!.toUpperCase()}${name.slice(1)}`]: items.length - MAX_ALIGNED } : {}) });
149
- return {
149
+ const mapped = {
150
150
  ...compared,
151
151
  alignedShare: alignment.alignedShare,
152
152
  ...capped("blocks", alignment.blocks.map((block) => ({ a: show(block.a), b: show(block.b), shift: block.shift, bytes: block.bytes }))),
153
153
  ...capped("onlyInA", alignment.onlyInA.map(show)),
154
154
  ...capped("onlyInB", alignment.onlyInB.map(show)),
155
155
  };
156
+ const cut = alignment.blocks.length > MAX_ALIGNED || alignment.onlyInA.length > MAX_ALIGNED || alignment.onlyInB.length > MAX_ALIGNED;
157
+ return cut ? reply(mapped, { hint: `A list holds only its first ${MAX_ALIGNED} items: moreBlocks, moreOnlyInA and moreOnlyInB count the others. Give --range to map a part of the releases.` }) : mapped;
156
158
  }
157
159
  // A poor match at the load addresses can mean that the releases are placed differently.
158
160
  // Each release gets its best shifts: data that stayed can outvote code that moved, so one is not enough.
@@ -195,7 +197,24 @@ async function compare(call: Call): Promise<unknown> {
195
197
  }
196
198
  }
197
199
 
198
- return {
200
+ // The next compare: the best suggested shift that the run does not have yet, else --align for two releases.
201
+ const rangeArgs = range === undefined ? [] : ["--range", `${formatC64Address(range.start)}-${formatC64Address(range.end)}`];
202
+ const runArgs = frames === undefined ? [] : ["--frames", String(frames), ...(stepsFile === undefined ? [] : ["--steps", stepsFile])];
203
+ const best = suggested.find((suggestion) => !("current" in suggestion));
204
+ const hints: string[] = [];
205
+ let nextAction: string | undefined;
206
+ if (best !== undefined && "shift" in best) {
207
+ const next = [...applied];
208
+ next[best.release - 1] = best.shift;
209
+ const shiftArgs = next.flatMap((shift, index) => (shift === 0 ? [] : ["--shift", `${index + 1}:${shift}`]));
210
+ hints.push("identicalShare is low: the releases can be at different addresses. nextAction runs compare with the first suggested shift. Try each shift in suggestedShifts. If no shift gives a high identicalShare, run compare with --align.");
211
+ nextAction = call.next("compare", ...positionals, ...shiftArgs, ...rangeArgs, ...runArgs);
212
+ } else if (share < 0.5 && positionals.length === 2 && shifts.size === 0 && frames === undefined) {
213
+ hints.push("identicalShare is low, and no suggested shift is better. The code and the data can be at other addresses in each release. Map the releases in blocks with --align.");
214
+ nextAction = call.next("compare", ...positionals, "--align", ...rangeArgs);
215
+ }
216
+ if (comparison.moreDifferences) hints.push("differences holds only the first differences. Give --range to compare a part of the releases.");
217
+ const body = {
199
218
  ...compared,
200
219
  differences: comparison.differences.map((difference, index) => ({
201
220
  start: formatC64Address(difference.start),
@@ -221,6 +240,7 @@ async function compare(call: Call): Promise<unknown> {
221
240
  ? {}
222
241
  : { run: { frames, steps: steps.length, releases: runs, ...(comparison.differences.length === 0 ? { skipped: "The releases have no differences, so no release ran." } : {}) } }),
223
242
  };
243
+ return hints.length === 0 && nextAction === undefined ? body : reply(body, { ...(hints.length === 0 ? {} : { hint: hints.join(" ") }), nextAction });
224
244
  }
225
245
 
226
246
  /** The stages of a capture as ranges; a stage that is not a capture stage is refused. `where` names the capture. */
@@ -229,7 +249,7 @@ function stagesOf(stages: Array<Record<string, unknown>> | undefined, where = "t
229
249
  const parse = (value: unknown) => {
230
250
  const at = typeof value === "string" ? c64AddressOf(value) : undefined;
231
251
  if (at !== undefined) return at;
232
- throw new Refusal("invalid-input", `the stages of ${where} are not the stages of a c64-unpacker capture; capture it again with c64-unpacker`);
252
+ throw new Refusal("invalid-input", `The stages of ${where} are not the stages of a capture.`, { hint: "Capture the unpacked program again, with its stages, and put the capture into the project knowledge." });
233
253
  };
234
254
  return stages.map((stage) => ({
235
255
  entry: parse(stage.entry),
@@ -270,7 +290,7 @@ const showRoots = (roots: readonly Root[]) => roots.map((root) => ({ address: fo
270
290
 
271
291
  const NO_ROOTS = "none: the program in the knowledge has no entry, and the image does not hold the hardware vectors at $fffa-$ffff, so no code region is reachable or unreachable.";
272
292
 
273
- const NO_STAGES = "The program in the knowledge has no stage log. Only a capture of c64-unpacker gives one. A capture of loads holds one part of a program and has none.";
293
+ const NO_STAGES = "The program in the knowledge has no stage log. Only a capture of the unpack stages gives one. A capture of the loads of a loader holds one part of a program and has none.";
274
294
 
275
295
  /** separate: evidence from the program in the knowledge, with all ranges in --out and the first ones in the result. */
276
296
  function separateCommand(call: Call): unknown {
@@ -284,11 +304,10 @@ function separateCommand(call: Call): unknown {
284
304
  const outside = { read: found.outside.read.map(show), executed: found.outside.executed.map(show), generated: found.outside.generated.map(show) };
285
305
  const roots = showRoots(found.roots);
286
306
  const written = out === undefined ? undefined : writeReported(out, `${JSON.stringify({ roots, ranges, codeRegions, outside }, null, 1)}\n`, { what: "--out" });
287
- const rest = out === undefined ? undefined : out;
288
- const list = <T>(items: T[]) => listed(items, max, undefined, rest);
307
+ const list = <T>(items: T[]) => listed(items, max, undefined, out ?? "a larger --max-listed, or --out <file>");
289
308
  const bytes = (filter: (range: (typeof found.ranges)[number]) => boolean) => found.ranges.filter(filter).reduce((sum, range) => sum + range.end - range.start + 1, 0);
290
309
  const lastStage = loaded.stages === undefined ? undefined : loaded.stages.length - 1;
291
- return {
310
+ const body = {
292
311
  ...(loaded.entry === undefined ? {} : { entry: formatC64Address(loaded.entry) }),
293
312
  ...(lastStage === undefined
294
313
  ? { noStages: NO_STAGES }
@@ -308,6 +327,27 @@ function separateCommand(call: Call): unknown {
308
327
  ...(coverage === undefined ? {} : { outside: { read: list(outside.read), executed: list(outside.executed), generated: list(outside.generated) } }),
309
328
  ...(written === undefined ? {} : written),
310
329
  };
330
+ return withFile(body, out);
331
+ }
332
+
333
+ /** True when a list of the body ({count, listed}) holds fewer items than its count. */
334
+ function hasCutList(value: unknown, depth = 0): boolean {
335
+ if (typeof value !== "object" || value === null || depth > 3) return false;
336
+ const { count, listed: items } = value as { count?: unknown; listed?: unknown };
337
+ if (typeof count === "number" && Array.isArray(items)) return items.length < count;
338
+ return Object.values(value).some((item) => hasCutList(item, depth + 1));
339
+ }
340
+
341
+ /** The note for a cut list: with --out, the file holds all items; without it, a larger --max-listed or --out gives them. */
342
+ function cutNote(body: unknown, out: string | undefined): string | undefined {
343
+ if (!hasCutList(body)) return undefined;
344
+ return out === undefined ? "A list in the body is cut: count gives its full size. To get the rest, give a larger --max-listed." : `A list in the body is cut: count gives its full size. ${out} holds all items.`;
345
+ }
346
+
347
+ /** A body with the note for a cut list when --out holds all items. Without --out, the envelope gives the note itself. */
348
+ function withFile(body: unknown, out: string | undefined): unknown {
349
+ const note = out === undefined ? undefined : cutNote(body, out);
350
+ return note === undefined ? body : reply(body, { hint: note });
311
351
  }
312
352
 
313
353
  /** The longest text that the result shows; --out has all of it. */
@@ -343,11 +383,11 @@ function leftoversCommand(call: Call): unknown {
343
383
  };
344
384
  const written = out === undefined ? undefined : writeReported(out, `${JSON.stringify(all, null, 1)}\n`, { what: "--out" });
345
385
  const list = <T>(items: T[]) => listed(items, max, undefined, out ?? "a larger --max-listed, or --out <file>");
346
- return {
386
+ const body = {
347
387
  ...(program.entry === undefined ? {} : { entry: formatC64Address(program.entry) }),
348
388
  roots: found.roots.length === 0 ? NO_ROOTS : showRoots(found.roots),
349
389
  ...(stages === undefined ? { noStages: NO_STAGES } : { stages: stages.length }),
350
- ...(coverage === undefined ? { noCoverage: "The knowledge has no coverage, so residue is empty and no finding has access. Add coverage with coverage of the c64-knowledge skill." } : {}),
390
+ ...(coverage === undefined ? { noCoverage: "The knowledge has no coverage, so residue is empty and no finding has access. Put the coverage of runs into the project knowledge." } : {}),
351
391
  text: list(all.text.map((item) => (item.text.length > SHOWN_TEXT ? { ...item, text: `${item.text.slice(0, SHOWN_TEXT)} ...`, length: item.text.length } : item))),
352
392
  basic: list(all.basic),
353
393
  fill: list(all.fill),
@@ -356,6 +396,7 @@ function leftoversCommand(call: Call): unknown {
356
396
  deadCode: list(all.deadCode),
357
397
  ...(written === undefined ? {} : written),
358
398
  };
399
+ return withFile(body, out);
359
400
  }
360
401
 
361
402
  const platform = () => new Map(platformNames().map((entry) => [entry.name, entry.address]));
@@ -375,18 +416,18 @@ function routineCommand(call: Call): unknown {
375
416
  start = call.parseAddress(given, "<module>");
376
417
  const modules = listModules(db);
377
418
  const module = modules.find((item) => item.start === start);
378
- if (module === undefined) throw new Refusal("not-found", `No module starts at ${formatC64Address(start)}. List the modules with knowledge.ts modules, or give a range <start>-<end>.`);
419
+ if (module === undefined) throw new Refusal("not-found", `No module starts at ${formatC64Address(start)}. List the modules of the project knowledge, or give a range <start>-<end>.`);
379
420
  const segment = segmentOf(start);
380
- if (segment === undefined) throw new UsageError(`The module at ${formatC64Address(start)} is outside the segments of the program.`);
421
+ if (segment === undefined) throw new UsageError(`The module at ${formatC64Address(start)} is outside the segments of the program.`, { hint: "Give a range <start>-<end> in one segment of the program." });
381
422
  end = (modules.find((item) => item.start > start && item.start <= segment.end)?.start ?? segment.end + 1) - 1;
382
423
  title ??= module.title;
383
424
  } else {
384
425
  ({ start, end } = call.parseRange(given, "<range>"));
385
- if (segmentOf(start) === undefined || segmentOf(start) !== segmentOf(end)) throw new UsageError(`${formatC64Address(start)}-${formatC64Address(end)} is not inside one segment of the program.`);
426
+ if (segmentOf(start) === undefined || segmentOf(start) !== segmentOf(end)) throw new UsageError(`${formatC64Address(start)}-${formatC64Address(end)} is not inside one segment of the program.`, { hint: "Give a range in one segment of the program." });
386
427
  }
387
428
  const range = { start, end };
388
429
  const name = call.string("name") ?? listSymbols(db, { start, end: start }, undefined, SEMANTIC_ORIGINS)[0]?.name;
389
- if (name === undefined) throw new UsageError(`The knowledge has no user or LLM name at ${formatC64Address(start)}: give --name.`);
430
+ if (name === undefined) throw new UsageError(`The knowledge has no user or LLM name at ${formatC64Address(start)}.`, { hint: "Give --name <name>, or name the start of the routine in the project knowledge first." });
390
431
  const { routine, leftOut } = routineFrom({
391
432
  name,
392
433
  ...(title === undefined ? {} : { title }),
@@ -450,7 +491,15 @@ function matchCommand(call: Call): unknown {
450
491
  )
451
492
  .sort((a, b) => a.start.localeCompare(b.start));
452
493
  const result: Record<string, unknown> = { library, routines: routines.length, matches: list(matches) };
453
- if (out === undefined) return result;
494
+ const noMatch = "No routine of the library is in the program. A packed program can hold a routine in a packed form. Unpack the program, put the unpacked program into the project knowledge, and run match again.";
495
+ const withNote = (shown: unknown, hint: string) => [cutNote(shown, undefined), hint].filter((part) => part !== undefined).join(" ");
496
+ if (out === undefined) {
497
+ if (matches.length === 0) return reply(result, { hint: noMatch });
498
+ return reply(result, {
499
+ hint: withNote(result, "Examine differing of each match. Then nextAction writes the names of the found routines as a batch of changes."),
500
+ nextAction: call.next("match", "--library", library, "--out", ".c64-re-tools/local/match.json"),
501
+ });
502
+ }
454
503
  const db = openForRead();
455
504
  let suggestions: ReturnType<typeof suggest>;
456
505
  try {
@@ -475,11 +524,11 @@ function matchCommand(call: Call): unknown {
475
524
  }
476
525
  const { batch, known, leftOut } = suggestions;
477
526
  const written = writeReported(out, batch.length === 0 ? "[]\n" : `[\n${batch.map((write) => ` ${JSON.stringify(write)}`).join(",\n")}\n]\n`, { what: "--out" });
478
- return {
479
- ...result,
480
- batch: { ...written, writes: batch.length, known, leftOut: list(leftOut) },
481
- ...(batch.length === 0 ? {} : { apply: `knowledge.ts apply ${out} --reason "names of library routines"` }),
482
- };
527
+ const body = { ...result, batch: { ...written, writes: batch.length, known, leftOut: list(leftOut) } };
528
+ // The batch is applied by the knowledge, not by this script: the hint gives the task, not a command.
529
+ if (matches.length === 0) return reply(body, { hint: noMatch });
530
+ if (batch.length === 0) return reply(body, { hint: withNote(body, "The batch has no writes. The project knowledge has the names of the found routines already, or batch.leftOut tells why the script left out a write.") });
531
+ return reply(body, { hint: withNote(body, `Apply the changes in ${out} to the project knowledge.`) });
483
532
  }
484
533
 
485
534
  const LIBRARY = { kind: "text", value: "<folder>", required: true, help: "the library: a plain folder of routine files beside the projects, relative to the project folder, for example ../library" } as const;
@@ -488,7 +537,7 @@ const COMMANDS: CommandSpec[] = [
488
537
  {
489
538
  name: "compare",
490
539
  summary: "Compares releases byte by byte, in their common ranges, and suggests shifts when they are placed differently. With --align, maps two releases with moved code in blocks of equal bytes, each with its own shift.",
491
- subjects: [{ name: "<release>", help: "knowledge (the program in the knowledge), a PRG at its load address, or an image.json of the c64-unpacker skill with the entry_state.json beside it. Two or more", list: true }],
540
+ subjects: [{ name: "<release>", help: "knowledge (the program in the knowledge), a PRG at its load address, or the image.json of a capture of the unpacked program with the entry_state.json beside it. Two or more", list: true }],
492
541
  options: {
493
542
  shift: {
494
543
  kind: "text",
@@ -539,7 +588,7 @@ const COMMANDS: CommandSpec[] = [
539
588
  summary: "Finds each routine of the library in the program of the knowledge: the opcodes and other fixed bytes equal, and the addresses into the routine moved by one shift.",
540
589
  options: {
541
590
  library: { ...LIBRARY, help: "the library folder, relative to the project folder, for example ../library" },
542
- out: { ...OPTIONS.out, output: "file", value: "<file>", help: "write the names of the routines at the found addresses as a batch for knowledge.ts apply" },
591
+ out: { ...OPTIONS.out, output: "file", value: "<file>", help: "write the names of the routines at the found addresses as a batch of changes for the project knowledge" },
543
592
  "max-listed": OPTIONS["max-listed"],
544
593
  },
545
594
  run: matchCommand,
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  name: c64-reverse-engineering
3
- description: Use this skill to reverse engineer a C64 program or a part of it. The work goes from an unknown disk or file to documented understanding or a rebuilt program. It decides what to learn next and which specialist skill does that work. Use it for questions such as "what does this game do", "find the main loop", "understand $2100" or "rebuild this program".
3
+ description: Reverse engineers a C64 program or a part of it, from an unknown disk image or file to documented understanding or a rebuilt program. It selects the next unknown to examine and the task that examines it. Use it when the user asks what a program does, for example "what does this game do", "find the main loop" or "understand $2100". Use it to rebuild a program from its original file, for example "rebuild this program". It does not do the specialist work of each task itself, and it does not add a feature to a program.
4
4
  ---
5
5
 
6
- # c64-reverse-engineering
6
+ # C64 reverse engineering
7
7
 
8
8
  ## Purpose
9
9
 
10
- Coordinate the reverse engineering of a C64 program. Decide the next unknown to examine and the specialist skill that examines it.
10
+ Coordinate the reverse engineering of a C64 program. Select the next unknown to examine and the task that examines it.
11
11
 
12
- This skill does not do the specialist work itself.
12
+ Do the specialist work of each task as that task tells. Do not do it in another way.
13
13
 
14
14
  ## Inputs
15
15
 
@@ -22,36 +22,25 @@ This skill does not do the specialist work itself.
22
22
  - reverse engineer and rebuild the whole program
23
23
  - The current project knowledge.
24
24
 
25
- ## Tools
25
+ ## Project rules
26
26
 
27
- This skill uses the other skills. It does not use the emulator tools directly.
28
-
29
- ### Project folder
30
-
31
- One repository can hold several programs, with one project folder for each program. A project folder holds `.c64-re-tools/`. Work on one project at a time:
32
-
33
- - From the root of the repository, give `--project <folder>` to each skill script, and `project` to each emulator tool with a path.
27
+ - One repository can hold several programs, with one project folder for each program. Work on one project at a time.
34
28
  - Write all files in the project folder. Do not write files at the root of the repository.
35
- - 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.
36
- - 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/`.
37
- - 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.
38
- - 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.
39
- - A subagent can have no emulator tools. Give it its experiments as run files of the c64-testing skill. Each run starts its own emulator, so many runs can go at the same time. The emulator of the emulator tools is one machine, for the main session.
40
- - To name a large program with more agents at the same time, give each agent one range of addresses. Each agent writes a batch with its owner range. Then join the batches with `knowledge.ts join` of the c64-knowledge skill, and apply the result one time.
41
- - Do not write a build script or a merge script. `source.ts generate --loader` of c64-source writes and assembles the loader, and `knowledge.ts join` of c64-knowledge joins the batches.
29
+ - A subagent can have no emulator tools. Give it its experiments as test run files. Many test runs can go at the same time. The emulator tools are for the main session only.
30
+ - To name a large program with more agents at the same time, give each agent one range of addresses. Each agent writes a batch of knowledge changes with its owner range. Then join the batches of the agents, and apply the joined batch to the project knowledge one time.
31
+ - Do not write a build script or a merge script. The generation of the source writes and assembles the loader. The project knowledge joins the batches.
42
32
  - Do not write a script that makes a deliverable again, for example a capture, copy or replay script. Commit the deliverable.
43
- - Write the knowledge only with the c64-knowledge script. Do not write or edit the files in `.c64-re-tools/knowledge/` yourself.
44
33
 
45
34
  ## What a rebuild keeps
46
35
 
47
36
  These rules apply to each rebuild:
48
37
 
49
- - Do not keep a cracktro. The capture of the c64-unpacker skill starts at the last stage, so the code of a cracktro is not in the program. Cut the data of a cracktro that the program does not read with `capture --exclude`.
38
+ - Do not keep a cracktro. A capture of a packed program starts at the last stage, so the code of a cracktro is not in the program. When the capture has data of a cracktro that the program does not read, capture again and exclude that range.
50
39
  - Keep all other bytes: unused bytes, dead code, old copies, texts and leftovers of the development. Record each one as a region with a comment. Do not remove them.
51
40
  - Keep a copy protection in the source, off by default. Record a `protection` switch and its patches.
52
41
  - Keep a trainer and a cheat in the source, off by default. Record a `trainer` or `cheat` switch and its patches.
53
42
  - When two or more releases have different corrections, record each release and one `fix` switch for each correction. The switch names the releases that have the correction. The default build has all corrections.
54
- - Record all switches with the c64-knowledge skill. Do not write a switch in a source file.
43
+ - Record all switches in the project knowledge. Do not write a switch in a source file.
55
44
  - When a crack removed a copy protection and no release has its bytes, write this in a comment and in the answer.
56
45
 
57
46
  ## Workflow
@@ -64,26 +53,26 @@ Select the path for the scope:
64
53
  ### The loop
65
54
 
66
55
  1. Write down the scope. Stop when the scope is complete.
67
- 2. Read the current knowledge for the subject with the c64-knowledge skill. Do not examine again what the knowledge already explains.
68
- 3. Find the next unknown or blocker, and use the specialist for it:
56
+ 2. Read the current project knowledge for the subject. Do not examine again what the knowledge already explains.
57
+ 3. Find the next unknown or blocker. Do the task for it:
69
58
 
70
- | Unknown | Skill |
59
+ | Unknown | Task |
71
60
  |---|---|
72
- | The files on a disk image, or a file to extract | c64-disk |
73
- | A BASIC program, and where it starts machine code | c64-basic |
74
- | A program that can be packed or crunched | c64-unpacker |
75
- | What the program does at run time: values, input, timing, screen | emulator |
76
- | The routines, code, data and references of the program | c64-static-analysis |
77
- | The platform meaning of an address or a register | c64-memory-map |
78
- | Differences between releases of the program | c64-provenance `compare`, then c64-knowledge `release`, `switch` and `patch` |
79
- | Leftovers of the development, a crack or a recrack: texts, old copies, unused bytes, dead code | c64-provenance `leftovers` |
80
- | A routine that another program of the workspace has, for example a music driver | c64-provenance, with the library |
81
- | Source code from the knowledge | c64-source |
82
- | Source code to build | c64-assembler |
83
- | Proof that a rebuild behaves as the original | c64-testing |
61
+ | The files on a disk image, or a file to extract | List the disk image. Extract the file into the project. |
62
+ | A BASIC program, and where it starts machine code | List the BASIC program. Find its SYS address. |
63
+ | A program that can be packed or crunched | Examine the program for a packer. Capture the unpacked program. |
64
+ | What the program does at run time: values, input, timing, screen | Run the program in the emulator. Read the values, give the input, measure the timing and capture the screen. |
65
+ | The routines, code, data and references of the program | Analyze the program statically. |
66
+ | The platform meaning of an address or a register | Find the address in the memory map of the C64. |
67
+ | Differences between releases of the program | Compare the releases. Record each release, switch and patch in the project knowledge. |
68
+ | Leftovers of the development, a crack or a recrack: texts, old copies, unused bytes, dead code | Find the leftovers in the program. |
69
+ | A routine that another program of the workspace has, for example a music driver | Match the program against the routine library of the workspace. |
70
+ | Source code from the knowledge | Generate the source from the project knowledge. |
71
+ | Source code to build | Assemble the source. |
72
+ | Proof that a rebuild behaves as the original | Test the rebuild against the original. |
84
73
 
85
74
  4. Interpret the result. Keep observed facts apart from your conclusions.
86
- 5. Record each conclusion that the evidence supports with the c64-knowledge skill: names of routines and variables, data classifications, comments.
75
+ 5. Record each conclusion that the evidence supports in the project knowledge: names of routines and variables, data classifications, comments.
87
76
  6. Go back to step 3 until the scope is complete.
88
77
 
89
78
  ### The stages of a full rebuild
@@ -92,22 +81,22 @@ Do the stages in this sequence. Go to the next stage only when its exit check is
92
81
 
93
82
  | Stage | Work | Exit check |
94
83
  |---|---|---|
95
- | 1. Acceptance | Ask the user for the criteria of the rebuild. Offer these: identical source, a verified loader, passed c64-testing scenarios, passed replays of the recordings, and a list of the code that no run executed. Also offer documentation of the flows, tables, formats and graphics. | The user gave the criteria. |
96
- | 2. Get | c64-disk: list the disk. Extract the start file into `original/`. | The start file is in the project. |
97
- | 3. Start | c64-basic: find the SYS address of the BASIC start. | You have the entry address. |
98
- | 4. Unpack | c64-unpacker: examine the program with `unpacker.ts inspect`, `trace` and `stages`. Capture a packed program with `unpacker.ts capture` into `.c64-re-tools/local/`. When a segment is the data of a cracktro and the program does not read it, capture again with `--exclude` for that range. Then c64-knowledge: put the capture, or the PRG of a program without a packer, into the knowledge with `knowledge.ts image`. | `program` of c64-knowledge shows the segments and the entry. |
99
- | 5. Run | First record: ask the user to play each part that the scope names, with `testing.ts record --play` of c64-testing. Tell the user which parts. Record a part yourself only when the sessions of the user do not have it. Put the recordings in `tests/recordings/`. Then use the emulator skill and `testing.ts run` of c64-testing for the parts that a recording cannot have. Write a coverage map for each part into `.c64-re-tools/local/`. Then c64-knowledge: add the maps and the `coverage.bin` of each recording with `knowledge.ts coverage`. | `program` of c64-knowledge lists a coverage map for each part that the scope names. |
100
- | 6. Analyze | c64-static-analysis: `static-analysis.ts analyze`. It reads the program and the coverage from the knowledge. | No coverage conflict is open. |
101
- | 7. Name | c64-provenance: if the workspace has a library, find its routines with `provenance.ts match` and apply the batch. Then c64-knowledge and c64-memory-map: name each routine in the scope and give it a comment. Record the modules. When the scope has hundreds of routines, ask the user which routines to name. The source gives the other routines an `l_xxxx` label. | Each routine that the user selected has a name and a comment. |
102
- | 8. Releases and switches | c64-knowledge: record the base release with `knowledge.ts release <label> --file original/<file> --base`. For a capture, copy its folder to `original/<label>/` first, because git ignores `.c64-re-tools/local/`. Record each other release. c64-provenance: compare the releases with `provenance.ts compare`, and find leftovers with `provenance.ts leftovers`. c64-knowledge: record a switch for each copy protection, trainer, cheat, crack change and correction, and a patch for each of its ranges. Record each leftover as a region with a comment. | `knowledge.ts switches` lists each switch. Each difference between the releases is in a patch, or the answer gives it as an exception. |
103
- | 9. Generate | c64-source: `source.ts generate --out src`. For an unpacked program, add `--loader`. | `check.identical` is true. `default.result` is `fits`. Each item of `releases` is `identical`, or `layout differs` as an exception. For an unpacked program, `loader.verified` is true. |
104
- | 10. Build and test | c64-assembler: `assembler.ts build` with `--release <base label> --compare` into `build/`, and the default build without options. c64-testing: `testing.ts test` with the scenarios in `tests/`. Replay each recording on the rebuild with `testing.ts replay`: give the checkpoint routine, the state and the random state (`--pin`) with the names of stage 7. | The criteria of stage 1 are true. |
105
- | 11. Document | When the criteria ask for documentation: c64-docs into `README.md` and `docs/`, with `docs.ts generate` and `docs.ts link`. | `docs.ts link --check` of c64-docs gives `result: "PASS"`. |
84
+ | 1. Acceptance | Ask the user for the criteria of the rebuild. Offer these criteria: identical source, a verified loader, passed test scenarios and passed replays of the recordings. Also offer a list of the code that no run executed, and documentation of the flows, tables, formats and graphics. | The user gave the criteria. |
85
+ | 2. Get | List the disk image. Extract the start file into `original/`. | The start file is in the project. |
86
+ | 3. Start | Find the SYS address of the BASIC start. | You have the entry address. |
87
+ | 4. Unpack | Examine the program for a packer. Trace it and find its stages. Capture a packed program into `.c64-re-tools/local/`. When a segment is the data of a cracktro and the program does not read it, capture again and exclude that range. Put the capture, or the PRG of a program without a packer, into the project knowledge. | The program in the project knowledge has the segments and the entry. |
88
+ | 5. Run | First, record. Ask the user to play each part that the scope names, in a recording session. Tell the user which parts. Record a part yourself only when the sessions of the user do not have it. Put the recordings in `tests/recordings/`. Then run the parts that a recording cannot have, in the emulator or as test runs. Write a coverage map for each part into `.c64-re-tools/local/`. Add the maps and the `coverage.bin` of each recording to the project knowledge. | The program in the project knowledge has a coverage map for each part that the scope names. |
89
+ | 6. Analyze | Analyze the program statically. The analysis reads the program and the coverage from the project knowledge. | No coverage conflict is open. |
90
+ | 7. Name | If the workspace has a routine library, match the program against it. Apply the matches to the project knowledge. Then name each routine in the scope and give it a comment. Find the platform addresses in the memory map of the C64. Record the modules. When the scope has hundreds of routines, ask the user which routines to name. The source gives the other routines an `l_xxxx` label. | Each routine that the user selected has a name and a comment. |
91
+ | 8. Releases and switches | For a capture, copy its folder to `original/<label>/` first, because git ignores `.c64-re-tools/local/`. Record the original file as the base release in the project knowledge. Record each other release. Compare the releases. Find the leftovers. Record a switch for each copy protection, trainer, cheat, crack change and correction. Record a patch for each range of a switch. Record each leftover as a region with a comment. | The project knowledge lists each switch. Each difference between the releases is in a patch, or the answer gives it as an exception. |
92
+ | 9. Generate | Generate the source from the project knowledge into `src`. For an unpacked program, also generate the loader. | The result of the generation is PASS. Each release with the result `layout differs` is an exception in the answer. |
93
+ | 10. Build and test | Build the base release into `build/`, and compare it with the original. Build the default build. Run the test scenarios in `tests/`. Replay each recording on the rebuild. For each replay, give the checkpoint routine, the state and the random state with the names of stage 7. | The criteria of stage 1 are true. |
94
+ | 11. Document | When the criteria ask for documentation, generate it into `README.md` and `docs/`. Then link it. | The link check of the documentation gives PASS. |
106
95
  | 12. Hand over | Find each file that you made outside `.c64-re-tools/local/` and that is not a deliverable. Move it into `.c64-re-tools/local/`. Then give the answer (below). | Each file that you made outside `.c64-re-tools/local/` is a deliverable. |
107
96
 
108
- In stage 5, make the recordings before you change the program. A recording needs no names, and its coverage gives the analysis of stage 6 more code. If you cannot get to a part of the program, ask the user how to get to it. Do stages 7 to 9 again until the source is clear. Each run of c64-source writes the source again.
97
+ In stage 5, make the recordings before you change the program. A recording needs no names, and its coverage gives the analysis of stage 6 more code. If you cannot get to a part of the program, ask the user how to get to it. Do stages 7 to 9 again until the source is clear. Each generation writes the source again.
109
98
 
110
- After stage 7, save each routine that other programs can have to the library with `provenance.ts routine` of c64-provenance. Examples are a music driver, a decruncher and a loader. Ask the user before you make a library.
99
+ After stage 7, save each routine that other programs can have to the routine library of the workspace. Examples are a music driver, a decruncher and a loader. Ask the user before you make a library.
111
100
 
112
101
  ### Deliverables of a full rebuild
113
102
 
@@ -115,8 +104,8 @@ After stage 7, save each routine that other programs can have to the library wit
115
104
  - the file of each release in `original/`
116
105
  - the generated source
117
106
  - the built program and the loader
118
- - the c64-testing scenarios
119
- - the c64-testing recordings in `tests/recordings/`
107
+ - the test scenarios
108
+ - the recordings in `tests/recordings/`
120
109
  - the documentation in `README.md` and `docs/`, when the criteria ask for it
121
110
  - the runs in `runs/` that the knowledge gives as evidence
122
111
  - the scripts in `tools/` for the formats of this program, when you wrote them.
@@ -128,7 +117,7 @@ All other files that you made are not deliverables. Keep them in `.c64-re-tools/
128
117
  Give the user a short answer at the end. Do not write a report file. Write a report file only when the user asks for it. The knowledge, `docs/` and the scenarios keep the durable results. The answer has:
129
118
 
130
119
  1. Each criterion of stage 1 and its result, and each exception that the user accepted.
131
- 2. The count of the code ranges that no run executed. The ranges are in the `not_executed.json` file of c64-source.
120
+ 2. The count of the code ranges that no run executed. The ranges are in `not_executed.json` in the folder of the generated source.
132
121
  3. The switches: the name, the kind and the default of each, and the releases that have it on. Also a copy protection that a crack removed and that no release has.
133
122
  4. Open questions: what the evidence does not explain.
134
123
 
@@ -140,20 +129,20 @@ If the project has no layout, use this one. No script checks it. Each script tak
140
129
 
141
130
  ```
142
131
  original/ the disk image or the program as you got it
143
- src/ the generated source from c64-source
144
- build/ programs from c64-assembler
145
- tests/ c64-testing scenarios, and the recordings in tests/recordings/
132
+ src/ the generated source
133
+ build/ the built programs
134
+ tests/ the test scenarios, and the recordings in tests/recordings/
146
135
  runs/ the runs that the knowledge gives as evidence
147
- docs/ the documentation from c64-docs, with the reference in docs/reference/
136
+ docs/ the documentation, with the reference in docs/reference/
148
137
  tools/ scripts for the formats of this program only
149
- README.md the entry page of the documentation from c64-docs
138
+ README.md the entry page of the documentation
150
139
  ```
151
140
 
152
141
  Commit each folder of the layout and `.c64-re-tools/knowledge/`. The knowledge holds the program, the entry state and the coverage, so the project needs no other folder for them. Put all other files that you make in `.c64-re-tools/local/`, also the captures and the coverage maps after you put them into the knowledge. Do not let git ignore a folder of the layout. Do not change the `.gitignore` files of the project.
153
142
 
154
143
  If the project has a layout, use that layout.
155
144
 
156
- A workspace with several projects keeps its library of routines in `library/` beside the projects. The library is not a project folder.
145
+ A workspace with several projects keeps its routine library in `library/` beside the projects. The library is not a project folder.
157
146
 
158
147
  ## Knowledge
159
148
 
@@ -161,10 +150,7 @@ Read:
161
150
  - the knowledge for the addresses, ranges and routines in the scope
162
151
  - the history of a conclusion that is surprising or that a person disputes.
163
152
 
164
- Automatic write:
165
- - none directly.
166
-
167
- Record durable conclusions with the c64-knowledge skill. Do not store:
153
+ Record durable conclusions in the project knowledge. Do not store:
168
154
  - the state of the current investigation
169
155
  - a name only because a routine needs a temporary name
170
156
  - guesses.
@@ -175,17 +161,14 @@ A clear answer for the scope, with the durable conclusions in the project knowle
175
161
 
176
162
  ## Failure and conflicts
177
163
 
178
- - A skill reports `installation-incomplete` or `machine-unavailable`: stop the whole task. Give the message to the user and wait for the user. Do not continue with other skills. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
164
+ - A task reports `installation-incomplete` or `machine-unavailable`: stop the whole task. Give the message to the user and wait for the user. Do not continue with other tasks.
179
165
  - A tool gives a wrong result, and the exit check of a stage cannot be true. Tell the user the defect and the evidence, and wait for the user. Do not make a workaround, for example a change to a generated file. When the user accepts an exception, give the defect and the exception in the answer of stage 12.
180
166
  - If the evidence does not support a conclusion, keep the unknown and get more evidence. Do not make up a meaning.
181
167
  - Before you replace current knowledge from the user or the LLM, read its history and the evidence for it.
182
- - A conflict from the static analysis: find the correct answer at run time with the emulator skill.
168
+ - A conflict from the static analysis: find the correct answer at run time in the emulator.
183
169
  - A test that is INCONCLUSIVE does not show a defect. Find why the test could not compare.
184
170
 
185
- ## Handoffs
186
-
187
- All specialist skills in the table above.
188
-
189
- A new feature or a correction of the rebuilt program → c64-development
171
+ ## After the work
190
172
 
191
- The start of a new program from the rebuilt program → c64-export
173
+ - To add a feature or a correction to the rebuilt program, develop it as a change of a rebuilt program.
174
+ - To start a new program from the rebuilt program, export the rebuilt program as a new project.