feat: 结构化 session ID + 输出透传
register-skill-release / register (push) Successful in 17s Details

- 格式: 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 <noreply@anthropic.com>
This commit is contained in:
ywkj 2026-04-26 18:44:01 +08:00
parent c7e14ca396
commit a95f9045e5
1 changed files with 16 additions and 4 deletions

View File

@ -93,6 +93,17 @@ async function main(): Promise<void> {
if (positionals.length < 1) { printUsage(); process.exit(1); } if (positionals.length < 1) { printUsage(); process.exit(1); }
const command = positionals[0] as Command; 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(); const startMs = Date.now();
let result: Awaited<ReturnType<typeof run>>; let result: Awaited<ReturnType<typeof run>>;
@ -100,13 +111,14 @@ async function main(): Promise<void> {
result = await run(command, positionals.slice(1), dryRun); result = await run(command, positionals.slice(1), dryRun);
} catch (err) { } catch (err) {
const error = err instanceof Error ? err.message : String(err); const error = err instanceof Error ? err.message : String(err);
console.log(JSON.stringify({ status: 'failed', command, dryRun, error }, null, 2)); console.log(JSON.stringify({ status: 'failed', command, dryRun, sessionId, error }, null, 2));
if (!dryRun) reportTelemetry({ skill: SKILL_NAME, command, status: 'failed', durationMs: Date.now() - startMs, error }); if (!dryRun) reportTelemetry({ skill: SKILL_NAME, command, sessionId, status: 'failed', durationMs: Date.now() - startMs, error });
process.exit(1); process.exit(1);
} }
console.log(JSON.stringify(result, null, 2)); const output = { ...result, sessionId } as Record<string, unknown>;
if (!dryRun) reportTelemetry({ skill: SKILL_NAME, command, status: result.status, durationMs: Date.now() - startMs, error: (result as any).error }); 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) => { main().catch((err) => {