@floless/app 0.157.0 → 0.158.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.
@@ -0,0 +1,181 @@
1
+ // The "FloLess is starting" page the launcher opens when the server is slow to answer.
2
+ // Dependency-free (Node built-ins only), like launch.mjs, which ships it.
3
+ //
4
+ // It is a local file, because nothing is listening on the app's port yet. A file:// page cannot
5
+ // fetch another file, but it can load one as a script, so the launcher rewrites `status.js` and the
6
+ // page re-loads it every second: `ready` sends the tab to the app, `stopped` / `gave-up` show what
7
+ // happened and what to do next. The page never reads the log and never shows an error text.
8
+ import { mkdirSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
9
+ import { join } from 'node:path';
10
+ import { pathToFileURL } from 'node:url';
11
+
12
+ export const STARTING_STATES = ['starting', 'slow', 'ready', 'stopped', 'gave-up'];
13
+
14
+ const RETRY_URL = 'floless://open';
15
+ const DOWNLOAD_URL = 'https://floless.io/app';
16
+
17
+ // Plain-English copy per state (design review, 2026-10-21). Buttons only where the person has a next
18
+ // step: while it is still starting, a retry would only begin a second launch.
19
+ export const STARTING_COPY = {
20
+ starting: { title: 'Starting FloLess', headline: 'Starting FloLess…',
21
+ body: 'FloLess is getting ready. This window will open the app by itself.', actions: [] },
22
+ slow: { title: 'Still starting FloLess', headline: 'Still starting. Thanks for waiting.',
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
+ ready: { title: 'Opening FloLess', headline: 'FloLess is ready', body: 'Opening now…', actions: [] },
25
+ stopped: { title: 'FloLess stopped', headline: 'FloLess stopped before it finished starting',
26
+ 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
+ actions: ['retry', 'download'] },
28
+ 'gave-up': { title: 'FloLess is taking longer than expected', headline: 'FloLess is taking longer than expected',
29
+ body: 'This window stopped waiting, but FloLess may still be starting in the background. Try opening it now, or start it again.',
30
+ actions: ['open', 'retry', 'download'] },
31
+ };
32
+
33
+ const esc = (text) => String(text).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
34
+
35
+ export function startingPageHtml(appUrl) {
36
+ const first = STARTING_COPY.starting;
37
+ const config = JSON.stringify({ appUrl, retryUrl: RETRY_URL, downloadUrl: DOWNLOAD_URL, copy: STARTING_COPY })
38
+ .replace(/</g, '\\u003c');
39
+ return `<!DOCTYPE html>
40
+ <html lang="en"><head><meta charset="UTF-8">
41
+ <meta name="viewport" content="width=device-width, initial-scale=1">
42
+ <meta name="color-scheme" content="dark light">
43
+ <title>${esc(first.title)}</title>
44
+ <style>
45
+ :root{--bg:#020817;--card:#0f141c;--fg:#f8fafc;--muted:#94a3b8;--border:#1c2535;--primary:#4a9eff;--on-primary:#020817}
46
+ @media (prefers-color-scheme: light){:root{--bg:#f8fafc;--card:#ffffff;--fg:#0f172a;--muted:#475569;--border:#e2e8f0;--primary:#2563eb;--on-primary:#ffffff}}
47
+ *{margin:0;padding:0;box-sizing:border-box}
48
+ body{font-family:-apple-system,'Segoe UI',Roboto,sans-serif;background:var(--bg);color:var(--fg);
49
+ min-height:100vh;display:flex;align-items:center;justify-content:center;padding:16px}
50
+ .card{text-align:center;max-width:440px;width:100%;padding:2.5rem 2rem;background:var(--card);
51
+ border:1px solid var(--border);border-radius:14px}
52
+ .mark{width:84px;height:84px;margin:0 auto 1.25rem;border-radius:22px;
53
+ background:linear-gradient(135deg,#4a9eff,#2c5f9e);display:flex;align-items:center;justify-content:center}
54
+ .mark svg{width:46px;height:46px}
55
+ h1{font-size:1.3rem;font-weight:700;margin-bottom:.5rem}
56
+ p{color:var(--muted);font-size:.92rem;line-height:1.55}
57
+ .bar{position:relative;height:3px;margin:1.6rem auto 0;max-width:260px;border-radius:3px;background:var(--border);overflow:hidden}
58
+ .bar::after{content:"";position:absolute;top:0;left:-40%;width:40%;height:100%;border-radius:3px;
59
+ background:var(--primary);animation:slide 1.6s linear infinite}
60
+ @keyframes slide{to{left:100%}}
61
+ @media (prefers-reduced-motion: reduce){.bar::after{animation:none;left:0;width:100%;opacity:.4}}
62
+ .bar[hidden]{display:none}
63
+ .actions{display:flex;flex-direction:column;gap:.6rem;margin-top:1.6rem}
64
+ .actions[hidden]{display:none}
65
+ .actions a{display:flex;align-items:center;justify-content:center;min-height:44px;padding:.6rem 1rem;border-radius:9px;
66
+ text-decoration:none;font-weight:600;font-size:.95rem;border:1px solid var(--border);color:var(--fg);background:transparent}
67
+ .actions a.primary{background:var(--primary);border-color:var(--primary);color:var(--on-primary)}
68
+ .actions a:hover{border-color:var(--primary)}
69
+ .actions a:focus-visible{outline:2px solid var(--primary);outline-offset:2px}
70
+ </style></head>
71
+ <body>
72
+ <main class="card">
73
+ <div class="mark" aria-hidden="true">
74
+ <svg viewBox="0 0 192 181" fill="none" xmlns="http://www.w3.org/2000/svg">
75
+ <path d="M93.4818 26.2302L32.3762 26.2313C25.5914 26.2314 19.347 32.217 15.0271 38.0025C11.2275 43.0912 8.72093 49.9322 8.72093 56.5314C8.72093 64.7036 10.9644 71.8345 15.0271 77.7851C19.2332 83.9459 26.1884 90.7551 32.3762 90.7551H159.101C165.715 90.7551 171.878 93.8886 176.177 98.8111C180.654 103.937 183.14 111.953 183.14 118.757C183.14 126.308 181.52 131.542 177.974 137.069C174.152 143.027 159.887 151.23 159.887 151.23" stroke="#fff" stroke-width="11.6719" stroke-linecap="round"/>
76
+ <path d="M90.1163 8.72095L106.704 26.7965" stroke="#fff" stroke-width="11.6712" stroke-linecap="round"/>
77
+ <path d="M90.1163 44.9346L106.704 26.859" stroke="#fff" stroke-width="11.6712" stroke-linecap="round"/>
78
+ <path d="M78.5336 136.746L95.1213 154.822" stroke="#fff" stroke-width="11.6712" stroke-linecap="round"/>
79
+ <path d="M78.5336 172.96L95.1213 154.885" stroke="#fff" stroke-width="11.6712" stroke-linecap="round"/>
80
+ <path d="M61.4378 154.466H82.2457" stroke="#fff" stroke-width="11.6712" stroke-linecap="square"/>
81
+ <circle cx="33.4" cy="156" r="18.9" stroke="#fff" stroke-width="8.72"/>
82
+ <circle cx="138.1" cy="156" r="18.9" stroke="#fff" stroke-width="8.72"/>
83
+ <circle cx="149.7" cy="24.7" r="18.9" stroke="#fff" stroke-width="8.72"/>
84
+ </svg>
85
+ </div>
86
+ <div id="status" role="status" aria-live="polite" aria-atomic="true">
87
+ <h1 id="headline">${esc(first.headline)}</h1>
88
+ <p id="body">${esc(first.body)}</p>
89
+ </div>
90
+ <div id="bar" class="bar" aria-hidden="true"></div>
91
+ <div id="actions" class="actions" hidden></div>
92
+ </main>
93
+ <script>
94
+ (function () {
95
+ var config = ${config};
96
+ var state = 'starting';
97
+ var labels = { open: 'Open FloLess', retry: 'Try again', download: 'Download FloLess' };
98
+ var hrefs = { open: config.appUrl, retry: config.retryUrl, download: config.downloadUrl };
99
+ function show(next) {
100
+ var copy = config.copy[next];
101
+ if (!copy || next === state) return;
102
+ state = next;
103
+ if (next === 'ready') { location.replace(config.appUrl); }
104
+ document.title = copy.title;
105
+ document.getElementById('headline').textContent = copy.headline;
106
+ document.getElementById('body').textContent = copy.body;
107
+ document.getElementById('bar').hidden = !(next === 'starting' || next === 'slow' || next === 'ready');
108
+ var actions = document.getElementById('actions');
109
+ actions.textContent = '';
110
+ copy.actions.forEach(function (name, i) {
111
+ var link = document.createElement('a');
112
+ link.href = hrefs[name];
113
+ link.textContent = labels[name];
114
+ if (i === 0) link.className = 'primary';
115
+ if (name === 'download') { link.target = '_blank'; link.rel = 'noopener'; }
116
+ actions.appendChild(link);
117
+ });
118
+ actions.hidden = copy.actions.length === 0;
119
+ if (copy.actions.length) actions.firstChild.focus();
120
+ }
121
+ window.flolessStarting = function (update) { if (update && update.state) show(update.state); };
122
+ var settled = { ready: true, stopped: true, 'gave-up': true };
123
+ function poll() {
124
+ if (settled[state]) return;
125
+ var tag = document.createElement('script');
126
+ tag.src = 'status.js?t=' + Date.now();
127
+ tag.onload = tag.onerror = function () { tag.remove(); setTimeout(poll, 1000); };
128
+ document.head.appendChild(tag);
129
+ }
130
+ poll();
131
+ })();
132
+ </script>
133
+ </body></html>
134
+ `;
135
+ }
136
+
137
+ export function statusScript(state) {
138
+ if (!STARTING_STATES.includes(state)) throw new Error(`unknown starting-page state: ${state}`);
139
+ return `window.flolessStarting && window.flolessStarting(${JSON.stringify({ state })});\n`;
140
+ }
141
+
142
+ // One folder per launch (port + launcher pid): two slow launches, say on different ports, must never
143
+ // share a status file, or the first server to answer would send BOTH tabs to an app that is not up.
144
+ // Folders from earlier launches are removed once they are a day old; a launch waits at most 15 minutes.
145
+ export const STALE_PAGE_MS = 24 * 60 * 60_000;
146
+ export function startingPageDir(base, port, pid, now = Date.now()) {
147
+ try {
148
+ for (const entry of readdirSync(base, { withFileTypes: true })) {
149
+ if (!entry.isDirectory()) continue;
150
+ const path = join(base, entry.name);
151
+ try { if (now - statSync(path).mtimeMs > STALE_PAGE_MS) rmSync(path, { recursive: true, force: true }); }
152
+ catch { /* in use or already gone: leave it */ }
153
+ }
154
+ } catch { /* no folder yet */ }
155
+ return join(base, `${port}-${pid}`);
156
+ }
157
+
158
+ const pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
159
+
160
+ // Write the page and its first status into `dir`; returns where it is and a way to move it on. Each
161
+ // status is written whole and renamed into place, so the page never loads half a file. Windows can
162
+ // refuse the rename while the browser is reading the file, so a write is retried for about two
163
+ // seconds; `status` returns whether it landed and never throws, since it must never stop the launcher.
164
+ export function writeStartingPage(dir, appUrl, { retries = 20, retryMs = 100, write = writeFileSync, rename = renameSync } = {}) {
165
+ mkdirSync(dir, { recursive: true });
166
+ const path = join(dir, 'index.html');
167
+ const statusPath = join(dir, 'status.js');
168
+ const status = (state) => {
169
+ const text = statusScript(state);
170
+ const temp = `${statusPath}.${process.pid}.tmp`;
171
+ for (let attempt = 0; attempt <= retries; attempt += 1) {
172
+ try { write(temp, text); rename(temp, statusPath); return true; }
173
+ catch { if (attempt < retries) pause(retryMs); }
174
+ }
175
+ try { rmSync(temp, { force: true }); } catch { /* best effort */ }
176
+ return false;
177
+ };
178
+ writeFileSync(path, startingPageHtml(appUrl));
179
+ status('starting');
180
+ return { path, url: pathToFileURL(path).href, status };
181
+ }
package/launch.mjs CHANGED
@@ -15,7 +15,8 @@ import { distributionProfile } from './distribution-profile-active.mjs';
15
15
  import { existsSync, readFileSync } from 'node:fs';
16
16
  import http from 'node:http';
17
17
  import { createInterface } from 'node:readline';
18
- import { rotateLog, openLogFd } from './log.mjs';
18
+ import { rotateLog, openLogFd, logDir } from './log.mjs';
19
+ import { startingPageDir, writeStartingPage } from './launch-starting-page.mjs';
19
20
  import { supervisorPidsToKill, teardownDecision, awareIsPresent, RUN_KEY, RUN_VALUE, PROTOCOL_KEY } from './teardown.mjs';
20
21
  import { resolveRealInstallExe } from './install-path.mjs';
21
22
  import { consumePostUpdateMarker } from './post-update-marker.mjs';
@@ -160,6 +161,7 @@ function startServerDetached() {
160
161
  shell,
161
162
  });
162
163
  child.unref();
164
+ return child;
163
165
  }
