lavish-axi 0.1.31 → 0.1.33
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/README.md +46 -23
- package/dist/chrome-client.js +304 -4
- package/dist/chrome.css +228 -2
- package/dist/cli.mjs +4500 -357
- package/package.json +2 -2
- package/skills/lavish/SKILL.md +14 -9
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ That loses the thing HTML is best at: interactivity.
|
|
|
33
33
|
|
|
34
34
|
Lavish Editor opens agent-generated HTML files in a local browser, lets you pinpoint elements or selected text and send feedback to the agent to address.
|
|
35
35
|
|
|
36
|
-
- **Local
|
|
36
|
+
- **Local-first** - Review local HTML artifacts with a local CLI and no cloud dependency in the core feedback loop; hosted sharing through third-party ht-ml.app is explicit and opt-in.
|
|
37
37
|
- **Human-AI collaboration** - Annotate elements, selected text ranges, and send messages to the agent without leaving Lavish Editor.
|
|
38
38
|
- **Battery included** - Lavish Editor teaches your agent good visualization for common use cases such as product or technical plans, design explorations and more out of the box.
|
|
39
39
|
|
|
@@ -88,7 +88,7 @@ npm install -g lavish-axi
|
|
|
88
88
|
lavish-axi setup hooks
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
This installs a `SessionStart` hook for **Claude Code**, **Codex**, and **
|
|
91
|
+
This installs a `SessionStart` hook for **Claude Code**, **Codex**, **OpenCode**, and **GitHub Copilot CLI** that surfaces open sessions, visualization playbooks, and usage guidance at the start of each session.
|
|
92
92
|
Unlike the skill, the hook also shows your live open sessions, so a fresh agent session can resume an in-flight review.
|
|
93
93
|
**Restart your agent session after running this** so the new hook takes effect.
|
|
94
94
|
|
|
@@ -117,8 +117,9 @@ pnpm link
|
|
|
117
117
|
▼
|
|
118
118
|
┌────────────────────────┐
|
|
119
119
|
│ Human annotates text │
|
|
120
|
-
│ or elements,
|
|
121
|
-
│
|
|
120
|
+
│ or elements, sends │
|
|
121
|
+
│ chat, or browser audit │
|
|
122
|
+
│ reports layout issues │
|
|
122
123
|
└───────┬────────────────┘
|
|
123
124
|
▼
|
|
124
125
|
┌────────────────────────┐
|
|
@@ -128,49 +129,71 @@ pnpm link
|
|
|
128
129
|
```
|
|
129
130
|
|
|
130
131
|
- **File-path identity** - Sessions are keyed by the canonical HTML file path, so agents do not need opaque IDs.
|
|
131
|
-
- **Portable artifacts** - The artifact runs in an iframe while Lavish injects a small SDK for annotations, snapshots, and
|
|
132
|
+
- **Portable artifacts** - The artifact runs in an iframe while Lavish injects a small SDK for annotations, snapshots, feedback controls, and render-time layout checks.
|
|
132
133
|
Lavish does not inject any design system, so the saved HTML file renders identically whether you open it through `lavish-axi` or directly in a browser.
|
|
133
134
|
Before writing HTML, choose a design system in strict priority order: follow a user-requested look first; otherwise inspect the project the artifact is about - the subject or product whose content or UI it represents, which may differ from your current working directory - and match that project's Tailwind or theme config, CSS variables or design tokens, component library, brand assets, or existing styled pages.
|
|
134
135
|
If the artifact previews, proposes, or mocks a specific app's UI, render it in that app's own design system so it faithfully shows the product, even when you are running in a different repo.
|
|
135
|
-
Only when both come up empty, run `lavish-axi design` for a copy-pasteable Tailwind CSS v4 + DaisyUI v5 CDN fallback.
|
|
136
|
-
That fallback guidance recommends DaisyUI's `luxury` theme by default
|
|
136
|
+
Only when both come up empty, run `lavish-axi design` for a copy-pasteable Tailwind CSS v4 + DaisyUI v5 CDN fallback, a content-to-playbook router, and Mermaid diagram tooling.
|
|
137
|
+
That fallback guidance recommends DaisyUI's `luxury` theme by default, warns not to `@apply` DaisyUI classes inside Tailwind browser-runtime style blocks, includes an optional layout safety CSS snippet for dense nested grid/flex layouts, and provides a pinned Mermaid CDN snippet with initialization for flows, architecture, state, and sequence diagrams.
|
|
138
|
+
- **Open-time layout gate** - The browser chrome masks each artifact until the real in-iframe layout audit reports no error-severity findings.
|
|
139
|
+
Warning-only artifacts reveal normally; error findings notify the agent through the same `layout_warnings` poll path and keep the curtain up until a clean reload.
|
|
140
|
+
The user can click **Show anyway**, and a bounded safety timeout reveals with a persistent layout-issues banner so review is never blocked indefinitely.
|
|
141
|
+
- **Layout warnings** - After fonts load and layout settles, the injected SDK audits the real browser render for page horizontal overflow, element overflow, clipped text, and overlapping text.
|
|
142
|
+
Intentional horizontal scrollers using `overflow-x: auto` or `scroll` are excluded.
|
|
143
|
+
Fresh warnings are returned from `lavish-axi poll` as `layout_warnings` with `selector`, `kind`, `overflowPx`, `viewportWidth`, and `severity`, so agents can fix unreadable layouts before asking the human to review.
|
|
137
144
|
- **Local assets** - Copy local images, CSS, fonts, and scripts next to the HTML artifact and reference them with relative paths from that directory; root-prefixed paths such as `/assets/logo.png` will not resolve through Lavish's artifact route.
|
|
145
|
+
- **Export and sharing** - `lavish-axi export` writes `<name>.export.html` by inlining local assets only, stripping the annotation SDK, and leaving remote CDN/font references as links that still need network access.
|
|
146
|
+
`lavish-axi share` publishes the same local-inlined HTML to [ht-ml.app](https://ht-ml.app), a third-party hosting service not part of Lavish.
|
|
147
|
+
Publishing sends the artifact to ht-ml.app's servers, public by default, or private and password-protected with `--password`; the response includes a secret `update_key` shown once for later management.
|
|
148
|
+
Bundling never fetches remote URLs, Lavish itself does not set a CSP, local reads stay confined and size-capped, and absolute `file://` paths outside safe inlined asset references are redacted before output.
|
|
149
|
+
Per-asset and per-bundle inline caps default to 10 MB and 25 MB, overridable with `LAVISH_AXI_EXPORT_MAX_ASSET_BYTES` and `LAVISH_AXI_EXPORT_MAX_BUNDLE_BYTES`.
|
|
150
|
+
Unresolved local assets or export notices such as author-set CSP meta tags and redacted file URLs are surfaced in command or browser output.
|
|
151
|
+
Use `--token` or `LAVISH_AXI_HTML_APP_TOKEN` for an optional bearer token; set `LAVISH_AXI_HTML_APP_API_URL` only when overriding the ht-ml.app API base.
|
|
138
152
|
- **Live reload** - Lavish watches the HTML artifact file by default and preserves the artifact iframe scroll position across reloads. To also reload on sibling asset changes, add `data-lavish-live-reload-root` to the root element or `<meta name="lavish-live-reload" content="root">`.
|
|
139
|
-
- **Feedback controls** - Native
|
|
153
|
+
- **Feedback controls** - Native controls (radios, checkboxes, inputs, selects, buttons, labels, disclosure summaries, contenteditable) are interactive automatically, so they do not need `data-lavish-action`.
|
|
140
154
|
For reversible choices, let option clicks update local state, then queue exactly one final answer from a per-question submit or Queue answer button with `window.lavish.queuePrompt()`.
|
|
141
155
|
Mark only custom (non-native) clickable elements with `data-lavish-action` so Lavish does not annotate them, and use `data-lavish-question` or `queueKey` when pre-send updates for the same question should replace each other.
|
|
142
|
-
The browser chrome keeps editing actions in the overflow menu (copy path, reload artifact, copy DOM snapshot, end session) and can submit queued prompts with **Send & end session**, which delivers the prompts before ending the session.
|
|
156
|
+
The browser chrome keeps editing actions in the overflow menu (copy path, reload artifact, copy DOM snapshot, export standalone HTML, publish link, end session) and can submit queued prompts with **Send & end session**, which delivers the prompts before ending the session.
|
|
143
157
|
- **Keyboard shortcuts** - In the chrome composer, Enter sends queued prompts and Shift+Enter inserts a newline.
|
|
144
158
|
In the annotation card, Enter queues the annotation, Shift+Enter inserts a newline, and Ctrl+Enter (Cmd+Enter on macOS) queues it and sends all queued prompts immediately.
|
|
145
|
-
- **Agent presence** - The browser shows when no agent is listening, keeps queued feedback for the next successful `lavish-axi poll` send even across reloads, and only blocks
|
|
159
|
+
- **Agent presence** - The browser shows when no agent is listening, keeps queued feedback and fresh layout warnings for the next successful `lavish-axi poll` send even across reloads, and only blocks human sends while the agent is working on delivered feedback. The no-timeout poll writes an immediate stderr banner and periodic stderr heartbeats while stdout stays reserved for the final response; if the poll is interrupted or times out, re-run it because queued feedback is never lost.
|
|
146
160
|
- **Precise targets** - Text annotations include selected text plus range anchors, so agents are not limited to whole-element selectors.
|
|
147
161
|
- **Server cleanup** - The detached server stops after the last session ends when nothing is connected, or after `LAVISH_AXI_IDLE_TIMEOUT_MS` (default 30 minutes) with no browser or poll connections.
|
|
148
162
|
Set `LAVISH_AXI_IDLE_TIMEOUT_MS=0` or `off` to disable idle self-shutdown.
|
|
149
|
-
- **Local-first state** - Session state stays under
|
|
163
|
+
- **Local-first state** - Session state stays under `~/.lavish-axi/` by default, or `LAVISH_AXI_STATE_DIR` when set.
|
|
150
164
|
- **Network binding** - The server binds to loopback (`127.0.0.1`) by default. Set `LAVISH_AXI_HOST` to bind elsewhere; a wildcard (`0.0.0.0` or `::`) binds every interface. Binding beyond loopback exposes an unauthenticated server that can read and serve arbitrary local files to anything that can reach it, so only do so on a trusted network. Set `LAVISH_AXI_LINK_HOST` to control the hostname written into generated session links (defaults to the bind address, or loopback when bound to a wildcard).
|
|
151
165
|
|
|
152
166
|
## CLI Reference
|
|
153
167
|
|
|
154
|
-
| Command
|
|
155
|
-
|
|
|
156
|
-
| `lavish-axi`
|
|
157
|
-
| `lavish-axi
|
|
158
|
-
| `lavish-axi
|
|
159
|
-
| `lavish-axi
|
|
160
|
-
| `lavish-axi
|
|
161
|
-
| `lavish-axi
|
|
162
|
-
| `lavish-axi
|
|
163
|
-
| `lavish-axi
|
|
164
|
-
| `lavish-axi
|
|
168
|
+
| Command | Description |
|
|
169
|
+
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
170
|
+
| `lavish-axi` | Show current sessions and usage guidance. |
|
|
171
|
+
| `lavish-axi update` | Check for or apply the latest npm release through the AXI SDK self-updater. |
|
|
172
|
+
| `lavish-axi <html-file>` | Open or resume a Lavish Editor session, with the open-time layout gate enabled by default. |
|
|
173
|
+
| `lavish-axi poll <html-file>` | Long-poll until the user sends feedback, ends the session, or the browser reports fresh `layout_warnings`; leave no-timeout polls running, or re-run them if interrupted. |
|
|
174
|
+
| `lavish-axi end <html-file>` | End a session. |
|
|
175
|
+
| `lavish-axi export <html-file>` | Write a portable copy of the artifact: one HTML file with its local assets inlined, so it opens with no server and no sibling files. Remote CDN/font references are left as links. |
|
|
176
|
+
| `lavish-axi share <html-file>` | Publish the artifact (local assets inlined) to [ht-ml.app](https://ht-ml.app), a third-party host not part of Lavish, and print a visitable URL plus a secret update key; shares are public by default, and `--password` makes viewers enter the password before viewing. |
|
|
177
|
+
| `lavish-axi stop` | Shut down the background server. |
|
|
178
|
+
| `lavish-axi playbook [id]` | List focused artifact guidance or show one playbook; agents must open each matching playbook before writing HTML. |
|
|
179
|
+
| `lavish-axi design` | Show the Tailwind + DaisyUI CDN fallback, content-to-playbook router, Mermaid diagram tooling, `luxury` default theme, DaisyUI `@apply` warning, and layout safety snippet. |
|
|
180
|
+
| `lavish-axi setup hooks` | Install or repair optional SessionStart hooks for Claude Code, Codex, OpenCode, and GitHub Copilot CLI; restart the agent session afterward. |
|
|
181
|
+
| `lavish-axi server` | Run the local Lavish Editor server. |
|
|
165
182
|
|
|
166
183
|
Known playbook IDs: `diagram`, `table`, `comparison`, `plan`, `code`, `input`, `slides`.
|
|
167
|
-
One artifact often combines several playbooks, such as a plan that includes a comparison and a diagram, so
|
|
184
|
+
One artifact often combines several playbooks, such as a plan that includes a comparison and a diagram, so agents must match against each `use_when` trigger and open every matching playbook before writing HTML.
|
|
185
|
+
For flows, architecture, state, or sequence diagrams, open the diagram playbook and use the Mermaid tooling from `lavish-axi design` unless SVG is needed for richly annotated nodes; avoid hand-built div/flexbox boxes-and-arrows.
|
|
168
186
|
|
|
169
187
|
### Flags
|
|
170
188
|
|
|
171
189
|
| Command | Flag | Description |
|
|
172
190
|
| ------------------------ | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
173
191
|
| `lavish-axi <html-file>` | `--no-open` | Ensure the server/session exists without opening another browser window. |
|
|
192
|
+
| `lavish-axi <html-file>` | `--no-gate` | Skip the open-time layout curtain for this browser open. |
|
|
193
|
+
| `lavish-axi update` | `--check` | Report current vs latest npm version without installing an update. |
|
|
194
|
+
| `lavish-axi export` | `--out <path>` | Write the export to a specific path instead of `<name>.export.html` next to the source. |
|
|
195
|
+
| `lavish-axi share` | `--password <pw>` | Make the third-party ht-ml.app page private; viewers must supply the password. |
|
|
196
|
+
| `lavish-axi share` | `--token <t>` | Attach an optional bearer token (`LAVISH_AXI_HTML_APP_TOKEN`); never required to publish. |
|
|
174
197
|
| `lavish-axi poll` | `--agent-reply "..."` | Show the agent's reply in the existing browser chat before polling again. |
|
|
175
198
|
| `lavish-axi poll` | `--timeout-ms <ms>` | Test/debug escape hatch only; agents should normally omit it and leave the long poll running. |
|
|
176
199
|
| `lavish-axi stop` | `--port <port>` | Shut down a server running on a non-default port. |
|
package/dist/chrome-client.js
CHANGED
|
@@ -24,19 +24,51 @@ const moreButton = /** @type {HTMLButtonElement} */ (document.getElementById("mo
|
|
|
24
24
|
const moreMenu = /** @type {HTMLDivElement} */ (document.getElementById("moreMenu"));
|
|
25
25
|
const reloadArtifactButton = /** @type {HTMLButtonElement} */ (document.getElementById("reloadArtifact"));
|
|
26
26
|
const copySnapshotButton = /** @type {HTMLButtonElement} */ (document.getElementById("copySnapshot"));
|
|
27
|
+
const exportArtifactButton = /** @type {HTMLButtonElement} */ (document.getElementById("exportArtifact"));
|
|
28
|
+
const shareArtifactButton = /** @type {HTMLButtonElement} */ (document.getElementById("shareArtifact"));
|
|
29
|
+
const shareDialog = /** @type {HTMLDivElement} */ (document.getElementById("shareDialog"));
|
|
30
|
+
const shareForm = /** @type {HTMLFormElement} */ (document.getElementById("shareForm"));
|
|
31
|
+
const shareCloseButton = /** @type {HTMLButtonElement} */ (document.getElementById("shareClose"));
|
|
32
|
+
const shareCancelButton = /** @type {HTMLButtonElement} */ (document.getElementById("shareCancel"));
|
|
33
|
+
const sharePublishButton = /** @type {HTMLButtonElement} */ (document.getElementById("sharePublish"));
|
|
34
|
+
const sharePasswordInput = /** @type {HTMLInputElement} */ (document.getElementById("sharePassword"));
|
|
35
|
+
const shareStatus = /** @type {HTMLDivElement} */ (document.getElementById("shareStatus"));
|
|
36
|
+
const shareResult = /** @type {HTMLDivElement} */ (document.getElementById("shareResult"));
|
|
37
|
+
const shareUrlInput = /** @type {HTMLInputElement} */ (document.getElementById("shareUrl"));
|
|
38
|
+
const shareUpdateKeyInput = /** @type {HTMLInputElement} */ (document.getElementById("shareUpdateKey"));
|
|
39
|
+
const copyShareUrlButton = /** @type {HTMLButtonElement} */ (document.getElementById("copyShareUrl"));
|
|
40
|
+
const copyUpdateKeyButton = /** @type {HTMLButtonElement} */ (document.getElementById("copyUpdateKey"));
|
|
27
41
|
const endButton = /** @type {HTMLButtonElement} */ (document.getElementById("end"));
|
|
28
42
|
const copyPathButton = /** @type {HTMLButtonElement} */ (document.getElementById("copyPath"));
|
|
29
43
|
const copyHint = /** @type {HTMLSpanElement} */ (document.getElementById("copyHint"));
|
|
30
44
|
const copyHintText = /** @type {HTMLSpanElement} */ (document.getElementById("copyHintText"));
|
|
31
45
|
const presenceBanner = /** @type {HTMLDivElement} */ (document.getElementById("presenceBanner"));
|
|
32
46
|
const endedOverlay = /** @type {HTMLDivElement} */ (document.getElementById("endedOverlay"));
|
|
47
|
+
const layoutGateOverlay = /** @type {HTMLDivElement} */ (document.getElementById("layoutGateOverlay"));
|
|
48
|
+
const layoutGateTitle = /** @type {HTMLDivElement} */ (document.getElementById("layoutGateTitle"));
|
|
49
|
+
const layoutGateCopy = /** @type {HTMLParagraphElement} */ (document.getElementById("layoutGateCopy"));
|
|
50
|
+
const layoutGateAction = /** @type {HTMLButtonElement} */ (document.getElementById("layoutGateAction"));
|
|
51
|
+
const layoutIssueBanner = /** @type {HTMLDivElement} */ (document.getElementById("layoutIssueBanner"));
|
|
33
52
|
const sendHint = /** @type {HTMLSpanElement} */ (document.getElementById("sendHint"));
|
|
53
|
+
const artifactSrc = frame.dataset.artifactSrc || frame.getAttribute?.("data-artifact-src") || frame.src || "";
|
|
34
54
|
|
|
35
55
|
const queued = loadQueuedPrompts();
|
|
36
56
|
let annotation = true;
|
|
37
57
|
let ended = false;
|
|
38
58
|
let agentPresence = "waiting";
|
|
39
59
|
let pendingSnapshot = "";
|
|
60
|
+
const layoutGateEnabled = sessionData.layoutGateEnabled !== false;
|
|
61
|
+
const configuredLayoutGateMaxHoldMs = Number(sessionData.layoutGateMaxHoldMs);
|
|
62
|
+
const layoutGateMaxHoldMs =
|
|
63
|
+
Number.isFinite(configuredLayoutGateMaxHoldMs) && configuredLayoutGateMaxHoldMs > 0
|
|
64
|
+
? Math.min(configuredLayoutGateMaxHoldMs, 60_000)
|
|
65
|
+
: 12_000;
|
|
66
|
+
let layoutGateVisible = false;
|
|
67
|
+
let layoutGateArmed = false;
|
|
68
|
+
let layoutGateManuallyBypassed = !layoutGateEnabled;
|
|
69
|
+
let layoutGateCycle = 0;
|
|
70
|
+
/** @type {ReturnType<typeof setTimeout> | undefined} */
|
|
71
|
+
let layoutGateTimer;
|
|
40
72
|
const snapshotRequests = [];
|
|
41
73
|
let endAfterSubmit = false;
|
|
42
74
|
let workingBubble = null;
|
|
@@ -91,7 +123,7 @@ function render() {
|
|
|
91
123
|
escapeHtml(prompt.prompt) +
|
|
92
124
|
'</span><button class="pill-close" type="button" aria-label="Remove queued prompt" data-index="' +
|
|
93
125
|
index +
|
|
94
|
-
'"
|
|
126
|
+
'"><svg width="10" height="10" viewBox="0 0 10 10" fill="none" aria-hidden="true" focusable="false"><path d="M1 1L9 9M9 1L1 9" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg></button></div><div class="pill-tooltip">' +
|
|
95
127
|
(prompt.selector
|
|
96
128
|
? '<div class="tooltip-label">Target</div><div class="pill-tooltip-target">' +
|
|
97
129
|
escapeHtml(prompt.selector) +
|
|
@@ -322,6 +354,122 @@ async function submitQueuedOnce() {
|
|
|
322
354
|
if (agentPresence === "listening") setAgentPresence("working");
|
|
323
355
|
}
|
|
324
356
|
|
|
357
|
+
function normalizeLayoutWarningsPayload(value) {
|
|
358
|
+
return Array.isArray(value) ? value.filter((item) => item && typeof item === "object") : [];
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function isErrorLayoutWarning(warning) {
|
|
362
|
+
return String(warning?.severity || "").toLowerCase() === "error";
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function setLayoutIssueBanner(visible, text = "This surface may have layout issues. Your agent has been notified.") {
|
|
366
|
+
if (!layoutIssueBanner) return;
|
|
367
|
+
layoutIssueBanner.textContent = text;
|
|
368
|
+
layoutIssueBanner.hidden = !visible;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function clearLayoutGateTimer() {
|
|
372
|
+
if (layoutGateTimer) clearTimeout(layoutGateTimer);
|
|
373
|
+
layoutGateTimer = undefined;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function setLayoutGateCard(state) {
|
|
377
|
+
if (!layoutGateTitle || !layoutGateCopy) return;
|
|
378
|
+
|
|
379
|
+
if (state === "held") {
|
|
380
|
+
layoutGateTitle.innerHTML = "Fixing a layout issue...";
|
|
381
|
+
layoutGateCopy.textContent =
|
|
382
|
+
"The real browser found overflow or overlapping content. Your agent has been notified and this will reveal after the next clean reload.";
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
layoutGateTitle.innerHTML = "Checking layout.<br>One moment.";
|
|
387
|
+
layoutGateCopy.textContent = "Lavish is waiting for fonts and final geometry before revealing this artifact.";
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function setLayoutGateActive(active) {
|
|
391
|
+
layoutGateVisible = active;
|
|
392
|
+
if (layoutGateOverlay) layoutGateOverlay.hidden = !active;
|
|
393
|
+
document.body?.classList?.toggle("layout-gate-active", active);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function revealLayoutGate({ showBanner = false, bannerText = undefined } = {}) {
|
|
397
|
+
clearLayoutGateTimer();
|
|
398
|
+
layoutGateArmed = false;
|
|
399
|
+
setLayoutGateActive(false);
|
|
400
|
+
setLayoutIssueBanner(showBanner, bannerText);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function forceRevealLayoutGate(reason) {
|
|
404
|
+
if (!layoutGateEnabled || ended) return;
|
|
405
|
+
if (reason === "manual") layoutGateManuallyBypassed = true;
|
|
406
|
+
const bannerText =
|
|
407
|
+
reason === "timeout"
|
|
408
|
+
? "This surface may have layout issues. Lavish revealed it after the safety timeout so review is never blocked."
|
|
409
|
+
: "This surface may have layout issues. You chose to show it before the layout check passed.";
|
|
410
|
+
revealLayoutGate({ showBanner: true, bannerText });
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function startLayoutGateCycle() {
|
|
414
|
+
if (!layoutGateEnabled || layoutGateManuallyBypassed || ended) return;
|
|
415
|
+
|
|
416
|
+
layoutGateCycle += 1;
|
|
417
|
+
layoutGateArmed = true;
|
|
418
|
+
setLayoutIssueBanner(false);
|
|
419
|
+
setLayoutGateCard("checking");
|
|
420
|
+
setLayoutGateActive(true);
|
|
421
|
+
clearLayoutGateTimer();
|
|
422
|
+
|
|
423
|
+
const cycle = layoutGateCycle;
|
|
424
|
+
layoutGateTimer = setTimeout(() => {
|
|
425
|
+
if (cycle !== layoutGateCycle || !layoutGateVisible || ended) return;
|
|
426
|
+
forceRevealLayoutGate("timeout");
|
|
427
|
+
}, layoutGateMaxHoldMs);
|
|
428
|
+
layoutGateTimer?.unref?.();
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function handleLayoutWarningsForGate(layoutWarnings) {
|
|
432
|
+
const warnings = normalizeLayoutWarningsPayload(layoutWarnings);
|
|
433
|
+
const hasErrors = warnings.some(isErrorLayoutWarning);
|
|
434
|
+
|
|
435
|
+
if (!layoutGateEnabled) return;
|
|
436
|
+
|
|
437
|
+
if (layoutGateManuallyBypassed) {
|
|
438
|
+
setLayoutIssueBanner(hasErrors);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (!layoutGateArmed && !layoutGateVisible) return;
|
|
443
|
+
|
|
444
|
+
if (!hasErrors) {
|
|
445
|
+
revealLayoutGate();
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
setLayoutGateCard("held");
|
|
450
|
+
setLayoutGateActive(true);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function initializeLayoutGate() {
|
|
454
|
+
if (!layoutGateEnabled) {
|
|
455
|
+
setLayoutGateActive(false);
|
|
456
|
+
setLayoutIssueBanner(false);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (layoutGateAction) layoutGateAction.onclick = () => forceRevealLayoutGate("manual");
|
|
461
|
+
startLayoutGateCycle();
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
async function submitLayoutWarnings(layoutWarnings) {
|
|
465
|
+
const response = await fetch("/api/" + key + "/layout-warnings", {
|
|
466
|
+
method: "POST",
|
|
467
|
+
headers: { "content-type": "application/json" },
|
|
468
|
+
body: JSON.stringify({ layout_warnings: normalizeLayoutWarningsPayload(layoutWarnings) }),
|
|
469
|
+
});
|
|
470
|
+
if (!response.ok) throw new Error("failed to submit layout warnings");
|
|
471
|
+
}
|
|
472
|
+
|
|
325
473
|
async function endSession() {
|
|
326
474
|
if (ended) return;
|
|
327
475
|
const response = await fetch("/api/" + key + "/end", { method: "POST" });
|
|
@@ -333,6 +481,8 @@ async function endSession() {
|
|
|
333
481
|
chatInput.disabled = true;
|
|
334
482
|
updateSendState();
|
|
335
483
|
if (presenceBanner) presenceBanner.hidden = true;
|
|
484
|
+
layoutGateManuallyBypassed = true;
|
|
485
|
+
revealLayoutGate();
|
|
336
486
|
postToFrame({ type: "lavish:setAnnotationMode", enabled: false });
|
|
337
487
|
endedOverlay.hidden = false;
|
|
338
488
|
}
|
|
@@ -353,10 +503,136 @@ function copyDomSnapshot() {
|
|
|
353
503
|
requestSnapshot("copy");
|
|
354
504
|
}
|
|
355
505
|
|
|
506
|
+
function exportFileName() {
|
|
507
|
+
const base = (filePath.split(/[\\/]/).pop() || "artifact.html").replace(/\.html?$/i, "");
|
|
508
|
+
return (base || "artifact") + ".export.html";
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function setExportLabel(text) {
|
|
512
|
+
const label = exportArtifactButton.querySelector("span");
|
|
513
|
+
if (label) label.textContent = text;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function unresolvedAssetText(count) {
|
|
517
|
+
return count === 1 ? "1 unresolved asset" : `${count} unresolved assets`;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function noticeText(count) {
|
|
521
|
+
return count === 1 ? "1 notice" : `${count} notices`;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function exportWarningText(unresolvedCount, noticeCount) {
|
|
525
|
+
if (unresolvedCount > 0 && noticeCount > 0) {
|
|
526
|
+
return `${unresolvedAssetText(unresolvedCount)} and ${noticeText(noticeCount)}`;
|
|
527
|
+
}
|
|
528
|
+
if (unresolvedCount > 0) return unresolvedAssetText(unresolvedCount);
|
|
529
|
+
return noticeText(noticeCount);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
async function exportArtifact() {
|
|
533
|
+
// The bundle inlines local assets server-side, so it can take a moment - keep the menu open
|
|
534
|
+
// and narrate progress in place instead of closing it and leaving the user with no feedback.
|
|
535
|
+
exportArtifactButton.disabled = true;
|
|
536
|
+
setExportLabel("Exporting...");
|
|
537
|
+
try {
|
|
538
|
+
const response = await fetch("/api/" + key + "/export");
|
|
539
|
+
if (!response.ok) throw new Error("export failed");
|
|
540
|
+
const warningCount = Number(response.headers.get("x-lavish-export-warning-count") || "0");
|
|
541
|
+
const noticeCount = Number(response.headers.get("x-lavish-export-notice-count") || "0");
|
|
542
|
+
const blob = await response.blob();
|
|
543
|
+
const url = URL.createObjectURL(blob);
|
|
544
|
+
const link = document.createElement("a");
|
|
545
|
+
link.href = url;
|
|
546
|
+
link.download = exportFileName();
|
|
547
|
+
document.body.appendChild(link);
|
|
548
|
+
link.click();
|
|
549
|
+
link.remove();
|
|
550
|
+
setTimeout(() => URL.revokeObjectURL(url), 2000);
|
|
551
|
+
if (warningCount > 0 || noticeCount > 0) {
|
|
552
|
+
setExportLabel(`Exported with ${exportWarningText(warningCount, noticeCount)}`);
|
|
553
|
+
} else {
|
|
554
|
+
setExportLabel("Export standalone HTML");
|
|
555
|
+
closeMenus();
|
|
556
|
+
}
|
|
557
|
+
} catch {
|
|
558
|
+
setExportLabel("Export failed - retry");
|
|
559
|
+
} finally {
|
|
560
|
+
exportArtifactButton.disabled = false;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function openShareDialog() {
|
|
565
|
+
closeMenus();
|
|
566
|
+
shareDialog.hidden = false;
|
|
567
|
+
shareStatus.textContent = "";
|
|
568
|
+
shareStatus.classList.remove("error");
|
|
569
|
+
shareResult.hidden = true;
|
|
570
|
+
sharePasswordInput.value = "";
|
|
571
|
+
sharePasswordInput.focus();
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function closeShareDialog() {
|
|
575
|
+
shareDialog.hidden = true;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
async function copyToButton(value, button, label) {
|
|
579
|
+
await copyText(value);
|
|
580
|
+
button.textContent = "Copied";
|
|
581
|
+
setTimeout(() => {
|
|
582
|
+
button.textContent = label;
|
|
583
|
+
}, 1200);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
async function publishShare(event) {
|
|
587
|
+
event.preventDefault();
|
|
588
|
+
sharePublishButton.disabled = true;
|
|
589
|
+
shareStatus.classList.remove("error");
|
|
590
|
+
shareStatus.textContent = "Publishing to ht-ml.app...";
|
|
591
|
+
shareResult.hidden = true;
|
|
592
|
+
const password = sharePasswordInput.value.trim();
|
|
593
|
+
const passwordProtected = Boolean(password);
|
|
594
|
+
try {
|
|
595
|
+
const response = await fetch("/api/" + key + "/share", {
|
|
596
|
+
method: "POST",
|
|
597
|
+
headers: { "content-type": "application/json" },
|
|
598
|
+
body: JSON.stringify(password ? { password } : {}),
|
|
599
|
+
});
|
|
600
|
+
const data = await response.json();
|
|
601
|
+
if (!response.ok) throw new Error(data.error || "publish failed");
|
|
602
|
+
shareUrlInput.value = data.url || "";
|
|
603
|
+
shareUpdateKeyInput.value = data.update_key || "";
|
|
604
|
+
const unresolvedAssets = Array.isArray(data.unresolved_local_assets) ? data.unresolved_local_assets : [];
|
|
605
|
+
const notices = Array.isArray(data.notices) ? data.notices : [];
|
|
606
|
+
const warningCount = unresolvedAssets.length;
|
|
607
|
+
const noticeCount = notices.length;
|
|
608
|
+
const noticeSummary = noticeCount ? noticeText(noticeCount) : "";
|
|
609
|
+
shareStatus.textContent =
|
|
610
|
+
warningCount > 0
|
|
611
|
+
? `Published with ${warningCount === 1 ? "1 unresolved local asset" : `${warningCount} unresolved local assets`}${noticeSummary ? ` and ${noticeSummary}` : ""}.${passwordProtected ? " This page is PASSWORD-PROTECTED; viewers also need the password." : ""}`
|
|
612
|
+
: noticeCount > 0
|
|
613
|
+
? `Published with ${noticeSummary}.${passwordProtected ? " This page is PASSWORD-PROTECTED; viewers also need the password." : ""}`
|
|
614
|
+
: passwordProtected
|
|
615
|
+
? "Published. This page is PASSWORD-PROTECTED; viewers also need the password."
|
|
616
|
+
: "Published. Anyone with the link can view this page.";
|
|
617
|
+
shareResult.hidden = false;
|
|
618
|
+
shareUrlInput.focus();
|
|
619
|
+
shareUrlInput.select();
|
|
620
|
+
} catch (error) {
|
|
621
|
+
shareStatus.classList.add("error");
|
|
622
|
+
shareStatus.textContent = error instanceof Error ? error.message : String(error);
|
|
623
|
+
} finally {
|
|
624
|
+
sharePublishButton.disabled = false;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
356
628
|
function resetFrame() {
|
|
629
|
+
startLayoutGateCycle();
|
|
357
630
|
// The iframe is sandboxed, so reload by resetting the iframe URL from chrome.
|
|
358
|
-
|
|
359
|
-
|
|
631
|
+
frame.src = artifactSrc || frame.src;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
function loadFrame() {
|
|
635
|
+
if (artifactSrc) frame.src = artifactSrc;
|
|
360
636
|
}
|
|
361
637
|
|
|
362
638
|
function reloadArtifact() {
|
|
@@ -404,10 +680,16 @@ window.addEventListener("message", (event) => {
|
|
|
404
680
|
if (msg.type === "lavish:scroll") {
|
|
405
681
|
lastScroll = { x: Number(msg.x) || 0, y: Number(msg.y) || 0 };
|
|
406
682
|
}
|
|
683
|
+
if (msg.type === "lavish:layoutWarnings") {
|
|
684
|
+
handleLayoutWarningsForGate(msg.layout_warnings);
|
|
685
|
+
submitLayoutWarnings(msg.layout_warnings).catch(() => {});
|
|
686
|
+
}
|
|
407
687
|
if (msg.type === "lavish:sendQueuedPrompts") sendQueued();
|
|
408
688
|
if (msg.type === "lavish:endSession") endSession();
|
|
409
689
|
});
|
|
410
690
|
|
|
691
|
+
loadFrame();
|
|
692
|
+
|
|
411
693
|
annotationSwitch.onclick = () => {
|
|
412
694
|
annotation = !annotation;
|
|
413
695
|
annotationSwitch.setAttribute("aria-pressed", String(annotation));
|
|
@@ -429,6 +711,16 @@ chatInput.addEventListener("input", hideSendHint);
|
|
|
429
711
|
copyPathButton.onclick = copyFilePath;
|
|
430
712
|
reloadArtifactButton.onclick = reloadArtifact;
|
|
431
713
|
copySnapshotButton.onclick = copyDomSnapshot;
|
|
714
|
+
exportArtifactButton.onclick = exportArtifact;
|
|
715
|
+
shareArtifactButton.onclick = openShareDialog;
|
|
716
|
+
shareCloseButton.onclick = closeShareDialog;
|
|
717
|
+
shareCancelButton.onclick = closeShareDialog;
|
|
718
|
+
shareForm.addEventListener("submit", publishShare);
|
|
719
|
+
shareDialog.addEventListener("click", (event) => {
|
|
720
|
+
if (event.target === shareDialog) closeShareDialog();
|
|
721
|
+
});
|
|
722
|
+
copyShareUrlButton.onclick = () => copyToButton(shareUrlInput.value, copyShareUrlButton, "Copy URL");
|
|
723
|
+
copyUpdateKeyButton.onclick = () => copyToButton(shareUpdateKeyInput.value, copyUpdateKeyButton, "Copy key");
|
|
432
724
|
endButton.onclick = () => {
|
|
433
725
|
closeMenus();
|
|
434
726
|
endSession();
|
|
@@ -439,7 +731,13 @@ document.addEventListener("mousedown", (event) => {
|
|
|
439
731
|
if (!sendMenu.hidden && !sendActions.contains(target)) setMenuOpen(sendCaret, sendMenu, false);
|
|
440
732
|
});
|
|
441
733
|
document.addEventListener("keydown", (event) => {
|
|
442
|
-
if (event.key === "Escape")
|
|
734
|
+
if (event.key === "Escape") {
|
|
735
|
+
if (!shareDialog.hidden) {
|
|
736
|
+
closeShareDialog();
|
|
737
|
+
} else {
|
|
738
|
+
closeMenus();
|
|
739
|
+
}
|
|
740
|
+
}
|
|
443
741
|
});
|
|
444
742
|
frame.addEventListener("load", () => {
|
|
445
743
|
postToFrame({ type: "lavish:setAnnotationMode", enabled: annotation && !ended });
|
|
@@ -447,6 +745,8 @@ frame.addEventListener("load", () => {
|
|
|
447
745
|
postToFrame({ type: "lavish:restoreScroll", x: lastScroll.x, y: lastScroll.y });
|
|
448
746
|
});
|
|
449
747
|
|
|
748
|
+
initializeLayoutGate();
|
|
749
|
+
|
|
450
750
|
const events = new EventSource("/events/" + key);
|
|
451
751
|
events.addEventListener("reload", () => resetFrame());
|
|
452
752
|
events.addEventListener("chrome-reload", () => reloadAfterServerRestart());
|