@floless/app 0.154.0 → 0.155.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 (47) hide show
  1. package/dist/floless-server.cjs +49492 -37984
  2. package/dist/schemas/steel.model.v2.schema.json +19 -5
  3. package/dist/skills/floless-app-onboarding/SKILL.md +22 -13
  4. package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +12 -8
  5. package/dist/skills/floless-app-steel-model/SKILL.md +23 -2
  6. package/dist/skills/floless-app-steel-takeoff/SKILL.md +158 -65
  7. package/dist/skills/floless-app-workflows/SKILL.md +23 -5
  8. package/dist/skills/floless-app-workflows/references/blender-exec.md +183 -0
  9. package/dist/skills/floless-app-workflows/references/dev-server-and-run-trace.md +27 -12
  10. package/dist/templates/blender-construction-sequence.flo +96 -0
  11. package/dist/web/agents.js +33 -13
  12. package/dist/web/app.css +275 -33
  13. package/dist/web/aware.js +745 -82
  14. package/dist/web/chat-question-card.js +477 -0
  15. package/dist/web/chat.css +177 -12
  16. package/dist/web/chat.js +1537 -717
  17. package/dist/web/commands-shell.js +424 -7
  18. package/dist/web/commands-steel.js +105 -4
  19. package/dist/web/guide.js +4 -3
  20. package/dist/web/index.html +96 -7
  21. package/dist/web/instructor.js +10 -9
  22. package/dist/web/left-pane.js +40 -3
  23. package/dist/web/media-player.js +234 -0
  24. package/dist/web/model-editor-contract.js +2 -0
  25. package/dist/web/model-editor-revit-adapter.js +1 -0
  26. package/dist/web/model-editor-steel-adapter.js +89 -1
  27. package/dist/web/model-panel-bridge.js +16 -2
  28. package/dist/web/model-view-query.js +590 -0
  29. package/dist/web/model-viewport-revit-adapter.js +15 -1
  30. package/dist/web/model-viewport-toolbar.js +5 -2
  31. package/dist/web/pages.js +592 -0
  32. package/dist/web/panels.js +2 -1
  33. package/dist/web/revit-editor.js +181 -16
  34. package/dist/web/run-progress.js +193 -0
  35. package/dist/web/run-strip.js +173 -0
  36. package/dist/web/steel-3d-core.js +70 -0
  37. package/dist/web/steel-editor.html +2751 -219
  38. package/dist/web/steel-frames-core.js +958 -0
  39. package/dist/web/steel-last-seen.js +315 -0
  40. package/dist/web/steel-marks-core.js +530 -0
  41. package/dist/web/steel-model-slim.js +95 -0
  42. package/dist/web/steel-model-v2-client-validation.js +14 -2
  43. package/dist/web/steel-model-v2-commands.js +258 -27
  44. package/dist/web/steel-model-v2-projection.js +78 -18
  45. package/dist/web/steel-read-confidence.js +11 -2
  46. package/dist/web/workspaces.js +416 -26
  47. package/package.json +3 -2
