rpg-engine 0.9.1 → 0.11.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 (171) hide show
  1. package/README.md +1 -1
  2. package/dist/adventures/placement.js +4 -0
  3. package/dist/adventures/source.js +6 -5
  4. package/dist/campaign/find-campaign.js +18 -0
  5. package/dist/campaign/host-files.js +8 -6
  6. package/dist/campaign/index.d.ts +1 -1
  7. package/dist/campaign/index.js +1 -1
  8. package/dist/campaign/settings.d.ts +2 -0
  9. package/dist/campaign/settings.js +12 -5
  10. package/dist/commands/advance.js +1 -1
  11. package/dist/commands/ask.js +1 -1
  12. package/dist/commands/config.js +21 -32
  13. package/dist/commands/import/import.js +1 -1
  14. package/dist/commands/instructions.js +1 -1
  15. package/dist/commands/mode.js +1 -1
  16. package/dist/commands/mood.js +2 -3
  17. package/dist/commands/move.js +1 -1
  18. package/dist/commands/package.d.ts +3 -3
  19. package/dist/commands/package.js +74 -37
  20. package/dist/commands/reveal.js +1 -1
  21. package/dist/commands/roll/roll.js +6 -12
  22. package/dist/commands/rules.js +0 -1
  23. package/dist/commands/scene.js +6 -8
  24. package/dist/commands/shared/adventures.js +21 -12
  25. package/dist/commands/shared/images.js +3 -1
  26. package/dist/commands/shared/knowledge.d.ts +8 -0
  27. package/dist/commands/shared/knowledge.js +41 -18
  28. package/dist/commands/shared/library.js +13 -5
  29. package/dist/commands/shared/mode.d.ts +7 -4
  30. package/dist/commands/shared/mode.js +28 -15
  31. package/dist/commands/shared/packages/catalog.d.ts +2 -0
  32. package/dist/commands/shared/packages/catalog.js +1 -0
  33. package/dist/commands/shared/packages/code.js +13 -2
  34. package/dist/commands/shared/page-words.d.ts +2 -0
  35. package/dist/commands/shared/page-words.js +13 -0
  36. package/dist/commands/shared/sheet.d.ts +3 -2
  37. package/dist/commands/shared/sheet.js +8 -5
  38. package/dist/commands/show.js +1 -1
  39. package/dist/commands/status.js +9 -5
  40. package/dist/commands/view/place.d.ts +2 -0
  41. package/dist/commands/view/place.js +17 -5
  42. package/dist/commands/write/write.js +4 -3
  43. package/dist/core/archive-paths.js +1 -1
  44. package/dist/core/context.d.ts +2 -0
  45. package/dist/core/package-api.d.ts +1 -1
  46. package/dist/core/package-declarations.d.ts +3 -3
  47. package/dist/core/package-declarations.js +3 -3
  48. package/dist/core/refusal.d.ts +12 -0
  49. package/dist/core/refusal.js +17 -0
  50. package/dist/core/store.d.ts +4 -0
  51. package/dist/core/store.js +20 -1
  52. package/dist/dashboard/api.js +37 -81
  53. package/dist/dashboard/app.js +10 -3
  54. package/dist/dashboard/asked.js +6 -3
  55. package/dist/dashboard/assets/master.svg +1 -2
  56. package/dist/dashboard/card.js +1 -1
  57. package/dist/dashboard/dice/load.js +6 -1
  58. package/dist/dashboard/dice/throw.js +5 -1
  59. package/dist/dashboard/dice/tray.js +5 -1
  60. package/dist/dashboard/footer.js +2 -2
  61. package/dist/dashboard/game-words.js +32 -32
  62. package/dist/dashboard/guide/ar.md +17 -17
  63. package/dist/dashboard/guide/cs.md +17 -17
  64. package/dist/dashboard/guide/da.md +16 -16
  65. package/dist/dashboard/guide/de.md +15 -15
  66. package/dist/dashboard/guide/el.md +19 -19
  67. package/dist/dashboard/guide/en.md +4 -4
  68. package/dist/dashboard/guide/es.md +17 -17
  69. package/dist/dashboard/guide/fi.md +19 -19
  70. package/dist/dashboard/guide/fr.md +16 -16
  71. package/dist/dashboard/guide/he.md +16 -16
  72. package/dist/dashboard/guide/hi.md +20 -20
  73. package/dist/dashboard/guide/hu.md +18 -18
  74. package/dist/dashboard/guide/is.md +16 -16
  75. package/dist/dashboard/guide/it.md +7 -7
  76. package/dist/dashboard/guide/ja.md +17 -17
  77. package/dist/dashboard/guide/ko.md +22 -22
  78. package/dist/dashboard/guide/nb.md +17 -17
  79. package/dist/dashboard/guide/nl.md +19 -19
  80. package/dist/dashboard/guide/pl.md +18 -18
  81. package/dist/dashboard/guide/pt.md +13 -13
  82. package/dist/dashboard/guide/ro.md +19 -19
  83. package/dist/dashboard/guide/ru.md +17 -17
  84. package/dist/dashboard/guide/sv.md +16 -16
  85. package/dist/dashboard/guide/tr.md +21 -21
  86. package/dist/dashboard/guide/uk.md +16 -16
  87. package/dist/dashboard/guide/zh.md +20 -20
  88. package/dist/dashboard/help/blocks.js +6 -0
  89. package/dist/dashboard/help/help.js +15 -3
  90. package/dist/dashboard/help/markdown.js +2 -1
  91. package/dist/dashboard/i18n/ar.json +54 -1
  92. package/dist/dashboard/i18n/cs.json +54 -1
  93. package/dist/dashboard/i18n/da.json +54 -1
  94. package/dist/dashboard/i18n/de.json +54 -1
  95. package/dist/dashboard/i18n/el.json +54 -1
  96. package/dist/dashboard/i18n/es.json +54 -1
  97. package/dist/dashboard/i18n/fi.json +54 -1
  98. package/dist/dashboard/i18n/fr.json +54 -1
  99. package/dist/dashboard/i18n/he.json +54 -1
  100. package/dist/dashboard/i18n/hi.json +54 -1
  101. package/dist/dashboard/i18n/hu.json +54 -1
  102. package/dist/dashboard/i18n/is.json +54 -1
  103. package/dist/dashboard/i18n/it.json +57 -4
  104. package/dist/dashboard/i18n/ja.json +54 -1
  105. package/dist/dashboard/i18n/ko.json +54 -1
  106. package/dist/dashboard/i18n/nb.json +54 -1
  107. package/dist/dashboard/i18n/nl.json +54 -1
  108. package/dist/dashboard/i18n/pl.json +54 -1
  109. package/dist/dashboard/i18n/pt.json +54 -1
  110. package/dist/dashboard/i18n/ro.json +54 -1
  111. package/dist/dashboard/i18n/ru.json +54 -1
  112. package/dist/dashboard/i18n/sv.json +54 -1
  113. package/dist/dashboard/i18n/tr.json +54 -1
  114. package/dist/dashboard/i18n/uk.json +54 -1
  115. package/dist/dashboard/i18n/zh.json +54 -1
  116. package/dist/dashboard/icons.js +2 -2
  117. package/dist/dashboard/journal.js +9 -4
  118. package/dist/dashboard/labels.js +5 -4
  119. package/dist/dashboard/language-choice.js +3 -3
  120. package/dist/dashboard/markdown.js +11 -4
  121. package/dist/dashboard/notes.js +4 -2
  122. package/dist/dashboard/notices.js +2 -2
  123. package/dist/dashboard/packages/ask-card.js +1 -1
  124. package/dist/dashboard/packages/packages.js +14 -10
  125. package/dist/dashboard/packages/page-code.js +11 -3
  126. package/dist/dashboard/packages/widgets.js +5 -5
  127. package/dist/dashboard/pages.js +3 -3
  128. package/dist/dashboard/place/map-sheet.js +4 -3
  129. package/dist/dashboard/place/map-view.js +17 -5
  130. package/dist/dashboard/refusals.js +61 -0
  131. package/dist/dashboard/rolls.js +3 -3
  132. package/dist/dashboard/settings.js +19 -5
  133. package/dist/dashboard/sheet.js +26 -7
  134. package/dist/dashboard/status.js +19 -13
  135. package/dist/dashboard/style.css +113 -16
  136. package/dist/dashboard/text.js +6 -2
  137. package/dist/dashboard/top.js +7 -9
  138. package/dist/dashboard/turns.js +7 -2
  139. package/dist/dashboard/world/lore.js +16 -15
  140. package/dist/dashboard/world/map.js +43 -1
  141. package/dist/dashboard/world/world.js +50 -15
  142. package/dist/dice/index.d.ts +1 -1
  143. package/dist/dice/oracle.d.ts +5 -3
  144. package/dist/dice/oracle.js +7 -6
  145. package/dist/extensions/extension.js +4 -1
  146. package/dist/helpers/codex.js +1 -1
  147. package/dist/packages/npm.js +17 -4
  148. package/dist/packages/tarball.js +8 -4
  149. package/dist/pages/index.d.ts +1 -1
  150. package/dist/pages/index.js +1 -1
  151. package/dist/pages/markdown.d.ts +2 -0
  152. package/dist/pages/markdown.js +21 -0
  153. package/dist/pages/world.js +4 -0
  154. package/dist/server/dashboard/index.js +8 -4
  155. package/dist/server/dashboard/writes.js +22 -13
  156. package/dist/server/mcp.d.ts +3 -1
  157. package/dist/server/mcp.js +20 -5
  158. package/dist/systems/game-system.d.ts +2 -0
  159. package/dist/systems/game-system.js +2 -0
  160. package/dist/systems/system-code.js +5 -0
  161. package/instructions/adventure.md +1 -1
  162. package/instructions/combat.md +1 -1
  163. package/instructions/core.md +2 -2
  164. package/instructions/import.md +1 -0
  165. package/instructions/session-zero.md +1 -1
  166. package/instructions/session.md +1 -1
  167. package/instructions/setup.md +1 -1
  168. package/package.json +2 -2
  169. package/systems/free/instructions/outcomes-rolled.md +1 -1
  170. package/systems/free/instructions/outcomes-tossed.md +1 -1
  171. package/systems/free/instructions/play.md +1 -2
