Week simulation + live dashboard + self-orientation + verification

Week simulation engine: 5 business days, 4-8 contracts per day,
3 rotating staffers with handoffs between days. Runs hybrid search
per contract via the gateway. 28 contracts, 108/108 filled (100%),
5 emergencies, 4 handoffs, 3.2s total.

Dashboard at :3700/ — dark theme, shows:
  - Contract cards sorted by priority with match status
  - Day navigation across the work week
  - Week summary stats (fill rate, emergencies, handoffs)
  - Live alerts (erratic/silent workers)
  - Playbook entries
  - Real-time service health + VRAM

Self-orientation (/context) + verification (/verify) endpoints so
any agent can understand the system and fact-check claims without
human intermediary.

Accessible on LAN at http://192.168.1.177:3700

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
root
2026-04-17 00:45:46 -05:00
co-authored by Claude Opus 4.6
parent a001a21902
commit 4a2bfce6e0
4 changed files with 404 additions and 1 deletions
+148 -1
View File
@@ -412,7 +412,26 @@ async function main() {
return new Response(await r.text(), { status: r.status, headers: { "Content-Type": "application/json" } });
}
return err("Unknown path. Available: /health /search /sql /match /worker/:id /ask /log /playbooks /profile/:id /vram /api/*", 404);
// Dashboard UI
if (url.pathname === "/" || url.pathname === "/dashboard") {
return new Response(Bun.file(import.meta.dir + "/dashboard.html"));
}
if (url.pathname === "/dashboard.css") {
return new Response(Bun.file(import.meta.dir + "/dashboard.css"), { headers: { "Content-Type": "text/css" } });
}
if (url.pathname === "/dashboard.ts" || url.pathname === "/dashboard.js") {
// Bun transpiles TS on the fly
const built = await Bun.build({ entrypoints: [import.meta.dir + "/dashboard.ts"], target: "browser" });
const js = await built.outputs[0].text();
return new Response(js, { headers: { "Content-Type": "application/javascript" } });
}
// Week simulation endpoint
if (url.pathname === "/simulation/run" && req.method === "POST") {
return ok(await runWeekSimulation());
}
return err("Unknown path. Available: / /health /search /sql /match /worker/:id /ask /log /playbooks /profile/:id /vram /context /verify /simulation/run", 404);
} catch (e: any) {
return err(e.message || String(e), 500);
}
@@ -423,3 +442,131 @@ async function main() {
}
main().catch(console.error);
// ─── Week simulation engine ───
const ROLES = ["Forklift Operator","Machine Operator","Assembler","Loader","Quality Tech","Welder","Sanitation Worker","Shipping Clerk","Production Worker","Maintenance Tech"];
const STATES = ["IL","IN","OH","MO","TN","KY","WI","MI"];
const CITIES: Record<string, string[]> = {
IL: ["Chicago","Springfield","Rockford","Peoria","Joliet"],
IN: ["Indianapolis","Fort Wayne","Evansville","South Bend"],
OH: ["Columbus","Cleveland","Cincinnati","Dayton"],
MO: ["St. Louis","Kansas City","Springfield"],
TN: ["Nashville","Memphis"], KY: ["Louisville","Lexington"],
WI: ["Milwaukee","Madison"], MI: ["Detroit","Grand Rapids"],
};
const CLIENTS = ["Midwest Logistics","Precision Mfg","Amazon DSP","CleanSpace","AutoParts Direct","Great Lakes Steel","Heartland Foods","Summit Packaging","Cardinal Health","TechFlow Assembly","River City Plastics","Prairie Wind Energy"];
const PRIORITIES = ["urgent","high","medium","medium","medium","low"];
const STARTS = ["5:00 AM","6:00 AM","6:30 AM","7:00 AM","7:30 AM","8:00 AM"];
const NOTES = [
"Warehouse expansion — need experienced workers",
"Peak season surge — client called last night",
"2nd shift, CNC preferred",
"Chemical plant — hazmat cert MANDATORY",
"ISO audit next week — need detail-oriented workers",
"Structural welding — experienced only",
"Regular fill — ongoing contract",
"Client doubled their order",
"Night shift coverage needed",
"Replacing 2 no-shows from yesterday",
];
function pick<T>(arr: T[]): T { return arr[Math.floor(Math.random() * arr.length)]; }
async function runWeekSimulation() {
const days = ["Monday","Tuesday","Wednesday","Thursday","Friday"];
const staffers = ["Sarah (Lead)","Mike (Senior)","Kim (Junior)"];
const results: any[] = [];
let totalFilled = 0, totalNeeded = 0, emergencies = 0, handoffs = 0, playbookEntries = 0;
for (let d = 0; d < days.length; d++) {
const dayLabel = days[d];
const numContracts = 4 + Math.floor(Math.random() * 5); // 4-8 per day
const contracts: any[] = [];
const staffer = staffers[d % staffers.length];
const handoffTo = staffers[(d + 1) % staffers.length];
for (let c = 0; c < numContracts; c++) {
const state = pick(STATES);
const city = pick(CITIES[state] || [state]);
const role = pick(ROLES);
const priority = pick(PRIORITIES) as string;
const headcount = priority === "urgent" ? 4 + Math.floor(Math.random() * 5) :
priority === "high" ? 3 + Math.floor(Math.random() * 3) :
2 + Math.floor(Math.random() * 3);
const minRel = priority === "urgent" ? 0.6 : priority === "high" ? 0.75 : 0.8;
const cid = `W${d+1}-${String(c+1).padStart(3,"0")}`;
if (priority === "urgent") emergencies++;
totalNeeded += headcount;
// Run hybrid search
let filled = 0;
let matches: any[] = [];
try {
const filt = `role = '${role}' AND state = '${state}' AND reliability >= ${minRel}`;
const r = await api("POST", "/vectors/hybrid", {
question: `Find ${role} workers for ${pick(NOTES)}`,
index_name: "ethereal_workers_v1",
sql_filter: filt,
filter_dataset: "ethereal_workers",
id_column: "worker_id",
top_k: headcount + 2,
generate: false,
});
matches = (r.sources || []).slice(0, headcount).map((s: any) => ({
doc_id: s.doc_id,
name: s.chunk_text?.split("—")[0]?.trim() || s.doc_id,
score: s.score,
}));
filled = matches.length;
} catch {}
totalFilled += Math.min(filled, headcount);
contracts.push({
id: cid, client: pick(CLIENTS), role, state, city,
headcount, filled: Math.min(filled, headcount), priority,
start: pick(STARTS), notes: pick(NOTES), matches,
staffer, handoff_to: d < 4 ? handoffTo : null,
});
}
// End of day: log playbook + prepare handoff
if (d < 4) {
handoffs++;
try {
await api("POST", "/api/ingest/file?name=successful_playbooks", null); // just trigger
} catch {}
}
playbookEntries++;
results.push({
label: dayLabel,
staffer,
handoff_to: d < 4 ? handoffTo : null,
contracts,
filled: contracts.reduce((s: number, c: any) => s + c.filled, 0),
needed: contracts.reduce((s: number, c: any) => s + c.headcount, 0),
});
}
const summary = {
total_contracts: results.reduce((s, d) => s + d.contracts.length, 0),
total_needed: totalNeeded,
total_filled: totalFilled,
fill_pct: Math.round(totalFilled / Math.max(totalNeeded, 1) * 100),
emergencies,
handoffs,
playbook_entries: playbookEntries,
};
// Log the week to playbooks
try {
const form = new FormData();
const csv = `timestamp,operation,approach,result,context\n"${new Date().toISOString()}","week_simulation: ${summary.total_contracts} contracts over 5 days","hybrid SQL+vector with multi-model routing","${summary.total_filled}/${summary.total_needed} filled (${summary.fill_pct}%)","${summary.emergencies} emergencies, ${summary.handoffs} handoffs"`;
form.append("file", new Blob([csv], { type: "text/csv" }), "playbook.csv");
await fetch(`${BASE}/ingest/file?name=successful_playbooks`, { method: "POST", body: form });
} catch {}
return { days: results, summary };
}