@akanjs/cli 3.0.0-beta.12 → 3.0.0-beta.14
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/.build-stamp +1 -1
- package/{TunnelShare-sbsaggmb.js → TunnelShare-r5tc2qk5.js} +2 -2
- package/{agent.command-7357vxd8.js → agent.command-bhwsc2aj.js} +1 -1
- package/{application.command-pc8mdn3w.js → application.command-436y543n.js} +1 -11
- package/{cloud.command-cawrd5nq.js → cloud.command-3xn0xpz8.js} +4 -17
- package/{cloud.script-1bmptvw0.js → cloud.script-0a76c2g8.js} +4 -5
- package/commandManifest.json +1 -1
- package/{context.command-982b6kdp.js → context.command-hxh96cc3.js} +4 -6
- package/{devTui-hmteztv3.js → devTui-4ted58a6.js} +1 -1
- package/{devTuiView-40jvjnyz.js → devTuiView-1dj2yq7t.js} +1 -1
- package/guideline.command-cyw8c0m0.js +48 -0
- package/guidelines/agentRule/agentRule.instruction.md +24 -13
- package/guidelines/conventions/conventions.instruction.md +6 -3
- package/guidelines/moduleCodegen/moduleCodegen.instruction.md +1 -1
- package/guidelines/workspaceRecipes/workspaceRecipes.generate.json +1 -0
- package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +62 -0
- package/index-1mrmve4s.js +61 -0
- package/{index-s3fvrydw.js → index-31hmq4ys.js} +1 -1
- package/{index-ay8wj00x.js → index-8tcj5wk8.js} +6 -19
- package/index-9fbk3dbh.js +234 -0
- package/{index-3pvkjza8.js → index-fad0hhty.js} +3 -3
- package/{index-jcekapz4.js → index-gm76f0qb.js} +1 -1
- package/{index-bw2marpf.js → index-myj01w9r.js} +18 -19
- package/{index-kbsach1y.js → index-r73ha1rf.js} +1 -1
- package/{index-r8bd61d9.js → index-sg1bgdhe.js} +65 -68
- package/{index-8tfmh0v6.js → index-tt6kzwj5.js} +5 -15
- package/index.js +14 -14
- package/{localRegistry.command-rx758ajg.js → localRegistry.command-4cbgz63s.js} +3 -4
- package/{module.command-c2eve036.js → module.command-ew0484va.js} +4 -7
- package/package.json +2 -5
- package/{primitive.command-c44f7z1s.js → primitive.command-50ecfzg4.js} +2 -5
- package/{quality.command-5evdd263.js → quality.command-a2jytczs.js} +63 -3
- package/{scalar.command-xyzerygj.js → scalar.command-bptz6aj6.js} +3 -6
- package/{subspace.command-ebfwzypw.js → subspace.command-kmemx1vm.js} +2 -2
- package/{tunnel.command-v6a7at16.js → tunnel.command-67q8vsg5.js} +2 -2
- package/{workflow.command-t174m6sy.js → workflow.command-2ze5y2xp.js} +4 -7
- package/{workspace.command-bg3eveth.js → workspace.command-2n385jkt.js} +9 -10
- package/abstractCompactor-bqh31fk5.js +0 -102
- package/guideline.command-jn0vwszx.js +0 -360
- package/index-ceph7zqj.js +0 -229
- package/index-fr2x3qvv.js +0 -841
- package/index-meh558jy.js +0 -65
- package/index-yc1keaer.js +0 -338
package/index-meh558jy.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// pkgs/@akanjs/devkit/abstractDoc.ts
|
|
3
|
-
class AbstractDoc {
|
|
4
|
-
path;
|
|
5
|
-
content;
|
|
6
|
-
siblingFiles;
|
|
7
|
-
static suffix = ".abstract.md";
|
|
8
|
-
static maxLines = 300;
|
|
9
|
-
static compactMinLines = 40;
|
|
10
|
-
static #facetRoots = "{lib,ui,webkit,srvkit,common,plugin}";
|
|
11
|
-
static isAbstractPath(filePath) {
|
|
12
|
-
return filePath.endsWith(AbstractDoc.suffix);
|
|
13
|
-
}
|
|
14
|
-
static lineCountOf(content) {
|
|
15
|
-
return content.split(/\r?\n/).length;
|
|
16
|
-
}
|
|
17
|
-
static kindOf(filePath) {
|
|
18
|
-
const [root, folder, ...rest] = filePath.split("/");
|
|
19
|
-
if (root !== "lib" || !folder)
|
|
20
|
-
return "other";
|
|
21
|
-
if (folder === "__scalar")
|
|
22
|
-
return rest.length === 2 ? "scalar" : "other";
|
|
23
|
-
if (rest.length !== 1)
|
|
24
|
-
return "other";
|
|
25
|
-
return folder.startsWith("_") ? "service" : "domain";
|
|
26
|
-
}
|
|
27
|
-
static async findAll(sys, { module } = {}) {
|
|
28
|
-
const filePaths = (await sys.getAllFiles(`${AbstractDoc.#facetRoots}/**/*${AbstractDoc.suffix}`)).sort();
|
|
29
|
-
const docs = await Promise.all(filePaths.map((filePath) => AbstractDoc.read(sys, filePath)));
|
|
30
|
-
if (!module)
|
|
31
|
-
return docs;
|
|
32
|
-
return docs.filter((doc) => doc.moduleName === module || doc.folderName === module);
|
|
33
|
-
}
|
|
34
|
-
static async read(sys, filePath) {
|
|
35
|
-
const dirPath = filePath.split("/").slice(0, -1).join("/");
|
|
36
|
-
const [content, folderFiles] = await Promise.all([sys.readFile(filePath), sys.readdir(dirPath)]);
|
|
37
|
-
return new AbstractDoc(filePath, content, folderFiles.filter((fileName) => !AbstractDoc.isAbstractPath(fileName)));
|
|
38
|
-
}
|
|
39
|
-
constructor(path, content, siblingFiles) {
|
|
40
|
-
this.path = path;
|
|
41
|
-
this.content = content;
|
|
42
|
-
this.siblingFiles = siblingFiles;
|
|
43
|
-
}
|
|
44
|
-
get kind() {
|
|
45
|
-
return AbstractDoc.kindOf(this.path);
|
|
46
|
-
}
|
|
47
|
-
get folderName() {
|
|
48
|
-
return this.path.split("/").at(-2) ?? "";
|
|
49
|
-
}
|
|
50
|
-
get moduleName() {
|
|
51
|
-
return (this.path.split("/").at(-1) ?? "").slice(0, -AbstractDoc.suffix.length);
|
|
52
|
-
}
|
|
53
|
-
get lineCount() {
|
|
54
|
-
return AbstractDoc.lineCountOf(this.content);
|
|
55
|
-
}
|
|
56
|
-
canReplaceWith(candidate) {
|
|
57
|
-
const next = candidate.trim();
|
|
58
|
-
if (!next.startsWith("#"))
|
|
59
|
-
return false;
|
|
60
|
-
const lineCount = AbstractDoc.lineCountOf(next);
|
|
61
|
-
return lineCount >= 3 && lineCount < this.lineCount;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export { AbstractDoc };
|
package/index-yc1keaer.js
DELETED
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import {
|
|
3
|
-
GlobalConfig
|
|
4
|
-
} from "./index-bw2marpf.js";
|
|
5
|
-
import {
|
|
6
|
-
Spinner
|
|
7
|
-
} from "./index-5nyznra1.js";
|
|
8
|
-
|
|
9
|
-
// pkgs/@akanjs/devkit/aiEditor.ts
|
|
10
|
-
import { input, select } from "@inquirer/prompts";
|
|
11
|
-
import {
|
|
12
|
-
AIMessage,
|
|
13
|
-
HumanMessage,
|
|
14
|
-
mapChatMessagesToStoredMessages,
|
|
15
|
-
mapStoredMessagesToChatMessages
|
|
16
|
-
} from "@langchain/core/messages";
|
|
17
|
-
import { ChatDeepSeek } from "@langchain/deepseek";
|
|
18
|
-
import { ChatOpenAI } from "@langchain/openai";
|
|
19
|
-
import { Logger } from "akanjs/common";
|
|
20
|
-
import chalk from "chalk";
|
|
21
|
-
var MAX_ASK_TRY = 300;
|
|
22
|
-
var deepSeekLlmModels = ["deepseek-v4-flash", "deepseek-v4-pro"];
|
|
23
|
-
var openAiLlmModels = ["gpt-5.5"];
|
|
24
|
-
var supportedLlmModels = [...deepSeekLlmModels, ...openAiLlmModels];
|
|
25
|
-
var isOpenAiLlmModel = (model) => openAiLlmModels.includes(model);
|
|
26
|
-
var parseTypescriptFileBlocks = (text) => {
|
|
27
|
-
const fileBlocks = [];
|
|
28
|
-
const codeBlockRegex = /```(?:typescript|ts|tsx)\s*\n([\s\S]*?)```/gi;
|
|
29
|
-
const filePathRegex = /^\s*\/\/\s*File:\s*(.+?)\s*$/im;
|
|
30
|
-
for (const codeBlock of text.matchAll(codeBlockRegex)) {
|
|
31
|
-
const content = codeBlock[1]?.trim();
|
|
32
|
-
if (!content)
|
|
33
|
-
continue;
|
|
34
|
-
const filePath = filePathRegex.exec(content)?.[1]?.trim();
|
|
35
|
-
if (!filePath)
|
|
36
|
-
continue;
|
|
37
|
-
fileBlocks.push({
|
|
38
|
-
filePath,
|
|
39
|
-
content: content.replace(filePathRegex, "").trim()
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
return fileBlocks;
|
|
43
|
-
};
|
|
44
|
-
var preserveTypescriptResponseContent = (previousContent, nextContent) => {
|
|
45
|
-
const previousWrites = parseTypescriptFileBlocks(previousContent);
|
|
46
|
-
const nextWrites = parseTypescriptFileBlocks(nextContent);
|
|
47
|
-
if (previousWrites.length > 0 && nextWrites.length === 0)
|
|
48
|
-
return previousContent;
|
|
49
|
-
return nextContent;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
class AiSession {
|
|
53
|
-
static #cacheDir = "node_modules/.cache/akan/aiSession";
|
|
54
|
-
static #chat = null;
|
|
55
|
-
static async init({ temperature = 0, useExisting = true } = {}) {
|
|
56
|
-
if (useExisting) {
|
|
57
|
-
const llmConfig = await AiSession.getLlmConfig();
|
|
58
|
-
if (llmConfig) {
|
|
59
|
-
AiSession.#setChatModel(llmConfig.model, llmConfig.apiKey);
|
|
60
|
-
Logger.rawLog(chalk.dim(`\uD83E\uDD16akan editor uses existing LLM config (${llmConfig.model})`));
|
|
61
|
-
return AiSession;
|
|
62
|
-
}
|
|
63
|
-
} else
|
|
64
|
-
Logger.rawLog(chalk.yellow("\uD83E\uDD16akan-editor is not initialized. LLM configuration should be set first."));
|
|
65
|
-
const llmConfig = await AiSession.#requestLlmConfig();
|
|
66
|
-
const { model, apiKey } = llmConfig;
|
|
67
|
-
await AiSession.#validateApiKey(model, apiKey);
|
|
68
|
-
const session = AiSession.#setChatModel(model, apiKey, { temperature });
|
|
69
|
-
await session.setLlmConfig({ model, apiKey });
|
|
70
|
-
return session;
|
|
71
|
-
}
|
|
72
|
-
static #setChatModel(model, apiKey, { temperature = 0 } = {}) {
|
|
73
|
-
AiSession.#chat = AiSession.#createChatModel(model, apiKey, {
|
|
74
|
-
temperature,
|
|
75
|
-
streaming: true
|
|
76
|
-
});
|
|
77
|
-
return AiSession;
|
|
78
|
-
}
|
|
79
|
-
static #createChatModel(model, apiKey, { temperature = 0, streaming = false } = {}) {
|
|
80
|
-
if (isOpenAiLlmModel(model))
|
|
81
|
-
return new ChatOpenAI({
|
|
82
|
-
modelName: model,
|
|
83
|
-
temperature,
|
|
84
|
-
streaming,
|
|
85
|
-
openAIApiKey: apiKey
|
|
86
|
-
});
|
|
87
|
-
return new ChatDeepSeek({
|
|
88
|
-
modelName: model,
|
|
89
|
-
temperature,
|
|
90
|
-
streaming,
|
|
91
|
-
apiKey
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
static async getLlmConfig() {
|
|
95
|
-
return await GlobalConfig.getLlmConfig();
|
|
96
|
-
}
|
|
97
|
-
static async setLlmConfig(llmConfig) {
|
|
98
|
-
await GlobalConfig.setLlmConfig(llmConfig);
|
|
99
|
-
return AiSession;
|
|
100
|
-
}
|
|
101
|
-
static async#requestLlmConfig() {
|
|
102
|
-
const model = await select({
|
|
103
|
-
message: "Select a LLM model",
|
|
104
|
-
choices: supportedLlmModels
|
|
105
|
-
});
|
|
106
|
-
const apiKey = await input({ message: "Enter your API key" });
|
|
107
|
-
return { model, apiKey };
|
|
108
|
-
}
|
|
109
|
-
static async#validateApiKey(modelName, apiKey) {
|
|
110
|
-
const spinner = new Spinner("Validating LLM API key...", {
|
|
111
|
-
prefix: `\uD83E\uDD16akan-editor`
|
|
112
|
-
}).start();
|
|
113
|
-
const chat = AiSession.#createChatModel(modelName, apiKey);
|
|
114
|
-
try {
|
|
115
|
-
await chat.invoke("Hi, and just say 'ok'");
|
|
116
|
-
spinner.succeed("LLM API key is valid");
|
|
117
|
-
return true;
|
|
118
|
-
} catch (error) {
|
|
119
|
-
spinner.fail(chalk.red(`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"`));
|
|
120
|
-
throw error;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
static async clearCache(workspaceRoot) {
|
|
124
|
-
const cacheDir = `${workspaceRoot}/${AiSession.#cacheDir}`;
|
|
125
|
-
await Bun.$`rm -rf ${cacheDir}`;
|
|
126
|
-
}
|
|
127
|
-
messageHistory = [];
|
|
128
|
-
sessionKey;
|
|
129
|
-
isCacheLoaded = false;
|
|
130
|
-
workspace;
|
|
131
|
-
constructor(type, {
|
|
132
|
-
workspace,
|
|
133
|
-
cacheKey,
|
|
134
|
-
isContinued
|
|
135
|
-
}) {
|
|
136
|
-
this.workspace = workspace;
|
|
137
|
-
this.sessionKey = `${type}${cacheKey ? `-${cacheKey}` : ""}`;
|
|
138
|
-
if (isContinued)
|
|
139
|
-
this.#cacheLoadPromise = this.#loadCache();
|
|
140
|
-
}
|
|
141
|
-
#cacheLoadPromise = null;
|
|
142
|
-
async#loadCache() {
|
|
143
|
-
const cacheFile = `${AiSession.#cacheDir}/${this.sessionKey}.json`;
|
|
144
|
-
const isCacheExists = await this.workspace.exists(cacheFile);
|
|
145
|
-
if (isCacheExists)
|
|
146
|
-
this.messageHistory = mapStoredMessagesToChatMessages(await this.workspace.readJson(cacheFile));
|
|
147
|
-
else
|
|
148
|
-
this.messageHistory = [];
|
|
149
|
-
this.isCacheLoaded = isCacheExists;
|
|
150
|
-
}
|
|
151
|
-
async#saveCache() {
|
|
152
|
-
const cacheFilePath = `${AiSession.#cacheDir}/${this.sessionKey}.json`;
|
|
153
|
-
await this.workspace.writeJson(cacheFilePath, mapChatMessagesToStoredMessages(this.messageHistory));
|
|
154
|
-
}
|
|
155
|
-
async ask(question, {
|
|
156
|
-
onReasoning = (reasoning) => {
|
|
157
|
-
Logger.raw(chalk.dim(reasoning));
|
|
158
|
-
},
|
|
159
|
-
onChunk = (chunk) => {
|
|
160
|
-
Logger.raw(chunk);
|
|
161
|
-
}
|
|
162
|
-
} = {}) {
|
|
163
|
-
if (!AiSession.#chat)
|
|
164
|
-
await AiSession.init();
|
|
165
|
-
if (this.#cacheLoadPromise)
|
|
166
|
-
await this.#cacheLoadPromise;
|
|
167
|
-
if (!AiSession.#chat)
|
|
168
|
-
throw new Error("Failed to initialize the AI session");
|
|
169
|
-
const loader = new Spinner(`${AiSession.#chat.model} is thinking...`, {
|
|
170
|
-
prefix: `\uD83E\uDD16akan-editor`
|
|
171
|
-
}).start();
|
|
172
|
-
try {
|
|
173
|
-
const humanMessage = new HumanMessage(question);
|
|
174
|
-
this.messageHistory.push(humanMessage);
|
|
175
|
-
const stream = await AiSession.#chat.stream(this.messageHistory);
|
|
176
|
-
let reasoningResponse = "", fullResponse = "";
|
|
177
|
-
for await (const chunk of stream) {
|
|
178
|
-
if (loader.isSpinning())
|
|
179
|
-
loader.succeed(`${AiSession.#chat.model} responded`);
|
|
180
|
-
if (!fullResponse.length) {
|
|
181
|
-
const reasoningContent = chunk.additional_kwargs.reasoning_content ?? "";
|
|
182
|
-
if (reasoningContent.length) {
|
|
183
|
-
reasoningResponse += reasoningContent;
|
|
184
|
-
onReasoning(reasoningContent);
|
|
185
|
-
continue;
|
|
186
|
-
} else if (chunk.content.length) {
|
|
187
|
-
reasoningResponse += `
|
|
188
|
-
`;
|
|
189
|
-
onReasoning(reasoningResponse);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
const content = chunk.content;
|
|
193
|
-
if (typeof content === "string") {
|
|
194
|
-
fullResponse += content;
|
|
195
|
-
onChunk(content);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
fullResponse += `
|
|
199
|
-
`;
|
|
200
|
-
onChunk(`
|
|
201
|
-
`);
|
|
202
|
-
this.messageHistory.push(new AIMessage(fullResponse));
|
|
203
|
-
return { content: fullResponse, messageHistory: this.messageHistory };
|
|
204
|
-
} catch {
|
|
205
|
-
loader.fail(`${AiSession.#chat.model} failed to respond`);
|
|
206
|
-
throw new Error("Failed to stream response");
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
async edit(question, { onChunk, onReasoning, maxTry = MAX_ASK_TRY, validate, approve, fallbackToPreviousTypescript } = {}) {
|
|
210
|
-
for (let tryCount = 0;tryCount < maxTry; tryCount++) {
|
|
211
|
-
let response = await this.ask(question, { onChunk, onReasoning });
|
|
212
|
-
if (validate?.length && tryCount === 0) {
|
|
213
|
-
const validateQuestion = `Double check if the response meets the requirements and conditions, and follow the instructions. If not, rewrite it.
|
|
214
|
-
${validate.map((v) => `- ${v}`).join(`
|
|
215
|
-
`)}`;
|
|
216
|
-
const validateResponse = await this.ask(validateQuestion, {
|
|
217
|
-
onChunk,
|
|
218
|
-
onReasoning
|
|
219
|
-
});
|
|
220
|
-
response = {
|
|
221
|
-
...validateResponse,
|
|
222
|
-
content: fallbackToPreviousTypescript ? preserveTypescriptResponseContent(response.content, validateResponse.content) : validateResponse.content
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
const isConfirmed = approve ? true : await select({
|
|
226
|
-
message: "Do you want to edit the response?",
|
|
227
|
-
choices: [
|
|
228
|
-
{ name: "\u2705 Yes, confirm and apply this result", value: true },
|
|
229
|
-
{ name: "\uD83D\uDD04 No, I want to edit it more", value: false }
|
|
230
|
-
]
|
|
231
|
-
});
|
|
232
|
-
if (isConfirmed) {
|
|
233
|
-
await this.#saveCache();
|
|
234
|
-
return response.content;
|
|
235
|
-
}
|
|
236
|
-
question = await input({ message: "What do you want to change?" });
|
|
237
|
-
tryCount++;
|
|
238
|
-
}
|
|
239
|
-
throw new Error("Failed to edit");
|
|
240
|
-
}
|
|
241
|
-
async editTypescript(question, options = {}) {
|
|
242
|
-
const content = await this.edit(question, options);
|
|
243
|
-
return this.#getTypescriptCode(content);
|
|
244
|
-
}
|
|
245
|
-
#getTypescriptCode(content) {
|
|
246
|
-
//! will be deprecated
|
|
247
|
-
const code = /```(typescript|tsx)([\s\S]*?)```/.exec(content);
|
|
248
|
-
return code?.[2] ?? content;
|
|
249
|
-
}
|
|
250
|
-
addToolMessgaes(messages) {
|
|
251
|
-
const toolMessages = messages.map((message) => new HumanMessage(message.content));
|
|
252
|
-
this.messageHistory.push(...toolMessages);
|
|
253
|
-
return this;
|
|
254
|
-
}
|
|
255
|
-
async writeTypescripts(question, executor, options = {}) {
|
|
256
|
-
const content = await this.edit(question, {
|
|
257
|
-
...options,
|
|
258
|
-
fallbackToPreviousTypescript: true
|
|
259
|
-
});
|
|
260
|
-
const writes = this.#getTypescriptCodes(content);
|
|
261
|
-
if (!writes.length)
|
|
262
|
-
throw new Error("No parseable TypeScript file blocks were found in the AI response. Include `// File: <path>` in each code block.");
|
|
263
|
-
for (const write of writes)
|
|
264
|
-
await executor.writeFile(write.filePath, write.content);
|
|
265
|
-
return await this.#tryFixTypescripts(writes, executor, options);
|
|
266
|
-
}
|
|
267
|
-
async#editTypescripts(question, options = {}, fallbackWrites) {
|
|
268
|
-
const content = await this.edit(question, {
|
|
269
|
-
...options,
|
|
270
|
-
fallbackToPreviousTypescript: true
|
|
271
|
-
});
|
|
272
|
-
const writes = this.#getTypescriptCodes(content);
|
|
273
|
-
if (!writes.length && fallbackWrites?.length)
|
|
274
|
-
return fallbackWrites;
|
|
275
|
-
if (!writes.length)
|
|
276
|
-
throw new Error("No parseable TypeScript file blocks were found in the AI response. Include `// File: <path>` in each code block.");
|
|
277
|
-
return writes;
|
|
278
|
-
}
|
|
279
|
-
async#tryFixTypescripts(writes, executor, options = {}) {
|
|
280
|
-
const MAX_EDIT_TRY = 5;
|
|
281
|
-
for (let tryCount = 0;tryCount < MAX_EDIT_TRY; tryCount++) {
|
|
282
|
-
const loader = new Spinner(`Type checking and linting...`, {
|
|
283
|
-
prefix: `\uD83E\uDD16akan-editor`
|
|
284
|
-
}).start();
|
|
285
|
-
const fileChecks = await Promise.all(writes.map(async ({ filePath }) => {
|
|
286
|
-
const lintResult = await executor.lint(filePath, { fix: true });
|
|
287
|
-
const typeCheckResult = await executor.typeCheckAsync(filePath);
|
|
288
|
-
const hasTypeErrors = typeCheckResult.fileErrors.length > 0;
|
|
289
|
-
const hasLintErrors = lintResult.errors.length > 0;
|
|
290
|
-
const needFix = hasTypeErrors || hasLintErrors;
|
|
291
|
-
return { filePath, typeCheckResult, lintResult, needFix };
|
|
292
|
-
}));
|
|
293
|
-
const hasAnyFix = fileChecks.some((fileCheck) => fileCheck.needFix);
|
|
294
|
-
if (hasAnyFix) {
|
|
295
|
-
loader.fail("Type checking and linting has some errors, try to fix them");
|
|
296
|
-
fileChecks.forEach((fileCheck) => {
|
|
297
|
-
Logger.rawLog(`TypeCheck Result
|
|
298
|
-
${fileCheck.typeCheckResult.message}
|
|
299
|
-
Lint Result
|
|
300
|
-
${fileCheck.lintResult.message}`);
|
|
301
|
-
this.addToolMessgaes([
|
|
302
|
-
{ type: "typescript", content: fileCheck.typeCheckResult.message },
|
|
303
|
-
{ type: "eslint", content: fileCheck.lintResult.message }
|
|
304
|
-
]);
|
|
305
|
-
});
|
|
306
|
-
writes = await this.#editTypescripts("Fix the typescript and eslint errors", {
|
|
307
|
-
...options,
|
|
308
|
-
validate: undefined,
|
|
309
|
-
approve: true
|
|
310
|
-
}, writes);
|
|
311
|
-
for (const write of writes)
|
|
312
|
-
await executor.writeFile(write.filePath, write.content);
|
|
313
|
-
} else {
|
|
314
|
-
loader.succeed("Type checking and linting has no errors");
|
|
315
|
-
return writes;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
throw new Error("Failed to create scalar");
|
|
319
|
-
}
|
|
320
|
-
#getTypescriptCodes(text) {
|
|
321
|
-
return parseTypescriptFileBlocks(text);
|
|
322
|
-
}
|
|
323
|
-
async editMarkdown(request, options = {}) {
|
|
324
|
-
const content = await this.edit(request, options);
|
|
325
|
-
return this.#getMarkdownContent(content);
|
|
326
|
-
}
|
|
327
|
-
#getMarkdownContent(text) {
|
|
328
|
-
const searchText = "```markdown";
|
|
329
|
-
const firstIndex = text.indexOf("```markdown");
|
|
330
|
-
const lastIndex = text.lastIndexOf("```");
|
|
331
|
-
if (firstIndex === -1)
|
|
332
|
-
return text;
|
|
333
|
-
else
|
|
334
|
-
return text.slice(firstIndex + searchText.length, lastIndex).trim();
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
export { AiSession };
|