From f09e04c11c54fcc0efbe8c65f6963bf97cd44f5e Mon Sep 17 00:00:00 2001 From: TheGaffer7839 <“thegaffer7839@gmail.com”> Date: Fri, 13 Nov 2026 11:34:50 +0100 Subject: [PATCH 01/20] Demo world, step 1: new look and chapter shell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The #demo routes now render a full-screen demo shell instead of the product console: a 72px top bar with five chapter tabs (#demo/bank, rules, post, pay, end), vault and wallet balances, and an exit link back to #agent-payments. Bare #demo opens #demo/post. Existing café features are regrouped into chapters with unchanged behaviour. Styles are scoped under body.demo-world so product views keep their look. Ask Dave is restyled inside the demo and shows an AI disclaimer there. Co-Authored-By: Claude Opus 5.5 --- app/public/app.js | 16 +++- app/public/ask-widget.js | 3 +- app/public/demo-cafe.css | 187 +++++++++++++++++++++++++++++++++++---- app/public/demo-cafe.js | 73 ++++++++++----- app/public/demo-world.js | 39 ++++++++ app/public/index.html | 79 +++++++++++++++-- app/server.ts | 2 +- app/ui.test.ts | 58 ++++++++++++ 8 files changed, 407 insertions(+), 50 deletions(-) create mode 100644 app/public/demo-world.js diff --git a/app/public/app.js b/app/public/app.js index d2c0e9f..2aebb71 100644 --- a/app/public/app.js +++ b/app/public/app.js @@ -1,4 +1,5 @@ import {enableCafe,refreshCafe,setCafeAsk} from './demo-cafe.js'; +import {demoRoute,applyDemoWorld} from './demo-world.js'; import { $, el, @@ -24,9 +25,14 @@ import { createAskWidget } from "./ask-widget.js"; mountIcons(); let askWidgetView = null; const cafeEnabled=await enableCafe(); +let lastView = null; function navigate() { + const demo = cafeEnabled ? demoRoute(location.hash || "#demo") : null; + if (demo && location.hash !== demo.hash) + history.replaceState(null, "", demo.hash); + applyDemoWorld(document, demo ? demo.chapter : null); const view = - cafeEnabled && (location.hash === "#demo" || !location.hash) + demo ? "demo-cafe" : location.hash === "#payments" ? "payments" @@ -52,7 +58,9 @@ function navigate() { ? "Ask Dave" : "1Click lab"; document.title = "Countersign · " + $("#page-label").textContent; - if (view === "demo-cafe") refreshCafe(); + // Chapter tabs switch views only; the ledger is read when entering the demo. + if (view === "demo-cafe" && lastView !== "demo-cafe") refreshCafe(); + lastView = view; if (view === "ask-dave") refreshAskSource(); if (view === "agent-payments") refreshAgentPayments(); if (askWidgetView) askWidgetView(view); @@ -61,7 +69,7 @@ window.addEventListener("hashchange", navigate); navigate(); document .querySelectorAll( - 'a[href="#demo"],a[href="#payments"],a[href="#quote-lab"],a[href="#ask-dave"],a[href="#agent-payments"]', + 'a[href="#demo"],a[href^="#demo/"],a[href="#payments"],a[href="#quote-lab"],a[href="#ask-dave"],a[href="#agent-payments"]', ) .forEach((link) => link.addEventListener("click", (event) => { @@ -458,7 +466,7 @@ const askWidget = createAskWidget({ window.scrollTo({ top: 0, behavior: "instant" }); }, }); -setCafeAsk(trigger=>askWidget.open("How is my agent doing?",trigger)); +setCafeAsk(trigger=>askWidget.open("How is my agent doing?",trigger),(bill,trigger)=>askWidget.askForBill(bill,trigger)); askFromBill((bill, trigger) => askWidget.askForBill(bill, trigger)); askWidgetView = (view) => { if (askWidget.setOnAskDaveView(view === "ask-dave")) askTextInput.focus(); diff --git a/app/public/ask-widget.js b/app/public/ask-widget.js index 4f096bc..287f4ec 100644 --- a/app/public/ask-widget.js +++ b/app/public/ask-widget.js @@ -30,6 +30,7 @@ export function createAskWidget({ onNavigate } = {}) { listTitle = el("h3", "Recent answers", "ask-widget-answers-title"), list = el("div", "", "ask-widget-answers ask-answer-list"), openLink = el("a", "Open full Ask Dave", "ask-widget-open"), + disclaimer = el("p", "Dave is AI and can make mistakes. Payments are always decided by the vault.", "ask-widget-disclaimer"), panelFoot = el("footer", "", "ask-widget-footer"); closeBtn.type = "button"; closeBtn.setAttribute("aria-label", "Close Ask Dave"); @@ -52,7 +53,7 @@ export function createAskWidget({ onNavigate } = {}) { panel.setAttribute("role", "dialog"); panel.setAttribute("aria-labelledby", "ask-widget-title"); panel.hidden = true; - panel.append(header, hint, sourceNote, listTitle, list, panelFoot); + panel.append(header, hint, sourceNote, listTitle, list, disclaimer, panelFoot); form = el("form", "", "ask-widget-form"); input = el("input", "", "ask-widget-input"); diff --git a/app/public/demo-cafe.css b/app/public/demo-cafe.css index 2bfa554..512af90 100644 --- a/app/public/demo-cafe.css +++ b/app/public/demo-cafe.css @@ -1,17 +1,172 @@ -#demo-cafe .cafe-strip { padding:20px; margin-bottom:24px; } -#demo-cafe .cafe-strip ol { display:flex; flex-wrap:wrap; gap:12px 36px; padding-left:20px; margin-top:12px; } -#demo-cafe .cafe-actions { display:flex; flex-wrap:wrap; align-items:center; gap:10px; margin:20px 0; } -#demo-cafe .cafe-live { display:flex; align-items:center; gap:6px; font-size:12px; } -#demo-cafe .cafe-ledger { display:grid; grid-template-columns:repeat(auto-fit,minmax(240px,1fr)); gap:16px; margin:16px 0; } -#demo-cafe .cafe-supplier { padding:20px; min-width:0; } -#demo-cafe .cafe-supplier strong { display:block; font-size:22px; margin:18px 0 6px; } -#demo-cafe code { display:block; overflow-wrap:anywhere; font-size:11px; margin:8px 0; } -#demo-cafe details { border-top:1px solid var(--line); padding:12px 0; } -#demo-cafe .cafe-bill { border-bottom:1px solid var(--line); padding:12px 0; } -#demo-cafe .cafe-bill span { display:block; margin-top:4px; } -#demo-cafe h2 { margin-top:24px; } -#cafe-read-at,#cafe-summary p { color:var(--muted); font-size:13px; margin:8px 0; } +/* Demo world. Everything is scoped under body.demo-world, which only the + #demo/* routes set, so the product views keep their own look. */ +.ask-widget-disclaimer { display: none; } -#demo-cafe .cafe-live { white-space:nowrap; } -#demo-cafe .cafe-live input { width:16px; height:16px; min-height:0; margin:0; padding:0; } -#demo-cafe .cafe-budget-note { flex-basis:100%; border-left:3px solid var(--line); padding:8px 12px; margin:8px 0; font-size:13px; } +body.demo-world { + --dw-bg: #0a0b0b; + --dw-surface: #121414; + --dw-surface-2: #1a1d1d; + --dw-line: #262a2a; + --dw-text: #eef2f0; + --dw-muted: #8b9692; + --dw-green: #00ec97; + --dw-on-green: #04120c; + --dw-red: #ff4d4f; + --dw-yellow: #ffd23f; + --dw-sans: "Helvetica Neue", Helvetica, Arial, sans-serif; + --dw-mono: ui-monospace, Menlo, monospace; + color-scheme: dark; + background: var(--dw-bg); + color: var(--dw-text); + font-family: var(--dw-sans); + overflow-x: hidden; +} +body.demo-world #workspace { margin: 0; min-height: 100vh; } +body.demo-world .content { max-width: none; margin: 0; padding: 0; } +body.demo-world #demo-cafe { min-height: 100vh; font-family: var(--dw-sans); font-size: 14px; line-height: 1.5; } +body.demo-world #demo-cafe h1, +body.demo-world #demo-cafe h2, +body.demo-world #demo-cafe h3 { color: var(--dw-text); font-family: var(--dw-sans); font-weight: 700; letter-spacing: -0.02em; margin: 0; } +body.demo-world #demo-cafe a { color: var(--dw-green); } +body.demo-world #demo-cafe :focus-visible { outline: 2px solid var(--dw-green); outline-offset: 2px; } + +/* Top bar */ +body.demo-world .dw-top { + height: 72px; display: grid; grid-template-columns: auto 1fr auto; align-items: stretch; gap: 24px; + padding: 0 32px; border-bottom: 1px solid var(--dw-line); background: var(--dw-bg); +} +body.demo-world .dw-brand { display: flex; flex-direction: column; justify-content: center; gap: 2px; min-width: 0; } +body.demo-world #cafe-title { font-size: 16px; white-space: nowrap; } +body.demo-world .dw-slash { color: var(--dw-muted); font-weight: 400; } +body.demo-world .dw-accent { color: var(--dw-green); } +body.demo-world #demo-cafe .dw-exit { color: var(--dw-muted); font-size: 11px; text-decoration: none; } +body.demo-world #demo-cafe .dw-exit:hover { color: var(--dw-text); text-decoration: underline; } +body.demo-world .dw-chapters { display: flex; justify-content: center; align-items: stretch; gap: 4px; min-width: 0; } +body.demo-world #demo-cafe .dw-tab { + display: flex; align-items: center; gap: 8px; padding: 0 14px; white-space: nowrap; + color: var(--dw-muted); text-decoration: none; font-size: 13px; font-weight: 600; + border-bottom: 2px solid transparent; margin-bottom: -1px; +} +body.demo-world #demo-cafe .dw-tab:hover { color: var(--dw-text); } +body.demo-world #demo-cafe .dw-tab[aria-current="page"] { color: var(--dw-text); border-bottom-color: var(--dw-green); } +body.demo-world .dw-num { font-family: var(--dw-mono); font-size: 11px; color: var(--dw-muted); } +body.demo-world .dw-tab[aria-current="page"] .dw-num { color: var(--dw-green); } +body.demo-world .dw-balances { display: flex; align-items: center; gap: 28px; } +body.demo-world .dw-balance { display: flex; flex-direction: column; align-items: flex-end; } +body.demo-world .dw-label { + display: block; font-family: var(--dw-mono); font-size: 11px; letter-spacing: 1.5px; + text-transform: uppercase; color: var(--dw-muted); margin: 0; +} +body.demo-world .dw-value { font-family: var(--dw-mono); font-size: 20px; font-weight: 700; color: var(--dw-text); white-space: nowrap; } +body.demo-world .dw-green { color: var(--dw-green); } + +/* Body and chapters */ +body.demo-world .dw-body { max-width: 1320px; margin: 0 auto; padding: 32px 32px 120px; } +body.demo-world .dw-chapter > h2, +body.demo-world .dw-main h2 { font-size: 30px; line-height: 1.15; margin: 6px 0 18px; } +body.demo-world .dw-kicker { font-family: var(--dw-mono); font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--dw-green); margin: 0; } +body.demo-world .dw-muted, +body.demo-world #cafe-read-at { color: var(--dw-muted); font-size: 13px; margin: 6px 0; } +body.demo-world .dw-mono, +body.demo-world #demo-cafe code { font-family: var(--dw-mono); } +body.demo-world .dw-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, 1fr); border-top: 1px solid var(--dw-line); } +body.demo-world .dw-grid[hidden] { display: none; } +body.demo-world .dw-col { padding: 20px 24px; min-width: 0; } +body.demo-world .dw-col + .dw-col { border-left: 1px solid var(--dw-line); } +body.demo-world .dw-col > .dw-label { margin-bottom: 8px; } +body.demo-world .dw-rows { border-top: 1px solid var(--dw-line); } +body.demo-world .dw-row { padding: 12px 0; border-bottom: 1px solid var(--dw-line); min-width: 0; } +body.demo-world .dw-row p { margin: 4px 0 0; overflow-wrap: anywhere; } +body.demo-world .dw-row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; } +body.demo-world .dw-row-head strong { font-size: 13px; overflow-wrap: anywhere; min-width: 0; } +body.demo-world .dw-fact { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 16px; align-items: baseline; } +body.demo-world .dw-fact strong { font-size: 15px; overflow-wrap: anywhere; } +body.demo-world .dw-reason { color: var(--dw-red); font-size: 13px; } +body.demo-world .dw-row .button { margin-top: 8px; } +body.demo-world .dw-tag { + font-family: var(--dw-mono); font-size: 10px; letter-spacing: 1px; font-weight: 700; padding: 2px 6px; white-space: nowrap; + color: var(--dw-muted); background: rgba(139, 150, 146, 0.13); +} +body.demo-world .dw-tag.paid { color: var(--dw-green); background: rgba(0, 236, 151, 0.13); } +body.demo-world .dw-tag.stopped { color: var(--dw-red); background: rgba(255, 77, 79, 0.13); } +body.demo-world .dw-tag.warn { color: var(--dw-yellow); background: rgba(255, 210, 63, 0.13); } + +/* Controls */ +body.demo-world #demo-cafe .cafe-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 20px 0; } +body.demo-world #demo-cafe .cafe-actions:empty { display: none; } +body.demo-world #demo-cafe .button, +body.demo-world .ask-widget-panel .button { + border-radius: 0; font-family: var(--dw-sans); font-weight: 700; background: transparent; + border: 1px solid var(--dw-line); color: var(--dw-text); +} +body.demo-world #demo-cafe .button.primary, +body.demo-world .ask-widget-panel .button.primary { background: var(--dw-green); border-color: var(--dw-green); color: var(--dw-on-green); } +body.demo-world #demo-cafe .button.primary:hover:not(:disabled) { background: #33f0ac; } +body.demo-world #demo-cafe .button:not(.primary):hover:not(:disabled), +body.demo-world .ask-widget-panel .button:not(.primary):hover:not(:disabled) { background: var(--dw-surface-2); color: var(--dw-text); } +body.demo-world #demo-cafe .button.ghost { border-color: transparent; color: var(--dw-muted); padding-inline: 0; } +body.demo-world #demo-cafe .button.ghost:hover:not(:disabled) { background: transparent; color: var(--dw-green); } +body.demo-world #demo-cafe .cafe-live { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dw-muted); white-space: nowrap; } +body.demo-world #demo-cafe .cafe-live input { width: 16px; height: 16px; min-height: 0; margin: 0; padding: 0; accent-color: var(--dw-green); } +body.demo-world #demo-cafe .cafe-budget-note { flex-basis: 100%; border-left: 2px solid var(--dw-yellow); padding: 8px 12px; margin: 8px 0; font-size: 13px; color: var(--dw-text); background: rgba(255, 210, 63, 0.08); } +body.demo-world #cafe-progress { font-family: var(--dw-mono); font-size: 12px; color: var(--dw-muted); } +body.demo-world #cafe-progress:empty { display: none; } +body.demo-world #cafe-feedback .notice { border-radius: 0; border: 0; border-left: 2px solid var(--dw-green); background: var(--dw-surface); color: var(--dw-text); margin: 0 0 20px; } +body.demo-world #cafe-feedback .notice.danger { border-left-color: var(--dw-red); } +body.demo-world #cafe-feedback .notice.warning { border-left-color: var(--dw-yellow); } + +/* End of day ledger */ +body.demo-world #demo-cafe .cafe-ledger { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); border-top: 1px solid var(--dw-line); border-left: 1px solid var(--dw-line); margin: 16px 0; } +body.demo-world #demo-cafe .cafe-supplier { padding: 20px; min-width: 0; border-right: 1px solid var(--dw-line); border-bottom: 1px solid var(--dw-line); } +body.demo-world #demo-cafe .cafe-supplier h3 { font-size: 16px; } +body.demo-world #demo-cafe .cafe-supplier strong { display: block; font-size: 22px; margin: 16px 0 4px; color: var(--dw-green); } +body.demo-world #demo-cafe code { display: block; overflow-wrap: anywhere; font-size: 11px; margin: 6px 0; color: var(--dw-muted); background: none; padding: 0; } +body.demo-world #demo-cafe details { border-top: 1px solid var(--dw-line); padding: 10px 0; } +body.demo-world #demo-cafe summary { cursor: pointer; font-family: var(--dw-mono); font-size: 12px; overflow-wrap: anywhere; } + +/* Ask Dave inside the demo */ +body.demo-world .ask-fab { border-radius: 0; background: var(--dw-green); border-color: var(--dw-green); color: var(--dw-on-green); box-shadow: none; } +body.demo-world .ask-fab:hover { background: #33f0ac; box-shadow: none; } +body.demo-world .ask-widget-panel { border-radius: 0; background: var(--dw-surface); border-color: var(--dw-line); color: var(--dw-text); box-shadow: none; font-family: var(--dw-sans); } +body.demo-world .ask-widget-panel h2, +body.demo-world .ask-widget-panel h3 { color: var(--dw-text); } +body.demo-world .ask-widget-answers-title { font-family: var(--dw-mono); font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--dw-muted); } +body.demo-world .ask-widget-hint, +body.demo-world .ask-widget-source, +body.demo-world .ask-widget-panel .ask-sources, +body.demo-world .ask-widget-panel .ask-loading { color: var(--dw-muted); } +body.demo-world .ask-widget-input { border-radius: 0; background: var(--dw-bg); border-color: var(--dw-line); color: var(--dw-text); } +body.demo-world .ask-widget-panel .ask-card { border-top-color: var(--dw-line); } +body.demo-world .ask-widget-panel .badge { border-radius: 0; font-family: var(--dw-mono); } +body.demo-world .ask-widget-panel .chip { border-radius: 0; background: transparent; border-color: var(--dw-line); color: var(--dw-muted); } +body.demo-world .ask-widget-panel .chip:hover:not(:disabled) { background: var(--dw-surface-2); color: var(--dw-green); border-color: var(--dw-line); } +body.demo-world .ask-widget-panel .ask-card-body.has-error .ask-line { color: var(--dw-red); } +body.demo-world .ask-widget-panel a { color: var(--dw-green); } +body.demo-world .ask-widget-disclaimer { display: block; margin: 0; padding-top: 8px; border-top: 1px solid var(--dw-line); font-size: 11px; color: var(--dw-muted); } + +/* Narrow screens: tabs drop under the brand; chapters stack. */ +@media (max-width: 1180px) { + body.demo-world .dw-top { height: auto; grid-template-columns: minmax(0, 1fr) auto; row-gap: 0; padding: 12px 24px 0; } + body.demo-world .dw-chapters { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; overflow-x: auto; height: 48px; margin: 8px -24px 0; padding: 0 12px; border-top: 1px solid var(--dw-line); } +} +@media (max-width: 900px) { + body.demo-world .dw-grid { grid-template-columns: minmax(0, 1fr); } + body.demo-world .dw-col { padding: 20px 0; } + body.demo-world .dw-col + .dw-col { border-left: 0; border-top: 1px solid var(--dw-line); } + body.demo-world .dw-main { order: -1; } + body.demo-world .dw-body { padding: 24px 16px 120px; } + body.demo-world .dw-fact { grid-template-columns: minmax(0, 1fr); gap: 2px; } +} +@media (max-width: 600px) { + body.demo-world .dw-top { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 0; } + body.demo-world .dw-balances { justify-content: space-between; gap: 16px; margin-top: 10px; } + body.demo-world .dw-balance { align-items: flex-start; } + body.demo-world .dw-value { font-size: 17px; } + body.demo-world .dw-chapters { margin: 10px -16px 0; padding: 0 4px; } + body.demo-world #demo-cafe .dw-tab { padding: 0 10px; } + body.demo-world .dw-chapter > h2, + body.demo-world .dw-main h2 { font-size: 24px; } +} +@media (max-width: 720px) { + body.demo-world .ask-widget-dock { background: var(--dw-bg); border-top-color: var(--dw-line); } +} diff --git a/app/public/demo-cafe.js b/app/public/demo-cafe.js index 28faa70..3dc6346 100644 --- a/app/public/demo-cafe.js +++ b/app/public/demo-cafe.js @@ -1,51 +1,80 @@ import {$,el,api,button,notice} from './components.js'; import {formatUnits,cafeBudgetSpent} from './state.js'; -let enabled=false,busy=false,ask=null; +let enabled=false,busy=false,ask=null,askBill=null; const root=$('#demo-cafe'),feedback=$('#cafe-feedback'); -export function setCafeAsk(callback){ask=callback;} +export function setCafeAsk(callback,billCallback=null){ask=callback;askBill=billCallback;} export async function enableCafe(){ try{enabled=(await api('/api/config')).demoEnabled===true;}catch{enabled=false;} $('#demo-nav').hidden=!enabled;return enabled; } function lock(){root.setAttribute('aria-busy',String(busy));root.querySelectorAll('button,input').forEach(n=>n.disabled=busy);} -const BUDGET_SPENT="Today's budget is spent: the vault is doing its job. Bills blocked by the budget can be resumed once earlier payments are 24 hours old. Policy and invoice expiry still apply. Press Reset café to start a fresh day."; +const BUDGET_SPENT="Today's budget is spent: the vault is doing its job. Bills blocked by the budget can be resumed once earlier payments are 24 hours old. Policy and invoice expiry still apply. Press Start a new day to reset the café."; // The existing Agent payments state already carries the vault's rolling usage. async function readSpending(state){ if(!state.ready)return null; try{const reply=await api('/api/agent/state');return reply.ok?reply.state.spending:null;}catch{return null;} } +const TAGS={paid:['PAID','paid'],rejected:['REJECTED','stopped'],blocked:['STOPPED','stopped'],failed:['STOPPED','stopped'],queued:['QUEUED','neutral'],proposed:['QUEUED','neutral'],pending:['PENDING','warn']}; +function tag(outcome){const [label,tone]=TAGS[outcome]??[String(outcome).toUpperCase(),'neutral'];return el('span',label,'dw-tag '+tone);} +function row(title,detail,outcome=null){ + const item=el('div','','dw-row'),head=el('div','','dw-row-head');head.append(el('strong',title,'dw-mono')); + if(outcome)head.append(tag(outcome));item.append(head);if(detail)item.append(el('p',detail,'dw-muted'));return item; +} +function fact(label,value){const item=el('div','','dw-row dw-fact');item.append(el('span',label,'dw-label'),el('strong',value,'dw-mono'));return item;} function render(state,spending=null){ - const summary=$('#cafe-summary'),actions=$('#cafe-actions'),ledger=$('#cafe-ledger'),rejected=$('#cafe-rejected'),bills=$('#cafe-bills'); - for(const target of [summary,actions,ledger,rejected,bills])target.replaceChildren(); + const ids=['#cafe-summary','#cafe-actions','#cafe-ledger','#cafe-rejected','#cafe-bills','#cafe-rules','#cafe-bank-actions','#cafe-post-actions','#cafe-pay-actions','#cafe-end-actions','#cafe-queue','#cafe-results']; + const [summary,actions,ledger,rejected,bills,rules,bank,post,pay,end,queue,results]=ids.map(id=>$(id)); + for(const target of [summary,actions,ledger,rejected,bills,rules,bank,post,pay,end,queue,results])target.replaceChildren(); + $('#cafe-read-at').textContent=''; if(!state.ready){ - summary.append(el('p',state.existing?'An agent vault exists. Reset backs it up before opening a fresh café.':'Open a café with three suppliers and 5 test NEAR.')); + $('#dw-vault').textContent='—'; + actions.append(el('p',state.existing?'An agent vault exists. Reset backs it up before opening a fresh café.':'Open a café with three suppliers and 5 test NEAR.','dw-muted')); actions.append(button(state.existing?'Reset café':'Open the café',()=>mutate(state.existing?'reset':'setup'),{tone:'primary'})); return; } - summary.append(el('p','Local sandbox · '+state.vault),el('p','Bean Co, Milk Co and Pastry Co have pinned signing keys and payouts. Milk Co has a weekly service.'), - el('p',`${state.policy.per_payment_near} NEAR per payment · ${state.policy.rolling_24h_limit_near} NEAR daily budget (rolling 24 hours) · expires ${new Date(state.policy.expires_at).toLocaleTimeString()}`), - el('strong',formatUnits(state.available)+' test NEAR available')); + $('#dw-vault').textContent=formatUnits(state.available)+' NEAR'; + // 01 The bank + summary.append(fact('Vault','Local sandbox · '+state.vault),fact('Balance',formatUnits(state.available)+' test NEAR available')); + bank.append(button('Top up vault (+5 test NEAR)',()=>mutate('faucet'),{tone:'primary'})); + // 02 Your rules (read only) + rules.append(fact('Per payment',state.policy.per_payment_near+' NEAR'),fact('Daily budget',state.policy.rolling_24h_limit_near+' NEAR · rolling 24 hours'), + fact('Expires',new Date(state.policy.expires_at).toLocaleTimeString()), + fact('Suppliers','Bean Co, Milk Co and Pastry Co have pinned signing keys and payouts. Milk Co has a weekly service.')); + // 03 Morning post + post.append(button("Receive today's invoices",()=>mutate('receive'),{tone:'primary'})); + for(const bill of state.bills)bills.append(row(bill.id,bill.merchant+' · '+bill.amount_near+' NEAR',bill.outcome)); + if(!state.bills.length)bills.append(el('p','No invoices yet.','dw-muted')); + for(const bill of state.rejected)rejected.append(row(bill.id,bill.reason,'rejected')); + if(!state.rejected.length)rejected.append(el('p','No invoices rejected at intake.','dw-muted')); + // 04 Agent pays const spent=cafeBudgetSpent(spending,state.bills,state.policy); - actions.append(button("Receive today's invoices",()=>mutate('receive'),{tone:'primary'}),button('Pay all',()=>mutate('pay-all',{live:$('#cafe-live').checked}),{tone:'primary'})); - const live=el('input');live.type='checkbox';live.id='cafe-live';const label=el('label','','cafe-live');label.append(live,el('span','Use live AI'));actions.append(label, - button('Top up vault (+5 test NEAR)',()=>mutate('faucet'),{tone:'secondary'}),button('Reset café',()=>mutate('reset'),{tone:'ghost'}),button('Refresh ledger',()=>refreshCafe(),{tone:'ghost'})); - // Sits directly under the action row, beside the faucet button. - if(spent){const note=el('p',BUDGET_SPENT+' Topping up adds balance; it does not raise the daily budget (rolling 24 hours).','cafe-budget-note');note.setAttribute('role','status');actions.append(note);} + pay.append(button('Pay all',()=>mutate('pay-all',{live:$('#cafe-live').checked}),{tone:'primary'})); + const live=el('input');live.type='checkbox';live.id='cafe-live';const label=el('label','','cafe-live');label.append(live,el('span','Use live AI'));pay.append(label); + // Sits with the payment results, beside Pay all. + if(spent){const note=el('p',BUDGET_SPENT+' Topping up adds balance; it does not raise the daily budget (rolling 24 hours).','cafe-budget-note');note.setAttribute('role','status');pay.append(note);} + const done=state.bills.filter(b=>['paid','blocked','failed'].includes(b.outcome)); + for(const bill of state.bills.filter(b=>!done.includes(b)))queue.append(row(bill.id,bill.merchant+' · '+bill.amount_near+' NEAR',bill.outcome)); + if(!queue.children?.length)queue.append(el('p','Nothing waiting.','dw-muted')); + for(const bill of done){ + const item=row(bill.id,bill.merchant+' · '+bill.amount_near+' NEAR',bill.outcome); + if(bill.error)item.append(el('p',bill.error,'dw-reason')); + item.append(button('Ask Dave why',event=>askBill?.(bill,event.currentTarget),{tone:'ghost'}));results.append(item); + } + if(!done.length)results.append(el('p','No payments yet. Press Pay all.','dw-muted')); + // 05 End of day for(const supplier of state.suppliers){ - const card=el('article','','panel cafe-supplier'); - card.append(el('h3',supplier.name),el('code',supplier.payee),el('strong',formatUnits(supplier.received)+' NEAR received'),el('p',supplier.paid_count+(supplier.paid_count===1?' bill paid':' bills paid'))); - if(!supplier.receipts.length)card.append(el('p','No paid invoices yet.')); + const card=el('article','','cafe-supplier'); + card.append(el('h3',supplier.name),el('code',supplier.payee),el('strong',formatUnits(supplier.received)+' NEAR received','dw-mono'),el('p',supplier.paid_count+(supplier.paid_count===1?' bill paid':' bills paid'),'dw-muted')); + if(!supplier.receipts.length)card.append(el('p','No paid invoices yet.','dw-muted')); for(const receipt of supplier.receipts){ const detail=el('details');detail.append(el('summary',receipt.invoice_id+' · '+formatUnits(receipt.amount)+' NEAR'), el('code','State: '+receipt.state),el('code','Attempt ID: '+receipt.attempt_id),el('code','Signed payload hash: '+receipt.payload_hash));card.append(detail); } ledger.append(card); } - const scam=el('article','','panel cafe-supplier');scam.append(el('h3','Scam payee'),el('code',state.scam.payee),el('strong',formatUnits(state.scam.received)+' NEAR received'),el('p','Live balance change since café setup.'));ledger.append(scam); + const scam=el('article','','cafe-supplier');scam.append(el('h3','Scam payee'),el('code',state.scam.payee),el('strong',formatUnits(state.scam.received)+' NEAR received','dw-mono'),el('p','Live balance change since café setup.','dw-muted'));ledger.append(scam); $('#cafe-read-at').textContent='Live chain read · '+new Date(state.read_at).toLocaleTimeString()+'. Received totals exclude initial account funding.'; - for(const bill of state.bills){const item=el('div','','cafe-bill');item.append(el('strong',bill.id),el('span',bill.merchant+' · '+bill.amount_near+' NEAR · '+bill.outcome));if(bill.error)item.append(el('p',bill.error));bills.append(item);} - for(const bill of state.rejected)rejected.append(el('p',bill.id+' — '+bill.reason)); - if(!state.rejected.length)rejected.append(el('p','No invoices rejected at intake.')); + end.append(button('Refresh ledger',()=>refreshCafe(),{tone:'ghost'}),button('Start a new day',()=>mutate('reset'),{tone:'secondary'})); } export async function refreshCafe(){ if(!enabled||busy)return;busy=true;lock(); @@ -59,7 +88,7 @@ async function mutate(action,body={}){ if(polling)return;polling=true; try{const reply=await api('/api/demo/progress');if(reply.ok&&reply.progress.running)$('#cafe-progress').textContent=`${reply.progress.completed} / ${reply.progress.total} processed · ${reply.progress.current??'Starting'}`;}catch{}finally{polling=false;} },1200):null; - try{const reply=await api('/api/demo/'+action,body);if(!reply.ok)throw Error(reply.error);render(reply.state,await readSpending(reply.state));notice(feedback,action==='pay-all'?'Payment run complete. Review the supplier ledger and blocked bills.':'Café updated.','success');} + try{const reply=await api('/api/demo/'+action,body);if(!reply.ok)throw Error(reply.error);render(reply.state,await readSpending(reply.state));notice(feedback,action==='pay-all'?'Payment run complete. Review the results and the supplier ledger.':'Café updated.','success');} catch(error){notice(feedback,'Café operation could not finish','danger',error.message);} finally{clearInterval(timer);$('#cafe-progress').textContent='';busy=false;lock();} } diff --git a/app/public/demo-world.js b/app/public/demo-world.js new file mode 100644 index 0000000..4f5b41a --- /dev/null +++ b/app/public/demo-world.js @@ -0,0 +1,39 @@ +// Demo world routing. Pure helpers plus one DOM toggle that only uses +// attributes and classList, so it stays unit-testable (see ui.test.ts). +export const CHAPTERS = [ + { id: "bank", number: "01", label: "The bank" }, + { id: "rules", number: "02", label: "Your rules" }, + { id: "post", number: "03", label: "Morning post" }, + { id: "pay", number: "04", label: "Agent pays" }, + { id: "end", number: "05", label: "End of day" }, +]; +export const DEFAULT_CHAPTER = "post"; + +// null: not a demo hash. Otherwise the chapter to show and its canonical hash. +export function demoRoute(hash) { + const value = String(hash ?? ""); + if (value !== "#demo" && !value.startsWith("#demo/")) return null; + const wanted = value.slice("#demo/".length); + const chapter = CHAPTERS.some((c) => c.id === wanted) ? wanted : DEFAULT_CHAPTER; + return { chapter, hash: "#demo/" + chapter }; +} + +// chapter null leaves the demo world and restores the product chrome. +export function applyDemoWorld(doc, chapter) { + const on = Boolean(chapter); + doc.body.classList.toggle("demo-world", on); + for (const selector of [".sidebar", ".topbar"]) { + const node = doc.querySelector(selector); + if (node) node.hidden = on; + } + doc.querySelectorAll(".dw-chapter").forEach((node) => { + node.hidden = node.dataset.chapter !== chapter; + }); + doc.querySelectorAll(".dw-tab").forEach((node) => { + if (node.dataset.chapter === chapter) { + node.setAttribute("aria-current", "page"); + // Narrow screens scroll the tab strip; keep the current chapter visible. + node.scrollIntoView?.({ block: "nearest", inline: "nearest" }); + } else node.removeAttribute("aria-current"); + }); +} diff --git a/app/public/index.html b/app/public/index.html index 438007e..08b89b1 100644 --- a/app/public/index.html +++ b/app/public/index.html @@ -61,12 +61,79 @@ >
-