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) => {