dewctl 0.9.0 → 0.9.2

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 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`. Source
15
- maps (`.map` files) are never uploaded: they stay on your computer.
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 `cookie` with your browser
24
- tool for its `url` — the cookie names no domain, so it goes to Dewdrop's host
25
- alone — then open the `url`. Without `--out` the pass is printed, to pipe into
26
- your tool — where a terminal log or a CI log can keep it. For example, in a
27
- script that drives Chrome with Puppeteer:
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({...pass.cookie, url: pass.url});
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 takes a cookie's `url` or its `path`, not both:
41
+ With Playwright:
36
42
 
37
43
  ```js
38
- const {path, ...cookie} = pass.cookie;
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` advances the paused room 60
60
- frames and returns once they are drawn; `dewctl speed 0.25` runs it at a
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
- A loop an agent might run — upload, seat, pause, look, step, look, resume:
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 # the agent's browser tool sets the cookie and opens the url
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 scene's manner rather than specific
175
- objects, which the two would fight over. A starter's prompt stands as it is.)
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
- You can't see Dewdrop's frames. After the upload that carries the colors, the words and the prompt, ask the user
214
- to look while moving, or for a screenshot, and ask three specific questions from `LOOK.md`: "Is the grass a bright
215
- plasticine green? Does the lamp glow? Is the sky a plain pale backdrop?" Put the answers under "Checked on
216
- Dewdrop", and change the code and `LOOK.md` together, one thing at a time.
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 |
@@ -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 ([limits](https://alpha.dewdrop.world/docs/limits#the-look)).
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
- - **Don't name objects in the prompt.** Describe them on their meshes. The prompt can't override the colors.
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. Words don't light
61
- a surface; warmth comes from color. A shadow is a thin dark mesh on the ground
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. Turn flat things to face the camera
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, WebRTC and workers aren't available. Sound plays through
83
- Web Audio; `<audio>` and `<video>` make no sound.
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 every edit. If the user runs `npx dewctl dev --watch`,
103
- every save uploads by itself, so don't upload as well: both build into the same folder. Judge the look there, in
104
- motion, not from a still frame. The first second is plain and grey.
105
-
106
- You can't see Dewdrop's frames. Ask the user specific questions ("Does the lantern glow?", "What does the sky look
107
- like?"), or ask for a screenshot. In the dev version, `dewdrop.evaluate` runs code in the game from the browser
108
- console or a script driving the browser, to read the game's state or change it
109
- ([run code](https://alpha.dewdrop.world/docs/development-flow#run-code-in-your-dev-version)). Change one thing
110
- at a time, so you know what each change did.
111
-
112
- ## 5. The project
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 logs` prints the dev version's recent console, page and backend, with positions in the
118
- game's source. `npx dewctl seat --out <file>` gets a pass for a browser a script drives: one use, within 10 minutes
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, ask the user for a screenshot of the game on Dewdrop to replace it before publishing (a PNG, JPEG or WebP
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dewctl",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Build and publish three.js games on Dewdrop.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/client.js CHANGED
@@ -1,4 +1,4 @@
1
- // Requests to Dewdrop, only ever to the address in dewdrop.json, signed in with the session login stored.
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 that holds the request answers when there
43
- // is news, within WAIT_S; one that answers at once instead is asked again after that long.
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
@@ -56,11 +56,14 @@ export class Client {
56
56
  const reason=error.name==='TimeoutError'?'no answer in two minutes':error.cause?.code??error.cause?.message??error.message;
57
57
  throw Object.assign(new Error(`Couldn't reach ${this.origin} (${reason}). Check your connection.`),{transient:true});
58
58
  }
59
- const contentType=response.headers.get('content-type')??'';
60
- if(!contentType.includes('application/json'))throw new ApiError(response.status,`${this.origin} didn't answer as Dewdrop does (HTTP ${response.status}). Try again in a moment.`);
61
- const data=await response.json();
59
+ // An answer in JSON is Dewdrop's, and a refusal in it is said in Dewdrop's words whatever its status, a 504
60
+ // included; anything else — a page from something between here and Dewdrop — is no answer of Dewdrop's.
61
+ const strange=new ApiError(response.status,`${this.origin} didn't answer as Dewdrop does (HTTP ${response.status}). Try again in a moment.`);
62
+ if(!(response.headers.get('content-type')??'').includes('application/json'))throw strange;
63
+ let data;
64
+ try { data=await response.json(); } catch(error) { if(signal?.aborted)throw error; throw strange; }
62
65
  if(response.status===401&&token)throw new ApiError(401,`Your sign-in has ended: it expired or was signed out. Run ${RUN} login.`,data);
63
- if(!response.ok)throw new ApiError(response.status,data.error??`HTTP ${response.status}`,data);
66
+ if(!response.ok)throw new ApiError(response.status,typeof data?.error==='string'&&data.error?data.error:`HTTP ${response.status}`,data);
64
67
  return data;
65
68
  }
