@henols/c64-re-tools 2.8.0-rc.2 → 2.8.0-rc.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 +5 -2
- package/skills/c64-assembler/scripts/assembler.ts +55 -48
- package/skills/c64-disk/scripts/disk.ts +3 -3
- package/skills/c64-disk/scripts/lib/containers.ts +2 -2
- package/skills/c64-docs/SKILL.md +1 -1
- package/skills/c64-docs/scripts/docs.ts +12 -20
- package/skills/c64-docs/scripts/lib/links.ts +1 -1
- package/skills/c64-docs/scripts/lib/markdown.ts +1 -1
- package/skills/c64-docs/scripts/lib/reference.ts +59 -13
- package/skills/c64-knowledge/SKILL.md +17 -8
- package/skills/c64-knowledge/scripts/knowledge.ts +200 -218
- package/skills/c64-knowledge/scripts/lib/check.ts +2 -3
- package/skills/c64-knowledge/scripts/lib/listing.ts +56 -24
- package/skills/c64-packer/scripts/packer.ts +3 -3
- package/skills/c64-provenance/SKILL.md +25 -16
- package/skills/c64-provenance/scripts/lib/compare.ts +31 -21
- package/skills/c64-provenance/scripts/lib/leftovers.ts +17 -35
- package/skills/c64-provenance/scripts/lib/library.ts +10 -10
- package/skills/c64-provenance/scripts/lib/runtime.ts +3 -14
- package/skills/c64-provenance/scripts/provenance.ts +129 -98
- package/skills/c64-source/references/loader.md +2 -1
- package/skills/c64-source/scripts/lib/export.ts +54 -303
- package/skills/c64-source/scripts/lib/loader.ts +31 -51
- package/skills/c64-source/scripts/lib/source.ts +51 -41
- package/skills/c64-source/scripts/lib/stage.ts +9 -25
- package/skills/c64-source/scripts/source.ts +134 -294
- package/skills/c64-static-analysis/SKILL.md +12 -7
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +1 -3
- package/skills/c64-static-analysis/scripts/lib/findings.ts +16 -3
- package/skills/c64-static-analysis/scripts/lib/idioms.ts +82 -10
- package/skills/c64-static-analysis/scripts/lib/triage.ts +112 -0
- package/skills/c64-static-analysis/scripts/static-analysis.ts +239 -147
- package/skills/c64-testing/SKILL.md +13 -7
- package/skills/c64-testing/scripts/lib/diff-files.ts +6 -13
- package/skills/c64-testing/scripts/lib/recording.ts +47 -66
- package/skills/c64-testing/scripts/lib/replay.ts +53 -9
- package/skills/c64-testing/scripts/lib/runs.ts +11 -29
- package/skills/c64-testing/scripts/lib/scenario.ts +30 -31
- package/skills/c64-testing/scripts/lib/start-screen.ts +42 -5
- package/skills/c64-testing/scripts/testing.ts +32 -7
- package/skills/c64-unpacker/SKILL.md +10 -7
- package/skills/c64-unpacker/scripts/lib/evidence.ts +23 -38
- package/skills/c64-unpacker/scripts/lib/loads.ts +24 -39
- package/skills/c64-unpacker/scripts/lib/machine.ts +38 -18
- package/skills/c64-unpacker/scripts/lib/stages.ts +142 -41
- package/skills/c64-unpacker/scripts/unpacker.ts +85 -68
- package/skills/emulator/SKILL.md +1 -0
- package/src/c64.ts +117 -10
- package/src/cli/ap-sdk.ts +1 -1
- package/src/cli/cleanup.ts +4 -2
- package/src/compare.ts +36 -16
- package/src/errors.ts +10 -1
- package/src/host/main.ts +2 -1
- package/src/host/server.ts +7 -11
- package/src/host/tools/c1541.ts +9 -3
- package/src/host/vice/adapter.ts +20 -43
- package/src/host/vice/binary-monitor.ts +22 -21
- package/src/host/vice/process.ts +31 -40
- package/src/host/vice/session.ts +187 -247
- package/src/host/vice/text-monitor.ts +3 -3
- package/src/host-client/autostart.ts +1 -1
- package/src/host-client/connect.ts +2 -1
- package/src/host-client/coverage.ts +0 -3
- package/src/host-client/entry-state.ts +4 -11
- package/src/host-client/image.ts +6 -11
- package/src/host-client/steps.ts +13 -113
- package/src/host-client/tools.ts +4 -4
- package/src/host-client/transfer.ts +10 -0
- package/src/host-client/vice-session.ts +10 -6
- package/src/knowledge/code-reach.ts +364 -0
- package/src/knowledge/conflicts.ts +34 -72
- package/src/knowledge/database.ts +40 -28
- package/src/knowledge/evidence.ts +2 -2
- package/src/knowledge/graph.ts +3 -3
- package/src/knowledge/history.ts +50 -90
- package/src/knowledge/import.ts +43 -71
- package/src/knowledge/join.ts +1 -1
- package/src/knowledge/names.ts +12 -7
- package/src/knowledge/program.ts +25 -46
- package/src/knowledge/read.ts +104 -100
- package/src/knowledge/schema.ts +9 -3
- package/src/knowledge/separate.ts +47 -19
- package/src/knowledge/start-screen.ts +7 -5
- package/src/knowledge/text.ts +56 -33
- package/src/knowledge/write.ts +274 -515
- package/src/loader.ts +7 -25
- package/src/mcp/inputs.ts +3 -3
- package/src/mcp/server.ts +19 -38
- package/src/mcp/session-source.ts +2 -1
- package/src/mcp/tools/debug.ts +97 -24
- package/src/mcp/tools/execution.ts +1 -1
- package/src/mcp/tools/input.ts +3 -3
- package/src/mcp/tools/machine.ts +3 -3
- package/src/mcp/tools/media.ts +4 -4
- package/src/mcp/tools/memory.ts +13 -17
- package/src/mcp/tools/video.ts +11 -25
- package/src/native/acme.ts +3 -3
- package/src/native/c64run.ts +2 -1
- package/src/native/decompiler/analyze.ts +10 -7
- package/src/native/decompiler/walk.ts +3 -4
- package/src/native/decompiler/wasm.ts +2 -2
- package/src/native/discover.ts +1 -1
- package/src/native/dxa.ts +9 -11
- package/src/native/exomizer.ts +1 -1
- package/src/native/processes.ts +4 -1
- package/src/native/run.ts +3 -3
- package/src/native/types.ts +5 -6
- package/src/opcodes.ts +3 -0
- package/src/platform.ts +9 -10
- package/src/program-code.ts +151 -0
- package/src/project.ts +8 -5
- package/src/protocol/framing.ts +51 -18
- package/src/protocol/messages.ts +1 -11
- package/src/protocol/tools.ts +0 -3
- package/src/protocol/vice.ts +588 -773
- package/src/script.ts +9 -14
- package/src/time.ts +1 -1
- package/src/trace.ts +3 -2
package/src/project.ts
CHANGED
|
@@ -16,7 +16,7 @@ export const PROJECT_DIRECTORY = ".c64-re-tools";
|
|
|
16
16
|
export const LOCAL_DIRECTORY = "local";
|
|
17
17
|
|
|
18
18
|
/** The folder in LOCAL_DIRECTORY for the reports of a generated source: its source map and the code that no run executed. */
|
|
19
|
-
|
|
19
|
+
const GENERATED_DIRECTORY = "generated";
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* The folder of the reports of the source that was generated into `out`, relative
|
|
@@ -292,11 +292,14 @@ export function resolveProjectPath(path: string, root = projectRoot()): string {
|
|
|
292
292
|
throw new Refusal("invalid-input", `${path} leads out of the project folder: give a path that stays inside it.`);
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
/** The folder of the committed knowledge text in PROJECT_DIRECTORY.
|
|
295
|
+
/** The folder of the committed knowledge text in PROJECT_DIRECTORY. */
|
|
296
296
|
export const KNOWLEDGE_TEXT_DIRECTORY = "knowledge";
|
|
297
297
|
|
|
298
|
-
/** The index of the knowledge in LOCAL_DIRECTORY
|
|
299
|
-
const
|
|
298
|
+
/** The index of the knowledge in LOCAL_DIRECTORY. */
|
|
299
|
+
export const KNOWLEDGE_INDEX_FILE = "knowledge.db";
|
|
300
|
+
|
|
301
|
+
/** The index and the files that SQLite keeps beside it. */
|
|
302
|
+
const KNOWLEDGE_INDEX_FILES = ["", "-wal", "-shm", "-journal"].map((suffix) => `${KNOWLEDGE_INDEX_FILE}${suffix}`);
|
|
300
303
|
|
|
301
304
|
/**
|
|
302
305
|
* The part of the knowledge that a path relative to the project folder is in:
|
|
@@ -308,7 +311,7 @@ export function knowledgePart(fromRoot: string): string | undefined {
|
|
|
308
311
|
const parts = fromRoot.split(/[\\/]+/).filter((part) => part !== "" && part !== ".").map((part) => part.toLowerCase());
|
|
309
312
|
if (parts[0] !== PROJECT_DIRECTORY) return undefined;
|
|
310
313
|
if (parts[1] === KNOWLEDGE_TEXT_DIRECTORY) return `${PROJECT_DIRECTORY}/${KNOWLEDGE_TEXT_DIRECTORY}/`;
|
|
311
|
-
if (parts[1] === LOCAL_DIRECTORY && parts.length === 3 &&
|
|
314
|
+
if (parts[1] === LOCAL_DIRECTORY && parts.length === 3 && KNOWLEDGE_INDEX_FILES.includes(parts[2]!)) return `${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/${parts[2]}`;
|
|
312
315
|
return undefined;
|
|
313
316
|
}
|
|
314
317
|
|
package/src/protocol/framing.ts
CHANGED
|
@@ -28,12 +28,6 @@ export class FrameTooLarge extends ProtocolError {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function frame(body: Uint8Array): Buffer {
|
|
32
|
-
const header = Buffer.allocUnsafe(HEADER_BYTES);
|
|
33
|
-
header.writeUInt32BE(body.length, 0);
|
|
34
|
-
return Buffer.concat([header, body]);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
31
|
/** Encodes one message and its attachments as one buffer, so writes never interleave. */
|
|
38
32
|
export function encodeFrame(message: ClientMessage | HostMessage, attachments: readonly Uint8Array[] = []): Buffer {
|
|
39
33
|
const total = attachments.reduce((sum, attachment) => sum + attachment.length, 0);
|
|
@@ -41,28 +35,67 @@ export function encodeFrame(message: ClientMessage | HostMessage, attachments: r
|
|
|
41
35
|
const announced = attachments.length === 0 ? message : { ...message, attachments: attachments.map((attachment) => attachment.length) };
|
|
42
36
|
const body = Buffer.from(JSON.stringify(announced), "utf8");
|
|
43
37
|
if (body.length > MAX_FRAME_BYTES) throw new FrameTooLarge("frame", body.length, MAX_FRAME_BYTES);
|
|
44
|
-
const frames =
|
|
38
|
+
const frames = 1 + attachments.reduce((sum, attachment) => sum + Math.ceil(attachment.length / MAX_FRAME_BYTES), 0);
|
|
39
|
+
const encoded = Buffer.allocUnsafe(frames * HEADER_BYTES + body.length + total);
|
|
40
|
+
let offset = 0;
|
|
41
|
+
const frame = (part: Uint8Array) => {
|
|
42
|
+
offset = encoded.writeUInt32BE(part.length, offset);
|
|
43
|
+
encoded.set(part, offset);
|
|
44
|
+
offset += part.length;
|
|
45
|
+
};
|
|
46
|
+
frame(body);
|
|
45
47
|
for (const attachment of attachments) {
|
|
46
|
-
for (let
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
for (let start = 0; start < attachment.length; start += MAX_FRAME_BYTES) frame(attachment.subarray(start, start + MAX_FRAME_BYTES));
|
|
49
|
+
}
|
|
50
|
+
return encoded;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The bytes of a stream so far. A decoder joins the chunks only once the bytes
|
|
55
|
+
* of its next step are all here: joining at each chunk copies a large frame
|
|
56
|
+
* again and again.
|
|
57
|
+
*/
|
|
58
|
+
export class StreamBuffer {
|
|
59
|
+
#chunks: Buffer[] = [];
|
|
60
|
+
length = 0;
|
|
61
|
+
|
|
62
|
+
push(chunk: Buffer): void {
|
|
63
|
+
this.#chunks.push(chunk);
|
|
64
|
+
this.length += chunk.length;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** All buffered bytes as one buffer. */
|
|
68
|
+
bytes(): Buffer {
|
|
69
|
+
if (this.#chunks.length !== 1) this.#chunks = [Buffer.concat(this.#chunks, this.length)];
|
|
70
|
+
return this.#chunks[0]!;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Drops the first `count` bytes. */
|
|
74
|
+
drop(count: number): void {
|
|
75
|
+
const rest = this.bytes().subarray(count);
|
|
76
|
+
this.#chunks = rest.length === 0 ? [] : [rest];
|
|
77
|
+
this.length = rest.length;
|
|
49
78
|
}
|
|
50
|
-
return Buffer.concat(frames);
|
|
51
79
|
}
|
|
52
80
|
|
|
53
81
|
/** Splits a stream into frame bodies. After a ProtocolError the decoder is unusable. */
|
|
54
82
|
class RawFrameDecoder {
|
|
55
|
-
#
|
|
83
|
+
readonly #stream = new StreamBuffer();
|
|
84
|
+
/** The bytes that the frame in front needs: its header, then its header and body. */
|
|
85
|
+
#needed = HEADER_BYTES;
|
|
56
86
|
|
|
57
87
|
push(chunk: Buffer): Buffer[] {
|
|
58
|
-
this.#
|
|
88
|
+
this.#stream.push(chunk);
|
|
59
89
|
const bodies: Buffer[] = [];
|
|
60
|
-
while (this.#
|
|
61
|
-
const
|
|
90
|
+
while (this.#stream.length >= this.#needed) {
|
|
91
|
+
const pending = this.#stream.bytes();
|
|
92
|
+
const length = pending.readUInt32BE(0);
|
|
62
93
|
if (length > MAX_FRAME_BYTES) throw new ProtocolError(`frame of ${length} bytes exceeds ${MAX_FRAME_BYTES}`);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
94
|
+
this.#needed = HEADER_BYTES + length;
|
|
95
|
+
if (pending.length < this.#needed) break;
|
|
96
|
+
bodies.push(Buffer.from(pending.subarray(HEADER_BYTES, HEADER_BYTES + length)));
|
|
97
|
+
this.#stream.drop(HEADER_BYTES + length);
|
|
98
|
+
this.#needed = HEADER_BYTES;
|
|
66
99
|
}
|
|
67
100
|
return bodies;
|
|
68
101
|
}
|
package/src/protocol/messages.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface WireError {
|
|
|
25
25
|
message: string;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
const ROLES = ["vice-session", "tool"] as const;
|
|
29
29
|
export type Role = (typeof ROLES)[number];
|
|
30
30
|
|
|
31
31
|
export const VIDEO_STANDARDS = ["pal", "ntsc"] as const;
|
|
@@ -96,7 +96,6 @@ export class ProtocolError extends Error {
|
|
|
96
96
|
override name = "ProtocolError";
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
/** Thrown by parameter/result validators; carries the wire code to answer with. */
|
|
100
99
|
/**
|
|
101
100
|
* The instruction at the end of a refusal that only the user can fix: a
|
|
102
101
|
* missing or broken tool, or a Host Runtime that does not run.
|
|
@@ -116,15 +115,6 @@ export function shownMessage(error: { code: string; message: string }): string {
|
|
|
116
115
|
/** A refusal that crosses the Host Runtime wire. */
|
|
117
116
|
export class WireFailure extends Refusal implements WireError {
|
|
118
117
|
override name = "WireFailure";
|
|
119
|
-
|
|
120
|
-
toWire(): WireError {
|
|
121
|
-
return { code: this.code, message: this.message };
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** The message of a caught value, which may not be an Error. */
|
|
126
|
-
export function describeError(error: unknown): string {
|
|
127
|
-
return error instanceof Error ? error.message : String(error);
|
|
128
118
|
}
|
|
129
119
|
|
|
130
120
|
export type Fields = Record<string, unknown>;
|
package/src/protocol/tools.ts
CHANGED
|
@@ -64,9 +64,6 @@ export type C1541Result =
|
|
|
64
64
|
/** petcat.decode takes no fields: the program bytes are the request's one attachment. */
|
|
65
65
|
export type PetcatParams = Record<string, never>;
|
|
66
66
|
|
|
67
|
-
/** A machine-code handoff: SYS with a constant address, or SYS/USR whose target is computed at run time. */
|
|
68
|
-
export type { BasicHandoff };
|
|
69
|
-
|
|
70
67
|
export type PetcatResult =
|
|
71
68
|
| { decoded: false; reason: string }
|
|
72
69
|
| {
|