create-byan-agent 2.0.1 → 2.1.1

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 (240) hide show
  1. package/API-BYAN-V2.md +741 -0
  2. package/BMAD-QUICK-REFERENCE.md +370 -0
  3. package/CHANGELOG-v2.1.0.md +371 -0
  4. package/LICENSE +1 -1
  5. package/MIGRATION-v2.0-to-v2.1.md +430 -0
  6. package/README-BYAN-V2.md +446 -0
  7. package/README.md +264 -201
  8. package/install/.eslintrc.js +20 -0
  9. package/install/.prettierrc +7 -0
  10. package/install/BUGFIX-CHALK.md +173 -0
  11. package/install/BUGFIX-DOCUMENTATION-INDEX.md +299 -0
  12. package/install/BUGFIX-PATH-RESOLUTION.md +293 -0
  13. package/install/BUGFIX-QUICKSTART.md +184 -0
  14. package/install/BUGFIX-SUMMARY.txt +91 -0
  15. package/install/BUGFIX-VISUAL-SUMMARY.md +253 -0
  16. package/install/DEPLOYMENT-GUIDE-V2.md +431 -0
  17. package/install/DOCS-INDEX.md +261 -0
  18. package/install/GUIDE-INSTALLATION-BYAN-SIMPLE.md +1083 -0
  19. package/install/INSTALLER-V2-CHANGES.md +472 -0
  20. package/install/LICENSE +21 -0
  21. package/install/PUBLICATION-CHECKLIST.md +265 -0
  22. package/install/PUBLISH-GUIDE.md +190 -0
  23. package/install/QUICKSTART.md +311 -0
  24. package/install/README-NPM-PUBLISH.md +298 -0
  25. package/install/README-NPM-SHORT.md +298 -0
  26. package/install/README-NPM.md +433 -0
  27. package/install/README-RACHID.md +302 -0
  28. package/install/README-V2-INDEX.md +306 -0
  29. package/install/README.md +298 -0
  30. package/install/RESUME-EXECUTIF-YAN.md +408 -0
  31. package/install/UPDATE-SUMMARY.md +205 -0
  32. package/install/__tests__/integration/detection-flow.test.js +154 -0
  33. package/install/__tests__/platforms/claude-code.test.js +175 -0
  34. package/install/__tests__/platforms/codex.test.js +80 -0
  35. package/install/__tests__/platforms/copilot-cli.test.js +118 -0
  36. package/install/__tests__/platforms/vscode.test.js +67 -0
  37. package/install/__tests__/utils/file-utils.test.js +87 -0
  38. package/install/__tests__/utils/git-detector.test.js +80 -0
  39. package/install/__tests__/utils/logger.test.js +83 -0
  40. package/install/__tests__/utils/node-detector.test.js +71 -0
  41. package/install/__tests__/utils/os-detector.test.js +63 -0
  42. package/install/__tests__/utils/yaml-utils.test.js +85 -0
  43. package/install/__tests__/yanstaller/detector.test.js +210 -0
  44. package/install/coverage/clover.xml +219 -0
  45. package/install/coverage/coverage-final.json +13 -0
  46. package/install/coverage/lcov-report/base.css +224 -0
  47. package/install/coverage/lcov-report/block-navigation.js +87 -0
  48. package/install/coverage/lcov-report/favicon.png +0 -0
  49. package/install/coverage/lcov-report/index.html +146 -0
  50. package/install/coverage/lcov-report/lib/errors.js.html +268 -0
  51. package/install/coverage/lcov-report/lib/exit-codes.js.html +247 -0
  52. package/install/coverage/lcov-report/lib/index.html +131 -0
  53. package/install/coverage/lcov-report/lib/platforms/claude-code.js.html +343 -0
  54. package/install/coverage/lcov-report/lib/platforms/codex.js.html +361 -0
  55. package/install/coverage/lcov-report/lib/platforms/copilot-cli.js.html +454 -0
  56. package/install/coverage/lcov-report/lib/platforms/index.html +176 -0
  57. package/install/coverage/lcov-report/lib/platforms/index.js.html +127 -0
  58. package/install/coverage/lcov-report/lib/platforms/vscode.js.html +238 -0
  59. package/install/coverage/lcov-report/lib/utils/config-loader.js.html +322 -0
  60. package/install/coverage/lcov-report/lib/utils/file-utils.js.html +397 -0
  61. package/install/coverage/lcov-report/lib/utils/git-detector.js.html +190 -0
  62. package/install/coverage/lcov-report/lib/utils/index.html +206 -0
  63. package/install/coverage/lcov-report/lib/utils/logger.js.html +277 -0
  64. package/install/coverage/lcov-report/lib/utils/node-detector.js.html +259 -0
  65. package/install/coverage/lcov-report/lib/utils/os-detector.js.html +307 -0
  66. package/install/coverage/lcov-report/lib/utils/yaml-utils.js.html +346 -0
  67. package/install/coverage/lcov-report/lib/yanstaller/backuper.js.html +409 -0
  68. package/install/coverage/lcov-report/lib/yanstaller/detector.js.html +508 -0
  69. package/install/coverage/lcov-report/lib/yanstaller/index.html +236 -0
  70. package/install/coverage/lcov-report/lib/yanstaller/index.js.html +364 -0
  71. package/install/coverage/lcov-report/lib/yanstaller/installer.js.html +505 -0
  72. package/install/coverage/lcov-report/lib/yanstaller/interviewer.js.html +349 -0
  73. package/install/coverage/lcov-report/lib/yanstaller/recommender.js.html +379 -0
  74. package/install/coverage/lcov-report/lib/yanstaller/troubleshooter.js.html +352 -0
  75. package/install/coverage/lcov-report/lib/yanstaller/validator.js.html +679 -0
  76. package/install/coverage/lcov-report/lib/yanstaller/wizard.js.html +412 -0
  77. package/install/coverage/lcov-report/platforms/claude-code.js.html +343 -0
  78. package/install/coverage/lcov-report/platforms/codex.js.html +361 -0
  79. package/install/coverage/lcov-report/platforms/copilot-cli.js.html +454 -0
  80. package/install/coverage/lcov-report/platforms/index.html +176 -0
  81. package/install/coverage/lcov-report/platforms/index.js.html +127 -0
  82. package/install/coverage/lcov-report/platforms/vscode.js.html +238 -0
  83. package/install/coverage/lcov-report/prettify.css +1 -0
  84. package/install/coverage/lcov-report/prettify.js +2 -0
  85. package/install/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  86. package/install/coverage/lcov-report/sorter.js +210 -0
  87. package/install/coverage/lcov-report/utils/file-utils.js.html +397 -0
  88. package/install/coverage/lcov-report/utils/git-detector.js.html +190 -0
  89. package/install/coverage/lcov-report/utils/index.html +191 -0
  90. package/install/coverage/lcov-report/utils/logger.js.html +277 -0
  91. package/install/coverage/lcov-report/utils/node-detector.js.html +259 -0
  92. package/install/coverage/lcov-report/utils/os-detector.js.html +307 -0
  93. package/install/coverage/lcov-report/utils/yaml-utils.js.html +346 -0
  94. package/install/coverage/lcov-report/yanstaller/detector.js.html +508 -0
  95. package/install/coverage/lcov-report/yanstaller/index.html +116 -0
  96. package/install/coverage/lcov.info +414 -0
  97. package/install/install.sh +239 -0
  98. package/install/jest.config.js +33 -0
  99. package/install/lib/errors.js +61 -0
  100. package/install/lib/exit-codes.js +54 -0
  101. package/install/lib/platforms/claude-code.js +86 -0
  102. package/install/lib/platforms/codex.js +92 -0
  103. package/install/lib/platforms/copilot-cli.js +123 -0
  104. package/install/lib/platforms/index.js +14 -0
  105. package/install/lib/platforms/vscode.js +51 -0
  106. package/install/lib/utils/config-loader.js +79 -0
  107. package/install/lib/utils/file-utils.js +104 -0
  108. package/install/lib/utils/git-detector.js +35 -0
  109. package/install/lib/utils/logger.js +64 -0
  110. package/install/lib/utils/node-detector.js +58 -0
  111. package/install/lib/utils/os-detector.js +74 -0
  112. package/install/lib/utils/yaml-utils.js +87 -0
  113. package/install/lib/yanstaller/backuper.js +108 -0
  114. package/install/lib/yanstaller/detector.js +141 -0
  115. package/install/lib/yanstaller/index.js +93 -0
  116. package/install/lib/yanstaller/installer.js +140 -0
  117. package/install/lib/yanstaller/interviewer.js +88 -0
  118. package/install/lib/yanstaller/recommender.js +98 -0
  119. package/install/lib/yanstaller/troubleshooter.js +89 -0
  120. package/install/lib/yanstaller/validator.js +198 -0
  121. package/install/lib/yanstaller/wizard.js +109 -0
  122. package/install/package-npm.json +55 -0
  123. package/install/package.json +63 -0
  124. package/install/src/byan-v2/context/copilot-context.js +79 -0
  125. package/install/src/byan-v2/context/session-state.js +98 -0
  126. package/install/src/byan-v2/dispatcher/complexity-scorer.js +232 -0
  127. package/install/src/byan-v2/dispatcher/local-executor.js +221 -0
  128. package/install/src/byan-v2/dispatcher/task-router.js +122 -0
  129. package/install/src/byan-v2/dispatcher/task-tool-interface-mock.js +134 -0
  130. package/install/src/byan-v2/dispatcher/task-tool-interface.js +123 -0
  131. package/install/src/byan-v2/generation/agent-profile-validator.js +113 -0
  132. package/install/src/byan-v2/generation/profile-template.js +113 -0
  133. package/install/src/byan-v2/generation/templates/default-agent.md +49 -0
  134. package/install/src/byan-v2/generation/templates/test-template.md +1 -0
  135. package/install/src/byan-v2/index.js +199 -0
  136. package/install/src/byan-v2/observability/error-tracker.js +105 -0
  137. package/install/src/byan-v2/observability/logger.js +154 -0
  138. package/install/src/byan-v2/observability/metrics-collector.js +194 -0
  139. package/install/src/byan-v2/orchestrator/analysis-state.js +268 -0
  140. package/install/src/byan-v2/orchestrator/generation-state.js +340 -0
  141. package/install/src/byan-v2/orchestrator/interview-state.js +271 -0
  142. package/install/src/byan-v2/orchestrator/state-machine.js +204 -0
  143. package/install/src/core/cache/cache.js +126 -0
  144. package/install/src/core/context/context.js +86 -0
  145. package/install/src/core/dispatcher/dispatcher.js +135 -0
  146. package/install/src/core/worker-pool/worker-pool.js +194 -0
  147. package/install/src/core/workflow/workflow-executor.js +220 -0
  148. package/install/src/index.js +139 -0
  149. package/install/src/observability/dashboard/dashboard.js +191 -0
  150. package/install/src/observability/logger/structured-logger.js +254 -0
  151. package/install/src/observability/metrics/metrics-collector.js +325 -0
  152. package/install/switch-to-v2.sh +126 -0
  153. package/install/test-chalk-fix.sh +210 -0
  154. package/install/test-installer-v2.sh +204 -0
  155. package/install/test-path-resolution.sh +200 -0
  156. package/package.json +53 -33
  157. package/src/byan-v2/context/copilot-context.js +79 -0
  158. package/src/byan-v2/context/session-state.js +98 -0
  159. package/src/byan-v2/data/mantras.json +852 -0
  160. package/src/byan-v2/dispatcher/complexity-scorer.js +232 -0
  161. package/src/byan-v2/dispatcher/five-whys-analyzer.js +310 -0
  162. package/src/byan-v2/dispatcher/local-executor.js +221 -0
  163. package/src/byan-v2/dispatcher/task-router.js +122 -0
  164. package/src/byan-v2/dispatcher/task-tool-interface-mock.js +134 -0
  165. package/src/byan-v2/dispatcher/task-tool-interface.js +123 -0
  166. package/src/byan-v2/generation/agent-profile-validator.js +113 -0
  167. package/src/byan-v2/generation/mantra-validator.js +416 -0
  168. package/src/byan-v2/generation/profile-template.js +113 -0
  169. package/src/byan-v2/generation/templates/default-agent.md +49 -0
  170. package/src/byan-v2/generation/templates/test-template.md +1 -0
  171. package/src/byan-v2/index.js +652 -0
  172. package/src/byan-v2/integration/voice-integration.js +295 -0
  173. package/src/byan-v2/observability/error-tracker.js +105 -0
  174. package/src/byan-v2/observability/logger.js +154 -0
  175. package/src/byan-v2/observability/metrics-collector.js +194 -0
  176. package/src/byan-v2/orchestrator/active-listener.js +541 -0
  177. package/src/byan-v2/orchestrator/analysis-state.js +268 -0
  178. package/src/byan-v2/orchestrator/generation-state.js +340 -0
  179. package/src/byan-v2/orchestrator/glossary-builder.js +431 -0
  180. package/src/byan-v2/orchestrator/interview-state.js +353 -0
  181. package/src/byan-v2/orchestrator/state-machine.js +253 -0
  182. package/src/core/cache/cache.js +126 -0
  183. package/src/core/context/context.js +86 -0
  184. package/src/core/dispatcher/dispatcher.js +135 -0
  185. package/src/core/worker-pool/worker-pool.js +194 -0
  186. package/src/core/workflow/workflow-executor.js +220 -0
  187. package/src/index.js +139 -0
  188. package/src/observability/dashboard/dashboard.js +191 -0
  189. package/src/observability/logger/structured-logger.js +254 -0
  190. package/src/observability/metrics/metrics-collector.js +325 -0
  191. package/templates/.github/agents/bmad-agent-test-dynamic.md +0 -21
  192. package/templates/.github/agents/franck.md +0 -379
  193. /package/{CHANGELOG.md → install/CHANGELOG.md} +0 -0
  194. /package/{bin → install/bin}/create-byan-agent-backup.js +0 -0
  195. /package/{bin → install/bin}/create-byan-agent-fixed.js +0 -0
  196. /package/{bin → install/bin}/create-byan-agent-v2.js +0 -0
  197. /package/{bin → install/bin}/create-byan-agent.js +0 -0
  198. /package/{templates → install/templates}/.github/agents/bmad-agent-bmad-master.md +0 -0
  199. /package/{templates → install/templates}/.github/agents/bmad-agent-bmb-agent-builder.md +0 -0
  200. /package/{templates → install/templates}/.github/agents/bmad-agent-bmb-module-builder.md +0 -0
  201. /package/{templates → install/templates}/.github/agents/bmad-agent-bmb-workflow-builder.md +0 -0
  202. /package/{templates → install/templates}/.github/agents/bmad-agent-bmm-analyst.md +0 -0
  203. /package/{templates → install/templates}/.github/agents/bmad-agent-bmm-architect.md +0 -0
  204. /package/{templates → install/templates}/.github/agents/bmad-agent-bmm-dev.md +0 -0
  205. /package/{templates → install/templates}/.github/agents/bmad-agent-bmm-pm.md +0 -0
  206. /package/{templates → install/templates}/.github/agents/bmad-agent-bmm-quick-flow-solo-dev.md +0 -0
  207. /package/{templates → install/templates}/.github/agents/bmad-agent-bmm-quinn.md +0 -0
  208. /package/{templates → install/templates}/.github/agents/bmad-agent-bmm-sm.md +0 -0
  209. /package/{templates → install/templates}/.github/agents/bmad-agent-bmm-tech-writer.md +0 -0
  210. /package/{templates → install/templates}/.github/agents/bmad-agent-bmm-ux-designer.md +0 -0
  211. /package/{templates → install/templates}/.github/agents/bmad-agent-byan-test.md +0 -0
  212. /package/{templates → install/templates}/.github/agents/bmad-agent-byan.md +0 -0
  213. /package/{templates → install/templates}/.github/agents/bmad-agent-carmack.md +0 -0
  214. /package/{templates → install/templates}/.github/agents/bmad-agent-cis-brainstorming-coach.md +0 -0
  215. /package/{templates → install/templates}/.github/agents/bmad-agent-cis-creative-problem-solver.md +0 -0
  216. /package/{templates → install/templates}/.github/agents/bmad-agent-cis-design-thinking-coach.md +0 -0
  217. /package/{templates → install/templates}/.github/agents/bmad-agent-cis-innovation-strategist.md +0 -0
  218. /package/{templates → install/templates}/.github/agents/bmad-agent-cis-presentation-master.md +0 -0
  219. /package/{templates → install/templates}/.github/agents/bmad-agent-cis-storyteller.md +0 -0
  220. /package/{templates → install/templates}/.github/agents/bmad-agent-marc.md +0 -0
  221. /package/{templates → install/templates}/.github/agents/bmad-agent-patnote.md +0 -0
  222. /package/{templates → install/templates}/.github/agents/bmad-agent-rachid.md +0 -0
  223. /package/{templates → install/templates}/.github/agents/bmad-agent-tea-tea.md +0 -0
  224. /package/{templates → install/templates}/_bmad/bmb/agents/agent-builder.md +0 -0
  225. /package/{templates → install/templates}/_bmad/bmb/agents/byan-test.md +0 -0
  226. /package/{templates → install/templates}/_bmad/bmb/agents/byan.md +0 -0
  227. /package/{templates → install/templates}/_bmad/bmb/agents/marc.md +0 -0
  228. /package/{templates → install/templates}/_bmad/bmb/agents/module-builder.md +0 -0
  229. /package/{templates → install/templates}/_bmad/bmb/agents/patnote.md +0 -0
  230. /package/{templates → install/templates}/_bmad/bmb/agents/rachid.md +0 -0
  231. /package/{templates → install/templates}/_bmad/bmb/agents/workflow-builder.md +0 -0
  232. /package/{templates → install/templates}/_bmad/bmb/workflows/byan/data/mantras.yaml +0 -0
  233. /package/{templates → install/templates}/_bmad/bmb/workflows/byan/data/templates.yaml +0 -0
  234. /package/{templates → install/templates}/_bmad/bmb/workflows/byan/delete-agent-workflow.md +0 -0
  235. /package/{templates → install/templates}/_bmad/bmb/workflows/byan/edit-agent-workflow.md +0 -0
  236. /package/{templates → install/templates}/_bmad/bmb/workflows/byan/interview-workflow.md +0 -0
  237. /package/{templates → install/templates}/_bmad/bmb/workflows/byan/quick-create-workflow.md +0 -0
  238. /package/{templates → install/templates}/_bmad/bmb/workflows/byan/templates/base-agent-template.md +0 -0
  239. /package/{templates → install/templates}/_bmad/bmb/workflows/byan/validate-agent-workflow.md +0 -0
  240. /package/{templates → install/templates}/_bmad/core/agents/carmack.md +0 -0
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Worker for executing tasks asynchronously
3
+ * Represents a single worker in the pool
4
+ *
5
+ * @class Worker
6
+ */
7
+ class Worker {
8
+ /**
9
+ * Create a new Worker
10
+ * @param {number} id - Unique worker identifier
11
+ */
12
+ constructor(id) {
13
+ this.id = id;
14
+ this.status = 'idle'; // idle, busy, error
15
+ this.currentTask = null;
16
+ }
17
+
18
+ /**
19
+ * Execute a task
20
+ * @param {Function|object} task - Task to execute (function or object with execute method)
21
+ * @returns {Promise<*>} Task result
22
+ */
23
+ async execute(task) {
24
+ this.status = 'busy';
25
+ this.currentTask = task;
26
+
27
+ try {
28
+ let result;
29
+
30
+ if (typeof task === 'function') {
31
+ result = await task();
32
+ } else if (task && typeof task.execute === 'function') {
33
+ result = await task.execute();
34
+ } else {
35
+ throw new Error('Task must be a function or have an execute method');
36
+ }
37
+
38
+ this.status = 'idle';
39
+ this.currentTask = null;
40
+ return result;
41
+ } catch (error) {
42
+ this.status = 'error';
43
+ this.currentTask = null;
44
+ throw error;
45
+ }
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Worker Pool for managing parallel task execution
51
+ * Provides a pool of workers with automatic task queuing
52
+ *
53
+ * @class WorkerPool
54
+ * @example
55
+ * const pool = new WorkerPool(3);
56
+ * const result = await pool.submitTask(async () => { return 'done'; });
57
+ */
58
+ class WorkerPool {
59
+ /**
60
+ * Create a new WorkerPool
61
+ * @param {number} maxWorkers - Maximum number of concurrent workers
62
+ * @throws {Error} If maxWorkers is not a positive number
63
+ */
64
+ constructor(maxWorkers = 4) {
65
+ if (typeof maxWorkers !== 'number' || maxWorkers < 1) {
66
+ throw new Error('maxWorkers must be a positive number');
67
+ }
68
+
69
+ this.maxWorkers = maxWorkers;
70
+ this.workers = [];
71
+ this.taskQueue = [];
72
+ this.activeTasks = 0;
73
+ this.isShutdown = false;
74
+
75
+ // Initialize workers
76
+ for (let i = 0; i < maxWorkers; i++) {
77
+ this.workers.push(new Worker(i));
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Submit a task to the pool
83
+ * @param {Function|object} task - Task to execute
84
+ * @returns {Promise<*>} Promise that resolves with task result
85
+ */
86
+ submitTask(task) {
87
+ if (this.isShutdown) {
88
+ return Promise.reject(new Error('Worker pool is shutdown'));
89
+ }
90
+
91
+ return new Promise((resolve, reject) => {
92
+ this.taskQueue.push({ task, resolve, reject });
93
+ this._processQueue();
94
+ });
95
+ }
96
+
97
+ /**
98
+ * Process the task queue
99
+ * @private
100
+ */
101
+ async _processQueue() {
102
+ // Find an idle worker
103
+ const idleWorker = this.workers.find(w => w.status === 'idle');
104
+
105
+ if (!idleWorker || this.taskQueue.length === 0) {
106
+ return;
107
+ }
108
+
109
+ const { task, resolve, reject } = this.taskQueue.shift();
110
+ this.activeTasks++;
111
+
112
+ try {
113
+ const result = await idleWorker.execute(task);
114
+ this.activeTasks--;
115
+ resolve(result);
116
+
117
+ // Process next task if any
118
+ if (this.taskQueue.length > 0) {
119
+ this._processQueue();
120
+ }
121
+ } catch (error) {
122
+ this.activeTasks--;
123
+ reject(error);
124
+
125
+ // Reset worker to idle on error
126
+ idleWorker.status = 'idle';
127
+
128
+ // Continue processing queue
129
+ if (this.taskQueue.length > 0) {
130
+ this._processQueue();
131
+ }
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Get number of active workers
137
+ * @returns {number} Number of busy workers
138
+ */
139
+ getActiveWorkers() {
140
+ return this.workers.filter(w => w.status === 'busy').length;
141
+ }
142
+
143
+ /**
144
+ * Get number of idle workers
145
+ * @returns {number} Number of idle workers
146
+ */
147
+ getIdleWorkers() {
148
+ return this.workers.filter(w => w.status === 'idle').length;
149
+ }
150
+
151
+ /**
152
+ * Get current queue size
153
+ * @returns {number} Number of queued tasks
154
+ */
155
+ getQueueSize() {
156
+ return this.taskQueue.length;
157
+ }
158
+
159
+ /**
160
+ * Get pool statistics
161
+ * @returns {object} Pool statistics
162
+ */
163
+ getStats() {
164
+ return {
165
+ totalWorkers: this.workers.length,
166
+ activeWorkers: this.getActiveWorkers(),
167
+ idleWorkers: this.getIdleWorkers(),
168
+ queueSize: this.getQueueSize(),
169
+ activeTasks: this.activeTasks
170
+ };
171
+ }
172
+
173
+ /**
174
+ * Shutdown the pool gracefully
175
+ * Waits for active tasks to complete
176
+ * @returns {Promise<void>}
177
+ */
178
+ async shutdown() {
179
+ this.isShutdown = true;
180
+
181
+ // Wait for all active tasks to complete
182
+ while (this.activeTasks > 0) {
183
+ await new Promise(resolve => setTimeout(resolve, 10));
184
+ }
185
+
186
+ // Clear queue and reject pending tasks
187
+ while (this.taskQueue.length > 0) {
188
+ const { reject } = this.taskQueue.shift();
189
+ reject(new Error('Worker pool shutdown'));
190
+ }
191
+ }
192
+ }
193
+
194
+ module.exports = { WorkerPool, Worker };
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Workflow Executor for BYAN v2.0
3
+ * Executes declarative YAML workflows with sequential step execution
4
+ *
5
+ * @module core/workflow/workflow-executor
6
+ * @version 2.0.0-HYPER-MVP
7
+ */
8
+
9
+ /**
10
+ * Workflow Executor - Orchestrates multi-step workflows
11
+ *
12
+ * @class WorkflowExecutor
13
+ * @example
14
+ * const executor = new WorkflowExecutor();
15
+ * const result = await executor.executeWorkflow(workflow);
16
+ */
17
+ class WorkflowExecutor {
18
+ constructor() {
19
+ this.currentWorkflow = null;
20
+ this.status = 'idle';
21
+ this.results = [];
22
+ this.isPaused = false;
23
+ }
24
+
25
+ /**
26
+ * Execute a workflow with sequential steps
27
+ *
28
+ * @param {Object} workflow - Workflow configuration
29
+ * @param {string} workflow.name - Workflow name
30
+ * @param {Array<Object>} workflow.steps - Array of steps
31
+ * @returns {Promise<Object>} Execution result
32
+ *
33
+ * @example
34
+ * const result = await executor.executeWorkflow({
35
+ * name: 'test-workflow',
36
+ * steps: [
37
+ * { id: 'step1', action: 'task1' },
38
+ * { id: 'step2', action: 'task2' }
39
+ * ]
40
+ * });
41
+ */
42
+ async executeWorkflow(workflow) {
43
+ if (!workflow) {
44
+ throw new Error('Workflow is required');
45
+ }
46
+
47
+ if (!workflow.name) {
48
+ throw new Error('Workflow name is required');
49
+ }
50
+
51
+ if (!Array.isArray(workflow.steps) || workflow.steps.length === 0) {
52
+ throw new Error('Workflow must have at least one step');
53
+ }
54
+
55
+ this.currentWorkflow = workflow;
56
+ this.status = 'running';
57
+ this.results = [];
58
+ this.isPaused = false;
59
+
60
+ const startTime = Date.now();
61
+ let stepsCompleted = 0;
62
+ let hasError = false;
63
+
64
+ try {
65
+ for (const step of workflow.steps) {
66
+ if (this.isPaused) {
67
+ this.status = 'paused';
68
+ return {
69
+ success: false,
70
+ paused: true,
71
+ stepsCompleted,
72
+ message: 'Workflow paused',
73
+ };
74
+ }
75
+
76
+ // Validate step
77
+ if (!step.id) {
78
+ throw new Error('Step id is required');
79
+ }
80
+
81
+ // Execute step (stub simulation)
82
+ const stepStartTime = Date.now();
83
+ const stepResult = await this._executeStep(step);
84
+ const stepDuration = Date.now() - stepStartTime;
85
+
86
+ this.results.push({
87
+ stepId: step.id,
88
+ action: step.action,
89
+ duration: stepDuration,
90
+ result: stepResult,
91
+ timestamp: new Date().toISOString(),
92
+ });
93
+
94
+ stepsCompleted++;
95
+ }
96
+
97
+ const totalDuration = Date.now() - startTime;
98
+ this.status = 'completed';
99
+
100
+ return {
101
+ success: true,
102
+ workflowName: workflow.name,
103
+ stepsCompleted,
104
+ totalSteps: workflow.steps.length,
105
+ duration: totalDuration,
106
+ results: this.results,
107
+ timestamp: new Date().toISOString(),
108
+ };
109
+
110
+ } catch (error) {
111
+ this.status = 'error';
112
+ hasError = true;
113
+
114
+ return {
115
+ success: false,
116
+ workflowName: workflow.name,
117
+ stepsCompleted,
118
+ totalSteps: workflow.steps.length,
119
+ error: error.message,
120
+ results: this.results,
121
+ };
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Execute a single step (stub implementation)
127
+ *
128
+ * @private
129
+ * @param {Object} step - Step configuration
130
+ * @returns {Promise<Object>} Step result
131
+ */
132
+ async _executeStep(step) {
133
+ // Simulate async execution
134
+ await new Promise((resolve) => setTimeout(resolve, 10));
135
+
136
+ return {
137
+ status: 'completed',
138
+ action: step.action,
139
+ output: `Result of ${step.action}`,
140
+ };
141
+ }
142
+
143
+ /**
144
+ * Get current execution status
145
+ *
146
+ * @returns {Object} Status information
147
+ *
148
+ * @example
149
+ * const status = executor.getExecutionStatus();
150
+ * console.log(status.status); // 'idle' | 'running' | 'paused' | 'completed' | 'error'
151
+ */
152
+ getExecutionStatus() {
153
+ return {
154
+ status: this.status,
155
+ currentWorkflow: this.currentWorkflow?.name || null,
156
+ stepsCompleted: this.results.length,
157
+ totalSteps: this.currentWorkflow?.steps?.length || 0,
158
+ isPaused: this.isPaused,
159
+ };
160
+ }
161
+
162
+ /**
163
+ * Pause workflow execution
164
+ *
165
+ * @returns {void}
166
+ *
167
+ * @example
168
+ * executor.pause();
169
+ */
170
+ pause() {
171
+ if (this.status === 'running') {
172
+ this.isPaused = true;
173
+ this.status = 'paused';
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Resume workflow execution
179
+ *
180
+ * @returns {void}
181
+ *
182
+ * @example
183
+ * executor.resume();
184
+ */
185
+ resume() {
186
+ if (this.status === 'paused') {
187
+ this.isPaused = false;
188
+ this.status = 'running';
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Get workflow execution results
194
+ *
195
+ * @returns {Array<Object>} Array of step results
196
+ *
197
+ * @example
198
+ * const results = executor.getResults();
199
+ * results.forEach(result => {
200
+ * console.log(`Step ${result.stepId}: ${result.result.status}`);
201
+ * });
202
+ */
203
+ getResults() {
204
+ return [...this.results];
205
+ }
206
+
207
+ /**
208
+ * Reset executor to initial state
209
+ *
210
+ * @returns {void}
211
+ */
212
+ reset() {
213
+ this.currentWorkflow = null;
214
+ this.status = 'idle';
215
+ this.results = [];
216
+ this.isPaused = false;
217
+ }
218
+ }
219
+
220
+ module.exports = { WorkflowExecutor };
@@ -0,0 +1,139 @@
1
+ /**
2
+ * BYAN v2.0 - Entry Point
3
+ *
4
+ * Architecture 4 Pilliers:
5
+ * - Agent: Expertise (modèles puissants)
6
+ * - Context: State management hiérarchique
7
+ * - Workflow: Orchestration déclarative
8
+ * - Worker: Exécution simple (modèles légers)
9
+ *
10
+ * @module byan-v2
11
+ * @version 2.0.0-alpha.1
12
+ */
13
+
14
+ // Core Components
15
+ const ContextLayer = require('./core/context/context');
16
+ const SimpleCache = require('./core/cache/cache');
17
+ const EconomicDispatcher = require('./core/dispatcher/dispatcher');
18
+ const { WorkerPool, Worker } = require('./core/worker-pool/worker-pool');
19
+ const { WorkflowExecutor } = require('./core/workflow/workflow-executor');
20
+
21
+ // Observability Components
22
+ const { StructuredLogger } = require('./observability/logger/structured-logger');
23
+ const { MetricsCollector } = require('./observability/metrics/metrics-collector');
24
+ const { printDashboard, generateSummary } = require('./observability/dashboard/dashboard');
25
+
26
+ // Dashboard wrapper class for easy integration
27
+ class Dashboard {
28
+ constructor(metrics, logger = null, workerPool = null) {
29
+ this.metrics = metrics;
30
+ this.logger = logger;
31
+ this.workerPool = workerPool;
32
+ }
33
+
34
+ render() {
35
+ return printDashboard({
36
+ metrics: this.metrics.getMetrics(),
37
+ logs: this.logger ? this.logger.getLogs() : [],
38
+ workers: this.workerPool ? this.workerPool.workers.map((w, i) => ({ id: w.id, status: w.status })) : [],
39
+ status: { version: '2.0.0-alpha.1' }
40
+ });
41
+ }
42
+
43
+ renderSummary() {
44
+ return generateSummary({
45
+ metrics: this.metrics.getStats ? this.metrics.getStats() : {},
46
+ logs: this.logger ? this.logger.getStats() : {}
47
+ });
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Factory function pour initialiser BYAN v2.0
53
+ *
54
+ * @param {Object} [options={}] - Options de configuration
55
+ * @param {number} [options.workerCount=2] - Nombre de workers
56
+ * @param {number} [options.cacheMaxSize=50] - Taille max cache (MB)
57
+ * @param {Object} [options.loggerOptions] - Options pour logger
58
+ * @returns {Object} Instance BYAN v2.0 configurée
59
+ *
60
+ * @example
61
+ * const byan = createByanInstance({ workerCount: 2 });
62
+ * await byan.executeWorkflow('_bmad/workflows/create-prd/workflow.yaml');
63
+ */
64
+ function createByanInstance(options = {}) {
65
+ const {
66
+ workerCount = 2,
67
+ cacheMaxSize = 50,
68
+ loggerOptions = {}
69
+ } = options;
70
+
71
+ // Initialize core components
72
+ const cache = new SimpleCache({ maxSizeMB: cacheMaxSize });
73
+ const contextLayer = new ContextLayer(); // Note: Current implementation doesn't use cache yet
74
+ const logger = new StructuredLogger(loggerOptions);
75
+ const metrics = new MetricsCollector();
76
+ const workerPool = new WorkerPool(workerCount);
77
+ const dashboard = new Dashboard(metrics, logger, workerPool);
78
+ const dispatcher = new EconomicDispatcher(workerPool);
79
+ const workflowExecutor = new WorkflowExecutor(contextLayer, dispatcher, logger);
80
+
81
+ return {
82
+ // Core
83
+ contextLayer,
84
+ cache,
85
+ dispatcher,
86
+ workerPool,
87
+ workflowExecutor,
88
+
89
+ // Observability
90
+ logger,
91
+ metrics,
92
+ dashboard,
93
+
94
+ // Convenience methods
95
+ async executeWorkflow(workflowPath, contextId = null) {
96
+ let context = {};
97
+ if (contextId) {
98
+ context = await contextLayer.loadContext('story', contextId);
99
+ }
100
+ return workflowExecutor.execute(workflowPath, context);
101
+ },
102
+
103
+ async loadContext(level, id = null) {
104
+ return contextLayer.loadContext(level, id);
105
+ },
106
+
107
+ getMetrics() {
108
+ return metrics.getMetrics();
109
+ },
110
+
111
+ showDashboard() {
112
+ return dashboard.render();
113
+ },
114
+
115
+ async shutdown() {
116
+ await workerPool.shutdown();
117
+ logger.info('BYAN v2.0 shutdown complete');
118
+ }
119
+ };
120
+ }
121
+
122
+ // Named exports (pour usage avancé)
123
+ module.exports = {
124
+ // Factory
125
+ createByanInstance,
126
+
127
+ // Core Components
128
+ ContextLayer,
129
+ SimpleCache,
130
+ EconomicDispatcher,
131
+ WorkerPool,
132
+ Worker,
133
+ WorkflowExecutor,
134
+
135
+ // Observability
136
+ StructuredLogger,
137
+ MetricsCollector,
138
+ Dashboard
139
+ };