rpg-engine 0.19.0 → 0.20.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 (152) hide show
  1. package/README.md +9 -6
  2. package/dist/campaign/create-campaign.js +2 -2
  3. package/dist/campaign/find-campaign.d.ts +4 -0
  4. package/dist/campaign/find-campaign.js +5 -1
  5. package/dist/campaign/host-files.js +22 -0
  6. package/dist/campaign/index.d.ts +2 -2
  7. package/dist/campaign/index.js +2 -2
  8. package/dist/campaign/last-choices.d.ts +10 -4
  9. package/dist/campaign/last-choices.js +43 -17
  10. package/dist/campaign/settings.d.ts +10 -2
  11. package/dist/campaign/settings.js +30 -6
  12. package/dist/chats/chat.d.ts +33 -0
  13. package/dist/chats/chat.js +50 -0
  14. package/dist/chats/claude-code.d.ts +5 -0
  15. package/dist/chats/claude-code.js +39 -0
  16. package/dist/chats/codex.d.ts +3 -0
  17. package/dist/chats/codex.js +42 -0
  18. package/dist/chats/index.d.ts +5 -0
  19. package/dist/chats/index.js +12 -0
  20. package/dist/chats/keep.d.ts +10 -0
  21. package/dist/chats/keep.js +50 -0
  22. package/dist/chats/read.d.ts +8 -0
  23. package/dist/chats/read.js +46 -0
  24. package/dist/cli/cli.js +6 -1
  25. package/dist/cli/command-line.js +3 -2
  26. package/dist/commands/book.d.ts +55 -0
  27. package/dist/commands/book.js +105 -0
  28. package/dist/commands/chats.d.ts +38 -0
  29. package/dist/commands/chats.js +93 -0
  30. package/dist/commands/config/config.js +1 -1
  31. package/dist/commands/config/dashboard.d.ts +8 -1
  32. package/dist/commands/config/dashboard.js +63 -15
  33. package/dist/commands/config/words.d.ts +1 -1
  34. package/dist/commands/config/words.js +17 -4
  35. package/dist/commands/find.js +1 -1
  36. package/dist/commands/image.d.ts +9 -0
  37. package/dist/commands/image.js +95 -18
  38. package/dist/commands/index.js +4 -0
  39. package/dist/commands/init.js +3 -3
  40. package/dist/commands/scene/close.d.ts +2 -0
  41. package/dist/commands/scene/close.js +13 -2
  42. package/dist/commands/scene/result.d.ts +2 -0
  43. package/dist/commands/scene/scene.d.ts +2 -0
  44. package/dist/commands/shared/campaign/book.d.ts +29 -0
  45. package/dist/commands/shared/campaign/book.js +95 -0
  46. package/dist/commands/shared/campaign/chats.d.ts +11 -0
  47. package/dist/commands/shared/campaign/chats.js +29 -0
  48. package/dist/commands/shared/campaign/images.js +7 -1
  49. package/dist/commands/shared/campaign/mode.js +3 -1
  50. package/dist/commands/shared/campaign/saves.js +13 -5
  51. package/dist/commands/shared/sheet/sheet.d.ts +7 -0
  52. package/dist/commands/shared/sheet/sheet.js +27 -0
  53. package/dist/commands/shared/time/dawn.d.ts +1 -1
  54. package/dist/commands/shared/time/dawn.js +19 -7
  55. package/dist/commands/status.d.ts +1 -0
  56. package/dist/commands/status.js +4 -0
  57. package/dist/commands/view/page.js +4 -3
  58. package/dist/commands/view/result.d.ts +2 -0
  59. package/dist/commands/view/view.d.ts +1 -0
  60. package/dist/commands/view/view.js +4 -0
  61. package/dist/core/consents.d.ts +2 -2
  62. package/dist/core/consents.js +3 -3
  63. package/dist/core/context.d.ts +38 -2
  64. package/dist/core/download.js +1 -1
  65. package/dist/dashboard/acts/names.js +10 -5
  66. package/dist/dashboard/acts/sending.js +5 -2
  67. package/dist/dashboard/acts/sheet.js +66 -15
  68. package/dist/dashboard/api.js +3 -3
  69. package/dist/dashboard/app.js +2 -2
  70. package/dist/dashboard/guide/ar.md +11 -10
  71. package/dist/dashboard/guide/cs.md +10 -9
  72. package/dist/dashboard/guide/da.md +12 -11
  73. package/dist/dashboard/guide/de.md +12 -11
  74. package/dist/dashboard/guide/el.md +12 -11
  75. package/dist/dashboard/guide/en.md +9 -8
  76. package/dist/dashboard/guide/es.md +10 -9
  77. package/dist/dashboard/guide/fi.md +10 -9
  78. package/dist/dashboard/guide/fr.md +16 -15
  79. package/dist/dashboard/guide/he.md +11 -10
  80. package/dist/dashboard/guide/hi.md +10 -9
  81. package/dist/dashboard/guide/hu.md +14 -13
  82. package/dist/dashboard/guide/is.md +10 -9
  83. package/dist/dashboard/guide/it.md +13 -12
  84. package/dist/dashboard/guide/ja.md +10 -9
  85. package/dist/dashboard/guide/ko.md +11 -10
  86. package/dist/dashboard/guide/nb.md +12 -11
  87. package/dist/dashboard/guide/nl.md +10 -9
  88. package/dist/dashboard/guide/pl.md +11 -10
  89. package/dist/dashboard/guide/pt.md +12 -11
  90. package/dist/dashboard/guide/ro.md +10 -9
  91. package/dist/dashboard/guide/ru.md +12 -11
  92. package/dist/dashboard/guide/sv.md +10 -9
  93. package/dist/dashboard/guide/tr.md +13 -12
  94. package/dist/dashboard/guide/uk.md +13 -12
  95. package/dist/dashboard/guide/zh.md +11 -10
  96. package/dist/dashboard/i18n/ar.json +31 -5
  97. package/dist/dashboard/i18n/cs.json +31 -5
  98. package/dist/dashboard/i18n/da.json +31 -5
  99. package/dist/dashboard/i18n/de.json +31 -5
  100. package/dist/dashboard/i18n/el.json +31 -5
  101. package/dist/dashboard/i18n/es.json +31 -5
  102. package/dist/dashboard/i18n/fi.json +31 -5
  103. package/dist/dashboard/i18n/fr.json +31 -5
  104. package/dist/dashboard/i18n/he.json +31 -5
  105. package/dist/dashboard/i18n/hi.json +31 -5
  106. package/dist/dashboard/i18n/hu.json +31 -5
  107. package/dist/dashboard/i18n/is.json +31 -5
  108. package/dist/dashboard/i18n/it.json +32 -6
  109. package/dist/dashboard/i18n/ja.json +31 -5
  110. package/dist/dashboard/i18n/ko.json +31 -5
  111. package/dist/dashboard/i18n/nb.json +31 -5
  112. package/dist/dashboard/i18n/nl.json +31 -5
  113. package/dist/dashboard/i18n/pl.json +31 -5
  114. package/dist/dashboard/i18n/pt.json +31 -5
  115. package/dist/dashboard/i18n/ro.json +31 -5
  116. package/dist/dashboard/i18n/ru.json +31 -5
  117. package/dist/dashboard/i18n/sv.json +31 -5
  118. package/dist/dashboard/i18n/tr.json +31 -5
  119. package/dist/dashboard/i18n/uk.json +31 -5
  120. package/dist/dashboard/i18n/zh.json +31 -5
  121. package/dist/dashboard/journal/book.js +106 -0
  122. package/dist/dashboard/journal/journal.js +9 -8
  123. package/dist/dashboard/parts/labels.js +6 -0
  124. package/dist/dashboard/parts/widgets.js +1 -1
  125. package/dist/dashboard/place/view.js +1 -1
  126. package/dist/dashboard/settings/settings.js +10 -4
  127. package/dist/dashboard/settings/setup.js +5 -3
  128. package/dist/dashboard/sheet/sheet.js +8 -5
  129. package/dist/dashboard/style.css +459 -96
  130. package/dist/dashboard/world/calendar.js +1 -1
  131. package/dist/dashboard/world/lore.js +1 -1
  132. package/dist/helpers/briefs.d.ts +5 -0
  133. package/dist/helpers/briefs.js +8 -0
  134. package/dist/helpers/chosen.d.ts +8 -2
  135. package/dist/helpers/chosen.js +110 -6
  136. package/dist/helpers/codex.js +2 -1
  137. package/dist/helpers/index.d.ts +2 -2
  138. package/dist/helpers/index.js +2 -2
  139. package/dist/images/images.d.ts +2 -0
  140. package/dist/images/images.js +16 -2
  141. package/dist/images/index.d.ts +1 -1
  142. package/dist/images/index.js +1 -1
  143. package/dist/server/approver.d.ts +6 -0
  144. package/dist/server/approver.js +28 -0
  145. package/dist/server/chats.d.ts +3 -0
  146. package/dist/server/chats.js +27 -0
  147. package/dist/server/dashboard/news.js +36 -5
  148. package/dist/server/mcp.js +37 -6
  149. package/dist/server/player-acts.d.ts +7 -2
  150. package/dist/server/player-acts.js +10 -3
  151. package/instructions/start.md +1 -1
  152. package/package.json +2 -2
