Smart Waste AI Build & Verification

By Mooroo · Published July 25, 2026

Assembles a self-contained HTML prototype from 10 parts, applies map patches, and performs static + runtime verification of structure, brackets, symbols, and AI logic.

7 cells1 experiment23 views0 forks

Inside this notebook

# Smart Waste AI — single-file build & static verification Assembles the 10 authored HTML/CSS/JS parts of the **Smart Waste AI** product prototype into one self-contained `smart-waste-ai.html`, applies two map-engine patches (street lattice geometry, zoom-out glyph, flow-chart legend), then statically verifies the bundle: doctype/structure, tag balance, zero external references, and a string/comment/template/regex-aware bracket-balance check over the JavaScript. The assembled file is written to `/home/user/` and auto-persisted to outputs.

import re

# ---------- 1. load the ten authored parts ----------
parts = [open(f'build/p{i:02d}.html').read() for i in range(1, 11)]
p09 = parts[8]

# ---------- 2. patches: map street lattice, zoom-out glyph, flow legend ----------
old_streets = """  const streets=el('g',{stroke:'var(--map-street)','stroke-width':'4','stroke-linecap':'round',opacity:'.9'});
  for(let r=0;r<4;r++){const a=WGRID[Math.min(r,2)][0],b=WGRID[Math.min(r,2)][r===3?2:2];
    const p1=r===3?WGRID[2][3]:WGRID[r][3];
    streets.appendChild(el('path',{d:`M${WGRID[Math.min(r,2)][0][0]},${WGRID[Math.min(r,2)][0][1]} L${p1[0]},${p1[1]}`,fill:'none'}));}
  for(let c=0;c<4;c++){const p1=c===3?WGRID[2][c]:WGRID[2][c];
    streets.appendChild(el('path',{d:`M${WGRID[0][Math.min(c,3)][0]},${WGRID[0][Math.min(c,3)][1]} L${WGRID[2][Math.min(c,3)][0]},${WGRID[2][Math.min(c,3)][1]}`,fill:'none'}));}
  world.appendChild(streets);"""
