@joystack/cli 0.0.0-stage → 0.1.43

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +738 -0
  2. package/LICENSE +202 -0
  3. package/README.md +21 -2
  4. package/bin/joystack.mjs +300 -0
  5. package/lib/agent-session.mjs +52 -0
  6. package/lib/agent-surface.mjs +333 -0
  7. package/lib/assets-json.mjs +205 -0
  8. package/lib/assets-page.mjs +184 -0
  9. package/lib/assets-sheet.mjs +365 -0
  10. package/lib/build-id.mjs +130 -0
  11. package/lib/bundle-primitives.mjs +123 -0
  12. package/lib/changelog.mjs +193 -0
  13. package/lib/config.mjs +56 -0
  14. package/lib/create.mjs +241 -0
  15. package/lib/dev.mjs +435 -0
  16. package/lib/engine.mjs +198 -0
  17. package/lib/feedback-sync.mjs +231 -0
  18. package/lib/feedback.mjs +209 -0
  19. package/lib/freeze.mjs +108 -0
  20. package/lib/game-files.mjs +99 -0
  21. package/lib/history.mjs +612 -0
  22. package/lib/inbox-cmd.mjs +57 -0
  23. package/lib/inject.mjs +250 -0
  24. package/lib/joystack-node-doors.mjs +230 -0
  25. package/lib/lane.mjs +141 -0
  26. package/lib/legacy-names.mjs +246 -0
  27. package/lib/lint.mjs +292 -0
  28. package/lib/login.mjs +134 -0
  29. package/lib/model-bake-cli.mjs +17 -0
  30. package/lib/model-bake.mjs +869 -0
  31. package/lib/npm.mjs +38 -0
  32. package/lib/ports.mjs +234 -0
  33. package/lib/primitives.mjs +393 -0
  34. package/lib/printable.mjs +12 -0
  35. package/lib/process-tree.mjs +30 -0
  36. package/lib/project.mjs +84 -0
  37. package/lib/publish.mjs +179 -0
  38. package/lib/replay-cmd.mjs +426 -0
  39. package/lib/replay-export.mjs +1379 -0
  40. package/lib/replay-list.mjs +308 -0
  41. package/lib/replay-profile.mjs +467 -0
  42. package/lib/replay-store.mjs +719 -0
  43. package/lib/room-reload.mjs +168 -0
  44. package/lib/room-server.mjs +539 -0
  45. package/lib/self-update.mjs +162 -0
  46. package/lib/shadow-resolve.mjs +85 -0
  47. package/lib/share.mjs +149 -0
  48. package/lib/smoke-gpu-preload.mjs +91 -0
  49. package/lib/source-path.mjs +33 -0
  50. package/lib/static-server.mjs +1238 -0
  51. package/lib/test-cmd.mjs +697 -0
  52. package/lib/test-policy.mjs +157 -0
  53. package/lib/test-reporter.mjs +177 -0
  54. package/lib/test-selection-cli.mjs +18 -0
  55. package/lib/update.mjs +299 -0
  56. package/package.json +27 -4
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,22 @@
1
- # Temporary Holding Version
1
+ # @joystack/cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Joystack game-development CLI: bootstrap, run, and publish multiplayer games.
4
+ A published game is served from its own address, `https://<slug>.joystack.games/`.
5
+
6
+ ```bash
7
+ npx joystack create my-game
8
+ cd my-game
9
+ npx joystack dev
10
+ ```
11
+
12
+ New here? Point your AI agent at **https://docs.joystack.ai/setup.md** and say
13
+ "set me up to make Joystack games."
14
+
15
+ ## License
16
+
17
+ This CLI is licensed under **Apache-2.0** (see `LICENSE`) — **the CLI only**.
18
+
19
+ The **Joystack engine** that the CLI downloads for you (after `joystack login`) is a
20
+ separate, proprietary work and is NOT covered by this package's license. It is
21
+ governed by the [Joystack Engine License](https://docs.joystack.ai/engine-license.md),
22
+ which you accept when connecting your computer to your Joystack account.
@@ -0,0 +1,300 @@
1
+ #!/usr/bin/env node
2
+ // joystack — the Joystack game-development CLI.
3
+ //
4
+ // Runs inside a standalone game folder (its own repo). The agent is the
5
+ // primary user: keep output plain, actionable, and machine-legible.
6
+ import { dev } from '../lib/dev.mjs';
7
+ import { agentSessionFromEnv } from '../lib/agent-session.mjs';
8
+ import { lane } from '../lib/lane.mjs';
9
+ import { login, logout, whoami } from '../lib/login.mjs';
10
+ import { publish } from '../lib/publish.mjs';
11
+ import { create } from '../lib/create.mjs';
12
+ import { parseTestArgs, TEST_HELP } from '../lib/test-policy.mjs';
13
+ import { testCmd } from '../lib/test-cmd.mjs';
14
+ import { lintCmd } from '../lib/lint.mjs';
15
+ import { update } from '../lib/update.mjs';
16
+ import { changelog } from '../lib/changelog.mjs';
17
+ import { sendFeedback } from '../lib/feedback.mjs';
18
+ import { syncFeedback } from '../lib/feedback-sync.mjs';
19
+ import { printableLines } from '../lib/printable.mjs';
20
+
21
+ const [, , cmd, ...rest] = process.argv;
22
+
23
+ function flag(name) {
24
+ const i = rest.indexOf(`--${name}`);
25
+ return i === -1 ? undefined : rest[i + 1];
26
+ }
27
+
28
+ const HELP = `joystack — build and run Joystack games
29
+
30
+ Usage:
31
+ joystack create <name> Bootstrap a new game folder (multiplayer works out of the box)
32
+ joystack dev [--port <n>] Run the full dev stack (game + multiplayer + services)
33
+ joystack dev --share ...and print a public link testers can play (needs cloudflared)
34
+ joystack dev --no-reload ...frozen as it is now: saves reach nobody until you restart it
35
+ joystack assets [<id>] Browse and drive your models, sounds and assets on their own
36
+ joystack assets <id> --sheet Draw a view sheet of a 3D asset to .joystack/sheets/ (--help: options)
37
+ joystack assets --json [<id>…] Print each asset's parameters, measured stats and flags as JSON
38
+ joystack lane <name> Open an isolated copy of the game to experiment in, safely
39
+ joystack test [aspect] Run targeted checks (no aspect: conservative full run)
40
+ joystack test --since <base> Submission: ordinary + triggered extended checks
41
+ joystack test --all Explicit full audit; add --list to preview selection
42
+ joystack test --help Everything about running and reading tests
43
+ joystack lint [--fix] Check the game against the Joystack rules (runs inside 'joystack test')
44
+ joystack changelog [<v>] What changed in the engine (default: everything newer than your pin)
45
+ joystack update [--rc <v>] Move this game to the latest engine release (--rc <v> takes a specific pre-release)
46
+ joystack model bake <glb> Re-bake a 3D model's server-side hit data now (normally automatic)
47
+ joystack publish [--slug <s>] [--dev-tools]
48
+ Publish this game to <slug>.joystack.games (--slug for an A/B copy;
49
+ --dev-tools makes that copy a review build with Tweaks on)
50
+ joystack build-id The id of this game's code as it is now, with its git commit
51
+ joystack replay list Every recorded session: when, how long, on what device, which build
52
+ joystack replay export [<id>] Turn a recorded session into tables you can query (Parquet)
53
+ joystack replay profile [<id>] --ticks <a-b>
54
+ Which functions ran in those ticks, as a table
55
+ joystack feedback Send reports + replies under notes/feedback/; pull outcomes back in
56
+ joystack inbox reply <id> "<text>" Answer a report a dev tool sent your agent; the text shows in the tool
57
+ joystack login Authenticate this machine as your Joystack player account
58
+ joystack logout [--all] Sign out: revoke the token (--all: on every machine)
59
+ joystack whoami Show who this machine publishes as
60
+ joystack help This message
61
+
62
+ The dev stack serves your game at http://localhost:8000/games/<name>/index.html
63
+ with local multiplayer on :1999. Run several at once (a lane, another game) and
64
+ each picks its own free ports — 'joystack dev' never disturbs a stack that isn't
65
+ its own.
66
+ `;
67
+
68
+ try {
69
+ switch (cmd) {
70
+ case 'dev': {
71
+ const handle = await dev({ port: flag('port') ? Number(flag('port')) : undefined, share: rest.includes('--share'), reload: !rest.includes('--no-reload'), agentSession: agentSessionFromEnv() });
72
+ const shutdown = () => {
73
+ handle.stop();
74
+ process.exit(0);
75
+ };
76
+ process.on('SIGINT', shutdown);
77
+ process.on('SIGTERM', shutdown);
78
+ // Keep the process alive; servers + children hold the loop open.
79
+ break;
80
+ }
81
+ case 'assets': {
82
+ // `--json`: print what each asset is, measured by the page headless,
83
+ // instead of opening it (assets-json.mjs). stdout carries the JSON and
84
+ // nothing else, so it can be piped; everything else goes to stderr.
85
+ if (rest.includes('--json')) {
86
+ const { assetsJson, parseJsonArgs, safeJson, JSON_HELP } = await import('../lib/assets-json.mjs');
87
+ const { printable } = await import('../lib/printable.mjs');
88
+ if (rest.includes('--help')) {
89
+ console.log(JSON_HELP);
90
+ break;
91
+ }
92
+ const progress = process.stderr.isTTY
93
+ ? (i, n, id) => process.stderr.write(`\r measuring ${i + 1}/${n} ${[...printable(id)].slice(0, 40).join('').padEnd(40)}`)
94
+ : () => {};
95
+ // A stack started for the listing is stopped on Ctrl-C too.
96
+ let started = null;
97
+ const interrupt = async () => {
98
+ await started?.stop();
99
+ process.exit(130);
100
+ };
101
+ process.on('SIGINT', interrupt);
102
+ process.on('SIGTERM', interrupt);
103
+ let out;
104
+ try {
105
+ out = await assetsJson({ ...parseJsonArgs(rest), startDev: dev, progress, onStarted: (s) => { started = s; } });
106
+ } catch (err) {
107
+ // An error here may quote the game's own text, so every line of it
108
+ // is made printable before it reaches the terminal.
109
+ if (process.stderr.isTTY) process.stderr.write('\r\x1b[K');
110
+ console.error(`joystack assets: ${printableLines(err?.message ?? err)}`);
111
+ process.exit(1);
112
+ }
113
+ if (process.stderr.isTTY) process.stderr.write('\r\x1b[K');
114
+ process.off('SIGINT', interrupt);
115
+ process.off('SIGTERM', interrupt);
116
+ const failed = out.assets.filter((a) => a.error);
117
+ for (const a of failed) console.error(`joystack assets: ${printable(a.id)} could not be measured: ${printable(a.error)}`);
118
+ // An exit code, not process.exit(): stdout to a pipe is written
119
+ // asynchronously, and exiting at once cuts a long listing off at the
120
+ // pipe's buffer (64 KB on macOS), which leaves invalid JSON.
121
+ process.exitCode = failed.length ? 1 : 0;
122
+ process.stdout.write(`${safeJson(out)}\n`);
123
+ break;
124
+ }
125
+ // `--sheet`: draw a view sheet headless and write it to disk, instead
126
+ // of opening the page (assets-sheet.mjs).
127
+ if (rest.includes('--sheet')) {
128
+ const { assetsSheet, parseSheetArgs, printable, SHEET_HELP } = await import('../lib/assets-sheet.mjs');
129
+ if (rest.includes('--help')) {
130
+ console.log(SHEET_HELP);
131
+ break;
132
+ }
133
+ let missingRefs;
134
+ try {
135
+ ({ missingRefs } = await assetsSheet({ ...parseSheetArgs(rest), startDev: dev }));
136
+ } catch (err) {
137
+ // An error here may quote the game's own text, so every line of it
138
+ // is made printable before it reaches the terminal.
139
+ console.error(`joystack assets: ${printableLines(err?.message ?? err)}`);
140
+ process.exit(1);
141
+ }
142
+ if (missingRefs.length) {
143
+ console.error(`joystack assets: ${missingRefs.length === 1 ? 'a reference image' : 'reference images'} declared in assets.js could not be shown: ${missingRefs.map((m) => printable(m.src)).join(', ')}`);
144
+ process.exit(1);
145
+ }
146
+ process.exit(0);
147
+ }
148
+ // The same dev stack `joystack dev` runs, opened on the assets page. Not a
149
+ // second server: the assets page is a page under /shared/, which this one
150
+ // already mounts. A healthy `joystack dev` already running for this game is
151
+ // reused rather than replaced (assets-page.mjs, openAssets).
152
+ const { openAssets, openBrowser, itemArg } = await import('../lib/assets-page.mjs');
153
+ const { reused, target, handle, agentUnreachable } = await openAssets({
154
+ port: flag('port') ? Number(flag('port')) : undefined,
155
+ item: itemArg(rest),
156
+ agentSession: agentSessionFromEnv(),
157
+ startDev: dev,
158
+ });
159
+ if (reused) console.log('\n → using the dev stack already running for this game');
160
+ if (agentUnreachable) {
161
+ console.log(' ⚠ that stack was not started by a coding agent, so notes sent from the Assets page are only filed.');
162
+ console.log(' To have them reach you, stop it and run `joystack dev` (or `joystack assets`) from your agent.');
163
+ }
164
+ console.log(`\n 🔎 Assets → ${target}\n`);
165
+ if (!rest.includes('--no-open')) openBrowser(target);
166
+ // A reused stack belongs to the `joystack dev` that started it; there is
167
+ // nothing here to keep alive or to stop.
168
+ if (!handle) break;
169
+ const shutdown = () => {
170
+ handle.stop();
171
+ process.exit(0);
172
+ };
173
+ process.on('SIGINT', shutdown);
174
+ process.on('SIGTERM', shutdown);
175
+ break;
176
+ }
177
+ case 'inbox': {
178
+ const { inboxReply, INBOX_HELP } = await import('../lib/inbox-cmd.mjs');
179
+ const dirAt = rest.indexOf('--dir');
180
+ if (dirAt !== -1 && (!rest[dirAt + 1] || rest[dirAt + 1].startsWith('--'))) throw new Error(`--dir needs a folder. Usage: ${INBOX_HELP}`);
181
+ const args = dirAt === -1 ? rest : [...rest.slice(0, dirAt), ...rest.slice(dirAt + 2)];
182
+ if (args[0] !== 'reply') throw new Error(`Usage: ${INBOX_HELP}`);
183
+ await inboxReply({ dir: flag('dir'), id: args[1], text: args.slice(2).join(' ') });
184
+ break;
185
+ }
186
+ case 'lane': {
187
+ const name = rest.find((a) => !a.startsWith('--'));
188
+ if (!name) throw new Error('Name the lane: joystack lane <name> (e.g. joystack lane judder)');
189
+ const { dir } = await lane(name);
190
+ console.log(`\nWork in it:\n cd ${dir} && npx joystack dev\n`);
191
+ break;
192
+ }
193
+ case 'create':
194
+ await create({ name: rest.find((a) => !a.startsWith('--')) });
195
+ break;
196
+ case 'test': {
197
+ const options = parseTestArgs(rest);
198
+ if (options.help) {
199
+ console.log(TEST_HELP);
200
+ break;
201
+ }
202
+ const { ok } = await testCmd(options);
203
+ process.exit(ok ? 0 : 1);
204
+ }
205
+ case 'lint': {
206
+ const { ok } = await lintCmd({ fix: rest.includes('--fix') });
207
+ process.exit(ok ? 0 : 1);
208
+ }
209
+ case 'changelog':
210
+ await changelog({
211
+ version: rest.find((a) => !a.startsWith('--')),
212
+ all: rest.includes('--all'),
213
+ });
214
+ break;
215
+ case 'update': {
216
+ // `--rc <version>` takes an exact release candidate by reference (a
217
+ // pre-release you were handed); no flag → the normal newest-stable update.
218
+ const rcIdx = rest.indexOf('--rc');
219
+ const target = rcIdx >= 0 ? rest[rcIdx + 1] : null;
220
+ if (rcIdx >= 0 && !target) throw new Error('`--rc` needs a version, e.g. `joystack update --rc 0.2.0-rc.1`');
221
+ await update({ target });
222
+ break;
223
+ }
224
+ case 'model': {
225
+ // `model` is the accessor for 3D-model tooling; `bake` is its first verb.
226
+ // Baking is normally automatic (dev/test/publish re-bake changed models);
227
+ // this is the explicit escape hatch.
228
+ const [verb, glb] = rest.filter((a) => !a.startsWith('--'));
229
+ if (verb !== 'bake') throw new Error(`Unknown model command: ${verb ?? '(none)'} — try: joystack model bake <file.glb>`);
230
+ if (!glb) throw new Error('Name the model: joystack model bake <file.glb>');
231
+ const { bakeModel } = await import('../lib/model-bake.mjs');
232
+ await bakeModel(glb);
233
+ break;
234
+ }
235
+ case 'build-id': {
236
+ const { buildIdCommand } = await import('../lib/build-id.mjs');
237
+ buildIdCommand({ json: rest.includes('--json') });
238
+ break;
239
+ }
240
+ case 'replay': {
241
+ // `replay` is the accessor for a recorded session; `export` is its first
242
+ // verb. Watching one back needs no command at all — it is `?replay=<id>`
243
+ // on the game's URL, or the toolbox's Sessions panel.
244
+ const { REPLAY_HELP, replayExport, replayProfile, replayList, parseReplayArgs } = await import('../lib/replay-cmd.mjs');
245
+ // Parsed in the lib so the argv split is under test — a flag's value must
246
+ // never slide into the session slot, and --help must be answered before
247
+ // anything is read as an id.
248
+ const { verb, id, out, ticks, json, repeat, help } = parseReplayArgs(rest);
249
+ if (help) {
250
+ console.log(REPLAY_HELP);
251
+ break;
252
+ }
253
+ if (verb === 'list') {
254
+ await replayList({ json });
255
+ break;
256
+ }
257
+ if (verb === 'profile') {
258
+ await replayProfile({ stream: id, ticks, out, repeat });
259
+ break;
260
+ }
261
+ if (verb !== 'export') {
262
+ throw new Error(`Unknown replay command: ${verb} — try: joystack replay list, joystack replay export, or joystack replay profile`);
263
+ }
264
+ await replayExport({ stream: id, out });
265
+ break;
266
+ }
267
+ case 'publish':
268
+ await publish({ slug: flag('slug'), devTools: rest.includes('--dev-tools') });
269
+ break;
270
+ case 'feedback':
271
+ // Send first, then sync: a report filed this run is already stamped with
272
+ // its id, so the same invocation can pull any outcome waiting for it.
273
+ await sendFeedback();
274
+ await syncFeedback();
275
+ break;
276
+ case 'login':
277
+ await login();
278
+ break;
279
+ case 'logout':
280
+ await logout({ all: rest.includes('--all') });
281
+ break;
282
+ case 'whoami':
283
+ await whoami();
284
+ break;
285
+ case undefined:
286
+ case 'help':
287
+ case '--help':
288
+ case '-h':
289
+ console.log(HELP);
290
+ break;
291
+ default:
292
+ console.error(`Unknown command: ${printableLines(cmd)}\n\n${HELP}`);
293
+ process.exit(2);
294
+ }
295
+ } catch (err) {
296
+ // Printable, line by line: a message can quote a file from the game folder
297
+ // or text a page returned, and a terminal must not act on either.
298
+ console.error(`joystack ${printableLines(cmd)}: ${printableLines(err?.message ?? err)}`);
299
+ process.exit(1);
300
+ }
@@ -0,0 +1,52 @@
1
+ // The coding-agent session that started this dev server, if one did.
2
+ //
3
+ // Claude Code exports the address of each session's inbox socket to every
4
+ // command that session runs (CLAUDE_CODE_MESSAGING_SOCKET, with a per-session
5
+ // CLAUDE_CODE_MESSAGING_TOKEN). A `joystack dev` the agent started therefore
6
+ // inherits the address of exactly the conversation that started it, and a
7
+ // message posted there reaches that conversation, starting a new turn if it
8
+ // is idle. No flag, plugin or setting is involved, and a dev server started
9
+ // from a plain terminal inherits nothing, so it never guesses at a session.
10
+ //
11
+ // The socket protocol is newline-delimited JSON: an optional auth line, then
12
+ // one frame per message. The auth line lets Claude Code verify the sender as
13
+ // one of the session's own child processes, which it delivers without asking.
14
+ import { existsSync } from 'node:fs';
15
+ import { createConnection } from 'node:net';
16
+ import { randomUUID } from 'node:crypto';
17
+
18
+ export function agentSessionFromEnv(env = process.env) {
19
+ const address = env.CLAUDE_CODE_MESSAGING_SOCKET;
20
+ if (!address) return null;
21
+ return { agent: 'Claude Code', socket: address.replace(/^uds:/, ''), token: env.CLAUDE_CODE_MESSAGING_TOKEN || null };
22
+ }
23
+
24
+ // The environment with the session's address and token removed, for the
25
+ // processes the dev server starts itself (the room server, the tunnel): none
26
+ // of them may post into the agent's conversation.
27
+ export function withoutAgentSession(env = process.env) {
28
+ const { CLAUDE_CODE_MESSAGING_SOCKET: _socket, CLAUDE_CODE_MESSAGING_TOKEN: _token, ...rest } = env;
29
+ return rest;
30
+ }
31
+
32
+ // The socket file is removed when its session exits. On native Windows the
33
+ // address is a named pipe, which has no file to check, so it counts as live.
34
+ export function sessionAlive(session) {
35
+ if (!session) return false;
36
+ return session.socket.startsWith('\\\\.\\pipe\\') || existsSync(session.socket);
37
+ }
38
+
39
+ // Resolves once the session has accepted the message; rejects if it cannot
40
+ // be reached within five seconds.
41
+ export function postToSession(session, content) {
42
+ return new Promise((resolve, reject) => {
43
+ const conn = createConnection(session.socket, () => {
44
+ if (session.token) conn.write(`${JSON.stringify({ type: 'auth', token: session.token })}\n`);
45
+ conn.end(`${JSON.stringify({ msgV: 1, msg_id: randomUUID(), type: 'user', message: { role: 'user', content }, priority: 'next' })}\n`);
46
+ });
47
+ conn.setTimeout(5000, () => conn.destroy(new Error('the agent session did not accept the message')));
48
+ conn.on('error', reject);
49
+ conn.on('close', (hadError) => { if (!hadError) resolve(); });
50
+ conn.resume();
51
+ });
52
+ }