Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
document.querySelectorAll('button[data-copy]').forEach(function(b){
b.addEventListener('click',function(){
var t=b.getAttribute('data-copy');
if(Array.from(t).length>50000){
var status=b.parentNode.querySelector('.copy-budget');
if(!status){status=document.createElement('p');status.className='copy-budget';
status.setAttribute('role','status');b.insertAdjacentElement('afterend',status);}
if(status.dataset.url)URL.revokeObjectURL(status.dataset.url);
status.textContent='Not copied: request exceeds 50,000 characters. '+
'Download the complete request and attach it to your coding chat. ';
var link=document.createElement('a');
link.href=URL.createObjectURL(new Blob([t],{type:'text/plain;charset=utf-8'}));
status.dataset.url=link.href;link.download='dashboard-request.txt';
link.textContent='Download complete request';status.appendChild(link);return;
}
var done=function(){b.classList.add('copied');setTimeout(function(){b.classList.remove('copied')},1200)};
if(navigator.clipboard){navigator.clipboard.writeText(t).then(done,function(){})}
});
Expand Down
17 changes: 16 additions & 1 deletion eyes/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,30 @@ def render_markdown(views) -> str:
code{color:var(--accent)}
"""

# Eyes renders without a Brain checkout. Match the family clipboard budget in
# PyAutoBrain/board/_theme.py; keep this standalone guard for that offline path.
MAX_PROMPT_CHARS = 50_000
JS = """
document.querySelectorAll('button[data-copy]').forEach(function(b){
b.addEventListener('click',function(){
var t=b.getAttribute('data-copy');
if(Array.from(t).length>__MAX_PROMPT_CHARS__){
var status=b.parentNode.querySelector('.copy-budget');
if(!status){status=document.createElement('p');status.className='copy-budget';
status.setAttribute('role','status');b.insertAdjacentElement('afterend',status);}
if(status.dataset.url)URL.revokeObjectURL(status.dataset.url);
status.textContent='Not copied: request exceeds 50,000 characters. '+
'Download the complete request and attach it to your coding chat. ';
var link=document.createElement('a');
link.href=URL.createObjectURL(new Blob([t],{type:'text/plain;charset=utf-8'}));
status.dataset.url=link.href;link.download='dashboard-request.txt';
link.textContent='Download complete request';status.appendChild(link);return;
}
var done=function(){b.classList.add('copied');setTimeout(function(){b.classList.remove('copied')},1200)};
if(navigator.clipboard){navigator.clipboard.writeText(t).then(done,function(){})}
});
});
"""
""".replace("__MAX_PROMPT_CHARS__", str(MAX_PROMPT_CHARS))


def _e(value) -> str:
Expand Down
38 changes: 38 additions & 0 deletions tests/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import json
import os
import re
import shutil
import subprocess
import urllib.parse
from pathlib import Path

Expand All @@ -11,6 +13,42 @@
from eyes import board, context, registry


@pytest.mark.parametrize("length", [50_000, 50_001])
def test_review_copy_budget_retains_complete_unicode_request(length):
node = shutil.which("node")
if not node:
pytest.skip("Node is needed for the browser clipboard contract")
script = (
r"""
const assert=require('assert');
let click,status,downloaded,writes=0;
const text='🌌'.repeat(LENGTH);
const b={getAttribute:()=>text,addEventListener:(event,fn)=>click=fn,
parentNode:{querySelector:()=>status},insertAdjacentElement:(where,s)=>status=s,
classList:{add(){},remove(){}}};
global.document={querySelectorAll:()=>[b],
createElement:()=>({dataset:{},setAttribute(){},appendChild(){}})};
Object.defineProperty(global,'navigator',{value:{clipboard:{writeText:async()=>{writes++}}}});
global.URL={createObjectURL:blob=>{downloaded=blob;return 'blob:test'},revokeObjectURL(){}};
global.setTimeout=()=>{};
"""
+ board.JS
+ r"""
click();assert.equal(writes,LENGTH<=50000?1:0);
if(LENGTH>50000){
assert.match(status.textContent,/Not copied/);
downloaded.text().then(value=>assert.equal(value,text));
}
"""
)
subprocess.run(
[node, "-e", script.replace("LENGTH", str(length))],
check=True,
capture_output=True,
text=True,
)


@pytest.fixture
def views(registry_file, project):
instances = registry.load(registry_file)
Expand Down
Loading