From a6b4f99a836c6a3fda0b5601e93a5486cac83af3 Mon Sep 17 00:00:00 2001 From: ywkj Date: Sun, 26 Apr 2026 19:01:10 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20session=20ID=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E7=94=B1=20auth-cli.ts=20=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - scripts/run.ts: 移除重复的 session ID 自动生成逻辑 - src/auth-cli.ts: 同步自 auth-runtime(模块级 SKILL_SESSION_ID) Co-Authored-By: Claude Opus 4.7 --- scripts/run.ts | 12 +----------- src/auth-cli.ts | 33 ++++++++++++--------------------- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/scripts/run.ts b/scripts/run.ts index 45e5bf2..03b2f04 100644 --- a/scripts/run.ts +++ b/scripts/run.ts @@ -93,17 +93,7 @@ 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 sessionId = process.env.SKILL_SESSION_ID!; // set by auth-cli.ts at module load const startMs = Date.now(); let result: Awaited>; diff --git a/src/auth-cli.ts b/src/auth-cli.ts index 07fdd09..e20a343 100644 --- a/src/auth-cli.ts +++ b/src/auth-cli.ts @@ -20,6 +20,18 @@ import * as path from 'path'; import * as os from 'os'; const home = process.env.HOME || os.homedir(); + +// ── session ID (Langfuse tracing) ── +// Priority: SKILL_SESSION_ID env > auto-generate +const SESSION_ID = 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 `skill-${tsPart}-${rand}`; +})(); +process.env.SKILL_SESSION_ID = SESSION_ID; + const AUTH_RT_BIN = process.env.AUTH_RT_BIN || (() => { // Check if auth-rt is in PATH @@ -43,20 +55,6 @@ export interface SessionResponse { hookToken?: string; } -export interface ClientConfig { - clientId: string; - name: string; - status: string; - metadata: { - provider?: { - api_key?: string; - base_url?: string; - model?: string; - }; - [key: string]: unknown; - }; -} - export interface SkillClientOptions { apiBase?: string; dryRun?: boolean; @@ -93,13 +91,6 @@ export class SkillClient { return JSON.parse(runCli('session')); } - async clientConfig(): Promise { - if (this.dryRun) { - return { clientId: '', name: '', status: 'active', metadata: {} }; - } - return JSON.parse(runCli('client-config')); - } - async get(urlPath: string): Promise { return this.request('GET', urlPath); }