@@ -0,0 +1,50 @@
1
+ import { join } from "node:path";
2
+ import { files } from "../core/store.js";
3
+ import { chatText, readChatText } from "./chat.js";
4
+ import { claudeCodeChats } from "./claude-code.js";
5
+ import { codexChats } from "./codex.js";
6
+ import { modifiedAt } from "./read.js";
7
+ /**
8
+ * Copies into `target` each chat of the campaign in `root` that the hosts keep in `folders`, as text, when it is new, changed since it was copied, or copied
9
+ * before the last of the loads that undid a stretch of it; a chat that does not read now is tried again the next time. Each is a file named by the day it
10
+ * began, its host and its id. How many it wrote.
11
+ */
12
+ export function keepChats(root, target, folders, platform, undone) {
13
+ const written = keptNames(target);
14
+ const lastLoad = Math.max(0, ...undone.map((stretch) => Date.parse(stretch.to)));
15
+ let count = 0;
16
+ for (const source of [...claudeCodeChats(folders.claudeCode, root), ...codexChats(folders.codex, root, platform)]) {
17
+ try {
18
+ const suffix = ` ${source.host} ${shortId(source.id)}.md`;
19
+ const before = written.find((name) => name.endsWith(suffix));
20
+ if (before !== undefined && (files().modified(join(target, before)) ?? 0) >= Math.max(modifiedAt(source.path), lastLoad)) {
21
+ continue;
22
+ }
23
+ const chat = source.read();
24
+ const first = chat?.messages[0];
25
+ if (chat === undefined || first === undefined) {
26
+ continue;
27
+ }
28
+ files().write(join(target, `${first.at.slice(0, 10)}${suffix}`), chatText(chat, undone));
29
+ count++;
30
+ }
31
+ catch {
32
+ // Tried again the next time.
33
+ }
34
+ }
35
+ return count;
36
+ }
37
+ /** The chats the campaign keeps as text in `target`, read back; a file rpg did not write is left out. Their host's own copy may be gone by now. */
38
+ export function keptChats(target) {
39
+ return keptNames(target).flatMap((name) => {
40
+ const chat = readChatText(files().text(join(target, name)) ?? "");
41
+ return chat === undefined ? [] : [chat];
42
+ });
43
+ }
44
+ function keptNames(target) {
45
+ return files().entries(target).filter((entry) => !entry.isFolder && entry.name.endsWith(".md")).map((entry) => entry.name);
46
+ }
47
+ /** The end of a chat's id, which differs between chats started in the same minute, as the beginning of Codex's does not. */
48
+ function shortId(id) {
49
+ return id.replaceAll("-", "").slice(-8);
50
+ }
@@ -0,0 +1,8 @@
1
+ /** The chat files in a host's folder, `.jsonl`, right inside it or in the folders below with `deep`; none when there is no such folder. */
2
+ export declare function chatFiles(folder: string, deep: boolean): string[];
3
+ /** Each line of a chat file read as JSON; a line that does not read, as one being written, is left out. */
4
+ export declare function jsonLines(path: string): unknown[];
5
+ /** The first line of a chat file read as JSON, without reading the rest; undefined when it does not read. */
6
+ export declare function firstJsonLine(path: string): unknown;
7
+ /** When a chat file last changed, in milliseconds. */
8
+ export declare function modifiedAt(path: string): number;
@@ -0,0 +1,46 @@
1
+ // The chats the AI hosts keep in their own folders, outside every campaign (T-225): the only files of this module read straight from the disk.
2
+ import { closeSync, existsSync, openSync, readFileSync, readSync, statSync } from "node:fs";
3
+ import { dirname, resolve } from "node:path";
4
+ import { filesIn } from "../core/files.js";
5
+ /** The chat files in a host's folder, `.jsonl`, right inside it or in the folders below with `deep`; none when there is no such folder. */
6
+ export function chatFiles(folder, deep) {
7
+ return existsSync(folder) ? filesIn(folder, (name) => name.endsWith(".jsonl")).filter((path) => deep || resolve(dirname(path)) === resolve(folder)) : [];
8
+ }
9
+ /** Each line of a chat file read as JSON; a line that does not read, as one being written, is left out. */
10
+ export function jsonLines(path) {
11
+ return readFileSync(path, "utf8").split("\n").flatMap((line) => {
12
+ try {
13
+ return line.trim() === "" ? [] : [JSON.parse(line)];
14
+ }
15
+ catch {
16
+ return [];
17
+ }
18
+ });
19
+ }
20
+ /** The first line of a chat file read as JSON, without reading the rest; undefined when it does not read. */
21
+ export function firstJsonLine(path) {
22
+ const handle = openSync(path, "r");
23
+ try {
24
+ let text = "";
25
+ const buffer = Buffer.alloc(65_536);
26
+ // The first line of a long chat can hold the host's whole instructions: read until it ends, a megabyte at most.
27
+ while (!text.includes("\n") && text.length < 1_048_576) {
28
+ const read = readSync(handle, buffer, 0, buffer.length, null);
29
+ if (read === 0) {
30
+ break;
31
+ }
32
+ text += buffer.toString("utf8", 0, read);
33
+ }
34
+ return JSON.parse(text.split("\n")[0] ?? "");
35
+ }
36
+ catch {
37
+ return undefined;
38
+ }
39
+ finally {
40
+ closeSync(handle);
41
+ }
42
+ }
43
+ /** When a chat file last changed, in milliseconds. */
44
+ export function modifiedAt(path) {
45
+ return statSync(path).mtimeMs;
46
+ }
package/dist/cli/cli.js CHANGED
@@ -2,7 +2,8 @@
2
2
  import { runCommandLine } from "./command-line.js";
