micro-models-agent 0.52.0 → 0.52.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 (231) hide show
  1. package/README.md +358 -358
  2. package/dist/main.js +244 -122
  3. package/dist/modules/browser/bridge-server.mjs +202 -202
  4. package/dist/skills/builtin/git.md +36 -36
  5. package/dist/skills/builtin/typescript.md +35 -35
  6. package/package.json +1 -1
  7. package/dist/cli/commands.js +0 -447
  8. package/dist/cli/completer.js +0 -167
  9. package/dist/cli/index.js +0 -2
  10. package/dist/cli/main.js +0 -153
  11. package/dist/cli/plugin-commands.js +0 -36
  12. package/dist/cli/repl-commands.js +0 -761
  13. package/dist/cli/repl.js +0 -702
  14. package/dist/cli/run-result.js +0 -33
  15. package/dist/cli/security-commands.js +0 -164
  16. package/dist/cli/setup.js +0 -237
  17. package/dist/config/config.js +0 -276
  18. package/dist/config/defaults.js +0 -141
  19. package/dist/config/domains.js +0 -179
  20. package/dist/config/experts.js +0 -15
  21. package/dist/config/index.js +0 -4
  22. package/dist/config/security.js +0 -213
  23. package/dist/config/types.js +0 -1
  24. package/dist/core/agent-moe.js +0 -102
  25. package/dist/core/agent.js +0 -1018
  26. package/dist/core/bootstrap.js +0 -481
  27. package/dist/core/crash-handler.js +0 -51
  28. package/dist/core/environment.js +0 -199
  29. package/dist/core/index.js +0 -2
  30. package/dist/core/prompt-builder.js +0 -76
  31. package/dist/core/session-logger.js +0 -251
  32. package/dist/core/types.js +0 -1
  33. package/dist/core/version.js +0 -26
  34. package/dist/core/workspace.js +0 -76
  35. package/dist/i18n/en.json +0 -679
  36. package/dist/i18n/index.js +0 -46
  37. package/dist/i18n/ru.json +0 -679
  38. package/dist/index.js +0 -22
  39. package/dist/llm/image-utils.js +0 -143
  40. package/dist/llm/index.js +0 -4
  41. package/dist/llm/model-loader.js +0 -78
  42. package/dist/llm/openai-compat.js +0 -497
  43. package/dist/llm/orchestrator.js +0 -200
  44. package/dist/llm/provider.js +0 -10
  45. package/dist/llm/response.js +0 -39
  46. package/dist/llm/token-counter.js +0 -39
  47. package/dist/llm/types.js +0 -1
  48. package/dist/logger/app-logger.js +0 -189
  49. package/dist/logger/file-log.js +0 -151
  50. package/dist/logger/index.js +0 -1
  51. package/dist/migration/backup.js +0 -45
  52. package/dist/migration/detect.js +0 -50
  53. package/dist/migration/index.js +0 -2
  54. package/dist/modules/artifacts/store.js +0 -61
  55. package/dist/modules/browser/actions.js +0 -76
  56. package/dist/modules/browser/bridge-client.js +0 -199
  57. package/dist/modules/browser/bridge-path.js +0 -10
  58. package/dist/modules/browser/cookie-store.js +0 -24
  59. package/dist/modules/browser/driver.js +0 -136
  60. package/dist/modules/browser/index.js +0 -7
  61. package/dist/modules/browser/module.js +0 -29
  62. package/dist/modules/browser/session.js +0 -342
  63. package/dist/modules/browser/snapshot.js +0 -148
  64. package/dist/modules/browser/types.js +0 -12
  65. package/dist/modules/certification/cli.js +0 -213
  66. package/dist/modules/certification/fact-checker.js +0 -82
  67. package/dist/modules/certification/loader.js +0 -106
  68. package/dist/modules/certification/manifest.js +0 -58
  69. package/dist/modules/certification/runner.js +0 -245
  70. package/dist/modules/certification/scenarios.js +0 -407
  71. package/dist/modules/certification/types.js +0 -1
  72. package/dist/modules/context/chunk-query.js +0 -100
  73. package/dist/modules/context/fact-extractor.js +0 -168
  74. package/dist/modules/context/history.js +0 -15
  75. package/dist/modules/context/index.js +0 -1
  76. package/dist/modules/context/manager.js +0 -440
  77. package/dist/modules/execution/audit-runners.js +0 -206
  78. package/dist/modules/execution/auditor.js +0 -218
  79. package/dist/modules/execution/execution-plugin.js +0 -431
  80. package/dist/modules/execution/index.js +0 -8
  81. package/dist/modules/execution/module.js +0 -625
  82. package/dist/modules/execution/moe-executor.js +0 -304
  83. package/dist/modules/execution/plan-coverage.js +0 -68
  84. package/dist/modules/execution/plan-persister.js +0 -46
  85. package/dist/modules/execution/plan-store.js +0 -196
  86. package/dist/modules/execution/plan-tool.js +0 -677
  87. package/dist/modules/execution/plan-validator.js +0 -153
  88. package/dist/modules/execution/planner.js +0 -94
  89. package/dist/modules/execution/stuck-detector.js +0 -746
  90. package/dist/modules/execution/tracker.js +0 -69
  91. package/dist/modules/execution/types.js +0 -1
  92. package/dist/modules/execution/verifier.js +0 -235
  93. package/dist/modules/execution/windows-commands.js +0 -41
  94. package/dist/modules/hallucination/confidence.js +0 -66
  95. package/dist/modules/hallucination/consistency.js +0 -26
  96. package/dist/modules/hallucination/detector.js +0 -47
  97. package/dist/modules/hallucination/factual.js +0 -169
  98. package/dist/modules/hallucination/index.js +0 -5
  99. package/dist/modules/hallucination/js-identifiers.js +0 -262
  100. package/dist/modules/hallucination/llm-judge.js +0 -101
  101. package/dist/modules/index.js +0 -5
  102. package/dist/modules/indexer/cache.js +0 -40
  103. package/dist/modules/indexer/index.js +0 -3
  104. package/dist/modules/indexer/module.js +0 -246
  105. package/dist/modules/indexer/project-profile.js +0 -183
  106. package/dist/modules/indexer/walker.js +0 -101
  107. package/dist/modules/lsp/check-tool.js +0 -58
  108. package/dist/modules/lsp/client.js +0 -389
  109. package/dist/modules/lsp/command.js +0 -60
  110. package/dist/modules/lsp/config.js +0 -135
  111. package/dist/modules/lsp/index.js +0 -3
  112. package/dist/modules/lsp/module.js +0 -260
  113. package/dist/modules/lsp/probe.js +0 -86
  114. package/dist/modules/lsp/project-root.js +0 -32
  115. package/dist/modules/lsp/startup-check.js +0 -144
  116. package/dist/modules/lsp/types.js +0 -1
  117. package/dist/modules/mcp/client.js +0 -399
  118. package/dist/modules/mcp/index.js +0 -3
  119. package/dist/modules/mcp/module.js +0 -142
  120. package/dist/modules/mcp/registry.js +0 -15
  121. package/dist/modules/memory/index.js +0 -1
  122. package/dist/modules/memory/module.js +0 -96
  123. package/dist/modules/memory/search.js +0 -42
  124. package/dist/modules/memory/store.js +0 -69
  125. package/dist/modules/pipelines/engine.js +0 -60
  126. package/dist/modules/pipelines/index.js +0 -3
  127. package/dist/modules/pipelines/parser.js +0 -56
  128. package/dist/modules/pipelines/template.js +0 -14
  129. package/dist/modules/plugins/builtin/lint-on-write.js +0 -334
  130. package/dist/modules/plugins/builtin/notify.js +0 -9
  131. package/dist/modules/plugins/index.js +0 -1
  132. package/dist/modules/plugins/loader.js +0 -70
  133. package/dist/modules/plugins/manager.js +0 -261
  134. package/dist/modules/plugins/types.js +0 -1
  135. package/dist/modules/pricing/index.js +0 -61
  136. package/dist/modules/pricing/prices.js +0 -129
  137. package/dist/modules/processes/detect.js +0 -34
  138. package/dist/modules/processes/index.js +0 -2
  139. package/dist/modules/processes/registry.js +0 -327
  140. package/dist/modules/processes/runner.js +0 -23
  141. package/dist/modules/providers/create.js +0 -22
  142. package/dist/modules/providers/fallback.js +0 -79
  143. package/dist/modules/providers/health.js +0 -46
  144. package/dist/modules/providers/index.js +0 -5
  145. package/dist/modules/providers/manager.js +0 -161
  146. package/dist/modules/providers/presets.js +0 -128
  147. package/dist/modules/providers/registry.js +0 -22
  148. package/dist/modules/providers/types.js +0 -1
  149. package/dist/modules/registry.js +0 -48
  150. package/dist/modules/security/audit-log.js +0 -136
  151. package/dist/modules/security/audit-notifier.js +0 -292
  152. package/dist/modules/security/command-validator.js +0 -219
  153. package/dist/modules/security/content-scanner.js +0 -53
  154. package/dist/modules/security/data-sanitizer.js +0 -89
  155. package/dist/modules/security/encryption.js +0 -242
  156. package/dist/modules/security/index.js +0 -14
  157. package/dist/modules/security/network-validator.js +0 -88
  158. package/dist/modules/security/path-validator.js +0 -203
  159. package/dist/modules/security/rate-limiter.js +0 -119
  160. package/dist/modules/security/security-policies.js +0 -531
  161. package/dist/modules/security/session-encryption.js +0 -210
  162. package/dist/modules/security/session-isolation.js +0 -95
  163. package/dist/modules/session/index.js +0 -3
  164. package/dist/modules/session/manager.js +0 -172
  165. package/dist/modules/session/module.js +0 -24
  166. package/dist/modules/session/store.js +0 -222
  167. package/dist/modules/session/types.js +0 -1
  168. package/dist/modules/skills/index.js +0 -2
  169. package/dist/modules/skills/loader.js +0 -72
  170. package/dist/modules/skills/matcher.js +0 -27
  171. package/dist/modules/skills/module.js +0 -129
  172. package/dist/modules/types.js +0 -1
  173. package/dist/modules/updater/checker.js +0 -96
  174. package/dist/modules/updater/index.js +0 -2
  175. package/dist/modules/updater/module.js +0 -116
  176. package/dist/modules/user-profile/compressor.js +0 -16
  177. package/dist/modules/user-profile/index.js +0 -1
  178. package/dist/modules/user-profile/profile.js +0 -68
  179. package/dist/tools/approve.js +0 -33
  180. package/dist/tools/attach-image.js +0 -101
  181. package/dist/tools/bash.js +0 -519
  182. package/dist/tools/browser.js +0 -115
  183. package/dist/tools/chunk-query.js +0 -100
  184. package/dist/tools/create-dir.js +0 -56
  185. package/dist/tools/delete-file.js +0 -63
  186. package/dist/tools/download-file.js +0 -117
  187. package/dist/tools/edit-file.js +0 -80
  188. package/dist/tools/enable-tools.js +0 -59
  189. package/dist/tools/executor.js +0 -154
  190. package/dist/tools/file-info.js +0 -47
  191. package/dist/tools/filter-tools.js +0 -17
  192. package/dist/tools/glob-tool.js +0 -27
  193. package/dist/tools/grep-tool.js +0 -125
  194. package/dist/tools/hidden-tools-block.js +0 -37
  195. package/dist/tools/index.js +0 -78
  196. package/dist/tools/list-dir.js +0 -49
  197. package/dist/tools/load-skill.js +0 -43
  198. package/dist/tools/mcp-call.js +0 -69
  199. package/dist/tools/move-file.js +0 -86
  200. package/dist/tools/path-utils.js +0 -101
  201. package/dist/tools/pipeline-run.js +0 -145
  202. package/dist/tools/preview.js +0 -2
  203. package/dist/tools/process-kill.js +0 -40
  204. package/dist/tools/process-list.js +0 -37
  205. package/dist/tools/process-log.js +0 -54
  206. package/dist/tools/question.js +0 -141
  207. package/dist/tools/read-file.js +0 -179
  208. package/dist/tools/recall.js +0 -118
  209. package/dist/tools/registry.js +0 -47
  210. package/dist/tools/remember.js +0 -68
  211. package/dist/tools/scope-check.js +0 -32
  212. package/dist/tools/search-history.js +0 -85
  213. package/dist/tools/subagent.js +0 -196
  214. package/dist/tools/types.js +0 -1
  215. package/dist/tools/user-input.js +0 -123
  216. package/dist/tools/web-browse.js +0 -87
  217. package/dist/tools/web-fetch.js +0 -119
  218. package/dist/tools/web-search.js +0 -105
  219. package/dist/tools/write-file.js +0 -82
  220. package/dist/ui/box.js +0 -77
  221. package/dist/ui/colors.js +0 -4
  222. package/dist/ui/diff.js +0 -178
  223. package/dist/ui/index.js +0 -6
  224. package/dist/ui/line-editor.js +0 -822
  225. package/dist/ui/line-math.js +0 -73
  226. package/dist/ui/md-formatter.js +0 -212
  227. package/dist/ui/output.js +0 -13
  228. package/dist/ui/plan-view.js +0 -103
  229. package/dist/ui/renderer.js +0 -259
  230. package/dist/ui/spinner.js +0 -70
  231. package/dist/ui/table.js +0 -144
