micro-models-agent 2.16.0 → 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 +34 -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 -1211
- 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 -277
- package/dist/assets/setup.js +3 -816
- package/dist/assets/smd.js +29 -1665
- package/dist/assets/styles.css +1 -1592
- 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
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { t } from "../../i18n/index";
|
|
2
|
-
const MIN_CHARS = 1;
|
|
3
|
-
/** Оба ответа должны быть не короче — короткий честный ответ ("Готово.") дважды
|
|
4
|
-
* подряд не деградация и не должен жечь hallucination-retry. */
|
|
5
|
-
const MIN_REPEAT_CHARS = 120;
|
|
6
|
-
const MIN_REPEAT_WORDS = 20;
|
|
7
|
-
/** Пересечение слов выше порога считается повтором (было 0.5). */
|
|
8
|
-
const REPEAT_OVERLAP_THRESHOLD = 0.8;
|
|
9
|
-
/** Проверка уверенности: пустой ответ, дословный повтор, низкая diversity. */
|
|
10
|
-
export class ConfidenceCheck {
|
|
11
|
-
previousResponse = "";
|
|
12
|
-
/** Запоминает предыдущий ответ для детекции повторов. */
|
|
13
|
-
setPreviousResponse(response) {
|
|
14
|
-
this.previousResponse = response;
|
|
15
|
-
}
|
|
16
|
-
/** Валидирует ответ: retry на пустоту/повтор, warn на низкую diversity, иначе pass. */
|
|
17
|
-
validate(response) {
|
|
18
|
-
if (!response || response.length < MIN_CHARS) {
|
|
19
|
-
return {
|
|
20
|
-
status: "retry",
|
|
21
|
-
kind: "short",
|
|
22
|
-
reason: t("hall.short_response"),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
// Короткие реплики не флагуются: приветствие, скупое подтверждение или
|
|
26
|
-
// однострочник — валидный ответ. Реальное усечение ловит finish_reason
|
|
27
|
-
// провайдера ("length"), пустоту — retry выше.
|
|
28
|
-
const wordCount = response.split(/\s+/).filter(Boolean).length;
|
|
29
|
-
// Языконезависимо: детекция повторов по пересечению слов. Флагуем только
|
|
30
|
-
// если ОБА ответа содержательные — короткий ответ после длинного (или два
|
|
31
|
-
// коротких) не цикл.
|
|
32
|
-
if (this.previousResponse) {
|
|
33
|
-
const prevWords = this.previousResponse.split(/\s+/).filter(Boolean).length;
|
|
34
|
-
const bothSubstantive = response.length >= MIN_REPEAT_CHARS &&
|
|
35
|
-
this.previousResponse.length >= MIN_REPEAT_CHARS &&
|
|
36
|
-
wordCount >= MIN_REPEAT_WORDS &&
|
|
37
|
-
prevWords >= MIN_REPEAT_WORDS;
|
|
38
|
-
if (bothSubstantive) {
|
|
39
|
-
const overlap = this.calculateOverlap(response, this.previousResponse);
|
|
40
|
-
if (overlap > REPEAT_OVERLAP_THRESHOLD) {
|
|
41
|
-
return {
|
|
42
|
-
status: "retry",
|
|
43
|
-
kind: "repetition",
|
|
44
|
-
reason: t("hall.repetitive", { pct: Math.round(overlap * 100) }),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
// Языконезависимо: очень низкая diversity слов (одни и те же слова по кругу)
|
|
50
|
-
const words = response
|
|
51
|
-
.toLowerCase()
|
|
52
|
-
.split(/\s+/)
|
|
53
|
-
.filter((w) => w.length > 2);
|
|
54
|
-
if (words.length >= 10) {
|
|
55
|
-
const unique = new Set(words);
|
|
56
|
-
const diversity = unique.size / words.length;
|
|
57
|
-
if (diversity < 0.25) {
|
|
58
|
-
return {
|
|
59
|
-
status: "warn",
|
|
60
|
-
kind: "diversity",
|
|
61
|
-
reason: t("hall.repetitive", {
|
|
62
|
-
pct: Math.round((1 - diversity) * 100),
|
|
63
|
-
}),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return { status: "pass" };
|
|
68
|
-
}
|
|
69
|
-
calculateOverlap(a, b) {
|
|
70
|
-
const wordsA = new Set(a.toLowerCase().split(/\s+/).filter(Boolean));
|
|
71
|
-
const wordsB = new Set(b.toLowerCase().split(/\s+/).filter(Boolean));
|
|
72
|
-
const smaller = Math.min(wordsA.size, wordsB.size);
|
|
73
|
-
if (smaller === 0)
|
|
74
|
-
return 0;
|
|
75
|
-
let matches = 0;
|
|
76
|
-
for (const w of wordsB)
|
|
77
|
-
if (wordsA.has(w))
|
|
78
|
-
matches++;
|
|
79
|
-
return matches / smaller;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/** Проверка консистентности: решения, созданные/удалённые файлы сессии. */
|
|
2
|
-
export class ConsistencyCheck {
|
|
3
|
-
decisions = [];
|
|
4
|
-
createdFiles = new Set();
|
|
5
|
-
deletedFiles = new Set();
|
|
6
|
-
/** Запоминает решение агента. */
|
|
7
|
-
trackDecision(decision, location) {
|
|
8
|
-
this.decisions.push({ decision, location });
|
|
9
|
-
}
|
|
10
|
-
/** Отмечает созданный файл (снимает с него флаг удалённого). */
|
|
11
|
-
trackCreatedFile(path) {
|
|
12
|
-
this.createdFiles.add(path);
|
|
13
|
-
// Удаление с последующим пересозданием снимает флаг — иначе wasFileDeleted()
|
|
14
|
-
// считает файл пропавшим и после delete+create.
|
|
15
|
-
this.deletedFiles.delete(path);
|
|
16
|
-
}
|
|
17
|
-
/** Отмечает удалённый файл. */
|
|
18
|
-
trackDeletedFile(path) {
|
|
19
|
-
this.deletedFiles.add(path);
|
|
20
|
-
}
|
|
21
|
-
/** Все созданные файлы. */
|
|
22
|
-
getCreatedFiles() {
|
|
23
|
-
return Array.from(this.createdFiles);
|
|
24
|
-
}
|
|
25
|
-
/** Все удалённые файлы. */
|
|
26
|
-
getDeletedFiles() {
|
|
27
|
-
return Array.from(this.deletedFiles);
|
|
28
|
-
}
|
|
29
|
-
/** Все отслеживаемые решения. */
|
|
30
|
-
getDecisions() {
|
|
31
|
-
return this.decisions;
|
|
32
|
-
}
|
|
33
|
-
/** True, если есть хоть одно решение. */
|
|
34
|
-
hasDecisions() {
|
|
35
|
-
return this.decisions.length > 0;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// Оркестратор проверок галлюцинаций: confidence → factual → LLM-судья.
|
|
2
|
-
import { ConsistencyCheck } from "./consistency";
|
|
3
|
-
import { ConfidenceCheck } from "./confidence";
|
|
4
|
-
import { FactualCheck } from "./factual";
|
|
5
|
-
import { LLMJudge } from "./llm-judge";
|
|
6
|
-
/** Детектор галлюцинаций: объединяет проверки уверенности, фактов и LLM-судью. */
|
|
7
|
-
export class HallucinationDetector {
|
|
8
|
-
consistency;
|
|
9
|
-
confidence;
|
|
10
|
-
factual;
|
|
11
|
-
judge;
|
|
12
|
-
constructor(baseDir, llmProvider, options) {
|
|
13
|
-
this.consistency = new ConsistencyCheck();
|
|
14
|
-
this.confidence = new ConfidenceCheck();
|
|
15
|
-
this.factual = baseDir ? new FactualCheck(baseDir) : null;
|
|
16
|
-
// Судья opt-out: работает только если передан провайдер И вызывающий явно
|
|
17
|
-
// его не отключил (главный агент отключает по умолчанию через
|
|
18
|
-
// config.hallucination.judge.enabled).
|
|
19
|
-
const judgeEnabled = options?.judgeEnabled ?? true;
|
|
20
|
-
this.judge = llmProvider && judgeEnabled ? new LLMJudge(llmProvider) : null;
|
|
21
|
-
}
|
|
22
|
-
/** Доступ к проверке консистентности (решения, созданные/удалённые файлы). */
|
|
23
|
-
getConsistencyCheck() {
|
|
24
|
-
return this.consistency;
|
|
25
|
-
}
|
|
26
|
-
/** Доступ к проверке уверенности (повторы, diversity). */
|
|
27
|
-
getConfidenceCheck() {
|
|
28
|
-
return this.confidence;
|
|
29
|
-
}
|
|
30
|
-
/** Добавляет файлы, известные из сводок компакции, в фактическую проверку. */
|
|
31
|
-
addKnownFiles(files) {
|
|
32
|
-
this.factual?.addKnownFiles(files);
|
|
33
|
-
}
|
|
34
|
-
/** Валидирует ответ: retry/block уверенности → факты → LLM-судья + warn-агрегация. */
|
|
35
|
-
async validate(response) {
|
|
36
|
-
const confidenceResult = this.confidence.validate(response);
|
|
37
|
-
if (confidenceResult.status === "retry" || confidenceResult.status === "block") {
|
|
38
|
-
return confidenceResult;
|
|
39
|
-
}
|
|
40
|
-
const deletedFiles = new Set(this.consistency.getDeletedFiles());
|
|
41
|
-
const factualResult = this.factual?.validate(response, deletedFiles);
|
|
42
|
-
if (factualResult && factualResult.status !== "pass") {
|
|
43
|
-
return factualResult;
|
|
44
|
-
}
|
|
45
|
-
// Судья по консистентности (LLM): быстрый путь (нет решений) — без LLM-вызова.
|
|
46
|
-
const judgeResult = this.judge ? await this.judge.validate(response, this.consistency) : null;
|
|
47
|
-
const warnings = [];
|
|
48
|
-
if (judgeResult && judgeResult.status === "warn")
|
|
49
|
-
warnings.push(judgeResult.reason || "");
|
|
50
|
-
if (confidenceResult.status === "warn")
|
|
51
|
-
warnings.push(confidenceResult.reason || "");
|
|
52
|
-
if (warnings.length > 0) {
|
|
53
|
-
return { status: "warn", reason: warnings.join("; ") };
|
|
54
|
-
}
|
|
55
|
-
return { status: "pass" };
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
// Фактическая проверка: упомянутые в ответе пути файлов против диска и индекса.
|
|
2
|
-
import { existsSync, readdirSync } from "fs";
|
|
3
|
-
import { resolve, isAbsolute, join } from "path";
|
|
4
|
-
import { t } from "../../i18n/index";
|
|
5
|
-
import { extractFileLikeTokens, stripUrls } from "./js-identifiers";
|
|
6
|
-
import { HALLUCINATION_NAME_CACHE_TTL_MS, HALLUCINATION_RESCAN_COOLDOWN_MS, } from "../../config/timeouts";
|
|
7
|
-
/** Генерированные/кэшированные каталоги — пропускаем при поиске голых имён. */
|
|
8
|
-
const IGNORED_DIRS = new Set([
|
|
9
|
-
"node_modules",
|
|
10
|
-
".git",
|
|
11
|
-
"dist",
|
|
12
|
-
"build",
|
|
13
|
-
"coverage",
|
|
14
|
-
".mma",
|
|
15
|
-
"_testing",
|
|
16
|
-
]);
|
|
17
|
-
/** Проверка фактов: упомянутые файлы существуют на диске/в индексе, иначе warn. */
|
|
18
|
-
export class FactualCheck {
|
|
19
|
-
baseDir;
|
|
20
|
-
nameCache = null;
|
|
21
|
-
nameCacheTime = 0;
|
|
22
|
-
lastRescan = 0;
|
|
23
|
-
static NAME_CACHE_TTL_MS = HALLUCINATION_NAME_CACHE_TTL_MS;
|
|
24
|
-
static RESCAN_COOLDOWN_MS = HALLUCINATION_RESCAN_COOLDOWN_MS;
|
|
25
|
-
static MAX_INDEXED_FILES = 20_000;
|
|
26
|
-
/** Файлы, известные из сводок компакции — переживают сбросы контекста. */
|
|
27
|
-
knownFiles = new Set();
|
|
28
|
-
constructor(baseDir) {
|
|
29
|
-
this.baseDir = baseDir;
|
|
30
|
-
}
|
|
31
|
-
/** Добавляет пути, известные из сводок компакции. Проверяются раньше скана ФС:
|
|
32
|
-
* голые имена из уплотнённых ходов узнаются, даже если каталог в IGNORED_DIRS. */
|
|
33
|
-
addKnownFiles(files) {
|
|
34
|
-
for (const f of files)
|
|
35
|
-
this.knownFiles.add(f);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Валидирует пути файлов в ответе: warn со списком отсутствующих, иначе pass.
|
|
39
|
-
* @param response текст ответа модели; @param deletedFiles уже удалённые (не флагуются).
|
|
40
|
-
*/
|
|
41
|
-
validate(response, deletedFiles) {
|
|
42
|
-
const filePaths = this.extractFilePaths(response);
|
|
43
|
-
if (filePaths.length === 0)
|
|
44
|
-
return { status: "pass" };
|
|
45
|
-
const deletedBasenames = deletedFiles
|
|
46
|
-
? new Set([...deletedFiles].map((p) => p.split(/[/\\]/).pop() ?? p))
|
|
47
|
-
: undefined;
|
|
48
|
-
const nonExistent = [];
|
|
49
|
-
for (const fp of filePaths) {
|
|
50
|
-
if (deletedBasenames?.has(fp))
|
|
51
|
-
continue;
|
|
52
|
-
if (!this.pathExists(fp)) {
|
|
53
|
-
nonExistent.push(fp);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (nonExistent.length > 0) {
|
|
57
|
-
return {
|
|
58
|
-
status: "warn",
|
|
59
|
-
reason: t("hall.unknown_paths", {
|
|
60
|
-
paths: nonExistent.slice(0, 5).join(", "),
|
|
61
|
-
}),
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
return { status: "pass" };
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Голые имена ("bikes.json") и относительные пути ("src/data/bikes.json")
|
|
68
|
-
* садятся на дерево проекта. Абсолютные проверяются как есть.
|
|
69
|
-
*/
|
|
70
|
-
pathExists(fp) {
|
|
71
|
-
if (isAbsolute(fp))
|
|
72
|
-
return existsSync(fp);
|
|
73
|
-
// Сначала известные файлы из сводок компакции
|
|
74
|
-
if (this.knownFiles.has(fp))
|
|
75
|
-
return true;
|
|
76
|
-
for (const cand of this.dotfileVariants(fp)) {
|
|
77
|
-
if (this.knownFiles.has(cand))
|
|
78
|
-
return true;
|
|
79
|
-
if (existsSync(resolve(this.baseDir, cand)))
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
// "foo.json" без каталога — голое имя, которое может жить где угодно под
|
|
83
|
-
// baseDir (напр. src/data/bikes.json). Резолв только от корня давал ложные
|
|
84
|
-
// "unknown file".
|
|
85
|
-
if (!fp.includes("/") && !fp.includes("\\")) {
|
|
86
|
-
return this.bareNameExists(fp);
|
|
87
|
-
}
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Токен-regex не якорит ведущую точку (`\b` не матчится между не-словом и
|
|
92
|
-
* `.`), поэтому дотфайлы (.prettierrc.json, .env, …) извлекаются как
|
|
93
|
-
* "prettierrc.json". Перед вердиктом "нет файла" пробуем basename с точкой,
|
|
94
|
-
* "src/config.json" даёт и "src/.config.json", а "mma/index-cache.json" —
|
|
95
|
-
* и ".mma/index-cache.json" (родители с точкой).
|
|
96
|
-
*/
|
|
97
|
-
dotfileVariants(fp) {
|
|
98
|
-
const variants = [fp];
|
|
99
|
-
const sep = fp.includes("\\") ? "\\" : "/";
|
|
100
|
-
const parts = fp.split(sep);
|
|
101
|
-
// Пробуем basename с точкой (старая логика)
|
|
102
|
-
const base = parts[parts.length - 1];
|
|
103
|
-
if (!base.startsWith(".")) {
|
|
104
|
-
const withDotBase = [...parts.slice(0, -1), `.${base}`].join(sep);
|
|
105
|
-
variants.push(withDotBase);
|
|
106
|
-
}
|
|
107
|
-
// Пробуем точку на каждом родительском компоненте
|
|
108
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
109
|
-
if (!parts[i].startsWith(".")) {
|
|
110
|
-
const dotted = [...parts.slice(0, i), `.${parts[i]}`, ...parts.slice(i + 1)].join(sep);
|
|
111
|
-
if (!variants.includes(dotted))
|
|
112
|
-
variants.push(dotted);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return variants;
|
|
116
|
-
}
|
|
117
|
-
bareNameExists(name) {
|
|
118
|
-
for (const cand of this.dotfileVariants(name)) {
|
|
119
|
-
if (existsSync(resolve(this.baseDir, cand)))
|
|
120
|
-
return true;
|
|
121
|
-
if (this.indexHas(cand))
|
|
122
|
-
return true;
|
|
123
|
-
// Известные файлы: голое имя может совпасть с полным путём из компакции
|
|
124
|
-
for (const known of this.knownFiles) {
|
|
125
|
-
if (known.endsWith(`/${cand}`) || known.endsWith(`\\${cand}`) || known === cand) {
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
// Имя файла может содержать пробел: «отчёт 1.txt» извлекается токеном
|
|
131
|
-
// «1.txt». Прежде чем объявлять файл отсутствующим, проверяем, не
|
|
132
|
-
// заканчивается ли какое-то известное имя на « 1.txt».
|
|
133
|
-
const spaceName = ` ${name}`;
|
|
134
|
-
for (const known of this.knownFiles) {
|
|
135
|
-
if (known.endsWith(spaceName))
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
for (const key of this.getNameIndex().keys()) {
|
|
139
|
-
if (key.endsWith(spaceName))
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
// write_file текущей сессии мог создать файл после сборки индекса.
|
|
143
|
-
// Перед warn — разовый рескан (rate-limited).
|
|
144
|
-
const now = Date.now();
|
|
145
|
-
if (now - this.lastRescan < FactualCheck.RESCAN_COOLDOWN_MS)
|
|
146
|
-
return false;
|
|
147
|
-
this.lastRescan = now;
|
|
148
|
-
this.nameCache = null;
|
|
149
|
-
this.nameCacheTime = 0;
|
|
150
|
-
return this.indexHas(name);
|
|
151
|
-
}
|
|
152
|
-
indexHas(name) {
|
|
153
|
-
return (this.getNameIndex().get(name)?.length ?? 0) > 0;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Индекс basename → пути, пересборка каждые NAME_CACHE_TTL_MS, чтобы новые
|
|
157
|
-
* файлы (write_file) подхватывались без полного скана на каждый ответ.
|
|
158
|
-
*/
|
|
159
|
-
getNameIndex() {
|
|
160
|
-
const now = Date.now();
|
|
161
|
-
if (this.nameCache && now - this.nameCacheTime < FactualCheck.NAME_CACHE_TTL_MS) {
|
|
162
|
-
return this.nameCache;
|
|
163
|
-
}
|
|
164
|
-
const index = new Map();
|
|
165
|
-
const scanned = this.scanDir(this.baseDir, index, 0);
|
|
166
|
-
if (scanned > 0 || index.size > 0) {
|
|
167
|
-
this.nameCache = index;
|
|
168
|
-
this.nameCacheTime = now;
|
|
169
|
-
}
|
|
170
|
-
return index;
|
|
171
|
-
}
|
|
172
|
-
scanDir(dir, index, count) {
|
|
173
|
-
if (count >= FactualCheck.MAX_INDEXED_FILES)
|
|
174
|
-
return count;
|
|
175
|
-
let entries;
|
|
176
|
-
try {
|
|
177
|
-
entries = readdirSync(dir, { withFileTypes: true });
|
|
178
|
-
}
|
|
179
|
-
catch {
|
|
180
|
-
return count;
|
|
181
|
-
}
|
|
182
|
-
for (const entry of entries) {
|
|
183
|
-
if (count >= FactualCheck.MAX_INDEXED_FILES)
|
|
184
|
-
break;
|
|
185
|
-
const full = join(dir, entry.name);
|
|
186
|
-
if (entry.isDirectory()) {
|
|
187
|
-
if (!IGNORED_DIRS.has(entry.name)) {
|
|
188
|
-
count = this.scanDir(full, index, count);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
else if (entry.isFile()) {
|
|
192
|
-
const list = index.get(entry.name);
|
|
193
|
-
if (list)
|
|
194
|
-
list.push(full);
|
|
195
|
-
else
|
|
196
|
-
index.set(entry.name, [full]);
|
|
197
|
-
count++;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return count;
|
|
201
|
-
}
|
|
202
|
-
extractFilePaths(text) {
|
|
203
|
-
return extractFileLikeTokens(stripUrls(text));
|
|
204
|
-
}
|
|
205
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// Детектор галлюцинаций: реэкспорт проверок (консистентность, уверенность, факты, LLM-судья).
|
|
2
|
-
export { HallucinationDetector } from "./detector";
|
|
3
|
-
export { ConsistencyCheck } from "./consistency";
|
|
4
|
-
export { ConfidenceCheck } from "./confidence";
|
|
5
|
-
export { FactualCheck } from "./factual";
|
|
6
|
-
export { LLMJudge } from "./llm-judge";
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JS/TS-глобалы, чей member access (`process.env`, `console.log`, `Math.max`)
|
|
3
|
-
* похож на путь к файлу для `\b[\w./\\-]+\.[a-z]+\b`-regex'ов, но является
|
|
4
|
-
* кодом, а не файлом. Общий для фактической проверки галлюцинаций и аудитора
|
|
5
|
-
* исполнения — оба перестают флаговать member access как "потерянные файлы".
|
|
6
|
-
*
|
|
7
|
-
* Здесь же общий фильтр "этот токен вообще файл?"
|
|
8
|
-
* (`isFilePathLike` / `extractFileLikeTokens` / `stripUrls`), чтобы два
|
|
9
|
-
* экстрактора не расходились (было: аудитор считал hostname URL
|
|
10
|
-
* `whom-pointing-jewel-maine.trycloudflare.com` в шаге плана потерянным
|
|
11
|
-
* файлом, а фактическая проверка корректно игнорировала).
|
|
12
|
-
*
|
|
13
|
-
* Голые токены `word.ext` гейтятся allow-list'ом реальных расширений
|
|
14
|
-
* (`FILE_EXTENSIONS`), а не deny-list'ом TLD — домен в любом нынешнем или
|
|
15
|
-
* будущем TLD (`Gismeteo.by`, `weather.com`, `example.xyz`) никогда не
|
|
16
|
-
* спутается с файлом, и список TLD вести не нужно.
|
|
17
|
-
*/
|
|
18
|
-
const JS_GLOBALS = new Set([
|
|
19
|
-
"process",
|
|
20
|
-
"console",
|
|
21
|
-
"math",
|
|
22
|
-
"json",
|
|
23
|
-
"global",
|
|
24
|
-
"globalthis",
|
|
25
|
-
"window",
|
|
26
|
-
"document",
|
|
27
|
-
"buffer",
|
|
28
|
-
"module",
|
|
29
|
-
"require",
|
|
30
|
-
"exports",
|
|
31
|
-
"url",
|
|
32
|
-
"promise",
|
|
33
|
-
"array",
|
|
34
|
-
"object",
|
|
35
|
-
"string",
|
|
36
|
-
"number",
|
|
37
|
-
"boolean",
|
|
38
|
-
"symbol",
|
|
39
|
-
"date",
|
|
40
|
-
"regexp",
|
|
41
|
-
"error",
|
|
42
|
-
"map",
|
|
43
|
-
"set",
|
|
44
|
-
"weakmap",
|
|
45
|
-
"weakset",
|
|
46
|
-
"proxy",
|
|
47
|
-
"reflect",
|
|
48
|
-
"intl",
|
|
49
|
-
"crypto",
|
|
50
|
-
"performance",
|
|
51
|
-
"fetch",
|
|
52
|
-
"navigator",
|
|
53
|
-
"location",
|
|
54
|
-
"settimeout",
|
|
55
|
-
"setinterval",
|
|
56
|
-
"cleartimeout",
|
|
57
|
-
"clearinterval",
|
|
58
|
-
"queuemicrotask",
|
|
59
|
-
"structuredclone",
|
|
60
|
-
"textencoder",
|
|
61
|
-
"textdecoder",
|
|
62
|
-
"atomics",
|
|
63
|
-
"sharedarraybuffer",
|
|
64
|
-
"dataview",
|
|
65
|
-
"arraybuffer",
|
|
66
|
-
"bigint",
|
|
67
|
-
"infinity",
|
|
68
|
-
"nan",
|
|
69
|
-
"undefined",
|
|
70
|
-
"bun",
|
|
71
|
-
"deno",
|
|
72
|
-
"node",
|
|
73
|
-
]);
|
|
74
|
-
/**
|
|
75
|
-
* True, если `candidate` начинается с известного JS/TS-глобала и точки
|
|
76
|
-
* (`process.env`, `console.log`, частичные совпадения `process.env.NODE`
|
|
77
|
-
* от `\b[\w./\\-]+\.[a-z]+`-regex'ов) — member access, не путь к файлу.
|
|
78
|
-
*/
|
|
79
|
-
export function isJsMemberAccess(candidate) {
|
|
80
|
-
const lower = candidate.toLowerCase();
|
|
81
|
-
const m = lower.match(/^([\w-]+)\./);
|
|
82
|
-
return m !== null && JS_GLOBALS.has(m[1]);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Расширения, делающие голый токен `word.ext` похожим на путь к файлу.
|
|
86
|
-
*
|
|
87
|
-
* Allow-list осознанно: перечислять всё, что НЕ файл (TLD, бренды, …) —
|
|
88
|
-
* хрупкая эвристика, которая никогда не полна. Вместо этого голый `word.ext`
|
|
89
|
-
* считается файлом только при известном расширении — так `Gismeteo.by`,
|
|
90
|
-
* `weather.com` и любой будущий TLD не флагуются, а настоящие
|
|
91
|
-
* `config.json` / `helper.ts` — да.
|
|
92
|
-
*/
|
|
93
|
-
const FILE_EXTENSIONS = new Set([
|
|
94
|
-
// исходники / код
|
|
95
|
-
"ts",
|
|
96
|
-
"tsx",
|
|
97
|
-
"js",
|
|
98
|
-
"jsx",
|
|
99
|
-
"mjs",
|
|
100
|
-
"cjs",
|
|
101
|
-
"py",
|
|
102
|
-
"pyc",
|
|
103
|
-
"rb",
|
|
104
|
-
"go",
|
|
105
|
-
"rs",
|
|
106
|
-
"java",
|
|
107
|
-
"jar",
|
|
108
|
-
"kt",
|
|
109
|
-
"kts",
|
|
110
|
-
"c",
|
|
111
|
-
"h",
|
|
112
|
-
"cc",
|
|
113
|
-
"cpp",
|
|
114
|
-
"cxx",
|
|
115
|
-
"hpp",
|
|
116
|
-
"hh",
|
|
117
|
-
"cs",
|
|
118
|
-
"php",
|
|
119
|
-
"swift",
|
|
120
|
-
"m",
|
|
121
|
-
"mm",
|
|
122
|
-
"lua",
|
|
123
|
-
"pl",
|
|
124
|
-
"sh",
|
|
125
|
-
"bash",
|
|
126
|
-
"zsh",
|
|
127
|
-
"fish",
|
|
128
|
-
"bat",
|
|
129
|
-
"cmd",
|
|
130
|
-
"ps1",
|
|
131
|
-
"vue",
|
|
132
|
-
"svelte",
|
|
133
|
-
"dart",
|
|
134
|
-
// конфиги / данные / доки
|
|
135
|
-
"json",
|
|
136
|
-
"jsonc",
|
|
137
|
-
"json5",
|
|
138
|
-
"yaml",
|
|
139
|
-
"yml",
|
|
140
|
-
"toml",
|
|
141
|
-
"ini",
|
|
142
|
-
"cfg",
|
|
143
|
-
"conf",
|
|
144
|
-
"env",
|
|
145
|
-
"xml",
|
|
146
|
-
"drawio",
|
|
147
|
-
"html",
|
|
148
|
-
"htm",
|
|
149
|
-
"md",
|
|
150
|
-
"markdown",
|
|
151
|
-
"rst",
|
|
152
|
-
"txt",
|
|
153
|
-
"log",
|
|
154
|
-
"csv",
|
|
155
|
-
"tsv",
|
|
156
|
-
"lock",
|
|
157
|
-
"sql",
|
|
158
|
-
"sqlite",
|
|
159
|
-
"db",
|
|
160
|
-
"wasm",
|
|
161
|
-
"map",
|
|
162
|
-
"css",
|
|
163
|
-
"scss",
|
|
164
|
-
"sass",
|
|
165
|
-
"less",
|
|
166
|
-
// ассеты / бинарники
|
|
167
|
-
"svg",
|
|
168
|
-
"png",
|
|
169
|
-
"jpg",
|
|
170
|
-
"jpeg",
|
|
171
|
-
"gif",
|
|
172
|
-
"webp",
|
|
173
|
-
"bmp",
|
|
174
|
-
"ico",
|
|
175
|
-
"avif",
|
|
176
|
-
"tiff",
|
|
177
|
-
"pdf",
|
|
178
|
-
"doc",
|
|
179
|
-
"docx",
|
|
180
|
-
"xls",
|
|
181
|
-
"xlsx",
|
|
182
|
-
"ppt",
|
|
183
|
-
"pptx",
|
|
184
|
-
"odt",
|
|
185
|
-
"ods",
|
|
186
|
-
"zip",
|
|
187
|
-
"gz",
|
|
188
|
-
"tar",
|
|
189
|
-
"tgz",
|
|
190
|
-
"bz2",
|
|
191
|
-
"xz",
|
|
192
|
-
"7z",
|
|
193
|
-
"rar",
|
|
194
|
-
"bin",
|
|
195
|
-
"exe",
|
|
196
|
-
"dll",
|
|
197
|
-
"so",
|
|
198
|
-
"o",
|
|
199
|
-
"a",
|
|
200
|
-
"dylib",
|
|
201
|
-
]);
|
|
202
|
-
/** Известные рантаймы/библиотеки на .js/.ts, которые НЕ файлы. */
|
|
203
|
-
const TECH_NAMES = new Set([
|
|
204
|
-
"node.js",
|
|
205
|
-
"react.js",
|
|
206
|
-
"vue.js",
|
|
207
|
-
"next.js",
|
|
208
|
-
"angular.js",
|
|
209
|
-
"express.js",
|
|
210
|
-
"deno.js",
|
|
211
|
-
"qwik.js",
|
|
212
|
-
"svelte.js",
|
|
213
|
-
"jquery.js",
|
|
214
|
-
]);
|
|
215
|
-
const FILE_TOKEN_RE = /\b(?:[a-zA-Z]:[\\/])?[\w./\\-]+\.[a-z]{1,6}\b/gi;
|
|
216
|
-
/**
|
|
217
|
-
* True, если `candidate` — правдоподобный токен пути: у пути с разделителем
|
|
218
|
-
* последний сегмент обязан нести непустой stem перед расширением (сегменты
|
|
219
|
-
* только из расширения вроде `tsx/.ts` отбрасываются), а голый `word.ext` —
|
|
220
|
-
* файл только при известном расширении (домены `Gismeteo.by` / `weather.com`
|
|
221
|
-
* — никогда файлы). JS member access (`process.env`) и техно-имена
|
|
222
|
-
* (`node.js`) — никогда файлы.
|
|
223
|
-
*/
|
|
224
|
-
export function isFilePathLike(s) {
|
|
225
|
-
const lower = s.toLowerCase();
|
|
226
|
-
if (TECH_NAMES.has(lower))
|
|
227
|
-
return false;
|
|
228
|
-
if (isJsMemberAccess(s))
|
|
229
|
-
return false;
|
|
230
|
-
const ext = s.split(".").pop()?.toLowerCase() || "";
|
|
231
|
-
if (!s.includes("/") && !s.includes("\\")) {
|
|
232
|
-
if (!/^\w+\.[a-z]{1,6}$/i.test(s))
|
|
233
|
-
return false;
|
|
234
|
-
return FILE_EXTENSIONS.has(ext);
|
|
235
|
-
}
|
|
236
|
-
// Токены с разделителем: требуем у ПОСЛЕДНЕГО сегмента настоящее имя
|
|
237
|
-
// (непустой stem перед расширением). Иначе сегмент только из расширения
|
|
238
|
-
// вроде "tsx/.ts" (из ".tsx/.ts" в описании шага) или дотфайл ("src/.env")
|
|
239
|
-
// читается как файл, и deliverable-gate требует "создать tsx/.ts"
|
|
240
|
-
// (было в ses_mstda6uo: шаг "Проверить что остались только .tsx/.ts файлы").
|
|
241
|
-
const last = s.split(/[\\/]/).pop() ?? "";
|
|
242
|
-
const lastDot = last.lastIndexOf(".");
|
|
243
|
-
if (lastDot <= 0)
|
|
244
|
-
return false;
|
|
245
|
-
return true;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Извлекает дедуплицированные файлоподобные токены из свободного текста.
|
|
249
|
-
* Голые `word.ext` фильтруются через `isFilePathLike` (allow-list реальных
|
|
250
|
-
* расширений — хосты/TLD вроде `whom-pointing-jewel-maine.trycloudflare.com`
|
|
251
|
-
* или `Gismeteo.by` не выживают); URL вырезаются заранее, чтобы
|
|
252
|
-
* `https://host/repo.git` не выжил как "файл".
|
|
253
|
-
*/
|
|
254
|
-
export function extractFileLikeTokens(text) {
|
|
255
|
-
const matches = text.match(FILE_TOKEN_RE) || [];
|
|
256
|
-
return [...new Set(matches.filter(isFilePathLike))];
|
|
257
|
-
}
|
|
258
|
-
/** Вырезает URL (scheme://… до пробела/кавычки), чтобы они не парсились как пути. */
|
|
259
|
-
export function stripUrls(text) {
|
|
260
|
-
return text.replace(/\bhttps?:\/\/[^\s"'<>]+/gi, " ");
|
|
261
|
-
}
|