rpg-engine 0.7.0 → 0.8.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.
Files changed (393) hide show
  1. package/dist/adventures/index.d.ts +1 -1
  2. package/dist/adventures/index.js +1 -1
  3. package/dist/adventures/source.js +13 -13
  4. package/dist/campaign/create-campaign.js +10 -1
  5. package/dist/campaign/host-files.d.ts +2 -1
  6. package/dist/campaign/host-files.js +11 -11
  7. package/dist/campaign/index.d.ts +1 -1
  8. package/dist/campaign/index.js +1 -1
  9. package/dist/campaign/settings.d.ts +55 -64
  10. package/dist/campaign/settings.js +171 -174
  11. package/dist/{cli.js → cli/cli.js} +3 -3
  12. package/dist/{command-line.d.ts → cli/command-line.d.ts} +1 -1
  13. package/dist/{command-line.js → cli/command-line.js} +21 -20
  14. package/dist/commands/advance.d.ts +1 -1
  15. package/dist/commands/advance.js +7 -7
  16. package/dist/commands/ask.d.ts +1 -8
  17. package/dist/commands/ask.js +16 -29
  18. package/dist/commands/{change.d.ts → change/change.d.ts} +2 -2
  19. package/dist/commands/{change.js → change/change.js} +46 -52
  20. package/dist/commands/{game-damage.d.ts → change/damage.d.ts} +2 -2
  21. package/dist/commands/{game-damage.js → change/damage.js} +3 -3
  22. package/dist/commands/{game-recipe-pace.d.ts → change/recipe-pace.d.ts} +2 -2
  23. package/dist/commands/{game-recipe-pace.js → change/recipe-pace.js} +4 -4
  24. package/dist/commands/config.d.ts +4 -4
  25. package/dist/commands/config.js +142 -138
  26. package/dist/commands/effect.d.ts +1 -1
  27. package/dist/commands/effect.js +11 -12
  28. package/dist/commands/find.d.ts +4 -4
  29. package/dist/commands/find.js +2 -2
  30. package/dist/commands/image.js +6 -6
  31. package/dist/commands/{import.d.ts → import/import.d.ts} +2 -2
  32. package/dist/commands/{import.js → import/import.js} +101 -101
  33. package/dist/commands/{game-import.d.ts → import/run.d.ts} +3 -3
  34. package/dist/commands/{game-import.js → import/run.js} +13 -12
  35. package/dist/commands/index.js +7 -7
  36. package/dist/commands/init.js +3 -3
  37. package/dist/commands/install.js +1 -1
  38. package/dist/commands/instructions.js +6 -6
  39. package/dist/commands/mode.d.ts +2 -2
  40. package/dist/commands/mode.js +8 -8
  41. package/dist/commands/mood.js +4 -4
  42. package/dist/commands/move.js +13 -20
  43. package/dist/commands/package.d.ts +2 -2
  44. package/dist/commands/package.js +138 -93
  45. package/dist/commands/rename.js +3 -3
  46. package/dist/commands/reveal.js +29 -18
  47. package/dist/commands/{roll.d.ts → roll/roll.d.ts} +4 -4
  48. package/dist/commands/{roll.js → roll/roll.js} +69 -69
  49. package/dist/commands/{game-tables.d.ts → roll/tables.d.ts} +2 -2
  50. package/dist/commands/{game-tables.js → roll/tables.js} +4 -4
  51. package/dist/commands/rules.d.ts +2 -2
  52. package/dist/commands/rules.js +3 -3
  53. package/dist/commands/save.d.ts +1 -1
  54. package/dist/commands/save.js +18 -18
  55. package/dist/commands/scene.d.ts +4 -4
  56. package/dist/commands/scene.js +31 -28
  57. package/dist/commands/{game-advance.d.ts → shared/advance.d.ts} +4 -4
  58. package/dist/commands/{game-advance.js → shared/advance.js} +27 -27
  59. package/dist/commands/{game-adventures.d.ts → shared/adventures.d.ts} +3 -3
  60. package/dist/commands/{game-adventures.js → shared/adventures.js} +20 -27
  61. package/dist/commands/{game-bonds.d.ts → shared/bonds.d.ts} +3 -3
  62. package/dist/commands/{game-bonds.js → shared/bonds.js} +2 -2
  63. package/dist/commands/{game-checks.d.ts → shared/checks.d.ts} +3 -3
  64. package/dist/commands/{game-checks.js → shared/checks.js} +7 -7
  65. package/dist/commands/{game-dice-pool.d.ts → shared/dice-pool.d.ts} +3 -3
  66. package/dist/commands/{game-dice-pool.js → shared/dice-pool.js} +19 -12
  67. package/dist/commands/{effect-layer.d.ts → shared/effect-layer.d.ts} +2 -2
  68. package/dist/commands/{effect-layer.js → shared/effect-layer.js} +12 -12
  69. package/dist/commands/{game-effects.d.ts → shared/effects.d.ts} +7 -7
  70. package/dist/commands/{game-effects.js → shared/effects.js} +19 -19
  71. package/dist/commands/{game-environment.d.ts → shared/environment.d.ts} +1 -1
  72. package/dist/commands/{game-environment.js → shared/environment.js} +3 -3
  73. package/dist/commands/{game-events.d.ts → shared/events.d.ts} +5 -5
  74. package/dist/commands/{game-events.js → shared/events.js} +20 -22
  75. package/dist/commands/{game-examples.d.ts → shared/examples.d.ts} +4 -8
  76. package/dist/commands/{game-examples.js → shared/examples.js} +23 -23
  77. package/dist/commands/{game-experience.d.ts → shared/experience.d.ts} +2 -2
  78. package/dist/commands/{game-experience.js → shared/experience.js} +8 -11
  79. package/dist/commands/{game-grid-moves.d.ts → shared/grid-moves.d.ts} +6 -6
  80. package/dist/commands/{game-grid-moves.js → shared/grid-moves.js} +5 -5
  81. package/dist/commands/{game-grids.d.ts → shared/grids.d.ts} +4 -9
  82. package/dist/commands/{game-grids.js → shared/grids.js} +20 -19
  83. package/dist/commands/{game-images.d.ts → shared/images.d.ts} +3 -3
  84. package/dist/commands/{game-images.js → shared/images.js} +7 -6
  85. package/dist/commands/shared/inputs.d.ts +9 -0
  86. package/dist/commands/shared/inputs.js +12 -0
  87. package/dist/commands/{game-journey.d.ts → shared/journey.d.ts} +4 -6
  88. package/dist/commands/{game-journey.js → shared/journey.js} +13 -15
  89. package/dist/commands/{game-knowledge.d.ts → shared/knowledge.d.ts} +15 -8
  90. package/dist/commands/{game-knowledge.js → shared/knowledge.js} +42 -42
  91. package/dist/{library-reader.js → commands/shared/library-reader.js} +4 -4
  92. package/dist/commands/{game-library.d.ts → shared/library.d.ts} +7 -4
  93. package/dist/commands/{game-library.js → shared/library.js} +70 -50
  94. package/dist/commands/{game-limits.d.ts → shared/limits.d.ts} +3 -3
  95. package/dist/commands/{game-limits.js → shared/limits.js} +3 -3
  96. package/dist/commands/{game-loot.d.ts → shared/loot.d.ts} +2 -2
  97. package/dist/commands/{game-loot.js → shared/loot.js} +3 -3
  98. package/dist/commands/{game-master-rolls.d.ts → shared/master-rolls.d.ts} +2 -2
  99. package/dist/commands/{game-master-rolls.js → shared/master-rolls.js} +6 -6
  100. package/dist/commands/{game-mode.d.ts → shared/mode.d.ts} +4 -6
  101. package/dist/commands/{game-mode.js → shared/mode.js} +10 -10
  102. package/dist/commands/{game-money.d.ts → shared/money.d.ts} +3 -3
  103. package/dist/commands/{game-money.js → shared/money.js} +4 -4
  104. package/dist/commands/{game-moods.d.ts → shared/moods.d.ts} +3 -3
  105. package/dist/commands/{game-moods.js → shared/moods.js} +3 -3
  106. package/dist/commands/{game-moves.d.ts → shared/moves.d.ts} +2 -2
  107. package/dist/commands/{game-moves.js → shared/moves.js} +5 -5
  108. package/dist/commands/{game-offers.d.ts → shared/offers.d.ts} +3 -3
  109. package/dist/commands/{game-offers.js → shared/offers.js} +9 -12
  110. package/dist/commands/{game-outside.d.ts → shared/outside.d.ts} +3 -3
  111. package/dist/commands/{game-outside.js → shared/outside.js} +9 -9
  112. package/dist/commands/{game-catalog.d.ts → shared/packages/catalog.d.ts} +1 -3
  113. package/dist/commands/{game-catalog.js → shared/packages/catalog.js} +17 -22
  114. package/dist/commands/{game-package-code.d.ts → shared/packages/code.d.ts} +10 -14
  115. package/dist/commands/{game-package-code.js → shared/packages/code.js} +156 -59
  116. package/dist/commands/{game-extension-list.d.ts → shared/packages/extensions.d.ts} +6 -6
  117. package/dist/commands/{game-extension-list.js → shared/packages/extensions.js} +43 -22
  118. package/dist/commands/{game-package-hooks.d.ts → shared/packages/hooks.d.ts} +3 -3
  119. package/dist/commands/{game-package-hooks.js → shared/packages/hooks.js} +3 -3
  120. package/dist/commands/{game-widgets.d.ts → shared/packages/widgets.d.ts} +6 -10
  121. package/dist/commands/{game-widgets.js → shared/packages/widgets.js} +57 -57
  122. package/dist/commands/{page-counters.d.ts → shared/page-counters.d.ts} +3 -3
  123. package/dist/commands/{page-counters.js → shared/page-counters.js} +5 -5
  124. package/dist/{page-words.d.ts → commands/shared/page-words.d.ts} +2 -2
  125. package/dist/{page-words.js → commands/shared/page-words.js} +5 -4
  126. package/dist/commands/{parts.d.ts → shared/parts.d.ts} +3 -3
  127. package/dist/commands/{parts.js → shared/parts.js} +4 -4
  128. package/dist/commands/{game-positions.d.ts → shared/positions.d.ts} +3 -5
  129. package/dist/commands/{game-positions.js → shared/positions.js} +6 -7
  130. package/dist/commands/{problems.d.ts → shared/problems.d.ts} +3 -3
  131. package/dist/commands/{problems.js → shared/problems.js} +21 -22
  132. package/dist/commands/{progression.d.ts → shared/progression.d.ts} +2 -2
  133. package/dist/commands/{progression.js → shared/progression.js} +4 -4
  134. package/dist/commands/{game-quests.d.ts → shared/quests.d.ts} +4 -4
  135. package/dist/commands/{game-quests.js → shared/quests.js} +6 -6
  136. package/dist/commands/{game-recipes.d.ts → shared/recipes.d.ts} +3 -3
  137. package/dist/commands/{game-recipes.js → shared/recipes.js} +3 -3
  138. package/dist/commands/{game-reminders.d.ts → shared/reminders.d.ts} +4 -4
  139. package/dist/commands/{game-reminders.js → shared/reminders.js} +4 -4
  140. package/dist/commands/{game-roads.d.ts → shared/roads.d.ts} +5 -5
  141. package/dist/commands/{game-roads.js → shared/roads.js} +43 -44
  142. package/dist/commands/{game-rules.d.ts → shared/rules.d.ts} +2 -2
  143. package/dist/commands/{game-rules.js → shared/rules.js} +4 -4
  144. package/dist/commands/{game-saves.d.ts → shared/saves.d.ts} +4 -4
  145. package/dist/commands/{game-saves.js → shared/saves.js} +51 -51
  146. package/dist/commands/{game-scene.d.ts → shared/scene.d.ts} +13 -3
  147. package/dist/commands/{game-scene.js → shared/scene.js} +41 -13
  148. package/dist/commands/{sheet.d.ts → shared/sheet.d.ts} +5 -5
  149. package/dist/commands/{sheet.js → shared/sheet.js} +76 -76
  150. package/dist/commands/{game-stacks.d.ts → shared/stacks.d.ts} +2 -9
  151. package/dist/commands/{game-stacks.js → shared/stacks.js} +22 -22
  152. package/dist/commands/{game-theme.d.ts → shared/theme.d.ts} +3 -3
  153. package/dist/commands/{game-theme.js → shared/theme.js} +2 -2
  154. package/dist/commands/{game-thoughts.d.ts → shared/thoughts.d.ts} +2 -4
  155. package/dist/commands/{game-thoughts.js → shared/thoughts.js} +6 -8
  156. package/dist/commands/{game-thresholds.d.ts → shared/thresholds.d.ts} +1 -1
  157. package/dist/commands/{game-thresholds.js → shared/thresholds.js} +4 -4
  158. package/dist/commands/{game-time.d.ts → shared/time.d.ts} +4 -4
  159. package/dist/commands/{game-time.js → shared/time.js} +6 -6
  160. package/dist/commands/{game-turn-uses.d.ts → shared/turn-uses.d.ts} +3 -3
  161. package/dist/commands/{game-turn-uses.js → shared/turn-uses.js} +12 -15
  162. package/dist/commands/{game-upkeep.d.ts → shared/upkeep.d.ts} +3 -3
  163. package/dist/commands/{game-upkeep.js → shared/upkeep.js} +69 -57
  164. package/dist/commands/{game-voices.d.ts → shared/voices.d.ts} +1 -1
  165. package/dist/commands/{game-voices.js → shared/voices.js} +2 -2
  166. package/dist/commands/{worked-out.d.ts → shared/worked-out.d.ts} +3 -8
  167. package/dist/commands/{worked-out.js → shared/worked-out.js} +238 -238
  168. package/dist/commands/{game-world.d.ts → shared/world.d.ts} +5 -14
  169. package/dist/commands/{game-world.js → shared/world.js} +72 -76
  170. package/dist/commands/show.d.ts +1 -1
  171. package/dist/commands/show.js +32 -17
  172. package/dist/commands/status.d.ts +1 -1
  173. package/dist/commands/status.js +28 -28
  174. package/dist/commands/thoughts.js +3 -3
  175. package/dist/commands/trade.js +9 -10
  176. package/dist/commands/translate.d.ts +1 -1
  177. package/dist/commands/translate.js +3 -3
  178. package/dist/commands/{game-open.d.ts → travel/open.d.ts} +3 -3
  179. package/dist/commands/{game-open.js → travel/open.js} +4 -5
  180. package/dist/commands/{route.d.ts → travel/route.d.ts} +1 -1
  181. package/dist/commands/{route.js → travel/route.js} +9 -10
  182. package/dist/commands/{travel.d.ts → travel/travel.d.ts} +2 -2
  183. package/dist/commands/{travel.js → travel/travel.js} +19 -21
  184. package/dist/commands/validate.js +5 -5
  185. package/dist/commands/{game-view-journal.d.ts → view/journal.d.ts} +5 -5
  186. package/dist/commands/{game-view-journal.js → view/journal.js} +5 -5
  187. package/dist/commands/{game-view-map.d.ts → view/map.d.ts} +3 -3
  188. package/dist/commands/{game-view-map.js → view/map.js} +15 -16
  189. package/dist/commands/{game-view-place.d.ts → view/place.d.ts} +6 -6
  190. package/dist/commands/{game-view-place.js → view/place.js} +108 -108
  191. package/dist/commands/{view.d.ts → view/view.d.ts} +16 -16
  192. package/dist/commands/{view.js → view/view.js} +35 -35
  193. package/dist/commands/{game-view-world.d.ts → view/world.d.ts} +4 -4
  194. package/dist/commands/{game-view-world.js → view/world.js} +7 -7
  195. package/dist/commands/{game-here.d.ts → write/here.d.ts} +5 -3
  196. package/dist/commands/{game-here.js → write/here.js} +18 -12
  197. package/dist/commands/{write.d.ts → write/write.d.ts} +6 -6
  198. package/dist/commands/{write.js → write/write.js} +44 -41
  199. package/dist/confirm/confirm.d.ts +2 -0
  200. package/dist/confirm/confirm.js +15 -5
  201. package/dist/core/consents.d.ts +3 -2
  202. package/dist/core/consents.js +43 -4
  203. package/dist/core/context.d.ts +8 -6
  204. package/dist/core/context.js +4 -2
  205. package/dist/core/download.js +16 -5
  206. package/dist/core/files.d.ts +6 -1
  207. package/dist/core/files.js +47 -21
  208. package/dist/core/formula.d.ts +7 -2
  209. package/dist/core/formula.js +63 -66
  210. package/dist/core/instruction-parts.js +1 -1
  211. package/dist/core/mood.d.ts +0 -1
  212. package/dist/core/mood.js +3 -3
  213. package/dist/core/package-api.d.ts +11 -0
  214. package/dist/core/package-api.js +2 -1
  215. package/dist/core/package-declarations.d.ts +9 -9
  216. package/dist/core/package-declarations.js +3 -3
  217. package/dist/core/process-mark.d.ts +8 -0
  218. package/dist/core/process-mark.js +72 -0
  219. package/dist/core/registry.d.ts +5 -0
  220. package/dist/core/registry.js +10 -0
  221. package/dist/core/session-store.d.ts +0 -1
  222. package/dist/core/session-store.js +11 -14
  223. package/dist/core/store.d.ts +4 -0
  224. package/dist/core/store.js +29 -8
  225. package/dist/core/text.d.ts +4 -0
  226. package/dist/core/text.js +11 -2
  227. package/dist/core/yaml-file.js +2 -2
  228. package/dist/dashboard/{acts.js → acts/acts.js} +2 -2
  229. package/dist/dashboard/{act-names.js → acts/names.js} +1 -1
  230. package/dist/dashboard/{act-sheet.js → acts/sheet.js} +3 -3
  231. package/dist/dashboard/{act-strip.js → acts/strip.js} +2 -2
  232. package/dist/dashboard/app.js +13 -13
  233. package/dist/dashboard/asked.js +1 -1
  234. package/dist/dashboard/dice/burn.js +1 -1
  235. package/dist/dashboard/dice/stage.js +1 -1
  236. package/dist/dashboard/{guide-blocks.js → help/blocks.js} +1 -1
  237. package/dist/dashboard/{help.js → help/help.js} +6 -6
  238. package/dist/dashboard/journal.js +1 -1
  239. package/dist/dashboard/kit.js +6 -5
  240. package/dist/dashboard/labels.js +7 -3
  241. package/dist/dashboard/markdown.js +1 -1
  242. package/dist/dashboard/{ask-card.js → packages/ask-card.js} +6 -6
  243. package/dist/dashboard/{package-page.js → packages/package-page.js} +3 -3
  244. package/dist/dashboard/{packages.js → packages/packages.js} +12 -12
  245. package/dist/dashboard/{page-code.js → packages/page-code.js} +4 -4
  246. package/dist/dashboard/{extension-widgets.js → packages/widgets.js} +5 -5
  247. package/dist/dashboard/party.js +1 -1
  248. package/dist/dashboard/person-panel.js +2 -13
  249. package/dist/dashboard/{map-sheet.js → place/map-sheet.js} +4 -4
  250. package/dist/dashboard/{place-map-view.js → place/map-view.js} +11 -11
  251. package/dist/dashboard/scene.js +4 -4
  252. package/dist/dashboard/settings.js +1 -1
  253. package/dist/dashboard/sheet.js +3 -3
  254. package/dist/dashboard/top.js +2 -2
  255. package/dist/dashboard/turns.js +2 -2
  256. package/dist/dashboard/widgets.js +1 -1
  257. package/dist/dashboard/{world-calendar.js → world/calendar.js} +7 -7
  258. package/dist/dashboard/{lore.js → world/known.js} +1 -1
  259. package/dist/dashboard/{world-lore.js → world/lore.js} +9 -9
  260. package/dist/dashboard/{world-map.js → world/map.js} +1 -1
  261. package/dist/dashboard/{world.js → world/world.js} +14 -14
  262. package/dist/dice/evaluate.js +1 -1
  263. package/dist/dice/index.d.ts +2 -2
  264. package/dist/dice/index.js +2 -2
  265. package/dist/dice/notation.d.ts +2 -0
  266. package/dist/dice/notation.js +22 -4
  267. package/dist/documents/markup.js +2 -2
  268. package/dist/documents/read.js +29 -13
  269. package/dist/effects/effect.js +2 -5
  270. package/dist/extensions/extension.js +6 -8
  271. package/dist/extensions/index.d.ts +1 -4
  272. package/dist/extensions/index.js +1 -4
  273. package/dist/extensions/words.js +2 -1
  274. package/dist/{pictures → helpers}/briefs.js +17 -14
  275. package/dist/{pictures → helpers}/claude.js +8 -18
  276. package/dist/{pictures → helpers}/codex.js +3 -15
  277. package/dist/helpers/index.d.ts +7 -0
  278. package/dist/helpers/index.js +9 -0
  279. package/dist/{pictures/helpers.d.ts → helpers/programs.d.ts} +6 -1
  280. package/dist/{pictures/helpers.js → helpers/programs.js} +16 -2
  281. package/dist/images/images.js +7 -5
  282. package/dist/images/index.d.ts +1 -1
  283. package/dist/images/index.js +1 -1
  284. package/dist/importer/index.d.ts +1 -1
  285. package/dist/importer/index.js +1 -1
  286. package/dist/importer/work.d.ts +0 -2
  287. package/dist/importer/work.js +9 -30
  288. package/dist/instructions/index.d.ts +2 -0
  289. package/dist/instructions/index.js +10 -0
  290. package/dist/languages/index.d.ts +1 -1
  291. package/dist/languages/index.js +1 -1
  292. package/dist/languages/language-pack.js +15 -3
  293. package/dist/library/books.js +29 -83
  294. package/dist/{extensions → packages}/engine.d.ts +1 -1
  295. package/dist/{extensions → packages}/engine.js +1 -1
  296. package/dist/packages/index.d.ts +3 -0
  297. package/dist/packages/index.js +4 -0
  298. package/dist/{extensions/packages.d.ts → packages/npm.d.ts} +2 -0
  299. package/dist/{extensions/packages.js → packages/npm.js} +74 -45
  300. package/dist/page.d.ts +9 -11
  301. package/dist/page.js +1 -2
  302. package/dist/pages/check.js +31 -40
  303. package/dist/pages/containers.js +20 -20
  304. package/dist/pages/environment.js +15 -15
  305. package/dist/pages/index.d.ts +9 -9
  306. package/dist/pages/index.js +9 -9
  307. package/dist/pages/inheritance.d.ts +2 -1
  308. package/dist/pages/inheritance.js +24 -24
  309. package/dist/pages/load.js +7 -7
  310. package/dist/pages/maps.d.ts +20 -0
  311. package/dist/pages/maps.js +51 -1
  312. package/dist/pages/markdown.d.ts +2 -0
  313. package/dist/pages/markdown.js +110 -79
  314. package/dist/pages/page-file.d.ts +2 -1
  315. package/dist/pages/page-file.js +31 -29
  316. package/dist/pages/rename-page.d.ts +4 -1
  317. package/dist/pages/rename-page.js +7 -3
  318. package/dist/pages/{stack-entry.d.ts → stacks/entry.d.ts} +0 -2
  319. package/dist/pages/{stack-entry.js → stacks/entry.js} +2 -6
  320. package/dist/pages/{stacks.d.ts → stacks/kinds.d.ts} +8 -1
  321. package/dist/pages/{stacks.js → stacks/kinds.js} +36 -41
  322. package/dist/pages/{stack-writes.d.ts → stacks/writes.d.ts} +2 -2
  323. package/dist/pages/{stack-writes.js → stacks/writes.js} +32 -32
  324. package/dist/pages/system-pages.js +15 -15
  325. package/dist/pages/world.js +25 -19
  326. package/dist/pages/write-page.js +35 -34
  327. package/dist/player-notes/index.d.ts +1 -1
  328. package/dist/player-notes/index.js +1 -1
  329. package/dist/rules/page-search.js +3 -4
  330. package/dist/rules/rule-book.js +1 -1
  331. package/dist/rules/search.js +21 -21
  332. package/dist/rules/shown.js +1 -3
  333. package/dist/saves/saves.d.ts +2 -2
  334. package/dist/saves/saves.js +15 -3
  335. package/dist/{bell-listener.js → server/bell-listener.js} +3 -3
  336. package/dist/server/dashboard/files.d.ts +59 -0
  337. package/dist/server/dashboard/files.js +326 -0
  338. package/dist/server/dashboard/index.d.ts +114 -0
  339. package/dist/server/dashboard/index.js +419 -0
  340. package/dist/server/dashboard/news.d.ts +39 -0
  341. package/dist/server/dashboard/news.js +390 -0
  342. package/dist/server/dashboard/player.d.ts +48 -0
  343. package/dist/server/dashboard/player.js +242 -0
  344. package/dist/server/dashboard/ports.d.ts +10 -0
  345. package/dist/server/dashboard/ports.js +15 -0
  346. package/dist/server/dashboard/writes.d.ts +58 -0
  347. package/dist/server/dashboard/writes.js +492 -0
  348. package/dist/{mcp-server.d.ts → server/mcp.d.ts} +2 -2
  349. package/dist/{mcp-server.js → server/mcp.js} +57 -42
  350. package/dist/systems/game-system.d.ts +5 -3
  351. package/dist/systems/game-system.js +178 -149
  352. package/dist/systems/index.d.ts +1 -1
  353. package/dist/systems/index.js +1 -1
  354. package/dist/{testing.d.ts → testing/index.d.ts} +6 -6
  355. package/dist/{testing.js → testing/index.js} +32 -18
  356. package/dist/{system-checks.js → testing/system-checks.js} +18 -12
  357. package/dist/themes/theme.d.ts +3 -3
  358. package/dist/themes/theme.js +14 -14
  359. package/dist/time/calendar.js +5 -2
  360. package/dist/triggers/trigger.js +5 -8
  361. package/instructions/dashboard-guide.md +2 -1
  362. package/instructions/play.md +1 -1
  363. package/package.json +5 -5
  364. package/dist/commands/game-maps.d.ts +0 -20
  365. package/dist/commands/game-maps.js +0 -51
  366. package/dist/dashboard-server.d.ts +0 -47
  367. package/dist/dashboard-server.js +0 -1830
  368. package/dist/pictures/index.d.ts +0 -7
  369. package/dist/pictures/index.js +0 -9
  370. /package/dist/{cli.d.ts → cli/cli.d.ts} +0 -0
  371. /package/dist/{library-reader.d.ts → commands/shared/library-reader.d.ts} +0 -0
  372. /package/dist/commands/{notes.d.ts → shared/notes.d.ts} +0 -0
  373. /package/dist/commands/{notes.js → shared/notes.js} +0 -0
  374. /package/dist/dashboard/{guide-markdown.js → help/markdown.js} +0 -0
  375. /package/dist/dashboard/{pack-card.js → packages/card.js} +0 -0
  376. /package/dist/dashboard/{people.js → packages/people.js} +0 -0
  377. /package/dist/dashboard/{place-map.js → place/map.js} +0 -0
  378. /package/dist/dashboard/{calendar.js → world/days.js} +0 -0
  379. /package/dist/{pictures → helpers}/briefs.d.ts +0 -0
  380. /package/dist/{pictures → helpers}/chosen.d.ts +0 -0
  381. /package/dist/{pictures → helpers}/chosen.js +0 -0
  382. /package/dist/{pictures → helpers}/claude.d.ts +0 -0
  383. /package/dist/{pictures → helpers}/codex.d.ts +0 -0
  384. /package/dist/{pictures → helpers}/stop.d.ts +0 -0
  385. /package/dist/{pictures → helpers}/stop.js +0 -0
  386. /package/dist/{pictures → helpers}/svg.d.ts +0 -0
  387. /package/dist/{pictures → helpers}/svg.js +0 -0
  388. /package/dist/{extensions → packages}/tarball.d.ts +0 -0
  389. /package/dist/{extensions → packages}/tarball.js +0 -0
  390. /package/dist/{bell-listener.d.ts → server/bell-listener.d.ts} +0 -0
  391. /package/dist/{player-acts.d.ts → server/player-acts.d.ts} +0 -0
  392. /package/dist/{player-acts.js → server/player-acts.js} +0 -0
  393. /package/dist/{system-checks.d.ts → testing/system-checks.d.ts} +0 -0
