@henols/c64-re-tools 2.8.0-rc.1 → 2.8.0-rc.3

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 (120) hide show
  1. package/package.json +1 -1
  2. package/skills/c64-assembler/SKILL.md +7 -4
  3. package/skills/c64-assembler/scripts/assembler.ts +73 -44
  4. package/skills/c64-disk/scripts/disk.ts +3 -3
  5. package/skills/c64-disk/scripts/lib/containers.ts +2 -2
  6. package/skills/c64-docs/SKILL.md +1 -1
  7. package/skills/c64-docs/scripts/docs.ts +12 -20
  8. package/skills/c64-docs/scripts/lib/links.ts +1 -1
  9. package/skills/c64-docs/scripts/lib/markdown.ts +1 -1
  10. package/skills/c64-docs/scripts/lib/reference.ts +59 -13
  11. package/skills/c64-knowledge/SKILL.md +17 -8
  12. package/skills/c64-knowledge/scripts/knowledge.ts +200 -218
  13. package/skills/c64-knowledge/scripts/lib/check.ts +2 -3
  14. package/skills/c64-knowledge/scripts/lib/listing.ts +62 -31
  15. package/skills/c64-packer/scripts/packer.ts +3 -3
  16. package/skills/c64-provenance/SKILL.md +28 -18
  17. package/skills/c64-provenance/scripts/lib/compare.ts +31 -21
  18. package/skills/c64-provenance/scripts/lib/leftovers.ts +17 -35
  19. package/skills/c64-provenance/scripts/lib/library.ts +10 -10
  20. package/skills/c64-provenance/scripts/lib/runtime.ts +3 -14
  21. package/skills/c64-provenance/scripts/provenance.ts +144 -113
  22. package/skills/c64-source/SKILL.md +6 -1
  23. package/skills/c64-source/references/loader.md +2 -1
  24. package/skills/c64-source/scripts/lib/export.ts +54 -301
  25. package/skills/c64-source/scripts/lib/loader.ts +31 -51
  26. package/skills/c64-source/scripts/lib/source.ts +53 -45
  27. package/skills/c64-source/scripts/lib/stage.ts +9 -25
  28. package/skills/c64-source/scripts/source.ts +134 -294
  29. package/skills/c64-static-analysis/SKILL.md +13 -7
  30. package/skills/c64-static-analysis/scripts/lib/coverage.ts +1 -3
  31. package/skills/c64-static-analysis/scripts/lib/findings.ts +16 -3
  32. package/skills/c64-static-analysis/scripts/lib/idioms.ts +98 -19
  33. package/skills/c64-static-analysis/scripts/lib/triage.ts +112 -0
  34. package/skills/c64-static-analysis/scripts/static-analysis.ts +249 -147
  35. package/skills/c64-testing/SKILL.md +13 -7
  36. package/skills/c64-testing/scripts/lib/diff-files.ts +6 -13
  37. package/skills/c64-testing/scripts/lib/recording.ts +47 -66
  38. package/skills/c64-testing/scripts/lib/replay.ts +53 -9
  39. package/skills/c64-testing/scripts/lib/runs.ts +11 -29
  40. package/skills/c64-testing/scripts/lib/scenario.ts +30 -31
  41. package/skills/c64-testing/scripts/lib/start-screen.ts +42 -5
  42. package/skills/c64-testing/scripts/testing.ts +32 -7
  43. package/skills/c64-unpacker/SKILL.md +9 -7
  44. package/skills/c64-unpacker/scripts/lib/evidence.ts +23 -38
  45. package/skills/c64-unpacker/scripts/lib/loads.ts +24 -39
  46. package/skills/c64-unpacker/scripts/lib/machine.ts +38 -18
  47. package/skills/c64-unpacker/scripts/lib/stages.ts +124 -40
  48. package/skills/c64-unpacker/scripts/unpacker.ts +81 -68
  49. package/skills/emulator/SKILL.md +1 -0
  50. package/src/c64.ts +133 -10
  51. package/src/cli/ap-sdk.ts +1 -1
  52. package/src/cli/cleanup.ts +4 -2
  53. package/src/compare.ts +36 -16
  54. package/src/errors.ts +10 -1
  55. package/src/host/main.ts +2 -1
  56. package/src/host/server.ts +7 -11
  57. package/src/host/tools/c1541.ts +9 -3
  58. package/src/host/vice/adapter.ts +20 -43
  59. package/src/host/vice/binary-monitor.ts +22 -21
  60. package/src/host/vice/process.ts +31 -40
  61. package/src/host/vice/session.ts +187 -247
  62. package/src/host/vice/text-monitor.ts +3 -3
  63. package/src/host-client/autostart.ts +1 -1
  64. package/src/host-client/connect.ts +2 -1
  65. package/src/host-client/coverage.ts +0 -3
  66. package/src/host-client/entry-state.ts +4 -11
  67. package/src/host-client/image.ts +6 -11
  68. package/src/host-client/steps.ts +13 -113
  69. package/src/host-client/tools.ts +4 -4
  70. package/src/host-client/transfer.ts +10 -0
  71. package/src/host-client/vice-session.ts +10 -6
  72. package/src/knowledge/code-reach.ts +364 -0
  73. package/src/knowledge/conflicts.ts +34 -72
  74. package/src/knowledge/database.ts +40 -28
  75. package/src/knowledge/evidence.ts +2 -2
  76. package/src/knowledge/graph.ts +3 -3
  77. package/src/knowledge/history.ts +50 -90
  78. package/src/knowledge/import.ts +28 -68
  79. package/src/knowledge/join.ts +1 -1
  80. package/src/knowledge/names.ts +12 -7
  81. package/src/knowledge/program.ts +59 -72
  82. package/src/knowledge/read.ts +104 -100
  83. package/src/knowledge/schema.ts +9 -3
  84. package/src/knowledge/separate.ts +175 -80
  85. package/src/knowledge/start-screen.ts +7 -5
  86. package/src/knowledge/text.ts +56 -33
  87. package/src/knowledge/write.ts +274 -515
  88. package/src/loader.ts +7 -25
  89. package/src/mcp/inputs.ts +3 -3
  90. package/src/mcp/server.ts +19 -38
  91. package/src/mcp/session-source.ts +2 -1
  92. package/src/mcp/tools/debug.ts +97 -24
  93. package/src/mcp/tools/execution.ts +1 -1
  94. package/src/mcp/tools/input.ts +3 -3
  95. package/src/mcp/tools/machine.ts +3 -3
  96. package/src/mcp/tools/media.ts +4 -4
  97. package/src/mcp/tools/memory.ts +13 -17
  98. package/src/mcp/tools/video.ts +11 -25
  99. package/src/native/acme.ts +3 -3
  100. package/src/native/c64run.ts +2 -1
  101. package/src/native/decompiler/analyze.ts +11 -8
  102. package/src/native/decompiler/walk.ts +3 -4
  103. package/src/native/decompiler/wasm.ts +2 -2
  104. package/src/native/discover.ts +1 -1
  105. package/src/native/dxa.ts +9 -11
  106. package/src/native/exomizer.ts +1 -1
  107. package/src/native/processes.ts +4 -1
  108. package/src/native/run.ts +3 -3
  109. package/src/native/types.ts +9 -8
  110. package/src/opcodes.ts +3 -0
  111. package/src/platform.ts +9 -10
  112. package/src/program-code.ts +151 -0
  113. package/src/project.ts +8 -5
  114. package/src/protocol/framing.ts +51 -18
  115. package/src/protocol/messages.ts +1 -11
  116. package/src/protocol/tools.ts +0 -3
  117. package/src/protocol/vice.ts +588 -773
  118. package/src/script.ts +25 -23
  119. package/src/time.ts +1 -1
  120. package/src/trace.ts +3 -2
