@henols/c64-re-tools 2.8.0-rc.2 → 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 (119) hide show
  1. package/package.json +1 -1
  2. package/skills/c64-assembler/SKILL.md +5 -2
  3. package/skills/c64-assembler/scripts/assembler.ts +55 -48
  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 +56 -24
  15. package/skills/c64-packer/scripts/packer.ts +3 -3
  16. package/skills/c64-provenance/SKILL.md +25 -16
  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 +129 -98
  22. package/skills/c64-source/references/loader.md +2 -1
  23. package/skills/c64-source/scripts/lib/export.ts +54 -303
  24. package/skills/c64-source/scripts/lib/loader.ts +31 -51
  25. package/skills/c64-source/scripts/lib/source.ts +51 -41
  26. package/skills/c64-source/scripts/lib/stage.ts +9 -25
  27. package/skills/c64-source/scripts/source.ts +134 -294
  28. package/skills/c64-static-analysis/SKILL.md +10 -5
  29. package/skills/c64-static-analysis/scripts/lib/coverage.ts +1 -3
  30. package/skills/c64-static-analysis/scripts/lib/findings.ts +16 -3
  31. package/skills/c64-static-analysis/scripts/lib/idioms.ts +82 -10
  32. package/skills/c64-static-analysis/scripts/lib/triage.ts +112 -0
  33. package/skills/c64-static-analysis/scripts/static-analysis.ts +239 -147
  34. package/skills/c64-testing/SKILL.md +13 -7
  35. package/skills/c64-testing/scripts/lib/diff-files.ts +6 -13
  36. package/skills/c64-testing/scripts/lib/recording.ts +47 -66
  37. package/skills/c64-testing/scripts/lib/replay.ts +53 -9
  38. package/skills/c64-testing/scripts/lib/runs.ts +11 -29
  39. package/skills/c64-testing/scripts/lib/scenario.ts +30 -31
  40. package/skills/c64-testing/scripts/lib/start-screen.ts +42 -5
  41. package/skills/c64-testing/scripts/testing.ts +32 -7
  42. package/skills/c64-unpacker/SKILL.md +9 -7
  43. package/skills/c64-unpacker/scripts/lib/evidence.ts +23 -38
  44. package/skills/c64-unpacker/scripts/lib/loads.ts +24 -39
  45. package/skills/c64-unpacker/scripts/lib/machine.ts +38 -18
  46. package/skills/c64-unpacker/scripts/lib/stages.ts +124 -40
  47. package/skills/c64-unpacker/scripts/unpacker.ts +81 -68
  48. package/skills/emulator/SKILL.md +1 -0
  49. package/src/c64.ts +117 -10
  50. package/src/cli/ap-sdk.ts +1 -1
  51. package/src/cli/cleanup.ts +4 -2
  52. package/src/compare.ts +36 -16
  53. package/src/errors.ts +10 -1
  54. package/src/host/main.ts +2 -1
  55. package/src/host/server.ts +7 -11
  56. package/src/host/tools/c1541.ts +9 -3
  57. package/src/host/vice/adapter.ts +20 -43
  58. package/src/host/vice/binary-monitor.ts +22 -21
  59. package/src/host/vice/process.ts +31 -40
  60. package/src/host/vice/session.ts +187 -247
  61. package/src/host/vice/text-monitor.ts +3 -3
  62. package/src/host-client/autostart.ts +1 -1
  63. package/src/host-client/connect.ts +2 -1
  64. package/src/host-client/coverage.ts +0 -3
  65. package/src/host-client/entry-state.ts +4 -11
  66. package/src/host-client/image.ts +6 -11
  67. package/src/host-client/steps.ts +13 -113
  68. package/src/host-client/tools.ts +4 -4
  69. package/src/host-client/transfer.ts +10 -0
  70. package/src/host-client/vice-session.ts +10 -6
  71. package/src/knowledge/code-reach.ts +364 -0
  72. package/src/knowledge/conflicts.ts +34 -72
  73. package/src/knowledge/database.ts +40 -28
  74. package/src/knowledge/evidence.ts +2 -2
  75. package/src/knowledge/graph.ts +3 -3
  76. package/src/knowledge/history.ts +50 -90
  77. package/src/knowledge/import.ts +28 -68
  78. package/src/knowledge/join.ts +1 -1
  79. package/src/knowledge/names.ts +12 -7
  80. package/src/knowledge/program.ts +25 -46
  81. package/src/knowledge/read.ts +104 -100
  82. package/src/knowledge/schema.ts +9 -3
  83. package/src/knowledge/separate.ts +47 -19
  84. package/src/knowledge/start-screen.ts +7 -5
  85. package/src/knowledge/text.ts +56 -33
  86. package/src/knowledge/write.ts +274 -515
  87. package/src/loader.ts +7 -25
  88. package/src/mcp/inputs.ts +3 -3
  89. package/src/mcp/server.ts +19 -38
  90. package/src/mcp/session-source.ts +2 -1
  91. package/src/mcp/tools/debug.ts +97 -24
  92. package/src/mcp/tools/execution.ts +1 -1
  93. package/src/mcp/tools/input.ts +3 -3
  94. package/src/mcp/tools/machine.ts +3 -3
  95. package/src/mcp/tools/media.ts +4 -4
  96. package/src/mcp/tools/memory.ts +13 -17
  97. package/src/mcp/tools/video.ts +11 -25
  98. package/src/native/acme.ts +3 -3
  99. package/src/native/c64run.ts +2 -1
  100. package/src/native/decompiler/analyze.ts +10 -7
  101. package/src/native/decompiler/walk.ts +3 -4
  102. package/src/native/decompiler/wasm.ts +2 -2
  103. package/src/native/discover.ts +1 -1
  104. package/src/native/dxa.ts +9 -11
  105. package/src/native/exomizer.ts +1 -1
  106. package/src/native/processes.ts +4 -1
  107. package/src/native/run.ts +3 -3
  108. package/src/native/types.ts +5 -6
  109. package/src/opcodes.ts +3 -0
  110. package/src/platform.ts +9 -10
  111. package/src/program-code.ts +151 -0
  112. package/src/project.ts +8 -5
  113. package/src/protocol/framing.ts +51 -18
  114. package/src/protocol/messages.ts +1 -11
  115. package/src/protocol/tools.ts +0 -3
  116. package/src/protocol/vice.ts +588 -773
  117. package/src/script.ts +9 -14
  118. package/src/time.ts +1 -1
  119. 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,
