rpg-engine 0.19.1 → 0.21.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.
- package/README.md +9 -6
- package/dist/adventures/index.d.ts +1 -1
- package/dist/adventures/index.js +1 -1
- package/dist/adventures/source.d.ts +3 -0
- package/dist/adventures/source.js +11 -49
- package/dist/campaign/create-campaign.d.ts +1 -1
- package/dist/campaign/create-campaign.js +4 -3
- package/dist/campaign/find-campaign.d.ts +6 -0
- package/dist/campaign/find-campaign.js +7 -1
- package/dist/campaign/host-files.js +22 -0
- package/dist/campaign/index.d.ts +2 -2
- package/dist/campaign/index.js +2 -2
- package/dist/campaign/last-choices.d.ts +10 -4
- package/dist/campaign/last-choices.js +43 -17
- package/dist/campaign/settings.d.ts +10 -2
- package/dist/campaign/settings.js +32 -8
- package/dist/chats/chat.d.ts +33 -0
- package/dist/chats/chat.js +50 -0
- package/dist/chats/claude-code.d.ts +5 -0
- package/dist/chats/claude-code.js +39 -0
- package/dist/chats/codex.d.ts +3 -0
- package/dist/chats/codex.js +42 -0
- package/dist/chats/index.d.ts +5 -0
- package/dist/chats/index.js +12 -0
- package/dist/chats/keep.d.ts +10 -0
- package/dist/chats/keep.js +50 -0
- package/dist/chats/read.d.ts +8 -0
- package/dist/chats/read.js +46 -0
- package/dist/cli/cli.js +6 -1
- package/dist/cli/command-line.js +3 -2
- package/dist/commands/book.d.ts +36 -0
- package/dist/commands/book.js +129 -0
- package/dist/commands/chats.d.ts +38 -0
- package/dist/commands/chats.js +93 -0
- package/dist/commands/config/config.js +2 -2
- package/dist/commands/config/dashboard.d.ts +8 -1
- package/dist/commands/config/dashboard.js +70 -16
- package/dist/commands/config/words.d.ts +1 -1
- package/dist/commands/config/words.js +18 -5
- package/dist/commands/find.js +1 -1
- package/dist/commands/image.d.ts +14 -0
- package/dist/commands/image.js +100 -20
- package/dist/commands/index.js +4 -0
- package/dist/commands/init.js +3 -3
- package/dist/commands/package/data.d.ts +35 -0
- package/dist/commands/package/data.js +117 -0
- package/dist/commands/package/here.d.ts +7 -2
- package/dist/commands/package/here.js +23 -11
- package/dist/commands/package/install.js +14 -15
- package/dist/commands/package/language.d.ts +15 -0
- package/dist/commands/package/language.js +109 -0
- package/dist/commands/package/package.js +20 -10
- package/dist/commands/package/result.d.ts +19 -0
- package/dist/commands/package/theme.d.ts +13 -0
- package/dist/commands/package/theme.js +66 -0
- package/dist/commands/package/uninstall.d.ts +4 -1
- package/dist/commands/package/uninstall.js +29 -9
- package/dist/commands/scene/close.d.ts +2 -0
- package/dist/commands/scene/close.js +20 -2
- package/dist/commands/scene/result.d.ts +2 -0
- package/dist/commands/scene/scene.d.ts +2 -0
- package/dist/commands/shared/books/adventures.d.ts +0 -4
- package/dist/commands/shared/books/adventures.js +2 -31
- package/dist/commands/shared/books/words.js +3 -2
- package/dist/commands/shared/campaign/book.d.ts +42 -0
- package/dist/commands/shared/campaign/book.js +118 -0
- package/dist/commands/shared/campaign/chats.d.ts +11 -0
- package/dist/commands/shared/campaign/chats.js +29 -0
- package/dist/commands/shared/campaign/images.js +7 -1
- package/dist/commands/shared/campaign/mode.js +3 -1
- package/dist/commands/shared/campaign/saves.js +13 -5
- package/dist/commands/shared/campaign/world.js +2 -1
- package/dist/commands/shared/packages/catalog.d.ts +3 -3
- package/dist/commands/shared/packages/catalog.js +98 -42
- package/dist/commands/shared/packages/unpacked.d.ts +50 -0
- package/dist/commands/shared/packages/unpacked.js +146 -0
- package/dist/commands/shared/sheet/sheet.d.ts +7 -0
- package/dist/commands/shared/sheet/sheet.js +27 -0
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +4 -0
- package/dist/commands/view/page.js +4 -3
- package/dist/commands/view/result.d.ts +2 -0
- package/dist/commands/view/view.d.ts +1 -0
- package/dist/commands/view/view.js +4 -0
- package/dist/core/archive.d.ts +13 -0
- package/dist/core/archive.js +76 -0
- package/dist/core/consents.d.ts +2 -2
- package/dist/core/consents.js +3 -3
- package/dist/core/context.d.ts +40 -2
- package/dist/core/context.js +1 -0
- package/dist/core/download.js +1 -1
- package/dist/core/store.d.ts +5 -1
- package/dist/core/store.js +15 -2
- package/dist/dashboard/acts/names.js +10 -5
- package/dist/dashboard/acts/sending.js +5 -2
- package/dist/dashboard/acts/sheet.js +66 -15
- package/dist/dashboard/api.js +27 -4
- package/dist/dashboard/app.js +9 -4
- package/dist/dashboard/guide/ar.md +16 -15
- package/dist/dashboard/guide/cs.md +15 -14
- package/dist/dashboard/guide/da.md +17 -16
- package/dist/dashboard/guide/de.md +17 -16
- package/dist/dashboard/guide/el.md +17 -16
- package/dist/dashboard/guide/en.md +14 -13
- package/dist/dashboard/guide/es.md +15 -14
- package/dist/dashboard/guide/fi.md +15 -14
- package/dist/dashboard/guide/fr.md +20 -19
- package/dist/dashboard/guide/he.md +15 -14
- package/dist/dashboard/guide/hi.md +15 -14
- package/dist/dashboard/guide/hu.md +19 -18
- package/dist/dashboard/guide/is.md +15 -14
- package/dist/dashboard/guide/it.md +18 -17
- package/dist/dashboard/guide/ja.md +15 -14
- package/dist/dashboard/guide/ko.md +16 -15
- package/dist/dashboard/guide/nb.md +17 -16
- package/dist/dashboard/guide/nl.md +15 -14
- package/dist/dashboard/guide/pl.md +16 -15
- package/dist/dashboard/guide/pt.md +16 -15
- package/dist/dashboard/guide/ro.md +15 -14
- package/dist/dashboard/guide/ru.md +16 -15
- package/dist/dashboard/guide/sv.md +15 -14
- package/dist/dashboard/guide/tr.md +18 -17
- package/dist/dashboard/guide/uk.md +19 -18
- package/dist/dashboard/guide/zh.md +16 -15
- package/dist/dashboard/i18n/ar.json +63 -9
- package/dist/dashboard/i18n/cs.json +63 -9
- package/dist/dashboard/i18n/da.json +63 -9
- package/dist/dashboard/i18n/de.json +63 -9
- package/dist/dashboard/i18n/el.json +63 -9
- package/dist/dashboard/i18n/es.json +63 -9
- package/dist/dashboard/i18n/fi.json +63 -9
- package/dist/dashboard/i18n/fr.json +63 -9
- package/dist/dashboard/i18n/he.json +63 -9
- package/dist/dashboard/i18n/hi.json +63 -9
- package/dist/dashboard/i18n/hu.json +63 -9
- package/dist/dashboard/i18n/is.json +63 -9
- package/dist/dashboard/i18n/it.json +64 -10
- package/dist/dashboard/i18n/ja.json +63 -9
- package/dist/dashboard/i18n/ko.json +63 -9
- package/dist/dashboard/i18n/nb.json +63 -9
- package/dist/dashboard/i18n/nl.json +63 -9
- package/dist/dashboard/i18n/pl.json +63 -9
- package/dist/dashboard/i18n/pt.json +63 -9
- package/dist/dashboard/i18n/ro.json +63 -9
- package/dist/dashboard/i18n/ru.json +63 -9
- package/dist/dashboard/i18n/sv.json +63 -9
- package/dist/dashboard/i18n/tr.json +63 -9
- package/dist/dashboard/i18n/uk.json +63 -9
- package/dist/dashboard/i18n/zh.json +63 -9
- package/dist/dashboard/journal/book.js +107 -0
- package/dist/dashboard/journal/journal.js +16 -12
- package/dist/dashboard/kit.js +1 -1
- package/dist/dashboard/packages/catalog.js +31 -14
- package/dist/dashboard/packages/engine.js +46 -2
- package/dist/dashboard/packages/installed.js +13 -0
- package/dist/dashboard/packages/outcomes.js +21 -0
- package/dist/dashboard/packages/packages.js +41 -18
- package/dist/dashboard/packages/rows.js +3 -1
- package/dist/dashboard/parts/icons.js +3 -0
- package/dist/dashboard/parts/labels.js +6 -0
- package/dist/dashboard/parts/picture.js +89 -0
- package/dist/dashboard/parts/refusals.js +8 -1
- package/dist/dashboard/parts/widgets.js +3 -2
- package/dist/dashboard/place/view.js +1 -1
- package/dist/dashboard/play/scene.js +8 -5
- package/dist/dashboard/settings/settings.js +32 -16
- package/dist/dashboard/settings/setup.js +5 -3
- package/dist/dashboard/sheet/party.js +5 -2
- package/dist/dashboard/sheet/sheet.js +10 -6
- package/dist/dashboard/shell/notices.js +2 -2
- package/dist/dashboard/shell/system-style.js +45 -12
- package/dist/dashboard/shell/tooltip.js +223 -0
- package/dist/dashboard/style.css +775 -261
- package/dist/dashboard/world/calendar.js +1 -1
- package/dist/dashboard/world/lore.js +5 -4
- package/dist/dashboard/world/place-card.js +2 -1
- package/dist/helpers/briefs.d.ts +5 -0
- package/dist/helpers/briefs.js +8 -0
- package/dist/helpers/chosen.d.ts +8 -2
- package/dist/helpers/chosen.js +110 -6
- package/dist/helpers/codex.js +2 -1
- package/dist/helpers/index.d.ts +2 -2
- package/dist/helpers/index.js +2 -2
- package/dist/images/images.d.ts +2 -0
- package/dist/images/images.js +16 -2
- package/dist/images/index.d.ts +1 -1
- package/dist/images/index.js +1 -1
- package/dist/languages/index.d.ts +1 -1
- package/dist/languages/index.js +1 -1
- package/dist/languages/pack.d.ts +4 -1
- package/dist/languages/pack.js +16 -5
- package/dist/packages/engine.d.ts +7 -0
- package/dist/packages/engine.js +32 -1
- package/dist/packages/index.d.ts +1 -1
- package/dist/packages/index.js +1 -1
- package/dist/server/approver.d.ts +6 -0
- package/dist/server/approver.js +28 -0
- package/dist/server/chats.d.ts +3 -0
- package/dist/server/chats.js +27 -0
- package/dist/server/dashboard/engine.d.ts +18 -0
- package/dist/server/dashboard/engine.js +31 -0
- package/dist/server/dashboard/files.d.ts +8 -1
- package/dist/server/dashboard/files.js +30 -10
- package/dist/server/dashboard/index.d.ts +3 -0
- package/dist/server/dashboard/index.js +10 -1
- package/dist/server/dashboard/news.js +36 -5
- package/dist/server/dashboard/pictures.d.ts +7 -0
- package/dist/server/dashboard/pictures.js +62 -0
- package/dist/server/dashboard/writes.d.ts +5 -3
- package/dist/server/dashboard/writes.js +45 -14
- package/dist/server/mcp.js +37 -6
- package/dist/server/player-acts.d.ts +7 -2
- package/dist/server/player-acts.js +10 -3
- package/dist/testing/index.js +1 -0
- package/dist/themes/index.d.ts +2 -1
- package/dist/themes/index.js +4 -2
- package/dist/themes/installed.d.ts +14 -0
- package/dist/themes/installed.js +28 -0
- package/dist/themes/theme.d.ts +7 -0
- package/dist/themes/theme.js +22 -0
- package/instructions/core.md +3 -3
- package/instructions/dashboard-guide.md +1 -0
- package/instructions/mentor-hints.md +1 -1
- package/instructions/mentor-tutorial.md +1 -1
- package/instructions/party.md +1 -1
- package/instructions/play.md +2 -2
- package/instructions/start.md +1 -1
- package/package.json +2 -2
- package/systems/free/instructions/outcomes-told.md +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Claude Code's chats (T-225): a folder for each folder a chat started in, named after its path, and a .jsonl for each chat, a JSON line for each event.
|
|
2
|
+
import { basename, join, resolve } from "node:path";
|
|
3
|
+
import { joinedMessages } from "./chat.js";
|
|
4
|
+
import { chatFiles, jsonLines } from "./read.js";
|
|
5
|
+
/** The chats Claude Code keeps of the campaign in `root`, in its folder of projects: those started in the campaign's folder, its subagents' left out. */
|
|
6
|
+
export function claudeCodeChats(projects, root) {
|
|
7
|
+
return chatFiles(join(projects, projectName(root)), false).map((path) => {
|
|
8
|
+
const id = basename(path, ".jsonl");
|
|
9
|
+
return { host: "claude-code", id, path, read: () => claudeCodeChat(path, id) };
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/** Claude Code names a project's folder after its path, each character but a letter or a digit made a hyphen. */
|
|
13
|
+
export function projectName(root) {
|
|
14
|
+
return resolve(root).replace(/[^a-zA-Z0-9]/g, "-");
|
|
15
|
+
}
|
|
16
|
+
function claudeCodeChat(path, id) {
|
|
17
|
+
return { host: "claude-code", id, messages: joinedMessages(jsonLines(path).flatMap(message)) };
|
|
18
|
+
}
|
|
19
|
+
/** The player's words or the master's of an event; none for a tool's call or result, the master's reasoning, a subagent's, or what Claude Code adds itself. */
|
|
20
|
+
function message(line) {
|
|
21
|
+
const event = line;
|
|
22
|
+
if ((event.type !== "user" && event.type !== "assistant") || event.isSidechain === true || event.isMeta === true || typeof event.timestamp !== "string") {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
const content = event.message?.content;
|
|
26
|
+
const texts = typeof content === "string"
|
|
27
|
+
? [content]
|
|
28
|
+
: Array.isArray(content)
|
|
29
|
+
? content.flatMap((block) => (block.type === "text" && typeof block.text === "string" ? [block.text] : []))
|
|
30
|
+
: [];
|
|
31
|
+
const who = event.type === "user" ? "player" : "master";
|
|
32
|
+
const at = event.timestamp;
|
|
33
|
+
return texts.map((text) => (who === "player" ? playerText(text) : text.trim())).filter((text) => text !== "").map((text) => ({ who, at, text }));
|
|
34
|
+
}
|
|
35
|
+
/** What the player wrote, without the reminders Claude Code adds to it; none for a command's output or an interruption, which Claude Code writes as the player's. */
|
|
36
|
+
function playerText(text) {
|
|
37
|
+
const own = text.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g, "").trim();
|
|
38
|
+
return own.startsWith("<") || own.startsWith("[Request interrupted") ? "" : own;
|
|
39
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type ChatSource } from "./chat.ts";
|
|
2
|
+
/** The chats Codex keeps of the campaign in `root`, in its folder of sessions: those started in the campaign's folder, its subagents' left out. */
|
|
3
|
+
export declare function codexChats(sessions: string, root: string, platform: string): ChatSource[];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Codex's chats (T-225): a .jsonl for each, in folders by the day it started, its first line saying the folder it started in.
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { joinedMessages } from "./chat.js";
|
|
4
|
+
import { chatFiles, firstJsonLine, jsonLines } from "./read.js";
|
|
5
|
+
/** The chats Codex keeps of the campaign in `root`, in its folder of sessions: those started in the campaign's folder, its subagents' left out. */
|
|
6
|
+
export function codexChats(sessions, root, platform) {
|
|
7
|
+
return chatFiles(sessions, true).flatMap((path) => {
|
|
8
|
+
const id = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.jsonl$/i.exec(path)?.[1];
|
|
9
|
+
return id === undefined ? [] : [{ host: "codex", id, path, read: () => codexChat(path, id, root, platform) }];
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function codexChat(path, id, root, platform) {
|
|
13
|
+
const meta = firstJsonLine(path);
|
|
14
|
+
const cwd = meta?.type === "session_meta" ? meta.payload?.cwd : undefined;
|
|
15
|
+
if (typeof cwd !== "string" || !samePlace(cwd, root, platform) || meta?.payload?.parent_thread_id !== undefined) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return { host: "codex", id, messages: joinedMessages(jsonLines(path).flatMap(message)) };
|
|
19
|
+
}
|
|
20
|
+
/** The player's words or the master's of an item; none for a tool, the master's reasoning, or the instructions Codex sends as the player's. */
|
|
21
|
+
function message(line) {
|
|
22
|
+
const item = line;
|
|
23
|
+
const role = item.payload?.role;
|
|
24
|
+
if (item.type !== "response_item" || item.payload?.type !== "message" || (role !== "user" && role !== "assistant") || typeof item.timestamp !== "string") {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
const kind = role === "user" ? "input_text" : "output_text";
|
|
28
|
+
const content = Array.isArray(item.payload.content) ? item.payload.content : [];
|
|
29
|
+
const at = item.timestamp;
|
|
30
|
+
return content
|
|
31
|
+
.flatMap((block) => (block.type === kind && typeof block.text === "string" ? [block.text.trim()] : []))
|
|
32
|
+
.filter((text) => text !== "" && !(role === "user" && isInstructions(text)))
|
|
33
|
+
.map((text) => ({ who: role === "user" ? "player" : "master", at, text }));
|
|
34
|
+
}
|
|
35
|
+
/** What Codex sends as the player's but is not: the campaign's AGENTS.md, and its tags such as <environment_context>. */
|
|
36
|
+
function isInstructions(text) {
|
|
37
|
+
return text.startsWith("<") || text.startsWith("# AGENTS.md instructions");
|
|
38
|
+
}
|
|
39
|
+
function samePlace(one, other, platform) {
|
|
40
|
+
const key = (path) => (platform === "win32" ? resolve(path).toLowerCase() : resolve(path));
|
|
41
|
+
return key(one) === key(other);
|
|
42
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ChatFolders } from "../core/context.ts";
|
|
2
|
+
export { type Chat, type ChatMessage, chatText, undoneAt, type UndoneStretch } from "./chat.ts";
|
|
3
|
+
export { keepChats, keptChats } from "./keep.ts";
|
|
4
|
+
/** Where Claude Code and Codex keep their chats, in the player's home unless the environment moves them. */
|
|
5
|
+
export declare function chatFolders(environment: Record<string, string | undefined>, home: string): ChatFolders;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The chats of the game as the AI hosts keep them on this computer, copied into the campaign as text (T-225): the player's words and the master's, never the
|
|
2
|
+
// master's reasoning nor its tools, which the log and the host's own chat keep.
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
export { chatText, undoneAt } from "./chat.js";
|
|
5
|
+
export { keepChats, keptChats } from "./keep.js";
|
|
6
|
+
/** Where Claude Code and Codex keep their chats, in the player's home unless the environment moves them. */
|
|
7
|
+
export function chatFolders(environment, home) {
|
|
8
|
+
return {
|
|
9
|
+
claudeCode: join(environment.CLAUDE_CONFIG_DIR || join(home, ".claude"), "projects"),
|
|
10
|
+
codex: join(environment.CODEX_HOME || join(home, ".codex"), "sessions"),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ChatFolders } from "../core/context.ts";
|
|
2
|
+
import { type Chat, type UndoneStretch } from "./chat.ts";
|
|
3
|
+
/**
|
|
4
|
+
* 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
|
|
5
|
+
* 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
|
|
6
|
+
* began, its host and its id. How many it wrote.
|
|
7
|
+
*/
|
|
8
|
+
export declare function keepChats(root: string, target: string, folders: ChatFolders, platform: string, undone: UndoneStretch[]): number;
|
|
9
|
+
/** 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. */
|
|
10
|
+
export declare function keptChats(target: string): Chat[];
|
|
@@ -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);
|
|
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) {
|
package/dist/cli/command-line.js
CHANGED
|
@@ -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
|
|
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,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type StoryScene } 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
|
+
through: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
8
|
+
}, z.core.$strip>, {
|
|
9
|
+
kind: "written";
|
|
10
|
+
number: number;
|
|
11
|
+
title: string;
|
|
12
|
+
scenes: StoryScene[];
|
|
13
|
+
words: number;
|
|
14
|
+
untold: number;
|
|
15
|
+
} | {
|
|
16
|
+
kind: "list";
|
|
17
|
+
written: number;
|
|
18
|
+
untold: StoryScene[];
|
|
19
|
+
craft: string | undefined;
|
|
20
|
+
chapter?: undefined;
|
|
21
|
+
number?: undefined;
|
|
22
|
+
} | {
|
|
23
|
+
kind: "read";
|
|
24
|
+
chapter: import("./shared/campaign/book.ts").WrittenChapter;
|
|
25
|
+
craft: string | undefined;
|
|
26
|
+
written?: undefined;
|
|
27
|
+
untold?: undefined;
|
|
28
|
+
number?: undefined;
|
|
29
|
+
} | {
|
|
30
|
+
kind: "removed";
|
|
31
|
+
number: number;
|
|
32
|
+
written?: undefined;
|
|
33
|
+
untold?: undefined;
|
|
34
|
+
craft?: undefined;
|
|
35
|
+
chapter?: undefined;
|
|
36
|
+
}>;
|
|
@@ -0,0 +1,129 @@
|
|
|
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, scenesText, storyScenes, untoldScenes, 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 scenes still untold a list shows, the first; the others are counted.
|
|
9
|
+
const listedScenes = 20;
|
|
10
|
+
// The longest chapter the book takes, in characters.
|
|
11
|
+
const chapterLength = 80_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: chapters of a novel, never summaries, each telling the scenes closed since the last one, "
|
|
15
|
+
+ "ended where the story turns. With nothing, it lists the closed scenes no chapter tells yet, which is how a campaign begun without the book gets the story so far; "
|
|
16
|
+
+ "text writes the next chapter, of those scenes or of those through one; with chapter alone, it reads one back, so that the voice holds from one to the next, and with text it writes it again; "
|
|
17
|
+
+ "empty text takes the last out. The first call in a chat says how to write them.",
|
|
18
|
+
group: "game",
|
|
19
|
+
positionals: ["chapter"],
|
|
20
|
+
input: z.object({
|
|
21
|
+
chapter: z.coerce.number().int().positive().optional().describe("the number of a chapter written, to read, write again or retitle; the next chapter if left out"),
|
|
22
|
+
title: z.string().optional().describe("the chapter's title, its first scene's if left out"),
|
|
23
|
+
text: z.string().optional().describe("the chapter's prose, in markdown; empty to take the last chapter out"),
|
|
24
|
+
through: z.coerce.number().int().positive().optional().describe("for the next chapter, the number of its last scene, when it tells only the first of the scenes still untold"),
|
|
25
|
+
}),
|
|
26
|
+
run(input, context) {
|
|
27
|
+
const root = requireCampaign(context.folder);
|
|
28
|
+
const written = campaignBook(root);
|
|
29
|
+
const untold = untoldScenes(root, written);
|
|
30
|
+
const craft = firstInChat(context, "book") ? chapterCraft : undefined;
|
|
31
|
+
const next = written.length + 1;
|
|
32
|
+
if (input.through !== undefined && input.chapter !== undefined && input.chapter !== next) {
|
|
33
|
+
throw new Error(`through is for the next chapter, ${next}: chapter ${input.chapter} keeps its scenes. Nothing written.`);
|
|
34
|
+
}
|
|
35
|
+
if (input.chapter === undefined && input.title === undefined && input.text === undefined) {
|
|
36
|
+
return { kind: "list", written: written.length, untold, craft };
|
|
37
|
+
}
|
|
38
|
+
if (input.chapter === undefined || input.chapter === next) {
|
|
39
|
+
return writeNext(root, context, next, chapterScenes(untold, input.through), input.title, input.text);
|
|
40
|
+
}
|
|
41
|
+
const before = written.find((chapter) => chapter.number === input.chapter);
|
|
42
|
+
if (before === undefined) {
|
|
43
|
+
throw new Error(`There is no chapter ${input.chapter}: the book has ${written.length}, and the next is ${next}. Nothing written.`);
|
|
44
|
+
}
|
|
45
|
+
if (input.text === undefined && input.title === undefined) {
|
|
46
|
+
return { kind: "read", chapter: before, craft };
|
|
47
|
+
}
|
|
48
|
+
if (input.text !== undefined && input.text.trim() === "") {
|
|
49
|
+
if (before.number !== written.length) {
|
|
50
|
+
throw new Error(`Chapter ${before.number} has chapters after it: write it again, or take out the last first. Nothing written.`);
|
|
51
|
+
}
|
|
52
|
+
removeChapter(root, before.number);
|
|
53
|
+
appendLogEntry(root, newDatedLogEntry(root, context, "book-chapter", "hidden", { chapter: before.number, removed: true }));
|
|
54
|
+
return { kind: "removed", number: before.number };
|
|
55
|
+
}
|
|
56
|
+
const scenes = storyScenes(root).slice(before.first - 1, before.last);
|
|
57
|
+
const text = proseOf(input.text ?? before.text);
|
|
58
|
+
const title = input.title?.trim() || before.title;
|
|
59
|
+
writeChapter(root, before.number, scenes, title, text);
|
|
60
|
+
return logged(root, context, { number: before.number, title, text, scenes, untold: untold.length });
|
|
61
|
+
},
|
|
62
|
+
format(result) {
|
|
63
|
+
const craft = "craft" in result && result.craft !== undefined ? `\n\n${result.craft}` : "";
|
|
64
|
+
if (result.kind === "list") {
|
|
65
|
+
if (result.untold.length === 0) {
|
|
66
|
+
return `${result.written === 0 ? "The book has no chapter yet" : `The book has ${result.written} ${result.written === 1 ? "chapter" : "chapters"}`}, and no closed scene waits for one: `
|
|
67
|
+
+ `the next chapter comes when the story turns, at a scene's end.${craft}`;
|
|
68
|
+
}
|
|
69
|
+
const lines = result.untold.slice(0, listedScenes).map(sceneLine);
|
|
70
|
+
const more = result.untold.length > listedScenes ? `\nAnd ${result.untold.length - listedScenes} more after them.` : "";
|
|
71
|
+
return `The book has ${result.written} ${result.written === 1 ? "chapter" : "chapters"}; ${scenesText(result.untold)} ${result.untold.length === 1 ? "waits" : "wait"} for the next. `
|
|
72
|
+
+ `Tell them in chapters, each ending where the story turns (through gives a chapter's last scene), 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 `Chapter ${result.chapter.number} «${result.chapter.title}», ${scenesText([{ number: result.chapter.first }, { number: result.chapter.last }])}:\n\n${result.chapter.text}${craft}`;
|
|
76
|
+
}
|
|
77
|
+
if (result.kind === "removed") {
|
|
78
|
+
return `Chapter ${result.number} taken out of the book: its scenes wait for a chapter again.`;
|
|
79
|
+
}
|
|
80
|
+
const left = result.untold === 0 ? "" : ` Still untold: ${result.untold} closed ${result.untold === 1 ? "scene" : "scenes"}, for the next chapter.`;
|
|
81
|
+
return `Chapter ${result.number} «${result.title}», ${scenesText(result.scenes)}, written, ${result.words} words: the player reads it in the Journal, under Story.${left}${craft}`;
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
/** The next chapter, telling these scenes. */
|
|
85
|
+
function writeNext(root, context, number, scenes, title, text) {
|
|
86
|
+
if (text === undefined || text.trim() === "") {
|
|
87
|
+
throw new Error(`Chapter ${number} is not written yet: give its text, the prose of ${scenesText(scenes)}. Nothing written.`);
|
|
88
|
+
}
|
|
89
|
+
const prose = proseOf(text);
|
|
90
|
+
const named = title?.trim() || scenes[0].title;
|
|
91
|
+
writeChapter(root, number, scenes, named, prose);
|
|
92
|
+
return logged(root, context, { number, title: named, text: prose, scenes, untold: untoldScenes(root).length });
|
|
93
|
+
}
|
|
94
|
+
/** The scenes the next chapter tells: the untold ones, or those through one; stops the command when there are none. */
|
|
95
|
+
function chapterScenes(untold, through) {
|
|
96
|
+
if (untold.length === 0) {
|
|
97
|
+
throw new Error("No closed scene waits for a chapter: the next comes when the story turns, at a scene's end. Nothing written.");
|
|
98
|
+
}
|
|
99
|
+
if (through === undefined) {
|
|
100
|
+
return untold;
|
|
101
|
+
}
|
|
102
|
+
const last = untold.findIndex((scene) => scene.number === through);
|
|
103
|
+
if (last === -1) {
|
|
104
|
+
throw new Error(`Scene ${through} is not one still untold: give through between ${untold[0].number} and ${untold.at(-1)?.number}. Nothing written.`);
|
|
105
|
+
}
|
|
106
|
+
return untold.slice(0, last + 1);
|
|
107
|
+
}
|
|
108
|
+
/** A chapter's prose as the book keeps it; stops the command when it is too long. */
|
|
109
|
+
function proseOf(text) {
|
|
110
|
+
const prose = text.replace(/\r\n?/g, "\n").trim().normalize("NFC");
|
|
111
|
+
if (prose.length > chapterLength) {
|
|
112
|
+
throw new Error(`This chapter is ${prose.length} characters, the book takes ${chapterLength}: end it sooner, with through. Nothing written.`);
|
|
113
|
+
}
|
|
114
|
+
return prose;
|
|
115
|
+
}
|
|
116
|
+
/** A chapter written, in the log, with its length. */
|
|
117
|
+
function logged(root, context, chapter) {
|
|
118
|
+
const words = chapter.text.split(/\s+/).filter((word) => word !== "").length;
|
|
119
|
+
appendLogEntry(root, newDatedLogEntry(root, context, "book-chapter", "hidden", { chapter: chapter.number, title: chapter.title, scenes: chapter.scenes.map((scene) => scene.number), words }));
|
|
120
|
+
return { kind: "written", number: chapter.number, title: chapter.title, scenes: chapter.scenes, words, untold: chapter.untold };
|
|
121
|
+
}
|
|
122
|
+
/** A scene still untold: its title and game date, its summary, and when it ran in real time, for chats to read it. */
|
|
123
|
+
function sceneLine(scene) {
|
|
124
|
+
const date = scene.date === undefined ? "" : `, ${scene.date}`;
|
|
125
|
+
const summary = scene.summary === undefined ? "" : `: ${scene.summary}`;
|
|
126
|
+
const otherDay = scene.to !== undefined && scene.to.slice(0, 10) !== scene.from.slice(0, 10) ? ` of ${scene.to.slice(0, 10)}` : "";
|
|
127
|
+
const until = scene.to === undefined ? "" : `, until ${scene.to.slice(11, 19)}${otherDay}`;
|
|
128
|
+
return `${scene.number} «${scene.title}»${date}${summary} (chats: day ${scene.from.slice(0, 10)}, from ${scene.from.slice(11, 19)}${until})`;
|
|
129
|
+
}
|
|
@@ -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) {
|
|
@@ -246,7 +246,7 @@ function configure(input, context) {
|
|
|
246
246
|
part,
|
|
247
247
|
};
|
|
248
248
|
}
|
|
249
|
-
const ordersKept = "Kept until the player lifts it; the lines and veils still come first. An order for this scene only stays in the scene; when unsure, ask in one
|
|
249
|
+
const ordersKept = "Kept until the player lifts it; the lines and veils still come first. An order for this scene only stays in the scene; when unsure, ask in one [OOC: …].";
|
|
250
250
|
// The settings of free words the player may leave unset again, with the value none, and all those of how the master writes (D-395).
|
|
251
251
|
const freeSettingNames = ["author", "style", "calendar"];
|
|
252
252
|
/** A setting the game system adds, shown, or changed to one of its values (DAT-10); refused with them for any other. */
|
|
@@ -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
|
-
/**
|
|
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 the lines 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;
|