dewctl 0.9.1 → 0.9.3
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 +33 -20
- package/examples/.agents/skills/look/SKILL.md +9 -6
- package/examples/AGENTS.md +61 -24
- package/package.json +1 -1
- package/src/client.js +13 -12
- package/src/logs.js +10 -5
- package/src/main.js +31 -26
- package/src/project.js +13 -13
- package/src/session.js +21 -13
- package/src/watch.js +6 -5
package/README.md
CHANGED
|
@@ -11,8 +11,10 @@ docs: https://alpha.dewdrop.world/docs
|
|
|
11
11
|
`dewctl logs` prints the dev version's recent console (the game's page and
|
|
12
12
|
backend lines, and how each seat's session ended), with positions in the built
|
|
13
13
|
code shown in your source by the last build's source maps; `--follow` keeps
|
|
14
|
-
printing. `dewctl dev` prints the same at a terminal and with `--watch
|
|
15
|
-
|
|
14
|
+
printing. `dewctl dev` prints the same at a terminal and with `--watch`, but
|
|
15
|
+
not with `--release`, and in a script returns once the upload is ready to play.
|
|
16
|
+
Source maps (`.map` files) are never uploaded: they stay on your computer
|
|
17
|
+
([Console and logs](https://alpha.dewdrop.world/docs/console)).
|
|
16
18
|
|
|
17
19
|
`dewctl seat --out .dewdrop-seat.json` gets a seat pass, which opens the dev
|
|
18
20
|
version in a browser your own tools drive, and writes it to a file only you can
|
|
@@ -20,24 +22,29 @@ read. Keep the file outside the bundle folder — dewctl refuses a path inside
|
|
|
20
22
|
it, as the pass would be uploaded with the game — and out of version control;
|
|
21
23
|
a dot-file in the game's folder, as here, is also one `dewctl dev --watch`
|
|
22
24
|
doesn't rebuild for. Get a new pass at the start of each test run, right after
|
|
23
|
-
an upload: it works once, within 10 minutes. Set its
|
|
24
|
-
tool for its `url` — the cookie names no domain, so
|
|
25
|
-
alone — then open the `url
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
an upload: it works once, within 10 minutes. Set its cookie's `name` and
|
|
26
|
+
`value` with your browser tool for its `url` — the cookie names no domain, so
|
|
27
|
+
it goes to Dewdrop's host alone — then open the `url`, wait for
|
|
28
|
+
`window.dewdrop`, and await `dewdrop.ready()`. Without `--out` the pass is
|
|
29
|
+
printed, to pipe into your tool — where a terminal log or a CI log can keep it.
|
|
30
|
+
For example, in a script that drives Chrome with Puppeteer
|
|
31
|
+
([Headless browsers](https://alpha.dewdrop.world/docs/headless)):
|
|
28
32
|
|
|
29
33
|
```js
|
|
30
34
|
const pass = JSON.parse(readFileSync('.dewdrop-seat.json', 'utf8'));
|
|
31
|
-
await page.setCookie({
|
|
35
|
+
await page.setCookie({name: pass.cookie.name, value: pass.cookie.value, url: pass.url});
|
|
32
36
|
await page.goto(pass.url);
|
|
37
|
+
await page.waitForFunction(() => window.dewdrop, {timeout: 120_000});
|
|
38
|
+
await page.evaluate(() => dewdrop.ready());
|
|
33
39
|
```
|
|
34
40
|
|
|
35
|
-
Playwright
|
|
41
|
+
With Playwright:
|
|
36
42
|
|
|
37
43
|
```js
|
|
38
|
-
|
|
39
|
-
await context.addCookies([{...cookie, url: pass.url}]);
|
|
44
|
+
await context.addCookies([{name: pass.cookie.name, value: pass.cookie.value, url: pass.url}]);
|
|
40
45
|
await page.goto(pass.url);
|
|
46
|
+
await page.waitForFunction(() => window.dewdrop, null, {timeout: 120_000});
|
|
47
|
+
await page.evaluate(() => dewdrop.ready());
|
|
41
48
|
```
|
|
42
49
|
|
|
43
50
|
## Your live seats
|
|
@@ -45,7 +52,7 @@ await page.goto(pass.url);
|
|
|
45
52
|
With a seat of yours playing the dev version — a tab you opened, or a browser
|
|
46
53
|
your tools drive with a seat pass — dewctl reaches it from the terminal, as the
|
|
47
54
|
page's own console does. It reaches only your own seats, in the dev version,
|
|
48
|
-
and never starts one.
|
|
55
|
+
and never starts one ([From the terminal](https://alpha.dewdrop.world/docs/terminal)).
|
|
49
56
|
|
|
50
57
|
- `dewctl sessions` lists your seats playing, newest first. The newest is the
|
|
51
58
|
one the commands below use unless `--seat` names another.
|
|
@@ -56,22 +63,28 @@ and never starts one.
|
|
|
56
63
|
stack in your source, by the last build's source maps, and exits 1.
|
|
57
64
|
`--json` prints `{"value":…}`, `{"error":"…"}` or `{}` (undefined).
|
|
58
65
|
- `dewctl pause` and `dewctl resume` stop and start the seat's room — its
|
|
59
|
-
backend and every seat in it; `dewctl step 60`
|
|
60
|
-
|
|
61
|
-
quarter speed (at most 1
|
|
66
|
+
backend and every seat in it; `dewctl step 60` runs the room 60 frames,
|
|
67
|
+
paused or not, then pauses it, and returns once they are drawn;
|
|
68
|
+
`dewctl speed 0.25` runs it at a quarter speed (at most 1, rounded down to
|
|
69
|
+
1/2, 1/3, 1/4 and so on, no slower than 1/300).
|
|
62
70
|
- `dewctl repl` evaluates each line you type; `.pause`, `.resume`, `.step N`,
|
|
63
71
|
`.speed K`, `.seat S`, `.backend`, `.page`, `.help` and `.exit` do what they
|
|
64
72
|
say.
|
|
65
73
|
|
|
66
|
-
|
|
74
|
+
Code you evaluate reaches what the game puts on `globalThis`, so in the dev
|
|
75
|
+
version put the state worth checking there:
|
|
76
|
+
`if (session.dev) globalThis.game = {player, level}`. A loop an agent might
|
|
77
|
+
run — upload, seat, open, pause, look, step, look, resume
|
|
78
|
+
([For coding agents](https://alpha.dewdrop.world/docs/coding-agents)):
|
|
67
79
|
|
|
68
80
|
```sh
|
|
69
|
-
dewctl dev
|
|
70
|
-
dewctl seat --out .dewdrop-seat.json
|
|
81
|
+
dewctl dev # in a script, returns once it's ready to play
|
|
82
|
+
dewctl seat --out .dewdrop-seat.json
|
|
83
|
+
# the agent's browser tool sets the pass's cookie, opens its url and awaits dewdrop.ready()
|
|
71
84
|
dewctl pause
|
|
72
|
-
dewctl eval 'player.position'
|
|
85
|
+
dewctl eval 'game.player.position'
|
|
73
86
|
dewctl step 60
|
|
74
|
-
dewctl eval 'player.position'
|
|
87
|
+
dewctl eval 'game.player.position'
|
|
75
88
|
dewctl resume
|
|
76
89
|
```
|
|
77
90
|
|
|
@@ -171,8 +171,8 @@ One sentence: the game, its medium, its time of day and its mood.
|
|
|
171
171
|
## Style prompt
|
|
172
172
|
|
|
173
173
|
`style: clay stop motion.` Matte plasticine with thumbprints, chunky rounded shapes, saturated colors, a tabletop
|
|
174
|
-
set. (The whole prompt as it goes into `renderer.prompt`: under 4 KiB, the
|
|
175
|
-
|
|
174
|
+
set. (The whole prompt as it goes into `renderer.prompt`: under 4 KiB, the style and then the frame as the camera
|
|
175
|
+
sees it, in the meshes' colors and words. A starter's prompt stands as it is.)
|
|
176
176
|
|
|
177
177
|
## Sky
|
|
178
178
|
|
|
@@ -210,10 +210,12 @@ A line per check: the date, what was looked at, and what changed because of it.
|
|
|
210
210
|
|
|
211
211
|
### 6. Check it on Dewdrop
|
|
212
212
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
213
|
+
After the upload that carries the colors, the words and the prompt, look first yourself: open the dev version in
|
|
214
|
+
your browser tool ([for coding agents](https://alpha.dewdrop.world/docs/coding-agents)), take screenshots after the
|
|
215
|
+
first second, and check each against `LOOK.md`. A screenshot is a still frame, and without hardware acceleration a
|
|
216
|
+
half-size preview, so then ask the user to judge the look in motion, with three specific questions from `LOOK.md`:
|
|
217
|
+
"Is the grass a bright plasticine green? Does the lamp glow? Is the sky a plain pale backdrop?" Put what you saw
|
|
218
|
+
and the answers under "Checked on Dewdrop", and change the code and `LOOK.md` together, one thing at a time.
|
|
217
219
|
|
|
218
220
|
## Dewdrop's terms
|
|
219
221
|
|
|
@@ -228,6 +230,7 @@ What a wish turns into. The [renderer](https://alpha.dewdrop.world/docs/renderer
|
|
|
228
230
|
| more detail, more realistic | more meshes and truer shapes, the biggest where the camera goes |
|
|
229
231
|
| fog, mist, rain, god rays | words in the prompt and the sky; colors faded with distance |
|
|
230
232
|
| smoke, steam | words alone; no mesh works for them |
|
|
233
|
+
| dust kicked up | a few big soft puffs |
|
|
231
234
|
| wood grain, fabric, rust, any texture | the material in the words; a texture file shows nothing |
|
|
232
235
|
| glow, neon, fire, a lit window | a bright saturated mesh described as glowing; a three.js light shows nothing |
|
|
233
236
|
| glass, a window | a mid blue-grey with the sky in its words; an unlit window is an opening with something behind it |
|
package/examples/AGENTS.md
CHANGED
|
@@ -32,7 +32,8 @@ Dewdrop renders the game from what is in the three.js scene ([renderer](https://
|
|
|
32
32
|
Textures, vertex colors, emissive colors, lights, shadows, fog, custom shaders, points, lines and sprites don't
|
|
33
33
|
show on Dewdrop. The prompt is at most 4 KiB, the background description and each description at most 1 KiB. A
|
|
34
34
|
scene draws at most 65,536 objects: each mesh counts once, and so does each instance.
|
|
35
|
-
The view is 16:9 (
|
|
35
|
+
The view is 16:9, or 9:16 on a phone held upright once the game calls `session.allowPortrait()`
|
|
36
|
+
([phones held upright](https://alpha.dewdrop.world/docs/sessions#phones-held-upright)).
|
|
36
37
|
|
|
37
38
|
## 3. The rules that matter most
|
|
38
39
|
|
|
@@ -52,13 +53,15 @@ A new look usually means changing the first three together.
|
|
|
52
53
|
([descriptions](https://alpha.dewdrop.world/docs/renderer#descriptions)).
|
|
53
54
|
- A group's description reaches every mesh under it that has none of its own; `null` gives none, and a mesh's
|
|
54
55
|
`name` is never used ([scene graph](https://alpha.dewdrop.world/docs/descriptions)).
|
|
55
|
-
- **
|
|
56
|
+
- **The prompt describes the frame as the camera sees it:** what's in the middle and what's where, in the meshes'
|
|
57
|
+
colors and words. A prompt that describes an object differently fights its mesh, and it can't override the colors.
|
|
56
58
|
- **Dewdrop keeps your shapes.** A style made of shapes needs them: cubes for voxel, folded flat faces for paper,
|
|
57
59
|
rounded lumpy forms for clay. A realistic look needs realistic shapes. A face needs eye and nose meshes. Build the
|
|
58
60
|
letters you want read ([shapes](https://alpha.dewdrop.world/docs/renderer#shapes)).
|
|
59
61
|
- **A light is a mesh.** Three.js lights don't show on Dewdrop. Give a lamp or candle a bright mesh described as
|
|
60
|
-
glowing. Night is every surface at about a fifth of its daylight color, with the lights in view.
|
|
61
|
-
|
|
62
|
+
glowing. Night is every surface at about a fifth of its daylight color, with the lights in view. Warmth comes from
|
|
63
|
+
color; say the same light in every description, and a light's own words light the frame, as a hand "holding a lit
|
|
64
|
+
candle" does. A shadow is a thin dark mesh on the ground
|
|
62
65
|
([light and shadow](https://alpha.dewdrop.world/docs/renderer#light-and-shadow)).
|
|
63
66
|
- **The sky is the background.** Describe it in `renderer.backgroundDescription`, not the prompt, with a matching
|
|
64
67
|
`scene.background` color. A gradient and the sun come from the words; a sun disc mesh shows as a flat coin. Big
|
|
@@ -70,7 +73,8 @@ A new look usually means changing the first three together.
|
|
|
70
73
|
parts a few meters from anywhere the camera goes. In first person, hold items 0.6 to 0.7 m from the camera, as
|
|
71
74
|
its children ([camera](https://alpha.dewdrop.world/docs/camera)).
|
|
72
75
|
- **Small moving things smear.** Make what matters large in frame. Fish, flocks and sparks: muted, about 0.6 m long
|
|
73
|
-
or more, 8 m or more from the camera. Smoke and steam can't be built
|
|
76
|
+
or more, 8 m or more from the camera. Smoke and steam can't be built; dust kicked up is a few big soft puffs.
|
|
77
|
+
Turn flat things to face the camera
|
|
74
78
|
([what to watch for](https://alpha.dewdrop.world/docs/renderer#what-to-watch-for)).
|
|
75
79
|
- To find which mesh became a blob, give the suspects a loud color such as magenta for a moment, and check again.
|
|
76
80
|
|
|
@@ -79,8 +83,9 @@ The code ([limits](https://alpha.dewdrop.world/docs/limits)):
|
|
|
79
83
|
that passed, don't cap a frame's time below about 0.25 s, and step in small fixed steps.
|
|
80
84
|
- `index.html`'s own scripts don't run. Leave `html` and `body` without a background, and don't set
|
|
81
85
|
`color-scheme: dark`. Put what the page shows under `public/ui/`, or import it.
|
|
82
|
-
- `fetch` reads only the game's own files. WebSocket
|
|
83
|
-
|
|
86
|
+
- `fetch` reads only the game's own files. WebSocket and WebRTC aren't available; web workers work, up to 8 at
|
|
87
|
+
once ([what works](https://alpha.dewdrop.world/docs/limits#your-code)). Sound plays through
|
|
88
|
+
Web Audio, `<audio>` and `new Audio()`; a `<video>` plays its sound but shows no picture.
|
|
84
89
|
- `localStorage` and `indexedDB` throw. Storage is `saves.storage` and `saves.indexedDB` from `dewdrop-sdk`, open
|
|
85
90
|
once `await saves.load()` is done, and kept only by `await saves.save()` ([saves](https://alpha.dewdrop.world/docs/saves)).
|
|
86
91
|
- `sessionStorage`, `location` navigation, and `alert`, `confirm` and `prompt` throw: keep state in memory, restart in the
|
|
@@ -99,27 +104,59 @@ in its dev version; there is no local preview.
|
|
|
99
104
|
4. **Style prompt:** set the prompt for the whole game, and the sky.
|
|
100
105
|
|
|
101
106
|
After each step, upload with `npm run dev`: it builds the game, uploads it and prints the link to play it on
|
|
102
|
-
Dewdrop. Upload when there is something to check, not after
|
|
103
|
-
every save uploads by itself, so don't upload as well: both
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
Dewdrop; in a script it returns once the game is ready to play. Upload when there is something to check, not after
|
|
108
|
+
every edit. If the user runs `npx dewctl dev --watch`, every save uploads by itself, so don't upload as well: both
|
|
109
|
+
build into the same folder.
|
|
110
|
+
|
|
111
|
+
Check each upload yourself first (section 5): read the game's state, step it, and take screenshots. Then ask the
|
|
112
|
+
user specific questions about it in motion ("Does the lantern glow as you walk past?", "What does the sky look
|
|
113
|
+
like?"): the user judges the look in motion, not from a still frame. Change one thing at a time, so you know what
|
|
114
|
+
each change did.
|
|
115
|
+
|
|
116
|
+
## 5. Check it yourself
|
|
117
|
+
|
|
118
|
+
You can play the dev version in a browser tool and work it from the terminal
|
|
119
|
+
([for coding agents](https://alpha.dewdrop.world/docs/coding-agents)).
|
|
120
|
+
|
|
121
|
+
1. In the dev version only, put the state worth checking on `globalThis`: code you run reaches nothing else.
|
|
122
|
+
`if (session.dev) globalThis.game = {player, level}`, with `session` from `dewdrop-sdk`.
|
|
123
|
+
2. Right after uploading, `npx dewctl seat --out .dewdrop-seat.json` gets a pass. It works once, within 10
|
|
124
|
+
minutes. Keep the file out of git and out of the build folder.
|
|
125
|
+
3. In a browser tool (headless is fine), set the pass's cookie, its `name` and `value`, for its `url`. Open the
|
|
126
|
+
`url`, wait for `window.dewdrop`, then `await dewdrop.ready()`. Keep that page in front, and give each player a
|
|
127
|
+
browser of its own. Each upload reloads the page: wait for `ready()` again
|
|
128
|
+
([headless browsers](https://alpha.dewdrop.world/docs/headless)).
|
|
129
|
+
4. Take screenshots after the first second, which is plain and grey. Without hardware acceleration the browser
|
|
130
|
+
gets a half-size preview at up to 5 frames a second: fine for layout and state, so let the user judge the look
|
|
131
|
+
in motion.
|
|
132
|
+
|
|
133
|
+
From the terminal ([commands](https://alpha.dewdrop.world/docs/terminal)):
|
|
134
|
+
- `npx dewctl sessions` lists your seats, newest first. `npx dewctl eval '<code>'` runs code in the newest and
|
|
135
|
+
prints the value: `--seat` names another seat, `--backend` runs it in the room's backend, and `--json` prints
|
|
136
|
+
JSON. An error prints its stack in your source.
|
|
137
|
+
- `npx dewctl pause`, `step N` (1 to 600: it runs N frames, then the room stays paused), `speed K` (above 0, at
|
|
138
|
+
most 1) and `resume` work the seat's whole room. `npx dewctl repl` is a console.
|
|
139
|
+
- While paused nothing moves: evaluate, `step 1`, evaluate again. Each stepped frame is 1/30 s of game time.
|
|
140
|
+
- To hold a key for 30 frames, evaluate
|
|
141
|
+
`document.dispatchEvent(new KeyboardEvent('keydown', {code: 'ArrowRight', key: 'ArrowRight', bubbles: true}))`,
|
|
142
|
+
`step 30`, then dispatch its `keyup` the same way.
|
|
143
|
+
- `npx dewctl logs` prints every seat's and the backend's console and how each session ended, with stacks in your
|
|
144
|
+
source. Read it while the game plays, or keep `--follow` running
|
|
145
|
+
([console](https://alpha.dewdrop.world/docs/console)).
|
|
146
|
+
|
|
147
|
+
In the page, `dewdrop.evaluate`, `pause`, `step`, `speed` and `resume` do the same, and `dewdrop.heap()` reads the
|
|
148
|
+
memory the game uses ([run code and step frames](https://alpha.dewdrop.world/docs/inspect)). Limits: 4 headless
|
|
149
|
+
players at once (`?as=5` to `?as=8`), about 120 evaluates a minute, and 600 stepped frames a minute for each room.
|
|
150
|
+
|
|
151
|
+
## 6. The project
|
|
113
152
|
|
|
114
153
|
- `dewdrop.json` connects the folder to the game: its name, the build command, the folder the build writes, and
|
|
115
154
|
the thumbnail ([dewdrop.json](https://alpha.dewdrop.world/docs/dewdrop-json)).
|
|
116
155
|
- `npm run dev` uploads the game to its dev version on Dewdrop once; `npx dewctl dev --watch` uploads it again on
|
|
117
|
-
every save. `npx dewctl
|
|
118
|
-
game
|
|
119
|
-
of getting it, so get a new one for each run. `npx dewctl status` shows both versions. Run `npx dewctl publish` only when the user asks: it puts the game
|
|
120
|
-
in front of players ([commands](https://alpha.dewdrop.world/docs/cli)).
|
|
156
|
+
every save. `npx dewctl status` shows both versions. Run `npx dewctl publish` only when the user asks: it puts
|
|
157
|
+
the game in front of players ([commands](https://alpha.dewdrop.world/docs/cli)).
|
|
121
158
|
- `LOOK.md` is the agreed look. In a starter game, README.md says how the game works and why its look works.
|
|
122
159
|
Read both first.
|
|
123
160
|
- `thumbnail.jpg` is the image players see for the game. A starter's shows the starter, so once the look has
|
|
124
|
-
changed,
|
|
125
|
-
of at most 1 MB, at 16:9).
|
|
161
|
+
changed, replace it before publishing: take a screenshot in the browser tool with a 16:9 window, or ask the user
|
|
162
|
+
for one of the game on Dewdrop (a PNG, JPEG or WebP of at most 1 MB, at 16:9).
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Requests to Dewdrop
|
|
1
|
+
// Requests to Dewdrop's address, signed in with the session login stored.
|
|
2
2
|
import {tarChunks} from './tar.js';
|
|
3
3
|
import {RUN} from './command.js';
|
|
4
4
|
// A refusal as Dewdrop answered it: its status, its words, and the whole answer for what else it says.
|
|
@@ -39,8 +39,8 @@ export function* parts(chunks,bytes=PART_BYTES) {
|
|
|
39
39
|
}
|
|
40
40
|
export class Client {
|
|
41
41
|
// `partBytes` is for the tests, which cut at a few bytes; a push's requests and a file's parts are PART_BYTES.
|
|
42
|
-
// `pollMs` is the least a wait on Dewdrop takes a round: a Dewdrop
|
|
43
|
-
//
|
|
42
|
+
// `pollMs` is the least a wait on Dewdrop takes a round: a request Dewdrop holds is answered when there is news,
|
|
43
|
+
// within WAIT_S, and an answer without news that comes at once is asked again after that long.
|
|
44
44
|
// `confirmed` holds the hashes of the files Dewdrop has been seen to have, for this run.
|
|
45
45
|
constructor(origin,credentials,{fetcher=fetch,pollMs=1000,timeoutMs=180000,storeMs=15*60*1000,partBytes=PART_BYTES}={}){this.origin=origin;this.credentials=credentials;this.fetcher=fetcher;this.pollMs=pollMs;this.timeoutMs=timeoutMs;this.storeMs=storeMs;this.partBytes=partBytes;this.holds=true;this.confirmed=new Set();}
|
|
46
46
|
// A request signed in with `token`. When Dewdrop can't be reached the failure is marked transient, which a watcher
|
|
@@ -117,7 +117,7 @@ export class Client {
|
|
|
117
117
|
let result;
|
|
118
118
|
try { result=await this.api(path,{method:'PUT',body,type:'application/x-tar',signal}); }
|
|
119
119
|
catch(error) {
|
|
120
|
-
if(first&&[405,413,415].includes(error.status))throw new Error('
|
|
120
|
+
if(first&&[405,413,415].includes(error.status))throw new Error('Dewdrop can\'t take this release right now. Try again later.');
|
|
121
121
|
if(error.status!==409||!Array.isArray(error.body?.missing))throw error;
|
|
122
122
|
const missing=new Set(error.body.missing);
|
|
123
123
|
for(const {sha256} of sent)if(!missing.has(sha256))this.confirmed.add(sha256);
|
|
@@ -149,14 +149,15 @@ export class Client {
|
|
|
149
149
|
// Completes a file's upload at `path` with the number of its parts, asking for the answer at once: Dewdrop takes a
|
|
150
150
|
// large one in over minutes, longer than a request stays open, so an answer at once names the `phase` it is in, and
|
|
151
151
|
// this follows at the same address, telling `progress` each phase it sees, until Dewdrop records the file — the
|
|
152
|
-
// answer with its `bytes` — or refuses it. A
|
|
152
|
+
// answer with its `bytes` — or refuses it. A completion done at once is recorded in the request itself.
|
|
153
153
|
async #complete(path,count,signal,progress) {
|
|
154
154
|
const deadline=Date.now()+this.storeMs;
|
|
155
155
|
let result=await this.api(path,{method:'POST',body:{parts:count},signal,prefer:'respond-async'}),phase;
|
|
156
156
|
while(result.bytes===undefined) {
|
|
157
157
|
if(Date.now()>=deadline)throw new Error(`Dewdrop is taking longer than fifteen minutes to store the upload. Run ${RUN} releases to see whether it arrived.`);
|
|
158
158
|
if(result.phase!==undefined&&result.phase!==phase){phase=result.phase;progress?.(phase);}
|
|
159
|
-
// Held by Dewdrop until the completion ends,
|
|
159
|
+
// Held by Dewdrop until the completion ends, within WAIT_S; an answer without `bytes` is asked again after the
|
|
160
|
+
// round's rest.
|
|
160
161
|
const asked=Date.now();
|
|
161
162
|
result=await this.api(path,{signal,prefer:`wait=${WAIT_S}`});
|
|
162
163
|
if(result.bytes===undefined)await this.#rest(asked,signal);
|
|
@@ -186,8 +187,8 @@ export class Client {
|
|
|
186
187
|
if(seen.release===release&&!seen.ready&&!seen.error)await this.#rest(asked,signal);
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
|
-
// The game as Dewdrop answers it once `version` is ready or refused, holding the request for it;
|
|
190
|
-
//
|
|
190
|
+
// The game as Dewdrop answers it once `version` is ready or refused, holding the request for it; should Dewdrop
|
|
191
|
+
// refuse that wait, the game is read as it stands instead, then and from then on.
|
|
191
192
|
async held(game,version,signal) {
|
|
192
193
|
if(!this.holds)return this.game(game,signal);
|
|
193
194
|
try{return await this.api(`/v1/games/${game}/${version}`,{signal,prefer:`wait=${WAIT_S}`});}
|
|
@@ -197,8 +198,8 @@ export class Client {
|
|
|
197
198
|
return this.game(game,signal);
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
|
-
// The rest of a round
|
|
201
|
-
//
|
|
201
|
+
// The rest of a round whose answer brought no news: the next is asked `pollMs` after this one was, so an answer
|
|
202
|
+
// that comes at once is never asked again in a loop.
|
|
202
203
|
async #rest(asked,signal) {
|
|
203
204
|
const left=this.pollMs-(Date.now()-asked);
|
|
204
205
|
if(left>0)await sleep(left,signal);
|
|
@@ -232,11 +233,11 @@ export class Client {
|
|
|
232
233
|
// Pauses, resumes, steps (`{frames}`) or slows (`{k}`) room `room`: `{frame, paused}`.
|
|
233
234
|
room(game,room,action,fields,signal){return this.#control(game,`rooms/${encodeURIComponent(room)}/${action}`,{method:'POST',body:fields,signal});}
|
|
234
235
|
// A control of the developer's own seats. Dewdrop's own words say what was wrong — which seat or room, what to run —
|
|
235
|
-
// but for a Dewdrop
|
|
236
|
+
// but for a route Dewdrop doesn't take, and a refusal to someone not on the game.
|
|
236
237
|
async #control(game,path,options) {
|
|
237
238
|
try { return await this.api(`/v1/games/${game}/dev/${path}`,options); }
|
|
238
239
|
catch(error) {
|
|
239
|
-
if(error.status===405||(error.status===404&&error.message==='Route not found'))throw new ApiError(error.status,'
|
|
240
|
+
if(error.status===405||(error.status===404&&error.message==='Route not found'))throw new ApiError(error.status,'Dewdrop can\'t control dev sessions from the CLI right now. Try again later.',error.body);
|
|
240
241
|
if(error.status===403)throw new ApiError(403,`Only ${game}'s owner and the developers it's shared with can use its dev version.`,error.body);
|
|
241
242
|
throw error;
|
|
242
243
|
}
|
package/src/logs.js
CHANGED
|
@@ -6,13 +6,19 @@ import {sleep} from './client.js';
|
|
|
6
6
|
const WAIT_MS=25000,MOST_REST_MS=30000;
|
|
7
7
|
// The characters but tab and line breaks that a terminal takes as commands rather than text, shown as `?`.
|
|
8
8
|
export const CONTROL=/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g;
|
|
9
|
+
// Text from Dewdrop as printed: a game's own words reach it — its console, what its code threw, its compile errors —
|
|
10
|
+
// so each control character is shown as `?`, and no game moves the cursor, retitles the window or writes the clipboard.
|
|
11
|
+
export const printable=text=>String(text).replace(CONTROL,'?');
|
|
12
|
+
// A value printed as JSON: JSON.stringify writes the controls below space as escapes itself, but not DEL and the C1
|
|
13
|
+
// controls, which a terminal may take as commands too; they are written as escapes as well, the JSON reading the same.
|
|
14
|
+
export const json=(value,indent)=>JSON.stringify(value,null,indent).replace(/[\x7f-\x9f]/g,c=>`\\u00${c.charCodeAt(0).toString(16)}`);
|
|
9
15
|
const two=n=>String(n).padStart(2,'0');
|
|
10
16
|
// A line as printed: this computer's time of it, where it came from — the page of a seat, named by its player, the
|
|
11
17
|
// backend, or a seat's session — its level, and its text, positions mapped by `maps` for the release that wrote it.
|
|
12
18
|
export function format(line,maps) {
|
|
13
19
|
const at=new Date(line.at),time=Number.isNaN(at.getTime())?'':`${two(at.getHours())}:${two(at.getMinutes())}:${two(at.getSeconds())} `;
|
|
14
20
|
const text=maps?maps.text(line.release,String(line.text)):String(line.text);
|
|
15
|
-
return `${time}[${line.source}${line.seat?` ${line.seat}`:''}] ${line.level}: ${text}
|
|
21
|
+
return printable(`${time}[${line.source}${line.seat?` ${line.seat}`:''}] ${line.level}: ${text}`);
|
|
16
22
|
}
|
|
17
23
|
// Prints `game`'s dev console from the start of what Dewdrop keeps: those lines alone, or with `follow` each new line
|
|
18
24
|
// as it comes until `signal` ends it, starting again from the start when the dev version restarts. Following, a
|
|
@@ -29,13 +35,13 @@ export async function printLogs(client,game,{signal,follow=false,maps,log=consol
|
|
|
29
35
|
catch(error) {
|
|
30
36
|
if(signal?.aborted)break;
|
|
31
37
|
if(!follow||!(error.transient||[429,503].includes(error.status)||error.status>=500))throw error;
|
|
32
|
-
if(!failures++)note(error.status===503?`Waiting for ${game}'s dev version to run
|
|
38
|
+
if(!failures++)note(error.status===503?`Waiting for ${game}'s dev version to run…`:printable(`${error.message} Following again once Dewdrop answers.`));
|
|
33
39
|
try { await sleep(Math.min(restMs*2**(failures-1),MOST_REST_MS),signal); } catch { break; }
|
|
34
40
|
continue;
|
|
35
41
|
}
|
|
36
42
|
failures=0;
|
|
37
43
|
const lines=Array.isArray(answer.lines)?answer.lines:[];
|
|
38
|
-
// A
|
|
44
|
+
// A `next` given as a number is passed back as the same digits.
|
|
39
45
|
const next=typeof answer.next==='string'&&answer.next?answer.next:Number.isSafeInteger(answer.next)&&answer.next>=0?String(answer.next):null;
|
|
40
46
|
if(answer.restarted) {
|
|
41
47
|
// Without `follow`, a dev version that keeps restarting under the read gives what it had.
|
|
@@ -52,8 +58,7 @@ export async function printLogs(client,game,{signal,follow=false,maps,log=consol
|
|
|
52
58
|
if(!follow&&(!lines.length||next===null||next===after))break;
|
|
53
59
|
if(next!==null)after=next;
|
|
54
60
|
}
|
|
55
|
-
// An answer with nothing new that came at once is asked again after a rest,
|
|
56
|
-
// request isn't asked in a loop.
|
|
61
|
+
// An answer with nothing new that came at once is asked again after a rest, never in a loop.
|
|
57
62
|
if(follow&&!lines.length) {
|
|
58
63
|
const left=restMs-(Date.now()-asked);
|
|
59
64
|
if(left>0)try { await sleep(left,signal); } catch { break; }
|
package/src/main.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import {spawn} from 'node:child_process';
|
|
4
4
|
import {readFileSync,writeFileSync,renameSync,rmSync} from 'node:fs';
|
|
5
5
|
import {randomBytes} from 'node:crypto';
|
|
6
|
-
import {readProject,
|
|
6
|
+
import {readProject,dewdropOrigin,initProject,chooseTemplate,projectPath,insideBundle,DEWDROP,GAME_NAME} from './project.js';
|
|
7
7
|
import {Credentials} from './credentials.js';
|
|
8
8
|
import {Client} from './client.js';
|
|
9
9
|
import {deploy,watch,size} from './watch.js';
|
|
@@ -12,7 +12,7 @@ import {signInLink,waitForApproval} from './login.js';
|
|
|
12
12
|
import {RUN} from './command.js';
|
|
13
13
|
import {syncThumbnail} from './thumbnail.js';
|
|
14
14
|
import {SourceMaps} from './sourcemap.js';
|
|
15
|
-
import {printLogs} from './logs.js';
|
|
15
|
+
import {printLogs,printable,json} from './logs.js';
|
|
16
16
|
import {findSeat,seatTable,codeOf,shown,machine,roomLine,frames,factor,repl} from './session.js';
|
|
17
17
|
|
|
18
18
|
const HELP=`${RUN} — make three.js games on Dewdrop
|
|
@@ -25,9 +25,10 @@ const HELP=`${RUN} — make three.js games on Dewdrop
|
|
|
25
25
|
login Sign in: prints a link to open in your browser and approve
|
|
26
26
|
logout Sign this computer out
|
|
27
27
|
dev [--watch] [--release ID] Build, upload and play the dev version; --watch repeats this on every
|
|
28
|
-
save, --release plays a kept upload without building.
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
save, --release plays a kept upload without building. Without --release,
|
|
29
|
+
dev then prints the dev version's console as logs --follow does, at a
|
|
30
|
+
terminal and with --watch, until Ctrl-C; in a script it returns once the
|
|
31
|
+
upload is ready to play. The build's source maps (.map files) are never
|
|
31
32
|
uploaded: they stay on this computer
|
|
32
33
|
logs [GAME] [--follow] Print the dev version's recent console: the game's page and backend lines,
|
|
33
34
|
and how each seat's session ended. Positions in the built code are shown
|
|
@@ -52,8 +53,10 @@ const HELP=`${RUN} — make three.js games on Dewdrop
|
|
|
52
53
|
and exits 1. --json prints {"value":…}, {"error":"…"} or {} (undefined)
|
|
53
54
|
pause [GAME] [--seat S] [--json] Pause your seat's room: its backend and every seat in it
|
|
54
55
|
resume [GAME] [--seat S] [--json] Resume it
|
|
55
|
-
step [GAME] [--seat S] [--json] N
|
|
56
|
-
|
|
56
|
+
step [GAME] [--seat S] [--json] N Run the room N frames (1 to 600), paused or not, then pause it; returns
|
|
57
|
+
once they are drawn
|
|
58
|
+
speed [GAME] [--seat S] [--json] K Run the room at K times its speed: K above 0 and at most 1, rounded down
|
|
59
|
+
to 1/2, 1/3, 1/4 and so on, no slower than 1/300
|
|
57
60
|
repl [GAME] [--seat S] [--backend] Evaluate each line you type in your seat. .pause, .resume, .step N,
|
|
58
61
|
.speed K, .seat S, .backend, .page, .help and .exit do what they say
|
|
59
62
|
stop Stop the dev version and disconnect its players
|
|
@@ -75,10 +78,11 @@ const HELP=`${RUN} — make three.js games on Dewdrop
|
|
|
75
78
|
eval, pause, resume, step, speed and repl also take the name of a game you develop. Those that reach your
|
|
76
79
|
seats reach only your own, in the dev version, and none starts one: open one in a browser first.
|
|
77
80
|
|
|
78
|
-
A coding agent driving the game, for example:
|
|
79
|
-
${RUN} dev && ${RUN} seat --out .dewdrop-seat.json upload, and get a pass for its browser tool
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
A coding agent driving the game, for example (${DEWDROP}/docs/coding-agents):
|
|
82
|
+
${RUN} dev && ${RUN} seat --out .dewdrop-seat.json # upload, and get a pass for its browser tool
|
|
83
|
+
# the browser tool sets the pass's cookie for its url, opens the url and awaits dewdrop.ready()
|
|
84
|
+
${RUN} pause && ${RUN} eval 'game.player.position' && ${RUN} step 60 && ${RUN} eval 'game.player.position'
|
|
85
|
+
${RUN} resume
|
|
82
86
|
Docs: ${DEWDROP}/docs
|
|
83
87
|
`;
|
|
84
88
|
// Each command's flags; share and unshare also take one address, delete one release, delete-game the game's name,
|
|
@@ -176,7 +180,7 @@ async function main() {
|
|
|
176
180
|
let project=null;
|
|
177
181
|
try { project=readProject(process.cwd()); }
|
|
178
182
|
catch(error) { if(flags.game===undefined)throw error; }
|
|
179
|
-
const origin=
|
|
183
|
+
const origin=dewdropOrigin();
|
|
180
184
|
const credentials=new Credentials(origin),client=new Client(origin,credentials);
|
|
181
185
|
// The commands that wait on Dewdrop stop waiting at Ctrl-C; the rest end the ordinary way. Every signal is taken,
|
|
182
186
|
// not the first alone: under `npm run dev`, npm passes the terminal's Ctrl-C on to the CLI, which has had it already,
|
|
@@ -190,13 +194,13 @@ async function main() {
|
|
|
190
194
|
if(command==='login') {
|
|
191
195
|
credentials.prepare();
|
|
192
196
|
const link=signInLink(origin);
|
|
193
|
-
console.log(`Open this link to sign in the Dewdrop CLI:\n\n ${link.url}\n\nCheck that the page shows ${link.code}, then choose Sign in the CLI. Waiting…`);
|
|
197
|
+
console.log(printable(`Open this link to sign in the Dewdrop CLI:\n\n ${link.url}\n\nCheck that the page shows ${link.code}, then choose Sign in the CLI. Waiting…`));
|
|
194
198
|
if(atScreen())open(link.url);
|
|
195
199
|
let me;
|
|
196
200
|
try { me=await waitForApproval(client,link.token,{signal}); }
|
|
197
201
|
catch(error) { throw signal.aborted?new Error('Sign-in cancelled.'):error; }
|
|
198
202
|
credentials.write({token:link.token,email:me.email,expires:me.expires});
|
|
199
|
-
console.log(`Signed in as ${me.username??me.email}.`);
|
|
203
|
+
console.log(printable(`Signed in as ${me.username??me.email}.`));
|
|
200
204
|
return;
|
|
201
205
|
}
|
|
202
206
|
if(command==='logout') {
|
|
@@ -225,21 +229,21 @@ async function main() {
|
|
|
225
229
|
if(flags.out?.split(/[\\/]/).includes('..'))throw new Error(`Name the --out file without .., such as .dewdrop-seat.json in the game's folder.`);
|
|
226
230
|
if(flags.out&&project&&insideBundle(project,flags.out))throw new Error(`${flags.out} is in ${project.bundle}, which ${RUN} dev uploads, so the pass would be uploaded with the game. Write it outside that folder: --out .dewdrop-seat.json writes it in the game's folder, which uploads skip.`);
|
|
227
231
|
const pass=await client.seat(game,signal);
|
|
228
|
-
if(!flags.out){process.stdout.write(`${
|
|
232
|
+
if(!flags.out){process.stdout.write(`${json(pass,2)}\n`);return;}
|
|
229
233
|
writePrivate(flags.out,`${JSON.stringify(pass,null,2)}\n`);
|
|
230
|
-
console.log(`Wrote a seat pass for ${game} to ${flags.out}. It expires at ${pass.expires}.`);
|
|
234
|
+
console.log(printable(`Wrote a seat pass for ${game} to ${flags.out}. It expires at ${pass.expires}.`));
|
|
231
235
|
return;
|
|
232
236
|
}
|
|
233
237
|
if(command==='sessions') {
|
|
234
238
|
const answer=await client.sessions(game,signal);
|
|
235
|
-
console.log(flags.json?
|
|
239
|
+
console.log(flags.json?json(answer):seatTable(answer.sessions,game));
|
|
236
240
|
return;
|
|
237
241
|
}
|
|
238
242
|
if(command==='eval') {
|
|
239
243
|
const code=await codeOf(flags.code,process.stdin,signal);
|
|
240
244
|
const seat=flags.seat??(await findSeat(client,game,undefined,signal)).seat;
|
|
241
245
|
const answer=await client.evaluate(game,seat,code,Boolean(flags.backend),signal);
|
|
242
|
-
if(flags.json)console.log(
|
|
246
|
+
if(flags.json)console.log(json(await machine(client,game,answer,maps,signal)));
|
|
243
247
|
else {
|
|
244
248
|
const printed=await shown(client,game,answer,maps,signal);
|
|
245
249
|
(printed.error?console.error:console.log)(printed.text);
|
|
@@ -251,7 +255,7 @@ async function main() {
|
|
|
251
255
|
const fields=command==='step'?{frames:frames(flags.frames)}:command==='speed'?{k:factor(flags.k)}:{};
|
|
252
256
|
const {room}=await findSeat(client,game,flags.seat,signal);
|
|
253
257
|
const answer=await client.room(game,room,command,fields,signal);
|
|
254
|
-
console.log(flags.json?
|
|
258
|
+
console.log(flags.json?json(answer):roomLine(room,answer,fields.k));
|
|
255
259
|
return;
|
|
256
260
|
}
|
|
257
261
|
if(command==='repl') {
|
|
@@ -263,22 +267,23 @@ async function main() {
|
|
|
263
267
|
try { state=await client.game(game); }
|
|
264
268
|
catch(error) { if(error.status===404)throw new Error(`${game} isn't on Dewdrop yet. Run ${RUN} dev to create it.`); throw error; }
|
|
265
269
|
const url=devPlayUrl(state);
|
|
266
|
-
console.log(`${game}\n Dev version: ${describe(state.dev,'stopped')}${state.dev.release?` — ${url}`:''}\n Published: ${describe(state.live,'not published')}${state.live.release?` — ${state.urls.play}`:''}\n Thumbnail: ${state.urls.thumbnail??'none'}`);
|
|
270
|
+
console.log(printable(`${game}\n Dev version: ${describe(state.dev,'stopped')}${state.dev.release?` — ${url}`:''}\n Published: ${describe(state.live,'not published')}${state.live.release?` — ${state.urls.play}`:''}\n Thumbnail: ${state.urls.thumbnail??'none'}`));
|
|
267
271
|
return;
|
|
268
272
|
}
|
|
269
273
|
if(command==='releases'){
|
|
270
274
|
const [{releases},state]=await Promise.all([client.releases(game),client.game(game)]);
|
|
271
275
|
if(!releases.length){console.log(`No uploads of ${game} yet. Run ${RUN} dev to make one.`);return;}
|
|
272
|
-
// What each release is to the game
|
|
276
|
+
// What each release is to the game: the versions running it, else whether it was published before, is an older
|
|
277
|
+
// dev build, or is the latest upload.
|
|
273
278
|
const status=release=>[release.sha256===state.dev.release&&'dev',release.sha256===state.live.release&&'published'].filter(Boolean).join(', ')||(release.published?'published before':release.devBuild?'dev build':'latest upload');
|
|
274
|
-
console.log(columns([['RELEASE','UPLOADED (UTC)','SIZE','STATUS','BY'],...releases.map(release=>[release.sha256.slice(0,12),new Date(release.created).toISOString().slice(0,16).replace('T',' '),size(release.bytes),status(release),release.email])]));
|
|
279
|
+
console.log(printable(columns([['RELEASE','UPLOADED (UTC)','SIZE','STATUS','BY'],...releases.map(release=>[release.sha256.slice(0,12),new Date(release.created).toISOString().slice(0,16).replace('T',' '),size(release.bytes),status(release),release.email])])));
|
|
275
280
|
return;
|
|
276
281
|
}
|
|
277
282
|
if(command==='delete'){
|
|
278
283
|
if(!flags.release)throw new Error(`delete needs a release id from ${RUN} releases.`);
|
|
279
284
|
const release=await releaseId(client,game,flags.release);
|
|
280
285
|
await client.deleteRelease(game,release);
|
|
281
|
-
console.log(`Deleted ${release.slice(0,12)} from ${game}.`);return;
|
|
286
|
+
console.log(printable(`Deleted ${release.slice(0,12)} from ${game}.`));return;
|
|
282
287
|
}
|
|
283
288
|
if(command==='delete-game'){
|
|
284
289
|
if(flags.name!==game)throw new Error(`delete-game takes the game's name to confirm. Run ${RUN} delete-game ${game} to delete ${game}.`);
|
|
@@ -303,11 +308,11 @@ async function main() {
|
|
|
303
308
|
// The thumbnail goes first, so an image Dewdrop refuses stops the publish before anything changes for players.
|
|
304
309
|
if(project.thumbnail&&await syncThumbnail(project,client,current,signal))console.log(`Uploaded the thumbnail, ${project.thumbnail}.`);
|
|
305
310
|
const state=await client.publish(game,release,signal);
|
|
306
|
-
console.log(`Published ${release.slice(0,12)}. Players can open ${game} at ${state.urls.play}`);return;
|
|
311
|
+
console.log(printable(`Published ${release.slice(0,12)}. Players can open ${game} at ${state.urls.play}`));return;
|
|
307
312
|
}
|
|
308
313
|
if(flags.release){
|
|
309
314
|
const release=await releaseId(client,game,flags.release);
|
|
310
|
-
try { await client.activate(game,release,signal,state=>console.log(`Starting ${release.slice(0,12)} at ${devPlayUrl(state)}`)); }
|
|
315
|
+
try { await client.activate(game,release,signal,state=>console.log(printable(`Starting ${release.slice(0,12)} at ${devPlayUrl(state)}`))); }
|
|
311
316
|
catch(error) { error.message=maps.text(release,error.message); throw error; }
|
|
312
317
|
console.log('Ready to play.');return;
|
|
313
318
|
}
|
|
@@ -325,4 +330,4 @@ async function main() {
|
|
|
325
330
|
}
|
|
326
331
|
}
|
|
327
332
|
}
|
|
328
|
-
main().catch(error=>{console.error(`dewctl: ${error.message}`);process.exitCode=1;});
|
|
333
|
+
main().catch(error=>{console.error(`dewctl: ${printable(error.message)}`);process.exitCode=1;});
|
package/src/project.js
CHANGED
|
@@ -14,12 +14,12 @@ import {readMaps,recordMaps} from './sourcemap.js';
|
|
|
14
14
|
const ignored = new Set(['node_modules','dist','target']);
|
|
15
15
|
export const GAME_NAME = /^[a-z][a-z0-9-]{0,47}$/;
|
|
16
16
|
export const DEWDROP = 'https://alpha.dewdrop.world';
|
|
17
|
-
// Dewdrop's address, or the one
|
|
18
|
-
//
|
|
19
|
-
export function
|
|
17
|
+
// Dewdrop's address, or the one DEWDROP_ORIGIN names, held to the same rule: an origin with no path, the slash an
|
|
18
|
+
// address bar adds naming the same origin.
|
|
19
|
+
export function dewdropOrigin(value = process.env.DEWDROP_ORIGIN ?? DEWDROP) {
|
|
20
20
|
const url = URL.parse(value);
|
|
21
21
|
if (!url || (url.origin !== value && `${url.origin}/` !== value) || !(url.protocol === 'https:' || url.protocol === 'http:' && url.hostname === '127.0.0.1')) {
|
|
22
|
-
throw new Error(`
|
|
22
|
+
throw new Error(`DEWDROP_ORIGIN must be an https:// address with no path, like https://example.com, not ${value}.`);
|
|
23
23
|
}
|
|
24
24
|
return url.origin;
|
|
25
25
|
}
|
|
@@ -184,7 +184,7 @@ const SDK_RANGE='^0.9.0';
|
|
|
184
184
|
const CLI_RANGE=`^${JSON.parse(readFileSync(new URL('../package.json',import.meta.url),'utf8')).version}`;
|
|
185
185
|
// The games a new one can start from: Blank, which ships with this CLI, and the starter games in the public
|
|
186
186
|
// starter-templates repository, a folder each, at the commit this release pins.
|
|
187
|
-
const STARTERS={repo:'DewdropLabs/starter-templates',commit:'
|
|
187
|
+
const STARTERS={repo:'DewdropLabs/starter-templates',commit:'f49e446e2f4b2de2a622c7ddd56060a167b6508f'};
|
|
188
188
|
const TEMPLATES={
|
|
189
189
|
blank:['Blank','a cube and a style prompt, the smallest game'],
|
|
190
190
|
'golden-glide':['Golden Glide','flight over golden-hour countryside, in gouache'],
|
|
@@ -230,10 +230,9 @@ function gameNameFrom(root) {
|
|
|
230
230
|
const slug=basename(resolve(root)).toLowerCase().replace(/[^a-z0-9]+/g,'-').replace(/^[^a-z]+/,'').replace(/-+$/,'').slice(0,48).replace(/-+$/,'');
|
|
231
231
|
return GAME_NAME.test(slug)?slug:`game-${randomBytes(4).toString('hex')}`;
|
|
232
232
|
}
|
|
233
|
-
// The build command for a project of its own: its build:dew npm script when it has one
|
|
234
|
-
//
|
|
235
|
-
//
|
|
236
|
-
// add one.
|
|
233
|
+
// The build command for a project of its own: its build:dew npm script when it has one, a script for the Dewdrop
|
|
234
|
+
// build alone, else its build script, named so init can say which it chose, else the default with no script, so
|
|
235
|
+
// init can tell the developer to add one.
|
|
237
236
|
function buildCommandFor(root) {
|
|
238
237
|
try {
|
|
239
238
|
const scripts=JSON.parse(readFileSync(join(root,'package.json'),'utf8')).scripts;
|
|
@@ -266,10 +265,11 @@ export async function initProject(root, game, template, choose) {
|
|
|
266
265
|
const write=(path,data)=>{const file=join(root,path),dir=mkdirSync(dirname(file),{recursive:true});if(dir)made.push(dir);writeFileSync(file,data,{flag:'wx'});made.push(file);};
|
|
267
266
|
try {
|
|
268
267
|
for(const {path,data} of files)write(path,edits.get(path)?.(data.toString())??data);
|
|
269
|
-
// The files every new game gets beside its own, each left as it is when the folder has one already:
|
|
270
|
-
//
|
|
271
|
-
// the game's look with the
|
|
272
|
-
|
|
268
|
+
// The files every new game gets beside its own, each left as it is when the folder has one already: .gitignore
|
|
269
|
+
// keeps the build, the packages and a seat pass out of version control; AGENTS.md guides coding agents, which
|
|
270
|
+
// read it by that name, and sends them to the look skill beside it, which agrees the game's look with the
|
|
271
|
+
// developer before anything is built.
|
|
272
|
+
if(starter)for(const name of ['.gitignore','AGENTS.md',LOOK_SKILL])if(!existsSync(join(root,name)))write(name,name==='.gitignore'?'dist/\nnode_modules/\n.dewdrop-seat.json\n':readFileSync(join(EXAMPLES,name)));
|
|
273
273
|
write('dewdrop.json',JSON.stringify(config,null,2)+'\n');
|
|
274
274
|
} catch(error) {
|
|
275
275
|
for(const file of made.reverse())rmSync(file,{recursive:true,force:true});
|
package/src/session.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import {createInterface} from 'node:readline';
|
|
6
6
|
import {readFileSync} from 'node:fs';
|
|
7
7
|
import {RUN} from './command.js';
|
|
8
|
-
import {
|
|
8
|
+
import {printable,json} from './logs.js';
|
|
9
9
|
|
|
10
10
|
// No seat of the developer's playing, in their words: how to get one.
|
|
11
11
|
const noSeat=game=>`No dev seat of yours is playing ${game}: open one in a browser (${RUN} seat) first.`;
|
|
@@ -23,7 +23,7 @@ export async function findSeat(client,game,seat,signal) {
|
|
|
23
23
|
export function seatTable(sessions,game) {
|
|
24
24
|
if(!sessions.length)return noSeat(game);
|
|
25
25
|
const width=Math.max(4,...sessions.map(each=>each.seat.length));
|
|
26
|
-
return [`${'SEAT'.padEnd(width)} ROOM`,...sessions.map((each,i)=>`${each.seat.padEnd(width)} ${each.room}${i===0?' (default)':''}`)].join('\n')
|
|
26
|
+
return printable([`${'SEAT'.padEnd(width)} ROOM`,...sessions.map((each,i)=>`${each.seat.padEnd(width)} ${each.room}${i===0?' (default)':''}`)].join('\n'));
|
|
27
27
|
}
|
|
28
28
|
// The code `eval` is given: the argument itself, everything on standard input for `-`, or a file's text for `@FILE`.
|
|
29
29
|
// Reading standard input ends at `signal`, the input let go so the CLI can end.
|
|
@@ -49,32 +49,39 @@ export async function shown(client,game,answer,maps,signal) {
|
|
|
49
49
|
if(typeof answer.error==='string') {
|
|
50
50
|
let text=answer.error;
|
|
51
51
|
if(maps)try { text=maps.text((await client.game(game,signal)).dev.release,text); } catch {}
|
|
52
|
-
return {error:true,text:text
|
|
52
|
+
return {error:true,text:printable(text)};
|
|
53
53
|
}
|
|
54
|
-
return {error:false,text:'value' in answer?
|
|
54
|
+
return {error:false,text:'value' in answer?json(answer.value,2):'undefined'};
|
|
55
55
|
}
|
|
56
56
|
// The answer to an evaluate, `--json`: as Dewdrop gave it, with the error's positions mapped as printed.
|
|
57
57
|
export async function machine(client,game,answer,maps,signal) {
|
|
58
58
|
if(typeof answer.error!=='string')return answer;
|
|
59
59
|
return {error:(await shown(client,game,answer,maps,signal)).text};
|
|
60
60
|
}
|
|
61
|
-
// A room's state after an action, in words
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
// A room's state after an action, in words, and after a speed the speed it runs at: the room rounds a factor `k`
|
|
62
|
+
// down to 1/2, 1/3, 1/4 and so on, and a paused room runs at it once resumed.
|
|
63
|
+
export function roomLine(room,{frame,paused},k) {
|
|
64
|
+
const line=printable(`Room ${room}: frame ${frame}, ${paused?'paused':'running'}.`);
|
|
65
|
+
if(k===undefined)return line;
|
|
66
|
+
const every=Math.ceil(1/k);
|
|
67
|
+
return `${line} It runs at ${every===1?'full':`1/${every}`} speed${paused?' once resumed':''}.`;
|
|
68
|
+
}
|
|
69
|
+
// Checks a step's frame count and a speed's factor before anything is asked of Dewdrop: a room runs no slower than
|
|
70
|
+
// 1/300 of its speed, so a factor it would round below that is refused.
|
|
64
71
|
export function frames(value) {
|
|
65
72
|
if(!/^[1-9][0-9]{0,2}$/.test(value??'')||Number(value)>600)throw new Error('step takes a number of frames from 1 to 600.');
|
|
66
73
|
return Number(value);
|
|
67
74
|
}
|
|
68
75
|
export function factor(value) {
|
|
69
76
|
const k=Number(value);
|
|
70
|
-
if(!/^(0|1)?(\.[0-9]+)?$/.test(value??'')||!(k>0&&k<=1))throw new Error('speed takes a factor above 0 and at most 1, such as 0.25.');
|
|
77
|
+
if(!/^(0|1)?(\.[0-9]+)?$/.test(value??'')||!(k>0&&k<=1)||Math.ceil(1/k)>300)throw new Error('speed takes a factor above 0 and at most 1, no slower than 1/300, such as 0.25.');
|
|
71
78
|
return k;
|
|
72
79
|
}
|
|
73
80
|
const HELP=`Each line is evaluated in the seat (or, after .backend, in its room's backend) and its value printed.
|
|
74
81
|
.pause Pause the seat's room
|
|
75
82
|
.resume Resume it
|
|
76
|
-
.step N
|
|
77
|
-
.speed K Run the room at K times its speed (above 0, at most 1)
|
|
83
|
+
.step N Run the room N frames (1 to 600), then pause it
|
|
84
|
+
.speed K Run the room at K times its speed (above 0, at most 1, no slower than 1/300)
|
|
78
85
|
.seat S Evaluate in your seat S from now on (${RUN} sessions lists them)
|
|
79
86
|
.backend Evaluate in the room's backend from now on
|
|
80
87
|
.page Evaluate in the seat's page again
|
|
@@ -87,8 +94,9 @@ export async function repl(client,game,{seat,backend=false,maps,input=process.st
|
|
|
87
94
|
const terminal=Boolean(input.isTTY&&output.isTTY);
|
|
88
95
|
const stop=new AbortController(),{signal}=stop;
|
|
89
96
|
let current=(await findSeat(client,game,seat)).seat;
|
|
90
|
-
|
|
91
|
-
const
|
|
97
|
+
// Everything the console prints names what Dewdrop answered — a seat, a room, a value — so all of it is printable.
|
|
98
|
+
const say=text=>output.write(`${printable(text)}\n`);
|
|
99
|
+
const prompt=()=>printable(`${game} ${current}${backend?' backend':''}> `);
|
|
92
100
|
say(`Evaluating in ${current}${backend?'\'s backend':''} of ${game}. .help lists the commands.`);
|
|
93
101
|
const lines=createInterface({input,output:terminal?output:undefined,terminal,prompt:prompt()});
|
|
94
102
|
// Ctrl-C at a terminal; a console reading a pipe ends at its end, once every line read is answered.
|
|
@@ -97,7 +105,7 @@ export async function repl(client,game,{seat,backend=false,maps,input=process.st
|
|
|
97
105
|
// The seat's room, asked each time: a seat may have joined another since.
|
|
98
106
|
const act=async(action,fields={})=>{
|
|
99
107
|
const {room}=await findSeat(client,game,current,signal);
|
|
100
|
-
say(roomLine(room,await client.room(game,room,action,fields,signal)));
|
|
108
|
+
say(roomLine(room,await client.room(game,room,action,fields,signal),fields.k));
|
|
101
109
|
};
|
|
102
110
|
const commands={
|
|
103
111
|
'.pause':()=>act('pause'),
|
package/src/watch.js
CHANGED
|
@@ -3,6 +3,7 @@ import {watch as watchDirectory} from 'node:fs';
|
|
|
3
3
|
import {fingerprint,build,snapshot,followed} from './project.js';
|
|
4
4
|
import {devPlayUrl} from './play.js';
|
|
5
5
|
import {RUN} from './command.js';
|
|
6
|
+
import {printable} from './logs.js';
|
|
6
7
|
|
|
7
8
|
// A byte count as a person reads it.
|
|
8
9
|
export function size(bytes) {
|
|
@@ -16,7 +17,7 @@ const count=(n,noun)=>`${n} ${noun}${n===1?'':'s'}`;
|
|
|
16
17
|
// What a push says as it goes, in the developer's terms: the files going up, or checked with Dewdrop first, the ones
|
|
17
18
|
// Dewdrop turned out to lack, and each phase of a file stored over minutes.
|
|
18
19
|
const telling=log=>event=>{
|
|
19
|
-
if(event.phase!==undefined)log(PHASES[event.phase]
|
|
20
|
+
if(event.phase!==undefined)log(PHASES[event.phase]??printable(`Dewdrop is ${event.phase} the upload…`));
|
|
20
21
|
else if(event.checking!==undefined)log(`Checking ${count(event.checking,'file')} (${size(event.bytes)}) with Dewdrop…`);
|
|
21
22
|
else if(event.missing!==undefined)log(`Uploading ${count(event.missing,'changed file')} (${size(event.bytes)})…`);
|
|
22
23
|
else if(event.files===0)log('Dewdrop has every file of the build; recording the release…');
|
|
@@ -33,7 +34,7 @@ export async function deploy(project,client,{signal,log=console.log,maps}={}) {
|
|
|
33
34
|
const bundle=await snapshot(project);
|
|
34
35
|
const {release}=await client.push(project.game,bundle,signal,telling(log));
|
|
35
36
|
maps?.remember(release,bundle.directory,bundle.maps);
|
|
36
|
-
try { await client.activate(project.game,release,signal,game=>log(`Starting ${release.slice(0,12)} at ${devPlayUrl(game)}`)); }
|
|
37
|
+
try { await client.activate(project.game,release,signal,game=>log(printable(`Starting ${release.slice(0,12)} at ${devPlayUrl(game)}`))); }
|
|
37
38
|
catch(error) { if(maps)error.message=maps.text(release,error.message); throw error; }
|
|
38
39
|
log('Ready to play.');
|
|
39
40
|
return {changed:false};
|
|
@@ -69,7 +70,7 @@ export async function watch(project,client,{signal,log=console.log,deployGame=de
|
|
|
69
70
|
following?.controller.abort();
|
|
70
71
|
const controller=new AbortController(),current={game,controller};
|
|
71
72
|
current.done=follow(game,signal?AbortSignal.any([signal,controller.signal]):controller.signal).catch(error=>{
|
|
72
|
-
if(!controller.signal.aborted&&!signal?.aborted)log(`dewctl: ${error.message}`);
|
|
73
|
+
if(!controller.signal.aborted&&!signal?.aborted)log(`dewctl: ${printable(error.message)}`);
|
|
73
74
|
}).finally(()=>{if(following===current)following=null;});
|
|
74
75
|
following=current;
|
|
75
76
|
};
|
|
@@ -95,13 +96,13 @@ export async function watch(project,client,{signal,log=console.log,deployGame=de
|
|
|
95
96
|
else startFollowing(game);
|
|
96
97
|
}).catch(error=>{
|
|
97
98
|
if(signal?.aborted)return;
|
|
98
|
-
log(`dewctl: ${error.message}`);
|
|
99
|
+
log(`dewctl: ${printable(error.message)}`);
|
|
99
100
|
if(error.status===401)log(`Paused until you sign in: run ${RUN} login in another terminal, then save a file.`);
|
|
100
101
|
else if(error.transient){log('Trying again in a moment.');dirty=true;changedAt=Date.now()+2000;}
|
|
101
102
|
else log('Fix it and save to try again.');
|
|
102
103
|
}).finally(()=>{running=null;});
|
|
103
104
|
}
|
|
104
|
-
}catch(error){log(`dewctl: ${error.message}`);log('Fix it and save to try again.');}
|
|
105
|
+
}catch(error){log(`dewctl: ${printable(error.message)}`);log('Fix it and save to try again.');}
|
|
105
106
|
await new Promise(resolve=>setTimeout(resolve,pollMs));
|
|
106
107
|
}
|
|
107
108
|
await running;
|