docs: cut the comments that were not earning their place

I wrote 731 comment lines on this branch against 4,530 lines of code — 14%,
where the rest of the repo runs at 1.8%. CLAUDE.md asks for code that reads
like its surroundings, and this did not.

Removed by genre rather than by taste:

- restating the code, e.g. "JS getUTCDay() numbering: Sunday = 0" above the
  map that literally shows it, and a docblock on startOfWeek explaining that
  it returns the start of the week;
- narrating history — "this used to rebuild the whole map", "left the bar
  recording forever" — which the commit message and git blame already carry;
- saying the same thing in several places: the "cannot record is not a
  denied microphone" reason appeared three times in one file, and the
  "aborting stops a per-minute metered call" reason across three files. Each
  now lives once, where the behaviour it explains lives;
- defending decisions nobody would question, like why toLatinDigits is its
  own module;
- over-explaining defensive branches, three separate comments to distinguish
  null from missing-kind from unrecognised-kind.

What stays is what the code cannot say: the patient-right convention in
toFdi, whose failure mode is a valid code for the wrong tooth; the
"this"-vs-"next" week anchoring; StrictMode re-arming mountedRef; Safari
accepting no mimeType hint; and the invariants whose violation already cost
a bug — the body parser's middleware ordering and the dispatch panel's
auto-fill rules.

Comments only. The diff contains no non-comment line.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-21 23:46:56 +08:00
parent 6e62ab0610
commit b5560b2f6b
27 changed files with 170 additions and 328 deletions

View File

@@ -22,8 +22,7 @@ export const voiceApi = {
payload: ExtractVoicePayload,
signal?: AbortSignal,
): Promise<{ success: boolean; data: VoiceExtractionResult }> => {
// The signal is forwarded so cancelling closes the connection, which aborts the
// metered vendor call server-side rather than letting it settle unseen.
// Forwarded so cancelling closes the connection; the controller turns that into an abort.
const response = await apiClient.post('/voice/extract', payload, { signal });
return response.data;
},

View File

@@ -9,11 +9,9 @@ const PREFERRED_MIME_TYPES = [
] as const;
/**
* Pick a container this browser can record AND the backend accepts.
*
* Chrome and Android produce webm/opus; Safari and iPad produce mp4/aac. Both go to the
* vendor unmodified, so there is no transcode step — but the choice still has to be made
* at record time, and `isTypeSupported` is missing entirely on older Safari.
* Pick a container this browser can record AND the backend accepts. Chrome and Android give
* webm/opus, Safari and iPad mp4/aac; both go to the vendor unmodified, so there is no
* transcode step and the list is an intersection, not a preference.
*/
export function pickRecordingMimeType(): string | null {
if (typeof MediaRecorder === 'undefined') return null;

View File

@@ -69,9 +69,8 @@ export function useVoiceCapture({
/** getUserMedia is async; without this a permission granted after unmount leaks the mic. */
const mountedRef = useRef(true);
/**
* Set synchronously on click. `phase` does not become 'recording' until getUserMedia
* resolves, so without this a second click during the permission prompt would start a
* second stream and orphan the first — mic indicator lit, interval leaked.
* Set synchronously on click: `phase` only becomes 'recording' once getUserMedia resolves,
* so a second click during the permission prompt would orphan the first stream.
*/
const startingRef = useRef(false);
@@ -139,9 +138,7 @@ export function useVoiceCapture({
);
const stop = useCallback(() => {
// No recorder means nothing will fire `onstop`, so nothing else will move the phase.
// Optional-chaining into a no-op here left the bar recording forever with a running
// timer, and only Cancel could get out of it.
// No recorder means nothing will fire `onstop`, so nothing else moves the phase.
if (!recorderRef.current) {
teardown();
setPhase('idle');
@@ -158,8 +155,9 @@ export function useVoiceCapture({
const onStart = useCallback(() => {
if (phase !== 'idle' || startingRef.current) return;
if (!isMediaRecorderSupported()) {
// Not a permission problem: this browser cannot record at all. Saying "microphone
// denied" sends the clinician to hunt for a permission nothing ever asked for.
// VOICE_UNSUPPORTED_FORMAT, not MIC_DENIED: nothing asked for a permission yet, and
// blaming the microphone sends the clinician into site settings for no reason. Same
// for the two paths below.
onError(clientError('VOICE_UNSUPPORTED_FORMAT'));
return;
}
@@ -187,7 +185,6 @@ export function useVoiceCapture({
const mimeType = pickRecordingMimeType();
if (mimeType === null) {
// The browser records, but in no container the transcription API accepts.
stream.getTracks().forEach((track) => track.stop());
onError(clientError('VOICE_UNSUPPORTED_FORMAT'));
return;
@@ -231,14 +228,10 @@ export function useVoiceCapture({
if (maxMs != null && elapsed >= maxMs) stop();
}, LEVEL_POLL_MS);
} catch {
// `new MediaRecorder(...)` and `recorder.start()` both throw on some browsers,
// and by then the stream is already live. Without this the promise rejects
// unhandled, the UI sits at 'idle' with nothing shown, and the browser's
// recording indicator stays lit until the workspace unmounts.
// `new MediaRecorder()` and `recorder.start()` both throw on some browsers, and by
// then the stream is live — without this the mic indicator stays lit until unmount.
teardown();
setPhase('idle');
// The permission was already granted by this point — what failed is the recorder
// itself, so this is "this browser cannot record", not "you denied the mic".
onError(clientError('VOICE_UNSUPPORTED_FORMAT'));
} finally {
startingRef.current = false;
@@ -248,8 +241,7 @@ export function useVoiceCapture({
const onCancel = useCallback(() => {
cancelledRef.current = true;
// Aborting closes the connection, which aborts the vendor call server-side. It is
// metered per minute, so letting it settle costs money for a result nobody sees.
// Aborting closes the connection, which aborts the vendor call server-side.
abortRef.current?.abort();
try {
recorderRef.current?.stop();
@@ -283,10 +275,9 @@ function attachLevelMeter(
source.connect(analyser);
const data = new Uint8Array(analyser.frequencyBinCount);
// Sample every frame so a transient is not missed, but publish at LEVEL_POLL_MS.
// This hook lives in TreatmentWorkspace, so an unthrottled setLevel re-renders the
// details editor, the FDI chart and the lab panel on every animation frame — about
// 7,200 whole-tree renders across a two-minute recording.
// Sample every frame so a transient is not missed, publish at LEVEL_POLL_MS. The hook
// lives in TreatmentWorkspace, so an unthrottled setLevel is ~7,200 whole-tree renders
// across a two-minute recording.
let peakSinceEmit = 0;
let lastEmit = 0;
const tick = (now: number) => {