@@ -0,0 +1,315 @@
1
+ /*
2
+ * steel-last-seen.js - where the Steel Model editor keeps "the model as this tab last had it" (#2209).
3
+ *
4
+ * The model-changed bar offers "See what changed". The server keeps no history of working-model writes, so
5
+ * the answer needs a copy of the model as the tab last saw it, taken when it loaded or when its own save
6
+ * succeeded. This module keeps those copies. The editor decides WHAT is a copy and WHEN one is taken
7
+ * (see `captureLastSeen` in steel-editor.html); this module only keeps and returns them, and it is built so
8
+ * that nothing it does can reach the editor's draft, its tags or its saves:
9
+ *
10
+ * - It touches no localStorage and no editor state. A draft row is the user's unsaved work; a copy is a
11
+ * convenience. They share nothing, so a full or failing store here can never put a draft at risk.
12
+ * - It never throws. Every failure becomes "no copy for that tag", which the page words as a plain
13
+ * sentence with a way forward.
14
+ * - A copy is returned only for the EXACT tag asked for. There is no "nearest" or "newest": a copy for
15
+ * the wrong tag would present someone's own later edits, or another person's, as what changed.
16
+ * - Records are immutable and keyed `scope|tag`. A tag is a content hash, so the same tag is the same
17
+ * content and a rewrite is skipped.
18
+ *
19
+ * WHY INDEXEDDB. localStorage is about 5 MB shared with the draft that protects unsaved edits; a model
20
+ * four times the size of a measured one already fills it with two draft rows, and a copy added to that
21
+ * quota could make the draft's own save fail. IndexedDB has its own, far larger, quota and is
22
+ * asynchronous. The in-memory copy answers the open-tab case without touching it.
23
+ *
24
+ * EVERY IndexedDB OPERATION IS BOUNDED. A blocked or hung open, a transaction that never completes, a
25
+ * connection that opens after we gave up: none may hold the editor. Each operation has a deadline
26
+ * (`LAST_SEEN_IDB_TIMEOUT_MS`); on timeout the operation is treated as unavailable, its transaction is
27
+ * ABORTED (so a write that timed out neither commits its record nor prunes anyone else's), a connection
28
+ * that opens after its deadline is closed on arrival, and its late result is discarded. A write is
29
+ * acknowledged on transaction `complete`, never on request success.
30
+ */
31
+ import { LAST_SEEN_SLIM_VERSION } from './steel-model-slim.js';
32
+
33
+ export const LAST_SEEN_DB_NAME = 'floless-steel-last-seen';
34
+ const DB_VERSION = 1;
35
+ const STORE_NAME = 'models';
36
+ const TS_INDEX = 'ts';
37
+
38
+ /** Copies kept per scope (project + editor type), newest first. An evicted copy degrades to "can't list". */
39
+ export const LAST_SEEN_KEEP_PER_SCOPE = 8;
40
+ /** Copies kept across all scopes, oldest evicted first. */
41
+ export const LAST_SEEN_KEEP_TOTAL = 40;
42
+ /** A slim copy over this is not kept at all. Below the route's body bound so a kept copy is never refused. */
43
+ export const LAST_SEEN_MAX_BYTES = 12 * 1024 * 1024;
44
+ /** Longest any one IndexedDB operation may take before it is treated as unavailable. */
45
+ export const LAST_SEEN_IDB_TIMEOUT_MS = 2000;
46
+ /** Copies the tab also holds in memory, newest first (cheap: the strings already exist). */
47
+ export const LAST_SEEN_MEMORY_KEEP = 3;
48
+
49
+ const encoder = typeof TextEncoder === 'function' ? new TextEncoder() : null;
50
+ /** The UTF-8 size of a string, the unit the byte caps and the stored `bytes` are in. */
51
+ export function byteLength(text) {
52
+ return encoder ? encoder.encode(text).length : unescape(encodeURIComponent(text)).length;
53
+ }
54
+
55
+ /**
56
+ * The slim-rule VERSION is part of the key, so a rule change makes a new key: the copy written under the new rules can never be
57
+ * mistaken for (or blocked by) a record left by the old ones, which would otherwise sit under the same key forever, unreadable,
58
+ * because a tag that is already stored is not rewritten. Old-version records simply age out through the eviction below.
59
+ */
60
+ export const lastSeenKey = (scope, tag) => `${scope}|${tag}|v${LAST_SEEN_SLIM_VERSION}`;
61
+ /** The scope of a key: everything before the last two segments (the tag and the version). */
62
+ const scopeOfKey = (key) => key.slice(0, key.lastIndexOf('|', key.lastIndexOf('|') - 1));
63
+
64
+ // ---- a deadline around one asynchronous step ---------------------------------------------------------
65
+
66
+ /**
67
+ * Run `start(register)` and settle with its result, or reject on `timeoutMs`. `register(cleanup)` adds
68
+ * work to run if the deadline passes first (abort a transaction, close a connection); if the deadline has
69
+ * already passed when it is called, the cleanup runs at once. A result arriving after the deadline is dropped.
70
+ *
71
+ * @param {number} timeoutMs
72
+ * @param {(register: (cleanup: () => void) => void) => any} start
73
+ */
74
+ export function withDeadline(timeoutMs, start) {
75
+ return new Promise((resolve, reject) => {
76
+ let settled = false;
77
+ const cleanups = [];
78
+ const run = (fn) => { try { fn(); } catch { /* best effort */ } };
79
+ const timer = setTimeout(() => {
80
+ if (settled) return;
81
+ settled = true;
82
+ for (const fn of cleanups) run(fn);
83
+ reject(new Error('timeout'));
84
+ }, timeoutMs);
85
+ const register = (fn) => { if (settled) run(fn); else cleanups.push(fn); };
86
+ Promise.resolve().then(() => start(register)).then(
87
+ (value) => { if (settled) return; settled = true; clearTimeout(timer); resolve(value); },
88
+ (error) => { if (settled) return; settled = true; clearTimeout(timer); reject(error); },
89
+ );
90
+ });
91
+ }
92
+
93
+ // ---- backends ------------------------------------------------------------------------------------------
94
+
95
+ /**
96
+ * A backend is `{ get(key): Promise<record|null>, put(record, limits): Promise<void> }`. This one keeps
97
+ * records in a Map: the unit tests' backend and the page's fallback where IndexedDB is absent.
98
+ */
99
+ export function createMemoryBackend() {
100
+ const records = new Map();
101
+ return {
102
+ kind: 'memory',
103
+ records,
104
+ async get(key) { return records.get(key) ?? null; },
105
+ async put(record, limits) {
106
+ if (!records.has(record.key)) records.set(record.key, record);
107
+ pruneMap(records, record.key, limits);
108
+ },
109
+ };
110
+ }
111
+
112
+ /** Keep the newest `keepPerScope` per scope and `keepTotal` overall; never the record just written. */
113
+ export function chooseEvictions(rows, justWritten, { keepPerScope, keepTotal }) {
114
+ const newestFirst = [...rows].sort((a, b) => b.ts - a.ts || (a.key < b.key ? -1 : 1));
115
+ // The record just written is always kept and counts toward its own scope, wherever the clock puts it.
116
+ const keep = new Set([justWritten]);
117
+ const perScope = new Map([[scopeOfKey(justWritten), 1]]);
118
+ for (const row of newestFirst) {
119
+ if (row.key === justWritten) continue;
120
+ const scope = scopeOfKey(row.key);
121
+ const count = perScope.get(scope) ?? 0;
122
+ if (count < keepPerScope && keep.size < keepTotal) { keep.add(row.key); perScope.set(scope, count + 1); }
123
+ }
124
+ return newestFirst.filter((row) => !keep.has(row.key)).map((row) => row.key);
125
+ }
126
+
127
+ function pruneMap(records, justWritten, limits) {
128
+ const rows = [...records.values()].map((r) => ({ key: r.key, ts: r.ts }));
129
+ for (const key of chooseEvictions(rows, justWritten, limits)) records.delete(key);
130
+ }
131
+
132
+ /**
133
+ * The IndexedDB backend. `factory` is an `IDBFactory` (injected so tests drive a fake one); every call is
134
+ * bounded by `timeoutMs`. Calls are serialised, so at most one connection or transaction is in play and a
135
+ * hung operation costs the next one at most its own deadline.
136
+ *
137
+ * @param {{ factory: any, timeoutMs?: number, warn?: (error: unknown) => unknown }} options
138
+ */
139
+ export function createIdbBackend({ factory, timeoutMs = LAST_SEEN_IDB_TIMEOUT_MS, warn = () => {} }) {
140
+ let db = null;
141
+ let tail = Promise.resolve();
142
+
143
+ const serialised = (task) => {
144
+ const result = tail.then(task, task);
145
+ tail = result.then(() => undefined, () => undefined);
146
+ return result;
147
+ };
148
+
149
+ function open(register) {
150
+ if (db) return Promise.resolve(db);
151
+ return new Promise((resolve, reject) => {
152
+ let late = false;
153
+ let request;
154
+ try { request = factory.open(LAST_SEEN_DB_NAME, DB_VERSION); } catch (error) { reject(error); return; }
155
+ register(() => { late = true; });
156
+ request.onupgradeneeded = () => {
157
+ // The upgrade is a transaction of its own. If this open was already abandoned there is nobody to use the database, so
158
+ // end the upgrade at once; otherwise a deadline must be able to end an upgrade that stalls.
159
+ const upgrade = request.transaction;
160
+ const abortUpgrade = () => { try { if (upgrade) upgrade.abort(); } catch { /* best effort */ } };
161
+ if (late) { abortUpgrade(); return; }
162
+ register(abortUpgrade);
163
+ const database = request.result;
164
+ const store = database.createObjectStore(STORE_NAME, { keyPath: 'key' });
165
+ store.createIndex(TS_INDEX, 'ts', { unique: false });
166
+ };
167
+ // Blocked is an answer, not a pause: this open is given up now, so a connection that arrives later (the other tab let go)
168
+ // belongs to nobody and is closed on arrival instead of being kept.
169
+ request.onblocked = () => { late = true; reject(new Error('blocked')); };
170
+ request.onerror = () => reject(request.error || new Error('open failed'));
171
+ request.onsuccess = () => {
172
+ const opened = request.result;
173
+ // Opened after the deadline: nobody is waiting, so don't keep a connection nobody will close.
174
+ if (late) { try { opened.close(); } catch { /* best effort */ } return; }
175
+ opened.onversionchange = () => { try { opened.close(); } catch { /* best effort */ } if (db === opened) db = null; };
176
+ opened.onclose = () => { if (db === opened) db = null; };
177
+ db = opened;
178
+ resolve(opened);
179
+ };
180
+ });
181
+ }
182
+
183
+ const bounded = (task) => serialised(() => withDeadline(timeoutMs, async (register) => {
184
+ try { return await task(await open(register), register); }
185
+ catch (error) { warn(error); throw error; }
186
+ }));
187
+
188
+ return {
189
+ kind: 'indexeddb',
190
+ get(key) {
191
+ return bounded((database, register) => new Promise((resolve, reject) => {
192
+ const tx = database.transaction(STORE_NAME, 'readonly');
193
+ register(() => tx.abort());
194
+ const request = tx.objectStore(STORE_NAME).get(key);
195
+ request.onsuccess = () => resolve(request.result ?? null);
196
+ request.onerror = () => reject(request.error || new Error('read failed'));
197
+ tx.onabort = () => reject(tx.error || new Error('read aborted'));
198
+ }));
199
+ },
200
+ put(record, limits) {
201
+ return bounded((database, register) => new Promise((resolve, reject) => {
202
+ const tx = database.transaction(STORE_NAME, 'readwrite');
203
+ register(() => tx.abort());
204
+ const store = tx.objectStore(STORE_NAME);
205
+ // Acknowledged on the transaction completing, never on a request succeeding.
206
+ tx.oncomplete = () => resolve();
207
+ tx.onabort = () => reject(tx.error || new Error('write aborted'));
208
+ tx.onerror = () => reject(tx.error || new Error('write failed'));
209
+ const exists = store.getKey(record.key);
210
+ exists.onsuccess = () => {
211
+ if (exists.result === undefined) store.put(record);
212
+ // Prune in the SAME transaction (atomic across tabs): metadata only, never the model strings.
213
+ const rows = [];
214
+ const cursor = store.index(TS_INDEX).openKeyCursor();
215
+ cursor.onsuccess = () => {
216
+ const at = cursor.result;
217
+ if (at) { rows.push({ key: at.primaryKey, ts: at.key }); at.continue(); return; }
218
+ for (const key of chooseEvictions(rows, record.key, limits)) store.delete(key);
219
+ };
220
+ cursor.onerror = () => reject(cursor.error || new Error('prune failed'));
221
+ };
222
+ exists.onerror = () => reject(exists.error || new Error('write failed'));
223
+ }));
224
+ },
225
+ };
226
+ }
227
+
228
+ // ---- the store ---------------------------------------------------------------------------------------
229
+
230
+ /**
231
+ * One tab's copies for one scope (a project + editor type, the same identity as its draft).
232
+ *
233
+ * commit(tag, modelJson) Synchronous. Remember `modelJson` (the JSON text of the slim model) as the
234
+ * model for `tag`: in memory at once, in storage soon. False when it was refused.
235
+ * recall(tag) Promise of `{ ok:true, model, tag, from }` or `{ ok:false, reason }`.
236
+ * idle() Promise that settles when no storage write is pending (tests, page hide).
237
+ *
238
+ * `modelJson` is a STRING, never an object: it is immutable once taken, costs nothing to store or send, and
239
+ * the page takes it in the same tick as the request body (so it can never describe a later edit).
240
+ *
241
+ * @param {{ scope: string, backend?: any, now?: () => number, warn?: (error: unknown) => unknown,
242
+ * limits?: { keepPerScope?: number, keepTotal?: number, maxBytes?: number } }} options
243
+ */
244
+ export function createLastSeenStore({ scope, backend = null, now = () => Date.now(), warn = () => {}, limits = {} }) {
245
+ const caps = {
246
+ keepPerScope: limits.keepPerScope ?? LAST_SEEN_KEEP_PER_SCOPE,
247
+ keepTotal: limits.keepTotal ?? LAST_SEEN_KEEP_TOTAL,
248
+ maxBytes: limits.maxBytes ?? LAST_SEEN_MAX_BYTES,
249
+ };
250
+ /** Newest first. */
251
+ let recent = [];
252
+ let queued = null;
253
+ let pumping = null;
254
+ let storage = backend ? 'ok' : 'unavailable';
255
+ let warned = false;
256
+
257
+ const fail = (error) => {
258
+ storage = 'unavailable';
259
+ if (!warned) { warned = true; try { warn(error); } catch { /* never throws */ } }
260
+ };
261
+
262
+ async function pump() {
263
+ while (queued) {
264
+ const record = queued;
265
+ queued = null;
266
+ try { await backend.put(record, { keepPerScope: caps.keepPerScope, keepTotal: caps.keepTotal }); storage = 'ok'; }
267
+ catch (error) { fail(error); }
268
+ }
269
+ pumping = null;
270
+ }
271
+
272
+ return {
273
+ get storageState() { return storage; },
274
+ commit(tag, modelJson) {
275
+ try {
276
+ if (typeof tag !== 'string' || !tag || typeof modelJson !== 'string' || !modelJson) return false;
277
+ const bytes = byteLength(modelJson);
278
+ if (bytes > caps.maxBytes) return false; // too big to keep anywhere, memory included
279
+ recent = [{ tag, model: modelJson, bytes }, ...recent.filter((entry) => entry.tag !== tag)].slice(0, LAST_SEEN_MEMORY_KEEP);
280
+ if (backend) {
281
+ // Last writer wins among writes that have not started: an intermediate tag of a quick run of
282
+ // saves is superseded before it matters (the draft is restamped to the newest).
283
+ queued = { key: lastSeenKey(scope, tag), scope, tag, ts: now(), v: LAST_SEEN_SLIM_VERSION, bytes, model: modelJson };
284
+ if (!pumping) pumping = pump();
285
+ }
286
+ return true;
287
+ } catch (error) { fail(error); return false; }
288
+ },
289
+ async recall(tag) {
290
+ try {
291
+ if (typeof tag !== 'string' || !tag) return { ok: false, reason: 'no-tag' };
292
+ const held = recent.find((entry) => entry.tag === tag);
293
+ if (held) return { ok: true, model: held.model, tag, from: 'memory' };
294
+ if (!backend) return { ok: false, reason: 'unavailable' };
295
+ let record;
296
+ try { record = await backend.get(lastSeenKey(scope, tag)); }
297
+ catch (error) { fail(error); return { ok: false, reason: 'unavailable' }; }
298
+ if (!record) return { ok: false, reason: 'none' };
299
+ const sound = record.v === LAST_SEEN_SLIM_VERSION && record.scope === scope && record.tag === tag
300
+ && typeof record.model === 'string' && record.bytes === byteLength(record.model);
301
+ return sound ? { ok: true, model: record.model, tag, from: 'storage' } : { ok: false, reason: 'unreadable' };
302
+ } catch (error) { fail(error); return { ok: false, reason: 'unavailable' }; }
303
+ },
304
+ idle() { return pumping ? pumping.then(() => undefined, () => undefined) : Promise.resolve(); },
305
+ };
306
+ }
307
+
308
+ /**
309
+ * The store the page uses: IndexedDB when the browser has it, memory only when it does not.
310
+ * @param {{ scope: string, indexedDB?: any, warn?: (error: unknown) => unknown }} options
311
+ */
312
+ export function createPageLastSeenStore({ scope, indexedDB: factory, warn }) {
313
+ const backend = factory ? createIdbBackend({ factory, warn }) : null;
314
+ return createLastSeenStore({ scope, backend, warn });
315
+ }