@typeonce/oxlint-plugin-ritmo 0.8.0 → 0.10.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 ADDED
@@ -0,0 +1,65 @@
1
+ # @typeonce/oxlint-plugin-ritmo
2
+
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 388a696: **The Ritmo skill routes each change to a playbook, and simulation code names no renderer type.**
8
+
9
+ - **Breaking: `ritmo/keep-simulation-headless` reports type-only renderer imports** (`import type { Container } from "pixi.js"`, `export type ... from "three"`) and subpath imports of `@typeonce/ritmo-render` and `@typeonce/ritmo-pixi`. A schema that names a renderer type ties the simulation to that renderer. Move the renderer service (a `Descriptor.Service<NodeRegistry.NodeRegistry<Sprite>>()(...)`) and the systems that use it into render code; services are not registered in the schema, so nothing else changes:
10
+
11
+ ```diff
12
+ -// src/game/schema.ts
13
+ -import type { Sprite } from "pixi.js"
14
+ -export const Sprites = Descriptor.Service<NodeRegistry.NodeRegistry<Sprite>>()("Game/Sprites")
15
+ +// src/render/sprites.ts
16
+ +import type { Sprite } from "pixi.js"
17
+ +export const Sprites = Descriptor.Service<NodeRegistry.NodeRegistry<Sprite>>()("Game/Sprites")
18
+ ```
19
+
20
+ - **The skill in `skills/ritmo` now has playbooks**: one per kind of change (a mechanic, content, UI and rendering, a bug fix, a refactor, state and upgrades), each a short list of steps that ends with the check that proves it. `SKILL.md` routes to them and keeps the principles. A game that already links the skill folder gets them on upgrade.
21
+
22
+ ### Patch Changes
23
+
24
+ - 7002f4d: **Everything a game's agent needs now ships with the packages, and `ritmo-devtools lint` reports simulation modules the lint rules miss.**
25
+
26
+ - **Breaking: `ritmo-devtools lint` fails on an uncovered simulation module.** Every module the entry loads that the `ritmo/keep-simulation-headless` override in `.oxlintrc.json` does not cover is reported as `uncovered-simulation-module`, and the command exits 1. Add the module (or its folder) to the simulation override's `"files"`, or stop importing values from it. Modules loaded only inside `lintTarget` are not checked. Requires Node 22.15 or newer (`engines.node` is now `>=22.15`).
27
+ - **An agent skill ships with `@typeonce/ritmo`** in `skills/ritmo/SKILL.md`, for every change: where the docs are, and principles for where a game's code and state belong. Link it into the folder the game's agent reads skills from, for example `ln -s ../../node_modules/@typeonce/ritmo/skills/ritmo .agents/skills/ritmo`. `SETUP.md` in `@typeonce/ritmo` is the one-time setup: the base packages and checks every game uses, the add-ons, and linking the skill.
28
+ - **Every package ships its `CHANGELOG.md`.** The upgrade notes for 0.8.0 and 0.9.0 are in the `@typeonce/ritmo` changelog.
29
+ - **JSDoc corrections.** Examples no longer provide randomness or time as services (use the `Random` resource and `Clock`), the `Command` module example declares its commands, inspector docs state that `added`/`changed` reads report records since the inspector's previous evaluation, and every example uses prefixed names (`"Game/Position"`). Guidance that lived only in the repository's guides (spawn order, `ReadonlyValue` helpers, re-entering a state, `thisTick` and plugin systems, service effects and rollback) is now in the JSDoc.
30
+ - Package READMEs link other packages' READMEs by GitHub URL, so the links work on npm.
31
+
32
+ ## 0.9.0
33
+
34
+ ### Minor Changes
35
+
36
+ - 003b902: **New package: `@typeonce/oxlint-plugin-ritmo`, oxlint rules for Ritmo games.**
37
+
38
+ Types reject wrong calls and devtools lints reject wrong runs; these rules catch the source patterns neither can see. Every report says what goes wrong and the Ritmo API to use instead.
39
+
40
+ Simulation files (listed in an `overrides` entry, so host, render, and unrelated files keep using the platform):
41
+
42
+ - `ritmo/use-clock-for-time`: `Date.now()`, `performance.now()`, `new Date()`, and timers; read the `Clock` resource.
43
+ - `ritmo/use-random-for-randomness`: `Math.random()` and `crypto` randomness; draw with `Random.draw(resources.rng)`.
44
+ - `ritmo/use-ops-for-math`: `Math.sin`, `Math.hypot`, `a ** b`, and the other functions engines approximate; use `Ops` (fixes itself once `Ops` is imported).
45
+ - `ritmo/keep-simulation-headless`: page globals, host I/O, and renderer or UI imports; take input and data from the host, draw in a render schedule.
46
+ - `ritmo/no-infinity-in-simulation-data`: `Infinity` and `NaN` in object literals, which cannot be saved and loaded; use `null`.
47
+
48
+ Every file:
49
+
50
+ - `ritmo/handle-tick-result`: a dropped `runtime.tick(...)`, `tryTick(...)`, or `restore(...)` result.
51
+ - `ritmo/prefix-descriptor-and-system-names`: names without a `Game/` prefix.
52
+ - `ritmo/use-cell-value`: `cell.present ? cell.get() : undefined`; use `cell.value()` (fixes itself).
53
+
54
+ ```jsonc
55
+ {
56
+ "jsPlugins": ["@typeonce/oxlint-plugin-ritmo"],
57
+ "rules": { "ritmo/handle-tick-result": "error" },
58
+ "overrides": [
59
+ {
60
+ "files": ["src/sim/**"],
61
+ "rules": { "ritmo/use-ops-for-math": "error" }
62
+ }
63
+ ]
64
+ }
65
+ ```
package/README.md CHANGED
@@ -14,11 +14,11 @@ Every report says what goes wrong and which Ritmo API to use instead.
14
14
  pnpm add -D @typeonce/oxlint-plugin-ritmo oxlint
