diff --git a/bots/codeChackTemplate.js b/bots/codeChackTemplate.js new file mode 100644 index 0000000..77b5d97 --- /dev/null +++ b/bots/codeChackTemplate.js @@ -0,0 +1,10 @@ +import * as skills from '../../../src/agent/library/skills.js'; +import * as world from '../../../src/agent/library/world.js'; +import Vec3 from 'vec3'; + +const log = skills.log; + +export async function main(bot) { + /* CODE HERE */ + log(bot, 'Code finished.'); +} \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..1bdf2b3 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,25 @@ +// eslint.config.js +import globals from "globals"; +import pluginJs from "@eslint/js"; + +/** @type {import('eslint').Linter.Config[]} */ +export default [ + // 首先引入推荐配置 + pluginJs.configs.recommended, + + // 然后覆盖或自定义特定规则 + { + languageOptions: { + globals: globals.browser, + ecmaVersion: 2021, + sourceType: "module", + }, + rules: { + "no-undef": "error", // 禁止使用未声明的变量或函数。 + "semi": ["error", "always"], // 强制在语句末尾使用分号。 + "curly": "warn", // 强制使用花括号包裹代码块。 + "no-unused-vars": "off", // 禁用未使用变量的警告。 + "no-unreachable": "off", // 禁用无法到达代码的警告。 + }, + }, +]; diff --git a/src/agent/coder.js b/src/agent/coder.js index d5bbf38..729bb03 100644 --- a/src/agent/coder.js +++ b/src/agent/coder.js @@ -14,6 +14,7 @@ export class Coder { this.executing = false; this.generating = false; this.code_template = ''; + this.code_chack_template = ''; this.timedout = false; this.cur_action_name = ''; @@ -21,7 +22,10 @@ export class Coder { if (err) throw err; this.code_template = data; }); - + readFile('./bots/codeChackTemplate.js', 'utf8', (err, data) => { + if (err) throw err; + this.code_chack_template = data; + }); mkdirSync('.' + this.fp, { recursive: true }); } @@ -64,6 +68,7 @@ export class Coder { for (let line of code.split('\n')) { src += ` ${line}\n`; } + let src_check_copy = this.code_chack_template.replace('/* CODE HERE */', src); src = this.code_template.replace('/* CODE HERE */', src); let filename = this.file_counter + '.js'; @@ -92,8 +97,7 @@ export class Coder { console.error('Error writing code execution file: ' + result); return null; } - - return [ main: mainFn ,src]; + return { func:{main: mainFn}, src_check_copy: src_check_copy }; } sanitizeCode(code) { @@ -170,10 +174,12 @@ export class Coder { } code = res.substring(res.indexOf('```')+3, res.lastIndexOf('```')); - let codeStagingResult,src; + let codeStagingResult,src_check_copy; try { - [codeStagingResult,src] = await this.stageCode(code); - const analysisResult = await this.checkCode(src); + const result = await this.stageCode(code); + codeStagingResult = result.func; + src_check_copy = result.src_check_copy; + const analysisResult = await this.checkCode(src_check_copy); if (analysisResult) { const message = 'Error: Code syntax error. Please try again:'+'\n'+analysisResult+'\n'+await this.agent.prompter.getRelevantSkillDocs(analysisResult,3); messages.push({ role: 'system', content: message });