@akanjs/devkit 3.0.0-beta.13 โ 3.0.0-beta.15
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/README.md +1 -0
- package/cloud/cloudApi.ts +17 -4
- package/cloud/constants.ts +0 -3
- package/cloud/globalConfig.ts +1 -9
- package/codeAgent/agent/AkanAuthStorageBackend.ts +105 -0
- package/codeAgent/agent/AkanCodeServices.ts +104 -0
- package/codeAgent/agent/CodeAgent.ts +543 -0
- package/codeAgent/agent/CodeAgentAsks.ts +87 -0
- package/codeAgent/agent/CodeAgentEventMapper.ts +260 -0
- package/codeAgent/agent/CodeAgentGate.ts +119 -0
- package/codeAgent/agent/CodeAgentRpcHost.ts +96 -0
- package/codeAgent/agent/CodeAgentStreamPrinter.ts +93 -0
- package/codeAgent/agent/CodeAgentUi.ts +52 -0
- package/codeAgent/agent/CodeMailbox.ts +175 -0
- package/codeAgent/agent/CodeSessionFork.ts +71 -0
- package/codeAgent/agent/CodeSessionIndex.ts +104 -0
- package/codeAgent/agent/SubagentPool.ts +173 -0
- package/codeAgent/agent/akanCodeModel.ts +81 -0
- package/codeAgent/agent/akanCodePaths.ts +31 -0
- package/codeAgent/agent/akanSystemPrompt.ts +49 -0
- package/codeAgent/agent/codeAgentContract.test.ts +529 -0
- package/codeAgent/agent/codeMailbox.test.ts +80 -0
- package/codeAgent/agent/codeSessionFork.test.ts +60 -0
- package/codeAgent/agent/codeSessionIndex.test.ts +72 -0
- package/codeAgent/agent/consoleToStderr.ts +18 -0
- package/codeAgent/feedback/DevLogFeedback.ts +97 -0
- package/codeAgent/feedback/PreviewChrome.ts +106 -0
- package/codeAgent/feedback/PreviewFeedback.ts +53 -0
- package/codeAgent/feedback/PreviewView.ts +107 -0
- package/codeAgent/feedback/TurnFeedback.ts +113 -0
- package/codeAgent/feedback/VerifyFeedback.ts +46 -0
- package/codeAgent/feedback/previewChrome.test.ts +73 -0
- package/codeAgent/index.ts +43 -0
- package/codeAgent/skills/akan-debug/SKILL.md +42 -0
- package/codeAgent/skills/akan-deps/SKILL.md +50 -0
- package/codeAgent/skills/akan-err/SKILL.md +39 -0
- package/codeAgent/skills/akan-module/SKILL.md +45 -0
- package/codeAgent/skills/akan-scaffold/SKILL.md +76 -0
- package/codeAgent/skills/akan-scalar/SKILL.md +52 -0
- package/codeAgent/skills/akan-service/SKILL.md +34 -0
- package/codeAgent/skills/akan-store/SKILL.md +63 -0
- package/codeAgent/skills/akan-ui/SKILL.md +63 -0
- package/codeAgent/skills/akan-validate/SKILL.md +44 -0
- package/codeAgent/tools/AkanCli.ts +62 -0
- package/codeAgent/tools/AkanCodePlugins.ts +135 -0
- package/codeAgent/tools/AkanEditScope.ts +58 -0
- package/codeAgent/tools/AkanEnvKeys.ts +56 -0
- package/codeAgent/tools/AkanToolPack.ts +114 -0
- package/codeAgent/tools/AkanVerifier.ts +55 -0
- package/codeAgent/tools/MailToolPack.ts +85 -0
- package/codeAgent/tools/McpClient.ts +162 -0
- package/codeAgent/tools/McpToolPack.ts +134 -0
- package/codeAgent/tools/SessionToolPack.ts +101 -0
- package/codeAgent/tools/WebToolPack.ts +153 -0
- package/codeAgent/tools/akanCodePlugins.test.ts +476 -0
- package/commandDecorators/command.ts +1 -1
- package/incrementalBuilder/incrementalBuilder.proc.ts +1 -1
- package/index.ts +3 -2
- package/package.json +5 -5
- package/stripAnsi.ts +3 -0
- package/testHelpers.ts +179 -0
- package/abstractCompactor.ts +0 -112
- package/aiEditor.test.ts +0 -60
- package/aiEditor.ts +0 -387
package/aiEditor.ts
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import { input, select } from "@inquirer/prompts";
|
|
2
|
-
import {
|
|
3
|
-
AIMessage,
|
|
4
|
-
type BaseMessage,
|
|
5
|
-
HumanMessage,
|
|
6
|
-
mapChatMessagesToStoredMessages,
|
|
7
|
-
mapStoredMessagesToChatMessages,
|
|
8
|
-
type StoredMessage,
|
|
9
|
-
} from "@langchain/core/messages";
|
|
10
|
-
import { ChatDeepSeek } from "@langchain/deepseek";
|
|
11
|
-
import { ChatOpenAI } from "@langchain/openai";
|
|
12
|
-
import { Logger } from "akanjs/common";
|
|
13
|
-
import chalk from "chalk";
|
|
14
|
-
|
|
15
|
-
import { GlobalConfig } from "./cloud";
|
|
16
|
-
import type { Executor, WorkspaceExecutor } from "./executors";
|
|
17
|
-
import { Spinner } from "./spinner";
|
|
18
|
-
import type { FileContent } from "./types";
|
|
19
|
-
|
|
20
|
-
const MAX_ASK_TRY = 300;
|
|
21
|
-
|
|
22
|
-
const deepSeekLlmModels = ["deepseek-v4-flash", "deepseek-v4-pro"] as const;
|
|
23
|
-
|
|
24
|
-
const openAiLlmModels = ["gpt-5.5"] as const;
|
|
25
|
-
|
|
26
|
-
export const supportedLlmModels = [...deepSeekLlmModels, ...openAiLlmModels] as const;
|
|
27
|
-
export type SupportedLlmModel = (typeof supportedLlmModels)[number];
|
|
28
|
-
type OpenAiLlmModel = (typeof openAiLlmModels)[number];
|
|
29
|
-
|
|
30
|
-
const isOpenAiLlmModel = (model: SupportedLlmModel): model is OpenAiLlmModel =>
|
|
31
|
-
openAiLlmModels.includes(model as OpenAiLlmModel);
|
|
32
|
-
|
|
33
|
-
interface EditOptions {
|
|
34
|
-
onReasoning?: (reasoning: string) => void;
|
|
35
|
-
onChunk?: (chunk: string) => void;
|
|
36
|
-
maxTry?: number;
|
|
37
|
-
validate?: string[];
|
|
38
|
-
approve?: boolean;
|
|
39
|
-
fallbackToPreviousTypescript?: boolean;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const parseTypescriptFileBlocks = (text: string): FileContent[] => {
|
|
43
|
-
const fileBlocks: FileContent[] = [];
|
|
44
|
-
const codeBlockRegex = /```(?:typescript|ts|tsx)\s*\n([\s\S]*?)```/gi;
|
|
45
|
-
const filePathRegex = /^\s*\/\/\s*File:\s*(.+?)\s*$/im;
|
|
46
|
-
|
|
47
|
-
for (const codeBlock of text.matchAll(codeBlockRegex)) {
|
|
48
|
-
const content = codeBlock[1]?.trim();
|
|
49
|
-
if (!content) continue;
|
|
50
|
-
|
|
51
|
-
const filePath = filePathRegex.exec(content)?.[1]?.trim();
|
|
52
|
-
if (!filePath) continue;
|
|
53
|
-
|
|
54
|
-
fileBlocks.push({
|
|
55
|
-
filePath,
|
|
56
|
-
content: content.replace(filePathRegex, "").trim(),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return fileBlocks;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const preserveTypescriptResponseContent = (previousContent: string, nextContent: string) => {
|
|
64
|
-
const previousWrites = parseTypescriptFileBlocks(previousContent);
|
|
65
|
-
const nextWrites = parseTypescriptFileBlocks(nextContent);
|
|
66
|
-
if (previousWrites.length > 0 && nextWrites.length === 0) return previousContent;
|
|
67
|
-
return nextContent;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export class AiSession {
|
|
71
|
-
static #cacheDir = "node_modules/.cache/akan/aiSession";
|
|
72
|
-
static #chat: ChatDeepSeek | ChatOpenAI | null = null;
|
|
73
|
-
static async init({ temperature = 0, useExisting = true }: { temperature?: number; useExisting?: boolean } = {}) {
|
|
74
|
-
if (useExisting) {
|
|
75
|
-
const llmConfig = await AiSession.getLlmConfig();
|
|
76
|
-
if (llmConfig) {
|
|
77
|
-
AiSession.#setChatModel(llmConfig.model, llmConfig.apiKey);
|
|
78
|
-
Logger.rawLog(chalk.dim(`๐คakan editor uses existing LLM config (${llmConfig.model})`));
|
|
79
|
-
return AiSession;
|
|
80
|
-
}
|
|
81
|
-
} else Logger.rawLog(chalk.yellow("๐คakan-editor is not initialized. LLM configuration should be set first."));
|
|
82
|
-
|
|
83
|
-
const llmConfig = await AiSession.#requestLlmConfig();
|
|
84
|
-
const { model, apiKey } = llmConfig;
|
|
85
|
-
|
|
86
|
-
await AiSession.#validateApiKey(model, apiKey);
|
|
87
|
-
const session = AiSession.#setChatModel(model, apiKey, { temperature });
|
|
88
|
-
await session.setLlmConfig({ model, apiKey });
|
|
89
|
-
return session;
|
|
90
|
-
}
|
|
91
|
-
static #setChatModel(model: SupportedLlmModel, apiKey: string, { temperature = 0 }: { temperature?: number } = {}) {
|
|
92
|
-
AiSession.#chat = AiSession.#createChatModel(model, apiKey, {
|
|
93
|
-
temperature,
|
|
94
|
-
streaming: true,
|
|
95
|
-
});
|
|
96
|
-
return AiSession;
|
|
97
|
-
}
|
|
98
|
-
static #createChatModel(
|
|
99
|
-
model: SupportedLlmModel,
|
|
100
|
-
apiKey: string,
|
|
101
|
-
{ temperature = 0, streaming = false }: { temperature?: number; streaming?: boolean } = {},
|
|
102
|
-
) {
|
|
103
|
-
if (isOpenAiLlmModel(model))
|
|
104
|
-
return new ChatOpenAI({
|
|
105
|
-
modelName: model,
|
|
106
|
-
temperature,
|
|
107
|
-
streaming,
|
|
108
|
-
openAIApiKey: apiKey,
|
|
109
|
-
});
|
|
110
|
-
return new ChatDeepSeek({
|
|
111
|
-
modelName: model,
|
|
112
|
-
temperature,
|
|
113
|
-
streaming,
|
|
114
|
-
apiKey,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
static async getLlmConfig() {
|
|
118
|
-
return await GlobalConfig.getLlmConfig();
|
|
119
|
-
}
|
|
120
|
-
static async setLlmConfig(llmConfig: { model: SupportedLlmModel; apiKey: string } | null) {
|
|
121
|
-
await GlobalConfig.setLlmConfig(llmConfig);
|
|
122
|
-
return AiSession;
|
|
123
|
-
}
|
|
124
|
-
static async #requestLlmConfig() {
|
|
125
|
-
const model = await select<SupportedLlmModel>({
|
|
126
|
-
message: "Select a LLM model",
|
|
127
|
-
choices: supportedLlmModels,
|
|
128
|
-
});
|
|
129
|
-
const apiKey = await input({ message: "Enter your API key" });
|
|
130
|
-
return { model, apiKey };
|
|
131
|
-
}
|
|
132
|
-
static async #validateApiKey(modelName: SupportedLlmModel, apiKey: string) {
|
|
133
|
-
const spinner = new Spinner("Validating LLM API key...", {
|
|
134
|
-
prefix: `๐คakan-editor`,
|
|
135
|
-
}).start();
|
|
136
|
-
const chat = AiSession.#createChatModel(modelName, apiKey);
|
|
137
|
-
try {
|
|
138
|
-
await chat.invoke("Hi, and just say 'ok'");
|
|
139
|
-
spinner.succeed("LLM API key is valid");
|
|
140
|
-
return true;
|
|
141
|
-
} catch (error) {
|
|
142
|
-
spinner.fail(
|
|
143
|
-
chalk.red(
|
|
144
|
-
`LLM API key is invalid. Please check your API key and try again. You can set it again by running "akan set-llm" or reset by running "akan reset-llm"`,
|
|
145
|
-
),
|
|
146
|
-
);
|
|
147
|
-
throw error;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
static async clearCache(workspaceRoot: string) {
|
|
151
|
-
const cacheDir = `${workspaceRoot}/${AiSession.#cacheDir}`;
|
|
152
|
-
await Bun.$`rm -rf ${cacheDir}`;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
messageHistory: BaseMessage[] = [];
|
|
156
|
-
readonly sessionKey: string;
|
|
157
|
-
isCacheLoaded: boolean = false;
|
|
158
|
-
workspace: WorkspaceExecutor;
|
|
159
|
-
constructor(
|
|
160
|
-
type: string,
|
|
161
|
-
{
|
|
162
|
-
workspace,
|
|
163
|
-
cacheKey,
|
|
164
|
-
isContinued,
|
|
165
|
-
}: {
|
|
166
|
-
workspace: WorkspaceExecutor;
|
|
167
|
-
cacheKey?: string;
|
|
168
|
-
isContinued?: boolean;
|
|
169
|
-
},
|
|
170
|
-
) {
|
|
171
|
-
this.workspace = workspace;
|
|
172
|
-
this.sessionKey = `${type}${cacheKey ? `-${cacheKey}` : ""}`;
|
|
173
|
-
if (isContinued) this.#cacheLoadPromise = this.#loadCache();
|
|
174
|
-
}
|
|
175
|
-
#cacheLoadPromise: Promise<void> | null = null;
|
|
176
|
-
async #loadCache() {
|
|
177
|
-
const cacheFile = `${AiSession.#cacheDir}/${this.sessionKey}.json`;
|
|
178
|
-
const isCacheExists = await this.workspace.exists(cacheFile);
|
|
179
|
-
if (isCacheExists)
|
|
180
|
-
this.messageHistory = mapStoredMessagesToChatMessages(
|
|
181
|
-
(await this.workspace.readJson(cacheFile)) as StoredMessage[],
|
|
182
|
-
);
|
|
183
|
-
else this.messageHistory = [];
|
|
184
|
-
this.isCacheLoaded = isCacheExists;
|
|
185
|
-
}
|
|
186
|
-
async #saveCache() {
|
|
187
|
-
const cacheFilePath = `${AiSession.#cacheDir}/${this.sessionKey}.json`;
|
|
188
|
-
await this.workspace.writeJson(cacheFilePath, mapChatMessagesToStoredMessages(this.messageHistory));
|
|
189
|
-
}
|
|
190
|
-
async ask(
|
|
191
|
-
question: string,
|
|
192
|
-
{
|
|
193
|
-
onReasoning = (reasoning: string) => {
|
|
194
|
-
Logger.raw(chalk.dim(reasoning));
|
|
195
|
-
},
|
|
196
|
-
onChunk = (chunk: string) => {
|
|
197
|
-
Logger.raw(chunk);
|
|
198
|
-
},
|
|
199
|
-
}: EditOptions = {},
|
|
200
|
-
): Promise<{ content: string; messageHistory: BaseMessage[] }> {
|
|
201
|
-
if (!AiSession.#chat) await AiSession.init();
|
|
202
|
-
if (this.#cacheLoadPromise) await this.#cacheLoadPromise;
|
|
203
|
-
|
|
204
|
-
if (!AiSession.#chat) throw new Error("Failed to initialize the AI session");
|
|
205
|
-
const loader = new Spinner(`${AiSession.#chat.model} is thinking...`, {
|
|
206
|
-
prefix: `๐คakan-editor`,
|
|
207
|
-
}).start();
|
|
208
|
-
try {
|
|
209
|
-
const humanMessage = new HumanMessage(question);
|
|
210
|
-
this.messageHistory.push(humanMessage);
|
|
211
|
-
const stream = await AiSession.#chat.stream(this.messageHistory);
|
|
212
|
-
let reasoningResponse = "",
|
|
213
|
-
fullResponse = "";
|
|
214
|
-
for await (const chunk of stream) {
|
|
215
|
-
if (loader.isSpinning()) loader.succeed(`${AiSession.#chat.model} responded`);
|
|
216
|
-
|
|
217
|
-
if (!fullResponse.length) {
|
|
218
|
-
const reasoningContent = (chunk.additional_kwargs as { reasoning_content?: string }).reasoning_content ?? "";
|
|
219
|
-
if (reasoningContent.length) {
|
|
220
|
-
reasoningResponse += reasoningContent;
|
|
221
|
-
onReasoning(reasoningContent);
|
|
222
|
-
continue;
|
|
223
|
-
} else if (chunk.content.length) {
|
|
224
|
-
reasoningResponse += "\n";
|
|
225
|
-
onReasoning(reasoningResponse);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const content = chunk.content;
|
|
230
|
-
if (typeof content === "string") {
|
|
231
|
-
fullResponse += content;
|
|
232
|
-
onChunk(content); // Send individual chunks to callback
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
fullResponse += "\n";
|
|
236
|
-
onChunk("\n");
|
|
237
|
-
this.messageHistory.push(new AIMessage(fullResponse));
|
|
238
|
-
return { content: fullResponse, messageHistory: this.messageHistory };
|
|
239
|
-
} catch {
|
|
240
|
-
loader.fail(`${AiSession.#chat.model} failed to respond`);
|
|
241
|
-
throw new Error("Failed to stream response");
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
async edit(
|
|
245
|
-
question: string,
|
|
246
|
-
{ onChunk, onReasoning, maxTry = MAX_ASK_TRY, validate, approve, fallbackToPreviousTypescript }: EditOptions = {},
|
|
247
|
-
) {
|
|
248
|
-
for (let tryCount = 0; tryCount < maxTry; tryCount++) {
|
|
249
|
-
let response = await this.ask(question, { onChunk, onReasoning });
|
|
250
|
-
if (validate?.length && tryCount === 0) {
|
|
251
|
-
const validateQuestion = `Double check if the response meets the requirements and conditions, and follow the instructions. If not, rewrite it.
|
|
252
|
-
${validate.map((v) => `- ${v}`).join("\n")}`;
|
|
253
|
-
const validateResponse = await this.ask(validateQuestion, {
|
|
254
|
-
onChunk,
|
|
255
|
-
onReasoning,
|
|
256
|
-
});
|
|
257
|
-
response = {
|
|
258
|
-
...validateResponse,
|
|
259
|
-
content: fallbackToPreviousTypescript
|
|
260
|
-
? preserveTypescriptResponseContent(response.content, validateResponse.content)
|
|
261
|
-
: validateResponse.content,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
const isConfirmed = approve
|
|
265
|
-
? true
|
|
266
|
-
: await select({
|
|
267
|
-
message: "Do you want to edit the response?",
|
|
268
|
-
choices: [
|
|
269
|
-
{ name: "โ
Yes, confirm and apply this result", value: true },
|
|
270
|
-
{ name: "๐ No, I want to edit it more", value: false },
|
|
271
|
-
],
|
|
272
|
-
});
|
|
273
|
-
if (isConfirmed) {
|
|
274
|
-
await this.#saveCache();
|
|
275
|
-
return response.content;
|
|
276
|
-
}
|
|
277
|
-
question = await input({ message: "What do you want to change?" });
|
|
278
|
-
tryCount++;
|
|
279
|
-
}
|
|
280
|
-
throw new Error("Failed to edit");
|
|
281
|
-
}
|
|
282
|
-
async editTypescript(question: string, options: EditOptions = {}) {
|
|
283
|
-
const content = await this.edit(question, options);
|
|
284
|
-
return this.#getTypescriptCode(content);
|
|
285
|
-
}
|
|
286
|
-
#getTypescriptCode(content: string) {
|
|
287
|
-
//! will be deprecated
|
|
288
|
-
const code = /```(typescript|tsx)([\s\S]*?)```/.exec(content);
|
|
289
|
-
// 2๋ฒ์งธ๋ก ํด์ผ ๋ฐํ๋๋๋ฐ ๋ชจ๋ฅด๊ฒ์ ์๋ฌดํผ ์ผ๋จ ์ด๋ ๊ฒ ํจ.
|
|
290
|
-
|
|
291
|
-
return code?.[2] ?? content;
|
|
292
|
-
// return code ? code[1] : content;
|
|
293
|
-
}
|
|
294
|
-
addToolMessgaes(messages: { type: string; content: string }[]) {
|
|
295
|
-
// const toolMessages = messages.map(
|
|
296
|
-
// (message) => new ToolMessage({ content: message.content, tool_call_id: message.type })
|
|
297
|
-
// );
|
|
298
|
-
const toolMessages = messages.map((message) => new HumanMessage(message.content));
|
|
299
|
-
this.messageHistory.push(...toolMessages);
|
|
300
|
-
return this;
|
|
301
|
-
}
|
|
302
|
-
async writeTypescripts(question: string, executor: Executor, options: EditOptions = {}) {
|
|
303
|
-
const content = await this.edit(question, {
|
|
304
|
-
...options,
|
|
305
|
-
fallbackToPreviousTypescript: true,
|
|
306
|
-
});
|
|
307
|
-
const writes = this.#getTypescriptCodes(content);
|
|
308
|
-
if (!writes.length)
|
|
309
|
-
throw new Error(
|
|
310
|
-
"No parseable TypeScript file blocks were found in the AI response. Include `// File: <path>` in each code block.",
|
|
311
|
-
);
|
|
312
|
-
for (const write of writes) await executor.writeFile(write.filePath, write.content);
|
|
313
|
-
return await this.#tryFixTypescripts(writes, executor, options);
|
|
314
|
-
}
|
|
315
|
-
async #editTypescripts(question: string, options: EditOptions = {}, fallbackWrites?: FileContent[]) {
|
|
316
|
-
const content = await this.edit(question, {
|
|
317
|
-
...options,
|
|
318
|
-
fallbackToPreviousTypescript: true,
|
|
319
|
-
});
|
|
320
|
-
const writes = this.#getTypescriptCodes(content);
|
|
321
|
-
if (!writes.length && fallbackWrites?.length) return fallbackWrites;
|
|
322
|
-
if (!writes.length)
|
|
323
|
-
throw new Error(
|
|
324
|
-
"No parseable TypeScript file blocks were found in the AI response. Include `// File: <path>` in each code block.",
|
|
325
|
-
);
|
|
326
|
-
return writes;
|
|
327
|
-
}
|
|
328
|
-
async #tryFixTypescripts(writes: FileContent[], executor: Executor, options: EditOptions = {}) {
|
|
329
|
-
const MAX_EDIT_TRY = 5;
|
|
330
|
-
for (let tryCount = 0; tryCount < MAX_EDIT_TRY; tryCount++) {
|
|
331
|
-
const loader = new Spinner(`Type checking and linting...`, {
|
|
332
|
-
prefix: `๐คakan-editor`,
|
|
333
|
-
}).start();
|
|
334
|
-
const fileChecks = await Promise.all(
|
|
335
|
-
writes.map(async ({ filePath }) => {
|
|
336
|
-
const lintResult = await executor.lint(filePath, { fix: true });
|
|
337
|
-
const typeCheckResult = await executor.typeCheckAsync(filePath);
|
|
338
|
-
const hasTypeErrors = typeCheckResult.fileErrors.length > 0;
|
|
339
|
-
const hasLintErrors = lintResult.errors.length > 0;
|
|
340
|
-
const needFix = hasTypeErrors || hasLintErrors;
|
|
341
|
-
return { filePath, typeCheckResult, lintResult, needFix };
|
|
342
|
-
}),
|
|
343
|
-
);
|
|
344
|
-
const hasAnyFix = fileChecks.some((fileCheck) => fileCheck.needFix);
|
|
345
|
-
if (hasAnyFix) {
|
|
346
|
-
loader.fail("Type checking and linting has some errors, try to fix them");
|
|
347
|
-
fileChecks.forEach((fileCheck) => {
|
|
348
|
-
Logger.rawLog(
|
|
349
|
-
`TypeCheck Result \n${fileCheck.typeCheckResult.message}\nLint Result \n${fileCheck.lintResult.message}`,
|
|
350
|
-
);
|
|
351
|
-
this.addToolMessgaes([
|
|
352
|
-
{ type: "typescript", content: fileCheck.typeCheckResult.message },
|
|
353
|
-
{ type: "eslint", content: fileCheck.lintResult.message },
|
|
354
|
-
]);
|
|
355
|
-
});
|
|
356
|
-
writes = await this.#editTypescripts(
|
|
357
|
-
"Fix the typescript and eslint errors",
|
|
358
|
-
{
|
|
359
|
-
...options,
|
|
360
|
-
validate: undefined,
|
|
361
|
-
approve: true,
|
|
362
|
-
},
|
|
363
|
-
writes,
|
|
364
|
-
);
|
|
365
|
-
for (const write of writes) await executor.writeFile(write.filePath, write.content);
|
|
366
|
-
} else {
|
|
367
|
-
loader.succeed("Type checking and linting has no errors");
|
|
368
|
-
return writes;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
throw new Error("Failed to create scalar");
|
|
372
|
-
}
|
|
373
|
-
#getTypescriptCodes(text: string): FileContent[] {
|
|
374
|
-
return parseTypescriptFileBlocks(text);
|
|
375
|
-
}
|
|
376
|
-
async editMarkdown(request: string, options: EditOptions = {}) {
|
|
377
|
-
const content = await this.edit(request, options);
|
|
378
|
-
return this.#getMarkdownContent(content);
|
|
379
|
-
}
|
|
380
|
-
#getMarkdownContent(text: string) {
|
|
381
|
-
const searchText = "```markdown";
|
|
382
|
-
const firstIndex = text.indexOf("```markdown");
|
|
383
|
-
const lastIndex = text.lastIndexOf("```");
|
|
384
|
-
if (firstIndex === -1) return text;
|
|
385
|
-
else return text.slice(firstIndex + searchText.length, lastIndex).trim();
|
|
386
|
-
}
|
|
387
|
-
}
|