@henols/c64-re-tools 2.3.0-rc.4 → 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 (62) 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/play.ts +1 -1
  39. package/skills/c64-testing/scripts/lib/recording.ts +7 -7
  40. package/skills/c64-testing/scripts/lib/replay.ts +7 -7
  41. package/skills/c64-testing/scripts/lib/runs.ts +6 -7
  42. package/skills/c64-testing/scripts/lib/scenario.ts +12 -6
  43. package/skills/c64-testing/scripts/testing.ts +36 -16
  44. package/skills/c64-unpacker/SKILL.md +273 -127
  45. package/skills/c64-unpacker/scripts/lib/loads.ts +3 -3
  46. package/skills/c64-unpacker/scripts/unpacker.ts +70 -11
  47. package/skills/emulator/SKILL.md +12 -12
  48. package/src/errors.ts +22 -2
  49. package/src/host/vice/session.ts +1 -1
  50. package/src/host-client/entry-state.ts +1 -1
  51. package/src/host-client/image.ts +3 -3
  52. package/src/host-client/steps.ts +1 -1
  53. package/src/knowledge/expression.ts +1 -1
  54. package/src/knowledge/names.ts +2 -3
  55. package/src/knowledge/program.ts +2 -3
  56. package/src/knowledge/write.ts +2 -2
  57. package/src/mcp/inputs.ts +1 -1
  58. package/src/mcp/tools/input.ts +1 -1
  59. package/src/mcp/tools/media.ts +1 -1
  60. package/src/native/exomizer.ts +2 -2
  61. package/src/project.ts +2 -2
  62. package/src/script.ts +164 -75
@@ -15,7 +15,7 @@ import { readPrg } from "#src/host-client/image.ts";
15
15
  import { writeReported, type Written } from "#src/host-client/transfer.ts";
16
16
  import { ViceSessionClient } from "#src/host-client/vice-session.ts";
17
17
  import { knowledgeAt, knowledgeNames } from "#src/knowledge/names.ts";
18
- import { listed, OPTIONS, runScript, UsageError, type Call, type CommandSpec, type OptionSpec } from "#src/script.ts";
18
+ import { listed, OPTIONS, reply, runScript, UsageError, type Call, type CommandSpec, type OptionSpec } from "#src/script.ts";
19
19
  import { basicStart, inspect, readMemoryMap, underRom, writtenThenExecuted } from "./lib/evidence.ts";
20
20
  import { loads, readLoadSteps } from "./lib/loads.ts";
21
21
  import { callReturn, captureSegments, executedIn, inRanges, mergeMaps, stageCandidates, stagePoints, withoutRanges } from "./lib/stages.ts";
@@ -39,7 +39,7 @@ async function runSteps(client: ViceSessionClient, steps: ActionStep[]): Promise
39
39
  }
40
40
 
41
41
  /** inspect, trace, stages and capture take a PRG: a disk, tape or cartridge file goes to loads. */
42
- const NOT_PRG_REMEDY = "Use loads, which runs a disk, tape or cartridge image, or get the PRG out of it with disk.ts read of the c64-disk skill";
42
+ const NOT_PRG_REMEDY = "Use loads, which runs a disk, tape or cartridge image, or extract the PRG from the image and give the path of that PRG";
43
43
  const readProgram = (path: string) => readPrg(path, NOT_PRG_REMEDY).bytes;
44
44
 
