pm-orchestrator-enhancement
Version:
PM Orchestrator Enhancement - Multi-agent parallel execution system
208 lines • 6.72 kB
JavaScript
;
/**
* Workflow Loader Module
*
* 設定ファイルの読み込み、パース、バリデーションを行います。
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkflowLoader = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const yaml = __importStar(require("js-yaml"));
const workflow_config_1 = require("./workflow-config");
class WorkflowLoader {
constructor() {
this.config = null;
}
/**
* ワークフロー設定ファイルを読み込む
*/
async loadFromFile(filePath) {
const absolutePath = path.resolve(filePath);
if (!fs.existsSync(absolutePath)) {
throw new Error(`Workflow config file not found: ${absolutePath}`);
}
const content = fs.readFileSync(absolutePath, 'utf-8');
const ext = path.extname(filePath).toLowerCase();
if (ext === '.yaml' || ext === '.yml') {
this.config = yaml.load(content);
}
else if (ext === '.json') {
this.config = JSON.parse(content);
}
else {
throw new Error(`Unsupported file format: ${ext}. Use .yaml, .yml, or .json`);
}
if (!this.config) {
throw new Error('Failed to load workflow config');
}
this.validateConfig(this.config);
return this.config;
}
/**
* デフォルトワークフローを読み込む
*/
loadDefault() {
this.config = {
workflows: workflow_config_1.DEFAULT_WORKFLOWS,
defaults: {
timeout: 3600000,
maxConcurrency: 3,
retryOnError: true
}
};
return this.config;
}
/**
* 設定をバリデーション
*/
validateConfig(config) {
if (!config.workflows || !Array.isArray(config.workflows)) {
throw new Error('Invalid workflow config: "workflows" must be an array');
}
for (const workflow of config.workflows) {
this.validateWorkflow(workflow);
}
}
/**
* 個別ワークフローをバリデーション
*/
validateWorkflow(workflow) {
if (!workflow.name) {
throw new Error('Workflow must have a name');
}
if (!workflow.pattern) {
throw new Error(`Workflow "${workflow.name}" must have a pattern`);
}
if (!workflow.steps || !Array.isArray(workflow.steps) || workflow.steps.length === 0) {
throw new Error(`Workflow "${workflow.name}" must have at least one step`);
}
const validAgents = [
'pm-orchestrator',
'rule-checker',
'code-analyzer',
'designer',
'implementer',
'tester',
'qa',
'cicd-engineer',
'reporter'
];
for (const step of workflow.steps) {
if (!step.agent) {
throw new Error(`Step in workflow "${workflow.name}" must have an agent`);
}
if (!validAgents.includes(step.agent)) {
throw new Error(`Invalid agent "${step.agent}" in workflow "${workflow.name}". ` +
`Valid agents: ${validAgents.join(', ')}`);
}
}
}
/**
* ユーザー入力にマッチするワークフローを検索
*/
findMatchingWorkflow(userInput) {
if (!this.config) {
this.loadDefault();
}
for (const workflow of this.config.workflows) {
if (this.matchesPattern(userInput, workflow.pattern)) {
return workflow;
}
}
return null;
}
/**
* パターンマッチング
*/
matchesPattern(input, pattern) {
if (typeof pattern === 'string') {
return input.toLowerCase().includes(pattern.toLowerCase());
}
else {
return pattern.test(input);
}
}
/**
* 全ワークフローを取得
*/
getAllWorkflows() {
if (!this.config) {
this.loadDefault();
}
return this.config.workflows;
}
/**
* デフォルト設定を取得
*/
getDefaults() {
if (!this.config) {
this.loadDefault();
}
return this.config.defaults || {
timeout: 3600000,
maxConcurrency: 3,
retryOnError: true
};
}
/**
* 設定をYAML形式で保存
*/
async saveToFile(filePath, format = 'yaml') {
if (!this.config) {
throw new Error('No config loaded');
}
const absolutePath = path.resolve(filePath);
const dir = path.dirname(absolutePath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
let content;
if (format === 'yaml') {
content = yaml.dump(this.config, {
indent: 2,
lineWidth: 100,
noRefs: true
});
}
else {
content = JSON.stringify(this.config, null, 2);
}
fs.writeFileSync(absolutePath, content, 'utf-8');
}
}
exports.WorkflowLoader = WorkflowLoader;
//# sourceMappingURL=workflow-loader.js.map