micro-models-agent 0.58.1 → 0.59.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/CHANGELOG.md +13 -0
- package/dist/i18n/en.json +718 -679
- package/dist/i18n/ru.json +718 -679
- package/dist/main.js +744 -391
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -2318,6 +2318,9 @@ var init_defaults = __esm(() => {
|
|
|
2318
2318
|
responseReserve: 0.15,
|
|
2319
2319
|
compactionThreshold: 0.75
|
|
2320
2320
|
},
|
|
2321
|
+
instructions: {
|
|
2322
|
+
summarize: true
|
|
2323
|
+
},
|
|
2321
2324
|
modelLoad: {
|
|
2322
2325
|
autoLoad: false,
|
|
2323
2326
|
flashAttention: true,
|
|
@@ -2692,7 +2695,7 @@ Fix the error and re-edit the file (a clean write clears the failure), or mark t
|
|
|
2692
2695
|
"lsp.check_unsupported": "No LSP server configured for: {path}",
|
|
2693
2696
|
"lsp.check_clean": "No errors or warnings detected ({count} file(s) checked).",
|
|
2694
2697
|
"lsp.checked_files": "Checked {count} file(s):",
|
|
2695
|
-
"lsp.startup_header": "[Existing project errors (checked at session start) — fix these
|
|
2698
|
+
"lsp.startup_header": "[Existing project errors (baseline, checked at session start) — informational. Do NOT fix them unless the current request is about these errors; otherwise ignore them and work only on what the user asked.]:",
|
|
2696
2699
|
"cli.description": "Micro Models Agent — AI coding agent for small models",
|
|
2697
2700
|
"cli.init": "Run interactive setup wizard",
|
|
2698
2701
|
"cli.config_saved": "Configuration saved to ~/.mma/config.json",
|
|
@@ -2912,6 +2915,8 @@ Excluded blocks: {count}`,
|
|
|
2912
2915
|
"repl.agents_label": "Instructions:",
|
|
2913
2916
|
"repl.not_found": "not found",
|
|
2914
2917
|
"repl.disabled": "disabled (--no-agents-md)",
|
|
2918
|
+
"repl.context_probe_small": 'Context probe: model "{model}" is loaded with {actual} tokens, configured {configured} — overflow risk',
|
|
2919
|
+
"repl.context_probe_big": 'Context probe: model "{model}" supports {actual} tokens — consider "mma context {actual}"',
|
|
2915
2920
|
"repl.show": "show",
|
|
2916
2921
|
"repl.hide": "hide",
|
|
2917
2922
|
"repl.resume_hint": "Use /resume <id> or /resume <name> to switch between sessions",
|
|
@@ -3459,7 +3464,7 @@ var init_ru = __esm(() => {
|
|
|
3459
3464
|
"lsp.check_unsupported": "Для файла не настроен LSP-сервер: {path}",
|
|
3460
3465
|
"lsp.check_clean": "Ошибок и предупреждений не обнаружено (проверено файлов: {count}).",
|
|
3461
3466
|
"lsp.checked_files": "Проверено файлов: {count}:",
|
|
3462
|
-
"lsp.startup_header": "[Существующие ошибки проекта (проверено при старте сессии) —
|
|
3467
|
+
"lsp.startup_header": "[Существующие ошибки проекта (базовый уровень, проверено при старте сессии) — справочно. Не исправляйте их, если текущий запрос не про эти ошибки; в противном случае игнорируйте их и выполняйте только то, о чём попросил пользователь.]:",
|
|
3463
3468
|
"cli.description": "Micro Models Agent — ИИ-агент для кодинга на малых моделях",
|
|
3464
3469
|
"cli.init": "Запустить мастер настройки",
|
|
3465
3470
|
"cli.config_saved": "Конфигурация сохранена в ~/.mma/config.json",
|
|
@@ -3675,6 +3680,8 @@ var init_ru = __esm(() => {
|
|
|
3675
3680
|
"repl.agents_label": "Инструкции:",
|
|
3676
3681
|
"repl.not_found": "не найден",
|
|
3677
3682
|
"repl.disabled": "отключено (--no-agents-md)",
|
|
3683
|
+
"repl.context_probe_small": 'Context-проб: модель "{model}" загружена с контекстом {actual} токенов, настроено {configured} — риск переполнения',
|
|
3684
|
+
"repl.context_probe_big": 'Context-проб: модель "{model}" поддерживает {actual} токенов — рассмотрите "mma context {actual}"',
|
|
3678
3685
|
"repl.show": "показ",
|
|
3679
3686
|
"repl.hide": "скрыть",
|
|
3680
3687
|
"repl.resume_hint": "Используйте /resume <id> или /resume <имя> для переключения между сессиями",
|
|
@@ -4466,6 +4473,7 @@ var init_domains = __esm(() => {
|
|
|
4466
4473
|
"model",
|
|
4467
4474
|
"contextWindow",
|
|
4468
4475
|
"contextBudget",
|
|
4476
|
+
"instructions",
|
|
4469
4477
|
"modelLoad",
|
|
4470
4478
|
"maxToolIterations",
|
|
4471
4479
|
"stuckThreshold",
|
|
@@ -6718,6 +6726,29 @@ var init_factory = __esm(() => {
|
|
|
6718
6726
|
});
|
|
6719
6727
|
|
|
6720
6728
|
// src/llm/model-loader.ts
|
|
6729
|
+
async function getLoadedContextLength(baseUrl, model, timeoutMs = 3000) {
|
|
6730
|
+
const base = baseUrl.replace(/\/$/, "").replace(/\/v1\/?$/, "");
|
|
6731
|
+
try {
|
|
6732
|
+
const response = await fetch(`${base}/api/v1/models`, {
|
|
6733
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
6734
|
+
});
|
|
6735
|
+
if (!response.ok)
|
|
6736
|
+
return null;
|
|
6737
|
+
const data = await response.json();
|
|
6738
|
+
const models = data.models || [];
|
|
6739
|
+
const found = models.find((m) => m.key === model || m.name === model || model.includes(m.key));
|
|
6740
|
+
if (!found)
|
|
6741
|
+
return null;
|
|
6742
|
+
const loadedInstance = (found.loaded_instances ?? [])[0];
|
|
6743
|
+
const actual = loadedInstance?.config?.context_length ?? found.max_context_length;
|
|
6744
|
+
if (typeof actual !== "number" || actual <= 0)
|
|
6745
|
+
return null;
|
|
6746
|
+
return { model: found.key ?? found.name ?? model, actual };
|
|
6747
|
+
} catch {
|
|
6748
|
+
return null;
|
|
6749
|
+
}
|
|
6750
|
+
}
|
|
6751
|
+
|
|
6721
6752
|
class ModelLoader {
|
|
6722
6753
|
baseUrl;
|
|
6723
6754
|
logger;
|
|
@@ -9906,6 +9937,7 @@ class PromptBuilder {
|
|
|
9906
9937
|
let usedTokens = 0;
|
|
9907
9938
|
const included = [];
|
|
9908
9939
|
const excluded = [];
|
|
9940
|
+
const excludedBlocks = [];
|
|
9909
9941
|
const blocks = [];
|
|
9910
9942
|
for (const block of essential) {
|
|
9911
9943
|
included.push(block.content);
|
|
@@ -9926,6 +9958,7 @@ class PromptBuilder {
|
|
|
9926
9958
|
usedTokens += tokens;
|
|
9927
9959
|
} else {
|
|
9928
9960
|
excluded.push(block.content);
|
|
9961
|
+
excludedBlocks.push(block);
|
|
9929
9962
|
}
|
|
9930
9963
|
blocks.push({
|
|
9931
9964
|
label: blockLabel(block.content),
|
|
@@ -9940,6 +9973,7 @@ class PromptBuilder {
|
|
|
9940
9973
|
|
|
9941
9974
|
`),
|
|
9942
9975
|
excluded,
|
|
9976
|
+
excludedBlocks,
|
|
9943
9977
|
blocks
|
|
9944
9978
|
};
|
|
9945
9979
|
}
|
|
@@ -14478,7 +14512,212 @@ var init_audit_gate = __esm(() => {
|
|
|
14478
14512
|
init_i18n();
|
|
14479
14513
|
});
|
|
14480
14514
|
|
|
14515
|
+
// src/core/prompt-overflow.ts
|
|
14516
|
+
import { createHash } from "crypto";
|
|
14517
|
+
import { existsSync as existsSync27, mkdirSync as mkdirSync13, readFileSync as readFileSync14, writeFileSync as writeFileSync10 } from "fs";
|
|
14518
|
+
import { join as join17 } from "path";
|
|
14519
|
+
function dryRunOverflow(allBlocks, systemBudget) {
|
|
14520
|
+
const builder = new PromptBuilder(systemBudget);
|
|
14521
|
+
builder.addBlocks(allBlocks);
|
|
14522
|
+
const result = builder.build();
|
|
14523
|
+
const includedTokens = result.blocks.filter((b) => b.included).reduce((sum, b) => sum + b.tokens, 0);
|
|
14524
|
+
const overflow = result.excludedBlocks.filter((b) => Boolean(b.kind));
|
|
14525
|
+
return { includedTokens, overflow };
|
|
14526
|
+
}
|
|
14527
|
+
function cacheKey(kind, content, maxTokens) {
|
|
14528
|
+
return createHash("sha256").update(`${kind}|${maxTokens}|${content}`).digest("hex").slice(0, 24);
|
|
14529
|
+
}
|
|
14530
|
+
function readCache(cacheDir, key) {
|
|
14531
|
+
try {
|
|
14532
|
+
const path = join17(cacheDir, `${key}.md`);
|
|
14533
|
+
if (!existsSync27(path))
|
|
14534
|
+
return null;
|
|
14535
|
+
const raw = readFileSync14(path, "utf-8").trim();
|
|
14536
|
+
if (!raw)
|
|
14537
|
+
return null;
|
|
14538
|
+
try {
|
|
14539
|
+
const parsed = JSON.parse(raw);
|
|
14540
|
+
if ((parsed.mode === "summary" || parsed.mode === "truncate") && typeof parsed.text === "string" && parsed.text) {
|
|
14541
|
+
return parsed;
|
|
14542
|
+
}
|
|
14543
|
+
} catch {
|
|
14544
|
+
return { mode: "summary", text: raw };
|
|
14545
|
+
}
|
|
14546
|
+
return null;
|
|
14547
|
+
} catch {}
|
|
14548
|
+
return null;
|
|
14549
|
+
}
|
|
14550
|
+
function writeCache(cacheDir, key, entry) {
|
|
14551
|
+
try {
|
|
14552
|
+
mkdirSync13(cacheDir, { recursive: true });
|
|
14553
|
+
writeFileSync10(join17(cacheDir, `${key}.md`), JSON.stringify(entry), "utf-8");
|
|
14554
|
+
} catch {}
|
|
14555
|
+
}
|
|
14556
|
+
async function collectText(provider, prompt, maxTokens) {
|
|
14557
|
+
let text = "";
|
|
14558
|
+
for await (const chunk of provider.chat([{ role: "user", content: prompt }], undefined, undefined, {
|
|
14559
|
+
maxTokens: maxTokens * 2,
|
|
14560
|
+
reasoningEffort: "none"
|
|
14561
|
+
})) {
|
|
14562
|
+
if (chunk.type === "text" && chunk.content)
|
|
14563
|
+
text += chunk.content;
|
|
14564
|
+
}
|
|
14565
|
+
return text.trim();
|
|
14566
|
+
}
|
|
14567
|
+
function truncateToTokens(content, maxTokens) {
|
|
14568
|
+
const maxChars = Math.max(200, maxTokens * CHARS_PER_TOKEN);
|
|
14569
|
+
if (content.length <= maxChars)
|
|
14570
|
+
return content;
|
|
14571
|
+
let cut = content.slice(0, maxChars);
|
|
14572
|
+
const lastBreak = cut.lastIndexOf(`
|
|
14573
|
+
`);
|
|
14574
|
+
if (lastBreak > maxChars * 0.5)
|
|
14575
|
+
cut = cut.slice(0, lastBreak);
|
|
14576
|
+
return `${cut.trimEnd()}
|
|
14577
|
+
|
|
14578
|
+
[...truncated — read the full file for details...]`;
|
|
14579
|
+
}
|
|
14580
|
+
function blockLabel2(content) {
|
|
14581
|
+
const first = content.split(`
|
|
14582
|
+
`)[0].trim();
|
|
14583
|
+
return first.length > 60 ? `${first.slice(0, 57)}...` : first;
|
|
14584
|
+
}
|
|
14585
|
+
async function resolvePromptOverflow(opts) {
|
|
14586
|
+
const { overflow, includedTokens, systemBudget, provider, cacheDir, logger } = opts;
|
|
14587
|
+
const sorted = [...overflow].sort((a, b) => KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind));
|
|
14588
|
+
const replacements = [];
|
|
14589
|
+
const warnings = [];
|
|
14590
|
+
let used = includedTokens;
|
|
14591
|
+
let unresolved = [];
|
|
14592
|
+
for (const block of sorted) {
|
|
14593
|
+
const kind = block.kind;
|
|
14594
|
+
const maxTokens = systemBudget - used - HINT_BLOCK_TOKENS;
|
|
14595
|
+
if (maxTokens < 100) {
|
|
14596
|
+
unresolved.push(kind);
|
|
14597
|
+
continue;
|
|
14598
|
+
}
|
|
14599
|
+
let mode = "summary";
|
|
14600
|
+
let text = "";
|
|
14601
|
+
const key = cacheKey(kind, block.content, maxTokens);
|
|
14602
|
+
const cached = readCache(cacheDir, key);
|
|
14603
|
+
if (cached) {
|
|
14604
|
+
text = cached.text;
|
|
14605
|
+
mode = cached.mode;
|
|
14606
|
+
logger?.debug(`Prompt overflow: cache hit for ${kind} (${key}, ${mode})`);
|
|
14607
|
+
} else if (provider) {
|
|
14608
|
+
const targetChars = Math.floor(maxTokens * (CHARS_PER_TOKEN - 1));
|
|
14609
|
+
try {
|
|
14610
|
+
const prompt = [
|
|
14611
|
+
`Summarize the following ${KIND_LABEL[kind]} document.`,
|
|
14612
|
+
`Target length: at most ${targetChars} characters (~${maxTokens} tokens). Be strict about it.`,
|
|
14613
|
+
`Preserve concrete facts: file paths, commands, rules, naming conventions, workflow steps.`,
|
|
14614
|
+
`Keep the structure (headings / bullet lists). Output ONLY the summary text.`,
|
|
14615
|
+
``,
|
|
14616
|
+
`--- DOCUMENT START ---`,
|
|
14617
|
+
block.content,
|
|
14618
|
+
`--- DOCUMENT END ---`
|
|
14619
|
+
].join(`
|
|
14620
|
+
`);
|
|
14621
|
+
text = await collectText(provider, prompt, maxTokens);
|
|
14622
|
+
let retries = 0;
|
|
14623
|
+
while (text && estimateTokens(text) > maxTokens && retries < 1) {
|
|
14624
|
+
retries++;
|
|
14625
|
+
logger?.debug(`Prompt overflow: ${kind} summary overshot (${estimateTokens(text)} > ${maxTokens} tok), compressing (retry ${retries})`);
|
|
14626
|
+
text = await collectText(provider, [
|
|
14627
|
+
`Compress the following text to at most ${targetChars} characters.`,
|
|
14628
|
+
`Keep the structure (headings / bullet lists) and all concrete facts: file paths, commands, rules.`,
|
|
14629
|
+
`Output ONLY the compressed text.`,
|
|
14630
|
+
``,
|
|
14631
|
+
`--- TEXT START ---`,
|
|
14632
|
+
text,
|
|
14633
|
+
`--- TEXT END ---`
|
|
14634
|
+
].join(`
|
|
14635
|
+
`), maxTokens);
|
|
14636
|
+
}
|
|
14637
|
+
} catch (err) {
|
|
14638
|
+
logger?.warn(`Prompt overflow: summarization failed for ${kind}: ${err?.message ?? err}`);
|
|
14639
|
+
text = "";
|
|
14640
|
+
}
|
|
14641
|
+
}
|
|
14642
|
+
if (!text) {
|
|
14643
|
+
mode = "truncate";
|
|
14644
|
+
text = truncateToTokens(block.content, maxTokens);
|
|
14645
|
+
}
|
|
14646
|
+
if (estimateTokens(text) > maxTokens) {
|
|
14647
|
+
if (mode === "summary") {
|
|
14648
|
+
mode = "truncate";
|
|
14649
|
+
}
|
|
14650
|
+
text = truncateToTokens(text, maxTokens);
|
|
14651
|
+
}
|
|
14652
|
+
const resolvedTokens = estimateTokens(text);
|
|
14653
|
+
used += resolvedTokens;
|
|
14654
|
+
writeCache(cacheDir, key, { mode, text });
|
|
14655
|
+
replacements.push({
|
|
14656
|
+
content: text,
|
|
14657
|
+
priority: "high",
|
|
14658
|
+
essential: false,
|
|
14659
|
+
estimatedTokens: resolvedTokens,
|
|
14660
|
+
kind
|
|
14661
|
+
});
|
|
14662
|
+
warnings.push({
|
|
14663
|
+
kind,
|
|
14664
|
+
label: blockLabel2(block.content),
|
|
14665
|
+
originalTokens: block.estimatedTokens,
|
|
14666
|
+
resolvedTokens,
|
|
14667
|
+
mode
|
|
14668
|
+
});
|
|
14669
|
+
}
|
|
14670
|
+
const hintBlock = replacements.length > 0 ? {
|
|
14671
|
+
content: [
|
|
14672
|
+
`[Instructions note] Some project blocks exceeded the system-prompt budget and were compressed:`,
|
|
14673
|
+
...warnings.map((w) => `- ${KIND_LABEL[w.kind]}: ${w.originalTokens} tokens → ${w.resolvedTokens} tokens (${w.mode})`),
|
|
14674
|
+
...unresolved.length > 0 ? unresolved.map((k) => `- ${KIND_LABEL[k]}: did not fit at all — read it yourself if needed`) : [],
|
|
14675
|
+
...warnings.filter((w) => KIND_SOURCE_FILE[w.kind]).map((w) => `Read the full ${KIND_SOURCE_FILE[w.kind]} with read_file if details are missing.`)
|
|
14676
|
+
].join(`
|
|
14677
|
+
`),
|
|
14678
|
+
priority: "high",
|
|
14679
|
+
essential: true,
|
|
14680
|
+
estimatedTokens: HINT_BLOCK_TOKENS
|
|
14681
|
+
} : null;
|
|
14682
|
+
return { replacements, hintBlock, warnings };
|
|
14683
|
+
}
|
|
14684
|
+
function resolveContextWindowSource(config) {
|
|
14685
|
+
const entries = config.provider.entries ?? [];
|
|
14686
|
+
const activeLabel = config.provider.active;
|
|
14687
|
+
const activeEntry = entries.find((e) => e.label && e.label === activeLabel) ?? (entries.length === 1 ? entries[0] : undefined);
|
|
14688
|
+
if (activeEntry?.contextWindow) {
|
|
14689
|
+
return { source: "entry", label: activeEntry.label, value: activeEntry.contextWindow };
|
|
14690
|
+
}
|
|
14691
|
+
return { source: "global", value: config.contextWindow };
|
|
14692
|
+
}
|
|
14693
|
+
function contextWindowHint(config, configDir, recommended) {
|
|
14694
|
+
const src = resolveContextWindowSource(config);
|
|
14695
|
+
if (src.source === "global") {
|
|
14696
|
+
return `run "mma context ${recommended}"`;
|
|
14697
|
+
}
|
|
14698
|
+
return `edit "${join17(configDir, "config", "provider.json")}" → provider.entries[label="${src.label}"].contextWindow = ${recommended}`;
|
|
14699
|
+
}
|
|
14700
|
+
function recommendContextSize(neededSystemTokens) {
|
|
14701
|
+
const sizes = [8192, 16384, 32768, 65536, 131072, 262144];
|
|
14702
|
+
return sizes.find((s) => Math.floor(s * 0.1) >= neededSystemTokens) ?? sizes[sizes.length - 1];
|
|
14703
|
+
}
|
|
14704
|
+
var HINT_BLOCK_TOKENS = 60, CHARS_PER_TOKEN = 4, KIND_ORDER, KIND_LABEL, KIND_SOURCE_FILE;
|
|
14705
|
+
var init_prompt_overflow = __esm(() => {
|
|
14706
|
+
init_prompt_builder();
|
|
14707
|
+
init_token_counter();
|
|
14708
|
+
KIND_ORDER = ["instructions", "project-map"];
|
|
14709
|
+
KIND_LABEL = {
|
|
14710
|
+
instructions: "project instructions (AGENTS.md)",
|
|
14711
|
+
"project-map": "project map"
|
|
14712
|
+
};
|
|
14713
|
+
KIND_SOURCE_FILE = {
|
|
14714
|
+
instructions: "AGENTS.md",
|
|
14715
|
+
"project-map": ""
|
|
14716
|
+
};
|
|
14717
|
+
});
|
|
14718
|
+
|
|
14481
14719
|
// src/core/agent.ts
|
|
14720
|
+
import { join as join18 } from "path";
|
|
14482
14721
|
function mutationTargetKey(name, rawArgs) {
|
|
14483
14722
|
let a = null;
|
|
14484
14723
|
if (typeof rawArgs === "string") {
|
|
@@ -14516,6 +14755,9 @@ class Agent {
|
|
|
14516
14755
|
probePassed;
|
|
14517
14756
|
reasoningState;
|
|
14518
14757
|
_currentIteration = 0;
|
|
14758
|
+
promptOverrides = new Map;
|
|
14759
|
+
overflowHintBlock = null;
|
|
14760
|
+
overflowResolved = false;
|
|
14519
14761
|
constructor(deps) {
|
|
14520
14762
|
this.deps = deps;
|
|
14521
14763
|
this.costTracker = new CostTracker(deps.config.model, deps.config.pricing);
|
|
@@ -14561,10 +14803,11 @@ class Agent {
|
|
|
14561
14803
|
buildSystemPrompt() {
|
|
14562
14804
|
const systemBudget = Math.floor(this.deps.config.contextWindow * this.deps.config.contextBudget.systemPrompt);
|
|
14563
14805
|
const builder = new PromptBuilder(systemBudget);
|
|
14564
|
-
|
|
14806
|
+
const applyOverrides = (blocks) => blocks.map((b) => b.kind && this.promptOverrides.has(b.kind) ? this.promptOverrides.get(b.kind) : b);
|
|
14807
|
+
builder.addBlocks(applyOverrides(this.deps.promptBlocks));
|
|
14565
14808
|
const dynamic = this.deps.getDynamicPromptBlocks?.() ?? [];
|
|
14566
14809
|
if (dynamic.length > 0) {
|
|
14567
|
-
builder.addBlocks(dynamic);
|
|
14810
|
+
builder.addBlocks(applyOverrides(dynamic));
|
|
14568
14811
|
}
|
|
14569
14812
|
const pluginBlocks = (this.deps.pluginManager.runOnBuildPrompt?.() ?? []).flatMap((content) => content && content.trim() !== "" ? [
|
|
14570
14813
|
{
|
|
@@ -14577,10 +14820,14 @@ class Agent {
|
|
|
14577
14820
|
if (pluginBlocks.length > 0) {
|
|
14578
14821
|
builder.addBlocks(pluginBlocks);
|
|
14579
14822
|
}
|
|
14823
|
+
if (this.overflowHintBlock) {
|
|
14824
|
+
builder.addBlock(this.overflowHintBlock);
|
|
14825
|
+
}
|
|
14580
14826
|
const result = builder.build();
|
|
14581
14827
|
return {
|
|
14582
14828
|
prompt: result.prompt,
|
|
14583
14829
|
excluded: result.excluded,
|
|
14830
|
+
excludedBlocks: result.excludedBlocks,
|
|
14584
14831
|
blocks: result.blocks
|
|
14585
14832
|
};
|
|
14586
14833
|
}
|
|
@@ -14613,6 +14860,32 @@ class Agent {
|
|
|
14613
14860
|
const tokenCount = this.deps.llmProvider.countTokens(prompt);
|
|
14614
14861
|
return { text: prompt, tokenCount, excluded };
|
|
14615
14862
|
}
|
|
14863
|
+
async resolvePromptOverflowOnce() {
|
|
14864
|
+
const cfg = this.deps.config;
|
|
14865
|
+
const dry = this.buildSystemPrompt();
|
|
14866
|
+
const overflow = dry.excludedBlocks.filter((b) => Boolean(b.kind));
|
|
14867
|
+
if (overflow.length === 0)
|
|
14868
|
+
return;
|
|
14869
|
+
const systemBudget = Math.floor(cfg.contextWindow * cfg.contextBudget.systemPrompt);
|
|
14870
|
+
const res = await resolvePromptOverflow({
|
|
14871
|
+
overflow,
|
|
14872
|
+
includedTokens: dry.blocks.filter((b) => b.included).reduce((s, b) => s + b.tokens, 0),
|
|
14873
|
+
systemBudget,
|
|
14874
|
+
provider: cfg.instructions?.summarize === false ? null : this.deps.llmProvider,
|
|
14875
|
+
cacheDir: join18(this.deps.baseDir, ".mma", "cache", "prompt-summaries"),
|
|
14876
|
+
logger: this.deps.logger
|
|
14877
|
+
});
|
|
14878
|
+
for (const r of res.replacements) {
|
|
14879
|
+
if (r.kind)
|
|
14880
|
+
this.promptOverrides.set(r.kind, r);
|
|
14881
|
+
}
|
|
14882
|
+
this.overflowHintBlock = res.hintBlock;
|
|
14883
|
+
const recommended = recommendContextSize(dry.blocks.filter((b) => b.included).reduce((s, b) => s + b.tokens, 0) + overflow.reduce((s, b) => s + b.estimatedTokens, 0) + HINT_BLOCK_TOKENS);
|
|
14884
|
+
const hint = this.deps.configDir ? contextWindowHint(cfg, this.deps.configDir, recommended) : `increase contextWindow (e.g. to ${recommended})`;
|
|
14885
|
+
for (const w of res.warnings) {
|
|
14886
|
+
this.deps.logger.warn(`Prompt overflow: "${w.label}" (${w.originalTokens} tok) exceeded the system-prompt budget (${systemBudget} tok) — ${w.mode === "summary" ? "summarized" : "truncated"} to ${w.resolvedTokens} tok. To fit fully, ${hint}.`);
|
|
14887
|
+
}
|
|
14888
|
+
}
|
|
14616
14889
|
refreshSystemPrompt() {
|
|
14617
14890
|
const { prompt } = this.buildSystemPrompt();
|
|
14618
14891
|
const current = this.deps.contextManager.getActiveHistory().find((m) => m.role === "system");
|
|
@@ -14655,6 +14928,14 @@ class Agent {
|
|
|
14655
14928
|
if (lazy.length > 0) {
|
|
14656
14929
|
this.deps.promptBlocks.push(...lazy);
|
|
14657
14930
|
}
|
|
14931
|
+
if (!this.overflowResolved) {
|
|
14932
|
+
this.overflowResolved = true;
|
|
14933
|
+
try {
|
|
14934
|
+
await this.resolvePromptOverflowOnce();
|
|
14935
|
+
} catch (err) {
|
|
14936
|
+
this.deps.logger.warn(`Prompt overflow resolution failed: ${err?.message ?? err} — oversized blocks will be dropped.`);
|
|
14937
|
+
}
|
|
14938
|
+
}
|
|
14658
14939
|
if (this.deps.reasoningProbe) {
|
|
14659
14940
|
this.probePassed = await this.deps.reasoningProbe();
|
|
14660
14941
|
}
|
|
@@ -15184,6 +15465,7 @@ var init_agent = __esm(() => {
|
|
|
15184
15465
|
init_tool_batch();
|
|
15185
15466
|
init_hallucination_gate();
|
|
15186
15467
|
init_audit_gate();
|
|
15468
|
+
init_prompt_overflow();
|
|
15187
15469
|
init_tool_output();
|
|
15188
15470
|
});
|
|
15189
15471
|
|
|
@@ -15761,8 +16043,8 @@ var init_confidence = __esm(() => {
|
|
|
15761
16043
|
});
|
|
15762
16044
|
|
|
15763
16045
|
// src/modules/hallucination/factual.ts
|
|
15764
|
-
import { existsSync as
|
|
15765
|
-
import { resolve as resolve14, isAbsolute as isAbsolute4, join as
|
|
16046
|
+
import { existsSync as existsSync28, readdirSync as readdirSync8 } from "fs";
|
|
16047
|
+
import { resolve as resolve14, isAbsolute as isAbsolute4, join as join19 } from "path";
|
|
15766
16048
|
|
|
15767
16049
|
class FactualCheck {
|
|
15768
16050
|
baseDir;
|
|
@@ -15805,13 +16087,13 @@ class FactualCheck {
|
|
|
15805
16087
|
}
|
|
15806
16088
|
pathExists(fp) {
|
|
15807
16089
|
if (isAbsolute4(fp))
|
|
15808
|
-
return
|
|
16090
|
+
return existsSync28(fp);
|
|
15809
16091
|
if (this.knownFiles.has(fp))
|
|
15810
16092
|
return true;
|
|
15811
16093
|
for (const cand of this.dotfileVariants(fp)) {
|
|
15812
16094
|
if (this.knownFiles.has(cand))
|
|
15813
16095
|
return true;
|
|
15814
|
-
if (
|
|
16096
|
+
if (existsSync28(resolve14(this.baseDir, cand)))
|
|
15815
16097
|
return true;
|
|
15816
16098
|
}
|
|
15817
16099
|
if (!fp.includes("/") && !fp.includes("\\")) {
|
|
@@ -15839,7 +16121,7 @@ class FactualCheck {
|
|
|
15839
16121
|
}
|
|
15840
16122
|
bareNameExists(name) {
|
|
15841
16123
|
for (const cand of this.dotfileVariants(name)) {
|
|
15842
|
-
if (
|
|
16124
|
+
if (existsSync28(resolve14(this.baseDir, cand)))
|
|
15843
16125
|
return true;
|
|
15844
16126
|
if (this.indexHas(cand))
|
|
15845
16127
|
return true;
|
|
@@ -15885,7 +16167,7 @@ class FactualCheck {
|
|
|
15885
16167
|
for (const entry of entries) {
|
|
15886
16168
|
if (count >= FactualCheck.MAX_INDEXED_FILES)
|
|
15887
16169
|
break;
|
|
15888
|
-
const full =
|
|
16170
|
+
const full = join19(dir, entry.name);
|
|
15889
16171
|
if (entry.isDirectory()) {
|
|
15890
16172
|
if (!IGNORED_DIRS2.has(entry.name)) {
|
|
15891
16173
|
count = this.scanDir(full, index, count);
|
|
@@ -16067,8 +16349,8 @@ var init_detector = __esm(() => {
|
|
|
16067
16349
|
});
|
|
16068
16350
|
|
|
16069
16351
|
// src/modules/lsp/command.ts
|
|
16070
|
-
import { delimiter, join as
|
|
16071
|
-
import { existsSync as
|
|
16352
|
+
import { delimiter, join as join20 } from "path";
|
|
16353
|
+
import { existsSync as existsSync29 } from "fs";
|
|
16072
16354
|
import { platform as platform4 } from "os";
|
|
16073
16355
|
function resolveSpawnCommand(command, platformName = platform4(), pathEnv = process.env.PATH ?? "") {
|
|
16074
16356
|
if (platformName !== "win32")
|
|
@@ -16079,8 +16361,8 @@ function resolveSpawnCommand(command, platformName = platform4(), pathEnv = proc
|
|
|
16079
16361
|
const dirs = pathEnv.split(delimiter).filter(Boolean);
|
|
16080
16362
|
for (const dir of dirs) {
|
|
16081
16363
|
for (const ext of WIN_EXTS) {
|
|
16082
|
-
const candidate =
|
|
16083
|
-
if (
|
|
16364
|
+
const candidate = join20(dir, `${command}${ext}`);
|
|
16365
|
+
if (existsSync29(candidate))
|
|
16084
16366
|
return `${command}${ext}`;
|
|
16085
16367
|
}
|
|
16086
16368
|
}
|
|
@@ -16724,7 +17006,7 @@ var init_chunk_query = __esm(() => {
|
|
|
16724
17006
|
});
|
|
16725
17007
|
|
|
16726
17008
|
// src/tools/chunk-query.ts
|
|
16727
|
-
import { readFileSync as
|
|
17009
|
+
import { readFileSync as readFileSync15 } from "node:fs";
|
|
16728
17010
|
import { resolve as resolve15 } from "node:path";
|
|
16729
17011
|
var chunkQueryTool;
|
|
16730
17012
|
var init_chunk_query2 = __esm(() => {
|
|
@@ -16797,7 +17079,7 @@ var init_chunk_query2 = __esm(() => {
|
|
|
16797
17079
|
return { success: false, output: `[SCOPE] ${check.reason || "Path not allowed"}` };
|
|
16798
17080
|
}
|
|
16799
17081
|
try {
|
|
16800
|
-
content =
|
|
17082
|
+
content = readFileSync15(resolvedInput, "utf8");
|
|
16801
17083
|
} catch (e) {
|
|
16802
17084
|
return { success: false, output: `Cannot read ${inputPath}: ${e.message}` };
|
|
16803
17085
|
}
|
|
@@ -17249,7 +17531,7 @@ var init_web_browse = __esm(() => {
|
|
|
17249
17531
|
});
|
|
17250
17532
|
|
|
17251
17533
|
// src/tools/download-file.ts
|
|
17252
|
-
import { writeFileSync as
|
|
17534
|
+
import { writeFileSync as writeFileSync11, mkdirSync as mkdirSync14 } from "fs";
|
|
17253
17535
|
import { dirname as dirname11 } from "path";
|
|
17254
17536
|
var MAX_DOWNLOAD_BYTES, downloadFileTool;
|
|
17255
17537
|
var init_download_file = __esm(() => {
|
|
@@ -17338,8 +17620,8 @@ var init_download_file = __esm(() => {
|
|
|
17338
17620
|
output: t("tool.download_too_large", { max: String(maxBytes) })
|
|
17339
17621
|
};
|
|
17340
17622
|
}
|
|
17341
|
-
|
|
17342
|
-
|
|
17623
|
+
mkdirSync14(dirname11(resolved), { recursive: true });
|
|
17624
|
+
writeFileSync11(resolved, buffer);
|
|
17343
17625
|
const contentType = response.headers.get("content-type")?.split(";")[0]?.trim() || "unknown";
|
|
17344
17626
|
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), true, `Status: ${response.status}`);
|
|
17345
17627
|
logFileWrite(ctx.sessionId, resolved, true, `Downloaded ${buffer.byteLength} bytes`);
|
|
@@ -18205,7 +18487,7 @@ ${JSON.stringify(result, null, 2)}`
|
|
|
18205
18487
|
|
|
18206
18488
|
// src/tools/search-history.ts
|
|
18207
18489
|
import * as fs from "fs";
|
|
18208
|
-
import { join as
|
|
18490
|
+
import { join as join21 } from "path";
|
|
18209
18491
|
import { homedir as homedir6 } from "os";
|
|
18210
18492
|
function searchFile(filePath, query, maxResults, results) {
|
|
18211
18493
|
if (!fs.existsSync(filePath))
|
|
@@ -18250,7 +18532,7 @@ var init_search_history = __esm(() => {
|
|
|
18250
18532
|
const query = String(args.query || "").toLowerCase();
|
|
18251
18533
|
const maxResults = Number(args.maxResults) || 5;
|
|
18252
18534
|
const sessionId = args.sessionId ? String(args.sessionId) : null;
|
|
18253
|
-
const sessionDir =
|
|
18535
|
+
const sessionDir = join21(homedir6(), ".mma", "sessions");
|
|
18254
18536
|
const results = [];
|
|
18255
18537
|
try {
|
|
18256
18538
|
if (!fs.existsSync(sessionDir)) {
|
|
@@ -18265,7 +18547,7 @@ var init_search_history = __esm(() => {
|
|
|
18265
18547
|
continue;
|
|
18266
18548
|
if (sessionId && entry.name !== sessionId)
|
|
18267
18549
|
continue;
|
|
18268
|
-
const historyFile =
|
|
18550
|
+
const historyFile = join21(sessionDir, entry.name, "history.jsonl");
|
|
18269
18551
|
searchFile(historyFile, query, maxResults, results);
|
|
18270
18552
|
if (results.length >= maxResults)
|
|
18271
18553
|
break;
|
|
@@ -18292,8 +18574,8 @@ var init_search_history = __esm(() => {
|
|
|
18292
18574
|
});
|
|
18293
18575
|
|
|
18294
18576
|
// src/modules/memory/search.ts
|
|
18295
|
-
import { readFileSync as
|
|
18296
|
-
import { join as
|
|
18577
|
+
import { readFileSync as readFileSync17, existsSync as existsSync31 } from "fs";
|
|
18578
|
+
import { join as join22 } from "path";
|
|
18297
18579
|
|
|
18298
18580
|
class MemorySearch {
|
|
18299
18581
|
memoryDir;
|
|
@@ -18304,10 +18586,10 @@ class MemorySearch {
|
|
|
18304
18586
|
const results = [];
|
|
18305
18587
|
const lowerQuery = query.toLowerCase();
|
|
18306
18588
|
for (const name of MEMORY_FILES) {
|
|
18307
|
-
const path =
|
|
18308
|
-
if (!
|
|
18589
|
+
const path = join22(this.memoryDir, `${name}.md`);
|
|
18590
|
+
if (!existsSync31(path))
|
|
18309
18591
|
continue;
|
|
18310
|
-
const content =
|
|
18592
|
+
const content = readFileSync17(path, "utf-8");
|
|
18311
18593
|
const lines = content.split(`
|
|
18312
18594
|
`);
|
|
18313
18595
|
for (const line of lines) {
|
|
@@ -18316,10 +18598,10 @@ class MemorySearch {
|
|
|
18316
18598
|
}
|
|
18317
18599
|
}
|
|
18318
18600
|
}
|
|
18319
|
-
const prefsPath =
|
|
18320
|
-
if (
|
|
18601
|
+
const prefsPath = join22(this.memoryDir, "preferences.json");
|
|
18602
|
+
if (existsSync31(prefsPath)) {
|
|
18321
18603
|
try {
|
|
18322
|
-
const prefs = JSON.parse(
|
|
18604
|
+
const prefs = JSON.parse(readFileSync17(prefsPath, "utf-8"));
|
|
18323
18605
|
for (const [key, value] of Object.entries(prefs)) {
|
|
18324
18606
|
const searchStr = `${key}=${value}`;
|
|
18325
18607
|
if (searchStr.toLowerCase().includes(lowerQuery)) {
|
|
@@ -18337,8 +18619,8 @@ var init_search = __esm(() => {
|
|
|
18337
18619
|
});
|
|
18338
18620
|
|
|
18339
18621
|
// src/modules/memory/store.ts
|
|
18340
|
-
import { readFileSync as
|
|
18341
|
-
import { join as
|
|
18622
|
+
import { readFileSync as readFileSync18, writeFileSync as writeFileSync12, appendFileSync as appendFileSync5, existsSync as existsSync32, mkdirSync as mkdirSync15 } from "fs";
|
|
18623
|
+
import { join as join23 } from "path";
|
|
18342
18624
|
|
|
18343
18625
|
class MemoryStore {
|
|
18344
18626
|
memoryDir;
|
|
@@ -18346,27 +18628,27 @@ class MemoryStore {
|
|
|
18346
18628
|
this.memoryDir = memoryDir;
|
|
18347
18629
|
this.ensureDir();
|
|
18348
18630
|
for (const name of MEMORY_FILES2) {
|
|
18349
|
-
const path =
|
|
18350
|
-
if (!
|
|
18351
|
-
|
|
18631
|
+
const path = join23(this.memoryDir, `${name}.md`);
|
|
18632
|
+
if (!existsSync32(path)) {
|
|
18633
|
+
writeFileSync12(path, `# ${name.charAt(0).toUpperCase() + name.slice(1)}
|
|
18352
18634
|
|
|
18353
18635
|
`, "utf-8");
|
|
18354
18636
|
}
|
|
18355
18637
|
}
|
|
18356
18638
|
}
|
|
18357
18639
|
ensureDir() {
|
|
18358
|
-
if (!
|
|
18359
|
-
|
|
18640
|
+
if (!existsSync32(this.memoryDir)) {
|
|
18641
|
+
mkdirSync15(this.memoryDir, { recursive: true });
|
|
18360
18642
|
}
|
|
18361
18643
|
}
|
|
18362
18644
|
read(name) {
|
|
18363
|
-
const path =
|
|
18364
|
-
if (!
|
|
18645
|
+
const path = join23(this.memoryDir, `${name}.md`);
|
|
18646
|
+
if (!existsSync32(path))
|
|
18365
18647
|
return "";
|
|
18366
|
-
return
|
|
18648
|
+
return readFileSync18(path, "utf-8");
|
|
18367
18649
|
}
|
|
18368
18650
|
append(name, entry) {
|
|
18369
|
-
const path =
|
|
18651
|
+
const path = join23(this.memoryDir, `${name}.md`);
|
|
18370
18652
|
const timestamp = new Date().toISOString().replace("T", " ").slice(0, 19);
|
|
18371
18653
|
const formatted = `- **${timestamp}** — ${entry}
|
|
18372
18654
|
`;
|
|
@@ -18377,14 +18659,14 @@ class MemoryStore {
|
|
|
18377
18659
|
return searchModule.query(query);
|
|
18378
18660
|
}
|
|
18379
18661
|
prefsPath() {
|
|
18380
|
-
return
|
|
18662
|
+
return join23(this.memoryDir, "preferences.json");
|
|
18381
18663
|
}
|
|
18382
18664
|
getPreferences() {
|
|
18383
18665
|
const path = this.prefsPath();
|
|
18384
|
-
if (!
|
|
18666
|
+
if (!existsSync32(path))
|
|
18385
18667
|
return {};
|
|
18386
18668
|
try {
|
|
18387
|
-
return JSON.parse(
|
|
18669
|
+
return JSON.parse(readFileSync18(path, "utf-8"));
|
|
18388
18670
|
} catch {
|
|
18389
18671
|
return {};
|
|
18390
18672
|
}
|
|
@@ -18392,14 +18674,14 @@ class MemoryStore {
|
|
|
18392
18674
|
setPreference(key, value) {
|
|
18393
18675
|
const prefs = this.getPreferences();
|
|
18394
18676
|
prefs[key] = value;
|
|
18395
|
-
|
|
18677
|
+
writeFileSync12(this.prefsPath(), JSON.stringify(prefs, null, 2), "utf-8");
|
|
18396
18678
|
}
|
|
18397
18679
|
deletePreference(key) {
|
|
18398
18680
|
const prefs = this.getPreferences();
|
|
18399
18681
|
if (!(key in prefs))
|
|
18400
18682
|
return false;
|
|
18401
18683
|
delete prefs[key];
|
|
18402
|
-
|
|
18684
|
+
writeFileSync12(this.prefsPath(), JSON.stringify(prefs, null, 2), "utf-8");
|
|
18403
18685
|
return true;
|
|
18404
18686
|
}
|
|
18405
18687
|
appendRule(category, pattern, cause, solution) {
|
|
@@ -18417,7 +18699,7 @@ var init_store2 = __esm(() => {
|
|
|
18417
18699
|
|
|
18418
18700
|
// src/tools/remember.ts
|
|
18419
18701
|
import { homedir as homedir7 } from "os";
|
|
18420
|
-
import { join as
|
|
18702
|
+
import { join as join24 } from "path";
|
|
18421
18703
|
var CATEGORIES, rememberTool;
|
|
18422
18704
|
var init_remember = __esm(() => {
|
|
18423
18705
|
init_i18n();
|
|
@@ -18456,7 +18738,7 @@ var init_remember = __esm(() => {
|
|
|
18456
18738
|
if (!CATEGORIES.includes(category)) {
|
|
18457
18739
|
return { success: false, output: t("tool.invalid_params") };
|
|
18458
18740
|
}
|
|
18459
|
-
const memoryDir =
|
|
18741
|
+
const memoryDir = join24(homedir7(), ".mma", "memory");
|
|
18460
18742
|
const store = new MemoryStore(memoryDir);
|
|
18461
18743
|
try {
|
|
18462
18744
|
if (category === "preferences") {
|
|
@@ -18489,7 +18771,7 @@ var init_remember = __esm(() => {
|
|
|
18489
18771
|
|
|
18490
18772
|
// src/tools/recall.ts
|
|
18491
18773
|
import { homedir as homedir8 } from "os";
|
|
18492
|
-
import { join as
|
|
18774
|
+
import { join as join25 } from "path";
|
|
18493
18775
|
function formatAll(store) {
|
|
18494
18776
|
const parts = [];
|
|
18495
18777
|
const prefs = store.getPreferences();
|
|
@@ -18573,7 +18855,7 @@ var init_recall = __esm(() => {
|
|
|
18573
18855
|
handler: async (_ctx, args) => {
|
|
18574
18856
|
const query = args.query ? String(args.query) : "";
|
|
18575
18857
|
const category = args.category ? String(args.category) : "";
|
|
18576
|
-
const memoryDir =
|
|
18858
|
+
const memoryDir = join25(homedir8(), ".mma", "memory");
|
|
18577
18859
|
const store = new MemoryStore(memoryDir);
|
|
18578
18860
|
try {
|
|
18579
18861
|
if (!query && !category) {
|
|
@@ -18611,9 +18893,9 @@ var init_recall = __esm(() => {
|
|
|
18611
18893
|
});
|
|
18612
18894
|
|
|
18613
18895
|
// src/modules/browser/bridge-path.ts
|
|
18614
|
-
import { existsSync as
|
|
18896
|
+
import { existsSync as existsSync33 } from "fs";
|
|
18615
18897
|
function pickExistingPath(candidates, fallback = candidates[0]) {
|
|
18616
|
-
return candidates.find((p) =>
|
|
18898
|
+
return candidates.find((p) => existsSync33(p)) ?? fallback;
|
|
18617
18899
|
}
|
|
18618
18900
|
var init_bridge_path = () => {};
|
|
18619
18901
|
|
|
@@ -18624,13 +18906,13 @@ __export(exports_bridge_client, {
|
|
|
18624
18906
|
});
|
|
18625
18907
|
import { spawn as spawn6 } from "child_process";
|
|
18626
18908
|
import { createInterface } from "readline";
|
|
18627
|
-
import { dirname as dirname12, join as
|
|
18909
|
+
import { dirname as dirname12, join as join26 } from "path";
|
|
18628
18910
|
import { fileURLToPath } from "url";
|
|
18629
18911
|
function bridgeScriptPath() {
|
|
18630
18912
|
const dir = dirname12(fileURLToPath(import.meta.url));
|
|
18631
18913
|
const candidates = [
|
|
18632
|
-
|
|
18633
|
-
|
|
18914
|
+
join26(dir, "bridge-server.mjs"),
|
|
18915
|
+
join26(dir, "modules", "browser", "bridge-server.mjs")
|
|
18634
18916
|
];
|
|
18635
18917
|
return pickExistingPath(candidates);
|
|
18636
18918
|
}
|
|
@@ -19184,15 +19466,15 @@ function buildTextExtractionScript() {
|
|
|
19184
19466
|
|
|
19185
19467
|
// src/modules/browser/cookie-store.ts
|
|
19186
19468
|
import { readFile, writeFile, mkdir } from "fs/promises";
|
|
19187
|
-
import { join as
|
|
19469
|
+
import { join as join27 } from "path";
|
|
19188
19470
|
|
|
19189
19471
|
class CookieStore {
|
|
19190
19472
|
filePath;
|
|
19191
19473
|
constructor(cookieDir) {
|
|
19192
|
-
this.filePath =
|
|
19474
|
+
this.filePath = join27(cookieDir, "cookies.json");
|
|
19193
19475
|
}
|
|
19194
19476
|
async save(cookies) {
|
|
19195
|
-
await mkdir(
|
|
19477
|
+
await mkdir(join27(this.filePath, ".."), { recursive: true });
|
|
19196
19478
|
await writeFile(this.filePath, JSON.stringify(cookies, null, 2), "utf-8");
|
|
19197
19479
|
}
|
|
19198
19480
|
async load() {
|
|
@@ -19550,10 +19832,10 @@ var init_session = __esm(() => {
|
|
|
19550
19832
|
});
|
|
19551
19833
|
|
|
19552
19834
|
// src/tools/browser.ts
|
|
19553
|
-
import { join as
|
|
19835
|
+
import { join as join28 } from "path";
|
|
19554
19836
|
function getSession(ctx) {
|
|
19555
19837
|
if (!session) {
|
|
19556
|
-
const cookieDir =
|
|
19838
|
+
const cookieDir = join28(ctx.baseDir, ".mma", "browser");
|
|
19557
19839
|
session = new BrowserSession({
|
|
19558
19840
|
...DEFAULT_BROWSER_CONFIG,
|
|
19559
19841
|
headless: ctx.config.browser?.headless ?? true,
|
|
@@ -19679,7 +19961,7 @@ __export(exports_image_utils, {
|
|
|
19679
19961
|
detectMime: () => detectMime,
|
|
19680
19962
|
bufferToDataUrl: () => bufferToDataUrl
|
|
19681
19963
|
});
|
|
19682
|
-
import { readFileSync as
|
|
19964
|
+
import { readFileSync as readFileSync19 } from "fs";
|
|
19683
19965
|
import { extname as extname4 } from "path";
|
|
19684
19966
|
function detectMime(filePath) {
|
|
19685
19967
|
const ext = extname4(filePath).toLowerCase();
|
|
@@ -19700,11 +19982,11 @@ async function readClipboardImage() {
|
|
|
19700
19982
|
async function readClipboardFallback() {
|
|
19701
19983
|
const { platform: platform6 } = await import("os");
|
|
19702
19984
|
const { execSync } = await import("child_process");
|
|
19703
|
-
const { readFileSync:
|
|
19704
|
-
const { join:
|
|
19985
|
+
const { readFileSync: readFileSync20, unlinkSync: unlinkSync5 } = await import("fs");
|
|
19986
|
+
const { join: join29 } = await import("path");
|
|
19705
19987
|
if (platform6() !== "linux")
|
|
19706
19988
|
return null;
|
|
19707
|
-
const tmpPath =
|
|
19989
|
+
const tmpPath = join29(process.env.TEMP || process.env.TMP || "/tmp", `mma-clip-${Date.now()}.png`);
|
|
19708
19990
|
const commands = [
|
|
19709
19991
|
`wl-paste --type image/png > "${tmpPath}" 2>/dev/null`,
|
|
19710
19992
|
`xclip -selection clipboard -t image/png -o > "${tmpPath}" 2>/dev/null`
|
|
@@ -19712,7 +19994,7 @@ async function readClipboardFallback() {
|
|
|
19712
19994
|
for (const cmd of commands) {
|
|
19713
19995
|
try {
|
|
19714
19996
|
execSync(cmd, { timeout: 5000 });
|
|
19715
|
-
const buf =
|
|
19997
|
+
const buf = readFileSync20(tmpPath);
|
|
19716
19998
|
unlinkSync5(tmpPath);
|
|
19717
19999
|
if (buf.length > 0)
|
|
19718
20000
|
return buf;
|
|
@@ -19724,7 +20006,7 @@ async function readClipboardFallback() {
|
|
|
19724
20006
|
return null;
|
|
19725
20007
|
}
|
|
19726
20008
|
async function loadFileAsDataUrl(filePath) {
|
|
19727
|
-
const buf =
|
|
20009
|
+
const buf = readFileSync19(filePath);
|
|
19728
20010
|
if (typeof Bun !== "undefined" && typeof Bun.Image !== "undefined") {
|
|
19729
20011
|
try {
|
|
19730
20012
|
const img = new Bun.Image(buf);
|
|
@@ -19784,7 +20066,7 @@ var init_image_utils = __esm(() => {
|
|
|
19784
20066
|
});
|
|
19785
20067
|
|
|
19786
20068
|
// src/tools/attach-image.ts
|
|
19787
|
-
import { existsSync as
|
|
20069
|
+
import { existsSync as existsSync34 } from "fs";
|
|
19788
20070
|
import { resolve as resolve16 } from "path";
|
|
19789
20071
|
var attachImageTool;
|
|
19790
20072
|
var init_attach_image = __esm(() => {
|
|
@@ -19836,7 +20118,7 @@ var init_attach_image = __esm(() => {
|
|
|
19836
20118
|
dataUrl = result.dataUrl;
|
|
19837
20119
|
} else {
|
|
19838
20120
|
const absPath = resolve16(ctx.baseDir, source);
|
|
19839
|
-
if (!
|
|
20121
|
+
if (!existsSync34(absPath)) {
|
|
19840
20122
|
return {
|
|
19841
20123
|
success: false,
|
|
19842
20124
|
output: t("image.not_found", { path: source })
|
|
@@ -20093,16 +20375,16 @@ class ModuleRegistry {
|
|
|
20093
20375
|
}
|
|
20094
20376
|
|
|
20095
20377
|
// src/modules/plugins/loader.ts
|
|
20096
|
-
import { readdirSync as readdirSync10, existsSync as
|
|
20097
|
-
import { join as
|
|
20378
|
+
import { readdirSync as readdirSync10, existsSync as existsSync35, statSync as statSync6 } from "fs";
|
|
20379
|
+
import { join as join29, basename as basename3 } from "path";
|
|
20098
20380
|
|
|
20099
20381
|
class PluginLoader {
|
|
20100
20382
|
loadFromDir(dirPath, pluginManager, logger2, options) {
|
|
20101
|
-
if (!
|
|
20383
|
+
if (!existsSync35(dirPath))
|
|
20102
20384
|
return;
|
|
20103
20385
|
const entries = readdirSync10(dirPath).sort();
|
|
20104
20386
|
for (const entry of entries) {
|
|
20105
|
-
const fullPath =
|
|
20387
|
+
const fullPath = join29(dirPath, entry);
|
|
20106
20388
|
const stat = statSync6(fullPath);
|
|
20107
20389
|
if (stat.isFile()) {
|
|
20108
20390
|
if (!entry.endsWith(".ts") && !entry.endsWith(".js"))
|
|
@@ -20118,8 +20400,8 @@ class PluginLoader {
|
|
|
20118
20400
|
}
|
|
20119
20401
|
findEntryFile(dir) {
|
|
20120
20402
|
for (const name of FOLDER_ENTRY_NAMES) {
|
|
20121
|
-
const candidate =
|
|
20122
|
-
if (
|
|
20403
|
+
const candidate = join29(dir, name);
|
|
20404
|
+
if (existsSync35(candidate))
|
|
20123
20405
|
return candidate;
|
|
20124
20406
|
}
|
|
20125
20407
|
return null;
|
|
@@ -20324,8 +20606,8 @@ var init_auto_fixer = __esm(() => {
|
|
|
20324
20606
|
|
|
20325
20607
|
// src/modules/plugins/builtin/lint-on-write.ts
|
|
20326
20608
|
import { spawn as spawn7, execSync } from "child_process";
|
|
20327
|
-
import { existsSync as
|
|
20328
|
-
import { resolve as resolve17, extname as extname6, join as
|
|
20609
|
+
import { existsSync as existsSync36, readFileSync as readFileSync20, writeFileSync as writeFileSync13 } from "fs";
|
|
20610
|
+
import { resolve as resolve17, extname as extname6, join as join30 } from "path";
|
|
20329
20611
|
import { platform as platform6 } from "os";
|
|
20330
20612
|
function lintCacheKey(baseDir, lintScript) {
|
|
20331
20613
|
return `${baseDir}::${lintScript}`;
|
|
@@ -20401,7 +20683,7 @@ class LintOnWritePlugin {
|
|
|
20401
20683
|
if (!path)
|
|
20402
20684
|
return;
|
|
20403
20685
|
const fullPath = resolve17(ctx.baseDir, path);
|
|
20404
|
-
if (!
|
|
20686
|
+
if (!existsSync36(fullPath))
|
|
20405
20687
|
return;
|
|
20406
20688
|
const signal = ctx.signal;
|
|
20407
20689
|
if (signal?.aborted)
|
|
@@ -20425,7 +20707,7 @@ class LintOnWritePlugin {
|
|
|
20425
20707
|
if (ext === ".ts" || ext === ".tsx" || ext === ".cts" || ext === ".mts") {
|
|
20426
20708
|
let content = "";
|
|
20427
20709
|
try {
|
|
20428
|
-
content =
|
|
20710
|
+
content = readFileSync20(filePath, "utf-8");
|
|
20429
20711
|
} catch {
|
|
20430
20712
|
return null;
|
|
20431
20713
|
}
|
|
@@ -20467,11 +20749,11 @@ class LintOnWritePlugin {
|
|
|
20467
20749
|
async runProjectLint(ctx, result, signal) {
|
|
20468
20750
|
let lintScript;
|
|
20469
20751
|
try {
|
|
20470
|
-
const packageJsonPath =
|
|
20471
|
-
if (!
|
|
20752
|
+
const packageJsonPath = join30(ctx.baseDir, "package.json");
|
|
20753
|
+
if (!existsSync36(packageJsonPath)) {
|
|
20472
20754
|
return;
|
|
20473
20755
|
}
|
|
20474
|
-
const packageJson = JSON.parse(
|
|
20756
|
+
const packageJson = JSON.parse(readFileSync20(packageJsonPath, "utf-8"));
|
|
20475
20757
|
lintScript = packageJson.scripts?.lint;
|
|
20476
20758
|
if (!lintScript) {
|
|
20477
20759
|
return;
|
|
@@ -20504,8 +20786,8 @@ ${stdout}`;
|
|
|
20504
20786
|
}
|
|
20505
20787
|
async runProjectTypeCheck(filePath, baseDir, result, signal) {
|
|
20506
20788
|
const projectRoot = findProjectRoot(filePath, baseDir, ["tsconfig.json", "package.json"]);
|
|
20507
|
-
const tsconfigPath =
|
|
20508
|
-
if (!
|
|
20789
|
+
const tsconfigPath = join30(projectRoot, "tsconfig.json");
|
|
20790
|
+
if (!existsSync36(tsconfigPath)) {
|
|
20509
20791
|
return;
|
|
20510
20792
|
}
|
|
20511
20793
|
const now = Date.now();
|
|
@@ -20526,9 +20808,9 @@ ${stdout}`;
|
|
|
20526
20808
|
const output = stderr || stdout;
|
|
20527
20809
|
const errors = parseTscOutput(output);
|
|
20528
20810
|
if (errors.length > 0) {
|
|
20529
|
-
const fixResult = autoFixErrors(filePath,
|
|
20811
|
+
const fixResult = autoFixErrors(filePath, readFileSync20(filePath, "utf-8"), errors);
|
|
20530
20812
|
if (fixResult.fixed) {
|
|
20531
|
-
|
|
20813
|
+
writeFileSync13(filePath, fixResult.newContent, "utf-8");
|
|
20532
20814
|
result.output += `
|
|
20533
20815
|
|
|
20534
20816
|
[Auto-fixed]: ${fixResult.applied.join("; ")}`;
|
|
@@ -20791,11 +21073,11 @@ class PlanTracker {
|
|
|
20791
21073
|
var init_tracker = () => {};
|
|
20792
21074
|
|
|
20793
21075
|
// src/modules/execution/plan-store.ts
|
|
20794
|
-
import { readFileSync as
|
|
20795
|
-
import { join as
|
|
21076
|
+
import { readFileSync as readFileSync21, writeFileSync as writeFileSync14, renameSync as renameSync3, mkdirSync as mkdirSync16, existsSync as existsSync37, readdirSync as readdirSync11, rmSync } from "fs";
|
|
21077
|
+
import { join as join31 } from "path";
|
|
20796
21078
|
function readPlanFile(path, fallbackBaseDir) {
|
|
20797
21079
|
try {
|
|
20798
|
-
const raw =
|
|
21080
|
+
const raw = readFileSync21(path, "utf-8");
|
|
20799
21081
|
if (!raw.trim())
|
|
20800
21082
|
return null;
|
|
20801
21083
|
const parsed = JSON.parse(raw);
|
|
@@ -20815,14 +21097,14 @@ function readPlanFile(path, fallbackBaseDir) {
|
|
|
20815
21097
|
}
|
|
20816
21098
|
function writePlanFile(path, plan) {
|
|
20817
21099
|
const tmpPath = `${path}.tmp`;
|
|
20818
|
-
|
|
21100
|
+
writeFileSync14(tmpPath, JSON.stringify(plan, null, 2), "utf-8");
|
|
20819
21101
|
renameSync3(tmpPath, path);
|
|
20820
21102
|
}
|
|
20821
21103
|
function listDir(dir, baseDir) {
|
|
20822
|
-
if (!
|
|
21104
|
+
if (!existsSync37(dir))
|
|
20823
21105
|
return [];
|
|
20824
21106
|
const files = readdirSync11(dir).filter((f) => f.endsWith(".json"));
|
|
20825
|
-
return files.map((f) => readPlanFile(
|
|
21107
|
+
return files.map((f) => readPlanFile(join31(dir, f), baseDir)).filter((p) => p !== null);
|
|
20826
21108
|
}
|
|
20827
21109
|
function toMeta(plan, status) {
|
|
20828
21110
|
return {
|
|
@@ -20843,33 +21125,33 @@ class PlanStore {
|
|
|
20843
21125
|
archiveDir;
|
|
20844
21126
|
legacyPath;
|
|
20845
21127
|
constructor(baseDir) {
|
|
20846
|
-
const mmaDir =
|
|
20847
|
-
if (!
|
|
20848
|
-
|
|
21128
|
+
const mmaDir = join31(baseDir, ".mma");
|
|
21129
|
+
if (!existsSync37(mmaDir))
|
|
21130
|
+
mkdirSync16(mmaDir, { recursive: true });
|
|
20849
21131
|
this.baseDir = baseDir;
|
|
20850
|
-
this.plansDir =
|
|
20851
|
-
this.draftsDir =
|
|
20852
|
-
this.archiveDir =
|
|
20853
|
-
this.legacyPath =
|
|
21132
|
+
this.plansDir = join31(mmaDir, "plans");
|
|
21133
|
+
this.draftsDir = join31(this.plansDir, "drafts");
|
|
21134
|
+
this.archiveDir = join31(this.plansDir, "archive");
|
|
21135
|
+
this.legacyPath = join31(mmaDir, LEGACY_FILE);
|
|
20854
21136
|
for (const dir of [this.plansDir, this.draftsDir, this.archiveDir]) {
|
|
20855
|
-
if (!
|
|
20856
|
-
|
|
21137
|
+
if (!existsSync37(dir))
|
|
21138
|
+
mkdirSync16(dir, { recursive: true });
|
|
20857
21139
|
}
|
|
20858
21140
|
}
|
|
20859
21141
|
activePath() {
|
|
20860
|
-
return
|
|
21142
|
+
return join31(this.plansDir, "active.json");
|
|
20861
21143
|
}
|
|
20862
21144
|
saveActive(plan) {
|
|
20863
21145
|
writePlanFile(this.activePath(), plan);
|
|
20864
21146
|
}
|
|
20865
21147
|
loadActive() {
|
|
20866
21148
|
const activePath = this.activePath();
|
|
20867
|
-
if (
|
|
21149
|
+
if (existsSync37(activePath)) {
|
|
20868
21150
|
const plan = readPlanFile(activePath, this.baseDir);
|
|
20869
21151
|
if (plan)
|
|
20870
21152
|
return plan;
|
|
20871
21153
|
}
|
|
20872
|
-
if (
|
|
21154
|
+
if (existsSync37(this.legacyPath)) {
|
|
20873
21155
|
const legacy = readPlanFile(this.legacyPath, this.baseDir);
|
|
20874
21156
|
if (legacy) {
|
|
20875
21157
|
this.saveActive(legacy);
|
|
@@ -20888,26 +21170,26 @@ class PlanStore {
|
|
|
20888
21170
|
}
|
|
20889
21171
|
clearActive() {
|
|
20890
21172
|
const p = this.activePath();
|
|
20891
|
-
if (
|
|
21173
|
+
if (existsSync37(p))
|
|
20892
21174
|
rmSync(p, { force: true });
|
|
20893
21175
|
}
|
|
20894
21176
|
saveDraft(plan) {
|
|
20895
|
-
writePlanFile(
|
|
21177
|
+
writePlanFile(join31(this.draftsDir, `${plan.id}.json`), plan);
|
|
20896
21178
|
}
|
|
20897
21179
|
loadDraft(id) {
|
|
20898
|
-
const p =
|
|
20899
|
-
return
|
|
21180
|
+
const p = join31(this.draftsDir, `${id}.json`);
|
|
21181
|
+
return existsSync37(p) ? readPlanFile(p, this.baseDir) : null;
|
|
20900
21182
|
}
|
|
20901
21183
|
removeDraft(id) {
|
|
20902
|
-
const p =
|
|
20903
|
-
if (
|
|
21184
|
+
const p = join31(this.draftsDir, `${id}.json`);
|
|
21185
|
+
if (existsSync37(p))
|
|
20904
21186
|
rmSync(p, { force: true });
|
|
20905
21187
|
}
|
|
20906
21188
|
listDrafts() {
|
|
20907
21189
|
return listDir(this.draftsDir, this.baseDir);
|
|
20908
21190
|
}
|
|
20909
21191
|
archivePlan(plan) {
|
|
20910
|
-
writePlanFile(
|
|
21192
|
+
writePlanFile(join31(this.archiveDir, `${plan.id}.json`), plan);
|
|
20911
21193
|
this.removeDraft(plan.id);
|
|
20912
21194
|
const active = this.loadActive();
|
|
20913
21195
|
if (active && active.id === plan.id) {
|
|
@@ -20918,8 +21200,8 @@ class PlanStore {
|
|
|
20918
21200
|
return listDir(this.archiveDir, this.baseDir);
|
|
20919
21201
|
}
|
|
20920
21202
|
removeArchived(id) {
|
|
20921
|
-
const p =
|
|
20922
|
-
if (
|
|
21203
|
+
const p = join31(this.archiveDir, `${id}.json`);
|
|
21204
|
+
if (existsSync37(p))
|
|
20923
21205
|
rmSync(p, { force: true });
|
|
20924
21206
|
}
|
|
20925
21207
|
listAll() {
|
|
@@ -20951,13 +21233,13 @@ class PlanStore {
|
|
|
20951
21233
|
this.clearActive();
|
|
20952
21234
|
return "active";
|
|
20953
21235
|
}
|
|
20954
|
-
const draftPath =
|
|
20955
|
-
if (
|
|
21236
|
+
const draftPath = join31(this.draftsDir, `${id}.json`);
|
|
21237
|
+
if (existsSync37(draftPath)) {
|
|
20956
21238
|
rmSync(draftPath, { force: true });
|
|
20957
21239
|
return "draft";
|
|
20958
21240
|
}
|
|
20959
|
-
const archivedPath =
|
|
20960
|
-
if (
|
|
21241
|
+
const archivedPath = join31(this.archiveDir, `${id}.json`);
|
|
21242
|
+
if (existsSync37(archivedPath)) {
|
|
20961
21243
|
rmSync(archivedPath, { force: true });
|
|
20962
21244
|
return "archived";
|
|
20963
21245
|
}
|
|
@@ -22077,7 +22359,7 @@ var init_plan_tool = __esm(() => {
|
|
|
22077
22359
|
});
|
|
22078
22360
|
|
|
22079
22361
|
// src/modules/execution/module.ts
|
|
22080
|
-
import { existsSync as
|
|
22362
|
+
import { existsSync as existsSync38, readFileSync as readFileSync22 } from "fs";
|
|
22081
22363
|
import { resolve as resolve18 } from "path";
|
|
22082
22364
|
|
|
22083
22365
|
class ExecutionModule {
|
|
@@ -22436,7 +22718,7 @@ class ExecutionModule {
|
|
|
22436
22718
|
"poetry.lock",
|
|
22437
22719
|
"requirements.txt"
|
|
22438
22720
|
];
|
|
22439
|
-
const hasLockFile = lockFiles.some((f) =>
|
|
22721
|
+
const hasLockFile = lockFiles.some((f) => existsSync38(resolve18(this.baseDir, f)));
|
|
22440
22722
|
if (!hasLockFile) {
|
|
22441
22723
|
if (contextManager) {
|
|
22442
22724
|
const hints = this.state.depsGateHints.get(step.id) || 0;
|
|
@@ -22468,7 +22750,7 @@ class ExecutionModule {
|
|
|
22468
22750
|
if (!r)
|
|
22469
22751
|
continue;
|
|
22470
22752
|
try {
|
|
22471
|
-
const content =
|
|
22753
|
+
const content = readFileSync22(r, "utf-8");
|
|
22472
22754
|
if (content.trim().length < 10) {
|
|
22473
22755
|
emptyFiles.push(r);
|
|
22474
22756
|
}
|
|
@@ -22576,8 +22858,8 @@ var init_module = __esm(() => {
|
|
|
22576
22858
|
});
|
|
22577
22859
|
|
|
22578
22860
|
// src/modules/security/session-encryption.ts
|
|
22579
|
-
import { readFileSync as
|
|
22580
|
-
import { join as
|
|
22861
|
+
import { readFileSync as readFileSync23, writeFileSync as writeFileSync15, existsSync as existsSync39, readdirSync as readdirSync12, unlinkSync as unlinkSync5 } from "fs";
|
|
22862
|
+
import { join as join32 } from "path";
|
|
22581
22863
|
import { homedir as homedir9 } from "os";
|
|
22582
22864
|
|
|
22583
22865
|
class SessionFileEncryptor {
|
|
@@ -22586,7 +22868,7 @@ class SessionFileEncryptor {
|
|
|
22586
22868
|
constructor(config) {
|
|
22587
22869
|
this.config = { ...DEFAULT_SESSION_ENCRYPTION, ...config };
|
|
22588
22870
|
this.encryptor = new ConfigEncryptor({
|
|
22589
|
-
keyPath: config?.keyPath ||
|
|
22871
|
+
keyPath: config?.keyPath || join32(homedir9(), ".mma", ".session-encryption-key")
|
|
22590
22872
|
});
|
|
22591
22873
|
}
|
|
22592
22874
|
isEnabled() {
|
|
@@ -22638,23 +22920,23 @@ class SessionFileEncryptor {
|
|
|
22638
22920
|
});
|
|
22639
22921
|
}
|
|
22640
22922
|
readSessionFile(filePath) {
|
|
22641
|
-
const content =
|
|
22923
|
+
const content = readFileSync23(filePath, "utf8");
|
|
22642
22924
|
return this.decryptFileContent(content);
|
|
22643
22925
|
}
|
|
22644
22926
|
writeSessionFile(filePath, content) {
|
|
22645
22927
|
const encrypted = this.encryptFileContent(content);
|
|
22646
|
-
|
|
22928
|
+
writeFileSync15(filePath, encrypted, "utf8");
|
|
22647
22929
|
}
|
|
22648
22930
|
readSessionJSON(filePath) {
|
|
22649
|
-
const content =
|
|
22931
|
+
const content = readFileSync23(filePath, "utf8");
|
|
22650
22932
|
return this.decryptJSON(content);
|
|
22651
22933
|
}
|
|
22652
22934
|
writeSessionJSON(filePath, obj) {
|
|
22653
22935
|
const content = this.encryptJSON(obj);
|
|
22654
|
-
|
|
22936
|
+
writeFileSync15(filePath, content, "utf8");
|
|
22655
22937
|
}
|
|
22656
22938
|
readSessionJSONL(filePath) {
|
|
22657
|
-
const content =
|
|
22939
|
+
const content = readFileSync23(filePath, "utf8");
|
|
22658
22940
|
const lines = content.split(`
|
|
22659
22941
|
`).filter((line) => line.trim());
|
|
22660
22942
|
const decryptedLines = this.decryptJSONL(lines);
|
|
@@ -22668,7 +22950,7 @@ class SessionFileEncryptor {
|
|
|
22668
22950
|
}
|
|
22669
22951
|
appendToSessionJSONL(filePath, obj) {
|
|
22670
22952
|
const encryptedLine = this.encryptFileContent(JSON.stringify(obj));
|
|
22671
|
-
|
|
22953
|
+
writeFileSync15(filePath, encryptedLine + `
|
|
22672
22954
|
`, {
|
|
22673
22955
|
flag: "a",
|
|
22674
22956
|
encoding: "utf8"
|
|
@@ -22679,12 +22961,12 @@ class SessionFileEncryptor {
|
|
|
22679
22961
|
return;
|
|
22680
22962
|
const files = readdirSync12(sessionDir);
|
|
22681
22963
|
for (const file of files) {
|
|
22682
|
-
const filePath =
|
|
22683
|
-
if (
|
|
22964
|
+
const filePath = join32(sessionDir, file);
|
|
22965
|
+
if (existsSync39(filePath) && !file.endsWith(".enc")) {
|
|
22684
22966
|
try {
|
|
22685
|
-
const content =
|
|
22967
|
+
const content = readFileSync23(filePath, "utf8");
|
|
22686
22968
|
const encrypted = this.encryptFileContent(content);
|
|
22687
|
-
|
|
22969
|
+
writeFileSync15(filePath + ".enc", encrypted, "utf8");
|
|
22688
22970
|
unlinkSync5(filePath);
|
|
22689
22971
|
} catch {}
|
|
22690
22972
|
}
|
|
@@ -22696,12 +22978,12 @@ class SessionFileEncryptor {
|
|
|
22696
22978
|
const files = readdirSync12(sessionDir);
|
|
22697
22979
|
for (const file of files) {
|
|
22698
22980
|
if (file.endsWith(".enc")) {
|
|
22699
|
-
const encFilePath =
|
|
22981
|
+
const encFilePath = join32(sessionDir, file);
|
|
22700
22982
|
const decFilePath = encFilePath.slice(0, -4);
|
|
22701
22983
|
try {
|
|
22702
|
-
const content =
|
|
22984
|
+
const content = readFileSync23(encFilePath, "utf8");
|
|
22703
22985
|
const decrypted = this.decryptFileContent(content);
|
|
22704
|
-
|
|
22986
|
+
writeFileSync15(decFilePath, decrypted, "utf8");
|
|
22705
22987
|
unlinkSync5(encFilePath);
|
|
22706
22988
|
} catch {}
|
|
22707
22989
|
}
|
|
@@ -22721,15 +23003,15 @@ var init_session_encryption = __esm(() => {
|
|
|
22721
23003
|
|
|
22722
23004
|
// src/modules/session/store.ts
|
|
22723
23005
|
import {
|
|
22724
|
-
existsSync as
|
|
22725
|
-
mkdirSync as
|
|
23006
|
+
existsSync as existsSync40,
|
|
23007
|
+
mkdirSync as mkdirSync17,
|
|
22726
23008
|
readdirSync as readdirSync13,
|
|
22727
|
-
readFileSync as
|
|
23009
|
+
readFileSync as readFileSync24,
|
|
22728
23010
|
rmSync as rmSync2,
|
|
22729
|
-
writeFileSync as
|
|
23011
|
+
writeFileSync as writeFileSync16,
|
|
22730
23012
|
appendFileSync as appendFileSync6
|
|
22731
23013
|
} from "fs";
|
|
22732
|
-
import { join as
|
|
23014
|
+
import { join as join33 } from "path";
|
|
22733
23015
|
import { gzipSync } from "zlib";
|
|
22734
23016
|
|
|
22735
23017
|
class SessionStore {
|
|
@@ -22743,7 +23025,7 @@ class SessionStore {
|
|
|
22743
23025
|
}
|
|
22744
23026
|
}
|
|
22745
23027
|
getSessionDir(id) {
|
|
22746
|
-
return
|
|
23028
|
+
return join33(this.baseDir, id);
|
|
22747
23029
|
}
|
|
22748
23030
|
updateEncryption(config) {
|
|
22749
23031
|
if (config?.enabled) {
|
|
@@ -22756,32 +23038,32 @@ class SessionStore {
|
|
|
22756
23038
|
return this.encryptor?.isEnabled() ?? false;
|
|
22757
23039
|
}
|
|
22758
23040
|
init() {
|
|
22759
|
-
|
|
23041
|
+
mkdirSync17(this.baseDir, { recursive: true, mode: 448 });
|
|
22760
23042
|
}
|
|
22761
23043
|
sessionDir(id) {
|
|
22762
|
-
return
|
|
23044
|
+
return join33(this.baseDir, id);
|
|
22763
23045
|
}
|
|
22764
23046
|
metaPath(id) {
|
|
22765
|
-
return
|
|
23047
|
+
return join33(this.sessionDir(id), "meta.json");
|
|
22766
23048
|
}
|
|
22767
23049
|
historyPath(id) {
|
|
22768
|
-
return
|
|
23050
|
+
return join33(this.sessionDir(id), "history.jsonl");
|
|
22769
23051
|
}
|
|
22770
23052
|
sessionLogPath(id) {
|
|
22771
|
-
return
|
|
23053
|
+
return join33(this.sessionDir(id), "session.jsonl");
|
|
22772
23054
|
}
|
|
22773
23055
|
sessionExists(id) {
|
|
22774
|
-
return
|
|
23056
|
+
return existsSync40(this.metaPath(id));
|
|
22775
23057
|
}
|
|
22776
23058
|
saveMeta(id, meta) {
|
|
22777
23059
|
this._metaCache.set(id, meta);
|
|
22778
23060
|
const dir = this.sessionDir(id);
|
|
22779
|
-
|
|
23061
|
+
mkdirSync17(dir, { recursive: true, mode: 448 });
|
|
22780
23062
|
const content = JSON.stringify(meta, null, 2);
|
|
22781
23063
|
if (this.encryptor) {
|
|
22782
|
-
|
|
23064
|
+
writeFileSync16(this.metaPath(id), this.encryptor.encryptFileContent(content), { encoding: "utf-8", mode: 384 });
|
|
22783
23065
|
} else {
|
|
22784
|
-
|
|
23066
|
+
writeFileSync16(this.metaPath(id), content, { encoding: "utf-8", mode: 384 });
|
|
22785
23067
|
}
|
|
22786
23068
|
}
|
|
22787
23069
|
loadMeta(id) {
|
|
@@ -22789,10 +23071,10 @@ class SessionStore {
|
|
|
22789
23071
|
if (cached)
|
|
22790
23072
|
return cached;
|
|
22791
23073
|
const path = this.metaPath(id);
|
|
22792
|
-
if (!
|
|
23074
|
+
if (!existsSync40(path))
|
|
22793
23075
|
return null;
|
|
22794
23076
|
try {
|
|
22795
|
-
const raw =
|
|
23077
|
+
const raw = readFileSync24(path, "utf-8");
|
|
22796
23078
|
const content = this.encryptor ? this.encryptor.decryptFileContent(raw) : raw;
|
|
22797
23079
|
const meta = JSON.parse(content);
|
|
22798
23080
|
this._metaCache.set(id, meta);
|
|
@@ -22803,10 +23085,10 @@ class SessionStore {
|
|
|
22803
23085
|
}
|
|
22804
23086
|
readMetaFromDisk(id) {
|
|
22805
23087
|
const path = this.metaPath(id);
|
|
22806
|
-
if (!
|
|
23088
|
+
if (!existsSync40(path))
|
|
22807
23089
|
return null;
|
|
22808
23090
|
try {
|
|
22809
|
-
const raw =
|
|
23091
|
+
const raw = readFileSync24(path, "utf-8");
|
|
22810
23092
|
const content = this.encryptor ? this.encryptor.decryptFileContent(raw) : raw;
|
|
22811
23093
|
return JSON.parse(content);
|
|
22812
23094
|
} catch {
|
|
@@ -22815,7 +23097,7 @@ class SessionStore {
|
|
|
22815
23097
|
}
|
|
22816
23098
|
appendMessage(id, msg) {
|
|
22817
23099
|
const dir = this.sessionDir(id);
|
|
22818
|
-
|
|
23100
|
+
mkdirSync17(dir, { recursive: true, mode: 448 });
|
|
22819
23101
|
const line = JSON.stringify(msg);
|
|
22820
23102
|
if (this.encryptor?.isEnabled()) {
|
|
22821
23103
|
appendFileSync6(this.historyPath(id), this.encryptor.encryptFileContent(line) + `
|
|
@@ -22833,10 +23115,10 @@ class SessionStore {
|
|
|
22833
23115
|
}
|
|
22834
23116
|
loadHistory(id) {
|
|
22835
23117
|
const path = this.historyPath(id);
|
|
22836
|
-
if (!
|
|
23118
|
+
if (!existsSync40(path))
|
|
22837
23119
|
return [];
|
|
22838
23120
|
try {
|
|
22839
|
-
const raw =
|
|
23121
|
+
const raw = readFileSync24(path, "utf-8");
|
|
22840
23122
|
const lines = raw.split(`
|
|
22841
23123
|
`).filter(Boolean);
|
|
22842
23124
|
const parseLine = (line) => {
|
|
@@ -22862,7 +23144,7 @@ class SessionStore {
|
|
|
22862
23144
|
}
|
|
22863
23145
|
appendSessionLog(id, entry) {
|
|
22864
23146
|
const dir = this.sessionDir(id);
|
|
22865
|
-
|
|
23147
|
+
mkdirSync17(dir, { recursive: true, mode: 448 });
|
|
22866
23148
|
const line = JSON.stringify(entry);
|
|
22867
23149
|
if (this.encryptor?.isEnabled()) {
|
|
22868
23150
|
appendFileSync6(this.sessionLogPath(id), this.encryptor.encryptFileContent(line) + `
|
|
@@ -22874,10 +23156,10 @@ class SessionStore {
|
|
|
22874
23156
|
}
|
|
22875
23157
|
loadSessionLog(id) {
|
|
22876
23158
|
const path = this.sessionLogPath(id);
|
|
22877
|
-
if (!
|
|
23159
|
+
if (!existsSync40(path))
|
|
22878
23160
|
return [];
|
|
22879
23161
|
try {
|
|
22880
|
-
const raw =
|
|
23162
|
+
const raw = readFileSync24(path, "utf-8");
|
|
22881
23163
|
const lines = raw.split(`
|
|
22882
23164
|
`).filter(Boolean);
|
|
22883
23165
|
const parseLine = (line) => {
|
|
@@ -22902,7 +23184,7 @@ class SessionStore {
|
|
|
22902
23184
|
}
|
|
22903
23185
|
}
|
|
22904
23186
|
listSessions() {
|
|
22905
|
-
if (!
|
|
23187
|
+
if (!existsSync40(this.baseDir))
|
|
22906
23188
|
return [];
|
|
22907
23189
|
const entries = readdirSync13(this.baseDir, { withFileTypes: true });
|
|
22908
23190
|
const sessions = [];
|
|
@@ -22919,7 +23201,7 @@ class SessionStore {
|
|
|
22919
23201
|
deleteSession(id) {
|
|
22920
23202
|
this._metaCache.delete(id);
|
|
22921
23203
|
const dir = this.sessionDir(id);
|
|
22922
|
-
if (
|
|
23204
|
+
if (existsSync40(dir)) {
|
|
22923
23205
|
rmSync2(dir, { recursive: true, force: true });
|
|
22924
23206
|
}
|
|
22925
23207
|
}
|
|
@@ -22931,11 +23213,11 @@ class SessionStore {
|
|
|
22931
23213
|
const updatedAt = new Date(session2.updatedAt);
|
|
22932
23214
|
if (updatedAt < thirtyDaysAgo) {
|
|
22933
23215
|
const historyPath = this.historyPath(session2.id);
|
|
22934
|
-
if (
|
|
22935
|
-
const content =
|
|
23216
|
+
if (existsSync40(historyPath)) {
|
|
23217
|
+
const content = readFileSync24(historyPath, "utf-8");
|
|
22936
23218
|
const compressed = gzipSync(content);
|
|
22937
|
-
const gzPath =
|
|
22938
|
-
|
|
23219
|
+
const gzPath = join33(this.baseDir, `${session2.id}.jsonl.gz`);
|
|
23220
|
+
writeFileSync16(gzPath, compressed);
|
|
22939
23221
|
rmSync2(historyPath);
|
|
22940
23222
|
const meta = this.loadMeta(session2.id);
|
|
22941
23223
|
if (meta) {
|
|
@@ -23159,8 +23441,8 @@ class ProfileCompressor {
|
|
|
23159
23441
|
}
|
|
23160
23442
|
|
|
23161
23443
|
// src/modules/user-profile/profile.ts
|
|
23162
|
-
import { readFileSync as
|
|
23163
|
-
import { join as
|
|
23444
|
+
import { readFileSync as readFileSync25, writeFileSync as writeFileSync17, existsSync as existsSync41, mkdirSync as mkdirSync18 } from "fs";
|
|
23445
|
+
import { join as join34 } from "path";
|
|
23164
23446
|
import { homedir as homedir10, hostname, platform as platform8, type } from "os";
|
|
23165
23447
|
import { env } from "process";
|
|
23166
23448
|
|
|
@@ -23184,17 +23466,17 @@ class UserProfile {
|
|
|
23184
23466
|
return this.info;
|
|
23185
23467
|
}
|
|
23186
23468
|
save() {
|
|
23187
|
-
if (!
|
|
23188
|
-
|
|
23469
|
+
if (!existsSync41(this.profileDir)) {
|
|
23470
|
+
mkdirSync18(this.profileDir, { recursive: true });
|
|
23189
23471
|
}
|
|
23190
|
-
|
|
23472
|
+
writeFileSync17(join34(this.profileDir, "profile.json"), JSON.stringify({ ...this.info, preferences: this.preferences }, null, 2), "utf-8");
|
|
23191
23473
|
}
|
|
23192
23474
|
load() {
|
|
23193
|
-
const path =
|
|
23194
|
-
if (!
|
|
23475
|
+
const path = join34(this.profileDir, "profile.json");
|
|
23476
|
+
if (!existsSync41(path))
|
|
23195
23477
|
return null;
|
|
23196
23478
|
try {
|
|
23197
|
-
const data = JSON.parse(
|
|
23479
|
+
const data = JSON.parse(readFileSync25(path, "utf-8"));
|
|
23198
23480
|
this.info = {
|
|
23199
23481
|
platform: data.platform,
|
|
23200
23482
|
os: data.os,
|
|
@@ -23229,12 +23511,12 @@ class UserProfile {
|
|
|
23229
23511
|
var init_profile = () => {};
|
|
23230
23512
|
|
|
23231
23513
|
// src/modules/skills/loader.ts
|
|
23232
|
-
import { readdirSync as readdirSync14, readFileSync as
|
|
23233
|
-
import { join as
|
|
23514
|
+
import { readdirSync as readdirSync14, readFileSync as readFileSync26, existsSync as existsSync42, statSync as statSync7 } from "fs";
|
|
23515
|
+
import { join as join35 } from "path";
|
|
23234
23516
|
|
|
23235
23517
|
class SkillsLoader {
|
|
23236
23518
|
loadFromDir(dirPath) {
|
|
23237
|
-
if (!
|
|
23519
|
+
if (!existsSync42(dirPath))
|
|
23238
23520
|
return [];
|
|
23239
23521
|
const skills = [];
|
|
23240
23522
|
this.scanDir(dirPath, skills);
|
|
@@ -23243,7 +23525,7 @@ class SkillsLoader {
|
|
|
23243
23525
|
scanDir(dirPath, skills) {
|
|
23244
23526
|
const entries = readdirSync14(dirPath);
|
|
23245
23527
|
for (const entry of entries) {
|
|
23246
|
-
const fullPath =
|
|
23528
|
+
const fullPath = join35(dirPath, entry);
|
|
23247
23529
|
let stat;
|
|
23248
23530
|
try {
|
|
23249
23531
|
stat = statSync7(fullPath);
|
|
@@ -23256,7 +23538,7 @@ class SkillsLoader {
|
|
|
23256
23538
|
}
|
|
23257
23539
|
if (!entry.endsWith(".md") && !entry.endsWith(".skill.md"))
|
|
23258
23540
|
continue;
|
|
23259
|
-
const content =
|
|
23541
|
+
const content = readFileSync26(fullPath, "utf-8");
|
|
23260
23542
|
const parsed = this.parseSkillFile(content, fullPath);
|
|
23261
23543
|
if (parsed)
|
|
23262
23544
|
skills.push(parsed);
|
|
@@ -23903,11 +24185,11 @@ var init_check_tool = __esm(() => {
|
|
|
23903
24185
|
});
|
|
23904
24186
|
|
|
23905
24187
|
// src/modules/lsp/module.ts
|
|
23906
|
-
import { existsSync as
|
|
24188
|
+
import { existsSync as existsSync43 } from "fs";
|
|
23907
24189
|
import { relative as relative5, resolve as resolve21 } from "path";
|
|
23908
|
-
import { join as
|
|
24190
|
+
import { join as join36 } from "path";
|
|
23909
24191
|
function hasTypeEnvironment(projectRoot) {
|
|
23910
|
-
return
|
|
24192
|
+
return existsSync43(join36(projectRoot, "tsconfig.json")) || existsSync43(join36(projectRoot, "jsconfig.json")) || existsSync43(join36(projectRoot, "node_modules"));
|
|
23911
24193
|
}
|
|
23912
24194
|
|
|
23913
24195
|
class LspModule {
|
|
@@ -23962,7 +24244,7 @@ class LspModule {
|
|
|
23962
24244
|
if (!filePath)
|
|
23963
24245
|
return;
|
|
23964
24246
|
const fullPath = resolve21(_ctx.baseDir, filePath);
|
|
23965
|
-
if (!
|
|
24247
|
+
if (!existsSync43(fullPath))
|
|
23966
24248
|
return;
|
|
23967
24249
|
const serverConfig = getServerForFile(fullPath, self.config);
|
|
23968
24250
|
if (!serverConfig)
|
|
@@ -24054,7 +24336,7 @@ ${items}`;
|
|
|
24054
24336
|
})
|
|
24055
24337
|
};
|
|
24056
24338
|
}
|
|
24057
|
-
if (!
|
|
24339
|
+
if (!existsSync43(resolved)) {
|
|
24058
24340
|
return { success: false, output: t("lsp.check_notfound", { path }) };
|
|
24059
24341
|
}
|
|
24060
24342
|
const files = await collectCheckFiles(resolved, this.config);
|
|
@@ -24171,8 +24453,8 @@ var init_lsp = __esm(() => {
|
|
|
24171
24453
|
});
|
|
24172
24454
|
|
|
24173
24455
|
// src/modules/lsp/startup-check.ts
|
|
24174
|
-
import { existsSync as
|
|
24175
|
-
import { join as
|
|
24456
|
+
import { existsSync as existsSync44 } from "fs";
|
|
24457
|
+
import { join as join37 } from "path";
|
|
24176
24458
|
import { spawn as spawn9 } from "child_process";
|
|
24177
24459
|
async function runStartupHealthCheck(config, baseDir, deps = {}) {
|
|
24178
24460
|
if (!config.enabled)
|
|
@@ -24199,7 +24481,7 @@ ${result.lines.join(`
|
|
|
24199
24481
|
}
|
|
24200
24482
|
async function runCheck(config, baseDir, deps) {
|
|
24201
24483
|
const projectRoot = findProjectRoot(baseDir, baseDir, ["tsconfig.json", "package.json"]);
|
|
24202
|
-
if (
|
|
24484
|
+
if (existsSync44(join37(projectRoot, "tsconfig.json"))) {
|
|
24203
24485
|
const runTsc = deps.runTsc ?? runTscDefault;
|
|
24204
24486
|
const errors = await runTsc(projectRoot, STARTUP_CHECK_TIMEOUT_MS);
|
|
24205
24487
|
if (errors.length === 0)
|
|
@@ -24301,8 +24583,8 @@ var init_startup_check = __esm(() => {
|
|
|
24301
24583
|
});
|
|
24302
24584
|
|
|
24303
24585
|
// src/modules/indexer/walker.ts
|
|
24304
|
-
import { readdirSync as readdirSync15, readFileSync as
|
|
24305
|
-
import { join as
|
|
24586
|
+
import { readdirSync as readdirSync15, readFileSync as readFileSync27, statSync as statSync8, lstatSync, existsSync as existsSync45, watch } from "fs";
|
|
24587
|
+
import { join as join38, relative as relative6, extname as extname7 } from "path";
|
|
24306
24588
|
|
|
24307
24589
|
class Indexer {
|
|
24308
24590
|
baseDir;
|
|
@@ -24329,7 +24611,7 @@ class Indexer {
|
|
|
24329
24611
|
let totalSize = 0;
|
|
24330
24612
|
let count = 0;
|
|
24331
24613
|
const walkDir2 = (dir) => {
|
|
24332
|
-
if (!
|
|
24614
|
+
if (!existsSync45(dir))
|
|
24333
24615
|
return;
|
|
24334
24616
|
let entries;
|
|
24335
24617
|
try {
|
|
@@ -24340,7 +24622,7 @@ class Indexer {
|
|
|
24340
24622
|
for (const entry of entries) {
|
|
24341
24623
|
if (count >= this.MAX_FILES)
|
|
24342
24624
|
return;
|
|
24343
|
-
const fullPath =
|
|
24625
|
+
const fullPath = join38(dir, entry);
|
|
24344
24626
|
const relPath = relative6(this.baseDir, fullPath);
|
|
24345
24627
|
try {
|
|
24346
24628
|
const lst = lstatSync(fullPath, { throwIfNoEntry: false });
|
|
@@ -24355,7 +24637,7 @@ class Indexer {
|
|
|
24355
24637
|
const ext = extname7(entry).toLowerCase();
|
|
24356
24638
|
const language = LANGUAGES[ext];
|
|
24357
24639
|
if (language) {
|
|
24358
|
-
const content =
|
|
24640
|
+
const content = readFileSync27(fullPath, "utf-8");
|
|
24359
24641
|
const exports = this.extractExports(content, language);
|
|
24360
24642
|
files.push({ path: relPath, language, exports, size: stat2.size });
|
|
24361
24643
|
totalSize += stat2.size;
|
|
@@ -24413,22 +24695,22 @@ var init_walker = __esm(() => {
|
|
|
24413
24695
|
});
|
|
24414
24696
|
|
|
24415
24697
|
// src/modules/indexer/cache.ts
|
|
24416
|
-
import { readFileSync as
|
|
24417
|
-
import { join as
|
|
24698
|
+
import { readFileSync as readFileSync28, writeFileSync as writeFileSync18, existsSync as existsSync46, mkdirSync as mkdirSync19, rmSync as rmSync3 } from "fs";
|
|
24699
|
+
import { join as join39 } from "path";
|
|
24418
24700
|
|
|
24419
24701
|
class IndexCache {
|
|
24420
24702
|
cachePath;
|
|
24421
24703
|
cache = null;
|
|
24422
24704
|
constructor(cacheDir) {
|
|
24423
|
-
this.cachePath =
|
|
24705
|
+
this.cachePath = join39(cacheDir, "index-cache.json");
|
|
24424
24706
|
}
|
|
24425
24707
|
load() {
|
|
24426
24708
|
if (this.cache)
|
|
24427
24709
|
return this.cache;
|
|
24428
|
-
if (!
|
|
24710
|
+
if (!existsSync46(this.cachePath))
|
|
24429
24711
|
return null;
|
|
24430
24712
|
try {
|
|
24431
|
-
this.cache = JSON.parse(
|
|
24713
|
+
this.cache = JSON.parse(readFileSync28(this.cachePath, "utf-8"));
|
|
24432
24714
|
return this.cache;
|
|
24433
24715
|
} catch {
|
|
24434
24716
|
return null;
|
|
@@ -24436,14 +24718,14 @@ class IndexCache {
|
|
|
24436
24718
|
}
|
|
24437
24719
|
save(result) {
|
|
24438
24720
|
this.cache = result;
|
|
24439
|
-
const dir =
|
|
24440
|
-
if (!
|
|
24441
|
-
|
|
24442
|
-
|
|
24721
|
+
const dir = join39(this.cachePath, "..");
|
|
24722
|
+
if (!existsSync46(dir))
|
|
24723
|
+
mkdirSync19(dir, { recursive: true });
|
|
24724
|
+
writeFileSync18(this.cachePath, JSON.stringify(result), "utf-8");
|
|
24443
24725
|
}
|
|
24444
24726
|
invalidate() {
|
|
24445
24727
|
this.cache = null;
|
|
24446
|
-
if (
|
|
24728
|
+
if (existsSync46(this.cachePath)) {
|
|
24447
24729
|
try {
|
|
24448
24730
|
rmSync3(this.cachePath);
|
|
24449
24731
|
} catch {}
|
|
@@ -24453,11 +24735,11 @@ class IndexCache {
|
|
|
24453
24735
|
var init_cache = () => {};
|
|
24454
24736
|
|
|
24455
24737
|
// src/modules/indexer/project-profile.ts
|
|
24456
|
-
import { readFileSync as
|
|
24457
|
-
import { join as
|
|
24738
|
+
import { readFileSync as readFileSync29, existsSync as existsSync47 } from "fs";
|
|
24739
|
+
import { join as join40 } from "path";
|
|
24458
24740
|
function detectManifest(baseDir) {
|
|
24459
24741
|
for (const manifest of MANIFEST_ORDER) {
|
|
24460
|
-
if (
|
|
24742
|
+
if (existsSync47(join40(baseDir, manifest)))
|
|
24461
24743
|
return manifest;
|
|
24462
24744
|
}
|
|
24463
24745
|
return null;
|
|
@@ -24474,7 +24756,7 @@ function cleanDependency(entry) {
|
|
|
24474
24756
|
}
|
|
24475
24757
|
function readPackageJson(baseDir) {
|
|
24476
24758
|
try {
|
|
24477
|
-
const raw = JSON.parse(
|
|
24759
|
+
const raw = JSON.parse(readFileSync29(join40(baseDir, "package.json"), "utf-8"));
|
|
24478
24760
|
if (!raw || typeof raw !== "object")
|
|
24479
24761
|
return null;
|
|
24480
24762
|
const profile = {
|
|
@@ -24498,7 +24780,7 @@ function readPackageJson(baseDir) {
|
|
|
24498
24780
|
}
|
|
24499
24781
|
function readPyproject(baseDir) {
|
|
24500
24782
|
try {
|
|
24501
|
-
const content =
|
|
24783
|
+
const content = readFileSync29(join40(baseDir, "pyproject.toml"), "utf-8");
|
|
24502
24784
|
const profile = { runtime: "python", deps: [], devDeps: [], scripts: {} };
|
|
24503
24785
|
const nameMatch = content.match(/^\s*name\s*=\s*"([^"]+)"/m);
|
|
24504
24786
|
if (nameMatch)
|
|
@@ -24514,7 +24796,7 @@ function readPyproject(baseDir) {
|
|
|
24514
24796
|
}
|
|
24515
24797
|
function readCargo(baseDir) {
|
|
24516
24798
|
try {
|
|
24517
|
-
const content =
|
|
24799
|
+
const content = readFileSync29(join40(baseDir, "Cargo.toml"), "utf-8");
|
|
24518
24800
|
const profile = { runtime: "rust", deps: [], devDeps: [], scripts: {} };
|
|
24519
24801
|
const nameMatch = content.match(/^\s*name\s*=\s*"([^"]+)"/m);
|
|
24520
24802
|
if (nameMatch)
|
|
@@ -24538,7 +24820,7 @@ function readCargo(baseDir) {
|
|
|
24538
24820
|
}
|
|
24539
24821
|
function readGoMod(baseDir) {
|
|
24540
24822
|
try {
|
|
24541
|
-
const content =
|
|
24823
|
+
const content = readFileSync29(join40(baseDir, "go.mod"), "utf-8");
|
|
24542
24824
|
const profile = { runtime: "go", deps: [], devDeps: [], scripts: {} };
|
|
24543
24825
|
const moduleMatch = content.match(/^module\s+(\S+)/m);
|
|
24544
24826
|
if (moduleMatch)
|
|
@@ -24556,7 +24838,7 @@ function readGoMod(baseDir) {
|
|
|
24556
24838
|
}
|
|
24557
24839
|
function readRequirements(baseDir) {
|
|
24558
24840
|
try {
|
|
24559
|
-
const content =
|
|
24841
|
+
const content = readFileSync29(join40(baseDir, "requirements.txt"), "utf-8");
|
|
24560
24842
|
const profile = { runtime: "python", deps: [], devDeps: [], scripts: {} };
|
|
24561
24843
|
for (const line of content.split(`
|
|
24562
24844
|
`)) {
|
|
@@ -24695,7 +24977,8 @@ class IndexerModule {
|
|
|
24695
24977
|
content,
|
|
24696
24978
|
priority: "normal",
|
|
24697
24979
|
essential: false,
|
|
24698
|
-
estimatedTokens: this.estimateTokens(content)
|
|
24980
|
+
estimatedTokens: this.estimateTokens(content),
|
|
24981
|
+
kind: "project-map"
|
|
24699
24982
|
};
|
|
24700
24983
|
}
|
|
24701
24984
|
getToolDefinitions() {
|
|
@@ -25105,7 +25388,7 @@ var init_mcp = __esm(() => {
|
|
|
25105
25388
|
|
|
25106
25389
|
// src/modules/memory/module.ts
|
|
25107
25390
|
import { homedir as homedir11 } from "os";
|
|
25108
|
-
import { join as
|
|
25391
|
+
import { join as join41 } from "path";
|
|
25109
25392
|
|
|
25110
25393
|
class MemoryModule {
|
|
25111
25394
|
name = "memory";
|
|
@@ -25114,7 +25397,7 @@ class MemoryModule {
|
|
|
25114
25397
|
if (storeOrDir instanceof MemoryStore) {
|
|
25115
25398
|
this.store = storeOrDir;
|
|
25116
25399
|
} else {
|
|
25117
|
-
const dir = storeOrDir ||
|
|
25400
|
+
const dir = storeOrDir || join41(homedir11(), ".mma", "memory");
|
|
25118
25401
|
this.store = new MemoryStore(dir);
|
|
25119
25402
|
}
|
|
25120
25403
|
}
|
|
@@ -25201,16 +25484,16 @@ var init_module8 = __esm(() => {
|
|
|
25201
25484
|
});
|
|
25202
25485
|
|
|
25203
25486
|
// src/core/version.ts
|
|
25204
|
-
import { existsSync as
|
|
25205
|
-
import { join as
|
|
25487
|
+
import { existsSync as existsSync48, readFileSync as readFileSync30 } from "fs";
|
|
25488
|
+
import { join as join42, dirname as dirname15 } from "path";
|
|
25206
25489
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
25207
25490
|
function readMmaVersion() {
|
|
25208
25491
|
const here = dirname15(fileURLToPath2(import.meta.url));
|
|
25209
|
-
const candidates = [
|
|
25492
|
+
const candidates = [join42(here, "..", "..", "package.json"), join42(here, "..", "package.json")];
|
|
25210
25493
|
for (const p of candidates) {
|
|
25211
|
-
if (
|
|
25494
|
+
if (existsSync48(p)) {
|
|
25212
25495
|
try {
|
|
25213
|
-
const raw = JSON.parse(
|
|
25496
|
+
const raw = JSON.parse(readFileSync30(p, "utf8"));
|
|
25214
25497
|
if (raw.version)
|
|
25215
25498
|
return raw.version;
|
|
25216
25499
|
} catch {}
|
|
@@ -25221,21 +25504,21 @@ function readMmaVersion() {
|
|
|
25221
25504
|
var init_version = () => {};
|
|
25222
25505
|
|
|
25223
25506
|
// src/core/environment.ts
|
|
25224
|
-
import { existsSync as
|
|
25507
|
+
import { existsSync as existsSync49, readFileSync as readFileSync31, readdirSync as readdirSync16 } from "fs";
|
|
25225
25508
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
25226
25509
|
import { createRequire as createRequire2 } from "module";
|
|
25227
|
-
import { join as
|
|
25510
|
+
import { join as join43, dirname as dirname16 } from "path";
|
|
25228
25511
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
25229
25512
|
import { arch, homedir as homedir12, hostname as hostname2, platform as platform10, release } from "os";
|
|
25230
25513
|
import { env as env2 } from "process";
|
|
25231
25514
|
function readEngineRequirement() {
|
|
25232
25515
|
const here = dirname16(fileURLToPath3(import.meta.url));
|
|
25233
|
-
const candidates = [
|
|
25516
|
+
const candidates = [join43(here, "..", "..", "package.json"), join43(here, "..", "package.json")];
|
|
25234
25517
|
for (const p of candidates) {
|
|
25235
|
-
if (!
|
|
25518
|
+
if (!existsSync49(p))
|
|
25236
25519
|
continue;
|
|
25237
25520
|
try {
|
|
25238
|
-
const raw = JSON.parse(
|
|
25521
|
+
const raw = JSON.parse(readFileSync31(p, "utf8"));
|
|
25239
25522
|
if (raw.engines?.node)
|
|
25240
25523
|
return String(raw.engines.node);
|
|
25241
25524
|
} catch {}
|
|
@@ -25298,7 +25581,7 @@ function toolVersion(cmd) {
|
|
|
25298
25581
|
function playwrightBrowsersDir() {
|
|
25299
25582
|
if (process.env.PLAYWRIGHT_BROWSERS_PATH)
|
|
25300
25583
|
return process.env.PLAYWRIGHT_BROWSERS_PATH;
|
|
25301
|
-
return process.platform === "win32" ?
|
|
25584
|
+
return process.platform === "win32" ? join43(homedir12(), "AppData", "Local", "ms-playwright") : join43(homedir12(), ".cache", "ms-playwright");
|
|
25302
25585
|
}
|
|
25303
25586
|
function playwrightInfo() {
|
|
25304
25587
|
let installed = false;
|
|
@@ -25307,14 +25590,14 @@ function playwrightInfo() {
|
|
|
25307
25590
|
try {
|
|
25308
25591
|
const require2 = createRequire2(import.meta.url);
|
|
25309
25592
|
const pkgPath = require2.resolve("playwright/package.json");
|
|
25310
|
-
installed =
|
|
25311
|
-
version = JSON.parse(
|
|
25593
|
+
installed = existsSync49(pkgPath);
|
|
25594
|
+
version = JSON.parse(readFileSync31(pkgPath, "utf8")).version || "";
|
|
25312
25595
|
} catch {
|
|
25313
25596
|
installed = false;
|
|
25314
25597
|
}
|
|
25315
25598
|
let browsersInstalled = false;
|
|
25316
25599
|
try {
|
|
25317
|
-
if (
|
|
25600
|
+
if (existsSync49(browsersDir)) {
|
|
25318
25601
|
browsersInstalled = readdirSync16(browsersDir).some((d) => /chrom/i.test(d));
|
|
25319
25602
|
}
|
|
25320
25603
|
} catch {
|
|
@@ -25421,24 +25704,24 @@ __export(exports_manifest, {
|
|
|
25421
25704
|
getCertMark: () => getCertMark,
|
|
25422
25705
|
bundledManifestPath: () => bundledManifestPath
|
|
25423
25706
|
});
|
|
25424
|
-
import { existsSync as
|
|
25425
|
-
import { dirname as dirname17, join as
|
|
25707
|
+
import { existsSync as existsSync50, readFileSync as readFileSync32, mkdirSync as mkdirSync20, writeFileSync as writeFileSync19 } from "fs";
|
|
25708
|
+
import { dirname as dirname17, join as join44 } from "path";
|
|
25426
25709
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
25427
25710
|
import { homedir as homedir13 } from "os";
|
|
25428
25711
|
function manifestPath(projectDir) {
|
|
25429
|
-
return
|
|
25712
|
+
return join44(projectDir, "certification", "certifications.json");
|
|
25430
25713
|
}
|
|
25431
25714
|
function globalManifestDir(override) {
|
|
25432
|
-
return override || process.env.MMA_CERT_HOME ||
|
|
25715
|
+
return override || process.env.MMA_CERT_HOME || join44(homedir13(), ".mma");
|
|
25433
25716
|
}
|
|
25434
25717
|
function globalManifestPath(override) {
|
|
25435
|
-
return
|
|
25718
|
+
return join44(globalManifestDir(override), "certifications.json");
|
|
25436
25719
|
}
|
|
25437
25720
|
function readManifest(projectDir) {
|
|
25438
25721
|
const path = manifestPath(projectDir);
|
|
25439
25722
|
try {
|
|
25440
|
-
if (
|
|
25441
|
-
const raw = JSON.parse(
|
|
25723
|
+
if (existsSync50(path)) {
|
|
25724
|
+
const raw = JSON.parse(readFileSync32(path, "utf-8"));
|
|
25442
25725
|
return { version: 1, certifications: raw.certifications ?? [] };
|
|
25443
25726
|
}
|
|
25444
25727
|
} catch {}
|
|
@@ -25446,14 +25729,14 @@ function readManifest(projectDir) {
|
|
|
25446
25729
|
}
|
|
25447
25730
|
function saveManifest(m, projectDir) {
|
|
25448
25731
|
const path = manifestPath(projectDir);
|
|
25449
|
-
|
|
25450
|
-
|
|
25732
|
+
mkdirSync20(join44(projectDir, "certification"), { recursive: true });
|
|
25733
|
+
writeFileSync19(path, JSON.stringify(m, null, 2), "utf-8");
|
|
25451
25734
|
}
|
|
25452
25735
|
function readGlobalManifest(override) {
|
|
25453
25736
|
const path = globalManifestPath(override);
|
|
25454
25737
|
try {
|
|
25455
|
-
if (
|
|
25456
|
-
const raw = JSON.parse(
|
|
25738
|
+
if (existsSync50(path)) {
|
|
25739
|
+
const raw = JSON.parse(readFileSync32(path, "utf-8"));
|
|
25457
25740
|
return { version: 1, certifications: raw.certifications ?? [] };
|
|
25458
25741
|
}
|
|
25459
25742
|
} catch {}
|
|
@@ -25461,8 +25744,8 @@ function readGlobalManifest(override) {
|
|
|
25461
25744
|
}
|
|
25462
25745
|
function saveGlobalManifest(m, override) {
|
|
25463
25746
|
const dir = globalManifestDir(override);
|
|
25464
|
-
|
|
25465
|
-
|
|
25747
|
+
mkdirSync20(dir, { recursive: true });
|
|
25748
|
+
writeFileSync19(globalManifestPath(override), JSON.stringify(m, null, 2), "utf-8");
|
|
25466
25749
|
}
|
|
25467
25750
|
function readMergedManifest(projectDir, override) {
|
|
25468
25751
|
const merged = new Map;
|
|
@@ -25519,17 +25802,17 @@ function getCertMark(model, providerUrl, currentVersion, projectDir, globalOverr
|
|
|
25519
25802
|
return isFullyPassed(entry) ? "certified" : "none";
|
|
25520
25803
|
}
|
|
25521
25804
|
function syncSnapshotPath(override) {
|
|
25522
|
-
return
|
|
25805
|
+
return join44(globalManifestDir(override), "certifications.synced.json");
|
|
25523
25806
|
}
|
|
25524
25807
|
function bundledManifestPath() {
|
|
25525
25808
|
const here = dirname17(fileURLToPath4(import.meta.url));
|
|
25526
25809
|
const candidates = [
|
|
25527
|
-
|
|
25528
|
-
|
|
25529
|
-
|
|
25810
|
+
join44(here, "certification", "certifications.json"),
|
|
25811
|
+
join44(here, "..", "certification", "certifications.json"),
|
|
25812
|
+
join44(here, "..", "..", "..", "certification", "certifications.json")
|
|
25530
25813
|
];
|
|
25531
25814
|
for (const p of candidates) {
|
|
25532
|
-
if (
|
|
25815
|
+
if (existsSync50(p))
|
|
25533
25816
|
return p;
|
|
25534
25817
|
}
|
|
25535
25818
|
return null;
|
|
@@ -25537,11 +25820,11 @@ function bundledManifestPath() {
|
|
|
25537
25820
|
function syncGlobalManifest(override, bundledPathOverride) {
|
|
25538
25821
|
try {
|
|
25539
25822
|
const bundledPath = bundledPathOverride ?? bundledManifestPath();
|
|
25540
|
-
if (!bundledPath || !
|
|
25823
|
+
if (!bundledPath || !existsSync50(bundledPath))
|
|
25541
25824
|
return { synced: false, reason: "no-bundled" };
|
|
25542
|
-
const raw =
|
|
25825
|
+
const raw = readFileSync32(bundledPath, "utf-8");
|
|
25543
25826
|
const snapshotPath = syncSnapshotPath(override);
|
|
25544
|
-
if (
|
|
25827
|
+
if (existsSync50(snapshotPath) && readFileSync32(snapshotPath, "utf-8") === raw) {
|
|
25545
25828
|
return { synced: false, reason: "unchanged" };
|
|
25546
25829
|
}
|
|
25547
25830
|
const bundled = JSON.parse(raw);
|
|
@@ -25552,8 +25835,8 @@ function syncGlobalManifest(override, bundledPathOverride) {
|
|
|
25552
25835
|
for (const e of bundled.certifications ?? [])
|
|
25553
25836
|
merged.set(certKey(e), e);
|
|
25554
25837
|
saveGlobalManifest({ version: 1, certifications: [...merged.values()] }, override);
|
|
25555
|
-
|
|
25556
|
-
|
|
25838
|
+
mkdirSync20(globalManifestDir(override), { recursive: true });
|
|
25839
|
+
writeFileSync19(snapshotPath, raw, "utf-8");
|
|
25557
25840
|
return { synced: true, reason: "synced" };
|
|
25558
25841
|
} catch {
|
|
25559
25842
|
return { synced: false, reason: "error" };
|
|
@@ -25569,13 +25852,13 @@ __export(exports_probe, {
|
|
|
25569
25852
|
resetProbeCache: () => resetProbeCache,
|
|
25570
25853
|
probeReasoningSupport: () => probeReasoningSupport,
|
|
25571
25854
|
getCachedProbeResult: () => getCachedProbeResult,
|
|
25572
|
-
cacheKey: () =>
|
|
25855
|
+
cacheKey: () => cacheKey2
|
|
25573
25856
|
});
|
|
25574
|
-
import { existsSync as
|
|
25575
|
-
import { join as
|
|
25857
|
+
import { existsSync as existsSync51, readFileSync as readFileSync33, writeFileSync as writeFileSync20, mkdirSync as mkdirSync21 } from "fs";
|
|
25858
|
+
import { join as join45, dirname as dirname18 } from "path";
|
|
25576
25859
|
import { homedir as homedir14 } from "os";
|
|
25577
25860
|
function cachePath() {
|
|
25578
|
-
return
|
|
25861
|
+
return join45(homedir14(), ".mma", "reasoning-cache.json");
|
|
25579
25862
|
}
|
|
25580
25863
|
async function probeReasoningSupport(provider, strategy, signal) {
|
|
25581
25864
|
if (strategy === "none")
|
|
@@ -25595,7 +25878,7 @@ async function probeReasoningSupport(provider, strategy, signal) {
|
|
|
25595
25878
|
return null;
|
|
25596
25879
|
}
|
|
25597
25880
|
}
|
|
25598
|
-
function
|
|
25881
|
+
function cacheKey2(baseUrl, model) {
|
|
25599
25882
|
return `${baseUrl}|${model}`;
|
|
25600
25883
|
}
|
|
25601
25884
|
function getCachedProbeResult(key) {
|
|
@@ -25624,15 +25907,15 @@ function setCachedProbeResult(key, result) {
|
|
|
25624
25907
|
function resetProbeCache() {
|
|
25625
25908
|
memCache.clear();
|
|
25626
25909
|
const path = cachePath();
|
|
25627
|
-
if (
|
|
25628
|
-
|
|
25910
|
+
if (existsSync51(path)) {
|
|
25911
|
+
writeFileSync20(path, "{}", "utf-8");
|
|
25629
25912
|
}
|
|
25630
25913
|
}
|
|
25631
25914
|
function readDiskCache() {
|
|
25632
25915
|
try {
|
|
25633
25916
|
const path = cachePath();
|
|
25634
|
-
if (
|
|
25635
|
-
return JSON.parse(
|
|
25917
|
+
if (existsSync51(path)) {
|
|
25918
|
+
return JSON.parse(readFileSync33(path, "utf-8"));
|
|
25636
25919
|
}
|
|
25637
25920
|
} catch {}
|
|
25638
25921
|
return {};
|
|
@@ -25640,8 +25923,8 @@ function readDiskCache() {
|
|
|
25640
25923
|
function writeDiskCache(data) {
|
|
25641
25924
|
try {
|
|
25642
25925
|
const path = cachePath();
|
|
25643
|
-
|
|
25644
|
-
|
|
25926
|
+
mkdirSync21(dirname18(path), { recursive: true });
|
|
25927
|
+
writeFileSync20(path, JSON.stringify(data, null, 2), "utf-8");
|
|
25645
25928
|
} catch {}
|
|
25646
25929
|
}
|
|
25647
25930
|
var PROBE_MESSAGES, CACHE_TTL_MS, memCache;
|
|
@@ -25733,8 +26016,8 @@ __export(exports_bootstrap, {
|
|
|
25733
26016
|
bootstrap: () => bootstrap
|
|
25734
26017
|
});
|
|
25735
26018
|
import { homedir as homedir15 } from "os";
|
|
25736
|
-
import { join as
|
|
25737
|
-
import { existsSync as
|
|
26019
|
+
import { join as join46, resolve as resolve22 } from "path";
|
|
26020
|
+
import { existsSync as existsSync52, readFileSync as readFileSync34 } from "fs";
|
|
25738
26021
|
function applyReasoningCliOverride(config, reasoningLevel) {
|
|
25739
26022
|
if (!reasoningLevel || reasoningLevel === "auto")
|
|
25740
26023
|
return;
|
|
@@ -25760,19 +26043,20 @@ function loadAgentsMdBlocks(baseDir, dir, skip) {
|
|
|
25760
26043
|
return [];
|
|
25761
26044
|
const blocks = [];
|
|
25762
26045
|
const candidates = [
|
|
25763
|
-
|
|
25764
|
-
|
|
25765
|
-
|
|
26046
|
+
join46(baseDir, "AGENTS.md"),
|
|
26047
|
+
join46(baseDir, ".mma", "AGENTS.md"),
|
|
26048
|
+
join46(dir, "AGENTS.md")
|
|
25766
26049
|
];
|
|
25767
26050
|
for (const p of candidates) {
|
|
25768
|
-
if (
|
|
25769
|
-
const content =
|
|
26051
|
+
if (existsSync52(p)) {
|
|
26052
|
+
const content = readFileSync34(p, "utf-8").trim();
|
|
25770
26053
|
if (content) {
|
|
25771
26054
|
blocks.push({
|
|
25772
26055
|
content,
|
|
25773
26056
|
priority: "high",
|
|
25774
26057
|
essential: false,
|
|
25775
|
-
estimatedTokens: estimateTokens(content)
|
|
26058
|
+
estimatedTokens: estimateTokens(content),
|
|
26059
|
+
kind: "instructions"
|
|
25776
26060
|
});
|
|
25777
26061
|
}
|
|
25778
26062
|
}
|
|
@@ -25843,8 +26127,8 @@ function buildSystemInfo(config, baseDir, profileCompressed) {
|
|
|
25843
26127
|
`);
|
|
25844
26128
|
}
|
|
25845
26129
|
async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reasoningLevel) {
|
|
25846
|
-
const dir = configDir || process.env.MMA_CONFIG_DIR ||
|
|
25847
|
-
const projectConfigPath = projectDir ?
|
|
26130
|
+
const dir = configDir || process.env.MMA_CONFIG_DIR || join46(homedir15(), ".mma");
|
|
26131
|
+
const projectConfigPath = projectDir ? join46(projectDir, ".mmrc") : join46(process.cwd(), ".mmrc");
|
|
25848
26132
|
const { config, legacyDetected } = loadConfig({ configDir: dir, projectConfigPath });
|
|
25849
26133
|
setLocale(config.locale);
|
|
25850
26134
|
applyReasoningCliOverride(config, reasoningLevel);
|
|
@@ -25855,7 +26139,7 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
25855
26139
|
}
|
|
25856
26140
|
} catch {}
|
|
25857
26141
|
const logger4 = new Logger(config.logLevel);
|
|
25858
|
-
logger4.setLogDir(
|
|
26142
|
+
logger4.setLogDir(join46(dir, "logs"));
|
|
25859
26143
|
logger4.debug("MMA bootstrap", {
|
|
25860
26144
|
version: config.version,
|
|
25861
26145
|
model: config.model
|
|
@@ -25884,7 +26168,24 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
25884
26168
|
logger4.info(`Model ${config.model} loaded in ${loadResult.loadTime}s`);
|
|
25885
26169
|
}
|
|
25886
26170
|
}
|
|
25887
|
-
const
|
|
26171
|
+
const contextProbePromise = (async () => {
|
|
26172
|
+
try {
|
|
26173
|
+
const probe = await getLoadedContextLength(config.provider.baseUrl, config.model);
|
|
26174
|
+
if (!probe)
|
|
26175
|
+
return null;
|
|
26176
|
+
if (probe.actual < config.contextWindow) {
|
|
26177
|
+
logger4.warn(`Context probe: model "${probe.model}" is loaded with ${probe.actual} tokens, but contextWindow is configured as ${config.contextWindow} — overflow/429 risk. Lower contextWindow or reload the model with a larger context.`);
|
|
26178
|
+
} else if (probe.actual > config.contextWindow) {
|
|
26179
|
+
logger4.info(`Context probe: model "${probe.model}" supports ${probe.actual} tokens — consider "mma context ${probe.actual}" to use the full window.`);
|
|
26180
|
+
} else {
|
|
26181
|
+
logger4.debug(`Context probe: configured contextWindow matches loaded context (${probe.actual})`);
|
|
26182
|
+
}
|
|
26183
|
+
return probe;
|
|
26184
|
+
} catch {
|
|
26185
|
+
return null;
|
|
26186
|
+
}
|
|
26187
|
+
})();
|
|
26188
|
+
const profile = new UserProfile(join46(dir));
|
|
25888
26189
|
profile.load() || profile.collect();
|
|
25889
26190
|
profile.save();
|
|
25890
26191
|
const llmProvider = buildActiveProvider(config, logger4).provider;
|
|
@@ -25918,7 +26219,7 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
25918
26219
|
for (const warning of envReport.warnings) {
|
|
25919
26220
|
logger4.warn(warning);
|
|
25920
26221
|
}
|
|
25921
|
-
const projectMapCacheDir =
|
|
26222
|
+
const projectMapCacheDir = join46(baseDir, ".mma");
|
|
25922
26223
|
const indexerModule = new IndexerModule({
|
|
25923
26224
|
baseDir,
|
|
25924
26225
|
cacheDir: projectMapCacheDir
|
|
@@ -25929,9 +26230,9 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
25929
26230
|
logger4.warn(`Project indexing failed: ${err.message}`);
|
|
25930
26231
|
}
|
|
25931
26232
|
const skillsLoader = new SkillsLoader;
|
|
25932
|
-
const builtinDir =
|
|
25933
|
-
const globalDir =
|
|
25934
|
-
const projectSkillsDir =
|
|
26233
|
+
const builtinDir = join46(import.meta.dirname, "skills", "builtin");
|
|
26234
|
+
const globalDir = join46(homedir15(), ".agents", "skills");
|
|
26235
|
+
const projectSkillsDir = join46(baseDir, ".mma", "skills");
|
|
25935
26236
|
const availableSkills = skillsLoader.loadFromAllSources(builtinDir, globalDir, projectSkillsDir);
|
|
25936
26237
|
const skillsBudget = Math.floor(config.contextWindow * config.skills.budget);
|
|
25937
26238
|
const skillsModule = new SkillsModule(availableSkills, skillsBudget);
|
|
@@ -25947,7 +26248,7 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
25947
26248
|
essential: true,
|
|
25948
26249
|
estimatedTokens: estimateTokens(systemInfoContent)
|
|
25949
26250
|
};
|
|
25950
|
-
const sessionDir =
|
|
26251
|
+
const sessionDir = join46(dir, "sessions");
|
|
25951
26252
|
const sessionStore = new SessionStore(sessionDir);
|
|
25952
26253
|
sessionStore.init();
|
|
25953
26254
|
const sessionManager = new SessionManager(sessionStore, {
|
|
@@ -26031,7 +26332,7 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
26031
26332
|
logger4.warn(`MCP init failed or timed out (${err instanceof Error ? err.message.slice(0, 120) : String(err)}) — continuing without MCP tools.`);
|
|
26032
26333
|
}
|
|
26033
26334
|
moduleRegistry.register(mcpModule);
|
|
26034
|
-
const memoryStore = new MemoryStore(
|
|
26335
|
+
const memoryStore = new MemoryStore(join46(dir, "memory"));
|
|
26035
26336
|
const memoryModule = new MemoryModule(memoryStore);
|
|
26036
26337
|
moduleRegistry.register(memoryModule);
|
|
26037
26338
|
if (config.browser.enabled) {
|
|
@@ -26058,8 +26359,8 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
26058
26359
|
pluginManager.register(plugin);
|
|
26059
26360
|
pluginManager.register(plugin2);
|
|
26060
26361
|
const pluginLoader = new PluginLoader;
|
|
26061
|
-
const globalPluginsDir =
|
|
26062
|
-
const projectPluginsDir =
|
|
26362
|
+
const globalPluginsDir = join46(homedir15(), ".mma", "plugins");
|
|
26363
|
+
const projectPluginsDir = join46(baseDir, ".mma", "plugins");
|
|
26063
26364
|
const mmaVersion = readMmaVersion();
|
|
26064
26365
|
pluginLoader.loadFromDir(globalPluginsDir, pluginManager, logger4, {
|
|
26065
26366
|
source: "global",
|
|
@@ -26093,6 +26394,34 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
26093
26394
|
estimatedTokens: 50
|
|
26094
26395
|
}
|
|
26095
26396
|
];
|
|
26397
|
+
{
|
|
26398
|
+
const dynamicBlocks = [];
|
|
26399
|
+
const skillsBlock = skillsModule.getSystemPromptBlock();
|
|
26400
|
+
if (skillsBlock)
|
|
26401
|
+
dynamicBlocks.push(skillsBlock);
|
|
26402
|
+
const mapBlock = indexerModule.getSystemPromptBlock();
|
|
26403
|
+
if (mapBlock)
|
|
26404
|
+
dynamicBlocks.push(mapBlock);
|
|
26405
|
+
const hiddenToolsBlock = buildHiddenToolsBlock(toolRegistry.getAll(), activeToolTags);
|
|
26406
|
+
if (hiddenToolsBlock) {
|
|
26407
|
+
dynamicBlocks.push({
|
|
26408
|
+
content: hiddenToolsBlock,
|
|
26409
|
+
priority: "low",
|
|
26410
|
+
essential: false,
|
|
26411
|
+
estimatedTokens: estimateTokens(hiddenToolsBlock)
|
|
26412
|
+
});
|
|
26413
|
+
}
|
|
26414
|
+
const systemBudget = Math.floor(config.contextWindow * config.contextBudget.systemPrompt);
|
|
26415
|
+
const dry = dryRunOverflow([...promptBlocks, ...dynamicBlocks], systemBudget);
|
|
26416
|
+
if (dry.overflow.length > 0) {
|
|
26417
|
+
const overflowTokens = dry.overflow.reduce((s, b) => s + b.estimatedTokens, 0);
|
|
26418
|
+
const recommended = recommendContextSize(dry.includedTokens + overflowTokens);
|
|
26419
|
+
const hint = contextWindowHint(config, dir, recommended);
|
|
26420
|
+
for (const b of dry.overflow) {
|
|
26421
|
+
logger4.warn(`Startup check: ${b.kind === "instructions" ? "AGENTS.md" : "project map"} (${b.estimatedTokens} tok) exceeds the system-prompt budget (${systemBudget} tok) — it will be summarized/truncated before the first run. To include it fully, ${hint}.`);
|
|
26422
|
+
}
|
|
26423
|
+
}
|
|
26424
|
+
}
|
|
26096
26425
|
const agentDeps = {
|
|
26097
26426
|
config,
|
|
26098
26427
|
configRef,
|
|
@@ -26103,6 +26432,7 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
26103
26432
|
hallucinationDetector,
|
|
26104
26433
|
logger: logger4,
|
|
26105
26434
|
baseDir,
|
|
26435
|
+
configDir: dir,
|
|
26106
26436
|
toolTags: activeToolTags,
|
|
26107
26437
|
promptBlocks,
|
|
26108
26438
|
envReport,
|
|
@@ -26159,7 +26489,8 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
26159
26489
|
baseDir,
|
|
26160
26490
|
noAgentsMd: noAgentsMd === true,
|
|
26161
26491
|
envReport,
|
|
26162
|
-
legacyDetected
|
|
26492
|
+
legacyDetected,
|
|
26493
|
+
contextProbe: contextProbePromise
|
|
26163
26494
|
};
|
|
26164
26495
|
}
|
|
26165
26496
|
var init_bootstrap = __esm(() => {
|
|
@@ -26192,6 +26523,7 @@ var init_bootstrap = __esm(() => {
|
|
|
26192
26523
|
init_agent();
|
|
26193
26524
|
init_version();
|
|
26194
26525
|
init_environment();
|
|
26526
|
+
init_prompt_overflow();
|
|
26195
26527
|
});
|
|
26196
26528
|
|
|
26197
26529
|
// node_modules/ansi-regex/index.js
|
|
@@ -34505,8 +34837,8 @@ var init_scenarios = __esm(() => {
|
|
|
34505
34837
|
});
|
|
34506
34838
|
|
|
34507
34839
|
// src/modules/certification/loader.ts
|
|
34508
|
-
import { existsSync as
|
|
34509
|
-
import { join as
|
|
34840
|
+
import { existsSync as existsSync54, readdirSync as readdirSync17, readFileSync as readFileSync36 } from "fs";
|
|
34841
|
+
import { join as join49 } from "path";
|
|
34510
34842
|
function validateScenario(s) {
|
|
34511
34843
|
const errors2 = [];
|
|
34512
34844
|
const isSkip = s.mode === "skip";
|
|
@@ -34558,12 +34890,12 @@ function loadScenarios(userDir) {
|
|
|
34558
34890
|
else
|
|
34559
34891
|
scenarios.push(s);
|
|
34560
34892
|
}
|
|
34561
|
-
if (userDir &&
|
|
34893
|
+
if (userDir && existsSync54(userDir)) {
|
|
34562
34894
|
for (const file of readdirSync17(userDir)) {
|
|
34563
34895
|
if (!file.endsWith(".yaml") && !file.endsWith(".yml"))
|
|
34564
34896
|
continue;
|
|
34565
34897
|
try {
|
|
34566
|
-
const raw =
|
|
34898
|
+
const raw = readFileSync36(join49(userDir, file), "utf-8");
|
|
34567
34899
|
const data = $parse(raw);
|
|
34568
34900
|
const parsed = normalizeScenario(data, file);
|
|
34569
34901
|
const errs = validateScenario(parsed);
|
|
@@ -34626,8 +34958,8 @@ var init_loader3 = __esm(() => {
|
|
|
34626
34958
|
});
|
|
34627
34959
|
|
|
34628
34960
|
// src/modules/certification/fact-checker.ts
|
|
34629
|
-
import { existsSync as
|
|
34630
|
-
import { join as
|
|
34961
|
+
import { existsSync as existsSync55, readFileSync as readFileSync37, statSync as statSync9 } from "fs";
|
|
34962
|
+
import { join as join50 } from "path";
|
|
34631
34963
|
function checkSandbox(sandboxDir, checks, exitCode, output) {
|
|
34632
34964
|
const failures = [];
|
|
34633
34965
|
for (const check of checks) {
|
|
@@ -34644,16 +34976,16 @@ function runCheck2(sandboxDir, check, exitCode, output) {
|
|
|
34644
34976
|
case "outputContains":
|
|
34645
34977
|
return output.includes(check.text);
|
|
34646
34978
|
case "fileExists":
|
|
34647
|
-
return isFile(
|
|
34979
|
+
return isFile(join50(sandboxDir, check.path));
|
|
34648
34980
|
case "fileNotExists":
|
|
34649
|
-
return !
|
|
34981
|
+
return !existsSync55(join50(sandboxDir, check.path));
|
|
34650
34982
|
case "dirExists":
|
|
34651
|
-
return isDir(
|
|
34983
|
+
return isDir(join50(sandboxDir, check.path));
|
|
34652
34984
|
case "fileContent": {
|
|
34653
|
-
const abs =
|
|
34985
|
+
const abs = join50(sandboxDir, check.path);
|
|
34654
34986
|
if (!isFile(abs))
|
|
34655
34987
|
return false;
|
|
34656
|
-
const content =
|
|
34988
|
+
const content = readFileSync37(abs, "utf-8");
|
|
34657
34989
|
if (check.contains !== undefined)
|
|
34658
34990
|
return content.includes(check.contains);
|
|
34659
34991
|
if (check.equals !== undefined)
|
|
@@ -34661,10 +34993,10 @@ function runCheck2(sandboxDir, check, exitCode, output) {
|
|
|
34661
34993
|
return false;
|
|
34662
34994
|
}
|
|
34663
34995
|
case "fileRegex": {
|
|
34664
|
-
const abs =
|
|
34996
|
+
const abs = join50(sandboxDir, check.path);
|
|
34665
34997
|
if (!isFile(abs))
|
|
34666
34998
|
return false;
|
|
34667
|
-
return new RegExp(check.pattern).test(
|
|
34999
|
+
return new RegExp(check.pattern).test(readFileSync37(abs, "utf-8"));
|
|
34668
35000
|
}
|
|
34669
35001
|
default:
|
|
34670
35002
|
return false;
|
|
@@ -34672,14 +35004,14 @@ function runCheck2(sandboxDir, check, exitCode, output) {
|
|
|
34672
35004
|
}
|
|
34673
35005
|
function isFile(p) {
|
|
34674
35006
|
try {
|
|
34675
|
-
return
|
|
35007
|
+
return existsSync55(p) && statSync9(p).isFile();
|
|
34676
35008
|
} catch {
|
|
34677
35009
|
return false;
|
|
34678
35010
|
}
|
|
34679
35011
|
}
|
|
34680
35012
|
function isDir(p) {
|
|
34681
35013
|
try {
|
|
34682
|
-
return
|
|
35014
|
+
return existsSync55(p) && statSync9(p).isDirectory();
|
|
34683
35015
|
} catch {
|
|
34684
35016
|
return false;
|
|
34685
35017
|
}
|
|
@@ -34710,8 +35042,8 @@ var init_fact_checker = () => {};
|
|
|
34710
35042
|
|
|
34711
35043
|
// src/modules/certification/runner.ts
|
|
34712
35044
|
import { spawn as spawn10 } from "child_process";
|
|
34713
|
-
import { existsSync as
|
|
34714
|
-
import { join as
|
|
35045
|
+
import { existsSync as existsSync56, mkdirSync as mkdirSync22, rmSync as rmSync4, cpSync as cpSync2, writeFileSync as writeFileSync22, readdirSync as readdirSync18, readFileSync as readFileSync38 } from "fs";
|
|
35046
|
+
import { join as join51, resolve as resolve23, dirname as dirname21, relative as relative7 } from "path";
|
|
34715
35047
|
async function runScenario(scenario, opts) {
|
|
34716
35048
|
if (scenario.mode === "skip") {
|
|
34717
35049
|
return {
|
|
@@ -34731,7 +35063,7 @@ async function runScenario(scenario, opts) {
|
|
|
34731
35063
|
let firstError;
|
|
34732
35064
|
let lastFailedSandbox;
|
|
34733
35065
|
for (let i = 1;i <= reps; i++) {
|
|
34734
|
-
const sandbox =
|
|
35066
|
+
const sandbox = join51(opts.sandboxBase, `run-${scenario.id}-${i}`);
|
|
34735
35067
|
let failures = [];
|
|
34736
35068
|
let exitCode = -1;
|
|
34737
35069
|
let output = "";
|
|
@@ -34755,9 +35087,9 @@ async function runScenario(scenario, opts) {
|
|
|
34755
35087
|
env3.MMA_PROVIDER_APIKEY = opts.providerKey;
|
|
34756
35088
|
if (scenario.config && opts.baseConfig) {
|
|
34757
35089
|
const merged = deepMergeAny(opts.baseConfig, scenario.config);
|
|
34758
|
-
const certConfigDir =
|
|
34759
|
-
|
|
34760
|
-
|
|
35090
|
+
const certConfigDir = join51(sandbox, ".mma");
|
|
35091
|
+
mkdirSync22(certConfigDir, { recursive: true });
|
|
35092
|
+
writeFileSync22(join51(certConfigDir, "config.json"), JSON.stringify(merged, null, 2), "utf-8");
|
|
34761
35093
|
env3.MMA_CONFIG_DIR = certConfigDir;
|
|
34762
35094
|
}
|
|
34763
35095
|
const res = await runner(env3, opts.mmaRoot, args, timeoutMs);
|
|
@@ -34802,14 +35134,14 @@ ${res.stderr}`;
|
|
|
34802
35134
|
}
|
|
34803
35135
|
function prepareSandbox(sandbox, scenario, mmaRoot) {
|
|
34804
35136
|
rmSync4(sandbox, { recursive: true, force: true });
|
|
34805
|
-
|
|
35137
|
+
mkdirSync22(sandbox, { recursive: true });
|
|
34806
35138
|
for (const f of scenario.fixtures ?? []) {
|
|
34807
|
-
const src =
|
|
34808
|
-
if (!
|
|
35139
|
+
const src = join51(mmaRoot, f.source);
|
|
35140
|
+
if (!existsSync56(src)) {
|
|
34809
35141
|
throw new Error(`fixture missing: ${f.source}`);
|
|
34810
35142
|
}
|
|
34811
|
-
const dest =
|
|
34812
|
-
|
|
35143
|
+
const dest = join51(sandbox, f.dest);
|
|
35144
|
+
mkdirSync22(dirname21(dest), { recursive: true });
|
|
34813
35145
|
cpSync2(src, dest);
|
|
34814
35146
|
}
|
|
34815
35147
|
}
|
|
@@ -34821,10 +35153,10 @@ function collectDiagnostics(sandbox) {
|
|
|
34821
35153
|
} else {
|
|
34822
35154
|
lines.push(" Files created: (none)");
|
|
34823
35155
|
}
|
|
34824
|
-
const planPath =
|
|
34825
|
-
if (
|
|
35156
|
+
const planPath = join51(sandbox, ".mma", "plans", "active.json");
|
|
35157
|
+
if (existsSync56(planPath)) {
|
|
34826
35158
|
try {
|
|
34827
|
-
const plan = JSON.parse(
|
|
35159
|
+
const plan = JSON.parse(readFileSync38(planPath, "utf-8"));
|
|
34828
35160
|
const steps = plan.steps ?? [];
|
|
34829
35161
|
const done = steps.filter((s) => s.status === "done").length;
|
|
34830
35162
|
const pending = steps.filter((s) => s.status === "pending" || s.status === "in_progress");
|
|
@@ -34843,7 +35175,7 @@ function listFiles(dir, root) {
|
|
|
34843
35175
|
for (const entry of readdirSync18(dir, { withFileTypes: true })) {
|
|
34844
35176
|
if (entry.name === ".mma")
|
|
34845
35177
|
continue;
|
|
34846
|
-
const abs =
|
|
35178
|
+
const abs = join51(dir, entry.name);
|
|
34847
35179
|
const rel = toForwardSlash(relative7(root, abs));
|
|
34848
35180
|
if (entry.isDirectory()) {
|
|
34849
35181
|
result.push(...listFiles(abs, root));
|
|
@@ -34855,15 +35187,15 @@ function listFiles(dir, root) {
|
|
|
34855
35187
|
return result;
|
|
34856
35188
|
}
|
|
34857
35189
|
function resolveMmaEntry(mmaRoot) {
|
|
34858
|
-
const dev =
|
|
34859
|
-
if (
|
|
35190
|
+
const dev = join51(mmaRoot, "src", "cli", "main.ts");
|
|
35191
|
+
if (existsSync56(dev))
|
|
34860
35192
|
return dev;
|
|
34861
|
-
return
|
|
35193
|
+
return join51(mmaRoot, "dist", "main.js");
|
|
34862
35194
|
}
|
|
34863
35195
|
function findMmaRoot(fromDir) {
|
|
34864
35196
|
const candidates = [resolve23(fromDir, "..", "..", ".."), resolve23(fromDir, "..")];
|
|
34865
35197
|
for (const c of candidates) {
|
|
34866
|
-
if (
|
|
35198
|
+
if (existsSync56(join51(c, "package.json")))
|
|
34867
35199
|
return c;
|
|
34868
35200
|
}
|
|
34869
35201
|
return process.cwd();
|
|
@@ -34930,16 +35262,16 @@ __export(exports_cli, {
|
|
|
34930
35262
|
certStatus: () => certStatus,
|
|
34931
35263
|
certList: () => certList
|
|
34932
35264
|
});
|
|
34933
|
-
import { rmSync as rmSync5, writeFileSync as
|
|
34934
|
-
import { join as
|
|
35265
|
+
import { rmSync as rmSync5, writeFileSync as writeFileSync23 } from "fs";
|
|
35266
|
+
import { join as join52, dirname as dirname22 } from "path";
|
|
34935
35267
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
34936
|
-
import { existsSync as
|
|
35268
|
+
import { existsSync as existsSync57, readFileSync as readFileSync39 } from "fs";
|
|
34937
35269
|
function readVersion() {
|
|
34938
|
-
const candidates = [
|
|
35270
|
+
const candidates = [join52(MMA_ROOT, "package.json")];
|
|
34939
35271
|
for (const p of candidates) {
|
|
34940
|
-
if (
|
|
35272
|
+
if (existsSync57(p)) {
|
|
34941
35273
|
try {
|
|
34942
|
-
const raw = JSON.parse(
|
|
35274
|
+
const raw = JSON.parse(readFileSync39(p, "utf-8"));
|
|
34943
35275
|
if (raw.version)
|
|
34944
35276
|
return raw.version;
|
|
34945
35277
|
} catch {}
|
|
@@ -34952,7 +35284,7 @@ function parseTags(s) {
|
|
|
34952
35284
|
}
|
|
34953
35285
|
async function certify(opts) {
|
|
34954
35286
|
const providerUrl = opts.providerUrl || opts.config.provider.baseUrl;
|
|
34955
|
-
const { scenarios, errors: errors2 } = loadScenarios(
|
|
35287
|
+
const { scenarios, errors: errors2 } = loadScenarios(join52(opts.projectDir, ".mma", "certification", "scenarios"));
|
|
34956
35288
|
for (const e of errors2)
|
|
34957
35289
|
console.error(pc2.yellow(` ${e}`));
|
|
34958
35290
|
let selected = filterByTags(scenarios, opts.tags);
|
|
@@ -34983,7 +35315,7 @@ async function certify(opts) {
|
|
|
34983
35315
|
return;
|
|
34984
35316
|
}
|
|
34985
35317
|
console.log(t("cli.cert_started", { model: opts.name, provider: providerUrl }));
|
|
34986
|
-
const sandboxBase =
|
|
35318
|
+
const sandboxBase = join52(process.cwd(), ".mma", "certification");
|
|
34987
35319
|
const results = [];
|
|
34988
35320
|
const total = selected.length;
|
|
34989
35321
|
let idx = 0;
|
|
@@ -35116,10 +35448,10 @@ function printResults(results) {
|
|
|
35116
35448
|
}
|
|
35117
35449
|
}
|
|
35118
35450
|
function writeReport(entry, projectDir) {
|
|
35119
|
-
const reportDir =
|
|
35451
|
+
const reportDir = join52(projectDir, "certification");
|
|
35120
35452
|
const ts = entry.certifiedAt.replace(/[:.]/g, "-").slice(0, 19);
|
|
35121
35453
|
const filename = `report-${entry.model.replace(/[/\\:]/g, "_")}-${ts}.json`;
|
|
35122
|
-
const reportPath =
|
|
35454
|
+
const reportPath = join52(reportDir, filename);
|
|
35123
35455
|
const report = {
|
|
35124
35456
|
model: entry.model,
|
|
35125
35457
|
providerUrl: entry.providerUrl,
|
|
@@ -35138,7 +35470,7 @@ function writeReport(entry, projectDir) {
|
|
|
35138
35470
|
}))
|
|
35139
35471
|
};
|
|
35140
35472
|
try {
|
|
35141
|
-
|
|
35473
|
+
writeFileSync23(reportPath, JSON.stringify(report, null, 2), "utf-8");
|
|
35142
35474
|
console.log(pc2.dim(`
|
|
35143
35475
|
Report: ${reportPath}`));
|
|
35144
35476
|
} catch (e) {
|
|
@@ -35162,8 +35494,8 @@ __export(exports_repl_commands, {
|
|
|
35162
35494
|
registerAllCommands: () => registerAllCommands,
|
|
35163
35495
|
COMMAND_GROUPS: () => COMMAND_GROUPS
|
|
35164
35496
|
});
|
|
35165
|
-
import { join as
|
|
35166
|
-
import { existsSync as
|
|
35497
|
+
import { join as join54, dirname as dirname24 } from "path";
|
|
35498
|
+
import { existsSync as existsSync59 } from "fs";
|
|
35167
35499
|
function registerAllCommands(ctx) {
|
|
35168
35500
|
registerBuiltinCommands(ctx);
|
|
35169
35501
|
registerMmaCommands(ctx);
|
|
@@ -35220,7 +35552,7 @@ function registerRunCommands(ctx) {
|
|
|
35220
35552
|
}
|
|
35221
35553
|
try {
|
|
35222
35554
|
const { loadFileAsDataUrl: loadFileAsDataUrl2, loadUrlAsDataUrl: loadUrlAsDataUrl2, readClipboardImage: readClipboardImage2 } = await Promise.resolve().then(() => (init_image_utils(), exports_image_utils));
|
|
35223
|
-
const { existsSync:
|
|
35555
|
+
const { existsSync: existsSync60 } = await import("fs");
|
|
35224
35556
|
const { resolve: resolve24 } = await import("path");
|
|
35225
35557
|
let dataUrl;
|
|
35226
35558
|
let label;
|
|
@@ -35240,7 +35572,7 @@ function registerRunCommands(ctx) {
|
|
|
35240
35572
|
label = source;
|
|
35241
35573
|
} else {
|
|
35242
35574
|
const absPath = resolve24(process.cwd(), source);
|
|
35243
|
-
if (!
|
|
35575
|
+
if (!existsSync60(absPath)) {
|
|
35244
35576
|
console.log(pc2.red(t("image.not_found", { path: source })));
|
|
35245
35577
|
return;
|
|
35246
35578
|
}
|
|
@@ -35345,7 +35677,7 @@ function registerConfigCommands(ctx) {
|
|
|
35345
35677
|
console.log(pc2.yellow(t("repl.wizard_running")));
|
|
35346
35678
|
await ctx.withExclusiveInput(async () => {
|
|
35347
35679
|
const answers = await runSetup(ctx.rl);
|
|
35348
|
-
const configPath =
|
|
35680
|
+
const configPath = join54(ctx.configDir, "config.json");
|
|
35349
35681
|
ctx.config.provider.type = answers.provider;
|
|
35350
35682
|
ctx.config.provider.baseUrl = answers.apiBase;
|
|
35351
35683
|
ctx.config.provider.apiKey = answers.apiKey;
|
|
@@ -35469,7 +35801,7 @@ function registerProviderCommands(ctx) {
|
|
|
35469
35801
|
return;
|
|
35470
35802
|
}
|
|
35471
35803
|
ctx.config.model = name;
|
|
35472
|
-
const configPath =
|
|
35804
|
+
const configPath = join54(ctx.configDir, "config.json");
|
|
35473
35805
|
saveConfig(ctx.config, configPath, dirname24(configPath));
|
|
35474
35806
|
await ctx.agent.reconfigure(ctx.config);
|
|
35475
35807
|
console.log(pc2.green(t("repl.model_set", { name })));
|
|
@@ -35494,7 +35826,7 @@ function registerProviderCommands(ctx) {
|
|
|
35494
35826
|
return;
|
|
35495
35827
|
}
|
|
35496
35828
|
ctx.config.contextWindow = size;
|
|
35497
|
-
const configPath =
|
|
35829
|
+
const configPath = join54(ctx.configDir, "config.json");
|
|
35498
35830
|
saveConfig(ctx.config, configPath, dirname24(configPath));
|
|
35499
35831
|
await ctx.agent.reconfigure(ctx.config);
|
|
35500
35832
|
console.log(pc2.green(t("cli.context_set", { size })));
|
|
@@ -35858,21 +36190,21 @@ async function runConfigMigrate(ctx) {
|
|
|
35858
36190
|
const { hasDomainFiles: hasDomainFiles3 } = await Promise.resolve().then(() => (init_domains(), exports_domains));
|
|
35859
36191
|
const { loadConfig: loadCfg } = await Promise.resolve().then(() => (init_config2(), exports_config));
|
|
35860
36192
|
const configDir = ctx.configDir;
|
|
35861
|
-
const configPath =
|
|
36193
|
+
const configPath = join54(configDir, "config.json");
|
|
35862
36194
|
if (hasDomainFiles3(configDir)) {
|
|
35863
36195
|
console.log(pc2.yellow(t("config.migrate_no_legacy")));
|
|
35864
36196
|
return;
|
|
35865
36197
|
}
|
|
35866
|
-
if (!
|
|
36198
|
+
if (!existsSync59(configPath)) {
|
|
35867
36199
|
console.log(pc2.yellow(t("config.migrate_no_legacy")));
|
|
35868
36200
|
return;
|
|
35869
36201
|
}
|
|
35870
36202
|
console.log(t("config.migrate_start"));
|
|
35871
|
-
const { config } = loadCfg({ configDir, projectConfigPath:
|
|
36203
|
+
const { config } = loadCfg({ configDir, projectConfigPath: join54(configDir, ".mmrc") });
|
|
35872
36204
|
saveConfig(config, configPath, configDir);
|
|
35873
36205
|
const { renameSync: renameSync4, readdirSync: readdirSync19 } = await import("fs");
|
|
35874
36206
|
renameSync4(configPath, configPath + ".bak");
|
|
35875
|
-
const domainFiles = readdirSync19(
|
|
36207
|
+
const domainFiles = readdirSync19(join54(configDir, "config")).filter((f) => f.endsWith(".json"));
|
|
35876
36208
|
console.log(pc2.green(t("config.migrate_done", { count: String(domainFiles.length) })));
|
|
35877
36209
|
}
|
|
35878
36210
|
var version2, COMMAND_GROUPS;
|
|
@@ -35934,14 +36266,14 @@ init_config2();
|
|
|
35934
36266
|
init_setup();
|
|
35935
36267
|
init_i18n();
|
|
35936
36268
|
init_colors();
|
|
35937
|
-
import { join as
|
|
36269
|
+
import { join as join53, dirname as dirname23 } from "path";
|
|
35938
36270
|
import { homedir as homedir17 } from "os";
|
|
35939
|
-
import { existsSync as
|
|
36271
|
+
import { existsSync as existsSync58 } from "fs";
|
|
35940
36272
|
|
|
35941
36273
|
// src/cli/security-commands.ts
|
|
35942
36274
|
init_bootstrap();
|
|
35943
36275
|
init_config2();
|
|
35944
|
-
import { join as
|
|
36276
|
+
import { join as join47, dirname as dirname19 } from "path";
|
|
35945
36277
|
import { homedir as homedir16 } from "os";
|
|
35946
36278
|
|
|
35947
36279
|
// src/modules/security/security-policies.ts
|
|
@@ -36467,7 +36799,7 @@ function createSecurityCommand(program2) {
|
|
|
36467
36799
|
}
|
|
36468
36800
|
});
|
|
36469
36801
|
securityCmd.command("set-policy").argument("<preset>", t("cli.security.preset")).description(t("cli.security.set_policy")).action(async (preset) => {
|
|
36470
|
-
const configPath =
|
|
36802
|
+
const configPath = join47(homedir16(), ".mma", "config.json");
|
|
36471
36803
|
const { config: appConfig } = await bootstrap();
|
|
36472
36804
|
const validPresets = ["strict", "balanced", "permissive"];
|
|
36473
36805
|
if (!validPresets.includes(preset)) {
|
|
@@ -36482,7 +36814,7 @@ function createSecurityCommand(program2) {
|
|
|
36482
36814
|
console.log(t("cli.security.policy_description", { description: policy.description }));
|
|
36483
36815
|
});
|
|
36484
36816
|
securityCmd.command("enable-encryption").description(t("cli.security.enable_encryption")).action(async () => {
|
|
36485
|
-
const configPath =
|
|
36817
|
+
const configPath = join47(homedir16(), ".mma", "config.json");
|
|
36486
36818
|
const { config: appConfig } = await bootstrap();
|
|
36487
36819
|
const security = appConfig.security = appConfig.security || {};
|
|
36488
36820
|
toggleSessionEncryption(security, true);
|
|
@@ -36490,7 +36822,7 @@ function createSecurityCommand(program2) {
|
|
|
36490
36822
|
console.log(t("cli.security.encryption_enabled"));
|
|
36491
36823
|
});
|
|
36492
36824
|
securityCmd.command("disable-encryption").description(t("cli.security.disable_encryption")).action(async () => {
|
|
36493
|
-
const configPath =
|
|
36825
|
+
const configPath = join47(homedir16(), ".mma", "config.json");
|
|
36494
36826
|
const { config: appConfig } = await bootstrap();
|
|
36495
36827
|
const security = appConfig.security = appConfig.security || {};
|
|
36496
36828
|
toggleSessionEncryption(security, false);
|
|
@@ -36498,7 +36830,7 @@ function createSecurityCommand(program2) {
|
|
|
36498
36830
|
console.log(t("cli.security.encryption_disabled"));
|
|
36499
36831
|
});
|
|
36500
36832
|
securityCmd.command("enable-audit").description(t("cli.security.enable_audit")).action(async () => {
|
|
36501
|
-
const configPath =
|
|
36833
|
+
const configPath = join47(homedir16(), ".mma", "config.json");
|
|
36502
36834
|
const { config: appConfig } = await bootstrap();
|
|
36503
36835
|
const security = appConfig.security = appConfig.security || {};
|
|
36504
36836
|
toggleAuditNotifier(security, true);
|
|
@@ -36506,7 +36838,7 @@ function createSecurityCommand(program2) {
|
|
|
36506
36838
|
console.log(t("cli.security.audit_enabled"));
|
|
36507
36839
|
});
|
|
36508
36840
|
securityCmd.command("disable-audit").description(t("cli.security.disable_audit")).action(async () => {
|
|
36509
|
-
const configPath =
|
|
36841
|
+
const configPath = join47(homedir16(), ".mma", "config.json");
|
|
36510
36842
|
const { config: appConfig } = await bootstrap();
|
|
36511
36843
|
const security = appConfig.security = appConfig.security || {};
|
|
36512
36844
|
toggleAuditNotifier(security, false);
|
|
@@ -36613,8 +36945,8 @@ function targetsFromProviders(entries) {
|
|
|
36613
36945
|
init_version();
|
|
36614
36946
|
|
|
36615
36947
|
// src/modules/updater/changelog-reader.ts
|
|
36616
|
-
import { readFileSync as
|
|
36617
|
-
import { dirname as dirname20, join as
|
|
36948
|
+
import { readFileSync as readFileSync35, existsSync as existsSync53 } from "fs";
|
|
36949
|
+
import { dirname as dirname20, join as join48 } from "path";
|
|
36618
36950
|
function readChangelog(packageName) {
|
|
36619
36951
|
try {
|
|
36620
36952
|
let dir = dirname20(import.meta.url);
|
|
@@ -36622,13 +36954,13 @@ function readChangelog(packageName) {
|
|
|
36622
36954
|
dir = decodeURIComponent(dir.slice(7));
|
|
36623
36955
|
}
|
|
36624
36956
|
for (let i = 0;i < 10; i++) {
|
|
36625
|
-
const pkgPath =
|
|
36626
|
-
if (
|
|
36627
|
-
const pkg = JSON.parse(
|
|
36957
|
+
const pkgPath = join48(dir, "package.json");
|
|
36958
|
+
if (existsSync53(pkgPath)) {
|
|
36959
|
+
const pkg = JSON.parse(readFileSync35(pkgPath, "utf-8"));
|
|
36628
36960
|
if (pkg.name === packageName) {
|
|
36629
|
-
const changelogPath =
|
|
36630
|
-
if (
|
|
36631
|
-
return
|
|
36961
|
+
const changelogPath = join48(dir, "CHANGELOG.md");
|
|
36962
|
+
if (existsSync53(changelogPath)) {
|
|
36963
|
+
return readFileSync35(changelogPath, "utf-8");
|
|
36632
36964
|
}
|
|
36633
36965
|
return null;
|
|
36634
36966
|
}
|
|
@@ -36695,7 +37027,7 @@ var version = readMmaVersion();
|
|
|
36695
37027
|
function buildInitCommand(program2) {
|
|
36696
37028
|
program2.command("init").description(t("cli.init")).action(async () => {
|
|
36697
37029
|
const answers = await runSetup();
|
|
36698
|
-
const configPath =
|
|
37030
|
+
const configPath = join53(homedir17(), ".mma", "config.json");
|
|
36699
37031
|
const { config } = await bootstrap();
|
|
36700
37032
|
config.provider.type = answers.provider;
|
|
36701
37033
|
config.provider.baseUrl = answers.apiBase;
|
|
@@ -36742,7 +37074,7 @@ function buildInitCommand(program2) {
|
|
|
36742
37074
|
function buildConfigCommands(program2) {
|
|
36743
37075
|
const configCmd = program2.command("config").description(t("cli.manage_config"));
|
|
36744
37076
|
configCmd.command("set").argument("<key>", t("cli.config_key")).argument("<value>", "Config value").description(t("cli.set_value")).action(async (key, value) => {
|
|
36745
|
-
const configPath =
|
|
37077
|
+
const configPath = join53(homedir17(), ".mma", "config.json");
|
|
36746
37078
|
const { config } = await bootstrap();
|
|
36747
37079
|
const keys = key.split(".");
|
|
36748
37080
|
let obj = config;
|
|
@@ -36772,24 +37104,24 @@ function buildConfigCommands(program2) {
|
|
|
36772
37104
|
configCmd.command("migrate").description(t("cli.migrate_config")).action(async () => {
|
|
36773
37105
|
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_config2(), exports_config));
|
|
36774
37106
|
const { hasDomainFiles: hasDomainFiles3 } = await Promise.resolve().then(() => (init_domains(), exports_domains));
|
|
36775
|
-
const configDir =
|
|
36776
|
-
const configPath =
|
|
37107
|
+
const configDir = join53(homedir17(), ".mma");
|
|
37108
|
+
const configPath = join53(configDir, "config.json");
|
|
36777
37109
|
if (hasDomainFiles3(configDir)) {
|
|
36778
37110
|
console.log(pc2.yellow(t("config.migrate_no_legacy")));
|
|
36779
37111
|
return;
|
|
36780
37112
|
}
|
|
36781
|
-
if (!
|
|
37113
|
+
if (!existsSync58(configPath)) {
|
|
36782
37114
|
console.log(pc2.yellow(t("config.migrate_no_legacy")));
|
|
36783
37115
|
return;
|
|
36784
37116
|
}
|
|
36785
37117
|
console.log(t("config.migrate_start"));
|
|
36786
|
-
const { config } = loadConfig2({ configDir, projectConfigPath:
|
|
37118
|
+
const { config } = loadConfig2({ configDir, projectConfigPath: join53(configDir, ".mmrc") });
|
|
36787
37119
|
saveConfig(config, configPath, configDir);
|
|
36788
37120
|
const bakPath = configPath + ".bak";
|
|
36789
37121
|
const { renameSync: renameSync4 } = await import("fs");
|
|
36790
37122
|
renameSync4(configPath, bakPath);
|
|
36791
37123
|
const { readdirSync: readdirSync19 } = await import("fs");
|
|
36792
|
-
const domainFiles = readdirSync19(
|
|
37124
|
+
const domainFiles = readdirSync19(join53(configDir, "config")).filter((f) => f.endsWith(".json"));
|
|
36793
37125
|
console.log(pc2.green(t("config.migrate_done", { count: String(domainFiles.length) })));
|
|
36794
37126
|
});
|
|
36795
37127
|
}
|
|
@@ -36831,7 +37163,7 @@ function buildModelCommands(program2) {
|
|
|
36831
37163
|
console.log(t("cli.model_hint"));
|
|
36832
37164
|
});
|
|
36833
37165
|
model.command("use").argument("<name>", "Model name").description(t("cli.set_model")).action(async (name) => {
|
|
36834
|
-
const configPath =
|
|
37166
|
+
const configPath = join53(homedir17(), ".mma", "config.json");
|
|
36835
37167
|
const { config } = await bootstrap();
|
|
36836
37168
|
config.model = name;
|
|
36837
37169
|
saveConfig(config, configPath, dirname23(configPath));
|
|
@@ -36872,7 +37204,7 @@ function buildModelCommands(program2) {
|
|
|
36872
37204
|
}
|
|
36873
37205
|
function buildContextCommand(program2) {
|
|
36874
37206
|
program2.command("context").description(t("cli.manage_context")).argument("<size>", "Context window size in tokens").action(async (size) => {
|
|
36875
|
-
const configPath =
|
|
37207
|
+
const configPath = join53(homedir17(), ".mma", "config.json");
|
|
36876
37208
|
const { config } = await bootstrap();
|
|
36877
37209
|
const contextWindow = parseInt(size, 10);
|
|
36878
37210
|
if (isNaN(contextWindow) || contextWindow < 1024) {
|
|
@@ -36920,7 +37252,7 @@ function buildProviderCommands(program2) {
|
|
|
36920
37252
|
console.log(t("cli.base_url"), config.provider.baseUrl);
|
|
36921
37253
|
});
|
|
36922
37254
|
provider.command("use").argument("<name>", "Provider name").description(t("cli.set_provider")).action(async (name) => {
|
|
36923
|
-
const configPath =
|
|
37255
|
+
const configPath = join53(homedir17(), ".mma", "config.json");
|
|
36924
37256
|
const { config, agent } = await bootstrap();
|
|
36925
37257
|
if (config.provider.entries && config.provider.entries.length > 0) {
|
|
36926
37258
|
try {
|
|
@@ -36943,7 +37275,7 @@ function buildProviderCommands(program2) {
|
|
|
36943
37275
|
}
|
|
36944
37276
|
});
|
|
36945
37277
|
provider.command("add").argument("<name>", "Provider type or label").option("--url <url>", "Base URL").option("--key <key>", "API key").option("--priority <n>", "Fallback priority (lower = tried first)").option("--context-window <n>", "Context window override for this entry").option("--rpm <n>", "Max requests per minute for this entry").option("--parallel <n>", "Max parallel tasks for this entry").description(t("cli.add_provider")).action(async (name, opts) => {
|
|
36946
|
-
const configPath =
|
|
37278
|
+
const configPath = join53(homedir17(), ".mma", "config.json");
|
|
36947
37279
|
const { config } = await bootstrap();
|
|
36948
37280
|
const entries = Array.isArray(config.provider.entries) ? config.provider.entries : [];
|
|
36949
37281
|
if (entries.length === 0) {
|
|
@@ -37954,8 +38286,8 @@ class LineEditor {
|
|
|
37954
38286
|
}
|
|
37955
38287
|
|
|
37956
38288
|
// src/cli/repl.ts
|
|
37957
|
-
import { existsSync as
|
|
37958
|
-
import { join as
|
|
38289
|
+
import { existsSync as existsSync60, readFileSync as readFileSync41, writeFileSync as writeFileSync24 } from "fs";
|
|
38290
|
+
import { join as join55 } from "path";
|
|
37959
38291
|
import { homedir as homedir18 } from "os";
|
|
37960
38292
|
|
|
37961
38293
|
// src/cli/completer.ts
|
|
@@ -38776,7 +39108,8 @@ class Repl {
|
|
|
38776
39108
|
logger;
|
|
38777
39109
|
slog;
|
|
38778
39110
|
envReport;
|
|
38779
|
-
|
|
39111
|
+
contextProbe;
|
|
39112
|
+
constructor(agent, config, sessionManager, skillsModule, pluginManager, configDir, baseDir, noAgentsMd, logger4, exitOnClose, envReport, historyPath, execModule, contextProbe) {
|
|
38780
39113
|
this.agent = agent;
|
|
38781
39114
|
this.config = config;
|
|
38782
39115
|
this.exitOnClose = exitOnClose === true;
|
|
@@ -38785,12 +39118,13 @@ class Repl {
|
|
|
38785
39118
|
this.pluginManager = pluginManager;
|
|
38786
39119
|
this.logger = logger4;
|
|
38787
39120
|
this.envReport = envReport;
|
|
39121
|
+
this.contextProbe = contextProbe;
|
|
38788
39122
|
this.execModule = execModule;
|
|
38789
39123
|
this.slog = new SessionLogger(sessionManager, logger4);
|
|
38790
|
-
this.configDir = configDir ||
|
|
39124
|
+
this.configDir = configDir || join55(homedir18(), ".mma");
|
|
38791
39125
|
this.baseDir = baseDir || process.cwd();
|
|
38792
39126
|
this.noAgentsMd = noAgentsMd === true;
|
|
38793
|
-
this.historyPath = historyPath ??
|
|
39127
|
+
this.historyPath = historyPath ?? join55(homedir18(), ".mma", "repl-history");
|
|
38794
39128
|
this.loadHistory();
|
|
38795
39129
|
this.rl = process.stdin.isTTY ? new LineEditor({
|
|
38796
39130
|
input: process.stdin,
|
|
@@ -38845,7 +39179,7 @@ class Repl {
|
|
|
38845
39179
|
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_config2(), exports_config));
|
|
38846
39180
|
const { bootstrap: bootstrap2 } = await Promise.resolve().then(() => (init_bootstrap(), exports_bootstrap));
|
|
38847
39181
|
this.agent.shutdown();
|
|
38848
|
-
const projectConfigPath =
|
|
39182
|
+
const projectConfigPath = join55(this.baseDir, ".mmrc");
|
|
38849
39183
|
const { config: freshConfig } = loadConfig2({
|
|
38850
39184
|
configDir: this.configDir,
|
|
38851
39185
|
projectConfigPath
|
|
@@ -38861,9 +39195,9 @@ class Repl {
|
|
|
38861
39195
|
this.setupCompleter();
|
|
38862
39196
|
}
|
|
38863
39197
|
loadHistory() {
|
|
38864
|
-
if (
|
|
39198
|
+
if (existsSync60(this.historyPath)) {
|
|
38865
39199
|
try {
|
|
38866
|
-
const raw =
|
|
39200
|
+
const raw = readFileSync41(this.historyPath, "utf-8");
|
|
38867
39201
|
this.history = raw.split(`
|
|
38868
39202
|
`).filter(Boolean).slice(-this.maxHistory);
|
|
38869
39203
|
} catch {
|
|
@@ -38873,7 +39207,7 @@ class Repl {
|
|
|
38873
39207
|
}
|
|
38874
39208
|
saveHistory() {
|
|
38875
39209
|
const allHistory = this.history.slice(-this.maxHistory);
|
|
38876
|
-
|
|
39210
|
+
writeFileSync24(this.historyPath, allHistory.join(`
|
|
38877
39211
|
`), "utf-8");
|
|
38878
39212
|
}
|
|
38879
39213
|
setupCompleter() {
|
|
@@ -39264,11 +39598,11 @@ ${t("image.clipboard_empty")}`));
|
|
|
39264
39598
|
row(t("repl.agents_label"), pc2.red(t("repl.disabled")));
|
|
39265
39599
|
} else {
|
|
39266
39600
|
const agentsMdCandidates = [
|
|
39267
|
-
|
|
39268
|
-
|
|
39269
|
-
|
|
39601
|
+
join55(this.baseDir, "AGENTS.md"),
|
|
39602
|
+
join55(this.baseDir, ".mma", "AGENTS.md"),
|
|
39603
|
+
join55(this.configDir, "AGENTS.md")
|
|
39270
39604
|
];
|
|
39271
|
-
const foundAgents = agentsMdCandidates.filter((p) =>
|
|
39605
|
+
const foundAgents = agentsMdCandidates.filter((p) => existsSync60(p));
|
|
39272
39606
|
if (foundAgents.length > 0) {
|
|
39273
39607
|
for (const p of foundAgents) {
|
|
39274
39608
|
row(t("repl.agents_label"), pc2.dim(p));
|
|
@@ -39279,7 +39613,7 @@ ${t("image.clipboard_empty")}`));
|
|
|
39279
39613
|
}
|
|
39280
39614
|
const meta = this.sessionManager?.getActiveMeta();
|
|
39281
39615
|
if (meta) {
|
|
39282
|
-
const sessionPath =
|
|
39616
|
+
const sessionPath = join55(this.configDir, "sessions", meta.id);
|
|
39283
39617
|
row(t("repl.session_label"), `${pc2.cyan(meta.name)} ${pc2.dim(`(${meta.id.slice(0, 12)})`)} — ${meta.messageCount} msgs ${pc2.dim(sessionPath)}`);
|
|
39284
39618
|
}
|
|
39285
39619
|
const isTty2 = process.stdout.isTTY === true;
|
|
@@ -39322,6 +39656,24 @@ ${line}
|
|
|
39322
39656
|
}
|
|
39323
39657
|
}).catch(() => {});
|
|
39324
39658
|
}
|
|
39659
|
+
if (this.contextProbe) {
|
|
39660
|
+
this.contextProbe.then((probe) => {
|
|
39661
|
+
if (!probe)
|
|
39662
|
+
return;
|
|
39663
|
+
this.sessionManager?.appendLog({
|
|
39664
|
+
ts: new Date().toISOString(),
|
|
39665
|
+
type: "context_probe",
|
|
39666
|
+
content: `model=${probe.model} actual=${probe.actual} configured=${this.config.contextWindow}`
|
|
39667
|
+
});
|
|
39668
|
+
const line = probe.actual < this.config.contextWindow ? `${pc2.yellow("⚠")} ${t("repl.context_probe_small", { model: probe.model, actual: probe.actual, configured: this.config.contextWindow })}` : probe.actual > this.config.contextWindow ? `${pc2.dim(t("repl.context_probe_big", { model: probe.model, actual: probe.actual }))}` : null;
|
|
39669
|
+
if (line) {
|
|
39670
|
+
process.stdout.write(`\x1B[2K\r${divider()}
|
|
39671
|
+
${line}
|
|
39672
|
+
`);
|
|
39673
|
+
this.rl.prompt();
|
|
39674
|
+
}
|
|
39675
|
+
}).catch(() => {});
|
|
39676
|
+
}
|
|
39325
39677
|
}
|
|
39326
39678
|
async probeLspBanner() {
|
|
39327
39679
|
const config = this.config.lsp ?? DEFAULT_LSP_CONFIG;
|
|
@@ -39394,8 +39746,8 @@ init_setup();
|
|
|
39394
39746
|
init_config2();
|
|
39395
39747
|
init_i18n();
|
|
39396
39748
|
init_colors();
|
|
39397
|
-
import { existsSync as
|
|
39398
|
-
import { join as
|
|
39749
|
+
import { existsSync as existsSync61 } from "fs";
|
|
39750
|
+
import { join as join57, dirname as dirname25 } from "path";
|
|
39399
39751
|
import { homedir as homedir20 } from "os";
|
|
39400
39752
|
|
|
39401
39753
|
// src/modules/updater/index.ts
|
|
@@ -39509,10 +39861,10 @@ init_environment();
|
|
|
39509
39861
|
init_data_sanitizer();
|
|
39510
39862
|
init_i18n();
|
|
39511
39863
|
init_utils();
|
|
39512
|
-
import { appendFileSync as appendFileSync7, mkdirSync as
|
|
39513
|
-
import { join as
|
|
39864
|
+
import { appendFileSync as appendFileSync7, mkdirSync as mkdirSync23 } from "fs";
|
|
39865
|
+
import { join as join56 } from "path";
|
|
39514
39866
|
import { homedir as homedir19 } from "os";
|
|
39515
|
-
var CRASH_LOG_DIR =
|
|
39867
|
+
var CRASH_LOG_DIR = join56(homedir19(), ".mma", "logs");
|
|
39516
39868
|
var CRASH_LOG_FILE = "crash.jsonl";
|
|
39517
39869
|
function formatCrashEntry(type2, err) {
|
|
39518
39870
|
const message = errMsg(err);
|
|
@@ -39527,8 +39879,8 @@ function formatCrashEntry(type2, err) {
|
|
|
39527
39879
|
}
|
|
39528
39880
|
function writeCrashEntry(dir, entry) {
|
|
39529
39881
|
try {
|
|
39530
|
-
|
|
39531
|
-
appendFileSync7(
|
|
39882
|
+
mkdirSync23(dir, { recursive: true });
|
|
39883
|
+
appendFileSync7(join56(dir, CRASH_LOG_FILE), JSON.stringify(entry) + `
|
|
39532
39884
|
`, "utf-8");
|
|
39533
39885
|
} catch {}
|
|
39534
39886
|
}
|
|
@@ -39705,9 +40057,9 @@ async function main() {
|
|
|
39705
40057
|
await updater?.waitForIdle();
|
|
39706
40058
|
process.exit(exitCode);
|
|
39707
40059
|
} else {
|
|
39708
|
-
const mmaDir = process.env.MMA_CONFIG_DIR ||
|
|
39709
|
-
const legacyConfigPath =
|
|
39710
|
-
let hasAnyConfig =
|
|
40060
|
+
const mmaDir = process.env.MMA_CONFIG_DIR || join57(homedir20(), ".mma");
|
|
40061
|
+
const legacyConfigPath = join57(mmaDir, "config.json");
|
|
40062
|
+
let hasAnyConfig = existsSync61(legacyConfigPath);
|
|
39711
40063
|
if (!hasAnyConfig) {
|
|
39712
40064
|
try {
|
|
39713
40065
|
const { hasDomainFiles: hasDomainFiles3 } = await Promise.resolve().then(() => (init_domains(), exports_domains));
|
|
@@ -39724,9 +40076,10 @@ async function main() {
|
|
|
39724
40076
|
configDir,
|
|
39725
40077
|
baseDir,
|
|
39726
40078
|
logger: logger4,
|
|
39727
|
-
envReport
|
|
40079
|
+
envReport,
|
|
40080
|
+
contextProbe
|
|
39728
40081
|
} = await bootstrap(undefined, projectDir, noAgentsMd, exitOnComplete, reasoningLevel);
|
|
39729
|
-
const repl = new Repl(agent, config, sessionManager, skillsModule, pluginManager, configDir, baseDir, noAgentsMd, logger4, true, envReport, undefined, execModule);
|
|
40082
|
+
const repl = new Repl(agent, config, sessionManager, skillsModule, pluginManager, configDir, baseDir, noAgentsMd, logger4, true, envReport, undefined, execModule, contextProbe);
|
|
39730
40083
|
if (!hasAnyConfig && !exitOnComplete) {
|
|
39731
40084
|
console.log(pc2.yellow(`
|
|
39732
40085
|
` + t("cli.first_run") + `
|