@yorha2b-lab/autodev 4.2.0 → 5.1.0

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.
Files changed (58) hide show
  1. package/.github/scripts/deploy/publish.py +2 -2
  2. package/.github/scripts/render/dashboard.py +13 -9
  3. package/CONTRIBUTING.md +0 -18
  4. package/bin/autodev.js +28 -26
  5. package/config.js +3 -3
  6. package/package.json +1 -3
  7. package/src/bootstrap/dialogs.js +10 -0
  8. package/src/bootstrap/handlebars.js +26 -0
  9. package/src/bootstrap/handlers.js +10 -0
  10. package/src/bootstrap/index.js +56 -0
  11. package/src/bootstrap/infrastructure.js +16 -0
  12. package/src/bootstrap/openai.js +13 -0
  13. package/src/bootstrap/prompts.js +10 -0
  14. package/src/bootstrap/yorha.js +39 -0
  15. package/src/commands/watch.js +15 -42
  16. package/src/dialogs/EN-US.js +55 -0
  17. package/src/dialogs/ZH-CN.js +55 -0
  18. package/src/{core/react-compiler.js → framework/react/generator/index.js} +1 -1
  19. package/src/{prompts/react/watch-part.js → framework/react/prompts/part.js} +1 -1
  20. package/{templates → src/framework}/react/utils/utils.js +1 -1
  21. package/src/handlers/api.js +92 -0
  22. package/src/handlers/page.js +70 -0
  23. package/src/handlers/part.js +59 -0
  24. package/src/{services/api-linker.js → labs/linker.js} +14 -31
  25. package/src/{services/proxy-tower.js → labs/tower.js} +10 -23
  26. package/src/services/llm.js +21 -20
  27. package/src/utils/infrastructure.js +5 -2
  28. package/src/utils/ux.js +21 -18
  29. package/src/commands/handlers/api-handler.js +0 -111
  30. package/src/commands/handlers/page-handler.js +0 -96
  31. package/src/commands/handlers/part-handler.js +0 -77
  32. package/src/core/context.js +0 -93
  33. /package/{templates → src/framework}/react/components/EditableCell.js +0 -0
  34. /package/{templates → src/framework}/react/components/MyBaseForm.js +0 -0
  35. /package/{templates → src/framework}/react/components/MyImage.js +0 -0
  36. /package/{templates → src/framework}/react/components/MyModalForm.js +0 -0
  37. /package/{templates → src/framework}/react/components/MyModalTable.js +0 -0
  38. /package/{templates → src/framework}/react/components/MySearchForm.js +0 -0
  39. /package/{templates → src/framework}/react/components/MyTable.js +0 -0
  40. /package/{templates → src/framework}/react/components/index.js +0 -0
  41. /package/{templates/react → src/framework/react/handlebars}/index.hbs +0 -0
  42. /package/{templates/react/handlebars → src/framework/react/handlebars/partials}/AlertInfo.hbs +0 -0
  43. /package/{templates/react/handlebars → src/framework/react/handlebars/partials}/FunctionButtons.hbs +0 -0
  44. /package/{templates/react/handlebars → src/framework/react/handlebars/partials}/MySearchForm.hbs +0 -0
  45. /package/{templates/react/handlebars → src/framework/react/handlebars/partials}/MyTable.hbs +0 -0
  46. /package/{templates/react/handlebars → src/framework/react/handlebars/partials}/handleBlock.hbs +0 -0
  47. /package/{templates/react/handlebars → src/framework/react/handlebars/partials}/hookBlock.hbs +0 -0
  48. /package/{templates/react/handlebars → src/framework/react/handlebars/partials}/operateBlock.hbs +0 -0
  49. /package/{templates/react/handlebars → src/framework/react/handlebars/partials}/renderBlock.hbs +0 -0
  50. /package/{templates/react/handlebars → src/framework/react/handlebars/partials}/stateBlock.hbs +0 -0
  51. /package/{templates/react → src/framework/react/handlebars}/resource.hbs +0 -0
  52. /package/{templates → src/framework}/react/hooks/useTableQuery.js +0 -0
  53. /package/src/{prompts/react/watch-api.js → framework/react/prompts/api.js} +0 -0
  54. /package/src/{prompts/react/api-linker.js → framework/react/prompts/linker.js} +0 -0
  55. /package/src/{prompts → framework/react/prompts}/mock.js +0 -0
  56. /package/src/{prompts/react/watch-page.js → framework/react/prompts/page.js} +0 -0
  57. /package/src/{prompts → framework/react/prompts}/system.js +0 -0
  58. /package/src/{schema/react → framework/react/schema}/page.json +0 -0