new_streets = """  const streets=el('g',{stroke:'var(--map-street)','stroke-width':'4','stroke-linecap':'round',opacity:'.9'});
  const q=(r,c)=>WGRID[r*3+c];
  const sline=(p1,p2)=>streets.appendChild(el('path',{d:`M${p1[0].toFixed(1)},${p1[1].toFixed(1)} L${p2[0].toFixed(1)},${p2[1].toFixed(1)}`,fill:'none'}));
  for(let r=0;r<3;r++){sline(q(r,0)[0],q(r,2)[1]);sline(q(r,0)[3],q(r,2)[2]);}
…
assembled: 208,103 bytes
external refs: ['http://www.w3.org/2000/svg', 'http://www.w3.org/2000/svg', 'http://www.w3.org/2000/svg', 'http://www.w3.org/2000/svg', 'http://www.w3.org/2000/svg']
  <div>: 459 open / 459 close
  <section>: 9 open / 9 close
  <button>: 63 open / 63 close
  <table>: 4 open / 6 close   <-- CHECK (4 vs 6)
  <svg>: 12 open / 12 close
  <aside>: 2 open / 2 close
  <nav>: 3 open / 3 close
  <header>: 2 open / 2 close
  <footer>: 1 open / 1 close
  <select>: 5 open / 5 close…
html = open('smart-waste-ai.html').read()
js = html.split('<script>')[1].split('</script>')[0]
lines = js.split('\n')

print('--- JS lines 733-748 (first unclosed brace at 739) ---')
for i in range(732, 748):
    print(i + 1, '|', lines[i][:150])
--- JS lines 733-748 (first unclosed brace at 739) ---
733 | 
734 | /* ---------- auth helpers ---------- */
735 | function signOut(){S.authed=false;toast('Signed out. See you soon!','info','logout');go('#/');}
736 | /* ============================================================
737 |    LANDING VIEW
738 |    ============================================================ */
739 | function vLanding(){return `
740 | ${lnavHTML()}
741 | <!-- ================= HERO ================= -->
742 | <header…
import re
html = open('smart-waste-ai.html').read()
js = html.split('<script>')[1].split('</script>')[0]

pairs = {')': '(', ']': '[', '}': '{'}
stack, state = [], 'code'          # entries: (char, line) or (char, line, 'tplmark')
prev_sig, i, n, errors = '', 0, len(js), []
cur_line = lambda pos: js.count('\n', 0, pos) + 1

while i < n:
    ch = js[i]; nx = js[i + 1] if i + 1 < n else ''
    if state == 'code':
        if ch == '/' and nx == '/': state = 'line'; i += 2; continue
        if ch == '/' and nx == '*': state = 'block'; i += 2; continue
        if ch == "'": state = 'sq'; i += 1; continue
        if ch == '"': state = 'dq'; i += 1; continue
        if ch == '`': state = 'tpl'; i += 1; continue
        if ch == '/' and (prev_sig in '(,=:[!&|?{};+-*%<>~^' or prev_sig == ''):
…
end state: code (expect: code)
unclosed stack: EMPTY (all balanced)
errors: NONE
function defs: 82
template literals (backticks): 292 -> even: True
import re
html = open('smart-waste-ai.html').read()

# symbols defined in the sprite (+ the one injected at boot)
defined = set(re.findall(r'<symbol id="i-([a-z-]+)"', html))
defined |= set(re.findall(r"insertAdjacentHTML\('beforeend',\s*'<symbol id=\"i-([a-z-]+)\"", html))
defined.add('minus')  # injected at boot via insertAdjacentHTML

# every icon('name') call and every <use href="#i-name"> in markup
used = set(re.findall(r"icon\('([a-z-]+)'", html))
used |= set(re.findall(r'use href="#i-([a-z-]+)"', html))

missing = sorted(used - defined)
unused = sorted(defined - used)
print(f'{len(defined)} symbols defined, {len(used)} referenced')
print('MISSING (referenced but not defined):', missing if missing else 'NONE')
print('unused (defined but never referenced):', unused if unused else 'NONE')

…
60 symbols defined, 33 referenced
MISSING (referenced but not defined): NONE
unused (defined but never referenced): ['activity', 'arrow-down', 'arrow-ur', 'building', 'chart', 'chev-d', 'cloud-sun', 'command', 'filter', 'gauge', 'grid', 'home', 'image', 'info', 'landmark', 'layers', 'list', 'lock', 'mail', 'minus', 'nav', 'recycle', 'settings', 'user', 'users', 'wallet', 'zap']
queried-but-never-defined ids: ['po-']

## Runtime smoke test No browser/Node exists in this sandbox, so this cell executes the bundle's full JavaScript payload inside a headless V8 engine (`mini_racer`) with stubbed browser globals. It runs **all 12 view renderers** (landing, auth, app shell, citizen/org/municipality dashboards, analytics, map, settings) and the **AI + priority engine** (`classify`, `priorityOf`, `rationaleFor`, duplicate detection, smart descriptions, ward geometry, chart math), asserting sane outputs — a real execution pass on top of the static verification above.

# ---- 1. get a JS engine ----
try:
    import mini_racer
except ImportError:
    %pip install -q mini-racer
    import mini_racer
from mini_racer import MiniRacer
import json, re

# ---- 2. extract the app's JS payload and strip the DOM-touching boot lines ----
html = open('smart-waste-ai.html').read()
js = html.split('<script>')[1].split('</script>')[0]
js = js.split('/* boot */')[0]          # drop applyTheme/render/error-listener boot (DOM-heavy)
print(f'JS payload under test: {len(js):,} bytes')

# ---- 3. browser-global stubs (DOM, canvas 2D, storage, observers) ----
harness = r"""
var matchMedia = function(){ return { matches:false, addEventListener:function(){}, removeEventListener:function(){} } };
…
Note: you may need to restart the kernel to use updated packages.
Smart Waste AI Build & Verification | Clusy