164
166
 
165
167
  function openBrowser(url) {
@@ -202,13 +204,94 @@ async function ensureServerUp() {
202
204
  log('server up');
203
205
  }
204
206
 
207
+ // How `open` waits for a server it has just started. A normal start answers within a few seconds and
208
+ // the app opens directly. A slow one — a large install has taken minutes — used to hit the 30 s
209
+ // limit above, and the launcher exited with no window at all: the user clicked Launch and saw
210
+ // nothing. Now a local "FloLess is starting" page opens instead, the launcher keeps waiting while the
211
+ // server process is alive, and the page turns into the app the moment it answers — or says plainly
212
+ // that the server stopped, with a Try again. Exported with its dependencies so a test can drive it on
213
+ // a fake clock.
214
+ export const QUICK_START_MS = 3000;
215
+ export const SLOW_START_MS = 60_000;
216
+ export const GIVE_UP_MS = 15 * 60_000;
217
+ // After the server process exits, how long it may still answer before the page says it stopped: a
218
+ // second launch that loses the port to a server already starting (the login supervisor's, say) exits
219
+ // once that one listens, and the person should get the running app, not "FloLess stopped".
220
+ export const EXIT_GRACE_MS = 10_000;
221
+
222
+ export async function startAndOpen({
223
+ start = startServerDetached,
224
+ healthy = ping,
225
+ open = openBrowser,
226
+ page = () => writeStartingPage(startingPageDir(join(dirname(logDir()), 'starting'), PORT, process.pid), BROWSER_URL),
227
+ now = Date.now,
228
+ sleep = (ms) => new Promise((r) => setTimeout(r, ms)),
229
+ say = log,
230
+ } = {}) {
231
+ say('starting server…');
232
+ const child = start();
233
+ let exited = child?.exitCode != null;
234
+ child?.once?.('exit', () => { exited = true; });
235
+ const startedAt = now();
236
+ 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;
239
+ await sleep(500);
240
+ }
241
+ // The page is a convenience; a data folder it cannot be written to must not cost the person the app.
242
+ let progress = null;
243
+ try { progress = page(); }
244
+ catch (error) { say(`could not write the starting page (${error?.message ?? error}); will open FloLess when it is ready`); }
245
+ if (progress) {
246
+ say(`server still starting — opened a page that switches to FloLess when it is ready (${progress.path})`);
247
+ open(progress.url);
248
+ }
249
+ // A final state the page never receives would leave it spinning, so it is retried for a few seconds.
250
+ // Returns whether the page got it.
251
+ const settle = async (state) => {
252
+ if (!progress) return false;
253
+ for (let i = 0; i < 5; i += 1) { if (progress.status(state) !== false) return true; await sleep(1000); }
254
+ say(`could not tell the starting page "${state}"`);
255
+ return false;
256
+ };
257
+ let slow = false;
258
+ let exitedAt = null;
259
+ for (;;) {
260
+ if (await healthy()) {
261
+ // No page, or a page that cannot be told: open the app itself rather than leave it spinning.
262
+ if (!(await settle('ready'))) open(BROWSER_URL);
263
+ say(`server up after ${Math.round((now() - startedAt) / 1000)}s`);
264
+ return 'ready';
265
+ }
266
+ if (exited) {
267
+ exitedAt ??= now();
268
+ if (now() - exitedAt >= EXIT_GRACE_MS) {
269
+ await settle('stopped');
270
+ say('the server stopped before it was ready');
271
+ process.exitCode = 1;
272
+ return 'stopped';
273
+ }
274
+ }
275
+ const elapsed = now() - startedAt;
276
+ if (elapsed >= GIVE_UP_MS) {
277
+ await settle('gave-up');
278
+ say(`server not ready after ${Math.round(elapsed / 60_000)} min — stopped waiting; it may still finish starting`);
279
+ process.exitCode = 1;
280
+ return 'gave-up';
281
+ }
282
+ if (!slow && elapsed >= SLOW_START_MS) { slow = true; progress?.status('slow'); }
283
+ await sleep(1000);
284
+ }
285
+ }
286
+
205
287
  export async function cmdOpen() {
206
288
  // A post-self-update relaunch must start the server but NOT open a second browser tab —
207
289
  // Velopack relaunches FlolessApp.exe bare (→ this `open` action), while the user's existing
208
290
  // tab is still alive and reconnects via its 5s health poll (#37). Consume the one-shot
209
291
  // marker the updater dropped before the Update.exe handoff; if present, behave like `start`.
210
292
  const postUpdate = consumePostUpdateMarker();
211
- if (await ping()) {
293
+ let serving = await ping();
294
+ if (serving) {
212
295
  // Something is already serving the port. If it's a DIFFERENT, OLDER floless.app build than
213
296
  // this one, take it over ("newest wins") so the version the user just launched is the one
214
297
  // they get — instead of silently opening the stale instance (e.g. a leftover dev server).
@@ -220,17 +303,17 @@ export async function cmdOpen() {
220
303
  + `this build is v${_selfVersion} (${_selfChannel ?? 'unknown'}) — taking over`);
221
304
  stopServer();
222
305
  await new Promise((r) => setTimeout(r, 500)); // let the OS release the port
223
- await ensureServerUp();
306
+ serving = false;
224
307
  } else {
225
308
  log(`already running${running.version ? ` (v${running.version}${running.channel ? `, ${running.channel}` : ''})` : ''}`);
226
309
  }
227
- } else {
228
- await ensureServerUp();
229
310
  }
230
311
  if (postUpdate) {
312
+ if (!serving) await ensureServerUp();
231
313
  log('post-update relaunch — server up; the existing tab reconnects via its health poll (no new tab)');
232
314
  return;
233
315
  }
316
+ if (!serving) { await startAndOpen(); return; }
234
317
  log(`opening ${BROWSER_URL}`);
235
318
  openBrowser(BROWSER_URL);
236
319
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.157.0",
3
+ "version": "0.158.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": {
@@ -71,6 +71,8 @@
71
71
  "verify:user-copy-impact": "node build/verify-user-copy-impact.mjs",
72
72
  "verify:user-copy": "node build/verify-user-copy.mjs",
73
73
  "verify:review-rounds": "node build/verify-review-rounds.mjs",
74
+ "pr-body-check": "node build/pr-body-check.mjs",
75
+ "pre-pr": "node build/pre-pr.mjs",
74
76
  "verify:instructor-coverage": "node build/verify-instructor-coverage.mjs",
75
77
  "verify:instructor-steps": "node build/verify-instructor-steps.mjs",
76
78
  "verify:no-echo": "node build/verify-no-echo.mjs",
@@ -1,50 +0,0 @@
1
- /**
2
- * A report that carries files (`report_folder`, #2262 slice 3c) refers to them as `assets/…`. Those resolve only inside
3
- * the report's Page version (its isolated /pages-content frame); in the run's HTML Viewer — a srcdoc frame on FloLess's
4
- * own origin — they would ask FloLess for files it does not serve, show broken pictures and log failed requests. So the
5
- * viewer shows a copy in which every reference to the report's own files is made inert, with a short note pointing to
6
- * the Page version, where the files are.
7
- *
8
- * The copy is PARSED, never run (DOMParser), and only references to `assets/…` change: src/href/poster/data/srcset,
9
- * CSS url(…) in <style> and style="…", and any @import that would load from FloLess's origin. A <base> is dropped, since
10
- * it would turn ordinary relative names into requests to FloLess. Everything else is kept as the run made it.
11
- *
12
- * Loaded as a classic script before aware.js; tested by server/report-files-web.test.ts with linkedom's DOMParser.
13
- */
14
- (function (root) {
15
- var ASSET = /^\s*(?:\.\/|\/)?assets\//i;
16
- /** An @import that stays outside FloLess's origin (https or data) can't ask FloLess for anything; others are dropped. */
17
- function cssClean(css) {
18
- return String(css)
19
- .replace(/@import[^;]*;?/gi, function (rule) { return /^@import\s+(?:url\(\s*)?['"]?\s*(?:https:|data:)/i.test(rule) ? rule : ''; })
20
- .replace(/url\(\s*(['"]?)\s*(?:\.\/|\/)?assets\/[^)]*\)/gi, 'url("data:,")');
21
- }
22
- /** The report with every reference to its own files made inert, and `note` (if any) shown first. */
23
- function neutralize(html, Parser, note) {
24
- var P = Parser || root.DOMParser;
25
- var doc = new P().parseFromString(String(html || ''), 'text/html');
26
- doc.querySelectorAll('base').forEach(function (b) { b.remove(); });
27
- doc.querySelectorAll('*').forEach(function (el) {
28
- ['src', 'href', 'poster', 'data', 'xlink:href'].forEach(function (name) {
29
- var v = el.getAttribute(name);
30
- if (v !== null && ASSET.test(v)) { el.setAttribute('data-floless-' + name.replace(':', '-'), v); el.removeAttribute(name); }
31
- });
32
- var srcset = el.getAttribute('srcset');
33
- if (srcset !== null && srcset.split(',').some(function (c) { return ASSET.test(c); })) {
34
- el.setAttribute('data-floless-srcset', srcset); el.removeAttribute('srcset');
35
- }
36
- var style = el.getAttribute('style');
37
- if (style && /assets\/|@import/i.test(style)) el.setAttribute('style', cssClean(style));
38
- if (String(el.tagName).toUpperCase() === 'STYLE') el.textContent = cssClean(el.textContent);
39
- });
40
- if (note && doc.body) {
41
- var p = doc.createElement('p');
42
- p.setAttribute('data-floless-files-note', '');
43
- p.setAttribute('style', 'margin:0;padding:.6rem 1rem;font:13px/1.5 system-ui,sans-serif;background:#111c33;color:#e2e8f0;border-left:3px solid #fbbf24');
44
- p.textContent = note;
45
- doc.body.insertBefore(p, doc.body.firstChild);
46
- }
47
- return '<!doctype html>' + doc.documentElement.outerHTML;
48
- }
49
- root.FlolessReportFiles = { neutralize: neutralize };
50
- })(typeof window !== 'undefined' ? window : globalThis);