@code-inspector/core 1.4.1 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.iife.js +1 -1
- package/dist/client.umd.js +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +19955 -19917
- package/package.json +7 -2
- package/types/client/ai.d.ts +112 -0
- package/types/client/index.d.ts +62 -2
- package/types/server/ai-provider-claude.d.ts +19 -0
- package/types/server/ai.d.ts +48 -0
- package/types/server/server.d.ts +20 -3
- package/types/server/transform/transform-vue-pug.d.ts +29 -0
- package/types/shared/browser-chalk.d.ts +60 -0
- package/types/shared/type.d.ts +47 -1
- package/types/shared/utils.d.ts +120 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-inspector/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"@vue/compiler-dom": "^3.5.13",
|
|
42
42
|
"chalk": "^4.1.1",
|
|
43
43
|
"dotenv": "^16.1.4",
|
|
44
|
-
"launch-ide": "1.4.
|
|
44
|
+
"launch-ide": "1.4.2",
|
|
45
|
+
"marked": "^17.0.1",
|
|
45
46
|
"portfinder": "^1.0.28"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"@babel/plugin-proposal-decorators": "^7.22.7",
|
|
50
51
|
"@babel/plugin-syntax-import-meta": "^7.10.4",
|
|
51
52
|
"@babel/plugin-transform-typescript": "^7.21.3",
|
|
53
|
+
"@floating-ui/dom": "^1.7.5",
|
|
52
54
|
"@types/node": "^18.14.1",
|
|
53
55
|
"@vue/babel-plugin-jsx": "^1.1.1",
|
|
54
56
|
"@vue/compiler-sfc": "^3.3.4",
|
|
@@ -61,6 +63,9 @@
|
|
|
61
63
|
"vite-plugin-node-stdlib-browser": "^0.2.1",
|
|
62
64
|
"volar-service-pug": "^0.0.63"
|
|
63
65
|
},
|
|
66
|
+
"optionalDependencies": {
|
|
67
|
+
"@anthropic-ai/claude-agent-sdk": "^0.2.29"
|
|
68
|
+
},
|
|
64
69
|
"scripts": {
|
|
65
70
|
"dev": "vite",
|
|
66
71
|
"build:server": "vite build",
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI 模块 - 客户端 AI 聊天功能相关类型、模板和样式
|
|
3
|
+
*/
|
|
4
|
+
import { TemplateResult } from 'lit';
|
|
5
|
+
/**
|
|
6
|
+
* 设置项目根路径(用于将绝对路径转为相对路径)
|
|
7
|
+
*/
|
|
8
|
+
export declare function setProjectRoot(root: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* 工具调用信息
|
|
11
|
+
*/
|
|
12
|
+
export interface ToolCall {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
input?: Record<string, any>;
|
|
16
|
+
result?: string;
|
|
17
|
+
isError?: boolean;
|
|
18
|
+
isComplete?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 消息内容块
|
|
22
|
+
*/
|
|
23
|
+
export interface ContentBlock {
|
|
24
|
+
type: 'text' | 'tool';
|
|
25
|
+
content?: string;
|
|
26
|
+
tool?: ToolCall;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 聊天消息类型
|
|
30
|
+
*/
|
|
31
|
+
export interface ChatMessage {
|
|
32
|
+
role: 'user' | 'assistant';
|
|
33
|
+
content: string;
|
|
34
|
+
blocks?: ContentBlock[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 聊天上下文信息(当前选中的元素)
|
|
38
|
+
*/
|
|
39
|
+
export interface ChatContext {
|
|
40
|
+
file: string;
|
|
41
|
+
line: number;
|
|
42
|
+
column: number;
|
|
43
|
+
name: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 聊天状态接口
|
|
47
|
+
*/
|
|
48
|
+
export interface ChatState {
|
|
49
|
+
showChatModal: boolean;
|
|
50
|
+
chatMessages: ChatMessage[];
|
|
51
|
+
chatInput: string;
|
|
52
|
+
chatLoading: boolean;
|
|
53
|
+
chatContext: ChatContext | null;
|
|
54
|
+
currentTools: Map<string, ToolCall>;
|
|
55
|
+
chatTheme: 'light' | 'dark';
|
|
56
|
+
turnStatus: 'idle' | 'running' | 'done' | 'interrupt';
|
|
57
|
+
turnDuration: number;
|
|
58
|
+
isDragging: boolean;
|
|
59
|
+
chatModel: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 聊天功能处理器接口
|
|
63
|
+
*/
|
|
64
|
+
export interface ChatHandlers {
|
|
65
|
+
closeChatModal: () => void;
|
|
66
|
+
clearChatMessages: () => void;
|
|
67
|
+
handleChatInput: (e: Event) => void;
|
|
68
|
+
handleChatKeyDown: (e: KeyboardEvent) => void;
|
|
69
|
+
sendChatMessage: () => void;
|
|
70
|
+
toggleTheme: () => void;
|
|
71
|
+
interruptChat: () => void;
|
|
72
|
+
handleDragStart: (e: MouseEvent) => void;
|
|
73
|
+
handleDragMove: (e: MouseEvent) => void;
|
|
74
|
+
handleDragEnd: () => void;
|
|
75
|
+
handleOverlayClick: () => void;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 更新聊天框位置(使用 floating-ui)
|
|
79
|
+
* @param referenceEl 参考元素(选中的 DOM 元素)
|
|
80
|
+
* @param floatingEl 浮动元素(聊天框)
|
|
81
|
+
* @returns cleanup 函数
|
|
82
|
+
*/
|
|
83
|
+
export declare function updateChatModalPosition(referenceEl: HTMLElement | null, floatingEl: HTMLElement | null): (() => void) | null;
|
|
84
|
+
/**
|
|
85
|
+
* 渲染聊天框模板
|
|
86
|
+
*/
|
|
87
|
+
export declare function renderChatModal(state: ChatState, handlers: ChatHandlers): TemplateResult;
|
|
88
|
+
/**
|
|
89
|
+
* 聊天框样式 - 命令行风格
|
|
90
|
+
*/
|
|
91
|
+
export declare const chatStyles: import("lit").CSSResult;
|
|
92
|
+
/**
|
|
93
|
+
* 流式事件处理器
|
|
94
|
+
*/
|
|
95
|
+
export interface StreamHandlers {
|
|
96
|
+
onText: (content: string) => void;
|
|
97
|
+
onToolStart: (toolId: string, toolName: string, index: number) => void;
|
|
98
|
+
onToolInput: (index: number, input: Record<string, any>) => void;
|
|
99
|
+
onToolResult: (toolUseId: string, content: string, isError?: boolean) => void;
|
|
100
|
+
onError: (error: Error) => void;
|
|
101
|
+
onSessionId?: (sessionId: string) => void;
|
|
102
|
+
onProjectRoot?: (cwd: string) => void;
|
|
103
|
+
onModel?: (model: string) => void;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 获取 AI 模型信息
|
|
107
|
+
*/
|
|
108
|
+
export declare function fetchModelInfo(ip: string, port: number): Promise<string>;
|
|
109
|
+
/**
|
|
110
|
+
* 发送聊天消息到服务器
|
|
111
|
+
*/
|
|
112
|
+
export declare function sendChatToServer(ip: string, port: number, message: string, context: ChatContext | null, history: ChatMessage[], handlers: StreamHandlers, signal?: AbortSignal, sessionId?: string | null): Promise<void>;
|
package/types/client/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LitElement, TemplateResult } from 'lit';
|
|
2
|
+
import { ChatMessage, ChatContext, ToolCall } from './ai';
|
|
2
3
|
interface Position {
|
|
3
4
|
left?: string;
|
|
4
5
|
right?: string;
|
|
@@ -42,12 +43,14 @@ export declare class CodeInspectorComponent extends LitElement {
|
|
|
42
43
|
autoToggle: boolean;
|
|
43
44
|
hideConsole: boolean;
|
|
44
45
|
locate: boolean;
|
|
45
|
-
copy: boolean | string;
|
|
46
|
+
copy: boolean | undefined | string;
|
|
46
47
|
target: string;
|
|
47
48
|
targetNode: HTMLElement | null;
|
|
48
49
|
ip: string;
|
|
50
|
+
ai: boolean;
|
|
49
51
|
private wheelThrottling;
|
|
50
52
|
modeKey: string;
|
|
53
|
+
defaultAction: string;
|
|
51
54
|
position: {
|
|
52
55
|
top: number;
|
|
53
56
|
right: number;
|
|
@@ -101,6 +104,28 @@ export declare class CodeInspectorComponent extends LitElement {
|
|
|
101
104
|
internalLocate: boolean;
|
|
102
105
|
internalCopy: boolean;
|
|
103
106
|
internalTarget: boolean;
|
|
107
|
+
internalAI: boolean;
|
|
108
|
+
showChatModal: boolean;
|
|
109
|
+
chatMessages: ChatMessage[];
|
|
110
|
+
chatInput: string;
|
|
111
|
+
chatLoading: boolean;
|
|
112
|
+
chatContext: ChatContext | null;
|
|
113
|
+
currentTools: Map<string, ToolCall>;
|
|
114
|
+
chatSessionId: string | null;
|
|
115
|
+
chatTheme: 'light' | 'dark';
|
|
116
|
+
turnStatus: 'idle' | 'running' | 'done' | 'interrupt';
|
|
117
|
+
turnDuration: number;
|
|
118
|
+
chatModel: string;
|
|
119
|
+
private chatAbortController;
|
|
120
|
+
private turnTimerInterval;
|
|
121
|
+
private turnStartTime;
|
|
122
|
+
isDragging: boolean;
|
|
123
|
+
private dragStartX;
|
|
124
|
+
private dragStartY;
|
|
125
|
+
private modalStartX;
|
|
126
|
+
private modalStartY;
|
|
127
|
+
private wasDragging;
|
|
128
|
+
private chatPositionCleanup;
|
|
104
129
|
inspectorSwitchRef: HTMLDivElement;
|
|
105
130
|
codeInspectorContainerRef: HTMLDivElement;
|
|
106
131
|
elementInfoRef: HTMLDivElement;
|
|
@@ -112,7 +137,12 @@ export declare class CodeInspectorComponent extends LitElement {
|
|
|
112
137
|
description: string;
|
|
113
138
|
checked: () => boolean;
|
|
114
139
|
onChange: () => void;
|
|
140
|
+
action: string;
|
|
141
|
+
fn: () => void;
|
|
142
|
+
key: number;
|
|
143
|
+
available: () => boolean;
|
|
115
144
|
}[];
|
|
145
|
+
private eventListeners;
|
|
116
146
|
isTracking: (e: any) => boolean | "";
|
|
117
147
|
getDomPropertyValue: (target: HTMLElement, property: string) => number;
|
|
118
148
|
calculateElementInfoPosition: (target: HTMLElement) => Promise<{
|
|
@@ -146,6 +176,10 @@ export declare class CodeInspectorComponent extends LitElement {
|
|
|
146
176
|
sendXHR: () => void;
|
|
147
177
|
sendImg: () => void;
|
|
148
178
|
buildTargetUrl: () => string;
|
|
179
|
+
locateCode: () => void;
|
|
180
|
+
copyCode: () => void;
|
|
181
|
+
targetCode: () => void;
|
|
182
|
+
dispatchCustomEvent: (action: 'locate' | 'copy' | 'target' | 'chat' | string) => void;
|
|
149
183
|
trackCode: () => void;
|
|
150
184
|
private handleModeShortcut;
|
|
151
185
|
showNotification(message: string, type?: 'success' | 'error'): void;
|
|
@@ -177,13 +211,39 @@ export declare class CodeInspectorComponent extends LitElement {
|
|
|
177
211
|
handleMouseLeaveNode: () => void;
|
|
178
212
|
toggleSettingsModal: () => void;
|
|
179
213
|
closeSettingsModal: () => void;
|
|
214
|
+
private clearAllActions;
|
|
180
215
|
toggleLocate: () => void;
|
|
181
216
|
toggleCopy: () => void;
|
|
182
217
|
toggleTarget: () => void;
|
|
218
|
+
toggleAICode: () => void;
|
|
219
|
+
openChatModal: () => void;
|
|
220
|
+
closeChatModal: () => void;
|
|
221
|
+
clearChatMessages: () => void;
|
|
222
|
+
toggleTheme: () => void;
|
|
223
|
+
handleChatInput: (e: Event) => void;
|
|
224
|
+
handleChatKeyDown: (e: KeyboardEvent) => void;
|
|
225
|
+
private scrollPending;
|
|
226
|
+
private scrollChatToBottom;
|
|
227
|
+
private startTurnTimer;
|
|
228
|
+
private stopTurnTimer;
|
|
229
|
+
interruptChat: () => void;
|
|
230
|
+
handleChatDragStart: (e: MouseEvent) => void;
|
|
231
|
+
handleChatDragMove: (e: MouseEvent) => void;
|
|
232
|
+
handleChatDragEnd: () => void;
|
|
233
|
+
handleOverlayClick: () => void;
|
|
234
|
+
sendChatMessage: () => Promise<void>;
|
|
235
|
+
/**
|
|
236
|
+
* Attach all event listeners
|
|
237
|
+
*/
|
|
238
|
+
private attachEventListeners;
|
|
239
|
+
/**
|
|
240
|
+
* Detach all event listeners
|
|
241
|
+
*/
|
|
242
|
+
private detachEventListeners;
|
|
183
243
|
protected firstUpdated(): void;
|
|
184
244
|
disconnectedCallback(): void;
|
|
185
245
|
renderNodeTree: (node: TreeNode) => TemplateResult;
|
|
186
246
|
render(): TemplateResult<1>;
|
|
187
|
-
static styles: import("lit").CSSResult;
|
|
247
|
+
static styles: import("lit").CSSResult[];
|
|
188
248
|
}
|
|
189
249
|
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AIOptions } from '../shared';
|
|
2
|
+
import type { AIContext, AIMessage } from './ai';
|
|
3
|
+
export interface ProviderCallbacks {
|
|
4
|
+
sendSSE: (data: object | string) => void;
|
|
5
|
+
onEnd: () => void;
|
|
6
|
+
}
|
|
7
|
+
export interface ProviderResult {
|
|
8
|
+
abort: () => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 获取模型信息
|
|
12
|
+
* 优先使用用户配置,否则通过 CLI 的 system 事件获取(无 API 消耗)
|
|
13
|
+
*/
|
|
14
|
+
export declare function getModelInfo(aiOptions: AIOptions | undefined): Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Claude provider 统一入口
|
|
17
|
+
* ai.ts 只需调用此函数,不感知 CLI/SDK 细节
|
|
18
|
+
*/
|
|
19
|
+
export declare function handleClaudeRequest(message: string, context: AIContext | null, history: AIMessage[], sessionId: string | undefined, cwd: string, aiOptions: AIOptions | undefined, callbacks: ProviderCallbacks): ProviderResult;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* AI 功能模块 - 处理与 AI Agent 的交互
|
|
4
|
+
* 通过 provider 模式支持不同的 AI 后端
|
|
5
|
+
*/
|
|
6
|
+
import http from 'http';
|
|
7
|
+
import type { AIOptions } from '../shared';
|
|
8
|
+
/**
|
|
9
|
+
* AI 上下文信息
|
|
10
|
+
*/
|
|
11
|
+
export interface AIContext {
|
|
12
|
+
file: string;
|
|
13
|
+
line: number;
|
|
14
|
+
column: number;
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* AI 消息
|
|
19
|
+
*/
|
|
20
|
+
export interface AIMessage {
|
|
21
|
+
role: 'user' | 'assistant';
|
|
22
|
+
content: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* AI 请求体
|
|
26
|
+
*/
|
|
27
|
+
export interface AIRequest {
|
|
28
|
+
message: string;
|
|
29
|
+
context: AIContext;
|
|
30
|
+
history: AIMessage[];
|
|
31
|
+
sessionId?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 从 behavior 配置中提取 AI 选项
|
|
35
|
+
*/
|
|
36
|
+
export declare function getAIOptions(behavior?: {
|
|
37
|
+
ai?: {
|
|
38
|
+
claudeCode?: boolean | AIOptions;
|
|
39
|
+
};
|
|
40
|
+
}): AIOptions | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* 处理 AI 请求
|
|
43
|
+
*/
|
|
44
|
+
export declare function handleAIRequest(req: http.IncomingMessage, res: http.ServerResponse, corsHeaders: Record<string, string>, aiOptions: AIOptions | undefined, projectRootPath: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* 处理 AI 模型信息请求
|
|
47
|
+
*/
|
|
48
|
+
export declare function handleAIModelRequest(res: http.ServerResponse, corsHeaders: Record<string, string>, aiOptions: AIOptions | undefined): Promise<void>;
|
package/types/server/server.d.ts
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* 本地服务器模块 - 处理 IDE 打开和 AI 请求
|
|
4
|
+
*/
|
|
2
5
|
import http from 'http';
|
|
3
|
-
import type {
|
|
6
|
+
import type { CodeOptions, RecordInfo } from '../shared';
|
|
7
|
+
export declare function getEnvVars(): Record<string, string>;
|
|
8
|
+
/** 项目根目录 */
|
|
4
9
|
export declare const ProjectRootPath: string;
|
|
10
|
+
/**
|
|
11
|
+
* 获取相对路径
|
|
12
|
+
*/
|
|
5
13
|
export declare function getRelativePath(filePath: string): string;
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
/**
|
|
15
|
+
* 根据用户配置返回绝对路径或者相对路径
|
|
16
|
+
*/
|
|
17
|
+
export declare function getRelativeOrAbsolutePath(filePath: string, pathType?: 'relative' | 'absolute'): string;
|
|
18
|
+
/**
|
|
19
|
+
* 创建 HTTP 服务器
|
|
20
|
+
*/
|
|
21
|
+
export declare function createServer(callback: (port: number) => void, options?: CodeOptions, record?: RecordInfo): http.Server;
|
|
22
|
+
/**
|
|
23
|
+
* 启动服务器
|
|
24
|
+
*/
|
|
8
25
|
export declare function startServer(options: CodeOptions, record: RecordInfo): Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import MagicString from 'magic-string';
|
|
2
|
+
import { EscapeTags } from '../../shared';
|
|
3
|
+
import type { ElementNode } from '@vue/compiler-dom';
|
|
4
|
+
export interface PugFileInfo {
|
|
5
|
+
content: string;
|
|
6
|
+
offsets: number[];
|
|
7
|
+
}
|
|
8
|
+
export declare const pugMap: Map<string, PugFileInfo>;
|
|
9
|
+
/**
|
|
10
|
+
* Check if a template node uses Pug syntax
|
|
11
|
+
* @param templateNode - The template element node to check
|
|
12
|
+
* @returns true if the template uses Pug, false otherwise
|
|
13
|
+
*/
|
|
14
|
+
export declare function isPugTemplate(templateNode: ElementNode | undefined): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Calculate line offsets for content
|
|
17
|
+
* @param content - The file content
|
|
18
|
+
* @returns Array of line offsets
|
|
19
|
+
*/
|
|
20
|
+
export declare function calculateLineOffsets(content: string): number[];
|
|
21
|
+
/**
|
|
22
|
+
* Transform Pug template in Vue SFC
|
|
23
|
+
* @param content - The file content
|
|
24
|
+
* @param filePath - The file path
|
|
25
|
+
* @param templateNode - The template element node
|
|
26
|
+
* @param escapeTags - Tags to escape from transformation
|
|
27
|
+
* @param s - MagicString instance for code transformation
|
|
28
|
+
*/
|
|
29
|
+
export declare function transformPugTemplate(content: string, filePath: string, templateNode: ElementNode, escapeTags: EscapeTags, s: MagicString): void;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 浏览器环境 console 彩色输出工具
|
|
3
|
+
*
|
|
4
|
+
* 使用方式类似 chalk,基于浏览器 console 的 %c 机制实现:
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* // 单行输出
|
|
8
|
+
* browserChalk.blue('[plugin]').green(' ready').log();
|
|
9
|
+
*
|
|
10
|
+
* // 多行输出
|
|
11
|
+
* browserChalk
|
|
12
|
+
* .blue('[plugin]')
|
|
13
|
+
* .line()
|
|
14
|
+
* .green('• line1')
|
|
15
|
+
* .line()
|
|
16
|
+
* .yellow('• line2')
|
|
17
|
+
* .log();
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
interface ChainResult {
|
|
21
|
+
text: string;
|
|
22
|
+
styles: string[];
|
|
23
|
+
}
|
|
24
|
+
export declare class BrowserChalkChain {
|
|
25
|
+
private parts;
|
|
26
|
+
push(text: string, style: string): this;
|
|
27
|
+
/** 换行 */
|
|
28
|
+
line(): this;
|
|
29
|
+
/** 合并另一个 chain 的内容 */
|
|
30
|
+
merge(other: BrowserChalkChain): this;
|
|
31
|
+
/** 构建最终的 text 和 styles 数组 */
|
|
32
|
+
build(): ChainResult;
|
|
33
|
+
/** 直接 console.log 输出 */
|
|
34
|
+
log(): void;
|
|
35
|
+
/** 直接 console.warn 输出 */
|
|
36
|
+
warn(): void;
|
|
37
|
+
/** 直接 console.error 输出 */
|
|
38
|
+
error(): void;
|
|
39
|
+
/** console.groupCollapsed 输出,label 为当前 chain 内容,fn 中输出 group 内容 */
|
|
40
|
+
groupCollapsed(fn: () => void): void;
|
|
41
|
+
group(fn: () => void): void;
|
|
42
|
+
blue(t: string): this;
|
|
43
|
+
green(t: string): this;
|
|
44
|
+
yellow(t: string): this;
|
|
45
|
+
red(t: string): this;
|
|
46
|
+
gray(t: string): this;
|
|
47
|
+
text(t: string): this;
|
|
48
|
+
styled(t: string, css: string): this;
|
|
49
|
+
/** 无参数:给上一个 part 追加 bold;有参数:输出纯 bold 文本 */
|
|
50
|
+
bold(t?: string): this;
|
|
51
|
+
style(style: string): this;
|
|
52
|
+
}
|
|
53
|
+
type ChalkFactory = {
|
|
54
|
+
[K in 'blue' | 'green' | 'yellow' | 'red' | 'gray' | 'text']: (t: string) => BrowserChalkChain;
|
|
55
|
+
} & {
|
|
56
|
+
bold: (t?: string) => BrowserChalkChain;
|
|
57
|
+
styled: (t: string, css: string) => BrowserChalkChain;
|
|
58
|
+
};
|
|
59
|
+
export declare const browserChalk: ChalkFactory;
|
|
60
|
+
export {};
|
package/types/shared/type.d.ts
CHANGED
|
@@ -2,11 +2,57 @@
|
|
|
2
2
|
import { Server } from 'http';
|
|
3
3
|
import type { Editor } from 'launch-ide';
|
|
4
4
|
export type HotKey = 'ctrlKey' | 'altKey' | 'metaKey' | 'shiftKey';
|
|
5
|
+
export type AIOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* @zh 指定使用的 Agent 类型。'cli' 使用本地 Claude Code CLI,'sdk' 使用 Claude Agent SDK。默认为 'cli'
|
|
8
|
+
* @en Specify the agent type to use. 'cli' uses local Claude Code CLI, 'sdk' uses Claude Agent SDK. Defaults to 'cli'
|
|
9
|
+
*/
|
|
10
|
+
agent?: 'cli' | 'sdk';
|
|
11
|
+
/**
|
|
12
|
+
* @zh SDK 选项,参数格式继承 @anthropic-ai/claude-agent-sdk 官方 SDK 的 Options 类型
|
|
13
|
+
* @en SDK options, parameter format follows the official @anthropic-ai/claude-agent-sdk Options type
|
|
14
|
+
* @see https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk
|
|
15
|
+
*/
|
|
16
|
+
sdkOptions?: {
|
|
17
|
+
/** 允许自动执行的工具列表 */
|
|
18
|
+
allowedTools?: string[];
|
|
19
|
+
/** 禁止的工具列表 */
|
|
20
|
+
disallowedTools?: string[];
|
|
21
|
+
/** 使用的模型 */
|
|
22
|
+
model?: string;
|
|
23
|
+
/** 最大执行轮数,默认为 20 */
|
|
24
|
+
maxTurns?: number;
|
|
25
|
+
/**
|
|
26
|
+
* 权限模式。默认为 'bypassPermissions'
|
|
27
|
+
* - 'default' 需要用户确认
|
|
28
|
+
* - 'acceptEdits' 自动接受编辑
|
|
29
|
+
* - 'bypassPermissions' 绕过所有权限检查
|
|
30
|
+
*/
|
|
31
|
+
permissionMode?: 'default' | 'acceptEdits' | 'bypassPermissions';
|
|
32
|
+
/** 系统提示 */
|
|
33
|
+
systemPrompt?: string | {
|
|
34
|
+
type: 'preset';
|
|
35
|
+
preset: 'claude_code';
|
|
36
|
+
append?: string;
|
|
37
|
+
};
|
|
38
|
+
/** 环境变量,传递给 Claude Code 进程。默认为 process.env */
|
|
39
|
+
env?: Record<string, string | undefined>;
|
|
40
|
+
/** MCP 服务器配置 */
|
|
41
|
+
mcpServers?: Record<string, any>;
|
|
42
|
+
/** 最大思考 token 数 */
|
|
43
|
+
maxThinkingTokens?: number;
|
|
44
|
+
/** 最大预算(美元) */
|
|
45
|
+
maxBudgetUsd?: number;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
5
48
|
export type Behavior = {
|
|
6
49
|
locate?: boolean;
|
|
7
50
|
copy?: boolean | string;
|
|
8
51
|
target?: string;
|
|
9
|
-
|
|
52
|
+
ai?: {
|
|
53
|
+
claudeCode?: boolean | AIOptions;
|
|
54
|
+
};
|
|
55
|
+
defaultAction?: 'copy' | 'locate' | 'target' | 'ai';
|
|
10
56
|
};
|
|
11
57
|
export type RecordInfo = {
|
|
12
58
|
port: number;
|
package/types/shared/utils.d.ts
CHANGED
|
@@ -6,14 +6,133 @@ export declare function getFilePathWithoutExt(filePath: string): string;
|
|
|
6
6
|
export declare function normalizePath(filepath: string): string;
|
|
7
7
|
export declare function isEscapeTags(escapeTags: EscapeTags, tag: string): boolean;
|
|
8
8
|
export declare function getDependenciesMap(): any;
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function getDependencies(): string[];
|
|
10
10
|
type BooleanFunction = () => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Determine if the current environment is development mode
|
|
13
|
+
*
|
|
14
|
+
* Priority: user-specified environment > system default environment
|
|
15
|
+
*
|
|
16
|
+
* @param userDev - User-specified development mode setting:
|
|
17
|
+
* - `true`: Force development mode
|
|
18
|
+
* - `false`: Force production mode
|
|
19
|
+
* - `function`: Dynamic function that returns boolean
|
|
20
|
+
* - `undefined`: Use system default
|
|
21
|
+
* @param systemDev - System default development mode (e.g., from NODE_ENV)
|
|
22
|
+
* @returns `true` if in development mode, `false` otherwise
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Force development mode
|
|
27
|
+
* isDev(true, false) // Returns: true
|
|
28
|
+
*
|
|
29
|
+
* // Force production mode
|
|
30
|
+
* isDev(false, true) // Returns: false
|
|
31
|
+
*
|
|
32
|
+
* // Use system default
|
|
33
|
+
* isDev(undefined, true) // Returns: true
|
|
34
|
+
*
|
|
35
|
+
* // Dynamic function
|
|
36
|
+
* isDev(() => process.env.NODE_ENV === 'development', false)
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
11
39
|
export declare function isDev(userDev: boolean | BooleanFunction | undefined, systemDev: boolean): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Check if a file matches the given condition
|
|
42
|
+
*
|
|
43
|
+
* Supports multiple condition types for flexible file matching:
|
|
44
|
+
* - String: Checks if file path contains the string
|
|
45
|
+
* - RegExp: Tests file path against the regular expression
|
|
46
|
+
* - Array: Recursively checks if file matches any condition in the array
|
|
47
|
+
*
|
|
48
|
+
* @param condition - The condition to match against:
|
|
49
|
+
* - `string`: File path must contain this string
|
|
50
|
+
* - `RegExp`: File path must match this pattern
|
|
51
|
+
* - `Array`: File path must match at least one condition
|
|
52
|
+
* @param file - The file path to check
|
|
53
|
+
* @returns `true` if the file matches the condition, `false` otherwise
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // String matching
|
|
58
|
+
* matchCondition('node_modules', '/path/to/node_modules/pkg') // Returns: true
|
|
59
|
+
*
|
|
60
|
+
* // RegExp matching
|
|
61
|
+
* matchCondition(/\.test\.ts$/, 'file.test.ts') // Returns: true
|
|
62
|
+
*
|
|
63
|
+
* // Array matching (OR logic)
|
|
64
|
+
* matchCondition(['src', /\.tsx$/], 'src/App.tsx') // Returns: true
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
12
67
|
export declare function matchCondition(condition: Condition, file: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Get the mapped file path based on the provided mappings configuration
|
|
70
|
+
*
|
|
71
|
+
* This function resolves file paths by applying mapping rules, which is useful for:
|
|
72
|
+
* - Resolving module aliases (e.g., '@/components' -> 'src/components')
|
|
73
|
+
* - Mapping node_modules paths to local source paths
|
|
74
|
+
* - Handling monorepo package paths
|
|
75
|
+
*
|
|
76
|
+
* @param file - The original file path to map
|
|
77
|
+
* @param mappings - Path mapping configuration, can be either:
|
|
78
|
+
* - Object: `{ '@/': 'src/', '~': 'node_modules/' }`
|
|
79
|
+
* - Array: `[{ find: '@/', replacement: 'src/' }, { find: /^~/, replacement: 'node_modules/' }]`
|
|
80
|
+
* @returns The mapped file path if a mapping is found and the file exists, otherwise returns the original path
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // Object mapping
|
|
85
|
+
* getMappingFilePath('@/components/Button.tsx', { '@/': 'src/' })
|
|
86
|
+
* // Returns: 'src/components/Button.tsx' (if file exists)
|
|
87
|
+
*
|
|
88
|
+
* // Array mapping with RegExp
|
|
89
|
+
* getMappingFilePath('~/lodash/index.js', [
|
|
90
|
+
* { find: /^~/, replacement: 'node_modules/' }
|
|
91
|
+
* ])
|
|
92
|
+
* // Returns: 'node_modules/lodash/index.js' (if file exists)
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
13
95
|
export declare function getMappingFilePath(file: string, mappings?: Record<string, string> | Array<{
|
|
14
96
|
find: string | RegExp;
|
|
15
97
|
replacement: string;
|
|
16
98
|
}>): string;
|
|
99
|
+
/**
|
|
100
|
+
* Check if a file should be excluded from processing
|
|
101
|
+
*
|
|
102
|
+
* Determines if a file should be excluded based on exclude/include patterns.
|
|
103
|
+
* Files in node_modules are always excluded unless explicitly included.
|
|
104
|
+
*
|
|
105
|
+
* Logic:
|
|
106
|
+
* - If file matches exclude pattern AND NOT in include pattern → excluded
|
|
107
|
+
* - If file matches include pattern → NOT excluded (even if in node_modules)
|
|
108
|
+
* - node_modules is always in the exclude list by default
|
|
109
|
+
*
|
|
110
|
+
* @param file - The file path to check
|
|
111
|
+
* @param options - Code inspector options containing exclude/include patterns
|
|
112
|
+
* @returns `true` if the file should be excluded, `false` otherwise
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const options = {
|
|
117
|
+
* exclude: [/\.test\.ts$/, 'dist'],
|
|
118
|
+
* include: ['src']
|
|
119
|
+
* };
|
|
120
|
+
*
|
|
121
|
+
* isExcludedFile('src/App.test.ts', options) // Returns: true (matches exclude)
|
|
122
|
+
* isExcludedFile('node_modules/pkg/index.js', options) // Returns: true (node_modules)
|
|
123
|
+
* isExcludedFile('src/index.ts', options) // Returns: false (in include)
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
17
126
|
export declare function isExcludedFile(file: string, options: CodeOptions): boolean;
|
|
18
127
|
export declare function hasWritePermission(filePath: string): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Check if a file should be ignored based on special directives in comments
|
|
130
|
+
* @param content - The file content to check
|
|
131
|
+
* @param fileType - The type of file ('vue', 'jsx', 'svelte', or unknown)
|
|
132
|
+
* @returns true if the file should be ignored, false otherwise
|
|
133
|
+
*/
|
|
134
|
+
export declare function isIgnoredFile({ content, fileType, }: {
|
|
135
|
+
content: string;
|
|
136
|
+
fileType: 'vue' | 'jsx' | 'svelte' | unknown;
|
|
137
|
+
}): boolean;
|
|
19
138
|
export {};
|