feat(#70): IMP-41 application_mode forwarding to FramePanel V4 badge tooltip (u1~u5)

Forward backend Step 9 `unit.application_candidates[]` (application_mode /
auto_applicable / delegated_to) onto FrameCandidate and surface the
application_mode as a Korean consequence phrase in the FramePanel V4-label
inline badge tooltip. Deterministic frontend-only refactor; no LLM call,
no V4-label color change, no outer composedTitle change.

u1: types/designAgent.ts — add optional applicationMode / autoApplicable /
    delegatedTo on FrameCandidate (legacy fixtures keep undefined).
u2: services/applicationMode.ts (new) — pure helper exporting
    ApplicationMode union, APPLICATION_MODE_TOOLTIP_KR (keyed by backend
    mode VALUE, NOT V4 label), buildBadgeTitle, mergeApplicationCandidates.
u3: tests/imp41_application_mode.test.ts (new) — 13 Vitest cases pinning
    composite output per mode, undefined/unknown→legacy fallback, merge by
    template_id, skip missing/empty/non-string keys, first-wins on dupes,
    empty/null/non-array input.
u4: services/designAgentApi.ts — bridge consumes mergeApplicationCandidates
    and forwards three fields onto FrameCandidate while preserving
    LABEL_PRIORITY sort and TOP_N_FRAMES slicing.
u5: components/FramePanel.tsx — V4-label badge `title` now calls
    `buildBadgeTitle(candidate.label, candidate.applicationMode)`;
    badge color className map preserved verbatim; outer composedTitle
    untouched.

Scope-qualified verification (5 files, IMP-41 axis only):
- Vitest: client/tests/imp41_application_mode.test.ts — 13/13 PASS.
- Diff↔Plan parity: 5 files match Stage 2 plan, no scope creep.
- AI-isolation contract honored: tooltip values originate from backend
  enum; no frontend re-derivation from V4 label.
- No spacing/font shrink; clipping resolution stays at layout/zone/frame
  layer (feedback_phase_z_spacing_direction).

Pre-existing unrelated diagnostics (BottomActions.tsx,
imp47b_human_review_toast.test.tsx) remain open on their own axes and are
not gated by this commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-22 00:17:32 +09:00
co-authored by Claude Opus 4.7
parent 90503cadd6
commit f358604fb3
5 changed files with 232 additions and 3 deletions
@@ -0,0 +1,64 @@
// ─── IMP-41 u2 — application_mode helper (issue #70) ────────────────────────
// Pure deterministic helpers for forwarding backend Step 9
// `unit.application_candidates[]` to the FramePanel V4-label badge tooltip.
//
// Keyed by backend `application_mode` VALUE (NOT V4 label) — preserves the
// AI-isolation contract: tooltip text is a read-only display of backend
// authority, never re-derived on the frontend from V4 label.
//
// Source of truth = src/phase_z2_pipeline.py APPLICATION_MODE_BY_V4_LABEL
// (:107-112) emitted via _application_candidates_for_unit() (:3071-3092)
// onto unit.application_candidates[] in step09_application_plan.json.
/** Backend application_mode enumeration (verbatim from APPLICATION_MODE_BY_V4_LABEL). */
export type ApplicationMode =
| 'direct_insert'
| 'same_frame_with_adjustment'
| 'layout_or_region_change'
| 'exclude';
/** Korean consequence phrases per issue #70 spec item #2. Keyed by mode VALUE. */
export const APPLICATION_MODE_TOOLTIP_KR: Record<ApplicationMode, string> = {
direct_insert: '코드 직접 적용',
same_frame_with_adjustment: 'AI 보강 필요',
layout_or_region_change: 'AI restructure 필요',
exclude: 'render path 제외',
};
/**
* Compose the V4-label badge tooltip title. When `applicationMode` resolves
* to a known mode the title shows the Korean consequence + raw mode token;
* otherwise (undefined or unknown — legacy fixtures pre-IMP-32) it falls
* back to the raw V4 label string per Stage 2 contract.
*/
export function buildBadgeTitle(
label: string,
applicationMode: string | undefined,
): string {
const consequence = applicationMode
? APPLICATION_MODE_TOOLTIP_KR[applicationMode as ApplicationMode]
: undefined;
return consequence
? `${consequence} (${applicationMode})`
: `V4 label: ${label}`;
}
/**
* Build a Map<template_id, applicationCandidate> from a Step 9
* `unit.application_candidates[]` array. Entries with a non-string or empty
* `template_id` are skipped. First occurrence wins on duplicate keys.
* Pure — does NOT sort, slice, or filter by label/confidence.
*/
export function mergeApplicationCandidates(
applicationCandidates: unknown,
): Map<string, any> {
const out = new Map<string, any>();
if (!Array.isArray(applicationCandidates)) return out;
for (const ac of applicationCandidates) {
const key = (ac as any)?.template_id;
if (typeof key === 'string' && key.length > 0 && !out.has(key)) {
out.set(key, ac);
}
}
return out;
}