Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

fix(website): report clipboard outcomes truthfully and recover safely

tt-a1if3a6152b2899
diff --git a/website/package.json b/website/package.json
index 21343820..12ceb738 100644
--- a/website/package.json
+++ b/website/package.json
@@ -12,7 +12,7 @@
"preview": "astro preview",
"check": "astro check",
"test": "node --test test/*.test.mjs ../test/cloudflare-output.test.mjs",
- "test:browser": "node --test --test-name-pattern=\"real Chrome\" ../test/site-language-continuity.test.mjs test/community-browser.test.mjs test/homepage-browser.test.mjs test/agent-diagrams-browser.test.mjs test/mco-source-case-browser.test.mjs test/gallery-browser.test.mjs"
+ "test:browser": "node --test --test-name-pattern=\"real Chrome\" ../test/site-language-continuity.test.mjs test/community-browser.test.mjs test/homepage-browser.test.mjs test/agent-diagrams-browser.test.mjs test/mco-source-case-browser.test.mjs test/gallery-browser.test.mjs test/clipboard-browser.test.mjs"
},
"dependencies": {
"@astrojs/react": "^6.0.6",
diff --git a/website/src/data/site-translations.mjs b/website/src/data/site-translations.mjs
index c0078aca..8969d6f7 100644
--- a/website/src/data/site-translations.mjs
+++ b/website/src/data/site-translations.mjs
@@ -21,7 +21,7 @@ export const indexCopy = {
'hero-badge':"Development Agent Skill · see what's new",'hero-works':'Works with',
'hero-h1':'<span class="l">Draw diagrams.</span><span class="l">With your <em>AI agent.</em></span>',
'hero-sub':'Archify is an open-source diagram skill for coding agents. Describe a system or workflow, or ask your agent to read a repository: create architecture, workflow, and sequence diagrams as interactive HTML you can explore and share.',
- 'hero-cta':'Get started','hero-stars':'stars on GitHub','copy':'Copy','copied':'Copied',
+ 'hero-cta':'Get started','hero-stars':'stars on GitHub','copy':'Copy','copied':'Copied','copySuccess':'Copied to clipboard.','copyFailure':'Copy failed. Select the text manually.',
'demo-watch':'Watch the 35s demo','demo-title':'Archify 35-second demo','demo-close':'Close demo',
'tour-title':'Live artifact tour',
'proof-live':'Live','proof-open':'Open artifact',
@@ -103,7 +103,7 @@ export const indexCopy = {
'hero-badge':'开发版 Agent 技能 · 查看更新','hero-works':'支持',
'hero-h1':'<span class="l">让你的 AI Agent</span><span class="l">画出<em>清晰的图。</em></span>',
'hero-sub':'Archify 是面向 Coding Agent 的开源画图工具(Agent Skill)。用自然语言描述系统或流程,或让 Agent 阅读代码仓库,生成架构图、流程图和时序图,交付可探索、可分享的交互式 HTML。',
- 'hero-cta':'开始使用','hero-stars':'GitHub Star','copy':'复制','copied':'已复制',
+ 'hero-cta':'开始使用','hero-stars':'GitHub Star','copy':'复制','copied':'已复制','copySuccess':'已复制到剪贴板。','copyFailure':'复制失败,请手动选择文本。',
'demo-watch':'观看 35 秒演示','demo-title':'Archify 35 秒演示','demo-close':'关闭演示',
'tour-title':'实时成品导览',
'proof-live':'实时','proof-open':'打开完整成品',
@@ -168,12 +168,12 @@ export const indexCopy = {
export const guideCopy = {
en: {
navGuide:'Guide',navProof:'Proof Lab',navStart:'Get started',navCommunity:'Community',navInstall:'Install Skill',versionLabel:'Scenario guide / development / v[[ARCHIFY_VERSION]]',eyebrow:'Question-first diagramming', headline:'Choose the question.<br>Get the <em>right diagram.</em>', lede:'Describe what your audience needs to understand. Archify recommends one bounded visual recipe—plus the evidence it must contain, when not to use it, and a prompt you can copy.',
- metricRecipes:'real-world<br>recipes',metricModes:'diagram modes<br>with recipes',metricRuntime:'runtime<br>dependencies',chooserTitle:'What must the diagram explain?',chooserBody:'Write a situation, not a diagram type. Specific system facts produce a stronger recommendation.',placeholder:'Example: Show an API request with JWT auth, a Redis cache miss, database fallback, and async tracing.',recommend:'Recommend a recipe →',clear:'Clear',libraryEyebrow:'Recipe library',libraryTitle:'13 small, opinionated starting points.',libraryBody:'Each recipe answers one technical question. That boundary keeps the result legible, reviewable, and honest about missing evidence.',footerLeft:'Generated from the same recipe source as the Archify CLI.',all:'All recipes',recommended:'Recommended recipe',use:'Use when',avoid:'Avoid when',must:'Evidence to include',presentation:'Presentation',prompt:'Copy-ready prompt',copyPrompt:'Copy prompt',copied:'Copied',alternatives:'Other possible fits:',confidence:'confidence',open:'Open recipe',proofReady:'Verified proof',proofLink:'Open verified example ↗',
+ metricRecipes:'real-world<br>recipes',metricModes:'diagram modes<br>with recipes',metricRuntime:'runtime<br>dependencies',chooserTitle:'What must the diagram explain?',chooserBody:'Write a situation, not a diagram type. Specific system facts produce a stronger recommendation.',placeholder:'Example: Show an API request with JWT auth, a Redis cache miss, database fallback, and async tracing.',recommend:'Recommend a recipe →',clear:'Clear',libraryEyebrow:'Recipe library',libraryTitle:'13 small, opinionated starting points.',libraryBody:'Each recipe answers one technical question. That boundary keeps the result legible, reviewable, and honest about missing evidence.',footerLeft:'Generated from the same recipe source as the Archify CLI.',all:'All recipes',recommended:'Recommended recipe',use:'Use when',avoid:'Avoid when',must:'Evidence to include',presentation:'Presentation',prompt:'Copy-ready prompt',copyPrompt:'Copy prompt',copied:'Copied',copySuccess:'Copied to clipboard.',copyFailure:'Copy failed. Select the text manually.',alternatives:'Other possible fits:',confidence:'confidence',open:'Open recipe',proofReady:'Verified proof',proofLink:'Open verified example ↗',
samples:[['API + cache miss','Show an API request with JWT auth, a Redis cache miss, database fallback, and async tracing.'],['Kafka + DLQ','Map Kafka topics, ordered processors, consumer groups, replay, state stores, and the dead-letter queue.'],['Incident response','Show how responders detect, triage, mitigate, escalate, communicate, and verify recovery.']]
},
zh: {
navGuide:'场景指南',navProof:'验证作品集',navStart:'开始使用',navCommunity:'社区包',navInstall:'安装技能',versionLabel:'场景指南 / 开发版 / v[[ARCHIFY_VERSION]]',eyebrow:'先问题,后图表',headline:'先选对问题,<br>再得到<em>对的图。</em>',lede:'描述受众真正需要理解的内容。Archify 会推荐一个有边界的视觉配方,同时给出证据清单、禁用条件和可复制提示词。',
- metricRecipes:'个真实场景<br>配方',metricModes:'种图表模式<br>有入门配方',metricRuntime:'个运行时<br>依赖',chooserTitle:'这张图必须解释什么?',chooserBody:'写清场景,不要只写图表类型。系统事实越具体,推荐越可靠。',placeholder:'例如:展示带 JWT 鉴权、Redis 缓存未命中、数据库回退和异步追踪的 API 请求。',recommend:'推荐配方 →',clear:'清空',libraryEyebrow:'配方库',libraryTitle:'13 个小而专的起点。',libraryBody:'每个配方只回答一个技术问题。清晰的边界让图更易读、可评审,也不会掩盖证据缺口。',footerLeft:'网页与 Archify CLI 使用同一份配方数据生成。',all:'全部配方',recommended:'推荐配方',use:'适合',avoid:'不要这样用',must:'必须包含的证据',presentation:'表现建议',prompt:'可直接复制的提示词',copyPrompt:'复制提示词',copied:'已复制',alternatives:'其他可能:',confidence:'置信度',open:'打开配方',proofReady:'已验证成品',proofLink:'打开验证成品 ↗',
+ metricRecipes:'个真实场景<br>配方',metricModes:'种图表模式<br>有入门配方',metricRuntime:'个运行时<br>依赖',chooserTitle:'这张图必须解释什么?',chooserBody:'写清场景,不要只写图表类型。系统事实越具体,推荐越可靠。',placeholder:'例如:展示带 JWT 鉴权、Redis 缓存未命中、数据库回退和异步追踪的 API 请求。',recommend:'推荐配方 →',clear:'清空',libraryEyebrow:'配方库',libraryTitle:'13 个小而专的起点。',libraryBody:'每个配方只回答一个技术问题。清晰的边界让图更易读、可评审,也不会掩盖证据缺口。',footerLeft:'网页与 Archify CLI 使用同一份配方数据生成。',all:'全部配方',recommended:'推荐配方',use:'适合',avoid:'不要这样用',must:'必须包含的证据',presentation:'表现建议',prompt:'可直接复制的提示词',copyPrompt:'复制提示词',copied:'已复制',copySuccess:'已复制到剪贴板。',copyFailure:'复制失败,请手动选择文本。',alternatives:'其他可能:',confidence:'置信度',open:'打开配方',proofReady:'已验证成品',proofLink:'打开验证成品 ↗',
samples:[['API + 缓存未命中','展示带 JWT 鉴权、Redis 缓存未命中、数据库回退和异步追踪的 API 请求。'],['Kafka + 死信','梳理 Kafka Topic、有序处理器、消费者组、重放、状态存储和死信队列。'],['事故处置','展示响应者如何发现、分诊、缓解、升级、沟通并验证恢复。']]
}
};
diff --git a/website/src/pages/guide.astro b/website/src/pages/guide.astro
index db5682a5..00d74eb1 100644
--- a/website/src/pages/guide.astro
+++ b/website/src/pages/guide.astro
@@ -6,6 +6,7 @@ import Navigation from '../components/Navigation.astro';
import RecipeReference from '../components/RecipeReference.astro';
import head from '../data/guide-head.html?raw';
import css from '../styles/guide.css?raw';
+import clipboardScript from '../scripts/clipboard.js?raw';
import pageScript from '../scripts/guide.js?raw';
const { lang = 'en' } = Astro.props;
---
@@ -63,6 +64,6 @@ const { lang = 'en' } = Astro.props;
<script is:inline id="guide-data" type="application/json" set:html={jsonScript(guide)}></script>
<script is:inline src="assets/site-language.js"></script>
- <script is:inline set:html={versioned(pageScript)}></script>
+ <script is:inline set:html={versioned(clipboardScript + "\n" + pageScript)}></script>
</SiteLayout>
diff --git a/website/src/pages/index.astro b/website/src/pages/index.astro
index 2c09cc47..7e65d087 100644
--- a/website/src/pages/index.astro
+++ b/website/src/pages/index.astro
@@ -8,6 +8,7 @@ import ProductFacts from '../components/ProductFacts.astro';
import { defaultProofLabels } from '../data/default-proof-labels.mjs';
import head from '../data/index-head.html?raw';
import css from '../styles/index.css?raw';
+import clipboardScript from '../scripts/clipboard.js?raw';
import pageScript from '../scripts/index.js?raw';
const installCommand = 'npx -y skills add tt-a1i/archify --skill archify --agent claude-code --global --copy --yes';
@@ -34,7 +35,7 @@ const { lang = 'en' } = Astro.props;
<div class="cmd-chip">
<span class="cmd-prompt" aria-hidden="true">$</span>
<code>npx skills add tt-a1i/archify -g</code>
- <button class="cmd-copy" type="button" data-copy-text="npx skills add tt-a1i/archify -g" aria-label="Copy install command">
+ <button class="cmd-copy" type="button" aria-describedby="hero-copy-status" data-copy-text="npx skills add tt-a1i/archify -g" aria-label="Copy install command">
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true"><rect x="4.5" y="4.5" width="8" height="8" rx="1.5" stroke="currentColor" stroke-width="1.3"/><path d="M9.5 4.5V3A1.5 1.5 0 0 0 8 1.5H3A1.5 1.5 0 0 0 1.5 3v5A1.5 1.5 0 0 0 3 9.5h1.5" stroke="currentColor" stroke-width="1.3"/></svg>
<span class="cmd-copy-label" data-i18n="copy">Copy</span>
</button>
@@ -48,6 +49,7 @@ const { lang = 'en' } = Astro.props;
<span data-i18n="demo-watch">Watch the 35s demo</span>
</button>
</div>
+ <p id="hero-copy-status" class="copy-status" role="status" aria-live="polite"></p>
<div class="hero-meta fade-up d4">
<span class="hero-works"><span data-i18n="hero-works">Works with</span> <b>Claude Code</b> · <b>Codex</b> · <b>Cursor</b> · <b>OpenCode</b> · <b>Copilot</b></span>
<a class="hero-stars" href="https://github.com/tt-a1i/archify" target="_blank" rel="noopener">
@@ -326,11 +328,12 @@ const { lang = 'en' } = Astro.props;
<p class="install-cmt" data-i18n="term-c1"># Install globally for your agent</p>
<div class="install-line">
<p class="install-cmd"><span aria-hidden="true">$ </span><code id="agent-command">{installCommand}</code></p>
- <button class="cmd-copy" type="button" data-copy-from="agent-command" aria-label="Copy install command">
+ <button class="cmd-copy" type="button" aria-describedby="agent-copy-status" data-copy-from="agent-command" aria-label="Copy install command">
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true"><rect x="4.5" y="4.5" width="8" height="8" rx="1.5" stroke="currentColor" stroke-width="1.3"/><path d="M9.5 4.5V3A1.5 1.5 0 0 0 8 1.5H3A1.5 1.5 0 0 0 1.5 3v5A1.5 1.5 0 0 0 3 9.5h1.5" stroke="currentColor" stroke-width="1.3"/></svg>
<span class="cmd-copy-label" data-i18n="copy">Copy</span>
</button>
</div>
+ <p id="agent-copy-status" class="copy-status" role="status" aria-live="polite"></p>
<p class="install-cmt" data-i18n="term-c2"># Or try it once with Codex, no permanent install</p>
<p class="install-cmd"><span aria-hidden="true">$ </span><code>npx skills use tt-a1i/archify@archify --agent codex</code></p>
<p class="install-cmt" data-i18n="term-c3"># Then just ask</p>
@@ -432,6 +435,6 @@ const { lang = 'en' } = Astro.props;
</dialog>
<script is:inline src="assets/site-language.js"></script>
- <script is:inline set:html={versioned(pageScript)}></script>
+ <script is:inline set:html={versioned(clipboardScript + "\n" + pageScript)}></script>
</SiteLayout>
diff --git a/website/src/pages/start.astro b/website/src/pages/start.astro
index 204fa673..90531a5f 100644
--- a/website/src/pages/start.astro
+++ b/website/src/pages/start.astro
@@ -6,6 +6,7 @@ import SiteLayout from '../layouts/SiteLayout.astro';
import Navigation from '../components/Navigation.astro';
import head from '../data/start-head.html?raw';
import css from '../styles/start.css?raw';
+import clipboardScript from '../scripts/clipboard.js?raw';
import pageScript from '../scripts/start.js?raw';
const { lang = 'en' } = Astro.props;
---
@@ -64,12 +65,14 @@ const { lang = 'en' } = Astro.props;
</div>
<div class="command-block">
- <div class="command-bar"><span data-en="Global install" data-zh="全局安装">Global install</span><button class="copy-button" type="button" data-copy-source="install-command" data-en="Copy" data-zh="复制">Copy</button></div>
+ <div class="command-bar"><span data-en="Global install" data-zh="全局安装">Global install</span><button class="copy-button" type="button" aria-describedby="install-copy-status" data-copy-source="install-command" data-en="Copy" data-zh="复制">Copy</button></div>
<pre id="install-command">npx -y skills add tt-a1i/archify --skill archify --agent codex --global --copy --yes</pre>
+ <p id="install-copy-status" class="copy-status" role="status" aria-live="polite"></p>
</div>
<div class="command-block">
- <div class="command-bar"><span data-en="This repository only" data-zh="仅安装到当前仓库">This repository only</span><button class="copy-button" type="button" data-copy-source="project-command" data-en="Copy" data-zh="复制">Copy</button></div>
+ <div class="command-bar"><span data-en="This repository only" data-zh="仅安装到当前仓库">This repository only</span><button class="copy-button" type="button" aria-describedby="project-copy-status" data-copy-source="project-command" data-en="Copy" data-zh="复制">Copy</button></div>
<pre id="project-command">npx -y skills add tt-a1i/archify --skill archify --agent codex --copy --yes</pre>
+ <p id="project-copy-status" class="copy-status" role="status" aria-live="polite"></p>
</div>
<p class="secondary-note" data-en="The Start link carries only your agent, language, diagram type, input mode, and a coarse source label. Journey events stay in this browser session and are never sent by Archify. No repository path, title, node, relationship, or source JSON is recorded." data-zh="Start 链接只携带 Agent、语言、图表类型、输入模式和粗粒度来源标签。转化步骤只保存在当前浏览器会话中,Archify 不会发送这些数据,也不会记录仓库路径、标题、节点、关系或源 JSON。">The Start link carries only your agent, language, diagram type, input mode, and a coarse source label. Journey events stay in this browser session and are never sent by Archify. No repository path, title, node, relationship, or source JSON is recorded.</p>
</article>
@@ -81,18 +84,18 @@ const { lang = 'en' } = Astro.props;
<ul class="include-list" id="include-list" aria-label="Required evidence">{starts.architecture.en.include.map((item, index) => <li data-en={item} data-zh={starts.architecture.zh.include[index]}>{item}</li>)}</ul>
<p class="prompt-box" id="recipe-prompt" data-en={starts.architecture.en.descriptionPrompt} data-zh={starts.architecture.zh.descriptionPrompt}>{starts.architecture.en.descriptionPrompt}</p>
<div class="actions">
- <button class="action action-primary" id="copy-starter" type="button" data-en="Copy install + prompt" data-zh="复制安装命令 + 提示词">Copy install + prompt</button>
- <button class="action" id="copy-prompt" type="button" data-en="Prompt only" data-zh="仅复制提示词">Prompt only</button>
+ <button class="action action-primary" id="copy-starter" aria-describedby="copy-status" type="button" data-en="Copy install + prompt" data-zh="复制安装命令 + 提示词">Copy install + prompt</button>
+ <button class="action" id="copy-prompt" aria-describedby="copy-status" type="button" data-en="Prompt only" data-zh="仅复制提示词">Prompt only</button>
<a class="action" id="proof-link" href={`gallery.html#proof-${starts.architecture.proof}`} data-en="Open verified proof ↗" data-zh="打开验证成品 ↗">Open verified proof ↗</a>
<a class="action" href="guide.html" data-en="Need another recipe?" data-zh="需要其他配方?">Need another recipe?</a>
</div>
+ <p id="copy-status" class="copy-status" role="status" aria-live="polite"></p>
<p class="proof-meta" id="proof-meta">{starts.architecture.type} · {starts.architecture.presentation.preset} · {starts.architecture.presentation.motion}</p>
</article>
</section>
<footer class="page-footer">
<span data-en={`Archify v${version} · ${productChannel} · self-contained HTML · typed JSON source`} data-zh={`Archify v${version} · ${productChannel === 'development' ? '开发版' : '稳定版'} · 独立 HTML · 类型化 JSON 源`}>Archify v{version} · {productChannel} · self-contained HTML · typed JSON source</span>
- <span id="copy-status" role="status" aria-live="polite"></span>
<a href="https://github.com/tt-a1i/archify" data-en="View source on GitHub ↗" data-zh="在 GitHub 查看源码 ↗">View source on GitHub ↗</a>
</footer>
<aside class="agent-guide-link" aria-label={lang === 'zh' ? 'Agent 画图指南' : 'Agent diagramming guide'}>
@@ -103,6 +106,6 @@ const { lang = 'en' } = Astro.props;
<script is:inline id="start-data" type="application/json" set:html={jsonScript(starts)}></script>
<script is:inline src="assets/site-language.js"></script>
- <script is:inline set:html={versioned(pageScript)}></script>
+ <script is:inline set:html={versioned(clipboardScript + "\n" + pageScript)}></script>
</SiteLayout>
diff --git a/website/src/scripts/clipboard.js b/website/src/scripts/clipboard.js
new file mode 100644
index 00000000..a7cea752
--- /dev/null
+++ b/website/src/scripts/clipboard.js
@@ -0,0 +1,29 @@
+// Shared only by the website copy controls. A failed browser API must never
+// become a successful UI receipt; the legacy fallback can also fail or throw.
+window.ArchifyClipboard = {
+ async copy(text, isCurrent = () => true) {
+ try {
+ if (navigator.clipboard?.writeText) {
+ await navigator.clipboard.writeText(text);
+ return true;
+ }
+ } catch (_) {}
+ if (!isCurrent()) return false;
+ const focus = document.activeElement;
+ const area = document.createElement('textarea');
+ area.value = text;
+ area.readOnly = true;
+ area.style.cssText = 'position:fixed;top:0;left:0;opacity:0;pointer-events:none';
+ try {
+ document.body.appendChild(area);
+ area.focus({ preventScroll: true });
+ area.select();
+ return document.execCommand('copy') === true;
+ } catch (_) {
+ return false;
+ } finally {
+ area.remove();
+ if (focus instanceof HTMLElement && focus.isConnected) focus.focus({ preventScroll: true });
+ }
+ }
+};
diff --git a/website/src/scripts/guide.js b/website/src/scripts/guide.js
index f18c4259..f3c79f0a 100644
--- a/website/src/scripts/guide.js
+++ b/website/src/scripts/guide.js
@@ -77,7 +77,7 @@
var alt = alternatives || [];
var html = '<div class="result-main"><div><span class="result-kicker">'+escapeHtml(t('recommended'))+' · '+escapeHtml(confidence)+' '+escapeHtml(t('confidence'))+'</span><h3>'+escapeHtml(recipe.title)+'</h3><p class="result-question">'+escapeHtml(recipe.question)+'</p><p class="result-summary">'+escapeHtml(recipe.summary)+'</p>'+(recipe.proof ? '<a class="proof-link" href="'+ArchifySiteLanguage.page('gallery', '#proof-'+encodeURIComponent(recipe.proof))+'">'+escapeHtml(t('proofLink'))+'</a>' : '')+'</div><div class="boundary"><div class="boundary-item"><small>'+escapeHtml(t('use'))+'</small><p>'+escapeHtml(recipe.useWhen)+'</p></div><div class="boundary-item avoid"><small>'+escapeHtml(t('avoid'))+'</small><p>'+escapeHtml(recipe.avoidWhen)+'</p></div></div></div>';
html += '<div class="result-grid"><div class="checklist"><div class="mini-heading">'+escapeHtml(t('must'))+'</div><ul>'+recipe.include.map(function (item) { return '<li>'+escapeHtml(item)+'</li>'; }).join('')+'</ul><div class="presentation"><span class="tag">'+escapeHtml(recipe.type)+'</span><span class="tag">'+escapeHtml(recipe.presentation.preset)+'</span><span class="tag">'+escapeHtml(recipe.presentation.motion)+'</span></div></div>';
- html += '<div class="prompt-box"><div class="prompt-bar"><div class="mini-heading" style="margin:0">'+escapeHtml(t('prompt'))+'</div><button class="copy" id="copy-prompt" type="button">'+escapeHtml(t('copyPrompt'))+'</button></div><p class="prompt-text">'+escapeHtml(recipe.prompt)+'</p></div></div>';
+ html += '<div class="prompt-box"><div class="prompt-bar"><div class="mini-heading" style="margin:0">'+escapeHtml(t('prompt'))+'</div><button class="copy" id="copy-prompt" aria-describedby="prompt-copy-status" type="button">'+escapeHtml(t('copyPrompt'))+'</button></div><p id="prompt-copy-status" class="copy-status" role="status" aria-live="polite"></p><p class="prompt-text">'+escapeHtml(recipe.prompt)+'</p></div></div>';
if (alt.length) html += '<div class="alternatives">'+escapeHtml(t('alternatives'))+alt.map(function (entry) { var item=local(entry.recipe); return '<button type="button" data-alt="'+item.id+'">'+escapeHtml(item.title)+' ['+item.type+']</button>'; }).join('')+'</div>';
var result = document.getElementById('result');
result.innerHTML = html;
@@ -101,13 +101,17 @@
renderSamples(); renderFilters(); renderCards();
if (lastRecipe) renderResult(lastRecipe,'selected',[]);
}
+ var copyAttempt = 0;
async function copyPrompt() {
if (!lastRecipe) return;
- var text = local(lastRecipe).prompt, button = document.getElementById('copy-prompt');
- try { await navigator.clipboard.writeText(text); } catch (_) {
- var area=document.createElement('textarea'); area.value=text; document.body.appendChild(area); area.select(); document.execCommand('copy'); area.remove();
- }
- button.textContent=t('copied'); setTimeout(function () { if (button.isConnected) button.textContent=t('copyPrompt'); },1200);
+ var text = local(lastRecipe).prompt, recipe = lastRecipe;
+ var button = document.getElementById('copy-prompt');
+ var status = document.getElementById('prompt-copy-status');
+ var attempt = ++copyAttempt;
+ status.textContent = '';
+ var isCurrent = function () { return attempt === copyAttempt && button.isConnected && recipe === lastRecipe; };
+ var ok = await ArchifyClipboard.copy(text, isCurrent);
+ if (isCurrent()) status.textContent = t(ok ? 'copySuccess' : 'copyFailure');
}
document.getElementById('recommend').addEventListener('click',runRecommendation);
document.getElementById('clear').addEventListener('click',function () { document.getElementById('scenario').value=''; document.getElementById('result').classList.remove('visible'); lastRecipe=null; });
diff --git a/website/src/scripts/index.js b/website/src/scripts/index.js
index f8113fb0..2efa47b8 100644
--- a/website/src/scripts/index.js
+++ b/website/src/scripts/index.js
@@ -258,8 +258,11 @@
/* ══ Agent command switcher ══ */
const agentCommand = $('agent-command');
const agentTabs = [...document.querySelectorAll('.agent-tabs button')];
+ let agentRevision = 0;
function selectAgent(tab, focus) {
+ agentRevision++;
agentTabs.forEach(t => { const on = t === tab; t.setAttribute('aria-selected', String(on)); t.tabIndex = on ? 0 : -1; });
+ $('agent-copy-status').textContent = '';
agentCommand.textContent = `npx -y skills add tt-a1i/archify --skill archify --agent ${tab.dataset.agent} --global --copy --yes`;
if (focus) tab.focus();
}
@@ -274,14 +277,19 @@
});
/* ══ Copy buttons ══ */
- document.querySelectorAll('.cmd-copy').forEach(button => button.addEventListener('click', async () => {
- const text = button.dataset.copyText || $(button.dataset.copyFrom).textContent;
- try { await navigator.clipboard.writeText(text); } catch (_) { return; }
- const label = button.querySelector('.cmd-copy-label');
- button.classList.add('is-copied');
- label.textContent = LANGS[lang].copied;
- setTimeout(() => { button.classList.remove('is-copied'); label.textContent = LANGS[lang].copy; }, 1600);
- }));
+ document.querySelectorAll('.cmd-copy').forEach(button => {
+ let attempt = 0;
+ const status = $(button.getAttribute('aria-describedby'));
+ const sourceText = () => button.dataset.copyText || $(button.dataset.copyFrom).textContent;
+ button.addEventListener('click', async () => {
+ const current = ++attempt, text = sourceText(), revision = agentRevision;
+ status.textContent = '';
+ const isCurrent = () => current === attempt && (!button.dataset.copyFrom || revision === agentRevision) && text === sourceText();
+ const ok = await ArchifyClipboard.copy(text, isCurrent);
+ if (!isCurrent()) return;
+ status.textContent = LANGS[lang][ok ? 'copySuccess' : 'copyFailure'];
+ });
+ });
/* ══ Demo lightbox — zero network cost until the trigger is pressed ══ */
const DEMO_SRC = 'https://github.com/user-attachments/assets/78570807-ba1d-4737-953f-55504a378a87';
diff --git a/website/src/scripts/start.js b/website/src/scripts/start.js
index 2d2e44e0..65c01f27 100644
--- a/website/src/scripts/start.js
+++ b/website/src/scripts/start.js
@@ -25,7 +25,7 @@
var includeList = document.getElementById('include-list');
var proofLink = document.getElementById('proof-link');
var proofMeta = document.getElementById('proof-meta');
- var copyStatus = document.getElementById('copy-status');
+ var copyStatuses = document.querySelectorAll('.copy-status');
var languageButton = document.getElementById('language');
var agentState = document.getElementById('agent-state');
var installCommand = document.getElementById('install-command');
@@ -87,7 +87,9 @@
: DATA[type][language].repositoryPrompt;
}
+ var copyAttempt = 0;
function render() {
+ copyAttempt++;
language = ArchifySiteLanguage.write(language);
var recipe = DATA[type];
var copy = recipe[language];
@@ -123,23 +125,10 @@
proofMeta.textContent = language === 'zh'
? '验证成品 · ' + recipe.presentation.preset + ' · ' + recipe.presentation.motion
: 'Verified proof · ' + recipe.presentation.preset + ' · ' + recipe.presentation.motion;
- copyStatus.textContent = '';
+ copyStatuses.forEach(function (status) { status.textContent = ''; });
updateUrl();
}
- function fallbackCopy(text) {
- var area = document.createElement('textarea');
- area.value = text;
- area.setAttribute('readonly', '');
- area.style.position = 'fixed';
- area.style.opacity = '0';
- document.body.appendChild(area);
- area.select();
- var ok = document.execCommand('copy');
- area.remove();
- if (!ok) throw new Error('copy failed');
- }
-
function starterText() {
var agentName = document.querySelector('[data-agent="' + agent + '"]').textContent;
if (language === 'zh') {
@@ -150,15 +139,17 @@
+ (input === 'description' ? '\n\nThen start any new chat and tell ' : '\n\nThen, in your target repository, ask ') + agentName + ':\n' + currentPrompt();
}
- async function copyText(text, step) {
- try {
- if (navigator.clipboard && window.isSecureContext) await navigator.clipboard.writeText(text);
- else fallbackCopy(text);
- if (step) recordStep(step);
- copyStatus.textContent = language === 'zh' ? '已复制到剪贴板。' : 'Copied to clipboard.';
- } catch (_) {
- copyStatus.textContent = language === 'zh' ? '复制失败,请手动选择文本。' : 'Copy failed. Select the text manually.';
- }
+ async function copyText(text, step, statusId) {
+ var copyStatus = document.getElementById(statusId);
+ var attempt = ++copyAttempt;
+ copyStatuses.forEach(function (status) { status.textContent = ''; });
+ var isCurrent = function () { return attempt === copyAttempt; };
+ var ok = await ArchifyClipboard.copy(text, isCurrent);
+ if (!isCurrent()) return;
+ if (ok && step) recordStep(step);
+ copyStatus.textContent = ok
+ ? (language === 'zh' ? '已复制到剪贴板。' : 'Copied to clipboard.')
+ : (language === 'zh' ? '复制失败,请手动选择文本。' : 'Copy failed. Select the text manually.');
}
document.querySelectorAll('[data-type]').forEach(function (button) {
@@ -221,14 +212,14 @@
document.querySelectorAll('[data-copy-source]').forEach(function (button) {
button.addEventListener('click', function () {
var step = button.dataset.copySource === 'install-command' ? 'global_install_copy' : 'project_install_copy';
- copyText(document.getElementById(button.dataset.copySource).textContent.trim(), step);
+ copyText(document.getElementById(button.dataset.copySource).textContent.trim(), step, button.getAttribute('aria-describedby'));
});
});
document.getElementById('copy-prompt').addEventListener('click', function () {
- copyText(currentPrompt(), 'prompt_copy');
+ copyText(currentPrompt(), 'prompt_copy', 'copy-status');
});
document.getElementById('copy-starter').addEventListener('click', function () {
- copyText(starterText(), 'starter_copy');
+ copyText(starterText(), 'starter_copy', 'copy-status');
});
proofLink.addEventListener('click', function () { recordStep('proof_open'); });
diff --git a/website/src/styles/guide.css b/website/src/styles/guide.css
index 219c5c4e..860db73a 100644
--- a/website/src/styles/guide.css
+++ b/website/src/styles/guide.css
@@ -150,3 +150,6 @@
.card-question { color:var(--text-2); font-size:.8125rem; }
.section-head h2 { font-size:clamp(2rem,4vw,3.25rem); }
.filter.active { color:var(--btn-fg); }
+
+ .copy-status { color:var(--text-2); font-size:.85rem; overflow-wrap:anywhere; }
+ .copy-status:empty { margin:0; }
diff --git a/website/src/styles/index.css b/website/src/styles/index.css
index 5e264bfc..824f670f 100644
--- a/website/src/styles/index.css
+++ b/website/src/styles/index.css
@@ -90,7 +90,8 @@
.cmd-chip code { font-family:inherit; white-space:nowrap; }
.cmd-copy { display:inline-flex; align-items:center; gap:.4rem; min-height:34px; padding:0 .65rem; border:1px solid transparent; border-radius:7px; background:rgba(var(--fg-rgb),.06); color:var(--text-2); font-family:var(--font-mono); font-size:.6875rem; letter-spacing:.04em; cursor:pointer; transition:color .18s var(--ease-out),background .18s var(--ease-out); }
.cmd-copy:hover { color:var(--text); background:rgba(var(--fg-rgb),.12); }
- .cmd-copy.is-copied { color:var(--signal); }
+ .copy-status { color:var(--text-2); font-size:.85rem; overflow-wrap:anywhere; }
+ .copy-status:empty { display:block; margin:0; }
.demo-trigger .play-ring { display:inline-flex; align-items:center; justify-content:center; width:20px; height:20px; border-radius:50%; background:var(--accent); color:var(--on-accent); padding-left:1px; }
.hero-meta { display:flex; flex-wrap:wrap; align-items:center; justify-content:center; gap:.5rem 1.5rem; margin-top:1.75rem; font-size:.8125rem; color:var(--text-3); }
diff --git a/website/src/styles/start.css b/website/src/styles/start.css
index c76749c4..5550dcd6 100644
--- a/website/src/styles/start.css
+++ b/website/src/styles/start.css
@@ -90,7 +90,9 @@
.page-footer { display:flex; align-items:center; justify-content:space-between; gap:1rem; margin-top:3.5rem; padding-top:1.5rem; border-top:1px solid var(--line); color:var(--dim); font-family:var(--font-mono); font-size:.625rem; letter-spacing:.04em; }
.page-footer a { color:var(--muted); text-decoration:none; transition:color .18s var(--ease-out); }
.page-footer a:hover { color:var(--ink); }
- #copy-status { min-height:1.1rem; color:var(--emerald); }
+ .copy-status { color:var(--text-2); font-size:.85rem; overflow-wrap:anywhere; }
+ .copy-status:not(:empty) { margin-top:.6rem; }
+ .command-block .copy-status:not(:empty) { padding:0 1rem .75rem; }
/* ENTRANCE — one quiet rise on load */
@keyframes rise { from { opacity:0; transform:translateY(14px); } to { opacity:1; transform:none; } }
diff --git a/website/test/clipboard-browser.test.mjs b/website/test/clipboard-browser.test.mjs
new file mode 100644
index 00000000..a957dd6e
--- /dev/null
+++ b/website/test/clipboard-browser.test.mjs
@@ -0,0 +1,158 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import fs from 'node:fs';
+import http from 'node:http';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { execFileSync } from 'node:child_process';
+import { ChromeVisualBrowser, findChrome } from '../../archify/bin/visual-check.mjs';
+
+const website = fileURLToPath(new URL('../', import.meta.url));
+const enabled = process.env.ARCHIFY_SITE_INTEGRATION === '1';
+const root = path.resolve(process.env.ARCHIFY_SITE_ROOT || path.join(website, 'dist'));
+const mount = process.env.ARCHIFY_SITE_BASE ?? '/archify';
+const target = mount ? 'github' : 'cloudflare';
+const output = path.join(website, '.browser-evidence', target, 'clipboard');
+
+test('real Chrome: website copy controls report real outcomes and preserve selected text and focus', {
+ skip: enabled ? false : 'Set ARCHIFY_SITE_INTEGRATION=1 and ARCHIFY_CHROME to run clipboard browser evidence.',
+ timeout: 120000,
+}, async () => {
+ const chrome = findChrome();
+ assert.ok(chrome, 'The requested clipboard gate requires usable Chrome.');
+ const server = http.createServer((request, response) => {
+ const url = new URL(request.url, 'http://127.0.0.1');
+ if (mount && !url.pathname.startsWith(`${mount}/`)) return response.writeHead(404).end();
+ let relative = url.pathname.slice(mount.length).replace(/^\/+/, '') || 'index.html';
+ if (!path.extname(relative)) relative += '.html';
+ const file = path.resolve(root, relative);
+ if (!file.startsWith(`${root}${path.sep}`)) return response.writeHead(404).end();
+ try {
+ const types = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.svg': 'image/svg+xml', '.woff2': 'font/woff2' };
+ response.setHeader('Content-Type', types[path.extname(file)] || 'application/octet-stream');
+ response.end(fs.readFileSync(file));
+ } catch { response.writeHead(404).end(); }
+ });
+ let browser;
+ const manifest = { target, capturedAt: new Date().toISOString(),
+ checkoutSha: execFileSync('git', ['rev-parse', 'HEAD'], { cwd: website, encoding: 'utf8' }).trim(),
+ runId: process.env.GITHUB_RUN_ID || null, receipts: [], screenshots: [] };
+ fs.mkdirSync(output, { recursive: true });
+ try {
+ await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
+ browser = new ChromeVisualBrowser(chrome);
+ const session = await browser.sessionPromise;
+ const evaluate = async expression => {
+ const result = await browser.cdp.send('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true }, session);
+ assert.ok(!result.exceptionDetails, JSON.stringify(result.exceptionDetails));
+ return result.result.value;
+ };
+ await browser.cdp.send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-reduced-motion', value: 'reduce' }] }, session);
+ await browser.cdp.send('Emulation.setDeviceMetricsOverride', { width: 320, height: 1000, deviceScaleFactor: 1, mobile: true }, session);
+ for (const lang of ['en', 'zh']) for (const page of ['index', 'guide', 'start']) {
+ const route = `${lang === 'zh' ? 'zh/' : ''}${page}.html`.replace('zh/index.html', 'zh.html');
+ const loaded = browser.cdp.waitFor('Page.loadEventFired', session); loaded.catch(() => {});
+ await browser.cdp.send('Page.navigate', { url: `http://127.0.0.1:${server.address().port}${mount}/${route}` }, session);
+ await loaded;
+ await evaluate('document.fonts.ready');
+ const controls = await evaluate(`(() => {
+ const page = ${JSON.stringify(page)};
+ if (page === 'guide') document.querySelectorAll('[data-recipe]')[1].click();
+ if (page === 'index') document.querySelector('.agent-tabs [data-agent="cursor"]').click();
+ if (page === 'start') {
+ document.querySelector('[data-agent="cursor"]').click();
+ document.querySelector('[data-type="workflow"]').click();
+ document.querySelector('[data-input="repository"]').click();
+ }
+ return page === 'index' ? ['[data-copy-text]', '[data-copy-from]'] : page === 'guide' ? ['#copy-prompt'] : ['[data-copy-source="install-command"]', '[data-copy-source="project-command"]', '#copy-prompt', '#copy-starter'];
+ })()`);
+ for (const selector of controls) for (const [api, fallback] of [['success', 'throw'], ['missing', 'true'], ['missing', 'false'], ['missing', 'throw'], ['reject', 'true'], ['reject', 'false'], ['reject', 'throw']]) {
+ const receipt = await evaluate(`(async () => {
+ const page = ${JSON.stringify(page)}, selector = ${JSON.stringify(selector)};
+ const api = ${JSON.stringify(api)}, fallback = ${JSON.stringify(fallback)};
+ const button = document.querySelector(selector);
+ const status = document.querySelector('#' + button.getAttribute('aria-describedby'));
+ let expected;
+ if (page === 'index') expected = button.dataset.copyText || document.getElementById(button.dataset.copyFrom).textContent;
+ else if (page === 'guide') expected = document.querySelector('.prompt-text').textContent;
+ else if (button.dataset.copySource) expected = document.getElementById(button.dataset.copySource).textContent.trim();
+ else if (selector === '#copy-prompt') expected = document.getElementById('recipe-prompt').textContent;
+ else {
+ const command = document.getElementById('install-command').textContent.trim(), prompt = document.getElementById('recipe-prompt').textContent;
+ expected = ${JSON.stringify(lang)} === 'zh' ? '为 Cursor 安装 Archify:\\n' + command + '\\n\\n然后在目标仓库中让 Cursor:\\n' + prompt : 'Install Archify for Cursor:\\n' + command + '\\n\\nThen, in your target repository, ask Cursor:\\n' + prompt;
+ }
+ const writes = [], legacy = [];
+ Object.defineProperty(navigator, 'clipboard', { configurable: true, value: api === 'missing' ? undefined : { writeText: async text => { writes.push(text); if (api === 'reject') throw Error('denied'); } } });
+ document.execCommand = command => { legacy.push({ command, text: document.activeElement.value }); if (fallback === 'throw') throw Error('unsupported'); return fallback === 'true'; };
+ button.scrollIntoView({ block: 'center', behavior: 'instant' }); button.focus({ preventScroll: true });
+ let events = 0; const onCopy = () => { events++; };
+ window.addEventListener('archify:start-funnel', onCopy);
+ const before = { areas: document.querySelectorAll('textarea').length, scroll: scrollY };
+ button.click();
+ for (let i = 0; !status.textContent && i < 30; i++) await new Promise(resolve => setTimeout(resolve, 10));
+ window.removeEventListener('archify:start-funnel', onCopy);
+ const box = status.getBoundingClientRect();
+ return { expected, writes, legacy, visible: box.width > 0 && box.height > 0 && box.top >= 0 && box.bottom <= innerHeight && box.left >= 0 && box.right <= innerWidth, status: status.textContent, role: status.getAttribute('role'), live: status.getAttribute('aria-live'), focus: document.activeElement === button, areas: document.querySelectorAll('textarea').length - before.areas, scrollDelta: scrollY - before.scroll, events };
+ })()`);
+ const ok = api === 'success' || fallback === 'true';
+ assert.equal(receipt.status, lang === 'zh' ? (ok ? '已复制到剪贴板。' : '复制失败,请手动选择文本。') : (ok ? 'Copied to clipboard.' : 'Copy failed. Select the text manually.'), `${page} ${selector} ${api}/${fallback}`);
+ assert.deepEqual(receipt.writes, api === 'missing' ? [] : [receipt.expected]);
+ assert.deepEqual(receipt.legacy, api === 'success' ? [] : [{ command: 'copy', text: receipt.expected }]);
+ assert.equal(receipt.visible, true, 'feedback is visible near the clicked control at 320px');
+ assert.equal(receipt.focus, true); assert.equal(receipt.areas, 0);
+ assert.equal(receipt.scrollDelta, 0, 'temporary textarea must not jump scroll');
+ assert.equal(receipt.role, 'status'); assert.equal(receipt.live, 'polite');
+ if (page === 'start') assert.equal(receipt.events, ok ? 1 : 0, 'only successful copies emit conversion events');
+ manifest.receipts.push({ lang, page, selector, api, fallback, ...receipt });
+ }
+ // Slow responses must not overwrite a newer failure, restore stale focus,
+ // or launch a fallback after the selected recipe/tab has been replaced.
+ for (const lateOutcome of ['resolve', 'reject']) {
+ const stale = await evaluate(`(async () => {
+ const page = ${JSON.stringify(page)}, button = document.querySelector(${JSON.stringify(controls.at(-1))});
+ const status = document.querySelector('#' + button.getAttribute('aria-describedby'));
+ let settleFirst, calls = 0, fallbacks = 0, events = 0;
+ const onCopy = () => { events++; }; window.addEventListener('archify:start-funnel', onCopy);
+ Object.defineProperty(navigator, 'clipboard', { configurable: true, value: { writeText: () => ++calls === 1 ? new Promise((resolve, reject) => { settleFirst = () => ${JSON.stringify(lateOutcome)} === 'resolve' ? resolve() : reject(Error('late')); }) : Promise.reject(Error('denied')) } });
+ document.execCommand = () => { fallbacks++; return false; };
+ button.click(); button.click();
+ await new Promise(resolve => setTimeout(resolve, 20));
+ const latest = status.textContent;
+ settleFirst(); await new Promise(resolve => setTimeout(resolve, 20));
+ const concurrency = { latest, after: status.textContent, fallbacks };
+ calls = 0; fallbacks = 0; button.click();
+ if (page === 'guide') { document.querySelectorAll('[data-recipe]')[2].click(); document.querySelectorAll('[data-recipe]')[1].click(); }
+ else if (page === 'start') { document.querySelector('[data-agent="codex"]').click(); document.querySelector('[data-agent="cursor"]').click(); }
+ else { document.querySelector('.agent-tabs [data-agent="codex"]').click(); document.querySelector('.agent-tabs [data-agent="cursor"]').click(); }
+ const focused = document.activeElement;
+ settleFirst(); await new Promise(resolve => setTimeout(resolve, 20));
+ window.removeEventListener('archify:start-funnel', onCopy);
+ return { concurrency, fallbacks, events, focus: document.activeElement === focused, status: page === 'guide' ? document.getElementById('prompt-copy-status').textContent : status.textContent };
+ })()`);
+ assert.ok(stale.concurrency.latest); assert.equal(stale.concurrency.after, stale.concurrency.latest);
+ assert.equal(stale.concurrency.fallbacks, 1); assert.equal(stale.fallbacks, 0); assert.equal(stale.events, 0); assert.equal(stale.focus, true); assert.equal(stale.status, '');
+ manifest.receipts.push({ lang, page, lateOutcome, stale });
+ }
+ for (const captureSelector of controls) for (const theme of ['light', 'dark']) {
+ await evaluate(`(async () => {
+ document.documentElement.dataset.theme = ${JSON.stringify(theme)};
+ Object.defineProperty(navigator, 'clipboard', { configurable: true, value: undefined });
+ document.execCommand = () => false;
+ const button = document.querySelector(${JSON.stringify(captureSelector)}); button.click();
+ await new Promise(resolve => setTimeout(resolve, 30));
+ const status = document.getElementById(button.getAttribute('aria-describedby'));
+ status.scrollIntoView({ block: 'center', behavior: 'instant' });
+ await new Promise(resolve => setTimeout(resolve, 300));
+ })()`);
+ const file = `${lang}-${page}-${controls.indexOf(captureSelector)}-320-${theme}-failure.png`;
+ const image = await browser.cdp.send('Page.captureScreenshot', { format: 'png' }, session);
+ fs.writeFileSync(path.join(output, file), Buffer.from(image.data, 'base64'));
+ manifest.screenshots.push(file);
+ }
+ fs.writeFileSync(path.join(output, 'manifest.json'), JSON.stringify(manifest, null, 2));
+ }
+ } finally {
+ if (browser) await browser.close();
+ await new Promise(resolve => server.close(resolve));
+ }
+});