mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 08:45:50 +00:00
更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121)
* style(B1-1): 格式化 ink/buddy/cli/context/screens/tasks/services/keybindings/state (43 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 修复了 Box.tsx 和 ScrollBox.tsx 中无效的 global.d.ts import。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-2): 格式化 commands (79 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-3): 格式化 components/messages,permissions,mcp,sandbox,shell (104 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-4): 格式化 components/PromptInput,FeedbackSurvey,tasks,agents,skills,design-system,wizard (73 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-5): 格式化 components其余 + hooks + tools (232 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-6): 格式化 main/entrypoints/utils/moreright (21 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: 更新 README,新增 Run.ps1/TODO.md,删除 V6.md - README.md: 大幅重写,更详细版本历史和配置示例 - Run.ps1: 新增 Windows 启动脚本 - TODO.md: 新增包完成清单 - V6.md: 删除(架构重构规划已不适用) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: 修复以前的问题 * fix: 修复 login 面板的问题 --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,219 +1,173 @@
|
||||
import { c as _c } from "react/compiler-runtime";
|
||||
import React, { createContext, useCallback, useContext, useEffect, useMemo } from 'react';
|
||||
import { saveCurrentProjectConfig } from '../utils/config.js';
|
||||
import React, {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
} from 'react'
|
||||
import { saveCurrentProjectConfig } from '../utils/config.js'
|
||||
|
||||
export type StatsStore = {
|
||||
increment(name: string, value?: number): void;
|
||||
set(name: string, value: number): void;
|
||||
observe(name: string, value: number): void;
|
||||
add(name: string, value: string): void;
|
||||
getAll(): Record<string, number>;
|
||||
};
|
||||
function percentile(sorted: number[], p: number): number {
|
||||
const index = p / 100 * (sorted.length - 1);
|
||||
const lower = Math.floor(index);
|
||||
const upper = Math.ceil(index);
|
||||
if (lower === upper) {
|
||||
return sorted[lower]!;
|
||||
}
|
||||
return sorted[lower]! + (sorted[upper]! - sorted[lower]!) * (index - lower);
|
||||
increment(name: string, value?: number): void
|
||||
set(name: string, value: number): void
|
||||
observe(name: string, value: number): void
|
||||
add(name: string, value: string): void
|
||||
getAll(): Record<string, number>
|
||||
}
|
||||
const RESERVOIR_SIZE = 1024;
|
||||
|
||||
function percentile(sorted: number[], p: number): number {
|
||||
const index = (p / 100) * (sorted.length - 1)
|
||||
const lower = Math.floor(index)
|
||||
const upper = Math.ceil(index)
|
||||
if (lower === upper) {
|
||||
return sorted[lower]!
|
||||
}
|
||||
return sorted[lower]! + (sorted[upper]! - sorted[lower]!) * (index - lower)
|
||||
}
|
||||
|
||||
const RESERVOIR_SIZE = 1024
|
||||
|
||||
type Histogram = {
|
||||
reservoir: number[];
|
||||
count: number;
|
||||
sum: number;
|
||||
min: number;
|
||||
max: number;
|
||||
};
|
||||
reservoir: number[]
|
||||
count: number
|
||||
sum: number
|
||||
min: number
|
||||
max: number
|
||||
}
|
||||
|
||||
export function createStatsStore(): StatsStore {
|
||||
const metrics = new Map<string, number>();
|
||||
const histograms = new Map<string, Histogram>();
|
||||
const sets = new Map<string, Set<string>>();
|
||||
const metrics = new Map<string, number>()
|
||||
const histograms = new Map<string, Histogram>()
|
||||
const sets = new Map<string, Set<string>>()
|
||||
|
||||
return {
|
||||
increment(name: string, value = 1) {
|
||||
metrics.set(name, (metrics.get(name) ?? 0) + value);
|
||||
metrics.set(name, (metrics.get(name) ?? 0) + value)
|
||||
},
|
||||
set(name: string, value: number) {
|
||||
metrics.set(name, value);
|
||||
metrics.set(name, value)
|
||||
},
|
||||
observe(name: string, value: number) {
|
||||
let h = histograms.get(name);
|
||||
let h = histograms.get(name)
|
||||
if (!h) {
|
||||
h = {
|
||||
reservoir: [],
|
||||
count: 0,
|
||||
sum: 0,
|
||||
min: value,
|
||||
max: value
|
||||
};
|
||||
histograms.set(name, h);
|
||||
h = { reservoir: [], count: 0, sum: 0, min: value, max: value }
|
||||
histograms.set(name, h)
|
||||
}
|
||||
h.count++;
|
||||
h.sum += value;
|
||||
h.count++
|
||||
h.sum += value
|
||||
if (value < h.min) {
|
||||
h.min = value;
|
||||
h.min = value
|
||||
}
|
||||
if (value > h.max) {
|
||||
h.max = value;
|
||||
h.max = value
|
||||
}
|
||||
// Reservoir sampling (Algorithm R)
|
||||
if (h.reservoir.length < RESERVOIR_SIZE) {
|
||||
h.reservoir.push(value);
|
||||
h.reservoir.push(value)
|
||||
} else {
|
||||
const j = Math.floor(Math.random() * h.count);
|
||||
const j = Math.floor(Math.random() * h.count)
|
||||
if (j < RESERVOIR_SIZE) {
|
||||
h.reservoir[j] = value;
|
||||
h.reservoir[j] = value
|
||||
}
|
||||
}
|
||||
},
|
||||
add(name: string, value: string) {
|
||||
let s = sets.get(name);
|
||||
let s = sets.get(name)
|
||||
if (!s) {
|
||||
s = new Set();
|
||||
sets.set(name, s);
|
||||
s = new Set()
|
||||
sets.set(name, s)
|
||||
}
|
||||
s.add(value);
|
||||
s.add(value)
|
||||
},
|
||||
getAll() {
|
||||
const result: Record<string, number> = Object.fromEntries(metrics);
|
||||
const result: Record<string, number> = Object.fromEntries(metrics)
|
||||
|
||||
for (const [name, h] of histograms) {
|
||||
if (h.count === 0) {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
result[`${name}_count`] = h.count;
|
||||
result[`${name}_min`] = h.min;
|
||||
result[`${name}_max`] = h.max;
|
||||
result[`${name}_avg`] = h.sum / h.count;
|
||||
const sorted = [...h.reservoir].sort((a, b) => a - b);
|
||||
result[`${name}_p50`] = percentile(sorted, 50);
|
||||
result[`${name}_p95`] = percentile(sorted, 95);
|
||||
result[`${name}_p99`] = percentile(sorted, 99);
|
||||
result[`${name}_count`] = h.count
|
||||
result[`${name}_min`] = h.min
|
||||
result[`${name}_max`] = h.max
|
||||
result[`${name}_avg`] = h.sum / h.count
|
||||
const sorted = [...h.reservoir].sort((a, b) => a - b)
|
||||
result[`${name}_p50`] = percentile(sorted, 50)
|
||||
result[`${name}_p95`] = percentile(sorted, 95)
|
||||
result[`${name}_p99`] = percentile(sorted, 99)
|
||||
}
|
||||
|
||||
for (const [name, s] of sets) {
|
||||
result[name] = s.size;
|
||||
result[name] = s.size
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
return result
|
||||
},
|
||||
}
|
||||
}
|
||||
export const StatsContext = createContext<StatsStore | null>(null);
|
||||
|
||||
export const StatsContext = createContext<StatsStore | null>(null)
|
||||
|
||||
type Props = {
|
||||
store?: StatsStore;
|
||||
children: React.ReactNode;
|
||||
};
|
||||
export function StatsProvider(t0) {
|
||||
const $ = _c(7);
|
||||
const {
|
||||
store: externalStore,
|
||||
children
|
||||
} = t0;
|
||||
let t1;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t1 = createStatsStore();
|
||||
$[0] = t1;
|
||||
} else {
|
||||
t1 = $[0];
|
||||
}
|
||||
const internalStore = t1;
|
||||
const store = externalStore ?? internalStore;
|
||||
let t2;
|
||||
let t3;
|
||||
if ($[1] !== store) {
|
||||
t2 = () => {
|
||||
const flush = () => {
|
||||
const metrics = store.getAll();
|
||||
if (Object.keys(metrics).length > 0) {
|
||||
saveCurrentProjectConfig(current => ({
|
||||
...current,
|
||||
lastSessionMetrics: metrics
|
||||
}));
|
||||
}
|
||||
};
|
||||
process.on("exit", flush);
|
||||
return () => {
|
||||
process.off("exit", flush);
|
||||
};
|
||||
};
|
||||
t3 = [store];
|
||||
$[1] = store;
|
||||
$[2] = t2;
|
||||
$[3] = t3;
|
||||
} else {
|
||||
t2 = $[2];
|
||||
t3 = $[3];
|
||||
}
|
||||
useEffect(t2, t3);
|
||||
let t4;
|
||||
if ($[4] !== children || $[5] !== store) {
|
||||
t4 = <StatsContext.Provider value={store}>{children}</StatsContext.Provider>;
|
||||
$[4] = children;
|
||||
$[5] = store;
|
||||
$[6] = t4;
|
||||
} else {
|
||||
t4 = $[6];
|
||||
}
|
||||
return t4;
|
||||
store?: StatsStore
|
||||
children: React.ReactNode
|
||||
}
|
||||
export function useStats() {
|
||||
const store = useContext(StatsContext);
|
||||
|
||||
export function StatsProvider({
|
||||
store: externalStore,
|
||||
children,
|
||||
}: Props): React.ReactNode {
|
||||
const internalStore = useMemo(() => createStatsStore(), [])
|
||||
const store = externalStore ?? internalStore
|
||||
|
||||
useEffect(() => {
|
||||
const flush = () => {
|
||||
const metrics = store.getAll()
|
||||
if (Object.keys(metrics).length > 0) {
|
||||
saveCurrentProjectConfig(current => ({
|
||||
...current,
|
||||
lastSessionMetrics: metrics,
|
||||
}))
|
||||
}
|
||||
}
|
||||
process.on('exit', flush)
|
||||
return () => {
|
||||
process.off('exit', flush)
|
||||
}
|
||||
}, [store])
|
||||
|
||||
return <StatsContext.Provider value={store}>{children}</StatsContext.Provider>
|
||||
}
|
||||
|
||||
export function useStats(): StatsStore {
|
||||
const store = useContext(StatsContext)
|
||||
if (!store) {
|
||||
throw new Error("useStats must be used within a StatsProvider");
|
||||
throw new Error('useStats must be used within a StatsProvider')
|
||||
}
|
||||
return store;
|
||||
return store
|
||||
}
|
||||
export function useCounter(name) {
|
||||
const $ = _c(3);
|
||||
const store = useStats();
|
||||
let t0;
|
||||
if ($[0] !== name || $[1] !== store) {
|
||||
t0 = value => store.increment(name, value);
|
||||
$[0] = name;
|
||||
$[1] = store;
|
||||
$[2] = t0;
|
||||
} else {
|
||||
t0 = $[2];
|
||||
}
|
||||
return t0;
|
||||
|
||||
export function useCounter(name: string): (value?: number) => void {
|
||||
const store = useStats()
|
||||
return useCallback(
|
||||
(value?: number) => store.increment(name, value),
|
||||
[store, name],
|
||||
)
|
||||
}
|
||||
export function useGauge(name) {
|
||||
const $ = _c(3);
|
||||
const store = useStats();
|
||||
let t0;
|
||||
if ($[0] !== name || $[1] !== store) {
|
||||
t0 = value => store.set(name, value);
|
||||
$[0] = name;
|
||||
$[1] = store;
|
||||
$[2] = t0;
|
||||
} else {
|
||||
t0 = $[2];
|
||||
}
|
||||
return t0;
|
||||
|
||||
export function useGauge(name: string): (value: number) => void {
|
||||
const store = useStats()
|
||||
return useCallback((value: number) => store.set(name, value), [store, name])
|
||||
}
|
||||
export function useTimer(name) {
|
||||
const $ = _c(3);
|
||||
const store = useStats();
|
||||
let t0;
|
||||
if ($[0] !== name || $[1] !== store) {
|
||||
t0 = value => store.observe(name, value);
|
||||
$[0] = name;
|
||||
$[1] = store;
|
||||
$[2] = t0;
|
||||
} else {
|
||||
t0 = $[2];
|
||||
}
|
||||
return t0;
|
||||
|
||||
export function useTimer(name: string): (value: number) => void {
|
||||
const store = useStats()
|
||||
return useCallback(
|
||||
(value: number) => store.observe(name, value),
|
||||
[store, name],
|
||||
)
|
||||
}
|
||||
export function useSet(name) {
|
||||
const $ = _c(3);
|
||||
const store = useStats();
|
||||
let t0;
|
||||
if ($[0] !== name || $[1] !== store) {
|
||||
t0 = value => store.add(name, value);
|
||||
$[0] = name;
|
||||
$[1] = store;
|
||||
$[2] = t0;
|
||||
} else {
|
||||
t0 = $[2];
|
||||
}
|
||||
return t0;
|
||||
|
||||
export function useSet(name: string): (value: string) => void {
|
||||
const store = useStats()
|
||||
return useCallback((value: string) => store.add(name, value), [store, name])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user