micro-models-agent 0.16.8 → 0.18.0

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.
package/dist/cli/repl.js CHANGED
@@ -161,17 +161,16 @@ export class Repl {
161
161
  const { resolve } = await import("path");
162
162
  let dataUrl;
163
163
  let label;
164
- let warning;
165
164
  if (source.toLowerCase() === "clipboard") {
166
- const clipPath = await readClipboardImage();
167
- if (!clipPath) {
165
+ const clipBuf = await readClipboardImage();
166
+ if (!clipBuf) {
168
167
  console.log(pc.yellow(t("image.clipboard_empty")));
169
168
  return;
170
169
  }
171
- const result = loadFileAsDataUrl(clipPath);
170
+ const { bufferToDataUrl } = await import("../llm/image-utils");
171
+ const result = await bufferToDataUrl(clipBuf);
172
172
  dataUrl = result.dataUrl;
173
173
  label = "clipboard";
174
- warning = result.warning;
175
174
  }
176
175
  else if (source.startsWith("http://") || source.startsWith("https://")) {
177
176
  const result = await loadUrlAsDataUrl(source);
@@ -184,10 +183,9 @@ export class Repl {
184
183
  console.log(pc.red(t("image.not_found", { path: source })));
185
184
  return;
186
185
  }
187
- const result = loadFileAsDataUrl(absPath);
186
+ const result = await loadFileAsDataUrl(absPath);
188
187
  dataUrl = result.dataUrl;
189
188
  label = source;
190
- warning = result.warning;
191
189
  }
192
190
  // Store the image data on the agent's context manager for the next message
193
191
  const contextManager = this.agent.contextManager;
@@ -201,8 +199,6 @@ export class Repl {
201
199
  });
202
200
  const sizeKb = Math.round((dataUrl.length * 3) / 4 / 1024);
203
201
  console.log(pc.green(t("image.attached", { source: label, size: `${sizeKb} KB` })));
204
- if (warning)
205
- console.log(pc.yellow(` ${warning}`));
206
202
  }
