@henols/c64-re-tools 2.4.0-rc.3 → 2.4.0-rc.5
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 +2 -0
- package/skills/c64-basic/SKILL.md +2 -0
- package/skills/c64-disk/SKILL.md +2 -0
- package/skills/c64-docs/SKILL.md +2 -0
- package/skills/c64-docs/scripts/docs.ts +6 -6
- package/skills/c64-knowledge/SKILL.md +2 -0
- package/skills/c64-memory-map/SKILL.md +2 -0
- package/skills/c64-packer/SKILL.md +2 -0
- package/skills/c64-provenance/SKILL.md +3 -0
- package/skills/c64-provenance/scripts/lib/library.ts +14 -8
- package/skills/c64-reverse-engineering/SKILL.md +3 -3
- package/skills/c64-source/SKILL.md +2 -0
- package/skills/c64-static-analysis/SKILL.md +2 -0
- package/skills/c64-testing/SKILL.md +2 -0
- package/skills/c64-unpacker/SKILL.md +2 -0
- package/src/host-client/transfer.ts +4 -3
- package/src/native/discover.ts +12 -2
- package/src/project.ts +58 -1
- package/src/script.ts +11 -6
package/package.json
CHANGED
|
@@ -59,6 +59,8 @@ A source that you generated from the project knowledge has switches in `config.a
|
|
|
59
59
|
|
|
60
60
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
61
61
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
62
|
+
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
63
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/original/game.prg`. The command writes only in its own project.
|
|
62
64
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
63
65
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
64
66
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -35,6 +35,8 @@ To get the command list, run the script with no arguments.
|
|
|
35
35
|
|
|
36
36
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
37
37
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
38
|
+
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
39
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/original/game.prg`. The command writes only in its own project.
|
|
38
40
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
39
41
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
40
42
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
package/skills/c64-disk/SKILL.md
CHANGED
|
@@ -61,6 +61,8 @@ To get the command list, run the script with no arguments.
|
|
|
61
61
|
|
|
62
62
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
63
63
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
64
|
+
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
65
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/original/game.prg`. The command writes only in its own project.
|
|
64
66
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
65
67
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
66
68
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
package/skills/c64-docs/SKILL.md
CHANGED
|
@@ -50,6 +50,8 @@ Get the values for the commands from these places:
|
|
|
50
50
|
|
|
51
51
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
52
52
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
53
|
+
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
54
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/original/game.prg`. The command writes only in its own project.
|
|
53
55
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
54
56
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
55
57
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -15,7 +15,7 @@ import { conflicts } from "#src/knowledge/conflicts.ts";
|
|
|
15
15
|
import { openForRead } from "#src/knowledge/database.ts";
|
|
16
16
|
import { programImage, type ProgramImage } from "#src/knowledge/program.ts";
|
|
17
17
|
import { currentRevision, listComments, listModules, listReferences, listRegions, listSymbols } from "#src/knowledge/read.ts";
|
|
18
|
-
import {
|
|
18
|
+
import { groupOf, namedGroup, projectRoot, resolveProjectFile, resolveProjectPath, type ProjectGroup } from "#src/project.ts";
|
|
19
19
|
import { listed, OPTIONS, reply, runScript, UsageError, type Call, type Reply } from "#src/script.ts";
|
|
20
20
|
import { checkLinks, linkPage, type Files, type LinkContext, type Names, type Problem } from "./lib/links.ts";
|
|
21
21
|
import { buildReference, GENERATED_MARK } from "./lib/reference.ts";
|
|
@@ -124,7 +124,7 @@ interface Scope {
|
|
|
124
124
|
group: ProjectGroup | undefined;
|
|
125
125
|
/** The folder of the given pages, relative to root: the project of the run, or "" for root itself. */
|
|
126
126
|
base: string;
|
|
127
|
-
/** True when the run is
|
|
127
|
+
/** True when the run is on the group folder: the project lookup refuses it, so nextAction gives it as --project. */
|
|
128
128
|
unnamed: boolean;
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -141,13 +141,11 @@ function linkScope(): Scope {
|
|
|
141
141
|
try {
|
|
142
142
|
root = projectRoot();
|
|
143
143
|
} catch (error) {
|
|
144
|
-
// The project lookup refuses a folder with
|
|
145
|
-
const group =
|
|
144
|
+
// The project lookup refuses a group folder: given with --project or as the working directory, link works on the group.
|
|
145
|
+
const group = namedGroup();
|
|
146
146
|
if (group === undefined) throw error;
|
|
147
147
|
return { root: group.root, group, base: "", unnamed: true };
|
|
148
148
|
}
|
|
149
|
-
const at = groupAt(root);
|
|
150
|
-
if (at !== undefined) return { root, group: at, base: "", unnamed: false };
|
|
151
149
|
const group = groupOf(root);
|
|
152
150
|
if (group === undefined) return { root, group, base: "", unnamed: false };
|
|
153
151
|
return { root: group.root, group, base: basename(root), unnamed: false };
|
|
@@ -212,6 +210,8 @@ function link(call: Call): Reply {
|
|
|
212
210
|
const walk = (relative: string) => {
|
|
213
211
|
for (const entry of readdirSync(join(real, relative), { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
214
212
|
const path = posix.join(relative, entry.name);
|
|
213
|
+
// A dot folder is no documentation: .c64-re-tools/ holds the knowledge and the scratch of the agent, .git/ the history.
|
|
214
|
+
if (entry.isDirectory() && entry.name.startsWith(".")) continue;
|
|
215
215
|
if (entry.isDirectory()) walk(path);
|
|
216
216
|
else if (entry.name.endsWith(".md")) found.push(posix.join(directory, path));
|
|
217
217
|
}
|
|
@@ -77,6 +77,8 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
|
|
|
77
77
|
|
|
78
78
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
79
79
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
80
|
+
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
81
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/original/game.prg`. The command writes only in its own project.
|
|
80
82
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
81
83
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
82
84
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -42,6 +42,8 @@ To get the command list, run the script with no arguments.
|
|
|
42
42
|
|
|
43
43
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
44
44
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
45
|
+
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
46
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/original/game.prg`. The command writes only in its own project.
|
|
45
47
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
46
48
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
47
49
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -41,6 +41,8 @@ To get the command list, run the script with no arguments.
|
|
|
41
41
|
|
|
42
42
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
43
43
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
44
|
+
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
45
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/original/game.prg`. The command writes only in its own project.
|
|
44
46
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
45
47
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
46
48
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -58,6 +58,8 @@ To get the command list, run the script with no arguments.
|
|
|
58
58
|
|
|
59
59
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
60
60
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
61
|
+
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
62
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/original/game.prg`. The command writes only in its own project.
|
|
61
63
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
62
64
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
63
65
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -247,6 +249,7 @@ Traps:
|
|
|
247
249
|
- Error `invalid-input` with "no user or LLM name": give `--name`.
|
|
248
250
|
- Error `conflict`: the library has a routine with that name. Give another `--name`, or give `--replace` to write over it.
|
|
249
251
|
- Error `invalid-input` with "is a project folder": the library folder is a project. Give a folder beside the projects.
|
|
252
|
+
- Error `invalid-input` with "a new library must not be in the project folder": the library folder does not exist, and it is in the project. Give a folder beside the projects, for example `../library`.
|
|
250
253
|
|
|
251
254
|
### `match`
|
|
252
255
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// suggests its names there as an apply batch. Nothing here writes knowledge.
|
|
6
6
|
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
|
-
import { mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
9
9
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
10
10
|
|
|
11
11
|
import { Refusal } from "#src/errors.ts";
|
|
@@ -14,7 +14,7 @@ import { formatC64Address, instructionLength } from "#src/c64.ts";
|
|
|
14
14
|
import { evaluate, identifiers, operandText } from "#src/knowledge/expression.ts";
|
|
15
15
|
import type { CommentRow, OperandRow, ReferenceRow, RegionRow, SymbolRow } from "#src/knowledge/read.ts";
|
|
16
16
|
import { COMMENT_PLACEMENTS, type CommentPlacement, isSemantic, OPERAND_SELECTS, type OperandSelect, REFERENCE_KINDS, type ReferenceKind, REGION_TYPES, type RegionType, SYMBOL_KINDS, type SymbolKind } from "#src/knowledge/schema.ts";
|
|
17
|
-
import { checkOutputPath, isInside, knowledgePart, PROJECT_DIRECTORY } from "#src/project.ts";
|
|
17
|
+
import { checkOutputPath, isInside, knowledgePart, LOCAL_DIRECTORY, PROJECT_DIRECTORY } from "#src/project.ts";
|
|
18
18
|
|
|
19
19
|
/** A routine shorter than this is not saved and not searched: its bytes occur by chance. */
|
|
20
20
|
export const MIN_ROUTINE = 16;
|
|
@@ -294,8 +294,10 @@ export function parseRoutine(text: string, file: string): Routine {
|
|
|
294
294
|
/**
|
|
295
295
|
* Refuses a library folder to write that is inside the project `root`, also
|
|
296
296
|
* through a symbolic link, when the output check of every script refuses it
|
|
297
|
-
* (checkOutputPath): for example a folder in the knowledge. A
|
|
298
|
-
* the project
|
|
297
|
+
* (checkOutputPath): for example a folder in the knowledge. A new library
|
|
298
|
+
* folder in the project is refused too, except in .c64-re-tools/local/: the
|
|
299
|
+
* other projects cannot match against it. A folder outside the project gets no
|
|
300
|
+
* check.
|
|
299
301
|
*/
|
|
300
302
|
function checkLibraryOutput(path: string, root: string): void {
|
|
301
303
|
let existing = path;
|
|
@@ -310,6 +312,10 @@ function checkLibraryOutput(path: string, root: string): void {
|
|
|
310
312
|
if (part !== undefined) {
|
|
311
313
|
throw new Refusal("invalid-input", `--library: ${shown} 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 library folder beside the projects, for example ../library.`);
|
|
312
314
|
}
|
|
315
|
+
// For example --library library from the folder above the projects: it names a folder in the project.
|
|
316
|
+
if (existing !== path && existsSync(join(base, PROJECT_DIRECTORY)) && !isInside(join(base, PROJECT_DIRECTORY, LOCAL_DIRECTORY), target)) {
|
|
317
|
+
throw new Refusal("invalid-input", `--library: there is no library folder ${shown} in the project folder, and a new library must not be in the project folder, because the other projects cannot match against it there. --library is relative to the project folder. Give a library folder beside the projects, for example ../library.`);
|
|
318
|
+
}
|
|
313
319
|
checkOutputPath(shown, "folder", { root: base, what: "--library" });
|
|
314
320
|
return;
|
|
315
321
|
}
|
|
@@ -317,10 +323,10 @@ function checkLibraryOutput(path: string, root: string): void {
|
|
|
317
323
|
}
|
|
318
324
|
|
|
319
325
|
/**
|
|
320
|
-
* The library folder that --library names, relative to the
|
|
321
|
-
*
|
|
322
|
-
* `create`, a missing folder is made; a folder inside
|
|
323
|
-
* the
|
|
326
|
+
* The library folder that --library names, relative to `cwd`: the scripts
|
|
327
|
+
* give the project folder, as for every path. A library is a plain folder,
|
|
328
|
+
* never a project. With `create`, a missing folder is made; a folder inside
|
|
329
|
+
* the project must pass checkLibraryOutput.
|
|
324
330
|
*/
|
|
325
331
|
export function libraryFolder(folder: string, options: { create: boolean; cwd?: string }): string {
|
|
326
332
|
if (folder.length === 0) throw new Refusal("invalid-input", "The library folder must not be empty.", { hint: "Give a library folder beside the projects, for example ../library." });
|
|
@@ -160,11 +160,11 @@ Some releases of a program have a different layout. Their code is at different a
|
|
|
160
160
|
|
|
161
161
|
1. Make the group folder in the git repository. Do not put `.c64-re-tools/` in it.
|
|
162
162
|
2. Ask the user before you move a project folder. Then move the current project into `<game>/v1/`. The project knowledge keeps its paths relative to the project folder. Thus the knowledge stays valid after the move.
|
|
163
|
-
3. Make a project folder for the new version, for example `<game>/v2/`. Start at stage 2 with the file of that release.
|
|
163
|
+
3. Make a project folder for the new version, for example `<game>/v2/`. Start at stage 2 with the file of that release. From the group folder, give `--project v2`. In the empty folder `v2/`, give `--project .`. The first write makes the project.
|
|
164
164
|
4. Keep the releases with the same layout in one version. Record them as releases with switches. For example, `v2` holds a base release and a second release from a different crack.
|
|
165
|
-
5. Save the routines of `v1` to the routine library in `<game>/library/`. In stage 7 of `v2`, match the program against that library. Then `v2` gets the names of `v1` for the same routines.
|
|
165
|
+
5. Save the routines of `v1` to the routine library in `<game>/library/`. Give `--library ../library`, because `--library` is relative to the project folder. In stage 7 of `v2`, match the program against that library. Then `v2` gets the names of `v1` for the same routines.
|
|
166
166
|
6. Use the same folders in each version, for example `src` and `docs/reference`.
|
|
167
|
-
7. From the group folder, give `--project v1` or `--project v2` to each script.
|
|
167
|
+
7. From the group folder, give `--project v1` or `--project v2` to each script. A script can read a file of another version, for example `../v1/original/<file>`. Use this to compare the releases of two versions. Record each release only in the project of its version.
|
|
168
168
|
8. Write the facts that the versions share one time, in the pages of the group folder. The pages of each version tell only how that version works.
|
|
169
169
|
|
|
170
170
|
## Knowledge
|
|
@@ -50,6 +50,8 @@ To get the command list, run the script with no arguments.
|
|
|
50
50
|
|
|
51
51
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
52
52
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
53
|
+
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
54
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/original/game.prg`. The command writes only in its own project.
|
|
53
55
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
54
56
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
55
57
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -57,6 +57,8 @@ To get the command list, run the script with no arguments.
|
|
|
57
57
|
|
|
58
58
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
59
59
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
60
|
+
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
61
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/original/game.prg`. The command writes only in its own project.
|
|
60
62
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
61
63
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
62
64
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -52,6 +52,8 @@ To get the command list, run the script with no arguments.
|
|
|
52
52
|
|
|
53
53
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
54
54
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
55
|
+
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
56
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/original/game.prg`. The command writes only in its own project.
|
|
55
57
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
56
58
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
57
59
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -72,6 +72,8 @@ The script refuses a step in an old form. The message gives the step to write.
|
|
|
72
72
|
|
|
73
73
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
74
74
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
75
|
+
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
76
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/original/game.prg`. The command writes only in its own project.
|
|
75
77
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
76
78
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
77
79
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -5,7 +5,7 @@ import { createHash } from "node:crypto";
|
|
|
5
5
|
import { lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
7
|
|
|
8
|
-
import { checkOutputPath, isInside, projectRoot, resolveProject, resolveProjectFile, writeProblem } from "../project.ts";
|
|
8
|
+
import { checkOutputPath, isInside, projectRoot, readGroup, resolveProject, resolveProjectFile, resolveReadFile, writeProblem } from "../project.ts";
|
|
9
9
|
import { isRefusal } from "../errors.ts";
|
|
10
10
|
import { MAX_ATTACHMENT_BYTES } from "../protocol/framing.ts";
|
|
11
11
|
import { WireFailure } from "../protocol/messages.ts";
|
|
@@ -45,13 +45,14 @@ export function readProjectFile(path: string, options: { root?: string; what?: s
|
|
|
45
45
|
const root = options.root ?? currentProject();
|
|
46
46
|
let real: string;
|
|
47
47
|
try {
|
|
48
|
-
real =
|
|
48
|
+
real = resolveReadFile(path, root);
|
|
49
49
|
} catch (error) {
|
|
50
50
|
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
51
51
|
throw new WireFailure("not-found", `${options.what === undefined ? "" : `${options.what}: `}There is no file at ${path} in the project folder.`);
|
|
52
52
|
}
|
|
53
53
|
if (isRefusal(error) && error.code === "invalid-input") {
|
|
54
|
-
|
|
54
|
+
const where = readGroup(root) === undefined ? "it" : "its group folder";
|
|
55
|
+
throw new WireFailure("invalid-input", `${options.what ?? path}: give a path relative to the project folder that stays inside ${where}, not ${path}.`);
|
|
55
56
|
}
|
|
56
57
|
throw error;
|
|
57
58
|
}
|
package/src/native/discover.ts
CHANGED
|
@@ -127,15 +127,25 @@ const VICE_FLAWS = [
|
|
|
127
127
|
"A program that compares the full byte of a joystick port also waits forever. " +
|
|
128
128
|
"A KERNAL tape LOAD of a .tap image stops after FOUND, with no LOADING, and the C64 shows READY. The fix is in the next VICE release, and in VICE nightly builds now (SVN r45971 or later). " +
|
|
129
129
|
"Install the latest VICE when this matters.",
|
|
130
|
+
noRevision:
|
|
131
|
+
"This VICE 3.10 shows no SVN revision: it is the 3.10 release, or a build from source without its revision. " +
|
|
132
|
+
"To build a nightly from source, run configure with SVN_REVISION_OVERRIDE=<revision>, so that x64sc -version shows the revision (for example x64sc (VICE 3.10 SVN r46290)).",
|
|
130
133
|
},
|
|
131
134
|
] as const;
|
|
132
135
|
|
|
133
|
-
/**
|
|
136
|
+
/**
|
|
137
|
+
* The known flaws of this VICE version. A build of the last flawed
|
|
138
|
+
* major.minor with no revision can be a nightly that has the fix: its
|
|
139
|
+
* flaw text tells how to build it with the revision.
|
|
140
|
+
*/
|
|
134
141
|
export function viceFlaws(version: ViceVersion): ViceFlaw[] {
|
|
135
142
|
return VICE_FLAWS.filter((flaw) => {
|
|
136
143
|
const newer = version.major > flaw.upTo.major || (version.major === flaw.upTo.major && version.minor > flaw.upTo.minor);
|
|
137
144
|
return !newer && (version.revision === undefined || version.revision < flaw.fixedRevision);
|
|
138
|
-
}).map((flaw) =>
|
|
145
|
+
}).map((flaw) => {
|
|
146
|
+
const last = version.major === flaw.upTo.major && version.minor === flaw.upTo.minor;
|
|
147
|
+
return { text: last && version.revision === undefined ? `${flaw.text} ${flaw.noRevision}` : flaw.text, breaks: flaw.breaks };
|
|
148
|
+
});
|
|
139
149
|
}
|
|
140
150
|
|
|
141
151
|
export function isOlderThanMinimum(version: { major: number; minor: number }): boolean {
|
package/src/project.ts
CHANGED
|
@@ -34,6 +34,9 @@ const SCRIPT_REMEDY = "Give --project <folder>";
|
|
|
34
34
|
/** The folder that --project chose for this process, or undefined. */
|
|
35
35
|
let chosen: string | undefined;
|
|
36
36
|
|
|
37
|
+
/** The group when --project chose a group folder: the project lookup refuses it, and only a command that works on a group uses it. */
|
|
38
|
+
let chosenGroup: ProjectGroup | undefined;
|
|
39
|
+
|
|
37
40
|
/** The project that the project lookup found from a working directory, kept for the next call from the same directory. */
|
|
38
41
|
let found: { cwd: string; root: string } | undefined;
|
|
39
42
|
|
|
@@ -106,9 +109,20 @@ export function findProject(cwd: string = process.cwd(), options: ProjectRemedy
|
|
|
106
109
|
if (below.length > 0) {
|
|
107
110
|
throw new Refusal("invalid-input", `${start} is not a project folder. These folders below it are projects: ${listed(below)}. ${remedy} with one of them.`);
|
|
108
111
|
}
|
|
112
|
+
// A folder of a group that is no project, for example its docs/: a write there would make it a project of the group.
|
|
113
|
+
const group = foldersUpFrom(start).slice(1).map(groupAt).find((each) => each !== undefined);
|
|
114
|
+
if (group !== undefined) {
|
|
115
|
+
const projects = [...group.projects.values()].map((project) => relative(start, project).split(sep).join("/"));
|
|
116
|
+
throw new Refusal("invalid-input", `${start} is in the group folder ${group.root}, and it is not a project folder. The projects of the group are ${listed(projects)}. ${remedy} with one of them. To make this folder a new project of the group, give the folder itself: .`);
|
|
117
|
+
}
|
|
109
118
|
return start;
|
|
110
119
|
}
|
|
111
120
|
|
|
121
|
+
/** The refusal of a group folder as a project: a write there would make it a project, and then it is no group. */
|
|
122
|
+
function groupRefusal(path: string, group: ProjectGroup, remedy: string): Refusal {
|
|
123
|
+
return new Refusal("invalid-input", `${path} is a group folder, not a project folder. These folders in it are projects: ${listed([...group.projects.keys()])}. ${remedy} with one of them.`);
|
|
124
|
+
}
|
|
125
|
+
|
|
112
126
|
/**
|
|
113
127
|
* The project folder that `folder` names, relative to `cwd` or absolute. It
|
|
114
128
|
* must be a folder. It is the project as given, also without .c64-re-tools/
|
|
@@ -221,6 +235,8 @@ export function ensureLocal(root: string): void {
|
|
|
221
235
|
/** The project of an MCP call or another caller without process state: `folder` when given, else the project lookup from `cwd`. */
|
|
222
236
|
export function resolveProject(folder: string | undefined, cwd: string = process.cwd(), options: ProjectRemedy = {}): string {
|
|
223
237
|
const root = folder === undefined ? findProject(cwd, options) : namedProject(folder, cwd);
|
|
238
|
+
const group = folder === undefined ? undefined : groupAt(root);
|
|
239
|
+
if (group !== undefined) throw groupRefusal(root, group, options.remedy ?? SCRIPT_REMEDY);
|
|
224
240
|
ensureLocal(root);
|
|
225
241
|
return root;
|
|
226
242
|
}
|
|
@@ -228,10 +244,17 @@ export function resolveProject(folder: string | undefined, cwd: string = process
|
|
|
228
244
|
/** Sets the project of this process from --project. Refuses a folder that the rules refuse. */
|
|
229
245
|
export function useProject(folder: string): void {
|
|
230
246
|
chosen = namedProject(folder);
|
|
247
|
+
chosenGroup = groupAt(chosen);
|
|
231
248
|
}
|
|
232
249
|
|
|
233
|
-
/** The
|
|
250
|
+
/** The group of a run that works on a group: the group folder that --project names, else the group folder that is the working directory. */
|
|
251
|
+
export function namedGroup(): ProjectGroup | undefined {
|
|
252
|
+
return chosen === undefined ? groupAt(process.cwd()) : chosenGroup;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** The project folder of this process: the --project choice, else the project lookup from the working directory. A group folder is refused. */
|
|
234
256
|
export function projectRoot(): string {
|
|
257
|
+
if (chosenGroup !== undefined) throw groupRefusal(chosenGroup.root, chosenGroup, SCRIPT_REMEDY);
|
|
235
258
|
let root = chosen;
|
|
236
259
|
if (root === undefined) {
|
|
237
260
|
const cwd = process.cwd();
|
|
@@ -393,3 +416,37 @@ export function resolveProjectFile(path: string, root = projectRoot()): string {
|
|
|
393
416
|
}
|
|
394
417
|
return real;
|
|
395
418
|
}
|
|
419
|
+
|
|
420
|
+
/** The group of each project that a read resolved a path for. */
|
|
421
|
+
const readGroups = new Map<string, ProjectGroup | undefined>();
|
|
422
|
+
|
|
423
|
+
/** The group folder of the project `root`, or undefined: the folder that a read of the project can reach. */
|
|
424
|
+
export function readGroup(root: string): ProjectGroup | undefined {
|
|
425
|
+
if (!readGroups.has(root)) readGroups.set(root, groupOf(root));
|
|
426
|
+
return readGroups.get(root);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Resolves a path that a command only reads, relative to the project folder,
|
|
431
|
+
* as resolveProjectPath does. In a group the path can also lead into the group
|
|
432
|
+
* folder, so a version reads the files of the other versions, for example
|
|
433
|
+
* ../v1/original/game.prg. A write stays in the project.
|
|
434
|
+
*/
|
|
435
|
+
export function resolveReadPath(path: string, root = projectRoot()): string {
|
|
436
|
+
const group = readGroup(root);
|
|
437
|
+
if (group === undefined || path.length === 0 || isAbsolute(path)) return resolveProjectPath(path, root);
|
|
438
|
+
const candidate = resolve(root, path);
|
|
439
|
+
if (isInside(group.root, candidate)) return candidate;
|
|
440
|
+
throw new Refusal("invalid-input", `${path} leads out of the group folder of the project: give a path that stays inside it.`);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** resolveReadPath to an existing entry whose real location is inside the project, or in a group inside the group folder, as resolveProjectFile does. */
|
|
444
|
+
export function resolveReadFile(path: string, root = projectRoot()): string {
|
|
445
|
+
const group = readGroup(root);
|
|
446
|
+
if (group === undefined) return resolveProjectFile(path, root);
|
|
447
|
+
const real = realpathSync(resolveReadPath(path, root));
|
|
448
|
+
if (!isInside(realpathSync(group.root), real)) {
|
|
449
|
+
throw new Refusal("invalid-input", `${path} leads out of the group folder of the project through a symbolic link.`);
|
|
450
|
+
}
|
|
451
|
+
return real;
|
|
452
|
+
}
|
package/src/script.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { parseArgs } from "node:util";
|
|
|
21
21
|
|
|
22
22
|
import { c64AddressOf, formatC64Address, SPACE_PATTERN, SYMBOL_NAME, type AddressRange } from "./c64.ts";
|
|
23
23
|
import { isRefusal, Refusal, splitMessage, type ErrorCode } from "./errors.ts";
|
|
24
|
-
import { checkOutputPath, projectRoot, resolveProjectPath, useProject, type OutputKind } from "./project.ts";
|
|
24
|
+
import { checkOutputPath, projectRoot, resolveProjectPath, resolveReadPath, useProject, type OutputKind } from "./project.ts";
|
|
25
25
|
import { STOP_AND_ASK } from "./protocol/messages.ts";
|
|
26
26
|
import { elapsedMs, startTrace, trace, type TraceFields } from "./trace.ts";
|
|
27
27
|
|
|
@@ -342,7 +342,7 @@ export function listed<T, U = T>(items: readonly T[], max: number, show: (item:
|
|
|
342
342
|
|
|
343
343
|
/** The conventions in the help of every script. */
|
|
344
344
|
export const CONVENTIONS = `Addresses are $ and 1 to 4 hex digits, for example '$c000' or '$fb', or a name: a symbol, else an analyzer name that only one analyzer gives. A range is <start>-<end>, for example '$c000-$cfff'. Quote them in a shell.
|
|
345
|
-
Paths are relative to the project folder. Every script takes --project <folder>: the project folder, relative to the working directory. Without it, the script uses the nearest folder at or above the working directory that holds .c64-re-tools/.
|
|
345
|
+
Paths are relative to the project folder. Every script takes --project <folder>: the project folder, relative to the working directory. Without it, the script uses the nearest folder at or above the working directory that holds .c64-re-tools/. In a group folder, give --project with a project of the group. A path that a command only reads can go into another project of the group, for example ../v1/original/game.prg.
|
|
346
346
|
Each command prints one JSON envelope: {ok: true, command, body, hint?, nextAction?} with exit status 0, or {ok: false, command?, code, error, hint?, nextAction?} with exit status 2.`;
|
|
347
347
|
|
|
348
348
|
function optionLabel(name: string, spec: OptionSpec): string {
|
|
@@ -444,11 +444,16 @@ function asksHelp(argv: readonly string[]): boolean {
|
|
|
444
444
|
return (end < 0 ? argv : argv.slice(0, end)).includes("--help");
|
|
445
445
|
}
|
|
446
446
|
|
|
447
|
-
/**
|
|
448
|
-
|
|
447
|
+
/**
|
|
448
|
+
* Refuses a path that is not relative to the project folder or that leads out
|
|
449
|
+
* of it; a path that the command only reads can also lead into the group folder
|
|
450
|
+
* of the project. A refusal of the project lookup itself passes on.
|
|
451
|
+
*/
|
|
452
|
+
function checkPath(text: string, what: string, read = false): void {
|
|
449
453
|
const root = projectRoot();
|
|
450
454
|
try {
|
|
451
|
-
|
|
455
|
+
if (read) resolveReadPath(text, root);
|
|
456
|
+
else resolveProjectPath(text, root);
|
|
452
457
|
} catch (error) {
|
|
453
458
|
if (isRefusal(error)) throw new UsageError(`${what}: ${error.message}`);
|
|
454
459
|
throw error;
|
|
@@ -606,7 +611,7 @@ export function parseCall(script: ScriptSpec, command: CommandSpec, argv: readon
|
|
|
606
611
|
if (spec.kind === "space" && !SPACE_PATTERN.test(text)) throw new UsageError(`--${name} must be c64, drive8, or bank0 to bank255, not ${JSON.stringify(text)}`);
|
|
607
612
|
if (spec.kind === "choice" && !(spec.choices ?? []).includes(text)) throw new UsageError(`--${name} must be one of ${(spec.choices ?? []).join(", ")}, not ${JSON.stringify(text)}`);
|
|
608
613
|
if (spec.kind === "path") {
|
|
609
|
-
if (spec.output === undefined) checkPath(text, `--${name}
|
|
614
|
+
if (spec.output === undefined) checkPath(text, `--${name}`, true);
|
|
610
615
|
else checkOutput(text, `--${name}`, spec.output);
|
|
611
616
|
}
|
|
612
617
|
}
|