@herbertgao/pi-extensions 2026.9.6 → 2026.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -8
- package/THIRD_PARTY_NOTICES.md +0 -4
- package/node_modules/@narumitw/pi-btw/README.md +2 -0
- package/node_modules/@narumitw/pi-btw/dist/index.ts +284 -365
- package/node_modules/@narumitw/pi-btw/dist/index.ts.map +3 -3
- package/node_modules/@narumitw/pi-btw/package.json +52 -53
- package/node_modules/@narumitw/pi-btw/src/bring-to-main.ts +494 -547
- package/node_modules/@narumitw/pi-btw/src/btw.ts +814 -856
- package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +673 -674
- package/node_modules/@narumitw/pi-btw/src/keybindings.ts +228 -270
- package/node_modules/@narumitw/pi-btw/src/main-tree-picker.ts +309 -318
- package/node_modules/@narumitw/pi-btw/src/menu.ts +416 -454
- package/node_modules/@narumitw/pi-btw/src/settings.ts +203 -219
- package/node_modules/@narumitw/pi-btw/src/side-thread.ts +173 -201
- package/node_modules/@narumitw/pi-btw/src/text.ts +21 -23
- package/node_modules/@narumitw/pi-btw/src/transcript-markdown.ts +65 -0
- package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +611 -662
- package/node_modules/pi-lens/CHANGELOG.md +239 -0
- package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +3 -0
- package/node_modules/pi-lens/dist/clients/actionable-warnings.js +30 -4
- package/node_modules/pi-lens/dist/clients/agent-behavior-client.js +2 -0
- package/node_modules/pi-lens/dist/clients/bash-file-access.js +26 -0
- package/node_modules/pi-lens/dist/clients/biome-client.js +1 -1
- package/node_modules/pi-lens/dist/clients/blocker-freshness.js +403 -35
- package/node_modules/pi-lens/dist/clients/bootstrap.js +6 -1
- package/node_modules/pi-lens/dist/clients/cascade-format.js +200 -4
- package/node_modules/pi-lens/dist/clients/code-quality-warnings.js +10 -2
- package/node_modules/pi-lens/dist/clients/degradation-ledger.js +16 -1
- package/node_modules/pi-lens/dist/clients/diagnostic-dispositions.js +12 -1
- package/node_modules/pi-lens/dist/clients/dispatch/ast-grep-catalog.js +65 -0
- package/node_modules/pi-lens/dist/clients/dispatch/auxiliary-lsp.js +28 -0
- package/node_modules/pi-lens/dist/clients/dispatch/dispatcher.js +9 -2
- package/node_modules/pi-lens/dist/clients/dispatch/finding-policy.js +222 -0
- package/node_modules/pi-lens/dist/clients/dispatch/indent-detect.js +389 -13
- package/node_modules/pi-lens/dist/clients/dispatch/integration.js +175 -25
- package/node_modules/pi-lens/dist/clients/dispatch/rule-ignores.js +62 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/ast-grep-napi.js +21 -41
- package/node_modules/pi-lens/dist/clients/dispatch/runners/biome-check.js +6 -1
- package/node_modules/pi-lens/dist/clients/dispatch/runners/rust-clippy.js +7 -7
- package/node_modules/pi-lens/dist/clients/dispatch/runners/shfmt.js +2 -12
- package/node_modules/pi-lens/dist/clients/dispatch/runners/tree-sitter.js +2 -21
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/runner-helpers.js +1 -1
- package/node_modules/pi-lens/dist/clients/dispatch/types.js +4 -1
- package/node_modules/pi-lens/dist/clients/disposition-publish.js +1 -0
- package/node_modules/pi-lens/dist/clients/effective-config.js +1 -1
- package/node_modules/pi-lens/dist/clients/file-kinds.js +26 -1
- package/node_modules/pi-lens/dist/clients/file-role.js +21 -21
- package/node_modules/pi-lens/dist/clients/file-utils.js +156 -10
- package/node_modules/pi-lens/dist/clients/finding-delivery-gate.js +56 -9
- package/node_modules/pi-lens/dist/clients/format-service.js +39 -21
- package/node_modules/pi-lens/dist/clients/formatters.js +60 -13
- package/node_modules/pi-lens/dist/clients/generation-guard.js +2 -2
- package/node_modules/pi-lens/dist/clients/git-guard.js +11 -3
- package/node_modules/pi-lens/dist/clients/indent-retarget.js +78 -8
- package/node_modules/pi-lens/dist/clients/installer/index.js +333 -114
- package/node_modules/pi-lens/dist/clients/instance-reaper-state.js +7 -0
- package/node_modules/pi-lens/dist/clients/instance-reaper.js +20 -10
- package/node_modules/pi-lens/dist/clients/language-profile.js +23 -1
- package/node_modules/pi-lens/dist/clients/language-registry.js +5 -1
- package/node_modules/pi-lens/dist/clients/latency-logger.js +4 -1
- package/node_modules/pi-lens/dist/clients/lens-engine.js +12 -3
- package/node_modules/pi-lens/dist/clients/lens-events.js +2 -1
- package/node_modules/pi-lens/dist/clients/lens-flag-registry.js +79 -0
- package/node_modules/pi-lens/dist/clients/live-bus-emitter.js +2 -1
- package/node_modules/pi-lens/dist/clients/lsp/client.js +25 -21
- package/node_modules/pi-lens/dist/clients/lsp/config.js +2 -2
- package/node_modules/pi-lens/dist/clients/lsp/index.js +7 -0
- package/node_modules/pi-lens/dist/clients/lsp/launch.js +16 -4
- package/node_modules/pi-lens/dist/clients/lsp/server.js +19 -2
- package/node_modules/pi-lens/dist/clients/lsp/workspace-diagnostics-cache.js +2 -1
- package/node_modules/pi-lens/dist/clients/lsp-mutation.js +5 -3
- package/node_modules/pi-lens/dist/clients/map-with-concurrency.js +12 -8
- package/node_modules/pi-lens/dist/clients/mcp/session.js +36 -4
- package/node_modules/pi-lens/dist/clients/ndjson-logger.js +24 -7
- package/node_modules/pi-lens/dist/clients/observed-mutation.js +40 -2
- package/node_modules/pi-lens/dist/clients/opaque-mutation-scan.js +23 -3
- package/node_modules/pi-lens/dist/clients/opengrep-client.js +110 -15
- package/node_modules/pi-lens/dist/clients/path-utils.js +123 -3
- package/node_modules/pi-lens/dist/clients/performance-report.js +5 -1
- package/node_modules/pi-lens/dist/clients/php-cs-fixer-config.js +1 -1
- package/node_modules/pi-lens/dist/clients/pipeline.js +74 -5
- package/node_modules/pi-lens/dist/clients/project-diagnostics/cache.js +37 -5
- package/node_modules/pi-lens/dist/clients/project-diagnostics/fresh-fetch.js +145 -18
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/dead-code.js +4 -1
- package/node_modules/pi-lens/dist/clients/project-diagnostics/scanner.js +59 -3
- package/node_modules/pi-lens/dist/clients/project-lens-config.js +45 -2
- package/node_modules/pi-lens/dist/clients/read-guard.js +70 -11
- package/node_modules/pi-lens/dist/clients/resource-sampler.js +147 -9
- package/node_modules/pi-lens/dist/clients/ruff-client.js +1 -1
- package/node_modules/pi-lens/dist/clients/runtime-agent-end.js +33 -5
- package/node_modules/pi-lens/dist/clients/runtime-context.js +6 -2
- package/node_modules/pi-lens/dist/clients/runtime-coordinator.js +77 -7
- package/node_modules/pi-lens/dist/clients/runtime-session.js +21 -2
- package/node_modules/pi-lens/dist/clients/runtime-tool-call.js +43 -12
- package/node_modules/pi-lens/dist/clients/runtime-tool-result.js +330 -85
- package/node_modules/pi-lens/dist/clients/runtime-turn.js +147 -17
- package/node_modules/pi-lens/dist/clients/safe-spawn.js +258 -5
- package/node_modules/pi-lens/dist/clients/scratch-tree-policy.js +6 -0
- package/node_modules/pi-lens/dist/clients/session-event-guard.js +50 -5
- package/node_modules/pi-lens/dist/clients/sg-runner.js +23 -11
- package/node_modules/pi-lens/dist/clients/sgconfig.js +79 -2
- package/node_modules/pi-lens/dist/clients/test-runner-client.js +6 -41
- package/node_modules/pi-lens/dist/clients/test-runner-delivery.js +43 -0
- package/node_modules/pi-lens/dist/clients/tool-agreement.js +423 -0
- package/node_modules/pi-lens/dist/clients/tool-config.js +50 -0
- package/node_modules/pi-lens/dist/clients/tool-cwd.js +47 -76
- package/node_modules/pi-lens/dist/clients/tool-policy.js +163 -7
- package/node_modules/pi-lens/dist/clients/tree-sitter-client.js +120 -0
- package/node_modules/pi-lens/dist/clients/tree-sitter-query-loader.js +127 -189
- package/node_modules/pi-lens/dist/clients/widget-state.js +98 -0
- package/node_modules/pi-lens/dist/clients/word-index.js +5 -2
- package/node_modules/pi-lens/dist/clients/write-ordering-guard.js +7 -0
- package/node_modules/pi-lens/dist/index.js +27416 -24153
- package/node_modules/pi-lens/dist/mcp/server.js +5 -2
- package/node_modules/pi-lens/dist/tools/lens-diagnostic-mark.js +7 -1
- package/node_modules/pi-lens/dist/tools/lens-diagnostics.js +168 -53
- package/node_modules/pi-lens/dist/tools/lsp-diagnostics.js +244 -72
- package/node_modules/pi-lens/docs/audit1.md +5 -5
- package/node_modules/pi-lens/docs/dependencies.md +11 -0
- package/node_modules/pi-lens/docs/dispositions.md +52 -0
- package/node_modules/pi-lens/docs/environment-variables.md +2 -2
- package/node_modules/pi-lens/docs/features.md +4 -4
- package/node_modules/pi-lens/docs/globalconfig.md +3 -1
- package/node_modules/pi-lens/docs/language-coverage.md +1 -0
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +53 -94
- package/node_modules/pi-lens/docs/pi-lens-investigator.md +43 -38
- package/node_modules/pi-lens/docs/pi-lens-retro.md +97 -0
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +53 -66
- package/node_modules/pi-lens/docs/release-qa-baseline.md +22 -0
- package/node_modules/pi-lens/docs/settings.md +7 -4
- package/node_modules/pi-lens/docs/tree-sitter_rules_catalog.md +1 -1
- package/node_modules/pi-lens/docs/usage.md +2 -0
- package/node_modules/pi-lens/package.json +1 -1
- package/node_modules/pi-lens/rules/tree-sitter-queries/typescript/sql-injection.yml +24 -12
- package/node_modules/pi-lens/scripts/analyze-pi-lens-logs.mjs +40 -0
- package/node_modules/pi-lens/skills/pi-lens-ast-grep/SKILL.md +15 -0
- package/node_modules/pi-lens/skills/pi-lens-lsp-navigation/SKILL.md +7 -0
- package/package.json +5 -11
- package/node_modules/@luxusai/pi-hindsight/CHANGELOG.md +0 -376
- package/node_modules/@luxusai/pi-hindsight/README.md +0 -92
- package/node_modules/@luxusai/pi-hindsight/docs/adr/001-memory-lifecycle-and-scope.md +0 -56
- package/node_modules/@luxusai/pi-hindsight/docs/adr/002-explicit-routing-strategy-seam.md +0 -169
- package/node_modules/@luxusai/pi-hindsight/docs/adr/003-tui-memory-mode-vocabulary.md +0 -107
- package/node_modules/@luxusai/pi-hindsight/docs/adr/004-lifeos-dual-bank-design.md +0 -89
- package/node_modules/@luxusai/pi-hindsight/docs/adr/005-domain-banks-and-agent-first-surface.md +0 -189
- package/node_modules/@luxusai/pi-hindsight/docs/assets/logos/pi-hindsight-logo-dark.webp +0 -0
- package/node_modules/@luxusai/pi-hindsight/docs/assets/logos/pi-hindsight-logo-dark@2x.webp +0 -0
- package/node_modules/@luxusai/pi-hindsight/docs/coding-memory-evaluation.md +0 -54
- package/node_modules/@luxusai/pi-hindsight/docs/compatibility.md +0 -75
- package/node_modules/@luxusai/pi-hindsight/docs/hindsight-core-functions.md +0 -300
- package/node_modules/@luxusai/pi-hindsight/docs/mission-and-mental-model-quality.md +0 -158
- package/node_modules/@luxusai/pi-hindsight/docs/next-opt-out-design.md +0 -164
- package/node_modules/@luxusai/pi-hindsight/docs/risky-memory-modes.md +0 -139
- package/node_modules/@luxusai/pi-hindsight/docs/starter-mental-model-suggestions.md +0 -74
- package/node_modules/@luxusai/pi-hindsight/docs/surface-reference.md +0 -261
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-operations.ts +0 -151
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-selection.ts +0 -18
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-settings-presenter.ts +0 -46
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-templates.ts +0 -383
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/banking.ts +0 -240
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/knowledge-page-seed.ts +0 -176
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/retain-strategies.ts +0 -178
- package/node_modules/@luxusai/pi-hindsight/extensions/client/client-retry.ts +0 -41
- package/node_modules/@luxusai/pi-hindsight/extensions/client/client.ts +0 -386
- package/node_modules/@luxusai/pi-hindsight/extensions/client/fetch-compat.ts +0 -39
- package/node_modules/@luxusai/pi-hindsight/extensions/client/timeout.ts +0 -34
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-defaults.ts +0 -140
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-editing-model.ts +0 -61
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-editing-registry.ts +0 -925
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-field-paths.ts +0 -247
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-normalize.ts +0 -547
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-writer.ts +0 -480
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config.ts +0 -182
- package/node_modules/@luxusai/pi-hindsight/extensions/config/setup-gate.ts +0 -86
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-execute.ts +0 -1010
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-parse.ts +0 -175
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-plan.ts +0 -425
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-presentation.ts +0 -210
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-sessions.ts +0 -817
- package/node_modules/@luxusai/pi-hindsight/extensions/index.ts +0 -25
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/git-seed.ts +0 -319
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle-recall.ts +0 -196
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle-retain.ts +0 -189
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle-runtime.ts +0 -65
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle.ts +0 -260
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/mental-models.ts +0 -244
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/observation-scopes.ts +0 -59
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/recall-cleanup.ts +0 -82
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/recall-visibility.ts +0 -45
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/recall.ts +0 -331
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain-cursor.ts +0 -354
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain-job-builder.ts +0 -66
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain-receipts.ts +0 -132
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain.ts +0 -228
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-bank-template-operations.ts +0 -74
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-config-operations.ts +0 -16
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-control-operations.ts +0 -648
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-diagnostics-operations.ts +0 -105
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-identity.ts +0 -68
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-operation-service.ts +0 -71
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-operation-types.ts +0 -13
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-recall-operations.ts +0 -162
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-retain-operations.ts +0 -131
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-scope.ts +0 -104
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-session-operations.ts +0 -37
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/operation-catalog.ts +0 -893
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/reflect-presenter.ts +0 -35
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/scope-migrate.ts +0 -177
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/tools.ts +0 -7
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/flush-presenter.ts +0 -21
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/jsonl-queue-store.ts +0 -112
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue-delivery.ts +0 -111
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue-lock.ts +0 -214
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue-operations.ts +0 -70
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue.ts +0 -392
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/bank-template-presentation.ts +0 -45
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/commands.ts +0 -9
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/guided-setup.ts +0 -860
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/prefill-input.ts +0 -105
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-flow.ts +0 -189
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-server-probe.ts +0 -299
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-actions.ts +0 -201
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-facts.ts +0 -47
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-render.ts +0 -239
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-types.ts +0 -50
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui.ts +0 -259
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/tool-presenters.ts +0 -77
- package/node_modules/@luxusai/pi-hindsight/extensions/types.ts +0 -534
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/diagnostics.ts +0 -319
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/messages.ts +0 -325
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/sanitize.ts +0 -42
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/session-memory-meta.ts +0 -244
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/session-operations.ts +0 -56
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/session.ts +0 -50
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/status-fields.ts +0 -167
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/status-health.ts +0 -207
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/status.ts +0 -120
- package/node_modules/@luxusai/pi-hindsight/extensions/version.ts +0 -8
- package/node_modules/@luxusai/pi-hindsight/package.json +0 -118
- package/node_modules/@luxusai/pi-hindsight/skills/hindsight-memory-doctor/SKILL.md +0 -75
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
AssistantMessageComponent,
|
|
4
|
+
getMarkdownTheme,
|
|
5
|
+
type KeybindingsManager,
|
|
6
|
+
type MarkdownTransformer,
|
|
7
|
+
type Theme,
|
|
8
|
+
UserMessageComponent,
|
|
8
9
|
} from "@earendil-works/pi-coding-agent";
|
|
9
10
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
type Component,
|
|
12
|
+
CURSOR_MARKER,
|
|
13
|
+
Editor,
|
|
14
|
+
type EditorTheme,
|
|
15
|
+
type Focusable,
|
|
16
|
+
Key,
|
|
17
|
+
Loader,
|
|
18
|
+
Markdown,
|
|
19
|
+
matchesKey,
|
|
20
|
+
ScrollView,
|
|
21
|
+
type TUI,
|
|
22
|
+
truncateToWidth,
|
|
23
|
+
VStack,
|
|
24
|
+
visibleWidth,
|
|
24
25
|
} from "@earendil-works/pi-tui";
|
|
25
26
|
import type { BtwFullscreenLayoutComponent } from "./fullscreen-ui.js";
|
|
26
27
|
import { BtwPasteGuard, type BtwShortcuts, getBtwShortcuts } from "./keybindings.js";
|
|
@@ -35,688 +36,636 @@ const RESERVED_APP_LINES = 3;
|
|
|
35
36
|
|
|
36
37
|
// A temporary fit after manual scrolling must not silently resume following new output.
|
|
37
38
|
class PreservingScrollView extends ScrollView {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (preserveManualPosition && this.isFollowingEnd) {
|
|
46
|
-
this.scrollTo(this.scrollTop, { disableFollow: true });
|
|
47
|
-
}
|
|
48
|
-
}
|
|
39
|
+
override updateLayout(contentHeight: number, viewportHeight: number, requestRender: () => void): void {
|
|
40
|
+
const preserveManualPosition = !this.isFollowingEnd;
|
|
41
|
+
super.updateLayout(contentHeight, viewportHeight, requestRender);
|
|
42
|
+
if (preserveManualPosition && this.isFollowingEnd) {
|
|
43
|
+
this.scrollTo(this.scrollTop, { disableFollow: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
export type TranscriptPagerAction =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
| { kind: "submit"; question: string }
|
|
50
|
+
| { kind: "bringToMain"; questionDraft: string }
|
|
51
|
+
| { kind: "close" };
|
|
55
52
|
|
|
56
53
|
export interface BtwThinkingControl {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
level: BtwThinkingLevel;
|
|
55
|
+
levels: readonly BtwThinkingLevel[];
|
|
56
|
+
keybindings: KeybindingsManager;
|
|
57
|
+
onChange: (level: BtwThinkingLevel) => void;
|
|
61
58
|
}
|
|
62
59
|
|
|
63
60
|
export interface BtwAnsweringViewOptions {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
markdownTransformers?: readonly MarkdownTransformer[];
|
|
62
|
+
steering?: {
|
|
63
|
+
questions: readonly string[];
|
|
64
|
+
onSubmit: (question: string) => void;
|
|
65
|
+
thinking?: BtwThinkingControl;
|
|
66
|
+
};
|
|
69
67
|
}
|
|
70
68
|
|
|
71
69
|
export class BtwTranscriptPager implements BtwFullscreenLayoutComponent, Focusable {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
private createFooterComponent(): Component {
|
|
305
|
-
return {
|
|
306
|
-
render: (width) => [this.renderFooter(width)],
|
|
307
|
-
invalidate() {},
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
private getMaxScrollOffset(): number {
|
|
312
|
-
return Math.max(0, this.lastContentLineCount - this.scrollView.viewportHeight);
|
|
313
|
-
}
|
|
70
|
+
private readonly shortcuts: BtwShortcuts;
|
|
71
|
+
private readonly pasteGuard = new BtwPasteGuard();
|
|
72
|
+
private readonly transcriptComponents: Component[];
|
|
73
|
+
private readonly editor: Editor;
|
|
74
|
+
private readonly canBringToMain: boolean;
|
|
75
|
+
private readonly scrollView: ScrollView;
|
|
76
|
+
private readonly layoutRoot: VStack;
|
|
77
|
+
private lastContentLineCount = 0;
|
|
78
|
+
private warning: string | undefined;
|
|
79
|
+
private finished = false;
|
|
80
|
+
private isFocused = false;
|
|
81
|
+
private thinkingLevel: BtwThinkingLevel | undefined;
|
|
82
|
+
|
|
83
|
+
constructor(
|
|
84
|
+
private readonly tui: TUI,
|
|
85
|
+
private readonly theme: Theme,
|
|
86
|
+
turns: readonly SideThreadTurn[],
|
|
87
|
+
private readonly onAction: (action: TranscriptPagerAction) => void,
|
|
88
|
+
private readonly options: {
|
|
89
|
+
startAtBottom?: boolean;
|
|
90
|
+
initialQuestion?: string;
|
|
91
|
+
markdownTransformers?: readonly MarkdownTransformer[];
|
|
92
|
+
thinking?: BtwThinkingControl;
|
|
93
|
+
} = {},
|
|
94
|
+
) {
|
|
95
|
+
this.shortcuts = getBtwShortcuts(tui, options.thinking?.keybindings);
|
|
96
|
+
this.transcriptComponents = buildTranscriptComponents(turns, this.theme, undefined, options.markdownTransformers);
|
|
97
|
+
this.canBringToMain = turns.some((turn) => turn.kind === "answered");
|
|
98
|
+
this.thinkingLevel = options.thinking?.level;
|
|
99
|
+
const editorTheme: EditorTheme = {
|
|
100
|
+
borderColor: (text) => this.theme.fg("accent", text),
|
|
101
|
+
selectList: {
|
|
102
|
+
selectedPrefix: (text) => this.theme.fg("accent", text),
|
|
103
|
+
selectedText: (text) => this.theme.fg("accent", text),
|
|
104
|
+
description: (text) => this.theme.fg("muted", text),
|
|
105
|
+
scrollInfo: (text) => this.theme.fg("dim", text),
|
|
106
|
+
noMatch: (text) => this.theme.fg("warning", text),
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
this.editor = new Editor(this.tui, editorTheme);
|
|
110
|
+
if (options.initialQuestion) this.editor.setText(options.initialQuestion);
|
|
111
|
+
this.editor.onChange = () => {
|
|
112
|
+
this.warning = undefined;
|
|
113
|
+
};
|
|
114
|
+
this.editor.onSubmit = (text) => {
|
|
115
|
+
const question = text.trim();
|
|
116
|
+
if (!question) {
|
|
117
|
+
this.warning = "Question cannot be empty";
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.finished = true;
|
|
121
|
+
this.onAction({ kind: "submit", question });
|
|
122
|
+
};
|
|
123
|
+
const transcript = this.createTranscriptComponent();
|
|
124
|
+
this.scrollView = new PreservingScrollView(transcript, {
|
|
125
|
+
follow: options.startAtBottom ? "end" : "none",
|
|
126
|
+
primary: true,
|
|
127
|
+
});
|
|
128
|
+
this.layoutRoot = new VStack([
|
|
129
|
+
{ component: this.createHeaderComponent(), basis: 1, shrink: 0, minSize: 1 },
|
|
130
|
+
{ component: this.scrollView, basis: 0, grow: 1, minSize: 0 },
|
|
131
|
+
{ component: this.createFooterComponent(), basis: 1, shrink: 0, minSize: 1 },
|
|
132
|
+
{ component: this.editor, basis: "auto", shrink: 1, minSize: 0 },
|
|
133
|
+
]);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
get focused(): boolean {
|
|
137
|
+
return this.isFocused;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
set focused(value: boolean) {
|
|
141
|
+
this.isFocused = value;
|
|
142
|
+
this.editor.focused = value;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
getFullscreenLayout(): Component {
|
|
146
|
+
return this.layoutRoot;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
render(width: number): string[] {
|
|
150
|
+
if (width <= 0) return [];
|
|
151
|
+
const safeWidth = Math.max(1, width);
|
|
152
|
+
const editorLines = this.editor.render(safeWidth);
|
|
153
|
+
const availableRows = Math.max(1, this.tui.terminal.rows - RESERVED_APP_LINES);
|
|
154
|
+
const viewportHeight = Math.max(0, availableRows - editorLines.length - TRANSCRIPT_CHROME_LINES);
|
|
155
|
+
const contentLines = renderTranscriptLines(this.transcriptComponents, safeWidth);
|
|
156
|
+
this.lastContentLineCount = contentLines.length;
|
|
157
|
+
this.scrollView.updateLayout(contentLines.length, viewportHeight, () => this.tui.requestRender());
|
|
158
|
+
|
|
159
|
+
return fitComposerLayout(
|
|
160
|
+
renderSideThreadHeader(safeWidth, this.theme, this.thinkingLevel),
|
|
161
|
+
contentLines.slice(this.scrollView.scrollTop, this.scrollView.scrollTop + viewportHeight),
|
|
162
|
+
this.renderFooter(safeWidth),
|
|
163
|
+
editorLines,
|
|
164
|
+
availableRows,
|
|
165
|
+
).map((line) => truncateToWidth(line, safeWidth));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
handleInput(data: string): void {
|
|
169
|
+
if (this.finished) return;
|
|
170
|
+
if (this.pasteGuard.consume(data)) {
|
|
171
|
+
this.editor.handleInput(data);
|
|
172
|
+
this.tui.requestRender();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (this.shortcuts.matches(data, "exit")) {
|
|
176
|
+
this.finished = true;
|
|
177
|
+
this.onAction({ kind: "close" });
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (this.canBringToMain && this.shortcuts.matches(data, "bringToMain")) {
|
|
181
|
+
this.finished = true;
|
|
182
|
+
this.onAction({ kind: "bringToMain", questionDraft: this.editor.getExpandedText() });
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const thinking = this.options.thinking;
|
|
186
|
+
if (thinking && thinking.levels.length > 1 && this.shortcuts.matches(data, "cycleThinkingLevel")) {
|
|
187
|
+
const currentIndex = thinking.levels.indexOf(this.thinkingLevel ?? thinking.level);
|
|
188
|
+
const nextLevel = thinking.levels[(currentIndex + 1) % thinking.levels.length];
|
|
189
|
+
if (nextLevel) {
|
|
190
|
+
this.thinkingLevel = nextLevel;
|
|
191
|
+
thinking.onChange(nextLevel);
|
|
192
|
+
this.warning = undefined;
|
|
193
|
+
this.tui.requestRender();
|
|
194
|
+
}
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (matchesKey(data, Key.pageUp)) {
|
|
198
|
+
this.scrollView.scrollBy(-Math.max(1, this.scrollView.viewportHeight));
|
|
199
|
+
this.tui.requestRender();
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (matchesKey(data, Key.pageDown)) {
|
|
203
|
+
this.scrollView.scrollBy(Math.max(1, this.scrollView.viewportHeight));
|
|
204
|
+
this.tui.requestRender();
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
this.editor.handleInput(data);
|
|
208
|
+
if (!this.finished) this.tui.requestRender();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
invalidate(): void {
|
|
212
|
+
this.layoutRoot.invalidate();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
dispose(): void {
|
|
216
|
+
if (this.finished) return;
|
|
217
|
+
this.finished = true;
|
|
218
|
+
this.onAction({ kind: "close" });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private renderFooter(width: number): string {
|
|
222
|
+
const exit = this.shortcuts.label("exit");
|
|
223
|
+
const bring = this.canBringToMain && this.shortcuts.keys.bringToMain.length > 0;
|
|
224
|
+
const bringKey = this.shortcuts.label("bringToMain");
|
|
225
|
+
if (this.warning) {
|
|
226
|
+
const warning = width < 32 ? `Empty • ${exit}` : `${this.warning} • ${exit} exit`;
|
|
227
|
+
return truncateToWidth(this.theme.fg("warning", warning), width);
|
|
228
|
+
}
|
|
229
|
+
const scrollable = this.getMaxScrollOffset() > 0;
|
|
230
|
+
const thinking = this.options.thinking;
|
|
231
|
+
const cycleHint =
|
|
232
|
+
thinking && thinking.levels.length > 1 && this.thinkingLevel && this.shortcuts.keys.cycleThinkingLevel.length
|
|
233
|
+
? ` • thinking ${this.thinkingLevel} • ${this.shortcuts.label("cycleThinkingLevel")} cycle`
|
|
234
|
+
: "";
|
|
235
|
+
const base = bring
|
|
236
|
+
? `btw • Enter send • ${bringKey} bring to main • ${exit} exit`
|
|
237
|
+
: `btw • Enter send • ${exit} exit`;
|
|
238
|
+
const fullBase = `${base}${cycleHint}`;
|
|
239
|
+
const fallbackBase = `btw • Enter • ${exit}`;
|
|
240
|
+
const compactBase = bring ? `btw • Enter • ${bringKey} • ${exit}` : fallbackBase;
|
|
241
|
+
const compactWithThinking = `${compactBase}${cycleHint}`;
|
|
242
|
+
let hints =
|
|
243
|
+
visibleWidth(fullBase) <= width
|
|
244
|
+
? fullBase
|
|
245
|
+
: visibleWidth(compactWithThinking) <= width
|
|
246
|
+
? compactWithThinking
|
|
247
|
+
: visibleWidth(compactBase) <= width
|
|
248
|
+
? compactBase
|
|
249
|
+
: fallbackBase;
|
|
250
|
+
if (scrollable) {
|
|
251
|
+
const history = ` • ${this.scrollView.scrollTop > 0 ? "↑ older" : "↓ newer"} • PgUp/PgDn history`;
|
|
252
|
+
const compactHistory = " • PgUp/PgDn";
|
|
253
|
+
const compactScrollable = bring
|
|
254
|
+
? `Enter • ${bringKey} • ${exit} • PgUp/PgDn`
|
|
255
|
+
: `${fallbackBase}${compactHistory}`;
|
|
256
|
+
if (visibleWidth(`${hints}${history}`) <= width) {
|
|
257
|
+
hints += history;
|
|
258
|
+
} else if (visibleWidth(`${compactBase}${history}`) <= width) {
|
|
259
|
+
hints = `${compactBase}${history}`;
|
|
260
|
+
} else if (visibleWidth(`${hints}${compactHistory}`) <= width) {
|
|
261
|
+
hints += compactHistory;
|
|
262
|
+
} else if (visibleWidth(`${compactBase}${compactHistory}`) <= width) {
|
|
263
|
+
hints = `${compactBase}${compactHistory}`;
|
|
264
|
+
} else if (visibleWidth(compactScrollable) <= width) {
|
|
265
|
+
hints = compactScrollable;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return truncateToWidth(this.theme.fg("muted", hints), width);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
private createHeaderComponent(): Component {
|
|
272
|
+
return {
|
|
273
|
+
render: (width) => [renderSideThreadHeader(width, this.theme, this.thinkingLevel)],
|
|
274
|
+
invalidate() {},
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
private createTranscriptComponent(): Component {
|
|
279
|
+
return {
|
|
280
|
+
render: (width) => {
|
|
281
|
+
const lines = renderTranscriptLines(this.transcriptComponents, width);
|
|
282
|
+
this.lastContentLineCount = lines.length;
|
|
283
|
+
return lines;
|
|
284
|
+
},
|
|
285
|
+
invalidate: () => {
|
|
286
|
+
for (const component of this.transcriptComponents) component.invalidate();
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private createFooterComponent(): Component {
|
|
292
|
+
return {
|
|
293
|
+
render: (width) => [this.renderFooter(width)],
|
|
294
|
+
invalidate() {},
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private getMaxScrollOffset(): number {
|
|
299
|
+
return Math.max(0, this.lastContentLineCount - this.scrollView.viewportHeight);
|
|
300
|
+
}
|
|
314
301
|
}
|
|
315
302
|
|
|
316
303
|
export class BtwAnsweringView implements BtwFullscreenLayoutComponent, Focusable {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
invalidate() {},
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
private createFooterComponent(): Component {
|
|
568
|
-
return {
|
|
569
|
-
render: (width) => [this.renderFooter(width)],
|
|
570
|
-
invalidate: () => this.loader.invalidate(),
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
private getMaxScrollOffset(): number {
|
|
575
|
-
return Math.max(0, this.lastContentLineCount - this.scrollView.viewportHeight);
|
|
576
|
-
}
|
|
304
|
+
private readonly shortcuts: BtwShortcuts;
|
|
305
|
+
private readonly pasteGuard = new BtwPasteGuard();
|
|
306
|
+
private readonly transcriptComponents: Component[];
|
|
307
|
+
private readonly loader: Loader;
|
|
308
|
+
private readonly editor: Editor | undefined;
|
|
309
|
+
private readonly controller = new AbortController();
|
|
310
|
+
private readonly scrollView: ScrollView;
|
|
311
|
+
private readonly layoutRoot: VStack;
|
|
312
|
+
private lastContentLineCount = 0;
|
|
313
|
+
private warning: string | undefined;
|
|
314
|
+
private finished = false;
|
|
315
|
+
private isFocused = false;
|
|
316
|
+
private thinkingLevel: BtwThinkingLevel | undefined;
|
|
317
|
+
|
|
318
|
+
constructor(
|
|
319
|
+
private readonly tui: TUI,
|
|
320
|
+
private readonly theme: Theme,
|
|
321
|
+
turns: readonly SideThreadTurn[],
|
|
322
|
+
pendingQuestion: string,
|
|
323
|
+
private readonly onCancel: () => void,
|
|
324
|
+
thinkingLevel?: BtwThinkingLevel,
|
|
325
|
+
private readonly options: BtwAnsweringViewOptions = {},
|
|
326
|
+
) {
|
|
327
|
+
this.shortcuts = getBtwShortcuts(tui, options.steering?.thinking?.keybindings);
|
|
328
|
+
this.transcriptComponents = buildTranscriptComponents(
|
|
329
|
+
turns,
|
|
330
|
+
this.theme,
|
|
331
|
+
pendingQuestion,
|
|
332
|
+
options.markdownTransformers,
|
|
333
|
+
);
|
|
334
|
+
this.thinkingLevel = options.steering?.thinking?.level ?? thinkingLevel;
|
|
335
|
+
this.loader = new Loader(
|
|
336
|
+
this.tui,
|
|
337
|
+
(text) => this.theme.fg("accent", text),
|
|
338
|
+
(text) => this.theme.fg("muted", text),
|
|
339
|
+
"Answering…",
|
|
340
|
+
);
|
|
341
|
+
if (options.steering) {
|
|
342
|
+
const editorTheme: EditorTheme = {
|
|
343
|
+
borderColor: (text) => this.theme.fg("accent", text),
|
|
344
|
+
selectList: {
|
|
345
|
+
selectedPrefix: (text) => this.theme.fg("accent", text),
|
|
346
|
+
selectedText: (text) => this.theme.fg("accent", text),
|
|
347
|
+
description: (text) => this.theme.fg("muted", text),
|
|
348
|
+
scrollInfo: (text) => this.theme.fg("dim", text),
|
|
349
|
+
noMatch: (text) => this.theme.fg("warning", text),
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
this.editor = new Editor(this.tui, editorTheme);
|
|
353
|
+
this.editor.onChange = () => {
|
|
354
|
+
this.warning = undefined;
|
|
355
|
+
};
|
|
356
|
+
this.editor.onSubmit = (text) => {
|
|
357
|
+
const question = text.trim();
|
|
358
|
+
if (!question) {
|
|
359
|
+
this.warning = "Question cannot be empty";
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
options.steering?.onSubmit(question);
|
|
363
|
+
this.warning = undefined;
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
const transcript = this.createTranscriptComponent();
|
|
367
|
+
this.scrollView = new PreservingScrollView(transcript, { follow: "end", primary: true });
|
|
368
|
+
this.layoutRoot = new VStack([
|
|
369
|
+
{ component: this.createHeaderComponent(), basis: 1, shrink: 0, minSize: 1 },
|
|
370
|
+
{ component: this.scrollView, basis: 0, grow: 1, minSize: 0 },
|
|
371
|
+
{
|
|
372
|
+
component: this.createSteeringComponent(),
|
|
373
|
+
basis: "auto",
|
|
374
|
+
shrink: 1,
|
|
375
|
+
minSize: 0,
|
|
376
|
+
maxSize: MAX_STEERING_DISPLAY_LINES,
|
|
377
|
+
},
|
|
378
|
+
{ component: this.createFooterComponent(), basis: 1, shrink: 0, minSize: 1 },
|
|
379
|
+
...(this.editor ? [{ component: this.editor, basis: "auto" as const, shrink: 1, minSize: 0 }] : []),
|
|
380
|
+
]);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
get focused(): boolean {
|
|
384
|
+
return this.isFocused;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
set focused(value: boolean) {
|
|
388
|
+
this.isFocused = value;
|
|
389
|
+
if (this.editor) this.editor.focused = value;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
get signal(): AbortSignal {
|
|
393
|
+
return this.controller.signal;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
getFullscreenLayout(): Component {
|
|
397
|
+
return this.layoutRoot;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
render(width: number): string[] {
|
|
401
|
+
if (width <= 0) return [];
|
|
402
|
+
const safeWidth = Math.max(1, width);
|
|
403
|
+
const availableRows = Math.max(1, this.tui.terminal.rows - RESERVED_APP_LINES);
|
|
404
|
+
const editorLines = this.editor?.render(safeWidth) ?? [];
|
|
405
|
+
const steeringCapacity = Math.max(0, availableRows - editorLines.length - TRANSCRIPT_CHROME_LINES);
|
|
406
|
+
const steeringLines = renderSteeringLines(
|
|
407
|
+
this.options.steering?.questions ?? [],
|
|
408
|
+
safeWidth,
|
|
409
|
+
this.theme,
|
|
410
|
+
Math.min(MAX_STEERING_DISPLAY_LINES, steeringCapacity),
|
|
411
|
+
);
|
|
412
|
+
const viewportHeight = Math.max(
|
|
413
|
+
0,
|
|
414
|
+
availableRows - editorLines.length - TRANSCRIPT_CHROME_LINES - steeringLines.length,
|
|
415
|
+
);
|
|
416
|
+
const contentLines = renderTranscriptLines(this.transcriptComponents, safeWidth);
|
|
417
|
+
this.lastContentLineCount = contentLines.length;
|
|
418
|
+
this.scrollView.updateLayout(contentLines.length, viewportHeight, () => this.tui.requestRender());
|
|
419
|
+
|
|
420
|
+
return fitComposerLayout(
|
|
421
|
+
renderSideThreadHeader(safeWidth, this.theme, this.thinkingLevel),
|
|
422
|
+
contentLines.slice(this.scrollView.scrollTop, this.scrollView.scrollTop + viewportHeight),
|
|
423
|
+
this.renderFooter(safeWidth),
|
|
424
|
+
editorLines,
|
|
425
|
+
availableRows,
|
|
426
|
+
steeringLines,
|
|
427
|
+
).map((line) => truncateToWidth(line, safeWidth));
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
handleInput(data: string): void {
|
|
431
|
+
if (this.finished) return;
|
|
432
|
+
if (this.pasteGuard.consume(data)) {
|
|
433
|
+
this.editor?.handleInput(data);
|
|
434
|
+
this.tui.requestRender();
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (this.shortcuts.matches(data, "exit")) {
|
|
438
|
+
this.finished = true;
|
|
439
|
+
this.loader.stop();
|
|
440
|
+
this.controller.abort();
|
|
441
|
+
this.onCancel();
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const thinking = this.options.steering?.thinking;
|
|
445
|
+
if (thinking && thinking.levels.length > 1 && this.shortcuts.matches(data, "cycleThinkingLevel")) {
|
|
446
|
+
const currentIndex = thinking.levels.indexOf(this.thinkingLevel ?? thinking.level);
|
|
447
|
+
const nextLevel = thinking.levels[(currentIndex + 1) % thinking.levels.length];
|
|
448
|
+
if (nextLevel) {
|
|
449
|
+
this.thinkingLevel = nextLevel;
|
|
450
|
+
thinking.onChange(nextLevel);
|
|
451
|
+
this.warning = undefined;
|
|
452
|
+
this.tui.requestRender();
|
|
453
|
+
}
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (matchesKey(data, Key.pageUp)) {
|
|
457
|
+
this.scrollView.scrollBy(-Math.max(1, this.scrollView.viewportHeight));
|
|
458
|
+
this.tui.requestRender();
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if (matchesKey(data, Key.pageDown)) {
|
|
462
|
+
this.scrollView.scrollBy(Math.max(1, this.scrollView.viewportHeight));
|
|
463
|
+
this.tui.requestRender();
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
this.editor?.handleInput(data);
|
|
467
|
+
this.tui.requestRender();
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
invalidate(): void {
|
|
471
|
+
this.layoutRoot.invalidate();
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
finish(): void {
|
|
475
|
+
this.finished = true;
|
|
476
|
+
this.loader.stop();
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
dispose(): void {
|
|
480
|
+
if (this.finished) {
|
|
481
|
+
this.loader.stop();
|
|
482
|
+
this.controller.abort();
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
this.finished = true;
|
|
486
|
+
this.loader.stop();
|
|
487
|
+
this.controller.abort();
|
|
488
|
+
this.onCancel();
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
private renderFooter(width: number): string {
|
|
492
|
+
const exit = this.shortcuts.label("exit");
|
|
493
|
+
if (this.warning) {
|
|
494
|
+
const warning = width < 32 ? `Empty • ${exit}` : `${this.warning} • ${exit} cancel`;
|
|
495
|
+
return truncateToWidth(this.theme.fg("warning", warning), width);
|
|
496
|
+
}
|
|
497
|
+
const baseHint = this.editor ? `Enter steer • ${exit} cancel` : `${exit} cancel`;
|
|
498
|
+
const thinking = this.options.steering?.thinking;
|
|
499
|
+
const cycleHint =
|
|
500
|
+
thinking && thinking.levels.length > 1 && this.thinkingLevel && this.shortcuts.keys.cycleThinkingLevel.length
|
|
501
|
+
? ` • thinking ${this.thinkingLevel} • ${this.shortcuts.label("cycleThinkingLevel")} cycle`
|
|
502
|
+
: "";
|
|
503
|
+
const scrollHint = this.getMaxScrollOffset() > 0 ? " • PgUp/PgDn history" : "";
|
|
504
|
+
const hints = `${baseHint}${cycleHint}${scrollHint}`;
|
|
505
|
+
const compactHints = this.editor ? `Enter • ${exit}` : exit;
|
|
506
|
+
const selectedHints = visibleWidth(hints) <= width ? hints : compactHints;
|
|
507
|
+
const loaderWidth = Math.max(1, width - visibleWidth(selectedHints) - 3);
|
|
508
|
+
const loaderLine = this.loader.render(loaderWidth).at(-1) ?? "Answering…";
|
|
509
|
+
return truncateToWidth(`${loaderLine} • ${this.theme.fg("muted", selectedHints)}`, width);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
private createHeaderComponent(): Component {
|
|
513
|
+
return {
|
|
514
|
+
render: (width) => [renderSideThreadHeader(width, this.theme, this.thinkingLevel)],
|
|
515
|
+
invalidate() {},
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
private createTranscriptComponent(): Component {
|
|
520
|
+
return {
|
|
521
|
+
render: (width) => {
|
|
522
|
+
const lines = renderTranscriptLines(this.transcriptComponents, width);
|
|
523
|
+
this.lastContentLineCount = lines.length;
|
|
524
|
+
return lines;
|
|
525
|
+
},
|
|
526
|
+
invalidate: () => {
|
|
527
|
+
for (const component of this.transcriptComponents) component.invalidate();
|
|
528
|
+
},
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
private createSteeringComponent(): Component {
|
|
533
|
+
return {
|
|
534
|
+
render: (width) =>
|
|
535
|
+
renderSteeringLines(this.options.steering?.questions ?? [], width, this.theme, MAX_STEERING_DISPLAY_LINES),
|
|
536
|
+
invalidate() {},
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
private createFooterComponent(): Component {
|
|
541
|
+
return {
|
|
542
|
+
render: (width) => [this.renderFooter(width)],
|
|
543
|
+
invalidate: () => this.loader.invalidate(),
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
private getMaxScrollOffset(): number {
|
|
548
|
+
return Math.max(0, this.lastContentLineCount - this.scrollView.viewportHeight);
|
|
549
|
+
}
|
|
577
550
|
}
|
|
578
551
|
|
|
579
552
|
export function formatSideTranscript(turns: readonly SideThreadTurn[]): string {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
553
|
+
return turns
|
|
554
|
+
.map((turn) => {
|
|
555
|
+
const question = escapeTerminalControls(turn.question);
|
|
556
|
+
const rawAnswer = escapeTerminalControls(turn.answer);
|
|
557
|
+
const answer = turn.kind === "error" ? `Error: ${rawAnswer}` : rawAnswer;
|
|
558
|
+
return `${question}\n\n${answer}`;
|
|
559
|
+
})
|
|
560
|
+
.join("\n\n");
|
|
588
561
|
}
|
|
589
562
|
|
|
590
563
|
function buildTranscriptComponents(
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
564
|
+
turns: readonly SideThreadTurn[],
|
|
565
|
+
theme: Theme,
|
|
566
|
+
pendingQuestion?: string,
|
|
567
|
+
markdownTransformers: readonly MarkdownTransformer[] = [],
|
|
594
568
|
): Component[] {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
);
|
|
623
|
-
}
|
|
624
|
-
return components;
|
|
569
|
+
const components = turns.flatMap((turn): Component[] => {
|
|
570
|
+
const question = new UserMessageComponent(
|
|
571
|
+
escapeTerminalControls(turn.question),
|
|
572
|
+
getMarkdownTheme(),
|
|
573
|
+
1,
|
|
574
|
+
markdownTransformers,
|
|
575
|
+
);
|
|
576
|
+
if (turn.kind === "error") {
|
|
577
|
+
const error = new Markdown(`Error: ${escapeTerminalControls(turn.answer)}`, 1, 1, getMarkdownTheme(), {
|
|
578
|
+
color: (text) => theme.fg("error", text),
|
|
579
|
+
});
|
|
580
|
+
return [question, error];
|
|
581
|
+
}
|
|
582
|
+
const response: AssistantMessage = {
|
|
583
|
+
...turn.response,
|
|
584
|
+
content: [{ type: "text", text: escapeTerminalControls(turn.answer) }],
|
|
585
|
+
stopReason: "stop",
|
|
586
|
+
errorMessage: undefined,
|
|
587
|
+
};
|
|
588
|
+
return [question, new AssistantMessageComponent(response, true, getMarkdownTheme(), "", 1, markdownTransformers)];
|
|
589
|
+
});
|
|
590
|
+
if (pendingQuestion) {
|
|
591
|
+
components.push(
|
|
592
|
+
new UserMessageComponent(escapeTerminalControls(pendingQuestion), getMarkdownTheme(), 1, markdownTransformers),
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
return components;
|
|
625
596
|
}
|
|
626
597
|
|
|
627
598
|
function renderTranscriptLines(components: readonly Component[], width: number): string[] {
|
|
628
|
-
|
|
629
|
-
.flatMap((component) => component.render(width))
|
|
630
|
-
.map(stripShellIntegrationMarkers);
|
|
599
|
+
return components.flatMap((component) => component.render(width)).map(stripShellIntegrationMarkers);
|
|
631
600
|
}
|
|
632
601
|
|
|
633
|
-
function renderSideThreadHeader(
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
const thinking = thinkingLevel ? ` · thinking ${thinkingLevel}` : "";
|
|
639
|
-
const title = truncateToWidth(`─ btw · side thread${thinking} `, width);
|
|
640
|
-
const ruleWidth = Math.max(0, width - visibleWidth(title));
|
|
641
|
-
return theme.fg("muted", `${title}${"─".repeat(ruleWidth)}`);
|
|
602
|
+
function renderSideThreadHeader(width: number, theme: Theme, thinkingLevel?: BtwThinkingLevel): string {
|
|
603
|
+
const thinking = thinkingLevel ? ` · thinking ${thinkingLevel}` : "";
|
|
604
|
+
const title = truncateToWidth(`─ btw · side thread${thinking} `, width);
|
|
605
|
+
const ruleWidth = Math.max(0, width - visibleWidth(title));
|
|
606
|
+
return theme.fg("muted", `${title}${"─".repeat(ruleWidth)}`);
|
|
642
607
|
}
|
|
643
608
|
|
|
644
609
|
function fitComposerLayout(
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
610
|
+
header: string,
|
|
611
|
+
contentLines: string[],
|
|
612
|
+
footer: string,
|
|
613
|
+
editorLines: string[],
|
|
614
|
+
availableRows: number,
|
|
615
|
+
statusLines: string[] = [],
|
|
651
616
|
): string[] {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
617
|
+
const lines = [header, ...contentLines, ...statusLines, footer, ...editorLines];
|
|
618
|
+
if (lines.length <= availableRows) return lines;
|
|
619
|
+
if (availableRows <= 1) return [header];
|
|
620
|
+
const editorBudget = Math.max(0, availableRows - 2);
|
|
621
|
+
return [header, footer, ...fitEditorLines(editorLines, editorBudget)];
|
|
657
622
|
}
|
|
658
623
|
|
|
659
624
|
function fitEditorLines(editorLines: string[], budget: number): string[] {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
625
|
+
if (budget <= 0) return [];
|
|
626
|
+
if (editorLines.length <= budget) return editorLines;
|
|
627
|
+
const cursorIndex = editorLines.findIndex((line) => line.includes(CURSOR_MARKER));
|
|
628
|
+
if (cursorIndex < 0) return editorLines.slice(-budget);
|
|
629
|
+
const start = Math.min(cursorIndex, editorLines.length - budget);
|
|
630
|
+
return editorLines.slice(start, start + budget);
|
|
666
631
|
}
|
|
667
632
|
|
|
668
|
-
function renderSteeringLines(
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
const hasOverflow = questions.length > maxLines;
|
|
689
|
-
const questionLimit = hasOverflow ? Math.max(1, maxLines - 1) : maxLines;
|
|
690
|
-
const lines = questions
|
|
691
|
-
.slice(0, questionLimit)
|
|
692
|
-
.map((question) =>
|
|
693
|
-
truncateToWidth(theme.fg("dim", `Steering: ${formatQuestion(question)}`), width),
|
|
694
|
-
);
|
|
695
|
-
if (hasOverflow) {
|
|
696
|
-
lines.push(
|
|
697
|
-
truncateToWidth(
|
|
698
|
-
theme.fg("dim", `Steering: … +${questions.length - questionLimit} more`),
|
|
699
|
-
width,
|
|
700
|
-
),
|
|
701
|
-
);
|
|
702
|
-
}
|
|
703
|
-
return lines;
|
|
633
|
+
function renderSteeringLines(questions: readonly string[], width: number, theme: Theme, maxLines: number): string[] {
|
|
634
|
+
if (questions.length === 0 || maxLines <= 0) return [];
|
|
635
|
+
const formatQuestion = (question: string) => sanitizeSingleLine(question) || "(non-printing message)";
|
|
636
|
+
if (maxLines === 1 && questions.length > 1) {
|
|
637
|
+
return [
|
|
638
|
+
truncateToWidth(
|
|
639
|
+
theme.fg("dim", `Steering (+${questions.length - 1} more): ${formatQuestion(questions[0] ?? "")}`),
|
|
640
|
+
width,
|
|
641
|
+
),
|
|
642
|
+
];
|
|
643
|
+
}
|
|
644
|
+
const hasOverflow = questions.length > maxLines;
|
|
645
|
+
const questionLimit = hasOverflow ? Math.max(1, maxLines - 1) : maxLines;
|
|
646
|
+
const lines = questions
|
|
647
|
+
.slice(0, questionLimit)
|
|
648
|
+
.map((question) => truncateToWidth(theme.fg("dim", `Steering: ${formatQuestion(question)}`), width));
|
|
649
|
+
if (hasOverflow) {
|
|
650
|
+
lines.push(truncateToWidth(theme.fg("dim", `Steering: … +${questions.length - questionLimit} more`), width));
|
|
651
|
+
}
|
|
652
|
+
return lines;
|
|
704
653
|
}
|
|
705
654
|
|
|
706
655
|
function stripShellIntegrationMarkers(line: string): string {
|
|
707
|
-
|
|
656
|
+
return OSC133_MARKERS.reduce((result, marker) => result.replaceAll(marker, ""), line);
|
|
708
657
|
}
|
|
709
658
|
|
|
710
659
|
function escapeTerminalControls(text: string): string {
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
660
|
+
return [...text]
|
|
661
|
+
.map((character) => {
|
|
662
|
+
if (character === "\n") return character;
|
|
663
|
+
if (character === "\t") return " ";
|
|
664
|
+
const code = character.charCodeAt(0);
|
|
665
|
+
if (code <= 31 || (code >= 127 && code <= 159)) {
|
|
666
|
+
return `\\x${code.toString(16).padStart(2, "0")}`;
|
|
667
|
+
}
|
|
668
|
+
return character;
|
|
669
|
+
})
|
|
670
|
+
.join("");
|
|
722
671
|
}
|