Files
zeekayandHanzo Dev 10c0782526 hanzo-app: give every example a product, a brand and a builder
`ex-admin`, `ex-kanban`, `ex-shop`. That is not a name, it is a filing
code, and it told every visitor that what they were looking at was a
sample of something rather than a thing. Nobody bookmarks Example #47.

So each one is now a product: a name, a mark, a hue that drives the kit's
--acc so the whole page inherits it, and a tagline in its own voice.
ex-kanban is Lanes — "a board with WIP limits that mean something, because
they stop you". The identity lives in ONE place (products.json) and the
shell is the only way a product is built, so an unbranded page cannot be
published.

AND A BUILDER. Ten named agents (agents.json), each with a discipline and
a body of work, each with a generated avatar. The byline reads "<Product>
— published by Hanzo AI, built by <Agent>, an AI agent working on <X>".
That is honest attribution, not decoration: the agent really did write the
app. They are described as what they are and never dressed as people — no
biography, no employer, no photograph, no testimonial. HIP-903. An agent
that genuinely built the thing needs none of that, and inventing it would
turn a true story into a false one.

LINEAGE IS RECORDED, NOT ASSERTED. Every product's project is created by
POST /v1/projects/fork from a gallery template, so projects.forked_from is
a fact the platform wrote at fork time. 74/74, across 28 parent templates.

AND FOR SIX OF THEM, THE BYTES ARE THE TEMPLATE'S. derive.py checks out
the parent, applies the agent's edit to its SOURCE, runs the template's
own build, and ships that. The diff is the point — proof the product is a
derivative and proof a template is agent-editable, in one artifact. It
also found what the pre-built demos were hiding: four templates did not
compile at all, and several 404'd on an /api/placeholder route that cannot
exist on a static host. Fixed upstream and in the edit respectively.

The other 68 carry a real fork edge but ship the kit build. Said plainly
in the README rather than papered over.

One slug now names the source file, the project and the host.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-28 09:36:36 -07:00

111 lines
6.0 KiB
HTML

