@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
package/src/remote/client.ts
CHANGED
|
@@ -1,24 +1,204 @@
|
|
|
1
|
-
import type { RemoteAppKind, RemoteControlRequest, RemoteControlResponse } from "./types";
|
|
2
|
-
import { readRemoteEndpoint } from "./endpoint";
|
|
1
|
+
import type { RemoteAppKind, RemoteControlRequest, RemoteControlResponse, RemoteEndpoint } from "./types";
|
|
2
|
+
import { currentPidNamespace, inNestedPidNamespace, readRemoteEndpoint, removeRemoteEndpointFiles } from "./endpoint";
|
|
3
|
+
import { isNetworkFailure } from "../utils/network-failure";
|
|
3
4
|
|
|
4
5
|
export interface SendRemoteControlRequestOptions {
|
|
5
6
|
dataDir: string;
|
|
6
7
|
appKind?: RemoteAppKind;
|
|
7
8
|
}
|
|
8
9
|
|
|
10
|
+
const APP_NAMES: Record<RemoteAppKind, string> = { tui: "terminal", desktop: "desktop" };
|
|
11
|
+
/** How long the app's health answer may take before it counts as unreachable; a busy app still answers well within it. */
|
|
12
|
+
const HEALTH_TIMEOUT_MS = 5_000;
|
|
13
|
+
|
|
14
|
+
/** Why no app took the request, with what to do about it in `details`. `code` is what `--json` reports. */
|
|
15
|
+
export class RemoteAppError extends Error {
|
|
16
|
+
readonly code: string;
|
|
17
|
+
readonly details: string;
|
|
18
|
+
|
|
19
|
+
constructor(code: string, message: string, details: string) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "RemoteAppError";
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.details = details;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* No app of this profile runs: none was started, or the one that wrote the
|
|
29
|
+
* endpoint file has exited without a clean quit (its terminal closed, it was
|
|
30
|
+
* killed). Says how to start one.
|
|
31
|
+
*/
|
|
32
|
+
export class RemoteAppNotRunningError extends RemoteAppError {
|
|
33
|
+
constructor(appKind?: RemoteAppKind, otherKind?: RemoteAppKind) {
|
|
34
|
+
super(
|
|
35
|
+
"app_not_running",
|
|
36
|
+
appKind ? `The Gloom ${APP_NAMES[appKind]} app is not running.` : "No Gloom app is running.",
|
|
37
|
+
otherKind
|
|
38
|
+
? `The ${APP_NAMES[otherKind]} app is: pass --app ${otherKind}, or leave --app out.`
|
|
39
|
+
: appKind === "desktop"
|
|
40
|
+
? "Open the Gloom desktop app, then try again."
|
|
41
|
+
: appKind === "tui"
|
|
42
|
+
? "Start it with `gloom` in another terminal, then try again."
|
|
43
|
+
: "Start one with `gloom` in another terminal or open the desktop app, then try again.",
|
|
44
|
+
);
|
|
45
|
+
this.name = "RemoteAppNotRunningError";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Both apps run and neither is the one last started: the caller names which. */
|
|
50
|
+
export class RemoteAppAmbiguousError extends RemoteAppError {
|
|
51
|
+
constructor() {
|
|
52
|
+
super("app_ambiguous", "The Gloom terminal and desktop apps are both running.", "Pass --app tui or --app desktop.");
|
|
53
|
+
this.name = "RemoteAppAmbiguousError";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* An endpoint file names an app this process cannot reach, and nothing proves
|
|
59
|
+
* the app gone: a sandbox that blocks localhost or hides other processes looks
|
|
60
|
+
* the same from inside as an app that quit. The file is kept.
|
|
61
|
+
*/
|
|
62
|
+
export class RemoteAppUnreachableError extends RemoteAppError {
|
|
63
|
+
constructor(endpoint: RemoteEndpoint, foreign: boolean) {
|
|
64
|
+
const address = `127.0.0.1:${endpoint.port}, where its endpoint file says it listens`;
|
|
65
|
+
super(
|
|
66
|
+
"app_unreachable",
|
|
67
|
+
`The Gloom ${APP_NAMES[endpoint.appKind] ?? "app"} app could not be reached.`,
|
|
68
|
+
`${foreign ? `What answers at ${address}, is not Gloom.` : `Nothing answered at ${address}.`} `
|
|
69
|
+
+ "If this command runs in a sandbox, let it reach 127.0.0.1 or run it outside the sandbox. "
|
|
70
|
+
+ "If Gloom has quit, start it again: the new app replaces the file.",
|
|
71
|
+
);
|
|
72
|
+
this.name = "RemoteAppUnreachableError";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Whether an endpoint's app is there: true, false, or null when this process cannot tell. */
|
|
77
|
+
function processAlive(endpoint: RemoteEndpoint): boolean | null {
|
|
78
|
+
// A process id is only meaningful in the namespace that issued it.
|
|
79
|
+
const own = currentPidNamespace();
|
|
80
|
+
const comparable = endpoint.pidNamespace !== undefined
|
|
81
|
+
? endpoint.pidNamespace === own
|
|
82
|
+
// A file from an app that did not name its namespace: doubt the ids only inside a sandbox's or container's own.
|
|
83
|
+
: !inNestedPidNamespace();
|
|
84
|
+
if (!comparable || !Number.isInteger(endpoint.pid) || endpoint.pid <= 0) return null;
|
|
85
|
+
try {
|
|
86
|
+
process.kill(endpoint.pid, 0);
|
|
87
|
+
return true;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
90
|
+
// One owned by another user, or that a sandbox will not let this process signal, still runs.
|
|
91
|
+
return code === "ESRCH" ? false : code === "EPERM" ? true : null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function connectionRefused(error: unknown): boolean {
|
|
96
|
+
const codes = [error, (error as { cause?: unknown } | null)?.cause]
|
|
97
|
+
.map((entry) => (entry as { code?: unknown } | null | undefined)?.code);
|
|
98
|
+
return codes.includes("ConnectionRefused") || codes.includes("ECONNREFUSED");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Gloom answered; the port refused; the connection failed some other way (a sandbox, a timeout); something else answered. */
|
|
102
|
+
type Health = "gloom" | "refused" | "failed" | "foreign";
|
|
103
|
+
|
|
104
|
+
/** Asks the endpoint's port, without the token, whether a Gloom app answers there. */
|
|
105
|
+
async function probeHealth(endpoint: RemoteEndpoint): Promise<Health> {
|
|
106
|
+
try {
|
|
107
|
+
const response = await fetch(`http://127.0.0.1:${endpoint.port}/health`, { signal: AbortSignal.timeout(HEALTH_TIMEOUT_MS) });
|
|
108
|
+
const body = await response.json().catch(() => {
|
|
109
|
+
// Intentional ignore: an answer that is not JSON is not Gloom's, which the null below says.
|
|
110
|
+
return null;
|
|
111
|
+
}) as { ok?: unknown } | null;
|
|
112
|
+
return response.ok && body?.ok === true ? "gloom" : "foreign";
|
|
113
|
+
} catch (error) {
|
|
114
|
+
return connectionRefused(error) ? "refused" : "failed";
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
type EndpointState =
|
|
119
|
+
| { kind: "running"; endpoint: RemoteEndpoint }
|
|
120
|
+
| { kind: "unreachable"; endpoint: RemoteEndpoint; foreign: boolean }
|
|
121
|
+
| { kind: "gone" };
|
|
122
|
+
|
|
123
|
+
/** Reads the endpoint files and probes each app once, however many files name it. */
|
|
124
|
+
function endpointReader(dataDir: string) {
|
|
125
|
+
const states = new Map<string, Promise<EndpointState>>();
|
|
126
|
+
|
|
127
|
+
const classify = async (endpoint: RemoteEndpoint): Promise<EndpointState> => {
|
|
128
|
+
const health = await probeHealth(endpoint);
|
|
129
|
+
if (health === "gloom") return { kind: "running", endpoint };
|
|
130
|
+
// Only proof on both counts removes the file: the app's process is gone, and its port refuses.
|
|
131
|
+
if (health === "refused" && processAlive(endpoint) === false) {
|
|
132
|
+
await removeRemoteEndpointFiles(dataDir, endpoint).catch(() => { /* Intentional ignore: a file another process removed or replaced first is not ours to clean. */ });
|
|
133
|
+
return { kind: "gone" };
|
|
134
|
+
}
|
|
135
|
+
return { kind: "unreachable", endpoint, foreign: health === "foreign" };
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
return async (appKind?: RemoteAppKind): Promise<EndpointState> => {
|
|
139
|
+
let endpoint: RemoteEndpoint;
|
|
140
|
+
try {
|
|
141
|
+
endpoint = await readRemoteEndpoint(dataDir, appKind);
|
|
142
|
+
} catch {
|
|
143
|
+
// Intentional ignore: a file that is absent, or cut short by an app that died writing it, names no app to reach.
|
|
144
|
+
return { kind: "gone" };
|
|
145
|
+
}
|
|
146
|
+
const key = `${endpoint.pid}:${endpoint.port}:${endpoint.token}`;
|
|
147
|
+
let state = states.get(key);
|
|
148
|
+
if (!state) states.set(key, state = classify(endpoint));
|
|
149
|
+
return state;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function unreachable(state: Extract<EndpointState, { kind: "unreachable" }>): RemoteAppUnreachableError {
|
|
154
|
+
return new RemoteAppUnreachableError(state.endpoint, state.foreign);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The running app to send to: the one asked for, else the one started last
|
|
159
|
+
* (`remote-control.json`), else the only one of the two still running. An
|
|
160
|
+
* endpoint file is removed only when its process is gone and its port refuses.
|
|
161
|
+
*/
|
|
162
|
+
export async function resolveRemoteEndpoint(dataDir: string, appKind?: RemoteAppKind): Promise<RemoteEndpoint> {
|
|
163
|
+
const read = endpointReader(dataDir);
|
|
164
|
+
if (appKind) {
|
|
165
|
+
const state = await read(appKind);
|
|
166
|
+
if (state.kind === "running") return state.endpoint;
|
|
167
|
+
if (state.kind === "unreachable") throw unreachable(state);
|
|
168
|
+
const other: RemoteAppKind = appKind === "tui" ? "desktop" : "tui";
|
|
169
|
+
throw new RemoteAppNotRunningError(appKind, (await read(other)).kind === "running" ? other : undefined);
|
|
170
|
+
}
|
|
171
|
+
const latest = await read();
|
|
172
|
+
if (latest.kind === "running") return latest.endpoint;
|
|
173
|
+
const states = await Promise.all([read("tui"), read("desktop")]);
|
|
174
|
+
const running = states.filter((state) => state.kind === "running");
|
|
175
|
+
if (running.length > 1) throw new RemoteAppAmbiguousError();
|
|
176
|
+
if (running[0]) return running[0].endpoint;
|
|
177
|
+
const blocked = [latest, ...states].find((state) => state.kind === "unreachable");
|
|
178
|
+
if (blocked) throw unreachable(blocked);
|
|
179
|
+
throw new RemoteAppNotRunningError();
|
|
180
|
+
}
|
|
181
|
+
|
|
9
182
|
export async function sendRemoteControlRequest(
|
|
10
183
|
request: RemoteControlRequest,
|
|
11
184
|
options: SendRemoteControlRequestOptions,
|
|
12
185
|
): Promise<RemoteControlResponse> {
|
|
13
|
-
const endpoint = await
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
186
|
+
const endpoint = await resolveRemoteEndpoint(options.dataDir, options.appKind);
|
|
187
|
+
let response: Response;
|
|
188
|
+
try {
|
|
189
|
+
response = await fetch(`http://127.0.0.1:${endpoint.port}/rpc`, {
|
|
190
|
+
method: "POST",
|
|
191
|
+
headers: {
|
|
192
|
+
authorization: `Bearer ${endpoint.token}`,
|
|
193
|
+
"content-type": "application/json",
|
|
194
|
+
},
|
|
195
|
+
body: JSON.stringify(request),
|
|
196
|
+
});
|
|
197
|
+
} catch (error) {
|
|
198
|
+
// It answered its health check a moment ago; the next call finds out whether it quit.
|
|
199
|
+
if (!isNetworkFailure(error)) throw error;
|
|
200
|
+
throw new RemoteAppUnreachableError(endpoint, false);
|
|
201
|
+
}
|
|
22
202
|
const payload = await response.json() as RemoteControlResponse;
|
|
23
203
|
if (!response.ok && payload.ok !== false) {
|
|
24
204
|
return {
|
|
@@ -77,11 +77,23 @@ function panePlacement(layout: LayoutConfig, instanceId: string): "docked" | "fl
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
export function paneSnapshot(state: AppState, pane: PaneInstanceConfig) {
|
|
80
|
+
return {
|
|
81
|
+
...paneSummary(state, pane),
|
|
82
|
+
runtimeState: state.paneState[pane.instanceId] ?? {},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A pane as the snapshot and every call's answer list it: where it is and
|
|
88
|
+
* whether it has focus, without its runtime state, which can hold everything
|
|
89
|
+
* it loaded (a news pane's stories). app://panes and app://pane-state/{paneId}
|
|
90
|
+
* carry that.
|
|
91
|
+
*/
|
|
92
|
+
export function paneSummary(state: AppState, pane: PaneInstanceConfig) {
|
|
80
93
|
return {
|
|
81
94
|
...pane,
|
|
82
95
|
placement: panePlacement(state.config.layout, pane.instanceId),
|
|
83
96
|
focused: state.focusedPaneId === pane.instanceId,
|
|
84
|
-
runtimeState: state.paneState[pane.instanceId] ?? {},
|
|
85
97
|
};
|
|
86
98
|
}
|
|
87
99
|
|
package/src/remote/controller.ts
CHANGED
|
@@ -37,6 +37,7 @@ import type {
|
|
|
37
37
|
} from "./types";
|
|
38
38
|
import type { RemoteUiRegistry } from "./semantic-tree";
|
|
39
39
|
import { commandBarResultsFromNodes, isCommandBarInputNode } from "./command-bar";
|
|
40
|
+
import { commandBarBlockedBy, coveredByWarning, formNodes, formSnapshot, noDialogToClose } from "./form";
|
|
40
41
|
import { findCommandBarResult, findMatchingUiNode } from "./matching";
|
|
41
42
|
import { REMOTE_AGENT_HELP, REMOTE_OPERATIONS, remoteControlSchema } from "./schema";
|
|
42
43
|
import {
|
|
@@ -100,6 +101,26 @@ interface AppRemoteControllerOptions {
|
|
|
100
101
|
const PLANNED_OPERATIONS = new Set(["watchlist.add", "watchlist.remove"]);
|
|
101
102
|
/** Reads change nothing, so their answer carries no layout or command-bar state. */
|
|
102
103
|
const READ_OPERATIONS = new Set(REMOTE_OPERATIONS.filter((entry) => entry.sideEffectLevel === "none").map((entry) => entry.id));
|
|
104
|
+
/**
|
|
105
|
+
* Calls that act on the dialog on top, or on nothing drawn behind it: made
|
|
106
|
+
* while a form or the setup covers the app, they are not reported as hidden.
|
|
107
|
+
* `ui.invoke` and `ui.invokeMatching` are, when the node they pressed is in a pane.
|
|
108
|
+
*/
|
|
109
|
+
const NOT_BEHIND_A_DIALOG = new Set([
|
|
110
|
+
"app.closeDialog",
|
|
111
|
+
"app.closeCommandBar",
|
|
112
|
+
"app.notify",
|
|
113
|
+
// What the pane settings dialog edits, and how an agent edits it while it is open.
|
|
114
|
+
"pane.setSetting",
|
|
115
|
+
"pane.setState",
|
|
116
|
+
"capability.invoke",
|
|
117
|
+
"watchlist.add",
|
|
118
|
+
"watchlist.remove",
|
|
119
|
+
// Another window: nothing in this one covers it.
|
|
120
|
+
"desktop.popOutPane",
|
|
121
|
+
"desktop.focusDetachedPane",
|
|
122
|
+
"desktop.closeDetachedPane",
|
|
123
|
+
]);
|
|
103
124
|
|
|
104
125
|
// A command with a wizard closes the bar and opens its form, so every call says whether one is open.
|
|
105
126
|
const DEFAULT_MUTATION_INCLUDE: RemoteStateInclude[] = ["app", "layout", "panes", "commandBar", "form"];
|
|
@@ -269,11 +290,17 @@ export function createAppRemoteController({
|
|
|
269
290
|
}
|
|
270
291
|
};
|
|
271
292
|
|
|
293
|
+
/** The open form, confirm or setup, as `app://form` reads it. */
|
|
294
|
+
const currentForm = () => formSnapshot(formNodes(uiRegistry), isDialogOpen());
|
|
295
|
+
|
|
272
296
|
const openCommandBar = async (input: Record<string, unknown>): Promise<unknown> => {
|
|
273
297
|
const mode = optionalString(input, "mode") ?? "command";
|
|
274
298
|
const query = optionalString(input, "query") ?? "";
|
|
275
299
|
// The bar would open over the dialog without its keys.
|
|
276
300
|
if (isDialogOpen()) throw new Error("A dialog is open. Close it first with app.closeDialog.");
|
|
301
|
+
// The setup holds the keys a person would open the bar with, and the bar would open behind it.
|
|
302
|
+
const blocked = commandBarBlockedBy(currentForm());
|
|
303
|
+
if (blocked) throw new Error(blocked);
|
|
277
304
|
if (getState().commandBarOpen) {
|
|
278
305
|
dispatch({ type: "SET_COMMAND_BAR", open: false });
|
|
279
306
|
await afterMutation();
|
|
@@ -438,7 +465,7 @@ export function createAppRemoteController({
|
|
|
438
465
|
dispatch({ type: "SET_COMMAND_BAR", open: false });
|
|
439
466
|
return getAfterMutationSummary();
|
|
440
467
|
case "app.closeDialog":
|
|
441
|
-
if (!closeTopmostDialog()) throw new Error(
|
|
468
|
+
if (!closeTopmostDialog()) throw new Error(noDialogToClose(currentForm()));
|
|
442
469
|
return getAfterMutationSummary();
|
|
443
470
|
case "app.setCommandBarQuery":
|
|
444
471
|
await setVisibleCommandBarQuery(stringInput(input, "query"));
|
|
@@ -663,6 +690,32 @@ export function createAppRemoteController({
|
|
|
663
690
|
}
|
|
664
691
|
};
|
|
665
692
|
|
|
693
|
+
/**
|
|
694
|
+
* Whether a call is made on the app behind an open form or setup rather than
|
|
695
|
+
* on the form itself: a UI node is behind it when it is drawn in a pane.
|
|
696
|
+
*/
|
|
697
|
+
const actsBehindDialog = (operation: string, rawInput: unknown): boolean => {
|
|
698
|
+
if (READ_OPERATIONS.has(operation) || NOT_BEHIND_A_DIALOG.has(operation)) return false;
|
|
699
|
+
if (operation !== "ui.invoke" && operation !== "ui.invokeMatching") return true;
|
|
700
|
+
const input = asRecord(rawInput);
|
|
701
|
+
const nodes = uiRegistry?.snapshot() ?? [];
|
|
702
|
+
const node = operation === "ui.invoke"
|
|
703
|
+
? nodes.find((entry) => entry.id === input.nodeId)
|
|
704
|
+
: findMatchingUiNode(nodes, input);
|
|
705
|
+
return !!node?.paneId;
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Runs a change, and says so when a form or the setup covered the app before
|
|
710
|
+
* and after it: the change happened behind it, where the person cannot see it.
|
|
711
|
+
*/
|
|
712
|
+
const withCoverWarning = async (behind: boolean, run: () => Promise<RemoteControlResponse>): Promise<RemoteControlResponse> => {
|
|
713
|
+
const before = behind ? coveredByWarning(currentForm()) : null;
|
|
714
|
+
const response = await run();
|
|
715
|
+
if (!before || !response.ok || !coveredByWarning(currentForm())) return response;
|
|
716
|
+
return { ...response, warnings: [...response.warnings ?? [], before] };
|
|
717
|
+
};
|
|
718
|
+
|
|
666
719
|
/** `context` comes from in-process callers only; the local endpoint never passes one. */
|
|
667
720
|
const handle = async (request: RemoteControlRequest, context: RemoteCallContext = {}): Promise<RemoteControlResponse> => {
|
|
668
721
|
try {
|
|
@@ -678,27 +731,31 @@ export function createAppRemoteController({
|
|
|
678
731
|
case "data":
|
|
679
732
|
return ok(await queryMarketData(request));
|
|
680
733
|
case "call": {
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
const currentRev = revisionFor(target.value);
|
|
688
|
-
if (request.expectRev && request.expectRev !== currentRev) {
|
|
689
|
-
throw new Error(`Revision mismatch for ${request.resource}: expected ${request.expectRev}, got ${currentRev}.`);
|
|
690
|
-
}
|
|
691
|
-
const nextValue = applyJsonPatch(target.value, request.patch as RemoteJsonPatchOperation[]);
|
|
692
|
-
if (!request.dryRun) {
|
|
693
|
-
await target.apply(nextValue);
|
|
694
|
-
await afterMutation();
|
|
695
|
-
}
|
|
696
|
-
return ok(
|
|
697
|
-
nextValue,
|
|
698
|
-
revisionFor(nextValue),
|
|
699
|
-
buildIncludedState(request.include, request.dryRun ? [] : DEFAULT_MUTATION_INCLUDE),
|
|
700
|
-
);
|
|
734
|
+
const behind = !request.dryRun && actsBehindDialog(request.operation, request.input);
|
|
735
|
+
return await withCoverWarning(behind, async () => {
|
|
736
|
+
const data = await call(request.operation, request.input, request.dryRun, context);
|
|
737
|
+
const defaults = request.dryRun || READ_OPERATIONS.has(request.operation) ? [] : DEFAULT_MUTATION_INCLUDE;
|
|
738
|
+
return ok(data, undefined, buildIncludedState(request.include, defaults));
|
|
739
|
+
});
|
|
701
740
|
}
|
|
741
|
+
case "patch":
|
|
742
|
+
return await withCoverWarning(!request.dryRun, async () => {
|
|
743
|
+
const target = patchTarget(request.resource);
|
|
744
|
+
const currentRev = revisionFor(target.value);
|
|
745
|
+
if (request.expectRev && request.expectRev !== currentRev) {
|
|
746
|
+
throw new Error(`Revision mismatch for ${request.resource}: expected ${request.expectRev}, got ${currentRev}.`);
|
|
747
|
+
}
|
|
748
|
+
const nextValue = applyJsonPatch(target.value, request.patch as RemoteJsonPatchOperation[]);
|
|
749
|
+
if (!request.dryRun) {
|
|
750
|
+
await target.apply(nextValue);
|
|
751
|
+
await afterMutation();
|
|
752
|
+
}
|
|
753
|
+
return ok(
|
|
754
|
+
nextValue,
|
|
755
|
+
revisionFor(nextValue),
|
|
756
|
+
buildIncludedState(request.include, request.dryRun ? [] : DEFAULT_MUTATION_INCLUDE),
|
|
757
|
+
);
|
|
758
|
+
});
|
|
702
759
|
case "batch": {
|
|
703
760
|
const responses = [];
|
|
704
761
|
const haltOnError = request.haltOnError !== false;
|
|
@@ -718,11 +775,16 @@ export function createAppRemoteController({
|
|
|
718
775
|
}
|
|
719
776
|
}
|
|
720
777
|
if (request.settle === "afterBatch") await afterMutation();
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
778
|
+
// Each step's warnings, once each, where a client prints the batch's own.
|
|
779
|
+
const warnings = [...new Set(responses.flatMap((response) => response.ok ? response.warnings ?? [] : []))];
|
|
780
|
+
return {
|
|
781
|
+
...ok({
|
|
782
|
+
ok: responses.every((response) => response.ok),
|
|
783
|
+
haltedAt,
|
|
784
|
+
responses,
|
|
785
|
+
}, undefined, buildIncludedState(request.include, request.dryRun ? [] : DEFAULT_MUTATION_INCLUDE)),
|
|
786
|
+
...(warnings.length > 0 ? { warnings } : {}),
|
|
787
|
+
};
|
|
726
788
|
}
|
|
727
789
|
default:
|
|
728
790
|
throw new Error(`Unknown remote request type: ${(request as { type?: unknown }).type}`);
|
package/src/remote/endpoint.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readFileSync, readlinkSync } from "fs";
|
|
1
2
|
import { readFile, rename, rm } from "fs/promises";
|
|
2
3
|
import { dirname, join } from "path";
|
|
3
4
|
import { makePrivateDir, writePrivateFile } from "../utils/private-files";
|
|
@@ -9,6 +10,29 @@ export function remoteEndpointPath(dataDir: string, appKind?: RemoteAppKind): st
|
|
|
9
10
|
return join(dataDir, appKind ? `remote-control.${appKind}.json` : DEFAULT_ENDPOINT_FILE);
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
/** This process's process-id namespace on Linux (`pid:[4026531836]`); undefined elsewhere, where there are none. */
|
|
14
|
+
export function currentPidNamespace(): string | undefined {
|
|
15
|
+
if (process.platform !== "linux") return undefined;
|
|
16
|
+
try {
|
|
17
|
+
return readlinkSync("/proc/self/ns/pid");
|
|
18
|
+
} catch {
|
|
19
|
+
// Intentional ignore: without /proc the namespace is unknown, and the caller treats it as such.
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Whether this process runs in a process-id namespace nested in another, as a sandbox's or a container's. */
|
|
25
|
+
export function inNestedPidNamespace(): boolean {
|
|
26
|
+
if (process.platform !== "linux") return false;
|
|
27
|
+
try {
|
|
28
|
+
const line = /^NSpid:\s*(.+)$/m.exec(readFileSync("/proc/self/status", "utf-8"))?.[1];
|
|
29
|
+
return !!line && line.trim().split(/\s+/).length > 1;
|
|
30
|
+
} catch {
|
|
31
|
+
// Intentional ignore: without /proc nothing says this process is nested, so its process ids are taken as they are.
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
12
36
|
export async function readRemoteEndpoint(dataDir: string, appKind?: RemoteAppKind): Promise<RemoteEndpoint> {
|
|
13
37
|
const raw = await readFile(remoteEndpointPath(dataDir, appKind), "utf-8");
|
|
14
38
|
return JSON.parse(raw) as RemoteEndpoint;
|
package/src/remote/form.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import type { RemoteUiRegistry } from "./semantic-tree";
|
|
1
2
|
import type { RemoteUiNodeSnapshot } from "./types";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The open form or confirm, read from the node the form modal registers: its
|
|
5
6
|
* kind, title, fields with their values and options, error, pending state and
|
|
6
|
-
* submit label, and the node that cancels or sends it.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* submit label, and the node that cancels or sends it. A full-window card
|
|
8
|
+
* such as the first-run setup reads the same way, as kind "setup" with its
|
|
9
|
+
* step and buttons (remote/surface.tsx). `covered` when another dialog (a
|
|
10
|
+
* listing picker, a sign-in) sits over it. `{ open: false }` when none is
|
|
11
|
+
* open, with `otherDialogOpen` while a dialog that is not a form (pane
|
|
9
12
|
* settings) is.
|
|
10
13
|
*/
|
|
11
14
|
export function formSnapshot(nodes: RemoteUiNodeSnapshot[], dialogOpen: boolean) {
|
|
@@ -15,6 +18,58 @@ export function formSnapshot(nodes: RemoteUiNodeSnapshot[], dialogOpen: boolean)
|
|
|
15
18
|
return { open: true, nodeId: node.id, actions: node.actions, ...form, ...(covered === true ? { covered } : {}) };
|
|
16
19
|
}
|
|
17
20
|
|
|
21
|
+
/** The nodes `formSnapshot` reads, without projecting the rest of the tree where the registry can. */
|
|
22
|
+
export function formNodes(registry: Pick<RemoteUiRegistry, "snapshot" | "snapshotRole"> | null | undefined): RemoteUiNodeSnapshot[] {
|
|
23
|
+
if (!registry) return [];
|
|
24
|
+
return registry.snapshotRole?.("form") ?? registry.snapshot();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The form on top: the last one opened that nothing covers, else the last one. */
|
|
18
28
|
export function findFormNode(nodes: RemoteUiNodeSnapshot[]): RemoteUiNodeSnapshot | undefined {
|
|
19
|
-
|
|
29
|
+
const forms = nodes.filter((entry) => entry.role === "form" && entry.metadata?.scope === "form");
|
|
30
|
+
return forms.filter((entry) => entry.metadata?.covered !== true).at(-1) ?? forms.at(-1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type FormState = Record<string, unknown>;
|
|
34
|
+
|
|
35
|
+
function isSetup(form: FormState): boolean {
|
|
36
|
+
return form.open === true && form.kind === "setup";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The open form by what it is and its title: `the setup dialog "What do you hold?"`. */
|
|
40
|
+
function formName(form: FormState): string {
|
|
41
|
+
const title = typeof form.title === "string" && form.title ? ` "${form.title}"` : "";
|
|
42
|
+
return isSetup(form) ? `the setup dialog${title}` : `the form${title}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function capitalized(text: string): string {
|
|
46
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** What a call made while `form` is open did not reach: the app behind it. */
|
|
50
|
+
export function coveredByWarning(form: FormState): string | null {
|
|
51
|
+
if (form.open !== true) {
|
|
52
|
+
return form.otherDialogOpen === true
|
|
53
|
+
? "A dialog is open over the app, so this change is behind it until the dialog closes (app.closeDialog)."
|
|
54
|
+
: null;
|
|
55
|
+
}
|
|
56
|
+
return isSetup(form)
|
|
57
|
+
? `${capitalized(formName(form))} covers the app, so this change is behind it until setup is finished or skipped. app://form lists its fields and buttons.`
|
|
58
|
+
: `${capitalized(formName(form))} is open over the app, so this change is behind it until the form is sent or cancelled (app://form).`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Why the command bar does not open while `form` is open, or null when nothing is. */
|
|
62
|
+
export function commandBarBlockedBy(form: FormState): string | null {
|
|
63
|
+
if (form.open !== true) return null;
|
|
64
|
+
return `${capitalized(formName(form))} covers the app, and the command bar would open behind it. `
|
|
65
|
+
+ `${isSetup(form) ? "Finish or skip setup first" : "Send or cancel it first"}: app://form lists its fields and buttons.`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Why app.closeDialog closed nothing: no dialog is open, and the setup is closed through its own buttons. */
|
|
69
|
+
export function noDialogToClose(form: FormState): string {
|
|
70
|
+
if (!isSetup(form)) return "No dialog is open.";
|
|
71
|
+
const skip = Array.isArray(form.actions) && form.actions.includes("cancel");
|
|
72
|
+
return skip
|
|
73
|
+
? `No dialog is open over ${formName(form)}. Skip setup with ui.invokeMatching { role: 'form', action: 'cancel' }, or finish it with its buttons (app://form).`
|
|
74
|
+
: `No dialog is open over ${formName(form)}, and this step cannot skip the whole setup. Press its buttons (app://form lists them); Skip leaves a step without filling it.`;
|
|
20
75
|
}
|
package/src/remote/resources.ts
CHANGED
|
@@ -4,16 +4,18 @@ import { apiClient } from "../api-client";
|
|
|
4
4
|
import type { AppAction, AppState } from "../state/app/context";
|
|
5
5
|
import type { PaneRuntimeState } from "../core/state/app/state";
|
|
6
6
|
import { setPaneSettings } from "../pane-settings";
|
|
7
|
-
import type
|
|
7
|
+
import { findPaneInstance, type LayoutConfig } from "../types/config";
|
|
8
|
+
import { getBasePaneDisplayTitle } from "../components/layout/pane/title";
|
|
8
9
|
import { commandBarResultsFromNodes, commandBarSnapshot } from "./command-bar";
|
|
9
|
-
import { formSnapshot } from "./form";
|
|
10
|
+
import { formNodes, formSnapshot } from "./form";
|
|
10
11
|
import type { RemoteUiRegistry } from "./semantic-tree";
|
|
11
12
|
import { REMOTE_AGENT_HELP, remoteControlSchema } from "./schema";
|
|
12
|
-
import type { RemoteIncludedState, RemoteStateInclude } from "./types";
|
|
13
|
+
import type { RemoteIncludedState, RemoteStateInclude, RemoteUiNodeSnapshot } from "./types";
|
|
13
14
|
import {
|
|
14
15
|
activeLayoutRev,
|
|
15
16
|
normalizeIncludes,
|
|
16
17
|
paneSnapshot,
|
|
18
|
+
paneSummary,
|
|
17
19
|
type PatchTarget,
|
|
18
20
|
} from "./controller-utils";
|
|
19
21
|
import { finiteOrNull } from "../utils/guards";
|
|
@@ -65,6 +67,28 @@ function brokerAccountsResource(state: AppState) {
|
|
|
65
67
|
}));
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
/**
|
|
71
|
+
* What the default snapshot leaves out for its size, and where to read it:
|
|
72
|
+
* an agent reads the schema and the guide once, not with every look.
|
|
73
|
+
*/
|
|
74
|
+
const SNAPSHOT_REFERENCES = {
|
|
75
|
+
schema: "Every resource and operation with its input: { type: 'schema' } (gloom remote schema). Read it once.",
|
|
76
|
+
help: "Recipes and caveats: app://remote/help (gloom remote help).",
|
|
77
|
+
ui: "ui lists the labelled controls; ui://tree lists every node, unlabelled click areas too.",
|
|
78
|
+
paneState: "What a pane loaded and where it is (panes[].runtimeState, config.layouts[].paneState): app://pane-state/{paneId}, app://panes, app://config.",
|
|
79
|
+
full: "app://snapshot/full has all of it inline.",
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/** The config without what each saved layout's panes loaded: app://config keeps it. */
|
|
83
|
+
function configSummary(config: AppState["config"]): AppState["config"] {
|
|
84
|
+
return { ...config, layouts: config.layouts.map(({ paneState: _paneState, ...layout }) => layout) };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A clickable box with no label: it says nothing an agent can act on by name. */
|
|
88
|
+
function isBareBox(node: { role: string; label?: string }): boolean {
|
|
89
|
+
return node.role === "box" && !node.label;
|
|
90
|
+
}
|
|
91
|
+
|
|
68
92
|
export function createRemoteResources({
|
|
69
93
|
dispatch,
|
|
70
94
|
getState,
|
|
@@ -74,8 +98,9 @@ export function createRemoteResources({
|
|
|
74
98
|
}: RemoteResourceContext) {
|
|
75
99
|
const getResource = (resource: string): unknown => {
|
|
76
100
|
const state = getState();
|
|
77
|
-
|
|
78
|
-
|
|
101
|
+
if (resource === "app://snapshot" || resource === "app://snapshot/full") {
|
|
102
|
+
const uiNodes = uiRegistry?.snapshot() ?? [];
|
|
103
|
+
const full = resource === "app://snapshot/full";
|
|
79
104
|
return {
|
|
80
105
|
rev: activeLayoutRev(state),
|
|
81
106
|
app: {
|
|
@@ -87,13 +112,13 @@ export function createRemoteResources({
|
|
|
87
112
|
commandBarQuery: state.commandBarQuery,
|
|
88
113
|
initialized: state.initialized,
|
|
89
114
|
},
|
|
90
|
-
config: state.config,
|
|
91
|
-
panes: state.config.layout.instances.map((pane) => paneSnapshot(state, pane)),
|
|
115
|
+
config: full ? state.config : configSummary(state.config),
|
|
116
|
+
panes: state.config.layout.instances.map((pane) => (full ? paneSnapshot : paneSummary)(state, pane)),
|
|
92
117
|
commandBar: commandBarSnapshot(state, uiNodes),
|
|
93
118
|
form: formSnapshot(uiNodes, isDialogOpen()),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
119
|
+
...full
|
|
120
|
+
? { ui: uiNodes, schema: remoteControlSchema(), help: REMOTE_AGENT_HELP }
|
|
121
|
+
: { ui: uiNodes.filter((node) => !isBareBox(node)), references: SNAPSHOT_REFERENCES },
|
|
97
122
|
};
|
|
98
123
|
}
|
|
99
124
|
if (resource === "app://config") return state.config;
|
|
@@ -142,14 +167,24 @@ export function createRemoteResources({
|
|
|
142
167
|
hasWizard: !!command.wizard?.length,
|
|
143
168
|
}));
|
|
144
169
|
}
|
|
145
|
-
if (resource === "app://command-bar") return commandBarSnapshot(state,
|
|
146
|
-
if (resource === "app://command-bar/results") return commandBarResultsFromNodes(
|
|
147
|
-
if (resource === "app://form") return formSnapshot(
|
|
170
|
+
if (resource === "app://command-bar") return commandBarSnapshot(state, uiRegistry?.snapshot() ?? []);
|
|
171
|
+
if (resource === "app://command-bar/results") return commandBarResultsFromNodes(uiRegistry?.snapshot() ?? []);
|
|
172
|
+
if (resource === "app://form") return formSnapshot(formNodes(uiRegistry), isDialogOpen());
|
|
148
173
|
if (resource === "app://capabilities") return pluginRegistry.capabilities.manifests();
|
|
149
174
|
if (resource === "app://auth") return apiClient.describeAuthState();
|
|
150
175
|
if (resource === "app://accounts") return brokerAccountsResource(state);
|
|
151
176
|
if (resource === "app://remote/help") return REMOTE_AGENT_HELP;
|
|
152
|
-
if (resource === "ui://tree") return
|
|
177
|
+
if (resource === "ui://tree") return uiRegistry?.snapshot() ?? [];
|
|
178
|
+
if (resource.startsWith("ui://node/")) {
|
|
179
|
+
const nodeId = decodeURIComponent(resource.slice("ui://node/".length));
|
|
180
|
+
const node = uiRegistry?.detail(nodeId);
|
|
181
|
+
if (!node) throw new Error(`No UI node "${nodeId}" is on screen. Read ui://tree for the current ones.`);
|
|
182
|
+
const pane = node.paneId ? findPaneInstance(state.config.layout, node.paneId) : undefined;
|
|
183
|
+
const paneDef = pane ? pluginRegistry.panes.get(pane.paneId) : undefined;
|
|
184
|
+
return pane && paneDef
|
|
185
|
+
? { ...node, paneTitle: getBasePaneDisplayTitle(state, pane, paneDef, pluginRegistry.panes) }
|
|
186
|
+
: node;
|
|
187
|
+
}
|
|
153
188
|
throw new Error(`Unknown remote resource "${resource}".`);
|
|
154
189
|
};
|
|
155
190
|
|
|
@@ -157,7 +192,9 @@ export function createRemoteResources({
|
|
|
157
192
|
const included = normalizeIncludes(include, defaults);
|
|
158
193
|
if (included.length === 0) return undefined;
|
|
159
194
|
const state = getState();
|
|
160
|
-
|
|
195
|
+
// The whole tree only for what lists from it; the form is read on its own.
|
|
196
|
+
let tree: RemoteUiNodeSnapshot[] | undefined;
|
|
197
|
+
const uiNodes = () => (tree ??= uiRegistry?.snapshot() ?? []);
|
|
161
198
|
const result: RemoteIncludedState = {
|
|
162
199
|
rev: activeLayoutRev(state),
|
|
163
200
|
included,
|
|
@@ -177,16 +214,16 @@ export function createRemoteResources({
|
|
|
177
214
|
}
|
|
178
215
|
if (included.includes("layout")) result.layout = state.config.layout;
|
|
179
216
|
if (included.includes("panes")) {
|
|
180
|
-
result.panes = state.config.layout.instances.map((pane) =>
|
|
217
|
+
result.panes = state.config.layout.instances.map((pane) => paneSummary(state, pane));
|
|
181
218
|
}
|
|
182
219
|
if (included.includes("commandBar") || included.includes("commandBar.results")) {
|
|
183
|
-
const commandBar = commandBarSnapshot(state, uiNodes);
|
|
220
|
+
const commandBar = commandBarSnapshot(state, uiNodes());
|
|
184
221
|
result.commandBar = included.includes("commandBar")
|
|
185
222
|
? commandBar
|
|
186
223
|
: { results: commandBar.results };
|
|
187
224
|
}
|
|
188
|
-
if (included.includes("form")) result.form = formSnapshot(
|
|
189
|
-
if (included.includes("ui")) result.ui = uiNodes;
|
|
225
|
+
if (included.includes("form")) result.form = formSnapshot(formNodes(uiRegistry), isDialogOpen());
|
|
226
|
+
if (included.includes("ui")) result.ui = uiNodes();
|
|
190
227
|
if (included.includes("schema")) result.schema = remoteControlSchema();
|
|
191
228
|
if (included.includes("help")) result.help = REMOTE_AGENT_HELP;
|
|
192
229
|
return result;
|