@henols/c64-re-tools 2.1.2 → 2.1.4
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.
- package/package.json +1 -1
- package/skills/c64-assembler/SKILL.md +1 -1
- package/skills/c64-assembler/scripts/assembler.ts +2 -2
- package/skills/c64-disk/scripts/lib/containers.ts +2 -1
- package/skills/c64-docs/SKILL.md +1 -1
- package/skills/c64-docs/scripts/docs.ts +5 -3
- package/skills/c64-emulator/SKILL.md +4 -0
- package/skills/c64-knowledge/SKILL.md +7 -2
- package/skills/c64-knowledge/scripts/knowledge.ts +6 -12
- package/skills/c64-knowledge/scripts/lib/listing.ts +8 -1
- package/skills/c64-memory-map/SKILL.md +3 -1
- package/skills/c64-memory-map/scripts/memory-map.ts +26 -5
- package/skills/c64-provenance/SKILL.md +5 -4
- package/skills/c64-provenance/scripts/lib/compare.ts +12 -0
- package/skills/c64-provenance/scripts/lib/library.ts +33 -5
- package/skills/c64-provenance/scripts/lib/separate.ts +34 -6
- package/skills/c64-provenance/scripts/provenance.ts +26 -11
- package/skills/c64-source/SKILL.md +3 -2
- package/skills/c64-source/scripts/lib/source.ts +18 -4
- package/skills/c64-source/scripts/source.ts +40 -28
- package/skills/c64-static-analysis/SKILL.md +4 -3
- package/skills/c64-static-analysis/scripts/lib/findings.ts +47 -10
- package/skills/c64-static-analysis/scripts/lib/pointers.ts +38 -25
- package/skills/c64-static-analysis/scripts/static-analysis.ts +17 -14
- package/skills/c64-testing/SKILL.md +6 -3
- package/skills/c64-testing/references/scenario-format.md +7 -3
- package/skills/c64-testing/scripts/lib/diff-files.ts +27 -8
- package/skills/c64-testing/scripts/lib/runs.ts +24 -8
- package/skills/c64-testing/scripts/lib/scenario.ts +133 -83
- package/skills/c64-testing/scripts/testing.ts +6 -3
- package/skills/c64-unpacker/SKILL.md +5 -4
- package/skills/c64-unpacker/scripts/lib/loads.ts +9 -3
- package/skills/c64-unpacker/scripts/lib/machine.ts +31 -0
- package/skills/c64-unpacker/scripts/unpacker.ts +4 -1
- package/src/host/vice/session.ts +118 -11
- package/src/host-client/image.ts +22 -8
- package/src/host-client/steps.ts +2 -2
- package/src/host-client/tools.ts +4 -3
- package/src/host-client/transfer.ts +8 -3
- package/src/host-client/vice-session.ts +3 -3
- package/src/knowledge/write.ts +110 -29
- package/src/mcp/output.ts +1 -1
- package/src/mcp/server.ts +7 -0
- package/src/mcp/tools/debug.ts +2 -1
- package/src/mcp/tools/media.ts +8 -5
- package/src/media.ts +18 -0
- package/src/opcodes.ts +31 -1
- package/src/platform.ts +14 -1
- package/src/project.ts +14 -3
- package/src/script.ts +71 -2
package/src/script.ts
CHANGED
|
@@ -65,6 +65,12 @@ export interface OptionSpec {
|
|
|
65
65
|
* --out and --out-<name> has it.
|
|
66
66
|
*/
|
|
67
67
|
output?: OutputKind;
|
|
68
|
+
/**
|
|
69
|
+
* An option whose value has a form: an example of that form for a value
|
|
70
|
+
* that is missing or starts with -, made from that value when it fits.
|
|
71
|
+
* The message then gives the form, not --<name>=<value>.
|
|
72
|
+
*/
|
|
73
|
+
example?: (given: string | undefined) => string;
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
/** The options that have one meaning in every script. A command can change the help, the value and whether it is required, never the kind. */
|
|
@@ -428,6 +434,67 @@ function refuseSplitRange(command: CommandSpec, options: Readonly<Record<string,
|
|
|
428
434
|
}
|
|
429
435
|
}
|
|
430
436
|
|
|
437
|
+
/** The options of a command for a message: --a, --b and --c, or a word that it has none. */
|
|
438
|
+
function optionList(options: Readonly<Record<string, OptionSpec>>): string {
|
|
439
|
+
const names = Object.keys(options).map((name) => `--${name}`);
|
|
440
|
+
if (names.length === 0) return "It takes no options";
|
|
441
|
+
return `Its options are ${names.length === 1 ? names[0] : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`}`;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/** True for a word that the command line reads as an option: - and one or more characters. A lone - is a subject (standard input). */
|
|
445
|
+
const isOptionWord = (word: string) => word.length > 1 && word.startsWith("-");
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Refuses the words of a command line that parseArgs refuses, with a message
|
|
449
|
+
* that names the option and tells what to give: an option that the command
|
|
450
|
+
* does not have, a flag with a value, an option without its value, a value
|
|
451
|
+
* that starts with -, and a range option in two parts.
|
|
452
|
+
*/
|
|
453
|
+
function refuseOptionWords(command: CommandSpec, options: Readonly<Record<string, OptionSpec>>, argv: readonly string[]): void {
|
|
454
|
+
const end = argv.indexOf("--");
|
|
455
|
+
const words = end < 0 ? argv : argv.slice(0, end);
|
|
456
|
+
for (let index = 0; index < words.length; index++) {
|
|
457
|
+
const word = words[index]!;
|
|
458
|
+
if (!isOptionWord(word)) continue;
|
|
459
|
+
if (!word.startsWith("--")) {
|
|
460
|
+
throw new UsageError(`${word} is not an option of ${command.name}: an option starts with --. ${optionList(options)}. Give a subject that starts with - after --, for example -- ${word}`);
|
|
461
|
+
}
|
|
462
|
+
const equals = word.indexOf("=");
|
|
463
|
+
const name = equals < 0 ? word.slice(2) : word.slice(2, equals);
|
|
464
|
+
const spec = options[name];
|
|
465
|
+
if (spec === undefined) throw new UsageError(`${command.name} has no option --${name}. ${optionList(options)}`);
|
|
466
|
+
if (spec.kind === "flag") {
|
|
467
|
+
if (equals >= 0) throw new UsageError(`--${name} is a flag: give --${name} without a value`);
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
let value: string;
|
|
471
|
+
let valueIndex = index;
|
|
472
|
+
if (equals >= 0) {
|
|
473
|
+
value = word.slice(equals + 1);
|
|
474
|
+
} else {
|
|
475
|
+
valueIndex = index + 1;
|
|
476
|
+
const next = words[valueIndex];
|
|
477
|
+
const form = (given: string | undefined) => (spec.example === undefined ? "" : `, for example --${name} ${spec.example(given)}`);
|
|
478
|
+
if (next === undefined) throw new UsageError(`--${name} needs a value: give --${name} ${spec.value ?? "<value>"}${form(undefined)}`);
|
|
479
|
+
if (isOptionWord(next)) {
|
|
480
|
+
if (spec.example !== undefined) throw new UsageError(`--${name} needs a value of the form ${spec.value ?? "<value>"}: give --${name} ${spec.value ?? "<value>"}${form(next)}, not ${next}`);
|
|
481
|
+
if ((spec.kind === "count" || spec.kind === "number") && /^-\d/.test(next)) {
|
|
482
|
+
const range = spec.kind === "count" ? `a whole number from ${spec.min ?? 0} to ${spec.max ?? Number.MAX_SAFE_INTEGER}` : `a number from ${spec.min ?? 0} to ${spec.max ?? 0xffff}`;
|
|
483
|
+
throw new UsageError(`--${name} must be ${range}, not ${JSON.stringify(next)}`);
|
|
484
|
+
}
|
|
485
|
+
throw new UsageError(`--${name} needs a value: give --${name} ${spec.value ?? "<value>"}, not ${next}. Give a value that starts with - as --${name}=${next}`);
|
|
486
|
+
}
|
|
487
|
+
value = next;
|
|
488
|
+
index++;
|
|
489
|
+
}
|
|
490
|
+
// A range option in two parts: --range '$1bc2' '$1c00'.
|
|
491
|
+
const second = words[valueIndex + 1];
|
|
492
|
+
if (spec.kind === "range" && rangeParts(value) === undefined && isAddressText(value) && second !== undefined && c64AddressOf(second) !== undefined) {
|
|
493
|
+
throw new UsageError(`--${name} is one token <start>-<end>: give --${name} '${value}-${second}', not '${value}' '${second}'`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
431
498
|
/**
|
|
432
499
|
* Refuses an output path before the command does any work: a path that
|
|
433
500
|
* leaves the project, a path in the knowledge, a folder where a file must be,
|
|
@@ -442,6 +509,7 @@ function checkOutput(text: string, what: string, kind: OutputKind): void {
|
|
|
442
509
|
export function parseCall(script: ScriptSpec, command: CommandSpec, argv: readonly string[]): Call {
|
|
443
510
|
const options = commandOptions(command);
|
|
444
511
|
refuseSplitRange(command, options, argv);
|
|
512
|
+
refuseOptionWords(command, options, argv);
|
|
445
513
|
let parsed: ReturnType<typeof parseArgs>;
|
|
446
514
|
try {
|
|
447
515
|
parsed = parseArgs({
|
|
@@ -450,8 +518,9 @@ export function parseCall(script: ScriptSpec, command: CommandSpec, argv: readon
|
|
|
450
518
|
allowPositionals: true,
|
|
451
519
|
options: Object.fromEntries(Object.entries(options).map(([name, spec]) => [name, { type: spec.kind === "flag" ? "boolean" : "string", ...(spec.multiple ? { multiple: true } : {}) }])),
|
|
452
520
|
});
|
|
453
|
-
} catch
|
|
454
|
-
|
|
521
|
+
} catch {
|
|
522
|
+
// refuseOptionWords gives a message of its own for each word that parseArgs refuses; this is the last guard.
|
|
523
|
+
throw new UsageError(`the command line of ${command.name} is not correct. Give each option as --name <value>, each flag as --name, and a subject that starts with - after --`);
|
|
455
524
|
}
|
|
456
525
|
const values = parsed.values as Record<string, string | boolean | string[] | undefined>;
|
|
457
526
|
const subjects = parsed.positionals;
|