rpg-engine 0.21.0 → 0.23.1
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 +5 -5
- package/dist/campaign/create-campaign.d.ts +5 -0
- package/dist/campaign/create-campaign.js +40 -12
- package/dist/campaign/find-campaign.d.ts +5 -0
- package/dist/campaign/find-campaign.js +10 -5
- package/dist/campaign/host-files.d.ts +15 -4
- package/dist/campaign/host-files.js +134 -14
- package/dist/campaign/index.d.ts +4 -3
- package/dist/campaign/index.js +4 -3
- package/dist/campaign/port.d.ts +6 -0
- package/dist/campaign/port.js +24 -0
- package/dist/campaign/settings.d.ts +17 -0
- package/dist/campaign/settings.js +24 -1
- package/dist/cli/cli.js +33 -6
- package/dist/commands/config/config.js +15 -1
- package/dist/commands/config/dashboard.d.ts +4 -0
- package/dist/commands/config/dashboard.js +43 -7
- package/dist/commands/config/shown.js +4 -0
- package/dist/commands/config/words.d.ts +3 -1
- package/dist/commands/config/words.js +29 -2
- package/dist/commands/image.d.ts +3 -0
- package/dist/commands/image.js +31 -4
- package/dist/commands/import/import.d.ts +1 -1
- package/dist/commands/import/import.js +5 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +21 -3
- package/dist/commands/mode.d.ts +1 -1
- package/dist/commands/package/data.js +27 -0
- package/dist/commands/package/theme.js +2 -1
- package/dist/commands/scene/scene.js +6 -1
- package/dist/commands/shared/books/adventures.d.ts +1 -0
- package/dist/commands/shared/books/adventures.js +1 -1
- package/dist/commands/shared/campaign/git.d.ts +25 -0
- package/dist/commands/shared/campaign/git.js +104 -0
- package/dist/commands/shared/campaign/images.js +5 -3
- package/dist/commands/shared/campaign/saves.js +5 -1
- package/dist/commands/shared/characters/voices.d.ts +2 -2
- package/dist/commands/shared/characters/voices.js +8 -5
- package/dist/commands/shared/packages/catalog.js +24 -5
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +8 -4
- package/dist/core/context.d.ts +17 -6
- package/dist/core/context.js +2 -1
- package/dist/core/version.d.ts +2 -0
- package/dist/core/version.js +5 -0
- package/dist/dashboard/guide/ar.md +12 -7
- package/dist/dashboard/guide/cs.md +11 -6
- package/dist/dashboard/guide/da.md +11 -6
- package/dist/dashboard/guide/de.md +13 -8
- package/dist/dashboard/guide/el.md +11 -6
- package/dist/dashboard/guide/en.md +10 -5
- package/dist/dashboard/guide/es.md +11 -6
- package/dist/dashboard/guide/fi.md +11 -6
- package/dist/dashboard/guide/fr.md +12 -7
- package/dist/dashboard/guide/he.md +11 -6
- package/dist/dashboard/guide/hi.md +11 -6
- package/dist/dashboard/guide/hu.md +11 -6
- package/dist/dashboard/guide/is.md +11 -6
- package/dist/dashboard/guide/it.md +42 -37
- package/dist/dashboard/guide/ja.md +12 -7
- package/dist/dashboard/guide/ko.md +11 -6
- package/dist/dashboard/guide/nb.md +12 -7
- package/dist/dashboard/guide/nl.md +13 -8
- package/dist/dashboard/guide/pl.md +11 -6
- package/dist/dashboard/guide/pt.md +11 -6
- package/dist/dashboard/guide/ro.md +11 -6
- package/dist/dashboard/guide/ru.md +12 -7
- package/dist/dashboard/guide/sv.md +11 -6
- package/dist/dashboard/guide/tr.md +12 -7
- package/dist/dashboard/guide/uk.md +12 -7
- package/dist/dashboard/guide/zh.md +11 -6
- package/dist/dashboard/i18n/ar.json +30 -2
- package/dist/dashboard/i18n/cs.json +30 -2
- package/dist/dashboard/i18n/da.json +30 -2
- package/dist/dashboard/i18n/de.json +30 -2
- package/dist/dashboard/i18n/el.json +30 -2
- package/dist/dashboard/i18n/es.json +30 -2
- package/dist/dashboard/i18n/fi.json +30 -2
- package/dist/dashboard/i18n/fr.json +30 -2
- package/dist/dashboard/i18n/he.json +30 -2
- package/dist/dashboard/i18n/hi.json +30 -2
- package/dist/dashboard/i18n/hu.json +30 -2
- package/dist/dashboard/i18n/is.json +30 -2
- package/dist/dashboard/i18n/it.json +30 -2
- package/dist/dashboard/i18n/ja.json +30 -2
- package/dist/dashboard/i18n/ko.json +30 -2
- package/dist/dashboard/i18n/nb.json +30 -2
- package/dist/dashboard/i18n/nl.json +30 -2
- package/dist/dashboard/i18n/pl.json +30 -2
- package/dist/dashboard/i18n/pt.json +30 -2
- package/dist/dashboard/i18n/ro.json +30 -2
- package/dist/dashboard/i18n/ru.json +30 -2
- package/dist/dashboard/i18n/sv.json +30 -2
- package/dist/dashboard/i18n/tr.json +30 -2
- package/dist/dashboard/i18n/uk.json +30 -2
- package/dist/dashboard/i18n/zh.json +30 -2
- package/dist/dashboard/packages/installed.js +2 -2
- package/dist/dashboard/packages/packages.js +1 -1
- package/dist/dashboard/parts/labels.js +7 -0
- package/dist/dashboard/settings/settings.js +45 -9
- package/dist/dashboard/shell/notices.js +1 -1
- package/dist/dashboard/shell/system-style.js +89 -5
- package/dist/dashboard/shell/tooltip.js +5 -4
- package/dist/dashboard/style.css +245 -84
- package/dist/git/git.d.ts +12 -0
- package/dist/git/git.js +175 -0
- package/dist/git/ignore.d.ts +2 -0
- package/dist/git/ignore.js +16 -0
- package/dist/git/index.d.ts +2 -0
- package/dist/git/index.js +2 -0
- package/dist/helpers/briefs.d.ts +4 -0
- package/dist/helpers/briefs.js +13 -0
- package/dist/helpers/chosen.d.ts +8 -4
- package/dist/helpers/chosen.js +38 -14
- package/dist/helpers/index.d.ts +3 -2
- package/dist/helpers/index.js +5 -3
- package/dist/helpers/opencode.d.ts +13 -0
- package/dist/helpers/opencode.js +202 -0
- package/dist/importer/index.d.ts +1 -1
- package/dist/importer/index.js +1 -1
- package/dist/instructions/index.d.ts +2 -2
- package/dist/instructions/index.js +3 -3
- package/dist/languages/pack.js +2 -1
- package/dist/server/approver.d.ts +4 -2
- package/dist/server/approver.js +27 -7
- package/dist/server/bell/antigravity.d.ts +10 -0
- package/dist/server/bell/antigravity.js +95 -0
- package/dist/server/bell/index.d.ts +2 -0
- package/dist/server/bell/index.js +2 -0
- package/dist/server/bell/listener.d.ts +43 -0
- package/dist/server/bell/listener.js +149 -0
- package/dist/server/dashboard/files.d.ts +3 -2
- package/dist/server/dashboard/files.js +44 -15
- package/dist/server/dashboard/index.d.ts +25 -3
- package/dist/server/dashboard/index.js +58 -23
- package/dist/server/dashboard/news.d.ts +5 -2
- package/dist/server/dashboard/news.js +82 -14
- package/dist/server/dashboard/ports.d.ts +17 -2
- package/dist/server/dashboard/ports.js +60 -4
- package/dist/server/mcp.d.ts +6 -4
- package/dist/server/mcp.js +66 -18
- package/dist/server/player-acts.d.ts +21 -1
- package/dist/server/player-acts.js +38 -2
- package/dist/server/route/front.d.ts +3 -0
- package/dist/server/route/front.js +97 -0
- package/dist/server/route/index.d.ts +3 -0
- package/dist/server/route/index.js +3 -0
- package/dist/server/route/notes.d.ts +8 -0
- package/dist/server/route/notes.js +50 -0
- package/dist/server/route/router.d.ts +31 -0
- package/dist/server/route/router.js +215 -0
- package/dist/themes/css.d.ts +1 -1
- package/dist/themes/css.js +101 -2
- package/dist/themes/index.d.ts +1 -1
- package/dist/themes/index.js +1 -1
- package/dist/themes/theme.d.ts +34 -3
- package/dist/themes/theme.js +176 -19
- package/instructions/core.md +1 -0
- package/instructions/dashboard-guide.md +1 -1
- package/instructions/start.md +1 -1
- package/instructions/voices-opencode.md +1 -0
- package/package.json +3 -2
- package/plugins/opencode.js +174 -0
- package/dist/server/bell-listener.d.ts +0 -9
- package/dist/server/bell-listener.js +0 -83
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ An AI is a wonderful storyteller, but a storyteller tends to make the world fit
|
|
|
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
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
|
|
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, Claude draws simpler vector ones; in OpenCode, and in Antigravity when its tool fails, the master draws them itself, the same way.
|
|
29
29
|
|
|
30
30
|
## The game
|
|
31
31
|
|
|
@@ -43,11 +43,11 @@ A game comes as a game system, a package the master installs when you set up a c
|
|
|
43
43
|
|
|
44
44
|
## What you need
|
|
45
45
|
|
|
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
|
|
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, Antigravity or OpenCode. 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.
|
|
47
47
|
|
|
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 **
|
|
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**, **Antigravity** and **OpenCode** are connected and checked, from the terminal and from their desktop apps, 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.
|
|
49
49
|
|
|
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
|
|
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; for OpenCode, the model you choose in it), or on your computer with a local model. RPG Engine itself never asks for an API key nor keeps one: where your agent lets you choose, sign it in with your account rather than with a key, which is paid by the call. You do not need to know how to program, and once your agent is installed, you are playing in a few minutes.
|
|
51
51
|
|
|
52
52
|
## Quick start
|
|
53
53
|
|
|
@@ -62,7 +62,7 @@ claude
|
|
|
62
62
|
|
|
63
63
|
If Windows answers that running scripts is disabled, write once `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`, answer yes and try again.
|
|
64
64
|
|
|
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
|
+
With Codex write `codex`, with Antigravity `agy`, with OpenCode `opencode`; with another agent, start it in that folder (the guide says how to connect it). Each of the four has a desktop app too: open the campaign folder in it. When it asks whether you trust the folder, say yes; careful, in Claude Code the answer already selected is *No, exit*. If you install an agent after you made the campaign, write `rpg init` in the campaign folder once, and open a new chat.
|
|
66
66
|
|
|
67
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.
|
|
68
68
|
|
|
@@ -5,3 +5,8 @@ import { type CampaignSettings } from "./settings.ts";
|
|
|
5
5
|
* and the host files that send them to the start lines and give Claude Code the character agent (D-97, D-242, D-490). `platform` is the operating system, as Node names it. Returns the campaign's full path.
|
|
6
6
|
*/
|
|
7
7
|
export declare function createCampaign(folder: string, settings: CampaignSettings, platform: string, instructions: HostInstructions): string;
|
|
8
|
+
/**
|
|
9
|
+
* Brings the files through which the AI hosts find the game up to date in a campaign that exists, as init does when given its folder again: the rpg server
|
|
10
|
+
* in .mcp.json when missing, and the host files. A broken settings file of a host, or a link among the folders written, stops it with how to fix it.
|
|
11
|
+
*/
|
|
12
|
+
export declare function updateHostFiles(root: string, platform: string, instructions: HostInstructions): void;
|
|
@@ -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, inboxFolderName, sessionsFolderName } from "./find-campaign.js";
|
|
6
|
+
import { campaignFileName, findCampaign, inboxFolderName, refuseCampaignLinks, sessionsFolderName } from "./find-campaign.js";
|
|
7
7
|
import { hostFileChanges, rpgServer, writeHostFile } from "./host-files.js";
|
|
8
8
|
import { settingsSchema } from "./settings.js";
|
|
9
9
|
/**
|
|
@@ -17,7 +17,8 @@ export function createCampaign(folder, settings, platform, instructions) {
|
|
|
17
17
|
if (!parsed.success) {
|
|
18
18
|
throw new Error(`The campaign settings are not valid:\n${z.prettifyError(parsed.error)}`);
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
refuseCampaignLinks(root);
|
|
21
|
+
const mcpConfig = mcpConfigWithRpg(root, platform, "create the campaign again");
|
|
21
22
|
const hostFiles = hostFileChanges(root, instructions, platform);
|
|
22
23
|
files().makeFolder(join(root, sessionsFolderName));
|
|
23
24
|
files().makeFolder(join(root, inboxFolderName));
|
|
@@ -28,19 +29,46 @@ export function createCampaign(folder, settings, platform, instructions) {
|
|
|
28
29
|
hostFiles.forEach(writeHostFile);
|
|
29
30
|
return root;
|
|
30
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Brings the files through which the AI hosts find the game up to date in a campaign that exists, as init does when given its folder again: the rpg server
|
|
34
|
+
* in .mcp.json when missing, and the host files. A broken settings file of a host, or a link among the folders written, stops it with how to fix it.
|
|
35
|
+
*/
|
|
36
|
+
export function updateHostFiles(root, platform, instructions) {
|
|
37
|
+
refuseCampaignLinks(root);
|
|
38
|
+
const again = "run rpg init in this folder again";
|
|
39
|
+
const before = mcpConfig(root, again);
|
|
40
|
+
const hostFiles = hostFileChanges(root, instructions, platform);
|
|
41
|
+
if (before.mcpServers?.rpg === undefined) {
|
|
42
|
+
files().write(join(root, ".mcp.json"), JSON.stringify(mcpConfigWithRpg(root, platform, again), null, 2) + "\n");
|
|
43
|
+
}
|
|
44
|
+
hostFiles.forEach(writeHostFile);
|
|
45
|
+
}
|
|
31
46
|
/** The folder's .mcp.json with the rpg server added; other servers already listed stay. On Windows a host must start rpg through cmd. */
|
|
32
|
-
function mcpConfigWithRpg(root, platform) {
|
|
47
|
+
function mcpConfigWithRpg(root, platform, again) {
|
|
48
|
+
const config = mcpConfig(root, again);
|
|
49
|
+
return { ...config, mcpServers: { ...config.mcpServers, rpg: rpgServer(platform) } };
|
|
50
|
+
}
|
|
51
|
+
/** The folder's .mcp.json, empty when there is none; refused, with how to fix it and what to do `again` after, when it holds no JSON object of servers. */
|
|
52
|
+
function mcpConfig(root, again) {
|
|
33
53
|
const path = join(root, ".mcp.json");
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
config = JSON.parse(files().text(path) ?? "");
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
throw new Error(`${path} is not valid JSON, so the rpg server cannot be added to it. Fix it or remove it by hand, then create the campaign again.`);
|
|
41
|
-
}
|
|
54
|
+
if (!files().exists(path)) {
|
|
55
|
+
return {};
|
|
42
56
|
}
|
|
43
|
-
|
|
57
|
+
let config;
|
|
58
|
+
try {
|
|
59
|
+
config = JSON.parse(files().text(path) ?? "");
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
throw new Error(`${path} is not valid JSON, so the rpg server cannot be added to it. Fix it or remove it by hand, then ${again}.`);
|
|
63
|
+
}
|
|
64
|
+
const servers = isObject(config) ? config.mcpServers : undefined;
|
|
65
|
+
if (!isObject(config) || (servers !== undefined && !isObject(servers))) {
|
|
66
|
+
throw new Error(`${path} is not a JSON object with its servers under mcpServers, so the rpg server cannot be added to it. Fix it or remove it by hand, then ${again}.`);
|
|
67
|
+
}
|
|
68
|
+
return config;
|
|
69
|
+
}
|
|
70
|
+
function isObject(value) {
|
|
71
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
44
72
|
}
|
|
45
73
|
/** A campaign cannot sit inside another one, nor hold one. */
|
|
46
74
|
function checkNoOtherCampaign(root) {
|
|
@@ -12,3 +12,8 @@ export declare const bookFolderName = "book";
|
|
|
12
12
|
export declare function findCampaign(folder: string): string | undefined;
|
|
13
13
|
/** Like findCampaign, but fails with a message that says how to get into a campaign. */
|
|
14
14
|
export declare function requireCampaign(folder: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* 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; in the hosts' folders,
|
|
17
|
+
* only those where it writes. Before the hosts' files are written, as by init, and at each command.
|
|
18
|
+
*/
|
|
19
|
+
export declare function refuseCampaignLinks(root: string): void;
|
|
@@ -28,7 +28,7 @@ export function requireCampaign(folder) {
|
|
|
28
28
|
if (root === undefined) {
|
|
29
29
|
throw new Error(`There is no campaign here: no ${campaignFileName} in ${resolve(folder)} or in the folders above it. Create one with the init command, or work from inside a campaign folder.`);
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
refuseCampaignLinks(root);
|
|
32
32
|
// The session of the MCP server watches the campaign from the first call that finds it (D-193).
|
|
33
33
|
files().track(root);
|
|
34
34
|
return root;
|
|
@@ -37,9 +37,14 @@ export function requireCampaign(folder) {
|
|
|
37
37
|
const layersFolder = "layers";
|
|
38
38
|
// 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
|
|
39
39
|
// that is a link the store refuses as it writes it.
|
|
40
|
-
const writtenFolders = ["world", "images", "rules", sessionsFolderName, bookFolderName, ".saves", "exports", ".player", ".imports",
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const writtenFolders = ["world", "images", "rules", sessionsFolderName, bookFolderName, ".saves", "exports", ".player", ".imports", layersFolder];
|
|
41
|
+
// The hosts' folders, where the engine writes only its own files, beside the player's: these alone are looked at, never what the player keeps in them.
|
|
42
|
+
const hostFolders = [".claude", join(".claude", "agents"), ".codex", ".agents", ".opencode", join(".opencode", "plugins"), join(".opencode", "agents")];
|
|
43
|
+
/**
|
|
44
|
+
* 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; in the hosts' folders,
|
|
45
|
+
* only those where it writes. Before the hosts' files are written, as by init, and at each command.
|
|
46
|
+
*/
|
|
47
|
+
export function refuseCampaignLinks(root) {
|
|
43
48
|
const store = files();
|
|
44
49
|
const folders = writtenFolders.map((name) => join(root, name));
|
|
45
50
|
const inside = (folder) => [
|
|
@@ -49,7 +54,7 @@ function refuseLinksOut(root) {
|
|
|
49
54
|
const types = folders.flatMap(inside);
|
|
50
55
|
const deeper = types.flatMap(inside);
|
|
51
56
|
const layerTypes = deeper.filter((path) => isInside(join(root, layersFolder), path)).flatMap(inside);
|
|
52
|
-
const linked = [...folders, ...types, ...deeper, ...layerTypes].find((path) => store.isLink(path));
|
|
57
|
+
const linked = [...folders, ...types, ...deeper, ...layerTypes, ...hostFolders.map((name) => join(root, name))].find((path) => store.isLink(path));
|
|
53
58
|
if (linked !== undefined) {
|
|
54
59
|
throw new Error(`${linked} is a link to somewhere else, and what the engine writes there would leave the campaign: replace it with a real folder, with what it holds copied in.`);
|
|
55
60
|
}
|
|
@@ -19,7 +19,10 @@ export declare function rpgServer(platform: string): {
|
|
|
19
19
|
};
|
|
20
20
|
/** The host files of a campaign that are missing or out of date, with the engine's texts given; a broken settings file of a host stops it with how to fix it. */
|
|
21
21
|
export declare function hostFileChanges(root: string, instructions: HostInstructions, platform: string): HostFile[];
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Brings the host files of a campaign up to date, as the MCP server starts: a file that cannot be read or written stays as it is, and none is written while a
|
|
24
|
+
* folder they go in is a link, which the first command refuses with how to fix it.
|
|
25
|
+
*/
|
|
23
26
|
export declare function refreshHostFiles(root: string, instructions: HostInstructions, platform: string): void;
|
|
24
27
|
/**
|
|
25
28
|
* Writes the master's effort the player chose where each host reads it, as config sets it (D-462); with `cleared`, takes it away, and each app keeps its own.
|
|
@@ -27,8 +30,16 @@ export declare function refreshHostFiles(root: string, instructions: HostInstruc
|
|
|
27
30
|
*/
|
|
28
31
|
export declare function writeEffortFiles(root: string, platform: string, cleared?: boolean): string[];
|
|
29
32
|
/**
|
|
30
|
-
* Whether the campaign has the character agent as a Claude Code agent (D-490): looked at as the MCP server starts, before it writes
|
|
31
|
-
* the chat found the agent, as
|
|
33
|
+
* Whether the campaign has the character agent as a Claude Code agent and as an OpenCode subagent (D-490): looked at as the MCP server starts, before it writes
|
|
34
|
+
* its host files, it says whether the chat found the agent, as both hosts read their agents only when a chat starts.
|
|
35
|
+
*/
|
|
36
|
+
export declare function hasCharacterAgent(root: string): {
|
|
37
|
+
claudeCode: boolean;
|
|
38
|
+
openCode: boolean;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Brings up to date the engine's files outside any campaign, in the player's home: Antigravity's own servers, which its app reads for every folder (D-578),
|
|
42
|
+
* when Antigravity is installed. What could not be written, with how to fix it; undefined when all is in order.
|
|
32
43
|
*/
|
|
33
|
-
export declare function
|
|
44
|
+
export declare function refreshUserHostFiles(userHome: string, platform: string): string | undefined;
|
|
34
45
|
export {};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// What an AI host reads in a campaign besides .mcp.json: AGENTS.md, opening with the start lines (D-97); CLAUDE.md, which imports it; Claude Code's settings,
|
|
2
2
|
// with its auto memory off, so that the master keeps nothing outside the campaign (D-242), the rpg server approved with its tools allowed (D-412) and no tasks in
|
|
3
3
|
// the background, so that the character agent answers within the master's turn (D-490), and the doorbell of the player's sentences (D-495); Codex's, with
|
|
4
|
-
// the rpg server and its memories off (D-362); Claude Code's character agent, the agent the master calls to voice a character (D-490)
|
|
5
|
-
// longer set up (D-493): a campaign's .gemini/ stays as it is.
|
|
4
|
+
// the rpg server and its memories off (D-362); Claude Code's character agent, the agent the master calls to voice a character (D-490); Antigravity's and
|
|
5
|
+
// OpenCode's, each with the rpg server and the doorbell (D-578). Gemini CLI is no longer set up (D-493): a campaign's .gemini/ stays as it is.
|
|
6
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
6
7
|
import { join } from "node:path";
|
|
7
8
|
import { files } from "../core/store.js";
|
|
9
|
+
import { refuseCampaignLinks } from "./find-campaign.js";
|
|
8
10
|
import { efforts, readTextSetting } from "./settings.js";
|
|
9
11
|
/** The files of the AI hosts at the top of a campaign, which are not the game's: a save leaves them as they are (SAV-2), Gemini CLI's of an older campaign too. */
|
|
10
|
-
export const hostFileNames = ["AGENTS.md", "CLAUDE.md", "CLAUDE.local.md", "GEMINI.md"];
|
|
12
|
+
export const hostFileNames = ["AGENTS.md", "CLAUDE.md", "CLAUDE.local.md", "GEMINI.md", "opencode.json"];
|
|
11
13
|
/** Writes a host file, or takes it away when it has no text. */
|
|
12
14
|
export function writeHostFile(file) {
|
|
13
15
|
if (file.text === undefined) {
|
|
@@ -29,8 +31,17 @@ export function rpgServer(platform) {
|
|
|
29
31
|
export function hostFileChanges(root, instructions, platform) {
|
|
30
32
|
return hostFiles(root, instructions, platform).map((file) => file()).filter((file) => file !== undefined);
|
|
31
33
|
}
|
|
32
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Brings the host files of a campaign up to date, as the MCP server starts: a file that cannot be read or written stays as it is, and none is written while a
|
|
36
|
+
* folder they go in is a link, which the first command refuses with how to fix it.
|
|
37
|
+
*/
|
|
33
38
|
export function refreshHostFiles(root, instructions, platform) {
|
|
39
|
+
try {
|
|
40
|
+
refuseCampaignLinks(root);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
34
45
|
for (const change of hostFiles(root, instructions, platform)) {
|
|
35
46
|
try {
|
|
36
47
|
const file = change();
|
|
@@ -63,11 +74,11 @@ export function writeEffortFiles(root, platform, cleared = false) {
|
|
|
63
74
|
});
|
|
64
75
|
}
|
|
65
76
|
/**
|
|
66
|
-
* Whether the campaign has the character agent as a Claude Code agent (D-490): looked at as the MCP server starts, before it writes
|
|
67
|
-
* the chat found the agent, as
|
|
77
|
+
* Whether the campaign has the character agent as a Claude Code agent and as an OpenCode subagent (D-490): looked at as the MCP server starts, before it writes
|
|
78
|
+
* its host files, it says whether the chat found the agent, as both hosts read their agents only when a chat starts.
|
|
68
79
|
*/
|
|
69
80
|
export function hasCharacterAgent(root) {
|
|
70
|
-
return files().fresh(characterAgentPath(root)) !== undefined;
|
|
81
|
+
return { claudeCode: files().fresh(characterAgentPath(root)) !== undefined, openCode: files().fresh(openCodeAgentPath(root)) !== undefined };
|
|
71
82
|
}
|
|
72
83
|
function hostFiles(root, instructions, platform) {
|
|
73
84
|
return [
|
|
@@ -75,9 +86,12 @@ function hostFiles(root, instructions, platform) {
|
|
|
75
86
|
() => claudeFile(root),
|
|
76
87
|
() => claudeSettingsFile(root),
|
|
77
88
|
() => characterAgentFile(root, instructions.character),
|
|
89
|
+
() => openCodeAgentFile(root, instructions.character),
|
|
78
90
|
() => codexConfigFile(root, platform),
|
|
79
91
|
() => antigravityServerFile(root, platform),
|
|
80
92
|
() => antigravityHooksFile(root),
|
|
93
|
+
() => openCodeConfigFile(root, platform),
|
|
94
|
+
() => openCodePluginFile(root),
|
|
81
95
|
];
|
|
82
96
|
}
|
|
83
97
|
/** 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. */
|
|
@@ -89,17 +103,89 @@ function antigravityServerFile(root, platform) {
|
|
|
89
103
|
return servers.rpg !== undefined ? undefined : { path, text: settingsText({ ...config, mcpServers: { ...servers, rpg: rpgServer(platform) } }) };
|
|
90
104
|
}
|
|
91
105
|
/**
|
|
92
|
-
* Antigravity's hooks for the campaign
|
|
93
|
-
* do (D-412), and asks for every other; the
|
|
106
|
+
* Antigravity's hooks for the campaign, under the key rpg, which is the engine's and is written again whenever it differs: before each tool, rpg --approve
|
|
107
|
+
* lets the rpg server's tools run without asking, as Claude Code's and Codex's settings do (D-412), and asks for every other; at the end of each turn, the
|
|
108
|
+
* doorbell (D-578). The player's own hooks stay beside them.
|
|
94
109
|
*/
|
|
95
110
|
function antigravityHooksFile(root) {
|
|
96
111
|
const path = join(root, ".agents", "hooks.json");
|
|
97
112
|
const text = files().fresh(path);
|
|
98
113
|
const hooks = text === undefined ? {} : jsonObject(path, text, "Antigravity cannot be set up for the game in it");
|
|
99
|
-
|
|
114
|
+
const rpg = { PreToolUse: [{ matcher: ".*", hooks: [approveHook] }], Stop: [antigravityBellHook] };
|
|
115
|
+
return JSON.stringify(hooks.rpg) === JSON.stringify(rpg) ? undefined : { path, text: settingsText({ ...hooks, rpg }) };
|
|
100
116
|
}
|
|
101
117
|
// Antigravity's hook that approves the rpg server's tools: it answers in about a second, as the hooks of a chat must.
|
|
102
118
|
const approveHook = { type: "command", command: "rpg --approve", timeout: 10 };
|
|
119
|
+
// Antigravity's Stop hook for the doorbell: it holds the turn's end until the player acts on the dashboard, writes in the chat or stops it; a day at most.
|
|
120
|
+
const antigravityBellHook = { type: "command", command: "rpg --listen antigravity", timeout: 86_400 };
|
|
121
|
+
/**
|
|
122
|
+
* OpenCode's settings for the campaign: the rpg server beside the player's own, in OpenCode's format, keeping what the player set on it, as its environment.
|
|
123
|
+
* Its tools need no permission: OpenCode's agent allows every tool unless told otherwise. The agent's own writing and editing of files is denied, and its
|
|
124
|
+
* shell asks, so that the master writes the campaign only through the rpg tools, as for Gemini CLI (D-362); a permission the player set stays theirs.
|
|
125
|
+
*/
|
|
126
|
+
function openCodeConfigFile(root, platform) {
|
|
127
|
+
const path = join(root, "opencode.json");
|
|
128
|
+
const text = files().fresh(path);
|
|
129
|
+
const config = text === undefined ? {} : jsonObject(path, text, "OpenCode cannot be set up for the game in it");
|
|
130
|
+
const mcp = isObject(config.mcp) ? config.mcp : {};
|
|
131
|
+
const servers = isObject(mcp.servers) ? mcp.servers : {};
|
|
132
|
+
const before = isObject(servers.rpg) ? servers.rpg : {};
|
|
133
|
+
const { command, args } = rpgServer(platform);
|
|
134
|
+
const rpg = { ...before, type: "local", command: [command, ...args] };
|
|
135
|
+
// OpenCode's tools that write or edit a file, a patch too, all ask for edit; its shell writes files as well, and asks the player each time.
|
|
136
|
+
const permission = config.permission === undefined ? openCodePermission : isObject(config.permission) ? { ...openCodePermission, ...config.permission } : config.permission;
|
|
137
|
+
const wanted = { ...config, permission, mcp: { ...mcp, servers: { ...servers, rpg } } };
|
|
138
|
+
return text !== undefined && JSON.stringify(wanted) === JSON.stringify(config) ? undefined : { path, text: settingsText(wanted) };
|
|
139
|
+
}
|
|
140
|
+
// What OpenCode's agent may do by itself in a campaign, where the player set nothing: no writing of files, and the shell only on the player's yes.
|
|
141
|
+
const openCodePermission = { edit: "deny", shell: "ask" };
|
|
142
|
+
/**
|
|
143
|
+
* The engine's plugin for OpenCode, which runs no hooks of its own: on OpenCode's events it runs the doorbell after each turn, and sends its line to the
|
|
144
|
+
* chat (D-578). Its source is in the package, under a name no host reads there; written again whenever it differs.
|
|
145
|
+
*/
|
|
146
|
+
function openCodePluginFile(root) {
|
|
147
|
+
const path = join(root, ".opencode", "plugins", "rpg.js");
|
|
148
|
+
openCodePlugin ??= readFileSync(new URL("../../plugins/opencode.js", import.meta.url), "utf8");
|
|
149
|
+
return files().fresh(path) === openCodePlugin ? undefined : { path, text: openCodePlugin };
|
|
150
|
+
}
|
|
151
|
+
let openCodePlugin;
|
|
152
|
+
/**
|
|
153
|
+
* Brings up to date the engine's files outside any campaign, in the player's home: Antigravity's own servers, which its app reads for every folder (D-578),
|
|
154
|
+
* when Antigravity is installed. What could not be written, with how to fix it; undefined when all is in order.
|
|
155
|
+
*/
|
|
156
|
+
export function refreshUserHostFiles(userHome, platform) {
|
|
157
|
+
try {
|
|
158
|
+
const file = antigravityInstalled(userHome, platform) ? antigravityAppFile(userHome, platform) : undefined;
|
|
159
|
+
if (file !== undefined) {
|
|
160
|
+
writeHostFile(file);
|
|
161
|
+
}
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
return error instanceof Error ? error.message : String(error);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** Whether Antigravity is installed for the player: its app's folder or its command line's in the home, or its program. */
|
|
169
|
+
function antigravityInstalled(userHome, platform) {
|
|
170
|
+
const program = platform === "win32" ? join(userHome, "AppData", "Local", "agy", "bin", "agy.exe") : join(userHome, ".local", "bin", "agy");
|
|
171
|
+
return [join(userHome, ".gemini", "antigravity"), join(userHome, ".gemini", "antigravity-cli"), program].some((path) => existsSync(path));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Antigravity's own servers, which its app starts for every folder: the rpg server beside the player's, keeping what they set on it, as disabled tools or its
|
|
175
|
+
* environment; outside a campaign it routes each conversation to the campaign it plays (D-578). An empty file holds no servers.
|
|
176
|
+
*/
|
|
177
|
+
function antigravityAppFile(userHome, platform) {
|
|
178
|
+
const path = join(userHome, ".gemini", "config", "mcp_config.json");
|
|
179
|
+
if (existsSync(path) && !statSync(path).isFile()) {
|
|
180
|
+
throw new Error(`${path} is a folder, not Antigravity's settings, so its app cannot be set up for the game: take it away, then run rpg init in the campaign again.`);
|
|
181
|
+
}
|
|
182
|
+
const text = files().fresh(path);
|
|
183
|
+
const config = text === undefined || text.trim() === "" ? {} : jsonObject(path, text, "Antigravity's app cannot be set up for the game", "run rpg init in the campaign again");
|
|
184
|
+
const servers = isObject(config.mcpServers) ? config.mcpServers : {};
|
|
185
|
+
const before = isObject(servers.rpg) ? servers.rpg : {};
|
|
186
|
+
const wanted = settingsText({ ...config, mcpServers: { ...servers, rpg: { ...before, ...rpgServer(platform) } } });
|
|
187
|
+
return text === wanted ? undefined : { path, text: wanted };
|
|
188
|
+
}
|
|
103
189
|
/** The master's effort the player chose (D-462), for each host's file; undefined when unset, and what the files hold stays. */
|
|
104
190
|
function chosenEffort(root) {
|
|
105
191
|
const effort = readTextSetting(root, "effort");
|
|
@@ -145,6 +231,37 @@ function characterAgentFile(root, instructions) {
|
|
|
145
231
|
].join("\n");
|
|
146
232
|
return files().fresh(path)?.replace(/\r\n/g, "\n") === text ? undefined : { path, text };
|
|
147
233
|
}
|
|
234
|
+
function openCodeAgentPath(root) {
|
|
235
|
+
return join(root, ".opencode", "agents", "rpg-character.md");
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* The character agent as an OpenCode subagent (D-490), as Claude Code's is written and taken away: every tool denied but execute and the rpg server's view,
|
|
239
|
+
* which OpenCode's subagents reach through execute, as Elena's probe proved it.
|
|
240
|
+
*/
|
|
241
|
+
function openCodeAgentFile(root, instructions) {
|
|
242
|
+
const path = openCodeAgentPath(root);
|
|
243
|
+
if (readTextSetting(root, "voices") === "master") {
|
|
244
|
+
return files().fresh(path) === undefined ? undefined : { path };
|
|
245
|
+
}
|
|
246
|
+
const rule = (action, effect) => [` - action: "${action}"`, ' resource: "*"', ` effect: ${effect}`];
|
|
247
|
+
const text = [
|
|
248
|
+
"---",
|
|
249
|
+
"# Written by rpg, which writes it again as the game starts: a change made here does not last.",
|
|
250
|
+
"description: Voices one character of the campaign at a key moment, knowing only what they know. Begin with their name, then the moment, as Voices says.",
|
|
251
|
+
"mode: subagent",
|
|
252
|
+
"permissions:",
|
|
253
|
+
...rule("*", "deny"),
|
|
254
|
+
...rule("execute", "allow"),
|
|
255
|
+
...rule("rpg_view", "allow"),
|
|
256
|
+
"---",
|
|
257
|
+
"",
|
|
258
|
+
instructions,
|
|
259
|
+
"",
|
|
260
|
+
'Your tool: tools.rpg.view, called through execute, as await tools.rpg.view({ as: "your name" }).',
|
|
261
|
+
"",
|
|
262
|
+
].join("\n");
|
|
263
|
+
return files().fresh(path)?.replace(/\r\n/g, "\n") === text ? undefined : { path, text };
|
|
264
|
+
}
|
|
148
265
|
/** CLAUDE.md, which Claude Code reads, importing AGENTS.md: added first to one that does not. */
|
|
149
266
|
function claudeFile(root) {
|
|
150
267
|
const path = join(root, "CLAUDE.md");
|
|
@@ -202,7 +319,10 @@ function codexConfigFile(root, platform, effort = chosenEffort(root)) {
|
|
|
202
319
|
const text = effort === undefined ? hidden : withTopKey(hidden, "model_reasoning_effort", effort === "app" ? undefined : JSON.stringify(effort));
|
|
203
320
|
const server = rpgServer(platform);
|
|
204
321
|
const tables = [
|
|
205
|
-
[
|
|
322
|
+
[
|
|
323
|
+
"mcp_servers.rpg",
|
|
324
|
+
`command = ${JSON.stringify(server.command)}\nargs = [${server.args.map((arg) => JSON.stringify(arg)).join(", ")}]\ntool_timeout_sec = 1800\ndefault_tools_approval_mode = "approve"\nenv_vars = ["CODEX_HOME", "SSH_AUTH_SOCK", "HTTPS_PROXY", "HTTP_PROXY", "NO_PROXY", "https_proxy", "http_proxy", "no_proxy"]`,
|
|
325
|
+
],
|
|
206
326
|
["memories", "generate_memories = false\nuse_memories = false"],
|
|
207
327
|
];
|
|
208
328
|
// A table's header with a comment after it is that table all the same.
|
|
@@ -226,8 +346,8 @@ function withTopKey(text, key, value) {
|
|
|
226
346
|
const joined = [head, rest.join("\n")].filter((part) => part.trim() !== "").join("\n\n");
|
|
227
347
|
return joined.trimEnd() === plain.trimEnd() ? text : joined;
|
|
228
348
|
}
|
|
229
|
-
/** A host's settings file read as a JSON object; refused, with how to fix it
|
|
230
|
-
function jsonObject(path, text, cannot) {
|
|
349
|
+
/** A host's settings file read as a JSON object; refused, with how to fix it and what to do `then`, when it is not one. */
|
|
350
|
+
function jsonObject(path, text, cannot, then = "try again") {
|
|
231
351
|
let settings;
|
|
232
352
|
try {
|
|
233
353
|
settings = JSON.parse(text.replace(/^\uFEFF/, ""));
|
|
@@ -236,7 +356,7 @@ function jsonObject(path, text, cannot) {
|
|
|
236
356
|
settings = undefined;
|
|
237
357
|
}
|
|
238
358
|
if (!isObject(settings)) {
|
|
239
|
-
throw new Error(`${path} is not valid JSON, so ${cannot}. Fix it or remove it by hand, then
|
|
359
|
+
throw new Error(`${path} is not valid JSON, so ${cannot}. Fix it or remove it by hand, then ${then}.`);
|
|
240
360
|
}
|
|
241
361
|
return settings;
|
|
242
362
|
}
|
package/dist/campaign/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { type ChoiceItem, type ChoiceSet, type PickRange, pickText, readChoices, readPick, writeChoices } from "./choices.ts";
|
|
2
|
-
export { createCampaign } from "./create-campaign.ts";
|
|
2
|
+
export { createCampaign, updateHostFiles } from "./create-campaign.ts";
|
|
3
3
|
export { bookFolderName, campaignFileName, findCampaign, houseRulesFolderName, inboxFolderName, requireCampaign, sessionsFolderName } from "./find-campaign.ts";
|
|
4
|
-
export { hasCharacterAgent, hostFileNames, refreshHostFiles, writeEffortFiles } from "./host-files.ts";
|
|
4
|
+
export { hasCharacterAgent, hostFileNames, refreshHostFiles, refreshUserHostFiles, 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 {
|
|
7
|
+
export { portFileName, savedPort, savePort } from "./port.ts";
|
|
8
|
+
export { type CampaignSettings, changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, characterWays, checkSettingName, checkSettings, chosenPictureMaker, clearSetting, closedSettings, companionWays, diceWays, efforts, entrySettingNames, gitIncludeWays, gitWays, 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
9
|
export { type CampaignState, changeState, changeStateAt, readState, readStateValues } from "./state.ts";
|
package/dist/campaign/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
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
|
-
export { createCampaign } from "./create-campaign.js";
|
|
3
|
+
export { createCampaign, updateHostFiles } from "./create-campaign.js";
|
|
4
4
|
export { bookFolderName, campaignFileName, findCampaign, houseRulesFolderName, inboxFolderName, requireCampaign, sessionsFolderName } from "./find-campaign.js";
|
|
5
|
-
export { hasCharacterAgent, hostFileNames, refreshHostFiles, writeEffortFiles } from "./host-files.js";
|
|
5
|
+
export { hasCharacterAgent, hostFileNames, refreshHostFiles, refreshUserHostFiles, 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 {
|
|
8
|
+
export { portFileName, savedPort, savePort } from "./port.js";
|
|
9
|
+
export { changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, characterWays, checkSettingName, checkSettings, chosenPictureMaker, clearSetting, closedSettings, companionWays, diceWays, efforts, entrySettingNames, gitIncludeWays, gitWays, 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
10
|
export { changeState, changeStateAt, readState, readStateValues } from "./state.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The file that keeps the port of the campaign's page, in its folder: this computer's, which the engine's .gitignore leaves out. */
|
|
2
|
+
export declare const portFileName = ".dashboard-port";
|
|
3
|
+
/** The port kept for the campaign's page; undefined when none is, or one that is no port. */
|
|
4
|
+
export declare function savedPort(root: string): number | undefined;
|
|
5
|
+
/** Keeps the port of the campaign's page; nothing when it cannot be written, as the page works all the same and the next chat chooses again. */
|
|
6
|
+
export declare function savePort(root: string, port: number): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The port of the campaign's page on this computer (D-577): chosen once, kept in a file of the campaign's own that git leaves out, so that it moves with
|
|
2
|
+
// the folder and never to another computer, and changed only when another program or campaign holds it.
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { files } from "../core/store.js";
|
|
5
|
+
/** The file that keeps the port of the campaign's page, in its folder: this computer's, which the engine's .gitignore leaves out. */
|
|
6
|
+
export const portFileName = ".dashboard-port";
|
|
7
|
+
/** The port kept for the campaign's page; undefined when none is, or one that is no port. */
|
|
8
|
+
export function savedPort(root) {
|
|
9
|
+
const text = files().text(join(root, portFileName))?.trim() ?? "";
|
|
10
|
+
const port = /^\d+$/.test(text) ? Number(text) : Number.NaN;
|
|
11
|
+
return Number.isInteger(port) && port > 0 && port < 65536 ? port : undefined;
|
|
12
|
+
}
|
|
13
|
+
/** Keeps the port of the campaign's page; nothing when it cannot be written, as the page works all the same and the next chat chooses again. */
|
|
14
|
+
export function savePort(root, port) {
|
|
15
|
+
if (savedPort(root) === port) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
files().write(join(root, portFileName), `${port}\n`);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// A folder that cannot be written keeps no port.
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -6,6 +6,10 @@ import { type CountedByGame } from "./levels.ts";
|
|
|
6
6
|
export declare const lethalities: readonly ["narrative", "epic", "dice"];
|
|
7
7
|
/** When the game may go back (D-55): never, to the last end of a scene once the player character dies, or to any save, which the player may also ask for. */
|
|
8
8
|
export declare const saveModes: readonly ["permadeath", "checkpoint", "free"];
|
|
9
|
+
/** What the engine does with git in a campaign that is a repository (D-576): nothing, a commit at each session's start, save and end of a scene, or a push too. */
|
|
10
|
+
export declare const gitWays: readonly ["off", "commit", "push"];
|
|
11
|
+
/** Whether the saves or the chats go into the campaign's repository (D-576): left out, as when unset, or in. */
|
|
12
|
+
export declare const gitIncludeWays: readonly ["out", "in"];
|
|
9
13
|
/**
|
|
10
14
|
* What the chosen difficulty, rigor or mentor means, as status and config give it, the rigor with what the game counts itself, a custom one with the levels of
|
|
11
15
|
* its items as custom-difficulty or custom-rigor writes them (T-132); undefined for another setting or a value it does not take.
|
|
@@ -242,6 +246,19 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
242
246
|
precedents: z.ZodOptional<z.ZodNullable<z.ZodPreprocess<z.ZodArray<z.ZodPreprocess<z.ZodString, unknown>>, unknown>>>;
|
|
243
247
|
learned: z.ZodOptional<z.ZodNullable<z.ZodPreprocess<z.ZodArray<z.ZodPreprocess<z.ZodString, unknown>>, unknown>>>;
|
|
244
248
|
library: z.ZodOptional<z.ZodNullable<z.ZodPreprocess<z.ZodArray<z.ZodPreprocess<z.ZodString, unknown>>, unknown>>>;
|
|
249
|
+
git: z.ZodOptional<z.ZodEnum<{
|
|
250
|
+
push: "push";
|
|
251
|
+
off: "off";
|
|
252
|
+
commit: "commit";
|
|
253
|
+
}>>;
|
|
254
|
+
"git-saves": z.ZodOptional<z.ZodEnum<{
|
|
255
|
+
out: "out";
|
|
256
|
+
in: "in";
|
|
257
|
+
}>>;
|
|
258
|
+
"git-sessions": z.ZodOptional<z.ZodEnum<{
|
|
259
|
+
out: "out";
|
|
260
|
+
in: "in";
|
|
261
|
+
}>>;
|
|
245
262
|
coins: z.ZodOptional<z.ZodUnknown>;
|
|
246
263
|
calendar: z.ZodOptional<z.ZodUnknown>;
|
|
247
264
|
fields: z.ZodOptional<z.ZodUnknown>;
|
|
@@ -12,6 +12,10 @@ const settingsHold = 'settings, such as "name: ..."';
|
|
|
12
12
|
export const lethalities = ["narrative", "epic", "dice"];
|
|
13
13
|
/** When the game may go back (D-55): never, to the last end of a scene once the player character dies, or to any save, which the player may also ask for. */
|
|
14
14
|
export const saveModes = ["permadeath", "checkpoint", "free"];
|
|
15
|
+
/** What the engine does with git in a campaign that is a repository (D-576): nothing, a commit at each session's start, save and end of a scene, or a push too. */
|
|
16
|
+
export const gitWays = ["off", "commit", "push"];
|
|
17
|
+
/** Whether the saves or the chats go into the campaign's repository (D-576): left out, as when unset, or in. */
|
|
18
|
+
export const gitIncludeWays = ["out", "in"];
|
|
15
19
|
/**
|
|
16
20
|
* What the chosen difficulty, rigor or mentor means, as status and config give it, the rigor with what the game counts itself, a custom one with the levels of
|
|
17
21
|
* its items as custom-difficulty or custom-rigor writes them (T-132); undefined for another setting or a value it does not take.
|
|
@@ -404,6 +408,10 @@ export const settingsSchema = z.object({
|
|
|
404
408
|
precedents: listSetting.describe("the rulings made without the text, each starting with the name of the rule in the system's language: Poisoned: …"),
|
|
405
409
|
learned: listSetting.describe("the game's mechanics the master has explained, by their names in the system's language: explained again only when the player gets one wrong"),
|
|
406
410
|
library: listSetting.describe("the player's library (D-491): folders of their books, or books, by full path, which rules searches after the game system"),
|
|
411
|
+
git: z.enum(gitWays).optional().describe("what rpg does with git where the campaign's folder is a repository: off (unset, nothing), commit (a commit at the start of each session, at each save and each end of a scene) "
|
|
412
|
+
+ "or push (a commit, then a push)"),
|
|
413
|
+
"git-saves": z.enum(gitIncludeWays).optional().describe("whether the saves' zips go into the campaign's repository: out (unset) or in"),
|
|
414
|
+
"git-sessions": z.enum(gitIncludeWays).optional().describe("whether the chats kept as text, all the player wrote, go into the campaign's repository: out (unset) or in, for a private one"),
|
|
407
415
|
// Checked by the money module (MON-1): coins written wrongly by hand must not stop the other settings from being read.
|
|
408
416
|
coins: z.unknown().optional().describe("the coins, for a game with money: each with its value in the smallest coin, such as gp 100, sp 10, cp 1"),
|
|
409
417
|
// Checked by the time module (TIM-8): a mistake there never stops the game, whose date stays day N.
|
|
@@ -443,7 +451,22 @@ const premiseSettingNames = ["premise", "preparation", "length"];
|
|
|
443
451
|
// 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).
|
|
444
452
|
// How the master writes: the core's own until the player chooses (D-395).
|
|
445
453
|
const styleSettingNames = ["prose", "story", "author", "style"];
|
|
446
|
-
const optionalSettingNames = [
|
|
454
|
+
const optionalSettingNames = [
|
|
455
|
+
"coins",
|
|
456
|
+
"pictures",
|
|
457
|
+
"effort",
|
|
458
|
+
"voices",
|
|
459
|
+
"calendar",
|
|
460
|
+
"calendar-start",
|
|
461
|
+
"between-sessions",
|
|
462
|
+
"git",
|
|
463
|
+
"git-saves",
|
|
464
|
+
"git-sessions",
|
|
465
|
+
...entrySettingNames,
|
|
466
|
+
...setupSettingNames,
|
|
467
|
+
...premiseSettingNames,
|
|
468
|
+
...styleSettingNames,
|
|
469
|
+
];
|
|
447
470
|
/** The YAML list of a list setting, edited in place so that its comments stay; created when missing. */
|
|
448
471
|
function listNode(document, setting) {
|
|
449
472
|
const node = document.get(setting, true);
|