Live Contracts canvas: Chicago permits × workers_500k × playbook patterns
New devop.live/lakehouse section pairs live public Chicago building
permits with derived staffing contracts, ranked candidates from the
500K worker bench, and meta-index discovered patterns per role+geo.
Makes the Phase 19 boost + Path 2 pattern discovery visible on real
external data, without needing a paying client to demo.
Backend:
- New /intelligence/permit_contracts endpoint
- Fetches 6 recent Chicago permits > $250K from the Socrata API
- Derives proposed fill: 1 worker per $150K of permit value (capped 2-8)
- For each: /vectors/hybrid with use_playbook_memory=true,
playbook_memory_k=25, auto availability>0.5 filter
- For each: /vectors/playbook_memory/patterns with k=25 min_freq=0.3
- Returns permit + proposed contract + top 5 candidates with boosts
and citations + discovered pattern + pattern_matched count
Frontend:
- New "Live Contracts" section on search.html between today's sim
contracts and Market Intelligence
- Per-permit card: cost + work_type + address + proposed role/count
+ pool size + top 3 candidates (with endorsement chip when boost
fires) + memory-derived pattern ("MEMORY (N playbooks): recurring
certifications: OSHA-10 47%, Forklift... · archetype mostly: ...")
Real working demo even without paying clients: shows the system
operating on genuinely external data with our synthetic-data-derived
learning applied.
This commit is contained in:
@@ -1240,6 +1240,107 @@ tr:hover{background:#111827}
|
||||
}
|
||||
}
|
||||
|
||||
// Intelligence: Chicago permits → assumed staffing contracts with
|
||||
// Phase 19-ranked candidates and Path-2 discovered patterns. Each
|
||||
// card pairs a REAL permit (live from data.cityofchicago.org) with
|
||||
// a PROPOSED fill drawn from our 500K worker bench. Surfaces the
|
||||
// meta-index dimension directly: "what past similar fills had in
|
||||
// common" for this role + geo.
|
||||
if (url.pathname === "/intelligence/permit_contracts" && req.method === "POST") {
|
||||
const start = Date.now();
|
||||
try {
|
||||
const permitUrl = "https://data.cityofchicago.org/resource/ydr8-5enu.json";
|
||||
// Recent + substantial permits only — skip tiny ones that
|
||||
// don't imply real staffing demand.
|
||||
const permits: any[] = await fetch(
|
||||
`${permitUrl}?$select=permit_type,work_type,work_description,reported_cost,street_number,street_direction,street_name,community_area,issue_date&`
|
||||
+ `$where=reported_cost>250000 AND issue_date>'2025-06-01'`
|
||||
+ `&$order=issue_date DESC&$limit=6`
|
||||
).then(r => r.json()).catch(() => []);
|
||||
|
||||
const typeToRole: Record<string, string> = {
|
||||
"Electrical Work": "Electrician",
|
||||
"Masonry Work": "Production Worker",
|
||||
"Mechanical Work": "Maintenance Tech",
|
||||
"Reroofing": "Production Worker",
|
||||
"Plumbing Work": "Maintenance Tech",
|
||||
};
|
||||
|
||||
const contracts: any[] = [];
|
||||
for (const p of permits) {
|
||||
const cost = parseFloat(p.reported_cost || 0);
|
||||
// Industry heuristic — one worker per $150K of permit value,
|
||||
// capped at 8 per contract for staffing realism.
|
||||
const count = Math.min(Math.max(Math.round(cost / 150000), 2), 8);
|
||||
const role = typeToRole[p.work_type || ""] || "Production Worker";
|
||||
const city = "Chicago";
|
||||
const state = "IL";
|
||||
|
||||
// Phase 19 ranked candidates. Soft availability filter
|
||||
// auto-applied by /search — this mirrors the real recruiter
|
||||
// query path exactly.
|
||||
const searchRes = await api("POST", "/vectors/hybrid", {
|
||||
index_name: "workers_500k_v1",
|
||||
filter_dataset: "workers_500k",
|
||||
id_column: "worker_id",
|
||||
sql_filter: `role = '${role}' AND state = '${state}' AND city = '${city}' AND CAST(availability AS DOUBLE) > 0.5`,
|
||||
question: `${role} for ${p.work_type || "construction"} in ${city}`,
|
||||
top_k: 5, generate: false,
|
||||
use_playbook_memory: true, playbook_memory_k: 25,
|
||||
}).catch(() => ({ sources: [] as any[] }));
|
||||
|
||||
// Path 2 — discovered patterns for this role in this city.
|
||||
const patternRes = await api("POST", "/vectors/playbook_memory/patterns", {
|
||||
query: `${role} in ${city}, ${state}`,
|
||||
top_k_playbooks: 25,
|
||||
min_trait_frequency: 0.3,
|
||||
}).catch(() => ({} as any));
|
||||
|
||||
const sources = (searchRes.sources || []).slice(0, 5).map((s: any) => {
|
||||
const name = String(s.chunk_text || "").split("—")[0]?.trim() || s.doc_id;
|
||||
return {
|
||||
doc_id: s.doc_id,
|
||||
name,
|
||||
score: s.score,
|
||||
playbook_boost: s.playbook_boost || 0,
|
||||
playbook_citations: s.playbook_citations || [],
|
||||
};
|
||||
});
|
||||
|
||||
contracts.push({
|
||||
permit: {
|
||||
cost,
|
||||
work_type: p.work_type || "General construction",
|
||||
description: (p.work_description || "").substring(0, 140),
|
||||
address: `${p.street_number || ""} ${p.street_direction || ""} ${p.street_name || ""}`.trim(),
|
||||
community_area: p.community_area,
|
||||
issue_date: (p.issue_date || "").substring(0, 10),
|
||||
},
|
||||
proposed: {
|
||||
role,
|
||||
count,
|
||||
city, state,
|
||||
pool_size: searchRes.sql_matches,
|
||||
candidates: sources,
|
||||
},
|
||||
discovered_pattern: patternRes.discovered_pattern,
|
||||
pattern_matched: patternRes.matched_playbooks ?? 0,
|
||||
pattern_workers_examined: patternRes.total_workers_examined ?? 0,
|
||||
});
|
||||
}
|
||||
|
||||
return ok({
|
||||
generated_at: new Date().toISOString(),
|
||||
count: contracts.length,
|
||||
contracts,
|
||||
duration_ms: Date.now() - start,
|
||||
note: "Live Chicago permits paired with workers_500k-ranked candidates and playbook_memory discovered patterns. The permit is real public data; the proposed fill is derived per industry heuristic (~$150K → 1 worker).",
|
||||
});
|
||||
} catch (e: any) {
|
||||
return err(`permit_contracts: ${e.message}`, 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Intelligence: Log a search → selection as a learned pattern
|
||||
if (url.pathname === "/intelligence/learn" && req.method === "POST") {
|
||||
const b = await json();
|
||||
|
||||
Reference in New Issue
Block a user