From 3f835eee9317c531c13b21d86a8f86b51efcd2f6 Mon Sep 17 00:00:00 2001 From: Aravind Date: Fri, 18 Sep 2026 15:35:15 +0530 Subject: [PATCH] =?UTF-8?q?refactor(ts-migration):=20Phase=2011=20batch=20?= =?UTF-8?q?7=20=E2=80=94=20the=20assistant's=20non-component=20modules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The eleven `.js` files under `src/components/ai-assistant/`: the blocks format, contexts, routing, history, placement, viewport, the greeting and prompt tables in `dynamic`, the derivations in `insights`, and `uiEdit`, whose boundary batch 1 already typed. 79 errors, and two optional markers cleared 63 of them. `plural(n, word, irregular)` is called with two arguments sixty times in `dynamic.ts` and its own body reads `irregular || \`${word}s\``, so the third parameter has always been optional in everything but the signature. `heading(value, sub)` is the same: `sub` is spread into the block and `undefined` is what most callers mean. Marking both optional is a statement about the existing contract, and the markers erase — the emitted signatures still read `plural=(n,word,irregular)` and `heading=(value,sub)`, checked in the output rather than assumed. Those three `heading` errors landed in `lib/skills/workforceFlow.ts`, already migrated and untouched here. Worth noting how that works: a function's arity only starts being enforced on its callers once the file defining it is TypeScript. Migrating a leaf makes claims about every file that imports it, which is why this phase moves bottom-up. The remaining nine were two `reduce` accumulators inferring `{}`, so `Object.values` over them produced `unknown`. Both are now stated — `{ label, count }` for the score bands, and the five-field hire grouping — which is more useful than `any` and exactly what the lines below them build. Measured against `dde4ba6`: typecheck 6 errors, unchanged; no new error anywhere lint exit 0, 0 errors, 289 warnings npm test 1684/1691, the same 7 failures verbatim build exit 0, identical bundle hash 74d17e2d… type erasure 83/83 byte-identical across Phase 11 so far No baseline artifact touched. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01HBG1wnuRfJKCstGB8Fekr8 --- src/components/ai-assistant/{blocks.js => blocks.ts} | 2 +- src/components/ai-assistant/{contexts.js => contexts.ts} | 0 src/components/ai-assistant/{dynamic.js => dynamic.ts} | 0 src/components/ai-assistant/{history.js => history.ts} | 0 src/components/ai-assistant/{insights.js => insights.ts} | 8 +++++--- .../ai-assistant/{placement.js => placement.ts} | 0 src/components/ai-assistant/{provider.js => provider.ts} | 0 src/components/ai-assistant/{routing.js => routing.ts} | 0 src/components/ai-assistant/{uiEdit.js => uiEdit.ts} | 0 .../ai-assistant/{useAssistant.js => useAssistant.ts} | 0 src/components/ai-assistant/{viewport.js => viewport.ts} | 0 11 files changed, 6 insertions(+), 4 deletions(-) rename src/components/ai-assistant/{blocks.js => blocks.ts} (98%) rename src/components/ai-assistant/{contexts.js => contexts.ts} (100%) rename src/components/ai-assistant/{dynamic.js => dynamic.ts} (100%) rename src/components/ai-assistant/{history.js => history.ts} (100%) rename src/components/ai-assistant/{insights.js => insights.ts} (98%) rename src/components/ai-assistant/{placement.js => placement.ts} (100%) rename src/components/ai-assistant/{provider.js => provider.ts} (100%) rename src/components/ai-assistant/{routing.js => routing.ts} (100%) rename src/components/ai-assistant/{uiEdit.js => uiEdit.ts} (100%) rename src/components/ai-assistant/{useAssistant.js => useAssistant.ts} (100%) rename src/components/ai-assistant/{viewport.js => viewport.ts} (100%) diff --git a/src/components/ai-assistant/blocks.js b/src/components/ai-assistant/blocks.ts similarity index 98% rename from src/components/ai-assistant/blocks.js rename to src/components/ai-assistant/blocks.ts index f5616f7..ff82087 100644 --- a/src/components/ai-assistant/blocks.js +++ b/src/components/ai-assistant/blocks.ts @@ -20,7 +20,7 @@ export const doc = (...blocks) => ({ export const text = (value) => value && { type: 'text', text: value }; /** A section label inside a response. */ -export const heading = (value, sub) => value && { type: 'heading', text: value, sub }; +export const heading = (value, sub?) => value && { type: 'heading', text: value, sub }; /** Headline figures. `items: [{ label, value, delta?, sub?, tone? }]` */ export const kpis = (items) => items?.length && { type: 'kpis', items }; diff --git a/src/components/ai-assistant/contexts.js b/src/components/ai-assistant/contexts.ts similarity index 100% rename from src/components/ai-assistant/contexts.js rename to src/components/ai-assistant/contexts.ts diff --git a/src/components/ai-assistant/dynamic.js b/src/components/ai-assistant/dynamic.ts similarity index 100% rename from src/components/ai-assistant/dynamic.js rename to src/components/ai-assistant/dynamic.ts diff --git a/src/components/ai-assistant/history.js b/src/components/ai-assistant/history.ts similarity index 100% rename from src/components/ai-assistant/history.js rename to src/components/ai-assistant/history.ts diff --git a/src/components/ai-assistant/insights.js b/src/components/ai-assistant/insights.ts similarity index 98% rename from src/components/ai-assistant/insights.js rename to src/components/ai-assistant/insights.ts index faea63d..1630aba 100644 --- a/src/components/ai-assistant/insights.js +++ b/src/components/ai-assistant/insights.ts @@ -15,7 +15,7 @@ import { PRIVILEGED_EVENTS, activitySignals } from '@/lib/activitySignals'; export const pct = (n, d) => (d ? Math.round((n / d) * 100) : 0); -export const plural = (n, word, irregular) => +export const plural = (n, word, irregular?) => `${n} ${n === 1 ? word : irregular || `${word}s`}`; export const verb = (n, singular, plural_) => (n === 1 ? singular : plural_); @@ -215,7 +215,7 @@ export function buildFacts({ ), experienced: profiles.filter((p) => (p.experience_years || 0) >= 3), avgScore: avg(profiles.filter((p) => p.krow_score > 0).map((p) => p.krow_score)), - bands: Object.values(profiles.reduce((acc, p) => { + bands: Object.values(profiles.reduce>((acc, p) => { const { label } = getScoreBand(p.krow_score || 0); acc[label] ||= { label, count: 0 }; acc[label].count += 1; @@ -241,7 +241,9 @@ export function buildFacts({ }; }); - const groupHires = (key) => Object.values(hires.reduce((acc, h) => { + const groupHires = (key) => Object.values(hires.reduce>((acc, h) => { const name = h[key] || 'Unspecified'; acc[name] ||= { name, count: 0, scores: [], days: [], ratings: [] }; acc[name].count += 1; diff --git a/src/components/ai-assistant/placement.js b/src/components/ai-assistant/placement.ts similarity index 100% rename from src/components/ai-assistant/placement.js rename to src/components/ai-assistant/placement.ts diff --git a/src/components/ai-assistant/provider.js b/src/components/ai-assistant/provider.ts similarity index 100% rename from src/components/ai-assistant/provider.js rename to src/components/ai-assistant/provider.ts diff --git a/src/components/ai-assistant/routing.js b/src/components/ai-assistant/routing.ts similarity index 100% rename from src/components/ai-assistant/routing.js rename to src/components/ai-assistant/routing.ts diff --git a/src/components/ai-assistant/uiEdit.js b/src/components/ai-assistant/uiEdit.ts similarity index 100% rename from src/components/ai-assistant/uiEdit.js rename to src/components/ai-assistant/uiEdit.ts diff --git a/src/components/ai-assistant/useAssistant.js b/src/components/ai-assistant/useAssistant.ts similarity index 100% rename from src/components/ai-assistant/useAssistant.js rename to src/components/ai-assistant/useAssistant.ts diff --git a/src/components/ai-assistant/viewport.js b/src/components/ai-assistant/viewport.ts similarity index 100% rename from src/components/ai-assistant/viewport.js rename to src/components/ai-assistant/viewport.ts