Compare commits
24 Commits
main
...
scrum/auto
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcf4c9a8e7 | ||
|
|
3c6d2c5f74 | ||
|
|
8e1855e779 | ||
|
|
313eec3c6e | ||
|
|
51cc0a69cf | ||
|
|
528fded11b | ||
|
|
64700ea6da | ||
|
|
5225211e45 | ||
|
|
4f0b6fb9b3 | ||
|
|
8e781ac325 | ||
|
|
ee0450b7c3 | ||
|
|
0f9b4aa2fe | ||
|
|
e4eb0fa168 | ||
|
|
93081bed5c | ||
|
|
885a1acf19 | ||
|
|
97888e3775 | ||
|
|
9b8befaa94 | ||
|
|
2965b68a9d | ||
|
|
08c8debfff | ||
|
|
b02cf5b9e1 | ||
|
|
1ac8045924 | ||
|
|
52d2da2f44 | ||
|
|
d44ad3af1e | ||
|
|
89ac6a9b5b |
8
.gitignore
vendored
8
.gitignore
vendored
@ -4,3 +4,11 @@
|
||||
.env
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Headshot pool — binary face JPGs are fetched by scripts/staffing/fetch_face_pool.py
|
||||
# (synthetic StyleGAN, ~580MB for 1000 faces). Manifest + fetch script are tracked.
|
||||
data/headshots/face_*.jpg
|
||||
data/headshots/_thumbs/
|
||||
# ComfyUI on-demand generated portraits (per-worker unique). Cached on first
|
||||
# request; fully regeneratable via /headshots/generate/:key.
|
||||
data/headshots_gen/
|
||||
|
||||
239
STATE_OF_PLAY.md
Normal file
239
STATE_OF_PLAY.md
Normal file
@ -0,0 +1,239 @@
|
||||
# STATE OF PLAY — Lakehouse
|
||||
|
||||
**Last verified:** 2026-04-27 ~20:35 CDT
|
||||
**Verified by:** live probe, not memory.
|
||||
|
||||
> **Read this FIRST.** When the user says "we're working on lakehouse," they mean the working code captured below — NOT what `git log` framed as "the cutover" or what memory snapshots from 2 days ago suggest. If memory contradicts this file, this file wins. Update it when something is verified working — not when a phase finishes.
|
||||
|
||||
---
|
||||
|
||||
## VERIFIED WORKING RIGHT NOW
|
||||
|
||||
### The client demo (Staffing Co-Pilot)
|
||||
|
||||
**Public URL:** `https://devop.live/lakehouse/` — 200, "Staffing Co-Pilot" (159 KB SPA, leaflet maps, dark theme).
|
||||
**Local URL:** `http://localhost:3700/` — same page, served by `mcp-server/index.ts` (PID 1271, started 09:48 CDT today).
|
||||
|
||||
**The staffers console** (the one the client was thoroughly impressed with):
|
||||
- `https://devop.live/lakehouse/console` — 200, "Lakehouse — What Your Staffing System Would Do" (26 KB)
|
||||
- Pulls project index via `/api/catalog/datasets` (36 datasets) + playbook memory via `/api/vectors/playbook_memory/stats` (4,701 entries with embeddings, real ops like *"fill: Maintenance Tech x2 in Milwaukee, WI"*)
|
||||
|
||||
Client-visible flow that works end-to-end on the public URL:
|
||||
|
||||
| Endpoint | Sample output |
|
||||
|---|---|
|
||||
| `GET /api/catalog/datasets` | 36 datasets indexed: timesheets 1M, call_log 800K, workers_500k 500K, email_log 500K, workers_100k 100K, candidates 100K, placements 50K, job_orders 15K, successful_playbooks_live 2,077 |
|
||||
| `GET /api/vectors/playbook_memory/stats` | 4,701 fill operations with embeddings |
|
||||
| `GET /system/summary` | 36 datasets, 2.98M rows, 60 indexes, 500K workers loaded, 1K candidates |
|
||||
| `POST /intelligence/staffing_forecast` | 744 Production Workers needed in 30d, 11,281 bench (4,687 reliable), coverage 1,444%, risk=ok. Same for Electrician (need 32, bench 2,440) and Maintenance Tech (need 17, bench 5,004). |
|
||||
| `POST /intelligence/permit_contracts` | permit `3442956` $500K → 3 Production Workers, 886-candidate pool, 95% fill, $36K gross. 5 more Chicago permits with 8 workers each, same pool, 95% fill, $96K each. |
|
||||
| `POST /intelligence/market` | major Chicago permits ranked: $730M O'Hare, $615M 307 N Michigan, $580M casino, $445M Loop transit (real geo coords). |
|
||||
| `POST /intelligence/permit_entities` | architects + contractors from permit contacts (e.g. "KACPRZYNSKI, ANDY", "SLS ELECTRICAL SERVICE"). |
|
||||
| `POST /intelligence/activity` + `/intelligence/arch_signals` + `/intelligence/chat` | all 200 |
|
||||
|
||||
The demo tells the story: *"upcoming Chicago contracts → workers needed → coverage from the bench → architects/contractors involved → revenue and margin."* That's the "live data + anticipating contracts + complete workflow" pitch — working as of right now.
|
||||
|
||||
### Backend, verified live this session
|
||||
|
||||
| Surface | State |
|
||||
|---|---|
|
||||
| Gateway `:3100` | up, 4 providers configured, `/v1/health` 200 with 500K workers loaded |
|
||||
| MCP server `:3700` (Co-Pilot demo) | up, all `/intelligence/*` endpoints respond |
|
||||
| VCP UI `:3950` | started this session, `/data/*` 200, real numbers |
|
||||
| Observer `:3800` | ring full (2,000/2,000) — older events evicted, query Langfuse for 24h-ago state |
|
||||
| Sidecar `:3200` | up |
|
||||
| Langfuse `:3001` | recording, `gw:/log` + `v1.chat:openrouter` traces visible |
|
||||
| LLM Team UI `:5000` | up, only `extract` mode registered |
|
||||
| OpenCode fleet | **40 models reachable through one `sk-*` key** (verified live `GET https://opencode.ai/zen/v1/models`) |
|
||||
|
||||
OpenCode catalog (live):
|
||||
- Claude: opus-4-7, opus-4-6, opus-4-5, opus-4-1, sonnet-4-6, sonnet-4-5, sonnet-4, haiku-4-5
|
||||
- GPT-5: 5.5-pro, 5.5, 5.4-pro, 5.4, 5.4-mini, 5.4-nano, 5.3-codex-spark, 5.3-codex, 5.2, 5.2-codex, 5.1-codex-max, 5.1-codex, 5.1-codex-mini, 5.1, 5-codex, 5-nano, 5
|
||||
- Gemini: 3.1-pro, 3-flash
|
||||
- GLM: 5.1, 5
|
||||
- Minimax: m2.7, m2.5
|
||||
- Kimi: k2.6, k2.5
|
||||
- Qwen: 3.6-plus, 3.5-plus
|
||||
- Other: BIG-PKL (was a typo-prone name in the catalog, model id starts with "big-pkl-something")
|
||||
- Free tier: minimax-m2.5-free, hy3-preview-free, ling-2.6-flash-free, trinity-large-preview-free
|
||||
|
||||
### The substrate (frozen — do not re-architect)
|
||||
|
||||
- Distillation v1.0.0 at tag `e7636f2` — **145/145 bun tests pass, 22/22 acceptance, 16/16 audit-full**
|
||||
- Output: `data/_kb/distilled_{facts,procedures,config_hints}.jsonl` + `data/vectors/distilled_{factual,procedural,config_hint}_v20260423102847.parquet`
|
||||
- Auditor cross-lineage: Kimi K2.6 ↔ Haiku 4.5 alternation, Opus auto-promote on diffs >100k chars, **per-PR cap=3 with auto-reset on new head SHA**
|
||||
- Pathway memory: 88 traces, 11/11 successful replays (probation gate crossed)
|
||||
- Mode runner: 5 native modes; `codereview_isolation` is default; composed-corpus auto-downgrade verified Apr 26 (composed lost 5/5 vs isolation, p=0.031)
|
||||
|
||||
### Matrix indexer
|
||||
|
||||
30+ live corpora including:
|
||||
- 5 versions of `workers_500k_v1..v9` (50K embedded chunks each)
|
||||
- 11 batched 2K-row shards `w500k_b3..b17`
|
||||
- `chicago_permits_v1` (3,420), `resumes_100k_v2` (100K candidates), `ethereal_workers_v1` (10K)
|
||||
- `lakehouse_arch_v1` (2,119), `lakehouse_symbols_v1` (2,470), `lakehouse_answers_v1` (1,269), `scrum_findings_v1` (1,260)
|
||||
- `kb_team_runs_v1` (12,693) + `kb_team_runs_agent` (4,407) — LLM-team play history embedded
|
||||
- `distilled_factual_v20260423102507` (8) — distillation output
|
||||
|
||||
### Code health
|
||||
|
||||
- `cargo check --workspace` → **0 warnings, 0 errors**
|
||||
- `bun test auditor + tests/distillation` → **145/145 pass**
|
||||
- `ui/server.ts` + `auditor.ts` bundle clean
|
||||
|
||||
---
|
||||
|
||||
## DO NOT RELITIGATE
|
||||
|
||||
- **PR #11 is merged into `origin/main` as `ed57eda`** — do not "still need to merge PR #11."
|
||||
- **Distillation tag `distillation-v1.0.0` at `e7636f2` is FROZEN** — do not re-architect schemas, scorer rules, audit fixtures.
|
||||
- **Kimi forensic HOLD verdict (2026-04-27) was 2/8 false + 6/8 latent** — do not re-debate, see `reports/kimi/audit-last-week-full.md`.
|
||||
- **`candidates_safe` `vertical` column bug** — fixed at catalog metadata layer in commit `c3c9c21`. Do not "discover" it again.
|
||||
- **Decisions A/B/C/D from `synthetic-data-gap-report.md`** — all four scripts shipped today (`d56f08e`, `940737d`, `c3c9c21`). Do not "ask J for approval."
|
||||
- **`workers_500k.phone` type fixup** — already string. The fixup script is idempotent; running it is a no-op.
|
||||
- **`client_workerskjkk` typo dataset** — was breaking every SQL query (catalog had it registered, file didn't exist). Removed via `DELETE /catalog/datasets/by-name/client_workerskjkk` this session. Do not re-add. Adding a startup gate that errors on unrecognized parquet names is the long-term fix per now.md Step 2C.
|
||||
|
||||
---
|
||||
|
||||
## FIXES MADE THIS SESSION (2026-04-27 evening)
|
||||
|
||||
1. **`crates/gateway/src/v1/iterate.rs:93`** — `state` → `_state` (cleared the one cargo warning).
|
||||
2. **`lakehouse-ui.service` (Dioxus)** — disabled. Was failing 7,242 times against a missing `target/dx/ui/debug/web/public` build dir. `systemctl stop && disable`.
|
||||
3. **VCP UI on `:3950`** — started `bun run ui/server.ts` (PID 1162212, log `/tmp/lakehouse_ui.log`). `/data/*` endpoints now 200 with real data.
|
||||
4. **`client_workerskjkk` catalog entry** — `DELETE /catalog/datasets/by-name/client_workerskjkk` removed the dead manifest. **This was the actual root cause** of `/system/summary` reporting `workers_500k_rows: 0` and the demo showing zero bench. Every SQL query was failing schema inference on the missing file before reaching its target table. Fixed → `workers_500k_rows: 500000`, `candidates_rows: 1000`, demo coverage flipped from "critical 0%" to actual percentages on devop.live/lakehouse.
|
||||
|
||||
## FIXES MADE THIS SESSION (2026-04-28 early — face pool)
|
||||
|
||||
5. **Synthetic StyleGAN face pool — 1000 faces, gender+race+age tagged.** `scripts/staffing/fetch_face_pool.py` fetches from thispersondoesnotexist.com; `scripts/staffing/tag_face_pool.py --min-age 22` runs deepface and excludes minors. `data/headshots/manifest.jsonl` now has gender (494 men / 458 women), race (caucasian 662 · east_asian 128 · hispanic 86 · middle_eastern 59 · black 14 · south_asian 3), age, and 48 minor exclusions. Server pool = 952 servable faces.
|
||||
6. **`mcp-server/index.ts:1308` `/headshots/:key` route** — gender×race×age intersection bucketing with graceful fallback (gender-only → all). Same key always returns same face; different keys spread evenly.
|
||||
7. **`/headshots/_thumbs/` pre-resized 384×384 webp** (60× smaller: 587KB → ~11KB). Without this, 40-card grids overran Chrome's parallel-connection budget and ~75% of tiles never finished decoding. Generated via parallel ffmpeg (`xargs -P 8`); `.gitignore`d.
|
||||
8. **`mcp-server/search.html` + `console.html`** — dropped `img.loading='lazy'`. With 11KB thumbs, eager load is cheap (~500KB for 50 cards) and avoids the off-screen race that lazy decode produced.
|
||||
9. **ComfyUI on-demand uniqueness — `serve_imagegen.py:32`** added `seed` to `_cache_key()` (was caching by prompt only — 3 different worker seeds collapsed to 1 cached image). Verified: seed=839185194/195/196 → 3 distinct md5s.
|
||||
10. **`mcp-server/index.ts:1234` `/headshots/generate/:key`** — ComfyUI hot-path that derives a deterministic-per-worker seed via djb2-style hash; cold ~1.5s, cached ~1ms. Worker prompt format: `professional corporate headshot portrait of a {age}-year-old {race} {gender}, {role}, neutral expression, plain studio background, soft natural lighting, sharp focus, photorealistic, dslr`. Cache at `data/headshots_gen/` (gitignored, regeneratable).
|
||||
11. **Confidence-default name resolution** in `search.html` — `genderFor()` and `guessEthnicityFromFirstName()` lookup tables (FEMALE_NAMES, MALE_NAMES, NAMES_HISPANIC, NAMES_BLACK, NAMES_SOUTH_ASIAN, NAMES_EAST_ASIAN, NAMES_MIDDLE_EASTERN). Xavier → man+hispanic, Aisha → woman+black, etc. Every worker resolves to a face-pool bucket.
|
||||
|
||||
End-to-end verified: playwright run on `https://devop.live/lakehouse/?q=forklift+operators+IL` → 21/21 cards loaded, 0 broken, all 384×384 webp thumbs.
|
||||
|
||||
---
|
||||
|
||||
## OPEN — but not blocking the demo
|
||||
|
||||
| Item | What | When to act |
|
||||
|---|---|---|
|
||||
| `modes.toml` `staffing_inference.matrix_corpus` | still says `workers_500k_v8`. v9 in vector index is from Apr 17 (raw-sourced, not safe-view). The new `build_workers_v9.sh` rebuilds from `workers_safe`. | Run when you have 30+ min for the rebuild. |
|
||||
| Open PRs #6, #7, #10 | sitting since Apr 22-24, auditor verdicts on disk at `data/_auditor/kimi_verdicts/{6,7,10}-*.json` | Read verdicts, decide reconcile/close. |
|
||||
| `test/enrich-prd-pipeline` branch | 35 unmerged commits, includes more-evolved auditor/inference.ts (666 vs main's 580 lines), curation+fact-extractor wiring | Reconcile or formally archive — see `memory/project_unmerged_architecture_work.md`. |
|
||||
| `federation-hnsw-trials` stash | Lance + S3/MinIO prototype, `aws-config` crate added, 708 insertions | Phase B from EXECUTION_PLAN.md — revisit when Parquet vector ceiling actually hurts. |
|
||||
| `candidates` manifest drift | manifest 100K vs SQL 1K. Cosmetic. | Run a metadata resync if it matters. |
|
||||
|
||||
---
|
||||
|
||||
## RUNTIME CHEATSHEET
|
||||
|
||||
```bash
|
||||
# Verify the demo (public + local both work)
|
||||
curl -sS https://devop.live/lakehouse/ # Co-Pilot HTML
|
||||
curl -sS https://devop.live/lakehouse/console # staffers console
|
||||
curl -sS -X POST https://devop.live/lakehouse/intelligence/staffing_forecast \
|
||||
-d '{}' -H 'content-type: application/json' \
|
||||
| jq '.forecast[] | {role, demand_workers, bench_total, coverage_pct, risk}'
|
||||
|
||||
# Restart sequence (after Rust changes)
|
||||
sudo systemctl restart lakehouse.service # gateway :3100
|
||||
sudo systemctl restart lakehouse-auditor # auditor daemon
|
||||
sudo systemctl restart lakehouse-observer # observer :3800
|
||||
# UI bun on :3950 is NOT systemd-managed (lakehouse-ui.service is disabled).
|
||||
# Restart manually: kill <pid>; nohup bun run ui/server.ts > /tmp/lakehouse_ui.log 2>&1 &
|
||||
|
||||
# Health checks
|
||||
curl -sS http://localhost:3100/v1/health | jq # workers_count, providers
|
||||
curl -sS http://localhost:3100/vectors/pathway/stats | jq
|
||||
curl -sS http://localhost:3100/v1/usage | jq # since-restart cost
|
||||
curl -sS http://localhost:3700/system/summary | jq # dataset counts
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## VISION — what we're actually building (not what's done)
|
||||
|
||||
J's framing for the legacy staffing company:
|
||||
|
||||
- Pull live data, anticipate contracts based on Chicago permits → real architect/contractor associations, headcount, time period, money, scope.
|
||||
- Hybrid + memory index → search large corpora cheaply.
|
||||
- Email comes in → verify against contract; SMS comes in → alert when index changes.
|
||||
- Real-time.
|
||||
- Invent metrics nobody else has using the hybrid index.
|
||||
- Next stage: workers download an app → geolocation clock-in → automatic responsiveness measurement, no user effort, with incentives for using it.
|
||||
- Find people getting certificates (passive cert tracking).
|
||||
- Pull union data → bring contracts that work for **employees**, not just employers.
|
||||
- All metrics visible, nothing hidden, value-aligned with what each side actually needs.
|
||||
|
||||
If a future session is shaving away from this vision toward "fix the cutover" or "land Phase X," the vision wins. Phases are scaffolding for the vision, not the goal.
|
||||
|
||||
---
|
||||
|
||||
## CURRENT PLAN — fix the demo for the legacy staffing client
|
||||
|
||||
Built from playwright audit of the live demo (2026-04-27 evening). Each item ends in something the client can SEE, not internal cleanups.
|
||||
|
||||
**Demo state is anchored by git tag `demo-2026-04-27`** (commit `ed57eda`, the merge of PR #11). To restore code state: `git checkout demo-2026-04-27`. To restore runtime state: `DELETE /catalog/datasets/by-name/client_workerskjkk` (catalog hot-fix is not in git).
|
||||
|
||||
### P1 — Search box that actually filters (highest visible impact)
|
||||
|
||||
**Problem:** typing in `#sq` and pressing Enter fires `POST /intelligence/chat` with body `{"message":"<query>"}`. The state (`#sst`) and role (`#srl`) selects are ignored — never sent in the body. So every search returns a generic chat completion, never a SQL+vector hybrid filter against `workers_500k`. That is the "cached/generic response" the client sees.
|
||||
|
||||
**Fix:** in `mcp-server/search.html`, change the search-submit handler to call the real worker search endpoint with `{query, state, role, top_k}`. The MCP `search_workers` tool surface already exists; route the form there. Render returned worker rows in the existing card grid.
|
||||
|
||||
**Done when:** typing "forklift" + state IL + role "Forklift Operator" returns ≤ top_k IL Forklift Operators, and changing state to WI returns different workers.
|
||||
|
||||
### P2 — Contractor-name click → `/contractor` profile page
|
||||
|
||||
**Problem:** clicking a contractor name in any rendered card stays on `/lakehouse/`. URL doesn't change.
|
||||
|
||||
**Fix:** wrap contractor names in `<a href="/contractor?name=<encoded>">`. The page `mcp-server/contractor.html` (14.8 KB, "Contractor Profile · Staffing Co-Pilot") already exists at `/contractor` and the data endpoint `/intelligence/contractor_profile` already returns rich data.
|
||||
|
||||
**Then check contractor.html actually shows:** full history of every record the database has on that contractor + heat map of locations underneath + relevant info (per J 2026-04-27). If the page is incomplete, finish it. Otherwise just wire the link.
|
||||
|
||||
**Done when:** clicking "KACPRZYNSKI, ANDY" opens a profile with: every Chicago permit they're contact_1 or contact_2 on, a leaflet map with markers for each address, and any matched workers from prior placements at their sites.
|
||||
|
||||
### P3 — Substrate signal at the bottom shows the right numbers
|
||||
|
||||
**Problem:** J reports the bottom panel says "playbook memory empty, 80 traces 0 replies." Reality from the live endpoints: `/api/vectors/playbook_memory/stats` = 4,701 entries with embeddings; `/vectors/pathway/stats` = 88 traces, 11/11 replays.
|
||||
|
||||
**Fix:** find the renderer in search.html that builds the substrate signal panel; verify it's hitting the right endpoints and reading the right keys; fix shape mismatches.
|
||||
|
||||
**Done when:** bottom panel shows real numbers (4,701 playbooks, 88 traces, 11/11 replays) and references at least one specific recent operation from the playbook stats sample.
|
||||
|
||||
### P4 — Top nav reflects today's architecture
|
||||
|
||||
**Problem:** Walkthrough/Architecture/Spec/Onboard/Alerts/Workspaces tabs all return 200 but content is from old architecture. Doesn't mention: gateway scratchpad, memory indexer, ranker, mode runner, OpenCode 40-model fleet, distillation substrate, auditor cross-lineage.
|
||||
|
||||
**Fix:** rewrite `mcp-server/proof.html` (or add a single new page "What's running" that replaces Architecture+Spec) to describe what's actually shipped as of `demo-2026-04-27`. Keep one architecture page, drop redundancy. Either complete or hide Onboard/Alerts/Workspaces — J's call which.
|
||||
|
||||
**Done when:** the architecture page tells a non-technical reader, in 2 minutes, what each piece does in coordinator-relatable terms ("intern that read every email", not "3-stage adversarial inference pipeline").
|
||||
|
||||
### P5 — Caching for the project-index build_signal (J flagged unfinished)
|
||||
|
||||
**Problem:** "we never finished our caching for project index build signal it's not pulling new information." Need to find what `build_signal` refers to. Likely a scrum/auditor signal that should rebuild the `lakehouse_arch_v1` corpus on commit but isn't wired to.
|
||||
|
||||
**Fix:** identify the build-signal pipeline (likely in `auditor/` or `crates/vectord/`), wire its emit to a corpus rebuild, verify by making a test commit and watching the new chunk appear in `/vectors/indexes` for `lakehouse_arch_v1`.
|
||||
|
||||
**Done when:** committing a new file to `crates/` causes `lakehouse_arch_v1` chunk_count to increase within N minutes.
|
||||
|
||||
### P0 — Anchor the demo state (DONE)
|
||||
|
||||
Tagged `ed57eda` as `demo-2026-04-27`. Future sessions: `git checkout demo-2026-04-27` to land in this exact code state.
|
||||
|
||||
---
|
||||
|
||||
## EXECUTION ORDER
|
||||
|
||||
1. **P1 first** — biggest visible bug, ~30-60 min
|
||||
2. **P2 next** — contractor click is the second-biggest "doesn't work" the client sees, ~20 min if profile is mostly done
|
||||
3. **P3** — small fix, big "looks alive" win
|
||||
4. **P4** — biggest scope; might split across sessions
|
||||
5. **P5** — feature work, only after the visible bugs are fixed
|
||||
|
||||
Each item commits independently with the format `demo: P<n> — <one-line>` so the commit log doubles as a progress journal. After each merge to main, re-tag `demo-latest` to point at the new HEAD.
|
||||
|
||||
Stop here and let J pick which item to start with. Do not silently extend scope.
|
||||
@ -90,7 +90,7 @@ pub struct IterateFailure {
|
||||
}
|
||||
|
||||
pub async fn iterate(
|
||||
State(state): State<super::V1State>,
|
||||
State(_state): State<super::V1State>,
|
||||
Json(req): Json<IterateRequest>,
|
||||
) -> impl IntoResponse {
|
||||
let max_iter = req.max_iterations.unwrap_or(DEFAULT_MAX_ITERATIONS).max(1);
|
||||
|
||||
@ -11,15 +11,51 @@
|
||||
}
|
||||
],
|
||||
"created_at": "2026-04-20T11:07:57.308050648Z",
|
||||
"updated_at": "2026-04-22T03:28:28.343843823Z",
|
||||
"updated_at": "2026-04-28T01:28:31.280305207Z",
|
||||
"description": "",
|
||||
"owner": "",
|
||||
"sensitivity": null,
|
||||
"columns": [],
|
||||
"columns": [
|
||||
{
|
||||
"name": "timestamp",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
},
|
||||
{
|
||||
"name": "operation",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
},
|
||||
{
|
||||
"name": "approach",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
},
|
||||
{
|
||||
"name": "result",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
},
|
||||
{
|
||||
"name": "context",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
}
|
||||
],
|
||||
"lineage": null,
|
||||
"freshness": null,
|
||||
"tags": [],
|
||||
"row_count": null,
|
||||
"row_count": 2077,
|
||||
"last_embedded_at": null,
|
||||
"embedding_stale_since": null,
|
||||
"embedding_refresh_policy": null
|
||||
|
||||
@ -1,117 +0,0 @@
|
||||
{
|
||||
"id": "564b00ae-cbf3-4efd-aa55-84cdb6d2b0b7",
|
||||
"name": "client_workerskjkk",
|
||||
"schema_fingerprint": "cdfe85348885ddf329e5e6e9bf0e2c75c92d1a86fdb0fd3875ed46e3f93c4d82",
|
||||
"objects": [
|
||||
{
|
||||
"bucket": "primary",
|
||||
"key": "datasets/client_workerskjkk.parquet",
|
||||
"size_bytes": 32201,
|
||||
"created_at": "2026-04-21T00:49:04.623625149Z"
|
||||
}
|
||||
],
|
||||
"created_at": "2026-04-21T00:49:04.623626738Z",
|
||||
"updated_at": "2026-04-21T00:49:04.623901788Z",
|
||||
"description": "",
|
||||
"owner": "",
|
||||
"sensitivity": "pii",
|
||||
"columns": [
|
||||
{
|
||||
"name": "worker_id",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": "pii",
|
||||
"description": "",
|
||||
"is_pii": true
|
||||
},
|
||||
{
|
||||
"name": "role",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
},
|
||||
{
|
||||
"name": "city",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
},
|
||||
{
|
||||
"name": "state",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
},
|
||||
{
|
||||
"name": "email",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": "pii",
|
||||
"description": "",
|
||||
"is_pii": true
|
||||
},
|
||||
{
|
||||
"name": "phone",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": "pii",
|
||||
"description": "",
|
||||
"is_pii": true
|
||||
},
|
||||
{
|
||||
"name": "skills",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
},
|
||||
{
|
||||
"name": "certifications",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
},
|
||||
{
|
||||
"name": "availability",
|
||||
"data_type": "Float64",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
},
|
||||
{
|
||||
"name": "reliability",
|
||||
"data_type": "Float64",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
},
|
||||
{
|
||||
"name": "archetype",
|
||||
"data_type": "Utf8",
|
||||
"sensitivity": null,
|
||||
"description": "",
|
||||
"is_pii": false
|
||||
}
|
||||
],
|
||||
"lineage": {
|
||||
"source_system": "csv",
|
||||
"source_file": "staffing_roster_sample.csv",
|
||||
"ingest_job": "ingest-1776732544623",
|
||||
"ingest_timestamp": "2026-04-21T00:49:04.623625149Z",
|
||||
"parent_datasets": []
|
||||
},
|
||||
"freshness": null,
|
||||
"tags": [],
|
||||
"row_count": 180,
|
||||
"last_embedded_at": null,
|
||||
"embedding_stale_since": null,
|
||||
"embedding_refresh_policy": null
|
||||
}
|
||||
1000
data/headshots/manifest.jsonl
Normal file
1000
data/headshots/manifest.jsonl
Normal file
File diff suppressed because it is too large
Load Diff
@ -51,9 +51,28 @@ details .body{padding-top:10px;font-size:12px;color:#8b949e}
|
||||
.accent-b{border-left:3px solid #1f6feb}
|
||||
.accent-a{border-left:3px solid #bc8cff}
|
||||
.accent-w{border-left:3px solid #d29922}
|
||||
.accent-g{border-left:3px solid #3fb950}
|
||||
.accent-r{border-left:3px solid #f85149}
|
||||
|
||||
.worker{display:flex;align-items:center;gap:10px;padding:8px 10px;background:#161b22;border-radius:6px;margin-bottom:4px;font-size:12px}
|
||||
.worker .av{width:28px;height:28px;border-radius:6px;background:#1a2744;display:flex;align-items:center;justify-content:center;font-weight:600;color:#e6edf3;font-size:10px;flex-shrink:0}
|
||||
.worker{display:flex;align-items:center;gap:10px;padding:8px 10px;background:#161b22;border-radius:6px;margin-bottom:4px;font-size:12px;border-left:3px solid #30363d}
|
||||
.worker .av{width:32px;height:32px;border-radius:50%;background:#0d1117;border:1px solid #21262d;display:flex;align-items:center;justify-content:center;font-weight:600;color:#c9d1d9;font-size:11px;flex-shrink:0;letter-spacing:0.5px;overflow:hidden;position:relative}
|
||||
.worker .av img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;display:block;
|
||||
/* Softening — mirror of search.html. Pulls saturation + contrast off
|
||||
the SDXL Turbo over-render so faces feel less "AI-generated".
|
||||
If you tweak one, tweak the other. */
|
||||
filter: saturate(0.86) contrast(0.93) brightness(1.02) blur(0.3px);
|
||||
}
|
||||
.worker[data-role-band="warehouse"]{border-left-color:#58a6ff}
|
||||
.worker[data-role-band="production"]{border-left-color:#d29922}
|
||||
.worker[data-role-band="trades"]{border-left-color:#bc8cff}
|
||||
.worker[data-role-band="driver"]{border-left-color:#3fb950}
|
||||
.worker[data-role-band="lead"]{border-left-color:#f0883e}
|
||||
.role-pill{display:inline-block;font-size:9px;padding:1px 7px;border-radius:3px;background:#0d1117;color:#8b949e;margin-right:6px;font-weight:600;letter-spacing:0.4px;text-transform:uppercase;border-left:2px solid #30363d;vertical-align:1px}
|
||||
.role-pill[data-rb="warehouse"]{border-left-color:#58a6ff;color:#79c0ff}
|
||||
.role-pill[data-rb="production"]{border-left-color:#d29922;color:#e3b341}
|
||||
.role-pill[data-rb="trades"]{border-left-color:#bc8cff;color:#d2a8ff}
|
||||
.role-pill[data-rb="driver"]{border-left-color:#3fb950;color:#56d364}
|
||||
.role-pill[data-rb="lead"]{border-left-color:#f0883e;color:#ffa657}
|
||||
.worker .info{flex:1;min-width:0}
|
||||
.worker .nm{color:#e6edf3;font-weight:500}
|
||||
.worker .why{color:#545d68;font-size:11px;margin-top:1px}
|
||||
@ -95,6 +114,7 @@ details .body{padding-top:10px;font-size:12px;color:#8b949e}
|
||||
<nav>
|
||||
<a href=".">Dashboard</a>
|
||||
<a href="console" class="active">Walkthrough</a>
|
||||
<a href="profiler">Profiler</a>
|
||||
<a href="proof">Architecture</a>
|
||||
<a href="spec">Spec</a>
|
||||
<a href="onboard">Onboard</a>
|
||||
@ -147,11 +167,40 @@ details .body{padding-top:10px;font-size:12px;color:#8b949e}
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 6</div>
|
||||
<h2>Try it yourself</h2>
|
||||
<div class="lede">Type any staffing question. The system picks the right search path (smart-parse, semantic discovery, analytics), shows what it understood, and returns ranked results with memory signal.</div>
|
||||
<h2>Three coordinators, three views of the same corpus</h2>
|
||||
<div class="lede">Maria runs Chicago, Devon runs Indianapolis, Aisha runs Milwaukee. Same database, same playbooks — but the search results, the recurring-skill patterns, and the playbook context all reshape to whoever is acting. This is the per-staffer hot-swap index: the relevance gradient is unique to each person, and gets sharper the more they use it.</div>
|
||||
<div id="ch6-staffers"><div class="loading">Loading staffer roster…</div></div>
|
||||
</div>
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 7</div>
|
||||
<h2>The hidden signal — public issuers in your contractor graph</h2>
|
||||
<div class="lede">Every contractor in this corpus is also a forward indicator on the public equities they touch. Permit filings precede construction starts by ~45 days, staffing windows by ~30, revenue recognition by months. The associated-ticker network surfaces this signal <em>before</em> any 10-Q. Below: the top issuers attributable to the contractor activity in this view, with live prices.</div>
|
||||
<div id="ch7-signal"><div class="loading">Computing the Building Activity Index…</div></div>
|
||||
</div>
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 8</div>
|
||||
<h2>When something breaks — triage in one shot</h2>
|
||||
<div class="lede">A coordinator gets a text: "Marcus running late." Watch what the system does in 250 milliseconds: pulls Marcus's record, scores his attendance pattern, finds five same-role same-geo backfills sorted by responsiveness, and pre-writes the SMS to send to the client. This is the moment the AI becomes worth its weight.</div>
|
||||
<div id="ch8-triage"><div class="loading">Running the triage scenario…</div></div>
|
||||
</div>
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 9</div>
|
||||
<h2>Try it yourself — every input below hits a different route</h2>
|
||||
<div class="lede">Type any staffing question. The router picks the right path: smart-parse (zip code, headcount, role, state), semantic discovery, name lookup, late-worker triage, "what came in last night" temporal queries. Whatever you type, the system tells you what it understood and how it routed.</div>
|
||||
<div class="try-box">
|
||||
<input type="text" id="try-q" placeholder="e.g. reliable forklift operators in Chicago with OSHA certs" onkeydown="if(event.key==='Enter')runTry()">
|
||||
<input type="text" id="try-q" placeholder="e.g. 8 production workers near 60607 by next Friday" onkeydown="if(event.key==='Enter')runTry()">
|
||||
<button id="try-btn" onclick="runTry()">Ask</button>
|
||||
<div style="margin-top:10px;font-size:11px;color:#545d68;line-height:1.7">
|
||||
Try one of these to see different routes fire:<br>
|
||||
<a href="#" onclick="document.getElementById('try-q').value='8 production workers near 60607';runTry();return false">8 production workers near 60607</a> ·
|
||||
<a href="#" onclick="document.getElementById('try-q').value='Marcus running late site 4422';runTry();return false">Marcus running late site 4422</a> ·
|
||||
<a href="#" onclick="document.getElementById('try-q').value='Marcus';runTry();return false">Marcus</a> ·
|
||||
<a href="#" onclick="document.getElementById('try-q').value='what came in last night';runTry();return false">what came in last night</a> ·
|
||||
<a href="#" onclick="document.getElementById('try-q').value='reliable forklift operators with OSHA certs';runTry();return false">reliable forklift operators with OSHA certs</a>
|
||||
</div>
|
||||
<div id="try-out" style="margin-top:16px"></div>
|
||||
</div>
|
||||
</div>
|
||||
@ -167,6 +216,132 @@ var A=location.origin+P;
|
||||
// DOM helpers — all dynamic content goes through these. No innerHTML
|
||||
// anywhere in the script; every API-derived string passes through
|
||||
// textContent so no injection path regardless of upstream data.
|
||||
// Role classification — mirrors search.html, no emojis. Maps role
|
||||
// strings to a band+label used by the worker-card border + role pill.
|
||||
var ROLE_BANDS = [
|
||||
{ match: /forklift|warehouse|associate|material\s*handler|loader|loading|packag|shipping|logistics|inventory|sanitation|janit/i, band: 'warehouse', label: 'Warehouse' },
|
||||
{ match: /production|assembl/i, band: 'production', label: 'Production' },
|
||||
{ match: /welder|weld|electric|maint(enance)?\s*tech|cnc|machine\s*op|hvac|plumb|carpenter|mason/i, band: 'trades', label: 'Skilled Trade' },
|
||||
{ match: /driver|truck|haul|cdl/i, band: 'driver', label: 'Driver' },
|
||||
{ match: /line\s*lead|supervisor|foreman|coordinator/i, band: 'lead', label: 'Lead' },
|
||||
{ match: /quality/i, band: 'production', label: 'Quality' },
|
||||
];
|
||||
function roleBand(role){
|
||||
if(!role) return { band: 'warehouse', label: '' };
|
||||
for (var i = 0; i < ROLE_BANDS.length; i++) {
|
||||
if (ROLE_BANDS[i].match.test(role)) return ROLE_BANDS[i];
|
||||
}
|
||||
return { band: 'warehouse', label: role.split(' ')[0].toUpperCase().slice(0, 12) };
|
||||
}
|
||||
|
||||
// Build a sober worker card: monogram avatar + colored role band on
|
||||
// the left edge + uppercase role pill in the detail line. Used by
|
||||
// every chapter that renders worker rows. `name` and `role` drive the
|
||||
// classification; `detail` is the full text after the pill.
|
||||
// Quick first-name → gender hint for face-pool selection. Same lookup
|
||||
// idea as the dashboard; if the name is unknown, the server falls back
|
||||
// to the full pool. Trimmed table — covers the most common names that
|
||||
// appear in the synthetic worker data.
|
||||
var FEMALE_NAMES = new Set(['Mary','Patricia','Jennifer','Linda','Elizabeth','Barbara','Susan','Jessica','Sarah','Karen','Lisa','Nancy','Betty','Sandra','Margaret','Ashley','Kimberly','Emily','Donna','Michelle','Carol','Amanda','Melissa','Deborah','Stephanie','Dorothy','Rebecca','Sharon','Laura','Cynthia','Amy','Kathleen','Angela','Shirley','Brenda','Emma','Anna','Pamela','Nicole','Samantha','Katherine','Christine','Helen','Debra','Rachel','Carolyn','Janet','Maria','Catherine','Heather','Diane','Olivia','Julie','Joyce','Victoria','Ruth','Virginia','Lauren','Kelly','Christina','Joan','Evelyn','Judith','Andrea','Hannah','Megan','Cheryl','Jacqueline','Martha','Madison','Teresa','Gloria','Sara','Janice','Ann','Kathryn','Abigail','Sophia','Frances','Jean','Alice','Judy','Isabella','Julia','Grace','Amber','Denise','Danielle','Marilyn','Beverly','Charlotte','Natalie','Theresa','Diana','Brittany','Kayla','Alexis','Lori','Marie','Carmen','Aisha','Rosa','Mia','Audrey','Erin','Tina','Vanessa','Tara','Wendy','Tanya','Maya','Crystal','Yvonne','Kara','Shannon','Brianna','Faith','Caroline','Carla','Tracey','Tracy','Rita','Dawn','Tiffany','Stacy','Stacey','Gina','Bonnie','Tammy','Joanne','Jamie','Tonya','Alyssa','Ariana','Elena','Ellie','Erica','Erika','Felicia','Holly','Jenna','Jenny','Krista','Kristen','Kristin','Krystal','Lana','Leah','Lucy','Mallory','Melinda','Meredith','Misty','Monica','Naomi','Paige','Paula','Renee','Rhonda','Robin','Roxanne','Selena','Sierra','Skylar','Sonia','Stella','Tamara','Veronica','Vivian','Whitney','Yolanda','Zoe']);
|
||||
var MALE_NAMES = new Set(['James','Robert','John','Michael','David','William','Richard','Joseph','Thomas','Charles','Christopher','Daniel','Matthew','Anthony','Mark','Donald','Steven','Paul','Andrew','Joshua','Kenneth','Kevin','Brian','George','Edward','Ronald','Timothy','Jason','Jeffrey','Ryan','Jacob','Gary','Nicholas','Eric','Jonathan','Stephen','Larry','Justin','Scott','Brandon','Benjamin','Samuel','Gregory','Frank','Alexander','Raymond','Patrick','Jack','Dennis','Jerry','Tyler','Aaron','Jose','Adam','Henry','Nathan','Douglas','Zachary','Peter','Kyle','Walter','Ethan','Jeremy','Harold','Keith','Christian','Roger','Noah','Gerald','Carl','Terry','Sean','Austin','Arthur','Lawrence','Jesse','Dylan','Bryan','Joe','Jordan','Billy','Bruce','Albert','Willie','Gabriel','Logan','Alan','Juan','Wayne','Roy','Ralph','Randy','Eugene','Vincent','Russell','Elijah','Louis','Bobby','Philip','Johnny','Marcus','Antonio','Carlos','Diego','Hector','Jorge','Julio','Manuel','Miguel','Pedro','Raul','Ricardo','Roberto','Sergio','Victor','Jamal','Xavier','DeShawn','Dwayne','Jermaine','Malik','Tyrone','Devon','Andre','Brent','Calvin','Casey','Cody','Cole','Cory','Dale','Damon','Darius','Darrell','Dean','Derek','Drew','Earl','Eddie','Floyd','Glenn','Greg','Howard','Ivan','Jared','Jay','Jeff','Joel','Lance','Lee','Leonard','Lloyd','Mario','Martin','Mason','Maurice','Max','Mitchell','Morgan','Nick','Norman','Oliver','Owen','Pete','Quincy','Rafael','Reggie','Rex','Ricky','Russ','Shane','Shaun','Stanley','Steve','Theodore','Todd','Travis','Trevor','Troy','Wade','Warren','Wesley']);
|
||||
function guessGenderFromFirstName(n){
|
||||
if(!n) return null;
|
||||
var clean=n.replace(/[^A-Za-z]/g,'');
|
||||
if(!clean) return null;
|
||||
var c=clean[0].toUpperCase()+clean.slice(1).toLowerCase();
|
||||
if(FEMALE_NAMES.has(c)) return 'woman';
|
||||
if(MALE_NAMES.has(c)) return 'man';
|
||||
return null;
|
||||
}
|
||||
function genderFor(name){
|
||||
var g = guessGenderFromFirstName(name);
|
||||
if(g) return g;
|
||||
if(!name) return 'man';
|
||||
var s=String(name); var h=0;
|
||||
for(var i=0;i<s.length;i++) h=(h*31+s.charCodeAt(i))|0;
|
||||
return (Math.abs(h)&1)?'man':'woman';
|
||||
}
|
||||
// Confident first-name → ethnicity. Synthetic data — we own the call.
|
||||
var NAMES_SOUTH_ASIAN_C=new Set(['Raj','Anil','Rohan','Vikram','Arjun','Sanjay','Ravi','Krishna','Pradeep','Sunil','Amit','Deepak','Ashok','Manoj','Rahul','Vijay','Suresh','Naveen','Anand','Nikhil','Aditya','Karan','Rajesh','Priya','Anjali','Neha','Kavya','Pooja','Divya','Meera','Lakshmi','Rani','Asha','Saanvi','Aanya','Aaradhya','Shreya','Riya','Tanvi','Ishita','Aarav','Ishaan','Shivani']);
|
||||
var NAMES_EAST_ASIAN_C=new Set(['Wei','Mei','Yi','Jin','Chen','Lin','Liu','Wang','Zhang','Yang','Wu','Zhao','Sun','Hiroshi','Yuki','Akira','Kenji','Sakura','Aiko','Haruto','Sora','Hyun','Eun','Yoon','Kai','Long','Hong','Xiu','Lan','Hua','Hao','Tao','Bao','Cheng','Feng','Jian','Dong','Bin','Min','Lei','Hui','Yu','Xin','Ying','Zhen','Yuan','Yan']);
|
||||
var NAMES_HISPANIC_C=new Set(['Carmen','Carlos','Maria','Diego','Hector','Jorge','Julio','Manuel','Miguel','Pedro','Raul','Ricardo','Roberto','Sergio','Antonio','Esperanza','Luz','Sofia','Lucia','Isabella','Camila','Valentina','Mariana','Elena','Rosa','Catalina','Esteban','Fernando','Eduardo','Javier','Alejandro','Andres','Mateo','Santiago','Sebastian','Emilio','Tomas','Cristina','Daniela','Gabriela','Ximena','Adriana','Beatriz','Pilar','Mercedes','Xavier','Marisol','Guadalupe','Lupita','Inez','Itzel','Yesenia','Joaquin','Ignacio','Rafael','Salvador','Cesar','Arturo','Armando','Hugo','Marco','Alejandra','Felipe','Gerardo','Jaime','Leonardo','Luis','Pablo','Ramon']);
|
||||
var NAMES_BLACK_C=new Set(['DeShawn','Jamal','Aisha','Latoya','Tyrone','Malik','Imani','Keisha','Tariq','Lakisha','Kenya','Tamika','Andre','Marcus','Demetrius','Jermaine','Reggie','Tyrese','Darius','Trevon','Kareem','Damon','Jalen','Jaylen','Dwayne','DaQuan','Aaliyah','Kiara','Janelle','Jasmine','Tanisha','Maurice','Tyrell','Kwame','Khalil','Terrell','Cedric','Nia','Zuri','Jada','Ebony','Dominique']);
|
||||
var NAMES_MIDDLE_EASTERN_C=new Set(['Layla','Omar','Khalid','Fatima','Yasmin','Hassan','Hussein','Ahmed','Mohamed','Mohammed','Ali','Karim','Yusuf','Yara','Nadia','Zainab','Rania','Samira','Mariam','Salma','Ibrahim','Mahmoud','Saif','Anwar','Bilal','Faisal','Hamza','Imran','Sami','Wael','Zaid','Amira','Iman','Lina','Mona','Noor','Rana','Soha','Zara']);
|
||||
// Surname → ethnicity. Surname is more diagnostic than first name
|
||||
// for hispanic and asian — "Anna Cruz" is hispanic via surname.
|
||||
var SURNAMES_HISPANIC_C=new Set(['Garcia','Rodriguez','Martinez','Hernandez','Lopez','Gonzalez','Perez','Sanchez','Ramirez','Torres','Flores','Rivera','Gomez','Diaz','Reyes','Cruz','Morales','Ortiz','Gutierrez','Chavez','Ramos','Ruiz','Alvarez','Mendoza','Vasquez','Castillo','Jimenez','Moreno','Romero','Herrera','Medina','Aguilar','Vargas','Castro','Fernandez','Guzman','Munoz','Salazar','Ortega','Delgado','Estrada','Ayala','Pena','Cabrera','Alvarado','Espinoza','Padilla','Cardenas','Cortes','Ibarra','Vega','Soto','Lara','Navarro','Campos','Acosta','Rios','Marquez','Sandoval','Maldonado','Solis','Rojas','Mejia','Beltran','Cervantes','Lozano','Carrillo','Trevino','Robles','Tapia','Lugo']);
|
||||
var SURNAMES_SOUTH_ASIAN_C=new Set(['Patel','Singh','Kumar','Sharma','Gupta','Shah','Mehta','Desai','Joshi','Reddy','Nair','Iyer','Verma','Agarwal','Kapoor','Chopra','Malhotra','Banerjee','Chatterjee','Mukherjee','Das','Sen','Bose','Roy','Sinha','Trivedi','Pandey','Mishra','Tiwari','Yadav','Chauhan','Rana','Thakur','Pillai','Menon','Krishnan','Rao','Naidu','Pradhan','Acharya','Devi','Kaur']);
|
||||
var SURNAMES_EAST_ASIAN_C=new Set(['Chen','Wang','Li','Liu','Yang','Huang','Zhao','Wu','Zhou','Xu','Zhu','Sun','Ma','Lin','Lee','Kim','Park','Choi','Jung','Kang','Cho','Yoon','Han','Lim','Oh','Nakamura','Tanaka','Suzuki','Yamamoto','Sato','Watanabe','Takahashi','Kobayashi','Yoshida','Saito','Nguyen','Tran','Le','Pham','Hoang','Phan','Vu','Vo','Dang','Bui','Do','Ngo','Truong','Mai','Cao','Wong','Tang','Tan','Cheng','Lau','Leung','Ng','Cheung','Yip','Hsu','Tsai','Hsieh']);
|
||||
var SURNAMES_MIDDLE_EASTERN_C=new Set(['Khan','Ahmed','Hussein','Hassan','Ali','Mahmoud','Mohamed','Mohammed','Saleh','Aziz','Karim','Hamad','Najjar','Haddad','Khoury','Mansour','Rahman','Iqbal','Malik','Sheikh','Siddiqui','Qureshi','Saeed']);
|
||||
|
||||
function guessEthnicityFromName(first, last){
|
||||
if(last){
|
||||
var s=last.replace(/[^A-Za-z]/g,'');
|
||||
if(s){
|
||||
var sc=s[0].toUpperCase()+s.slice(1).toLowerCase();
|
||||
if(SURNAMES_HISPANIC_C.has(sc)) return 'hispanic';
|
||||
if(SURNAMES_MIDDLE_EASTERN_C.has(sc)) return 'middle_eastern';
|
||||
if(SURNAMES_SOUTH_ASIAN_C.has(sc)) return 'south_asian';
|
||||
if(SURNAMES_EAST_ASIAN_C.has(sc)) return 'east_asian';
|
||||
}
|
||||
}
|
||||
if(first){
|
||||
var clean=first.replace(/[^A-Za-z]/g,'');
|
||||
if(clean){
|
||||
var c=clean[0].toUpperCase()+clean.slice(1).toLowerCase();
|
||||
if(NAMES_MIDDLE_EASTERN_C.has(c)) return 'middle_eastern';
|
||||
if(NAMES_BLACK_C.has(c)) return 'black';
|
||||
if(NAMES_HISPANIC_C.has(c)) return 'hispanic';
|
||||
if(NAMES_SOUTH_ASIAN_C.has(c)) return 'south_asian';
|
||||
if(NAMES_EAST_ASIAN_C.has(c)) return 'east_asian';
|
||||
}
|
||||
}
|
||||
return 'caucasian';
|
||||
}
|
||||
function guessEthnicityFromFirstName(n){
|
||||
if(!n) return 'caucasian';
|
||||
var clean=n.replace(/[^A-Za-z]/g,''); if(!clean) return 'caucasian';
|
||||
var c=clean[0].toUpperCase()+clean.slice(1).toLowerCase();
|
||||
if(NAMES_MIDDLE_EASTERN_C.has(c)) return 'middle_eastern';
|
||||
if(NAMES_BLACK_C.has(c)) return 'black';
|
||||
if(NAMES_HISPANIC_C.has(c)) return 'hispanic';
|
||||
if(NAMES_SOUTH_ASIAN_C.has(c)) return 'south_asian';
|
||||
if(NAMES_EAST_ASIAN_C.has(c)) return 'east_asian';
|
||||
return 'caucasian';
|
||||
}
|
||||
|
||||
function workerRow(name, role, detail, opts){
|
||||
opts = opts || {};
|
||||
var band = roleBand(role||'');
|
||||
var w = el('div','worker');
|
||||
if(band.band) w.dataset.roleBand = band.band;
|
||||
var initials = (name||'?').split(' ').map(function(s){return (s[0]||'').toUpperCase()}).join('').substring(0,2);
|
||||
var av = el('div','av',initials);
|
||||
// Headshot insertion removed 2026-04-28. The .av element stays as
|
||||
// a monogram-initials avatar.
|
||||
w.appendChild(av);
|
||||
var info = el('div','info');
|
||||
var nm = el('div','nm', name||'?');
|
||||
if(opts.endorsed){
|
||||
nm.appendChild(el('span','boost-chip',opts.endorsed));
|
||||
}
|
||||
info.appendChild(nm);
|
||||
var why = el('div','why');
|
||||
if(band.label){
|
||||
var pill = document.createElement('span'); pill.className='role-pill';
|
||||
pill.dataset.rb = band.band;
|
||||
pill.textContent = band.label;
|
||||
why.appendChild(pill);
|
||||
}
|
||||
why.appendChild(document.createTextNode(detail||''));
|
||||
info.appendChild(why);
|
||||
w.appendChild(info);
|
||||
if(opts.score){
|
||||
w.appendChild(el('div','score', opts.score));
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
function el(tag, cls, text){
|
||||
var e=document.createElement(tag);
|
||||
if(cls) e.className=cls;
|
||||
@ -191,6 +366,9 @@ window.addEventListener('load',function(){
|
||||
loadChapter3();
|
||||
loadChapter4();
|
||||
loadChapter5();
|
||||
loadChapter6();
|
||||
loadChapter7();
|
||||
loadChapter8();
|
||||
});
|
||||
|
||||
// ─── Chapter 1 ────────────────────────────────────────────
|
||||
@ -306,6 +484,30 @@ function loadChapter4(){
|
||||
addr.style.cssText='color:#8b949e;font-size:12px;margin-top:2px';
|
||||
card.appendChild(addr);
|
||||
|
||||
// Contractor names link to the full /contractor profile page —
|
||||
// heat map, project index, history, 12 awaiting public-data
|
||||
// sources. The staffer click-through J asked for.
|
||||
if(p.contact_1_name || p.contact_2_name){
|
||||
var contractors=document.createElement('div');
|
||||
contractors.style.cssText='color:#8b949e;font-size:12px;margin-top:4px';
|
||||
contractors.appendChild(document.createTextNode('Contractors: '));
|
||||
var seen=[];
|
||||
[p.contact_1_name, p.contact_2_name].forEach(function(n,i){
|
||||
if(!n || seen.indexOf(n)>=0) return;
|
||||
seen.push(n);
|
||||
if(seen.length>1) contractors.appendChild(document.createTextNode(' · '));
|
||||
var a=document.createElement('a');
|
||||
a.href=P+'/contractor?name='+encodeURIComponent(n);
|
||||
a.target='_blank';
|
||||
a.rel='noopener';
|
||||
a.style.cssText='color:#58a6ff;text-decoration:none;border-bottom:1px dotted #58a6ff44';
|
||||
a.title='Open full contractor profile';
|
||||
a.textContent=n;
|
||||
contractors.appendChild(a);
|
||||
});
|
||||
card.appendChild(contractors);
|
||||
}
|
||||
|
||||
card.appendChild(el('div','step-label','STEP 1 · Derive staffing need'));
|
||||
var s1=el('div','step-body');
|
||||
s1.appendChild(document.createTextNode('Industry heuristic: ~1 worker per $150K of permit cost, capped 2-8. Resulting contract: '));
|
||||
@ -321,21 +523,13 @@ function loadChapter4(){
|
||||
|
||||
var list=document.createElement('div');list.style.marginTop='6px';
|
||||
(prop.candidates||[]).slice(0,5).forEach(function(cand,i){
|
||||
var w=el('div','worker');
|
||||
var initials=(cand.name||'?').split(' ').map(function(s){return (s[0]||'').toUpperCase()}).join('').substring(0,2);
|
||||
w.appendChild(el('div','av',initials));
|
||||
var info=el('div','info');
|
||||
var nm=el('div','nm',cand.name||cand.doc_id||'?');
|
||||
if((cand.playbook_boost||0)>0){
|
||||
var ncit=(cand.playbook_citations||[]).length;
|
||||
nm.appendChild(el('span','boost-chip','Endorsed · '+ncit+' past fill'+(ncit!==1?'s':'')));
|
||||
}
|
||||
info.appendChild(nm);
|
||||
var why=cand.doc_id+' · '+(cand.playbook_boost>0?'boosted +'+cand.playbook_boost.toFixed(3)+' by memory · ':'')+'semantic score '+(cand.score||0).toFixed(3);
|
||||
info.appendChild(el('div','why',why));
|
||||
w.appendChild(info);
|
||||
w.appendChild(el('div','score','#'+(i+1)));
|
||||
list.appendChild(w);
|
||||
var detail = cand.doc_id+' · '+(cand.playbook_boost>0?'boosted +'+cand.playbook_boost.toFixed(3)+' by memory · ':'')+'semantic score '+(cand.score||0).toFixed(3);
|
||||
var endorsed = (cand.playbook_boost||0) > 0
|
||||
? 'Endorsed · '+((cand.playbook_citations||[]).length)+' past fill'+((cand.playbook_citations||[]).length!==1?'s':'')
|
||||
: null;
|
||||
list.appendChild(workerRow(cand.name||cand.doc_id||'?', prop.role||'', detail, {
|
||||
endorsed: endorsed, score: '#'+(i+1)
|
||||
}));
|
||||
});
|
||||
card.appendChild(list);
|
||||
|
||||
@ -407,7 +601,182 @@ function loadChapter5(){
|
||||
});
|
||||
}
|
||||
|
||||
// ─── Chapter 6 ────────────────────────────────────────────
|
||||
// ─── Chapter 6 — per-staffer hot-swap ─────────────────────
|
||||
function loadChapter6(){
|
||||
apiGet('/staffers').then(function(r){
|
||||
var host=document.getElementById('ch6-staffers');host.textContent='';
|
||||
var staffers=(r&&r.staffers)||[];
|
||||
if(!staffers.length){
|
||||
host.appendChild(el('div','err','No staffer roster — /staffers returned empty.'));
|
||||
return;
|
||||
}
|
||||
var grid=document.createElement('div'); grid.className='grid'; grid.style.gridTemplateColumns='repeat(auto-fit,minmax(280px,1fr))';
|
||||
staffers.forEach(function(s){
|
||||
var card=el('div','card accent-b');
|
||||
var name=el('div',null,s.name);
|
||||
name.style.cssText='font-size:18px;font-weight:700;color:#e6edf3;letter-spacing:-0.3px';
|
||||
card.appendChild(name);
|
||||
var role=el('div',null,s.display||'');
|
||||
role.style.cssText='font-size:11px;color:#545d68;text-transform:uppercase;letter-spacing:1.2px;margin-top:2px';
|
||||
card.appendChild(role);
|
||||
var ter=el('div',null,'Territory: '+s.territory.state+' · '+s.territory.cities.slice(0,3).join(', ')+'…');
|
||||
ter.style.cssText='color:#8b949e;font-size:12px;margin-top:8px';
|
||||
card.appendChild(ter);
|
||||
var greet=el('div',null,s.greeting||'');
|
||||
greet.style.cssText='color:#c9d1d9;font-size:11px;margin-top:6px;line-height:1.5;border-top:1px dashed #1f2631;padding-top:6px';
|
||||
card.appendChild(greet);
|
||||
grid.appendChild(card);
|
||||
});
|
||||
host.appendChild(grid);
|
||||
var narr=el('div','narr');
|
||||
narr.appendChild(el('strong',null,'What this means for a staffer. '));
|
||||
narr.appendChild(document.createTextNode('Same query — "forklift operators" — returns 89 Indiana workers when Devon is acting, 16 Wisconsin workers when Aisha is acting, 167 Illinois workers when Maria is acting. The MEMORY panel relabels itself with whoever\'s viewing. The corpus stays intact; the relevance gradient is per coordinator. As they each accumulate fills, their slice of the playbook compounds independently.'));
|
||||
host.appendChild(narr);
|
||||
}).catch(function(e){
|
||||
var h=document.getElementById('ch6-staffers');h.textContent='';h.appendChild(el('div','err','Staffer roster unavailable: '+(e.message||e)));
|
||||
});
|
||||
}
|
||||
|
||||
// ─── Chapter 7 — Construction Activity Signal Engine ──────
|
||||
function loadChapter7(){
|
||||
Promise.all([
|
||||
api('/intelligence/profiler_index',{limit:200}),
|
||||
]).then(function(rs){
|
||||
var prof=rs[0]||{};
|
||||
var rows=prof.contractors||[];
|
||||
var host=document.getElementById('ch7-signal');host.textContent='';
|
||||
// Aggregate basket
|
||||
var byTicker={};
|
||||
rows.forEach(function(r){
|
||||
var ts=(r.tickers&&r.tickers.direct?r.tickers.direct:[]).concat(r.tickers&&r.tickers.associated?r.tickers.associated:[]);
|
||||
ts.forEach(function(t){
|
||||
if(!t||!t.ticker) return;
|
||||
if(!byTicker[t.ticker]) byTicker[t.ticker]={ticker:t.ticker,count:0,kinds:new Set()};
|
||||
byTicker[t.ticker].count++;
|
||||
byTicker[t.ticker].kinds.add(t.via);
|
||||
});
|
||||
});
|
||||
var basket=Object.values(byTicker).sort(function(a,b){return b.count-a.count});
|
||||
var attribCost=0;
|
||||
rows.forEach(function(r){
|
||||
var ts=(r.tickers&&r.tickers.direct?r.tickers.direct:[]).concat(r.tickers&&r.tickers.associated?r.tickers.associated:[]);
|
||||
if(ts.length>0) attribCost += (r.total_cost||0);
|
||||
});
|
||||
var totalAttrib = basket.reduce(function(s,b){return s+b.count},0);
|
||||
if(!basket.length){
|
||||
host.appendChild(el('div','loading','No public-issuer attributions in this view yet.'));
|
||||
return;
|
||||
}
|
||||
// Top-line metric strip
|
||||
var grid=document.createElement('div');grid.className='grid';
|
||||
var c1=el('div','card accent-g');
|
||||
var b1=el('div',null,basket.length); b1.style.cssText='font-size:30px;font-weight:800;color:#3fb950;line-height:1';
|
||||
c1.appendChild(b1);
|
||||
var l1=el('div',null,'Public issuers in scope'); l1.style.cssText='font-size:10px;color:#545d68;text-transform:uppercase;letter-spacing:1.2px;margin-top:8px;font-weight:600';
|
||||
c1.appendChild(l1);
|
||||
var s1=el('div',null,totalAttrib+' attribution edges across the contractor graph'); s1.style.cssText='font-size:12px;color:#8b949e;margin-top:4px';
|
||||
c1.appendChild(s1);
|
||||
grid.appendChild(c1);
|
||||
var c2=el('div','card accent-b');
|
||||
var bav = attribCost>=1e9?'$'+(attribCost/1e9).toFixed(2)+'B':attribCost>=1e6?'$'+(attribCost/1e6).toFixed(0)+'M':'$'+Math.round(attribCost/1e3)+'K';
|
||||
var b2=el('div',null,bav); b2.style.cssText='font-size:30px;font-weight:800;color:#58a6ff;line-height:1';
|
||||
c2.appendChild(b2);
|
||||
var l2=el('div',null,'Attributed build value'); l2.style.cssText='font-size:10px;color:#545d68;text-transform:uppercase;letter-spacing:1.2px;margin-top:8px;font-weight:600';
|
||||
c2.appendChild(l2);
|
||||
var s2=el('div',null,'Permits with at least one wired public-issuer thread'); s2.style.cssText='font-size:12px;color:#8b949e;margin-top:4px';
|
||||
c2.appendChild(s2);
|
||||
grid.appendChild(c2);
|
||||
var c3=el('div','card accent-l');
|
||||
var b3=el('div',null,rows.length); b3.style.cssText='font-size:30px;font-weight:800;color:#bc8cff;line-height:1';
|
||||
c3.appendChild(b3);
|
||||
var l3=el('div',null,'Contractors indexed'); l3.style.cssText='font-size:10px;color:#545d68;text-transform:uppercase;letter-spacing:1.2px;margin-top:8px;font-weight:600';
|
||||
c3.appendChild(l3);
|
||||
var s3=el('div',null,'Each is also a heat map of where they work'); s3.style.cssText='font-size:12px;color:#8b949e;margin-top:4px';
|
||||
c3.appendChild(s3);
|
||||
grid.appendChild(c3);
|
||||
host.appendChild(grid);
|
||||
// Top issuer table
|
||||
var tHdr=document.createElement('div');tHdr.style.cssText='color:#545d68;font-size:11px;text-transform:uppercase;letter-spacing:1.4px;font-weight:600;margin:14px 0 8px';
|
||||
tHdr.textContent='Top public issuers attributable in this view';
|
||||
host.appendChild(tHdr);
|
||||
basket.slice(0,8).forEach(function(b){
|
||||
var row=el('div','row');
|
||||
var left=document.createElement('div');left.style.flex='1';left.style.minWidth='0';
|
||||
var tk=el('div','title',b.ticker);
|
||||
tk.style.cssText+='font-family:ui-monospace,monospace;color:#3fb950';
|
||||
left.appendChild(tk);
|
||||
var kinds=Array.from(b.kinds);
|
||||
var meta=el('div','meta',b.count+' attribution'+(b.count===1?'':'s')+' · '+kinds.join('+'));
|
||||
left.appendChild(meta);
|
||||
row.appendChild(left);
|
||||
var right=document.createElement('div');right.style.cssText='font-size:11px;color:#58a6ff';
|
||||
var a=document.createElement('a');a.href=P+'/profiler';a.target='_blank';a.style.color='#58a6ff';a.style.textDecoration='none';
|
||||
a.textContent='see in profiler →';
|
||||
right.appendChild(a);
|
||||
row.appendChild(right);
|
||||
host.appendChild(row);
|
||||
});
|
||||
var narr=el('div','narr');
|
||||
narr.appendChild(el('strong',null,'What this means for the business. '));
|
||||
narr.appendChild(document.createTextNode('The data corpus is also a market-signal engine. When a contractor co-files permits with a public company, that contractor inherits the ticker as an associated indicator. Permit volume changes precede earnings calls by months. As we add cities (NYC DOB next, then LA / Houston / Boston) the network compounds — and we own a piece of the signal that nobody else has.'));
|
||||
host.appendChild(narr);
|
||||
}).catch(function(e){
|
||||
var h=document.getElementById('ch7-signal');h.textContent='';h.appendChild(el('div','err','Signal engine unavailable: '+(e.message||e)));
|
||||
});
|
||||
}
|
||||
|
||||
// ─── Chapter 8 — Triage in one shot ───────────────────────
|
||||
function loadChapter8(){
|
||||
api('/intelligence/chat',{message:'Marcus running late site 4422'}).then(function(d){
|
||||
var host=document.getElementById('ch8-triage');host.textContent='';
|
||||
if(d.type!=='triage'){
|
||||
host.appendChild(el('div','err','Triage route did not fire. Got type=' + (d.type||'?')));
|
||||
return;
|
||||
}
|
||||
// Worker card
|
||||
var wc=el('div','card accent-r');
|
||||
var lbl=el('div',null,'⚠ TRIAGE EVENT'); lbl.style.cssText='font-size:10px;color:#f85149;text-transform:uppercase;letter-spacing:1.2px;font-weight:700;margin-bottom:8px';
|
||||
wc.appendChild(lbl);
|
||||
var nm=el('div',null,d.worker.name); nm.style.cssText='font-size:18px;font-weight:700;color:#e6edf3';
|
||||
wc.appendChild(nm);
|
||||
var loc=el('div',null,(d.worker.role||'?')+' · '+(d.worker.city||'')+', '+(d.worker.state||''));
|
||||
loc.style.cssText='font-size:12px;color:#8b949e;margin-top:2px';
|
||||
wc.appendChild(loc);
|
||||
var stats=document.createElement('div');stats.style.cssText='display:flex;gap:14px;font-size:11px;color:#8b949e;margin-top:8px;flex-wrap:wrap';
|
||||
[['Reliability',Math.round((d.worker.rel||0)*100)+'%'],['Responsiveness',Math.round((d.worker.resp||0)*100)+'%'],['Availability',Math.round((d.worker.avail||0)*100)+'%']].forEach(function(p){
|
||||
var s=document.createElement('span');
|
||||
var l=document.createElement('span');l.textContent=p[0]+': ';
|
||||
var b=document.createElement('b');b.style.color='#e6edf3';b.textContent=p[1];
|
||||
s.appendChild(l);s.appendChild(b);stats.appendChild(s);
|
||||
});
|
||||
wc.appendChild(stats);
|
||||
host.appendChild(wc);
|
||||
// Draft SMS
|
||||
var smsLabel=el('div',null,'DRAFT SMS — TO CLIENT'); smsLabel.style.cssText='font-size:10px;color:#d29922;text-transform:uppercase;letter-spacing:1.2px;font-weight:700;margin:14px 0 4px';
|
||||
host.appendChild(smsLabel);
|
||||
var smsBox=el('div',null,d.draft_sms||'');
|
||||
smsBox.style.cssText='background:#0d1117;border:1px solid #21262d;border-radius:6px;padding:10px 12px;font-family:ui-monospace,monospace;font-size:12px;color:#e6edf3;line-height:1.5;white-space:pre-wrap';
|
||||
host.appendChild(smsBox);
|
||||
// Backfills
|
||||
if((d.backfills||[]).length){
|
||||
var bfHdr=document.createElement('div');bfHdr.style.cssText='font-size:11px;color:#3fb950;text-transform:uppercase;letter-spacing:1.2px;font-weight:600;margin:14px 0 8px';
|
||||
bfHdr.textContent='✓ '+d.backfills.length+' local '+(d.worker.role||'workers')+' available — sorted by responsiveness';
|
||||
host.appendChild(bfHdr);
|
||||
d.backfills.slice(0,5).forEach(function(c){
|
||||
var detail=(c.role||'?')+' · '+(c.city||'')+', '+(c.state||'')+' · rel '+Math.round((c.rel||0)*100)+'% · resp '+Math.round((c.resp||0)*100)+'%';
|
||||
host.appendChild(workerRow(c.name||'?', c.role||'', detail));
|
||||
});
|
||||
}
|
||||
var narr=el('div','narr');
|
||||
narr.appendChild(el('strong',null,'What this means for a coordinator. '));
|
||||
narr.appendChild(document.createTextNode('A normal afternoon: text rolls in, coordinator opens 3 tabs to look up the worker, checks the bench by hand, drafts a message. 20 minutes. Here: the system pulled the profile, scored attendance, surfaced 5 same-role same-geo backfills sorted by who actually answers their phone, and pre-wrote the client-facing SMS. The coordinator clicks send. ' + d.duration_ms + 'ms.'));
|
||||
host.appendChild(narr);
|
||||
}).catch(function(e){
|
||||
var h=document.getElementById('ch8-triage');h.textContent='';h.appendChild(el('div','err','Triage demo unavailable: '+(e.message||e)));
|
||||
});
|
||||
}
|
||||
|
||||
// ─── Chapter 9 (was 6) — Try it yourself ──────────────────
|
||||
function runTry(){
|
||||
var q=document.getElementById('try-q').value.trim();if(!q)return;
|
||||
var btn=document.getElementById('try-btn'),out=document.getElementById('try-out');
|
||||
@ -437,23 +806,16 @@ function runTry(){
|
||||
|
||||
var workers=d.sql_results||d.vector_results||d.results||[];
|
||||
workers.slice(0,5).forEach(function(w,i){
|
||||
var row=el('div','worker');
|
||||
var nm=w.name||(w.text||'').split('—')[0].trim()||w.doc_id||'?';
|
||||
var initials=nm.split(' ').map(function(s){return (s[0]||'').toUpperCase()}).join('').substring(0,2);
|
||||
row.appendChild(el('div','av',initials));
|
||||
var info=el('div','info');
|
||||
var n=el('div','nm',nm);
|
||||
if((w.playbook_boost||0)>0){
|
||||
n.appendChild(el('span','boost-chip','Endorsed · '+((w.playbook_citations||[]).length||'?')+' past fill(s)'));
|
||||
}
|
||||
info.appendChild(n);
|
||||
var bits=[];
|
||||
if(w.role) bits.push(w.role);
|
||||
if(w.city&&w.state) bits.push(w.city+', '+w.state);
|
||||
if(w.rel!==undefined) bits.push('reliability '+Math.round(w.rel*100)+'%');
|
||||
if(w.avail!==undefined) bits.push('availability '+Math.round(w.avail*100)+'%');
|
||||
info.appendChild(el('div','why',bits.join(' · ')||'AI semantic match'));
|
||||
row.appendChild(info);
|
||||
var endorsed = (w.playbook_boost||0) > 0
|
||||
? 'Endorsed · '+((w.playbook_citations||[]).length||'?')+' past fill(s)'
|
||||
: null;
|
||||
var row = workerRow(nm, w.role||'', bits.join(' · ')||'AI semantic match', { endorsed: endorsed });
|
||||
row.appendChild(el('div','score','#'+(i+1)));
|
||||
card.appendChild(row);
|
||||
});
|
||||
|
||||
606
mcp-server/contractor.html
Normal file
606
mcp-server/contractor.html
Normal file
@ -0,0 +1,606 @@
|
||||
<!DOCTYPE html>
|
||||
<html><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Contractor Profile · Staffing Co-Pilot</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
<style>
|
||||
*{margin:0;padding:0;box-sizing:border-box}
|
||||
html,body{overflow-x:hidden}
|
||||
body{font-family:'Inter',-apple-system,system-ui,sans-serif;background:#090c10;color:#b0b8c4;font-size:14px;line-height:1.6}
|
||||
.bar{background:#0d1117;padding:0 24px;height:56px;border-bottom:1px solid #171d27;display:flex;justify-content:space-between;align-items:center}
|
||||
.bar h1{font-size:14px;font-weight:600;color:#e6edf3}
|
||||
.bar a{color:#545d68;text-decoration:none;font-size:12px;padding:6px 14px;border-radius:6px}
|
||||
.bar a:hover{color:#e6edf3;background:#161b22}
|
||||
.content{max-width:1100px;margin:0 auto;padding:24px 20px 40px}
|
||||
.search-box{background:#0d1117;border:1px solid #21262d;border-radius:10px;padding:16px;margin-bottom:24px;display:flex;gap:10px}
|
||||
.search-box input{flex:1;padding:12px 16px;background:#161b22;border:1px solid #21262d;border-radius:8px;color:#e6edf3;font-size:14px;outline:none}
|
||||
.search-box input:focus{border-color:#388bfd}
|
||||
.search-box button{padding:12px 24px;background:#1f6feb;border:none;border-radius:8px;color:#fff;font-weight:600;cursor:pointer}
|
||||
.hero{background:#0d1117;border:1px solid #171d27;border-radius:12px;padding:24px;margin-bottom:16px}
|
||||
.hero h2{color:#e6edf3;font-size:22px;font-weight:700;letter-spacing:-0.5px;margin-bottom:6px}
|
||||
.hero .ticker-row{display:flex;align-items:center;gap:10px;margin-top:10px;flex-wrap:wrap}
|
||||
.hero .ticker{font-family:ui-monospace,SFMono-Regular,monospace;background:#161b22;padding:4px 10px;border-radius:6px;color:#3fb950;border:1px solid #3fb95066;font-weight:600;font-size:12px}
|
||||
.hero .meta{font-size:12px;color:#8b949e}
|
||||
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(320px,1fr));gap:14px}
|
||||
.card{background:#0d1117;border:1px solid #171d27;border-radius:10px;padding:16px}
|
||||
.card h3{font-size:11px;color:#545d68;text-transform:uppercase;letter-spacing:1.2px;margin-bottom:10px;font-weight:600}
|
||||
.card .big{font-size:24px;font-weight:700;color:#e6edf3;letter-spacing:-0.5px;margin-bottom:4px}
|
||||
.card .sub{font-size:11px;color:#8b949e;line-height:1.5}
|
||||
.card a{color:#58a6ff;text-decoration:none;font-size:11px}
|
||||
.row{display:flex;justify-content:space-between;align-items:baseline;padding:6px 0;border-bottom:1px dashed #1f2631;font-size:11px}
|
||||
.row:last-child{border:none}
|
||||
.row .l{color:#8b949e}
|
||||
.row .v{color:#e6edf3;font-family:ui-monospace,monospace;font-variant-numeric:tabular-nums}
|
||||
.chip{display:inline-block;padding:3px 8px;border-radius:9px;font-size:10px;font-weight:600;margin-right:6px;margin-bottom:4px}
|
||||
.ld{color:#3d444d;text-align:center;padding:60px;font-size:13px}
|
||||
.empty{color:#545d68;font-size:11px;font-style:italic;line-height:1.5}
|
||||
.wide{grid-column:1/-1}
|
||||
.heatmap{height:380px;border-radius:8px;border:1px solid #1f2631;overflow:hidden;margin-top:10px}
|
||||
.heatmap .leaflet-container{background:#0a0d12}
|
||||
.timeline{margin-top:10px;display:flex;align-items:flex-end;gap:2px;height:80px;padding:6px 0;border-bottom:1px solid #1f2631}
|
||||
.timeline .tbar{flex:1;background:#1f6feb;min-height:2px;border-radius:2px 2px 0 0;position:relative;cursor:help}
|
||||
.timeline .tbar:hover{background:#58a6ff}
|
||||
.timeline-axis{display:flex;justify-content:space-between;font-size:10px;color:#545d68;padding-top:4px;font-family:ui-monospace,monospace}
|
||||
.placeholder-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:10px;margin-top:14px}
|
||||
.ph-card{background:#0a0d12;border:1px dashed #21262d;border-radius:8px;padding:12px 14px;position:relative}
|
||||
.ph-card h4{font-size:11px;color:#8b949e;font-weight:600;margin-bottom:4px;display:flex;align-items:center;gap:6px}
|
||||
.ph-card h4 .badge{font-size:9px;padding:2px 6px;border-radius:8px;background:#161b22;color:#d29922;border:1px solid #d2992244;font-weight:600;letter-spacing:0.5px;text-transform:uppercase}
|
||||
.ph-card .why{font-size:11px;color:#e6edf3;line-height:1.5;margin-bottom:6px}
|
||||
.ph-card .would{font-size:10px;color:#545d68;font-family:ui-monospace,monospace;line-height:1.5;border-top:1px dashed #1f2631;padding-top:6px;margin-top:6px}
|
||||
.section-label{font-size:10px;color:#545d68;text-transform:uppercase;letter-spacing:1.4px;font-weight:600;margin:24px 0 8px}
|
||||
@media(max-width:640px){.bar{padding:0 14px}.content{padding:14px}.hero{padding:16px}.hero h2{font-size:18px}.card{padding:12px}}
|
||||
</style>
|
||||
</head><body>
|
||||
<div class="bar">
|
||||
<h1>Staffing Co-Pilot · Contractor Profile</h1>
|
||||
<a href="/">← Dashboard</a>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="search-box">
|
||||
<input id="q" type="text" placeholder="Type a contractor name (e.g., Turner Construction Company)" onkeydown="if(event.key==='Enter')lookup()">
|
||||
<button onclick="lookup()">Look up</button>
|
||||
</div>
|
||||
<div id="out"><div class="ld">Type a name above to load the full portfolio across every wired data source.</div></div>
|
||||
</div>
|
||||
<script>
|
||||
function $(id){return document.getElementById(id)}
|
||||
|
||||
// Path prefix detection — devop.live serves this page under /lakehouse,
|
||||
// localhost:3700 serves it at root. URL rewrites must preserve whatever
|
||||
// prefix the user reached the page through, otherwise the back-link and
|
||||
// browser refresh break.
|
||||
var P=location.pathname.indexOf('/lakehouse')>=0?'/lakehouse':'';
|
||||
|
||||
// Bootstrap from URL: /contractor?name=Turner+Construction
|
||||
window.addEventListener('load', function(){
|
||||
var name = new URLSearchParams(location.search).get('name');
|
||||
if(name){
|
||||
$('q').value = name;
|
||||
lookup();
|
||||
}
|
||||
// Back link respects the prefix too
|
||||
var back=document.querySelector('.bar a');
|
||||
if(back) back.href=P+'/';
|
||||
});
|
||||
|
||||
function lookup(){
|
||||
var name = $('q').value.trim();
|
||||
if(!name){ $('out').textContent = ''; return; }
|
||||
history.replaceState({}, '', P+'/contractor?name='+encodeURIComponent(name));
|
||||
var out = $('out');
|
||||
out.textContent = '';
|
||||
var ld = document.createElement('div');
|
||||
ld.className = 'ld';
|
||||
ld.textContent = 'Pulling OSHA, SEC, Stooq, Chicago history, USASpending… (~5-10s on cold cache)';
|
||||
out.appendChild(ld);
|
||||
fetch(P+'/intelligence/contractor_profile',{
|
||||
method:'POST',
|
||||
headers:{'Content-Type':'application/json'},
|
||||
body:JSON.stringify({name:name})
|
||||
}).then(function(r){return r.json()}).then(function(d){
|
||||
render(d);
|
||||
}).catch(function(e){
|
||||
out.textContent = '';
|
||||
var err = document.createElement('div');
|
||||
err.className = 'ld';
|
||||
err.style.color = '#f85149';
|
||||
err.textContent = 'profile failed: '+e.message;
|
||||
out.appendChild(err);
|
||||
});
|
||||
}
|
||||
|
||||
function render(d){
|
||||
var out = $('out');
|
||||
out.textContent = '';
|
||||
|
||||
// ─── Hero — name, ticker, parent ─────────────
|
||||
var hero = document.createElement('div');
|
||||
hero.className = 'hero';
|
||||
var h2 = document.createElement('h2');
|
||||
h2.textContent = d.display_name;
|
||||
hero.appendChild(h2);
|
||||
var sub = document.createElement('div');
|
||||
sub.className = 'meta';
|
||||
sub.textContent = 'Internal ticker: '+(d.ticker||'?')+' · profile generated '+new Date(d.generated_at).toLocaleTimeString();
|
||||
hero.appendChild(sub);
|
||||
|
||||
var trow = document.createElement('div');
|
||||
trow.className = 'ticker-row';
|
||||
// Direct ticker
|
||||
var s = d.stock;
|
||||
if(s && s.status==='ok'){
|
||||
var tk = document.createElement('span');
|
||||
tk.className = 'ticker';
|
||||
tk.textContent = s.ticker;
|
||||
trow.appendChild(tk);
|
||||
var px = document.createElement('span');
|
||||
px.className = 'meta';
|
||||
px.textContent = (s.company_name||'')+(s.exchange?' · '+s.exchange:'')+(s.price?' · $'+s.price.toFixed(2):'');
|
||||
if(s.day_change_pct!=null && !isNaN(s.day_change_pct)){
|
||||
var ch = (s.day_change_pct>=0?'+':'')+s.day_change_pct.toFixed(2)+'%';
|
||||
var chSpan = document.createElement('span');
|
||||
chSpan.style.color = s.day_change_pct>=0?'#3fb950':'#f85149';
|
||||
chSpan.style.marginLeft = '6px';
|
||||
chSpan.textContent = ch;
|
||||
px.appendChild(chSpan);
|
||||
}
|
||||
trow.appendChild(px);
|
||||
} else {
|
||||
var noTk = document.createElement('span');
|
||||
noTk.className = 'meta';
|
||||
noTk.textContent = 'Private — no direct US ticker';
|
||||
trow.appendChild(noTk);
|
||||
}
|
||||
// Parent link
|
||||
var pl = d.parent_link;
|
||||
if(pl && pl.status==='ok'){
|
||||
var arrow = document.createElement('span');
|
||||
arrow.className = 'meta';
|
||||
arrow.style.color = '#545d68';
|
||||
arrow.textContent = ' → parent ';
|
||||
trow.appendChild(arrow);
|
||||
var pTk = document.createElement('span');
|
||||
pTk.className = 'ticker';
|
||||
pTk.style.color = '#d29922';
|
||||
pTk.style.borderColor = '#d2992266';
|
||||
pTk.textContent = pl.parent_ticker || '?';
|
||||
pTk.title = pl.link_source || '';
|
||||
trow.appendChild(pTk);
|
||||
var pName = document.createElement('span');
|
||||
pName.className = 'meta';
|
||||
pName.textContent = pl.parent_name+(pl.parent_exchange?' · '+pl.parent_exchange:'')+(pl.parent_country?' · '+pl.parent_country:'');
|
||||
trow.appendChild(pName);
|
||||
} else if(pl && pl.status==='no_link'){
|
||||
var pp = document.createElement('span');
|
||||
pp.className = 'meta';
|
||||
pp.style.fontStyle = 'italic';
|
||||
pp.textContent = ' · '+(pl.reason||'no public parent identified');
|
||||
trow.appendChild(pp);
|
||||
}
|
||||
hero.appendChild(trow);
|
||||
out.appendChild(hero);
|
||||
|
||||
// ─── Grid of cards ─────────────────────────────
|
||||
var grid = document.createElement('div');
|
||||
grid.className = 'grid';
|
||||
|
||||
// OSHA
|
||||
var oCard = card('OSHA SAFETY HISTORY (NATIONAL)');
|
||||
var osha = d.osha || {};
|
||||
if(osha.status==='ok'){
|
||||
big(oCard, osha.inspection_count + ' inspections', 'most recent '+(osha.most_recent_date||'?'));
|
||||
rowEl(oCard, 'States seen', (osha.states_seen||[]).join(', ') || '?');
|
||||
rowEl(oCard, 'Most recent', osha.most_recent_date||'?');
|
||||
if(osha.recent_inspections && osha.recent_inspections.length){
|
||||
var rep = document.createElement('div');
|
||||
rep.style.marginTop = '8px';
|
||||
rep.style.fontSize = '10px';
|
||||
rep.style.color = '#545d68';
|
||||
rep.textContent = 'Recent inspections:';
|
||||
oCard.appendChild(rep);
|
||||
osha.recent_inspections.slice(0,5).forEach(function(i){
|
||||
var r = document.createElement('div');
|
||||
r.style.fontSize = '10px';
|
||||
r.style.color = '#8b949e';
|
||||
r.style.fontFamily = 'ui-monospace,monospace';
|
||||
r.style.padding = '2px 0';
|
||||
var a = document.createElement('a');
|
||||
a.href = i.detail_url;
|
||||
a.target = '_blank';
|
||||
a.textContent = i.id;
|
||||
r.appendChild(a);
|
||||
r.appendChild(document.createTextNode(' · '+i.date+' · '+i.state+' · '+i.type+' · '+i.scope));
|
||||
oCard.appendChild(r);
|
||||
});
|
||||
}
|
||||
} else if(osha.status==='no_match'){
|
||||
big(oCard, 'No inspections', 'clean record');
|
||||
} else {
|
||||
empty(oCard, 'OSHA fetch error: '+(osha.error||'unknown'));
|
||||
}
|
||||
grid.appendChild(oCard);
|
||||
|
||||
// Chicago history
|
||||
var hCard = card('CHICAGO PERMIT HISTORY (24mo + LIFETIME)');
|
||||
var hist = d.history || {};
|
||||
if(hist.status==='ok'){
|
||||
big(hCard, hist.permits_historical_total+' permits all-time',
|
||||
hist.permits_last_180d+' in last 180d · '+hist.permits_last_24mo+' in 24mo · trend: '+hist.trend);
|
||||
rowEl(hCard, 'Cost (24mo)', hist.total_cost_last_24mo>=1e6 ? '$'+(hist.total_cost_last_24mo/1e6).toFixed(1)+'M' : '$'+Math.round(hist.total_cost_last_24mo/1e3)+'K');
|
||||
if(hist.recent_permits && hist.recent_permits.length){
|
||||
var rh = document.createElement('div');
|
||||
rh.style.marginTop = '8px';
|
||||
rh.style.fontSize = '10px';
|
||||
rh.style.color = '#545d68';
|
||||
rh.textContent = 'Recent Chicago permits:';
|
||||
hCard.appendChild(rh);
|
||||
hist.recent_permits.slice(0,5).forEach(function(p){
|
||||
var r = document.createElement('div');
|
||||
r.style.fontSize = '10px';
|
||||
r.style.color = '#8b949e';
|
||||
r.style.padding = '2px 0';
|
||||
r.textContent = '· '+(p.date||'?')+' · '+p.work_type+' · $'+(p.cost||0).toLocaleString()+' · '+p.address;
|
||||
hCard.appendChild(r);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
empty(hCard, 'Chicago history error');
|
||||
}
|
||||
grid.appendChild(hCard);
|
||||
|
||||
// Federal contracts
|
||||
var fCard = card('FEDERAL CONTRACTS (USASpending.gov)');
|
||||
var fed = d.federal || {};
|
||||
if(fed.status==='ok' && fed.total_awards_count>0){
|
||||
var dollars = fed.total_awards_value>=1e9 ? '$'+(fed.total_awards_value/1e9).toFixed(2)+'B'
|
||||
: fed.total_awards_value>=1e6 ? '$'+(fed.total_awards_value/1e6).toFixed(1)+'M'
|
||||
: '$'+Math.round(fed.total_awards_value/1e3)+'K';
|
||||
big(fCard, dollars, fed.total_awards_count+' awards · most recent '+(fed.most_recent_award_date||'?'));
|
||||
if(fed.top_agencies && fed.top_agencies.length){
|
||||
var ta = document.createElement('div');
|
||||
ta.style.marginTop = '6px';
|
||||
ta.style.fontSize = '10px';
|
||||
ta.style.color = '#545d68';
|
||||
ta.textContent = 'Top awarding agencies:';
|
||||
fCard.appendChild(ta);
|
||||
fed.top_agencies.forEach(function(a){
|
||||
var r = document.createElement('div');
|
||||
r.style.fontSize = '11px';
|
||||
r.style.color = '#8b949e';
|
||||
r.style.padding = '3px 0';
|
||||
var dollars2 = a.value>=1e6 ? '$'+(a.value/1e6).toFixed(1)+'M' : '$'+Math.round(a.value/1e3)+'K';
|
||||
r.textContent = '· '+a.agency+' — '+dollars2;
|
||||
fCard.appendChild(r);
|
||||
});
|
||||
}
|
||||
if(fed.source_url){
|
||||
var lnk = document.createElement('a');
|
||||
lnk.href = fed.source_url;
|
||||
lnk.target = '_blank';
|
||||
lnk.style.display = 'inline-block';
|
||||
lnk.style.marginTop = '8px';
|
||||
lnk.textContent = 'View on usaspending.gov ↗';
|
||||
fCard.appendChild(lnk);
|
||||
}
|
||||
} else if(fed.status==='no_match'){
|
||||
big(fCard, 'No federal contracts', 'on file under this name');
|
||||
} else {
|
||||
empty(fCard, 'usaspending error');
|
||||
}
|
||||
grid.appendChild(fCard);
|
||||
|
||||
// Debarment + NLRB combined
|
||||
var rCard = card('DEBARMENT + LABOR ACTIONS');
|
||||
var deb = d.debarment || {};
|
||||
var nlrb = d.nlrb || {};
|
||||
rowEl(rCard, 'SAM.gov excluded', deb.status==='needs_setup' ? 'awaiting API key' : (deb.sam_excluded?'YES':'no'));
|
||||
rowEl(rCard, 'IDOL debarred', deb.status==='needs_setup' ? 'awaiting scrape' : (deb.idol_debarred?'YES':'no'));
|
||||
rowEl(rCard, 'NLRB cases', nlrb.status==='needs_setup' ? 'awaiting scrape' : (nlrb.total_cases||0));
|
||||
if(deb.status==='needs_setup' || nlrb.status==='needs_setup'){
|
||||
var dn = document.createElement('div');
|
||||
dn.className = 'empty';
|
||||
dn.style.marginTop = '8px';
|
||||
dn.textContent = 'Both sources pending wire-up: '+(deb.reason||nlrb.reason||'');
|
||||
rCard.appendChild(dn);
|
||||
}
|
||||
grid.appendChild(rCard);
|
||||
|
||||
// ILSOS
|
||||
var iCard = card('CORPORATE REGISTRY (Illinois SoS)');
|
||||
var ilsos = d.ilsos || {};
|
||||
if(ilsos.status==='source_unreachable'){
|
||||
rowEl(iCard, 'Status', 'source blocked at our ASN');
|
||||
var en = document.createElement('div');
|
||||
en.className = 'empty';
|
||||
en.style.marginTop = '8px';
|
||||
en.textContent = ilsos.reason||'';
|
||||
iCard.appendChild(en);
|
||||
} else if(ilsos.status==='ok'){
|
||||
rowEl(iCard, 'Entity name', ilsos.entity_name||'?');
|
||||
rowEl(iCard, 'File #', ilsos.file_number||'?');
|
||||
rowEl(iCard, 'Status', ilsos.status_text||'?');
|
||||
rowEl(iCard, 'Formed', ilsos.formation_date||'?');
|
||||
rowEl(iCard, 'Registered agent', ilsos.registered_agent||'?');
|
||||
} else {
|
||||
empty(iCard, 'no ILSOS data');
|
||||
}
|
||||
grid.appendChild(iCard);
|
||||
|
||||
out.appendChild(grid);
|
||||
|
||||
// ─── Project Index summary — the staffer-facing build-signal score ──
|
||||
var pixHeader = document.createElement('div');
|
||||
pixHeader.className = 'section-label';
|
||||
pixHeader.textContent = '◆ Project Index — build-signal score';
|
||||
out.appendChild(pixHeader);
|
||||
|
||||
var pixCard = document.createElement('div');
|
||||
pixCard.className = 'card wide';
|
||||
// Score is a simple weighted blend of the wired signals — designed to
|
||||
// be replaced with a real model once enough placeholders are wired.
|
||||
var hist2 = d.history || {};
|
||||
var pixScore = 0;
|
||||
var pixDrivers = [];
|
||||
if(hist2.permits_last_180d){ pixScore += Math.min(hist2.permits_last_180d * 5, 30); pixDrivers.push(hist2.permits_last_180d+' Chicago permits in 180d (+'+Math.min(hist2.permits_last_180d*5,30)+')'); }
|
||||
if(hist2.trend === 'rising'){ pixScore += 10; pixDrivers.push('permit trend rising (+10)'); }
|
||||
if(d.osha && d.osha.status==='ok' && d.osha.inspection_count>0){ pixScore -= Math.min(d.osha.inspection_count*5, 25); pixDrivers.push(d.osha.inspection_count+' OSHA inspections (-'+Math.min(d.osha.inspection_count*5,25)+')'); }
|
||||
if(d.federal && d.federal.status==='ok' && d.federal.total_awards_count>0){ pixScore += 15; pixDrivers.push('federally-vetted contractor (+15)'); }
|
||||
if(d.debarment && d.debarment.sam_excluded){ pixScore -= 50; pixDrivers.push('SAM.gov excluded (-50)'); }
|
||||
if(d.stock && d.stock.status==='ok'){ pixScore += 5; pixDrivers.push('public ticker (+5)'); }
|
||||
pixScore = Math.max(0, Math.min(100, 50 + pixScore));
|
||||
var pixColor = pixScore >= 70 ? '#3fb950' : pixScore >= 40 ? '#d29922' : '#f85149';
|
||||
var pixHero = document.createElement('div');
|
||||
pixHero.style.cssText = 'display:flex;align-items:baseline;gap:14px;margin-bottom:8px';
|
||||
var pixBig = document.createElement('span');
|
||||
pixBig.style.cssText = 'font-size:42px;font-weight:700;color:'+pixColor+';letter-spacing:-1px';
|
||||
pixBig.textContent = pixScore;
|
||||
pixHero.appendChild(pixBig);
|
||||
var pixLabel = document.createElement('span');
|
||||
pixLabel.style.cssText = 'font-size:12px;color:#8b949e';
|
||||
pixLabel.textContent = pixScore >= 70 ? 'Strong staffing partner — wired signals positive' : pixScore >= 40 ? 'Mixed signals — review drivers below' : 'Caution — wired signals negative';
|
||||
pixHero.appendChild(pixLabel);
|
||||
pixCard.appendChild(pixHero);
|
||||
if(pixDrivers.length){
|
||||
var pixDrv = document.createElement('div');
|
||||
pixDrv.style.cssText = 'font-size:11px;color:#8b949e;line-height:1.7;font-family:ui-monospace,monospace';
|
||||
pixDrv.textContent = pixDrivers.join(' · ');
|
||||
pixCard.appendChild(pixDrv);
|
||||
}
|
||||
var pixFoot = document.createElement('div');
|
||||
pixFoot.style.cssText = 'font-size:10px;color:#545d68;margin-top:8px;font-style:italic;line-height:1.5';
|
||||
pixFoot.textContent = 'Score is a placeholder weighted blend of the 6 wired signals above. Real ML model lands once 12 awaiting sources below ship — that gives the index 18 features instead of 6.';
|
||||
pixCard.appendChild(pixFoot);
|
||||
out.appendChild(pixCard);
|
||||
|
||||
// ─── Heat map — every Chicago permit they're contact_1 or contact_2 on ─
|
||||
var mapHeader = document.createElement('div');
|
||||
mapHeader.className = 'section-label';
|
||||
mapHeader.textContent = '◆ Where they\'ve worked — Chicago permits, last 24 months';
|
||||
out.appendChild(mapHeader);
|
||||
var mapCard = document.createElement('div');
|
||||
mapCard.className = 'card wide';
|
||||
var mapDiv = document.createElement('div');
|
||||
mapDiv.className = 'heatmap';
|
||||
mapDiv.id = 'cmap';
|
||||
mapCard.appendChild(mapDiv);
|
||||
var mapHint = document.createElement('div');
|
||||
mapHint.style.cssText = 'font-size:11px;color:#545d68;margin-top:8px';
|
||||
mapHint.textContent = 'Loading geo from chicago_permits…';
|
||||
mapCard.appendChild(mapHint);
|
||||
out.appendChild(mapCard);
|
||||
|
||||
// Plot the recent_permits embedded in the contractor profile (now
|
||||
// includes lat/lng/permit_id/description per the entity.ts change).
|
||||
// Color by cost: green <$100K, amber $100K-$1M, red ≥$1M.
|
||||
var permits = (hist2.recent_permits||[]).filter(function(p){return p.lat&&p.lng});
|
||||
if(!permits.length){
|
||||
mapHint.textContent = 'No geocoded permits in the contractor history (Socrata may not have lat/lng for these records).';
|
||||
} else {
|
||||
// Construct map only after the div is in the DOM; defer one tick.
|
||||
setTimeout(function(){
|
||||
var map = L.map('cmap', {zoomControl:true, attributionControl:false}).setView([41.88,-87.63], 11);
|
||||
L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png',{maxZoom:19}).addTo(map);
|
||||
var bounds = [];
|
||||
var costs = permits.map(function(p){return Number(p.cost)||0});
|
||||
var maxCost = Math.max.apply(null, costs.concat([1]));
|
||||
permits.forEach(function(p){
|
||||
var c = Number(p.cost)||0;
|
||||
var radius = 4 + (c/maxCost)*16;
|
||||
var color = c >= 1000000 ? '#f85149' : c >= 100000 ? '#d29922' : '#3fb950';
|
||||
var marker = L.circleMarker([p.lat,p.lng],{radius:radius, color:color, weight:1, fillOpacity:0.55});
|
||||
// Build popup via DOM (no innerHTML — keeps the XSS hook happy)
|
||||
var pop = document.createElement('div');
|
||||
pop.style.cssText = 'font-family:ui-monospace,monospace;font-size:11px;color:#0a0d12;min-width:160px';
|
||||
var costRow = document.createElement('div');
|
||||
costRow.style.cssText = 'font-weight:700;margin-bottom:4px';
|
||||
costRow.textContent = '$'+c.toLocaleString()+' · '+(p.date||'?');
|
||||
pop.appendChild(costRow);
|
||||
var wt = document.createElement('div');
|
||||
wt.textContent = p.work_type||'?';
|
||||
pop.appendChild(wt);
|
||||
var addr = document.createElement('div');
|
||||
addr.style.color = '#545d68';
|
||||
addr.textContent = p.address||'?';
|
||||
pop.appendChild(addr);
|
||||
if(p.permit_id){
|
||||
var pid = document.createElement('div');
|
||||
pid.style.cssText = 'color:#545d68;margin-top:4px;font-size:10px';
|
||||
pid.textContent = 'permit '+p.permit_id;
|
||||
pop.appendChild(pid);
|
||||
}
|
||||
marker.bindPopup(pop);
|
||||
marker.addTo(map);
|
||||
bounds.push([p.lat, p.lng]);
|
||||
});
|
||||
if(bounds.length>1) map.fitBounds(bounds, {padding:[24,24]});
|
||||
mapHint.textContent = permits.length+' permits plotted · green <$100K, amber $100K-$1M, red ≥$1M · radius: relative cost';
|
||||
}, 50);
|
||||
}
|
||||
|
||||
// ─── History timeline — monthly permit volume + cost trend ─────────
|
||||
if(hist2.recent_permits && hist2.recent_permits.length){
|
||||
var tlHeader = document.createElement('div');
|
||||
tlHeader.className = 'section-label';
|
||||
tlHeader.textContent = '◆ Activity timeline — Chicago permits by month';
|
||||
out.appendChild(tlHeader);
|
||||
var tlCard = document.createElement('div');
|
||||
tlCard.className = 'card wide';
|
||||
// Bucket by year-month
|
||||
var buckets = {};
|
||||
hist2.recent_permits.forEach(function(p){
|
||||
var d = (p.date||'').substring(0,7); // YYYY-MM
|
||||
if(!d) return;
|
||||
buckets[d] = buckets[d] || {count:0, cost:0};
|
||||
buckets[d].count++;
|
||||
buckets[d].cost += Number(p.cost)||0;
|
||||
});
|
||||
var months = Object.keys(buckets).sort();
|
||||
if(months.length){
|
||||
var maxC = Math.max.apply(null, months.map(function(m){return buckets[m].count}));
|
||||
var tl = document.createElement('div'); tl.className='timeline';
|
||||
months.forEach(function(m){
|
||||
var b = buckets[m];
|
||||
var bar = document.createElement('div'); bar.className='tbar';
|
||||
bar.style.height = Math.max(2, Math.round(b.count/maxC*72)) + 'px';
|
||||
bar.title = m+' · '+b.count+' permit'+(b.count===1?'':'s')+' · $'+Math.round(b.cost).toLocaleString();
|
||||
tl.appendChild(bar);
|
||||
});
|
||||
tlCard.appendChild(tl);
|
||||
var ax = document.createElement('div'); ax.className='timeline-axis';
|
||||
var first = document.createElement('span'); first.textContent = months[0];
|
||||
var last = document.createElement('span'); last.textContent = months[months.length-1];
|
||||
ax.appendChild(first); ax.appendChild(last);
|
||||
tlCard.appendChild(ax);
|
||||
}
|
||||
out.appendChild(tlCard);
|
||||
}
|
||||
|
||||
// ─── 12 awaiting-source placeholders ──────────────────────────────
|
||||
// Each one names a real public data source that would feed the
|
||||
// build-signal index, with a one-line "why a staffer cares" framing
|
||||
// and a sample shape of what the panel would show once wired.
|
||||
var phHeader = document.createElement('div');
|
||||
phHeader.className = 'section-label';
|
||||
phHeader.textContent = '◆ 12 awaiting sources — what plugs in next';
|
||||
out.appendChild(phHeader);
|
||||
var phGrid = document.createElement('div');
|
||||
phGrid.className = 'placeholder-grid';
|
||||
PLACEHOLDERS.forEach(function(p){
|
||||
var c = document.createElement('div'); c.className='ph-card';
|
||||
var h = document.createElement('h4');
|
||||
var name = document.createElement('span'); name.textContent = p.name;
|
||||
var badge = document.createElement('span'); badge.className='badge'; badge.textContent='AWAITING';
|
||||
h.appendChild(name); h.appendChild(badge);
|
||||
c.appendChild(h);
|
||||
var why = document.createElement('div'); why.className='why'; why.textContent = p.why;
|
||||
c.appendChild(why);
|
||||
var would = document.createElement('div'); would.className='would';
|
||||
would.textContent = 'Would show: ' + p.would;
|
||||
c.appendChild(would);
|
||||
phGrid.appendChild(c);
|
||||
});
|
||||
out.appendChild(phGrid);
|
||||
|
||||
// Roadmap footer
|
||||
var foot = document.createElement('div');
|
||||
foot.style.marginTop = '20px';
|
||||
foot.style.fontSize = '10px';
|
||||
foot.style.color = '#484f58';
|
||||
foot.style.lineHeight = '1.6';
|
||||
foot.textContent = 'Wired: OSHA Enforcement · SEC EDGAR + Stooq · Chicago Socrata permits (lat/lng) · USASpending.gov · curated parent-ticker map · ILSOS (datacenter ASN blocked). 12 awaiting sources above are real public datasets that would 3× the feature count of the build-signal index — each one labeled with the one-liner the staffer would ask before placing a worker.';
|
||||
out.appendChild(foot);
|
||||
}
|
||||
|
||||
// Twelve real public data sources, framed in coordinator language.
|
||||
// Each is a placeholder; the panel renders them as "AWAITING" with a
|
||||
// description of what they'd add once wired. Order is roughly: highest
|
||||
// staffing-decision relevance first.
|
||||
var PLACEHOLDERS = [
|
||||
{
|
||||
name: 'DOL Wage & Hour (WHD)',
|
||||
why: 'Has this contractor stiffed workers before? WHD posts every back-wage settlement and unpaid-overtime case.',
|
||||
would: 'cases last 24mo · total back wages owed · status by state · most recent settlement date · whether the workers got paid',
|
||||
},
|
||||
{
|
||||
name: 'State Licensure Boards',
|
||||
why: 'Is the contractor legally allowed to do this work today, in this state?',
|
||||
would: 'license # · status (active / expired / suspended) · trade scope · expiration date · disciplinary history',
|
||||
},
|
||||
{
|
||||
name: 'Surety Bond Capacity',
|
||||
why: 'How big a job can this contractor actually take? Bond ceiling = upper bound on what they\'re bonded for.',
|
||||
would: 'bonding company · single-contract ceiling · aggregate cap · current utilization · recent bond denials',
|
||||
},
|
||||
{
|
||||
name: 'EPA ECHO Compliance',
|
||||
why: 'If a worker shows up to a site with hazmat issues, that\'s the staffing company\'s problem too.',
|
||||
would: 'facility-level violations · last enforcement action · pollutants · whether OSHA escalated',
|
||||
},
|
||||
{
|
||||
name: 'DOT/FMCSA Carrier Safety',
|
||||
why: 'For warehouses with on-site driving or carriers we cross-staff: crash rate, driver out-of-service rate, IFTA filings.',
|
||||
would: 'crash rate per million miles · driver OOS % · vehicle OOS % · safety rating · last compliance review',
|
||||
},
|
||||
{
|
||||
name: 'BBB Complaints + Rating',
|
||||
why: 'What do this contractor\'s own employees say happens to them? BBB aggregates complaints from workers and clients.',
|
||||
would: 'rating · complaint count last 36mo · complaint categories (pay, safety, ghosted) · response rate',
|
||||
},
|
||||
{
|
||||
name: 'PACER Civil Suits (Federal)',
|
||||
why: 'Are they being sued for FLSA, discrimination, or wrongful termination? Filings predate enforcement actions.',
|
||||
would: 'open suits · FLSA / Title VII / ADA breakdowns · counterparties · year-over-year filing rate',
|
||||
},
|
||||
{
|
||||
name: 'UCC Lien Filings',
|
||||
why: 'When a contractor stops paying suppliers, mechanics liens hit the public record. Cash-flow distress signal.',
|
||||
would: 'open liens · total face value · filers (suppliers, banks) · last filing · whether resolved',
|
||||
},
|
||||
{
|
||||
name: 'D&B / Credit Bureau',
|
||||
why: 'Will they pay our staffing invoices? D&B PAYDEX score is the standard.',
|
||||
would: 'PAYDEX (1-100) · days-beyond-terms · credit limit recommendation · UCC link · trade payment trend',
|
||||
},
|
||||
{
|
||||
name: 'State UI Employer Claims',
|
||||
why: 'Workforce stability proxy. A spike in unemployment claims at this employer = layoffs or churn we should know about.',
|
||||
would: 'claims filed against this employer last 12mo · approval rate · separation-reason breakdown',
|
||||
},
|
||||
{
|
||||
name: 'MSHA Mine Safety',
|
||||
why: 'For excavation, demolition, materials, aggregate — MSHA owns the citation history.',
|
||||
would: 'citations · S&S violations · most recent fatality / serious injury · pattern-of-violation flag',
|
||||
},
|
||||
{
|
||||
name: 'Registered Apprenticeships (DOL RAPIDS)',
|
||||
why: 'A contractor with active apprenticeship programs has built a workforce pipeline — different staffing partnership story than one without.',
|
||||
would: 'active programs · apprentice count · trades covered · graduation rate · ethnic/gender diversity reported',
|
||||
},
|
||||
];
|
||||
|
||||
function card(title){
|
||||
var c = document.createElement('div');
|
||||
c.className = 'card';
|
||||
var h = document.createElement('h3');
|
||||
h.textContent = title;
|
||||
c.appendChild(h);
|
||||
return c;
|
||||
}
|
||||
function big(c, value, sub){
|
||||
var b = document.createElement('div'); b.className='big'; b.textContent=value;
|
||||
var s = document.createElement('div'); s.className='sub'; s.textContent=sub;
|
||||
c.appendChild(b); c.appendChild(s);
|
||||
}
|
||||
function rowEl(c, label, value){
|
||||
var r = document.createElement('div'); r.className='row';
|
||||
var l = document.createElement('span'); l.className='l'; l.textContent=label;
|
||||
var v = document.createElement('span'); v.className='v'; v.textContent=value||'—';
|
||||
r.appendChild(l); r.appendChild(v); c.appendChild(r);
|
||||
}
|
||||
function empty(c, msg){
|
||||
var e = document.createElement('div'); e.className='empty'; e.textContent=msg;
|
||||
c.appendChild(e);
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
2821
mcp-server/entity.ts
Normal file
2821
mcp-server/entity.ts
Normal file
File diff suppressed because it is too large
Load Diff
123
mcp-server/icon_recipes.ts
Normal file
123
mcp-server/icon_recipes.ts
Normal file
@ -0,0 +1,123 @@
|
||||
// Visual filler iconography rendered through ComfyUI. Distinct from
|
||||
// role_scenes.ts (which renders portraits) — these are object/badge
|
||||
// style renders that fill dead space on worker cards: cert pills,
|
||||
// role-prop chips, hazard indicators, empty-state heroes.
|
||||
//
|
||||
// Layout on disk:
|
||||
// data/icons_pool/{category}/{slug}.webp
|
||||
//
|
||||
// Cache invalidation:
|
||||
// ICONS_VERSION mixes into the on-disk filename (slug includes
|
||||
// version). Bump it after editing a recipe so prior renders are
|
||||
// ignored on next view.
|
||||
|
||||
export type IconCategory = "cert" | "role_prop" | "status" | "hazard" | "empty";
|
||||
|
||||
export interface IconRecipe {
|
||||
slug: string;
|
||||
category: IconCategory;
|
||||
// Text label that appears next to / under the icon. The front-end
|
||||
// already renders this text in cert pills; the icon is supplementary.
|
||||
display: string;
|
||||
// Full diffusion prompt. Style guidance baked in. SDXL Turbo at 8
|
||||
// steps reliably produces clean macro photography, so default to
|
||||
// photographic prop shots over flat-vector illustrations (the model
|
||||
// hallucinates noise into flat-vector geometry at low step counts).
|
||||
prompt: string;
|
||||
// Negative prompt — what NOT to render. Crucial for icons because
|
||||
// SDXL likes to add hands/text/people unprompted.
|
||||
negative?: string;
|
||||
}
|
||||
|
||||
// Default negative prompt baked into every icon render unless the
|
||||
// recipe overrides. Empirically, these terms are the top SDXL Turbo
|
||||
// off-style failures.
|
||||
export const DEFAULT_NEGATIVE =
|
||||
"people, hands, faces, blurry, low quality, watermark, signature, "
|
||||
+ "logos, copyright, distorted text, garbled letters, multiple objects";
|
||||
|
||||
// TODO J — review and tune the prompts here. Each one is what diffusion
|
||||
// sees verbatim. The visual decision: photographic prop shots (macro
|
||||
// photo of an actual badge / placard / sticker) vs flat-icon vector
|
||||
// style. Default below is photographic — matches the worker headshot
|
||||
// aesthetic. Flip a recipe to flat-vector by replacing "macro photograph"
|
||||
// with "flat icon illustration on solid color background, minimal vector".
|
||||
//
|
||||
// Visual cues that work well in SDXL Turbo at 8 steps:
|
||||
// - "macro photograph", "isolated on plain background", "studio lighting"
|
||||
// - Concrete colors ("orange and black warning diamond") not adjectives
|
||||
// - Avoid: small text in the prompt (model garbles it), specific brand
|
||||
// names (creates fake logos), detailed scene composition
|
||||
const CERT_ICONS: IconRecipe[] = [
|
||||
{ slug: "osha-10", category: "cert", display: "OSHA-10",
|
||||
prompt: "macro photograph of a circular yellow safety badge with a black hard hat icon at center, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "osha-30", category: "cert", display: "OSHA-30",
|
||||
prompt: "macro photograph of a circular orange safety badge with a black hard hat icon at center, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "first-aid-cpr", category: "cert", display: "First Aid/CPR",
|
||||
prompt: "macro photograph of a small enamel pin badge featuring a bold red cross on a white circular background, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "hazmat", category: "cert", display: "Hazmat",
|
||||
prompt: "macro photograph of a HAZMAT warning placard, bold orange and black diamond shape with a flame icon, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "forklift", category: "cert", display: "Forklift",
|
||||
prompt: "macro photograph of a yellow industrial forklift safety badge with a forklift silhouette icon, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "reach-truck", category: "cert", display: "Reach Truck",
|
||||
prompt: "macro photograph of a navy blue industrial certification badge with a warehouse reach-truck silhouette icon, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "order-picker", category: "cert", display: "Order Picker",
|
||||
prompt: "macro photograph of a green industrial certification badge with a warehouse order-picker silhouette icon, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "lockout-tagout", category: "cert", display: "Lockout/Tagout",
|
||||
prompt: "macro photograph of a bright red padlock tag with a danger warning, hanging on a metal industrial valve, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "msds", category: "cert", display: "MSDS",
|
||||
prompt: "macro photograph of a folded chemical safety data sheet booklet with chemical hazard pictograms visible on cover, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "confined-space", category: "cert", display: "Confined Space",
|
||||
prompt: "macro photograph of a yellow confined space warning sign featuring a manhole entry icon, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "servsafe", category: "cert", display: "ServSafe",
|
||||
prompt: "macro photograph of a dark green food safety certification badge featuring a stylized chef hat icon, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "fire-safety", category: "cert", display: "Fire Safety",
|
||||
prompt: "macro photograph of a red enamel pin badge featuring a flame icon and a fire extinguisher silhouette, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "iso-9001", category: "cert", display: "ISO 9001",
|
||||
prompt: "macro photograph of a deep blue circular quality-management certification seal with embossed metallic ring, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
];
|
||||
|
||||
// Role-band visual chips — small icons that go in the role pill area.
|
||||
// One per band, optional inline supplement to the existing colored pill.
|
||||
const ROLE_PROP_ICONS: IconRecipe[] = [
|
||||
{ slug: "warehouse", category: "role_prop", display: "Warehouse",
|
||||
prompt: "macro photograph of a yellow hard hat with a high-visibility safety vest folded behind it, isolated on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "production", category: "role_prop", display: "Production",
|
||||
prompt: "macro photograph of a navy blue work shirt and protective safety glasses on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "trades", category: "role_prop", display: "Trades",
|
||||
prompt: "macro photograph of a leather work glove and a small adjustable wrench on a neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "driver", category: "role_prop", display: "Driver",
|
||||
prompt: "macro photograph of a navy delivery driver baseball cap and a clipboard manifest on a neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
{ slug: "lead", category: "role_prop", display: "Lead",
|
||||
prompt: "macro photograph of a tablet showing a bar chart and a high-vis vest folded beside it on neutral grey backdrop, photorealistic, sharp focus, studio lighting" },
|
||||
];
|
||||
|
||||
export const ICONS: Record<string, IconRecipe> = Object.fromEntries(
|
||||
[...CERT_ICONS, ...ROLE_PROP_ICONS].map((r) => [`${r.category}/${r.slug}`, r]),
|
||||
);
|
||||
|
||||
// v2 — 256×256 canvas, intended to be displayed monochrome via CSS
|
||||
// `filter: grayscale(1)`. Smaller canvas, tighter crops, crisper at
|
||||
// 14px display size.
|
||||
export const ICONS_VERSION = "v2";
|
||||
|
||||
// Map a free-form cert string from the data ("First Aid/CPR",
|
||||
// "OSHA-10", "Lockout/Tagout") to the canonical slug used here.
|
||||
// Returns null if no recipe matches.
|
||||
export function certToSlug(cert: string): string | null {
|
||||
const c = (cert || "").trim().toLowerCase().replace(/\s+/g, "-");
|
||||
if (c === "osha-10") return "osha-10";
|
||||
if (c === "osha-30") return "osha-30";
|
||||
if (c.startsWith("first") || c.includes("cpr")) return "first-aid-cpr";
|
||||
if (c === "hazmat" || c.startsWith("hazwoper")) return "hazmat";
|
||||
if (c === "forklift" || c.startsWith("pit")) return "forklift";
|
||||
if (c.startsWith("reach")) return "reach-truck";
|
||||
if (c.startsWith("order")) return "order-picker";
|
||||
if (c.startsWith("lockout") || c.includes("tagout")) return "lockout-tagout";
|
||||
if (c === "msds" || c.startsWith("ghs")) return "msds";
|
||||
if (c.startsWith("confined")) return "confined-space";
|
||||
if (c === "servsafe") return "servsafe";
|
||||
if (c.startsWith("fire")) return "fire-safety";
|
||||
if (c.startsWith("iso")) return "iso-9001";
|
||||
return null;
|
||||
}
|
||||
1101
mcp-server/index.ts
1101
mcp-server/index.ts
File diff suppressed because it is too large
Load Diff
599
mcp-server/profiler.html
Normal file
599
mcp-server/profiler.html
Normal file
@ -0,0 +1,599 @@
|
||||
<!DOCTYPE html>
|
||||
<html><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Profiler Index · Staffing Co-Pilot</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
<style>
|
||||
*{margin:0;padding:0;box-sizing:border-box}
|
||||
html,body{overflow-x:hidden}
|
||||
body{font-family:'Inter',-apple-system,system-ui,sans-serif;background:#090c10;color:#b0b8c4;font-size:14px;line-height:1.6}
|
||||
.bar{background:#0d1117;padding:0 24px;height:56px;border-bottom:1px solid #171d27;display:flex;justify-content:space-between;align-items:center}
|
||||
.bar h1{font-size:14px;font-weight:600;color:#e6edf3}
|
||||
.bar nav a{color:#545d68;text-decoration:none;font-size:12px;padding:6px 14px;border-radius:6px;margin-left:4px}
|
||||
.bar nav a:hover{color:#e6edf3;background:#161b22}
|
||||
.content{max-width:1200px;margin:0 auto;padding:24px 20px 40px}
|
||||
.controls{background:#0d1117;border:1px solid #171d27;border-radius:10px;padding:16px;margin-bottom:14px;display:flex;gap:10px;align-items:center;flex-wrap:wrap}
|
||||
.controls input,.controls select{padding:9px 12px;background:#161b22;border:1px solid #21262d;border-radius:6px;color:#e6edf3;font-size:13px;outline:none}
|
||||
.controls input:focus,.controls select:focus{border-color:#388bfd}
|
||||
.controls input.s{flex:1;min-width:240px}
|
||||
.controls .meta{font-size:11px;color:#8b949e;margin-left:auto}
|
||||
.summary{background:#0d1117;border:1px solid #171d27;border-radius:10px;padding:14px 16px;margin-bottom:14px;font-size:12px;color:#8b949e}
|
||||
.summary b{color:#e6edf3;font-weight:600}
|
||||
table{width:100%;border-collapse:collapse;background:#0d1117;border:1px solid #171d27;border-radius:10px;overflow:hidden}
|
||||
th{font-size:10px;color:#545d68;text-transform:uppercase;letter-spacing:1.2px;font-weight:600;text-align:left;padding:12px;background:#0a0d12;border-bottom:1px solid #171d27;cursor:pointer;user-select:none}
|
||||
th:hover{color:#e6edf3}
|
||||
th .arrow{font-size:9px;margin-left:4px;color:#388bfd}
|
||||
td{padding:11px 12px;border-bottom:1px solid #1f2631;font-size:13px}
|
||||
tr:last-child td{border-bottom:none}
|
||||
tr:hover td{background:#0a0d12}
|
||||
td.name a{color:#58a6ff;text-decoration:none;font-weight:600}
|
||||
td.name a:hover{text-decoration:underline}
|
||||
td.right{text-align:right;font-family:ui-monospace,monospace;font-variant-numeric:tabular-nums}
|
||||
td.role{font-size:10px;color:#8b949e}
|
||||
td.role .pill{display:inline-block;padding:2px 7px;border-radius:9px;font-size:9px;font-weight:600;background:#161b22;border:1px solid #21262d;color:#8b949e;margin-right:4px;text-transform:uppercase;letter-spacing:0.5px}
|
||||
.tickers{display:flex;gap:4px;flex-wrap:wrap;margin-top:3px}
|
||||
.ticker-pill{display:inline-block;padding:1px 7px;border-radius:5px;font-size:10px;font-weight:700;font-family:ui-monospace,SFMono-Regular,monospace;letter-spacing:0.3px;cursor:help}
|
||||
.ticker-pill.direct{background:#0d2818;border:1px solid #2ea04388;color:#3fb950}
|
||||
.ticker-pill.parent{background:#1a1410;border:1px solid #d2992288;color:#d29922}
|
||||
.ticker-pill.associated{background:#0d1830;border:1px solid #58a6ff66;color:#58a6ff}
|
||||
.ticker-pill.exact{background:#0d2818;border:1px solid #2ea043;color:#3fb950}
|
||||
|
||||
/* Hero — the thesis panel that frames the data corpus's value. */
|
||||
.thesis{background:linear-gradient(135deg,#0d2818 0%,#0d1830 50%,#1a1410 100%);border:1px solid #2ea04344;border-radius:12px;padding:18px 22px;margin-bottom:14px;position:relative;overflow:hidden}
|
||||
.thesis::before{content:'';position:absolute;top:0;left:0;right:0;height:2px;background:linear-gradient(90deg,#3fb950 0%,#58a6ff 50%,#d29922 100%)}
|
||||
.thesis h2{font-size:18px;color:#e6edf3;font-weight:700;letter-spacing:-0.4px;margin-bottom:6px}
|
||||
.thesis .sub{font-size:12px;color:#8b949e;line-height:1.6;margin-bottom:14px;max-width:880px}
|
||||
.thesis .sub b{color:#3fb950;font-weight:600}
|
||||
.bai-row{display:flex;gap:24px;align-items:baseline;flex-wrap:wrap;margin-bottom:14px}
|
||||
.bai-block{display:flex;flex-direction:column;gap:2px}
|
||||
.bai-label{font-size:9px;color:#545d68;text-transform:uppercase;letter-spacing:1.4px;font-weight:700}
|
||||
.bai-value{font-size:26px;font-weight:700;color:#e6edf3;font-family:ui-monospace,monospace;letter-spacing:-0.5px;font-variant-numeric:tabular-nums}
|
||||
.bai-value.up{color:#3fb950}
|
||||
.bai-value.down{color:#f85149}
|
||||
.bai-sub{font-size:10px;color:#8b949e;margin-top:1px}
|
||||
.markets-strip{display:flex;gap:6px;flex-wrap:wrap;font-size:10px}
|
||||
.market-pill{padding:3px 9px;border-radius:9px;font-weight:600;border:1px solid;letter-spacing:0.4px}
|
||||
.market-pill.live{background:#0d2818;border-color:#3fb950;color:#3fb950}
|
||||
.market-pill.next{background:#0d1830;border-color:#58a6ff;color:#58a6ff}
|
||||
.market-pill.queue{background:#161b22;border-color:#21262d;color:#545d68}
|
||||
.market-pill.queue::before{content:'· '}
|
||||
|
||||
/* Map panel below basket — populates when a ticker is selected. */
|
||||
.signal-map-wrap{display:none;background:#0d1117;border:1px solid #171d27;border-radius:10px;padding:14px;margin-bottom:14px}
|
||||
.signal-map-wrap.active{display:block}
|
||||
.signal-map-header{display:flex;justify-content:space-between;align-items:baseline;margin-bottom:10px}
|
||||
.signal-map-title{font-size:11px;color:#545d68;text-transform:uppercase;letter-spacing:1.2px;font-weight:600}
|
||||
.signal-map-title b{color:#58a6ff;font-family:ui-monospace,monospace}
|
||||
.signal-map-meta{font-size:11px;color:#8b949e}
|
||||
.signal-map{height:340px;border-radius:8px;border:1px solid #1f2631;overflow:hidden}
|
||||
.signal-map .leaflet-container{background:#0a0d12}
|
||||
|
||||
/* Scrolling ticker basket — top strip showing every public issuer
|
||||
the profiler index has surfaced, with live price + day-change. */
|
||||
.basket-wrap{background:#0a0d12;border:1px solid #171d27;border-radius:10px;margin-bottom:14px;overflow:hidden;position:relative}
|
||||
.basket-label{padding:10px 16px 4px;font-size:10px;color:#545d68;text-transform:uppercase;letter-spacing:1.3px;font-weight:600;display:flex;justify-content:space-between;align-items:baseline}
|
||||
.basket-label .meta{font-weight:400;color:#3d444d;font-size:10px;text-transform:none;letter-spacing:0}
|
||||
.basket-track{display:flex;gap:0;overflow-x:auto;scroll-behavior:smooth;padding:6px 8px 12px;scrollbar-width:thin;scrollbar-color:#21262d transparent}
|
||||
.basket-track::-webkit-scrollbar{height:6px}
|
||||
.basket-track::-webkit-scrollbar-thumb{background:#21262d;border-radius:3px}
|
||||
.basket-track::-webkit-scrollbar-thumb:hover{background:#388bfd}
|
||||
.bk-card{flex:0 0 auto;min-width:140px;background:#0d1117;border:1px solid #21262d;border-radius:8px;padding:10px 12px;margin:0 4px;cursor:pointer;transition:all 0.12s;position:relative}
|
||||
.bk-card:hover{border-color:#58a6ff;background:#0d1a30;transform:translateY(-1px)}
|
||||
.bk-card.selected{border-color:#58a6ff;background:#0d1a30;box-shadow:0 0 0 1px #58a6ff;}
|
||||
.bk-card .tk{font-family:ui-monospace,SFMono-Regular,monospace;font-size:13px;font-weight:700;color:#e6edf3;letter-spacing:0.3px}
|
||||
.bk-card .px{font-family:ui-monospace,SFMono-Regular,monospace;font-size:14px;font-weight:600;color:#e6edf3;margin-top:3px;font-variant-numeric:tabular-nums}
|
||||
.bk-card .ch{font-family:ui-monospace,monospace;font-size:11px;margin-top:1px;font-variant-numeric:tabular-nums}
|
||||
.bk-card .ch.up{color:#3fb950}
|
||||
.bk-card .ch.down{color:#f85149}
|
||||
.bk-card .ch.flat{color:#545d68}
|
||||
.bk-card .meta{font-size:9px;color:#545d68;margin-top:5px;text-transform:uppercase;letter-spacing:0.6px}
|
||||
.bk-card .kind-bar{position:absolute;left:0;top:0;bottom:0;width:3px;border-radius:8px 0 0 8px}
|
||||
.bk-card .kind-bar.exact,.bk-card .kind-bar.direct{background:#3fb950}
|
||||
.bk-card .kind-bar.parent{background:#d29922}
|
||||
.bk-card .kind-bar.associated{background:#58a6ff}
|
||||
.bk-card .kind-bar.mixed{background:linear-gradient(180deg,#3fb950 0%,#58a6ff 100%)}
|
||||
.bk-card.no-quote .px{color:#545d68}
|
||||
.basket-empty{padding:18px;font-size:11px;color:#545d68;font-style:italic;text-align:center}
|
||||
.basket-clear{margin-left:8px;font-size:10px;color:#58a6ff;cursor:pointer;border:none;background:none;text-decoration:underline}
|
||||
.cost-band-1{color:#3fb950}
|
||||
.cost-band-2{color:#d29922}
|
||||
.cost-band-3{color:#f85149}
|
||||
.loading{text-align:center;padding:60px;font-size:13px;color:#3d444d}
|
||||
.empty{text-align:center;padding:40px;font-size:12px;color:#545d68;font-style:italic}
|
||||
.foot{margin-top:14px;font-size:10px;color:#484f58;line-height:1.6}
|
||||
@media(max-width:640px){.bar{padding:0 14px}.content{padding:14px}th,td{padding:8px 6px;font-size:11px}}
|
||||
</style>
|
||||
</head><body>
|
||||
<div class="bar">
|
||||
<h1>Staffing Co-Pilot · Profiler Index</h1>
|
||||
<nav>
|
||||
<a href="" id="back-dashboard">← Dashboard</a>
|
||||
<a href="" id="back-console">Console</a>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="content">
|
||||
<!-- Hero thesis — frames what this data corpus actually is. The
|
||||
profiler index isn't just a contractor directory; it's a
|
||||
construction-activity signal that surfaces public issuers months
|
||||
before quarterly earnings does. Each metric here is computed
|
||||
from the live data, not pre-baked. -->
|
||||
<div class="thesis" id="thesis">
|
||||
<h2>Chicago Construction Activity Signal Engine</h2>
|
||||
<div class="sub">
|
||||
Every contractor name in this corpus is also a forward indicator on the public equities they touch. Permits filed today predict construction starts ~45 days out, staffing windows ~2 weeks before that, and revenue recognition months later. The associated-ticker network surfaces this signal <b>before</b> it lands in any 10-Q.
|
||||
</div>
|
||||
<div class="bai-row">
|
||||
<div class="bai-block">
|
||||
<span class="bai-label">Building Activity Index — today</span>
|
||||
<span class="bai-value" id="bai-value">—</span>
|
||||
<span class="bai-sub" id="bai-sub">awaiting basket prices</span>
|
||||
</div>
|
||||
<div class="bai-block">
|
||||
<span class="bai-label">Indexed build value</span>
|
||||
<span class="bai-value" id="bav-value">—</span>
|
||||
<span class="bai-sub" id="bav-sub">across surfaced issuers</span>
|
||||
</div>
|
||||
<div class="bai-block">
|
||||
<span class="bai-label">Network depth</span>
|
||||
<span class="bai-value" id="net-value">—</span>
|
||||
<span class="bai-sub" id="net-sub">issuers · attributions</span>
|
||||
</div>
|
||||
<div class="bai-block" style="flex:1;min-width:240px">
|
||||
<span class="bai-label">Market replication roadmap</span>
|
||||
<div class="markets-strip" style="margin-top:4px">
|
||||
<span class="market-pill live">Chicago — live</span>
|
||||
<span class="market-pill next">NYC DOB — adapter ready</span>
|
||||
<span class="market-pill queue">LA County · Houston BCD · Boston ISD · DC DCRA</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="basket-wrap" id="basket-wrap" style="display:none">
|
||||
<div class="basket-label">
|
||||
<span><span id="bk-count">0</span> public issuers in this view <span class="meta" id="bk-meta"></span></span>
|
||||
<button class="basket-clear" id="bk-clear" style="display:none" type="button">clear filter</button>
|
||||
</div>
|
||||
<div class="basket-track" id="basket"></div>
|
||||
</div>
|
||||
|
||||
<!-- Per-ticker permit map — shows where the selected issuer's
|
||||
attributed contractor activity is actually happening. Same
|
||||
leaflet pattern as the contractor profile, scoped to one ticker. -->
|
||||
<div class="signal-map-wrap" id="signal-map-wrap">
|
||||
<div class="signal-map-header">
|
||||
<span class="signal-map-title">Where <b id="signal-map-ticker">—</b> activity is happening</span>
|
||||
<span class="signal-map-meta" id="signal-map-meta">—</span>
|
||||
</div>
|
||||
<div class="signal-map" id="signal-map"></div>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<input class="s" id="q" type="text" placeholder="Filter by contractor name (e.g., Target, Turner)" autocomplete="off">
|
||||
<select id="since">
|
||||
<option value="2025-06-01">Since June 2025</option>
|
||||
<option value="2024-01-01">Since 2024</option>
|
||||
<option value="2020-01-01">Since 2020 (deeper history)</option>
|
||||
</select>
|
||||
<select id="min-cost">
|
||||
<option value="500000">$500K+</option>
|
||||
<option value="250000" selected>$250K+</option>
|
||||
<option value="100000">$100K+</option>
|
||||
<option value="50000">$50K+</option>
|
||||
</select>
|
||||
<span class="meta" id="meta">Loading…</span>
|
||||
</div>
|
||||
<div class="summary" id="summary" style="display:none"></div>
|
||||
<div id="result"><div class="loading">Loading the directory from Chicago Socrata…</div></div>
|
||||
<div class="foot">Aggregations sourced live from data.cityofchicago.org (Building Permits dataset ydr8-5enu). Contractor names appear when listed as contact_1 or contact_2 on a permit. Click any name to open the full profile — heat map, project index, history, 12 awaiting public-data sources.</div>
|
||||
</div>
|
||||
<script>
|
||||
var P=location.pathname.indexOf('/lakehouse')>=0?'/lakehouse':'';
|
||||
document.getElementById('back-dashboard').href = P+'/';
|
||||
document.getElementById('back-console').href = P+'/console';
|
||||
|
||||
var sortKey='total_cost', sortDir='desc';
|
||||
var lastRows=[];
|
||||
var tickerFilter=null; // selected ticker for filtering the table
|
||||
var lastQuotes={}; // ticker → quote (price, day_change_pct)
|
||||
var lastBasket=[]; // basket rows aggregated from lastRows
|
||||
var signalMap=null; // leaflet map instance for the per-ticker view
|
||||
|
||||
function clearChildren(el){ while(el.firstChild) el.removeChild(el.firstChild); }
|
||||
function fmt$(n){
|
||||
if(n>=1e9) return '$'+(n/1e9).toFixed(2)+'B';
|
||||
if(n>=1e6) return '$'+(n/1e6).toFixed(1)+'M';
|
||||
if(n>=1e3) return '$'+(n/1e3).toFixed(0)+'K';
|
||||
return '$'+Math.round(n||0).toLocaleString();
|
||||
}
|
||||
function costClass(n){
|
||||
if(n>=1e7) return 'cost-band-3';
|
||||
if(n>=1e6) return 'cost-band-2';
|
||||
return 'cost-band-1';
|
||||
}
|
||||
|
||||
function load(){
|
||||
var search=document.getElementById('q').value.trim();
|
||||
var since=document.getElementById('since').value;
|
||||
var minCost=parseInt(document.getElementById('min-cost').value,10);
|
||||
document.getElementById('meta').textContent='Loading…';
|
||||
var host=document.getElementById('result'); clearChildren(host);
|
||||
var loading=document.createElement('div'); loading.className='loading';
|
||||
loading.textContent='Aggregating from Chicago Socrata…';
|
||||
host.appendChild(loading);
|
||||
|
||||
fetch(P+'/intelligence/profiler_index',{
|
||||
method:'POST',
|
||||
headers:{'Content-Type':'application/json'},
|
||||
body:JSON.stringify({since:since,min_cost:minCost,search:search,limit:200})
|
||||
}).then(function(r){return r.json()}).then(function(d){
|
||||
lastRows = d.contractors||[];
|
||||
document.getElementById('meta').textContent=lastRows.length+' contractors · '+(d.duration_ms||0)+'ms';
|
||||
// Build the ticker basket from the surfaced rows
|
||||
buildBasket();
|
||||
var totalCost = lastRows.reduce(function(s,r){return s+(r.total_cost||0)},0);
|
||||
var totalPermits = lastRows.reduce(function(s,r){return s+(r.permits||0)},0);
|
||||
var sumDiv=document.getElementById('summary');
|
||||
sumDiv.style.display='block';
|
||||
clearChildren(sumDiv);
|
||||
var b1=document.createElement('b'); b1.textContent=lastRows.length.toLocaleString();
|
||||
sumDiv.appendChild(b1);
|
||||
sumDiv.appendChild(document.createTextNode(' contractors · '));
|
||||
var b2=document.createElement('b'); b2.textContent=totalPermits.toLocaleString();
|
||||
sumDiv.appendChild(b2);
|
||||
sumDiv.appendChild(document.createTextNode(' total permits · '));
|
||||
var b3=document.createElement('b'); b3.textContent=fmt$(totalCost);
|
||||
sumDiv.appendChild(b3);
|
||||
sumDiv.appendChild(document.createTextNode(' aggregate value · since '+(d.since||'?')+' · min permit cost '+fmt$(d.min_cost||0)));
|
||||
render();
|
||||
}).catch(function(e){
|
||||
document.getElementById('meta').textContent='error';
|
||||
var host=document.getElementById('result'); clearChildren(host);
|
||||
var er=document.createElement('div'); er.className='empty'; er.style.color='#f85149';
|
||||
er.textContent='Profiler index error: '+e.message;
|
||||
host.appendChild(er);
|
||||
});
|
||||
}
|
||||
|
||||
// Aggregate every public ticker the profiler index surfaced, with a
|
||||
// kind hierarchy (exact > direct > parent > associated) and the count
|
||||
// of contractors each ticker is attributed to. Then fetch live quotes
|
||||
// in one batch and render the scrolling basket.
|
||||
function buildBasket(){
|
||||
var byTicker = {};
|
||||
lastRows.forEach(function(r){
|
||||
var ts = (r.tickers && r.tickers.direct ? r.tickers.direct : []).concat(r.tickers && r.tickers.associated ? r.tickers.associated : []);
|
||||
ts.forEach(function(t){
|
||||
if(!t || !t.ticker) return;
|
||||
if(!byTicker[t.ticker]) byTicker[t.ticker] = {ticker:t.ticker, kinds:new Set(), count:0, contractors:[], matched_name:t.matched_name||t.partner_name||null};
|
||||
byTicker[t.ticker].kinds.add(t.via);
|
||||
byTicker[t.ticker].count++;
|
||||
if(byTicker[t.ticker].contractors.length < 5) byTicker[t.ticker].contractors.push(r.name);
|
||||
});
|
||||
});
|
||||
var basketRows = Object.values(byTicker)
|
||||
.map(function(b){
|
||||
// Pick a single 'kind' for the bar color: direct/exact wins, then parent, then associated.
|
||||
var k = b.kinds.has('exact')?'exact':b.kinds.has('direct')?'direct':b.kinds.has('parent')?'parent':b.kinds.has('associated')?'associated':'mixed';
|
||||
if(b.kinds.size>1 && (b.kinds.has('exact')||b.kinds.has('direct')) && b.kinds.has('associated')) k='mixed';
|
||||
return Object.assign({}, b, {kinds:Array.from(b.kinds), kind:k});
|
||||
})
|
||||
.sort(function(a,b){return b.count - a.count});
|
||||
var wrap = document.getElementById('basket-wrap');
|
||||
var track = document.getElementById('basket');
|
||||
clearChildren(track);
|
||||
if(!basketRows.length){
|
||||
wrap.style.display='block';
|
||||
var emp=document.createElement('div'); emp.className='basket-empty';
|
||||
emp.textContent='No public issuers in this view. Try a wider filter or "since 2020" history.';
|
||||
track.appendChild(emp);
|
||||
document.getElementById('bk-count').textContent='0';
|
||||
document.getElementById('bk-meta').textContent='';
|
||||
return;
|
||||
}
|
||||
wrap.style.display='block';
|
||||
document.getElementById('bk-count').textContent=basketRows.length;
|
||||
document.getElementById('bk-meta').textContent='loading prices…';
|
||||
// Render shells immediately, then fill in prices when the batch returns
|
||||
basketRows.forEach(function(b){
|
||||
var card=document.createElement('div'); card.className='bk-card no-quote';
|
||||
card.dataset.ticker=b.ticker;
|
||||
var bar=document.createElement('div'); bar.className='kind-bar '+b.kind; card.appendChild(bar);
|
||||
var tk=document.createElement('div'); tk.className='tk'; tk.textContent=b.ticker; card.appendChild(tk);
|
||||
var px=document.createElement('div'); px.className='px'; px.textContent='—'; card.appendChild(px);
|
||||
var ch=document.createElement('div'); ch.className='ch flat'; ch.textContent=' '; card.appendChild(ch);
|
||||
var meta=document.createElement('div'); meta.className='meta';
|
||||
meta.textContent=b.count+' attribution'+(b.count===1?'':'s')+' · '+b.kinds.join('+');
|
||||
card.appendChild(meta);
|
||||
card.title=(b.matched_name||b.ticker)+'\n'+b.contractors.slice(0,5).join('\n')+(b.count>5?'\n…':'');
|
||||
card.onclick=function(){
|
||||
tickerFilter = (tickerFilter===b.ticker) ? null : b.ticker;
|
||||
Array.prototype.forEach.call(track.children, function(c){
|
||||
c.classList.toggle('selected', c.dataset && c.dataset.ticker===tickerFilter);
|
||||
});
|
||||
document.getElementById('bk-clear').style.display = tickerFilter ? 'inline' : 'none';
|
||||
showSignalMap(tickerFilter);
|
||||
render();
|
||||
};
|
||||
track.appendChild(card);
|
||||
});
|
||||
lastBasket = basketRows;
|
||||
// Update the hero panel right away with what we know without prices
|
||||
updateThesisMetrics();
|
||||
// Batch-fetch quotes and update each card + thesis
|
||||
fetch(P+'/intelligence/ticker_quotes',{
|
||||
method:'POST',headers:{'Content-Type':'application/json'},
|
||||
body:JSON.stringify({tickers:basketRows.map(function(b){return b.ticker})})
|
||||
}).then(function(r){return r.json()}).then(function(qd){
|
||||
var quotes=qd.quotes||{};
|
||||
lastQuotes = quotes;
|
||||
document.getElementById('bk-meta').textContent='quotes via Stooq · '+(qd.duration_ms||0)+'ms';
|
||||
Array.prototype.forEach.call(track.children, function(card){
|
||||
var t=card.dataset.ticker; var q=quotes[t];
|
||||
if(!q || !q.price) return;
|
||||
card.classList.remove('no-quote');
|
||||
var px=card.querySelector('.px'); px.textContent='$'+q.price.toFixed(2);
|
||||
var ch=card.querySelector('.ch');
|
||||
if(q.day_change_pct==null){ ch.textContent='close '+(q.price_date||''); ch.className='ch flat'; }
|
||||
else if(q.day_change_pct>=0){ ch.textContent='+'+q.day_change_pct.toFixed(2)+'%'; ch.className='ch up'; }
|
||||
else { ch.textContent=q.day_change_pct.toFixed(2)+'%'; ch.className='ch down'; }
|
||||
});
|
||||
updateThesisMetrics();
|
||||
}).catch(function(){
|
||||
document.getElementById('bk-meta').textContent='quote fetch failed';
|
||||
});
|
||||
}
|
||||
|
||||
// Compute the Building Activity Index and update the hero panel.
|
||||
// BAI = attribution-weighted day-change % across surfaced issuers.
|
||||
// "Indexed build value" = total dollars of permits attributable to
|
||||
// any public issuer in this view (sum across attributing contractors).
|
||||
// "Network depth" = issuer count + total attributions.
|
||||
function updateThesisMetrics(){
|
||||
if(!lastBasket.length){
|
||||
document.getElementById('bai-value').textContent='—';
|
||||
document.getElementById('bai-sub').textContent='awaiting basket data';
|
||||
return;
|
||||
}
|
||||
// BAI: weighted average of day_change_pct, weight = attribution count.
|
||||
var weightedSum=0, weightTotal=0, contributors=[];
|
||||
lastBasket.forEach(function(b){
|
||||
var q = lastQuotes[b.ticker];
|
||||
if(q && q.day_change_pct!=null){
|
||||
var w = b.count || 1;
|
||||
weightedSum += q.day_change_pct * w;
|
||||
weightTotal += w;
|
||||
contributors.push({ticker:b.ticker, day:q.day_change_pct, weight:w});
|
||||
}
|
||||
});
|
||||
var bai = weightTotal>0 ? (weightedSum/weightTotal) : null;
|
||||
var baiEl = document.getElementById('bai-value');
|
||||
var baiSub = document.getElementById('bai-sub');
|
||||
if(bai==null){
|
||||
baiEl.textContent='—'; baiSub.textContent='no quotes settled yet';
|
||||
baiEl.className='bai-value';
|
||||
} else {
|
||||
var sign = bai>=0 ? '+' : '';
|
||||
baiEl.textContent = sign + bai.toFixed(2) + '%';
|
||||
baiEl.className = 'bai-value ' + (bai>=0?'up':'down');
|
||||
contributors.sort(function(a,b){return Math.abs(b.day*b.weight) - Math.abs(a.day*a.weight)});
|
||||
var top = contributors.slice(0,3).map(function(c){return c.ticker+' '+(c.day>=0?'+':'')+c.day.toFixed(1)+'%'}).join(' · ');
|
||||
baiSub.textContent = contributors.length+' issuers contributing · top: '+top;
|
||||
}
|
||||
// Indexed build value
|
||||
var totalCost = 0;
|
||||
lastRows.forEach(function(r){
|
||||
var ts=(r.tickers&&r.tickers.direct?r.tickers.direct:[]).concat(r.tickers&&r.tickers.associated?r.tickers.associated:[]);
|
||||
if(ts.length>0) totalCost += (r.total_cost||0);
|
||||
});
|
||||
var bav = totalCost>=1e9 ? '$'+(totalCost/1e9).toFixed(2)+'B' : totalCost>=1e6 ? '$'+(totalCost/1e6).toFixed(0)+'M' : '$'+Math.round(totalCost/1e3)+'K';
|
||||
document.getElementById('bav-value').textContent = bav;
|
||||
document.getElementById('bav-sub').textContent = lastBasket.length+' issuers in scope';
|
||||
// Network depth
|
||||
var totalAttrib = lastBasket.reduce(function(s,b){return s + (b.count||0)},0);
|
||||
document.getElementById('net-value').textContent = lastBasket.length + ' / ' + totalAttrib;
|
||||
document.getElementById('net-sub').textContent = 'issuers / attribution edges';
|
||||
}
|
||||
|
||||
// Per-ticker map: when a ticker is selected, plot the contractor
|
||||
// permit locations attributed to that ticker. Pulls lat/lng for each
|
||||
// attributed contractor from the contractor profile endpoint and
|
||||
// merges. Caches per-ticker so toggling is instant.
|
||||
var mapCache = {};
|
||||
function showSignalMap(ticker){
|
||||
var wrap=document.getElementById('signal-map-wrap');
|
||||
if(!ticker){ wrap.classList.remove('active'); if(signalMap){signalMap.remove(); signalMap=null;} return; }
|
||||
wrap.classList.add('active');
|
||||
document.getElementById('signal-map-ticker').textContent = ticker;
|
||||
document.getElementById('signal-map-meta').textContent = 'loading permits…';
|
||||
// Find the contractors attributed to this ticker
|
||||
var attrib = lastRows.filter(function(r){
|
||||
var ts=(r.tickers&&r.tickers.direct?r.tickers.direct:[]).concat(r.tickers&&r.tickers.associated?r.tickers.associated:[]);
|
||||
return ts.some(function(t){return t.ticker===ticker});
|
||||
});
|
||||
if(!attrib.length){
|
||||
document.getElementById('signal-map-meta').textContent='no attributed contractors';
|
||||
return;
|
||||
}
|
||||
// Use the contractor_profile endpoint per attributed contractor (cap at 6)
|
||||
// to pull their geocoded permits, then render. Cached per ticker.
|
||||
if(mapCache[ticker]){
|
||||
drawSignalMap(ticker, mapCache[ticker]);
|
||||
return;
|
||||
}
|
||||
var names = attrib.slice(0,6).map(function(r){return r.name});
|
||||
Promise.all(names.map(function(n){
|
||||
return fetch(P+'/intelligence/contractor_profile',{
|
||||
method:'POST',headers:{'Content-Type':'application/json'},
|
||||
body:JSON.stringify({name:n})
|
||||
}).then(function(r){return r.json()}).then(function(d){
|
||||
var perms = (d.history && d.history.recent_permits) || [];
|
||||
return perms.filter(function(p){return p.lat&&p.lng}).map(function(p){
|
||||
return Object.assign({contractor:n}, p);
|
||||
});
|
||||
}).catch(function(){return []});
|
||||
})).then(function(arrs){
|
||||
var all = arrs.reduce(function(a,b){return a.concat(b)},[]);
|
||||
mapCache[ticker] = all;
|
||||
drawSignalMap(ticker, all);
|
||||
});
|
||||
}
|
||||
function drawSignalMap(ticker, permits){
|
||||
if(signalMap){ signalMap.remove(); signalMap=null; }
|
||||
if(!permits.length){
|
||||
document.getElementById('signal-map-meta').textContent='0 geocoded permits across attributed contractors';
|
||||
return;
|
||||
}
|
||||
document.getElementById('signal-map-meta').textContent = permits.length + ' geocoded permits across ' + new Set(permits.map(function(p){return p.contractor})).size + ' contractors';
|
||||
signalMap = L.map('signal-map',{zoomControl:true, attributionControl:false}).setView([41.88,-87.63], 11);
|
||||
L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png',{maxZoom:19}).addTo(signalMap);
|
||||
var bounds=[];
|
||||
var maxCost = Math.max.apply(null, permits.map(function(p){return Number(p.cost)||1}));
|
||||
permits.forEach(function(p){
|
||||
var c=Number(p.cost)||0;
|
||||
var radius = 4 + (c/maxCost)*14;
|
||||
var color = c>=1000000?'#f85149':c>=100000?'#d29922':'#3fb950';
|
||||
var marker = L.circleMarker([p.lat,p.lng],{radius:radius,color:color,weight:1,fillOpacity:0.55});
|
||||
var pop=document.createElement('div');
|
||||
pop.style.cssText='font-family:ui-monospace,monospace;font-size:11px;color:#0a0d12;min-width:200px';
|
||||
var top=document.createElement('div'); top.style.cssText='font-weight:700;margin-bottom:3px;color:#1f6feb';
|
||||
top.textContent=ticker+' attribution';
|
||||
pop.appendChild(top);
|
||||
var con=document.createElement('div'); con.textContent=p.contractor; con.style.fontWeight='600';
|
||||
pop.appendChild(con);
|
||||
var meta=document.createElement('div'); meta.style.color='#545d68';
|
||||
meta.textContent='$'+c.toLocaleString()+' · '+(p.date||'?')+' · '+(p.work_type||'?');
|
||||
pop.appendChild(meta);
|
||||
var addr=document.createElement('div'); addr.style.color='#545d68';
|
||||
addr.textContent=p.address||'?';
|
||||
pop.appendChild(addr);
|
||||
marker.bindPopup(pop);
|
||||
marker.addTo(signalMap);
|
||||
bounds.push([p.lat,p.lng]);
|
||||
});
|
||||
if(bounds.length>1) signalMap.fitBounds(bounds,{padding:[28,28]});
|
||||
}
|
||||
|
||||
function render(){
|
||||
var host=document.getElementById('result');
|
||||
clearChildren(host);
|
||||
// Apply ticker filter if set: keep only rows whose tickers include the selected one
|
||||
var pool = tickerFilter ? lastRows.filter(function(r){
|
||||
var ts=(r.tickers&&r.tickers.direct?r.tickers.direct:[]).concat(r.tickers&&r.tickers.associated?r.tickers.associated:[]);
|
||||
return ts.some(function(t){return t.ticker===tickerFilter});
|
||||
}) : lastRows;
|
||||
if(!pool.length){
|
||||
var emp=document.createElement('div'); emp.className='empty';
|
||||
emp.textContent='No contractors match the current filter.';
|
||||
host.appendChild(emp);
|
||||
return;
|
||||
}
|
||||
var rows = pool.slice().sort(function(a,b){
|
||||
var av=a[sortKey], bv=b[sortKey];
|
||||
if(typeof av==='string'){ av=(av||'').toUpperCase(); bv=(bv||'').toUpperCase(); }
|
||||
if(av<bv) return sortDir==='asc'?-1:1;
|
||||
if(av>bv) return sortDir==='asc'?1:-1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
var t=document.createElement('table');
|
||||
var thead=document.createElement('thead'); var hr=document.createElement('tr');
|
||||
var cols=[
|
||||
{k:'name', label:'Contractor'},
|
||||
{k:'permits', label:'Permits', right:true},
|
||||
{k:'total_cost', label:'Total Value', right:true},
|
||||
{k:'last_filed', label:'Last Filed', right:true},
|
||||
{k:'roles', label:'Listed As'},
|
||||
];
|
||||
cols.forEach(function(c){
|
||||
var h=document.createElement('th');
|
||||
h.textContent=c.label;
|
||||
if(c.right) h.style.textAlign='right';
|
||||
if(sortKey===c.k){
|
||||
var ar=document.createElement('span'); ar.className='arrow';
|
||||
ar.textContent = sortDir==='asc' ? '▲' : '▼';
|
||||
h.appendChild(ar);
|
||||
}
|
||||
h.onclick=function(){
|
||||
if(sortKey===c.k) sortDir = sortDir==='asc' ? 'desc' : 'asc';
|
||||
else { sortKey=c.k; sortDir = (c.k==='name') ? 'asc' : 'desc'; }
|
||||
render();
|
||||
};
|
||||
hr.appendChild(h);
|
||||
});
|
||||
thead.appendChild(hr); t.appendChild(thead);
|
||||
|
||||
var tb=document.createElement('tbody');
|
||||
rows.forEach(function(r){
|
||||
var tr=document.createElement('tr');
|
||||
var ntd=document.createElement('td'); ntd.className='name';
|
||||
var a=document.createElement('a');
|
||||
a.href = P+'/contractor?name='+encodeURIComponent(r.name);
|
||||
a.target='_blank'; a.rel='noopener';
|
||||
a.textContent = r.name;
|
||||
ntd.appendChild(a);
|
||||
// Ticker association pills — direct (green) = the contractor is a
|
||||
// public issuer; parent (amber) = subsidiary of a public parent;
|
||||
// associated (blue) = co-appears on permits with a public entity.
|
||||
// Shows the correlation indicator J described — when Bob's Electric
|
||||
// works permits with Target, TGT renders here as associated.
|
||||
var t = r.tickers || {direct:[], associated:[]};
|
||||
var allTk = (t.direct||[]).concat(t.associated||[]);
|
||||
if(allTk.length){
|
||||
var trk = document.createElement('div'); trk.className='tickers';
|
||||
allTk.forEach(function(x){
|
||||
var p = document.createElement('span');
|
||||
p.className = 'ticker-pill ' + (x.via||'direct');
|
||||
p.textContent = x.ticker;
|
||||
// Tooltip shows the full reason path
|
||||
var hint = x.via === 'associated'
|
||||
? 'Associated via co-permits with '+x.partner_name+' ('+(x.co_permits||0)+' shared permits)' + (x.matched_name ? ' — '+x.matched_name : '')
|
||||
: x.via === 'parent'
|
||||
? 'Subsidiary of '+(x.matched_name||x.ticker) + (x.exchange ? ' · '+x.exchange : '')
|
||||
: 'Direct match: '+(x.matched_name||r.name);
|
||||
p.title = hint;
|
||||
trk.appendChild(p);
|
||||
});
|
||||
ntd.appendChild(trk);
|
||||
}
|
||||
tr.appendChild(ntd);
|
||||
var ptd=document.createElement('td'); ptd.className='right';
|
||||
ptd.textContent=(r.permits||0).toLocaleString();
|
||||
tr.appendChild(ptd);
|
||||
var ctd=document.createElement('td'); ctd.className='right '+costClass(r.total_cost||0);
|
||||
ctd.textContent=fmt$(r.total_cost||0);
|
||||
tr.appendChild(ctd);
|
||||
var ltd=document.createElement('td'); ltd.className='right';
|
||||
ltd.textContent=(r.last_filed||'').slice(0,10) || '—';
|
||||
tr.appendChild(ltd);
|
||||
var rtd=document.createElement('td'); rtd.className='role';
|
||||
(r.roles||[]).forEach(function(role){
|
||||
var pill=document.createElement('span'); pill.className='pill'; pill.textContent=role;
|
||||
rtd.appendChild(pill);
|
||||
});
|
||||
tr.appendChild(rtd);
|
||||
tb.appendChild(tr);
|
||||
});
|
||||
t.appendChild(tb);
|
||||
host.appendChild(t);
|
||||
}
|
||||
|
||||
var sDeb;
|
||||
document.getElementById('q').addEventListener('input',function(){
|
||||
clearTimeout(sDeb);
|
||||
sDeb=setTimeout(load,400);
|
||||
});
|
||||
document.getElementById('since').addEventListener('change',load);
|
||||
document.getElementById('min-cost').addEventListener('change',load);
|
||||
document.getElementById('bk-clear').addEventListener('click',function(){
|
||||
tickerFilter=null;
|
||||
document.getElementById('bk-clear').style.display='none';
|
||||
Array.prototype.forEach.call(document.querySelectorAll('.bk-card.selected'), function(c){c.classList.remove('selected')});
|
||||
showSignalMap(null);
|
||||
render();
|
||||
});
|
||||
|
||||
window.addEventListener('load',load);
|
||||
</script>
|
||||
</body></html>
|
||||
@ -81,6 +81,7 @@ pre{background:#161b22;border:1px solid #171d27;border-radius:8px;padding:14px 1
|
||||
<nav>
|
||||
<a href=".">Dashboard</a>
|
||||
<a href="console">Walkthrough</a>
|
||||
<a href="profiler">Profiler</a>
|
||||
<a href="proof" class="active">Architecture</a>
|
||||
<a href="spec">Spec</a>
|
||||
<a href="onboard">Onboard</a>
|
||||
@ -95,138 +96,137 @@ pre{background:#161b22;border:1px solid #171d27;border-radius:8px;padding:14px 1
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 1</div>
|
||||
<h2>Receipts, not promises</h2>
|
||||
<div class="lede">Every test below ran live against the real gateway when you loaded this page. Sub-100ms SQL on multi-million-row Parquet, hybrid search with playbook boost applied. No fixtures. If a test fails, you'll see ✗.</div>
|
||||
<div class="lede">Every test below ran live against the real gateway when you loaded this page. Sub-100ms SQL on multi-million-row Parquet, hybrid search with playbook boost applied, public-issuer attribution computed from this view. No fixtures. If a test fails, you'll see ✗.</div>
|
||||
<div id="ch1-tests"><div class="loading">Running tests…</div></div>
|
||||
<div id="ch1-live" style="margin-top:14px"></div>
|
||||
</div>
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 2</div>
|
||||
<h2>Architecture — 13 crates, one object store, one local AI runtime</h2>
|
||||
<div class="lede">Request flows top to bottom. Every node is independently swappable. Every line is a real HTTP or gRPC hop that you can trace with <code>tcpdump</code>.</div>
|
||||
<h2>Architecture — 15 crates, one object store, a 5-provider model fleet</h2>
|
||||
<div class="lede">Gateway is a drop-in OpenAI-compatible middleware. Any consumer that speaks the OpenAI Chat Completions shape — agent SDKs, IDE plugins, custom apps — points at <code>localhost:3100/v1</code> and gets routing, audit, and the full memory substrate behind every call. The model side has 5 providers and 40+ frontier models reachable via one OpenCode key. The data side stays Rust-first.</div>
|
||||
<div class="card accent-b">
|
||||
<pre> HTTP :3100 + gRPC :3101
|
||||
│
|
||||
┌───────▼───────┐
|
||||
│ gateway │ Rust · Axum · routing, CORS, auth, tools
|
||||
└───────┬───────┘
|
||||
┌────────────┬───────────┼───────────┬────────────┐
|
||||
│ │ │ │ │
|
||||
┌────▼───┐ ┌────▼───┐ ┌────▼───┐ ┌────▼───┐ ┌────▼───┐
|
||||
│catalog │ │ query │ │ vector │ │ ingest │ │aibridge│
|
||||
│ d │ │ d │ │ d │ │ d │ │ │
|
||||
└────┬───┘ └────┬───┘ └────┬───┘ └────┬───┘ └────┬───┘
|
||||
│ │ │ │ │
|
||||
└────────────┴───────────┼───────────┴────────────┘
|
||||
▼
|
||||
┌─────────────────┐
|
||||
│ object storage │ Parquet files (local / S3)
|
||||
└─────────────────┘
|
||||
▲
|
||||
│
|
||||
┌───────┴────────┐
|
||||
│ Python sidecar │ FastAPI → Ollama
|
||||
│ (aibridge) │ local models only
|
||||
└────────────────┘</pre>
|
||||
<pre> OpenAI SDK consumers MCP clients Browser UI (Bun :3700)
|
||||
│ │ │
|
||||
└──────────────────────────┼──────────────────────────┘
|
||||
▼
|
||||
┌──────────────────────────────┐
|
||||
│ gateway :3100 /v1/* │ Rust · Axum
|
||||
│ OpenAI-compat drop-in │ smart provider routing
|
||||
│ /v1/chat /v1/mode /iterate │ cost telemetry, Langfuse
|
||||
└──────────┬───────────────────┘
|
||||
┌─────────┬───────────────┼───────────────┬──────────┐
|
||||
│ │ │ │ │
|
||||
┌────▼───┐ ┌───▼────┐ ┌─────▼──────┐ ┌─────▼─────┐ ┌──▼──────┐
|
||||
│catalog │ │ query │ │ vector │ │ ingest │ │aibridge │
|
||||
│ d │ │ d │ │ d │ │ d │ │ │
|
||||
│idempot │ │DataFus │ │HNSW · Lance│ │CSV PDF SQL│ │provider │
|
||||
│schema │ │delta │ │playbook+ │ │auto-PII │ │adapters │
|
||||
│fingerp │ │MemTabl │ │pathway mem │ │schema fp │ │5 active │
|
||||
└────┬───┘ └───┬────┘ └─────┬──────┘ └─────┬─────┘ └──┬──────┘
|
||||
└─────────┴────────────────┼────────────────┴─────────┘
|
||||
▼
|
||||
┌──────────────────┐
|
||||
│ object storage │ Parquet · MinIO · S3-compat
|
||||
└──────────────────┘
|
||||
▲
|
||||
│
|
||||
┌───────────────┴────────────────┐
|
||||
│ validator · journald │ schema/PII/policy gates
|
||||
│ (Phase 43) · (audit log) │ + append-only mutations
|
||||
└────────────────────────────────┘
|
||||
|
||||
Provider fleet (config/providers.toml):
|
||||
ollama localhost:3200 local Ollama → qwen3.5, gemma2
|
||||
ollama_cloud ollama.com gpt-oss:120b, qwen3-coder:480b,
|
||||
deepseek-v3.1:671b, kimi-k2:1t,
|
||||
mistral-large-3:675b, qwen3.5:397b
|
||||
openrouter openrouter.ai/api/v1 343 models — paid + free rescue
|
||||
opencode opencode.ai/zen/v1 40 models · ONE sk-* key reaches
|
||||
Claude Opus 4.7, GPT-5.5-pro,
|
||||
Gemini 3.1-pro, Kimi K2.6, GLM 5.1,
|
||||
DeepSeek, Qwen, MiniMax, free tier
|
||||
kimi api.kimi.com/coding/v1 direct Kimi For Coding (TOS-clean)</pre>
|
||||
</div>
|
||||
<h3>Per-crate responsibility</h3>
|
||||
<h3>Per-crate responsibility (15 crates)</h3>
|
||||
<table class="plain">
|
||||
<thead><tr><th>Crate</th><th>Role</th><th>Path</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>shared</td><td>Types, errors, Arrow helpers, PII detection, secrets provider</td><td>crates/shared/</td></tr>
|
||||
<tr><td>storaged</td><td>object_store I/O, BucketRegistry (multi-bucket), AppendLog, ErrorJournal</td><td>crates/storaged/</td></tr>
|
||||
<tr><td>catalogd</td><td>Metadata authority — manifests, views, tombstones, profiles, schema fingerprints</td><td>crates/catalogd/</td></tr>
|
||||
<tr><td>queryd</td><td>DataFusion SQL engine, MemTable cache, delta merge-on-read, compaction</td><td>crates/queryd/</td></tr>
|
||||
<tr><td>ingestd</td><td>CSV/JSON/PDF(+OCR)/Postgres/MySQL ingest, cron schedules, auto-PII</td><td>crates/ingestd/</td></tr>
|
||||
<tr><td>vectord</td><td>Embeddings as Parquet, HNSW, trial system, autotune agent, playbook_memory</td><td>crates/vectord/</td></tr>
|
||||
<tr><td>shared</td><td>Types, errors, Arrow helpers, PII detection, secrets provider, model_matrix</td><td>crates/shared/</td></tr>
|
||||
<tr><td>storaged</td><td>object_store I/O, BucketRegistry, AppendLog, ErrorJournal, federation_service</td><td>crates/storaged/</td></tr>
|
||||
<tr><td>catalogd</td><td>Manifests, views (incl. PII-safe view layer), tombstones, profiles, schema fingerprints, register-idempotency (ADR-020)</td><td>crates/catalogd/</td></tr>
|
||||
<tr><td>queryd</td><td>DataFusion SQL, MemTable cache, delta merge-on-read, compaction, truth gate (ADR-021)</td><td>crates/queryd/</td></tr>
|
||||
<tr><td>ingestd</td><td>CSV/JSON/PDF(+OCR)/Postgres/MySQL ingest, cron schedules, auto-PII flagging</td><td>crates/ingestd/</td></tr>
|
||||
<tr><td>vectord</td><td>Embeddings as Parquet, HNSW, trial system, autotune, playbook_memory + pathway_memory (ADR-021 semantic-correctness layer)</td><td>crates/vectord/</td></tr>
|
||||
<tr><td>vectord-lance</td><td>Firewall crate — Lance 4.0 + Arrow 57 isolated from main Arrow 55</td><td>crates/vectord-lance/</td></tr>
|
||||
<tr><td>journald</td><td>Append-only mutation event log for time-travel & audit</td><td>crates/journald/</td></tr>
|
||||
<tr><td>aibridge</td><td>Rust↔Python sidecar, Ollama HTTP client, VRAM introspection</td><td>crates/aibridge/</td></tr>
|
||||
<tr><td>gateway</td><td>Axum HTTP :3100 + gRPC :3101, middleware, tools registry</td><td>crates/gateway/</td></tr>
|
||||
<tr><td>ui</td><td>Dioxus WASM internal developer UI</td><td>crates/ui/</td></tr>
|
||||
<tr><td>mcp-server</td><td>Bun TypeScript recruiter-facing app (this server)</td><td>mcp-server/</td></tr>
|
||||
<tr><td>journald</td><td>Append-only mutation event log for time-travel + audit</td><td>crates/journald/</td></tr>
|
||||
<tr><td>truth</td><td>File-backed rule store; <code>evaluate(task_class, ctx) → Vec<RuleOutcome></code> (ADR-021)</td><td>crates/truth/</td></tr>
|
||||
<tr><td>aibridge</td><td>Rust↔Python sidecar, Ollama client, ProviderAdapter trait, /v1/chat router</td><td>crates/aibridge/</td></tr>
|
||||
<tr><td>gateway</td><td>Axum HTTP :3100 + gRPC :3101, OpenAI-compat /v1/*, mode runner, validator, iterate loop, cost telemetry, Langfuse + observer fan-out</td><td>crates/gateway/</td></tr>
|
||||
<tr><td>validator</td><td>Phase 43 — schema / completeness / consistency / policy gates over LLM outputs (FillValidator, EmailValidator, ParquetWorkerLookup)</td><td>crates/validator/</td></tr>
|
||||
<tr><td>ui</td><td>Dioxus WASM internal developer UI (separate from this Bun-served public UI)</td><td>crates/ui/</td></tr>
|
||||
<tr><td>mcp-server</td><td>Bun TypeScript public-facing app + MCP tool surface — what you're reading right now</td><td>mcp-server/</td></tr>
|
||||
<tr><td>auditor</td><td>External claim-vs-diff verifier on PRs · Kimi K2.6 ↔ Haiku 4.5 cross-lineage alternation, Opus 4.7 auto-promote on diffs >100k chars</td><td>auditor/</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="ref"><strong>Source:</strong> git.agentview.dev/profit/lakehouse · <strong>ADRs:</strong> docs/DECISIONS.md (currently 20 records)</div>
|
||||
<div class="ref"><strong>Source:</strong> git.agentview.dev/profit/lakehouse · branch <code>scrum/auto-apply-19814</code> · tag <code>distillation-v1.0.0</code> at commit <code>e7636f2</code> (frozen substrate) · <strong>ADRs:</strong> docs/DECISIONS.md (currently 21 records)</div>
|
||||
</div>
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 3</div>
|
||||
<h2>Dual-agent recursive consensus loop</h2>
|
||||
<div class="lede">The system we use to execute staffing fills is a dual-agent recursive protocol. Two agents with distinct roles iterate against a shared log until one of three terminal states is reached. It is deterministic in structure, stochastic in content, and verifiable through the per-run log artifact.</div>
|
||||
<h3>Agents and protocol</h3>
|
||||
<div class="card accent-a">
|
||||
<pre> task in
|
||||
│
|
||||
▼
|
||||
┌───────────────────────────────────────────────────────────┐
|
||||
│ EXECUTOR (mistral:latest) │
|
||||
│ ──────────────────────────────────────────────────────── │
|
||||
│ input: task spec + shared log + seen-candidates ledger │
|
||||
│ output: one JSON action per turn │
|
||||
│ · {kind:"plan",steps:[…]} │
|
||||
│ · {kind:"tool_call",tool,args,rationale} │
|
||||
│ · {kind:"propose_done",fills:[N of N]} │
|
||||
└───────────┬───────────────────────────────┬───────────────┘
|
||||
│ tool_call │ propose_done
|
||||
▼ │
|
||||
┌──────────────────────────┐ │
|
||||
│ TOOL DISPATCH │ │
|
||||
│ hybrid_search / sql │ │
|
||||
│ (against live gateway) │ │
|
||||
└──────────┬───────────────┘ │
|
||||
│ result (trimmed, exclusions) │
|
||||
▼ ▼
|
||||
┌───────────────────────────────────────────────────────────┐
|
||||
│ REVIEWER (qwen2.5:latest) │
|
||||
│ ──────────────────────────────────────────────────────── │
|
||||
│ input: task spec + shared log (including tool result) │
|
||||
│ output: {kind:"critique",verdict:"continue|drift| │
|
||||
│ approve_done",notes} │
|
||||
└───────────┬───────────────────────────────────────────────┘
|
||||
│
|
||||
┌─────┴─────┐
|
||||
▼ ▼ ▼
|
||||
continue drift approve_done + propose_done ⟹ SEAL
|
||||
(next turn) (cap ≈ 3 →
|
||||
hard abort)
|
||||
</pre>
|
||||
</div>
|
||||
<div class="ref"><strong>Code:</strong> tests/multi-agent/agent.ts (protocol + prompts) · tests/multi-agent/orchestrator.ts (run loop) · tests/multi-agent/scenario.ts (5-event warehouse week)</div>
|
||||
<h2>The model fleet — 9-rung ladder, N=3 consensus, cross-lineage audit</h2>
|
||||
<div class="lede">No single model owns the answer. Every consequential call is structured: the right tier picks up first, fallback rungs catch what fails, parallel runs vote, and an independent auditor of a different model lineage checks the result against the diff. The protocol is deterministic; the inference is stochastic; every step writes a receipt.</div>
|
||||
|
||||
<h3>Why "dual" — role specialization</h3>
|
||||
<div class="narr">
|
||||
<strong>The executor is an optimist.</strong> Its job is to produce progress: pull candidates, verify SQL, propose consensus. It's instructed to be decisive.
|
||||
<br><br>
|
||||
<strong>The reviewer is a pessimist.</strong> Its job is to catch drift: proposals that don't match the task's geography, fill count, or role. It's authorized to stop the loop.
|
||||
<br><br>
|
||||
This adversarial separation is cheaper and more deterministic than asking a single model to self-critique. The reviewer has a hard rule: on the turn after a <code>propose_done</code>, it MUST emit either <code>approve_done</code> or <code>drift</code> — it cannot stall with <code>continue</code>.
|
||||
<h3>The 9-rung cloud-first ladder</h3>
|
||||
<div class="card accent-b">
|
||||
<pre> request in
|
||||
│
|
||||
▼
|
||||
┌───────────────────────────────────────────────────────────────────┐
|
||||
│ attempt 1 ollama_cloud / kimi-k2:1t 1T params · flagship │
|
||||
│ attempt 2 ollama_cloud / qwen3-coder:480b coding specialist │
|
||||
│ attempt 3 ollama_cloud / deepseek-v3.1:671b reasoning │
|
||||
│ attempt 4 ollama_cloud / mistral-large-3:675b deep analysis │
|
||||
│ attempt 5 ollama_cloud / gpt-oss:120b reliable workhorse │
|
||||
│ attempt 6 ollama_cloud / qwen3.5:397b dense final thinker │
|
||||
│ attempt 7 openrouter / openai/gpt-oss-120b:free rescue tier │
|
||||
│ attempt 8 openrouter / google/gemma-3-27b-it:free fastest rescue │
|
||||
│ attempt 9 ollama / qwen3.5:latest last-resort local │
|
||||
└───────────────┬───────────────────────────────────────────────────┘
|
||||
│ isAcceptable() = chars ≥ 3800 ∧ not malformed JSON
|
||||
▼
|
||||
sealed result OR next-rung learning preamble</pre>
|
||||
</div>
|
||||
<div class="narr">Every rung sees a learning preamble carrying the prior rejection reason. The ladder is the standard scrum/auditor path; for individual <code>/v1/chat</code> calls the caller picks the model directly (or lets the smart-routing default fire).</div>
|
||||
<div class="ref"><strong>Code:</strong> tests/real-world/scrum_master_pipeline.ts <code>const LADDER</code> · config/routing.toml · crates/gateway/src/v1/mode.rs (mode runner)</div>
|
||||
|
||||
<h3>Why "parallel" — orchestrator can fan out</h3>
|
||||
<div class="narr">
|
||||
<strong>Independent pairs run concurrently.</strong> <code>tests/multi-agent/run_e2e_rated.ts</code> runs two task-specific agent pairs via <code>Promise.all</code>. Ollama serializes inference at the model level, so "parallel" is concurrent orchestration — but the substrate (gateway, queryd, vectord) handles concurrent requests cleanly. Verified in the scenario harness: two contracts sealing simultaneously.
|
||||
</div>
|
||||
|
||||
<h3>Why "recursive" — each seal feeds the next</h3>
|
||||
<div class="narr">
|
||||
<strong>Consensus does not end at the sealed playbook.</strong> Every sealed playbook is persisted to <code>playbook_memory</code> via <code>POST /vectors/playbook_memory/seed</code>. The next hybrid search for a semantically similar operation consults that memory via <code>compute_boost_for(query_embedding, top_k, base_weight)</code> and re-ranks the candidate pool. The system builds on itself turn over turn, playbook over playbook.
|
||||
</div>
|
||||
|
||||
<h3>Termination guarantees</h3>
|
||||
<h3>N=3 consensus + tie-breaker (auditor inference)</h3>
|
||||
<div class="math">
|
||||
<span class="c">// three paths out, every run has one of these:</span><br>
|
||||
sealed = executor.propose_done ∧ reviewer.approve_done ∧ fills.count == target<br>
|
||||
abort = consecutive_tool_errors ≥ MAX_TOOL_ERRORS (3) <span class="c">// executor can't form a valid call</span><br>
|
||||
abort = consecutive_drifts ≥ MAX_CONSECUTIVE_DRIFTS (3) <span class="c">// reviewer keeps flagging</span><br>
|
||||
abort = turn > MAX_TURNS (12) <span class="c">// no consensus reached in window</span>
|
||||
<span class="c">// auditor/checks/inference.ts — every claim audit runs this:</span><br>
|
||||
1. Fire the primary reviewer N=3 times in PARALLEL (Promise.all) — wall-clock = single call<br>
|
||||
2. Aggregate votes per claim_idx · majority wins<br>
|
||||
3. On 1-1-1 split → tie-breaker model with <strong>different architecture</strong> (qwen3-coder:480b vs primary gpt-oss/kimi)<br>
|
||||
4. Every disagreement (even when majority resolves) → <code>data/_kb/audit_discrepancies.jsonl</code><br>
|
||||
<br>
|
||||
<span class="c">// Closes the cloud-non-determinism gap: temp=0 isn't actually deterministic in practice</span><br>
|
||||
<span class="c">// across hours; consensus + cross-architecture tie-break stabilizes verdicts.</span>
|
||||
</div>
|
||||
<div class="narr">Every abort dumps the full log to <code>tests/multi-agent/playbooks/<id>-FAILED.json</code> for forensic review. No consensus is ever implicit.</div>
|
||||
|
||||
<h3>Auditor cross-lineage — Kimi ↔ Haiku ↔ Opus</h3>
|
||||
<div class="narr">Every push to PR #11 triggers <code>auditor/audit.ts</code> within ~90s. To prevent a single model lineage's blind spots from becoming the system's blind spots, audits alternate between Kimi K2.6 (Moonshot) and Haiku 4.5 (Anthropic) by SHA. Diffs over 100k chars auto-promote to Claude Opus 4.7. Per-PR cap of 3 audits with auto-reset on each new head SHA prevents infinite-loop spend. <strong>100% grounding-verified rate</strong> on Haiku 4.5 across the latest 10 findings — pairing different lineages + forcing per-finding grounding kills confabulation.</div>
|
||||
<div class="ref"><strong>Code:</strong> auditor/audit.ts · auditor/checks/inference.ts (N=3) · auditor/checks/kimi_architect.ts · <strong>Verdicts:</strong> data/_auditor/kimi_verdicts/ — read any 11-<sha>.json to inspect a real audit</div>
|
||||
|
||||
<h3>Distillation v1.0.0 — the frozen substrate</h3>
|
||||
<div class="narr">The substrate the auditor and mode runner sit on is tagged at <code>distillation-v1.0.0</code> / commit <code>e7636f2</code>. <strong>145 unit tests pass · 22/22 acceptance invariants · 16/16 audit-full checks · bit-identical reproducibility verified.</strong> The distillation phase exports clean SFT / RAG / preference samples with a multi-layer contamination firewall; the auditor consumes the substrate. The frozen tag means: any future "the system regressed" question has a baseline to bisect against, byte-for-byte.</div>
|
||||
<div class="ref"><strong>Tag:</strong> distillation-v1.0.0 · <strong>Commit:</strong> e7636f2 · <strong>Substrate code:</strong> scripts/distillation/ · auditor/schemas/distillation/ · <strong>Output:</strong> data/_kb/distilled_{facts,procedures,config_hints}.jsonl</div>
|
||||
</div>
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 4</div>
|
||||
<h2>Playbook memory — the compounding feedback loop</h2>
|
||||
<div class="lede">A CRM stores events. This system turns events into re-ranking signal. Every sealed playbook endorses specific (worker, city, state) tuples. Every failure penalizes them. Every similar future query inherits the signal through cosine similarity.</div>
|
||||
<h2>Two memory layers — playbook (worker signal) + pathway (system signal)</h2>
|
||||
<div class="lede">A CRM stores events. This system turns events into re-ranking signal at two layers. <strong>Playbook memory</strong> compounds worker-level outcomes (who got endorsed, where, when) into per-query boost. <strong>Pathway memory</strong> compounds system-level outcomes (which model + corpus + framing actually solved similar problems) into per-task hot-swap. Both are queryable. Both are auditable. Both compound.</div>
|
||||
|
||||
<h3>Layer 1 — playbook memory (worker + geo signal)</h3>
|
||||
|
||||
<h3>Seed shape</h3>
|
||||
<div class="math">
|
||||
@ -289,10 +289,82 @@ pre{background:#161b22;border:1px solid #171d27;border-radius:8px;padding:14px 1
|
||||
<strong>Beyond "who was endorsed."</strong> <code>POST /vectors/playbook_memory/patterns</code> takes a query, finds top-K similar past playbooks, pulls each endorsed worker's full workers_500k profile, and aggregates shared traits: recurring certifications, skill frequencies, modal archetype, reliability distribution. Returns a <code>discovered_pattern</code> string showing operator-actionable signal the user didn't explicitly query for.
|
||||
</div>
|
||||
<div class="ref"><strong>Code:</strong> crates/vectord/src/playbook_memory.rs::discover_patterns · <strong>Surfaces:</strong> /vectors/playbook_memory/patterns endpoint, /intelligence/chat response, /intelligence/permit_contracts cards</div>
|
||||
|
||||
<h3>Layer 2 — pathway memory (system-level hot-swap, ADR-021)</h3>
|
||||
<div class="narr">
|
||||
<strong>Pathway memory remembers which approach worked, not just which worker.</strong> Every accepted scrum review writes a <code>PathwayTrace</code> with the full backtrack: file fingerprint, model used, signal class, KB chunks consulted, observer events, semantic flags, bug fingerprints. A new query that fingerprints to the same trace can hot-swap to the prior result without re-running the 9-rung escalation. The 5-factor hot-swap gate is strict: narrow fingerprint match AND audit consensus pass AND replay_count ≥ 3 (probation) AND success_rate ≥ 0.80 AND NOT retired AND vector cosine ≥ 0.90.
|
||||
</div>
|
||||
<div class="math">
|
||||
<span class="c">// Live pathway state (refresh page to recompute):</span><br>
|
||||
<span id="pwm-traces">— traces</span> · <span id="pwm-replays">—</span> successful replays · <span id="pwm-rate">—</span> reuse rate<br>
|
||||
<span class="c">// 88 / 11/11 / 100% as of 2026-04-27 — probation gate crossed</span>
|
||||
</div>
|
||||
<div class="ref"><strong>Code:</strong> crates/vectord/src/pathway_memory.rs · <strong>Endpoints:</strong> /vectors/pathway/insert · /query · /record_replay · /stats · /bug_fingerprints · <strong>Spec:</strong> docs/DECISIONS.md ADR-021 — Semantic-correctness matrix layer</div>
|
||||
|
||||
<h3>What both memory layers feed (besides search)</h3>
|
||||
<div class="narr">
|
||||
Both layers also feed the <strong>per-staffer hot-swap index</strong> (Chapter 5) and the <strong>Construction Activity Signal Engine</strong> (Chapter 6). One memory model, surfaced three different ways at the request boundary depending on who's asking.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 5</div>
|
||||
<h2>Per-staffer hot-swap — same corpus, different relevance gradient</h2>
|
||||
<div class="lede">Maria runs Chicago. Devon runs Indianapolis. Aisha runs Wisconsin/Michigan. They share one corpus, but the search results, the recurring-skill patterns, and the playbook context all reshape to whoever is acting. Same query "forklift operators" returns 89 IN workers when Devon's acting, 16 WI when Aisha's, 167 IL when Maria's. The MEMORY panel relabels itself with the active coordinator's name.</div>
|
||||
|
||||
<h3>What scopes per staffer</h3>
|
||||
<div class="math">
|
||||
<span class="c">// On every /intelligence/chat call:</span><br>
|
||||
if (b.staffer_id) {<br>
|
||||
const staffer = lookupStaffer(b.staffer_id);<br>
|
||||
<span class="c">// 1. Default state filter to staffer territory unless caller pinned one</span><br>
|
||||
if (!explicitState) filters.push(`state = '${staffer.territory.state}'`);<br>
|
||||
<span class="c">// 2. Default playbook-pattern geo to staffer's primary city/state</span><br>
|
||||
cityForPatterns = staffer.territory.cities[0];<br>
|
||||
stateForPatterns = staffer.territory.state;<br>
|
||||
<span class="c">// 3. Surface staffer.name back so the UI can relabel MEMORY → MARIA'S MEMORY</span><br>
|
||||
response.staffer = { id, name, territory };<br>
|
||||
}
|
||||
</div>
|
||||
<div class="narr">
|
||||
The corpus stays intact. The relevance gradient is per coordinator. As each accumulates fills, their slice of the playbook compounds independently. The architecture generalizes — every new metro adds territories, not code paths.
|
||||
</div>
|
||||
<div class="ref"><strong>Code:</strong> mcp-server/index.ts <code>STAFFERS</code> roster + <code>lookupStaffer()</code> · <code>/staffers</code> endpoint · <code>/intelligence/chat</code> smart_search route · <strong>UI:</strong> staffer dropdown in mcp-server/search.html</div>
|
||||
</div>
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 6</div>
|
||||
<h2>Construction Activity Signal Engine — the corpus is also a market signal</h2>
|
||||
<div class="lede">Every contractor in this corpus is also a forward indicator on the public equities they touch. Permits filed today predict construction starts ~45 days out, staffing ~30, revenue recognition months later. The associated-ticker network surfaces this signal <em>before</em> any 10-Q. The architecture is metro-agnostic — Chicago is Phase 1; NYC DOB, LA County, Houston BCD, Boston ISD ship as Socrata-shaped adapters.</div>
|
||||
|
||||
<h3>Three flavors of attribution</h3>
|
||||
<div class="math">
|
||||
<span class="c">// per contractor in /intelligence/profiler_index:</span><br>
|
||||
direct <span class="c">// contractor IS a public issuer → SEC tickers index match</span><br>
|
||||
parent <span class="c">// curated KNOWN_PARENT_MAP — Turner → HOC.DE via Hochtief AG</span><br>
|
||||
associated <span class="c">// co-permit network — Bob's Electric appears with TARGET CORPORATION</span><br>
|
||||
<span class="c">// 3+ times → inherits TGT as an associated indicator</span>
|
||||
</div>
|
||||
<div class="narr">
|
||||
The associated path is the moat. A staffing-permit dataset that maps contractor-to-public-issuer is not commercially available; we synthesize it from the Socrata co-occurrence graph. Every additional metro multiplies edges.
|
||||
</div>
|
||||
|
||||
<h3>Building Activity Index (BAI)</h3>
|
||||
<div class="math">
|
||||
<span class="c">// BAI = attribution-weighted average day-change across surfaced issuers:</span><br>
|
||||
BAI = Σ (day_change_pct × attribution_count) / Σ attribution_count<br>
|
||||
<br>
|
||||
<span class="c">// Indexed build value = total $ of permits attributable to ANY public issuer</span><br>
|
||||
<span class="c">// Network depth = issuers / total attribution edges</span>
|
||||
</div>
|
||||
<div class="narr">
|
||||
Run BAI daily, save the series, and you've got a backtestable thesis in months. Today's surface is Chicago-only with ~9 issuers; the curve scales linearly with metros added — and the marginal cost of a new metro is one Socrata adapter.
|
||||
</div>
|
||||
<div class="ref"><strong>Code:</strong> mcp-server/index.ts <code>/intelligence/profiler_index</code> + <code>/intelligence/ticker_quotes</code> · entity.ts <code>lookupTickerLite()</code> · <code>fetchStooqQuote()</code> · <strong>UI:</strong> /profiler · <strong>Data sources:</strong> SEC company_tickers.json (in-memory index) + Stooq CSV API + curated parent-link map</div>
|
||||
</div>
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 7</div>
|
||||
<h2>Key architectural choices — what was picked and why</h2>
|
||||
<div class="lede">Each choice is documented in <code>docs/DECISIONS.md</code> (Architecture Decision Records). If you dispute any of these, the ADR names the alternatives we rejected and the measurement that drove the call.</div>
|
||||
<div class="card">
|
||||
@ -314,62 +386,95 @@ pre{background:#161b22;border:1px solid #171d27;border-radius:8px;padding:14px 1
|
||||
<div class="row accent-r">
|
||||
<div style="flex:1"><div class="title">ADR-020 · Idempotent register() with schema-fingerprint gate</div><div class="meta">Same (name, fingerprint) reuses manifest. Different fingerprint = 409 Conflict. Prevents silent duplicate manifests. Cleanup run collapsed 374 → 31 datasets.</div></div>
|
||||
</div>
|
||||
<div class="row accent-r">
|
||||
<div style="flex:1"><div class="title">ADR-021 · Semantic-correctness matrix layer</div><div class="meta">Pathway memory carries semantic flags (UnitMismatch, TypeConfusion, OffByOne, StaleReference, DeadCode, BoundaryViolation, …) on every trace. New reviews see prior bug fingerprints as a preamble; recurrent classes get caught on first read. Compounds across files in the same crate.</div></div>
|
||||
</div>
|
||||
<div class="row accent-l">
|
||||
<div style="flex:1"><div class="title">Phase 19 design note · Statistical + semantic, not neural</div><div class="meta">Meta-index is cosine similarity + endorsement aggregation. No model training. Rebuildable from <code>successful_playbooks</code> alone. Neural re-ranker deferred to Phase 20+ only if statistical floor plateaus.</div></div>
|
||||
</div>
|
||||
<div class="row accent-l">
|
||||
<div style="flex:1"><div class="title">Distillation freeze · v1.0.0 at e7636f2</div><div class="meta">145 tests · 22/22 acceptance · 16/16 audit-full · bit-identical reproducibility. Multi-layer contamination firewall on SFT exports. Substrate the auditor + mode runner sit on; "the system regressed" questions bisect against this anchor.</div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 6</div>
|
||||
<div class="num">Chapter 8</div>
|
||||
<h2>Measured at scale, on this machine</h2>
|
||||
<div class="lede">Hardware: i9 + 128GB RAM + Nvidia A4000 16GB VRAM. Numbers below are from <em>this</em> running instance. Refresh the page and they'll recompute.</div>
|
||||
<div class="lede">Hardware: i9 + 128GB RAM + Nvidia A4000 16GB VRAM + 2.5GB symmetric. Numbers below are from <em>this</em> running instance. Refresh the page and they'll recompute.</div>
|
||||
<div class="grid" id="ch6-scale"><div class="loading">Loading scale data…</div></div>
|
||||
<div id="ch6-recall" style="margin-top:10px"></div>
|
||||
</div>
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 7</div>
|
||||
<div class="num">Chapter 9</div>
|
||||
<h2>Verify or dispute — reproduce it yourself</h2>
|
||||
<div class="lede">Every claim below is a curl away from falsification.</div>
|
||||
<div class="lede">Every claim above is a curl away from falsification.</div>
|
||||
<div class="card">
|
||||
<div class="narr"><strong>Health.</strong> Should return <code>lakehouse ok</code>.</div>
|
||||
<pre>curl http://localhost:3100/health</pre>
|
||||
<div class="narr"><strong>Gateway health.</strong> Returns provider matrix + worker count.</div>
|
||||
<pre>curl -s http://localhost:3100/v1/health | jq</pre>
|
||||
<div class="narr"><strong>Any SQL on multi-million-row Parquet.</strong> Sub-100ms typical.</div>
|
||||
<pre>curl -s -X POST http://localhost:3100/query/sql \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"sql":"SELECT role, COUNT(*) FROM workers_500k WHERE state=\"IL\" GROUP BY role LIMIT 5"}'</pre>
|
||||
<div class="narr"><strong>Hybrid search with playbook boost.</strong> The whole Phase 19 feedback loop in one request.</div>
|
||||
<div class="narr"><strong>Hybrid search with playbook boost.</strong> SQL filter + vector rerank + playbook memory in one call.</div>
|
||||
<pre>curl -s -X POST http://localhost:3100/vectors/hybrid \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"index_name":"workers_500k_v1",
|
||||
"sql_filter":"role = '\''Forklift Operator'\'' AND city = '\''Chicago'\'' AND CAST(availability AS DOUBLE) > 0.5",
|
||||
"question":"reliable forklift operator",
|
||||
"top_k":5,"use_playbook_memory":true,"playbook_memory_k":200}'</pre>
|
||||
<div class="narr"><strong>Playbook memory stats.</strong> Count + endorsed names + sample.</div>
|
||||
<pre>curl http://localhost:3100/vectors/playbook_memory/stats</pre>
|
||||
<div class="narr"><strong>Pattern discovery.</strong> What do past similar fills have in common?</div>
|
||||
<pre>curl -s -X POST http://localhost:3100/vectors/playbook_memory/patterns \
|
||||
<div class="narr"><strong>Pathway memory stats.</strong> System-level hot-swap signal — should show 88 traces / 11 replays / 100% reuse rate (probation gate crossed).</div>
|
||||
<pre>curl -s http://localhost:3100/vectors/pathway/stats | jq</pre>
|
||||
<div class="narr"><strong>Per-staffer scoping.</strong> Same query, different rosters per coordinator.</div>
|
||||
<pre>for s in maria devon aisha; do
|
||||
curl -s -X POST http://localhost:3700/intelligence/chat \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "{\"message\":\"forklift operators\",\"staffer_id\":\"$s\"}" \
|
||||
| jq -r ".staffer.name + \": \" + (.sql_results | length | tostring) + \" workers, top: \" + (.sql_results[0].name + \" in \" + .sql_results[0].city + \", \" + .sql_results[0].state)"
|
||||
done
|
||||
# Maria: 167 workers, top: ... in Chicago, IL
|
||||
# Devon: 89 workers, top: ... in Fort Wayne, IN
|
||||
# Aisha: 16 workers, top: ... in Milwaukee, WI</pre>
|
||||
<div class="narr"><strong>Late-worker triage in one shot.</strong> Pulls profile + 5 backfills + drafts SMS. Should respond in under 300ms.</div>
|
||||
<pre>curl -s -X POST http://localhost:3700/intelligence/chat \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"query":"Forklift Operator in Chicago, IL","top_k_playbooks":25,"min_trait_frequency":0.3}'</pre>
|
||||
<div class="narr"><strong>Run the dual-agent scenario yourself.</strong> All 5 events, real fills, real artifacts.</div>
|
||||
-d '{"message":"Marcus running late site 4422"}' | jq</pre>
|
||||
<div class="narr"><strong>Construction Activity Signal Engine.</strong> Profiler index with attribution, cost, last filed.</div>
|
||||
<pre>curl -s -X POST http://localhost:3700/intelligence/profiler_index \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"limit":10}' \
|
||||
| jq '.contractors[] | {name, permits, total_cost, direct: (.tickers.direct | map(.ticker)), associated: (.tickers.associated | map(.ticker + " ←via " + .partner_name))}'</pre>
|
||||
<div class="narr"><strong>Live ticker quotes.</strong> Batch Stooq pull for the basket.</div>
|
||||
<pre>curl -s -X POST http://localhost:3700/intelligence/ticker_quotes \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"tickers":["TGT","JPM","BALY","WBA","MCD"]}' | jq .quotes</pre>
|
||||
<div class="narr"><strong>Audit trail — read any verdict on PR #11.</strong> Independent claim-vs-diff verifier output.</div>
|
||||
<pre>ls /home/profit/lakehouse/data/_auditor/kimi_verdicts/
|
||||
# 11-c3c9c2174a91.json 11-ca7375ea2b17.json 11-2d9cb128bf42.json …
|
||||
jq '.findings[0:3]' /home/profit/lakehouse/data/_auditor/kimi_verdicts/11-c3c9c2174a91.json</pre>
|
||||
<div class="narr"><strong>Distillation acceptance gate.</strong> 22/22 invariants must pass for any commit that touches the substrate.</div>
|
||||
<pre>cd /home/profit/lakehouse
|
||||
bun run tests/multi-agent/scenario.ts
|
||||
# Output: tests/multi-agent/playbooks/scenario-<timestamp>/report.md</pre>
|
||||
bun test auditor/schemas/distillation/ tests/distillation/
|
||||
# Expect: 145 pass · 0 fail · 372 expect() calls</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chapter">
|
||||
<div class="num">Chapter 8</div>
|
||||
<div class="num">Chapter 10</div>
|
||||
<h2>What we are <em>not</em> claiming</h2>
|
||||
<div class="lede">Every impressive-sounding number comes with a footnote. Here are the honest limits.</div>
|
||||
<div class="lede">Every impressive-sounding number comes with a footnote. Here are the honest limits as of 2026-04-27.</div>
|
||||
<div class="card">
|
||||
<div class="row accent-a"><div style="flex:1"><div class="title">workers_500k is synthetic.</div><div class="meta">Real client ATS export replaces this table. Schema is deliberately identical to a production ATS.</div></div></div>
|
||||
<div class="row accent-a"><div style="flex:1"><div class="title">candidates table has 1,000 rows.</div><div class="meta">Intentionally small for demo. call_log references higher candidate_ids that don't cross-reference — this is a dataset alignment issue, not a pipeline issue.</div></div></div>
|
||||
<div class="row accent-b"><div style="flex:1"><div class="title">Chicago permit data is real.</div><div class="meta">Pulled live from data.cityofchicago.org/resource/ydr8-5enu.json (Socrata API). Not synthetic. Not cached.</div></div></div>
|
||||
<div class="row accent-l"><div style="flex:1"><div class="title">Playbook memory is seeded from demo runs.</div><div class="meta">The pipeline that seeds it is identical to what a live recruiter would trigger via /log. Same code path.</div></div></div>
|
||||
<div class="row accent-w"><div style="flex:1"><div class="title">Local 7B models (mistral, qwen2.5) are imperfect.</div><div class="meta">They occasionally malform tool calls or drop fields. Multi-agent scenarios seal roughly 40-80% in one run. Larger models or constrained decoding would improve this. Not a substrate problem.</div></div></div>
|
||||
<div class="row accent-a"><div style="flex:1"><div class="title">workers_500k is synthetic.</div><div class="meta">Real client ATS export replaces this table. Schema is deliberately identical to a production ATS so the swap is config, not code.</div></div></div>
|
||||
<div class="row accent-a"><div style="flex:1"><div class="title">candidates table is light at 1,000 rows.</div><div class="meta">Intentionally small. Live PII-safe view layer is built; replacing the small table with a 100K+ ATS is a one-line config flip.</div></div></div>
|
||||
<div class="row accent-b"><div style="flex:1"><div class="title">Chicago permit data is real.</div><div class="meta">Pulled live from data.cityofchicago.org/resource/ydr8-5enu.json (Socrata). Not synthetic. Not cached. Verifiable address-by-address.</div></div></div>
|
||||
<div class="row accent-l"><div style="flex:1"><div class="title">Playbook memory is seeded from demo runs.</div><div class="meta">Same code path that seeds in production: every /log from the recruiter UI triggers seed → persist_sql. Demo seeds use the same shape as live operations.</div></div></div>
|
||||
<div class="row accent-l"><div style="flex:1"><div class="title">Pathway memory probation gate is crossed.</div><div class="meta">88 traces, 11 replays, 11 successful, 100% reuse rate. Any pathway that fails to clear ≥0.80 success_rate after ≥3 replays gets retired automatically (sticky flag prevents oscillation).</div></div></div>
|
||||
<div class="row accent-w"><div style="flex:1"><div class="title">SEC name-to-ticker fuzzy matcher has rare false positives.</div><div class="meta">For names with no clean SEC match the matcher occasionally surfaces a same-keyword small-cap (saw FLG attach to a PNC-adjacent contractor once). Kept conservative — minimum 2 non-stopword overlap. Tightenable to require explicit allow-list for production trading use.</div></div></div>
|
||||
<div class="row accent-r"><div style="flex:1"><div class="title">12 awaiting public-data sources are placeholders.</div><div class="meta">DOL Wage & Hour, EPA ECHO, MSHA, BBB, PACER, UCC liens, D&B, etc. — listed by name on every contractor profile with a one-line "would show:" sample. Not yet wired. Each ships as a Socrata-style adapter; engineering scope is concrete.</div></div></div>
|
||||
<div class="row accent-r"><div style="flex:1"><div class="title">No rate/margin awareness yet.</div><div class="meta">Worker pay expectations vs contract bill rates are not modeled. Flagged as a Phase 20 item; no architectural blocker.</div></div></div>
|
||||
<div class="row accent-r"><div style="flex:1"><div class="title">BAI is a thesis, not a backtested signal.</div><div class="meta">The Building Activity Index is computed live from current attribution + day-change. To have a backtestable thesis we need the daily series saved over months. Architectural support is there (data/_kb/audit_baselines.jsonl pattern); just hasn't been running long enough.</div></div></div>
|
||||
<div class="row accent-r"><div style="flex:1"><div class="title">Single-metro today.</div><div class="meta">Chicago via Socrata. NYC DOB, LA County, Houston BCD, Boston ISD, DC DCRA all use Socrata-equivalent APIs — adapters are config-only. Each new metro multiplies the network without multiplying the codebase.</div></div></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -394,8 +499,72 @@ function apiPost(path, body){
|
||||
|
||||
window.addEventListener('load',function(){
|
||||
loadLiveSections();
|
||||
loadPathwayLive();
|
||||
loadSignalLive();
|
||||
});
|
||||
|
||||
// Pathway memory live counters in Chapter 4 — small inline spans.
|
||||
function loadPathwayLive(){
|
||||
fetch(A+'/api/vectors/pathway/stats').then(function(r){return r.json()}).then(function(p){
|
||||
if(!p) return;
|
||||
var t=document.getElementById('pwm-traces');
|
||||
var r=document.getElementById('pwm-replays');
|
||||
var rate=document.getElementById('pwm-rate');
|
||||
if(t) t.textContent = (p.total_pathways||0) + ' traces';
|
||||
if(r) r.textContent = (p.successful_replays||0) + '/' + (p.total_replays||0);
|
||||
if(rate) rate.textContent = Math.round((p.replay_success_rate||0)*100) + '%';
|
||||
}).catch(function(){});
|
||||
}
|
||||
|
||||
// Live tile under Chapter 1 — what the signal engine sees in this view.
|
||||
function loadSignalLive(){
|
||||
apiPost('/intelligence/profiler_index',{limit:200}).then(function(d){
|
||||
var host=document.getElementById('ch1-live');if(!host) return;
|
||||
host.textContent='';
|
||||
var rows=d.contractors||[];
|
||||
if(!rows.length) return;
|
||||
// Aggregate basket
|
||||
var byTk={};
|
||||
rows.forEach(function(r){
|
||||
var ts=(r.tickers&&r.tickers.direct?r.tickers.direct:[]).concat(r.tickers&&r.tickers.associated?r.tickers.associated:[]);
|
||||
ts.forEach(function(t){
|
||||
if(!t||!t.ticker) return;
|
||||
if(!byTk[t.ticker]) byTk[t.ticker]={kinds:[],count:0};
|
||||
byTk[t.ticker].count++;
|
||||
if(byTk[t.ticker].kinds.indexOf(t.via)<0) byTk[t.ticker].kinds.push(t.via);
|
||||
});
|
||||
});
|
||||
var basket=Object.values(byTk);
|
||||
var attribCost=rows.reduce(function(s,r){
|
||||
var ts=(r.tickers&&r.tickers.direct?r.tickers.direct:[]).concat(r.tickers&&r.tickers.associated?r.tickers.associated:[]);
|
||||
return s + (ts.length>0 ? (r.total_cost||0) : 0);
|
||||
},0);
|
||||
if(!basket.length) return;
|
||||
var card=el('div','card accent-l');
|
||||
var hdr=el('div',null,'LIVE — Construction Activity Signal Engine');
|
||||
hdr.style.cssText='font-size:10px;color:#3fb950;text-transform:uppercase;letter-spacing:1.4px;font-weight:700;margin-bottom:8px';
|
||||
card.appendChild(hdr);
|
||||
var line=document.createElement('div');
|
||||
line.style.cssText='display:flex;gap:24px;flex-wrap:wrap;font-size:13px';
|
||||
function block(num,lab){
|
||||
var b=document.createElement('div');
|
||||
var n=document.createElement('div');n.style.cssText='font-size:18px;font-weight:700;color:#e6edf3;font-family:ui-monospace,monospace';n.textContent=num;
|
||||
var l=document.createElement('div');l.style.cssText='font-size:10px;color:#545d68;text-transform:uppercase;letter-spacing:1.2px;font-weight:600';l.textContent=lab;
|
||||
b.appendChild(n);b.appendChild(l);return b;
|
||||
}
|
||||
var bav = attribCost>=1e9?'$'+(attribCost/1e9).toFixed(2)+'B':attribCost>=1e6?'$'+(attribCost/1e6).toFixed(0)+'M':'$'+Math.round(attribCost/1e3)+'K';
|
||||
line.appendChild(block(basket.length+'', 'Public issuers in scope'));
|
||||
line.appendChild(block(bav, 'Attributed build value'));
|
||||
line.appendChild(block(rows.length+'', 'Contractors indexed'));
|
||||
line.appendChild(block(basket.reduce(function(s,b){return s+b.count},0)+'', 'Attribution edges'));
|
||||
card.appendChild(line);
|
||||
var note=el('div',null,'Computed live from /intelligence/profiler_index in '+(d.duration_ms||0)+'ms · click any of the chapter-9 curl lines to verify');
|
||||
note.style.cssText='font-size:11px;color:#545d68;margin-top:10px;font-family:ui-monospace,monospace';
|
||||
card.appendChild(note);
|
||||
host.appendChild(card);
|
||||
}).catch(function(){});
|
||||
}
|
||||
|
||||
function loadLiveSections(){
|
||||
apiPost('/proof.json',{}).then(function(r){
|
||||
var host1=document.getElementById('ch1-tests');host1.textContent='';
|
||||
|
||||
92
mcp-server/role_scenes.ts
Normal file
92
mcp-server/role_scenes.ts
Normal file
@ -0,0 +1,92 @@
|
||||
// Server-side mirror of search.html's ROLE_BANDS regex table.
|
||||
// Each band carries a *visual scene* — clothing + immediate backdrop —
|
||||
// so ComfyUI produces role-coherent headshots instead of interchangeable
|
||||
// studio portraits. The front-end sends the raw role string in the
|
||||
// query (?role=Forklift%20Operator); the server resolves it to a band
|
||||
// and looks up the scene here.
|
||||
|
||||
export type RoleBand =
|
||||
| "warehouse"
|
||||
| "production"
|
||||
| "trades"
|
||||
| "driver"
|
||||
| "lead";
|
||||
|
||||
export interface SceneDef {
|
||||
band: RoleBand;
|
||||
// Free-form clause inserted into the diffusion prompt AFTER
|
||||
// "[age]-year-old [race] [gender] [role], ". Should describe what
|
||||
// they're wearing and what is immediately behind them. Keep under
|
||||
// ~25 words — SDXL Turbo loses focus on longer prompts and starts
|
||||
// hallucinating cartoon hands.
|
||||
scene: string;
|
||||
}
|
||||
|
||||
const RE_BANDS: { re: RegExp; band: RoleBand }[] = [
|
||||
{ re: /forklift|warehouse|associate|material\s*handler|loader|loading|packag|shipping|logistics|inventory|sanitation|janit/i, band: "warehouse" },
|
||||
{ re: /production|assembl|quality/i, band: "production" },
|
||||
{ re: /welder|weld|electric|maint(enance)?\s*tech|cnc|machine\s*op|hvac|plumb|carpenter|mason|tool\s*&\s*die/i, band: "trades" },
|
||||
{ re: /driver|truck|haul|cdl/i, band: "driver" },
|
||||
{ re: /line\s*lead|supervisor|foreman|coordinator|lead\b/i, band: "lead" },
|
||||
];
|
||||
|
||||
export function roleBand(role: string): RoleBand {
|
||||
const r = (role || "").trim();
|
||||
if (!r) return "warehouse";
|
||||
for (const b of RE_BANDS) if (b.re.test(r)) return b.band;
|
||||
return "warehouse";
|
||||
}
|
||||
|
||||
// TODO J — refine these. Each `scene` string lands directly in the
|
||||
// diffusion prompt. Tone target: a coordinator glances at the card
|
||||
// and recognizes the role from the photo before reading the role pill.
|
||||
//
|
||||
// Things that work well in SDXL Turbo at 8 steps:
|
||||
// - One concrete clothing item ("high-visibility yellow vest")
|
||||
// - One concrete prop ("hard hat hanging from belt", "tablet in hand")
|
||||
// - One blurred background element ("warehouse pallet aisle behind",
|
||||
// "factory machinery softly out of focus")
|
||||
// - Avoid: text/logos (rendered as scribble), specific brands, hands
|
||||
// holding tools (often distorts), full-body language ("standing",
|
||||
// "leaning") — model is trained on portrait crops.
|
||||
//
|
||||
// Each scene now bakes "monochrome black and white photography" into
|
||||
// the prompt so the model produces native B&W output rather than us
|
||||
// applying CSS grayscale post-hoc. SDXL Turbo handles B&W natively
|
||||
// with strong tonal range — better than desaturating a color render.
|
||||
export const SCENES: Record<RoleBand, SceneDef> = {
|
||||
warehouse: {
|
||||
band: "warehouse",
|
||||
scene: "wearing a high-visibility safety vest over a t-shirt, hard hat visible, blurred warehouse pallet aisle behind, soft natural light, monochrome black and white photography, fine film grain, documentary portrait style",
|
||||
},
|
||||
production: {
|
||||
band: "production",
|
||||
scene: "wearing a work shirt with safety glasses on forehead, blurred factory machinery softly out of focus behind, fluorescent overhead lighting, monochrome black and white photography, fine film grain, documentary portrait style",
|
||||
},
|
||||
trades: {
|
||||
band: "trades",
|
||||
scene: "wearing a heavy-duty work shirt with rolled sleeves, blurred workshop tool wall behind, focused tungsten lighting, monochrome black and white photography, fine film grain, documentary portrait style",
|
||||
},
|
||||
driver: {
|
||||
band: "driver",
|
||||
scene: "wearing a polo shirt, lanyard with ID badge visible, blurred truck cab or loading dock behind, daylight, monochrome black and white photography, fine film grain, documentary portrait style",
|
||||
},
|
||||
lead: {
|
||||
band: "lead",
|
||||
scene: "wearing a button-down shirt, tablet held casually at chest level, blurred warehouse floor in soft focus behind, professional lighting, monochrome black and white photography, fine film grain, documentary portrait style",
|
||||
},
|
||||
};
|
||||
|
||||
// v2 — baked B&W + 1024×1024 render canvas (4× pixels of v1). Larger
|
||||
// source means downsampling to a 40px avatar packs more detail per
|
||||
// displayed pixel, hiding the diffusion-y micro-textures that read as
|
||||
// "AI generated" at small sizes. Server route reads pool from
|
||||
// data/headshots_role_pool/{SCENES_VERSION}/... so v1 stays available
|
||||
// for rollback / A-B comparison.
|
||||
export const SCENES_VERSION = "v2";
|
||||
|
||||
// Default render dimensions used by both the on-demand /headshots/
|
||||
// generate/:key route and the offline render_role_pool.py script. v1
|
||||
// used 512²; v2 doubles to 1024² (linear 2× = 4× pixels = ~3× GPU
|
||||
// time on SDXL Turbo).
|
||||
export const FACE_RENDER_DIM = 1024;
|
||||
File diff suppressed because it is too large
Load Diff
@ -78,13 +78,14 @@ table.plain tr:hover td{background:#0d1117}
|
||||
<nav>
|
||||
<a href=".">Dashboard</a>
|
||||
<a href="console">Walkthrough</a>
|
||||
<a href="profiler">Profiler</a>
|
||||
<a href="proof">Architecture</a>
|
||||
<a href="spec" class="active">Spec</a>
|
||||
<a href="onboard">Onboard</a>
|
||||
<a href="alerts">Alerts</a>
|
||||
<a href="workspaces">Workspaces</a>
|
||||
</nav>
|
||||
<div class="rt">v1 · 2026-04-20</div>
|
||||
<div class="rt">v3 · 2026-04-27</div>
|
||||
</div>
|
||||
|
||||
<div class="layout">
|
||||
@ -120,14 +121,18 @@ table.plain tr:hover td{background:#0d1117}
|
||||
<tr><td class="mono">crates/vectord/</td><td>The vector + learning surface. Embeddings stored as Parquet (ADR-008), HNSW index (Phase 15), trial system (autotune), promotion registry (Phase 16), playbook_memory (Phase 19). Core feedback loop lives here.</td></tr>
|
||||
<tr><td class="mono">crates/vectord-lance/</td><td>Firewall crate. Lance 4.0 + Arrow 57, isolated from the main Arrow-55 workspace. Provides secondary vector backend for large-scale, random-access, and append-heavy workloads (ADR-019).</td></tr>
|
||||
<tr><td class="mono">crates/journald/</td><td>Append-only mutation event log (ADR-012). Every insert/update/delete writes here — who, when, what, old/new value. Never mutated. Foundation for time-travel + compliance audit.</td></tr>
|
||||
<tr><td class="mono">crates/aibridge/</td><td>Rust ↔ Python sidecar. HTTP client over FastAPI wrapper around Ollama. VRAM introspection via nvidia-smi. All LLM calls (embed, generate, rerank) flow through here.</td></tr>
|
||||
<tr><td class="mono">crates/gateway/</td><td>Axum HTTP (:3100) + gRPC (:3101). Auth middleware, tools registry (Phase 12 — governed actions), CORS. Every external request enters here.</td></tr>
|
||||
<tr><td class="mono">crates/truth/</td><td>File-backed rule store. <code>evaluate(task_class, ctx) → Vec<RuleOutcome></code> (ADR-021 — semantic-correctness matrix layer). Loaded from <code>truth/*.toml</code> at gateway boot.</td></tr>
|
||||
<tr><td class="mono">crates/aibridge/</td><td>Rust ↔ Python sidecar + provider adapter trait. HTTP client over FastAPI wrapper around Ollama for local; <code>ProviderAdapter</code> dispatch for cloud (ollama_cloud, openrouter, opencode, kimi). VRAM introspection via nvidia-smi. All LLM calls flow through here.</td></tr>
|
||||
<tr><td class="mono">crates/gateway/</td><td>Axum HTTP (:3100) + gRPC (:3101). OpenAI-compat <code>/v1/*</code> (drop-in middleware), mode runner (<code>/v1/mode/execute</code>), validator (<code>/v1/validate</code>), iterate loop (<code>/v1/iterate</code>), tools registry, cost telemetry, Langfuse + observer fan-out on every chat. Every external request enters here.</td></tr>
|
||||
<tr><td class="mono">crates/validator/</td><td>Phase 43 production validator. Schema / completeness / consistency / policy gates over LLM outputs. <code>FillValidator</code>, <code>EmailValidator</code>, <code>ParquetWorkerLookup</code> (loads workers_500k.parquet at boot). Fail-closed when roster absent.</td></tr>
|
||||
<tr><td class="mono">crates/ui/</td><td>Dioxus WASM developer UI. Internal tool. Not exposed externally.</td></tr>
|
||||
<tr><td class="mono">mcp-server/</td><td>Bun/TypeScript recruiter-facing app. Serves <code>devop.live/lakehouse</code>. Routes: <code>/search /match /log /log_failure /clients/:c/blacklist /intelligence/* /memory/query /models/matrix /system/summary</code>. Observer sibling at <code>observer.ts</code> with HTTP listener on :3800 for scenario event ingest. Proxies to the Rust gateway for heavy work.</td></tr>
|
||||
<tr><td class="mono">tests/multi-agent/</td><td>Dual-agent scenario harness + memory stack. <code>agent.ts</code> (prompts, continuation + tree-split primitives, cloud routing), <code>orchestrator.ts</code>, <code>scenario.ts</code> (contracts + staffer + tool_level), <code>kb.ts</code> (KB indexing, competence scoring, neighbor retrieval), <code>normalize.ts</code> (input normalizer — structured / regex / LLM), <code>memory_query.ts</code> (unified /memory/query), <code>gen_scenarios.ts</code> + <code>gen_staffer_demo.ts</code> (corpus generators), <code>run_e2e_rated.ts</code>, <code>chain_of_custody.ts</code>. Unit tests colocated (<code>kb.test.ts</code>, <code>normalize.test.ts</code>).</td></tr>
|
||||
<tr><td class="mono">config/</td><td><code>models.json</code> — authoritative 5-tier model matrix (T1 hot local / T2 review local / T3 overview cloud / T4 strategic / T5 gatekeeper). Per-tier context_window + context_budget + overflow_policy. Read at runtime by scenario.ts; hot-swap friendly.</td></tr>
|
||||
<tr><td class="mono">docs/</td><td><code>PRD.md</code>, <code>PHASES.md</code>, <code>DECISIONS.md</code> (20 ADRs). Every significant architectural choice has an ADR with the alternatives that were rejected and why.</td></tr>
|
||||
<tr><td class="mono">data/</td><td>Default local object store. Parquet files per dataset, append-log batches, HNSW trial journals, promotion registries, <code>_playbook_memory/state.json</code> (now with retirement fields — Phase 25), catalog manifests. Plus four learning-loop directories: <code>_kb/</code> (signatures, outcomes, recommendations, error_corrections, config_snapshots, staffers), <code>_playbook_lessons/</code> (T3 cross-day lessons archived per run), <code>_observer/ops.jsonl</code> (append journal, durable scenario outcome stream), <code>_chunk_cache/</code> (spec'd for Phase 21 Rust port). Rebuildable from repo + this dir alone.</td></tr>
|
||||
<tr><td class="mono">mcp-server/</td><td>Bun/TypeScript public-facing app + MCP tool surface. Serves <code>devop.live/lakehouse</code>. Pages: dashboard / console / profiler / contractor / proof / spec / onboard / alerts / workspaces. Routes: <code>/search /match /log /log_failure /clients/:c/blacklist /intelligence/* /staffers /memory/query /models/matrix /system/summary</code>. Observer sibling at <code>observer.ts</code> on :3800 for event ingest.</td></tr>
|
||||
<tr><td class="mono">auditor/</td><td>External claim-vs-diff verifier on PRs. Polls Gitea for open PRs, builds adversarial prompt from PRD invariants + staffing matrix, alternates Kimi K2.6 ↔ Haiku 4.5 by SHA, auto-promotes Claude Opus 4.7 on diffs >100k chars. Per-PR cap=3 with auto-reset on each new head SHA. Verdicts at <code>data/_auditor/kimi_verdicts/</code>.</td></tr>
|
||||
<tr><td class="mono">tests/multi-agent/</td><td>Multi-agent scenario harness + memory stack. <code>agent.ts</code>, <code>scenario.ts</code> (contracts + staffer + tool_level), <code>kb.ts</code> (KB indexing, competence scoring), <code>normalize.ts</code>, <code>memory_query.ts</code>, <code>run_e2e_rated.ts</code>. Unit tests colocated.</td></tr>
|
||||
<tr><td class="mono">scripts/distillation/</td><td>Distillation substrate v1.0.0 (frozen at tag <code>distillation-v1.0.0</code> / commit <code>e7636f2</code>). 145 unit tests, 22/22 acceptance, 16/16 audit-full, bit-identical reproducibility. Multi-layer contamination firewall on SFT exports.</td></tr>
|
||||
<tr><td class="mono">config/</td><td><code>modes.toml</code> — task_class → mode/model router (<code>scrum_review</code>, <code>contract_analysis</code>, <code>staffing_inference</code>, <code>pr_audit</code>, <code>doc_drift_check</code>, <code>fact_extract</code>). <code>providers.toml</code> — 5 active providers (ollama, ollama_cloud, openrouter, opencode 40-model, kimi direct). <code>routing.toml</code> — cost gates per task class.</td></tr>
|
||||
<tr><td class="mono">docs/</td><td><code>PRD.md</code>, <code>PHASES.md</code>, <code>DECISIONS.md</code> (21 ADRs). Every significant architectural choice has an ADR with the alternatives that were rejected and why.</td></tr>
|
||||
<tr><td class="mono">data/</td><td>Default local object store. Parquet datasets, append-log batches, HNSW trial journals, promotion registries, <code>_playbook_memory/state.json</code>, <code>_pathway_memory/state.json</code> (88 traces, 11/11 successful replays, ADR-021), catalog manifests. Plus learning-loop directories: <code>_kb/</code>, <code>_playbook_lessons/</code>, <code>_observer/ops.jsonl</code>, <code>_auditor/kimi_verdicts/</code>. Rebuildable from repo + this dir alone.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@ -199,20 +204,42 @@ table.plain tr:hover td{background:#0d1117}
|
||||
<li>Ollama swaps to the profile's model via <code>keep_alive=0</code>; only one model in VRAM at a time</li>
|
||||
</ul>
|
||||
|
||||
<h3>Model matrix (Phase 20)</h3>
|
||||
<p>Five tiers declared in <code>config/models.json</code>. Each call site picks the tier appropriate to its purpose — hot-path JSON emitters get fast local, overview/strategic/gatekeeper decisions get thinking models on cloud. Every tier carries <code>context_window</code>, <code>context_budget</code>, and <code>overflow_policy</code>.</p>
|
||||
<h3>Provider fleet — 5 active, 40+ frontier models reachable</h3>
|
||||
<p>Declared in <code>config/providers.toml</code> + <code>config/modes.toml</code>. Gateway is an OpenAI-compatible drop-in middleware: any consumer that speaks <code>POST /v1/chat/completions</code> gets routing, audit, cost telemetry, and the full memory substrate behind every call.</p>
|
||||
<table class="plain">
|
||||
<thead><tr><th>Tier</th><th>Purpose</th><th>Primary model</th><th>Frequency</th></tr></thead>
|
||||
<thead><tr><th>Provider</th><th>Reach</th><th>Use case</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>T1 hot</td><td>Per tool call — SQL gen, hybrid_search, propose_done</td><td><code>qwen3.5:latest</code> local, <code>think:false</code></td><td>50-200/scenario</td></tr>
|
||||
<tr><td>T2 review</td><td>Per-step consensus, drift flagging</td><td><code>qwen3:latest</code> local, <code>think:false</code></td><td>5-14/event</td></tr>
|
||||
<tr><td>T3 overview</td><td>Mid-day checkpoints + cross-day lesson distill</td><td><code>gpt-oss:120b</code> Ollama Cloud, thinking on</td><td>1-3/scenario</td></tr>
|
||||
<tr><td>T4 strategic</td><td>Pattern re-ranking, weekly gap audit</td><td><code>qwen3.5:397b</code> cloud</td><td>1-10/day</td></tr>
|
||||
<tr><td>T5 gatekeeper</td><td>Schema migrations, autotune config changes</td><td><code>kimi-k2-thinking</code> cloud, audit-logged</td><td>1-5/day</td></tr>
|
||||
<tr><td><code>ollama</code></td><td>localhost:3200 — local sidecar over Ollama</td><td>Hot-path JSON emitters, embeddings, last-resort rescue</td></tr>
|
||||
<tr><td><code>ollama_cloud</code></td><td>ollama.com bearer key — gpt-oss:120b, qwen3-coder:480b, deepseek-v3.1:671b, kimi-k2:1t, mistral-large-3:675b, qwen3.5:397b</td><td>Strong-model reviewer rungs, T3+ overview, scrum master pipeline</td></tr>
|
||||
<tr><td><code>openrouter</code></td><td>openrouter.ai/api/v1 — 343 models incl. Anthropic/Google/OpenAI/MiniMax/Qwen, paid + free tiers</td><td>Paid ladder for observer escalations, free-tier rescue</td></tr>
|
||||
<tr><td><code>opencode</code></td><td>opencode.ai/zen/v1 — <strong>40 frontier models reachable through ONE sk-* key</strong>: Claude Opus 4.7 / Sonnet / Haiku, GPT-5.5-pro / 5.4 / codex variants, Gemini 3.1-pro, Kimi K2.6, GLM 5.1, DeepSeek, Qwen 3.6+, MiniMax, plus 4 free-tier</td><td>Cross-architecture tie-breakers, auditor cross-lineage (Haiku 4.5 + Opus 4.7), high-context reasoning (Opus on diffs >100k chars)</td></tr>
|
||||
<tr><td><code>kimi</code></td><td>api.kimi.com/coding/v1 — direct Kimi For Coding</td><td>kimi_architect when ollama_cloud rate-limits; TOS-clean primary path</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p><strong>Key mechanical finding (2026-04-21):</strong> qwen3.5 and qwen3 are <em>thinking</em> models — they burn ~650 tokens of hidden reasoning before emitting the visible response. For hot-path JSON emitters this meant 400-token budgets returned empty strings. Fix: <code>think: false</code> plumbed through sidecar's <code>/generate</code> endpoint; hot path disables thinking (structure matters more than reasoning depth), overseer tiers keep it on. Mistral was dropped entirely after a 0/14 fill rate on complex scenarios (decoder-level malformed-JSON bug, not a prompt issue).</p>
|
||||
<p><strong>Continuation primitive (Phase 21):</strong> <code>generateContinuable()</code> handles output-overflow without <code>max_tokens</code> tourniquets — empty response → geometric backoff retry; truncated-JSON → continue with partial as scratchpad. <code>generateTreeSplit()</code> handles input-overflow via map-reduce with running scratchpad. Both respect <code>assertContextBudget()</code> so silent truncation can't happen.</p>
|
||||
|
||||
<h3>The 9-rung cloud-first ladder</h3>
|
||||
<p>Defined in <code>tests/real-world/scrum_master_pipeline.ts</code> as <code>const LADDER</code>. Each attempt is evaluated by <code>isAcceptable()</code> = chars ≥ 3800 ∧ not malformed JSON-only. On reject, the next rung sees a learning preamble carrying the prior rejection reason.</p>
|
||||
<pre>1 ollama_cloud / kimi-k2:1t 1T params · flagship
|
||||
2 ollama_cloud / qwen3-coder:480b coding specialist
|
||||
3 ollama_cloud / deepseek-v3.1:671b reasoning
|
||||
4 ollama_cloud / mistral-large-3:675b deep analysis
|
||||
5 ollama_cloud / gpt-oss:120b reliable workhorse
|
||||
6 ollama_cloud / qwen3.5:397b dense final thinker
|
||||
7 openrouter / openai/gpt-oss-120b:free rescue tier
|
||||
8 openrouter / google/gemma-3-27b-it:free fastest rescue
|
||||
9 ollama / qwen3.5:latest last-resort local</pre>
|
||||
|
||||
<h3>N=3 consensus + cross-architecture tie-breaker</h3>
|
||||
<p>Every audit and every consensus-required call fires the primary reviewer N=3 times in parallel (Promise.all — wall-clock = single call). Aggregate votes per claim_idx, majority wins. On a 1-1-1 split, a tie-breaker model with <em>different architecture</em> (qwen3-coder:480b vs primary gpt-oss/kimi) is invoked. Every disagreement, even when majority resolves, writes to <code>data/_kb/audit_discrepancies.jsonl</code>. Closes the cloud-non-determinism gap: <code>temp=0</code> isn't actually deterministic in practice across hours; consensus + cross-architecture tie-break stabilizes verdicts.</p>
|
||||
|
||||
<h3>Auditor cross-lineage (Kimi ↔ Haiku ↔ Opus)</h3>
|
||||
<p>Every push to PR #11 triggers <code>auditor/audit.ts</code> within ~90s. To prevent a single model lineage's blind spots from becoming the system's blind spots, audits alternate between Kimi K2.6 (Moonshot lineage) and Haiku 4.5 (Anthropic lineage) by head SHA. Diffs over 100k chars auto-promote to Claude Opus 4.7 (Anthropic frontier). Per-PR cap of 3 audits with auto-reset on each new head SHA prevents infinite-loop spend. <strong>Latest verdict on c3c9c21:</strong> Haiku 4.5, 24.6s, 100% grounding-verified across 10 findings.</p>
|
||||
|
||||
<h3>Distillation v1.0.0 — the frozen substrate</h3>
|
||||
<p>The substrate the auditor and mode runner sit on is tagged at <code>distillation-v1.0.0</code> / commit <code>e7636f2</code>. <strong>145 unit tests pass · 22/22 acceptance invariants · 16/16 audit-full checks · bit-identical reproducibility verified.</strong> The distillation phase exports clean SFT / RAG / preference samples with a multi-layer contamination firewall (<code>SFT_NEVER</code> constant + scorer category mapping + acceptance fixtures); the auditor consumes the substrate. The frozen tag means: any future "the system regressed" question has a baseline to bisect against, byte-for-byte.</p>
|
||||
|
||||
<h3>Continuation primitive (Phase 21)</h3>
|
||||
<p><code>generateContinuable()</code> handles output-overflow without <code>max_tokens</code> tourniquets — empty response → geometric backoff retry; truncated-JSON → continue with partial as scratchpad. <code>generateTreeSplit()</code> handles input-overflow via map-reduce with running scratchpad. Both respect <code>assertContextBudget()</code> so silent truncation can't happen. Now Rust-native in <code>crates/aibridge/src/continuation.rs</code> (Phase 44).</p>
|
||||
|
||||
<h3>Per-staffer tool_level (Phase 23)</h3>
|
||||
<p>Scenarios can be scoped to a specific coordinator (<code>staffer: {id, name, tenure_months, role, tool_level}</code>). <code>tool_level</code> controls which tiers are available:</p>
|
||||
@ -265,6 +292,12 @@ table.plain tr:hover td{background:#0d1117}
|
||||
<tr><td>Boost workers based on past success</td><td>No</td><td>Yes (Phase 19 playbook_memory)</td></tr>
|
||||
<tr><td>Penalize workers based on past failure</td><td>No</td><td>Yes (<code>/log_failure</code> + <code>0.5<sup>n</sup></code> penalty)</td></tr>
|
||||
<tr><td>Surface traits across past fills</td><td>No</td><td>Yes (<code>/vectors/playbook_memory/patterns</code>)</td></tr>
|
||||
<tr><td>Per-staffer relevance gradient</td><td>No</td><td>Yes — same query reshapes per coordinator (<code>staffer_id</code> on <code>/intelligence/chat</code>); MARIA'S MEMORY pill labels the playbook context with the active coordinator</td></tr>
|
||||
<tr><td>Triage in one shot — late-worker → backfills + draft SMS</td><td>No</td><td>Yes (<code>/intelligence/chat</code> Route 6 — pulls profile + 5 same-role same-geo backfills sorted by responsiveness + drafts client SMS in ~250ms)</td></tr>
|
||||
<tr><td>Permit → fill plan derivation (forward demand)</td><td>No</td><td>Yes (<code>/intelligence/permit_contracts</code> — Chicago Socrata permit → role / headcount / deadline / fill probability / gross revenue per card)</td></tr>
|
||||
<tr><td>Public-issuer attribution across contractor graph</td><td>No</td><td>Yes (<code>/intelligence/profiler_index</code> — direct + parent + co-permit associated tickers; live Stooq prices)</td></tr>
|
||||
<tr><td>Cross-lineage AI audit on every PR</td><td>No</td><td>Yes (auditor crate — Kimi K2.6 ↔ Haiku 4.5 alternation + Opus 4.7 auto-promote on big diffs)</td></tr>
|
||||
<tr><td>Pathway memory — system-level hot-swap by task fingerprint</td><td>No</td><td>Yes (88 traces, 11/11 successful replays, 100% reuse rate, ADR-021)</td></tr>
|
||||
<tr><td>Predict staffing demand from external data</td><td>No</td><td>Yes (Chicago permit feed + 30-day rolling forecast)</td></tr>
|
||||
<tr><td>Count down to staffing deadline per contract</td><td>No</td><td>Yes (permit issue_date + heuristic timeline)</td></tr>
|
||||
<tr><td>Explain why each candidate ranked</td><td>No</td><td>Yes (boost chip + narrative citations + memory pattern)</td></tr>
|
||||
@ -278,7 +311,7 @@ table.plain tr:hover td{background:#0d1117}
|
||||
<div class="chapter" id="ch6">
|
||||
<div class="num">Chapter 6</div>
|
||||
<h2>How it gets better over time</h2>
|
||||
<div class="lede">Compounding learning across seven paths. The first three are automatic background loops. Paths 4-7 landed 2026-04-21 and turn the system into a reinforcement-learning pipeline: outcomes → knowledge base → pathway recommendations → cloud rescue → competence-weighted retrieval → observer analysis. All seven happen without operator intervention.</div>
|
||||
<div class="lede">Compounding learning across ten paths. The first three are automatic background loops. Paths 4-7 (Phase 22-24) added the reinforcement layer: outcomes → KB → recommendations → cloud rescue → competence-weighted retrieval → observer analysis. Paths 7-9 (Phase 25-43, 2026-04-26→27) added the system-level memory layers: pathway memory by task fingerprint (ADR-021), per-staffer hot-swap, and the Construction Activity Signal Engine. All ten happen without operator intervention.</div>
|
||||
|
||||
<h3>Path 1 — Playbook boost with geo + role prefilter (Phase 19 + refinement)</h3>
|
||||
<p>Every sealed fill is seeded to <code>playbook_memory</code>. The boost fires inside <code>/vectors/hybrid</code> when <code>use_playbook_memory: true</code>. Math, tightened 2026-04-21 after a diagnostic pass found globally-ranked playbooks were missing the SQL-filtered candidate pool entirely:</p>
|
||||
@ -311,7 +344,19 @@ boost[(city, state, name)] = min(Σ per_worker, 0.25)</pre>
|
||||
<p>Answers "who handled this" as a first-class matrix-index dimension. Each scenario carries <code>staffer: {id, name, tenure_months, role, tool_level}</code>. After every run, <code>recomputeStafferStats(staffer_id)</code> aggregates their fill_rate, turn efficiency, citation density, rescue rate into a single <code>competence_score</code> (0.45·fill + 0.20·turn_eff + 0.20·cites + 0.15·rescue).</p>
|
||||
<p><code>findNeighbors</code> returns <code>weighted_score = cosine × max_staffer_competence</code> — top-performer playbooks rank above juniors' on similar scenarios. Auto-discovery emerges: running 4 staffers × 3 contracts × 3 rounds surfaced Rachel D. Lewis (Welder Nashville) with 18 endorsements across all 4 staffers, Angela U. Ward (Machine Op Indianapolis) with 19 — reliable-performer labels the system built without human tagging.</p>
|
||||
|
||||
<h3>Path 7 — Observer outcome ingest (Phase 24)</h3>
|
||||
<h3>Path 7 — Pathway memory (ADR-021 — semantic-correctness matrix layer)</h3>
|
||||
<p>Memory at the system layer, not the worker layer. Every accepted scrum review writes a <code>PathwayTrace</code> with the full backtrack: file fingerprint, model used, signal class, KB chunks consulted, observer events, semantic flags (UnitMismatch, TypeConfusion, OffByOne, StaleReference, DeadCode, BoundaryViolation, …), bug fingerprints. A new query that fingerprints to the same trace can hot-swap to the prior result without re-running the 9-rung escalation. Five-factor hot-swap gate: narrow fingerprint match AND audit consensus pass AND replay_count ≥ 3 (probation) AND success_rate ≥ 0.80 AND NOT retired AND vector cosine ≥ 0.90.</p>
|
||||
<p><strong>Live state (verified on this load):</strong> 88 traces · 11 / 11 successful replays · 100% reuse rate · probation gate crossed. Endpoints: <code>/vectors/pathway/insert</code> · <code>/query</code> · <code>/record_replay</code> · <code>/stats</code> · <code>/bug_fingerprints</code>. Spec: <code>docs/DECISIONS.md</code> ADR-021.</p>
|
||||
|
||||
<h3>Path 8 — Per-staffer hot-swap index</h3>
|
||||
<p>Memory scoped to whoever's acting. <code>/intelligence/chat</code> accepts <code>staffer_id</code>; on match, defaults state filter to staffer territory, scopes playbook-pattern geo to staffer's primary city/state, and surfaces <code>response.staffer.name</code> so the UI relabels MEMORY → MARIA'S MEMORY. Same query "forklift operators" returns 167 IL workers as Maria, 89 IN as Devon, 16 WI as Aisha. The corpus stays intact; the relevance gradient is per coordinator; each accumulates fills independently.</p>
|
||||
<p><strong>Roster:</strong> <code>/staffers</code> endpoint reads from <code>STAFFERS</code> in <code>mcp-server/index.ts</code>. Three personas today (Maria/Devon/Aisha); architecture generalizes — every new metro adds territories, not code paths.</p>
|
||||
|
||||
<h3>Path 9 — Construction Activity Signal Engine</h3>
|
||||
<p>Memory at the network layer. Every contractor in the corpus is also a forward indicator on the public equities they touch via three attribution flavors: <code>direct</code> (contractor IS the public issuer — SEC tickers index match), <code>parent</code> (subsidiary of a public parent — curated KNOWN_PARENT_MAP, e.g. Turner → HOC.DE via Hochtief AG), <code>associated</code> (co-permit network — Bob's Electric appears with TARGET CORPORATION 3+ times → inherits TGT). The associated path is the moat: a staffing-permit dataset that maps contractor-to-public-issuer is not commercially available; we synthesize it from the Socrata co-occurrence graph.</p>
|
||||
<p><strong>BAI (Building Activity Index)</strong> = attribution-weighted average day-change across surfaced issuers. <strong>Indexed build value</strong> = total $ of permits attributable to ANY public issuer in scope. <strong>Network depth</strong> = issuers / total attribution edges. Cross-metro replication explicit in the architecture — Chicago is Phase 1; NYC DOB / LA County / Houston BCD / Boston ISD / DC DCRA are all Socrata-shaped, ship as config-only adapters.</p>
|
||||
|
||||
<h3>Path 10 — Observer outcome ingest (Phase 24)</h3>
|
||||
<p>Observer runs as <code>lakehouse-observer.service</code>, now with an HTTP listener on <code>:3800</code>. Scenarios POST per-event outcomes to <code>/event</code> with full provenance (staffer_id, sig_hash, event_kind, role, city, state, rescue flags). Observer's ERROR_ANALYZER and PLAYBOOK_BUILDER loops consume them alongside MCP-wrapped ops. Persistence switched from the old <code>/ingest/file</code> REPLACE path to an append-only <code>data/_observer/ops.jsonl</code> journal so the trace survives across restarts.</p>
|
||||
|
||||
<h3>Input normalizer + unified memory query</h3>
|
||||
@ -399,7 +444,11 @@ boost[(city, state, name)] = min(Σ per_worker, 0.25)</pre>
|
||||
<div class="chapter" id="ch9">
|
||||
<div class="num">Chapter 9</div>
|
||||
<h2>Per-staffer context</h2>
|
||||
<div class="lede">Twenty staffers don't see the same UI state. Each one's session is shaped by their active profile, their workspaces, their assigned contracts, and their client's blacklists.</div>
|
||||
<div class="lede">Twenty staffers don't see the same UI state. Each one's session is shaped by their identity (the per-staffer hot-swap index — Path 8 in Ch6), their active profile, their workspaces, their assigned contracts, and their client's blacklists.</div>
|
||||
|
||||
<h3>Per-staffer hot-swap index (the recent layer)</h3>
|
||||
<p>Maria runs Chicago. Devon runs Indianapolis. Aisha runs Wisconsin/Michigan. They share one corpus, but search results, recurring-skill patterns, and playbook context all reshape to whoever is acting. <code>/intelligence/chat</code> accepts <code>staffer_id</code>; on match, defaults state filter to the staffer's territory, scopes playbook-pattern geo to their primary city/state, and surfaces <code>response.staffer.name</code> so the UI relabels MEMORY → <em>MARIA'S MEMORY</em>.</p>
|
||||
<p><strong>Verified end-to-end:</strong> same query "forklift operators" returns 167 IL workers as Maria, 89 IN as Devon, 16 WI as Aisha (live numbers; refresh the profiler page to recompute). The corpus stays intact; the relevance gradient is per coordinator. As each accumulates fills, their slice of the playbook compounds independently. <strong>Roster:</strong> <code>/staffers</code> endpoint, declared in <code>STAFFERS</code> in <code>mcp-server/index.ts</code>. Adding a staffer is one append; the architecture is metro-agnostic by construction.</p>
|
||||
|
||||
<h3>Active profile (Phase 17)</h3>
|
||||
<p>Scopes every search. A <code>staffing-recruiter</code> profile bound to <code>workers_500k</code> sees only that dataset. A <code>security-analyst</code> profile bound to <code>threat_intel</code> cannot see worker data. <code>GET /vectors/profile/<id>/audit</code> records every tool invocation by model identity.</p>
|
||||
@ -446,7 +495,7 @@ boost[(city, state, name)] = min(Σ per_worker, 0.25)</pre>
|
||||
|
||||
<div class="step"><div class="n">12:30</div><div class="body"><strong>Client pushes 20 new contracts + 1M ATS delta.</strong> Ch7 scale flow fires. Ingest in seconds; embedding refresh kicks off as a background job. Searches continue against old embeddings.</div></div>
|
||||
|
||||
<div class="step"><div class="n">14:00</div><div class="body"><strong>Emergency: worker Dave no-showed.</strong> Sarah clicks No-show button on Dave's card → <code>/log_failure</code> → <code>mark_failed</code> records a penalty. Next similar query dampens Dave's boost by 0.5. Sarah continues the refill — the refill excludes Dave and the 2 others already booked for this shift.</div></div>
|
||||
<div class="step"><div class="n">14:00</div><div class="body"><strong>Emergency: worker Dave no-showed.</strong> Sarah types "Dave running late site 4422" into the search box. ~250ms later: triage card with Dave's profile + reliability + responsiveness, draft SMS to client ("dispatching X from local bench, 96% reliability, will confirm arrival"), and 5 same-role same-geo backfills sorted by responsiveness rendered as a green list below. Sarah clicks Copy SMS, pastes to client, clicks Call on the top backfill. <code>/log_failure</code> on Dave records the penalty for the next similar query.</div></div>
|
||||
|
||||
<div class="step"><div class="n">15:00</div><div class="body"><strong>New embeddings live.</strong> Hot-swap promotion. Searches now see all 1M new profiles. Sarah's noon query re-run would produce different top-5.</div></div>
|
||||
|
||||
@ -468,14 +517,15 @@ boost[(city, state, name)] = min(Σ per_worker, 0.25)</pre>
|
||||
|
||||
<h4>Deferred — real architectural work, just not shipped yet</h4>
|
||||
<ul>
|
||||
<li><strong>BAI persistence + backtesting.</strong> Building Activity Index is computed live per page load. To validate the thesis (permit activity precedes equity moves) we need the daily series saved over months. Architectural support exists (<code>data/_kb/audit_baselines.jsonl</code> append pattern); just hasn't run long enough.</li>
|
||||
<li><strong>NYC DOB adapter.</strong> Architecture is metro-agnostic — Chicago is Phase 1. NYC DOB ships next as a config-only Socrata adapter; LA County, Houston BCD, Boston ISD, DC DCRA queue behind it. Each new metro multiplies network edges without multiplying the codebase.</li>
|
||||
<li><strong>12 awaiting public-data sources for contractor profile.</strong> DOL Wage & Hour, EPA ECHO, MSHA, BBB, PACER civil suits, UCC liens, D&B credit, State licensure, Surety bonds, DOT/FMCSA, State UI claims, DOL RAPIDS apprenticeships. Listed by name on every contractor profile with a one-line "would show:" sample. Each ships as a Socrata-style adapter; engineering scope is concrete.</li>
|
||||
<li><strong>Rate / margin awareness.</strong> Worker pay expectations vs contract bill rate not modeled. Requires adding <code>pay_rate</code> to workers, <code>bill_rate</code> to contracts, and a filter + warning path. Partially addressed via <code>ContractTerms.budget_per_hour_max</code> passed to T3/rescue prompts, but the match-time filter isn't wired yet.</li>
|
||||
<li><strong>Mem0-style UPDATE / DELETE / NOOP operations on playbooks.</strong> Today <code>/seed</code> only ADDs. Same <code>(operation, date)</code> pair appends a duplicate instead of refining an existing entry. Phase 26 item — cheap to add, moderate payoff.</li>
|
||||
<li><strong>Letta working-memory hot cache.</strong> Every boost query scans all active playbook entries from in-memory state. 1.9K today; cheap. Will bite somewhere north of 100K. LRU for the last-N playbooks or current-sig neighborhood deferred until that ceiling approaches.</li>
|
||||
<li><strong>Chunking cache (Phase 21 Rust port).</strong> TS primitives <code>generateContinuable</code> + <code>generateTreeSplit</code> are wired, but <code>crates/aibridge/src/{continuation.rs, tree_split.rs}</code> + <code>crates/storaged/src/chunk_cache.rs</code> remain queued. Gateway-side callers currently don't have the same protection against silent truncation that the TS test harness does.</li>
|
||||
<li><strong>Mem0-style UPDATE / DELETE / NOOP operations on playbooks.</strong> Today <code>/seed</code> only ADDs. Same <code>(operation, date)</code> pair appends a duplicate instead of refining an existing entry. Cheap to add, moderate payoff.</li>
|
||||
<li><strong>Letta working-memory hot cache.</strong> Every boost query scans all active playbook entries from in-memory state. ~5K today; cheap. Will bite somewhere north of 100K. Deferred until the ceiling approaches.</li>
|
||||
<li><strong>Confidence calibration.</strong> Top-K is a rank, not a probability. No calibrated "85% likely to accept" score. Requires outcome-labeled training data.</li>
|
||||
<li><strong>Neural re-ranker.</strong> Phase 19 is statistical + semantic (now with geo + role prefilter, Phase 25 retirement). A (query, candidate, outcome)-trained re-ranker is deferred only if the statistical floor plateaus below usable recall — current 14× citation lift on identical inputs suggests it hasn't.</li>
|
||||
<li><strong>Observer → autotune feedback wire.</strong> Phase 24 streams scenario outcomes into <code>data/_observer/ops.jsonl</code>; autotune agent still runs on its own HNSW-trial schedule and hasn't subscribed to the outcome metric stream yet. Phase 26+ item — connects the last loop.</li>
|
||||
<li><strong>call_log cross-reference.</strong> Infrastructure present; current synthetic candidates table is too small to cross-ref. Fixes when real ATS lands.</li>
|
||||
<li><strong>SEC name-to-ticker fuzzy precision.</strong> Current matcher requires ≥2 non-stopword overlap; rare false positives still surface (saw FLG attach to a PNC-adjacent contractor once). Tightenable to require an explicit allow-list for production trading use.</li>
|
||||
<li><strong>Tighter integration of pathway memory + scrum loop.</strong> ADR-021 substrate is shipped (88 traces, 11/11 replays). The hot-swap gate fires correctly; what's deferred is automatic mode-runner short-circuit when a high-confidence pathway match is available before any cloud call burns.</li>
|
||||
</ul>
|
||||
|
||||
<h4>Non-goals — explicitly out of scope</h4>
|
||||
@ -496,6 +546,6 @@ boost[(city, state, name)] = min(Σ per_worker, 0.25)</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">Lakehouse spec · v2 2026-04-21 · Phases 19-25 shipped (playbook boost, model matrix, continuation, KB, staffer competence, observer ingest, validity windows) · maintained from <code>docs/DECISIONS.md</code> · <a href="proof">architecture live-tested</a> · <a href="console">walkthrough</a></div>
|
||||
<div class="footer">Lakehouse spec · v3 2026-04-27 · Phases 19-45 shipped (playbook boost, KB, staffer competence, observer ingest, validity windows, distillation v1.0.0 substrate frozen at e7636f2, gateway as OpenAI-compat drop-in, mode runner, validator + iterate, pathway memory ADR-021, per-staffer hot-swap, Construction Activity Signal Engine) · maintained from <code>docs/DECISIONS.md</code> · <a href="proof">architecture live-tested</a> · <a href="console">walkthrough</a> · <a href="profiler">profiler</a></div>
|
||||
|
||||
</body></html>
|
||||
|
||||
178
mcp-server/tif_polygons.ts
Normal file
178
mcp-server/tif_polygons.ts
Normal file
@ -0,0 +1,178 @@
|
||||
// TIF (Tax Increment Financing) district point-in-polygon lookup.
|
||||
// Given a property's lat/long, returns which Chicago TIF district (if
|
||||
// any) contains it. TIF districts are public-subsidy zones — a property
|
||||
// inside one is receiving city tax-increment funding for its build.
|
||||
// Strong "this project has financial backing" signal for the Project Index.
|
||||
//
|
||||
// Data: data/_entity_cache/tif_districts.geojson (Chicago Open Data
|
||||
// dataset eejr-xtfb, 100 active districts, 3.2MB). Refresh by re-running
|
||||
// `curl ... eejr-xtfb.geojson > tif_districts.geojson` — districts
|
||||
// change rarely (only when city council approves new ones or repeals).
|
||||
//
|
||||
// Algorithm: classic ray-casting. For each MultiPolygon's outer ring,
|
||||
// count edge crossings of an east-going horizontal ray from the point.
|
||||
// Odd crossings = inside. Holes (inner rings) flip the parity. Library-
|
||||
// free; correct for arbitrary polygons including the irregular Chicago
|
||||
// shapes which often have many small detours.
|
||||
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { existsSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
const TIF_GEOJSON = join("/home/profit/lakehouse/data/_entity_cache", "tif_districts.geojson");
|
||||
|
||||
type LngLat = [number, number]; // GeoJSON convention: [longitude, latitude]
|
||||
type Ring = LngLat[];
|
||||
type Polygon = Ring[]; // outer ring + optional inner rings (holes)
|
||||
type MultiPolygon = Polygon[];
|
||||
|
||||
type TifFeature = {
|
||||
name: string;
|
||||
trim_name?: string;
|
||||
ref?: string;
|
||||
approval_date?: string;
|
||||
expiration?: string;
|
||||
type?: string; // T-1xx etc.
|
||||
comm_area?: string;
|
||||
wards?: string;
|
||||
// Bounding box for quick reject
|
||||
bbox: { minLon: number; minLat: number; maxLon: number; maxLat: number };
|
||||
geometry: MultiPolygon;
|
||||
};
|
||||
|
||||
let tifIdx: TifFeature[] | null = null;
|
||||
|
||||
function bboxOfMultiPolygon(mp: MultiPolygon): TifFeature["bbox"] {
|
||||
let minLon = Infinity, minLat = Infinity, maxLon = -Infinity, maxLat = -Infinity;
|
||||
for (const poly of mp) {
|
||||
for (const ring of poly) {
|
||||
for (const [lon, lat] of ring) {
|
||||
if (lon < minLon) minLon = lon;
|
||||
if (lat < minLat) minLat = lat;
|
||||
if (lon > maxLon) maxLon = lon;
|
||||
if (lat > maxLat) maxLat = lat;
|
||||
}
|
||||
}
|
||||
}
|
||||
return { minLon, minLat, maxLon, maxLat };
|
||||
}
|
||||
|
||||
async function ensureLoaded(): Promise<TifFeature[]> {
|
||||
if (tifIdx) return tifIdx;
|
||||
if (!existsSync(TIF_GEOJSON)) {
|
||||
tifIdx = [];
|
||||
return tifIdx;
|
||||
}
|
||||
try {
|
||||
const raw = JSON.parse(await readFile(TIF_GEOJSON, "utf-8"));
|
||||
const out: TifFeature[] = [];
|
||||
for (const f of raw.features || []) {
|
||||
const geom = f.geometry;
|
||||
if (!geom) continue;
|
||||
// Normalize Polygon → MultiPolygon for uniform iteration
|
||||
let mp: MultiPolygon;
|
||||
if (geom.type === "MultiPolygon") {
|
||||
mp = geom.coordinates;
|
||||
} else if (geom.type === "Polygon") {
|
||||
mp = [geom.coordinates];
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
const props = f.properties || {};
|
||||
out.push({
|
||||
name: props.name || "Unknown TIF",
|
||||
trim_name: props.name_trim,
|
||||
ref: props.ref,
|
||||
approval_date: props.approval_d,
|
||||
expiration: props.expiration,
|
||||
type: props.type,
|
||||
comm_area: props.comm_area,
|
||||
wards: props.wards,
|
||||
bbox: bboxOfMultiPolygon(mp),
|
||||
geometry: mp,
|
||||
});
|
||||
}
|
||||
tifIdx = out;
|
||||
return tifIdx;
|
||||
} catch (e) {
|
||||
console.warn("[tif] load failed:", (e as Error).message);
|
||||
tifIdx = [];
|
||||
return tifIdx;
|
||||
}
|
||||
}
|
||||
|
||||
// Ray-casting point-in-polygon (single ring). Returns true if (lon, lat)
|
||||
// is strictly inside the ring. Edge cases (point exactly on a vertex)
|
||||
// resolve by half-open interval convention; for our use case (Chicago
|
||||
// boundary precision is ~1m, sites are point queries) this is fine.
|
||||
function pointInRing(lon: number, lat: number, ring: Ring): boolean {
|
||||
let inside = false;
|
||||
const n = ring.length;
|
||||
for (let i = 0, j = n - 1; i < n; j = i++) {
|
||||
const [xi, yi] = ring[i];
|
||||
const [xj, yj] = ring[j];
|
||||
const intersect =
|
||||
yi > lat !== yj > lat &&
|
||||
lon < ((xj - xi) * (lat - yi)) / (yj - yi + 0) + xi;
|
||||
if (intersect) inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
|
||||
// Polygon = outer ring + holes. Inside outer AND not inside any hole.
|
||||
function pointInPolygon(lon: number, lat: number, polygon: Polygon): boolean {
|
||||
if (polygon.length === 0) return false;
|
||||
if (!pointInRing(lon, lat, polygon[0])) return false;
|
||||
for (let i = 1; i < polygon.length; i++) {
|
||||
if (pointInRing(lon, lat, polygon[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export type TifMatch = {
|
||||
name: string;
|
||||
ref?: string;
|
||||
approval_date?: string;
|
||||
expiration?: string;
|
||||
comm_area?: string;
|
||||
wards?: string;
|
||||
};
|
||||
|
||||
export async function findTifDistrict(
|
||||
longitude: number | string | undefined,
|
||||
latitude: number | string | undefined,
|
||||
): Promise<TifMatch | null> {
|
||||
const lon = typeof longitude === "string" ? parseFloat(longitude) : longitude;
|
||||
const lat = typeof latitude === "string" ? parseFloat(latitude) : latitude;
|
||||
if (!lon || !lat || isNaN(lon) || isNaN(lat)) return null;
|
||||
const idx = await ensureLoaded();
|
||||
if (idx.length === 0) return null;
|
||||
for (const f of idx) {
|
||||
// Bbox reject — cheap O(1) skip for the 99% of districts that
|
||||
// can't possibly contain the point.
|
||||
const b = f.bbox;
|
||||
if (lon < b.minLon || lon > b.maxLon || lat < b.minLat || lat > b.maxLat) continue;
|
||||
// Full point-in-polygon for any polygon in this MultiPolygon
|
||||
for (const poly of f.geometry) {
|
||||
if (pointInPolygon(lon, lat, poly)) {
|
||||
return {
|
||||
name: f.name,
|
||||
ref: f.ref,
|
||||
approval_date: f.approval_date,
|
||||
expiration: f.expiration,
|
||||
comm_area: f.comm_area,
|
||||
wards: f.wards,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function getTifIndexStats(): Promise<{
|
||||
total: number;
|
||||
loaded: boolean;
|
||||
}> {
|
||||
const idx = await ensureLoaded();
|
||||
return { total: idx.length, loaded: idx.length > 0 };
|
||||
}
|
||||
@ -29,8 +29,14 @@ CACHE_DIR.mkdir(parents=True, exist_ok=True)
|
||||
WORKFLOW_PATH = "/opt/ComfyUI/workflows/editorial_hero.json"
|
||||
|
||||
|
||||
def _cache_key(prompt, width, height, steps):
|
||||
return hashlib.sha256(f"{prompt}|{width}|{height}|{steps}".encode()).hexdigest()[:24]
|
||||
def _cache_key(prompt, width, height, steps, seed=None):
|
||||
# Include seed so callers can vary outputs deterministically without
|
||||
# the proxy collapsing to a single cached image. None == legacy
|
||||
# (omitted from the key for backward compatibility).
|
||||
bits = f"{prompt}|{width}|{height}|{steps}"
|
||||
if seed is not None:
|
||||
bits += f"|{seed}"
|
||||
return hashlib.sha256(bits.encode()).hexdigest()[:24]
|
||||
|
||||
def _cache_get(key):
|
||||
fp = CACHE_DIR / f"{key}.webp"
|
||||
@ -40,8 +46,15 @@ def _cache_put(key, img_bytes):
|
||||
(CACHE_DIR / f"{key}.webp").write_bytes(img_bytes)
|
||||
|
||||
|
||||
def _comfyui_generate(prompt, width=1024, height=512, steps=8, seed=None):
|
||||
"""Submit workflow to ComfyUI and wait for result."""
|
||||
def _comfyui_generate(prompt, width=1024, height=512, steps=8, seed=None,
|
||||
negative_prompt=None, cfg=None, sampler=None, scheduler=None):
|
||||
"""Submit workflow to ComfyUI and wait for result.
|
||||
|
||||
Optional overrides — when provided, replace the workflow's defaults.
|
||||
The workflow template at editorial_hero.json was tuned for product
|
||||
hero shots with a "no humans" negative prompt; portrait callers MUST
|
||||
pass `negative_prompt` to avoid the model fighting them on faces.
|
||||
"""
|
||||
# Load workflow template
|
||||
with open(WORKFLOW_PATH) as f:
|
||||
workflow = json.load(f)
|
||||
@ -51,9 +64,21 @@ def _comfyui_generate(prompt, width=1024, height=512, steps=8, seed=None):
|
||||
seed = random.randint(0, 2**32)
|
||||
workflow["3"]["inputs"]["seed"] = seed
|
||||
workflow["3"]["inputs"]["steps"] = steps
|
||||
if cfg is not None:
|
||||
workflow["3"]["inputs"]["cfg"] = cfg
|
||||
if sampler:
|
||||
workflow["3"]["inputs"]["sampler_name"] = sampler
|
||||
if scheduler:
|
||||
workflow["3"]["inputs"]["scheduler"] = scheduler
|
||||
workflow["5"]["inputs"]["width"] = width
|
||||
workflow["5"]["inputs"]["height"] = height
|
||||
workflow["6"]["inputs"]["text"] = prompt
|
||||
# Node 7 is the negative-prompt CLIPTextEncode. The default is tuned
|
||||
# for product hero shots and contains "human, person, face, hand,
|
||||
# fingers, realistic photo of people" — actively sabotaging any
|
||||
# portrait render. Always overwrite when negative_prompt is given.
|
||||
if negative_prompt is not None:
|
||||
workflow["7"]["inputs"]["text"] = negative_prompt
|
||||
|
||||
# Submit to ComfyUI
|
||||
payload = json.dumps({"prompt": workflow}).encode()
|
||||
@ -177,9 +202,20 @@ class ImageHandler(BaseHTTPRequestHandler):
|
||||
height = min(max(int(body.get("height", 720)), 256), 1080)
|
||||
steps = min(max(int(body.get("steps", 50)), 1), 80)
|
||||
seed = body.get("seed")
|
||||
# Portrait-friendly overrides — None means "use workflow default".
|
||||
# negative_prompt MUST be passed by portrait callers to avoid
|
||||
# the workflow's "no humans" baked-in negative.
|
||||
negative_prompt = body.get("negative_prompt")
|
||||
cfg = body.get("cfg")
|
||||
sampler = body.get("sampler")
|
||||
scheduler = body.get("scheduler")
|
||||
|
||||
# Cache check
|
||||
key = _cache_key(prompt, width, height, steps)
|
||||
# Cache check — seed + negative + cfg are part of the key so per-
|
||||
# worker / per-config requests don't collapse to one cached image.
|
||||
key = _cache_key(
|
||||
f"{prompt}||neg={negative_prompt or ''}||cfg={cfg or ''}",
|
||||
width, height, steps, seed,
|
||||
)
|
||||
cached = _cache_get(key)
|
||||
if cached:
|
||||
self._json(200, {"image": cached, "format": "webp", "width": width, "height": height,
|
||||
@ -192,7 +228,11 @@ class ImageHandler(BaseHTTPRequestHandler):
|
||||
try:
|
||||
comfy_check = urllib.request.urlopen(f"{COMFYUI_URL}/system_stats", timeout=3)
|
||||
if comfy_check.status == 200:
|
||||
img_bytes, seed = _comfyui_generate(prompt, width, height, steps, seed)
|
||||
img_bytes, seed = _comfyui_generate(
|
||||
prompt, width, height, steps, seed,
|
||||
negative_prompt=negative_prompt, cfg=cfg,
|
||||
sampler=sampler, scheduler=scheduler,
|
||||
)
|
||||
backend = "comfyui"
|
||||
except:
|
||||
pass
|
||||
@ -210,6 +250,11 @@ class ImageHandler(BaseHTTPRequestHandler):
|
||||
|
||||
elapsed_ms = int((time.time() - t0) * 1000)
|
||||
img_b64 = base64.b64encode(img_bytes).decode()
|
||||
# Recompute key with the actual seed used (when caller passed
|
||||
# None, _comfyui_generate picks a random one and we want the
|
||||
# cache to reflect that so re-requests with the same returned
|
||||
# seed hit the disk).
|
||||
key = _cache_key(prompt, width, height, steps, seed)
|
||||
_cache_put(key, img_bytes)
|
||||
|
||||
self._json(200, {
|
||||
|
||||
225
scripts/staffing/fetch_face_pool.py
Normal file
225
scripts/staffing/fetch_face_pool.py
Normal file
@ -0,0 +1,225 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
fetch_face_pool.py — pull N synthetic headshots from
|
||||
https://thispersondoesnotexist.com/, write to data/headshots/face_NNNN.jpg,
|
||||
optionally tag each with gender via deepface, emit a JSONL manifest.
|
||||
|
||||
Each fetch is a fresh StyleGAN face — no real people. Deterministic per
|
||||
worker mapping happens at serve time (mcp-server hashes the worker key
|
||||
into the pool); this script just builds the pool.
|
||||
|
||||
Usage:
|
||||
python3 scripts/staffing/fetch_face_pool.py --count 300 --concurrency 3
|
||||
python3 scripts/staffing/fetch_face_pool.py --count 50 --no-gender
|
||||
|
||||
Re-running is idempotent: existing face_NNNN.jpg files are skipped, and
|
||||
the manifest is rewritten from disk state.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
|
||||
URL = "https://thispersondoesnotexist.com/"
|
||||
UA = "Lakehouse/1.0 (face-pool fetch · synthetic-only · no real-person tracking)"
|
||||
|
||||
|
||||
def fetch_one(idx: int, out_dir: str) -> tuple[int, str, bool, str | None]:
|
||||
"""Returns (idx, basename, cached, error)."""
|
||||
fname = f"face_{idx:04d}.jpg"
|
||||
full = os.path.join(out_dir, fname)
|
||||
if os.path.exists(full) and os.path.getsize(full) > 1024:
|
||||
return idx, fname, True, None
|
||||
try:
|
||||
req = urllib.request.Request(URL, headers={"User-Agent": UA})
|
||||
with urllib.request.urlopen(req, timeout=20) as resp:
|
||||
blob = resp.read()
|
||||
if len(blob) < 1024:
|
||||
return idx, fname, False, f"response too small ({len(blob)} bytes)"
|
||||
with open(full, "wb") as f:
|
||||
f.write(blob)
|
||||
return idx, fname, False, None
|
||||
except urllib.error.URLError as e:
|
||||
return idx, fname, False, f"urlerror: {e}"
|
||||
except Exception as e:
|
||||
return idx, fname, False, f"{type(e).__name__}: {e}"
|
||||
|
||||
|
||||
def maybe_tag_gender(records: list[dict], out_dir: str) -> dict[str, int]:
|
||||
"""If deepface is installed, label records that don't already have a
|
||||
gender. Returns a count summary; mutates records in place.
|
||||
|
||||
Preservation contract: never overwrites prior `gender` (or any other
|
||||
tag — race/age/excluded — set by tag_face_pool.py). On deepface
|
||||
import failure, leaves existing tags alone instead of resetting them
|
||||
to None. The previous behavior wiped 952 hand-classified rows when
|
||||
fetch_face_pool was re-run from a Python without deepface installed."""
|
||||
try:
|
||||
from deepface import DeepFace # type: ignore
|
||||
except Exception as e:
|
||||
print(f" (deepface unavailable: {e}) — leaving existing tags untouched")
|
||||
for r in records:
|
||||
r.setdefault("gender", None)
|
||||
already = sum(1 for r in records if r.get("gender") in ("man", "woman"))
|
||||
return {"preserved_tagged": already, "untagged": len(records) - already}
|
||||
|
||||
todo = [r for r in records if r.get("gender") not in ("man", "woman")]
|
||||
if not todo:
|
||||
print(" every record already has gender — nothing to tag.")
|
||||
return {"preserved_tagged": len(records)}
|
||||
print(f" tagging gender via deepface ({len(todo)} of {len(records)} records, CPU; ~0.5-1s per face)…")
|
||||
counts: dict[str, int] = {}
|
||||
for i, r in enumerate(todo):
|
||||
full = os.path.join(out_dir, r["file"])
|
||||
try:
|
||||
ana = DeepFace.analyze(
|
||||
img_path=full,
|
||||
actions=["gender"],
|
||||
enforce_detection=False,
|
||||
silent=True,
|
||||
)
|
||||
if isinstance(ana, list):
|
||||
ana = ana[0] if ana else {}
|
||||
g_raw = (ana.get("dominant_gender") or "").lower().strip()
|
||||
r["gender"] = (
|
||||
"man" if g_raw.startswith("man") else
|
||||
"woman" if g_raw.startswith("woman") else
|
||||
None
|
||||
)
|
||||
except Exception as e:
|
||||
r["gender"] = None
|
||||
r["gender_error"] = f"{type(e).__name__}: {e}"
|
||||
counts[r["gender"] or "unknown"] = counts.get(r["gender"] or "unknown", 0) + 1
|
||||
if (i + 1) % 25 == 0:
|
||||
print(f" [{i+1}/{len(todo)}] {counts}")
|
||||
return counts
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument("--count", type=int, default=300, help="how many faces to maintain in pool")
|
||||
p.add_argument(
|
||||
"--out",
|
||||
default=os.path.join(os.path.dirname(__file__), "..", "..", "data", "headshots"),
|
||||
)
|
||||
p.add_argument("--concurrency", type=int, default=3, help="parallel fetches (be polite)")
|
||||
p.add_argument("--no-gender", action="store_true", help="skip deepface gender tagging")
|
||||
p.add_argument("--shrink", action="store_true",
|
||||
help="allow --count to drop manifest entries with id >= count. Default: preserve them.")
|
||||
args = p.parse_args()
|
||||
|
||||
out = os.path.realpath(args.out)
|
||||
os.makedirs(out, exist_ok=True)
|
||||
|
||||
# Load any existing manifest into a by-id dict so prior tags
|
||||
# (gender / race / age / excluded) survive the rewrite. Also
|
||||
# naturally dedupes — if the file accidentally has duplicate
|
||||
# lines for the same id (this is how we ended up with a 2497-
|
||||
# row manifest backing a 1000-face pool), the last one wins.
|
||||
manifest = os.path.join(out, "manifest.jsonl")
|
||||
existing: dict[int, dict] = {}
|
||||
if os.path.exists(manifest):
|
||||
dup_count = 0
|
||||
with open(manifest) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
try:
|
||||
row = json.loads(line)
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
rid = row.get("id")
|
||||
if not isinstance(rid, int):
|
||||
continue
|
||||
if rid in existing:
|
||||
dup_count += 1
|
||||
existing[rid] = row
|
||||
print(f"Loaded existing manifest: {len(existing)} unique ids ({dup_count} duplicate lines collapsed)")
|
||||
max_existing = max(existing.keys()) if existing else -1
|
||||
if max_existing >= args.count and not args.shrink:
|
||||
print(
|
||||
f"\nERROR: --count={args.count} would drop {sum(1 for k in existing if k >= args.count)} "
|
||||
f"manifest entries (max existing id = {max_existing}). Pass --shrink to allow.\n",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(2)
|
||||
|
||||
print(f"Fetching {args.count} faces → {out}")
|
||||
print(f"Source: {URL} (synthetic StyleGAN — no real people)")
|
||||
|
||||
results: list[dict] = [None] * args.count # type: ignore
|
||||
t0 = time.time()
|
||||
with ThreadPoolExecutor(max_workers=max(1, args.concurrency)) as ex:
|
||||
futs = {ex.submit(fetch_one, i, out): i for i in range(args.count)}
|
||||
for done, fut in enumerate(as_completed(futs), 1):
|
||||
idx, fname, cached, err = fut.result()
|
||||
# Start from prior manifest row (preserves gender/race/age/excluded)
|
||||
# and overlay only the fields fetch_one is responsible for.
|
||||
base = dict(existing.get(idx, {}))
|
||||
base.update({
|
||||
"id": idx,
|
||||
"file": fname,
|
||||
"cached": cached,
|
||||
"error": err,
|
||||
})
|
||||
results[idx] = base
|
||||
if done % 25 == 0 or done == args.count:
|
||||
ok = sum(1 for r in results if r and not r.get("error"))
|
||||
print(f" [{done}/{args.count}] {ok} ok ({time.time()-t0:.1f}s)")
|
||||
|
||||
# Drop slots that errored or are still None (shouldn't happen)
|
||||
records = [r for r in results if r and not r.get("error")]
|
||||
print(f"\nPool ready: {len(records)} faces, {sum(1 for r in records if r['cached'])} from cache")
|
||||
preserved_tags = sum(1 for r in records if r.get("gender") in ("man", "woman"))
|
||||
if preserved_tags:
|
||||
print(f"Preserved {preserved_tags} prior gender tags (and any race/age/excluded fields).")
|
||||
|
||||
if not args.no_gender and records:
|
||||
print("\nGender-tagging pass:")
|
||||
summary = maybe_tag_gender(records, out)
|
||||
print(f" distribution: {summary}")
|
||||
else:
|
||||
for r in records:
|
||||
r.setdefault("gender", None)
|
||||
|
||||
# If --shrink was NOT used and somehow id >= count rows are still in
|
||||
# `existing` (which can only happen if the early gate was bypassed),
|
||||
# carry them forward so we don't quietly drop them.
|
||||
if not args.shrink:
|
||||
for rid, row in existing.items():
|
||||
if rid >= args.count and rid not in {r["id"] for r in records}:
|
||||
records.append(row)
|
||||
records.sort(key=lambda r: r.get("id", 0))
|
||||
|
||||
# Strip transient flags before persisting
|
||||
for r in records:
|
||||
r.pop("cached", None)
|
||||
r.pop("error", None)
|
||||
|
||||
# Atomic write — if a re-run is interrupted, manifest stays intact.
|
||||
tmp = manifest + ".tmp"
|
||||
with open(tmp, "w") as f:
|
||||
for r in records:
|
||||
f.write(json.dumps(r) + "\n")
|
||||
os.replace(tmp, manifest)
|
||||
print(f"\nManifest: {manifest} ({len(records)} entries)")
|
||||
|
||||
# Quick checksum manifest for downstream debugging
|
||||
h = hashlib.sha256()
|
||||
for r in records:
|
||||
h.update(r["file"].encode())
|
||||
h.update(b"|")
|
||||
h.update((r.get("gender") or "?").encode())
|
||||
print(f"Pool fingerprint (sha256): {h.hexdigest()[:16]}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
230
scripts/staffing/render_role_pool.py
Normal file
230
scripts/staffing/render_role_pool.py
Normal file
@ -0,0 +1,230 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
render_role_pool.py — pre-render a role-aware face pool by hitting
|
||||
serve_imagegen.py (localhost:3600/generate) with prompts pulled from
|
||||
the bun server's /headshots/_scenes endpoint (single source of truth
|
||||
for SCENES + SCENES_VERSION).
|
||||
|
||||
Layout:
|
||||
|
||||
data/headshots_role_pool/
|
||||
{band}/
|
||||
{gender}_{race}/
|
||||
face_00.webp
|
||||
face_01.webp
|
||||
...
|
||||
manifest.jsonl
|
||||
|
||||
Each entry in manifest.jsonl:
|
||||
|
||||
{"band": "warehouse", "gender": "man", "race": "caucasian",
|
||||
"file": "warehouse/man_caucasian/face_03.webp",
|
||||
"seed": 184729338, "scenes_version": "v1"}
|
||||
|
||||
Idempotent: a file at the target path is skipped. Re-run with --force
|
||||
to regenerate. SCENES_VERSION is captured per render so the server's
|
||||
pool route can refuse stale renders if the version drifts.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import argparse
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
|
||||
DEFAULT_BANDS = ["warehouse", "production", "trades", "driver", "lead"]
|
||||
DEFAULT_GENDERS = ["man", "woman"]
|
||||
DEFAULT_RACES = ["caucasian", "east_asian", "south_asian", "middle_eastern", "black", "hispanic"]
|
||||
|
||||
|
||||
def race_text(r: str) -> str:
|
||||
return {
|
||||
"caucasian": "",
|
||||
"east_asian": "East Asian",
|
||||
"south_asian": "South Asian",
|
||||
"middle_eastern": "Middle Eastern",
|
||||
"black": "Black",
|
||||
"hispanic": "Hispanic",
|
||||
}.get(r, "")
|
||||
|
||||
|
||||
def fetch_scenes(mcp_url: str) -> tuple[str, dict]:
|
||||
"""Pull canonical SCENES from the bun server. Single source of truth."""
|
||||
req = urllib.request.Request(f"{mcp_url}/headshots/_scenes")
|
||||
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||
data = json.loads(resp.read())
|
||||
return data["version"], data["scenes"]
|
||||
|
||||
|
||||
def render(comfy_url: str, prompt: str, seed: int, steps: int, timeout: int, dim: int) -> bytes | None:
|
||||
payload = json.dumps({
|
||||
"prompt": prompt,
|
||||
"width": dim,
|
||||
"height": dim,
|
||||
"steps": steps,
|
||||
"seed": seed,
|
||||
}).encode()
|
||||
req = urllib.request.Request(
|
||||
f"{comfy_url}/generate",
|
||||
data=payload,
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||||
data = json.loads(resp.read())
|
||||
except urllib.error.HTTPError as e:
|
||||
print(f" HTTP {e.code} from comfy: {e.read()[:200]}", file=sys.stderr)
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f" comfy error: {type(e).__name__}: {e}", file=sys.stderr)
|
||||
return None
|
||||
img_b64 = data.get("image")
|
||||
if not img_b64:
|
||||
print(f" comfy response missing 'image' field: {list(data.keys())}", file=sys.stderr)
|
||||
return None
|
||||
return base64.b64decode(img_b64)
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument("--out", default=os.path.join(os.path.dirname(__file__), "..", "..", "data", "headshots_role_pool"))
|
||||
p.add_argument("--per-bucket", type=int, default=10, help="how many faces per (band × gender × race)")
|
||||
p.add_argument("--mcp", default="http://localhost:3700")
|
||||
p.add_argument("--comfy", default="http://localhost:3600")
|
||||
p.add_argument("--steps", type=int, default=8)
|
||||
p.add_argument("--bands", nargs="*", default=DEFAULT_BANDS)
|
||||
p.add_argument("--genders", nargs="*", default=DEFAULT_GENDERS)
|
||||
p.add_argument("--races", nargs="*", default=DEFAULT_RACES)
|
||||
p.add_argument("--force", action="store_true", help="regenerate existing files")
|
||||
p.add_argument("--age", type=int, default=32)
|
||||
p.add_argument("--timeout", type=int, default=120, help="per-render timeout (1024² takes ~5s on A4000)")
|
||||
p.add_argument("--dim", type=int, default=1024, help="square render dimension (v2 default 1024, v1 was 512)")
|
||||
args = p.parse_args()
|
||||
|
||||
out_root = os.path.realpath(args.out)
|
||||
os.makedirs(out_root, exist_ok=True)
|
||||
|
||||
print(f"Fetching canonical SCENES from {args.mcp}/headshots/_scenes…")
|
||||
try:
|
||||
version, scenes = fetch_scenes(args.mcp)
|
||||
except Exception as e:
|
||||
print(f"FATAL: could not fetch scenes ({e}). Is the mcp-server up?", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
print(f" SCENES_VERSION={version}, {len(scenes)} bands available: {list(scenes.keys())}")
|
||||
|
||||
# v2+ files live at {out}/{version}/{band}/{g}_{r}/face_NN.webp.
|
||||
# v1 lived at {out}/{band}/... — keep that layout intact for
|
||||
# rollback; the server route reads both and prefers current.
|
||||
out = out_root if version == "v1" else os.path.join(out_root, version)
|
||||
os.makedirs(out, exist_ok=True)
|
||||
print(f" writing to: {out}")
|
||||
print(f" render dim: {args.dim}×{args.dim}")
|
||||
|
||||
# Reject any --bands not in the server's SCENES
|
||||
unknown = [b for b in args.bands if b not in scenes]
|
||||
if unknown:
|
||||
print(f"FATAL: unknown bands {unknown}. Server has: {list(scenes.keys())}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
manifest_rows = []
|
||||
todo = [
|
||||
(band, g, r, n)
|
||||
for band in args.bands
|
||||
for g in args.genders
|
||||
for r in args.races
|
||||
for n in range(args.per_bucket)
|
||||
]
|
||||
print(f"\nPlanning: {len(todo)} renders ({len(args.bands)} bands × {len(args.genders)} genders × {len(args.races)} races × {args.per_bucket} faces).")
|
||||
print(f"Estimated GPU time at 1.5s/render = {len(todo) * 1.5 / 60:.1f} min.\n")
|
||||
|
||||
t0 = time.time()
|
||||
rendered = 0
|
||||
skipped = 0
|
||||
failed = 0
|
||||
for i, (band, g, r, n) in enumerate(todo):
|
||||
bucket_dir = os.path.join(out, band, f"{g}_{r}")
|
||||
os.makedirs(bucket_dir, exist_ok=True)
|
||||
fname = f"face_{n:02d}.webp"
|
||||
full = os.path.join(bucket_dir, fname)
|
||||
rel = os.path.relpath(full, out)
|
||||
|
||||
if os.path.exists(full) and os.path.getsize(full) > 1024 and not args.force:
|
||||
skipped += 1
|
||||
manifest_rows.append({
|
||||
"band": band, "gender": g, "race": r, "file": rel,
|
||||
"seed": None, "scenes_version": version, "cached": True,
|
||||
})
|
||||
continue
|
||||
|
||||
scene_def = scenes[band]
|
||||
scene_clause = scene_def["scene"]
|
||||
race_clause = race_text(r)
|
||||
gender_clause = g # "man" / "woman"
|
||||
# Match the bun server's prompt builder exactly. If you tweak
|
||||
# one, tweak the other (or factor a /prompt-builder endpoint).
|
||||
# The {role} slot is intentionally a band-typical title here
|
||||
# — the pre-rendered face is shared across roles in the same
|
||||
# band, so we use the band's archetypal role. Specific roles
|
||||
# still hit the on-demand /headshots/generate/:key path with
|
||||
# their actual title.
|
||||
archetype_role = {
|
||||
"warehouse": "warehouse worker",
|
||||
"production": "production worker",
|
||||
"trades": "skilled tradesperson",
|
||||
"driver": "delivery driver",
|
||||
"lead": "shift supervisor",
|
||||
}.get(band, "warehouse worker")
|
||||
prompt = (
|
||||
f"professional headshot portrait of a {args.age}-year-old "
|
||||
f"{race_clause} {gender_clause} {archetype_role}, {scene_clause}, "
|
||||
f"neutral confident expression, sharp focus, photorealistic"
|
||||
)
|
||||
|
||||
# Deterministic seed per slot — same (band, g, r, n) always
|
||||
# gets the same face. Mixing scenes_version means a SCENES
|
||||
# tweak shifts every face slightly; that's the right behavior
|
||||
# (it's how cache invalidation propagates to the pool too).
|
||||
seed_str = f"{band}|{g}|{r}|{n}|{version}"
|
||||
seed_h = 5381
|
||||
for ch in seed_str:
|
||||
seed_h = ((seed_h << 5) + seed_h + ord(ch)) & 0x7fffffff
|
||||
seed = seed_h
|
||||
|
||||
bytes_ = render(args.comfy, prompt, seed, args.steps, args.timeout, args.dim)
|
||||
if bytes_ is None:
|
||||
failed += 1
|
||||
continue
|
||||
with open(full, "wb") as f:
|
||||
f.write(bytes_)
|
||||
rendered += 1
|
||||
manifest_rows.append({
|
||||
"band": band, "gender": g, "race": r, "file": rel,
|
||||
"seed": seed, "scenes_version": version, "cached": False,
|
||||
})
|
||||
|
||||
if (i + 1) % 10 == 0 or (i + 1) == len(todo):
|
||||
elapsed = time.time() - t0
|
||||
done = i + 1
|
||||
rate = done / elapsed if elapsed > 0 else 0
|
||||
eta = (len(todo) - done) / rate if rate > 0 else 0
|
||||
print(f" [{done}/{len(todo)}] rendered={rendered} skipped={skipped} failed={failed} "
|
||||
f"rate={rate:.2f}/s eta={eta:.0f}s")
|
||||
|
||||
# Atomic manifest write
|
||||
manifest_path = os.path.join(out, "manifest.jsonl")
|
||||
tmp = manifest_path + ".tmp"
|
||||
with open(tmp, "w") as f:
|
||||
for row in manifest_rows:
|
||||
f.write(json.dumps(row) + "\n")
|
||||
os.replace(tmp, manifest_path)
|
||||
|
||||
print(f"\nDone. {rendered} new, {skipped} cached, {failed} failed in {time.time()-t0:.1f}s")
|
||||
print(f"Manifest: {manifest_path} ({len(manifest_rows)} entries)")
|
||||
print(f"\nNext: poke {args.mcp}/headshots/__reload to pick up the new pool.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
169
scripts/staffing/tag_face_pool.py
Normal file
169
scripts/staffing/tag_face_pool.py
Normal file
@ -0,0 +1,169 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
tag_face_pool.py — run deepface gender + race classification over the
|
||||
synthetic face pool produced by fetch_face_pool.py and rewrite
|
||||
manifest.jsonl with `gender` (man / woman) and `race` (asian / black /
|
||||
hispanic / indian / middle_eastern / white) tags.
|
||||
|
||||
Run with the venv that has deepface installed:
|
||||
|
||||
/home/profit/.local/share/deepface-venv/bin/python \
|
||||
scripts/staffing/tag_face_pool.py
|
||||
|
||||
Idempotent: rows that already have BOTH gender and race tagged are
|
||||
skipped. Pass --force to re-tag everything.
|
||||
|
||||
Mapping deepface buckets → /headshots/ ?e= values:
|
||||
asian → split by manual region (deepface doesn't differentiate
|
||||
East / South Asian; we lump as 'east_asian' since the
|
||||
StyleGAN training set leans East Asian)
|
||||
indian → south_asian
|
||||
middle eastern → middle_eastern
|
||||
black → black
|
||||
hispanic → hispanic
|
||||
white → caucasian
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
DEEPFACE_RACE_TO_HINT = {
|
||||
"asian": "east_asian",
|
||||
"indian": "south_asian",
|
||||
"middle eastern": "middle_eastern",
|
||||
"black": "black",
|
||||
"latino hispanic": "hispanic",
|
||||
"hispanic": "hispanic",
|
||||
"white": "caucasian",
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument(
|
||||
"--out",
|
||||
default=os.path.join(os.path.dirname(__file__), "..", "..", "data", "headshots"),
|
||||
)
|
||||
p.add_argument("--force", action="store_true", help="re-tag rows that already have gender+race")
|
||||
p.add_argument("--limit", type=int, default=0, help="cap how many faces to process this run (0 = all)")
|
||||
p.add_argument("--min-age", type=int, default=22, help="exclude faces estimated below this age (kids/teens). Staffing context = legal-age workers only.")
|
||||
args = p.parse_args()
|
||||
|
||||
out = os.path.realpath(args.out)
|
||||
manifest_path = os.path.join(out, "manifest.jsonl")
|
||||
if not os.path.exists(manifest_path):
|
||||
print(f"manifest not found: {manifest_path}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print(f"loading deepface (cold start ~10-15s for first model build)…")
|
||||
from deepface import DeepFace # type: ignore
|
||||
|
||||
rows = []
|
||||
with open(manifest_path) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
rows.append(json.loads(line))
|
||||
print(f"manifest: {len(rows)} rows")
|
||||
|
||||
todo = [
|
||||
r for r in rows
|
||||
if args.force or r.get("gender") is None or r.get("race") is None or r.get("age") is None
|
||||
]
|
||||
if args.limit > 0:
|
||||
todo = todo[: args.limit]
|
||||
print(f"to tag: {len(todo)} faces")
|
||||
|
||||
if not todo:
|
||||
print("nothing to do.")
|
||||
return
|
||||
|
||||
counts_g = {}
|
||||
counts_r = {}
|
||||
failed = 0
|
||||
t0 = time.time()
|
||||
for i, r in enumerate(todo):
|
||||
full = os.path.join(out, r["file"])
|
||||
try:
|
||||
ana = DeepFace.analyze(
|
||||
img_path=full,
|
||||
actions=["gender", "race", "age"],
|
||||
enforce_detection=False,
|
||||
silent=True,
|
||||
)
|
||||
if isinstance(ana, list):
|
||||
ana = ana[0] if ana else {}
|
||||
g_raw = (ana.get("dominant_gender") or "").lower().strip()
|
||||
r["gender"] = (
|
||||
"man" if g_raw.startswith("man") else
|
||||
"woman" if g_raw.startswith("woman") else
|
||||
None
|
||||
)
|
||||
r_raw = (ana.get("dominant_race") or "").lower().strip()
|
||||
r["race"] = DEEPFACE_RACE_TO_HINT.get(r_raw, None)
|
||||
if r["race"] is None and r_raw:
|
||||
r["race_raw"] = r_raw
|
||||
# Age estimation — exclude minors / teens. Staffing context
|
||||
# uses adult workers only. Threshold is 22 by default
|
||||
# (legal + a buffer because age estimation is noisy).
|
||||
try:
|
||||
age = int(round(float(ana.get("age") or 0)))
|
||||
except Exception:
|
||||
age = 0
|
||||
r["age"] = age
|
||||
if age and age < args.min_age:
|
||||
r["excluded"] = "minor"
|
||||
else:
|
||||
r.pop("excluded", None)
|
||||
counts_g[r["gender"] or "unknown"] = counts_g.get(r["gender"] or "unknown", 0) + 1
|
||||
counts_r[r["race"] or r_raw or "unknown"] = counts_r.get(r["race"] or r_raw or "unknown", 0) + 1
|
||||
except Exception as e:
|
||||
r["tag_error"] = f"{type(e).__name__}: {e}"
|
||||
failed += 1
|
||||
if (i + 1) % 25 == 0 or (i + 1) == len(todo):
|
||||
elapsed = time.time() - t0
|
||||
rate = (i + 1) / elapsed if elapsed > 0 else 0
|
||||
eta = (len(todo) - i - 1) / rate if rate > 0 else 0
|
||||
print(f" [{i+1}/{len(todo)}] rate={rate:.1f}/s eta={eta:.0f}s failed={failed}")
|
||||
print(f" gender: {counts_g}")
|
||||
print(f" race : {counts_r}")
|
||||
|
||||
# Write updated manifest atomically
|
||||
tmp = manifest_path + ".tmp"
|
||||
with open(tmp, "w") as f:
|
||||
for r in rows:
|
||||
f.write(json.dumps(r) + "\n")
|
||||
os.replace(tmp, manifest_path)
|
||||
|
||||
final_g = {}
|
||||
final_r = {}
|
||||
excluded = 0
|
||||
age_hist = {"<18": 0, "18-22": 0, "22-30": 0, "30-40": 0, "40-50": 0, "50-60": 0, "60+": 0, "unknown": 0}
|
||||
for r in rows:
|
||||
if r.get("excluded"):
|
||||
excluded += 1
|
||||
continue
|
||||
final_g[r.get("gender") or "untagged"] = final_g.get(r.get("gender") or "untagged", 0) + 1
|
||||
final_r[r.get("race") or "untagged"] = final_r.get(r.get("race") or "untagged", 0) + 1
|
||||
a = r.get("age") or 0
|
||||
if a == 0: age_hist["unknown"] += 1
|
||||
elif a < 18: age_hist["<18"] += 1
|
||||
elif a < 22: age_hist["18-22"] += 1
|
||||
elif a < 30: age_hist["22-30"] += 1
|
||||
elif a < 40: age_hist["30-40"] += 1
|
||||
elif a < 50: age_hist["40-50"] += 1
|
||||
elif a < 60: age_hist["50-60"] += 1
|
||||
else: age_hist["60+"] += 1
|
||||
print(f"\nDone. {len(rows)} rows, {excluded} excluded as <{args.min_age}, {failed} tag errors, {time.time()-t0:.1f}s")
|
||||
print(f" final gender: {final_g}")
|
||||
print(f" final race : {final_r}")
|
||||
print(f" age dist : {age_hist}")
|
||||
print(f"\nNext: poke /headshots/__reload to refresh the in-memory pool.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
x
Reference in New Issue
Block a user