@@ -752,12 +747,12 @@ async function envelope(script: Envelope): Promise<void> {
752
747
  if (error instanceof UsageError) {
753
748
  const help = `To get the usage, run ${script.name}.ts${commandName === undefined ? "" : ` ${commandName}`} --help.`;
754
749
  shown = { error: shown.error, hint: shown.hint === undefined ? help : `${sentence(shown.hint)} ${help}` };
755
- nextAction = commandLine(commandName === undefined ? [] : [commandName, "--help"]);
750
+ nextAction = commandLine(commandName === undefined ? ["--help"] : [commandName, "--help"]);
756
751
  }
757
752
  } else {
758
753
  code = "operation-failed";
759
754
  const where = commandName === undefined ? `${script.name}.ts` : `${script.name}.ts ${commandName}`;
760
- const text = (error instanceof Error ? error.message : String(error)).replace(/\.$/, "");
755
+ const text = describeError(error).replace(/\.$/, "");
761
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." };
762
757
  }
763
758
  const message = shown.hint === undefined ? shown.error : `${shown.error} ${shown.hint}`;
@@ -790,7 +785,7 @@ async function envelope(script: Envelope): Promise<void> {
790
785
  const picked = pickFields(shownBody, fields);
791
786
  shownBody = picked.body;
792
787
  if (picked.missing.length > 0) {
793
- const top = typeof body === "object" && body !== null && !Array.isArray(body) ? Object.keys(body) : [];
788
+ const top = isObject(body) ? Object.keys(body) : [];
794
789
  const lacks = `The body has no ${wordList(picked.missing)}. ${top.length === 0 ? "It has no fields." : `Its fields are ${wordList(top)}.`}`;
795
790
  shownHint = shownHint === undefined ? lacks : `${sentence(shownHint)} ${lacks}`;
796
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
  }