@@ -1,304 +0,0 @@
1
- import { getExpertConfig } from "../../config/experts";
2
- import { filterToolsByTags } from "../../tools/filter-tools";
3
- import { StuckDetector } from "./stuck-detector";
4
- import { t } from "../../i18n/index";
5
- import { ArtifactStore } from "../artifacts/store";
6
- const TRANSIENT_ERROR_PATTERNS = [
7
- "timeout",
8
- "Timeout",
9
- "TIMEOUT",
10
- "5xx",
11
- "500",
12
- "502",
13
- "503",
14
- "network",
15
- "Network",
16
- "ECONNREFUSED",
17
- "ECONNRESET",
18
- "fetch failed",
19
- "abort",
20
- "Abort",
21
- ];
22
- function isTransientError(error) {
23
- return TRANSIENT_ERROR_PATTERNS.some((p) => error.includes(p));
24
- }
25
- function sleep(ms) {
26
- return new Promise((r) => setTimeout(r, ms));
27
- }
28
- export function topologicalSort(subtasks) {
29
- const sorted = [];
30
- const remaining = new Set(subtasks.map((s) => s.id));
31
- const subtaskMap = new Map(subtasks.map((s) => [s.id, s]));
32
- while (remaining.size > 0) {
33
- const ready = [];
34
- for (const id of remaining) {
35
- const sub = subtaskMap.get(id);
36
- const depsSatisfied = (sub.depends_on || []).every((d) => !remaining.has(d));
37
- if (depsSatisfied) {
38
- ready.push(sub);
39
- }
40
- }
41
- if (ready.length === 0) {
42
- break;
43
- }
44
- sorted.push(ready);
45
- for (const r of ready) {
46
- remaining.delete(r.id);
47
- }
48
- }
49
- return sorted;
50
- }
51
- async function executeSubtask(subtask, deps, _sharedContext) {
52
- const startTime = Date.now();
53
- const expertConfig = getExpertConfig(deps.config, subtask.expert_tag);
54
- if (!expertConfig) {
55
- return {
56
- subtaskId: subtask.id,
57
- success: false,
58
- summary: `Unknown expert_tag: ${subtask.expert_tag}`,
59
- result: "",
60
- error: `No expert config found for tag "${subtask.expert_tag}"`,
61
- durationMs: Date.now() - startTime,
62
- };
63
- }
64
- const subagentTool = deps.toolRegistry.get("subagent");
65
- if (!subagentTool) {
66
- return {
67
- subtaskId: subtask.id,
68
- success: false,
69
- summary: "Subagent tool not registered",
70
- result: "",
71
- error: "Subagent tool not found in registry",
72
- durationMs: Date.now() - startTime,
73
- };
74
- }
75
- const allTools = deps.toolRegistry.getAll();
76
- const filteredTools = filterToolsByTags(allTools, expertConfig.tool_tags);
77
- if (filteredTools.length === 0) {
78
- return {
79
- subtaskId: subtask.id,
80
- success: false,
81
- summary: `No tools available for expert "${subtask.expert_tag}" (tags: ${expertConfig.tool_tags.join(", ")})`,
82
- result: "",
83
- error: "No matching tools",
84
- durationMs: Date.now() - startTime,
85
- };
86
- }
87
- const maxAttempts = expertConfig.max_attempts || 3;
88
- let lastError = "";
89
- const stuckDetector = new StuckDetector(maxAttempts * 2, maxAttempts);
90
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
91
- stuckDetector.recordIteration(1);
92
- try {
93
- const allowedFiles = subtask.allowed_files || [];
94
- const readOnlyFiles = subtask.read_only_files || [];
95
- const scopePrompt = allowedFiles.length > 0 || readOnlyFiles.length > 0
96
- ? `\n\nAllowed files to write: ${allowedFiles.join(", ") || "(none)"}\nRead-only files: ${readOnlyFiles.join(", ") || "(none)"}`
97
- : "";
98
- const taskPrompt = `${subtask.description}\n\nExpected output: ${subtask.expected_output}\nSuccess criteria:\n${(subtask.success_criteria || []).map((c) => `- ${c}`).join("\n")}${scopePrompt}`;
99
- const subagentArgs = {
100
- task: taskPrompt,
101
- allowed_files: allowedFiles,
102
- read_only_files: readOnlyFiles,
103
- tool_tags: expertConfig.tool_tags,
104
- };
105
- if (deps.config.subagent?.resultMode === "file") {
106
- subagentArgs.result_mode = "file";
107
- subagentArgs.artifact_name = subtask.id;
108
- }
109
- const result = await subagentTool.handler({
110
- config: deps.config,
111
- baseDir: deps.baseDir,
112
- logger: deps.logger,
113
- llmProvider: deps.llmProvider,
114
- toolExecutor: deps.toolExecutor,
115
- sessionId: "moe",
116
- }, subagentArgs);
117
- if (result.success) {
118
- if (deps.config.subagent?.resultMode === "file") {
119
- const pathMatch = result.output.match(/saved to artifact: (.+)/);
120
- const abs = pathMatch ? pathMatch[1].trim() : "";
121
- if (abs) {
122
- const store = new ArtifactStore({
123
- baseDir: deps.baseDir,
124
- sessionId: "moe",
125
- });
126
- const full = store.read(abs.split(/[\\/]/).pop() || ""); // file name only, scoped to root
127
- deps.logger.debug(`MoE subtask "${subtask.id}" attached artifact ${abs} (${full?.length ?? 0} chars) to Router`);
128
- return {
129
- subtaskId: subtask.id,
130
- success: true,
131
- summary: `Artifact: ${abs}`,
132
- result: full ?? result.output,
133
- durationMs: Date.now() - startTime,
134
- };
135
- }
136
- }
137
- return {
138
- subtaskId: subtask.id,
139
- success: true,
140
- summary: `Completed: ${subtask.id}`,
141
- result: result.output,
142
- durationMs: Date.now() - startTime,
143
- };
144
- }
145
- lastError = result.output;
146
- stuckDetector.recordToolError("subagent", result.output);
147
- // Inject actionable hints into the next retry's prompt
148
- if (attempt < maxAttempts) {
149
- const hints = stuckDetector.getActionableHints();
150
- const recovery = stuckDetector.getRecoveryMessage();
151
- if (hints.length > 0) {
152
- deps.logger.debug(`Hint for subtask "${subtask.id}" retry: ${hints.join("; ")}`);
153
- }
154
- if (recovery) {
155
- deps.logger.debug(`Recovery for subtask "${subtask.id}": ${recovery}`);
156
- }
157
- }
158
- if (isTransientError(lastError) && attempt < maxAttempts) {
159
- const delay = Math.min(1000 * Math.pow(2, attempt - 1), 8000);
160
- deps.logger.debug(`Retrying subtask "${subtask.id}" (attempt ${attempt}/${maxAttempts}) after ${delay}ms: transient error`);
161
- await sleep(delay);
162
- continue;
163
- }
164
- // Non-transient failure — build detailed error with hints
165
- const hints = stuckDetector.getActionableHints();
166
- let errorDetail = result.output;
167
- if (hints.length > 0) {
168
- errorDetail += `\n\n${t("exec.hints", { hints: hints.map((h) => `- ${h}`).join("\n") })}`;
169
- }
170
- if (lastError) {
171
- errorDetail +=
172
- "\n\nIf relevant skills are available, consider loading one with load_skill for expert guidance.";
173
- }
174
- return {
175
- subtaskId: subtask.id,
176
- success: false,
177
- summary: `Failed: ${subtask.id}`,
178
- result: result.output,
179
- error: errorDetail,
180
- durationMs: Date.now() - startTime,
181
- };
182
- }
183
- catch (e) {
184
- lastError = e.message;
185
- stuckDetector.recordToolError("subagent", e.message);
186
- if (isTransientError(lastError) && attempt < maxAttempts) {
187
- const delay = Math.min(1000 * Math.pow(2, attempt - 1), 8000);
188
- deps.logger.debug(`Retrying subtask "${subtask.id}" (attempt ${attempt}/${maxAttempts}) after ${delay}ms: ${lastError}`);
189
- await sleep(delay);
190
- continue;
191
- }
192
- const hints = stuckDetector.getActionableHints();
193
- let errorDetail = e.message;
194
- if (hints.length > 0) {
195
- errorDetail += `\n\n${t("exec.hints", { hints: hints.map((h) => `- ${h}`).join("\n") })}`;
196
- }
197
- if (lastError) {
198
- errorDetail +=
199
- "\n\nIf relevant skills are available, consider loading one with load_skill for expert guidance.";
200
- }
201
- return {
202
- subtaskId: subtask.id,
203
- success: false,
204
- summary: `Error: ${subtask.id}`,
205
- result: "",
206
- error: errorDetail,
207
- durationMs: Date.now() - startTime,
208
- };
209
- }
210
- }
211
- // Exhausted retries — build detailed failure
212
- const stuckReason = stuckDetector.getStuckReason();
213
- let finalError = lastError;
214
- if (stuckReason) {
215
- finalError += `\n${stuckReason}`;
216
- }
217
- return {
218
- subtaskId: subtask.id,
219
- success: false,
220
- summary: `Failed after ${maxAttempts} attempts: ${subtask.id}`,
221
- result: "",
222
- error: finalError,
223
- durationMs: Date.now() - startTime,
224
- };
225
- }
226
- export class MoEExecutor {
227
- deps;
228
- constructor(deps) {
229
- this.deps = deps;
230
- }
231
- async executePlan(plan) {
232
- const results = [];
233
- const errors = [];
234
- const warnings = [];
235
- const waves = topologicalSort(plan.subtasks);
236
- if (waves.length === 0) {
237
- return {
238
- success: false,
239
- results: [],
240
- errors: ["Failed to topologically sort subtasks (possible cycle)"],
241
- warnings: [],
242
- };
243
- }
244
- // Verify all subtasks are included — catch silent drops from unresolved dependencies
245
- const sortedCount = waves.flat().length;
246
- if (sortedCount < plan.subtasks.length) {
247
- const missing = plan.subtasks
248
- .filter((s) => !waves.flat().some((w) => w.id === s.id))
249
- .map((s) => s.id);
250
- return {
251
- success: false,
252
- results: [],
253
- errors: [
254
- `Missing subtasks after topological sort: ${missing.join(", ")} (dangling or invalid depends_on)`,
255
- ],
256
- warnings: [],
257
- };
258
- }
259
- for (let waveIdx = 0; waveIdx < waves.length; waveIdx++) {
260
- const wave = waves[waveIdx];
261
- // Cap concurrent subtasks per wave (rateLimits.maxParallelTasks, default 5).
262
- const maxParallel = this.deps.config?.security?.rateLimits?.maxParallelTasks ?? 5;
263
- let active = 0;
264
- const waiters = [];
265
- const acquire = () => active < maxParallel
266
- ? Promise.resolve(active++)
267
- : new Promise((resolve) => waiters.push(() => resolve(active++)));
268
- const release = () => {
269
- active--;
270
- const next = waiters.shift();
271
- if (next)
272
- next();
273
- };
274
- const wavePromises = wave.map(async (subtask) => {
275
- await acquire();
276
- let result;
277
- try {
278
- result = await executeSubtask(subtask, this.deps, plan.shared_context);
279
- }
280
- catch (e) {
281
- result = {
282
- subtaskId: subtask.id,
283
- success: false,
284
- summary: `Unhandled error: ${subtask.id}`,
285
- result: "",
286
- error: e instanceof Error ? e.message : String(e),
287
- durationMs: 0,
288
- };
289
- }
290
- finally {
291
- release();
292
- }
293
- results.push(result);
294
- return result;
295
- });
296
- await Promise.all(wavePromises);
297
- }
298
- const failed = results.filter((r) => !r.success);
299
- if (failed.length > 0) {
300
- errors.push(...failed.map((f) => `[${f.subtaskId}] ${f.error || f.summary}`));
301
- }
302
- return { success: failed.length === 0, results, errors, warnings };
303
- }
304
- }
@@ -1,68 +0,0 @@
1
- const FILE_PATH_RE = /\b[\w./\\-]+\.[a-z]+\b/gi;
2
- const IGNORED_EXT = new Set([
3
- "tsx",
4
- "jsx",
5
- "json5",
6
- "mdx",
7
- "yml",
8
- "yaml",
9
- "toml",
10
- "lock",
11
- "svg",
12
- "png",
13
- "jpg",
14
- "jpeg",
15
- "gif",
16
- "webp",
17
- "ico",
18
- "css",
19
- "scss",
20
- "less",
21
- "html",
22
- ]);
23
- /**
24
- * Extract file paths (with extensions) mentioned in a task statement.
25
- * Used to check whether a generated plan covers every file the task requires.
26
- */
27
- export function extractFilePaths(text) {
28
- if (!text)
29
- return [];
30
- const seen = new Set();
31
- const result = [];
32
- for (const m of text.matchAll(FILE_PATH_RE)) {
33
- let p = m[0];
34
- // Trim trailing punctuation that regex greedily keeps (e.g. "test.ts.")
35
- p = p.replace(/[.,;:)\]>]+$/g, "");
36
- const ext = p.split(".").pop()?.toLowerCase() ?? "";
37
- if (!p || IGNORED_EXT.has(ext))
38
- continue;
39
- const key = p.toLowerCase();
40
- if (seen.has(key))
41
- continue;
42
- seen.add(key);
43
- result.push(p);
44
- }
45
- return result;
46
- }
47
- function basename(p) {
48
- const parts = p.split(/[/\\]/);
49
- return parts[parts.length - 1] ?? p;
50
- }
51
- /**
52
- * Compare the file requirements in the task statement against the plan's step
53
- * descriptions. A requirement is "covered" when its path (or its basename)
54
- * appears in at least one step. Returns the missing paths.
55
- */
56
- export function checkPlanCoverage(taskText, stepDescriptions) {
57
- const taskPaths = extractFilePaths(taskText);
58
- if (taskPaths.length === 0)
59
- return { missing: [] };
60
- const stepText = stepDescriptions.map((s) => s.toLowerCase()).join("\n");
61
- const missing = taskPaths.filter((p) => {
62
- const lower = p.toLowerCase();
63
- const base = basename(lower);
64
- // A step mentioning either the full relative path or its basename counts.
65
- return !stepText.includes(lower) && !stepText.includes(base);
66
- });
67
- return { missing };
68
- }
@@ -1,46 +0,0 @@
1
- import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
2
- import { join } from "path";
3
- export class PlanPersister {
4
- filePath;
5
- constructor(baseDir) {
6
- const mmaDir = join(baseDir, ".mma");
7
- if (!existsSync(mmaDir)) {
8
- mkdirSync(mmaDir, { recursive: true });
9
- }
10
- this.filePath = join(mmaDir, "plan.json");
11
- }
12
- save(plan) {
13
- const file = {
14
- id: plan.id,
15
- title: plan.title,
16
- steps: plan.steps,
17
- createdAt: plan.createdAt,
18
- updatedAt: new Date().toISOString(),
19
- baseDir: plan.baseDir,
20
- };
21
- writeFileSync(this.filePath, JSON.stringify(file, null, 2), "utf-8");
22
- }
23
- load() {
24
- if (!existsSync(this.filePath))
25
- return null;
26
- try {
27
- const raw = readFileSync(this.filePath, "utf-8");
28
- const file = JSON.parse(raw);
29
- return {
30
- id: file.id || "plan_legacy",
31
- title: file.title,
32
- steps: file.steps,
33
- createdAt: file.createdAt,
34
- baseDir: file.baseDir || process.cwd(),
35
- };
36
- }
37
- catch {
38
- return null;
39
- }
40
- }
41
- clear() {
42
- if (existsSync(this.filePath)) {
43
- writeFileSync(this.filePath, "", "utf-8");
44
- }
45
- }
46
- }
@@ -1,196 +0,0 @@
1
- import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, rmSync } from "fs";
2
- import { join } from "path";
3
- const LEGACY_FILE = "plan.json";
4
- function readPlanFile(path, fallbackBaseDir) {
5
- try {
6
- const raw = readFileSync(path, "utf-8");
7
- if (!raw.trim())
8
- return null;
9
- const parsed = JSON.parse(raw);
10
- if (!parsed || !Array.isArray(parsed.steps))
11
- return null;
12
- return {
13
- id: parsed.id || "plan_legacy",
14
- title: parsed.title || "Legacy plan",
15
- steps: parsed.steps,
16
- createdAt: parsed.createdAt || new Date().toISOString(),
17
- baseDir: parsed.baseDir || fallbackBaseDir,
18
- name: parsed.name,
19
- };
20
- }
21
- catch {
22
- return null;
23
- }
24
- }
25
- function writePlanFile(path, plan) {
26
- writeFileSync(path, JSON.stringify(plan, null, 2), "utf-8");
27
- }
28
- function listDir(dir, baseDir) {
29
- if (!existsSync(dir))
30
- return [];
31
- const files = readdirSync(dir).filter((f) => f.endsWith(".json"));
32
- return files.map((f) => readPlanFile(join(dir, f), baseDir)).filter((p) => p !== null);
33
- }
34
- function toMeta(plan, status) {
35
- return {
36
- id: plan.id,
37
- name: plan.name,
38
- title: plan.title,
39
- status,
40
- createdAt: plan.createdAt,
41
- stepCount: plan.steps.length,
42
- doneCount: plan.steps.filter((s) => s.status === "done" || s.status === "skipped").length,
43
- };
44
- }
45
- export class PlanStore {
46
- baseDir;
47
- plansDir;
48
- draftsDir;
49
- archiveDir;
50
- legacyPath;
51
- constructor(baseDir) {
52
- const mmaDir = join(baseDir, ".mma");
53
- if (!existsSync(mmaDir))
54
- mkdirSync(mmaDir, { recursive: true });
55
- this.baseDir = baseDir;
56
- this.plansDir = join(mmaDir, "plans");
57
- this.draftsDir = join(this.plansDir, "drafts");
58
- this.archiveDir = join(this.plansDir, "archive");
59
- this.legacyPath = join(mmaDir, LEGACY_FILE);
60
- for (const dir of [this.plansDir, this.draftsDir, this.archiveDir]) {
61
- if (!existsSync(dir))
62
- mkdirSync(dir, { recursive: true });
63
- }
64
- }
65
- activePath() {
66
- return join(this.plansDir, "active.json");
67
- }
68
- // ---- Active plan ----
69
- saveActive(plan) {
70
- writePlanFile(this.activePath(), plan);
71
- }
72
- loadActive() {
73
- const activePath = this.activePath();
74
- if (existsSync(activePath)) {
75
- const plan = readPlanFile(activePath, this.baseDir);
76
- if (plan)
77
- return plan;
78
- }
79
- // Legacy migration: read .mma/plan.json and move to active
80
- if (existsSync(this.legacyPath)) {
81
- const legacy = readPlanFile(this.legacyPath, this.baseDir);
82
- if (legacy) {
83
- this.saveActive(legacy);
84
- try {
85
- rmSync(this.legacyPath, { force: true });
86
- }
87
- catch { }
88
- return legacy;
89
- }
90
- }
91
- return null;
92
- }
93
- clearActive() {
94
- const p = this.activePath();
95
- if (existsSync(p))
96
- rmSync(p, { force: true });
97
- }
98
- // ---- Drafts (saved plans) ----
99
- saveDraft(plan) {
100
- writePlanFile(join(this.draftsDir, `${plan.id}.json`), plan);
101
- }
102
- loadDraft(id) {
103
- const p = join(this.draftsDir, `${id}.json`);
104
- return existsSync(p) ? readPlanFile(p, this.baseDir) : null;
105
- }
106
- removeDraft(id) {
107
- const p = join(this.draftsDir, `${id}.json`);
108
- if (existsSync(p))
109
- rmSync(p, { force: true });
110
- }
111
- listDrafts() {
112
- return listDir(this.draftsDir, this.baseDir);
113
- }
114
- // ---- Archive ----
115
- archivePlan(plan) {
116
- writePlanFile(join(this.archiveDir, `${plan.id}.json`), plan);
117
- // Remove from drafts if present
118
- this.removeDraft(plan.id);
119
- // If archived plan was active, clear active
120
- const active = this.loadActive();
121
- if (active && active.id === plan.id) {
122
- this.clearActive();
123
- }
124
- }
125
- listArchived() {
126
- return listDir(this.archiveDir, this.baseDir);
127
- }
128
- removeArchived(id) {
129
- const p = join(this.archiveDir, `${id}.json`);
130
- if (existsSync(p))
131
- rmSync(p, { force: true });
132
- }
133
- // ---- Cross-status queries ----
134
- listAll() {
135
- const metas = [];
136
- const active = this.loadActive();
137
- if (active)
138
- metas.push(toMeta(active, "active"));
139
- for (const p of this.listDrafts())
140
- metas.push(toMeta(p, "draft"));
141
- for (const p of this.listArchived())
142
- metas.push(toMeta(p, "archived"));
143
- return metas;
144
- }
145
- find(id) {
146
- const active = this.loadActive();
147
- if (active && active.id === id)
148
- return { plan: active, status: "active" };
149
- const draft = this.loadDraft(id);
150
- if (draft)
151
- return { plan: draft, status: "draft" };
152
- const archived = this.listArchived().find((p) => p.id === id);
153
- if (archived)
154
- return { plan: archived, status: "archived" };
155
- return null;
156
- }
157
- // ---- Deletion (the user asked for plans to actually go away) ----
158
- /** Permanently delete a plan wherever it lives. Returns its status, or null
159
- * when no plan with that id exists. */
160
- deletePlan(id) {
161
- const active = this.loadActive();
162
- if (active && active.id === id) {
163
- this.clearActive();
164
- return "active";
165
- }
166
- const draftPath = join(this.draftsDir, `${id}.json`);
167
- if (existsSync(draftPath)) {
168
- rmSync(draftPath, { force: true });
169
- return "draft";
170
- }
171
- const archivedPath = join(this.archiveDir, `${id}.json`);
172
- if (existsSync(archivedPath)) {
173
- rmSync(archivedPath, { force: true });
174
- return "archived";
175
- }
176
- return null;
177
- }
178
- /** Delete every plan (active, drafts, archive). Returns the number removed. */
179
- purgeAll() {
180
- let n = 0;
181
- const active = this.loadActive();
182
- if (active) {
183
- this.clearActive();
184
- n++;
185
- }
186
- for (const p of this.listDrafts()) {
187
- this.removeDraft(p.id);
188
- n++;
189
- }
190
- for (const p of this.listArchived()) {
191
- this.removeArchived(p.id);
192
- n++;
193
- }
194
- return n;
195
- }
196
- }