207
203
  catch (err) {
208
204
  console.log(pc.red(t("image.error", { message: err.message })));
@@ -760,15 +756,13 @@ export class Repl {
760
756
  // Ctrl+V: try to paste image from clipboard
761
757
  if (key.ctrl && key.name === "v" && !this.agentRunning) {
762
758
  try {
763
- const { readClipboardImage, loadFileAsDataUrl } = await import("../llm/image-utils");
764
- const clipPath = await readClipboardImage();
765
- if (clipPath) {
766
- const { dataUrl, warning } = loadFileAsDataUrl(clipPath);
759
+ const { readClipboardImage, bufferToDataUrl } = await import("../llm/image-utils");
760
+ const clipBuf = await readClipboardImage();
761
+ if (clipBuf) {
762
+ const { dataUrl } = await bufferToDataUrl(clipBuf);
767
763
  this.pendingClipboardImage = dataUrl;
768
764
  const sizeKb = Math.round((dataUrl.length * 3) / 4 / 1024);
769
765
  console.log(pc.green(`\n${t("image.attached", { source: "clipboard", size: `${sizeKb} KB` })}`));
770
- if (warning)
771
- console.log(pc.yellow(` ${warning}`));
772
766
  this.rl.prompt();
773
767
  }
774
768
  }
@@ -19,6 +19,7 @@ import { SkillsLoader, SkillsMatcher, SkillsModule, } from "../modules/skills/in
19
19
  import { BrowserModule } from "../modules/browser/index";
20
20
  import { IndexerModule } from "../modules/indexer/index";
21
21
  import { MCPModule } from "../modules/mcp/index";
22
+ import { MemoryModule } from "../modules/memory/module";
22
23
  import { setLocale } from "../i18n/index";
23
24
  import { Agent } from "./agent";
24
25
  import { homedir } from "os";
@@ -202,6 +203,8 @@ export async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplet
202
203
  const mcpModule = new MCPModule(config);
203
204
  await mcpModule.initialize();
204
205
  moduleRegistry.register(mcpModule);
206
+ const memoryModule = new MemoryModule(join(dir, 'memory'));
207
+ moduleRegistry.register(memoryModule);
205
208
  if (config.browser.enabled) {
206
209
  const browserModule = new BrowserModule();
207
210
  moduleRegistry.register(browserModule);
package/dist/i18n/en.json CHANGED
@@ -120,6 +120,7 @@
120
120
  "tool.no_history": "No history entries matching \"{query}\"",
121
121
  "tool.no_sessions_dir": "No sessions directory found at {dir}",
122
122
  "tool.history_error": "Error searching history: {error}",
123
+ "tool.memory_error": "Memory error: {error}",
123
124
  "tool.screenshot_unavailable": "[Screenshot captured \u2014 image not available for text-only model]",
124
125
  "tool.timeout": "Tool {name} timed out after {seconds} seconds",
125
126
  "tool.interactive_disabled": "Interactive tool is disabled in exit-on-complete mode. Proceed without asking the user.",
@@ -447,5 +448,14 @@
447
448
  "image.error": "Failed to load image: {message}",
448
449
  "tool.friendly.attach_image": "Attach image",
449
450
  "repl.image": "Attach image",
450
- "repl.image_usage": "/image <path|url|clipboard> — attach an image to the next message"
451
+ "repl.image_usage": "/image <path|url|clipboard> — attach an image to the next message",
452
+ "tool.friendly.remember": "Remember",
453
+ "tool.friendly.recall": "Recall",
454
+ "tool.remember.preference": "Remembered: {key} = {value}",
455
+ "tool.remember.entry": "Remembered: {category} — \"{entry}\"",
456
+ "tool.remember.key_required": "Key is required for preferences",
457
+ "tool.remember.entry_required": "Entry text is required",
458
+ "tool.recall.empty": "Nothing found for \"{query}\"",
459
+ "tool.recall.no_memory": "Memory is empty",
460
+ "tool.recall.search_results": "{category} results:\n{results}"
451
461
  }
package/dist/i18n/ru.json CHANGED
@@ -120,6 +120,7 @@
120
120
  "tool.no_history": "Нет записей истории по \"{query}\"",
121
121
  "tool.no_sessions_dir": "Каталог сессий не найден по {dir}",
122
122
  "tool.history_error": "Ошибка поиска истории: {error}",
123
+ "tool.memory_error": "Ошибка памяти: {error}",
123
124
  "tool.screenshot_unavailable": "[Скриншот сделан — изображение недоступно для текстовой модели]",
124
125
  "tool.timeout": "Инструмент {name} превысил таймаут ({seconds} сек)",
125
126
  "tool.interactive_disabled": "Интерактивный инструмент отключён в режиме exit-on-complete. Продолжай без вопроса пользователю.",
@@ -447,5 +448,14 @@
447
448
  "image.error": "Не удалось загрузить изображение: {message}",
448
449
  "tool.friendly.attach_image": "Прикрепить изображение",
449
450
  "repl.image": "Прикрепить изображение",
450
- "repl.image_usage": "/image <путь|URL|clipboard> — прикрепить изображение к следующему сообщению"
451
+ "repl.image_usage": "/image <путь|URL|clipboard> — прикрепить изображение к следующему сообщению",
452
+ "tool.friendly.remember": "Запомнить",
453
+ "tool.friendly.recall": "Вспомнить",
454
+ "tool.remember.preference": "Запомнено: {key} = {value}",
455
+ "tool.remember.entry": "Запомнено: {category} — \"{entry}\"",
456
+ "tool.remember.key_required": "Для preferences требуется ключ (key)",
457
+ "tool.remember.entry_required": "Требуется текст записи",
458
+ "tool.recall.empty": "Ничего не найдено по \"{query}\"",
459
+ "tool.recall.no_memory": "Память пуста",
460
+ "tool.recall.search_results": "Результаты {category}:\n{results}"
451
461
  }
@@ -9,97 +9,136 @@ const MIME_MAP = {
9
9
  ".bmp": "image/bmp",
10
10
  ".svg": "image/svg+xml",
11
11
  };
12
- /**
13
- * Detect MIME type from file extension.
14
- */
12
+ /** Detect MIME type from file extension. */
15
13
  export function detectMime(filePath) {
16
14
  const ext = extname(filePath).toLowerCase();
17
15
  return MIME_MAP[ext] ?? "image/png";
18
16
  }
19
17
  /**
20
- * Load an image from a file path and return as base64 data URL.
21
- * Resizes if raw data exceeds maxBytes. Default max: 50KB (~16K tokens in base64).
18
+ * Read image from system clipboard using Bun.Image (macOS/Windows).
19
+ * Falls back to platform-specific commands on Linux.
20
+ * Returns null if clipboard has no image.
22
21
  */
23
- export function loadFileAsDataUrl(filePath, maxBytes = 50 * 1024) {
24
- const mime = detectMime(filePath);
25
- let buf = readFileSync(filePath);
26
- let resized = false;
27
- let warning;
28
- if (buf.length > maxBytes) {
29
- const ratio = maxBytes / buf.length;
30
- warning = `Image ${Math.round(buf.length / 1024)}KB exceeds ${Math.round(maxBytes / 1024)}KB limit — resized to ~${Math.round(maxBytes / 1024)}KB (quality may reduce). Tip: crop the image before pasting.`;
31
- buf = buf.subarray(0, maxBytes); // naive truncation — better than nothing
32
- resized = true;
22
+ export async function readClipboardImage() {
23
+ // Bun.Image.fromClipboard() works on macOS and Windows
24
+ if (typeof Bun !== "undefined" && typeof Bun.Image !== "undefined") {
25
+ try {
26
+ const img = Bun.Image.fromClipboard();
27
+ if (img) {
28
+ const buf = await img
29
+ .resize(800, 800, { fit: "inside" })
30
+ .jpeg({ quality: 60 })
31
+ .buffer();
32
+ return Buffer.from(buf);
33
+ }
34
+ }
35
+ catch {
36
+ // Bun.Image.fromClipboard() failed — fall through to platform fallback
37
+ }
33
38
  }
39
+ // Linux fallback: xclip/wl-paste → temp file → read
40
+ return readClipboardFallback();
41
+ }
42
+ async function readClipboardFallback() {
43
+ const { platform } = await import("os");
44
+ const { execSync } = await import("child_process");
45
+ const { readFileSync, unlinkSync } = await import("fs");
46
+ const { join } = await import("path");
47
+ const tmpPath = join(process.env.TEMP || process.env.TMP || "/tmp", `mma-clip-${Date.now()}.png`);
48
+ try {
49
+ if (platform() === "linux") {
50
+ execSync(`xclip -selection clipboard -t image/png -o > "${tmpPath}" 2>/dev/null`, { timeout: 5000 });
51
+ }
52
+ else {
53
+ return null; // macOS/Windows should use Bun.Image
54
+ }
55
+ const buf = readFileSync(tmpPath);
56
+ unlinkSync(tmpPath);
57
+ return buf.length > 0 ? buf : null;
58
+ }
59
+ catch {
60
+ try {
61
+ unlinkSync(tmpPath);
62
+ }
63
+ catch { }
64
+ return null;
65
+ }
66
+ }
67
+ /**
68
+ * Load an image from a file path, resize via Bun.Image, return as JPEG data URL.
69
+ * Target: ~800px wide, JPEG quality 60 — typically 5-15KB (~2-4K tokens).
70
+ */
71
+ export async function loadFileAsDataUrl(filePath) {
72
+ const buf = readFileSync(filePath);
73
+ // Use Bun.Image if available — resize + convert to JPEG
74
+ if (typeof Bun !== "undefined" && typeof Bun.Image !== "undefined") {
75
+ try {
76
+ const img = new Bun.Image(buf);
77
+ const { width } = await img.metadata();
78
+ const targetWidth = Math.min(800, width || 800);
79
+ const dataUrl = await img
80
+ .resize(targetWidth, 800, { fit: "inside" })
81
+ .jpeg({ quality: 60 })
82
+ .dataurl();
83
+ return { dataUrl };
84
+ }
85
+ catch {
86
+ // Bun.Image failed — fall through to raw base64
87
+ }
88
+ }
89
+ // Fallback: raw base64 (no resize)
34
90
  const b64 = buf.toString("base64");
35
- return { dataUrl: `data:${mime};base64,${b64}`, mime, resized, warning };
91
+ const ext = filePath.split(".").pop()?.toLowerCase();
92
+ const mime = ext === "jpg" || ext === "jpeg" ? "image/jpeg" : ext === "webp" ? "image/webp" : "image/png";
93
+ return { dataUrl: `data:${mime};base64,${b64}` };
36
94
  }
37
95
  /**
38
- * Load an image from a URL, return as base64 data URL.
96
+ * Load an image from a URL, resize, return as JPEG data URL.
39
97
  */
40
98
  export async function loadUrlAsDataUrl(url) {
41
99
  const resp = await fetch(url);
42
100
  if (!resp.ok) {
43
101
  throw new Error(`Failed to fetch image: ${resp.status} ${resp.statusText}`);
44
102
  }
45
- const contentType = resp.headers.get("content-type") ?? "image/png";
46
- const mime = contentType.split(";")[0].trim();
47
103
  const buf = Buffer.from(await resp.arrayBuffer());
104
+ if (typeof Bun !== "undefined" && typeof Bun.Image !== "undefined") {
105
+ try {
106
+ const img = new Bun.Image(buf);
107
+ const { width } = await img.metadata();
108
+ const targetWidth = Math.min(800, width || 800);
109
+ const dataUrl = await img
110
+ .resize(targetWidth, 800, { fit: "inside" })
111
+ .jpeg({ quality: 60 })
112
+ .dataurl();
113
+ return { dataUrl };
114
+ }
115
+ catch {
116
+ // fall through
117
+ }
118
+ }
48
119
  const b64 = buf.toString("base64");
49
- return { dataUrl: `data:${mime};base64,${b64}`, mime };
120
+ return { dataUrl: `data:image/png;base64,${b64}` };
50
121
  }
51
122
  /**
52
- * Read image from system clipboard (platform-specific).
53
- * Returns null if clipboard has no image.
123
+ * Process a clipboard buffer (already resized by readClipboardImage)
124
+ * into a data URL. Used by Ctrl+V handler.
54
125
  */
55
- export async function readClipboardImage() {
56
- const { platform } = await import("os");
57
- if (platform() === "win32") {
58
- return readClipboardWindows();
59
- }
60
- if (platform() === "darwin") {
61
- return readClipboardMacos();
62
- }
63
- return readClipboardLinux();
64
- }
65
- async function readClipboardWindows() {
66
- try {
67
- const { execSync } = await import("child_process");
68
- const tmpPath = `${process.env.TEMP || process.env.TMP || "/tmp"}\\mma-clip-${Date.now()}.png`;
69
- // Use single quotes in PowerShell to avoid backslash issues
70
- const psScript = `Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img -ne $null) { $img.Save('${tmpPath}'); Write-Output 'OK' } else { Write-Output 'EMPTY' }`;
71
- const out = execSync(`powershell -NoProfile -Command "${psScript}"`, {
72
- timeout: 5000,
73
- encoding: "utf-8",
74
- });
75
- if (out.includes("OK")) {
76
- return tmpPath;
126
+ export async function bufferToDataUrl(buf) {
127
+ if (typeof Bun !== "undefined" && typeof Bun.Image !== "undefined") {
128
+ try {
129
+ const img = new Bun.Image(buf);
130
+ const { width } = await img.metadata();
131
+ const targetWidth = Math.min(800, width || 800);
132
+ const dataUrl = await img
133
+ .resize(targetWidth, 800, { fit: "inside" })
134
+ .jpeg({ quality: 60 })
135
+ .dataurl();
136
+ return { dataUrl };
137
+ }
138
+ catch {
139
+ // fall through
77
140
  }
78
- return null;
79
- }
80
- catch {
81
- return null;
82
- }
83
- }
84
- async function readClipboardMacos() {
85
- try {
86
- const { execSync } = await import("child_process");
87
- const tmpPath = `/tmp/mma-clip-${Date.now()}.png`;
88
- execSync(`pngpaste "${tmpPath}"`, { timeout: 5000 });
89
- return tmpPath;
90
- }
91
- catch {
92
- return null;
93
- }
94
- }
95
- async function readClipboardLinux() {
96
- try {
97
- const { execSync } = await import("child_process");
98
- const tmpPath = `/tmp/mma-clip-${Date.now()}.png`;
99
- execSync(`xclip -selection clipboard -t image/png -o > "${tmpPath}" 2>/dev/null`, { timeout: 5000 });
100
- return tmpPath;
101
- }
102
- catch {
103
- return null;
104
141
  }
142
+ const b64 = buf.toString("base64");
143
+ return { dataUrl: `data:image/png;base64,${b64}` };
105
144
  }
@@ -0,0 +1,48 @@
1
+ import { homedir } from 'os';
2
+ import { join } from 'path';
3
+ import { MemoryStore } from './store';
4
+ import { rememberTool } from '../../tools/remember';
5
+ import { recallTool } from '../../tools/recall';
6
+ export class MemoryModule {
7
+ name = 'memory';
8
+ store;
9
+ constructor(memoryDir) {
10
+ const dir = memoryDir || join(homedir(), '.mma', 'memory');
11
+ this.store = new MemoryStore(dir);
12
+ }
13
+ getSystemPromptBlock() {
14
+ const prefs = this.store.getPreferences();
15
+ if (Object.keys(prefs).length === 0)
16
+ return null;
17
+ const prefStr = Object.entries(prefs)
18
+ .map(([k, v]) => `${k}=${v}`)
19
+ .join(', ');
20
+ return {
21
+ content: `User preferences: ${prefStr}`,
22
+ priority: 'normal',
23
+ essential: false,
24
+ estimatedTokens: Math.ceil(prefStr.length / 4) + 10,
25
+ };
26
+ }
27
+ getToolDefinitions() {
28
+ return [rememberTool, recallTool];
29
+ }
30
+ getPlugin() {
31
+ return {
32
+ name: 'memory',
33
+ isBuiltin: true,
34
+ onBuildPrompt: () => {
35
+ const prefs = this.store.getPreferences();
36
+ if (Object.keys(prefs).length === 0)
37
+ return null;
38
+ const prefStr = Object.entries(prefs)
39
+ .map(([k, v]) => `${k}=${v}`)
40
+ .join(', ');
41
+ return `User preferences: ${prefStr}`;
42
+ },
43
+ };
44
+ }
45
+ getStore() {
46
+ return this.store;
47
+ }
48
+ }
@@ -1,6 +1,6 @@
1
1
  import { readFileSync, existsSync } from 'fs';
2
2
  import { join } from 'path';
3
- const MEMORY_FILES = ['conventions', 'decisions', 'errors'];
3
+ const MEMORY_FILES = ['conventions', 'decisions', 'errors', 'facts'];
4
4
  export class MemorySearch {
5
5
  memoryDir;
6
6
  constructor(memoryDir) {
@@ -21,6 +21,20 @@ export class MemorySearch {
21
21
  }
22
22
  }
23
23
  }
24
+ // Search preferences.json
25
+ const prefsPath = join(this.memoryDir, 'preferences.json');
26
+ if (existsSync(prefsPath)) {
27
+ try {
28
+ const prefs = JSON.parse(readFileSync(prefsPath, 'utf-8'));
29
+ for (const [key, value] of Object.entries(prefs)) {
30
+ const searchStr = `${key}=${value}`;
31
+ if (searchStr.toLowerCase().includes(lowerQuery)) {
32
+ results.push({ file: 'preferences', match: `${key} = ${value}` });
33
+ }
34
+ }
35
+ }
36
+ catch { /* skip */ }
37
+ }
24
38
  return results;
25
39
  }
26
40
  }
@@ -1,7 +1,7 @@
1
1
  import { readFileSync, writeFileSync, appendFileSync, existsSync, mkdirSync } from 'fs';
2
2
  import { join } from 'path';
3
3
  import { MemorySearch } from './search';
4
- const MEMORY_FILES = ['conventions', 'decisions', 'errors'];
4
+ const MEMORY_FILES = ['conventions', 'decisions', 'errors', 'facts'];
5
5
  export class MemoryStore {
6
6
  memoryDir;
7
7
  constructor(memoryDir) {
@@ -35,4 +35,31 @@ export class MemoryStore {
35
35
  const searchModule = new MemorySearch(this.memoryDir);
36
36
  return searchModule.query(query);
37
37
  }
38
+ prefsPath() {
39
+ return join(this.memoryDir, 'preferences.json');
40
+ }
41
+ getPreferences() {
42
+ const path = this.prefsPath();
43
+ if (!existsSync(path))
44
+ return {};
45
+ try {
46
+ return JSON.parse(readFileSync(path, 'utf-8'));
47
+ }
48
+ catch {
49
+ return {};
50
+ }
51
+ }
52
+ setPreference(key, value) {
53
+ const prefs = this.getPreferences();
54
+ prefs[key] = value;
55
+ writeFileSync(this.prefsPath(), JSON.stringify(prefs, null, 2), 'utf-8');
56
+ }
57
+ deletePreference(key) {
58
+ const prefs = this.getPreferences();
59
+ if (!(key in prefs))
60
+ return false;
61
+ delete prefs[key];
62
+ writeFileSync(this.prefsPath(), JSON.stringify(prefs, null, 2), 'utf-8');
63
+ return true;
64
+ }
38
65
  }
@@ -1,9 +1,8 @@
1
1
  import { existsSync } from "fs";
2
2
  import { resolve } from "path";
3
3
  import { t } from "../i18n/index";
4
- import { loadFileAsDataUrl, loadUrlAsDataUrl, readClipboardImage } from "../llm/image-utils";
4
+ import { loadFileAsDataUrl, loadUrlAsDataUrl, readClipboardImage, bufferToDataUrl } from "../llm/image-utils";
5
5
  import { logSecurityBlock } from "../modules/security/audit-log";
6
- const MAX_IMAGE_BYTES = 10 * 1024 * 1024; // 10 MB
7
6
  export const attachImageTool = {
8
7
  name: "attach_image",
9
8
  description: "Attach an image to the conversation from a file path, URL, or clipboard. The image will be included in the next message sent to the model. Supports PNG, JPEG, GIF, WebP.",
@@ -26,14 +25,14 @@ export const attachImageTool = {
26
25
  try {
27
26
  let dataUrl;
28
27
  if (source.toLowerCase() === "clipboard") {
29
- const clipPath = await readClipboardImage();
30
- if (!clipPath) {
28
+ const clipBuf = await readClipboardImage();
29
+ if (!clipBuf) {
31
30
  return {
32
31
  success: false,
33
32
  output: t("image.clipboard_empty"),
34
33
  };
35
34
  }
36
- const result = loadFileAsDataUrl(clipPath, MAX_IMAGE_BYTES);
35
+ const result = await bufferToDataUrl(clipBuf);
37
36
  dataUrl = result.dataUrl;
38
37
  }
39
38
  else if (source.startsWith("http://") || source.startsWith("https://")) {
@@ -60,7 +59,7 @@ export const attachImageTool = {
60
59
  };
61
60
  }
62
61
  }
63
- const result = loadFileAsDataUrl(absPath, MAX_IMAGE_BYTES);
62
+ const result = await loadFileAsDataUrl(absPath);
64
63
  dataUrl = result.dataUrl;
65
64
  }
66
65
  // Add the image as a pending content part on the context manager
@@ -24,11 +24,13 @@ import { createLoadSkillTool } from './load-skill';
24
24
  import { pipelineRunTool } from './pipeline-run';
25
25
  import { mcpCallTool } from './mcp-call';
26
26
  import { searchHistoryTool } from './search-history';
27
+ import { rememberTool } from './remember';
28
+ import { recallTool } from './recall';
27
29
  import { createBrowserTool } from './browser';
28
30
  import { attachImageTool } from './attach-image';
29
31
  export { ToolRegistry, ToolExecutor };
30
32
  export { filterToolsByTags } from './filter-tools';
31
- export { readFileTool, writeFileTool, editFileTool, globTool, grepTool, listDirTool, createDirTool, deleteFileTool, moveFileTool, fileInfoTool, bashTool, subagentTool, processListTool, processLogTool, processKillTool, webSearchTool, webFetchTool, webBrowseTool, questionTool, approveTool, createLoadSkillTool, pipelineRunTool, mcpCallTool, searchHistoryTool, createBrowserTool, attachImageTool, };
33
+ export { readFileTool, writeFileTool, editFileTool, globTool, grepTool, listDirTool, createDirTool, deleteFileTool, moveFileTool, fileInfoTool, bashTool, subagentTool, processListTool, processLogTool, processKillTool, webSearchTool, webFetchTool, webBrowseTool, questionTool, approveTool, createLoadSkillTool, pipelineRunTool, mcpCallTool, searchHistoryTool, rememberTool, recallTool, createBrowserTool, attachImageTool, };
32
34
  export function registerAllTools(registry, skillsModule) {
33
35
  const tools = [
34
36
  readFileTool, writeFileTool, editFileTool,
@@ -0,0 +1,110 @@
1
+ import { homedir } from 'os';
2
+ import { join } from 'path';
3
+ import { t } from '../i18n/index';
4
+ import { MemoryStore } from '../modules/memory/store';
5
+ const CATEGORIES = ['preferences', 'conventions', 'decisions', 'errors', 'facts'];
6
+ export const recallTool = {
7
+ name: 'recall',
8
+ description: 'Recall stored information from memory. Search across preferences, facts, conventions, decisions, errors.',
9
+ tags: ['memory'],
10
+ parameters: {
11
+ type: 'object',
12
+ properties: {
13
+ query: {
14
+ type: 'string',
15
+ description: 'Search query (full-text search across all memory)',
16
+ },
17
+ category: {
18
+ type: 'string',
19
+ description: 'Limit to specific category: preferences, conventions, decisions, errors, facts',
20
+ enum: CATEGORIES,
21
+ },
22
+ },
23
+ },
24
+ handler: async (_ctx, args) => {
25
+ const query = args.query ? String(args.query) : '';
26
+ const category = args.category ? String(args.category) : '';
27
+ const memoryDir = join(homedir(), '.mma', 'memory');
28
+ const store = new MemoryStore(memoryDir);
29
+ try {
30
+ // No query, no category → show everything
31
+ if (!query && !category) {
32
+ return { success: true, output: formatAll(store) };
33
+ }
34
+ // Category only → show that category
35
+ if (!query && category) {
36
+ return { success: true, output: formatCategory(store, category) };
37
+ }
38
+ // Query with optional category → search
39
+ if (category) {
40
+ const results = searchCategory(store, category, query);
41
+ if (results.length === 0) {
42
+ return { success: true, output: t('tool.recall.empty', { query }) };
43
+ }
44
+ return { success: true, output: t('tool.recall.search_results', { category, results: results.join('\n') }) };
45
+ }
46
+ // Query across all
47
+ const results = store.search(query);
48
+ if (results.length === 0) {
49
+ return { success: true, output: t('tool.recall.empty', { query }) };
50
+ }
51
+ const formatted = results.map(r => `[${r.file}] ${r.match}`).join('\n');
52
+ return { success: true, output: t('tool.recall.search_results', { category: 'all', results: formatted }) };
53
+ }
54
+ catch (err) {
55
+ return { success: true, output: t('tool.memory_error', { error: String(err) }) };
56
+ }
57
+ },
58
+ };
59
+ function formatAll(store) {
60
+ const parts = [];
61
+ const prefs = store.getPreferences();
62
+ if (Object.keys(prefs).length > 0) {
63
+ parts.push('Preferences:');
64
+ for (const [k, v] of Object.entries(prefs)) {
65
+ parts.push(` ${k} = ${v}`);
66
+ }
67
+ }
68
+ for (const cat of ['facts', 'conventions', 'decisions', 'errors']) {
69
+ const content = store.read(cat);
70
+ const entries = content.split('\n').filter(l => l.startsWith('- '));
71
+ if (entries.length > 0) {
72
+ parts.push(`\n${cat.charAt(0).toUpperCase() + cat.slice(1)} (last 5):`);
73
+ for (const e of entries.slice(-5)) {
74
+ parts.push(` ${e}`);
75
+ }
76
+ }
77
+ }
78
+ return parts.length > 0 ? parts.join('\n') : t('tool.recall.no_memory');
79
+ }
80
+ function formatCategory(store, category) {
81
+ if (category === 'preferences') {
82
+ const prefs = store.getPreferences();
83
+ if (Object.keys(prefs).length === 0)
84
+ return t('tool.recall.no_memory');
85
+ const lines = ['Preferences:'];
86
+ for (const [k, v] of Object.entries(prefs)) {
87
+ lines.push(` ${k} = ${v}`);
88
+ }
89
+ return lines.join('\n');
90
+ }
91
+ const content = store.read(category);
92
+ const entries = content.split('\n').filter(l => l.startsWith('- '));
93
+ if (entries.length === 0)
94
+ return t('tool.recall.no_memory');
95
+ return `${category.charAt(0).toUpperCase() + category.slice(1)} (${entries.length} entries):\n${entries.join('\n')}`;
96
+ }
97
+ function searchCategory(store, category, query) {
98
+ if (category === 'preferences') {
99
+ const prefs = store.getPreferences();
100
+ const lower = query.toLowerCase();
101
+ return Object.entries(prefs)
102
+ .filter(([k, v]) => k.toLowerCase().includes(lower) || v.toLowerCase().includes(lower))
103
+ .map(([k, v]) => ` ${k} = ${v}`);
104
+ }
105
+ const content = store.read(category);
106
+ const lower = query.toLowerCase();
107
+ return content.split('\n')
108
+ .filter(l => l.startsWith('- ') && l.toLowerCase().includes(lower))
109
+ .map(l => ` ${l}`);
110
+ }
@@ -0,0 +1,67 @@
1
+ import { homedir } from 'os';
2
+ import { join } from 'path';
3
+ import { t } from '../i18n/index';
4
+ import { MemoryStore } from '../modules/memory/store';
5
+ const CATEGORIES = ['preferences', 'conventions', 'decisions', 'errors', 'facts'];
6
+ export const rememberTool = {
7
+ name: 'remember',
8
+ description: 'Remember information across sessions. Use for user preferences, facts, conventions, decisions, or errors.',
9
+ tags: ['memory'],
10
+ parameters: {
11
+ type: 'object',
12
+ properties: {
13
+ category: {
14
+ type: 'string',
15
+ description: 'Memory category: preferences, conventions, decisions, errors, facts',
16
+ enum: CATEGORIES,
17
+ },
18
+ key: {
19
+ type: 'string',
20
+ description: 'Key name (required for preferences, e.g. "color", "language")',
21
+ },
22
+ value: {
23
+ type: 'string',
24
+ description: 'Value to store (required for preferences)',
25
+ },
26
+ entry: {
27
+ type: 'string',
28
+ description: 'Text entry to append (for conventions, decisions, errors, facts)',
29
+ },
30
+ },
31
+ required: ['category'],
32
+ },
33
+ handler: async (_ctx, args) => {
34
+ const category = String(args.category || '');
35
+ if (!CATEGORIES.includes(category)) {
36
+ return { success: false, output: t('tool.invalid_params') };
37
+ }
38
+ const memoryDir = join(homedir(), '.mma', 'memory');
39
+ const store = new MemoryStore(memoryDir);
40
+ try {
41
+ if (category === 'preferences') {
42
+ const key = String(args.key || '');
43
+ const value = String(args.value || '');
44
+ if (!key) {
45
+ return { success: false, output: t('tool.remember.key_required') };
46
+ }
47
+ store.setPreference(key, value);
48
+ return {
49
+ success: true,
50
+ output: t('tool.remember.preference', { key, value }),
51
+ };
52
+ }
53
+ const entry = String(args.entry || '');
54
+ if (!entry) {
55
+ return { success: false, output: t('tool.remember.entry_required') };
56
+ }
57
+ store.append(category, entry);
58
+ return {
59
+ success: true,
60
+ output: t('tool.remember.entry', { category, entry }),
61
+ };
62
+ }
63
+ catch (err) {
64
+ return { success: true, output: t('tool.memory_error', { error: String(err) }) };
65
+ }
66
+ },
67
+ };
package/package.json CHANGED
@@ -1,43 +1,44 @@
1
- {
2
- "name": "micro-models-agent",
3
- "version": "0.16.8",
4
- "description": "Micro Models Agent (MMA) — LLM agent harness for small models (Qwen3.5-9B, 32K-64K context)",
5
- "type": "module",
6
- "bin": {
7
- "mma": "bin/mma.mjs"
8
- },
9
- "files": [
10
- "dist/",
11
- "bin/"
12
- ],
13
- "engines": {
14
- "node": ">=20"
15
- },
16
- "scripts": {
17
- "mma": "bun run src/cli/main.ts",
18
- "build": "bun run build:tsc && bun run build:copy-assets",
19
- "build:tsc": "tsc -p tsconfig.build.json",
20
- "build:copy-assets": "powershell -Command \"Copy-Item -Recurse -Force 'src/modules/skills/builtin' 'dist/skills/builtin'\"",
21
- "build:prod": "bun run 'build:bundle' && bun run 'build:copy-assets'",
22
- "build:clean": "cmd /c \"if exist dist rmdir /s /q dist\"",
23
- "build:bundle": "bun build ./src/cli/main.ts --outfile ./dist/main.js --target node --format esm --external playwright",
24
- "dev": "bun --watch src/cli/main.ts",
25
- "typecheck": "tsc --noEmit",
26
- "test": "vitest run",
27
- "test:watch": "vitest",
28
- "test:integration": "vitest run --config vitest.integration.config.ts"
29
- },
30
- "dependencies": {
31
- "commander": "^12.0.0",
32
- "js-tiktoken": "^1.0.0",
33
- "jsonrepair": "^3.15.0",
34
- "picocolors": "^1.1.1",
35
- "playwright": "^1.62.0",
36
- "string-width": "^8.2.2"
37
- },
38
- "devDependencies": {
39
- "@types/node": "^22.0.0",
40
- "typescript": "^5.8.0",
41
- "vitest": "^3.0.0"
42
- }
43
- }
1
+ {
2
+ "name": "micro-models-agent",
3
+ "version": "0.18.0",
4
+ "description": "Micro Models Agent (MMA) — LLM agent harness for small models (Qwen3.5-9B, 32K-64K context)",
5
+ "type": "module",
6
+ "bin": {
7
+ "mma": "bin/mma.mjs"
8
+ },
9
+ "files": [
10
+ "dist/",
11
+ "bin/"
12
+ ],
13
+ "engines": {
14
+ "node": ">=20"
15
+ },
16
+ "scripts": {
17
+ "mma": "bun run src/cli/main.ts",
18
+ "build": "bun run build:tsc && bun run build:copy-assets",
19
+ "build:tsc": "tsc -p tsconfig.build.json",
20
+ "build:copy-assets": "powershell -Command \"Copy-Item -Recurse -Force 'src/modules/skills/builtin' 'dist/skills/builtin'\"",
21
+ "build:prod": "bun run 'build:bundle' && bun run 'build:copy-assets'",
22
+ "build:clean": "cmd /c \"if exist dist rmdir /s /q dist\"",
23
+ "build:bundle": "bun build ./src/cli/main.ts --outfile ./dist/main.js --target node --format esm --external playwright",
24
+ "dev": "bun --watch src/cli/main.ts",
25
+ "typecheck": "tsc --noEmit",
26
+ "test": "vitest run",
27
+ "test:watch": "vitest",
28
+ "test:integration": "vitest run --config vitest.integration.config.ts"
29
+ },
30
+ "dependencies": {
31
+ "commander": "^12.0.0",
32
+ "js-tiktoken": "^1.0.0",
33
+ "jsonrepair": "^3.15.0",
34
+ "picocolors": "^1.1.1",
35
+ "playwright": "^1.62.0",
36
+ "string-width": "^8.2.2"
37
+ },
38
+ "devDependencies": {
39
+ "@types/bun": "^1.3.14",
40
+ "@types/node": "^22.0.0",
41
+ "typescript": "^5.8.0",
42
+ "vitest": "^3.0.0"
43
+ }
44
+ }