micro-models-agent 0.41.2 → 0.43.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/bin/mma.mjs +41 -41
- package/dist/cli/commands.js +19 -9
- package/dist/cli/completer.js +37 -36
- package/dist/cli/index.js +2 -2
- package/dist/cli/main.js +23 -48
- package/dist/cli/repl-commands.js +12 -40
- package/dist/cli/repl.js +87 -217
- package/dist/cli/security-commands.js +7 -5
- package/dist/cli/setup.js +26 -8
- package/dist/config/config.js +5 -52
- package/dist/config/defaults.js +5 -29
- package/dist/config/experts.js +1 -1
- package/dist/config/index.js +3 -3
- package/dist/config/security.js +10 -3
- package/dist/core/agent-moe.js +10 -2
- package/dist/core/agent.js +82 -273
- package/dist/core/bootstrap.js +13 -80
- package/dist/core/index.js +2 -2
- package/dist/core/prompt-builder.js +2 -23
- package/dist/core/session-logger.js +4 -46
- package/dist/i18n/en.json +2 -75
- package/dist/i18n/ru.json +1 -74
- package/dist/index.js +1 -1
- package/dist/llm/image-utils.js +5 -4
- package/dist/llm/index.js +4 -4
- package/dist/llm/model-loader.js +6 -6
- package/dist/llm/openai-compat.js +34 -40
- package/dist/llm/orchestrator.js +29 -33
- package/dist/llm/response.js +9 -9
- package/dist/logger/app-logger.js +1 -1
- package/dist/logger/index.js +1 -1
- package/dist/main.js +648 -183
- package/dist/migration/backup.js +13 -13
- package/dist/migration/detect.js +11 -11
- package/dist/migration/index.js +2 -2
- package/dist/modules/browser/actions.js +4 -34
- package/dist/modules/browser/bridge-server.mjs +202 -202
- package/dist/modules/browser/cookie-store.js +6 -6
- package/dist/modules/browser/index.js +5 -7
- package/dist/modules/browser/module.js +7 -8
- package/dist/modules/browser/session.js +84 -87
- package/dist/modules/browser/snapshot.js +58 -92
- package/dist/modules/browser/types.js +1 -4
- package/dist/modules/certification/cli.js +4 -2
- package/dist/modules/certification/fact-checker.js +3 -1
- package/dist/modules/certification/loader.js +9 -3
- package/dist/modules/certification/runner.js +4 -1
- package/dist/modules/context/index.js +1 -1
- package/dist/modules/context/manager.js +86 -160
- package/dist/modules/execution/auditor.js +25 -177
- package/dist/modules/execution/module.js +544 -201
- package/dist/modules/execution/moe-executor.js +0 -25
- package/dist/modules/execution/plan-store.js +3 -1
- package/dist/modules/execution/plan-validator.js +10 -10
- package/dist/modules/execution/planner.js +1 -6
- package/dist/modules/execution/stuck-detector.js +10 -173
- package/dist/modules/execution/verifier.js +42 -86
- package/dist/modules/hallucination/confidence.js +1 -8
- package/dist/modules/hallucination/detector.js +5 -2
- package/dist/modules/hallucination/factual.js +64 -3
- package/dist/modules/hallucination/index.js +1 -1
- package/dist/modules/hallucination/js-identifiers.js +0 -190
- package/dist/modules/hallucination/llm-judge.js +3 -1
- package/dist/modules/indexer/cache.js +7 -9
- package/dist/modules/indexer/index.js +3 -3
- package/dist/modules/indexer/module.js +42 -95
- package/dist/modules/indexer/walker.js +17 -17
- package/dist/modules/lsp/client.js +31 -74
- package/dist/modules/lsp/config.js +33 -87
- package/dist/modules/lsp/index.js +3 -3
- package/dist/modules/lsp/module.js +21 -185
- package/dist/modules/mcp/module.js +6 -2
- package/dist/modules/memory/index.js +1 -1
- package/dist/modules/memory/module.js +23 -71
- package/dist/modules/memory/search.js +9 -11
- package/dist/modules/memory/store.js +13 -13
- package/dist/modules/pipelines/engine.js +10 -10
- package/dist/modules/pipelines/index.js +3 -3
- package/dist/modules/pipelines/parser.js +14 -17
- package/dist/modules/pipelines/template.js +1 -1
- package/dist/modules/plugins/builtin/lint-on-write.js +16 -21
- package/dist/modules/plugins/builtin/notify.js +2 -3
- package/dist/modules/plugins/index.js +1 -1
- package/dist/modules/plugins/loader.js +17 -59
- package/dist/modules/plugins/manager.js +17 -73
- package/dist/modules/processes/index.js +1 -1
- package/dist/modules/processes/registry.js +46 -135
- package/dist/modules/registry.js +2 -4
- package/dist/modules/security/audit-notifier.js +39 -39
- package/dist/modules/security/command-validator.js +8 -2
- package/dist/modules/security/data-sanitizer.js +9 -1
- package/dist/modules/security/encryption.js +56 -58
- package/dist/modules/security/network-validator.js +9 -1
- package/dist/modules/security/path-validator.js +3 -1
- package/dist/modules/security/security-policies.js +19 -3
- package/dist/modules/security/session-encryption.js +1 -1
- package/dist/modules/security/session-isolation.js +8 -8
- package/dist/modules/session/index.js +3 -3
- package/dist/modules/session/module.js +5 -5
- package/dist/modules/session/store.js +9 -3
- package/dist/modules/skills/module.js +2 -1
- package/dist/modules/updater/checker.js +6 -70
- package/dist/modules/updater/index.js +1 -2
- package/dist/modules/user-profile/compressor.js +2 -2
- package/dist/modules/user-profile/index.js +1 -1
- package/dist/modules/user-profile/profile.js +9 -9
- package/dist/tools/attach-image.js +1 -1
- package/dist/tools/bash.js +19 -178
- package/dist/tools/browser.js +29 -46
- package/dist/tools/executor.js +5 -4
- package/dist/tools/file-info.js +12 -13
- package/dist/tools/filter-tools.js +2 -9
- package/dist/tools/glob-tool.js +11 -11
- package/dist/tools/grep-tool.js +3 -1
- package/dist/tools/index.js +2 -13
- package/dist/tools/list-dir.js +17 -18
- package/dist/tools/load-skill.js +3 -1
- package/dist/tools/path-utils.js +4 -4
- package/dist/tools/pipeline-run.js +25 -25
- package/dist/tools/process-kill.js +11 -11
- package/dist/tools/process-list.js +22 -20
- package/dist/tools/process-log.js +18 -22
- package/dist/tools/question.js +3 -1
- package/dist/tools/read-file.js +2 -10
- package/dist/tools/recall.js +37 -44
- package/dist/tools/registry.js +4 -15
- package/dist/tools/remember.js +29 -29
- package/dist/tools/scope-check.js +9 -9
- package/dist/tools/subagent.js +9 -54
- package/dist/tools/user-input.js +1 -1
- package/dist/tools/web-browse.js +3 -3
- package/dist/tools/web-fetch.js +3 -3
- package/dist/tools/web-search.js +3 -3
- package/dist/tools/write-file.js +3 -1
- package/dist/ui/box.js +5 -1
- package/dist/ui/index.js +6 -6
- package/dist/ui/md-formatter.js +33 -33
- package/dist/ui/output.js +5 -5
- package/dist/ui/renderer.js +10 -15
- package/dist/ui/table.js +1 -1
- package/package.json +48 -48
- package/dist/cli/plugin-commands.js +0 -36
- package/dist/cli/run-result.js +0 -22
- package/dist/core/version.js +0 -24
- package/dist/modules/artifacts/store.js +0 -61
- package/dist/modules/browser/bridge-client.js +0 -199
- package/dist/modules/browser/bridge-path.js +0 -10
- package/dist/modules/browser/driver.js +0 -136
- package/dist/modules/context/chunk-query.js +0 -100
- package/dist/modules/context/fact-extractor.js +0 -162
- package/dist/modules/context/history.js +0 -15
- package/dist/modules/execution/audit-runners.js +0 -152
- package/dist/modules/execution/execution-plugin.js +0 -272
- package/dist/modules/execution/plan-tool.js +0 -508
- package/dist/modules/execution/windows-commands.js +0 -41
- package/dist/modules/indexer/project-profile.js +0 -183
- package/dist/modules/lsp/check-tool.js +0 -58
- package/dist/modules/lsp/command.js +0 -60
- package/dist/modules/lsp/probe.js +0 -76
- package/dist/modules/lsp/project-root.js +0 -32
- package/dist/modules/lsp/startup-check.js +0 -141
- package/dist/modules/processes/detect.js +0 -34
- package/dist/modules/skills/matcher.js +0 -27
- package/dist/modules/updater/module.js +0 -116
- package/dist/tools/chunk-query.js +0 -99
- package/dist/tools/download-file.js +0 -116
- package/dist/tools/enable-tools.js +0 -58
- package/dist/tools/hidden-tools-block.js +0 -37
- package/dist/ui/line-editor.js +0 -703
- package/dist/ui/line-math.js +0 -69
- package/dist/ui/plan-view.js +0 -103
package/dist/tools/remember.js
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import { homedir } from
|
|
2
|
-
import { join } from
|
|
3
|
-
import { t } from
|
|
4
|
-
import { MemoryStore } from
|
|
5
|
-
const CATEGORIES = [
|
|
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
6
|
export const rememberTool = {
|
|
7
|
-
name:
|
|
8
|
-
description:
|
|
9
|
-
tags: [
|
|
7
|
+
name: 'remember',
|
|
8
|
+
description: 'Remember information across sessions. Use for user preferences, facts, conventions, decisions, or errors.',
|
|
9
|
+
tags: ['memory'],
|
|
10
10
|
parameters: {
|
|
11
|
-
type:
|
|
11
|
+
type: 'object',
|
|
12
12
|
properties: {
|
|
13
13
|
category: {
|
|
14
|
-
type:
|
|
15
|
-
description:
|
|
14
|
+
type: 'string',
|
|
15
|
+
description: 'Memory category: preferences, conventions, decisions, errors, facts',
|
|
16
16
|
enum: CATEGORIES,
|
|
17
17
|
},
|
|
18
18
|
key: {
|
|
19
|
-
type:
|
|
19
|
+
type: 'string',
|
|
20
20
|
description: 'Key name (required for preferences, e.g. "color", "language")',
|
|
21
21
|
},
|
|
22
22
|
value: {
|
|
23
|
-
type:
|
|
24
|
-
description:
|
|
23
|
+
type: 'string',
|
|
24
|
+
description: 'Value to store (required for preferences)',
|
|
25
25
|
},
|
|
26
26
|
entry: {
|
|
27
|
-
type:
|
|
28
|
-
description:
|
|
27
|
+
type: 'string',
|
|
28
|
+
description: 'Text entry to append (for conventions, decisions, errors, facts)',
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
|
-
required: [
|
|
31
|
+
required: ['category'],
|
|
32
32
|
},
|
|
33
33
|
handler: async (_ctx, args) => {
|
|
34
|
-
const category = String(args.category ||
|
|
34
|
+
const category = String(args.category || '');
|
|
35
35
|
if (!CATEGORIES.includes(category)) {
|
|
36
|
-
return { success: false, output: t(
|
|
36
|
+
return { success: false, output: t('tool.invalid_params') };
|
|
37
37
|
}
|
|
38
|
-
const memoryDir = join(homedir(),
|
|
38
|
+
const memoryDir = join(homedir(), '.mma', 'memory');
|
|
39
39
|
const store = new MemoryStore(memoryDir);
|
|
40
40
|
try {
|
|
41
|
-
if (category ===
|
|
42
|
-
const key = String(args.key ||
|
|
43
|
-
const value = String(args.value ||
|
|
41
|
+
if (category === 'preferences') {
|
|
42
|
+
const key = String(args.key || '');
|
|
43
|
+
const value = String(args.value || '');
|
|
44
44
|
if (!key) {
|
|
45
|
-
return { success: false, output: t(
|
|
45
|
+
return { success: false, output: t('tool.remember.key_required') };
|
|
46
46
|
}
|
|
47
47
|
store.setPreference(key, value);
|
|
48
48
|
return {
|
|
49
49
|
success: true,
|
|
50
|
-
output: t(
|
|
50
|
+
output: t('tool.remember.preference', { key, value }),
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
const entry = String(args.entry ||
|
|
53
|
+
const entry = String(args.entry || '');
|
|
54
54
|
if (!entry) {
|
|
55
|
-
return { success: false, output: t(
|
|
55
|
+
return { success: false, output: t('tool.remember.entry_required') };
|
|
56
56
|
}
|
|
57
57
|
store.append(category, entry);
|
|
58
58
|
return {
|
|
59
59
|
success: true,
|
|
60
|
-
output: t(
|
|
60
|
+
output: t('tool.remember.entry', { category, entry }),
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
catch (err) {
|
|
64
|
-
return { success: true, output: t(
|
|
64
|
+
return { success: true, output: t('tool.memory_error', { error: String(err) }) };
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
};
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { resolve, normalize } from
|
|
1
|
+
import { resolve, normalize } from 'path';
|
|
2
2
|
export function isPathInScope(baseDir, targetPath, scope) {
|
|
3
3
|
const baseResolved = resolve(baseDir);
|
|
4
4
|
const targetResolved = resolve(baseDir, normalize(targetPath));
|
|
5
5
|
if (!targetResolved.startsWith(baseResolved)) {
|
|
6
|
-
return { allowed: false, reason:
|
|
6
|
+
return { allowed: false, reason: 'Path is outside the base working directory' };
|
|
7
7
|
}
|
|
8
8
|
if (!scope)
|
|
9
9
|
return { allowed: true };
|
|
10
|
-
const isRead = scope.read_only_files.some(
|
|
11
|
-
const isWrite = scope.allowed_files.some(
|
|
10
|
+
const isRead = scope.read_only_files.some(f => targetResolved.startsWith(resolve(baseDir, f)));
|
|
11
|
+
const isWrite = scope.allowed_files.some(f => targetResolved.startsWith(resolve(baseDir, f)));
|
|
12
12
|
if (isWrite)
|
|
13
13
|
return { allowed: true };
|
|
14
14
|
if (isRead)
|
|
15
|
-
return { allowed: true, reason:
|
|
16
|
-
return { allowed: false, reason:
|
|
15
|
+
return { allowed: true, reason: 'Read-only file' };
|
|
16
|
+
return { allowed: false, reason: 'Path is not within the allowed scope for this sub-agent' };
|
|
17
17
|
}
|
|
18
18
|
export function isPathWritable(baseDir, targetPath, scope) {
|
|
19
19
|
const baseResolved = resolve(baseDir);
|
|
20
20
|
const targetResolved = resolve(baseDir, normalize(targetPath));
|
|
21
21
|
if (!targetResolved.startsWith(baseResolved)) {
|
|
22
|
-
return { allowed: false, reason:
|
|
22
|
+
return { allowed: false, reason: 'Path is outside the base working directory' };
|
|
23
23
|
}
|
|
24
24
|
if (!scope)
|
|
25
25
|
return { allowed: true };
|
|
26
|
-
const isWrite = scope.allowed_files.some(
|
|
26
|
+
const isWrite = scope.allowed_files.some(f => targetResolved.startsWith(resolve(baseDir, f)));
|
|
27
27
|
if (isWrite)
|
|
28
28
|
return { allowed: true };
|
|
29
|
-
return { allowed: false, reason:
|
|
29
|
+
return { allowed: false, reason: 'Path is not within the writable scope for this sub-agent' };
|
|
30
30
|
}
|
package/dist/tools/subagent.js
CHANGED
|
@@ -5,20 +5,6 @@ import { HallucinationDetector } from "../modules/hallucination/detector";
|
|
|
5
5
|
import { PluginManager } from "../modules/plugins/manager";
|
|
6
6
|
import { logSecurityBlock } from "../modules/security/audit-log";
|
|
7
7
|
import { getSessionSecurityConfig } from "../modules/security/session-isolation";
|
|
8
|
-
import { ArtifactStore } from "../modules/artifacts/store";
|
|
9
|
-
/** Fixed system prompt (KV-cache friendly when stableSystemPrompt is on). */
|
|
10
|
-
export const SUBAGENT_SYSTEM_PROMPT_TEMPLATE = `You are a sub-agent working on a specific task. You have your own context window and tool set.
|
|
11
|
-
|
|
12
|
-
Workflow rules:
|
|
13
|
-
- Prefer small, focused steps. Verify your own work (typecheck/tests) before finishing.
|
|
14
|
-
- For large outputs, write the result to a file with write_file instead of reproducing it in your answer.
|
|
15
|
-
- If the task is big and decomposable, delegate parts to the subagent tool instead of doing everything in one context.
|
|
16
|
-
- When you finish, return a concise final answer; do not repeat file contents verbatim if you already wrote them to disk.`;
|
|
17
|
-
function buildSubagentSystemPrompt(context, stable) {
|
|
18
|
-
if (stable)
|
|
19
|
-
return SUBAGENT_SYSTEM_PROMPT_TEMPLATE;
|
|
20
|
-
return `You are a sub-agent working on a specific task. ${context ? `Context: ${context}` : ""}`;
|
|
21
|
-
}
|
|
22
8
|
export const subagentTool = {
|
|
23
9
|
name: "subagent",
|
|
24
10
|
description: "Spawn an isolated sub-agent to work on a task independently. The sub-agent has its own context and executes autonomously. Use for parallel work or complex sub-tasks.",
|
|
@@ -61,15 +47,6 @@ export const subagentTool = {
|
|
|
61
47
|
items: { type: "string" },
|
|
62
48
|
description: "Tool tags to expose to the sub-agent",
|
|
63
49
|
},
|
|
64
|
-
result_mode: {
|
|
65
|
-
type: "string",
|
|
66
|
-
enum: ["text", "file"],
|
|
67
|
-
description: '"file": persist the full result to an artifact and return a path + summary (pass-by-reference). "text" (default): return the full text into context.',
|
|
68
|
-
},
|
|
69
|
-
artifact_name: {
|
|
70
|
-
type: "string",
|
|
71
|
-
description: "Artifact file name (sanitized). Default: subagent-<timestamp>.",
|
|
72
|
-
},
|
|
73
50
|
},
|
|
74
51
|
required: ["task"],
|
|
75
52
|
},
|
|
@@ -109,10 +86,8 @@ export const subagentTool = {
|
|
|
109
86
|
// Defensive guard: if the caller requested specific tool tags but none of the
|
|
110
87
|
// registered tools match, the sub-agent would have zero tools and would
|
|
111
88
|
// hallucinate instead of acting. Warn the caller so it can correct the tags.
|
|
112
|
-
// Uses getByTags (not getAllForLLM) because alwaysOn tools always match the
|
|
113
|
-
// latter — the guard must test real tag coverage, not schema presence.
|
|
114
89
|
if (toolTags && toolTags.length > 0) {
|
|
115
|
-
const matched = ctx.toolExecutor.
|
|
90
|
+
const matched = ctx.toolExecutor.getToolDefinitions(toolTags);
|
|
116
91
|
if (matched.length === 0) {
|
|
117
92
|
return {
|
|
118
93
|
success: false,
|
|
@@ -129,10 +104,10 @@ export const subagentTool = {
|
|
|
129
104
|
const parentScope = ctx.scope;
|
|
130
105
|
ctx.toolExecutor.setScope(scope || { allowed_files: [], read_only_files: [] });
|
|
131
106
|
const systemPrompt = {
|
|
132
|
-
content:
|
|
107
|
+
content: `You are a sub-agent working on a specific task. ${context ? `Context: ${context}` : ""}`,
|
|
133
108
|
priority: "critical",
|
|
134
109
|
essential: true,
|
|
135
|
-
estimatedTokens:
|
|
110
|
+
estimatedTokens: 100,
|
|
136
111
|
};
|
|
137
112
|
const subDeps = {
|
|
138
113
|
config: ctx.config,
|
|
@@ -153,35 +128,15 @@ export const subagentTool = {
|
|
|
153
128
|
let scopeRestored = false;
|
|
154
129
|
try {
|
|
155
130
|
const result = await subAgent.run(fullTask);
|
|
156
|
-
|
|
157
|
-
|
|
131
|
+
return result.success
|
|
132
|
+
? {
|
|
133
|
+
success: true,
|
|
134
|
+
output: `Sub-agent completed:\n${result.text}\n\nIterations: ${result.iterationCount}`,
|
|
135
|
+
}
|
|
136
|
+
: {
|
|
158
137
|
success: false,
|
|
159
138
|
output: `Sub-agent failed: ${result.error}\nPartial output: ${result.text}`,
|
|
160
139
|
};
|
|
161
|
-
}
|
|
162
|
-
const resultMode = args.result_mode || ctx.config.subagent?.resultMode || "text";
|
|
163
|
-
if (resultMode === "file") {
|
|
164
|
-
const store = new ArtifactStore({
|
|
165
|
-
baseDir: ctx.baseDir,
|
|
166
|
-
sessionId: ctx.sessionId || "default",
|
|
167
|
-
artifactsDir: ctx.config.subagent?.artifactsDir,
|
|
168
|
-
});
|
|
169
|
-
const abs = store.save(args.artifact_name || `subagent-${Date.now()}`, result.text, "md");
|
|
170
|
-
const summary = store.summary(result.text, ctx.config.subagent?.maxSummaryChars ?? 2000);
|
|
171
|
-
ctx.logger.debug(`subagent result persisted to artifact ${abs} (${result.text.length} chars, ${result.iterationCount} iterations)`);
|
|
172
|
-
return {
|
|
173
|
-
success: true,
|
|
174
|
-
output: t("tool.subagent_artifact", {
|
|
175
|
-
path: abs,
|
|
176
|
-
iterations: String(result.iterationCount),
|
|
177
|
-
summary,
|
|
178
|
-
}),
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
return {
|
|
182
|
-
success: true,
|
|
183
|
-
output: `Sub-agent completed:\n${result.text}\n\nIterations: ${result.iterationCount}`,
|
|
184
|
-
};
|
|
185
140
|
}
|
|
186
141
|
finally {
|
|
187
142
|
if (!scopeRestored) {
|
package/dist/tools/user-input.js
CHANGED
|
@@ -82,7 +82,7 @@ export async function askChoice(question, options, opts = {}) {
|
|
|
82
82
|
const answer = await promptLine(rl, choicePrompt(entryCount, multiple));
|
|
83
83
|
const parsed = parseSelection(answer, entryCount, multiple);
|
|
84
84
|
if (parsed) {
|
|
85
|
-
return parsed.map((i) =>
|
|
85
|
+
return parsed.map((i) => opts.allowCustom && i === customEntry ? CUSTOM_INDEX : i);
|
|
86
86
|
}
|
|
87
87
|
console.log(t("tool.user_input.invalid"));
|
|
88
88
|
}
|
package/dist/tools/web-browse.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { t } from "../i18n/index";
|
|
2
|
-
import { isUrlAllowed, sanitizeUrl } from "../modules/security/network-validator";
|
|
3
|
-
import { logNetworkRequest, logSecurityBlock } from "../modules/security/audit-log";
|
|
2
|
+
import { isUrlAllowed, sanitizeUrl, } from "../modules/security/network-validator";
|
|
3
|
+
import { logNetworkRequest, logSecurityBlock, } from "../modules/security/audit-log";
|
|
4
4
|
import { getSessionSecurityConfig } from "../modules/security/session-isolation";
|
|
5
5
|
import { MAX_PREVIEW_LINES } from "./preview";
|
|
6
6
|
const MAX_CHARS = 3000;
|
|
7
7
|
export const webBrowseTool = {
|
|
8
8
|
name: "web_browse",
|
|
9
|
-
description: `Fetch and read a web page. Returns the page content as plain text (max ${MAX_PREVIEW_LINES} lines / ${MAX_CHARS} chars)
|
|
9
|
+
description: `Fetch and read a web page. Returns the page content as plain text (max ${MAX_PREVIEW_LINES} lines / ${MAX_CHARS} chars).`,
|
|
10
10
|
tags: ["research"],
|
|
11
11
|
parameters: {
|
|
12
12
|
type: "object",
|
package/dist/tools/web-fetch.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t } from "../i18n/index";
|
|
2
|
-
import { isUrlAllowed, sanitizeUrl } from "../modules/security/network-validator";
|
|
3
|
-
import { logNetworkRequest, logSecurityBlock } from "../modules/security/audit-log";
|
|
2
|
+
import { isUrlAllowed, sanitizeUrl, } from "../modules/security/network-validator";
|
|
3
|
+
import { logNetworkRequest, logSecurityBlock, } from "../modules/security/audit-log";
|
|
4
4
|
import { getSessionSecurityConfig } from "../modules/security/session-isolation";
|
|
5
5
|
import { DEFAULT_SECURITY_CONFIG } from "../config/security";
|
|
6
6
|
import { MAX_PREVIEW_LINES } from "./preview";
|
|
@@ -16,7 +16,7 @@ function stripHtml(html) {
|
|
|
16
16
|
}
|
|
17
17
|
export const webFetchTool = {
|
|
18
18
|
name: "web_fetch",
|
|
19
|
-
description:
|
|
19
|
+
description: "Fetch a URL and convert its content to markdown. Use for reading documentation, APIs, web pages.",
|
|
20
20
|
tags: ["research"],
|
|
21
21
|
parameters: {
|
|
22
22
|
type: "object",
|
package/dist/tools/web-search.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t } from "../i18n/index";
|
|
2
|
-
import { isUrlAllowed, sanitizeUrl } from "../modules/security/network-validator";
|
|
3
|
-
import { logNetworkRequest, logSecurityBlock } from "../modules/security/audit-log";
|
|
2
|
+
import { isUrlAllowed, sanitizeUrl, } from "../modules/security/network-validator";
|
|
3
|
+
import { logNetworkRequest, logSecurityBlock, } from "../modules/security/audit-log";
|
|
4
4
|
import { getSessionSecurityConfig } from "../modules/security/session-isolation";
|
|
5
5
|
export const webSearchTool = {
|
|
6
6
|
name: "web_search",
|
|
7
|
-
description: "Search the web for information. Returns search results with titles and snippets.
|
|
7
|
+
description: "Search the web for information. Returns search results with titles and snippets.",
|
|
8
8
|
tags: ["research"],
|
|
9
9
|
parameters: {
|
|
10
10
|
type: "object",
|
package/dist/tools/write-file.js
CHANGED
|
@@ -71,7 +71,9 @@ export const writeFileTool = {
|
|
|
71
71
|
oldContent = readFileSync(resolved, "utf-8");
|
|
72
72
|
}
|
|
73
73
|
writeFileSync(resolved, content, "utf-8");
|
|
74
|
-
const diff = fileExists
|
|
74
|
+
const diff = fileExists
|
|
75
|
+
? generateDiff(oldContent, content)
|
|
76
|
+
: generateNewFileDiff(content);
|
|
75
77
|
// Increment file operations counter
|
|
76
78
|
ctx.fileOperationsCount = currentCount + 1;
|
|
77
79
|
// Log successful file write
|
package/dist/ui/box.js
CHANGED
|
@@ -65,7 +65,11 @@ export function box(lines, opts = {}) {
|
|
|
65
65
|
out.push(pc.dim(`┌${"─".repeat(width - 2)}┐`));
|
|
66
66
|
}
|
|
67
67
|
for (const line of wrapped) {
|
|
68
|
-
out.push(pc.dim("│") +
|
|
68
|
+
out.push(pc.dim("│") +
|
|
69
|
+
" ".repeat(pad) +
|
|
70
|
+
padTo(line, inner) +
|
|
71
|
+
" ".repeat(pad) +
|
|
72
|
+
pc.dim("│"));
|
|
69
73
|
}
|
|
70
74
|
out.push(pc.dim(`└${"─".repeat(width - 2)}┘`));
|
|
71
75
|
return out;
|
package/dist/ui/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { formatMarkdown, formatError, formatSuccess, formatWarning, FormattingStream
|
|
2
|
-
export { writeOutput, writeError, writeSuccess, writeWarning } from
|
|
3
|
-
export { formatTable, splitRow, isSeparatorRow, getTerminalWidth } from
|
|
4
|
-
export { box, divider, wrapText } from
|
|
5
|
-
export { Spinner, isSpinnerSupported } from
|
|
6
|
-
export { Renderer, isRichTerminal, summarizeArgs } from
|
|
1
|
+
export { formatMarkdown, formatError, formatSuccess, formatWarning, FormattingStream } from './md-formatter';
|
|
2
|
+
export { writeOutput, writeError, writeSuccess, writeWarning } from './output';
|
|
3
|
+
export { formatTable, splitRow, isSeparatorRow, getTerminalWidth } from './table';
|
|
4
|
+
export { box, divider, wrapText } from './box';
|
|
5
|
+
export { Spinner, isSpinnerSupported } from './spinner';
|
|
6
|
+
export { Renderer, isRichTerminal, summarizeArgs } from './renderer';
|
package/dist/ui/md-formatter.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { pc } from
|
|
2
|
-
import { t } from
|
|
3
|
-
import { formatTable, getTerminalWidth } from
|
|
1
|
+
import { pc } from './colors';
|
|
2
|
+
import { t } from '../i18n/index';
|
|
3
|
+
import { formatTable, getTerminalWidth } from './table';
|
|
4
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
5
|
const STRING = /('[^']*'|"[^"]*"|`[^`]*`)/g;
|
|
6
6
|
const COMMENT = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|#[^\n]*)/g;
|
|
@@ -8,21 +8,21 @@ const NUMBER = /\b(\d+\.?\d*)\b/g;
|
|
|
8
8
|
const TAG = /<\/?([A-Z][a-zA-Z0-9]*|[a-z][a-zA-Z0-9-]*)/g;
|
|
9
9
|
const ATTR = /\b([a-zA-Z-]+=)"([^"]*)"/g;
|
|
10
10
|
function highlight(code, lang) {
|
|
11
|
-
if (lang ===
|
|
11
|
+
if (lang === 'html' || lang === 'xml' || lang === 'svg') {
|
|
12
12
|
code = code.replace(COMMENT, (m) => pc.dim(pc.green(m)));
|
|
13
|
-
code = code.replace(ATTR, (_m, attr, val) => pc.yellow(attr) +
|
|
14
|
-
code = code.replace(TAG, (_m, tag) =>
|
|
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
15
|
}
|
|
16
|
-
else if (lang ===
|
|
16
|
+
else if (lang === 'css' || lang === 'scss' || lang === 'less') {
|
|
17
17
|
code = code.replace(COMMENT, (m) => pc.dim(pc.green(m)));
|
|
18
18
|
code = code.replace(STRING, (m) => pc.green(m));
|
|
19
19
|
code = code.replace(NUMBER, (m) => pc.yellow(m));
|
|
20
20
|
}
|
|
21
|
-
else if (lang ===
|
|
21
|
+
else if (lang === 'bash' || lang === 'sh' || lang === 'shell' || lang === 'zsh') {
|
|
22
22
|
code = code.replace(COMMENT, (m) => pc.dim(pc.green(m)));
|
|
23
23
|
code = code.replace(STRING, (m) => pc.green(m));
|
|
24
24
|
}
|
|
25
|
-
else if (lang ===
|
|
25
|
+
else if (lang === 'json') {
|
|
26
26
|
code = code.replace(STRING, (m) => pc.green(m));
|
|
27
27
|
code = code.replace(NUMBER, (m) => pc.yellow(m));
|
|
28
28
|
}
|
|
@@ -37,7 +37,7 @@ function highlight(code, lang) {
|
|
|
37
37
|
}
|
|
38
38
|
function isTableRow(line) {
|
|
39
39
|
const trimmed = line.trim();
|
|
40
|
-
if (!trimmed.startsWith(
|
|
40
|
+
if (!trimmed.startsWith('|'))
|
|
41
41
|
return false;
|
|
42
42
|
const pipes = trimmed.match(/\|/g);
|
|
43
43
|
return (pipes?.length ?? 0) >= 2;
|
|
@@ -46,9 +46,9 @@ function isHorizontalRule(line) {
|
|
|
46
46
|
return /^(-{3,}|\*{3,}|_{3,})\s*$/.test(line.trim());
|
|
47
47
|
}
|
|
48
48
|
export class FormattingStream {
|
|
49
|
-
buffer =
|
|
49
|
+
buffer = '';
|
|
50
50
|
inCodeBlock = false;
|
|
51
|
-
codeLang =
|
|
51
|
+
codeLang = '';
|
|
52
52
|
codeLines = [];
|
|
53
53
|
tableBuffer = [];
|
|
54
54
|
onWrite;
|
|
@@ -60,7 +60,7 @@ export class FormattingStream {
|
|
|
60
60
|
write(chunk) {
|
|
61
61
|
this.buffer += chunk;
|
|
62
62
|
let idx;
|
|
63
|
-
while ((idx = this.buffer.indexOf(
|
|
63
|
+
while ((idx = this.buffer.indexOf('\n')) !== -1) {
|
|
64
64
|
const line = this.buffer.slice(0, idx);
|
|
65
65
|
this.buffer = this.buffer.slice(idx + 1);
|
|
66
66
|
this.processLine(line);
|
|
@@ -75,8 +75,8 @@ export class FormattingStream {
|
|
|
75
75
|
}
|
|
76
76
|
if (this.buffer.length > 0) {
|
|
77
77
|
const line = this.buffer;
|
|
78
|
-
this.buffer =
|
|
79
|
-
if (line.trim() ===
|
|
78
|
+
this.buffer = '';
|
|
79
|
+
if (line.trim() === '```' || line.trim().startsWith('```')) {
|
|
80
80
|
if (this.codeLines.length > 0) {
|
|
81
81
|
this.emitCodeBlock();
|
|
82
82
|
}
|
|
@@ -86,7 +86,7 @@ export class FormattingStream {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
processLine(line) {
|
|
89
|
-
if (line.trim() ===
|
|
89
|
+
if (line.trim() === '```' || line.trim().startsWith('```')) {
|
|
90
90
|
if (this.inCodeBlock) {
|
|
91
91
|
this.emitCodeBlock();
|
|
92
92
|
}
|
|
@@ -128,18 +128,18 @@ export class FormattingStream {
|
|
|
128
128
|
emitCodeBlock() {
|
|
129
129
|
this.inCodeBlock = false;
|
|
130
130
|
if (this.codeLines.length > 0) {
|
|
131
|
-
const code = this.codeLines.join(
|
|
131
|
+
const code = this.codeLines.join('\n');
|
|
132
132
|
const highlighted = highlight(code, this.codeLang);
|
|
133
|
-
const lang = this.codeLang ? ` ${this.codeLang} ` :
|
|
134
|
-
const top = pc.dim(`┌─${lang}${
|
|
133
|
+
const lang = this.codeLang ? ` ${this.codeLang} ` : ' ';
|
|
134
|
+
const top = pc.dim(`┌─${lang}${'─'.repeat(Math.max(0, this.width - 3 - lang.length))}┐`);
|
|
135
135
|
this.onWrite(top);
|
|
136
|
-
for (const l of highlighted.split(
|
|
137
|
-
this.onWrite(pc.dim(
|
|
136
|
+
for (const l of highlighted.split('\n')) {
|
|
137
|
+
this.onWrite(pc.dim('│ ') + l);
|
|
138
138
|
}
|
|
139
|
-
this.onWrite(pc.dim(`└${
|
|
139
|
+
this.onWrite(pc.dim(`└${'─'.repeat(Math.max(0, this.width - 1))}┘`));
|
|
140
140
|
}
|
|
141
141
|
this.codeLines = [];
|
|
142
|
-
this.codeLang =
|
|
142
|
+
this.codeLang = '';
|
|
143
143
|
}
|
|
144
144
|
formatLine(line) {
|
|
145
145
|
let result = line;
|
|
@@ -152,18 +152,18 @@ export class FormattingStream {
|
|
|
152
152
|
return pc.cyan(pc.bold(content));
|
|
153
153
|
}
|
|
154
154
|
if (isHorizontalRule(result)) {
|
|
155
|
-
return pc.dim(
|
|
155
|
+
return pc.dim('─'.repeat(Math.max(0, Math.min(this.width, 60))));
|
|
156
156
|
}
|
|
157
157
|
const quote = result.match(/^(>+)\s?(.*)$/);
|
|
158
158
|
if (quote) {
|
|
159
159
|
const depth = Math.min(quote[1].length, 4);
|
|
160
|
-
const marker = pc.dim(
|
|
160
|
+
const marker = pc.dim('▍'.repeat(depth));
|
|
161
161
|
return `${marker} ${this.formatInline(quote[2])}`;
|
|
162
162
|
}
|
|
163
163
|
const checkbox = result.match(/^[-*]\s+\[([ xX])\]\s+(.+)$/);
|
|
164
164
|
if (checkbox) {
|
|
165
|
-
const checked = checkbox[1].toLowerCase() ===
|
|
166
|
-
const mark = checked ? pc.green(
|
|
165
|
+
const checked = checkbox[1].toLowerCase() === 'x';
|
|
166
|
+
const mark = checked ? pc.green('✓') : pc.dim('☐');
|
|
167
167
|
return ` ${mark} ${this.formatInline(checkbox[2])}`;
|
|
168
168
|
}
|
|
169
169
|
const ordered = result.match(/^(\d+)[.)]\s+(.+)$/);
|
|
@@ -172,7 +172,7 @@ export class FormattingStream {
|
|
|
172
172
|
}
|
|
173
173
|
const bullet = result.match(/^[-*]\s+(.+)$/);
|
|
174
174
|
if (bullet) {
|
|
175
|
-
return ` ${pc.dim(
|
|
175
|
+
return ` ${pc.dim('•')} ${this.formatInline(bullet[1])}`;
|
|
176
176
|
}
|
|
177
177
|
return this.formatInline(result);
|
|
178
178
|
}
|
|
@@ -187,7 +187,7 @@ export class FormattingStream {
|
|
|
187
187
|
result = result.replace(/\*([^*]+)\*/g, (_, s) => pc.italic(s));
|
|
188
188
|
result = result.replace(/(^|\s)_([^_\n]+)_(?=\s|$)/g, (_m, pre, s) => pre + pc.italic(s));
|
|
189
189
|
result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, label, url) => {
|
|
190
|
-
const short = url.length > 80 ? url.slice(0, 77) +
|
|
190
|
+
const short = url.length > 80 ? url.slice(0, 77) + '…' : url;
|
|
191
191
|
return `${pc.cyan(label)} ${pc.dim(`(${short})`)}`;
|
|
192
192
|
});
|
|
193
193
|
result = result.replace(/\u0000(\d+)\u0000/g, (_m, i) => codeSpans[Number(i)]);
|
|
@@ -199,14 +199,14 @@ export function formatMarkdown(text) {
|
|
|
199
199
|
const stream = new FormattingStream((l) => lines.push(l));
|
|
200
200
|
stream.write(text);
|
|
201
201
|
stream.flush();
|
|
202
|
-
return lines.join(
|
|
202
|
+
return lines.join('\n');
|
|
203
203
|
}
|
|
204
204
|
export function formatError(text) {
|
|
205
|
-
return pc.red(pc.bold(t(
|
|
205
|
+
return pc.red(pc.bold(t('ui.error_prefix')) + text);
|
|
206
206
|
}
|
|
207
207
|
export function formatSuccess(text) {
|
|
208
|
-
return pc.green(pc.bold(t(
|
|
208
|
+
return pc.green(pc.bold(t('ui.success_prefix')) + text);
|
|
209
209
|
}
|
|
210
210
|
export function formatWarning(text) {
|
|
211
|
-
return pc.yellow(pc.bold(t(
|
|
211
|
+
return pc.yellow(pc.bold(t('ui.warning_prefix')) + text);
|
|
212
212
|
}
|
package/dist/ui/output.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { formatMarkdown, formatError, formatSuccess, formatWarning } from
|
|
1
|
+
import { formatMarkdown, formatError, formatSuccess, formatWarning } from './md-formatter';
|
|
2
2
|
export function writeOutput(text) {
|
|
3
|
-
process.stdout.write(formatMarkdown(text) +
|
|
3
|
+
process.stdout.write(formatMarkdown(text) + '\n');
|
|
4
4
|
}
|
|
5
5
|
export function writeError(text) {
|
|
6
|
-
process.stderr.write(formatError(text) +
|
|
6
|
+
process.stderr.write(formatError(text) + '\n');
|
|
7
7
|
}
|
|
8
8
|
export function writeSuccess(text) {
|
|
9
|
-
process.stdout.write(formatSuccess(text) +
|
|
9
|
+
process.stdout.write(formatSuccess(text) + '\n');
|
|
10
10
|
}
|
|
11
11
|
export function writeWarning(text) {
|
|
12
|
-
process.stdout.write(formatWarning(text) +
|
|
12
|
+
process.stdout.write(formatWarning(text) + '\n');
|
|
13
13
|
}
|
package/dist/ui/renderer.js
CHANGED
|
@@ -118,36 +118,29 @@ export class Renderer {
|
|
|
118
118
|
thinkingEnd() {
|
|
119
119
|
this.spinner.stop();
|
|
120
120
|
}
|
|
121
|
-
toolStart(tool, args
|
|
121
|
+
toolStart(tool, args) {
|
|
122
122
|
this.endCard();
|
|
123
123
|
this.spinner.stop();
|
|
124
124
|
const summary = summarizeArgs(args);
|
|
125
|
-
const step = stepContext ? ` ${pc.cyan(`← ${stepContext}`)}` : "";
|
|
126
125
|
if (!this.rich) {
|
|
127
|
-
this.out.write(`\n${pc.dim("⚙")} ${friendlyTool(tool)}${summary ? ` ${pc.dim(summary)}` : ""}
|
|
126
|
+
this.out.write(`\n${pc.dim("⚙")} ${friendlyTool(tool)}${summary ? ` ${pc.dim(summary)}` : ""}\n`);
|
|
128
127
|
return;
|
|
129
128
|
}
|
|
130
129
|
this.card = { tool, args, body: [], start: Date.now() };
|
|
131
130
|
if (this.toolStyle === "inline") {
|
|
132
131
|
const marker = toolMarker(tool);
|
|
133
|
-
this.out.write(`\n${pc.dim(marker)} ${friendlyTool(tool)}${summary ? ` ${pc.dim(summary)}` : ""}
|
|
132
|
+
this.out.write(`\n${pc.dim(marker)} ${friendlyTool(tool)}${summary ? ` ${pc.dim(summary)}` : ""}\n`);
|
|
134
133
|
return;
|
|
135
134
|
}
|
|
136
|
-
this.spinner.start(`${pc.dim("⚙")} ${friendlyTool(tool)}${summary ? ` ${pc.dim(summary)}` : ""}
|
|
137
|
-
}
|
|
138
|
-
/** Live plan checklist — prints the plan block as-is (already colored). */
|
|
139
|
-
planBlock(lines) {
|
|
140
|
-
this.endCard();
|
|
141
|
-
this.spinner.stop();
|
|
142
|
-
for (const line of lines) {
|
|
143
|
-
this.out.write(`${line}\n`);
|
|
144
|
-
}
|
|
135
|
+
this.spinner.start(`${pc.dim("⚙")} ${friendlyTool(tool)}${summary ? ` ${pc.dim(summary)}` : ""}`);
|
|
145
136
|
}
|
|
146
137
|
toolEnd(_tool, duration, error, ctxDelta) {
|
|
147
138
|
this.spinner.stop();
|
|
148
139
|
if (!this.rich) {
|
|
149
140
|
if (ctxDelta !== undefined && ctxDelta !== 0) {
|
|
150
|
-
const deltaStr = ctxDelta > 0
|
|
141
|
+
const deltaStr = ctxDelta > 0
|
|
142
|
+
? pc.green(`+${ctxDelta}`)
|
|
143
|
+
: pc.yellow(`${ctxDelta} ↓`);
|
|
151
144
|
this.out.write(`${pc.dim("ctx")} ${deltaStr}\n`);
|
|
152
145
|
}
|
|
153
146
|
return;
|
|
@@ -158,7 +151,9 @@ export class Renderer {
|
|
|
158
151
|
const marker = error ? pc.red("✗") : pc.green("✓");
|
|
159
152
|
let footer = `${marker} ${pc.dim(`${duration}ms`)}`;
|
|
160
153
|
if (ctxDelta !== undefined && ctxDelta !== 0) {
|
|
161
|
-
const deltaStr = ctxDelta > 0
|
|
154
|
+
const deltaStr = ctxDelta > 0
|
|
155
|
+
? pc.green(`+${ctxDelta}`)
|
|
156
|
+
: pc.yellow(`${ctxDelta} ↓`);
|
|
162
157
|
footer += ` ${pc.dim("ctx")} ${deltaStr}`;
|
|
163
158
|
}
|
|
164
159
|
if (this.toolStyle === "inline") {
|
package/dist/ui/table.js
CHANGED
|
@@ -106,7 +106,7 @@ export function formatTable(tableLines, opts = {}) {
|
|
|
106
106
|
for (let c = 0; c < columnCount; c++) {
|
|
107
107
|
const raw = row[c] ?? "";
|
|
108
108
|
const cell = truncate(raw, widths[c]);
|
|
109
|
-
const a = isHeader && align[c] === undefined ? "center" :
|
|
109
|
+
const a = isHeader && align[c] === undefined ? "center" : align[c] ?? "left";
|
|
110
110
|
cells.push(pad(cell, widths[c], a));
|
|
111
111
|
}
|
|
112
112
|
const content = cells.map((c) => pc.dim("│ ") + c).join("") + pc.dim("│");
|