diff --git a/src/cli/commands/approval-runs.ts b/src/cli/commands/approval-runs.ts index 597a288..952e1ce 100644 --- a/src/cli/commands/approval-runs.ts +++ b/src/cli/commands/approval-runs.ts @@ -187,7 +187,7 @@ export async function handleApprovalRunsCommand( } if (action === "get") { - const recordId = args.command[2]; + const recordId = args.command[2] ?? stringOption(args.options["record-id"]) ?? stringOption(args.options.id); if (!recordId) throw new Error("Missing approval run recordId"); const rawJson = booleanOption(args.options["raw-json"]) ?? booleanOption(args.options.rawJson); if (rawJson) { @@ -226,21 +226,21 @@ export async function handleApprovalRunsCommand( } if (action === "cited-rules") { - const recordId = args.command[2]; + const recordId = args.command[2] ?? stringOption(args.options["record-id"]) ?? stringOption(args.options.id); if (!recordId) throw usageError("Usage: seal-use approval-runs cited-rules "); await runCapability("sealApprovalRunCitedRulesGet", client, corp, { recordId }, outputOptions(args.options)); return; } if (action === "document-summary") { - const recordId = args.command[2]; + const recordId = args.command[2] ?? stringOption(args.options["record-id"]) ?? stringOption(args.options.id); if (!recordId) throw usageError("Usage: seal-use approval-runs document-summary "); await runCapability("sealApprovalRunDocumentSummaryGet", client, corp, { recordId }, outputOptions(args.options)); return; } if (action === "diagnose") { - const recordId = args.command[2]; + const recordId = args.command[2] ?? stringOption(args.options["record-id"]) ?? stringOption(args.options.id); const sn = stringOption(args.options.sn) ?? stringOption(args.options["document-sn"]); if (!recordId && !sn) { throw usageError("Usage: seal-use approval-runs diagnose |--sn [--full] [--corp ]"); diff --git a/src/cli/commands/langfuse.ts b/src/cli/commands/langfuse.ts index 1932d5e..77e184e 100644 --- a/src/cli/commands/langfuse.ts +++ b/src/cli/commands/langfuse.ts @@ -20,7 +20,12 @@ export async function handleLangfuseCommand( const options = args.options; const out = outputOptions(options); const traceId = () => maybeName ?? stringOption(options["trace-id"]); - const refreshIfMissing = () => booleanOption(options["refresh-if-missing"]); + const refreshIfMissing = () => { + if (booleanOption(options["no-refresh"]) || booleanOption(options.offline)) return false; + const explicit = booleanOption(options["refresh-if-missing"]); + if (explicit !== undefined) return explicit; + return true; + }; if (action === "check") { await runLangfuseCapability("sealLangfuseConnectionCheck", {}, out); diff --git a/src/domains/langfuse/config.ts b/src/domains/langfuse/config.ts index 0864013..193a3bb 100644 --- a/src/domains/langfuse/config.ts +++ b/src/domains/langfuse/config.ts @@ -1,3 +1,5 @@ +import { existsSync, readFileSync } from "node:fs"; +import { resolve } from "node:path"; import { CliError } from "../../core/errors.js"; /** @@ -9,8 +11,8 @@ import { CliError } from "../../core/errors.js"; * embeds them into release binaries. End users therefore need zero setup. * * Precedence: injected build vars → plain `LANGFUSE_*` shell vars (development - * convenience when running from source) → nothing. Reading user config files is - * deliberately absent: this domain must work without any local configuration. + * convenience when running from source) → gitignored local `.env.langfuse` → nothing. + * Reading user config files is deliberately absent: this domain must work without any local configuration. */ export type LangfuseConfig = { baseUrl: string; @@ -31,6 +33,29 @@ function normalizeBaseUrl(baseUrl: string): string { return baseUrl.replace(/\/+$/, ""); } +function tryReadEnvLangfuse(): Record { + if (process.env.NODE_ENV === "test") return {}; + try { + const envPath = resolve(process.cwd(), ".env.langfuse"); + if (!existsSync(envPath)) return {}; + const content = readFileSync(envPath, "utf8"); + const result: Record = {}; + for (const line of content.split("\n")) { + const trimmed = line.trim(); + if (!trimmed || trimmed.startsWith("#")) continue; + const idx = trimmed.indexOf("="); + if (idx !== -1) { + const key = trimmed.slice(0, idx).trim(); + const val = trimmed.slice(idx + 1).trim().replace(/^["']|["']$/g, ""); + result[key] = val; + } + } + return result; + } catch { + return {}; + } +} + export function hasLangfuseCredentials(): boolean { const { baseUrl, publicKey, secretKey } = readLangfuseCredentials(); return Boolean(baseUrl && publicKey && secretKey); @@ -43,18 +68,12 @@ function readLangfuseCredentials(): { secretKey?: string; projectId?: string; } { - // Literal `process.env.X` accesses on purpose: `bun build --env=SEAL_BUILD_*` - // inlines static property reads at compile time, while a computed key - // (`process.env["SEAL_BUILD_" + name]`) stays a runtime lookup and comes back - // empty from a release binary. Reads happen per call so tests and dev shells - // can change the environment between invocations. The `LANGFUSE_*` fallbacks - // are deliberately outside the SEAL_BUILD_ prefix: they are never inlined and - // remain live shell-env vars for development runs from source. + const envFile = tryReadEnvLangfuse(); return { - baseUrl: pick(process.env.SEAL_BUILD_LANGFUSE_BASE_URL, process.env.LANGFUSE_BASE_URL), - publicKey: pick(process.env.SEAL_BUILD_LANGFUSE_PUBLIC_KEY, process.env.LANGFUSE_PUBLIC_KEY), - secretKey: pick(process.env.SEAL_BUILD_LANGFUSE_SECRET_KEY, process.env.LANGFUSE_SECRET_KEY), - projectId: pick(process.env.SEAL_BUILD_LANGFUSE_PROJECT_ID, process.env.LANGFUSE_PROJECT_ID) + baseUrl: pick(process.env.SEAL_BUILD_LANGFUSE_BASE_URL, process.env.LANGFUSE_BASE_URL, envFile.LANGFUSE_BASE_URL), + publicKey: pick(process.env.SEAL_BUILD_LANGFUSE_PUBLIC_KEY, process.env.LANGFUSE_PUBLIC_KEY, envFile.LANGFUSE_PUBLIC_KEY), + secretKey: pick(process.env.SEAL_BUILD_LANGFUSE_SECRET_KEY, process.env.LANGFUSE_SECRET_KEY, envFile.LANGFUSE_SECRET_KEY), + projectId: pick(process.env.SEAL_BUILD_LANGFUSE_PROJECT_ID, process.env.LANGFUSE_PROJECT_ID, envFile.LANGFUSE_PROJECT_ID) }; } diff --git a/src/domains/seal/capabilities/approval-runs.ts b/src/domains/seal/capabilities/approval-runs.ts index 465b0b1..7d8a303 100644 --- a/src/domains/seal/capabilities/approval-runs.ts +++ b/src/domains/seal/capabilities/approval-runs.ts @@ -787,6 +787,12 @@ export const approvalRunsCapabilities = [ hoseDocument: `seal-use approval-runs url ${detail.id} --type hose-document --corp ${context.corp.id}`, diagnoseConflict: invoiceConflicts[0]?.nextCommand, traceInvoice: invoiceConflicts[0] ? `seal-use invoices trace ${invoiceConflicts[0].invoiceNumber} --corp ${context.corp.id}` : undefined, + traceSearch: detail.sourceExtendData?._langfuseTraceId + ? `seal-use langfuse search ${detail.sourceExtendData._langfuseTraceId} --query <关键词>` + : undefined, + traceOutline: detail.sourceExtendData?._langfuseTraceId + ? `seal-use langfuse outline ${detail.sourceExtendData._langfuseTraceId} --include-io-preview` + : undefined, replay: `seal-use approval-runs replay ${detail.id} --dry-run --corp ${context.corp.id}` } }; diff --git a/src/domains/seal/capabilities/helpers.ts b/src/domains/seal/capabilities/helpers.ts index 7711a89..d0509e8 100644 --- a/src/domains/seal/capabilities/helpers.ts +++ b/src/domains/seal/capabilities/helpers.ts @@ -598,7 +598,7 @@ export function summarizeApprovalRunDetail(record: ApprovalRun) { export function summarizeApprovalRunResult(record: ApprovalRun) { const result = asRecord(record.result); return { - ...summarizeExtraFindings(record), + ...summarizeExtraFindings(record, true), recordId: record.id, sourceDocumentSN: record.sourceDocumentSN, sourceDocumentId: record.sourceDocumentId,