@gloom-sh/terminal 0.20.3 → 0.20.5
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 +2 -0
- package/bin/gloom +9 -0
- package/bin/without-bun.cjs +98 -0
- package/package.json +3 -1
- package/src/account/auth-dialog.tsx +17 -0
- package/src/api-client/data.ts +144 -35
- package/src/api-client/fx-interventions.ts +64 -0
- package/src/api-client/index.ts +1 -0
- package/src/api-client/release-summaries.ts +21 -0
- package/src/api-client/types/econ.ts +12 -0
- package/src/api-client/yield-curves.ts +1 -1
- package/src/app/global-shortcuts.ts +4 -1
- package/src/app/keybindings/actions.ts +8 -2
- package/src/app/keybindings/config.ts +2 -1
- package/src/app/keybindings/index.ts +1 -0
- package/src/app/keybindings/labels.ts +6 -1
- package/src/app/keybindings/resolve.ts +23 -4
- package/src/app/keybindings/terminal-keys.ts +35 -0
- package/src/app/pane-runtime/index.tsx +2 -2
- package/src/app/pane-runtime/ticker-open-runtime.ts +274 -67
- package/src/architecture/ui-literals-allowlist.json +1 -1
- package/src/capabilities/chart-series.ts +27 -1
- package/src/cli/commands/keybindings.ts +5 -5
- package/src/cli/commands/market.ts +154 -21
- package/src/cli/commands/news-search.ts +60 -10
- package/src/cli/commands/overview.ts +16 -1
- package/src/cli/commands/plugins.ts +27 -5
- package/src/cli/commands/remote.ts +16 -17
- package/src/cli/commands/system.ts +20 -4
- package/src/cli/commands/ticker.ts +60 -19
- package/src/cli/fx-forward.ts +25 -7
- package/src/cli/glossary.ts +19 -5
- package/src/cli/history-rows.ts +5 -3
- package/src/cli/index.ts +8 -8
- package/src/cli/known-gaps.ts +27 -1
- package/src/cli/listing-arg.ts +11 -1
- package/src/cli/name-entries.ts +5 -1
- package/src/cli/not-a-ticker.ts +4 -0
- package/src/cli/pane-functions/function-help.ts +5 -5
- package/src/cli/report-tables.ts +18 -6
- package/src/cli/result.ts +15 -7
- package/src/cli/types.ts +2 -0
- package/src/components/chart/composite/axis-overlays.tsx +22 -0
- package/src/components/chart/composite/composite-chart.tsx +54 -13
- package/src/components/chart/composite/event-captions.ts +109 -0
- package/src/components/chart/composite/event-guides.ts +74 -0
- package/src/components/chart/composite/rasterizer.ts +2 -0
- package/src/components/chart/composite/text-renderer.ts +2 -0
- package/src/components/chart/composite/types.ts +31 -0
- package/src/components/command-bar/layout-items/focused-pane.ts +5 -5
- package/src/components/command-bar/pane-settings.ts +2 -2
- package/src/components/command-bar/routes/root/provider-search.ts +5 -4
- package/src/components/command-bar/routes/root/results.ts +6 -2
- package/src/components/command-bar/routes/ticker-search/results.ts +51 -0
- package/src/components/command-bar/routes/ticker-search/route.ts +3 -2
- package/src/components/input-search-bar.tsx +9 -2
- package/src/components/layout/detached-pane-shell.tsx +1 -1
- package/src/components/layout/floating-pane.tsx +5 -1
- package/src/components/layout/pane/footer/index.tsx +21 -14
- package/src/components/layout/pane/footer/model.ts +6 -0
- package/src/components/layout/pane/header.tsx +2 -0
- package/src/components/layout/shell/action-menu-overlay.tsx +10 -5
- package/src/components/layout/shell/active-drag.ts +149 -105
- package/src/components/layout/shell/drag/drop-zones.ts +162 -0
- package/src/components/layout/shell/drag/index.ts +47 -218
- package/src/components/layout/shell/drag/live.ts +10 -3
- package/src/components/layout/shell/drag/overlays.tsx +182 -5
- package/src/components/layout/shell/drag/runtime.ts +29 -6
- package/src/components/layout/shell/drag/shared-edges.ts +156 -0
- package/src/components/layout/shell/index.tsx +11 -6
- package/src/components/layout/shell/menu.ts +11 -2
- package/src/components/layout/shell/native/pointer-runtime.ts +25 -0
- package/src/components/layout/shell/native/window-state.ts +2 -2
- package/src/components/layout/shell/pane/capture.ts +4 -1
- package/src/components/layout/shell/pane/layers.tsx +71 -7
- package/src/components/layout/shell/terminal-pointer-runtime.ts +18 -9
- package/src/components/layout/shell/window-mode/index.ts +8 -10
- package/src/components/layout/status-bar.tsx +6 -1
- package/src/components/layout/window-edit/mode.ts +39 -7
- package/src/components/layout/window-edit/presentation.ts +1 -1
- package/src/components/onboarding/first-run-workspace.ts +44 -2
- package/src/components/onboarding/onboarding-frame.tsx +11 -2
- package/src/components/onboarding/onboarding-keyboard.ts +20 -0
- package/src/components/onboarding/onboarding-wizard.tsx +16 -11
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +62 -1
- package/src/components/onboarding/use-onboarding-progress.ts +12 -4
- package/src/components/pane-settings-dialog/desktop.tsx +2 -2
- package/src/components/pane-settings-dialog/tui.tsx +2 -2
- package/src/components/pane-settings-dialog/value.ts +6 -0
- package/src/components/pane-settings-dialog.tsx +3 -3
- package/src/components/reader/detail-reader.tsx +4 -0
- package/src/components/ui/button.tsx +2 -0
- package/src/components/ui/choice-dialog.tsx +1 -0
- package/src/components/ui/data-table/index.tsx +4 -3
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/list-view.tsx +7 -12
- package/src/components/ui/loading.tsx +10 -3
- package/src/components/ui/menu.tsx +6 -2
- package/src/components/ui/page-stack-view.tsx +3 -0
- package/src/components/ui/pane-link-chip.tsx +269 -54
- package/src/components/ui/query-bar.tsx +2 -1
- package/src/components/ui/quote.ts +14 -1
- package/src/components/ui/tabs.tsx +97 -19
- package/src/core/state/app/layout-reducer.ts +7 -0
- package/src/core/state/app/layout.ts +44 -7
- package/src/core/state/app/state.ts +1 -1
- package/src/core/state/app/types.ts +22 -2
- package/src/data/config/layout.ts +5 -2
- package/src/docs/snapshot.json +54 -13
- package/src/i18n/es.ts +9 -8
- package/src/i18n/ja.ts +9 -8
- package/src/i18n/ko.ts +9 -8
- package/src/i18n/zh-cn.ts +9 -8
- package/src/i18n/zh-tw.ts +9 -8
- package/src/layout/pane-manager/floating-actions.ts +17 -0
- package/src/layout/pane-manager/floating-stack.ts +187 -0
- package/src/layout/pane-manager/floating.ts +4 -2
- package/src/layout/pane-manager/gridlock.ts +5 -1
- package/src/layout/pane-manager/index.ts +11 -0
- package/src/layout/pane-manager/layout-state.ts +10 -3
- package/src/market-data/depositary-pair.ts +5 -3
- package/src/market-data/futures-board.ts +46 -1
- package/src/market-data/futures-contract.ts +12 -3
- package/src/market-data/fx-interventions.ts +270 -0
- package/src/market-data/market/dated-previous-close.ts +94 -15
- package/src/market-data/market/status.ts +17 -1
- package/src/news/news-model.ts +44 -2
- package/src/plugins/builtin/alerts/cli.ts +4 -4
- package/src/plugins/builtin/alerts/format.ts +1 -2
- package/src/plugins/builtin/alerts/headless.ts +1 -2
- package/src/plugins/builtin/alerts/move-checks.ts +12 -6
- package/src/plugins/builtin/alerts/move.ts +30 -9
- package/src/plugins/builtin/alerts/pane.tsx +0 -2
- package/src/plugins/builtin/alerts/storage.ts +4 -2
- package/src/plugins/builtin/alerts/types.ts +12 -0
- package/src/plugins/builtin/analytics/risk-client.ts +10 -4
- package/src/plugins/builtin/analytics/risk-episodes.ts +5 -4
- package/src/plugins/builtin/analytics/risk-headless.ts +4 -2
- package/src/plugins/builtin/analytics/risk-sectors.ts +91 -0
- package/src/plugins/builtin/awards/index.tsx +1 -1
- package/src/plugins/builtin/buildout/index.tsx +1 -0
- package/src/plugins/builtin/catalysts/index.tsx +2 -2
- package/src/plugins/builtin/cds/headless.ts +4 -0
- package/src/plugins/builtin/changelog/index.tsx +292 -101
- package/src/plugins/builtin/changelog/versions.ts +293 -0
- package/src/plugins/builtin/chart-composer/headless.ts +2 -1
- package/src/plugins/builtin/chart-composer/index.tsx +1 -0
- package/src/plugins/builtin/chart-composer/intervention-events.ts +105 -0
- package/src/plugins/builtin/chart-composer/pane.tsx +21 -7
- package/src/plugins/builtin/chat/content/composer.tsx +5 -4
- package/src/plugins/builtin/chat/content/index.tsx +12 -2
- package/src/plugins/builtin/chat/content/layout-metrics.ts +3 -3
- package/src/plugins/builtin/chat/content/open-targets.ts +3 -3
- package/src/plugins/builtin/chat/layout.ts +5 -2
- package/src/plugins/builtin/chat/message/pane-chip.tsx +61 -40
- package/src/plugins/builtin/chat/message/render-state.ts +2 -5
- package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
- package/src/plugins/builtin/chat/pane-links/previews.ts +51 -5
- package/src/plugins/builtin/chat/pane-links/share-card.ts +36 -0
- package/src/plugins/builtin/cloud/askg/attached-pane.tsx +10 -5
- package/src/plugins/builtin/cloud/askg/controller.ts +141 -5
- package/src/plugins/builtin/cloud/askg/executor.ts +113 -4
- package/src/plugins/builtin/cloud/askg/manifest.ts +28 -13
- package/src/plugins/builtin/cloud/askg/model.ts +14 -4
- package/src/plugins/builtin/cloud/askg/pane.tsx +70 -46
- package/src/plugins/builtin/cloud/askg/tool-display.ts +1 -0
- package/src/plugins/builtin/cloud/askg/turn-parts.tsx +70 -0
- package/src/plugins/builtin/cloud/terminal-relay/engine.ts +50 -130
- package/src/plugins/builtin/cloud/terminal-relay/policy.ts +327 -7
- package/src/plugins/builtin/cloud/terminal-relay/prompts.tsx +2 -1
- package/src/plugins/builtin/cloud/terminal-relay/redact.ts +52 -9
- package/src/plugins/builtin/commodities-energy/index.tsx +1 -3
- package/src/plugins/builtin/commodities-energy/view-state.ts +3 -0
- package/src/plugins/builtin/commodity-balances/index.tsx +1 -0
- package/src/plugins/builtin/company-attention/index.tsx +1 -1
- package/src/plugins/builtin/company-kpis/headless.ts +3 -1
- package/src/plugins/builtin/company-kpis/index.tsx +2 -2
- package/src/plugins/builtin/cot/headless.ts +14 -2
- package/src/plugins/builtin/cot/index.tsx +1 -1
- package/src/plugins/builtin/cpi/index.tsx +1 -1
- package/src/plugins/builtin/crypto-board/index.tsx +1 -0
- package/src/plugins/builtin/dividend-yield/index.tsx +1 -0
- package/src/plugins/builtin/doe/index.tsx +1 -1
- package/src/plugins/builtin/earnings/index.tsx +2 -2
- package/src/plugins/builtin/earnings-calls/headless.ts +5 -1
- package/src/plugins/builtin/earnings-calls/index.tsx +1 -0
- package/src/plugins/builtin/econ/calendar-model.ts +74 -1
- package/src/plugins/builtin/econ/fred-catalog.ts +3 -1
- package/src/plugins/builtin/econ/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/pane.tsx +6 -0
- package/src/plugins/builtin/estimate-revisions/index.tsx +1 -0
- package/src/plugins/builtin/executives/index.tsx +1 -0
- package/src/plugins/builtin/filing-events/index.tsx +1 -0
- package/src/plugins/builtin/fixed-income/index.tsx +1 -0
- package/src/plugins/builtin/futures/index.tsx +25 -4
- package/src/plugins/builtin/futures/model.ts +28 -32
- package/src/plugins/builtin/futures/series.ts +4 -3
- package/src/plugins/builtin/futures/table.tsx +16 -9
- package/src/plugins/builtin/futures/use-board-terms.ts +3 -3
- package/src/plugins/builtin/futures-curve/headless.ts +3 -3
- package/src/plugins/builtin/futures-curve/index.tsx +1 -1
- package/src/plugins/builtin/futures-curve/model.ts +18 -0
- package/src/plugins/builtin/gpu/index.tsx +1 -1
- package/src/plugins/builtin/help/functions-table.tsx +1 -1
- package/src/plugins/builtin/help/index.tsx +14 -4
- package/src/plugins/builtin/help/keybindings-editor.tsx +19 -5
- package/src/plugins/builtin/holders/index.tsx +1 -0
- package/src/plugins/builtin/holders/report-header.ts +2 -2
- package/src/plugins/builtin/insider/index.tsx +1 -0
- package/src/plugins/builtin/iv-history/index.tsx +1 -1
- package/src/plugins/builtin/jobs/index.tsx +1 -0
- package/src/plugins/builtin/layout-manager/index.tsx +8 -8
- package/src/plugins/builtin/macro-day/headless.ts +27 -8
- package/src/plugins/builtin/macro-day/index.tsx +1 -1
- package/src/plugins/builtin/macro-day/model.ts +19 -3
- package/src/plugins/builtin/macro-day/pane.tsx +14 -9
- package/src/plugins/builtin/macro-day/releases.ts +25 -7
- package/src/plugins/builtin/market-valuation/index.tsx +1 -0
- package/src/plugins/builtin/market-valuation/pane.tsx +8 -0
- package/src/plugins/builtin/members/index.tsx +1 -1
- package/src/plugins/builtin/mna/index.tsx +1 -0
- package/src/plugins/builtin/news/headless.ts +2 -2
- package/src/plugins/builtin/news/index.tsx +4 -3
- package/src/plugins/builtin/news/wire/index.tsx +5 -1
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +4 -0
- package/src/plugins/builtin/news/wire/news/list-search.ts +5 -2
- package/src/plugins/builtin/options/index.tsx +1 -0
- package/src/plugins/builtin/options-positioning/index.tsx +1 -0
- package/src/plugins/builtin/pe-band/index.tsx +1 -1
- package/src/plugins/builtin/perps/markets-section.tsx +5 -2
- package/src/plugins/builtin/plugin-marketplace/pane.tsx +11 -11
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +25 -0
- package/src/plugins/builtin/portfolio-list/headless.ts +15 -6
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +3 -1
- package/src/plugins/builtin/power/index.tsx +1 -1
- package/src/plugins/builtin/realized-vol/index.tsx +1 -1
- package/src/plugins/builtin/research/event-model.ts +9 -1
- package/src/plugins/builtin/research/event-sources.ts +22 -0
- package/src/plugins/builtin/research/headless.ts +11 -5
- package/src/plugins/builtin/research/index.tsx +4 -0
- package/src/plugins/builtin/research-search/index.tsx +1 -0
- package/src/plugins/builtin/research-search/pane.tsx +8 -0
- package/src/plugins/builtin/revenue-breakdown/index.tsx +1 -0
- package/src/plugins/builtin/reverse-dcf/index.tsx +1 -1
- package/src/plugins/builtin/risk-factors/index.tsx +1 -0
- package/src/plugins/builtin/scanner/headless.ts +52 -13
- package/src/plugins/builtin/seasonality/index.tsx +1 -1
- package/src/plugins/builtin/sec/index.tsx +1 -0
- package/src/plugins/builtin/series-inventory.ts +1 -1
- package/src/plugins/builtin/shared/cloud-upgrade.ts +27 -3
- package/src/plugins/builtin/shared/scanner-capture.ts +11 -3
- package/src/plugins/builtin/shared/series-list-detail.tsx +5 -0
- package/src/plugins/builtin/short-interest/index.tsx +1 -0
- package/src/plugins/builtin/social-mentions/index.tsx +1 -1
- package/src/plugins/builtin/supply-chain/index.tsx +1 -0
- package/src/plugins/builtin/thirteenf/data.ts +43 -10
- package/src/plugins/builtin/thirteenf/headless.ts +55 -11
- package/src/plugins/builtin/thirteenf/model.ts +25 -9
- package/src/plugins/builtin/thirteenf/report-notes.ts +27 -6
- package/src/plugins/builtin/thirteenf/types.ts +2 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +1 -1
- package/src/plugins/builtin/ticker-detail/financials/model.ts +12 -0
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +3 -3
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +5 -5
- package/src/plugins/builtin/ticker-detail/headless.ts +18 -13
- package/src/plugins/builtin/ticker-detail/index.tsx +4 -0
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +54 -5
- package/src/plugins/builtin/ticker-detail/overview/model.ts +6 -4
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +34 -17
- package/src/plugins/builtin/ticker-detail/pane.tsx +7 -2
- package/src/plugins/builtin/time-sales/client.ts +9 -11
- package/src/plugins/builtin/time-sales/index.tsx +1 -1
- package/src/plugins/builtin/treasury-auctions/after.ts +267 -0
- package/src/plugins/builtin/treasury-auctions/cache.ts +18 -3
- package/src/plugins/builtin/treasury-auctions/client.ts +33 -2
- package/src/plugins/builtin/treasury-auctions/headless.ts +109 -19
- package/src/plugins/builtin/treasury-auctions/index.tsx +14 -4
- package/src/plugins/builtin/treasury-auctions/model.ts +256 -28
- package/src/plugins/builtin/treasury-auctions/pane.tsx +139 -28
- package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +5 -2
- package/src/plugins/builtin/treasury-auctions/types.ts +7 -1
- package/src/plugins/builtin/vol-surface/index.tsx +1 -1
- package/src/plugins/builtin/world-venue-map/index.ts +1 -0
- package/src/plugins/builtin/yield-curve/curves.ts +10 -4
- package/src/plugins/builtin/yield-curve/headless.ts +6 -2
- package/src/plugins/builtin/yield-curve/index.tsx +3 -3
- package/src/plugins/builtin/yield-curve/series.ts +10 -0
- package/src/plugins/builtin/yield-curve/world.ts +3 -1
- package/src/plugins/installer.ts +45 -0
- package/src/portfolio/column-values.ts +2 -1
- package/src/public/__snapshots__/public-api.test.ts.snap +4 -0
- package/src/public/remote.ts +7 -1
- package/src/remote/client.ts +191 -11
- package/src/remote/controller-utils.ts +13 -1
- package/src/remote/controller.ts +88 -26
- package/src/remote/endpoint.ts +24 -0
- package/src/remote/form.ts +59 -4
- package/src/remote/resources.ts +56 -19
- package/src/remote/schema.ts +22 -9
- package/src/remote/secrets.ts +12 -0
- package/src/remote/semantic-helpers.ts +29 -1
- package/src/remote/semantic-tree.tsx +44 -15
- package/src/remote/server.ts +2 -1
- package/src/remote/surface.tsx +192 -0
- package/src/remote/types.ts +5 -0
- package/src/renderers/cloudflare/worker.ts +16 -1
- package/src/renderers/dom/styles.css +40 -6
- package/src/renderers/opentui/host.tsx +6 -0
- package/src/renderers/share/layout-view.tsx +1 -1
- package/src/series/standalone.ts +2 -2
- package/src/shares/api.ts +21 -4
- package/src/shares/item.ts +73 -0
- package/src/shares/pane-item.ts +205 -0
- package/src/shares/pane.ts +4 -0
- package/src/shares/payload.ts +9 -5
- package/src/sources/gloomberb-cloud/news.ts +37 -12
- package/src/state/opening-ticker-panes.ts +47 -0
- package/src/test-support/cli-context.ts +2 -0
- package/src/test-support/preload.ts +4 -1
- package/src/tickers/instrument-kind.ts +23 -3
- package/src/tickers/renamed-listings.ts +105 -0
- package/src/tickers/search/index.ts +103 -16
- package/src/time-series/resolve.ts +2 -2
- package/src/types/config.ts +5 -0
- package/src/types/context-menu.ts +2 -0
- package/src/types/financials.ts +1 -0
- package/src/types/plugin-commands.ts +140 -0
- package/src/types/plugin-context.ts +125 -0
- package/src/types/plugin-contributions.ts +55 -0
- package/src/types/plugin-definition.ts +234 -0
- package/src/types/plugin-notifications.ts +38 -0
- package/src/types/plugin-pane-settings.ts +116 -0
- package/src/types/plugin-pane-templates.ts +160 -0
- package/src/types/plugin-panes.ts +243 -0
- package/src/types/plugin-reports.ts +35 -0
- package/src/types/plugin-shared.ts +14 -0
- package/src/types/plugin-state.ts +71 -0
- package/src/types/plugin.ts +14 -1169
- package/src/ui/index.tsx +14 -3
- package/src/updater/github-releases.ts +23 -0
- package/src/utils/central-banks.ts +86 -1
- package/src/utils/cli-output.ts +22 -9
- package/src/utils/datetime-format.ts +12 -3
- package/src/utils/depositary-receipt.ts +28 -3
- package/src/utils/fundamentals.ts +14 -0
- package/src/utils/max-drawdown.ts +97 -16
- package/src/utils/untrusted-text.ts +29 -0
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { commandBarResultsFromNodes } from "../../../../remote/command-bar";
|
|
2
|
-
import { findCommandBarResult, findMatchingUiNode } from "../../../../remote/matching";
|
|
3
1
|
import type {
|
|
4
2
|
RemoteCallContext,
|
|
5
3
|
RemoteControlRequest,
|
|
@@ -16,14 +14,15 @@ import {
|
|
|
16
14
|
type TerminalRelayToolKind,
|
|
17
15
|
} from "./manifest";
|
|
18
16
|
import {
|
|
19
|
-
|
|
20
|
-
NAVIGATION_RESULT_KINDS,
|
|
17
|
+
describeConfirmedOperation,
|
|
21
18
|
operationPolicy,
|
|
22
19
|
patchPolicy,
|
|
20
|
+
planUiCall,
|
|
21
|
+
UiCallRefusal,
|
|
22
|
+
type UiCallPlan,
|
|
23
23
|
} from "./policy";
|
|
24
24
|
import { REDACTED, redactConfig, redactRelayResult, redactResource } from "./redact";
|
|
25
25
|
import { keyArgumentLines, shortValue, type CallSummary } from "./summary";
|
|
26
|
-
import { logFailure } from "../../../../utils/log-failure";
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
28
|
* Runs the tool calls Gloom Cloud relays from a remote assistant, in this
|
|
@@ -41,7 +40,6 @@ import { logFailure } from "../../../../utils/log-failure";
|
|
|
41
40
|
* 60 s for an answer, then up to 15 s for the operation.
|
|
42
41
|
*/
|
|
43
42
|
|
|
44
|
-
export const RELAY_PROMPT_SCOPE = "terminal-relay-prompt";
|
|
45
43
|
export const CONFIRM_WINDOW_MS = 60_000;
|
|
46
44
|
const EXECUTION_BUDGET_MS = 15_000;
|
|
47
45
|
/** Answers the server cannot take (a call frame tens of megabytes long) are cut to fit. */
|
|
@@ -112,10 +110,8 @@ interface PlannedCall {
|
|
|
112
110
|
* run. Passed back once the person allows it, so the app does not ask twice.
|
|
113
111
|
*/
|
|
114
112
|
confirmKey?: string;
|
|
115
|
-
/**
|
|
116
|
-
|
|
117
|
-
/** Refuses a semantic action aimed at the relay's own prompt. */
|
|
118
|
-
targetsPrompt?: () => Promise<boolean>;
|
|
113
|
+
/** A call that acts on what is on screen, checked again right before it runs (policy.ts). */
|
|
114
|
+
recheck?: UiCallPlan["recheck"];
|
|
119
115
|
}
|
|
120
116
|
|
|
121
117
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
@@ -312,6 +308,11 @@ export class TerminalRelayEngine {
|
|
|
312
308
|
controller: new AbortController(),
|
|
313
309
|
};
|
|
314
310
|
this.live.set(call.id, call);
|
|
311
|
+
// Ends when this call has run or failed: the next prompt opens only then (prompt()).
|
|
312
|
+
let finish!: () => void;
|
|
313
|
+
const finished = new Promise<void>((resolve) => {
|
|
314
|
+
finish = resolve;
|
|
315
|
+
});
|
|
315
316
|
try {
|
|
316
317
|
if (!caller || !caller.id) throw new RelayRefusal("not_allowed", "The call does not say which assistant sent it.");
|
|
317
318
|
if (typeof data.tool !== "string") throw new RelayRefusal("not_allowed", "The call names no tool.");
|
|
@@ -321,19 +322,15 @@ export class TerminalRelayEngine {
|
|
|
321
322
|
|
|
322
323
|
await this.ensureApproved(call);
|
|
323
324
|
const plan = await this.plan(binding, input);
|
|
324
|
-
if (plan.confirm) await this.confirm(call, plan.confirm);
|
|
325
|
+
if (plan.confirm) await this.confirm(call, plan.confirm, finished);
|
|
325
326
|
|
|
326
327
|
// Last check before anything runs.
|
|
327
328
|
if (!this.isLive(call)) return;
|
|
328
329
|
if (this.options.grants.decision(caller.id) === "deny" || this.options.grants.decision(caller.id) === null) {
|
|
329
330
|
throw new RelayRefusal("revoked", "This assistant's access to the terminal was revoked.");
|
|
330
331
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
if (plan.stillSame && !(await plan.stillSame())) {
|
|
335
|
-
throw new RelayRefusal("not_allowed", "What the call pointed at changed while the person decided, so it did not run. Read the state again and retry.");
|
|
336
|
-
}
|
|
332
|
+
const stale = await plan.recheck?.(this.promptOpen);
|
|
333
|
+
if (stale) throw new RelayRefusal("not_allowed", stale);
|
|
337
334
|
if (!this.isLive(call)) return;
|
|
338
335
|
|
|
339
336
|
const result = await this.execute(binding, plan, input, call);
|
|
@@ -348,6 +345,7 @@ export class TerminalRelayEngine {
|
|
|
348
345
|
: new RelayRefusal("app_error", error instanceof Error ? error.message : String(error));
|
|
349
346
|
this.reply(call, { ok: false, error: { code: refusal.code, message: refusal.message } });
|
|
350
347
|
} finally {
|
|
348
|
+
finish();
|
|
351
349
|
if (this.live.get(call.id) === call) this.live.delete(call.id);
|
|
352
350
|
}
|
|
353
351
|
}
|
|
@@ -361,8 +359,16 @@ export class TerminalRelayEngine {
|
|
|
361
359
|
/**
|
|
362
360
|
* One prompt at a time; each keeps its own 60 s window from when it opens.
|
|
363
361
|
* Aborting the call (a cancel, a revoke, a lost connection) closes it at once.
|
|
362
|
+
* A confirmed call keeps the next prompt closed until `heldUntil` (it has
|
|
363
|
+
* run), so it runs with no other prompt open and the person never answers
|
|
364
|
+
* one while a call they allowed still acts.
|
|
364
365
|
*/
|
|
365
|
-
private prompt<T>(
|
|
366
|
+
private prompt<T>(
|
|
367
|
+
call: LiveCall,
|
|
368
|
+
kind: "approval" | "confirmation",
|
|
369
|
+
ask: (signal: AbortSignal) => Promise<T>,
|
|
370
|
+
heldUntil?: Promise<void>,
|
|
371
|
+
): Promise<T | "timeout"> {
|
|
366
372
|
this.announceWaiting(call, kind, this.now() + this.confirmWindowMs);
|
|
367
373
|
const run = async (): Promise<T | "timeout"> => {
|
|
368
374
|
if (!this.isLive(call)) throw new RelayRefusal("app_error", "cancelled");
|
|
@@ -388,9 +394,10 @@ export class TerminalRelayEngine {
|
|
|
388
394
|
}
|
|
389
395
|
};
|
|
390
396
|
const result = this.promptChain.then(run, run);
|
|
391
|
-
|
|
397
|
+
const answered = result.catch(() => {
|
|
392
398
|
// Intentional ignore: the returned result reports this failure; the chain only stays usable.
|
|
393
399
|
});
|
|
400
|
+
this.promptChain = heldUntil ? Promise.all([answered, heldUntil]).then(() => {}) : answered;
|
|
394
401
|
return result;
|
|
395
402
|
}
|
|
396
403
|
|
|
@@ -412,8 +419,8 @@ export class TerminalRelayEngine {
|
|
|
412
419
|
}
|
|
413
420
|
}
|
|
414
421
|
|
|
415
|
-
private async confirm(call: LiveCall, summary: CallSummary): Promise<void> {
|
|
416
|
-
const answer = await this.prompt(call, "confirmation", (signal) => this.options.prompts.askConfirmation(call.caller, summary, signal));
|
|
422
|
+
private async confirm(call: LiveCall, summary: CallSummary, ran: Promise<void>): Promise<void> {
|
|
423
|
+
const answer = await this.prompt(call, "confirmation", (signal) => this.options.prompts.askConfirmation(call.caller, summary, signal), ran);
|
|
417
424
|
if (!this.isLive(call)) throw new RelayRefusal("app_error", "cancelled");
|
|
418
425
|
if (answer === "timeout") {
|
|
419
426
|
throw new RelayRefusal("confirmation_timeout", `The person did not confirm "${summary.title}" within ${Math.round(this.confirmWindowMs / 1_000)} s, so it did not run.`);
|
|
@@ -427,11 +434,6 @@ export class TerminalRelayEngine {
|
|
|
427
434
|
return response.data;
|
|
428
435
|
}
|
|
429
436
|
|
|
430
|
-
private async uiNodes(): Promise<RemoteUiNodeSnapshot[]> {
|
|
431
|
-
const nodes = await this.read("ui://tree");
|
|
432
|
-
return Array.isArray(nodes) ? nodes as RemoteUiNodeSnapshot[] : [];
|
|
433
|
-
}
|
|
434
|
-
|
|
435
437
|
/** The request to run and, for the `confirm` cases, what the person is asked. */
|
|
436
438
|
private async plan(binding: TerminalRelayToolKind, input: Record<string, unknown>): Promise<PlannedCall> {
|
|
437
439
|
switch (binding.kind) {
|
|
@@ -485,67 +487,30 @@ export class TerminalRelayEngine {
|
|
|
485
487
|
const { policy } = operationPolicy(operation);
|
|
486
488
|
if (policy === "allow") return { request, binding, confirm: null };
|
|
487
489
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
: findMatchingUiNode(nodes, input);
|
|
495
|
-
};
|
|
496
|
-
const target = await find();
|
|
497
|
-
const targetsPrompt = async () => (await find())?.metadata?.scope === RELAY_PROMPT_SCOPE;
|
|
498
|
-
if (target?.metadata?.scope === RELAY_PROMPT_SCOPE || this.promptOpen) {
|
|
499
|
-
throw new RelayRefusal("not_allowed", "A Gloom confirmation is open; the assistant cannot act on it.");
|
|
500
|
-
}
|
|
501
|
-
if (LOCAL_UI_ACTIONS.has(action)) return { request, binding, confirm: null, targetsPrompt };
|
|
502
|
-
const fingerprint = target ? `${target.id}|${target.role}|${target.label ?? ""}` : "";
|
|
503
|
-
return {
|
|
504
|
-
request,
|
|
505
|
-
binding,
|
|
506
|
-
targetsPrompt,
|
|
507
|
-
stillSame: async () => {
|
|
508
|
-
const now = await find();
|
|
509
|
-
return (now ? `${now.id}|${now.role}|${now.label ?? ""}` : "") === fingerprint;
|
|
510
|
-
},
|
|
511
|
-
confirm: {
|
|
512
|
-
title: `${action === "press" ? "Press" : `Run "${action}" on`} ${target?.label ? `"${shortValue(target.label)}"` : "a control"}`,
|
|
513
|
-
lines: [
|
|
514
|
-
{ label: "Control", value: target ? `${target.label ? shortValue(target.label) : "unlabelled"} (${target.role})` : "none visible yet" },
|
|
515
|
-
{ label: "Action", value: action },
|
|
516
|
-
...(input.input !== undefined ? [{ label: "Input", value: shortValue(input.input) }] : []),
|
|
517
|
-
],
|
|
518
|
-
},
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
if (policy === "navigation") {
|
|
523
|
-
const find = async () => findCommandBarResult(commandBarResultsFromNodes(await this.uiNodes()), input);
|
|
524
|
-
const result = await find();
|
|
525
|
-
if (!result) throw new RelayRefusal("invalid_input", "No matching command-bar result is visible.");
|
|
526
|
-
const kind = typeof result.kind === "string" ? result.kind : "";
|
|
527
|
-
if (NAVIGATION_RESULT_KINDS.has(kind)) return { request, binding, confirm: null };
|
|
528
|
-
const fingerprint = `${shortValue(result.label)}|${kind}|${shortValue(result.itemId)}`;
|
|
529
|
-
return {
|
|
530
|
-
request,
|
|
531
|
-
binding,
|
|
532
|
-
stillSame: async () => {
|
|
533
|
-
const now = await find();
|
|
534
|
-
return !!now && `${shortValue(now.label)}|${typeof now.kind === "string" ? now.kind : ""}|${shortValue(now.itemId)}` === fingerprint;
|
|
535
|
-
},
|
|
536
|
-
confirm: {
|
|
537
|
-
title: `Run "${shortValue(result.label)}" from the command bar`,
|
|
538
|
-
lines: [
|
|
539
|
-
{ label: "Command", value: shortValue(result.label) },
|
|
540
|
-
...(result.detail ? [{ label: "Detail", value: shortValue(result.detail) }] : []),
|
|
541
|
-
],
|
|
542
|
-
},
|
|
543
|
-
};
|
|
490
|
+
let ui: UiCallPlan | null;
|
|
491
|
+
try {
|
|
492
|
+
ui = await planUiCall(operation, input, { read: (resource) => this.read(resource), promptOpen: this.promptOpen });
|
|
493
|
+
} catch (error) {
|
|
494
|
+
if (error instanceof UiCallRefusal) throw new RelayRefusal(error.code, error.message);
|
|
495
|
+
throw error;
|
|
544
496
|
}
|
|
497
|
+
if (ui) return { request, binding, confirm: ui.confirm, recheck: ui.recheck };
|
|
545
498
|
|
|
546
499
|
const planned = await this.plannedChange(operation, input);
|
|
547
500
|
if (planned) return { request, binding, ...planned };
|
|
548
|
-
|
|
501
|
+
const described = await describeConfirmedOperation(operation, input, (resource) => this.read(resource));
|
|
502
|
+
if (described) {
|
|
503
|
+
const recheck = described.recheck;
|
|
504
|
+
return { request, binding, confirm: described.confirm, ...(recheck ? { recheck: () => recheck() } : {}) };
|
|
505
|
+
}
|
|
506
|
+
return {
|
|
507
|
+
request,
|
|
508
|
+
binding,
|
|
509
|
+
confirm: {
|
|
510
|
+
title: terminalRelayToolTitle(operation),
|
|
511
|
+
lines: [{ label: "Operation", value: operation }, ...keyArgumentLines(input)],
|
|
512
|
+
},
|
|
513
|
+
};
|
|
549
514
|
}
|
|
550
515
|
|
|
551
516
|
/**
|
|
@@ -575,52 +540,6 @@ export class TerminalRelayEngine {
|
|
|
575
540
|
};
|
|
576
541
|
}
|
|
577
542
|
|
|
578
|
-
private async operationSummary(operation: string, input: Record<string, unknown>): Promise<CallSummary> {
|
|
579
|
-
if (operation === "capability.invoke") {
|
|
580
|
-
const capabilityId = typeof input.capabilityId === "string" ? input.capabilityId : "";
|
|
581
|
-
const operationId = typeof input.operationId === "string" ? input.operationId : "";
|
|
582
|
-
let plugin = capabilityId;
|
|
583
|
-
let operationTitle = operationId;
|
|
584
|
-
try {
|
|
585
|
-
const manifests = await this.read("app://capabilities");
|
|
586
|
-
const manifest = Array.isArray(manifests)
|
|
587
|
-
? manifests.find((entry) => isRecord(entry) && entry.id === capabilityId) as Record<string, unknown> | undefined
|
|
588
|
-
: undefined;
|
|
589
|
-
if (manifest && typeof manifest.name === "string") plugin = manifest.name;
|
|
590
|
-
const operations = manifest && Array.isArray(manifest.operations) ? manifest.operations : [];
|
|
591
|
-
const described = operations.find((entry) => isRecord(entry) && entry.id === operationId) as Record<string, unknown> | undefined;
|
|
592
|
-
if (described && typeof described.title === "string") operationTitle = described.title;
|
|
593
|
-
} catch (error) {
|
|
594
|
-
// The ids alone still say what runs.
|
|
595
|
-
logFailure("cloud.terminal-relay", "Read plugin names for a confirmation failed")(error);
|
|
596
|
-
}
|
|
597
|
-
return {
|
|
598
|
-
title: `${shortValue(operationTitle)} with ${shortValue(plugin)}`,
|
|
599
|
-
lines: [
|
|
600
|
-
{ label: "Plugin", value: `${shortValue(plugin)}${plugin !== capabilityId ? ` (${shortValue(capabilityId)})` : ""}` },
|
|
601
|
-
{ label: "Operation", value: shortValue(operationId) },
|
|
602
|
-
...keyArgumentLines(input.payload),
|
|
603
|
-
],
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
if (operation === "layout.delete") {
|
|
607
|
-
let name = `#${String(input.index)}`;
|
|
608
|
-
try {
|
|
609
|
-
const layouts = await this.read("app://layouts");
|
|
610
|
-
const layout = Array.isArray(layouts) && typeof input.index === "number" ? layouts[input.index] : undefined;
|
|
611
|
-
if (isRecord(layout) && typeof layout.name === "string") name = `"${shortValue(layout.name)}"`;
|
|
612
|
-
} catch (error) {
|
|
613
|
-
// The index still identifies it.
|
|
614
|
-
logFailure("cloud.terminal-relay", "Read layout names for a confirmation failed")(error);
|
|
615
|
-
}
|
|
616
|
-
return { title: `Delete the layout ${name}`, lines: [{ label: "Undo", value: "Not available for a deleted layout" }] };
|
|
617
|
-
}
|
|
618
|
-
return {
|
|
619
|
-
title: terminalRelayToolTitle(operation),
|
|
620
|
-
lines: [{ label: "Operation", value: operation }, ...keyArgumentLines(input)],
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
|
|
624
543
|
private async withBudget<T>(work: Promise<T>): Promise<T> {
|
|
625
544
|
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
626
545
|
try {
|
|
@@ -725,7 +644,8 @@ export class TerminalRelayEngine {
|
|
|
725
644
|
} catch {
|
|
726
645
|
// Intentional ignore: a pane without settings rejects this read, and its content has none.
|
|
727
646
|
}
|
|
728
|
-
const
|
|
647
|
+
const tree = await this.read("ui://tree");
|
|
648
|
+
const nodes = (Array.isArray(tree) ? tree as RemoteUiNodeSnapshot[] : []).filter((node) => (
|
|
729
649
|
(node.paneId === instanceId || node.metadata?.paneInstanceId === instanceId)
|
|
730
650
|
// A bare clickable box says nothing about what the pane shows.
|
|
731
651
|
&& !(node.role === "box" && !node.label)
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { commandBarResultsFromNodes } from "../../../../remote/command-bar";
|
|
2
|
+
import { findCommandBarResult, findMatchingUiNode } from "../../../../remote/matching";
|
|
3
|
+
import { remoteMenuItemId, resolveRemoteListIndex, resolveRemoteRowIndex } from "../../../../remote/semantic-helpers";
|
|
4
|
+
import type { RemoteSideEffectLevel, RemoteUiNodeSnapshot } from "../../../../remote/types";
|
|
5
|
+
import { logFailure } from "../../../../utils/log-failure";
|
|
6
|
+
import { keyArgumentLines, shortValue, type CallSummary } from "./summary";
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* What a remote assistant connected through Gloom Cloud may do in this app.
|
|
10
|
+
* Ask Gloom applies the same table to its own calls (askg/executor.ts), with
|
|
11
|
+
* no approval step: it is the person's own assistant, but it reads the same
|
|
12
|
+
* untrusted text.
|
|
5
13
|
*
|
|
6
14
|
* - `allow`: runs once the person approved the assistant for this terminal
|
|
7
15
|
* (one prompt per assistant, see grants.ts).
|
|
@@ -11,7 +19,8 @@ import type { RemoteSideEffectLevel } from "../../../../remote/types";
|
|
|
11
19
|
* order, a transfer, a message, a plugin capability) asks each time.
|
|
12
20
|
* - `local-ui`: `allow` for semantic UI actions that only move, select or
|
|
13
21
|
* type inside the app; `confirm` for every other action (press, submit,
|
|
14
|
-
* activate), since a button can send an order or a
|
|
22
|
+
* activate, an item of a plain menu), since a button can send an order or a
|
|
23
|
+
* message.
|
|
15
24
|
* - `navigation`: `allow` when the command-bar row opens a ticker or a pane;
|
|
16
25
|
* `confirm` for rows that run a command.
|
|
17
26
|
*
|
|
@@ -76,7 +85,7 @@ export const TERMINAL_RELAY_OPERATION_POLICY: Readonly<Record<string, TerminalRe
|
|
|
76
85
|
"layout.focusRegion": { policy: "allow", reason: OPEN },
|
|
77
86
|
"layout.setGrid": { policy: "allow", reason: ARRANGE },
|
|
78
87
|
"desktop.popOutPane": { policy: "allow", reason: "Moves a pane into its own desktop window." },
|
|
79
|
-
"desktop.dockPane": { policy: "allow", reason: "
|
|
88
|
+
"desktop.dockPane": { policy: "allow", reason: "Returns a popped-out desktop pane to the main window." },
|
|
80
89
|
"desktop.closeDetachedPane": { policy: "allow", reason: "Closes a detached desktop window." },
|
|
81
90
|
"desktop.focusDetachedPane": { policy: "allow", reason: "Focuses a detached desktop window." },
|
|
82
91
|
"capability.invoke": {
|
|
@@ -113,9 +122,10 @@ export function operationPolicy(operation: string): TerminalRelayPolicyEntry {
|
|
|
113
122
|
/**
|
|
114
123
|
* UI actions that only scroll, move a cursor, select or type inside the app.
|
|
115
124
|
* Everything else a node exposes (press, submit, activate, toggle, release)
|
|
116
|
-
* may act outside it and asks each time
|
|
125
|
+
* may act outside it and asks each time, and so does `select` on a plain
|
|
126
|
+
* menu, which runs the item (actionRunsSomething).
|
|
117
127
|
*/
|
|
118
|
-
|
|
128
|
+
const LOCAL_UI_ACTIONS: ReadonlySet<string> = new Set([
|
|
119
129
|
"scroll",
|
|
120
130
|
"scrollBy",
|
|
121
131
|
"scrollTo",
|
|
@@ -133,7 +143,7 @@ export const LOCAL_UI_ACTIONS: ReadonlySet<string> = new Set([
|
|
|
133
143
|
]);
|
|
134
144
|
|
|
135
145
|
/** Command-bar rows that only open a ticker or a pane. */
|
|
136
|
-
|
|
146
|
+
const NAVIGATION_RESULT_KINDS: ReadonlySet<string> = new Set([
|
|
137
147
|
"ticker",
|
|
138
148
|
"ticker-search",
|
|
139
149
|
"pane",
|
|
@@ -143,6 +153,316 @@ export const NAVIGATION_RESULT_KINDS: ReadonlySet<string> = new Set([
|
|
|
143
153
|
"mode",
|
|
144
154
|
]);
|
|
145
155
|
|
|
156
|
+
/** `metadata.scope` of the relay's own prompts (prompts.tsx). */
|
|
157
|
+
export const RELAY_PROMPT_SCOPE = "terminal-relay-prompt";
|
|
158
|
+
/** `metadata.scope` of Ask Gloom's approval row, its keys and the pane-consent prompt. */
|
|
159
|
+
export const ASKG_PROMPT_SCOPE = "askg-prompt";
|
|
160
|
+
/**
|
|
161
|
+
* The prompts that ask the person about an assistant's calls. No UI call acts
|
|
162
|
+
* on one, whichever assistant sent it: it could otherwise approve itself.
|
|
163
|
+
* Every control drawn inside one carries its scope (RemoteUiScope), labelled
|
|
164
|
+
* or not.
|
|
165
|
+
*/
|
|
166
|
+
const PROMPT_SCOPES: ReadonlySet<string> = new Set([RELAY_PROMPT_SCOPE, ASKG_PROMPT_SCOPE]);
|
|
167
|
+
|
|
168
|
+
function isPromptNode(node: RemoteUiNodeSnapshot | undefined): boolean {
|
|
169
|
+
const scope = node?.metadata?.scope;
|
|
170
|
+
return typeof scope === "string" && PROMPT_SCOPES.has(scope);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const PROMPT_OPEN = "A Gloom confirmation is open; the assistant cannot act on it.";
|
|
174
|
+
const TARGET_CHANGED = "What the call pointed at changed while the person decided, so it did not run. Read the state again and retry.";
|
|
175
|
+
|
|
176
|
+
/** A UI call the policy refuses outright, before anything is asked. */
|
|
177
|
+
export class UiCallRefusal extends Error {
|
|
178
|
+
constructor(readonly code: "not_allowed" | "invalid_input", message: string) {
|
|
179
|
+
super(message);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** What the policy says about one call that acts on what is on screen. */
|
|
184
|
+
export interface UiCallPlan {
|
|
185
|
+
/** What the person is asked before it runs; null runs it without asking. */
|
|
186
|
+
confirm: CallSummary | null;
|
|
187
|
+
/**
|
|
188
|
+
* Right before the call runs, after any answer: why it may no longer run (a
|
|
189
|
+
* confirmation is open, the call now aims at a prompt, or what the person
|
|
190
|
+
* allowed is not what is there now), or null.
|
|
191
|
+
*/
|
|
192
|
+
recheck(promptOpen: boolean): Promise<string | null>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface UiCallContext {
|
|
196
|
+
/** Reads one app resource (`ui://tree`, `ui://node/{id}`, `app://layouts`). */
|
|
197
|
+
read(resource: string): Promise<unknown>;
|
|
198
|
+
/** One of the caller's own confirmations waits for the person. */
|
|
199
|
+
promptOpen: boolean;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
type ReadResource = UiCallContext["read"];
|
|
203
|
+
|
|
204
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
205
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function readUiTree(read: ReadResource): Promise<RemoteUiNodeSnapshot[]> {
|
|
209
|
+
const nodes = await read("ui://tree");
|
|
210
|
+
return Array.isArray(nodes) ? nodes as RemoteUiNodeSnapshot[] : [];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Whether a UI action runs something rather than only moving, selecting or
|
|
215
|
+
* typing. A plain menu's `select` runs the item it picks (a pane's action
|
|
216
|
+
* menu); a select field's menu only picks a value.
|
|
217
|
+
*/
|
|
218
|
+
function actionRunsSomething(node: RemoteUiNodeSnapshot | undefined, action: string): boolean {
|
|
219
|
+
if (!LOCAL_UI_ACTIONS.has(action)) return true;
|
|
220
|
+
return action === "select" && node?.role === "menu" && (node.metadata?.selection ?? "none") === "none";
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** A control by what the person sees: `"Place order" (button)`. */
|
|
224
|
+
function controlName(node: RemoteUiNodeSnapshot): string {
|
|
225
|
+
return node.label ? `"${shortValue(node.label)}" (${node.role})` : `an unlabelled ${node.role}`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Actions that run one row or item of the control: a menu's item, a table's row, a list's entry. */
|
|
229
|
+
const ITEM_ACTIONS: ReadonlySet<string> = new Set(["activate", "activateRow", "select"]);
|
|
230
|
+
|
|
231
|
+
function textOf(value: unknown): string | undefined {
|
|
232
|
+
return typeof value === "string" && value ? value : undefined;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The label of the item an action's input picks, found the way the control
|
|
237
|
+
* itself finds it (semantic-helpers.ts): a Menu by id alone, a DataTable's
|
|
238
|
+
* row by index or key, a ListView's entry by index, id or label.
|
|
239
|
+
*/
|
|
240
|
+
function pickedItemLabel(role: string, metadata: Record<string, unknown> | undefined, input: unknown): string | undefined {
|
|
241
|
+
if (role === "menu") {
|
|
242
|
+
const id = remoteMenuItemId(input);
|
|
243
|
+
const items = Array.isArray(metadata?.items) ? metadata.items.filter(isRecord) : [];
|
|
244
|
+
return id === undefined ? undefined : textOf(items.find((item) => item.id === id)?.label);
|
|
245
|
+
}
|
|
246
|
+
if (role === "table") {
|
|
247
|
+
const rows = Array.isArray(metadata?.rows) ? metadata.rows.map((row) => (isRecord(row) ? row : {})) : [];
|
|
248
|
+
const row = rows[resolveRemoteRowIndex(input, rows, (entry) => (typeof entry.key === "string" ? entry.key : undefined))];
|
|
249
|
+
const cells = Array.isArray(row?.cells) ? row.cells.filter(isRecord) : [];
|
|
250
|
+
return cells.map((cell) => textOf(cell.text)).find(Boolean);
|
|
251
|
+
}
|
|
252
|
+
const items = Array.isArray(metadata?.items) ? metadata.items.map((item) => (isRecord(item) ? item : {})) : [];
|
|
253
|
+
return textOf(items[resolveRemoteListIndex(input, items)]?.label);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** One node with its pane's title and its detail (a table's rows); null when unreadable. */
|
|
257
|
+
async function readNodeDetail(nodeId: string, read: ReadResource): Promise<Record<string, unknown> | null> {
|
|
258
|
+
try {
|
|
259
|
+
const detail = await read(`ui://node/${encodeURIComponent(nodeId)}`);
|
|
260
|
+
return isRecord(detail) ? detail : null;
|
|
261
|
+
} catch {
|
|
262
|
+
// Intentional ignore: the tree already named the control, and the pane and the row only add to it.
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
interface TargetDescription {
|
|
268
|
+
title: string;
|
|
269
|
+
lines: CallSummary["lines"];
|
|
270
|
+
/** The same while the call would act on the same control, pane and row. */
|
|
271
|
+
fingerprint: string;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* What a UI action that runs something is asked as: the control by label and
|
|
276
|
+
* role, the pane it is in, and for a row or item the label it shows.
|
|
277
|
+
*/
|
|
278
|
+
async function describeTarget(
|
|
279
|
+
node: RemoteUiNodeSnapshot | undefined,
|
|
280
|
+
action: string,
|
|
281
|
+
input: unknown,
|
|
282
|
+
read: ReadResource,
|
|
283
|
+
): Promise<TargetDescription> {
|
|
284
|
+
const inputLine = input !== undefined ? [{ label: "Input", value: shortValue(input) }] : [];
|
|
285
|
+
if (!node) {
|
|
286
|
+
return {
|
|
287
|
+
title: action === "press" ? "Press a control" : `Run "${shortValue(action)}" on a control`,
|
|
288
|
+
lines: [{ label: "Control", value: "none visible yet" }, ...inputLine],
|
|
289
|
+
fingerprint: "",
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
const detail = await readNodeDetail(node.id, read);
|
|
293
|
+
const paneTitle = typeof detail?.paneTitle === "string" && detail.paneTitle.trim() ? shortValue(detail.paneTitle) : null;
|
|
294
|
+
const metadata = isRecord(detail?.metadata) ? detail.metadata : node.metadata;
|
|
295
|
+
const item = ITEM_ACTIONS.has(action) ? pickedItemLabel(node.role, metadata, input) : undefined;
|
|
296
|
+
const control = controlName(node);
|
|
297
|
+
const title = item
|
|
298
|
+
? `Choose "${shortValue(item)}" ${node.role === "menu" ? "from" : "in"} ${control}`
|
|
299
|
+
: action === "press" ? `Press ${control}` : `Run "${shortValue(action)}" on ${control}`;
|
|
300
|
+
return {
|
|
301
|
+
title,
|
|
302
|
+
lines: [
|
|
303
|
+
...(paneTitle ? [{ label: "Pane", value: paneTitle }] : []),
|
|
304
|
+
...(item ? [] : inputLine),
|
|
305
|
+
],
|
|
306
|
+
fingerprint: [node.id, node.role, node.label ?? "", paneTitle ?? "", item ?? ""].join("|"),
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* The per-call policy of an operation that acts on what is on screen
|
|
312
|
+
* (`local-ui`, `navigation`), for every assistant that drives the app: the
|
|
313
|
+
* terminal relay and Ask Gloom. Null for any other policy, which the caller
|
|
314
|
+
* applies as the table says. Throws UiCallRefusal for a call that may not run
|
|
315
|
+
* at all: one aimed at a confirmation prompt, or any while one is open.
|
|
316
|
+
*/
|
|
317
|
+
export async function planUiCall(
|
|
318
|
+
operation: string,
|
|
319
|
+
input: Record<string, unknown>,
|
|
320
|
+
context: UiCallContext,
|
|
321
|
+
): Promise<UiCallPlan | null> {
|
|
322
|
+
const { policy } = operationPolicy(operation);
|
|
323
|
+
if (policy === "local-ui") return planLocalUiCall(operation, input, context);
|
|
324
|
+
if (policy === "navigation") return planCommandBarCall(input, context);
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async function planLocalUiCall(
|
|
329
|
+
operation: string,
|
|
330
|
+
input: Record<string, unknown>,
|
|
331
|
+
{ read, promptOpen }: UiCallContext,
|
|
332
|
+
): Promise<UiCallPlan> {
|
|
333
|
+
const action = typeof input.action === "string" && input.action ? input.action : "press";
|
|
334
|
+
const find = async () => {
|
|
335
|
+
const nodes = await readUiTree(read);
|
|
336
|
+
return operation === "ui.invoke"
|
|
337
|
+
? nodes.find((node) => node.id === input.nodeId)
|
|
338
|
+
: findMatchingUiNode(nodes, input);
|
|
339
|
+
};
|
|
340
|
+
const target = await find();
|
|
341
|
+
if (promptOpen || isPromptNode(target)) throw new UiCallRefusal("not_allowed", PROMPT_OPEN);
|
|
342
|
+
if (!actionRunsSomething(target, action)) {
|
|
343
|
+
return {
|
|
344
|
+
confirm: null,
|
|
345
|
+
// Nothing was asked, so it runs only if it still runs nothing: the
|
|
346
|
+
// control may have appeared, or a select field's menu given way to a
|
|
347
|
+
// plain one, since the screen was read.
|
|
348
|
+
recheck: async (open) => {
|
|
349
|
+
const now = await find();
|
|
350
|
+
if (open || isPromptNode(now)) return PROMPT_OPEN;
|
|
351
|
+
return actionRunsSomething(now, action) ? TARGET_CHANGED : null;
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
const asked = await describeTarget(target, action, input.input, read);
|
|
356
|
+
return {
|
|
357
|
+
confirm: { title: asked.title, lines: asked.lines },
|
|
358
|
+
recheck: async (open) => {
|
|
359
|
+
const now = await find();
|
|
360
|
+
if (open || isPromptNode(now)) return PROMPT_OPEN;
|
|
361
|
+
const current = await describeTarget(now, action, input.input, read);
|
|
362
|
+
return current.fingerprint === asked.fingerprint ? null : TARGET_CHANGED;
|
|
363
|
+
},
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
async function planCommandBarCall(
|
|
368
|
+
input: Record<string, unknown>,
|
|
369
|
+
{ read, promptOpen }: UiCallContext,
|
|
370
|
+
): Promise<UiCallPlan> {
|
|
371
|
+
if (promptOpen) throw new UiCallRefusal("not_allowed", PROMPT_OPEN);
|
|
372
|
+
const find = async () => findCommandBarResult(commandBarResultsFromNodes(await readUiTree(read)), input);
|
|
373
|
+
const result = await find();
|
|
374
|
+
if (!result) throw new UiCallRefusal("invalid_input", "No matching command-bar result is visible.");
|
|
375
|
+
const kindOf = (row: typeof result) => (typeof row.kind === "string" ? row.kind : "");
|
|
376
|
+
const fingerprintOf = (row: typeof result) => `${shortValue(row.label)}|${kindOf(row)}|${shortValue(row.itemId)}`;
|
|
377
|
+
if (NAVIGATION_RESULT_KINDS.has(kindOf(result))) {
|
|
378
|
+
return { confirm: null, recheck: async (open) => (open ? PROMPT_OPEN : null) };
|
|
379
|
+
}
|
|
380
|
+
const fingerprint = fingerprintOf(result);
|
|
381
|
+
return {
|
|
382
|
+
confirm: {
|
|
383
|
+
title: `Run "${shortValue(result.label)}" from the command bar`,
|
|
384
|
+
lines: [
|
|
385
|
+
{ label: "Command", value: shortValue(result.label) },
|
|
386
|
+
...(result.detail ? [{ label: "Detail", value: shortValue(result.detail) }] : []),
|
|
387
|
+
],
|
|
388
|
+
},
|
|
389
|
+
recheck: async (open) => {
|
|
390
|
+
if (open) return PROMPT_OPEN;
|
|
391
|
+
const now = await find();
|
|
392
|
+
return now && fingerprintOf(now) === fingerprint ? null : TARGET_CHANGED;
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** A `confirm` operation as the person is asked about it, and what is checked again before it runs. */
|
|
398
|
+
export interface ConfirmedOperationPlan {
|
|
399
|
+
confirm: CallSummary;
|
|
400
|
+
/** Why the call may no longer run (what it named is gone or changed), or null. */
|
|
401
|
+
recheck?: () => Promise<string | null>;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* How the relay and Ask Gloom ask about a `confirm` operation that has no dry
|
|
406
|
+
* run of its own: the layout a delete removes, by name, and the plugin and
|
|
407
|
+
* operation a capability call runs. Null leaves the caller's own wording.
|
|
408
|
+
*/
|
|
409
|
+
export async function describeConfirmedOperation(
|
|
410
|
+
operation: string,
|
|
411
|
+
input: Record<string, unknown>,
|
|
412
|
+
read: ReadResource,
|
|
413
|
+
): Promise<ConfirmedOperationPlan | null> {
|
|
414
|
+
if (operation === "layout.delete") {
|
|
415
|
+
const layoutName = async (): Promise<string | null> => {
|
|
416
|
+
const layouts = await read("app://layouts");
|
|
417
|
+
const layout = Array.isArray(layouts) && typeof input.index === "number" ? layouts[input.index] : undefined;
|
|
418
|
+
return isRecord(layout) && typeof layout.name === "string" ? layout.name : null;
|
|
419
|
+
};
|
|
420
|
+
let name: string | null = null;
|
|
421
|
+
try {
|
|
422
|
+
name = await layoutName();
|
|
423
|
+
} catch (error) {
|
|
424
|
+
// The index still identifies it.
|
|
425
|
+
logFailure("cloud.terminal-relay", "Read layout names for a confirmation failed")(error);
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
confirm: {
|
|
429
|
+
title: `Delete the layout ${name ? `"${shortValue(name)}"` : `#${String(input.index)}`}`,
|
|
430
|
+
lines: [{ label: "Undo", value: "Not available for a deleted layout" }],
|
|
431
|
+
},
|
|
432
|
+
// The layout at that place now is not the one the person agreed to lose.
|
|
433
|
+
recheck: name === null ? undefined : async () => ((await layoutName()) === name ? null : TARGET_CHANGED),
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
if (operation === "capability.invoke") {
|
|
437
|
+
const capabilityId = typeof input.capabilityId === "string" ? input.capabilityId : "";
|
|
438
|
+
const operationId = typeof input.operationId === "string" ? input.operationId : "";
|
|
439
|
+
let plugin = capabilityId;
|
|
440
|
+
let operationTitle = operationId;
|
|
441
|
+
try {
|
|
442
|
+
const manifests = await read("app://capabilities");
|
|
443
|
+
const manifest = Array.isArray(manifests)
|
|
444
|
+
? manifests.find((entry) => isRecord(entry) && entry.id === capabilityId) as Record<string, unknown> | undefined
|
|
445
|
+
: undefined;
|
|
446
|
+
if (manifest && typeof manifest.name === "string") plugin = manifest.name;
|
|
447
|
+
const operations = manifest && Array.isArray(manifest.operations) ? manifest.operations : [];
|
|
448
|
+
const described = operations.find((entry) => isRecord(entry) && entry.id === operationId) as Record<string, unknown> | undefined;
|
|
449
|
+
if (described && typeof described.title === "string") operationTitle = described.title;
|
|
450
|
+
} catch (error) {
|
|
451
|
+
// The ids alone still say what runs.
|
|
452
|
+
logFailure("cloud.terminal-relay", "Read plugin names for a confirmation failed")(error);
|
|
453
|
+
}
|
|
454
|
+
return {
|
|
455
|
+
// The title names the plugin and the operation; the lines are the
|
|
456
|
+
// order itself, every one of them in sight (symbol, side, size, price).
|
|
457
|
+
confirm: {
|
|
458
|
+
title: `${shortValue(operationTitle)} with ${shortValue(plugin)}`,
|
|
459
|
+
lines: keyArgumentLines(input.payload),
|
|
460
|
+
},
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
|
|
146
466
|
/** What the policy carries into a tool's description. */
|
|
147
467
|
export function policySentence(policy: TerminalRelayPolicy): string {
|
|
148
468
|
switch (policy) {
|
|
@@ -151,7 +471,7 @@ export function policySentence(policy: TerminalRelayPolicy): string {
|
|
|
151
471
|
case "confirm":
|
|
152
472
|
return "The person confirms each call in Gloom; unanswered after 60 s it is denied.";
|
|
153
473
|
case "local-ui":
|
|
154
|
-
return "Scroll, select, setValue and focus run once the assistant is approved; press, submit and other actions are confirmed by the person on each call.";
|
|
474
|
+
return "Scroll, select, setValue and focus run once the assistant is approved; press, submit, choosing a menu item and other actions are confirmed by the person on each call.";
|
|
155
475
|
case "navigation":
|
|
156
476
|
return "Rows that open a ticker or a pane run once the assistant is approved; rows that run a command are confirmed by the person on each call.";
|
|
157
477
|
}
|