@floless/app 0.155.2 → 0.157.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 (64) hide show
  1. package/cli-actions.mjs +392 -0
  2. package/dist/floless-server.cjs +182734 -141519
  3. package/dist/schemas/drawing-check.profile.v1.schema.json +15 -2
  4. package/dist/schemas/steel.model.v2.schema.json +25 -1
  5. package/dist/skills/floless-app-actions/SKILL.md +199 -0
  6. package/dist/skills/floless-app-approval/SKILL.md +8 -5
  7. package/dist/skills/floless-app-bridge/SKILL.md +12 -9
  8. package/dist/skills/floless-app-knowledge/SKILL.md +50 -14
  9. package/dist/skills/floless-app-new-workflow/SKILL.md +26 -10
  10. package/dist/skills/floless-app-onboarding/SKILL.md +31 -1
  11. package/dist/skills/floless-app-onboarding/references/aware-runtime.md +4 -4
  12. package/dist/skills/floless-app-queue/SKILL.md +10 -6
  13. package/dist/skills/floless-app-report-issue/SKILL.md +15 -12
  14. package/dist/skills/floless-app-rfi/SKILL.md +98 -73
  15. package/dist/skills/floless-app-routines/SKILL.md +27 -15
  16. package/dist/skills/floless-app-routines/references/routines-api.md +8 -2
  17. package/dist/skills/floless-app-steel-model/SKILL.md +1 -1
  18. package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +4 -2
  19. package/dist/skills/floless-app-tweak-contract/SKILL.md +25 -5
  20. package/dist/skills/floless-app-workflows/SKILL.md +50 -13
  21. package/dist/skills/floless-app-workflows/references/agent-steps.md +119 -0
  22. package/dist/web/agent-steps.js +1750 -0
  23. package/dist/web/agents.js +33 -8
  24. package/dist/web/app.css +681 -4
  25. package/dist/web/app.js +111 -11
  26. package/dist/web/aware-update-client.js +1 -0
  27. package/dist/web/aware.js +1257 -202
  28. package/dist/web/chat-landing-scene.js +372 -0
  29. package/dist/web/chat.css +254 -1
  30. package/dist/web/chat.js +2657 -87
  31. package/dist/web/commands-drawing-check.js +17 -0
  32. package/dist/web/commands-shell.js +1108 -4
  33. package/dist/web/commands-steel.js +6 -0
  34. package/dist/web/connections.js +1 -0
  35. package/dist/web/drawing-check-editor.html +33 -5
  36. package/dist/web/drawing-check-editor.js +538 -22
  37. package/dist/web/drawing-check-overlay.js +13 -0
  38. package/dist/web/flo-avatar.js +28 -3
  39. package/dist/web/guide.js +7 -2
  40. package/dist/web/index.html +171 -7
  41. package/dist/web/instructor.js +6 -4
  42. package/dist/web/leave-guard.js +4 -2
  43. package/dist/web/left-pane.js +8 -3
  44. package/dist/web/model-revit-module.js +15 -0
  45. package/dist/web/model-view-query.js +12 -2
  46. package/dist/web/model-viewport-revit-adapter.js +3 -1
  47. package/dist/web/pages.js +891 -36
  48. package/dist/web/panels.js +8 -5
  49. package/dist/web/parser-setup-recovery.js +12 -4
  50. package/dist/web/project-access.js +549 -0
  51. package/dist/web/project-reconciliation.js +357 -0
  52. package/dist/web/report-files.js +50 -0
  53. package/dist/web/revit-editor.js +116 -27
  54. package/dist/web/startup-admission.js +132 -0
  55. package/dist/web/steel-3d-core.js +9 -0
  56. package/dist/web/steel-editor.html +642 -22
  57. package/dist/web/steel-model-v2-commands.js +63 -5
  58. package/dist/web/step-rename.js +287 -0
  59. package/dist/web/terminal-requests.js +590 -0
  60. package/dist/web/tool-updates.js +148 -13
  61. package/dist/web/workspace-root-management.js +39 -0
  62. package/dist/web/workspaces.js +1879 -74
  63. package/launch.mjs +82 -2
  64. package/package.json +3 -1
