rpg-engine 0.22.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.
Files changed (119) hide show
  1. package/README.md +5 -5
  2. package/dist/campaign/create-campaign.d.ts +5 -0
  3. package/dist/campaign/create-campaign.js +40 -12
  4. package/dist/campaign/find-campaign.d.ts +5 -0
  5. package/dist/campaign/find-campaign.js +10 -5
  6. package/dist/campaign/host-files.d.ts +15 -4
  7. package/dist/campaign/host-files.js +130 -13
  8. package/dist/campaign/index.d.ts +2 -2
  9. package/dist/campaign/index.js +2 -2
  10. package/dist/cli/cli.js +18 -6
  11. package/dist/commands/config/dashboard.js +6 -1
  12. package/dist/commands/config/words.js +1 -1
  13. package/dist/commands/image.d.ts +3 -0
  14. package/dist/commands/image.js +31 -4
  15. package/dist/commands/import/import.d.ts +1 -1
  16. package/dist/commands/import/import.js +5 -0
  17. package/dist/commands/init.d.ts +2 -0
  18. package/dist/commands/init.js +21 -3
  19. package/dist/commands/shared/campaign/git.js +1 -1
  20. package/dist/commands/shared/campaign/images.js +5 -3
  21. package/dist/commands/shared/characters/voices.d.ts +2 -2
  22. package/dist/commands/shared/characters/voices.js +8 -5
  23. package/dist/core/context.d.ts +15 -6
  24. package/dist/core/context.js +2 -1
  25. package/dist/dashboard/guide/ar.md +7 -4
  26. package/dist/dashboard/guide/cs.md +6 -3
  27. package/dist/dashboard/guide/da.md +6 -3
  28. package/dist/dashboard/guide/de.md +6 -3
  29. package/dist/dashboard/guide/el.md +6 -3
  30. package/dist/dashboard/guide/en.md +5 -2
  31. package/dist/dashboard/guide/es.md +6 -3
  32. package/dist/dashboard/guide/fi.md +6 -3
  33. package/dist/dashboard/guide/fr.md +7 -4
  34. package/dist/dashboard/guide/he.md +6 -3
  35. package/dist/dashboard/guide/hi.md +6 -3
  36. package/dist/dashboard/guide/hu.md +6 -3
  37. package/dist/dashboard/guide/is.md +6 -3
  38. package/dist/dashboard/guide/it.md +37 -34
  39. package/dist/dashboard/guide/ja.md +6 -3
  40. package/dist/dashboard/guide/ko.md +6 -3
  41. package/dist/dashboard/guide/nb.md +6 -3
  42. package/dist/dashboard/guide/nl.md +8 -5
  43. package/dist/dashboard/guide/pl.md +6 -3
  44. package/dist/dashboard/guide/pt.md +6 -3
  45. package/dist/dashboard/guide/ro.md +6 -3
  46. package/dist/dashboard/guide/ru.md +7 -4
  47. package/dist/dashboard/guide/sv.md +6 -3
  48. package/dist/dashboard/guide/tr.md +7 -4
  49. package/dist/dashboard/guide/uk.md +7 -4
  50. package/dist/dashboard/guide/zh.md +6 -3
  51. package/dist/dashboard/i18n/ar.json +5 -2
  52. package/dist/dashboard/i18n/cs.json +5 -2
  53. package/dist/dashboard/i18n/da.json +5 -2
  54. package/dist/dashboard/i18n/de.json +5 -2
  55. package/dist/dashboard/i18n/el.json +5 -2
  56. package/dist/dashboard/i18n/es.json +5 -2
  57. package/dist/dashboard/i18n/fi.json +5 -2
  58. package/dist/dashboard/i18n/fr.json +5 -2
  59. package/dist/dashboard/i18n/he.json +5 -2
  60. package/dist/dashboard/i18n/hi.json +5 -2
  61. package/dist/dashboard/i18n/hu.json +5 -2
  62. package/dist/dashboard/i18n/is.json +5 -2
  63. package/dist/dashboard/i18n/it.json +5 -2
  64. package/dist/dashboard/i18n/ja.json +5 -2
  65. package/dist/dashboard/i18n/ko.json +5 -2
  66. package/dist/dashboard/i18n/nb.json +5 -2
  67. package/dist/dashboard/i18n/nl.json +5 -2
  68. package/dist/dashboard/i18n/pl.json +5 -2
  69. package/dist/dashboard/i18n/pt.json +5 -2
  70. package/dist/dashboard/i18n/ro.json +5 -2
  71. package/dist/dashboard/i18n/ru.json +5 -2
  72. package/dist/dashboard/i18n/sv.json +5 -2
  73. package/dist/dashboard/i18n/tr.json +5 -2
  74. package/dist/dashboard/i18n/uk.json +5 -2
  75. package/dist/dashboard/i18n/zh.json +5 -2
  76. package/dist/dashboard/parts/labels.js +1 -1
  77. package/dist/dashboard/settings/settings.js +13 -4
  78. package/dist/dashboard/shell/notices.js +1 -1
  79. package/dist/dashboard/style.css +15 -7
  80. package/dist/helpers/briefs.d.ts +4 -0
  81. package/dist/helpers/briefs.js +13 -0
  82. package/dist/helpers/chosen.d.ts +8 -4
  83. package/dist/helpers/chosen.js +38 -14
  84. package/dist/helpers/index.d.ts +3 -2
  85. package/dist/helpers/index.js +5 -3
  86. package/dist/helpers/opencode.d.ts +13 -0
  87. package/dist/helpers/opencode.js +202 -0
  88. package/dist/instructions/index.d.ts +2 -2
  89. package/dist/instructions/index.js +3 -3
  90. package/dist/server/approver.d.ts +4 -2
  91. package/dist/server/approver.js +27 -7
  92. package/dist/server/bell/antigravity.d.ts +10 -0
  93. package/dist/server/bell/antigravity.js +95 -0
  94. package/dist/server/bell/index.d.ts +2 -0
  95. package/dist/server/bell/index.js +2 -0
  96. package/dist/server/bell/listener.d.ts +43 -0
  97. package/dist/server/bell/listener.js +149 -0
  98. package/dist/server/dashboard/index.d.ts +10 -1
  99. package/dist/server/dashboard/index.js +6 -1
  100. package/dist/server/dashboard/news.d.ts +3 -1
  101. package/dist/server/dashboard/news.js +64 -10
  102. package/dist/server/mcp.d.ts +3 -2
  103. package/dist/server/mcp.js +11 -7
  104. package/dist/server/player-acts.d.ts +21 -1
  105. package/dist/server/player-acts.js +38 -2
  106. package/dist/server/route/front.d.ts +3 -0
  107. package/dist/server/route/front.js +97 -0
  108. package/dist/server/route/index.d.ts +3 -0
  109. package/dist/server/route/index.js +3 -0
  110. package/dist/server/route/notes.d.ts +8 -0
  111. package/dist/server/route/notes.js +50 -0
  112. package/dist/server/route/router.d.ts +31 -0
  113. package/dist/server/route/router.js +215 -0
  114. package/instructions/start.md +1 -1
  115. package/instructions/voices-opencode.md +1 -0
  116. package/package.json +3 -2
  117. package/plugins/opencode.js +174 -0
  118. package/dist/server/bell-listener.d.ts +0 -10
  119. package/dist/server/bell-listener.js +0 -52
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 simpler ones.
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 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
+ **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 **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
+ 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 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; 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
- const mcpConfig = mcpConfigWithRpg(root, platform);
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
- let config = {};
35
- if (files().exists(path)) {
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
- return { ...config, mcpServers: { ...config.mcpServers, rpg: rpgServer(platform) } };
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
- refuseLinksOut(root);
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", ".claude", ".codex", layersFolder];
41
- /** 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. */
42
- function refuseLinksOut(root) {
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
- /** 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. */
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 its host files, it says whether
31
- * the chat found the agent, as Claude Code reads its agents only when a chat starts.
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 hasCharacterAgent(root: string): boolean;
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). Gemini CLI is no
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
- /** 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. */
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 its host files, it says whether
67
- * the chat found the agent, as Claude Code reads its agents only when a chat starts.
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: 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.
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
- return hooks.rpg !== undefined ? undefined : { path, text: settingsText({ ...hooks, rpg: { PreToolUse: [{ matcher: ".*", hooks: [approveHook] }] } }) };
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");
@@ -229,8 +346,8 @@ function withTopKey(text, key, value) {
229
346
  const joined = [head, rest.join("\n")].filter((part) => part.trim() !== "").join("\n\n");
230
347
  return joined.trimEnd() === plain.trimEnd() ? text : joined;
231
348
  }
232
- /** A host's settings file read as a JSON object; refused, with how to fix it, when it is not one. */
233
- 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") {
234
351
  let settings;
235
352
  try {
236
353
  settings = JSON.parse(text.replace(/^\uFEFF/, ""));
@@ -239,7 +356,7 @@ function jsonObject(path, text, cannot) {
239
356
  settings = undefined;
240
357
  }
241
358
  if (!isObject(settings)) {
242
- throw new Error(`${path} is not valid JSON, so ${cannot}. Fix it or remove it by hand, then try again.`);
359
+ throw new Error(`${path} is not valid JSON, so ${cannot}. Fix it or remove it by hand, then ${then}.`);
243
360
  }
244
361
  return settings;
245
362
  }
@@ -1,7 +1,7 @@
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
7
  export { portFileName, savedPort, savePort } from "./port.ts";
@@ -1,8 +1,8 @@
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
8
  export { portFileName, savedPort, savePort } from "./port.js";
package/dist/cli/cli.js CHANGED
@@ -2,20 +2,32 @@
2
2
  import { runCommandLine } from "./command-line.js";
3
3
  const args = process.argv.slice(2);
4
4
  // "rpg mcp" turns the process into a server for an AI host; "rpg --read-library" reads the player's books apart, as rules starts it (LIB-3); "rpg --listen"
5
- // is Claude Code's doorbell for the player's sentences on the dashboard (D-495); "rpg --approve" is Antigravity's hook that lets the rpg tools run; everything
6
- // else is a command.
5
+ // is the doorbell for the player's sentences on the dashboard (D-495), Claude Code's, or with its host's name another's (D-578); "rpg --approve" is
6
+ // Antigravity's hook that lets the rpg tools run; everything else is a command.
7
7
  if (args.length === 1 && args[0] === "mcp") {
8
8
  // The server and its SDK load only here: every other command starts faster without them (D-194).
9
9
  const { startMcpServer } = await import("../server/mcp.js");
10
- await startMcpServer();
10
+ const { serverInput } = await import("../server/route/index.js");
11
+ // Outside a campaign the router serves (D-578), through children, for Antigravity's app; in one, the server as always.
12
+ const input = serverInput();
13
+ if (input !== undefined) {
14
+ await startMcpServer(input);
15
+ }
11
16
  }
12
17
  else if (args[0] === "--read-library") {
13
18
  const { readLibraryHere } = await import("../commands/shared/books/library-reader.js");
14
19
  await readLibraryHere();
15
20
  }
16
- else if (args.length === 1 && args[0] === "--listen") {
17
- const { listenHere } = await import("../server/bell-listener.js");
18
- await listenHere();
21
+ else if (args[0] === "--listen" && args.length <= 2) {
22
+ const { listen, listeningHosts } = await import("../server/bell/index.js");
23
+ const host = listeningHosts.find((one) => one === (args[1] ?? "claude"));
24
+ if (host === undefined) {
25
+ console.error(`rpg --listen does not know the host ${args[1]}: give one of ${listeningHosts.join(", ")}, or none for Claude Code.`);
26
+ process.exitCode = 1;
27
+ }
28
+ else {
29
+ await listen(host);
30
+ }
19
31
  }
20
32
  else if (args.length === 1 && args[0] === "--approve") {
21
33
  const { approveHere } = await import("../server/approver.js");
@@ -188,6 +188,8 @@ const madeBy = {
188
188
  Claude: "Claude draws them on this computer, as vector pictures, from your Claude plan.",
189
189
  Antigravity: "Antigravity makes them in your chat, from your Google plan.",
190
190
  };
191
+ // The chat in use draws them itself, as OpenCode (D-572).
192
+ const drawnInChat = "{maker} draws them in your chat, as simple vector pictures, from your plan.";
191
193
  // The master makes them with an image tool of its own, as ElevenLabs's (D-572).
192
194
  const madeWithTool = "The master makes them with {tool}.";
193
195
  const toolAsked = "The master asks you in the chat which tool to use.";
@@ -197,7 +199,7 @@ const madeMeanwhile = "{by} makes them meanwhile.";
197
199
  // Whoever makes them, the player may give a page a picture of their own (D-572 (3)).
198
200
  const ownPicture = "You can also give a page you see a picture of your own: with its picture button, or dropped in the campaign's inbox folder for the master.";
199
201
  /** Every note the pictures' setting may have, which the dashboard writes in its language (D-394). */
200
- export const picturesNotes = [...Object.values(madeBy), madeWithTool, toolAsked, refusedNote, madeMeanwhile, ownPicture, ...[...Object.values(codexSays), ...Object.values(claudeSays)].map(notReadyText)];
202
+ export const picturesNotes = [...Object.values(madeBy), drawnInChat, madeWithTool, toolAsked, refusedNote, madeMeanwhile, ownPicture, ...[...Object.values(codexSays), ...Object.values(claudeSays)].map(notReadyText)];
201
203
  /**
202
204
  * Whether this computer makes pictures, and with whose plan, in the player's words (D-308, D-390); why not and how to have them; where the maker the player
203
205
  * chose made none and the chat in use makes them, why (D-572); nothing where no maker is asked.
@@ -222,6 +224,9 @@ function picturesReadyNote(context) {
222
224
  if (ready.askTool === true) {
223
225
  return { note: { text: toolAsked } };
224
226
  }
227
+ if (ready.draws === true) {
228
+ return { note: { text: drawnInChat, values: { maker: ready.maker ?? "" } } };
229
+ }
225
230
  return { note: { text: madeBy[ready.maker === "Claude" || ready.maker === "Antigravity" ? ready.maker : "Codex"] } };
226
231
  }
227
232
  /** The pictures' note with the line that the player may give a picture of their own after it. */
@@ -153,7 +153,7 @@ export const playerWords = {
153
153
  about: "who makes the pictures",
154
154
  values: pictureMakers,
155
155
  means: {
156
- chat: "your AI app, by its own means: Claude draws them as vector pictures, Codex and Antigravity paint them, each from your plan",
156
+ chat: "your AI app, by its own means: Claude draws them as vector pictures, Codex and Antigravity paint them, OpenCode and the other apps draw simple vector pictures in the chat, each from your plan",
157
157
  codex: "Codex paints them on this computer, from your ChatGPT plan (Plus or higher)",
158
158
  elevenlabs: "the master makes them with ElevenLabs, connected to your AI app, from your ElevenLabs plan",
159
159
  other: "another image tool connected to your AI app: the master asks you which in the chat",
@@ -19,6 +19,8 @@ interface ImageResult {
19
19
  tool?: string;
20
20
  /** The player chose another image tool and has not named it yet: the master asks which (D-572). */
21
21
  askTool?: true;
22
+ /** The brief is the SVG one: the chat draws the picture itself and gives it with svg (D-572). */
23
+ draw?: true;
22
24
  /** Why the chat in use made it, or makes it, in place of the maker the player chose (D-572). */
23
25
  instead?: string;
24
26
  }
@@ -26,6 +28,7 @@ export declare const image: import("../core/registry.ts").Command<z.ZodObject<{
26
28
  page: z.ZodString;
27
29
  file: z.ZodOptional<z.ZodString>;
28
30
  url: z.ZodOptional<z.ZodString>;
31
+ svg: z.ZodOptional<z.ZodString>;
29
32
  describe: z.ZodOptional<z.ZodString>;
30
33
  }, z.core.$strip>, ImageResult>;
31
34
  /** Writes a picture into the campaign's images folder and links it in the page, logging it; `from` is the file it was read from, if any. */