Staffing Co-Pilot UI — architecture-first enrichments + shift clock
lakehouse/auditor 2 blocking issues: todo!() macro call in tests/real-world/scrum_master_pipeline.ts

J's direction: the dashboard was explanatory but not *actionable* as
a staffing-matrix console. Refactor so the architecture claims from
docs/PRD.md surface as operational signals on every contract card.

Backend (mcp-server/index.ts):

  + GET|POST /intelligence/arch_signals — probes live substrate health
    so the dashboard shows instant-search latency, index shape,
    playbook-memory entries, and pathway-memory (ADR-021) trace count.
    Fires one fresh /vectors/hybrid probe against workers_500k_v1 so
    the "instant search" number on screen is live, not cached.

  * /intelligence/permit_contracts now times every hybrid call per
    contract and returns search_latency_ms, so the card can display
    the per-query latency pill (⚡ 342ms).

  + Per-contract computed fields returned from the backend:
      search_latency_ms      — real /vectors/hybrid duration
      fill_probability       — base_pct (by pool_size×count ratio)
                               + curve [d0, d3, d7, d14, d21, d30]
                               with cumulative fill% per bucket
      economics              — avg_pay_rate, gross_revenue,
                               gross_margin, margin_pct,
                               payout_window_days [30, 45],
                               over_bill_count,
                               over_bill_pool_margin_at_risk
      shifts_needed          — 1st/2nd/3rd/4th inferred from
                               permit work_type + description regex

  * Pre-existing dangling-brace bug in api() fixed (the `activeTrace`
    logging block had been misplaced at module scope, referencing
    variables that only existed inside the function). Restart was
    failing with "Unexpected }" at line 76. Moved tracing inside the
    try block where parsed/path/body/ms are in scope.

Frontend (mcp-server/search.html):

  + Top "Substrate Signals" section — 4 live tiles (instant search,
    index, playbook memory, pathway matrix). Color-codes latency
    (green <100ms, amber <500ms, red otherwise).
  + "24/7 Shift Coverage" section — SVG 24-hour clock with 4 colored
    shift arcs (1st/2nd/3rd/4th), current-time needle, center label
    showing the live shift, per-shift contract count tiles beside.
    4th shift assumes weekend/split; handles 3rd-shift wrap across
    midnight by splitting into two arcs.
  + Per-card architecture pills: instant-search latency, SQL-filter
    pool-size with k=200 boost note, shift requirements.
  + Per-card fill-probability horizontal stacked bar with day
    markers (d0/d3/d7/d14/d21/d30) and per-bucket segment shading
    (green → amber → orange → red as time decays).
  + Per-card economics 4-tile grid: Est. Revenue, Est. Margin (with
    % colored by health), Payout Window (30–45d standard), Over-Bill
    Pool count + margin at risk.

Architecture smoke test (tests/architecture_smoke.ts, earlier commit)
still green: 11/11 pass including the new /intelligence/arch_signals
+ permit_contracts enrichments.