@@ -61,13 +61,18 @@ export function WorldView({ version, lead, players, tab, item }) {
61
61
  const shown = world === null ? ["map"] : worldTabs;
62
62
  const chosen = shown.find((one) => one === tab) ?? "map";
63
63
  const names = { map: t("Map"), lore: t("Lore"), documents: t("Documents"), calendar: t("Calendar") };
64
- // A page of the lore that is a spot on the map leads there; a place on the map to all the character knows of it.
64
+ // A page of the lore that is on the map, a place, a region or a way, leads there; a place on the map to all the character knows of it.
65
65
  const onMap = (places) => {
66
- const spot = places.find((place) => map?.places.some((one) => one.name === place && one.x !== undefined && one.radius === undefined));
66
+ const spot = places.find((place) => map?.places.some((one) => one.name === place && one.x !== undefined) || map?.roads.some((road) => road.name === place));
67
67
  return spot === undefined ? undefined : sectionAddress("world", "map", spot);
68
68
  };
69
+ // What a region or a way is, by its name, as the map's list says it, for the lore (D-548).
70
+ const kinds = useMemo(() => new Map([
71
+ ...(map?.places ?? []).filter((one) => one.radius !== undefined).map((one) => [one.name, [t("Region"), biomeLabel(one.biome)].filter((part) => part !== undefined).join(" · ")]),
72
+ ...(map?.roads ?? []).map((road) => [road.name, wayLabel(road.kind)]),
73
+ ]), [map]);
69
74
  const readMore = (place) => world?.known.some((entry) => entry.name === place) ? sectionAddress("world", "lore", place) : undefined;
70
- return (_jsxs("section", { class: "world", "aria-labelledby": "world-title", children: [_jsx(PageHead, { section: "world", id: "world-title" }), shown.length > 1 && _jsx(PageTabs, { section: "world", label: t("World"), chosen: chosen, tabs: shown.map((key) => ({ key, name: names[key] })) }), _jsxs("div", { class: "world-panel", id: "world-panel", ...(shown.length > 1 ? { role: "tabpanel", "aria-labelledby": `world-tab-${chosen}` } : {}), children: [chosen === "map" && _jsx(MapTab, { map: map, problem: problem, lead: lead, place: item, readMore: readMore }), chosen !== "map" && world === undefined && _jsx("p", { class: "browse-none", children: worldProblem ?? t("Reading…") }), chosen === "lore" && world && _jsx(LoreTab, { world: world, version: version, open: item, onMap: onMap, ...(players === undefined ? {} : { players }) }), chosen === "documents" && world && _jsx(DocumentsTab, { world: world, open: item, ...(players === undefined ? {} : { players }) }), chosen === "calendar" && world && _jsx(CalendarTab, { calendar: world.calendar })] }), _jsx(WidgetCards, { place: "page", page: "world" })] }));
75
+ return (_jsxs("section", { class: "world", "aria-labelledby": "world-title", children: [_jsx(PageHead, { section: "world", id: "world-title" }), shown.length > 1 && _jsx(PageTabs, { section: "world", label: t("World"), chosen: chosen, tabs: shown.map((key) => ({ key, name: names[key] })) }), _jsxs("div", { class: "world-panel", id: "world-panel", ...(shown.length > 1 ? { role: "tabpanel", "aria-labelledby": `world-tab-${chosen}` } : {}), children: [chosen === "map" && _jsx(MapTab, { map: map, problem: problem, lead: lead, place: item, readMore: readMore }), chosen !== "map" && world === undefined && _jsx("p", { class: "browse-none", children: worldProblem ?? t("Reading…") }), chosen === "lore" && world && _jsx(LoreTab, { world: world, version: version, open: item, onMap: onMap, kinds: kinds, ...(players === undefined ? {} : { players }) }), chosen === "documents" && world && _jsx(DocumentsTab, { world: world, open: item, ...(players === undefined ? {} : { players }) }), chosen === "calendar" && world && _jsx(CalendarTab, { calendar: world.calendar })] }), _jsx(WidgetCards, { place: "page", page: "world" })] }));
71
76
  }
72
77
  /** The world map's tab: the map's card, and the places as a list, its twin; `place` opens one on its own map, as the lore's Show on the map. */
73
78
  function MapTab({ map, problem, lead, place, readMore }) {
@@ -90,11 +95,11 @@ function MapTab({ map, problem, lead, place, readMore }) {
90
95
  setFocus((before) => ({ name: to, count: before.count + 1 }));
91
96
  }
92
97
  };
