diff --git a/.changes/planning/fix-17991-copy-chosen-design-2f5881f0.md b/.changes/planning/fix-17991-copy-chosen-design-2f5881f0.md
new file mode 100644
index 0000000000..5076e1748b
--- /dev/null
+++ b/.changes/planning/fix-17991-copy-chosen-design-2f5881f0.md
@@ -0,0 +1,7 @@
+---
+bump: patch
+---
+
+### Changed
+
+- Shared `proto-pin.js` synced where this plugin carries it: the frame helper answers a host page's copy-out ask with the page's copy-out text; no other change to this plugin.
diff --git a/.changes/prototype/fix-17991-copy-chosen-design-694e6c08.md b/.changes/prototype/fix-17991-copy-chosen-design-694e6c08.md
new file mode 100644
index 0000000000..40cf01c519
--- /dev/null
+++ b/.changes/prototype/fix-17991-copy-chosen-design-694e6c08.md
@@ -0,0 +1,7 @@
+---
+bump: minor
+---
+
+### Added
+
+- The notes host page's Copy menu has Copy chosen design: it copies the text the mockup's own copy-out terminator gives, which a mockup builds in `window.uiFeedbackCopyOut`. Framed by the host page, the mockup's data bar, marked `data-harness-chrome`, hides, and the bar's Sample data menu presses its controls; opened alone from `file://` the page keeps its own bar.
diff --git a/docs/contracts/ui-feedback/README.md b/docs/contracts/ui-feedback/README.md
index 430c0741e7..08ed8dd8c0 100644
--- a/docs/contracts/ui-feedback/README.md
+++ b/docs/contracts/ui-feedback/README.md
@@ -105,6 +105,14 @@ validator checks every note, takes all or none, skips a note already in the log,
imported notes toward `x-maxNotesPerRun`, and refuses while a server runs on the data dir. The
block is data like any note; it is never run as text.
+Copy chosen design copies the mockup's own copy-out terminator text. A page whose terminator text
+comes from a `window.uiFeedbackCopyOut()` function returning a string says so in the ready message
+(`copyOut: true`). The host page then asks with `{type: "copy-out"}`, and the frame helper answers
+`{type: "chosen", text}`. The host page keeps one reply per ask, and only when `chosenFrom`
+(`frame-channel.mjs`) admits it: a non-empty string of at most 8000 code points, kept whole, with
+no `<` before a letter, `!`, `/` or `?`, and no control character but tab and line breaks. It sets
+the text as a textarea value and copies it; it never renders it as markup.
+
## Controls
`controls.schema.json` defines the controls manifest: the one list of what can vary on the framed
diff --git a/lib/ui-feedback/frame-channel.mjs b/lib/ui-feedback/frame-channel.mjs
index 366eb90be2..a1b395a1dd 100644
--- a/lib/ui-feedback/frame-channel.mjs
+++ b/lib/ui-feedback/frame-channel.mjs
@@ -48,6 +48,21 @@ export function namesFrom(m) {
return out;
}
+/** The most code points a chosen design keeps: two note texts (note.schema.json's text maxLength is 4000). */
+const CHOSEN_MAX = 8000;
+const MARKUP = /<[A-Za-z!/?]/;
+const CONTROL = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
+
+/**
+ * The text of the frame's chosen-design reply (the mockup's copy-out terminator text), whole and as sent, or null when
+ * the message is not a `chosen` one, its text is not a non-empty string, runs past 8000 code points, or holds a tag,
+ * comment or processing instruction, or a control character other than tab and line breaks.
+ */
+export function chosenFrom(m) {
+ const t = m?.type === "chosen" && typeof m.text === "string" ? m.text : "";
+ return t.trim() && [...t].length <= CHOSEN_MAX && !MARKUP.test(t) && !CONTROL.test(t) ? t : null;
+}
+
/**
* Calls `onBlocked` unless the returned function is called first, within `ms`. On a frame a CSP
* blocks, Firefox fires no load event and Chrome fires one
diff --git a/lib/ui-feedback/frame-channel.test.mjs b/lib/ui-feedback/frame-channel.test.mjs
index 59fca93e34..febc6fbd08 100644
--- a/lib/ui-feedback/frame-channel.test.mjs
+++ b/lib/ui-feedback/frame-channel.test.mjs
@@ -1,7 +1,7 @@
import { strict as assert } from "node:assert";
import { readFileSync } from "node:fs";
import { test } from "node:test";
-import { awaitReady, frameTarget, fromFrame, namesFrom, READY_MS, viewFrom } from "./frame-channel.mjs";
+import { awaitReady, chosenFrom, frameTarget, fromFrame, namesFrom, READY_MS, viewFrom } from "./frame-channel.mjs";
const DEV = "http://localhost:5173";
const HOST = readFileSync(new URL("./host.html", import.meta.url), "utf8");
@@ -149,3 +149,26 @@ test("the frame's names for listed notes keep positive integer keys and string p
]);
assert.deepEqual([...namesFrom({ names: "x" })], []);
});
+
+const CHOSEN = "direction: B Cards\nnotes: keep the status pill; a < b stays text\ntest-ids: B: shipments-row, shipments-title\n";
+
+test("the frame's chosen design is kept whole, its lines and spacing as sent", () => {
+ assert.equal(chosenFrom({ type: "chosen", text: CHOSEN }), CHOSEN);
+});
+
+test("a chosen design of 8000 code points is kept and one of 8001 is refused, never cut", () => {
+ assert.equal(chosenFrom({ type: "chosen", text: "😀".repeat(8000) }), "😀".repeat(8000));
+ assert.equal(chosenFrom({ type: "chosen", text: "😀".repeat(8001) }), null);
+});
+
+test("a chosen-design message of another type, or whose text is not a non-empty string, is refused", () => {
+ for (const m of [{ type: "named", text: CHOSEN }, { text: CHOSEN }, { type: "chosen", text: 7 }, { type: "chosen", text: ["a"] }, { type: "chosen" }, { type: "chosen", text: " \n " }, null, "chosen"]) {
+ assert.equal(chosenFrom(m), null, JSON.stringify(m));
+ }
+});
+
+test("a chosen design holding markup or a control character is refused", () => {
+ for (const text of ['notes: ', "ab", "", "", "", "bell\u0007", "nul\u0000"]) {
+ assert.equal(chosenFrom({ type: "chosen", text }), null, JSON.stringify(text));
+ }
+});
diff --git a/lib/ui-feedback/host.html b/lib/ui-feedback/host.html
index c3f6a08159..5677eb8059 100644
--- a/lib/ui-feedback/host.html
+++ b/lib/ui-feedback/host.html
@@ -234,6 +234,7 @@
Copy
diff --git a/lib/ui-feedback/host.mjs b/lib/ui-feedback/host.mjs
index a827d2bdf5..0a10f92604 100644
--- a/lib/ui-feedback/host.mjs
+++ b/lib/ui-feedback/host.mjs
@@ -1,5 +1,5 @@
import { draftStore, problems, readerName, use } from "/note-model.mjs";
-import { awaitReady, frameTarget, fromFrame, namesFrom, READY_MS, viewFrom } from "/frame-channel.mjs";
+import { awaitReady, chosenFrom, frameTarget, fromFrame, namesFrom, READY_MS, viewFrom } from "/frame-channel.mjs";
import { edges } from "/bar-edges.mjs";
const $ = (id) => document.getElementById(id);
@@ -44,6 +44,7 @@ function takeControls(m) {
: m.controls === false ? "The mockup's controls manifest is not JSON, so only its built-in controls are here."
: m.controls == null ? "The mockup has no controls manifest." : `${controls.length} control(s) from the mockup's manifest.`;
for (const b of [$("copy-config"), $("reset-controls"), $("copy-values")]) b.disabled = !controls.length;
+ $("copy-chosen").disabled = m.copyOut !== true;
renderControls();
renderSteps();
}
@@ -551,6 +552,30 @@ function copyAll() {
else manual();
}
+/** The mockup's copy-out terminator text, asked of the frame; only the one reply to an ask is copied, as text. */
+let wantChosen = false;
+function askChosen() {
+ closeMenus();
+ $("copy-button").focus();
+ wantChosen = true;
+ toFrame({ type: "copy-out" });
+}
+function copyChosen(m) {
+ wantChosen = false;
+ if ($("panel").hidden) setPanel(true);
+ selectTab(tabs[0], false);
+ if (typeof m.text !== "string") return say("The mockup's copy-out function gave nothing, so nothing was copied; see the mockup's console.");
+ const text = chosenFrom(m);
+ if (text === null) return say("The mockup's chosen design is not plain text of at most 8000 characters, so nothing was copied.");
+ $("block").value = text;
+ $("copyout").hidden = false;
+ $("block").select();
+ const done = () => say("Copied the chosen design. Paste it to Claude.");
+ const manual = () => say("Select the text below and copy it, then paste it to Claude.");
+ if (navigator.clipboard) navigator.clipboard.writeText(text).then(done, manual);
+ else manual();
+}
+
function render() {
const listening = noSession
? "No session: the notes server is not answering. Your notes stay on this page; Copy all notes makes a block to paste to Claude."
@@ -682,6 +707,7 @@ addEventListener("message", (e) => {
else if (m.type === "shown" && m.found === false && chosen) say("That note's place is not on the mockup now, so no box is drawn.");
else if (m.type === "content" && fits(m.name, schema.properties.content)) { content = m.name; renderControls(); }
else if (m.type === "want-text") askText();
+ else if (m.type === "chosen" && wantChosen) copyChosen(m);
else if (m.type === "key" && FRAME_KEYS.has(m.key)) shortcut(m.key);
else if (m.type === "pinned" && picking === "element") {
const note = noteFrom(m, "element");
@@ -719,6 +745,7 @@ $("dock").addEventListener("click", () => setPanel($("panel").hidden));
$("markers").addEventListener("click", () => setMarkers(!markersShown));
$("cancel").addEventListener("click", closeComposer);
$("copy").addEventListener("click", copyAll);
+$("copy-chosen").addEventListener("click", askChosen);
$("copy-config").addEventListener("click", copyConfig);
$("copy-values").addEventListener("click", () => { closeMenus(); $("copy-button").focus(); if ($("panel").hidden) setPanel(true); selectTab(tabs[1], false); copyConfig(); });
$("side").addEventListener("click", () => setSide($("panel").dataset.side === "start" ? "end" : "start"));
@@ -794,7 +821,7 @@ try {
if (loads > 1) {
ready = false;
picking = null;
- for (const b of [...Object.values(buttons), $("quote"), $("controls-fields"), $("copy-config"), $("reset-controls"), $("copy-values"), $("vprev"), $("vnext")]) b.disabled = true;
+ for (const b of [...Object.values(buttons), $("quote"), $("controls-fields"), $("copy-config"), $("reset-controls"), $("copy-values"), $("copy-chosen"), $("vprev"), $("vnext")]) b.disabled = true;
for (const b of $("data-list").children) b.disabled = true;
say("The mockup loaded another page in its frame, so this page stopped listening to it. Reload to start again.");
$("controls-status").textContent = "The mockup loaded another page in its frame, so these controls no longer reach it. Reload to start again.";
diff --git a/lib/ui-feedback/proto-pin.js b/lib/ui-feedback/proto-pin.js
index 25553e2e7e..89188a5e21 100644
--- a/lib/ui-feedback/proto-pin.js
+++ b/lib/ui-feedback/proto-pin.js
@@ -633,6 +633,7 @@
else if (m.type === "name") names(m.targets);
else if (m.type === "set") setControls(m.values);
else if (m.type === "press" && !mode) replay([m.step]);
+ else if (m.type === "copy-out") post({ type: "chosen", text: copyOut() });
else if (m.type === "focus") {
const p = pins.find(x => x.n === m.n);
if (!p) return;
@@ -641,9 +642,20 @@
else scrollTo({ top: Math.max(0, at.y - innerHeight / 3), behavior });
}
});
+ /** The page's copy-out terminator text, from the function its own terminator calls; null when it has none. */
+ function copyOut() {
+ try {
+ const t = typeof window.uiFeedbackCopyOut === "function" ? window.uiFeedbackCopyOut() : null;
+ return typeof t === "string" ? t : null;
+ } catch (err) {
+ console.error("ui-feedback: the page's uiFeedbackCopyOut threw", err);
+ return null;
+ }
+ }
const marks = [...document.querySelectorAll("[data-data-control]")].map(stepOf).filter(Boolean);
post({
type: "ready",
+ copyOut: typeof window.uiFeedbackCopyOut === "function",
controls: window.uiFeedbackControls?.manifest() ?? null,
data: [...new Map(marks.map(m => [JSON.stringify(m), m])).values()],
content: document.querySelector('[data-content-set="demo"]') && document.querySelector('[data-content-set="worst"]') ? root.dataset.vsContent || null : null,
diff --git a/plugins/planning/shared/web/proto-pin.js b/plugins/planning/shared/web/proto-pin.js
index a230a91069..7b9b3c9e54 100644
--- a/plugins/planning/shared/web/proto-pin.js
+++ b/plugins/planning/shared/web/proto-pin.js
@@ -635,6 +635,7 @@
else if (m.type === "name") names(m.targets);
else if (m.type === "set") setControls(m.values);
else if (m.type === "press" && !mode) replay([m.step]);
+ else if (m.type === "copy-out") post({ type: "chosen", text: copyOut() });
else if (m.type === "focus") {
const p = pins.find(x => x.n === m.n);
if (!p) return;
@@ -643,9 +644,20 @@
else scrollTo({ top: Math.max(0, at.y - innerHeight / 3), behavior });
}
});
+ /** The page's copy-out terminator text, from the function its own terminator calls; null when it has none. */
+ function copyOut() {
+ try {
+ const t = typeof window.uiFeedbackCopyOut === "function" ? window.uiFeedbackCopyOut() : null;
+ return typeof t === "string" ? t : null;
+ } catch (err) {
+ console.error("ui-feedback: the page's uiFeedbackCopyOut threw", err);
+ return null;
+ }
+ }
const marks = [...document.querySelectorAll("[data-data-control]")].map(stepOf).filter(Boolean);
post({
type: "ready",
+ copyOut: typeof window.uiFeedbackCopyOut === "function",
controls: window.uiFeedbackControls?.manifest() ?? null,
data: [...new Map(marks.map(m => [JSON.stringify(m), m])).values()],
content: document.querySelector('[data-content-set="demo"]') && document.querySelector('[data-content-set="worst"]') ? root.dataset.vsContent || null : null,
diff --git a/plugins/prototype/notes-bridge/frame-channel.mjs b/plugins/prototype/notes-bridge/frame-channel.mjs
index 06e7f4c324..da470892ab 100644
--- a/plugins/prototype/notes-bridge/frame-channel.mjs
+++ b/plugins/prototype/notes-bridge/frame-channel.mjs
@@ -50,6 +50,21 @@ export function namesFrom(m) {
return out;
}
+/** The most code points a chosen design keeps: two note texts (note.schema.json's text maxLength is 4000). */
+const CHOSEN_MAX = 8000;
+const MARKUP = /<[A-Za-z!/?]/;
+const CONTROL = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
+
+/**
+ * The text of the frame's chosen-design reply (the mockup's copy-out terminator text), whole and as sent, or null when
+ * the message is not a `chosen` one, its text is not a non-empty string, runs past 8000 code points, or holds a tag,
+ * comment or processing instruction, or a control character other than tab and line breaks.
+ */
+export function chosenFrom(m) {
+ const t = m?.type === "chosen" && typeof m.text === "string" ? m.text : "";
+ return t.trim() && [...t].length <= CHOSEN_MAX && !MARKUP.test(t) && !CONTROL.test(t) ? t : null;
+}
+
/**
* Calls `onBlocked` unless the returned function is called first, within `ms`. On a frame a CSP
* blocks, Firefox fires no load event and Chrome fires one
diff --git a/plugins/prototype/notes-bridge/host.html b/plugins/prototype/notes-bridge/host.html
index af3fa87790..ab9432c20c 100644
--- a/plugins/prototype/notes-bridge/host.html
+++ b/plugins/prototype/notes-bridge/host.html
@@ -236,6 +236,7 @@
Copy
diff --git a/plugins/prototype/notes-bridge/host.mjs b/plugins/prototype/notes-bridge/host.mjs
index d61f216804..56c90527ec 100644
--- a/plugins/prototype/notes-bridge/host.mjs
+++ b/plugins/prototype/notes-bridge/host.mjs
@@ -1,7 +1,7 @@
// GENERATED from lib/ui-feedback/host.mjs by scripts/sync-shared-copies.sh. Do not edit this copy:
// edit the canonical source, then rerun the script.
import { draftStore, problems, readerName, use } from "/note-model.mjs";
-import { awaitReady, frameTarget, fromFrame, namesFrom, READY_MS, viewFrom } from "/frame-channel.mjs";
+import { awaitReady, chosenFrom, frameTarget, fromFrame, namesFrom, READY_MS, viewFrom } from "/frame-channel.mjs";
import { edges } from "/bar-edges.mjs";
const $ = (id) => document.getElementById(id);
@@ -46,6 +46,7 @@ function takeControls(m) {
: m.controls === false ? "The mockup's controls manifest is not JSON, so only its built-in controls are here."
: m.controls == null ? "The mockup has no controls manifest." : `${controls.length} control(s) from the mockup's manifest.`;
for (const b of [$("copy-config"), $("reset-controls"), $("copy-values")]) b.disabled = !controls.length;
+ $("copy-chosen").disabled = m.copyOut !== true;
renderControls();
renderSteps();
}
@@ -553,6 +554,30 @@ function copyAll() {
else manual();
}
+/** The mockup's copy-out terminator text, asked of the frame; only the one reply to an ask is copied, as text. */
+let wantChosen = false;
+function askChosen() {
+ closeMenus();
+ $("copy-button").focus();
+ wantChosen = true;
+ toFrame({ type: "copy-out" });
+}
+function copyChosen(m) {
+ wantChosen = false;
+ if ($("panel").hidden) setPanel(true);
+ selectTab(tabs[0], false);
+ if (typeof m.text !== "string") return say("The mockup's copy-out function gave nothing, so nothing was copied; see the mockup's console.");
+ const text = chosenFrom(m);
+ if (text === null) return say("The mockup's chosen design is not plain text of at most 8000 characters, so nothing was copied.");
+ $("block").value = text;
+ $("copyout").hidden = false;
+ $("block").select();
+ const done = () => say("Copied the chosen design. Paste it to Claude.");
+ const manual = () => say("Select the text below and copy it, then paste it to Claude.");
+ if (navigator.clipboard) navigator.clipboard.writeText(text).then(done, manual);
+ else manual();
+}
+
function render() {
const listening = noSession
? "No session: the notes server is not answering. Your notes stay on this page; Copy all notes makes a block to paste to Claude."
@@ -684,6 +709,7 @@ addEventListener("message", (e) => {
else if (m.type === "shown" && m.found === false && chosen) say("That note's place is not on the mockup now, so no box is drawn.");
else if (m.type === "content" && fits(m.name, schema.properties.content)) { content = m.name; renderControls(); }
else if (m.type === "want-text") askText();
+ else if (m.type === "chosen" && wantChosen) copyChosen(m);
else if (m.type === "key" && FRAME_KEYS.has(m.key)) shortcut(m.key);
else if (m.type === "pinned" && picking === "element") {
const note = noteFrom(m, "element");
@@ -721,6 +747,7 @@ $("dock").addEventListener("click", () => setPanel($("panel").hidden));
$("markers").addEventListener("click", () => setMarkers(!markersShown));
$("cancel").addEventListener("click", closeComposer);
$("copy").addEventListener("click", copyAll);
+$("copy-chosen").addEventListener("click", askChosen);
$("copy-config").addEventListener("click", copyConfig);
$("copy-values").addEventListener("click", () => { closeMenus(); $("copy-button").focus(); if ($("panel").hidden) setPanel(true); selectTab(tabs[1], false); copyConfig(); });
$("side").addEventListener("click", () => setSide($("panel").dataset.side === "start" ? "end" : "start"));
@@ -796,7 +823,7 @@ try {
if (loads > 1) {
ready = false;
picking = null;
- for (const b of [...Object.values(buttons), $("quote"), $("controls-fields"), $("copy-config"), $("reset-controls"), $("copy-values"), $("vprev"), $("vnext")]) b.disabled = true;
+ for (const b of [...Object.values(buttons), $("quote"), $("controls-fields"), $("copy-config"), $("reset-controls"), $("copy-values"), $("copy-chosen"), $("vprev"), $("vnext")]) b.disabled = true;
for (const b of $("data-list").children) b.disabled = true;
say("The mockup loaded another page in its frame, so this page stopped listening to it. Reload to start again.");
$("controls-status").textContent = "The mockup loaded another page in its frame, so these controls no longer reach it. Reload to start again.";
diff --git a/plugins/prototype/notes-bridge/proto-pin.js b/plugins/prototype/notes-bridge/proto-pin.js
index a230a91069..7b9b3c9e54 100644
--- a/plugins/prototype/notes-bridge/proto-pin.js
+++ b/plugins/prototype/notes-bridge/proto-pin.js
@@ -635,6 +635,7 @@
else if (m.type === "name") names(m.targets);
else if (m.type === "set") setControls(m.values);
else if (m.type === "press" && !mode) replay([m.step]);
+ else if (m.type === "copy-out") post({ type: "chosen", text: copyOut() });
else if (m.type === "focus") {
const p = pins.find(x => x.n === m.n);
if (!p) return;
@@ -643,9 +644,20 @@
else scrollTo({ top: Math.max(0, at.y - innerHeight / 3), behavior });
}
});
+ /** The page's copy-out terminator text, from the function its own terminator calls; null when it has none. */
+ function copyOut() {
+ try {
+ const t = typeof window.uiFeedbackCopyOut === "function" ? window.uiFeedbackCopyOut() : null;
+ return typeof t === "string" ? t : null;
+ } catch (err) {
+ console.error("ui-feedback: the page's uiFeedbackCopyOut threw", err);
+ return null;
+ }
+ }
const marks = [...document.querySelectorAll("[data-data-control]")].map(stepOf).filter(Boolean);
post({
type: "ready",
+ copyOut: typeof window.uiFeedbackCopyOut === "function",
controls: window.uiFeedbackControls?.manifest() ?? null,
data: [...new Map(marks.map(m => [JSON.stringify(m), m])).values()],
content: document.querySelector('[data-content-set="demo"]') && document.querySelector('[data-content-set="worst"]') ? root.dataset.vsContent || null : null,
diff --git a/plugins/prototype/skills/explore-directions/SKILL.md b/plugins/prototype/skills/explore-directions/SKILL.md
index 91d58c8b0a..40fd99662f 100644
--- a/plugins/prototype/skills/explore-directions/SKILL.md
+++ b/plugins/prototype/skills/explore-directions/SKILL.md
@@ -169,7 +169,7 @@ page with synthetic data and an in-page switcher. Assemble one per task:
3. **A copy-out terminator**, a small control that lifts the winning-variant key, notes and the
proposed test ids back out as text you can paste into your durable answer. It lists the test
ids per variant, read from the page's `data-testid` attributes rather than typed out, so the
- list matches the markup.
+ list matches the markup. Build its text as [reference/feedback.md](reference/feedback.md#the-copy-out-function) says.
Constraints:
diff --git a/plugins/prototype/skills/explore-directions/assets/variant-switcher.html b/plugins/prototype/skills/explore-directions/assets/variant-switcher.html
index cc1101acf1..90636caf5c 100644
--- a/plugins/prototype/skills/explore-directions/assets/variant-switcher.html
+++ b/plugins/prototype/skills/explore-directions/assets/variant-switcher.html
@@ -26,6 +26,8 @@
elements inside it are lost: wire variant interactions with listeners delegated from document.
Chrome, not a contestant: leave its look alone. It takes the notes host page's light and dark
tokens, and it hides when that page frames the mockup, whose command bar steps the variants.
+ Under that bar it also hides every element marked data-harness-chrome, such as the page's data
+ bar, whose controls the bar's Sample data menu presses.
-->
@@ -64,7 +66,7 @@
--uif-shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 10px 32px rgb(0 0 0 / 0.5);
}
}
- :root[data-ui-feedback-bar] .vs { display: none; }
+ :root[data-ui-feedback-bar] .vs, :root[data-ui-feedback-bar] [data-harness-chrome] { display: none !important; }
.vs {
position: fixed;
inset-block-end: 24px;
diff --git a/plugins/prototype/skills/explore-directions/reference/data-controls.md b/plugins/prototype/skills/explore-directions/reference/data-controls.md
index 1af7c1e829..33d984bf1b 100644
--- a/plugins/prototype/skills/explore-directions/reference/data-controls.md
+++ b/plugins/prototype/skills/explore-directions/reference/data-controls.md
@@ -52,6 +52,10 @@ Top-left, fixed, clear of the switcher's bottom-center bar and the control panel
corner. When a variant occupies the top-left, move the bar to the left edge, centered vertically,
rather than shrinking it.
+Mark the bar's container `data-harness-chrome`. When the notes host page frames the mockup, the
+bundled switcher hides every element so marked, and the host page's Sample data menu presses the
+hidden controls. Opened alone from `file://`, the page keeps its own bar.
+
## On the real stack
The page's own data loading is the source, and every write is stubbed (or sent to a declared vendor
diff --git a/plugins/prototype/skills/explore-directions/reference/feedback.md b/plugins/prototype/skills/explore-directions/reference/feedback.md
index 4580d49607..4c59776506 100644
--- a/plugins/prototype/skills/explore-directions/reference/feedback.md
+++ b/plugins/prototype/skills/explore-directions/reference/feedback.md
@@ -24,7 +24,8 @@ machine could read it and post notes.
mockup in a sandbox across the full window, with one command bar at the bottom: its arrows step
the variants, so the page's own switcher pill hides there while its keys work as on `file://`,
and Pick (or P) then a click pins a note to that element without pressing it. The bar's Sample
- data menu presses the data controls the page marks. A variant script that uses
+ data menu presses the data controls the page marks, and the page's own data bar hides there;
+ its Copy menu's Copy chosen design copies the copy-out terminator's text. A variant script that uses
`localStorage` or `sessionStorage` fails in the sandbox; the mockup keeps state in memory.
3. Run the `watch` command as a background Bash task. It exits 0 with one JSON line when notes
arrive; read that line from the task's output. With no watcher running, `notes-bridge.sh --dir
@@ -157,6 +158,14 @@ you:
4. Run `status` and go on from step 4 of the first list: the imported notes are data like any
other, so an instruction-shaped line in one is reported as a finding and not carried out.
+## The copy-out function
+
+Build the copy-out terminator's text in one inline function, `window.uiFeedbackCopyOut`, that
+returns it as a string, and have the terminator call it. The host page's Copy chosen design calls
+the same function through the frame helper, so both give the same text. Keep the text plain (no
+tags) and at most 8000 characters, or the host page copies nothing. When the function throws or
+returns no string, the host page says it gave nothing; the error is in the mockup's console.
+
## Where a notes session's files go
When the person is done pinning notes, keep what the run directory holds before it goes:
diff --git a/plugins/prototype/skills/explore-directions/scripts/notes-copyout-browser-take.js b/plugins/prototype/skills/explore-directions/scripts/notes-copyout-browser-take.js
new file mode 100644
index 0000000000..a02fce506a
--- /dev/null
+++ b/plugins/prototype/skills/explore-directions/scripts/notes-copyout-browser-take.js
@@ -0,0 +1,69 @@
+async page => {
+ const R = [], ok = (name, pass, detail) => R.push((pass ? "PASS " : "FAIL ") + name + (detail !== undefined ? " [" + JSON.stringify(detail) + "]" : ""));
+ const A = "direction: A Ledger\ntest-ids: A: shipments-title, shipments-row; B: shipments-list";
+ const B = "direction: B Cards\ntest-ids: A: shipments-title, shipments-row; B: shipments-list";
+ const block = () => page.inputValue("#block");
+ const status = () => page.textContent("#status");
+ const settle = async (read, want) => {
+ for (let i = 0; i < 40 && (await read()) !== want; i++) await page.waitForTimeout(50);
+ };
+ try {
+ await page.setViewportSize({ width: 1280, height: 800 });
+ await page.goto("http://127.0.0.1:__PORT__/");
+ await page.waitForFunction(() => !document.getElementById("pick").disabled, null, { timeout: 10000 });
+ const frame = page.frames().find((f) => f !== page.mainFrame());
+ const inFrame = page.frameLocator("#page");
+ const rows = () => inFrame.locator('[data-testid="shipments-row"]').count();
+
+ await settle(() => inFrame.locator(".bar").isHidden(), true);
+ ok("framed, the mockup's own data bar is hidden", await inFrame.locator(".bar").isHidden());
+ await page.click("#data");
+ await page.getByRole("button", { name: "seed 10" }).click();
+ await settle(rows, 13);
+ ok("Sample data still presses the hidden bar's Seed control", (await rows()) === 13, await rows());
+
+ await page.click("#copy-button");
+ ok("the Copy menu offers Copy chosen design, on", await page.isEnabled("#copy-chosen"));
+ await page.click("#copy-chosen");
+ await settle(block, A);
+ ok("Copy chosen design copies the shown variant's copy-out text", (await block()) === A, await block());
+ ok("it is the text the page's own copy-out gives", (await block()) === (await frame.evaluate(() => window.uiFeedbackCopyOut())));
+ ok("the copy is said in the status line", /Copied the chosen design/.test(await status()), await status());
+
+ await page.click("#vnext");
+ await page.click("#copy-button");
+ await page.click("#copy-chosen");
+ await settle(block, B);
+ ok("after the view arrows show variant B, the copy names B", (await block()) === B, await block());
+
+ await frame.evaluate(() => { window.__markup = true; });
+ await page.click("#copy-button");
+ await page.click("#copy-chosen");
+ await page.waitForFunction(() => /nothing was copied/.test(document.getElementById("status").textContent), null, { timeout: 5000 }).catch(() => {});
+ ok("a copy-out holding markup copies nothing and says why", (await block()) === B && /nothing was copied/.test(await status()), [await block(), await status()]);
+ ok("and makes no element and runs no handler", (await page.$$("#panel img")).length === 0 && await page.evaluate(() => window.__xss) === undefined);
+
+ for (const why of ["throws", "returns no string", "is gone"]) {
+ await frame.evaluate((w) => {
+ window.uiFeedbackCopyOut = w === "throws" ? () => { throw new Error("broken copy-out"); } : w === "returns no string" ? () => 42 : undefined;
+ }, why);
+ await page.click("#copy-button");
+ await page.click("#copy-chosen");
+ await page.waitForFunction(() => /gave nothing/.test(document.getElementById("status").textContent), null, { timeout: 5000 }).catch(() => {});
+ ok(`when the page's copy-out function ${why}, nothing is copied and the status says it gave nothing`, (await block()) === B && /gave nothing.*console/.test(await status()), [await block(), await status()]);
+ await page.evaluate(() => { document.getElementById("status").textContent = ""; });
+ }
+
+ await frame.evaluate(() => window.parent.postMessage({ type: "chosen", text: "unasked" }, "*"));
+ await page.waitForTimeout(300);
+ ok("a chosen-design message the host page did not ask for copies nothing", (await block()) === B, await block());
+
+ await page.goto("__FILE__");
+ ok("opened alone from file://, the page keeps its data bar", await page.isVisible(".bar"));
+ await page.click("#copy-out");
+ ok("and its own copy-out gives the same text", (await page.textContent("#copied")) === A, await page.textContent("#copied"));
+ } catch (e) {
+ R.push("ERROR " + String(e).split("\n")[0]);
+ }
+ return R.join("\n");
+}
diff --git a/plugins/prototype/skills/explore-directions/scripts/notes-copyout-browser.test.sh b/plugins/prototype/skills/explore-directions/scripts/notes-copyout-browser.test.sh
new file mode 100755
index 0000000000..13e59ebd57
--- /dev/null
+++ b/plugins/prototype/skills/explore-directions/scripts/notes-copyout-browser.test.sh
@@ -0,0 +1,93 @@
+#!/usr/bin/env bash
+# test-scope: plugins/prototype/notes-bridge/* plugins/prototype/skills/explore-directions/assets/variant-switcher.html plugins/prototype/lib/browser-test-helpers.sh plugins/prototype/skills/explore-directions/scripts/notes-copyout-browser-take.js plugins/prototype/.claude-plugin/plugin.json
+set -euo pipefail
+
+here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+skill=$(cd "$here/.." && pwd)
+bridge=$(cd "$skill/../../notes-bridge" && pwd)
+# shellcheck source=../../../lib/browser-test-helpers.sh
+source "$here/../../../lib/browser-test-helpers.sh"
+browser_setup ed-notes-copyout edo playwright-cli node python3 curl
+
+cat >"$d/explore-directions.html" <<'HTML'
+
+
+
+
+
+/shipments variants
+
+
+
+
+ Seed 10
+ Clear
+
+
+
+
+ Copy chosen design
+
+
+
+HTML
+cat "$skill/assets/variant-switcher.html" >>"$d/explore-directions.html"
+printf '%s\n' '' '' >>"$d/explore-directions.html"
+
+browser_serve
+
+pw open >/dev/null 2>&1
+python3 -c '
+import sys
+src, dst, port, page = sys.argv[1:]
+text = open(src, encoding="utf-8").read().replace("__PORT__", port).replace("__FILE__", "file://" + page)
+open(dst, "w", encoding="utf-8", newline="\n").write(text)
+' "$here/notes-copyout-browser-take.js" "$tmp/take.js" "$port" "$d/explore-directions.html"
+n=0
+while IFS= read -r line; do
+ n=$((n + 1))
+ case "$line" in
+ PASS\ *) ok "take: ${line#PASS }" ;;
+ *) bad "take: $line" ;;
+ esac
+done < <(code "$tmp/take.js" | result | tr -d '\r' | grep -E '^(PASS|FAIL|ERROR) ')
+((n > 0)) || bad "take: no results"
+
+if ((fails)); then
+ echo "notes-copyout-browser: $fails failed"
+ exit 1
+fi
+echo "notes-copyout-browser: all passed"