micro-models-agent 0.54.1 → 0.55.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 (232) hide show
  1. package/README.md +358 -358
  2. package/dist/certification/certifications.json +493 -493
  3. package/dist/main.js +489 -82
  4. package/dist/modules/browser/bridge-server.mjs +202 -202
  5. package/dist/skills/builtin/git.md +36 -36
  6. package/dist/skills/builtin/typescript.md +35 -35
  7. package/package.json +1 -1
  8. package/dist/cli/commands.js +0 -447
  9. package/dist/cli/completer.js +0 -167
  10. package/dist/cli/index.js +0 -2
  11. package/dist/cli/main.js +0 -153
  12. package/dist/cli/plugin-commands.js +0 -36
  13. package/dist/cli/repl-commands.js +0 -761
  14. package/dist/cli/repl.js +0 -702
  15. package/dist/cli/run-result.js +0 -33
  16. package/dist/cli/security-commands.js +0 -164
  17. package/dist/cli/setup.js +0 -237
  18. package/dist/config/config.js +0 -276
  19. package/dist/config/defaults.js +0 -141
  20. package/dist/config/domains.js +0 -179
  21. package/dist/config/experts.js +0 -15
  22. package/dist/config/index.js +0 -4
  23. package/dist/config/security.js +0 -213
  24. package/dist/config/types.js +0 -1
  25. package/dist/core/agent-moe.js +0 -102
  26. package/dist/core/agent.js +0 -1018
  27. package/dist/core/bootstrap.js +0 -481
  28. package/dist/core/crash-handler.js +0 -51
  29. package/dist/core/environment.js +0 -199
  30. package/dist/core/index.js +0 -2
  31. package/dist/core/prompt-builder.js +0 -76
  32. package/dist/core/session-logger.js +0 -251
  33. package/dist/core/types.js +0 -1
  34. package/dist/core/version.js +0 -26
  35. package/dist/core/workspace.js +0 -76
  36. package/dist/i18n/en.json +0 -679
  37. package/dist/i18n/index.js +0 -46
  38. package/dist/i18n/ru.json +0 -679
  39. package/dist/index.js +0 -22
  40. package/dist/llm/image-utils.js +0 -143
  41. package/dist/llm/index.js +0 -4
  42. package/dist/llm/model-loader.js +0 -78
  43. package/dist/llm/openai-compat.js +0 -497
  44. package/dist/llm/orchestrator.js +0 -200
  45. package/dist/llm/provider.js +0 -10
  46. package/dist/llm/response.js +0 -39
  47. package/dist/llm/token-counter.js +0 -39
  48. package/dist/llm/types.js +0 -1
  49. package/dist/logger/app-logger.js +0 -189
  50. package/dist/logger/file-log.js +0 -151
  51. package/dist/logger/index.js +0 -1
  52. package/dist/migration/backup.js +0 -45
  53. package/dist/migration/detect.js +0 -50
  54. package/dist/migration/index.js +0 -2
  55. package/dist/modules/artifacts/store.js +0 -61
  56. package/dist/modules/browser/actions.js +0 -76
  57. package/dist/modules/browser/bridge-client.js +0 -199
  58. package/dist/modules/browser/bridge-path.js +0 -10
  59. package/dist/modules/browser/cookie-store.js +0 -24
  60. package/dist/modules/browser/driver.js +0 -136
  61. package/dist/modules/browser/index.js +0 -7
  62. package/dist/modules/browser/module.js +0 -29
  63. package/dist/modules/browser/session.js +0 -342
  64. package/dist/modules/browser/snapshot.js +0 -148
  65. package/dist/modules/browser/types.js +0 -12
  66. package/dist/modules/certification/cli.js +0 -213
  67. package/dist/modules/certification/fact-checker.js +0 -82
  68. package/dist/modules/certification/loader.js +0 -106
  69. package/dist/modules/certification/manifest.js +0 -58
  70. package/dist/modules/certification/runner.js +0 -245
  71. package/dist/modules/certification/scenarios.js +0 -407
  72. package/dist/modules/certification/types.js +0 -1
  73. package/dist/modules/context/chunk-query.js +0 -100
  74. package/dist/modules/context/fact-extractor.js +0 -168
  75. package/dist/modules/context/history.js +0 -15
  76. package/dist/modules/context/index.js +0 -1
  77. package/dist/modules/context/manager.js +0 -440
  78. package/dist/modules/execution/audit-runners.js +0 -206
  79. package/dist/modules/execution/auditor.js +0 -218
  80. package/dist/modules/execution/execution-plugin.js +0 -431
  81. package/dist/modules/execution/index.js +0 -8
  82. package/dist/modules/execution/module.js +0 -625
  83. package/dist/modules/execution/moe-executor.js +0 -304
  84. package/dist/modules/execution/plan-coverage.js +0 -68
  85. package/dist/modules/execution/plan-persister.js +0 -46
  86. package/dist/modules/execution/plan-store.js +0 -196
  87. package/dist/modules/execution/plan-tool.js +0 -677
  88. package/dist/modules/execution/plan-validator.js +0 -153
  89. package/dist/modules/execution/planner.js +0 -94
  90. package/dist/modules/execution/stuck-detector.js +0 -746
  91. package/dist/modules/execution/tracker.js +0 -69
  92. package/dist/modules/execution/types.js +0 -1
  93. package/dist/modules/execution/verifier.js +0 -235
  94. package/dist/modules/execution/windows-commands.js +0 -41
  95. package/dist/modules/hallucination/confidence.js +0 -66
  96. package/dist/modules/hallucination/consistency.js +0 -26
  97. package/dist/modules/hallucination/detector.js +0 -47
  98. package/dist/modules/hallucination/factual.js +0 -169
  99. package/dist/modules/hallucination/index.js +0 -5
  100. package/dist/modules/hallucination/js-identifiers.js +0 -262
  101. package/dist/modules/hallucination/llm-judge.js +0 -101
  102. package/dist/modules/index.js +0 -5
  103. package/dist/modules/indexer/cache.js +0 -40
  104. package/dist/modules/indexer/index.js +0 -3
  105. package/dist/modules/indexer/module.js +0 -246
  106. package/dist/modules/indexer/project-profile.js +0 -183
  107. package/dist/modules/indexer/walker.js +0 -101
  108. package/dist/modules/lsp/check-tool.js +0 -58
  109. package/dist/modules/lsp/client.js +0 -389
  110. package/dist/modules/lsp/command.js +0 -60
  111. package/dist/modules/lsp/config.js +0 -135
  112. package/dist/modules/lsp/index.js +0 -3
  113. package/dist/modules/lsp/module.js +0 -260
  114. package/dist/modules/lsp/probe.js +0 -86
  115. package/dist/modules/lsp/project-root.js +0 -32
  116. package/dist/modules/lsp/startup-check.js +0 -144
  117. package/dist/modules/lsp/types.js +0 -1
  118. package/dist/modules/mcp/client.js +0 -399
  119. package/dist/modules/mcp/index.js +0 -3
  120. package/dist/modules/mcp/module.js +0 -142
  121. package/dist/modules/mcp/registry.js +0 -15
  122. package/dist/modules/memory/index.js +0 -1
  123. package/dist/modules/memory/module.js +0 -96
  124. package/dist/modules/memory/search.js +0 -42
  125. package/dist/modules/memory/store.js +0 -69
  126. package/dist/modules/pipelines/engine.js +0 -60
  127. package/dist/modules/pipelines/index.js +0 -3
  128. package/dist/modules/pipelines/parser.js +0 -56
  129. package/dist/modules/pipelines/template.js +0 -14
  130. package/dist/modules/plugins/builtin/lint-on-write.js +0 -334
  131. package/dist/modules/plugins/builtin/notify.js +0 -9
  132. package/dist/modules/plugins/index.js +0 -1
  133. package/dist/modules/plugins/loader.js +0 -70
  134. package/dist/modules/plugins/manager.js +0 -261
  135. package/dist/modules/plugins/types.js +0 -1
  136. package/dist/modules/pricing/index.js +0 -61
  137. package/dist/modules/pricing/prices.js +0 -129
  138. package/dist/modules/processes/detect.js +0 -34
  139. package/dist/modules/processes/index.js +0 -2
  140. package/dist/modules/processes/registry.js +0 -327
  141. package/dist/modules/processes/runner.js +0 -23
  142. package/dist/modules/providers/create.js +0 -22
  143. package/dist/modules/providers/fallback.js +0 -79
  144. package/dist/modules/providers/health.js +0 -46
  145. package/dist/modules/providers/index.js +0 -5
  146. package/dist/modules/providers/manager.js +0 -161
  147. package/dist/modules/providers/presets.js +0 -128
  148. package/dist/modules/providers/registry.js +0 -22
  149. package/dist/modules/providers/types.js +0 -1
  150. package/dist/modules/registry.js +0 -48
  151. package/dist/modules/security/audit-log.js +0 -136
  152. package/dist/modules/security/audit-notifier.js +0 -292
  153. package/dist/modules/security/command-validator.js +0 -219
  154. package/dist/modules/security/content-scanner.js +0 -53
  155. package/dist/modules/security/data-sanitizer.js +0 -89
  156. package/dist/modules/security/encryption.js +0 -242
  157. package/dist/modules/security/index.js +0 -14
  158. package/dist/modules/security/network-validator.js +0 -88
  159. package/dist/modules/security/path-validator.js +0 -203
  160. package/dist/modules/security/rate-limiter.js +0 -119
  161. package/dist/modules/security/security-policies.js +0 -531
  162. package/dist/modules/security/session-encryption.js +0 -210
  163. package/dist/modules/security/session-isolation.js +0 -95
  164. package/dist/modules/session/index.js +0 -3
  165. package/dist/modules/session/manager.js +0 -172
  166. package/dist/modules/session/module.js +0 -24
  167. package/dist/modules/session/store.js +0 -222
  168. package/dist/modules/session/types.js +0 -1
  169. package/dist/modules/skills/index.js +0 -2
  170. package/dist/modules/skills/loader.js +0 -72
  171. package/dist/modules/skills/matcher.js +0 -27
  172. package/dist/modules/skills/module.js +0 -129
  173. package/dist/modules/types.js +0 -1
  174. package/dist/modules/updater/checker.js +0 -96
  175. package/dist/modules/updater/index.js +0 -2
  176. package/dist/modules/updater/module.js +0 -116
  177. package/dist/modules/user-profile/compressor.js +0 -16
  178. package/dist/modules/user-profile/index.js +0 -1
  179. package/dist/modules/user-profile/profile.js +0 -68
  180. package/dist/tools/approve.js +0 -33
  181. package/dist/tools/attach-image.js +0 -101
  182. package/dist/tools/bash.js +0 -519
  183. package/dist/tools/browser.js +0 -115
  184. package/dist/tools/chunk-query.js +0 -100
  185. package/dist/tools/create-dir.js +0 -56
  186. package/dist/tools/delete-file.js +0 -63
  187. package/dist/tools/download-file.js +0 -117
  188. package/dist/tools/edit-file.js +0 -80
  189. package/dist/tools/enable-tools.js +0 -59
  190. package/dist/tools/executor.js +0 -154
  191. package/dist/tools/file-info.js +0 -47
  192. package/dist/tools/filter-tools.js +0 -17
  193. package/dist/tools/glob-tool.js +0 -27
  194. package/dist/tools/grep-tool.js +0 -125
  195. package/dist/tools/hidden-tools-block.js +0 -37
  196. package/dist/tools/index.js +0 -78
  197. package/dist/tools/list-dir.js +0 -49
  198. package/dist/tools/load-skill.js +0 -43
  199. package/dist/tools/mcp-call.js +0 -69
  200. package/dist/tools/move-file.js +0 -86
  201. package/dist/tools/path-utils.js +0 -101
  202. package/dist/tools/pipeline-run.js +0 -145
  203. package/dist/tools/preview.js +0 -2
  204. package/dist/tools/process-kill.js +0 -40
  205. package/dist/tools/process-list.js +0 -37
  206. package/dist/tools/process-log.js +0 -54
  207. package/dist/tools/question.js +0 -141
  208. package/dist/tools/read-file.js +0 -179
  209. package/dist/tools/recall.js +0 -118
  210. package/dist/tools/registry.js +0 -47
  211. package/dist/tools/remember.js +0 -68
  212. package/dist/tools/scope-check.js +0 -32
  213. package/dist/tools/search-history.js +0 -85
  214. package/dist/tools/subagent.js +0 -196
  215. package/dist/tools/types.js +0 -1
  216. package/dist/tools/user-input.js +0 -123
  217. package/dist/tools/web-browse.js +0 -87
  218. package/dist/tools/web-fetch.js +0 -119
  219. package/dist/tools/web-search.js +0 -105
  220. package/dist/tools/write-file.js +0 -82
  221. package/dist/ui/box.js +0 -77
  222. package/dist/ui/colors.js +0 -4
  223. package/dist/ui/diff.js +0 -178
  224. package/dist/ui/index.js +0 -6
  225. package/dist/ui/line-editor.js +0 -822
  226. package/dist/ui/line-math.js +0 -73
  227. package/dist/ui/md-formatter.js +0 -212
  228. package/dist/ui/output.js +0 -13
  229. package/dist/ui/plan-view.js +0 -103
  230. package/dist/ui/renderer.js +0 -259
  231. package/dist/ui/spinner.js +0 -70
  232. package/dist/ui/table.js +0 -144
