micro-models-agent 0.46.1 → 0.46.3

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 (218) hide show
  1. package/README.md +312 -312
  2. package/dist/main.js +724 -530
  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 +48 -48
  7. package/dist/cli/commands.js +0 -323
  8. package/dist/cli/completer.js +0 -167
  9. package/dist/cli/index.js +0 -2
  10. package/dist/cli/main.js +0 -165
  11. package/dist/cli/plugin-commands.js +0 -36
  12. package/dist/cli/repl-commands.js +0 -661
  13. package/dist/cli/repl.js +0 -616
  14. package/dist/cli/run-result.js +0 -22
  15. package/dist/cli/security-commands.js +0 -164
  16. package/dist/cli/setup.js +0 -231
  17. package/dist/config/config.js +0 -249
  18. package/dist/config/defaults.js +0 -124
  19. package/dist/config/experts.js +0 -15
  20. package/dist/config/index.js +0 -3
  21. package/dist/config/security.js +0 -193
  22. package/dist/config/types.js +0 -1
  23. package/dist/core/agent-moe.js +0 -102
  24. package/dist/core/agent.js +0 -886
  25. package/dist/core/bootstrap.js +0 -404
  26. package/dist/core/index.js +0 -2
  27. package/dist/core/prompt-builder.js +0 -76
  28. package/dist/core/session-logger.js +0 -197
  29. package/dist/core/types.js +0 -1
  30. package/dist/core/version.js +0 -24
  31. package/dist/core/workspace.js +0 -76
  32. package/dist/i18n/en.json +0 -598
  33. package/dist/i18n/index.js +0 -46
  34. package/dist/i18n/ru.json +0 -598
  35. package/dist/index.js +0 -22
  36. package/dist/llm/image-utils.js +0 -143
  37. package/dist/llm/index.js +0 -4
  38. package/dist/llm/model-loader.js +0 -78
  39. package/dist/llm/openai-compat.js +0 -359
  40. package/dist/llm/orchestrator.js +0 -198
  41. package/dist/llm/provider.js +0 -10
  42. package/dist/llm/response.js +0 -39
  43. package/dist/llm/token-counter.js +0 -39
  44. package/dist/llm/types.js +0 -1
  45. package/dist/logger/app-logger.js +0 -143
  46. package/dist/logger/file-log.js +0 -151
  47. package/dist/logger/index.js +0 -1
  48. package/dist/migration/backup.js +0 -45
  49. package/dist/migration/detect.js +0 -50
  50. package/dist/migration/index.js +0 -2
  51. package/dist/modules/artifacts/store.js +0 -61
  52. package/dist/modules/browser/actions.js +0 -76
  53. package/dist/modules/browser/bridge-client.js +0 -199
  54. package/dist/modules/browser/bridge-path.js +0 -10
  55. package/dist/modules/browser/cookie-store.js +0 -24
  56. package/dist/modules/browser/driver.js +0 -136
  57. package/dist/modules/browser/index.js +0 -7
  58. package/dist/modules/browser/module.js +0 -29
  59. package/dist/modules/browser/session.js +0 -338
  60. package/dist/modules/browser/snapshot.js +0 -148
  61. package/dist/modules/browser/types.js +0 -12
  62. package/dist/modules/certification/cli.js +0 -174
  63. package/dist/modules/certification/fact-checker.js +0 -82
  64. package/dist/modules/certification/loader.js +0 -105
  65. package/dist/modules/certification/manifest.js +0 -50
  66. package/dist/modules/certification/runner.js +0 -159
  67. package/dist/modules/certification/scenarios.js +0 -124
  68. package/dist/modules/certification/types.js +0 -1
  69. package/dist/modules/context/chunk-query.js +0 -100
  70. package/dist/modules/context/fact-extractor.js +0 -162
  71. package/dist/modules/context/history.js +0 -15
  72. package/dist/modules/context/index.js +0 -1
  73. package/dist/modules/context/manager.js +0 -423
  74. package/dist/modules/execution/audit-runners.js +0 -152
  75. package/dist/modules/execution/auditor.js +0 -218
  76. package/dist/modules/execution/execution-plugin.js +0 -272
  77. package/dist/modules/execution/index.js +0 -8
  78. package/dist/modules/execution/module.js +0 -436
  79. package/dist/modules/execution/moe-executor.js +0 -291
  80. package/dist/modules/execution/plan-coverage.js +0 -68
  81. package/dist/modules/execution/plan-persister.js +0 -46
  82. package/dist/modules/execution/plan-store.js +0 -157
  83. package/dist/modules/execution/plan-tool.js +0 -508
  84. package/dist/modules/execution/plan-validator.js +0 -153
  85. package/dist/modules/execution/planner.js +0 -90
  86. package/dist/modules/execution/stuck-detector.js +0 -510
  87. package/dist/modules/execution/tracker.js +0 -67
  88. package/dist/modules/execution/types.js +0 -1
  89. package/dist/modules/execution/verifier.js +0 -222
  90. package/dist/modules/execution/windows-commands.js +0 -41
  91. package/dist/modules/hallucination/confidence.js +0 -66
  92. package/dist/modules/hallucination/consistency.js +0 -26
  93. package/dist/modules/hallucination/detector.js +0 -43
  94. package/dist/modules/hallucination/factual.js +0 -129
  95. package/dist/modules/hallucination/index.js +0 -5
  96. package/dist/modules/hallucination/js-identifiers.js +0 -262
  97. package/dist/modules/hallucination/llm-judge.js +0 -101
  98. package/dist/modules/index.js +0 -5
  99. package/dist/modules/indexer/cache.js +0 -40
  100. package/dist/modules/indexer/index.js +0 -3
  101. package/dist/modules/indexer/module.js +0 -245
  102. package/dist/modules/indexer/project-profile.js +0 -183
  103. package/dist/modules/indexer/walker.js +0 -101
  104. package/dist/modules/lsp/check-tool.js +0 -58
  105. package/dist/modules/lsp/client.js +0 -278
  106. package/dist/modules/lsp/command.js +0 -60
  107. package/dist/modules/lsp/config.js +0 -135
  108. package/dist/modules/lsp/index.js +0 -3
  109. package/dist/modules/lsp/module.js +0 -232
  110. package/dist/modules/lsp/probe.js +0 -76
  111. package/dist/modules/lsp/project-root.js +0 -32
  112. package/dist/modules/lsp/startup-check.js +0 -141
  113. package/dist/modules/lsp/types.js +0 -1
  114. package/dist/modules/mcp/client.js +0 -399
  115. package/dist/modules/mcp/index.js +0 -3
  116. package/dist/modules/mcp/module.js +0 -142
  117. package/dist/modules/mcp/registry.js +0 -15
  118. package/dist/modules/memory/index.js +0 -1
  119. package/dist/modules/memory/module.js +0 -96
  120. package/dist/modules/memory/search.js +0 -42
  121. package/dist/modules/memory/store.js +0 -69
  122. package/dist/modules/pipelines/engine.js +0 -60
  123. package/dist/modules/pipelines/index.js +0 -3
  124. package/dist/modules/pipelines/parser.js +0 -56
  125. package/dist/modules/pipelines/template.js +0 -14
  126. package/dist/modules/plugins/builtin/lint-on-write.js +0 -231
  127. package/dist/modules/plugins/builtin/notify.js +0 -9
  128. package/dist/modules/plugins/index.js +0 -1
  129. package/dist/modules/plugins/loader.js +0 -70
  130. package/dist/modules/plugins/manager.js +0 -217
  131. package/dist/modules/plugins/types.js +0 -1
  132. package/dist/modules/processes/detect.js +0 -34
  133. package/dist/modules/processes/index.js +0 -2
  134. package/dist/modules/processes/registry.js +0 -327
  135. package/dist/modules/processes/runner.js +0 -23
  136. package/dist/modules/registry.js +0 -47
  137. package/dist/modules/security/audit-log.js +0 -136
  138. package/dist/modules/security/audit-notifier.js +0 -292
  139. package/dist/modules/security/command-validator.js +0 -205
  140. package/dist/modules/security/content-scanner.js +0 -53
  141. package/dist/modules/security/data-sanitizer.js +0 -89
  142. package/dist/modules/security/encryption.js +0 -242
  143. package/dist/modules/security/index.js +0 -14
  144. package/dist/modules/security/network-validator.js +0 -71
  145. package/dist/modules/security/path-validator.js +0 -207
  146. package/dist/modules/security/rate-limiter.js +0 -119
  147. package/dist/modules/security/security-policies.js +0 -531
  148. package/dist/modules/security/session-encryption.js +0 -210
  149. package/dist/modules/security/session-isolation.js +0 -95
  150. package/dist/modules/session/index.js +0 -3
  151. package/dist/modules/session/manager.js +0 -172
  152. package/dist/modules/session/module.js +0 -24
  153. package/dist/modules/session/store.js +0 -222
  154. package/dist/modules/session/types.js +0 -1
  155. package/dist/modules/skills/index.js +0 -2
  156. package/dist/modules/skills/loader.js +0 -72
  157. package/dist/modules/skills/matcher.js +0 -27
  158. package/dist/modules/skills/module.js +0 -129
  159. package/dist/modules/types.js +0 -1
  160. package/dist/modules/updater/checker.js +0 -96
  161. package/dist/modules/updater/index.js +0 -2
  162. package/dist/modules/updater/module.js +0 -116
  163. package/dist/modules/user-profile/compressor.js +0 -16
  164. package/dist/modules/user-profile/index.js +0 -1
  165. package/dist/modules/user-profile/profile.js +0 -68
  166. package/dist/tools/approve.js +0 -32
  167. package/dist/tools/attach-image.js +0 -89
  168. package/dist/tools/bash.js +0 -496
  169. package/dist/tools/browser.js +0 -114
  170. package/dist/tools/chunk-query.js +0 -99
  171. package/dist/tools/create-dir.js +0 -55
  172. package/dist/tools/delete-file.js +0 -62
  173. package/dist/tools/download-file.js +0 -116
  174. package/dist/tools/edit-file.js +0 -79
  175. package/dist/tools/enable-tools.js +0 -58
  176. package/dist/tools/executor.js +0 -144
  177. package/dist/tools/file-info.js +0 -46
  178. package/dist/tools/filter-tools.js +0 -17
  179. package/dist/tools/glob-tool.js +0 -26
  180. package/dist/tools/grep-tool.js +0 -84
  181. package/dist/tools/hidden-tools-block.js +0 -37
  182. package/dist/tools/index.js +0 -78
  183. package/dist/tools/list-dir.js +0 -48
  184. package/dist/tools/load-skill.js +0 -42
  185. package/dist/tools/mcp-call.js +0 -68
  186. package/dist/tools/move-file.js +0 -85
  187. package/dist/tools/path-utils.js +0 -51
  188. package/dist/tools/pipeline-run.js +0 -144
  189. package/dist/tools/preview.js +0 -2
  190. package/dist/tools/process-kill.js +0 -29
  191. package/dist/tools/process-list.js +0 -36
  192. package/dist/tools/process-log.js +0 -45
  193. package/dist/tools/question.js +0 -140
  194. package/dist/tools/read-file.js +0 -91
  195. package/dist/tools/recall.js +0 -117
  196. package/dist/tools/registry.js +0 -47
  197. package/dist/tools/remember.js +0 -67
  198. package/dist/tools/scope-check.js +0 -30
  199. package/dist/tools/search-history.js +0 -84
  200. package/dist/tools/subagent.js +0 -196
  201. package/dist/tools/types.js +0 -1
  202. package/dist/tools/user-input.js +0 -123
  203. package/dist/tools/web-browse.js +0 -86
  204. package/dist/tools/web-fetch.js +0 -98
  205. package/dist/tools/web-search.js +0 -78
  206. package/dist/tools/write-file.js +0 -81
  207. package/dist/ui/box.js +0 -77
  208. package/dist/ui/colors.js +0 -4
  209. package/dist/ui/diff.js +0 -178
  210. package/dist/ui/index.js +0 -6
  211. package/dist/ui/line-editor.js +0 -703
  212. package/dist/ui/line-math.js +0 -69
  213. package/dist/ui/md-formatter.js +0 -212
  214. package/dist/ui/output.js +0 -13
  215. package/dist/ui/plan-view.js +0 -103
  216. package/dist/ui/renderer.js +0 -209
  217. package/dist/ui/spinner.js +0 -70
  218. package/dist/ui/table.js +0 -144
