diff --git a/.agents/notes/implemented/feature/2026-11-09-sdk-prompt-time-zone.i18n.yaml b/.agents/notes/implemented/feature/2026-11-09-sdk-prompt-time-zone.i18n.yaml index b990b8bec6..0fb681452f 100644 --- a/.agents/notes/implemented/feature/2026-11-09-sdk-prompt-time-zone.i18n.yaml +++ b/.agents/notes/implemented/feature/2026-11-09-sdk-prompt-time-zone.i18n.yaml @@ -15,5 +15,5 @@ en: b67b2d44aeb2dc6b zh: 69d0356bfe3204a6 /agent-note-per-prompt-sdk-time-zone/consequences: - en: afe2bb440de799ca - zh: 2a6d55e8c4f2dc21 + en: ec0b5f4a68aaa351 + zh: 4eb09ed822f456a2 diff --git a/.agents/notes/implemented/feature/2026-11-09-sdk-prompt-time-zone.md b/.agents/notes/implemented/feature/2026-11-09-sdk-prompt-time-zone.md index 4161b2f79a..6d8a423f13 100644 --- a/.agents/notes/implemented/feature/2026-11-09-sdk-prompt-time-zone.md +++ b/.agents/notes/implemented/feature/2026-11-09-sdk-prompt-time-zone.md @@ -29,7 +29,7 @@ The zone stays request-local message source data, as in the [explicit Schedule t ## Consequences -- SDK embeddings that pass no zone now report the runtime process zone. In a container this is usually `UTC`, which may differ from the user's zone; the [upgrade guide](../../../../docs/upgrade-guide/v0.2.2-rc.1/sdk-prompt-time-zone/guide.md) tells consumers to pass `timeZone` or `time_zone`, or to set `TZ`. +- SDK embeddings that pass no zone now report the runtime process zone. In a container this is usually `UTC`, which may differ from the user's zone; the [upgrade guide](../../../../docs/upgrade-guide/v0.2.2-rc.5/sdk-prompt-time-zone/guide.md) tells consumers to pass `timeZone` or `time_zone`, or to set `TZ`. - SDK subagent children receive prompts without a zone, so they report their own process zone; in-process children see `unavailable`, as on Web. - A reader that predates the relaxed check ignores an SDK prompt zone; the [persistence record](../../../../docs/persistence-changes/2026-11-09-sdk-prompt-time-zone.md) keeps the format version. - `packages/sdk/server/tests/time-zone.spec.ts` pins canonical, rejected, sampled, and unusable zones, the `session/query` route, and matching `/plan` sources on the SDK and native command paths. `apps/cli/tests/profiles/sdk/keyless-smoke.e2e.ts` asserts the model-visible line through the shipped `sdk` profile. The SDK snapshot driver sends `timeZone: 'UTC'` and runs with `TZ=UTC`. diff --git a/.agents/notes/implemented/feature/2026-11-09-sdk-prompt-time-zone.zh.md b/.agents/notes/implemented/feature/2026-11-09-sdk-prompt-time-zone.zh.md index 648839051a..eaedf2cb51 100644 --- a/.agents/notes/implemented/feature/2026-11-09-sdk-prompt-time-zone.zh.md +++ b/.agents/notes/implemented/feature/2026-11-09-sdk-prompt-time-zone.zh.md @@ -29,7 +29,7 @@ Web 与 Desktop 的 prompt 携带浏览器时区,Host 规范化后把它记录 ## 影响 -- 不传时区的 SDK 嵌入方现在上报运行时进程时区。容器中通常是 `UTC`,可能与用户时区不同;[升级指南](../../../../docs/upgrade-guide/v0.2.2-rc.1/sdk-prompt-time-zone/guide.zh.md)要求使用方传入 `timeZone` 或 `time_zone`,或设置 `TZ`。 +- 不传时区的 SDK 嵌入方现在上报运行时进程时区。容器中通常是 `UTC`,可能与用户时区不同;[升级指南](../../../../docs/upgrade-guide/v0.2.2-rc.5/sdk-prompt-time-zone/guide.zh.md)要求使用方传入 `timeZone` 或 `time_zone`,或设置 `TZ`。 - SDK subagent 子运行时收到的 prompt 不带时区,因此上报自身进程时区;进程内子 agent 与 Web 上一样看到 `unavailable`。 - 早于放宽检查的读取方会忽略 SDK prompt 的时区;[持久化记录](../../../../docs/persistence-changes/2026-11-09-sdk-prompt-time-zone.zh.md)保持格式版本不变。 - `packages/sdk/server/tests/time-zone.spec.ts` 固定规范化、拒绝、采样与不可用时区,`session/query` 路由,以及 SDK 与原生命令路径上一致的 `/plan` 来源。`apps/cli/tests/profiles/sdk/keyless-smoke.e2e.ts` 通过随发行版交付的 `sdk` profile 断言模型可见的那一行。SDK snapshot 驱动发送 `timeZone: 'UTC'` 并在 `TZ=UTC` 下运行。 diff --git a/docs/upgrade-guide/v0.2.2-rc.1/sdk-prompt-time-zone/guide.i18n.yaml b/docs/upgrade-guide/v0.2.2-rc.5/sdk-prompt-time-zone/guide.i18n.yaml similarity index 87% rename from docs/upgrade-guide/v0.2.2-rc.1/sdk-prompt-time-zone/guide.i18n.yaml rename to docs/upgrade-guide/v0.2.2-rc.5/sdk-prompt-time-zone/guide.i18n.yaml index 5f8d3e4a06..fbf727afa4 100644 --- a/docs/upgrade-guide/v0.2.2-rc.1/sdk-prompt-time-zone/guide.i18n.yaml +++ b/docs/upgrade-guide/v0.2.2-rc.5/sdk-prompt-time-zone/guide.i18n.yaml @@ -1,13 +1,13 @@ # Bilingual-pair consistency record for guide.md (docs/i18n/README.md): per heading # section, a hash of its English and Chinese blocks outside code blocks and generated regions. # After editing either side, bring the other along and re-record with: -# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.2-rc.1/sdk-prompt-time-zone/guide.md +# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.2-rc.5/sdk-prompt-time-zone/guide.md /: en: a07259d8388d4cac zh: 2e52c1c30028a099 /sdk-prompts-report-the-process-time-zone-by-default: - en: 6e4beab2de07e795 - zh: cc8f67b4ce53dfd0 + en: a05ff032b245d2a9 + zh: 65a504c65b00ed4f /sdk-prompts-report-the-process-time-zone-by-default/change: en: 6f9aa3d02e634b47 zh: 9637bed97668d8d7 diff --git a/docs/upgrade-guide/v0.2.2-rc.1/sdk-prompt-time-zone/guide.md b/docs/upgrade-guide/v0.2.2-rc.5/sdk-prompt-time-zone/guide.md similarity index 100% rename from docs/upgrade-guide/v0.2.2-rc.1/sdk-prompt-time-zone/guide.md rename to docs/upgrade-guide/v0.2.2-rc.5/sdk-prompt-time-zone/guide.md diff --git a/docs/upgrade-guide/v0.2.2-rc.1/sdk-prompt-time-zone/guide.zh.md b/docs/upgrade-guide/v0.2.2-rc.5/sdk-prompt-time-zone/guide.zh.md similarity index 100% rename from docs/upgrade-guide/v0.2.2-rc.1/sdk-prompt-time-zone/guide.zh.md rename to docs/upgrade-guide/v0.2.2-rc.5/sdk-prompt-time-zone/guide.zh.md diff --git a/packages/util/time/README.i18n.yaml b/packages/util/time/README.i18n.yaml index ddb345191a..c1d4450640 100644 --- a/packages/util/time/README.i18n.yaml +++ b/packages/util/time/README.i18n.yaml @@ -18,11 +18,11 @@ en: bbff250eba0f1b89 zh: 0a618f05cc88ee2b /dsh-util-time/use-this-package/when-to-use-it: - en: 094e97351a65e8ea - zh: 519ff7be1121d9f4 + en: bab06d282fb17258 + zh: 98f58fa097250a4d /dsh-util-time/use-this-package/entry-point: - en: 7ca7ddebcb6af6be - zh: 4702a29079d6b8a7 + en: 00bca9104915bdc3 + zh: 670fc4533eae245b /dsh-util-time/understand-the-implementation: en: 402cdc78fc0f0dda zh: 3ddbee420e1a70a6 diff --git a/packages/util/time/README.md b/packages/util/time/README.md index 579e5fc055..0b292f89af 100644 --- a/packages/util/time/README.md +++ b/packages/util/time/README.md @@ -29,7 +29,7 @@ Shared time vocabulary for instant, zone, elapsed-time, and recurrence boundarie It is a **library, not a service or plugin**: no `ctx`, registers nothing, holds no state. -Call it at the boundary that receives the zone or the wall-clock selector, before the value reaches anything durable. `dsh-api-session-controller` and `dsh-subagent` admit a caller-reported zone through `canonicalClientTimeZone`; `dsh-time-context` admits the zone a request turn reports through `canonicalizeTimeZone` and refuses an alias rather than rewriting it; `dsh-schedule` reads absolute and wall-clock selectors through the strict parsers, resolves local targets through `resolveLocalInstant`, and uses the shared `Cron` / `RRule` recurrence values; `dsh-session-format-v0-to-v1` validates a stored schedule instant through `fourDigitYearEpoch` while keeping its own released-log error. `dsh-time-context` reads its elapsed reading through `Duration` and keeps the wording of the line it injects. Schedule retains its record types, relative intervals, daily/weekly policy, and delivery limits. The library works in Host and browser code without a Cordis service. +Call it at the boundary that receives the zone or the wall-clock selector, before the value reaches anything durable. `dsh-api-session-controller`, `dsh-subagent`, and `dsh-sdk-jsonrpc-server` admit a caller-reported zone through `canonicalClientTimeZone`; `dsh-time-context` admits the zone a request turn reports through `canonicalizeTimeZone` and refuses an alias rather than rewriting it; `dsh-schedule` reads absolute and wall-clock selectors through the strict parsers, resolves local targets through `resolveLocalInstant`, and uses the shared `Cron` / `RRule` recurrence values; `dsh-session-format-v0-to-v1` validates a stored schedule instant through `fourDigitYearEpoch` while keeping its own released-log error. `dsh-time-context` reads its elapsed reading through `Duration` and keeps the wording of the line it injects. Schedule retains its record types, relative intervals, daily/weekly policy, and delivery limits. The library works in Host and browser code without a Cordis service. ### Entry point @@ -48,7 +48,7 @@ if (local.kind === 'accepted') { Duration.fromMilliseconds(1_500).decompose() // { days: 0, hours: 0, minutes: 0, seconds: 1, milliseconds: 500 } ``` -`canonicalClientTimeZone` answers `undefined` for a name it refuses, and the caller raises its own refusal — `session/invalid-time-zone` for the Session prompt, `subagent/invalid-time-zone` for a subagent continuation. `canonicalizeTimeZone`, the strict parsers, and `fourDigitYearEpoch` instead report why they refused, as a discriminated result whose `rejected` arm carries a stable reason, so each caller chooses its own code and diagnostic. `formatFourDigitYearInstant` and `resolveLocalInstant` take already-validated values and answer a string, or epoch milliseconds, with `undefined` for an unrepresentable epoch or a wall-clock value inside a DST gap. `Duration` is a frozen value type over one millisecond count: it validates that the count is finite and inside the exactly representable range, and splits a non-negative span into whole parts. It publishes only the operations its consumers call; a member for another unit or for span arithmetic lands with the caller that needs it. +`canonicalClientTimeZone` answers `undefined` for a name it refuses, and the caller raises its own refusal — `session/invalid-time-zone` for the Session prompt, `subagent/invalid-time-zone` for a subagent continuation. The SDK server rejects an invalid explicit zone with a `TypeError` before creating a Session or routing a command. Its JSON-RPC transport returns error code `-32603`. `canonicalizeTimeZone`, the strict parsers, and `fourDigitYearEpoch` instead report why they refused, as a discriminated result whose `rejected` arm carries a stable reason, so each caller chooses its own code and diagnostic. `formatFourDigitYearInstant` and `resolveLocalInstant` take already-validated values and answer a string, or epoch milliseconds, with `undefined` for an unrepresentable epoch or a wall-clock value inside a DST gap. `Duration` is a frozen value type over one millisecond count: it validates that the count is finite and inside the exactly representable range, and splits a non-negative span into whole parts. It publishes only the operations its consumers call; a member for another unit or for span arithmetic lands with the caller that needs it. ----- diff --git a/packages/util/time/README.zh.md b/packages/util/time/README.zh.md index 9b6a6c30e6..e2acedd86b 100644 --- a/packages/util/time/README.zh.md +++ b/packages/util/time/README.zh.md @@ -29,7 +29,7 @@ kind: "package-library" 它是**库,不是服务也不是插件**:无 `ctx`、不注册任何东西、不持有状态。 -在接收时区或墙钟选择器的那个边界上调用它,让值在进入任何持久物之前先过一遍。`dsh-api-session-controller` 与 `dsh-subagent` 通过 `canonicalClientTimeZone` 接收调用方所报时区;`dsh-time-context` 通过 `canonicalizeTimeZone` 接收某一轮请求所报时区,并拒绝别名而不是把它改写;`dsh-schedule` 通过严格解析器读取绝对选择器与墙钟选择器,通过 `resolveLocalInstant` 解析本地目标,并使用共享的 `Cron` / `RRule` 重复规则值;`dsh-session-format-v0-to-v1` 通过 `fourDigitYearEpoch` 校验持久记录里的调度时刻,同时保留它自己的已发布日志错误。`dsh-time-context` 通过 `Duration` 读取其耗时读数,并保留它注入那一行的措辞。Schedule 保留记录类型、相对间隔、每日/每周策略和投递限制。库可用于宿主和浏览器代码,无需 Cordis 服务。 +在接收时区或墙钟选择器的那个边界上调用它,让值在进入任何持久物之前先过一遍。`dsh-api-session-controller`、`dsh-subagent` 和 `dsh-sdk-jsonrpc-server` 通过 `canonicalClientTimeZone` 接收调用方所报时区;`dsh-time-context` 通过 `canonicalizeTimeZone` 接收某一轮请求所报时区,并拒绝别名而不是把它改写;`dsh-schedule` 通过严格解析器读取绝对选择器与墙钟选择器,通过 `resolveLocalInstant` 解析本地目标,并使用共享的 `Cron` / `RRule` 重复规则值;`dsh-session-format-v0-to-v1` 通过 `fourDigitYearEpoch` 校验持久记录里的调度时刻,同时保留它自己的已发布日志错误。`dsh-time-context` 通过 `Duration` 读取其耗时读数,并保留它注入那一行的措辞。Schedule 保留记录类型、相对间隔、每日/每周策略和投递限制。库可用于宿主和浏览器代码,无需 Cordis 服务。 ### 入口 @@ -48,7 +48,7 @@ if (local.kind === 'accepted') { Duration.fromMilliseconds(1_500).decompose() // { days: 0, hours: 0, minutes: 0, seconds: 1, milliseconds: 500 } ``` -不可用的时区名称由 `canonicalClientTimeZone` 回答 `undefined`,由调用方抛出自己的拒绝——Session 提示词用 `session/invalid-time-zone`,subagent 续话用 `subagent/invalid-time-zone`。`canonicalizeTimeZone`、各严格解析器与 `fourDigitYearEpoch` 则会说明拒绝原因,以带判别值的结果回答,其 `rejected` 分支携带稳定的拒绝原因,由各调用方选择自己的错误码与诊断文案。`formatFourDigitYearInstant` 与 `resolveLocalInstant` 接收已校验的值,分别回答字符串与纪元毫秒,无法表示的纪元或落在 DST 缺口内的墙钟值回答 `undefined`。`Duration` 是一个基于单一毫秒计数的冻结值类型:它校验计数有限且落在可精确表示的范围内,并把非负的时间段拆成整数量。它只发布消费方会调用的部分;面向其它单位或时间段算术的成员都随第一个需要它的调用方落地。 +不可用的时区名称由 `canonicalClientTimeZone` 回答 `undefined`,由调用方抛出自己的拒绝——Session 提示词用 `session/invalid-time-zone`,subagent 续话用 `subagent/invalid-time-zone`。SDK 服务端在创建 Session 或分派命令前校验显式传入的时区,无效值会触发 `TypeError`,JSON-RPC 传输层返回错误码 `-32603`。`canonicalizeTimeZone`、各严格解析器与 `fourDigitYearEpoch` 则会说明拒绝原因,以带判别值的结果回答,其 `rejected` 分支携带稳定的拒绝原因,由各调用方选择自己的错误码与诊断文案。`formatFourDigitYearInstant` 与 `resolveLocalInstant` 接收已校验的值,分别回答字符串与纪元毫秒,无法表示的纪元或落在 DST 缺口内的墙钟值回答 `undefined`。`Duration` 是一个基于单一毫秒计数的冻结值类型:它校验计数有限且落在可精确表示的范围内,并把非负的时间段拆成整数量。它只发布消费方会调用的部分;面向其它单位或时间段算术的成员都随第一个需要它的调用方落地。 ----- diff --git a/scripts/smoke-python-runtime.py b/scripts/smoke-python-runtime.py index 1abc9246f3..4520eea2f0 100644 --- a/scripts/smoke-python-runtime.py +++ b/scripts/smoke-python-runtime.py @@ -103,6 +103,7 @@ LEGACY_CUSTOM_DISABLED_ROWS = ( "tool-todo", "tool-web", ) +SNAPSHOT_TIME_ZONE = "UTC" SNAPSHOT_PROMPT = "Run the advanced packaged-runtime snapshot scenario." SNAPSHOT_SESSION_ID = "advanced-executable" SNAPSHOT_DIRECT_CHILD_PROMPT = "Reply with exactly DIRECT_CHILD_OK and nothing else." @@ -898,8 +899,8 @@ def main() -> None: print("smoke-python-runtime: sdk-live passed") return - # SDK prompts without timeZone record the runtime process zone; pin it so snapshots match on every host. - os.environ["TZ"] = "UTC" + # Child processes that sample their own time zone inherit the snapshot zone. + os.environ["TZ"] = SNAPSHOT_TIME_ZONE with MockModel() as model: if args.scenario == "sdk-plugin-manager": assert args.exe is not None @@ -993,7 +994,7 @@ def _smoke_sdk_authoring_cached(base_url: str, executable: Path, update_snapshot env={"DSH_PERMISSION_MODE": "danger-full-access", "DSH_TELEMETRY_DISABLED": "1", "DSH_RESOURCE_CACHE": str(cache)}, request_timeout_seconds=60, ) as harness: - result = harness.run(AUTHORING_PROMPT, session_id="authoring") + result = harness.run(AUTHORING_PROMPT, session_id="authoring", time_zone=SNAPSHOT_TIME_ZONE) assert result.final_response == EXPECTED_TEXT, result.final_response requests = MockModelHandler.requests[first:] assert len(requests) == 2, requests @@ -1488,7 +1489,7 @@ def smoke_sdk_minimal( base_url=base_url, request_timeout_seconds=60, ) as harness: - result = harness.run(MINIMAL_PROMPT, session_id="minimal-agent-smoke") + result = harness.run(MINIMAL_PROMPT, session_id="minimal-agent-smoke", time_zone=SNAPSHOT_TIME_ZONE) event_text = json.dumps(result.events) if MINIMAL_TEXT not in event_text: @@ -1551,7 +1552,7 @@ def smoke_sdk_dynamic_tools(base_url: str, executable: Path, update_snapshots: b }, api_key="sk-keyless-smoke", base_url=base_url, request_timeout_seconds=60, ) as harness: - result = harness.run(DYNAMIC_TOOLS_PROMPT, session_id="dynamic-tools-smoke") + result = harness.run(DYNAMIC_TOOLS_PROMPT, session_id="dynamic-tools-smoke", time_zone=SNAPSHOT_TIME_ZONE) assert result.final_response == DYNAMIC_TOOLS_TEXT, result.final_response assert task.read_text(encoding="utf-8") == "Call snapshot_ping once.\n" logs = read_session_logs(sessions) @@ -1815,7 +1816,8 @@ def smoke_sdk_snapshot_mode( MockModelHandler.direct_child_finished.set() result = harness.run( - SNAPSHOT_PROMPT, session_id=SNAPSHOT_SESSION_ID, on_notification=observe_child, + SNAPSHOT_PROMPT, session_id=SNAPSHOT_SESSION_ID, time_zone=SNAPSHOT_TIME_ZONE, + on_notification=observe_child, ) assert result.final_response == SNAPSHOT_FINAL_TEXT, (result.final_response, harness.client._runtime_diagnostics()) @@ -1977,9 +1979,9 @@ def smoke_sdk_restart_snapshot(base_url: str, executable: Path, update_snapshots ) with connect() as harness: - first = harness.run(RESTART_FIRST_PROMPT, session_id=RESTART_FIRST_SESSION_ID) + first = harness.run(RESTART_FIRST_PROMPT, session_id=RESTART_FIRST_SESSION_ID, time_zone=SNAPSHOT_TIME_ZONE) with connect() as harness: - second = harness.run(RESTART_SECOND_PROMPT, session_id=RESTART_SECOND_SESSION_ID) + second = harness.run(RESTART_SECOND_PROMPT, session_id=RESTART_SECOND_SESSION_ID, time_zone=SNAPSHOT_TIME_ZONE) requests = MockModelHandler.requests[first_request:] if len(requests) != 2: raise AssertionError(f"restart snapshot expected two model requests: {requests}") @@ -2017,7 +2019,7 @@ def smoke_sdk_restart_snapshot(base_url: str, executable: Path, update_snapshots raise AssertionError(f"resume changed the saved identity: {session.id}") if len(MockModelHandler.requests) != first_request + 2: raise AssertionError("resume sent a model request before receiving new input") - resumed = session.run(RESUME_PROMPT) + resumed = session.run(RESUME_PROMPT, time_zone=SNAPSHOT_TIME_ZONE) requests = MockModelHandler.requests[first_request + 2:] if len(requests) != 1 or resumed.final_response != RESUME_TEXT: @@ -2118,8 +2120,8 @@ def smoke_sdk_scheduler_recovery(base_url: str, executable: Path, update_snapsho ) with connect() as harness: - failed = harness.run(RECOVERY_PROMPT, session_id=RECOVERY_SESSION_ID) - continued = harness.run(RECOVERY_CONTINUE_PROMPT, session_id=RECOVERY_SESSION_ID) + failed = harness.run(RECOVERY_PROMPT, session_id=RECOVERY_SESSION_ID, time_zone=SNAPSHOT_TIME_ZONE) + continued = harness.run(RECOVERY_CONTINUE_PROMPT, session_id=RECOVERY_SESSION_ID, time_zone=SNAPSHOT_TIME_ZONE) results = [failed, continued] if [result.finish_reason for result in results] != ["error", "completed"]: outcomes = [