From d77c0505d8f8078a804c1177200a86bf7c590e7e Mon Sep 17 00:00:00 2001 From: yunyingk Date: Fri, 23 Oct 2026 17:01:21 +0800 Subject: [PATCH] Refine simulation batch timestamps and update source messaging --- skills/seal-use/references/cli.md | 1 + src/cli/commands/update.ts | 34 ++++++++++++++++--- .../seal/capabilities/simulation.test.ts | 9 +++++ src/domains/seal/capabilities/simulation.ts | 23 ++++++++++++- src/domains/seal/simulation/batch-search.ts | 11 ++++-- 5 files changed, 69 insertions(+), 9 deletions(-) diff --git a/skills/seal-use/references/cli.md b/skills/seal-use/references/cli.md index 276c58a..10d656c 100644 --- a/skills/seal-use/references/cli.md +++ b/skills/seal-use/references/cli.md @@ -529,6 +529,7 @@ seal-use simulation search "任务 fe1993e4" --since 7d --all --corp ``` > **本地聚合,不是云端原生检索**:`/api/v1/simulation/batches` 只有 `limit`/`offset`,没有名称或关键词检索,批次对象也没有 `name` 字段(界面的「任务 fe1993e4」是 UUID 末 8 位)。`list --query/--since/--until` 与 `search` 都是 CLI 先把批次拉到本地再过滤,返回体固定带 `retrieval: { mode: "local_scan", serverSideSearch: false, scanned }`;命中范围以 `scanned` 为准,不覆盖未扫描的批次(`truncated: true` 时用 `--all` 或调大 `--max-scan`)。不要把它当作服务端能力向用户描述。 +> 每个批次返回 `id`、`status`、`approvalCode`、`sourceSystem`、`totalCount/processedCount/successCount/failedCount`、`requestSummary`、`resultSummary`、`createdAt`/`updatedAt`(北京时间秒级,如 `2026-10-10T14:38:17+08:00`)、`createdAtMs`(精确毫秒)、`flowIds`/`packageIds`/`packageLabel`/`templateId`,可据此直接核对界面任务与取数时间窗。 ## Failure Handling diff --git a/src/cli/commands/update.ts b/src/cli/commands/update.ts index 26d2036..b8151c5 100644 --- a/src/cli/commands/update.ts +++ b/src/cli/commands/update.ts @@ -160,18 +160,32 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp // `.old.` backup (undeletable while its image was executing). pruneUpdateLeftovers(process.execPath); - const releases = await fetchGitHubReleases(repo, 30); + const { releases, source } = await fetchReleasesWithSource(repo, 30); const release = targetVersion ? (releases.find((r) => r.version === targetVersion || r.tagName === targetVersion || r.tagName === `v${targetVersion}`) ?? await fetchGitHubRelease(repo, targetVersion)) : (releases[0] ?? await fetchGitHubRelease(repo)); if (!release) { + const mirrorMode = getMirrorMode(); + const newest = releases[0]?.version; + const wanted = targetVersion ? `v${targetVersion.replace(/^v/, "")}` : "最新版本"; + const sourcesTried = mirrorMode === "auto" + ? ["Gitea 国内镜像", "GitHub"] + : mirrorMode === "gitea" ? ["Gitea 国内镜像"] : ["GitHub"]; + const message = targetVersion && newest + ? `${source === "gitea" ? "国内镜像(Gitea)" : "GitHub"} 尚未提供 ${wanted}(该源当前最新 v${newest})。已尝试的更新源:${sourcesTried.join("、")};镜像同步存在时间差,请稍后重试。` + : `无法访问更新源(已尝试:${sourcesTried.join("、")})。请检查网络后重试。`; + printJson({ updated: false, currentVersion: VERSION, mode: "binary", - message: `Failed to query releases from repository '${repo}'` + mirrorMode, + sourcesTried, + releaseSource: source, + sourceLatestVersion: newest ?? null, + message }); return; } @@ -445,7 +459,10 @@ export function getMirrorMode(): "auto" | "github" | "gitea" { return "auto"; } -async function fetchGitHubReleases(repo: string, limit = 20): Promise { +async function fetchReleasesWithSource( + repo: string, + limit = 20 +): Promise<{ releases: GitHubRelease[]; source: "gitea" | "github" | null }> { const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN; const headers: Record = { "User-Agent": `seal-use/${VERSION}`, @@ -509,13 +526,20 @@ async function fetchGitHubReleases(repo: string, limit = 20): Promise 0) return list; + if (list.length > 0) { + return { releases: list, source: url.includes("git.ying-qing.cn") ? "gitea" : "github" }; + } } catch { // try next source } } - return []; + return { releases: [], source: null }; +} + +async function fetchGitHubReleases(repo: string, limit = 20): Promise { + const { releases } = await fetchReleasesWithSource(repo, limit); + return releases; } async function fetchGitHubRelease(repo: string, targetVersion?: string): Promise { diff --git a/src/domains/seal/capabilities/simulation.test.ts b/src/domains/seal/capabilities/simulation.test.ts index dcb4f42..98051f5 100644 --- a/src/domains/seal/capabilities/simulation.test.ts +++ b/src/domains/seal/capabilities/simulation.test.ts @@ -791,6 +791,15 @@ describe("simulation tool handlers", () => { } }); expect((result.batches as Array<{ id: string }>)[0]?.id).toBe(newer.id); + // 时间统一为北京时间秒级, 并附带 epoch 毫秒与单号标识, 便于核对界面任务 + expect((result.batches as Array>)[0]).toMatchObject({ + createdAt: "2026-10-10T14:38:17+08:00", + createdAtMs: Date.parse("2026-10-10T06:38:17.757Z"), + updatedAt: "2026-08-24T16:50:16+08:00", + flowIds: ["B26017701"], + packageIds: [], + templateId: null + }); }); test("list tool paginates when all=true is requested", async () => { diff --git a/src/domains/seal/capabilities/simulation.ts b/src/domains/seal/capabilities/simulation.ts index 155dd3b..ef7d9c0 100644 --- a/src/domains/seal/capabilities/simulation.ts +++ b/src/domains/seal/capabilities/simulation.ts @@ -10,6 +10,7 @@ import { import * as helpers from "./helpers.js"; import { parseDurationMs } from "../../../core/duration.js"; import { + batchTimestampMs, collectSimulationBatches, DEFAULT_SIMULATION_MAX_SCAN, DEFAULT_SIMULATION_SCAN_LIMIT, @@ -28,6 +29,26 @@ const { filterRuns } = helpers; +/** + * 列表/检索的统一展示: 时间统一成北京时间秒级(附 epoch 毫秒便于精确比较), + * 并带上单号/材料包标识, 让检索结果无需二次 get 就能对上界面里的任务。 + */ +function presentSimulationBatch(batch: SimulationBatch) { + const createdAtMs = batchTimestampMs(batch.createdAt); + const updatedAtMs = batchTimestampMs(batch.updatedAt); + + return { + ...summarizeSimulationBatch(batch), + createdAt: createdAtMs === null ? (batch.createdAt ?? null) : formatBeijingIso(createdAtMs), + createdAtMs, + updatedAt: updatedAtMs === null ? (batch.updatedAt ?? null) : formatBeijingIso(updatedAtMs), + flowIds: batch.params?.flowIds ?? [], + packageIds: batch.params?.packageIds ?? [], + packageLabel: batch.params?.packageLabel ?? null, + templateId: batch.params?.templateId ?? null + }; +} + export const simulationCapabilities = [ { name: "sealSimulationFeishuApprovalDefinitionsList", @@ -265,7 +286,7 @@ export const simulationCapabilities = [ until: untilMs === undefined ? null : formatBeijingIso(untilMs) }, count: matched.length, - batches: matched.map(summarizeSimulationBatch), + batches: matched.map(presentSimulationBatch), next: { getBatch: "seal-use simulation get ", getRecords: "seal-use simulation batch-records ", diff --git a/src/domains/seal/simulation/batch-search.ts b/src/domains/seal/simulation/batch-search.ts index e130a9d..9241f3e 100644 --- a/src/domains/seal/simulation/batch-search.ts +++ b/src/domains/seal/simulation/batch-search.ts @@ -89,12 +89,17 @@ function batchHaystack(batch: SimulationBatch): string { .join("\n"); } -function batchCreatedAtMs(batch: SimulationBatch): number | null { - if (batch.createdAt === undefined) return null; - const ms = typeof batch.createdAt === "number" ? batch.createdAt : Date.parse(batch.createdAt); +/** 批次时间戳既可能是 epoch 毫秒,也可能是上游原样返回的 ISO 字符串。 */ +export function batchTimestampMs(value: string | number | undefined): number | null { + if (value === undefined) return null; + const ms = typeof value === "number" ? value : Date.parse(value); return Number.isFinite(ms) ? ms : null; } +function batchCreatedAtMs(batch: SimulationBatch): number | null { + return batchTimestampMs(batch.createdAt); +} + export function filterSimulationBatches( batches: SimulationBatch[], filter: SimulationBatchFilter = {}