micro-models-agent 2.16.1 → 2.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- 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/tools/remember.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/** Тул записи в межсессионную память (preferences, факты, решения, ошибки). */
|
|
2
|
-
import { t } from "../i18n/index";
|
|
3
|
-
import { MemoryStore } from "../modules/memory/store";
|
|
4
|
-
import { globalMemoryDir } from "../config/paths";
|
|
5
|
-
/** Категории памяти. */
|
|
6
|
-
const CATEGORIES = ["preferences", "conventions", "decisions", "errors", "facts"];
|
|
7
|
-
/** Пишет факт/преференс в глобальную память. Параметры: category, key/value или entry. */
|
|
8
|
-
export const rememberTool = {
|
|
9
|
-
name: "remember",
|
|
10
|
-
icon: "🧠",
|
|
11
|
-
description: "Remember information across sessions. Use for user preferences, facts, conventions, decisions, or errors.",
|
|
12
|
-
tags: ["memory"],
|
|
13
|
-
parameters: {
|
|
14
|
-
type: "object",
|
|
15
|
-
properties: {
|
|
16
|
-
category: {
|
|
17
|
-
type: "string",
|
|
18
|
-
description: "Memory category: preferences, conventions, decisions, errors, facts",
|
|
19
|
-
enum: CATEGORIES,
|
|
20
|
-
},
|
|
21
|
-
key: {
|
|
22
|
-
type: "string",
|
|
23
|
-
description: 'Key name (required for preferences, e.g. "color", "language")',
|
|
24
|
-
},
|
|
25
|
-
value: {
|
|
26
|
-
type: "string",
|
|
27
|
-
description: "Value to store (required for preferences)",
|
|
28
|
-
},
|
|
29
|
-
entry: {
|
|
30
|
-
type: "string",
|
|
31
|
-
description: "Text entry to append (for conventions, decisions, errors, facts)",
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
required: ["category"],
|
|
35
|
-
},
|
|
36
|
-
handler: async (_ctx, args) => {
|
|
37
|
-
const category = String(args.category || "");
|
|
38
|
-
if (!CATEGORIES.includes(category)) {
|
|
39
|
-
return { success: false, output: t("tool.invalid_params") };
|
|
40
|
-
}
|
|
41
|
-
const memoryDir = globalMemoryDir();
|
|
42
|
-
const store = new MemoryStore(memoryDir);
|
|
43
|
-
try {
|
|
44
|
-
if (category === "preferences") {
|
|
45
|
-
const key = String(args.key || "");
|
|
46
|
-
const value = String(args.value || "");
|
|
47
|
-
if (!key) {
|
|
48
|
-
return { success: false, output: t("tool.remember.key_required") };
|
|
49
|
-
}
|
|
50
|
-
store.setPreference(key, value);
|
|
51
|
-
return {
|
|
52
|
-
success: true,
|
|
53
|
-
output: t("tool.remember.preference", { key, value }),
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
const entry = String(args.entry || "");
|
|
57
|
-
if (!entry) {
|
|
58
|
-
return { success: false, output: t("tool.remember.entry_required") };
|
|
59
|
-
}
|
|
60
|
-
store.append(category, entry);
|
|
61
|
-
return {
|
|
62
|
-
success: true,
|
|
63
|
-
output: t("tool.remember.entry", { category, entry }),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
// Упавшая запись — провал: отчёт об успехе заставлял агента (и учёт
|
|
68
|
-
// падений) верить, что память сохранена.
|
|
69
|
-
return { success: false, output: t("tool.memory_error", { error: String(err) }) };
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { resolve, normalize } from "path";
|
|
2
|
-
import { isInsideDir, matchesScopeEntry } from "./path-utils";
|
|
3
|
-
export function isPathInScope(baseDir, targetPath, scope) {
|
|
4
|
-
const baseResolved = resolve(baseDir);
|
|
5
|
-
const targetResolved = resolve(baseDir, normalize(targetPath));
|
|
6
|
-
// Separator- and case-safe containment (sibling prefixes cannot pass).
|
|
7
|
-
if (!isInsideDir(targetResolved, baseResolved)) {
|
|
8
|
-
return { allowed: false, reason: "Path is outside the base working directory" };
|
|
9
|
-
}
|
|
10
|
-
if (!scope)
|
|
11
|
-
return { allowed: true };
|
|
12
|
-
const isRead = scope.read_only_files.some((f) => matchesScopeEntry(targetResolved, resolve(baseDir, f)));
|
|
13
|
-
const isWrite = scope.allowed_files.some((f) => matchesScopeEntry(targetResolved, resolve(baseDir, f)));
|
|
14
|
-
if (isWrite)
|
|
15
|
-
return { allowed: true };
|
|
16
|
-
if (isRead)
|
|
17
|
-
return { allowed: true, reason: "Read-only file" };
|
|
18
|
-
return { allowed: false, reason: "Path is not within the allowed scope for this sub-agent" };
|
|
19
|
-
}
|
|
20
|
-
export function isPathWritable(baseDir, targetPath, scope) {
|
|
21
|
-
const baseResolved = resolve(baseDir);
|
|
22
|
-
const targetResolved = resolve(baseDir, normalize(targetPath));
|
|
23
|
-
if (!isInsideDir(targetResolved, baseResolved)) {
|
|
24
|
-
return { allowed: false, reason: "Path is outside the base working directory" };
|
|
25
|
-
}
|
|
26
|
-
if (!scope)
|
|
27
|
-
return { allowed: true };
|
|
28
|
-
const isWrite = scope.allowed_files.some((f) => matchesScopeEntry(targetResolved, resolve(baseDir, f)));
|
|
29
|
-
if (isWrite)
|
|
30
|
-
return { allowed: true };
|
|
31
|
-
return { allowed: false, reason: "Path is not within the writable scope for this sub-agent" };
|
|
32
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/** Тулы записи (для классификации отказа как write). */
|
|
2
|
-
const WRITE_TOOLS = new Set([
|
|
3
|
-
"write_file",
|
|
4
|
-
"edit_file",
|
|
5
|
-
"delete_file",
|
|
6
|
-
"create_dir",
|
|
7
|
-
"move_file",
|
|
8
|
-
"download_file",
|
|
9
|
-
]);
|
|
10
|
-
/**
|
|
11
|
-
* Отказы скоупа идут через i18n-ключи file.path_not_allowed(_short)
|
|
12
|
-
* ("Path not allowed" / "Путь недопустим") и "[SCOPE]"-префикс chunk-query.
|
|
13
|
-
*/
|
|
14
|
-
export function isPathDenialOutput(output) {
|
|
15
|
-
if (!output)
|
|
16
|
-
return false;
|
|
17
|
-
return (output.includes("Path not allowed") ||
|
|
18
|
-
output.includes("Путь недопустим") ||
|
|
19
|
-
output.startsWith("[SCOPE]"));
|
|
20
|
-
}
|
|
21
|
-
/** Извлекает путь из аргументов tool call (по именам ключей, иначе по виду). */
|
|
22
|
-
function pathArgOf(args) {
|
|
23
|
-
if (!args)
|
|
24
|
-
return "";
|
|
25
|
-
for (const key of ["path", "file", "input_path", "target", "source", "destination", "dir"]) {
|
|
26
|
-
const v = args[key];
|
|
27
|
-
if (typeof v === "string" && v.trim())
|
|
28
|
-
return v.trim();
|
|
29
|
-
}
|
|
30
|
-
for (const v of Object.values(args)) {
|
|
31
|
-
if (typeof v === "string" && /\.[\w-]+$/.test(v))
|
|
32
|
-
return v.trim();
|
|
33
|
-
}
|
|
34
|
-
return "";
|
|
35
|
-
}
|
|
36
|
-
/** Наблюдает результаты тулов субагента, копит scope-отказы по путям. */
|
|
37
|
-
export class ScopeDenialCollector {
|
|
38
|
-
denied = new Map();
|
|
39
|
-
plugin = {
|
|
40
|
-
name: "scope-denial-collector",
|
|
41
|
-
isBuiltin: true,
|
|
42
|
-
onAfterTool: (_ctx, call, result) => {
|
|
43
|
-
const name = call.name;
|
|
44
|
-
if (!name || !result || result.success)
|
|
45
|
-
return;
|
|
46
|
-
if (!isPathDenialOutput(typeof result.output === "string" ? result.output : undefined)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const path = pathArgOf(call.arguments);
|
|
50
|
-
if (!path)
|
|
51
|
-
return;
|
|
52
|
-
const write = WRITE_TOOLS.has(name);
|
|
53
|
-
this.denied.set(path, { path, write });
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
/** Все отказы дедуплицированно. */
|
|
57
|
-
getDenied() {
|
|
58
|
-
return Array.from(this.denied.values());
|
|
59
|
-
}
|
|
60
|
-
/** read_only=true — только если все отказы были чисто read. */
|
|
61
|
-
toScopeRequest(reason = "sub-agent was denied access to files needed for the task") {
|
|
62
|
-
const all = this.getDenied();
|
|
63
|
-
if (all.length === 0)
|
|
64
|
-
return null;
|
|
65
|
-
return {
|
|
66
|
-
files: all.map((d) => d.path),
|
|
67
|
-
read_only: !all.some((d) => d.write),
|
|
68
|
-
reason,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/** Сериализует запрос в `<scope-request>`-блок результата. */
|
|
73
|
-
export function formatScopeRequest(req) {
|
|
74
|
-
return `<scope-request>${JSON.stringify(req)}</scope-request>`;
|
|
75
|
-
}
|
|
76
|
-
/** Парсит `<scope-request>`-блок из текста. Битый/пустой — null. */
|
|
77
|
-
export function parseScopeRequest(text) {
|
|
78
|
-
if (!text)
|
|
79
|
-
return null;
|
|
80
|
-
const match = text.match(/<scope-request>([\s\S]*?)<\/scope-request>/);
|
|
81
|
-
if (!match)
|
|
82
|
-
return null;
|
|
83
|
-
try {
|
|
84
|
-
const parsed = JSON.parse(match[1]);
|
|
85
|
-
if (!Array.isArray(parsed.files) || parsed.files.length === 0)
|
|
86
|
-
return null;
|
|
87
|
-
return {
|
|
88
|
-
files: parsed.files.map(String),
|
|
89
|
-
read_only: !!parsed.read_only,
|
|
90
|
-
reason: String(parsed.reason || "access denied"),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/** Тул поиска по истории сессий (JSONL всех сессий, cap результатов). */
|
|
2
|
-
import * as fs from "fs";
|
|
3
|
-
import { join } from "path";
|
|
4
|
-
import { t } from "../i18n/index";
|
|
5
|
-
import { globalSessionsDir } from "../config/paths";
|
|
6
|
-
/** Ищет запрос в одном history.jsonl, складывает ужатые JSON-записи. */
|
|
7
|
-
function searchFile(filePath, query, maxResults, results) {
|
|
8
|
-
if (!fs.existsSync(filePath))
|
|
9
|
-
return;
|
|
10
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
11
|
-
for (const line of content.split("\n").filter(Boolean)) {
|
|
12
|
-
if (line.toLowerCase().includes(query)) {
|
|
13
|
-
try {
|
|
14
|
-
const entry = JSON.parse(line);
|
|
15
|
-
results.push(`[${filePath}] ${JSON.stringify(entry).slice(0, 200)}`);
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
/* skip */
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (results.length >= maxResults)
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/** Ищет по прошлым взаимодействиям всех сессий. Параметры: query, maxResults, sessionId. */
|
|
26
|
-
export const searchHistoryTool = {
|
|
27
|
-
name: "search_history",
|
|
28
|
-
icon: "🕵️",
|
|
29
|
-
description: "Search through session history for past interactions across all sessions.",
|
|
30
|
-
tags: ["research"],
|
|
31
|
-
parameters: {
|
|
32
|
-
type: "object",
|
|
33
|
-
properties: {
|
|
34
|
-
query: { type: "string", description: "Search query" },
|
|
35
|
-
maxResults: {
|
|
36
|
-
type: "number",
|
|
37
|
-
description: "Maximum results (default 5)",
|
|
38
|
-
},
|
|
39
|
-
sessionId: {
|
|
40
|
-
type: "string",
|
|
41
|
-
description: "Optional: limit search to a specific session",
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
required: ["query"],
|
|
45
|
-
},
|
|
46
|
-
handler: async (_ctx, args) => {
|
|
47
|
-
const query = String(args.query || "").toLowerCase();
|
|
48
|
-
const maxResults = Number(args.maxResults) || 5;
|
|
49
|
-
const sessionId = args.sessionId ? String(args.sessionId) : null;
|
|
50
|
-
const sessionDir = globalSessionsDir();
|
|
51
|
-
const results = [];
|
|
52
|
-
try {
|
|
53
|
-
if (!fs.existsSync(sessionDir)) {
|
|
54
|
-
return {
|
|
55
|
-
success: true,
|
|
56
|
-
output: t("tool.no_sessions_dir", { dir: sessionDir }),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const entries = fs.readdirSync(sessionDir, { withFileTypes: true });
|
|
60
|
-
for (const entry of entries) {
|
|
61
|
-
if (!entry.isDirectory())
|
|
62
|
-
continue;
|
|
63
|
-
if (sessionId && entry.name !== sessionId)
|
|
64
|
-
continue;
|
|
65
|
-
const historyFile = join(sessionDir, entry.name, "history.jsonl");
|
|
66
|
-
searchFile(historyFile, query, maxResults, results);
|
|
67
|
-
if (results.length >= maxResults)
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
if (results.length === 0) {
|
|
71
|
-
return { success: true, output: t("tool.no_history", { query }) };
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
success: true,
|
|
75
|
-
output: t("tool.history_results", {
|
|
76
|
-
query,
|
|
77
|
-
results: results.join("\n"),
|
|
78
|
-
}),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
return {
|
|
83
|
-
success: false,
|
|
84
|
-
output: t("tool.history_error", { error: String(err) }),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/** Тул метаданных текущей сессии (id, модель, бюджет контекста; alwaysOn). */
|
|
2
|
-
import { t } from "../i18n/index";
|
|
3
|
-
/** Показывает сессию и загрузку контекстного бюджета. Без активной — пометка. */
|
|
4
|
-
export const sessionInfoTool = {
|
|
5
|
-
name: "session_info",
|
|
6
|
-
icon: "ℹ️",
|
|
7
|
-
description: "Show metadata about the current session: id, name, model, provider, context window, message count, and how much of the context budget is used. Use when the user asks which session this is or how much context is left.",
|
|
8
|
-
alwaysOn: true,
|
|
9
|
-
boundedOutput: true,
|
|
10
|
-
parameters: {
|
|
11
|
-
type: "object",
|
|
12
|
-
properties: {},
|
|
13
|
-
},
|
|
14
|
-
handler: async (ctx) => {
|
|
15
|
-
const meta = ctx.sessionManager?.getActiveMeta();
|
|
16
|
-
if (!meta) {
|
|
17
|
-
return { success: true, output: t("tool.session_info.no_active") };
|
|
18
|
-
}
|
|
19
|
-
const provider = ctx.config.provider;
|
|
20
|
-
const providerName = provider.active ?? provider.type ?? "unknown";
|
|
21
|
-
const lines = [
|
|
22
|
-
t("tool.session_info.result", {
|
|
23
|
-
id: meta.id,
|
|
24
|
-
name: meta.name,
|
|
25
|
-
model: meta.model ?? ctx.config.model ?? "unknown",
|
|
26
|
-
provider: providerName,
|
|
27
|
-
contextWindow: String(meta.contextWindow ?? ctx.config.contextWindow),
|
|
28
|
-
messages: String(meta.messageCount),
|
|
29
|
-
createdAt: meta.createdAt,
|
|
30
|
-
updatedAt: meta.updatedAt,
|
|
31
|
-
}),
|
|
32
|
-
];
|
|
33
|
-
const snapshot = ctx.contextManager?.getSnapshot();
|
|
34
|
-
if (snapshot) {
|
|
35
|
-
const used = snapshot.tokens;
|
|
36
|
-
const budget = snapshot.budget.history;
|
|
37
|
-
const percent = budget > 0 ? Math.round((used / budget) * 100) : 0;
|
|
38
|
-
lines.push(t("tool.session_info.context", {
|
|
39
|
-
used: String(used),
|
|
40
|
-
budget: String(budget),
|
|
41
|
-
percent: String(percent),
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
return { success: true, output: lines.join("\n") };
|
|
45
|
-
},
|
|
46
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/** Тул ручной установки reasoning-уровня (транзиентный, с кулдауном). */
|
|
2
|
-
import { t } from "../i18n/index";
|
|
3
|
-
/** Допустимые уровни reasoning. */
|
|
4
|
-
const VALID_LEVELS = ["default", "none", "low", "medium", "high", "max"];
|
|
5
|
-
/**
|
|
6
|
-
* Фабрика тула set_thinking (уровень на следующий LLM-вызов; штатно рулит
|
|
7
|
-
* харнесс). Возврат: определение тула.
|
|
8
|
-
*/
|
|
9
|
-
export function createSetThinkingTool(state, config, getCurrentIteration) {
|
|
10
|
-
return {
|
|
11
|
-
name: "set_thinking",
|
|
12
|
-
description: "Set reasoning effort level for the next LLM call. Normally managed automatically by the harness. Use only to force deeper thinking for genuinely hard subproblems or shallower for mechanical batches.",
|
|
13
|
-
icon: "🧠",
|
|
14
|
-
tags: [],
|
|
15
|
-
alwaysOn: true,
|
|
16
|
-
parameters: {
|
|
17
|
-
type: "object",
|
|
18
|
-
properties: {
|
|
19
|
-
level: {
|
|
20
|
-
type: "string",
|
|
21
|
-
enum: ["none", "low", "high", "max"],
|
|
22
|
-
description: "Reasoning effort level to set",
|
|
23
|
-
},
|
|
24
|
-
reason: {
|
|
25
|
-
type: "string",
|
|
26
|
-
description: "Why changing the level",
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
required: ["level"],
|
|
30
|
-
},
|
|
31
|
-
handler: async (_ctx, args) => {
|
|
32
|
-
const requested = args.level;
|
|
33
|
-
const reason = args.reason || "agent override";
|
|
34
|
-
if (!VALID_LEVELS.includes(requested) && requested !== "auto") {
|
|
35
|
-
return {
|
|
36
|
-
success: false,
|
|
37
|
-
output: t("tool.thinking_invalid_level", { level: requested }),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
// Проверка кулдауна.
|
|
41
|
-
const currentIter = getCurrentIteration();
|
|
42
|
-
const elapsed = currentIter - state.overrideIteration;
|
|
43
|
-
if (elapsed > 0 && elapsed < config.overrideCooldown) {
|
|
44
|
-
return {
|
|
45
|
-
success: true,
|
|
46
|
-
output: t("tool.thinking_cooldown", {
|
|
47
|
-
remaining: config.overrideCooldown - elapsed,
|
|
48
|
-
current: state.level,
|
|
49
|
-
}),
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
// Кламп в настроенные границы.
|
|
53
|
-
let level = requested;
|
|
54
|
-
const levelOrder = ["none", "low", "medium", "high", "max"];
|
|
55
|
-
const minIdx = levelOrder.indexOf(config.min);
|
|
56
|
-
const maxIdx = levelOrder.indexOf(config.max);
|
|
57
|
-
const reqIdx = levelOrder.indexOf(level);
|
|
58
|
-
let clamped = false;
|
|
59
|
-
if (reqIdx >= 0 && reqIdx < minIdx) {
|
|
60
|
-
level = config.min;
|
|
61
|
-
clamped = true;
|
|
62
|
-
}
|
|
63
|
-
else if (reqIdx > maxIdx) {
|
|
64
|
-
level = config.max;
|
|
65
|
-
clamped = true;
|
|
66
|
-
}
|
|
67
|
-
state.level = level;
|
|
68
|
-
state.overrideIteration = currentIter;
|
|
69
|
-
const msg = clamped
|
|
70
|
-
? t("tool.thinking_set_clamped", { level, reason })
|
|
71
|
-
: t("tool.thinking_set", { level, reason });
|
|
72
|
-
return { success: true, output: msg };
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
package/dist/tools/subagent.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
/** Тул изолированного субагента (свой контекст, скоуп, теги тулов, MoE-off). */
|
|
2
|
-
import { t } from "../i18n/index";
|
|
3
|
-
import { Agent } from "../core/agent";
|
|
4
|
-
import { ContextManager } from "../modules/context/manager";
|
|
5
|
-
import { HallucinationDetector } from "../modules/hallucination/detector";
|
|
6
|
-
import { PluginManager } from "../modules/plugins/manager";
|
|
7
|
-
import { logSecurityBlock } from "../modules/security/audit-log";
|
|
8
|
-
import { getSessionSecurityConfig } from "../modules/security/session-isolation";
|
|
9
|
-
import { ArtifactStore } from "../modules/artifacts/store";
|
|
10
|
-
import { ScopeDenialCollector, formatScopeRequest } from "./scope-request";
|
|
11
|
-
/** Фиксированный системный промпт (KV-cache дружит при stableSystemPrompt). */
|
|
12
|
-
export const SUBAGENT_SYSTEM_PROMPT_TEMPLATE = `You are a sub-agent working on a specific task. You have your own context window and tool set.
|
|
13
|
-
|
|
14
|
-
Workflow rules:
|
|
15
|
-
- Prefer small, focused steps. Verify your own work (typecheck/tests) before finishing.
|
|
16
|
-
- For large outputs, write the result to a file with write_file instead of reproducing it in your answer.
|
|
17
|
-
- If the task is big and decomposable, delegate parts to the subagent tool instead of doing everything in one context.
|
|
18
|
-
- When you finish, return a concise final answer; do not repeat file contents verbatim if you already wrote them to disk.`;
|
|
19
|
-
/** Собирает системный промпт субагента (стабильный или с контекстом). */
|
|
20
|
-
function buildSubagentSystemPrompt(context, stable) {
|
|
21
|
-
if (stable)
|
|
22
|
-
return SUBAGENT_SYSTEM_PROMPT_TEMPLATE;
|
|
23
|
-
return `You are a sub-agent working on a specific task. ${context ? `Context: ${context}` : ""}`;
|
|
24
|
-
}
|
|
25
|
-
/** Спавнит изолированного субагента. Параметры: task, scope-файлы, tool_tags, result_mode. */
|
|
26
|
-
export const subagentTool = {
|
|
27
|
-
name: "subagent",
|
|
28
|
-
icon: "🤖",
|
|
29
|
-
description: "Spawn an isolated sub-agent to work on a task independently. The sub-agent has its own context and executes autonomously. Use for parallel work or complex sub-tasks.",
|
|
30
|
-
tags: ["code"],
|
|
31
|
-
timeoutMs: 180000,
|
|
32
|
-
parameters: {
|
|
33
|
-
type: "object",
|
|
34
|
-
properties: {
|
|
35
|
-
task: {
|
|
36
|
-
type: "string",
|
|
37
|
-
description: "Task description for the sub-agent",
|
|
38
|
-
},
|
|
39
|
-
context: {
|
|
40
|
-
type: "string",
|
|
41
|
-
description: "Optional context or constraints",
|
|
42
|
-
},
|
|
43
|
-
expert_tag: {
|
|
44
|
-
type: "string",
|
|
45
|
-
description: "Expert tag for tool filtering and model selection",
|
|
46
|
-
},
|
|
47
|
-
allowed_files: {
|
|
48
|
-
type: "array",
|
|
49
|
-
items: { type: "string" },
|
|
50
|
-
description: "Files/directories the sub-agent can read and write",
|
|
51
|
-
},
|
|
52
|
-
read_only_files: {
|
|
53
|
-
type: "array",
|
|
54
|
-
items: { type: "string" },
|
|
55
|
-
description: "Files/directories the sub-agent can read but not write",
|
|
56
|
-
},
|
|
57
|
-
shared_context: {
|
|
58
|
-
type: "string",
|
|
59
|
-
description: "Shared context/rules passed to the sub-agent",
|
|
60
|
-
},
|
|
61
|
-
max_tokens: {
|
|
62
|
-
type: "number",
|
|
63
|
-
description: "Maximum tokens for the sub-agent response",
|
|
64
|
-
},
|
|
65
|
-
tool_tags: {
|
|
66
|
-
type: "array",
|
|
67
|
-
items: { type: "string" },
|
|
68
|
-
description: "Tool tags to expose to the sub-agent",
|
|
69
|
-
},
|
|
70
|
-
result_mode: {
|
|
71
|
-
type: "string",
|
|
72
|
-
enum: ["text", "file"],
|
|
73
|
-
description: '"file": persist the full result to an artifact and return a path + summary (pass-by-reference). "text" (default): return the full text into context.',
|
|
74
|
-
},
|
|
75
|
-
artifact_name: {
|
|
76
|
-
type: "string",
|
|
77
|
-
description: "Artifact file name (sanitized). Default: subagent-<timestamp>.",
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
required: ["task"],
|
|
81
|
-
},
|
|
82
|
-
handler: async (ctx, args) => {
|
|
83
|
-
const task = String(args.task || "");
|
|
84
|
-
const context = String(args.context || "");
|
|
85
|
-
if (!task) {
|
|
86
|
-
return { success: false, output: t("tool.name_or_task") };
|
|
87
|
-
}
|
|
88
|
-
// Сессионный security-конфиг.
|
|
89
|
-
const securityConfig = ctx.sessionContext
|
|
90
|
-
? getSessionSecurityConfig(ctx.config, ctx.sessionContext)
|
|
91
|
-
: ctx.config.security;
|
|
92
|
-
// Лимит глубины рекурсии. Глубину читаем из SHARED-контекста исполнителя
|
|
93
|
-
// (его видят вложенные субагенты) — `ctx.recursionDepth` снапшотился раз при
|
|
94
|
-
// bootstrap и не инкрементился, поэтому гард не срабатывал и субагент мог
|
|
95
|
-
// спавнить субагентов безгранично.
|
|
96
|
-
const executor = ctx.toolExecutor;
|
|
97
|
-
const parentDepth = executor?.getRecursionDepth?.() ?? (ctx.recursionDepth ?? 0);
|
|
98
|
-
const maxDepth = securityConfig?.maxRecursionDepth ?? 3;
|
|
99
|
-
const currentDepth = parentDepth;
|
|
100
|
-
if (currentDepth >= maxDepth) {
|
|
101
|
-
logSecurityBlock(ctx.sessionId, "bash_command", `Maximum recursion depth (${maxDepth}) exceeded`, task);
|
|
102
|
-
return {
|
|
103
|
-
success: false,
|
|
104
|
-
output: `[SECURITY BLOCKED] Maximum sub-agent recursion depth (${maxDepth}) exceeded`,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
const scope = args.allowed_files || args.read_only_files
|
|
108
|
-
? {
|
|
109
|
-
allowed_files: args.allowed_files || [],
|
|
110
|
-
read_only_files: args.read_only_files || [],
|
|
111
|
-
}
|
|
112
|
-
: ctx.scope;
|
|
113
|
-
const toolTags = args.tool_tags ? args.tool_tags : undefined;
|
|
114
|
-
if (!ctx.llmProvider || !ctx.toolExecutor) {
|
|
115
|
-
return {
|
|
116
|
-
success: false,
|
|
117
|
-
output: t("tool.subagent_cannot_run"),
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
// Оборонительный гард: запрошенные tool_tags ни с чем не мэтчатся — у
|
|
121
|
-
// субагента ноль тулов, и он галлюцинирует вместо действий. Предупредить
|
|
122
|
-
// вызывающего для коррекции тегов. Проверка через getByTags (не
|
|
123
|
-
// getAllForLLM): alwaysOn мэтчатся всегда — гард меряет реальное покрытие,
|
|
124
|
-
// а не присутствие в схеме.
|
|
125
|
-
if (toolTags && toolTags.length > 0) {
|
|
126
|
-
const matched = ctx.toolExecutor.getRegistry().getByTags(toolTags);
|
|
127
|
-
if (matched.length === 0) {
|
|
128
|
-
return {
|
|
129
|
-
success: false,
|
|
130
|
-
output: `[SECURITY BLOCKED] No tools match the requested tool_tags: [${toolTags.join(", ")}]. Check the subagent tool_tags parameter and retry with valid tags (e.g. "file", "code", "shell", "research").`,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
// Сейв/рестор shared-скоупа исполнителя, чтобы субагент не мутировал скоуп
|
|
135
|
-
// родителя навсегда. Текущий скоуп — из shared-исполнителя, не `ctx.scope`:
|
|
136
|
-
// MoE зовёт тул с ad-hoc контекстом без scope — снапшот `ctx.scope` ресторил
|
|
137
|
-
// бы "unrestricted" и сносил изоляцию всей волне.
|
|
138
|
-
const parentScope = executor?.getScope?.() ?? ctx.scope;
|
|
139
|
-
const appliedScope = scope || { allowed_files: [], read_only_files: [] };
|
|
140
|
-
// Compare-and-restore: параллельная MoE-волна могла тем временем поставить
|
|
141
|
-
// свой скоуп — чужого свежего владельца не затирать.
|
|
142
|
-
const restoreScope = () => {
|
|
143
|
-
if (ctx.toolExecutor?.getScope?.() === appliedScope) {
|
|
144
|
-
ctx.toolExecutor.setScope(parentScope);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
try {
|
|
148
|
-
const subContextManager = new ContextManager(ctx.config.contextWindow, ctx.config.contextBudget);
|
|
149
|
-
const subPluginManager = new PluginManager();
|
|
150
|
-
// Детерминированный трекинг scope-отказов: блокировки файловых тулов
|
|
151
|
-
// ребёнка скоуп-гардом всплывают машиночитаемым блоком <scope-request>
|
|
152
|
-
// в результате (см. MoE executor / Router).
|
|
153
|
-
const scopeCollector = new ScopeDenialCollector();
|
|
154
|
-
subPluginManager.register(scopeCollector.plugin, "builtin");
|
|
155
|
-
const hallucinationDetector = new HallucinationDetector(ctx.baseDir, ctx.llmProvider);
|
|
156
|
-
ctx.toolExecutor.setScope(appliedScope);
|
|
157
|
-
// Cleanup на исполнителе — рестор скоупа при таймауте/аборте, даже если
|
|
158
|
-
// `finally` агента не отработал (брошенный промис).
|
|
159
|
-
ctx.cleanup = restoreScope;
|
|
160
|
-
// Глубину — на shared-контекст исполнителя, чтобы ВЛОЖЕННЫЕ субагенты
|
|
161
|
-
// видели уровень глубже (и гард выше мог сработать).
|
|
162
|
-
ctx.recursionDepth = currentDepth + 1;
|
|
163
|
-
executor?.setRecursionDepth?.(currentDepth + 1);
|
|
164
|
-
const systemPrompt = {
|
|
165
|
-
content: buildSubagentSystemPrompt(context, ctx.config.subagent?.stableSystemPrompt !== false),
|
|
166
|
-
priority: "critical",
|
|
167
|
-
essential: true,
|
|
168
|
-
estimatedTokens: 150,
|
|
169
|
-
};
|
|
170
|
-
// MoE — TOP-LEVEL режим оркестрации: субагент от тула subagent всегда идёт
|
|
171
|
-
// plain single-agent циклом. Шаринг родительского конфига заставлял каждого
|
|
172
|
-
// MoE-субагента реентерить runWithMoE — планировать свои сабтаски и рекурсивно
|
|
173
|
-
// спавнить вложенных субагентов (лимит — лишь maxRecursionDepth), что вешало
|
|
174
|
-
// исполнение на минуты без прогресс-событий.
|
|
175
|
-
const subConfig = { ...ctx.config, moe: { ...ctx.config.moe, enabled: false } };
|
|
176
|
-
const subDeps = {
|
|
177
|
-
config: subConfig,
|
|
178
|
-
llmProvider: ctx.llmProvider,
|
|
179
|
-
toolExecutor: ctx.toolExecutor,
|
|
180
|
-
pluginManager: subPluginManager,
|
|
181
|
-
contextManager: subContextManager,
|
|
182
|
-
hallucinationDetector,
|
|
183
|
-
logger: ctx.logger,
|
|
184
|
-
baseDir: ctx.baseDir,
|
|
185
|
-
scope,
|
|
186
|
-
toolTags,
|
|
187
|
-
promptBlocks: [systemPrompt],
|
|
188
|
-
};
|
|
189
|
-
const subAgent = (ctx.agentFactory ?? ((d) => new Agent(d)))(subDeps);
|
|
190
|
-
const fullTask = context ? `${task}\n\nContext: ${context}` : task;
|
|
191
|
-
try {
|
|
192
|
-
const result = await subAgent.run(fullTask);
|
|
193
|
-
const pickUsage = () => result.promptTokens !== undefined || result.totalTokens !== undefined
|
|
194
|
-
? {
|
|
195
|
-
promptTokens: result.promptTokens ?? 0,
|
|
196
|
-
completionTokens: result.completionTokens ?? 0,
|
|
197
|
-
totalTokens: result.totalTokens ?? 0,
|
|
198
|
-
}
|
|
199
|
-
: undefined;
|
|
200
|
-
if (!result.success) {
|
|
201
|
-
let output = t("tool.subagent_failed", {
|
|
202
|
-
error: String(result.error),
|
|
203
|
-
text: result.text,
|
|
204
|
-
});
|
|
205
|
-
const scopeReq = scopeCollector.toScopeRequest();
|
|
206
|
-
if (scopeReq)
|
|
207
|
-
output += `\n${formatScopeRequest(scopeReq)}`;
|
|
208
|
-
return { success: false, output };
|
|
209
|
-
}
|
|
210
|
-
const resultMode = args.result_mode || ctx.config.subagent?.resultMode || "text";
|
|
211
|
-
if (resultMode === "file") {
|
|
212
|
-
const store = new ArtifactStore({
|
|
213
|
-
baseDir: ctx.baseDir,
|
|
214
|
-
sessionId: ctx.sessionId || "default",
|
|
215
|
-
artifactsDir: ctx.config.subagent?.artifactsDir,
|
|
216
|
-
});
|
|
217
|
-
const abs = store.save(args.artifact_name || `subagent-${Date.now()}`, result.text, "md");
|
|
218
|
-
const summary = store.summary(result.text, ctx.config.subagent?.maxSummaryChars ?? 2000);
|
|
219
|
-
ctx.logger.debug(`subagent result persisted to artifact ${abs} (${result.text.length} chars, ${result.iterationCount} iterations)`);
|
|
220
|
-
return {
|
|
221
|
-
success: true,
|
|
222
|
-
output: t("tool.subagent_artifact", {
|
|
223
|
-
path: abs,
|
|
224
|
-
iterations: String(result.iterationCount),
|
|
225
|
-
summary,
|
|
226
|
-
}),
|
|
227
|
-
// Структурированный путь, чтобы вызывающие (MoE executor) не парсили
|
|
228
|
-
// локализованную строку `output`.
|
|
229
|
-
artifactPath: abs,
|
|
230
|
-
usage: pickUsage(),
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
return {
|
|
234
|
-
success: true,
|
|
235
|
-
output: t("tool.subagent_completed", {
|
|
236
|
-
text: result.text,
|
|
237
|
-
iterations: String(result.iterationCount),
|
|
238
|
-
}),
|
|
239
|
-
usage: pickUsage(),
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
finally {
|
|
243
|
-
// Рестор точного скоупа родителя (compare-and-restore — свежий скоуп
|
|
244
|
-
// параллельного сиблинга не затирать). undefined — "без ограничений",
|
|
245
|
-
// пустым скоупом (запрет всего) становиться не должен.
|
|
246
|
-
restoreScope();
|
|
247
|
-
if (ctx.cleanup === restoreScope)
|
|
248
|
-
ctx.cleanup = undefined;
|
|
249
|
-
ctx.recursionDepth = currentDepth;
|
|
250
|
-
executor?.setRecursionDepth?.(currentDepth);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
catch (e) {
|
|
254
|
-
return { success: false, output: t("tool.subagent_error", { error: e.message }) };
|
|
255
|
-
}
|
|
256
|
-
},
|
|
257
|
-
};
|