一键导入
migrate-state
Safely evolve GameState shape — bump stateVersion, write a pure migration function, update replay fixtures and snapshot baselines
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Safely evolve GameState shape — bump stateVersion, write a pure migration function, update replay fixtures and snapshot baselines
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Write cutting-edge and modern native CSS. Apply this skill whenever writing, reviewing, or refactoring CSS for components, layouts, design systems, or theming, even if the user doesn't say "modern CSS" explicitly. Covers a self-contained design-token scale (color, size, shadow, ease, type), cascade layers (@layer), @scope for component isolation (donut scopes, :scope specificity, scoping proximity), container queries, :has(), OKLCH/color-mix, native nesting, subgrid, fluid typography via clamp(), scroll-driven animations, logical properties, and concrete native replacements for SCSS mixins, maps, and variables.
Apply this skill whenever the task involves web security: writing or auditing HTTP security headers, configuring CSP, CORS, HSTS, or Permissions-Policy, sanitising untrusted HTML (Sanitizer API / DOMPurify), implementing Trusted Types to prevent DOM-XSS, setting up the Reporting API to capture CSP/COEP/deprecation violations, hardening cookies (SameSite, HttpOnly, Secure, Partitioned), implementing WebAuthn / Credential Management, using Web Crypto for client-side cryptography, or auditing code for XSS, CSRF, clickjacking, MIME-sniffing, mixed content, or cross-origin data leakage. Triggers on keywords: XSS, CSRF, CSP, CORS, HSTS, SameSite, innerHTML, eval, Trusted Types, Sanitizer, ReportingObserver, WebAuthn, cross-origin, clickjacking, Content-Security-Policy, Referrer-Policy, Permissions-Policy, subresource integrity, cookie security, secure context, same-origin, mixed content.
Patterns for invoking the GitHub CLI (gh) from agents. Covers structured output, pagination, repo targeting, search vs list, gh api fallback.
Audit and update durable architecture guidance after a cross-layer implementation, file move, package boundary change, coverage config change, or SDTE feature. Use when agent needs to reconcile AGENTS.md, package AGENTS.md files, local .agents/skills, older specs, dynamic imports, and test or coverage configuration with the architecture that was actually implemented.
Run the Spec → Design → Tasks → Execution workflow for non-trivial work — produces /specs/<feature>/{spec,design,tasks}.md, drives atomic per-task execution, and ends with a Review phase. Invoke when starting a new package, new game system, GameState shape change, or any change touching > 3 files or crossing a layer boundary.
Best practices for building scalable plain Web Components without turning custom elements into “god objects”. Provides patterns that keep Web Components modular, reusable, maintainable, and focused on UI concerns.
| name | migrate-state |
| description | Safely evolve GameState shape — bump stateVersion, write a pure migration function, update replay fixtures and snapshot baselines |
Use whenever GameState shape changes (adding, removing, or renaming fields).
Skipping this process silently breaks replay tests and deterministic run snapshots.
Every structural change to GameState requires:
stateVersion incrementNever change field types or names without bumping stateVersion.
stateVersion if absentGameState must have:
export type GameState = Readonly<{
stateVersion: number;
seed: number;
prng: PrngState;
frameIndex: number;
/* … */
}>;
createInitialState must set stateVersion: CURRENT_STATE_VERSION from
packages/game/lib/core/constants.ts.
stateVersionIn packages/game/lib/core/types.ts, bump the version constant or literal and update
all places that construct a literal GameState (tests, createInitialState, factories).
export const CURRENT_STATE_VERSION = 2; // was 1
If old states remain supported, create or update packages/game/lib/state/migrations.ts:
import type { GameState } from "../core/types.ts";
/** V1 shape — keep as a local type, do not export */
type GameStateV1 = Omit<GameState, "newField"> & { stateVersion: 1 };
export const migrateV1toV2 = (old: GameStateV1): GameState => ({
...old,
stateVersion: 2,
newField: deriveDefaultValue(old),
});
Rules for migration functions:
If the active spec intentionally drops old-state compatibility, delete stale migration code and update parser/tests so old versions fail explicitly.
After the migration, replay fixture and snapshot tests will fail because the state shape changed. Update committed JSON baselines:
pnpm --filter @bruff/game run test
Review the diff before committing — the snapshot changes should exactly match the new fields you added.
Replay fixtures live in packages/game/tests/fixtures/*.json; final-state snapshots live in packages/game/tests/snapshots/*.json. If the fixture format changes, update ReplayFixture, ReplayError, parseReplayFixture, and runReplay tests together.
If multiple migrations exist, compose them in order:
export const migrateToLatest = (
raw: unknown,
): Result<GameState, MigrationError> => {
// version guard
if (!isGameStateV1(raw)) return error({ type: "unrecognised-state-shape" });
const v2 = migrateV1toV2(raw);
// const v3 = migrateV2toV3(v2);
return ok(v2);
};
stateVersion incremented in GameState type and CURRENT_STATE_VERSIONcreateInitialState produces new stateVersionseed, prng, and frameIndex remain present and deterministicResult values