Merge remote-tracking branch 'origin/feat/server-refactor' into fix/serve-command-real-impl

This commit is contained in:
DoSun 2026-05-14 17:07:50 +08:00
commit 481e6fc3c9
3 changed files with 14 additions and 4 deletions

View File

@ -1,6 +1,6 @@
/** /**
* CoStrict * CoStrict
* ~/.claude/csc-auth.json * ~/.costrict/share/auth.json
*/ */
import { promises as fs } from 'node:fs' import { promises as fs } from 'node:fs'
@ -62,7 +62,7 @@ export async function loadCoStrictCredentials(): Promise<CoStrictCredentials | n
} }
/** /**
* CoStrict ~/.claude/csc-auth.json * CoStrict ~/.costrict/share/auth.json
*/ */
export async function saveCoStrictCredentials( export async function saveCoStrictCredentials(
credentials: CoStrictCredentials, credentials: CoStrictCredentials,

View File

@ -1,3 +1,5 @@
import { basename } from 'path'
export const INIT_TIMEOUT_MS = (() => { export const INIT_TIMEOUT_MS = (() => {
const raw = Number(process.env.CSC_SERVE_INIT_TIMEOUT_MS) const raw = Number(process.env.CSC_SERVE_INIT_TIMEOUT_MS)
return Number.isFinite(raw) && raw > 0 ? raw : 120000 return Number.isFinite(raw) && raw > 0 ? raw : 120000
@ -6,10 +8,18 @@ export const INIT_TIMEOUT_MS = (() => {
export function getScriptArgsForChild(): string[] { export function getScriptArgsForChild(): string[] {
const argv1 = process.argv[1] const argv1 = process.argv[1]
if (!argv1) return [] if (!argv1) return []
// If the executable is not bun/node, we're in a compiled standalone binary.
// In compiled mode, argv[1] may be the original entrypoint path (e.g.
// "src/entrypoints/cli.tsx") which looks like a script — prevent that.
const execBase = basename(process.execPath)
if (!/^(bun|node)/i.test(execBase)) return []
// Bun standalone executable embeds a virtual snapshot path like "B:/~BUN/root/cli.js". // Bun standalone executable embeds a virtual snapshot path like "B:/~BUN/root/cli.js".
// This is not a real file on disk — skip it so the child process (the same exe) // This is not a real file on disk — skip it so the child process (the same exe)
// is not launched with a bogus script argument. // is not launched with a bogus script argument.
if (argv1.startsWith('B:/~BUN/') || argv1.startsWith('/snapshot/')) return [] if (argv1.startsWith('B:/~BUN/') || argv1.startsWith('/snapshot/')) return []
// When running as a compiled standalone binary (./csc), argv[1] is the binary
// itself — same as execPath. Do not treat it as a script file.
if (argv1 === process.execPath) return []
if (argv1.endsWith('.ts') || argv1.endsWith('.tsx') || argv1.includes('/') || argv1.includes('\\')) { if (argv1.endsWith('.ts') || argv1.endsWith('.tsx') || argv1.includes('/') || argv1.includes('\\')) {
return [argv1] return [argv1]
} }

View File

@ -406,7 +406,7 @@ export CSC_RAW_DUMP_LOCAL_DIR=/tmp/raw-dump-debug
| 运行时 | Effect-TS | Bun + 纯 Node.js API | | 运行时 | Effect-TS | Bun + 纯 Node.js API |
| 上报模式 | 单条即时上报 | 队列 + batch worker 顺序消费 | | 上报模式 | 单条即时上报 | 队列 + batch worker 顺序消费 |
| 限流防护 | 无 | 队列 + 单 worker + 重试 + 批次延迟 + 抖动 | | 限流防护 | 无 | 队列 + 单 worker + 重试 + 批次延迟 + 抖动 |
| 凭证路径 | `~/.costrict/credentials.json` | `~/.claude/csc-auth.json` | | 凭证路径 | `~/.costrict/credentials.json` | `~/.costrict/share/auth.json` |
--- ---