@@ -1,73 +0,0 @@
1
- import stringWidth from "string-width";
2
- const ANSI_RE = /\x1b\[[0-9;?]*[ -/]*[@-~]/g;
3
- export function stripAnsi(s) {
4
- return s.replace(ANSI_RE, "");
5
- }
6
- export function charLen(s) {
7
- return Array.from(s).length;
8
- }
9
- export function wrapLine(line, width, firstRowWidth) {
10
- const w = width > 0 ? width : 80;
11
- // Only the FIRST visual row shares its screen line with something else
12
- // (e.g. the prompt); every continuation row uses the full width.
13
- let limit = firstRowWidth !== undefined && firstRowWidth > 0 ? firstRowWidth : w;
14
- const chars = Array.from(line);
15
- const rows = [];
16
- let start = 0;
17
- let cells = 0;
18
- for (let i = 0; i < chars.length; i++) {
19
- const ch = chars[i];
20
- if (ch === "\n") {
21
- rows.push({ text: chars.slice(start, i).join(""), charStart: start });
22
- start = i + 1;
23
- cells = 0;
24
- continue;
25
- }
26
- const cw = stringWidth(ch);
27
- if (cells + cw > limit && cells > 0) {
28
- rows.push({ text: chars.slice(start, i).join(""), charStart: start });
29
- start = i;
30
- cells = cw;
31
- limit = w;
32
- }
33
- else {
34
- cells += cw;
35
- }
36
- }
37
- rows.push({ text: chars.slice(start).join(""), charStart: start });
38
- return rows;
39
- }
40
- export function buildLayout(lines, width, firstRowWidth) {
41
- const rows = [];
42
- for (let b = 0; b < lines.length; b++) {
43
- for (const r of wrapLine(lines[b], width, b === 0 ? firstRowWidth : undefined)) {
44
- rows.push({ bufRow: b, charStart: r.charStart, text: r.text });
45
- }
46
- }
47
- return rows;
48
- }
49
- export function layoutIndexFor(rows, bufRow, col) {
50
- let idx = 0;
51
- for (let i = 0; i < rows.length; i++) {
52
- if (rows[i].bufRow === bufRow && rows[i].charStart <= col)
53
- idx = i;
54
- }
55
- return idx;
56
- }
57
- export function visualColAt(rows, idx, col) {
58
- const r = rows[idx];
59
- const upTo = col - r.charStart;
60
- return stringWidth(Array.from(r.text).slice(0, upTo).join(""));
61
- }
62
- export function charOffsetFor(rows, idx, visualCol) {
63
- const r = rows[idx];
64
- const chars = Array.from(r.text);
65
- let cells = 0;
66
- for (let i = 0; i < chars.length; i++) {
67
- const cw = stringWidth(chars[i]);
68
- if (cells + cw > visualCol)
69
- return r.charStart + i;
70
- cells += cw;
71
- }
72
- return r.charStart + chars.length;
73
- }
@@ -1,212 +0,0 @@
1
- import { pc } from "./colors";
2
- import { t } from "../i18n/index";
3
- import { formatTable, getTerminalWidth } from "./table";
4
- const KW = /\b(import|export|from|const|let|var|function|return|if|else|for|while|do|switch|case|break|continue|new|class|extends|implements|interface|type|enum|namespace|module|declare|abstract|async|await|yield|throw|try|catch|finally|typeof|instanceof|in|of|as|is|keyof|readonly|static|private|public|protected|get|set|constructor|this|super|void|never|any|unknown|boolean|string|number|symbol|object|true|false|null|undefined|default)\b/g;
5
- const STRING = /('[^']*'|"[^"]*"|`[^`]*`)/g;
6
- const COMMENT = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|#[^\n]*)/g;
7
- const NUMBER = /\b(\d+\.?\d*)\b/g;
8
- const TAG = /<\/?([A-Z][a-zA-Z0-9]*|[a-z][a-zA-Z0-9-]*)/g;
9
- const ATTR = /\b([a-zA-Z-]+=)"([^"]*)"/g;
10
- function highlight(code, lang) {
11
- if (lang === "html" || lang === "xml" || lang === "svg") {
12
- code = code.replace(COMMENT, (m) => pc.dim(pc.green(m)));
13
- code = code.replace(ATTR, (_m, attr, val) => pc.yellow(attr) + "=" + pc.green('"' + val + '"'));
14
- code = code.replace(TAG, (_m, tag) => "<" + pc.cyan(tag));
15
- }
16
- else if (lang === "css" || lang === "scss" || lang === "less") {
17
- code = code.replace(COMMENT, (m) => pc.dim(pc.green(m)));
18
- code = code.replace(STRING, (m) => pc.green(m));
19
- code = code.replace(NUMBER, (m) => pc.yellow(m));
20
- }
21
- else if (lang === "bash" || lang === "sh" || lang === "shell" || lang === "zsh") {
22
- code = code.replace(COMMENT, (m) => pc.dim(pc.green(m)));
23
- code = code.replace(STRING, (m) => pc.green(m));
24
- }
25
- else if (lang === "json") {
26
- code = code.replace(STRING, (m) => pc.green(m));
27
- code = code.replace(NUMBER, (m) => pc.yellow(m));
28
- }
29
- else {
30
- // js, ts, jsx, tsx, and fallback
31
- code = code.replace(COMMENT, (m) => pc.dim(pc.green(m)));
32
- code = code.replace(STRING, (m) => pc.green(m));
33
- code = code.replace(KW, (m) => pc.magenta(m));
34
- code = code.replace(NUMBER, (m) => pc.yellow(m));
35
- }
36
- return code;
37
- }
38
- function isTableRow(line) {
39
- const trimmed = line.trim();
40
- if (!trimmed.startsWith("|"))
41
- return false;
42
- const pipes = trimmed.match(/\|/g);
43
- return (pipes?.length ?? 0) >= 2;
44
- }
45
- function isHorizontalRule(line) {
46
- return /^(-{3,}|\*{3,}|_{3,})\s*$/.test(line.trim());
47
- }
48
- export class FormattingStream {
49
- buffer = "";
50
- inCodeBlock = false;
51
- codeLang = "";
52
- codeLines = [];
53
- tableBuffer = [];
54
- onWrite;
55
- width;
56
- constructor(onWrite, width) {
57
- this.onWrite = onWrite;
58
- this.width = width ?? getTerminalWidth();
59
- }
60
- write(chunk) {
61
- this.buffer += chunk;
62
- let idx;
63
- while ((idx = this.buffer.indexOf("\n")) !== -1) {
64
- const line = this.buffer.slice(0, idx);
65
- this.buffer = this.buffer.slice(idx + 1);
66
- this.processLine(line);
67
- }
68
- }
69
- flush() {
70
- if (this.inCodeBlock && this.codeLines.length > 0) {
71
- this.emitCodeBlock();
72
- }
73
- if (this.tableBuffer.length > 0) {
74
- this.flushTable();
75
- }
76
- if (this.buffer.length > 0) {
77
- const line = this.buffer;
78
- this.buffer = "";
79
- if (line.trim() === "```" || line.trim().startsWith("```")) {
80
- if (this.codeLines.length > 0) {
81
- this.emitCodeBlock();
82
- }
83
- return;
84
- }
85
- this.onWrite(this.formatLine(line));
86
- }
87
- }
88
- processLine(line) {
89
- if (line.trim() === "```" || line.trim().startsWith("```")) {
90
- if (this.inCodeBlock) {
91
- this.emitCodeBlock();
92
- }
93
- else {
94
- this.inCodeBlock = true;
95
- this.codeLang = line.trim().slice(3).trim();
96
- this.codeLines = [];
97
- }
98
- return;
99
- }
100
- if (this.inCodeBlock) {
101
- this.codeLines.push(line);
102
- return;
103
- }
104
- if (isTableRow(line)) {
105
- this.tableBuffer.push(line);
106
- return;
107
- }
108
- if (this.tableBuffer.length > 0) {
109
- this.flushTable();
110
- }
111
- this.onWrite(this.formatLine(line));
112
- }
113
- flushTable() {
114
- const lines = this.tableBuffer;
115
- this.tableBuffer = [];
116
- const hasSeparator = lines.length >= 2 && /^\s*\|?[\s:|-]+\|?\s*$/.test(lines[1].trim());
117
- if (hasSeparator) {
118
- for (const l of formatTable(lines, { maxWidth: this.width })) {
119
- this.onWrite(l);
120
- }
121
- }
122
- else {
123
- for (const l of lines) {
124
- this.onWrite(this.formatLine(l));
125
- }
126
- }
127
- }
128
- emitCodeBlock() {
129
- this.inCodeBlock = false;
130
- if (this.codeLines.length > 0) {
131
- const code = this.codeLines.join("\n");
132
- const highlighted = highlight(code, this.codeLang);
133
- const lang = this.codeLang ? ` ${this.codeLang} ` : " ";
134
- const top = pc.dim(`┌─${lang}${"─".repeat(Math.max(0, this.width - 3 - lang.length))}┐`);
135
- this.onWrite(top);
136
- for (const l of highlighted.split("\n")) {
137
- this.onWrite(pc.dim("│ ") + l);
138
- }
139
- this.onWrite(pc.dim(`└${"─".repeat(Math.max(0, this.width - 1))}┘`));
140
- }
141
- this.codeLines = [];
142
- this.codeLang = "";
143
- }
144
- formatLine(line) {
145
- let result = line;
146
- const heading = result.match(/^(#{1,6})\s+(.+)$/);
147
- if (heading) {
148
- const level = heading[1].length;
149
- const content = this.formatInline(heading[2]);
150
- if (level === 1)
151
- return pc.cyan(pc.bold(pc.underline(content)));
152
- return pc.cyan(pc.bold(content));
153
- }
154
- if (isHorizontalRule(result)) {
155
- return pc.dim("─".repeat(Math.max(0, Math.min(this.width, 60))));
156
- }
157
- const quote = result.match(/^(>+)\s?(.*)$/);
158
- if (quote) {
159
- const depth = Math.min(quote[1].length, 4);
160
- const marker = pc.dim("▍".repeat(depth));
161
- return `${marker} ${this.formatInline(quote[2])}`;
162
- }
163
- const checkbox = result.match(/^[-*]\s+\[([ xX])\]\s+(.+)$/);
164
- if (checkbox) {
165
- const checked = checkbox[1].toLowerCase() === "x";
166
- const mark = checked ? pc.green("✓") : pc.dim("☐");
167
- return ` ${mark} ${this.formatInline(checkbox[2])}`;
168
- }
169
- const ordered = result.match(/^(\d+)[.)]\s+(.+)$/);
170
- if (ordered) {
171
- return ` ${pc.yellow(ordered[1])}. ${this.formatInline(ordered[2])}`;
172
- }
173
- const bullet = result.match(/^[-*]\s+(.+)$/);
174
- if (bullet) {
175
- return ` ${pc.dim("•")} ${this.formatInline(bullet[1])}`;
176
- }
177
- return this.formatInline(result);
178
- }
179
- formatInline(text) {
180
- const codeSpans = [];
181
- let result = text.replace(/`([^`]+)`/g, (_m, c) => {
182
- codeSpans.push(pc.yellow(c));
183
- return `\u0000${codeSpans.length - 1}\u0000`;
184
- });
185
- result = result.replace(/\*\*(.+?)\*\*/g, (_, s) => pc.bold(s));
186
- result = result.replace(/~~(.+?)~~/g, (_, s) => pc.strikethrough(s));
187
- result = result.replace(/\*([^*]+)\*/g, (_, s) => pc.italic(s));
188
- result = result.replace(/(^|\s)_([^_\n]+)_(?=\s|$)/g, (_m, pre, s) => pre + pc.italic(s));
189
- result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, label, url) => {
190
- const short = url.length > 80 ? url.slice(0, 77) + "…" : url;
191
- return `${pc.cyan(label)} ${pc.dim(`(${short})`)}`;
192
- });
193
- result = result.replace(/\u0000(\d+)\u0000/g, (_m, i) => codeSpans[Number(i)]);
194
- return result;
195
- }
196
- }
197
- export function formatMarkdown(text) {
198
- const lines = [];
199
- const stream = new FormattingStream((l) => lines.push(l));
200
- stream.write(text);
201
- stream.flush();
202
- return lines.join("\n");
203
- }
204
- export function formatError(text) {
205
- return pc.red(pc.bold(t("ui.error_prefix")) + text);
206
- }
207
- export function formatSuccess(text) {
208
- return pc.green(pc.bold(t("ui.success_prefix")) + text);
209
- }
210
- export function formatWarning(text) {
211
- return pc.yellow(pc.bold(t("ui.warning_prefix")) + text);
212
- }
package/dist/ui/output.js DELETED
@@ -1,13 +0,0 @@
1
- import { formatMarkdown, formatError, formatSuccess, formatWarning } from "./md-formatter";
2
- export function writeOutput(text) {
3
- process.stdout.write(formatMarkdown(text) + "\n");
4
- }
5
- export function writeError(text) {
6
- process.stderr.write(formatError(text) + "\n");
7
- }
8
- export function writeSuccess(text) {
9
- process.stdout.write(formatSuccess(text) + "\n");
10
- }
11
- export function writeWarning(text) {
12
- process.stdout.write(formatWarning(text) + "\n");
13
- }
@@ -1,103 +0,0 @@
1
- import { existsSync, readFileSync } from "fs";
2
- import { join } from "path";
3
- import { pc } from "./colors";
4
- import { extractFileLikeTokens, stripUrls } from "../modules/hallucination/js-identifiers";
5
- import { t } from "../i18n/index";
6
- export function readActivePlan(baseDir) {
7
- const p = join(baseDir, ".mma", "plans", "active.json");
8
- if (!existsSync(p))
9
- return null;
10
- try {
11
- const raw = readFileSync(p, "utf-8");
12
- if (!raw.trim())
13
- return null;
14
- const parsed = JSON.parse(raw);
15
- if (!parsed || !Array.isArray(parsed.steps))
16
- return null;
17
- return {
18
- id: parsed.id || "plan",
19
- title: parsed.title || "Plan",
20
- steps: parsed.steps,
21
- createdAt: parsed.createdAt || new Date().toISOString(),
22
- baseDir: parsed.baseDir || baseDir,
23
- name: parsed.name,
24
- };
25
- }
26
- catch {
27
- return null;
28
- }
29
- }
30
- export function currentStepIndex(plan) {
31
- const idx = plan.steps.findIndex((s) => s.status !== "done" && s.status !== "skipped");
32
- return idx === -1 ? 0 : idx;
33
- }
34
- function stepMark(step) {
35
- switch (step.status) {
36
- case "done":
37
- return pc.green("[x]");
38
- case "in_progress":
39
- return pc.yellow("[*]");
40
- case "failed":
41
- return pc.red("[!]");
42
- case "skipped":
43
- return pc.dim("[-]");
44
- default:
45
- return pc.dim("[ ]");
46
- }
47
- }
48
- export function formatPlanChecklist(plan) {
49
- const done = plan.steps.filter((s) => s.status === "done" || s.status === "skipped").length;
50
- const total = plan.steps.length;
51
- const pct = total === 0 ? 0 : Math.round((done / total) * 100);
52
- const cur = currentStepIndex(plan);
53
- const barLen = 15;
54
- const filled = Math.round((pct / 100) * barLen);
55
- const bar = pc.green("█".repeat(filled)) + pc.dim("░".repeat(barLen - filled));
56
- const title = plan.title.replace(/^\[\d+[^]]*\]\s*/, "");
57
- const lines = [
58
- `${pc.cyan(`[${plan.id}]`)} ${pc.bold(title)} ${bar} ${pc.dim(`${done}/${total} ${pct}%`)}`,
59
- ];
60
- for (let i = 0; i < plan.steps.length; i++) {
61
- const step = plan.steps[i];
62
- const active = i === cur;
63
- const desc = active ? pc.yellow(step.description) : pc.dim(step.description);
64
- lines.push(` ${stepMark(step)} ${step.id}. ${desc}`);
65
- for (const sub of step.subtasks ?? []) {
66
- lines.push(` ${sub.done ? pc.green("[x]") : pc.dim("[ ]")} ${sub.text}`);
67
- }
68
- }
69
- return lines;
70
- }
71
- const STRUCTURAL_TOOLS = new Set([
72
- "plan",
73
- "todo",
74
- "verify",
75
- "project_map",
76
- "lsp_check",
77
- "enable_tools",
78
- ]);
79
- function truncate(s, max = 48) {
80
- return s.length > max ? `${s.slice(0, max - 1)}…` : s;
81
- }
82
- export function stepContextForTool(plan, tool, args) {
83
- if (!plan || STRUCTURAL_TOOLS.has(tool))
84
- return null;
85
- const argStr = JSON.stringify(args);
86
- const callPaths = extractFileLikeTokens(stripUrls(argStr)).map((p) => p.toLowerCase());
87
- if (callPaths.length > 0) {
88
- for (const step of plan.steps) {
89
- if (step.status === "done" || step.status === "skipped")
90
- continue;
91
- const stepPaths = extractFileLikeTokens(stripUrls(step.description)).map((p) => p.toLowerCase());
92
- if (stepPaths.length > 0 &&
93
- stepPaths.some((s) => callPaths.some((c) => c.includes(s) || s.includes(c)))) {
94
- return t("ui.step_context", { id: step.id, desc: truncate(step.description) });
95
- }
96
- }
97
- }
98
- const cur = currentStepIndex(plan);
99
- const step = plan.steps[cur];
100
- if (!step)
101
- return null;
102
- return t("ui.step_context", { id: step.id, desc: truncate(step.description) });
103
- }
@@ -1,259 +0,0 @@
1
- import { pc } from "./colors";
2
- import { FormattingStream } from "./md-formatter";
3
- import { Spinner } from "./spinner";
4
- import { box, divider } from "./box";
5
- import { getTerminalWidth } from "./table";
6
- import { t } from "../i18n/index";
7
- import { formatCost } from "../modules/pricing/prices";
8
- import { isAbsolute, relative, sep } from "path";
9
- function formatUsd(cost) {
10
- return formatCost(cost);
11
- }
12
- /** Tools whose `path` argument is shown in the header. */
13
- const PATH_TOOLS = new Set([
14
- "read_file",
15
- "write_file",
16
- "edit_file",
17
- "delete_file",
18
- "create_dir",
19
- "move_file",
20
- "list_dir",
21
- "file_info",
22
- ]);
23
- function toDisplayPath(baseDir, p) {
24
- if (!baseDir || !isAbsolute(p))
25
- return p;
26
- const rel = relative(baseDir, p);
27
- // Outside baseDir (../ prefix) or another drive (absolute result) → keep as-is.
28
- if (!rel || rel.startsWith("..") || isAbsolute(rel))
29
- return p;
30
- return rel.split(sep).join("/");
31
- }
32
- const GUTTER = " ";
33
- /** Tools that show a busy spinner while running (inline mode). */
34
- const BUSY_TOOLS = new Set(["lsp_check"]);
35
- /** opencode-like leading marker per tool category. */
36
- export function toolMarker(tool) {
37
- switch (tool) {
38
- case "write_file":
39
- case "edit_file":
40
- case "create_dir":
41
- case "move_file":
42
- case "delete_file":
43
- return "←";
44
- case "read_file":
45
- case "list_dir":
46
- case "file_info":
47
- return "→";
48
- case "glob":
49
- case "grep":
50
- return "✱";
51
- case "bash":
52
- return "$";
53
- default:
54
- return "⚙";
55
- }
56
- }
57
- export function isRichTerminal() {
58
- return Boolean(process.stdout.isTTY) && !process.env.CI;
59
- }
60
- /** Short human-friendly summary of tool arguments. */
61
- export function summarizeArgs(args) {
62
- const preferred = ["path", "file", "query", "url", "command", "name"];
63
- for (const key of preferred) {
64
- const value = args[key];
65
- if (typeof value === "string" && value) {
66
- return value.length > 60 ? `${value.slice(0, 57)}…` : value;
67
- }
68
- }
69
- const serialized = JSON.stringify(args);
70
- if (!serialized || serialized === "{}")
71
- return "";
72
- return serialized.length > 60 ? `${serialized.slice(0, 57)}…` : serialized;
73
- }
74
- function friendlyTool(tool) {
75
- const key = `tool.friendly.${tool}`;
76
- const value = t(key);
77
- return value !== key ? value : tool;
78
- }
79
- /**
80
- * Streams agent events to the terminal. Rich mode (TTY) adds a spinner
81
- * and boxed tool cards; plain mode falls back to simple prefixed lines.
82
- * Colors come from `colors.ts`, disabled outside a TTY, in CI, or on NO_COLOR.
83
- */
84
- export class Renderer {
85
- rich;
86
- spinner;
87
- fmt;
88
- out;
89
- err;
90
- width;
91
- toolStyle;
92
- baseDir;
93
- card = null;
94
- constructor(opts = {}) {
95
- this.rich = opts.rich ?? isRichTerminal();
96
- this.out = opts.out ?? process.stdout;
97
- this.err = opts.err ?? process.stderr;
98
- this.width = opts.width ?? getTerminalWidth();
99
- this.toolStyle = opts.toolStyle ?? "inline";
100
- this.baseDir = opts.baseDir;
101
- this.spinner = new Spinner({
102
- enabled: this.rich && (opts.spinner ?? true),
103
- stream: this.err,
104
- width: this.width,
105
- });
106
- this.fmt = new FormattingStream((line) => this.out.write(`${line}\n`), this.width);
107
- }
108
- /** Final answer streamed from the model (markdown-formatted). */
109
- text(chunk) {
110
- this.endCard();
111
- this.spinner.stop();
112
- this.fmt.write(chunk);
113
- }
114
- /** Arbitrary status/meta text (tool output, reasoning, MoE status). */
115
- meta(chunk) {
116
- this.spinner.stop();
117
- if (this.card) {
118
- if (this.toolStyle === "inline") {
119
- this.writeInlineBody(chunk);
120
- }
121
- else {
122
- this.card.body.push(chunk);
123
- }
124
- }
125
- else {
126
- this.out.write(chunk);
127
- }
128
- }
129
- /** Stream tool body lines with the gutter prefix, skipping blank lines. */
130
- writeInlineBody(chunk) {
131
- for (const line of chunk.split("\n")) {
132
- if (line.trim() === "")
133
- continue;
134
- this.out.write(`${GUTTER}${line}\n`);
135
- }
136
- }
137
- /** Dimmed reasoning stream (already colored by the agent). */
138
- reasoning(chunk) {
139
- this.spinner.stop();
140
- this.out.write(pc.dim(chunk));
141
- }
142
- /** Model is loading / generating — show the thinking spinner. */
143
- thinkingStart() {
144
- this.spinner.start(t("ui.thinking"));
145
- }
146
- /** LLM call finished; clear the thinking spinner. */
147
- thinkingEnd() {
148
- this.spinner.stop();
149
- }
150
- toolStart(tool, args, stepContext, icon) {
151
- this.endCard();
152
- this.spinner.stop();
153
- const displayArgs = PATH_TOOLS.has(tool) && typeof args.path === "string"
154
- ? { ...args, path: toDisplayPath(this.baseDir, args.path) }
155
- : args;
156
- const summary = summarizeArgs(displayArgs);
157
- const step = stepContext ? ` ${pc.cyan(`← ${stepContext}`)}` : "";
158
- const marker = icon || toolMarker(tool);
159
- if (!this.rich) {
160
- this.out.write(`\n${pc.dim(marker)} ${friendlyTool(tool)}${summary ? ` ${pc.dim(summary)}` : ""}${step}\n`);
161
- return;
162
- }
163
- this.card = { tool, args, body: [], start: Date.now() };
164
- if (this.toolStyle === "inline") {
165
- this.out.write(`\n${pc.dim(marker)} ${friendlyTool(tool)}${summary ? ` ${pc.dim(summary)}` : ""}${step}\n`);
166
- if (BUSY_TOOLS.has(tool)) {
167
- this.spinner.start(t("ui.tool_running", { tool: friendlyTool(tool) }));
168
- }
169
- return;
170
- }
171
- this.spinner.start(`${pc.dim(marker)} ${friendlyTool(tool)}${summary ? ` ${pc.dim(summary)}` : ""}${step}`);
172
- }
173
- /** Live plan checklist — prints the plan block as-is (already colored). */
174
- planBlock(lines) {
175
- this.endCard();
176
- this.spinner.stop();
177
- for (const line of lines) {
178
- this.out.write(`${line}\n`);
179
- }
180
- }
181
- toolEnd(_tool, duration, error, ctxDelta, costUsd, provider, model) {
182
- this.spinner.stop();
183
- const prov = provider && model ? `${pc.dim(`${provider}·${model}`)}` : undefined;
184
- if (!this.rich) {
185
- const parts = [];
186
- if (ctxDelta !== undefined && ctxDelta !== 0) {
187
- const deltaStr = ctxDelta > 0 ? pc.green(`+${ctxDelta}`) : pc.yellow(`${ctxDelta} ↓`);
188
- parts.push(`${pc.dim("ctx")} ${deltaStr}`);
189
- }
190
- if (costUsd !== undefined && costUsd > 0) {
191
- parts.push(`${pc.dim("cost")} ${pc.yellow(formatUsd(costUsd))}`);
192
- }
193
- if (prov)
194
- parts.push(prov);
195
- if (parts.length > 0)
196
- this.out.write(`${parts.join(" ")}\n`);
197
- return;
198
- }
199
- if (!this.card)
200
- return;
201
- const { tool, args, body } = this.card;
202
- const marker = error ? pc.red("✗") : pc.green("✓");
203
- let footer = `${marker} ${pc.dim(`${duration}ms`)}`;
204
- if (ctxDelta !== undefined && ctxDelta !== 0) {
205
- const deltaStr = ctxDelta > 0 ? pc.green(`+${ctxDelta}`) : pc.yellow(`${ctxDelta} ↓`);
206
- footer += ` ${pc.dim("ctx")} ${deltaStr}`;
207
- }
208
- if (costUsd !== undefined && costUsd > 0) {
209
- footer += ` ${pc.dim("cost")} ${pc.yellow(formatUsd(costUsd))}`;
210
- }
211
- if (prov) {
212
- footer += ` ${pc.dim("via")} ${prov}`;
213
- }
214
- if (this.toolStyle === "inline") {
215
- this.out.write(`${GUTTER}${footer}\n`);
216
- this.out.write(`${divider(this.width)}\n`);
217
- this.card = null;
218
- return;
219
- }
220
- const lines = [];
221
- const summary = summarizeArgs(args);
222
- if (summary)
223
- lines.push(pc.dim(summary));
224
- for (const chunk of body) {
225
- for (const line of chunk.split("\n")) {
226
- if (line.trim() !== "")
227
- lines.push(line);
228
- }
229
- }
230
- lines.push(footer);
231
- const title = `${marker} ${friendlyTool(tool)}`;
232
- for (const line of box(lines, { title, width: this.width })) {
233
- this.out.write(`${line}\n`);
234
- }
235
- this.card = null;
236
- }
237
- /** Raw pre-formatted text (diff blocks, warnings). */
238
- raw(text) {
239
- this.endCard();
240
- this.spinner.stop();
241
- this.out.write(text);
242
- }
243
- error(text) {
244
- this.endCard();
245
- this.spinner.stop();
246
- this.err.write(`${pc.red(text)}\n`);
247
- }
248
- flush() {
249
- this.endCard();
250
- this.spinner.stop();
251
- this.fmt.flush();
252
- }
253
- endCard() {
254
- if (!this.card)
255
- return;
256
- const { tool, start } = this.card;
257
- this.toolEnd(tool, Date.now() - start);
258
- }
259
- }