@floless/app 0.157.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.
- package/cli-actions.mjs +7 -0
- package/dist/floless-server.cjs +188306 -155284
- package/dist/schemas/drawing-check.profile.v1.schema.json +33 -1
- package/dist/skills/floless-app-actions/SKILL.md +26 -5
- package/dist/skills/floless-app-bridge/SKILL.md +5 -3
- package/dist/skills/floless-app-knowledge/SKILL.md +14 -1
- package/dist/skills/floless-app-knowledge/references/schema.md +4 -1
- package/dist/skills/floless-app-onboarding/SKILL.md +67 -4
- package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +7 -4
- package/dist/skills/floless-app-queue/SKILL.md +3 -1
- package/dist/skills/floless-app-steel-model/SKILL.md +41 -1
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +71 -1
- package/dist/skills/floless-app-workflows/SKILL.md +6 -3
- package/dist/web/agents.js +12 -5
- package/dist/web/app.css +229 -27
- package/dist/web/app.js +6 -0
- package/dist/web/aware.js +275 -64
- package/dist/web/chat.css +60 -22
- package/dist/web/chat.js +396 -59
- package/dist/web/commands-shell.js +546 -11
- package/dist/web/commands-steel.js +1 -0
- package/dist/web/drawing-check-editor.html +10 -0
- package/dist/web/drawing-check-editor.js +44 -0
- package/dist/web/guide.js +4 -2
- package/dist/web/index.html +66 -12
- package/dist/web/instructor.js +21 -9
- package/dist/web/kb-categories.js +351 -0
- package/dist/web/kb-graph-worker.js +73 -0
- package/dist/web/pages.js +185 -19
- package/dist/web/project-access.js +67 -8
- package/dist/web/project-modules.js +474 -0
- package/dist/web/project-workflows.js +274 -0
- package/dist/web/run-page-view.js +353 -0
- package/dist/web/steel-3d-core.js +46 -0
- package/dist/web/steel-3d-view.js +8 -38
- package/dist/web/steel-editor.html +225 -43
- package/dist/web/tab-signal.js +323 -0
- package/dist/web/terminal-requests.js +48 -7
- package/dist/web/workspace-root-recovery.js +119 -0
- package/dist/web/workspaces.js +1597 -220
- package/launch-starting-page.mjs +184 -0
- package/launch.mjs +214 -73
- package/package.json +7 -1
- package/dist/web/report-files.js +0 -50
|
@@ -0,0 +1,184 @@
|
|
|
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', 'port-busy'];
|
|
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
|
+
'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'] },
|
|
28
|
+
stopped: { title: 'FloLess stopped', headline: 'FloLess stopped before it finished starting',
|
|
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.',
|
|
30
|
+
actions: ['retry', 'download'] },
|
|
31
|
+
'gave-up': { title: 'FloLess is taking longer than expected', headline: 'FloLess is taking longer than expected',
|
|
32
|
+
body: 'This window stopped waiting, but FloLess may still be starting in the background. Try opening it now, or start it again.',
|
|
33
|
+
actions: ['open', 'retry', 'download'] },
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const esc = (text) => String(text).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
37
|
+
|
|
38
|
+
export function startingPageHtml(appUrl) {
|
|
39
|
+
const first = STARTING_COPY.starting;
|
|
40
|
+
const config = JSON.stringify({ appUrl, retryUrl: RETRY_URL, downloadUrl: DOWNLOAD_URL, copy: STARTING_COPY })
|
|
41
|
+
.replace(/</g, '\\u003c');
|
|
42
|
+
return `<!DOCTYPE html>
|
|
43
|
+
<html lang="en"><head><meta charset="UTF-8">
|
|
44
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
45
|
+
<meta name="color-scheme" content="dark light">
|
|
46
|
+
<title>${esc(first.title)}</title>
|
|
47
|
+
<style>
|
|
48
|
+
:root{--bg:#020817;--card:#0f141c;--fg:#f8fafc;--muted:#94a3b8;--border:#1c2535;--primary:#4a9eff;--on-primary:#020817}
|
|
49
|
+
@media (prefers-color-scheme: light){:root{--bg:#f8fafc;--card:#ffffff;--fg:#0f172a;--muted:#475569;--border:#e2e8f0;--primary:#2563eb;--on-primary:#ffffff}}
|
|
50
|
+
*{margin:0;padding:0;box-sizing:border-box}
|
|
51
|
+
body{font-family:-apple-system,'Segoe UI',Roboto,sans-serif;background:var(--bg);color:var(--fg);
|
|
52
|
+
min-height:100vh;display:flex;align-items:center;justify-content:center;padding:16px}
|
|
53
|
+
.card{text-align:center;max-width:440px;width:100%;padding:2.5rem 2rem;background:var(--card);
|
|
54
|
+
border:1px solid var(--border);border-radius:14px}
|
|
55
|
+
.mark{width:84px;height:84px;margin:0 auto 1.25rem;border-radius:22px;
|
|
56
|
+
background:linear-gradient(135deg,#4a9eff,#2c5f9e);display:flex;align-items:center;justify-content:center}
|
|
57
|
+
.mark svg{width:46px;height:46px}
|
|
58
|
+
h1{font-size:1.3rem;font-weight:700;margin-bottom:.5rem}
|
|
59
|
+
p{color:var(--muted);font-size:.92rem;line-height:1.55}
|
|
60
|
+
.bar{position:relative;height:3px;margin:1.6rem auto 0;max-width:260px;border-radius:3px;background:var(--border);overflow:hidden}
|
|
61
|
+
.bar::after{content:"";position:absolute;top:0;left:-40%;width:40%;height:100%;border-radius:3px;
|
|
62
|
+
background:var(--primary);animation:slide 1.6s linear infinite}
|
|
63
|
+
@keyframes slide{to{left:100%}}
|
|
64
|
+
@media (prefers-reduced-motion: reduce){.bar::after{animation:none;left:0;width:100%;opacity:.4}}
|
|
65
|
+
.bar[hidden]{display:none}
|
|
66
|
+
.actions{display:flex;flex-direction:column;gap:.6rem;margin-top:1.6rem}
|
|
67
|
+
.actions[hidden]{display:none}
|
|
68
|
+
.actions a{display:flex;align-items:center;justify-content:center;min-height:44px;padding:.6rem 1rem;border-radius:9px;
|
|
69
|
+
text-decoration:none;font-weight:600;font-size:.95rem;border:1px solid var(--border);color:var(--fg);background:transparent}
|
|
70
|
+
.actions a.primary{background:var(--primary);border-color:var(--primary);color:var(--on-primary)}
|
|
71
|
+
.actions a:hover{border-color:var(--primary)}
|
|
72
|
+
.actions a:focus-visible{outline:2px solid var(--primary);outline-offset:2px}
|
|
73
|
+
</style></head>
|
|
74
|
+
<body>
|
|
75
|
+
<main class="card">
|
|
76
|
+
<div class="mark" aria-hidden="true">
|
|
77
|
+
<svg viewBox="0 0 192 181" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
78
|
+
<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"/>
|
|
79
|
+
<path d="M90.1163 8.72095L106.704 26.7965" stroke="#fff" stroke-width="11.6712" stroke-linecap="round"/>
|
|
80
|
+
<path d="M90.1163 44.9346L106.704 26.859" stroke="#fff" stroke-width="11.6712" stroke-linecap="round"/>
|
|
81
|
+
<path d="M78.5336 136.746L95.1213 154.822" stroke="#fff" stroke-width="11.6712" stroke-linecap="round"/>
|
|
82
|
+
<path d="M78.5336 172.96L95.1213 154.885" stroke="#fff" stroke-width="11.6712" stroke-linecap="round"/>
|
|
83
|
+
<path d="M61.4378 154.466H82.2457" stroke="#fff" stroke-width="11.6712" stroke-linecap="square"/>
|
|
84
|
+
<circle cx="33.4" cy="156" r="18.9" stroke="#fff" stroke-width="8.72"/>
|
|
85
|
+
<circle cx="138.1" cy="156" r="18.9" stroke="#fff" stroke-width="8.72"/>
|
|
86
|
+
<circle cx="149.7" cy="24.7" r="18.9" stroke="#fff" stroke-width="8.72"/>
|
|
87
|
+
</svg>
|
|
88
|
+
</div>
|
|
89
|
+
<div id="status" role="status" aria-live="polite" aria-atomic="true">
|
|
90
|
+
<h1 id="headline">${esc(first.headline)}</h1>
|
|
91
|
+
<p id="body">${esc(first.body)}</p>
|
|
92
|
+
</div>
|
|
93
|
+
<div id="bar" class="bar" aria-hidden="true"></div>
|
|
94
|
+
<div id="actions" class="actions" hidden></div>
|
|
95
|
+
</main>
|
|
96
|
+
<script>
|
|
97
|
+
(function () {
|
|
98
|
+
var config = ${config};
|
|
99
|
+
var state = 'starting';
|
|
100
|
+
var labels = { open: 'Open FloLess', retry: 'Try again', download: 'Download FloLess' };
|
|
101
|
+
var hrefs = { open: config.appUrl, retry: config.retryUrl, download: config.downloadUrl };
|
|
102
|
+
function show(next) {
|
|
103
|
+
var copy = config.copy[next];
|
|
104
|
+
if (!copy || next === state) return;
|
|
105
|
+
state = next;
|
|
106
|
+
if (next === 'ready') { location.replace(config.appUrl); }
|
|
107
|
+
document.title = copy.title;
|
|
108
|
+
document.getElementById('headline').textContent = copy.headline;
|
|
109
|
+
document.getElementById('body').textContent = copy.body;
|
|
110
|
+
document.getElementById('bar').hidden = !(next === 'starting' || next === 'slow' || next === 'ready');
|
|
111
|
+
var actions = document.getElementById('actions');
|
|
112
|
+
actions.textContent = '';
|
|
113
|
+
copy.actions.forEach(function (name, i) {
|
|
114
|
+
var link = document.createElement('a');
|
|
115
|
+
link.href = hrefs[name];
|
|
116
|
+
link.textContent = labels[name];
|
|
117
|
+
if (i === 0) link.className = 'primary';
|
|
118
|
+
if (name === 'download') { link.target = '_blank'; link.rel = 'noopener'; }
|
|
119
|
+
actions.appendChild(link);
|
|
120
|
+
});
|
|
121
|
+
actions.hidden = copy.actions.length === 0;
|
|
122
|
+
if (copy.actions.length) actions.firstChild.focus();
|
|
123
|
+
}
|
|
124
|
+
window.flolessStarting = function (update) { if (update && update.state) show(update.state); };
|
|
125
|
+
var settled = { ready: true, stopped: true, 'gave-up': true, 'port-busy': true };
|
|
126
|
+
function poll() {
|
|
127
|
+
if (settled[state]) return;
|
|
128
|
+
var tag = document.createElement('script');
|
|
129
|
+
tag.src = 'status.js?t=' + Date.now();
|
|
130
|
+
tag.onload = tag.onerror = function () { tag.remove(); setTimeout(poll, 1000); };
|
|
131
|
+
document.head.appendChild(tag);
|
|
132
|
+
}
|
|
133
|
+
poll();
|
|
134
|
+
})();
|
|
135
|
+
</script>
|
|
136
|
+
</body></html>
|
|
137
|
+
`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function statusScript(state) {
|
|
141
|
+
if (!STARTING_STATES.includes(state)) throw new Error(`unknown starting-page state: ${state}`);
|
|
142
|
+
return `window.flolessStarting && window.flolessStarting(${JSON.stringify({ state })});\n`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// One folder per launch (port + launcher pid): two slow launches, say on different ports, must never
|
|
146
|
+
// share a status file, or the first server to answer would send BOTH tabs to an app that is not up.
|
|
147
|
+
// Folders from earlier launches are removed once they are a day old; a launch waits at most 15 minutes.
|
|
148
|
+
export const STALE_PAGE_MS = 24 * 60 * 60_000;
|
|
149
|
+
export function startingPageDir(base, port, pid, now = Date.now()) {
|
|
150
|
+
try {
|
|
151
|
+
for (const entry of readdirSync(base, { withFileTypes: true })) {
|
|
152
|
+
if (!entry.isDirectory()) continue;
|
|
153
|
+
const path = join(base, entry.name);
|
|
154
|
+
try { if (now - statSync(path).mtimeMs > STALE_PAGE_MS) rmSync(path, { recursive: true, force: true }); }
|
|
155
|
+
catch { /* in use or already gone: leave it */ }
|
|
156
|
+
}
|
|
157
|
+
} catch { /* no folder yet */ }
|
|
158
|
+
return join(base, `${port}-${pid}`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
162
|
+
|
|
163
|
+
// Write the page and its first status into `dir`; returns where it is and a way to move it on. Each
|
|
164
|
+
// status is written whole and renamed into place, so the page never loads half a file. Windows can
|
|
165
|
+
// refuse the rename while the browser is reading the file, so a write is retried for about two
|
|
166
|
+
// seconds; `status` returns whether it landed and never throws, since it must never stop the launcher.
|
|
167
|
+
export function writeStartingPage(dir, appUrl, { retries = 20, retryMs = 100, write = writeFileSync, rename = renameSync } = {}) {
|
|
168
|
+
mkdirSync(dir, { recursive: true });
|
|
169
|
+
const path = join(dir, 'index.html');
|
|
170
|
+
const statusPath = join(dir, 'status.js');
|
|
171
|
+
const status = (state) => {
|
|
172
|
+
const text = statusScript(state);
|
|
173
|
+
const temp = `${statusPath}.${process.pid}.tmp`;
|
|
174
|
+
for (let attempt = 0; attempt <= retries; attempt += 1) {
|
|
175
|
+
try { write(temp, text); rename(temp, statusPath); return true; }
|
|
176
|
+
catch { if (attempt < retries) pause(retryMs); }
|
|
177
|
+
}
|
|
178
|
+
try { rmSync(temp, { force: true }); } catch { /* best effort */ }
|
|
179
|
+
return false;
|
|
180
|
+
};
|
|
181
|
+
writeFileSync(path, startingPageHtml(appUrl));
|
|
182
|
+
status('starting');
|
|
183
|
+
return { path, url: pathToFileURL(path).href, status };
|
|
184
|
+
}
|
package/launch.mjs
CHANGED
|
@@ -14,8 +14,10 @@ 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
|
-
import { rotateLog, openLogFd } from './log.mjs';
|
|
19
|
+
import { rotateLog, openLogFd, logDir } from './log.mjs';
|
|
20
|
+
import { startingPageDir, writeStartingPage } from './launch-starting-page.mjs';
|
|
19
21
|
import { supervisorPidsToKill, teardownDecision, awareIsPresent, RUN_KEY, RUN_VALUE, PROTOCOL_KEY } from './teardown.mjs';
|
|
20
22
|
import { resolveRealInstallExe } from './install-path.mjs';
|
|
21
23
|
import { consumePostUpdateMarker } from './post-update-marker.mjs';
|
|
@@ -38,38 +40,91 @@ const isPackagedDistributionExe = (path = process.execPath) => basename(path ||
|
|
|
38
40
|
// logging" intent.)
|
|
39
41
|
const log = (m) => { try { process.stdout.write(`floless: ${m}\n`); } catch { /* dead stdout (GUI subsystem, no console) */ } };
|
|
40
42
|
|
|
41
|
-
//
|
|
42
|
-
function
|
|
43
|
+
// A complete, identifiable FloLess response, bounded even if a listener trickles bytes forever.
|
|
44
|
+
async function readHealth({ url = HEALTH_URL, timeoutMs = 5000 } = {}) {
|
|
43
45
|
return new Promise((resolve) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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));
|
|
47
58
|
});
|
|
48
|
-
req.on('error', () =>
|
|
49
|
-
|
|
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'));
|
|
50
73
|
});
|
|
51
74
|
}
|
|
52
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
|
+
|
|
53
120
|
// Probe the running server via /api/health for what it says about itself: its build version
|
|
54
121
|
// (appVersion — the installed build, "so it's scriptable") AND its distribution channel. Either is
|
|
55
122
|
// null when unreachable, non-JSON, or not a floless server — in which case we never touch it.
|
|
56
123
|
// `channel` is additionally null on builds older than the field, which shouldTakeOver reads as
|
|
57
124
|
// "cannot identify, do not evict".
|
|
58
|
-
function probeRunning() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
let body = '';
|
|
62
|
-
res.on('data', (c) => { body += c; });
|
|
63
|
-
res.on('end', () => {
|
|
64
|
-
try {
|
|
65
|
-
const j = JSON.parse(body);
|
|
66
|
-
resolve({ version: j.appVersion || null, channel: j.appChannel || null });
|
|
67
|
-
} catch { resolve({ version: null, channel: null }); }
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
req.on('error', () => resolve({ version: null, channel: null }));
|
|
71
|
-
req.on('timeout', () => { req.destroy(); resolve({ version: null, channel: null }); });
|
|
72
|
-
});
|
|
125
|
+
async function probeRunning() {
|
|
126
|
+
const response = await readHealth();
|
|
127
|
+
return { version: response?.appVersion ?? null, channel: response?.appChannel ?? null };
|
|
73
128
|
}
|
|
74
129
|
|
|
75
130
|
// Compare dotted numeric versions: 1 if a>b, -1 if a<b, 0 if equal.
|
|
@@ -117,15 +172,6 @@ export function shouldTakeOver(runningVersion, selfVersion, channels = {}) {
|
|
|
117
172
|
let _selfVersion = null;
|
|
118
173
|
let _selfChannel = null;
|
|
119
174
|
|
|
120
|
-
async function waitHealthy(timeoutMs = 30000) {
|
|
121
|
-
const deadline = Date.now() + timeoutMs;
|
|
122
|
-
while (Date.now() < deadline) {
|
|
123
|
-
if (await ping()) return true;
|
|
124
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
125
|
-
}
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
175
|
// Resolve how to start the server from wherever this launcher is installed:
|
|
130
176
|
// 1. Packaged SEA exe → spawn SELF with --serve (the main.ts dispatcher serves).
|
|
131
177
|
// 2. Repo checkout → run TypeScript source, even when an old dist/ bundle exists.
|
|
@@ -160,6 +206,7 @@ function startServerDetached() {
|
|
|
160
206
|
shell,
|
|
161
207
|
});
|
|
162
208
|
child.unref();
|
|
209
|
+
return child;
|
|
163
210
|
}
|
|
164
211
|
|
|
165
212
|
function openBrowser(url) {
|
|
@@ -189,26 +236,117 @@ function stopServer() {
|
|
|
189
236
|
}
|
|
190
237
|
}
|
|
191
238
|
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
async function ensureServerUp() {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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;
|
|
248
|
+
}
|
|
249
|
+
say('server up');
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// How `open` waits for a server it has just started. A normal start answers within a few seconds and
|
|
254
|
+
// the app opens directly. A slow one — a large install has taken minutes — used to hit the 30 s
|
|
255
|
+
// limit above, and the launcher exited with no window at all: the user clicked Launch and saw
|
|
256
|
+
// nothing. Now a local "FloLess is starting" page opens instead, the launcher keeps waiting while the
|
|
257
|
+
// server process is alive, and the page turns into the app the moment it answers — or says plainly
|
|
258
|
+
// that the server stopped, with a Try again. Exported with its dependencies so a test can drive it on
|
|
259
|
+
// a fake clock.
|
|
260
|
+
export const QUICK_START_MS = 3000;
|
|
261
|
+
export const SLOW_START_MS = 60_000;
|
|
262
|
+
export const GIVE_UP_MS = 15 * 60_000;
|
|
263
|
+
// After the server process exits, how long it may still answer before the page says it stopped: a
|
|
264
|
+
// second launch that loses the port to a server already starting (the login supervisor's, say) exits
|
|
265
|
+
// once that one listens, and the person should get the running app, not "FloLess stopped".
|
|
266
|
+
export const EXIT_GRACE_MS = 10_000;
|
|
267
|
+
|
|
268
|
+
export async function startAndOpen({
|
|
269
|
+
start = startServerDetached,
|
|
270
|
+
healthy = ping,
|
|
271
|
+
listening = portListening,
|
|
272
|
+
open = openBrowser,
|
|
273
|
+
page = () => writeStartingPage(startingPageDir(join(dirname(logDir()), 'starting'), PORT, process.pid), BROWSER_URL),
|
|
274
|
+
now = Date.now,
|
|
275
|
+
sleep = (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
276
|
+
say = log,
|
|
277
|
+
} = {}) {
|
|
278
|
+
say('starting server…');
|
|
279
|
+
const attempt = createServerAttempt({ start, healthy, listening, now, say });
|
|
280
|
+
let result;
|
|
281
|
+
const startedAt = now();
|
|
282
|
+
while (now() - startedAt < QUICK_START_MS) {
|
|
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;
|
|
286
|
+
await sleep(500);
|
|
287
|
+
}
|
|
288
|
+
// The page is a convenience; a data folder it cannot be written to must not cost the person the app.
|
|
289
|
+
let progress = null;
|
|
290
|
+
try { progress = page(); }
|
|
291
|
+
catch (error) { say(`could not write the starting page (${error?.message ?? error}); will open FloLess when it is ready`); }
|
|
292
|
+
if (progress) {
|
|
293
|
+
say(`server still starting — opened a page that switches to FloLess when it is ready (${progress.path})`);
|
|
294
|
+
open(progress.url);
|
|
295
|
+
}
|
|
296
|
+
// A final state the page never receives would leave it spinning, so it is retried for a few seconds.
|
|
297
|
+
// Returns whether the page got it.
|
|
298
|
+
const settle = async (state) => {
|
|
299
|
+
if (!progress) return false;
|
|
300
|
+
for (let i = 0; i < 5; i += 1) { if (progress.status(state) !== false) return true; await sleep(1000); }
|
|
301
|
+
say(`could not tell the starting page "${state}"`);
|
|
302
|
+
return false;
|
|
303
|
+
};
|
|
304
|
+
let slow = false;
|
|
305
|
+
let exitedAt = null;
|
|
306
|
+
for (;;) {
|
|
307
|
+
result = await attempt.poll();
|
|
308
|
+
if (result === 'ready') {
|
|
309
|
+
// No page, or a page that cannot be told: open the app itself rather than leave it spinning.
|
|
310
|
+
if (!(await settle('ready'))) open(BROWSER_URL);
|
|
311
|
+
say(`server up after ${Math.round((now() - startedAt) / 1000)}s`);
|
|
312
|
+
return 'ready';
|
|
313
|
+
}
|
|
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) {
|
|
321
|
+
exitedAt ??= now();
|
|
322
|
+
if (now() - exitedAt >= EXIT_GRACE_MS) {
|
|
323
|
+
await settle('stopped');
|
|
324
|
+
say('the server stopped before it was ready');
|
|
325
|
+
process.exitCode = 1;
|
|
326
|
+
return 'stopped';
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const elapsed = now() - startedAt;
|
|
330
|
+
if (elapsed >= GIVE_UP_MS) {
|
|
331
|
+
await settle('gave-up');
|
|
332
|
+
say(`server not ready after ${Math.round(elapsed / 60_000)} min — stopped waiting; it may still finish starting`);
|
|
333
|
+
process.exitCode = 1;
|
|
334
|
+
return 'gave-up';
|
|
335
|
+
}
|
|
336
|
+
if (!slow && elapsed >= SLOW_START_MS) { slow = true; progress?.status('slow'); }
|
|
337
|
+
await sleep(1000);
|
|
201
338
|
}
|
|
202
|
-
log('server up');
|
|
203
339
|
}
|
|
204
340
|
|
|
205
|
-
export async function cmdOpen(
|
|
341
|
+
export async function cmdOpen({ marker = consumePostUpdateMarker, healthy = ping, ensure = ensureServerUp,
|
|
342
|
+
startOpen = startAndOpen, say = log, open = openBrowser } = {}) {
|
|
206
343
|
// A post-self-update relaunch must start the server but NOT open a second browser tab —
|
|
207
344
|
// Velopack relaunches FlolessApp.exe bare (→ this `open` action), while the user's existing
|
|
208
345
|
// tab is still alive and reconnects via its 5s health poll (#37). Consume the one-shot
|
|
209
346
|
// marker the updater dropped before the Update.exe handoff; if present, behave like `start`.
|
|
210
|
-
const postUpdate =
|
|
211
|
-
|
|
347
|
+
const postUpdate = marker();
|
|
348
|
+
let serving = await healthy();
|
|
349
|
+
if (serving) {
|
|
212
350
|
// Something is already serving the port. If it's a DIFFERENT, OLDER floless.app build than
|
|
213
351
|
// this one, take it over ("newest wins") so the version the user just launched is the one
|
|
214
352
|
// they get — instead of silently opening the stale instance (e.g. a leftover dev server).
|
|
@@ -220,19 +358,19 @@ export async function cmdOpen() {
|
|
|
220
358
|
+ `this build is v${_selfVersion} (${_selfChannel ?? 'unknown'}) — taking over`);
|
|
221
359
|
stopServer();
|
|
222
360
|
await new Promise((r) => setTimeout(r, 500)); // let the OS release the port
|
|
223
|
-
|
|
361
|
+
serving = false;
|
|
224
362
|
} else {
|
|
225
363
|
log(`already running${running.version ? ` (v${running.version}${running.channel ? `, ${running.channel}` : ''})` : ''}`);
|
|
226
364
|
}
|
|
227
|
-
} else {
|
|
228
|
-
await ensureServerUp();
|
|
229
365
|
}
|
|
230
366
|
if (postUpdate) {
|
|
231
|
-
|
|
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)');
|
|
232
369
|
return;
|
|
233
370
|
}
|
|
371
|
+
if (!serving) { await startOpen(); return; }
|
|
234
372
|
log(`opening ${BROWSER_URL}`);
|
|
235
|
-
|
|
373
|
+
open(BROWSER_URL);
|
|
236
374
|
}
|
|
237
375
|
|
|
238
376
|
// `start` (the in-tab recovery trigger, fired as floless://start from a tab whose
|
|
@@ -241,11 +379,11 @@ export async function cmdOpen() {
|
|
|
241
379
|
// counterpart to `open`, and the action autostart-on-login uses too.
|
|
242
380
|
export async function cmdStart() {
|
|
243
381
|
if (await ping()) { log('already running'); return; }
|
|
244
|
-
await ensureServerUp();
|
|
382
|
+
if (!(await ensureServerUp())) process.exitCode = 1;
|
|
245
383
|
}
|
|
246
384
|
|
|
247
385
|
// `supervise` — the login-autostart entry: KEEP the local server alive. Starts it if
|
|
248
|
-
// down, then polls every few seconds
|
|
386
|
+
// down, then polls every few seconds. Failed startup retries retain a ~33s minimum cadence.
|
|
249
387
|
// This is the ROBUST recovery path: pure local process management — no browser, no
|
|
250
388
|
// floless:// protocol, no admin. (The in-tab Restart button depends on the browser
|
|
251
389
|
// honoring the floless:// handler, which locked-down / corporate-managed browsers can
|
|
@@ -262,14 +400,16 @@ const SUPERVISE_POLL_MS = 3000;
|
|
|
262
400
|
// set it from outside (a user-set value would short-circuit the detach step).
|
|
263
401
|
const SUPERVISE_RESPAWN_ENV = 'FLOLESS_SUPERVISE_RESPAWNED';
|
|
264
402
|
|
|
265
|
-
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() } = {}) {
|
|
266
406
|
// Only the packaged SEA exe (autostart-wired by the Velopack hook) takes the
|
|
267
407
|
// detached-respawn path — its argv is `<exe> --supervise`, which the dispatcher in
|
|
268
408
|
// main.ts handles. The npm channel has process.execPath = node.exe and respawning
|
|
269
409
|
// `node --supervise` would fail with `bad option: --supervise`; autostart is also
|
|
270
410
|
// never wired in that channel, so a foreground loop with visible logs is the right
|
|
271
411
|
// dev behavior. Detect the SEA channel by the exe basename (`FlolessApp.exe`).
|
|
272
|
-
const isSeaChannel =
|
|
412
|
+
const isSeaChannel = packaged;
|
|
273
413
|
if (isSeaChannel && !process.env[SUPERVISE_RESPAWN_ENV]) {
|
|
274
414
|
// First entry on the packaged SEA: re-spawn ourselves detached, then exit, so the
|
|
275
415
|
// logon Scheduled Task that launched us COMPLETES immediately (returns to "Ready")
|
|
@@ -292,21 +432,25 @@ export async function cmdSupervise() {
|
|
|
292
432
|
log('supervisor re-spawned detached');
|
|
293
433
|
return;
|
|
294
434
|
}
|
|
295
|
-
|
|
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();
|
|
296
443
|
for (;;) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
log((await waitHealthy()) ? 'server up' : 'server not healthy yet — will retry');
|
|
308
|
-
}
|
|
309
|
-
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);
|
|
310
454
|
}
|
|
311
455
|
}
|
|
312
456
|
|
|
@@ -503,9 +647,7 @@ function apiJson(path, method = 'GET') {
|
|
|
503
647
|
// triggers the browser handoff, and polls the gate state until it goes valid.
|
|
504
648
|
export async function cmdLogin() {
|
|
505
649
|
if (!(await ping())) {
|
|
506
|
-
|
|
507
|
-
startServerDetached();
|
|
508
|
-
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; }
|
|
509
651
|
}
|
|
510
652
|
const started = await apiJson('/api/license/start', 'POST').catch(() => ({}));
|
|
511
653
|
log(`opening sign-in in your browser${started.signInUrl ? `: ${started.signInUrl}` : ''}`);
|
|
@@ -685,8 +827,7 @@ export async function cmdActionsCli(argv) {
|
|
|
685
827
|
ensureServer: async () => {
|
|
686
828
|
if (await ping()) return true;
|
|
687
829
|
say('Starting FloLess…');
|
|
688
|
-
|
|
689
|
-
return waitHealthy();
|
|
830
|
+
return ensureServerUp({ say });
|
|
690
831
|
},
|
|
691
832
|
out: (text) => write(process.stdout, text),
|
|
692
833
|
err: say,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floless/app",
|
|
3
|
-
"version": "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": {
|
|
@@ -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",
|
|
@@ -86,14 +88,18 @@
|
|
|
86
88
|
},
|
|
87
89
|
"devDependencies": {
|
|
88
90
|
"@fastify/static": "^8.0.0",
|
|
91
|
+
"@gltf-transform/core": "4.5.1",
|
|
92
|
+
"@gltf-transform/extensions": "4.5.1",
|
|
89
93
|
"@types/node": "^22.0.0",
|
|
90
94
|
"@types/yauzl": "3.4.0",
|
|
91
95
|
"ajv": "8.17.1",
|
|
92
96
|
"chokidar": "^4.0.0",
|
|
97
|
+
"earcut": "3.2.4",
|
|
93
98
|
"esbuild": "^0.28.0",
|
|
94
99
|
"fastify": "^5.0.0",
|
|
95
100
|
"fflate": "^0.8.3",
|
|
96
101
|
"linkedom": "^0.18.12",
|
|
102
|
+
"meshoptimizer": "1.3.0",
|
|
97
103
|
"pino-pretty": "^13.0.0",
|
|
98
104
|
"postject": "^1.0.0-alpha.6",
|
|
99
105
|
"rcedit": "^5.0.2",
|