micro-models-agent 0.43.3 → 0.45.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/README.md +312 -312
- package/bin/mma.mjs +41 -41
- package/dist/main.js +333 -66
- package/dist/skills/builtin/git.md +36 -36
- package/dist/skills/builtin/typescript.md +35 -35
- package/package.json +1 -1
- package/dist/cli/commands.js +0 -333
- package/dist/cli/completer.js +0 -168
- package/dist/cli/index.js +0 -2
- package/dist/cli/main.js +0 -140
- package/dist/cli/repl-commands.js +0 -633
- package/dist/cli/repl.js +0 -486
- package/dist/cli/security-commands.js +0 -166
- package/dist/cli/setup.js +0 -249
- package/dist/config/config.js +0 -202
- package/dist/config/defaults.js +0 -100
- package/dist/config/experts.js +0 -15
- package/dist/config/index.js +0 -3
- package/dist/config/security.js +0 -200
- package/dist/config/types.js +0 -1
- package/dist/core/agent-moe.js +0 -110
- package/dist/core/agent.js +0 -695
- package/dist/core/bootstrap.js +0 -337
- package/dist/core/index.js +0 -2
- package/dist/core/prompt-builder.js +0 -55
- package/dist/core/session-logger.js +0 -155
- package/dist/core/types.js +0 -1
- package/dist/core/workspace.js +0 -76
- package/dist/i18n/en.json +0 -525
- package/dist/i18n/index.js +0 -46
- package/dist/i18n/ru.json +0 -525
- package/dist/index.js +0 -22
- package/dist/llm/image-utils.js +0 -144
- package/dist/llm/index.js +0 -4
- package/dist/llm/model-loader.js +0 -78
- package/dist/llm/openai-compat.js +0 -353
- package/dist/llm/orchestrator.js +0 -194
- package/dist/llm/provider.js +0 -10
- package/dist/llm/response.js +0 -39
- package/dist/llm/token-counter.js +0 -39
- package/dist/llm/types.js +0 -1
- package/dist/logger/app-logger.js +0 -143
- package/dist/logger/file-log.js +0 -151
- package/dist/logger/index.js +0 -1
- package/dist/migration/backup.js +0 -45
- package/dist/migration/detect.js +0 -50
- package/dist/migration/index.js +0 -2
- package/dist/modules/browser/actions.js +0 -46
- package/dist/modules/browser/cookie-store.js +0 -24
- package/dist/modules/browser/index.js +0 -5
- package/dist/modules/browser/module.js +0 -28
- package/dist/modules/browser/session.js +0 -335
- package/dist/modules/browser/snapshot.js +0 -114
- package/dist/modules/browser/types.js +0 -9
- package/dist/modules/certification/cli.js +0 -176
- package/dist/modules/certification/fact-checker.js +0 -84
- package/dist/modules/certification/loader.js +0 -111
- package/dist/modules/certification/manifest.js +0 -50
- package/dist/modules/certification/runner.js +0 -162
- package/dist/modules/certification/scenarios.js +0 -124
- package/dist/modules/certification/types.js +0 -1
- package/dist/modules/context/index.js +0 -1
- package/dist/modules/context/manager.js +0 -349
- package/dist/modules/execution/auditor.js +0 -66
- package/dist/modules/execution/index.js +0 -8
- package/dist/modules/execution/module.js +0 -779
- package/dist/modules/execution/moe-executor.js +0 -266
- package/dist/modules/execution/plan-coverage.js +0 -68
- package/dist/modules/execution/plan-persister.js +0 -46
- package/dist/modules/execution/plan-store.js +0 -159
- package/dist/modules/execution/plan-validator.js +0 -153
- package/dist/modules/execution/planner.js +0 -85
- package/dist/modules/execution/stuck-detector.js +0 -347
- package/dist/modules/execution/tracker.js +0 -67
- package/dist/modules/execution/types.js +0 -1
- package/dist/modules/execution/verifier.js +0 -178
- package/dist/modules/hallucination/confidence.js +0 -59
- package/dist/modules/hallucination/consistency.js +0 -26
- package/dist/modules/hallucination/detector.js +0 -46
- package/dist/modules/hallucination/factual.js +0 -190
- package/dist/modules/hallucination/index.js +0 -5
- package/dist/modules/hallucination/js-identifiers.js +0 -72
- package/dist/modules/hallucination/llm-judge.js +0 -103
- package/dist/modules/index.js +0 -5
- package/dist/modules/indexer/cache.js +0 -38
- package/dist/modules/indexer/index.js +0 -3
- package/dist/modules/indexer/module.js +0 -192
- package/dist/modules/indexer/walker.js +0 -101
- package/dist/modules/lsp/client.js +0 -235
- package/dist/modules/lsp/config.js +0 -81
- package/dist/modules/lsp/index.js +0 -3
- package/dist/modules/lsp/module.js +0 -68
- package/dist/modules/lsp/types.js +0 -1
- package/dist/modules/mcp/client.js +0 -399
- package/dist/modules/mcp/index.js +0 -3
- package/dist/modules/mcp/module.js +0 -146
- package/dist/modules/mcp/registry.js +0 -15
- package/dist/modules/memory/index.js +0 -1
- package/dist/modules/memory/module.js +0 -48
- package/dist/modules/memory/search.js +0 -40
- package/dist/modules/memory/store.js +0 -69
- package/dist/modules/pipelines/engine.js +0 -60
- package/dist/modules/pipelines/index.js +0 -3
- package/dist/modules/pipelines/parser.js +0 -53
- package/dist/modules/pipelines/template.js +0 -14
- package/dist/modules/plugins/builtin/lint-on-write.js +0 -226
- package/dist/modules/plugins/builtin/notify.js +0 -8
- package/dist/modules/plugins/index.js +0 -1
- package/dist/modules/plugins/loader.js +0 -28
- package/dist/modules/plugins/manager.js +0 -161
- package/dist/modules/plugins/types.js +0 -1
- package/dist/modules/processes/index.js +0 -2
- package/dist/modules/processes/registry.js +0 -238
- package/dist/modules/processes/runner.js +0 -23
- package/dist/modules/registry.js +0 -45
- package/dist/modules/security/audit-log.js +0 -136
- package/dist/modules/security/audit-notifier.js +0 -292
- package/dist/modules/security/command-validator.js +0 -211
- package/dist/modules/security/content-scanner.js +0 -53
- package/dist/modules/security/data-sanitizer.js +0 -97
- package/dist/modules/security/encryption.js +0 -240
- package/dist/modules/security/index.js +0 -14
- package/dist/modules/security/network-validator.js +0 -79
- package/dist/modules/security/path-validator.js +0 -209
- package/dist/modules/security/rate-limiter.js +0 -119
- package/dist/modules/security/security-policies.js +0 -547
- package/dist/modules/security/session-encryption.js +0 -210
- package/dist/modules/security/session-isolation.js +0 -95
- package/dist/modules/session/index.js +0 -3
- package/dist/modules/session/manager.js +0 -172
- package/dist/modules/session/module.js +0 -24
- package/dist/modules/session/store.js +0 -228
- package/dist/modules/session/types.js +0 -1
- package/dist/modules/skills/index.js +0 -2
- package/dist/modules/skills/loader.js +0 -72
- package/dist/modules/skills/module.js +0 -130
- package/dist/modules/types.js +0 -1
- package/dist/modules/updater/checker.js +0 -32
- package/dist/modules/updater/index.js +0 -1
- package/dist/modules/user-profile/compressor.js +0 -16
- package/dist/modules/user-profile/index.js +0 -1
- package/dist/modules/user-profile/profile.js +0 -68
- package/dist/tools/approve.js +0 -32
- package/dist/tools/attach-image.js +0 -89
- package/dist/tools/bash.js +0 -337
- package/dist/tools/browser.js +0 -97
- package/dist/tools/create-dir.js +0 -55
- package/dist/tools/delete-file.js +0 -62
- package/dist/tools/edit-file.js +0 -79
- package/dist/tools/executor.js +0 -145
- package/dist/tools/file-info.js +0 -45
- package/dist/tools/filter-tools.js +0 -10
- package/dist/tools/glob-tool.js +0 -26
- package/dist/tools/grep-tool.js +0 -86
- package/dist/tools/index.js +0 -67
- package/dist/tools/list-dir.js +0 -47
- package/dist/tools/load-skill.js +0 -44
- package/dist/tools/mcp-call.js +0 -68
- package/dist/tools/move-file.js +0 -85
- package/dist/tools/path-utils.js +0 -51
- package/dist/tools/pipeline-run.js +0 -144
- package/dist/tools/preview.js +0 -2
- package/dist/tools/process-kill.js +0 -29
- package/dist/tools/process-list.js +0 -38
- package/dist/tools/process-log.js +0 -41
- package/dist/tools/question.js +0 -142
- package/dist/tools/read-file.js +0 -83
- package/dist/tools/recall.js +0 -110
- package/dist/tools/registry.js +0 -36
- package/dist/tools/remember.js +0 -67
- package/dist/tools/scope-check.js +0 -30
- package/dist/tools/search-history.js +0 -84
- package/dist/tools/subagent.js +0 -151
- package/dist/tools/types.js +0 -1
- package/dist/tools/user-input.js +0 -123
- package/dist/tools/web-browse.js +0 -86
- package/dist/tools/web-fetch.js +0 -98
- package/dist/tools/web-search.js +0 -78
- package/dist/tools/write-file.js +0 -83
- package/dist/ui/box.js +0 -81
- package/dist/ui/colors.js +0 -4
- package/dist/ui/diff.js +0 -178
- package/dist/ui/index.js +0 -6
- package/dist/ui/md-formatter.js +0 -212
- package/dist/ui/output.js +0 -13
- package/dist/ui/renderer.js +0 -204
- package/dist/ui/spinner.js +0 -70
- package/dist/ui/table.js +0 -144
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { t } from "../../i18n/index";
|
|
2
|
-
const MIN_CHARS = 1;
|
|
3
|
-
const MIN_WORDS = 5;
|
|
4
|
-
export class ConfidenceCheck {
|
|
5
|
-
previousResponse = "";
|
|
6
|
-
setPreviousResponse(response) {
|
|
7
|
-
this.previousResponse = response;
|
|
8
|
-
}
|
|
9
|
-
validate(response) {
|
|
10
|
-
if (!response || response.length < MIN_CHARS) {
|
|
11
|
-
return { status: "retry", reason: t("hall.short_response") };
|
|
12
|
-
}
|
|
13
|
-
// Language-agnostic: very short response with no structured content
|
|
14
|
-
const wordCount = response.split(/\s+/).filter(Boolean).length;
|
|
15
|
-
const hasStructure = /```|^\s*[-*]\s|^\s*\d+\.\s|<[^>]+>/m.test(response);
|
|
16
|
-
if (wordCount < MIN_WORDS && !hasStructure) {
|
|
17
|
-
return {
|
|
18
|
-
status: "warn",
|
|
19
|
-
reason: t("hall.short_response"),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
// Language-agnostic: repetition detection via word overlap
|
|
23
|
-
if (this.previousResponse) {
|
|
24
|
-
const overlap = this.calculateOverlap(response, this.previousResponse);
|
|
25
|
-
if (overlap > 0.5) {
|
|
26
|
-
return {
|
|
27
|
-
status: "retry",
|
|
28
|
-
reason: t("hall.repetitive", { pct: Math.round(overlap * 100) }),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// Language-agnostic: very low word diversity (same words repeated)
|
|
33
|
-
const words = response
|
|
34
|
-
.toLowerCase()
|
|
35
|
-
.split(/\s+/)
|
|
36
|
-
.filter((w) => w.length > 2);
|
|
37
|
-
if (words.length >= 10) {
|
|
38
|
-
const unique = new Set(words);
|
|
39
|
-
const diversity = unique.size / words.length;
|
|
40
|
-
if (diversity < 0.25) {
|
|
41
|
-
return {
|
|
42
|
-
status: "warn",
|
|
43
|
-
reason: t("hall.repetitive", {
|
|
44
|
-
pct: Math.round((1 - diversity) * 100),
|
|
45
|
-
}),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return { status: "pass" };
|
|
50
|
-
}
|
|
51
|
-
calculateOverlap(a, b) {
|
|
52
|
-
const wordsA = new Set(a.toLowerCase().split(/\s+/));
|
|
53
|
-
const wordsB = b.toLowerCase().split(/\s+/);
|
|
54
|
-
if (wordsB.length === 0)
|
|
55
|
-
return 0;
|
|
56
|
-
const matches = wordsB.filter((w) => wordsA.has(w));
|
|
57
|
-
return matches.length / wordsB.length;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export class ConsistencyCheck {
|
|
2
|
-
decisions = [];
|
|
3
|
-
createdFiles = new Set();
|
|
4
|
-
deletedFiles = new Set();
|
|
5
|
-
trackDecision(decision, location) {
|
|
6
|
-
this.decisions.push({ decision, location });
|
|
7
|
-
}
|
|
8
|
-
trackCreatedFile(path) {
|
|
9
|
-
this.createdFiles.add(path);
|
|
10
|
-
}
|
|
11
|
-
trackDeletedFile(path) {
|
|
12
|
-
this.deletedFiles.add(path);
|
|
13
|
-
}
|
|
14
|
-
getCreatedFiles() {
|
|
15
|
-
return Array.from(this.createdFiles);
|
|
16
|
-
}
|
|
17
|
-
getDeletedFiles() {
|
|
18
|
-
return Array.from(this.deletedFiles);
|
|
19
|
-
}
|
|
20
|
-
getDecisions() {
|
|
21
|
-
return this.decisions;
|
|
22
|
-
}
|
|
23
|
-
hasDecisions() {
|
|
24
|
-
return this.decisions.length > 0;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { ConsistencyCheck } from "./consistency";
|
|
2
|
-
import { ConfidenceCheck } from "./confidence";
|
|
3
|
-
import { FactualCheck } from "./factual";
|
|
4
|
-
import { LLMJudge } from "./llm-judge";
|
|
5
|
-
export class HallucinationDetector {
|
|
6
|
-
consistency;
|
|
7
|
-
confidence;
|
|
8
|
-
factual;
|
|
9
|
-
judge;
|
|
10
|
-
constructor(baseDir, llmProvider) {
|
|
11
|
-
this.consistency = new ConsistencyCheck();
|
|
12
|
-
this.confidence = new ConfidenceCheck();
|
|
13
|
-
this.factual = baseDir ? new FactualCheck(baseDir) : null;
|
|
14
|
-
this.judge = llmProvider ? new LLMJudge(llmProvider) : null;
|
|
15
|
-
}
|
|
16
|
-
getConsistencyCheck() {
|
|
17
|
-
return this.consistency;
|
|
18
|
-
}
|
|
19
|
-
getConfidenceCheck() {
|
|
20
|
-
return this.confidence;
|
|
21
|
-
}
|
|
22
|
-
async validate(response) {
|
|
23
|
-
const confidenceResult = this.confidence.validate(response);
|
|
24
|
-
if (confidenceResult.status === "retry" ||
|
|
25
|
-
confidenceResult.status === "block") {
|
|
26
|
-
return confidenceResult;
|
|
27
|
-
}
|
|
28
|
-
const factualResult = this.factual?.validate(response);
|
|
29
|
-
if (factualResult && factualResult.status !== "pass") {
|
|
30
|
-
return factualResult;
|
|
31
|
-
}
|
|
32
|
-
// LLM-as-judge consistency: fast path (no decisions) skips any LLM call.
|
|
33
|
-
const judgeResult = this.judge
|
|
34
|
-
? await this.judge.validate(response, this.consistency)
|
|
35
|
-
: null;
|
|
36
|
-
const warnings = [];
|
|
37
|
-
if (judgeResult && judgeResult.status === "warn")
|
|
38
|
-
warnings.push(judgeResult.reason || "");
|
|
39
|
-
if (confidenceResult.status === "warn")
|
|
40
|
-
warnings.push(confidenceResult.reason || "");
|
|
41
|
-
if (warnings.length > 0) {
|
|
42
|
-
return { status: "warn", reason: warnings.join("; ") };
|
|
43
|
-
}
|
|
44
|
-
return { status: "pass" };
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync } from "fs";
|
|
2
|
-
import { resolve, isAbsolute, join } from "path";
|
|
3
|
-
import { t } from "../../i18n/index";
|
|
4
|
-
import { isJsMemberAccess } from "./js-identifiers";
|
|
5
|
-
/** Generated/cached dirs to skip when scanning for bare file names. */
|
|
6
|
-
const IGNORED_DIRS = new Set([
|
|
7
|
-
"node_modules",
|
|
8
|
-
".git",
|
|
9
|
-
"dist",
|
|
10
|
-
"build",
|
|
11
|
-
"coverage",
|
|
12
|
-
".mma",
|
|
13
|
-
"_testing",
|
|
14
|
-
]);
|
|
15
|
-
const NON_FILE_EXTENSIONS = new Set([
|
|
16
|
-
"com",
|
|
17
|
-
"org",
|
|
18
|
-
"net",
|
|
19
|
-
"gov",
|
|
20
|
-
"edu",
|
|
21
|
-
"io",
|
|
22
|
-
"dev",
|
|
23
|
-
"app",
|
|
24
|
-
"co",
|
|
25
|
-
"ai",
|
|
26
|
-
"ru",
|
|
27
|
-
"de",
|
|
28
|
-
"fr",
|
|
29
|
-
"uk",
|
|
30
|
-
"us",
|
|
31
|
-
"es",
|
|
32
|
-
"it",
|
|
33
|
-
"jp",
|
|
34
|
-
"cn",
|
|
35
|
-
"br",
|
|
36
|
-
]);
|
|
37
|
-
/** Well-known runtime/library names that end in .js/.ts but are NOT files. */
|
|
38
|
-
const TECH_NAMES = new Set([
|
|
39
|
-
"node.js",
|
|
40
|
-
"react.js",
|
|
41
|
-
"vue.js",
|
|
42
|
-
"next.js",
|
|
43
|
-
"angular.js",
|
|
44
|
-
"express.js",
|
|
45
|
-
"deno.js",
|
|
46
|
-
"qwik.js",
|
|
47
|
-
"svelte.js",
|
|
48
|
-
"jquery.js",
|
|
49
|
-
]);
|
|
50
|
-
/**
|
|
51
|
-
* JS/TS global identifiers whose member access (`process.env`, `console.log`)
|
|
52
|
-
* looks like a file path to the regex but is code, not a file.
|
|
53
|
-
*/
|
|
54
|
-
function looksLikeFilePath(s) {
|
|
55
|
-
const lower = s.toLowerCase();
|
|
56
|
-
// "Node.js" etc. are technologies, not files — never flag them.
|
|
57
|
-
if (TECH_NAMES.has(lower))
|
|
58
|
-
return false;
|
|
59
|
-
if (!s.includes("/") && !s.includes("\\") && !s.match(/^\w+\.[a-z]{2,4}$/i))
|
|
60
|
-
return false;
|
|
61
|
-
// process.env / console.log / Math.max — member access on JS globals,
|
|
62
|
-
// not file paths. Only applies to bare `word.word` (no slashes).
|
|
63
|
-
if (isJsMemberAccess(s))
|
|
64
|
-
return false;
|
|
65
|
-
const ext = s.split(".").pop()?.toLowerCase() || "";
|
|
66
|
-
return !NON_FILE_EXTENSIONS.has(ext);
|
|
67
|
-
}
|
|
68
|
-
export class FactualCheck {
|
|
69
|
-
baseDir;
|
|
70
|
-
nameCache = null;
|
|
71
|
-
nameCacheTime = 0;
|
|
72
|
-
lastRescan = 0;
|
|
73
|
-
static NAME_CACHE_TTL_MS = 5_000;
|
|
74
|
-
static RESCAN_COOLDOWN_MS = 2_000;
|
|
75
|
-
static MAX_INDEXED_FILES = 20_000;
|
|
76
|
-
constructor(baseDir) {
|
|
77
|
-
this.baseDir = baseDir;
|
|
78
|
-
}
|
|
79
|
-
validate(response) {
|
|
80
|
-
const filePaths = this.extractFilePaths(response);
|
|
81
|
-
if (filePaths.length === 0)
|
|
82
|
-
return { status: "pass" };
|
|
83
|
-
const nonExistent = [];
|
|
84
|
-
for (const fp of filePaths) {
|
|
85
|
-
if (!this.pathExists(fp)) {
|
|
86
|
-
nonExistent.push(fp);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (nonExistent.length > 0) {
|
|
90
|
-
return {
|
|
91
|
-
status: "warn",
|
|
92
|
-
reason: t("hall.unknown_paths", {
|
|
93
|
-
paths: nonExistent.slice(0, 5).join(", "),
|
|
94
|
-
}),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
return { status: "pass" };
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Bare filenames ("bikes.json") and relative paths ("src/data/bikes.json")
|
|
101
|
-
* both land on the project tree. Absolute paths are checked as-is.
|
|
102
|
-
*/
|
|
103
|
-
pathExists(fp) {
|
|
104
|
-
if (isAbsolute(fp))
|
|
105
|
-
return existsSync(fp);
|
|
106
|
-
// "foo.json" has no directory part — treat it as a bare name that may
|
|
107
|
-
// live anywhere under baseDir (e.g. src/data/bikes.json). Resolving it
|
|
108
|
-
// against the workspace root alone produced false "unknown file" warnings.
|
|
109
|
-
if (!fp.includes("/") && !fp.includes("\\")) {
|
|
110
|
-
return this.bareNameExists(fp);
|
|
111
|
-
}
|
|
112
|
-
return existsSync(resolve(this.baseDir, fp));
|
|
113
|
-
}
|
|
114
|
-
bareNameExists(name) {
|
|
115
|
-
if (existsSync(resolve(this.baseDir, name)))
|
|
116
|
-
return true;
|
|
117
|
-
if (this.indexHas(name))
|
|
118
|
-
return true;
|
|
119
|
-
// A write_file from this session may have created the file after the
|
|
120
|
-
// index was built. Do a one-off rescan (rate-limited) before warning.
|
|
121
|
-
const now = Date.now();
|
|
122
|
-
if (now - this.lastRescan < FactualCheck.RESCAN_COOLDOWN_MS)
|
|
123
|
-
return false;
|
|
124
|
-
this.lastRescan = now;
|
|
125
|
-
this.nameCache = null;
|
|
126
|
-
this.nameCacheTime = 0;
|
|
127
|
-
return this.indexHas(name);
|
|
128
|
-
}
|
|
129
|
-
indexHas(name) {
|
|
130
|
-
return (this.getNameIndex().get(name)?.length ?? 0) > 0;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Basename → paths index, rebuilt every NAME_CACHE_TTL_MS so newly created
|
|
134
|
-
* files (write_file) are picked up without a full scan on every response.
|
|
135
|
-
*/
|
|
136
|
-
getNameIndex() {
|
|
137
|
-
const now = Date.now();
|
|
138
|
-
if (this.nameCache &&
|
|
139
|
-
now - this.nameCacheTime < FactualCheck.NAME_CACHE_TTL_MS) {
|
|
140
|
-
return this.nameCache;
|
|
141
|
-
}
|
|
142
|
-
const index = new Map();
|
|
143
|
-
const scanned = this.scanDir(this.baseDir, index, 0);
|
|
144
|
-
if (scanned > 0 || index.size > 0) {
|
|
145
|
-
this.nameCache = index;
|
|
146
|
-
this.nameCacheTime = now;
|
|
147
|
-
}
|
|
148
|
-
return index;
|
|
149
|
-
}
|
|
150
|
-
scanDir(dir, index, count) {
|
|
151
|
-
if (count >= FactualCheck.MAX_INDEXED_FILES)
|
|
152
|
-
return count;
|
|
153
|
-
let entries;
|
|
154
|
-
try {
|
|
155
|
-
entries = readdirSync(dir, { withFileTypes: true });
|
|
156
|
-
}
|
|
157
|
-
catch {
|
|
158
|
-
return count;
|
|
159
|
-
}
|
|
160
|
-
for (const entry of entries) {
|
|
161
|
-
if (count >= FactualCheck.MAX_INDEXED_FILES)
|
|
162
|
-
break;
|
|
163
|
-
const full = join(dir, entry.name);
|
|
164
|
-
if (entry.isDirectory()) {
|
|
165
|
-
if (!IGNORED_DIRS.has(entry.name)) {
|
|
166
|
-
count = this.scanDir(full, index, count);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else if (entry.isFile()) {
|
|
170
|
-
const list = index.get(entry.name);
|
|
171
|
-
if (list)
|
|
172
|
-
list.push(full);
|
|
173
|
-
else
|
|
174
|
-
index.set(entry.name, [full]);
|
|
175
|
-
count++;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return count;
|
|
179
|
-
}
|
|
180
|
-
extractFilePaths(text) {
|
|
181
|
-
// Capture absolute Windows paths (with drive letter) and relative paths.
|
|
182
|
-
// The old pattern started at a word boundary, so "E:\project\src\a.ts"
|
|
183
|
-
// only matched "project\src\a.ts" — resolve() then glued that onto
|
|
184
|
-
// baseDir producing a bogus path and a false "unknown file" warning
|
|
185
|
-
// even for files that actually exist on disk.
|
|
186
|
-
const pattern = /\b(?:[a-zA-Z]:[\\/])?[\w./\\-]+\.[a-z]{2,6}\b/gi;
|
|
187
|
-
const matches = text.match(pattern) || [];
|
|
188
|
-
return [...new Set(matches)].filter(looksLikeFilePath);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JS/TS global identifiers whose member access (`process.env`, `console.log`,
|
|
3
|
-
* `Math.max`) looks like a file path to `\b[\w./\\-]+\.[a-z]+\b`-style regexes
|
|
4
|
-
* but is code, not a file. Shared by the hallucination factual check and the
|
|
5
|
-
* execution auditor so both stop flagging member access as "missing files".
|
|
6
|
-
*/
|
|
7
|
-
const JS_GLOBALS = new Set([
|
|
8
|
-
"process",
|
|
9
|
-
"console",
|
|
10
|
-
"math",
|
|
11
|
-
"json",
|
|
12
|
-
"global",
|
|
13
|
-
"globalthis",
|
|
14
|
-
"window",
|
|
15
|
-
"document",
|
|
16
|
-
"buffer",
|
|
17
|
-
"module",
|
|
18
|
-
"require",
|
|
19
|
-
"exports",
|
|
20
|
-
"url",
|
|
21
|
-
"promise",
|
|
22
|
-
"array",
|
|
23
|
-
"object",
|
|
24
|
-
"string",
|
|
25
|
-
"number",
|
|
26
|
-
"boolean",
|
|
27
|
-
"symbol",
|
|
28
|
-
"date",
|
|
29
|
-
"regexp",
|
|
30
|
-
"error",
|
|
31
|
-
"map",
|
|
32
|
-
"set",
|
|
33
|
-
"weakmap",
|
|
34
|
-
"weakset",
|
|
35
|
-
"proxy",
|
|
36
|
-
"reflect",
|
|
37
|
-
"intl",
|
|
38
|
-
"crypto",
|
|
39
|
-
"performance",
|
|
40
|
-
"fetch",
|
|
41
|
-
"navigator",
|
|
42
|
-
"location",
|
|
43
|
-
"settimeout",
|
|
44
|
-
"setinterval",
|
|
45
|
-
"cleartimeout",
|
|
46
|
-
"clearinterval",
|
|
47
|
-
"queuemicrotask",
|
|
48
|
-
"structuredclone",
|
|
49
|
-
"textencoder",
|
|
50
|
-
"textdecoder",
|
|
51
|
-
"atomics",
|
|
52
|
-
"sharedarraybuffer",
|
|
53
|
-
"dataview",
|
|
54
|
-
"arraybuffer",
|
|
55
|
-
"bigint",
|
|
56
|
-
"infinity",
|
|
57
|
-
"nan",
|
|
58
|
-
"undefined",
|
|
59
|
-
"bun",
|
|
60
|
-
"deno",
|
|
61
|
-
"node",
|
|
62
|
-
]);
|
|
63
|
-
/**
|
|
64
|
-
* True when `candidate` starts with a known JS/TS global followed by a dot
|
|
65
|
-
* (`process.env`, `console.log`, `process.env.NODE` partial matches from
|
|
66
|
-
* `\b[\w./\\-]+\.[a-z]+`-style regexes) — member access, not a file path.
|
|
67
|
-
*/
|
|
68
|
-
export function isJsMemberAccess(candidate) {
|
|
69
|
-
const lower = candidate.toLowerCase();
|
|
70
|
-
const m = lower.match(/^([\w-]+)\./);
|
|
71
|
-
return m !== null && JS_GLOBALS.has(m[1]);
|
|
72
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { t } from "../../i18n/index";
|
|
2
|
-
const JUDGE_TIMEOUT_MS = 15000;
|
|
3
|
-
const MAX_DECISIONS_SHOWN = 6;
|
|
4
|
-
const MAX_RESPONSE_CHARS = 2000;
|
|
5
|
-
/**
|
|
6
|
-
* LLM-as-judge consistency check. Asks a model whether the agent's latest
|
|
7
|
-
* response contradicts any of its earlier decisions — replacing the fragile
|
|
8
|
-
* word-matching heuristic that only caught exact substring reversals.
|
|
9
|
-
*
|
|
10
|
-
* Fast path: when no decisions are tracked, returns pass without any LLM call.
|
|
11
|
-
* Any judge failure (timeout, provider error, unparseable verdict) degrades to
|
|
12
|
-
* pass so the agent loop is never blocked by the judge.
|
|
13
|
-
*/
|
|
14
|
-
export class LLMJudge {
|
|
15
|
-
provider;
|
|
16
|
-
constructor(provider) {
|
|
17
|
-
this.provider = provider;
|
|
18
|
-
}
|
|
19
|
-
async validate(response, consistency) {
|
|
20
|
-
const decisions = consistency.getDecisions();
|
|
21
|
-
if (decisions.length === 0) {
|
|
22
|
-
return { status: "pass" };
|
|
23
|
-
}
|
|
24
|
-
const shown = decisions.slice(-MAX_DECISIONS_SHOWN);
|
|
25
|
-
const decisionLines = shown
|
|
26
|
-
.map((d, i) => `${i + 1}. [${d.location || "agent"}] "${d.decision}"`)
|
|
27
|
-
.join("\n");
|
|
28
|
-
const system = `You are a consistency checker for an AI coding agent. The agent previously made these decisions:
|
|
29
|
-
|
|
30
|
-
${decisionLines}
|
|
31
|
-
|
|
32
|
-
Decide whether the agent's NEW response contradicts any of these decisions. A contradiction means reversing or abandoning a previously stated approach (e.g. switching to a different framework, changing a chosen strategy, or undoing a decision that was explicitly made).
|
|
33
|
-
|
|
34
|
-
Reply with ONLY valid JSON, no other text:
|
|
35
|
-
- {"contradicts": false}
|
|
36
|
-
- {"contradicts": true, "reason": "short explanation"}`;
|
|
37
|
-
const user = `Agent's new response:\n\n${response.slice(0, MAX_RESPONSE_CHARS)}`;
|
|
38
|
-
try {
|
|
39
|
-
const verdictText = await this.askJudge([
|
|
40
|
-
{ role: "system", content: system },
|
|
41
|
-
{ role: "user", content: user },
|
|
42
|
-
]);
|
|
43
|
-
const verdict = this.parseVerdict(verdictText);
|
|
44
|
-
if (verdict.contradicts) {
|
|
45
|
-
const reason = verdict.reason?.trim()
|
|
46
|
-
? ` — ${verdict.reason.trim()}`
|
|
47
|
-
: "";
|
|
48
|
-
return {
|
|
49
|
-
status: "warn",
|
|
50
|
-
reason: t("hall.contradiction_llm", { reason }),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return { status: "pass" };
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
return { status: "pass" };
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async askJudge(messages) {
|
|
60
|
-
let text = "";
|
|
61
|
-
let timer;
|
|
62
|
-
const consume = (async () => {
|
|
63
|
-
for await (const chunk of this.provider.chat(messages, [])) {
|
|
64
|
-
if (chunk.type === "text" && chunk.content) {
|
|
65
|
-
text += chunk.content;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return text;
|
|
69
|
-
})();
|
|
70
|
-
const timeout = new Promise((_, reject) => {
|
|
71
|
-
timer = setTimeout(() => reject(new Error("LLM judge timed out")), JUDGE_TIMEOUT_MS);
|
|
72
|
-
});
|
|
73
|
-
try {
|
|
74
|
-
return await Promise.race([consume, timeout]);
|
|
75
|
-
}
|
|
76
|
-
finally {
|
|
77
|
-
if (timer)
|
|
78
|
-
clearTimeout(timer);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
parseVerdict(text) {
|
|
82
|
-
const block = text.match(/\{[\s\S]*\}/);
|
|
83
|
-
if (block) {
|
|
84
|
-
try {
|
|
85
|
-
const obj = JSON.parse(block[0]);
|
|
86
|
-
if (typeof obj.contradicts === "boolean") {
|
|
87
|
-
return {
|
|
88
|
-
contradicts: obj.contradicts,
|
|
89
|
-
reason: typeof obj.reason === "string" ? obj.reason : undefined,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
// fall through to lenient parsing
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
const lower = text.toLowerCase();
|
|
98
|
-
if (lower.includes('"contradicts": true') || /^yes\b/.test(lower.trim())) {
|
|
99
|
-
return { contradicts: true, reason: text.slice(0, 200) };
|
|
100
|
-
}
|
|
101
|
-
return { contradicts: false };
|
|
102
|
-
}
|
|
103
|
-
}
|
package/dist/modules/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync, rmSync } from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
export class IndexCache {
|
|
4
|
-
cachePath;
|
|
5
|
-
cache = null;
|
|
6
|
-
constructor(cacheDir) {
|
|
7
|
-
this.cachePath = join(cacheDir, 'index-cache.json');
|
|
8
|
-
}
|
|
9
|
-
load() {
|
|
10
|
-
if (this.cache)
|
|
11
|
-
return this.cache;
|
|
12
|
-
if (!existsSync(this.cachePath))
|
|
13
|
-
return null;
|
|
14
|
-
try {
|
|
15
|
-
this.cache = JSON.parse(readFileSync(this.cachePath, 'utf-8'));
|
|
16
|
-
return this.cache;
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
save(result) {
|
|
23
|
-
this.cache = result;
|
|
24
|
-
const dir = join(this.cachePath, '..');
|
|
25
|
-
if (!existsSync(dir))
|
|
26
|
-
mkdirSync(dir, { recursive: true });
|
|
27
|
-
writeFileSync(this.cachePath, JSON.stringify(result), 'utf-8');
|
|
28
|
-
}
|
|
29
|
-
invalidate() {
|
|
30
|
-
this.cache = null;
|
|
31
|
-
if (existsSync(this.cachePath)) {
|
|
32
|
-
try {
|
|
33
|
-
rmSync(this.cachePath);
|
|
34
|
-
}
|
|
35
|
-
catch { /* ignore */ }
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|