package/src/script.ts CHANGED
@@ -21,10 +21,10 @@
21
21
  import { resolve } from "node:path";
22
22
  import { parseArgs } from "node:util";
23
23
 
24
- import { c64AddressOf, formatC64Address, SPACE_PATTERN, SYMBOL_NAME, type AddressRange } from "./c64.ts";
25
- import { isRefusal, Refusal, splitMessage, type ErrorCode } from "./errors.ts";
24
+ import { c64AddressOf, formatC64Address, isAddressText, SPACE_PATTERN, SYMBOL_NAME, type AddressRange } from "./c64.ts";
25
+ import { describeError, isRefusal, Refusal, splitMessage, type ErrorCode } from "./errors.ts";
26
26
  import { checkOutputPath, projectRoot, resolveProjectPath, resolveReadPath, useProject, type OutputKind } from "./project.ts";
27
- import { STOP_AND_ASK } from "./protocol/messages.ts";
27
+ import { isObject, STOP_AND_ASK } from "./protocol/messages.ts";
28
28
  import { elapsedMs, startTrace, trace, type TraceFields } from "./trace.ts";
29
29
 
30
30
  /** A wrong command line: an invalid-input refusal that also shows the usage of the command. */
@@ -175,7 +175,7 @@ export interface ScriptSpec {
175
175
  const NUMBER_PATTERNS = [/^\$([0-9a-fA-F]{1,8})$/, /^%([01]{1,32})$/, /^(\d{1,10})$/];
176
176
 
177
177
  /** A value as $ and hex digits, % and binary digits, or decimal digits; undefined for other text. */
178
- export function numberOf(text: string): number | undefined {
178
+ function numberOf(text: string): number | undefined {
179
179
  const [hex, binary, decimal] = NUMBER_PATTERNS.map((pattern) => pattern.exec(text)?.[1]);
180
180
  if (hex !== undefined) return Number.parseInt(hex, 16);
181
181
  if (binary !== undefined) return Number.parseInt(binary, 2);
@@ -183,11 +183,6 @@ export function numberOf(text: string): number | undefined {
183
183
  return undefined;
184
184
  }
185
185
 
186
- /** True when the text has the form of an address: $ and 1 to 4 hex digits, or a name. */
187
- export function isAddressText(text: string): boolean {
188
- return c64AddressOf(text) !== undefined || SYMBOL_NAME.test(text);
189
- }
190
-
191
186
  /** Splits <start>-<end>. A name has no hyphen, so the first hyphen is the split. */
192
187
  function rangeParts(text: string): [string, string] | undefined {
193
188
  const parts = text.split("-");
@@ -366,7 +361,7 @@ function synopsis(script: string, command: CommandSpec): string {
366
361
  }
367
362
 
368
363
  /** The help body of one command: its synopsis, subjects and options. */
369
- export function commandHelp(script: ScriptSpec, command: CommandSpec): Record<string, unknown> {
364
+ function commandHelp(script: ScriptSpec, command: CommandSpec): Record<string, unknown> {
370
365
  return {
371
366
  command: command.name,
372
367
  synopsis: synopsis(script.name, command),
@@ -385,7 +380,7 @@ export function commandHelp(script: ScriptSpec, command: CommandSpec): Record<st
385
380
  }
386
381
 
387
382
  /** The help body of a script: its commands. */
388
- export function scriptHelp(script: ScriptSpec): Record<string, unknown> {
383
+ function scriptHelp(script: ScriptSpec): Record<string, unknown> {
389
384
  return {
390
385
  script: `${script.name}.ts`,
391
386
  summary: script.summary,
@@ -475,7 +470,11 @@ export function pickFields(body: unknown, paths: readonly string[]): { body: unk
475
470
  rest: readonly string[];
476
471
  }
477
472
  const pick = (node: unknown, wanted: readonly Wanted[]): unknown => {
478
- if (Array.isArray(node)) return node.map((item) => pick(item, wanted));
473
+ if (Array.isArray(node)) {
474
+ // An empty list has no item that lacks the field.
475
+ if (node.length === 0) for (const item of wanted) found.add(item.path);
476
+ return node.map((item) => pick(item, wanted));
477
+ }
479
478
  if (typeof node !== "object" || node === null) return undefined;
480
479
  const out: Record<string, unknown> = {};
481
480
  const groups = new Map<string, Wanted[]>();
@@ -683,19 +682,22 @@ export function parseCall(script: ScriptSpec, command: CommandSpec, argv: readon
683
682
  // ---------------------------------------------------------------------------
684
683
  // Running
685
684
 
686
- /** A hint for a body with a cut list: the rest of the first list that has one. */
687
- function cutListHint(body: unknown): string | undefined {
688
- const lists = (value: unknown, depth: number): string | undefined => {
685
+ /** A hint for a body with a cut list: the rest of the first cut list that the fields show, or of the first one without --fields. */
686
+ function cutListHint(body: unknown, fields?: readonly string[]): string | undefined {
687
+ // A field shows a list when it is the list, a field in it, or a field that holds it.
688
+ const shown = (path: string) => fields === undefined || path === "" || fields.some((field) => field === path || field.startsWith(`${path}.`) || path.startsWith(`${field}.`));
689
+ const lists = (value: unknown, path: string, depth: number): string | undefined => {
689
690
  if (typeof value !== "object" || value === null || depth > 2) return undefined;
690
691
  const rest = (value as { rest?: unknown; count?: unknown }).rest;
691
- if (typeof rest === "string" && typeof (value as { count?: unknown }).count === "number") return rest;
692
- for (const item of Object.values(value)) {
693
- const found = lists(item, depth + 1);
692
+ if (typeof rest === "string" && typeof (value as { count?: unknown }).count === "number") return shown(path) ? rest : undefined;
693
+ // A path through a list names the field of each item, so an item adds no key to the path.
694
+ for (const [key, item] of Object.entries(value)) {
695
+ const found = lists(item, Array.isArray(value) ? path : path === "" ? key : `${path}.${key}`, depth + 1);
694
696
  if (found !== undefined) return found;
695
697
  }
696
698
  return undefined;
697
699
  };
698
- const rest = lists(body, 0);
700
+ const rest = lists(body, "", 0);
699
701
  return rest === undefined ? undefined : `A list in the body is cut: count gives its full size. To get the rest, give ${rest}.`;
700
702
  }
701
703
 
@@ -745,12 +747,12 @@ async function envelope(script: Envelope): Promise<void> {
745
747
  if (error instanceof UsageError) {
746
748
  const help = `To get the usage, run ${script.name}.ts${commandName === undefined ? "" : ` ${commandName}`} --help.`;
747
749
  shown = { error: shown.error, hint: shown.hint === undefined ? help : `${sentence(shown.hint)} ${help}` };
748
- nextAction = commandLine(commandName === undefined ? [] : [commandName, "--help"]);
750
+ nextAction = commandLine(commandName === undefined ? ["--help"] : [commandName, "--help"]);
749
751
  }
750
752
  } else {
751
753
  code = "operation-failed";
752
754
  const where = commandName === undefined ? `${script.name}.ts` : `${script.name}.ts ${commandName}`;
753
- const text = (error instanceof Error ? error.message : String(error)).replace(/\.$/, "");
755
+ const text = describeError(error).replace(/\.$/, "");
754
756
  shown = { error: `${where} failed inside c64-re-tools: ${text}.`, hint: "This is a fault of the toolkit, not of the call. Give this message to the user. Set C64RT_TRACE to get its details in the trace." };
755
757
  }
756
758
  const message = shown.hint === undefined ? shown.error : `${shown.error} ${shown.hint}`;
@@ -775,7 +777,7 @@ async function envelope(script: Envelope): Promise<void> {
775
777
  commandName = command;
776
778
  });
777
779
  const { body, hint, nextAction } = result instanceof Reply ? result : { body: result ?? {}, hint: undefined, nextAction: undefined };
778
- const cut = cutListHint(body);
780
+ const cut = cutListHint(body, fields);
779
781
  let shownHint = hint === undefined ? cut : cut === undefined || hint.includes("--max-listed") ? hint : `${sentence(hint)} ${cut}`;
780
782
  let shownBody: unknown = body ?? {};
781
783
  // The fields are a view of the result: the command has done its work, so a path that the body lacks is no failure.
@@ -783,7 +785,7 @@ async function envelope(script: Envelope): Promise<void> {
783
785
  const picked = pickFields(shownBody, fields);
784
786
  shownBody = picked.body;
785
787
  if (picked.missing.length > 0) {
786
- const top = typeof body === "object" && body !== null && !Array.isArray(body) ? Object.keys(body) : [];
788
+ const top = isObject(body) ? Object.keys(body) : [];
787
789
  const lacks = `The body has no ${wordList(picked.missing)}. ${top.length === 0 ? "It has no fields." : `Its fields are ${wordList(top)}.`}`;
788
790
  shownHint = shownHint === undefined ? lacks : `${sentence(shownHint)} ${lacks}`;
789
791
  }
package/src/time.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // +01:00, also in summer: no timestamp repeats when the clocks go back, and
3
3
  // the text of two timestamps sorts in time order.
4
4
 
5
- const CET_OFFSET_MS = 60 * 60 * 1000;
5
+ export const CET_OFFSET_MS = 60 * 60 * 1000;
6
6
 
7
7
  /** `time` as `2026-10-09T14:03:21.123+01:00`. */
8
8
  export function isoCet(time: Date = new Date()): string {
package/src/trace.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  import { appendFileSync, copyFileSync, mkdirSync, readFileSync } from "node:fs";
8
8
  import { join } from "node:path";
9
9
 
10
+ import { describeError } from "./errors.ts";
10
11
  import { fileStampCet, isoCet } from "./time.ts";
11
12
 
12
13
  export const TRACE_VARIABLE = "C64RT_TRACE";
@@ -161,7 +162,7 @@ export interface TraceTarget {
161
162
  }
162
163
 
163
164
  /** The target that C64RT_TRACE in `env` gives: its directory, or nothing. */
164
- export function traceTargetFromEnv(env: NodeJS.ProcessEnv = process.env): TraceTarget {
165
+ function traceTargetFromEnv(env: NodeJS.ProcessEnv = process.env): TraceTarget {
165
166
  const path = env[TRACE_VARIABLE];
166
167
  return path === undefined || path === "" ? {} : { dir: { path, given: `${TRACE_VARIABLE}=${path}` } };
167
168
  }
@@ -183,7 +184,7 @@ export function startTrace(kind: TraceKind, options: { env?: NodeJS.ProcessEnv;
183
184
  current = Trace.open(kind, dir.path, new Date(), echo);
184
185
  } catch (error) {
185
186
  current = noFile();
186
- options.warn?.(`${dir.given} cannot be used (${error instanceof Error ? error.message : String(error)}); no trace file is written.`);
187
+ options.warn?.(`${dir.given} cannot be used (${describeError(error)}); no trace file is written.`);
187
188
  }
188
189
  return current;
189
190
  }