micro-models-agent 0.50.4 → 0.51.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +358 -358
- package/dist/main.js +923 -590
- package/dist/modules/browser/bridge-server.mjs +202 -202
- package/dist/skills/builtin/git.md +36 -36
- package/dist/skills/builtin/typescript.md +35 -35
- package/package.json +48 -48
- package/dist/cli/commands.js +0 -323
- package/dist/cli/completer.js +0 -167
- package/dist/cli/index.js +0 -2
- package/dist/cli/main.js +0 -165
- package/dist/cli/plugin-commands.js +0 -36
- package/dist/cli/repl-commands.js +0 -661
- package/dist/cli/repl.js +0 -616
- package/dist/cli/run-result.js +0 -22
- package/dist/cli/security-commands.js +0 -164
- package/dist/cli/setup.js +0 -231
- package/dist/config/config.js +0 -249
- package/dist/config/defaults.js +0 -124
- package/dist/config/experts.js +0 -15
- package/dist/config/index.js +0 -3
- package/dist/config/security.js +0 -193
- package/dist/config/types.js +0 -1
- package/dist/core/agent-moe.js +0 -102
- package/dist/core/agent.js +0 -886
- package/dist/core/bootstrap.js +0 -404
- package/dist/core/index.js +0 -2
- package/dist/core/prompt-builder.js +0 -76
- package/dist/core/session-logger.js +0 -197
- package/dist/core/types.js +0 -1
- package/dist/core/version.js +0 -24
- package/dist/core/workspace.js +0 -76
- package/dist/i18n/en.json +0 -598
- package/dist/i18n/index.js +0 -46
- package/dist/i18n/ru.json +0 -598
- package/dist/index.js +0 -22
- package/dist/llm/image-utils.js +0 -143
- package/dist/llm/index.js +0 -4
- package/dist/llm/model-loader.js +0 -78
- package/dist/llm/openai-compat.js +0 -359
- package/dist/llm/orchestrator.js +0 -198
- package/dist/llm/provider.js +0 -10
- package/dist/llm/response.js +0 -39
- package/dist/llm/token-counter.js +0 -39
- package/dist/llm/types.js +0 -1
- package/dist/logger/app-logger.js +0 -143
- package/dist/logger/file-log.js +0 -151
- package/dist/logger/index.js +0 -1
- package/dist/migration/backup.js +0 -45
- package/dist/migration/detect.js +0 -50
- package/dist/migration/index.js +0 -2
- package/dist/modules/artifacts/store.js +0 -61
- package/dist/modules/browser/actions.js +0 -76
- package/dist/modules/browser/bridge-client.js +0 -199
- package/dist/modules/browser/bridge-path.js +0 -10
- package/dist/modules/browser/cookie-store.js +0 -24
- package/dist/modules/browser/driver.js +0 -136
- package/dist/modules/browser/index.js +0 -7
- package/dist/modules/browser/module.js +0 -29
- package/dist/modules/browser/session.js +0 -338
- package/dist/modules/browser/snapshot.js +0 -148
- package/dist/modules/browser/types.js +0 -12
- package/dist/modules/certification/cli.js +0 -174
- package/dist/modules/certification/fact-checker.js +0 -82
- package/dist/modules/certification/loader.js +0 -105
- package/dist/modules/certification/manifest.js +0 -50
- package/dist/modules/certification/runner.js +0 -159
- package/dist/modules/certification/scenarios.js +0 -124
- package/dist/modules/certification/types.js +0 -1
- package/dist/modules/context/chunk-query.js +0 -100
- package/dist/modules/context/fact-extractor.js +0 -162
- package/dist/modules/context/history.js +0 -15
- package/dist/modules/context/index.js +0 -1
- package/dist/modules/context/manager.js +0 -423
- package/dist/modules/execution/audit-runners.js +0 -152
- package/dist/modules/execution/auditor.js +0 -218
- package/dist/modules/execution/execution-plugin.js +0 -272
- package/dist/modules/execution/index.js +0 -8
- package/dist/modules/execution/module.js +0 -436
- package/dist/modules/execution/moe-executor.js +0 -291
- package/dist/modules/execution/plan-coverage.js +0 -68
- package/dist/modules/execution/plan-persister.js +0 -46
- package/dist/modules/execution/plan-store.js +0 -157
- package/dist/modules/execution/plan-tool.js +0 -508
- package/dist/modules/execution/plan-validator.js +0 -153
- package/dist/modules/execution/planner.js +0 -90
- package/dist/modules/execution/stuck-detector.js +0 -510
- package/dist/modules/execution/tracker.js +0 -67
- package/dist/modules/execution/types.js +0 -1
- package/dist/modules/execution/verifier.js +0 -222
- package/dist/modules/execution/windows-commands.js +0 -41
- package/dist/modules/hallucination/confidence.js +0 -66
- package/dist/modules/hallucination/consistency.js +0 -26
- package/dist/modules/hallucination/detector.js +0 -43
- package/dist/modules/hallucination/factual.js +0 -129
- package/dist/modules/hallucination/index.js +0 -5
- package/dist/modules/hallucination/js-identifiers.js +0 -262
- package/dist/modules/hallucination/llm-judge.js +0 -101
- package/dist/modules/index.js +0 -5
- package/dist/modules/indexer/cache.js +0 -40
- package/dist/modules/indexer/index.js +0 -3
- package/dist/modules/indexer/module.js +0 -245
- package/dist/modules/indexer/project-profile.js +0 -183
- package/dist/modules/indexer/walker.js +0 -101
- package/dist/modules/lsp/check-tool.js +0 -58
- package/dist/modules/lsp/client.js +0 -278
- package/dist/modules/lsp/command.js +0 -60
- package/dist/modules/lsp/config.js +0 -135
- package/dist/modules/lsp/index.js +0 -3
- package/dist/modules/lsp/module.js +0 -232
- package/dist/modules/lsp/probe.js +0 -76
- package/dist/modules/lsp/project-root.js +0 -32
- package/dist/modules/lsp/startup-check.js +0 -141
- package/dist/modules/lsp/types.js +0 -1
- package/dist/modules/mcp/client.js +0 -399
- package/dist/modules/mcp/index.js +0 -3
- package/dist/modules/mcp/module.js +0 -142
- package/dist/modules/mcp/registry.js +0 -15
- package/dist/modules/memory/index.js +0 -1
- package/dist/modules/memory/module.js +0 -96
- package/dist/modules/memory/search.js +0 -42
- package/dist/modules/memory/store.js +0 -69
- package/dist/modules/pipelines/engine.js +0 -60
- package/dist/modules/pipelines/index.js +0 -3
- package/dist/modules/pipelines/parser.js +0 -56
- package/dist/modules/pipelines/template.js +0 -14
- package/dist/modules/plugins/builtin/lint-on-write.js +0 -231
- package/dist/modules/plugins/builtin/notify.js +0 -9
- package/dist/modules/plugins/index.js +0 -1
- package/dist/modules/plugins/loader.js +0 -70
- package/dist/modules/plugins/manager.js +0 -217
- package/dist/modules/plugins/types.js +0 -1
- package/dist/modules/processes/detect.js +0 -34
- package/dist/modules/processes/index.js +0 -2
- package/dist/modules/processes/registry.js +0 -327
- package/dist/modules/processes/runner.js +0 -23
- package/dist/modules/registry.js +0 -47
- package/dist/modules/security/audit-log.js +0 -136
- package/dist/modules/security/audit-notifier.js +0 -292
- package/dist/modules/security/command-validator.js +0 -205
- package/dist/modules/security/content-scanner.js +0 -53
- package/dist/modules/security/data-sanitizer.js +0 -89
- package/dist/modules/security/encryption.js +0 -242
- package/dist/modules/security/index.js +0 -14
- package/dist/modules/security/network-validator.js +0 -71
- package/dist/modules/security/path-validator.js +0 -207
- package/dist/modules/security/rate-limiter.js +0 -119
- package/dist/modules/security/security-policies.js +0 -531
- package/dist/modules/security/session-encryption.js +0 -210
- package/dist/modules/security/session-isolation.js +0 -95
- package/dist/modules/session/index.js +0 -3
- package/dist/modules/session/manager.js +0 -172
- package/dist/modules/session/module.js +0 -24
- package/dist/modules/session/store.js +0 -222
- package/dist/modules/session/types.js +0 -1
- package/dist/modules/skills/index.js +0 -2
- package/dist/modules/skills/loader.js +0 -72
- package/dist/modules/skills/matcher.js +0 -27
- package/dist/modules/skills/module.js +0 -129
- package/dist/modules/types.js +0 -1
- package/dist/modules/updater/checker.js +0 -96
- package/dist/modules/updater/index.js +0 -2
- package/dist/modules/updater/module.js +0 -116
- package/dist/modules/user-profile/compressor.js +0 -16
- package/dist/modules/user-profile/index.js +0 -1
- package/dist/modules/user-profile/profile.js +0 -68
- package/dist/tools/approve.js +0 -32
- package/dist/tools/attach-image.js +0 -89
- package/dist/tools/bash.js +0 -496
- package/dist/tools/browser.js +0 -114
- package/dist/tools/chunk-query.js +0 -99
- package/dist/tools/create-dir.js +0 -55
- package/dist/tools/delete-file.js +0 -62
- package/dist/tools/download-file.js +0 -116
- package/dist/tools/edit-file.js +0 -79
- package/dist/tools/enable-tools.js +0 -58
- package/dist/tools/executor.js +0 -144
- package/dist/tools/file-info.js +0 -46
- package/dist/tools/filter-tools.js +0 -17
- package/dist/tools/glob-tool.js +0 -26
- package/dist/tools/grep-tool.js +0 -84
- package/dist/tools/hidden-tools-block.js +0 -37
- package/dist/tools/index.js +0 -78
- package/dist/tools/list-dir.js +0 -48
- package/dist/tools/load-skill.js +0 -42
- package/dist/tools/mcp-call.js +0 -68
- package/dist/tools/move-file.js +0 -85
- package/dist/tools/path-utils.js +0 -51
- package/dist/tools/pipeline-run.js +0 -144
- package/dist/tools/preview.js +0 -2
- package/dist/tools/process-kill.js +0 -29
- package/dist/tools/process-list.js +0 -36
- package/dist/tools/process-log.js +0 -45
- package/dist/tools/question.js +0 -140
- package/dist/tools/read-file.js +0 -91
- package/dist/tools/recall.js +0 -117
- package/dist/tools/registry.js +0 -47
- package/dist/tools/remember.js +0 -67
- package/dist/tools/scope-check.js +0 -30
- package/dist/tools/search-history.js +0 -84
- package/dist/tools/subagent.js +0 -196
- package/dist/tools/types.js +0 -1
- package/dist/tools/user-input.js +0 -123
- package/dist/tools/web-browse.js +0 -86
- package/dist/tools/web-fetch.js +0 -98
- package/dist/tools/web-search.js +0 -78
- package/dist/tools/write-file.js +0 -81
- package/dist/ui/box.js +0 -77
- package/dist/ui/colors.js +0 -4
- package/dist/ui/diff.js +0 -178
- package/dist/ui/index.js +0 -6
- package/dist/ui/line-editor.js +0 -703
- package/dist/ui/line-math.js +0 -69
- package/dist/ui/md-formatter.js +0 -212
- package/dist/ui/output.js +0 -13
- package/dist/ui/plan-view.js +0 -103
- package/dist/ui/renderer.js +0 -209
- package/dist/ui/spinner.js +0 -70
- package/dist/ui/table.js +0 -144
package/dist/main.js
CHANGED
|
@@ -2634,6 +2634,7 @@ Fix the error and re-edit the file (a clean write clears the failure), or mark t
|
|
|
2634
2634
|
"cli.set_value": "Set a config value",
|
|
2635
2635
|
"cli.set_done": "Set {key}={value}",
|
|
2636
2636
|
"cli.show_config": "Show current config",
|
|
2637
|
+
"cli.migrate_config": "Migrate legacy config.json to domain format",
|
|
2637
2638
|
"cli.manage_models": "Manage models",
|
|
2638
2639
|
"cli.list_models": "List available models",
|
|
2639
2640
|
"cli.current_model": "Current model:",
|
|
@@ -3020,6 +3021,11 @@ Apply a matching solution from these results. If none is relevant — do NOT rep
|
|
|
3020
3021
|
"tool.friendly.project_map": "Project map",
|
|
3021
3022
|
"config.decryption_warning": "Warning: Failed to decrypt config: {error}",
|
|
3022
3023
|
"config.encryption_warning": "Warning: Failed to encrypt config: {error}",
|
|
3024
|
+
"config.migrate_start": "Migrating config to domain format...",
|
|
3025
|
+
"config.migrate_done": "Migration complete. Created {count} domain files. Legacy saved as config.json.bak.",
|
|
3026
|
+
"config.migrate_no_legacy": "No legacy config.json found. Already using domain format.",
|
|
3027
|
+
"config.migrate_error": "Migration failed: {error}",
|
|
3028
|
+
"config.legacy_hint": 'Config: using legacy config.json. Run "mma config migrate" to switch to domain format.',
|
|
3023
3029
|
"image.source_required": 'Image source is required. Provide a file path, URL, or "clipboard".',
|
|
3024
3030
|
"image.clipboard_empty": "Clipboard does not contain an image. Copy an image first (e.g. screenshot with Win+Shift+S).",
|
|
3025
3031
|
"image.not_found": "Image file not found: {path}",
|
|
@@ -3353,6 +3359,7 @@ var init_ru = __esm(() => {
|
|
|
3353
3359
|
"cli.set_value": "Установить значение",
|
|
3354
3360
|
"cli.set_done": "Установлено {key}={value}",
|
|
3355
3361
|
"cli.show_config": "Показать текущий конфиг",
|
|
3362
|
+
"cli.migrate_config": "Мигрировать legacy config.json в domain-формат",
|
|
3356
3363
|
"cli.manage_models": "Управление моделями",
|
|
3357
3364
|
"cli.list_models": "Список доступных моделей",
|
|
3358
3365
|
"cli.current_model": "Текущая модель:",
|
|
@@ -3739,6 +3746,11 @@ var init_ru = __esm(() => {
|
|
|
3739
3746
|
"tool.friendly.project_map": "Карта проекта",
|
|
3740
3747
|
"config.decryption_warning": "Предупреждение: не удалось расшифровать конфигурацию: {error}",
|
|
3741
3748
|
"config.encryption_warning": "Предупреждение: не удалось зашифровать конфигурацию: {error}",
|
|
3749
|
+
"config.migrate_start": "Миграция конфига в domain-формат...",
|
|
3750
|
+
"config.migrate_done": "Миграция завершена. Создано {count} domain файлов. Legacy сохранён как config.json.bak.",
|
|
3751
|
+
"config.migrate_no_legacy": "Legacy config.json не найден. Уже используется domain-формат.",
|
|
3752
|
+
"config.migrate_error": "Ошибка миграции: {error}",
|
|
3753
|
+
"config.legacy_hint": 'Config: используется legacy config.json. Запустите "mma config migrate" для перехода к domain-формату.',
|
|
3742
3754
|
"image.source_required": 'Укажите источник изображения: путь к файлу, URL или "clipboard".',
|
|
3743
3755
|
"image.clipboard_empty": "Буфер обмена не содержит изображение. Скопируйте изображение (например, скриншот через Win+Shift+S).",
|
|
3744
3756
|
"image.not_found": "Файл изображения не найден: {path}",
|
|
@@ -4142,15 +4154,163 @@ var init_encryption = __esm(() => {
|
|
|
4142
4154
|
];
|
|
4143
4155
|
});
|
|
4144
4156
|
|
|
4157
|
+
// src/config/domains.ts
|
|
4158
|
+
var exports_domains = {};
|
|
4159
|
+
__export(exports_domains, {
|
|
4160
|
+
saveDomainFiles: () => saveDomainFiles,
|
|
4161
|
+
loadDomainFiles: () => loadDomainFiles,
|
|
4162
|
+
hasDomainFiles: () => hasDomainFiles,
|
|
4163
|
+
getDomainFilePath: () => getDomainFilePath,
|
|
4164
|
+
extractDomain: () => extractDomain,
|
|
4165
|
+
domainForKey: () => domainForKey,
|
|
4166
|
+
CONFIG_DOMAINS: () => CONFIG_DOMAINS
|
|
4167
|
+
});
|
|
4168
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync3, mkdirSync as mkdirSync2, readdirSync as readdirSync3 } from "fs";
|
|
4169
|
+
import { join as join4 } from "path";
|
|
4170
|
+
function regexReplacer(_key, value) {
|
|
4171
|
+
if (value instanceof RegExp) {
|
|
4172
|
+
return { __regex: true, source: value.source, flags: value.flags };
|
|
4173
|
+
}
|
|
4174
|
+
return value;
|
|
4175
|
+
}
|
|
4176
|
+
function regexReviver(_key, value) {
|
|
4177
|
+
if (value && typeof value === "object" && value.__regex === true) {
|
|
4178
|
+
const { source, flags } = value;
|
|
4179
|
+
try {
|
|
4180
|
+
return new RegExp(source, flags);
|
|
4181
|
+
} catch {
|
|
4182
|
+
return value;
|
|
4183
|
+
}
|
|
4184
|
+
}
|
|
4185
|
+
return value;
|
|
4186
|
+
}
|
|
4187
|
+
function deepMerge(target, source) {
|
|
4188
|
+
const result = { ...target };
|
|
4189
|
+
for (const key of Object.keys(source)) {
|
|
4190
|
+
const srcVal = source[key];
|
|
4191
|
+
const tgtVal = target[key];
|
|
4192
|
+
if (srcVal !== null && srcVal !== undefined && typeof srcVal === "object" && !Array.isArray(srcVal) && typeof tgtVal === "object" && !Array.isArray(tgtVal)) {
|
|
4193
|
+
result[key] = deepMerge(tgtVal, srcVal);
|
|
4194
|
+
} else if (srcVal !== undefined) {
|
|
4195
|
+
result[key] = srcVal;
|
|
4196
|
+
}
|
|
4197
|
+
}
|
|
4198
|
+
return result;
|
|
4199
|
+
}
|
|
4200
|
+
function extractDomain(config, domain) {
|
|
4201
|
+
const keys = CONFIG_DOMAINS[domain];
|
|
4202
|
+
if (!keys)
|
|
4203
|
+
return {};
|
|
4204
|
+
const subset = {};
|
|
4205
|
+
for (const key of keys) {
|
|
4206
|
+
if (config[key] !== undefined) {
|
|
4207
|
+
subset[key] = config[key];
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
return subset;
|
|
4211
|
+
}
|
|
4212
|
+
function getDomainFilePath(configDir, domain) {
|
|
4213
|
+
return join4(configDir, "config", `${domain}.json`);
|
|
4214
|
+
}
|
|
4215
|
+
function hasDomainFiles(configDir) {
|
|
4216
|
+
const configDirPath = join4(configDir, "config");
|
|
4217
|
+
if (!existsSync4(configDirPath))
|
|
4218
|
+
return false;
|
|
4219
|
+
try {
|
|
4220
|
+
const files = readdirSync3(configDirPath);
|
|
4221
|
+
return files.some((f) => f.endsWith(".json"));
|
|
4222
|
+
} catch {
|
|
4223
|
+
return false;
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
function loadDomainFiles(configDir) {
|
|
4227
|
+
const configDirPath = join4(configDir, "config");
|
|
4228
|
+
if (!existsSync4(configDirPath))
|
|
4229
|
+
return null;
|
|
4230
|
+
let result = {};
|
|
4231
|
+
let anyLoaded = false;
|
|
4232
|
+
for (const domain of Object.keys(CONFIG_DOMAINS)) {
|
|
4233
|
+
const filePath = getDomainFilePath(configDir, domain);
|
|
4234
|
+
if (!existsSync4(filePath))
|
|
4235
|
+
continue;
|
|
4236
|
+
try {
|
|
4237
|
+
const raw = readFileSync3(filePath, "utf-8");
|
|
4238
|
+
const data = JSON.parse(raw, regexReviver);
|
|
4239
|
+
result = deepMerge(result, data);
|
|
4240
|
+
anyLoaded = true;
|
|
4241
|
+
} catch {}
|
|
4242
|
+
}
|
|
4243
|
+
return anyLoaded ? result : null;
|
|
4244
|
+
}
|
|
4245
|
+
function saveDomainFiles(config, configDir) {
|
|
4246
|
+
const configDirPath = join4(configDir, "config");
|
|
4247
|
+
mkdirSync2(configDirPath, { recursive: true });
|
|
4248
|
+
for (const [domain, keys] of Object.entries(CONFIG_DOMAINS)) {
|
|
4249
|
+
const subset = {};
|
|
4250
|
+
let hasContent = false;
|
|
4251
|
+
for (const key of keys) {
|
|
4252
|
+
if (config[key] !== undefined) {
|
|
4253
|
+
subset[key] = config[key];
|
|
4254
|
+
hasContent = true;
|
|
4255
|
+
}
|
|
4256
|
+
}
|
|
4257
|
+
if (!hasContent)
|
|
4258
|
+
continue;
|
|
4259
|
+
const filePath = getDomainFilePath(configDir, domain);
|
|
4260
|
+
writeFileSync3(filePath, JSON.stringify(subset, regexReplacer, 2), "utf-8");
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
function domainForKey(key) {
|
|
4264
|
+
for (const [domain, keys] of Object.entries(CONFIG_DOMAINS)) {
|
|
4265
|
+
if (keys.includes(key))
|
|
4266
|
+
return domain;
|
|
4267
|
+
}
|
|
4268
|
+
return null;
|
|
4269
|
+
}
|
|
4270
|
+
var CONFIG_DOMAINS;
|
|
4271
|
+
var init_domains = __esm(() => {
|
|
4272
|
+
CONFIG_DOMAINS = {
|
|
4273
|
+
core: [
|
|
4274
|
+
"version",
|
|
4275
|
+
"model",
|
|
4276
|
+
"contextWindow",
|
|
4277
|
+
"contextBudget",
|
|
4278
|
+
"modelLoad",
|
|
4279
|
+
"maxToolIterations",
|
|
4280
|
+
"stuckThreshold",
|
|
4281
|
+
"autoPlan",
|
|
4282
|
+
"showReasoning",
|
|
4283
|
+
"logLevel",
|
|
4284
|
+
"locale"
|
|
4285
|
+
],
|
|
4286
|
+
provider: ["provider", "orchestrator", "retry", "pricing"],
|
|
4287
|
+
moe: ["moe", "experts"],
|
|
4288
|
+
security: ["security"],
|
|
4289
|
+
browser: ["browser"],
|
|
4290
|
+
search: ["webSearch", "errorWebSearch"],
|
|
4291
|
+
tools: ["tools", "subagent"],
|
|
4292
|
+
session: ["session", "sessionIsolation"],
|
|
4293
|
+
ui: ["ui"],
|
|
4294
|
+
mcp: ["mcpServers"],
|
|
4295
|
+
lsp: ["lsp"],
|
|
4296
|
+
skills: ["skills"],
|
|
4297
|
+
updater: ["updater"]
|
|
4298
|
+
};
|
|
4299
|
+
});
|
|
4300
|
+
|
|
4145
4301
|
// src/config/config.ts
|
|
4146
4302
|
var exports_config = {};
|
|
4147
4303
|
__export(exports_config, {
|
|
4148
4304
|
validateConfig: () => validateConfig,
|
|
4149
4305
|
saveConfig: () => saveConfig,
|
|
4150
|
-
loadConfig: () => loadConfig
|
|
4306
|
+
loadConfig: () => loadConfig,
|
|
4307
|
+
CONFIG_FILE: () => CONFIG_FILE,
|
|
4308
|
+
CONFIG_DOMAIN_DIR: () => CONFIG_DOMAIN_DIR,
|
|
4309
|
+
CONFIG_DIR: () => CONFIG_DIR
|
|
4151
4310
|
});
|
|
4152
|
-
import { existsSync as
|
|
4153
|
-
import { join as
|
|
4311
|
+
import { existsSync as existsSync5, readFileSync as readFileSync4, unlinkSync, writeFileSync as writeFileSync4, mkdirSync as mkdirSync3 } from "fs";
|
|
4312
|
+
import { join as join5, dirname } from "path";
|
|
4313
|
+
import { homedir as homedir2 } from "os";
|
|
4154
4314
|
function restoreDangerousPatterns(patterns, defaults) {
|
|
4155
4315
|
const fallback = Array.isArray(defaults) ? defaults : [];
|
|
4156
4316
|
if (!Array.isArray(patterns) || patterns.length === 0) {
|
|
@@ -4170,26 +4330,26 @@ function restoreDangerousPatterns(patterns, defaults) {
|
|
|
4170
4330
|
return fallback[i] || fallback[0] || p;
|
|
4171
4331
|
});
|
|
4172
4332
|
}
|
|
4173
|
-
function
|
|
4333
|
+
function deepMerge2(target, source) {
|
|
4174
4334
|
const result = { ...target };
|
|
4175
4335
|
for (const key of Object.keys(source)) {
|
|
4176
4336
|
const srcVal = source[key];
|
|
4177
4337
|
const tgtVal = target[key];
|
|
4178
4338
|
if (srcVal !== null && srcVal !== undefined && typeof srcVal === "object" && !Array.isArray(srcVal) && typeof tgtVal === "object" && !Array.isArray(tgtVal)) {
|
|
4179
|
-
result[key] =
|
|
4339
|
+
result[key] = deepMerge2(tgtVal, srcVal);
|
|
4180
4340
|
} else if (srcVal !== undefined) {
|
|
4181
4341
|
result[key] = srcVal;
|
|
4182
4342
|
}
|
|
4183
4343
|
}
|
|
4184
4344
|
return result;
|
|
4185
4345
|
}
|
|
4186
|
-
function
|
|
4346
|
+
function regexReplacer2(_key, value) {
|
|
4187
4347
|
if (value instanceof RegExp) {
|
|
4188
4348
|
return { __regex: true, source: value.source, flags: value.flags };
|
|
4189
4349
|
}
|
|
4190
4350
|
return value;
|
|
4191
4351
|
}
|
|
4192
|
-
function
|
|
4352
|
+
function regexReviver2(_key, value) {
|
|
4193
4353
|
if (value && typeof value === "object" && value.__regex === true) {
|
|
4194
4354
|
const { source, flags } = value;
|
|
4195
4355
|
try {
|
|
@@ -4219,8 +4379,8 @@ function normalizeLspServerArgs(config) {
|
|
|
4219
4379
|
}
|
|
4220
4380
|
function loadJSON(path) {
|
|
4221
4381
|
try {
|
|
4222
|
-
if (
|
|
4223
|
-
return JSON.parse(
|
|
4382
|
+
if (existsSync5(path)) {
|
|
4383
|
+
return JSON.parse(readFileSync4(path, "utf-8"), regexReviver2);
|
|
4224
4384
|
}
|
|
4225
4385
|
} catch {}
|
|
4226
4386
|
return null;
|
|
@@ -4262,8 +4422,8 @@ function applyEnvVars(config) {
|
|
|
4262
4422
|
return result;
|
|
4263
4423
|
}
|
|
4264
4424
|
function loadConfig(options) {
|
|
4265
|
-
const globalPath =
|
|
4266
|
-
|
|
4425
|
+
const globalPath = join5(options.configDir, "config.json");
|
|
4426
|
+
mkdirSync3(options.configDir, { recursive: true });
|
|
4267
4427
|
const detector = new MigrationDetector(options.configDir);
|
|
4268
4428
|
if (detector.needsMigration()) {
|
|
4269
4429
|
const backup = new BackupManager(options.configDir);
|
|
@@ -4275,16 +4435,23 @@ function loadConfig(options) {
|
|
|
4275
4435
|
} catch {}
|
|
4276
4436
|
}
|
|
4277
4437
|
let config = { ...DEFAULTS };
|
|
4438
|
+
let legacyDetected = false;
|
|
4278
4439
|
const globalData = loadJSON(globalPath);
|
|
4279
4440
|
if (globalData) {
|
|
4280
|
-
config =
|
|
4441
|
+
config = deepMerge2(config, globalData);
|
|
4442
|
+
legacyDetected = true;
|
|
4281
4443
|
}
|
|
4282
|
-
|
|
4283
|
-
|
|
4444
|
+
const domainConfig = loadDomainFiles(options.configDir);
|
|
4445
|
+
if (domainConfig) {
|
|
4446
|
+
config = deepMerge2(config, domainConfig);
|
|
4447
|
+
legacyDetected = false;
|
|
4448
|
+
}
|
|
4449
|
+
if (!globalData && !domainConfig) {
|
|
4450
|
+
saveDomainFiles(config, options.configDir);
|
|
4284
4451
|
}
|
|
4285
4452
|
const projectData = loadJSON(options.projectConfigPath);
|
|
4286
4453
|
if (projectData) {
|
|
4287
|
-
config =
|
|
4454
|
+
config = deepMerge2(config, projectData);
|
|
4288
4455
|
}
|
|
4289
4456
|
if (config.security?.contentScan?.dangerousPatterns) {
|
|
4290
4457
|
config.security.contentScan.dangerousPatterns = restoreDangerousPatterns(config.security.contentScan.dangerousPatterns, DEFAULT_SECURITY_CONFIG.contentScan.dangerousPatterns);
|
|
@@ -4300,7 +4467,7 @@ function loadConfig(options) {
|
|
|
4300
4467
|
} catch (e) {
|
|
4301
4468
|
console.warn(t("config.decryption_warning", { error: e.message }));
|
|
4302
4469
|
}
|
|
4303
|
-
return config;
|
|
4470
|
+
return { config, legacyDetected };
|
|
4304
4471
|
}
|
|
4305
4472
|
function validateConfig(config, allToolTags) {
|
|
4306
4473
|
const errors = validateExpertConfig(config, allToolTags);
|
|
@@ -4316,21 +4483,25 @@ ${errors.join(`
|
|
|
4316
4483
|
`)}`);
|
|
4317
4484
|
}
|
|
4318
4485
|
}
|
|
4319
|
-
function saveConfig(config, configPath) {
|
|
4486
|
+
function saveConfig(config, configPath, configDir) {
|
|
4487
|
+
if (configDir) {
|
|
4488
|
+
saveDomainFiles(config, configDir);
|
|
4489
|
+
return;
|
|
4490
|
+
}
|
|
4320
4491
|
const dir = dirname(configPath);
|
|
4321
|
-
|
|
4492
|
+
mkdirSync3(dir, { recursive: true });
|
|
4322
4493
|
try {
|
|
4323
4494
|
const encryptor = new ConfigEncryptor;
|
|
4324
4495
|
const encryptedConfig = encryptor.encrypt({
|
|
4325
4496
|
...config
|
|
4326
4497
|
});
|
|
4327
|
-
|
|
4498
|
+
writeFileSync4(configPath, JSON.stringify(encryptedConfig, regexReplacer2, 2), "utf-8");
|
|
4328
4499
|
} catch (e) {
|
|
4329
4500
|
console.warn(t("config.encryption_warning", { error: e.message }));
|
|
4330
|
-
|
|
4501
|
+
writeFileSync4(configPath, JSON.stringify(config, regexReplacer2, 2), "utf-8");
|
|
4331
4502
|
}
|
|
4332
4503
|
}
|
|
4333
|
-
var LEGACY_LSP_SERVER_ARGS;
|
|
4504
|
+
var CONFIG_DIR, CONFIG_FILE, CONFIG_DOMAIN_DIR, LEGACY_LSP_SERVER_ARGS;
|
|
4334
4505
|
var init_config2 = __esm(() => {
|
|
4335
4506
|
init_defaults();
|
|
4336
4507
|
init_security();
|
|
@@ -4339,6 +4510,10 @@ var init_config2 = __esm(() => {
|
|
|
4339
4510
|
init_detect();
|
|
4340
4511
|
init_backup();
|
|
4341
4512
|
init_encryption();
|
|
4513
|
+
init_domains();
|
|
4514
|
+
CONFIG_DIR = join5(homedir2(), ".mma");
|
|
4515
|
+
CONFIG_FILE = join5(CONFIG_DIR, "config.json");
|
|
4516
|
+
CONFIG_DOMAIN_DIR = join5(CONFIG_DIR, "config");
|
|
4342
4517
|
LEGACY_LSP_SERVER_ARGS = {
|
|
4343
4518
|
typescript: { args: ["typescript-language-server", "--stdio"], timeout: 30000 },
|
|
4344
4519
|
javascript: { args: ["typescript-language-server", "--stdio"], timeout: 30000 },
|
|
@@ -4409,31 +4584,31 @@ var init_data_sanitizer = __esm(() => {
|
|
|
4409
4584
|
// src/logger/file-log.ts
|
|
4410
4585
|
import {
|
|
4411
4586
|
appendFileSync,
|
|
4412
|
-
mkdirSync as
|
|
4413
|
-
existsSync as
|
|
4414
|
-
readdirSync as
|
|
4587
|
+
mkdirSync as mkdirSync4,
|
|
4588
|
+
existsSync as existsSync6,
|
|
4589
|
+
readdirSync as readdirSync4,
|
|
4415
4590
|
renameSync,
|
|
4416
4591
|
statSync,
|
|
4417
4592
|
unlinkSync as unlinkSync2
|
|
4418
4593
|
} from "node:fs";
|
|
4419
|
-
import { join as
|
|
4594
|
+
import { join as join6 } from "node:path";
|
|
4420
4595
|
|
|
4421
4596
|
class FileLogWriter {
|
|
4422
4597
|
logDir = null;
|
|
4423
4598
|
sessionLogPath = null;
|
|
4424
4599
|
setLogDir(dir) {
|
|
4425
4600
|
this.logDir = dir;
|
|
4426
|
-
if (!
|
|
4427
|
-
|
|
4601
|
+
if (!existsSync6(dir)) {
|
|
4602
|
+
mkdirSync4(dir, { recursive: true });
|
|
4428
4603
|
}
|
|
4429
4604
|
}
|
|
4430
4605
|
initSessionLog(sessionId) {
|
|
4431
4606
|
if (!this.logDir)
|
|
4432
4607
|
return;
|
|
4433
|
-
if (!
|
|
4434
|
-
|
|
4608
|
+
if (!existsSync6(this.logDir)) {
|
|
4609
|
+
mkdirSync4(this.logDir, { recursive: true });
|
|
4435
4610
|
}
|
|
4436
|
-
this.sessionLogPath =
|
|
4611
|
+
this.sessionLogPath = join6(this.logDir, `${sessionId}.log`);
|
|
4437
4612
|
this.cleanupOldLogs();
|
|
4438
4613
|
}
|
|
4439
4614
|
closeSessionLog() {
|
|
@@ -4445,16 +4620,16 @@ class FileLogWriter {
|
|
|
4445
4620
|
if (!this.logDir)
|
|
4446
4621
|
return "";
|
|
4447
4622
|
const date = new Date().toISOString().slice(0, 10);
|
|
4448
|
-
return
|
|
4623
|
+
return join6(this.logDir, `${date}.log`);
|
|
4449
4624
|
}
|
|
4450
4625
|
rotateIfNeeded(filePath) {
|
|
4451
|
-
if (!
|
|
4626
|
+
if (!existsSync6(filePath))
|
|
4452
4627
|
return;
|
|
4453
4628
|
const size = statSync(filePath).size;
|
|
4454
4629
|
if (size < MAX_LOG_SIZE)
|
|
4455
4630
|
return;
|
|
4456
4631
|
let idx = 1;
|
|
4457
|
-
while (
|
|
4632
|
+
while (existsSync6(`${filePath}.${idx}`))
|
|
4458
4633
|
idx++;
|
|
4459
4634
|
renameSync(filePath, `${filePath}.${idx}`);
|
|
4460
4635
|
}
|
|
@@ -4462,8 +4637,8 @@ class FileLogWriter {
|
|
|
4462
4637
|
const fp = this.getLogPath();
|
|
4463
4638
|
if (!fp)
|
|
4464
4639
|
return;
|
|
4465
|
-
if (this.logDir && !
|
|
4466
|
-
|
|
4640
|
+
if (this.logDir && !existsSync6(this.logDir)) {
|
|
4641
|
+
mkdirSync4(this.logDir, { recursive: true });
|
|
4467
4642
|
}
|
|
4468
4643
|
this.rotateIfNeeded(fp);
|
|
4469
4644
|
const line = `[${new Date().toISOString()}] [${level}] [${tag}] ${message}
|
|
@@ -4504,13 +4679,13 @@ ${trimmed}`);
|
|
|
4504
4679
|
this.log("INFO", `REPL/${tag}`, trimmed);
|
|
4505
4680
|
}
|
|
4506
4681
|
cleanupOldLogs(maxDays = DEFAULT_MAX_DAYS, maxFiles = MAX_LOG_FILES) {
|
|
4507
|
-
if (!this.logDir || !
|
|
4682
|
+
if (!this.logDir || !existsSync6(this.logDir))
|
|
4508
4683
|
return;
|
|
4509
4684
|
const now = Date.now();
|
|
4510
|
-
const list = () =>
|
|
4685
|
+
const list = () => readdirSync4(this.logDir).filter((f) => f.endsWith(".log") || /\.log\.\d+$/.test(f)).map((f) => ({
|
|
4511
4686
|
name: f,
|
|
4512
|
-
path:
|
|
4513
|
-
mtime: statSync(
|
|
4687
|
+
path: join6(this.logDir, f),
|
|
4688
|
+
mtime: statSync(join6(this.logDir, f)).mtimeMs
|
|
4514
4689
|
})).sort((a, b) => b.mtime - a.mtime);
|
|
4515
4690
|
for (const f of list()) {
|
|
4516
4691
|
if (now - f.mtime > maxDays * 24 * 60 * 60 * 1000) {
|
|
@@ -4603,8 +4778,8 @@ var require_picocolors = __commonJS((exports, module) => {
|
|
|
4603
4778
|
});
|
|
4604
4779
|
|
|
4605
4780
|
// src/logger/app-logger.ts
|
|
4606
|
-
import { appendFileSync as appendFileSync2, mkdirSync as
|
|
4607
|
-
import { join as
|
|
4781
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, existsSync as existsSync7 } from "fs";
|
|
4782
|
+
import { join as join7 } from "path";
|
|
4608
4783
|
function isColorEnabled() {
|
|
4609
4784
|
return !process.env.NO_COLOR && !process.env.CI && process.stdout.isTTY === true;
|
|
4610
4785
|
}
|
|
@@ -4625,15 +4800,15 @@ class Logger {
|
|
|
4625
4800
|
}
|
|
4626
4801
|
setLogDir(dir) {
|
|
4627
4802
|
this.logDir = dir;
|
|
4628
|
-
if (!
|
|
4629
|
-
|
|
4803
|
+
if (!existsSync7(dir)) {
|
|
4804
|
+
mkdirSync5(dir, { recursive: true });
|
|
4630
4805
|
}
|
|
4631
4806
|
this.fileLog.setLogDir(dir);
|
|
4632
4807
|
}
|
|
4633
4808
|
setSessionDir(dir) {
|
|
4634
4809
|
this.sessionDir = dir;
|
|
4635
|
-
if (!
|
|
4636
|
-
|
|
4810
|
+
if (!existsSync7(dir)) {
|
|
4811
|
+
mkdirSync5(dir, { recursive: true });
|
|
4637
4812
|
}
|
|
4638
4813
|
}
|
|
4639
4814
|
clearSessionDir() {
|
|
@@ -4700,7 +4875,7 @@ class Logger {
|
|
|
4700
4875
|
const logTarget = this.sessionDir ?? this.logDir;
|
|
4701
4876
|
if (logTarget) {
|
|
4702
4877
|
try {
|
|
4703
|
-
appendFileSync2(
|
|
4878
|
+
appendFileSync2(join7(logTarget, "app.jsonl"), JSON.stringify({
|
|
4704
4879
|
level,
|
|
4705
4880
|
ts,
|
|
4706
4881
|
prefix: this.prefix,
|
|
@@ -4729,7 +4904,7 @@ class Logger {
|
|
|
4729
4904
|
if (!logTarget)
|
|
4730
4905
|
return;
|
|
4731
4906
|
try {
|
|
4732
|
-
appendFileSync2(
|
|
4907
|
+
appendFileSync2(join7(logTarget, "app.jsonl"), JSON.stringify({
|
|
4733
4908
|
level: "info",
|
|
4734
4909
|
ts: new Date().toISOString(),
|
|
4735
4910
|
type,
|
|
@@ -4746,7 +4921,7 @@ class Logger {
|
|
|
4746
4921
|
const sanitizedMsg = sanitizeLogMessage(msg);
|
|
4747
4922
|
const sanitizedMeta = meta ? this.sanitizeMeta(meta) : undefined;
|
|
4748
4923
|
try {
|
|
4749
|
-
appendFileSync2(
|
|
4924
|
+
appendFileSync2(join7(logTarget, "app.jsonl"), JSON.stringify({
|
|
4750
4925
|
level,
|
|
4751
4926
|
ts,
|
|
4752
4927
|
prefix: this.prefix,
|
|
@@ -6446,7 +6621,7 @@ var init_executor = __esm(() => {
|
|
|
6446
6621
|
|
|
6447
6622
|
// src/tools/path-utils.ts
|
|
6448
6623
|
import { resolve, normalize, dirname as dirname2, basename, sep, relative, isAbsolute } from "path";
|
|
6449
|
-
import { existsSync as
|
|
6624
|
+
import { existsSync as existsSync8 } from "fs";
|
|
6450
6625
|
function isInsideDir(targetPath, dirPath) {
|
|
6451
6626
|
const norm = (p) => process.platform === "win32" ? p.toLowerCase() : p;
|
|
6452
6627
|
const t2 = norm(resolve(targetPath));
|
|
@@ -6464,23 +6639,23 @@ function matchesScopeEntry(targetResolved, entryResolved) {
|
|
|
6464
6639
|
function safeResolvePath(baseDir, userPath) {
|
|
6465
6640
|
const asIs = resolve(normalize(userPath));
|
|
6466
6641
|
if (userPath.startsWith("/") || userPath.startsWith("\\")) {
|
|
6467
|
-
if (
|
|
6642
|
+
if (existsSync8(asIs) || existsSync8(dirname2(asIs)))
|
|
6468
6643
|
return asIs;
|
|
6469
6644
|
}
|
|
6470
6645
|
const norm = normalize(userPath);
|
|
6471
6646
|
if (isAbsolute(norm)) {
|
|
6472
|
-
if (
|
|
6647
|
+
if (existsSync8(norm) || existsSync8(dirname2(norm)))
|
|
6473
6648
|
return norm;
|
|
6474
6649
|
const stripped2 = norm.replace(/^[/\\]/, "");
|
|
6475
6650
|
const relativeCandidate = resolve(baseDir, stripped2);
|
|
6476
|
-
if (
|
|
6651
|
+
if (existsSync8(relativeCandidate) || existsSync8(dirname2(relativeCandidate))) {
|
|
6477
6652
|
return relativeCandidate;
|
|
6478
6653
|
}
|
|
6479
6654
|
return norm;
|
|
6480
6655
|
}
|
|
6481
6656
|
const stripped = norm.replace(/^[/\\]/, "");
|
|
6482
6657
|
const resolved = resolve(baseDir, stripped);
|
|
6483
|
-
if (
|
|
6658
|
+
if (existsSync8(resolved) || existsSync8(dirname2(resolved)))
|
|
6484
6659
|
return resolved;
|
|
6485
6660
|
const baseNorm = normalize(baseDir);
|
|
6486
6661
|
let cur = baseNorm;
|
|
@@ -6497,11 +6672,11 @@ function safeResolvePath(baseDir, userPath) {
|
|
|
6497
6672
|
if (afterChar && afterChar !== "\\" && afterChar !== "/") {
|
|
6498
6673
|
const fixed = stripped.slice(0, afterIdx) + sep + stripped.slice(afterIdx);
|
|
6499
6674
|
const fixedResolved = resolve(baseDir, normalize(fixed));
|
|
6500
|
-
if (
|
|
6675
|
+
if (existsSync8(fixedResolved) || existsSync8(dirname2(fixedResolved))) {
|
|
6501
6676
|
return fixedResolved;
|
|
6502
6677
|
}
|
|
6503
6678
|
const fromParent = resolve(dirname2(cur), normalize(fixed));
|
|
6504
|
-
if (
|
|
6679
|
+
if (existsSync8(fromParent) || existsSync8(dirname2(fromParent))) {
|
|
6505
6680
|
return fromParent;
|
|
6506
6681
|
}
|
|
6507
6682
|
}
|
|
@@ -6699,10 +6874,10 @@ __export(exports_audit_notifier, {
|
|
|
6699
6874
|
DEFAULT_AUDIT_NOTIFIER_CONFIG: () => DEFAULT_AUDIT_NOTIFIER_CONFIG,
|
|
6700
6875
|
AuditNotifier: () => AuditNotifier
|
|
6701
6876
|
});
|
|
6702
|
-
import { writeFileSync as
|
|
6703
|
-
import { join as
|
|
6704
|
-
import { homedir as
|
|
6705
|
-
import { readFileSync as
|
|
6877
|
+
import { writeFileSync as writeFileSync5, appendFileSync as appendFileSync3, existsSync as existsSync9, mkdirSync as mkdirSync6 } from "fs";
|
|
6878
|
+
import { join as join8, dirname as dirname3 } from "path";
|
|
6879
|
+
import { homedir as homedir3 } from "os";
|
|
6880
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
6706
6881
|
|
|
6707
6882
|
class AuditNotifier {
|
|
6708
6883
|
config;
|
|
@@ -6728,7 +6903,7 @@ class AuditNotifier {
|
|
|
6728
6903
|
ensureLogDirectory() {
|
|
6729
6904
|
if (this.config.filePath) {
|
|
6730
6905
|
const dir = dirname3(this.config.filePath);
|
|
6731
|
-
|
|
6906
|
+
mkdirSync6(dir, { recursive: true });
|
|
6732
6907
|
}
|
|
6733
6908
|
}
|
|
6734
6909
|
shouldNotify(eventType) {
|
|
@@ -6850,11 +7025,11 @@ class AuditNotifier {
|
|
|
6850
7025
|
this.isProcessing = false;
|
|
6851
7026
|
}
|
|
6852
7027
|
readNotifications(limit = 100) {
|
|
6853
|
-
if (!this.config.filePath || !
|
|
7028
|
+
if (!this.config.filePath || !existsSync9(this.config.filePath)) {
|
|
6854
7029
|
return [];
|
|
6855
7030
|
}
|
|
6856
7031
|
try {
|
|
6857
|
-
const content =
|
|
7032
|
+
const content = readFileSync5(this.config.filePath, "utf8");
|
|
6858
7033
|
const lines = content.split(`
|
|
6859
7034
|
`).filter(Boolean);
|
|
6860
7035
|
return lines.slice(-limit).map((line) => JSON.parse(line));
|
|
@@ -6864,7 +7039,7 @@ class AuditNotifier {
|
|
|
6864
7039
|
}
|
|
6865
7040
|
clearNotifications() {
|
|
6866
7041
|
if (this.config.filePath) {
|
|
6867
|
-
|
|
7042
|
+
writeFileSync5(this.config.filePath, "", "utf8");
|
|
6868
7043
|
}
|
|
6869
7044
|
this.retryQueue = [];
|
|
6870
7045
|
}
|
|
@@ -6907,7 +7082,7 @@ var init_audit_notifier = __esm(() => {
|
|
|
6907
7082
|
};
|
|
6908
7083
|
DEFAULT_AUDIT_NOTIFIER_CONFIG = {
|
|
6909
7084
|
enabled: false,
|
|
6910
|
-
filePath:
|
|
7085
|
+
filePath: join8(homedir3(), ".mma", "logs", "audit-notifications.jsonl"),
|
|
6911
7086
|
webhookTimeout: 5000,
|
|
6912
7087
|
minSeverity: "medium",
|
|
6913
7088
|
eventTypes: [
|
|
@@ -6924,26 +7099,26 @@ var init_audit_notifier = __esm(() => {
|
|
|
6924
7099
|
});
|
|
6925
7100
|
|
|
6926
7101
|
// src/modules/security/audit-log.ts
|
|
6927
|
-
import { existsSync as
|
|
6928
|
-
import { resolve as resolve3, join as
|
|
6929
|
-
import { homedir as
|
|
7102
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync7, appendFileSync as appendFileSync4 } from "fs";
|
|
7103
|
+
import { resolve as resolve3, join as join9 } from "path";
|
|
7104
|
+
import { homedir as homedir4 } from "os";
|
|
6930
7105
|
function getAuditDir() {
|
|
6931
7106
|
return _sessionAuditDir ?? _globalAuditDir;
|
|
6932
7107
|
}
|
|
6933
7108
|
function setAuditSessionDir(dir) {
|
|
6934
7109
|
_sessionAuditDir = dir;
|
|
6935
|
-
if (!
|
|
6936
|
-
|
|
7110
|
+
if (!existsSync10(dir)) {
|
|
7111
|
+
mkdirSync7(dir, { recursive: true, mode: 448 });
|
|
6937
7112
|
}
|
|
6938
7113
|
}
|
|
6939
7114
|
function logAudit(entry) {
|
|
6940
7115
|
const dir = getAuditDir();
|
|
6941
|
-
if (!
|
|
6942
|
-
|
|
7116
|
+
if (!existsSync10(dir)) {
|
|
7117
|
+
mkdirSync7(dir, { recursive: true, mode: 448 });
|
|
6943
7118
|
}
|
|
6944
7119
|
try {
|
|
6945
7120
|
const logEntry = JSON.stringify(entry);
|
|
6946
|
-
appendFileSync4(
|
|
7121
|
+
appendFileSync4(join9(dir, "audit.jsonl"), logEntry + `
|
|
6947
7122
|
`, "utf8");
|
|
6948
7123
|
} catch {}
|
|
6949
7124
|
try {
|
|
@@ -7003,11 +7178,11 @@ function logSecurityBlock(sessionId, action, reason, details) {
|
|
|
7003
7178
|
var _globalAuditDir, _sessionAuditDir = null;
|
|
7004
7179
|
var init_audit_log = __esm(() => {
|
|
7005
7180
|
init_audit_notifier();
|
|
7006
|
-
_globalAuditDir = resolve3(
|
|
7181
|
+
_globalAuditDir = resolve3(homedir4(), ".mma", "logs");
|
|
7007
7182
|
});
|
|
7008
7183
|
|
|
7009
7184
|
// src/tools/read-file.ts
|
|
7010
|
-
import { readFileSync as
|
|
7185
|
+
import { readFileSync as readFileSync6, existsSync as existsSync11, statSync as statSync2, openSync, readSync, closeSync } from "fs";
|
|
7011
7186
|
import { extname } from "path";
|
|
7012
7187
|
function readLineSlice(path, offset, limit) {
|
|
7013
7188
|
const fd = openSync(path, "r");
|
|
@@ -7108,7 +7283,7 @@ var init_read_file = __esm(() => {
|
|
|
7108
7283
|
})
|
|
7109
7284
|
};
|
|
7110
7285
|
}
|
|
7111
|
-
if (!
|
|
7286
|
+
if (!existsSync11(resolved)) {
|
|
7112
7287
|
const output = resolved !== path ? t("file.notfound_resolved", {
|
|
7113
7288
|
path,
|
|
7114
7289
|
resolved
|
|
@@ -7125,7 +7300,7 @@ var init_read_file = __esm(() => {
|
|
|
7125
7300
|
total = slice.total;
|
|
7126
7301
|
selected = slice.selected;
|
|
7127
7302
|
} else {
|
|
7128
|
-
const content =
|
|
7303
|
+
const content = readFileSync6(resolved, "utf-8");
|
|
7129
7304
|
lines = content.split(`
|
|
7130
7305
|
`);
|
|
7131
7306
|
total = lines.length;
|
|
@@ -7217,16 +7392,16 @@ __export(exports_session_isolation, {
|
|
|
7217
7392
|
cleanupSessionTempDir: () => cleanupSessionTempDir,
|
|
7218
7393
|
DEFAULT_SESSION_ISOLATION: () => DEFAULT_SESSION_ISOLATION
|
|
7219
7394
|
});
|
|
7220
|
-
import { join as
|
|
7221
|
-
import { homedir as
|
|
7222
|
-
import { mkdirSync as
|
|
7395
|
+
import { join as join10, resolve as resolve5 } from "path";
|
|
7396
|
+
import { homedir as homedir5 } from "os";
|
|
7397
|
+
import { mkdirSync as mkdirSync8, existsSync as existsSync12 } from "fs";
|
|
7223
7398
|
function createSessionContext(sessionId, projectDir, isolationConfig, securityOverrides) {
|
|
7224
7399
|
const config = { ...DEFAULT_SESSION_ISOLATION, ...isolationConfig };
|
|
7225
|
-
const baseDir = config.baseDir ||
|
|
7226
|
-
const tempDir =
|
|
7227
|
-
if (config.isolateTempFiles && !
|
|
7400
|
+
const baseDir = config.baseDir || join10(homedir5(), ".mma", "sessions", sessionId);
|
|
7401
|
+
const tempDir = join10(baseDir, "temp");
|
|
7402
|
+
if (config.isolateTempFiles && !existsSync12(tempDir)) {
|
|
7228
7403
|
try {
|
|
7229
|
-
|
|
7404
|
+
mkdirSync8(tempDir, { recursive: true, mode: 448 });
|
|
7230
7405
|
} catch {}
|
|
7231
7406
|
}
|
|
7232
7407
|
return {
|
|
@@ -7476,7 +7651,7 @@ var init_diff = __esm(() => {
|
|
|
7476
7651
|
});
|
|
7477
7652
|
|
|
7478
7653
|
// src/tools/write-file.ts
|
|
7479
|
-
import { writeFileSync as
|
|
7654
|
+
import { writeFileSync as writeFileSync6, mkdirSync as mkdirSync9, existsSync as existsSync13, readFileSync as readFileSync7 } from "fs";
|
|
7480
7655
|
import { dirname as dirname4 } from "path";
|
|
7481
7656
|
var writeFileTool;
|
|
7482
7657
|
var init_write_file = __esm(() => {
|
|
@@ -7535,15 +7710,15 @@ var init_write_file = __esm(() => {
|
|
|
7535
7710
|
}
|
|
7536
7711
|
}
|
|
7537
7712
|
const dir = dirname4(resolved);
|
|
7538
|
-
if (!
|
|
7539
|
-
|
|
7713
|
+
if (!existsSync13(dir)) {
|
|
7714
|
+
mkdirSync9(dir, { recursive: true });
|
|
7540
7715
|
}
|
|
7541
|
-
const fileExists =
|
|
7716
|
+
const fileExists = existsSync13(resolved);
|
|
7542
7717
|
let oldContent = "";
|
|
7543
7718
|
if (fileExists) {
|
|
7544
|
-
oldContent =
|
|
7719
|
+
oldContent = readFileSync7(resolved, "utf-8");
|
|
7545
7720
|
}
|
|
7546
|
-
|
|
7721
|
+
writeFileSync6(resolved, content, "utf-8");
|
|
7547
7722
|
const diff = fileExists ? generateDiff(oldContent, content) : generateNewFileDiff(content);
|
|
7548
7723
|
ctx.fileOperationsCount = currentCount + 1;
|
|
7549
7724
|
logFileWrite(ctx.sessionId, path, true, `File ${fileExists ? "updated" : "created"}`);
|
|
@@ -7553,7 +7728,7 @@ var init_write_file = __esm(() => {
|
|
|
7553
7728
|
});
|
|
7554
7729
|
|
|
7555
7730
|
// src/tools/edit-file.ts
|
|
7556
|
-
import { readFileSync as
|
|
7731
|
+
import { readFileSync as readFileSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
7557
7732
|
var editFileTool;
|
|
7558
7733
|
var init_edit_file = __esm(() => {
|
|
7559
7734
|
init_i18n();
|
|
@@ -7600,7 +7775,7 @@ var init_edit_file = __esm(() => {
|
|
|
7600
7775
|
})
|
|
7601
7776
|
};
|
|
7602
7777
|
}
|
|
7603
|
-
const content =
|
|
7778
|
+
const content = readFileSync8(resolved, "utf-8");
|
|
7604
7779
|
const oldStr = String(args.old);
|
|
7605
7780
|
const newStr = String(args.new);
|
|
7606
7781
|
if (!content.includes(oldStr)) {
|
|
@@ -7620,7 +7795,7 @@ var init_edit_file = __esm(() => {
|
|
|
7620
7795
|
};
|
|
7621
7796
|
}
|
|
7622
7797
|
}
|
|
7623
|
-
|
|
7798
|
+
writeFileSync7(resolved, updated, "utf-8");
|
|
7624
7799
|
const diff = generateDiff(content, updated);
|
|
7625
7800
|
ctx.fileOperationsCount = currentCount + 1;
|
|
7626
7801
|
logFileWrite(ctx.sessionId, path, true, "File edited");
|
|
@@ -7777,7 +7952,7 @@ var init_grep_tool = __esm(() => {
|
|
|
7777
7952
|
});
|
|
7778
7953
|
|
|
7779
7954
|
// src/tools/list-dir.ts
|
|
7780
|
-
import { readdirSync as
|
|
7955
|
+
import { readdirSync as readdirSync5, statSync as statSync3, existsSync as existsSync14 } from "fs";
|
|
7781
7956
|
import { resolve as resolve8 } from "path";
|
|
7782
7957
|
var listDirTool;
|
|
7783
7958
|
var init_list_dir = __esm(() => {
|
|
@@ -7809,10 +7984,10 @@ var init_list_dir = __esm(() => {
|
|
|
7809
7984
|
})
|
|
7810
7985
|
};
|
|
7811
7986
|
}
|
|
7812
|
-
if (!
|
|
7987
|
+
if (!existsSync14(resolved)) {
|
|
7813
7988
|
return { success: false, output: t("file.dir_notfound", { path }) };
|
|
7814
7989
|
}
|
|
7815
|
-
const entries =
|
|
7990
|
+
const entries = readdirSync5(resolved);
|
|
7816
7991
|
const lines = entries.map((e) => {
|
|
7817
7992
|
const full = resolve8(resolved, e);
|
|
7818
7993
|
return statSync3(full).isDirectory() ? `${e}/` : e;
|
|
@@ -7829,7 +8004,7 @@ var init_list_dir = __esm(() => {
|
|
|
7829
8004
|
});
|
|
7830
8005
|
|
|
7831
8006
|
// src/tools/create-dir.ts
|
|
7832
|
-
import { mkdirSync as
|
|
8007
|
+
import { mkdirSync as mkdirSync10, existsSync as existsSync15 } from "fs";
|
|
7833
8008
|
var createDirTool;
|
|
7834
8009
|
var init_create_dir = __esm(() => {
|
|
7835
8010
|
init_i18n();
|
|
@@ -7872,8 +8047,8 @@ var init_create_dir = __esm(() => {
|
|
|
7872
8047
|
})
|
|
7873
8048
|
};
|
|
7874
8049
|
}
|
|
7875
|
-
if (!
|
|
7876
|
-
|
|
8050
|
+
if (!existsSync15(resolved)) {
|
|
8051
|
+
mkdirSync10(resolved, { recursive: true });
|
|
7877
8052
|
}
|
|
7878
8053
|
ctx.fileOperationsCount = currentCount + 1;
|
|
7879
8054
|
logFileWrite(ctx.sessionId, path, true, "Directory created");
|
|
@@ -7883,7 +8058,7 @@ var init_create_dir = __esm(() => {
|
|
|
7883
8058
|
});
|
|
7884
8059
|
|
|
7885
8060
|
// src/tools/delete-file.ts
|
|
7886
|
-
import { unlinkSync as unlinkSync3, existsSync as
|
|
8061
|
+
import { unlinkSync as unlinkSync3, existsSync as existsSync16, statSync as statSync4, readFileSync as readFileSync9 } from "fs";
|
|
7887
8062
|
var deleteFileTool;
|
|
7888
8063
|
var init_delete_file = __esm(() => {
|
|
7889
8064
|
init_i18n();
|
|
@@ -7927,13 +8102,13 @@ var init_delete_file = __esm(() => {
|
|
|
7927
8102
|
})
|
|
7928
8103
|
};
|
|
7929
8104
|
}
|
|
7930
|
-
if (!
|
|
8105
|
+
if (!existsSync16(resolved)) {
|
|
7931
8106
|
return { success: false, output: t("file.notfound", { path }) };
|
|
7932
8107
|
}
|
|
7933
8108
|
if (statSync4(resolved).isDirectory()) {
|
|
7934
8109
|
return { success: false, output: t("file.is_directory", { path }) };
|
|
7935
8110
|
}
|
|
7936
|
-
const content =
|
|
8111
|
+
const content = readFileSync9(resolved, "utf-8");
|
|
7937
8112
|
unlinkSync3(resolved);
|
|
7938
8113
|
const diff = generateDeleteDiff(content);
|
|
7939
8114
|
ctx.fileOperationsCount = currentCount + 1;
|
|
@@ -7944,7 +8119,7 @@ var init_delete_file = __esm(() => {
|
|
|
7944
8119
|
});
|
|
7945
8120
|
|
|
7946
8121
|
// src/tools/move-file.ts
|
|
7947
|
-
import { renameSync as renameSync2, existsSync as
|
|
8122
|
+
import { renameSync as renameSync2, existsSync as existsSync17, mkdirSync as mkdirSync11 } from "fs";
|
|
7948
8123
|
import { resolve as resolve9, normalize as normalize3, dirname as dirname5 } from "path";
|
|
7949
8124
|
var moveFileTool;
|
|
7950
8125
|
var init_move_file = __esm(() => {
|
|
@@ -8003,15 +8178,15 @@ var init_move_file = __esm(() => {
|
|
|
8003
8178
|
})
|
|
8004
8179
|
};
|
|
8005
8180
|
}
|
|
8006
|
-
if (!
|
|
8181
|
+
if (!existsSync17(fromResolved)) {
|
|
8007
8182
|
return {
|
|
8008
8183
|
success: false,
|
|
8009
8184
|
output: t("file.not_found_short", { path: fromPath })
|
|
8010
8185
|
};
|
|
8011
8186
|
}
|
|
8012
8187
|
const toDir = dirname5(toResolved);
|
|
8013
|
-
if (!
|
|
8014
|
-
|
|
8188
|
+
if (!existsSync17(toDir)) {
|
|
8189
|
+
mkdirSync11(toDir, { recursive: true });
|
|
8015
8190
|
}
|
|
8016
8191
|
renameSync2(fromResolved, toResolved);
|
|
8017
8192
|
const diff = generateMoveDiff(fromPath, toPath);
|
|
@@ -8027,7 +8202,7 @@ var init_move_file = __esm(() => {
|
|
|
8027
8202
|
});
|
|
8028
8203
|
|
|
8029
8204
|
// src/tools/file-info.ts
|
|
8030
|
-
import { statSync as statSync5, existsSync as
|
|
8205
|
+
import { statSync as statSync5, existsSync as existsSync18 } from "fs";
|
|
8031
8206
|
var fileInfoTool;
|
|
8032
8207
|
var init_file_info = __esm(() => {
|
|
8033
8208
|
init_i18n();
|
|
@@ -8058,7 +8233,7 @@ var init_file_info = __esm(() => {
|
|
|
8058
8233
|
})
|
|
8059
8234
|
};
|
|
8060
8235
|
}
|
|
8061
|
-
if (!
|
|
8236
|
+
if (!existsSync18(resolved)) {
|
|
8062
8237
|
return { success: false, output: t("file.not_found_short", { path }) };
|
|
8063
8238
|
}
|
|
8064
8239
|
const stat = statSync5(resolved);
|
|
@@ -9120,8 +9295,8 @@ var init_prompt_builder = __esm(() => {
|
|
|
9120
9295
|
});
|
|
9121
9296
|
|
|
9122
9297
|
// src/core/session-logger.ts
|
|
9123
|
-
import { join as
|
|
9124
|
-
import { readFileSync as
|
|
9298
|
+
import { join as join11 } from "path";
|
|
9299
|
+
import { readFileSync as readFileSync10, existsSync as existsSync19 } from "fs";
|
|
9125
9300
|
|
|
9126
9301
|
class SessionLogger {
|
|
9127
9302
|
session;
|
|
@@ -9329,10 +9504,10 @@ class SessionLogger {
|
|
|
9329
9504
|
logSessionStart(data) {
|
|
9330
9505
|
const meta = this.session?.getActiveMeta();
|
|
9331
9506
|
if (meta) {
|
|
9332
|
-
const logPath =
|
|
9507
|
+
const logPath = join11(this.session.getSessionDirectory(meta.id), "session.jsonl");
|
|
9333
9508
|
try {
|
|
9334
|
-
if (
|
|
9335
|
-
const content =
|
|
9509
|
+
if (existsSync19(logPath)) {
|
|
9510
|
+
const content = readFileSync10(logPath, "utf-8");
|
|
9336
9511
|
if (content.includes('"type":"session_start"'))
|
|
9337
9512
|
return;
|
|
9338
9513
|
}
|
|
@@ -11056,7 +11231,7 @@ var init_stuck_detector = __esm(() => {
|
|
|
11056
11231
|
});
|
|
11057
11232
|
|
|
11058
11233
|
// src/modules/artifacts/store.ts
|
|
11059
|
-
import { existsSync as
|
|
11234
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync12, readFileSync as readFileSync11, writeFileSync as writeFileSync8 } from "node:fs";
|
|
11060
11235
|
import { resolve as resolve10, relative as relative2, isAbsolute as isAbsolute2 } from "node:path";
|
|
11061
11236
|
|
|
11062
11237
|
class ArtifactStore {
|
|
@@ -11082,21 +11257,21 @@ class ArtifactStore {
|
|
|
11082
11257
|
save(name, content, ext = "md") {
|
|
11083
11258
|
const safe = ArtifactStore.sanitizeName(name);
|
|
11084
11259
|
const dir = resolve10(this.root);
|
|
11085
|
-
|
|
11260
|
+
mkdirSync12(dir, { recursive: true });
|
|
11086
11261
|
const abs = resolve10(dir, `${safe}.${ext}`);
|
|
11087
11262
|
if (!ArtifactStore.isInside(dir, abs)) {
|
|
11088
11263
|
throw new Error(`Artifact path escapes root: ${abs}`);
|
|
11089
11264
|
}
|
|
11090
|
-
|
|
11265
|
+
writeFileSync8(abs, content, "utf8");
|
|
11091
11266
|
return abs;
|
|
11092
11267
|
}
|
|
11093
11268
|
read(path) {
|
|
11094
11269
|
const abs = resolve10(this.root, path);
|
|
11095
11270
|
if (!ArtifactStore.isInside(this.root, abs))
|
|
11096
11271
|
return null;
|
|
11097
|
-
if (!
|
|
11272
|
+
if (!existsSync20(abs))
|
|
11098
11273
|
return null;
|
|
11099
|
-
return
|
|
11274
|
+
return readFileSync11(abs, "utf8");
|
|
11100
11275
|
}
|
|
11101
11276
|
summary(content, maxChars) {
|
|
11102
11277
|
if (content.length <= maxChars)
|
|
@@ -11420,15 +11595,15 @@ var init_moe_executor = __esm(() => {
|
|
|
11420
11595
|
});
|
|
11421
11596
|
|
|
11422
11597
|
// src/modules/lsp/project-root.ts
|
|
11423
|
-
import { existsSync as
|
|
11424
|
-
import { dirname as dirname6, join as
|
|
11598
|
+
import { existsSync as existsSync21 } from "fs";
|
|
11599
|
+
import { dirname as dirname6, join as join12 } from "path";
|
|
11425
11600
|
function findProjectRoot(filePath, baseDir, markers) {
|
|
11426
11601
|
if (!markers || markers.length === 0)
|
|
11427
11602
|
return baseDir;
|
|
11428
11603
|
let dir = dirname6(filePath);
|
|
11429
11604
|
const root = baseDir.replace(/[\\/]+$/, "");
|
|
11430
11605
|
while (true) {
|
|
11431
|
-
if (markers.some((m) =>
|
|
11606
|
+
if (markers.some((m) => existsSync21(join12(dir, m)))) {
|
|
11432
11607
|
return dir;
|
|
11433
11608
|
}
|
|
11434
11609
|
if (dir === root)
|
|
@@ -11651,13 +11826,13 @@ var init_js_identifiers = __esm(() => {
|
|
|
11651
11826
|
});
|
|
11652
11827
|
|
|
11653
11828
|
// src/modules/execution/audit-runners.ts
|
|
11654
|
-
import { existsSync as
|
|
11655
|
-
import { dirname as dirname7, join as
|
|
11829
|
+
import { existsSync as existsSync22, readdirSync as readdirSync6, readFileSync as readFileSync12 } from "fs";
|
|
11830
|
+
import { dirname as dirname7, join as join13, resolve as resolve11 } from "path";
|
|
11656
11831
|
function resolveTestCommand(dir) {
|
|
11657
|
-
const pkgPath =
|
|
11658
|
-
if (
|
|
11832
|
+
const pkgPath = join13(dir, "package.json");
|
|
11833
|
+
if (existsSync22(pkgPath)) {
|
|
11659
11834
|
try {
|
|
11660
|
-
const pkg = JSON.parse(
|
|
11835
|
+
const pkg = JSON.parse(readFileSync12(pkgPath, "utf-8"));
|
|
11661
11836
|
const script = pkg?.scripts?.test;
|
|
11662
11837
|
if (typeof script === "string" && script.trim())
|
|
11663
11838
|
return script.trim();
|
|
@@ -11673,7 +11848,7 @@ function resolveTestCommand(dir) {
|
|
|
11673
11848
|
"jest.config.cjs",
|
|
11674
11849
|
"bunfig.toml"
|
|
11675
11850
|
]) {
|
|
11676
|
-
if (
|
|
11851
|
+
if (existsSync22(join13(dir, f))) {
|
|
11677
11852
|
if (f.startsWith("vitest"))
|
|
11678
11853
|
return "bunx vitest run";
|
|
11679
11854
|
if (f.startsWith("jest"))
|
|
@@ -11682,12 +11857,12 @@ function resolveTestCommand(dir) {
|
|
|
11682
11857
|
return "bun test";
|
|
11683
11858
|
}
|
|
11684
11859
|
}
|
|
11685
|
-
if (
|
|
11860
|
+
if (existsSync22(join13(dir, "pyproject.toml")) || existsSync22(join13(dir, "pytest.ini")) || existsSync22(join13(dir, "conftest.py"))) {
|
|
11686
11861
|
return "python -m pytest -q";
|
|
11687
11862
|
}
|
|
11688
|
-
if (
|
|
11863
|
+
if (existsSync22(join13(dir, "go.mod")))
|
|
11689
11864
|
return "go test ./...";
|
|
11690
|
-
if (
|
|
11865
|
+
if (existsSync22(join13(dir, "Cargo.toml")))
|
|
11691
11866
|
return "cargo test";
|
|
11692
11867
|
return "bun test";
|
|
11693
11868
|
}
|
|
@@ -11696,12 +11871,12 @@ function findTestFile(dir, depth = 0) {
|
|
|
11696
11871
|
return null;
|
|
11697
11872
|
let entries;
|
|
11698
11873
|
try {
|
|
11699
|
-
entries =
|
|
11874
|
+
entries = readdirSync6(dir, { withFileTypes: true });
|
|
11700
11875
|
} catch {
|
|
11701
11876
|
return null;
|
|
11702
11877
|
}
|
|
11703
11878
|
for (const e of entries) {
|
|
11704
|
-
const full =
|
|
11879
|
+
const full = join13(dir, e.name);
|
|
11705
11880
|
if (e.isDirectory()) {
|
|
11706
11881
|
if (SKIP_DIRS.has(e.name))
|
|
11707
11882
|
continue;
|
|
@@ -11777,7 +11952,7 @@ function findTypecheckRoot(baseDir, existingFiles = []) {
|
|
|
11777
11952
|
for (const start of candidates) {
|
|
11778
11953
|
let dir = resolve11(start);
|
|
11779
11954
|
for (let depth = 0;depth <= 10; depth++) {
|
|
11780
|
-
if (
|
|
11955
|
+
if (existsSync22(join13(dir, "tsconfig.json"))) {
|
|
11781
11956
|
if (!best || depth < best.depth)
|
|
11782
11957
|
best = { depth, root: dir };
|
|
11783
11958
|
break;
|
|
@@ -11821,11 +11996,11 @@ var init_audit_runners = __esm(() => {
|
|
|
11821
11996
|
});
|
|
11822
11997
|
|
|
11823
11998
|
// src/modules/execution/auditor.ts
|
|
11824
|
-
import { existsSync as
|
|
11825
|
-
import { resolve as resolve12, join as
|
|
11999
|
+
import { existsSync as existsSync23, readdirSync as readdirSync7 } from "fs";
|
|
12000
|
+
import { resolve as resolve12, join as join14, basename as basename2 } from "path";
|
|
11826
12001
|
function findExistingFile(baseDir, filePath) {
|
|
11827
12002
|
const direct = resolve12(baseDir, filePath);
|
|
11828
|
-
if (
|
|
12003
|
+
if (existsSync23(direct))
|
|
11829
12004
|
return direct;
|
|
11830
12005
|
const name = basename2(filePath).toLowerCase();
|
|
11831
12006
|
const suffix = filePath.replace(/\\/g, "/").toLowerCase();
|
|
@@ -11835,14 +12010,14 @@ function findExistingFile(baseDir, filePath) {
|
|
|
11835
12010
|
return;
|
|
11836
12011
|
let entries;
|
|
11837
12012
|
try {
|
|
11838
|
-
entries =
|
|
12013
|
+
entries = readdirSync7(dir, { withFileTypes: true });
|
|
11839
12014
|
} catch {
|
|
11840
12015
|
return;
|
|
11841
12016
|
}
|
|
11842
12017
|
for (const e of entries) {
|
|
11843
12018
|
if (found)
|
|
11844
12019
|
return;
|
|
11845
|
-
const full =
|
|
12020
|
+
const full = join14(dir, e.name);
|
|
11846
12021
|
if (e.isDirectory()) {
|
|
11847
12022
|
if (SKIP_DIRS.has(e.name))
|
|
11848
12023
|
continue;
|
|
@@ -11980,8 +12155,8 @@ var init_auditor = __esm(() => {
|
|
|
11980
12155
|
});
|
|
11981
12156
|
|
|
11982
12157
|
// src/modules/execution/verifier.ts
|
|
11983
|
-
import { existsSync as
|
|
11984
|
-
import { resolve as resolve13, extname as extname2, join as
|
|
12158
|
+
import { existsSync as existsSync24 } from "fs";
|
|
12159
|
+
import { resolve as resolve13, extname as extname2, join as join15 } from "path";
|
|
11985
12160
|
import { spawn as spawn3 } from "child_process";
|
|
11986
12161
|
|
|
11987
12162
|
class StepVerifier {
|
|
@@ -11991,7 +12166,7 @@ class StepVerifier {
|
|
|
11991
12166
|
}
|
|
11992
12167
|
async checkFileExists(path) {
|
|
11993
12168
|
const resolved = resolve13(this.baseDir, path);
|
|
11994
|
-
const exists =
|
|
12169
|
+
const exists = existsSync24(resolved);
|
|
11995
12170
|
return {
|
|
11996
12171
|
passed: exists,
|
|
11997
12172
|
message: exists ? t("verify.file_exists", { path }) : t("verify.file_not_found", { path })
|
|
@@ -12010,7 +12185,7 @@ class StepVerifier {
|
|
|
12010
12185
|
}
|
|
12011
12186
|
async runTypeCheck() {
|
|
12012
12187
|
const tsconfigPath = resolve13(this.baseDir, "tsconfig.json");
|
|
12013
|
-
if (!
|
|
12188
|
+
if (!existsSync24(tsconfigPath)) {
|
|
12014
12189
|
return { passed: true, message: "No tsconfig.json found — skipping type check" };
|
|
12015
12190
|
}
|
|
12016
12191
|
try {
|
|
@@ -12023,8 +12198,8 @@ class StepVerifier {
|
|
|
12023
12198
|
}
|
|
12024
12199
|
async runTypeCheckForFile(filePath) {
|
|
12025
12200
|
const projectRoot = findProjectRoot(filePath, this.baseDir, ["tsconfig.json", "package.json"]);
|
|
12026
|
-
const tsconfigPath =
|
|
12027
|
-
if (!
|
|
12201
|
+
const tsconfigPath = join15(projectRoot, "tsconfig.json");
|
|
12202
|
+
if (!existsSync24(tsconfigPath)) {
|
|
12028
12203
|
return { passed: true, message: "No tsconfig.json found — skipping type check" };
|
|
12029
12204
|
}
|
|
12030
12205
|
try {
|
|
@@ -12037,7 +12212,7 @@ class StepVerifier {
|
|
|
12037
12212
|
}
|
|
12038
12213
|
async runTests() {
|
|
12039
12214
|
const pkgPath = resolve13(this.baseDir, "package.json");
|
|
12040
|
-
if (!
|
|
12215
|
+
if (!existsSync24(pkgPath)) {
|
|
12041
12216
|
return { passed: true, message: "No package.json found — skipping tests" };
|
|
12042
12217
|
}
|
|
12043
12218
|
try {
|
|
@@ -12639,16 +12814,41 @@ ${t("tool.truncated", { tokens: Math.ceil(removedChars / 2) })}`;
|
|
|
12639
12814
|
}
|
|
12640
12815
|
contextManager.addMessage({ role: "user", content: input });
|
|
12641
12816
|
slog.logUser(input);
|
|
12642
|
-
|
|
12643
|
-
|
|
12817
|
+
const startedAt = Date.now();
|
|
12818
|
+
let toolCalls = 0;
|
|
12819
|
+
const countTool = (ev) => {
|
|
12820
|
+
if (ev.type === "end")
|
|
12821
|
+
toolCalls++;
|
|
12822
|
+
onTool?.(ev);
|
|
12823
|
+
};
|
|
12824
|
+
const emitTurnEnd = (result, err) => {
|
|
12825
|
+
const interrupted = err instanceof Error && err.name === "AbortError" || this.shutdownRequested;
|
|
12826
|
+
pluginManager.runOnTurnEnd?.({
|
|
12827
|
+
logger,
|
|
12828
|
+
sessionManager: sessionManager?.getActiveMeta(),
|
|
12829
|
+
contextManager
|
|
12830
|
+
}, {
|
|
12831
|
+
success: !!result && result.success !== false && !err,
|
|
12832
|
+
durationMs: Date.now() - startedAt,
|
|
12833
|
+
textLength: (result?.text || "").length,
|
|
12834
|
+
toolCalls,
|
|
12835
|
+
interrupted: interrupted || undefined
|
|
12836
|
+
});
|
|
12837
|
+
};
|
|
12838
|
+
try {
|
|
12839
|
+
const result = config.moe?.enabled === true ? await runWithMoE({
|
|
12644
12840
|
config,
|
|
12645
12841
|
llmProvider,
|
|
12646
12842
|
toolExecutor,
|
|
12647
12843
|
logger,
|
|
12648
12844
|
baseDir: this.deps.baseDir
|
|
12649
|
-
}, input, () => this.executeSingleAgentLoop(input, onChunk, onMeta,
|
|
12845
|
+
}, input, () => this.executeSingleAgentLoop(input, onChunk, onMeta, countTool, onPhase), { onMeta, onTool: countTool, onPhase }) : await this.executeSingleAgentLoop(input, onChunk, onMeta, countTool, onPhase);
|
|
12846
|
+
emitTurnEnd(result);
|
|
12847
|
+
return result;
|
|
12848
|
+
} catch (err) {
|
|
12849
|
+
emitTurnEnd(null, err);
|
|
12850
|
+
throw err;
|
|
12650
12851
|
}
|
|
12651
|
-
return this.executeSingleAgentLoop(input, onChunk, onMeta, onTool, onPhase);
|
|
12652
12852
|
}
|
|
12653
12853
|
async executeSingleAgentLoop(input, onChunk, onMeta, onTool, onPhase) {
|
|
12654
12854
|
const {
|
|
@@ -12936,10 +13136,12 @@ ${t("tool.truncated", { tokens: Math.ceil(removedChars / 2) })}`;
|
|
|
12936
13136
|
}
|
|
12937
13137
|
}
|
|
12938
13138
|
pluginManager.runOnToolEnd({ iteration, logger, contextManager }, { id: call.id, name: call.name, arguments: call.arguments }, result, duration);
|
|
12939
|
-
if (result.display) {
|
|
12940
|
-
|
|
13139
|
+
if (result.display !== undefined) {
|
|
13140
|
+
if (result.display.length > 0) {
|
|
13141
|
+
onMeta?.(`
|
|
12941
13142
|
` + result.display + `
|
|
12942
13143
|
`);
|
|
13144
|
+
}
|
|
12943
13145
|
} else {
|
|
12944
13146
|
const metaOut = pluginManager.runOnMeta({ iteration, logger, contextManager }, result.output);
|
|
12945
13147
|
onMeta?.(`
|
|
@@ -13894,8 +14096,8 @@ var init_confidence = __esm(() => {
|
|
|
13894
14096
|
});
|
|
13895
14097
|
|
|
13896
14098
|
// src/modules/hallucination/factual.ts
|
|
13897
|
-
import { existsSync as
|
|
13898
|
-
import { resolve as resolve14, isAbsolute as isAbsolute3, join as
|
|
14099
|
+
import { existsSync as existsSync25, readdirSync as readdirSync8 } from "fs";
|
|
14100
|
+
import { resolve as resolve14, isAbsolute as isAbsolute3, join as join16 } from "path";
|
|
13899
14101
|
|
|
13900
14102
|
class FactualCheck {
|
|
13901
14103
|
baseDir;
|
|
@@ -13935,13 +14137,13 @@ class FactualCheck {
|
|
|
13935
14137
|
}
|
|
13936
14138
|
pathExists(fp) {
|
|
13937
14139
|
if (isAbsolute3(fp))
|
|
13938
|
-
return
|
|
14140
|
+
return existsSync25(fp);
|
|
13939
14141
|
if (this.knownFiles.has(fp))
|
|
13940
14142
|
return true;
|
|
13941
14143
|
for (const cand of this.dotfileVariants(fp)) {
|
|
13942
14144
|
if (this.knownFiles.has(cand))
|
|
13943
14145
|
return true;
|
|
13944
|
-
if (
|
|
14146
|
+
if (existsSync25(resolve14(this.baseDir, cand)))
|
|
13945
14147
|
return true;
|
|
13946
14148
|
}
|
|
13947
14149
|
if (!fp.includes("/") && !fp.includes("\\")) {
|
|
@@ -13958,7 +14160,7 @@ class FactualCheck {
|
|
|
13958
14160
|
}
|
|
13959
14161
|
bareNameExists(name) {
|
|
13960
14162
|
for (const cand of this.dotfileVariants(name)) {
|
|
13961
|
-
if (
|
|
14163
|
+
if (existsSync25(resolve14(this.baseDir, cand)))
|
|
13962
14164
|
return true;
|
|
13963
14165
|
if (this.indexHas(cand))
|
|
13964
14166
|
return true;
|
|
@@ -13997,14 +14199,14 @@ class FactualCheck {
|
|
|
13997
14199
|
return count;
|
|
13998
14200
|
let entries;
|
|
13999
14201
|
try {
|
|
14000
|
-
entries =
|
|
14202
|
+
entries = readdirSync8(dir, { withFileTypes: true });
|
|
14001
14203
|
} catch {
|
|
14002
14204
|
return count;
|
|
14003
14205
|
}
|
|
14004
14206
|
for (const entry of entries) {
|
|
14005
14207
|
if (count >= FactualCheck.MAX_INDEXED_FILES)
|
|
14006
14208
|
break;
|
|
14007
|
-
const full =
|
|
14209
|
+
const full = join16(dir, entry.name);
|
|
14008
14210
|
if (entry.isDirectory()) {
|
|
14009
14211
|
if (!IGNORED_DIRS.has(entry.name)) {
|
|
14010
14212
|
count = this.scanDir(full, index, count);
|
|
@@ -14178,8 +14380,8 @@ var init_detector = __esm(() => {
|
|
|
14178
14380
|
});
|
|
14179
14381
|
|
|
14180
14382
|
// src/modules/lsp/command.ts
|
|
14181
|
-
import { delimiter, join as
|
|
14182
|
-
import { existsSync as
|
|
14383
|
+
import { delimiter, join as join17 } from "path";
|
|
14384
|
+
import { existsSync as existsSync26 } from "fs";
|
|
14183
14385
|
import { platform as platform3 } from "os";
|
|
14184
14386
|
function resolveSpawnCommand(command, platformName = platform3(), pathEnv = process.env.PATH ?? "") {
|
|
14185
14387
|
if (platformName !== "win32")
|
|
@@ -14190,8 +14392,8 @@ function resolveSpawnCommand(command, platformName = platform3(), pathEnv = proc
|
|
|
14190
14392
|
const dirs = pathEnv.split(delimiter).filter(Boolean);
|
|
14191
14393
|
for (const dir of dirs) {
|
|
14192
14394
|
for (const ext of WIN_EXTS) {
|
|
14193
|
-
const candidate =
|
|
14194
|
-
if (
|
|
14395
|
+
const candidate = join17(dir, `${command}${ext}`);
|
|
14396
|
+
if (existsSync26(candidate))
|
|
14195
14397
|
return `${command}${ext}`;
|
|
14196
14398
|
}
|
|
14197
14399
|
}
|
|
@@ -14303,6 +14505,18 @@ var init_checker = __esm(() => {
|
|
|
14303
14505
|
// src/modules/plugins/manager.ts
|
|
14304
14506
|
class PluginManager {
|
|
14305
14507
|
plugins = [];
|
|
14508
|
+
hostBridge = null;
|
|
14509
|
+
setHostBridge(bridge) {
|
|
14510
|
+
this.hostBridge = bridge;
|
|
14511
|
+
}
|
|
14512
|
+
withHost(ctx) {
|
|
14513
|
+
if (!ctx || typeof ctx !== "object")
|
|
14514
|
+
return ctx;
|
|
14515
|
+
if (!this.hostBridge || ctx.hostBridge !== undefined) {
|
|
14516
|
+
return ctx;
|
|
14517
|
+
}
|
|
14518
|
+
return { ...ctx, hostBridge: this.hostBridge };
|
|
14519
|
+
}
|
|
14306
14520
|
register(plugin, source) {
|
|
14307
14521
|
if (source)
|
|
14308
14522
|
plugin.source = source;
|
|
@@ -14341,7 +14555,8 @@ class PluginManager {
|
|
|
14341
14555
|
}
|
|
14342
14556
|
});
|
|
14343
14557
|
}
|
|
14344
|
-
async runOnBeforeTool(
|
|
14558
|
+
async runOnBeforeTool(rawCtx, call) {
|
|
14559
|
+
const ctx = this.withHost(rawCtx);
|
|
14345
14560
|
for (const plugin of this.plugins) {
|
|
14346
14561
|
if (plugin.onBeforeTool) {
|
|
14347
14562
|
try {
|
|
@@ -14353,7 +14568,8 @@ class PluginManager {
|
|
|
14353
14568
|
}
|
|
14354
14569
|
return true;
|
|
14355
14570
|
}
|
|
14356
|
-
async runOnAfterTool(
|
|
14571
|
+
async runOnAfterTool(rawCtx, call, result) {
|
|
14572
|
+
const ctx = this.withHost(rawCtx);
|
|
14357
14573
|
for (const plugin of this.plugins) {
|
|
14358
14574
|
if (plugin.onAfterTool) {
|
|
14359
14575
|
try {
|
|
@@ -14362,7 +14578,8 @@ class PluginManager {
|
|
|
14362
14578
|
}
|
|
14363
14579
|
}
|
|
14364
14580
|
}
|
|
14365
|
-
async runOnError(
|
|
14581
|
+
async runOnError(rawCtx, error) {
|
|
14582
|
+
const ctx = this.withHost(rawCtx);
|
|
14366
14583
|
for (const plugin of this.plugins) {
|
|
14367
14584
|
if (plugin.onError) {
|
|
14368
14585
|
try {
|
|
@@ -14371,7 +14588,8 @@ class PluginManager {
|
|
|
14371
14588
|
}
|
|
14372
14589
|
}
|
|
14373
14590
|
}
|
|
14374
|
-
runOnSessionStart(
|
|
14591
|
+
runOnSessionStart(rawCtx) {
|
|
14592
|
+
const ctx = this.withHost(rawCtx);
|
|
14375
14593
|
for (const plugin of this.plugins) {
|
|
14376
14594
|
if (plugin.onSessionStart) {
|
|
14377
14595
|
try {
|
|
@@ -14380,7 +14598,8 @@ class PluginManager {
|
|
|
14380
14598
|
}
|
|
14381
14599
|
}
|
|
14382
14600
|
}
|
|
14383
|
-
runOnBeforeThink(
|
|
14601
|
+
runOnBeforeThink(rawCtx) {
|
|
14602
|
+
const ctx = this.withHost(rawCtx);
|
|
14384
14603
|
for (const plugin of this.plugins) {
|
|
14385
14604
|
if (plugin.onBeforeThink) {
|
|
14386
14605
|
try {
|
|
@@ -14389,7 +14608,8 @@ class PluginManager {
|
|
|
14389
14608
|
}
|
|
14390
14609
|
}
|
|
14391
14610
|
}
|
|
14392
|
-
runOnAfterThink(
|
|
14611
|
+
runOnAfterThink(rawCtx, response) {
|
|
14612
|
+
const ctx = this.withHost(rawCtx);
|
|
14393
14613
|
for (const plugin of this.plugins) {
|
|
14394
14614
|
if (plugin.onAfterThink) {
|
|
14395
14615
|
try {
|
|
@@ -14398,7 +14618,8 @@ class PluginManager {
|
|
|
14398
14618
|
}
|
|
14399
14619
|
}
|
|
14400
14620
|
}
|
|
14401
|
-
runOnSessionEnd(
|
|
14621
|
+
runOnSessionEnd(rawCtx) {
|
|
14622
|
+
const ctx = this.withHost(rawCtx);
|
|
14402
14623
|
for (const plugin of this.plugins) {
|
|
14403
14624
|
if (plugin.onSessionEnd) {
|
|
14404
14625
|
try {
|
|
@@ -14407,7 +14628,8 @@ class PluginManager {
|
|
|
14407
14628
|
}
|
|
14408
14629
|
}
|
|
14409
14630
|
}
|
|
14410
|
-
runOnToolCall(
|
|
14631
|
+
runOnToolCall(rawCtx) {
|
|
14632
|
+
const ctx = this.withHost(rawCtx);
|
|
14411
14633
|
for (const plugin of this.plugins) {
|
|
14412
14634
|
if (plugin.onToolCall) {
|
|
14413
14635
|
try {
|
|
@@ -14416,7 +14638,8 @@ class PluginManager {
|
|
|
14416
14638
|
}
|
|
14417
14639
|
}
|
|
14418
14640
|
}
|
|
14419
|
-
runOnPhase(
|
|
14641
|
+
runOnPhase(rawCtx, phase) {
|
|
14642
|
+
const ctx = this.withHost(rawCtx);
|
|
14420
14643
|
for (const plugin of this.plugins) {
|
|
14421
14644
|
if (plugin.onPhase) {
|
|
14422
14645
|
try {
|
|
@@ -14425,7 +14648,8 @@ class PluginManager {
|
|
|
14425
14648
|
}
|
|
14426
14649
|
}
|
|
14427
14650
|
}
|
|
14428
|
-
runOnToolStart(
|
|
14651
|
+
runOnToolStart(rawCtx, call) {
|
|
14652
|
+
const ctx = this.withHost(rawCtx);
|
|
14429
14653
|
for (const plugin of this.plugins) {
|
|
14430
14654
|
if (plugin.onToolStart) {
|
|
14431
14655
|
try {
|
|
@@ -14434,7 +14658,8 @@ class PluginManager {
|
|
|
14434
14658
|
}
|
|
14435
14659
|
}
|
|
14436
14660
|
}
|
|
14437
|
-
runOnToolEnd(
|
|
14661
|
+
runOnToolEnd(rawCtx, call, result, durationMs) {
|
|
14662
|
+
const ctx = this.withHost(rawCtx);
|
|
14438
14663
|
for (const plugin of this.plugins) {
|
|
14439
14664
|
if (plugin.onToolEnd) {
|
|
14440
14665
|
try {
|
|
@@ -14443,7 +14668,8 @@ class PluginManager {
|
|
|
14443
14668
|
}
|
|
14444
14669
|
}
|
|
14445
14670
|
}
|
|
14446
|
-
runOnText(
|
|
14671
|
+
runOnText(rawCtx, chunk) {
|
|
14672
|
+
const ctx = this.withHost(rawCtx);
|
|
14447
14673
|
for (const plugin of this.plugins) {
|
|
14448
14674
|
if (plugin.onText) {
|
|
14449
14675
|
try {
|
|
@@ -14455,7 +14681,8 @@ class PluginManager {
|
|
|
14455
14681
|
}
|
|
14456
14682
|
return chunk;
|
|
14457
14683
|
}
|
|
14458
|
-
runOnMeta(
|
|
14684
|
+
runOnMeta(rawCtx, chunk) {
|
|
14685
|
+
const ctx = this.withHost(rawCtx);
|
|
14459
14686
|
for (const plugin of this.plugins) {
|
|
14460
14687
|
if (plugin.onMeta) {
|
|
14461
14688
|
try {
|
|
@@ -14467,6 +14694,16 @@ class PluginManager {
|
|
|
14467
14694
|
}
|
|
14468
14695
|
return chunk;
|
|
14469
14696
|
}
|
|
14697
|
+
runOnTurnEnd(rawCtx, summary) {
|
|
14698
|
+
const ctx = this.withHost(rawCtx);
|
|
14699
|
+
for (const plugin of this.plugins) {
|
|
14700
|
+
if (plugin.onTurnEnd) {
|
|
14701
|
+
try {
|
|
14702
|
+
plugin.onTurnEnd(ctx, summary);
|
|
14703
|
+
} catch {}
|
|
14704
|
+
}
|
|
14705
|
+
}
|
|
14706
|
+
}
|
|
14470
14707
|
}
|
|
14471
14708
|
var init_manager3 = __esm(() => {
|
|
14472
14709
|
init_checker();
|
|
@@ -14786,7 +15023,7 @@ ${joined}` }
|
|
|
14786
15023
|
var DEFAULT_CHUNK_SYSTEM_PROMPT = 'Answer the query using ONLY the provided text. Be concise. If the text does not contain the answer, say "NO_EVIDENCE".', DEFAULT_SYNTHESIS_SYSTEM_PROMPT = "You are given a query and per-chunk answers over a large text. Produce the final answer to the query, combining evidence from the chunks. If no chunk had evidence, say so.";
|
|
14787
15024
|
|
|
14788
15025
|
// src/tools/chunk-query.ts
|
|
14789
|
-
import { readFileSync as
|
|
15026
|
+
import { readFileSync as readFileSync13 } from "node:fs";
|
|
14790
15027
|
import { resolve as resolve16 } from "node:path";
|
|
14791
15028
|
var chunkQueryTool;
|
|
14792
15029
|
var init_chunk_query = __esm(() => {
|
|
@@ -14856,7 +15093,7 @@ var init_chunk_query = __esm(() => {
|
|
|
14856
15093
|
return { success: false, output: `[SCOPE] ${check.reason || "Path not allowed"}` };
|
|
14857
15094
|
}
|
|
14858
15095
|
try {
|
|
14859
|
-
content =
|
|
15096
|
+
content = readFileSync13(resolve16(ctx.baseDir, inputPath), "utf8");
|
|
14860
15097
|
} catch (e) {
|
|
14861
15098
|
return { success: false, output: `Cannot read ${inputPath}: ${e.message}` };
|
|
14862
15099
|
}
|
|
@@ -15256,7 +15493,7 @@ var init_web_browse = __esm(() => {
|
|
|
15256
15493
|
});
|
|
15257
15494
|
|
|
15258
15495
|
// src/tools/download-file.ts
|
|
15259
|
-
import { writeFileSync as
|
|
15496
|
+
import { writeFileSync as writeFileSync9, mkdirSync as mkdirSync13 } from "fs";
|
|
15260
15497
|
import { dirname as dirname9 } from "path";
|
|
15261
15498
|
var MAX_DOWNLOAD_BYTES, downloadFileTool;
|
|
15262
15499
|
var init_download_file = __esm(() => {
|
|
@@ -15345,8 +15582,8 @@ var init_download_file = __esm(() => {
|
|
|
15345
15582
|
output: t("tool.download_too_large", { max: String(maxBytes) })
|
|
15346
15583
|
};
|
|
15347
15584
|
}
|
|
15348
|
-
|
|
15349
|
-
|
|
15585
|
+
mkdirSync13(dirname9(resolved), { recursive: true });
|
|
15586
|
+
writeFileSync9(resolved, buffer);
|
|
15350
15587
|
const contentType = response.headers.get("content-type")?.split(";")[0]?.trim() || "unknown";
|
|
15351
15588
|
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), true, `Status: ${response.status}`);
|
|
15352
15589
|
logFileWrite(ctx.sessionId, resolved, true, `Downloaded ${buffer.byteLength} bytes`);
|
|
@@ -16185,8 +16422,8 @@ ${JSON.stringify(result, null, 2)}`
|
|
|
16185
16422
|
|
|
16186
16423
|
// src/tools/search-history.ts
|
|
16187
16424
|
import * as fs from "fs";
|
|
16188
|
-
import { join as
|
|
16189
|
-
import { homedir as
|
|
16425
|
+
import { join as join18 } from "path";
|
|
16426
|
+
import { homedir as homedir6 } from "os";
|
|
16190
16427
|
function searchFile(filePath, query, maxResults, results) {
|
|
16191
16428
|
if (!fs.existsSync(filePath))
|
|
16192
16429
|
return;
|
|
@@ -16230,7 +16467,7 @@ var init_search_history = __esm(() => {
|
|
|
16230
16467
|
const query = String(args.query || "").toLowerCase();
|
|
16231
16468
|
const maxResults = Number(args.maxResults) || 5;
|
|
16232
16469
|
const sessionId = args.sessionId ? String(args.sessionId) : null;
|
|
16233
|
-
const sessionDir =
|
|
16470
|
+
const sessionDir = join18(homedir6(), ".mma", "sessions");
|
|
16234
16471
|
const results = [];
|
|
16235
16472
|
try {
|
|
16236
16473
|
if (!fs.existsSync(sessionDir)) {
|
|
@@ -16245,7 +16482,7 @@ var init_search_history = __esm(() => {
|
|
|
16245
16482
|
continue;
|
|
16246
16483
|
if (sessionId && entry.name !== sessionId)
|
|
16247
16484
|
continue;
|
|
16248
|
-
const historyFile =
|
|
16485
|
+
const historyFile = join18(sessionDir, entry.name, "history.jsonl");
|
|
16249
16486
|
searchFile(historyFile, query, maxResults, results);
|
|
16250
16487
|
if (results.length >= maxResults)
|
|
16251
16488
|
break;
|
|
@@ -16272,8 +16509,8 @@ var init_search_history = __esm(() => {
|
|
|
16272
16509
|
});
|
|
16273
16510
|
|
|
16274
16511
|
// src/modules/memory/search.ts
|
|
16275
|
-
import { readFileSync as
|
|
16276
|
-
import { join as
|
|
16512
|
+
import { readFileSync as readFileSync15, existsSync as existsSync28 } from "fs";
|
|
16513
|
+
import { join as join19 } from "path";
|
|
16277
16514
|
|
|
16278
16515
|
class MemorySearch {
|
|
16279
16516
|
memoryDir;
|
|
@@ -16284,10 +16521,10 @@ class MemorySearch {
|
|
|
16284
16521
|
const results = [];
|
|
16285
16522
|
const lowerQuery = query.toLowerCase();
|
|
16286
16523
|
for (const name of MEMORY_FILES) {
|
|
16287
|
-
const path =
|
|
16288
|
-
if (!
|
|
16524
|
+
const path = join19(this.memoryDir, `${name}.md`);
|
|
16525
|
+
if (!existsSync28(path))
|
|
16289
16526
|
continue;
|
|
16290
|
-
const content =
|
|
16527
|
+
const content = readFileSync15(path, "utf-8");
|
|
16291
16528
|
const lines = content.split(`
|
|
16292
16529
|
`);
|
|
16293
16530
|
for (const line of lines) {
|
|
@@ -16296,10 +16533,10 @@ class MemorySearch {
|
|
|
16296
16533
|
}
|
|
16297
16534
|
}
|
|
16298
16535
|
}
|
|
16299
|
-
const prefsPath =
|
|
16300
|
-
if (
|
|
16536
|
+
const prefsPath = join19(this.memoryDir, "preferences.json");
|
|
16537
|
+
if (existsSync28(prefsPath)) {
|
|
16301
16538
|
try {
|
|
16302
|
-
const prefs = JSON.parse(
|
|
16539
|
+
const prefs = JSON.parse(readFileSync15(prefsPath, "utf-8"));
|
|
16303
16540
|
for (const [key, value] of Object.entries(prefs)) {
|
|
16304
16541
|
const searchStr = `${key}=${value}`;
|
|
16305
16542
|
if (searchStr.toLowerCase().includes(lowerQuery)) {
|
|
@@ -16317,8 +16554,8 @@ var init_search = __esm(() => {
|
|
|
16317
16554
|
});
|
|
16318
16555
|
|
|
16319
16556
|
// src/modules/memory/store.ts
|
|
16320
|
-
import { readFileSync as
|
|
16321
|
-
import { join as
|
|
16557
|
+
import { readFileSync as readFileSync16, writeFileSync as writeFileSync10, appendFileSync as appendFileSync5, existsSync as existsSync29, mkdirSync as mkdirSync14 } from "fs";
|
|
16558
|
+
import { join as join20 } from "path";
|
|
16322
16559
|
|
|
16323
16560
|
class MemoryStore {
|
|
16324
16561
|
memoryDir;
|
|
@@ -16326,27 +16563,27 @@ class MemoryStore {
|
|
|
16326
16563
|
this.memoryDir = memoryDir;
|
|
16327
16564
|
this.ensureDir();
|
|
16328
16565
|
for (const name of MEMORY_FILES2) {
|
|
16329
|
-
const path =
|
|
16330
|
-
if (!
|
|
16331
|
-
|
|
16566
|
+
const path = join20(this.memoryDir, `${name}.md`);
|
|
16567
|
+
if (!existsSync29(path)) {
|
|
16568
|
+
writeFileSync10(path, `# ${name.charAt(0).toUpperCase() + name.slice(1)}
|
|
16332
16569
|
|
|
16333
16570
|
`, "utf-8");
|
|
16334
16571
|
}
|
|
16335
16572
|
}
|
|
16336
16573
|
}
|
|
16337
16574
|
ensureDir() {
|
|
16338
|
-
if (!
|
|
16339
|
-
|
|
16575
|
+
if (!existsSync29(this.memoryDir)) {
|
|
16576
|
+
mkdirSync14(this.memoryDir, { recursive: true });
|
|
16340
16577
|
}
|
|
16341
16578
|
}
|
|
16342
16579
|
read(name) {
|
|
16343
|
-
const path =
|
|
16344
|
-
if (!
|
|
16580
|
+
const path = join20(this.memoryDir, `${name}.md`);
|
|
16581
|
+
if (!existsSync29(path))
|
|
16345
16582
|
return "";
|
|
16346
|
-
return
|
|
16583
|
+
return readFileSync16(path, "utf-8");
|
|
16347
16584
|
}
|
|
16348
16585
|
append(name, entry) {
|
|
16349
|
-
const path =
|
|
16586
|
+
const path = join20(this.memoryDir, `${name}.md`);
|
|
16350
16587
|
const timestamp = new Date().toISOString().replace("T", " ").slice(0, 19);
|
|
16351
16588
|
const formatted = `- **${timestamp}** — ${entry}
|
|
16352
16589
|
`;
|
|
@@ -16357,14 +16594,14 @@ class MemoryStore {
|
|
|
16357
16594
|
return searchModule.query(query);
|
|
16358
16595
|
}
|
|
16359
16596
|
prefsPath() {
|
|
16360
|
-
return
|
|
16597
|
+
return join20(this.memoryDir, "preferences.json");
|
|
16361
16598
|
}
|
|
16362
16599
|
getPreferences() {
|
|
16363
16600
|
const path = this.prefsPath();
|
|
16364
|
-
if (!
|
|
16601
|
+
if (!existsSync29(path))
|
|
16365
16602
|
return {};
|
|
16366
16603
|
try {
|
|
16367
|
-
return JSON.parse(
|
|
16604
|
+
return JSON.parse(readFileSync16(path, "utf-8"));
|
|
16368
16605
|
} catch {
|
|
16369
16606
|
return {};
|
|
16370
16607
|
}
|
|
@@ -16372,14 +16609,14 @@ class MemoryStore {
|
|
|
16372
16609
|
setPreference(key, value) {
|
|
16373
16610
|
const prefs = this.getPreferences();
|
|
16374
16611
|
prefs[key] = value;
|
|
16375
|
-
|
|
16612
|
+
writeFileSync10(this.prefsPath(), JSON.stringify(prefs, null, 2), "utf-8");
|
|
16376
16613
|
}
|
|
16377
16614
|
deletePreference(key) {
|
|
16378
16615
|
const prefs = this.getPreferences();
|
|
16379
16616
|
if (!(key in prefs))
|
|
16380
16617
|
return false;
|
|
16381
16618
|
delete prefs[key];
|
|
16382
|
-
|
|
16619
|
+
writeFileSync10(this.prefsPath(), JSON.stringify(prefs, null, 2), "utf-8");
|
|
16383
16620
|
return true;
|
|
16384
16621
|
}
|
|
16385
16622
|
appendRule(category, pattern, cause, solution) {
|
|
@@ -16396,8 +16633,8 @@ var init_store2 = __esm(() => {
|
|
|
16396
16633
|
});
|
|
16397
16634
|
|
|
16398
16635
|
// src/tools/remember.ts
|
|
16399
|
-
import { homedir as
|
|
16400
|
-
import { join as
|
|
16636
|
+
import { homedir as homedir7 } from "os";
|
|
16637
|
+
import { join as join21 } from "path";
|
|
16401
16638
|
var CATEGORIES, rememberTool;
|
|
16402
16639
|
var init_remember = __esm(() => {
|
|
16403
16640
|
init_i18n();
|
|
@@ -16436,7 +16673,7 @@ var init_remember = __esm(() => {
|
|
|
16436
16673
|
if (!CATEGORIES.includes(category)) {
|
|
16437
16674
|
return { success: false, output: t("tool.invalid_params") };
|
|
16438
16675
|
}
|
|
16439
|
-
const memoryDir =
|
|
16676
|
+
const memoryDir = join21(homedir7(), ".mma", "memory");
|
|
16440
16677
|
const store = new MemoryStore(memoryDir);
|
|
16441
16678
|
try {
|
|
16442
16679
|
if (category === "preferences") {
|
|
@@ -16468,8 +16705,8 @@ var init_remember = __esm(() => {
|
|
|
16468
16705
|
});
|
|
16469
16706
|
|
|
16470
16707
|
// src/tools/recall.ts
|
|
16471
|
-
import { homedir as
|
|
16472
|
-
import { join as
|
|
16708
|
+
import { homedir as homedir8 } from "os";
|
|
16709
|
+
import { join as join22 } from "path";
|
|
16473
16710
|
function formatAll(store) {
|
|
16474
16711
|
const parts = [];
|
|
16475
16712
|
const prefs = store.getPreferences();
|
|
@@ -16553,7 +16790,7 @@ var init_recall = __esm(() => {
|
|
|
16553
16790
|
handler: async (_ctx, args) => {
|
|
16554
16791
|
const query = args.query ? String(args.query) : "";
|
|
16555
16792
|
const category = args.category ? String(args.category) : "";
|
|
16556
|
-
const memoryDir =
|
|
16793
|
+
const memoryDir = join22(homedir8(), ".mma", "memory");
|
|
16557
16794
|
const store = new MemoryStore(memoryDir);
|
|
16558
16795
|
try {
|
|
16559
16796
|
if (!query && !category) {
|
|
@@ -16591,9 +16828,9 @@ var init_recall = __esm(() => {
|
|
|
16591
16828
|
});
|
|
16592
16829
|
|
|
16593
16830
|
// src/modules/browser/bridge-path.ts
|
|
16594
|
-
import { existsSync as
|
|
16831
|
+
import { existsSync as existsSync30 } from "fs";
|
|
16595
16832
|
function pickExistingPath(candidates, fallback = candidates[0]) {
|
|
16596
|
-
return candidates.find((p) =>
|
|
16833
|
+
return candidates.find((p) => existsSync30(p)) ?? fallback;
|
|
16597
16834
|
}
|
|
16598
16835
|
var init_bridge_path = () => {};
|
|
16599
16836
|
|
|
@@ -16604,13 +16841,13 @@ __export(exports_bridge_client, {
|
|
|
16604
16841
|
});
|
|
16605
16842
|
import { spawn as spawn5 } from "child_process";
|
|
16606
16843
|
import { createInterface } from "readline";
|
|
16607
|
-
import { dirname as dirname10, join as
|
|
16844
|
+
import { dirname as dirname10, join as join23 } from "path";
|
|
16608
16845
|
import { fileURLToPath } from "url";
|
|
16609
16846
|
function bridgeScriptPath() {
|
|
16610
16847
|
const dir = dirname10(fileURLToPath(import.meta.url));
|
|
16611
16848
|
const candidates = [
|
|
16612
|
-
|
|
16613
|
-
|
|
16849
|
+
join23(dir, "bridge-server.mjs"),
|
|
16850
|
+
join23(dir, "modules", "browser", "bridge-server.mjs")
|
|
16614
16851
|
];
|
|
16615
16852
|
return pickExistingPath(candidates);
|
|
16616
16853
|
}
|
|
@@ -17164,15 +17401,15 @@ function buildTextExtractionScript() {
|
|
|
17164
17401
|
|
|
17165
17402
|
// src/modules/browser/cookie-store.ts
|
|
17166
17403
|
import { readFile, writeFile, mkdir } from "fs/promises";
|
|
17167
|
-
import { join as
|
|
17404
|
+
import { join as join24 } from "path";
|
|
17168
17405
|
|
|
17169
17406
|
class CookieStore {
|
|
17170
17407
|
filePath;
|
|
17171
17408
|
constructor(cookieDir) {
|
|
17172
|
-
this.filePath =
|
|
17409
|
+
this.filePath = join24(cookieDir, "cookies.json");
|
|
17173
17410
|
}
|
|
17174
17411
|
async save(cookies) {
|
|
17175
|
-
await mkdir(
|
|
17412
|
+
await mkdir(join24(this.filePath, ".."), { recursive: true });
|
|
17176
17413
|
await writeFile(this.filePath, JSON.stringify(cookies, null, 2), "utf-8");
|
|
17177
17414
|
}
|
|
17178
17415
|
async load() {
|
|
@@ -17530,10 +17767,10 @@ var init_session = __esm(() => {
|
|
|
17530
17767
|
});
|
|
17531
17768
|
|
|
17532
17769
|
// src/tools/browser.ts
|
|
17533
|
-
import { join as
|
|
17770
|
+
import { join as join25 } from "path";
|
|
17534
17771
|
function getSession(ctx) {
|
|
17535
17772
|
if (!session) {
|
|
17536
|
-
const cookieDir =
|
|
17773
|
+
const cookieDir = join25(ctx.baseDir, ".mma", "browser");
|
|
17537
17774
|
session = new BrowserSession({
|
|
17538
17775
|
...DEFAULT_BROWSER_CONFIG,
|
|
17539
17776
|
headless: ctx.config.browser?.headless ?? true,
|
|
@@ -17659,7 +17896,7 @@ __export(exports_image_utils, {
|
|
|
17659
17896
|
detectMime: () => detectMime,
|
|
17660
17897
|
bufferToDataUrl: () => bufferToDataUrl
|
|
17661
17898
|
});
|
|
17662
|
-
import { readFileSync as
|
|
17899
|
+
import { readFileSync as readFileSync17 } from "fs";
|
|
17663
17900
|
import { extname as extname3 } from "path";
|
|
17664
17901
|
function detectMime(filePath) {
|
|
17665
17902
|
const ext = extname3(filePath).toLowerCase();
|
|
@@ -17680,9 +17917,9 @@ async function readClipboardImage() {
|
|
|
17680
17917
|
async function readClipboardFallback() {
|
|
17681
17918
|
const { platform: platform5 } = await import("os");
|
|
17682
17919
|
const { execSync } = await import("child_process");
|
|
17683
|
-
const { readFileSync:
|
|
17684
|
-
const { join:
|
|
17685
|
-
const tmpPath =
|
|
17920
|
+
const { readFileSync: readFileSync18, unlinkSync: unlinkSync4 } = await import("fs");
|
|
17921
|
+
const { join: join26 } = await import("path");
|
|
17922
|
+
const tmpPath = join26(process.env.TEMP || process.env.TMP || "/tmp", `mma-clip-${Date.now()}.png`);
|
|
17686
17923
|
try {
|
|
17687
17924
|
if (platform5() === "linux") {
|
|
17688
17925
|
execSync(`xclip -selection clipboard -t image/png -o > "${tmpPath}" 2>/dev/null`, {
|
|
@@ -17691,7 +17928,7 @@ async function readClipboardFallback() {
|
|
|
17691
17928
|
} else {
|
|
17692
17929
|
return null;
|
|
17693
17930
|
}
|
|
17694
|
-
const buf =
|
|
17931
|
+
const buf = readFileSync18(tmpPath);
|
|
17695
17932
|
unlinkSync4(tmpPath);
|
|
17696
17933
|
return buf.length > 0 ? buf : null;
|
|
17697
17934
|
} catch {
|
|
@@ -17702,7 +17939,7 @@ async function readClipboardFallback() {
|
|
|
17702
17939
|
}
|
|
17703
17940
|
}
|
|
17704
17941
|
async function loadFileAsDataUrl(filePath) {
|
|
17705
|
-
const buf =
|
|
17942
|
+
const buf = readFileSync17(filePath);
|
|
17706
17943
|
if (typeof Bun !== "undefined" && typeof Bun.Image !== "undefined") {
|
|
17707
17944
|
try {
|
|
17708
17945
|
const img = new Bun.Image(buf);
|
|
@@ -17762,7 +17999,7 @@ var init_image_utils = __esm(() => {
|
|
|
17762
17999
|
});
|
|
17763
18000
|
|
|
17764
18001
|
// src/tools/attach-image.ts
|
|
17765
|
-
import { existsSync as
|
|
18002
|
+
import { existsSync as existsSync31 } from "fs";
|
|
17766
18003
|
import { resolve as resolve17 } from "path";
|
|
17767
18004
|
var attachImageTool;
|
|
17768
18005
|
var init_attach_image = __esm(() => {
|
|
@@ -17814,7 +18051,7 @@ var init_attach_image = __esm(() => {
|
|
|
17814
18051
|
dataUrl = result.dataUrl;
|
|
17815
18052
|
} else {
|
|
17816
18053
|
const absPath = resolve17(ctx.baseDir, source);
|
|
17817
|
-
if (!
|
|
18054
|
+
if (!existsSync31(absPath)) {
|
|
17818
18055
|
return {
|
|
17819
18056
|
success: false,
|
|
17820
18057
|
output: t("image.not_found", { path: source })
|
|
@@ -18072,16 +18309,16 @@ class ModuleRegistry {
|
|
|
18072
18309
|
}
|
|
18073
18310
|
|
|
18074
18311
|
// src/modules/plugins/loader.ts
|
|
18075
|
-
import { readdirSync as
|
|
18076
|
-
import { join as
|
|
18312
|
+
import { readdirSync as readdirSync10, existsSync as existsSync32, statSync as statSync6 } from "fs";
|
|
18313
|
+
import { join as join26, basename as basename3 } from "path";
|
|
18077
18314
|
|
|
18078
18315
|
class PluginLoader {
|
|
18079
18316
|
loadFromDir(dirPath, pluginManager, logger, options) {
|
|
18080
|
-
if (!
|
|
18317
|
+
if (!existsSync32(dirPath))
|
|
18081
18318
|
return;
|
|
18082
|
-
const entries =
|
|
18319
|
+
const entries = readdirSync10(dirPath).sort();
|
|
18083
18320
|
for (const entry of entries) {
|
|
18084
|
-
const fullPath =
|
|
18321
|
+
const fullPath = join26(dirPath, entry);
|
|
18085
18322
|
const stat = statSync6(fullPath);
|
|
18086
18323
|
if (stat.isFile()) {
|
|
18087
18324
|
if (!entry.endsWith(".ts") && !entry.endsWith(".js"))
|
|
@@ -18097,8 +18334,8 @@ class PluginLoader {
|
|
|
18097
18334
|
}
|
|
18098
18335
|
findEntryFile(dir) {
|
|
18099
18336
|
for (const name of FOLDER_ENTRY_NAMES) {
|
|
18100
|
-
const candidate =
|
|
18101
|
-
if (
|
|
18337
|
+
const candidate = join26(dir, name);
|
|
18338
|
+
if (existsSync32(candidate))
|
|
18102
18339
|
return candidate;
|
|
18103
18340
|
}
|
|
18104
18341
|
return null;
|
|
@@ -18140,8 +18377,8 @@ var init_loader = __esm(() => {
|
|
|
18140
18377
|
|
|
18141
18378
|
// src/modules/plugins/builtin/lint-on-write.ts
|
|
18142
18379
|
import { spawn as spawn6, execSync } from "child_process";
|
|
18143
|
-
import { existsSync as
|
|
18144
|
-
import { resolve as resolve18, extname as extname4, join as
|
|
18380
|
+
import { existsSync as existsSync33, readFileSync as readFileSync18 } from "fs";
|
|
18381
|
+
import { resolve as resolve18, extname as extname4, join as join27 } from "path";
|
|
18145
18382
|
import { platform as platform5 } from "os";
|
|
18146
18383
|
function lintCacheKey(baseDir, lintScript) {
|
|
18147
18384
|
return `${baseDir}::${lintScript}`;
|
|
@@ -18217,7 +18454,7 @@ class LintOnWritePlugin {
|
|
|
18217
18454
|
if (!path)
|
|
18218
18455
|
return;
|
|
18219
18456
|
const fullPath = resolve18(ctx.baseDir, path);
|
|
18220
|
-
if (!
|
|
18457
|
+
if (!existsSync33(fullPath))
|
|
18221
18458
|
return;
|
|
18222
18459
|
const signal = ctx.signal;
|
|
18223
18460
|
if (signal?.aborted)
|
|
@@ -18241,7 +18478,7 @@ class LintOnWritePlugin {
|
|
|
18241
18478
|
if (ext === ".ts" || ext === ".tsx" || ext === ".cts" || ext === ".mts") {
|
|
18242
18479
|
let content = "";
|
|
18243
18480
|
try {
|
|
18244
|
-
content =
|
|
18481
|
+
content = readFileSync18(filePath, "utf-8");
|
|
18245
18482
|
} catch {
|
|
18246
18483
|
return null;
|
|
18247
18484
|
}
|
|
@@ -18283,11 +18520,11 @@ class LintOnWritePlugin {
|
|
|
18283
18520
|
async runProjectLint(ctx, result, signal) {
|
|
18284
18521
|
let lintScript;
|
|
18285
18522
|
try {
|
|
18286
|
-
const packageJsonPath =
|
|
18287
|
-
if (!
|
|
18523
|
+
const packageJsonPath = join27(ctx.baseDir, "package.json");
|
|
18524
|
+
if (!existsSync33(packageJsonPath)) {
|
|
18288
18525
|
return;
|
|
18289
18526
|
}
|
|
18290
|
-
const packageJson = JSON.parse(
|
|
18527
|
+
const packageJson = JSON.parse(readFileSync18(packageJsonPath, "utf-8"));
|
|
18291
18528
|
lintScript = packageJson.scripts?.lint;
|
|
18292
18529
|
if (!lintScript) {
|
|
18293
18530
|
return;
|
|
@@ -18320,8 +18557,8 @@ ${stdout}`;
|
|
|
18320
18557
|
}
|
|
18321
18558
|
async runProjectTypeCheck(filePath, baseDir, result, signal) {
|
|
18322
18559
|
const projectRoot = findProjectRoot(filePath, baseDir, ["tsconfig.json", "package.json"]);
|
|
18323
|
-
const tsconfigPath =
|
|
18324
|
-
if (!
|
|
18560
|
+
const tsconfigPath = join27(projectRoot, "tsconfig.json");
|
|
18561
|
+
if (!existsSync33(tsconfigPath)) {
|
|
18325
18562
|
return;
|
|
18326
18563
|
}
|
|
18327
18564
|
const now = Date.now();
|
|
@@ -18577,11 +18814,11 @@ class PlanTracker {
|
|
|
18577
18814
|
var init_tracker = () => {};
|
|
18578
18815
|
|
|
18579
18816
|
// src/modules/execution/plan-store.ts
|
|
18580
|
-
import { readFileSync as
|
|
18581
|
-
import { join as
|
|
18817
|
+
import { readFileSync as readFileSync19, writeFileSync as writeFileSync11, mkdirSync as mkdirSync15, existsSync as existsSync34, readdirSync as readdirSync11, rmSync } from "fs";
|
|
18818
|
+
import { join as join28 } from "path";
|
|
18582
18819
|
function readPlanFile(path, fallbackBaseDir) {
|
|
18583
18820
|
try {
|
|
18584
|
-
const raw =
|
|
18821
|
+
const raw = readFileSync19(path, "utf-8");
|
|
18585
18822
|
if (!raw.trim())
|
|
18586
18823
|
return null;
|
|
18587
18824
|
const parsed = JSON.parse(raw);
|
|
@@ -18600,13 +18837,13 @@ function readPlanFile(path, fallbackBaseDir) {
|
|
|
18600
18837
|
}
|
|
18601
18838
|
}
|
|
18602
18839
|
function writePlanFile(path, plan) {
|
|
18603
|
-
|
|
18840
|
+
writeFileSync11(path, JSON.stringify(plan, null, 2), "utf-8");
|
|
18604
18841
|
}
|
|
18605
18842
|
function listDir(dir, baseDir) {
|
|
18606
|
-
if (!
|
|
18843
|
+
if (!existsSync34(dir))
|
|
18607
18844
|
return [];
|
|
18608
|
-
const files =
|
|
18609
|
-
return files.map((f) => readPlanFile(
|
|
18845
|
+
const files = readdirSync11(dir).filter((f) => f.endsWith(".json"));
|
|
18846
|
+
return files.map((f) => readPlanFile(join28(dir, f), baseDir)).filter((p) => p !== null);
|
|
18610
18847
|
}
|
|
18611
18848
|
function toMeta(plan, status) {
|
|
18612
18849
|
return {
|
|
@@ -18627,33 +18864,33 @@ class PlanStore {
|
|
|
18627
18864
|
archiveDir;
|
|
18628
18865
|
legacyPath;
|
|
18629
18866
|
constructor(baseDir) {
|
|
18630
|
-
const mmaDir =
|
|
18631
|
-
if (!
|
|
18632
|
-
|
|
18867
|
+
const mmaDir = join28(baseDir, ".mma");
|
|
18868
|
+
if (!existsSync34(mmaDir))
|
|
18869
|
+
mkdirSync15(mmaDir, { recursive: true });
|
|
18633
18870
|
this.baseDir = baseDir;
|
|
18634
|
-
this.plansDir =
|
|
18635
|
-
this.draftsDir =
|
|
18636
|
-
this.archiveDir =
|
|
18637
|
-
this.legacyPath =
|
|
18871
|
+
this.plansDir = join28(mmaDir, "plans");
|
|
18872
|
+
this.draftsDir = join28(this.plansDir, "drafts");
|
|
18873
|
+
this.archiveDir = join28(this.plansDir, "archive");
|
|
18874
|
+
this.legacyPath = join28(mmaDir, LEGACY_FILE);
|
|
18638
18875
|
for (const dir of [this.plansDir, this.draftsDir, this.archiveDir]) {
|
|
18639
|
-
if (!
|
|
18640
|
-
|
|
18876
|
+
if (!existsSync34(dir))
|
|
18877
|
+
mkdirSync15(dir, { recursive: true });
|
|
18641
18878
|
}
|
|
18642
18879
|
}
|
|
18643
18880
|
activePath() {
|
|
18644
|
-
return
|
|
18881
|
+
return join28(this.plansDir, "active.json");
|
|
18645
18882
|
}
|
|
18646
18883
|
saveActive(plan) {
|
|
18647
18884
|
writePlanFile(this.activePath(), plan);
|
|
18648
18885
|
}
|
|
18649
18886
|
loadActive() {
|
|
18650
18887
|
const activePath = this.activePath();
|
|
18651
|
-
if (
|
|
18888
|
+
if (existsSync34(activePath)) {
|
|
18652
18889
|
const plan = readPlanFile(activePath, this.baseDir);
|
|
18653
18890
|
if (plan)
|
|
18654
18891
|
return plan;
|
|
18655
18892
|
}
|
|
18656
|
-
if (
|
|
18893
|
+
if (existsSync34(this.legacyPath)) {
|
|
18657
18894
|
const legacy = readPlanFile(this.legacyPath, this.baseDir);
|
|
18658
18895
|
if (legacy) {
|
|
18659
18896
|
this.saveActive(legacy);
|
|
@@ -18667,26 +18904,26 @@ class PlanStore {
|
|
|
18667
18904
|
}
|
|
18668
18905
|
clearActive() {
|
|
18669
18906
|
const p = this.activePath();
|
|
18670
|
-
if (
|
|
18907
|
+
if (existsSync34(p))
|
|
18671
18908
|
rmSync(p, { force: true });
|
|
18672
18909
|
}
|
|
18673
18910
|
saveDraft(plan) {
|
|
18674
|
-
writePlanFile(
|
|
18911
|
+
writePlanFile(join28(this.draftsDir, `${plan.id}.json`), plan);
|
|
18675
18912
|
}
|
|
18676
18913
|
loadDraft(id) {
|
|
18677
|
-
const p =
|
|
18678
|
-
return
|
|
18914
|
+
const p = join28(this.draftsDir, `${id}.json`);
|
|
18915
|
+
return existsSync34(p) ? readPlanFile(p, this.baseDir) : null;
|
|
18679
18916
|
}
|
|
18680
18917
|
removeDraft(id) {
|
|
18681
|
-
const p =
|
|
18682
|
-
if (
|
|
18918
|
+
const p = join28(this.draftsDir, `${id}.json`);
|
|
18919
|
+
if (existsSync34(p))
|
|
18683
18920
|
rmSync(p, { force: true });
|
|
18684
18921
|
}
|
|
18685
18922
|
listDrafts() {
|
|
18686
18923
|
return listDir(this.draftsDir, this.baseDir);
|
|
18687
18924
|
}
|
|
18688
18925
|
archivePlan(plan) {
|
|
18689
|
-
writePlanFile(
|
|
18926
|
+
writePlanFile(join28(this.archiveDir, `${plan.id}.json`), plan);
|
|
18690
18927
|
this.removeDraft(plan.id);
|
|
18691
18928
|
const active = this.loadActive();
|
|
18692
18929
|
if (active && active.id === plan.id) {
|
|
@@ -18697,8 +18934,8 @@ class PlanStore {
|
|
|
18697
18934
|
return listDir(this.archiveDir, this.baseDir);
|
|
18698
18935
|
}
|
|
18699
18936
|
removeArchived(id) {
|
|
18700
|
-
const p =
|
|
18701
|
-
if (
|
|
18937
|
+
const p = join28(this.archiveDir, `${id}.json`);
|
|
18938
|
+
if (existsSync34(p))
|
|
18702
18939
|
rmSync(p, { force: true });
|
|
18703
18940
|
}
|
|
18704
18941
|
listAll() {
|
|
@@ -18730,13 +18967,13 @@ class PlanStore {
|
|
|
18730
18967
|
this.clearActive();
|
|
18731
18968
|
return "active";
|
|
18732
18969
|
}
|
|
18733
|
-
const draftPath =
|
|
18734
|
-
if (
|
|
18970
|
+
const draftPath = join28(this.draftsDir, `${id}.json`);
|
|
18971
|
+
if (existsSync34(draftPath)) {
|
|
18735
18972
|
rmSync(draftPath, { force: true });
|
|
18736
18973
|
return "draft";
|
|
18737
18974
|
}
|
|
18738
|
-
const archivedPath =
|
|
18739
|
-
if (
|
|
18975
|
+
const archivedPath = join28(this.archiveDir, `${id}.json`);
|
|
18976
|
+
if (existsSync34(archivedPath)) {
|
|
18740
18977
|
rmSync(archivedPath, { force: true });
|
|
18741
18978
|
return "archived";
|
|
18742
18979
|
}
|
|
@@ -19772,7 +20009,7 @@ var init_plan_tool = __esm(() => {
|
|
|
19772
20009
|
});
|
|
19773
20010
|
|
|
19774
20011
|
// src/modules/execution/module.ts
|
|
19775
|
-
import { existsSync as
|
|
20012
|
+
import { existsSync as existsSync35, readFileSync as readFileSync20 } from "fs";
|
|
19776
20013
|
import { resolve as resolve19 } from "path";
|
|
19777
20014
|
|
|
19778
20015
|
class ExecutionModule {
|
|
@@ -20106,7 +20343,7 @@ class ExecutionModule {
|
|
|
20106
20343
|
"poetry.lock",
|
|
20107
20344
|
"requirements.txt"
|
|
20108
20345
|
];
|
|
20109
|
-
const hasLockFile = lockFiles.some((f) =>
|
|
20346
|
+
const hasLockFile = lockFiles.some((f) => existsSync35(resolve19(this.baseDir, f)));
|
|
20110
20347
|
if (!hasLockFile) {
|
|
20111
20348
|
if (contextManager) {
|
|
20112
20349
|
const hints = this.state.depsGateHints.get(step.id) || 0;
|
|
@@ -20138,7 +20375,7 @@ class ExecutionModule {
|
|
|
20138
20375
|
if (!r)
|
|
20139
20376
|
continue;
|
|
20140
20377
|
try {
|
|
20141
|
-
const content =
|
|
20378
|
+
const content = readFileSync20(r, "utf-8");
|
|
20142
20379
|
if (content.trim().length < 10) {
|
|
20143
20380
|
emptyFiles.push(r);
|
|
20144
20381
|
}
|
|
@@ -20246,9 +20483,9 @@ var init_module = __esm(() => {
|
|
|
20246
20483
|
});
|
|
20247
20484
|
|
|
20248
20485
|
// src/modules/security/session-encryption.ts
|
|
20249
|
-
import { readFileSync as
|
|
20250
|
-
import { join as
|
|
20251
|
-
import { homedir as
|
|
20486
|
+
import { readFileSync as readFileSync21, writeFileSync as writeFileSync12, existsSync as existsSync36, readdirSync as readdirSync12, unlinkSync as unlinkSync4 } from "fs";
|
|
20487
|
+
import { join as join29 } from "path";
|
|
20488
|
+
import { homedir as homedir9 } from "os";
|
|
20252
20489
|
|
|
20253
20490
|
class SessionFileEncryptor {
|
|
20254
20491
|
config;
|
|
@@ -20256,7 +20493,7 @@ class SessionFileEncryptor {
|
|
|
20256
20493
|
constructor(config) {
|
|
20257
20494
|
this.config = { ...DEFAULT_SESSION_ENCRYPTION, ...config };
|
|
20258
20495
|
this.encryptor = new ConfigEncryptor({
|
|
20259
|
-
keyPath: config?.keyPath ||
|
|
20496
|
+
keyPath: config?.keyPath || join29(homedir9(), ".mma", ".session-encryption-key")
|
|
20260
20497
|
});
|
|
20261
20498
|
}
|
|
20262
20499
|
isEnabled() {
|
|
@@ -20301,23 +20538,23 @@ class SessionFileEncryptor {
|
|
|
20301
20538
|
return lines.map((line) => this.decryptFileContent(line));
|
|
20302
20539
|
}
|
|
20303
20540
|
readSessionFile(filePath) {
|
|
20304
|
-
const content =
|
|
20541
|
+
const content = readFileSync21(filePath, "utf8");
|
|
20305
20542
|
return this.decryptFileContent(content);
|
|
20306
20543
|
}
|
|
20307
20544
|
writeSessionFile(filePath, content) {
|
|
20308
20545
|
const encrypted = this.encryptFileContent(content);
|
|
20309
|
-
|
|
20546
|
+
writeFileSync12(filePath, encrypted, "utf8");
|
|
20310
20547
|
}
|
|
20311
20548
|
readSessionJSON(filePath) {
|
|
20312
|
-
const content =
|
|
20549
|
+
const content = readFileSync21(filePath, "utf8");
|
|
20313
20550
|
return this.decryptJSON(content);
|
|
20314
20551
|
}
|
|
20315
20552
|
writeSessionJSON(filePath, obj) {
|
|
20316
20553
|
const content = this.encryptJSON(obj);
|
|
20317
|
-
|
|
20554
|
+
writeFileSync12(filePath, content, "utf8");
|
|
20318
20555
|
}
|
|
20319
20556
|
readSessionJSONL(filePath) {
|
|
20320
|
-
const content =
|
|
20557
|
+
const content = readFileSync21(filePath, "utf8");
|
|
20321
20558
|
const lines = content.split(`
|
|
20322
20559
|
`).filter((line) => line.trim());
|
|
20323
20560
|
const decryptedLines = this.decryptJSONL(lines);
|
|
@@ -20331,7 +20568,7 @@ class SessionFileEncryptor {
|
|
|
20331
20568
|
}
|
|
20332
20569
|
appendToSessionJSONL(filePath, obj) {
|
|
20333
20570
|
const encryptedLine = this.encryptFileContent(JSON.stringify(obj));
|
|
20334
|
-
|
|
20571
|
+
writeFileSync12(filePath, encryptedLine + `
|
|
20335
20572
|
`, {
|
|
20336
20573
|
flag: "a",
|
|
20337
20574
|
encoding: "utf8"
|
|
@@ -20340,14 +20577,14 @@ class SessionFileEncryptor {
|
|
|
20340
20577
|
encryptSessionDirectory(sessionDir) {
|
|
20341
20578
|
if (!this.config.enabled)
|
|
20342
20579
|
return;
|
|
20343
|
-
const files =
|
|
20580
|
+
const files = readdirSync12(sessionDir);
|
|
20344
20581
|
for (const file of files) {
|
|
20345
|
-
const filePath =
|
|
20346
|
-
if (
|
|
20582
|
+
const filePath = join29(sessionDir, file);
|
|
20583
|
+
if (existsSync36(filePath) && !file.endsWith(".enc")) {
|
|
20347
20584
|
try {
|
|
20348
|
-
const content =
|
|
20585
|
+
const content = readFileSync21(filePath, "utf8");
|
|
20349
20586
|
const encrypted = this.encryptFileContent(content);
|
|
20350
|
-
|
|
20587
|
+
writeFileSync12(filePath + ".enc", encrypted, "utf8");
|
|
20351
20588
|
unlinkSync4(filePath);
|
|
20352
20589
|
} catch {}
|
|
20353
20590
|
}
|
|
@@ -20356,15 +20593,15 @@ class SessionFileEncryptor {
|
|
|
20356
20593
|
decryptSessionDirectory(sessionDir) {
|
|
20357
20594
|
if (!this.config.enabled)
|
|
20358
20595
|
return;
|
|
20359
|
-
const files =
|
|
20596
|
+
const files = readdirSync12(sessionDir);
|
|
20360
20597
|
for (const file of files) {
|
|
20361
20598
|
if (file.endsWith(".enc")) {
|
|
20362
|
-
const encFilePath =
|
|
20599
|
+
const encFilePath = join29(sessionDir, file);
|
|
20363
20600
|
const decFilePath = encFilePath.slice(0, -4);
|
|
20364
20601
|
try {
|
|
20365
|
-
const content =
|
|
20602
|
+
const content = readFileSync21(encFilePath, "utf8");
|
|
20366
20603
|
const decrypted = this.decryptFileContent(content);
|
|
20367
|
-
|
|
20604
|
+
writeFileSync12(decFilePath, decrypted, "utf8");
|
|
20368
20605
|
unlinkSync4(encFilePath);
|
|
20369
20606
|
} catch {}
|
|
20370
20607
|
}
|
|
@@ -20384,15 +20621,15 @@ var init_session_encryption = __esm(() => {
|
|
|
20384
20621
|
|
|
20385
20622
|
// src/modules/session/store.ts
|
|
20386
20623
|
import {
|
|
20387
|
-
existsSync as
|
|
20388
|
-
mkdirSync as
|
|
20389
|
-
readdirSync as
|
|
20390
|
-
readFileSync as
|
|
20624
|
+
existsSync as existsSync37,
|
|
20625
|
+
mkdirSync as mkdirSync16,
|
|
20626
|
+
readdirSync as readdirSync13,
|
|
20627
|
+
readFileSync as readFileSync22,
|
|
20391
20628
|
rmSync as rmSync2,
|
|
20392
|
-
writeFileSync as
|
|
20629
|
+
writeFileSync as writeFileSync13,
|
|
20393
20630
|
appendFileSync as appendFileSync6
|
|
20394
20631
|
} from "fs";
|
|
20395
|
-
import { join as
|
|
20632
|
+
import { join as join30 } from "path";
|
|
20396
20633
|
import { gzipSync } from "zlib";
|
|
20397
20634
|
|
|
20398
20635
|
class SessionStore {
|
|
@@ -20406,7 +20643,7 @@ class SessionStore {
|
|
|
20406
20643
|
}
|
|
20407
20644
|
}
|
|
20408
20645
|
getSessionDir(id) {
|
|
20409
|
-
return
|
|
20646
|
+
return join30(this.baseDir, id);
|
|
20410
20647
|
}
|
|
20411
20648
|
updateEncryption(config) {
|
|
20412
20649
|
if (config?.enabled) {
|
|
@@ -20419,32 +20656,32 @@ class SessionStore {
|
|
|
20419
20656
|
return this.encryptor?.isEnabled() ?? false;
|
|
20420
20657
|
}
|
|
20421
20658
|
init() {
|
|
20422
|
-
|
|
20659
|
+
mkdirSync16(this.baseDir, { recursive: true, mode: 448 });
|
|
20423
20660
|
}
|
|
20424
20661
|
sessionDir(id) {
|
|
20425
|
-
return
|
|
20662
|
+
return join30(this.baseDir, id);
|
|
20426
20663
|
}
|
|
20427
20664
|
metaPath(id) {
|
|
20428
|
-
return
|
|
20665
|
+
return join30(this.sessionDir(id), "meta.json");
|
|
20429
20666
|
}
|
|
20430
20667
|
historyPath(id) {
|
|
20431
|
-
return
|
|
20668
|
+
return join30(this.sessionDir(id), "history.jsonl");
|
|
20432
20669
|
}
|
|
20433
20670
|
sessionLogPath(id) {
|
|
20434
|
-
return
|
|
20671
|
+
return join30(this.sessionDir(id), "session.jsonl");
|
|
20435
20672
|
}
|
|
20436
20673
|
sessionExists(id) {
|
|
20437
|
-
return
|
|
20674
|
+
return existsSync37(this.metaPath(id));
|
|
20438
20675
|
}
|
|
20439
20676
|
saveMeta(id, meta) {
|
|
20440
20677
|
this._metaCache.set(id, meta);
|
|
20441
20678
|
const dir = this.sessionDir(id);
|
|
20442
|
-
|
|
20679
|
+
mkdirSync16(dir, { recursive: true, mode: 448 });
|
|
20443
20680
|
const content = JSON.stringify(meta, null, 2);
|
|
20444
20681
|
if (this.encryptor) {
|
|
20445
|
-
|
|
20682
|
+
writeFileSync13(this.metaPath(id), this.encryptor.encryptFileContent(content), { encoding: "utf-8", mode: 384 });
|
|
20446
20683
|
} else {
|
|
20447
|
-
|
|
20684
|
+
writeFileSync13(this.metaPath(id), content, { encoding: "utf-8", mode: 384 });
|
|
20448
20685
|
}
|
|
20449
20686
|
}
|
|
20450
20687
|
loadMeta(id) {
|
|
@@ -20452,10 +20689,10 @@ class SessionStore {
|
|
|
20452
20689
|
if (cached)
|
|
20453
20690
|
return cached;
|
|
20454
20691
|
const path = this.metaPath(id);
|
|
20455
|
-
if (!
|
|
20692
|
+
if (!existsSync37(path))
|
|
20456
20693
|
return null;
|
|
20457
20694
|
try {
|
|
20458
|
-
const raw =
|
|
20695
|
+
const raw = readFileSync22(path, "utf-8");
|
|
20459
20696
|
const content = this.encryptor ? this.encryptor.decryptFileContent(raw) : raw;
|
|
20460
20697
|
const meta = JSON.parse(content);
|
|
20461
20698
|
this._metaCache.set(id, meta);
|
|
@@ -20466,7 +20703,7 @@ class SessionStore {
|
|
|
20466
20703
|
}
|
|
20467
20704
|
appendMessage(id, msg) {
|
|
20468
20705
|
const dir = this.sessionDir(id);
|
|
20469
|
-
|
|
20706
|
+
mkdirSync16(dir, { recursive: true, mode: 448 });
|
|
20470
20707
|
const line = JSON.stringify(msg);
|
|
20471
20708
|
if (this.encryptor?.isEnabled()) {
|
|
20472
20709
|
appendFileSync6(this.historyPath(id), this.encryptor.encryptFileContent(line) + `
|
|
@@ -20484,10 +20721,10 @@ class SessionStore {
|
|
|
20484
20721
|
}
|
|
20485
20722
|
loadHistory(id) {
|
|
20486
20723
|
const path = this.historyPath(id);
|
|
20487
|
-
if (!
|
|
20724
|
+
if (!existsSync37(path))
|
|
20488
20725
|
return [];
|
|
20489
20726
|
try {
|
|
20490
|
-
const raw =
|
|
20727
|
+
const raw = readFileSync22(path, "utf-8");
|
|
20491
20728
|
const lines = raw.split(`
|
|
20492
20729
|
`).filter(Boolean);
|
|
20493
20730
|
const parseLine = (line) => {
|
|
@@ -20513,7 +20750,7 @@ class SessionStore {
|
|
|
20513
20750
|
}
|
|
20514
20751
|
appendSessionLog(id, entry) {
|
|
20515
20752
|
const dir = this.sessionDir(id);
|
|
20516
|
-
|
|
20753
|
+
mkdirSync16(dir, { recursive: true, mode: 448 });
|
|
20517
20754
|
const line = JSON.stringify(entry);
|
|
20518
20755
|
if (this.encryptor?.isEnabled()) {
|
|
20519
20756
|
appendFileSync6(this.sessionLogPath(id), this.encryptor.encryptFileContent(line) + `
|
|
@@ -20525,10 +20762,10 @@ class SessionStore {
|
|
|
20525
20762
|
}
|
|
20526
20763
|
loadSessionLog(id) {
|
|
20527
20764
|
const path = this.sessionLogPath(id);
|
|
20528
|
-
if (!
|
|
20765
|
+
if (!existsSync37(path))
|
|
20529
20766
|
return [];
|
|
20530
20767
|
try {
|
|
20531
|
-
const raw =
|
|
20768
|
+
const raw = readFileSync22(path, "utf-8");
|
|
20532
20769
|
const lines = raw.split(`
|
|
20533
20770
|
`).filter(Boolean);
|
|
20534
20771
|
const parseLine = (line) => {
|
|
@@ -20553,9 +20790,9 @@ class SessionStore {
|
|
|
20553
20790
|
}
|
|
20554
20791
|
}
|
|
20555
20792
|
listSessions() {
|
|
20556
|
-
if (!
|
|
20793
|
+
if (!existsSync37(this.baseDir))
|
|
20557
20794
|
return [];
|
|
20558
|
-
const entries =
|
|
20795
|
+
const entries = readdirSync13(this.baseDir, { withFileTypes: true });
|
|
20559
20796
|
const sessions = [];
|
|
20560
20797
|
for (const entry of entries) {
|
|
20561
20798
|
if (entry.isDirectory()) {
|
|
@@ -20570,7 +20807,7 @@ class SessionStore {
|
|
|
20570
20807
|
deleteSession(id) {
|
|
20571
20808
|
this._metaCache.delete(id);
|
|
20572
20809
|
const dir = this.sessionDir(id);
|
|
20573
|
-
if (
|
|
20810
|
+
if (existsSync37(dir)) {
|
|
20574
20811
|
rmSync2(dir, { recursive: true, force: true });
|
|
20575
20812
|
}
|
|
20576
20813
|
}
|
|
@@ -20582,11 +20819,11 @@ class SessionStore {
|
|
|
20582
20819
|
const updatedAt = new Date(session2.updatedAt);
|
|
20583
20820
|
if (updatedAt < thirtyDaysAgo) {
|
|
20584
20821
|
const historyPath = this.historyPath(session2.id);
|
|
20585
|
-
if (
|
|
20586
|
-
const content =
|
|
20822
|
+
if (existsSync37(historyPath)) {
|
|
20823
|
+
const content = readFileSync22(historyPath, "utf-8");
|
|
20587
20824
|
const compressed = gzipSync(content);
|
|
20588
|
-
const gzPath =
|
|
20589
|
-
|
|
20825
|
+
const gzPath = join30(this.baseDir, `${session2.id}.jsonl.gz`);
|
|
20826
|
+
writeFileSync13(gzPath, compressed);
|
|
20590
20827
|
rmSync2(historyPath);
|
|
20591
20828
|
}
|
|
20592
20829
|
}
|
|
@@ -20795,9 +21032,9 @@ class ProfileCompressor {
|
|
|
20795
21032
|
}
|
|
20796
21033
|
|
|
20797
21034
|
// src/modules/user-profile/profile.ts
|
|
20798
|
-
import { readFileSync as
|
|
20799
|
-
import { join as
|
|
20800
|
-
import { homedir as
|
|
21035
|
+
import { readFileSync as readFileSync23, writeFileSync as writeFileSync14, existsSync as existsSync38, mkdirSync as mkdirSync17 } from "fs";
|
|
21036
|
+
import { join as join31 } from "path";
|
|
21037
|
+
import { homedir as homedir10, hostname, platform as platform7, type } from "os";
|
|
20801
21038
|
import { env } from "process";
|
|
20802
21039
|
|
|
20803
21040
|
class UserProfile {
|
|
@@ -20813,24 +21050,24 @@ class UserProfile {
|
|
|
20813
21050
|
os: `${type()} ${hostname()}`,
|
|
20814
21051
|
hostname: hostname(),
|
|
20815
21052
|
shell: env.SHELL || env.ComSpec || "unknown",
|
|
20816
|
-
home:
|
|
21053
|
+
home: homedir10(),
|
|
20817
21054
|
nodeVersion: process.version,
|
|
20818
21055
|
preferences: { ...this.preferences }
|
|
20819
21056
|
};
|
|
20820
21057
|
return this.info;
|
|
20821
21058
|
}
|
|
20822
21059
|
save() {
|
|
20823
|
-
if (!
|
|
20824
|
-
|
|
21060
|
+
if (!existsSync38(this.profileDir)) {
|
|
21061
|
+
mkdirSync17(this.profileDir, { recursive: true });
|
|
20825
21062
|
}
|
|
20826
|
-
|
|
21063
|
+
writeFileSync14(join31(this.profileDir, "profile.json"), JSON.stringify({ ...this.info, preferences: this.preferences }, null, 2), "utf-8");
|
|
20827
21064
|
}
|
|
20828
21065
|
load() {
|
|
20829
|
-
const path =
|
|
20830
|
-
if (!
|
|
21066
|
+
const path = join31(this.profileDir, "profile.json");
|
|
21067
|
+
if (!existsSync38(path))
|
|
20831
21068
|
return null;
|
|
20832
21069
|
try {
|
|
20833
|
-
const data = JSON.parse(
|
|
21070
|
+
const data = JSON.parse(readFileSync23(path, "utf-8"));
|
|
20834
21071
|
this.info = {
|
|
20835
21072
|
platform: data.platform,
|
|
20836
21073
|
os: data.os,
|
|
@@ -20865,21 +21102,21 @@ class UserProfile {
|
|
|
20865
21102
|
var init_profile = () => {};
|
|
20866
21103
|
|
|
20867
21104
|
// src/modules/skills/loader.ts
|
|
20868
|
-
import { readdirSync as
|
|
20869
|
-
import { join as
|
|
21105
|
+
import { readdirSync as readdirSync14, readFileSync as readFileSync24, existsSync as existsSync39, statSync as statSync7 } from "fs";
|
|
21106
|
+
import { join as join32 } from "path";
|
|
20870
21107
|
|
|
20871
21108
|
class SkillsLoader {
|
|
20872
21109
|
loadFromDir(dirPath) {
|
|
20873
|
-
if (!
|
|
21110
|
+
if (!existsSync39(dirPath))
|
|
20874
21111
|
return [];
|
|
20875
21112
|
const skills = [];
|
|
20876
21113
|
this.scanDir(dirPath, skills);
|
|
20877
21114
|
return skills;
|
|
20878
21115
|
}
|
|
20879
21116
|
scanDir(dirPath, skills) {
|
|
20880
|
-
const entries =
|
|
21117
|
+
const entries = readdirSync14(dirPath);
|
|
20881
21118
|
for (const entry of entries) {
|
|
20882
|
-
const fullPath =
|
|
21119
|
+
const fullPath = join32(dirPath, entry);
|
|
20883
21120
|
const stat = statSync7(fullPath);
|
|
20884
21121
|
if (stat.isDirectory()) {
|
|
20885
21122
|
this.scanDir(fullPath, skills);
|
|
@@ -20887,7 +21124,7 @@ class SkillsLoader {
|
|
|
20887
21124
|
}
|
|
20888
21125
|
if (!entry.endsWith(".md") && !entry.endsWith(".skill.md"))
|
|
20889
21126
|
continue;
|
|
20890
|
-
const content =
|
|
21127
|
+
const content = readFileSync24(fullPath, "utf-8");
|
|
20891
21128
|
const parsed = this.parseSkillFile(content, fullPath);
|
|
20892
21129
|
if (parsed)
|
|
20893
21130
|
skills.push(parsed);
|
|
@@ -21524,7 +21761,7 @@ var init_check_tool = __esm(() => {
|
|
|
21524
21761
|
});
|
|
21525
21762
|
|
|
21526
21763
|
// src/modules/lsp/module.ts
|
|
21527
|
-
import { existsSync as
|
|
21764
|
+
import { existsSync as existsSync40 } from "fs";
|
|
21528
21765
|
import { relative as relative4, resolve as resolve22 } from "path";
|
|
21529
21766
|
|
|
21530
21767
|
class LspModule {
|
|
@@ -21579,7 +21816,7 @@ class LspModule {
|
|
|
21579
21816
|
if (!filePath)
|
|
21580
21817
|
return;
|
|
21581
21818
|
const fullPath = resolve22(_ctx.baseDir, filePath);
|
|
21582
|
-
if (!
|
|
21819
|
+
if (!existsSync40(fullPath))
|
|
21583
21820
|
return;
|
|
21584
21821
|
const serverConfig = getServerForFile(fullPath, self.config);
|
|
21585
21822
|
if (!serverConfig)
|
|
@@ -21671,7 +21908,7 @@ ${items}`;
|
|
|
21671
21908
|
})
|
|
21672
21909
|
};
|
|
21673
21910
|
}
|
|
21674
|
-
if (!
|
|
21911
|
+
if (!existsSync40(resolved)) {
|
|
21675
21912
|
return { success: false, output: t("lsp.check_notfound", { path }) };
|
|
21676
21913
|
}
|
|
21677
21914
|
const files = await collectCheckFiles(resolved, this.config);
|
|
@@ -21771,8 +22008,8 @@ var init_lsp = __esm(() => {
|
|
|
21771
22008
|
});
|
|
21772
22009
|
|
|
21773
22010
|
// src/modules/lsp/startup-check.ts
|
|
21774
|
-
import { existsSync as
|
|
21775
|
-
import { join as
|
|
22011
|
+
import { existsSync as existsSync41 } from "fs";
|
|
22012
|
+
import { join as join33 } from "path";
|
|
21776
22013
|
import { spawn as spawn8 } from "child_process";
|
|
21777
22014
|
async function runStartupHealthCheck(config, baseDir, deps = {}) {
|
|
21778
22015
|
if (!config.enabled)
|
|
@@ -21799,7 +22036,7 @@ ${result.lines.join(`
|
|
|
21799
22036
|
}
|
|
21800
22037
|
async function runCheck(config, baseDir, deps) {
|
|
21801
22038
|
const projectRoot = findProjectRoot(baseDir, baseDir, ["tsconfig.json", "package.json"]);
|
|
21802
|
-
if (
|
|
22039
|
+
if (existsSync41(join33(projectRoot, "tsconfig.json"))) {
|
|
21803
22040
|
const runTsc = deps.runTsc ?? runTscDefault;
|
|
21804
22041
|
const errors = await runTsc(projectRoot, STARTUP_CHECK_TIMEOUT_MS);
|
|
21805
22042
|
if (errors.length === 0)
|
|
@@ -21899,8 +22136,8 @@ var init_startup_check = __esm(() => {
|
|
|
21899
22136
|
});
|
|
21900
22137
|
|
|
21901
22138
|
// src/modules/indexer/walker.ts
|
|
21902
|
-
import { readdirSync as
|
|
21903
|
-
import { join as
|
|
22139
|
+
import { readdirSync as readdirSync15, readFileSync as readFileSync25, statSync as statSync8, existsSync as existsSync42, watch } from "fs";
|
|
22140
|
+
import { join as join34, relative as relative5, extname as extname5 } from "path";
|
|
21904
22141
|
|
|
21905
22142
|
class Indexer {
|
|
21906
22143
|
baseDir;
|
|
@@ -21927,18 +22164,18 @@ class Indexer {
|
|
|
21927
22164
|
let totalSize = 0;
|
|
21928
22165
|
let count = 0;
|
|
21929
22166
|
const walkDir2 = (dir) => {
|
|
21930
|
-
if (!
|
|
22167
|
+
if (!existsSync42(dir))
|
|
21931
22168
|
return;
|
|
21932
22169
|
let entries;
|
|
21933
22170
|
try {
|
|
21934
|
-
entries =
|
|
22171
|
+
entries = readdirSync15(dir);
|
|
21935
22172
|
} catch {
|
|
21936
22173
|
return;
|
|
21937
22174
|
}
|
|
21938
22175
|
for (const entry of entries) {
|
|
21939
22176
|
if (count >= this.MAX_FILES)
|
|
21940
22177
|
return;
|
|
21941
|
-
const fullPath =
|
|
22178
|
+
const fullPath = join34(dir, entry);
|
|
21942
22179
|
const relPath = relative5(this.baseDir, fullPath);
|
|
21943
22180
|
const stat2 = statSync8(fullPath);
|
|
21944
22181
|
if (stat2.isDirectory()) {
|
|
@@ -21949,7 +22186,7 @@ class Indexer {
|
|
|
21949
22186
|
const ext = extname5(entry).toLowerCase();
|
|
21950
22187
|
const language = LANGUAGES[ext];
|
|
21951
22188
|
if (language) {
|
|
21952
|
-
const content =
|
|
22189
|
+
const content = readFileSync25(fullPath, "utf-8");
|
|
21953
22190
|
const exports = this.extractExports(content, language);
|
|
21954
22191
|
files.push({ path: relPath, language, exports, size: stat2.size });
|
|
21955
22192
|
totalSize += stat2.size;
|
|
@@ -22001,22 +22238,22 @@ var init_walker = __esm(() => {
|
|
|
22001
22238
|
});
|
|
22002
22239
|
|
|
22003
22240
|
// src/modules/indexer/cache.ts
|
|
22004
|
-
import { readFileSync as
|
|
22005
|
-
import { join as
|
|
22241
|
+
import { readFileSync as readFileSync26, writeFileSync as writeFileSync15, existsSync as existsSync43, mkdirSync as mkdirSync18, rmSync as rmSync3 } from "fs";
|
|
22242
|
+
import { join as join35 } from "path";
|
|
22006
22243
|
|
|
22007
22244
|
class IndexCache {
|
|
22008
22245
|
cachePath;
|
|
22009
22246
|
cache = null;
|
|
22010
22247
|
constructor(cacheDir) {
|
|
22011
|
-
this.cachePath =
|
|
22248
|
+
this.cachePath = join35(cacheDir, "index-cache.json");
|
|
22012
22249
|
}
|
|
22013
22250
|
load() {
|
|
22014
22251
|
if (this.cache)
|
|
22015
22252
|
return this.cache;
|
|
22016
|
-
if (!
|
|
22253
|
+
if (!existsSync43(this.cachePath))
|
|
22017
22254
|
return null;
|
|
22018
22255
|
try {
|
|
22019
|
-
this.cache = JSON.parse(
|
|
22256
|
+
this.cache = JSON.parse(readFileSync26(this.cachePath, "utf-8"));
|
|
22020
22257
|
return this.cache;
|
|
22021
22258
|
} catch {
|
|
22022
22259
|
return null;
|
|
@@ -22024,14 +22261,14 @@ class IndexCache {
|
|
|
22024
22261
|
}
|
|
22025
22262
|
save(result) {
|
|
22026
22263
|
this.cache = result;
|
|
22027
|
-
const dir =
|
|
22028
|
-
if (!
|
|
22029
|
-
|
|
22030
|
-
|
|
22264
|
+
const dir = join35(this.cachePath, "..");
|
|
22265
|
+
if (!existsSync43(dir))
|
|
22266
|
+
mkdirSync18(dir, { recursive: true });
|
|
22267
|
+
writeFileSync15(this.cachePath, JSON.stringify(result), "utf-8");
|
|
22031
22268
|
}
|
|
22032
22269
|
invalidate() {
|
|
22033
22270
|
this.cache = null;
|
|
22034
|
-
if (
|
|
22271
|
+
if (existsSync43(this.cachePath)) {
|
|
22035
22272
|
try {
|
|
22036
22273
|
rmSync3(this.cachePath);
|
|
22037
22274
|
} catch {}
|
|
@@ -22041,11 +22278,11 @@ class IndexCache {
|
|
|
22041
22278
|
var init_cache = () => {};
|
|
22042
22279
|
|
|
22043
22280
|
// src/modules/indexer/project-profile.ts
|
|
22044
|
-
import { readFileSync as
|
|
22045
|
-
import { join as
|
|
22281
|
+
import { readFileSync as readFileSync27, existsSync as existsSync44 } from "fs";
|
|
22282
|
+
import { join as join36 } from "path";
|
|
22046
22283
|
function detectManifest(baseDir) {
|
|
22047
22284
|
for (const manifest of MANIFEST_ORDER) {
|
|
22048
|
-
if (
|
|
22285
|
+
if (existsSync44(join36(baseDir, manifest)))
|
|
22049
22286
|
return manifest;
|
|
22050
22287
|
}
|
|
22051
22288
|
return null;
|
|
@@ -22062,7 +22299,7 @@ function cleanDependency(entry) {
|
|
|
22062
22299
|
}
|
|
22063
22300
|
function readPackageJson(baseDir) {
|
|
22064
22301
|
try {
|
|
22065
|
-
const raw = JSON.parse(
|
|
22302
|
+
const raw = JSON.parse(readFileSync27(join36(baseDir, "package.json"), "utf-8"));
|
|
22066
22303
|
if (!raw || typeof raw !== "object")
|
|
22067
22304
|
return null;
|
|
22068
22305
|
const profile = {
|
|
@@ -22086,7 +22323,7 @@ function readPackageJson(baseDir) {
|
|
|
22086
22323
|
}
|
|
22087
22324
|
function readPyproject(baseDir) {
|
|
22088
22325
|
try {
|
|
22089
|
-
const content =
|
|
22326
|
+
const content = readFileSync27(join36(baseDir, "pyproject.toml"), "utf-8");
|
|
22090
22327
|
const profile = { runtime: "python", deps: [], devDeps: [], scripts: {} };
|
|
22091
22328
|
const nameMatch = content.match(/^\s*name\s*=\s*"([^"]+)"/m);
|
|
22092
22329
|
if (nameMatch)
|
|
@@ -22102,7 +22339,7 @@ function readPyproject(baseDir) {
|
|
|
22102
22339
|
}
|
|
22103
22340
|
function readCargo(baseDir) {
|
|
22104
22341
|
try {
|
|
22105
|
-
const content =
|
|
22342
|
+
const content = readFileSync27(join36(baseDir, "Cargo.toml"), "utf-8");
|
|
22106
22343
|
const profile = { runtime: "rust", deps: [], devDeps: [], scripts: {} };
|
|
22107
22344
|
const nameMatch = content.match(/^\s*name\s*=\s*"([^"]+)"/m);
|
|
22108
22345
|
if (nameMatch)
|
|
@@ -22126,7 +22363,7 @@ function readCargo(baseDir) {
|
|
|
22126
22363
|
}
|
|
22127
22364
|
function readGoMod(baseDir) {
|
|
22128
22365
|
try {
|
|
22129
|
-
const content =
|
|
22366
|
+
const content = readFileSync27(join36(baseDir, "go.mod"), "utf-8");
|
|
22130
22367
|
const profile = { runtime: "go", deps: [], devDeps: [], scripts: {} };
|
|
22131
22368
|
const moduleMatch = content.match(/^module\s+(\S+)/m);
|
|
22132
22369
|
if (moduleMatch)
|
|
@@ -22144,7 +22381,7 @@ function readGoMod(baseDir) {
|
|
|
22144
22381
|
}
|
|
22145
22382
|
function readRequirements(baseDir) {
|
|
22146
22383
|
try {
|
|
22147
|
-
const content =
|
|
22384
|
+
const content = readFileSync27(join36(baseDir, "requirements.txt"), "utf-8");
|
|
22148
22385
|
const profile = { runtime: "python", deps: [], devDeps: [], scripts: {} };
|
|
22149
22386
|
for (const line of content.split(`
|
|
22150
22387
|
`)) {
|
|
@@ -22602,8 +22839,8 @@ var init_mcp = __esm(() => {
|
|
|
22602
22839
|
});
|
|
22603
22840
|
|
|
22604
22841
|
// src/modules/memory/module.ts
|
|
22605
|
-
import { homedir as
|
|
22606
|
-
import { join as
|
|
22842
|
+
import { homedir as homedir11 } from "os";
|
|
22843
|
+
import { join as join37 } from "path";
|
|
22607
22844
|
|
|
22608
22845
|
class MemoryModule {
|
|
22609
22846
|
name = "memory";
|
|
@@ -22612,7 +22849,7 @@ class MemoryModule {
|
|
|
22612
22849
|
if (storeOrDir instanceof MemoryStore) {
|
|
22613
22850
|
this.store = storeOrDir;
|
|
22614
22851
|
} else {
|
|
22615
|
-
const dir = storeOrDir ||
|
|
22852
|
+
const dir = storeOrDir || join37(homedir11(), ".mma", "memory");
|
|
22616
22853
|
this.store = new MemoryStore(dir);
|
|
22617
22854
|
}
|
|
22618
22855
|
}
|
|
@@ -22698,16 +22935,16 @@ var init_module8 = __esm(() => {
|
|
|
22698
22935
|
});
|
|
22699
22936
|
|
|
22700
22937
|
// src/core/version.ts
|
|
22701
|
-
import { existsSync as
|
|
22702
|
-
import { join as
|
|
22938
|
+
import { existsSync as existsSync45, readFileSync as readFileSync28 } from "fs";
|
|
22939
|
+
import { join as join38, dirname as dirname13 } from "path";
|
|
22703
22940
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
22704
22941
|
function readMmaVersion() {
|
|
22705
22942
|
const here = dirname13(fileURLToPath2(import.meta.url));
|
|
22706
|
-
const candidates = [
|
|
22943
|
+
const candidates = [join38(here, "..", "..", "package.json"), join38(here, "..", "package.json")];
|
|
22707
22944
|
for (const p of candidates) {
|
|
22708
|
-
if (
|
|
22945
|
+
if (existsSync45(p)) {
|
|
22709
22946
|
try {
|
|
22710
|
-
const raw = JSON.parse(
|
|
22947
|
+
const raw = JSON.parse(readFileSync28(p, "utf8"));
|
|
22711
22948
|
if (raw.version)
|
|
22712
22949
|
return raw.version;
|
|
22713
22950
|
} catch {}
|
|
@@ -22718,21 +22955,21 @@ function readMmaVersion() {
|
|
|
22718
22955
|
var init_version = () => {};
|
|
22719
22956
|
|
|
22720
22957
|
// src/core/environment.ts
|
|
22721
|
-
import { existsSync as
|
|
22958
|
+
import { existsSync as existsSync46, readFileSync as readFileSync29, readdirSync as readdirSync16 } from "fs";
|
|
22722
22959
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
22723
22960
|
import { createRequire as createRequire2 } from "module";
|
|
22724
|
-
import { join as
|
|
22961
|
+
import { join as join39, dirname as dirname14 } from "path";
|
|
22725
22962
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
22726
|
-
import { arch, homedir as
|
|
22963
|
+
import { arch, homedir as homedir12, hostname as hostname2, platform as platform9, release } from "os";
|
|
22727
22964
|
import { env as env2 } from "process";
|
|
22728
22965
|
function readEngineRequirement() {
|
|
22729
22966
|
const here = dirname14(fileURLToPath3(import.meta.url));
|
|
22730
|
-
const candidates = [
|
|
22967
|
+
const candidates = [join39(here, "..", "..", "package.json"), join39(here, "..", "package.json")];
|
|
22731
22968
|
for (const p of candidates) {
|
|
22732
|
-
if (!
|
|
22969
|
+
if (!existsSync46(p))
|
|
22733
22970
|
continue;
|
|
22734
22971
|
try {
|
|
22735
|
-
const raw = JSON.parse(
|
|
22972
|
+
const raw = JSON.parse(readFileSync29(p, "utf8"));
|
|
22736
22973
|
if (raw.engines?.node)
|
|
22737
22974
|
return String(raw.engines.node);
|
|
22738
22975
|
} catch {}
|
|
@@ -22795,7 +23032,7 @@ function toolVersion(cmd) {
|
|
|
22795
23032
|
function playwrightBrowsersDir() {
|
|
22796
23033
|
if (process.env.PLAYWRIGHT_BROWSERS_PATH)
|
|
22797
23034
|
return process.env.PLAYWRIGHT_BROWSERS_PATH;
|
|
22798
|
-
return process.platform === "win32" ?
|
|
23035
|
+
return process.platform === "win32" ? join39(homedir12(), "AppData", "Local", "ms-playwright") : join39(homedir12(), ".cache", "ms-playwright");
|
|
22799
23036
|
}
|
|
22800
23037
|
function playwrightInfo() {
|
|
22801
23038
|
let installed = false;
|
|
@@ -22804,15 +23041,15 @@ function playwrightInfo() {
|
|
|
22804
23041
|
try {
|
|
22805
23042
|
const require2 = createRequire2(import.meta.url);
|
|
22806
23043
|
const pkgPath = require2.resolve("playwright/package.json");
|
|
22807
|
-
installed =
|
|
22808
|
-
version = JSON.parse(
|
|
23044
|
+
installed = existsSync46(pkgPath);
|
|
23045
|
+
version = JSON.parse(readFileSync29(pkgPath, "utf8")).version || "";
|
|
22809
23046
|
} catch {
|
|
22810
23047
|
installed = false;
|
|
22811
23048
|
}
|
|
22812
23049
|
let browsersInstalled = false;
|
|
22813
23050
|
try {
|
|
22814
|
-
if (
|
|
22815
|
-
browsersInstalled =
|
|
23051
|
+
if (existsSync46(browsersDir)) {
|
|
23052
|
+
browsersInstalled = readdirSync16(browsersDir).some((d) => /chrom/i.test(d));
|
|
22816
23053
|
}
|
|
22817
23054
|
} catch {
|
|
22818
23055
|
browsersInstalled = false;
|
|
@@ -22874,7 +23111,7 @@ function collectEnvironment(opts) {
|
|
|
22874
23111
|
release: release(),
|
|
22875
23112
|
hostname: hostname2(),
|
|
22876
23113
|
shell: env2.SHELL || env2.ComSpec || "unknown",
|
|
22877
|
-
home:
|
|
23114
|
+
home: homedir12(),
|
|
22878
23115
|
cwd: process.cwd()
|
|
22879
23116
|
},
|
|
22880
23117
|
paths: { configDir: opts.configDir, baseDir: opts.baseDir || process.cwd() },
|
|
@@ -22905,9 +23142,9 @@ __export(exports_bootstrap, {
|
|
|
22905
23142
|
buildSystemInfo: () => buildSystemInfo,
|
|
22906
23143
|
bootstrap: () => bootstrap
|
|
22907
23144
|
});
|
|
22908
|
-
import { homedir as
|
|
22909
|
-
import { join as
|
|
22910
|
-
import { existsSync as
|
|
23145
|
+
import { homedir as homedir13 } from "os";
|
|
23146
|
+
import { join as join40, resolve as resolve23 } from "path";
|
|
23147
|
+
import { existsSync as existsSync47, readFileSync as readFileSync30, writeFileSync as writeFileSync16 } from "fs";
|
|
22911
23148
|
function buildSystemInfo(config, baseDir, profileCompressed) {
|
|
22912
23149
|
const now = new Date().toISOString().replace("T", " ").slice(0, 19);
|
|
22913
23150
|
const isWin = profileCompressed.toLowerCase().includes("win32");
|
|
@@ -22960,9 +23197,9 @@ function buildSystemInfo(config, baseDir, profileCompressed) {
|
|
|
22960
23197
|
`);
|
|
22961
23198
|
}
|
|
22962
23199
|
async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
22963
|
-
const dir = configDir ||
|
|
22964
|
-
const projectConfigPath = projectDir ?
|
|
22965
|
-
const config = loadConfig({ configDir: dir, projectConfigPath });
|
|
23200
|
+
const dir = configDir || join40(homedir13(), ".mma");
|
|
23201
|
+
const projectConfigPath = projectDir ? join40(projectDir, ".mmrc") : join40(process.cwd(), ".mmrc");
|
|
23202
|
+
const { config, legacyDetected } = loadConfig({ configDir: dir, projectConfigPath });
|
|
22966
23203
|
setLocale(config.locale);
|
|
22967
23204
|
try {
|
|
22968
23205
|
const { globalAuditNotifier: globalAuditNotifier2 } = await Promise.resolve().then(() => (init_audit_notifier(), exports_audit_notifier));
|
|
@@ -22971,7 +23208,7 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
|
22971
23208
|
}
|
|
22972
23209
|
} catch {}
|
|
22973
23210
|
const logger = new Logger(config.logLevel);
|
|
22974
|
-
logger.setLogDir(
|
|
23211
|
+
logger.setLogDir(join40(dir, "logs"));
|
|
22975
23212
|
logger.debug("MMA bootstrap", {
|
|
22976
23213
|
version: config.version,
|
|
22977
23214
|
model: config.model
|
|
@@ -22993,7 +23230,7 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
|
22993
23230
|
logger.info(`Model ${config.model} loaded in ${loadResult.loadTime}s`);
|
|
22994
23231
|
}
|
|
22995
23232
|
}
|
|
22996
|
-
const profile = new UserProfile(
|
|
23233
|
+
const profile = new UserProfile(join40(dir));
|
|
22997
23234
|
profile.load() || profile.collect();
|
|
22998
23235
|
profile.save();
|
|
22999
23236
|
const providerManager = new ProviderManager(config.provider, {
|
|
@@ -23019,7 +23256,7 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
|
23019
23256
|
for (const warning of envReport.warnings) {
|
|
23020
23257
|
logger.warn(warning);
|
|
23021
23258
|
}
|
|
23022
|
-
const projectMapCacheDir =
|
|
23259
|
+
const projectMapCacheDir = join40(baseDir, ".mma");
|
|
23023
23260
|
const indexerModule = new IndexerModule({
|
|
23024
23261
|
baseDir,
|
|
23025
23262
|
cacheDir: projectMapCacheDir
|
|
@@ -23030,9 +23267,9 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
|
23030
23267
|
logger.warn(`Project indexing failed: ${err.message}`);
|
|
23031
23268
|
}
|
|
23032
23269
|
const skillsLoader = new SkillsLoader;
|
|
23033
|
-
const builtinDir =
|
|
23034
|
-
const globalDir =
|
|
23035
|
-
const projectSkillsDir =
|
|
23270
|
+
const builtinDir = join40(import.meta.dirname, "skills", "builtin");
|
|
23271
|
+
const globalDir = join40(homedir13(), ".agents", "skills");
|
|
23272
|
+
const projectSkillsDir = join40(baseDir, ".mma", "skills");
|
|
23036
23273
|
const availableSkills = skillsLoader.loadFromAllSources(builtinDir, globalDir, projectSkillsDir);
|
|
23037
23274
|
const skillsBudget = Math.floor(config.contextWindow * config.skills.budget);
|
|
23038
23275
|
const skillsModule = new SkillsModule(availableSkills, skillsBudget);
|
|
@@ -23048,11 +23285,11 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
|
23048
23285
|
essential: true,
|
|
23049
23286
|
estimatedTokens: Math.ceil(systemInfoContent.length / 4)
|
|
23050
23287
|
};
|
|
23051
|
-
const agentsMdGlobal =
|
|
23052
|
-
if (!
|
|
23053
|
-
|
|
23288
|
+
const agentsMdGlobal = join40(dir, "AGENTS.md");
|
|
23289
|
+
if (!existsSync47(agentsMdGlobal)) {
|
|
23290
|
+
writeFileSync16(agentsMdGlobal, "", "utf-8");
|
|
23054
23291
|
}
|
|
23055
|
-
const sessionDir =
|
|
23292
|
+
const sessionDir = join40(dir, "sessions");
|
|
23056
23293
|
const sessionStore = new SessionStore(sessionDir);
|
|
23057
23294
|
sessionStore.init();
|
|
23058
23295
|
const sessionManager = new SessionManager(sessionStore, {
|
|
@@ -23117,10 +23354,7 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
|
23117
23354
|
const hallucinationDetector = new HallucinationDetector(baseDir, llmProvider);
|
|
23118
23355
|
const moduleRegistry = new ModuleRegistry;
|
|
23119
23356
|
const execModule = new ExecutionModule(baseDir, config.stuckThreshold, config.errorWebSearch?.threshold ?? 5);
|
|
23120
|
-
|
|
23121
|
-
if (activeMeta && activeMeta.messageCount > 0) {
|
|
23122
|
-
execModule.restorePlan();
|
|
23123
|
-
}
|
|
23357
|
+
execModule.restorePlan();
|
|
23124
23358
|
moduleRegistry.register(execModule);
|
|
23125
23359
|
execModule.setHallucinationDetector(hallucinationDetector);
|
|
23126
23360
|
const sessionModule = new SessionModule(sessionManager);
|
|
@@ -23129,7 +23363,7 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
|
23129
23363
|
const mcpModule = new MCPModule(config);
|
|
23130
23364
|
await mcpModule.initialize();
|
|
23131
23365
|
moduleRegistry.register(mcpModule);
|
|
23132
|
-
const memoryStore = new MemoryStore(
|
|
23366
|
+
const memoryStore = new MemoryStore(join40(dir, "memory"));
|
|
23133
23367
|
const memoryModule = new MemoryModule(memoryStore);
|
|
23134
23368
|
moduleRegistry.register(memoryModule);
|
|
23135
23369
|
if (config.browser.enabled) {
|
|
@@ -23183,8 +23417,8 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
|
23183
23417
|
pluginManager.register(plugin);
|
|
23184
23418
|
pluginManager.register(plugin2);
|
|
23185
23419
|
const pluginLoader = new PluginLoader;
|
|
23186
|
-
const globalPluginsDir =
|
|
23187
|
-
const projectPluginsDir =
|
|
23420
|
+
const globalPluginsDir = join40(homedir13(), ".mma", "plugins");
|
|
23421
|
+
const projectPluginsDir = join40(baseDir, ".mma", "plugins");
|
|
23188
23422
|
const mmaVersion = readMmaVersion();
|
|
23189
23423
|
pluginLoader.loadFromDir(globalPluginsDir, pluginManager, logger, {
|
|
23190
23424
|
source: "global",
|
|
@@ -23210,13 +23444,13 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
|
23210
23444
|
const skipAgentsMd = noAgentsMd === true;
|
|
23211
23445
|
if (!skipAgentsMd) {
|
|
23212
23446
|
const agentsMdCandidates = [
|
|
23213
|
-
|
|
23214
|
-
|
|
23215
|
-
|
|
23447
|
+
join40(baseDir, "AGENTS.md"),
|
|
23448
|
+
join40(baseDir, ".mma", "AGENTS.md"),
|
|
23449
|
+
join40(dir, "AGENTS.md")
|
|
23216
23450
|
];
|
|
23217
23451
|
for (const p of agentsMdCandidates) {
|
|
23218
|
-
if (
|
|
23219
|
-
const content =
|
|
23452
|
+
if (existsSync47(p)) {
|
|
23453
|
+
const content = readFileSync30(p, "utf-8").trim();
|
|
23220
23454
|
if (content) {
|
|
23221
23455
|
agentsMdBlocks.push({
|
|
23222
23456
|
content,
|
|
@@ -23292,7 +23526,8 @@ async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
|
23292
23526
|
configDir: dir,
|
|
23293
23527
|
baseDir,
|
|
23294
23528
|
noAgentsMd: skipAgentsMd,
|
|
23295
|
-
envReport
|
|
23529
|
+
envReport,
|
|
23530
|
+
legacyDetected
|
|
23296
23531
|
};
|
|
23297
23532
|
}
|
|
23298
23533
|
var init_bootstrap = __esm(() => {
|
|
@@ -24020,8 +24255,16 @@ async function runSetup(externalRl) {
|
|
|
24020
24255
|
securityFlagsBlock = (await ask(rl, t("setup.security_flags_block"), "n")).toLowerCase() === "y";
|
|
24021
24256
|
securityPathsDeny = (await ask(rl, t("setup.security_paths_deny"), "Y")).toLowerCase() !== "n";
|
|
24022
24257
|
}
|
|
24023
|
-
if (ownRl)
|
|
24258
|
+
if (ownRl) {
|
|
24024
24259
|
rl.close();
|
|
24260
|
+
process.stdin.removeAllListeners("data");
|
|
24261
|
+
process.stdin.removeAllListeners("keypress");
|
|
24262
|
+
if (typeof process.stdin.setRawMode === "function") {
|
|
24263
|
+
process.stdin.setRawMode(false);
|
|
24264
|
+
}
|
|
24265
|
+
process.stdin.pause();
|
|
24266
|
+
process.stdin.resume();
|
|
24267
|
+
}
|
|
24025
24268
|
const answers = {
|
|
24026
24269
|
provider,
|
|
24027
24270
|
apiBase,
|
|
@@ -24081,21 +24324,21 @@ __export(exports_manifest, {
|
|
|
24081
24324
|
getCertMark: () => getCertMark,
|
|
24082
24325
|
MANIFEST_PATH: () => MANIFEST_PATH
|
|
24083
24326
|
});
|
|
24084
|
-
import { existsSync as
|
|
24085
|
-
import { homedir as
|
|
24086
|
-
import { join as
|
|
24327
|
+
import { existsSync as existsSync48, readFileSync as readFileSync31, mkdirSync as mkdirSync19, writeFileSync as writeFileSync17 } from "fs";
|
|
24328
|
+
import { homedir as homedir15 } from "os";
|
|
24329
|
+
import { join as join42 } from "path";
|
|
24087
24330
|
function readManifest(path = MANIFEST_PATH) {
|
|
24088
24331
|
try {
|
|
24089
|
-
if (
|
|
24090
|
-
const raw = JSON.parse(
|
|
24332
|
+
if (existsSync48(path)) {
|
|
24333
|
+
const raw = JSON.parse(readFileSync31(path, "utf-8"));
|
|
24091
24334
|
return { version: 1, certifications: raw.certifications ?? [] };
|
|
24092
24335
|
}
|
|
24093
24336
|
} catch {}
|
|
24094
24337
|
return { version: 1, certifications: [] };
|
|
24095
24338
|
}
|
|
24096
24339
|
function saveManifest(m, path = MANIFEST_PATH) {
|
|
24097
|
-
|
|
24098
|
-
|
|
24340
|
+
mkdirSync19(join42(homedir15(), ".mma"), { recursive: true });
|
|
24341
|
+
writeFileSync17(path, JSON.stringify(m, null, 2), "utf-8");
|
|
24099
24342
|
}
|
|
24100
24343
|
function upsertCertification(entry, path = MANIFEST_PATH) {
|
|
24101
24344
|
const m = readManifest(path);
|
|
@@ -24129,7 +24372,7 @@ function getCertMark(model, providerUrl, currentVersion, path = MANIFEST_PATH) {
|
|
|
24129
24372
|
}
|
|
24130
24373
|
var MANIFEST_PATH;
|
|
24131
24374
|
var init_manifest = __esm(() => {
|
|
24132
|
-
MANIFEST_PATH =
|
|
24375
|
+
MANIFEST_PATH = join42(homedir15(), ".mma", "certifications.json");
|
|
24133
24376
|
});
|
|
24134
24377
|
|
|
24135
24378
|
// node_modules/yaml/dist/nodes/identity.js
|
|
@@ -31252,8 +31495,8 @@ var init_scenarios = __esm(() => {
|
|
|
31252
31495
|
});
|
|
31253
31496
|
|
|
31254
31497
|
// src/modules/certification/loader.ts
|
|
31255
|
-
import { existsSync as
|
|
31256
|
-
import { join as
|
|
31498
|
+
import { existsSync as existsSync49, readdirSync as readdirSync17, readFileSync as readFileSync32 } from "fs";
|
|
31499
|
+
import { join as join43 } from "path";
|
|
31257
31500
|
function validateScenario(s) {
|
|
31258
31501
|
const errors2 = [];
|
|
31259
31502
|
const isSkip = s.mode === "skip";
|
|
@@ -31302,12 +31545,12 @@ function loadScenarios(userDir) {
|
|
|
31302
31545
|
else
|
|
31303
31546
|
scenarios.push(s);
|
|
31304
31547
|
}
|
|
31305
|
-
if (userDir &&
|
|
31306
|
-
for (const file of
|
|
31548
|
+
if (userDir && existsSync49(userDir)) {
|
|
31549
|
+
for (const file of readdirSync17(userDir)) {
|
|
31307
31550
|
if (!file.endsWith(".yaml") && !file.endsWith(".yml"))
|
|
31308
31551
|
continue;
|
|
31309
31552
|
try {
|
|
31310
|
-
const raw =
|
|
31553
|
+
const raw = readFileSync32(join43(userDir, file), "utf-8");
|
|
31311
31554
|
const data = $parse(raw);
|
|
31312
31555
|
const parsed = normalizeScenario(data, file);
|
|
31313
31556
|
const errs = validateScenario(parsed);
|
|
@@ -31360,8 +31603,8 @@ var init_loader3 = __esm(() => {
|
|
|
31360
31603
|
});
|
|
31361
31604
|
|
|
31362
31605
|
// src/modules/certification/fact-checker.ts
|
|
31363
|
-
import { existsSync as
|
|
31364
|
-
import { join as
|
|
31606
|
+
import { existsSync as existsSync50, readFileSync as readFileSync33, statSync as statSync9 } from "fs";
|
|
31607
|
+
import { join as join44 } from "path";
|
|
31365
31608
|
function checkSandbox(sandboxDir, checks, exitCode, output) {
|
|
31366
31609
|
const failures = [];
|
|
31367
31610
|
for (const check of checks) {
|
|
@@ -31378,16 +31621,16 @@ function runCheck2(sandboxDir, check, exitCode, output) {
|
|
|
31378
31621
|
case "outputContains":
|
|
31379
31622
|
return output.includes(check.text);
|
|
31380
31623
|
case "fileExists":
|
|
31381
|
-
return isFile(
|
|
31624
|
+
return isFile(join44(sandboxDir, check.path));
|
|
31382
31625
|
case "fileNotExists":
|
|
31383
|
-
return !
|
|
31626
|
+
return !existsSync50(join44(sandboxDir, check.path));
|
|
31384
31627
|
case "dirExists":
|
|
31385
|
-
return isDir(
|
|
31628
|
+
return isDir(join44(sandboxDir, check.path));
|
|
31386
31629
|
case "fileContent": {
|
|
31387
|
-
const abs =
|
|
31630
|
+
const abs = join44(sandboxDir, check.path);
|
|
31388
31631
|
if (!isFile(abs))
|
|
31389
31632
|
return false;
|
|
31390
|
-
const content =
|
|
31633
|
+
const content = readFileSync33(abs, "utf-8");
|
|
31391
31634
|
if (check.contains !== undefined)
|
|
31392
31635
|
return content.includes(check.contains);
|
|
31393
31636
|
if (check.equals !== undefined)
|
|
@@ -31395,10 +31638,10 @@ function runCheck2(sandboxDir, check, exitCode, output) {
|
|
|
31395
31638
|
return false;
|
|
31396
31639
|
}
|
|
31397
31640
|
case "fileRegex": {
|
|
31398
|
-
const abs =
|
|
31641
|
+
const abs = join44(sandboxDir, check.path);
|
|
31399
31642
|
if (!isFile(abs))
|
|
31400
31643
|
return false;
|
|
31401
|
-
return new RegExp(check.pattern).test(
|
|
31644
|
+
return new RegExp(check.pattern).test(readFileSync33(abs, "utf-8"));
|
|
31402
31645
|
}
|
|
31403
31646
|
default:
|
|
31404
31647
|
return false;
|
|
@@ -31406,14 +31649,14 @@ function runCheck2(sandboxDir, check, exitCode, output) {
|
|
|
31406
31649
|
}
|
|
31407
31650
|
function isFile(p) {
|
|
31408
31651
|
try {
|
|
31409
|
-
return
|
|
31652
|
+
return existsSync50(p) && statSync9(p).isFile();
|
|
31410
31653
|
} catch {
|
|
31411
31654
|
return false;
|
|
31412
31655
|
}
|
|
31413
31656
|
}
|
|
31414
31657
|
function isDir(p) {
|
|
31415
31658
|
try {
|
|
31416
|
-
return
|
|
31659
|
+
return existsSync50(p) && statSync9(p).isDirectory();
|
|
31417
31660
|
} catch {
|
|
31418
31661
|
return false;
|
|
31419
31662
|
}
|
|
@@ -31444,9 +31687,9 @@ var init_fact_checker = () => {};
|
|
|
31444
31687
|
|
|
31445
31688
|
// src/modules/certification/runner.ts
|
|
31446
31689
|
import { spawn as spawn9 } from "child_process";
|
|
31447
|
-
import { existsSync as
|
|
31690
|
+
import { existsSync as existsSync51, mkdirSync as mkdirSync20, rmSync as rmSync4, cpSync as cpSync2 } from "fs";
|
|
31448
31691
|
import { platform as platform10 } from "os";
|
|
31449
|
-
import { join as
|
|
31692
|
+
import { join as join45, resolve as resolve24, dirname as dirname16 } from "path";
|
|
31450
31693
|
async function runScenario(scenario, opts) {
|
|
31451
31694
|
if (scenario.mode === "skip") {
|
|
31452
31695
|
return {
|
|
@@ -31465,7 +31708,7 @@ async function runScenario(scenario, opts) {
|
|
|
31465
31708
|
let passed = 0;
|
|
31466
31709
|
let firstError;
|
|
31467
31710
|
for (let i = 1;i <= reps; i++) {
|
|
31468
|
-
const sandbox =
|
|
31711
|
+
const sandbox = join45(opts.sandboxBase, `run-${scenario.id}-${i}`);
|
|
31469
31712
|
let failures = [];
|
|
31470
31713
|
let exitCode = -1;
|
|
31471
31714
|
let output = "";
|
|
@@ -31524,27 +31767,27 @@ ${res.stderr}`;
|
|
|
31524
31767
|
}
|
|
31525
31768
|
function prepareSandbox(sandbox, scenario, mmaRoot) {
|
|
31526
31769
|
rmSync4(sandbox, { recursive: true, force: true });
|
|
31527
|
-
|
|
31770
|
+
mkdirSync20(sandbox, { recursive: true });
|
|
31528
31771
|
for (const f of scenario.fixtures ?? []) {
|
|
31529
|
-
const src =
|
|
31530
|
-
if (!
|
|
31772
|
+
const src = join45(mmaRoot, f.source);
|
|
31773
|
+
if (!existsSync51(src)) {
|
|
31531
31774
|
throw new Error(`fixture missing: ${f.source}`);
|
|
31532
31775
|
}
|
|
31533
|
-
const dest =
|
|
31534
|
-
|
|
31776
|
+
const dest = join45(sandbox, f.dest);
|
|
31777
|
+
mkdirSync20(dirname16(dest), { recursive: true });
|
|
31535
31778
|
cpSync2(src, dest);
|
|
31536
31779
|
}
|
|
31537
31780
|
}
|
|
31538
31781
|
function resolveMmaEntry(mmaRoot) {
|
|
31539
|
-
const dev =
|
|
31540
|
-
if (
|
|
31782
|
+
const dev = join45(mmaRoot, "src", "cli", "main.ts");
|
|
31783
|
+
if (existsSync51(dev))
|
|
31541
31784
|
return dev;
|
|
31542
|
-
return
|
|
31785
|
+
return join45(mmaRoot, "dist", "main.js");
|
|
31543
31786
|
}
|
|
31544
31787
|
function findMmaRoot(fromDir) {
|
|
31545
31788
|
const candidates = [resolve24(fromDir, "..", "..", ".."), resolve24(fromDir, "..")];
|
|
31546
31789
|
for (const c of candidates) {
|
|
31547
|
-
if (
|
|
31790
|
+
if (existsSync51(join45(c, "package.json")))
|
|
31548
31791
|
return c;
|
|
31549
31792
|
}
|
|
31550
31793
|
return process.cwd();
|
|
@@ -31611,16 +31854,16 @@ __export(exports_cli, {
|
|
|
31611
31854
|
certList: () => certList
|
|
31612
31855
|
});
|
|
31613
31856
|
import { rmSync as rmSync5 } from "fs";
|
|
31614
|
-
import { homedir as
|
|
31615
|
-
import { join as
|
|
31857
|
+
import { homedir as homedir16 } from "os";
|
|
31858
|
+
import { join as join46, dirname as dirname17 } from "path";
|
|
31616
31859
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
31617
|
-
import { existsSync as
|
|
31860
|
+
import { existsSync as existsSync52, readFileSync as readFileSync34 } from "fs";
|
|
31618
31861
|
function readVersion() {
|
|
31619
|
-
const candidates = [
|
|
31862
|
+
const candidates = [join46(MMA_ROOT, "package.json")];
|
|
31620
31863
|
for (const p of candidates) {
|
|
31621
|
-
if (
|
|
31864
|
+
if (existsSync52(p)) {
|
|
31622
31865
|
try {
|
|
31623
|
-
const raw = JSON.parse(
|
|
31866
|
+
const raw = JSON.parse(readFileSync34(p, "utf-8"));
|
|
31624
31867
|
if (raw.version)
|
|
31625
31868
|
return raw.version;
|
|
31626
31869
|
} catch {}
|
|
@@ -31656,7 +31899,7 @@ async function certify(opts) {
|
|
|
31656
31899
|
return;
|
|
31657
31900
|
}
|
|
31658
31901
|
console.log(t("cli.cert_started", { model: opts.name, provider: providerUrl }));
|
|
31659
|
-
const sandboxBase =
|
|
31902
|
+
const sandboxBase = join46(process.cwd(), ".mma", "certification");
|
|
31660
31903
|
const results = [];
|
|
31661
31904
|
const total = selected.length;
|
|
31662
31905
|
let idx = 0;
|
|
@@ -31768,9 +32011,9 @@ var init_cli = __esm(() => {
|
|
|
31768
32011
|
init_loader3();
|
|
31769
32012
|
init_runner2();
|
|
31770
32013
|
init_manifest();
|
|
31771
|
-
HERE =
|
|
32014
|
+
HERE = dirname17(fileURLToPath4(import.meta.url));
|
|
31772
32015
|
MMA_ROOT = findMmaRoot(HERE);
|
|
31773
|
-
USER_SCENARIO_DIR =
|
|
32016
|
+
USER_SCENARIO_DIR = join46(homedir16(), ".mma", "certification", "scenarios");
|
|
31774
32017
|
});
|
|
31775
32018
|
|
|
31776
32019
|
// src/cli/repl-commands.ts
|
|
@@ -31779,8 +32022,9 @@ __export(exports_repl_commands, {
|
|
|
31779
32022
|
registerAllCommands: () => registerAllCommands,
|
|
31780
32023
|
COMMAND_GROUPS: () => COMMAND_GROUPS
|
|
31781
32024
|
});
|
|
31782
|
-
import { join as
|
|
31783
|
-
import { homedir as
|
|
32025
|
+
import { join as join48, dirname as dirname19 } from "path";
|
|
32026
|
+
import { homedir as homedir18 } from "os";
|
|
32027
|
+
import { existsSync as existsSync54 } from "fs";
|
|
31784
32028
|
function registerAllCommands(ctx) {
|
|
31785
32029
|
registerBuiltinCommands(ctx);
|
|
31786
32030
|
registerMmaCommands(ctx);
|
|
@@ -31837,7 +32081,7 @@ function registerMmaCommands(ctx) {
|
|
|
31837
32081
|
}
|
|
31838
32082
|
try {
|
|
31839
32083
|
const { loadFileAsDataUrl: loadFileAsDataUrl2, loadUrlAsDataUrl: loadUrlAsDataUrl2, readClipboardImage: readClipboardImage2 } = await Promise.resolve().then(() => (init_image_utils(), exports_image_utils));
|
|
31840
|
-
const { existsSync:
|
|
32084
|
+
const { existsSync: existsSync55 } = await import("fs");
|
|
31841
32085
|
const { resolve: resolve25 } = await import("path");
|
|
31842
32086
|
let dataUrl;
|
|
31843
32087
|
let label;
|
|
@@ -31857,7 +32101,7 @@ function registerMmaCommands(ctx) {
|
|
|
31857
32101
|
label = source;
|
|
31858
32102
|
} else {
|
|
31859
32103
|
const absPath = resolve25(process.cwd(), source);
|
|
31860
|
-
if (!
|
|
32104
|
+
if (!existsSync55(absPath)) {
|
|
31861
32105
|
console.log(pc2.red(t("image.not_found", { path: source })));
|
|
31862
32106
|
return;
|
|
31863
32107
|
}
|
|
@@ -31910,6 +32154,31 @@ function registerMmaCommands(ctx) {
|
|
|
31910
32154
|
}
|
|
31911
32155
|
}
|
|
31912
32156
|
});
|
|
32157
|
+
ctx.registerCommand({
|
|
32158
|
+
name: "config migrate",
|
|
32159
|
+
description: t("cli.migrate_config"),
|
|
32160
|
+
action: async () => {
|
|
32161
|
+
const { hasDomainFiles: hasDomainFiles3 } = await Promise.resolve().then(() => (init_domains(), exports_domains));
|
|
32162
|
+
const { loadConfig: loadCfg } = await Promise.resolve().then(() => (init_config2(), exports_config));
|
|
32163
|
+
const configDir = ctx.configDir;
|
|
32164
|
+
const configPath = join48(configDir, "config.json");
|
|
32165
|
+
if (hasDomainFiles3(configDir)) {
|
|
32166
|
+
console.log(pc2.yellow(t("config.migrate_no_legacy")));
|
|
32167
|
+
return;
|
|
32168
|
+
}
|
|
32169
|
+
if (!existsSync54(configPath)) {
|
|
32170
|
+
console.log(pc2.yellow(t("config.migrate_no_legacy")));
|
|
32171
|
+
return;
|
|
32172
|
+
}
|
|
32173
|
+
console.log(t("config.migrate_start"));
|
|
32174
|
+
const { config } = loadCfg({ configDir, projectConfigPath: join48(configDir, ".mmrc") });
|
|
32175
|
+
saveConfig(config, configPath, configDir);
|
|
32176
|
+
const { renameSync: renameSync3, readdirSync: readdirSync18 } = await import("fs");
|
|
32177
|
+
renameSync3(configPath, configPath + ".bak");
|
|
32178
|
+
const domainFiles = readdirSync18(join48(configDir, "config")).filter((f) => f.endsWith(".json"));
|
|
32179
|
+
console.log(pc2.green(t("config.migrate_done", { count: String(domainFiles.length) })));
|
|
32180
|
+
}
|
|
32181
|
+
});
|
|
31913
32182
|
ctx.registerCommand({
|
|
31914
32183
|
name: "reasoning",
|
|
31915
32184
|
description: t("repl.reasoning"),
|
|
@@ -31948,7 +32217,7 @@ function registerMmaCommands(ctx) {
|
|
|
31948
32217
|
console.log(pc2.yellow(t("repl.wizard_running")));
|
|
31949
32218
|
await ctx.withExclusiveInput(async () => {
|
|
31950
32219
|
const answers = await runSetup(ctx.rl);
|
|
31951
|
-
const configPath =
|
|
32220
|
+
const configPath = join48(homedir18(), ".mma", "config.json");
|
|
31952
32221
|
ctx.config.provider.type = answers.provider;
|
|
31953
32222
|
ctx.config.provider.baseUrl = answers.apiBase;
|
|
31954
32223
|
ctx.config.provider.apiKey = answers.apiKey;
|
|
@@ -31956,7 +32225,7 @@ function registerMmaCommands(ctx) {
|
|
|
31956
32225
|
ctx.config.contextWindow = answers.contextWindow;
|
|
31957
32226
|
ctx.config.maxToolIterations = answers.maxToolIterations;
|
|
31958
32227
|
ctx.config.locale = answers.locale;
|
|
31959
|
-
saveConfig(ctx.config, configPath);
|
|
32228
|
+
saveConfig(ctx.config, configPath, dirname19(configPath));
|
|
31960
32229
|
await ctx.agent.reconfigure(ctx.config);
|
|
31961
32230
|
console.log(pc2.green(t("cli.config_saved")));
|
|
31962
32231
|
});
|
|
@@ -32070,8 +32339,8 @@ Excluded blocks: ${info.excluded.length}`));
|
|
|
32070
32339
|
return;
|
|
32071
32340
|
}
|
|
32072
32341
|
ctx.config.model = name;
|
|
32073
|
-
const configPath =
|
|
32074
|
-
saveConfig(ctx.config, configPath);
|
|
32342
|
+
const configPath = join48(homedir18(), ".mma", "config.json");
|
|
32343
|
+
saveConfig(ctx.config, configPath, dirname19(configPath));
|
|
32075
32344
|
await ctx.agent.reconfigure(ctx.config);
|
|
32076
32345
|
console.log(pc2.green(t("repl.model_set", { name })));
|
|
32077
32346
|
return;
|
|
@@ -32095,8 +32364,8 @@ Excluded blocks: ${info.excluded.length}`));
|
|
|
32095
32364
|
return;
|
|
32096
32365
|
}
|
|
32097
32366
|
ctx.config.contextWindow = size;
|
|
32098
|
-
const configPath =
|
|
32099
|
-
saveConfig(ctx.config, configPath);
|
|
32367
|
+
const configPath = join48(homedir18(), ".mma", "config.json");
|
|
32368
|
+
saveConfig(ctx.config, configPath, dirname19(configPath));
|
|
32100
32369
|
await ctx.agent.reconfigure(ctx.config);
|
|
32101
32370
|
console.log(pc2.green(t("cli.context_set", { size })));
|
|
32102
32371
|
}
|
|
@@ -32110,12 +32379,12 @@ Excluded blocks: ${info.excluded.length}`));
|
|
|
32110
32379
|
if (ctx.sessionManager && ctx.config.session.autoSave) {}
|
|
32111
32380
|
ctx.agent.shutdown();
|
|
32112
32381
|
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_config2(), exports_config));
|
|
32113
|
-
const { homedir:
|
|
32114
|
-
const { join:
|
|
32382
|
+
const { homedir: homedir19 } = await import("os");
|
|
32383
|
+
const { join: join49 } = await import("path");
|
|
32115
32384
|
const configDir = ctx.configDir;
|
|
32116
32385
|
const baseDir = ctx.baseDir;
|
|
32117
|
-
const projectConfigPath =
|
|
32118
|
-
const freshConfig = loadConfig2({ configDir, projectConfigPath });
|
|
32386
|
+
const projectConfigPath = join49(baseDir, ".mmrc");
|
|
32387
|
+
const { config: freshConfig } = loadConfig2({ configDir, projectConfigPath });
|
|
32119
32388
|
Object.assign(ctx.config, freshConfig);
|
|
32120
32389
|
const { bootstrap: bootstrap2 } = await Promise.resolve().then(() => (init_bootstrap(), exports_bootstrap));
|
|
32121
32390
|
const result = await bootstrap2(configDir, baseDir, false, false);
|
|
@@ -32517,14 +32786,15 @@ init_config2();
|
|
|
32517
32786
|
init_setup();
|
|
32518
32787
|
init_i18n();
|
|
32519
32788
|
init_colors();
|
|
32520
|
-
import { join as
|
|
32521
|
-
import { homedir as
|
|
32789
|
+
import { join as join47, dirname as dirname18 } from "path";
|
|
32790
|
+
import { homedir as homedir17 } from "os";
|
|
32791
|
+
import { existsSync as existsSync53 } from "fs";
|
|
32522
32792
|
|
|
32523
32793
|
// src/cli/security-commands.ts
|
|
32524
32794
|
init_bootstrap();
|
|
32525
32795
|
init_config2();
|
|
32526
|
-
import { join as
|
|
32527
|
-
import { homedir as
|
|
32796
|
+
import { join as join41, dirname as dirname15 } from "path";
|
|
32797
|
+
import { homedir as homedir14 } from "os";
|
|
32528
32798
|
|
|
32529
32799
|
// src/modules/security/security-policies.ts
|
|
32530
32800
|
init_security();
|
|
@@ -33037,7 +33307,7 @@ function createSecurityCommand(program2) {
|
|
|
33037
33307
|
}
|
|
33038
33308
|
});
|
|
33039
33309
|
securityCmd.command("set-policy").argument("<preset>", t("cli.security.preset")).description(t("cli.security.set_policy")).action(async (preset) => {
|
|
33040
|
-
const configPath =
|
|
33310
|
+
const configPath = join41(homedir14(), ".mma", "config.json");
|
|
33041
33311
|
const { config: appConfig } = await bootstrap();
|
|
33042
33312
|
const validPresets = ["strict", "balanced", "permissive"];
|
|
33043
33313
|
if (!validPresets.includes(preset)) {
|
|
@@ -33047,12 +33317,12 @@ function createSecurityCommand(program2) {
|
|
|
33047
33317
|
const policy = getSecurityPolicy(preset);
|
|
33048
33318
|
const newSecurityConfig = applySecurityPolicy(preset);
|
|
33049
33319
|
appConfig.security = newSecurityConfig;
|
|
33050
|
-
saveConfig(appConfig, configPath);
|
|
33320
|
+
saveConfig(appConfig, configPath, dirname15(configPath));
|
|
33051
33321
|
console.log(t("cli.security.policy_applied", { name: policy.name }));
|
|
33052
33322
|
console.log(t("cli.security.policy_description", { description: policy.description }));
|
|
33053
33323
|
});
|
|
33054
33324
|
securityCmd.command("enable-encryption").description(t("cli.security.enable_encryption")).action(async () => {
|
|
33055
|
-
const configPath =
|
|
33325
|
+
const configPath = join41(homedir14(), ".mma", "config.json");
|
|
33056
33326
|
const { config: appConfig } = await bootstrap();
|
|
33057
33327
|
appConfig.security = appConfig.security || {};
|
|
33058
33328
|
appConfig.security.sessionEncryption = {
|
|
@@ -33060,11 +33330,11 @@ function createSecurityCommand(program2) {
|
|
|
33060
33330
|
encryptHistory: true,
|
|
33061
33331
|
encryptSessionLog: true
|
|
33062
33332
|
};
|
|
33063
|
-
saveConfig(appConfig, configPath);
|
|
33333
|
+
saveConfig(appConfig, configPath, dirname15(configPath));
|
|
33064
33334
|
console.log(t("cli.security.encryption_enabled"));
|
|
33065
33335
|
});
|
|
33066
33336
|
securityCmd.command("disable-encryption").description(t("cli.security.disable_encryption")).action(async () => {
|
|
33067
|
-
const configPath =
|
|
33337
|
+
const configPath = join41(homedir14(), ".mma", "config.json");
|
|
33068
33338
|
const { config: appConfig } = await bootstrap();
|
|
33069
33339
|
appConfig.security = appConfig.security || {};
|
|
33070
33340
|
appConfig.security.sessionEncryption = {
|
|
@@ -33072,11 +33342,11 @@ function createSecurityCommand(program2) {
|
|
|
33072
33342
|
encryptHistory: false,
|
|
33073
33343
|
encryptSessionLog: false
|
|
33074
33344
|
};
|
|
33075
|
-
saveConfig(appConfig, configPath);
|
|
33345
|
+
saveConfig(appConfig, configPath, dirname15(configPath));
|
|
33076
33346
|
console.log(t("cli.security.encryption_disabled"));
|
|
33077
33347
|
});
|
|
33078
33348
|
securityCmd.command("enable-audit").description(t("cli.security.enable_audit")).action(async () => {
|
|
33079
|
-
const configPath =
|
|
33349
|
+
const configPath = join41(homedir14(), ".mma", "config.json");
|
|
33080
33350
|
const { config: appConfig } = await bootstrap();
|
|
33081
33351
|
appConfig.security = appConfig.security || {};
|
|
33082
33352
|
appConfig.security.auditNotifier = {
|
|
@@ -33086,11 +33356,11 @@ function createSecurityCommand(program2) {
|
|
|
33086
33356
|
maxRetries: 3,
|
|
33087
33357
|
webhookTimeout: 5000
|
|
33088
33358
|
};
|
|
33089
|
-
saveConfig(appConfig, configPath);
|
|
33359
|
+
saveConfig(appConfig, configPath, dirname15(configPath));
|
|
33090
33360
|
console.log(t("cli.security.audit_enabled"));
|
|
33091
33361
|
});
|
|
33092
33362
|
securityCmd.command("disable-audit").description(t("cli.security.disable_audit")).action(async () => {
|
|
33093
|
-
const configPath =
|
|
33363
|
+
const configPath = join41(homedir14(), ".mma", "config.json");
|
|
33094
33364
|
const { config: appConfig } = await bootstrap();
|
|
33095
33365
|
appConfig.security = appConfig.security || {};
|
|
33096
33366
|
appConfig.security.auditNotifier = {
|
|
@@ -33098,7 +33368,7 @@ function createSecurityCommand(program2) {
|
|
|
33098
33368
|
maxRetries: 3,
|
|
33099
33369
|
webhookTimeout: 5000
|
|
33100
33370
|
};
|
|
33101
|
-
saveConfig(appConfig, configPath);
|
|
33371
|
+
saveConfig(appConfig, configPath, dirname15(configPath));
|
|
33102
33372
|
console.log(t("cli.security.audit_disabled"));
|
|
33103
33373
|
});
|
|
33104
33374
|
securityCmd.command("audit-stats").description(t("cli.security.audit_stats")).action(async () => {
|
|
@@ -33160,7 +33430,7 @@ function createProgram() {
|
|
|
33160
33430
|
const program2 = new Command().name("mma").description(t("cli.description")).version(version).option("--no-agents-md", t("cli.no_agents_md")).option("-d, --dir <path>", t("cli.dir")).option("-e, --exit-on-complete", t("cli.exit_on_complete")).option("-j, --json", t("cli.json"));
|
|
33161
33431
|
program2.command("init").description(t("cli.init")).action(async () => {
|
|
33162
33432
|
const answers = await runSetup();
|
|
33163
|
-
const configPath =
|
|
33433
|
+
const configPath = join47(homedir17(), ".mma", "config.json");
|
|
33164
33434
|
const { config } = await bootstrap();
|
|
33165
33435
|
config.provider.type = answers.provider;
|
|
33166
33436
|
config.provider.baseUrl = answers.apiBase;
|
|
@@ -33200,12 +33470,12 @@ function createProgram() {
|
|
|
33200
33470
|
config.security.paths.denied = [];
|
|
33201
33471
|
}
|
|
33202
33472
|
}
|
|
33203
|
-
saveConfig(config, configPath);
|
|
33473
|
+
saveConfig(config, configPath, dirname18(configPath));
|
|
33204
33474
|
console.log(t("cli.config_saved"));
|
|
33205
33475
|
});
|
|
33206
33476
|
const configCmd = program2.command("config").description(t("cli.manage_config"));
|
|
33207
33477
|
configCmd.command("set").argument("<key>", t("cli.config_key")).argument("<value>", "Config value").description(t("cli.set_value")).action(async (key, value) => {
|
|
33208
|
-
const configPath =
|
|
33478
|
+
const configPath = join47(homedir17(), ".mma", "config.json");
|
|
33209
33479
|
const { config } = await bootstrap();
|
|
33210
33480
|
const keys = key.split(".");
|
|
33211
33481
|
let obj = config;
|
|
@@ -33225,13 +33495,36 @@ function createProgram() {
|
|
|
33225
33495
|
obj[lastKey] = parseFloat(value);
|
|
33226
33496
|
else
|
|
33227
33497
|
obj[lastKey] = value;
|
|
33228
|
-
saveConfig(config, configPath);
|
|
33498
|
+
saveConfig(config, configPath, dirname18(configPath));
|
|
33229
33499
|
console.log(t("cli.set_done", { key, value }));
|
|
33230
33500
|
});
|
|
33231
33501
|
configCmd.command("show").description(t("cli.show_config")).action(async () => {
|
|
33232
33502
|
const { config } = await bootstrap();
|
|
33233
33503
|
console.log(JSON.stringify(config, null, 2));
|
|
33234
33504
|
});
|
|
33505
|
+
configCmd.command("migrate").description(t("cli.migrate_config")).action(async () => {
|
|
33506
|
+
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_config2(), exports_config));
|
|
33507
|
+
const { hasDomainFiles: hasDomainFiles3 } = await Promise.resolve().then(() => (init_domains(), exports_domains));
|
|
33508
|
+
const configDir = join47(homedir17(), ".mma");
|
|
33509
|
+
const configPath = join47(configDir, "config.json");
|
|
33510
|
+
if (hasDomainFiles3(configDir)) {
|
|
33511
|
+
console.log(pc2.yellow(t("config.migrate_no_legacy")));
|
|
33512
|
+
return;
|
|
33513
|
+
}
|
|
33514
|
+
if (!existsSync53(configPath)) {
|
|
33515
|
+
console.log(pc2.yellow(t("config.migrate_no_legacy")));
|
|
33516
|
+
return;
|
|
33517
|
+
}
|
|
33518
|
+
console.log(t("config.migrate_start"));
|
|
33519
|
+
const { config } = loadConfig2({ configDir, projectConfigPath: join47(configDir, ".mmrc") });
|
|
33520
|
+
saveConfig(config, configPath, configDir);
|
|
33521
|
+
const bakPath = configPath + ".bak";
|
|
33522
|
+
const { renameSync: renameSync3 } = await import("fs");
|
|
33523
|
+
renameSync3(configPath, bakPath);
|
|
33524
|
+
const { readdirSync: readdirSync18 } = await import("fs");
|
|
33525
|
+
const domainFiles = readdirSync18(join47(configDir, "config")).filter((f) => f.endsWith(".json"));
|
|
33526
|
+
console.log(pc2.green(t("config.migrate_done", { count: String(domainFiles.length) })));
|
|
33527
|
+
});
|
|
33235
33528
|
const model = program2.command("model").description(t("cli.manage_models"));
|
|
33236
33529
|
model.command("list").description(t("cli.list_models")).action(async () => {
|
|
33237
33530
|
const { config } = await bootstrap();
|
|
@@ -33268,10 +33561,10 @@ function createProgram() {
|
|
|
33268
33561
|
console.log(t("cli.model_hint"));
|
|
33269
33562
|
});
|
|
33270
33563
|
model.command("use").argument("<name>", "Model name").description(t("cli.set_model")).action(async (name) => {
|
|
33271
|
-
const configPath =
|
|
33564
|
+
const configPath = join47(homedir17(), ".mma", "config.json");
|
|
33272
33565
|
const { config } = await bootstrap();
|
|
33273
33566
|
config.model = name;
|
|
33274
|
-
saveConfig(config, configPath);
|
|
33567
|
+
saveConfig(config, configPath, dirname18(configPath));
|
|
33275
33568
|
console.log(t("cli.model_set", { name }));
|
|
33276
33569
|
});
|
|
33277
33570
|
model.command("certify").argument("<name>", "Model name").option("--provider-url <url>", t("cli.cert_provider_url")).option("--provider-key <key>", t("cli.cert_provider_key")).option("--context-window <n>", t("cli.cert_context_window")).option("--tags <tags>", t("cli.cert_tags"), "core").option("--reps <n>", t("cli.cert_reps")).option("--force", t("cli.cert_force")).option("--clean", t("cli.cert_clean")).description(t("cli.certify")).action(async (name, cmdOpts) => {
|
|
@@ -33304,7 +33597,7 @@ function createProgram() {
|
|
|
33304
33597
|
await uncertify2(name, config);
|
|
33305
33598
|
});
|
|
33306
33599
|
program2.command("context").description(t("cli.manage_context")).argument("<size>", "Context window size in tokens").action(async (size) => {
|
|
33307
|
-
const configPath =
|
|
33600
|
+
const configPath = join47(homedir17(), ".mma", "config.json");
|
|
33308
33601
|
const { config } = await bootstrap();
|
|
33309
33602
|
const contextWindow = parseInt(size, 10);
|
|
33310
33603
|
if (isNaN(contextWindow) || contextWindow < 1024) {
|
|
@@ -33312,7 +33605,7 @@ function createProgram() {
|
|
|
33312
33605
|
return;
|
|
33313
33606
|
}
|
|
33314
33607
|
config.contextWindow = contextWindow;
|
|
33315
|
-
saveConfig(config, configPath);
|
|
33608
|
+
saveConfig(config, configPath, dirname18(configPath));
|
|
33316
33609
|
console.log(t("cli.context_set", { size: contextWindow }));
|
|
33317
33610
|
});
|
|
33318
33611
|
const provider = program2.command("provider").description(t("cli.manage_providers"));
|
|
@@ -33350,7 +33643,7 @@ function createProgram() {
|
|
|
33350
33643
|
console.log(t("cli.base_url"), config.provider.baseUrl);
|
|
33351
33644
|
});
|
|
33352
33645
|
provider.command("use").argument("<name>", "Provider name").description(t("cli.set_provider")).action(async (name) => {
|
|
33353
|
-
const configPath =
|
|
33646
|
+
const configPath = join47(homedir17(), ".mma", "config.json");
|
|
33354
33647
|
const { config, agent } = await bootstrap();
|
|
33355
33648
|
if (config.provider.entries && config.provider.entries.length > 0) {
|
|
33356
33649
|
try {
|
|
@@ -33366,14 +33659,14 @@ function createProgram() {
|
|
|
33366
33659
|
if (baseUrl) {
|
|
33367
33660
|
config.provider.baseUrl = baseUrl;
|
|
33368
33661
|
}
|
|
33369
|
-
saveConfig(config, configPath);
|
|
33662
|
+
saveConfig(config, configPath, dirname18(configPath));
|
|
33370
33663
|
console.log(t("cli.provider_set", { name }));
|
|
33371
33664
|
if (baseUrl) {
|
|
33372
33665
|
console.log(t("cli.provider_base_hint", { baseUrl }));
|
|
33373
33666
|
}
|
|
33374
33667
|
});
|
|
33375
33668
|
provider.command("add").argument("<name>", "Provider type or label").option("--url <url>", "Base URL").option("--key <key>", "API key").option("--priority <n>", "Fallback priority (lower = tried first)").option("--context-window <n>", "Context window override for this entry").option("--rpm <n>", "Max requests per minute for this entry").option("--parallel <n>", "Max parallel tasks for this entry").description(t("cli.add_provider")).action(async (name, opts) => {
|
|
33376
|
-
const configPath =
|
|
33669
|
+
const configPath = join47(homedir17(), ".mma", "config.json");
|
|
33377
33670
|
const { config } = await bootstrap();
|
|
33378
33671
|
const entries = Array.isArray(config.provider.entries) ? config.provider.entries : [];
|
|
33379
33672
|
if (entries.length === 0) {
|
|
@@ -33405,7 +33698,7 @@ function createProgram() {
|
|
|
33405
33698
|
});
|
|
33406
33699
|
config.provider.entries = entries;
|
|
33407
33700
|
config.provider.active = config.provider.active || config.provider.type;
|
|
33408
|
-
saveConfig(config, configPath);
|
|
33701
|
+
saveConfig(config, configPath, dirname18(configPath));
|
|
33409
33702
|
console.log(pc2.green(t("cli.provider_added", { name })));
|
|
33410
33703
|
console.log(t("cli.provider_switch_hint"));
|
|
33411
33704
|
});
|
|
@@ -33742,6 +34035,10 @@ class LineEditor {
|
|
|
33742
34035
|
this.lastWasCR = false;
|
|
33743
34036
|
return;
|
|
33744
34037
|
}
|
|
34038
|
+
if (this.questionCb) {
|
|
34039
|
+
this.submit();
|
|
34040
|
+
return;
|
|
34041
|
+
}
|
|
33745
34042
|
this.insertNewline();
|
|
33746
34043
|
return;
|
|
33747
34044
|
case "backspace":
|
|
@@ -34278,9 +34575,9 @@ class LineEditor {
|
|
|
34278
34575
|
}
|
|
34279
34576
|
|
|
34280
34577
|
// src/cli/repl.ts
|
|
34281
|
-
import { existsSync as
|
|
34282
|
-
import { join as
|
|
34283
|
-
import { homedir as
|
|
34578
|
+
import { existsSync as existsSync55, readFileSync as readFileSync37, writeFileSync as writeFileSync18 } from "fs";
|
|
34579
|
+
import { join as join49 } from "path";
|
|
34580
|
+
import { homedir as homedir19 } from "os";
|
|
34284
34581
|
|
|
34285
34582
|
// src/cli/completer.ts
|
|
34286
34583
|
class SlashCommandProvider {
|
|
@@ -34864,7 +35161,6 @@ ${pc2.dim(marker)} ${friendlyTool(tool)}${summary ? ` ${pc2.dim(summary)}` : ""}
|
|
|
34864
35161
|
|
|
34865
35162
|
// src/cli/repl.ts
|
|
34866
35163
|
init_box();
|
|
34867
|
-
init_string_width();
|
|
34868
35164
|
init_i18n();
|
|
34869
35165
|
init_repl_commands();
|
|
34870
35166
|
|
|
@@ -35050,6 +35346,22 @@ function formatContextBar(used, limit, compactions, quality) {
|
|
|
35050
35346
|
}
|
|
35051
35347
|
return line;
|
|
35052
35348
|
}
|
|
35349
|
+
function createHostBridge(opts) {
|
|
35350
|
+
return {
|
|
35351
|
+
isBusy: opts.isBusy,
|
|
35352
|
+
async submit(text, o) {
|
|
35353
|
+
if (opts.isBusy())
|
|
35354
|
+
throw new Error("agent is busy");
|
|
35355
|
+
for (const url of o?.images ?? [])
|
|
35356
|
+
opts.addPendingImage(url);
|
|
35357
|
+
return opts.runAgent(text);
|
|
35358
|
+
},
|
|
35359
|
+
interrupt() {
|
|
35360
|
+
if (opts.isBusy())
|
|
35361
|
+
opts.interruptRun();
|
|
35362
|
+
}
|
|
35363
|
+
};
|
|
35364
|
+
}
|
|
35053
35365
|
|
|
35054
35366
|
class Repl {
|
|
35055
35367
|
completer = new Completer;
|
|
@@ -35088,10 +35400,10 @@ class Repl {
|
|
|
35088
35400
|
this.envReport = envReport;
|
|
35089
35401
|
this.execModule = execModule;
|
|
35090
35402
|
this.slog = new SessionLogger(sessionManager, logger);
|
|
35091
|
-
this.configDir = configDir ||
|
|
35403
|
+
this.configDir = configDir || join49(homedir19(), ".mma");
|
|
35092
35404
|
this.baseDir = baseDir || process.cwd();
|
|
35093
35405
|
this.noAgentsMd = noAgentsMd === true;
|
|
35094
|
-
this.historyPath = historyPath ??
|
|
35406
|
+
this.historyPath = historyPath ?? join49(homedir19(), ".mma", "repl-history");
|
|
35095
35407
|
this.loadHistory();
|
|
35096
35408
|
this.rl = process.stdin.isTTY ? new LineEditor({
|
|
35097
35409
|
input: process.stdin,
|
|
@@ -35122,11 +35434,24 @@ class Repl {
|
|
|
35122
35434
|
registerAllCommands(this);
|
|
35123
35435
|
this.setupCompleter();
|
|
35124
35436
|
this.setupListeners();
|
|
35437
|
+
if (pluginManager) {
|
|
35438
|
+
pluginManager.setHostBridge(createHostBridge({
|
|
35439
|
+
isBusy: () => this.agentRunning,
|
|
35440
|
+
addPendingImage: (url) => {
|
|
35441
|
+
this.agent.contextManager?.addPendingImage?.({
|
|
35442
|
+
type: "image_url",
|
|
35443
|
+
image_url: { url }
|
|
35444
|
+
});
|
|
35445
|
+
},
|
|
35446
|
+
runAgent: (text) => this.runAgent(text),
|
|
35447
|
+
interruptRun: () => this.agent.shutdown()
|
|
35448
|
+
}));
|
|
35449
|
+
}
|
|
35125
35450
|
}
|
|
35126
35451
|
loadHistory() {
|
|
35127
|
-
if (
|
|
35452
|
+
if (existsSync55(this.historyPath)) {
|
|
35128
35453
|
try {
|
|
35129
|
-
const raw =
|
|
35454
|
+
const raw = readFileSync37(this.historyPath, "utf-8");
|
|
35130
35455
|
this.history = raw.split(`
|
|
35131
35456
|
`).filter(Boolean).slice(-this.maxHistory);
|
|
35132
35457
|
} catch {
|
|
@@ -35136,7 +35461,7 @@ class Repl {
|
|
|
35136
35461
|
}
|
|
35137
35462
|
saveHistory() {
|
|
35138
35463
|
const allHistory = this.history.slice(-this.maxHistory);
|
|
35139
|
-
|
|
35464
|
+
writeFileSync18(this.historyPath, allHistory.join(`
|
|
35140
35465
|
`), "utf-8");
|
|
35141
35466
|
}
|
|
35142
35467
|
setupCompleter() {
|
|
@@ -35523,11 +35848,11 @@ ${t("image.clipboard_empty")}`));
|
|
|
35523
35848
|
row(t("repl.agents_label"), pc2.red(t("repl.disabled")));
|
|
35524
35849
|
} else {
|
|
35525
35850
|
const agentsMdCandidates = [
|
|
35526
|
-
|
|
35527
|
-
|
|
35528
|
-
|
|
35851
|
+
join49(this.baseDir, "AGENTS.md"),
|
|
35852
|
+
join49(this.baseDir, ".mma", "AGENTS.md"),
|
|
35853
|
+
join49(this.configDir, "AGENTS.md")
|
|
35529
35854
|
];
|
|
35530
|
-
const foundAgents = agentsMdCandidates.filter((p) =>
|
|
35855
|
+
const foundAgents = agentsMdCandidates.filter((p) => existsSync55(p));
|
|
35531
35856
|
if (foundAgents.length > 0) {
|
|
35532
35857
|
for (const p of foundAgents) {
|
|
35533
35858
|
row(t("repl.agents_label"), pc2.dim(p));
|
|
@@ -35538,24 +35863,35 @@ ${t("image.clipboard_empty")}`));
|
|
|
35538
35863
|
}
|
|
35539
35864
|
const meta = this.sessionManager?.getActiveMeta();
|
|
35540
35865
|
if (meta) {
|
|
35541
|
-
const sessionPath =
|
|
35866
|
+
const sessionPath = join49(this.configDir, "sessions", meta.id);
|
|
35542
35867
|
row(t("repl.session_label"), `${pc2.cyan(meta.name)} ${pc2.dim(`(${meta.id.slice(0, 12)})`)} — ${meta.messageCount} msgs ${pc2.dim(sessionPath)}`);
|
|
35543
35868
|
}
|
|
35544
|
-
const headerWidth = Math.max(50, Math.min(96, process.stdout.columns || 96));
|
|
35545
35869
|
const isTty2 = process.stdout.isTTY === true;
|
|
35546
35870
|
const lspEnabled = isTty2 && (this.config.lsp ?? DEFAULT_LSP_CONFIG).enabled !== false;
|
|
35547
|
-
if (lspEnabled) {
|
|
35548
|
-
row(t("repl.lsp_label"), pc2.dim("…"));
|
|
35549
|
-
}
|
|
35550
35871
|
for (const line of info) {
|
|
35551
35872
|
console.log(pc2.dim(line).trimEnd());
|
|
35552
35873
|
}
|
|
35553
35874
|
console.log();
|
|
35875
|
+
try {
|
|
35876
|
+
const { existsSync: exists } = await import("fs");
|
|
35877
|
+
const { join: pathJoin } = await import("path");
|
|
35878
|
+
const { hasDomainFiles: hasDomainFiles3 } = await Promise.resolve().then(() => (init_domains(), exports_domains));
|
|
35879
|
+
const legacyPath = pathJoin(this.configDir, "config.json");
|
|
35880
|
+
if (exists(legacyPath) && !hasDomainFiles3(this.configDir)) {
|
|
35881
|
+
console.log(pc2.yellow(` ${t("config.legacy_hint")}`));
|
|
35882
|
+
console.log();
|
|
35883
|
+
}
|
|
35884
|
+
} catch {}
|
|
35554
35885
|
this.rl.prompt();
|
|
35555
35886
|
if (lspEnabled) {
|
|
35556
35887
|
this.probeLspBanner().then((lspSummary) => {
|
|
35557
|
-
if (lspSummary)
|
|
35558
|
-
|
|
35888
|
+
if (lspSummary) {
|
|
35889
|
+
const line = `${pc2.green(t("repl.agent"))}${pc2.yellow(t("repl.lsp_label"))} ${lspSummary}`;
|
|
35890
|
+
process.stdout.write(`\x1B[2K\r${divider()}
|
|
35891
|
+
${line}
|
|
35892
|
+
`);
|
|
35893
|
+
this.rl.prompt();
|
|
35894
|
+
}
|
|
35559
35895
|
}).catch(() => {});
|
|
35560
35896
|
}
|
|
35561
35897
|
if ((this.config.provider.entries?.length ?? 0) > 1) {
|
|
@@ -35571,17 +35907,6 @@ ${t("image.clipboard_empty")}`));
|
|
|
35571
35907
|
}).catch(() => {});
|
|
35572
35908
|
}
|
|
35573
35909
|
}
|
|
35574
|
-
updateLspRow(headerWidth, summary) {
|
|
35575
|
-
if (this.agentRunning || !process.stdout.isTTY)
|
|
35576
|
-
return;
|
|
35577
|
-
if ((process.stdout.columns ?? 96) < headerWidth)
|
|
35578
|
-
return;
|
|
35579
|
-
const rowText = `${pc2.yellow(t("repl.lsp_label"))} ${summary.replace(/\s+/g, " ").trim()}`;
|
|
35580
|
-
if (stringWidth(rowText) > headerWidth)
|
|
35581
|
-
return;
|
|
35582
|
-
const line = pc2.dim(rowText);
|
|
35583
|
-
process.stdout.write(`\x1B[2A\r\x1B[2K${line}\x1B[2B\r`);
|
|
35584
|
-
}
|
|
35585
35910
|
async probeLspBanner() {
|
|
35586
35911
|
const config = this.config.lsp ?? DEFAULT_LSP_CONFIG;
|
|
35587
35912
|
try {
|
|
@@ -35653,9 +35978,9 @@ init_setup();
|
|
|
35653
35978
|
init_config2();
|
|
35654
35979
|
init_i18n();
|
|
35655
35980
|
init_colors();
|
|
35656
|
-
import { existsSync as
|
|
35657
|
-
import { join as
|
|
35658
|
-
import { homedir as
|
|
35981
|
+
import { existsSync as existsSync56 } from "fs";
|
|
35982
|
+
import { join as join51, dirname as dirname20 } from "path";
|
|
35983
|
+
import { homedir as homedir21 } from "os";
|
|
35659
35984
|
|
|
35660
35985
|
// src/modules/updater/index.ts
|
|
35661
35986
|
init_checker();
|
|
@@ -35758,10 +36083,10 @@ class UpdaterModule {
|
|
|
35758
36083
|
init_environment();
|
|
35759
36084
|
init_data_sanitizer();
|
|
35760
36085
|
init_i18n();
|
|
35761
|
-
import { appendFileSync as appendFileSync7, mkdirSync as
|
|
35762
|
-
import { join as
|
|
35763
|
-
import { homedir as
|
|
35764
|
-
var CRASH_LOG_DIR =
|
|
36086
|
+
import { appendFileSync as appendFileSync7, mkdirSync as mkdirSync21 } from "fs";
|
|
36087
|
+
import { join as join50 } from "path";
|
|
36088
|
+
import { homedir as homedir20 } from "os";
|
|
36089
|
+
var CRASH_LOG_DIR = join50(homedir20(), ".mma", "logs");
|
|
35765
36090
|
var CRASH_LOG_FILE = "crash.jsonl";
|
|
35766
36091
|
function formatCrashEntry(type2, err) {
|
|
35767
36092
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -35771,13 +36096,13 @@ function formatCrashEntry(type2, err) {
|
|
|
35771
36096
|
type: type2,
|
|
35772
36097
|
message: sanitizeLogMessage(message),
|
|
35773
36098
|
stack: sanitizeLogMessage(stack),
|
|
35774
|
-
environment: collectEnvironment({ configDir:
|
|
36099
|
+
environment: collectEnvironment({ configDir: homedir20(), scanTools: false })
|
|
35775
36100
|
};
|
|
35776
36101
|
}
|
|
35777
36102
|
function writeCrashEntry(dir, entry) {
|
|
35778
36103
|
try {
|
|
35779
|
-
|
|
35780
|
-
appendFileSync7(
|
|
36104
|
+
mkdirSync21(dir, { recursive: true });
|
|
36105
|
+
appendFileSync7(join50(dir, CRASH_LOG_FILE), JSON.stringify(entry) + `
|
|
35781
36106
|
`, "utf-8");
|
|
35782
36107
|
} catch {}
|
|
35783
36108
|
}
|
|
@@ -35835,7 +36160,10 @@ async function main() {
|
|
|
35835
36160
|
}
|
|
35836
36161
|
if (program2.args.length > 0) {
|
|
35837
36162
|
const prompt = program2.args.join(" ");
|
|
35838
|
-
const { agent, config, baseDir } = await bootstrap(undefined, projectDir, noAgentsMd, exitOnComplete);
|
|
36163
|
+
const { agent, config, baseDir, legacyDetected } = await bootstrap(undefined, projectDir, noAgentsMd, exitOnComplete);
|
|
36164
|
+
if (legacyDetected) {
|
|
36165
|
+
console.error(pc2.yellow(` ${t("config.legacy_hint")}`));
|
|
36166
|
+
}
|
|
35839
36167
|
const updater = exitOnComplete ? undefined : startAutoUpdate(config);
|
|
35840
36168
|
if (jsonMode) {
|
|
35841
36169
|
const result2 = await agent.run(prompt);
|
|
@@ -35882,31 +36210,48 @@ async function main() {
|
|
|
35882
36210
|
await updater?.waitForIdle();
|
|
35883
36211
|
process.exit(exitCode);
|
|
35884
36212
|
} else {
|
|
35885
|
-
const
|
|
35886
|
-
|
|
36213
|
+
const mmaDir = join51(homedir21(), ".mma");
|
|
36214
|
+
const legacyConfigPath = join51(mmaDir, "config.json");
|
|
36215
|
+
let hasAnyConfig = existsSync56(legacyConfigPath);
|
|
36216
|
+
if (!hasAnyConfig) {
|
|
36217
|
+
try {
|
|
36218
|
+
const { hasDomainFiles: hasDomainFiles3 } = await Promise.resolve().then(() => (init_domains(), exports_domains));
|
|
36219
|
+
hasAnyConfig = hasDomainFiles3(mmaDir);
|
|
36220
|
+
} catch {}
|
|
36221
|
+
}
|
|
36222
|
+
const {
|
|
36223
|
+
agent,
|
|
36224
|
+
config,
|
|
36225
|
+
sessionManager,
|
|
36226
|
+
skillsModule,
|
|
36227
|
+
pluginManager,
|
|
36228
|
+
execModule,
|
|
36229
|
+
configDir,
|
|
36230
|
+
baseDir,
|
|
36231
|
+
logger,
|
|
36232
|
+
envReport
|
|
36233
|
+
} = await bootstrap(undefined, projectDir, noAgentsMd, exitOnComplete);
|
|
36234
|
+
const repl = new Repl(agent, config, sessionManager, skillsModule, pluginManager, configDir, baseDir, noAgentsMd, logger, true, envReport, undefined, execModule);
|
|
36235
|
+
if (!hasAnyConfig) {
|
|
35887
36236
|
console.log(pc2.yellow(`
|
|
35888
36237
|
` + t("cli.first_run") + `
|
|
35889
36238
|
`));
|
|
35890
|
-
const answers = await runSetup();
|
|
35891
|
-
|
|
35892
|
-
|
|
35893
|
-
|
|
35894
|
-
|
|
35895
|
-
|
|
35896
|
-
|
|
35897
|
-
|
|
35898
|
-
|
|
35899
|
-
|
|
35900
|
-
|
|
35901
|
-
|
|
35902
|
-
if (config2.security) {
|
|
35903
|
-
config2.security.enabled = true;
|
|
35904
|
-
config2.security.bash.enabled = true;
|
|
35905
|
-
config2.security.bash.blockDangerousFlags = answers.securityFlagsBlock || config2.security.bash.blockDangerousFlags;
|
|
36239
|
+
const answers = await runSetup(repl.rl);
|
|
36240
|
+
config.provider.type = answers.provider;
|
|
36241
|
+
config.provider.baseUrl = answers.apiBase;
|
|
36242
|
+
config.provider.apiKey = answers.apiKey;
|
|
36243
|
+
config.model = answers.model;
|
|
36244
|
+
config.contextWindow = answers.contextWindow;
|
|
36245
|
+
config.maxToolIterations = answers.maxToolIterations;
|
|
36246
|
+
config.locale = answers.locale;
|
|
36247
|
+
if (config.security) {
|
|
36248
|
+
config.security.enabled = true;
|
|
36249
|
+
config.security.bash.enabled = true;
|
|
36250
|
+
config.security.bash.blockDangerousFlags = answers.securityFlagsBlock || config.security.bash.blockDangerousFlags;
|
|
35906
36251
|
if (answers.securityBashBlock) {
|
|
35907
|
-
|
|
36252
|
+
config.security.bash.blacklist = [
|
|
35908
36253
|
...new Set([
|
|
35909
|
-
...
|
|
36254
|
+
...config.security.bash.blacklist,
|
|
35910
36255
|
"rm",
|
|
35911
36256
|
"dd",
|
|
35912
36257
|
"chmod",
|
|
@@ -35927,25 +36272,13 @@ async function main() {
|
|
|
35927
36272
|
];
|
|
35928
36273
|
}
|
|
35929
36274
|
if (!answers.securityPathsDeny) {
|
|
35930
|
-
|
|
36275
|
+
config.security.paths.denied = [];
|
|
35931
36276
|
}
|
|
35932
36277
|
}
|
|
35933
|
-
saveConfig(
|
|
36278
|
+
saveConfig(config, legacyConfigPath, dirname20(legacyConfigPath));
|
|
36279
|
+
await agent.reconfigure(config);
|
|
35934
36280
|
}
|
|
35935
|
-
const {
|
|
35936
|
-
agent,
|
|
35937
|
-
config,
|
|
35938
|
-
sessionManager,
|
|
35939
|
-
skillsModule,
|
|
35940
|
-
pluginManager,
|
|
35941
|
-
execModule,
|
|
35942
|
-
configDir,
|
|
35943
|
-
baseDir,
|
|
35944
|
-
logger,
|
|
35945
|
-
envReport
|
|
35946
|
-
} = await bootstrap(undefined, projectDir, noAgentsMd, exitOnComplete);
|
|
35947
36281
|
startAutoUpdate(config);
|
|
35948
|
-
const repl = new Repl(agent, config, sessionManager, skillsModule, pluginManager, configDir, baseDir, noAgentsMd, logger, true, envReport, undefined, execModule);
|
|
35949
36282
|
await repl.start();
|
|
35950
36283
|
}
|
|
35951
36284
|
}
|