@@ -0,0 +1,357 @@
1
+ /* Project-folder observations are display data; only reviewed server routes admit a folder. */
2
+ (() => {
3
+ const modal = document.getElementById('workspace-root-modal');
4
+ if (!modal) return;
5
+ const section = document.createElement('section');
6
+ section.className = 'workspace-root-management project-reconciliation';
7
+ section.setAttribute('aria-label', 'Project folders');
8
+ modal.querySelector('#workspace-root-status').after(section);
9
+ const esc = (value) => String(value ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
10
+ let data = null, review = null, problem = '', busy = false, sequence = 0, opener = null, draftName = null, draftAcknowledged = false;
11
+ let sessionReady = null;
12
+ let focusTimer = null, focusGeneration = 0, draftScope = null;
13
+ let listSequence = 0, listBusyOwner = null, decisionBusyOwner = null;
14
+ let recoveryResult = null, recoveryError = '', recoveryBusyTransaction = null;
15
+ let activeCheck = null;
16
+ const currentRoot = () => window.flolessWorkspaceRoot?.current()?.root;
17
+ const sameRoot = (a, b) => !!a && !!b && a.rootId === b.rootId && a.generation === b.generation;
18
+ const reviewScope = () => review ? JSON.stringify([review.root?.rootId, review.root?.generation, review.reviewId]) : null;
19
+ function resetDraft() { draftName = null; draftAcknowledged = false; draftScope = reviewScope(); }
20
+ function captureDraft() {
21
+ if (!review || draftScope !== reviewScope() || !sameRoot(review.root, currentRoot())) return;
22
+ const name = section.querySelector('#project-reconciliation-name');
23
+ const ack = section.querySelector('#project-reconciliation-ack');
24
+ if (name) draftName = name.value;
25
+ if (ack) draftAcknowledged = !!ack.checked;
26
+ }
27
+ function cancelAutofocus() {
28
+ clearTimeout(focusTimer); focusTimer = null; focusGeneration++;
29
+ }
30
+ const carriers = {
31
+ 'shell.project-folders-review': () => 'data-command-id="shell.project-folders-review"',
32
+ 'shell.project-folders-check': () => 'data-command-id="shell.project-folders-check"',
33
+ 'shell.project-candidate-review': (id) => `data-command-id="shell.project-candidate-review#${esc(id)}"`,
34
+ 'shell.project-registration-locate': (id) => `data-command-id="shell.project-registration-locate#${esc(id)}"`,
35
+ 'shell.project-candidate-name': (id) => `data-command-id="shell.project-candidate-name#${esc(id)}"`,
36
+ 'shell.project-reconciliation-acknowledge': (id) => `data-command-id="shell.project-reconciliation-acknowledge#${esc(id)}"`,
37
+ 'shell.project-candidate-show': (id) => `data-command-id="shell.project-candidate-show#${esc(id)}"`,
38
+ 'shell.project-candidate-retry': (id) => `data-command-id="shell.project-candidate-retry#${esc(id)}"`,
39
+ 'shell.project-candidate-import': (id) => `data-command-id="shell.project-candidate-import#${esc(id)}"`,
40
+ 'shell.project-registration-reconcile': (id) => `data-command-id="shell.project-registration-reconcile#${esc(id)}"`,
41
+ 'shell.project-folder-leave': () => 'data-command-id="shell.project-folder-leave"',
42
+ 'shell.project-folder-recovery-retry': (id) => `data-command-id="shell.project-folder-recovery-retry#${esc(id)}"`,
43
+ };
44
+ const command = (id, instance, label) => carriers[id](instance) + (instance ? ` data-command-instance-label="${esc(label || instance)}"` : '');
45
+ const button = (act, label, id, instance, primary = false) => `<button type="button" data-folder-action="${act}" ${command(id, instance, review?.candidate?.name || review?.candidate?.path)}${primary ? ' class="primary"' : ''}${busy ? ' disabled data-blocked-reason="FloLess is finishing this folder review."' : ''}>${label}</button>`;
46
+ async function api(path, body) {
47
+ if (body !== undefined && !sessionReady) {
48
+ sessionReady = (async () => {
49
+ const response = await fetch('/api/editor/session', { method: 'POST', credentials: 'same-origin' });
50
+ const result = await response.json().catch(() => null);
51
+ if (!response.ok && !(response.status === 403 && result?.error === 'editor_session_unavailable')) {
52
+ throw new Error('The local browser session could not be opened. Close this dialog and try again.');
53
+ }
54
+ })().catch((error) => { sessionReady = null; throw error; });
55
+ }
56
+ if (body !== undefined) await sessionReady;
57
+ const response = await fetch(path, { credentials: 'same-origin', headers: { 'content-type': 'application/json' },
58
+ ...(body === undefined ? {} : { method: 'POST', body: JSON.stringify(body) }) });
59
+ const result = await response.json();
60
+ if (!response.ok || result.ok === false) {
61
+ const message = [result.userMessage, result.message, result.error].find((value) => typeof value === 'string' && value.trim());
62
+ throw new Error(message || 'FloLess could not finish this folder review. Check the folder and try again.');
63
+ }
64
+ return result;
65
+ }
66
+ function paintNotice() {
67
+ const notice = document.getElementById('ws-folder-review-note');
68
+ if (!notice) return;
69
+ const count = sameRoot(data?.root, currentRoot()) ? (data.candidates?.length || 0) + (data.unavailable?.length || 0) : 0;
70
+ const recovery = sameRoot(data?.root, currentRoot()) && (data.pendingRecovery || data.recoveryUnavailableReason);
71
+ notice.hidden = !count && !recovery;
72
+ notice.innerHTML = count || recovery ? `${recovery ? 'Project folder recovery needs review.' : `${count} project folder${count === 1 ? '' : 's'} need review.`} <button type="button" data-folder-notice ${command('shell.project-folders-review')}>Review folders</button>` : '';
73
+ }
74
+ function recoveryHtml() {
75
+ if (!sameRoot(data?.root, currentRoot())) return '';
76
+ let html = '';
77
+ const pending = data.pendingRecovery;
78
+ if (data.recoveryUnavailableReason) html += `<div class="workspace-root-error" role="status">${esc(data.recoveryUnavailableReason)} Check project folders to try reading the recovery record again.</div>`;
79
+ if (pending) {
80
+ const operation = { move: 'Moving a project', archive: 'Archiving a project', restore: 'Restoring a project', delete: 'Removing a project',
81
+ 'create-publish': 'Creating a project', 'create-reserve': 'Preparing a project', 'collection-transition': 'Moving a project', remove: 'Removing a project', repair: 'Updating a project folder' }[pending.operation] || 'Changing a project folder';
82
+ html += `<div class="workspace-root-management-note"><h4>Folder change needs recovery</h4><p>${esc(operation)} was interrupted.</p>`;
83
+ if (pending.source) html += `<p>From</p><code class="workspace-root-management-target">${esc(pending.source)}</code>`;
84
+ if (pending.destination) html += `<p>To</p><code class="workspace-root-management-target">${esc(pending.destination)}</code>`;
85
+ html += `<p>${esc(pending.userMessage || 'Review the affected folder, then retry recovery.')}</p>`;
86
+ if (pending.supported === false) html += '<p>FloLess cannot finish this change automatically. Restore the named folder through your file manager, then retry recovery. The Current Workspace directory path is shown above.</p>';
87
+ else html += '<p>Retry may finish the change, cancel it, or still need your help. Use your file manager to inspect or restore the named folder; the Current Workspace directory path is shown above.</p>';
88
+ const retrying = decisionBusyOwner !== null && recoveryBusyTransaction === pending.transactionId;
89
+ html += `<button type="button" data-folder-action="recover" data-folder-id="${esc(pending.transactionId)}" ${command('shell.project-folder-recovery-retry', pending.transactionId, pending.source || pending.destination || currentRoot().path)} aria-busy="${retrying}"${decisionBusyOwner !== null ? ` disabled data-blocked-reason="${retrying ? 'FloLess is retrying this folder recovery.' : 'FloLess is finishing a folder decision.'}"` : ''}>${retrying ? 'Retrying recovery…' : 'Retry folder recovery'}</button></div>`;
90
+ }
91
+ if (recoveryError) html += `<div class="workspace-root-error" role="alert">${esc(recoveryError)}</div>`;
92
+ if (recoveryResult && sameRoot(recoveryResult.root, currentRoot())) {
93
+ html += `<div class="workspace-root-management-message" id="project-folder-recovery-result" role="status" aria-live="polite" tabindex="-1">${esc(recoveryResult.message)}`;
94
+ if (recoveryResult.source) html += `<code class="workspace-root-management-target">From ${esc(recoveryResult.source)}</code>`;
95
+ if (recoveryResult.destination) html += `<code class="workspace-root-management-target">To ${esc(recoveryResult.destination)}</code>`;
96
+ html += '</div>';
97
+ }
98
+ return html;
99
+ }
100
+ function render() {
101
+ busy = decisionBusyOwner !== null || (!review && listBusyOwner !== null);
102
+ const active = section.contains(document.activeElement) ? document.activeElement : null;
103
+ const focused = active?.getAttribute('data-command-id');
104
+ const focusedRecoveryResult = active?.id === 'project-folder-recovery-result';
105
+ const caret = active?.id === 'project-reconciliation-name' ? [active.selectionStart, active.selectionEnd, active.selectionDirection] : null;
106
+ section.setAttribute('aria-busy', String(busy));
107
+ let html = '<h3>Project folders</h3>' + recoveryHtml();
108
+ if (!review) {
109
+ html += '<p class="workspace-root-management-note">Folders changed outside FloLess stay here until you review them.</p>';
110
+ html += button('check', busy ? 'Checking…' : 'Check project folders', 'shell.project-folders-check');
111
+ if (data?.checkedAt) html += `<p class="workspace-root-management-note">Last checked ${esc(new Date(data.checkedAt).toLocaleString())}${data.checking ? ' · checking…' : ''}</p>`;
112
+ const rows = [...(data?.candidates || []), ...(data?.unavailable || [])];
113
+ if (rows.length) {
114
+ html += '<div class="project-reconciliation-list">';
115
+ for (const row of rows) {
116
+ const unavailable = !!row.registrationId && !row.candidateId;
117
+ const identity = unavailable ? row.registrationId : row.candidateId;
118
+ html += `<div class="workspace-root-management-row"><div><b>${esc(row.name || row.locator || 'Project folder')}</b>`
119
+ + `<code data-tip="${esc(row.path)}">${esc(row.path)}</code>`
120
+ + `<span class="workspace-root-management-state">${esc(row.summary || (unavailable ? 'Project folder unavailable' : 'Not added to FloLess'))}${row.archived ? ' · Archive folder' : ''}</span></div>`
121
+ + `<button type="button" data-folder-action="${unavailable ? 'locate' : 'review'}" data-folder-id="${esc(identity)}" ${command(unavailable ? 'shell.project-registration-locate' : 'shell.project-candidate-review', identity, row.name || row.path)}${busy ? ' disabled data-blocked-reason="FloLess is checking project folders."' : ''}>${unavailable ? 'Locate folder…' : 'Review…'}</button></div>`;
122
+ }
123
+ html += '</div>';
124
+ } else if (data) html += '<p class="workspace-root-management-note">No project folders need review from the last check.</p>';
125
+ else html += '<p class="workspace-root-management-note">Checking project folders…</p>';
126
+ } else {
127
+ const candidate = review.candidate || {};
128
+ const registrationId = review.registration?.registrationId;
129
+ html += `<h4>${esc(candidate.name || candidate.locator || 'Review project folder')}</h4>`;
130
+ if (review.previousPath) html += `<p class="workspace-root-management-note">Previously saved at</p><code class="workspace-root-management-target">${esc(review.previousPath)}</code>`;
131
+ html += `<p class="workspace-root-management-note">Found at</p><code class="workspace-root-management-target">${esc(candidate.path)}</code>`;
132
+ html += `<p class="workspace-root-management-note">${esc(review.warning || candidate.summary || 'Review this folder before adding it to FloLess.')}</p>`;
133
+ if (review.choices?.canImport) html += `<label class="project-setup-field">Project name<input type="text" id="project-reconciliation-name" value="${esc(draftName ?? candidate.name ?? candidate.locator ?? '')}" ${command('shell.project-candidate-name', candidate.candidateId, candidate.name || candidate.path)}${busy ? ' disabled data-blocked-reason="FloLess is finishing this folder review."' : ''}></label>`
134
+ + '<p class="workspace-root-management-note">Import creates a separate project. The original stays where it is. FloLess reports which data and approvals can be carried.</p>';
135
+ // Ambiguity must be acknowledged by the person; the server revalidates every decision.
136
+ if (review.choices?.canReconcile && review.ambiguous) html += `<label class="project-reconciliation-choice"><input type="checkbox" id="project-reconciliation-ack" ${command('shell.project-reconciliation-acknowledge', registrationId, candidate.name || candidate.path)}${draftAcknowledged ? ' checked' : ''}${busy ? ' disabled data-blocked-reason="FloLess is finishing this folder review."' : ''}>I moved this folder and want it to remain the existing project.</label>`;
137
+ html += '<div class="project-reconciliation-actions">';
138
+ if (review.choices?.canShowFolder) html += button('show', 'Show folder', 'shell.project-candidate-show', candidate.candidateId);
139
+ html += button('retry', 'Check again', 'shell.project-candidate-retry', candidate.candidateId);
140
+ if (review.choices?.canImport) html += button('import', 'Import as a new project', 'shell.project-candidate-import', candidate.candidateId, true);
141
+ if (review.choices?.canReconcile && registrationId) html += button('reconcile', 'Use folder for existing project', 'shell.project-registration-reconcile', registrationId);
142
+ html += button('back', 'Leave for later', 'shell.project-folder-leave') + '</div>';
143
+ }
144
+ if (problem) html += `<div class="workspace-root-error" role="alert">${esc(problem)} ${review
145
+ ? button('retry', 'Check again', 'shell.project-candidate-retry', review.candidate?.candidateId)
146
+ : button('check', 'Try again', 'shell.project-folders-check')}</div>`;
147
+ section.innerHTML = html;
148
+ if (focused) {
149
+ const target = Array.from(section.querySelectorAll('[data-command-id]')).find((el) => el.getAttribute('data-command-id') === focused);
150
+ target?.focus({ preventScroll: true });
151
+ if (caret && typeof target?.setSelectionRange === 'function' && Number.isInteger(caret[0]) && Number.isInteger(caret[1])) target.setSelectionRange(...caret);
152
+ }
153
+ if (focusedRecoveryResult) section.querySelector('#project-folder-recovery-result')?.focus({ preventScroll: true });
154
+ paintNotice();
155
+ }
156
+ async function load(check = false) {
157
+ const root = currentRoot();
158
+ const intent = sequence;
159
+ // A cached background read cannot outrank the discovery the person asked to finish.
160
+ if (!check && activeCheck && activeCheck.intent === intent && sameRoot(activeCheck.root, root)) {
161
+ activeCheck.refreshAfter = true;
162
+ return;
163
+ }
164
+ const request = ++listSequence;
165
+ const checking = check ? { root, intent, request, refreshAfter: false } : null;
166
+ if (checking) activeCheck = checking;
167
+ let accepted = false;
168
+ // Updating the observation list does not disable the form for an unchanged review.
169
+ listBusyOwner = request;
170
+ if (decisionBusyOwner === null) problem = '';
171
+ render();
172
+ try {
173
+ const result = await api('/api/project-reconciliation' + (check ? '/check' : ''), check ? {} : undefined);
174
+ if (request !== listSequence || intent !== sequence || !sameRoot(root, currentRoot()) || !sameRoot(result.root, root)) return;
175
+ if (data?.pendingRecovery?.transactionId !== result.pendingRecovery?.transactionId) recoveryError = '';
176
+ data = result;
177
+ accepted = true;
178
+ } catch (error) { if (request === listSequence && intent === sequence && sameRoot(root, currentRoot())) problem = error.message; }
179
+ finally {
180
+ const refresh = accepted && checking && activeCheck === checking && checking.refreshAfter
181
+ && intent === sequence && request === listSequence && sameRoot(root, currentRoot());
182
+ if (checking && activeCheck === checking) activeCheck = null;
183
+ if (listBusyOwner === request) { listBusyOwner = null; render(); }
184
+ if (refresh) load();
185
+ }
186
+ }
187
+ async function openRegistration(registrationId) {
188
+ return open(registrationId);
189
+ }
190
+ async function open(registrationId) {
191
+ cancelAutofocus();
192
+ sequence++; listSequence++; listBusyOwner = null; decisionBusyOwner = null; recoveryBusyTransaction = null;
193
+ const focusIntent = focusGeneration;
194
+ opener = document.activeElement;
195
+ review = null; resetDraft(); problem = ''; render();
196
+ await window.flolessWorkspaceRoot.open();
197
+ const root = currentRoot();
198
+ await load();
199
+ if (focusIntent !== focusGeneration || !sameRoot(root, currentRoot()) || !modal.classList.contains('show')) return;
200
+ focusTimer = setTimeout(() => {
201
+ focusTimer = null;
202
+ if (focusIntent !== focusGeneration || !sameRoot(root, currentRoot()) || !modal.classList.contains('show')) return;
203
+ const target = registrationId
204
+ ? Array.from(section.querySelectorAll('[data-folder-id]')).find((row) => row.dataset.folderId === registrationId)
205
+ : section.querySelector('button');
206
+ if (target) target.focus({ preventScroll: true });
207
+ else if (registrationId) { problem = 'Check project folders to review the current location of this project.'; render(); }
208
+ }, 0);
209
+ }
210
+ async function act(action, id) {
211
+ if (action === 'recover') return retryRecovery(id);
212
+ if (busy) return;
213
+ cancelAutofocus();
214
+ if (action === 'back') {
215
+ sequence++; listSequence++; listBusyOwner = null;
216
+ review = null; resetDraft(); problem = ''; render(); section.querySelector('button')?.focus(); return;
217
+ }
218
+ if (action === 'check') return load(true);
219
+ const root = currentRoot();
220
+ const request = ++sequence;
221
+ const original = review;
222
+ const name = section.querySelector('#project-reconciliation-name')?.value;
223
+ const acknowledged = !!section.querySelector('#project-reconciliation-ack')?.checked;
224
+ captureDraft();
225
+ if (action === 'reconcile' && review?.ambiguous && !acknowledged) {
226
+ problem = 'Confirm that you moved this folder, or import it as a separate project.'; render(); return;
227
+ }
228
+ decisionBusyOwner = request; problem = ''; render();
229
+ try {
230
+ let result;
231
+ if (action === 'review' || action === 'retry') {
232
+ const candidateId = id || original?.candidate?.candidateId;
233
+ result = await api(`/api/project-reconciliation/${encodeURIComponent(candidateId)}/review`, {});
234
+ } else if (action === 'locate') {
235
+ result = await api(`/api/project-reconciliation/${encodeURIComponent(id)}/choose`, {});
236
+ if (result.cancelled) return;
237
+ } else if (action === 'show') {
238
+ await api(`/api/project-reconciliation/${encodeURIComponent(original.candidate.candidateId)}/open`, {});
239
+ return;
240
+ } else if (action === 'import') {
241
+ result = await api(`/api/project-reconciliation/${encodeURIComponent(original.candidate.candidateId)}/import`, { reviewId: original.reviewId, name });
242
+ } else if (action === 'reconcile') {
243
+ result = await api(`/api/project-reconciliation/${encodeURIComponent(original.registration.registrationId)}/reconcile`, {
244
+ reviewId: original.reviewId, interpretation: original.interpretation === 'restore' ? 'restore' : 'move',
245
+ ...(original.ambiguous ? { acknowledgeAmbiguous: acknowledged } : {}),
246
+ });
247
+ }
248
+ if (request !== sequence || !sameRoot(root, currentRoot())) return;
249
+ if (action === 'import' || action === 'reconcile') {
250
+ review = null;
251
+ resetDraft();
252
+ if (window.flolessWorkspaces?.folderDecisionCompleted) window.flolessWorkspaces.folderDecisionCompleted(result, action)
253
+ .catch(() => showToast('The folder decision was saved, but the project list could not refresh. Reload to see it.', 'warn'));
254
+ else {
255
+ window.dispatchEvent(new CustomEvent('floless:projects-changed', { detail: { rootId: root.rootId, generation: root.generation } }));
256
+ showToast(`${action === 'import' ? 'Imported' : 'Project folder updated for'} “${result.project.name}”.`, 'ok');
257
+ }
258
+ data = null;
259
+ modal.classList.remove('show');
260
+ opener?.isConnected && opener.focus({ preventScroll: true });
261
+ load();
262
+ } else {
263
+ if (!sameRoot(result.root, root)) throw new Error('The Workspace directory changed. Check the project folder again.');
264
+ review = result;
265
+ if (draftScope !== reviewScope()) resetDraft();
266
+ }
267
+ } catch (error) { if (request === sequence) problem = error.message; }
268
+ finally {
269
+ if (decisionBusyOwner === request) {
270
+ decisionBusyOwner = null; render();
271
+ if (request === sequence && sameRoot(root, currentRoot()) && review !== original && modal.classList.contains('show')) section.querySelector('input, button')?.focus({ preventScroll: true });
272
+ }
273
+ }
274
+ }
275
+ async function retryRecovery(transactionId) {
276
+ if (decisionBusyOwner !== null) return;
277
+ const root = currentRoot(), pending = data?.pendingRecovery;
278
+ if (!sameRoot(data?.root, root) || pending?.transactionId !== transactionId) {
279
+ recoveryError = 'This folder recovery has changed. Check project folders to review its current state.'; render(); return;
280
+ }
281
+ cancelAutofocus(); captureDraft();
282
+ const request = ++sequence;
283
+ decisionBusyOwner = request; recoveryBusyTransaction = transactionId;
284
+ recoveryError = ''; recoveryResult = null; render();
285
+ let settled = false;
286
+ try {
287
+ const result = await api('/api/project-reconciliation/recover', { transactionId });
288
+ if (request !== sequence || !sameRoot(root, currentRoot()) || !sameRoot(result.root, root)) return;
289
+ // A background observation can reveal a newer transaction; never replace or focus it from this reply.
290
+ if (data?.pendingRecovery && data.pendingRecovery.transactionId !== transactionId) return;
291
+ if (!['none', 'committed', 'rolled-back', 'needs-restoration'].includes(result.outcome)) throw new Error('FloLess could not confirm the recovery result. Check project folders and try again.');
292
+ data = { ...data, root, pendingRecovery: result.pending || null };
293
+ const message = result.outcome === 'committed' ? 'Folder recovery completed.'
294
+ : result.outcome === 'rolled-back' ? 'The interrupted folder change was cancelled.'
295
+ : result.outcome === 'needs-restoration' ? 'Recovery still needs your help.'
296
+ : result.pending ? 'Folder recovery is still waiting.' : 'No folder recovery is waiting.';
297
+ recoveryResult = { root, transactionId, source: pending.source, destination: pending.destination,
298
+ message: message + (result.outcome === 'needs-restoration' && result.pending?.userMessage ? ` ${result.pending.userMessage}` : '') };
299
+ settled = true;
300
+ if (result.outcome === 'committed' || result.outcome === 'rolled-back') window.dispatchEvent(new CustomEvent('floless:projects-changed', { detail: { rootId: root.rootId, generation: root.generation } }));
301
+ } catch (error) {
302
+ if (request === sequence && sameRoot(root, currentRoot()) && (!data?.pendingRecovery || data.pendingRecovery.transactionId === transactionId)) recoveryError = error.message;
303
+ } finally {
304
+ if (decisionBusyOwner === request) {
305
+ decisionBusyOwner = null; recoveryBusyTransaction = null; render();
306
+ if (request === sequence && sameRoot(root, currentRoot()) && modal.classList.contains('show')) {
307
+ const retry = Array.from(section.querySelectorAll('[data-folder-action="recover"]')).find((target) => target.dataset.folderId === transactionId);
308
+ if (retry) retry.focus({ preventScroll: true });
309
+ else if (settled) section.querySelector('#project-folder-recovery-result')?.focus({ preventScroll: true });
310
+ }
311
+ }
312
+ }
313
+ }
314
+ section.addEventListener('click', (event) => {
315
+ const target = event.target.closest('[data-folder-action]');
316
+ if (target) act(target.dataset.folderAction, target.dataset.folderId);
317
+ });
318
+ section.addEventListener('input', captureDraft);
319
+ section.addEventListener('change', captureDraft);
320
+ modal.addEventListener('pointerdown', cancelAutofocus);
321
+ modal.addEventListener('keydown', (event) => {
322
+ if (!modal.classList.contains('show')) return;
323
+ cancelAutofocus();
324
+ if (event.key === 'Escape' && busy) { event.preventDefault(); event.stopPropagation(); return; }
325
+ if (event.key !== 'Tab') return;
326
+ const controls = Array.from(modal.querySelectorAll('button:not([disabled]), input:not([disabled]), [tabindex="0"]'))
327
+ .filter((control) => !control.closest('[hidden]') && (!control.getClientRects || control.getClientRects().length > 0));
328
+ const first = controls[0], last = controls[controls.length - 1];
329
+ if (event.shiftKey && (document.activeElement === first || !modal.contains(document.activeElement))) {
330
+ event.preventDefault(); last?.focus();
331
+ } else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first?.focus(); }
332
+ });
333
+ document.addEventListener('click', (event) => {
334
+ if (event.target.closest('#workspace-root-cancel')) {
335
+ cancelAutofocus();
336
+ sequence++; listSequence++; listBusyOwner = null; decisionBusyOwner = null; recoveryBusyTransaction = null;
337
+ review = null; resetDraft(); render();
338
+ }
339
+ if (event.target.closest('[data-folder-notice]')) open();
340
+ });
341
+ let observedRoot = null;
342
+ window.addEventListener('floless:workspace-root-state', () => {
343
+ const root = currentRoot();
344
+ if (sameRoot(observedRoot, root)) return;
345
+ observedRoot = root;
346
+ cancelAutofocus();
347
+ sequence++; listSequence++; listBusyOwner = null; decisionBusyOwner = null; recoveryBusyTransaction = null;
348
+ recoveryError = ''; recoveryResult = null;
349
+ data = null; review = null; resetDraft(); render();
350
+ if (root) load();
351
+ });
352
+ window.addEventListener('floless:projects-changed', (event) => { if (event.detail?.kind !== 'metadata') load(); });
353
+ window.flolessProjectReconciliation = { open, openRegistration, paintNotice };
354
+ render();
355
+ // Boot inspection only. Saves never trigger this discovery projection.
356
+ window.flolessWorkspaceRoot.refresh().then(() => { observedRoot = currentRoot(); if (!data && !busy) load(); });
357
+ })();
@@ -0,0 +1,50 @@
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);