From a95f9045e58c8313e25ae20b7187de29f4982d8e Mon Sep 17 00:00:00 2001 From: ywkj Date: Sun, 26 Apr 2026 18:44:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=93=E6=9E=84=E5=8C=96=20session?= =?UTF-8?q?=20ID=20+=20=E8=BE=93=E5=87=BA=E9=80=8F=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 格式: vps-YYYYMMDD-HHMMSS-xxxx (vps = video-product-snapshot) - 优先级: --session-id CLI > SKILL_SESSION_ID env > 自动生成 - sessionId 写入 stdout JSON,telemetry 同步上报 Co-Authored-By: Claude Opus 4.7 --- scripts/run.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/run.ts b/scripts/run.ts index f1572fc..45e5bf2 100644 --- a/scripts/run.ts +++ b/scripts/run.ts @@ -93,6 +93,17 @@ async function main(): Promise { if (positionals.length < 1) { printUsage(); process.exit(1); } const command = positionals[0] as Command; + + // Resolve session ID: explicit CLI arg > env > auto-generate structured ID + const sessionId = process.env.SKILL_SESSION_ID || (() => { + const ts = new Date(); + const pad = (n: number) => String(n).padStart(2, '0'); + const tsPart = `${ts.getFullYear()}${pad(ts.getMonth()+1)}${pad(ts.getDate())}-${pad(ts.getHours())}${pad(ts.getMinutes())}${pad(ts.getSeconds())}`; + const rand = Math.random().toString(36).slice(2, 6); + return `vps-${tsPart}-${rand}`; + })(); + process.env.SKILL_SESSION_ID = sessionId; + const startMs = Date.now(); let result: Awaited>; @@ -100,13 +111,14 @@ async function main(): Promise { result = await run(command, positionals.slice(1), dryRun); } catch (err) { const error = err instanceof Error ? err.message : String(err); - console.log(JSON.stringify({ status: 'failed', command, dryRun, error }, null, 2)); - if (!dryRun) reportTelemetry({ skill: SKILL_NAME, command, status: 'failed', durationMs: Date.now() - startMs, error }); + console.log(JSON.stringify({ status: 'failed', command, dryRun, sessionId, error }, null, 2)); + if (!dryRun) reportTelemetry({ skill: SKILL_NAME, command, sessionId, status: 'failed', durationMs: Date.now() - startMs, error }); process.exit(1); } - console.log(JSON.stringify(result, null, 2)); - if (!dryRun) reportTelemetry({ skill: SKILL_NAME, command, status: result.status, durationMs: Date.now() - startMs, error: (result as any).error }); + const output = { ...result, sessionId } as Record; + console.log(JSON.stringify(output, null, 2)); + if (!dryRun) reportTelemetry({ skill: SKILL_NAME, command, sessionId, status: result.status, durationMs: Date.now() - startMs, error: (result as any).error }); } main().catch((err) => {