@@ -1,9 +1,9 @@
1
1
  // What the campaign's game system offers of the engine's settings (DAT-16), the settings of its own that a value asks (DAT-17), and the parts its values choose (DAT-18).
2
- import { readSettings, settingNames } from "../campaign/index.js";
3
- import { comparableText } from "../core/text.js";
4
- import { engineOfferings, engineSettingValue, heldSettings, installedSystems, offeredEngineValues, playedValueOf } from "../systems/index.js";
5
- import { campaignSystem, playedSettingValue, valuesText } from "./game-world.js";
2
+ import { readSettings, settingNames } from "../../campaign/index.js";
3
+ import { sameWord } from "../../core/text.js";
4
+ import { engineOfferings, engineSettingValue, heldSettings, offeredEngineValues, playedValueOf, readableSystems } from "../../systems/index.js";
6
5
  import { partText } from "./parts.js";
6
+ import { campaignSystem, playedSettingValue, valuesText } from "./world.js";
7
7
  /** The settings of the system that hold in the campaign, in the system's order (DAT-17): those no value asks, and those a value it plays asks. */
8
8
  export function heldSystemSettings(root, context) {
9
9
  const system = campaignSystem(root, context);
@@ -26,7 +26,7 @@ export function isFixedSetting(root, context, name) {
26
26
  * those the game plays with one value, and with those written with a value it does not offer (DAT-16).
27
27
  */
28
28
  export function missingWithSystems(root, missing, context) {
29
- const names = installedSystems(context.systemFolders).map((system) => system.name);
29
+ const names = readableSystems(context.systemFolders).map((system) => system.name);
30
30
  const system = names.length > 0 ? `system (installed: ${names.join(", ")})` : "system";
31
31
  const written = readSettings(root);
32
32
  const unoffered = (name) => written[name] !== undefined && written[name] !== null && playedEngineSetting(root, context, name) === undefined;
@@ -52,7 +52,7 @@ export function unofferedLines(root, context) {
52
52
  return system === undefined ? [] : settingNames.flatMap((name) => {
53
53
  const value = written[name];
54
54
  const offered = offeredValues(root, context, name);
55
- if (typeof value !== "string" || offered === undefined || offered.length < 2 || offered.some((one) => same(one, value))) {
55
+ if (typeof value !== "string" || offered === undefined || offered.length < 2 || offered.some((one) => sameWord(one, value))) {
56
56
  return [];
57
57
  }
58
58
  return [`${name} ${value} does not go with ${excluding(root, context, name, value)}: ask the player for ${orList(offered)}, then set it with config.`];
@@ -61,7 +61,7 @@ export function unofferedLines(root, context) {
61
61
  /** Why the game takes no such value of an engine's setting (DAT-16), as config refuses it; undefined when it takes it, or offers them all. */
62
62
  export function offerRefusal(root, context, name, value) {
63
63
  const offered = offeredValues(root, context, name);
64
- if (offered === undefined || offered.some((one) => same(one, value))) {
64
+ if (offered === undefined || offered.some((one) => sameWord(one, value))) {
65
65
  return undefined;
66
66
  }
67
67
  return offered.length === 1
@@ -70,7 +70,7 @@ export function offerRefusal(root, context, name, value) {
70
70
  }
71
71
  /** "outcomes told, which offers only narrative or epic": the settings of the system whose values ask a setting of its own (DAT-17), as config names them. */
72
72
  export function askedBy(root, context, name) {
73
- const askers = (campaignSystem(root, context)?.settings ?? []).flatMap((setting) => setting.values.filter((value) => value.asks.some((asked) => same(asked, name))).map((value) => `${setting.name} ${value.value}`));
73
+ const askers = (campaignSystem(root, context)?.settings ?? []).flatMap((setting) => setting.values.filter((value) => value.asks.some((asked) => sameWord(asked, name))).map((value) => `${setting.name} ${value.value}`));
74
74
  return orList(askers);
75
75
  }
76
76
  /** "lethality (narrative, epic)": an engine's setting as the setup asks it, with the values the game offers; undefined when it offers them all. */
@@ -103,16 +103,13 @@ function excluding(root, context, name, value) {
103
103
  const system = campaignSystem(root, context);
104
104
  const offering = system === undefined
105
105
  ? undefined
106
- : engineOfferings(system, played(root, context)).find((one) => Object.entries(one.offers).some(([setting, values]) => same(setting, name) && !values.some((other) => same(other, value))));
106
+ : engineOfferings(system, played(root, context)).find((one) => Object.entries(one.offers).some(([setting, values]) => sameWord(setting, name) && !values.some((other) => sameWord(other, value))));
107
107
  return offering?.from ?? "this game";
108
108
  }
109
109
  /** The value the campaign plays of a setting of its system. */
110
110
  function played(root, context) {
111
111
  return (setting) => playedSettingValue(root, context, setting);
112
112
  }
113
- function same(one, other) {
114
- return comparableText(one) === comparableText(other.trim());
115
- }
116
113
  /** "narrative or epic". */
117
114
  function orList(values) {
118
115
  return values.length === 1 ? values[0] : `${values.slice(0, -1).join(", ")} or ${values.at(-1) ?? ""}`;
@@ -1,6 +1,6 @@
1
- import type { Context } from "../core/context.ts";
2
- import type { OutsideChange } from "../core/session-store.ts";
3
- import { type World } from "../pages/index.ts";
1
+ import type { Context } from "../../core/context.ts";
2
+ import type { OutsideChange } from "../../core/session-store.ts";
3
+ import { type World } from "../../pages/index.ts";
4
4
  /**
5
5
  * What changed outside the chat since its last call (OUT-1–OUT-3): each page with its fields before and after and whether its text changed, campaign.yaml and
6
6
  * state.yaml with their keys, the other files named; a hidden line in the log; and the events it set off, fired from the world `before` it, when known.
@@ -2,15 +2,15 @@
2
2
  // hears it at the head of the next call, the log keeps it hidden, and the planned events it sets off fire as after a command.
3
3
  import { join, relative, sep } from "node:path";
4
4
  import { parse } from "yaml";
5
- import { campaignFileName } from "../campaign/index.js";
6
- import { filesIn } from "../core/files.js";
7
- import { appendLogEntry, logFileName, readLog } from "../core/log.js";
8
- import { files } from "../core/store.js";
9
- import { readFields, splitPageFile, worldFolderName } from "../pages/index.js";
10
- import { fireEvents, nowDueNote } from "./game-events.js";
11
- import { isGameFile } from "./game-saves.js";
12
- import { newDatedLogEntry, readPresent } from "./game-time.js";
13
- import { campaignWorld } from "./game-world.js";
5
+ import { campaignFileName } from "../../campaign/index.js";
6
+ import { filesIn } from "../../core/files.js";
7
+ import { appendLogEntry, logFileName, readLog } from "../../core/log.js";
8
+ import { files } from "../../core/store.js";
9
+ import { readFields, splitPageFile, worldFolderName } from "../../pages/index.js";
10
+ import { fireEvents, nowDueNote } from "./events.js";
11
+ import { isGameFile } from "./saves.js";
12
+ import { newDatedLogEntry, readPresent } from "./time.js";
13
+ import { campaignWorld } from "./world.js";
14
14
  // At most this many changes are named; the rest are counted: a folder rewritten whole would fill the answer.
15
15
  const mostNamed = 10;
16
16
  // The files a command writes before its line in the log is stamped: a file changed this long after the log's last line was changed outside it.
@@ -1,4 +1,4 @@
1
- import type { Context } from "../core/context.ts";
1
+ import type { Context } from "../../../core/context.ts";
2
2
  /** The kinds of packages the catalog lists. */
3
3
  export type CatalogKind = "system" | "adventure" | "extension" | "language";
4
4
  /** A package one may add, as the page lists it (D-486 (3)). */
@@ -43,7 +43,5 @@ export interface InstallableSystem {
43
43
  }
44
44
  /** The game systems npm has that this computer has not, ours first, with ours from the engine's list beside them, npm answering in time or not (D-513 (1)). */
45
45
  export declare function installableSystems(context: Context): Promise<InstallableSystem[]>;
46
- /** The topic a GitHub repository carries to be found as an adventure (D-485 (4)). */
47
- export declare const adventureTopic = "rpg-engine-adventure";
48
46
  /** What npm and GitHub offer now, ours first, then by title; each source asked once, side by side. */
49
47
  export declare function catalog(root: string, context: Context): Promise<Catalog>;
@@ -1,15 +1,16 @@
1
1
  // The catalog of the packages one may add (D-485, D-486): what npm has for this rpg-engine, extensions, game systems and languages, and the adventures
2
2
  // GitHub has by their topic, each with what the player needs to trust it and whether it is here already.
3
3
  import { join } from "node:path";
4
- import { readManifest } from "../adventures/index.js";
5
- import { ourSystems, readsApi } from "../core/package-declarations.js";
6
- import { files } from "../core/store.js";
7
- import { comparableText } from "../core/text.js";
8
- import { isNewerVersion } from "../core/version.js";
9
- import { installedExtensions, isVerified, readExtension, shortName } from "../extensions/index.js";
10
- import { installedLanguages } from "../languages/index.js";
11
- import { systemFolders } from "../systems/index.js";
12
- import { installedAdventures } from "./game-adventures.js";
4
+ import { readManifest } from "../../../adventures/index.js";
5
+ import { ourSystems, readsApi } from "../../../core/package-declarations.js";
6
+ import { files } from "../../../core/store.js";
7
+ import { comparableText } from "../../../core/text.js";
8
+ import { isNewerVersion } from "../../../core/version.js";
9
+ import { installedExtensions, readExtension, shortName } from "../../../extensions/index.js";
10
+ import { installedLanguages } from "../../../languages/index.js";
11
+ import { isVerified } from "../../../packages/index.js";
12
+ import { systemFolders } from "../../../systems/index.js";
13
+ import { installedAdventures } from "../adventures.js";
13
14
  // How long the setup waits for npm before it offers ours alone.
14
15
  const systemsWait = 5000;
15
16
  /** The game systems npm has that this computer has not, ours first, with ours from the engine's list beside them, npm answering in time or not (D-513 (1)). */
@@ -34,24 +35,24 @@ export async function installableSystems(context) {
34
35
  return listed.filter((system) => !here.includes(installedName(system))).sort((first, second) => Number(second.verified) - Number(first.verified) || first.name.localeCompare(second.name));
35
36
  }
36
37
  /** The topic a GitHub repository carries to be found as an adventure (D-485 (4)). */
37
- export const adventureTopic = "rpg-engine-adventure";
38
+ const adventureTopic = "rpg-engine-adventure";
38
39
  // How many repositories are read, each with its adventure.yaml: GitHub answers without a login only so many times an hour.
39
40
  const mostAdventures = 30;
40
41
  const kinds = new Set(["system", "extension", "language"]);
41
42
  /** What npm and GitHub offer now, ours first, then by title; each source asked once, side by side. */
42
43
  export async function catalog(root, context) {
43
- const [npm, github] = await Promise.all([npmEntries(root, context), githubEntries(root, context)]);
44
+ const [npm, github] = await Promise.all([npmEntries(context), githubEntries(root, context)]);
44
45
  const entries = [...npm.entries, ...github.entries].sort((first, second) => Number(second.verified) - Number(first.verified) || first.title.localeCompare(second.title));
45
46
  return { entries, failed: { ...(npm.failed === undefined ? {} : { npm: npm.failed }), ...(github.failed === undefined ? {} : { github: github.failed }) } };
46
47
  }
47
- async function npmEntries(root, context) {
48
+ async function npmEntries(context) {
48
49
  const searched = context.packages === undefined ? { failed: "only the game's server and the command line reach npm" } : await context.packages.search();
49
50
  if ("failed" in searched) {
50
51
  return { entries: [], failed: searched.failed };
51
52
  }
52
53
  // A package made for an API this engine does not read is not offered (D-515).
53
54
  const listed = searched.filter((one) => kinds.has(one.kind ?? "") && (one.kind === "language" || readsApi(one.api, one.kind === "system" ? "system" : "extension")));
54
- return { entries: listed.map((one) => npmEntry(one, installedVersion(root, context, one))) };
55
+ return { entries: listed.map((one) => npmEntry(one, installedVersion(context, one))) };
55
56
  }
56
57
  function npmEntry(found, installed) {
57
58
  const ours = isVerified(found.name, false);
@@ -71,7 +72,7 @@ function npmEntry(found, installed) {
71
72
  };
72
73
  }
73
74
  /** The version of this npm package installed here: an extension's, or a game system's. */
74
- function installedVersion(root, context, found) {
75
+ function installedVersion(context, found) {
75
76
  if (found.kind === "extension") {
76
77
  const here = installedExtensions(context.extensionFolders ?? []).find((one) => one.package === found.name);
77
78
  try {
@@ -85,14 +86,8 @@ function installedVersion(root, context, found) {
85
86
  return installedLanguages(context.extensionFolders ?? []).find((one) => one.package === found.name)?.version;
86
87
  }
87
88
  // A system npm installed, by its package's own version.
88
- const folder = systemFolders(context.systemFolders).find((one) => packageNameIn(one.folder) === found.name)?.folder;
89
- return folder === undefined ? undefined : packageVersionIn(folder);
90
- }
91
- function packageNameIn(folder) {
92
- return packageIn(folder)?.name;
93
- }
94
- function packageVersionIn(folder) {
95
- return packageIn(folder)?.version;
89
+ const folder = systemFolders(context.systemFolders).find((one) => packageIn(one.folder)?.name === found.name)?.folder;
90
+ return folder === undefined ? undefined : packageIn(folder)?.version;
96
91
  }
97
92
  function packageIn(folder) {
98
93
  try {
@@ -1,12 +1,10 @@
1
- import type { CardAsked, Context } from "../core/context.ts";
2
- import type { Asking, Game, GameView, PackageCode } from "../core/package-api.ts";
3
- import type { Problem } from "../core/problem.ts";
4
- import { type Command } from "../core/registry.ts";
5
- import { type CodePackage, type Extension } from "../extensions/index.ts";
6
- import { type GameDate } from "../time/index.ts";
7
- import { type Told } from "./ask.ts";
8
- /** The folder of the campaign where a package keeps its own files, its state among them (D-433, D-436): an extension's, or its game system's. */
9
- export declare const extensionsFolderName = "extensions";
1
+ import type { CardAsked, Context } from "../../../core/context.ts";
2
+ import type { Asking, Game, GameView, PackageCode } from "../../../core/package-api.ts";
3
+ import type { Problem } from "../../../core/problem.ts";
4
+ import { type Command } from "../../../core/registry.ts";
5
+ import { type CodePackage } from "../../../extensions/index.ts";
6
+ import { type GameDate } from "../../../time/index.ts";
7
+ import { type Told } from "../../ask.ts";
10
8
  /** The packages that bring code to the campaign (D-514): its game system first, then its extensions in the order campaign.yaml lists them. */
11
9
  export declare function campaignPackages(root: string, context: Context): CodePackage[];
12
10
  /** The campaign's game system as a package of the campaign (D-514): its package.json's name and version, or, for one that is data alone, its name and the engine's version. */
@@ -17,17 +15,17 @@ export declare function packageLabel(code: CodePackage): string;
17
15
  * The commands of the campaign's packages whose code may run (D-63, D-428, D-441), as commands of rpg-engine: each runs with the game of D-436 and gives the
18
16
  * master its text; by name, the package and version that give it, so that a server knows when another takes its place.
19
17
  */
20
- export declare function packageCommands(root: string, context: Context, taken: string[]): Promise<{
18
+ export declare function packageCommands(root: string, context: Context): Promise<{
21
19
  commands: Command[];
22
20
  sources: Record<string, string>;
23
21
  problems: Problem[];
24
22
  }>;
25
23
  /** The names of a package's commands, its code loaded and checked as the campaign would use it; it throws what keeps it from being used. */
26
- export declare function packageCommandNames(code: CodePackage, context: Context, taken: string[]): Promise<string[]>;
24
+ export declare function packageCommandNames(code: CodePackage, context: Context): Promise<string[]>;
27
25
  /** Tells the loader npm has just installed: code installed again at the same version is read anew. */
28
26
  export declare function packagesInstalled(): void;
29
27
  /** What keeps the code of the campaign's packages from being used, for validate and status: it loads them. */
30
- export declare function packageCodeProblems(root: string, context: Context, taken: string[]): Promise<Problem[]>;
28
+ export declare function packageCodeProblems(root: string, context: Context): Promise<Problem[]>;
31
29
  /**
32
30
  * What the campaign's packages say after time passed from one date to another, or as the game starts, when both are the same (D-436). The time has passed
33
31
  * whatever they do: one that fails says so in its line, never in place of the output.
@@ -55,8 +53,6 @@ export declare function loadCampaignCode(context: Context): Promise<void>;
55
53
  export declare function loadNewSystemCode(context: Context): Promise<void>;
56
54
  /** A package's lines for the master, cut at the most it may say in one call, with a line that says so. */
57
55
  export declare function cappedLines(code: CodePackage, lines: string[]): string[];
58
- /** A package that is an extension. */
59
- export declare function isExtension(code: CodePackage): code is Extension;
60
56
  /**
61
57
  * The game as a package's code reaches it (D-436, D-505, D-514): what a widget reads, the dice, asking the player, its own state, the fields it may write and
62
58
  * the log; nothing else is written. A command's or time's game writes nothing once the call is stopped (ASK-9); a hook's finishes what the engine began.
@@ -12,38 +12,40 @@ import { join } from "node:path";
12
12
  import { fileURLToPath, pathToFileURL } from "node:url";
13
13
  import { parse, stringify } from "yaml";
14
14
  import { z } from "zod";
15
- import { campaignFileName, findCampaign, readTextSetting, requireCampaign } from "../campaign/index.js";
16
- import { installedFromFolder, realPath } from "../core/files.js";
17
- import { parseFormula } from "../core/formula.js";
18
- import { appendLogEntry } from "../core/log.js";
19
- import { defineCommand } from "../core/registry.js";
20
- import { files } from "../core/store.js";
21
- import { sameName, sameWord, valueNamed } from "../core/text.js";
22
- import { getVersion } from "../core/version.js";
23
- import { readCounter } from "../counters/index.js";
24
- import { rollDice } from "../dice/index.js";
25
- import { withEffect } from "../effects/index.js";
26
- import { wordIn } from "../extensions/index.js";
27
- import { concernsPlayer, environmentAt, isInParty, isPartyMember, isPlayerCharacter, locate, pagesWithNameOrAlias, playerCharacters } from "../pages/index.js";
28
- import { givenCode, loadSystemCode, systemHasCode, systemPackage, systemPageModule } from "../systems/index.js";
29
- import { formatGameDate } from "../time/index.js";
30
- import { askedRoll, isCheckDice, tonesOf } from "./ask.js";
31
- import { change } from "./change.js";
32
- import { effectiveFields, effectsOf } from "./effect-layer.js";
33
- import { checkEffectsReadable, saveEffects } from "./game-effects.js";
34
- import { campaignExtensions, packageWords, runsCode } from "./game-extension-list.js";
35
- import { behindTheScreen, sealHiddenRoll } from "./game-master-rolls.js";
36
- import { keepingConditionNote } from "./game-reminders.js";
37
- import { readOpenScene } from "./game-scene.js";
38
- import { calendarDayOf, newDatedLogEntry, presentDate } from "./game-time.js";
39
- import { widgetCard } from "./game-widgets.js";
40
- import { campaignSystem, campaignSystemWords, campaignWorld } from "./game-world.js";
41
- import { formulaValue } from "./worked-out.js";
42
- import { writePackageFields } from "./write.js";
15
+ import { campaignFileName, findCampaign, readTextSetting, requireCampaign } from "../../../campaign/index.js";
16
+ import { installedFromFolder, realPath } from "../../../core/files.js";
17
+ import { parseFormula } from "../../../core/formula.js";
18
+ import { appendLogEntry } from "../../../core/log.js";
19
+ import { commandLineFieldProblem, defineCommand } from "../../../core/registry.js";
20
+ import { files } from "../../../core/store.js";
21
+ import { sameName, sameWord, valueNamed } from "../../../core/text.js";
22
+ import { getVersion } from "../../../core/version.js";
23
+ import { readCounter } from "../../../counters/index.js";
24
+ import { rollDice } from "../../../dice/index.js";
25
+ import { withEffect } from "../../../effects/index.js";
26
+ import { wordIn } from "../../../extensions/index.js";
27
+ import { carriesNamed, concernsPlayer, environmentAt, isInParty, isPartyMember, isPlayerCharacter, locate, pagesWithNameOrAlias, playerCharacters } from "../../../pages/index.js";
28
+ import { givenCode, loadSystemCode, systemHasCode, systemPackage, systemPageModule } from "../../../systems/index.js";
29
+ import { formatGameDate } from "../../../time/index.js";
30
+ import { askedRoll, isCheckDice, tonesOf } from "../../ask.js";
31
+ import { change } from "../../change/change.js";
32
+ import { writePackageFields } from "../../write/write.js";
33
+ import { effectiveFields, effectsOf } from "../effect-layer.js";
34
+ import { checkEffectsReadable, saveEffects } from "../effects.js";
35
+ import { behindTheScreen, sealHiddenRoll } from "../master-rolls.js";
36
+ import { keepingConditionNote } from "../reminders.js";
37
+ import { readOpenScene } from "../scene.js";
38
+ import { calendarDayOf, newDatedLogEntry, presentDate } from "../time.js";
39
+ import { formulaValue } from "../worked-out.js";
40
+ import { campaignSystem, campaignSystemWords, campaignWorld } from "../world.js";
41
+ import { campaignExtensions, packageWords, runsCode } from "./extensions.js";
42
+ import { widgetCard } from "./widgets.js";
43
43
  /** The folder of the campaign where a package keeps its own files, its state among them (D-433, D-436): an extension's, or its game system's. */
44
- export const extensionsFolderName = "extensions";
44
+ const extensionsFolderName = "extensions";
45
45
  /** The longest description a command of a package may give the master, in words (D-441): it is read in every chat. */
46
46
  const descriptionWords = 150;
47
+ // The longest a package's timePassed may take, a question to the player included: past it, or after the call is stopped, the time has passed all the same.
48
+ const longestPackageWait = 10 * 60 * 1000;
47
49
  /** The packages that bring code to the campaign (D-514): its game system first, then its extensions in the order campaign.yaml lists them. */
48
50
  export function campaignPackages(root, context) {
49
51
  const system = campaignSystemPackage(root, context);
@@ -62,7 +64,8 @@ export function packageLabel(code) {
62
64
  * The commands of the campaign's packages whose code may run (D-63, D-428, D-441), as commands of rpg-engine: each runs with the game of D-436 and gives the
63
65
  * master its text; by name, the package and version that give it, so that a server knows when another takes its place.
64
66
  */
65
- export async function packageCommands(root, context, taken) {
67
+ export async function packageCommands(root, context) {
68
+ const taken = await engineCommandNames();
66
69
  const commands = [];
67
70
  const sources = {};
68
71
  const problems = [];
@@ -85,7 +88,8 @@ export async function packageCommands(root, context, taken) {
85
88
  return { commands, sources, problems };
86
89
  }
87
90
  /** The names of a package's commands, its code loaded and checked as the campaign would use it; it throws what keeps it from being used. */
88
- export async function packageCommandNames(code, context, taken) {
91
+ export async function packageCommandNames(code, context) {
92
+ const taken = await engineCommandNames();
89
93
  const names = [];
90
94
  for (const command of (await packageCode(code, context))?.commands ?? []) {
91
95
  names.push(asCommand(code, command, [...taken, ...names]).name);
@@ -97,8 +101,8 @@ export function packagesInstalled() {
97
101
  installs += 1;
98
102
  }
99
103
  /** What keeps the code of the campaign's packages from being used, for validate and status: it loads them. */
100
- export async function packageCodeProblems(root, context, taken) {
101
- return (await packageCommands(root, context, taken)).problems;
104
+ export async function packageCodeProblems(root, context) {
105
+ return [...(await packageCommands(root, context)).problems, ...packageStateProblems(root, context)];
102
106
  }
103
107
  /**
104
108
  * What the campaign's packages say after time passed from one date to another, or as the game starts, when both are the same (D-436). The time has passed
@@ -110,12 +114,22 @@ export async function timePassedLines(root, context, from, to) {
110
114
  try {
111
115
  const given = await packageCode(code, context);
112
116
  if (given?.timePassed !== undefined) {
113
- lines.push(...cappedLines(code, await given.timePassed({ from: momentOf(root, context, from), to: momentOf(root, context, to) }, gameOf(root, context, code))));
117
+ // Its own stop, which the cap and the call's own stop both give: past either, its game writes nothing more.
118
+ const own = new AbortController();
119
+ const signal = context.signal === undefined ? own.signal : AbortSignal.any([context.signal, own.signal]);
120
+ const game = gameOf(root, { ...context, signal }, code);
121
+ const said = await withinCall(given.timePassed({ from: momentOf(root, context, from), to: momentOf(root, context, to) }, game), signal, () => own.abort());
122
+ if (said !== undefined && (!Array.isArray(said) || !said.every((line) => typeof line === "string"))) {
123
+ throw new Error("its timePassed gave no list of lines, which is what it gives");
124
+ }
125
+ lines.push(...cappedLines(code, (said ?? [])));
114
126
  }
115
127
  }
116
128
  catch (error) {
117
- // One line: the master reads it among others.
118
- lines.push(`The ${packageLabel(code)} failed after the time passed: ${firstLine(error)}. The time did pass: do not advance again; validate says how to fix it.`);
129
+ // One line: the master reads it among others; a call the player stopped is no fault of the package's.
130
+ lines.push(error instanceof StoppedCall
131
+ ? `The ${packageLabel(code)} gave nothing before the call was stopped. The time did pass: do not advance again.`
132
+ : `The ${packageLabel(code)} failed after the time passed: ${firstLine(error)}. The time did pass: do not advance again; validate says how to fix it.`);
119
133
  }
120
134
  }
121
135
  return lines;
@@ -162,7 +176,7 @@ export async function loadCampaignCode(context) {
162
176
  try {
163
177
  const root = findCampaign(context.folder);
164
178
  if (root !== undefined) {
165
- await packageCommands(root, context, []);
179
+ await packageCommands(root, context);
166
180
  }
167
181
  }
168
182
  catch {
@@ -192,9 +206,6 @@ export async function loadNewSystemCode(context) {
192
206
  await loadCampaignCode(context);
193
207
  }
194
208
  }
195
- /** The most a package says in one call, after the engine's writes or as time passes, in lines and in characters; what is more is cut, with a line. */
196
- const mostLines = 5;
197
- const mostCharacters = 600;
198
209
  /** A package's lines for the master, cut at the most it may say in one call, with a line that says so. */
199
210
  export function cappedLines(code, lines) {
200
211
  const kept = [];
@@ -208,10 +219,6 @@ export function cappedLines(code, lines) {
208
219
  }
209
220
  return kept;
210
221
  }
211
- /** A package that is an extension. */
212
- export function isExtension(code) {
213
- return code.kind === "extension";
214
- }
215
222
  /**
216
223
  * The game as a package's code reaches it (D-436, D-505, D-514): what a widget reads, the dice, asking the player, its own state, the fields it may write and
217
224
  * the log; nothing else is written. A command's or time's game writes nothing once the call is stopped (ASK-9); a hook's finishes what the engine began.
@@ -248,10 +255,11 @@ export function gameOf(root, context, code, options = {}) {
248
255
  },
249
256
  change: (page, field, amount, why) => {
250
257
  live();
251
- const result = change.run(change.input.parse({ page, field, ...amount, why }), context);
252
- // The change of a counter is made at once; only a rest's dice wait, which change is not given here.
258
+ // By, to or spend alone, as the kit's types say: never a recipe or faces, which code written by hand could slip in.
259
+ const { by, to, spend } = amount;
260
+ const result = change.run(change.input.parse({ page, field, by, to, spend, why }), context);
253
261
  if (result instanceof Promise) {
254
- throw new Error("game.change changes a counter or money at once: give it by, to or spend, never a recipe. Nothing changed.");
262
+ throw new Error("game.change changes a counter or money at once: give it by, to or spend. Nothing changed.");
255
263
  }
256
264
  return change.format(result);
257
265
  },
@@ -265,7 +273,7 @@ export function gameOf(root, context, code, options = {}) {
265
273
  const { who, question, check, notation } = wanted;
266
274
  const told = toldOf(root, context, code, wanted, who);
267
275
  asked.card = told.card ?? asked.card;
268
- return askedOf(await askedRoll(root, context, askedQuestion(packageText(root, code, question), check, notation), [{ label: check.trim(), notation }], who, told));
276
+ return askedOf(await askedRoll(root, context, askedQuestion(packageText(root, code, question), check, notation), [{ label: packageText(root, code, check.trim()), notation }], who, told));
269
277
  })();
270
278
  },
271
279
  state: {
@@ -323,7 +331,7 @@ export function gameViewOf(root, context, code) {
323
331
  setting: (name) => readTextSetting(root, name),
324
332
  // A name in the campaign's language is the system's by its words, Prono its Prone (D-403).
325
333
  sameName: (one, other) => sameWord(one, other, campaignSystemWords(root, context)),
326
- state: { read: () => parse(files().text(statePath(root, code)) ?? "null") },
334
+ state: { read: () => readPackageState(root, code) },
327
335
  };
328
336
  }
329
337
  /**
@@ -351,6 +359,26 @@ export function toldOf(root, context, code, wanted, who) {
351
359
  export function firstLine(error) {
352
360
  return (error instanceof Error ? error.message : String(error)).split("\n")[0].replace(/[:.]$/, "");
353
361
  }
362
+ /**
363
+ * A system's code as the engine loaded it, or why it is not there: not loaded, loaded at another version than the one installed now, refused or broken; undefined
364
+ * when it brings none.
365
+ */
366
+ /** Whether a package's code is refused, as another's without the player's yes, one made for another API or with commands refused: said once, not at each call. */
367
+ export function codeRefused(code, context) {
368
+ const loaded = context.systemCode?.[code.name];
369
+ return isExtension(code) ? refused.has(codeKey(code)) : loaded !== undefined && "refused" in loaded;
370
+ }
371
+ /** The names of rpg-engine's own commands, which no package's command may take; read when needed, as the list of commands holds this module. */
372
+ async function engineCommandNames() {
373
+ return (await import("../../index.js")).commands.map((command) => command.name);
374
+ }
375
+ /** The most a package says in one call, after the engine's writes or as time passes, in lines and in characters; what is more is cut, with a line. */
376
+ const mostLines = 5;
377
+ const mostCharacters = 600;
378
+ /** A package that is an extension. */
379
+ function isExtension(code) {
380
+ return code.kind === "extension";
381
+ }
354
382
  function systemCodePackage(system) {
355
383
  const own = systemPackage(system.folder);
356
384
  const page = systemPageModule(system.folder);
@@ -371,6 +399,7 @@ function systemCodePackage(system) {
371
399
  }
372
400
  /** A command of a package as a command of rpg-engine, refused when its name is not the package's or is taken, or its description is too long. */
373
401
  function asCommand(code, command, taken) {
402
+ checkCommandShape(command);
374
403
  const name = command.name.trim();
375
404
  const words = command.description.split(/\s+/).length;
376
405
  if (name !== code.name && !name.startsWith(`${code.name}-`)) {
@@ -395,7 +424,11 @@ function asCommand(code, command, taken) {
395
424
  const campaign = requireCampaign(called.folder);
396
425
  const asked = {};
397
426
  try {
398
- return { text: await command.run(input, gameOf(campaign, called, code, { asked })) };
427
+ const text = await command.run(input, gameOf(campaign, called, code, { asked }));
428
+ if (typeof text !== "string") {
429
+ throw new Error(`The extension ${code.package}'s command ${name} gave no text: a command gives the master its answer as text. Tell its author.`);
430
+ }
431
+ return { text };
399
432
  }
400
433
  finally {
401
434
  // The card of its last question, as it is after the dice, read once the call ends, however it ends (D-507).
@@ -407,6 +440,57 @@ function asCommand(code, command, taken) {
407
440
  format: (result) => result.text,
408
441
  });
409
442
  }
443
+ /** A call the player stopped while a package's code had not answered. */
444
+ class StoppedCall extends Error {
445
+ }
446
+ /** What a package's code gives, unless the call is stopped first or it takes longer than any answer of the player's should: then why not. */
447
+ async function withinCall(work, signal, giveUp) {
448
+ // Never a rejection that nothing handles, when it ends after the call went on without it.
449
+ Promise.resolve(work).catch(() => undefined);
450
+ let timer;
451
+ let abort = () => undefined;
452
+ const stopped = new Promise((_, refuse) => {
453
+ timer = setTimeout(() => {
454
+ refuse(new Error(`it gave nothing for ${longestPackageWait / 60_000} minutes`));
455
+ giveUp();
456
+ }, longestPackageWait);
457
+ abort = () => refuse(new StoppedCall("the call was stopped before it gave anything"));
458
+ if (signal?.aborted === true) {
459
+ abort();
460
+ }
461
+ signal?.addEventListener("abort", abort, { once: true });
462
+ });
463
+ try {
464
+ return await Promise.race([Promise.resolve(work), stopped]);
465
+ }
466
+ finally {
467
+ clearTimeout(timer);
468
+ signal?.removeEventListener("abort", abort);
469
+ }
470
+ }
471
+ /** A package's command as its code must give it, for an author who writes it by hand: refused with the shape it takes. */
472
+ function checkCommandShape(command) {
473
+ const given = command;
474
+ const name = typeof given.name === "string" ? given.name.trim() : "";
475
+ if (name === "") {
476
+ throw new Error("a command has no name: give each command a name, the package's or one starting with it");
477
+ }
478
+ if (typeof given.description !== "string" || given.description.trim() === "") {
479
+ throw new Error(`its command ${name} has no description: give it one, written for an AI`);
480
+ }
481
+ if (!(given.input instanceof z.ZodObject)) {
482
+ throw new Error(`its command ${name} gives its input in another shape: give it as z.object({...}), with the z the kit gives`);
483
+ }
484
+ if (typeof given.run !== "function") {
485
+ throw new Error(`its command ${name} has no run: give it run(input, game), which gives its answer as text`);
486
+ }
487
+ // A field the command line would read as something else is refused at once, never lost when the command runs.
488
+ const positionals = Array.isArray(given.positionals) ? given.positionals : [];
489
+ const problem = Object.keys(given.input.shape).map((field) => commandLineFieldProblem(`its command ${name}`, field, positionals.includes(field))).find((found) => found !== undefined);
490
+ if (problem !== undefined) {
491
+ throw new Error(problem.replace(/: rename it\.$/, ": rename it"));
492
+ }
493
+ }
410
494
  // The code of each extension, by its file and version, loaded once for the process: an import is never undone, a new version is another. What each gave,
411
495
  // once loaded, is kept apart too, for the hooks the commands call at once.
412
496
  const loaded = new Map();
@@ -435,15 +519,6 @@ function extensionCode(extension) {
435
519
  function codeKey(code) {
436
520
  return `${code.package}@${code.version}#${installs}`;
437
521
  }
438
- /**
439
- * A system's code as the engine loaded it, or why it is not there: not loaded, loaded at another version than the one installed now, refused or broken; undefined
440
- * when it brings none.
441
- */
442
- /** Whether a package's code is refused, as another's without the player's yes, one made for another API or with commands refused: said once, not at each call. */
443
- export function codeRefused(code, context) {
444
- const loaded = context.systemCode?.[code.name];
445
- return isExtension(code) ? refused.has(codeKey(code)) : loaded !== undefined && "refused" in loaded;
446
- }
447
522
  function systemCode(code, context) {
448
523
  if (!systemHasCode(code.folder)) {
449
524
  return undefined;
@@ -478,6 +553,27 @@ function momentOf(root, context, date) {
478
553
  function statePath(root, code) {
479
554
  return join(root, extensionsFolderName, code.name, "state.yaml");
480
555
  }
556
+ /** A package's state as its code reads it; it throws, naming the file and how to fix it, when the file does not read. */
557
+ function readPackageState(root, code) {
558
+ const read = parsedState(root, code);
559
+ if (read.problem !== undefined) {
560
+ throw new Error(`${read.problem.path} does not read: ${read.problem.message} Fix: ${read.problem.fix}.`);
561
+ }
562
+ return read.value;
563
+ }
564
+ /** The packages' state files that do not read, which only their code reads, for validate. */
565
+ function packageStateProblems(root, context) {
566
+ return campaignPackages(root, context).flatMap((code) => parsedState(root, code).problem ?? []);
567
+ }
568
+ function parsedState(root, code) {
569
+ try {
570
+ return { value: parse(files().text(statePath(root, code)) ?? "null") };
571
+ }
572
+ catch (error) {
573
+ const fix = `correct it by hand, or delete it for the ${packageLabel(code)} to start its state again`;
574
+ return { problem: { path: `${extensionsFolderName}/${code.name}/state.yaml`, message: `${firstLine(error)}.`, fix } };
575
+ }
576
+ }
481
577
  /**
482
578
  * A page as a package reads it (D-505): in the party or not, the player's or not, its fields as show gives them, effects and what the system works out included;
483
579
  * an effect it has by the system's name or its word in the campaign's language (D-403).
@@ -494,6 +590,7 @@ function gamePage(world, page, words) {
494
590
  return counter === undefined ? undefined : { value: counter.value, ...(counter.max === undefined ? {} : { max: counter.max }) };
495
591
  },
496
592
  has: (effect) => effectsOf(page).some((one) => sameWord(effect, one.name, words)),
593
+ carries: (thing) => carriesNamed(world, page, thing, (one, other) => sameWord(one, other, words)),
497
594
  formula: (text) => {
498
595
  let formula;
499
596
  try {
@@ -1,9 +1,9 @@
1
- import type { Context } from "../core/context.ts";
2
- import type { InstructionPart } from "../core/instruction-parts.ts";
3
- import type { Problem } from "../core/problem.ts";
4
- import { type CodePackage, type Extension, type ExtensionWords } from "../extensions/index.ts";
5
- import type { FigureSize } from "../page.ts";
6
- import { type GameSystem } from "../systems/index.ts";
1
+ import type { Context } from "../../../core/context.ts";
2
+ import type { InstructionPart } from "../../../core/instruction-parts.ts";
3
+ import type { FigureSize } from "../../../core/package-api.ts";
4
+ import type { Problem } from "../../../core/problem.ts";
5
+ import { type CodePackage, type Extension, type ExtensionWords } from "../../../extensions/index.ts";
6
+ import { type GameSystem } from "../../../systems/index.ts";
7
7
  /** The extensions the campaign uses, and what keeps one from being used, with how to fix it. */
8
8
  export interface CampaignExtensions {
9
9
  extensions: Extension[];