@joystack/cli 0.1.48 → 0.1.49

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/CHANGELOG.md CHANGED
@@ -14,6 +14,28 @@ Versions: [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
14
14
 
15
15
  ## [Unreleased]
16
16
 
17
+ ## [0.1.49] - 2026-10-10
18
+
19
+ ### Added
20
+
21
+ - `joystack land <name>` puts a lane's work into your game and removes the
22
+ lane, from the game folder or from inside the lane. It saves the lane's
23
+ unsaved work first. When the lane and the game changed the same lines, it
24
+ stops with the merge in progress and lists the files; once the merge is
25
+ settled and committed, run it again to remove the lane.
26
+
27
+ ### Changed
28
+
29
+ - In the Joystack maker, `joystack lane`, `dev`, `publish` and `land` answer
30
+ for the maker: the folder is already the conversation's lane, its game is
31
+ already running on the person's page, and publishing does what the page's
32
+ Publish button does. On your own computer they work as before.
33
+
34
+ ### Fixed
35
+
36
+ - On Windows, exporting a replay no longer fails now and then with `EPERM`
37
+ while another program still has the file it just wrote open.
38
+
17
39
  ## [0.1.48] - 2026-10-10
18
40
 
19
41
  ### Added
package/bin/joystack.mjs CHANGED
@@ -6,6 +6,8 @@
6
6
  import { dev } from '../lib/dev.mjs';
7
7
  import { agentSessionFromEnv } from '../lib/agent-session.mjs';
8
8
  import { lane } from '../lib/lane.mjs';
9
+ import { land } from '../lib/land.mjs';
10
+ import { MAKER_DEV, MAKER_LANE, makerDraft, makerPublish } from '../lib/maker.mjs';
9
11
  import { login, logout, whoami } from '../lib/login.mjs';
10
12
  import { publish } from '../lib/publish.mjs';
11
13
  import { create } from '../lib/create.mjs';
@@ -38,6 +40,7 @@ Usage:
38
40
  joystack assets <id> --sheet Draw a view sheet of a 3D asset to .joystack/sheets/ (--help: options)
39
41
  joystack assets --json [<id>…] Print each asset's parameters, measured stats and flags as JSON
40
42
  joystack lane <name> Open an isolated copy of the game to experiment in, safely
43
+ joystack land <name> Put a lane's work into the game, then remove the lane
41
44
  joystack test [aspect] Run targeted checks (no aspect: conservative full run)
42
45
  joystack test --since <base> Submission: ordinary + triggered extended checks
43
46
  joystack test --all Explicit full audit; add --list to preview selection
@@ -72,6 +75,10 @@ its own.
72
75
  try {
73
76
  switch (cmd) {
74
77
  case 'dev': {
78
+ if (makerDraft()) {
79
+ console.log(MAKER_DEV);
80
+ break;
81
+ }
75
82
  const handle = await dev({ port: flag('port') ? Number(flag('port')) : undefined, share: rest.includes('--share'), reload: !rest.includes('--no-reload'), agentSession: agentSessionFromEnv() });
76
83
  const shutdown = () => {
77
84
  handle.stop();
@@ -188,12 +195,24 @@ try {
188
195
  break;
189
196
  }
190
197
  case 'lane': {
198
+ if (makerDraft()) {
199
+ console.log(MAKER_LANE);
200
+ break;
201
+ }
191
202
  const name = rest.find((a) => !a.startsWith('--'));
192
203
  if (!name) throw new Error('Name the lane: joystack lane <name> (e.g. joystack lane judder)');
193
204
  const { dir } = await lane(name);
194
205
  console.log(`\nWork in it:\n cd ${dir} && npx joystack dev\n`);
195
206
  break;
196
207
  }
208
+ case 'land': {
209
+ if (makerDraft()) {
210
+ await makerPublish(makerDraft());
211
+ break;
212
+ }
213
+ await land(rest.find((a) => !a.startsWith('--')));
214
+ break;
215
+ }
197
216
  case 'setup':
198
217
  process.stdout.write(setupGuide());
199
218
  break;
@@ -272,6 +291,10 @@ try {
272
291
  break;
273
292
  }
274
293
  case 'publish':
294
+ if (makerDraft()) {
295
+ await makerPublish(makerDraft(), { slug: flag('slug') });
296
+ break;
297
+ }
275
298
  await publish({ slug: flag('slug'), devTools: rest.includes('--dev-tools'), open: rest.includes('--open') });
276
299
  break;
277
300
  case 'feedback':
package/lib/dev.mjs CHANGED
@@ -110,7 +110,12 @@ export async function dev(opts = {}) {
110
110
  // (agent-session.mjs). Only the interactive `joystack dev` and `joystack assets`
111
111
  // commands pass one; a stack started by `joystack test` or any other caller has
112
112
  // none, so no test run can wake the agent that started it.
113
- async function startDev({ cwd = process.cwd(), port, noMp = process.env.NO_MP === '1', watch = true, reload = true, share = false, openShare = openTunnel, log = console.log, agentSession = null, devLogPath = null } = {}, onFailure) {
113
+ //
114
+ // `shareIsOwner` is for a host that serves the share link to the creator
115
+ // alone and keeps everyone else off the dev tools' routes (the Joystack
116
+ // maker): a report sent through the link then counts as one from this
117
+ // machine, so it can wake the agent and read its reply.
118
+ async function startDev({ cwd = process.cwd(), port, noMp = process.env.NO_MP === '1', watch = true, reload = true, share = false, openShare = openTunnel, log = console.log, agentSession = null, shareIsOwner = false, devLogPath = null } = {}, onFailure) {
114
119
  const project = findProject(cwd);
115
120
  // Q4 revision: the engine is not an npm dependency — install/refresh it from
116
121
  // the platform's login-gated registry (no-op when the pinned version is in).
@@ -322,6 +327,7 @@ async function startDev({ cwd = process.cwd(), port, noMp = process.env.NO_MP ==
322
327
  log, // agent-inbox report lines ride the dev logger
323
328
  engineVersion: engine.version ?? null, // stamped on agent-inbox reports
324
329
  agentSession, // woken by agent-inbox reports sent from this machine
330
+ shareIsOwner, // and by those sent through the share link, when it is the creator's alone
325
331
  mounts: mountsFor(codeDir),
326
332
  ...(first ? { fixedBuild: first.build } : {}),
327
333
  versions: live ? {
package/lib/land.mjs ADDED
@@ -0,0 +1,63 @@
1
+ // `joystack land <name>`: put a lane's work into the game, then remove the
2
+ // lane (the /worktree skill, "Land the winner").
3
+ //
4
+ // Run from the game folder or from inside the lane. The lane's unsaved work
5
+ // is saved first, since landing is what the creator asked for. The game
6
+ // folder then merges the lane's branch. On a clean merge the lane's folder
7
+ // and branch go; on a clash the merge is left in progress in the game folder,
8
+ // with the rule for settling it, and running `land` again once it is settled
9
+ // and committed removes the lane.
10
+ import { execFileSync } from 'node:child_process';
11
+ import { existsSync } from 'node:fs';
12
+ import { dirname, resolve } from 'node:path';
13
+ import { isLane } from './lane.mjs';
14
+ import { findProject } from './project.mjs';
15
+
16
+ const git = (cwd, ...args) => execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
17
+
18
+ export const CLASH_RULE =
19
+ 'Keep both changes wherever both can be kept. Stop and ask the creator only where the two truly ' +
20
+ 'contradict, in game terms ("both versions change how jumping feels"), never in git terms.';
21
+
22
+ export async function land(name, { cwd = process.cwd(), log = console.log } = {}) {
23
+ if (!name) throw new Error('Name the lane: joystack land <name> (the name it was opened with: joystack lane <name>)');
24
+ const here = findProject(cwd).dir;
25
+ const main = isLane(here) ? findProject(dirname(git(here, 'rev-parse', '--path-format=absolute', '--git-common-dir'))).dir : here;
26
+ const slug = findProject(main).slug;
27
+ const branch = `lane/${name}`;
28
+ const dir = resolve(main, '..', `${slug}-${name}`);
29
+ try {
30
+ git(main, 'rev-parse', '--verify', '--quiet', `refs/heads/${branch}`);
31
+ } catch {
32
+ throw new Error(`There is no lane called "${name}" (no branch ${branch}).`);
33
+ }
34
+
35
+ if (existsSync(dir) && git(dir, 'status', '--porcelain')) {
36
+ git(dir, 'add', '-A');
37
+ git(dir, 'commit', '-q', '-m', `save: lane ${name}`);
38
+ log(`→ saved the lane's unsaved work (${branch})`);
39
+ }
40
+
41
+ if (git(main, 'diff', '--name-only', '--diff-filter=U')) {
42
+ throw new Error(`The game folder ${main} is still in the middle of a merge. Settle it and commit, then run joystack land ${name} again.\n${CLASH_RULE}`);
43
+ }
44
+ try {
45
+ git(main, 'merge', '--no-edit', branch);
46
+ } catch (err) {
47
+ const clashed = git(main, 'diff', '--name-only', '--diff-filter=U');
48
+ if (!clashed) throw new Error(`Landing ${branch} failed: ${String(err.stderr || err.message).trim()}`);
49
+ throw new Error(
50
+ `Landing ${branch} clashed with the game in:\n${clashed.split('\n').map((f) => ` ${f}`).join('\n')}\n` +
51
+ `The merge is in progress in ${main}. ${CLASH_RULE}\n` +
52
+ `Then commit the merge, and run joystack land ${name} again to remove the lane.`,
53
+ );
54
+ }
55
+ log(`→ landed ${branch} into the game`);
56
+
57
+ if (existsSync(dir)) {
58
+ git(main, 'worktree', 'remove', dir);
59
+ log(`→ removed ${dir}`);
60
+ }
61
+ git(main, 'branch', '-d', branch);
62
+ return { dir, branch };
63
+ }
package/lib/maker.mjs ADDED
@@ -0,0 +1,63 @@
1
+ // The commands that answer differently inside the Joystack maker.
2
+ //
3
+ // The maker is a web page around the same agent a creator runs in a game
4
+ // folder: it gives each conversation a lane of its own (a "draft"), runs that
5
+ // lane's dev server on the person's page, and has a Publish button that puts
6
+ // the draft in the game and the game online. Its agent reads the same
7
+ // AGENTS.md and skills as anyone, so it runs the same commands. These answer
8
+ // for the maker instead of doing what they do on a laptop, where they would
9
+ // open a lane the person never sees, start a server nobody looks at, or
10
+ // publish behind the page's back.
11
+ //
12
+ // The maker sets JOYSTACK_MAKER on the agent's process: the address of its
13
+ // own control API for this conversation's draft. Only the agent's commands
14
+ // carry it, never the dev servers the maker starts itself.
15
+
16
+ export function makerDraft(env = process.env) {
17
+ const at = String(env.JOYSTACK_MAKER ?? '').trim().replace(/\/+$/, '');
18
+ return at || null;
19
+ }
20
+
21
+ export const MAKER_LANE =
22
+ "You are in the Joystack maker: this folder is already this conversation's lane " +
23
+ '(the person sees it as a draft on their page). Build here. No new lane was made.';
24
+
25
+ export const MAKER_DEV =
26
+ "You are in the Joystack maker: this folder's dev server is already running, and the " +
27
+ 'person plays the game on their page, beside the chat. Every file you save shows up ' +
28
+ 'there. Nothing was started.';
29
+
30
+ // `publish` and `land` both do what the page's Publish button does: the draft
31
+ // goes into the game, and the game goes online under the name it has. The
32
+ // maker does it once the agent's turn ends, since it merges the files the
33
+ // agent is still working in. A game that has never been online has no name
34
+ // yet; the person picks one on the page.
35
+ export async function makerPublish(at, { slug = null, log = console.log, fetchImpl = fetch } = {}) {
36
+ if (slug) {
37
+ throw new Error(
38
+ 'You are in the Joystack maker: a game here has one name, which the person picks on their page, ' +
39
+ 'so --slug copies are not available. Run the command without --slug to publish under that name.',
40
+ );
41
+ }
42
+ let res;
43
+ try {
44
+ res = await fetchImpl(`${at}/publish`, { method: 'POST', signal: AbortSignal.timeout(15_000) });
45
+ } catch (err) {
46
+ throw new Error(`You are in the Joystack maker, and it did not answer (${err?.message ?? err}). Ask the person to press Publish on their page.`);
47
+ }
48
+ const body = await res.json().catch(() => ({}));
49
+ if (body.needsName) {
50
+ throw new Error(
51
+ 'You are in the Joystack maker, and this game has never been published: its first publish needs ' +
52
+ 'a name, which the person picks. Ask them to press Publish on their page.',
53
+ );
54
+ }
55
+ if (!res.ok || !body.ok) {
56
+ throw new Error(`You are in the Joystack maker, and it could not publish: ${body.error ?? `HTTP ${res.status}`}. Ask the person to press Publish on their page.`);
57
+ }
58
+ log(
59
+ 'You are in the Joystack maker: publishing this draft. When this turn ends, it goes into the game ' +
60
+ `and the game goes online${body.url ? ` at ${body.url}` : ''}. The person sees it happen on their page.`,
61
+ );
62
+ return body;
63
+ }
@@ -1064,7 +1064,7 @@ function rowSink({ file, columns, rowsPerGroup }) {
1064
1064
  finish() {
1065
1065
  flush();
1066
1066
  pq.finish();
1067
- renameSync(partial, file);
1067
+ renameInto(partial, file);
1068
1068
  return rows;
1069
1069
  },
1070
1070
  // Called when the run did not get that far. Best-effort: a leftover
@@ -1075,6 +1075,21 @@ function rowSink({ file, columns, rowsPerGroup }) {
1075
1075
  };
1076
1076
  }
1077
1077
 
1078
+ // On Windows a file that was just written can be refused a rename for a moment
1079
+ // (EPERM, EBUSY or EACCES) while another process still has it open. The
1080
+ // rename is retried for up to two seconds before it fails.
1081
+ function renameInto(from, to) {
1082
+ for (let i = 0; ; i++) {
1083
+ try {
1084
+ renameSync(from, to);
1085
+ return;
1086
+ } catch (err) {
1087
+ if (i >= 40 || !['EPERM', 'EBUSY', 'EACCES'].includes(err.code)) throw err;
1088
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50);
1089
+ }
1090
+ }
1091
+ }
1092
+
1078
1093
  /** A streaming Parquet writer for a table of `columns`, sized as the export sizes its own. */
1079
1094
  export function rowSinkFor(file, columns, rowsPerGroup) {
1080
1095
  return rowSink({ file, columns, rowsPerGroup: groupFor(columns, rowsPerGroup) });
@@ -337,6 +337,9 @@ export function createStaticServer({
337
337
  // in agent-session.mjs), or null. When set, an agent-inbox report from this
338
338
  // machine also wakes that session.
339
339
  agentSession = null,
340
+ // Whether a request through the share link is the creator's own (startDev's
341
+ // `shareIsOwner`): its agent-inbox reports then count as from this machine.
342
+ shareIsOwner = false,
340
343
  }) {
341
344
  // The tunnel hostname `joystack dev --share` opened to this server, once it is
342
345
  // up (setShareHost). See trustedHost.
@@ -858,6 +861,9 @@ export function createStaticServer({
858
861
  return turn;
859
862
  };
860
863
  const agentConnected = () => (sessionAlive(agentSession) ? agentSession.agent : null);
864
+ // The creator's own browser: on this machine, or through a share link that
865
+ // only the creator can reach the dev tools by.
866
+ const fromCreator = (req) => fromThisMachine(req) || (shareIsOwner && isShareHost(req.headers.host, shareHost));
861
867
 
862
868
  // The reply credential: this server's port and a bearer token, readable only
863
869
  // by the owner of the game folder, one file per server, so with two servers
@@ -890,7 +896,7 @@ export function createStaticServer({
890
896
  res.writeHead(403, { 'Content-Type': 'text/plain' });
891
897
  return res.end('cross-origin post rejected');
892
898
  }
893
- const local = fromThisMachine(req);
899
+ const local = fromCreator(req);
894
900
  const maxBytes = local ? AGENT_INBOX_LOCAL_MAX_BYTES : AGENT_INBOX_MAX_BYTES;
895
901
  const chunks = [];
896
902
  let size = 0;
@@ -986,7 +992,7 @@ export function createStaticServer({
986
992
  // so only this machine may read its replies. The custom header forces a CORS
987
993
  // preflight, which this server never grants, so no foreign page can read it.
988
994
  function handleInboxStatus(req, res) {
989
- if (!fromThisMachine(req) || !sameOrigin(req, { shareHost }) || req.headers['x-joystack-agent-ui'] !== '1') {
995
+ if (!fromCreator(req) || !sameOrigin(req, { shareHost }) || req.headers['x-joystack-agent-ui'] !== '1') {
990
996
  res.writeHead(403, { 'Content-Type': 'text/plain' });
991
997
  return res.end('dev tools only');
992
998
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystack/cli",
3
- "version": "0.1.48",
3
+ "version": "0.1.49",
4
4
  "description": "Joystack game development CLI \u2014 dev server, login, and publishing for standalone Joystack games.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",