93
- // A place the address names, on its own map, its card open.
98
+ // A place, a region or a way the address names, on its own map: a place with its card open, a region or a way marked.
94
99
  useEffect(() => {
95
- const spot = place === undefined ? undefined : map?.places.find((one) => one.name === place && one.x !== undefined);
96
- if (map !== undefined && spot !== undefined) {
97
- goTo(mapNameOf(map, spot), spot.name);
100
+ const there = map === undefined || place === undefined ? undefined : mapHolding(map, place);
101
+ if (there !== undefined && place !== undefined) {
102
+ goTo(there, place);
98
103
  // The map in sight, wherever the page was scrolled to in the lore.
99
104
  requestAnimationFrame(() => document.querySelector(".map-card")?.scrollIntoView({ block: "start" }));
100
105
  }
@@ -112,7 +117,7 @@ function MapTab({ map, problem, lead, place, readMore }) {
112
117
  location.replace(sectionAddress("world"));
113
118
  }
114
119
  };
115
- return (_jsxs("div", { class: "world-map", children: [_jsx(MapCard, { map: drawn, full: map, part: part, layout: layout, lead: lead, chosen: chosen, focus: focus, onChoose: choose, onGo: goTo, readMore: readMore }, part.name), _jsx(PlacesList, { map: drawn, layout: layout, onChoose: choose })] }));
120
+ return (_jsxs("div", { class: "world-map", children: [_jsx(MapCard, { map: drawn, full: map, part: part, layout: layout, lead: lead, chosen: chosen, focus: focus, onChoose: choose, onGo: goTo, readMore: readMore }, part.name), _jsx(PlacesList, { map: drawn, full: map, layout: layout, onChoose: choose })] }));
116
121
  }
117
122
  /**
118
123
  * The map's card: its head, with the maps the character knows as tabs; the map with its tools and the card of the chosen place; the key under it. `map` is what
@@ -151,15 +156,17 @@ function MapCard({ map, full, part, layout, lead, chosen, focus, onChoose, onGo,
151
156
  observer.observe(element);
152
157
  return () => observer.disconnect();
153
158
  }, []);
154
- // The first view: all the character knows; on a phone, the land around the party.
159
+ // The first view: all the character knows; on a phone, the land around the party; with a place already chosen, as from the Lore's Show on the map, that place.
155
160
  useEffect(() => {
156
161
  if (size !== undefined && view === undefined) {
157
- setView(startView(map, lifted, size));
162
+ const spot = shownPoint(map, layout, focus.name);
163
+ const start = startView(map, lifted, size);
164
+ setView(spot === undefined ? start : roomFor(spot, start, size, size.width < 600));
158
165
  }
159
166
  }, [size]);
160
167
  // A place chosen: the map brings it where the card leaves room, right of it on a wide screen, above it on a phone.
161
168
  useEffect(() => {
162
- const spot = layout.spots.find((one) => one.name === focus.name);
169
+ const spot = shownPoint(map, layout, focus.name);
163
170
  if (spot !== undefined && size !== undefined && view !== undefined) {
164
171
  setView(roomFor(spot, view, size, narrow));
165
172
  }
@@ -304,7 +311,7 @@ function Drawing({ map, layout, ways, trails, lifted, ghost, passages, lead, vie
304
311
  const big = isParty || (placeKinds[spot.kind ?? ""]?.size ?? 0) >= 2;
305
312
  return { text: spot.name, x: X(spot.x), y: Y(spot.y), r: isParty ? 19 : symbolOf(spot).r + 1, size: big ? 16 : 13.5, weight: weightOf(spot, layout) };
306
313
  }), markBoxes, [...reserved, ...regionBoxes], width, height);
307
- return (_jsxs("svg", { class: "map-svg", viewBox: `0 0 ${width} ${height}`, "aria-hidden": "true", children: [_jsxs("defs", { children: [_jsx(GlassDefs, { prefix: "map" }), _jsxs("filter", { id: "map-grain", x: "0", y: "0", width: "100%", height: "100%", children: [_jsx("feTurbulence", { type: "fractalNoise", baseFrequency: "0.9", numOctaves: 3, seed: 2 }), _jsx("feColorMatrix", { values: "0 0 0 0 0.35 0 0 0 0 0.25 0 0 0 0 0.12 0 0 0 0.09 0" }), _jsx("feComposite", { in2: "SourceGraphic", operator: "in" })] }), _jsxs("filter", { id: "map-ink", x: "-5%", y: "-5%", width: "110%", height: "110%", children: [_jsx("feTurbulence", { type: "fractalNoise", baseFrequency: "0.05", numOctaves: 2, seed: 4 }), _jsx("feDisplacementMap", { in: "SourceGraphic", scale: 2.2 })] }), _jsxs("radialGradient", { id: "map-age", cx: "50%", cy: "50%", r: "72%", children: [_jsx("stop", { offset: "0.62", "stop-color": "#6e5028", "stop-opacity": "0" }), _jsx("stop", { offset: "1", "stop-color": "#6e5028", "stop-opacity": "0.3" })] }), _jsx("clipPath", { id: "map-token", children: _jsx("circle", { r: 13 }) }), wayNames.map((run, index) => run === undefined ? null : _jsx("path", { id: `world-way-name-${index}`, d: pathOf(run) }, index))] }), _jsx("rect", { class: "map-fog", width: width, height: height }), hexes.map((hex, index) => (_jsx("polygon", { class: hex.lit ? `hex lit ${biomeLook(hex.biome)}` : "hex fogged", "fill-opacity": hex.lit ? (0.8 + hex.tone * 0.2).toFixed(2) : undefined, points: hexCorners(hex, across).map((corner) => `${X(corner.x).toFixed(1)},${Y(corner.y).toFixed(1)}`).join(" ") }, index))), hexPixels >= 24 && (_jsx("g", { class: "tufts", children: hexes.filter((hex) => hex.lit && hex.biome !== undefined && biomes[hex.biome] !== undefined).flatMap((hex, index) => marksOf(hex, hexPixels).map((mark, at) => (_jsx("path", { class: `tuft ${hex.biome}`, transform: `translate(${(X(hex.x) + mark.x).toFixed(1)} ${(Y(hex.y) + mark.y).toFixed(1)}) scale(${mark.scale.toFixed(2)})`, d: biomes[hex.biome ?? ""].mark }, `${index} ${at}`)))) })), [...edges].map(([region, segments]) => (_jsx("path", { class: `region-edge ${biomeLook(layout.regions.find((one) => one.name === region)?.biome)}`, d: segments.map(([from, to]) => `M${X(from.x).toFixed(1)} ${Y(from.y).toFixed(1)}L${X(to.x).toFixed(1)} ${Y(to.y).toFixed(1)}`).join(""), filter: "url(#map-ink)" }, region))), _jsx("rect", { class: "map-grain", width: width, height: height, filter: "url(#map-grain)" }), trails.map((run, index) => _jsx("path", { class: "trail", d: line(run) }, index)), ghost !== undefined && (_jsxs("g", { class: "ghost", children: [ghost.ways.map((way) => _jsx(WayDrawing, { way: way, look: wayLook(way.kind), screen: screen, weight: weight }, way.name)), ghost.spots.map((spot) => _jsx(PlaceSymbol, { spot: spot, x: X(spot.x), y: Y(spot.y), chosen: false }, spot.name))] })), drawn.map((way) => _jsx(WayDrawing, { way: way, look: wayLook(way.kind), screen: screen, weight: weight }, way.name)), drawn.map((way, index) => wayNames[index] === undefined ? null : (_jsx("text", { class: `way-label ${wayLook(way.kind)}`, dy: wayLook(way.kind) === "river" ? -16 : -6, children: _jsx("textPath", { href: `#world-way-name-${index}`, startOffset: "50%", "text-anchor": "middle", children: way.name }) }, way.name))), _jsx("rect", { class: "map-age", width: width, height: height, fill: "url(#map-age)" }), layout.spots.filter((spot) => passages.includes(spot.name)).map((spot) => _jsx("circle", { class: "passage-ring", cx: X(spot.x), cy: Y(spot.y), r: symbolOf(spot).r + 5 }, spot.name)), layout.spots.filter((spot) => spot !== layout.partySpot).map((spot) => _jsx(PlaceSymbol, { spot: spot, x: X(spot.x), y: Y(spot.y), chosen: spot.name === chosen }, spot.name)), party !== undefined && (_jsxs("g", { class: layout.partySpot !== undefined && layout.partySpot.name === chosen ? "party-mark selected" : "party-mark", transform: `translate(${X(party.x).toFixed(1)} ${Y(party.y).toFixed(1)})`, "data-place": layout.partySpot?.name, children: [_jsx("circle", { class: "party-pulse", r: 17 }), _jsxs("g", { filter: "url(#map-drop)", children: [_jsx("circle", { class: "party-ring", r: 17 }), _jsx("circle", { class: "party-disc", r: 14.5 }), image !== undefined && _jsx("image", { href: image, x: -13, y: -13, width: 26, height: 26, "clip-path": "url(#map-token)" }), _jsx(Glass, { r: 14.5, prefix: "map" })] })] })), _jsxs("g", { class: "labels", children: [layout.regions.map((region, index) => {
314
+ return (_jsxs("svg", { class: "map-svg", viewBox: `0 0 ${width} ${height}`, "aria-hidden": "true", children: [_jsxs("defs", { children: [_jsx(GlassDefs, { prefix: "map" }), _jsxs("filter", { id: "map-grain", x: "0", y: "0", width: "100%", height: "100%", children: [_jsx("feTurbulence", { type: "fractalNoise", baseFrequency: "0.9", numOctaves: 3, seed: 2 }), _jsx("feColorMatrix", { values: "0 0 0 0 0.35 0 0 0 0 0.25 0 0 0 0 0.12 0 0 0 0.09 0" }), _jsx("feComposite", { in2: "SourceGraphic", operator: "in" })] }), _jsxs("filter", { id: "map-ink", x: "-5%", y: "-5%", width: "110%", height: "110%", children: [_jsx("feTurbulence", { type: "fractalNoise", baseFrequency: "0.05", numOctaves: 2, seed: 4 }), _jsx("feDisplacementMap", { in: "SourceGraphic", scale: 2.2 })] }), _jsxs("radialGradient", { id: "map-age", cx: "50%", cy: "50%", r: "72%", children: [_jsx("stop", { offset: "0.62", "stop-color": "#6e5028", "stop-opacity": "0" }), _jsx("stop", { offset: "1", "stop-color": "#6e5028", "stop-opacity": "0.3" })] }), _jsx("clipPath", { id: "map-token", children: _jsx("circle", { r: 13 }) }), wayNames.map((run, index) => run === undefined ? null : _jsx("path", { id: `world-way-name-${index}`, d: pathOf(run) }, index))] }), _jsx("rect", { class: "map-fog", width: width, height: height }), hexes.map((hex, index) => (_jsx("polygon", { class: hex.lit ? `hex lit ${biomeLook(hex.biome)}` : "hex fogged", "fill-opacity": hex.lit ? (0.8 + hex.tone * 0.2).toFixed(2) : undefined, points: hexCorners(hex, across).map((corner) => `${X(corner.x).toFixed(1)},${Y(corner.y).toFixed(1)}`).join(" ") }, index))), hexPixels >= 24 && (_jsx("g", { class: "tufts", children: hexes.filter((hex) => hex.lit && hex.biome !== undefined && biomes[hex.biome] !== undefined).flatMap((hex, index) => marksOf(hex, hexPixels).map((mark, at) => (_jsx("path", { class: `tuft ${hex.biome}`, transform: `translate(${(X(hex.x) + mark.x).toFixed(1)} ${(Y(hex.y) + mark.y).toFixed(1)}) scale(${mark.scale.toFixed(2)})`, d: biomes[hex.biome ?? ""].mark }, `${index} ${at}`)))) })), [...edges].map(([region, segments]) => (_jsx("path", { class: `region-edge ${biomeLook(layout.regions.find((one) => one.name === region)?.biome)}${region === chosen ? " selected" : ""}`, d: segments.map(([from, to]) => `M${X(from.x).toFixed(1)} ${Y(from.y).toFixed(1)}L${X(to.x).toFixed(1)} ${Y(to.y).toFixed(1)}`).join(""), filter: "url(#map-ink)" }, region))), _jsx("rect", { class: "map-grain", width: width, height: height, filter: "url(#map-grain)" }), trails.map((run, index) => _jsx("path", { class: "trail", d: line(run) }, index)), drawn.filter((way) => way.name === chosen).map((way, index) => _jsx("path", { class: "chosen-way", d: line(way.course) }, index)), ghost !== undefined && (_jsxs("g", { class: "ghost", children: [ghost.ways.map((way, index) => _jsx(WayDrawing, { way: way, look: wayLook(way.kind), screen: screen, weight: weight }, `${way.name} ${index}`)), ghost.spots.map((spot) => _jsx(PlaceSymbol, { spot: spot, x: X(spot.x), y: Y(spot.y), chosen: false }, spot.name))] })), drawn.map((way, index) => _jsx(WayDrawing, { way: way, look: wayLook(way.kind), screen: screen, weight: weight }, `${way.name} ${index}`)), drawn.map((way, index) => wayNames[index] === undefined ? null : (_jsx("text", { class: `way-label ${wayLook(way.kind)}`, dy: wayLook(way.kind) === "river" ? -16 : -6, children: _jsx("textPath", { href: `#world-way-name-${index}`, startOffset: "50%", "text-anchor": "middle", children: way.name }) }, `${way.name} ${index}`))), _jsx("rect", { class: "map-age", width: width, height: height, fill: "url(#map-age)" }), layout.spots.filter((spot) => passages.includes(spot.name)).map((spot) => _jsx("circle", { class: "passage-ring", cx: X(spot.x), cy: Y(spot.y), r: symbolOf(spot).r + 5 }, spot.name)), layout.spots.filter((spot) => spot !== layout.partySpot).map((spot) => _jsx(PlaceSymbol, { spot: spot, x: X(spot.x), y: Y(spot.y), chosen: spot.name === chosen }, spot.name)), party !== undefined && (_jsxs("g", { class: layout.partySpot !== undefined && layout.partySpot.name === chosen ? "party-mark selected" : "party-mark", transform: `translate(${X(party.x).toFixed(1)} ${Y(party.y).toFixed(1)})`, "data-place": layout.partySpot?.name, children: [_jsx("circle", { class: "party-pulse", r: 17 }), _jsxs("g", { filter: "url(#map-drop)", children: [_jsx("circle", { class: "party-ring", r: 17 }), _jsx("circle", { class: "party-disc", r: 14.5 }), image !== undefined && _jsx("image", { href: image, x: -13, y: -13, width: 26, height: 26, "clip-path": "url(#map-token)" }), _jsx(Glass, { r: 14.5, prefix: "map" })] })] })), _jsxs("g", { class: "labels", children: [layout.regions.map((region, index) => {
308
315
  const placed = regionLabels[index];
309
316
  return placed === undefined ? null : (_jsxs("g", { children: [_jsx("text", { class: "label region-label", x: placed.x, y: placed.y, "text-anchor": "middle", children: region.name }), region.terrain !== undefined && _jsx("text", { class: "label region-note", x: placed.x, y: placed.y + 15, "text-anchor": "middle", children: terrainLabel(region.terrain) })] }, region.name));
310
317
  }), layout.spots.map((spot, index) => {
@@ -338,9 +345,14 @@ function PlaceCard({ place, map, layout, narrow, onClose, onGo, readMore }) {
338
345
  const closer = useRef(null);
339
346
  // Its text, read when the card opens: the first lines as the character knows them.
340
347
  useEffect(() => {
348
+ // Only this place's: an answer for the one opened before, which came late, is left.
349
+ let live = true;
341
350
  setText(undefined);
342
- readView(place.name).then((page) => setText(page.kind === "page" ? plainLine(page.text) : undefined), () => setText(undefined));
351
+ readView(place.name).then((page) => live && setText(page.kind === "page" ? plainLine(page.text) : undefined), () => live && setText(undefined));
343
352
  closer.current?.focus({ preventScroll: true });
353
+ return () => {
354
+ live = false;
355
+ };
344
356
  }, [place.name]);
345
357
  const eyebrow = [placeKindLabel(place.kind) ?? t("Place"), region?.name, here || place.from?.direction === undefined ? undefined : t("{distance} from you", { distance: fromLabel(place.from, (km) => lengthText(km, map.unit)) })].filter((part) => part !== undefined);
346
358
  return (_jsxs("div", { class: narrow ? "place-card sheet" : "place-card", role: "dialog", "aria-labelledby": "place-card-title", onPointerDown: (event) => event.stopPropagation(), onPointerUp: (event) => event.stopPropagation(), children: [place.image !== undefined && _jsx("img", { class: "pc-image", src: pictureAddress(place.image), alt: "" }), _jsx("button", { ref: closer, type: "button", class: "pc-close icon-button", "aria-label": t("Close"), onClick: onClose, children: _jsx(Icon, { name: "close" }) }), _jsxs("div", { class: "pc-body", children: [_jsx("p", { class: "eyebrow pc-eyebrow", children: eyebrow.join(" · ") }), _jsx("h3", { id: "place-card-title", children: place.name }), here && (_jsxs("p", { class: "pc-here", children: [_jsx("span", { class: "here-dot", "aria-hidden": "true" }), t("Your party is here")] })), text !== undefined && _jsx("p", { class: "pc-text", children: text }), readMore !== undefined && _jsx("a", { class: "pc-more md-link", href: readMore, children: t("Read all you know") }), inside.length > 0 && (_jsxs(_Fragment, { children: [_jsx("h4", { class: "eyebrow pc-sub", children: t("Inside") }), _jsx("ul", { class: "in-chips", children: inside.flatMap((child) => [
@@ -357,12 +369,12 @@ function Key({ map, layout, narrow, trail, passages }) {
357
369
  return (_jsxs("details", { class: "map-key", open: !narrow, children: [_jsx("summary", { children: t("Key") }), _jsxs("div", { class: "key-groups", children: [_jsxs("div", { class: "key-group", children: [_jsx("h4", { class: "eyebrow key-title", children: t("Ways") }), _jsxs("ul", { children: [ways.map((look) => (_jsxs("li", { children: [_jsxs("svg", { class: "key-way", viewBox: "0 0 30 16", "aria-hidden": "true", children: [look === "river" && _jsx("path", { class: "river-water", d: "M2 9.6Q8 5.8 15 8.2T28 6.6L28 9.6Q22 12 15 10.4T2 10.8Z" }), look === "road" && (_jsxs(_Fragment, { children: [_jsx("path", { class: "road-ink", d: "M2 9q7-4 13-1t13-1", "stroke-width": 3.8 }), _jsx("path", { class: "road-paper", d: "M2 9q7-4 13-1t13-1", "stroke-width": 1.5 })] })), (look === "path" || look === "other") && _jsx("path", { class: `${look}-ink`, d: "M2 9q7-4 13-1t13-1", "stroke-width": 1.4 })] }), wayLabel(look)] }, look))), trail && (_jsxs("li", { children: [_jsx("svg", { class: "key-way", viewBox: "0 0 30 16", "aria-hidden": "true", children: _jsx("path", { class: "trail", d: "M4 8h22" }) }), t("Your trail")] })), _jsxs("li", { children: [_jsxs("svg", { class: "key-symbol", viewBox: "-9 -9 18 18", "aria-hidden": "true", children: [_jsx("circle", { class: "party-ring", r: 7.5 }), _jsx("circle", { class: "party-disc", r: 5.5 })] }), t("Your party")] }), passages && (_jsxs("li", { children: [_jsx("svg", { class: "key-symbol", viewBox: "-12 -12 24 24", "aria-hidden": "true", children: _jsx("circle", { class: "passage-ring", r: 9 }) }), t("Passage to another map")] }))] })] }), _jsxs("div", { class: "key-group", children: [_jsx("h4", { class: "eyebrow key-title", children: t("Land") }), _jsxs("ul", { children: [lands.map((look) => (_jsxs("li", { children: [_jsx(BiomeSwatch, { look: look }), biomeLabel(look) ?? t("Other land")] }, look))), _jsxs("li", { children: [_jsx("svg", { class: "key-swatch", viewBox: "0 0 22 16", "aria-hidden": "true", children: _jsx("rect", { class: "hex fogged", x: 1, y: 1, width: 20, height: 14, rx: 3 }) }), t("Not found yet")] })] })] }), _jsxs("div", { class: "key-group", children: [_jsx("h4", { class: "eyebrow key-title", children: t("Places") }), _jsx("ul", { children: kinds.map((kind) => (_jsxs("li", { children: [_jsx("svg", { class: "key-symbol", viewBox: "-17 -17 34 34", "aria-hidden": "true", children: _jsx(PlaceSymbol, { spot: { name: kind, x: 0, y: 0, within: [], ...(kind === "other" ? {} : { kind }) }, x: 0, y: 0, chosen: false }) }), placeKindLabel(kind) ?? t("Other place")] }, kind))) })] })] })] }));
358
370
  }
359
371
  /** The map's twin: every place the character knows, nearest the party first, with how far and which way; then the regions and the ways. */
360
- function PlacesList({ map, layout, onChoose }) {
372
+ function PlacesList({ map, full, layout, onChoose }) {
361
373
  const choose = (name) => {
362
374
  onChoose(name);
363
375
  document.querySelector(".map")?.scrollIntoView({ block: "nearest", behavior: "smooth" });
364
376
  };
365
- return (_jsxs("section", { class: "card map-list", "aria-labelledby": "places-title", children: [_jsxs("header", { class: "map-head", children: [_jsx("h3", { id: "places-title", children: t("Places you know") }), _jsx("span", { class: "map-sub", children: map.party === undefined ? t("on the map") : t("from your party, as the crow flies") })] }), _jsx("ol", { class: "places", children: layout.spots.map((spot) => (_jsx("li", { children: _jsxs("button", { type: "button", class: "place-row", onClick: () => choose(spot.name), children: [_jsx("span", { class: "pr-name", children: spot.name }), _jsx("span", { class: "pr-kind", children: [placeKindLabel(spot.kind) ?? t("Place"), ...(layout.inside(spot.name).length > 0 ? [t("{count} inside", { count: layout.inside(spot.name).length })] : [])].join(" · ") }), _jsx("span", { class: "pr-far num", dir: "auto", children: spot.from === undefined ? "" : fromLabel(spot.from, (km) => lengthText(km, map.unit)) })] }) }, spot.name))) }), (layout.regions.length > 0 || map.roads.length > 0) && _jsx("h4", { class: "eyebrow pc-sub", children: t("Regions and ways") }), _jsxs("ul", { class: "places", children: [layout.regions.map((region) => _jsx(RegionRow, { region: region, unit: map.unit }, region.name)), map.roads.map((road) => (_jsx("li", { children: _jsxs("span", { class: "place-row static", children: [_jsx("span", { class: "pr-name", children: road.name }), _jsx("span", { class: "pr-kind", children: wayLabel(road.kind) }), _jsx("span", { class: "pr-far num", children: lengthText(road.points.slice(1).reduce((sum, point) => sum + point.km, 0), map.unit) })] }) }, road.name)))] })] }));
377
+ return (_jsxs("section", { class: "card map-list", "aria-labelledby": "places-title", children: [_jsxs("header", { class: "map-head", children: [_jsx("h3", { id: "places-title", children: t("Places you know") }), _jsx("span", { class: "map-sub", children: map.party === undefined ? t("on the map") : t("from your party, as the crow flies") })] }), _jsx("ol", { class: "places", children: layout.spots.map((spot) => (_jsx("li", { children: _jsxs("button", { type: "button", class: "place-row", onClick: () => choose(spot.name), children: [_jsx("span", { class: "pr-name", children: spot.name }), _jsx("span", { class: "pr-kind", children: [placeKindLabel(spot.kind) ?? t("Place"), ...(layout.inside(spot.name).length > 0 ? [t("{count} inside", { count: layout.inside(spot.name).length })] : [])].join(" · ") }), _jsx("span", { class: "pr-far num", dir: "auto", children: spot.from === undefined ? "" : fromLabel(spot.from, (km) => lengthText(km, map.unit)) })] }) }, spot.name))) }), (layout.regions.length > 0 || map.roads.length > 0) && _jsx("h4", { class: "eyebrow pc-sub", children: t("Regions and ways") }), _jsxs("ul", { class: "places", children: [layout.regions.map((region) => _jsx(RegionRow, { region: region, unit: map.unit }, region.name)), waysListed(map.roads, full.roads).map((road) => (_jsx("li", { children: _jsxs("span", { class: "place-row static", children: [_jsx("span", { class: "pr-name", children: road.name }), _jsx("span", { class: "pr-kind", children: wayLabel(road.kind) }), _jsx("span", { class: "pr-far num", children: lengthText(road.km, map.unit) })] }) }, road.name)))] })] }));
366
378
  }
367
379
  function RegionRow({ region, unit }) {
368
380
  return (_jsx("li", { children: _jsxs("span", { class: "place-row static", children: [_jsx("span", { class: "pr-name", children: region.name }), _jsxs("span", { class: "pr-kind", children: [region.biome !== undefined && biomes[region.biome] !== undefined && _jsx(BiomeSwatch, { look: region.biome }), [t("Region"), biomeLabel(region.biome), region.terrain === undefined ? undefined : terrainLabel(region.terrain)].filter((part) => part !== undefined).join(" · ")] }), _jsx("span", { class: "pr-far num", dir: "auto", children: t("{length} across", { length: lengthText(region.radius * 2, unit) }) })] }) }));
@@ -413,3 +425,26 @@ function wayLabel(kind) {
413
425
  const labels = { river: t("River"), road: t("Road"), path: t("Path"), portal: t("Portal"), other: t("Other way") };
414
426
  return labels[kind] ?? `${kind[0]?.toUpperCase() ?? ""}${kind.slice(1)}`;
415
427
  }
428
+ /**
429
+ * The ways of a map as its list names them: each once, with its whole length, on this map and the others it leads to, its pieces together; a portal, which
430
+ * has none, left out.
431
+ */
432
+ function waysListed(roads, whole) {
433
+ const names = [...new Set(roads.filter((road) => road.kind !== "portal").map((road) => road.name))];
434
+ return names.map((name) => {
435
+ const pieces = whole.filter((road) => road.name === name);
436
+ const km = pieces.reduce((sum, road) => sum + road.points.slice(1).reduce((length, point) => length + point.km, 0), 0);
437
+ return { name, kind: pieces[0]?.kind ?? "other", km };
438
+ });
439
+ }
440
+ /** The map that draws a name: a place's or a region's own, the middle of a way's; none for a name it does not draw. */
441
+ function mapHolding(map, name) {
442
+ const points = map.roads.find((road) => road.name === name)?.points;
443
+ const point = map.places.find((one) => one.name === name && one.x !== undefined) ?? points?.[Math.floor(points.length / 2)];
444
+ return point === undefined ? undefined : mapNameOf(map, point);
445
+ }
446
+ /** Where the map brings a name chosen: a place, the middle of a region, or the middle of a way; none for a name it does not draw. */
447
+ function shownPoint(map, layout, name) {
448
+ const points = map.roads.find((road) => road.name === name)?.points;
449
+ return layout.spots.find((one) => one.name === name) ?? layout.regions.find((one) => one.name === name) ?? points?.[Math.floor((points?.length ?? 0) / 2)];
450
+ }
@@ -1,6 +1,6 @@
1
1
  export { type CoinSide, coinSides, type CoinToss, mostCoins, tossCoins } from "./coins.ts";
2
2
  export { DiceError, diceProblem, parseNotation } from "./notation.ts";
3
- export { askOracle, type OracleAnswer, oracleResult } from "./oracle.ts";
3
+ export { askOracle, type OracleAnswer, oracleResult, type OracleYes } from "./oracle.ts";
4
4
  export { createProof, fingerprint, sha256 } from "./proof.ts";
5
5
  export { type DiceRoll, type FaceSource, rollDice, type ThrownDie } from "./roll-dice.ts";
6
6
  export { type RandomTable, readRandomTable, rollOnTable, type TableRoll, type TableRow } from "./tables.ts";
@@ -10,10 +10,12 @@ export interface OracleAnswer {
10
10
  extreme: boolean;
11
11
  text: string;
12
12
  }
13
+ /** Where a d100 says yes: low, up to the odds; high, above 100 less the odds, as Ironsworn's oracle. */
14
+ export type OracleYes = "low" | "high";
13
15
  /** Asks the oracle with the odds named, in any case, with hyphens for spaces too; refused, with the five odds, for any other. */
14
- export declare function askOracle(odds: string, source: FaceSource): OracleAnswer;
15
- /** Yes when the d100 is no higher than the chance; extreme on a double, 11 to 99 and 100 as 00. */
16
- export declare function oracleResult(chance: number, rolled: number): {
16
+ export declare function askOracle(odds: string, source: FaceSource, yesOn?: OracleYes): OracleAnswer;
17
+ /** Yes when the d100 is no higher than the chance, or above 100 less the chance when yes is high; extreme on a double, 11 to 99 and 100 as 00. */
18
+ export declare function oracleResult(chance: number, rolled: number, yesOn?: OracleYes): {
17
19
  yes: boolean;
18
20
  extreme: boolean;
19
21
  };
@@ -1,22 +1,23 @@
1
- // A yes/no oracle: a d100 against the odds, yes when it is no higher; a double (11, 22, … 00) makes the answer extreme.
1
+ // A yes/no oracle: a d100 against the odds, yes when it is no higher, or, in a game that reads it so, when it is above 100 less the odds; a double (11, 22, … 00)
2
+ // makes the answer extreme.
2
3
  import { DiceError } from "./notation.js";
3
4
  import { rollDice } from "./roll-dice.js";
4
5
  /** The odds an oracle is asked with, and the chance of a yes in a hundred. */
5
6
  export const oracleOdds = { "almost certain": 90, likely: 75, "50/50": 50, unlikely: 25, "small chance": 10 };
6
7
  /** Asks the oracle with the odds named, in any case, with hyphens for spaces too; refused, with the five odds, for any other. */
7
- export function askOracle(odds, source) {
8
+ export function askOracle(odds, source, yesOn = "low") {
8
9
  const name = odds.trim().toLowerCase().replace(/[-\s]+/g, " ");
9
10
  const chance = Object.hasOwn(oracleOdds, name) ? oracleOdds[name] : undefined;
10
11
  if (chance === undefined) {
11
12
  throw new DiceError(`"${odds}" are no odds of the oracle: give one of ${Object.keys(oracleOdds).join(", ")}.`);
12
13
  }
13
14
  const roll = rollDice("d100", source);
14
- const { yes, extreme } = oracleResult(chance, roll.total);
15
+ const { yes, extreme } = oracleResult(chance, roll.total, yesOn);
15
16
  const answer = yes ? (extreme ? "Yes, and more: something beyond what was asked." : "Yes.") : extreme ? "No, and worse." : "No.";
16
17
  const shown = `${name[0].toUpperCase()}${name.slice(1)} (${chance}%)`;
17
18
  return { odds: name, chance, roll, yes, extreme, text: `${shown}: [d100 = ${roll.total}] ${answer}` };
18
19
  }
19
- /** Yes when the d100 is no higher than the chance; extreme on a double, 11 to 99 and 100 as 00. */
20
- export function oracleResult(chance, rolled) {
21
- return { yes: rolled <= chance, extreme: rolled === 100 || (rolled % 11 === 0 && rolled < 100) };
20
+ /** Yes when the d100 is no higher than the chance, or above 100 less the chance when yes is high; extreme on a double, 11 to 99 and 100 as 00. */
21
+ export function oracleResult(chance, rolled, yesOn = "low") {
22
+ return { yes: yesOn === "high" ? rolled > 100 - chance : rolled <= chance, extreme: rolled === 100 || (rolled % 11 === 0 && rolled < 100) };
22
23
  }
@@ -83,10 +83,13 @@ export function readExtension(folder) {
83
83
  throw new Error(`${owner} cannot be read, because its ${extensionFileName} is not valid: ${z.prettifyError(declared.error).replace(/\s+/g, " ")}`);
84
84
  }
85
85
  const { title, about, language, attribution, needs, calendar, icons, widgets, figures } = declared.data;
86
- // Its page code is a file of its own, by real paths, links included (D-510).
86
+ // Its page code is a file of its own, by real paths, links included (D-510); its code too, as the player's yes covers only its own files (T-63).
87
87
  if (marker.page !== undefined && !isInside(realPath(folder), realPath(resolve(folder, marker.page)))) {
88
88
  throw new Error(`${owner} cannot be used, because its page, ${marker.page}, is not inside its package: name a file of its own, such as dist/page.js.`);
89
89
  }
90
+ if (manifest.data.main !== undefined && !isInside(realPath(folder), realPath(resolve(folder, manifest.data.main)))) {
91
+ throw new Error(`${owner} cannot be used, because its code, ${manifest.data.main}, is not inside its package: name a file of its own as its main, such as dist/index.js.`);
92
+ }
90
93
  const adds = Object.fromEntries(systemAdditionNames.flatMap((key) => (declared.data[key] === undefined ? [] : [[key, declared.data[key]]])));
91
94
  const parts = readParts(folder, owner);
92
95
  // What the master reads of it in every chat, kept short (D-441).
@@ -130,7 +130,7 @@ function write(brief) {
130
130
  function read(folder, brief, _writable, signal) {
131
131
  const last = join(folder, ".last.txt");
132
132
  // The folder is the working one, never in the line: the shell would read a title's $(…) or %…% (Matteo's review, D-489).
133
- const line = `${codex} exec --ephemeral --skip-git-repo-check -s workspace-write -o .last.txt --ignore-user-config --ignore-rules -`;
133
+ const line = `${codex} exec --ephemeral --skip-git-repo-check -s workspace-write -c shell_environment_policy.inherit=core -o .last.txt --ignore-user-config --ignore-rules -`;
134
134
  return new Promise((done) => {
135
135
  const child = spawn(line, { shell: true, windowsHide: true, cwd: folder, env: helperEnvironment("codex"), stdio: ["pipe", "ignore", "pipe"] });
136
136
  // Dropped while it runs: the helper stops with all it started.
@@ -1,9 +1,10 @@
1
1
  import { spawn, spawnSync } from "node:child_process";
2
- import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync } from "node:fs";
2
+ import { cpSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { isAbsolute, join, resolve } from "node:path";
5
5
  import { ourScope } from "../core/consents.js";
6
6
  import { packageApi, readsApi } from "../core/package-declarations.js";
7
+ import { Refusal } from "../core/refusal.js";
7
8
  import { isNewerVersion } from "../core/version.js";
8
9
  import { isTarball, tarballText, unpackTarball } from "./tarball.js";
9
10
  /** The keyword of the packages for rpg-engine on npm, by which they are found (D-439). */
@@ -297,7 +298,8 @@ async function installCopy(folder, spec, expected, run) {
297
298
  }
298
299
  else {
299
300
  // What npm or git keep beside a package's own files is no part of it.
300
- cpSync(resolve(spec), staged, { recursive: true, filter: (path) => !/[\\/](node_modules|\.git)([\\/]|$)/.test(path.slice(resolve(spec).length)) });
301
+ // A link would bring in what it points to, which is not what was asked about.
302
+ cpSync(resolve(spec), staged, { recursive: true, filter: (path) => !/[\\/](node_modules|\.git)([\\/]|$)/.test(path.slice(resolve(spec).length)) && plainEntry(path, spec) });
301
303
  }
302
304
  }
303
305
  catch (error) {
@@ -358,6 +360,7 @@ function infoOf(read) {
358
360
  version: read.version ?? "",
359
361
  ...(typeof marker?.kind === "string" ? { kind: marker.kind } : {}),
360
362
  ...(typeof marker?.api === "number" ? { api: marker.api } : {}),
363
+ ...(typeof marker?.system === "string" ? { system: marker.system } : {}),
361
364
  ...(read.description === undefined ? {} : { description: read.description }),
362
365
  ...(authorOf(read) === undefined ? {} : { author: authorOf(read) }),
363
366
  // What runs: a main, exports or a command; a package of texts alone has none.
@@ -382,7 +385,7 @@ async function json(url) {
382
385
  }
383
386
  function checkedSpec(spec) {
384
387
  if (!npmSpec.test(spec)) {
385
- throw new Error(`"${spec}" is not the name of an npm package, with its version if wanted, such as @rpgengine/weather or @rpgengine/weather@0.1.0.`);
388
+ throw new Refusal(`"${spec}" is not the name of an npm package, with its version if wanted, such as @rpgengine/weather or @rpgengine/weather@0.1.0.`, "not-a-name", { name: spec });
386
389
  }
387
390
  return spec;
388
391
  }
@@ -390,7 +393,7 @@ function checkedSpec(spec) {
390
393
  function quotedFolder(folder) {
391
394
  const path = resolve(folder);
392
395
  if (/["%$`!&]/.test(path)) {
393
- throw new Error(`The folder ${path} has characters npm cannot be given safely ("%$\`!&): move it to another path.`);
396
+ throw new Refusal(`The folder ${path} has characters npm cannot be given safely ("%$\`!&): move it to another path.`, "folder-characters", { name: path });
394
397
  }
395
398
  return `"${path}"`;
396
399
  }
@@ -416,3 +419,13 @@ function stopTree(pid) {
416
419
  process.kill(pid, "SIGKILL");
417
420
  }
418
421
  }
422
+ /** True for a plain file or folder of the package folder `spec`; it throws for a link, which refuses the package whole, as a link in a .tgz does. */
423
+ function plainEntry(path, spec) {
424
+ if (lstatSync(path).isSymbolicLink() && resolve(path) === resolve(spec)) {
425
+ throw new Refusal(`${spec} is a link to another folder: give the folder it points to.`, "archive-link", { name: spec, entry: path });
426
+ }
427
+ if (lstatSync(path).isSymbolicLink()) {
428
+ throw new Refusal(`${spec} holds ${path}, which is a link to somewhere else: the package is refused whole. Replace the link with what it points to.`, "archive-link", { name: spec, entry: path });
429
+ }
430
+ return true;
431
+ }
@@ -1,9 +1,10 @@
1
1
  // A package's .tgz as npm pack makes it (D-452): a gzipped tar with its files under package/. Read with Node alone and checked whole before anything is
2
2
  // written: a path that would leave the folder or that Windows reads otherwise, a link, a device, a duplicate or an archive cut short refuse it.
3
3
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
- import { resolve } from "node:path";
4
+ import { basename, resolve } from "node:path";
5
5
  import { gunzipSync } from "node:zlib";
6
6
  import { archivePathParts, insideFolder, refuseTwice } from "../core/archive-paths.js";
7
+ import { Refusal } from "../core/refusal.js";
7
8
  // The most an archive may unpack to: a package is never this big, a malicious archive could be.
8
9
  const largest = 512 * 1024 * 1024;
9
10
  const block = 512;
@@ -38,7 +39,10 @@ function entries(archive) {
38
39
  }
39
40
  catch (error) {
40
41
  const big = error instanceof RangeError || (error instanceof Error && /larger than|maxOutputLength/i.test(error.message));
41
- throw new Error(big ? `${archive} unpacks to more than ${largest / 1024 / 1024} MB, more than a package may.` : `${archive} is not a package's .tgz that reads: ${error instanceof Error ? error.message : String(error)}`);
42
+ const name = basename(archive);
43
+ throw big
44
+ ? new Refusal(`${archive} unpacks to more than ${largest / 1024 / 1024} MB, more than a package may.`, "archive-big", { name, size: String(largest / 1024 / 1024) })
45
+ : new Refusal(`${archive} is not a package's .tgz that reads: ${error instanceof Error ? error.message : String(error)}`, "archive-unread", { name });
42
46
  }
43
47
  const found = [];
44
48
  let longName;
@@ -50,7 +54,7 @@ function entries(archive) {
50
54
  const sizeField = text(header, 124, 12).trim();
51
55
  const size = /^[0-7]*$/.test(sizeField) ? Number.parseInt(sizeField || "0", 8) : Number.NaN;
52
56
  if (!Number.isSafeInteger(size) || at + block + size > tar.length) {
53
- throw new Error(`${archive} is cut short, or is not a .tgz npm pack made: it is refused whole.`);
57
+ throw new Refusal(`${archive} is cut short, or is not a .tgz npm pack made: it is refused whole.`, "archive-unread", { name: basename(archive) });
54
58
  }
55
59
  const type = String.fromCharCode(header[156] || 48);
56
60
  const data = tar.subarray(at + block, at + block + size);
@@ -67,7 +71,7 @@ function entries(archive) {
67
71
  continue;
68
72
  }
69
73
  if (type !== "0" && type !== "5") {
70
- throw new Error(`${archive} holds ${name}, which is not a plain file or folder (a link or a device): it is refused whole.`);
74
+ throw new Refusal(`${archive} holds ${name}, which is not a plain file or folder (a link or a device): it is refused whole.`, "archive-link", { name: basename(archive), entry: name });
71
75
  }
72
76
  found.push({ path: packagePath(archive, name), directory: type === "5", data });
73
77
  }
@@ -4,7 +4,7 @@ export { changedEnvironment, environmentAt, type EnvironmentEntry, formatEnviron
4
4
  export { baseChain, baseFieldOf, baseValue, derivedPages, followersOf, holdsField, type Inherited, inheritedByBase, inheritedFields, introductionFollowersOf, isNeverInherited, keepersOf, newBaseProblem, ownField, ownFieldChange, removedFieldName, sameAsBase, sectionFollowersOf, shownPart, uniquePage, writtenFieldName, } from "./inheritance.ts";
5
5
  export { carriedWeight, type LoadRule, weightUnit } from "./load.ts";
6
6
  export { type MapField, mapKey, mapOf, mapProblems, type PlaceMap, readMapField, sameFrame } from "./maps.ts";
7
- export { everyGoalTicked, firstTable, goalsIn, introductionText, type Link, links, partContent, readSection, secretNames, sectionTitles, type TextMode, textParts, withLinksAsWords, withoutComments, withoutFencedBlocks, } from "./markdown.ts";
7
+ export { everyGoalTicked, firstTable, goalsIn, introductionText, type Link, links, partContent, readSection, secretNames, sectionTitles, type TextMode, textParts, withLinksAsWords, withoutComments, withoutFencedBlocks, withoutUnreadSecrets, } from "./markdown.ts";
8
8
  export { changedFields, type FieldChange, formatFields, linkListItems, readFields, readFieldValue, splitPageFile } from "./page-file.ts";
9
9
  export { type PageType, pageTypeNames, worldFolderName } from "./page-types.ts";
10
10
  export { formatPosition, type Position, readPosition } from "./positions.ts";
@@ -5,7 +5,7 @@ export { changedEnvironment, environmentAt, formatEnvironmentEntry, placesAround
5
5
  export { baseChain, baseFieldOf, baseValue, derivedPages, followersOf, holdsField, inheritedByBase, inheritedFields, introductionFollowersOf, isNeverInherited, keepersOf, newBaseProblem, ownField, ownFieldChange, removedFieldName, sameAsBase, sectionFollowersOf, shownPart, uniquePage, writtenFieldName, } from "./inheritance.js";
6
6
  export { carriedWeight, weightUnit } from "./load.js";
7
7
  export { mapKey, mapOf, mapProblems, readMapField, sameFrame } from "./maps.js";
8
- export { everyGoalTicked, firstTable, goalsIn, introductionText, links, partContent, readSection, secretNames, sectionTitles, textParts, withLinksAsWords, withoutComments, withoutFencedBlocks, } from "./markdown.js";
8
+ export { everyGoalTicked, firstTable, goalsIn, introductionText, links, partContent, readSection, secretNames, sectionTitles, textParts, withLinksAsWords, withoutComments, withoutFencedBlocks, withoutUnreadSecrets, } from "./markdown.js";
9
9
  export { changedFields, formatFields, linkListItems, readFields, readFieldValue, splitPageFile } from "./page-file.js";
10
10
  export { pageTypeNames, worldFolderName } from "./page-types.js";
11
11
  export { formatPosition, readPosition } from "./positions.js";
@@ -47,6 +47,8 @@ export declare function trimBlankLines(text: string): string;
47
47
  export declare function withoutComments(text: string): string;
48
48
  /** The lines, counted from 1, that mark a secret the engine does not read as one, as a callout four spaces in: written for a secret, read as public text. */
49
49
  export declare function unreadSecretLines(text: string): number[];
50
+ /** A text without the secrets the engine does not read as ones (unreadSecretLines), each with the rest of its quoted block: in doubt, hidden from the player. */
51
+ export declare function withoutUnreadSecrets(text: string): string;
50
52
  /** The goals a text lists as checkboxes, outside code blocks, each with whether it is ticked; and the text without them, for a quest's card (VIEW-8). */
51
53
  export declare function goalsIn(text: string): {
52
54
  goals: {
@@ -144,6 +144,27 @@ export function unreadSecretLines(text) {
144
144
  const views = lineViews(lines);
145
145
  return lines.flatMap((line, index) => (isProse(views[index]) && /\[!secret\]/i.test(line) && !secretPattern.test(line) ? [index + 1] : []));
146
146
  }
147
+ /** A text without the secrets the engine does not read as ones (unreadSecretLines), each with the rest of its quoted block: in doubt, hidden from the player. */
148
+ export function withoutUnreadSecrets(text) {
149
+ const unread = new Set(unreadSecretLines(text));
150
+ if (unread.size === 0) {
151
+ return text;
152
+ }
153
+ // The secret's block goes on while its lines are quoted as deep as its first, as > > for one inside a callout; one in a line of prose is that line alone.
154
+ let level = 0;
155
+ return text.split("\n").filter((line, index) => {
156
+ const quotes = (/^\s*((?:>\s*)*)/.exec(line)?.[1].match(/>/g) ?? []).length;
157
+ if (unread.has(index + 1)) {
158
+ level = quotes;
159
+ return false;
160
+ }
161
+ if (level > 0 && quotes >= level) {
162
+ return false;
163
+ }
164
+ level = 0;
165
+ return true;
166
+ }).join("\n");
167
+ }
147
168
  /** The goals a text lists as checkboxes, outside code blocks, each with whether it is ticked; and the text without them, for a quest's card (VIEW-8). */
148
169
  export function goalsIn(text) {
149
170
  const lines = text.replace(/\r\n/g, "\n").split("\n");
@@ -1,4 +1,5 @@
1
1
  import { basename, join, relative, resolve, sep } from "node:path";
2
+ import { isReservedName } from "../core/archive-paths.js";
2
3
  import { translationFolder } from "../core/files.js";
3
4
  import { frozen } from "../core/frozen.js";
4
5
  import { files } from "../core/store.js";
@@ -303,6 +304,9 @@ export function checkPageName(name) {
303
304
  if (name === "" || name.length > longestName || name.trim() !== name || name.endsWith(".") || forbiddenCharacters.test(name)) {
304
305
  throw new Error(`"${name}" cannot be a page name. Names become file names and links: at most ${longestName} characters, without \\ / : * ? " < > | # ^ [ ], line breaks, spaces at the ends or a final dot.`);
305
306
  }
307
+ if (isReservedName(name)) {
308
+ throw new Error(`"${name}" cannot be a page name: Windows keeps it for a device, as CON, NUL or COM1. Give it another name, as "${name} (place)".`);
309
+ }
306
310
  // A name that ends as a file does, as Bruna.md or Mappa.png, makes a page no link reaches (LNK-1).
307
311
  if (links(`[[${name}]]`)[0]?.page !== name) {
308
312
  const ending = /\.[a-z0-9]+$/i.test(name);
@@ -168,14 +168,18 @@ async function answer(request, response, served) {
168
168
  // Only the dashboard's own page, at its own address: no other site may read what the player sees, nor a name that leads elsewhere (D-272).
169
169
  const own = [`http://localhost:${served.port}`, `http://127.0.0.1:${served.port}`];
170
170
  const origin = request.headers.origin;
171
+ // An address that does not read, as //, is no page of the dashboard's.
172
+ const url = URL.parse(request.url ?? "/", own[0]) ?? new URL("/404", own[0]);
173
+ const path = url.pathname;
171
174
  // A request another site makes the browser send, as an image's, which carries no origin, says so in Sec-Fetch-Site: never ours, nor the hook's, which sends none.
172
- const crossSite = request.headers["sec-fetch-site"] === "cross-site";
173
- if (!own.includes(`http://${request.headers.host ?? ""}`) || (origin !== undefined && !own.includes(origin)) || crossSite) {
175
+ // Another program's page on this computer, at another port, is the same site: it may only open the page itself, as a link does, never the API, the bell or a frame.
176
+ const site = request.headers["sec-fetch-site"];
177
+ const visit = request.headers["sec-fetch-mode"] === "navigate" && request.headers["sec-fetch-dest"] === "document" && path === "/";
178
+ const foreign = site === "cross-site" || (site === "same-site" && !visit);
179
+ if (!own.includes(`http://${request.headers.host ?? ""}`) || (origin !== undefined && !own.includes(origin)) || foreign) {
174
180
  send(response, 403, "text/plain; charset=utf-8", `The dashboard answers only its own page, at http://localhost:${served.port}.`);
175
181
  return;
176
182
  }
177
- const url = new URL(request.url ?? "/", own[0]);
178
- const path = url.pathname;
179
183
  // The page answers the master's question with a click, and changes the player's settings: what it sends, and only from itself (D-279, D-341).
180
184
  if (request.method === "POST" && path === "/api/run" && origin !== undefined) {
181
185
  await runForPlayer(request, response, served);
@@ -3,7 +3,7 @@ import { z } from "zod";
3
3
  import { readAdventureZip } from "../../adventures/index.js";
4
4
  import { findCampaign, readSettings, readTextSetting, requireCampaign, settingNames } from "../../campaign/index.js";
5
5
  import { config, playerSettingNamed, playerSettings, setupSettingNamed } from "../../commands/config.js";
6
- import { adventureText, isInstalledPackage, packageCommand, YesRefused } from "../../commands/package.js";
6
+ import { adventureText, isInstalledPackage, packageCommand } from "../../commands/package.js";
7
7
  import { playerSaveNews, save } from "../../commands/save.js";
8
8
  import { installAdventure } from "../../commands/shared/adventures.js";
9
9
  import { libraryContents, libraryEntries, startLibraryReading, unquoted } from "../../commands/shared/library.js";
@@ -13,6 +13,7 @@ import { packageCommands } from "../../commands/shared/packages/code.js";
13
13
  import { exportsFolderName, resetPoints } from "../../commands/shared/saves.js";
14
14
  import { campaignSystem, campaignWorld } from "../../commands/shared/world.js";
15
15
  import { packagesFolder } from "../../core/context.js";
16
+ import { Refusal, refusalBody } from "../../core/refusal.js";
16
17
  import { files, withFiles } from "../../core/store.js";
17
18
  import { comparableText } from "../../core/text.js";
18
19
  import { getVersion, isNewerVersion } from "../../core/version.js";
@@ -208,7 +209,7 @@ export async function changePackage(request, response, served) {
208
209
  const { action, name } = parsed.data;
209
210
  // The page updates or takes away only what this computer has: it never brings a package new to it, nor its window, by these (D-510).
210
211
  if (!isInstalledPackage(served.context, name)) {
211
- sendJson(response, 400, { error: `${name} is not installed on this computer: add a package from the Packages page, where you choose it.` });
212
+ sendJson(response, 400, { error: `${name} is not installed on this computer: add a package from the Packages page, where you choose it.`, code: "not-here", values: { name } });
212
213
  return;
213
214
  }
214
215
  const done = action === "update" ? "updated" : action === "remove" ? "took out of the campaign" : "uninstalled";
@@ -231,11 +232,15 @@ export async function addPackage(request, response, served) {
231
232
  return;
232
233
  }
233
234
  if (!json && bytes === undefined) {
234
- sendJson(response, 413, { error: `The file is more than ${largestUpload / 1024 / 1024} MB: no package is that big.` });
235
+ sendJson(response, 413, { error: `The file is more than ${largestUpload / 1024 / 1024} MB: no package is that big.`, code: "file-big", values: { size: String(largestUpload / 1024 / 1024) } });
235
236
  return;
236
237
  }
237
238
  if (bytes !== undefined && !/\.(zip|tgz|tar\.gz)$/i.test(file)) {
238
- sendJson(response, 400, { error: `${file} is neither a .zip nor a .tgz: an adventure comes as a .zip, an extension, a game system or a language as a .tgz.` });
239
+ sendJson(response, 400, {
240
+ error: `${file} is neither a .zip nor a .tgz: an adventure comes as a .zip, an extension, a game system or a language as a .tgz.`,
241
+ code: "file-kind",
242
+ values: { name: file },
243
+ });
239
244
  return;
240
245
  }
241
246
  const source = given?.success === true ? given.data.source : file;
@@ -339,20 +344,24 @@ export async function engineNow(request, response, served) {
339
344
  await packageWork(response, served, "rpg-engine", "engine", async () => {
340
345
  const latest = await updater.latest();
341
346
  if ("failed" in latest) {
342
- throw new Error(`${latest.failed}: update it once this computer is online. Nothing changed.`);
347
+ throw new Refusal(`${latest.failed}: update it once this computer is online. Nothing changed.`, "engine-offline", { why: latest.failed });
343
348
  }
344
349
  if (!isNewerVersion(latest.version, onDisk)) {
345
- throw new Error(onDisk === version ? `rpg-engine ${version} is npm's latest: there is nothing to update.` : `rpg-engine ${onDisk} is installed already: it comes with a new chat.`);
350
+ throw onDisk === version
351
+ ? new Refusal(`rpg-engine ${version} is npm's latest: there is nothing to update.`, "engine-latest", { version })
352
+ : new Refusal(`rpg-engine ${onDisk} is installed already: it comes with a new chat.`, "engine-installed", { version: onDisk });
346
353
  }
347
354
  const installed = await updater.installed();
348
355
  if (installed.how !== "global") {
349
- throw new Error(installed.how === "link"
350
- ? `rpg-engine here is a link to the folder ${installed.folder}, made by npm link for its development: update it there, with git pull and npm run build. Nothing changed.`
351
- : `rpg-engine runs from ${installed.folder}, not from npm's global folder: update it the way it was installed. Nothing changed.`);
356
+ throw installed.how === "link"
357
+ ? new Refusal(`rpg-engine here is a link to the folder ${installed.folder}, made by npm link for its development: update it there, with git pull and npm run build. Nothing changed.`, "engine-link", { name: installed.folder })
358
+ : new Refusal(`rpg-engine runs from ${installed.folder}, not from npm's global folder: update it the way it was installed. Nothing changed.`, "engine-elsewhere", {
359
+ name: installed.folder,
360
+ });
352
361
  }
353
362
  const why = await updater.update(latest.version);
354
363
  if (why !== undefined) {
355
- throw new Error(`rpg-engine could not be updated: ${why}. Nothing changed.`);
364
+ throw new Refusal(`rpg-engine could not be updated: ${why}. Nothing changed.`, "engine-failed", { why });
356
365
  }
357
366
  // The chat goes on with the server it started, and so does this page: the new engine comes with a new chat, or the app opened again.
358
367
  const host = served.context.host?.() ?? "";
@@ -394,7 +403,7 @@ export async function exportCampaign(request, response, served) {
394
403
  sendJson(response, 200, result.kind === "exported" ? { file: basename(result.file), pages: result.pages } : {});
395
404
  }
396
405
  catch (error) {
397
- sendJson(response, 400, { error: error instanceof Error ? error.message : String(error) });
406
+ sendJson(response, 400, refusalBody(error));
398
407
  }
399
408
  }
400
409
  /** A zip of the campaign's exports/ folder, for the browser to save: by its name alone, never a path. */
@@ -436,7 +445,7 @@ function inLanguage(installed, served, language) {
436
445
  */
437
446
  async function packageWork(response, served, name, action, work) {
438
447
  if (served.packageWork !== undefined) {
439
- sendJson(response, 409, { error: `${served.packageWork.name} is still being worked on: wait for it, then try again.`, code: "busy" });
448
+ sendJson(response, 409, { error: `${served.packageWork.name} is still being worked on: wait for it, then try again.`, code: "busy", values: { name: served.packageWork.name } });
440
449
  return;
441
450
  }
442
451
  served.packageWork = { name, action, phase: "working" };
@@ -475,7 +484,7 @@ async function packageWork(response, served, name, action, work) {
475
484
  sendJson(response, 202, { kind: done.kind, ...done.answer });
476
485
  }
477
486
  catch (error) {
478
- sendJson(response, 400, { error: error instanceof Error ? error.message : String(error), ...(error instanceof YesRefused ? { code: error.code } : {}) });
487
+ sendJson(response, 400, refusalBody(error));
479
488
  }
480
489
  finally {
481
490
  served.packageWork = undefined;
@@ -1,8 +1,10 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { type Context } from "../core/context.ts";
3
3
  import { SessionStore } from "../core/session-store.ts";
4
+ /** The line that closes every answer of a tool, a phrase of the page's, so that its languages have it. */
5
+ export declare const masterScreenLine = "The text above lies behind the master's screen, forbidden to the players' eyes.";
4
6
  /**
5
- * The MCP server: every command becomes a tool with the same name, description and parameters, and answers with the same text as the command line. Its instructions send
7
+ * The MCP server: every command becomes a tool with the same name, description and parameters, and answers with the same text as the command line, closed by a line for the player's eyes (T-176). Its instructions send
6
8
  * the host to instructions, then status. The commands that ask the player appear for a host that shows forms, through which they ask (D-148), and wherever the
7
9
  * dashboard runs, whose page asks first (D-279).
8
10
  */