micro-models-agent 2.16.1 → 2.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +8 -3
- package/dist/assets/app.js +1 -314
- package/dist/assets/hljs.js +5 -1244
- package/dist/assets/index.html +11 -0
- package/dist/assets/js/api.js +1 -28
- package/dist/assets/js/core/menus.js +1 -0
- package/dist/assets/js/core/store/feed.js +1 -0
- package/dist/assets/js/core/store/index.js +1 -0
- package/dist/assets/js/core/store/session.js +1 -0
- package/dist/assets/js/core/store/settings.js +1 -0
- package/dist/assets/js/core/store/tabs.js +1 -0
- package/dist/assets/js/dialog.js +1 -105
- package/dist/assets/js/dom.js +1 -178
- package/dist/assets/js/feed/core.js +1 -0
- package/dist/assets/js/feed/history.js +1 -0
- package/dist/assets/js/feed/plan.js +1 -0
- package/dist/assets/js/feed/question.js +3 -0
- package/dist/assets/js/feed/sidebar.js +1 -0
- package/dist/assets/js/feed/stream.js +1 -0
- package/dist/assets/js/feed/turn.js +5 -0
- package/dist/assets/js/feed.js +1 -1250
- package/dist/assets/js/format.js +2 -122
- package/dist/assets/js/i18n.js +1 -46
- package/dist/assets/js/rail.js +1 -114
- package/dist/assets/js/session/cmdk.js +1 -0
- package/dist/assets/js/session/composer.js +1 -0
- package/dist/assets/js/session/sessions-menu.js +1 -0
- package/dist/assets/js/session/tabs.js +1 -0
- package/dist/assets/js/settings/controls.js +1 -0
- package/dist/assets/js/settings/editors.js +1 -0
- package/dist/assets/js/settings/form.js +1 -0
- package/dist/assets/js/settings/modal.js +1 -0
- package/dist/assets/js/settings/panels.js +1 -0
- package/dist/assets/js/settings/providers.js +1 -0
- package/dist/assets/js/settings/search.js +1 -0
- package/dist/assets/js/settings/subdialog.js +1 -0
- package/dist/assets/js/settings/write.js +1 -0
- package/dist/assets/js/settings.js +1 -1914
- package/dist/assets/js/sidebar/core.js +1 -0
- package/dist/assets/js/sidebar/lsp.js +2 -0
- package/dist/assets/js/sidebar/map.js +1 -0
- package/dist/assets/js/sidebar/state.js +1 -0
- package/dist/assets/js/sidebar/trace.js +5 -0
- package/dist/assets/js/sidebar.js +1 -705
- package/dist/assets/js/store.js +1 -82
- package/dist/assets/js/subdialog.js +1 -0
- package/dist/assets/md.js +1 -291
- package/dist/assets/setup.js +3 -816
- package/dist/assets/smd.js +29 -1665
- package/dist/assets/styles.css +1 -1598
- package/dist/certification/certifications.json +1 -494
- package/dist/i18n/en.json +1 -1851
- package/dist/i18n/ru.json +1 -1854
- package/dist/main.js +815 -55797
- package/dist/modules/browser/bridge-server.mjs +2 -252
- package/package.json +10 -5
- package/dist/assets/js/settings-controls.js +0 -452
- package/dist/assets/js/tabs.js +0 -867
- package/dist/cli/cache-line.js +0 -31
- package/dist/cli/command-suggest.js +0 -39
- package/dist/cli/commands.js +0 -781
- package/dist/cli/completer.js +0 -268
- package/dist/cli/index.js +0 -3
- package/dist/cli/json-payload.js +0 -32
- package/dist/cli/main.js +0 -346
- package/dist/cli/onboarding-commands.js +0 -126
- package/dist/cli/plugin-commands.js +0 -38
- package/dist/cli/relaunch.js +0 -40
- package/dist/cli/repl-commands-lsp.js +0 -75
- package/dist/cli/repl-commands-skills.js +0 -105
- package/dist/cli/repl-commands.js +0 -1218
- package/dist/cli/repl.js +0 -1238
- package/dist/cli/run-result.js +0 -38
- package/dist/cli/security-commands.js +0 -177
- package/dist/cli/setup-order.js +0 -6
- package/dist/cli/setup-prompt.js +0 -50
- package/dist/cli/setup.js +0 -161
- package/dist/cli/web-command.js +0 -98
- package/dist/config/budget.js +0 -48
- package/dist/config/config.js +0 -345
- package/dist/config/defaults.js +0 -197
- package/dist/config/domains.js +0 -135
- package/dist/config/env.js +0 -46
- package/dist/config/experts.js +0 -17
- package/dist/config/index.js +0 -5
- package/dist/config/paths.js +0 -56
- package/dist/config/redact.js +0 -44
- package/dist/config/registry-extra.js +0 -334
- package/dist/config/registry.js +0 -584
- package/dist/config/security.js +0 -212
- package/dist/config/timeouts.js +0 -74
- package/dist/config/types.js +0 -1
- package/dist/config/utils.js +0 -57
- package/dist/core/agent/artifact-progress.js +0 -59
- package/dist/core/agent/artifact-resolve.js +0 -79
- package/dist/core/agent/audit-gate.js +0 -53
- package/dist/core/agent/compaction.js +0 -89
- package/dist/core/agent/constants.js +0 -90
- package/dist/core/agent/context-log.js +0 -454
- package/dist/core/agent/context-renderer.js +0 -45
- package/dist/core/agent/critic-gate.js +0 -132
- package/dist/core/agent/hallucination-gate.js +0 -197
- package/dist/core/agent/loop-state.js +0 -68
- package/dist/core/agent/prefix-monitor.js +0 -101
- package/dist/core/agent/reasoning-resolver.js +0 -65
- package/dist/core/agent/token-tracker.js +0 -99
- package/dist/core/agent/tool-batch.js +0 -312
- package/dist/core/agent/tool-images.js +0 -18
- package/dist/core/agent/tool-output.js +0 -116
- package/dist/core/agent/tool-pairing.js +0 -60
- package/dist/core/agent-moe.js +0 -248
- package/dist/core/agent.js +0 -1299
- package/dist/core/bootstrap/agent-phase.js +0 -66
- package/dist/core/bootstrap/config-phase.js +0 -86
- package/dist/core/bootstrap/modules-phase.js +0 -269
- package/dist/core/bootstrap/provider-phase.js +0 -183
- package/dist/core/bootstrap/session-phase.js +0 -204
- package/dist/core/bootstrap/state.js +0 -94
- package/dist/core/bootstrap/workspace-phase.js +0 -115
- package/dist/core/bootstrap.js +0 -112
- package/dist/core/crash-handler.js +0 -62
- package/dist/core/environment.js +0 -224
- package/dist/core/host-plan.js +0 -43
- package/dist/core/host.js +0 -23
- package/dist/core/index.js +0 -3
- package/dist/core/prompt-builder.js +0 -95
- package/dist/core/prompt-overflow.js +0 -306
- package/dist/core/session-logger.js +0 -375
- package/dist/core/system-prompt.js +0 -117
- package/dist/core/types.js +0 -1
- package/dist/core/version.js +0 -28
- package/dist/core/web-host.js +0 -34
- package/dist/core/workspace.js +0 -80
- package/dist/i18n/index.js +0 -80
- package/dist/index.js +0 -30
- package/dist/llm/cache-usage.js +0 -76
- package/dist/llm/image-utils.js +0 -138
- package/dist/llm/index.js +0 -4
- package/dist/llm/llm-errors.js +0 -50
- package/dist/llm/model-loader.js +0 -86
- package/dist/llm/models-dev.js +0 -121
- package/dist/llm/openai-compat.js +0 -756
- package/dist/llm/orchestrator.js +0 -294
- package/dist/llm/provider-budget.js +0 -68
- package/dist/llm/provider-context.js +0 -233
- package/dist/llm/provider.js +0 -9
- package/dist/llm/response.js +0 -44
- package/dist/llm/stream-state.js +0 -26
- package/dist/llm/token-counter.js +0 -83
- package/dist/llm/types.js +0 -1
- package/dist/logger/app-logger.js +0 -212
- package/dist/logger/file-log.js +0 -160
- package/dist/logger/index.js +0 -2
- package/dist/migration/backup.js +0 -56
- package/dist/migration/detect.js +0 -61
- package/dist/migration/index.js +0 -3
- package/dist/modules/artifacts/store.js +0 -62
- package/dist/modules/browser/actions.js +0 -79
- package/dist/modules/browser/bridge-client.js +0 -203
- package/dist/modules/browser/bridge-path.js +0 -10
- package/dist/modules/browser/console-buffer.js +0 -37
- package/dist/modules/browser/cookie-store.js +0 -29
- package/dist/modules/browser/driver-types.js +0 -1
- package/dist/modules/browser/driver.js +0 -186
- package/dist/modules/browser/index.js +0 -9
- package/dist/modules/browser/module.js +0 -30
- package/dist/modules/browser/session.js +0 -322
- package/dist/modules/browser/snapshot.js +0 -154
- package/dist/modules/browser/types.js +0 -13
- package/dist/modules/certification/cli.js +0 -264
- package/dist/modules/certification/fact-checker.js +0 -90
- package/dist/modules/certification/loader.js +0 -127
- package/dist/modules/certification/manifest.js +0 -231
- package/dist/modules/certification/runner.js +0 -233
- package/dist/modules/certification/scenarios.js +0 -586
- package/dist/modules/certification/syntax-scenarios.js +0 -50
- package/dist/modules/certification/types.js +0 -1
- package/dist/modules/context/chunk-query.js +0 -122
- package/dist/modules/context/fact-extractor.js +0 -170
- package/dist/modules/context/history.js +0 -15
- package/dist/modules/context/index.js +0 -2
- package/dist/modules/context/manager.js +0 -482
- package/dist/modules/critic/client.js +0 -176
- package/dist/modules/critic/evidence.js +0 -81
- package/dist/modules/critic/provider.js +0 -45
- package/dist/modules/critic/tools.js +0 -78
- package/dist/modules/critic/types.js +0 -1
- package/dist/modules/execution/audit-runners.js +0 -206
- package/dist/modules/execution/auditor.js +0 -222
- package/dist/modules/execution/execution-plugin.js +0 -478
- package/dist/modules/execution/index.js +0 -8
- package/dist/modules/execution/input-from.js +0 -70
- package/dist/modules/execution/module.js +0 -891
- package/dist/modules/execution/moe-executor.js +0 -443
- package/dist/modules/execution/plan-actions.js +0 -642
- package/dist/modules/execution/plan-checks.js +0 -35
- package/dist/modules/execution/plan-coverage.js +0 -71
- package/dist/modules/execution/plan-persister.js +0 -46
- package/dist/modules/execution/plan-steps.js +0 -31
- package/dist/modules/execution/plan-store.js +0 -274
- package/dist/modules/execution/plan-tool.js +0 -249
- package/dist/modules/execution/plan-validator.js +0 -197
- package/dist/modules/execution/planner.js +0 -103
- package/dist/modules/execution/stuck-detector.js +0 -834
- package/dist/modules/execution/tracker.js +0 -92
- package/dist/modules/execution/transient-error.js +0 -30
- package/dist/modules/execution/types.js +0 -1
- package/dist/modules/execution/verifier.js +0 -343
- package/dist/modules/execution/windows-commands.js +0 -52
- package/dist/modules/hallucination/artifact-claim.js +0 -93
- package/dist/modules/hallucination/confidence.js +0 -81
- package/dist/modules/hallucination/consistency.js +0 -37
- package/dist/modules/hallucination/detector.js +0 -57
- package/dist/modules/hallucination/factual.js +0 -205
- package/dist/modules/hallucination/index.js +0 -6
- package/dist/modules/hallucination/js-identifiers.js +0 -261
- package/dist/modules/hallucination/llm-judge.js +0 -116
- package/dist/modules/hallucination/success-claim.js +0 -59
- package/dist/modules/index.js +0 -5
- package/dist/modules/indexer/cache.js +0 -88
- package/dist/modules/indexer/index.js +0 -4
- package/dist/modules/indexer/map-command.js +0 -33
- package/dist/modules/indexer/map-select.js +0 -87
- package/dist/modules/indexer/module.js +0 -293
- package/dist/modules/indexer/project-profile.js +0 -184
- package/dist/modules/indexer/symbols.js +0 -189
- package/dist/modules/indexer/walker.js +0 -285
- package/dist/modules/lsp/check-tool.js +0 -61
- package/dist/modules/lsp/client.js +0 -406
- package/dist/modules/lsp/command.js +0 -53
- package/dist/modules/lsp/config.js +0 -189
- package/dist/modules/lsp/index.js +0 -4
- package/dist/modules/lsp/module.js +0 -295
- package/dist/modules/lsp/probe.js +0 -86
- package/dist/modules/lsp/project-root.js +0 -69
- package/dist/modules/lsp/startup-check.js +0 -154
- package/dist/modules/lsp/types.js +0 -1
- package/dist/modules/mcp/client.js +0 -445
- package/dist/modules/mcp/index.js +0 -4
- package/dist/modules/mcp/module.js +0 -295
- package/dist/modules/mcp/registry.js +0 -20
- package/dist/modules/memory/index.js +0 -2
- package/dist/modules/memory/module.js +0 -101
- package/dist/modules/memory/search.js +0 -45
- package/dist/modules/memory/store.js +0 -107
- package/dist/modules/onboarding/init.js +0 -47
- package/dist/modules/onboarding/meet.js +0 -30
- package/dist/modules/onboarding/mode.js +0 -30
- package/dist/modules/onboarding/prompts.js +0 -43
- package/dist/modules/pipelines/engine.js +0 -70
- package/dist/modules/pipelines/index.js +0 -4
- package/dist/modules/pipelines/parser.js +0 -59
- package/dist/modules/pipelines/template.js +0 -18
- package/dist/modules/plugins/builtin/lint-on-write.js +0 -377
- package/dist/modules/plugins/builtin/notify.js +0 -11
- package/dist/modules/plugins/index.js +0 -2
- package/dist/modules/plugins/loader.js +0 -85
- package/dist/modules/plugins/manager.js +0 -244
- package/dist/modules/plugins/types.js +0 -1
- package/dist/modules/pricing/index.js +0 -70
- package/dist/modules/pricing/prices.js +0 -147
- package/dist/modules/processes/detect.js +0 -34
- package/dist/modules/processes/index.js +0 -4
- package/dist/modules/processes/kill-tree.js +0 -52
- package/dist/modules/processes/registry.js +0 -294
- package/dist/modules/processes/runner.js +0 -23
- package/dist/modules/providers/cache.js +0 -23
- package/dist/modules/providers/capabilities.js +0 -28
- package/dist/modules/providers/create.js +0 -21
- package/dist/modules/providers/factory.js +0 -28
- package/dist/modules/providers/fallback.js +0 -81
- package/dist/modules/providers/health.js +0 -47
- package/dist/modules/providers/index.js +0 -6
- package/dist/modules/providers/manager.js +0 -207
- package/dist/modules/providers/naming.js +0 -15
- package/dist/modules/providers/preflight.js +0 -71
- package/dist/modules/providers/presets.js +0 -232
- package/dist/modules/providers/registry.js +0 -27
- package/dist/modules/providers/types.js +0 -1
- package/dist/modules/reasoning/policy.js +0 -42
- package/dist/modules/reasoning/probe.js +0 -116
- package/dist/modules/registry.js +0 -48
- package/dist/modules/security/audit-log.js +0 -119
- package/dist/modules/security/audit-notifier.js +0 -267
- package/dist/modules/security/command-validator.js +0 -272
- package/dist/modules/security/content-scanner.js +0 -53
- package/dist/modules/security/data-sanitizer.js +0 -82
- package/dist/modules/security/encryption.js +0 -216
- package/dist/modules/security/index.js +0 -15
- package/dist/modules/security/network-validator.js +0 -236
- package/dist/modules/security/path-validator.js +0 -261
- package/dist/modules/security/protected-paths.js +0 -73
- package/dist/modules/security/rate-limiter.js +0 -98
- package/dist/modules/security/security-policies.js +0 -499
- package/dist/modules/security/session-encryption.js +0 -182
- package/dist/modules/security/session-isolation.js +0 -75
- package/dist/modules/session/auto-name.js +0 -63
- package/dist/modules/session/export.js +0 -98
- package/dist/modules/session/index.js +0 -4
- package/dist/modules/session/manager.js +0 -234
- package/dist/modules/session/module.js +0 -33
- package/dist/modules/session/store.js +0 -295
- package/dist/modules/session/types.js +0 -1
- package/dist/modules/setup/answers.js +0 -35
- package/dist/modules/setup/apply.js +0 -79
- package/dist/modules/setup/discovery.js +0 -72
- package/dist/modules/skills/index.js +0 -3
- package/dist/modules/skills/loader.js +0 -86
- package/dist/modules/skills/matcher.js +0 -27
- package/dist/modules/skills/module.js +0 -141
- package/dist/modules/types.js +0 -1
- package/dist/modules/updater/changelog-reader.js +0 -93
- package/dist/modules/updater/checker.js +0 -101
- package/dist/modules/updater/dev-detect.js +0 -18
- package/dist/modules/updater/index.js +0 -4
- package/dist/modules/updater/module.js +0 -129
- package/dist/modules/user-profile/compressor.js +0 -18
- package/dist/modules/user-profile/index.js +0 -2
- package/dist/modules/user-profile/profile.js +0 -77
- package/dist/modules/webui/answer-api.js +0 -29
- package/dist/modules/webui/assets.js +0 -50
- package/dist/modules/webui/body.js +0 -21
- package/dist/modules/webui/commands-settings.js +0 -209
- package/dist/modules/webui/commands-shared.js +0 -60
- package/dist/modules/webui/commands.js +0 -174
- package/dist/modules/webui/config-api.js +0 -134
- package/dist/modules/webui/file-api.js +0 -202
- package/dist/modules/webui/forward.js +0 -159
- package/dist/modules/webui/history-api.js +0 -112
- package/dist/modules/webui/host-state.js +0 -60
- package/dist/modules/webui/i18n-api.js +0 -9
- package/dist/modules/webui/limits.js +0 -6
- package/dist/modules/webui/log-forward.js +0 -20
- package/dist/modules/webui/memory-commands.js +0 -64
- package/dist/modules/webui/model-cache.js +0 -18
- package/dist/modules/webui/module.js +0 -148
- package/dist/modules/webui/persist.js +0 -24
- package/dist/modules/webui/prompt-io.js +0 -97
- package/dist/modules/webui/providers-api.js +0 -337
- package/dist/modules/webui/providers-view.js +0 -56
- package/dist/modules/webui/reasoning-view.js +0 -15
- package/dist/modules/webui/run-agent.js +0 -81
- package/dist/modules/webui/server.js +0 -284
- package/dist/modules/webui/sessions-api.js +0 -178
- package/dist/modules/webui/settings-api.js +0 -561
- package/dist/modules/webui/setup-api.js +0 -201
- package/dist/modules/webui/state.js +0 -74
- package/dist/modules/webui/util.js +0 -261
- package/dist/output/bus.js +0 -37
- package/dist/output/channel.js +0 -285
- package/dist/output/format.js +0 -15
- package/dist/output/index.js +0 -8
- package/dist/output/json-sink.js +0 -24
- package/dist/output/machine.js +0 -9
- package/dist/output/session-sink.js +0 -27
- package/dist/output/types.js +0 -1
- package/dist/tools/approve.js +0 -41
- package/dist/tools/attach-image.js +0 -102
- package/dist/tools/auto-fixer.js +0 -180
- package/dist/tools/auto-tags.js +0 -83
- package/dist/tools/bash.js +0 -649
- package/dist/tools/browser.js +0 -160
- package/dist/tools/chunk-query.js +0 -112
- package/dist/tools/create-dir.js +0 -60
- package/dist/tools/delete-file.js +0 -67
- package/dist/tools/download-file.js +0 -142
- package/dist/tools/edit-file.js +0 -136
- package/dist/tools/enable-tools.js +0 -59
- package/dist/tools/executor.js +0 -304
- package/dist/tools/file-info.js +0 -49
- package/dist/tools/filter-tools.js +0 -17
- package/dist/tools/glob-tool.js +0 -37
- package/dist/tools/grep-tool.js +0 -142
- package/dist/tools/hidden-tools-block.js +0 -37
- package/dist/tools/index.js +0 -88
- package/dist/tools/list-dir.js +0 -53
- package/dist/tools/load-skill.js +0 -51
- package/dist/tools/mcp-call.js +0 -80
- package/dist/tools/meet-done.js +0 -14
- package/dist/tools/move-file.js +0 -94
- package/dist/tools/path-utils.js +0 -108
- package/dist/tools/pipeline-run.js +0 -167
- package/dist/tools/preview.js +0 -2
- package/dist/tools/process-ids.js +0 -31
- package/dist/tools/process-kill.js +0 -33
- package/dist/tools/process-list.js +0 -38
- package/dist/tools/process-log.js +0 -49
- package/dist/tools/process-wait.js +0 -63
- package/dist/tools/prompt-io.js +0 -29
- package/dist/tools/question.js +0 -288
- package/dist/tools/read-file.js +0 -200
- package/dist/tools/recall.js +0 -124
- package/dist/tools/registry.js +0 -48
- package/dist/tools/remember.js +0 -72
- package/dist/tools/scope-check.js +0 -32
- package/dist/tools/scope-request.js +0 -96
- package/dist/tools/search-history.js +0 -88
- package/dist/tools/session-info.js +0 -46
- package/dist/tools/set-thinking.js +0 -75
- package/dist/tools/subagent.js +0 -257
- package/dist/tools/syntax-validator.js +0 -379
- package/dist/tools/types.js +0 -1
- package/dist/tools/user-input.js +0 -134
- package/dist/tools/web-browse.js +0 -93
- package/dist/tools/web-fetch.js +0 -108
- package/dist/tools/web-search.js +0 -107
- package/dist/tools/write-file.js +0 -128
- package/dist/ui/action-log.js +0 -13
- package/dist/ui/box.js +0 -78
- package/dist/ui/colors.js +0 -6
- package/dist/ui/diff.js +0 -189
- package/dist/ui/index.js +0 -7
- package/dist/ui/line-editor.js +0 -1083
- package/dist/ui/line-math.js +0 -98
- package/dist/ui/md-formatter.js +0 -322
- package/dist/ui/output.js +0 -19
- package/dist/ui/plan-view.js +0 -109
- package/dist/ui/renderer.js +0 -589
- package/dist/ui/spinner.js +0 -91
- package/dist/ui/table.js +0 -142
- package/dist/ui/theme.js +0 -143
- package/dist/utils/child-run.js +0 -20
- package/dist/utils/error.js +0 -4
- package/dist/utils/index.js +0 -6
- package/dist/utils/retry.js +0 -17
- package/dist/utils/sleep.js +0 -23
- package/dist/utils/truncate.js +0 -9
package/dist/ui/line-math.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// Математика строк редактора: ANSI-стрип, перенос по ширине, буфер↔экран маппинг.
|
|
2
|
-
import stringWidth from "string-width";
|
|
3
|
-
const ANSI_RE = /\x1b\[[0-9;?]*[ -/]*[@-~]/g;
|
|
4
|
-
/** Срезает ANSI-последовательности. */
|
|
5
|
-
export function stripAnsi(s) {
|
|
6
|
-
return s.replace(ANSI_RE, "");
|
|
7
|
-
}
|
|
8
|
-
/** Длина в символах (не в байтах/ячейках). */
|
|
9
|
-
export function charLen(s) {
|
|
10
|
-
return Array.from(s).length;
|
|
11
|
-
}
|
|
12
|
-
/** Перенос строки по ширине (по словам, CJK-корректно). */
|
|
13
|
-
export function wrapLine(line, width, firstRowWidth) {
|
|
14
|
-
const w = width > 0 ? width : 80;
|
|
15
|
-
// Только ПЕРВАЯ визуальная строка делит экранную строку с чем-то ещё
|
|
16
|
-
// (напр. с промптом); все продолжения — на полную ширину.
|
|
17
|
-
let limit = firstRowWidth !== undefined && firstRowWidth > 0 ? firstRowWidth : w;
|
|
18
|
-
const chars = Array.from(line);
|
|
19
|
-
const rows = [];
|
|
20
|
-
let start = 0;
|
|
21
|
-
let cells = 0;
|
|
22
|
-
let lastSpaceIdx = -1;
|
|
23
|
-
let lastSpaceCells = 0;
|
|
24
|
-
for (let i = 0; i < chars.length; i++) {
|
|
25
|
-
const ch = chars[i];
|
|
26
|
-
if (ch === "\n") {
|
|
27
|
-
rows.push({ text: chars.slice(start, i).join(""), charStart: start });
|
|
28
|
-
start = i + 1;
|
|
29
|
-
cells = 0;
|
|
30
|
-
lastSpaceIdx = -1;
|
|
31
|
-
lastSpaceCells = 0;
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
const cw = stringWidth(ch);
|
|
35
|
-
if (ch === " ") {
|
|
36
|
-
lastSpaceIdx = i;
|
|
37
|
-
lastSpaceCells = cells;
|
|
38
|
-
}
|
|
39
|
-
if (cells + cw > limit && cells > 0) {
|
|
40
|
-
if (lastSpaceIdx > start) {
|
|
41
|
-
rows.push({ text: chars.slice(start, lastSpaceIdx).join(""), charStart: start });
|
|
42
|
-
start = lastSpaceIdx + 1;
|
|
43
|
-
cells = Math.max(0, cells - lastSpaceCells - 1);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
rows.push({ text: chars.slice(start, i).join(""), charStart: start });
|
|
47
|
-
start = i;
|
|
48
|
-
cells = cw;
|
|
49
|
-
}
|
|
50
|
-
lastSpaceIdx = -1;
|
|
51
|
-
lastSpaceCells = 0;
|
|
52
|
-
limit = w;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
cells += cw;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
rows.push({ text: chars.slice(start).join(""), charStart: start });
|
|
59
|
-
return rows;
|
|
60
|
-
}
|
|
61
|
-
/** Раскладка всех строк буфера в визуальные ряды. */
|
|
62
|
-
export function buildLayout(lines, width, firstRowWidth) {
|
|
63
|
-
const rows = [];
|
|
64
|
-
for (let b = 0; b < lines.length; b++) {
|
|
65
|
-
for (const r of wrapLine(lines[b], width, b === 0 ? firstRowWidth : undefined)) {
|
|
66
|
-
rows.push({ bufRow: b, charStart: r.charStart, text: r.text });
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return rows;
|
|
70
|
-
}
|
|
71
|
-
/** Индекс визуального ряда по позиции буфера. */
|
|
72
|
-
export function layoutIndexFor(rows, bufRow, col) {
|
|
73
|
-
let idx = 0;
|
|
74
|
-
for (let i = 0; i < rows.length; i++) {
|
|
75
|
-
if (rows[i].bufRow === bufRow && rows[i].charStart <= col)
|
|
76
|
-
idx = i;
|
|
77
|
-
}
|
|
78
|
-
return idx;
|
|
79
|
-
}
|
|
80
|
-
/** Визуальная колонка по смещению в буфере. */
|
|
81
|
-
export function visualColAt(rows, idx, col) {
|
|
82
|
-
const r = rows[idx];
|
|
83
|
-
const upTo = col - r.charStart;
|
|
84
|
-
return stringWidth(Array.from(r.text).slice(0, upTo).join(""));
|
|
85
|
-
}
|
|
86
|
-
/** Смещение в буфере по визуальной колонке. */
|
|
87
|
-
export function charOffsetFor(rows, idx, visualCol) {
|
|
88
|
-
const r = rows[idx];
|
|
89
|
-
const chars = Array.from(r.text);
|
|
90
|
-
let cells = 0;
|
|
91
|
-
for (let i = 0; i < chars.length; i++) {
|
|
92
|
-
const cw = stringWidth(chars[i]);
|
|
93
|
-
if (cells + cw > visualCol)
|
|
94
|
-
return r.charStart + i;
|
|
95
|
-
cells += cw;
|
|
96
|
-
}
|
|
97
|
-
return r.charStart + chars.length;
|
|
98
|
-
}
|
package/dist/ui/md-formatter.js
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
// Markdown-форматтер чата: стриминг строк, подсветка кода, таблицы (см. STYLE.md).
|
|
2
|
-
import { pc } from "./colors";
|
|
3
|
-
import stringWidth from "string-width";
|
|
4
|
-
import { t } from "../i18n/index";
|
|
5
|
-
import { formatTable, getTerminalWidth } from "./table";
|
|
6
|
-
import { glyph } from "./theme";
|
|
7
|
-
const KW = /\b(import|export|from|const|let|var|function|return|if|else|for|while|do|switch|case|break|continue|new|class|extends|implements|interface|type|enum|namespace|module|declare|abstract|async|await|yield|throw|try|catch|finally|typeof|instanceof|in|of|as|is|keyof|readonly|static|private|public|protected|get|set|constructor|this|super|void|never|any|unknown|boolean|string|number|symbol|object|true|false|null|undefined|default)\b/g;
|
|
8
|
-
const STRING = /('[^']*'|"[^"]*"|`[^`]*`)/g;
|
|
9
|
-
const COMMENT = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|#[^\n]*)/g;
|
|
10
|
-
const NUMBER = /\b(\d+\.?\d*)\b/g;
|
|
11
|
-
const TAG = /<\/?([A-Z][a-zA-Z0-9]*|[a-z][a-zA-Z0-9-]*)/g;
|
|
12
|
-
const ATTR = /\b([a-zA-Z-]+=)"([^"]*)"/g;
|
|
13
|
-
function highlight(code, lang) {
|
|
14
|
-
if (lang === "html" || lang === "xml" || lang === "svg") {
|
|
15
|
-
code = code.replace(COMMENT, (m) => pc.dim(pc.green(m)));
|
|
16
|
-
code = code.replace(ATTR, (_m, attr, val) => `${pc.yellow(attr)}=${pc.green(`"${val}"`)}`);
|
|
17
|
-
code = code.replace(TAG, (_m, tag) => `<${pc.cyan(tag)}`);
|
|
18
|
-
}
|
|
19
|
-
else if (lang === "css" || lang === "scss" || lang === "less") {
|
|
20
|
-
code = code.replace(COMMENT, (m) => pc.dim(pc.green(m)));
|
|
21
|
-
code = code.replace(STRING, (m) => pc.green(m));
|
|
22
|
-
code = code.replace(NUMBER, (m) => pc.yellow(m));
|
|
23
|
-
}
|
|
24
|
-
else if (lang === "bash" || lang === "sh" || lang === "shell" || lang === "zsh") {
|
|
25
|
-
code = code.replace(COMMENT, (m) => pc.dim(pc.green(m)));
|
|
26
|
-
code = code.replace(STRING, (m) => pc.green(m));
|
|
27
|
-
}
|
|
28
|
-
else if (lang === "json") {
|
|
29
|
-
code = code.replace(STRING, (m) => pc.green(m));
|
|
30
|
-
code = code.replace(NUMBER, (m) => pc.yellow(m));
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
// js, ts, jsx, tsx, and fallback
|
|
34
|
-
code = code.replace(COMMENT, (m) => pc.dim(pc.green(m)));
|
|
35
|
-
code = code.replace(STRING, (m) => pc.green(m));
|
|
36
|
-
code = code.replace(KW, (m) => pc.magenta(m));
|
|
37
|
-
code = code.replace(NUMBER, (m) => pc.yellow(m));
|
|
38
|
-
}
|
|
39
|
-
return code;
|
|
40
|
-
}
|
|
41
|
-
function isTableRow(line) {
|
|
42
|
-
const trimmed = line.trim();
|
|
43
|
-
if (!trimmed.startsWith("|"))
|
|
44
|
-
return false;
|
|
45
|
-
const pipes = trimmed.match(/\|/g);
|
|
46
|
-
return (pipes?.length ?? 0) >= 2;
|
|
47
|
-
}
|
|
48
|
-
function isHorizontalRule(line) {
|
|
49
|
-
return /^(-{3,}|\*{3,}|_{3,})\s*$/.test(line.trim());
|
|
50
|
-
}
|
|
51
|
-
/** Стриминговый форматтер markdown в терминальные строки. */
|
|
52
|
-
export class FormattingStream {
|
|
53
|
-
buffer = "";
|
|
54
|
-
inCodeBlock = false;
|
|
55
|
-
codeLang = "";
|
|
56
|
-
codeLines = [];
|
|
57
|
-
tableBuffer = [];
|
|
58
|
-
onWrite;
|
|
59
|
-
onRawWrite;
|
|
60
|
-
width;
|
|
61
|
-
/** Колонок сырого партиала, показанного сейчас в терминале. */
|
|
62
|
-
partialWritten = 0;
|
|
63
|
-
/** Сколько символов pending-строки уже стримлено сырьём. */
|
|
64
|
-
streamedChars = 0;
|
|
65
|
-
/** Колонок зарезервировано слева (префикс вызывающего), чтобы партиал не враппился. */
|
|
66
|
-
reservedCols;
|
|
67
|
-
/**
|
|
68
|
-
* Стрим текущей (ещё не завершённой переводом строки) строки сырьём для живого
|
|
69
|
-
* фидбэка. По умолчанию выкл; офлайн-вызывающие используют `formatMarkdown`.
|
|
70
|
-
*/
|
|
71
|
-
streamPartials;
|
|
72
|
-
constructor(onWrite, width, onRawWrite, opts = {}) {
|
|
73
|
-
this.onWrite = onWrite;
|
|
74
|
-
this.onRawWrite = onRawWrite ?? onWrite;
|
|
75
|
-
this.width = width ?? getTerminalWidth();
|
|
76
|
-
this.reservedCols = opts.reservedCols ?? 0;
|
|
77
|
-
this.streamPartials = opts.streamPartials ?? false;
|
|
78
|
-
}
|
|
79
|
-
write(chunk) {
|
|
80
|
-
this.buffer += chunk;
|
|
81
|
-
let idx;
|
|
82
|
-
while ((idx = this.buffer.indexOf("\n")) !== -1) {
|
|
83
|
-
const line = this.buffer.slice(0, idx);
|
|
84
|
-
this.buffer = this.buffer.slice(idx + 1);
|
|
85
|
-
this.emitPartialRewind();
|
|
86
|
-
this.processLine(line);
|
|
87
|
-
}
|
|
88
|
-
if (this.buffer.length > 0 && !this.inCodeBlock) {
|
|
89
|
-
this.streamPartial();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Стримит pending-строку сырьём для real-time фидбэка; форматированная строка
|
|
94
|
-
* заменяет её по приходу перевода строки.
|
|
95
|
-
*
|
|
96
|
-
* Замена — ОТНОСИТЕЛЬНЫМ движением курсора (`\x1b[<cols>D`), корректным лишь
|
|
97
|
-
* пока стримленный текст сидит на одной визуальной строке, с которой начал.
|
|
98
|
-
* Если партиал шире терминала, он враппится и каждый относительный сдвиг бьёт
|
|
99
|
-
* мимо — та самая битая выдача после рефактора вывода 1.0.0 (потерянные/
|
|
100
|
-
* переставленные символы, потёкшие маркеры, ломаные таблицы). Поэтому стрим
|
|
101
|
-
* замирает на последнем влезшем чанке, а строка рендерится по завершении.
|
|
102
|
-
*/
|
|
103
|
-
streamPartial() {
|
|
104
|
-
if (!this.streamPartials)
|
|
105
|
-
return;
|
|
106
|
-
const available = Math.max(1, this.width - this.reservedCols);
|
|
107
|
-
if (stringWidth(this.buffer) > available)
|
|
108
|
-
return;
|
|
109
|
-
const delta = this.buffer.slice(this.streamedChars);
|
|
110
|
-
if (!delta)
|
|
111
|
-
return;
|
|
112
|
-
this.onRawWrite(delta);
|
|
113
|
-
this.streamedChars = this.buffer.length;
|
|
114
|
-
this.partialWritten = stringWidth(this.buffer);
|
|
115
|
-
}
|
|
116
|
-
emitPartialRewind() {
|
|
117
|
-
if (this.partialWritten > 0) {
|
|
118
|
-
// Откат поверх стримленного партиала + стереть хвост, оставшийся от более
|
|
119
|
-
// короткой форматированной замены, до рендера строки вызывающим.
|
|
120
|
-
this.onRawWrite(`\x1b[${this.partialWritten}D\x1b[K`);
|
|
121
|
-
this.partialWritten = 0;
|
|
122
|
-
}
|
|
123
|
-
this.streamedChars = 0;
|
|
124
|
-
}
|
|
125
|
-
/** Есть ли показанный партиал или необработанный буфер. @internal */
|
|
126
|
-
hasPartial() {
|
|
127
|
-
return this.partialWritten > 0 || this.buffer.length > 0 || this.tableBuffer.length > 0;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Финализирует показанный сырой партиал, чтобы следующая запись началась с новой строки.
|
|
131
|
-
* Терминируется только уже стримленный партиал (одиночный перевод строки через
|
|
132
|
-
* `onRawWrite`); pending-буфер таблицы сбрасывается. Открытый кодовый блок
|
|
133
|
-
* осознанно не трогается: закрытие здесь сделало бы настоящий закрывающий fence
|
|
134
|
-
* похожим на новый открывающий и испортило бы всю прозу дальше. Блок эмитит
|
|
135
|
-
* финальный `flush()`. Идемпотентно.
|
|
136
|
-
*/
|
|
137
|
-
flushPartialNow() {
|
|
138
|
-
if (this.partialWritten > 0) {
|
|
139
|
-
// Строка уже на экране сырьём; терминируем как есть (может быть оборвана
|
|
140
|
-
// посреди markdown) и дропаем, чтобы не отрендерить дважды.
|
|
141
|
-
this.onRawWrite("\n");
|
|
142
|
-
this.partialWritten = 0;
|
|
143
|
-
this.streamedChars = 0;
|
|
144
|
-
this.buffer = "";
|
|
145
|
-
}
|
|
146
|
-
else if (this.buffer.length > 0 && !this.inCodeBlock) {
|
|
147
|
-
// Не стримлено (plain-режим) — рендерим pending-строку сейчас.
|
|
148
|
-
const line = this.buffer;
|
|
149
|
-
this.buffer = "";
|
|
150
|
-
this.streamedChars = 0;
|
|
151
|
-
this.onWrite(this.formatLine(line));
|
|
152
|
-
}
|
|
153
|
-
if (this.tableBuffer.length > 0) {
|
|
154
|
-
this.flushTable();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
flush() {
|
|
158
|
-
if (this.tableBuffer.length > 0) {
|
|
159
|
-
this.flushTable();
|
|
160
|
-
}
|
|
161
|
-
if (this.inCodeBlock) {
|
|
162
|
-
if (this.buffer.length > 0) {
|
|
163
|
-
// Закрывающий fence в EOF без trailing newline: считаем закрытием, а не
|
|
164
|
-
// контентом кода (иначе "```" потечёт в блок).
|
|
165
|
-
if (this.buffer.trim().startsWith("```")) {
|
|
166
|
-
this.buffer = "";
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
this.codeLines.push(this.buffer);
|
|
170
|
-
this.buffer = "";
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if (this.codeLines.length > 0) {
|
|
174
|
-
this.emitCodeBlock();
|
|
175
|
-
}
|
|
176
|
-
this.streamedChars = 0;
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
if (this.buffer.length > 0) {
|
|
180
|
-
const line = this.buffer;
|
|
181
|
-
this.buffer = "";
|
|
182
|
-
this.emitPartialRewind();
|
|
183
|
-
this.onWrite(this.formatLine(line));
|
|
184
|
-
}
|
|
185
|
-
this.streamedChars = 0;
|
|
186
|
-
}
|
|
187
|
-
processLine(line) {
|
|
188
|
-
if (line.trim() === "```" || line.trim().startsWith("```")) {
|
|
189
|
-
if (this.inCodeBlock) {
|
|
190
|
-
this.emitCodeBlock();
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
// Pending-таблица не должна эмититься ПОСЛЕ идущего за ней кодового блока:
|
|
194
|
-
// сбрасываем до входа в fence.
|
|
195
|
-
if (this.tableBuffer.length > 0)
|
|
196
|
-
this.flushTable();
|
|
197
|
-
this.inCodeBlock = true;
|
|
198
|
-
this.codeLang = line.trim().slice(3).trim();
|
|
199
|
-
this.codeLines = [];
|
|
200
|
-
}
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
if (this.inCodeBlock) {
|
|
204
|
-
this.codeLines.push(line);
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
if (isTableRow(line)) {
|
|
208
|
-
this.tableBuffer.push(line);
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
if (this.tableBuffer.length > 0) {
|
|
212
|
-
this.flushTable();
|
|
213
|
-
}
|
|
214
|
-
this.onWrite(this.formatLine(line));
|
|
215
|
-
}
|
|
216
|
-
flushTable() {
|
|
217
|
-
const lines = this.tableBuffer;
|
|
218
|
-
this.tableBuffer = [];
|
|
219
|
-
const hasSeparator = lines.length >= 2 && /^\s*\|?[\s:|-]+\|?\s*$/.test(lines[1].trim());
|
|
220
|
-
if (hasSeparator) {
|
|
221
|
-
for (const l of formatTable(lines, { maxWidth: this.width })) {
|
|
222
|
-
this.onWrite(l);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
for (const l of lines) {
|
|
227
|
-
this.onWrite(this.formatLine(l));
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
emitCodeBlock() {
|
|
232
|
-
this.inCodeBlock = false;
|
|
233
|
-
if (this.codeLines.length > 0) {
|
|
234
|
-
const code = this.codeLines.join("\n");
|
|
235
|
-
const highlighted = highlight(code, this.codeLang);
|
|
236
|
-
// Без рамки: только dim-ярлык языка и левый гуттер. Коробочные кодовые
|
|
237
|
-
// блоки запрещены стилем чата (docs/design/ui/STYLE.md).
|
|
238
|
-
if (this.codeLang)
|
|
239
|
-
this.onWrite(pc.dim(` ${this.codeLang}`));
|
|
240
|
-
for (const l of highlighted.split("\n")) {
|
|
241
|
-
this.onWrite(pc.dim(`${glyph.group} `) + l);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
this.codeLines = [];
|
|
245
|
-
this.codeLang = "";
|
|
246
|
-
}
|
|
247
|
-
formatLine(line) {
|
|
248
|
-
const result = line;
|
|
249
|
-
const heading = result.match(/^(#{1,6})\s+(.+)$/);
|
|
250
|
-
if (heading) {
|
|
251
|
-
const level = heading[1].length;
|
|
252
|
-
const content = this.formatInline(heading[2]);
|
|
253
|
-
if (level === 1)
|
|
254
|
-
return pc.cyan(pc.bold(pc.underline(content)));
|
|
255
|
-
return pc.cyan(pc.bold(content));
|
|
256
|
-
}
|
|
257
|
-
if (isHorizontalRule(result)) {
|
|
258
|
-
return pc.dim("─".repeat(Math.max(0, Math.min(this.width, 60))));
|
|
259
|
-
}
|
|
260
|
-
const quote = result.match(/^(>+)\s?(.*)$/);
|
|
261
|
-
if (quote) {
|
|
262
|
-
const depth = Math.min(quote[1].length, 4);
|
|
263
|
-
const marker = pc.dim("▍".repeat(depth));
|
|
264
|
-
return `${marker} ${this.formatInline(quote[2])}`;
|
|
265
|
-
}
|
|
266
|
-
const checkbox = result.match(/^[-*]\s+\[([ xX])\]\s+(.+)$/);
|
|
267
|
-
if (checkbox) {
|
|
268
|
-
const checked = checkbox[1].toLowerCase() === "x";
|
|
269
|
-
const mark = checked ? pc.green("✓") : pc.dim("☐");
|
|
270
|
-
return ` ${mark} ${this.formatInline(checkbox[2])}`;
|
|
271
|
-
}
|
|
272
|
-
const ordered = result.match(/^(\d+)[.)]\s+(.+)$/);
|
|
273
|
-
if (ordered) {
|
|
274
|
-
return ` ${pc.yellow(ordered[1])}. ${this.formatInline(ordered[2])}`;
|
|
275
|
-
}
|
|
276
|
-
const bullet = result.match(/^[-*]\s+(.+)$/);
|
|
277
|
-
if (bullet) {
|
|
278
|
-
return ` ${pc.dim("•")} ${this.formatInline(bullet[1])}`;
|
|
279
|
-
}
|
|
280
|
-
return this.formatInline(result);
|
|
281
|
-
}
|
|
282
|
-
formatInline(text) {
|
|
283
|
-
const codeSpans = [];
|
|
284
|
-
let result = text.replace(/`([^`]+)`/g, (_m, c) => {
|
|
285
|
-
codeSpans.push(pc.yellow(c));
|
|
286
|
-
return `\u0000${codeSpans.length - 1}\u0000`;
|
|
287
|
-
});
|
|
288
|
-
// `***text***` (bold+italic) до одиночных `**`/`*`, иначе вложенность
|
|
289
|
-
// рвётся и во вложении остаётся висящая звёздочка.
|
|
290
|
-
result = result.replace(/\*\*\*(.+?)\*\*\*/g, (_, s) => pc.bold(pc.italic(s)));
|
|
291
|
-
result = result.replace(/\*\*(.+?)\*\*/g, (_, s) => pc.bold(s));
|
|
292
|
-
result = result.replace(/~~(.+?)~~/g, (_, s) => pc.strikethrough(s));
|
|
293
|
-
result = result.replace(/\*([^*]+)\*/g, (_, s) => pc.italic(s));
|
|
294
|
-
result = result.replace(/(^|\s)_([^_\n]+)_(?=\s|$)/g, (_m, pre, s) => pre + pc.italic(s));
|
|
295
|
-
result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, label, url) => {
|
|
296
|
-
const short = url.length > 80 ? `${url.slice(0, 77)}…` : url;
|
|
297
|
-
return `${pc.cyan(label)} ${pc.dim(`(${short})`)}`;
|
|
298
|
-
});
|
|
299
|
-
result = result.replace(/\u0000(\d+)\u0000/g, (_m, i) => codeSpans[Number(i)]);
|
|
300
|
-
return result;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
/** Форматирует markdown-текст целиком в терминальные строки. */
|
|
304
|
-
export function formatMarkdown(text) {
|
|
305
|
-
const lines = [];
|
|
306
|
-
const stream = new FormattingStream((l) => lines.push(l));
|
|
307
|
-
stream.write(text);
|
|
308
|
-
stream.flush();
|
|
309
|
-
return lines.join("\n");
|
|
310
|
-
}
|
|
311
|
-
/** Форматирует ошибку (красный префикс из i18n). */
|
|
312
|
-
export function formatError(text) {
|
|
313
|
-
return pc.red(pc.bold(t("ui.error_prefix")) + text);
|
|
314
|
-
}
|
|
315
|
-
/** Форматирует успех (зелёный префикс из i18n). */
|
|
316
|
-
export function formatSuccess(text) {
|
|
317
|
-
return pc.green(pc.bold(t("ui.success_prefix")) + text);
|
|
318
|
-
}
|
|
319
|
-
/** Форматирует предупреждение (жёлтый префикс из i18n). */
|
|
320
|
-
export function formatWarning(text) {
|
|
321
|
-
return pc.yellow(pc.bold(t("ui.warning_prefix")) + text);
|
|
322
|
-
}
|
package/dist/ui/output.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Короткие писатели в канал: markdown/ошибка/успех/предупреждение.
|
|
2
|
-
import { getDefaultChannel } from "../output";
|
|
3
|
-
import { formatMarkdown, formatError, formatSuccess, formatWarning } from "./md-formatter";
|
|
4
|
-
/** Пишет markdown-текст в stdout. */
|
|
5
|
-
export function writeOutput(text) {
|
|
6
|
-
getDefaultChannel().writeRaw(`${formatMarkdown(text)}\n`);
|
|
7
|
-
}
|
|
8
|
-
/** Пишет ошибку в stderr. */
|
|
9
|
-
export function writeError(text) {
|
|
10
|
-
getDefaultChannel().writeRaw(`${formatError(text)}\n`, "stderr");
|
|
11
|
-
}
|
|
12
|
-
/** Пишет успех в stdout. */
|
|
13
|
-
export function writeSuccess(text) {
|
|
14
|
-
getDefaultChannel().writeRaw(`${formatSuccess(text)}\n`);
|
|
15
|
-
}
|
|
16
|
-
/** Пишет предупреждение блочной строкой. */
|
|
17
|
-
export function writeWarning(text) {
|
|
18
|
-
getDefaultChannel().writeLine(formatWarning(text));
|
|
19
|
-
}
|
package/dist/ui/plan-view.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// Вид плана в чате: чтение active.json, чеклист с прогресс-баром, контекст шага.
|
|
2
|
-
import { existsSync, readFileSync } from "fs";
|
|
3
|
-
import { join } from "path";
|
|
4
|
-
import { pc } from "./colors";
|
|
5
|
-
import { glyph } from "./theme";
|
|
6
|
-
import { extractFileLikeTokens, stripUrls } from "../modules/hallucination/js-identifiers";
|
|
7
|
-
import { t } from "../i18n/index";
|
|
8
|
-
import { projectMmaDir } from "../config/paths";
|
|
9
|
-
/** Читает активный план из .mma/plans/active.json. Нет/бит — null. */
|
|
10
|
-
export function readActivePlan(baseDir) {
|
|
11
|
-
const p = join(projectMmaDir(baseDir), "plans", "active.json");
|
|
12
|
-
if (!existsSync(p))
|
|
13
|
-
return null;
|
|
14
|
-
try {
|
|
15
|
-
const raw = readFileSync(p, "utf-8");
|
|
16
|
-
if (!raw.trim())
|
|
17
|
-
return null;
|
|
18
|
-
const parsed = JSON.parse(raw);
|
|
19
|
-
if (!parsed || !Array.isArray(parsed.steps))
|
|
20
|
-
return null;
|
|
21
|
-
return {
|
|
22
|
-
id: parsed.id || "plan",
|
|
23
|
-
title: parsed.title || "Plan",
|
|
24
|
-
steps: parsed.steps,
|
|
25
|
-
createdAt: parsed.createdAt || new Date().toISOString(),
|
|
26
|
-
baseDir: parsed.baseDir || baseDir,
|
|
27
|
-
name: parsed.name,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/** Индекс текущего шага (первый не done/skipped). */
|
|
35
|
-
export function currentStepIndex(plan) {
|
|
36
|
-
return plan.steps.findIndex((s) => s.status !== "done" && s.status !== "skipped");
|
|
37
|
-
}
|
|
38
|
-
function stepMark(step) {
|
|
39
|
-
switch (step.status) {
|
|
40
|
-
case "done":
|
|
41
|
-
return pc.green(glyph.success);
|
|
42
|
-
case "in_progress":
|
|
43
|
-
return pc.cyan(glyph.action);
|
|
44
|
-
case "failed":
|
|
45
|
-
return pc.red(glyph.failure);
|
|
46
|
-
case "skipped":
|
|
47
|
-
return pc.dim("–");
|
|
48
|
-
default:
|
|
49
|
-
return pc.dim("○");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/** Рендерит чеклист плана с прогресс-баром ▰▱ построчно. */
|
|
53
|
-
export function formatPlanChecklist(plan) {
|
|
54
|
-
const done = plan.steps.filter((s) => s.status === "done" || s.status === "skipped").length;
|
|
55
|
-
const total = plan.steps.length;
|
|
56
|
-
const pct = total === 0 ? 0 : Math.round((done / total) * 100);
|
|
57
|
-
const cur = currentStepIndex(plan);
|
|
58
|
-
const barLen = 10;
|
|
59
|
-
const filled = Math.round((pct / 100) * barLen);
|
|
60
|
-
const bar = pc.green("▰".repeat(filled)) + pc.dim("▱".repeat(barLen - filled));
|
|
61
|
-
const title = plan.title.replace(/^\[\d+[^]]*\]\s*/, "");
|
|
62
|
-
const lines = [
|
|
63
|
-
`${pc.cyan(glyph.action)} ${pc.bold(title)} ${bar} ${pc.dim(`${done}/${total}`)}`,
|
|
64
|
-
];
|
|
65
|
-
for (let i = 0; i < plan.steps.length; i++) {
|
|
66
|
-
const step = plan.steps[i];
|
|
67
|
-
const active = i === cur;
|
|
68
|
-
const desc = active ? pc.yellow(step.description) : pc.dim(step.description);
|
|
69
|
-
lines.push(` ${stepMark(step)} ${step.id}. ${desc}`);
|
|
70
|
-
for (const sub of step.subtasks ?? []) {
|
|
71
|
-
lines.push(` ${sub.done ? pc.green(glyph.success) : pc.dim("○")} [${sub.id}] ${sub.text}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return lines;
|
|
75
|
-
}
|
|
76
|
-
const STRUCTURAL_TOOLS = new Set([
|
|
77
|
-
"plan",
|
|
78
|
-
"plan_step",
|
|
79
|
-
"todo",
|
|
80
|
-
"verify",
|
|
81
|
-
"project_map",
|
|
82
|
-
"lsp_check",
|
|
83
|
-
"enable_tools",
|
|
84
|
-
]);
|
|
85
|
-
function truncate(s, max = 48) {
|
|
86
|
-
return s.length > max ? `${s.slice(0, max - 1)}…` : s;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Подбирает шаг плана под вызов тула по файловым токенам аргументов.
|
|
90
|
-
* Структурные тулы и вызовы без путей — null.
|
|
91
|
-
*/
|
|
92
|
-
export function stepContextForTool(plan, tool, args) {
|
|
93
|
-
if (!plan || STRUCTURAL_TOOLS.has(tool))
|
|
94
|
-
return null;
|
|
95
|
-
const argStr = JSON.stringify(args);
|
|
96
|
-
const callPaths = extractFileLikeTokens(stripUrls(argStr)).map((p) => p.toLowerCase());
|
|
97
|
-
if (callPaths.length > 0) {
|
|
98
|
-
for (const step of plan.steps) {
|
|
99
|
-
if (step.status === "done" || step.status === "skipped")
|
|
100
|
-
continue;
|
|
101
|
-
const stepPaths = extractFileLikeTokens(stripUrls(step.description)).map((p) => p.toLowerCase());
|
|
102
|
-
if (stepPaths.length > 0 &&
|
|
103
|
-
stepPaths.some((s) => callPaths.some((c) => c.includes(s) || s.includes(c)))) {
|
|
104
|
-
return t("ui.step_context", { id: step.id, desc: truncate(step.description) });
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return null;
|
|
109
|
-
}
|