@dxos/plugin-chess 0.10.0 → 0.11.1

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.
Files changed (163) hide show
  1. package/dist/lib/ChessPlugin.mjs +2 -0
  2. package/dist/lib/ChessPlugin.node.mjs +19 -0
  3. package/dist/lib/ChessPlugin.node.mjs.map +1 -0
  4. package/dist/lib/ChessPlugin.workerd.mjs +15 -0
  5. package/dist/lib/ChessPlugin.workerd.mjs.map +1 -0
  6. package/dist/lib/capabilities/node.mjs +8 -0
  7. package/dist/lib/capabilities/node.mjs.map +1 -0
  8. package/dist/lib/capabilities.mjs +9 -0
  9. package/dist/lib/capabilities.mjs.map +1 -0
  10. package/dist/lib/chunk-ChessArticle.mjs +89 -0
  11. package/dist/lib/chunk-ChessArticle.mjs.map +1 -0
  12. package/dist/lib/chunk-ChessCard.mjs +25 -0
  13. package/dist/lib/chunk-ChessCard.mjs.map +1 -0
  14. package/dist/lib/chunk-ChessPlugin.mjs +26 -0
  15. package/dist/lib/chunk-ChessPlugin.mjs.map +1 -0
  16. package/dist/lib/chunk-game-variant.mjs +34 -0
  17. package/dist/lib/chunk-game-variant.mjs.map +1 -0
  18. package/dist/lib/chunk-meta.mjs +29 -0
  19. package/dist/lib/chunk-meta.mjs.map +1 -0
  20. package/dist/lib/chunk-move.mjs +23 -0
  21. package/dist/lib/chunk-move.mjs.map +1 -0
  22. package/dist/lib/chunk-operation-handler.mjs +11 -0
  23. package/dist/lib/chunk-operation-handler.mjs.map +1 -0
  24. package/dist/lib/chunk-play.mjs +32 -0
  25. package/dist/lib/chunk-play.mjs.map +1 -0
  26. package/dist/lib/chunk-print.mjs +18 -0
  27. package/dist/lib/chunk-print.mjs.map +1 -0
  28. package/dist/lib/chunk-rebuild-position-index.mjs +126 -0
  29. package/dist/lib/chunk-rebuild-position-index.mjs.map +1 -0
  30. package/dist/lib/chunk-skill-definition.mjs +10 -0
  31. package/dist/lib/chunk-skill-definition.mjs.map +1 -0
  32. package/dist/lib/{neutral/chunk-IKWULCKX.mjs → chunk-skills.mjs} +14 -20
  33. package/dist/lib/chunk-skills.mjs.map +1 -0
  34. package/dist/lib/chunk-types.mjs +202 -0
  35. package/dist/lib/chunk-types.mjs.map +1 -0
  36. package/dist/lib/components.mjs +224 -0
  37. package/dist/lib/components.mjs.map +1 -0
  38. package/dist/lib/containers.mjs +8 -0
  39. package/dist/lib/containers.mjs.map +1 -0
  40. package/dist/lib/index.mjs +4 -0
  41. package/dist/lib/meta.mjs +2 -0
  42. package/dist/lib/operations.mjs +7 -0
  43. package/dist/lib/operations.mjs.map +1 -0
  44. package/dist/lib/plugin.mjs +9 -0
  45. package/dist/lib/plugin.mjs.map +1 -0
  46. package/dist/lib/skills.mjs +2 -0
  47. package/dist/lib/testing.mjs +2 -0
  48. package/dist/lib/translations.mjs +51 -0
  49. package/dist/lib/translations.mjs.map +1 -0
  50. package/dist/lib/types.mjs +2 -0
  51. package/dist/types/src/capabilities/game-variant.d.ts +1 -1
  52. package/dist/types/src/capabilities/node.d.ts +5 -0
  53. package/dist/types/src/capabilities/node.d.ts.map +1 -0
  54. package/dist/types/src/capabilities/operation-handler.d.ts +1 -1
  55. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +52 -4
  56. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -1
  57. package/dist/types/src/components/Chessboard/types.d.ts +1 -1
  58. package/dist/types/src/components/Chessboard/types.d.ts.map +1 -1
  59. package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts +4 -1
  60. package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts.map +1 -1
  61. package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts +52 -4
  62. package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts.map +1 -1
  63. package/dist/types/src/containers/ChessCard/ChessCard.d.ts +4 -1
  64. package/dist/types/src/containers/ChessCard/ChessCard.d.ts.map +1 -1
  65. package/dist/types/src/internal/position-index.d.ts +34 -0
  66. package/dist/types/src/internal/position-index.d.ts.map +1 -0
  67. package/dist/types/src/operations/index.d.ts.map +1 -1
  68. package/dist/types/src/operations/move.d.ts.map +1 -1
  69. package/dist/types/src/operations/play.d.ts.map +1 -1
  70. package/dist/types/src/operations/rebuild-position-index.d.ts +4 -0
  71. package/dist/types/src/operations/rebuild-position-index.d.ts.map +1 -0
  72. package/dist/types/src/operations/rebuild-position-index.test.d.ts +2 -0
  73. package/dist/types/src/operations/rebuild-position-index.test.d.ts.map +1 -0
  74. package/dist/types/src/translations.d.ts +52 -4
  75. package/dist/types/src/translations.d.ts.map +1 -1
  76. package/dist/types/src/types/ChessOperation.d.ts +11 -3
  77. package/dist/types/src/types/ChessOperation.d.ts.map +1 -1
  78. package/dist/types/src/types/ChessPositionIndex.d.ts +50 -0
  79. package/dist/types/src/types/ChessPositionIndex.d.ts.map +1 -0
  80. package/dist/types/src/types/PlayerReview.d.ts +23 -0
  81. package/dist/types/src/types/PlayerReview.d.ts.map +1 -0
  82. package/dist/types/src/types/index.d.ts +2 -0
  83. package/dist/types/src/types/index.d.ts.map +1 -1
  84. package/dist/types/tsconfig.tsbuildinfo +1 -1
  85. package/dx.config.ts +1 -1
  86. package/package.json +50 -43
  87. package/src/ChessPlugin.node.ts +2 -2
  88. package/src/ChessPlugin.tsx +2 -2
  89. package/src/ChessPlugin.workerd.ts +2 -2
  90. package/src/capabilities/node.ts +16 -0
  91. package/src/components/Chessboard/Info.tsx +2 -2
  92. package/src/components/Chessboard/types.ts +1 -1
  93. package/src/containers/ChessArticle/ChessArticle.stories.tsx +2 -2
  94. package/src/containers/ChessArticle/ChessArticle.tsx +19 -13
  95. package/src/containers/ChessCard/ChessCard.stories.tsx +2 -2
  96. package/src/containers/ChessCard/ChessCard.tsx +2 -0
  97. package/src/internal/position-index.ts +148 -0
  98. package/src/operations/index.ts +1 -0
  99. package/src/operations/move.ts +1 -2
  100. package/src/operations/play.ts +1 -2
  101. package/src/operations/rebuild-position-index.test.ts +118 -0
  102. package/src/operations/rebuild-position-index.ts +73 -0
  103. package/src/translations.ts +19 -1
  104. package/src/types/ChessOperation.ts +25 -4
  105. package/src/types/ChessPositionIndex.ts +53 -0
  106. package/src/types/PlayerReview.ts +48 -0
  107. package/src/types/index.ts +2 -0
  108. package/dist/lib/neutral/ChessArticle-MPRT54KQ.mjs +0 -89
  109. package/dist/lib/neutral/ChessArticle-MPRT54KQ.mjs.map +0 -7
  110. package/dist/lib/neutral/ChessCard-VJ3I6MIB.mjs +0 -24
  111. package/dist/lib/neutral/ChessCard-VJ3I6MIB.mjs.map +0 -7
  112. package/dist/lib/neutral/ChessPlugin.mjs +0 -10
  113. package/dist/lib/neutral/ChessPlugin.mjs.map +0 -7
  114. package/dist/lib/neutral/ChessPlugin.node.mjs +0 -23
  115. package/dist/lib/neutral/ChessPlugin.node.mjs.map +0 -7
  116. package/dist/lib/neutral/ChessPlugin.workerd.mjs +0 -21
  117. package/dist/lib/neutral/ChessPlugin.workerd.mjs.map +0 -7
  118. package/dist/lib/neutral/capabilities/index.mjs +0 -13
  119. package/dist/lib/neutral/capabilities/index.mjs.map +0 -7
  120. package/dist/lib/neutral/chunk-AMXVX7V2.mjs +0 -8
  121. package/dist/lib/neutral/chunk-AMXVX7V2.mjs.map +0 -7
  122. package/dist/lib/neutral/chunk-DXIET5G2.mjs +0 -148
  123. package/dist/lib/neutral/chunk-DXIET5G2.mjs.map +0 -7
  124. package/dist/lib/neutral/chunk-EXZ3XFEG.mjs +0 -41
  125. package/dist/lib/neutral/chunk-EXZ3XFEG.mjs.map +0 -7
  126. package/dist/lib/neutral/chunk-IKWULCKX.mjs.map +0 -7
  127. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +0 -10
  128. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +0 -7
  129. package/dist/lib/neutral/chunk-YZTKZ5F7.mjs +0 -42
  130. package/dist/lib/neutral/chunk-YZTKZ5F7.mjs.map +0 -7
  131. package/dist/lib/neutral/components/index.mjs +0 -240
  132. package/dist/lib/neutral/components/index.mjs.map +0 -7
  133. package/dist/lib/neutral/containers/index.mjs +0 -11
  134. package/dist/lib/neutral/containers/index.mjs.map +0 -7
  135. package/dist/lib/neutral/game-variant-ZLPEN2QK.mjs +0 -41
  136. package/dist/lib/neutral/game-variant-ZLPEN2QK.mjs.map +0 -7
  137. package/dist/lib/neutral/index.mjs +0 -18
  138. package/dist/lib/neutral/index.mjs.map +0 -7
  139. package/dist/lib/neutral/meta.json +0 -1
  140. package/dist/lib/neutral/meta.mjs +0 -8
  141. package/dist/lib/neutral/meta.mjs.map +0 -7
  142. package/dist/lib/neutral/move-UMDTQST4.mjs +0 -37
  143. package/dist/lib/neutral/move-UMDTQST4.mjs.map +0 -7
  144. package/dist/lib/neutral/operation-handler-EKZKFQUG.mjs +0 -13
  145. package/dist/lib/neutral/operation-handler-EKZKFQUG.mjs.map +0 -7
  146. package/dist/lib/neutral/operations/index.mjs +0 -8
  147. package/dist/lib/neutral/operations/index.mjs.map +0 -7
  148. package/dist/lib/neutral/play-7XTJZ4N6.mjs +0 -46
  149. package/dist/lib/neutral/play-7XTJZ4N6.mjs.map +0 -7
  150. package/dist/lib/neutral/plugin.mjs +0 -16
  151. package/dist/lib/neutral/plugin.mjs.map +0 -7
  152. package/dist/lib/neutral/print-JR4VB3UX.mjs +0 -29
  153. package/dist/lib/neutral/print-JR4VB3UX.mjs.map +0 -7
  154. package/dist/lib/neutral/skill-definition-ZGQBUE4R.mjs +0 -15
  155. package/dist/lib/neutral/skill-definition-ZGQBUE4R.mjs.map +0 -7
  156. package/dist/lib/neutral/skills/index.mjs +0 -8
  157. package/dist/lib/neutral/skills/index.mjs.map +0 -7
  158. package/dist/lib/neutral/testing.mjs +0 -8
  159. package/dist/lib/neutral/testing.mjs.map +0 -7
  160. package/dist/lib/neutral/translations.mjs +0 -39
  161. package/dist/lib/neutral/translations.mjs.map +0 -7
  162. package/dist/lib/neutral/types/index.mjs +0 -10
  163. package/dist/lib/neutral/types/index.mjs.map +0 -7
