@typeonce/ritmo-devtools 0.21.0 → 0.23.0
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/CHANGELOG.md +82 -0
- package/README.md +61 -10
- package/dist/Desync.d.ts +2 -2
- package/dist/Desync.d.ts.map +1 -1
- package/dist/Desync.js +2 -1
- package/dist/Desync.js.map +1 -1
- package/dist/Format.d.ts +8 -1
- package/dist/Format.d.ts.map +1 -1
- package/dist/Format.js +13 -2
- package/dist/Format.js.map +1 -1
- package/dist/Fuzz.d.ts +12 -5
- package/dist/Fuzz.d.ts.map +1 -1
- package/dist/Fuzz.js +8 -1
- package/dist/Fuzz.js.map +1 -1
- package/dist/Replay.d.ts +50 -13
- package/dist/Replay.d.ts.map +1 -1
- package/dist/Replay.js +59 -8
- package/dist/Replay.js.map +1 -1
- package/dist/Session.d.ts +7 -15
- package/dist/Session.d.ts.map +1 -1
- package/dist/Session.js +41 -3
- package/dist/Session.js.map +1 -1
- package/dist/Verify.d.ts +11 -2
- package/dist/Verify.d.ts.map +1 -1
- package/dist/Verify.js +12 -7
- package/dist/Verify.js.map +1 -1
- package/dist/cli.js +19 -6
- package/dist/cli.js.map +1 -1
- package/dist/internal/packageVersions.d.ts +28 -0
- package/dist/internal/packageVersions.d.ts.map +1 -0
- package/dist/internal/packageVersions.js +144 -0
- package/dist/internal/packageVersions.js.map +1 -0
- package/dist/internal/replayStart.d.ts +18 -0
- package/dist/internal/replayStart.d.ts.map +1 -0
- package/dist/internal/replayStart.js +16 -0
- package/dist/internal/replayStart.js.map +1 -0
- package/dist/internal/skillLink.d.ts +1 -9
- package/dist/internal/skillLink.d.ts.map +1 -1
- package/dist/internal/skillLink.js +29 -6
- package/dist/internal/skillLink.js.map +1 -1
- package/dist/internal/version.d.ts +1 -1
- package/dist/internal/version.js +1 -1
- package/package.json +3 -3
- package/src/Desync.ts +3 -2
- package/src/Format.ts +15 -2
- package/src/Fuzz.ts +17 -5
- package/src/Replay.ts +104 -17
- package/src/Session.ts +41 -34
- package/src/Verify.ts +21 -9
- package/src/cli.ts +18 -6
- package/src/internal/packageVersions.ts +150 -0
- package/src/internal/replayStart.ts +16 -0
- package/src/internal/skillLink.ts +31 -8
- package/src/internal/version.ts +1 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The version check for the `ritmo-devtools lint` CLI (Node only): whether
|
|
3
|
+
* every Ritmo package the game installs is the same version. Each package
|
|
4
|
+
* depends on `@typeonce/ritmo` at its own minor, so `@typeonce/ritmo-browser`
|
|
5
|
+
* 0.22 beside `@typeonce/ritmo` 0.23 installs a second, hidden copy of core
|
|
6
|
+
* 0.22 under browser, and the game then gets type errors between the two
|
|
7
|
+
* copies that name neither.
|
|
8
|
+
*
|
|
9
|
+
* It resolves packages as Node does, by walking up from a folder through
|
|
10
|
+
* each `node_modules`, so it reads npm and yarn trees (hoisted or nested,
|
|
11
|
+
* workspaces included) and pnpm's (symlinks into `node_modules/.pnpm`) the
|
|
12
|
+
* same way. Yarn Plug'n'Play installs no `node_modules`: nothing is found
|
|
13
|
+
* and nothing is said.
|
|
14
|
+
*/
|
|
15
|
+
import { readdirSync, readFileSync, realpathSync } from "node:fs"
|
|
16
|
+
import { basename, dirname, join, relative, sep } from "node:path"
|
|
17
|
+
|
|
18
|
+
const scope = "@typeonce"
|
|
19
|
+
|
|
20
|
+
/** The Ritmo packages, all released at one version: `@typeonce/ritmo*` and `@typeonce/oxlint-plugin-ritmo`. */
|
|
21
|
+
const isRitmo = (name: string): boolean => name.startsWith(`${scope}/`) && name.includes("ritmo")
|
|
22
|
+
|
|
23
|
+
/** One installed copy of a Ritmo package. */
|
|
24
|
+
export interface Installed {
|
|
25
|
+
readonly name: string
|
|
26
|
+
readonly version: string
|
|
27
|
+
/** Where it was found, relative to the game's folder: the `node_modules` entry Node resolves it through. */
|
|
28
|
+
readonly path: string
|
|
29
|
+
/** The package it was resolved from, when it is not the copy the game itself resolves. */
|
|
30
|
+
readonly under: string | undefined
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type Versions =
|
|
34
|
+
| { readonly _tag: "Same"; readonly installed: ReadonlyArray<Installed> }
|
|
35
|
+
| { readonly _tag: "Mismatched"; readonly installed: ReadonlyArray<Installed> }
|
|
36
|
+
|
|
37
|
+
const isRecord = (value: unknown): value is Readonly<Record<string, unknown>> => typeof value === "object" && value !== null
|
|
38
|
+
|
|
39
|
+
const readManifest = (folder: string): { readonly name: string; readonly version: string; readonly needs: ReadonlyArray<string> } | undefined => {
|
|
40
|
+
let manifest: unknown
|
|
41
|
+
try {
|
|
42
|
+
manifest = JSON.parse(readFileSync(join(folder, "package.json"), "utf8"))
|
|
43
|
+
} catch {
|
|
44
|
+
return undefined
|
|
45
|
+
}
|
|
46
|
+
if (!isRecord(manifest) || typeof manifest["name"] !== "string" || typeof manifest["version"] !== "string") return undefined
|
|
47
|
+
const needs = new Set<string>()
|
|
48
|
+
for (const field of ["dependencies", "peerDependencies", "optionalDependencies"]) {
|
|
49
|
+
const entries = manifest[field]
|
|
50
|
+
if (isRecord(entries)) for (const name of Object.keys(entries)) if (isRitmo(name)) needs.add(name)
|
|
51
|
+
}
|
|
52
|
+
return { name: manifest["name"], version: manifest["version"], needs: [...needs] }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The `node_modules` folders Node looks in from `folder`, nearest first. */
|
|
56
|
+
const lookups = (folder: string): ReadonlyArray<string> => {
|
|
57
|
+
const found: Array<string> = []
|
|
58
|
+
for (let at = folder; ; at = dirname(at)) {
|
|
59
|
+
if (basename(at) !== "node_modules") found.push(join(at, "node_modules"))
|
|
60
|
+
if (dirname(at) === at) return found
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const realpath = (path: string): string | undefined => {
|
|
65
|
+
try {
|
|
66
|
+
return realpathSync(path)
|
|
67
|
+
} catch {
|
|
68
|
+
return undefined
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Where `name` resolves from `folder`, as Node finds it: the entry it resolves through, and its real path. */
|
|
73
|
+
const resolveFrom = (folder: string, name: string): { readonly entry: string; readonly real: string } | undefined => {
|
|
74
|
+
for (const modules of lookups(folder)) {
|
|
75
|
+
const entry = join(modules, ...name.split("/"))
|
|
76
|
+
const real = realpath(entry)
|
|
77
|
+
if (real !== undefined && readManifest(real) !== undefined) return { entry, real }
|
|
78
|
+
}
|
|
79
|
+
return undefined
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Every Ritmo package name in a `node_modules/@typeonce` the game's folder can see. */
|
|
83
|
+
const visibleNames = (cwd: string): ReadonlyArray<string> => {
|
|
84
|
+
const names = new Set<string>()
|
|
85
|
+
for (const modules of lookups(cwd)) {
|
|
86
|
+
let entries: ReadonlyArray<string>
|
|
87
|
+
try {
|
|
88
|
+
entries = readdirSync(join(modules, scope))
|
|
89
|
+
} catch {
|
|
90
|
+
continue
|
|
91
|
+
}
|
|
92
|
+
for (const entry of entries) if (isRitmo(`${scope}/${entry}`)) names.add(`${scope}/${entry}`)
|
|
93
|
+
}
|
|
94
|
+
return [...names].sort()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Every copy of a Ritmo package installed for the game in `cwd`: the ones the
|
|
99
|
+
* game resolves, then, through each one's dependencies, every other copy one
|
|
100
|
+
* of them resolves (an npm copy nested under it, or pnpm's store folder).
|
|
101
|
+
*/
|
|
102
|
+
export const check = (cwd: string): Versions => {
|
|
103
|
+
const root = realpath(cwd) ?? cwd
|
|
104
|
+
const installed: Array<Installed> = []
|
|
105
|
+
const seen = new Set<string>()
|
|
106
|
+
const queue: Array<{ readonly folder: string; readonly under: string | undefined }> = []
|
|
107
|
+
const add = (found: { readonly entry: string; readonly real: string } | undefined, under: string | undefined) => {
|
|
108
|
+
if (found === undefined || seen.has(found.real)) return
|
|
109
|
+
const manifest = readManifest(found.real)
|
|
110
|
+
if (manifest === undefined) return
|
|
111
|
+
seen.add(found.real)
|
|
112
|
+
installed.push({ name: manifest.name, version: manifest.version, path: relative(root, found.entry).split(sep).join("/"), under })
|
|
113
|
+
queue.push({ folder: found.real, under: manifest.name })
|
|
114
|
+
}
|
|
115
|
+
for (const name of visibleNames(root)) add(resolveFrom(root, name), undefined)
|
|
116
|
+
// Each package resolves its own dependencies from where it really is (pnpm: its store folder).
|
|
117
|
+
for (let next = queue.shift(); next !== undefined; next = queue.shift()) {
|
|
118
|
+
for (const name of readManifest(next.folder)?.needs ?? []) add(resolveFrom(next.folder, name), next.under)
|
|
119
|
+
}
|
|
120
|
+
const versions = new Set(installed.map(({ version }) => version))
|
|
121
|
+
return { _tag: versions.size > 1 ? "Mismatched" : "Same", installed }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const named = ({ name, version }: Installed): string => `${name} ${version}`
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The CLI text for the version check: nothing when every copy is one
|
|
128
|
+
* version, one warning otherwise, naming each package and version and the fix.
|
|
129
|
+
*/
|
|
130
|
+
export const format = (versions: Versions): string => {
|
|
131
|
+
if (versions._tag === "Same") return ""
|
|
132
|
+
const top = versions.installed.filter(({ under }) => under === undefined)
|
|
133
|
+
const nested = versions.installed.filter(({ under }) => under !== undefined)
|
|
134
|
+
// The version the others are measured against: core's, or the most common one.
|
|
135
|
+
const core = top.find(({ name }) => name === `${scope}/ritmo`)
|
|
136
|
+
const counts = new Map<string, number>()
|
|
137
|
+
for (const { version } of top) counts.set(version, (counts.get(version) ?? 0) + 1)
|
|
138
|
+
const reference = core?.version ?? [...counts].sort(([, left], [, right]) => right - left)[0]?.[0] ?? versions.installed[0]!.version
|
|
139
|
+
const off = top.filter(({ version }) => version !== reference)
|
|
140
|
+
const beside = core !== undefined ? named(core) : `the other ${scope} packages at ${reference}`
|
|
141
|
+
const seconds = nested.map((copy) => `a second ${named(copy)} under ${copy.under}`)
|
|
142
|
+
const head = off.length > 0
|
|
143
|
+
? `${off.map(named).join(", ")} ${off.length === 1 ? "is" : "are"} installed with ${beside}${seconds.length > 0 ? ` (and ${seconds.join(", ")})` : ""}`
|
|
144
|
+
: `${seconds.join(", ")} ${seconds.length === 1 ? "is" : "are"} installed beside ${beside}`
|
|
145
|
+
return [
|
|
146
|
+
`warning mismatched-versions ${scope} packages: ${head}: each copy has its own types, so values from one do not type-check against the other`,
|
|
147
|
+
` fix: install the same version of every ${scope} package`,
|
|
148
|
+
...versions.installed.map((copy) => ` ${copy.path} ${named(copy)}`)
|
|
149
|
+
].join("\n")
|
|
150
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a replay's checksums cannot be compared with its recording's, or
|
|
3
|
+
* `undefined` when they can.
|
|
4
|
+
*
|
|
5
|
+
* Tick 0 is the world when the recorder started: the replay starts where the
|
|
6
|
+
* recorded run did. A later start is a save the rolling window moved to, and
|
|
7
|
+
* a save does not hold what the live game still had in flight there (events
|
|
8
|
+
* published and not yet read, each reader's position in `added()`,
|
|
9
|
+
* `changed()`, and the other streams, transient values), so an ordinary game
|
|
10
|
+
* replays to a different checksum from it. Comparing would report a
|
|
11
|
+
* nondeterminism that is not there.
|
|
12
|
+
*/
|
|
13
|
+
export const savedStart = (file: { readonly start: { readonly tick: number } }): string | undefined =>
|
|
14
|
+
file.start.tick === 0
|
|
15
|
+
? undefined
|
|
16
|
+
: `starts from a save at tick ${file.start.tick}: checksums are not compared (a save does not hold events in flight or what each reader had already seen); check determinism with Determinism.check, or with a replay recorded from the recorder's first tick`
|
|
@@ -5,18 +5,41 @@
|
|
|
5
5
|
* version. It is a note: it never fails the lint, since where an agent reads
|
|
6
6
|
* skills from is the project's choice.
|
|
7
7
|
*/
|
|
8
|
-
import { lstatSync, realpathSync } from "node:fs"
|
|
8
|
+
import { existsSync, lstatSync, readdirSync, realpathSync } from "node:fs"
|
|
9
9
|
import { join, sep } from "node:path"
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
const
|
|
11
|
+
/** What an agent misses without each skill `@typeonce/ritmo` ships. A skill not listed here gets {@link missing}. */
|
|
12
|
+
const misses: Readonly<Record<string, string>> = {
|
|
13
13
|
ritmo: "reads the playbooks for this Ritmo version",
|
|
14
14
|
"ritmo-prototype": "can prototype a mechanic with this Ritmo version",
|
|
15
15
|
"ritmo-onboarding": "can teach the game to strangers with this Ritmo version",
|
|
16
|
-
"ritmo-polish": "can polish the game's feel, feedback, and UI with this Ritmo version"
|
|
17
|
-
|
|
16
|
+
"ritmo-polish": "can polish the game's feel, feedback, and UI with this Ritmo version",
|
|
17
|
+
"ritmo-pixel-art": "makes and checks the game's pixel art with `ritmo-tools pixel` and this Ritmo version's principles",
|
|
18
|
+
"ritmo-fx": "makes and reviews the game's pixel art effects with `ritmo-tools fx` for this Ritmo version",
|
|
19
|
+
"ritmo-sounds": "makes and reviews the game's sound effects with `ritmo-tools sound` for this Ritmo version",
|
|
20
|
+
"ritmo-music": "makes and reviews the game's music with `ritmo-tools music` for this Ritmo version"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const missing = (skill: Skill): string => misses[skill] ?? `reads the ${skill} skill of this Ritmo version`
|
|
24
|
+
|
|
25
|
+
export type Skill = string
|
|
18
26
|
|
|
19
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The skills to check: every folder with a `SKILL.md` in the installed
|
|
29
|
+
* `@typeonce/ritmo/skills`, so a skill a later version ships is checked
|
|
30
|
+
* with no change here. Without an installed package to read, the skills
|
|
31
|
+
* listed in {@link misses}.
|
|
32
|
+
*/
|
|
33
|
+
const skillsIn = (cwd: string): ReadonlyArray<Skill> => {
|
|
34
|
+
const installed = join(cwd, "node_modules", "@typeonce", "ritmo", "skills")
|
|
35
|
+
try {
|
|
36
|
+
const found = readdirSync(installed).filter((name) => existsSync(join(installed, name, "SKILL.md"))).sort()
|
|
37
|
+
if (found.length > 0) return found
|
|
38
|
+
} catch {
|
|
39
|
+
// Not installed here: check the skills this version knows.
|
|
40
|
+
}
|
|
41
|
+
return Object.keys(misses).sort()
|
|
42
|
+
}
|
|
20
43
|
|
|
21
44
|
/** The folders agents read skills from, relative to the working directory. */
|
|
22
45
|
const folders = (skill: Skill) => [`.agents/skills/${skill}`, `.claude/skills/${skill}`] as const
|
|
@@ -54,7 +77,7 @@ const checkSkill = (cwd: string, skill: Skill): SkillLink => {
|
|
|
54
77
|
|
|
55
78
|
/** Where each skill is in `cwd`: linked from the installed package, copied in, or missing. */
|
|
56
79
|
export const check = (cwd: string): ReadonlyArray<SkillLink> =>
|
|
57
|
-
(
|
|
80
|
+
skillsIn(cwd).map((skill) => checkSkill(cwd, skill))
|
|
58
81
|
|
|
59
82
|
const formatOne = (link: SkillLink): string => {
|
|
60
83
|
const installed = `node_modules/@typeonce/ritmo/skills/${link.skill}`
|
|
@@ -64,7 +87,7 @@ const formatOne = (link: SkillLink): string => {
|
|
|
64
87
|
case "Missing":
|
|
65
88
|
return `note skill-not-linked ${link.skill}\n`
|
|
66
89
|
+ ` No ${folders(link.skill).join(" or ")} links to ${installed}.\n`
|
|
67
|
-
+ ` Link it (SETUP.md step 2) so your agent ${
|
|
90
|
+
+ ` Link it (SETUP.md step 2) so your agent ${missing(link.skill)}.`
|
|
68
91
|
case "Copied":
|
|
69
92
|
return `note skill-copied ${link.path}\n`
|
|
70
93
|
+ ` This is a copy of the ${link.skill} skill, or a link to somewhere else: it goes stale on the next upgrade.\n`
|
package/src/internal/version.ts
CHANGED