micro-models-agent 0.18.3 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/bootstrap.js +5 -12
- package/dist/modules/hallucination/confidence.js +7 -2
- package/dist/modules/hallucination/consistency.js +12 -6
- package/dist/modules/hallucination/detector.js +10 -18
- package/dist/modules/hallucination/index.js +3 -4
- package/dist/tools/create-dir.js +0 -1
- package/dist/tools/delete-file.js +0 -1
- package/dist/tools/read-file.js +0 -3
- package/dist/tools/write-file.js +1 -2
- package/package.json +1 -1
- package/dist/main.js +0 -18225
- package/dist/modules/hallucination/factual.js +0 -170
package/dist/core/bootstrap.js
CHANGED
|
@@ -34,10 +34,9 @@ function buildSystemInfo(config, baseDir, profileCompressed) {
|
|
|
34
34
|
`Workspace: ${baseDir}`,
|
|
35
35
|
`${profileCompressed}`,
|
|
36
36
|
`Reply in the user's language. Use tools for filesystem, bash, web access.`,
|
|
37
|
-
`
|
|
38
|
-
`
|
|
39
|
-
`If
|
|
40
|
-
`If a tool call fails (e.g., a skill is too large), try an alternative approach or continue without it. Do not reply with empty text when the task is unfinished.`,
|
|
37
|
+
`Use tools when needed. Explain briefly what you're doing if it's not obvious.`,
|
|
38
|
+
`Answer the user's question directly. Only take action when the user explicitly asks you to change, create, or fix something.`,
|
|
39
|
+
`If a tool call fails, report the error and ask the user how to proceed.`,
|
|
41
40
|
``,
|
|
42
41
|
`Design principles — apply them automatically without naming them:`,
|
|
43
42
|
`- Do not add code, files, or abstractions that are not needed right now (YAGNI — You Ain't Gonna Need It). If something is not required by the current task, omit it.`,
|
|
@@ -49,7 +48,7 @@ function buildSystemInfo(config, baseDir, profileCompressed) {
|
|
|
49
48
|
}
|
|
50
49
|
lines.push(``, `Bash tool rules:`, `- Use the "workdir" parameter to run commands in a specific directory. Do NOT chain "cd dir && cmd" — the security module blocks the "&&" operator.`, `- Run one command per tool call. Split multi-step shell operations into separate bash calls.`);
|
|
51
50
|
if (config.autoPlan) {
|
|
52
|
-
lines.push(``, `Plan rule: For
|
|
51
|
+
lines.push(``, `Plan rule: For complex tasks with 3+ steps, you may create a plan using the "plan" tool. For simple questions, just answer directly.`);
|
|
53
52
|
}
|
|
54
53
|
const hasMCP = config.mcpServers &&
|
|
55
54
|
Object.values(config.mcpServers).some((s) => s.enabled !== false);
|
|
@@ -187,12 +186,6 @@ export async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplet
|
|
|
187
186
|
toolCtx.llmProvider = llmProvider;
|
|
188
187
|
toolCtx.toolExecutor = toolExecutor;
|
|
189
188
|
const hallucinationDetector = new HallucinationDetector();
|
|
190
|
-
const factualCheck = hallucinationDetector.getFactualCheck();
|
|
191
|
-
factualCheck.setBaseDir(baseDir);
|
|
192
|
-
toolCtx.trackReadPath = (p) => factualCheck.trackReadPath(p);
|
|
193
|
-
toolCtx.trackCreatedPath = (p) => factualCheck.trackCreatedPath(p);
|
|
194
|
-
toolCtx.trackDeletedPath = (p) => factualCheck.trackDeletedPath(p);
|
|
195
|
-
toolCtx.trackDocumentContent = (c) => factualCheck.trackDocumentContent(c);
|
|
196
189
|
const moduleRegistry = new ModuleRegistry();
|
|
197
190
|
const execModule = new ExecutionModule(baseDir, config.stuckThreshold);
|
|
198
191
|
moduleRegistry.register(execModule);
|
|
@@ -203,7 +196,7 @@ export async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplet
|
|
|
203
196
|
const mcpModule = new MCPModule(config);
|
|
204
197
|
await mcpModule.initialize();
|
|
205
198
|
moduleRegistry.register(mcpModule);
|
|
206
|
-
const memoryModule = new MemoryModule(join(dir,
|
|
199
|
+
const memoryModule = new MemoryModule(join(dir, "memory"));
|
|
207
200
|
moduleRegistry.register(memoryModule);
|
|
208
201
|
if (config.browser.enabled) {
|
|
209
202
|
const browserModule = new BrowserModule();
|
|
@@ -30,14 +30,19 @@ export class ConfidenceCheck {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
// Language-agnostic: very low word diversity (same words repeated)
|
|
33
|
-
const words = response
|
|
33
|
+
const words = response
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.split(/\s+/)
|
|
36
|
+
.filter((w) => w.length > 2);
|
|
34
37
|
if (words.length >= 10) {
|
|
35
38
|
const unique = new Set(words);
|
|
36
39
|
const diversity = unique.size / words.length;
|
|
37
40
|
if (diversity < 0.25) {
|
|
38
41
|
return {
|
|
39
42
|
status: "warn",
|
|
40
|
-
reason: t("hall.repetitive", {
|
|
43
|
+
reason: t("hall.repetitive", {
|
|
44
|
+
pct: Math.round((1 - diversity) * 100),
|
|
45
|
+
}),
|
|
41
46
|
};
|
|
42
47
|
}
|
|
43
48
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t } from
|
|
1
|
+
import { t } from "../../i18n/index";
|
|
2
2
|
export class ConsistencyCheck {
|
|
3
3
|
decisions = [];
|
|
4
4
|
createdFiles = new Set();
|
|
@@ -18,8 +18,11 @@ export class ConsistencyCheck {
|
|
|
18
18
|
validate(response) {
|
|
19
19
|
const lower = response.toLowerCase();
|
|
20
20
|
for (const d of this.decisions) {
|
|
21
|
-
const decisionWords = d.decision
|
|
22
|
-
|
|
21
|
+
const decisionWords = d.decision
|
|
22
|
+
.toLowerCase()
|
|
23
|
+
.split(/\s+/)
|
|
24
|
+
.filter((w) => w.length > 3);
|
|
25
|
+
const contradicts = decisionWords.some((word) => {
|
|
23
26
|
// English patterns
|
|
24
27
|
if (lower.includes(`instead of ${word}`))
|
|
25
28
|
return true;
|
|
@@ -50,11 +53,14 @@ export class ConsistencyCheck {
|
|
|
50
53
|
});
|
|
51
54
|
if (contradicts) {
|
|
52
55
|
return {
|
|
53
|
-
status:
|
|
54
|
-
reason: t(
|
|
56
|
+
status: "warn",
|
|
57
|
+
reason: t("hall.contradiction", {
|
|
58
|
+
decision: d.decision,
|
|
59
|
+
location: d.location,
|
|
60
|
+
}),
|
|
55
61
|
};
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
|
-
return { status:
|
|
64
|
+
return { status: "pass" };
|
|
59
65
|
}
|
|
60
66
|
}
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { ConfidenceCheck } from './confidence';
|
|
1
|
+
import { ConsistencyCheck } from "./consistency";
|
|
2
|
+
import { ConfidenceCheck } from "./confidence";
|
|
4
3
|
export class HallucinationDetector {
|
|
5
|
-
factual;
|
|
6
4
|
consistency;
|
|
7
5
|
confidence;
|
|
8
6
|
constructor() {
|
|
9
|
-
this.factual = new FactualCheck();
|
|
10
7
|
this.consistency = new ConsistencyCheck();
|
|
11
8
|
this.confidence = new ConfidenceCheck();
|
|
12
9
|
}
|
|
13
|
-
getFactualCheck() {
|
|
14
|
-
return this.factual;
|
|
15
|
-
}
|
|
16
10
|
getConsistencyCheck() {
|
|
17
11
|
return this.consistency;
|
|
18
12
|
}
|
|
@@ -21,21 +15,19 @@ export class HallucinationDetector {
|
|
|
21
15
|
}
|
|
22
16
|
validate(response) {
|
|
23
17
|
const confidenceResult = this.confidence.validate(response);
|
|
24
|
-
if (confidenceResult.status ===
|
|
18
|
+
if (confidenceResult.status === "retry" ||
|
|
19
|
+
confidenceResult.status === "block") {
|
|
25
20
|
return confidenceResult;
|
|
26
21
|
}
|
|
27
|
-
const factualResult = this.factual.validate(response);
|
|
28
22
|
const consistencyResult = this.consistency.validate(response);
|
|
29
23
|
const warnings = [];
|
|
30
|
-
if (
|
|
31
|
-
warnings.push(
|
|
32
|
-
if (
|
|
33
|
-
warnings.push(
|
|
34
|
-
if (confidenceResult.status === 'warn')
|
|
35
|
-
warnings.push(confidenceResult.reason || '');
|
|
24
|
+
if (consistencyResult.status === "warn")
|
|
25
|
+
warnings.push(consistencyResult.reason || "");
|
|
26
|
+
if (confidenceResult.status === "warn")
|
|
27
|
+
warnings.push(confidenceResult.reason || "");
|
|
36
28
|
if (warnings.length > 0) {
|
|
37
|
-
return { status:
|
|
29
|
+
return { status: "warn", reason: warnings.join("; ") };
|
|
38
30
|
}
|
|
39
|
-
return { status:
|
|
31
|
+
return { status: "pass" };
|
|
40
32
|
}
|
|
41
33
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { HallucinationDetector } from
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export { ConfidenceCheck } from './confidence';
|
|
1
|
+
export { HallucinationDetector, } from "./detector";
|
|
2
|
+
export { ConsistencyCheck } from "./consistency";
|
|
3
|
+
export { ConfidenceCheck } from "./confidence";
|
package/dist/tools/create-dir.js
CHANGED
|
@@ -50,7 +50,6 @@ export const createDirTool = {
|
|
|
50
50
|
ctx.fileOperationsCount = currentCount + 1;
|
|
51
51
|
// Log directory creation
|
|
52
52
|
logFileWrite(ctx.sessionId, path, true, "Directory created");
|
|
53
|
-
ctx.trackCreatedPath?.(path);
|
|
54
53
|
return { success: true, output: t("file.created", { path }) };
|
|
55
54
|
},
|
|
56
55
|
};
|
|
@@ -57,7 +57,6 @@ export const deleteFileTool = {
|
|
|
57
57
|
ctx.fileOperationsCount = currentCount + 1;
|
|
58
58
|
// Log successful file deletion
|
|
59
59
|
logFileDelete(ctx.sessionId, path, true);
|
|
60
|
-
ctx.trackDeletedPath?.(path);
|
|
61
60
|
return { success: true, output: t("file.deleted", { path }), diff };
|
|
62
61
|
},
|
|
63
62
|
};
|
package/dist/tools/read-file.js
CHANGED
|
@@ -44,10 +44,7 @@ export const readFileTool = {
|
|
|
44
44
|
if (!existsSync(resolved)) {
|
|
45
45
|
return { success: false, output: t("file.notfound", { path }) };
|
|
46
46
|
}
|
|
47
|
-
ctx.trackReadPath?.(path);
|
|
48
47
|
const content = readFileSync(resolved, "utf-8");
|
|
49
|
-
// Track file paths mentioned in the document (e.g. structure.md, README)
|
|
50
|
-
ctx.trackDocumentContent?.(content);
|
|
51
48
|
const lines = content.split("\n");
|
|
52
49
|
const total = lines.length;
|
|
53
50
|
const offset = args.offset || 1;
|
package/dist/tools/write-file.js
CHANGED
|
@@ -73,8 +73,7 @@ export const writeFileTool = {
|
|
|
73
73
|
// Increment file operations counter
|
|
74
74
|
ctx.fileOperationsCount = currentCount + 1;
|
|
75
75
|
// Log successful file write
|
|
76
|
-
logFileWrite(ctx.sessionId, path, true, `File ${fileExists ?
|
|
77
|
-
ctx.trackCreatedPath?.(path);
|
|
76
|
+
logFileWrite(ctx.sessionId, path, true, `File ${fileExists ? "updated" : "created"}`);
|
|
78
77
|
return { success: true, output: t("file.written", { path }), diff };
|
|
79
78
|
},
|
|
80
79
|
};
|