@@ -1,111 +0,0 @@
1
- module.exports = async (filePath, liveResponse = null) => {
2
-
3
- const fs = require('fs')
4
- const ora = require('ora')
5
- const path = require('path')
6
- const chalk = require('chalk')
7
-
8
- const {
9
- unwrapSignal,
10
- config, language,
11
- alignResponseFields
12
- } = require('../../core/context').get()
13
-
14
- const { pagesDir } = config
15
-
16
- const startTime = Date.now()
17
- const fileName = liveResponse?.fileName ?? path.basename(filePath, path.extname(filePath))
18
- const resourcePath = path.join(process.cwd(), pagesDir, fileName, 'resource.js')
19
-
20
- const spinner = ora({
21
- text: chalk.yellow(language(
22
- `🤖 Pod 153: [侦察] 发现加密数据源 [${fileName}]。正在尝试执行语义对齐协议...\n`,
23
- `🤖 Pod 153: [Recon] Encrypted data source [${fileName}] detected. Initiating semantic alignment...\n`
24
- )),
25
- color: 'yellow'
26
- }).start()
27
-
28
- try {
29
- if (!fs.existsSync(resourcePath)) {
30
- throw new Error(language(
31
- `🤖 Pod 153: [警告] 地堡数据库中未检索到模块 [${fileName}] 的资源文件。请先执行视觉构筑。`,
32
- `🤖 Pod 153: [Warning] Module [${fileName}] resource not found in Bunker database. Please execute visual construction first.`
33
- ))
34
- }
35
-
36
- let rawJson = liveResponse ? liveResponse.data : JSON.parse(fs.readFileSync(filePath, 'utf8'))
37
- let resourceStr = fs.readFileSync(resourcePath, 'utf8')
38
-
39
- const coreArray = unwrapSignal(rawJson)
40
-
41
- if (!coreArray || coreArray.length === 0) {
42
- console.log(chalk.gray(language(
43
- ` [System] 数据格式非标准 JSON,将尝试原始字符对齐。`,
44
- ` [System] Data format is not standard JSON, will try to align by character.`)
45
- ))
46
- }
47
-
48
- const sampleData = coreArray && coreArray.length > 0 ? [coreArray[0]] : rawJson
49
-
50
- spinner.text = chalk.yellow(language(
51
- `🧑‍💻 9S: 正在扫描前后端字段差异... 执行语义桥接任务。`,
52
- `🧑‍💻 9S: Scanning field differences... Bridging semantic gaps.`
53
- ))
54
-
55
- const extractKeys = str => {
56
- const keys = []
57
- const regex = /(dataIndex|name)\s*:\s*['"]([^'"]+)['"]/g
58
- let match
59
- while ((match = regex.exec(str)) !== null) {
60
- keys.push(match[2])
61
- }
62
- return Array.from(new Set(keys))
63
- }
64
-
65
- const result = await alignResponseFields({ responseStr: JSON.stringify(sampleData), resourceStr: extractKeys(resourceStr).join(',') })
66
- let changeCount = 0
67
- const resultMapping = {}
68
- Object.entries(result).forEach(([oldField, newField]) => {
69
- if (oldField === newField) return
70
- const regex = new RegExp(`(dataIndex|name)\\s*:\\s*['"]${oldField}['"]`, 'g')
71
- resourceStr = resourceStr.replace(regex, `$1: '${newField}'`)
72
- changeCount++
73
- resultMapping[oldField] = newField
74
- })
75
-
76
- fs.writeFileSync(resourcePath, resourceStr)
77
- const endTime = Date.now()
78
-
79
- spinner.succeed(chalk.green(language(
80
- `🤖 Pod 153: [肯定] 语义桥接协议执行完毕。已物理修正 ${changeCount} 处字段偏差。耗时: ${(endTime - startTime) / 1000}s`,
81
- `🤖 Pod 153: [Affirmative] Semantic bridge protocol complete. Corrected ${changeCount} field deviations. Elapsed: ${(endTime - startTime) / 1000}s`
82
- )))
83
-
84
- if (changeCount > 0) {
85
- console.log(chalk.magenta(`\n┌────── [ YoRHa Autonomous Backend Alignment ] ──────┐`))
86
- Object.entries(resultMapping).forEach(([oldField, newField]) => {
87
- // 💡 物理校准:计算空格数量,让箭头对齐在第 15 个字符位
88
- // 中文字符长度 * 2 是为了抵消它在终端占的双倍宽度
89
- const padding = ' '.repeat(Math.max(1, 15 - oldField.length * 2))
90
- console.log(
91
- chalk.gray(` │ `) +
92
- chalk.yellow(oldField) +
93
- padding +
94
- chalk.cyan(` -> `) +
95
- chalk.white(newField)
96
- )
97
- })
98
- console.log(chalk.magenta(`└───────────────────────────────────────────────────────┘\n`))
99
- }
100
-
101
- if (fs.existsSync(filePath)) {
102
- fs.unlinkSync(filePath)
103
- }
104
-
105
- } catch (error) {
106
- spinner.fail(chalk.red(language(
107
- `🤖 Pod 153: [严重警告] 信号对齐失败。接口数据遭遇强力防火墙:${error}`,
108
- `🤖 Pod 153: [CRITICAL] Alignment failed. Encountered powerful API firewall: ${error}`
109
- )))
110
- }
111
- }
@@ -1,96 +0,0 @@
1
- module.exports = async filePath => {
2
-
3
- const fs = require('fs')
4
- const ora = require('ora')
5
- const path = require('path')
6
- const chalk = require('chalk')
7
-
8
- const {
9
- language,
10
- pagePrompt,
11
- menus, config,
12
- index, resource,
13
- contextStringify,
14
- generateMock, recognizePage,
15
- } = require('../../core/context').get()
16
-
17
- const { useDemo, pagesDir, needMock } = config
18
-
19
- const startTime = Date.now()
20
- const fileName = path.basename(filePath, path.extname(filePath))
21
- const mockDir = path.join(process.cwd(), 'mock')
22
- const targetDir = path.join(process.cwd(), pagesDir, fileName)
23
-
24
- const spinner = ora({
25
- text: chalk.cyan(language(
26
- `[System] 视觉传感器捕捉完成: [${fileName}]。正在调配地堡资源进行物理构筑...\n`,
27
- `[System] Visual sensor captured: [${fileName}]. Allocating Bunker resources for physical construction...\n`
28
- )),
29
- color: 'cyan'
30
- }).start()
31
-
32
- try {
33
-
34
- if (fs.existsSync(targetDir)) {
35
- spinner.warn(chalk.yellow(language(
36
- `🤖 Pod 042: [拦截] 模块 [${fileName}] 已存在于地堡数据库中。为了防止数据覆盖,构筑协议已跳过。`,
37
- `🤖 Pod 042: [Intercept] Module [${fileName}] already exists. Construction skipped to prevent overwrite.`
38
- )))
39
- return
40
- }
41
-
42
- if (!fs.existsSync(mockDir)) fs.mkdirSync(mockDir, { recursive: true })
43
- if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true })
44
-
45
- let pageConfig
46
- if (useDemo) {
47
- console.log(chalk.yellow(language(
48
- `\n🤖 Pod 042: [报告] 拦截到实弹请求。正在空投标准模拟包: example.json\n`,
49
- `\n🤖 Pod 042: [Report] Real-fire request intercepted. Dropping simulation package: example.json\n`
50
- )))
51
- pageConfig = require('../../../example/example.json')
52
- } else {
53
- spinner.text = chalk.cyan(language(
54
- `🤖 Pod 042: 正在上传视觉元数据至司令部进行语义分析...\n`,
55
- `🤖 Pod 042: Uploading visual metadata to Command for semantic analysis...\n`
56
- ))
57
- pageConfig = await recognizePage({ prompt: pagePrompt, filePath })
58
- }
59
-
60
- fs.writeFileSync(path.join(targetDir, 'resource.js'), resource({ pageConfig }))
61
- fs.writeFileSync(path.join(targetDir, 'index.js'), index({ fileName, pageConfig }))
62
-
63
- if (!menus.find(m => m.key === fileName)) {
64
- menus.push({ label: fileName, key: fileName })
65
- }
66
-
67
- if (needMock) {
68
- spinner.text = chalk.yellow(language(
69
- `🧑‍💻 9S: 正在突破目标防火墙... 执行数据伪装程序 [${fileName}]`,
70
- `🧑‍💻 9S: Piercing target firewall... Executing data camouflage [${fileName}]`
71
- ))
72
- const rawContent = await generateMock({ columns: pageConfig.table.columns, fileName })
73
- fs.writeFileSync(path.join(mockDir, `${fileName}.js`), `export default ${contextStringify({ context: rawContent })}`)
74
- console.log(chalk.green(language(
75
- `\n[Success] 9S 报告: Mock 数据生成成功`,
76
- `\n[Success] 9S Report: Mock data generation successful.`
77
- )))
78
- }
79
-
80
- const endTime = Date.now()
81
- spinner.succeed(chalk.green(language(
82
- `🤖 Pod 042: [报告] 构筑协议执行完毕。模块 [${fileName}] 物理装配达成。耗时: ${(endTime - startTime) / 1000}s`,
83
- `🤖 Pod 042: [Report] Protocol complete. Physical assembly of [${fileName}] achieved. Elapsed: ${(endTime - startTime) / 1000}s`
84
- )))
85
-
86
- if (fs.existsSync(filePath)) {
87
- fs.unlinkSync(filePath)
88
- }
89
-
90
- } catch (error) {
91
- spinner.fail(chalk.red(language(
92
- `🤖 Pod 042: [警告] 构筑中断。检测到逻辑病毒或连接超时:${error}`,
93
- `🤖 Pod 042: [Warning] Construction aborted. Logic virus or timeout detected: ${error}`
94
- )))
95
- }
96
- }
@@ -1,77 +0,0 @@
1
- module.exports = async filePath => {
2
-
3
- const fs = require('fs')
4
- const ora = require('ora')
5
- const chalk = require('chalk')
6
-
7
- const {
8
- language,
9
- partPrompt,
10
- recognizePage,
11
- contextStringify,
12
- cleanCode, formatFormItemAndColumns,
13
- } = require('../../core/context').get()
14
-
15
- const startTime = Date.now()
16
-
17
- const spinner = ora({
18
- text: chalk.cyan(language(
19
- `[System] 侦测到局部视觉样本。正在执行“碎片构筑协议”...`,
20
- `[System] Partial visual sample detected. Executing 'Fragment Construction Protocol'...`
21
- )),
22
- color: 'cyan'
23
- }).start()
24
-
25
- try {
26
- spinner.text = chalk.cyan(language(
27
- `🤖 Pod 042: 正在从神经云网络提取 UI 元数据...\n`,
28
- `🤖 Pod 042: Extracting UI metadata from neural cloud network...\n`
29
- ))
30
-
31
- const pageConfig = await recognizePage({ prompt: partPrompt, filePath, taskType: 'part' })
32
-
33
- const { formItems, dictBlocks, processedColumns } = formatFormItemAndColumns({ pageConfig })
34
-
35
- const result = Object.fromEntries(Object.entries({ formItems, processedColumns }).filter(([key, value]) => value?.length > 0))
36
-
37
- let mainConfigStr = cleanCode(contextStringify({ context: result }))
38
-
39
- let optionsCodeStr = ''
40
- dictBlocks.forEach(key => {
41
- const optionsArray = pageConfig.optionDict?.[key] ?? []
42
- const arrayItemsStr = optionsArray.map(opt => ` { label: '${opt.label}', value: '${opt.value}' }`).join(',\n')
43
- optionsCodeStr += `\nexport const ${key} = [\n${arrayItemsStr}\n]\n`
44
- })
45
-
46
- const finalResult = `${mainConfigStr}\n${optionsCodeStr}`
47
- const endTime = Date.now()
48
-
49
- spinner.stop()
50
-
51
- console.log(chalk.magenta(`\n┌────────────────── [ YoRHa Construction Output ] ──────────────────┐`))
52
- console.log(chalk.gray(`│ Source: ${filePath}`))
53
- console.log(chalk.gray(`│ Protocol: Partial UI Fragment | Status: SUCCESS`))
54
- console.log(chalk.magenta(`├────────────────────────────────────────────────────────────────────┘`))
55
- console.log(chalk.white(finalResult))
56
- console.log(chalk.magenta(`┌────────────────────────────────────────────────────────────────────┐`))
57
- console.log(chalk.green(language(
58
- `│ 🤖 Pod 042 报告:局部构筑达成。耗时: ${(endTime - startTime) / 1000}s`,
59
- `│ 🤖 Pod 042 Report: Partial construction achieved. Elapsed: ${(endTime - startTime) / 1000}s`
60
- )))
61
- console.log(chalk.green(language(
62
- `│ 命令:请手动将上述代码块物理装配至您的目标文件中。`,
63
- `│ Command: Please manually assemble the above code block into your target file.`
64
- )))
65
- console.log(chalk.magenta(`└───────────────────────────────────────────────────────────────────┘\n`))
66
-
67
- if (fs.existsSync(filePath)) {
68
- fs.unlinkSync(filePath)
69
- }
70
-
71
- } catch (error) {
72
- spinner.fail(chalk.red(language(
73
- `🤖 Pod 042: [警告] 碎片构筑失败。系统检测到逻辑干扰:${error}`,
74
- `🤖 Pod 042: [Warning] Fragment construction failed. Logic interference detected: ${error}`
75
- )))
76
- }
77
- }
@@ -1,93 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const chalk = require('chalk')
4
- const OpenAI = require('openai')
5
- const Handlebars = require('handlebars')
6
- const stringify = require('json-stringify-pretty-compact')
7
-
8
- const contextStringify = ({ context, indent = 4, maxLength = 200 }) => stringify.default(context, { indent, maxLength })
9
-
10
- Handlebars.registerHelper('raw', opt => opt.fn())
11
- Handlebars.registerHelper('stringify', (context, maxLength = 200) => context ? new Handlebars.SafeString(contextStringify({ context, maxLength })) : '[]')
12
-
13
- let instance = null
14
-
15
- module.exports = {
16
-
17
- init: options => {
18
-
19
- const template = options.template
20
- const uxCtx = require('../utils/ux')
21
- const coreCtx = require('../utils/core')
22
- const infrastructureCtx = require('../utils/infrastructure')
23
-
24
- const { language } = uxCtx
25
- const { getConfig, getExistingMenus } = infrastructureCtx
26
-
27
- const config = getConfig()
28
- const { hbsDir } = config
29
-
30
- const menus = getExistingMenus()
31
- const apiHandler = require('../commands/handlers/api-handler')
32
- const pageHandler = require('../commands/handlers/page-handler')
33
- const partHandler = require('../commands/handlers/part-handler')
34
- const tplDir = hbsDir !== '' ? path.join(process.cwd(), hbsDir) : path.join(__dirname, `../../templates/${template}`)
35
-
36
- const compilerPath = path.join(__dirname, `./${template}-compiler.js`)
37
- if (!fs.existsSync(compilerPath)) {
38
- console.error(chalk.red(language(`❌ 暂不支持 [${template}] 框架。欢迎提交 Pull Request 贡献。`, `❌ [${template}] framework not supported. Welcome to contribute a Pull Request to help.`)))
39
- return
40
- }
41
-
42
- const partialsDir = hbsDir !== '' ? path.join(process.cwd(), hbsDir, 'handlebars') : path.join(__dirname, `../../templates/${template}/handlebars`)
43
- fs.readdirSync(partialsDir).forEach(file => {
44
- if (file.endsWith('.hbs')) {
45
- const name = path.basename(file, '.hbs') // 去掉后缀拿名字
46
- const content = fs.readFileSync(path.join(partialsDir, file), 'utf-8')
47
- Handlebars.registerPartial(name, `${content}\n`)
48
- }
49
- })
50
-
51
- const promptCtx = {
52
- mockPrompt: require(`../prompts/mock.js`),
53
- sysPrompt: require(`../prompts/system.js`),
54
- apiPrompt: require(`../prompts/${template}/watch-api.js`),
55
- pagePrompt: require(`../prompts/${template}/watch-page.js`),
56
- partPrompt: require(`../prompts/${template}/watch-part.js`),
57
- linkerPrompt: require(`../prompts/${template}/api-linker.js`),
58
- }
59
-
60
- const hbsTplCtx = {
61
- indexTpl: Handlebars.compile(fs.readFileSync(path.join(tplDir, 'index.hbs'), 'utf-8')),
62
- resourceTpl: Handlebars.compile(fs.readFileSync(path.join(tplDir, 'resource.hbs'), 'utf-8')),
63
- }
64
-
65
- const pkgEnv = path.resolve(__dirname, '../.env')
66
- const localEnv = path.resolve(process.cwd(), '.env')
67
- require('dotenv').config({ path: fs.existsSync(localEnv) ? localEnv : pkgEnv })
68
- const openAI = new OpenAI({ apiKey: process.env.API_KEY, baseURL: process.env.BASE_URL })
69
-
70
- const cliCtx = { options }
71
- const handlerCtx = { apiHandler, pageHandler, partHandler }
72
- const finalInfrastructureCtx = { menus, config, ...infrastructureCtx }
73
- const llmCtx = require('../services/llm')({ config, openAI, template, ...promptCtx })
74
- const compileCtx = require(compilerPath)({ config, contextStringify, ...coreCtx, ...hbsTplCtx })
75
-
76
- instance = {
77
- openAI,
78
- ...uxCtx,
79
- ...cliCtx,
80
- ...llmCtx,
81
- ...coreCtx,
82
- ...promptCtx,
83
- ...hbsTplCtx,
84
- ...handlerCtx,
85
- ...compileCtx,
86
- contextStringify,
87
- ...finalInfrastructureCtx,
88
- }
89
- return instance
90
- },
91
-
92
- get: () => instance
93
- }