@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,509 +1,471 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ExtensionCommandContext,
|
|
3
|
-
KeybindingsManager,
|
|
4
|
-
Theme,
|
|
5
|
-
} from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import type { ExtensionCommandContext, KeybindingsManager, Theme } from "@earendil-works/pi-coding-agent";
|
|
6
2
|
import type { Component, TUI } from "@earendil-works/pi-tui";
|
|
7
3
|
import type { MenuContext, RunMenuResult } from "@narumitw/pi-tui-kit";
|
|
8
4
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
BTW_SHORTCUT_ACTIONS,
|
|
6
|
+
type BtwShortcutAction,
|
|
7
|
+
normalizeBtwKey,
|
|
8
|
+
resolveBtwShortcuts,
|
|
9
|
+
validateBtwShortcutEdit,
|
|
14
10
|
} from "./keybindings.js";
|
|
15
11
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
type BtwSettings,
|
|
13
|
+
type BtwSettingsPatch,
|
|
14
|
+
btwSettingsPath,
|
|
15
|
+
effectiveFullscreenCopyOnSelect,
|
|
16
|
+
effectiveRememberThinkingLevelChanges,
|
|
17
|
+
readBtwSettings,
|
|
18
|
+
type UpdateBtwSettingsOptions,
|
|
19
|
+
updateBtwSettings,
|
|
24
20
|
} from "./settings.js";
|
|
25
21
|
import { BTW_THINKING_LEVELS, type BtwThinkingLevel } from "./side-thread.js";
|
|
26
22
|
import { formatKeyLabel, sanitizeSingleLine } from "./text.js";
|
|
27
23
|
|
|
28
24
|
interface BtwMenuState {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
kind: "valid" | "invalid";
|
|
26
|
+
settings: BtwSettings;
|
|
27
|
+
reason?: string;
|
|
32
28
|
}
|
|
33
29
|
|
|
34
30
|
export interface BtwResumeThreadSummary {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
id: string;
|
|
32
|
+
title: string;
|
|
33
|
+
questionCount: number;
|
|
38
34
|
}
|
|
39
35
|
|
|
40
36
|
export interface ShowBtwCommandMenuOptions {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
patch: BtwSettingsPatch,
|
|
48
|
-
options: UpdateBtwSettingsOptions,
|
|
49
|
-
) => Promise<BtwSettings>;
|
|
37
|
+
currentThinkingLevel: BtwThinkingLevel;
|
|
38
|
+
availableThinkingLevels: readonly BtwThinkingLevel[];
|
|
39
|
+
resumeThreads?: readonly BtwResumeThreadSummary[];
|
|
40
|
+
settingsPath?: string;
|
|
41
|
+
readSettings?: typeof readBtwSettings;
|
|
42
|
+
updateSettings?: (patch: BtwSettingsPatch, options: UpdateBtwSettingsOptions) => Promise<BtwSettings>;
|
|
50
43
|
}
|
|
51
44
|
|
|
52
|
-
export type BtwCommandMenuResult =
|
|
53
|
-
| "start"
|
|
54
|
-
| "tree"
|
|
55
|
-
| "closed"
|
|
56
|
-
| { kind: "resume"; threadId: string };
|
|
45
|
+
export type BtwCommandMenuResult = "start" | "tree" | "closed" | { kind: "resume"; threadId: string };
|
|
57
46
|
|
|
58
47
|
type BtwMenuScreen = "main" | "resume" | "settings" | "invalid" | "shortcut" | "shortcut-input";
|
|
59
48
|
type BtwMenuAction =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
49
|
+
| "start"
|
|
50
|
+
| "start-tree"
|
|
51
|
+
| "resume"
|
|
52
|
+
| "set-thinking"
|
|
53
|
+
| "set-remember"
|
|
54
|
+
| "set-fullscreen-copy"
|
|
55
|
+
| "edit-shortcut"
|
|
56
|
+
| "save-shortcut"
|
|
57
|
+
| "reset-shortcut";
|
|
69
58
|
const SAME_AS_MAIN_THREAD = "Same as main thread";
|
|
70
59
|
type BtwCustomOptions = Parameters<ExtensionCommandContext["ui"]["custom"]>[1];
|
|
71
60
|
|
|
72
61
|
type BtwCustomFactory<T> = (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
62
|
+
tui: TUI,
|
|
63
|
+
theme: Theme,
|
|
64
|
+
keybindings: KeybindingsManager,
|
|
65
|
+
done: (result: T) => void,
|
|
77
66
|
) => Component;
|
|
78
67
|
|
|
79
68
|
export async function showBtwCommandMenu(
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
ctx: ExtensionCommandContext,
|
|
70
|
+
options: ShowBtwCommandMenuOptions,
|
|
82
71
|
): Promise<BtwCommandMenuResult> {
|
|
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
|
-
validateCurrent: (settings) => {
|
|
153
|
-
const conflict = validate(settings);
|
|
154
|
-
if (conflict) throw new Error(conflict);
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
);
|
|
158
|
-
if (signal.aborted) return { kind: "rejected" } as const;
|
|
159
|
-
notifySafely(ctx, "Pi BTW shortcut saved; applies when opening or resuming BTW.", "info");
|
|
160
|
-
return { kind: "back" } as const;
|
|
161
|
-
} catch (error) {
|
|
162
|
-
if (!signal.aborted) notifySaveFailure(ctx, error);
|
|
163
|
-
return { kind: "rejected" } as const;
|
|
164
|
-
}
|
|
165
|
-
};
|
|
72
|
+
if (ctx.mode !== "tui") return "closed";
|
|
73
|
+
const { defineMenu, runMenu } = await import("@narumitw/pi-tui-kit");
|
|
74
|
+
if (ctx.signal?.aborted) return "closed";
|
|
75
|
+
const settingsPath = options.settingsPath ?? btwSettingsPath();
|
|
76
|
+
const readSettings = options.readSettings ?? readBtwSettings;
|
|
77
|
+
const updateSettings = options.updateSettings ?? updateBtwSettings;
|
|
78
|
+
const levels =
|
|
79
|
+
options.availableThinkingLevels.length > 0
|
|
80
|
+
? [...options.availableThinkingLevels]
|
|
81
|
+
: (["off"] satisfies BtwThinkingLevel[]);
|
|
82
|
+
const displaySettingsPath = sanitizeSingleLine(settingsPath);
|
|
83
|
+
const resumeThreads = options.resumeThreads ?? [];
|
|
84
|
+
let startSelected = false;
|
|
85
|
+
let treeSelected = false;
|
|
86
|
+
let resumedThreadId: string | undefined;
|
|
87
|
+
let keybindings: KeybindingsManager | undefined;
|
|
88
|
+
let shortcut: BtwShortcutAction = "exit";
|
|
89
|
+
const shortcutLabels: Record<BtwShortcutAction, string> = {
|
|
90
|
+
exit: "Exit shortcut",
|
|
91
|
+
cycleThinkingLevel: "Cycle thinking level shortcut",
|
|
92
|
+
bringToMain: "Bring to main shortcut",
|
|
93
|
+
};
|
|
94
|
+
const shortcutValue = (settings: BtwSettings, action: BtwShortcutAction): string => {
|
|
95
|
+
if (!keybindings) return "Default";
|
|
96
|
+
const effective = resolveBtwShortcuts(settings.keybindings, keybindings, effectiveFullscreenCopyOnSelect(settings));
|
|
97
|
+
const configured = settings.keybindings?.[action];
|
|
98
|
+
if (configured !== undefined && !effective.keys[action].includes(configured)) {
|
|
99
|
+
return `Fallback (${effective.label(action)}; saved ${formatKeyLabel(configured)})`;
|
|
100
|
+
}
|
|
101
|
+
const source = configured === undefined ? (action === "cycleThinkingLevel" ? "Inherit Pi" : "Default") : "Custom";
|
|
102
|
+
return `${source} (${effective.label(action)})`;
|
|
103
|
+
};
|
|
104
|
+
const saveShortcut = async (state: BtwMenuState, value: string | undefined, signal: AbortSignal) => {
|
|
105
|
+
if (!keybindings || state.kind !== "valid" || signal.aborted) return { kind: "rejected" } as const;
|
|
106
|
+
const action = shortcut;
|
|
107
|
+
const manager = keybindings;
|
|
108
|
+
const validate = (settings: BtwSettings) =>
|
|
109
|
+
validateBtwShortcutEdit(
|
|
110
|
+
action,
|
|
111
|
+
value,
|
|
112
|
+
settings.keybindings ?? {},
|
|
113
|
+
manager,
|
|
114
|
+
effectiveFullscreenCopyOnSelect(settings),
|
|
115
|
+
);
|
|
116
|
+
const error = validate(state.settings);
|
|
117
|
+
if (error) {
|
|
118
|
+
notifySafely(ctx, error, "error");
|
|
119
|
+
return { kind: "rejected" } as const;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
await updateSettings(
|
|
123
|
+
{ keybindings: { [action]: value === undefined ? undefined : normalizeBtwKey(value) } },
|
|
124
|
+
{
|
|
125
|
+
settingsPath,
|
|
126
|
+
signal,
|
|
127
|
+
validateCurrent: (settings) => {
|
|
128
|
+
const conflict = validate(settings);
|
|
129
|
+
if (conflict) throw new Error(conflict);
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
if (signal.aborted) return { kind: "rejected" } as const;
|
|
134
|
+
notifySafely(ctx, "Pi BTW shortcut saved; applies when opening or resuming BTW.", "info");
|
|
135
|
+
return { kind: "back" } as const;
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if (!signal.aborted) notifySaveFailure(ctx, error);
|
|
138
|
+
return { kind: "rejected" } as const;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
166
141
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const value = effectiveRememberThinkingLevelChanges(settings) ? "On" : "Off";
|
|
188
|
-
return settings.thinkingLevel === undefined ? `${value} (fixed levels only)` : value;
|
|
189
|
-
};
|
|
142
|
+
const loadState = async (): Promise<BtwMenuState> => {
|
|
143
|
+
const loaded = await readSettings(settingsPath);
|
|
144
|
+
if (loaded.kind === "invalid") {
|
|
145
|
+
return { kind: "invalid", settings: {}, reason: loaded.reason };
|
|
146
|
+
}
|
|
147
|
+
return { kind: "valid", settings: loaded.kind === "loaded" ? loaded.settings : {} };
|
|
148
|
+
};
|
|
149
|
+
const currentMainThinkingLevel = clampToAvailableThinkingLevel(options.currentThinkingLevel, levels);
|
|
150
|
+
const displayThinkingLevel = (settings: BtwSettings): string =>
|
|
151
|
+
settings.thinkingLevel === undefined
|
|
152
|
+
? SAME_AS_MAIN_THREAD
|
|
153
|
+
: clampToAvailableThinkingLevel(settings.thinkingLevel, levels);
|
|
154
|
+
const displayThinkingSummary = (settings: BtwSettings): string =>
|
|
155
|
+
settings.thinkingLevel === undefined
|
|
156
|
+
? `${SAME_AS_MAIN_THREAD} (currently ${currentMainThinkingLevel})`
|
|
157
|
+
: displayThinkingLevel(settings);
|
|
158
|
+
const displayRememberSummary = (settings: BtwSettings): string => {
|
|
159
|
+
const value = effectiveRememberThinkingLevelChanges(settings) ? "On" : "Off";
|
|
160
|
+
return settings.thinkingLevel === undefined ? `${value} (fixed levels only)` : value;
|
|
161
|
+
};
|
|
190
162
|
|
|
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
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
if (signal.aborted) return { kind: "rejected" };
|
|
381
|
-
notifySafely(ctx, `Copy selection automatically: ${value}.`, "info");
|
|
382
|
-
return { kind: "stay" };
|
|
383
|
-
} catch (error) {
|
|
384
|
-
if (!signal.aborted) notifySaveFailure(ctx, error);
|
|
385
|
-
return { kind: "rejected" };
|
|
386
|
-
}
|
|
387
|
-
},
|
|
388
|
-
},
|
|
389
|
-
});
|
|
163
|
+
const menu = defineMenu<BtwMenuState, BtwMenuScreen, BtwMenuAction, MenuContext>({
|
|
164
|
+
start: "main",
|
|
165
|
+
screens: {
|
|
166
|
+
main: ({ state }) => ({
|
|
167
|
+
kind: "actions",
|
|
168
|
+
title: "Pi BTW",
|
|
169
|
+
lines: [
|
|
170
|
+
`Thinking: ${displayThinkingSummary(state.settings)} · Remember changes: ${displayRememberSummary(state.settings)}`,
|
|
171
|
+
`Copy on select: ${effectiveFullscreenCopyOnSelect(state.settings) ? "On" : "Off"}`,
|
|
172
|
+
],
|
|
173
|
+
items: [
|
|
174
|
+
{
|
|
175
|
+
id: "start",
|
|
176
|
+
label: "Start side thread",
|
|
177
|
+
description: "Open an empty side thread",
|
|
178
|
+
action: "start",
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
id: "start-tree",
|
|
182
|
+
label: "Start from main thread tree…",
|
|
183
|
+
description: "Choose context without switching the main branch",
|
|
184
|
+
action: "start-tree",
|
|
185
|
+
},
|
|
186
|
+
...(resumeThreads.length > 0
|
|
187
|
+
? [
|
|
188
|
+
{
|
|
189
|
+
id: "resume" as const,
|
|
190
|
+
label: "Resume side thread",
|
|
191
|
+
description: "Continue an in-memory side thread",
|
|
192
|
+
to: "resume" as const,
|
|
193
|
+
},
|
|
194
|
+
]
|
|
195
|
+
: []),
|
|
196
|
+
{
|
|
197
|
+
id: "settings",
|
|
198
|
+
label: "Settings",
|
|
199
|
+
description: "Choose thinking, keybindings, and selection copying",
|
|
200
|
+
to: state.kind === "invalid" ? "invalid" : "settings",
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
hint: "close",
|
|
204
|
+
}),
|
|
205
|
+
resume: () => ({
|
|
206
|
+
kind: "choice",
|
|
207
|
+
title: "Resume BTW side thread",
|
|
208
|
+
enableSearch: true,
|
|
209
|
+
items: resumeThreads.map((thread) => ({
|
|
210
|
+
id: thread.id,
|
|
211
|
+
label: thread.title,
|
|
212
|
+
description: `${thread.questionCount} ${thread.questionCount === 1 ? "question" : "questions"}`,
|
|
213
|
+
})),
|
|
214
|
+
action: "resume",
|
|
215
|
+
viewportSize: 10,
|
|
216
|
+
hint: "back",
|
|
217
|
+
}),
|
|
218
|
+
settings: ({ state }) => ({
|
|
219
|
+
kind: "settings",
|
|
220
|
+
title: "Pi BTW Settings",
|
|
221
|
+
lines: [`User settings · ${displaySettingsPath}`],
|
|
222
|
+
items: [
|
|
223
|
+
{
|
|
224
|
+
id: "thinkingLevel",
|
|
225
|
+
label: "Thinking level",
|
|
226
|
+
description: `Set the starting level for future pi-btw side threads. Currently ${currentMainThinkingLevel}.`,
|
|
227
|
+
currentValue: displayThinkingLevel(state.settings),
|
|
228
|
+
values: [SAME_AS_MAIN_THREAD, ...levels],
|
|
229
|
+
action: "set-thinking",
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
id: "rememberThinkingLevelChanges",
|
|
233
|
+
label: "Remember thinking level changes",
|
|
234
|
+
description: "Save shortcut changes for fixed thinking levels to pi-btw.json.",
|
|
235
|
+
currentValue: effectiveRememberThinkingLevelChanges(state.settings) ? "On" : "Off",
|
|
236
|
+
values: ["On", "Off"],
|
|
237
|
+
action: "set-remember",
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
id: "fullscreenCopyOnSelect",
|
|
241
|
+
label: "Copy selection automatically",
|
|
242
|
+
description: "Copy mouse selections immediately instead of with the configured copy key.",
|
|
243
|
+
currentValue: effectiveFullscreenCopyOnSelect(state.settings) ? "On" : "Off",
|
|
244
|
+
values: ["On", "Off"],
|
|
245
|
+
action: "set-fullscreen-copy",
|
|
246
|
+
},
|
|
247
|
+
...BTW_SHORTCUT_ACTIONS.map((action) => ({
|
|
248
|
+
id: action,
|
|
249
|
+
label: shortcutLabels[action],
|
|
250
|
+
description: "Edit a BTW-only key combination or restore its default. Ctrl+C always hard-cancels.",
|
|
251
|
+
currentValue: shortcutValue(state.settings, action),
|
|
252
|
+
action: "edit-shortcut" as const,
|
|
253
|
+
})),
|
|
254
|
+
],
|
|
255
|
+
}),
|
|
256
|
+
shortcut: ({ state }) => ({
|
|
257
|
+
kind: "actions",
|
|
258
|
+
title: shortcutLabels[shortcut],
|
|
259
|
+
lines: [shortcutValue(state.settings, shortcut), "Ctrl+C always hard-cancels BTW."],
|
|
260
|
+
items: [
|
|
261
|
+
{ id: "edit", label: "Edit key combination…", to: "shortcut-input" },
|
|
262
|
+
{ id: "reset", label: "Restore default", action: "reset-shortcut" },
|
|
263
|
+
],
|
|
264
|
+
hint: "back",
|
|
265
|
+
}),
|
|
266
|
+
"shortcut-input": () => ({
|
|
267
|
+
kind: "input",
|
|
268
|
+
title: shortcutLabels[shortcut],
|
|
269
|
+
lines: ["Type a key name, not the shortcut itself. For example: ctrl+q or f6."],
|
|
270
|
+
placeholder: "Key combination",
|
|
271
|
+
action: "save-shortcut",
|
|
272
|
+
hint: "back",
|
|
273
|
+
}),
|
|
274
|
+
invalid: ({ state }) => ({
|
|
275
|
+
kind: "detail",
|
|
276
|
+
title: "Pi BTW Settings · Read only",
|
|
277
|
+
lines: [
|
|
278
|
+
`Invalid settings file. Fix ${displaySettingsPath} before saving.`,
|
|
279
|
+
sanitizeSingleLine(state.reason ?? "The settings file is invalid."),
|
|
280
|
+
],
|
|
281
|
+
hint: "back",
|
|
282
|
+
}),
|
|
283
|
+
},
|
|
284
|
+
actions: {
|
|
285
|
+
"edit-shortcut": ({ itemId }) => {
|
|
286
|
+
if (!BTW_SHORTCUT_ACTIONS.includes(itemId as BtwShortcutAction)) return { kind: "rejected" };
|
|
287
|
+
shortcut = itemId as BtwShortcutAction;
|
|
288
|
+
return { kind: "to", screen: "shortcut" };
|
|
289
|
+
},
|
|
290
|
+
"save-shortcut": ({ state, value, signal }) => saveShortcut(state, value?.trim() ?? "", signal),
|
|
291
|
+
"reset-shortcut": ({ state, signal }) => saveShortcut(state, undefined, signal),
|
|
292
|
+
start: async () => {
|
|
293
|
+
startSelected = true;
|
|
294
|
+
return { kind: "close" };
|
|
295
|
+
},
|
|
296
|
+
"start-tree": async () => {
|
|
297
|
+
treeSelected = true;
|
|
298
|
+
return { kind: "close" };
|
|
299
|
+
},
|
|
300
|
+
resume: async ({ itemId }: { itemId: string }) => {
|
|
301
|
+
if (!resumeThreads.some((thread) => thread.id === itemId)) {
|
|
302
|
+
return { kind: "rejected" } as const;
|
|
303
|
+
}
|
|
304
|
+
resumedThreadId = itemId;
|
|
305
|
+
return { kind: "close" } as const;
|
|
306
|
+
},
|
|
307
|
+
"set-thinking": async ({ value, signal }) => {
|
|
308
|
+
if (!value) return { kind: "rejected" };
|
|
309
|
+
const patch =
|
|
310
|
+
value === SAME_AS_MAIN_THREAD
|
|
311
|
+
? ({ thinkingLevel: undefined } satisfies BtwSettingsPatch)
|
|
312
|
+
: levels.includes(value as BtwThinkingLevel)
|
|
313
|
+
? ({ thinkingLevel: value as BtwThinkingLevel } satisfies BtwSettingsPatch)
|
|
314
|
+
: undefined;
|
|
315
|
+
if (!patch) return { kind: "rejected" };
|
|
316
|
+
try {
|
|
317
|
+
await updateSettings(patch, { settingsPath, signal });
|
|
318
|
+
if (signal.aborted) return { kind: "rejected" };
|
|
319
|
+
notifySafely(ctx, `Pi BTW thinking level: ${value}.`, "info");
|
|
320
|
+
return { kind: "stay" };
|
|
321
|
+
} catch (error) {
|
|
322
|
+
if (!signal.aborted) notifySaveFailure(ctx, error);
|
|
323
|
+
return { kind: "rejected" };
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
"set-remember": async ({ value, signal }) => {
|
|
327
|
+
if (value !== "On" && value !== "Off") return { kind: "rejected" };
|
|
328
|
+
try {
|
|
329
|
+
await updateSettings({ rememberThinkingLevelChanges: value === "On" }, { settingsPath, signal });
|
|
330
|
+
if (signal.aborted) return { kind: "rejected" };
|
|
331
|
+
notifySafely(ctx, `Remember thinking level changes: ${value}.`, "info");
|
|
332
|
+
return { kind: "stay" };
|
|
333
|
+
} catch (error) {
|
|
334
|
+
if (!signal.aborted) notifySaveFailure(ctx, error);
|
|
335
|
+
return { kind: "rejected" };
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
"set-fullscreen-copy": async ({ value, signal }) => {
|
|
339
|
+
if (value !== "On" && value !== "Off") return { kind: "rejected" };
|
|
340
|
+
try {
|
|
341
|
+
await updateSettings({ fullscreenCopyOnSelect: value === "On" }, { settingsPath, signal });
|
|
342
|
+
if (signal.aborted) return { kind: "rejected" };
|
|
343
|
+
notifySafely(ctx, `Copy selection automatically: ${value}.`, "info");
|
|
344
|
+
return { kind: "stay" };
|
|
345
|
+
} catch (error) {
|
|
346
|
+
if (!signal.aborted) notifySaveFailure(ctx, error);
|
|
347
|
+
return { kind: "rejected" };
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
});
|
|
390
352
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
353
|
+
const result = await runBtwMenuPreservingEditor(
|
|
354
|
+
ctx,
|
|
355
|
+
(menuContext) => runMenu(menuContext, menu, { getState: loadState }),
|
|
356
|
+
(manager) => {
|
|
357
|
+
keybindings = manager;
|
|
358
|
+
},
|
|
359
|
+
);
|
|
360
|
+
if (result.kind !== "closed" || result.reason !== "close") return "closed";
|
|
361
|
+
if (resumedThreadId) return { kind: "resume", threadId: resumedThreadId };
|
|
362
|
+
if (treeSelected) return "tree";
|
|
363
|
+
return startSelected ? "start" : "closed";
|
|
402
364
|
}
|
|
403
365
|
|
|
404
366
|
export async function showBtwCustomPreservingEditor<T>(
|
|
405
|
-
|
|
406
|
-
|
|
367
|
+
ctx: ExtensionCommandContext,
|
|
368
|
+
factory: BtwCustomFactory<T>,
|
|
407
369
|
): Promise<T | undefined> {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
370
|
+
let liveEditorText = ctx.ui.getEditorText();
|
|
371
|
+
let completed = false;
|
|
372
|
+
const result = await ctx.ui.custom<T>((tui, theme, keybindings, done) =>
|
|
373
|
+
factory(tui, theme, keybindings, (value) => {
|
|
374
|
+
try {
|
|
375
|
+
liveEditorText = ctx.ui.getEditorText();
|
|
376
|
+
} catch {
|
|
377
|
+
// Keep completion finite if session replacement invalidates the editor context.
|
|
378
|
+
}
|
|
379
|
+
completed = true;
|
|
380
|
+
done(value);
|
|
381
|
+
}),
|
|
382
|
+
);
|
|
383
|
+
if (completed) {
|
|
384
|
+
try {
|
|
385
|
+
if (ctx.ui.getEditorText() !== liveEditorText) ctx.ui.setEditorText(liveEditorText);
|
|
386
|
+
} catch {
|
|
387
|
+
// A replaced context owns a different editor and must not receive stale restoration.
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return result;
|
|
429
391
|
}
|
|
430
392
|
|
|
431
393
|
export async function runBtwMenuPreservingEditor(
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
394
|
+
ctx: ExtensionCommandContext,
|
|
395
|
+
run: (menuContext: MenuContext) => Promise<RunMenuResult>,
|
|
396
|
+
onKeybindings?: (keybindings: KeybindingsManager) => void,
|
|
435
397
|
): Promise<RunMenuResult> {
|
|
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
|
-
|
|
398
|
+
let liveEditorText = ctx.ui.getEditorText();
|
|
399
|
+
let completed = false;
|
|
400
|
+
const ui = new Proxy(ctx.ui, {
|
|
401
|
+
get(target, property) {
|
|
402
|
+
if (property === "custom") {
|
|
403
|
+
return <Value>(factory: BtwCustomFactory<Value>, customOptions?: BtwCustomOptions) =>
|
|
404
|
+
target.custom<Value>((tui, theme, keybindings, done) => {
|
|
405
|
+
onKeybindings?.(keybindings);
|
|
406
|
+
return factory(tui, theme, keybindings, (value) => {
|
|
407
|
+
try {
|
|
408
|
+
liveEditorText = target.getEditorText();
|
|
409
|
+
} catch {
|
|
410
|
+
// Keep completion finite if session replacement invalidates the editor context.
|
|
411
|
+
}
|
|
412
|
+
completed = true;
|
|
413
|
+
done(value);
|
|
414
|
+
});
|
|
415
|
+
}, customOptions);
|
|
416
|
+
}
|
|
417
|
+
const value = Reflect.get(target, property, target) as unknown;
|
|
418
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
const result = await run({ mode: ctx.mode, hasUI: ctx.hasUI, ui });
|
|
422
|
+
if (result.kind !== "stale" && completed) {
|
|
423
|
+
try {
|
|
424
|
+
if (ctx.ui.getEditorText() !== liveEditorText) ctx.ui.setEditorText(liveEditorText);
|
|
425
|
+
} catch {
|
|
426
|
+
// A replaced context owns a different editor and must not receive stale restoration.
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return result;
|
|
468
430
|
}
|
|
469
431
|
|
|
470
432
|
function clampToAvailableThinkingLevel(
|
|
471
|
-
|
|
472
|
-
|
|
433
|
+
requested: BtwThinkingLevel,
|
|
434
|
+
available: readonly BtwThinkingLevel[],
|
|
473
435
|
): BtwThinkingLevel {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
436
|
+
if (available.includes(requested)) return requested;
|
|
437
|
+
const requestedIndex = BTW_THINKING_LEVELS.indexOf(requested);
|
|
438
|
+
for (let index = requestedIndex; index < BTW_THINKING_LEVELS.length; index += 1) {
|
|
439
|
+
const candidate = BTW_THINKING_LEVELS[index];
|
|
440
|
+
if (candidate && available.includes(candidate)) return candidate;
|
|
441
|
+
}
|
|
442
|
+
for (let index = requestedIndex - 1; index >= 0; index -= 1) {
|
|
443
|
+
const candidate = BTW_THINKING_LEVELS[index];
|
|
444
|
+
if (candidate && available.includes(candidate)) return candidate;
|
|
445
|
+
}
|
|
446
|
+
return available[0] ?? "off";
|
|
485
447
|
}
|
|
486
448
|
|
|
487
449
|
function notifySaveFailure(ctx: ExtensionCommandContext, error: unknown): void {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
450
|
+
notifySafely(
|
|
451
|
+
ctx,
|
|
452
|
+
`Pi BTW settings were not saved; the previous value remains active: ${formatError(error)}`,
|
|
453
|
+
"error",
|
|
454
|
+
);
|
|
493
455
|
}
|
|
494
456
|
|
|
495
457
|
function notifySafely(
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
458
|
+
ctx: ExtensionCommandContext,
|
|
459
|
+
message: string,
|
|
460
|
+
level: Parameters<ExtensionCommandContext["ui"]["notify"]>[1],
|
|
499
461
|
): void {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
462
|
+
try {
|
|
463
|
+
ctx.ui.notify(sanitizeSingleLine(message), level);
|
|
464
|
+
} catch {
|
|
465
|
+
// A completed save remains valid if its command context was replaced before notification.
|
|
466
|
+
}
|
|
505
467
|
}
|
|
506
468
|
|
|
507
469
|
function formatError(error: unknown): string {
|
|
508
|
-
|
|
470
|
+
return error instanceof Error ? error.message : String(error);
|
|
509
471
|
}
|