3
3
  const args = process.argv.slice(2);
4
4
  // "rpg mcp" turns the process into a server for an AI host; "rpg --read-library" reads the player's books apart, as rules starts it (LIB-3); "rpg --listen"
5
- // is Claude Code's doorbell for the player's sentences on the dashboard (D-495); everything else is a command.
5
+ // is Claude Code's doorbell for the player's sentences on the dashboard (D-495); "rpg --approve" is Antigravity's hook that lets the rpg tools run; everything
6
+ // else is a command.
6
7
  if (args.length === 1 && args[0] === "mcp") {
7
8
  // The server and its SDK load only here: every other command starts faster without them (D-194).
8
9
  const { startMcpServer } = await import("../server/mcp.js");
@@ -16,6 +17,10 @@ else if (args.length === 1 && args[0] === "--listen") {
16
17
  const { listenHere } = await import("../server/bell-listener.js");
17
18
  await listenHere();
18
19
  }
20
+ else if (args.length === 1 && args[0] === "--approve") {
21
+ const { approveHere } = await import("../server/approver.js");
22
+ await approveHere();
23
+ }
19
24
  else {
20
25
  const { output, exitCode } = await runCommandLine(args);
21
26
  if (exitCode === 0) {
@@ -1,6 +1,6 @@
1
1
  import { parseArgs } from "node:util";
2
2
  import { z } from "zod";
3
- import { findCampaign } from "../campaign/index.js";
3
+ import { chosenPictureMaker, findCampaign } from "../campaign/index.js";
4
4
  import { commands } from "../commands/index.js";
5
5
  import { libraryRunner } from "../commands/shared/books/library-reader.js";
6
6
  import { loadCampaignCode, packageCommands } from "../commands/shared/packages/code.js";
@@ -23,7 +23,8 @@ const hookCommands = new Set(["ask", "change", "effect", "roll", "scene"]);
23
23
  /** The `rpg` command line: finds the command, validates its input, runs it and renders the result. */
24
24
  export async function runCommandLine(argv, context = {
25
25
  ...defaultContext(),
26
- pictures: hostPictures(() => undefined),
26
+ // Who makes the pictures, as the campaign of the folder chose (D-572); else Claude's drawing.
27
+ pictures: hostPictures(() => undefined, () => chosenPictureMaker(process.cwd())),
27
28
  // An import run apart by the MCP server uses the helper of the chat that started it.
28
29
  reader: hostReader(() => process.env.RPG_HOST || undefined),
29
30
  packages: npmPackages(packagesFolder()),
@@ -0,0 +1,55 @@
1
+ import { z } from "zod";
2
+ import { type SceneChapter } from "./shared/campaign/book.ts";
3
+ export declare const book: import("../core/registry.ts").Command<z.ZodObject<{
4
+ chapter: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
5
+ title: z.ZodOptional<z.ZodString>;
6
+ text: z.ZodOptional<z.ZodString>;
7
+ }, z.core.$strip>, {
8
+ kind: "list";
9
+ written: number;
10
+ closed: number;
11
+ missing: SceneChapter[];
12
+ craft: string | undefined;
13
+ scene?: undefined;
14
+ chapter?: undefined;
15
+ had?: undefined;
16
+ title?: undefined;
17
+ words?: undefined;
18
+ left?: undefined;
19
+ } | {
20
+ kind: "read";
21
+ scene: SceneChapter;
22
+ chapter: import("./shared/campaign/book.ts").BookChapter | undefined;
23
+ craft: string | undefined;
24
+ written?: undefined;
25
+ closed?: undefined;
26
+ missing?: undefined;
27
+ had?: undefined;
28
+ title?: undefined;
29
+ words?: undefined;
30
+ left?: undefined;
31
+ } | {
32
+ kind: "removed";
33
+ scene: SceneChapter;
34
+ had: boolean;
35
+ written?: undefined;
36
+ closed?: undefined;
37
+ missing?: undefined;
38
+ craft?: undefined;
39
+ chapter?: undefined;
40
+ title?: undefined;
41
+ words?: undefined;
42
+ left?: undefined;
43
+ } | {
44
+ kind: "written";
45
+ scene: SceneChapter;
46
+ title: string;
47
+ words: number;
48
+ left: number[];
49
+ written?: undefined;
50
+ closed?: undefined;
51
+ missing?: undefined;
52
+ craft?: undefined;
53
+ chapter?: undefined;
54
+ had?: undefined;
55
+ }>;
@@ -0,0 +1,105 @@
1
+ import { z } from "zod";
2
+ import { requireCampaign } from "../campaign/index.js";
3
+ import { appendLogEntry } from "../core/log.js";
4
+ import { defineCommand } from "../core/registry.js";
5
+ import { campaignBook, chapterCraft, removeChapter, sceneChapters, writeChapter } from "./shared/campaign/book.js";
6
+ import { firstInChat } from "./shared/campaign/parts.js";
7
+ import { newDatedLogEntry } from "./shared/time/time.js";
8
+ // How many chapters still to write a list shows, the first; the others are counted.
9
+ const listedChapters = 20;
10
+ // The longest chapter the book takes, in characters.
11
+ const chapterLength = 60_000;
12
+ export const book = defineCommand({
13
+ name: "book",
14
+ description: "The campaign's story told as a book, which the player reads in the dashboard's Journal: a novel's chapter, never a summary, for each closed scene, by its number. "
15
+ + "Write each once its scene closes. With nothing, it lists the closed chapters still to write, which is how a campaign begun without the book gets the story so far; "
16
+ + "with chapter alone, it reads one back, so that the voice holds from one to the next; empty text takes it out. The first call in a chat says how to write them.",
17
+ group: "game",
18
+ positionals: ["chapter"],
19
+ input: z.object({
20
+ chapter: z.coerce.number().int().positive().optional().describe("the chapter's number, its scene's as the journal counts them"),
21
+ title: z.string().optional().describe("the chapter's title, its scene's if left out"),
22
+ text: z.string().optional().describe("the chapter's prose, in markdown; empty to take it out"),
23
+ }),
24
+ run(input, context) {
25
+ const root = requireCampaign(context.folder);
26
+ const scenes = sceneChapters(root);
27
+ const written = campaignBook(root);
28
+ const craft = firstInChat(context, "book") ? chapterCraft : undefined;
29
+ const unwritten = (scene) => scene.to !== undefined && !written.some((chapter) => chapter.number === scene.number);
30
+ if (input.chapter === undefined) {
31
+ if (input.title !== undefined || input.text !== undefined) {
32
+ throw new Error("Give chapter, the number of the chapter to write: book alone lists those still to write. Nothing written.");
33
+ }
34
+ return { kind: "list", written: written.length, closed: scenes.filter((scene) => scene.to !== undefined).length, missing: scenes.filter(unwritten), craft };
35
+ }
36
+ const scene = closedScene(scenes, input.chapter);
37
+ const before = written.find((chapter) => chapter.number === scene.number);
38
+ if (input.text === undefined && input.title === undefined) {
39
+ return { kind: "read", scene, chapter: before, craft };
40
+ }
41
+ const text = (input.text ?? before?.text ?? "").replace(/\r\n?/g, "\n").trim().normalize("NFC");
42
+ if (input.text !== undefined && text === "") {
43
+ if (before !== undefined) {
44
+ removeChapter(root, scene.number);
45
+ appendLogEntry(root, newDatedLogEntry(root, context, "book-chapter", "hidden", { chapter: scene.number, removed: true }));
46
+ }
47
+ return { kind: "removed", scene, had: before !== undefined };
48
+ }
49
+ if (text === "") {
50
+ throw new Error(`Chapter ${scene.number} is not written yet: give its text with the title. Nothing written.`);
51
+ }
52
+ if (text.length > chapterLength) {
53
+ throw new Error(`This chapter is ${text.length} characters, the book takes ${chapterLength}: tell the scene shorter. Nothing written.`);
54
+ }
55
+ const title = input.title?.trim() || before?.title || scene.title;
56
+ writeChapter(root, scene, title, text);
57
+ const words = text.split(/\s+/).filter((word) => word !== "").length;
58
+ appendLogEntry(root, newDatedLogEntry(root, context, "book-chapter", "hidden", { chapter: scene.number, title, words }));
59
+ return { kind: "written", scene, title, words, left: scenes.filter((other) => other.number !== scene.number && unwritten(other)).map((other) => other.number) };
60
+ },
61
+ format(result) {
62
+ const craft = "craft" in result && result.craft !== undefined ? `\n\n${result.craft}` : "";
63
+ if (result.kind === "list") {
64
+ if (result.closed === 0) {
65
+ return `No scene has closed yet: the book's first chapter comes with the first scene's end.${craft}`;
66
+ }
67
+ if (result.missing.length === 0) {
68
+ return `The book has every closed chapter, ${result.written}: write the next when its scene closes.${craft}`;
69
+ }
70
+ const lines = result.missing.slice(0, listedChapters).map(missingLine);
71
+ const more = result.missing.length > listedChapters ? `\nAnd ${result.missing.length - listedChapters} more after them.` : "";
72
+ return `The book has ${result.written} of ${result.closed} closed chapters. To write, in order, each from its chats first, then its summary and the pages:\n${lines.join("\n")}${more}${craft}`;
73
+ }
74
+ if (result.kind === "read") {
75
+ return result.chapter === undefined
76
+ ? `Chapter ${result.scene.number} is not written yet.\n${missingLine(result.scene)}${craft}`
77
+ : `Chapter ${result.scene.number} «${result.chapter.title}»:\n\n${result.chapter.text}${craft}`;
78
+ }
79
+ if (result.kind === "removed") {
80
+ return result.had ? `Chapter ${result.scene.number} taken out of the book.` : `Chapter ${result.scene.number} was not in the book: nothing changed.`;
81
+ }
82
+ const shown = result.left.slice(0, listedChapters).join(", ");
83
+ const left = result.left.length === 0 ? "" : ` Still to write: ${shown}${result.left.length > listedChapters ? "…" : ""}.`;
84
+ return `Chapter ${result.scene.number} «${result.title}» written, ${result.words} words: the player reads it in the Journal, under Story.${left}`;
85
+ },
86
+ });
87
+ /** The closed scene that is a chapter's; stops the command for any other number. */
88
+ function closedScene(scenes, number) {
89
+ const scene = scenes.find((one) => one.number === number);
90
+ if (scene === undefined) {
91
+ throw new Error(`There is no chapter ${number}: the story has ${scenes.length}. book alone lists those still to write. Nothing written.`);
92
+ }
93
+ if (scene.to === undefined) {
94
+ throw new Error(`Chapter ${number} is the scene still open: write it once the scene closes. Nothing written.`);
95
+ }
96
+ return scene;
97
+ }
98
+ /** A chapter to write: its title and game date, its summary, and when it ran in real time, for chats to read it. */
99
+ function missingLine(scene) {
100
+ const date = scene.date === undefined ? "" : `, ${scene.date}`;
101
+ const summary = scene.summary === undefined ? "" : `: ${scene.summary}`;
102
+ const otherDay = scene.to !== undefined && scene.to.slice(0, 10) !== scene.from.slice(0, 10) ? ` of ${scene.to.slice(0, 10)}` : "";
103
+ const until = scene.to === undefined ? "" : `, until ${scene.to.slice(11, 19)}${otherDay}`;
104
+ return `${scene.number} «${scene.title}»${date}${summary} (chats: day ${scene.from.slice(0, 10)}, from ${scene.from.slice(11, 19)}${until})`;
105
+ }
@@ -0,0 +1,38 @@
1
+ import { z } from "zod";
2
+ import { type ChatMessage } from "../chats/index.ts";
3
+ export declare const chats: import("../core/registry.ts").Command<z.ZodObject<{
4
+ text: z.ZodOptional<z.ZodString>;
5
+ day: z.ZodOptional<z.ZodString>;
6
+ from: z.ZodOptional<z.ZodString>;
7
+ }, z.core.$strip>, {
8
+ kind: "day";
9
+ day: string;
10
+ messages: ChatMessage[];
11
+ next: string;
12
+ leftOut: number;
13
+ days?: undefined;
14
+ passages?: undefined;
15
+ more?: undefined;
16
+ } | {
17
+ kind: "days";
18
+ days: [string, number][];
19
+ leftOut: number;
20
+ day?: undefined;
21
+ messages?: undefined;
22
+ next?: undefined;
23
+ passages?: undefined;
24
+ more?: undefined;
25
+ } | {
26
+ kind: "found";
27
+ passages: {
28
+ text: string;
29
+ who: "player" | "master";
30
+ at: string;
31
+ }[];
32
+ more: number;
33
+ leftOut: number;
34
+ day?: undefined;
35
+ messages?: undefined;
36
+ next?: undefined;
37
+ days?: undefined;
38
+ }>;
@@ -0,0 +1,93 @@
1
+ import { z } from "zod";
2
+ import { requireCampaign } from "../campaign/index.js";
3
+ import { undoneAt } from "../chats/index.js";
4
+ import { defineCommand } from "../core/registry.js";
5
+ import { comparableText } from "../core/text.js";
6
+ import { campaignChats, undoneStretches } from "./shared/campaign/chats.js";
7
+ // How many passages a search shows, the newest first; the others are counted.
8
+ const shownPassages = 8;
9
+ // About how many characters a passage shows around the words found.
10
+ const passageLength = 320;
11
+ // About how many characters a day's reading gives at once: the rest is read from where it stopped.
12
+ const readLength = 24_000;
13
+ export const chats = defineCommand({
14
+ name: "chats",
15
+ description: "Read what the player and you said in the campaign's past chats, kept as text: what was narrated or promised, a detail described, a name said and never written. "
16
+ + "Give words to find the passages that hold them, the newest first; a day, as find gives it, to read that day's chats in order; nothing to list the days. "
17
+ + "What a loaded save undid is left out: it did not happen. The chat going on is yours already, and may be a few minutes behind here.",
18
+ group: "game",
19
+ readOnly: true,
20
+ positionals: ["text"],
21
+ input: z.object({
22
+ text: z.string().optional().describe("words to find in the chats, ignoring case and accents"),
23
+ day: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "a day is written 2026-11-19").optional().describe("a day of real time, as 2026-11-19, to read its chats in order"),
24
+ from: z.string().regex(/^\d{2}:\d{2}(:\d{2})?$/, "a time is written 21:40 or 21:40:15").optional().describe("with day: read from this time (UTC), where the last reading stopped"),
25
+ }),
26
+ run(input, context) {
27
+ const root = requireCampaign(context.folder);
28
+ const undone = undoneStretches(root);
29
+ const all = campaignChats(root).flatMap((chat) => chat.messages).sort((one, other) => one.at.localeCompare(other.at));
30
+ const standing = all.filter((message) => undoneAt(message.at, undone) === undefined);
31
+ const leftOut = all.length - standing.length;
32
+ if (input.day !== undefined) {
33
+ const day = input.day;
34
+ const from = input.from === undefined ? `${day}T00:00:00Z` : `${day}T${input.from.length === 5 ? `${input.from}:00` : input.from}Z`;
35
+ const ofDay = (messages) => messages.filter((message) => message.at.startsWith(day) && message.at >= from);
36
+ const read = upTo(ofDay(standing), readLength);
37
+ return { kind: "day", day, messages: read, next: ofDay(standing)[read.length]?.at, leftOut: ofDay(all).length - ofDay(standing).length };
38
+ }
39
+ const words = comparableText(input.text ?? "").split(/\s+/).filter((word) => word !== "");
40
+ if (words.length === 0) {
41
+ const days = new Map();
42
+ standing.forEach((message) => days.set(message.at.slice(0, 10), (days.get(message.at.slice(0, 10)) ?? 0) + 1));
43
+ return { kind: "days", days: [...days].reverse(), leftOut };
44
+ }
45
+ const holds = (message) => words.every((word) => comparableText(message.text).includes(word));
46
+ const found = standing.filter(holds).reverse();
47
+ return {
48
+ kind: "found",
49
+ passages: found.slice(0, shownPassages).map((message) => ({ ...message, text: passage(message.text, words[0] ?? "") })),
50
+ more: Math.max(0, found.length - shownPassages),
51
+ leftOut: all.filter(holds).length - found.length,
52
+ };
53
+ },
54
+ format(result) {
55
+ const undone = result.leftOut > 0
56
+ ? `\n\n${result.leftOut} message${result.leftOut === 1 ? "" : "s"} of what a loaded save undid ${result.leftOut === 1 ? "is" : "are"} left out: ${result.leftOut === 1 ? "it" : "they"} did not happen.`
57
+ : "";
58
+ if (result.kind === "days") {
59
+ return result.days.length === 0
60
+ ? `The campaign keeps no chat yet: they are copied from Claude Code and Codex as the game goes on.${undone}`
61
+ : `Days with chats, the newest first (give one as day to read it):\n${result.days.map(([day, count]) => `${day}: ${count} messages`).join("\n")}${undone}`;
62
+ }
63
+ if (result.kind === "day") {
64
+ const lines = result.messages.map((message) => `${message.at.slice(11, 19)} ${speaker(message)}: ${message.text}`);
65
+ const rest = result.next === undefined ? "" : `\n\nThe day goes on: call chats again with day ${result.day} and from ${result.next.slice(11, 19)}.`;
66
+ return `${lines.length === 0 ? `No chat of ${result.day}${result.next === undefined ? "" : " from then"}: call chats without words for the days.` : lines.join("\n\n")}${rest}${undone}`;
67
+ }
68
+ const lines = result.passages.map((message) => `${message.at.slice(0, 16).replace("T", " ")} ${speaker(message)}: ${message.text}`);
69
+ const more = result.more > 0 ? `\n\nAnd ${result.more} older: give more words, or read their day.` : "";
70
+ return `${lines.length === 0 ? "No chat holds those words. What happened only in this chat is yours already." : lines.join("\n\n")}${more}${undone}`;
71
+ },
72
+ });
73
+ function speaker(message) {
74
+ return message.who === "player" ? "Player" : "Master";
75
+ }
76
+ /** The messages from the first, as many as fit in `length` characters, one at least. */
77
+ function upTo(messages, length) {
78
+ let used = 0;
79
+ return messages.filter((message, index) => {
80
+ used += message.text.length;
81
+ return index === 0 || used <= length;
82
+ });
83
+ }
84
+ /** The part of a message around the first word found, on one line. */
85
+ function passage(text, word) {
86
+ const flat = text.replace(/\s+/g, " ").trim();
87
+ if (flat.length <= passageLength) {
88
+ return flat;
89
+ }
90
+ const at = Math.max(0, comparableText(flat).indexOf(word));
91
+ const start = Math.max(0, Math.min(at - passageLength / 3, flat.length - passageLength));
92
+ return `${start > 0 ? "…" : ""}${flat.slice(start, start + passageLength).trim()}${start + passageLength < flat.length ? "…" : ""}`;
93
+ }
@@ -185,7 +185,7 @@ function configure(input, context) {
185
185
  // What the next campaign's setup suggests; a custom difficulty or rigor is this campaign's own (T-134).
186
186
  const chosen = readSettings(root)[input.setting];
187
187
  if (chosen !== customLevel) {
188
- rememberChoice(context.home, input.setting, chosen);
188
+ rememberChoice(context.home, root, input.setting, chosen);
189
189
  }
190
190
  }
191
191
  if (startsCustom && leveledName !== undefined && readSettings(root)[leveledName] === customLevel) {
@@ -17,10 +17,17 @@ export interface PlayerSetting {
17
17
  last?: string;
18
18
  /** In the setup, the question its card asks in place of its name, as how well the player knows the game (D-347). */
19
19
  question?: string;
20
- /** What the player should know of it on this computer, as whether pictures can be made here; fix when it says how to have what is missing. */
20
+ /** In the setup, the game system its question names as {game}, by its name (T-211). */
21
+ game?: string;
22
+ /**
23
+ * What the player should know of it on this computer, as whether pictures can be made here; fix when it says how to have what is missing; the values its
24
+ * {names} take, as a maker's own words; and a line after it.
25
+ */
21
26
  note?: {
22
27
  text: string;
23
28
  fix?: true;
29
+ values?: Record<string, string>;
30
+ also?: string;
24
31
  };
25
32
  /** A setting of the player's own words, as the author the master writes like, the longest its text may be (D-395); for a list, each item's (D-563). */
26
33
  most?: number;
@@ -1,7 +1,7 @@
1
1
  // The player's settings and the setup's questions as the dashboard shows them (D-341, D-370)
2
2
  import { customLevel, customLevels, customSettings, lastChoices, listSettingNames, readOneSetting, readSettings, setupSettingNames } from "../../campaign/index.js";
3
3
  import { comparableText } from "../../core/text.js";
4
- import { claudeSays, codexSays } from "../../helpers/index.js";
4
+ import { claudeSays, codexClient, codexSays } from "../../helpers/index.js";
5
5
  import { readBetweenSessions } from "../../time/index.js";
6
6
  import { heldSystemSettings, isLeading, offeredValues, playedEngineSetting } from "../shared/campaign/offers.js";
7
7
  import { playedSettingValue } from "../shared/campaign/world.js";
@@ -24,19 +24,23 @@ export function setupQuestions(root, context, writtenWorld) {
24
24
  // The value a system's setting suggests (DAT-17).
25
25
  const systemSuggests = Object.fromEntries(held.flatMap((setting) => setting.values.filter((value) => value.suggested === true).map((value) => [setting.name, value.value])));
26
26
  // The player's last choices first: how they like to play, from their last campaign on this computer (T-134).
27
- const last = lastChoices(context.home);
27
+ const last = lastChoices(context.home, root);
28
28
  const suggested = { ...suggestedValues, ...(difficulty === undefined ? {} : { lethality: suggestedLethality[difficulty] ?? "dice" }), ...systemSuggests, ...last };
29
29
  // The system's settings others depend on right after the mentor, before what they change (DAT-16, DAT-17).
30
30
  const leading = held.filter(isLeading).map((setting) => setting.name);
31
31
  const order = setupOrder.filter((name) => !writtenWorld || !worldSettingNames.includes(name));
32
32
  const others = system.filter((name) => !leading.includes(name));
33
- return [...order.slice(0, 1), ...leading, ...order.slice(1), ...others, "lines", "veils"].flatMap(named).map((question) => {
33
+ // How well the player knows the game, once the chat has chosen it: the question names it (T-211).
34
+ const game = settings.system;
35
+ const first = game === undefined ? [] : order.slice(0, 1);
36
+ return [...first, ...leading, ...order.slice(1), ...others, "lines", "veils"].flatMap(named).map((question) => {
34
37
  const suggestion = suggested[question.name];
35
38
  // A suggestion the game does not offer is none (DAT-16).
36
39
  const offered = suggestion !== undefined && (question.choices === undefined || question.choices.some((choice) => choice.value === suggestion));
37
40
  const asked = { ...question, ...(question.choices === undefined ? {} : { choices: question.choices.filter((choice) => choice.value !== customLevel) }) };
38
41
  const lastOne = offered && last[question.name] === suggestion ? { last: suggestion } : {};
39
- return { ...(question.name === "mentor" ? mentorQuestion(asked) : unsetUnanswered(asked, settings)), ...(offered ? { suggested: suggestion } : {}), ...lastOne };
42
+ const worded = Object.hasOwn(questionTexts, question.name) ? { question: questionTexts[question.name] } : {};
43
+ return { ...(question.name === "mentor" ? mentorQuestion(asked, game ?? "") : unsetUnanswered(asked, settings)), ...worded, ...(offered ? { suggested: suggestion } : {}), ...lastOne };
40
44
  });
41
45
  }
42
46
  /** A setting only the setup lets the dashboard change (D-370): how the character and the companions come, the preparation, the length, the name; undefined for any other. */
@@ -91,7 +95,7 @@ export function playerSettings(root, context) {
91
95
  ...(choices === undefined ? {} : { choices }),
92
96
  ...(words.most === undefined ? {} : { most: words.most }),
93
97
  }];
94
- }).flatMap((setting) => offeredSetting(root, context, setting)),
98
+ }).flatMap((setting) => offeredSetting(root, context, setting)).map((setting) => (setting.name === "pictures-by" ? makersInChat(context, setting) : setting)),
95
99
  ...own,
96
100
  ];
97
101
  }
@@ -101,13 +105,15 @@ export function playerSettingNamed(root, context, name) {
101
105
  }
102
106
  // The setup's questions, in the order the player meets them on the dashboard: how well they know the game, how it plays, how it is rolled, who comes along,
103
107
  // the world and how long it plays, then the limits.
104
- const setupOrder = ["mentor", "difficulty", "lethality", "saves", "rigor", "dice", "master-rolls", "units", "character", "companions", "preparation", "length"];
108
+ const setupOrder = ["mentor", "difficulty", "lethality", "saves", "rigor", "dice", "master-rolls", "units", "character", "companions", "preparation", "length", "pictures", "pictures-by"];
109
+ // The questions the setup's cards ask in place of a setting's name (D-572).
110
+ const questionTexts = { pictures: "Do you want pictures of places and of those you meet?", "pictures-by": "Who makes them?" };
105
111
  // The mentor as the setup asks it (D-347): how well the player knows the game, each answer a way of the mentor, from the newest player's.
106
112
  const mentorAnswers = { tutorial: "never played it", hints: "a little", off: "I know it" };
107
113
  // What the setup asks only of a world not written (D-80, D-558): a written one has its own.
108
114
  const worldSettingNames = ["preparation", "length"];
109
115
  // The values the game suggests in the setup, as the design has them by default (D-370): never chosen for the player.
110
- const suggestedValues = { saves: "checkpoint", rigor: "smooth", "master-rolls": "behind the screen", character: "made with the player", preparation: "on the fly", length: "one evening" };
116
+ const suggestedValues = { saves: "checkpoint", rigor: "smooth", "master-rolls": "behind the screen", character: "made with the player", preparation: "on the fly", length: "one evening", "pictures-by": "chat" };
111
117
  // The lethality the difficulty suggests (D-141).
112
118
  const suggestedLethality = { story: "narrative", easy: "epic" };
113
119
  /** A question whose value is only the one shown while it is unset, as master-rolls behind the screen (D-287): still unanswered in the setup. */
@@ -115,11 +121,22 @@ function unsetUnanswered(question, settings) {
115
121
  const { value, ...unanswered } = question;
116
122
  return value !== undefined && wordsOf(question.name)?.unset === value && settings[question.name] === undefined ? unanswered : question;
117
123
  }
118
- /** The mentor as the setup asks it (D-347): how well the player knows the game, never played it first. */
119
- function mentorQuestion(question) {
124
+ /** The mentor as the setup asks it (D-347): how well the player knows the game, by the name of its system (T-211), never played it first. */
125
+ function mentorQuestion(question, game) {
120
126
  const order = Object.keys(mentorAnswers);
121
127
  const choices = (question.choices ?? []).map((choice) => ({ ...choice, label: mentorAnswers[choice.value] })).sort((one, other) => order.indexOf(one.value) - order.indexOf(other.value));
122
- return { ...question, question: "How well do you know this game?", about: "the master teaches it as much as you need", choices };
128
+ // Free play has no rules of its own to know: the question is about role-playing games.
129
+ const named = game === freePlay ? { question: "How well do you know role-playing games?" } : { question: "How well do you know {game}?", game };
130
+ return { ...question, ...named, about: "the master teaches it as much as you need", choices };
131
+ }
132
+ // The engine's own game system, free play, without rules of its own.
133
+ const freePlay = "free";
134
+ /** Who makes the pictures as the chat in use offers it (D-572): in Codex, Codex is the chat itself, so it is not offered, and a campaign that chose it plays chat. */
135
+ function makersInChat(context, setting) {
136
+ if (context.host?.() !== codexClient) {
137
+ return setting;
138
+ }
139
+ return { ...setting, ...(setting.value === "codex" ? { value: "chat" } : {}), choices: setting.choices?.filter((choice) => choice.value !== "codex") };
123
140
  }
124
141
  /** A player's setting as the game offers it (DAT-16): none where it plays one value alone; only the values it offers, and no value written that it does not. */
125
142
  function offeredSetting(root, context, setting) {
@@ -134,14 +151,45 @@ function offeredSetting(root, context, setting) {
134
151
  const kept = offered.some((one) => comparableText(one) === comparableText(value ?? "")) ? { value } : {};
135
152
  return [{ ...rest, ...kept, ...(setting.choices === undefined ? {} : { choices: setting.choices.filter((choice) => offered.some((one) => comparableText(one) === comparableText(choice.value))) }) }];
136
153
  }
137
- // Who makes the pictures on this computer, in the player's words (D-390).
138
- const madeBy = { Codex: "Codex makes them on this computer, from your ChatGPT plan.", Claude: "Claude draws them on this computer, as vector pictures, from your Claude plan." };
154
+ // Who makes the pictures on this computer, in the player's words (D-390, D-572).
155
+ const madeBy = {
156
+ Codex: "Codex makes them on this computer, from your ChatGPT plan.",
157
+ Claude: "Claude draws them on this computer, as vector pictures, from your Claude plan.",
158
+ Antigravity: "Antigravity makes them in your chat, from your Google plan.",
159
+ };
160
+ // The master makes them with an image tool of its own, as ElevenLabs's (D-572).
161
+ const madeWithTool = "The master makes them with {tool}.";
162
+ const toolAsked = "The master asks you in the chat which tool to use.";
163
+ // Where the maker the player chose made no picture, and the chat in use makes them (D-572): it refused one, with its own words, or it cannot.
164
+ const refusedNote = "{maker} refused the last picture: {why}. {by} makes them instead.";
165
+ const madeMeanwhile = "{by} makes them meanwhile.";
139
166
  /** Every note the pictures' setting may have, which the dashboard writes in its language (D-394). */
140
- export const picturesNotes = [...Object.values(madeBy), ...[...Object.values(codexSays), ...Object.values(claudeSays)].map(notReadyText)];
141
- /** Whether this computer makes pictures, and with whose plan, in the player's words (D-308, D-390); why not and how to have them; nothing where no maker is asked. */
167
+ export const picturesNotes = [...Object.values(madeBy), madeWithTool, toolAsked, refusedNote, madeMeanwhile, ...[...Object.values(codexSays), ...Object.values(claudeSays)].map(notReadyText)];
168
+ /**
169
+ * Whether this computer makes pictures, and with whose plan, in the player's words (D-308, D-390); why not and how to have them; where the maker the player
170
+ * chose made none and the chat in use makes them, why (D-572); nothing where no maker is asked.
171
+ */
142
172
  function picturesReadyNote(context) {
143
173
  const ready = context.pictures?.ready(true);
144
- return ready === undefined ? {} : { note: ready.ready ? { text: madeBy[ready.maker ?? "Codex"] } : { text: notReadyText(ready), fix: true } };
174
+ if (ready === undefined) {
175
+ return {};
176
+ }
177
+ if (!ready.ready) {
178
+ return { note: { text: notReadyText(ready), fix: true } };
179
+ }
180
+ const instead = ready.instead;
181
+ if (instead !== undefined) {
182
+ return instead.refused === true
183
+ ? { note: { text: refusedNote, values: { maker: instead.maker, why: instead.why.replace(/\.$/, ""), by: instead.by } } }
184
+ : { note: { text: notReadyText(instead), fix: true, values: { by: instead.by }, also: madeMeanwhile } };
185
+ }
186
+ if (ready.tool !== undefined) {
187
+ return { note: { text: madeWithTool, values: { tool: ready.tool } } };
188
+ }
189
+ if (ready.askTool === true) {
190
+ return { note: { text: toolAsked } };
191
+ }
192
+ return { note: { text: madeBy[ready.maker === "Claude" || ready.maker === "Antigravity" ? ready.maker : "Codex"] } };
145
193
  }
146
194
  /** How the player has pictures, or else why there are none. */
147
195
  function notReadyText(said) {
@@ -1,7 +1,7 @@
1
1
  export declare const styleSettingNames: string[];
2
2
  export declare const betweenSessionsWays: readonly ["stops", "1d per 7d", "1d per 1d"];
3
3
  /** The settings the player changes on the dashboard (D-341): how the game plays for them; the master's own, as house rules, coins and precedents, stay in the chat. */
4
- export declare const playerSettingNames: readonly ["difficulty", "custom-difficulty", "lethality", "saves", "rigor", "custom-rigor", "between-sessions", "mentor", "learned", "prose", "story", "author", "style", "dice", "master-rolls", "units", "voices", "pictures", "effort", "lines", "veils", "orders", "language"];
4
+ export declare const playerSettingNames: readonly ["difficulty", "custom-difficulty", "lethality", "saves", "rigor", "custom-rigor", "between-sessions", "mentor", "learned", "prose", "story", "author", "style", "dice", "master-rolls", "units", "voices", "pictures", "pictures-by", "effort", "lines", "veils", "orders", "language"];
5
5
  export declare const playerWords: Record<(typeof playerSettingNames)[number], PlayerWords>;
6
6
  /**
7
7
  * What a setting of the player's is to them, its values and what each means; what the master does when an item is added to a list or taken off it, or a text