Download src/db/default-samples-loader.js from VanyaJ/bada-terminal: direct link, hf CLI and curl.
- Browser
- Download file 10.2 kB
-
https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/db/default-samples-loader.js
- Command line
-
hf download hf://VanyaJ/bada-terminal/src/db/default-samples-loader.js
-
curl -L -o default-samples-loader.js https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/db/default-samples-loader.js
10.2 kB
| const fs = require('fs'); | |
| const path = require('path'); | |
| /** | |
| * Inserts default samples (harnesses, batch tasks, and workflows) into the database. | |
| * @param {string} projectId | |
| * @param {object} dbInstance The database instance (SqliteDb or JsonFallbackDb) | |
| */ | |
| function insertDefaultSamples(projectId, dbInstance) { | |
| const isPackaged = (() => { | |
| try { | |
| const { app } = require('electron'); | |
| return app && app.isPackaged; | |
| } catch (e) { | |
| return false; | |
| } | |
| })(); | |
| if (process.env.SKIP_DEFAULT_SAMPLES || isPackaged || process.env.NODE_ENV === 'production') { | |
| return; | |
| } | |
| if (!dbInstance) { | |
| console.error('[DefaultSamplesLoader] Cannot insert samples: dbInstance is undefined'); | |
| return; | |
| } | |
| // 1. ํ๋ค์ค ์ํ 3์ข | |
| const harnesses = [ | |
| { | |
| id: 'cell-design-lint', | |
| name: '์ ์ค๊ณ ์ ์ ๋ฆฐํฐ ๊ฒ์ฆ', | |
| description: '๋ฐฐํฐ๋ฆฌ anode/cathode ๋ ์ํผ ์ค์ ๋ฐ ๋๊ป ๋ฒ์(0.05 ~ 0.15mm) ๋ฑ ๋ฌผ๋ฆฌ ์คํ ๊ธฐ๋ณธ ๊ท์น ์๋ฐ ์ฌ๋ถ๋ฅผ ๊ฒ์ฆํ๋ ๋ฆฐํฐ ์คํฌ๋ฆฝํธ์ ๋๋ค.', | |
| validation_command: 'npm run lint', | |
| max_retries: 3, | |
| trigger_pattern: 'src/**/*.js', | |
| success_criteria: '{"regex_match": "PASS"}', | |
| tool_chain: '["node", "npm"]' | |
| }, | |
| { | |
| id: 'battery-spec-test', | |
| name: '๋ฐฐํฐ๋ฆฌ ์ฉ๋ ์๋ฎฌ๋ ์ดํฐ ๊ฒ์ฆ', | |
| description: '์ค๊ณ๋ ๋ฐฐํฐ๋ฆฌ ์ ์ฌ์์ ๋ํ ์๋์ง ๋ฐ๋(Wh/kg) ๋ฐ ์๋ช ์์ธก ๊ฒ์ฆ์ฉ ๋จ์ ํ ์คํธ๋ฅผ ๊ฐ๋ํฉ๋๋ค.', | |
| validation_command: 'npm test', | |
| max_retries: 5, | |
| trigger_pattern: 'tests/**/*.js', | |
| success_criteria: '{"regex_match": "OK"}', | |
| tool_chain: '["node", "npm"]' | |
| }, | |
| { | |
| id: 'integrity-config-validator', | |
| name: '๋ฌด๊ฒฐ์ฑ ์ค์ ํ์ผ ๊ฒ์ฆ', | |
| description: 'ํ๋ก์ ํธ ๋ด ์ฃผ์ ํ๊ฒฝ ๋ณ์ ๋ฐ ์ค์ ์ฌ์ ๋ฐ์ดํฐ ํ์ผ(JSON)์ ์คํค๋ง ๊ตฌ์กฐ ์ ํฉ์ฑ์ ๊ฒ์ฆํฉ๋๋ค.', | |
| validation_command: 'node scripts/validate-spec.js', | |
| max_retries: 2, | |
| trigger_pattern: 'config/*.json', | |
| success_criteria: '{"regex_match": "valid"}', | |
| tool_chain: '["node"]' | |
| } | |
| ]; | |
| for (const h of harnesses) { | |
| try { | |
| const existing = dbInstance.getHarness(h.id); | |
| if (!existing) { | |
| dbInstance.saveHarness(projectId, h); | |
| } | |
| } catch (e) { | |
| console.error('[SampleHarness] Failed to insert harness sample:', e.message); | |
| } | |
| } | |
| // 2. ๋ฐฐ์น ์์ ์ํ 2์ข | |
| const batchTasks = [ | |
| { | |
| id: 'task_daily_build_and_lint', | |
| name: '๋งค์ผ ๋น๋ ๋ฐ ๋ฆฐํธ ๊ฒ์ฆ', | |
| project_id: projectId, | |
| cron_expr: '0 3 * * *', | |
| is_active: 0, | |
| is_tested_success: 0, | |
| steps_json: JSON.stringify([ | |
| { | |
| id: 'lint', | |
| type: 'cli', | |
| name: '๋ฆฐํธ ๋ถ์ (Mocked)', | |
| config: { command: 'echo "Running mock linter..." && echo "PASS"' }, | |
| on_failure: 'abort' | |
| }, | |
| { | |
| id: 'test', | |
| type: 'cli', | |
| name: '๋จ์ ํ ์คํธ (Mocked)', | |
| config: { command: 'echo "Running mock battery spec tests..." && echo "OK"' }, | |
| on_failure: 'continue' | |
| } | |
| ]) | |
| }, | |
| { | |
| id: 'task_rag_indexing', | |
| name: '์ํค ์จํจ๋ก์ง ์ง์ ์ธ๋ฑ์ฑ ์ค์ผ์ค', | |
| project_id: projectId, | |
| cron_expr: '0 1 * * *', | |
| is_active: 0, | |
| is_tested_success: 0, | |
| steps_json: JSON.stringify([ | |
| { | |
| id: 'wiki_index', | |
| type: 'cli', | |
| name: '์ํค ์์ธ ๋น๋ (Mocked)', | |
| config: { command: 'echo "Building project ontology graph..." && echo "Done"' }, | |
| on_failure: 'abort' | |
| } | |
| ]) | |
| } | |
| ]; | |
| for (const t of batchTasks) { | |
| try { | |
| const tasks = dbInstance.getBatchTasks(projectId); | |
| const existing = tasks ? tasks.find(x => x.id === t.id) : null; | |
| if (!existing) { | |
| dbInstance.saveBatchTask(projectId, t); | |
| } | |
| } catch (e) { | |
| console.error('[SampleBatch] Failed to insert batch sample:', e.message); | |
| } | |
| } | |
| // 3. ๋ฐฐํฐ๋ฆฌ ์ญ์ค๊ณ ์ค์ผ์คํธ๋ ์ด์ ์ํฌํ๋ก์ฐ ์ํ (Mocked) | |
| const workflowObj = { | |
| id: 'wf_battery_redesign', | |
| name: '๐ ๋ฐฐํฐ๋ฆฌ ์ญ์ค๊ณ ์ค์ผ์คํธ๋ ์ด์ ์ํฌํ๋ก์ฐ (Mocked)', | |
| description: '๋ชฉ์ ๋ชจ๋ธ ๋ฐ ์๋ฎฌ๋ ์ดํฐ API๋ฅผ ์ฐ๋ํ์ฌ ๊ธฐํ ์ฌ์์ ๋ฐ๋ฅธ ์ ๊ทน ๋ ์ํผ ๋ฐ ์ค๊ณ๋ฅผ ๋ฐ๋ณต ๋ฃจํ๋ก ์กฐ์จํ๋ ์์ฌ๊ฒฐ์ ์ธ๊ณผ ์ฒด์ธ ์ํฌํ๋ก์ฐ ์์์ ๋๋ค.', | |
| graph_json: JSON.stringify({ | |
| nodes: [ | |
| { | |
| id: 'input_init', | |
| name: '1. Input Gateway', | |
| type: 'input', | |
| config: { | |
| filePath: 'cell_data.csv', | |
| targetSpec: { energy_density: 250 } | |
| } | |
| }, | |
| { | |
| id: 'cell_gen', | |
| name: '2. Cell Design Sub-Agent', | |
| type: 'agent', | |
| config: { | |
| agentProfileId: 'cell_gen', | |
| prompt: 'Target spec: energy_density={{nodes.input_init.output.targetSpec.energy_density}} Wh/kg. Run mock redesign model and output anode recipe config.' | |
| } | |
| }, | |
| { | |
| id: 'spec_eval', | |
| name: '3. Spec Validator', | |
| type: 'validator', | |
| config: { | |
| target: { | |
| energy_density: { type: 'lower_bound', value: 250 } | |
| }, | |
| predictions: '{{nodes.cell_gen.output.new_cell_design}}' | |
| } | |
| }, | |
| { | |
| id: 'loop_gate', | |
| name: '4. Loop Gate', | |
| type: 'loop', | |
| config: { | |
| overallResult: '{{nodes.spec_eval.output.overallResult}}' | |
| } | |
| } | |
| ], | |
| edges: [ | |
| { source: 'input_init', target: 'cell_gen' }, | |
| { source: 'cell_gen', target: 'spec_eval' }, | |
| { source: 'spec_eval', target: 'loop_gate' } | |
| ] | |
| }) | |
| }; | |
| // 4. ๋ฐฐํฐ๋ฆฌ ๊ณ ๋ํ ์ ์ด ์ํฌํ๋ก์ฐ ์ํ (Mocked) | |
| const workflowAdvancedObj = { | |
| id: 'wf_battery_advanced', | |
| name: '๐ ๋ฐฐํฐ๋ฆฌ ๊ณ ๋ํ ์ ์ด ์ํฌํ๋ก์ฐ (Mocked)', | |
| description: '์กฐ๊ฑด ๋ถ๊ธฐ, ๋ค์ค ์์ด์ ํธ, ๋ฃจํ๋ฐฑ, ๊ทธ๋ฆฌ๊ณ ์ง์ ์์ฑ(๋ณด๊ณ ์/๋ ธํธ) ๋ ธ๋๊ฐ ํฌํจ๋ ๊ณ ๋ํ๋ ์๋ํ ์ต์ ํ ์๋๋ฆฌ์ค์ ๋๋ค.', | |
| graph_json: JSON.stringify({ | |
| nodes: [ | |
| { | |
| id: 'input_init', | |
| name: '1. Input Gateway', | |
| type: 'input', | |
| config: { | |
| filePath: 'cell_data.csv', | |
| targetSpec: { energy_density: 250 } | |
| } | |
| }, | |
| { | |
| id: 'cell_gen', | |
| name: '2. Cell Design Sub-Agent', | |
| type: 'agent', | |
| config: { | |
| agentProfileId: 'cell_gen', | |
| prompt: 'Target spec: energy_density={{nodes.input_init.output.targetSpec.energy_density}} Wh/kg. Run mock redesign model.' | |
| } | |
| }, | |
| { | |
| id: 'spec_eval', | |
| name: '3. Spec Validator', | |
| type: 'validator', | |
| config: { | |
| target: { | |
| energy_density: { type: 'lower_bound', value: 250 } | |
| }, | |
| predictions: '{{nodes.cell_gen.output.new_cell_design}}' | |
| } | |
| }, | |
| { | |
| id: 'temp_check', | |
| name: '4. Temp/Thickness Check (Condition)', | |
| type: 'condition', | |
| config: { | |
| expression: '{{nodes.cell_gen.output.new_cell_design.anode_thickness}} > 0.09', | |
| trueNodeId: 'cooling_gen', | |
| falseNodeId: 'loop_gate' | |
| } | |
| }, | |
| { | |
| id: 'cooling_gen', | |
| name: '5. Cooling Design Sub-Agent', | |
| type: 'agent', | |
| config: { | |
| agentProfileId: 'cooling_agent', | |
| prompt: 'Anode thickness is {{nodes.cell_gen.output.new_cell_design.anode_thickness}} (> 0.09). Design cooling pack.' | |
| } | |
| }, | |
| { | |
| id: 'loop_gate', | |
| name: '6. Loop Gate', | |
| type: 'loop', | |
| config: { | |
| overallResult: '{{nodes.spec_eval.output.overallResult}}', | |
| loopTargetNodeId: 'cell_gen' | |
| } | |
| }, | |
| { | |
| id: 'note_gen', | |
| name: '7. Wiki Knowledge Note Writer', | |
| type: 'note', | |
| config: { | |
| title: '๋ฐฐํฐ๋ฆฌ ์ค๊ณ ์ง์๋ ธํธ - {{runId}}', | |
| tags: ['battery', 'knowledge', 'recipe'], | |
| content: '### ๋ฐฐํฐ๋ฆฌ ์ต์ ํ ์ค๊ณ ์๋ฃ\n- ์๋์ง ๋ฐ๋: {{nodes.cell_gen.output.new_cell_design.energy_density}} Wh/kg\n- ์๊ทน ๋๊ป: {{nodes.cell_gen.output.new_cell_design.anode_thickness}} mm\n- ์ต์ข ํ์ : {{nodes.spec_eval.output.overallResult}}' | |
| } | |
| }, | |
| { | |
| id: 'report_gen', | |
| name: '8. PDF/Markdown Report Generator', | |
| type: 'report', | |
| config: { | |
| filePath: 'wiki/workflows/reports/battery_final_{{runId}}.md', | |
| template: '# ์ต์ข ๋ฐฐํฐ๋ฆฌ ์ต์ ํ ๋ณด๊ณ ์\n\n- Run ID: {{runId}}\n- ์ต์ข ํ์ : {{nodes.spec_eval.output.overallResult}}\n- ์์ธ ์คํ: {{nodes.cell_gen.output.new_cell_design}}' | |
| } | |
| } | |
| ], | |
| edges: [ | |
| { source: 'input_init', target: 'cell_gen' }, | |
| { source: 'cell_gen', target: 'spec_eval' }, | |
| { source: 'spec_eval', target: 'temp_check' }, | |
| { source: 'temp_check', target: 'cooling_gen' }, | |
| { source: 'cooling_gen', target: 'loop_gate' }, | |
| { source: 'temp_check', target: 'loop_gate' }, | |
| { source: 'loop_gate', target: 'note_gen' }, | |
| { source: 'note_gen', target: 'report_gen' }, | |
| { source: 'loop_gate', target: 'cell_gen', loopback: true } | |
| ] | |
| }) | |
| }; | |
| try { | |
| const existing = dbInstance.getWorkflow(workflowObj.id); | |
| if (!existing) { | |
| dbInstance.saveWorkflow(projectId, workflowObj); | |
| } | |
| } catch (e) { | |
| console.error('[SampleWorkflow] Failed to insert workflow sample:', e.message); | |
| } | |
| try { | |
| const existing = dbInstance.getWorkflow(workflowAdvancedObj.id); | |
| if (!existing) { | |
| dbInstance.saveWorkflow(projectId, workflowAdvancedObj); | |
| } | |
| } catch (e) { | |
| console.error('[SampleWorkflow] Failed to insert advanced workflow sample:', e.message); | |
| } | |
| } | |
| module.exports = { | |
| insertDefaultSamples | |
| }; | |