@@ -0,0 +1,2 @@
1
+ import { t as ChessPlugin } from "./chunk-ChessPlugin.mjs";
2
+ export { ChessPlugin, ChessPlugin as default };
@@ -0,0 +1,19 @@
1
+ import { Chess, ChessPositionIndex, PlayerReview } from "#types";
2
+ import { Plugin } from "@dxos/app-framework";
3
+ import { AppPlugin } from "@dxos/app-toolkit";
4
+ import { OperationHandler, SkillDefinition } from "#capabilities";
5
+ import { meta } from "#meta";
6
+ //#region src/ChessPlugin.node.ts
7
+ /**
8
+ * Headless variant of ChessPlugin (no React surfaces / GameVariant).
9
+ * Used in node contexts (CLI, agents) where rendering is unavailable.
10
+ */
11
+ var ChessPlugin = Plugin.define(meta).pipe(AppPlugin.addSchemaModule({ schema: [
12
+ Chess.State,
13
+ ChessPositionIndex.PositionIndex,
14
+ PlayerReview.Review
15
+ ] }), AppPlugin.addSkillDefinitionModule({ activate: SkillDefinition }), AppPlugin.addOperationHandlerModule({ activate: OperationHandler }), Plugin.make);
16
+ //#endregion
17
+ export { ChessPlugin, ChessPlugin as default };
18
+
19
+ //# sourceMappingURL=ChessPlugin.node.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChessPlugin.node.mjs","names":[],"sources":["../../src/ChessPlugin.node.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\nimport { AppPlugin } from '@dxos/app-toolkit';\n\nimport { OperationHandler, SkillDefinition } from '#capabilities';\nimport { meta } from '#meta';\nimport { Chess, ChessPositionIndex, PlayerReview } from '#types';\n\n/**\n * Headless variant of ChessPlugin (no React surfaces / GameVariant).\n * Used in node contexts (CLI, agents) where rendering is unavailable.\n */\nexport const ChessPlugin = Plugin.define(meta).pipe(\n AppPlugin.addSchemaModule({ schema: [Chess.State, ChessPositionIndex.PositionIndex, PlayerReview.Review] }),\n AppPlugin.addSkillDefinitionModule({ activate: SkillDefinition }),\n AppPlugin.addOperationHandlerModule({ activate: OperationHandler }),\n Plugin.make,\n);\n\nexport default ChessPlugin;\n"],"mappings":";;;;;;;;;;AAeA,IAAa,cAAc,OAAO,OAAO,IAAI,CAAC,CAAC,KAC7C,UAAU,gBAAgB,EAAE,QAAQ;CAAC,MAAM;CAAO,mBAAmB;CAAe,aAAa;AAAM,EAAE,CAAC,GAC1G,UAAU,yBAAyB,EAAE,UAAU,gBAAgB,CAAC,GAChE,UAAU,0BAA0B,EAAE,UAAU,iBAAiB,CAAC,GAClE,OAAO,IACT"}
@@ -0,0 +1,15 @@
1
+ import { Chess, ChessPositionIndex, PlayerReview } from "#types";
2
+ import { Plugin } from "@dxos/app-framework";
3
+ import { AppPlugin } from "@dxos/app-toolkit";
4
+ import { OperationHandler } from "#capabilities";
5
+ import { meta } from "#meta";
6
+ //#region src/ChessPlugin.workerd.ts
7
+ var ChessPlugin = Plugin.define(meta).pipe(AppPlugin.addOperationHandlerModule({ activate: OperationHandler }), AppPlugin.addSchemaModule({ schema: [
8
+ Chess.State,
9
+ ChessPositionIndex.PositionIndex,
10
+ PlayerReview.Review
11
+ ] }), Plugin.make);
12
+ //#endregion
13
+ export { ChessPlugin, ChessPlugin as default };
14
+
15
+ //# sourceMappingURL=ChessPlugin.workerd.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChessPlugin.workerd.mjs","names":[],"sources":["../../src/ChessPlugin.workerd.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\nimport { AppPlugin } from '@dxos/app-toolkit';\n\nimport { OperationHandler } from '#capabilities';\nimport { meta } from '#meta';\nimport { Chess, ChessPositionIndex, PlayerReview } from '#types';\n\nexport const ChessPlugin = Plugin.define(meta).pipe(\n AppPlugin.addOperationHandlerModule({ activate: OperationHandler }),\n AppPlugin.addSchemaModule({ schema: [Chess.State, ChessPositionIndex.PositionIndex, PlayerReview.Review] }),\n Plugin.make,\n);\n\nexport default ChessPlugin;\n"],"mappings":";;;;;;AAWA,IAAa,cAAc,OAAO,OAAO,IAAI,CAAC,CAAC,KAC7C,UAAU,0BAA0B,EAAE,UAAU,iBAAiB,CAAC,GAClE,UAAU,gBAAgB,EAAE,QAAQ;CAAC,MAAM;CAAO,mBAAmB;CAAe,aAAa;AAAM,EAAE,CAAC,GAC1G,OAAO,IACT"}
@@ -0,0 +1,8 @@
1
+ import { Capability } from "@dxos/app-framework";
2
+ //#region src/capabilities/node.ts
3
+ var SkillDefinition = Capability.lazy("SkillDefinition", () => import("../chunk-skill-definition.mjs"));
4
+ var OperationHandler = Capability.lazy("OperationHandler", () => import("../chunk-operation-handler.mjs"));
5
+ //#endregion
6
+ export { OperationHandler, SkillDefinition };
7
+
8
+ //# sourceMappingURL=node.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.mjs","names":[],"sources":["../../../src/capabilities/node.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { Capability } from '@dxos/app-framework';\nimport type { OperationHandlerSet } from '@dxos/compute';\n\n// The capabilities `ChessPlugin.node` activates, and only those. `Capability.lazy` defers the\n// import at runtime but a bundler still walks it, so listing the React surfaces here would pull\n// the plugin's components into every node and bun build.\n\nexport const SkillDefinition = Capability.lazy('SkillDefinition', () => import('./skill-definition'));\nexport const OperationHandler = Capability.lazy<OperationHandlerSet.OperationHandlerSet>(\n 'OperationHandler',\n () => import('./operation-handler'),\n);\n"],"mappings":";;AAWA,IAAa,kBAAkB,WAAW,KAAK,yBAAyB,OAAO,gCAAqB;AACpG,IAAa,mBAAmB,WAAW,KACzC,0BACM,OAAO,iCACf"}
@@ -0,0 +1,9 @@
1
+ import { Capability } from "@dxos/app-framework";
2
+ //#region src/capabilities/index.ts
3
+ var SkillDefinition = Capability.lazy("SkillDefinition", () => import("./chunk-skill-definition.mjs"));
4
+ var GameVariant = Capability.lazy("GameVariant", () => import("./chunk-game-variant.mjs"));
5
+ var OperationHandler = Capability.lazy("OperationHandler", () => import("./chunk-operation-handler.mjs"));
6
+ //#endregion
7
+ export { GameVariant, OperationHandler, SkillDefinition };
8
+
9
+ //# sourceMappingURL=capabilities.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.mjs","names":[],"sources":["../../src/capabilities/index.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Capability } from '@dxos/app-framework';\nimport type { OperationHandlerSet } from '@dxos/compute';\n\nexport const SkillDefinition = Capability.lazy('SkillDefinition', () => import('./skill-definition'));\nexport const GameVariant = Capability.lazy('GameVariant', () => import('./game-variant'));\nexport const OperationHandler = Capability.lazy<OperationHandlerSet.OperationHandlerSet>(\n 'OperationHandler',\n () => import('./operation-handler'),\n);\n"],"mappings":";;AAOA,IAAa,kBAAkB,WAAW,KAAK,yBAAyB,OAAO,+BAAqB;AACpG,IAAa,cAAc,WAAW,KAAK,qBAAqB,OAAO,2BAAiB;AACxF,IAAa,mBAAmB,WAAW,KACzC,0BACM,OAAO,gCACf"}
@@ -0,0 +1,89 @@
1
+ import { Chess } from "#types";
2
+ import { Chess as Chess$1 } from "chess.js";
3
+ import { Obj } from "@dxos/echo";
4
+ import { meta } from "#meta";
5
+ import { useCallback, useRef, useState } from "react";
6
+ import { useObject } from "@dxos/echo-react";
7
+ import { Panel, Toolbar, useTranslation } from "@dxos/react-ui";
8
+ import { mx } from "@dxos/ui-theme";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ import { AppSurface } from "@dxos/app-toolkit/ui";
11
+ import { Chessboard } from "#components";
12
+ //#region src/containers/ChessArticle/ChessArticle.tsx
13
+ var ChessArticle = ({ role, variant }) => {
14
+ const { t } = useTranslation(meta.profile.key);
15
+ const [orientation, setOrientation] = useState("white");
16
+ const [showInfo, setShowInfo] = useState(true);
17
+ const controller = useRef(null);
18
+ const handleSelect = useCallback((index) => {
19
+ controller.current?.setMoveNumber(index);
20
+ }, []);
21
+ const state = Obj.instanceOf(Chess.State, variant) ? variant : void 0;
22
+ const [pgn] = useObject(state, "pgn");
23
+ const [fen] = useObject(state, "fen");
24
+ const isGameOver = (() => {
25
+ if (!pgn && !fen) return false;
26
+ try {
27
+ const chess = new Chess$1();
28
+ if (pgn) chess.loadPgn(pgn);
29
+ else if (fen) chess.load(fen);
30
+ return chess.isGameOver();
31
+ } catch {
32
+ return false;
33
+ }
34
+ })();
35
+ const handleNewGame = useCallback(() => {
36
+ if (!state) return;
37
+ Obj.update(state, (state) => {
38
+ state.pgn = void 0;
39
+ state.fen = void 0;
40
+ });
41
+ }, [state]);
42
+ if (!state) return null;
43
+ return /* @__PURE__ */ jsx(Chessboard.Root, {
44
+ state,
45
+ ref: controller,
46
+ children: /* @__PURE__ */ jsxs(Panel.Root, {
47
+ role,
48
+ classNames: "@container",
49
+ children: [/* @__PURE__ */ jsx(Panel.Toolbar, {
50
+ asChild: true,
51
+ children: /* @__PURE__ */ jsxs(Toolbar.Root, { children: [
52
+ isGameOver && /* @__PURE__ */ jsx(Toolbar.Button, {
53
+ onClick: handleNewGame,
54
+ children: t("new-game.button")
55
+ }),
56
+ /* @__PURE__ */ jsx("div", { className: "grow" }),
57
+ /* @__PURE__ */ jsx(Toolbar.IconButton, {
58
+ icon: "ph--info--regular",
59
+ iconOnly: true,
60
+ label: t("toggle-info.button"),
61
+ classNames: mx("invisible @4xl:visible"),
62
+ onClick: () => setShowInfo((open) => !open)
63
+ })
64
+ ] })
65
+ }), /* @__PURE__ */ jsx(Panel.Content, { children: /* @__PURE__ */ jsxs("div", {
66
+ className: mx("grid h-full w-full", showInfo && "@4xl:grid-cols-[1fr_320px] gap-8", role === AppSurface.Article.role && "p-4", role === AppSurface.Section.role && "aspect-square", role === AppSurface.Section.role && showInfo && "@4xl:aspect-auto"),
67
+ children: [/* @__PURE__ */ jsx(Chessboard.Content, { children: /* @__PURE__ */ jsx(Chessboard.Board, {
68
+ classNames: "border rounded-xs",
69
+ orientation
70
+ }) }), showInfo && /* @__PURE__ */ jsx("div", {
71
+ className: "hidden @4xl:flex flex-col justify-center items-center overflow-hidden",
72
+ children: /* @__PURE__ */ jsx(Chessboard.Info, {
73
+ orientation,
74
+ min: 8,
75
+ max: 8,
76
+ onOrientationChange: setOrientation,
77
+ onClose: () => setShowInfo(false),
78
+ onSelect: handleSelect
79
+ })
80
+ })]
81
+ }) })]
82
+ })
83
+ });
84
+ };
85
+ ChessArticle.displayName = "ChessArticle";
86
+ //#endregion
87
+ export { ChessArticle as default };
88
+
89
+ //# sourceMappingURL=chunk-ChessArticle.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-ChessArticle.mjs","names":[],"sources":["../../src/containers/ChessArticle/ChessArticle.tsx"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport React, { useCallback, useRef, useState } from 'react';\n\nimport { AppSurface } from '@dxos/app-toolkit/ui';\nimport { Obj } from '@dxos/echo';\nimport { useObject } from '@dxos/echo-react';\nimport { type GameVariantSurfaceProps } from '@dxos/plugin-game/types';\nimport { Panel, Toolbar, useTranslation } from '@dxos/react-ui';\nimport { type Player } from '@dxos/react-ui-gameboard';\nimport { mx } from '@dxos/ui-theme';\n\nimport { Chessboard, type ChessboardController, type ChessboardInfoProps } from '#components';\nimport { meta } from '#meta';\nimport { Chess } from '#types';\n\nexport type ChessArticleProps = GameVariantSurfaceProps;\n\nexport const ChessArticle = ({ role, variant }: ChessArticleProps) => {\n const { t } = useTranslation(meta.profile.key);\n const [orientation, setOrientation] = useState<Player>('white');\n const [showInfo, setShowInfo] = useState(true);\n const controller = useRef<ChessboardController>(null);\n\n const handleSelect = useCallback<NonNullable<ChessboardInfoProps['onSelect']>>((index) => {\n controller.current?.setMoveNumber(index);\n }, []);\n\n const state = Obj.instanceOf(Chess.State, variant) ? variant : undefined;\n const [pgn] = useObject(state, 'pgn');\n const [fen] = useObject(state, 'fen');\n\n const isGameOver = (() => {\n if (!pgn && !fen) {\n return false;\n }\n try {\n const chess = new ChessJS();\n if (pgn) {\n chess.loadPgn(pgn);\n } else if (fen) {\n chess.load(fen);\n }\n return chess.isGameOver();\n } catch {\n return false;\n }\n })();\n\n const handleNewGame = useCallback(() => {\n if (!state) {\n return;\n }\n Obj.update(state, (state) => {\n state.pgn = undefined;\n state.fen = undefined;\n });\n }, [state]);\n\n if (!state) {\n return null;\n }\n\n return (\n <Chessboard.Root state={state} ref={controller}>\n <Panel.Root role={role} classNames='@container'>\n <Panel.Toolbar asChild>\n <Toolbar.Root>\n {isGameOver && <Toolbar.Button onClick={handleNewGame}>{t('new-game.button')}</Toolbar.Button>}\n <div className='grow' />\n <Toolbar.IconButton\n icon='ph--info--regular'\n iconOnly\n label={t('toggle-info.button')}\n classNames={mx('invisible @4xl:visible')}\n onClick={() => setShowInfo((open) => !open)}\n />\n </Toolbar.Root>\n </Panel.Toolbar>\n <Panel.Content>\n <div\n className={mx(\n 'grid h-full w-full',\n showInfo && '@4xl:grid-cols-[1fr_320px] gap-8',\n role === AppSurface.Article.role && 'p-4',\n role === AppSurface.Section.role && 'aspect-square',\n role === AppSurface.Section.role && showInfo && '@4xl:aspect-auto',\n )}\n >\n <Chessboard.Content>\n <Chessboard.Board classNames='border rounded-xs' orientation={orientation} />\n </Chessboard.Content>\n {showInfo && (\n <div className='hidden @4xl:flex flex-col justify-center items-center overflow-hidden'>\n <Chessboard.Info\n orientation={orientation}\n min={8}\n max={8}\n onOrientationChange={setOrientation}\n onClose={() => setShowInfo(false)}\n onSelect={handleSelect}\n />\n </div>\n )}\n </div>\n </Panel.Content>\n </Panel.Root>\n </Chessboard.Root>\n );\n};\n\nChessArticle.displayName = 'ChessArticle';\n"],"mappings":";;;;;;;;;;;;AAqBA,IAAa,gBAAgB,EAAE,MAAM,cAAiC;CACpE,MAAM,EAAE,MAAM,eAAe,KAAK,QAAQ,GAAG;CAC7C,MAAM,CAAC,aAAa,kBAAkB,SAAiB,OAAO;CAC9D,MAAM,CAAC,UAAU,eAAe,SAAS,IAAI;CAC7C,MAAM,aAAa,OAA6B,IAAI;CAEpD,MAAM,eAAe,aAA2D,UAAU;EACxF,WAAW,SAAS,cAAc,KAAK;CACzC,GAAG,CAAC,CAAC;CAEL,MAAM,QAAQ,IAAI,WAAW,MAAM,OAAO,OAAO,IAAI,UAAU,KAAA;CAC/D,MAAM,CAAC,OAAO,UAAU,OAAO,KAAK;CACpC,MAAM,CAAC,OAAO,UAAU,OAAO,KAAK;CAEpC,MAAM,oBAAoB;EACxB,IAAI,CAAC,OAAO,CAAC,KACX,OAAO;EAET,IAAI;GACF,MAAM,QAAQ,IAAI,QAAQ;GAC1B,IAAI,KACF,MAAM,QAAQ,GAAG;QACZ,IAAI,KACT,MAAM,KAAK,GAAG;GAEhB,OAAO,MAAM,WAAW;EAC1B,QAAQ;GACN,OAAO;EACT;CACF,EAAA,CAAG;CAEH,MAAM,gBAAgB,kBAAkB;EACtC,IAAI,CAAC,OACH;EAEF,IAAI,OAAO,QAAQ,UAAU;GAC3B,MAAM,MAAM,KAAA;GACZ,MAAM,MAAM,KAAA;EACd,CAAC;CACH,GAAG,CAAC,KAAK,CAAC;CAEV,IAAI,CAAC,OACH,OAAO;CAGT,OACE,oBAAC,WAAW,MAAZ;EAAwB;EAAO,KAAK;YAClC,qBAAC,MAAM,MAAP;GAAkB;GAAM,YAAW;aAAnC,CACE,oBAAC,MAAM,SAAP;IAAe,SAAA;cACb,qBAAC,QAAQ,MAAT,EAAA,UAAA;KACG,cAAc,oBAAC,QAAQ,QAAT;MAAgB,SAAS;gBAAgB,EAAE,iBAAiB;KAAkB,CAAA;KAC7F,oBAAC,OAAD,EAAK,WAAU,OAAQ,CAAA;KACvB,oBAAC,QAAQ,YAAT;MACE,MAAK;MACL,UAAA;MACA,OAAO,EAAE,oBAAoB;MAC7B,YAAY,GAAG,wBAAwB;MACvC,eAAe,aAAa,SAAS,CAAC,IAAI;KAC3C,CAAA;IACW,EAAA,CAAA;GACD,CAAA,GACf,oBAAC,MAAM,SAAP,EAAA,UACE,qBAAC,OAAD;IACE,WAAW,GACT,sBACA,YAAY,oCACZ,SAAS,WAAW,QAAQ,QAAQ,OACpC,SAAS,WAAW,QAAQ,QAAQ,iBACpC,SAAS,WAAW,QAAQ,QAAQ,YAAY,kBAClD;cAPF,CASE,oBAAC,WAAW,SAAZ,EAAA,UACE,oBAAC,WAAW,OAAZ;KAAkB,YAAW;KAAiC;IAAc,CAAA,EAC1D,CAAA,GACnB,YACC,oBAAC,OAAD;KAAK,WAAU;eACb,oBAAC,WAAW,MAAZ;MACe;MACb,KAAK;MACL,KAAK;MACL,qBAAqB;MACrB,eAAe,YAAY,KAAK;MAChC,UAAU;KACX,CAAA;IACE,CAAA,CAEJ;MACQ,CAAA,CACL;;CACG,CAAA;AAErB;AAEA,aAAa,cAAc"}
@@ -0,0 +1,25 @@
1
+ import { Chess } from "#types";
2
+ import { Obj } from "@dxos/echo";
3
+ import "react";
4
+ import { Card } from "@dxos/react-ui";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import { Chessboard } from "#components";
7
+ //#region src/containers/ChessCard/ChessCard.tsx
8
+ var ChessCard = ({ variant }) => {
9
+ if (!Obj.instanceOf(Chess.State, variant)) return null;
10
+ return /* @__PURE__ */ jsx(Card.Body, { children: /* @__PURE__ */ jsx(Card.Section, {
11
+ classNames: "aspect-square",
12
+ children: /* @__PURE__ */ jsx(Card.Row, {
13
+ fullWidth: true,
14
+ children: /* @__PURE__ */ jsx(Chessboard.Root, {
15
+ state: variant,
16
+ children: /* @__PURE__ */ jsx(Chessboard.Content, { children: /* @__PURE__ */ jsx(Chessboard.Board, {}) })
17
+ })
18
+ })
19
+ }) });
20
+ };
21
+ ChessCard.displayName = "ChessCard";
22
+ //#endregion
23
+ export { ChessCard as default };
24
+
25
+ //# sourceMappingURL=chunk-ChessCard.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-ChessCard.mjs","names":[],"sources":["../../src/containers/ChessCard/ChessCard.tsx"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { Obj } from '@dxos/echo';\nimport { type GameVariantSurfaceProps } from '@dxos/plugin-game/types';\nimport { Card } from '@dxos/react-ui';\n\nimport { Chessboard } from '#components';\nimport { Chess } from '#types';\n\nexport type ChessCardProps = GameVariantSurfaceProps;\n\nexport const ChessCard = ({ variant }: ChessCardProps) => {\n if (!Obj.instanceOf(Chess.State, variant)) {\n return null;\n }\n\n return (\n <Card.Body>\n <Card.Section classNames='aspect-square'>\n <Card.Row fullWidth>\n <Chessboard.Root state={variant}>\n <Chessboard.Content>\n <Chessboard.Board />\n </Chessboard.Content>\n </Chessboard.Root>\n </Card.Row>\n </Card.Section>\n </Card.Body>\n );\n};\n\nChessCard.displayName = 'ChessCard';\n"],"mappings":";;;;;;;AAeA,IAAa,aAAa,EAAE,cAA8B;CACxD,IAAI,CAAC,IAAI,WAAW,MAAM,OAAO,OAAO,GACtC,OAAO;CAGT,OACE,oBAAC,KAAK,MAAN,EAAA,UACE,oBAAC,KAAK,SAAN;EAAc,YAAW;YACvB,oBAAC,KAAK,KAAN;GAAU,WAAA;aACR,oBAAC,WAAW,MAAZ;IAAiB,OAAO;cACtB,oBAAC,WAAW,SAAZ,EAAA,UACE,oBAAC,WAAW,OAAZ,CAAmB,CAAA,EACD,CAAA;GACL,CAAA;EACT,CAAA;CACE,CAAA,EACL,CAAA;AAEf;AAEA,UAAU,cAAc"}
@@ -0,0 +1,26 @@
1
+ import { Chess, ChessPositionIndex, PlayerReview } from "#types";
2
+ import { Plugin } from "@dxos/app-framework";
3
+ import { AppActivationEvents, AppPlugin } from "@dxos/app-toolkit";
4
+ import { GameVariant, OperationHandler, SkillDefinition } from "#capabilities";
5
+ import { meta } from "#meta";
6
+ import { translations } from "#translations";
7
+ //#endregion
8
+ //#region src/ChessPlugin.tsx
9
+ var ChessPlugin = Plugin.define(meta).pipe(Plugin.addModule({
10
+ id: "game-variant",
11
+ activatesOn: AppActivationEvents.SetupSchema,
12
+ activate: GameVariant
13
+ }), AppPlugin.addSkillDefinitionModule({ activate: SkillDefinition }), AppPlugin.addOperationHandlerModule({ activate: OperationHandler }), AppPlugin.addPluginAssetModule({ asset: {
14
+ pluginId: meta.profile.key,
15
+ path: "PLUGIN.mdl",
16
+ content: "---\nid: org.dxos.plugin.chess\nname: ChessPlugin\nversion: 0.1.0\n---\n\nA two-player chess game plugin for `DXOS` Composer.\n\n## Extensions\n\nThe following extension dialects are used in this document.\nEach extension is defined in the Appendix or resolved via its URI.\n\n| Term | URI |\n|-------------|--------------------------------|\n| `type` | `org.dxos.mdl.type@1.0` |\n| `feat` | `org.dxos.mdl.feat@1.0` |\n| `test` | `org.dxos.mdl.test@1.0` |\n| `component` | `org.dxos.mdl.component@1.0` |\n| `op` | `org.dxos.mdl.op@1.0` |\n| `service` | `org.dxos.mdl.service@1.0` |\n\n## Types\n\n```mdl\ntype Color\n literals: white | black\n```\n\n```mdl\ntype PieceKind\n literals: pawn | rook | knight | bishop | queen | king\n```\n\n```mdl\ntype Piece\n fields:\n kind: PieceKind\n color: Color\n```\n\n```mdl\ntype Square\n fields:\n file: a | b | c | d | e | f | g | h\n rank: 1..8\n piece?: Piece\n```\n\n```mdl\ntype Move\n fields:\n from: Square\n to: Square\n promotion?: PieceKind # only valid for pawn reaching back rank\n```\n\n```mdl\ntype Board\n fields:\n squares: Square[8][8]\n turn: Color\n status: playing | check | checkmate | stalemate\n moves: Move[] # full move history\n```\n\n```mdl\ntype Player\n fields:\n id: string\n name: string\n color: Color\n```\n\n```mdl\ntype GameStatus\n literals: waiting | active | finished\n```\n\n```mdl\ntype Game\n fields:\n id: string\n players: Player[2]\n board: Board\n status: GameStatus\n winner?: Player\n```\n\n## Components\n\n```mdl\ncomponent Lobby\n desc: Entry point where players create or join a game.\n props:\n playerId: string\n state:\n games: Game[] # list of open/active games\n selected?: Game\n slots:\n header?: ReactNode\n empty?: ReactNode # shown when games list is empty\n actions:\n createGame() → Game\n joinGame(game: Game) → Game\n spectate(game: Game)\n emits:\n onJoin(game: Game)\n layout: |\n ┌─────────────────────────┐\n │ [header slot] │\n ├─────────────────────────┤\n │ Game list │\n │ ┌───────────────────┐ │\n │ │ game row │ │\n │ └───────────────────┘ │\n │ [empty slot] │\n ├─────────────────────────┤\n │ [Create Game] │\n └─────────────────────────┘\n```\n\n```mdl\ncomponent Gameboard\n desc: Interactive chess board for an active game.\n props:\n game: Game\n playerId: string # identifies which side the viewer plays\n state:\n selected?: Square # currently selected square\n highlights: Square[] # legal move targets for selected piece\n perspective: Color # which side is at the bottom (default: player's color)\n slots:\n toolbar?: ReactNode\n sidebar?: ReactNode\n overlay?: ReactNode # e.g. checkmate / promotion dialogs\n actions:\n selectSquare(square: Square)\n submitMove(move: Move)\n flipBoard()\n emits:\n onMove(move: Move)\n onResign()\n layout: |\n ┌─────────────────────────┐\n │ [toolbar slot] │\n ├──────────┬──────────────┤\n │ │ [sidebar] │\n │ 8×8 │ │\n │ board │ move history │\n │ │ │\n ├──────────┴──────────────┤\n │ [overlay slot] │\n └─────────────────────────┘\n```\n\n## Services\n\n```mdl\nservice ChessEngine\n desc: Validates moves and computes game state. May be local (WASM) or remote.\n loading: lazy\n ops:\n validate(board: Board, move: Move) → Move\n legalMoves(board: Board, square: Square) → Square[]\n applyMove(board: Board, move: Move) → Board\n errors:\n EngineNotReady: engine has not finished loading\n```\n\n```mdl\nservice GameStore\n desc: Persists and replicates Game state via ECHO.\n ops:\n create(white: Player, black: Player) → Game\n load(id: string) → Game\n save(game: Game) → Game\n list() → Game[]\n effects: [echo:write, echo:read]\n```\n\n## Operations\n\nPure operations (no effects, no service dependencies) — safe to call anywhere.\n\n```mdl\nop getLegalMoves\n desc: Returns legal target squares for the piece on the given square.\n input:\n board: Board\n square: Square\n output: Square[]\n errors:\n EmptySquare: no piece on square\n WrongSide: piece does not belong to the active side\n requires: [ChessEngine]\n```\n\n```mdl\nop validateMove\n desc: Checks a move against chess rules without mutating state.\n input:\n board: Board\n move: Move\n output: Move\n errors:\n IllegalMove: move violates chess rules\n WrongTurn: piece does not belong to the active side\n GameOver: game has already ended\n requires: [ChessEngine]\n```\n\n```mdl\nop applyMove\n desc: Applies a validated move and returns the next board state.\n input:\n board: Board\n move: Move # must be pre-validated\n output: Board\n requires: [ChessEngine]\n note: does not persist; use submitMove for the full transactional flow\n```\n\nEffectful operations — mutate persistent state.\n\n```mdl\nop startGame\n desc: Creates a new Game with two players and an initial Board.\n input:\n white: Player\n black: Player\n output: Game\n effects: [echo:write]\n requires: [GameStore]\n```\n\n```mdl\nop submitMove\n desc: Validates and applies a move, then persists the updated Game.\n input:\n game: Game\n player: Player\n move: Move\n output: Game\n errors:\n WrongTurn: player is not the active side\n IllegalMove: move violates chess rules\n GameOver: game has already ended\n effects: [echo:write]\n requires: [ChessEngine, GameStore]\n note: |\n Composes validateMove → applyMove → GameStore.save.\n Atomic: Game is not persisted if validation fails.\n```\n\n```mdl\nop resignGame\n desc: Player forfeits; opponent wins.\n input:\n game: Game\n player: Player\n output: Game # Game.status === finished, Game.winner set\n errors:\n GameOver: game has already ended\n effects: [echo:write]\n requires: [GameStore]\n```\n\n## Features\n\n```mdl\nfeat F-1: Start Game\n\n req F-1.1: New Board created with pieces in standard starting positions.\n req F-1.2: White moves first.\n```\n\n```mdl\nfeat F-2: Make Move\n\n req F-2.1:\n when: player submits a Move on their turn\n then: Move validated against chess rules\n errors: [InvalidMove, WrongTurn, GameOver]\n\n req F-2.2:\n when: Move is valid\n then: Board updated; turn advances to opponent\n\n req F-2.3:\n when: resulting position leaves opponent's king in check\n then: Board.status set to check\n\n req F-2.4:\n when: no legal moves remain for the side to move\n then: Board.status set to checkmate (if in check) or stalemate\n```\n\n```mdl\nfeat F-3: Lobby\n\n req F-3.1: Player sees list of open games on entering the Lobby.\n req F-3.2:\n when: player creates a game\n then: new Game created with status waiting; player assigned white\n\n req F-3.3:\n when: second player joins an open game\n then: Game.status transitions to active; joining player assigned black\n\n req F-3.4:\n when: Game.status becomes active\n then: both players navigated to Gameboard\n```\n\n```mdl\nfeat F-4: Gameboard\n\n req F-4.1:\n when: player selects a square containing their piece\n then: legal move targets highlighted on board\n\n req F-4.2:\n when: player selects a highlighted target square\n then: Move submitted via submitMove(); board updated on success\n\n req F-4.3:\n when: pawn reaches the back rank\n then: promotion dialog shown via overlay slot; player selects piece kind\n\n req F-4.4:\n when: Game.status is finished\n then: result overlay shown (winner or draw); further moves disabled\n```\n\n```mdl\nfeat F-5: Move Validation\n\n req F-5.1:\n when: Gameboard calls submitMove\n then: op:validateMove runs before any state change\n\n req F-5.2:\n when: validation fails\n then: error returned to caller; Game state unchanged\n\n req F-5.3:\n when: square is selected on Gameboard\n then: op:getLegalMoves called; results drive component:Gameboard.highlights\n```\n\n```mdl\nfeat F-6: Game Persistence\n\n req F-6.1:\n when: op:startGame completes\n then: Game written to ECHO and visible in component:Lobby game list\n\n req F-6.2:\n when: op:submitMove completes\n then: updated Game replicated to all peers via ECHO\n\n req F-6.3:\n when: peer receives a Game update\n then: component:Gameboard re-renders with new Board state\n tags: [collaborative]\n```\n\n## Acceptance\n\n```mdl\ntest T-1: New game starting position\n given: a new game is started\n then:\n - Board.turn === white\n - Board.status === playing\n - each player has 16 pieces in standard positions\n```\n\n```mdl\ntest T-2: Illegal move rejected\n given: it is white's turn\n when: white attempts to move a black piece\n then: WrongTurn error; Board unchanged\n```\n\n```mdl\ntest T-3: Create and join game\n given: two players are in the Lobby\n when: player A creates a game, player B joins it\n then:\n - Game.status === active\n - Game.players[0].color === white # creator\n - Game.players[1].color === black # joiner\n - both players see the Gameboard\n```\n\n```mdl\ntest T-4: Legal move highlight\n given: Gameboard is shown, it is white's turn\n when: white selects the e2 pawn\n then:\n - squares e3 and e4 are highlighted\n - no other squares are highlighted\n```\n\n```mdl\ntest T-5: Pawn promotion\n given: white pawn is on e7, it is white's turn\n when: white moves pawn to e8\n then:\n - promotion overlay appears\n - after player selects queen, Move recorded with promotion: queen\n - board shows white queen on e8\n```\n\n```mdl\ntest T-6: Submit valid move\n given: active game, white's turn, white player logged in\n when: white submits pawn e2→e4\n then:\n - op:validateMove returns move without error\n - Board updated: e4 occupied by white pawn, e2 empty\n - Game.board.turn === black\n - Game persisted to ECHO\n```\n\n```mdl\ntest T-7: Submit invalid move rejected atomically\n given: active game, white's turn\n when: white submits an illegal move (e2→e5)\n then:\n - IllegalMove error returned\n - Game.board unchanged\n - no ECHO write occurs\n```\n\n```mdl\ntest T-8: Legal moves highlighted\n given: new game, white's turn, Gameboard shown\n when: player selects e2\n then:\n - op:getLegalMoves returns [e3, e4]\n - Gameboard.highlights === [e3, e4]\n```\n\n---\n\n## Appendix: Extension Definitions\n\nExtension block types used in this document are defined below using\nthe core `ext` primitive — the only construct the base language provides.\n\n```mdl\next type\n uri: dxos.spec/ext/type@1.0\n desc: A named data structure with typed fields and optional literals.\n fields:\n desc?: Prose\n fields?: FieldMap # name[?]: TypeExpr (# inline comment)\n literals?: UnionList # a | b | c\n extends?: TypeRef[]\n```\n\n```mdl\next feat\n uri: dxos.spec/ext/feat@1.0\n desc: A named feature grouping one or more requirements.\n fields:\n desc?: Prose\n req: RequirementList\n nesting: self # feat blocks may contain feat blocks\n```\n\n```mdl\next test\n uri: dxos.spec/ext/test@1.0\n desc: An acceptance scenario expressed as given / when / then steps.\n fields:\n given?: Step | Step[]\n when?: Step | Step[]\n then: Step | Step[]\n tags?: TagList\n```\n\n```mdl\next component\n uri: org.dxos.mdl.component@1.0\n desc: A UI component with props, internal state, slots, actions, and events.\n fields:\n desc?: Prose\n props?: FieldMap # external inputs (immutable inside component)\n state?: FieldMap # internal reactive state\n slots?: FieldMap # named ReactNode injection points\n actions?: ActionMap # methods the component exposes or handles\n emits?: EventMap # events the component raises to its parent\n layout?: CodeBlock # ASCII sketch of visual structure (non-normative)\n```\n\n```mdl\next op\n uri: org.dxos.mdl.op@1.0\n desc: |\n A named operation with typed inputs, outputs, and declared errors.\n Pure ops have no effects or requires. Effectful ops declare both.\n fields:\n desc?: Prose\n input?: FieldMap # named input parameters\n output?: TypeExpr # return type\n errors?: ErrorMap # name: Prose (when this error occurs)\n effects?: EffectList # echo:read | echo:write | http | fs | ...\n requires?: ServiceList # injected service dependencies\n note?: Prose # implementation guidance (non-normative)\n```\n\n```mdl\next service\n uri: org.dxos.mdl.service@1.0\n desc: An external or system-level dependency providing named operations.\n fields:\n desc?: Prose\n loading?: eager | lazy\n ops?: OpMap # name(params) → ReturnType\n errors?: ErrorMap\n note?: Prose\n```\n",
17
+ mimeType: "application/x-mdl"
18
+ } }), AppPlugin.addSchemaModule({ schema: [
19
+ Chess.State,
20
+ ChessPositionIndex.PositionIndex,
21
+ PlayerReview.Review
22
+ ] }), AppPlugin.addTranslationsModule({ translations }), Plugin.make);
23
+ //#endregion
24
+ export { ChessPlugin as t };
25
+
26
+ //# sourceMappingURL=chunk-ChessPlugin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-ChessPlugin.mjs","names":[],"sources":["../../src/ChessPlugin.tsx"],"sourcesContent":["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\nimport { AppActivationEvents, AppPlugin } from '@dxos/app-toolkit';\n\nimport { GameVariant, OperationHandler, SkillDefinition } from '#capabilities';\nimport { meta } from '#meta';\nimport { translations } from '#translations';\nimport { Chess, ChessPositionIndex, PlayerReview } from '#types';\n\n// eslint-disable-next-line import/no-relative-packages\nimport pluginSpec from '../PLUGIN.mdl?raw';\n\nexport const ChessPlugin = Plugin.define(meta).pipe(\n Plugin.addModule({\n id: 'game-variant',\n activatesOn: AppActivationEvents.SetupSchema,\n activate: GameVariant,\n }),\n AppPlugin.addSkillDefinitionModule({ activate: SkillDefinition }),\n AppPlugin.addOperationHandlerModule({ activate: OperationHandler }),\n AppPlugin.addPluginAssetModule({\n asset: { pluginId: meta.profile.key, path: 'PLUGIN.mdl', content: pluginSpec, mimeType: 'application/x-mdl' },\n }),\n AppPlugin.addSchemaModule({ schema: [Chess.State, ChessPositionIndex.PositionIndex, PlayerReview.Review] }),\n AppPlugin.addTranslationsModule({ translations }),\n Plugin.make,\n);\n\nexport default ChessPlugin;\n"],"mappings":";;;;;;;;AAeA,IAAa,cAAc,OAAO,OAAO,IAAI,CAAC,CAAC,KAC7C,OAAO,UAAU;CACf,IAAI;CACJ,aAAa,oBAAoB;CACjC,UAAU;AACZ,CAAC,GACD,UAAU,yBAAyB,EAAE,UAAU,gBAAgB,CAAC,GAChE,UAAU,0BAA0B,EAAE,UAAU,iBAAiB,CAAC,GAClE,UAAU,qBAAqB,EAC7B,OAAO;CAAE,UAAU,KAAK,QAAQ;CAAK,MAAM;CAAc,SAAS;CAAY,UAAU;AAAoB,EAC9G,CAAC,GACD,UAAU,gBAAgB,EAAE,QAAQ;CAAC,MAAM;CAAO,mBAAmB;CAAe,aAAa;AAAM,EAAE,CAAC,GAC1G,UAAU,sBAAsB,EAAE,aAAa,CAAC,GAChD,OAAO,IACT"}
@@ -0,0 +1,34 @@
1
+ import { Chess } from "#types";
2
+ import { Capability } from "@dxos/app-framework";
3
+ import * as Schema from "effect/Schema";
4
+ import { Type } from "@dxos/echo";
5
+ import { GameCapabilities } from "@dxos/plugin-game/types";
6
+ import * as Effect from "effect/Effect";
7
+ import { ChessArticle, ChessCard } from "#containers";
8
+ //#region src/capabilities/game-variant.ts
9
+ var CreateChessInput = Schema.Struct({
10
+ name: Schema.optional(Schema.String.annotations({
11
+ title: "Name",
12
+ description: "Optional name for the game."
13
+ })),
14
+ pgn: Schema.optional(Schema.String.annotations({
15
+ title: "PGN",
16
+ description: "Optional Portable Game Notation to start from."
17
+ }))
18
+ });
19
+ var variant = {
20
+ id: Type.getTypename(Chess.State),
21
+ label: "Chess",
22
+ icon: "ph--shield-chevron--regular",
23
+ variantType: Chess.State,
24
+ inputSchema: CreateChessInput,
25
+ roles: ["white", "black"],
26
+ createVariant: (input) => Effect.sync(() => Chess.make({ pgn: typeof input.pgn === "string" ? input.pgn : void 0 })),
27
+ card: ChessCard,
28
+ article: ChessArticle
29
+ };
30
+ var game_variant_default = Capability.makeModule(() => Effect.succeed(Capability.contributes(GameCapabilities.VariantProvider, variant)));
31
+ //#endregion
32
+ export { game_variant_default as default };
33
+
34
+ //# sourceMappingURL=chunk-game-variant.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-game-variant.mjs","names":[],"sources":["../../src/capabilities/game-variant.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\n\nimport { Capability } from '@dxos/app-framework';\nimport { Type } from '@dxos/echo';\nimport { GameCapabilities, type GameVariant } from '@dxos/plugin-game/types';\n\nimport { ChessArticle, ChessCard } from '#containers';\nimport { Chess } from '#types';\n\nconst CreateChessInput = Schema.Struct({\n name: Schema.optional(\n Schema.String.annotations({\n title: 'Name',\n description: 'Optional name for the game.',\n }),\n ),\n pgn: Schema.optional(\n Schema.String.annotations({\n title: 'PGN',\n description: 'Optional Portable Game Notation to start from.',\n }),\n ),\n});\n\nconst variant: GameVariant = {\n id: Type.getTypename(Chess.State),\n label: 'Chess',\n icon: 'ph--shield-chevron--regular',\n variantType: Chess.State,\n inputSchema: CreateChessInput,\n roles: ['white', 'black'] as const,\n createVariant: (input) =>\n Effect.sync(() => Chess.make({ pgn: typeof input.pgn === 'string' ? input.pgn : undefined })),\n card: ChessCard,\n article: ChessArticle,\n};\n\nexport default Capability.makeModule(() =>\n Effect.succeed(Capability.contributes(GameCapabilities.VariantProvider, variant)),\n);\n"],"mappings":";;;;;;;;AAcA,IAAM,mBAAmB,OAAO,OAAO;CACrC,MAAM,OAAO,SACX,OAAO,OAAO,YAAY;EACxB,OAAO;EACP,aAAa;CACf,CAAC,CACH;CACA,KAAK,OAAO,SACV,OAAO,OAAO,YAAY;EACxB,OAAO;EACP,aAAa;CACf,CAAC,CACH;AACF,CAAC;AAED,IAAM,UAAuB;CAC3B,IAAI,KAAK,YAAY,MAAM,KAAK;CAChC,OAAO;CACP,MAAM;CACN,aAAa,MAAM;CACnB,aAAa;CACb,OAAO,CAAC,SAAS,OAAO;CACxB,gBAAgB,UACd,OAAO,WAAW,MAAM,KAAK,EAAE,KAAK,OAAO,MAAM,QAAQ,WAAW,MAAM,MAAM,KAAA,EAAU,CAAC,CAAC;CAC9F,MAAM;CACN,SAAS;AACX;AAEA,IAAA,uBAAe,WAAW,iBACxB,OAAO,QAAQ,WAAW,YAAY,iBAAiB,iBAAiB,OAAO,CAAC,CAClF"}
@@ -0,0 +1,29 @@
1
+ import { trim } from "@dxos/util";
2
+ import { Plugin } from "@dxos/app-framework";
3
+ import { Config2 } from "@dxos/app-framework/config";
4
+ //#region dx.config.ts
5
+ var dx_config_default = Config2.make({ plugin: {
6
+ key: "org.dxos.plugin.chess",
7
+ name: "Chess",
8
+ author: "DXOS",
9
+ description: trim`
10
+ Full-featured chess game supporting multiplayer matches with friends or practice sessions against AI opponents.
11
+ Track game history and analyze moves in real-time.
12
+ `,
13
+ source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-chess",
14
+ icon: {
15
+ key: "ph--shield-chevron--regular",
16
+ hue: "amber"
17
+ },
18
+ spec: "PLUGIN.mdl",
19
+ tags: ["alpha", "game"],
20
+ screenshots: [{ dark: "https://dxos.network/plugin-details-chess-dark.png" }],
21
+ dependsOn: ["org.dxos.plugin.game"]
22
+ } });
23
+ //#endregion
24
+ //#region src/meta.ts
25
+ var meta = Plugin.getMetaFromConfig(dx_config_default);
26
+ //#endregion
27
+ export { meta as t };
28
+
29
+ //# sourceMappingURL=chunk-meta.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-meta.mjs","names":[],"sources":["../../dx.config.ts","../../src/meta.ts"],"sourcesContent":["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Config2 } from '@dxos/app-framework/config';\nimport { trim } from '@dxos/util';\n\nexport default Config2.make({\n plugin: {\n key: 'org.dxos.plugin.chess',\n name: 'Chess',\n author: 'DXOS',\n description: trim`\n Full-featured chess game supporting multiplayer matches with friends or practice sessions against AI opponents.\n Track game history and analyze moves in real-time.\n `,\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-chess',\n icon: { key: 'ph--shield-chevron--regular', hue: 'amber' },\n spec: 'PLUGIN.mdl',\n tags: ['alpha', 'game'],\n screenshots: [{ dark: 'https://dxos.network/plugin-details-chess-dark.png' }],\n dependsOn: ['org.dxos.plugin.game'],\n },\n});\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\n\nimport config from '../dx.config';\n\nexport const meta = Plugin.getMetaFromConfig(config);\n"],"mappings":";;;;AAOA,IAAA,oBAAe,QAAQ,KAAK,EAC1B,QAAQ;CACN,KAAK;CACL,MAAM;CACN,QAAQ;CACR,aAAa,IAAI;;;;CAIjB,QAAQ;CACR,MAAM;EAAE,KAAK;EAA+B,KAAK;CAAQ;CACzD,MAAM;CACN,MAAM,CAAC,SAAS,MAAM;CACtB,aAAa,CAAC,EAAE,MAAM,qDAAqD,CAAC;CAC5E,WAAW,CAAC,sBAAsB;AACpC,EACF,CAAC;;;ACfD,IAAa,OAAO,OAAO,kBAAkB,iBAAM"}
@@ -0,0 +1,23 @@
1
+ import { l as State, n as Move } from "./chunk-types.mjs";
2
+ import { Operation } from "@dxos/compute";
3
+ import { Chess } from "chess.js";
4
+ import { Obj } from "@dxos/echo";
5
+ import * as Effect from "effect/Effect";
6
+ import { loadGame } from "@dxos/plugin-game";
7
+ //#region src/operations/move.ts
8
+ var handler = Move.pipe(Operation.withHandler(Effect.fn(function* ({ game, move }) {
9
+ const { variant } = yield* loadGame(game, State);
10
+ const chess = new Chess();
11
+ if (variant.pgn) chess.loadPgn(variant.pgn);
12
+ else if (variant.fen) chess.load(variant.fen);
13
+ chess.move(move, { strict: false });
14
+ const pgn = chess.pgn();
15
+ Obj.update(variant, (variant) => {
16
+ variant.pgn = pgn;
17
+ });
18
+ return { pgn };
19
+ })));
20
+ //#endregion
21
+ export { handler as default };
22
+
23
+ //# sourceMappingURL=chunk-move.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-move.mjs","names":[],"sources":["../../src/operations/move.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport * as Effect from 'effect/Effect';\n\nimport { Operation } from '@dxos/compute';\nimport { Obj } from '@dxos/echo';\nimport { loadGame } from '@dxos/plugin-game';\n\nimport { Chess, ChessOperation } from '../types';\n\nconst handler: Operation.WithHandler<typeof ChessOperation.Move> = ChessOperation.Move.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ game, move }) {\n const { variant } = yield* loadGame(game, Chess.State);\n const chess = new ChessJS();\n if (variant.pgn) {\n chess.loadPgn(variant.pgn);\n } else if (variant.fen) {\n chess.load(variant.fen);\n }\n\n chess.move(move, { strict: false });\n const pgn = chess.pgn();\n Obj.update(variant, (variant) => {\n variant.pgn = pgn;\n });\n return { pgn };\n }),\n ),\n);\n\nexport default handler;\n"],"mappings":";;;;;;;AAaA,IAAM,UAAA,KAAiF,KACrF,UAAU,YACR,OAAO,GAAG,WAAW,EAAE,MAAM,QAAQ;CACnC,MAAM,EAAE,YAAY,OAAO,SAAS,MAAM,KAAW;CACrD,MAAM,QAAQ,IAAI,MAAQ;CAC1B,IAAI,QAAQ,KACV,MAAM,QAAQ,QAAQ,GAAG;MACpB,IAAI,QAAQ,KACjB,MAAM,KAAK,QAAQ,GAAG;CAGxB,MAAM,KAAK,MAAM,EAAE,QAAQ,MAAM,CAAC;CAClC,MAAM,MAAM,MAAM,IAAI;CACtB,IAAI,OAAO,UAAU,YAAY;EAC/B,QAAQ,MAAM;CAChB,CAAC;CACD,OAAO,EAAE,IAAI;AACf,CAAC,CACH,CACF"}
@@ -0,0 +1,11 @@
1
+ import { Capabilities, Capability } from "@dxos/app-framework";
2
+ import * as Effect from "effect/Effect";
3
+ import { ChessOperationHandlerSet } from "#operations";
4
+ //#region src/capabilities/operation-handler.ts
5
+ var operation_handler_default = Capability.makeModule(Effect.fnUntraced(function* () {
6
+ return Capability.contributes(Capabilities.OperationHandler, ChessOperationHandlerSet);
7
+ }));
8
+ //#endregion
9
+ export { operation_handler_default as default };
10
+
11
+ //# sourceMappingURL=chunk-operation-handler.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-operation-handler.mjs","names":[],"sources":["../../src/capabilities/operation-handler.ts"],"sourcesContent":["// Copyright 2025 DXOS.org\n\nimport * as Effect from 'effect/Effect';\n\nimport { Capabilities, Capability } from '@dxos/app-framework';\nimport type { OperationHandlerSet } from '@dxos/compute';\n\nimport { ChessOperationHandlerSet } from '#operations';\n\nexport default Capability.makeModule<OperationHandlerSet.OperationHandlerSet>(\n Effect.fnUntraced(function* () {\n return Capability.contributes(Capabilities.OperationHandler, ChessOperationHandlerSet);\n }),\n);\n"],"mappings":";;;;AASA,IAAA,4BAAe,WAAW,WACxB,OAAO,WAAW,aAAa;CAC7B,OAAO,WAAW,YAAY,aAAa,kBAAkB,wBAAwB;AACvF,CAAC,CACH"}
@@ -0,0 +1,32 @@
1
+ import { l as State, r as Play } from "./chunk-types.mjs";
2
+ import { Operation } from "@dxos/compute";
3
+ import { Chess } from "chess.js";
4
+ import { Obj } from "@dxos/echo";
5
+ import * as Effect from "effect/Effect";
6
+ import { loadGame } from "@dxos/plugin-game";
7
+ //#region src/operations/play.ts
8
+ var handler = Play.pipe(Operation.withHandler(Effect.fn(function* ({ game, side = "any" }) {
9
+ const { variant } = yield* loadGame(game, State);
10
+ const chess = new Chess();
11
+ if (variant.pgn) chess.loadPgn(variant.pgn);
12
+ else if (variant.fen) chess.load(variant.fen);
13
+ if (!(side === "any" || chess.turn() === "w" && side === "white" || chess.turn() === "b" && side === "black")) return {
14
+ move: void 0,
15
+ pgn: variant.pgn ?? ""
16
+ };
17
+ const moves = chess.moves();
18
+ const move = moves[Math.floor(Math.random() * moves.length)];
19
+ chess.move(move, { strict: false });
20
+ const pgn = chess.pgn();
21
+ Obj.update(variant, (variant) => {
22
+ variant.pgn = pgn;
23
+ });
24
+ return {
25
+ move,
26
+ pgn
27
+ };
28
+ })));
29
+ //#endregion
30
+ export { handler as default };
31
+
32
+ //# sourceMappingURL=chunk-play.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-play.mjs","names":[],"sources":["../../src/operations/play.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport * as Effect from 'effect/Effect';\n\nimport { Operation } from '@dxos/compute';\nimport { Obj } from '@dxos/echo';\nimport { loadGame } from '@dxos/plugin-game';\n\nimport { Chess, ChessOperation } from '../types';\n\nconst handler: Operation.WithHandler<typeof ChessOperation.Play> = ChessOperation.Play.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ game, side = 'any' }) {\n const { variant } = yield* loadGame(game, Chess.State);\n const chess = new ChessJS();\n if (variant.pgn) {\n chess.loadPgn(variant.pgn);\n } else if (variant.fen) {\n chess.load(variant.fen);\n }\n\n if (\n !(side === 'any' || (chess.turn() === 'w' && side === 'white') || (chess.turn() === 'b' && side === 'black'))\n ) {\n return { move: undefined, pgn: variant.pgn ?? '' };\n }\n\n const moves = chess.moves();\n const move = moves[Math.floor(Math.random() * moves.length)];\n\n chess.move(move, { strict: false });\n const pgn = chess.pgn();\n Obj.update(variant, (variant) => {\n variant.pgn = pgn;\n });\n return { move, pgn };\n }),\n ),\n);\n\nexport default handler;\n"],"mappings":";;;;;;;AAaA,IAAM,UAAA,KAAiF,KACrF,UAAU,YACR,OAAO,GAAG,WAAW,EAAE,MAAM,OAAO,SAAS;CAC3C,MAAM,EAAE,YAAY,OAAO,SAAS,MAAM,KAAW;CACrD,MAAM,QAAQ,IAAI,MAAQ;CAC1B,IAAI,QAAQ,KACV,MAAM,QAAQ,QAAQ,GAAG;MACpB,IAAI,QAAQ,KACjB,MAAM,KAAK,QAAQ,GAAG;CAGxB,IACE,EAAE,SAAS,SAAU,MAAM,KAAK,MAAM,OAAO,SAAS,WAAa,MAAM,KAAK,MAAM,OAAO,SAAS,UAEpG,OAAO;EAAE,MAAM,KAAA;EAAW,KAAK,QAAQ,OAAO;CAAG;CAGnD,MAAM,QAAQ,MAAM,MAAM;CAC1B,MAAM,OAAO,MAAM,KAAK,MAAM,KAAK,OAAO,IAAI,MAAM,MAAM;CAE1D,MAAM,KAAK,MAAM,EAAE,QAAQ,MAAM,CAAC;CAClC,MAAM,MAAM,MAAM,IAAI;CACtB,IAAI,OAAO,UAAU,YAAY;EAC/B,QAAQ,MAAM;CAChB,CAAC;CACD,OAAO;EAAE;EAAM;CAAI;AACrB,CAAC,CACH,CACF"}
@@ -0,0 +1,18 @@
1
+ import { i as Print } from "./chunk-types.mjs";
2
+ import { Operation } from "@dxos/compute";
3
+ import { Chess } from "chess.js";
4
+ import * as Effect from "effect/Effect";
5
+ //#region src/operations/print.ts
6
+ var handler = Print.pipe(Operation.withHandler(Effect.fn(function* ({ pgn, fen }) {
7
+ try {
8
+ const chess = new Chess(fen);
9
+ if (pgn) chess.loadPgn(pgn);
10
+ return { ascii: chess.ascii() };
11
+ } catch {
12
+ return { ascii: "" };
13
+ }
14
+ })));
15
+ //#endregion
16
+ export { handler as default };
17
+
18
+ //# sourceMappingURL=chunk-print.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-print.mjs","names":[],"sources":["../../src/operations/print.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport * as Effect from 'effect/Effect';\n\nimport { Operation } from '@dxos/compute';\n\nimport { ChessOperation } from '../types';\n\nconst handler: Operation.WithHandler<typeof ChessOperation.Print> = ChessOperation.Print.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ pgn, fen }) {\n try {\n const chess = new ChessJS(fen);\n if (pgn) {\n chess.loadPgn(pgn);\n }\n return { ascii: chess.ascii() };\n } catch {\n return { ascii: '' };\n }\n }),\n ),\n);\n\nexport default handler;\n"],"mappings":";;;;;AAWA,IAAM,UAAA,MAAmF,KACvF,UAAU,YACR,OAAO,GAAG,WAAW,EAAE,KAAK,OAAO;CACjC,IAAI;EACF,MAAM,QAAQ,IAAI,MAAQ,GAAG;EAC7B,IAAI,KACF,MAAM,QAAQ,GAAG;EAEnB,OAAO,EAAE,OAAO,MAAM,MAAM,EAAE;CAChC,QAAQ;EACN,OAAO,EAAE,OAAO,GAAG;CACrB;AACF,CAAC,CACH,CACF"}
@@ -0,0 +1,126 @@
1
+ import { a as RebuildPositionIndex, l as State } from "./chunk-types.mjs";
2
+ import { Operation } from "@dxos/compute";
3
+ import { Chess } from "chess.js";
4
+ import { Database, Filter, Obj, Ref } from "@dxos/echo";
5
+ import { Game, GameVariantMismatchError, loadGame } from "@dxos/plugin-game/types";
6
+ import * as Effect from "effect/Effect";
7
+ import * as Option from "effect/Option";
8
+ import { invariant } from "@dxos/invariant";
9
+ //#region src/internal/position-index.ts
10
+ /** Normalizes a FEN to the position key (board, side, castling, en passant). */
11
+ var normalizeFen = (fen) => fen.split(" ").slice(0, 4).join(" ");
12
+ var sideToTurn = (side) => side === "white" ? "w" : "b";
13
+ /**
14
+ * Positions where `side` is to move, derived from chess state PGN/FEN.
15
+ * Only positions within the first {@link OPENING_FULL_MOVE_LIMIT} full moves are indexed.
16
+ */
17
+ var positionsForSide = ({ pgn, fen, side }) => {
18
+ const probe = new Chess();
19
+ const chess = new Chess();
20
+ try {
21
+ if (pgn) probe.loadPgn(pgn);
22
+ else if (fen) {
23
+ probe.load(fen);
24
+ chess.load(fen);
25
+ }
26
+ } catch {
27
+ return [];
28
+ }
29
+ const moves = probe.history().slice(0, 20);
30
+ const turn = sideToTurn(side);
31
+ const fens = [];
32
+ if (chess.turn() === turn) fens.push(normalizeFen(chess.fen()));
33
+ for (const move of moves) {
34
+ chess.move(move);
35
+ if (chess.turn() === turn) fens.push(normalizeFen(chess.fen()));
36
+ }
37
+ return fens;
38
+ };
39
+ /** Resolves which side the reviewed player played in a game, if any. */
40
+ var playerSideInGame = (review, game) => {
41
+ for (const player of game.players ?? []) {
42
+ if (review.playerIdentity && player.identity === review.playerIdentity) return player.role === "black" ? "black" : "white";
43
+ if (review.playerName && player.name?.trim().toLowerCase() === review.playerName.trim().toLowerCase()) return player.role === "black" ? "black" : "white";
44
+ }
45
+ };
46
+ /** Builds a fresh side→fen→games index from processed games. */
47
+ var buildIndex = (entries) => {
48
+ const index = {
49
+ white: {},
50
+ black: {}
51
+ };
52
+ for (const { game, side, fens } of entries) for (const fen of fens) {
53
+ const bucket = index[side][fen] ?? [];
54
+ if (!bucket.some((existing) => existing.id === game.id)) bucket.push(game);
55
+ index[side][fen] = bucket;
56
+ }
57
+ return index;
58
+ };
59
+ var gameIdsKey = (games) => games.map((game) => game.id).toSorted().join("\0");
60
+ var refsGameIdsKey = (games) => games.map((gameRef) => gameRef.target?.id ?? gameRef.uri).toSorted().join("\0");
61
+ /**
62
+ * Applies a rebuilt index onto an existing {@link ChessPositionIndex.PositionIndex},
63
+ * mutating only FEN leaves whose game sets changed and removing stale FEN keys.
64
+ */
65
+ var applyIndexDiff = (positionIndex, next) => {
66
+ let updatedLeaves = 0;
67
+ Obj.update(positionIndex, (positionIndex) => {
68
+ for (const side of ["white", "black"]) {
69
+ const sideIndex = positionIndex.index[side];
70
+ const nextSide = next[side];
71
+ for (const fen of Object.keys(sideIndex)) if (!nextSide[fen]) {
72
+ delete sideIndex[fen];
73
+ updatedLeaves++;
74
+ }
75
+ for (const [fen, games] of Object.entries(nextSide)) {
76
+ const existing = sideIndex[fen];
77
+ if (existing && refsGameIdsKey(existing.games) === gameIdsKey(games)) continue;
78
+ sideIndex[fen] = { games: games.map((game) => Ref.make(game)) };
79
+ updatedLeaves++;
80
+ }
81
+ }
82
+ });
83
+ return updatedLeaves;
84
+ };
85
+ //#endregion
86
+ //#region src/operations/rebuild-position-index.ts
87
+ var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-chess/src/operations/rebuild-position-index.ts";
88
+ var rebuild_position_index_default = RebuildPositionIndex.pipe(Operation.withHandler(Effect.fn(function* ({ review: reviewRef }) {
89
+ const review = yield* Database.load(reviewRef);
90
+ invariant(review.playerIdentity || review.playerName, "Player review requires playerIdentity or playerName to match games.", {
91
+ "~LogMeta": "~LogMeta",
92
+ F: __dxlog_file,
93
+ L: 20,
94
+ S: this,
95
+ A: ["review.playerIdentity || review.playerName", "'Player review requires playerIdentity or playerName to match games.'"]
96
+ });
97
+ const positionIndex = yield* Database.load(review.positionIndex);
98
+ const games = yield* Database.query(Filter.type(Game.Game)).run;
99
+ const processed = [];
100
+ for (const game of games) {
101
+ const side = playerSideInGame(review, game);
102
+ if (!side) continue;
103
+ const loaded = yield* loadGame(Ref.make(game), State).pipe(Effect.asSome, Effect.catchIf((error) => error instanceof GameVariantMismatchError, () => Effect.succeedNone));
104
+ if (Option.isNone(loaded)) continue;
105
+ const { variant } = loaded.value;
106
+ processed.push({
107
+ game,
108
+ side,
109
+ fens: positionsForSide({
110
+ pgn: variant.pgn,
111
+ fen: variant.fen,
112
+ side
113
+ })
114
+ });
115
+ }
116
+ const positionsUpdated = applyIndexDiff(positionIndex, buildIndex(processed));
117
+ yield* Database.flush();
118
+ return {
119
+ gamesScanned: processed.length,
120
+ positionsUpdated
121
+ };
122
+ })), Operation.opaqueHandler);
123
+ //#endregion
124
+ export { rebuild_position_index_default as default };
125
+
126
+ //# sourceMappingURL=chunk-rebuild-position-index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-rebuild-position-index.mjs","names":[],"sources":["../../src/internal/position-index.ts","../../src/operations/rebuild-position-index.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\n\nimport { Obj, Ref } from '@dxos/echo';\nimport { type Game } from '@dxos/plugin-game/types';\n\nimport * as ChessPositionIndex from '../types/ChessPositionIndex';\nimport * as PlayerReview from '../types/PlayerReview';\n\n/** Normalizes a FEN to the position key (board, side, castling, en passant). */\nexport const normalizeFen = (fen: string): string => fen.split(' ').slice(0, 4).join(' ');\n\nconst sideToTurn = (side: ChessPositionIndex.Side): 'w' | 'b' => (side === 'white' ? 'w' : 'b');\n\n/** Maximum full moves per game indexed (opening window). */\nexport const OPENING_FULL_MOVE_LIMIT = 10;\n\n/** Half-move cap for the opening window. */\nexport const OPENING_PLY_LIMIT = OPENING_FULL_MOVE_LIMIT * 2;\n\n/**\n * Positions where `side` is to move, derived from chess state PGN/FEN.\n * Only positions within the first {@link OPENING_FULL_MOVE_LIMIT} full moves are indexed.\n */\nexport const positionsForSide = ({\n pgn,\n fen,\n side,\n}: {\n pgn?: string;\n fen?: string;\n side: ChessPositionIndex.Side;\n}): string[] => {\n const probe = new ChessJS();\n const chess = new ChessJS();\n try {\n if (pgn) {\n probe.loadPgn(pgn);\n } else if (fen) {\n // A FEN-only game has no move history to replay, so index from the supplied position itself.\n probe.load(fen);\n chess.load(fen);\n }\n } catch {\n // chess.js throws on malformed PGN/FEN; a single bad record must not abort the rebuild.\n return [];\n }\n\n const moves = probe.history().slice(0, OPENING_PLY_LIMIT);\n const turn = sideToTurn(side);\n const fens: string[] = [];\n\n if (chess.turn() === turn) {\n fens.push(normalizeFen(chess.fen()));\n }\n\n for (const move of moves) {\n chess.move(move);\n if (chess.turn() === turn) {\n fens.push(normalizeFen(chess.fen()));\n }\n }\n\n return fens;\n};\n\n/** Resolves which side the reviewed player played in a game, if any. */\nexport const playerSideInGame = (review: PlayerReview.Review, game: Game.Game): ChessPositionIndex.Side | undefined => {\n for (const player of game.players ?? []) {\n if (review.playerIdentity && player.identity === review.playerIdentity) {\n return player.role === 'black' ? 'black' : 'white';\n }\n if (review.playerName && player.name?.trim().toLowerCase() === review.playerName.trim().toLowerCase()) {\n return player.role === 'black' ? 'black' : 'white';\n }\n }\n return undefined;\n};\n\nexport type BuiltSideIndex = Record<string, Game.Game[]>;\n\nexport type BuiltIndex = Record<ChessPositionIndex.Side, BuiltSideIndex>;\n\n/** Builds a fresh side→fen→games index from processed games. */\nexport const buildIndex = (\n entries: ReadonlyArray<{ game: Game.Game; side: ChessPositionIndex.Side; fens: readonly string[] }>,\n): BuiltIndex => {\n const index: BuiltIndex = { white: {}, black: {} };\n for (const { game, side, fens } of entries) {\n for (const fen of fens) {\n const bucket = index[side][fen] ?? [];\n if (!bucket.some((existing) => existing.id === game.id)) {\n bucket.push(game);\n }\n index[side][fen] = bucket;\n }\n }\n return index;\n};\n\nconst gameIdsKey = (games: ReadonlyArray<{ id: string }>): string =>\n games\n .map((game) => game.id)\n .toSorted()\n .join('\\0');\n\nconst refsGameIdsKey = (games: ReadonlyArray<Ref.Ref<Game.Game>>): string =>\n games\n .map((gameRef) => gameRef.target?.id ?? gameRef.uri)\n .toSorted()\n .join('\\0');\n\n/**\n * Applies a rebuilt index onto an existing {@link ChessPositionIndex.PositionIndex},\n * mutating only FEN leaves whose game sets changed and removing stale FEN keys.\n */\nexport const applyIndexDiff = (positionIndex: ChessPositionIndex.PositionIndex, next: BuiltIndex): number => {\n let updatedLeaves = 0;\n\n Obj.update(positionIndex, (positionIndex) => {\n for (const side of ['white', 'black'] as const) {\n const sideIndex = positionIndex.index[side];\n const nextSide = next[side];\n\n for (const fen of Object.keys(sideIndex)) {\n if (!nextSide[fen]) {\n delete sideIndex[fen];\n updatedLeaves++;\n }\n }\n\n for (const [fen, games] of Object.entries(nextSide)) {\n const existing = sideIndex[fen];\n if (existing && refsGameIdsKey(existing.games) === gameIdsKey(games)) {\n continue;\n }\n\n sideIndex[fen] = { games: games.map((game) => Ref.make(game)) };\n updatedLeaves++;\n }\n }\n });\n\n return updatedLeaves;\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\n\nimport { Operation } from '@dxos/compute';\nimport { Database, Filter, Ref } from '@dxos/echo';\nimport { invariant } from '@dxos/invariant';\nimport { Game, GameVariantMismatchError, loadGame } from '@dxos/plugin-game/types';\n\nimport * as positionIndexInternal from '../internal/position-index';\nimport { Chess, ChessOperation, ChessPositionIndex } from '../types';\n\nexport default ChessOperation.RebuildPositionIndex.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ review: reviewRef }) {\n const review = yield* Database.load(reviewRef);\n invariant(\n review.playerIdentity || review.playerName,\n 'Player review requires playerIdentity or playerName to match games.',\n );\n\n const positionIndex = yield* Database.load(review.positionIndex);\n const games = yield* Database.query(Filter.type(Game.Game)).run;\n\n const processed: Array<{\n game: Game.Game;\n side: ChessPositionIndex.Side;\n fens: readonly string[];\n }> = [];\n\n for (const game of games) {\n const side = positionIndexInternal.playerSideInGame(review, game);\n if (!side) {\n continue;\n }\n\n // Skip games whose variant is not chess, but let database/ref failures abort the rebuild\n // rather than silently producing a partial index.\n const loaded = yield* loadGame(Ref.make(game), Chess.State).pipe(\n Effect.asSome,\n Effect.catchIf(\n (error) => error instanceof GameVariantMismatchError,\n () => Effect.succeedNone,\n ),\n );\n if (Option.isNone(loaded)) {\n continue;\n }\n\n const { variant } = loaded.value;\n processed.push({\n game,\n side,\n fens: positionIndexInternal.positionsForSide({\n pgn: variant.pgn,\n fen: variant.fen,\n side,\n }),\n });\n }\n\n const nextIndex = positionIndexInternal.buildIndex(processed);\n const positionsUpdated = positionIndexInternal.applyIndexDiff(positionIndex, nextIndex);\n yield* Database.flush();\n\n return { gamesScanned: processed.length, positionsUpdated };\n }),\n ),\n Operation.opaqueHandler,\n);\n"],"mappings":";;;;;;;;;;AAaA,IAAa,gBAAgB,QAAwB,IAAI,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG;AAExF,IAAM,cAAc,SAA8C,SAAS,UAAU,MAAM;;;;;AAY3F,IAAa,oBAAoB,EAC/B,KACA,KACA,WAKc;CACd,MAAM,QAAQ,IAAI,MAAQ;CAC1B,MAAM,QAAQ,IAAI,MAAQ;CAC1B,IAAI;EACF,IAAI,KACF,MAAM,QAAQ,GAAG;OACZ,IAAI,KAAK;GAEd,MAAM,KAAK,GAAG;GACd,MAAM,KAAK,GAAG;EAChB;CACF,QAAQ;EAEN,OAAO,CAAC;CACV;CAEA,MAAM,QAAQ,MAAM,QAAQ,CAAC,CAAC,MAAM,GAAA,EAAoB;CACxD,MAAM,OAAO,WAAW,IAAI;CAC5B,MAAM,OAAiB,CAAC;CAExB,IAAI,MAAM,KAAK,MAAM,MACnB,KAAK,KAAK,aAAa,MAAM,IAAI,CAAC,CAAC;CAGrC,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,KAAK,IAAI;EACf,IAAI,MAAM,KAAK,MAAM,MACnB,KAAK,KAAK,aAAa,MAAM,IAAI,CAAC,CAAC;CAEvC;CAEA,OAAO;AACT;;AAGA,IAAa,oBAAoB,QAA6B,SAAyD;CACrH,KAAK,MAAM,UAAU,KAAK,WAAW,CAAC,GAAG;EACvC,IAAI,OAAO,kBAAkB,OAAO,aAAa,OAAO,gBACtD,OAAO,OAAO,SAAS,UAAU,UAAU;EAE7C,IAAI,OAAO,cAAc,OAAO,MAAM,KAAK,CAAC,CAAC,YAAY,MAAM,OAAO,WAAW,KAAK,CAAC,CAAC,YAAY,GAClG,OAAO,OAAO,SAAS,UAAU,UAAU;CAE/C;AAEF;;AAOA,IAAa,cACX,YACe;CACf,MAAM,QAAoB;EAAE,OAAO,CAAC;EAAG,OAAO,CAAC;CAAE;CACjD,KAAK,MAAM,EAAE,MAAM,MAAM,UAAU,SACjC,KAAK,MAAM,OAAO,MAAM;EACtB,MAAM,SAAS,MAAM,KAAK,CAAC,QAAQ,CAAC;EACpC,IAAI,CAAC,OAAO,MAAM,aAAa,SAAS,OAAO,KAAK,EAAE,GACpD,OAAO,KAAK,IAAI;EAElB,MAAM,KAAK,CAAC,OAAO;CACrB;CAEF,OAAO;AACT;AAEA,IAAM,cAAc,UAClB,MACG,KAAK,SAAS,KAAK,EAAE,CAAA,CACrB,SAAS,CAAA,CACT,KAAK,IAAI;AAEd,IAAM,kBAAkB,UACtB,MACG,KAAK,YAAY,QAAQ,QAAQ,MAAM,QAAQ,GAAG,CAAA,CAClD,SAAS,CAAA,CACT,KAAK,IAAI;;;;;AAMd,IAAa,kBAAkB,eAAiD,SAA6B;CAC3G,IAAI,gBAAgB;CAEpB,IAAI,OAAO,gBAAgB,kBAAkB;EAC3C,KAAK,MAAM,QAAQ,CAAC,SAAS,OAAO,GAAY;GAC9C,MAAM,YAAY,cAAc,MAAM;GACtC,MAAM,WAAW,KAAK;GAEtB,KAAK,MAAM,OAAO,OAAO,KAAK,SAAS,GACrC,IAAI,CAAC,SAAS,MAAM;IAClB,OAAO,UAAU;IACjB;GACF;GAGF,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,GAAG;IACnD,MAAM,WAAW,UAAU;IAC3B,IAAI,YAAY,eAAe,SAAS,KAAK,MAAM,WAAW,KAAK,GACjE;IAGF,UAAU,OAAO,EAAE,OAAO,MAAM,KAAK,SAAS,IAAI,KAAK,IAAI,CAAC,EAAE;IAC9D;GACF;EACF;CACF,CAAC;CAED,OAAO;AACT;;;;ACpIA,IAAA,iCAAA,qBAAmD,KACjD,UAAU,YACR,OAAO,GAAG,WAAW,EAAE,QAAQ,aAAa;CAC1C,MAAM,SAAS,OAAO,SAAS,KAAK,SAAS;CAC7C,UACE,OAAO,kBAAkB,OAAO,YAChC,uEACH;EAAA,YAAA;EAAA,GAAA;EAAA,GAAA;EAAA,GAAA;EAAA,GAAA,CAAA,8CAAA,uEAAA;CAAA,CAAC;CAEA,MAAM,gBAAgB,OAAO,SAAS,KAAK,OAAO,aAAa;CAC/D,MAAM,QAAQ,OAAO,SAAS,MAAM,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC;CAE5D,MAAM,YAID,CAAC;CAEN,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,OAAO,iBAAuC,QAAQ,IAAI;EAChE,IAAI,CAAC,MACH;EAKF,MAAM,SAAS,OAAO,SAAS,IAAI,KAAK,IAAI,GAAG,KAAW,CAAC,CAAC,KAC1D,OAAO,QACP,OAAO,SACJ,UAAU,iBAAiB,gCACtB,OAAO,WACf,CACF;EACA,IAAI,OAAO,OAAO,MAAM,GACtB;EAGF,MAAM,EAAE,YAAY,OAAO;EAC3B,UAAU,KAAK;GACb;GACA;GACA,MAAM,iBAAuC;IAC3C,KAAK,QAAQ;IACb,KAAK,QAAQ;IACb;GACF,CAAC;EACH,CAAC;CACH;CAGA,MAAM,mBAAmB,eAAqC,eAD5C,WAAiC,SAC0B,CAAS;CACtF,OAAO,SAAS,MAAM;CAEtB,OAAO;EAAE,cAAc,UAAU;EAAQ;CAAiB;AAC5D,CAAC,CACH,GACA,UAAU,aACZ"}