<!--hz {"title":"Sheets","archetype":"collaborative editor / spreadsheet","creator":"live","desc":"Spreadsheet with a real formula engine: cell references, ranges, SUM/AVG/MIN/MAX/COUNT/IF, dependency-aware recalculation, cycle detection, keyboard navigation and cross-tab sync.","nav":[["#/","Grid"]]} -->
<div class="row" style="margin-bottom:10px">
<h1 style="margin:0">Sheets</h1><span class="tag acc" id="peers">1</span>
<span class="mono small" id="ref">A1</span>
<input id="fx" placeholder="Value or =SUM(B2:B9)" style="max-width:420px">
<span class="spacer"></span>
<button id="demo">Reset demo</button><button class="p" id="save">Save</button>
</div>
<div class="pane"><div class="scroll-x" style="max-height:66vh;overflow:auto"><table id="grid"></table></div></div>
<p class="hz-note" style="margin-top:14px">Formulas are evaluated by a small engine in this page — references, ranges, six functions and cycle detection. Edits sync live to other tabs of this browser.</p>
<script>
const {h,fill,$,$$,store,fmt,toast,submit} = hz;
const COLS = 8, ROWS = 22, A = i => String.fromCharCode(65+i);
const DEMO = {
A1:'Region', B1:'Units', C1:'Price', D1:'Revenue',
A2:'North', B2:'120', C2:'18.50', D2:'=B2*C2',
A3:'South', B3:'84', C3:'21.00', D3:'=B3*C3',
A4:'East', B4:'156', C4:'17.25', D4:'=B4*C4',
A5:'West', B5:'99', C5:'24.00', D5:'=B5*C5',
A7:'Total', B7:'=SUM(B2:B5)', D7:'=SUM(D2:D5)',
A8:'Average', D8:'=AVG(D2:D5)',
A9:'Best', D9:'=MAX(D2:D5)',
A10:'Rows', B10:'=COUNT(B2:B5)',
A12:'Healthy?', B12:'=IF(D7>6000,1,0)',
};
const cells = store('sheets.cells', DEMO);
let sel = 'A1';
const bc = 'BroadcastChannel' in self ? new BroadcastChannel('hz-sheets') : null;
const meId = Math.random().toString(36).slice(2);
const peers = new Map();
const num = v => { const n = parseFloat(v); return isNaN(n) ? 0 : n; };
function expand(range, seen){
const [a,b] = range.split(':');
const c1 = a.charCodeAt(0)-65, r1 = +a.slice(1), c2 = b.charCodeAt(0)-65, r2 = +b.slice(1);
const out = [];
for(let c=Math.min(c1,c2);c<=Math.max(c1,c2);c++)
for(let r=Math.min(r1,r2);r<=Math.max(r1,r2);r++) out.push(num(value(A(c)+r, seen)));
return out;
}
function value(ref, seen){
const raw = cells.get()[ref];
if(raw == null || raw === '') return '';
if(String(raw)[0] !== '=') return raw;
if(seen.has(ref)) return '#CYCLE';
seen = new Set([...seen, ref]);
let e = String(raw).slice(1).toUpperCase();
try {
e = e.replace(/\b(SUM|AVG|MIN|MAX|COUNT)\(([A-H]\d+:[A-H]\d+)\)/g, (_,f,rg) => {
const xs = expand(rg, seen);
return f==='SUM'? xs.reduce((a,b)=>a+b,0) : f==='AVG'? (xs.reduce((a,b)=>a+b,0)/(xs.length||1))
: f==='MIN'? Math.min(...xs) : f==='MAX'? Math.max(...xs) : xs.filter(x=>x!==0).length;
});
e = e.replace(/\bIF\(([^,]+),([^,]+),([^)]+)\)/g, '(($1)?($2):($3))');
e = e.replace(/\b([A-H])(\d+)\b/g, (_,c,r)=> { const v = value(c+r, seen); return String(num(v)); });
if(!/^[-+*/%()<>=!?:.\s0-9]+$/.test(e)) return '#SYNTAX';
const out = Function('return ('+e.replace(/([^<>!])=([^=])/g,'$1==$2')+')')();
return typeof out === 'number' ? (Math.round(out*1e6)/1e6) : out;
} catch(err){ return '#ERR'; }
}
function render(){
const body = [h('tr', h('th',''), ...Array.from({length:COLS},(_,c)=>h('th',{style:{textAlign:'center'}},A(c))))];
for(let r=1;r<=ROWS;r++){
body.push(h('tr', h('th',{style:{textAlign:'right'}},r),
...Array.from({length:COLS},(_,c)=>{
const ref = A(c)+r, v = value(ref, new Set());
const isNum = v!=='' && !isNaN(parseFloat(v)) && String(cells.get()[ref]||'')[0]!=='\'';
const others = [...peers.values()].filter(p=>p.sel===ref);
return h('td',{style:{padding:'0',minWidth:'92px',
outline: ref===sel?'2px solid var(--acc)':others.length?'2px solid '+others[0].color:'',
outlineOffset:'-2px', textAlign:isNum?'right':'left'},
onclick:()=>pick(ref)},
h('div',{style:{padding:'7px 9px',whiteSpace:'nowrap',overflow:'hidden',textOverflow:'ellipsis',
fontVariantNumeric:'tabular-nums',
fontWeight: r===1?'650':'', color: String(v).startsWith('#')?'var(--bad)':''},
title: cells.get()[ref]||''},
typeof v==='number' ? fmt.n(v, v%1?2:0) : String(v)));
})));
}
fill($('#grid'), body);
}
function pick(ref){ sel = ref; $('#ref').textContent = ref; $('#fx').value = cells.get()[ref] ?? '';
render(); bc?.postMessage({from:meId, sel:ref, color:'#8b5cf6'}); }
$('#fx').addEventListener('keydown', e => {
if(e.key==='Enter'){ set(sel, e.target.value);
const c = sel.charCodeAt(0)-65, r = +sel.slice(1);
pick(A(c) + Math.min(ROWS, r+1)); $('#fx').focus(); }
});
$('#fx').addEventListener('blur', () => set(sel, $('#fx').value));
function set(ref, v){ cells.set(o=>({...o,[ref]:v})); render(); bc?.postMessage({from:meId, ref, v}); }
addEventListener('keydown', e => {
if(document.activeElement === $('#fx')) return;
const c = sel.charCodeAt(0)-65, r = +sel.slice(1);
const map = {ArrowRight:[1,0],ArrowLeft:[-1,0],ArrowDown:[0,1],ArrowUp:[0,-1],Tab:[1,0]};
if(map[e.key]){ e.preventDefault();
pick(A(Math.max(0,Math.min(COLS-1,c+map[e.key][0]))) + Math.max(1,Math.min(ROWS,r+map[e.key][1]))); }
else if(e.key==='Delete'||e.key==='Backspace'){ e.preventDefault(); set(sel,''); }
else if(e.key.length===1){ $('#fx').value = e.key; $('#fx').focus(); }
});
if(bc) bc.onmessage = e => { const d=e.data; if(d.from===meId) return;
if(d.ref!==undefined){ cells.set(o=>({...o,[d.ref]:d.v})); }
if(d.sel) peers.set(d.from,{sel:d.sel,color:d.color,at:Date.now()});
$('#peers').textContent = peers.size+1; render(); };
$('#demo').onclick = () => { cells.set({...DEMO}); render(); toast('Demo data restored'); };
$('#save').onclick = async () => { try{ await submit('sheets.save',{cells:cells.get()}); toast('Sheet saved to @hanzo/base'); }
catch(e){ toast('Save failed — kept locally'); } };
setInterval(()=>{ [...peers].forEach(([k,p])=>{ if(Date.now()-p.at>6000) peers.delete(k); });
$('#peers').textContent = peers.size+1; }, 3000);
pick('A1'); render();
</script>