refactor: 重构项目结构,将 tracer 模块提取为独立子包

- 将 tracer 相关代码移动到 tracers.ts 子目录中
- 新增类型定义文件,统一管理命令类型
- 实现上下文管理机制,集中处理 tracer 命令
- 更新构建配置和依赖管理
- 移除旧的根目录文件,保持代码结构清晰
This commit is contained in:
2026-02-04 13:45:17 +08:00
parent c90f4a0244
commit a3bbd5638a
21 changed files with 468 additions and 53 deletions

View File

@@ -0,0 +1,57 @@
import type { BaseTracerCommand, JsonValue } from './common';
type BaseArrayTracerCommand = BaseTracerCommand & {
type: 'ArrayTracer';
};
type ArrayTracerCreateCommand = BaseArrayTracerCommand & {
action: 'create';
params: {
description: string;
array?: JsonValue[];
};
};
type ArrayTracerScaleCommand = BaseArrayTracerCommand & {
action: 'scale';
params: {
size: number;
};
};
type ArrayTracerPickCommand = BaseArrayTracerCommand & {
action: 'pick';
params: {
index: number;
};
};
type ArrayTracerDropCommand = BaseArrayTracerCommand & {
action: 'drop';
params: {
index: number;
};
};
type ArrayTracerPatchCommand = BaseArrayTracerCommand & {
action: 'patch';
params: {
index: number;
value: JsonValue;
};
};
type ArrayTracerUnsetCommand = BaseArrayTracerCommand & {
action: 'unset';
params: {
index: number;
};
};
export type ArrayTracerCommand =
| ArrayTracerCreateCommand
| ArrayTracerScaleCommand
| ArrayTracerPickCommand
| ArrayTracerDropCommand
| ArrayTracerPatchCommand
| ArrayTracerUnsetCommand;

View File

@@ -0,0 +1,8 @@
import type { ArrayTracerCommand } from './array-tracer';
import type { ControlTracerCommand } from './control-tracer';
import type { LogTracerCommand } from './log-tracer';
export type TracerCommand =
| ArrayTracerCommand
| LogTracerCommand
| ControlTracerCommand;

View File

@@ -0,0 +1,16 @@
export type JsonValue =
| string
| number
| boolean
| null
| JsonValue[]
| { [key: string]: JsonValue };
export type TracerType = 'ArrayTracer' | 'LogTracer' | 'ControlTracer';
export type TracerId = ReturnType<typeof crypto.randomUUID>;
export type BaseTracerCommand = {
type: TracerType;
tracer: TracerId;
};

View File

@@ -0,0 +1,23 @@
import type { BaseTracerCommand } from './common';
type BaseControlTracerCommand = BaseTracerCommand & {
type: 'ControlTracer';
};
type ControlTracerCreateCommand = BaseControlTracerCommand & {
action: 'create';
params: {
description: string;
};
};
type ControlTracerStepCommand = BaseControlTracerCommand & {
action: 'step';
params: {
lines: number[];
};
};
export type ControlTracerCommand =
| ControlTracerCreateCommand
| ControlTracerStepCommand;

View File

@@ -0,0 +1,5 @@
export * from './array-tracer';
export * from './command';
export * from './common';
export * from './control-tracer';
export * from './log-tracer';

View File

@@ -0,0 +1,21 @@
import type { BaseTracerCommand } from "./common";
type BaseLogTracerCommand = BaseTracerCommand & {
type: 'LogTracer';
};
type LogTracerCreateCommand = BaseLogTracerCommand & {
action: 'create';
params: {
description: string;
};
};
type LogTracerLogCommand = BaseLogTracerCommand & {
action: 'log';
params: {
message: string;
};
};
export type LogTracerCommand = LogTracerCreateCommand | LogTracerLogCommand;