bada-terminal / src /db /default-samples-loader.js
VanyaJ's picture
Release BADA Terminal v2.1.0 (Enterprise Ontology, NVIDIA auto-ontology, Release Preflight)
d739b1b verified
Raw History Blame Contribute Delete
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
};