J specifically wanted: "shoot for the stars · hyperfocus · our
architecture is better because it self-regulates, uses hot-swap,
pulls from real data, and shows instant searches from clever
indexing." Every one of those is now a specific visible signal on
the page, not prose in the README.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
root
2026-04-24 14:24:11 -05:00
co-authored by Claude Opus 4.7
parent 4a94da2d41
commit 858954975b
2 changed files with 450 additions and 25 deletions
+281 -1
View File
@@ -116,6 +116,24 @@ body{font-family:'Inter',-apple-system,system-ui,'Segoe UI',sans-serif;backgroun
<div id="main"><div class="ld">Analyzing contracts and workers...</div></div>
<!-- Architecture signals — 4 live metrics proving the substrate claims -->
<div class="section" id="arch-signals-section">
<div class="section-header">
<span class="section-title">Substrate Signals — Architecture Live</span>
<span class="section-meta" id="arch-signals-meta">Instant search · Hot-swap-ready index · Self-regulating memory</span>
</div>
<div id="arch-signals" style="display:grid;grid-template-columns:repeat(4,1fr);gap:10px"><div class="ld" style="grid-column:1/-1">Probing substrate…</div></div>
</div>
<!-- 24/7 Shift clock — shows active contracts per shift + current time -->
<div class="section" id="shift-clock-section">
<div class="section-header">
<span class="section-title">24/7 Shift Coverage</span>
<span class="section-meta" id="shift-clock-meta">1st 06–14 · 2nd 14–22 · 3rd 22–06 · 4th weekend/split · now → red marker</span>
</div>
<div id="shift-clock" style="display:grid;grid-template-columns:220px 1fr;gap:20px;align-items:center"><div class="ld" style="grid-column:1/-1">Loading shift distribution…</div></div>
</div>
<div class="section" id="staffing-forecast-section">
<div class="section-header">
<span class="section-title">Staffing Forecast — Next 30 Days</span>
@@ -167,7 +185,7 @@ var P=location.pathname.indexOf('/lakehouse')>=0?'/lakehouse':'';
var A=location.origin+P;
var AC=['#1a2744','#1a3a2a','#2a1a3a','#3a2a1a','#1a3a3a','#2a2a1a'];
var lastQuery='';
window.addEventListener('load',function(){loadSystemSummary();loadDay();loadStaffingForecast();loadLiveContracts();loadMarket();loadLearning()});
window.addEventListener('load',function(){loadSystemSummary();loadArchSignals();loadDay();loadStaffingForecast();loadLiveContracts();loadMarket();loadLearning()});
function loadSystemSummary(){
api('/system/summary',{}).then(function(s){
@@ -196,6 +214,171 @@ function loadSystemSummary(){
}).catch(function(){/* non-fatal */});
}
// ─── Substrate signals: render the 4 architecture-health tiles ───
function loadArchSignals(){
var el=document.getElementById('arch-signals');
api('/intelligence/arch_signals',{}).then(function(s){
el.textContent='';
function tile(label, big, sub, accent){
var t=document.createElement('div');
t.style.cssText='background:#0d1117;border:1px solid #171d27;border-radius:10px;padding:14px 16px;border-left:3px solid '+(accent||'#58a6ff');
var l=document.createElement('div');l.style.cssText='font-size:10px;text-transform:uppercase;letter-spacing:1px;color:#545d68;margin-bottom:6px';l.textContent=label;
var b=document.createElement('div');b.style.cssText='font-size:20px;font-weight:600;color:#e6edf3;line-height:1.1';b.textContent=big;
var u=document.createElement('div');u.style.cssText='font-size:10px;color:#8b949e;margin-top:6px;line-height:1.4';u.textContent=sub;
t.appendChild(l);t.appendChild(b);t.appendChild(u);
return t;
}
var idx=s.index||{};
var pbm=s.playbook_memory||{};
var pwm=s.pathway_memory||{};
// Tile 1 — instant search (the "we cleverly indexed at ingest" claim)
var latencyColor=s.instant_search_probe_ms<100?'#2ea043':s.instant_search_probe_ms<500?'#d29922':'#f85149';
el.appendChild(tile(
'Instant Search',
(s.instant_search_probe_ms||'?')+'ms',
'Live /vectors/hybrid probe · 500K-row index · '+(idx.chunk_count||0).toLocaleString()+' chunks',
latencyColor
));
// Tile 2 — index shape (hot-swap claim)
el.appendChild(tile(
'Index',
(idx.dimensions||768)+'d · '+(idx.model||'?'),
(idx.source||'?')+' → '+(idx.name||'?')+' · '+(idx.backend||'parquet'),
'#58a6ff'
));
// Tile 3 — self-regulating memory
el.appendChild(tile(
'Playbook Memory',
(pbm.entries||0).toLocaleString()+' entries',
pbm.entries>0?'Meta-index active · boosts candidates from past fills':'Empty · POST /vectors/playbook_memory/rebuild to populate',
pbm.entries>0?'#2ea043':'#d29922'
));
// Tile 4 — ADR-021 pathway compounding
el.appendChild(tile(
'Pathway Matrix',
(pwm.total_pathways||0)+' traces',
pwm.retired+' retired · '+pwm.total_replays+' replays · ADR-021 compounding',
'#58a6ff'
));
}).catch(function(e){
el.textContent='substrate signals unavailable: '+e.message;
});
}
// ─── 24/7 Shift clock: SVG dial + per-shift contract counts ──────
function loadShiftClock(contracts){
var root=document.getElementById('shift-clock');
if(!contracts||!contracts.length){root.textContent='No live contracts to bucket by shift.';return;}
root.textContent='';
// SVG dial — 24h circle, 4 colored arcs for shifts, current-time needle
var SHIFT_COLORS={'1st':'#f9d171','2nd':'#f5894a','3rd':'#5f5fff','4th':'#2ea043'};
var SHIFT_HOURS={'1st':[6,14],'2nd':[14,22],'3rd':[22,6],'4th':null/* rotating */};
var now=new Date();
var hr=now.getHours()+now.getMinutes()/60;
var isWeekend=now.getDay()===0||now.getDay()===6;
// SVG — 200x200 clock
var R=90, CX=100, CY=100;
var svgNS='http://www.w3.org/2000/svg';
var svg=document.createElementNS(svgNS,'svg');
svg.setAttribute('viewBox','0 0 200 200');svg.setAttribute('width','200');svg.setAttribute('height','200');
svg.style.cssText='display:block';
// Outer ring
var bg=document.createElementNS(svgNS,'circle');
bg.setAttribute('cx',CX);bg.setAttribute('cy',CY);bg.setAttribute('r',R);
bg.setAttribute('fill','#0d1117');bg.setAttribute('stroke','#30363d');bg.setAttribute('stroke-width','1');
svg.appendChild(bg);
// Shift arcs — 1st/2nd/3rd as hour arcs. 4th (weekend/split) gets a dashed band.
function arcPath(startHr,endHr){
// 12 o'clock is 0h, clockwise, full circle = 24h
function pt(h){
var ang=((h/24)*2*Math.PI)-Math.PI/2;
return [CX+R*Math.cos(ang), CY+R*Math.sin(ang)];
}
var p0=pt(startHr), p1=pt(endHr);
var largeArc=(endHr-startHr+24)%24>12?1:0;
return 'M '+p0[0]+' '+p0[1]+' A '+R+' '+R+' 0 '+largeArc+' 1 '+p1[0]+' '+p1[1];
}
['1st','2nd','3rd'].forEach(function(shift){
var hrs=SHIFT_HOURS[shift];
var s,e;
if(shift==='3rd'){s=22;e=30;/* wraps to 06 */}else{s=hrs[0];e=hrs[1];}
var path=document.createElementNS(svgNS,'path');
path.setAttribute('d',arcPath(s,e%24===0?24:e%24||24));
// Handle 3rd wrap: split into two arcs
if(shift==='3rd'){
path.setAttribute('d',arcPath(22,24)+' '+arcPath(0,6));
}
path.setAttribute('fill','none');
path.setAttribute('stroke',SHIFT_COLORS[shift]);
path.setAttribute('stroke-width','10');
path.setAttribute('stroke-linecap','butt');
svg.appendChild(path);
});
// Hour tick marks at 0/6/12/18
[0,6,12,18].forEach(function(h){
var ang=((h/24)*2*Math.PI)-Math.PI/2;
var x1=CX+(R-7)*Math.cos(ang), y1=CY+(R-7)*Math.sin(ang);
var x2=CX+(R+2)*Math.cos(ang), y2=CY+(R+2)*Math.sin(ang);
var ln=document.createElementNS(svgNS,'line');
ln.setAttribute('x1',x1);ln.setAttribute('y1',y1);ln.setAttribute('x2',x2);ln.setAttribute('y2',y2);
ln.setAttribute('stroke','#8b949e');ln.setAttribute('stroke-width','1');
svg.appendChild(ln);
// Hour label
var xl=CX+(R-22)*Math.cos(ang), yl=CY+(R-22)*Math.sin(ang);
var tx=document.createElementNS(svgNS,'text');
tx.setAttribute('x',xl);tx.setAttribute('y',yl+3);
tx.setAttribute('text-anchor','middle');tx.setAttribute('fill','#8b949e');
tx.setAttribute('font-size','9');tx.setAttribute('font-family','monospace');
tx.textContent=String(h).padStart(2,'0');
svg.appendChild(tx);
});
// Current time needle
var ang=((hr/24)*2*Math.PI)-Math.PI/2;
var nx=CX+(R-3)*Math.cos(ang), ny=CY+(R-3)*Math.sin(ang);
var needle=document.createElementNS(svgNS,'line');
needle.setAttribute('x1',CX);needle.setAttribute('y1',CY);
needle.setAttribute('x2',nx);needle.setAttribute('y2',ny);
needle.setAttribute('stroke','#f85149');needle.setAttribute('stroke-width','2');
svg.appendChild(needle);
var dot=document.createElementNS(svgNS,'circle');
dot.setAttribute('cx',CX);dot.setAttribute('cy',CY);dot.setAttribute('r','3');
dot.setAttribute('fill','#f85149');
svg.appendChild(dot);
// Center label — current shift
function currentShift(){
if(isWeekend) return '4th';
if(hr>=6&&hr<14) return '1st';
if(hr>=14&&hr<22) return '2nd';
return '3rd';
}
var cs=currentShift();
var label=document.createElementNS(svgNS,'text');
label.setAttribute('x',CX);label.setAttribute('y',CY+30);
label.setAttribute('text-anchor','middle');label.setAttribute('fill',SHIFT_COLORS[cs]);
label.setAttribute('font-size','11');label.setAttribute('font-weight','600');
label.textContent=cs+' shift · '+now.toTimeString().slice(0,5);
svg.appendChild(label);
root.appendChild(svg);
// Right column — per-shift contract counts
var counts={'1st':0,'2nd':0,'3rd':0,'4th':0};
contracts.forEach(function(c){(c.shifts_needed||['1st']).forEach(function(s){if(counts[s]!==undefined)counts[s]++;});});
var right=document.createElement('div');right.style.cssText='display:grid;grid-template-columns:repeat(2,1fr);gap:10px';
['1st','2nd','3rd','4th'].forEach(function(s){
var cell=document.createElement('div');
cell.style.cssText='background:#0d1117;border:1px solid #171d27;border-radius:8px;padding:10px 12px;border-left:3px solid '+SHIFT_COLORS[s]+(cs===s?';box-shadow:0 0 0 1px '+SHIFT_COLORS[s]:'');
var head=document.createElement('div');head.style.cssText='font-size:10px;color:'+SHIFT_COLORS[s]+';font-weight:600;text-transform:uppercase;letter-spacing:1px;margin-bottom:4px';
head.textContent=s+' shift'+(cs===s?' · active':'');
var big=document.createElement('div');big.style.cssText='font-size:20px;font-weight:600;color:#e6edf3';big.textContent=counts[s];
var sub=document.createElement('div');sub.style.cssText='font-size:10px;color:#8b949e;margin-top:2px';
sub.textContent=(counts[s]===1?'contract needs':'contracts need')+' '+s+' coverage';
cell.appendChild(head);cell.appendChild(big);cell.appendChild(sub);
right.appendChild(cell);
});
root.appendChild(right);
}
function loadStaffingForecast(){
api('/intelligence/staffing_forecast',{}).then(function(r){
var el=document.getElementById('staffing-forecast');el.textContent='';
@@ -274,6 +457,8 @@ function loadLiveContracts(){
if(!r||!r.contracts||r.contracts.length===0){
el.textContent='No permits returned.';return;
}
// Feed shift clock before rendering cards so both land together.
loadShiftClock(r.contracts);
r.contracts.forEach(function(c){
var p=c.permit||{}, prop=c.proposed||{}, tl=c.timeline||{};
var urg=tl.urgency||'scheduled';
@@ -309,6 +494,101 @@ function loadLiveContracts(){
right.appendChild(rate);
}
hdr.appendChild(left);hdr.appendChild(right);card.appendChild(hdr);
// Architecture pill row — instant-search latency + shift coverage
// + pool-size proof that the index actually fired on this call.
// This is the "our substrate is better" surface J asked for.
var pillRow=document.createElement('div');
pillRow.style.cssText='display:flex;gap:6px;flex-wrap:wrap;margin-bottom:10px;font-size:10px';
function pill(text,color,title){
var p=document.createElement('span');
p.style.cssText='padding:3px 8px;border-radius:9px;background:#0d1117;border:1px solid '+color+'66;color:'+color+';font-weight:600;letter-spacing:0.3px';
if(title) p.title=title;
p.textContent=text;
return p;
}
if(c.search_latency_ms!==undefined){
var latColor=c.search_latency_ms<500?'#3fb950':c.search_latency_ms<2000?'#d29922':'#f85149';
pillRow.appendChild(pill('⚡ '+c.search_latency_ms+'ms', latColor,
'Time for /vectors/hybrid to rank '+(prop.pool_size||0).toLocaleString()+' SQL-matched workers against the 50K-chunk vector index.'));
}
if(prop.pool_size!==undefined){
pillRow.appendChild(pill(prop.pool_size.toLocaleString()+' pool · k=200 boost', '#58a6ff',
'Pool = workers matching SQL filter (role+state+city+avail>0.5). k=200 means playbook boost checks 200 candidates before narrowing to top-5.'));
}
if(c.shifts_needed&&c.shifts_needed.length){
var shiftColor={'1st':'#f9d171','2nd':'#f5894a','3rd':'#5f5fff','4th':'#2ea043'};
c.shifts_needed.forEach(function(sh){
pillRow.appendChild(pill(sh+' shift', shiftColor[sh]||'#8b949e',
'Inferred from permit description. See 24/7 shift clock above for live distribution.'));
});
}
if(pillRow.childNodes.length) card.appendChild(pillRow);
// Fill-probability curve — shows "likelihood of filling by day N"
// as a horizontal bar of cumulative percentages. Drill down that
// J asked for: "percentage likelihood of filling them on a certain time."
if(c.fill_probability&&c.fill_probability.curve){
var fp=c.fill_probability;
var fpRow=document.createElement('div');
fpRow.style.cssText='background:#0d1117;border:1px solid #171d27;border-radius:8px;padding:10px 12px;margin-bottom:10px';
var fpLabel=document.createElement('div');
fpLabel.style.cssText='display:flex;justify-content:space-between;font-size:10px;color:#8b949e;text-transform:uppercase;letter-spacing:1px;margin-bottom:6px';
var fpTitle=document.createElement('span');fpTitle.style.color='#e6edf3';fpTitle.textContent='Fill Probability';
var fpBase=document.createElement('span');fpBase.textContent='base '+fp.base_pct+'% · pool × urgency';
fpLabel.appendChild(fpTitle);fpLabel.appendChild(fpBase);
fpRow.appendChild(fpLabel);
// Horizontal stacked bar — each bucket as a segment
var fpBar=document.createElement('div');
fpBar.style.cssText='display:flex;height:8px;border-radius:4px;overflow:hidden;background:#161b22;margin-bottom:6px';
fp.curve.forEach(function(pt,idx){
var prev=idx===0?0:fp.curve[idx-1].cumulative_pct;
var delta=pt.cumulative_pct-prev;
if(delta<=0) return;
var seg=document.createElement('div');
var shade=pt.day<=7?'#3fb950':pt.day<=14?'#d29922':pt.day<=21?'#e8751a':'#f85149';
seg.style.cssText='flex:'+delta+' 0 0;background:'+shade;
seg.title='days '+(idx>0?fp.curve[idx-1].day:0)+'–'+pt.day+': +'+delta+'% cumulative';
fpBar.appendChild(seg);
});
fpRow.appendChild(fpBar);
// Day-marker row
var fpMarks=document.createElement('div');
fpMarks.style.cssText='display:flex;justify-content:space-between;font-size:9px;color:#545d68;font-family:monospace';
fp.curve.forEach(function(pt){
var m=document.createElement('span');
m.textContent='d'+pt.day+':'+pt.cumulative_pct+'%';
fpMarks.appendChild(m);
});
fpRow.appendChild(fpMarks);
card.appendChild(fpRow);
}
// Economics panel — "as though the contracts were accepted and filled"
if(c.economics){
var ec=c.economics;
var ecRow=document.createElement('div');
ecRow.style.cssText='background:#0d1117;border:1px solid #171d27;border-radius:8px;padding:10px 12px;margin-bottom:10px;display:grid;grid-template-columns:repeat(4,1fr);gap:8px';
function ecCell(label,big,sub,color){
var cell=document.createElement('div');
var l=document.createElement('div');l.style.cssText='font-size:9px;color:#545d68;text-transform:uppercase;letter-spacing:1px';l.textContent=label;
var b=document.createElement('div');b.style.cssText='font-size:13px;font-weight:600;color:'+(color||'#e6edf3');b.textContent=big;
var s=document.createElement('div');s.style.cssText='font-size:9px;color:#8b949e;margin-top:1px';s.textContent=sub;
cell.appendChild(l);cell.appendChild(b);cell.appendChild(s);
return cell;
}
ecRow.appendChild(ecCell('Est. Revenue','$'+ec.gross_revenue.toLocaleString(),
prop.count+' × '+ec.hours_per_week+'h × '+ec.weeks_assumed+'w','#e6edf3'));
var marginColor=ec.margin_pct>=25?'#3fb950':ec.margin_pct>=10?'#d29922':'#f85149';
ecRow.appendChild(ecCell('Est. Margin','$'+ec.gross_margin.toLocaleString(),
ec.margin_pct+'% · avg pay $'+ec.avg_pay_rate+'/hr',marginColor));
ecRow.appendChild(ecCell('Payout Window',ec.payout_window_days[0]+'–'+ec.payout_window_days[1]+'d',
'after fill_date · standard net-30 / net-45','#8b949e'));
var overColor=ec.over_bill_count>0?'#f85149':'#8b949e';
ecRow.appendChild(ecCell('Over-Bill Pool',ec.over_bill_count+'/'+(prop.candidates||[]).length,
ec.over_bill_count>0?'$'+ec.over_bill_pool_margin_at_risk.toLocaleString()+' at risk':'none flagged',overColor));
card.appendChild(ecRow);
}
// Description
if(p.description){
var desc=document.createElement('div');desc.style.cssText='color:#94a3b8;font-size:11px;margin-bottom:10px;line-height:1.5';