rpg-engine 0.22.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/campaign/create-campaign.d.ts +6 -1
- package/dist/campaign/create-campaign.js +41 -13
- package/dist/campaign/find-campaign.d.ts +5 -0
- package/dist/campaign/find-campaign.js +20 -5
- package/dist/campaign/host-files.d.ts +14 -4
- package/dist/campaign/host-files.js +193 -36
- package/dist/campaign/index.d.ts +2 -2
- package/dist/campaign/index.js +2 -2
- package/dist/campaign/settings.d.ts +3 -3
- package/dist/campaign/settings.js +5 -4
- package/dist/cli/cli.js +28 -7
- package/dist/commands/config/config.js +1 -1
- package/dist/commands/config/dashboard.js +28 -6
- package/dist/commands/config/words.js +2 -1
- package/dist/commands/image.d.ts +3 -0
- package/dist/commands/image.js +32 -5
- package/dist/commands/import/import.d.ts +3 -1
- package/dist/commands/import/import.js +16 -3
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +21 -3
- package/dist/commands/instructions.js +1 -1
- package/dist/commands/shared/campaign/git.js +1 -1
- package/dist/commands/shared/campaign/images.js +6 -3
- package/dist/commands/shared/campaign/mode.js +1 -1
- package/dist/commands/shared/characters/voices.d.ts +2 -2
- package/dist/commands/shared/characters/voices.js +9 -6
- package/dist/commands/shared/sheet/sheet.d.ts +2 -2
- package/dist/commands/shared/sheet/sheet.js +3 -3
- package/dist/core/context.d.ts +21 -6
- package/dist/core/context.js +2 -1
- package/dist/dashboard/acts/acts.js +39 -11
- package/dist/dashboard/acts/head.js +7 -0
- package/dist/dashboard/acts/names.js +4 -2
- package/dist/dashboard/acts/sending.js +23 -22
- package/dist/dashboard/acts/sheet.js +7 -149
- package/dist/dashboard/acts/strip.js +10 -14
- package/dist/dashboard/acts/talk.js +51 -0
- package/dist/dashboard/acts/thing.js +169 -0
- package/dist/dashboard/app.js +3 -3
- package/dist/dashboard/guide/ar.md +17 -14
- package/dist/dashboard/guide/cs.md +15 -12
- package/dist/dashboard/guide/da.md +15 -12
- package/dist/dashboard/guide/de.md +14 -11
- package/dist/dashboard/guide/el.md +14 -11
- package/dist/dashboard/guide/en.md +13 -10
- package/dist/dashboard/guide/es.md +14 -11
- package/dist/dashboard/guide/fi.md +14 -11
- package/dist/dashboard/guide/fr.md +14 -11
- package/dist/dashboard/guide/he.md +14 -11
- package/dist/dashboard/guide/hi.md +14 -11
- package/dist/dashboard/guide/hu.md +14 -11
- package/dist/dashboard/guide/is.md +14 -11
- package/dist/dashboard/guide/it.md +57 -54
- package/dist/dashboard/guide/ja.md +14 -11
- package/dist/dashboard/guide/ko.md +15 -12
- package/dist/dashboard/guide/nb.md +14 -11
- package/dist/dashboard/guide/nl.md +16 -13
- package/dist/dashboard/guide/pl.md +14 -11
- package/dist/dashboard/guide/pt.md +14 -11
- package/dist/dashboard/guide/ro.md +15 -12
- package/dist/dashboard/guide/ru.md +14 -11
- package/dist/dashboard/guide/sv.md +15 -12
- package/dist/dashboard/guide/tr.md +15 -12
- package/dist/dashboard/guide/uk.md +15 -12
- package/dist/dashboard/guide/zh.md +15 -12
- package/dist/dashboard/i18n/ar.json +28 -11
- package/dist/dashboard/i18n/cs.json +28 -11
- package/dist/dashboard/i18n/da.json +28 -11
- package/dist/dashboard/i18n/de.json +28 -11
- package/dist/dashboard/i18n/el.json +28 -11
- package/dist/dashboard/i18n/es.json +28 -11
- package/dist/dashboard/i18n/fi.json +28 -11
- package/dist/dashboard/i18n/fr.json +28 -11
- package/dist/dashboard/i18n/he.json +28 -11
- package/dist/dashboard/i18n/hi.json +28 -11
- package/dist/dashboard/i18n/hu.json +28 -11
- package/dist/dashboard/i18n/is.json +28 -11
- package/dist/dashboard/i18n/it.json +104 -87
- package/dist/dashboard/i18n/ja.json +28 -11
- package/dist/dashboard/i18n/ko.json +28 -11
- package/dist/dashboard/i18n/nb.json +28 -11
- package/dist/dashboard/i18n/nl.json +28 -11
- package/dist/dashboard/i18n/pl.json +28 -11
- package/dist/dashboard/i18n/pt.json +28 -11
- package/dist/dashboard/i18n/ro.json +28 -11
- package/dist/dashboard/i18n/ru.json +28 -11
- package/dist/dashboard/i18n/sv.json +28 -11
- package/dist/dashboard/i18n/tr.json +28 -11
- package/dist/dashboard/i18n/uk.json +28 -11
- package/dist/dashboard/i18n/zh.json +28 -11
- package/dist/dashboard/packages/packages.js +1 -1
- package/dist/dashboard/parts/icons.js +2 -0
- package/dist/dashboard/parts/labels.js +2 -1
- package/dist/dashboard/parts/layout.js +34 -0
- package/dist/dashboard/parts/widgets.js +6 -2
- package/dist/dashboard/settings/language-choice.js +1 -1
- package/dist/dashboard/settings/settings.js +73 -39
- package/dist/dashboard/settings/tabs.js +14 -0
- package/dist/dashboard/sheet/sheet.js +54 -33
- package/dist/dashboard/shell/notices.js +2 -2
- package/dist/dashboard/style.css +135 -52
- package/dist/helpers/antigravity.d.ts +47 -0
- package/dist/helpers/antigravity.js +434 -0
- package/dist/helpers/briefs.d.ts +4 -0
- package/dist/helpers/briefs.js +13 -0
- package/dist/helpers/chosen.d.ts +15 -7
- package/dist/helpers/chosen.js +96 -45
- package/dist/helpers/index.d.ts +4 -2
- package/dist/helpers/index.js +6 -3
- package/dist/helpers/opencode.d.ts +13 -0
- package/dist/helpers/opencode.js +295 -0
- package/dist/helpers/programs.d.ts +8 -0
- package/dist/helpers/programs.js +35 -2
- package/dist/helpers/stop.d.ts +2 -0
- package/dist/helpers/stop.js +20 -1
- package/dist/helpers/svg.d.ts +4 -1
- package/dist/helpers/svg.js +16 -4
- package/dist/instructions/index.d.ts +4 -2
- package/dist/instructions/index.js +6 -3
- package/dist/server/approver.d.ts +4 -2
- package/dist/server/approver.js +27 -7
- package/dist/server/bell/antigravity.d.ts +15 -0
- package/dist/server/bell/antigravity.js +113 -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 +154 -0
- package/dist/server/dashboard/index.d.ts +10 -1
- package/dist/server/dashboard/index.js +6 -1
- package/dist/server/dashboard/news.d.ts +3 -1
- package/dist/server/dashboard/news.js +64 -10
- package/dist/server/fence.d.ts +21 -0
- package/dist/server/fence.js +69 -0
- package/dist/server/mcp.d.ts +3 -2
- package/dist/server/mcp.js +37 -7
- package/dist/server/player-acts.d.ts +21 -1
- package/dist/server/player-acts.js +39 -3
- 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/server/subagent.d.ts +4 -0
- package/dist/server/subagent.js +30 -0
- package/instructions/start.md +1 -1
- package/instructions/voices-antigravity.md +1 -0
- package/instructions/voices-codex.md +1 -0
- 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 -10
- package/dist/server/bell-listener.js +0 -52
package/dist/helpers/chosen.js
CHANGED
|
@@ -1,91 +1,115 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { antigravityPainter, antigravityReader, antigravityWriter } from "./antigravity.js";
|
|
2
|
+
import { antigravityBrief, chatBrief, drawnBrief } from "./briefs.js";
|
|
2
3
|
import { claudePictures, claudeReader, claudeWriter } from "./claude.js";
|
|
3
4
|
import { codexPictures, codexReader, codexWriter } from "./codex.js";
|
|
5
|
+
import { openCodeReader, openCodeWriter } from "./opencode.js";
|
|
4
6
|
/** The chat whose own pictures are Codex's, as its MCP client names itself. */
|
|
5
7
|
export const codexClient = "codex-mcp-client";
|
|
6
8
|
/** Antigravity's chat, as its MCP client names itself: it makes its pictures itself. */
|
|
7
9
|
export const antigravityClient = "antigravity-client";
|
|
10
|
+
/** OpenCode's chat, as its MCP client names itself: its master draws the pictures, and OpenCode does the work outside the chat there, and nowhere else (D-578 (3)). */
|
|
11
|
+
export const openCodeClient = "opencode";
|
|
8
12
|
/**
|
|
9
13
|
* The pictures of this computer, by the campaign's choice, which `choice` reads when a picture is asked: unset or chat, the chat `host` names, by its own
|
|
10
|
-
* means; codex
|
|
11
|
-
* in use; once it refused, it is not asked again while the
|
|
14
|
+
* means; codex or antigravity, a maker apart from the chat in use, or the chat's own in its own chat; elevenlabs, or the name of another image tool of the
|
|
15
|
+
* master's, from the brief. A maker apart, where it cannot or refuses, leaves the picture to the chat in use; once it refused, it is not asked again while the
|
|
16
|
+
* server lives, until the choice changes.
|
|
12
17
|
*/
|
|
13
|
-
export function hostPictures(host, choice = () => undefined, codex = codexPictures(), claude = claudePictures()) {
|
|
14
|
-
|
|
18
|
+
export function hostPictures(host, choice = () => undefined, codex = codexPictures(), claude = claudePictures(), antigravity = antigravityPainter()) {
|
|
19
|
+
// The makers the campaign may choose apart from the chat in use, by their values: each with its name, its own chat, and its refusal remembered.
|
|
20
|
+
const makersApart = {
|
|
21
|
+
[codexChoice]: { maker: codex, name: "Codex", chat: codexClient },
|
|
22
|
+
[antigravityChoice]: { maker: antigravity, name: "Antigravity", chat: antigravityClient },
|
|
23
|
+
};
|
|
15
24
|
let lastChoice;
|
|
16
|
-
// The chat in use, by its own means.
|
|
17
|
-
const chat = () =>
|
|
18
|
-
|
|
25
|
+
// The chat in use, by its own means: Claude's drawing in Claude Code, whose clients' names start with claude, and where no chat names itself.
|
|
26
|
+
const chat = () => {
|
|
27
|
+
const name = host() ?? "";
|
|
28
|
+
if (name === "" || name.toLowerCase().startsWith("claude")) {
|
|
29
|
+
return claude;
|
|
30
|
+
}
|
|
31
|
+
return name === codexClient ? codex : name === antigravityClient ? antigravityPictures : chatDrawing(chatNames[name] ?? name);
|
|
32
|
+
};
|
|
33
|
+
// The maker the campaign chose, and the maker apart it is, which leaves the picture to the chat in use where it cannot; in its own chat, the chat's own.
|
|
19
34
|
const chosen = () => {
|
|
20
35
|
const said = choice()?.trim();
|
|
21
|
-
// The player chose again:
|
|
36
|
+
// The player chose again: every maker apart is asked again.
|
|
22
37
|
if (said !== lastChoice) {
|
|
23
|
-
refused = undefined;
|
|
38
|
+
Object.values(makersApart).forEach((one) => (one.refused = undefined));
|
|
24
39
|
lastChoice = said;
|
|
25
40
|
}
|
|
26
41
|
const key = said?.toLowerCase();
|
|
27
42
|
if (key === undefined || key === "" || key === chatChoice) {
|
|
28
|
-
return { maker: chat()
|
|
43
|
+
return { maker: chat() };
|
|
29
44
|
}
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
const apart = makersApart[key];
|
|
46
|
+
if (apart !== undefined) {
|
|
47
|
+
return host() === apart.chat ? { maker: chat() } : { maker: apart.maker, apart };
|
|
32
48
|
}
|
|
33
|
-
return { maker: key === otherChoice ? unnamedTool : masterTool(key === elevenlabsChoice ? "ElevenLabs" : said ?? "")
|
|
49
|
+
return { maker: key === otherChoice ? unnamedTool : masterTool(key === elevenlabsChoice ? "ElevenLabs" : said ?? "") };
|
|
50
|
+
};
|
|
51
|
+
// A maker apart's record, as Codex is the chat's own in Codex too.
|
|
52
|
+
const apartOf = (maker) => Object.values(makersApart).find((one) => one.maker === maker);
|
|
53
|
+
// A maker's own answer, or its refusal remembered.
|
|
54
|
+
const readyOf = (maker, again) => {
|
|
55
|
+
const refused = apartOf(maker)?.refused;
|
|
56
|
+
return refused === undefined ? maker.ready(again) : { ready: false, why: refused };
|
|
34
57
|
};
|
|
35
|
-
// Codex's own answer, or its refusal remembered; in Codex, the chat's own.
|
|
36
|
-
const codexReady = (again) => (refused === undefined ? codex.ready(again) : { ready: false, why: refused });
|
|
37
58
|
const madeInstead = async (subject, instead) => {
|
|
38
59
|
const other = chat();
|
|
39
60
|
if (!other.ready().ready) {
|
|
40
61
|
return { refused: instead.why };
|
|
41
62
|
}
|
|
42
|
-
// A chat that paints itself gets no picture to make after its call answered: the next ones are its own.
|
|
63
|
+
// A chat that paints or draws itself gets no picture to make after its call answered: the next ones are its own.
|
|
43
64
|
if (other.brief !== undefined) {
|
|
44
|
-
return { refused: `${instead.why}; the next pictures are yours to make with your own image tool` };
|
|
65
|
+
return { refused: `${instead.why}; the next pictures are yours to ${drawsItself(other) ? "draw as SVG code and give with image, svg" : "make with your own image tool"}` };
|
|
45
66
|
}
|
|
46
67
|
const made = await other.make(subject);
|
|
47
68
|
return "refused" in made ? { refused: `${instead.why}; ${instead.by} made none either: ${made.refused}` } : { ...made, instead };
|
|
48
69
|
};
|
|
49
|
-
const fallbackOf = (said, refusedPicture = refused !== undefined) => {
|
|
70
|
+
const fallbackOf = (said, apart, refusedPicture = apart.refused !== undefined) => {
|
|
50
71
|
const other = chat().ready();
|
|
51
72
|
const by = other.ready ? other.maker : undefined;
|
|
52
|
-
return by === undefined
|
|
73
|
+
return by === undefined
|
|
74
|
+
? undefined
|
|
75
|
+
: { maker: apart.name, by, why: said.why, ...(said.fix === undefined ? {} : { fix: said.fix }), ...(refusedPicture ? { refused: true } : {}) };
|
|
53
76
|
};
|
|
54
77
|
return {
|
|
55
78
|
ready: (again) => {
|
|
56
|
-
const { maker,
|
|
57
|
-
|
|
58
|
-
|
|
79
|
+
const { maker, apart } = chosen();
|
|
80
|
+
const said = readyOf(maker, again);
|
|
81
|
+
if (apart === undefined) {
|
|
82
|
+
return said;
|
|
59
83
|
}
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
return said.ready || instead === undefined ? said : { ready: true, maker: instead.by, instead };
|
|
84
|
+
const instead = said.ready ? undefined : fallbackOf(said, apart);
|
|
85
|
+
return said.ready || instead === undefined ? said : { ready: true, maker: instead.by, ...(drawsItself(chat()) ? { draws: true } : {}), instead };
|
|
63
86
|
},
|
|
64
87
|
make: async (subject) => {
|
|
65
|
-
const { maker,
|
|
66
|
-
const said =
|
|
88
|
+
const { maker, apart } = chosen();
|
|
89
|
+
const said = readyOf(maker);
|
|
67
90
|
if (!said.ready) {
|
|
68
|
-
const instead =
|
|
91
|
+
const instead = apart === undefined ? undefined : fallbackOf(said, apart);
|
|
69
92
|
return instead === undefined ? { refused: said.why } : madeInstead(subject, instead);
|
|
70
93
|
}
|
|
71
94
|
const made = await maker.make(subject);
|
|
72
|
-
|
|
95
|
+
const remembered = apartOf(maker);
|
|
96
|
+
if (!("refused" in made) || remembered === undefined) {
|
|
73
97
|
return made;
|
|
74
98
|
}
|
|
75
|
-
// A refusal of this one picture, as the safety check's, leaves
|
|
99
|
+
// A refusal of this one picture, as the safety check's, leaves the maker asked for the next.
|
|
76
100
|
if (made.onlyThis !== true) {
|
|
77
|
-
refused = made.refused;
|
|
101
|
+
remembered.refused = made.refused;
|
|
78
102
|
}
|
|
79
|
-
const instead =
|
|
103
|
+
const instead = apart === undefined ? undefined : fallbackOf({ why: made.refused }, apart, true);
|
|
80
104
|
return instead === undefined ? made : madeInstead(subject, instead);
|
|
81
105
|
},
|
|
82
106
|
brief: (subject) => {
|
|
83
|
-
const { maker,
|
|
84
|
-
if (
|
|
107
|
+
const { maker, apart } = chosen();
|
|
108
|
+
if (apart === undefined) {
|
|
85
109
|
return maker.ready().ready ? maker.brief?.(subject) : undefined;
|
|
86
110
|
}
|
|
87
|
-
//
|
|
88
|
-
return
|
|
111
|
+
// The maker apart not ready: a chat that paints itself makes it in its place.
|
|
112
|
+
return readyOf(maker).ready ? undefined : chat().brief?.(subject);
|
|
89
113
|
},
|
|
90
114
|
};
|
|
91
115
|
}
|
|
@@ -93,6 +117,7 @@ export function hostPictures(host, choice = () => undefined, codex = codexPictur
|
|
|
93
117
|
// image tool of the master's.
|
|
94
118
|
const chatChoice = "chat";
|
|
95
119
|
const codexChoice = "codex";
|
|
120
|
+
const antigravityChoice = "antigravity";
|
|
96
121
|
const elevenlabsChoice = "elevenlabs";
|
|
97
122
|
const otherChoice = "other";
|
|
98
123
|
// Another image tool of the master's, which the player has not named yet: the master asks them which, from the same brief.
|
|
@@ -101,12 +126,27 @@ const unnamedTool = {
|
|
|
101
126
|
make: () => Promise.resolve({ refused: "the master makes the pictures with another tool, which the player has not named yet" }),
|
|
102
127
|
brief: chatBrief,
|
|
103
128
|
};
|
|
104
|
-
// Antigravity paints in its own chat, from the brief the image command gives it: the engine starts nothing.
|
|
129
|
+
// Antigravity paints in its own chat, from the brief the image command gives it, or draws the SVG where its tool fails: the engine starts nothing.
|
|
105
130
|
const antigravityPictures = {
|
|
106
131
|
ready: () => ({ ready: true, maker: "Antigravity" }),
|
|
107
132
|
make: () => Promise.resolve({ refused: "Antigravity makes its pictures in its own chat" }),
|
|
108
|
-
brief:
|
|
133
|
+
brief: antigravityBrief,
|
|
109
134
|
};
|
|
135
|
+
// The chats' names for the player, by the names their MCP clients give themselves; any other is shown as it comes.
|
|
136
|
+
const chatNames = { [openCodeClient]: "OpenCode" };
|
|
137
|
+
/** A chat that draws its pictures itself as SVG code (D-572), as OpenCode: from the SVG brief image gives it, handed back with image, svg; the engine starts nothing. */
|
|
138
|
+
export function chatDrawing(name) {
|
|
139
|
+
return {
|
|
140
|
+
ready: () => ({ ready: true, maker: name, draws: true }),
|
|
141
|
+
make: () => Promise.resolve({ refused: `${name} draws its pictures in its own chat` }),
|
|
142
|
+
brief: drawnBrief,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
// Whether a maker is a chat that draws itself; one with no brief never is, and is not asked.
|
|
146
|
+
function drawsItself(maker) {
|
|
147
|
+
const said = maker.brief === undefined ? undefined : maker.ready();
|
|
148
|
+
return said?.ready === true && said.draws === true;
|
|
149
|
+
}
|
|
110
150
|
// An image tool of the master's own, by its name, as ElevenLabs's: the same brief, and the engine starts nothing.
|
|
111
151
|
function masterTool(name) {
|
|
112
152
|
return {
|
|
@@ -115,20 +155,31 @@ function masterTool(name) {
|
|
|
115
155
|
brief: chatBrief,
|
|
116
156
|
};
|
|
117
157
|
}
|
|
118
|
-
/** The writer of text of this computer for the chat `host` names (D-406),
|
|
119
|
-
export function hostWriter(host, codex = codexWriter(), claude = claudeWriter()) {
|
|
120
|
-
const writers = () =>
|
|
158
|
+
/** The writer of text of this computer for the chat `host` names (D-406): Codex first, then Claude; in OpenCode, OpenCode before them, in Antigravity, its agy (D-579 (1)). */
|
|
159
|
+
export function hostWriter(host, codex = codexWriter(), claude = claudeWriter(), openCode = openCodeWriter(), antigravity = antigravityWriter()) {
|
|
160
|
+
const writers = () => {
|
|
161
|
+
const chat = host();
|
|
162
|
+
return chat === codexClient ? [codex] : chat === openCodeClient ? [openCode, codex, claude] : chat === antigravityClient ? [antigravity, codex, claude] : [codex, claude];
|
|
163
|
+
};
|
|
121
164
|
return {
|
|
122
165
|
ready: () => writers().some((writer) => writer.ready()),
|
|
123
166
|
write: (brief) => (writers().find((writer) => writer.ready()) ?? codex).write(brief),
|
|
124
167
|
};
|
|
125
168
|
}
|
|
126
|
-
/**
|
|
127
|
-
|
|
128
|
-
|
|
169
|
+
/**
|
|
170
|
+
* The importer of this computer for the chat `host` names (D-489 (1)): Codex in Codex, else Claude first, which Elena's probe measured, then Codex; in OpenCode,
|
|
171
|
+
* OpenCode before them, in Antigravity, its agy (D-579 (1)).
|
|
172
|
+
*/
|
|
173
|
+
export function hostReader(host, codex = codexReader(), claude = claudeReader(), openCode = openCodeReader(), antigravity = antigravityReader()) {
|
|
174
|
+
const readers = () => {
|
|
175
|
+
const chat = host();
|
|
176
|
+
return chat === codexClient ? [codex] : chat === openCodeClient ? [openCode, claude, codex] : chat === antigravityClient ? [antigravity, claude, codex] : [claude, codex];
|
|
177
|
+
};
|
|
129
178
|
return {
|
|
130
179
|
ready: () => readers().some((reader) => reader.ready()),
|
|
131
180
|
program: () => readers().find((reader) => reader.ready())?.program?.(),
|
|
181
|
+
model: () => readers().find((reader) => reader.ready())?.model?.(),
|
|
182
|
+
clean: () => [codex, claude, openCode, antigravity].forEach((reader) => reader.clean?.()),
|
|
132
183
|
read: (folder, brief, writable, signal) => (readers().find((reader) => reader.ready()) ?? claude).read(folder, brief, writable, signal),
|
|
133
184
|
};
|
|
134
185
|
}
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { type AgySettings, antigravityPainter, antigravityReader, antigravitySays, antigravityWriter, painterSettings, playerModel, readerSettings, sealedSettings } from "./antigravity.ts";
|
|
2
|
+
export { antigravityBrief, chatBrief, drawnBrief, paintedBrief, svgBrief } from "./briefs.ts";
|
|
3
|
+
export { antigravityClient, chatDrawing, codexClient, hostPictures, hostReader, hostWriter, openCodeClient } from "./chosen.ts";
|
|
3
4
|
export { claudeSays } from "./claude.ts";
|
|
4
5
|
export { codexPictures, codexSays } from "./codex.ts";
|
|
6
|
+
export { openCodeReader, openCodeWriter, readerRules } from "./opencode.ts";
|
|
5
7
|
export { computerHelpers, helperChanges, helperCommand, queueInCodex } from "./programs.ts";
|
|
6
8
|
export { stopProcess } from "./stop.ts";
|
|
7
9
|
export { cleanSvg, svgIn } from "./svg.ts";
|
package/dist/helpers/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
// Codex and Claude Code on the player's computer, found, installed and signed in with the player's yes (D-424), and what they do for the game: pictures made
|
|
2
|
-
// from words (D-308, D-390), Codex's painted else Claude's SVG, the importer's reading and the page's words;
|
|
3
|
-
|
|
4
|
-
export {
|
|
2
|
+
// from words (D-308, D-390), Codex's painted else Claude's SVG, the importer's reading and the page's words; OpenCode for the last two in its own chat
|
|
3
|
+
// (D-578 (3)), and Antigravity's agy for the same in its own (D-579 (1)); injected through Context, so that tests never spend.
|
|
4
|
+
export { antigravityPainter, antigravityReader, antigravitySays, antigravityWriter, painterSettings, playerModel, readerSettings, sealedSettings } from "./antigravity.js";
|
|
5
|
+
export { antigravityBrief, chatBrief, drawnBrief, paintedBrief, svgBrief } from "./briefs.js";
|
|
6
|
+
export { antigravityClient, chatDrawing, codexClient, hostPictures, hostReader, hostWriter, openCodeClient } from "./chosen.js";
|
|
5
7
|
export { claudeSays } from "./claude.js";
|
|
6
8
|
export { codexPictures, codexSays } from "./codex.js";
|
|
9
|
+
export { openCodeReader, openCodeWriter, readerRules } from "./opencode.js";
|
|
7
10
|
export { computerHelpers, helperChanges, helperCommand, queueInCodex } from "./programs.js";
|
|
8
11
|
export { stopProcess } from "./stop.js";
|
|
9
12
|
export { cleanSvg, svgIn } from "./svg.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DocumentReader, TextWriter } from "../core/context.ts";
|
|
2
|
+
/** A permission rule of an OpenCode agent: the last that matches decides. */
|
|
3
|
+
export interface OpenCodeRule {
|
|
4
|
+
action: string;
|
|
5
|
+
resource: string;
|
|
6
|
+
effect: "allow" | "deny";
|
|
7
|
+
}
|
|
8
|
+
/** OpenCode on this computer as a writer of text (D-406): an agent that may use no tool, in an empty folder of its own. `program` is the line that starts it. */
|
|
9
|
+
export declare function openCodeWriter(program?: string): TextWriter;
|
|
10
|
+
/** OpenCode on this computer as the importer (D-489 (1)): in the import's folder, reading only there and writing only in the folders given. */
|
|
11
|
+
export declare function openCodeReader(program?: string): DocumentReader;
|
|
12
|
+
/** The importer's fence (D-489 (1)), as Elena's probe proved it: everything denied, then reading in the folder and editing in the folders given, never outside it. */
|
|
13
|
+
export declare function readerRules(writable: string[]): OpenCodeRule[];
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// OpenCode does the work outside the chat where it is the chat in use (D-578 (3)): the writer of text (D-406) and the importer (D-489 (1)), with the player's own
|
|
2
|
+
// model, the last one they chose in it, never one or a key the engine picks. Each run has an agent of its own, given in the environment and never as a file in
|
|
3
|
+
// the player's folders, with every tool denied but what it needs; the project's own configuration is left out, and the session it made is deleted as it ends.
|
|
4
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
5
|
+
import { randomBytes } from "node:crypto";
|
|
6
|
+
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { basename, join } from "node:path";
|
|
9
|
+
import { isAlive } from "../core/process-mark.js";
|
|
10
|
+
import { chatEnvironment, isOwn, knownReady } from "./programs.js";
|
|
11
|
+
import { stopProcess, stopTree, whenEnded } from "./stop.js";
|
|
12
|
+
// The same limits as Claude's: a brief in three minutes, a run of the importer in thirty.
|
|
13
|
+
const longest = 3 * 60 * 1000;
|
|
14
|
+
const longestReading = 30 * 60 * 1000;
|
|
15
|
+
// How long the deletion of a session may take: it took under a second.
|
|
16
|
+
const deleteWait = 30_000;
|
|
17
|
+
/** OpenCode on this computer as a writer of text (D-406): an agent that may use no tool, in an empty folder of its own. `program` is the line that starts it. */
|
|
18
|
+
export function openCodeWriter(program = "opencode") {
|
|
19
|
+
const ready = openCodeReady(program);
|
|
20
|
+
return {
|
|
21
|
+
ready: () => ready().ready,
|
|
22
|
+
write: async (brief) => {
|
|
23
|
+
const model = ready();
|
|
24
|
+
if (!model.ready || model.maker === undefined) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const folder = mkdtempSync(join(tmpdir(), "rpg-writing-"));
|
|
28
|
+
try {
|
|
29
|
+
const ran = await runAgent(program, model.maker, folder, writerAgent, brief, longest);
|
|
30
|
+
return ran.code === 0 && ran.error === undefined ? ran.text : undefined;
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
rmSync(folder, { recursive: true, force: true });
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** OpenCode on this computer as the importer (D-489 (1)): in the import's folder, reading only there and writing only in the folders given. */
|
|
39
|
+
export function openCodeReader(program = "opencode") {
|
|
40
|
+
const ready = openCodeReady(program);
|
|
41
|
+
return {
|
|
42
|
+
ready: () => ready().ready,
|
|
43
|
+
program: () => "OpenCode",
|
|
44
|
+
clean: () => void sweepRuns(program),
|
|
45
|
+
// The model OpenCode named when it was asked whether it is ready, for the player, as it may be paid by the call.
|
|
46
|
+
model: () => {
|
|
47
|
+
const model = ready();
|
|
48
|
+
return model.ready ? model.maker : undefined;
|
|
49
|
+
},
|
|
50
|
+
read: async (folder, brief, writable, signal) => {
|
|
51
|
+
const model = ready();
|
|
52
|
+
if (!model.ready || model.maker === undefined) {
|
|
53
|
+
return { failed: model.ready ? "OpenCode has no model" : model.why };
|
|
54
|
+
}
|
|
55
|
+
ownRepository(folder);
|
|
56
|
+
const ran = await runAgent(program, model.maker, folder, readerAgent(writable), brief, longestReading, signal);
|
|
57
|
+
if (ran.code === 0 && ran.error === undefined && ran.text !== undefined) {
|
|
58
|
+
return { said: ran.text };
|
|
59
|
+
}
|
|
60
|
+
const said = ran.error ?? ran.errors.trim().split("\n").at(-1)?.trim() ?? "";
|
|
61
|
+
return { failed: said === "" ? "OpenCode stopped without an answer" : `OpenCode said: ${said}` };
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A git repository of the import's folder's own, where the campaign above it is one: OpenCode lets an agent read up to the root of the repository it runs in,
|
|
67
|
+
* the campaign's secrets too, and with its own the import's folder is the root. Without git on this computer nothing is done, as no campaign is a repository.
|
|
68
|
+
*/
|
|
69
|
+
function ownRepository(folder) {
|
|
70
|
+
if (!existsSync(join(folder, ".git"))) {
|
|
71
|
+
spawnSync("git", ["init", "-q"], { cwd: folder, windowsHide: true, timeout: 15_000, stdio: "ignore" });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** The importer's fence (D-489 (1)), as Elena's probe proved it: everything denied, then reading in the folder and editing in the folders given, never outside it. */
|
|
75
|
+
export function readerRules(writable) {
|
|
76
|
+
return [
|
|
77
|
+
{ action: "*", resource: "*", effect: "deny" },
|
|
78
|
+
{ action: "read", resource: "*", effect: "allow" },
|
|
79
|
+
{ action: "glob", resource: "*", effect: "allow" },
|
|
80
|
+
{ action: "grep", resource: "*", effect: "allow" },
|
|
81
|
+
...writable.flatMap((name) => [{ action: "edit", resource: `${name}/*`, effect: "allow" }, { action: "edit", resource: `${name}/**`, effect: "allow" }]),
|
|
82
|
+
{ action: "external_directory", resource: "*", effect: "deny" },
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
const writerAgent = { name: "rpg-writer", system: "You write what a brief asks, and only that.", rules: [{ action: "*", resource: "*", effect: "deny" }] };
|
|
86
|
+
function readerAgent(writable) {
|
|
87
|
+
return { name: "rpg-reader", system: "You read a player's documents and write a tabletop adventure from them, as files in this folder.", rules: readerRules(writable) };
|
|
88
|
+
}
|
|
89
|
+
// Whether OpenCode is ready, by the line that starts it: asked once, as the other helpers are, and remembered.
|
|
90
|
+
const readies = new Map();
|
|
91
|
+
function openCodeReady(program) {
|
|
92
|
+
const known = readies.get(program) ?? knownReady(() => modelOf(program));
|
|
93
|
+
readies.set(program, known);
|
|
94
|
+
return known;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The player's model in OpenCode, as its maker, without starting one: OpenCode answers, the last model the player chose (`recent[0]` of model.json in its state
|
|
98
|
+
* folder), and that model among those OpenCode can use now. Not ready otherwise.
|
|
99
|
+
*/
|
|
100
|
+
function modelOf(program) {
|
|
101
|
+
const paths = quietRun(`${program} debug paths`);
|
|
102
|
+
const state = paths === undefined ? undefined : /^state\s+(.+?)\s*$/m.exec(paths)?.[1];
|
|
103
|
+
if (state === undefined) {
|
|
104
|
+
return { ready: false, why: "OpenCode does not answer on this computer" };
|
|
105
|
+
}
|
|
106
|
+
const model = lastModel(join(state, "model.json"));
|
|
107
|
+
if (model === undefined) {
|
|
108
|
+
return { ready: false, why: "OpenCode has no model chosen yet: the player picks one in it" };
|
|
109
|
+
}
|
|
110
|
+
const models = quietRun(`${program} models --standalone`);
|
|
111
|
+
if (models === undefined || !models.split(/\r?\n/).some((line) => line.trim() === model.name)) {
|
|
112
|
+
return { ready: false, why: `OpenCode cannot use its model ${model.name} now` };
|
|
113
|
+
}
|
|
114
|
+
return { ready: true, maker: model.variant === undefined ? model.name : `${model.name}#${model.variant}` };
|
|
115
|
+
}
|
|
116
|
+
/** The last model the player chose in OpenCode, with its variant; undefined where there is none, or one whose name the shell could misread. */
|
|
117
|
+
function lastModel(file) {
|
|
118
|
+
try {
|
|
119
|
+
const json = JSON.parse(readFileSync(file, "utf8"));
|
|
120
|
+
const first = json.recent?.[0];
|
|
121
|
+
const name = typeof first?.providerID === "string" && typeof first.modelID === "string" ? `${first.providerID}/${first.modelID}` : undefined;
|
|
122
|
+
const variant = name === undefined ? undefined : json.variant?.[name];
|
|
123
|
+
const safe = (value) => /^[\w.:/@+-]+$/.test(value);
|
|
124
|
+
if (name === undefined || !safe(name)) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
return typeof variant === "string" && safe(variant) ? { name, variant } : { name };
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** What a quick command of OpenCode printed, from a folder of no campaign; undefined where it failed. */
|
|
134
|
+
function quietRun(line) {
|
|
135
|
+
const run = spawnSync(line, { shell: true, encoding: "utf8", timeout: 15_000, windowsHide: true, cwd: tmpdir(), env: openCodeEnvironment() });
|
|
136
|
+
return run.error === undefined && run.status === 0 ? run.stdout : undefined;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* One run of an agent: `opencode run` with a session whose name the engine chose, deleted however the run ends; the answer is the last text part of its
|
|
140
|
+
* events, as a model may write two whole answers in two steps.
|
|
141
|
+
*/
|
|
142
|
+
function runAgent(program, model, folder, agent, brief, limit, signal) {
|
|
143
|
+
const session = `ses_rpg${randomBytes(10).toString("hex")}`;
|
|
144
|
+
const config = { agents: { [agent.name]: { description: agent.system, mode: "primary", system: agent.system, permissions: agent.rules } } };
|
|
145
|
+
const environment = { ...openCodeEnvironment(), OPENCODE_CONFIG_CONTENT: JSON.stringify(config), OPENCODE_DISABLE_PROJECT_CONFIG: "1" };
|
|
146
|
+
const line = `${program} run --standalone --agent ${agent.name} -m "${model}" --format json --archived --session ${session}`;
|
|
147
|
+
void sweepRuns(program);
|
|
148
|
+
markRun(session, { engine: process.pid, program });
|
|
149
|
+
return new Promise((done) => {
|
|
150
|
+
// Off Windows it leads a group of its own: the shell alone, stopped, would leave OpenCode running with the output held open.
|
|
151
|
+
const child = spawn(line, { shell: true, windowsHide: true, cwd: folder, env: environment, stdio: ["pipe", "pipe", "pipe"], detached: process.platform !== "win32" });
|
|
152
|
+
let stopped = false;
|
|
153
|
+
if (child.pid !== undefined) {
|
|
154
|
+
markRun(session, { engine: process.pid, child: child.pid, program });
|
|
155
|
+
}
|
|
156
|
+
// Dropped while it runs: OpenCode stops with its own server.
|
|
157
|
+
const stop = () => {
|
|
158
|
+
stopped = true;
|
|
159
|
+
if (process.platform === "win32" || child.pid === undefined) {
|
|
160
|
+
stopTree(child);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
stopProcess(child.pid);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
167
|
+
let output = "";
|
|
168
|
+
let errors = "";
|
|
169
|
+
const timer = setTimeout(stop, limit);
|
|
170
|
+
child.stdout.setEncoding("utf8");
|
|
171
|
+
child.stderr.setEncoding("utf8");
|
|
172
|
+
child.stdout.on("data", (chunk) => (output += chunk));
|
|
173
|
+
child.stderr.on("data", (chunk) => (errors += chunk));
|
|
174
|
+
child.stdin.on("error", () => undefined);
|
|
175
|
+
child.on("error", () => undefined);
|
|
176
|
+
whenEnded(child, (exitCode) => {
|
|
177
|
+
clearTimeout(timer);
|
|
178
|
+
signal?.removeEventListener("abort", stop);
|
|
179
|
+
const events = eventsOf(output);
|
|
180
|
+
const text = events.filter((event) => event.type === "text").map((event) => event.part?.text).filter((one) => typeof one === "string" && one.trim() !== "").at(-1);
|
|
181
|
+
const failed = events.find((event) => event.type === "error");
|
|
182
|
+
const error = failed === undefined ? undefined : errorText(failed);
|
|
183
|
+
// A run stopped after its last step finished keeps its answer.
|
|
184
|
+
const finished = events.some((event) => event.type === "step_finish" && event.part?.reason === "stop");
|
|
185
|
+
const code = stopped && finished && error === undefined ? 0 : exitCode;
|
|
186
|
+
void deleteSession(program, session).then(() => {
|
|
187
|
+
unmarkRun(session);
|
|
188
|
+
done({ code, errors, ...(typeof text === "string" ? { text: text.trim() } : {}), ...(error === undefined ? {} : { error }) });
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
child.stdin.end(brief);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/** Deletes a session of the engine's from the player's OpenCode, whether the run made it or not. */
|
|
195
|
+
function deleteSession(program, session) {
|
|
196
|
+
return new Promise((done) => {
|
|
197
|
+
const child = spawn(`${program} session delete ${session} --standalone`, { shell: true, windowsHide: true, cwd: tmpdir(), env: openCodeEnvironment(), stdio: "ignore" });
|
|
198
|
+
const timer = setTimeout(() => stopTree(child), deleteWait);
|
|
199
|
+
child.on("error", () => undefined);
|
|
200
|
+
child.on("close", () => {
|
|
201
|
+
clearTimeout(timer);
|
|
202
|
+
done();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
// The marks of the runs under way, one a session: a run stopped from outside, as by an import's cancel, leaves its own, and the next sweep deletes its session.
|
|
207
|
+
function runsFolder() {
|
|
208
|
+
return join(tmpdir(), "rpg-opencode-runs");
|
|
209
|
+
}
|
|
210
|
+
function markRun(session, mark) {
|
|
211
|
+
try {
|
|
212
|
+
mkdirSync(runsFolder(), { recursive: true });
|
|
213
|
+
writeFileSync(join(runsFolder(), `${session}.json`), JSON.stringify(mark));
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
// No mark: a run stopped from outside would leave its session, as before.
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function unmarkRun(session) {
|
|
220
|
+
try {
|
|
221
|
+
rmSync(join(runsFolder(), `${session}.json`), { force: true });
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
// Held a moment: a sweep finds its engine alive, or takes it later.
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Deletes the sessions that runs of `program` stopped from outside left: each mark whose engine process is gone, its OpenCode stopped first if it still runs.
|
|
229
|
+
* Only marks of the same program line, never a line read from a file alone. Never throws.
|
|
230
|
+
*/
|
|
231
|
+
async function sweepRuns(program) {
|
|
232
|
+
try {
|
|
233
|
+
const marks = readdirSync(runsFolder()).filter((name) => /^ses_rpg[0-9a-f]{20}\.json$/.test(name));
|
|
234
|
+
for (const name of marks) {
|
|
235
|
+
const file = join(runsFolder(), name);
|
|
236
|
+
const mark = markOf(file);
|
|
237
|
+
if (mark === undefined || mark.program !== program || isAlive(mark.engine) || !isOwn(file)) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
await sweepRun(program, file, mark);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
// No marks: nothing to sweep.
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// One mark of a run whose engine is gone: its OpenCode stopped if it still runs, its session deleted, the mark taken away.
|
|
248
|
+
async function sweepRun(program, file, mark) {
|
|
249
|
+
const taken = `${file}.taken`;
|
|
250
|
+
try {
|
|
251
|
+
// Taken by this sweep alone: another at the same time finds it gone.
|
|
252
|
+
renameSync(file, taken);
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (mark.child !== undefined && isAlive(mark.child)) {
|
|
258
|
+
stopProcess(mark.child);
|
|
259
|
+
}
|
|
260
|
+
await deleteSession(program, basename(file, ".json"));
|
|
261
|
+
rmSync(taken, { force: true });
|
|
262
|
+
}
|
|
263
|
+
function markOf(file) {
|
|
264
|
+
try {
|
|
265
|
+
const mark = JSON.parse(readFileSync(file, "utf8"));
|
|
266
|
+
const pid = (value) => (typeof value === "number" && Number.isInteger(value) && value > 0 ? value : undefined);
|
|
267
|
+
const engine = pid(mark.engine);
|
|
268
|
+
const child = pid(mark.child);
|
|
269
|
+
return engine === undefined || typeof mark.program !== "string" ? undefined : { engine, program: mark.program, ...(child === undefined ? {} : { child }) };
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function eventsOf(output) {
|
|
276
|
+
return output.split("\n").flatMap((line) => {
|
|
277
|
+
try {
|
|
278
|
+
const event = JSON.parse(line);
|
|
279
|
+
return typeof event === "object" && event !== null ? [event] : [];
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
return [];
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function errorText(event) {
|
|
287
|
+
const message = event.error?.data?.message ?? event.error?.name;
|
|
288
|
+
return typeof message === "string" && message !== "" ? message : "it failed";
|
|
289
|
+
}
|
|
290
|
+
// The chat's variables OpenCode's runs never get: the engine's, the chat's session and folder, and what OpenCode would take from the chat.
|
|
291
|
+
const chatVariables = /^(RPG_|OPENCODE_(SESSION_ID|CLIENT|CONFIG_CONTENT|DISABLE_PROJECT_CONFIG|SERVER_PASSWORD)$|PWD$|OLDPWD$|INIT_CWD$)/i;
|
|
292
|
+
/** The environment of OpenCode's runs: the chat's own, without what names the campaign; the player's keys and settings stay, as their model needs them. */
|
|
293
|
+
function openCodeEnvironment() {
|
|
294
|
+
return chatEnvironment(chatVariables);
|
|
295
|
+
}
|
|
@@ -22,6 +22,14 @@ export declare function knownReady(check: () => PicturesReady): (again?: boolean
|
|
|
22
22
|
* told not to look for programs in the folder it starts in, which could be a campaign's.
|
|
23
23
|
*/
|
|
24
24
|
export declare function helperEnvironment(name: HelperName): NodeJS.ProcessEnv;
|
|
25
|
+
/** Whether a file or folder of the temporary folder is this user's own, never another's left to have the engine stop or run something; always on Windows. */
|
|
26
|
+
export declare function isOwn(path: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The environment of a program of the chat in use, as OpenCode or Antigravity: the chat's own, without the variables whose names `dropped` matches nor any that
|
|
29
|
+
* names the `campaign`'s folder, and the PATH without its folders; the player's keys and settings stay. On Windows the shell does not look for programs in the
|
|
30
|
+
* folder it starts in.
|
|
31
|
+
*/
|
|
32
|
+
export declare function chatEnvironment(dropped: RegExp, campaign?: string): NodeJS.ProcessEnv;
|
|
25
33
|
/**
|
|
26
34
|
* The player's sign-in, started once and kept alive until it ends or ten minutes pass. It answers once the program printed its link, for a browser that did
|
|
27
35
|
* not open, or ended, or after a few seconds; how it ends later is told by the next call.
|
package/dist/helpers/programs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Codex and Claude Code with the player's own login (D-424, D-425): found on the PATH or in the engine's folder, installed there with npm, never globally, and
|
|
2
2
|
// signed in by the player in the browser; started through the shell from a folder of no campaign, without the chat's variables or an API key.
|
|
3
3
|
import { spawn, spawnSync } from "node:child_process";
|
|
4
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
5
5
|
import { homedir, tmpdir } from "node:os";
|
|
6
|
-
import { delimiter, join } from "node:path";
|
|
6
|
+
import { delimiter, dirname, join } from "node:path";
|
|
7
7
|
import { stopTree } from "./stop.js";
|
|
8
8
|
// The npm package of each program.
|
|
9
9
|
const packages = { codex: "@openai/codex", claude: "@anthropic-ai/claude-code" };
|
|
@@ -132,6 +132,39 @@ export function helperEnvironment(name) {
|
|
|
132
132
|
const own = Object.fromEntries(Object.entries(process.env).filter(([variable]) => kept.has(variable.toUpperCase()) || !dropped.test(variable)));
|
|
133
133
|
return { ...own, NoDefaultCurrentDirectoryInExePath: "1" };
|
|
134
134
|
}
|
|
135
|
+
/** Whether a file or folder of the temporary folder is this user's own, never another's left to have the engine stop or run something; always on Windows. */
|
|
136
|
+
export function isOwn(path) {
|
|
137
|
+
try {
|
|
138
|
+
return process.getuid === undefined || statSync(path).uid === process.getuid();
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The environment of a program of the chat in use, as OpenCode or Antigravity: the chat's own, without the variables whose names `dropped` matches nor any that
|
|
146
|
+
* names the `campaign`'s folder, and the PATH without its folders; the player's keys and settings stay. On Windows the shell does not look for programs in the
|
|
147
|
+
* folder it starts in.
|
|
148
|
+
*/
|
|
149
|
+
export function chatEnvironment(dropped, campaign = process.cwd()) {
|
|
150
|
+
// The folder the chat runs in, a campaign's; never a root, which every path would name.
|
|
151
|
+
const here = dirname(campaign) === campaign ? "\u0000" : campaign.toLowerCase().replace(/[\\/]+$/, "");
|
|
152
|
+
// A folder of the PATH in the campaign: the campaign itself or one below it, never a sibling whose name begins the same.
|
|
153
|
+
const inCampaign = (folder) => {
|
|
154
|
+
const path = folder.toLowerCase().replace(/[\\/]+$/, "");
|
|
155
|
+
return path === here || path.startsWith(`${here}\\`) || path.startsWith(`${here}/`);
|
|
156
|
+
};
|
|
157
|
+
const kept = Object.entries(process.env).flatMap(([variable, value]) => {
|
|
158
|
+
if (value === undefined || dropped.test(variable)) {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
if (variable.toUpperCase() === "PATH") {
|
|
162
|
+
return [[variable, value.split(delimiter).filter((folder) => !inCampaign(folder)).join(delimiter)]];
|
|
163
|
+
}
|
|
164
|
+
return value.toLowerCase().includes(here) ? [] : [[variable, value]];
|
|
165
|
+
});
|
|
166
|
+
return { ...Object.fromEntries(kept), NoDefaultCurrentDirectoryInExePath: "1" };
|
|
167
|
+
}
|
|
135
168
|
/**
|
|
136
169
|
* The player's sign-in, started once and kept alive until it ends or ten minutes pass. It answers once the program printed its link, for a browser that did
|
|
137
170
|
* not open, or ended, or after a few seconds; how it ends later is told by the next call.
|