@crowdedkingdoms/crowdyjs 18.22.0-test.1 → 18.23.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -1
- package/dist/crowdy-dsh/bridge.d.ts +72 -3
- package/dist/crowdy-dsh/bridge.d.ts.map +1 -1
- package/dist/crowdy-dsh/bridge.js +243 -12
- package/dist/crowdy-dsh/game-paths.d.ts +8 -0
- package/dist/crowdy-dsh/game-paths.d.ts.map +1 -0
- package/dist/crowdy-dsh/game-paths.js +20 -0
- package/dist/crowdy-dsh/pane.d.ts +18 -1
- package/dist/crowdy-dsh/pane.d.ts.map +1 -1
- package/dist/crowdy-dsh/pane.js +86 -2
- package/dist/crowdy-dsh/protocol.d.ts +165 -2
- package/dist/crowdy-dsh/protocol.d.ts.map +1 -1
- package/dist/crowdy-dsh/protocol.js +24 -1
- package/dist/crowdy-studio/controller.d.ts +100 -0
- package/dist/crowdy-studio/controller.d.ts.map +1 -1
- package/dist/crowdy-studio/controller.js +363 -1
- package/dist/crowdy-studio/dom-shell.d.ts +11 -0
- package/dist/crowdy-studio/dom-shell.d.ts.map +1 -1
- package/dist/crowdy-studio/dom-shell.js +182 -0
- package/dist/crowdy-studio/draft/github-draft-store.d.ts +143 -0
- package/dist/crowdy-studio/draft/github-draft-store.d.ts.map +1 -0
- package/dist/crowdy-studio/draft/github-draft-store.js +477 -0
- package/dist/crowdy-studio/draft/hash.d.ts +12 -0
- package/dist/crowdy-studio/draft/hash.d.ts.map +1 -0
- package/dist/crowdy-studio/draft/hash.js +25 -0
- package/dist/crowdy-studio/draft/index.d.ts +6 -0
- package/dist/crowdy-studio/draft/index.d.ts.map +1 -0
- package/dist/crowdy-studio/draft/index.js +5 -0
- package/dist/crowdy-studio/draft/overlay-storage.d.ts +48 -0
- package/dist/crowdy-studio/draft/overlay-storage.d.ts.map +1 -0
- package/dist/crowdy-studio/draft/overlay-storage.js +94 -0
- package/dist/crowdy-studio/draft/paths.d.ts +20 -0
- package/dist/crowdy-studio/draft/paths.d.ts.map +1 -0
- package/dist/crowdy-studio/draft/paths.js +54 -0
- package/dist/crowdy-studio/draft/types.d.ts +137 -0
- package/dist/crowdy-studio/draft/types.d.ts.map +1 -0
- package/dist/crowdy-studio/draft/types.js +29 -0
- package/dist/crowdy-studio/editor.d.ts +2 -0
- package/dist/crowdy-studio/editor.d.ts.map +1 -1
- package/dist/crowdy-studio/embed/panel.d.ts +8 -0
- package/dist/crowdy-studio/embed/panel.d.ts.map +1 -1
- package/dist/crowdy-studio/embed/panel.js +2 -0
- package/dist/crowdy-studio/github/index.d.ts +1 -1
- package/dist/crowdy-studio/github/index.d.ts.map +1 -1
- package/dist/crowdy-studio/github/transport.d.ts +59 -0
- package/dist/crowdy-studio/github/transport.d.ts.map +1 -1
- package/dist/crowdy-studio/github/transport.js +30 -1
- package/dist/crowdy-studio/index.d.ts +1 -0
- package/dist/crowdy-studio/index.d.ts.map +1 -1
- package/dist/crowdy-studio/index.js +1 -0
- package/dist/crowdy-studio/models.d.ts +1 -1
- package/dist/crowdy-studio/models.d.ts.map +1 -1
- package/dist/crowdy-studio/monaco-editor.d.ts.map +1 -1
- package/dist/crowdy-studio/monaco-editor.js +16 -0
- package/dist/crowdy-studio/mount.d.ts +2 -0
- package/dist/crowdy-studio/mount.d.ts.map +1 -1
- package/dist/crowdy-studio/mount.js +2 -0
- package/dist/crowdy-studio/repository-tree.d.ts +14 -0
- package/dist/crowdy-studio/repository-tree.d.ts.map +1 -0
- package/dist/crowdy-studio/repository-tree.js +45 -0
- package/dist/crowdy-studio/styles.d.ts +1 -1
- package/dist/crowdy-studio/styles.d.ts.map +1 -1
- package/dist/crowdy-studio/styles.js +1 -0
- package/dist/crowdy-studio/textarea-editor.d.ts.map +1 -1
- package/dist/crowdy-studio/textarea-editor.js +10 -4
- package/dist/default-origin.d.ts +6 -6
- package/dist/default-origin.d.ts.map +1 -1
- package/dist/default-origin.js +6 -6
- package/dist/generated/graphql-schema.d.ts +84 -2
- package/dist/generated/graphql-schema.d.ts.map +1 -1
- package/dist/generated/graphql-schema.js +9 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -334,7 +334,7 @@ never told about, so a native refresh without it is a re-placement.
|
|
|
334
334
|
| `client.playerWallet` | Player spend: balance, ledger, hourly charges, spend caps, card setup, auto-recharge. A ck-exec mod's compute is billed here, to its owner. |
|
|
335
335
|
| `client.marketplace` | Player-authorized grid claims (`claimGridOwnership`, `claimGridChunk`, `releaseClaimedGrid`, requests and invites) and studio moderation of player code (admission queue, listing administration, claim policy). Mods publish and install through `client.exec`. |
|
|
336
336
|
| `client.crowdyStudio` | Cloud project, personal-library, and common-file APIs for Crowdy Studio: target-scoped files, metadata/module names, optimistic revisions, copy-by-value imports, atomic saves. |
|
|
337
|
-
| `client.crowdyStudioGitHub` | Optional GitHub repository for a Crowdy Studio project: status, `bind` (push the project in, or take the repository), `unbind`, `refresh`, `layout
|
|
337
|
+
| `client.crowdyStudioGitHub` | Optional GitHub repository for a Crowdy Studio project: status, `bind` (push the project in, or take the repository), `unbind`, `refresh`, `layout` (with `kind`: a mod or a Construct game), `tree`, `getFile`, batched `getFiles`, commit-guarded `putFile` / `deleteFile`, and `commitFiles` (many changes as one commit). While bound the repository is the working tree and every Studio save commits; the project's `files` are the server's mirror at `github.sha`. Never required. |
|
|
338
338
|
| `client.udp` | UDP proxy subscriptions + spatial mutations (`sendActorUpdate`, `sendVoxelUpdate`, `sendAudioPacket`, `sendVideoPacket` / `sendVideoFrame`, `sendTextPacket`, `sendClientEvent`, `sendSingleActorMessage`, `sendChannelMessage`, `sendRangedChannelMessage`). |
|
|
339
339
|
| `client.realtime` | Connection status, manual `connect()` / `disconnect()`, `onStatus()` listener. |
|
|
340
340
|
| `client.refreshGameplayToken()` | Safely rotates an active game client's app token (see [Token refresh](#token-refresh-during-gameplay)). |
|
|
@@ -1237,6 +1237,43 @@ its `sandbox="allow-scripts allow-same-origin"` does not isolate it from the
|
|
|
1237
1237
|
page; that CSP is the control. See the
|
|
1238
1238
|
[`@crowdedkingdoms/crowdy-dsh` README on npm](https://www.npmjs.com/package/@crowdedkingdoms/crowdy-dsh).
|
|
1239
1239
|
|
|
1240
|
+
### The game editor (a Construct game's repository)
|
|
1241
|
+
|
|
1242
|
+
When the open project is bound to a game generated from the Construct
|
|
1243
|
+
template, the API reports it as such (`crowdyStudioGitHubLayout.kind ===
|
|
1244
|
+
'CONSTRUCT_GAME'`) and Studio edits the game itself instead of mod crates,
|
|
1245
|
+
provided the host gives the controller a draft store:
|
|
1246
|
+
|
|
1247
|
+
```ts
|
|
1248
|
+
import { GitHubDraftStore, IndexedDbDraftOverlayStorage } from '@crowdedkingdoms/crowdyjs/crowdy-studio';
|
|
1249
|
+
|
|
1250
|
+
const storage = new IndexedDbDraftOverlayStorage();
|
|
1251
|
+
const studio = createCrowdyStudioEmbed({
|
|
1252
|
+
// ...
|
|
1253
|
+
draftStore: ({ appId, projectId, githubSha }) =>
|
|
1254
|
+
new GitHubDraftStore({ transport: game.crowdyStudioGitHub, appId, projectId, baseCommitSha: githubSha, storage }),
|
|
1255
|
+
});
|
|
1256
|
+
// A Live code link names the project; open it first.
|
|
1257
|
+
studio.toggle({ gridId, targetPermissions, projectId });
|
|
1258
|
+
```
|
|
1259
|
+
|
|
1260
|
+
The draft is the game's working copy until the player commits. Everything
|
|
1261
|
+
reads it: the Files pane (dirty files marked, discard per file), the editor,
|
|
1262
|
+
the agent (in game mode), and whatever the game hot-reloads from it. Versions
|
|
1263
|
+
are git blob ids, so an untouched file carries its GitHub blob id. The hosted
|
|
1264
|
+
store keeps edits in IndexedDB on the game's own origin and reads the bound
|
|
1265
|
+
branch through `crowdyStudioGitHub.tree` and `getFiles` (100 paths a call);
|
|
1266
|
+
**Commit** (or the agent's `commit_game_files`, which the player confirms in
|
|
1267
|
+
the pane) publishes the draft as ONE commit through `commitFiles`; an agent's
|
|
1268
|
+
commit carries exactly the files the player approved, and is refused as stale
|
|
1269
|
+
if one of them changed while they decided. When the
|
|
1270
|
+
branch moved meanwhile, the store rebases every edit that does not collide and
|
|
1271
|
+
lists the rest as conflicts the player settles (keep mine / take theirs). A
|
|
1272
|
+
game that runs a local dev server can implement `DraftStore` over its checkout
|
|
1273
|
+
instead. The page answers the agent's draft requests and its `preview_status`
|
|
1274
|
+
(through the host's `dshHost.previewStatus`), and boots the harness in game
|
|
1275
|
+
mode, rebooting it when the open project changes editor.
|
|
1276
|
+
|
|
1240
1277
|
## Errors
|
|
1241
1278
|
|
|
1242
1279
|
Transport and protocol failures throw structured error classes:
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*/
|
|
26
26
|
import type { CrowdyStudioController } from '../crowdy-studio/controller.js';
|
|
27
27
|
import type { PlayerHostAdapterV1 } from '../player-host/types.js';
|
|
28
|
-
import { type DshGridContext, type DshGridProgramStatus, type DshScreenshotResult } from './protocol.js';
|
|
28
|
+
import { type DshGridContext, type DshGridProgramStatus, type DshPreviewStatus, type DshScreenshotResult, type DshStudioMode } from './protocol.js';
|
|
29
29
|
import type { CrowdyStudioDshTransport, CrowdyStudioModelCatalogEntry } from './transport.js';
|
|
30
30
|
/** What the game supplies so the model can see and act. */
|
|
31
31
|
export interface CrowdyStudioDshHost {
|
|
@@ -46,6 +46,28 @@ export interface CrowdyStudioDshHost {
|
|
|
46
46
|
playerHost?: Pick<PlayerHostAdapterV1, 'observe'>;
|
|
47
47
|
/** Recent `crowdy::log` lines from the CLIENT module and browser runtime errors. */
|
|
48
48
|
clientLogs?(): readonly string[];
|
|
49
|
+
/**
|
|
50
|
+
* Where the game serves its playbook: markdown pages the agent reads with
|
|
51
|
+
* `read_playbook`, and `skills/index.json` naming the skills the game offers
|
|
52
|
+
* in the game editor (`[{ name, description, page }]`). Relative values
|
|
53
|
+
* resolve against this page. Omit when the game ships none.
|
|
54
|
+
*/
|
|
55
|
+
playbookBase?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Game editor: whether the world took the draft. Resolves with the result of
|
|
58
|
+
* the remount for `afterRevision` (or the latest), waiting up to `timeoutMs`.
|
|
59
|
+
* Omit when the game cannot report it; `preview_status` then says so.
|
|
60
|
+
*/
|
|
61
|
+
previewStatus?(input: {
|
|
62
|
+
afterRevision?: number;
|
|
63
|
+
timeoutMs: number;
|
|
64
|
+
}): Promise<DshPreviewStatus>;
|
|
65
|
+
/**
|
|
66
|
+
* Ask ck-api whether this player may draft or deploy live. The API refuses
|
|
67
|
+
* when Allow Live Modding is off. Omit and the dock's deploy is not gated
|
|
68
|
+
* here; the construct supplies it.
|
|
69
|
+
*/
|
|
70
|
+
authorizeLiveModding?(action: 'draft_test' | 'deploy_live'): Promise<void>;
|
|
49
71
|
/**
|
|
50
72
|
* Grid capability (bridge v4, DN-10). With it the agent can read the grid
|
|
51
73
|
* the open project is bound to and run a JS grid program from a project
|
|
@@ -78,6 +100,12 @@ export interface StudioDshBridgeOptions {
|
|
|
78
100
|
getToken(): string | null;
|
|
79
101
|
/** GraphQL endpoint the harness reads/writes project files through. */
|
|
80
102
|
graphqlUrl: string;
|
|
103
|
+
/**
|
|
104
|
+
* Force the editor the harness boots. Omitted, the bridge follows the
|
|
105
|
+
* controller: `game` when the open project is a Construct game with a draft
|
|
106
|
+
* store (`repositoryMode`), `mod` otherwise.
|
|
107
|
+
*/
|
|
108
|
+
studioMode?: DshStudioMode;
|
|
81
109
|
host?: CrowdyStudioDshHost;
|
|
82
110
|
/** Longest screenshot side, in pixels. */
|
|
83
111
|
maxCaptureSide?: number;
|
|
@@ -92,11 +120,27 @@ export interface StudioDshBridgeOptions {
|
|
|
92
120
|
projectName: string;
|
|
93
121
|
mode: 'draft' | 'live';
|
|
94
122
|
}): Promise<boolean>;
|
|
95
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* Ask the player, on the page, whether the agent may commit the draft: the
|
|
125
|
+
* files and the agent's message. Resolves `true` to commit. Without it
|
|
126
|
+
* `draft.commit` is refused, for the same reason as a live deploy: the
|
|
127
|
+
* approval inside the harness UI is not visible to the page.
|
|
128
|
+
*/
|
|
129
|
+
confirmCommit?(summary: {
|
|
130
|
+
projectName: string;
|
|
131
|
+
message: string;
|
|
132
|
+
files: string[];
|
|
133
|
+
deleted: string[];
|
|
134
|
+
}): Promise<boolean>;
|
|
135
|
+
/** Called when the worker changed a project file (mod editor), after the controller reloaded. */
|
|
96
136
|
onFileChanged?(change: {
|
|
97
137
|
target: 'SERVER' | 'CLIENT';
|
|
98
138
|
path: string;
|
|
99
139
|
}): void;
|
|
140
|
+
/** Called after the agent changed the game draft. */
|
|
141
|
+
onDraftChanged?(change: {
|
|
142
|
+
paths: string[];
|
|
143
|
+
}): void;
|
|
100
144
|
onWarning?(message: string): void;
|
|
101
145
|
onStatus?(status: StudioDshBridgeStatus): void;
|
|
102
146
|
}
|
|
@@ -139,8 +183,20 @@ export declare class StudioDshBridge {
|
|
|
139
183
|
private status;
|
|
140
184
|
/** One live-deploy question at a time: a second request must not replace the first prompt. */
|
|
141
185
|
private liveDeployPending;
|
|
186
|
+
/** One commit question at a time, for the same reason. */
|
|
187
|
+
private commitPending;
|
|
188
|
+
/** The editor this boot mounted; fixed until the harness reboots. */
|
|
189
|
+
private mode;
|
|
190
|
+
/** The draft store whose changes are forwarded as `page.draftChanged`. */
|
|
191
|
+
private watchedDraft;
|
|
192
|
+
private draftUnsubscribe;
|
|
193
|
+
private skills;
|
|
142
194
|
constructor(options: StudioDshBridgeOptions);
|
|
143
195
|
get currentStatus(): StudioDshBridgeStatus;
|
|
196
|
+
/** The editor the harness was booted with (`game` edits the bound Construct game). */
|
|
197
|
+
get studioMode(): DshStudioMode;
|
|
198
|
+
/** The editor the controller wants now; differs from {@link studioMode} when the harness must reboot. */
|
|
199
|
+
desiredStudioMode(): DshStudioMode;
|
|
144
200
|
/** The models the harness was booted with. */
|
|
145
201
|
get catalog(): readonly CrowdyStudioModelCatalogEntry[];
|
|
146
202
|
/**
|
|
@@ -162,6 +218,11 @@ export declare class StudioDshBridge {
|
|
|
162
218
|
/** Re-send the token (the page refreshed it). */
|
|
163
219
|
tokenChanged(): void;
|
|
164
220
|
private bootMessage;
|
|
221
|
+
/**
|
|
222
|
+
* Sessions of the two editors never share a store: a game session restored
|
|
223
|
+
* into a mod boot would talk about files and tools that are not there.
|
|
224
|
+
*/
|
|
225
|
+
private persistScope;
|
|
165
226
|
private openChannel;
|
|
166
227
|
private hello;
|
|
167
228
|
private emit;
|
|
@@ -170,13 +231,21 @@ export declare class StudioDshBridge {
|
|
|
170
231
|
private handle;
|
|
171
232
|
private onWorkerEvent;
|
|
172
233
|
private dispatch;
|
|
234
|
+
private requireDraft;
|
|
235
|
+
/** The commit gate: the player sees the files and the agent's message, and says yes on the page. */
|
|
236
|
+
private commitDraft;
|
|
237
|
+
/** The skills the game offers in the game editor, from `<playbookBase>skills/index.json`. */
|
|
238
|
+
private listSkills;
|
|
239
|
+
private readPlaybook;
|
|
173
240
|
private gridHost;
|
|
174
241
|
private build;
|
|
175
242
|
private runtimeStatus;
|
|
176
243
|
private screenshot;
|
|
177
244
|
private watchController;
|
|
245
|
+
/** Forward every change of the open game draft, the agent's own writes included. */
|
|
246
|
+
private watchDraft;
|
|
178
247
|
private setStatus;
|
|
179
248
|
}
|
|
180
249
|
/** Render the harness settings that point its native adapter at the metered endpoint. */
|
|
181
|
-
export declare function renderSettingsYaml(modelBaseUrl: string, models: readonly CrowdyStudioModelCatalogEntry[]): string;
|
|
250
|
+
export declare function renderSettingsYaml(modelBaseUrl: string, models: readonly CrowdyStudioModelCatalogEntry[], mode?: DshStudioMode): string;
|
|
182
251
|
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/crowdy-dsh/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,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CAAC,aAAa;YAgDP,QAAQ;IAuJtB,OAAO,CAAC,YAAY;IAQpB,oGAAoG;YACtF,WAAW;IAqCzB,6FAA6F;YAC/E,UAAU;YA8BV,YAAY;IAc1B,OAAO,CAAC,QAAQ;YAMF,KAAK;IA+BnB,OAAO,CAAC,aAAa;YAYP,UAAU;IAoBxB,OAAO,CAAC,eAAe;IAwBvB,oFAAoF;IACpF,OAAO,CAAC,UAAU;IAiBlB,OAAO,CAAC,SAAS;CAIlB;AAgED,yFAAyF;AACzF,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,SAAS,6BAA6B,EAAE,EAChD,IAAI,GAAE,aAAqB,GAC1B,MAAM,CAwBR"}
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
* its own origin with a `MessageChannel` relay is tracked as a follow-up.
|
|
25
25
|
*/
|
|
26
26
|
import { CROWDY_DSH_PROTOCOL_VERSION, isDshBridgeFrame, isDshFrameMessage, } from './protocol.js';
|
|
27
|
+
import { assertPlaybookPage } from './game-paths.js';
|
|
28
|
+
import { DraftError } from '../crowdy-studio/draft/index.js';
|
|
27
29
|
const DEFAULT_MAX_SIDE = 1280;
|
|
28
30
|
const HELLO_DEBOUNCE_MS = 1500;
|
|
29
31
|
export class StudioDshBridge {
|
|
@@ -50,10 +52,26 @@ export class StudioDshBridge {
|
|
|
50
52
|
this.status = { phase: 'idle' };
|
|
51
53
|
/** One live-deploy question at a time: a second request must not replace the first prompt. */
|
|
52
54
|
this.liveDeployPending = false;
|
|
55
|
+
/** One commit question at a time, for the same reason. */
|
|
56
|
+
this.commitPending = false;
|
|
57
|
+
/** The editor this boot mounted; fixed until the harness reboots. */
|
|
58
|
+
this.mode = 'mod';
|
|
59
|
+
/** The draft store whose changes are forwarded as `page.draftChanged`. */
|
|
60
|
+
this.watchedDraft = null;
|
|
61
|
+
this.draftUnsubscribe = null;
|
|
62
|
+
this.skills = null;
|
|
53
63
|
}
|
|
54
64
|
get currentStatus() {
|
|
55
65
|
return this.status;
|
|
56
66
|
}
|
|
67
|
+
/** The editor the harness was booted with (`game` edits the bound Construct game). */
|
|
68
|
+
get studioMode() {
|
|
69
|
+
return this.mode;
|
|
70
|
+
}
|
|
71
|
+
/** The editor the controller wants now; differs from {@link studioMode} when the harness must reboot. */
|
|
72
|
+
desiredStudioMode() {
|
|
73
|
+
return this.options.studioMode ?? (this.options.controller.getState().repositoryMode ? 'game' : 'mod');
|
|
74
|
+
}
|
|
57
75
|
/** The models the harness was booted with. */
|
|
58
76
|
get catalog() {
|
|
59
77
|
return this.models;
|
|
@@ -65,12 +83,20 @@ export class StudioDshBridge {
|
|
|
65
83
|
async attach(frame) {
|
|
66
84
|
this.detach();
|
|
67
85
|
this.setStatus({ phase: 'waiting-for-frame' });
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
86
|
+
// The editor is a boot-time choice: the boot message waits until the
|
|
87
|
+
// controller knows it. The frame listener goes in first so a harness that
|
|
88
|
+
// says `ready` early is still answered.
|
|
89
|
+
const prepared = (async () => {
|
|
90
|
+
await this.options.controller.whenEditorKnown();
|
|
91
|
+
this.mode = this.desiredStudioMode();
|
|
92
|
+
this.models = await this.options.transport.models(this.options.appId);
|
|
93
|
+
if (this.models.length === 0) {
|
|
94
|
+
throw new Error('No model is allowed for this app; ask the app owner to enable the Studio agent.');
|
|
95
|
+
}
|
|
96
|
+
this.connect();
|
|
97
|
+
})();
|
|
73
98
|
await new Promise((resolve, reject) => {
|
|
99
|
+
let bootPosted = false;
|
|
74
100
|
const timeout = setTimeout(() => {
|
|
75
101
|
cleanup();
|
|
76
102
|
reject(new Error('The agent did not start within 60s.'));
|
|
@@ -78,6 +104,10 @@ export class StudioDshBridge {
|
|
|
78
104
|
const cleanup = () => {
|
|
79
105
|
clearTimeout(timeout);
|
|
80
106
|
};
|
|
107
|
+
prepared.catch((error) => {
|
|
108
|
+
cleanup();
|
|
109
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
110
|
+
});
|
|
81
111
|
this.frameListener = (event) => {
|
|
82
112
|
if (event.source !== frame.contentWindow)
|
|
83
113
|
return;
|
|
@@ -87,10 +117,11 @@ export class StudioDshBridge {
|
|
|
87
117
|
if (!isDshFrameMessage(data))
|
|
88
118
|
return;
|
|
89
119
|
if (data.type === 'crowdy-dsh:ready') {
|
|
90
|
-
if (this.booted)
|
|
120
|
+
if (this.booted || bootPosted)
|
|
91
121
|
return;
|
|
122
|
+
bootPosted = true;
|
|
92
123
|
this.setStatus({ phase: 'booting' });
|
|
93
|
-
frame.contentWindow?.postMessage(this.bootMessage(), location.origin);
|
|
124
|
+
void prepared.then(() => frame.contentWindow?.postMessage(this.bootMessage(), location.origin), () => undefined);
|
|
94
125
|
}
|
|
95
126
|
else if (data.type === 'crowdy-dsh:booted') {
|
|
96
127
|
this.booted = true;
|
|
@@ -125,6 +156,9 @@ export class StudioDshBridge {
|
|
|
125
156
|
this.frameListener = null;
|
|
126
157
|
this.unsubscribeState?.();
|
|
127
158
|
this.unsubscribeState = null;
|
|
159
|
+
this.draftUnsubscribe?.();
|
|
160
|
+
this.draftUnsubscribe = null;
|
|
161
|
+
this.watchedDraft = null;
|
|
128
162
|
if (this.tokenTimer)
|
|
129
163
|
clearInterval(this.tokenTimer);
|
|
130
164
|
this.tokenTimer = null;
|
|
@@ -164,6 +198,7 @@ export class StudioDshBridge {
|
|
|
164
198
|
const projectId = this.options.controller.getState().project?.projectId ?? '';
|
|
165
199
|
// No token here: `crowdy.json` lands in the worker's filesystem. The
|
|
166
200
|
// token follows over the channel once the worker says it is ready.
|
|
201
|
+
const persistScope = this.persistScope();
|
|
167
202
|
const crowdy = {
|
|
168
203
|
graphqlUrl: this.options.graphqlUrl,
|
|
169
204
|
appId: this.options.appId,
|
|
@@ -171,19 +206,27 @@ export class StudioDshBridge {
|
|
|
171
206
|
bridgeChannel: this.channelName,
|
|
172
207
|
bridgeNonce: this.nonce,
|
|
173
208
|
root: '/dsh/workspace',
|
|
174
|
-
persistScope
|
|
209
|
+
persistScope,
|
|
210
|
+
studioMode: this.mode,
|
|
175
211
|
};
|
|
176
212
|
return {
|
|
177
213
|
type: 'crowdy-dsh:boot',
|
|
178
214
|
files: {
|
|
179
215
|
'crowdy.json': JSON.stringify(crowdy, null, 2),
|
|
180
|
-
'settings.yaml': renderSettingsYaml(this.options.transport.modelBaseUrl, this.models),
|
|
216
|
+
'settings.yaml': renderSettingsYaml(this.options.transport.modelBaseUrl, this.models, this.mode),
|
|
181
217
|
},
|
|
182
218
|
nonce: this.nonce,
|
|
183
|
-
persistScope
|
|
219
|
+
persistScope,
|
|
184
220
|
mount: '/dsh/workspace',
|
|
185
221
|
};
|
|
186
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Sessions of the two editors never share a store: a game session restored
|
|
225
|
+
* into a mod boot would talk about files and tools that are not there.
|
|
226
|
+
*/
|
|
227
|
+
persistScope() {
|
|
228
|
+
return this.mode === 'game' ? `${this.options.persistScope}/game` : this.options.persistScope;
|
|
229
|
+
}
|
|
187
230
|
// ── channel ─────────────────────────────────────────────────────────────────
|
|
188
231
|
openChannel() {
|
|
189
232
|
this.channel = new BroadcastChannel(this.channelName);
|
|
@@ -217,7 +260,9 @@ export class StudioDshBridge {
|
|
|
217
260
|
}
|
|
218
261
|
fail(id, error) {
|
|
219
262
|
const message = error instanceof Error ? error.message : String(error);
|
|
220
|
-
|
|
263
|
+
// A draft failure carries a stable code the worker maps onto its filesystem errors.
|
|
264
|
+
const code = error instanceof DraftError ? error.code : 'PAGE_ERROR';
|
|
265
|
+
const frame = { v: CROWDY_DSH_PROTOCOL_VERSION, n: this.nonce, from: 'page', t: 'err', id, code, message };
|
|
221
266
|
this.channel?.postMessage(frame);
|
|
222
267
|
}
|
|
223
268
|
async handle(data) {
|
|
@@ -249,6 +294,10 @@ export class StudioDshBridge {
|
|
|
249
294
|
case 'worker.ready': {
|
|
250
295
|
const ready = payload;
|
|
251
296
|
this.setStatus({ phase: 'ready', ...(ready.store ? { store: ready.store } : {}) });
|
|
297
|
+
// A harness build that predates game mode mounts the mod crates whatever the boot said.
|
|
298
|
+
if (this.mode === 'game' && !(ready.modes ?? []).includes('game')) {
|
|
299
|
+
this.options.onWarning?.('This agent build cannot edit the game repository. Update @crowdedkingdoms/crowdy-dsh to a release with game mode.');
|
|
300
|
+
}
|
|
252
301
|
this.hello();
|
|
253
302
|
return;
|
|
254
303
|
}
|
|
@@ -263,6 +312,12 @@ export class StudioDshBridge {
|
|
|
263
312
|
}
|
|
264
313
|
case 'worker.openFile': {
|
|
265
314
|
const ref = payload;
|
|
315
|
+
if (ref.target === 'REPO' || this.options.controller.getState().repositoryMode) {
|
|
316
|
+
void this.options.controller.openRepositoryFile(ref.path).catch(() => {
|
|
317
|
+
// The draft may not have the file yet; the tree shows what it listed.
|
|
318
|
+
});
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
266
321
|
try {
|
|
267
322
|
this.options.controller.openFile({ source: 'PROJECT', target: ref.target, path: ref.path });
|
|
268
323
|
}
|
|
@@ -378,10 +433,154 @@ export class StudioDshBridge {
|
|
|
378
433
|
}
|
|
379
434
|
case 'grid.programStatus':
|
|
380
435
|
return { programs: this.gridHost().programs() };
|
|
436
|
+
case 'studio.readPlaybook':
|
|
437
|
+
return this.readPlaybook(params?.page ?? '');
|
|
438
|
+
case 'studio.listSkills':
|
|
439
|
+
return { skills: await this.listSkills() };
|
|
440
|
+
case 'draft.tree':
|
|
441
|
+
return this.requireDraft().snapshot();
|
|
442
|
+
case 'draft.read': {
|
|
443
|
+
const { paths } = params;
|
|
444
|
+
if (!Array.isArray(paths) || paths.length > 200 || !paths.every((p) => typeof p === 'string')) {
|
|
445
|
+
throw new DraftError('DRAFT_PATH_REFUSED', 'draft.read takes 1 to 200 paths.');
|
|
446
|
+
}
|
|
447
|
+
return (await this.requireDraft().read(paths));
|
|
448
|
+
}
|
|
449
|
+
case 'draft.write': {
|
|
450
|
+
const { path, content, precondition } = params;
|
|
451
|
+
if (typeof path !== 'string' || typeof content !== 'string') {
|
|
452
|
+
throw new DraftError('DRAFT_PATH_REFUSED', 'draft.write takes a path and text content.');
|
|
453
|
+
}
|
|
454
|
+
const result = await this.requireDraft().write(path, content, { source: 'agent', precondition });
|
|
455
|
+
this.options.onDraftChanged?.({ paths: [result.path] });
|
|
456
|
+
return result;
|
|
457
|
+
}
|
|
458
|
+
case 'draft.delete': {
|
|
459
|
+
const { path, precondition } = params;
|
|
460
|
+
const result = await this.requireDraft().remove(path, { source: 'agent', precondition });
|
|
461
|
+
this.options.onDraftChanged?.({ paths: [result.path] });
|
|
462
|
+
return result;
|
|
463
|
+
}
|
|
464
|
+
case 'draft.commit':
|
|
465
|
+
return (await this.commitDraft(params));
|
|
466
|
+
case 'preview.status': {
|
|
467
|
+
const { afterRevision, timeoutMs } = (params ?? {});
|
|
468
|
+
const wait = Math.min(Math.max(Number(timeoutMs) || 10000, 1000), 60000);
|
|
469
|
+
const preview = this.options.host?.previewStatus;
|
|
470
|
+
if (!preview) {
|
|
471
|
+
return {
|
|
472
|
+
revision: this.requireDraft().snapshot().revision,
|
|
473
|
+
ok: true,
|
|
474
|
+
errors: [],
|
|
475
|
+
note: 'This game does not report whether the world took the draft; ask the player or take a screenshot.',
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
return (await preview({ ...(afterRevision !== undefined ? { afterRevision } : {}), timeoutMs: wait }));
|
|
479
|
+
}
|
|
381
480
|
default:
|
|
382
481
|
throw new Error(`Unsupported bridge method ${String(method)}`);
|
|
383
482
|
}
|
|
384
483
|
}
|
|
484
|
+
requireDraft() {
|
|
485
|
+
const draft = this.options.controller.draftStore;
|
|
486
|
+
if (!draft) {
|
|
487
|
+
throw new DraftError('DRAFT_UNAVAILABLE', 'The open project has no game draft; this is the mod editor.');
|
|
488
|
+
}
|
|
489
|
+
return draft;
|
|
490
|
+
}
|
|
491
|
+
/** The commit gate: the player sees the files and the agent's message, and says yes on the page. */
|
|
492
|
+
async commitDraft(params) {
|
|
493
|
+
const message = typeof params.message === 'string' ? params.message.trim() : '';
|
|
494
|
+
if (!message)
|
|
495
|
+
throw new DraftError('DRAFT_PATH_REFUSED', 'A commit needs a message describing the change.');
|
|
496
|
+
const paths = Array.isArray(params.paths) ? params.paths.filter((p) => typeof p === 'string') : undefined;
|
|
497
|
+
const confirm = this.options.confirmCommit;
|
|
498
|
+
if (!confirm) {
|
|
499
|
+
throw new DraftError('DRAFT_DECLINED', 'Commits from the agent are not enabled on this page; use Commit in Crowdy Studio.');
|
|
500
|
+
}
|
|
501
|
+
if (this.commitPending)
|
|
502
|
+
throw new DraftError('DRAFT_DECLINED', 'A commit is already waiting for the player. Wait for it before asking again.');
|
|
503
|
+
this.commitPending = true;
|
|
504
|
+
try {
|
|
505
|
+
const draft = this.requireDraft();
|
|
506
|
+
const snapshot = draft.snapshot();
|
|
507
|
+
const wanted = paths && paths.length > 0 ? new Set(paths) : null;
|
|
508
|
+
const files = snapshot.entries.filter((e) => e.dirty && (!wanted || wanted.has(e.path))).map((e) => e.path);
|
|
509
|
+
const deleted = snapshot.deleted.filter((p) => !wanted || wanted.has(p));
|
|
510
|
+
if (files.length + deleted.length === 0)
|
|
511
|
+
throw new DraftError('DRAFT_NOT_FOUND', 'The draft has nothing to commit.');
|
|
512
|
+
const projectName = this.options.controller.getState().project?.metadata.name ?? 'this game';
|
|
513
|
+
if (!(await confirm({ projectName, message, files, deleted }))) {
|
|
514
|
+
throw new DraftError('DRAFT_DECLINED', 'The player declined the commit. The draft is unchanged; ask before committing again.');
|
|
515
|
+
}
|
|
516
|
+
// Exactly what the player approved: a write made while they decided stays in the draft,
|
|
517
|
+
// and an approved file that changed meanwhile is not committed unseen.
|
|
518
|
+
const approved = [...files, ...deleted];
|
|
519
|
+
const after = draft.snapshot();
|
|
520
|
+
const versionIn = (view, path) => view.deleted.includes(path) ? null : (view.entries.find((e) => e.path === path)?.hash ?? null);
|
|
521
|
+
const changed = approved.filter((path) => versionIn(snapshot, path) !== versionIn(after, path));
|
|
522
|
+
if (changed.length > 0) {
|
|
523
|
+
throw new DraftError('DRAFT_STALE', `${changed.join(', ')} changed while the player was deciding; ask to commit again.`);
|
|
524
|
+
}
|
|
525
|
+
return await this.options.controller.commitRepository({ message, paths: approved });
|
|
526
|
+
}
|
|
527
|
+
finally {
|
|
528
|
+
this.commitPending = false;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
/** The skills the game offers in the game editor, from `<playbookBase>skills/index.json`. */
|
|
532
|
+
async listSkills() {
|
|
533
|
+
if (this.skills)
|
|
534
|
+
return this.skills;
|
|
535
|
+
const configured = this.options.host?.playbookBase;
|
|
536
|
+
if (!configured)
|
|
537
|
+
return [];
|
|
538
|
+
const root = playbookRoot(configured);
|
|
539
|
+
let body;
|
|
540
|
+
try {
|
|
541
|
+
const response = await fetch(new URL('skills/index.json', root));
|
|
542
|
+
if (!response.ok)
|
|
543
|
+
return [];
|
|
544
|
+
body = await response.json();
|
|
545
|
+
}
|
|
546
|
+
catch {
|
|
547
|
+
return [];
|
|
548
|
+
}
|
|
549
|
+
const listed = body?.skills;
|
|
550
|
+
const skills = [];
|
|
551
|
+
for (const raw of Array.isArray(listed) ? listed : []) {
|
|
552
|
+
const entry = raw;
|
|
553
|
+
if (typeof entry.name !== 'string' || !/^[a-z0-9][a-z0-9-]{0,63}$/.test(entry.name))
|
|
554
|
+
continue;
|
|
555
|
+
if (typeof entry.description !== 'string' || !entry.description.trim())
|
|
556
|
+
continue;
|
|
557
|
+
if (typeof entry.page !== 'string')
|
|
558
|
+
continue;
|
|
559
|
+
try {
|
|
560
|
+
skills.push({ name: entry.name, description: entry.description.trim().slice(0, 500), page: assertPlaybookPage(entry.page) });
|
|
561
|
+
}
|
|
562
|
+
catch {
|
|
563
|
+
// A page outside the shipped tree is not offered.
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
this.skills = skills;
|
|
567
|
+
return skills;
|
|
568
|
+
}
|
|
569
|
+
async readPlaybook(page) {
|
|
570
|
+
const safe = assertPlaybookPage(page);
|
|
571
|
+
const configured = this.options.host?.playbookBase;
|
|
572
|
+
if (!configured)
|
|
573
|
+
throw new Error('This game does not ship a playbook.');
|
|
574
|
+
const root = playbookRoot(configured);
|
|
575
|
+
const url = new URL(safe, root);
|
|
576
|
+
if (url.origin !== root.origin || !url.pathname.startsWith(root.pathname)) {
|
|
577
|
+
throw new Error('Playbook pages stay inside the game.');
|
|
578
|
+
}
|
|
579
|
+
const response = await fetch(url);
|
|
580
|
+
if (!response.ok)
|
|
581
|
+
throw new Error(`No playbook page ${safe}.`);
|
|
582
|
+
return { text: await response.text() };
|
|
583
|
+
}
|
|
385
584
|
gridHost() {
|
|
386
585
|
const grid = this.options.host?.grid;
|
|
387
586
|
if (!grid)
|
|
@@ -392,6 +591,9 @@ export class StudioDshBridge {
|
|
|
392
591
|
const controller = this.options.controller;
|
|
393
592
|
if (!controller.getState().project)
|
|
394
593
|
throw new Error('No project is open in Crowdy Studio.');
|
|
594
|
+
const authorize = this.options.host?.authorizeLiveModding;
|
|
595
|
+
if (authorize)
|
|
596
|
+
await authorize(mode === 'draft' ? 'draft_test' : 'deploy_live');
|
|
395
597
|
const result = mode === 'draft' ? await controller.testDraft() : await controller.deployLive();
|
|
396
598
|
const state = controller.getState();
|
|
397
599
|
const diagnostics = [...state.authoritativeDiagnostics, ...state.localDiagnostics].map(toDshDiagnostic);
|
|
@@ -468,9 +670,29 @@ export class StudioDshBridge {
|
|
|
468
670
|
this.emit('page.saved', { revision: state.project?.revision.id, githubSha });
|
|
469
671
|
}
|
|
470
672
|
this.lastSaveState = state.saveState;
|
|
673
|
+
this.watchDraft();
|
|
471
674
|
});
|
|
472
675
|
this.tokenTimer = setInterval(() => this.tokenChanged(), 20000);
|
|
473
676
|
}
|
|
677
|
+
/** Forward every change of the open game draft, the agent's own writes included. */
|
|
678
|
+
watchDraft() {
|
|
679
|
+
const draft = this.options.controller.draftStore;
|
|
680
|
+
if (draft === this.watchedDraft)
|
|
681
|
+
return;
|
|
682
|
+
this.draftUnsubscribe?.();
|
|
683
|
+
this.draftUnsubscribe = null;
|
|
684
|
+
this.watchedDraft = draft;
|
|
685
|
+
if (!draft)
|
|
686
|
+
return;
|
|
687
|
+
this.draftUnsubscribe = draft.subscribe((event) => {
|
|
688
|
+
this.emit('page.draftChanged', {
|
|
689
|
+
revision: event.revision,
|
|
690
|
+
baseCommitSha: event.baseCommitSha,
|
|
691
|
+
changes: event.changes,
|
|
692
|
+
source: event.source,
|
|
693
|
+
});
|
|
694
|
+
});
|
|
695
|
+
}
|
|
474
696
|
setStatus(status) {
|
|
475
697
|
this.status = status;
|
|
476
698
|
this.options.onStatus?.(status);
|
|
@@ -533,7 +755,7 @@ function summarizeProject(project) {
|
|
|
533
755
|
};
|
|
534
756
|
}
|
|
535
757
|
/** Render the harness settings that point its native adapter at the metered endpoint. */
|
|
536
|
-
export function renderSettingsYaml(modelBaseUrl, models) {
|
|
758
|
+
export function renderSettingsYaml(modelBaseUrl, models, mode = 'mod') {
|
|
537
759
|
const quote = (value) => JSON.stringify(value);
|
|
538
760
|
const lines = [
|
|
539
761
|
'# Written by Crowdy Studio at boot; the metered model endpoint fronts the platform key.',
|
|
@@ -555,8 +777,17 @@ export function renderSettingsYaml(modelBaseUrl, models) {
|
|
|
555
777
|
if (first) {
|
|
556
778
|
lines.push('agent-default-model:', ' provider: deepseek-official', ` model: ${quote(first.id)}`);
|
|
557
779
|
}
|
|
780
|
+
// The game editor is its own agent preset; the mod editor keeps the image's default.
|
|
781
|
+
if (mode === 'game')
|
|
782
|
+
lines.push('agent-presets:', ' default: crowdy-game');
|
|
558
783
|
return `${lines.join('\n')}\n`;
|
|
559
784
|
}
|
|
785
|
+
function playbookRoot(base) {
|
|
786
|
+
const withSlash = base.endsWith('/') ? base : `${base}/`;
|
|
787
|
+
if (/^https?:\/\//.test(withSlash))
|
|
788
|
+
return new URL(withSlash);
|
|
789
|
+
return new URL(withSlash, location.origin);
|
|
790
|
+
}
|
|
560
791
|
/** Downscale and PNG-encode a frame in the page. */
|
|
561
792
|
async function encodePng(source, maxSide) {
|
|
562
793
|
let bitmap;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Playbook pages the agent may read: markdown the game ships under its
|
|
3
|
+
* `playbookBase`. Which repository paths the game editor may touch is
|
|
4
|
+
* `crowdy-studio/draft/paths.ts`.
|
|
5
|
+
*/
|
|
6
|
+
/** A relative markdown page under the playbook root. Refuses anything that leaves that tree. */
|
|
7
|
+
export declare function assertPlaybookPage(page: string): string;
|
|
8
|
+
//# sourceMappingURL=game-paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"game-paths.d.ts","sourceRoot":"","sources":["../../src/crowdy-dsh/game-paths.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gGAAgG;AAChG,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAevD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Playbook pages the agent may read: markdown the game ships under its
|
|
3
|
+
* `playbookBase`. Which repository paths the game editor may touch is
|
|
4
|
+
* `crowdy-studio/draft/paths.ts`.
|
|
5
|
+
*/
|
|
6
|
+
/** A relative markdown page under the playbook root. Refuses anything that leaves that tree. */
|
|
7
|
+
export function assertPlaybookPage(page) {
|
|
8
|
+
const trimmed = page.trim().replace(/^\/+/, '');
|
|
9
|
+
if (!trimmed ||
|
|
10
|
+
trimmed.includes('..') ||
|
|
11
|
+
trimmed.includes('\\') ||
|
|
12
|
+
/[?#\0]/.test(trimmed) ||
|
|
13
|
+
trimmed.startsWith('.')) {
|
|
14
|
+
throw new Error('Playbook pages are markdown files shipped with the game.');
|
|
15
|
+
}
|
|
16
|
+
if (!/^[\w./-]+\.md$/.test(trimmed)) {
|
|
17
|
+
throw new Error('Name a playbook page such as playbook/authoring-loop.md.');
|
|
18
|
+
}
|
|
19
|
+
return trimmed;
|
|
20
|
+
}
|