micro-models-agent 0.60.1 → 0.61.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +601 -584
- package/README.md +358 -358
- package/dist/certification/certifications.json +493 -493
- package/dist/cli/commands.js +447 -0
- package/dist/cli/completer.js +167 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/main.js +153 -0
- package/dist/cli/plugin-commands.js +36 -0
- package/dist/cli/repl-commands.js +761 -0
- package/dist/cli/repl.js +702 -0
- package/dist/cli/run-result.js +33 -0
- package/dist/cli/security-commands.js +164 -0
- package/dist/cli/setup.js +237 -0
- package/dist/config/config.js +276 -0
- package/dist/config/defaults.js +141 -0
- package/dist/config/domains.js +179 -0
- package/dist/config/experts.js +15 -0
- package/dist/config/index.js +4 -0
- package/dist/config/security.js +213 -0
- package/dist/config/types.js +1 -0
- package/dist/core/agent-moe.js +102 -0
- package/dist/core/agent.js +1018 -0
- package/dist/core/bootstrap.js +481 -0
- package/dist/core/crash-handler.js +51 -0
- package/dist/core/environment.js +199 -0
- package/dist/core/index.js +2 -0
- package/dist/core/prompt-builder.js +76 -0
- package/dist/core/session-logger.js +251 -0
- package/dist/core/types.js +1 -0
- package/dist/core/version.js +26 -0
- package/dist/core/workspace.js +76 -0
- package/dist/i18n/en.json +757 -746
- package/dist/i18n/index.js +46 -0
- package/dist/i18n/ru.json +757 -746
- package/dist/index.js +22 -0
- package/dist/llm/image-utils.js +143 -0
- package/dist/llm/index.js +4 -0
- package/dist/llm/model-loader.js +78 -0
- package/dist/llm/openai-compat.js +497 -0
- package/dist/llm/orchestrator.js +200 -0
- package/dist/llm/provider.js +10 -0
- package/dist/llm/response.js +39 -0
- package/dist/llm/token-counter.js +39 -0
- package/dist/llm/types.js +1 -0
- package/dist/logger/app-logger.js +189 -0
- package/dist/logger/file-log.js +151 -0
- package/dist/logger/index.js +1 -0
- package/dist/main.js +503 -340
- package/dist/migration/backup.js +45 -0
- package/dist/migration/detect.js +50 -0
- package/dist/migration/index.js +2 -0
- package/dist/modules/artifacts/store.js +61 -0
- package/dist/modules/browser/actions.js +76 -0
- package/dist/modules/browser/bridge-client.js +199 -0
- package/dist/modules/browser/bridge-path.js +10 -0
- package/dist/modules/browser/bridge-server.mjs +219 -219
- package/dist/modules/browser/cookie-store.js +24 -0
- package/dist/modules/browser/driver.js +136 -0
- package/dist/modules/browser/index.js +7 -0
- package/dist/modules/browser/module.js +29 -0
- package/dist/modules/browser/session.js +342 -0
- package/dist/modules/browser/snapshot.js +148 -0
- package/dist/modules/browser/types.js +12 -0
- package/dist/modules/certification/cli.js +213 -0
- package/dist/modules/certification/fact-checker.js +82 -0
- package/dist/modules/certification/loader.js +106 -0
- package/dist/modules/certification/manifest.js +58 -0
- package/dist/modules/certification/runner.js +245 -0
- package/dist/modules/certification/scenarios.js +407 -0
- package/dist/modules/certification/types.js +1 -0
- package/dist/modules/context/chunk-query.js +100 -0
- package/dist/modules/context/fact-extractor.js +168 -0
- package/dist/modules/context/history.js +15 -0
- package/dist/modules/context/index.js +1 -0
- package/dist/modules/context/manager.js +440 -0
- package/dist/modules/execution/audit-runners.js +206 -0
- package/dist/modules/execution/auditor.js +218 -0
- package/dist/modules/execution/execution-plugin.js +431 -0
- package/dist/modules/execution/index.js +8 -0
- package/dist/modules/execution/module.js +625 -0
- package/dist/modules/execution/moe-executor.js +304 -0
- package/dist/modules/execution/plan-coverage.js +68 -0
- package/dist/modules/execution/plan-persister.js +46 -0
- package/dist/modules/execution/plan-store.js +196 -0
- package/dist/modules/execution/plan-tool.js +677 -0
- package/dist/modules/execution/plan-validator.js +153 -0
- package/dist/modules/execution/planner.js +94 -0
- package/dist/modules/execution/stuck-detector.js +746 -0
- package/dist/modules/execution/tracker.js +69 -0
- package/dist/modules/execution/types.js +1 -0
- package/dist/modules/execution/verifier.js +235 -0
- package/dist/modules/execution/windows-commands.js +41 -0
- package/dist/modules/hallucination/confidence.js +66 -0
- package/dist/modules/hallucination/consistency.js +26 -0
- package/dist/modules/hallucination/detector.js +47 -0
- package/dist/modules/hallucination/factual.js +169 -0
- package/dist/modules/hallucination/index.js +5 -0
- package/dist/modules/hallucination/js-identifiers.js +262 -0
- package/dist/modules/hallucination/llm-judge.js +101 -0
- package/dist/modules/index.js +5 -0
- package/dist/modules/indexer/cache.js +40 -0
- package/dist/modules/indexer/index.js +3 -0
- package/dist/modules/indexer/module.js +246 -0
- package/dist/modules/indexer/project-profile.js +183 -0
- package/dist/modules/indexer/walker.js +101 -0
- package/dist/modules/lsp/check-tool.js +58 -0
- package/dist/modules/lsp/client.js +389 -0
- package/dist/modules/lsp/command.js +60 -0
- package/dist/modules/lsp/config.js +135 -0
- package/dist/modules/lsp/index.js +3 -0
- package/dist/modules/lsp/module.js +260 -0
- package/dist/modules/lsp/probe.js +86 -0
- package/dist/modules/lsp/project-root.js +32 -0
- package/dist/modules/lsp/startup-check.js +144 -0
- package/dist/modules/lsp/types.js +1 -0
- package/dist/modules/mcp/client.js +399 -0
- package/dist/modules/mcp/index.js +3 -0
- package/dist/modules/mcp/module.js +142 -0
- package/dist/modules/mcp/registry.js +15 -0
- package/dist/modules/memory/index.js +1 -0
- package/dist/modules/memory/module.js +96 -0
- package/dist/modules/memory/search.js +42 -0
- package/dist/modules/memory/store.js +69 -0
- package/dist/modules/pipelines/engine.js +60 -0
- package/dist/modules/pipelines/index.js +3 -0
- package/dist/modules/pipelines/parser.js +56 -0
- package/dist/modules/pipelines/template.js +14 -0
- package/dist/modules/plugins/builtin/lint-on-write.js +334 -0
- package/dist/modules/plugins/builtin/notify.js +9 -0
- package/dist/modules/plugins/index.js +1 -0
- package/dist/modules/plugins/loader.js +70 -0
- package/dist/modules/plugins/manager.js +261 -0
- package/dist/modules/plugins/types.js +1 -0
- package/dist/modules/pricing/index.js +61 -0
- package/dist/modules/pricing/prices.js +129 -0
- package/dist/modules/processes/detect.js +34 -0
- package/dist/modules/processes/index.js +2 -0
- package/dist/modules/processes/registry.js +327 -0
- package/dist/modules/processes/runner.js +23 -0
- package/dist/modules/providers/create.js +22 -0
- package/dist/modules/providers/fallback.js +79 -0
- package/dist/modules/providers/health.js +46 -0
- package/dist/modules/providers/index.js +5 -0
- package/dist/modules/providers/manager.js +161 -0
- package/dist/modules/providers/presets.js +128 -0
- package/dist/modules/providers/registry.js +22 -0
- package/dist/modules/providers/types.js +1 -0
- package/dist/modules/registry.js +48 -0
- package/dist/modules/security/audit-log.js +136 -0
- package/dist/modules/security/audit-notifier.js +292 -0
- package/dist/modules/security/command-validator.js +219 -0
- package/dist/modules/security/content-scanner.js +53 -0
- package/dist/modules/security/data-sanitizer.js +89 -0
- package/dist/modules/security/encryption.js +242 -0
- package/dist/modules/security/index.js +14 -0
- package/dist/modules/security/network-validator.js +88 -0
- package/dist/modules/security/path-validator.js +203 -0
- package/dist/modules/security/rate-limiter.js +119 -0
- package/dist/modules/security/security-policies.js +531 -0
- package/dist/modules/security/session-encryption.js +210 -0
- package/dist/modules/security/session-isolation.js +95 -0
- package/dist/modules/session/index.js +3 -0
- package/dist/modules/session/manager.js +172 -0
- package/dist/modules/session/module.js +24 -0
- package/dist/modules/session/store.js +222 -0
- package/dist/modules/session/types.js +1 -0
- package/dist/modules/skills/index.js +2 -0
- package/dist/modules/skills/loader.js +72 -0
- package/dist/modules/skills/matcher.js +27 -0
- package/dist/modules/skills/module.js +129 -0
- package/dist/modules/types.js +1 -0
- package/dist/modules/updater/checker.js +96 -0
- package/dist/modules/updater/index.js +2 -0
- package/dist/modules/updater/module.js +116 -0
- package/dist/modules/user-profile/compressor.js +16 -0
- package/dist/modules/user-profile/index.js +1 -0
- package/dist/modules/user-profile/profile.js +68 -0
- package/dist/skills/builtin/git.md +36 -36
- package/dist/skills/builtin/typescript.md +35 -35
- package/dist/tools/approve.js +33 -0
- package/dist/tools/attach-image.js +101 -0
- package/dist/tools/bash.js +519 -0
- package/dist/tools/browser.js +115 -0
- package/dist/tools/chunk-query.js +100 -0
- package/dist/tools/create-dir.js +56 -0
- package/dist/tools/delete-file.js +63 -0
- package/dist/tools/download-file.js +117 -0
- package/dist/tools/edit-file.js +80 -0
- package/dist/tools/enable-tools.js +59 -0
- package/dist/tools/executor.js +154 -0
- package/dist/tools/file-info.js +47 -0
- package/dist/tools/filter-tools.js +17 -0
- package/dist/tools/glob-tool.js +27 -0
- package/dist/tools/grep-tool.js +125 -0
- package/dist/tools/hidden-tools-block.js +37 -0
- package/dist/tools/index.js +78 -0
- package/dist/tools/list-dir.js +49 -0
- package/dist/tools/load-skill.js +43 -0
- package/dist/tools/mcp-call.js +69 -0
- package/dist/tools/move-file.js +86 -0
- package/dist/tools/path-utils.js +101 -0
- package/dist/tools/pipeline-run.js +145 -0
- package/dist/tools/preview.js +2 -0
- package/dist/tools/process-kill.js +40 -0
- package/dist/tools/process-list.js +37 -0
- package/dist/tools/process-log.js +54 -0
- package/dist/tools/question.js +141 -0
- package/dist/tools/read-file.js +179 -0
- package/dist/tools/recall.js +118 -0
- package/dist/tools/registry.js +47 -0
- package/dist/tools/remember.js +68 -0
- package/dist/tools/scope-check.js +32 -0
- package/dist/tools/search-history.js +85 -0
- package/dist/tools/subagent.js +196 -0
- package/dist/tools/types.js +1 -0
- package/dist/tools/user-input.js +123 -0
- package/dist/tools/web-browse.js +87 -0
- package/dist/tools/web-fetch.js +119 -0
- package/dist/tools/web-search.js +105 -0
- package/dist/tools/write-file.js +82 -0
- package/dist/ui/box.js +77 -0
- package/dist/ui/colors.js +4 -0
- package/dist/ui/diff.js +178 -0
- package/dist/ui/index.js +6 -0
- package/dist/ui/line-editor.js +822 -0
- package/dist/ui/line-math.js +73 -0
- package/dist/ui/md-formatter.js +212 -0
- package/dist/ui/output.js +13 -0
- package/dist/ui/plan-view.js +103 -0
- package/dist/ui/renderer.js +259 -0
- package/dist/ui/spinner.js +70 -0
- package/dist/ui/table.js +144 -0
- package/package.json +51 -51
package/dist/main.js
CHANGED
|
@@ -2728,6 +2728,14 @@ Fix the error and re-edit the file (a clean write clears the failure), or mark t
|
|
|
2728
2728
|
"cli.manage_context": "Manage context window",
|
|
2729
2729
|
"cli.invalid_context_size": "Invalid context size. Must be a number >= 1024",
|
|
2730
2730
|
"cli.context_set": "Context window set to: {size} tokens",
|
|
2731
|
+
"cli.context_budget_header": "Context budget (window {window} tokens):",
|
|
2732
|
+
"cli.context_system_line": " system prompt: {tokens} tokens ({percent}%)",
|
|
2733
|
+
"cli.context_reserve_line": " response reserve: {tokens} tokens ({percent}%)",
|
|
2734
|
+
"cli.context_history_line": " history: {tokens} tokens ({percent}%)",
|
|
2735
|
+
"cli.context_system_fraction": "System-prompt share of the context window (0.05–0.9)",
|
|
2736
|
+
"cli.context_reserve_fraction": "Response-reserve share of the context window (0.05–0.9)",
|
|
2737
|
+
"cli.context_fraction_set": "{key} share set to {value}",
|
|
2738
|
+
"cli.context_invalid_fraction": "Invalid share. Use a number between 0.05 and 0.9 (system + reserve must stay below 0.95).",
|
|
2731
2739
|
"repl.reload": "Reload agent with current config",
|
|
2732
2740
|
"repl.reload_usage": "Usage: /reload",
|
|
2733
2741
|
"repl.reloading": "Reloading agent...",
|
|
@@ -2893,7 +2901,7 @@ Available commands:`,
|
|
|
2893
2901
|
"repl.sysprompt_tokens": "System prompt ({count} tokens):",
|
|
2894
2902
|
"repl.excluded_blocks": `
|
|
2895
2903
|
Excluded blocks: {count}`,
|
|
2896
|
-
"repl.context_usage": "Usage: /context <size> (min 1024)",
|
|
2904
|
+
"repl.context_usage": "Usage: /context [<size> | system <fraction> | reserve <fraction>] (min 1024; fractions 0.05–0.9)",
|
|
2897
2905
|
"repl.msgs": "msgs",
|
|
2898
2906
|
"repl.max_iters": "Max iters:",
|
|
2899
2907
|
"repl.stuck_thresh": "Stuck thresh:",
|
|
@@ -3206,6 +3214,9 @@ Apply a matching solution from these results. If none is relevant — do NOT rep
|
|
|
3206
3214
|
"prompt.overflow.summarizing": 'System prompt overflow: summarizing "{label}" ({original} tok → {budget} tok budget) with the model…',
|
|
3207
3215
|
"prompt.overflow.truncating": 'System prompt overflow: truncating "{label}" ({original} tok) — summarization unavailable.',
|
|
3208
3216
|
"prompt.overflow.summarize_failed": 'System prompt overflow: summarization failed for "{label}": {error} — falling back to truncation.',
|
|
3217
|
+
"prompt.overflow.hint_needed": "the prompt needs ~{needed} system tokens (current budget: {window} × {fraction} = {budget})",
|
|
3218
|
+
"prompt.overflow.hint_window": "raise contextWindow to at least {required} (standard size {recommended}) — {how}",
|
|
3219
|
+
"prompt.overflow.hint_fraction": "or keep the window and raise contextBudget.systemPrompt to ~{fraction} (run: mma context --system {fraction})",
|
|
3209
3220
|
"prompt.overflow.exceeded": 'Prompt overflow: "{label}" ({original} tok) exceeded the system-prompt budget ({budget} tok) — {mode} to {resolved} tok. To fit fully, {hint}.',
|
|
3210
3221
|
"prompt.overflow.failed": "Prompt overflow resolution failed: {error} — oversized blocks will be dropped.",
|
|
3211
3222
|
"prompt.overflow.startup": "Startup check: {block} ({original} tok) exceeds the system-prompt budget ({budget} tok) — it will be summarized/truncated before the first run. To include it fully, {hint}.",
|
|
@@ -3531,6 +3542,14 @@ var init_ru = __esm(() => {
|
|
|
3531
3542
|
"cli.manage_context": "Управление контекстным окном",
|
|
3532
3543
|
"cli.invalid_context_size": "Некорректный размер контекста. Должно быть число >= 1024",
|
|
3533
3544
|
"cli.context_set": "Контекстное окно установлено: {size} токенов",
|
|
3545
|
+
"cli.context_budget_header": "Бюджет контекста (окно {window} токенов):",
|
|
3546
|
+
"cli.context_system_line": " системный промпт: {tokens} токенов ({percent}%)",
|
|
3547
|
+
"cli.context_reserve_line": " резерв ответа: {tokens} токенов ({percent}%)",
|
|
3548
|
+
"cli.context_history_line": " история: {tokens} токенов ({percent}%)",
|
|
3549
|
+
"cli.context_system_fraction": "Доля системного промпта в контекстном окне (0.05–0.9)",
|
|
3550
|
+
"cli.context_reserve_fraction": "Доля резерва ответа в контекстном окне (0.05–0.9)",
|
|
3551
|
+
"cli.context_fraction_set": "Доля {key} установлена: {value}",
|
|
3552
|
+
"cli.context_invalid_fraction": "Некорректная доля. Нужно число от 0.05 до 0.9 (системный + резерв должны оставаться ниже 0.95).",
|
|
3534
3553
|
"cli.set_model": "Установить модель по умолчанию",
|
|
3535
3554
|
"cli.model_set": "Модель установлена: {name}",
|
|
3536
3555
|
"cli.certify": "Запустить сертификационный набор для модели",
|
|
@@ -3692,7 +3711,7 @@ var init_ru = __esm(() => {
|
|
|
3692
3711
|
"repl.sysprompt_tokens": "Системный промпт ({count} токенов):",
|
|
3693
3712
|
"repl.excluded_blocks": `
|
|
3694
3713
|
Исключённые блоки: {count}`,
|
|
3695
|
-
"repl.context_usage": "Использование: /context <размер> (мин 1024)",
|
|
3714
|
+
"repl.context_usage": "Использование: /context [<размер> | system <доля> | reserve <доля>] (мин 1024; доли 0.05–0.9)",
|
|
3696
3715
|
"repl.msgs": "сообщ.",
|
|
3697
3716
|
"repl.max_iters": "Макс итераций:",
|
|
3698
3717
|
"repl.stuck_thresh": "Порог зависания:",
|
|
@@ -4012,6 +4031,9 @@ var init_ru = __esm(() => {
|
|
|
4012
4031
|
"prompt.overflow.summarizing": 'Переполнение системного промпта: суммаризирую "{label}" ({original} токенов → бюджет {budget} токенов) моделью…',
|
|
4013
4032
|
"prompt.overflow.truncating": 'Переполнение системного промпта: обрезаю "{label}" ({original} токенов) — суммаризация недоступна.',
|
|
4014
4033
|
"prompt.overflow.summarize_failed": 'Переполнение системного промпта: не удалось суммаризировать "{label}": {error} — перехожу к обрезке.',
|
|
4034
|
+
"prompt.overflow.hint_needed": "промпту нужно ~{needed} токенов системного бюджета (сейчас: {window} × {fraction} = {budget})",
|
|
4035
|
+
"prompt.overflow.hint_window": "подними contextWindow минимум до {required} (стандартный размер {recommended}) — {how}",
|
|
4036
|
+
"prompt.overflow.hint_fraction": "или оставь окно и подними contextBudget.systemPrompt до ~{fraction} (выполни: mma context --system {fraction})",
|
|
4015
4037
|
"prompt.overflow.exceeded": 'Промпт переполнен: "{label}" ({original} токенов) превысил бюджет системного промпта ({budget} токенов) — {mode} до {resolved} токенов. Чтобы включить полностью, {hint}.',
|
|
4016
4038
|
"prompt.overflow.failed": "Не удалось разрешить переполнение промпта: {error} — слишком большие блоки будут отброшены.",
|
|
4017
4039
|
"prompt.overflow.startup": "Проверка при старте: {block} ({original} токенов) превышает бюджет системного промпта ({budget} токенов) — будет суммаризован/обрезан перед первым запуском. Чтобы включить полностью, {hint}.",
|
|
@@ -5720,6 +5742,26 @@ var init_token_counter = __esm(() => {
|
|
|
5720
5742
|
init_dist();
|
|
5721
5743
|
});
|
|
5722
5744
|
|
|
5745
|
+
// src/core/version.ts
|
|
5746
|
+
import { existsSync as existsSync9, readFileSync as readFileSync5 } from "fs";
|
|
5747
|
+
import { join as join9, dirname as dirname3 } from "path";
|
|
5748
|
+
import { fileURLToPath } from "url";
|
|
5749
|
+
function readMmaVersion() {
|
|
5750
|
+
const here = dirname3(fileURLToPath(import.meta.url));
|
|
5751
|
+
const candidates = [join9(here, "..", "..", "package.json"), join9(here, "..", "package.json")];
|
|
5752
|
+
for (const p of candidates) {
|
|
5753
|
+
if (existsSync9(p)) {
|
|
5754
|
+
try {
|
|
5755
|
+
const raw = JSON.parse(readFileSync5(p, "utf8"));
|
|
5756
|
+
if (raw.version)
|
|
5757
|
+
return raw.version;
|
|
5758
|
+
} catch {}
|
|
5759
|
+
}
|
|
5760
|
+
}
|
|
5761
|
+
return "0.0.0";
|
|
5762
|
+
}
|
|
5763
|
+
var init_version = () => {};
|
|
5764
|
+
|
|
5723
5765
|
// src/modules/security/rate-limiter.ts
|
|
5724
5766
|
class RateLimiter {
|
|
5725
5767
|
config;
|
|
@@ -5856,6 +5898,11 @@ var exports_openai_compat = {};
|
|
|
5856
5898
|
__export(exports_openai_compat, {
|
|
5857
5899
|
OpenAICompatProvider: () => OpenAICompatProvider
|
|
5858
5900
|
});
|
|
5901
|
+
function defaultUserAgent() {
|
|
5902
|
+
if (cachedUserAgent === null)
|
|
5903
|
+
cachedUserAgent = `micro-models-agent/${readMmaVersion()}`;
|
|
5904
|
+
return cachedUserAgent;
|
|
5905
|
+
}
|
|
5859
5906
|
function buildRequestBody(opts) {
|
|
5860
5907
|
const body = {
|
|
5861
5908
|
model: opts.model,
|
|
@@ -5895,6 +5942,8 @@ class OpenAICompatProvider {
|
|
|
5895
5942
|
retryConfig;
|
|
5896
5943
|
rateLimiter;
|
|
5897
5944
|
debug;
|
|
5945
|
+
getSessionId;
|
|
5946
|
+
userAgent;
|
|
5898
5947
|
constructor(config) {
|
|
5899
5948
|
this.config = config;
|
|
5900
5949
|
this.model = config.model;
|
|
@@ -5908,6 +5957,8 @@ class OpenAICompatProvider {
|
|
|
5908
5957
|
noDataTimeoutMs: 180000
|
|
5909
5958
|
};
|
|
5910
5959
|
this.rateLimiter = createRateLimiter(config.rateLimits);
|
|
5960
|
+
this.getSessionId = config.getSessionId;
|
|
5961
|
+
this.userAgent = config.userAgent ?? defaultUserAgent();
|
|
5911
5962
|
this.debug = config.logger ? config.logger.debug.bind(config.logger) : null;
|
|
5912
5963
|
}
|
|
5913
5964
|
async* chat(messages, tools, signal, options) {
|
|
@@ -6197,11 +6248,15 @@ class OpenAICompatProvider {
|
|
|
6197
6248
|
}
|
|
6198
6249
|
buildRequestSetup(signal) {
|
|
6199
6250
|
const headers = {
|
|
6200
|
-
"Content-Type": "application/json"
|
|
6251
|
+
"Content-Type": "application/json",
|
|
6252
|
+
"User-Agent": this.userAgent
|
|
6201
6253
|
};
|
|
6202
6254
|
if (this.config.apiKey && this.config.apiKey !== "not-needed") {
|
|
6203
6255
|
headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
6204
6256
|
}
|
|
6257
|
+
const sessionId = this.getSessionId?.();
|
|
6258
|
+
if (sessionId)
|
|
6259
|
+
headers["x-opencode-session"] = sessionId;
|
|
6205
6260
|
const controller = new AbortController;
|
|
6206
6261
|
let timedOut = false;
|
|
6207
6262
|
const timeoutId = setTimeout(() => {
|
|
@@ -6313,7 +6368,8 @@ class OpenAICompatProvider {
|
|
|
6313
6368
|
try {
|
|
6314
6369
|
const url = `${this.config.baseUrl.replace(/\/+$/, "")}/models`;
|
|
6315
6370
|
const headers = {
|
|
6316
|
-
"Content-Type": "application/json"
|
|
6371
|
+
"Content-Type": "application/json",
|
|
6372
|
+
"User-Agent": this.userAgent
|
|
6317
6373
|
};
|
|
6318
6374
|
if (this.config.apiKey && this.config.apiKey !== "not-needed") {
|
|
6319
6375
|
headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
@@ -6387,10 +6443,11 @@ class OpenAICompatProvider {
|
|
|
6387
6443
|
});
|
|
6388
6444
|
}
|
|
6389
6445
|
}
|
|
6390
|
-
var REQUEST_TIMEOUT_MS = 120000, MAX_RATE_WAIT_MS = 30000;
|
|
6446
|
+
var REQUEST_TIMEOUT_MS = 120000, MAX_RATE_WAIT_MS = 30000, cachedUserAgent = null;
|
|
6391
6447
|
var init_openai_compat = __esm(() => {
|
|
6392
6448
|
init_token_counter();
|
|
6393
6449
|
init_i18n();
|
|
6450
|
+
init_version();
|
|
6394
6451
|
init_rate_limiter();
|
|
6395
6452
|
init_llm_errors();
|
|
6396
6453
|
});
|
|
@@ -6411,6 +6468,7 @@ function openaiCompat(opts) {
|
|
|
6411
6468
|
retry,
|
|
6412
6469
|
rateLimits,
|
|
6413
6470
|
maxCompletionTokens: opts.maxCompletionTokens,
|
|
6471
|
+
getSessionId: opts.getSessionId,
|
|
6414
6472
|
logger: opts.logger
|
|
6415
6473
|
});
|
|
6416
6474
|
}
|
|
@@ -6688,6 +6746,7 @@ class ProviderManager {
|
|
|
6688
6746
|
retry: entry.retry ?? this.opts.retry,
|
|
6689
6747
|
rateLimits: entry.rateLimits ?? this.opts.rateLimits,
|
|
6690
6748
|
maxCompletionTokens: entry.maxCompletionTokens,
|
|
6749
|
+
getSessionId: this.opts.getSessionId,
|
|
6691
6750
|
logger: this.opts.logger
|
|
6692
6751
|
}, this.registry);
|
|
6693
6752
|
this.cache.set(key, provider);
|
|
@@ -6772,11 +6831,12 @@ var init_fallback = __esm(() => {
|
|
|
6772
6831
|
});
|
|
6773
6832
|
|
|
6774
6833
|
// src/modules/providers/factory.ts
|
|
6775
|
-
function buildActiveProvider(config, logger) {
|
|
6834
|
+
function buildActiveProvider(config, logger, opts) {
|
|
6776
6835
|
const manager = new ProviderManager(config.provider, {
|
|
6777
6836
|
contextWindow: config.contextWindow,
|
|
6778
6837
|
retry: config.retry,
|
|
6779
6838
|
rateLimits: config.security?.rateLimits,
|
|
6839
|
+
getSessionId: opts?.getSessionId,
|
|
6780
6840
|
logger
|
|
6781
6841
|
});
|
|
6782
6842
|
manager.setModel(config.model);
|
|
@@ -7120,8 +7180,8 @@ var init_executor = __esm(() => {
|
|
|
7120
7180
|
});
|
|
7121
7181
|
|
|
7122
7182
|
// src/tools/path-utils.ts
|
|
7123
|
-
import { resolve, normalize, dirname as
|
|
7124
|
-
import { existsSync as
|
|
7183
|
+
import { resolve, normalize, dirname as dirname4, basename, sep, relative, isAbsolute } from "path";
|
|
7184
|
+
import { existsSync as existsSync10 } from "fs";
|
|
7125
7185
|
function toForwardSlash(p) {
|
|
7126
7186
|
return p.replace(/\\/g, "/");
|
|
7127
7187
|
}
|
|
@@ -7142,30 +7202,30 @@ function matchesScopeEntry(targetResolved, entryResolved) {
|
|
|
7142
7202
|
function safeResolvePath(baseDir, userPath) {
|
|
7143
7203
|
const asIs = resolve(normalize(userPath));
|
|
7144
7204
|
if (userPath.startsWith("/") || userPath.startsWith("\\")) {
|
|
7145
|
-
if (
|
|
7205
|
+
if (existsSync10(asIs) || existsSync10(dirname4(asIs)))
|
|
7146
7206
|
return asIs;
|
|
7147
7207
|
}
|
|
7148
7208
|
const norm = normalize(userPath);
|
|
7149
7209
|
if (isAbsolute(norm)) {
|
|
7150
|
-
if (
|
|
7210
|
+
if (existsSync10(norm) || existsSync10(dirname4(norm)))
|
|
7151
7211
|
return norm;
|
|
7152
7212
|
const stripped2 = norm.replace(/^[/\\]/, "");
|
|
7153
7213
|
const relativeCandidate = resolve(baseDir, stripped2);
|
|
7154
|
-
if (
|
|
7214
|
+
if (existsSync10(relativeCandidate) || existsSync10(dirname4(relativeCandidate))) {
|
|
7155
7215
|
return relativeCandidate;
|
|
7156
7216
|
}
|
|
7157
7217
|
return norm;
|
|
7158
7218
|
}
|
|
7159
7219
|
const stripped = norm.replace(/^[/\\]/, "");
|
|
7160
7220
|
const resolved = resolve(baseDir, stripped);
|
|
7161
|
-
if (
|
|
7221
|
+
if (existsSync10(resolved) || existsSync10(dirname4(resolved)))
|
|
7162
7222
|
return resolved;
|
|
7163
7223
|
const baseNorm = normalize(baseDir);
|
|
7164
7224
|
let cur = baseNorm;
|
|
7165
|
-
while (cur && cur !==
|
|
7225
|
+
while (cur && cur !== dirname4(cur)) {
|
|
7166
7226
|
const name = basename(cur);
|
|
7167
7227
|
if (!name) {
|
|
7168
|
-
cur =
|
|
7228
|
+
cur = dirname4(cur);
|
|
7169
7229
|
continue;
|
|
7170
7230
|
}
|
|
7171
7231
|
let idx = stripped.toLowerCase().indexOf(name.toLowerCase());
|
|
@@ -7175,17 +7235,17 @@ function safeResolvePath(baseDir, userPath) {
|
|
|
7175
7235
|
if (afterChar && afterChar !== "\\" && afterChar !== "/") {
|
|
7176
7236
|
const fixed = stripped.slice(0, afterIdx) + sep + stripped.slice(afterIdx);
|
|
7177
7237
|
const fixedResolved = resolve(baseDir, normalize(fixed));
|
|
7178
|
-
if (
|
|
7238
|
+
if (existsSync10(fixedResolved) || existsSync10(dirname4(fixedResolved))) {
|
|
7179
7239
|
return fixedResolved;
|
|
7180
7240
|
}
|
|
7181
|
-
const fromParent = resolve(
|
|
7182
|
-
if (
|
|
7241
|
+
const fromParent = resolve(dirname4(cur), normalize(fixed));
|
|
7242
|
+
if (existsSync10(fromParent) || existsSync10(dirname4(fromParent))) {
|
|
7183
7243
|
return fromParent;
|
|
7184
7244
|
}
|
|
7185
7245
|
}
|
|
7186
7246
|
idx = stripped.toLowerCase().indexOf(name.toLowerCase(), idx + 1);
|
|
7187
7247
|
}
|
|
7188
|
-
cur =
|
|
7248
|
+
cur = dirname4(cur);
|
|
7189
7249
|
}
|
|
7190
7250
|
return resolved;
|
|
7191
7251
|
}
|
|
@@ -7402,10 +7462,10 @@ __export(exports_audit_notifier, {
|
|
|
7402
7462
|
DEFAULT_AUDIT_NOTIFIER_CONFIG: () => DEFAULT_AUDIT_NOTIFIER_CONFIG,
|
|
7403
7463
|
AuditNotifier: () => AuditNotifier
|
|
7404
7464
|
});
|
|
7405
|
-
import { writeFileSync as writeFileSync5, appendFileSync as appendFileSync3, existsSync as
|
|
7406
|
-
import { join as
|
|
7465
|
+
import { writeFileSync as writeFileSync5, appendFileSync as appendFileSync3, existsSync as existsSync11, mkdirSync as mkdirSync6 } from "fs";
|
|
7466
|
+
import { join as join10, dirname as dirname5 } from "path";
|
|
7407
7467
|
import { homedir as homedir3 } from "os";
|
|
7408
|
-
import { readFileSync as
|
|
7468
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
7409
7469
|
|
|
7410
7470
|
class AuditNotifier {
|
|
7411
7471
|
config;
|
|
@@ -7430,7 +7490,7 @@ class AuditNotifier {
|
|
|
7430
7490
|
}
|
|
7431
7491
|
ensureLogDirectory() {
|
|
7432
7492
|
if (this.config.filePath) {
|
|
7433
|
-
const dir =
|
|
7493
|
+
const dir = dirname5(this.config.filePath);
|
|
7434
7494
|
mkdirSync6(dir, { recursive: true });
|
|
7435
7495
|
}
|
|
7436
7496
|
}
|
|
@@ -7560,11 +7620,11 @@ class AuditNotifier {
|
|
|
7560
7620
|
}
|
|
7561
7621
|
}
|
|
7562
7622
|
readNotifications(limit = 100) {
|
|
7563
|
-
if (!this.config.filePath || !
|
|
7623
|
+
if (!this.config.filePath || !existsSync11(this.config.filePath)) {
|
|
7564
7624
|
return [];
|
|
7565
7625
|
}
|
|
7566
7626
|
try {
|
|
7567
|
-
const content =
|
|
7627
|
+
const content = readFileSync6(this.config.filePath, "utf8");
|
|
7568
7628
|
const lines = content.split(`
|
|
7569
7629
|
`).filter(Boolean);
|
|
7570
7630
|
return lines.slice(-limit).map((line) => JSON.parse(line));
|
|
@@ -7618,7 +7678,7 @@ var init_audit_notifier = __esm(() => {
|
|
|
7618
7678
|
};
|
|
7619
7679
|
DEFAULT_AUDIT_NOTIFIER_CONFIG = {
|
|
7620
7680
|
enabled: false,
|
|
7621
|
-
filePath:
|
|
7681
|
+
filePath: join10(homedir3(), ".mma", "logs", "audit-notifications.jsonl"),
|
|
7622
7682
|
webhookTimeout: 5000,
|
|
7623
7683
|
minSeverity: "medium",
|
|
7624
7684
|
eventTypes: [
|
|
@@ -7635,26 +7695,26 @@ var init_audit_notifier = __esm(() => {
|
|
|
7635
7695
|
});
|
|
7636
7696
|
|
|
7637
7697
|
// src/modules/security/audit-log.ts
|
|
7638
|
-
import { existsSync as
|
|
7639
|
-
import { resolve as resolve3, join as
|
|
7698
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync7, appendFileSync as appendFileSync4 } from "fs";
|
|
7699
|
+
import { resolve as resolve3, join as join11 } from "path";
|
|
7640
7700
|
import { homedir as homedir4 } from "os";
|
|
7641
7701
|
function getAuditDir() {
|
|
7642
7702
|
return _sessionAuditDir ?? _globalAuditDir;
|
|
7643
7703
|
}
|
|
7644
7704
|
function setAuditSessionDir(dir) {
|
|
7645
7705
|
_sessionAuditDir = dir;
|
|
7646
|
-
if (!
|
|
7706
|
+
if (!existsSync12(dir)) {
|
|
7647
7707
|
mkdirSync7(dir, { recursive: true, mode: 448 });
|
|
7648
7708
|
}
|
|
7649
7709
|
}
|
|
7650
7710
|
function logAudit(entry) {
|
|
7651
7711
|
const dir = getAuditDir();
|
|
7652
|
-
if (!
|
|
7712
|
+
if (!existsSync12(dir)) {
|
|
7653
7713
|
mkdirSync7(dir, { recursive: true, mode: 448 });
|
|
7654
7714
|
}
|
|
7655
7715
|
try {
|
|
7656
7716
|
const logEntry = JSON.stringify(entry);
|
|
7657
|
-
appendFileSync4(
|
|
7717
|
+
appendFileSync4(join11(dir, "audit.jsonl"), logEntry + `
|
|
7658
7718
|
`, "utf8");
|
|
7659
7719
|
} catch {}
|
|
7660
7720
|
try {
|
|
@@ -7718,7 +7778,7 @@ var init_audit_log = __esm(() => {
|
|
|
7718
7778
|
});
|
|
7719
7779
|
|
|
7720
7780
|
// src/tools/read-file.ts
|
|
7721
|
-
import { readFileSync as
|
|
7781
|
+
import { readFileSync as readFileSync7, existsSync as existsSync13, statSync as statSync2, openSync, readSync, closeSync } from "fs";
|
|
7722
7782
|
import { extname } from "path";
|
|
7723
7783
|
function readLineSlice(path, offset, limit) {
|
|
7724
7784
|
const fd = openSync(path, "r");
|
|
@@ -7819,7 +7879,7 @@ var init_read_file = __esm(() => {
|
|
|
7819
7879
|
})
|
|
7820
7880
|
};
|
|
7821
7881
|
}
|
|
7822
|
-
if (!
|
|
7882
|
+
if (!existsSync13(resolved)) {
|
|
7823
7883
|
const output = resolved !== path ? t("file.notfound_resolved", {
|
|
7824
7884
|
path,
|
|
7825
7885
|
resolved
|
|
@@ -7836,7 +7896,7 @@ var init_read_file = __esm(() => {
|
|
|
7836
7896
|
total = slice.total;
|
|
7837
7897
|
selected = slice.selected;
|
|
7838
7898
|
} else {
|
|
7839
|
-
const content =
|
|
7899
|
+
const content = readFileSync7(resolved, "utf-8");
|
|
7840
7900
|
lines = content.split(`
|
|
7841
7901
|
`);
|
|
7842
7902
|
total = lines.length;
|
|
@@ -7928,14 +7988,14 @@ __export(exports_session_isolation, {
|
|
|
7928
7988
|
cleanupSessionTempDir: () => cleanupSessionTempDir,
|
|
7929
7989
|
DEFAULT_SESSION_ISOLATION: () => DEFAULT_SESSION_ISOLATION
|
|
7930
7990
|
});
|
|
7931
|
-
import { join as
|
|
7991
|
+
import { join as join12, resolve as resolve5 } from "path";
|
|
7932
7992
|
import { homedir as homedir5 } from "os";
|
|
7933
|
-
import { mkdirSync as mkdirSync8, existsSync as
|
|
7993
|
+
import { mkdirSync as mkdirSync8, existsSync as existsSync14 } from "fs";
|
|
7934
7994
|
function createSessionContext(sessionId, projectDir, isolationConfig, securityOverrides) {
|
|
7935
7995
|
const config = { ...DEFAULT_SESSION_ISOLATION, ...isolationConfig };
|
|
7936
|
-
const baseDir = config.baseDir ||
|
|
7937
|
-
const tempDir =
|
|
7938
|
-
if (config.isolateTempFiles && !
|
|
7996
|
+
const baseDir = config.baseDir || join12(homedir5(), ".mma", "sessions", sessionId);
|
|
7997
|
+
const tempDir = join12(baseDir, "temp");
|
|
7998
|
+
if (config.isolateTempFiles && !existsSync14(tempDir)) {
|
|
7939
7999
|
try {
|
|
7940
8000
|
mkdirSync8(tempDir, { recursive: true, mode: 448 });
|
|
7941
8001
|
} catch {}
|
|
@@ -8185,8 +8245,8 @@ var init_diff = __esm(() => {
|
|
|
8185
8245
|
});
|
|
8186
8246
|
|
|
8187
8247
|
// src/tools/syntax-validator.ts
|
|
8188
|
-
import { writeFileSync as writeFileSync6, existsSync as
|
|
8189
|
-
import { extname as extname2, dirname as
|
|
8248
|
+
import { writeFileSync as writeFileSync6, existsSync as existsSync15, unlinkSync as unlinkSync3 } from "fs";
|
|
8249
|
+
import { extname as extname2, dirname as dirname6 } from "path";
|
|
8190
8250
|
import { spawn } from "child_process";
|
|
8191
8251
|
function contentHash(content) {
|
|
8192
8252
|
let h = 5381;
|
|
@@ -8250,7 +8310,7 @@ async function preValidateSyntax(filePath, content, baseDir) {
|
|
|
8250
8310
|
const tmpFile = `${filePath}.tmp${ext}`;
|
|
8251
8311
|
try {
|
|
8252
8312
|
writeFileSync6(tmpFile, content, "utf-8");
|
|
8253
|
-
await runCommand(`bun build --no-bundle --target=bun "${tmpFile}"`,
|
|
8313
|
+
await runCommand(`bun build --no-bundle --target=bun "${tmpFile}"`, dirname6(filePath), 5000);
|
|
8254
8314
|
SYNTAX_CACHE.set(filePath, { hash, error: null });
|
|
8255
8315
|
return { valid: true };
|
|
8256
8316
|
} catch (err) {
|
|
@@ -8262,7 +8322,7 @@ async function preValidateSyntax(filePath, content, baseDir) {
|
|
|
8262
8322
|
return { valid: false, error };
|
|
8263
8323
|
} finally {
|
|
8264
8324
|
try {
|
|
8265
|
-
if (
|
|
8325
|
+
if (existsSync15(tmpFile))
|
|
8266
8326
|
unlinkSync3(tmpFile);
|
|
8267
8327
|
} catch {}
|
|
8268
8328
|
}
|
|
@@ -8276,7 +8336,7 @@ async function preValidateSyntax(filePath, content, baseDir) {
|
|
|
8276
8336
|
const tmpFile = `${filePath}.tmp${ext}`;
|
|
8277
8337
|
try {
|
|
8278
8338
|
writeFileSync6(tmpFile, content, "utf-8");
|
|
8279
|
-
await runCommand(`node --check "${tmpFile}"`,
|
|
8339
|
+
await runCommand(`node --check "${tmpFile}"`, dirname6(filePath), 5000);
|
|
8280
8340
|
SYNTAX_CACHE.set(filePath, { hash, error: null });
|
|
8281
8341
|
return { valid: true };
|
|
8282
8342
|
} catch (err) {
|
|
@@ -8288,7 +8348,7 @@ async function preValidateSyntax(filePath, content, baseDir) {
|
|
|
8288
8348
|
return { valid: false, error };
|
|
8289
8349
|
} finally {
|
|
8290
8350
|
try {
|
|
8291
|
-
if (
|
|
8351
|
+
if (existsSync15(tmpFile))
|
|
8292
8352
|
unlinkSync3(tmpFile);
|
|
8293
8353
|
} catch {}
|
|
8294
8354
|
}
|
|
@@ -8328,8 +8388,8 @@ var init_syntax_validator = __esm(() => {
|
|
|
8328
8388
|
});
|
|
8329
8389
|
|
|
8330
8390
|
// src/tools/write-file.ts
|
|
8331
|
-
import { writeFileSync as writeFileSync7, mkdirSync as mkdirSync9, existsSync as
|
|
8332
|
-
import { dirname as
|
|
8391
|
+
import { writeFileSync as writeFileSync7, mkdirSync as mkdirSync9, existsSync as existsSync16, readFileSync as readFileSync8 } from "fs";
|
|
8392
|
+
import { dirname as dirname7 } from "path";
|
|
8333
8393
|
var writeFileTool;
|
|
8334
8394
|
var init_write_file = __esm(() => {
|
|
8335
8395
|
init_i18n();
|
|
@@ -8387,8 +8447,8 @@ var init_write_file = __esm(() => {
|
|
|
8387
8447
|
};
|
|
8388
8448
|
}
|
|
8389
8449
|
}
|
|
8390
|
-
const dir =
|
|
8391
|
-
if (!
|
|
8450
|
+
const dir = dirname7(resolved);
|
|
8451
|
+
if (!existsSync16(dir)) {
|
|
8392
8452
|
mkdirSync9(dir, { recursive: true });
|
|
8393
8453
|
}
|
|
8394
8454
|
const validation = await preValidateSyntax(resolved, content, ctx.baseDir);
|
|
@@ -8399,10 +8459,10 @@ var init_write_file = __esm(() => {
|
|
|
8399
8459
|
};
|
|
8400
8460
|
}
|
|
8401
8461
|
const conflicts = detectImportConflicts(content);
|
|
8402
|
-
const fileExists =
|
|
8462
|
+
const fileExists = existsSync16(resolved);
|
|
8403
8463
|
let oldContent = "";
|
|
8404
8464
|
if (fileExists) {
|
|
8405
|
-
oldContent =
|
|
8465
|
+
oldContent = readFileSync8(resolved, "utf-8");
|
|
8406
8466
|
}
|
|
8407
8467
|
writeFileSync7(resolved, content, "utf-8");
|
|
8408
8468
|
const diff = fileExists ? generateDiff(oldContent, content) : generateNewFileDiff(content);
|
|
@@ -8419,7 +8479,7 @@ var init_write_file = __esm(() => {
|
|
|
8419
8479
|
});
|
|
8420
8480
|
|
|
8421
8481
|
// src/tools/edit-file.ts
|
|
8422
|
-
import { readFileSync as
|
|
8482
|
+
import { readFileSync as readFileSync9, writeFileSync as writeFileSync8 } from "fs";
|
|
8423
8483
|
var editFileTool;
|
|
8424
8484
|
var init_edit_file = __esm(() => {
|
|
8425
8485
|
init_i18n();
|
|
@@ -8467,7 +8527,7 @@ var init_edit_file = __esm(() => {
|
|
|
8467
8527
|
})
|
|
8468
8528
|
};
|
|
8469
8529
|
}
|
|
8470
|
-
const content =
|
|
8530
|
+
const content = readFileSync9(resolved, "utf-8");
|
|
8471
8531
|
const oldStr = String(args.old);
|
|
8472
8532
|
const newStr = String(args.new);
|
|
8473
8533
|
if (!content.includes(oldStr)) {
|
|
@@ -8675,7 +8735,7 @@ var init_grep_tool = __esm(() => {
|
|
|
8675
8735
|
});
|
|
8676
8736
|
|
|
8677
8737
|
// src/tools/list-dir.ts
|
|
8678
|
-
import { readdirSync as readdirSync5, statSync as statSync3, existsSync as
|
|
8738
|
+
import { readdirSync as readdirSync5, statSync as statSync3, existsSync as existsSync17 } from "fs";
|
|
8679
8739
|
import { resolve as resolve8 } from "path";
|
|
8680
8740
|
var IGNORED_DIRS, listDirTool;
|
|
8681
8741
|
var init_list_dir = __esm(() => {
|
|
@@ -8708,7 +8768,7 @@ var init_list_dir = __esm(() => {
|
|
|
8708
8768
|
})
|
|
8709
8769
|
};
|
|
8710
8770
|
}
|
|
8711
|
-
if (!
|
|
8771
|
+
if (!existsSync17(resolved)) {
|
|
8712
8772
|
return { success: false, output: t("file.dir_notfound", { path }) };
|
|
8713
8773
|
}
|
|
8714
8774
|
const entries = readdirSync5(resolved).filter((e) => !IGNORED_DIRS.has(e));
|
|
@@ -8728,7 +8788,7 @@ var init_list_dir = __esm(() => {
|
|
|
8728
8788
|
});
|
|
8729
8789
|
|
|
8730
8790
|
// src/tools/create-dir.ts
|
|
8731
|
-
import { mkdirSync as mkdirSync10, existsSync as
|
|
8791
|
+
import { mkdirSync as mkdirSync10, existsSync as existsSync18 } from "fs";
|
|
8732
8792
|
var createDirTool;
|
|
8733
8793
|
var init_create_dir = __esm(() => {
|
|
8734
8794
|
init_i18n();
|
|
@@ -8771,7 +8831,7 @@ var init_create_dir = __esm(() => {
|
|
|
8771
8831
|
})
|
|
8772
8832
|
};
|
|
8773
8833
|
}
|
|
8774
|
-
if (!
|
|
8834
|
+
if (!existsSync18(resolved)) {
|
|
8775
8835
|
mkdirSync10(resolved, { recursive: true });
|
|
8776
8836
|
}
|
|
8777
8837
|
ctx.fileOperationsCount = currentCount + 1;
|
|
@@ -8782,7 +8842,7 @@ var init_create_dir = __esm(() => {
|
|
|
8782
8842
|
});
|
|
8783
8843
|
|
|
8784
8844
|
// src/tools/delete-file.ts
|
|
8785
|
-
import { unlinkSync as unlinkSync4, existsSync as
|
|
8845
|
+
import { unlinkSync as unlinkSync4, existsSync as existsSync19, statSync as statSync4, readFileSync as readFileSync10 } from "fs";
|
|
8786
8846
|
var deleteFileTool;
|
|
8787
8847
|
var init_delete_file = __esm(() => {
|
|
8788
8848
|
init_i18n();
|
|
@@ -8826,13 +8886,13 @@ var init_delete_file = __esm(() => {
|
|
|
8826
8886
|
})
|
|
8827
8887
|
};
|
|
8828
8888
|
}
|
|
8829
|
-
if (!
|
|
8889
|
+
if (!existsSync19(resolved)) {
|
|
8830
8890
|
return { success: false, output: t("file.notfound", { path }) };
|
|
8831
8891
|
}
|
|
8832
8892
|
if (statSync4(resolved).isDirectory()) {
|
|
8833
8893
|
return { success: false, output: t("file.is_directory", { path }) };
|
|
8834
8894
|
}
|
|
8835
|
-
const content =
|
|
8895
|
+
const content = readFileSync10(resolved, "utf-8");
|
|
8836
8896
|
unlinkSync4(resolved);
|
|
8837
8897
|
const diff = generateDeleteDiff(content);
|
|
8838
8898
|
ctx.fileOperationsCount = currentCount + 1;
|
|
@@ -8843,8 +8903,8 @@ var init_delete_file = __esm(() => {
|
|
|
8843
8903
|
});
|
|
8844
8904
|
|
|
8845
8905
|
// src/tools/move-file.ts
|
|
8846
|
-
import { renameSync as renameSync2, existsSync as
|
|
8847
|
-
import { resolve as resolve9, normalize as normalize3, dirname as
|
|
8906
|
+
import { renameSync as renameSync2, existsSync as existsSync20, mkdirSync as mkdirSync11 } from "fs";
|
|
8907
|
+
import { resolve as resolve9, normalize as normalize3, dirname as dirname8 } from "path";
|
|
8848
8908
|
var moveFileTool;
|
|
8849
8909
|
var init_move_file = __esm(() => {
|
|
8850
8910
|
init_i18n();
|
|
@@ -8902,14 +8962,14 @@ var init_move_file = __esm(() => {
|
|
|
8902
8962
|
})
|
|
8903
8963
|
};
|
|
8904
8964
|
}
|
|
8905
|
-
if (!
|
|
8965
|
+
if (!existsSync20(fromResolved)) {
|
|
8906
8966
|
return {
|
|
8907
8967
|
success: false,
|
|
8908
8968
|
output: t("file.not_found_short", { path: fromPath })
|
|
8909
8969
|
};
|
|
8910
8970
|
}
|
|
8911
|
-
const toDir =
|
|
8912
|
-
if (!
|
|
8971
|
+
const toDir = dirname8(toResolved);
|
|
8972
|
+
if (!existsSync20(toDir)) {
|
|
8913
8973
|
mkdirSync11(toDir, { recursive: true });
|
|
8914
8974
|
}
|
|
8915
8975
|
renameSync2(fromResolved, toResolved);
|
|
@@ -8926,7 +8986,7 @@ var init_move_file = __esm(() => {
|
|
|
8926
8986
|
});
|
|
8927
8987
|
|
|
8928
8988
|
// src/tools/file-info.ts
|
|
8929
|
-
import { statSync as statSync5, existsSync as
|
|
8989
|
+
import { statSync as statSync5, existsSync as existsSync21 } from "fs";
|
|
8930
8990
|
var fileInfoTool;
|
|
8931
8991
|
var init_file_info = __esm(() => {
|
|
8932
8992
|
init_i18n();
|
|
@@ -8957,7 +9017,7 @@ var init_file_info = __esm(() => {
|
|
|
8957
9017
|
})
|
|
8958
9018
|
};
|
|
8959
9019
|
}
|
|
8960
|
-
if (!
|
|
9020
|
+
if (!existsSync21(resolved)) {
|
|
8961
9021
|
return { success: false, output: t("file.not_found_short", { path }) };
|
|
8962
9022
|
}
|
|
8963
9023
|
const stat = statSync5(resolved);
|
|
@@ -10057,8 +10117,8 @@ var init_prompt_builder = __esm(() => {
|
|
|
10057
10117
|
});
|
|
10058
10118
|
|
|
10059
10119
|
// src/core/session-logger.ts
|
|
10060
|
-
import { join as
|
|
10061
|
-
import { readFileSync as
|
|
10120
|
+
import { join as join13 } from "path";
|
|
10121
|
+
import { readFileSync as readFileSync11, existsSync as existsSync22 } from "fs";
|
|
10062
10122
|
|
|
10063
10123
|
class SessionLogger {
|
|
10064
10124
|
session;
|
|
@@ -10266,10 +10326,10 @@ class SessionLogger {
|
|
|
10266
10326
|
logSessionStart(data) {
|
|
10267
10327
|
const meta = this.session?.getActiveMeta();
|
|
10268
10328
|
if (meta) {
|
|
10269
|
-
const logPath =
|
|
10329
|
+
const logPath = join13(this.session.getSessionDirectory(meta.id), "session.jsonl");
|
|
10270
10330
|
try {
|
|
10271
|
-
if (
|
|
10272
|
-
const content =
|
|
10331
|
+
if (existsSync22(logPath)) {
|
|
10332
|
+
const content = readFileSync11(logPath, "utf-8");
|
|
10273
10333
|
if (content.includes('"type":"session_start"'))
|
|
10274
10334
|
return;
|
|
10275
10335
|
}
|
|
@@ -11140,8 +11200,10 @@ ${PLAN_SYSTEM_PROMPT_RULES}`;
|
|
|
11140
11200
|
class OrchestratorClient {
|
|
11141
11201
|
config;
|
|
11142
11202
|
provider = null;
|
|
11143
|
-
|
|
11203
|
+
getSessionId;
|
|
11204
|
+
constructor(config, defaultProvider, opts) {
|
|
11144
11205
|
this.config = config;
|
|
11206
|
+
this.getSessionId = opts?.getSessionId;
|
|
11145
11207
|
if (!config.model)
|
|
11146
11208
|
return;
|
|
11147
11209
|
if (config.provider) {
|
|
@@ -11161,6 +11223,7 @@ class OrchestratorClient {
|
|
|
11161
11223
|
contextWindow: config.contextWindow ?? DEFAULT_ORCH_CONTEXT_WINDOW,
|
|
11162
11224
|
retry: config.retry,
|
|
11163
11225
|
rateLimits: config.rateLimits,
|
|
11226
|
+
getSessionId: this.getSessionId,
|
|
11164
11227
|
logger: config.logger
|
|
11165
11228
|
});
|
|
11166
11229
|
manager.setModel(config.model);
|
|
@@ -12186,7 +12249,7 @@ var init_stuck_detector = __esm(() => {
|
|
|
12186
12249
|
});
|
|
12187
12250
|
|
|
12188
12251
|
// src/modules/artifacts/store.ts
|
|
12189
|
-
import { existsSync as
|
|
12252
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync12, readFileSync as readFileSync12, writeFileSync as writeFileSync9 } from "node:fs";
|
|
12190
12253
|
import { resolve as resolve10, relative as relative2, isAbsolute as isAbsolute2 } from "node:path";
|
|
12191
12254
|
|
|
12192
12255
|
class ArtifactStore {
|
|
@@ -12224,9 +12287,9 @@ class ArtifactStore {
|
|
|
12224
12287
|
const abs = resolve10(this.root, path);
|
|
12225
12288
|
if (!ArtifactStore.isInside(this.root, abs))
|
|
12226
12289
|
return null;
|
|
12227
|
-
if (!
|
|
12290
|
+
if (!existsSync23(abs))
|
|
12228
12291
|
return null;
|
|
12229
|
-
return
|
|
12292
|
+
return readFileSync12(abs, "utf8");
|
|
12230
12293
|
}
|
|
12231
12294
|
summary(content, maxChars) {
|
|
12232
12295
|
if (content.length <= maxChars)
|
|
@@ -12726,23 +12789,23 @@ var init_moe_executor = __esm(() => {
|
|
|
12726
12789
|
});
|
|
12727
12790
|
|
|
12728
12791
|
// src/modules/lsp/project-root.ts
|
|
12729
|
-
import { existsSync as
|
|
12730
|
-
import { dirname as
|
|
12792
|
+
import { existsSync as existsSync24 } from "fs";
|
|
12793
|
+
import { dirname as dirname9, join as join14, relative as relative3, isAbsolute as isAbsolute3 } from "path";
|
|
12731
12794
|
function findProjectRoot(filePath, baseDir, markers) {
|
|
12732
12795
|
if (!markers || markers.length === 0)
|
|
12733
12796
|
return baseDir;
|
|
12734
|
-
let dir =
|
|
12797
|
+
let dir = dirname9(filePath);
|
|
12735
12798
|
const root = baseDir.replace(/[\\/]+$/, "");
|
|
12736
12799
|
const rel = relative3(root, dir);
|
|
12737
12800
|
if (rel && rel.startsWith("..") || isAbsolute3(rel))
|
|
12738
12801
|
dir = root;
|
|
12739
12802
|
while (true) {
|
|
12740
|
-
if (markers.some((m) =>
|
|
12803
|
+
if (markers.some((m) => existsSync24(join14(dir, m)))) {
|
|
12741
12804
|
return dir;
|
|
12742
12805
|
}
|
|
12743
12806
|
if (dir === root)
|
|
12744
12807
|
return dir;
|
|
12745
|
-
const parent =
|
|
12808
|
+
const parent = dirname9(dir);
|
|
12746
12809
|
if (parent === dir)
|
|
12747
12810
|
return root;
|
|
12748
12811
|
dir = parent;
|
|
@@ -12960,13 +13023,13 @@ var init_js_identifiers = __esm(() => {
|
|
|
12960
13023
|
});
|
|
12961
13024
|
|
|
12962
13025
|
// src/modules/execution/audit-runners.ts
|
|
12963
|
-
import { existsSync as
|
|
12964
|
-
import { dirname as
|
|
13026
|
+
import { existsSync as existsSync25, readdirSync as readdirSync6, readFileSync as readFileSync13 } from "fs";
|
|
13027
|
+
import { dirname as dirname10, join as join15, resolve as resolve11 } from "path";
|
|
12965
13028
|
function resolveTestCommand(dir) {
|
|
12966
|
-
const pkgPath =
|
|
12967
|
-
if (
|
|
13029
|
+
const pkgPath = join15(dir, "package.json");
|
|
13030
|
+
if (existsSync25(pkgPath)) {
|
|
12968
13031
|
try {
|
|
12969
|
-
const pkg = JSON.parse(
|
|
13032
|
+
const pkg = JSON.parse(readFileSync13(pkgPath, "utf-8"));
|
|
12970
13033
|
const script = pkg?.scripts?.test;
|
|
12971
13034
|
if (typeof script === "string" && script.trim())
|
|
12972
13035
|
return script.trim();
|
|
@@ -12982,7 +13045,7 @@ function resolveTestCommand(dir) {
|
|
|
12982
13045
|
"jest.config.cjs",
|
|
12983
13046
|
"bunfig.toml"
|
|
12984
13047
|
]) {
|
|
12985
|
-
if (
|
|
13048
|
+
if (existsSync25(join15(dir, f))) {
|
|
12986
13049
|
if (f.startsWith("vitest"))
|
|
12987
13050
|
return "bunx vitest run";
|
|
12988
13051
|
if (f.startsWith("jest"))
|
|
@@ -12991,12 +13054,12 @@ function resolveTestCommand(dir) {
|
|
|
12991
13054
|
return "bun test";
|
|
12992
13055
|
}
|
|
12993
13056
|
}
|
|
12994
|
-
if (
|
|
13057
|
+
if (existsSync25(join15(dir, "pyproject.toml")) || existsSync25(join15(dir, "pytest.ini")) || existsSync25(join15(dir, "conftest.py"))) {
|
|
12995
13058
|
return "python -m pytest -q";
|
|
12996
13059
|
}
|
|
12997
|
-
if (
|
|
13060
|
+
if (existsSync25(join15(dir, "go.mod")))
|
|
12998
13061
|
return "go test ./...";
|
|
12999
|
-
if (
|
|
13062
|
+
if (existsSync25(join15(dir, "Cargo.toml")))
|
|
13000
13063
|
return "cargo test";
|
|
13001
13064
|
return "bun test";
|
|
13002
13065
|
}
|
|
@@ -13010,7 +13073,7 @@ function findTestFile(dir, depth = 0) {
|
|
|
13010
13073
|
return null;
|
|
13011
13074
|
}
|
|
13012
13075
|
for (const e of entries) {
|
|
13013
|
-
const full =
|
|
13076
|
+
const full = join15(dir, e.name);
|
|
13014
13077
|
if (e.isDirectory()) {
|
|
13015
13078
|
if (SKIP_DIRS.has(e.name))
|
|
13016
13079
|
continue;
|
|
@@ -13086,12 +13149,12 @@ function findTypecheckRoot(baseDir, existingFiles = []) {
|
|
|
13086
13149
|
for (const start of candidates) {
|
|
13087
13150
|
let dir = resolve11(start);
|
|
13088
13151
|
for (let depth = 0;depth <= 10; depth++) {
|
|
13089
|
-
if (
|
|
13152
|
+
if (existsSync25(join15(dir, "tsconfig.json"))) {
|
|
13090
13153
|
if (!best || depth < best.depth)
|
|
13091
13154
|
best = { depth, root: dir };
|
|
13092
13155
|
break;
|
|
13093
13156
|
}
|
|
13094
|
-
const parent =
|
|
13157
|
+
const parent = dirname10(dir);
|
|
13095
13158
|
if (parent === dir)
|
|
13096
13159
|
break;
|
|
13097
13160
|
dir = parent;
|
|
@@ -13130,11 +13193,11 @@ var init_audit_runners = __esm(() => {
|
|
|
13130
13193
|
});
|
|
13131
13194
|
|
|
13132
13195
|
// src/modules/execution/auditor.ts
|
|
13133
|
-
import { existsSync as
|
|
13134
|
-
import { resolve as resolve12, join as
|
|
13196
|
+
import { existsSync as existsSync26, readdirSync as readdirSync7 } from "fs";
|
|
13197
|
+
import { resolve as resolve12, join as join16, basename as basename2 } from "path";
|
|
13135
13198
|
function findExistingFile(baseDir, filePath) {
|
|
13136
13199
|
const direct = resolve12(baseDir, filePath);
|
|
13137
|
-
if (
|
|
13200
|
+
if (existsSync26(direct))
|
|
13138
13201
|
return direct;
|
|
13139
13202
|
const name = basename2(filePath).toLowerCase();
|
|
13140
13203
|
const suffix = toForwardSlash(filePath).toLowerCase();
|
|
@@ -13151,7 +13214,7 @@ function findExistingFile(baseDir, filePath) {
|
|
|
13151
13214
|
for (const e of entries) {
|
|
13152
13215
|
if (found)
|
|
13153
13216
|
return;
|
|
13154
|
-
const full =
|
|
13217
|
+
const full = join16(dir, e.name);
|
|
13155
13218
|
if (e.isDirectory()) {
|
|
13156
13219
|
if (SKIP_DIRS.has(e.name))
|
|
13157
13220
|
continue;
|
|
@@ -13290,8 +13353,8 @@ var init_auditor = __esm(() => {
|
|
|
13290
13353
|
});
|
|
13291
13354
|
|
|
13292
13355
|
// src/modules/execution/verifier.ts
|
|
13293
|
-
import { existsSync as
|
|
13294
|
-
import { resolve as resolve13, extname as extname3, join as
|
|
13356
|
+
import { existsSync as existsSync27, readFileSync as readFileSync14 } from "fs";
|
|
13357
|
+
import { resolve as resolve13, extname as extname3, join as join17 } from "path";
|
|
13295
13358
|
import { spawn as spawn4 } from "child_process";
|
|
13296
13359
|
|
|
13297
13360
|
class StepVerifier {
|
|
@@ -13301,7 +13364,7 @@ class StepVerifier {
|
|
|
13301
13364
|
}
|
|
13302
13365
|
async checkFileExists(path) {
|
|
13303
13366
|
const resolved = resolve13(this.baseDir, path);
|
|
13304
|
-
const exists =
|
|
13367
|
+
const exists = existsSync27(resolved);
|
|
13305
13368
|
return {
|
|
13306
13369
|
passed: exists,
|
|
13307
13370
|
message: exists ? t("verify.file_exists", { path }) : t("verify.file_not_found", { path })
|
|
@@ -13320,7 +13383,7 @@ class StepVerifier {
|
|
|
13320
13383
|
}
|
|
13321
13384
|
async runTypeCheck() {
|
|
13322
13385
|
const tsconfigPath = resolve13(this.baseDir, "tsconfig.json");
|
|
13323
|
-
if (!
|
|
13386
|
+
if (!existsSync27(tsconfigPath)) {
|
|
13324
13387
|
return { passed: true, message: "No tsconfig.json found — skipping type check" };
|
|
13325
13388
|
}
|
|
13326
13389
|
try {
|
|
@@ -13333,8 +13396,8 @@ class StepVerifier {
|
|
|
13333
13396
|
}
|
|
13334
13397
|
async runTypeCheckForFile(filePath) {
|
|
13335
13398
|
const projectRoot = findProjectRoot(filePath, this.baseDir, ["tsconfig.json", "package.json"]);
|
|
13336
|
-
const tsconfigPath =
|
|
13337
|
-
if (!
|
|
13399
|
+
const tsconfigPath = join17(projectRoot, "tsconfig.json");
|
|
13400
|
+
if (!existsSync27(tsconfigPath)) {
|
|
13338
13401
|
return { passed: true, message: "No tsconfig.json found — skipping type check" };
|
|
13339
13402
|
}
|
|
13340
13403
|
try {
|
|
@@ -13347,7 +13410,7 @@ class StepVerifier {
|
|
|
13347
13410
|
}
|
|
13348
13411
|
async runTests() {
|
|
13349
13412
|
const pkgPath = resolve13(this.baseDir, "package.json");
|
|
13350
|
-
if (!
|
|
13413
|
+
if (!existsSync27(pkgPath)) {
|
|
13351
13414
|
return { passed: true, message: "No package.json found — skipping tests" };
|
|
13352
13415
|
}
|
|
13353
13416
|
try {
|
|
@@ -13389,13 +13452,13 @@ class StepVerifier {
|
|
|
13389
13452
|
const path = rest.slice(0, colon);
|
|
13390
13453
|
const needle = rest.slice(colon + 1);
|
|
13391
13454
|
const resolved = resolve13(this.baseDir, path);
|
|
13392
|
-
if (!
|
|
13455
|
+
if (!existsSync27(resolved)) {
|
|
13393
13456
|
const item = { passed: false, message: t("verify.file_not_found", { path }) };
|
|
13394
13457
|
details.push(item);
|
|
13395
13458
|
errors.push(`[${subtask.id}] ${item.message}`);
|
|
13396
13459
|
continue;
|
|
13397
13460
|
}
|
|
13398
|
-
const content =
|
|
13461
|
+
const content = readFileSync14(resolved, "utf-8");
|
|
13399
13462
|
const passed = content.includes(needle);
|
|
13400
13463
|
details.push({ passed, message: `substring "${needle}" in ${path}: ${passed}` });
|
|
13401
13464
|
if (!passed)
|
|
@@ -13581,7 +13644,7 @@ async function runWithMoE(deps, input, fallback, opts = {}) {
|
|
|
13581
13644
|
rateLimits: config.security?.rateLimits,
|
|
13582
13645
|
logger,
|
|
13583
13646
|
experts: config.experts
|
|
13584
|
-
}, llmProvider);
|
|
13647
|
+
}, llmProvider, { getSessionId: () => sessionId });
|
|
13585
13648
|
}
|
|
13586
13649
|
if (!orchestrator.isEnabled()) {
|
|
13587
13650
|
logger.warn("MoE enabled but no orchestrator model configured — falling back to single-agent. Set orchestrator.model to activate MoE.");
|
|
@@ -14582,8 +14645,8 @@ var init_audit_gate = __esm(() => {
|
|
|
14582
14645
|
|
|
14583
14646
|
// src/core/prompt-overflow.ts
|
|
14584
14647
|
import { createHash } from "crypto";
|
|
14585
|
-
import { existsSync as
|
|
14586
|
-
import { join as
|
|
14648
|
+
import { existsSync as existsSync28, mkdirSync as mkdirSync13, readFileSync as readFileSync15, writeFileSync as writeFileSync10 } from "fs";
|
|
14649
|
+
import { join as join18 } from "path";
|
|
14587
14650
|
function dryRunOverflow(allBlocks, systemBudget) {
|
|
14588
14651
|
const builder = new PromptBuilder(systemBudget);
|
|
14589
14652
|
builder.addBlocks(allBlocks);
|
|
@@ -14597,10 +14660,10 @@ function cacheKey(kind, content, maxTokens) {
|
|
|
14597
14660
|
}
|
|
14598
14661
|
function readCache(cacheDir, key) {
|
|
14599
14662
|
try {
|
|
14600
|
-
const path =
|
|
14601
|
-
if (!
|
|
14663
|
+
const path = join18(cacheDir, `${key}.md`);
|
|
14664
|
+
if (!existsSync28(path))
|
|
14602
14665
|
return null;
|
|
14603
|
-
const raw =
|
|
14666
|
+
const raw = readFileSync15(path, "utf-8").trim();
|
|
14604
14667
|
if (!raw)
|
|
14605
14668
|
return null;
|
|
14606
14669
|
try {
|
|
@@ -14618,7 +14681,7 @@ function readCache(cacheDir, key) {
|
|
|
14618
14681
|
function writeCache(cacheDir, key, entry) {
|
|
14619
14682
|
try {
|
|
14620
14683
|
mkdirSync13(cacheDir, { recursive: true });
|
|
14621
|
-
writeFileSync10(
|
|
14684
|
+
writeFileSync10(join18(cacheDir, `${key}.md`), JSON.stringify(entry), "utf-8");
|
|
14622
14685
|
} catch {}
|
|
14623
14686
|
}
|
|
14624
14687
|
async function collectText(provider, prompt, maxTokens) {
|
|
@@ -14778,12 +14841,39 @@ function contextWindowHint(config, configDir, recommended) {
|
|
|
14778
14841
|
if (src.source === "global") {
|
|
14779
14842
|
return `run "mma context ${recommended}"`;
|
|
14780
14843
|
}
|
|
14781
|
-
return `edit "${
|
|
14844
|
+
return `edit "${join18(configDir, "config", "provider.json")}" → provider.entries[label="${src.label}"].contextWindow = ${recommended}`;
|
|
14782
14845
|
}
|
|
14783
14846
|
function recommendContextSize(neededSystemTokens) {
|
|
14784
14847
|
const sizes = [8192, 16384, 32768, 65536, 131072, 262144];
|
|
14785
14848
|
return sizes.find((s) => Math.floor(s * 0.1) >= neededSystemTokens) ?? sizes[sizes.length - 1];
|
|
14786
14849
|
}
|
|
14850
|
+
function requiredContextWindow(neededTokens, systemFraction) {
|
|
14851
|
+
const fraction = systemFraction > 0 ? systemFraction : 0.1;
|
|
14852
|
+
return Math.ceil(neededTokens / fraction);
|
|
14853
|
+
}
|
|
14854
|
+
function requiredSystemFraction(neededTokens, contextWindow) {
|
|
14855
|
+
if (contextWindow <= 0)
|
|
14856
|
+
return 1;
|
|
14857
|
+
return Math.min(1, Math.ceil(neededTokens / contextWindow * 100) / 100);
|
|
14858
|
+
}
|
|
14859
|
+
function overflowHint(config, configDir, neededTokens) {
|
|
14860
|
+
const fraction = config.contextBudget?.systemPrompt ?? 0.1;
|
|
14861
|
+
const budget = Math.floor(config.contextWindow * fraction);
|
|
14862
|
+
const recommended = recommendContextSize(neededTokens);
|
|
14863
|
+
const requiredWindow = requiredContextWindow(neededTokens, fraction);
|
|
14864
|
+
const requiredFraction = requiredSystemFraction(neededTokens, config.contextWindow);
|
|
14865
|
+
const how = configDir ? contextWindowHint(config, configDir, recommended) : `increase contextWindow (e.g. to ${recommended})`;
|
|
14866
|
+
return [
|
|
14867
|
+
t("prompt.overflow.hint_needed", {
|
|
14868
|
+
needed: neededTokens,
|
|
14869
|
+
window: config.contextWindow,
|
|
14870
|
+
fraction,
|
|
14871
|
+
budget
|
|
14872
|
+
}),
|
|
14873
|
+
t("prompt.overflow.hint_window", { required: requiredWindow, recommended, how }),
|
|
14874
|
+
t("prompt.overflow.hint_fraction", { fraction: requiredFraction })
|
|
14875
|
+
].join(" ");
|
|
14876
|
+
}
|
|
14787
14877
|
var HINT_BLOCK_TOKENS = 60, CHARS_PER_TOKEN = 4, KIND_ORDER, KIND_LABEL, KIND_SOURCE_FILE;
|
|
14788
14878
|
var init_prompt_overflow = __esm(() => {
|
|
14789
14879
|
init_prompt_builder();
|
|
@@ -14801,7 +14891,7 @@ var init_prompt_overflow = __esm(() => {
|
|
|
14801
14891
|
});
|
|
14802
14892
|
|
|
14803
14893
|
// src/core/agent.ts
|
|
14804
|
-
import { join as
|
|
14894
|
+
import { join as join19 } from "path";
|
|
14805
14895
|
function mutationTargetKey(name, rawArgs) {
|
|
14806
14896
|
let a = null;
|
|
14807
14897
|
if (typeof rawArgs === "string") {
|
|
@@ -14956,7 +15046,7 @@ class Agent {
|
|
|
14956
15046
|
includedTokens: dry.blocks.filter((b) => b.included).reduce((s, b) => s + b.tokens, 0),
|
|
14957
15047
|
systemBudget,
|
|
14958
15048
|
provider: cfg.instructions?.summarize === false ? null : this.deps.llmProvider,
|
|
14959
|
-
cacheDir:
|
|
15049
|
+
cacheDir: join19(this.deps.baseDir, ".mma", "cache", "prompt-summaries"),
|
|
14960
15050
|
logger: this.deps.logger
|
|
14961
15051
|
});
|
|
14962
15052
|
for (const r of res.replacements) {
|
|
@@ -14964,8 +15054,8 @@ class Agent {
|
|
|
14964
15054
|
this.promptOverrides.set(r.kind, r);
|
|
14965
15055
|
}
|
|
14966
15056
|
this.overflowHintBlock = res.hintBlock;
|
|
14967
|
-
const
|
|
14968
|
-
const hint =
|
|
15057
|
+
const needed = dry.blocks.filter((b) => b.included).reduce((s, b) => s + b.tokens, 0) + overflow.reduce((s, b) => s + b.estimatedTokens, 0) + HINT_BLOCK_TOKENS;
|
|
15058
|
+
const hint = overflowHint(cfg, this.deps.configDir, needed);
|
|
14969
15059
|
for (const w of res.warnings) {
|
|
14970
15060
|
this.deps.logger.warn(t("prompt.overflow.exceeded", {
|
|
14971
15061
|
label: w.label,
|
|
@@ -15459,7 +15549,9 @@ class Agent {
|
|
|
15459
15549
|
}
|
|
15460
15550
|
async reconfigure(config) {
|
|
15461
15551
|
const { TokenCounter: TokenCounter2 } = await Promise.resolve().then(() => (init_token_counter(), exports_token_counter));
|
|
15462
|
-
const { provider: newProvider } = buildActiveProvider(config, this.deps.logger
|
|
15552
|
+
const { provider: newProvider } = buildActiveProvider(config, this.deps.logger, {
|
|
15553
|
+
getSessionId: () => this.deps.sessionManager?.getActiveMeta()?.id
|
|
15554
|
+
});
|
|
15463
15555
|
this.deps.llmProvider = newProvider;
|
|
15464
15556
|
this.deps.toolExecutor.updateProvider(newProvider);
|
|
15465
15557
|
const newTokenCounter = new TokenCounter2(config.model);
|
|
@@ -15470,7 +15562,9 @@ class Agent {
|
|
|
15470
15562
|
this.costTracker.setModel(config.model);
|
|
15471
15563
|
}
|
|
15472
15564
|
setProvider(name, model) {
|
|
15473
|
-
const { manager, provider } = buildActiveProvider(this.deps.config, this.deps.logger
|
|
15565
|
+
const { manager, provider } = buildActiveProvider(this.deps.config, this.deps.logger, {
|
|
15566
|
+
getSessionId: () => this.deps.sessionManager?.getActiveMeta()?.id
|
|
15567
|
+
});
|
|
15474
15568
|
manager.switch(name, model);
|
|
15475
15569
|
const providerCfg = manager.toConfig();
|
|
15476
15570
|
this.deps.config.provider = providerCfg;
|
|
@@ -15481,7 +15575,8 @@ class Agent {
|
|
|
15481
15575
|
const manager = new ProviderManager(this.deps.config.provider, {
|
|
15482
15576
|
contextWindow: this.deps.config.contextWindow,
|
|
15483
15577
|
retry: this.deps.config.retry,
|
|
15484
|
-
rateLimits: this.deps.config.security?.rateLimits
|
|
15578
|
+
rateLimits: this.deps.config.security?.rateLimits,
|
|
15579
|
+
getSessionId: () => this.deps.sessionManager?.getActiveMeta()?.id
|
|
15485
15580
|
});
|
|
15486
15581
|
const activeName = this.deps.config.provider.active;
|
|
15487
15582
|
return manager.list().map((e) => ({
|
|
@@ -15495,6 +15590,7 @@ class Agent {
|
|
|
15495
15590
|
contextWindow: this.deps.config.contextWindow,
|
|
15496
15591
|
retry: this.deps.config.retry,
|
|
15497
15592
|
rateLimits: this.deps.config.security?.rateLimits,
|
|
15593
|
+
getSessionId: () => this.deps.sessionManager?.getActiveMeta()?.id,
|
|
15498
15594
|
logger: this.deps.logger
|
|
15499
15595
|
});
|
|
15500
15596
|
manager.setModel(this.deps.config.model);
|
|
@@ -16134,8 +16230,8 @@ var init_confidence = __esm(() => {
|
|
|
16134
16230
|
});
|
|
16135
16231
|
|
|
16136
16232
|
// src/modules/hallucination/factual.ts
|
|
16137
|
-
import { existsSync as
|
|
16138
|
-
import { resolve as resolve14, isAbsolute as isAbsolute4, join as
|
|
16233
|
+
import { existsSync as existsSync29, readdirSync as readdirSync8 } from "fs";
|
|
16234
|
+
import { resolve as resolve14, isAbsolute as isAbsolute4, join as join20 } from "path";
|
|
16139
16235
|
|
|
16140
16236
|
class FactualCheck {
|
|
16141
16237
|
baseDir;
|
|
@@ -16178,13 +16274,13 @@ class FactualCheck {
|
|
|
16178
16274
|
}
|
|
16179
16275
|
pathExists(fp) {
|
|
16180
16276
|
if (isAbsolute4(fp))
|
|
16181
|
-
return
|
|
16277
|
+
return existsSync29(fp);
|
|
16182
16278
|
if (this.knownFiles.has(fp))
|
|
16183
16279
|
return true;
|
|
16184
16280
|
for (const cand of this.dotfileVariants(fp)) {
|
|
16185
16281
|
if (this.knownFiles.has(cand))
|
|
16186
16282
|
return true;
|
|
16187
|
-
if (
|
|
16283
|
+
if (existsSync29(resolve14(this.baseDir, cand)))
|
|
16188
16284
|
return true;
|
|
16189
16285
|
}
|
|
16190
16286
|
if (!fp.includes("/") && !fp.includes("\\")) {
|
|
@@ -16212,7 +16308,7 @@ class FactualCheck {
|
|
|
16212
16308
|
}
|
|
16213
16309
|
bareNameExists(name) {
|
|
16214
16310
|
for (const cand of this.dotfileVariants(name)) {
|
|
16215
|
-
if (
|
|
16311
|
+
if (existsSync29(resolve14(this.baseDir, cand)))
|
|
16216
16312
|
return true;
|
|
16217
16313
|
if (this.indexHas(cand))
|
|
16218
16314
|
return true;
|
|
@@ -16258,7 +16354,7 @@ class FactualCheck {
|
|
|
16258
16354
|
for (const entry of entries) {
|
|
16259
16355
|
if (count >= FactualCheck.MAX_INDEXED_FILES)
|
|
16260
16356
|
break;
|
|
16261
|
-
const full =
|
|
16357
|
+
const full = join20(dir, entry.name);
|
|
16262
16358
|
if (entry.isDirectory()) {
|
|
16263
16359
|
if (!IGNORED_DIRS2.has(entry.name)) {
|
|
16264
16360
|
count = this.scanDir(full, index, count);
|
|
@@ -16440,8 +16536,8 @@ var init_detector = __esm(() => {
|
|
|
16440
16536
|
});
|
|
16441
16537
|
|
|
16442
16538
|
// src/modules/lsp/command.ts
|
|
16443
|
-
import { delimiter, join as
|
|
16444
|
-
import { existsSync as
|
|
16539
|
+
import { delimiter, join as join21 } from "path";
|
|
16540
|
+
import { existsSync as existsSync30 } from "fs";
|
|
16445
16541
|
import { platform as platform4 } from "os";
|
|
16446
16542
|
function resolveSpawnCommand(command, platformName = platform4(), pathEnv = process.env.PATH ?? "") {
|
|
16447
16543
|
if (platformName !== "win32")
|
|
@@ -16452,8 +16548,8 @@ function resolveSpawnCommand(command, platformName = platform4(), pathEnv = proc
|
|
|
16452
16548
|
const dirs = pathEnv.split(delimiter).filter(Boolean);
|
|
16453
16549
|
for (const dir of dirs) {
|
|
16454
16550
|
for (const ext of WIN_EXTS) {
|
|
16455
|
-
const candidate =
|
|
16456
|
-
if (
|
|
16551
|
+
const candidate = join21(dir, `${command}${ext}`);
|
|
16552
|
+
if (existsSync30(candidate))
|
|
16457
16553
|
return `${command}${ext}`;
|
|
16458
16554
|
}
|
|
16459
16555
|
}
|
|
@@ -17097,7 +17193,7 @@ var init_chunk_query = __esm(() => {
|
|
|
17097
17193
|
});
|
|
17098
17194
|
|
|
17099
17195
|
// src/tools/chunk-query.ts
|
|
17100
|
-
import { readFileSync as
|
|
17196
|
+
import { readFileSync as readFileSync16 } from "node:fs";
|
|
17101
17197
|
import { resolve as resolve15 } from "node:path";
|
|
17102
17198
|
var chunkQueryTool;
|
|
17103
17199
|
var init_chunk_query2 = __esm(() => {
|
|
@@ -17170,7 +17266,7 @@ var init_chunk_query2 = __esm(() => {
|
|
|
17170
17266
|
return { success: false, output: `[SCOPE] ${check.reason || "Path not allowed"}` };
|
|
17171
17267
|
}
|
|
17172
17268
|
try {
|
|
17173
|
-
content =
|
|
17269
|
+
content = readFileSync16(resolvedInput, "utf8");
|
|
17174
17270
|
} catch (e) {
|
|
17175
17271
|
return { success: false, output: `Cannot read ${inputPath}: ${e.message}` };
|
|
17176
17272
|
}
|
|
@@ -17623,7 +17719,7 @@ var init_web_browse = __esm(() => {
|
|
|
17623
17719
|
|
|
17624
17720
|
// src/tools/download-file.ts
|
|
17625
17721
|
import { writeFileSync as writeFileSync11, mkdirSync as mkdirSync14 } from "fs";
|
|
17626
|
-
import { dirname as
|
|
17722
|
+
import { dirname as dirname12 } from "path";
|
|
17627
17723
|
var MAX_DOWNLOAD_BYTES, downloadFileTool;
|
|
17628
17724
|
var init_download_file = __esm(() => {
|
|
17629
17725
|
init_i18n();
|
|
@@ -17711,7 +17807,7 @@ var init_download_file = __esm(() => {
|
|
|
17711
17807
|
output: t("tool.download_too_large", { max: String(maxBytes) })
|
|
17712
17808
|
};
|
|
17713
17809
|
}
|
|
17714
|
-
mkdirSync14(
|
|
17810
|
+
mkdirSync14(dirname12(resolved), { recursive: true });
|
|
17715
17811
|
writeFileSync11(resolved, buffer);
|
|
17716
17812
|
const contentType = response.headers.get("content-type")?.split(";")[0]?.trim() || "unknown";
|
|
17717
17813
|
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), true, `Status: ${response.status}`);
|
|
@@ -18578,7 +18674,7 @@ ${JSON.stringify(result, null, 2)}`
|
|
|
18578
18674
|
|
|
18579
18675
|
// src/tools/search-history.ts
|
|
18580
18676
|
import * as fs from "fs";
|
|
18581
|
-
import { join as
|
|
18677
|
+
import { join as join22 } from "path";
|
|
18582
18678
|
import { homedir as homedir6 } from "os";
|
|
18583
18679
|
function searchFile(filePath, query, maxResults, results) {
|
|
18584
18680
|
if (!fs.existsSync(filePath))
|
|
@@ -18623,7 +18719,7 @@ var init_search_history = __esm(() => {
|
|
|
18623
18719
|
const query = String(args.query || "").toLowerCase();
|
|
18624
18720
|
const maxResults = Number(args.maxResults) || 5;
|
|
18625
18721
|
const sessionId = args.sessionId ? String(args.sessionId) : null;
|
|
18626
|
-
const sessionDir =
|
|
18722
|
+
const sessionDir = join22(homedir6(), ".mma", "sessions");
|
|
18627
18723
|
const results = [];
|
|
18628
18724
|
try {
|
|
18629
18725
|
if (!fs.existsSync(sessionDir)) {
|
|
@@ -18638,7 +18734,7 @@ var init_search_history = __esm(() => {
|
|
|
18638
18734
|
continue;
|
|
18639
18735
|
if (sessionId && entry.name !== sessionId)
|
|
18640
18736
|
continue;
|
|
18641
|
-
const historyFile =
|
|
18737
|
+
const historyFile = join22(sessionDir, entry.name, "history.jsonl");
|
|
18642
18738
|
searchFile(historyFile, query, maxResults, results);
|
|
18643
18739
|
if (results.length >= maxResults)
|
|
18644
18740
|
break;
|
|
@@ -18665,8 +18761,8 @@ var init_search_history = __esm(() => {
|
|
|
18665
18761
|
});
|
|
18666
18762
|
|
|
18667
18763
|
// src/modules/memory/search.ts
|
|
18668
|
-
import { readFileSync as
|
|
18669
|
-
import { join as
|
|
18764
|
+
import { readFileSync as readFileSync18, existsSync as existsSync32 } from "fs";
|
|
18765
|
+
import { join as join23 } from "path";
|
|
18670
18766
|
|
|
18671
18767
|
class MemorySearch {
|
|
18672
18768
|
memoryDir;
|
|
@@ -18677,10 +18773,10 @@ class MemorySearch {
|
|
|
18677
18773
|
const results = [];
|
|
18678
18774
|
const lowerQuery = query.toLowerCase();
|
|
18679
18775
|
for (const name of MEMORY_FILES) {
|
|
18680
|
-
const path =
|
|
18681
|
-
if (!
|
|
18776
|
+
const path = join23(this.memoryDir, `${name}.md`);
|
|
18777
|
+
if (!existsSync32(path))
|
|
18682
18778
|
continue;
|
|
18683
|
-
const content =
|
|
18779
|
+
const content = readFileSync18(path, "utf-8");
|
|
18684
18780
|
const lines = content.split(`
|
|
18685
18781
|
`);
|
|
18686
18782
|
for (const line of lines) {
|
|
@@ -18689,10 +18785,10 @@ class MemorySearch {
|
|
|
18689
18785
|
}
|
|
18690
18786
|
}
|
|
18691
18787
|
}
|
|
18692
|
-
const prefsPath =
|
|
18693
|
-
if (
|
|
18788
|
+
const prefsPath = join23(this.memoryDir, "preferences.json");
|
|
18789
|
+
if (existsSync32(prefsPath)) {
|
|
18694
18790
|
try {
|
|
18695
|
-
const prefs = JSON.parse(
|
|
18791
|
+
const prefs = JSON.parse(readFileSync18(prefsPath, "utf-8"));
|
|
18696
18792
|
for (const [key, value] of Object.entries(prefs)) {
|
|
18697
18793
|
const searchStr = `${key}=${value}`;
|
|
18698
18794
|
if (searchStr.toLowerCase().includes(lowerQuery)) {
|
|
@@ -18710,8 +18806,8 @@ var init_search = __esm(() => {
|
|
|
18710
18806
|
});
|
|
18711
18807
|
|
|
18712
18808
|
// src/modules/memory/store.ts
|
|
18713
|
-
import { readFileSync as
|
|
18714
|
-
import { join as
|
|
18809
|
+
import { readFileSync as readFileSync19, writeFileSync as writeFileSync12, appendFileSync as appendFileSync5, existsSync as existsSync33, mkdirSync as mkdirSync15 } from "fs";
|
|
18810
|
+
import { join as join24 } from "path";
|
|
18715
18811
|
|
|
18716
18812
|
class MemoryStore {
|
|
18717
18813
|
memoryDir;
|
|
@@ -18719,8 +18815,8 @@ class MemoryStore {
|
|
|
18719
18815
|
this.memoryDir = memoryDir;
|
|
18720
18816
|
this.ensureDir();
|
|
18721
18817
|
for (const name of MEMORY_FILES2) {
|
|
18722
|
-
const path =
|
|
18723
|
-
if (!
|
|
18818
|
+
const path = join24(this.memoryDir, `${name}.md`);
|
|
18819
|
+
if (!existsSync33(path)) {
|
|
18724
18820
|
writeFileSync12(path, `# ${name.charAt(0).toUpperCase() + name.slice(1)}
|
|
18725
18821
|
|
|
18726
18822
|
`, "utf-8");
|
|
@@ -18728,18 +18824,18 @@ class MemoryStore {
|
|
|
18728
18824
|
}
|
|
18729
18825
|
}
|
|
18730
18826
|
ensureDir() {
|
|
18731
|
-
if (!
|
|
18827
|
+
if (!existsSync33(this.memoryDir)) {
|
|
18732
18828
|
mkdirSync15(this.memoryDir, { recursive: true });
|
|
18733
18829
|
}
|
|
18734
18830
|
}
|
|
18735
18831
|
read(name) {
|
|
18736
|
-
const path =
|
|
18737
|
-
if (!
|
|
18832
|
+
const path = join24(this.memoryDir, `${name}.md`);
|
|
18833
|
+
if (!existsSync33(path))
|
|
18738
18834
|
return "";
|
|
18739
|
-
return
|
|
18835
|
+
return readFileSync19(path, "utf-8");
|
|
18740
18836
|
}
|
|
18741
18837
|
append(name, entry) {
|
|
18742
|
-
const path =
|
|
18838
|
+
const path = join24(this.memoryDir, `${name}.md`);
|
|
18743
18839
|
const timestamp = new Date().toISOString().replace("T", " ").slice(0, 19);
|
|
18744
18840
|
const formatted = `- **${timestamp}** — ${entry}
|
|
18745
18841
|
`;
|
|
@@ -18750,14 +18846,14 @@ class MemoryStore {
|
|
|
18750
18846
|
return searchModule.query(query);
|
|
18751
18847
|
}
|
|
18752
18848
|
prefsPath() {
|
|
18753
|
-
return
|
|
18849
|
+
return join24(this.memoryDir, "preferences.json");
|
|
18754
18850
|
}
|
|
18755
18851
|
getPreferences() {
|
|
18756
18852
|
const path = this.prefsPath();
|
|
18757
|
-
if (!
|
|
18853
|
+
if (!existsSync33(path))
|
|
18758
18854
|
return {};
|
|
18759
18855
|
try {
|
|
18760
|
-
return JSON.parse(
|
|
18856
|
+
return JSON.parse(readFileSync19(path, "utf-8"));
|
|
18761
18857
|
} catch {
|
|
18762
18858
|
return {};
|
|
18763
18859
|
}
|
|
@@ -18790,7 +18886,7 @@ var init_store2 = __esm(() => {
|
|
|
18790
18886
|
|
|
18791
18887
|
// src/tools/remember.ts
|
|
18792
18888
|
import { homedir as homedir7 } from "os";
|
|
18793
|
-
import { join as
|
|
18889
|
+
import { join as join25 } from "path";
|
|
18794
18890
|
var CATEGORIES, rememberTool;
|
|
18795
18891
|
var init_remember = __esm(() => {
|
|
18796
18892
|
init_i18n();
|
|
@@ -18829,7 +18925,7 @@ var init_remember = __esm(() => {
|
|
|
18829
18925
|
if (!CATEGORIES.includes(category)) {
|
|
18830
18926
|
return { success: false, output: t("tool.invalid_params") };
|
|
18831
18927
|
}
|
|
18832
|
-
const memoryDir =
|
|
18928
|
+
const memoryDir = join25(homedir7(), ".mma", "memory");
|
|
18833
18929
|
const store = new MemoryStore(memoryDir);
|
|
18834
18930
|
try {
|
|
18835
18931
|
if (category === "preferences") {
|
|
@@ -18862,7 +18958,7 @@ var init_remember = __esm(() => {
|
|
|
18862
18958
|
|
|
18863
18959
|
// src/tools/recall.ts
|
|
18864
18960
|
import { homedir as homedir8 } from "os";
|
|
18865
|
-
import { join as
|
|
18961
|
+
import { join as join26 } from "path";
|
|
18866
18962
|
function formatAll(store) {
|
|
18867
18963
|
const parts = [];
|
|
18868
18964
|
const prefs = store.getPreferences();
|
|
@@ -18946,7 +19042,7 @@ var init_recall = __esm(() => {
|
|
|
18946
19042
|
handler: async (_ctx, args) => {
|
|
18947
19043
|
const query = args.query ? String(args.query) : "";
|
|
18948
19044
|
const category = args.category ? String(args.category) : "";
|
|
18949
|
-
const memoryDir =
|
|
19045
|
+
const memoryDir = join26(homedir8(), ".mma", "memory");
|
|
18950
19046
|
const store = new MemoryStore(memoryDir);
|
|
18951
19047
|
try {
|
|
18952
19048
|
if (!query && !category) {
|
|
@@ -18984,9 +19080,9 @@ var init_recall = __esm(() => {
|
|
|
18984
19080
|
});
|
|
18985
19081
|
|
|
18986
19082
|
// src/modules/browser/bridge-path.ts
|
|
18987
|
-
import { existsSync as
|
|
19083
|
+
import { existsSync as existsSync34 } from "fs";
|
|
18988
19084
|
function pickExistingPath(candidates, fallback = candidates[0]) {
|
|
18989
|
-
return candidates.find((p) =>
|
|
19085
|
+
return candidates.find((p) => existsSync34(p)) ?? fallback;
|
|
18990
19086
|
}
|
|
18991
19087
|
var init_bridge_path = () => {};
|
|
18992
19088
|
|
|
@@ -18997,13 +19093,13 @@ __export(exports_bridge_client, {
|
|
|
18997
19093
|
});
|
|
18998
19094
|
import { spawn as spawn6 } from "child_process";
|
|
18999
19095
|
import { createInterface } from "readline";
|
|
19000
|
-
import { dirname as
|
|
19001
|
-
import { fileURLToPath } from "url";
|
|
19096
|
+
import { dirname as dirname13, join as join27 } from "path";
|
|
19097
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
19002
19098
|
function bridgeScriptPath() {
|
|
19003
|
-
const dir =
|
|
19099
|
+
const dir = dirname13(fileURLToPath2(import.meta.url));
|
|
19004
19100
|
const candidates = [
|
|
19005
|
-
|
|
19006
|
-
|
|
19101
|
+
join27(dir, "bridge-server.mjs"),
|
|
19102
|
+
join27(dir, "modules", "browser", "bridge-server.mjs")
|
|
19007
19103
|
];
|
|
19008
19104
|
return pickExistingPath(candidates);
|
|
19009
19105
|
}
|
|
@@ -19557,15 +19653,15 @@ function buildTextExtractionScript() {
|
|
|
19557
19653
|
|
|
19558
19654
|
// src/modules/browser/cookie-store.ts
|
|
19559
19655
|
import { readFile, writeFile, mkdir } from "fs/promises";
|
|
19560
|
-
import { join as
|
|
19656
|
+
import { join as join28 } from "path";
|
|
19561
19657
|
|
|
19562
19658
|
class CookieStore {
|
|
19563
19659
|
filePath;
|
|
19564
19660
|
constructor(cookieDir) {
|
|
19565
|
-
this.filePath =
|
|
19661
|
+
this.filePath = join28(cookieDir, "cookies.json");
|
|
19566
19662
|
}
|
|
19567
19663
|
async save(cookies) {
|
|
19568
|
-
await mkdir(
|
|
19664
|
+
await mkdir(join28(this.filePath, ".."), { recursive: true });
|
|
19569
19665
|
await writeFile(this.filePath, JSON.stringify(cookies, null, 2), "utf-8");
|
|
19570
19666
|
}
|
|
19571
19667
|
async load() {
|
|
@@ -19923,10 +20019,10 @@ var init_session = __esm(() => {
|
|
|
19923
20019
|
});
|
|
19924
20020
|
|
|
19925
20021
|
// src/tools/browser.ts
|
|
19926
|
-
import { join as
|
|
20022
|
+
import { join as join29 } from "path";
|
|
19927
20023
|
function getSession(ctx) {
|
|
19928
20024
|
if (!session) {
|
|
19929
|
-
const cookieDir =
|
|
20025
|
+
const cookieDir = join29(ctx.baseDir, ".mma", "browser");
|
|
19930
20026
|
session = new BrowserSession({
|
|
19931
20027
|
...DEFAULT_BROWSER_CONFIG,
|
|
19932
20028
|
headless: ctx.config.browser?.headless ?? true,
|
|
@@ -20052,7 +20148,7 @@ __export(exports_image_utils, {
|
|
|
20052
20148
|
detectMime: () => detectMime,
|
|
20053
20149
|
bufferToDataUrl: () => bufferToDataUrl
|
|
20054
20150
|
});
|
|
20055
|
-
import { readFileSync as
|
|
20151
|
+
import { readFileSync as readFileSync20 } from "fs";
|
|
20056
20152
|
import { extname as extname4 } from "path";
|
|
20057
20153
|
function detectMime(filePath) {
|
|
20058
20154
|
const ext = extname4(filePath).toLowerCase();
|
|
@@ -20073,11 +20169,11 @@ async function readClipboardImage() {
|
|
|
20073
20169
|
async function readClipboardFallback() {
|
|
20074
20170
|
const { platform: platform6 } = await import("os");
|
|
20075
20171
|
const { execSync } = await import("child_process");
|
|
20076
|
-
const { readFileSync:
|
|
20077
|
-
const { join:
|
|
20172
|
+
const { readFileSync: readFileSync21, unlinkSync: unlinkSync5 } = await import("fs");
|
|
20173
|
+
const { join: join30 } = await import("path");
|
|
20078
20174
|
if (platform6() !== "linux")
|
|
20079
20175
|
return null;
|
|
20080
|
-
const tmpPath =
|
|
20176
|
+
const tmpPath = join30(process.env.TEMP || process.env.TMP || "/tmp", `mma-clip-${Date.now()}.png`);
|
|
20081
20177
|
const commands = [
|
|
20082
20178
|
`wl-paste --type image/png > "${tmpPath}" 2>/dev/null`,
|
|
20083
20179
|
`xclip -selection clipboard -t image/png -o > "${tmpPath}" 2>/dev/null`
|
|
@@ -20085,7 +20181,7 @@ async function readClipboardFallback() {
|
|
|
20085
20181
|
for (const cmd of commands) {
|
|
20086
20182
|
try {
|
|
20087
20183
|
execSync(cmd, { timeout: 5000 });
|
|
20088
|
-
const buf =
|
|
20184
|
+
const buf = readFileSync21(tmpPath);
|
|
20089
20185
|
unlinkSync5(tmpPath);
|
|
20090
20186
|
if (buf.length > 0)
|
|
20091
20187
|
return buf;
|
|
@@ -20097,7 +20193,7 @@ async function readClipboardFallback() {
|
|
|
20097
20193
|
return null;
|
|
20098
20194
|
}
|
|
20099
20195
|
async function loadFileAsDataUrl(filePath) {
|
|
20100
|
-
const buf =
|
|
20196
|
+
const buf = readFileSync20(filePath);
|
|
20101
20197
|
if (typeof Bun !== "undefined" && typeof Bun.Image !== "undefined") {
|
|
20102
20198
|
try {
|
|
20103
20199
|
const img = new Bun.Image(buf);
|
|
@@ -20157,7 +20253,7 @@ var init_image_utils = __esm(() => {
|
|
|
20157
20253
|
});
|
|
20158
20254
|
|
|
20159
20255
|
// src/tools/attach-image.ts
|
|
20160
|
-
import { existsSync as
|
|
20256
|
+
import { existsSync as existsSync35 } from "fs";
|
|
20161
20257
|
import { resolve as resolve16 } from "path";
|
|
20162
20258
|
var attachImageTool;
|
|
20163
20259
|
var init_attach_image = __esm(() => {
|
|
@@ -20209,7 +20305,7 @@ var init_attach_image = __esm(() => {
|
|
|
20209
20305
|
dataUrl = result.dataUrl;
|
|
20210
20306
|
} else {
|
|
20211
20307
|
const absPath = resolve16(ctx.baseDir, source);
|
|
20212
|
-
if (!
|
|
20308
|
+
if (!existsSync35(absPath)) {
|
|
20213
20309
|
return {
|
|
20214
20310
|
success: false,
|
|
20215
20311
|
output: t("image.not_found", { path: source })
|
|
@@ -20518,16 +20614,16 @@ class ModuleRegistry {
|
|
|
20518
20614
|
}
|
|
20519
20615
|
|
|
20520
20616
|
// src/modules/plugins/loader.ts
|
|
20521
|
-
import { readdirSync as readdirSync10, existsSync as
|
|
20522
|
-
import { join as
|
|
20617
|
+
import { readdirSync as readdirSync10, existsSync as existsSync36, statSync as statSync6 } from "fs";
|
|
20618
|
+
import { join as join30, basename as basename3 } from "path";
|
|
20523
20619
|
|
|
20524
20620
|
class PluginLoader {
|
|
20525
20621
|
loadFromDir(dirPath, pluginManager, logger2, options) {
|
|
20526
|
-
if (!
|
|
20622
|
+
if (!existsSync36(dirPath))
|
|
20527
20623
|
return;
|
|
20528
20624
|
const entries = readdirSync10(dirPath).sort();
|
|
20529
20625
|
for (const entry of entries) {
|
|
20530
|
-
const fullPath =
|
|
20626
|
+
const fullPath = join30(dirPath, entry);
|
|
20531
20627
|
const stat = statSync6(fullPath);
|
|
20532
20628
|
if (stat.isFile()) {
|
|
20533
20629
|
if (!entry.endsWith(".ts") && !entry.endsWith(".js"))
|
|
@@ -20543,8 +20639,8 @@ class PluginLoader {
|
|
|
20543
20639
|
}
|
|
20544
20640
|
findEntryFile(dir) {
|
|
20545
20641
|
for (const name of FOLDER_ENTRY_NAMES) {
|
|
20546
|
-
const candidate =
|
|
20547
|
-
if (
|
|
20642
|
+
const candidate = join30(dir, name);
|
|
20643
|
+
if (existsSync36(candidate))
|
|
20548
20644
|
return candidate;
|
|
20549
20645
|
}
|
|
20550
20646
|
return null;
|
|
@@ -20749,8 +20845,8 @@ var init_auto_fixer = __esm(() => {
|
|
|
20749
20845
|
|
|
20750
20846
|
// src/modules/plugins/builtin/lint-on-write.ts
|
|
20751
20847
|
import { spawn as spawn7, execSync } from "child_process";
|
|
20752
|
-
import { existsSync as
|
|
20753
|
-
import { resolve as resolve17, extname as extname6, join as
|
|
20848
|
+
import { existsSync as existsSync37, readFileSync as readFileSync21, writeFileSync as writeFileSync13 } from "fs";
|
|
20849
|
+
import { resolve as resolve17, extname as extname6, join as join31 } from "path";
|
|
20754
20850
|
import { platform as platform6 } from "os";
|
|
20755
20851
|
function lintCacheKey(baseDir, lintScript) {
|
|
20756
20852
|
return `${baseDir}::${lintScript}`;
|
|
@@ -20826,7 +20922,7 @@ class LintOnWritePlugin {
|
|
|
20826
20922
|
if (!path)
|
|
20827
20923
|
return;
|
|
20828
20924
|
const fullPath = resolve17(ctx.baseDir, path);
|
|
20829
|
-
if (!
|
|
20925
|
+
if (!existsSync37(fullPath))
|
|
20830
20926
|
return;
|
|
20831
20927
|
const signal = ctx.signal;
|
|
20832
20928
|
if (signal?.aborted)
|
|
@@ -20850,7 +20946,7 @@ class LintOnWritePlugin {
|
|
|
20850
20946
|
if (ext === ".ts" || ext === ".tsx" || ext === ".cts" || ext === ".mts") {
|
|
20851
20947
|
let content = "";
|
|
20852
20948
|
try {
|
|
20853
|
-
content =
|
|
20949
|
+
content = readFileSync21(filePath, "utf-8");
|
|
20854
20950
|
} catch {
|
|
20855
20951
|
return null;
|
|
20856
20952
|
}
|
|
@@ -20892,11 +20988,11 @@ class LintOnWritePlugin {
|
|
|
20892
20988
|
async runProjectLint(ctx, result, signal) {
|
|
20893
20989
|
let lintScript;
|
|
20894
20990
|
try {
|
|
20895
|
-
const packageJsonPath =
|
|
20896
|
-
if (!
|
|
20991
|
+
const packageJsonPath = join31(ctx.baseDir, "package.json");
|
|
20992
|
+
if (!existsSync37(packageJsonPath)) {
|
|
20897
20993
|
return;
|
|
20898
20994
|
}
|
|
20899
|
-
const packageJson = JSON.parse(
|
|
20995
|
+
const packageJson = JSON.parse(readFileSync21(packageJsonPath, "utf-8"));
|
|
20900
20996
|
lintScript = packageJson.scripts?.lint;
|
|
20901
20997
|
if (!lintScript) {
|
|
20902
20998
|
return;
|
|
@@ -20929,8 +21025,8 @@ ${stdout}`;
|
|
|
20929
21025
|
}
|
|
20930
21026
|
async runProjectTypeCheck(filePath, baseDir, result, signal) {
|
|
20931
21027
|
const projectRoot = findProjectRoot(filePath, baseDir, ["tsconfig.json", "package.json"]);
|
|
20932
|
-
const tsconfigPath =
|
|
20933
|
-
if (!
|
|
21028
|
+
const tsconfigPath = join31(projectRoot, "tsconfig.json");
|
|
21029
|
+
if (!existsSync37(tsconfigPath)) {
|
|
20934
21030
|
return;
|
|
20935
21031
|
}
|
|
20936
21032
|
const now = Date.now();
|
|
@@ -20951,7 +21047,7 @@ ${stdout}`;
|
|
|
20951
21047
|
const output = stderr || stdout;
|
|
20952
21048
|
const errors = parseTscOutput(output);
|
|
20953
21049
|
if (errors.length > 0) {
|
|
20954
|
-
const fixResult = autoFixErrors(filePath,
|
|
21050
|
+
const fixResult = autoFixErrors(filePath, readFileSync21(filePath, "utf-8"), errors);
|
|
20955
21051
|
if (fixResult.fixed) {
|
|
20956
21052
|
writeFileSync13(filePath, fixResult.newContent, "utf-8");
|
|
20957
21053
|
result.output += `
|
|
@@ -21216,11 +21312,11 @@ class PlanTracker {
|
|
|
21216
21312
|
var init_tracker = () => {};
|
|
21217
21313
|
|
|
21218
21314
|
// src/modules/execution/plan-store.ts
|
|
21219
|
-
import { readFileSync as
|
|
21220
|
-
import { join as
|
|
21315
|
+
import { readFileSync as readFileSync22, writeFileSync as writeFileSync14, renameSync as renameSync3, mkdirSync as mkdirSync16, existsSync as existsSync38, readdirSync as readdirSync11, rmSync } from "fs";
|
|
21316
|
+
import { join as join32 } from "path";
|
|
21221
21317
|
function readPlanFile(path, fallbackBaseDir) {
|
|
21222
21318
|
try {
|
|
21223
|
-
const raw =
|
|
21319
|
+
const raw = readFileSync22(path, "utf-8");
|
|
21224
21320
|
if (!raw.trim())
|
|
21225
21321
|
return null;
|
|
21226
21322
|
const parsed = JSON.parse(raw);
|
|
@@ -21244,10 +21340,10 @@ function writePlanFile(path, plan) {
|
|
|
21244
21340
|
renameSync3(tmpPath, path);
|
|
21245
21341
|
}
|
|
21246
21342
|
function listDir(dir, baseDir) {
|
|
21247
|
-
if (!
|
|
21343
|
+
if (!existsSync38(dir))
|
|
21248
21344
|
return [];
|
|
21249
21345
|
const files = readdirSync11(dir).filter((f) => f.endsWith(".json"));
|
|
21250
|
-
return files.map((f) => readPlanFile(
|
|
21346
|
+
return files.map((f) => readPlanFile(join32(dir, f), baseDir)).filter((p) => p !== null);
|
|
21251
21347
|
}
|
|
21252
21348
|
function toMeta(plan, status) {
|
|
21253
21349
|
return {
|
|
@@ -21268,33 +21364,33 @@ class PlanStore {
|
|
|
21268
21364
|
archiveDir;
|
|
21269
21365
|
legacyPath;
|
|
21270
21366
|
constructor(baseDir) {
|
|
21271
|
-
const mmaDir =
|
|
21272
|
-
if (!
|
|
21367
|
+
const mmaDir = join32(baseDir, ".mma");
|
|
21368
|
+
if (!existsSync38(mmaDir))
|
|
21273
21369
|
mkdirSync16(mmaDir, { recursive: true });
|
|
21274
21370
|
this.baseDir = baseDir;
|
|
21275
|
-
this.plansDir =
|
|
21276
|
-
this.draftsDir =
|
|
21277
|
-
this.archiveDir =
|
|
21278
|
-
this.legacyPath =
|
|
21371
|
+
this.plansDir = join32(mmaDir, "plans");
|
|
21372
|
+
this.draftsDir = join32(this.plansDir, "drafts");
|
|
21373
|
+
this.archiveDir = join32(this.plansDir, "archive");
|
|
21374
|
+
this.legacyPath = join32(mmaDir, LEGACY_FILE);
|
|
21279
21375
|
for (const dir of [this.plansDir, this.draftsDir, this.archiveDir]) {
|
|
21280
|
-
if (!
|
|
21376
|
+
if (!existsSync38(dir))
|
|
21281
21377
|
mkdirSync16(dir, { recursive: true });
|
|
21282
21378
|
}
|
|
21283
21379
|
}
|
|
21284
21380
|
activePath() {
|
|
21285
|
-
return
|
|
21381
|
+
return join32(this.plansDir, "active.json");
|
|
21286
21382
|
}
|
|
21287
21383
|
saveActive(plan) {
|
|
21288
21384
|
writePlanFile(this.activePath(), plan);
|
|
21289
21385
|
}
|
|
21290
21386
|
loadActive() {
|
|
21291
21387
|
const activePath = this.activePath();
|
|
21292
|
-
if (
|
|
21388
|
+
if (existsSync38(activePath)) {
|
|
21293
21389
|
const plan = readPlanFile(activePath, this.baseDir);
|
|
21294
21390
|
if (plan)
|
|
21295
21391
|
return plan;
|
|
21296
21392
|
}
|
|
21297
|
-
if (
|
|
21393
|
+
if (existsSync38(this.legacyPath)) {
|
|
21298
21394
|
const legacy = readPlanFile(this.legacyPath, this.baseDir);
|
|
21299
21395
|
if (legacy) {
|
|
21300
21396
|
this.saveActive(legacy);
|
|
@@ -21313,26 +21409,26 @@ class PlanStore {
|
|
|
21313
21409
|
}
|
|
21314
21410
|
clearActive() {
|
|
21315
21411
|
const p = this.activePath();
|
|
21316
|
-
if (
|
|
21412
|
+
if (existsSync38(p))
|
|
21317
21413
|
rmSync(p, { force: true });
|
|
21318
21414
|
}
|
|
21319
21415
|
saveDraft(plan) {
|
|
21320
|
-
writePlanFile(
|
|
21416
|
+
writePlanFile(join32(this.draftsDir, `${plan.id}.json`), plan);
|
|
21321
21417
|
}
|
|
21322
21418
|
loadDraft(id) {
|
|
21323
|
-
const p =
|
|
21324
|
-
return
|
|
21419
|
+
const p = join32(this.draftsDir, `${id}.json`);
|
|
21420
|
+
return existsSync38(p) ? readPlanFile(p, this.baseDir) : null;
|
|
21325
21421
|
}
|
|
21326
21422
|
removeDraft(id) {
|
|
21327
|
-
const p =
|
|
21328
|
-
if (
|
|
21423
|
+
const p = join32(this.draftsDir, `${id}.json`);
|
|
21424
|
+
if (existsSync38(p))
|
|
21329
21425
|
rmSync(p, { force: true });
|
|
21330
21426
|
}
|
|
21331
21427
|
listDrafts() {
|
|
21332
21428
|
return listDir(this.draftsDir, this.baseDir);
|
|
21333
21429
|
}
|
|
21334
21430
|
archivePlan(plan) {
|
|
21335
|
-
writePlanFile(
|
|
21431
|
+
writePlanFile(join32(this.archiveDir, `${plan.id}.json`), plan);
|
|
21336
21432
|
this.removeDraft(plan.id);
|
|
21337
21433
|
const active = this.loadActive();
|
|
21338
21434
|
if (active && active.id === plan.id) {
|
|
@@ -21343,8 +21439,8 @@ class PlanStore {
|
|
|
21343
21439
|
return listDir(this.archiveDir, this.baseDir);
|
|
21344
21440
|
}
|
|
21345
21441
|
removeArchived(id) {
|
|
21346
|
-
const p =
|
|
21347
|
-
if (
|
|
21442
|
+
const p = join32(this.archiveDir, `${id}.json`);
|
|
21443
|
+
if (existsSync38(p))
|
|
21348
21444
|
rmSync(p, { force: true });
|
|
21349
21445
|
}
|
|
21350
21446
|
listAll() {
|
|
@@ -21376,13 +21472,13 @@ class PlanStore {
|
|
|
21376
21472
|
this.clearActive();
|
|
21377
21473
|
return "active";
|
|
21378
21474
|
}
|
|
21379
|
-
const draftPath =
|
|
21380
|
-
if (
|
|
21475
|
+
const draftPath = join32(this.draftsDir, `${id}.json`);
|
|
21476
|
+
if (existsSync38(draftPath)) {
|
|
21381
21477
|
rmSync(draftPath, { force: true });
|
|
21382
21478
|
return "draft";
|
|
21383
21479
|
}
|
|
21384
|
-
const archivedPath =
|
|
21385
|
-
if (
|
|
21480
|
+
const archivedPath = join32(this.archiveDir, `${id}.json`);
|
|
21481
|
+
if (existsSync38(archivedPath)) {
|
|
21386
21482
|
rmSync(archivedPath, { force: true });
|
|
21387
21483
|
return "archived";
|
|
21388
21484
|
}
|
|
@@ -22502,7 +22598,7 @@ var init_plan_tool = __esm(() => {
|
|
|
22502
22598
|
});
|
|
22503
22599
|
|
|
22504
22600
|
// src/modules/execution/module.ts
|
|
22505
|
-
import { existsSync as
|
|
22601
|
+
import { existsSync as existsSync39, readFileSync as readFileSync23 } from "fs";
|
|
22506
22602
|
import { resolve as resolve18 } from "path";
|
|
22507
22603
|
|
|
22508
22604
|
class ExecutionModule {
|
|
@@ -22861,7 +22957,7 @@ class ExecutionModule {
|
|
|
22861
22957
|
"poetry.lock",
|
|
22862
22958
|
"requirements.txt"
|
|
22863
22959
|
];
|
|
22864
|
-
const hasLockFile = lockFiles.some((f) =>
|
|
22960
|
+
const hasLockFile = lockFiles.some((f) => existsSync39(resolve18(this.baseDir, f)));
|
|
22865
22961
|
if (!hasLockFile) {
|
|
22866
22962
|
if (contextManager) {
|
|
22867
22963
|
const hints = this.state.depsGateHints.get(step.id) || 0;
|
|
@@ -22893,7 +22989,7 @@ class ExecutionModule {
|
|
|
22893
22989
|
if (!r)
|
|
22894
22990
|
continue;
|
|
22895
22991
|
try {
|
|
22896
|
-
const content =
|
|
22992
|
+
const content = readFileSync23(r, "utf-8");
|
|
22897
22993
|
if (content.trim().length < 10) {
|
|
22898
22994
|
emptyFiles.push(r);
|
|
22899
22995
|
}
|
|
@@ -23001,8 +23097,8 @@ var init_module = __esm(() => {
|
|
|
23001
23097
|
});
|
|
23002
23098
|
|
|
23003
23099
|
// src/modules/security/session-encryption.ts
|
|
23004
|
-
import { readFileSync as
|
|
23005
|
-
import { join as
|
|
23100
|
+
import { readFileSync as readFileSync24, writeFileSync as writeFileSync15, existsSync as existsSync40, readdirSync as readdirSync12, unlinkSync as unlinkSync5 } from "fs";
|
|
23101
|
+
import { join as join33 } from "path";
|
|
23006
23102
|
import { homedir as homedir9 } from "os";
|
|
23007
23103
|
|
|
23008
23104
|
class SessionFileEncryptor {
|
|
@@ -23011,7 +23107,7 @@ class SessionFileEncryptor {
|
|
|
23011
23107
|
constructor(config) {
|
|
23012
23108
|
this.config = { ...DEFAULT_SESSION_ENCRYPTION, ...config };
|
|
23013
23109
|
this.encryptor = new ConfigEncryptor({
|
|
23014
|
-
keyPath: config?.keyPath ||
|
|
23110
|
+
keyPath: config?.keyPath || join33(homedir9(), ".mma", ".session-encryption-key")
|
|
23015
23111
|
});
|
|
23016
23112
|
}
|
|
23017
23113
|
isEnabled() {
|
|
@@ -23063,7 +23159,7 @@ class SessionFileEncryptor {
|
|
|
23063
23159
|
});
|
|
23064
23160
|
}
|
|
23065
23161
|
readSessionFile(filePath) {
|
|
23066
|
-
const content =
|
|
23162
|
+
const content = readFileSync24(filePath, "utf8");
|
|
23067
23163
|
return this.decryptFileContent(content);
|
|
23068
23164
|
}
|
|
23069
23165
|
writeSessionFile(filePath, content) {
|
|
@@ -23071,7 +23167,7 @@ class SessionFileEncryptor {
|
|
|
23071
23167
|
writeFileSync15(filePath, encrypted, "utf8");
|
|
23072
23168
|
}
|
|
23073
23169
|
readSessionJSON(filePath) {
|
|
23074
|
-
const content =
|
|
23170
|
+
const content = readFileSync24(filePath, "utf8");
|
|
23075
23171
|
return this.decryptJSON(content);
|
|
23076
23172
|
}
|
|
23077
23173
|
writeSessionJSON(filePath, obj) {
|
|
@@ -23079,7 +23175,7 @@ class SessionFileEncryptor {
|
|
|
23079
23175
|
writeFileSync15(filePath, content, "utf8");
|
|
23080
23176
|
}
|
|
23081
23177
|
readSessionJSONL(filePath) {
|
|
23082
|
-
const content =
|
|
23178
|
+
const content = readFileSync24(filePath, "utf8");
|
|
23083
23179
|
const lines = content.split(`
|
|
23084
23180
|
`).filter((line) => line.trim());
|
|
23085
23181
|
const decryptedLines = this.decryptJSONL(lines);
|
|
@@ -23104,10 +23200,10 @@ class SessionFileEncryptor {
|
|
|
23104
23200
|
return;
|
|
23105
23201
|
const files = readdirSync12(sessionDir);
|
|
23106
23202
|
for (const file of files) {
|
|
23107
|
-
const filePath =
|
|
23108
|
-
if (
|
|
23203
|
+
const filePath = join33(sessionDir, file);
|
|
23204
|
+
if (existsSync40(filePath) && !file.endsWith(".enc")) {
|
|
23109
23205
|
try {
|
|
23110
|
-
const content =
|
|
23206
|
+
const content = readFileSync24(filePath, "utf8");
|
|
23111
23207
|
const encrypted = this.encryptFileContent(content);
|
|
23112
23208
|
writeFileSync15(filePath + ".enc", encrypted, "utf8");
|
|
23113
23209
|
unlinkSync5(filePath);
|
|
@@ -23121,10 +23217,10 @@ class SessionFileEncryptor {
|
|
|
23121
23217
|
const files = readdirSync12(sessionDir);
|
|
23122
23218
|
for (const file of files) {
|
|
23123
23219
|
if (file.endsWith(".enc")) {
|
|
23124
|
-
const encFilePath =
|
|
23220
|
+
const encFilePath = join33(sessionDir, file);
|
|
23125
23221
|
const decFilePath = encFilePath.slice(0, -4);
|
|
23126
23222
|
try {
|
|
23127
|
-
const content =
|
|
23223
|
+
const content = readFileSync24(encFilePath, "utf8");
|
|
23128
23224
|
const decrypted = this.decryptFileContent(content);
|
|
23129
23225
|
writeFileSync15(decFilePath, decrypted, "utf8");
|
|
23130
23226
|
unlinkSync5(encFilePath);
|
|
@@ -23146,15 +23242,15 @@ var init_session_encryption = __esm(() => {
|
|
|
23146
23242
|
|
|
23147
23243
|
// src/modules/session/store.ts
|
|
23148
23244
|
import {
|
|
23149
|
-
existsSync as
|
|
23245
|
+
existsSync as existsSync41,
|
|
23150
23246
|
mkdirSync as mkdirSync17,
|
|
23151
23247
|
readdirSync as readdirSync13,
|
|
23152
|
-
readFileSync as
|
|
23248
|
+
readFileSync as readFileSync25,
|
|
23153
23249
|
rmSync as rmSync2,
|
|
23154
23250
|
writeFileSync as writeFileSync16,
|
|
23155
23251
|
appendFileSync as appendFileSync6
|
|
23156
23252
|
} from "fs";
|
|
23157
|
-
import { join as
|
|
23253
|
+
import { join as join34 } from "path";
|
|
23158
23254
|
import { gzipSync } from "zlib";
|
|
23159
23255
|
|
|
23160
23256
|
class SessionStore {
|
|
@@ -23168,7 +23264,7 @@ class SessionStore {
|
|
|
23168
23264
|
}
|
|
23169
23265
|
}
|
|
23170
23266
|
getSessionDir(id) {
|
|
23171
|
-
return
|
|
23267
|
+
return join34(this.baseDir, id);
|
|
23172
23268
|
}
|
|
23173
23269
|
updateEncryption(config) {
|
|
23174
23270
|
if (config?.enabled) {
|
|
@@ -23184,19 +23280,19 @@ class SessionStore {
|
|
|
23184
23280
|
mkdirSync17(this.baseDir, { recursive: true, mode: 448 });
|
|
23185
23281
|
}
|
|
23186
23282
|
sessionDir(id) {
|
|
23187
|
-
return
|
|
23283
|
+
return join34(this.baseDir, id);
|
|
23188
23284
|
}
|
|
23189
23285
|
metaPath(id) {
|
|
23190
|
-
return
|
|
23286
|
+
return join34(this.sessionDir(id), "meta.json");
|
|
23191
23287
|
}
|
|
23192
23288
|
historyPath(id) {
|
|
23193
|
-
return
|
|
23289
|
+
return join34(this.sessionDir(id), "history.jsonl");
|
|
23194
23290
|
}
|
|
23195
23291
|
sessionLogPath(id) {
|
|
23196
|
-
return
|
|
23292
|
+
return join34(this.sessionDir(id), "session.jsonl");
|
|
23197
23293
|
}
|
|
23198
23294
|
sessionExists(id) {
|
|
23199
|
-
return
|
|
23295
|
+
return existsSync41(this.metaPath(id));
|
|
23200
23296
|
}
|
|
23201
23297
|
saveMeta(id, meta) {
|
|
23202
23298
|
this._metaCache.set(id, meta);
|
|
@@ -23214,10 +23310,10 @@ class SessionStore {
|
|
|
23214
23310
|
if (cached)
|
|
23215
23311
|
return cached;
|
|
23216
23312
|
const path = this.metaPath(id);
|
|
23217
|
-
if (!
|
|
23313
|
+
if (!existsSync41(path))
|
|
23218
23314
|
return null;
|
|
23219
23315
|
try {
|
|
23220
|
-
const raw =
|
|
23316
|
+
const raw = readFileSync25(path, "utf-8");
|
|
23221
23317
|
const content = this.encryptor ? this.encryptor.decryptFileContent(raw) : raw;
|
|
23222
23318
|
const meta = JSON.parse(content);
|
|
23223
23319
|
this._metaCache.set(id, meta);
|
|
@@ -23228,10 +23324,10 @@ class SessionStore {
|
|
|
23228
23324
|
}
|
|
23229
23325
|
readMetaFromDisk(id) {
|
|
23230
23326
|
const path = this.metaPath(id);
|
|
23231
|
-
if (!
|
|
23327
|
+
if (!existsSync41(path))
|
|
23232
23328
|
return null;
|
|
23233
23329
|
try {
|
|
23234
|
-
const raw =
|
|
23330
|
+
const raw = readFileSync25(path, "utf-8");
|
|
23235
23331
|
const content = this.encryptor ? this.encryptor.decryptFileContent(raw) : raw;
|
|
23236
23332
|
return JSON.parse(content);
|
|
23237
23333
|
} catch {
|
|
@@ -23258,10 +23354,10 @@ class SessionStore {
|
|
|
23258
23354
|
}
|
|
23259
23355
|
loadHistory(id) {
|
|
23260
23356
|
const path = this.historyPath(id);
|
|
23261
|
-
if (!
|
|
23357
|
+
if (!existsSync41(path))
|
|
23262
23358
|
return [];
|
|
23263
23359
|
try {
|
|
23264
|
-
const raw =
|
|
23360
|
+
const raw = readFileSync25(path, "utf-8");
|
|
23265
23361
|
const lines = raw.split(`
|
|
23266
23362
|
`).filter(Boolean);
|
|
23267
23363
|
const parseLine = (line) => {
|
|
@@ -23299,10 +23395,10 @@ class SessionStore {
|
|
|
23299
23395
|
}
|
|
23300
23396
|
loadSessionLog(id) {
|
|
23301
23397
|
const path = this.sessionLogPath(id);
|
|
23302
|
-
if (!
|
|
23398
|
+
if (!existsSync41(path))
|
|
23303
23399
|
return [];
|
|
23304
23400
|
try {
|
|
23305
|
-
const raw =
|
|
23401
|
+
const raw = readFileSync25(path, "utf-8");
|
|
23306
23402
|
const lines = raw.split(`
|
|
23307
23403
|
`).filter(Boolean);
|
|
23308
23404
|
const parseLine = (line) => {
|
|
@@ -23327,7 +23423,7 @@ class SessionStore {
|
|
|
23327
23423
|
}
|
|
23328
23424
|
}
|
|
23329
23425
|
listSessions() {
|
|
23330
|
-
if (!
|
|
23426
|
+
if (!existsSync41(this.baseDir))
|
|
23331
23427
|
return [];
|
|
23332
23428
|
const entries = readdirSync13(this.baseDir, { withFileTypes: true });
|
|
23333
23429
|
const sessions = [];
|
|
@@ -23344,7 +23440,7 @@ class SessionStore {
|
|
|
23344
23440
|
deleteSession(id) {
|
|
23345
23441
|
this._metaCache.delete(id);
|
|
23346
23442
|
const dir = this.sessionDir(id);
|
|
23347
|
-
if (
|
|
23443
|
+
if (existsSync41(dir)) {
|
|
23348
23444
|
rmSync2(dir, { recursive: true, force: true });
|
|
23349
23445
|
}
|
|
23350
23446
|
}
|
|
@@ -23356,10 +23452,10 @@ class SessionStore {
|
|
|
23356
23452
|
const updatedAt = new Date(session2.updatedAt);
|
|
23357
23453
|
if (updatedAt < thirtyDaysAgo) {
|
|
23358
23454
|
const historyPath = this.historyPath(session2.id);
|
|
23359
|
-
if (
|
|
23360
|
-
const content =
|
|
23455
|
+
if (existsSync41(historyPath)) {
|
|
23456
|
+
const content = readFileSync25(historyPath, "utf-8");
|
|
23361
23457
|
const compressed = gzipSync(content);
|
|
23362
|
-
const gzPath =
|
|
23458
|
+
const gzPath = join34(this.baseDir, `${session2.id}.jsonl.gz`);
|
|
23363
23459
|
writeFileSync16(gzPath, compressed);
|
|
23364
23460
|
rmSync2(historyPath);
|
|
23365
23461
|
const meta = this.loadMeta(session2.id);
|
|
@@ -23589,8 +23685,8 @@ class ProfileCompressor {
|
|
|
23589
23685
|
}
|
|
23590
23686
|
|
|
23591
23687
|
// src/modules/user-profile/profile.ts
|
|
23592
|
-
import { readFileSync as
|
|
23593
|
-
import { join as
|
|
23688
|
+
import { readFileSync as readFileSync26, writeFileSync as writeFileSync17, existsSync as existsSync42, mkdirSync as mkdirSync18 } from "fs";
|
|
23689
|
+
import { join as join35 } from "path";
|
|
23594
23690
|
import { homedir as homedir10, hostname, platform as platform8, type } from "os";
|
|
23595
23691
|
import { env } from "process";
|
|
23596
23692
|
|
|
@@ -23614,17 +23710,17 @@ class UserProfile {
|
|
|
23614
23710
|
return this.info;
|
|
23615
23711
|
}
|
|
23616
23712
|
save() {
|
|
23617
|
-
if (!
|
|
23713
|
+
if (!existsSync42(this.profileDir)) {
|
|
23618
23714
|
mkdirSync18(this.profileDir, { recursive: true });
|
|
23619
23715
|
}
|
|
23620
|
-
writeFileSync17(
|
|
23716
|
+
writeFileSync17(join35(this.profileDir, "profile.json"), JSON.stringify({ ...this.info, preferences: this.preferences }, null, 2), "utf-8");
|
|
23621
23717
|
}
|
|
23622
23718
|
load() {
|
|
23623
|
-
const path =
|
|
23624
|
-
if (!
|
|
23719
|
+
const path = join35(this.profileDir, "profile.json");
|
|
23720
|
+
if (!existsSync42(path))
|
|
23625
23721
|
return null;
|
|
23626
23722
|
try {
|
|
23627
|
-
const data = JSON.parse(
|
|
23723
|
+
const data = JSON.parse(readFileSync26(path, "utf-8"));
|
|
23628
23724
|
this.info = {
|
|
23629
23725
|
platform: data.platform,
|
|
23630
23726
|
os: data.os,
|
|
@@ -23659,12 +23755,12 @@ class UserProfile {
|
|
|
23659
23755
|
var init_profile = () => {};
|
|
23660
23756
|
|
|
23661
23757
|
// src/modules/skills/loader.ts
|
|
23662
|
-
import { readdirSync as readdirSync14, readFileSync as
|
|
23663
|
-
import { join as
|
|
23758
|
+
import { readdirSync as readdirSync14, readFileSync as readFileSync27, existsSync as existsSync43, statSync as statSync7 } from "fs";
|
|
23759
|
+
import { join as join36 } from "path";
|
|
23664
23760
|
|
|
23665
23761
|
class SkillsLoader {
|
|
23666
23762
|
loadFromDir(dirPath) {
|
|
23667
|
-
if (!
|
|
23763
|
+
if (!existsSync43(dirPath))
|
|
23668
23764
|
return [];
|
|
23669
23765
|
const skills = [];
|
|
23670
23766
|
this.scanDir(dirPath, skills);
|
|
@@ -23673,7 +23769,7 @@ class SkillsLoader {
|
|
|
23673
23769
|
scanDir(dirPath, skills) {
|
|
23674
23770
|
const entries = readdirSync14(dirPath);
|
|
23675
23771
|
for (const entry of entries) {
|
|
23676
|
-
const fullPath =
|
|
23772
|
+
const fullPath = join36(dirPath, entry);
|
|
23677
23773
|
let stat;
|
|
23678
23774
|
try {
|
|
23679
23775
|
stat = statSync7(fullPath);
|
|
@@ -23686,7 +23782,7 @@ class SkillsLoader {
|
|
|
23686
23782
|
}
|
|
23687
23783
|
if (!entry.endsWith(".md") && !entry.endsWith(".skill.md"))
|
|
23688
23784
|
continue;
|
|
23689
|
-
const content =
|
|
23785
|
+
const content = readFileSync27(fullPath, "utf-8");
|
|
23690
23786
|
const parsed = this.parseSkillFile(content, fullPath);
|
|
23691
23787
|
if (parsed)
|
|
23692
23788
|
skills.push(parsed);
|
|
@@ -24333,11 +24429,11 @@ var init_check_tool = __esm(() => {
|
|
|
24333
24429
|
});
|
|
24334
24430
|
|
|
24335
24431
|
// src/modules/lsp/module.ts
|
|
24336
|
-
import { existsSync as
|
|
24432
|
+
import { existsSync as existsSync44 } from "fs";
|
|
24337
24433
|
import { relative as relative5, resolve as resolve21 } from "path";
|
|
24338
|
-
import { join as
|
|
24434
|
+
import { join as join37 } from "path";
|
|
24339
24435
|
function hasTypeEnvironment(projectRoot) {
|
|
24340
|
-
return
|
|
24436
|
+
return existsSync44(join37(projectRoot, "tsconfig.json")) || existsSync44(join37(projectRoot, "jsconfig.json")) || existsSync44(join37(projectRoot, "node_modules"));
|
|
24341
24437
|
}
|
|
24342
24438
|
|
|
24343
24439
|
class LspModule {
|
|
@@ -24392,7 +24488,7 @@ class LspModule {
|
|
|
24392
24488
|
if (!filePath)
|
|
24393
24489
|
return;
|
|
24394
24490
|
const fullPath = resolve21(_ctx.baseDir, filePath);
|
|
24395
|
-
if (!
|
|
24491
|
+
if (!existsSync44(fullPath))
|
|
24396
24492
|
return;
|
|
24397
24493
|
const serverConfig = getServerForFile(fullPath, self.config);
|
|
24398
24494
|
if (!serverConfig)
|
|
@@ -24484,7 +24580,7 @@ ${items}`;
|
|
|
24484
24580
|
})
|
|
24485
24581
|
};
|
|
24486
24582
|
}
|
|
24487
|
-
if (!
|
|
24583
|
+
if (!existsSync44(resolved)) {
|
|
24488
24584
|
return { success: false, output: t("lsp.check_notfound", { path }) };
|
|
24489
24585
|
}
|
|
24490
24586
|
const files = await collectCheckFiles(resolved, this.config);
|
|
@@ -24601,8 +24697,8 @@ var init_lsp = __esm(() => {
|
|
|
24601
24697
|
});
|
|
24602
24698
|
|
|
24603
24699
|
// src/modules/lsp/startup-check.ts
|
|
24604
|
-
import { existsSync as
|
|
24605
|
-
import { join as
|
|
24700
|
+
import { existsSync as existsSync45 } from "fs";
|
|
24701
|
+
import { join as join38 } from "path";
|
|
24606
24702
|
import { spawn as spawn9 } from "child_process";
|
|
24607
24703
|
async function runStartupHealthCheck(config, baseDir, deps = {}) {
|
|
24608
24704
|
if (!config.enabled)
|
|
@@ -24629,7 +24725,7 @@ ${result.lines.join(`
|
|
|
24629
24725
|
}
|
|
24630
24726
|
async function runCheck(config, baseDir, deps) {
|
|
24631
24727
|
const projectRoot = findProjectRoot(baseDir, baseDir, ["tsconfig.json", "package.json"]);
|
|
24632
|
-
if (
|
|
24728
|
+
if (existsSync45(join38(projectRoot, "tsconfig.json"))) {
|
|
24633
24729
|
const runTsc = deps.runTsc ?? runTscDefault;
|
|
24634
24730
|
const errors = await runTsc(projectRoot, STARTUP_CHECK_TIMEOUT_MS);
|
|
24635
24731
|
if (errors.length === 0)
|
|
@@ -24902,8 +24998,8 @@ var init_symbols = __esm(() => {
|
|
|
24902
24998
|
});
|
|
24903
24999
|
|
|
24904
25000
|
// src/modules/indexer/walker.ts
|
|
24905
|
-
import { readdirSync as readdirSync15, readFileSync as
|
|
24906
|
-
import { join as
|
|
25001
|
+
import { readdirSync as readdirSync15, readFileSync as readFileSync28, statSync as statSync8, lstatSync, existsSync as existsSync46, watch } from "fs";
|
|
25002
|
+
import { join as join39, relative as relative6, extname as extname7 } from "path";
|
|
24907
25003
|
function isIgnoredDirName(name) {
|
|
24908
25004
|
return IGNORE_DIRS.has(name.toLowerCase());
|
|
24909
25005
|
}
|
|
@@ -24936,7 +25032,7 @@ class Indexer {
|
|
|
24936
25032
|
let totalSize = 0;
|
|
24937
25033
|
let count = 0;
|
|
24938
25034
|
const walkDir2 = (dir) => {
|
|
24939
|
-
if (!
|
|
25035
|
+
if (!existsSync46(dir))
|
|
24940
25036
|
return;
|
|
24941
25037
|
let entries;
|
|
24942
25038
|
try {
|
|
@@ -24947,7 +25043,7 @@ class Indexer {
|
|
|
24947
25043
|
for (const entry of entries) {
|
|
24948
25044
|
if (count >= this.MAX_FILES)
|
|
24949
25045
|
return;
|
|
24950
|
-
const fullPath =
|
|
25046
|
+
const fullPath = join39(dir, entry);
|
|
24951
25047
|
const relPath = relative6(this.baseDir, fullPath);
|
|
24952
25048
|
try {
|
|
24953
25049
|
const lst = lstatSync(fullPath, { throwIfNoEntry: false });
|
|
@@ -24962,7 +25058,7 @@ class Indexer {
|
|
|
24962
25058
|
const ext = extname7(entry).toLowerCase();
|
|
24963
25059
|
const language = languageIdForExt(ext);
|
|
24964
25060
|
if (language) {
|
|
24965
|
-
const content =
|
|
25061
|
+
const content = readFileSync28(fullPath, "utf-8");
|
|
24966
25062
|
const exports = extractSymbols(content, language);
|
|
24967
25063
|
files.push({ path: relPath, language, exports, size: stat2.size });
|
|
24968
25064
|
totalSize += stat2.size;
|
|
@@ -25032,22 +25128,22 @@ var init_walker = __esm(() => {
|
|
|
25032
25128
|
});
|
|
25033
25129
|
|
|
25034
25130
|
// src/modules/indexer/cache.ts
|
|
25035
|
-
import { readFileSync as
|
|
25036
|
-
import { join as
|
|
25131
|
+
import { readFileSync as readFileSync29, writeFileSync as writeFileSync18, existsSync as existsSync47, mkdirSync as mkdirSync19, rmSync as rmSync3 } from "fs";
|
|
25132
|
+
import { join as join40 } from "path";
|
|
25037
25133
|
|
|
25038
25134
|
class IndexCache {
|
|
25039
25135
|
cachePath;
|
|
25040
25136
|
cache = null;
|
|
25041
25137
|
constructor(cacheDir) {
|
|
25042
|
-
this.cachePath =
|
|
25138
|
+
this.cachePath = join40(cacheDir, "index-cache.json");
|
|
25043
25139
|
}
|
|
25044
25140
|
load() {
|
|
25045
25141
|
if (this.cache)
|
|
25046
25142
|
return this.cache;
|
|
25047
|
-
if (!
|
|
25143
|
+
if (!existsSync47(this.cachePath))
|
|
25048
25144
|
return null;
|
|
25049
25145
|
try {
|
|
25050
|
-
this.cache = JSON.parse(
|
|
25146
|
+
this.cache = JSON.parse(readFileSync29(this.cachePath, "utf-8"));
|
|
25051
25147
|
return this.cache;
|
|
25052
25148
|
} catch {
|
|
25053
25149
|
return null;
|
|
@@ -25055,14 +25151,14 @@ class IndexCache {
|
|
|
25055
25151
|
}
|
|
25056
25152
|
save(result) {
|
|
25057
25153
|
this.cache = result;
|
|
25058
|
-
const dir =
|
|
25059
|
-
if (!
|
|
25154
|
+
const dir = join40(this.cachePath, "..");
|
|
25155
|
+
if (!existsSync47(dir))
|
|
25060
25156
|
mkdirSync19(dir, { recursive: true });
|
|
25061
25157
|
writeFileSync18(this.cachePath, JSON.stringify(result), "utf-8");
|
|
25062
25158
|
}
|
|
25063
25159
|
invalidate() {
|
|
25064
25160
|
this.cache = null;
|
|
25065
|
-
if (
|
|
25161
|
+
if (existsSync47(this.cachePath)) {
|
|
25066
25162
|
try {
|
|
25067
25163
|
rmSync3(this.cachePath);
|
|
25068
25164
|
} catch {}
|
|
@@ -25137,11 +25233,11 @@ var init_map_select = __esm(() => {
|
|
|
25137
25233
|
});
|
|
25138
25234
|
|
|
25139
25235
|
// src/modules/indexer/project-profile.ts
|
|
25140
|
-
import { readFileSync as
|
|
25141
|
-
import { join as
|
|
25236
|
+
import { readFileSync as readFileSync30, existsSync as existsSync48 } from "fs";
|
|
25237
|
+
import { join as join41 } from "path";
|
|
25142
25238
|
function detectManifest(baseDir) {
|
|
25143
25239
|
for (const manifest of MANIFEST_ORDER) {
|
|
25144
|
-
if (
|
|
25240
|
+
if (existsSync48(join41(baseDir, manifest)))
|
|
25145
25241
|
return manifest;
|
|
25146
25242
|
}
|
|
25147
25243
|
return null;
|
|
@@ -25158,7 +25254,7 @@ function cleanDependency(entry) {
|
|
|
25158
25254
|
}
|
|
25159
25255
|
function readPackageJson(baseDir) {
|
|
25160
25256
|
try {
|
|
25161
|
-
const raw = JSON.parse(
|
|
25257
|
+
const raw = JSON.parse(readFileSync30(join41(baseDir, "package.json"), "utf-8"));
|
|
25162
25258
|
if (!raw || typeof raw !== "object")
|
|
25163
25259
|
return null;
|
|
25164
25260
|
const profile = {
|
|
@@ -25182,7 +25278,7 @@ function readPackageJson(baseDir) {
|
|
|
25182
25278
|
}
|
|
25183
25279
|
function readPyproject(baseDir) {
|
|
25184
25280
|
try {
|
|
25185
|
-
const content =
|
|
25281
|
+
const content = readFileSync30(join41(baseDir, "pyproject.toml"), "utf-8");
|
|
25186
25282
|
const profile = { runtime: "python", deps: [], devDeps: [], scripts: {} };
|
|
25187
25283
|
const nameMatch = content.match(/^\s*name\s*=\s*"([^"]+)"/m);
|
|
25188
25284
|
if (nameMatch)
|
|
@@ -25198,7 +25294,7 @@ function readPyproject(baseDir) {
|
|
|
25198
25294
|
}
|
|
25199
25295
|
function readCargo(baseDir) {
|
|
25200
25296
|
try {
|
|
25201
|
-
const content =
|
|
25297
|
+
const content = readFileSync30(join41(baseDir, "Cargo.toml"), "utf-8");
|
|
25202
25298
|
const profile = { runtime: "rust", deps: [], devDeps: [], scripts: {} };
|
|
25203
25299
|
const nameMatch = content.match(/^\s*name\s*=\s*"([^"]+)"/m);
|
|
25204
25300
|
if (nameMatch)
|
|
@@ -25222,7 +25318,7 @@ function readCargo(baseDir) {
|
|
|
25222
25318
|
}
|
|
25223
25319
|
function readGoMod(baseDir) {
|
|
25224
25320
|
try {
|
|
25225
|
-
const content =
|
|
25321
|
+
const content = readFileSync30(join41(baseDir, "go.mod"), "utf-8");
|
|
25226
25322
|
const profile = { runtime: "go", deps: [], devDeps: [], scripts: {} };
|
|
25227
25323
|
const moduleMatch = content.match(/^module\s+(\S+)/m);
|
|
25228
25324
|
if (moduleMatch)
|
|
@@ -25240,7 +25336,7 @@ function readGoMod(baseDir) {
|
|
|
25240
25336
|
}
|
|
25241
25337
|
function readRequirements(baseDir) {
|
|
25242
25338
|
try {
|
|
25243
|
-
const content =
|
|
25339
|
+
const content = readFileSync30(join41(baseDir, "requirements.txt"), "utf-8");
|
|
25244
25340
|
const profile = { runtime: "python", deps: [], devDeps: [], scripts: {} };
|
|
25245
25341
|
for (const line of content.split(`
|
|
25246
25342
|
`)) {
|
|
@@ -25305,7 +25401,7 @@ var init_project_profile = __esm(() => {
|
|
|
25305
25401
|
});
|
|
25306
25402
|
|
|
25307
25403
|
// src/modules/indexer/module.ts
|
|
25308
|
-
import { dirname as
|
|
25404
|
+
import { dirname as dirname15 } from "path";
|
|
25309
25405
|
|
|
25310
25406
|
class IndexerModule {
|
|
25311
25407
|
name = "indexer";
|
|
@@ -25474,7 +25570,7 @@ ${t("indexer.and_more", { count: result.files.length - listed.length })}` : "";
|
|
|
25474
25570
|
const counts = {};
|
|
25475
25571
|
for (const f of result.files) {
|
|
25476
25572
|
const normalized = toForwardSlash(f.path);
|
|
25477
|
-
const dir =
|
|
25573
|
+
const dir = dirname15(normalized);
|
|
25478
25574
|
const key = dir === "." ? "(root)" : dir;
|
|
25479
25575
|
counts[key] = (counts[key] || 0) + 1;
|
|
25480
25576
|
}
|
|
@@ -25796,7 +25892,7 @@ var init_mcp = __esm(() => {
|
|
|
25796
25892
|
|
|
25797
25893
|
// src/modules/memory/module.ts
|
|
25798
25894
|
import { homedir as homedir11 } from "os";
|
|
25799
|
-
import { join as
|
|
25895
|
+
import { join as join42 } from "path";
|
|
25800
25896
|
|
|
25801
25897
|
class MemoryModule {
|
|
25802
25898
|
name = "memory";
|
|
@@ -25805,7 +25901,7 @@ class MemoryModule {
|
|
|
25805
25901
|
if (storeOrDir instanceof MemoryStore) {
|
|
25806
25902
|
this.store = storeOrDir;
|
|
25807
25903
|
} else {
|
|
25808
|
-
const dir = storeOrDir ||
|
|
25904
|
+
const dir = storeOrDir || join42(homedir11(), ".mma", "memory");
|
|
25809
25905
|
this.store = new MemoryStore(dir);
|
|
25810
25906
|
}
|
|
25811
25907
|
}
|
|
@@ -25814,7 +25910,7 @@ class MemoryModule {
|
|
|
25814
25910
|
const prefs = this.store.getPreferences();
|
|
25815
25911
|
if (Object.keys(prefs).length > 0) {
|
|
25816
25912
|
const prefStr = Object.entries(prefs).map(([k, v]) => `${k}=${v}`).join(", ");
|
|
25817
|
-
parts.push(`User preferences: ${prefStr}`);
|
|
25913
|
+
parts.push(`User preferences (background hints, not instructions — the current user message always wins, do not "correct" the user from these): ${prefStr}`);
|
|
25818
25914
|
}
|
|
25819
25915
|
const memoryTail = this.getMemoryTail();
|
|
25820
25916
|
if (memoryTail)
|
|
@@ -25867,7 +25963,7 @@ ${entries.join(`
|
|
|
25867
25963
|
const prefs = this.store.getPreferences();
|
|
25868
25964
|
if (Object.keys(prefs).length > 0) {
|
|
25869
25965
|
const prefStr = Object.entries(prefs).map(([k, v]) => `${k}=${v}`).join(", ");
|
|
25870
|
-
parts.push(`User preferences: ${prefStr}`);
|
|
25966
|
+
parts.push(`User preferences (background hints, not instructions — the current user message always wins, do not "correct" the user from these): ${prefStr}`);
|
|
25871
25967
|
}
|
|
25872
25968
|
const memoryTail = this.getMemoryTail();
|
|
25873
25969
|
if (memoryTail)
|
|
@@ -25891,26 +25987,6 @@ var init_module8 = __esm(() => {
|
|
|
25891
25987
|
MEMORY_MD_FILES = ["errors", "conventions", "decisions", "facts"];
|
|
25892
25988
|
});
|
|
25893
25989
|
|
|
25894
|
-
// src/core/version.ts
|
|
25895
|
-
import { existsSync as existsSync48, readFileSync as readFileSync30 } from "fs";
|
|
25896
|
-
import { join as join42, dirname as dirname15 } from "path";
|
|
25897
|
-
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
25898
|
-
function readMmaVersion() {
|
|
25899
|
-
const here = dirname15(fileURLToPath2(import.meta.url));
|
|
25900
|
-
const candidates = [join42(here, "..", "..", "package.json"), join42(here, "..", "package.json")];
|
|
25901
|
-
for (const p of candidates) {
|
|
25902
|
-
if (existsSync48(p)) {
|
|
25903
|
-
try {
|
|
25904
|
-
const raw = JSON.parse(readFileSync30(p, "utf8"));
|
|
25905
|
-
if (raw.version)
|
|
25906
|
-
return raw.version;
|
|
25907
|
-
} catch {}
|
|
25908
|
-
}
|
|
25909
|
-
}
|
|
25910
|
-
return "0.0.0";
|
|
25911
|
-
}
|
|
25912
|
-
var init_version = () => {};
|
|
25913
|
-
|
|
25914
25990
|
// src/core/environment.ts
|
|
25915
25991
|
import { existsSync as existsSync49, readFileSync as readFileSync31, readdirSync as readdirSync16 } from "fs";
|
|
25916
25992
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
@@ -26491,6 +26567,7 @@ function buildSystemInfo(config, baseDir, profileCompressed) {
|
|
|
26491
26567
|
`Reply in the user's language. Use tools for file ops (read/write/edit/delete), search (glob/grep), shell (bash), web, subagents, browser, MCP. Explain briefly if not obvious. On tool failure: analyze, fix the call, retry up to 2x with different approaches, then ask the user.`,
|
|
26492
26568
|
`Design: YAGNI (no unneeded code), KISS (simple over clever), DRY (reuse existing utilities).`,
|
|
26493
26569
|
`SCOPE DISCIPLINE: do ONLY what the user explicitly asked — no extra features, files, refactors, "improvements", or fixes beyond the request. Read-only requests ("расскажи", "покажи", "объясни", "check") mean READ-ONLY: inspect and answer, never create/modify/delete anything. If the task is ambiguous (what to create, where, which variant) or the request implies action on something you could not find — STOP and ask the user a short clarifying question in plain text instead of guessing.`,
|
|
26570
|
+
`INPUT PRIORITY: the current user message outranks stored memory/preferences/facts. Never override, reinterpret, or "correct" an explicit value the user states now (city, path, name, language, choice) because a stored preference disagrees — follow the user's current message. If they truly conflict or look like a typo, ask the user instead of assuming.`,
|
|
26494
26571
|
`NOT FOUND ≠ MISSING PROJECT: a "not found" tool result means the PATH was wrong (typo, different location), not that the project does not exist. Before creating or scaffolding ANY project/files: first run list_dir on the working directory to see what is already there; if a user-named path is not found, list its parent directory to locate the real path. NEVER create a new project when the user asked about an existing one — inspect first, create only after confirming the workspace is empty AND the user asked for creation.`
|
|
26495
26572
|
];
|
|
26496
26573
|
if (isWin) {
|
|
@@ -26596,7 +26673,9 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
26596
26673
|
const profile = new UserProfile(join46(dir));
|
|
26597
26674
|
profile.load() || profile.collect();
|
|
26598
26675
|
profile.save();
|
|
26599
|
-
|
|
26676
|
+
let activeSessionManager;
|
|
26677
|
+
const getSessionId = () => activeSessionManager?.getActiveMeta()?.id;
|
|
26678
|
+
const llmProvider = buildActiveProvider(config, logger4, { getSessionId }).provider;
|
|
26600
26679
|
const providerSpec = BUILTIN_PROVIDERS.find((p) => p.type === config.provider.type);
|
|
26601
26680
|
const reasoningStrategy = providerSpec?.capabilities.reasoningStrategy ?? "none";
|
|
26602
26681
|
let reasoningProbePromise = Promise.resolve(false);
|
|
@@ -26675,6 +26754,7 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
26675
26754
|
maxSessions: config.session.maxSessions,
|
|
26676
26755
|
isolation: config.sessionIsolation
|
|
26677
26756
|
});
|
|
26757
|
+
activeSessionManager = sessionManager;
|
|
26678
26758
|
if (config.session.autoSave && !sessionManager.getActive()) {
|
|
26679
26759
|
sessionManager.create();
|
|
26680
26760
|
}
|
|
@@ -26836,8 +26916,7 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete, reas
|
|
|
26836
26916
|
const dry = dryRunOverflow([...promptBlocks, ...dynamicBlocks], systemBudget);
|
|
26837
26917
|
if (dry.overflow.length > 0) {
|
|
26838
26918
|
const overflowTokens = dry.overflow.reduce((s, b) => s + b.estimatedTokens, 0);
|
|
26839
|
-
const
|
|
26840
|
-
const hint = contextWindowHint(config, dir, recommended);
|
|
26919
|
+
const hint = overflowHint(config, dir, dry.includedTokens + overflowTokens);
|
|
26841
26920
|
for (const b of dry.overflow) {
|
|
26842
26921
|
logger4.warn(t("prompt.overflow.startup", {
|
|
26843
26922
|
block: b.kind === "instructions" ? "AGENTS.md" : "project map",
|
|
@@ -27742,6 +27821,49 @@ var init_map_command = __esm(() => {
|
|
|
27742
27821
|
init_i18n();
|
|
27743
27822
|
});
|
|
27744
27823
|
|
|
27824
|
+
// src/config/budget.ts
|
|
27825
|
+
function budgetBreakdown(config) {
|
|
27826
|
+
const window = config.contextWindow;
|
|
27827
|
+
const budget = config.contextBudget;
|
|
27828
|
+
const system = Math.floor(window * budget.systemPrompt);
|
|
27829
|
+
const reserve = Math.floor(window * budget.responseReserve);
|
|
27830
|
+
const history = window - system - reserve;
|
|
27831
|
+
return {
|
|
27832
|
+
window,
|
|
27833
|
+
system,
|
|
27834
|
+
reserve,
|
|
27835
|
+
history,
|
|
27836
|
+
systemFraction: budget.systemPrompt,
|
|
27837
|
+
reserveFraction: budget.responseReserve,
|
|
27838
|
+
historyFraction: window > 0 ? history / window : 0
|
|
27839
|
+
};
|
|
27840
|
+
}
|
|
27841
|
+
function setBudgetShare(config, key, value) {
|
|
27842
|
+
if (!Number.isFinite(value) || value < MIN_SHARE || value > MAX_SHARE)
|
|
27843
|
+
return "range";
|
|
27844
|
+
const budget = config.contextBudget;
|
|
27845
|
+
const nextSystem = key === "system" ? value : budget.systemPrompt;
|
|
27846
|
+
const nextReserve = key === "reserve" ? value : budget.responseReserve;
|
|
27847
|
+
if (nextSystem + nextReserve > MAX_COMBINED)
|
|
27848
|
+
return "combined";
|
|
27849
|
+
budget[key === "system" ? "systemPrompt" : "responseReserve"] = value;
|
|
27850
|
+
return null;
|
|
27851
|
+
}
|
|
27852
|
+
function budgetBreakdownLines(config) {
|
|
27853
|
+
const bd = budgetBreakdown(config);
|
|
27854
|
+
const pct = (f) => Math.round(f * 100);
|
|
27855
|
+
return [
|
|
27856
|
+
t("cli.context_budget_header", { window: bd.window }),
|
|
27857
|
+
t("cli.context_system_line", { tokens: bd.system, percent: pct(bd.systemFraction) }),
|
|
27858
|
+
t("cli.context_reserve_line", { tokens: bd.reserve, percent: pct(bd.reserveFraction) }),
|
|
27859
|
+
t("cli.context_history_line", { tokens: bd.history, percent: pct(bd.historyFraction) })
|
|
27860
|
+
];
|
|
27861
|
+
}
|
|
27862
|
+
var MIN_SHARE = 0.05, MAX_SHARE = 0.9, MAX_COMBINED = 0.95;
|
|
27863
|
+
var init_budget = __esm(() => {
|
|
27864
|
+
init_i18n();
|
|
27865
|
+
});
|
|
27866
|
+
|
|
27745
27867
|
// node_modules/yaml/dist/nodes/identity.js
|
|
27746
27868
|
var require_identity = __commonJS((exports) => {
|
|
27747
27869
|
var ALIAS = Symbol.for("yaml.alias");
|
|
@@ -36293,11 +36415,28 @@ function registerProviderCommands(ctx) {
|
|
|
36293
36415
|
ctx.registerCommand({
|
|
36294
36416
|
name: "context",
|
|
36295
36417
|
description: t("cli.manage_context"),
|
|
36296
|
-
usage: "
|
|
36418
|
+
usage: t("repl.context_usage"),
|
|
36297
36419
|
action: async (args) => {
|
|
36420
|
+
const save = async () => {
|
|
36421
|
+
const configPath = join54(ctx.configDir, "config.json");
|
|
36422
|
+
saveConfig(ctx.config, configPath, dirname24(configPath));
|
|
36423
|
+
await ctx.agent.reconfigure(ctx.config);
|
|
36424
|
+
};
|
|
36298
36425
|
if (args.length === 0) {
|
|
36299
|
-
|
|
36300
|
-
|
|
36426
|
+
for (const line of budgetBreakdownLines(ctx.config))
|
|
36427
|
+
console.log(line);
|
|
36428
|
+
console.log(pc2.dim(t("repl.context_usage")));
|
|
36429
|
+
return;
|
|
36430
|
+
}
|
|
36431
|
+
if (args[0] === "system" || args[0] === "reserve") {
|
|
36432
|
+
const key = args[0];
|
|
36433
|
+
const value = Number(args[1]);
|
|
36434
|
+
if (setBudgetShare(ctx.config, key, value) !== null) {
|
|
36435
|
+
console.log(pc2.yellow(t("cli.context_invalid_fraction")));
|
|
36436
|
+
return;
|
|
36437
|
+
}
|
|
36438
|
+
await save();
|
|
36439
|
+
console.log(pc2.green(t("cli.context_fraction_set", { key, value })));
|
|
36301
36440
|
return;
|
|
36302
36441
|
}
|
|
36303
36442
|
const size = parseInt(args[0], 10);
|
|
@@ -36306,9 +36445,7 @@ function registerProviderCommands(ctx) {
|
|
|
36306
36445
|
return;
|
|
36307
36446
|
}
|
|
36308
36447
|
ctx.config.contextWindow = size;
|
|
36309
|
-
|
|
36310
|
-
saveConfig(ctx.config, configPath, dirname24(configPath));
|
|
36311
|
-
await ctx.agent.reconfigure(ctx.config);
|
|
36448
|
+
await save();
|
|
36312
36449
|
console.log(pc2.green(t("cli.context_set", { size })));
|
|
36313
36450
|
}
|
|
36314
36451
|
});
|
|
@@ -36695,6 +36832,7 @@ var init_repl_commands = __esm(() => {
|
|
|
36695
36832
|
init_i18n();
|
|
36696
36833
|
init_setup();
|
|
36697
36834
|
init_config2();
|
|
36835
|
+
init_budget();
|
|
36698
36836
|
init_token_counter();
|
|
36699
36837
|
init_map_command();
|
|
36700
36838
|
init_utils();
|
|
@@ -37426,6 +37564,7 @@ function targetsFromProviders(entries) {
|
|
|
37426
37564
|
// src/cli/commands.ts
|
|
37427
37565
|
init_version();
|
|
37428
37566
|
init_map_command();
|
|
37567
|
+
init_budget();
|
|
37429
37568
|
|
|
37430
37569
|
// src/modules/updater/changelog-reader.ts
|
|
37431
37570
|
import { readFileSync as readFileSync35, existsSync as existsSync53 } from "fs";
|
|
@@ -37686,9 +37825,25 @@ function buildModelCommands(program2) {
|
|
|
37686
37825
|
});
|
|
37687
37826
|
}
|
|
37688
37827
|
function buildContextCommand(program2) {
|
|
37689
|
-
program2.command("context").description(t("cli.manage_context")).argument("
|
|
37690
|
-
const
|
|
37691
|
-
const
|
|
37828
|
+
program2.command("context").description(t("cli.manage_context")).argument("[size]", "Context window size in tokens (omit to show the budget breakdown)").option("--system <fraction>", t("cli.context_system_fraction")).option("--reserve <fraction>", t("cli.context_reserve_fraction")).action(async (size, opts) => {
|
|
37829
|
+
const { config, configDir } = await bootstrap();
|
|
37830
|
+
const configPath = join53(configDir, "config.json");
|
|
37831
|
+
if (opts.system !== undefined || opts.reserve !== undefined) {
|
|
37832
|
+
const key = opts.system !== undefined ? "system" : "reserve";
|
|
37833
|
+
const value = Number(opts.system ?? opts.reserve);
|
|
37834
|
+
if (setBudgetShare(config, key, value) !== null) {
|
|
37835
|
+
console.log(t("cli.context_invalid_fraction"));
|
|
37836
|
+
return;
|
|
37837
|
+
}
|
|
37838
|
+
saveConfig(config, configPath, dirname23(configPath));
|
|
37839
|
+
console.log(t("cli.context_fraction_set", { key, value }));
|
|
37840
|
+
return;
|
|
37841
|
+
}
|
|
37842
|
+
if (size === undefined) {
|
|
37843
|
+
for (const line of budgetBreakdownLines(config))
|
|
37844
|
+
console.log(line);
|
|
37845
|
+
return;
|
|
37846
|
+
}
|
|
37692
37847
|
const contextWindow = parseInt(size, 10);
|
|
37693
37848
|
if (isNaN(contextWindow) || contextWindow < 1024) {
|
|
37694
37849
|
console.log(t("cli.invalid_context_size"));
|
|
@@ -40245,6 +40400,7 @@ init_colors();
|
|
|
40245
40400
|
import { existsSync as existsSync61 } from "fs";
|
|
40246
40401
|
import { join as join57, dirname as dirname25 } from "path";
|
|
40247
40402
|
import { homedir as homedir20 } from "os";
|
|
40403
|
+
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
40248
40404
|
|
|
40249
40405
|
// src/modules/updater/index.ts
|
|
40250
40406
|
init_checker();
|
|
@@ -40352,6 +40508,11 @@ ${t("cli.changelog_title", { version: result.latest })}
|
|
|
40352
40508
|
await this.runOnce();
|
|
40353
40509
|
}
|
|
40354
40510
|
}
|
|
40511
|
+
// src/modules/updater/dev-detect.ts
|
|
40512
|
+
function isDevEntryPath(path) {
|
|
40513
|
+
const clean = path.split(/[?#]/)[0];
|
|
40514
|
+
return clean.endsWith(".ts") || clean.endsWith(".tsx") || clean.endsWith(".mts") || clean.endsWith(".cts");
|
|
40515
|
+
}
|
|
40355
40516
|
// src/core/crash-handler.ts
|
|
40356
40517
|
init_environment();
|
|
40357
40518
|
init_data_sanitizer();
|
|
@@ -40440,6 +40601,8 @@ function closestCommand(input, known, maxDistance = 2) {
|
|
|
40440
40601
|
// src/cli/main.ts
|
|
40441
40602
|
init_utils();
|
|
40442
40603
|
function startAutoUpdate(config) {
|
|
40604
|
+
if (isDevEntryPath(fileURLToPath6(import.meta.url)))
|
|
40605
|
+
return;
|
|
40443
40606
|
try {
|
|
40444
40607
|
const module = new UpdaterModule(config.updater, readMmaVersion(), "micro-models-agent", {
|
|
40445
40608
|
info: (m) => process.stderr.write(pc2.dim(m) + `
|