micro-models-agent 0.50.4 → 0.51.2

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 +358 -358
  2. package/dist/main.js +923 -590
  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,198 +0,0 @@
1
- import { OpenAICompatProvider } from "./openai-compat";
2
- import { jsonrepair } from "jsonrepair";
3
- const PLAN_SYSTEM_PROMPT = `You are a planning assistant for an agent system with multiple expert sub-agents.
4
- Break down the user's task into subtasks that can be executed by different expert agents.
5
-
6
- Available experts and their tool tags:
7
- - code: file operations, code editing, shell commands
8
- - research: web search, web fetch, web browse, history search
9
- - browser: browser automation, screenshots
10
- - vision: browser + file reading for visual tasks
11
-
12
- Rules:
13
- 1. Each subtask must have an expert_tag from the available experts.
14
- 2. Use depends_on for ordering when subtask B reads what subtask A writes.
15
- 3. Independent subtasks should NOT depend on each other (they run in parallel).
16
- 4. allowed_files is for files the subtask will CREATE or MODIFY.
17
- 5. read_only_files is for files the subtask needs to READ only.
18
- 6. File paths should be relative to the workspace root.
19
- 7. Do NOT use keyword matching to determine task type. Instead, analyze the actual nature of the task.
20
-
21
- Respond with a JSON object only (no markdown fences):
22
- {
23
- "title": "Plan title",
24
- "subtasks": [
25
- {
26
- "id": "task-1",
27
- "description": "Clear description",
28
- "expert_tag": "code",
29
- "allowed_files": ["src/file.ts"],
30
- "read_only_files": [],
31
- "depends_on": [],
32
- "input_from": [],
33
- "expected_output": "What this subtask produces",
34
- "success_criteria": ["criterion 1", "criterion 2"]
35
- }
36
- ],
37
- "shared_context": {
38
- "rules": ["rule 1"],
39
- "refs": []
40
- }
41
- }`;
42
- const VERIFY_SYSTEM_PROMPT = `You are a verification and merge assistant for an agent system with multiple expert sub-agents.
43
- You receive the original plan, the results from each subtask, and any verification errors.
44
- Your job is to determine if the overall task was completed successfully or if re-planning is needed.
45
-
46
- Respond with JSON only:
47
- - If successful: {"type": "final", "finalAnswer": "summary of results", "explanation": "details"}
48
- - If re-plan needed: {"type": "replan", "plan": {updated MoEPlan}, "explanation": "why re-plan is needed"}
49
-
50
- Max 3 re-plan cycles. After 3 cycles, return partial result.`;
51
- export class OrchestratorClient {
52
- config;
53
- provider = null;
54
- replanCycle = 0;
55
- constructor(config, defaultProvider) {
56
- this.config = config;
57
- if (config.model) {
58
- if (config.provider) {
59
- this.provider = new OpenAICompatProvider({
60
- model: config.model,
61
- baseUrl: config.provider.baseUrl || "http://localhost:1234/v1",
62
- apiKey: config.provider.apiKey,
63
- retry: config.retry,
64
- });
65
- }
66
- else if (defaultProvider) {
67
- this.provider = defaultProvider;
68
- }
69
- else {
70
- this.provider = new OpenAICompatProvider({
71
- model: config.model,
72
- baseUrl: "http://localhost:1234/v1",
73
- retry: config.retry,
74
- });
75
- }
76
- }
77
- }
78
- isEnabled() {
79
- return this.provider !== null;
80
- }
81
- getReplanCycle() {
82
- return this.replanCycle;
83
- }
84
- async chat(messages) {
85
- if (!this.provider)
86
- throw new Error("Orchestrator not enabled");
87
- const chunks = [];
88
- for await (const chunk of this.provider.chat(messages)) {
89
- chunks.push(chunk);
90
- }
91
- return chunks
92
- .filter((c) => c.type === "text")
93
- .map((c) => c.content)
94
- .join("");
95
- }
96
- parseJSON(text) {
97
- try {
98
- return JSON.parse(text);
99
- }
100
- catch {
101
- try {
102
- const repaired = jsonrepair(text);
103
- return JSON.parse(repaired);
104
- }
105
- catch {
106
- const jsonMatch = text.match(/\{[\s\S]*\}/);
107
- if (jsonMatch) {
108
- try {
109
- const repaired = jsonrepair(jsonMatch[0]);
110
- return JSON.parse(repaired);
111
- }
112
- catch {
113
- /* fall through */
114
- }
115
- }
116
- return null;
117
- }
118
- }
119
- }
120
- async plan(userPrompt, _context) {
121
- if (!this.provider)
122
- return { error: "Orchestrator not enabled — no orchestrator model configured" };
123
- const messages = [
124
- { role: "system", content: PLAN_SYSTEM_PROMPT },
125
- { role: "user", content: userPrompt },
126
- ];
127
- const text = await this.chat(messages);
128
- const parsed = this.parseJSON(text);
129
- if (parsed && parsed.subtasks && parsed.subtasks.length > 0) {
130
- return { plan: parsed, raw: text };
131
- }
132
- return { error: `Failed to parse plan from LLM output. Raw: ${text.slice(0, 500)}` };
133
- }
134
- async verifyAndMerge(input) {
135
- if (!this.provider)
136
- return { type: "final", finalAnswer: input.results.map((r) => r.summary).join("\n") };
137
- this.replanCycle++;
138
- if (this.replanCycle > 3) {
139
- return {
140
- type: "final",
141
- finalAnswer: input.results
142
- .map((r) => `${r.subtaskId}: ${r.success ? "OK" : "FAIL"} — ${r.summary}`)
143
- .join("\n"),
144
- explanation: "Max re-plan cycles (3) reached. Returning partial results.",
145
- };
146
- }
147
- const context = JSON.stringify(input, null, 2);
148
- const messages = [
149
- { role: "system", content: VERIFY_SYSTEM_PROMPT },
150
- { role: "user", content: context },
151
- ];
152
- const text = await this.chat(messages);
153
- const parsed = this.parseJSON(text);
154
- if (parsed && parsed.type) {
155
- return parsed;
156
- }
157
- return {
158
- type: "final",
159
- finalAnswer: input.results.map((r) => r.summary).join("\n"),
160
- explanation: "Failed to parse verifier output, returning collected results.",
161
- };
162
- }
163
- async createPlan(task) {
164
- if (!this.provider)
165
- throw new Error("Orchestrator not enabled");
166
- const messages = [
167
- {
168
- role: "system",
169
- content: 'You are a planning assistant. Break down tasks into steps. Respond with JSON only: {"steps": ["step 1", "step 2", ...]}',
170
- },
171
- { role: "user", content: task },
172
- ];
173
- const text = await this.chat(messages);
174
- try {
175
- return JSON.parse(text);
176
- }
177
- catch {
178
- return { steps: [task] };
179
- }
180
- }
181
- async resolveConflict(context) {
182
- if (!this.provider)
183
- throw new Error("Orchestrator not enabled");
184
- const messages = [
185
- {
186
- role: "system",
187
- content: "You are a conflict resolution assistant. Analyze the situation and recommend the best path forward.",
188
- },
189
- { role: "user", content: context },
190
- ];
191
- let result = "";
192
- for await (const chunk of this.provider.chat(messages)) {
193
- if (chunk.type === "text" && chunk.content)
194
- result += chunk.content;
195
- }
196
- return result;
197
- }
198
- }
@@ -1,10 +0,0 @@
1
- // src/llm/provider.ts
2
- /** Helper: extract plain text from message content (for token counting, logging, etc.) */
3
- export function getMessageText(content) {
4
- if (typeof content === "string")
5
- return content;
6
- return content
7
- .filter((p) => p.type === "text")
8
- .map((p) => p.text)
9
- .join("");
10
- }
@@ -1,39 +0,0 @@
1
- export function parseChunks(chunks) {
2
- let text = "";
3
- let reasoning;
4
- const toolCalls = [];
5
- let hasToolCalls = false;
6
- for (const chunk of chunks) {
7
- if (chunk.type === "text" && chunk.content) {
8
- text += chunk.content;
9
- }
10
- if (chunk.type === "reasoning" && chunk.content) {
11
- reasoning = (reasoning || "") + chunk.content;
12
- }
13
- if (chunk.type === "tool_call" && chunk.toolCall) {
14
- hasToolCalls = true;
15
- let parsedArgs;
16
- try {
17
- parsedArgs = JSON.parse(chunk.toolCall.arguments);
18
- }
19
- catch {
20
- parsedArgs = {};
21
- }
22
- toolCalls.push({
23
- id: chunk.toolCall.id,
24
- name: chunk.toolCall.name,
25
- arguments: parsedArgs,
26
- });
27
- }
28
- }
29
- if (hasToolCalls) {
30
- return { type: "tool_call", calls: toolCalls, reasoning };
31
- }
32
- if (reasoning && !text) {
33
- return { type: "reasoning", content: reasoning };
34
- }
35
- if (!text && !reasoning) {
36
- return { type: "empty" };
37
- }
38
- return { type: "text", content: text || "", reasoning };
39
- }
@@ -1,39 +0,0 @@
1
- // src/llm/token-counter.ts
2
- import { encodingForModel, getEncoding } from "js-tiktoken";
3
- import { getMessageText } from "./provider";
4
- export class TokenCounter {
5
- encoder;
6
- constructor(model = "gpt-4o") {
7
- try {
8
- this.encoder = encodingForModel(model);
9
- }
10
- catch {
11
- // Fallback to cl100k_base for unknown models
12
- this.encoder = getEncoding("cl100k_base");
13
- }
14
- }
15
- count(text) {
16
- if (!text)
17
- return 0;
18
- return this.encoder.encode(text).length;
19
- }
20
- countMessages(messages) {
21
- let total = 0;
22
- for (const msg of messages) {
23
- // ~4 tokens per message overhead (role, boundaries)
24
- total += 4;
25
- const text = getMessageText(msg.content);
26
- total += this.count(text);
27
- if (msg.role === "tool")
28
- total += 2; // tool_call_id
29
- }
30
- total += 2; // assistant priming
31
- return total;
32
- }
33
- encode(text) {
34
- return this.encoder.encode(text);
35
- }
36
- decode(tokens) {
37
- return this.encoder.decode(tokens);
38
- }
39
- }
package/dist/llm/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,143 +0,0 @@
1
- import { appendFileSync, mkdirSync, existsSync } from "fs";
2
- import { join } from "path";
3
- import { sanitizeLogMessage } from "../modules/security/data-sanitizer";
4
- import { FileLogWriter } from "./file-log";
5
- import pc from "picocolors";
6
- const LEVELS = { debug: 0, info: 1, warn: 2, error: 3 };
7
- const LEVEL_COLORS = {
8
- debug: (s) => pc.dim(s),
9
- info: (s) => s,
10
- warn: (s) => pc.yellow(s),
11
- error: (s) => pc.red(s),
12
- };
13
- function isColorEnabled() {
14
- return !process.env.NO_COLOR && !process.env.CI && process.stdout.isTTY === true;
15
- }
16
- export class Logger {
17
- level;
18
- prefix;
19
- logDir = null;
20
- sessionDir = null;
21
- fileLog;
22
- constructor(level = "info", prefix = "") {
23
- this.level = level;
24
- this.prefix = prefix;
25
- this.fileLog = new FileLogWriter();
26
- }
27
- setLevel(level) {
28
- this.level = level;
29
- }
30
- setLogDir(dir) {
31
- this.logDir = dir;
32
- if (!existsSync(dir)) {
33
- mkdirSync(dir, { recursive: true });
34
- }
35
- this.fileLog.setLogDir(dir);
36
- }
37
- setSessionDir(dir) {
38
- this.sessionDir = dir;
39
- if (!existsSync(dir)) {
40
- mkdirSync(dir, { recursive: true });
41
- }
42
- }
43
- clearSessionDir() {
44
- this.sessionDir = null;
45
- }
46
- /** Open a per-session `.log` file (legacy v1 behavior). */
47
- initSessionLog(sessionId) {
48
- this.fileLog.initSessionLog(sessionId);
49
- }
50
- /** Fall back to daily log files when no session is active. */
51
- closeSessionLog() {
52
- this.fileLog.closeSessionLog();
53
- }
54
- getLogPath() {
55
- return this.fileLog.getLogPath();
56
- }
57
- cleanupOldLogs(maxDays, maxFiles) {
58
- this.fileLog.cleanupOldLogs(maxDays, maxFiles);
59
- }
60
- // --- Tagged helpers (legacy v1 API) ---
61
- logLLMRequest(model, messagesCount, promptPreview, caller) {
62
- this.fileLog.logLLMRequest(model, messagesCount, promptPreview, caller);
63
- }
64
- logLLMResponse(model, responseLength, genTimeMs, error, caller) {
65
- this.fileLog.logLLMResponse(model, responseLength, genTimeMs, error, caller);
66
- }
67
- logToolCall(tool, preview, result) {
68
- this.fileLog.logToolCall(tool, preview, result);
69
- }
70
- logToolOutput(tool, output, exitCode) {
71
- this.fileLog.logToolOutput(tool, output, exitCode);
72
- }
73
- logREPL(tag, content) {
74
- this.fileLog.logREPL(tag, content);
75
- }
76
- child(prefix) {
77
- const childLogger = new Logger(this.level, this.prefix ? `${this.prefix}:${prefix}` : prefix);
78
- if (this.logDir)
79
- childLogger.setLogDir(this.logDir);
80
- if (this.sessionDir)
81
- childLogger.setSessionDir(this.sessionDir);
82
- return childLogger;
83
- }
84
- debug(msg, meta) {
85
- this.log("debug", msg, meta);
86
- }
87
- info(msg, meta) {
88
- this.log("info", msg, meta);
89
- }
90
- warn(msg, meta) {
91
- this.log("warn", msg, meta);
92
- }
93
- error(msg, meta) {
94
- this.log("error", msg, meta);
95
- }
96
- log(level, msg, meta) {
97
- if (LEVELS[level] < LEVELS[this.level])
98
- return;
99
- // Sanitize log message to remove sensitive data
100
- const sanitizedMsg = sanitizeLogMessage(msg);
101
- const sanitizedMeta = meta ? this.sanitizeMeta(meta) : undefined;
102
- const ts = new Date().toISOString();
103
- const prefix = this.prefix ? ` [${this.prefix}]` : "";
104
- const metaStr = sanitizedMeta ? ` ${JSON.stringify(sanitizedMeta)}` : "";
105
- const line = `[${level.toUpperCase()}]${prefix} ${ts} — ${sanitizedMsg}${metaStr}`;
106
- console.log(isColorEnabled() ? LEVEL_COLORS[level](line) : line);
107
- // Legacy v1 behavior: also append to the tagged `.log` file (session or daily).
108
- this.fileLog.log(level.toUpperCase(), this.prefix || "MMA", `${ts} — ${sanitizedMsg}${metaStr}`);
109
- const logTarget = this.sessionDir ?? this.logDir;
110
- if (logTarget) {
111
- try {
112
- appendFileSync(join(logTarget, "app.jsonl"), JSON.stringify({
113
- level,
114
- ts,
115
- prefix: this.prefix,
116
- msg: sanitizedMsg,
117
- meta: sanitizedMeta ?? null,
118
- }) + "\n", "utf-8");
119
- }
120
- catch {
121
- /* file logging is best-effort */
122
- }
123
- }
124
- }
125
- /**
126
- * Sanitize metadata object to remove sensitive data
127
- */
128
- sanitizeMeta(meta) {
129
- const sanitized = {};
130
- for (const [key, value] of Object.entries(meta)) {
131
- if (typeof value === "string") {
132
- sanitized[key] = sanitizeLogMessage(value);
133
- }
134
- else if (typeof value === "object" && value !== null) {
135
- sanitized[key] = this.sanitizeMeta(value);
136
- }
137
- else {
138
- sanitized[key] = value;
139
- }
140
- }
141
- return sanitized;
142
- }
143
- }
@@ -1,151 +0,0 @@
1
- import { appendFileSync, mkdirSync, existsSync, readdirSync, renameSync, statSync, unlinkSync, } from "node:fs";
2
- import { join } from "node:path";
3
- const MAX_LOG_SIZE = 5 * 1024 * 1024;
4
- const MAX_LOG_FILES = 30;
5
- const DEFAULT_MAX_DAYS = 30;
6
- const TOOL_OUTPUT_LIMIT = 2000;
7
- /**
8
- * Tagged file logger (legacy MMA v1 behavior).
9
- *
10
- * Writes human-readable log lines to `~/.mma/logs/`:
11
- * - `<sessionId>.log` while a session is active
12
- * - `YYYY-MM-DD.log` for everything outside a session
13
- *
14
- * Features restored from v1:
15
- * - size-based rotation (5 MB → file.log.1, file.log.2, ...)
16
- * - cleanup of old logs (age + max file count)
17
- * - tagged helpers: LLM request/response, tool calls, REPL
18
- */
19
- export class FileLogWriter {
20
- logDir = null;
21
- sessionLogPath = null;
22
- setLogDir(dir) {
23
- this.logDir = dir;
24
- if (!existsSync(dir)) {
25
- mkdirSync(dir, { recursive: true });
26
- }
27
- }
28
- /** Open a per-session log file. Triggers cleanup of old logs. */
29
- initSessionLog(sessionId) {
30
- if (!this.logDir)
31
- return;
32
- if (!existsSync(this.logDir)) {
33
- mkdirSync(this.logDir, { recursive: true });
34
- }
35
- this.sessionLogPath = join(this.logDir, `${sessionId}.log`);
36
- this.cleanupOldLogs();
37
- }
38
- /** Fall back to daily log files when no session is active. */
39
- closeSessionLog() {
40
- this.sessionLogPath = null;
41
- }
42
- getLogPath() {
43
- if (this.sessionLogPath)
44
- return this.sessionLogPath;
45
- if (!this.logDir)
46
- return "";
47
- const date = new Date().toISOString().slice(0, 10);
48
- return join(this.logDir, `${date}.log`);
49
- }
50
- /** Rotate the file if it exceeds the size limit. */
51
- rotateIfNeeded(filePath) {
52
- if (!existsSync(filePath))
53
- return;
54
- const size = statSync(filePath).size;
55
- if (size < MAX_LOG_SIZE)
56
- return;
57
- let idx = 1;
58
- while (existsSync(`${filePath}.${idx}`))
59
- idx++;
60
- renameSync(filePath, `${filePath}.${idx}`);
61
- }
62
- log(level, tag, message) {
63
- const fp = this.getLogPath();
64
- if (!fp)
65
- return;
66
- if (this.logDir && !existsSync(this.logDir)) {
67
- mkdirSync(this.logDir, { recursive: true });
68
- }
69
- this.rotateIfNeeded(fp);
70
- const line = `[${new Date().toISOString()}] [${level}] [${tag}] ${message}\n`;
71
- try {
72
- appendFileSync(fp, line, "utf-8");
73
- }
74
- catch {
75
- /* file logging is best-effort */
76
- }
77
- }
78
- logLLMRequest(model, messagesCount, promptPreview, caller) {
79
- const tag = caller ? `LLM/${caller}` : "LLM";
80
- this.log("INFO", tag, `→ ${model} | ${messagesCount} messages | "${promptPreview.slice(0, 100)}"`);
81
- }
82
- logLLMResponse(model, responseLength, genTimeMs, error, caller) {
83
- const tag = caller ? `LLM/${caller}` : "LLM";
84
- if (error) {
85
- this.log("ERROR", tag, `← ${model} | ${responseLength} chars | ${genTimeMs}ms | ERROR: ${error}`);
86
- }
87
- else {
88
- this.log("INFO", tag, `← ${model} | ${responseLength} chars | ${genTimeMs}ms`);
89
- }
90
- }
91
- logToolCall(tool, preview, result) {
92
- const previewTrimmed = preview.length > 200 ? preview.slice(0, 200) + "..." : preview;
93
- if (result !== undefined) {
94
- const resultTrimmed = result.length > 200 ? result.slice(0, 200) + "..." : result;
95
- this.log("INFO", "TOOL", `${tool} | ${previewTrimmed} → ${resultTrimmed}`);
96
- }
97
- else {
98
- this.log("INFO", "TOOL", `${tool} | ${previewTrimmed}`);
99
- }
100
- }
101
- logToolOutput(tool, output, exitCode) {
102
- const trimmed = output.length > TOOL_OUTPUT_LIMIT
103
- ? output.slice(0, TOOL_OUTPUT_LIMIT) +
104
- `\n... (truncated ${output.length - TOOL_OUTPUT_LIMIT} chars)`
105
- : output;
106
- this.log("DEBUG", "TOOL_OUTPUT", `${tool} exit:${exitCode}\n${trimmed}`);
107
- }
108
- logREPL(tag, content) {
109
- const trimmed = content.length > 400 ? content.slice(0, 400) + "..." : content;
110
- this.log("INFO", `REPL/${tag}`, trimmed);
111
- }
112
- /**
113
- * Clean up old log files.
114
- * - Deletes files older than maxDays
115
- * - Keeps at most maxFiles most recent .log files
116
- */
117
- cleanupOldLogs(maxDays = DEFAULT_MAX_DAYS, maxFiles = MAX_LOG_FILES) {
118
- if (!this.logDir || !existsSync(this.logDir))
119
- return;
120
- const now = Date.now();
121
- const list = () => readdirSync(this.logDir)
122
- .filter((f) => f.endsWith(".log") || /\.log\.\d+$/.test(f))
123
- .map((f) => ({
124
- name: f,
125
- path: join(this.logDir, f),
126
- mtime: statSync(join(this.logDir, f)).mtimeMs,
127
- }))
128
- .sort((a, b) => b.mtime - a.mtime);
129
- // 1. Delete by age.
130
- for (const f of list()) {
131
- if (now - f.mtime > maxDays * 24 * 60 * 60 * 1000) {
132
- try {
133
- unlinkSync(f.path);
134
- }
135
- catch {
136
- /* ignore */
137
- }
138
- }
139
- }
140
- // 2. Delete excess (fresh but more than maxFiles).
141
- const remaining = list();
142
- for (let i = maxFiles; i < remaining.length; i++) {
143
- try {
144
- unlinkSync(remaining[i].path);
145
- }
146
- catch {
147
- /* ignore */
148
- }
149
- }
150
- }
151
- }
@@ -1 +0,0 @@
1
- export { Logger } from "./app-logger";
@@ -1,45 +0,0 @@
1
- import { copyFileSync, cpSync, existsSync, mkdirSync, readdirSync, writeFileSync } from "fs";
2
- import { join } from "path";
3
- import { t } from "../i18n/index";
4
- export class BackupManager {
5
- configDir;
6
- constructor(configDir) {
7
- this.configDir = configDir;
8
- }
9
- backupConfig() {
10
- const configPath = join(this.configDir, "config.json");
11
- if (!existsSync(configPath))
12
- return;
13
- const bakPath = join(this.configDir, "config.json.bak");
14
- copyFileSync(configPath, bakPath);
15
- }
16
- backupAll() {
17
- const bakDir = this.configDir + ".bak";
18
- if (existsSync(bakDir))
19
- return;
20
- if (existsSync(this.configDir)) {
21
- cpSync(this.configDir, bakDir, { recursive: true });
22
- }
23
- }
24
- writeFreshConfig(config) {
25
- if (!existsSync(this.configDir)) {
26
- mkdirSync(this.configDir, { recursive: true });
27
- }
28
- writeFileSync(join(this.configDir, "config.json"), JSON.stringify(config, null, 2), "utf-8");
29
- }
30
- getBackupSummary() {
31
- const lines = [];
32
- const bakConfig = join(this.configDir, "config.json.bak");
33
- const bakDir = this.configDir + ".bak";
34
- if (existsSync(bakConfig)) {
35
- lines.push(t("migration.config_bak"));
36
- }
37
- if (existsSync(bakDir)) {
38
- const files = readdirSync(bakDir);
39
- lines.push(t("migration.dir_bak", { count: files.length }));
40
- }
41
- return lines.length > 0
42
- ? `${t("migration.migrated")}\n${lines.join("\n")}`
43
- : t("migration.not_needed");
44
- }
45
- }
@@ -1,50 +0,0 @@
1
- import { existsSync, readFileSync, readdirSync } from "fs";
2
- import { join } from "path";
3
- const V1_ONLY_FIELDS = ["apiBase", "apiKey", "chatEndpoint", "temperature", "maxTokens"];
4
- export class MigrationDetector {
5
- configDir;
6
- constructor(configDir) {
7
- this.configDir = configDir;
8
- }
9
- needsMigration() {
10
- const configPath = join(this.configDir, "config.json");
11
- if (!existsSync(configPath))
12
- return false;
13
- try {
14
- const content = readFileSync(configPath, "utf-8");
15
- const config = JSON.parse(content);
16
- if (config.version && config.version.startsWith("2."))
17
- return false;
18
- for (const field of V1_ONLY_FIELDS) {
19
- if (field in config)
20
- return true;
21
- }
22
- const v2Required = ["provider", "contextWindow", "contextBudget"];
23
- const hasAllV2Fields = v2Required.every((f) => f in config);
24
- if (!hasAllV2Fields)
25
- return true;
26
- return false;
27
- }
28
- catch {
29
- return true;
30
- }
31
- }
32
- hasOldSessions() {
33
- const sessionsDir = join(this.configDir, "sessions");
34
- if (!existsSync(sessionsDir))
35
- return false;
36
- return readdirSync(sessionsDir).length > 0;
37
- }
38
- hasOldProfile() {
39
- const profilePath = join(this.configDir, "profile.json");
40
- if (!existsSync(profilePath))
41
- return false;
42
- try {
43
- const profile = JSON.parse(readFileSync(profilePath, "utf-8"));
44
- return !profile.platform && !profile.os;
45
- }
46
- catch {
47
- return false;
48
- }
49
- }
50
- }
@@ -1,2 +0,0 @@
1
- export { MigrationDetector } from "./detect";
2
- export { BackupManager } from "./backup";