15
15
  ```
16
16
 
17
- Released together with [`@typeonce/ritmo`](https://www.npmjs.com/package/@typeonce/ritmo), always with the same version. Requires oxlint 1.86 or newer.
17
+ Released together with [`@typeonce/ritmo`](https://github.com/typeonce-dev/ritmo/blob/main/packages/core/README.md), always with the same version. Requires oxlint 1.86 or newer.
18
18
 
19
19
  ## Setup
20
20
 
21
- Register the plugin and turn the rules on in `.oxlintrc.json`. The simulation rules go in an `overrides` entry that lists the game's simulation files: the code its fixed-step schedules run, which must replay exactly and run headless. Host, render, UI, tool, and unrelated files are not listed, so they keep using the platform freely.
21
+ Register the plugin and turn the rules on in `.oxlintrc.json`. The simulation rules go in an `overrides` entry that lists the game's simulation files: the code its fixed-step schedules run, which must replay exactly and run headless. Host, render, UI, tool, and unrelated files are not listed, so they keep using the platform freely. A file the override does not list gets no simulation checks, so list folders rather than single files, and run `ritmo-devtools lint` from `@typeonce/ritmo-devtools`: it reports every module the simulation loads that the override misses.
22
22
 
23
23
  ```jsonc
24
24
  {
@@ -100,7 +100,7 @@ Catches `Math.random()`, `crypto.getRandomValues()`, and `crypto.randomUUID()`.
100
100
 
101
101
  ### `ritmo/use-ops-for-math`
102
102
 
103
- The spec lets engines approximate `Math.sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `atan2`, `exp`, `expm1`, `log`, `log2`, `log10`, `log1p`, `cbrt`, `pow`, `hypot`, `sinh`, `cosh`, `tanh`, `asinh`, `acosh`, `atanh`, and `a ** b`, and they do: Chrome, Safari, macOS, and Linux disagree in the last bit, and a simulation grows that bit into a different run. [`Ops`](../math/README.md#determinism-across-devices) from `@typeonce/ritmo-math` has each of them as a port that returns the same bits everywhere.
103
+ The spec lets engines approximate `Math.sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `atan2`, `exp`, `expm1`, `log`, `log2`, `log10`, `log1p`, `cbrt`, `pow`, `hypot`, `sinh`, `cosh`, `tanh`, `asinh`, `acosh`, `atanh`, and `a ** b`, and they do: Chrome, Safari, macOS, and Linux disagree in the last bit, and a simulation grows that bit into a different run. [`Ops`](https://github.com/typeonce-dev/ritmo/blob/main/packages/math/README.md#determinism-across-devices) from `@typeonce/ritmo-math` has each of them as a port that returns the same bits everywhere.
104
104
 
105
105
  ```ts
106
106
  const turn = Math.atan2(Math.sin(b - a), Math.cos(b - a)) // reported
@@ -122,7 +122,7 @@ The simulation runs in tests, bots, replays, and on servers, where there is no p
122
122
  |---|---|
123
123
  | Page globals: `window`, `document`, `navigator`, `matchMedia`, ... | Capture input in the host with `Keyboard`, `Pointer`, or `Touch` from `@typeonce/ritmo-browser` and `InputCapture` into a resource that systems read. Pass page state (size, settings) in with `runtime.send(...)` or a resource. |
124
124
  | Host I/O: `localStorage`, `fetch`, `WebSocket`, `location`, ... | Do the I/O in host code and pass the result in with `runtime.send(...)` or a resource. Save and load the world in the host with `runtime.snapshot()` and `runtime.restore(...)`. |
125
- | Renderer and UI imports: `pixi.js`, `three`, `@typeonce/ritmo-render`, `react`, `preact`, ... | Draw from a render schedule in host files: mirror entities into nodes with `RenderSync` and a `NodeRegistry` from `@typeonce/ritmo-render`. Name a renderer type in the schema with `import type`, which is not reported. |
125
+ | Renderer and UI imports, types included: `pixi.js`, `three`, `@typeonce/ritmo-render`, `react`, `preact`, ... | Draw from a render schedule in render code: mirror entities into nodes with `RenderSync` and a `NodeRegistry` from `@typeonce/ritmo-render`, and declare renderer services (a node registry) and their types there; renderer nodes stay in the registry, never in components. The schema and simulation systems name no renderer type, so another renderer can replace this one. |
126
126
 
127
127
  Locals and fields with these names (`term.window`, a `location` parameter) are not globals and are not reported.
128
128
 
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Simulation code runs headless (tests, bots, replays, servers): it never
3
- * touches the page, does host I/O, or imports a renderer. The host feeds it
4
- * input and data, and a render schedule draws it.
3
+ * touches the page, does host I/O, or imports a renderer, not even a type,
4
+ * so another renderer can replace the current one. The host feeds it input
5
+ * and data, and render code draws it.
5
6
  */
6
7
  declare const _default: import("@oxlint/plugins").Rule;
7
8
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"keep-simulation-headless.d.ts","sourceRoot":"","sources":["../../src/rules/keep-simulation-headless.ts"],"names":[],"mappings":"AA6BA;;;;GAIG"}
1
+ {"version":3,"file":"keep-simulation-headless.d.ts","sourceRoot":"","sources":["../../src/rules/keep-simulation-headless.ts"],"names":[],"mappings":"AA6BA;;;;;GAKG"}
@@ -15,11 +15,12 @@ const renderers = new Set([
15
15
  "vue", "svelte", "solid-js", "phaser", "konva", "p5", "babylonjs", "@babylonjs/core"
16
16
  ]);
17
17
  /** Renderer and UI packages, by scope or subpath. */
18
- const rendererPrefixes = ["@pixi/", "@preact/", "@react-three/", "three/", "react-dom/", "preact/", "@babylonjs/", "solid-js/"];
18
+ const rendererPrefixes = ["@typeonce/ritmo-render/", "@typeonce/ritmo-pixi/", "@pixi/", "@preact/", "@react-three/", "three/", "react-dom/", "preact/", "@babylonjs/", "solid-js/"];
19
19
  /**
20
20
  * Simulation code runs headless (tests, bots, replays, servers): it never
21
- * touches the page, does host I/O, or imports a renderer. The host feeds it
22
- * input and data, and a render schedule draws it.
21
+ * touches the page, does host I/O, or imports a renderer, not even a type,
22
+ * so another renderer can replace the current one. The host feeds it input
23
+ * and data, and render code draws it.
23
24
  */
24
25
  export default defineRule({
25
26
  meta: {
@@ -31,7 +32,8 @@ export default defineRule({
31
32
  messages: {
32
33
  page: "`{{name}}` is the page, which tests, bots, and replays do not have. Capture input in the host with `Keyboard`, `Pointer`, or `Touch` from `@typeonce/ritmo-browser` and `InputCapture` into a resource, and read that resource in systems. Pass other page state (size, settings) in from host code with `runtime.send(...)` or a resource.",
33
34
  io: "`{{name}}` is host I/O, which tests, bots, and replays do not have and cannot reproduce. Do the I/O in host code and pass the result in with `runtime.send(...)` or a resource; save and load the world in host code with `runtime.snapshot()` and `runtime.restore(...)`.",
34
- renderer: "The simulation imports `{{source}}`, a renderer or UI package, so it no longer runs headless. Draw from a render schedule in host files: mirror entities into nodes with `RenderSync` and a `NodeRegistry` from `@typeonce/ritmo-render`. To name a renderer type in the schema (a service), use `import type`, which does not run."
35
+ renderer: "The simulation imports `{{source}}`, a renderer or UI package, so it no longer runs headless. Draw from a render schedule in render code: mirror entities into nodes with `RenderSync` and a `NodeRegistry` from `@typeonce/ritmo-render`, and declare its services (a node registry) there. Renderer nodes stay in the registry, never in components.",
36
+ rendererType: "The simulation names a type from `{{source}}`, a renderer or UI package, so it is tied to that renderer and another one cannot replace it. Declare renderer services (a node registry) and their types in render code; services are not registered in the schema. Renderer nodes stay in the registry, never in components."
35
37
  },
36
38
  schema: [
37
39
  {
@@ -53,22 +55,20 @@ export default defineRule({
53
55
  const isRenderer = (source) => renderers.has(source) ||
54
56
  rendererPrefixes.some((prefix) => source.startsWith(prefix)) ||
55
57
  extra.some((entry) => (entry.endsWith("/") ? source.startsWith(entry) : source === entry || source.startsWith(`${entry}/`)));
56
- const checkSource = (node, source) => {
58
+ const checkSource = (node, source, onlyTypes = false) => {
57
59
  if (source !== undefined && isRenderer(source))
58
- context.report({ node, messageId: "renderer", data: { source } });
60
+ context.report({ node, messageId: onlyTypes ? "rendererType" : "renderer", data: { source } });
59
61
  };
60
62
  return {
61
63
  ImportDeclaration(node) {
62
- if (!importsOnlyTypes(node))
63
- checkSource(node, node.source.value);
64
+ checkSource(node, node.source.value, importsOnlyTypes(node));
64
65
  },
65
66
  ExportNamedDeclaration(node) {
66
- if (node.source !== null && node.exportKind !== "type")
67
- checkSource(node, node.source.value);
67
+ if (node.source !== null)
68
+ checkSource(node, node.source.value, node.exportKind === "type");
68
69
  },
69
70
  ExportAllDeclaration(node) {
70
- if (node.exportKind !== "type")
71
- checkSource(node, node.source.value);
71
+ checkSource(node, node.source.value, node.exportKind === "type");
72
72
  },
73
73
  ImportExpression(node) {
74
74
  checkSource(node, stringValue(node.source));
@@ -1 +1 @@
1
- {"version":3,"file":"keep-simulation-headless.js","sourceRoot":"","sources":["../../src/rules/keep-simulation-headless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAE9F,mDAAmD;AACnD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC;IACnB,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,kBAAkB,EAAE,kBAAkB;IACjG,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ;CACrG,CAAC,CAAA;AAEF,8DAA8D;AAC9D,MAAM,EAAE,GAAG,IAAI,GAAG,CAAC;IACjB,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS;CACtI,CAAC,CAAA;AAEF,+CAA+C;AAC/C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,wBAAwB,EAAE,sBAAsB,EAAE,SAAS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,KAAK,EAAE,IAAI,CAAC,UAAU,KAAK,MAAM,CAAC,CAAA;YAClE,CAAC;YACD,gBAAgB,CAAC,IAAI;gBACnB,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;YAC7C,CAAC;YACD,UAAU,CAAC,IAAI;gBACb,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;gBAChF,IAAI,IAAI,KAAK,SAAS;oBAAE,OAAM;gBAC9B,0CAA0C;gBAC1C,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,iBAAiB;oBAAE,OAAM;gBACxF,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC;oBAAE,OAAM;gBAC7C,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;YACtE,CAAC;SACF,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeonce/oxlint-plugin-ritmo",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Oxlint rules for Ritmo games: deterministic, headless simulation code and checked runtime results",
5
5
  "author": "Sandro Maglione",
6
6
  "license": "MIT",
@@ -27,6 +27,7 @@
27
27
  "src/**/*.ts",
28
28
  "dist",
29
29
  "README.md",
30
+ "CHANGELOG.md",
30
31
  "LICENSE"
31
32
  ],
32
33
  "exports": {
@@ -21,7 +21,7 @@ const renderers = new Set([
21
21
  ])
22
22
 
23
23
  /** Renderer and UI packages, by scope or subpath. */
24
- const rendererPrefixes = ["@pixi/", "@preact/", "@react-three/", "three/", "react-dom/", "preact/", "@babylonjs/", "solid-js/"]
24
+ const rendererPrefixes = ["@typeonce/ritmo-render/", "@typeonce/ritmo-pixi/", "@pixi/", "@preact/", "@react-three/", "three/", "react-dom/", "preact/", "@babylonjs/", "solid-js/"]
25
25
 
26
26
  interface Options {
27
27
  readonly packages?: ReadonlyArray<string>
@@ -29,8 +29,9 @@ interface Options {
29
29
 
30
30
  /**
31
31
  * Simulation code runs headless (tests, bots, replays, servers): it never
32
- * touches the page, does host I/O, or imports a renderer. The host feeds it
33
- * input and data, and a render schedule draws it.
32
+ * touches the page, does host I/O, or imports a renderer, not even a type,
33
+ * so another renderer can replace the current one. The host feeds it input
34
+ * and data, and render code draws it.
34
35
  */
35
36
  export default defineRule({
36
37
  meta: {
@@ -45,7 +46,9 @@ export default defineRule({
45
46
  io:
46
47
  "`{{name}}` is host I/O, which tests, bots, and replays do not have and cannot reproduce. Do the I/O in host code and pass the result in with `runtime.send(...)` or a resource; save and load the world in host code with `runtime.snapshot()` and `runtime.restore(...)`.",
47
48
  renderer:
48
- "The simulation imports `{{source}}`, a renderer or UI package, so it no longer runs headless. Draw from a render schedule in host files: mirror entities into nodes with `RenderSync` and a `NodeRegistry` from `@typeonce/ritmo-render`. To name a renderer type in the schema (a service), use `import type`, which does not run."
49
+ "The simulation imports `{{source}}`, a renderer or UI package, so it no longer runs headless. Draw from a render schedule in render code: mirror entities into nodes with `RenderSync` and a `NodeRegistry` from `@typeonce/ritmo-render`, and declare its services (a node registry) there. Renderer nodes stay in the registry, never in components.",
50
+ rendererType:
51
+ "The simulation names a type from `{{source}}`, a renderer or UI package, so it is tied to that renderer and another one cannot replace it. Declare renderer services (a node registry) and their types in render code; services are not registered in the schema. Renderer nodes stay in the registry, never in components."
49
52
  },
50
53
  schema: [
51
54
  {
@@ -68,18 +71,18 @@ export default defineRule({
68
71
  renderers.has(source) ||
69
72
  rendererPrefixes.some((prefix) => source.startsWith(prefix)) ||
70
73
  extra.some((entry) => (entry.endsWith("/") ? source.startsWith(entry) : source === entry || source.startsWith(`${entry}/`)))
71
- const checkSource = (node: ESTree.Node, source: string | undefined): void => {
72
- if (source !== undefined && isRenderer(source)) context.report({ node, messageId: "renderer", data: { source } })
74
+ const checkSource = (node: ESTree.Node, source: string | undefined, onlyTypes = false): void => {
75
+ if (source !== undefined && isRenderer(source)) context.report({ node, messageId: onlyTypes ? "rendererType" : "renderer", data: { source } })
73
76
  }
74
77
  return {
75
78
  ImportDeclaration(node) {
76
- if (!importsOnlyTypes(node)) checkSource(node, node.source.value)
79
+ checkSource(node, node.source.value, importsOnlyTypes(node))
77
80
  },
78
81
  ExportNamedDeclaration(node) {
79
- if (node.source !== null && node.exportKind !== "type") checkSource(node, node.source.value)
82
+ if (node.source !== null) checkSource(node, node.source.value, node.exportKind === "type")
80
83
  },
81
84
  ExportAllDeclaration(node) {
82
- if (node.exportKind !== "type") checkSource(node, node.source.value)
85
+ checkSource(node, node.source.value, node.exportKind === "type")
83
86
  },
84
87
  ImportExpression(node) {
85
88
  checkSource(node, stringValue(node.source))