Compare commits

...
2 Commits
Author SHA1 Message Date
ClaudeandClaude Opus 5.5 c4aa1790cc fix(chat): strip slot reserves the panel's worst case by slot width; enforce 36/24/24 stretch lengths (BUG-2339)
Independent Staging Quality Gate / validate-frontend (push) Successful in 6m13s
Independent Staging Quality Gate / validate-python (push) Successful in 8m7s
Independent Staging Quality Gate / publish (push) Successful in 3m53s
The strip grew 300 -> 317px at completion on desktop (a 54-character
sentence). Stretches longer than 36 / 24 / 24 characters now go to the
existing segment rewrite (rejected again if still long; program-written
strips refused); nothing is cut. The reserved height follows the slot's own
width (container query: 436 / 392 / 324 / 300px), each band at its measured
worst case, so skeleton, cross-fade and final heights are equal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
2026-11-24 23:41:59 +08:00
ClaudeandClaude Opus 5.5 99074e916a fix(chat): skeletons for the strip / week / month calendar while streaming, one cross-fade at completion (BUG-2339)
The answer slot shows a skeleton of what it will hold (strip, or the day
calendar for the writer's day_range) built from the real component's boxes,
with the chart pages' slow-pulse skeleton blocks; when the whole answer is
complete the component is drawn in the same grid cell and the two cross-fade
once (opacity, --motion-standard / --ease-standard; instant under reduced
motion). Dark 平 legend chip gets a tertiary-ink hairline ring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
2026-11-24 23:25:02 +08:00
13 changed files with 478 additions and 51 deletions
+26
View File
@@ -31807,3 +31807,29 @@
- 已知不足:手机说明框为最坏情况留了 248px,短内容时下半空着;深色下「平」的图例色块对比低;链接只到星历页,不带月份和对象。
- 关联记录:BUG-2308、BUG-2320(时间条的位置和动效)、BUG-2327(动效令牌)。
- 修复版本:分支 `claude/day-calendar`(本地提交,未推送)。
## BUG-2339 | 回答生成时时间条、一周日历、月历位置上是空壳,写完才突然出现
- 状态:fixed-pending-verify(本地提交,未推送;待负责人在 staging 看过)。
- 首次发现 / 最近更新:2026-11-24(负责人)/ 2026-11-24。
- 现象:回答生成时,新组件(时间条、按天日历)的位置只有一个空壳(标题加一条灰底,或一张灰格子日历);时间一节写完时时间条在生成途中插进来,生成完再上色。另:深色下按天日历图例里「平」的色块几乎看不见。
- 触发条件:问答页本命问答新形状(`## 结论` 开头),首轮需要时间条、追问结论卡有时间标签、或写手给了 `day_range`;深色模式。
- 根因:BUG-2320 的预留位置只放了标签和一条中性底(`chat-answer-strip-placeholder`),时间一节写完就在生成途中画进时间条(BUG-2308 的「整条一次进来」);BUG-2337 生成时用同一张日历的灰格子占位。都不是骨架,也不是在整篇写完时一次换上。「平」的色块用 `--strip-none`(`--color-canvas-strong`),深色下 #3b3a37 落在 #262624 上对比太低。
- 修复:
- `AnswerStripSlot`(`chat-answer-shape.tsx`)生成时只放骨架:时间条骨架 = 标题行 + N 块(时间一节写完后按各段月数定宽,之前 5 块等宽)+ 刻度行 + 面板框 + 页脚一行;一周 = 7 格 + 说明框 + 链接行;月历 = 星期行 + 5–6 行格子 + 说明框 + 链接行(`AnswerDayCalendarSkeleton`,`chat-answer-day-calendar.tsx`)。骨架用真组件同样的类名搭框,所以外高相同;色块复用星盘页 `chart-skeleton-bar`(1.6s 慢速透明度起伏,减弱动效时不动),不新造样式。
- 显示哪种骨架由位置将要放什么决定:写手请求了 `day_range` → 日历骨架;否则 `stripSlotRequired`(BUG-2320)或时间一节已写完 → 时间条骨架;都不知道 → 没有位置(同以前)。
- 整篇回答完成时(`streaming` 变 false)才画真组件,画在同一个格子里(位置改为单格 grid,两层叠放),骨架同一节点加 `is-leaving`:透明度交叉淡入淡出,`--motion-standard` / `--ease-standard`,只动 opacity;淡完后移除骨架。生成途中不换(每次流式片段都不动骨架);减弱动效时直接换。从骨架换上的时间条不再用 `is-arriving` 上滑。历史回答没有骨架。完成时结果和骨架不是同一种(日历没回来)时直接换。
- 深色「平」图例色块加一圈 1px `--color-ink-tertiary` 内描边(两个深色入口都写),底色不变。
- 原值 / 新值 / 原因:生成时标签 + 灰条、时间条写完即画 / 骨架直到整篇完成、一次交叉淡化 / 负责人 2026-11-24。
- 验证:
- 新增 `frontend/tests/chat-answer-skeleton-2339.test.tsx`(4 条):时间条骨架从第一帧在、同一节点、生成中没有时间条、块数 5 → 3、片段增长不换;完成时同一位置同一骨架节点变 `is-leaving`、时间条在其上、无 `is-arriving`;历史无骨架;`day_range` 时日历骨架 7 格、完成时淡出;骨架和日历同类名同格数(一周、整月);CSS 档位、只动透明度、减弱动效、深色「平」。在旧代码上失败(没有骨架类)。
- 钉住断言按原值 / 新值 / 原因改:`chat-answer-tidy-2320`(占位 → 骨架;写正文时不画时间条)、`chat-answer-strip-2308`(时间条在完成时进来、无 `is-arriving`;程序补上的时间条完成时落进位置)。
- Chromium 实测(组件渲染:真实组件 + 本分支编译的产品样式表)骨架 / 交叉中 / 完成的位置高度,三帧都相等:时间条(最长的合规真实回答:感情追问)手机 390 为 392 / 392 / 392px,1280 宽 300 ×3;时间条最长合成例(四段都是最长的起止、「有机会,但费力」、那一句 36 字、该做 / 别做各 24 字、三种图例、页脚带出生时间一句)390 为 392 ×3,1280 为 300 ×3,位置宽度 320 / 343 / 480 / 640px 处为 436 / 392 / 324 / 300 ×3;一周 409.4 ×3(390)、321.4 ×3(1280);月历 588.9 ×3(390)、532.9 ×3(1280);没有横向滚动。截图:`/workspace/eval-read-1116/chat-ux-prototype/build/skeleton-2339/`(strip / stripmax / week / month × 三帧 × 手机浅 / 深,另有最长例桌面两帧;交叉中那一帧用只在截图页里的样式把两层停在 0.5)。
- 协调窗口复查(11-24):第一版桌面时间条在完成时从 300 长到 317px(真实 Obama 换工作回答第一段那一句 54 字,写手没守 36 字)。改为:
1. 程序守住长度(`stripPanelOverflow`,`chat-answer-shape.ts`:那一句 36 字、该做 / 别做各 24 字,按写法规则的数,证据编号不计):写手超长的一段由 `checkStripTone` 整段(一句 + 该做 + 别做)送进现有的分段补写,补写后仍超长的不用(`fix#:long`,`chat-answer-repair.ts`;说法检查只读小标题和那一句);程序补时间条的回复超长不用(`timelineSectionFromReply`)。不截断任何文字。
2. 预留高度按位置自己的宽度(container query)分四档,每档取该档最窄宽度下的最坏情况:宽度 320–328px 量得 432px,343px 量得 387px,480px 量得 318px,640px 量得 293px;预留 436 / 392(343px 起)/ 324(480px 起)/ 300(640px 起)。原值:按视口 408px,641px 起 300px;原因:问答栏会随侧栏和星盘面板变窄,480–639px 宽的栏超过 300px,360px 手机超过 408px。日历位置不受这条最小高度影响(`:not(.is-days)`)。
3. 测试:`chat-answer-skeleton-2339` 新增 2 条(36 / 24 / 24 放得下、多一个字送补写、补写和补时间条超长被拒、编号留在原处;每档预留不低于实测最坏值);`chat-answer-tidy-2320` 的预留断言按原值 / 新值 / 原因改。
- 已知不足:超长的一段补写失败时,那一段仍按原文显示,位置会在完成时变高;页脚的转折点那一句长度没有程序上限(最坏例按一句约 40 字量);位置窄于 320px 时会超出。需要时间条但最后没有(补写失败)时,位置仍在完成时收起。
- 防复发:上面的测试;骨架和真组件共用框的类名,改真组件尺寸时骨架跟着变。
- 关联记录:BUG-2305、BUG-2308、BUG-2320(预留位置)、BUG-2327 / 2328(动效档位)、BUG-2336 / 2337(按天日历)、BUG-1520(骨架样式)。
- 修复版本:分支 `claude/skeleton-2339`(本地提交,未推送)。
+40 -8
View File
@@ -2134,16 +2134,22 @@ button.chat-chart-resize-handle:active { position: absolute; top: 0; left: -3px;
.chat-answer-strip-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px var(--space-3); }
/* BUG-2320: the strip's fixed place. A row that streams here reserves the final strip's height from the first frame
(the panel takes the spare height, so the strip is one fixed-size card whatever its words); history rows do not. */
/* Measured in Chromium with the longest words the writing rules allow (when line, a 36-character sentence, 该做 / 别做 24
characters each, a three-line footer on a phone / two lines wider): 407px at 360–390px wide, 297px from 641px on (a little room is kept). */
.chat-answer-strip-slot { display: flex; flex-direction: column; --chat-strip-slot-height: 408px; }
@media (min-width: 641px) { .chat-answer-strip-slot { --chat-strip-slot-height: 300px; } }
.chat-answer-strip-slot.is-reserved { min-height: var(--chat-strip-slot-height); }
/* BUG-2339: the slot is one grid cell; the skeleton and the strip (or calendar) sit in it together while they cross-fade.
Its reserved height follows the slot's own width (the answer column narrows with the sidebar and the chart panel), each
band at the panel's worst case at that band's narrowest width: the longest ranges with 「有机会,但费力」, a 36-character
sentence and 该做 / 别做 24 characters each (program-enforced, stripPanelOverflow), all three legend labels and the
footer with the birth-time note. Measured in Chromium: 432px at 320–328px, 387px at 343px, 318px at 480px, 293px at
640px (a little room is kept). 原值: by viewport — 408px, 300px from 641px on; 新值: by slot width — 436 / 392 from
343px / 324 from 480px / 300 from 640px; 原因: a 480–639px column (tablet with the sidebar open, a wide chart panel)
overran 300px and a 360px phone overran 408px. */
.chat-answer-strip-slot { display: grid; grid-template-columns: minmax(0, 1fr); container-type: inline-size; }
.chat-answer-strip-slot > * { grid-area: 1 / 1; min-width: 0; --chat-strip-slot-height: 436px; }
@container (min-width: 343px) { .chat-answer-strip-slot > * { --chat-strip-slot-height: 392px; } }
@container (min-width: 480px) { .chat-answer-strip-slot > * { --chat-strip-slot-height: 324px; } }
@container (min-width: 640px) { .chat-answer-strip-slot > * { --chat-strip-slot-height: 300px; } }
.chat-answer-strip-slot.is-reserved:not(.is-days) > * { min-height: var(--chat-strip-slot-height); }
.chat-answer-strip-slot > .chat-answer-strip { flex: 1; }
.chat-answer-strip-slot.is-reserved .chat-answer-strip-detail { flex: 1; }
.chat-answer-strip-placeholder { display: flex; flex-direction: column; gap: var(--space-2); }
.chat-answer-strip-placeholder .chat-answer-label { margin: 0; }
.chat-answer-strip-placeholder-bar { display: block; height: 44px; border-radius: 8px; background: var(--strip-none); }
.chat-answer-strip-bar, .chat-answer-strip-ticks { display: grid; gap: 3px; }
.chat-answer-strip-segment[data-slot="button"] { display: grid; min-width: 0; height: 44px; place-items: center; padding: 0 2px; border: 0; border-radius: 8px; color: var(--color-ink); font-size: var(--type-caption); font-weight: 400; line-height: 1.2; white-space: normal; cursor: pointer; overflow-wrap: anywhere; }
/* BUG-2310: 有机会 / 有机会,但费力 / 较费力; no tag (and receipts stored with the old tones) stays the neutral fill. */
@@ -2258,6 +2264,32 @@ button.chat-chart-resize-handle:active { position: absolute; top: 0; left: -3px;
.is-latest-answer > .chat-answer-next { animation: none; }
.chat-answer-strip-panel, .chat-answer-strip-panel[data-active], .chat-answer-strip-segment[data-slot="button"] { transition: none; }
}
/*
* BUG-2339 (owner 2026-11-24): while the answer is written the slot holds a skeleton of the strip or day calendar — the
* real component's boxes (same classes, so the same outer height) filled with the chart pages' slow opacity pulse
* (`chart-skeleton-bar`, chart-board.css). When the whole answer is complete the component is drawn in the same cell
* and the two cross-fade once: opacity only, standard step, in-place curve. Reduced motion: no pulse, instant swap.
*/
.chat-answer-slot-skeleton { display: flex; flex-direction: column; transition: opacity var(--motion-standard) var(--ease-standard), visibility 0s linear var(--motion-standard); }
.chat-answer-slot-skeleton > * { flex: 1; }
.chat-answer-slot-skeleton.is-leaving { visibility: hidden; opacity: 0; }
.chat-answer-slot-skeleton.is-leaving ~ * { animation: chat-answer-fade-in var(--motion-standard) var(--ease-standard) both; }
.chat-answer-strip-skeleton { display: flex; flex-direction: column; gap: var(--space-2); }
.chat-answer-strip-skeleton .chat-answer-label { margin: 0; }
.chat-answer-strip-skeleton .chat-answer-strip-ticks { min-height: 1.5em; align-items: center; }
.chart-skeleton-bar.chat-answer-strip-skeleton-block { height: 44px; border-radius: 8px; }
.chart-skeleton-bar.chat-answer-strip-skeleton-tick { width: min(36px, 100%); }
.chat-answer-slot-skeleton-box { align-content: start; gap: 10px; }
@media (prefers-reduced-motion: reduce) {
.chat-answer-slot-skeleton { transition: none; }
.chat-answer-slot-skeleton.is-leaving ~ * { animation: none; }
}
/* BUG-2339: the 平 legend chip is the neutral fill, nearly the dark canvas itself; a hairline ring in the tertiary ink
makes it readable there (the fill stays the cells' own). */
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) .chat-answer-strip-legend i.is-mid { box-shadow: inset 0 0 0 1px var(--color-ink-tertiary); }
}
:root[data-theme="dark"] .chat-answer-strip-legend i.is-mid { box-shadow: inset 0 0 0 1px var(--color-ink-tertiary); }
.chat-answer-next .conversation-follow-ups { margin: 0; }
.chat-answer-next .conversation-follow-up { height: auto; min-height: 44px; padding-block: 10px; white-space: normal; text-align: left; }
.conversation-follow-up:disabled { cursor: not-allowed; opacity: .56; }
@@ -86,6 +86,47 @@ function rangeHeading(range: DayRange, week: boolean): string {
return `${dayLabel(range.start)}到 ${dayLabel(range.end)}`;
}
/** The cells the calendar draws for a range (a week row, or Monday-first month weeks) and its heading line. */
export function dayCalendarLayout(range: DayRange): { week: boolean; dates: string[]; heading: string } {
const week = isWeekRange(range);
const dates = week ? weekDates(range) : gridDates(range);
const heading = rangeHeading(range, week);
return { week, dates, heading: week ? `${heading}(${dayLabel(dates[0]!)}到 ${dayLabel(dates.at(-1)!)})` : heading };
}
/**
* BUG-2339 (owner 2026-11-24): what stands in the slot while the answer is written — the same heading, the same cells
* (a week's seven, or the month grid with its weekday row), the same fixed-height box and link row, each piece a soft
* pulsing block in the chart pages' skeleton style (`chart-skeleton-bar`), so its outer height is the calendar's own.
*/
export function AnswerDayCalendarSkeleton({ range }: Readonly<{ range: DayRange }>) {
const { week, dates, heading } = dayCalendarLayout(range);
return (
<div className={`chat-answer-days${week ? " is-week" : " is-month"}`}>
<div className="chat-answer-strip-head">
<p className="chat-answer-label">{heading}</p>
<div className="chat-answer-strip-legend" />
</div>
{week ? null : (
<div className="chat-answer-days-head">
{WEEKDAY_HEAD.map((name) => <span key={name}>{name}</span>)}
</div>
)}
<div className="chat-answer-days-grid">
{dates.map((date) => (date >= range.start && date <= range.end
? <span key={date} className="chart-skeleton-bar is-cell chat-answer-day" />
: <span key={date} className="chat-answer-day is-outside" />))}
</div>
<div className="chat-answer-days-detail chat-answer-slot-skeleton-box">
<span className="chart-skeleton-bar" style={{ width: "55%" }} />
<span className="chart-skeleton-bar" style={{ width: "90%" }} />
<span className="chart-skeleton-bar" style={{ width: "70%" }} />
</div>
<span className="chat-answer-days-link"><span className="chart-skeleton-bar" style={{ width: 132 }} /></span>
</div>
);
}
export function AnswerDayCalendar({ range, calendar, reserve = false }: Readonly<{ range: DayRange; calendar?: AnswerDayCalendar; reserve?: boolean }>) {
const week = isWeekRange(range);
const byDate = new Map((calendar?.days ?? []).map((day) => [day.date, day]));
@@ -98,12 +139,12 @@ export function AnswerDayCalendar({ range, calendar, reserve = false }: Readonly
const selected = selectedDate ? asDay(byDate.get(selectedDate)!) : null;
const today = localToday();
const used = calendar ? LEVELS.filter((level) => [...named].some((date) => byDate.get(date)?.level === level)) : [];
const dates = week ? weekDates(range) : gridDates(range);
const { dates, heading: label } = dayCalendarLayout(range);
const heading = rangeHeading(range, week);
return (
<section className={`chat-answer-days${week ? " is-week" : " is-month"}${calendar ? " is-known" : " is-pending"}`} aria-label={heading}>
<div className="chat-answer-strip-head">
<p className="chat-answer-label">{week ? `${heading}(${dayLabel(dates[0]!)}到 ${dayLabel(dates.at(-1)!)})` : heading}</p>
<p className="chat-answer-label">{label}</p>
{used.length || reserve ? (
<div className="chat-answer-strip-legend" aria-hidden="true">
{used.map((level) => <span key={level}><i className={`is-${level}`} />{LEVEL_ZH[level]}</span>)}
+70 -11
View File
@@ -1,8 +1,9 @@
"use client";
import { ChevronRight } from "lucide-react";
import { useEffect, useState, type ReactNode } from "react";
import { useEffect, useState, type ReactNode, type TransitionEvent } from "react";
import { AnswerDayCalendarSkeleton } from "@/components/chat-answer-day-calendar";
import { ConversationFollowUps } from "@/components/conversation-follow-ups";
import { Button } from "@/components/ui/button";
import type { ChartBoardStyle } from "@/lib/chart-board-style";
@@ -16,6 +17,8 @@ import {
type AnswerTone,
type TimelineSegment,
} from "@/lib/chat-answer-shape";
import type { DayRange } from "@/lib/chat-day-calendar";
import { prefersReducedMotion } from "@/lib/motion/tokens";
import { CHART_SIZE, HOUSE_POLYGONS, polygonPoints } from "@/lib/north-indian-chart-geometry";
import { useUiStore } from "@/stores/ui-store";
@@ -182,7 +185,7 @@ export function segmentWeights(segments: readonly TimelineSegment[]): number[] {
* it wraps under the heading on very narrow widths); the turning-point sentence and the birth-time note are ONE small
* muted footer line under the panel (`stripFooterLine`).
*/
export function AnswerYearStrip({ timeline, tones, timeSensitive = false, reserve = false }: Readonly<{ timeline: NonNullable<AnswerShape["timeline"]>; tones?: readonly AnswerTone[]; timeSensitive?: boolean; reserve?: boolean }>) {
export function AnswerYearStrip({ timeline, tones, timeSensitive = false, reserve = false, arriving = reserve }: Readonly<{ timeline: NonNullable<AnswerShape["timeline"]>; tones?: readonly AnswerTone[]; timeSensitive?: boolean; reserve?: boolean; arriving?: boolean }>) {
const [picked, setPicked] = useState(0);
const segments = timeline.segments;
if (!segments.length) return null;
@@ -201,7 +204,8 @@ export function AnswerYearStrip({ timeline, tones, timeSensitive = false, reserv
const footer = stripFooterLine(timeline.note, timeSensitive);
return (
// BUG-2308: a strip that arrives in a live row (`reserve`) enters once, as a whole (opacity and transform only).
<section className={`chat-answer-strip${reserve ? " is-arriving" : ""}`} aria-label={timeline.heading}>
// BUG-2339: a strip that replaces its skeleton cross-fades with it instead (`arriving` false, see AnswerStripSlot).
<section className={`chat-answer-strip${arriving ? " is-arriving" : ""}`} aria-label={timeline.heading}>
<div className="chat-answer-strip-head">
<p className="chat-answer-label">{timeline.heading}</p>
{used.length || reserve ? (
@@ -250,22 +254,77 @@ export function AnswerYearStrip({ timeline, tones, timeSensitive = false, reserv
);
}
/** BUG-2339: what the slot will hold, known while the answer is written (the skeleton drawn until it completes). */
export type AnswerSlotSkeleton =
| Readonly<{ kind: "strip"; heading: string; weights: readonly number[] }>
| Readonly<{ kind: "days"; range: DayRange }>;
/** Five even blocks when the time section is not written yet. */
export const STRIP_SKELETON_WEIGHTS: readonly number[] = [1, 1, 1, 1, 1];
/**
* BUG-2339: the strip's skeleton — the heading row, one block per stretch (widths as the strip's when the section is
* written, else five even ones), the tick row, the panel box and the footer line — the strip's own classes for every
* box, so in the reserved slot it is exactly the strip's size; each piece is the chart pages' pulsing block.
*/
function AnswerYearStripSkeleton({ heading, weights }: Readonly<{ heading: string; weights: readonly number[] }>) {
const columns = weights.map((weight) => `minmax(40px, ${weight}fr)`).join(" ");
return (
<div className="chat-answer-strip-skeleton">
<div className="chat-answer-strip-head">
<p className="chat-answer-label">{heading}</p>
<div className="chat-answer-strip-legend" />
</div>
<div className="chat-answer-strip-bar" style={{ gridTemplateColumns: columns }}>
{weights.map((_, index) => <span key={index} className="chart-skeleton-bar chat-answer-strip-skeleton-block" />)}
</div>
<div className="chat-answer-strip-ticks" style={{ gridTemplateColumns: columns }}>
{weights.map((_, index) => <span key={index}><span className="chart-skeleton-bar chat-answer-strip-skeleton-tick" /></span>)}
</div>
<div className="chat-answer-strip-detail chat-answer-slot-skeleton-box">
<span className="chart-skeleton-bar" style={{ width: "45%" }} />
<span className="chart-skeleton-bar" style={{ width: "85%" }} />
<span className="chart-skeleton-bar" style={{ width: "65%" }} />
<span className="chart-skeleton-bar" style={{ width: "70%" }} />
</div>
<p className="chat-answer-strip-caveat"><span className="chart-skeleton-bar" style={{ width: "60%" }} /></p>
</div>
);
}
/**
* BUG-2320: the strip's fixed place — under the chart row, above the year sentence and the body — whatever order the
* writer used (the parser lifts the time section). In a row that streams here (`reserved`) the slot has the final strip's
* fixed height from the first frame (the label and a neutral bar stand in until the section is complete), so nothing
* moves when the strip is drawn into it. Rows read from history use the wrapper without a reserved height.
* fixed height from the first frame, so nothing moves when the strip is drawn into it. Rows read from history use the
* wrapper without a reserved height and never show a skeleton.
*
* BUG-2339 (owner 2026-11-24): while the answer is written the slot holds the skeleton of what it will hold (`skeleton`,
* strip or day calendar) and nothing else; when the whole answer is complete (`children` arrive) the strip or calendar
* is drawn in the same grid cell over the skeleton and the two cross-fade once — opacity only, `--motion-standard` /
* `--ease-standard` — then the skeleton is removed. Under reduced motion the swap is instant. 原值 (BUG-2320 / 2337): a
* label and a neutral bar, then the strip drawn mid-stream when its section was complete; the calendar's own grid in
* neutral; 新值: one skeleton until completion, one cross-fade; 原因: the owner saw an empty shell while it generated.
*/
export function AnswerStripSlot({ reserved, heading, days = false, children }: Readonly<{ reserved: boolean; heading: string; days?: boolean; children: ReactNode }>) {
export function AnswerStripSlot({ reserved, days = false, skeleton = null, children }: Readonly<{ reserved: boolean; days?: boolean; skeleton?: AnswerSlotSkeleton | null; children: ReactNode }>) {
const [faded, setFaded] = useState(false);
const settled = children !== null && children !== undefined && children !== false;
useEffect(() => {
// The skeleton blocks are the chart pages' (chart-board.css, loaded with the chart panel); load it if not yet there.
if (skeleton && !settled) void import("@/components/chart-board/chart-board-styles").catch(() => undefined);
}, [skeleton, settled]);
const showSkeleton = skeleton !== null && !(settled && (faded || prefersReducedMotion()));
const onFaded = (event: TransitionEvent<HTMLDivElement>) => {
if (settled && event.target === event.currentTarget && event.propertyName === "opacity") setFaded(true);
};
// BUG-2337: `days` — the slot holds the day calendar (its own fixed heights; the strip's reserved height does not apply).
return (
<div className={`chat-answer-strip-slot${days ? " is-days" : ""}${reserved ? " is-reserved" : ""}`}>
{children ?? (
<div className="chat-answer-strip-placeholder" aria-hidden="true">
<p className="chat-answer-label">{heading}</p>
<span className="chat-answer-strip-placeholder-bar" />
{showSkeleton ? (
<div className={`chat-answer-slot-skeleton${settled ? " is-leaving" : ""}`} aria-hidden="true" onTransitionEnd={onFaded}>
{skeleton.kind === "days" ? <AnswerDayCalendarSkeleton range={skeleton.range} /> : <AnswerYearStripSkeleton heading={skeleton.heading} weights={skeleton.weights} />}
</div>
)}
) : null}
{children}
</div>
);
}
@@ -4,7 +4,7 @@ import { answerAreaNameOverrides } from "@/lib/chat-chart-areas";
import { memo, useCallback, useEffect, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
import { prefetchOnIdle } from "@/components/chat-chunk-prefetch";
import { AnswerAreas, AnswerEvidenceGroup, AnswerStripSlot, AnswerVerdict, AnswerYearStrip } from "@/components/chat-answer-shape";
import { AnswerAreas, AnswerEvidenceGroup, AnswerStripSlot, AnswerVerdict, AnswerYearStrip, segmentWeights, STRIP_SKELETON_WEIGHTS, type AnswerSlotSkeleton } from "@/components/chat-answer-shape";
import { AnswerDayCalendar } from "@/components/chat-answer-day-calendar";
import { clampDayRange, type DayRange } from "@/lib/chat-day-calendar";
import { ConsultAnswerBasis } from "@/components/consult-answer-basis";
@@ -230,6 +230,20 @@ export function ChatMessageContent({
const dayCalendar = !streaming ? answerShape?.dayCalendar : undefined;
const dayRange = dayCalendar ? { start: dayCalendar.start, end: dayCalendar.end } : streaming ? dayRangeFromKey(streamedDays || liveDays) : null;
const slotWanted = Boolean(shape && streaming && !dayRange && stripSlotRequired(shape.verdict.facts.map((fact) => fact.label), liveTurn === "first"));
// BUG-2339 (owner 2026-11-24): while the answer is written the slot shows the skeleton of what it will hold — the day
// calendar when the writer asked for a day range, else the strip when the structure requires one (or its section is
// already written; then with its stretches' widths). The last skeleton seen is kept so the completing row cross-fades
// from exactly what was on screen; it is replaced only when what it stands for changes, never per streamed chunk.
const liveSkeleton: AnswerSlotSkeleton | null = !shape || !streaming
? null
: dayRange
? { kind: "days", range: dayRange }
: slotWanted || (shape.timeline && !shape.timelineLive)
? { kind: "strip", heading: shape.timeline?.heading ?? DEFAULT_TIMELINE_HEADING, weights: shape.timeline && !shape.timelineLive ? segmentWeights(shape.timeline.segments) : STRIP_SKELETON_WEIGHTS }
: null;
const liveSkeletonKey = liveSkeleton ? JSON.stringify(liveSkeleton) : "";
const [shownSkeleton, setShownSkeleton] = useState<{ key: string; skeleton: AnswerSlotSkeleton | null }>({ key: "", skeleton: null });
if (streaming && shownSkeleton.key !== liveSkeletonKey) setShownSkeleton({ key: liveSkeletonKey, skeleton: liveSkeleton });
const liveAreas = areasFromKey(streamed?.key ?? "");
const areas = streaming
? liveAreas
@@ -257,20 +271,28 @@ export function ChatMessageContent({
if (shape) {
const ascendant = chartData?.natal.find((row) => row.body === "Ascendant")?.sign;
const shapedBody = splitSpokenAnswerAndTechniqueAudit(shape.body).spoken;
// BUG-2308 (owner: the strip came in 「一卡一卡的」): while its section is still being written the strip is not drawn;
// it mounts once, whole, when the section is complete, and enters with one soft motion (live rows only).
const strip = shape.timeline && !dayRange && !(streaming && shape.timelineLive) ? (
// BUG-2308 (owner: the strip came in 「一卡一卡的」) → BUG-2339: the strip is drawn once, whole, when the answer is
// complete (its skeleton stands in until then). 原值: drawn as soon as its section was complete, mid-stream; 新值: at
// completion only; 原因: owner 2026-11-24 — skeleton while generating, one cross-fade when the whole answer is done.
const reserved = streamed !== null;
const strip = !streaming && shape.timeline && !dayRange ? (
<AnswerYearStrip
timeline={shape.timeline}
tones={streaming ? undefined : stripTones(shape.timeline.segments, answerShape?.tones)}
timeSensitive={!streaming && answerShape?.timeSensitive === true}
reserve={streaming || streamed !== null}
tones={stripTones(shape.timeline.segments, answerShape?.tones)}
timeSensitive={answerShape?.timeSensitive === true}
reserve={reserved}
arriving={reserved && shownSkeleton.skeleton?.kind !== "strip"}
/>
) : null;
const reserved = streamed !== null;
const slot = dayRange
? <AnswerStripSlot reserved={reserved} days heading="">{<AnswerDayCalendar range={dayRange} calendar={dayCalendar} reserve={reserved} />}</AnswerStripSlot>
: strip || slotWanted ? <AnswerStripSlot reserved={reserved} heading={shape.timeline?.heading ?? DEFAULT_TIMELINE_HEADING}>{strip}</AnswerStripSlot> : null;
const settledDays = !streaming && dayRange && dayCalendar ? <AnswerDayCalendar range={dayRange} calendar={dayCalendar} reserve={reserved} /> : null;
const settledKind = settledDays ? "days" : strip ? "strip" : null;
// The skeleton fades out only into what it stood for; a different outcome (no calendar came back) swaps instantly.
const skeleton = streaming ? liveSkeleton : shownSkeleton.skeleton?.kind === settledKind ? shownSkeleton.skeleton : null;
const slot = streaming
? (liveSkeleton ? <AnswerStripSlot reserved={reserved} days={liveSkeleton.kind === "days"} skeleton={liveSkeleton}>{null}</AnswerStripSlot> : null)
: settledKind
? <AnswerStripSlot reserved={reserved} days={settledKind === "days"} skeleton={skeleton}>{settledDays ?? strip}</AnswerStripSlot>
: null;
return (
<div className="message-answer chat-answer-shaped" ref={answerRef}>
<AnswerVerdict verdict={shape.verdict} />
+5 -2
View File
@@ -22,7 +22,7 @@ import { NEUTRAL_WORDING } from "./chat-answer-checks.ts";
import { isProtectedRemoval } from "./chat-answer-direct-reply.ts";
import { isGuaranteeSentence } from "./timing-output-guard.ts";
import { lordshipTable, normalizeTableCard, periodTable, tableCardView, tableFlags, type TableFlag } from "./chat-answer-tables.ts";
import { STRIP_HEDGE_WORDS, type AnswerTone } from "./chat-answer-shape.ts";
import { STRIP_HEDGE_WORDS, stripPanelOverflow, type AnswerTone } from "./chat-answer-shape.ts";
import { addImpliedKeys, bodyTerms, checkBodyDirection, checkBodyMechanism, checkStripTone, checkTimelineEntries, hasEvidenceTags, mechanismCount, stripToneMismatch } from "./chat-evidence-keys.ts";
type Json = Record<string, unknown>;
@@ -300,8 +300,11 @@ export function applyAnswerRepair(answer: string, repair: AnswerRepair, flags: R
// BUG-2281 review: a strip segment's rewrite keeps its 「**小标题**(起止):」 lead and now matches its program tone.
if (flag.kind === "verdict_hedge" && STRIP_HEDGE_WORDS.test(fix.text)) { rejected.push(`fix#${fix.id}:hedge`); continue; }
const stripLabel = stripLabelOfKind(flag.kind);
// BUG-2339: the tone is read on the title and sentence only (a whole-stretch rewrite carries 该做 / 别做 too), and a
// rewrite still longer than the panel's worst case is not used.
if (stripLabel
&& (!/^\*\*[^*]{1,12}\*\*[ \t]*[((][^()()]{2,40}[))]/u.test(fix.text) || stripToneMismatch(fix.text, stripLabel))) { rejected.push(`fix#${fix.id}:tone`); continue; }
&& (!/^\*\*[^*]{1,12}\*\*[ \t]*[((][^()()]{2,40}[))]/u.test(fix.text) || stripToneMismatch(fix.text.split(/该做[::]|别做[::]/u)[0]!, stripLabel))) { rejected.push(`fix#${fix.id}:tone`); continue; }
if (stripLabel && stripPanelOverflow(fix.text.replace(/^\*\*[^*]{1,12}\*\*[ \t]*[((][^()()]{2,40}[))][ \t]*[::]?/u, ""))) { rejected.push(`fix#${fix.id}:long`); continue; }
output = output.replace(flag.sentence, () => fix.text);
fixed += 1;
}
+16
View File
@@ -435,6 +435,22 @@ export function rangeDays(range: string, fallbackStart?: number): readonly [stri
return to > from ? [from, to] : null;
}
/**
* BUG-2339 (coordinator 2026-11-24: the desktop strip still grew 300 → 317px at completion — a writer's 54-character
* sentence). The strip slot's reserved heights are measured for the panel's worst case at these maxima (the writing
* rules' own numbers: 那一句 36 字以内,该做、别做各 24 字以内), so the program now holds every stretch to them: an over-long
* stretch is sent to the existing segment rewrite (checkStripTone → repair, rejected again if still too long) and the
* program-written strip is refused when over. Nothing is cut.
*/
export const STRIP_SENTENCE_MAX = 36;
export const STRIP_ADVICE_MAX = 24;
const stripChars = (text: string) => Array.from(text.replace(/〔[^〕]*〕/gu, "").replace(/\s+/gu, "").replace(/[。!?;;,,.]+$/u, "")).length;
/** True when a stretch's text after its 「**小标题**(起止):」 lead does not fit the panel's measured worst case. */
export function stripPanelOverflow(rest: string): boolean {
const { sentence, doThis, avoid } = splitAdvice(rest);
return stripChars(sentence) > STRIP_SENTENCE_MAX || stripChars(doThis) > STRIP_ADVICE_MAX || stripChars(avoid) > STRIP_ADVICE_MAX;
}
function splitAdvice(rest: string): { sentence: string; doThis: string; avoid: string } {
const text = plain(rest);
const doAt = text.search(/该做[::]/u);
+3 -1
View File
@@ -19,7 +19,7 @@ import { normalizeEvidenceTags } from "./chat-evidence-tags.ts";
import { splitJudgmentBasis } from "./consult-judgment-basis.ts";
import {
currentMonthIndex, DEFAULT_TIMELINE_HEADING, EASIEST_TIME_LABEL, rangeDays, type AnswerTone, isTimelineHeading, MAX_TIMELINE_SEGMENTS, parseAnswerShape, rangeMonths,
STRIP_ENGINEERING_WORDS, STRIP_HEDGE_WORDS, STRIP_LATIN, STRIP_STRAIN_SAID, stripLabelMismatch, stripTitleMismatch, TIME_WINDOW_LABELS, VERDICT_HEADING, verdictDomain, type AnswerShape, type AnswerShapeDomain,
STRIP_ENGINEERING_WORDS, STRIP_HEDGE_WORDS, STRIP_LATIN, stripPanelOverflow, STRIP_STRAIN_SAID, stripLabelMismatch, stripTitleMismatch, TIME_WINDOW_LABELS, VERDICT_HEADING, verdictDomain, type AnswerShape, type AnswerShapeDomain,
} from "./chat-answer-shape.ts";
export const BEST_TIME_LABEL = "最好的时候";
@@ -443,6 +443,8 @@ export function timelineSectionFromReply(reply: string, stretches: readonly Prog
if ([title, sentence, doThis, avoid].some((part) => TERM_OR_DETAIL.test(part) || /[(())〔〕::]/u.test(part))) return null;
if ([title, sentence, doThis, avoid].some((part) => STRIP_ENGINEERING_WORDS.test(part) || STRIP_HEDGE_WORDS.test(part) || STRIP_LATIN.test(part))) return null;
if (stripLabelMismatch(`${title} ${sentence}`, stretch.label) || stripTitleMismatch(title, stretch.label)) return null;
// BUG-2339: the panel's reserved height holds 36 / 24 / 24 characters at most; a longer reply is not used.
if (stripPanelOverflow(`${sentence}。该做:${doThis}。别做:${avoid}。`)) return null;
lines.push(`- **${title}**(${stretch.range}):${sentence}。该做:${doThis}。别做:${avoid}。〔${stretch.keys.join(" ")}〕`);
}
return lines.length <= MAX_TIMELINE_SEGMENTS ? lines.join("\n") : null;
+11 -2
View File
@@ -28,7 +28,7 @@ import { programKpLines, programStretches, programYear, segmentLabel } from "./c
import { kpPacketFromCard, packetSystemsLine } from "./chat-kp-timing.ts";
import { stripDomain } from "./chat-strip-status.ts";
import { splitJudgmentBasis } from "./consult-judgment-basis.ts";
import { ANSWER_TONE_LABELS, FOLLOW_UP_HEADING, isTimelineHeading, STRIP_ENGINEERING_WORDS, STRIP_HEDGE_WORDS, stripLabelMismatch, stripTitleMismatch, VERDICT_HEADING, type AnswerTone } from "./chat-answer-shape.ts";
import { ANSWER_TONE_LABELS, FOLLOW_UP_HEADING, isTimelineHeading, STRIP_ENGINEERING_WORDS, STRIP_HEDGE_WORDS, stripLabelMismatch, stripPanelOverflow, stripTitleMismatch, STRIP_ADVICE_MAX, STRIP_SENTENCE_MAX, VERDICT_HEADING, type AnswerTone } from "./chat-answer-shape.ts";
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- card JSON is read loosely; every value is checked where used
type J = Record<string, any>;
@@ -652,7 +652,16 @@ export function checkStripTone(text: string, card: EvidenceCard | null): PlainFl
const rest = hit[4]!;
const cut = rest.search(/该做[::]|别做[::]|〔/u);
const sentence = (cut >= 0 ? rest.slice(0, cut) : rest).replace(/\s+$/u, "");
if (!stripToneMismatch(`${hit[2]} ${sentence}`, label, hit[2])) continue;
const tone = stripToneMismatch(`${hit[2]} ${sentence}`, label, hit[2]);
// BUG-2339: a stretch longer than the panel's measured worst case goes to the same rewrite, the whole stretch (sentence,
// 该做, 别做) at once; nothing is cut.
const whole = (rest.search(/〔/u) >= 0 ? rest.slice(0, rest.search(/〔/u)) : rest).replace(/\s+$/u, "");
const long = stripPanelOverflow(whole);
if (!tone && !long) continue;
if (long) {
out.push({ kind: `strip_${label}`, sentence: `${hit[1]}${whole}`.trim(), card: `${tone ? `${LABEL_FIX[label]};` : ""}这一段写长了,时间条下面的说明框放不下:那一句 ${STRIP_SENTENCE_MAX} 字以内,该做、别做各 ${STRIP_ADVICE_MAX} 字以内,意思不变;只说一件确定的事,不写可能、或许、也许、不排除、视情况这类两头的话。保留「**小标题**(起止):一句。该做:……。别做:……。」的写法和括号里的起止年月,不写术语` });
continue;
}
out.push({ kind: `strip_${label}`, sentence: `${hit[1]}${sentence}`.trim(), card: `${LABEL_FIX[label]};只说一件确定的事,不写可能、或许、也许、不排除、视情况这类两头的话。保留「**小标题**(起止):」的写法和括号里的起止年月,不写术语` });
}
return out;
+3 -1
View File
@@ -164,7 +164,9 @@ test("BUG-2305: nothing above the body moves between the last streaming frame an
const done = top();
assert.deepEqual(done.shape, last.shape, "the same elements above the body");
done.nodes.forEach((node, index) => assert.equal(node, last.nodes[index], "the same DOM nodes (nothing re-inserted)"));
assert.equal(done.strip, 2);
// 原值:2;新值:4(时间条自己的图例和页脚两行,加上正在淡出的骨架里同样的两行);原因:BUG-2339 完成时骨架和时间条在同一格里交叉淡化,
// 骨架淡完后才移除。流式时的 2 行现在是骨架的(同类名、同位置)。
assert.equal(done.strip, 4);
// The row's words refined to the receipt's areas; its height is fixed in CSS.
assert.match(h.container.text, /这次看了 2 个地方:感情和伴侣、收入/u);
assert.match(css, /\.chat-answer-areas\[data-slot="button"\] \{ display: flex; width: 100%; height: 78px;/u);
@@ -0,0 +1,204 @@
// BUG-2339 (owner 2026-11-24): while the answer is written, the slot under the chart row shows a skeleton of what it
// will hold — the strip (heading row, one block per stretch, tick row, panel box, footer line) or the day calendar (a
// week's seven cells, or the month grid with its weekday row, the fixed box, the link row) — in the chart pages'
// skeleton style; when the whole answer is complete the real component is drawn in the same cell and the two
// cross-fade once (opacity only, --motion-standard / --ease-standard); never per streamed chunk; history rows never
// show a skeleton; the dark 平 legend chip gets a hairline ring from an existing neutral token.
// Heights: skeleton and final are the same boxes (measured in Chromium, see BUG_HISTORY BUG-2339); here the structure
// that makes them equal is pinned (same classes, same cell count, the strip's reserved slot).
import "./install-test-document";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import React from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { AnswerDayCalendar, AnswerDayCalendarSkeleton } from "../src/components/chat-answer-day-calendar.tsx";
import { AnswerStripSlot } from "../src/components/chat-answer-shape.tsx";
import { ChatMessageContent } from "../src/components/chat-message-content.tsx";
import { applyAnswerRepair } from "../src/lib/chat-answer-repair.ts";
import { STRIP_ADVICE_MAX, STRIP_SENTENCE_MAX, stripPanelOverflow } from "../src/lib/chat-answer-shape.ts";
import { timelineSectionFromReply, type ProgramStretch } from "../src/lib/chat-answer-timeline.ts";
import { checkStripTone } from "../src/lib/chat-evidence-keys.ts";
import { loadChatMarkdown } from "../src/lib/chat-markdown-loader.ts";
import { beginChatWait, feedChatWait, resetChatWaitForTests } from "../src/lib/chat-wait-store.ts";
import { createClientLifecycleHarness } from "./react-client-lifecycle-test-support";
const css = readFileSync(new URL("../src/app/globals.css", import.meta.url), "utf8");
const classOf = (node: { getAttribute(name: string): string | null }) => node.getAttribute("class") ?? "";
const count = (html: string, pattern: RegExp) => (html.match(pattern) ?? []).length;
const VERDICT = [
"## 结论",
"你最适合靠一门说得清的专业本事收钱。",
"- **钱从哪来**:专业本事换客户结算",
"- **最好的时候**:2027 年 1 月到 5 月中旬",
].join("\n");
const TIME = [
"## 接下来一年",
"- **收进**(现在到 2026 年 12 月):进钱的门路是开的。该做:先写清价格。别做:别先垫钱。",
"- **好谈**(2027 年 1 月到 5 月中旬):谈下来的钱落得到手里。该做:主动开价。别做:别压价。",
"- **守住**(2027 年 5 月中旬到 10 月):支出多。该做:两笔账分开记。别做:别签长期承诺。",
].join("\n");
const BODY = "## 你在钱上的长处和短处\n**你挣钱的路子比存钱的路子宽。** 活是你自己干的。";
test("BUG-2339 strip: skeleton from the first frame until completion (no strip mid-stream), then one cross-fade in the same slot", async () => {
await loadChatMarkdown();
resetChatWaitForTests();
beginChatWait("req-1", "s", true, true);
const h = createClientLifecycleHarness();
try {
const all = () => h.elements();
const slot = () => all().find((node) => classOf(node).startsWith("chat-answer-strip-slot"));
const skeleton = () => all().find((node) => classOf(node).startsWith("chat-answer-slot-skeleton"));
const strips = () => all().filter((node) => /(?:^| )chat-answer-strip(?: |$)/u.test(classOf(node)));
const blocks = () => all().filter((node) => classOf(node).includes("chat-answer-strip-skeleton-block")).length;
await h.render(<ChatMessageContent text={"## 结论\n你最适合靠一门说得清的专业本事收钱。\n"} structured streaming />);
const first = slot()!;
const sk = skeleton()!;
assert.equal(classOf(first), "chat-answer-strip-slot is-reserved");
assert.equal(classOf(sk), "chat-answer-slot-skeleton");
assert.equal(sk.getAttribute("aria-hidden"), "true");
assert.equal(blocks(), 5, "five even blocks before the time section is written");
// 原值 (BUG-2308 / 2320): the strip was drawn as soon as its section was complete; 新值: skeleton until the whole
// answer completes, with the written stretches' count; 原因: owner 2026-11-24.
await h.render(<ChatMessageContent text={`${VERDICT}\n\n${TIME}\n\n${BODY}`} structured streaming />);
assert.equal(slot(), first);
assert.equal(skeleton(), sk, "the same skeleton node while streaming");
assert.equal(strips().length, 0, "no strip while the answer is written");
assert.equal(blocks(), 3, "one block per written stretch");
await h.render(<ChatMessageContent text={`${VERDICT}\n\n${TIME}\n\n${BODY}\n\n更多正文。`} structured streaming />);
assert.equal(skeleton(), sk, "no swap per chunk");
assert.equal(classOf(sk), "chat-answer-slot-skeleton");
// Completion: the strip is drawn into the same slot after the same skeleton node, which starts leaving.
await h.render(<ChatMessageContent text={`${VERDICT}\n\n${TIME}\n\n${BODY}\n\n更多正文。`} structured answerShape={{ areas: [2], tones: ["chance", "chance", "strain"] }} />);
assert.equal(slot(), first);
assert.equal(classOf(first), "chat-answer-strip-slot is-reserved");
assert.equal(skeleton(), sk);
assert.equal(classOf(sk), "chat-answer-slot-skeleton is-leaving");
assert.equal(strips().length, 1);
assert.ok(first.childNodes.indexOf(strips()[0]!) > first.childNodes.indexOf(sk), "the strip sits over the skeleton");
assert.doesNotMatch(classOf(strips()[0]!), /is-arriving/u, "cross-fade instead of the slide-in entrance");
} finally {
await h.close();
resetChatWaitForTests();
}
// History: the strip alone, no skeleton.
const stored = renderToStaticMarkup(<ChatMessageContent text={`${VERDICT}\n\n${TIME}\n\n${BODY}`} structured answerShape={{ areas: [2], tones: ["chance", "chance", "strain"] }} />);
assert.doesNotMatch(stored, /chat-answer-slot-skeleton|chart-skeleton-bar/u);
});
test("BUG-2339 days: the writer's day range shows the calendar skeleton while streaming; the calendar cross-fades in at completion", async () => {
await loadChatMarkdown();
resetChatWaitForTests();
beginChatWait("req-2", "s", false, true);
feedChatWait("req-2", { type: "run.started", runId: "r", requestId: "req-2" } as never);
feedChatWait("req-2", { type: "tool.started", callId: "c", tool: "run-jyotish-consultation", label: "正在计算个人星盘", dayRange: { start: "2026-11-30", end: "2026-12-06" } } as never);
const answer = "## 结论\n这周挑周三。\n- **最好的日子**:周三 12 月 2 日\n- **避开**:周六 12 月 5 日\n\n**周三最好。** 这天顺。";
const h = createClientLifecycleHarness();
try {
const all = () => h.elements();
const skeleton = () => all().find((node) => classOf(node).startsWith("chat-answer-slot-skeleton"));
await h.render(<ChatMessageContent text={answer} structured streaming />);
const sk = skeleton()!;
assert.ok(sk);
assert.equal(all().filter((node) => /(?:^| )chat-answer-days(?: |$)/u.test(classOf(node))).length, 1, "only the skeleton's grid");
assert.equal(all().filter((node) => classOf(node).includes("chart-skeleton-bar is-cell chat-answer-day")).length, 7);
const days = Array.from({ length: 7 }, (_, index) => ({ date: `2026-${index ? "12" : "11"}-${String(index ? index + 0 : 30).padStart(2, "0")}`, level: index === 2 ? "good" as const : "mid" as const, theme: "career", reasons: [] }));
await h.render(<ChatMessageContent text={answer} structured answerShape={{ areas: [], tones: [], dayCalendar: { start: "2026-11-30", end: "2026-12-06", days, mentioned: ["2026-12-02"], best: "2026-12-02" } }} />);
assert.equal(skeleton(), sk);
assert.equal(classOf(sk), "chat-answer-slot-skeleton is-leaving");
assert.ok(all().some((node) => /chat-answer-days is-week is-known/u.test(classOf(node))));
} finally {
await h.close();
resetChatWaitForTests();
}
});
test("BUG-2339 same boxes: the calendar skeleton draws the calendar's own cells, box and link row (week and month)", () => {
for (const range of [{ start: "2026-11-30", end: "2026-12-06" }, { start: "2026-12-01", end: "2026-12-31" }]) {
const skeleton = renderToStaticMarkup(<AnswerDayCalendarSkeleton range={range} />);
const calendar = renderToStaticMarkup(<AnswerDayCalendar range={range} reserve />);
assert.equal(count(skeleton, /chat-answer-day[ "]/gu), count(calendar, /chat-answer-day[ "]/gu), "same cell count");
for (const box of ["chat-answer-strip-head", "chat-answer-days-grid", "chat-answer-days-detail", "chat-answer-days-link"]) assert.ok(skeleton.includes(box), box);
assert.equal(skeleton.includes("chat-answer-days-head"), calendar.includes("chat-answer-days-head"), "the weekday row only on the month");
assert.match(skeleton, new RegExp(`class="chat-answer-days ${range.end === "2026-12-06" ? "is-week" : "is-month"}"`, "u"));
}
const strip = renderToStaticMarkup(<AnswerStripSlot reserved skeleton={{ kind: "strip", heading: "接下来一年", weights: [2, 1] }}>{null}</AnswerStripSlot>);
for (const box of ["chat-answer-strip-head", "chat-answer-strip-bar", "chat-answer-strip-ticks", "chat-answer-strip-detail", "chat-answer-strip-caveat"]) assert.ok(strip.includes(box), box);
assert.match(strip, /grid-template-columns:minmax\(40px, 2fr\) minmax\(40px, 1fr\)/u, "the stretches' widths");
assert.match(strip, /^<div class="chat-answer-strip-slot is-reserved">/u);
});
test("BUG-2339 CSS: one cell, opacity-only cross-fade on the motion tokens, no pulse and instant under reduced motion, dark 平 chip", () => {
assert.match(css, /\.chat-answer-strip-slot \{ display: grid; grid-template-columns: minmax\(0, 1fr\);/u);
assert.match(css, /\.chat-answer-strip-slot > \* \{ grid-area: 1 \/ 1; min-width: 0; --chat-strip-slot-height: \d+px; \}/u);
assert.match(css, /\.chat-answer-slot-skeleton \{[^}]*transition: opacity var\(--motion-standard\) var\(--ease-standard\), visibility 0s linear var\(--motion-standard\); \}/u);
assert.match(css, /\.chat-answer-slot-skeleton\.is-leaving \{ visibility: hidden; opacity: 0; \}/u);
assert.match(css, /\.chat-answer-slot-skeleton\.is-leaving ~ \* \{ animation: chat-answer-fade-in var\(--motion-standard\) var\(--ease-standard\) both; \}/u);
assert.match(css, /@keyframes chat-answer-fade-in \{ from \{ opacity: 0; \} to \{ opacity: 1; \} \}/u);
const block = css.slice(css.indexOf("BUG-2339 (owner 2026-11-24): while the answer"), css.indexOf(".chat-answer-next .conversation-follow-ups"));
assert.doesNotMatch(block.replace(/\/\*[\s\S]*?\*\//gu, ""), /transition:[^;]*(?:height|width|transform)|\b\d+ms\b/u, "opacity only, tokens only");
assert.match(block, /@media \(prefers-reduced-motion: reduce\) \{\n {2}\.chat-answer-slot-skeleton \{ transition: none; \}\n {2}\.chat-answer-slot-skeleton\.is-leaving ~ \* \{ animation: none; \}\n\}/u);
assert.doesNotMatch(block, /shimmer|background-position/u, "no shimmer, the existing slow pulse");
assert.match(block, /:root:not\(\[data-theme="light"\]\) \.chat-answer-strip-legend i\.is-mid \{ box-shadow: inset 0 0 0 1px var\(--color-ink-tertiary\); \}/u);
assert.match(block, /:root\[data-theme="dark"\] \.chat-answer-strip-legend i\.is-mid \{ box-shadow: inset 0 0 0 1px var\(--color-ink-tertiary\); \}/u);
assert.doesNotMatch(css, /chat-answer-strip-placeholder/u, "the old label-and-bar stand-in is gone");
const shapeSource = readFileSync(new URL("../src/components/chat-answer-shape.tsx", import.meta.url), "utf8");
assert.match(shapeSource, /prefersReducedMotion\(\)/u, "reduced motion swaps instantly");
});
// Coordinator 2026-11-24: the desktop strip still grew 300 → 317px at completion (a writer's 54-character sentence). The
// reserved heights are the panel's worst case at the program-enforced maxima, by the slot's own width; measured in
// Chromium with a synthetic max-length strip (longest ranges with 「有机会,但费力」, 36 / 24 / 24 characters, all legend
// labels, footer with the birth-time note) and the longest compliant real answer: skeleton / mid / final equal at every
// band edge. The table below is that measurement (natural height without the reservation); each band must hold it.
const WORST_AT: ReadonlyArray<readonly [number, number]> = [[320, 432], [343, 387], [480, 318], [640, 293]];
const cutTo = (text: string, n: number) => Array.from(text.repeat(4)).slice(0, n).join("");
const SENT = "手上的位置和资源都能用上谈下来的条件也更实在其中一月上旬最集中再往后排";
const ADV = "把想换的方向先谈成一两件具体的事再定下一步怎么走";
test("BUG-2339 max length: 36 / 24 / 24 characters fit, one more is sent to the rewrite, the rewrite and fill are refused when over", () => {
const fits = `${cutTo(SENT, STRIP_SENTENCE_MAX)}。该做:${cutTo(ADV, STRIP_ADVICE_MAX)}。别做:${cutTo(ADV, STRIP_ADVICE_MAX)}。`;
assert.equal(stripPanelOverflow(fits), false);
assert.equal(stripPanelOverflow(`${cutTo(SENT, STRIP_SENTENCE_MAX + 1)}。该做:短。别做:短。`), true);
assert.equal(stripPanelOverflow(`短。该做:${cutTo(ADV, STRIP_ADVICE_MAX + 1)}。别做:短。`), true);
assert.equal(stripPanelOverflow(`短。该做:短。别做:${cutTo(ADV, STRIP_ADVICE_MAX + 1)}。`), true);
assert.equal(stripPanelOverflow(`${cutTo(SENT, STRIP_SENTENCE_MAX)}。〔W1 T3〕`), false, "evidence keys do not count");
// The writer's over-long stretch (the owner-visible case): the whole stretch goes to the existing rewrite, nothing cut.
const long = `${cutTo(SENT, 54)}。该做:谈。别做:拖。`;
const text = ["## 结论", "好。", "", "## 接下来一年", `- **谈成**(现在到 2027 年 1 月):${long}〔W1〕`, "", "## 你的长处和短处", "**稳。** 没问题。", "", "## 判断依据", "", "- **x**:说明。〔Sa〕"].join("\n");
const flags = checkStripTone(text, minimalCard());
assert.equal(flags.length, 1);
assert.equal(flags[0]!.sentence, `**谈成**(现在到 2027 年 1 月):${long}`);
assert.match(flags[0]!.card, /那一句 36 字以内,该做、别做各 24 字以内/u);
const flag = { id: 1, kind: flags[0]!.kind, sentence: flags[0]!.sentence };
const tooLong = applyAnswerRepair(text, { layers: [], fixes: [{ id: 1, text: `**谈成**(现在到 2027 年 1 月):${cutTo(SENT, 40)}。该做:谈。别做:拖。` }] }, [flag], minimalCard());
assert.deepEqual(tooLong.rejected, ["fix#1:long"]);
const fixed = applyAnswerRepair(text, { layers: [], fixes: [{ id: 1, text: `**谈成**(现在到 2027 年 1 月):${cutTo(SENT, 30)}。该做:谈。别做:拖。` }] }, [flag], minimalCard());
assert.equal(fixed.fixed, 1);
assert.match(fixed.output, /〔W1〕/u, "the keys stay after the rewritten stretch");
const only: ProgramStretch[] = [{ keys: ["W1"], from: 0, to: 0, fromDay: "2026-11-01", toDay: "2027-01-01", label: "chance", reasons: "", basis: "", rules: [], range: "现在到 2026 年 12 月" }];
assert.equal(timelineSectionFromReply(JSON.stringify({ stretches: [{ title: "谈成", sentence: cutTo(SENT, 37), do: "多见客户", avoid: "别拖着" }] }), only), null);
assert.ok(timelineSectionFromReply(JSON.stringify({ stretches: [{ title: "谈成", sentence: cutTo(SENT, 36), do: "多见客户", avoid: "别拖着" }] }), only));
});
test("BUG-2339 max length: each slot-width band reserves at least the measured worst case (skeleton = mid = final)", () => {
const bands: Array<readonly [number, number]> = [[0, Number(/\.chat-answer-strip-slot > \* \{[^}]*--chat-strip-slot-height: (\d+)px;/u.exec(css)![1])]];
for (const hit of css.matchAll(/@container \(min-width: (\d+)px\) \{ \.chat-answer-strip-slot > \* \{ --chat-strip-slot-height: (\d+)px; \} \}/gu)) bands.push([Number(hit[1]), Number(hit[2])]);
assert.deepEqual(bands, [[0, 436], [343, 392], [480, 324], [640, 300]]);
for (const [width, worst] of WORST_AT) {
const reserve = [...bands].reverse().find(([from]) => width >= from)![1];
assert.ok(reserve >= worst, `${width}px: ${reserve} >= ${worst}`);
}
assert.match(css, /\.chat-answer-strip-slot \{[^}]*container-type: inline-size;/u);
assert.match(css, /\.chat-answer-strip-slot\.is-reserved:not\(\.is-days\) > \* \{ min-height: var\(--chat-strip-slot-height\); \}/u);
});
function minimalCard() {
return {
domains: ["career"],
base: { natal: { ascendant: { sign: "Capricorn" }, houses: {}, planets: {}, more: {} }, timing: {} },
domain_sections: {},
} as never;
}
+12 -7
View File
@@ -276,11 +276,17 @@ test("BUG-2308 motion: the strip is not drawn while its section is written; it m
assert.equal(above.length, 1);
await h.render(<ChatMessageContent text={`${verdict}\n\n${timeline}\n`} structured streaming />);
assert.equal(strips().length, 0, "the last stretch line is still the live section");
// The section is complete (the body heading has begun): the strip mounts whole, once, entering softly.
// 原值: the section complete (body heading begun) → the strip mounted mid-stream with is-arriving; 新值 (BUG-2339):
// the skeleton stays until the whole answer completes, then the strip mounts once and cross-fades with it (no
// is-arriving); 原因: owner 2026-11-24 — skeleton while generating, one swap at completion.
await h.render(<ChatMessageContent text={`${verdict}\n\n${timeline}\n\n${body}`} structured streaming />);
assert.equal(strips().length, 0);
const bodyNode = shaped().childNodes.find((node) => node.getAttribute("class") === "message-markdown")!;
const bodyAt = shaped().childNodes.indexOf(bodyNode);
await h.render(<ChatMessageContent text={`${verdict}\n\n${timeline}\n\n${body}`} structured answerShape={{ areas: [10], tones: ["none", "chance", "strain"] }} />);
assert.equal(strips().length, 1);
const strip = strips()[0]!;
assert.match(strip.getAttribute("class")!, /is-arriving/u);
assert.doesNotMatch(strip.getAttribute("class")!, /is-arriving/u);
assert.equal(h.elements().filter((node) => (node.getAttribute("class") ?? "").includes("chat-answer-strip-segment")).length, 3);
above.forEach((node, index) => assert.equal(shaped().childNodes[index], node, "the blocks above keep their nodes and places"));
// 原值:strip is a direct child of the answer; 新值:it sits in the slot (BUG-2320), the slot is the child under the verdict;
@@ -288,11 +294,7 @@ test("BUG-2308 motion: the strip is not drawn while its section is written; it m
const slotNode = shaped().childNodes.find((node) => (node.getAttribute("class") ?? "").includes("chat-answer-strip-slot"))!;
assert.ok(slotNode.childNodes.includes(strip), "the strip is drawn into its slot");
assert.ok(shaped().childNodes.indexOf(slotNode) > shaped().childNodes.indexOf(above[0]!), "the strip under the verdict");
const bodyNode = shaped().childNodes.find((node) => node.getAttribute("class") === "message-markdown")!;
const bodyAt = shaped().childNodes.indexOf(bodyNode);
// Completion (tones arrive): the same strip node, the same body node and place.
await h.render(<ChatMessageContent text={`${verdict}\n\n${timeline}\n\n${body}`} structured answerShape={{ areas: [10], tones: ["none", "chance", "strain"] }} />);
assert.equal(strips()[0], strip);
// Completion: the same body node and place.
assert.equal(shaped().childNodes.indexOf(bodyNode), bodyAt);
} finally {
await h.close();
@@ -319,6 +321,9 @@ test("BUG-2308 → BUG-2320: a strip the program added after the body was on scr
const reserved = slot()!;
assert.ok(shaped().childNodes.indexOf(reserved) < bodyAt, "the slot is reserved above the body");
await h.render(<ChatMessageContent text={added} structured streaming />);
// 原值: the added strip was drawn into the slot mid-stream; 新值: it is drawn at completion (BUG-2339 skeleton until
// then); 原因: owner 2026-11-24.
await h.render(<ChatMessageContent text={added} structured answerShape={{ areas: [], tones: [] }} />);
const children = shaped().childNodes;
assert.equal(slot(), reserved, "the same slot");
assert.ok(reserved.childNodes.some((node) => /(?:^| )chat-answer-strip(?: |$)/u.test(node.getAttribute("class") ?? "")), "the strip is drawn into it");
+12 -6
View File
@@ -83,14 +83,17 @@ test("BUG-2320 slot: reserved at the final strip's height from the first frame,
const first = slot()!;
assert.ok(first, "slot from the first frame");
assert.equal(classOf(first), "chat-answer-strip-slot is-reserved");
assert.ok(first.childNodes.some((node) => classOf(node) === "chat-answer-strip-placeholder"), "label and a neutral bar stand in");
// 原值: a label and a neutral bar stood in (chat-answer-strip-placeholder); 新值: the strip's skeleton (BUG-2339);
// 原因: owner 2026-11-24 — a skeleton while generating, one cross-fade at completion.
assert.ok(first.childNodes.some((node) => classOf(node) === "chat-answer-slot-skeleton"), "the strip's skeleton stands in");
// The time section is being written: still the placeholder, same node.
await h.render(<ChatMessageContent text={`${VERDICT}\n\n${TIME.split("\n").slice(0, 3).join("\n")}\n`} structured streaming />);
assert.equal(slot(), first);
// Body streaming: the strip is drawn into the same slot; the body sits under it.
// Body streaming: 原值: the strip was drawn into the same slot; 新值: the skeleton stays until completion (BUG-2339);
// 原因: owner 2026-11-24. The body sits under the slot.
await h.render(<ChatMessageContent text={`${VERDICT}\n\n${TIME}\n\n${BODY}`} structured streaming />);
assert.equal(slot(), first);
assert.ok(first.childNodes.some((node) => /(?:^| )chat-answer-strip(?: |$)/u.test(classOf(node))));
assert.ok(!first.childNodes.some((node) => /(?:^| )chat-answer-strip(?: |$)/u.test(classOf(node))));
const bodyNode = shapedChildren(h).find((node) => classOf(node) === "message-markdown")!;
const bodyAt = shapedChildren(h).indexOf(bodyNode);
assert.ok(shapedChildren(h).indexOf(first) < bodyAt);
@@ -104,9 +107,12 @@ test("BUG-2320 slot: reserved at the final strip's height from the first frame,
resetChatWaitForTests();
}
// The height is one fixed value per width band; the panel takes the spare height; the footer keeps two lines' room.
assert.match(css, /\.chat-answer-strip-slot\.is-reserved \{ min-height: var\(--chat-strip-slot-height\); \}/u);
assert.match(css, /\.chat-answer-strip-slot \{[^}]*--chat-strip-slot-height: \d+px;/u);
assert.match(css, /@media \(min-width: 641px\) \{ \.chat-answer-strip-slot \{ --chat-strip-slot-height: \d+px; \} \}/u);
// 原值: min-height on the slot, 408px and 300px from a 641px viewport; 新值 (BUG-2339): on the slot's layers, by the
// slot's own width (container query) 436 / 392 from 343px / 324 from 480px / 300 from 640px; 原因: the column narrows with
// the sidebar and the chart panel; a 480–639px column overran 300px and a 360px phone 408px (worst cases 318 / 432px).
assert.match(css, /\.chat-answer-strip-slot\.is-reserved:not\(\.is-days\) > \* \{ min-height: var\(--chat-strip-slot-height\); \}/u);
assert.match(css, /\.chat-answer-strip-slot > \* \{[^}]*--chat-strip-slot-height: \d+px;/u);
assert.match(css, /@container \(min-width: 640px\) \{ \.chat-answer-strip-slot > \* \{ --chat-strip-slot-height: \d+px; \} \}/u);
assert.match(css, /\.chat-answer-strip-slot\.is-reserved \.chat-answer-strip-detail \{ flex: 1; \}/u);
assert.match(css, /\.chat-answer-strip-slot\.is-reserved \.chat-answer-strip-caveat \{ min-height: 3em; \}/u);
// Not required: a personality first turn drops the slot the moment its labels show (before any body text); a