@floless/app 0.158.0 → 0.159.0

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 (35) hide show
  1. package/dist/floless-server.cjs +92620 -75445
  2. package/dist/schemas/drawing-check.profile.v1.schema.json +33 -1
  3. package/dist/skills/floless-app-actions/SKILL.md +23 -5
  4. package/dist/skills/floless-app-bridge/SKILL.md +5 -3
  5. package/dist/skills/floless-app-onboarding/SKILL.md +67 -4
  6. package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +7 -4
  7. package/dist/skills/floless-app-queue/SKILL.md +3 -1
  8. package/dist/skills/floless-app-steel-model/SKILL.md +11 -5
  9. package/dist/skills/floless-app-steel-takeoff/SKILL.md +28 -8
  10. package/dist/skills/floless-app-workflows/SKILL.md +6 -3
  11. package/dist/web/agents.js +12 -5
  12. package/dist/web/app.css +87 -13
  13. package/dist/web/app.js +6 -0
  14. package/dist/web/aware.js +29 -4
  15. package/dist/web/chat.css +42 -22
  16. package/dist/web/chat.js +181 -30
  17. package/dist/web/commands-shell.js +305 -4
  18. package/dist/web/commands-steel.js +1 -0
  19. package/dist/web/drawing-check-editor.html +10 -0
  20. package/dist/web/drawing-check-editor.js +44 -0
  21. package/dist/web/guide.js +4 -2
  22. package/dist/web/index.html +41 -9
  23. package/dist/web/instructor.js +20 -8
  24. package/dist/web/pages.js +71 -13
  25. package/dist/web/project-access.js +67 -8
  26. package/dist/web/project-modules.js +474 -0
  27. package/dist/web/project-workflows.js +274 -0
  28. package/dist/web/steel-3d-core.js +46 -0
  29. package/dist/web/steel-3d-view.js +8 -38
  30. package/dist/web/steel-editor.html +192 -49
  31. package/dist/web/workspace-root-recovery.js +119 -0
  32. package/dist/web/workspaces.js +358 -114
  33. package/launch-starting-page.mjs +5 -2
  34. package/launch.mjs +136 -78
  35. package/package.json +5 -1
@@ -9,7 +9,7 @@ import { mkdirSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } f
9
9
  import { join } from 'node:path';
10
10
  import { pathToFileURL } from 'node:url';
11
11
 
12
- export const STARTING_STATES = ['starting', 'slow', 'ready', 'stopped', 'gave-up'];
12
+ export const STARTING_STATES = ['starting', 'slow', 'ready', 'stopped', 'gave-up', 'port-busy'];
13
13
 
14
14
  const RETRY_URL = 'floless://open';
15
15
  const DOWNLOAD_URL = 'https://floless.io/app';
