[P1/高] ContextBuilder 时区硬编码 Asia/Shanghai,跨时区用户显示错误 #43

Closed
opened 2026-07-21 21:56:07 +08:00 by thzxx · 1 comment
Owner

问题类型

缺陷 / 高 / Agent 引擎

文件位置

electron/harness/prompts/context-builder.ts

问题描述

ContextBuilder.buildSystemPrompt 中:

const now = new Date();
const timezone = 'Asia/Shanghai'; // 硬编码
const formattedTime = now.toLocaleString('zh-CN', { timeZone: timezone });

硬编码 Asia/Shanghai 时区:

  • 跨时区用户(海外华人、出差)看到的时间与本地不符
  • 系统提示中时间错误可能影响 LLM 理解
  • 违反本地化原则

影响

  • 时间显示错误
  • LLM 时间感知不准

建议修复

// 使用系统本地时区
const formattedTime = now.toLocaleString('zh-CN', {
  timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
});

// 或显式传入
const timezone = process.env.TZ
  ?? Intl.DateTimeFormat().resolvedOptions().timeZone;

同时考虑添加 timezone 配置项让用户覆盖。

## 问题类型 缺陷 / 高 / Agent 引擎 ## 文件位置 `electron/harness/prompts/context-builder.ts` ## 问题描述 ContextBuilder.buildSystemPrompt 中: ```ts const now = new Date(); const timezone = 'Asia/Shanghai'; // 硬编码 const formattedTime = now.toLocaleString('zh-CN', { timeZone: timezone }); ``` 硬编码 Asia/Shanghai 时区: - 跨时区用户(海外华人、出差)看到的时间与本地不符 - 系统提示中时间错误可能影响 LLM 理解 - 违反本地化原则 ## 影响 - 时间显示错误 - LLM 时间感知不准 ## 建议修复 ```ts // 使用系统本地时区 const formattedTime = now.toLocaleString('zh-CN', { timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, }); // 或显式传入 const timezone = process.env.TZ ?? Intl.DateTimeFormat().resolvedOptions().timeZone; ``` 同时考虑添加 timezone 配置项让用户覆盖。
thzxx added the Agent????? labels 2026-07-21 21:56:07 +08:00
Author
Owner

修复说明

文件: electron/harness/prompts/context-builder.ts

修复: 时区硬编码 Asia/Shanghai 改为 Intl.DateTimeFormat().resolvedOptions().timeZone(系统本地时区),兜底回退 Asia/Shanghai。System Prompt 中的时区标注同步使用本地时区名。

验证: tsc --noEmit 类型检查通过。

## 修复说明 **文件**: `electron/harness/prompts/context-builder.ts` **修复**: 时区硬编码 `Asia/Shanghai` 改为 `Intl.DateTimeFormat().resolvedOptions().timeZone`(系统本地时区),兜底回退 `Asia/Shanghai`。System Prompt 中的时区标注同步使用本地时区名。 **验证**: `tsc --noEmit` 类型检查通过。
thzxx closed this issue 2026-07-22 09:43:24 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MetonaTeam/metona-ai-desktop#43