@floless/app 0.155.2 → 0.156.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 +376 -0
- package/dist/floless-server.cjs +100135 -86559
- package/dist/skills/floless-app-actions/SKILL.md +137 -0
- package/dist/skills/floless-app-approval/SKILL.md +8 -5
- package/dist/skills/floless-app-bridge/SKILL.md +12 -9
- package/dist/skills/floless-app-knowledge/SKILL.md +30 -13
- package/dist/skills/floless-app-new-workflow/SKILL.md +4 -4
- package/dist/skills/floless-app-onboarding/SKILL.md +1 -1
- package/dist/skills/floless-app-onboarding/references/aware-runtime.md +4 -4
- package/dist/skills/floless-app-queue/SKILL.md +10 -6
- package/dist/skills/floless-app-report-issue/SKILL.md +13 -10
- package/dist/skills/floless-app-rfi/SKILL.md +59 -68
- package/dist/skills/floless-app-routines/SKILL.md +19 -14
- package/dist/skills/floless-app-routines/references/routines-api.md +8 -2
- package/dist/skills/floless-app-workflows/SKILL.md +5 -4
- package/dist/web/agent-steps.js +933 -0
- package/dist/web/agents.js +5 -0
- package/dist/web/app.css +205 -3
- package/dist/web/app.js +1 -0
- package/dist/web/aware.js +584 -44
- package/dist/web/chat.css +9 -0
- package/dist/web/chat.js +195 -13
- package/dist/web/commands-shell.js +288 -1
- package/dist/web/index.html +52 -1
- package/dist/web/instructor.js +4 -2
- package/dist/web/leave-guard.js +4 -2
- package/dist/web/left-pane.js +8 -3
- package/dist/web/model-revit-module.js +15 -0
- package/dist/web/model-viewport-revit-adapter.js +3 -1
- package/dist/web/pages.js +27 -3
- package/dist/web/panels.js +3 -3
- package/dist/web/project-reconciliation.js +357 -0
- package/dist/web/revit-editor.js +116 -27
- package/dist/web/terminal-requests.js +541 -0
- package/dist/web/tool-updates.js +147 -13
- package/dist/web/workspaces.js +213 -12
- package/launch.mjs +80 -2
- package/package.json +1 -1
package/dist/web/pages.js
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
function sourceText(source) {
|
|
47
47
|
if (!source) return '';
|
|
48
48
|
if (source.kind === 'chat') return 'Made in AI Chat';
|
|
49
|
-
if (source.kind === 'workflow') return 'From a workflow';
|
|
49
|
+
if (source.kind === 'workflow') return 'From a workflow run';
|
|
50
50
|
return 'Added by the AI';
|
|
51
51
|
}
|
|
52
52
|
const versionsText = (n) => `${n} version${n === 1 ? '' : 's'}`;
|
|
@@ -80,6 +80,16 @@
|
|
|
80
80
|
</div>`;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/** A workflow's Page (#2262 slice 3a), kept in the workflow's own folder: a normal row, or — when its record cannot
|
|
84
|
+
* be read — a row that says so under the workflow's name. Never hidden; deleting it is the Page viewer's job. */
|
|
85
|
+
function workflowRowHtml(w) {
|
|
86
|
+
if (w.page && typeof w.home === 'string') return rowHtml(w.home, w.page);
|
|
87
|
+
return `<div class="pg-row pg-row-damaged" role="listitem">
|
|
88
|
+
<div class="pg-row-text"><span class="pg-row-title">${esc(w.workflowName)}: its Page can’t be opened</span>
|
|
89
|
+
<span class="pg-row-meta">${esc(w.note || 'FloLess couldn’t read this workflow’s Page.')}</span></div>
|
|
90
|
+
</div>`;
|
|
91
|
+
}
|
|
92
|
+
|
|
83
93
|
/**
|
|
84
94
|
* Render the Pages of one home into `container`. `opts.hideWhenEmpty` (the Workspaces landing) renders
|
|
85
95
|
* nothing at all for a home with no Pages, so the landing is not cluttered with an empty section.
|
|
@@ -104,7 +114,10 @@
|
|
|
104
114
|
}
|
|
105
115
|
if (container.dataset.pagesToken !== token) return;
|
|
106
116
|
const pages = Array.isArray(body.pages) ? body.pages : [];
|
|
107
|
-
|
|
117
|
+
// The Pages this home's workflows keep in their own folders (each names its own home).
|
|
118
|
+
const fromWorkflows = Array.isArray(body.workflowPages) ? body.workflowPages.filter((w) => w && typeof w.workflowName === 'string') : [];
|
|
119
|
+
const workflowsNote = typeof body.workflowPagesNote === 'string' ? body.workflowPagesNote : '';
|
|
120
|
+
if (!pages.length && !fromWorkflows.length && !workflowsNote) {
|
|
108
121
|
container.innerHTML = opts.hideWhenEmpty ? '' : `${opts.headHtml || ''}<div class="pg-empty">
|
|
109
122
|
<p class="pg-empty-title">No Pages yet</p>
|
|
110
123
|
<p>Reports, dashboards and summaries saved in this home appear here with their versions.</p>
|
|
@@ -114,12 +127,21 @@
|
|
|
114
127
|
// Landing rows remain usable during loading: preserve the person's latest row, not the
|
|
115
128
|
// one focused when the request began. Other surfaces replace rows with Loading immediately.
|
|
116
129
|
if (opts.hideWhenEmpty) focusedPageCommand = container.contains(document.activeElement) ? document.activeElement?.getAttribute('data-command-id') : null;
|
|
117
|
-
|
|
130
|
+
const own = pages.length ? `<div class="pg-list" role="list" aria-label="${esc(opts.label || 'Pages')}">${pages.map((p) => rowHtml(body.home || home, p)).join('')}</div>` : '';
|
|
131
|
+
const workflows = fromWorkflows.length || workflowsNote ? `<div class="pg-group-label">From workflows</div>
|
|
132
|
+
${workflowsNote ? `<p class="pg-empty">${esc(workflowsNote)}</p>` : ''}
|
|
133
|
+
${fromWorkflows.length ? `<div class="pg-list" role="list" aria-label="Pages from workflows">${fromWorkflows.map(workflowRowHtml).join('')}</div>` : ''}` : '';
|
|
134
|
+
container.innerHTML = `${opts.headHtml || ''}${own}${workflows}`;
|
|
118
135
|
if (focusedPageCommand && document.activeElement === document.body && container.isConnected) {
|
|
119
136
|
[...container.querySelectorAll('[data-command-id]')].find((el) => el.getAttribute('data-command-id') === focusedPageCommand)?.focus({ preventScroll: true });
|
|
120
137
|
}
|
|
121
138
|
}
|
|
122
139
|
|
|
140
|
+
/** Tell the rest of the window a Page is gone, so nothing keeps offering to open it (the report viewer's links). */
|
|
141
|
+
function announceDeleted(home, id) {
|
|
142
|
+
window.dispatchEvent(new CustomEvent('floless:page-deleted', { detail: { home, id } }));
|
|
143
|
+
}
|
|
144
|
+
|
|
123
145
|
function refreshLists() {
|
|
124
146
|
for (const e of [...lists]) {
|
|
125
147
|
if (!e.container.isConnected) { lists.delete(e); continue; }
|
|
@@ -143,6 +165,7 @@
|
|
|
143
165
|
if (!ok) return;
|
|
144
166
|
try {
|
|
145
167
|
await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
168
|
+
announceDeleted(home, id);
|
|
146
169
|
toast('Page deleted.', 'ok');
|
|
147
170
|
} catch (err) {
|
|
148
171
|
toast(`FloLess couldn’t delete it. ${err?.body?.error || 'Try again in a moment.'}`, 'warn');
|
|
@@ -553,6 +576,7 @@
|
|
|
553
576
|
toast(`FloLess couldn’t delete this Page. ${err?.body?.error || 'Try again in a moment.'}`, 'warn');
|
|
554
577
|
return;
|
|
555
578
|
}
|
|
579
|
+
announceDeleted(view.home, p.id);
|
|
556
580
|
closeViewer();
|
|
557
581
|
toast(`Deleted “${p.title}”.`, 'ok');
|
|
558
582
|
refreshLists();
|
package/dist/web/panels.js
CHANGED
|
@@ -642,7 +642,7 @@
|
|
|
642
642
|
} catch (err) {
|
|
643
643
|
const b = err && err.body;
|
|
644
644
|
if (b) setUndoRedoEnabled(b.canUndo, b.canRedo);
|
|
645
|
-
if (b && b.
|
|
645
|
+
if (b && b.code === 'nothing-to-undo') showToast('Nothing to undo', 'info');
|
|
646
646
|
else showToast('We couldn’t undo that change. Nothing else was changed. Try again.', 'warn');
|
|
647
647
|
return false;
|
|
648
648
|
}
|
|
@@ -658,7 +658,7 @@
|
|
|
658
658
|
} catch (err) {
|
|
659
659
|
const b = err && err.body;
|
|
660
660
|
if (b) setUndoRedoEnabled(b.canUndo, b.canRedo);
|
|
661
|
-
if (b && b.
|
|
661
|
+
if (b && b.code === 'nothing-to-redo') showToast('Nothing to redo', 'info');
|
|
662
662
|
else showToast('We couldn’t redo that change. Nothing else was changed. Try again.', 'warn');
|
|
663
663
|
return false;
|
|
664
664
|
}
|
|
@@ -712,7 +712,7 @@
|
|
|
712
712
|
} catch (err) {
|
|
713
713
|
const b = err && err.body;
|
|
714
714
|
if (b) setUndoRedoEnabled(b.canUndo, b.canRedo);
|
|
715
|
-
if (b && b.
|
|
715
|
+
if (b && b.code === 'already-default') showToast('Already the default dashboard', 'info');
|
|
716
716
|
else showToast('We couldn’t reset the dashboard. Your current layout is still here. Try again.', 'warn');
|
|
717
717
|
}
|
|
718
718
|
};
|
|
@@ -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) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[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
|
+
})();
|