45
45
  async function trace(program: string, options: { frames: number; entry?: number; steps: ActionStep[]; max: number }): Promise<{ output: Record<string, unknown>; failed: boolean }> {
@@ -112,7 +112,7 @@ async function trace(program: string, options: { frames: number; entry?: number;
112
112
  }
113
113
  }
114
114
 
115
- const NO_BASIC = "the program is no BASIC program at $0801, so RUN cannot start it. Give --entry <address>.";
115
+ const NO_BASIC = "The program is not a BASIC program at $0801, so RUN cannot start it. Give --entry <address>.";
116
116
 
117
117
  /** Why a run stopped before its frames: what stopped the CPU, where, and after how many frames. */
118
118
  function stoppedEarly(stopReason: string, pc: number, ran: number, frames: number): string {
@@ -585,20 +585,79 @@ const stepsOf = (call: Call) => {
585
585
  const path = call.string("steps");
586
586
  return path === undefined ? [] : readActionSteps(path, "--steps", knowledgeAt());
587
587
  };
588
+ /** The --entry and --steps of the call, so that the next command starts the program in the same way. */
589
+ const sameStart = (call: Call): string[] => {
590
+ const entry = call.address("entry");
591
+ const steps = call.string("steps");
592
+ return [...(entry === undefined ? [] : ["--entry", formatC64Address(entry)]), ...(steps === undefined ? [] : ["--steps", steps])];
593
+ };
594
+ /** The hints of a result, as one text, or undefined when there is none. */
595
+ const joined = (hints: Array<string | undefined>) => {
596
+ const given = hints.filter((hint): hint is string => hint !== undefined);
597
+ return given.length === 0 ? undefined : given.join(" ");
598
+ };
599
+ /** The folder that a capture writes when the agent follows the nextAction of stages. */
600
+ const CAPTURE_OUT = ".c64-re-tools/local/capture";
601
+
602
+ /** inspect: the next step is a run of the program with trace. A program without a BASIC start needs --entry for it. */
603
+ function inspected(call: Call) {
604
+ const program = call.subject(0);
605
+ const bytes = readProgram(program);
606
+ const evidence = inspect(bytes);
607
+ if (basicStart(bytes) === undefined) return reply(evidence, { hint: "The program is not a BASIC program at $0801, so RUN cannot start it. Find the start address of the code, and give it as --entry to trace, stages and capture." });
608
+ return reply(evidence, { hint: "Run trace to get the evidence of a run.", nextAction: call.next("trace", program) });
609
+ }
610
+
611
+ /** trace: after code that the program wrote and executed, the next step is stages. */
612
+ function traced(call: Call, { output, failed }: { output: Record<string, unknown>; failed: boolean }) {
613
+ const result = outcome({ output, failed });
614
+ if (failed) return result;
615
+ const more = (output.writtenThenExecuted as { rest?: string }).rest === undefined ? undefined : "The list writtenThenExecuted is cut. Give a larger --max-listed to see all of it.";
616
+ if (output.packing === "unlikely") return reply(result, { hint: joined(["The program executed no code that it wrote. If the program waits for a key or a joystick, give the input in --steps and run trace again.", more]) });
617
+ return reply(result, { hint: joined(["Run stages to find the entry of each stage.", more]), nextAction: call.next("stages", call.subject(0), ...sameStart(call)) });
618
+ }
619
+
620
+ /** stages: the entry of the last stage is usually the start of the program; the next step is a capture there. */
621
+ function staged(call: Call, { output, failed }: { output: Record<string, unknown>; failed: boolean }) {
622
+ const result = outcome({ output, failed });
623
+ if (failed) return result;
624
+ const last = (output.stages as Array<{ entry: string }>).at(-1)!.entry;
625
+ const more = output.moreStages === true ? `The script followed only the first ${MAX_STAGES} stages. Give a larger --min-stage, so that small stages join.` : undefined;
626
+ return reply(result, {
627
+ hint: joined([more, `Disassemble the code at ${last}, the entry of the last stage. Make sure that it is the start of the program and not a second unpacker. Then capture at that address.`]),
628
+ nextAction: call.next("capture", call.subject(0), "--until", last, "--out", CAPTURE_OUT, ...sameStart(call)),
629
+ });
630
+ }
631
+
632
+ /** capture: the next step is a check of the entry, then the capture goes into the project knowledge. */
633
+ function captured(call: Call, { output, failed }: { output: Record<string, unknown>; failed: boolean }) {
634
+ const result = outcome({ output, failed });
635
+ if (failed) return result;
636
+ return reply(result, { hint: `Disassemble the code at ${output.pc as string}. Make sure that it is the program and not the unpacker again. Then put the capture ${call.string("out")!}/image.json into the project knowledge.` });
637
+ }
638
+
639
+ /** loads: each capture goes into the project knowledge when the agent works on that part. */
640
+ function loaded(call: Call, { output, failed }: { output: Record<string, unknown>; failed: boolean }) {
641
+ const result = outcome({ output, failed });
642
+ if (failed) return result;
643
+ const out = call.string("out")!;
644
+ const drive = call.flag("drive") ? ` Put the drive RAM ${out}/<name>/drive8.prg into the project knowledge in the space drive8.` : "";
645
+ return reply(result, { hint: `Put the capture ${out}/<name>/image.json of the part that you work on into the project knowledge.${drive}` });
646
+ }
588
647
 
589
648
  const COMMANDS: CommandSpec[] = [
590
649
  {
591
650
  name: "inspect",
592
651
  summary: "Packing evidence: the BASIC start and the entropy of the bytes.",
593
652
  subjects: [PROGRAM],
594
- run: (call) => inspect(readProgram(call.subject(0))),
653
+ run: inspected,
595
654
  },
596
655
  {
597
656
  name: "trace",
598
657
  summary: "Runs the program and reports the memory that it wrote and then executed.",
599
658
  subjects: [PROGRAM],
600
659
  options: { frames: FRAMES, entry: ENTRY, steps: STEPS, "max-listed": OPTIONS["max-listed"] },
601
- run: async (call) => outcome(await trace(call.subject(0), { frames: call.count("frames")!, steps: stepsOf(call), max: call.count("max-listed")!, ...entryOf(call) })),
660
+ run: async (call) => traced(call, await trace(call.subject(0), { frames: call.count("frames")!, steps: stepsOf(call), max: call.count("max-listed")!, ...entryOf(call) })),
602
661
  },
603
662
  {
604
663
  name: "stages",
@@ -610,8 +669,8 @@ const COMMANDS: CommandSpec[] = [
610
669
  const steps = stepsOf(call);
611
670
  // A runUntil step to a raster line or a memory value cannot be tracked in chunks of frames; capture takes it.
612
671
  const untracked = steps.findIndex((step) => "runUntil" in step && !trackedRunUntil(step));
613
- if (untracked >= 0) throw new UsageError(`--steps ${call.string("steps")!}: step ${untracked + 1}: stages takes a runUntil step only with an address target without a condition. Use frames steps, or capture`);
614
- return outcome(await stages(call.subject(0), { frames: call.count("frames")!, steps, minStage: call.count("min-stage")!, ...entryOf(call) }));
672
+ if (untracked >= 0) throw new UsageError(`--steps ${call.string("steps")!}: step ${untracked + 1}: stages takes a runUntil step only with an address target without a condition. Use frames steps, or use capture.`);
673
+ return staged(call, await stages(call.subject(0), { frames: call.count("frames")!, steps, minStage: call.count("min-stage")!, ...entryOf(call) }));
615
674
  },
616
675
  },
617
676
  {
@@ -636,9 +695,9 @@ const COMMANDS: CommandSpec[] = [
636
695
  const show = (item: AddressRange) => `${formatC64Address(item.start)}-${formatC64Address(item.end)}`;
637
696
  const holds = (item: AddressRange) => until >= item.start && until <= item.end;
638
697
  const excluded = call.ranges("exclude").find(holds);
639
- if (excluded !== undefined) throw new UsageError(`--exclude ${show(excluded)} holds the entry --until ${formatC64Address(until)}. A segment must hold the entry: give an --exclude range without it`);
640
- if (range !== undefined && !holds(range)) throw new UsageError(`--range ${show(range)} does not hold the entry --until ${formatC64Address(until)}. Give a --range that holds the entry`);
641
- return outcome(await capture(call.subject(0), { until, out: call.string("out")!, ...(range === undefined ? {} : { range }), exclude: call.ranges("exclude"), timeoutFrames: call.count("timeout-frames")!, steps: stepsOf(call), minStage: call.count("min-stage")!, ...entryOf(call) }));
698
+ if (excluded !== undefined) throw new UsageError(`--exclude ${show(excluded)} holds the entry --until ${formatC64Address(until)}. A segment must hold the entry: give an --exclude range without it.`);
699
+ if (range !== undefined && !holds(range)) throw new UsageError(`--range ${show(range)} does not hold the entry --until ${formatC64Address(until)}. Give a --range that holds the entry.`);
700
+ return captured(call, await capture(call.subject(0), { until, out: call.string("out")!, ...(range === undefined ? {} : { range }), exclude: call.ranges("exclude"), timeoutFrames: call.count("timeout-frames")!, steps: stepsOf(call), minStage: call.count("min-stage")!, ...entryOf(call) }));
642
701
  },
643
702
  },
644
703
  {
@@ -652,7 +711,7 @@ const COMMANDS: CommandSpec[] = [
652
711
  "min-block": { kind: "count", value: "<bytes>", min: 1, max: 0x10000, default: 64, help: "write a changed block of at least this many bytes (default 64)" },
653
712
  exclude: EXCLUDE,
654
713
  },
655
- run: async (call) => outcome(await loads(call.subject(0), { out: call.string("out")!, steps: readLoadSteps(call.string("steps")!), drive: call.flag("drive"), minBlock: call.count("min-block")!, exclude: call.ranges("exclude") })),
714
+ run: async (call) => loaded(call, await loads(call.subject(0), { out: call.string("out")!, steps: readLoadSteps(call.string("steps")!), drive: call.flag("drive"), minBlock: call.count("min-block")!, exclude: call.ranges("exclude") })),
656
715
  },
657
716
  ];
658
717
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: emulator
3
- description: Use this skill to operate and debug the live emulator through the MCP tools of the c64-re-tools machine server. For the C64, the tool names start with c64_. It loads programs and disks, controls and steps the CPU, and sets breakpoints and watchpoints. It reads and writes memory and registers, gives keyboard and joystick input, advances frames and captures the screen. Do not use it for static analysis, project knowledge, assembly or disk inspection.
3
+ description: Operates and debugs the live emulator through the MCP tools of the machine server. For the C64, the tool names start with c64_. It loads programs and disks, controls and steps the CPU, and sets breakpoints and watchpoints. It reads and writes memory and registers, gives keyboard and joystick input, advances frames and captures the screen. Use it to get runtime evidence or runtime state from the machine. Use it when the user must play or look at the program in a window. It does not analyze code statically, change the project knowledge, assemble source or list the files on a disk image.
4
4
  ---
5
5
 
6
6
  # emulator
@@ -19,7 +19,7 @@ The MCP server knows the machine and the emulator. Its instructions, its tool de
19
19
  - The target address, state or condition, when the question needs one.
20
20
  - The project path of the program or disk to load, when the question needs one.
21
21
 
22
- A tool takes addresses, not names. The server instructions give the address format. Get the address of a name with `knowledge.ts at <name>` of the c64-knowledge skill.
22
+ A tool takes addresses, not names. The server instructions give the address format. Get the address of a name from the project knowledge.
23
23
 
24
24
  ## Tools
25
25
 
@@ -59,11 +59,11 @@ To keep a coverage run:
59
59
  1. Clear the memory map with `c64_memmap` action `clear`.
60
60
  2. Run the part of the program that you want to keep.
61
61
  3. Read the map with `c64_memmap` action `read` and `out`, for example to `.c64-re-tools/local/attract.bin`.
62
- 4. Add the file to the knowledge with `coverage` of the c64-knowledge skill.
62
+ 4. Add the file to the coverage of the project knowledge.
63
63
 
64
64
  ## Workflow
65
65
 
66
- 1. Read the project knowledge for the addresses in the question. Use the c64-knowledge skill.
66
+ 1. Read the project knowledge for the addresses in the question.
67
67
  2. Get the machine state with `c64_status`.
68
68
  3. Load the subject if it is not loaded. Use `c64_autostart` to start it as a user does. Use `c64_program_load` to put a program in memory with no start.
69
69
  4. Set the stop condition. Use a breakpoint, a watchpoint or a `c64_run_until` target. Add a condition when the stop must occur only in one state.
@@ -78,7 +78,7 @@ Before a risky experiment, save the state with `c64_snapshot`. Restore it to try
78
78
  Some programs read input in a way that the input tools cannot give. The tool description tells when. Then use one of these ways:
79
79
 
80
80
  - Open the window and ask the user to give the input.
81
- - Record a session with a `press` step. Use `testing.ts record` of the c64-testing skill.
81
+ - Record a test session with a `press` step.
82
82
 
83
83
  Do not change the program to make it accept the input.
84
84
 
@@ -102,7 +102,7 @@ Automatic write:
102
102
  - none.
103
103
 
104
104
  Write after interpretation:
105
- - a symbol, a region or a comment that the runtime evidence justifies. Record it with the c64-knowledge skill.
105
+ - a symbol, a region or a comment that the runtime evidence justifies. Record it in the project knowledge.
106
106
 
107
107
  Do not store:
108
108
  - breakpoints or watchpoints
@@ -128,11 +128,11 @@ An error is `{"error": {"code": "...", "message": "..."}}`. The message tells wh
128
128
  - `stopReason` `timeout` or `jam`: this is evidence too. Report it. For `jam`, report the address.
129
129
  - A different code: the message names the cause. Change the call, or report the cause.
130
130
 
131
- If the runtime evidence does not agree with the current knowledge, do not change the knowledge. Report the conflict and hand it to c64-knowledge.
131
+ If the runtime evidence does not agree with the current knowledge, do not change the knowledge. Report the conflict with the runtime evidence. Then resolve the conflict in the project knowledge.
132
132
 
133
- ## Handoffs
133
+ ## Other tasks
134
134
 
135
- - Static explanation of code → c64-static-analysis
136
- - Durable conclusion or a knowledge conflict → c64-knowledge
137
- - Comparison or assertion between runs → c64-testing
138
- - Meaning of a C64 address or register → c64-memory-map
135
+ - To explain code without a run, analyze the program statically.
136
+ - Record a durable conclusion in the project knowledge.
137
+ - To compare runs or to assert values in a run, write a test run file.
138
+ - To find the meaning of a C64 address or register, read the memory map of the C64.
package/src/errors.ts CHANGED
@@ -21,17 +21,37 @@ export const ERROR_CODES = [
21
21
  ] as const;
22
22
  export type ErrorCode = (typeof ERROR_CODES)[number];
23
23
 
24
- /** A refused operation: a stable code and a message that tells what is wrong and what to do. */
24
+ /**
25
+ * A refused operation: a stable code and a message that tells what is wrong
26
+ * and what to do. The optional hint holds the "what to do" apart; without it,
27
+ * a script splits the message after its first sentence (splitMessage).
28
+ */
25
29
  export class Refusal extends Error {
26
30
  override name = "Refusal";
27
31
  readonly code: ErrorCode;
32
+ readonly hint?: string;
28
33
 
29
- constructor(code: ErrorCode, message: string) {
34
+ constructor(code: ErrorCode, message: string, options: { hint?: string } = {}) {
30
35
  super(message);
31
36
  this.code = code;
37
+ if (options.hint !== undefined) this.hint = options.hint;
32
38
  }
33
39
  }
34
40
 
41
+ /**
42
+ * Splits a message into what is wrong (the first sentence) and what to do (the
43
+ * rest). A sentence ends at ". " before a capital letter, a backtick, a $, a
44
+ * quote or --. With a given hint, the whole message is the error.
45
+ */
46
+ export function splitMessage(message: string, hint?: string): { error: string; hint?: string } {
47
+ const flat = message.trim();
48
+ if (hint !== undefined) return { error: flat, hint };
49
+ const cut = /\.\s+(?=[A-Z`$"'(]|--)/.exec(flat);
50
+ const error = cut === null ? flat : flat.slice(0, cut.index + 1);
51
+ const rest = cut === null ? "" : flat.slice(cut.index + cut[0].length).trim();
52
+ return rest === "" ? { error } : { error, hint: rest };
53
+ }
54
+
35
55
  /** True for an Error with a code from ERROR_CODES: a refusal, whatever its class. */
36
56
  export function isRefusal(error: unknown): error is Error & { code: ErrorCode } {
37
57
  const code = (error as { code?: unknown } | undefined)?.code;
@@ -1828,7 +1828,7 @@ async function setPoint(
1828
1828
  */
1829
1829
  function checkDirectoryEntry(entries: DiskFile[], index: number): void {
1830
1830
  const entry = entries[index - 1];
1831
- if (entry === undefined) throw new WireFailure("invalid-input", `The disk has ${entries.length} directory entries, so index ${index - 1} selects no entry. The c64-disk directory list gives the index of each entry.`);
1831
+ if (entry === undefined) throw new WireFailure("invalid-input", `The disk has ${entries.length} directory entries, so index ${index - 1} selects no entry. List the directory of the disk to get the index of each entry.`);
1832
1832
  if (entry.type === "del") throw new WireFailure("invalid-input", `Directory entry ${index - 1} (${entry.name}) is a DEL entry and holds no program. Give the index of a PRG entry.`);
1833
1833
  }
1834
1834
 
@@ -36,7 +36,7 @@ const isByte = (value: unknown): value is number => Number.isInteger(value) && (
36
36
  /** The entry state of a value. `where` names it in a refusal, for example a file or "the entry state of the knowledge". */
37
37
  export function parseEntryState(value: unknown, where: string): EntryState {
38
38
  const fail = (what: string): never => {
39
- throw new Refusal("invalid-input", `${where} is not an entry state of a c64-unpacker capture: ${what}. Capture the program again with c64-unpacker capture or loads.`);
39
+ throw new Refusal("invalid-input", `${where} is not an entry state of a program capture: ${what}. Capture the program again at its entry point.`);
40
40
  };
41
41
  if (!isObject(value)) return fail("it is not a JSON object");
42
42
  const registers = isObject(value.registers) ? value.registers : fail("it has no registers");
@@ -34,7 +34,7 @@ const MEDIA_KINDS: Record<string, string> = {
34
34
  };
35
35
 
36
36
  /** The remedy for a disk, tape or cartridge file where a PRG must be: get the PRG out of it. */
37
- export const MEDIA_REMEDY = "Get the PRG out of it with disk.ts read (or disk.ts crt for a cartridge) of the c64-disk skill";
37
+ export const MEDIA_REMEDY = "Get the PRG out of it, and give the path of that PRG";
38
38
 
39
39
  /**
40
40
  * Refuses a file that is no PRG by its extension (`type`, lowercase, without
@@ -75,12 +75,12 @@ export function readPrg(path: string, remedy = MEDIA_REMEDY, accepted = "a PRG")
75
75
  /** Reads an image.json or a PRG, relative to the project folder. Refuses every other file as readPrg does. */
76
76
  export function readImage(path: string): Image {
77
77
  if (!path.endsWith(".json")) {
78
- const range = readPrg(path, MEDIA_REMEDY, "an image.json of the c64-unpacker skill or a PRG");
78
+ const range = readPrg(path, MEDIA_REMEDY, "an image.json of an unpacked program or a PRG");
79
79
  return { segments: [{ start: range.start, end: range.end }], byteAt: (address) => range.body[address - range.start]! };
80
80
  }
81
81
  const { bytes } = readProjectFile(path);
82
82
  const fail = (what: string): never => {
83
- throw new Refusal("invalid-input", `${path} is not an image.json of the c64-unpacker skill: ${what}`);
83
+ throw new Refusal("invalid-input", `${path} is not an image.json of an unpacked program: ${what}`);
84
84
  };
85
85
  const isObject = (value: unknown): value is Record<string, unknown> => typeof value === "object" && value !== null && !Array.isArray(value);
86
86
  let parsed: unknown;
@@ -229,7 +229,7 @@ function checkTarget(value: unknown, where: string, fail: (message: string) => n
229
229
  }
230
230
 
231
231
  /** What a step of a script without the replay core gets for press: the scripts that read these steps run without a window. */
232
- const PRESS_REMEDY = "press pushes keys of the keyboard matrix, and only the replay core of c64-testing has them. Use type for the KERNAL keyboard queue, or put the press step in a record file and play it with testing.ts record of c64-testing";
232
+ const PRESS_REMEDY = "press pushes keys of the keyboard matrix, and only the replay of a record file has them. Use type for the KERNAL keyboard queue, or put the press step in a record file and play the record file";
233
233
 
234
234
  /** Checks the input of one step kind and returns it with the defaults of its MCP tool. */
235
235
  function checkInput(kind: ActionStepKind, value: unknown, at: string, fail: (message: string) => never): ActionStep {
@@ -119,7 +119,7 @@ function value(node: Node, resolve: (name: string) => number | undefined): numbe
119
119
  return node.value;
120
120
  case "name": {
121
121
  const found = resolve(node.name);
122
- if (found === undefined) throw new Refusal("invalid-input", `${node.name} is not a symbol of the knowledge or a platform name. Give a number, a symbol that knowledge.ts symbols lists, or a platform name that memory-map.ts at gives.`);
122
+ if (found === undefined) throw new Refusal("invalid-input", `${node.name} is not a symbol of the knowledge or a platform name. Give a number, a symbol of the project knowledge, or a platform name of the C64 memory map.`);
123
123
  return found;
124
124
  }
125
125
  case "unary": {
@@ -19,9 +19,8 @@ export function addressOfName(db: DatabaseSync | undefined, name: string, space:
19
19
  const addresses = [...new Set(rows.map((row) => row.address))];
20
20
  if (addresses.length === 1) return addresses[0]!;
21
21
  const where = space === DEFAULT_SPACE ? "" : ` in ${space}`;
22
- if (addresses.length > 1) throw new Refusal("invalid-input", `the analyzers give ${name} to ${rows.map((row) => `${formatC64Address(row.address)} (${row.origin})`).join(" and ")}${where}. Give the address`);
23
- const option = space === DEFAULT_SPACE ? "" : ` --space ${space}`;
24
- throw new Refusal("not-found", `${name} is not a name in the knowledge${where}. Give a $ address, or a name that knowledge.ts symbols${option} lists, with or without --analyzer.`);
22
+ if (addresses.length > 1) throw new Refusal("invalid-input", `the analyzers give ${name} to ${rows.map((row) => `${formatC64Address(row.address)} (${row.origin})`).join(" and ")}${where}. Give the address.`);
23
+ throw new Refusal("not-found", `${name} is not a name in the knowledge${where}. Give a $ address, or a symbol or an analyzer name of the project knowledge${where}.`);
25
24
  }
26
25
 
27
26
  /** Every name of a space with its address: the symbols, and each analyzer name that addressOfName accepts. With kinds, only names of those kinds. */
@@ -38,7 +38,7 @@ export interface ProgramImage {
38
38
  /** The byte at an address inside a segment. */
39
39
  byteAt: (address: number) => number;
40
40
  entry?: number;
41
- /** The machine state at the entry: the content of the entry_state.json of the c64-unpacker skill. */
41
+ /** The machine state at the entry: the content of the entry_state.json of a capture. */
42
42
  state?: Record<string, unknown>;
43
43
  /** The stages of the unpacker capture, in order: the last one is the program. */
44
44
  stages?: Array<Record<string, unknown>>;
@@ -220,8 +220,7 @@ export function requireProgram(db: DatabaseSync | undefined, space: Space = DEFA
220
220
  const image = programImage(db, space);
221
221
  if (image !== undefined) return image;
222
222
  const where = space === DEFAULT_SPACE ? "" : ` in ${space}`;
223
- const option = space === DEFAULT_SPACE ? "" : ` --space ${space}`;
224
- throw new Refusal("not-found", `The knowledge has no program${where}. Put it in with knowledge.ts image <image.json|prg>${option} of the c64-knowledge skill.`);
223
+ throw new Refusal("not-found", `The knowledge has no program${where}. Put the program into the project knowledge${where}: a PRG, or the image.json of a capture.`);
225
224
  }
226
225
 
227
226
  /** The pages of an entry state: $0000-$03ff as the capture wrote them, 256 bytes as hex for each page. */
@@ -177,7 +177,7 @@ export class Change {
177
177
  if (found.length > 0) {
178
178
  throw new Refusal(
179
179
  "conflict",
180
- `The knowledge has ${found.length} conflict${found.length === 1 ? "" : "s"} from a git merge, for example ${describe(found[0]!)}. Nothing was written. Run knowledge.ts merge to decide them, then write again.`,
180
+ `The knowledge has ${found.length} conflict${found.length === 1 ? "" : "s"} from a git merge, for example ${describe(found[0]!)}. Nothing was written. Decide the conflicts of the git merge in the project knowledge. Then write again.`,
181
181
  );
182
182
  }
183
183
  const current = currentRevision(db);
@@ -735,7 +735,7 @@ function checkModule(request: ModuleRequest): void {
735
735
  checkAddress(request.start, "start");
736
736
  if (!MODULE_FILE.test(request.file)) throw new Refusal("invalid-input", "A module file is a name of letters, digits, underscores or hyphens (at most 60) that ends in .asm, without a directory.");
737
737
  if (isGeneratedFile(request.file)) {
738
- throw new Refusal("invalid-input", `c64-source writes ${GENERATED_FILES.join(", ")} itself, in any letter case, so a module cannot have the file ${request.file}. Give the module another file.`);
738
+ throw new Refusal("invalid-input", `A module cannot have the file ${request.file}, because the generated source writes ${GENERATED_FILES.join(", ")} itself, in any letter case. Give the module another file.`);
739
739
  }
740
740
  if (request.title !== undefined && (request.title.trim().length === 0 || request.title.length > MAX_COMMENT)) throw new Refusal("invalid-input", `A module title has 1 to ${MAX_COMMENT} characters.`);
741
741
  }
package/src/mcp/inputs.ts CHANGED
@@ -28,7 +28,7 @@ export const MemoryViewInput = z
28
28
  export const AddressInput = z
29
29
  .string()
30
30
  .refine((value) => c64AddressOf(value) !== undefined, {
31
- message: "must be $ and 1 to 4 hex digits, for example $c000 or $fb. A tool takes no names: get the address of a name with knowledge.ts at <name> of the c64-knowledge skill",
31
+ message: "must be $ and 1 to 4 hex digits, for example $c000 or $fb. A tool takes no names: get the address of the name from the project knowledge",
32
32
  })
33
33
  .transform((value) => c64AddressOf(value)!)
34
34
  .describe("C64 address: $ and 1 to 4 hex digits, $0000 to $ffff");
@@ -14,7 +14,7 @@ export const c64Keyboard = defineTool({
14
14
  description:
15
15
  `Type up to ${MAX_KEYBOARD_BYTES} keys into the C64 keyboard queue. The C64 reads them while it runs. ` +
16
16
  "Only a program that reads keys through the KERNAL sees them. A program that reads the keyboard hardware directly does not see them. Many games do that. " +
17
- "No tool presses one key of the keyboard matrix. For one specific key, ask the user to press it in the window, or give a press step in a record file of c64-testing. " +
17
+ "No tool presses one key of the keyboard matrix. For one specific key, ask the user to press it in the window, or play a record file with a press step. " +
18
18
  'Mode text types text, for example "RUN\\n". Letters of either case type the normal (unshifted) key. A line break types RETURN. ' +
19
19
  "Mode petscii types PETSCII codes 1 to 255 in bytes, for example [147] to clear the screen. " +
20
20
  "While c64_autostart loads a program, this tool refuses keys: see c64_autostart. " +
@@ -27,7 +27,7 @@ export const c64Autostart = defineTool({
27
27
  "The C64 resets and loads the file. With run true (the default), it also runs the file. A disk image stays in drive 8. " +
28
28
  "A cartridge stays in the C64 through every reset, as on a real C64. An autostart of a file that is not a cartridge detaches it first. " +
29
29
  "Both joysticks are centred first: joystick port 1 uses the keyboard lines, and a held direction changes the RUN that the autostart types. " +
30
- "Without index, a disk image loads like LOAD\"*\",8,1. index selects one directory entry by its number in the c64-disk directory list (0 is the first entry). " +
30
+ "Without index, a disk image loads like LOAD\"*\",8,1. index selects one directory entry by its number in the directory list of the disk (0 is the first entry). " +
31
31
  "The tool refuses an index of a DEL entry, or an index after the last entry. " +
32
32
  "The machine runs when this tool returns, and the load continues. The emulator keeps warp mode on until it types RUN. " +
33
33
  "A key in that time stops the autostart, so c64_keyboard refuses keys until then. Run frames with c64_execution advance-frames until c64_status gives warp false. " +
@@ -75,13 +75,13 @@ export async function pack(params: PackParams, context: ToolContext): Promise<Pa
75
75
  const output = workspace.directory("out");
76
76
  const packedPath = join(output, PACKED);
77
77
  const packing = await runToolOrFail("Exomizer", "The pack", { argv: sfxArguments(executable, params, inputs, packedPath), cwd: workspace.root, timeoutMs: TIMEOUT_MS }, context);
78
- if (packing.code !== 0) throw new WireFailure("operation-failed", `Exomizer could not pack the program (exit ${packing.code}).${outputTail("Exomizer", packing, workspace.root, PROBLEM)}`);
78
+ if (packing.code !== 0) throw new WireFailure("operation-failed", `Exomizer could not pack the program (exit ${packing.code}).${outputTail("Exomizer", packing, workspace.root, PROBLEM)} Correct the call as this output tells, or give this message to the user.`);
79
79
  if (!existsSync(packedPath)) throw new WireFailure("operation-failed", "Exomizer reported success but wrote no program.");
80
80
  const unpackedPath = join(output, UNPACKED);
81
81
  const unpacking = await runToolOrFail("Exomizer", "The unpack check", { argv: [executable, "desfx", "-o", unpackedPath, packedPath], cwd: workspace.root, timeoutMs: TIMEOUT_MS }, context);
82
82
  const found = parseDesfx(`${unpacking.stdout}\n${unpacking.stderr}`);
83
83
  if (unpacking.code !== 0 || found === undefined || !existsSync(unpackedPath)) {
84
- throw new WireFailure("operation-failed", `Exomizer could not unpack the packed program in its emulator (exit ${unpacking.code}).${outputTail("Exomizer", unpacking, workspace.root)}`);
84
+ throw new WireFailure("operation-failed", `Exomizer could not unpack the packed program in its emulator (exit ${unpacking.code}).${outputTail("Exomizer", unpacking, workspace.root)} Give this message to the user.`);
85
85
  }
86
86
  return { program: readFileSync(packedPath), unpacked: readFileSync(unpackedPath), ...found };
87
87
  } finally {
package/src/project.ts CHANGED
@@ -279,9 +279,9 @@ export function checkOutputPath(path: string, kind: OutputKind, options: { root?
279
279
  const prefix = `${what === undefined ? "" : `${what}: `}${path}`;
280
280
  // The index is one file in the folder for local files: another name in that folder is good.
281
281
  if (!part.endsWith("/")) {
282
- throw new Refusal("invalid-input", `${prefix} is the index of the knowledge${path === part ? "" : ` (${part})`}. Only the c64-knowledge skill writes it: a write there destroys the index. Give another file name, for example ${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/<other name>.`);
282
+ throw new Refusal("invalid-input", `${prefix} is the index of the knowledge${path === part ? "" : ` (${part})`}. Only the commands that change the project knowledge write it: a write there destroys the index. Give another file name, for example ${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/<other name>.`);
283
283
  }
284
- throw new Refusal("invalid-input", `${prefix} is in ${part}, the knowledge of the project. Only the c64-knowledge skill writes it: a write there destroys the knowledge. Give a path outside ${part}, for example ${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/<${kind === "folder" ? "folder" : "file"}>.`);
284
+ throw new Refusal("invalid-input", `${prefix} 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 path outside ${part}, for example ${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/<${kind === "folder" ? "folder" : "file"}>.`);
285
285
  };
286
286
  let target: string;
287
287
  try {