@@ -22,6 +22,9 @@ export const STARTING_COPY = {
22
22
  slow: { title: 'Still starting FloLess', headline: 'Still starting. Thanks for waiting.',
23
23
  body: 'Large installs can take a few minutes to start. Keep this window open and FloLess will appear when it is ready.', actions: [] },
24
24
  ready: { title: 'Opening FloLess', headline: 'FloLess is ready', body: 'Opening now…', actions: [] },
25
+ 'port-busy': { title: 'FloLess cannot open yet', headline: 'FloLess cannot open yet',
26
+ body: 'FloLess’s connection is unavailable. Another program may be using it. Close that program if you can, then choose Try again.',
27
+ actions: ['retry'] },
25
28
  stopped: { title: 'FloLess stopped', headline: 'FloLess stopped before it finished starting',
26
29
  body: 'It closed before it was ready, so nothing opened. Try again, or open FloLess from the Start menu. If it keeps happening, download the latest version.',
27
30
  actions: ['retry', 'download'] },
@@ -119,7 +122,7 @@ export function startingPageHtml(appUrl) {
119
122
  if (copy.actions.length) actions.firstChild.focus();
120
123
  }
121
124
  window.flolessStarting = function (update) { if (update && update.state) show(update.state); };
122
- var settled = { ready: true, stopped: true, 'gave-up': true };
125
+ var settled = { ready: true, stopped: true, 'gave-up': true, 'port-busy': true };
123
126
  function poll() {
124
127
  if (settled[state]) return;
125
128
  var tag = document.createElement('script');
package/launch.mjs CHANGED
@@ -14,6 +14,7 @@ import { fileURLToPath } from 'node:url';
14
14
  import { distributionProfile } from './distribution-profile-active.mjs';
15
15
  import { existsSync, readFileSync } from 'node:fs';
16
16
  import http from 'node:http';
17
+ import net from 'node:net';
17
18
  import { createInterface } from 'node:readline';
18
19
  import { rotateLog, openLogFd, logDir } from './log.mjs';
19
20
  import { startingPageDir, writeStartingPage } from './launch-starting-page.mjs';
@@ -39,38 +40,91 @@ const isPackagedDistributionExe = (path = process.execPath) => basename(path ||
39
40
  // logging" intent.)
40
41
  const log = (m) => { try { process.stdout.write(`floless: ${m}\n`); } catch { /* dead stdout (GUI subsystem, no console) */ } };
41
42
 
42
- // One health probe → resolves true iff the server answers 200 quickly.
43
- function ping() {
43
+ // A complete, identifiable FloLess response, bounded even if a listener trickles bytes forever.
44
+ async function readHealth({ url = HEALTH_URL, timeoutMs = 5000 } = {}) {
44
45
  return new Promise((resolve) => {
45
- const req = http.get(HEALTH_URL, { timeout: 1500 }, (res) => {
46
- res.resume();
47
- resolve(res.statusCode === 200);
46
+ let done = false;
47
+ const finish = (value) => { if (done) return; done = true; clearTimeout(timer); req.destroy(); resolve(value); };
48
+ const timer = setTimeout(() => finish(null), timeoutMs);
49
+ const req = http.get(url, (res) => {
50
+ let body = '';
51
+ res.on('data', (chunk) => { body += chunk; if (body.length > 65536) finish(null); });
52
+ res.on('end', () => {
53
+ try { const j = JSON.parse(body); finish(res.statusCode === 200 && j?.ok === true && typeof j.appVersion === 'string' && j.appVersion.length > 0 ? j : null); }
54
+ catch { finish(null); }
55
+ });
56
+ res.on('error', () => finish(null));
57
+ res.on('aborted', () => finish(null));
48
58
  });
49
- req.on('error', () => resolve(false));
50
- req.on('timeout', () => { req.destroy(); resolve(false); });
59
+ req.on('error', () => finish(null));
60
+ });
61
+ }
62
+
63
+ export async function ping(options) { return (await readHealth(options)) !== null; }
64
+
65
+ // A failed health request does not mean the port is free. On uncertainty, never spawn over it.
66
+ export function portListening({ port = PORT, timeoutMs = 500 } = {}) {
67
+ return new Promise((resolve) => {
68
+ const socket = net.createConnection({ host: '127.0.0.1', port });
69
+ const finish = (value) => { clearTimeout(timer); socket.destroy(); resolve(value); };
70
+ const timer = setTimeout(() => finish(true), timeoutMs);
71
+ socket.once('connect', () => finish(true));
72
+ socket.once('error', (error) => finish(error.code !== 'ECONNREFUSED'));
51
73
  });
52
74
  }
53
75
 
76
+ export const BUSY_PORT_GRACE_MS = 30_000;
77
+
78
+ // Retain the child across supervisor ticks: slow work before listen must not start another boot.
79
+ export function createServerAttempt({ start = startServerDetached, healthy = ping, listening = portListening, now = Date.now, say = log } = {}) {
80
+ let child = null;
81
+ let exited = false;
82
+ let attached = false;
83
+ let busySince = null;
84
+ return {
85
+ get exited() { return exited && !attached; },
86
+ async poll() {
87
+ const left = busySince === null ? BUSY_PORT_GRACE_MS : BUSY_PORT_GRACE_MS - (now() - busySince);
88
+ // The grace bounds one attachment, not all future supervisor probes. An expired grace must
89
+ // not trap the retained attempt in 1 ms probes that cannot recognise a healthy listener.
90
+ const remaining = left > 0 ? left : BUSY_PORT_GRACE_MS;
91
+ if (await healthy({ timeoutMs: Math.min(5000, remaining) })) { busySince = null; return 'ready'; }
92
+ if (child && !exited) return 'waiting';
93
+ attached = await listening({ timeoutMs: Math.min(500, remaining) });
94
+ if (attached) {
95
+ busySince ??= now();
96
+ return now() - busySince >= BUSY_PORT_GRACE_MS ? 'port-busy' : 'waiting';
97
+ }
98
+ busySince = null;
99
+ if (child) return 'stopped';
100
+ child = start();
101
+ exited = child?.exitCode != null;
102
+ child?.once?.('exit', () => { exited = true; });
103
+ child?.once?.('error', (error) => { exited = true; say(`could not start the server (${error?.code ?? 'unknown error'})`); });
104
+ return 'waiting';
105
+ },
106
+ };
107
+ }
108
+
109
+ export async function waitForServerAttempt(attempt, { timeoutMs = BUSY_PORT_GRACE_MS + 6000, now = Date.now,
110
+ sleep = (ms) => new Promise((r) => setTimeout(r, ms)) } = {}) {
111
+ const deadline = now() + timeoutMs;
112
+ while (now() < deadline) {
113
+ const result = await attempt.poll();
114
+ if (result !== 'waiting') return result;
115
+ await sleep(1000);
116
+ }
117
+ return 'waiting';
118
+ }
119
+
54
120
  // Probe the running server via /api/health for what it says about itself: its build version
55
121
  // (appVersion — the installed build, "so it's scriptable") AND its distribution channel. Either is
56
122
  // null when unreachable, non-JSON, or not a floless server — in which case we never touch it.
57
123
  // `channel` is additionally null on builds older than the field, which shouldTakeOver reads as
58
124
  // "cannot identify, do not evict".
59
- function probeRunning() {
60
- return new Promise((resolve) => {
61
- const req = http.get(HEALTH_URL, { timeout: 1500 }, (res) => {
62
- let body = '';
63
- res.on('data', (c) => { body += c; });
64
- res.on('end', () => {
65
- try {
66
- const j = JSON.parse(body);
67
- resolve({ version: j.appVersion || null, channel: j.appChannel || null });
68
- } catch { resolve({ version: null, channel: null }); }
69
- });
70
- });
71
- req.on('error', () => resolve({ version: null, channel: null }));
72
- req.on('timeout', () => { req.destroy(); resolve({ version: null, channel: null }); });
73
- });
125
+ async function probeRunning() {
126
+ const response = await readHealth();
127
+ return { version: response?.appVersion ?? null, channel: response?.appChannel ?? null };
74
128
  }
75
129
 
76
130
  // Compare dotted numeric versions: 1 if a>b, -1 if a<b, 0 if equal.
@@ -118,15 +172,6 @@ export function shouldTakeOver(runningVersion, selfVersion, channels = {}) {
118
172
  let _selfVersion = null;
119
173
  let _selfChannel = null;
120
174
 
121
- async function waitHealthy(timeoutMs = 30000) {
122
- const deadline = Date.now() + timeoutMs;
123
- while (Date.now() < deadline) {
124
- if (await ping()) return true;
125
- await new Promise((r) => setTimeout(r, 500));
126
- }
127
- return false;
128
- }
129
-
130
175
  // Resolve how to start the server from wherever this launcher is installed:
131
176
  // 1. Packaged SEA exe → spawn SELF with --serve (the main.ts dispatcher serves).
132
177
  // 2. Repo checkout → run TypeScript source, even when an old dist/ bundle exists.
@@ -191,17 +236,18 @@ function stopServer() {
191
236
  }
192
237
  }
193
238
 
194
- // Start the detached server if it isn't already listening; block until healthy.
195
- // Shared by `open` (which then opens the browser) and `start` (which does not).
196
- async function ensureServerUp() {
197
- if (await ping()) return;
198
- log('starting server…');
199
- startServerDetached();
200
- if (!(await waitHealthy())) {
201
- log(`server did not become healthy on ${HEALTH_URL} within 30s — check for errors with "npm run dev"`);
202
- process.exit(1);
239
+ // Headless startup: identify an existing listener or start on a free port, then return whether it
240
+ // became healthy within the bounded wait. Used by start, login, actions and the post-update open.
241
+ export async function ensureServerUp({ attempt = createServerAttempt(), wait = waitForServerAttempt, say = log } = {}) {
242
+ const result = await wait(attempt);
243
+ if (result !== 'ready') {
244
+ say(result === 'port-busy' ? 'FloLess’s connection is unavailable. Another program may be using it. Close that program if you can, then launch FloLess again.'
245
+ : result === 'stopped' ? 'FloLess stopped before it finished starting. Try again, or open FloLess from the Start menu.'
246
+ : 'FloLess is not ready yet. Wait a moment, then launch FloLess again.');
247
+ return false;
203
248
  }
204
- log('server up');
249
+ say('server up');
250
+ return true;
205
251
  }
206
252
 
207
253
  // How `open` waits for a server it has just started. A normal start answers within a few seconds and
@@ -222,6 +268,7 @@ export const EXIT_GRACE_MS = 10_000;
222
268
  export async function startAndOpen({
223
269
  start = startServerDetached,
224
270
  healthy = ping,
271
+ listening = portListening,
225
272
  open = openBrowser,
226
273
  page = () => writeStartingPage(startingPageDir(join(dirname(logDir()), 'starting'), PORT, process.pid), BROWSER_URL),
227
274
  now = Date.now,
@@ -229,13 +276,13 @@ export async function startAndOpen({
229
276
  say = log,
230
277
  } = {}) {
231
278
  say('starting server…');
232
- const child = start();
233
- let exited = child?.exitCode != null;
234
- child?.once?.('exit', () => { exited = true; });
279
+ const attempt = createServerAttempt({ start, healthy, listening, now, say });
280
+ let result;
235
281
  const startedAt = now();
236
282
  while (now() - startedAt < QUICK_START_MS) {
237
- if (await healthy()) { say('server up'); say(`opening ${BROWSER_URL}`); open(BROWSER_URL); return 'opened'; }
238
- if (exited) break;
283
+ result = await attempt.poll();
284
+ if (result === 'ready') { say('server up'); say(`opening ${BROWSER_URL}`); open(BROWSER_URL); return 'opened'; }
285
+ if (attempt.exited || result === 'port-busy') break;
239
286
  await sleep(500);
240
287
  }
241
288
  // The page is a convenience; a data folder it cannot be written to must not cost the person the app.
@@ -257,13 +304,20 @@ export async function startAndOpen({
257
304
  let slow = false;
258
305
  let exitedAt = null;
259
306
  for (;;) {
260
- if (await healthy()) {
307
+ result = await attempt.poll();
308
+ if (result === 'ready') {
261
309
  // No page, or a page that cannot be told: open the app itself rather than leave it spinning.
262
310
  if (!(await settle('ready'))) open(BROWSER_URL);
263
311
  say(`server up after ${Math.round((now() - startedAt) / 1000)}s`);
264
312
  return 'ready';
265
313
  }
266
- if (exited) {
314
+ if (result === 'port-busy') {
315
+ await settle('port-busy');
316
+ say('FloLess’s connection is unavailable. Another program may be using it. Close that program if you can, then launch FloLess again.');
317
+ process.exitCode = 1;
318
+ return 'port-busy';
319
+ }
320
+ if (attempt.exited) {
267
321
  exitedAt ??= now();
268
322
  if (now() - exitedAt >= EXIT_GRACE_MS) {
269
323
  await settle('stopped');
@@ -284,13 +338,14 @@ export async function startAndOpen({
284
338
  }
285
339
  }
286
340
 
287
- export async function cmdOpen() {
341
+ export async function cmdOpen({ marker = consumePostUpdateMarker, healthy = ping, ensure = ensureServerUp,
342
+ startOpen = startAndOpen, say = log, open = openBrowser } = {}) {
288
343
  // A post-self-update relaunch must start the server but NOT open a second browser tab —
289
344
  // Velopack relaunches FlolessApp.exe bare (→ this `open` action), while the user's existing
290
345
  // tab is still alive and reconnects via its 5s health poll (#37). Consume the one-shot
291
346
  // marker the updater dropped before the Update.exe handoff; if present, behave like `start`.
292
- const postUpdate = consumePostUpdateMarker();
293
- let serving = await ping();
347
+ const postUpdate = marker();
348
+ let serving = await healthy();
294
349
  if (serving) {
295
350
  // Something is already serving the port. If it's a DIFFERENT, OLDER floless.app build than
296
351
  // this one, take it over ("newest wins") so the version the user just launched is the one
@@ -309,13 +364,13 @@ export async function cmdOpen() {
309
364
  }
310
365
  }
311
366
  if (postUpdate) {
312
- if (!serving) await ensureServerUp();
313
- log('post-update relaunch — server up; the existing tab reconnects via its health poll (no new tab)');
367
+ if (!serving && !(await ensure())) { process.exitCode = 1; return; }
368
+ say('post-update relaunch — server up; the existing tab reconnects via its health poll (no new tab)');
314
369
  return;
315
370
  }
316
- if (!serving) { await startAndOpen(); return; }
371
+ if (!serving) { await startOpen(); return; }
317
372
  log(`opening ${BROWSER_URL}`);
318
- openBrowser(BROWSER_URL);
373
+ open(BROWSER_URL);
319
374
  }
320
375
 
321
376
  // `start` (the in-tab recovery trigger, fired as floless://start from a tab whose
@@ -324,11 +379,11 @@ export async function cmdOpen() {
324
379
  // counterpart to `open`, and the action autostart-on-login uses too.
325
380
  export async function cmdStart() {
326
381
  if (await ping()) { log('already running'); return; }
327
- await ensureServerUp();
382
+ if (!(await ensureServerUp())) process.exitCode = 1;
328
383
  }
329
384
 
330
385
  // `supervise` — the login-autostart entry: KEEP the local server alive. Starts it if
331
- // down, then polls every few seconds and respawns it within ~5s whenever it dies.
386
+ // down, then polls every few seconds. Failed startup retries retain a ~33s minimum cadence.
332
387
  // This is the ROBUST recovery path: pure local process management — no browser, no
333
388
  // floless:// protocol, no admin. (The in-tab Restart button depends on the browser
334
389
  // honoring the floless:// handler, which locked-down / corporate-managed browsers can
@@ -345,14 +400,16 @@ const SUPERVISE_POLL_MS = 3000;
345
400
  // set it from outside (a user-set value would short-circuit the detach step).
346
401
  const SUPERVISE_RESPAWN_ENV = 'FLOLESS_SUPERVISE_RESPAWNED';
347
402
 
348
- export async function cmdSupervise() {
403
+ export async function cmdSupervise({ start = startServerDetached, healthy = ping, listening = portListening,
404
+ now = Date.now, sleep = (ms) => new Promise((r) => setTimeout(r, ms)), say = log,
405
+ packaged = isPackagedDistributionExe() } = {}) {
349
406
  // Only the packaged SEA exe (autostart-wired by the Velopack hook) takes the
350
407
  // detached-respawn path — its argv is `<exe> --supervise`, which the dispatcher in
351
408
  // main.ts handles. The npm channel has process.execPath = node.exe and respawning
352
409
  // `node --supervise` would fail with `bad option: --supervise`; autostart is also
353
410
  // never wired in that channel, so a foreground loop with visible logs is the right
354
411
  // dev behavior. Detect the SEA channel by the exe basename (`FlolessApp.exe`).
355
- const isSeaChannel = isPackagedDistributionExe();
412
+ const isSeaChannel = packaged;
356
413
  if (isSeaChannel && !process.env[SUPERVISE_RESPAWN_ENV]) {
357
414
  // First entry on the packaged SEA: re-spawn ourselves detached, then exit, so the
358
415
  // logon Scheduled Task that launched us COMPLETES immediately (returns to "Ready")
@@ -375,21 +432,25 @@ export async function cmdSupervise() {
375
432
  log('supervisor re-spawned detached');
376
433
  return;
377
434
  }
378
- log('supervisor up — keeping the server alive');
435
+ say('supervisor up — keeping the server alive');
436
+ let lastStartAt = null;
437
+ const beginAttempt = () => createServerAttempt({ healthy, listening, now, say, start: () => {
438
+ lastStartAt = now();
439
+ say('server not responding — (re)starting');
440
+ return start();
441
+ } });
442
+ let attempt = beginAttempt();
379
443
  for (;;) {
380
- if (!(await ping())) {
381
- log('server not responding — (re)starting');
382
- // Spawn + BLOCK on waitHealthy (≤30s) before the next iteration: this serializes
383
- // the loop so one outage = one spawn (no self-race), and a persistently-failing
384
- // server retries on a ~33s cadence rather than churning. We deliberately do NOT
385
- // route through ensureServerUp() — it process.exit(1)s on failure, which would
386
- // kill the supervisor itself. If a spawn ever races another launcher (e.g. a
387
- // manual floless://start), the loser's app.listen() throws EADDRINUSE and that
388
- // process exits cleanly — never two live servers.
389
- startServerDetached();
390
- log((await waitHealthy()) ? 'server up' : 'server not healthy yet — will retry');
391
- }
392
- await new Promise((r) => setTimeout(r, SUPERVISE_POLL_MS));
444
+ const result = await waitForServerAttempt(attempt, { now, sleep });
445
+ if (result === 'stopped') {
446
+ say('the server stopped before it was ready — will retry');
447
+ if (lastStartAt !== null) await sleep(Math.max(0, 30_000 - (now() - lastStartAt)));
448
+ attempt = beginAttempt();
449
+ } else if (result === 'port-busy') {
450
+ say('FloLess’s connection is unavailable. Another program may be using it; waiting for it to close.');
451
+ attempt = beginAttempt();
452
+ } else if (result === 'waiting') say('server not healthy yet — will keep waiting');
453
+ await sleep(SUPERVISE_POLL_MS);
393
454
  }
394
455
  }
395
456
 
@@ -586,9 +647,7 @@ function apiJson(path, method = 'GET') {
586
647
  // triggers the browser handoff, and polls the gate state until it goes valid.
587
648
  export async function cmdLogin() {
588
649
  if (!(await ping())) {
589
- log('starting server…');
590
- startServerDetached();
591
- if (!(await waitHealthy())) { log('server did not start — try "npm run dev" to see errors'); process.exit(1); }
650
+ if (!(await ensureServerUp())) { process.exitCode = 1; return; }
592
651
  }
593
652
  const started = await apiJson('/api/license/start', 'POST').catch(() => ({}));
594
653
  log(`opening sign-in in your browser${started.signInUrl ? `: ${started.signInUrl}` : ''}`);
@@ -768,8 +827,7 @@ export async function cmdActionsCli(argv) {
768
827
  ensureServer: async () => {
769
828
  if (await ping()) return true;
770
829
  say('Starting FloLess…');
771
- startServerDetached();
772
- return waitHealthy();
830
+ return ensureServerUp({ say });
773
831
  },
774
832
  out: (text) => write(process.stdout, text),
775
833
  err: say,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.158.0",
3
+ "version": "0.159.0",
4
4
  "type": "module",
5
5
  "description": "Thin localhost host for floless.app — serves web/ and shells the aware CLI. No engine, no LLM.",
6
6
  "bin": {
@@ -88,14 +88,18 @@
88
88
  },
89
89
  "devDependencies": {
90
90
  "@fastify/static": "^8.0.0",
91
+ "@gltf-transform/core": "4.5.1",
92
+ "@gltf-transform/extensions": "4.5.1",
91
93
  "@types/node": "^22.0.0",
92
94
  "@types/yauzl": "3.4.0",
93
95
  "ajv": "8.17.1",
94
96
  "chokidar": "^4.0.0",
97
+ "earcut": "3.2.4",
95
98
  "esbuild": "^0.28.0",
96
99
  "fastify": "^5.0.0",
97
100
  "fflate": "^0.8.3",
98
101
  "linkedom": "^0.18.12",
102
+ "meshoptimizer": "1.3.0",
99
103
  "pino-pretty": "^13.0.0",
100
104
  "postject": "^1.0.0-alpha.6",
101
105
  "rcedit": "^5.0.2",