micro-models-agent 2.16.1 → 2.17.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/CHANGELOG.md +34 -0
- package/README.md +8 -3
- package/dist/assets/app.js +1 -314
- package/dist/assets/hljs.js +5 -1244
- package/dist/assets/index.html +11 -0
- package/dist/assets/js/api.js +1 -28
- package/dist/assets/js/core/menus.js +1 -0
- package/dist/assets/js/core/store/feed.js +1 -0
- package/dist/assets/js/core/store/index.js +1 -0
- package/dist/assets/js/core/store/session.js +1 -0
- package/dist/assets/js/core/store/settings.js +1 -0
- package/dist/assets/js/core/store/tabs.js +1 -0
- package/dist/assets/js/dialog.js +1 -105
- package/dist/assets/js/dom.js +1 -178
- package/dist/assets/js/feed/core.js +1 -0
- package/dist/assets/js/feed/history.js +1 -0
- package/dist/assets/js/feed/plan.js +1 -0
- package/dist/assets/js/feed/question.js +3 -0
- package/dist/assets/js/feed/sidebar.js +1 -0
- package/dist/assets/js/feed/stream.js +1 -0
- package/dist/assets/js/feed/turn.js +5 -0
- package/dist/assets/js/feed.js +1 -1250
- package/dist/assets/js/format.js +2 -122
- package/dist/assets/js/i18n.js +1 -46
- package/dist/assets/js/rail.js +1 -114
- package/dist/assets/js/session/cmdk.js +1 -0
- package/dist/assets/js/session/composer.js +1 -0
- package/dist/assets/js/session/sessions-menu.js +1 -0
- package/dist/assets/js/session/tabs.js +1 -0
- package/dist/assets/js/settings/controls.js +1 -0
- package/dist/assets/js/settings/editors.js +1 -0
- package/dist/assets/js/settings/form.js +1 -0
- package/dist/assets/js/settings/modal.js +1 -0
- package/dist/assets/js/settings/panels.js +1 -0
- package/dist/assets/js/settings/providers.js +1 -0
- package/dist/assets/js/settings/search.js +1 -0
- package/dist/assets/js/settings/subdialog.js +1 -0
- package/dist/assets/js/settings/write.js +1 -0
- package/dist/assets/js/settings.js +1 -1914
- package/dist/assets/js/sidebar/core.js +1 -0
- package/dist/assets/js/sidebar/lsp.js +2 -0
- package/dist/assets/js/sidebar/map.js +1 -0
- package/dist/assets/js/sidebar/state.js +1 -0
- package/dist/assets/js/sidebar/trace.js +5 -0
- package/dist/assets/js/sidebar.js +1 -705
- package/dist/assets/js/store.js +1 -82
- package/dist/assets/js/subdialog.js +1 -0
- package/dist/assets/md.js +1 -291
- package/dist/assets/setup.js +3 -816
- package/dist/assets/smd.js +29 -1665
- package/dist/assets/styles.css +1 -1598
- package/dist/certification/certifications.json +1 -494
- package/dist/i18n/en.json +1 -1851
- package/dist/i18n/ru.json +1 -1854
- package/dist/main.js +815 -55797
- package/dist/modules/browser/bridge-server.mjs +2 -252
- package/package.json +10 -5
- package/dist/assets/js/settings-controls.js +0 -452
- package/dist/assets/js/tabs.js +0 -867
- package/dist/cli/cache-line.js +0 -31
- package/dist/cli/command-suggest.js +0 -39
- package/dist/cli/commands.js +0 -781
- package/dist/cli/completer.js +0 -268
- package/dist/cli/index.js +0 -3
- package/dist/cli/json-payload.js +0 -32
- package/dist/cli/main.js +0 -346
- package/dist/cli/onboarding-commands.js +0 -126
- package/dist/cli/plugin-commands.js +0 -38
- package/dist/cli/relaunch.js +0 -40
- package/dist/cli/repl-commands-lsp.js +0 -75
- package/dist/cli/repl-commands-skills.js +0 -105
- package/dist/cli/repl-commands.js +0 -1218
- package/dist/cli/repl.js +0 -1238
- package/dist/cli/run-result.js +0 -38
- package/dist/cli/security-commands.js +0 -177
- package/dist/cli/setup-order.js +0 -6
- package/dist/cli/setup-prompt.js +0 -50
- package/dist/cli/setup.js +0 -161
- package/dist/cli/web-command.js +0 -98
- package/dist/config/budget.js +0 -48
- package/dist/config/config.js +0 -345
- package/dist/config/defaults.js +0 -197
- package/dist/config/domains.js +0 -135
- package/dist/config/env.js +0 -46
- package/dist/config/experts.js +0 -17
- package/dist/config/index.js +0 -5
- package/dist/config/paths.js +0 -56
- package/dist/config/redact.js +0 -44
- package/dist/config/registry-extra.js +0 -334
- package/dist/config/registry.js +0 -584
- package/dist/config/security.js +0 -212
- package/dist/config/timeouts.js +0 -74
- package/dist/config/types.js +0 -1
- package/dist/config/utils.js +0 -57
- package/dist/core/agent/artifact-progress.js +0 -59
- package/dist/core/agent/artifact-resolve.js +0 -79
- package/dist/core/agent/audit-gate.js +0 -53
- package/dist/core/agent/compaction.js +0 -89
- package/dist/core/agent/constants.js +0 -90
- package/dist/core/agent/context-log.js +0 -454
- package/dist/core/agent/context-renderer.js +0 -45
- package/dist/core/agent/critic-gate.js +0 -132
- package/dist/core/agent/hallucination-gate.js +0 -197
- package/dist/core/agent/loop-state.js +0 -68
- package/dist/core/agent/prefix-monitor.js +0 -101
- package/dist/core/agent/reasoning-resolver.js +0 -65
- package/dist/core/agent/token-tracker.js +0 -99
- package/dist/core/agent/tool-batch.js +0 -312
- package/dist/core/agent/tool-images.js +0 -18
- package/dist/core/agent/tool-output.js +0 -116
- package/dist/core/agent/tool-pairing.js +0 -60
- package/dist/core/agent-moe.js +0 -248
- package/dist/core/agent.js +0 -1299
- package/dist/core/bootstrap/agent-phase.js +0 -66
- package/dist/core/bootstrap/config-phase.js +0 -86
- package/dist/core/bootstrap/modules-phase.js +0 -269
- package/dist/core/bootstrap/provider-phase.js +0 -183
- package/dist/core/bootstrap/session-phase.js +0 -204
- package/dist/core/bootstrap/state.js +0 -94
- package/dist/core/bootstrap/workspace-phase.js +0 -115
- package/dist/core/bootstrap.js +0 -112
- package/dist/core/crash-handler.js +0 -62
- package/dist/core/environment.js +0 -224
- package/dist/core/host-plan.js +0 -43
- package/dist/core/host.js +0 -23
- package/dist/core/index.js +0 -3
- package/dist/core/prompt-builder.js +0 -95
- package/dist/core/prompt-overflow.js +0 -306
- package/dist/core/session-logger.js +0 -375
- package/dist/core/system-prompt.js +0 -117
- package/dist/core/types.js +0 -1
- package/dist/core/version.js +0 -28
- package/dist/core/web-host.js +0 -34
- package/dist/core/workspace.js +0 -80
- package/dist/i18n/index.js +0 -80
- package/dist/index.js +0 -30
- package/dist/llm/cache-usage.js +0 -76
- package/dist/llm/image-utils.js +0 -138
- package/dist/llm/index.js +0 -4
- package/dist/llm/llm-errors.js +0 -50
- package/dist/llm/model-loader.js +0 -86
- package/dist/llm/models-dev.js +0 -121
- package/dist/llm/openai-compat.js +0 -756
- package/dist/llm/orchestrator.js +0 -294
- package/dist/llm/provider-budget.js +0 -68
- package/dist/llm/provider-context.js +0 -233
- package/dist/llm/provider.js +0 -9
- package/dist/llm/response.js +0 -44
- package/dist/llm/stream-state.js +0 -26
- package/dist/llm/token-counter.js +0 -83
- package/dist/llm/types.js +0 -1
- package/dist/logger/app-logger.js +0 -212
- package/dist/logger/file-log.js +0 -160
- package/dist/logger/index.js +0 -2
- package/dist/migration/backup.js +0 -56
- package/dist/migration/detect.js +0 -61
- package/dist/migration/index.js +0 -3
- package/dist/modules/artifacts/store.js +0 -62
- package/dist/modules/browser/actions.js +0 -79
- package/dist/modules/browser/bridge-client.js +0 -203
- package/dist/modules/browser/bridge-path.js +0 -10
- package/dist/modules/browser/console-buffer.js +0 -37
- package/dist/modules/browser/cookie-store.js +0 -29
- package/dist/modules/browser/driver-types.js +0 -1
- package/dist/modules/browser/driver.js +0 -186
- package/dist/modules/browser/index.js +0 -9
- package/dist/modules/browser/module.js +0 -30
- package/dist/modules/browser/session.js +0 -322
- package/dist/modules/browser/snapshot.js +0 -154
- package/dist/modules/browser/types.js +0 -13
- package/dist/modules/certification/cli.js +0 -264
- package/dist/modules/certification/fact-checker.js +0 -90
- package/dist/modules/certification/loader.js +0 -127
- package/dist/modules/certification/manifest.js +0 -231
- package/dist/modules/certification/runner.js +0 -233
- package/dist/modules/certification/scenarios.js +0 -586
- package/dist/modules/certification/syntax-scenarios.js +0 -50
- package/dist/modules/certification/types.js +0 -1
- package/dist/modules/context/chunk-query.js +0 -122
- package/dist/modules/context/fact-extractor.js +0 -170
- package/dist/modules/context/history.js +0 -15
- package/dist/modules/context/index.js +0 -2
- package/dist/modules/context/manager.js +0 -482
- package/dist/modules/critic/client.js +0 -176
- package/dist/modules/critic/evidence.js +0 -81
- package/dist/modules/critic/provider.js +0 -45
- package/dist/modules/critic/tools.js +0 -78
- package/dist/modules/critic/types.js +0 -1
- package/dist/modules/execution/audit-runners.js +0 -206
- package/dist/modules/execution/auditor.js +0 -222
- package/dist/modules/execution/execution-plugin.js +0 -478
- package/dist/modules/execution/index.js +0 -8
- package/dist/modules/execution/input-from.js +0 -70
- package/dist/modules/execution/module.js +0 -891
- package/dist/modules/execution/moe-executor.js +0 -443
- package/dist/modules/execution/plan-actions.js +0 -642
- package/dist/modules/execution/plan-checks.js +0 -35
- package/dist/modules/execution/plan-coverage.js +0 -71
- package/dist/modules/execution/plan-persister.js +0 -46
- package/dist/modules/execution/plan-steps.js +0 -31
- package/dist/modules/execution/plan-store.js +0 -274
- package/dist/modules/execution/plan-tool.js +0 -249
- package/dist/modules/execution/plan-validator.js +0 -197
- package/dist/modules/execution/planner.js +0 -103
- package/dist/modules/execution/stuck-detector.js +0 -834
- package/dist/modules/execution/tracker.js +0 -92
- package/dist/modules/execution/transient-error.js +0 -30
- package/dist/modules/execution/types.js +0 -1
- package/dist/modules/execution/verifier.js +0 -343
- package/dist/modules/execution/windows-commands.js +0 -52
- package/dist/modules/hallucination/artifact-claim.js +0 -93
- package/dist/modules/hallucination/confidence.js +0 -81
- package/dist/modules/hallucination/consistency.js +0 -37
- package/dist/modules/hallucination/detector.js +0 -57
- package/dist/modules/hallucination/factual.js +0 -205
- package/dist/modules/hallucination/index.js +0 -6
- package/dist/modules/hallucination/js-identifiers.js +0 -261
- package/dist/modules/hallucination/llm-judge.js +0 -116
- package/dist/modules/hallucination/success-claim.js +0 -59
- package/dist/modules/index.js +0 -5
- package/dist/modules/indexer/cache.js +0 -88
- package/dist/modules/indexer/index.js +0 -4
- package/dist/modules/indexer/map-command.js +0 -33
- package/dist/modules/indexer/map-select.js +0 -87
- package/dist/modules/indexer/module.js +0 -293
- package/dist/modules/indexer/project-profile.js +0 -184
- package/dist/modules/indexer/symbols.js +0 -189
- package/dist/modules/indexer/walker.js +0 -285
- package/dist/modules/lsp/check-tool.js +0 -61
- package/dist/modules/lsp/client.js +0 -406
- package/dist/modules/lsp/command.js +0 -53
- package/dist/modules/lsp/config.js +0 -189
- package/dist/modules/lsp/index.js +0 -4
- package/dist/modules/lsp/module.js +0 -295
- package/dist/modules/lsp/probe.js +0 -86
- package/dist/modules/lsp/project-root.js +0 -69
- package/dist/modules/lsp/startup-check.js +0 -154
- package/dist/modules/lsp/types.js +0 -1
- package/dist/modules/mcp/client.js +0 -445
- package/dist/modules/mcp/index.js +0 -4
- package/dist/modules/mcp/module.js +0 -295
- package/dist/modules/mcp/registry.js +0 -20
- package/dist/modules/memory/index.js +0 -2
- package/dist/modules/memory/module.js +0 -101
- package/dist/modules/memory/search.js +0 -45
- package/dist/modules/memory/store.js +0 -107
- package/dist/modules/onboarding/init.js +0 -47
- package/dist/modules/onboarding/meet.js +0 -30
- package/dist/modules/onboarding/mode.js +0 -30
- package/dist/modules/onboarding/prompts.js +0 -43
- package/dist/modules/pipelines/engine.js +0 -70
- package/dist/modules/pipelines/index.js +0 -4
- package/dist/modules/pipelines/parser.js +0 -59
- package/dist/modules/pipelines/template.js +0 -18
- package/dist/modules/plugins/builtin/lint-on-write.js +0 -377
- package/dist/modules/plugins/builtin/notify.js +0 -11
- package/dist/modules/plugins/index.js +0 -2
- package/dist/modules/plugins/loader.js +0 -85
- package/dist/modules/plugins/manager.js +0 -244
- package/dist/modules/plugins/types.js +0 -1
- package/dist/modules/pricing/index.js +0 -70
- package/dist/modules/pricing/prices.js +0 -147
- package/dist/modules/processes/detect.js +0 -34
- package/dist/modules/processes/index.js +0 -4
- package/dist/modules/processes/kill-tree.js +0 -52
- package/dist/modules/processes/registry.js +0 -294
- package/dist/modules/processes/runner.js +0 -23
- package/dist/modules/providers/cache.js +0 -23
- package/dist/modules/providers/capabilities.js +0 -28
- package/dist/modules/providers/create.js +0 -21
- package/dist/modules/providers/factory.js +0 -28
- package/dist/modules/providers/fallback.js +0 -81
- package/dist/modules/providers/health.js +0 -47
- package/dist/modules/providers/index.js +0 -6
- package/dist/modules/providers/manager.js +0 -207
- package/dist/modules/providers/naming.js +0 -15
- package/dist/modules/providers/preflight.js +0 -71
- package/dist/modules/providers/presets.js +0 -232
- package/dist/modules/providers/registry.js +0 -27
- package/dist/modules/providers/types.js +0 -1
- package/dist/modules/reasoning/policy.js +0 -42
- package/dist/modules/reasoning/probe.js +0 -116
- package/dist/modules/registry.js +0 -48
- package/dist/modules/security/audit-log.js +0 -119
- package/dist/modules/security/audit-notifier.js +0 -267
- package/dist/modules/security/command-validator.js +0 -272
- package/dist/modules/security/content-scanner.js +0 -53
- package/dist/modules/security/data-sanitizer.js +0 -82
- package/dist/modules/security/encryption.js +0 -216
- package/dist/modules/security/index.js +0 -15
- package/dist/modules/security/network-validator.js +0 -236
- package/dist/modules/security/path-validator.js +0 -261
- package/dist/modules/security/protected-paths.js +0 -73
- package/dist/modules/security/rate-limiter.js +0 -98
- package/dist/modules/security/security-policies.js +0 -499
- package/dist/modules/security/session-encryption.js +0 -182
- package/dist/modules/security/session-isolation.js +0 -75
- package/dist/modules/session/auto-name.js +0 -63
- package/dist/modules/session/export.js +0 -98
- package/dist/modules/session/index.js +0 -4
- package/dist/modules/session/manager.js +0 -234
- package/dist/modules/session/module.js +0 -33
- package/dist/modules/session/store.js +0 -295
- package/dist/modules/session/types.js +0 -1
- package/dist/modules/setup/answers.js +0 -35
- package/dist/modules/setup/apply.js +0 -79
- package/dist/modules/setup/discovery.js +0 -72
- package/dist/modules/skills/index.js +0 -3
- package/dist/modules/skills/loader.js +0 -86
- package/dist/modules/skills/matcher.js +0 -27
- package/dist/modules/skills/module.js +0 -141
- package/dist/modules/types.js +0 -1
- package/dist/modules/updater/changelog-reader.js +0 -93
- package/dist/modules/updater/checker.js +0 -101
- package/dist/modules/updater/dev-detect.js +0 -18
- package/dist/modules/updater/index.js +0 -4
- package/dist/modules/updater/module.js +0 -129
- package/dist/modules/user-profile/compressor.js +0 -18
- package/dist/modules/user-profile/index.js +0 -2
- package/dist/modules/user-profile/profile.js +0 -77
- package/dist/modules/webui/answer-api.js +0 -29
- package/dist/modules/webui/assets.js +0 -50
- package/dist/modules/webui/body.js +0 -21
- package/dist/modules/webui/commands-settings.js +0 -209
- package/dist/modules/webui/commands-shared.js +0 -60
- package/dist/modules/webui/commands.js +0 -174
- package/dist/modules/webui/config-api.js +0 -134
- package/dist/modules/webui/file-api.js +0 -202
- package/dist/modules/webui/forward.js +0 -159
- package/dist/modules/webui/history-api.js +0 -112
- package/dist/modules/webui/host-state.js +0 -60
- package/dist/modules/webui/i18n-api.js +0 -9
- package/dist/modules/webui/limits.js +0 -6
- package/dist/modules/webui/log-forward.js +0 -20
- package/dist/modules/webui/memory-commands.js +0 -64
- package/dist/modules/webui/model-cache.js +0 -18
- package/dist/modules/webui/module.js +0 -148
- package/dist/modules/webui/persist.js +0 -24
- package/dist/modules/webui/prompt-io.js +0 -97
- package/dist/modules/webui/providers-api.js +0 -337
- package/dist/modules/webui/providers-view.js +0 -56
- package/dist/modules/webui/reasoning-view.js +0 -15
- package/dist/modules/webui/run-agent.js +0 -81
- package/dist/modules/webui/server.js +0 -284
- package/dist/modules/webui/sessions-api.js +0 -178
- package/dist/modules/webui/settings-api.js +0 -561
- package/dist/modules/webui/setup-api.js +0 -201
- package/dist/modules/webui/state.js +0 -74
- package/dist/modules/webui/util.js +0 -261
- package/dist/output/bus.js +0 -37
- package/dist/output/channel.js +0 -285
- package/dist/output/format.js +0 -15
- package/dist/output/index.js +0 -8
- package/dist/output/json-sink.js +0 -24
- package/dist/output/machine.js +0 -9
- package/dist/output/session-sink.js +0 -27
- package/dist/output/types.js +0 -1
- package/dist/tools/approve.js +0 -41
- package/dist/tools/attach-image.js +0 -102
- package/dist/tools/auto-fixer.js +0 -180
- package/dist/tools/auto-tags.js +0 -83
- package/dist/tools/bash.js +0 -649
- package/dist/tools/browser.js +0 -160
- package/dist/tools/chunk-query.js +0 -112
- package/dist/tools/create-dir.js +0 -60
- package/dist/tools/delete-file.js +0 -67
- package/dist/tools/download-file.js +0 -142
- package/dist/tools/edit-file.js +0 -136
- package/dist/tools/enable-tools.js +0 -59
- package/dist/tools/executor.js +0 -304
- package/dist/tools/file-info.js +0 -49
- package/dist/tools/filter-tools.js +0 -17
- package/dist/tools/glob-tool.js +0 -37
- package/dist/tools/grep-tool.js +0 -142
- package/dist/tools/hidden-tools-block.js +0 -37
- package/dist/tools/index.js +0 -88
- package/dist/tools/list-dir.js +0 -53
- package/dist/tools/load-skill.js +0 -51
- package/dist/tools/mcp-call.js +0 -80
- package/dist/tools/meet-done.js +0 -14
- package/dist/tools/move-file.js +0 -94
- package/dist/tools/path-utils.js +0 -108
- package/dist/tools/pipeline-run.js +0 -167
- package/dist/tools/preview.js +0 -2
- package/dist/tools/process-ids.js +0 -31
- package/dist/tools/process-kill.js +0 -33
- package/dist/tools/process-list.js +0 -38
- package/dist/tools/process-log.js +0 -49
- package/dist/tools/process-wait.js +0 -63
- package/dist/tools/prompt-io.js +0 -29
- package/dist/tools/question.js +0 -288
- package/dist/tools/read-file.js +0 -200
- package/dist/tools/recall.js +0 -124
- package/dist/tools/registry.js +0 -48
- package/dist/tools/remember.js +0 -72
- package/dist/tools/scope-check.js +0 -32
- package/dist/tools/scope-request.js +0 -96
- package/dist/tools/search-history.js +0 -88
- package/dist/tools/session-info.js +0 -46
- package/dist/tools/set-thinking.js +0 -75
- package/dist/tools/subagent.js +0 -257
- package/dist/tools/syntax-validator.js +0 -379
- package/dist/tools/types.js +0 -1
- package/dist/tools/user-input.js +0 -134
- package/dist/tools/web-browse.js +0 -93
- package/dist/tools/web-fetch.js +0 -108
- package/dist/tools/web-search.js +0 -107
- package/dist/tools/write-file.js +0 -128
- package/dist/ui/action-log.js +0 -13
- package/dist/ui/box.js +0 -78
- package/dist/ui/colors.js +0 -6
- package/dist/ui/diff.js +0 -189
- package/dist/ui/index.js +0 -7
- package/dist/ui/line-editor.js +0 -1083
- package/dist/ui/line-math.js +0 -98
- package/dist/ui/md-formatter.js +0 -322
- package/dist/ui/output.js +0 -19
- package/dist/ui/plan-view.js +0 -109
- package/dist/ui/renderer.js +0 -589
- package/dist/ui/spinner.js +0 -91
- package/dist/ui/table.js +0 -142
- package/dist/ui/theme.js +0 -143
- package/dist/utils/child-run.js +0 -20
- package/dist/utils/error.js +0 -4
- package/dist/utils/index.js +0 -6
- package/dist/utils/retry.js +0 -17
- package/dist/utils/sleep.js +0 -23
- package/dist/utils/truncate.js +0 -9
package/dist/cli/commands.js
DELETED
|
@@ -1,781 +0,0 @@
|
|
|
1
|
-
// Commander-программа: setup/meet/init/web/agents/config/session/* и фабрика createProgram.
|
|
2
|
-
import { Command } from "commander";
|
|
3
|
-
import { bootstrap } from "../core/bootstrap";
|
|
4
|
-
import { saveConfig } from "../config/config";
|
|
5
|
-
import { runSetup } from "./setup";
|
|
6
|
-
import { applyAnswersToConfig } from "./setup-order";
|
|
7
|
-
import { t } from "../i18n/index";
|
|
8
|
-
import { pc } from "../ui/colors";
|
|
9
|
-
import { join, dirname } from "path";
|
|
10
|
-
import { homedir } from "os";
|
|
11
|
-
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
12
|
-
import { formatExport, redactExport, sanitizeFileName, extensionFor, } from "../modules/session/export";
|
|
13
|
-
import { createSecurityCommand } from "./security-commands";
|
|
14
|
-
import { createPluginCommand } from "./plugin-commands";
|
|
15
|
-
import { HOSTED_BASE_URLS } from "../modules/providers/presets";
|
|
16
|
-
import { providerNameTaken } from "../modules/providers/naming";
|
|
17
|
-
import { probeProviders, targetsFromProviders } from "../modules/providers/health";
|
|
18
|
-
import { readMmaVersion } from "../core/version";
|
|
19
|
-
import { runMapAction } from "../modules/indexer/map-command";
|
|
20
|
-
import { budgetBreakdownLines, setBudgetShare } from "../config/budget";
|
|
21
|
-
import { fetchProviderBudget } from "../llm/provider-budget";
|
|
22
|
-
import { formatCost } from "../modules/pricing/prices";
|
|
23
|
-
import { readChangelog, extractLatestChangelog, extractChangelogRange, } from "../modules/updater/changelog-reader";
|
|
24
|
-
import { getDefaultChannel, writeMachineJson } from "../output";
|
|
25
|
-
import { setConfigValue } from "../config/registry";
|
|
26
|
-
import { redactConfigSecrets } from "../config/redact";
|
|
27
|
-
import { MMA_DIR_NAME, globalConfigFile, globalExportsDir } from "../config/paths";
|
|
28
|
-
const version = readMmaVersion();
|
|
29
|
-
/** Конфиг для `mma config show`: секреты затёрты, если явно не просили. */
|
|
30
|
-
export function configForDisplay(config, showSecrets) {
|
|
31
|
-
return showSecrets ? config : redactConfigSecrets(config);
|
|
32
|
-
}
|
|
33
|
-
/** Общее тело визарда настройки провайдера (`mma setup` и устаревший `mma init`). */
|
|
34
|
-
async function runWizardCommand() {
|
|
35
|
-
const answers = await runSetup();
|
|
36
|
-
const configPath = globalConfigFile();
|
|
37
|
-
const { config } = await bootstrap();
|
|
38
|
-
applyAnswersToConfig(config, answers);
|
|
39
|
-
saveConfig(config, configPath, dirname(configPath));
|
|
40
|
-
getDefaultChannel().writeLine(t("cli.config_saved"));
|
|
41
|
-
}
|
|
42
|
-
function buildSetupCommand(program) {
|
|
43
|
-
program.command("setup").description(t("cli.setup")).action(runWizardCommand);
|
|
44
|
-
}
|
|
45
|
-
function buildMeetCommand(program) {
|
|
46
|
-
program.command("meet").description(t("cli.meet")).action(() => { });
|
|
47
|
-
}
|
|
48
|
-
function buildInitCommand(program) {
|
|
49
|
-
program
|
|
50
|
-
.command("init")
|
|
51
|
-
.description(t("cli.init"))
|
|
52
|
-
.action(async () => {
|
|
53
|
-
getDefaultChannel().writeLine(pc.yellow(t("cli.init_deprecated")));
|
|
54
|
-
await runWizardCommand();
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
function buildWebCommand(program) {
|
|
58
|
-
program
|
|
59
|
-
.command("web")
|
|
60
|
-
.description(t("cli.web.description"))
|
|
61
|
-
.option("-p, --port <n>", t("cli.web.port"))
|
|
62
|
-
.option("--host <addr>", t("cli.web.host"))
|
|
63
|
-
.option("--token <t>", t("cli.web.token"))
|
|
64
|
-
.option("--no-open", t("cli.web.no_open"))
|
|
65
|
-
.action(() => {
|
|
66
|
-
/* Диспатчится из main.ts после program.parse(): веб-сервер долгоживущий,
|
|
67
|
-
хук one-shot выхода его резать не должен. */
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function buildAgentsCommand(program) {
|
|
71
|
-
const agents = program.command("agents").description(t("cli.agents"));
|
|
72
|
-
agents
|
|
73
|
-
.command("init")
|
|
74
|
-
.description(t("cli.agents_init"))
|
|
75
|
-
.action(() => { });
|
|
76
|
-
}
|
|
77
|
-
function buildConfigCommands(program) {
|
|
78
|
-
const configCmd = program.command("config").description(t("cli.manage_config"));
|
|
79
|
-
configCmd
|
|
80
|
-
.command("set")
|
|
81
|
-
.argument("<key>", t("cli.config_key"))
|
|
82
|
-
.argument("<value>", t("cli.config_value"))
|
|
83
|
-
.description(t("cli.set_value"))
|
|
84
|
-
.option("--force", t("cli.config_force"))
|
|
85
|
-
.action(async (key, value, opts) => {
|
|
86
|
-
const configPath = globalConfigFile();
|
|
87
|
-
const { config } = await bootstrap();
|
|
88
|
-
if (opts.force) {
|
|
89
|
-
const keys = key.split(".");
|
|
90
|
-
let obj = config;
|
|
91
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
92
|
-
if (!(keys[i] in obj))
|
|
93
|
-
obj[keys[i]] = {};
|
|
94
|
-
obj = obj[keys[i]];
|
|
95
|
-
}
|
|
96
|
-
const lastKey = keys[keys.length - 1];
|
|
97
|
-
if (value === "true")
|
|
98
|
-
obj[lastKey] = true;
|
|
99
|
-
else if (value === "false")
|
|
100
|
-
obj[lastKey] = false;
|
|
101
|
-
else if (/^\d+$/.test(value))
|
|
102
|
-
obj[lastKey] = parseInt(value, 10);
|
|
103
|
-
else if (/^\d+\.\d+$/.test(value))
|
|
104
|
-
obj[lastKey] = parseFloat(value);
|
|
105
|
-
else
|
|
106
|
-
obj[lastKey] = value;
|
|
107
|
-
saveConfig(config, configPath, dirname(configPath));
|
|
108
|
-
getDefaultChannel().writeLine(t("cli.set_done", { key, value }));
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const r = setConfigValue(config, key, value);
|
|
112
|
-
if (!r.ok) {
|
|
113
|
-
getDefaultChannel().writeLine(pc.yellow(t("cli.config_invalid", { key: r.input, reason: r.reason })), "stderr");
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
saveConfig(config, configPath, dirname(configPath));
|
|
117
|
-
getDefaultChannel().writeLine(t("cli.set_done", { key: r.key, value: r.display }));
|
|
118
|
-
});
|
|
119
|
-
configCmd
|
|
120
|
-
.command("show")
|
|
121
|
-
.description(t("cli.show_config"))
|
|
122
|
-
.option("--show-secrets", t("cli.show_secrets"))
|
|
123
|
-
.action(async (opts) => {
|
|
124
|
-
const { config } = await bootstrap();
|
|
125
|
-
writeMachineJson(configForDisplay(config, opts.showSecrets));
|
|
126
|
-
});
|
|
127
|
-
configCmd
|
|
128
|
-
.command("migrate")
|
|
129
|
-
.description(t("cli.migrate_config"))
|
|
130
|
-
.action(async () => {
|
|
131
|
-
const { loadConfig } = await import("../config/config");
|
|
132
|
-
const { hasDomainFiles } = await import("../config/domains");
|
|
133
|
-
const configDir = join(homedir(), MMA_DIR_NAME);
|
|
134
|
-
const configPath = join(configDir, "config.json");
|
|
135
|
-
if (hasDomainFiles(configDir)) {
|
|
136
|
-
getDefaultChannel().writeLine(pc.yellow(t("config.migrate_no_legacy")));
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if (!existsSync(configPath)) {
|
|
140
|
-
getDefaultChannel().writeLine(pc.yellow(t("config.migrate_no_legacy")));
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
getDefaultChannel().writeLine(t("config.migrate_start"));
|
|
144
|
-
const { config } = loadConfig({ configDir, projectConfigPath: join(configDir, ".mmrc") });
|
|
145
|
-
saveConfig(config, configPath, configDir);
|
|
146
|
-
// Переименование legacy-файла.
|
|
147
|
-
const bakPath = `${configPath}.bak`;
|
|
148
|
-
const { renameSync } = await import("fs");
|
|
149
|
-
renameSync(configPath, bakPath);
|
|
150
|
-
const { readdirSync } = await import("fs");
|
|
151
|
-
const domainFiles = readdirSync(join(configDir, "config")).filter((f) => f.endsWith(".json"));
|
|
152
|
-
getDefaultChannel().writeLine(pc.green(t("config.migrate_done", { count: String(domainFiles.length) })));
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
function buildModelCommands(program) {
|
|
156
|
-
const model = program.command("model").description(t("cli.manage_models"));
|
|
157
|
-
model
|
|
158
|
-
.command("list")
|
|
159
|
-
.description(t("cli.list_models"))
|
|
160
|
-
.action(async () => {
|
|
161
|
-
const { config } = await bootstrap();
|
|
162
|
-
getDefaultChannel().writeLine(`${t("cli.current_model")} ${config.model}`);
|
|
163
|
-
// Тянем доступные модели с провайдера.
|
|
164
|
-
const { createProvider } = await import("../modules/providers/create");
|
|
165
|
-
const { activeProviderEndpoint } = await import("../modules/providers/manager");
|
|
166
|
-
const endpoint = activeProviderEndpoint(config.provider);
|
|
167
|
-
const provider = createProvider(endpoint.type, {
|
|
168
|
-
model: config.model,
|
|
169
|
-
baseUrl: endpoint.baseUrl,
|
|
170
|
-
apiKey: endpoint.apiKey,
|
|
171
|
-
contextWindow: config.contextWindow,
|
|
172
|
-
});
|
|
173
|
-
const spinner = (await import("../ui/spinner")).Spinner;
|
|
174
|
-
const s = new spinner();
|
|
175
|
-
s.start(t("cli.fetching_models"));
|
|
176
|
-
try {
|
|
177
|
-
const models = await provider.listModels();
|
|
178
|
-
s.stop();
|
|
179
|
-
if (models.length > 0) {
|
|
180
|
-
getDefaultChannel().writeLine(t("cli.available_models"));
|
|
181
|
-
const { getCertMark } = await import("../modules/certification/manifest");
|
|
182
|
-
for (const m of models) {
|
|
183
|
-
const marker = m === config.model ? "* " : " ";
|
|
184
|
-
const mark = getCertMark(m, config.provider.baseUrl, version, process.cwd());
|
|
185
|
-
const cert = mark === "certified" ? "✔" : mark === "stale" ? "○" : "·";
|
|
186
|
-
const label = mark === "certified"
|
|
187
|
-
? ` ${pc.green(t("cli.cert_label"))}`
|
|
188
|
-
: mark === "stale"
|
|
189
|
-
? ` ${pc.yellow(t("cli.cert_stale_label"))}`
|
|
190
|
-
: "";
|
|
191
|
-
getDefaultChannel().writeLine(` ${marker}${cert} ${m}${label}`);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
getDefaultChannel().writeLine(t("cli.no_models_found"));
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
catch (err) {
|
|
199
|
-
s.stop();
|
|
200
|
-
getDefaultChannel().writeLine(t("cli.model_fetch_failed", { error: String(err) }));
|
|
201
|
-
}
|
|
202
|
-
getDefaultChannel().writeLine(t("cli.model_hint"));
|
|
203
|
-
});
|
|
204
|
-
model
|
|
205
|
-
.command("use")
|
|
206
|
-
.argument("<name>", t("cli.model_name"))
|
|
207
|
-
.description(t("cli.set_model"))
|
|
208
|
-
.action(async (name) => {
|
|
209
|
-
const configPath = globalConfigFile();
|
|
210
|
-
const { config } = await bootstrap();
|
|
211
|
-
config.model = name;
|
|
212
|
-
saveConfig(config, configPath, dirname(configPath));
|
|
213
|
-
getDefaultChannel().writeLine(t("cli.model_set", { name }));
|
|
214
|
-
});
|
|
215
|
-
model
|
|
216
|
-
.command("certify")
|
|
217
|
-
.argument("<name>", t("cli.model_name"))
|
|
218
|
-
.option("--provider-url <url>", t("cli.cert_provider_url"))
|
|
219
|
-
.option("--provider-key <key>", t("cli.cert_provider_key"))
|
|
220
|
-
.option("--context-window <n>", t("cli.cert_context_window"))
|
|
221
|
-
.option("--tags <tags>", t("cli.cert_tags"), "core")
|
|
222
|
-
.option("--scenarios <ids>", t("cli.cert_scenarios"))
|
|
223
|
-
.option("--timeout <ms>", t("cli.cert_timeout"))
|
|
224
|
-
.option("--reps <n>", t("cli.cert_reps"))
|
|
225
|
-
.option("--force", t("cli.cert_force"))
|
|
226
|
-
.option("--clean", t("cli.cert_clean"))
|
|
227
|
-
.description(t("cli.certify"))
|
|
228
|
-
.action(async (name, cmdOpts) => {
|
|
229
|
-
const { config } = await bootstrap();
|
|
230
|
-
const { certify, parseTags } = await import("../modules/certification/cli");
|
|
231
|
-
await certify({
|
|
232
|
-
name,
|
|
233
|
-
providerUrl: cmdOpts.providerUrl,
|
|
234
|
-
providerKey: cmdOpts.providerKey,
|
|
235
|
-
contextWindow: cmdOpts.contextWindow ? parseInt(cmdOpts.contextWindow, 10) : undefined,
|
|
236
|
-
tags: parseTags(cmdOpts.tags),
|
|
237
|
-
scenarios: cmdOpts.scenarios
|
|
238
|
-
? String(cmdOpts.scenarios)
|
|
239
|
-
.split(",")
|
|
240
|
-
.map((x) => x.trim())
|
|
241
|
-
.filter(Boolean)
|
|
242
|
-
: undefined,
|
|
243
|
-
reps: cmdOpts.reps ? parseInt(cmdOpts.reps, 10) : 3,
|
|
244
|
-
timeout: cmdOpts.timeout ? parseInt(cmdOpts.timeout, 10) : undefined,
|
|
245
|
-
force: cmdOpts.force === true,
|
|
246
|
-
clean: cmdOpts.clean === true,
|
|
247
|
-
config,
|
|
248
|
-
projectDir: process.cwd(),
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
model
|
|
252
|
-
.command("cert-status")
|
|
253
|
-
.argument("<name>", t("cli.model_name"))
|
|
254
|
-
.description(t("cli.cert_status"))
|
|
255
|
-
.action(async (name) => {
|
|
256
|
-
const { config } = await bootstrap();
|
|
257
|
-
const { certStatus } = await import("../modules/certification/cli");
|
|
258
|
-
await certStatus(name, config, process.cwd());
|
|
259
|
-
});
|
|
260
|
-
model
|
|
261
|
-
.command("cert-list")
|
|
262
|
-
.description(t("cli.cert_list"))
|
|
263
|
-
.action(async () => {
|
|
264
|
-
const { certList } = await import("../modules/certification/cli");
|
|
265
|
-
await certList(process.cwd());
|
|
266
|
-
});
|
|
267
|
-
model
|
|
268
|
-
.command("uncertify")
|
|
269
|
-
.argument("<name>", t("cli.model_name"))
|
|
270
|
-
.description(t("cli.cert_uncertify"))
|
|
271
|
-
.action(async (name) => {
|
|
272
|
-
const { config } = await bootstrap();
|
|
273
|
-
const { uncertify } = await import("../modules/certification/cli");
|
|
274
|
-
await uncertify(name, config, process.cwd());
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
function buildContextCommand(program) {
|
|
278
|
-
program
|
|
279
|
-
.command("context")
|
|
280
|
-
.description(t("cli.manage_context"))
|
|
281
|
-
.argument("[size]", t("cli.context_size_arg"))
|
|
282
|
-
.option("--system <fraction>", t("cli.context_system_fraction"))
|
|
283
|
-
.option("--reserve <fraction>", t("cli.context_reserve_fraction"))
|
|
284
|
-
.action(async (size, opts) => {
|
|
285
|
-
const { config, configDir } = await bootstrap();
|
|
286
|
-
const configPath = join(configDir, "config.json");
|
|
287
|
-
if (opts.system !== undefined || opts.reserve !== undefined) {
|
|
288
|
-
const key = opts.system !== undefined ? "system" : "reserve";
|
|
289
|
-
const value = Number(opts.system ?? opts.reserve);
|
|
290
|
-
if (setBudgetShare(config, key, value) !== null) {
|
|
291
|
-
getDefaultChannel().writeLine(t("cli.context_invalid_fraction"));
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
saveConfig(config, configPath, dirname(configPath));
|
|
295
|
-
getDefaultChannel().writeLine(t("cli.context_fraction_set", { key, value }));
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
if (size === undefined) {
|
|
299
|
-
for (const line of budgetBreakdownLines(config))
|
|
300
|
-
getDefaultChannel().writeLine(line);
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
const contextWindow = parseInt(size, 10);
|
|
304
|
-
if (Number.isNaN(contextWindow) || contextWindow < 1024) {
|
|
305
|
-
getDefaultChannel().writeLine(t("cli.invalid_context_size"));
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
config.contextWindow = contextWindow;
|
|
309
|
-
saveConfig(config, configPath, dirname(configPath));
|
|
310
|
-
getDefaultChannel().writeLine(t("cli.context_set", { size: contextWindow }));
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
function buildUsageCommand(program) {
|
|
314
|
-
program
|
|
315
|
-
.command("usage")
|
|
316
|
-
.description(t("cli.usage"))
|
|
317
|
-
.action(async () => {
|
|
318
|
-
const { config, logger } = await bootstrap();
|
|
319
|
-
const { type: provider, baseUrl, apiKey } = config.provider;
|
|
320
|
-
const result = await fetchProviderBudget(provider, baseUrl, apiKey, {
|
|
321
|
-
log: (level, message) => (level === "warn" ? logger.warn(message) : logger.debug(message)),
|
|
322
|
-
});
|
|
323
|
-
if (result.reason === "unsupported") {
|
|
324
|
-
getDefaultChannel().writeLine(t("cli.usage_unsupported", { provider }));
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
if (result.reason === "no-key") {
|
|
328
|
-
getDefaultChannel().writeLine(t("cli.usage_no_key"));
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
if (result.reason === "error" || !result.budget) {
|
|
332
|
-
getDefaultChannel().writeLine(t("cli.usage_error", { error: result.error ?? "" }));
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
const b = result.budget;
|
|
336
|
-
let printed = false;
|
|
337
|
-
if (b.keyUsageUsd !== undefined) {
|
|
338
|
-
getDefaultChannel().writeLine(t("cli.usage_key_usage", { usage: formatCost(b.keyUsageUsd) }));
|
|
339
|
-
printed = true;
|
|
340
|
-
}
|
|
341
|
-
if (b.keyLimitUsd !== undefined && b.keyRemainingUsd !== undefined) {
|
|
342
|
-
getDefaultChannel().writeLine(t("cli.usage_key_limit", {
|
|
343
|
-
limit: formatCost(b.keyLimitUsd),
|
|
344
|
-
remaining: formatCost(b.keyRemainingUsd),
|
|
345
|
-
}));
|
|
346
|
-
printed = true;
|
|
347
|
-
}
|
|
348
|
-
if (b.balanceUsd !== undefined) {
|
|
349
|
-
getDefaultChannel().writeLine(t("cli.usage_balance", { balance: formatCost(b.balanceUsd) }));
|
|
350
|
-
printed = true;
|
|
351
|
-
}
|
|
352
|
-
if (b.totalCreditsUsd !== undefined && b.totalUsageUsd !== undefined) {
|
|
353
|
-
getDefaultChannel().writeLine(t("cli.usage_account", {
|
|
354
|
-
credits: formatCost(b.totalCreditsUsd),
|
|
355
|
-
used: formatCost(b.totalUsageUsd),
|
|
356
|
-
}));
|
|
357
|
-
printed = true;
|
|
358
|
-
}
|
|
359
|
-
if (!printed)
|
|
360
|
-
getDefaultChannel().writeLine(t("cli.usage_empty"));
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
function buildMapCommand(program) {
|
|
364
|
-
program
|
|
365
|
-
.command("map")
|
|
366
|
-
.description(t("cli.map.description"))
|
|
367
|
-
.argument("[action]", t("cli.map.action"), "summary")
|
|
368
|
-
.argument("[query]", t("cli.map.query"))
|
|
369
|
-
.action(async (action, query) => {
|
|
370
|
-
const { agent } = await bootstrap();
|
|
371
|
-
const indexer = agent.getModule("indexer");
|
|
372
|
-
if (!indexer) {
|
|
373
|
-
getDefaultChannel().writeLine(t("indexer.not_indexed"));
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
const result = await runMapAction(indexer, action, query);
|
|
377
|
-
getDefaultChannel().writeLine(result.output);
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
function buildProviderCommands(program) {
|
|
381
|
-
const provider = program.command("provider").description(t("cli.manage_providers"));
|
|
382
|
-
provider
|
|
383
|
-
.command("check")
|
|
384
|
-
.description(t("cli.provider_check"))
|
|
385
|
-
.option("--timeout <ms>", t("cli.probe_timeout"))
|
|
386
|
-
.action(async (opts) => {
|
|
387
|
-
const { config, agent } = await bootstrap();
|
|
388
|
-
const providers = agent.listProviders();
|
|
389
|
-
const targets = targetsFromProviders(providers.length > 0
|
|
390
|
-
? providers
|
|
391
|
-
.map((p) => ({ name: p.label, provider: agent.getProviderFor(p.label) }))
|
|
392
|
-
.filter((x) => Boolean(x.provider))
|
|
393
|
-
: [
|
|
394
|
-
{
|
|
395
|
-
name: config.provider.type,
|
|
396
|
-
provider: agent.getProviderFor(config.provider.active || config.provider.type),
|
|
397
|
-
},
|
|
398
|
-
].filter((x) => Boolean(x.provider)));
|
|
399
|
-
const results = await probeProviders(targets, {
|
|
400
|
-
timeoutMs: opts.timeout ? Number(opts.timeout) : 5000,
|
|
401
|
-
});
|
|
402
|
-
for (const r of results) {
|
|
403
|
-
const mark = r.ok ? pc.green("✓") : pc.red("✗");
|
|
404
|
-
const detail = r.ok ? pc.dim(`${r.ms}ms, ${r.models} models`) : pc.red(r.error ?? "failed");
|
|
405
|
-
getDefaultChannel().writeLine(` ${mark} ${r.name.padEnd(16)} ${detail}`);
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
provider
|
|
409
|
-
.command("list")
|
|
410
|
-
.description(t("cli.list_providers"))
|
|
411
|
-
.action(async () => {
|
|
412
|
-
const { config, agent } = await bootstrap();
|
|
413
|
-
const providers = agent.listProviders();
|
|
414
|
-
if (providers.length > 0) {
|
|
415
|
-
getDefaultChannel().writeLine(t("cli.current_provider"));
|
|
416
|
-
for (const p of providers) {
|
|
417
|
-
const marker = p.active ? pc.green("* ") : " ";
|
|
418
|
-
const prio = p.priority !== undefined ? ` ${pc.dim(`prio=${p.priority}`)}` : "";
|
|
419
|
-
getDefaultChannel().writeLine(` ${marker}${p.label} (${pc.dim(p.type)}) ${pc.dim(p.baseUrl)}${prio}`);
|
|
420
|
-
}
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
getDefaultChannel().writeLine(`${t("cli.current_provider")} ${config.provider.type}`);
|
|
424
|
-
getDefaultChannel().writeLine(`${t("cli.base_url")} ${config.provider.baseUrl}`);
|
|
425
|
-
});
|
|
426
|
-
provider
|
|
427
|
-
.command("use")
|
|
428
|
-
.argument("<name>", t("cli.provider_name"))
|
|
429
|
-
.description(t("cli.set_provider"))
|
|
430
|
-
.action(async (name) => {
|
|
431
|
-
const configPath = globalConfigFile();
|
|
432
|
-
const { config, agent } = await bootstrap();
|
|
433
|
-
if (config.provider.entries && config.provider.entries.length > 0) {
|
|
434
|
-
try {
|
|
435
|
-
await agent.setProvider(name);
|
|
436
|
-
// Персист: `agent.setProvider` мутит только in-memory конфиг, так что свитч
|
|
437
|
-
// молча терялся на выходе для мульти-записных конфигов.
|
|
438
|
-
saveConfig(config, configPath, dirname(configPath));
|
|
439
|
-
getDefaultChannel().writeLine(t("cli.provider_set", { name }));
|
|
440
|
-
}
|
|
441
|
-
catch (e) {
|
|
442
|
-
getDefaultChannel().writeLine(pc.red(e.message));
|
|
443
|
-
}
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
config.provider.type = name;
|
|
447
|
-
const baseUrl = HOSTED_BASE_URLS[name];
|
|
448
|
-
if (baseUrl) {
|
|
449
|
-
config.provider.baseUrl = baseUrl;
|
|
450
|
-
}
|
|
451
|
-
saveConfig(config, configPath, dirname(configPath));
|
|
452
|
-
getDefaultChannel().writeLine(t("cli.provider_set", { name }));
|
|
453
|
-
if (baseUrl) {
|
|
454
|
-
getDefaultChannel().writeLine(t("cli.provider_base_hint", { baseUrl }));
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
provider
|
|
458
|
-
.command("add")
|
|
459
|
-
.argument("<name>", t("cli.provider_type_label"))
|
|
460
|
-
.option("--url <url>", t("cli.provider_base_url"))
|
|
461
|
-
.option("--key <key>", t("cli.provider_api_key"))
|
|
462
|
-
.option("--priority <n>", t("cli.provider_priority"))
|
|
463
|
-
.option("--context-window <n>", t("cli.provider_context_window"))
|
|
464
|
-
.option("--rpm <n>", t("cli.provider_rpm"))
|
|
465
|
-
.option("--parallel <n>", t("cli.provider_parallel"))
|
|
466
|
-
.description(t("cli.add_provider"))
|
|
467
|
-
.action(async (name, opts) => {
|
|
468
|
-
const configPath = globalConfigFile();
|
|
469
|
-
const { config } = await bootstrap();
|
|
470
|
-
const entries = Array.isArray(config.provider.entries) ? config.provider.entries : [];
|
|
471
|
-
// Есть legacy-одиночка — сидим список сначала с него.
|
|
472
|
-
if (entries.length === 0) {
|
|
473
|
-
entries.push({
|
|
474
|
-
type: config.provider.type,
|
|
475
|
-
label: config.provider.type,
|
|
476
|
-
baseUrl: config.provider.baseUrl,
|
|
477
|
-
apiKey: config.provider.apiKey,
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
const baseUrl = opts.url || HOSTED_BASE_URLS[name] || HOSTED_BASE_URLS[`opencode-${name}`] || "";
|
|
481
|
-
if (!baseUrl) {
|
|
482
|
-
getDefaultChannel().writeLine(pc.red(t("cli.provider_no_url", { name })));
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
if (providerNameTaken(entries, name)) {
|
|
486
|
-
getDefaultChannel().writeLine(pc.red(t("cli.provider_name_conflict", { name })));
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
entries.push({
|
|
490
|
-
type: name,
|
|
491
|
-
label: name,
|
|
492
|
-
baseUrl,
|
|
493
|
-
apiKey: opts.key,
|
|
494
|
-
...(opts.priority !== undefined ? { priority: Number(opts.priority) } : {}),
|
|
495
|
-
...(opts.contextWindow !== undefined
|
|
496
|
-
? { contextWindow: Number(opts.contextWindow) }
|
|
497
|
-
: {}),
|
|
498
|
-
...(opts.rpm !== undefined || opts.parallel !== undefined
|
|
499
|
-
? {
|
|
500
|
-
rateLimits: {
|
|
501
|
-
maxRequestsPerMinute: Number(opts.rpm ?? 0) || 60,
|
|
502
|
-
maxParallelTasks: Number(opts.parallel ?? 0) || 1,
|
|
503
|
-
},
|
|
504
|
-
}
|
|
505
|
-
: {}),
|
|
506
|
-
});
|
|
507
|
-
config.provider.entries = entries;
|
|
508
|
-
config.provider.active = config.provider.active || config.provider.type;
|
|
509
|
-
saveConfig(config, configPath, dirname(configPath));
|
|
510
|
-
getDefaultChannel().writeLine(pc.green(t("cli.provider_added", { name })));
|
|
511
|
-
getDefaultChannel().writeLine(t("cli.provider_switch_hint"));
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
function buildSessionCommands(program) {
|
|
515
|
-
const session = program.command("session").description(t("cli.manage_sessions"));
|
|
516
|
-
session
|
|
517
|
-
.command("list")
|
|
518
|
-
.description(t("cli.list_sessions"))
|
|
519
|
-
.action(async () => {
|
|
520
|
-
const { sessionManager } = await bootstrap();
|
|
521
|
-
const sessions = sessionManager.list();
|
|
522
|
-
if (sessions.length === 0) {
|
|
523
|
-
getDefaultChannel().writeLine(t("session.no_sessions"));
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
const active = sessionManager.getActive();
|
|
527
|
-
for (const s of sessions) {
|
|
528
|
-
const marker = s.id === active ? "*" : " ";
|
|
529
|
-
getDefaultChannel().writeLine(` ${marker} ${s.id.slice(0, 12)} ${s.name} ${s.messageCount} ${t("repl.msgs")} ${s.updatedAt.slice(0, 10)}`);
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
session
|
|
533
|
-
.command("show")
|
|
534
|
-
.argument("<id>", t("cli.session_id"))
|
|
535
|
-
.description(t("cli.show_details"))
|
|
536
|
-
.action(async (id) => {
|
|
537
|
-
const { sessionManager } = await bootstrap();
|
|
538
|
-
const meta = sessionManager.get(id);
|
|
539
|
-
if (!meta) {
|
|
540
|
-
getDefaultChannel().writeLine(t("session.not_found", { id }));
|
|
541
|
-
return;
|
|
542
|
-
}
|
|
543
|
-
getDefaultChannel().writeLine(`${t("cli.session_field_id")} ${meta.id}`);
|
|
544
|
-
getDefaultChannel().writeLine(`${t("cli.session_field_name")} ${meta.name}`);
|
|
545
|
-
getDefaultChannel().writeLine(`${t("cli.session_field_created")} ${meta.createdAt}`);
|
|
546
|
-
getDefaultChannel().writeLine(`${t("cli.session_field_updated")} ${meta.updatedAt}`);
|
|
547
|
-
getDefaultChannel().writeLine(`${t("cli.session_field_messages")} ${meta.messageCount}`);
|
|
548
|
-
getDefaultChannel().writeLine(`${t("cli.session_field_model")} ${meta.model}`);
|
|
549
|
-
getDefaultChannel().writeLine(`${t("cli.session_field_context")} ${meta.contextWindow}`);
|
|
550
|
-
getDefaultChannel().writeLine(`${t("cli.session_field_project")} ${meta.projectDir}`);
|
|
551
|
-
const moeEvents = sessionManager.loadSessionLog(id).filter((e) => e.type.startsWith("moe_"));
|
|
552
|
-
if (moeEvents.length > 0) {
|
|
553
|
-
getDefaultChannel().writeLine("");
|
|
554
|
-
getDefaultChannel().writeLine(pc.cyan(t("cli.session_moe_events")));
|
|
555
|
-
for (const e of moeEvents) {
|
|
556
|
-
const ts = e.ts.slice(11, 19);
|
|
557
|
-
if (e.type === "moe_subtask") {
|
|
558
|
-
getDefaultChannel().writeLine(` ${pc.dim(ts)} [subtask] ${e.subtaskId} (${e.expertTag}) ${e.status ?? ""}${e.durationMs !== undefined ? ` ${e.durationMs}ms` : ""}`);
|
|
559
|
-
}
|
|
560
|
-
else if (e.type === "moe_plan") {
|
|
561
|
-
getDefaultChannel().writeLine(` ${pc.dim(ts)} [plan] ${e.status === "ok" ? e.subtaskIds?.join(", ") : e.status}`);
|
|
562
|
-
}
|
|
563
|
-
else if (e.type === "moe_replan") {
|
|
564
|
-
getDefaultChannel().writeLine(` ${pc.dim(ts)} [replan] cycle ${e.cycle}: ${e.subtaskIds?.join(", ")}`);
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
const usage = e.usageByTag
|
|
568
|
-
? " | usage: " +
|
|
569
|
-
Object.entries(e.usageByTag)
|
|
570
|
-
.map(([tag, u]) => `${tag}=${u.totalTokens}t`)
|
|
571
|
-
.join(", ")
|
|
572
|
-
: "";
|
|
573
|
-
getDefaultChannel().writeLine(` ${pc.dim(ts)} [verify] ${e.decision ?? e.status ?? "?"}${e.explanation ? ` — ${e.explanation}` : ""}${usage}`);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
const usageEvents = sessionManager.loadSessionLog(id).filter((e) => e.type === "llm_usage");
|
|
578
|
-
if (usageEvents.length > 0) {
|
|
579
|
-
let prompt = 0;
|
|
580
|
-
let completion = 0;
|
|
581
|
-
let cached = 0;
|
|
582
|
-
for (const e of usageEvents) {
|
|
583
|
-
prompt += e.promptTokens ?? 0;
|
|
584
|
-
completion += e.completionTokens ?? 0;
|
|
585
|
-
cached += e.cachedTokens ?? 0;
|
|
586
|
-
}
|
|
587
|
-
getDefaultChannel().writeLine("");
|
|
588
|
-
getDefaultChannel().writeLine(pc.cyan(t("cli.session_usage", {
|
|
589
|
-
prompt,
|
|
590
|
-
completion,
|
|
591
|
-
total: prompt + completion,
|
|
592
|
-
})));
|
|
593
|
-
if (cached > 0 && prompt > 0) {
|
|
594
|
-
const hit = Math.round((cached / prompt) * 100);
|
|
595
|
-
getDefaultChannel().writeLine(pc.dim(t("cli.session_cache", {
|
|
596
|
-
hit,
|
|
597
|
-
cached,
|
|
598
|
-
uncached: Math.max(0, prompt - cached),
|
|
599
|
-
})));
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
});
|
|
603
|
-
session
|
|
604
|
-
.command("export")
|
|
605
|
-
.argument("<id>", t("cli.session_id_or_prefix"))
|
|
606
|
-
.description(t("cli.export_session"))
|
|
607
|
-
.option("--format <format>", t("cli.export_format"), "md")
|
|
608
|
-
.option("--out <path>", t("cli.export_out"))
|
|
609
|
-
.option("--no-redact", t("cli.export_no_redact"))
|
|
610
|
-
.option("--compact", t("cli.export_compact"))
|
|
611
|
-
.action(async (id, opts) => {
|
|
612
|
-
const { sessionManager } = await bootstrap();
|
|
613
|
-
const meta = sessionManager.get(id) ??
|
|
614
|
-
sessionManager.list().find((s) => s.id.startsWith(id)) ??
|
|
615
|
-
sessionManager.list().find((s) => s.name.toLowerCase().includes(id.toLowerCase()));
|
|
616
|
-
if (!meta) {
|
|
617
|
-
getDefaultChannel().writeLine(t("session.not_found", { id }));
|
|
618
|
-
return;
|
|
619
|
-
}
|
|
620
|
-
const format = opts.format;
|
|
621
|
-
if (format !== "md" && format !== "json" && format !== "jsonl") {
|
|
622
|
-
getDefaultChannel().writeLine(t("export.invalid_format", { format }));
|
|
623
|
-
return;
|
|
624
|
-
}
|
|
625
|
-
const messages = sessionManager.getHistory(meta.id);
|
|
626
|
-
const log = sessionManager.loadSessionLog(meta.id);
|
|
627
|
-
if (format === "jsonl" ? log.length === 0 : messages.length === 0) {
|
|
628
|
-
getDefaultChannel().writeLine(t("export.empty"));
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
const text = redactExport(formatExport({ meta, messages, log }, format, { compact: opts.compact }), opts.redact);
|
|
632
|
-
if (opts.out === "-") {
|
|
633
|
-
getDefaultChannel().writeLine(text);
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
const baseDir = opts.out ? dirname(opts.out) : globalExportsDir();
|
|
637
|
-
const path = opts.out ??
|
|
638
|
-
join(baseDir, `${sanitizeFileName(meta.name)}-${meta.id.slice(0, 8)}.${extensionFor(format)}`);
|
|
639
|
-
try {
|
|
640
|
-
mkdirSync(baseDir, { recursive: true });
|
|
641
|
-
writeFileSync(path, text, "utf-8");
|
|
642
|
-
}
|
|
643
|
-
catch (e) {
|
|
644
|
-
getDefaultChannel().writeLine(t("export.write_failed", { error: String(e) }));
|
|
645
|
-
return;
|
|
646
|
-
}
|
|
647
|
-
getDefaultChannel().writeLine(t("export.written", { path }));
|
|
648
|
-
getDefaultChannel().writeLine(t(opts.redact ? "export.redacted" : "export.raw"));
|
|
649
|
-
});
|
|
650
|
-
session
|
|
651
|
-
.command("delete")
|
|
652
|
-
.argument("<id>", t("cli.session_id"))
|
|
653
|
-
.description(t("cli.delete_session"))
|
|
654
|
-
.action(async (id) => {
|
|
655
|
-
const { sessionManager } = await bootstrap();
|
|
656
|
-
sessionManager.delete(id);
|
|
657
|
-
getDefaultChannel().writeLine(t("session.deleted", { id }));
|
|
658
|
-
});
|
|
659
|
-
session
|
|
660
|
-
.command("prune")
|
|
661
|
-
.description(t("cli.prune_sessions"))
|
|
662
|
-
.option("--dry-run", t("cli.prune_dry_run"))
|
|
663
|
-
.action(async (opts) => {
|
|
664
|
-
const { sessionManager } = await bootstrap();
|
|
665
|
-
const active = sessionManager.getActive();
|
|
666
|
-
const candidates = sessionManager
|
|
667
|
-
.list()
|
|
668
|
-
.filter((s) => s.id !== active && sessionManager.isEmptySession(s.id));
|
|
669
|
-
if (candidates.length === 0) {
|
|
670
|
-
getDefaultChannel().writeLine(t("session.prune_empty"));
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
if (opts.dryRun) {
|
|
674
|
-
getDefaultChannel().writeLine(t("session.prune_dry", { n: candidates.length }));
|
|
675
|
-
}
|
|
676
|
-
else {
|
|
677
|
-
const deleted = sessionManager.pruneEmpty(active ?? undefined);
|
|
678
|
-
getDefaultChannel().writeLine(t("session.pruned", { n: deleted.length }));
|
|
679
|
-
}
|
|
680
|
-
for (const s of candidates) {
|
|
681
|
-
getDefaultChannel().writeLine(` ${s.id.slice(0, 12)} ${s.name}`);
|
|
682
|
-
}
|
|
683
|
-
});
|
|
684
|
-
}
|
|
685
|
-
function buildChangelogCommand(program) {
|
|
686
|
-
program
|
|
687
|
-
.command("changelog")
|
|
688
|
-
.description(t("cli.changelog_title", { version }))
|
|
689
|
-
.option("--from <version>", t("cli.changelog_range", { from: "..." }))
|
|
690
|
-
.action((opts) => {
|
|
691
|
-
const changelog = readChangelog("micro-models-agent");
|
|
692
|
-
if (!changelog) {
|
|
693
|
-
getDefaultChannel().writeLine(pc.yellow(t("cli.changelog_not_found")));
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
|
-
if (opts.from) {
|
|
697
|
-
const range = extractChangelogRange(changelog, opts.from, version);
|
|
698
|
-
if (!range) {
|
|
699
|
-
getDefaultChannel().writeLine(pc.yellow(t("cli.changelog_not_found")));
|
|
700
|
-
return;
|
|
701
|
-
}
|
|
702
|
-
getDefaultChannel().writeLine(pc.cyan(t("cli.changelog_range", { from: opts.from })));
|
|
703
|
-
getDefaultChannel().writeLine(range);
|
|
704
|
-
}
|
|
705
|
-
else {
|
|
706
|
-
const latest = extractLatestChangelog(changelog);
|
|
707
|
-
if (!latest) {
|
|
708
|
-
getDefaultChannel().writeLine(pc.yellow(t("cli.changelog_not_found")));
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
getDefaultChannel().writeLine(pc.cyan(t("cli.changelog_title", { version })));
|
|
712
|
-
getDefaultChannel().writeLine(latest);
|
|
713
|
-
}
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
/** Тонкий оркестратор: собирает CLI из per-domain builder-функций. */
|
|
717
|
-
export function createProgram() {
|
|
718
|
-
const program = new Command()
|
|
719
|
-
.name("mma")
|
|
720
|
-
.description(t("cli.description"))
|
|
721
|
-
.version(version)
|
|
722
|
-
.option("--no-agents-md", t("cli.no_agents_md"))
|
|
723
|
-
.option("-d, --dir <path>", t("cli.dir"))
|
|
724
|
-
.option("-e, --exit-on-complete", t("cli.exit_on_complete"))
|
|
725
|
-
.option("-j, --json", t("cli.json"))
|
|
726
|
-
.option("--reasoning <level>", t("cli.reasoning_level"), "auto")
|
|
727
|
-
.option("--verbose", t("cli.verbose"))
|
|
728
|
-
.option("--context-log", t("cli.context_log"));
|
|
729
|
-
buildSetupCommand(program);
|
|
730
|
-
buildMeetCommand(program);
|
|
731
|
-
buildInitCommand(program);
|
|
732
|
-
buildAgentsCommand(program);
|
|
733
|
-
buildWebCommand(program);
|
|
734
|
-
buildConfigCommands(program);
|
|
735
|
-
buildModelCommands(program);
|
|
736
|
-
buildContextCommand(program);
|
|
737
|
-
buildUsageCommand(program);
|
|
738
|
-
buildMapCommand(program);
|
|
739
|
-
buildProviderCommands(program);
|
|
740
|
-
buildSessionCommands(program);
|
|
741
|
-
// Подключаем security-команды.
|
|
742
|
-
createSecurityCommand(program);
|
|
743
|
-
// Подключаем plugin-команды.
|
|
744
|
-
createPluginCommand(program);
|
|
745
|
-
buildChangelogCommand(program);
|
|
746
|
-
program
|
|
747
|
-
.argument("[prompt...]", t("cli.prompt_arg"))
|
|
748
|
-
.description(t("cli.run_prompt"))
|
|
749
|
-
.action((_prompt) => {
|
|
750
|
-
/* Обрабатывает main.ts после program.parse(). */
|
|
751
|
-
});
|
|
752
|
-
// Экшены субкоманд гонят полный bootstrap() (reasoning-пробник, индексер,
|
|
753
|
-
// плагины…), оставляющий открытые хендлы: без явного exit процесс висит после
|
|
754
|
-
// печати результата ("config set" напечатал и не вышел). Prompt/REPL-пути
|
|
755
|
-
// выходят явно в main.ts; каждая СУБКОМАНДА — one-shot: выходим, как резолвнится action.
|
|
756
|
-
//
|
|
757
|
-
// Хук навешиваем РЕКУРСИВНО на все подкоманды (не только верхнего уровня):
|
|
758
|
-
// у вложенных (`session show`, `model certify`, `provider use` …) родитель
|
|
759
|
-
// без action, поэтому postAction родителя не срабатывает, и фоновые хендлы
|
|
760
|
-
// bootstrap держат процесс — команда «виснет» после вывода. На `program`
|
|
761
|
-
// хук не вешаем: его action — prompt/REPL, которым управляет main.ts.
|
|
762
|
-
const attachOneShotExit = (cmd) => {
|
|
763
|
-
cmd.hook("postAction", () => {
|
|
764
|
-
process.exit(0);
|
|
765
|
-
});
|
|
766
|
-
for (const sub of cmd.commands)
|
|
767
|
-
attachOneShotExit(sub);
|
|
768
|
-
};
|
|
769
|
-
// `meet`/`agents` — не one-shot: их пустые action лишь маркируют намерение, и
|
|
770
|
-
// main.ts проваливается в интерактивный REPL. `web` долгоживущий (сервер
|
|
771
|
-
// стартует из main.ts после parse). Хук выхода сработал бы во время
|
|
772
|
-
// program.parse() и убил процесс до ветки. `mma init`/`mma setup` — one-shot
|
|
773
|
-
// визарды, обязаны выйти после прогона.
|
|
774
|
-
const longRunningCommands = new Set(["meet", "agents", "web"]);
|
|
775
|
-
for (const cmd of program.commands) {
|
|
776
|
-
if (longRunningCommands.has(cmd.name()))
|
|
777
|
-
continue;
|
|
778
|
-
attachOneShotExit(cmd);
|
|
779
|
-
}
|
|
780
|
-
return program;
|
|
781
|
-
}
|