66
69
  // The session this computer holds, or why there is none to use.
@@ -114,7 +117,7 @@ export class Client {
114
117
  let result;
115
118
  try { result=await this.api(path,{method:'PUT',body,type:'application/x-tar',signal}); }
116
119
  catch(error) {
117
- if(first&&[405,413,415].includes(error.status))throw new Error('This Dewdrop is older than this dewctl and can\'t take the release yet. Try again later.');
120
+ if(first&&[405,413,415].includes(error.status))throw new Error('Dewdrop can\'t take this release right now. Try again later.');
118
121
  if(error.status!==409||!Array.isArray(error.body?.missing))throw error;
119
122
  const missing=new Set(error.body.missing);
120
123
  for(const {sha256} of sent)if(!missing.has(sha256))this.confirmed.add(sha256);
@@ -146,14 +149,15 @@ export class Client {
146
149
  // Completes a file's upload at `path` with the number of its parts, asking for the answer at once: Dewdrop takes a
147
150
  // large one in over minutes, longer than a request stays open, so an answer at once names the `phase` it is in, and
148
151
  // this follows at the same address, telling `progress` each phase it sees, until Dewdrop records the file — the
149
- // answer with its `bytes` — or refuses it. A Dewdrop that is done at once records it in the request itself.
152
+ // answer with its `bytes` — or refuses it. A completion done at once is recorded in the request itself.
150
153
  async #complete(path,count,signal,progress) {
151
154
  const deadline=Date.now()+this.storeMs;
152
155
  let result=await this.api(path,{method:'POST',body:{parts:count},signal,prefer:'respond-async'}),phase;
153
156
  while(result.bytes===undefined) {
154
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.`);
155
158
  if(result.phase!==undefined&&result.phase!==phase){phase=result.phase;progress?.(phase);}
156
- // Held by Dewdrop until the completion ends, or answered at once by one that does not hold a poll.
159
+ // Held by Dewdrop until the completion ends, within WAIT_S; an answer without `bytes` is asked again after the
160
+ // round's rest.
157
161
  const asked=Date.now();
158
162
  result=await this.api(path,{signal,prefer:`wait=${WAIT_S}`});
159
163
  if(result.bytes===undefined)await this.#rest(asked,signal);
@@ -183,8 +187,8 @@ export class Client {
183
187
  if(seen.release===release&&!seen.ready&&!seen.error)await this.#rest(asked,signal);
184
188
  }
185
189
  }
186
- // The game as Dewdrop answers it once `version` is ready or refused, holding the request for it; a Dewdrop from
187
- // before that route answers the game as it stands, and is asked that way from then on.
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.
188
192
  async held(game,version,signal) {
189
193
  if(!this.holds)return this.game(game,signal);
190
194
  try{return await this.api(`/v1/games/${game}/${version}`,{signal,prefer:`wait=${WAIT_S}`});}
@@ -194,17 +198,18 @@ export class Client {
194
198
  return this.game(game,signal);
195
199
  }
196
200
  }
197
- // The rest of a round that came back at once: a Dewdrop holding the request has answered with news, one that
198
- // answered at once is asked again `pollMs` after it was asked.
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.
199
203
  async #rest(asked,signal) {
200
204
  const left=this.pollMs-(Date.now()-asked);
201
205
  if(left>0)await sleep(left,signal);
202
206
  }
203
207
  // Sets the game's thumbnail to the image, sent as itself under its type.
204
208
  thumbnail(game,bytes,type,signal){return this.api(`/v1/games/${game}/thumbnail`,{method:'PUT',body:bytes,type,signal});}
205
- // The dev version's console lines after `after`, held up to `wait` ms for new ones. A refusal says why in the
206
- // developer's terms.
207
- devLogs(game,after,wait,signal){return this.#dev(game,`logs?after=${after}&wait=${wait}`,{signal});}
209
+ // The dev version's console lines after cursor `after` — none for the start, or a `next` Dewdrop answered, which
210
+ // is its own and goes back as it came — held up to `wait` ms for new ones. A refusal says why in the developer's
211
+ // terms.
212
+ devLogs(game,after,wait,signal){return this.#dev(game,`logs?${after==null?'':`after=${encodeURIComponent(after)}&`}wait=${wait}`,{signal});}
208
213
  // A seat pass for the dev version: one use, within minutes, by whatever the developer's own tools are.
209
214
  seat(game,signal){return this.#dev(game,'seat',{method:'POST',body:{},signal});}
210
215
  async #dev(game,path,options) {
@@ -228,11 +233,11 @@ export class Client {
228
233
  // Pauses, resumes, steps (`{frames}`) or slows (`{k}`) room `room`: `{frame, paused}`.
229
234
  room(game,room,action,fields,signal){return this.#control(game,`rooms/${encodeURIComponent(room)}/${action}`,{method:'POST',body:fields,signal});}
230
235
  // A control of the developer's own seats. Dewdrop's own words say what was wrong — which seat or room, what to run —
231
- // but for a Dewdrop from before these routes, and a refusal to someone not on the game.
236
+ // but for a route Dewdrop doesn't take, and a refusal to someone not on the game.
232
237
  async #control(game,path,options) {
233
238
  try { return await this.api(`/v1/games/${game}/dev/${path}`,options); }
234
239
  catch(error) {
235
- if(error.status===405||(error.status===404&&error.message==='Route not found'))throw new ApiError(error.status,'This Dewdrop can\'t control dev sessions from the CLI yet. Try again later.',error.body);
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);
236
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);
237
242
  throw error;
238
243
  }
package/src/logs.js CHANGED
@@ -19,8 +19,9 @@ export function format(line,maps) {
19
19
  // Dewdrop that can't be reached, a dev version not running and a limit reached are waited out, resting longer after
20
20
  // each failure in a row; any other refusal, or any refusal at all without `follow`, is thrown. `note` says what
21
21
  // happened to the lines rather than printing one.
22
+ // Where the read has got to is Dewdrop's own: none at first, then each answer's `next`, passed back as it came.
22
23
  export async function printLogs(client,game,{signal,follow=false,maps,log=console.log,note=log,restMs=1000,waitMs=WAIT_MS}={}) {
23
- let after=0,failures=0,printed=0,restarts=0;
24
+ let after=null,failures=0,printed=0,restarts=0;
24
25
  while(!signal?.aborted) {
25
26
  const asked=Date.now();
26
27
  let answer;
@@ -34,21 +35,24 @@ export async function printLogs(client,game,{signal,follow=false,maps,log=consol
34
35
  }
35
36
  failures=0;
36
37
  const lines=Array.isArray(answer.lines)?answer.lines:[];
38
+ // A `next` given as a number is passed back as the same digits.
39
+ const next=typeof answer.next==='string'&&answer.next?answer.next:Number.isSafeInteger(answer.next)&&answer.next>=0?String(answer.next):null;
37
40
  if(answer.restarted) {
38
41
  // Without `follow`, a dev version that keeps restarting under the read gives what it had.
39
42
  if(!follow&&++restarts>2)break;
40
- if(follow&&after>0)note(`(${game}'s dev version restarted.)`);
41
- after=0;
42
- } else {
43
- if(answer.lost>0)note(`(${answer.lost} line${answer.lost===1?' was':'s were'} dropped here, written faster than Dewdrop keeps them)`);
44
- for(const line of lines)log(format(line,maps));
45
- printed+=lines.length;
46
- const next=Number.isSafeInteger(answer.next)?answer.next:after;
47
- if(!follow&&(!lines.length||next<=after))break;
48
- after=next;
43
+ if(follow&&after!==null&&after!=='0')note(`(${game}'s dev version restarted.)`);
49
44
  }
50
- // An answer with nothing new that came at once is asked again after a rest, so a Dewdrop that doesn't hold the
51
- // request isn't asked in a loop.
45
+ if(answer.lost>0)note(`(${answer.lost} line${answer.lost===1?' was':'s were'} dropped here, written faster than Dewdrop keeps them)`);
46
+ for(const line of lines)log(format(line,maps));
47
+ printed+=lines.length;
48
+ // A restart is read again from where its answer says, or from the start; otherwise, without `follow`, the read
49
+ // ends once an answer brings nothing new.
50
+ if(answer.restarted)after=next;
51
+ else {
52
+ if(!follow&&(!lines.length||next===null||next===after))break;
53
+ if(next!==null)after=next;
54
+ }
55
+ // An answer with nothing new that came at once is asked again after a rest, never in a loop.
52
56
  if(follow&&!lines.length) {
53
57
  const left=restMs-(Date.now()-asked);
54
58
  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,platformOrigin,initProject,chooseTemplate,projectPath,insideBundle,DEWDROP,GAME_NAME} from './project.js';
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';
@@ -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. At a terminal, and
29
- with --watch, dev then prints the dev version's console as logs --follow
30
- does, until Ctrl-C. The build's source maps (.map files) are never
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 Advance the paused room N frames (1 to 600), once they are drawn
56
- speed [GAME] [--seat S] [--json] K Run the room at K times its speed: above 0, at most 1
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
- ${RUN} pause && ${RUN} eval 'player.position' && ${RUN} step 60 && ${RUN} eval 'player.position'
81
- dewctl resume
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=platformOrigin();
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,
@@ -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?JSON.stringify(answer):roomLine(room,answer)+(command==='speed'?` It runs at ${fields.k}× speed.`:''));
258
+ console.log(flags.json?JSON.stringify(answer):roomLine(room,answer,fields.k));
255
259
  return;
256
260
  }
257
261
  if(command==='repl') {
@@ -269,7 +273,8 @@ async function main() {
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, the reason Dewdrop keeps it, and for an old dev build when it goes.
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
279
  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])]));
