@floless/app 0.169.0 → 0.171.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/dist/floless-server.cjs +65531 -43728
- package/dist/schemas/drawing-check.profile.v1.schema.json +12 -2
- package/dist/schemas/steel.model.v2.schema.json +196 -4
- package/dist/skills/floless-app-bridge/SKILL.md +3 -3
- package/dist/skills/floless-app-knowledge/SKILL.md +46 -15
- package/dist/skills/floless-app-new-workflow/SKILL.md +8 -1
- package/dist/skills/floless-app-onboarding/SKILL.md +5 -4
- package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +0 -3
- package/dist/skills/floless-app-queue/SKILL.md +2 -3
- package/dist/skills/floless-app-report-issue/SKILL.md +2 -2
- package/dist/skills/floless-app-routines/SKILL.md +2 -2
- package/dist/skills/floless-app-routines/references/routines-api.md +20 -8
- package/dist/skills/floless-app-steel-model/SKILL.md +42 -39
- package/dist/skills/floless-app-steel-model/references/custom-connections.md +47 -0
- package/dist/skills/floless-app-steel-model/references/custom-sections.md +32 -0
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +31 -1
- package/dist/skills/floless-app-ui/SKILL.md +71 -126
- package/dist/skills/floless-app-workflows/SKILL.md +22 -3
- package/dist/skills/floless-app-workflows/references/agent-steps.md +40 -6
- package/dist/skills/floless-app-workflows/references/exec-contract.md +27 -0
- package/dist/skills/floless-app-workflows/references/script-runner.md +105 -0
- package/dist/web/add-ons.js +407 -0
- package/dist/web/agent-steps.js +89 -18
- package/dist/web/agents.js +32 -22
- package/dist/web/analytics.js +1 -1
- package/dist/web/app.css +331 -190
- package/dist/web/app.js +33 -13
- package/dist/web/aware.js +926 -218
- package/dist/web/chat.css +6 -1
- package/dist/web/chat.js +316 -112
- package/dist/web/checkpoint-standard.js +5 -3
- package/dist/web/commands-drawing-check.js +1 -0
- package/dist/web/commands-filter.js +23 -0
- package/dist/web/commands-shell.js +479 -78
- package/dist/web/commands-steel.js +69 -2
- package/dist/web/commands-tekla-parser.js +23 -0
- package/dist/web/connections.js +14 -3
- package/dist/web/drawing-check-editor.js +352 -88
- package/dist/web/failure-copy.js +33 -2
- package/dist/web/filter-ai-proposal.js +11 -8
- package/dist/web/flo-3d.js +1 -1
- package/dist/web/guide.js +36 -29
- package/dist/web/index.html +98 -57
- package/dist/web/instructor.js +101 -17
- package/dist/web/kb-categories.js +64 -7
- package/dist/web/left-pane.js +4 -1
- package/dist/web/local-discovery.js +8 -7
- package/dist/web/missed-routines.js +239 -0
- package/dist/web/model-change-findings.js +430 -0
- package/dist/web/model-change-review.js +414 -0
- package/dist/web/model-editor-steel-adapter.js +2 -2
- package/dist/web/model-measure.js +6 -0
- package/dist/web/model-spatial-panel.js +19 -4
- package/dist/web/model-spatial-tools.js +3 -3
- package/dist/web/model-viewport-revit-adapter.js +3 -3
- package/dist/web/origin-rule.js +155 -0
- package/dist/web/project-access.js +1 -1
- package/dist/web/project-history.js +7 -1
- package/dist/web/project-modules.js +2 -2
- package/dist/web/project-rfis.js +6 -1
- package/dist/web/project-workflows.js +2 -2
- package/dist/web/revit-editor.css +85 -0
- package/dist/web/revit-editor.js +58 -9
- package/dist/web/run-history.js +12 -1
- package/dist/web/sha256-sync.js +62 -0
- package/dist/web/steel-3d-core.js +46 -9
- package/dist/web/steel-3d-flo.js +153 -7
- package/dist/web/steel-3d-view.js +33 -5
- package/dist/web/steel-ai-marks.js +3 -1
- package/dist/web/steel-custom-connection.js +161 -0
- package/dist/web/steel-custom-sections.js +1796 -0
- package/dist/web/steel-editor.html +732 -161
- package/dist/web/steel-environments.js +297 -0
- package/dist/web/steel-filter-usage.js +299 -0
- package/dist/web/steel-filter.html +104 -6
- package/dist/web/steel-model-v2-client-validation.js +11 -1
- package/dist/web/steel-model-v2-commands.js +116 -13
- package/dist/web/steel-model-v2-projection.js +1 -1
- package/dist/web/steel-read-confidence.js +1 -56
- package/dist/web/step-rename.js +3 -2
- package/dist/web/tekla-editor.html +1 -0
- package/dist/web/terminal-requests.js +1 -1
- package/dist/web/tool-updates.js +7 -6
- package/dist/web/workspaces.js +1968 -138
- package/launch.mjs +87 -9
- package/package.json +4 -1
- package/dist/web/panels.js +0 -831
package/dist/web/panels.js
DELETED
|
@@ -1,831 +0,0 @@
|
|
|
1
|
-
/* ============================================================================
|
|
2
|
-
* panels.js — Custom Panels: renders ~/.floless/ui/extensions.json (the
|
|
3
|
-
* declarative descriptor the terminal AI composes) into the Dashboard view and
|
|
4
|
-
* extra Inspect tabs. See docs/superpowers/specs/2026-06-10-declarative-ui-
|
|
5
|
-
* extensions-design.md.
|
|
6
|
-
*
|
|
7
|
-
* Pure renderer, by contract: blocks come from the shipped catalog, data payloads
|
|
8
|
-
* arrive pre-resolved from GET /api/extensions, and EVERY interpolated string is
|
|
9
|
-
* escaped — no AI/user-authored HTML ever reaches the DOM (text renders as text).
|
|
10
|
-
* Loaded AFTER app.js + aware.js: reuses their globals (state, renderInspect,
|
|
11
|
-
* escapeHtml, escapeAttr, showToast) and the minimal window.flolessBridge seams
|
|
12
|
-
* (api, showHtmlReport, …) instead of duplicating run/report plumbing.
|
|
13
|
-
* ========================================================================== */
|
|
14
|
-
(() => {
|
|
15
|
-
const bridge = window.flolessBridge || {};
|
|
16
|
-
// aware.js always loads first and provides api; this fallback only guards a
|
|
17
|
-
// pathological load order so the file can't throw at parse time.
|
|
18
|
-
const api = bridge.api || (async (path, opts = {}) => {
|
|
19
|
-
await globalThis.flolessStartupAdmission?.admit(path, { method: opts?.method, signal: opts?.signal });
|
|
20
|
-
const { timeoutMs, ...requestOptions } = opts;
|
|
21
|
-
if (!requestOptions.signal && Number.isFinite(timeoutMs)) requestOptions.signal = AbortSignal.timeout(timeoutMs);
|
|
22
|
-
const res = await fetch(path, { headers: { 'content-type': 'application/json' }, ...requestOptions });
|
|
23
|
-
const body = await res.json().catch(() => ({ ok: false, code: 'response-unreadable' }));
|
|
24
|
-
if (!res.ok || body.ok === false) {
|
|
25
|
-
// #3097: the server's own sentence when it wrote one, else the shared one; never "HTTP <status>".
|
|
26
|
-
const readOnly = /^(GET|HEAD)$/.test(String(requestOptions.method || 'GET').toUpperCase());
|
|
27
|
-
const err = new Error(personText(body) || failureCopy({ status: res.status, body }, { retrySafe: readOnly }).text);
|
|
28
|
-
err.body = body;
|
|
29
|
-
err.status = res.status;
|
|
30
|
-
throw err;
|
|
31
|
-
}
|
|
32
|
-
return body;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const $canvasMain = document.getElementById('canvas-main');
|
|
36
|
-
const $dashboard = document.getElementById('dashboard');
|
|
37
|
-
const $dashDot = document.getElementById('dash-dot'); // the "updated" dot, now in the ≡ menu item
|
|
38
|
-
const $menuBtn = document.getElementById('menu-btn'); // hosts the dashboard-updated badge (#149)
|
|
39
|
-
const $menuViewLabel = document.getElementById('menu-view-label'); // the ≡ "Switch to Dashboard/Canvas" label
|
|
40
|
-
const $extBadge = document.getElementById('ext-badge');
|
|
41
|
-
const $extMenu = document.getElementById('ext-menu');
|
|
42
|
-
const $extUndo = document.getElementById('ext-undo');
|
|
43
|
-
const $extRedo = document.getElementById('ext-redo');
|
|
44
|
-
const $extHistory = document.getElementById('ext-history');
|
|
45
|
-
const $centerName = document.getElementById('center-panel-name');
|
|
46
|
-
const $centerRole = document.getElementById('center-panel-role');
|
|
47
|
-
const $resetModal = document.getElementById('ext-reset-modal');
|
|
48
|
-
const $menuViewItem = document.getElementById('menu-view-switch'); // the ≡ view-switch row itself
|
|
49
|
-
if (!$dashboard) return; // markup absent — nothing to wire
|
|
50
|
-
|
|
51
|
-
// ── Dashboard UI availability gate (#902) ───────────────────────────────────
|
|
52
|
-
// The Dashboard is TEMPORARILY hidden from Workflows: at this stage it adds more
|
|
53
|
-
// product noise than value. This is an exposure gate, not a removal — the
|
|
54
|
-
// descriptor, its store and API, the block renderers, and every user's saved
|
|
55
|
-
// panels and history are all still here and still working. Flipping this one flag
|
|
56
|
-
// back to true is the whole of re-enabling it, which is why every suppression
|
|
57
|
-
// below reads from it rather than deleting the code it guards.
|
|
58
|
-
const DASHBOARD_UI_ENABLED = false;
|
|
59
|
-
|
|
60
|
-
const LS_VIEW = 'floless:view';
|
|
61
|
-
let view = 'canvas';
|
|
62
|
-
// The persisted preference is only honoured while the surface is exposed, so a user
|
|
63
|
-
// whose last session ended on the Dashboard opens on Canvas instead of landing on a
|
|
64
|
-
// view they can no longer leave. The stored value is deliberately NOT rewritten:
|
|
65
|
-
// re-enabling the feature restores each user's own last view.
|
|
66
|
-
try {
|
|
67
|
-
if (DASHBOARD_UI_ENABLED && localStorage.getItem(LS_VIEW) === 'dashboard') view = 'dashboard';
|
|
68
|
-
} catch { /* private mode */ }
|
|
69
|
-
|
|
70
|
-
// Hide the ≡ "Switch to Dashboard" row. Hidden, not removed: the markup and its
|
|
71
|
-
// data-command-id stay in index.html, so re-enabling needs no markup change.
|
|
72
|
-
if (!DASHBOARD_UI_ENABLED && $menuViewItem) $menuViewItem.hidden = true;
|
|
73
|
-
|
|
74
|
-
// Hiding the DOM is only half of it. The Instructor's `?` / "see all" sheet
|
|
75
|
-
// catalogues every REGISTERED command and synthesizes a row for one with no visible
|
|
76
|
-
// carrier — on purpose, so it can tell you what FloLess does on a screen you are not
|
|
77
|
-
// on. A gated-off feature is not that case: leaving those registrations in place
|
|
78
|
-
// keeps advertising controls nothing can reach.
|
|
79
|
-
//
|
|
80
|
-
// The set is DERIVED from the four containers that hold Dashboard-only controls
|
|
81
|
-
// rather than listed by hand, so a control added to the Customized menu later is
|
|
82
|
-
// retired with the rest instead of quietly reappearing in the sheet. It cannot
|
|
83
|
-
// over-reach either: it walks only these roots.
|
|
84
|
-
const DASHBOARD_COMMAND_ROOTS = [
|
|
85
|
-
'#menu-view-switch', // the ≡ Canvas|Dashboard switch
|
|
86
|
-
'#ext-badge', // the Customized badge
|
|
87
|
-
'#ext-menu', // …and its Undo · Redo · Reset menu
|
|
88
|
-
'#ext-reset-modal', // the Reset-to-default confirm
|
|
89
|
-
];
|
|
90
|
-
// Deferred to DOMContentLoaded because commands-shell.js, which defines these,
|
|
91
|
-
// loads AFTER this file — retiring them now would find nothing and silently no-op.
|
|
92
|
-
if (!DASHBOARD_UI_ENABLED) {
|
|
93
|
-
const retireDashboardCommands = () => {
|
|
94
|
-
if (!window.Commands || !window.Commands.retire) return;
|
|
95
|
-
// A carrier may be `template#instance`; the registry is keyed by template.
|
|
96
|
-
const templateOf = (el) => {
|
|
97
|
-
const raw = el.getAttribute('data-command-id');
|
|
98
|
-
const parts = raw && window.Commands.split ? window.Commands.split(raw) : null;
|
|
99
|
-
return parts && parts.template ? parts.template : null;
|
|
100
|
-
};
|
|
101
|
-
const candidates = new Set();
|
|
102
|
-
for (const sel of DASHBOARD_COMMAND_ROOTS) {
|
|
103
|
-
const root = document.querySelector(sel);
|
|
104
|
-
if (!root) continue;
|
|
105
|
-
for (const el of [root, ...root.querySelectorAll('[data-command-id]')]) {
|
|
106
|
-
const t = templateOf(el);
|
|
107
|
-
if (t) candidates.add(t);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// A template that ALSO has a carrier outside these roots is shared, and stays.
|
|
111
|
-
// `shell.dialog-cancel` is the reason this pass exists: one registration serves the
|
|
112
|
-
// Cancel button of every dialog in FloLess, including the Reset-to-default confirm,
|
|
113
|
-
// so retiring it on the Dashboard's account would take Cancel guidance away from all
|
|
114
|
-
// of them. Only a command that lives NOWHERE else is Dashboard-only.
|
|
115
|
-
for (const el of document.querySelectorAll('[data-command-id]')) {
|
|
116
|
-
if (DASHBOARD_COMMAND_ROOTS.some((sel) => el.closest(sel))) continue;
|
|
117
|
-
const t = templateOf(el);
|
|
118
|
-
if (t) candidates.delete(t);
|
|
119
|
-
}
|
|
120
|
-
for (const t of candidates) window.Commands.retire(t);
|
|
121
|
-
};
|
|
122
|
-
if (document.readyState === 'loading') {
|
|
123
|
-
document.addEventListener('DOMContentLoaded', retireDashboardCommands, { once: true });
|
|
124
|
-
} else {
|
|
125
|
-
retireDashboardCommands();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
let booted = false; // flips in boot() — called by aware.js once licensed + AWARE-ready
|
|
130
|
-
let ext = { descriptor: null, validation: null, data: {} };
|
|
131
|
-
let pendingCustomize = 0; // queued ui-customize requests (the composer's "waiting" line)
|
|
132
|
-
// run-app gate cache: appId -> { state, runnable, runState, missing }. Cleared on
|
|
133
|
-
// every refetch so a Compile elsewhere re-arms the buttons.
|
|
134
|
-
const appGate = new Map();
|
|
135
|
-
const RUN_APP_RE = /^run-app:([A-Za-z0-9._-]+)$/;
|
|
136
|
-
|
|
137
|
-
// ── descriptor accessors (defensive — the store is loose by design) ─────────
|
|
138
|
-
function allPanels() {
|
|
139
|
-
const d = ext.descriptor;
|
|
140
|
-
if (!d || !Array.isArray(d.panels)) return [];
|
|
141
|
-
return d.panels.filter((p) => p && typeof p === 'object' && !Array.isArray(p));
|
|
142
|
-
}
|
|
143
|
-
// v1 honors two slots. Anything else lands on the Dashboard rather than
|
|
144
|
-
// vanishing — a panel the user asked for must never silently disappear.
|
|
145
|
-
// Gated at the accessor so BOTH consumers — the Inspector tab strip and the tab body
|
|
146
|
-
// renderer — go dark together (#902). A contributed tab is Dashboard content wearing
|
|
147
|
-
// an Inspector hat; it must not survive the surface it belongs to.
|
|
148
|
-
const inspectPanels = () => (DASHBOARD_UI_ENABLED ? allPanels().filter((p) => p.slot === 'inspect-tab') : []);
|
|
149
|
-
const dashboardPanels = () => allPanels().filter((p) => p.slot !== 'inspect-tab');
|
|
150
|
-
const descriptorInvalid = () => !!(ext.validation && ext.validation.valid === false);
|
|
151
|
-
|
|
152
|
-
// ── view toggle (Canvas | Dashboard) ─────────────────────────────────────────
|
|
153
|
-
// The "dashboard updated" signal: a dot on the ≡ menu's view-switch item AND a badge on
|
|
154
|
-
// the ≡ hamburger, so it's visible without opening the menu (#149 — the old toggle that
|
|
155
|
-
// hosted the dot is gone).
|
|
156
|
-
function setDashUpdated(on) {
|
|
157
|
-
// One choke point for both signals, so gating here covers every caller: while the
|
|
158
|
-
// Dashboard is hidden there is nowhere for "updated" to send anyone (#902).
|
|
159
|
-
if (!DASHBOARD_UI_ENABLED) on = false;
|
|
160
|
-
if ($dashDot) $dashDot.hidden = !on;
|
|
161
|
-
if ($menuBtn) $menuBtn.classList.toggle('has-dash-update', on);
|
|
162
|
-
}
|
|
163
|
-
function applyView() {
|
|
164
|
-
const dash = view === 'dashboard';
|
|
165
|
-
if ($canvasMain) $canvasMain.classList.toggle('view-dashboard', dash);
|
|
166
|
-
$dashboard.hidden = !dash;
|
|
167
|
-
// The Canvas|Dashboard toggle now lives in the ≡ menu as one contextual item (#149):
|
|
168
|
-
// its label names the OTHER view — the destination of the switch.
|
|
169
|
-
if ($menuViewLabel) $menuViewLabel.textContent = dash ? 'Switch to Canvas' : 'Switch to Dashboard';
|
|
170
|
-
if ($centerName) $centerName.textContent = dash ? 'Dashboard' : 'Canvas';
|
|
171
|
-
if ($centerRole) $centerRole.textContent = dash ? 'your panels · composed by your terminal AI' : 'transparency layer · read-mostly';
|
|
172
|
-
if (dash) setDashUpdated(false); // seen — clear the "updated" signal
|
|
173
|
-
}
|
|
174
|
-
function setView(v) {
|
|
175
|
-
view = v === 'dashboard' ? 'dashboard' : 'canvas';
|
|
176
|
-
try { localStorage.setItem(LS_VIEW, view); } catch { /* private mode */ }
|
|
177
|
-
applyView();
|
|
178
|
-
if (view === 'dashboard') renderDashboard();
|
|
179
|
-
}
|
|
180
|
-
// The only caller of setView. Gated here rather than inside setView so a hidden
|
|
181
|
-
// Dashboard never REWRITES `floless:view` to 'canvas' — the user's stored preference
|
|
182
|
-
// has to survive the gate to be worth restoring when it lifts (#902).
|
|
183
|
-
function toggleView() {
|
|
184
|
-
if (!DASHBOARD_UI_ENABLED) return;
|
|
185
|
-
setView(view === 'dashboard' ? 'canvas' : 'dashboard');
|
|
186
|
-
}
|
|
187
|
-
// The ≡ menu's "Switch to Dashboard/Canvas" item drives the view (the header toggle was
|
|
188
|
-
// removed in #149). handleMenuAction lives in app.js and is already wrapped in aware.js
|
|
189
|
-
// for graft/bake; wrap once more here for view-switch and fall through for everything else.
|
|
190
|
-
const _prevHandleMenuAction = handleMenuAction;
|
|
191
|
-
handleMenuAction = function (action) {
|
|
192
|
-
if (action === 'view-switch') { toggleView(); return; }
|
|
193
|
-
_prevHandleMenuAction(action);
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
// ── block renderers (all output escaped; placeholders over errors) ──────────
|
|
197
|
-
const payloadFor = (source) => (typeof source === 'string' ? ext.data[source] : undefined);
|
|
198
|
-
function rowsFrom(payload) {
|
|
199
|
-
if (Array.isArray(payload)) return payload;
|
|
200
|
-
if (payload && typeof payload === 'object' && Array.isArray(payload.rows)) return payload.rows;
|
|
201
|
-
return null;
|
|
202
|
-
}
|
|
203
|
-
const fmtVal = (v) =>
|
|
204
|
-
typeof v === 'number' || typeof v === 'string' ? String(v) : v == null ? '—' : JSON.stringify(v);
|
|
205
|
-
|
|
206
|
-
function placeholderHtml(msg) {
|
|
207
|
-
return `<div class="ext-placeholder">${escapeHtml(msg)}</div>`;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function statHtml(b) {
|
|
211
|
-
return `<div class="ext-stat">` +
|
|
212
|
-
`<div class="ext-stat-label">${escapeHtml(String(b.label ?? ''))}</div>` +
|
|
213
|
-
`<div class="ext-stat-value">${escapeHtml(fmtVal(b.value))}</div>` +
|
|
214
|
-
(b.hint != null ? `<div class="ext-stat-hint">${escapeHtml(String(b.hint))}</div>` : '') +
|
|
215
|
-
`</div>`;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Columns: the declared list wins; otherwise the union of keys from a row sample.
|
|
219
|
-
function columnsFor(rows, declared) {
|
|
220
|
-
if (Array.isArray(declared) && declared.length && declared.every((c) => typeof c === 'string')) return declared;
|
|
221
|
-
const cols = [];
|
|
222
|
-
for (const r of rows.slice(0, 20)) for (const k of Object.keys(r)) if (!cols.includes(k)) cols.push(k);
|
|
223
|
-
return cols;
|
|
224
|
-
}
|
|
225
|
-
// Sort mirroring html-report's #210 semantics: numbers compare numerically,
|
|
226
|
-
// everything else as strings, and rows MISSING the key sort last — under BOTH
|
|
227
|
-
// directions (the 0.62 fix).
|
|
228
|
-
function sortRows(rows, key, desc) {
|
|
229
|
-
const missing = (v) => v === undefined || v === null || v === '';
|
|
230
|
-
return rows.slice().sort((a, b) => {
|
|
231
|
-
const va = a ? a[key] : undefined;
|
|
232
|
-
const vb = b ? b[key] : undefined;
|
|
233
|
-
if (missing(va) && missing(vb)) return 0;
|
|
234
|
-
if (missing(va)) return 1;
|
|
235
|
-
if (missing(vb)) return -1;
|
|
236
|
-
const na = typeof va === 'number' ? va : Number(va);
|
|
237
|
-
const nb = typeof vb === 'number' ? vb : Number(vb);
|
|
238
|
-
const cmp = !Number.isNaN(na) && !Number.isNaN(nb) ? na - nb : String(va).localeCompare(String(vb));
|
|
239
|
-
return desc ? -cmp : cmp;
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
const MAX_ROWS = 200; // defensive cap; a panel is a glance, not a data dump
|
|
243
|
-
|
|
244
|
-
// The last run's trace exists but the server couldn't parse it (corrupt/truncated):
|
|
245
|
-
// distinct from "no run yet" — don't tell the user to run something that DID run.
|
|
246
|
-
const traceUnreadable = (payload) =>
|
|
247
|
-
!!(payload && typeof payload === 'object' && payload.traceUnreadable === true);
|
|
248
|
-
// #2644: a Drawing Checker or Steel Model workflow this account's plan does not include: its run is not shown, and
|
|
249
|
-
// the panel says why in the module's own words (never "run it", which would not help).
|
|
250
|
-
function moduleRefusedHtml(payload) {
|
|
251
|
-
if (!payload || typeof payload !== 'object' || payload.moduleRefused !== true) return null;
|
|
252
|
-
const sentence = typeof payload.userMessage === 'string' && payload.userMessage.trim() ? payload.userMessage.trim()
|
|
253
|
-
: 'this workflow is part of a module this account’s plan does not include.';
|
|
254
|
-
return placeholderHtml(`Locked: ${sentence}`);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function tableHtml(b) {
|
|
258
|
-
const payload = payloadFor(b.source);
|
|
259
|
-
const locked = moduleRefusedHtml(payload);
|
|
260
|
-
if (locked) return locked;
|
|
261
|
-
if (traceUnreadable(payload)) {
|
|
262
|
-
return placeholderHtml(`The last run of “${String(b.source ?? '')}” finished, but its trace couldn’t be read — re-run to refresh this table.`);
|
|
263
|
-
}
|
|
264
|
-
const rows = rowsFrom(payload);
|
|
265
|
-
if (!rows || !rows.length) {
|
|
266
|
-
if (payload && typeof payload === 'object' && !Array.isArray(payload)) {
|
|
267
|
-
// A run-output envelope with no row data: the run happened, it just isn't
|
|
268
|
-
// tabular — say so (and point at the block that fits) instead of "run it".
|
|
269
|
-
if ('rows' in payload || 'html' in payload) {
|
|
270
|
-
return placeholderHtml(`The last run of “${String(b.source ?? '')}” produced no table rows${typeof payload.html === 'string' ? ' — use a report block for this source instead' : ''}.`);
|
|
271
|
-
}
|
|
272
|
-
// A plain object payload (last-run-status / routine-status) → a field/value
|
|
273
|
-
// table, mirroring html-report's object auto-render.
|
|
274
|
-
const entries = Object.entries(payload).filter(([, v]) => typeof v !== 'object' || v === null);
|
|
275
|
-
if (entries.length) {
|
|
276
|
-
const body = entries.map(([k, v]) =>
|
|
277
|
-
`<tr><td>${escapeHtml(k)}</td><td>${escapeHtml(v == null ? '—' : String(v))}</td></tr>`,
|
|
278
|
-
).join('');
|
|
279
|
-
return `<div class="ext-table-wrap"><table class="ext-table"><tbody>${body}</tbody></table></div>`;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
return placeholderHtml(`No data for “${String(b.source ?? '')}” yet — run the workflow to fill this table.`);
|
|
283
|
-
}
|
|
284
|
-
let shown = rows.filter((r) => r && typeof r === 'object' && !Array.isArray(r));
|
|
285
|
-
const cols = columnsFor(shown, b.columns);
|
|
286
|
-
if (typeof b.sort === 'string' && b.sort) shown = sortRows(shown, b.sort, b['sort-desc'] === true);
|
|
287
|
-
const more = Math.max(0, shown.length - MAX_ROWS);
|
|
288
|
-
if (more) shown = shown.slice(0, MAX_ROWS);
|
|
289
|
-
const isNum = (v) => typeof v === 'number' || (typeof v === 'string' && v.trim() !== '' && !Number.isNaN(Number(v)));
|
|
290
|
-
const head = cols.map((c) => `<th>${escapeHtml(c)}</th>`).join('');
|
|
291
|
-
const body = shown.map((r) =>
|
|
292
|
-
`<tr>${cols.map((c) => {
|
|
293
|
-
const v = r[c];
|
|
294
|
-
const txt = v == null ? '' : typeof v === 'object' ? JSON.stringify(v) : String(v);
|
|
295
|
-
return `<td${isNum(v) ? ' class="num"' : ''}>${escapeHtml(txt)}</td>`;
|
|
296
|
-
}).join('')}</tr>`,
|
|
297
|
-
).join('');
|
|
298
|
-
return `<div class="ext-table-wrap"><table class="ext-table"><thead><tr>${head}</tr></thead><tbody>${body}</tbody></table></div>` +
|
|
299
|
-
(more ? `<div class="ext-table-more">…and ${more} more row${more === 1 ? '' : 's'}</div>` : '');
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
function textHtml(b) {
|
|
303
|
-
const content = typeof b.content === 'string' ? b.content : '';
|
|
304
|
-
const paras = content.split(/\r?\n\s*\r?\n/).map((p) => p.trim()).filter(Boolean);
|
|
305
|
-
if (!paras.length) return '';
|
|
306
|
-
// Escaped FIRST, then single newlines become <br> — markup in content stays text.
|
|
307
|
-
return `<div class="ext-text">${paras.map((p) => `<p>${escapeHtml(p).replace(/\r?\n/g, '<br>')}</p>`).join('')}</div>`;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function reportHtml(b) {
|
|
311
|
-
const payload = payloadFor(b.source);
|
|
312
|
-
const title = typeof b.title === 'string' && b.title ? b.title : String(b.source ?? 'Report');
|
|
313
|
-
const locked = moduleRefusedHtml(payload);
|
|
314
|
-
if (locked) return locked;
|
|
315
|
-
if (traceUnreadable(payload)) {
|
|
316
|
-
return placeholderHtml(`The last run of “${String(b.source ?? '')}” finished, but its trace couldn’t be read — re-run to refresh this report.`);
|
|
317
|
-
}
|
|
318
|
-
const html = payload && typeof payload === 'object' && typeof payload.html === 'string' ? payload.html : null;
|
|
319
|
-
if (!html) return placeholderHtml(`No report for “${String(b.source ?? '')}” yet — run the workflow to generate one.`);
|
|
320
|
-
return `<div class="ext-report-row">` +
|
|
321
|
-
`<span class="ext-report-title">${escapeHtml(title)}</span>` +
|
|
322
|
-
`<button type="button" class="ext-report-open" data-source="${escapeAttr(String(b.source))}" data-title="${escapeAttr(title)}" data-tip="Open in the HTML Viewer — the report the run produced, never composed by the UI">View report ▸</button>` +
|
|
323
|
-
`</div>`;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function actionHtml(b) {
|
|
327
|
-
const label = escapeHtml(String(b.label ?? 'Action'));
|
|
328
|
-
const actionId = typeof b['action-id'] === 'string' ? b['action-id'] : '';
|
|
329
|
-
const m = RUN_APP_RE.exec(actionId);
|
|
330
|
-
if (!m) {
|
|
331
|
-
// Declared intent the host doesn't wire yet — inert, honestly labeled.
|
|
332
|
-
return `<button type="button" class="ext-action" disabled data-tip="${escapeAttr(`This action (“${actionId || 'unnamed'}”) isn't wired in this FloLess version.`)}">${label}</button>`;
|
|
333
|
-
}
|
|
334
|
-
const appId = m[1];
|
|
335
|
-
const gate = appGate.get(appId);
|
|
336
|
-
let disabled = ' disabled';
|
|
337
|
-
let tip;
|
|
338
|
-
if (!gate || gate.state === 'loading') tip = 'Checking workflow state…';
|
|
339
|
-
else if (gate.locked) tip = `Locked: ${gate.locked}`;
|
|
340
|
-
else if (gate.missing) tip = `Blocked: workflow “${appId}” is not installed.`;
|
|
341
|
-
else if (!gate.runnable) {
|
|
342
|
-
// The same stale-lock language the header Run button teaches.
|
|
343
|
-
tip = gate.runState === 'drift'
|
|
344
|
-
? 'Blocked: the .flo changed since the last approve — Compile first'
|
|
345
|
-
: 'Blocked: not compiled — Compile first';
|
|
346
|
-
} else {
|
|
347
|
-
disabled = '';
|
|
348
|
-
tip = `Run ${appId} for real against the live host`;
|
|
349
|
-
}
|
|
350
|
-
const inputs = b.inputs && typeof b.inputs === 'object' && !Array.isArray(b.inputs) ? b.inputs : {};
|
|
351
|
-
return `<button type="button" class="ext-action ext-action-run" data-app="${escapeAttr(appId)}" data-inputs="${escapeAttr(JSON.stringify(inputs))}"${disabled} data-tip="${escapeAttr(tip)}">▶ ${label}</button>`;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
function unknownHtml(b) {
|
|
355
|
-
return `<div class="ext-placeholder ext-unknown">This “${escapeHtml(String(b.type ?? '?'))}” block needs a newer FloLess — it appears once you update.</div>`;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
function blocksHtml(blocks) {
|
|
359
|
-
let html = '';
|
|
360
|
-
let statRun = []; // consecutive stats render as ONE KPI strip (mirrors AWARE's fallback renderer)
|
|
361
|
-
const flush = () => { if (statRun.length) { html += `<div class="ext-stat-row">${statRun.join('')}</div>`; statRun = []; } };
|
|
362
|
-
for (const block of blocks) {
|
|
363
|
-
if (!block || typeof block !== 'object') continue;
|
|
364
|
-
if (block.type === 'stat') { statRun.push(statHtml(block)); continue; }
|
|
365
|
-
flush();
|
|
366
|
-
switch (block.type) {
|
|
367
|
-
case 'table': html += tableHtml(block); break;
|
|
368
|
-
case 'text': html += textHtml(block); break;
|
|
369
|
-
case 'report': html += reportHtml(block); break;
|
|
370
|
-
case 'action': html += actionHtml(block); break;
|
|
371
|
-
default: html += unknownHtml(block);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
flush();
|
|
375
|
-
return html;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function panelHtml(p) {
|
|
379
|
-
const blocks = Array.isArray(p.blocks) ? p.blocks : [];
|
|
380
|
-
return `<section class="ext-panel" data-panel="${escapeAttr(String(p.id ?? ''))}">` +
|
|
381
|
-
`<div class="ext-panel-title">${escapeHtml(String(p.title ?? p.id ?? 'Panel'))}</div>` +
|
|
382
|
-
blocksHtml(blocks) +
|
|
383
|
-
`</section>`;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// ── Dashboard render ─────────────────────────────────────────────────────────
|
|
387
|
-
function composerHtml() {
|
|
388
|
-
return `<div class="ext-composer-wrap">` +
|
|
389
|
-
`<div class="ext-pending" id="ext-pending" hidden></div>` +
|
|
390
|
-
`<div class="ext-composer">` +
|
|
391
|
-
`<input type="text" id="ext-composer-input" placeholder="Describe what to add or change — your terminal AI applies it" autocomplete="off" aria-label="Describe a dashboard change">` +
|
|
392
|
-
`<button type="button" id="ext-composer-send">Queue for terminal AI</button>` +
|
|
393
|
-
`</div>` +
|
|
394
|
-
`<div class="ext-composer-hint">Try: “Show the last BOM run as a table with a re-run button”.</div>` +
|
|
395
|
-
`</div>`;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
function renderDashboard() {
|
|
399
|
-
const v = ext.validation;
|
|
400
|
-
const panels = descriptorInvalid() ? [] : dashboardPanels();
|
|
401
|
-
let html = '';
|
|
402
|
-
if (descriptorInvalid()) {
|
|
403
|
-
// Server-validated invalid descriptor ⇒ shipped default + a visible warning —
|
|
404
|
-
// a user file can never brick the app (design hard requirement).
|
|
405
|
-
const errs = Array.isArray(v.errors) ? v.errors : [];
|
|
406
|
-
html += `<div class="ext-invalid">` +
|
|
407
|
-
`<div class="ext-invalid-title">⚠ Your customization file has errors — showing the default view</div>` +
|
|
408
|
-
(errs.length ? `<ul>${errs.slice(0, 6).map((e) => `<li>${escapeHtml(String(e))}</li>`).join('')}</ul>` : '') +
|
|
409
|
-
`<div class="ext-invalid-hint">Ask your terminal AI to fix it, or use Undo (Customized, top left).</div>` +
|
|
410
|
-
`</div>`;
|
|
411
|
-
} else {
|
|
412
|
-
if (v && v.valid == null && v.note && panels.length) {
|
|
413
|
-
html += `<div class="ext-note">${escapeHtml(String(v.note))}</div>`;
|
|
414
|
-
}
|
|
415
|
-
if (v && v.valid === true && Array.isArray(v.warnings) && v.warnings.length) {
|
|
416
|
-
html += `<div class="ext-note">⚠ ${escapeHtml(String(v.warnings[0]))}${v.warnings.length > 1 ? ` (+${v.warnings.length - 1} more)` : ''}</div>`;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
if (panels.length) {
|
|
420
|
-
html += `<div class="ext-grid">${panels.map(panelHtml).join('')}</div>`;
|
|
421
|
-
} else if (!descriptorInvalid()) {
|
|
422
|
-
// Quiet empty state: one sentence + the composer below. Nothing disabled.
|
|
423
|
-
html += `<div class="ext-empty">No custom panels yet — describe what you want below and your terminal AI builds it.</div>`;
|
|
424
|
-
}
|
|
425
|
-
html += composerHtml();
|
|
426
|
-
// Post-reset escape hatch: with no panels there is no Customized pill — and so
|
|
427
|
-
// no Undo control — which would strand a mistaken Reset (its dialog promises
|
|
428
|
-
// recoverability). The empty state offers the newest snapshot back, one click.
|
|
429
|
-
const offerRestore = !panels.length && !descriptorInvalid();
|
|
430
|
-
if (offerRestore) html += `<div class="ext-restore" id="ext-restore" hidden></div>`;
|
|
431
|
-
$dashboard.innerHTML = html;
|
|
432
|
-
renderPending();
|
|
433
|
-
ensureGates(collectRunAppIds(panels));
|
|
434
|
-
if (offerRestore) maybeOfferRestore();
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// Fill the empty state's restore line iff history holds a snapshot. Disappears
|
|
438
|
-
// naturally when panels exist (only rendered in the empty branch) or when
|
|
439
|
-
// history is empty (this leaves it hidden). Re-checked on every re-render.
|
|
440
|
-
async function maybeOfferRestore() {
|
|
441
|
-
let history = [];
|
|
442
|
-
try { ({ history } = await api('/api/extensions/history')); } catch { return; }
|
|
443
|
-
const el = document.getElementById('ext-restore'); // may be gone if a re-render raced this fetch
|
|
444
|
-
if (!el || !Array.isArray(history) || !history.length) return;
|
|
445
|
-
const when = relAgo(String(history[0].timestamp || ''));
|
|
446
|
-
el.innerHTML = `Previous layout saved${when ? ' ' + escapeHtml(when) : ''} — ` +
|
|
447
|
-
`<button type="button" class="ext-restore-btn">Restore it</button>`;
|
|
448
|
-
el.hidden = false;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// ── run-app gating (the same runnable gate the header Run button enforces) ──
|
|
452
|
-
function collectRunAppIds(panels) {
|
|
453
|
-
const ids = new Set();
|
|
454
|
-
for (const p of panels) {
|
|
455
|
-
for (const b of Array.isArray(p.blocks) ? p.blocks : []) {
|
|
456
|
-
if (b && typeof b === 'object' && b.type === 'action' && typeof b['action-id'] === 'string') {
|
|
457
|
-
const m = RUN_APP_RE.exec(b['action-id']);
|
|
458
|
-
if (m) ids.add(m[1]);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
return [...ids];
|
|
463
|
-
}
|
|
464
|
-
function ensureGates(ids) {
|
|
465
|
-
for (const id of ids) {
|
|
466
|
-
if (appGate.has(id)) continue;
|
|
467
|
-
appGate.set(id, { state: 'loading' });
|
|
468
|
-
api(`/api/app/${encodeURIComponent(id)}`)
|
|
469
|
-
.then(({ app }) => appGate.set(id, { state: 'ready', runnable: !!app.runnable, runState: app.runState, missing: false }))
|
|
470
|
-
// #2644: a module workflow this account's plan does not include answers 403 with its own sentence; it is
|
|
471
|
-
// locked, not missing, so the panel says that instead of "not installed".
|
|
472
|
-
.catch((e) => {
|
|
473
|
-
const locked = e?.status === 403 && typeof e.body?.userMessage === 'string' ? e.body.userMessage.trim() : '';
|
|
474
|
-
appGate.set(id, { state: 'ready', runnable: false, runState: 'uncompiled', missing: !locked, locked });
|
|
475
|
-
})
|
|
476
|
-
.then(() => renderActiveSurfaces());
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// ── delegated interactions (innerHTML rebuilds; listeners must survive) ─────
|
|
481
|
-
function onSurfaceClick(e) {
|
|
482
|
-
if (e.target.closest('#ext-composer-send')) { submitCustomize(); return; }
|
|
483
|
-
const restore = e.target.closest('.ext-restore-btn');
|
|
484
|
-
if (restore) { restoreFromHistory(restore); return; }
|
|
485
|
-
const rep = e.target.closest('.ext-report-open');
|
|
486
|
-
if (rep) { openReport(rep.dataset.source, rep.dataset.title); return; }
|
|
487
|
-
const run = e.target.closest('.ext-action-run');
|
|
488
|
-
if (run && !run.disabled) runAction(run);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// The empty state's "Restore it" — the same undo the Customized menu offers,
|
|
492
|
-
// reachable when the pill (and with it the menu) is gone after a reset.
|
|
493
|
-
async function restoreFromHistory(btn) {
|
|
494
|
-
btn.disabled = true;
|
|
495
|
-
const ok = await undoNow();
|
|
496
|
-
if (!ok) btn.disabled = false; // success re-renders the dashboard; the line goes away
|
|
497
|
-
}
|
|
498
|
-
$dashboard.addEventListener('click', onSurfaceClick);
|
|
499
|
-
const $inspectBody = document.getElementById('inspect-body');
|
|
500
|
-
if ($inspectBody) $inspectBody.addEventListener('click', onSurfaceClick);
|
|
501
|
-
$dashboard.addEventListener('keydown', (e) => {
|
|
502
|
-
if (e.key === 'Enter' && e.target && e.target.id === 'ext-composer-input') {
|
|
503
|
-
e.preventDefault();
|
|
504
|
-
submitCustomize();
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
function openReport(source, title) {
|
|
509
|
-
const payload = payloadFor(source);
|
|
510
|
-
const html = payload && typeof payload === 'object' && typeof payload.html === 'string' ? payload.html : null;
|
|
511
|
-
if (!html) { showToast('No report yet — run the workflow first.', 'info'); return; }
|
|
512
|
-
const savedPath = payload && typeof payload.saved_path === 'string' ? payload.saved_path : null;
|
|
513
|
-
if (bridge.showHtmlReport) bridge.showHtmlReport(title || 'Report', html, savedPath);
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
async function runAction(btn) {
|
|
517
|
-
const appId = btn.dataset.app;
|
|
518
|
-
let inputs = {};
|
|
519
|
-
try { inputs = JSON.parse(btn.dataset.inputs || '{}'); } catch { /* inert inputs */ }
|
|
520
|
-
const prev = btn.textContent;
|
|
521
|
-
btn.disabled = true;
|
|
522
|
-
btn.textContent = '◆ Running…';
|
|
523
|
-
try {
|
|
524
|
-
const res = await api('/api/run', { method: 'POST', body: JSON.stringify({ id: appId,
|
|
525
|
-
runRequestId: crypto.randomUUID(), runOrigin: 'panel', simulate: false, inputs }) });
|
|
526
|
-
if (res.credentialIssue) {
|
|
527
|
-
showToast(`Session expired — reconnect ${res.credentialIssue.label} (≡ menu → Integrations), then run again.`, 'warn');
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
const html = res.report && res.report.html;
|
|
531
|
-
if (html && bridge.showHtmlReport) bridge.showHtmlReport(`${appId} · report`, html, res.savedPath);
|
|
532
|
-
else showToast(`Run complete · ${appId}`, 'ok');
|
|
533
|
-
} catch (err) {
|
|
534
|
-
const cred = err && err.body && err.body.credentialIssue;
|
|
535
|
-
if (cred) showToast(`Session expired — reconnect ${cred.label} (≡ menu → Integrations), then run again.`, 'warn');
|
|
536
|
-
// #2123: FloLess declined before anything started (archived, edited, re-published) and said why in plain words.
|
|
537
|
-
else if (err && err.body && err.body.notRun && typeof err.body.error === 'string') showToast(err.body.error, 'info');
|
|
538
|
-
else showToast('The workflow could not run. Your inputs are still here. Check that its connection is open, then try again.', 'warn');
|
|
539
|
-
} finally {
|
|
540
|
-
btn.disabled = false;
|
|
541
|
-
btn.textContent = prev;
|
|
542
|
-
fetchExtensions(); // last-run bindings just changed (SSE run-ended also fires; refetch is idempotent)
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
// ── Customize composer (the Tweak reverse channel, dashboard-scoped) ────────
|
|
547
|
-
async function submitCustomize() {
|
|
548
|
-
const input = document.getElementById('ext-composer-input');
|
|
549
|
-
const btn = document.getElementById('ext-composer-send');
|
|
550
|
-
const instruction = input ? input.value.trim() : '';
|
|
551
|
-
if (!instruction) { if (input) input.focus(); return; }
|
|
552
|
-
if (btn) { btn.disabled = true; btn.textContent = 'Queueing…'; }
|
|
553
|
-
try {
|
|
554
|
-
const { request } = await api('/api/extensions/customize', { method: 'POST', body: JSON.stringify({ instruction }) });
|
|
555
|
-
// Copy the MARKED form so a pasted ui-customize request is recognized, not run verbatim (#73).
|
|
556
|
-
const line = bridge.markedInstruction ? bridge.markedInstruction(request)
|
|
557
|
-
: bridge.instructionFor ? bridge.instructionFor(request) : instruction;
|
|
558
|
-
const copied = bridge.copyToClipboard ? await bridge.copyToClipboard(line) : false;
|
|
559
|
-
showToast(copied ? 'Queued for your terminal AI · copied to clipboard' : 'Queued for your terminal AI', 'ok');
|
|
560
|
-
if (input) input.value = '';
|
|
561
|
-
if (bridge.loadRequests) bridge.loadRequests();
|
|
562
|
-
refreshPending();
|
|
563
|
-
} catch (err) {
|
|
564
|
-
showToast('We couldn’t send that change to your terminal AI. Your work is still here. Try again.', 'warn');
|
|
565
|
-
} finally {
|
|
566
|
-
if (btn) { btn.disabled = false; btn.textContent = 'Queue for terminal AI'; }
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// Between "queued" and "applied" the dashboard looks unchanged — say so inline,
|
|
571
|
-
// not just in a transient toast (UX review: kill the dead air for non-technical users).
|
|
572
|
-
async function refreshPending() {
|
|
573
|
-
if (!booted) return;
|
|
574
|
-
try {
|
|
575
|
-
const { requests } = await api('/api/requests');
|
|
576
|
-
pendingCustomize = (requests || []).filter((r) => r.type === 'ui-customize').length;
|
|
577
|
-
} catch { pendingCustomize = 0; }
|
|
578
|
-
renderPending();
|
|
579
|
-
}
|
|
580
|
-
function renderPending() {
|
|
581
|
-
const el = document.getElementById('ext-pending');
|
|
582
|
-
if (!el) return;
|
|
583
|
-
el.hidden = pendingCustomize === 0;
|
|
584
|
-
el.textContent = pendingCustomize === 0 ? '' :
|
|
585
|
-
`${pendingCustomize} change${pendingCustomize === 1 ? '' : 's'} queued for your terminal AI — paste the copied instruction there, or say “apply my floless request”.`;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
// ── Customized badge + Undo / History / Reset menu ───────────────────────────
|
|
589
|
-
function renderBadge() {
|
|
590
|
-
if (!$extBadge) return;
|
|
591
|
-
// The badge's whole menu (Undo · History · Reset) edits Dashboard panels, so it goes
|
|
592
|
-
// with the Dashboard — a populated descriptor must not light it up while the surface
|
|
593
|
-
// it describes is unreachable (#902).
|
|
594
|
-
const has = DASHBOARD_UI_ENABLED && allPanels().length > 0;
|
|
595
|
-
$extBadge.hidden = !has;
|
|
596
|
-
if (!has) closeExtMenu();
|
|
597
|
-
}
|
|
598
|
-
let extMenuOpen = false;
|
|
599
|
-
function openExtMenu() {
|
|
600
|
-
renderHistoryList();
|
|
601
|
-
const r = $extBadge.getBoundingClientRect();
|
|
602
|
-
$extMenu.style.left = Math.round(Math.max(8, Math.min(r.left, window.innerWidth - 300))) + 'px';
|
|
603
|
-
$extMenu.hidden = false;
|
|
604
|
-
$extMenu.classList.add('show');
|
|
605
|
-
$extBadge.setAttribute('aria-expanded', 'true');
|
|
606
|
-
extMenuOpen = true;
|
|
607
|
-
}
|
|
608
|
-
function closeExtMenu() {
|
|
609
|
-
if (!extMenuOpen) return;
|
|
610
|
-
$extMenu.classList.remove('show');
|
|
611
|
-
$extMenu.hidden = true;
|
|
612
|
-
$extBadge.setAttribute('aria-expanded', 'false');
|
|
613
|
-
extMenuOpen = false;
|
|
614
|
-
}
|
|
615
|
-
if ($extBadge) {
|
|
616
|
-
$extBadge.addEventListener('click', (e) => {
|
|
617
|
-
e.stopPropagation();
|
|
618
|
-
if (extMenuOpen) closeExtMenu(); else openExtMenu();
|
|
619
|
-
});
|
|
620
|
-
document.addEventListener('click', (e) => {
|
|
621
|
-
if (extMenuOpen && !$extMenu.contains(e.target) && e.target !== $extBadge) closeExtMenu();
|
|
622
|
-
});
|
|
623
|
-
document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && extMenuOpen) closeExtMenu(); });
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
// `relAgo` is app.js's, like `escapeHtml` and `escapeAttr` above — this file carried a
|
|
627
|
-
// byte-identical copy of the same 'just now / N min ago / N h ago / N d ago' ladder.
|
|
628
|
-
|
|
629
|
-
// Reflect undo/redo availability on the menu buttons (disabled, not hidden — they're
|
|
630
|
-
// persistent navigation controls; the native :disabled state communicates "you're at
|
|
631
|
-
// the end of the stack"). Called on menu open and after every undo/redo/reset.
|
|
632
|
-
function setUndoRedoEnabled(canUndo, canRedo) {
|
|
633
|
-
if ($extUndo) $extUndo.disabled = !canUndo;
|
|
634
|
-
if ($extRedo) $extRedo.disabled = !canRedo;
|
|
635
|
-
}
|
|
636
|
-
async function renderHistoryList() {
|
|
637
|
-
if (!$extHistory) return;
|
|
638
|
-
$extHistory.innerHTML = '<div class="ext-history-empty">loading…</div>';
|
|
639
|
-
try {
|
|
640
|
-
const { history, canUndo, canRedo } = await api('/api/extensions/history');
|
|
641
|
-
setUndoRedoEnabled(canUndo, canRedo);
|
|
642
|
-
if (!history || !history.length) {
|
|
643
|
-
$extHistory.innerHTML = '<div class="ext-history-empty">No snapshots yet — every change lands here automatically.</div>';
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
$extHistory.innerHTML = history.slice(0, 8).map((h) => {
|
|
647
|
-
const when = relAgo(h.timestamp) || (h.timestamp ? new Date(h.timestamp).toLocaleString() : '—');
|
|
648
|
-
const now = h.current ? '<span class="ext-history-current">now</span>' : '';
|
|
649
|
-
return `<div class="ext-history-item${h.current ? ' is-current' : ''}"><span class="ext-history-when" data-tip="${escapeAttr(h.timestamp)}">${escapeHtml(when)}</span>` +
|
|
650
|
-
`<span class="ext-history-count">${now}${Number(h.panelsCount) || 0} panel${h.panelsCount === 1 ? '' : 's'}</span></div>`;
|
|
651
|
-
}).join('');
|
|
652
|
-
} catch {
|
|
653
|
-
$extHistory.innerHTML = '<div class="ext-history-empty">history unavailable</div>';
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
// The one undo body — shared by the Customized menu's "Undo" and the empty state's
|
|
658
|
-
// "Restore it". Walks one state back per call (multi-level). Returns whether it moved.
|
|
659
|
-
async function undoNow() {
|
|
660
|
-
try {
|
|
661
|
-
const res = await api('/api/extensions/undo', { method: 'POST' });
|
|
662
|
-
setUndoRedoEnabled(res.canUndo, res.canRedo);
|
|
663
|
-
showToast('Restored the previous layout', 'ok');
|
|
664
|
-
fetchExtensions();
|
|
665
|
-
return true;
|
|
666
|
-
} catch (err) {
|
|
667
|
-
const b = err && err.body;
|
|
668
|
-
if (b) setUndoRedoEnabled(b.canUndo, b.canRedo);
|
|
669
|
-
if (b && b.code === 'nothing-to-undo') showToast('Nothing to undo', 'info');
|
|
670
|
-
else showToast('We couldn’t undo that change. Nothing else was changed. Try again.', 'warn');
|
|
671
|
-
return false;
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
// Redo — walks one state forward through the redo branch (a new edit truncates it).
|
|
675
|
-
async function redoNow() {
|
|
676
|
-
try {
|
|
677
|
-
const res = await api('/api/extensions/redo', { method: 'POST' });
|
|
678
|
-
setUndoRedoEnabled(res.canUndo, res.canRedo);
|
|
679
|
-
showToast('Restored the next layout', 'ok');
|
|
680
|
-
fetchExtensions();
|
|
681
|
-
return true;
|
|
682
|
-
} catch (err) {
|
|
683
|
-
const b = err && err.body;
|
|
684
|
-
if (b) setUndoRedoEnabled(b.canUndo, b.canRedo);
|
|
685
|
-
if (b && b.code === 'nothing-to-redo') showToast('Nothing to redo', 'info');
|
|
686
|
-
else showToast('We couldn’t redo that change. Nothing else was changed. Try again.', 'warn');
|
|
687
|
-
return false;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
if ($extUndo) $extUndo.onclick = () => { closeExtMenu(); undoNow(); };
|
|
691
|
-
if ($extRedo) $extRedo.onclick = () => { closeExtMenu(); redoNow(); };
|
|
692
|
-
|
|
693
|
-
// Ctrl/Cmd+Z = undo, Ctrl/Cmd+Y or Ctrl/Cmd+Shift+Z = redo — multi-level, matching the
|
|
694
|
-
// menu. Only while the Dashboard view is active and focus isn't in a text field, so it
|
|
695
|
-
// never steals a real input's (or the terminal's) own undo.
|
|
696
|
-
document.addEventListener('keydown', (e) => {
|
|
697
|
-
if (view !== 'dashboard') return;
|
|
698
|
-
if (!(e.ctrlKey || e.metaKey) || e.altKey) return;
|
|
699
|
-
const t = e.target;
|
|
700
|
-
if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.isContentEditable)) return;
|
|
701
|
-
const k = e.key.toLowerCase();
|
|
702
|
-
if (k === 'z' && !e.shiftKey) { e.preventDefault(); undoNow(); }
|
|
703
|
-
else if (k === 'y' || (k === 'z' && e.shiftKey)) { e.preventDefault(); redoNow(); }
|
|
704
|
-
});
|
|
705
|
-
|
|
706
|
-
// Reset is recoverable (archived to history first) but still asks — mirrors the
|
|
707
|
-
// routine-delete confirm: Cancel holds focus; Esc/backdrop cancel.
|
|
708
|
-
function confirmReset() {
|
|
709
|
-
return new Promise((resolve) => {
|
|
710
|
-
const $confirm = document.getElementById('ext-reset-confirm');
|
|
711
|
-
const $cancel = document.getElementById('ext-reset-cancel');
|
|
712
|
-
$resetModal.classList.add('show');
|
|
713
|
-
setTimeout(() => $cancel.focus(), 0);
|
|
714
|
-
const done = (result) => {
|
|
715
|
-
$resetModal.classList.remove('show');
|
|
716
|
-
$confirm.onclick = $cancel.onclick = $resetModal.onclick = $resetModal.onmousedown = null;
|
|
717
|
-
document.removeEventListener('keydown', onKey, true);
|
|
718
|
-
resolve(result);
|
|
719
|
-
};
|
|
720
|
-
const onKey = (e) => { if (e.key === 'Escape') { e.preventDefault(); done(false); } };
|
|
721
|
-
$confirm.onclick = () => done(true);
|
|
722
|
-
$cancel.onclick = () => done(false);
|
|
723
|
-
onBackdropDismiss($resetModal, () => done(false));
|
|
724
|
-
document.addEventListener('keydown', onKey, true);
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
const $extReset = document.getElementById('ext-reset');
|
|
728
|
-
if ($extReset) $extReset.onclick = async () => {
|
|
729
|
-
closeExtMenu();
|
|
730
|
-
if (!(await confirmReset())) return;
|
|
731
|
-
try {
|
|
732
|
-
const res = await api('/api/extensions/reset', { method: 'POST' });
|
|
733
|
-
setUndoRedoEnabled(res.canUndo, res.canRedo); // symmetric with undo/redo (Undo recovers it)
|
|
734
|
-
showToast('Dashboard reset — your panels were saved to history', 'ok');
|
|
735
|
-
fetchExtensions();
|
|
736
|
-
} catch (err) {
|
|
737
|
-
const b = err && err.body;
|
|
738
|
-
if (b) setUndoRedoEnabled(b.canUndo, b.canRedo);
|
|
739
|
-
if (b && b.code === 'already-default') showToast('Already the default dashboard', 'info');
|
|
740
|
-
else showToast('We couldn’t reset the dashboard. Your current layout is still here. Try again.', 'warn');
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
|
|
744
|
-
// ── extra Inspect tabs (slot: inspect-tab) ───────────────────────────────────
|
|
745
|
-
function renderInspectTabs() {
|
|
746
|
-
const tabs = document.getElementById('tabs');
|
|
747
|
-
if (!tabs) return;
|
|
748
|
-
tabs.querySelectorAll('button.ext-tab').forEach((b) => b.remove());
|
|
749
|
-
const list = descriptorInvalid() ? [] : inspectPanels();
|
|
750
|
-
for (const p of list) {
|
|
751
|
-
const b = document.createElement('button');
|
|
752
|
-
b.className = 'ext-tab';
|
|
753
|
-
b.dataset.tab = 'ext:' + String(p.id ?? '');
|
|
754
|
-
b.textContent = String(p.title ?? p.id ?? 'Panel');
|
|
755
|
-
tabs.appendChild(b); // app.js's delegated $tabs.onclick handles activation
|
|
756
|
-
}
|
|
757
|
-
if (typeof state.currentTab === 'string' && state.currentTab.startsWith('ext:')) {
|
|
758
|
-
const alive = list.some((p) => 'ext:' + String(p.id ?? '') === state.currentTab);
|
|
759
|
-
if (!alive) state.currentTab = 'description'; // panel renamed/removed — heal to a real tab
|
|
760
|
-
tabs.querySelectorAll('button').forEach((b) => b.classList.toggle('active', b.dataset.tab === state.currentTab));
|
|
761
|
-
renderInspect();
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
function renderExtInspect(panelId) {
|
|
766
|
-
const $bd = document.getElementById('inspect-body');
|
|
767
|
-
if (!$bd) return;
|
|
768
|
-
const p = inspectPanels().find((x) => String(x.id ?? '') === panelId);
|
|
769
|
-
if (!p) {
|
|
770
|
-
$bd.innerHTML = '<div class="empty-state">This panel was removed from your customization.</div>';
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
773
|
-
$bd.innerHTML = `<div class="ext-inspect">` +
|
|
774
|
-
`<div class="inspect-head-row"><div class="inspect-title">${escapeHtml(String(p.title ?? p.id))}</div></div>` +
|
|
775
|
-
`<div class="inspect-meta">custom panel · composed by your terminal AI</div>` +
|
|
776
|
-
blocksHtml(Array.isArray(p.blocks) ? p.blocks : []) +
|
|
777
|
-
`</div>`;
|
|
778
|
-
ensureGates(collectRunAppIds([p]));
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
// Route ext:* tabs through our renderer; everything else stays app.js's.
|
|
782
|
-
// (Same reassignment pattern aware.js uses for renderChat/selectAgent.)
|
|
783
|
-
const _renderInspect = renderInspect;
|
|
784
|
-
renderInspect = function renderInspectWithPanels() {
|
|
785
|
-
if (typeof state.currentTab === 'string' && state.currentTab.startsWith('ext:')) {
|
|
786
|
-
renderExtInspect(state.currentTab.slice(4));
|
|
787
|
-
return;
|
|
788
|
-
}
|
|
789
|
-
_renderInspect();
|
|
790
|
-
};
|
|
791
|
-
|
|
792
|
-
function renderActiveSurfaces() {
|
|
793
|
-
renderDashboard();
|
|
794
|
-
if (typeof state.currentTab === 'string' && state.currentTab.startsWith('ext:')) renderInspect();
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
// ── fetch + public surface ───────────────────────────────────────────────────
|
|
798
|
-
async function fetchExtensions(opts = {}) {
|
|
799
|
-
if (!booted) return;
|
|
800
|
-
let res;
|
|
801
|
-
try {
|
|
802
|
-
res = await api('/api/extensions');
|
|
803
|
-
} catch {
|
|
804
|
-
return; // gated/offline — keep the current render; the next signal retries
|
|
805
|
-
}
|
|
806
|
-
ext = { descriptor: res.descriptor ?? null, validation: res.validation ?? null, data: res.data || {} };
|
|
807
|
-
appGate.clear(); // compiles/installs elsewhere may have changed the gates
|
|
808
|
-
renderBadge();
|
|
809
|
-
renderInspectTabs();
|
|
810
|
-
renderDashboard();
|
|
811
|
-
// Content changed while the user is on Canvas → light the Dashboard dot
|
|
812
|
-
// (never auto-switch — don't yank their context).
|
|
813
|
-
if (opts.fromChange && view === 'canvas' && allPanels().length) setDashUpdated(true);
|
|
814
|
-
refreshPending();
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
function boot() {
|
|
818
|
-
if (booted) return;
|
|
819
|
-
booted = true;
|
|
820
|
-
fetchExtensions();
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
window.flolessPanels = {
|
|
824
|
-
boot,
|
|
825
|
-
refresh: (opts) => fetchExtensions(opts || {}),
|
|
826
|
-
refreshData: () => fetchExtensions(),
|
|
827
|
-
refreshPending,
|
|
828
|
-
};
|
|
829
|
-
|
|
830
|
-
applyView(); // restore the persisted view immediately (no fetch until boot)
|
|
831
|
-
})();
|