@@ -1,291 +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
- let lastResult = null;
90
- const stuckDetector = new StuckDetector(maxAttempts * 2, maxAttempts);
91
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
92
- stuckDetector.recordIteration(1);
93
- try {
94
- const allowedFiles = subtask.allowed_files || [];
95
- const readOnlyFiles = subtask.read_only_files || [];
96
- const scopePrompt = allowedFiles.length > 0 || readOnlyFiles.length > 0
97
- ? `\n\nAllowed files to write: ${allowedFiles.join(", ") || "(none)"}\nRead-only files: ${readOnlyFiles.join(", ") || "(none)"}`
98
- : "";
99
- const taskPrompt = `${subtask.description}\n\nExpected output: ${subtask.expected_output}\nSuccess criteria:\n${(subtask.success_criteria || []).map((c) => `- ${c}`).join("\n")}${scopePrompt}`;
100
- const subagentArgs = {
101
- task: taskPrompt,
102
- allowed_files: allowedFiles,
103
- read_only_files: readOnlyFiles,
104
- tool_tags: expertConfig.tool_tags,
105
- };
106
- if (deps.config.subagent?.resultMode === "file") {
107
- subagentArgs.result_mode = "file";
108
- subagentArgs.artifact_name = subtask.id;
109
- }
110
- const result = await subagentTool.handler({
111
- config: deps.config,
112
- baseDir: deps.baseDir,
113
- logger: deps.logger,
114
- llmProvider: deps.llmProvider,
115
- toolExecutor: deps.toolExecutor,
116
- sessionId: "moe",
117
- }, subagentArgs);
118
- if (result.success) {
119
- if (deps.config.subagent?.resultMode === "file") {
120
- const pathMatch = result.output.match(/saved to artifact: (.+)/);
121
- const abs = pathMatch ? pathMatch[1].trim() : "";
122
- if (abs) {
123
- const store = new ArtifactStore({
124
- baseDir: deps.baseDir,
125
- sessionId: "moe",
126
- });
127
- const full = store.read(abs.split(/[\\/]/).pop() || ""); // file name only, scoped to root
128
- deps.logger.debug(`MoE subtask "${subtask.id}" attached artifact ${abs} (${full?.length ?? 0} chars) to Router`);
129
- return {
130
- subtaskId: subtask.id,
131
- success: true,
132
- summary: `Artifact: ${abs}`,
133
- result: full ?? result.output,
134
- durationMs: Date.now() - startTime,
135
- };
136
- }
137
- }
138
- return {
139
- subtaskId: subtask.id,
140
- success: true,
141
- summary: `Completed: ${subtask.id}`,
142
- result: result.output,
143
- durationMs: Date.now() - startTime,
144
- };
145
- }
146
- lastError = result.output;
147
- lastResult = result;
148
- stuckDetector.recordToolError("subagent", result.output);
149
- // Inject actionable hints into the next retry's prompt
150
- if (attempt < maxAttempts) {
151
- const hints = stuckDetector.getActionableHints();
152
- const recovery = stuckDetector.getRecoveryMessage();
153
- if (hints.length > 0) {
154
- deps.logger.debug(`Hint for subtask "${subtask.id}" retry: ${hints.join("; ")}`);
155
- }
156
- if (recovery) {
157
- deps.logger.debug(`Recovery for subtask "${subtask.id}": ${recovery}`);
158
- }
159
- }
160
- if (isTransientError(lastError) && attempt < maxAttempts) {
161
- const delay = Math.min(1000 * Math.pow(2, attempt - 1), 8000);
162
- deps.logger.debug(`Retrying subtask "${subtask.id}" (attempt ${attempt}/${maxAttempts}) after ${delay}ms: transient error`);
163
- await sleep(delay);
164
- continue;
165
- }
166
- // Non-transient failure — build detailed error with hints
167
- const hints = stuckDetector.getActionableHints();
168
- let errorDetail = result.output;
169
- if (hints.length > 0) {
170
- errorDetail += `\n\n${t("exec.hints", { hints: hints.map((h) => `- ${h}`).join("\n") })}`;
171
- }
172
- if (lastError) {
173
- errorDetail +=
174
- "\n\nIf relevant skills are available, consider loading one with load_skill for expert guidance.";
175
- }
176
- return {
177
- subtaskId: subtask.id,
178
- success: false,
179
- summary: `Failed: ${subtask.id}`,
180
- result: result.output,
181
- error: errorDetail,
182
- durationMs: Date.now() - startTime,
183
- };
184
- }
185
- catch (e) {
186
- lastError = e.message;
187
- stuckDetector.recordToolError("subagent", e.message);
188
- if (isTransientError(lastError) && attempt < maxAttempts) {
189
- const delay = Math.min(1000 * Math.pow(2, attempt - 1), 8000);
190
- deps.logger.debug(`Retrying subtask "${subtask.id}" (attempt ${attempt}/${maxAttempts}) after ${delay}ms: ${lastError}`);
191
- await sleep(delay);
192
- continue;
193
- }
194
- const hints = stuckDetector.getActionableHints();
195
- let errorDetail = e.message;
196
- if (hints.length > 0) {
197
- errorDetail += `\n\n${t("exec.hints", { hints: hints.map((h) => `- ${h}`).join("\n") })}`;
198
- }
199
- if (lastError) {
200
- errorDetail +=
201
- "\n\nIf relevant skills are available, consider loading one with load_skill for expert guidance.";
202
- }
203
- return {
204
- subtaskId: subtask.id,
205
- success: false,
206
- summary: `Error: ${subtask.id}`,
207
- result: "",
208
- error: errorDetail,
209
- durationMs: Date.now() - startTime,
210
- };
211
- }
212
- }
213
- // Exhausted retries — build detailed failure
214
- const stuckReason = stuckDetector.getStuckReason();
215
- let finalError = lastError;
216
- if (stuckReason) {
217
- finalError += `\n${stuckReason}`;
218
- }
219
- return {
220
- subtaskId: subtask.id,
221
- success: false,
222
- summary: `Failed after ${maxAttempts} attempts: ${subtask.id}`,
223
- result: "",
224
- error: finalError,
225
- durationMs: Date.now() - startTime,
226
- };
227
- }
228
- export class MoEExecutor {
229
- deps;
230
- constructor(deps) {
231
- this.deps = deps;
232
- }
233
- async executePlan(plan) {
234
- const results = [];
235
- const errors = [];
236
- const warnings = [];
237
- const waves = topologicalSort(plan.subtasks);
238
- if (waves.length === 0) {
239
- return {
240
- success: false,
241
- results: [],
242
- errors: ["Failed to topologically sort subtasks (possible cycle)"],
243
- warnings: [],
244
- };
245
- }
246
- // Verify all subtasks are included — catch silent drops from unresolved dependencies
247
- const sortedCount = waves.flat().length;
248
- if (sortedCount < plan.subtasks.length) {
249
- const missing = plan.subtasks
250
- .filter((s) => !waves.flat().some((w) => w.id === s.id))
251
- .map((s) => s.id);
252
- return {
253
- success: false,
254
- results: [],
255
- errors: [
256
- `Missing subtasks after topological sort: ${missing.join(", ")} (dangling or invalid depends_on)`,
257
- ],
258
- warnings: [],
259
- };
260
- }
261
- for (let waveIdx = 0; waveIdx < waves.length; waveIdx++) {
262
- const wave = waves[waveIdx];
263
- const wavePromises = wave.map((subtask) => executeSubtask(subtask, this.deps, plan.shared_context)
264
- .then((result) => {
265
- results.push(result);
266
- return result;
267
- })
268
- .catch((e) => {
269
- const errResult = {
270
- subtaskId: subtask.id,
271
- success: false,
272
- summary: `Unhandled error: ${subtask.id}`,
273
- result: "",
274
- error: e.message,
275
- durationMs: 0,
276
- };
277
- results.push(errResult);
278
- return errResult;
279
- }));
280
- await Promise.all(wavePromises);
281
- }
282
- const failed = results.filter((r) => !r.success);
283
- if (failed.length > 0) {
284
- errors.push(...failed.map((f) => `[${f.subtaskId}] ${f.error || f.summary}`));
285
- }
286
- return { success: failed.length === 0, results, errors, warnings };
287
- }
288
- getChainMaxAttempts() {
289
- return 3;
290
- }
291
- }
@@ -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,157 +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
- }