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.
- package/README.md +9 -6
- package/dist/campaign/create-campaign.js +2 -2
- package/dist/campaign/find-campaign.d.ts +4 -0
- package/dist/campaign/find-campaign.js +5 -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 +30 -6
- 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 +55 -0
- package/dist/commands/book.js +105 -0
- package/dist/commands/chats.d.ts +38 -0
- package/dist/commands/chats.js +93 -0
- package/dist/commands/config/config.js +1 -1
- package/dist/commands/config/dashboard.d.ts +8 -1
- package/dist/commands/config/dashboard.js +63 -15
- package/dist/commands/config/words.d.ts +1 -1
- package/dist/commands/config/words.js +17 -4
- package/dist/commands/find.js +1 -1
- package/dist/commands/image.d.ts +9 -0
- package/dist/commands/image.js +95 -18
- package/dist/commands/index.js +4 -0
- package/dist/commands/init.js +3 -3
- package/dist/commands/scene/close.d.ts +2 -0
- package/dist/commands/scene/close.js +13 -2
- package/dist/commands/scene/result.d.ts +2 -0
- package/dist/commands/scene/scene.d.ts +2 -0
- package/dist/commands/shared/campaign/book.d.ts +29 -0
- package/dist/commands/shared/campaign/book.js +95 -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/sheet/sheet.d.ts +7 -0
- package/dist/commands/shared/sheet/sheet.js +27 -0
- package/dist/commands/shared/time/dawn.d.ts +1 -1
- package/dist/commands/shared/time/dawn.js +19 -7
- 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/consents.d.ts +2 -2
- package/dist/core/consents.js +3 -3
- package/dist/core/context.d.ts +38 -2
- package/dist/core/download.js +1 -1
- 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 +3 -3
- package/dist/dashboard/app.js +2 -2
- package/dist/dashboard/guide/ar.md +11 -10
- package/dist/dashboard/guide/cs.md +10 -9
- package/dist/dashboard/guide/da.md +12 -11
- package/dist/dashboard/guide/de.md +12 -11
- package/dist/dashboard/guide/el.md +12 -11
- package/dist/dashboard/guide/en.md +9 -8
- package/dist/dashboard/guide/es.md +10 -9
- package/dist/dashboard/guide/fi.md +10 -9
- package/dist/dashboard/guide/fr.md +16 -15
- package/dist/dashboard/guide/he.md +11 -10
- package/dist/dashboard/guide/hi.md +10 -9
- package/dist/dashboard/guide/hu.md +14 -13
- package/dist/dashboard/guide/is.md +10 -9
- package/dist/dashboard/guide/it.md +13 -12
- package/dist/dashboard/guide/ja.md +10 -9
- package/dist/dashboard/guide/ko.md +11 -10
- package/dist/dashboard/guide/nb.md +12 -11
- package/dist/dashboard/guide/nl.md +10 -9
- package/dist/dashboard/guide/pl.md +11 -10
- package/dist/dashboard/guide/pt.md +12 -11
- package/dist/dashboard/guide/ro.md +10 -9
- package/dist/dashboard/guide/ru.md +12 -11
- package/dist/dashboard/guide/sv.md +10 -9
- package/dist/dashboard/guide/tr.md +13 -12
- package/dist/dashboard/guide/uk.md +13 -12
- package/dist/dashboard/guide/zh.md +11 -10
- package/dist/dashboard/i18n/ar.json +31 -5
- package/dist/dashboard/i18n/cs.json +31 -5
- package/dist/dashboard/i18n/da.json +31 -5
- package/dist/dashboard/i18n/de.json +31 -5
- package/dist/dashboard/i18n/el.json +31 -5
- package/dist/dashboard/i18n/es.json +31 -5
- package/dist/dashboard/i18n/fi.json +31 -5
- package/dist/dashboard/i18n/fr.json +31 -5
- package/dist/dashboard/i18n/he.json +31 -5
- package/dist/dashboard/i18n/hi.json +31 -5
- package/dist/dashboard/i18n/hu.json +31 -5
- package/dist/dashboard/i18n/is.json +31 -5
- package/dist/dashboard/i18n/it.json +32 -6
- package/dist/dashboard/i18n/ja.json +31 -5
- package/dist/dashboard/i18n/ko.json +31 -5
- package/dist/dashboard/i18n/nb.json +31 -5
- package/dist/dashboard/i18n/nl.json +31 -5
- package/dist/dashboard/i18n/pl.json +31 -5
- package/dist/dashboard/i18n/pt.json +31 -5
- package/dist/dashboard/i18n/ro.json +31 -5
- package/dist/dashboard/i18n/ru.json +31 -5
- package/dist/dashboard/i18n/sv.json +31 -5
- package/dist/dashboard/i18n/tr.json +31 -5
- package/dist/dashboard/i18n/uk.json +31 -5
- package/dist/dashboard/i18n/zh.json +31 -5
- package/dist/dashboard/journal/book.js +106 -0
- package/dist/dashboard/journal/journal.js +9 -8
- package/dist/dashboard/parts/labels.js +6 -0
- package/dist/dashboard/parts/widgets.js +1 -1
- package/dist/dashboard/place/view.js +1 -1
- package/dist/dashboard/settings/settings.js +10 -4
- package/dist/dashboard/settings/setup.js +5 -3
- package/dist/dashboard/sheet/sheet.js +8 -5
- package/dist/dashboard/style.css +459 -96
- package/dist/dashboard/world/calendar.js +1 -1
- package/dist/dashboard/world/lore.js +1 -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/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/news.js +36 -5
- 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/instructions/start.md +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,7 +24,8 @@ An AI is a wonderful storyteller, but a storyteller tends to make the world fit
|
|
|
24
24
|
- **Follow quests** with goals and deadlines, and a **journal** that tells your story in chapters.
|
|
25
25
|
- **Save**, as in a video game: at the end of every scene, to go back or start over as you choose.
|
|
26
26
|
- **Choose how you play**: difficulty, lethality, how much the master teaches the rules, its style, your lines and veils.
|
|
27
|
-
- **Play in your language**: the dashboard speaks 26, and any other is translated for you.
|
|
27
|
+
- **Play in your language**: the dashboard speaks 26, and any other is translated for you.
|
|
28
|
+
- **See where you are**: pictures of the places you reach, the quests you take and the people you meet. Painted ones, as the inn above, come from **Codex** signed in with your ChatGPT account, even when your master is Claude Code; Antigravity paints its own. Install Codex with `npm install -g @openai/codex` and sign in once with `codex login`. With Claude Code alone, the master draws simpler ones.
|
|
28
29
|
|
|
29
30
|
## The game
|
|
30
31
|
|
|
@@ -42,11 +43,11 @@ A game comes as a game system, a package the master installs when you set up a c
|
|
|
42
43
|
|
|
43
44
|
## What you need
|
|
44
45
|
|
|
45
|
-
**Node.js 24** or newer, a web browser, and an AI agent to be the master: an AI app that can work with the files on your computer, such as Claude Code or
|
|
46
|
+
**Node.js 24** or newer, a web browser, and an AI agent to be the master: an AI app that can work with the files on your computer, such as Claude Code, Codex or Antigravity. A plain chat such as claude.ai or ChatGPT, or a phone app, is not enough: the master needs to reach the campaign's files on your computer.
|
|
46
47
|
|
|
47
|
-
RPG Engine is tied to no AI company: any agent that supports MCP tools can be the master, local ones included. We play and test it with **Claude Code**; **Codex**
|
|
48
|
+
RPG Engine is tied to no AI company: any agent that supports MCP tools can be the master, local ones included. We play and test it with **Claude Code**; **Codex** and **Antigravity** are connected and checked, but no whole campaign has been played with them yet; [the guide](https://github.com/stefanocaronia/rpg-engine/blob/main/src/dashboard/guide/en.md#24-connect-your-ai) says how to connect any other agent. Give the master the largest model you have: a small one is easier to talk into revealing secrets or bending the rules.
|
|
48
49
|
|
|
49
|
-
RPG Engine is free: the master runs on your agent's own plan (for Claude Code, a paid Claude plan; for Codex, a ChatGPT account), or on your computer with a local model. RPG Engine itself never uses an API key, which is paid by the call: sign your agent in with your account, not with a key. You do not need to know how to program, and once your agent is installed, you are playing in a few minutes.
|
|
50
|
+
RPG Engine is free: the master runs on your agent's own plan (for Claude Code, a paid Claude plan; for Codex, a ChatGPT account; for Antigravity, a Google account), or on your computer with a local model. RPG Engine itself never uses an API key, which is paid by the call: sign your agent in with your account, not with a key. You do not need to know how to program, and once your agent is installed, you are playing in a few minutes.
|
|
50
51
|
|
|
51
52
|
## Quick start
|
|
52
53
|
|
|
@@ -61,7 +62,7 @@ claude
|
|
|
61
62
|
|
|
62
63
|
If Windows answers that running scripts is disabled, write once `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`, answer yes and try again.
|
|
63
64
|
|
|
64
|
-
With Codex write `codex`; with another agent, start it in that folder (the guide says how to connect it). When it asks whether you trust the folder, say yes; careful, in Claude Code the answer already selected is *No, exit*.
|
|
65
|
+
With Codex write `codex`, with Antigravity `agy`; with another agent, start it in that folder (the guide says how to connect it). When it asks whether you trust the folder, say yes; careful, in Claude Code the answer already selected is *No, exit*.
|
|
65
66
|
|
|
66
67
|
Then write *Hi! Let's start.* The master answers with the link to your dashboard: open it beside the chat. It asks how you want to play, a few questions at a time, then you make your character together, and the story begins.
|
|
67
68
|
|
|
@@ -69,7 +70,9 @@ Then write *Hi! Let's start.* The master answers with the link to your dashboard
|
|
|
69
70
|
|
|
70
71
|
## Try it, and tell us
|
|
71
72
|
|
|
72
|
-
RPG Engine is at its first versions, and it grows with the games played on it. Try it, and when something breaks
|
|
73
|
+
RPG Engine is at its first versions, and it grows with the games played on it. Try it, and when something breaks or confuses you, open an [issue on GitHub](https://github.com/stefanocaronia/rpg-engine/issues): what you did, what you expected, what happened. Every report helps. Questions, ideas and the stories of your games go to the [Discussions](https://github.com/stefanocaronia/rpg-engine/discussions).
|
|
74
|
+
|
|
75
|
+
RPG Engine takes no pull requests: we write its code with our AI, from your reports. To add something to the game, make a package of your own, a [game system](https://github.com/stefanocaronia/rpg-engine/blob/main/docs/game-systems.md) or an [extension](https://github.com/stefanocaronia/rpg-engine/blob/main/docs/extensions.md), in a repository of yours.
|
|
73
76
|
|
|
74
77
|
## How it works
|
|
75
78
|
|
|
@@ -3,7 +3,7 @@ import { join, resolve } from "node:path";
|
|
|
3
3
|
import { stringify } from "yaml";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { files } from "../core/store.js";
|
|
6
|
-
import { campaignFileName, findCampaign } from "./find-campaign.js";
|
|
6
|
+
import { campaignFileName, findCampaign, sessionsFolderName } from "./find-campaign.js";
|
|
7
7
|
import { hostFileChanges, rpgServer, writeHostFile } from "./host-files.js";
|
|
8
8
|
import { settingsSchema } from "./settings.js";
|
|
9
9
|
/**
|
|
@@ -19,7 +19,7 @@ export function createCampaign(folder, settings, platform, instructions) {
|
|
|
19
19
|
}
|
|
20
20
|
const mcpConfig = mcpConfigWithRpg(root, platform);
|
|
21
21
|
const hostFiles = hostFileChanges(root, instructions, platform);
|
|
22
|
-
files().makeFolder(join(root,
|
|
22
|
+
files().makeFolder(join(root, sessionsFolderName));
|
|
23
23
|
files().write(join(root, campaignFileName), `# Campaign settings: change them with the config command.\n${stringify(parsed.data)}`);
|
|
24
24
|
// A new campaign starts in setup (MOD-1).
|
|
25
25
|
files().write(join(root, "state.yaml"), "# The present of the game, kept by rpg: mode, date and current scene.\nmode: setup\n");
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
export declare const campaignFileName = "campaign.yaml";
|
|
3
3
|
/** The folder of a campaign with its house rules, a markdown file for each (D-178). */
|
|
4
4
|
export declare const houseRulesFolderName = "rules";
|
|
5
|
+
/** The folder of a campaign with its chats as text, copied from the AI hosts as they go on, kept out of the saves (T-225). */
|
|
6
|
+
export declare const sessionsFolderName = "sessions";
|
|
7
|
+
/** The folder of a campaign with its story told as a book, a chapter for each closed scene, kept out of the saves (T-227). */
|
|
8
|
+
export declare const bookFolderName = "book";
|
|
5
9
|
/** The campaign that holds `folder`: the nearest folder, from `folder` upwards, with a campaign.yaml. */
|
|
6
10
|
export declare function findCampaign(folder: string): string | undefined;
|
|
7
11
|
/** Like findCampaign, but fails with a message that says how to get into a campaign. */
|
|
@@ -4,6 +4,10 @@ import { files, isInside } from "../core/store.js";
|
|
|
4
4
|
export const campaignFileName = "campaign.yaml";
|
|
5
5
|
/** The folder of a campaign with its house rules, a markdown file for each (D-178). */
|
|
6
6
|
export const houseRulesFolderName = "rules";
|
|
7
|
+
/** The folder of a campaign with its chats as text, copied from the AI hosts as they go on, kept out of the saves (T-225). */
|
|
8
|
+
export const sessionsFolderName = "sessions";
|
|
9
|
+
/** The folder of a campaign with its story told as a book, a chapter for each closed scene, kept out of the saves (T-227). */
|
|
10
|
+
export const bookFolderName = "book";
|
|
7
11
|
/** The campaign that holds `folder`: the nearest folder, from `folder` upwards, with a campaign.yaml. */
|
|
8
12
|
export function findCampaign(folder) {
|
|
9
13
|
let current = resolve(folder);
|
|
@@ -31,7 +35,7 @@ export function requireCampaign(folder) {
|
|
|
31
35
|
const layersFolder = "layers";
|
|
32
36
|
// The folders the engine writes in: a link among them, a junction that came with a folder someone else made, would carry its writes outside the campaign. A file
|
|
33
37
|
// that is a link the store refuses as it writes it.
|
|
34
|
-
const writtenFolders = ["world", "images", "rules",
|
|
38
|
+
const writtenFolders = ["world", "images", "rules", sessionsFolderName, bookFolderName, ".saves", "exports", ".player", ".imports", ".claude", ".codex", layersFolder];
|
|
35
39
|
/** Throws when a folder the engine writes in, or one in it two levels deep, three for the layers, is a link: a symbolic link or a junction. */
|
|
36
40
|
function refuseLinksOut(root) {
|
|
37
41
|
const store = files();
|
|
@@ -76,8 +76,30 @@ function hostFiles(root, instructions, platform) {
|
|
|
76
76
|
() => claudeSettingsFile(root),
|
|
77
77
|
() => characterAgentFile(root, instructions.character),
|
|
78
78
|
() => codexConfigFile(root, platform),
|
|
79
|
+
() => antigravityServerFile(root, platform),
|
|
80
|
+
() => antigravityHooksFile(root),
|
|
79
81
|
];
|
|
80
82
|
}
|
|
83
|
+
/** Antigravity's servers for the campaign, in the format of .mcp.json: the rpg server added when missing; the player's own servers, and their rpg, stay. */
|
|
84
|
+
function antigravityServerFile(root, platform) {
|
|
85
|
+
const path = join(root, ".agents", "mcp_config.json");
|
|
86
|
+
const text = files().fresh(path);
|
|
87
|
+
const config = text === undefined ? {} : jsonObject(path, text, "Antigravity cannot be set up for the game in it");
|
|
88
|
+
const servers = isObject(config.mcpServers) ? config.mcpServers : {};
|
|
89
|
+
return servers.rpg !== undefined ? undefined : { path, text: settingsText({ ...config, mcpServers: { ...servers, rpg: rpgServer(platform) } }) };
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Antigravity's hooks for the campaign: before each tool, rpg --approve lets the rpg server's tools run without asking, as Claude Code's and Codex's settings
|
|
93
|
+
* do (D-412), and asks for every other; the player's own hooks stay beside it.
|
|
94
|
+
*/
|
|
95
|
+
function antigravityHooksFile(root) {
|
|
96
|
+
const path = join(root, ".agents", "hooks.json");
|
|
97
|
+
const text = files().fresh(path);
|
|
98
|
+
const hooks = text === undefined ? {} : jsonObject(path, text, "Antigravity cannot be set up for the game in it");
|
|
99
|
+
return hooks.rpg !== undefined ? undefined : { path, text: settingsText({ ...hooks, rpg: { PreToolUse: [{ matcher: ".*", hooks: [approveHook] }] } }) };
|
|
100
|
+
}
|
|
101
|
+
// Antigravity's hook that approves the rpg server's tools: it answers in about a second, as the hooks of a chat must.
|
|
102
|
+
const approveHook = { type: "command", command: "rpg --approve", timeout: 10 };
|
|
81
103
|
/** The master's effort the player chose (D-462), for each host's file; undefined when unset, and what the files hold stays. */
|
|
82
104
|
function chosenEffort(root) {
|
|
83
105
|
const effort = readTextSetting(root, "effort");
|
package/dist/campaign/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { type ChoiceItem, type ChoiceSet, type PickRange, pickText, readChoices, readPick, writeChoices } from "./choices.ts";
|
|
2
2
|
export { createCampaign } from "./create-campaign.ts";
|
|
3
|
-
export { campaignFileName, findCampaign, houseRulesFolderName, requireCampaign } from "./find-campaign.ts";
|
|
3
|
+
export { bookFolderName, campaignFileName, findCampaign, houseRulesFolderName, requireCampaign, sessionsFolderName } from "./find-campaign.ts";
|
|
4
4
|
export { hasCharacterAgent, hostFileNames, refreshHostFiles, writeEffortFiles } from "./host-files.ts";
|
|
5
5
|
export { lastChoices, rememberChoice, rememberedSettings } from "./last-choices.ts";
|
|
6
6
|
export { type CountedByGame, customLevel, customLevels, customSettings, difficulties, difficultyItems, itemMeaning, leveled, type LeveledSetting, rigorItems, rigors, startingLevels } from "./levels.ts";
|
|
7
|
-
export { type CampaignSettings, changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, characterWays, checkSettingName, checkSettings, clearSetting, closedSettings, companionWays, diceWays, efforts, entrySettingNames, lengths, lethalities, listLimits, listSettingNames, mapSettingNames, masterRollWays, mentorWays, missingSettings, pictureWays, preparations, proseWays, readCampaignData, readListSetting, readOneSetting, readSettings, readTextSetting, saveModes, settingDescription, settingMeaning, type SettingName, settingNames, setupSettingNames, storyWays, styleTextLengths, unansweredSettings, unitSystems, voiceWays, } from "./settings.ts";
|
|
7
|
+
export { type CampaignSettings, changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, characterWays, checkSettingName, checkSettings, chosenPictureMaker, clearSetting, closedSettings, companionWays, diceWays, efforts, entrySettingNames, lengths, lethalities, listLimits, listSettingNames, mapSettingNames, masterRollWays, mentorWays, missingSettings, pictureMakers, pictureWays, preparations, proseWays, readCampaignData, readListSetting, readOneSetting, readSettings, readTextSetting, saveModes, settingDescription, settingMeaning, type SettingName, settingNames, setupSettingNames, storyWays, styleTextLengths, unansweredSettings, unitSystems, voiceWays, } from "./settings.ts";
|
|
8
8
|
export { type CampaignState, changeState, changeStateAt, readState, readStateValues } from "./state.ts";
|
package/dist/campaign/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// The campaign: a folder with campaign.yaml, its settings, the present, the sessions and the files an AI host reads.
|
|
2
2
|
export { pickText, readChoices, readPick, writeChoices } from "./choices.js";
|
|
3
3
|
export { createCampaign } from "./create-campaign.js";
|
|
4
|
-
export { campaignFileName, findCampaign, houseRulesFolderName, requireCampaign } from "./find-campaign.js";
|
|
4
|
+
export { bookFolderName, campaignFileName, findCampaign, houseRulesFolderName, requireCampaign, sessionsFolderName } from "./find-campaign.js";
|
|
5
5
|
export { hasCharacterAgent, hostFileNames, refreshHostFiles, writeEffortFiles } from "./host-files.js";
|
|
6
6
|
export { lastChoices, rememberChoice, rememberedSettings } from "./last-choices.js";
|
|
7
7
|
export { customLevel, customLevels, customSettings, difficulties, difficultyItems, itemMeaning, leveled, rigorItems, rigors, startingLevels } from "./levels.js";
|
|
8
|
-
export { changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, characterWays, checkSettingName, checkSettings, clearSetting, closedSettings, companionWays, diceWays, efforts, entrySettingNames, lengths, lethalities, listLimits, listSettingNames, mapSettingNames, masterRollWays, mentorWays, missingSettings, pictureWays, preparations, proseWays, readCampaignData, readListSetting, readOneSetting, readSettings, readTextSetting, saveModes, settingDescription, settingMeaning, settingNames, setupSettingNames, storyWays, styleTextLengths, unansweredSettings, unitSystems, voiceWays, } from "./settings.js";
|
|
8
|
+
export { changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, characterWays, checkSettingName, checkSettings, chosenPictureMaker, clearSetting, closedSettings, companionWays, diceWays, efforts, entrySettingNames, lengths, lethalities, listLimits, listSettingNames, mapSettingNames, masterRollWays, mentorWays, missingSettings, pictureMakers, pictureWays, preparations, proseWays, readCampaignData, readListSetting, readOneSetting, readSettings, readTextSetting, saveModes, settingDescription, settingMeaning, settingNames, setupSettingNames, storyWays, styleTextLengths, unansweredSettings, unitSystems, voiceWays, } from "./settings.js";
|
|
9
9
|
export { changeState, changeStateAt, readState, readStateValues } from "./state.js";
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/** The settings whose last choice a new campaign's setup suggests: how the player likes to play, never what belongs to one game, as how well they know it. */
|
|
2
2
|
export declare const rememberedSettings: readonly string[];
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The last choice of each remembered setting, from the player's folder on this computer; for `campaign`, only those of the campaigns before it, never its own
|
|
5
|
+
* (T-212). None when there is no folder or the file does not read.
|
|
6
|
+
*/
|
|
7
|
+
export declare function lastChoices(home: string | undefined, campaign?: string): Record<string, string>;
|
|
8
|
+
/**
|
|
9
|
+
* Remembers a choice of a remembered setting in the player's folder, as the campaign `campaign` made it; a choice of another setting, or a folder that cannot
|
|
10
|
+
* be written, changes nothing.
|
|
11
|
+
*/
|
|
12
|
+
export declare function rememberChoice(home: string | undefined, campaign: string, name: string, value: unknown): void;
|
|
@@ -1,34 +1,60 @@
|
|
|
1
1
|
// The player's last choices of the setup's settings on this computer (D-37, T-134): what the setup of a new campaign suggests, never chooses.
|
|
2
2
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
4
|
/** The settings whose last choice a new campaign's setup suggests: how the player likes to play, never what belongs to one game, as how well they know it. */
|
|
5
5
|
export const rememberedSettings = ["difficulty", "lethality", "saves", "rigor", "dice", "master-rolls", "units", "companions", "preparation", "length"];
|
|
6
6
|
const fileName = "last-choices.json";
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const entries = read !== null && typeof read === "object" && !Array.isArray(read) ? Object.entries(read) : [];
|
|
15
|
-
return Object.fromEntries(entries.filter((entry) => rememberedSettings.includes(entry[0]) && typeof entry[1] === "string"));
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return {};
|
|
19
|
-
}
|
|
7
|
+
/**
|
|
8
|
+
* The last choice of each remembered setting, from the player's folder on this computer; for `campaign`, only those of the campaigns before it, never its own
|
|
9
|
+
* (T-212). None when there is no folder or the file does not read.
|
|
10
|
+
*/
|
|
11
|
+
export function lastChoices(home, campaign) {
|
|
12
|
+
const kept = readKept(home);
|
|
13
|
+
return campaign !== undefined && kept.campaign === resolve(campaign) ? kept.before : { ...kept.before, ...kept.own };
|
|
20
14
|
}
|
|
21
|
-
/**
|
|
22
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Remembers a choice of a remembered setting in the player's folder, as the campaign `campaign` made it; a choice of another setting, or a folder that cannot
|
|
17
|
+
* be written, changes nothing.
|
|
18
|
+
*/
|
|
19
|
+
export function rememberChoice(home, campaign, name, value) {
|
|
23
20
|
if (home === undefined || !rememberedSettings.includes(name) || typeof value !== "string") {
|
|
24
21
|
return;
|
|
25
22
|
}
|
|
23
|
+
const kept = readKept(home);
|
|
24
|
+
const root = resolve(campaign);
|
|
25
|
+
// Another campaign's choices become those before this one.
|
|
26
|
+
const next = kept.campaign === root ? { ...kept, own: { ...kept.own, [name]: value } } : { campaign: root, own: { [name]: value }, before: { ...kept.before, ...kept.own } };
|
|
26
27
|
const file = join(home, fileName);
|
|
27
28
|
try {
|
|
28
29
|
mkdirSync(dirname(file), { recursive: true });
|
|
29
|
-
writeFileSync(file, `${JSON.stringify(
|
|
30
|
+
writeFileSync(file, `${JSON.stringify(next, null, 2)}\n`);
|
|
30
31
|
}
|
|
31
32
|
catch {
|
|
32
33
|
// A suggestion lost is no reason to stop the change the player asked for.
|
|
33
34
|
}
|
|
34
35
|
}
|
|
36
|
+
/** The file as kept; a file of the choices alone, as written before T-212, holds those of the campaigns before; none when it does not read. */
|
|
37
|
+
function readKept(home) {
|
|
38
|
+
if (home === undefined) {
|
|
39
|
+
return { own: {}, before: {} };
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const read = JSON.parse(readFileSync(join(home, fileName), "utf8"));
|
|
43
|
+
const object = isObject(read) ? read : {};
|
|
44
|
+
if (!("before" in object) && !("own" in object)) {
|
|
45
|
+
return { own: {}, before: choicesOf(object) };
|
|
46
|
+
}
|
|
47
|
+
return { ...(typeof object.campaign === "string" ? { campaign: object.campaign } : {}), own: choicesOf(object.own), before: choicesOf(object.before) };
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return { own: {}, before: {} };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** The remembered settings of an object read, each with its value. */
|
|
54
|
+
function choicesOf(read) {
|
|
55
|
+
const entries = isObject(read) ? Object.entries(read) : [];
|
|
56
|
+
return Object.fromEntries(entries.filter((entry) => rememberedSettings.includes(entry[0]) && typeof entry[1] === "string"));
|
|
57
|
+
}
|
|
58
|
+
function isObject(read) {
|
|
59
|
+
return read !== null && typeof read === "object" && !Array.isArray(read);
|
|
60
|
+
}
|
|
@@ -80,6 +80,13 @@ export declare const voiceWays: readonly ["master", "auto", "important", "always
|
|
|
80
80
|
export { unitSystems };
|
|
81
81
|
/** Which pictures the engine has made, where it can (D-308, D-388, D-420): none, only those the player asks for, or one for each new place, quest and one met. */
|
|
82
82
|
export declare const pictureWays: readonly ["none", "on request", "new elements"];
|
|
83
|
+
/**
|
|
84
|
+
* Who makes the pictures (D-572): the chat in use by its own means, as when unset, Codex, the master with ElevenLabs's image tool, or another tool the player
|
|
85
|
+
* names in the chat; any other value is that tool's name.
|
|
86
|
+
*/
|
|
87
|
+
export declare const pictureMakers: readonly ["chat", "codex", "elevenlabs", "other"];
|
|
88
|
+
/** Who makes the pictures of the campaign of a folder, as its pictures-by setting says; undefined when unset, or with no campaign that reads. */
|
|
89
|
+
export declare function chosenPictureMaker(folder: string): string | undefined;
|
|
83
90
|
/** How much the master thinks before each answer, written for each AI app in the campaign's folder (D-462). */
|
|
84
91
|
export declare const efforts: readonly ["low", "medium", "high"];
|
|
85
92
|
/** How the companions come (D-76, D-221): none, made in session zero with the player or by the master, or met in play. */
|
|
@@ -222,6 +229,7 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
222
229
|
"on request": "on request";
|
|
223
230
|
"new elements": "new elements";
|
|
224
231
|
}>, unknown>>;
|
|
232
|
+
"pictures-by": z.ZodOptional<z.ZodString>;
|
|
225
233
|
effort: z.ZodOptional<z.ZodEnum<{
|
|
226
234
|
low: "low";
|
|
227
235
|
medium: "medium";
|
|
@@ -261,7 +269,7 @@ export declare const mapSettingNames: SettingName[];
|
|
|
261
269
|
/** The settings that hold entries by name: what the campaign adds to its game system, where the dashboard shows the extensions' widgets (D-502), and the items of a custom difficulty or rigor (T-132). */
|
|
262
270
|
export declare const entrySettingNames: SettingName[];
|
|
263
271
|
/**
|
|
264
|
-
* What only the setup asks (D-241, MOD-3, D-347, D-287, D-557): how much the master teaches the game, whether the master's rolls are shown, how the
|
|
265
|
-
* character and the companions come, when the story starts, and the lines and veils, which "none" answers too.
|
|
272
|
+
* What only the setup asks (D-241, MOD-3, D-347, D-287, D-557, D-572): how much the master teaches the game, whether the master's rolls are shown, how the
|
|
273
|
+
* player character and the companions come, when the story starts, the pictures and who makes them, and the lines and veils, which "none" answers too.
|
|
266
274
|
*/
|
|
267
275
|
export declare const setupSettingNames: SettingName[];
|
|
@@ -5,7 +5,7 @@ import { unitSystems } from "../core/length.js";
|
|
|
5
5
|
import { files } from "../core/store.js";
|
|
6
6
|
import { comparableText } from "../core/text.js";
|
|
7
7
|
import { readYamlFile, readYamlValues, writeYamlFile } from "../core/yaml-file.js";
|
|
8
|
-
import { campaignFileName } from "./find-campaign.js";
|
|
8
|
+
import { campaignFileName, findCampaign } from "./find-campaign.js";
|
|
9
9
|
import { customLevel, difficulties, difficultyItems, levelMeaning, rigorItems, rigors } from "./levels.js";
|
|
10
10
|
const settingsHold = 'settings, such as "name: ..."';
|
|
11
11
|
/** What a fall means (D-13, D-141): the character never dies, dies only when it matters, or as the dice say. */
|
|
@@ -20,7 +20,7 @@ export function settingMeaning(name, value, counted, custom) {
|
|
|
20
20
|
if ((name === "difficulty" || name === "rigor") && typeof value === "string") {
|
|
21
21
|
return levelMeaning(name, value, counted, custom);
|
|
22
22
|
}
|
|
23
|
-
const meanings = { mentor: mentorMeanings, ...styleMeanings };
|
|
23
|
+
const meanings = { mentor: mentorMeanings, "pictures-by": pictureMakerMeanings, ...styleMeanings };
|
|
24
24
|
const own = Object.hasOwn(meanings, name) ? meanings[name] : undefined;
|
|
25
25
|
return typeof value === "string" && own !== undefined && Object.hasOwn(own, value) ? own[value] : undefined;
|
|
26
26
|
}
|
|
@@ -275,6 +275,28 @@ export const voiceWays = ["master", "auto", "important", "always"];
|
|
|
275
275
|
export { unitSystems };
|
|
276
276
|
/** Which pictures the engine has made, where it can (D-308, D-388, D-420): none, only those the player asks for, or one for each new place, quest and one met. */
|
|
277
277
|
export const pictureWays = ["none", "on request", "new elements"];
|
|
278
|
+
/**
|
|
279
|
+
* Who makes the pictures (D-572): the chat in use by its own means, as when unset, Codex, the master with ElevenLabs's image tool, or another tool the player
|
|
280
|
+
* names in the chat; any other value is that tool's name.
|
|
281
|
+
*/
|
|
282
|
+
export const pictureMakers = ["chat", "codex", "elevenlabs", "other"];
|
|
283
|
+
/** What each way of making the pictures means to the master, which config gives for the chosen one, and the player's change of it on the dashboard (D-572). */
|
|
284
|
+
const pictureMakerMeanings = {
|
|
285
|
+
chat: "you make them by this chat's own means, as image gives them",
|
|
286
|
+
codex: "Codex makes them on this computer; where it cannot, this chat does, and you hear why",
|
|
287
|
+
elevenlabs: "you make them with ElevenLabs's image tool, from the brief image gives you",
|
|
288
|
+
other: "another image tool of yours, not named yet: ask the player which, then set its name with config pictures-by",
|
|
289
|
+
};
|
|
290
|
+
/** Who makes the pictures of the campaign of a folder, as its pictures-by setting says; undefined when unset, or with no campaign that reads. */
|
|
291
|
+
export function chosenPictureMaker(folder) {
|
|
292
|
+
try {
|
|
293
|
+
const root = findCampaign(folder);
|
|
294
|
+
return root === undefined ? undefined : readTextSetting(root, "pictures-by");
|
|
295
|
+
}
|
|
296
|
+
catch {
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
278
300
|
/** How much the master thinks before each answer, written for each AI app in the campaign's folder (D-462). */
|
|
279
301
|
export const efforts = ["low", "medium", "high"];
|
|
280
302
|
/** How the companions come (D-76, D-221): none, made in session zero with the player or by the master, or met in play. */
|
|
@@ -371,6 +393,8 @@ export const settingsSchema = z.object({
|
|
|
371
393
|
// new places and new places and quests, as campaigns wrote it before quests and then those met had pictures, are read as the value that took their place (D-388, D-420).
|
|
372
394
|
pictures: z.preprocess((value) => (value === "new places" || value === "new places and quests" ? "new elements" : value), z.enum(pictureWays)).optional().describe("the pictures of places, quests and those met the engine has made on this computer, which spend the player's plan, Codex's or Claude's: none, on request (those the player asks for) "
|
|
373
395
|
+ "or new elements (one for each new place and quest, and for each character and kind of creature the character meets)"),
|
|
396
|
+
"pictures-by": z.string().trim().min(1).optional().describe("who makes the pictures, the player's to choose: chat (the default: this chat by its own means), codex (Codex, from the player's ChatGPT plan, Plus or higher; "
|
|
397
|
+
+ "where it cannot, this chat makes them), elevenlabs (you, with ElevenLabs's image tool), other (another tool of yours the player names: ask which) or that tool's name"),
|
|
374
398
|
effort: z.enum(efforts).optional().describe("how much the master thinks before each answer, the player's to choose: low, medium or high, written where Claude Code and Codex read it in the campaign's folder; "
|
|
375
399
|
+ "unset, each app keeps its own"),
|
|
376
400
|
lines: listSetting.describe("what never appears in the game"),
|
|
@@ -409,14 +433,14 @@ export const mapSettingNames = ["fields", "tables", "computed", "counters", "rec
|
|
|
409
433
|
/** The settings that hold entries by name: what the campaign adds to its game system, where the dashboard shows the extensions' widgets (D-502), and the items of a custom difficulty or rigor (T-132). */
|
|
410
434
|
export const entrySettingNames = [...mapSettingNames, "widgets", "custom-difficulty", "custom-rigor"];
|
|
411
435
|
/**
|
|
412
|
-
* What only the setup asks (D-241, MOD-3, D-347, D-287, D-557): how much the master teaches the game, whether the master's rolls are shown, how the
|
|
413
|
-
* character and the companions come, when the story starts, and the lines and veils, which "none" answers too.
|
|
436
|
+
* What only the setup asks (D-241, MOD-3, D-347, D-287, D-557, D-572): how much the master teaches the game, whether the master's rolls are shown, how the
|
|
437
|
+
* player character and the companions come, when the story starts, the pictures and who makes them, and the lines and veils, which "none" answers too.
|
|
414
438
|
*/
|
|
415
|
-
export const setupSettingNames = ["mentor", "master-rolls", "character", "companions", "calendar-start", "lines", "veils"];
|
|
439
|
+
export const setupSettingNames = ["mentor", "master-rolls", "character", "companions", "calendar-start", "pictures", "pictures-by", "lines", "veils"];
|
|
416
440
|
/** What the setup asks only of a campaign without a written world (D-79, D-80, D-558, MOD-3). */
|
|
417
441
|
const premiseSettingNames = ["premise", "preparation", "length"];
|
|
418
442
|
// Settings that only some games have, or that only the setup asks: never asked for in play when missing.
|
|
419
|
-
// The pictures: status asks for them once, only where they can be made (D-308).
|
|
443
|
+
// The pictures: the setup asks them; in a campaign made before, status asks for them once, only where they can be made (D-308, D-572).
|
|
420
444
|
// How the master writes: the core's own until the player chooses (D-395).
|
|
421
445
|
const styleSettingNames = ["prose", "story", "author", "style"];
|
|
422
446
|
const optionalSettingNames = ["coins", "pictures", "effort", "voices", "calendar", "calendar-start", "between-sessions", ...entrySettingNames, ...setupSettingNames, ...premiseSettingNames, ...styleSettingNames];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** A chat of the game as a host kept it: the host, its id, and the player's and the master's messages in order. */
|
|
2
|
+
export interface Chat {
|
|
3
|
+
host: string;
|
|
4
|
+
id: string;
|
|
5
|
+
messages: ChatMessage[];
|
|
6
|
+
}
|
|
7
|
+
/** A message of the player or of the master, with when it was written, ISO 8601. */
|
|
8
|
+
export interface ChatMessage {
|
|
9
|
+
who: "player" | "master";
|
|
10
|
+
at: string;
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
/** A chat a host keeps on this computer: its host and id, its file, and the chat read from it; none when it is not the campaign's, or holds no message. */
|
|
14
|
+
export interface ChatSource {
|
|
15
|
+
host: string;
|
|
16
|
+
id: string;
|
|
17
|
+
path: string;
|
|
18
|
+
read(): Chat | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** A chat's messages with the next one of the same speaker joined to it, as the master's words before and after a tool. */
|
|
21
|
+
export declare function joinedMessages(messages: ChatMessage[]): ChatMessage[];
|
|
22
|
+
/** A stretch of real time a load undid: from when the save it loaded was made to when it was loaded; what was said in it did not happen. */
|
|
23
|
+
export interface UndoneStretch {
|
|
24
|
+
from: string;
|
|
25
|
+
to: string;
|
|
26
|
+
save: number;
|
|
27
|
+
}
|
|
28
|
+
/** The stretch a load undid that a moment falls in; none when it is part of the story as it stands. */
|
|
29
|
+
export declare function undoneAt(at: string, undone: UndoneStretch[]): UndoneStretch | undefined;
|
|
30
|
+
/** A chat as the campaign keeps it: markdown, each message under who wrote it and when, in UTC as the log has it, and whether a load undid it. */
|
|
31
|
+
export declare function chatText(chat: Chat, undone: UndoneStretch[]): string;
|
|
32
|
+
/** A chat read back from the text the campaign keeps; none when the text is not one rpg wrote. */
|
|
33
|
+
export declare function readChatText(text: string): Chat | undefined;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** A chat's messages with the next one of the same speaker joined to it, as the master's words before and after a tool. */
|
|
2
|
+
export function joinedMessages(messages) {
|
|
3
|
+
return messages.reduce((joined, message) => {
|
|
4
|
+
const last = joined.at(-1);
|
|
5
|
+
if (last?.who === message.who) {
|
|
6
|
+
last.text = `${last.text}\n\n${message.text}`;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
joined.push({ ...message });
|
|
10
|
+
}
|
|
11
|
+
return joined;
|
|
12
|
+
}, []);
|
|
13
|
+
}
|
|
14
|
+
/** The stretch a load undid that a moment falls in; none when it is part of the story as it stands. */
|
|
15
|
+
export function undoneAt(at, undone) {
|
|
16
|
+
const time = Date.parse(at);
|
|
17
|
+
return undone.find((stretch) => time > Date.parse(stretch.from) && time < Date.parse(stretch.to));
|
|
18
|
+
}
|
|
19
|
+
/** A chat as the campaign keeps it: markdown, each message under who wrote it and when, in UTC as the log has it, and whether a load undid it. */
|
|
20
|
+
export function chatText(chat, undone) {
|
|
21
|
+
const head = [`# ${chat.messages[0]?.at.slice(0, 10) ?? ""} · ${chat.host}`, "", `Written by rpg from the chat ${chat.host} keeps (${chat.id}), again as it goes on: a change made here does not last.`];
|
|
22
|
+
const messages = chat.messages.map((message) => {
|
|
23
|
+
const stretch = undoneAt(message.at, undone);
|
|
24
|
+
const mark = stretch === undefined ? "" : ` · undone by loading save ${stretch.save}`;
|
|
25
|
+
return `**${message.who === "player" ? "Player" : "Master"}** · ${message.at.slice(0, 19).replace("T", " ")} UTC${mark}\n\n${message.text.trim()}`;
|
|
26
|
+
});
|
|
27
|
+
return `${[head.join("\n"), ...messages].join("\n\n")}\n`;
|
|
28
|
+
}
|
|
29
|
+
// The line above each message of a kept chat: who, when, and the mark of a load that undid it.
|
|
30
|
+
const messageHead = /^\*\*(Player|Master)\*\* · (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}) UTC(?: · undone by loading save \d+)?$/;
|
|
31
|
+
/** A chat read back from the text the campaign keeps; none when the text is not one rpg wrote. */
|
|
32
|
+
export function readChatText(text) {
|
|
33
|
+
const lines = text.replace(/\r\n/g, "\n").split("\n");
|
|
34
|
+
const written = /^Written by rpg from the chat (\S+) keeps \(([^)]+)\)/.exec(lines[2] ?? "");
|
|
35
|
+
if (written === null) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const messages = [];
|
|
39
|
+
for (const line of lines.slice(3)) {
|
|
40
|
+
const head = messageHead.exec(line);
|
|
41
|
+
const last = messages.at(-1);
|
|
42
|
+
if (head !== null) {
|
|
43
|
+
messages.push({ who: head[1] === "Player" ? "player" : "master", at: `${head[2]}T${head[3]}Z`, text: "" });
|
|
44
|
+
}
|
|
45
|
+
else if (last !== undefined) {
|
|
46
|
+
last.text = `${last.text}\n${line}`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { host: written[1] ?? "", id: written[2] ?? "", messages: messages.map((message) => ({ ...message, text: message.text.trim() })) };
|
|
50
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ChatSource } from "./chat.ts";
|
|
2
|
+
/** 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. */
|
|
3
|
+
export declare function claudeCodeChats(projects: string, root: string): ChatSource[];
|
|
4
|
+
/** Claude Code names a project's folder after its path, each character but a letter or a digit made a hyphen. */
|
|
5
|
+
export declare function projectName(root: string): string;
|
|
@@ -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[];
|