275
280
  return;
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 DEWDROP_PLATFORM names: an https:// origin, or plain http:// to this
18
- // computer's own loopback address, which a credential never leaves. The slash an address bar adds is the same origin.
19
- export function platformOrigin(value = process.env.DEWDROP_PLATFORM ?? DEWDROP) {
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(`DEWDROP_PLATFORM must be an https:// address with no path, like https://example.com, not ${value}.`);
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:'7fbfbd8ef6d1a1c830de0ac2634a126f73c8fa79'};
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 — a project set up before
234
- // dewdrop-sdk 0.6, whose SDK init leaves as it is, builds for Dewdrop through that script alone — else its build
235
- // script, named so init can say which it chose, else the default with no script, so init can tell the developer to
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: AGENTS.md
270
- // guides coding agents, which read it by that name, and sends them to the look skill beside it, which agrees
271
- // the game's look with the 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':readFileSync(join(EXAMPLES,name)));
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
@@ -58,23 +58,30 @@ 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
- export const roomLine=(room,{frame,paused})=>`Room ${room}: frame ${frame}, ${paused?'paused':'running'}.`;
63
- // Checks a step's frame count and a speed's factor before anything is asked of Dewdrop.
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=`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 Advance the paused room N frames (1 to 600)
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
@@ -97,7 +104,7 @@ export async function repl(client,game,{seat,backend=false,maps,input=process.st
97
104
  // The seat's room, asked each time: a seat may have joined another since.
98
105
  const act=async(action,fields={})=>{
99
106
  const {room}=await findSeat(client,game,current,signal);
100
- say(roomLine(room,await client.room(game,room,action,fields,signal)));
107
+ say(roomLine(room,await client.room(game,room,action,fields,signal),fields.k));
101
108
  };
102
109
  const commands={
103
110
  '.pause':()=>act('pause'),