gloomberb 0.20.3 → 0.20.4

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.
Files changed (154) hide show
  1. package/package.json +1 -1
  2. package/src/account/auth-dialog.tsx +17 -0
  3. package/src/api-client/data.ts +6 -0
  4. package/src/api-client/fx-interventions.ts +64 -0
  5. package/src/api-client/index.ts +1 -0
  6. package/src/api-client/release-summaries.ts +21 -0
  7. package/src/app/keybindings/actions.ts +2 -2
  8. package/src/app/pane-runtime/ticker-open-runtime.ts +245 -66
  9. package/src/cli/commands/market.ts +77 -1
  10. package/src/cli/commands/news-search.ts +1 -3
  11. package/src/cli/commands/plugins.ts +27 -5
  12. package/src/cli/commands/system.ts +19 -3
  13. package/src/cli/commands/ticker.ts +60 -19
  14. package/src/cli/index.ts +8 -8
  15. package/src/cli/pane-functions/function-help.ts +3 -3
  16. package/src/cli/report-tables.ts +18 -6
  17. package/src/cli/result.ts +15 -7
  18. package/src/cli/types.ts +2 -0
  19. package/src/components/chart/composite/axis-overlays.tsx +22 -0
  20. package/src/components/chart/composite/composite-chart.tsx +54 -13
  21. package/src/components/chart/composite/event-captions.ts +109 -0
  22. package/src/components/chart/composite/event-guides.ts +74 -0
  23. package/src/components/chart/composite/rasterizer.ts +2 -0
  24. package/src/components/chart/composite/text-renderer.ts +2 -0
  25. package/src/components/chart/composite/types.ts +31 -0
  26. package/src/components/command-bar/layout-items/focused-pane.ts +5 -5
  27. package/src/components/command-bar/routes/root/provider-search.ts +5 -4
  28. package/src/components/command-bar/routes/ticker-search/results.ts +51 -0
  29. package/src/components/command-bar/routes/ticker-search/route.ts +3 -2
  30. package/src/components/layout/detached-pane-shell.tsx +1 -1
  31. package/src/components/layout/floating-pane.tsx +5 -1
  32. package/src/components/layout/pane/footer/index.tsx +21 -14
  33. package/src/components/layout/pane/footer/model.ts +6 -0
  34. package/src/components/layout/shell/action-menu-overlay.tsx +10 -5
  35. package/src/components/layout/shell/active-drag.ts +149 -105
  36. package/src/components/layout/shell/drag/drop-zones.ts +162 -0
  37. package/src/components/layout/shell/drag/index.ts +47 -218
  38. package/src/components/layout/shell/drag/live.ts +10 -3
  39. package/src/components/layout/shell/drag/overlays.tsx +182 -5
  40. package/src/components/layout/shell/drag/runtime.ts +29 -6
  41. package/src/components/layout/shell/drag/shared-edges.ts +156 -0
  42. package/src/components/layout/shell/index.tsx +11 -6
  43. package/src/components/layout/shell/menu.ts +11 -2
  44. package/src/components/layout/shell/native/pointer-runtime.ts +25 -0
  45. package/src/components/layout/shell/native/window-state.ts +2 -2
  46. package/src/components/layout/shell/pane/layers.tsx +71 -7
  47. package/src/components/layout/shell/terminal-pointer-runtime.ts +18 -9
  48. package/src/components/layout/shell/window-mode/index.ts +8 -10
  49. package/src/components/layout/window-edit/mode.ts +39 -7
  50. package/src/components/layout/window-edit/presentation.ts +1 -1
  51. package/src/components/onboarding/onboarding-keyboard.ts +4 -0
  52. package/src/components/onboarding/onboarding-wizard.tsx +8 -3
  53. package/src/components/ui/button.tsx +2 -0
  54. package/src/components/ui/choice-dialog.tsx +1 -0
  55. package/src/components/ui/data-table/index.tsx +4 -3
  56. package/src/components/ui/list-view.tsx +7 -12
  57. package/src/components/ui/loading.tsx +10 -3
  58. package/src/components/ui/menu.tsx +6 -2
  59. package/src/components/ui/quote.ts +14 -1
  60. package/src/data/config/layout.ts +5 -2
  61. package/src/docs/snapshot.json +29 -5
  62. package/src/i18n/es.ts +9 -8
  63. package/src/i18n/ja.ts +9 -8
  64. package/src/i18n/ko.ts +9 -8
  65. package/src/i18n/zh-cn.ts +9 -8
  66. package/src/i18n/zh-tw.ts +9 -8
  67. package/src/layout/pane-manager/floating-actions.ts +17 -0
  68. package/src/layout/pane-manager/floating-stack.ts +187 -0
  69. package/src/layout/pane-manager/floating.ts +4 -2
  70. package/src/layout/pane-manager/gridlock.ts +5 -1
  71. package/src/layout/pane-manager/index.ts +11 -0
  72. package/src/layout/pane-manager/layout-state.ts +10 -3
  73. package/src/market-data/futures-board.ts +46 -1
  74. package/src/market-data/futures-contract.ts +12 -3
  75. package/src/market-data/fx-interventions.ts +270 -0
  76. package/src/news/news-model.ts +44 -2
  77. package/src/plugins/builtin/alerts/cli.ts +4 -4
  78. package/src/plugins/builtin/alerts/format.ts +1 -2
  79. package/src/plugins/builtin/alerts/headless.ts +1 -2
  80. package/src/plugins/builtin/alerts/move-checks.ts +12 -6
  81. package/src/plugins/builtin/alerts/move.ts +30 -9
  82. package/src/plugins/builtin/alerts/pane.tsx +0 -2
  83. package/src/plugins/builtin/alerts/storage.ts +4 -2
  84. package/src/plugins/builtin/alerts/types.ts +12 -0
  85. package/src/plugins/builtin/changelog/index.tsx +292 -101
  86. package/src/plugins/builtin/changelog/versions.ts +293 -0
  87. package/src/plugins/builtin/chart-composer/intervention-events.ts +105 -0
  88. package/src/plugins/builtin/chart-composer/pane.tsx +21 -7
  89. package/src/plugins/builtin/chat/message/render-state.ts +2 -5
  90. package/src/plugins/builtin/cloud/askg/attached-pane.tsx +10 -5
  91. package/src/plugins/builtin/cloud/askg/controller.ts +141 -5
  92. package/src/plugins/builtin/cloud/askg/executor.ts +113 -4
  93. package/src/plugins/builtin/cloud/askg/manifest.ts +28 -13
  94. package/src/plugins/builtin/cloud/askg/model.ts +14 -4
  95. package/src/plugins/builtin/cloud/askg/pane.tsx +70 -46
  96. package/src/plugins/builtin/cloud/askg/turn-parts.tsx +70 -0
  97. package/src/plugins/builtin/cloud/terminal-relay/engine.ts +50 -130
  98. package/src/plugins/builtin/cloud/terminal-relay/policy.ts +327 -7
  99. package/src/plugins/builtin/cloud/terminal-relay/prompts.tsx +2 -1
  100. package/src/plugins/builtin/cloud/terminal-relay/redact.ts +47 -6
  101. package/src/plugins/builtin/commodities-energy/index.tsx +1 -3
  102. package/src/plugins/builtin/commodities-energy/view-state.ts +3 -0
  103. package/src/plugins/builtin/cot/headless.ts +14 -2
  104. package/src/plugins/builtin/earnings/index.tsx +2 -2
  105. package/src/plugins/builtin/futures/index.tsx +25 -4
  106. package/src/plugins/builtin/futures/model.ts +28 -32
  107. package/src/plugins/builtin/futures/series.ts +4 -3
  108. package/src/plugins/builtin/futures/table.tsx +16 -9
  109. package/src/plugins/builtin/futures/use-board-terms.ts +3 -3
  110. package/src/plugins/builtin/help/index.tsx +3 -3
  111. package/src/plugins/builtin/help/keybindings-editor.tsx +18 -4
  112. package/src/plugins/builtin/layout-manager/index.tsx +8 -8
  113. package/src/plugins/builtin/news/headless.ts +2 -2
  114. package/src/plugins/builtin/news/index.tsx +3 -3
  115. package/src/plugins/builtin/perps/markets-section.tsx +5 -2
  116. package/src/plugins/builtin/plugin-marketplace/pane.tsx +11 -11
  117. package/src/plugins/builtin/portfolio-list/summary/index.tsx +3 -1
  118. package/src/plugins/builtin/research/event-model.ts +9 -1
  119. package/src/plugins/builtin/research/event-sources.ts +22 -0
  120. package/src/plugins/builtin/research/headless.ts +3 -3
  121. package/src/plugins/builtin/shared/cloud-upgrade.ts +27 -3
  122. package/src/plugins/builtin/ticker-detail/overview/components.tsx +54 -5
  123. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +28 -13
  124. package/src/plugins/builtin/ticker-detail/pane.tsx +7 -2
  125. package/src/plugins/installer.ts +45 -0
  126. package/src/remote/resources.ts +12 -1
  127. package/src/remote/schema.ts +1 -0
  128. package/src/remote/semantic-helpers.ts +29 -1
  129. package/src/remote/semantic-tree.tsx +32 -15
  130. package/src/renderers/cloudflare/worker.ts +16 -1
  131. package/src/renderers/dom/styles.css +40 -6
  132. package/src/renderers/share/layout-view.tsx +1 -1
  133. package/src/sources/gloomberb-cloud/news.ts +35 -12
  134. package/src/state/opening-ticker-panes.ts +47 -0
  135. package/src/test-support/cli-context.ts +2 -0
  136. package/src/test-support/preload.ts +4 -1
  137. package/src/tickers/instrument-kind.ts +23 -3
  138. package/src/types/config.ts +5 -0
  139. package/src/types/context-menu.ts +2 -0
  140. package/src/types/plugin-commands.ts +140 -0
  141. package/src/types/plugin-context.ts +125 -0
  142. package/src/types/plugin-contributions.ts +55 -0
  143. package/src/types/plugin-definition.ts +234 -0
  144. package/src/types/plugin-notifications.ts +38 -0
  145. package/src/types/plugin-pane-settings.ts +114 -0
  146. package/src/types/plugin-pane-templates.ts +160 -0
  147. package/src/types/plugin-panes.ts +221 -0
  148. package/src/types/plugin-reports.ts +35 -0
  149. package/src/types/plugin-shared.ts +14 -0
  150. package/src/types/plugin-state.ts +71 -0
  151. package/src/types/plugin.ts +14 -1169
  152. package/src/ui/index.tsx +14 -3
  153. package/src/updater/github-releases.ts +23 -0
  154. package/src/utils/cli-output.ts +22 -9
@@ -4,7 +4,13 @@ import {
4
4
  type ASKGToolResultOutcome,
5
5
  type ASKGTransport,
6
6
  } from "../../../../api-client/askg";
7
- import { toolCallRemainingMs, type ASKGToolExecutor, type ASKGToolPreview } from "./executor";
7
+ import {
8
+ CONFIRMATION_WAITING_NOTE,
9
+ toolCallRemainingMs,
10
+ type ASKGToolExecutor,
11
+ type ASKGToolGate,
12
+ type ASKGToolPreview,
13
+ } from "./executor";
8
14
  import {
9
15
  activeTurn,
10
16
  askgReducer,
@@ -167,6 +173,15 @@ export class ASKGSessionController {
167
173
  private sessionRequest: Promise<ASKGSessionStartResponse> | null = null;
168
174
  private manifest: ASKGControllerManifest | null = null;
169
175
  private readonly confirmations = new Map<string, (answer: ConfirmationAnswer) => void>();
176
+ /**
177
+ * Calls that change the app, or ask first, take turns here (enterLane): each
178
+ * decides whether to ask, asks and runs before the next one starts, so at
179
+ * most one question is ever open and nothing it would press changes under
180
+ * it. Reads run at once.
181
+ */
182
+ private laneTail: Promise<void> = Promise.resolve();
183
+ /** Calls waiting for their turn, by tool call id; a question that opens refuses them. */
184
+ private readonly queued = new Map<string, () => void>();
170
185
  private readonly toolTasks = new Set<Promise<void>>();
171
186
  private turnAbort: AbortController | null = null;
172
187
  /** Ratings of one answer go out in the order they were made. */
@@ -409,11 +424,66 @@ export class ASKGSessionController {
409
424
  return;
410
425
  }
411
426
 
427
+ const refuse = (): Promise<void> => this.deliver({
428
+ turnId: call.turnId,
429
+ toolCallId: call.toolCallId,
430
+ status: "denied",
431
+ truncated: false,
432
+ elapsedMs: Math.max(0, this.now() - startedAt),
433
+ note: CONFIRMATION_WAITING_NOTE,
434
+ });
435
+ // Decided before anything is awaited, so two calls that arrive together
436
+ // take turns in the order they came.
437
+ const exclusive = this.takesTurns(call);
438
+ if (exclusive && this.confirmations.size > 0) {
439
+ await refuse();
440
+ return;
441
+ }
442
+ const turn = exclusive ? this.enterLane(call.toolCallId) : null;
443
+
412
444
  try {
445
+ if (turn && !(await turn.ready)) {
446
+ await refuse();
447
+ return;
448
+ }
449
+ if (signal?.aborted || this.toolRowStatus(call.toolCallId) !== "pending") return;
450
+ // Its turn came after the server stopped waiting for it.
451
+ if (turn && toolCallRemainingMs(call, this.now()) <= 0) {
452
+ await this.deliver({
453
+ turnId: call.turnId,
454
+ toolCallId: call.toolCallId,
455
+ status: "timeout",
456
+ truncated: false,
457
+ elapsedMs: Math.max(0, this.now() - startedAt),
458
+ note: "Tool call timed out.",
459
+ });
460
+ return;
461
+ }
462
+ // A call that acts on what is on screen goes by the policy shared with
463
+ // the terminal relay: a press asks, a scroll does not, and nothing acts
464
+ // on a confirmation or while one waits.
465
+ const gate = await this.gateCall(call, signal);
466
+ if (signal?.aborted || this.toolRowStatus(call.toolCallId) !== "pending") return;
467
+ if (gate?.kind === "refusal") {
468
+ await this.deliver({
469
+ turnId: call.turnId,
470
+ toolCallId: call.toolCallId,
471
+ status: "denied",
472
+ truncated: false,
473
+ elapsedMs: Math.max(0, this.now() - startedAt),
474
+ note: gate.message,
475
+ });
476
+ return;
477
+ }
478
+ // This app's own manifest says which tools ask first, whatever the frame says.
479
+ const asks = requiresLocalConfirmation(call)
480
+ || this.manifest?.tools.find((tool) => tool.name === call.name)?.confirm === "always"
481
+ || gate?.kind === "ask";
413
482
  let confirmed = false;
414
483
  let confirmedChange: string | undefined;
415
- if (requiresLocalConfirmation(call)) {
416
- const preview = await this.previewCall(call, signal);
484
+ if (asks) {
485
+ // A UI action is described by the control it presses; there is no dry run for it.
486
+ const preview = gate?.kind === "ask" ? null : await this.previewCall(call, signal);
417
487
  // The turn ended or moved on while the app looked.
418
488
  if (signal?.aborted || this.toolRowStatus(call.toolCallId) !== "pending") return;
419
489
  if (preview?.kind === "refusal") {
@@ -425,10 +495,14 @@ export class ASKGSessionController {
425
495
  if (preview?.kind === "no-change") {
426
496
  confirmed = true;
427
497
  } else {
498
+ // One question at a time: every call still waiting for its turn is refused.
499
+ this.refuseQueued();
428
500
  this.dispatch({
429
501
  type: "tool-awaiting-confirmation",
430
502
  toolCallId: call.toolCallId,
431
- ...(preview?.kind === "change" ? { preview: preview.summary } : {}),
503
+ ...(gate?.kind === "ask"
504
+ ? { title: gate.title, ...(gate.lines.length > 0 ? { preview: gate.lines.join("\n") } : {}) }
505
+ : preview?.kind === "change" ? { preview: preview.summary } : {}),
432
506
  });
433
507
  const answer = await this.awaitConfirmation(
434
508
  call.toolCallId,
@@ -470,8 +544,10 @@ export class ASKGSessionController {
470
544
  return;
471
545
  }
472
546
  const payload = await executor.execute(call, {
473
- confirmed: confirmed || !requiresLocalConfirmation(call),
547
+ confirmed: confirmed || !asks,
474
548
  ...(confirmedChange ? { confirmedChange } : {}),
549
+ ...(gate ? { gate } : {}),
550
+ promptOpen: () => this.confirmationOpen(call.toolCallId),
475
551
  ...(signal ? { signal } : {}),
476
552
  });
477
553
  await this.deliver(payload);
@@ -481,7 +557,67 @@ export class ASKGSessionController {
481
557
  ));
482
558
  } finally {
483
559
  this.confirmations.delete(call.toolCallId);
560
+ turn?.leave();
561
+ }
562
+ }
563
+
564
+ /**
565
+ * Whether a call takes turns with the others: anything but a read this
566
+ * app's manifest knows, and anything that asks first. A tool the manifest
567
+ * does not know waits its turn too; the executor refuses it anyway.
568
+ */
569
+ private takesTurns(call: ASKGToolCallEvent): boolean {
570
+ const tool = this.manifest?.tools.find((entry) => entry.name === call.name);
571
+ return !tool
572
+ || tool.writeTier !== "read"
573
+ || call.writeTier !== "read"
574
+ || tool.confirm === "always"
575
+ || requiresLocalConfirmation(call);
576
+ }
577
+
578
+ /** Queues a call behind the ones before it; `ready` is false when a question opened while it waited. */
579
+ private enterLane(toolCallId: string): { ready: Promise<boolean>; leave: () => void } {
580
+ const ahead = this.laneTail;
581
+ let leave!: () => void;
582
+ const left = new Promise<void>((resolve) => {
583
+ leave = resolve;
584
+ });
585
+ this.laneTail = ahead.then(() => left);
586
+ const ready = new Promise<boolean>((resolve) => {
587
+ this.queued.set(toolCallId, () => resolve(false));
588
+ void ahead.then(() => {
589
+ this.queued.delete(toolCallId);
590
+ resolve(true);
591
+ });
592
+ });
593
+ return { ready, leave };
594
+ }
595
+
596
+ private refuseQueued(): void {
597
+ for (const refuse of this.queued.values()) refuse();
598
+ this.queued.clear();
599
+ }
600
+
601
+ /**
602
+ * The shared policy's word on a call that acts on what is on screen or a
603
+ * confirmed operation it describes; null for any other call. Throws when
604
+ * it cannot tell, and the call does not run.
605
+ */
606
+ private async gateCall(call: ASKGToolCallEvent, signal?: AbortSignal): Promise<ASKGToolGate | null> {
607
+ const manifest = this.manifest ?? await this.options.loadManifest();
608
+ this.manifest = manifest;
609
+ return await this.options.getExecutor(manifest)?.gate(call, {
610
+ promptOpen: this.confirmationOpen(call.toolCallId),
611
+ ...(signal ? { signal } : {}),
612
+ }) ?? null;
613
+ }
614
+
615
+ /** A confirmation other than this call's waits for the person. */
616
+ private confirmationOpen(toolCallId: string): boolean {
617
+ for (const pending of this.confirmations.keys()) {
618
+ if (pending !== toolCallId) return true;
484
619
  }
620
+ return false;
485
621
  }
486
622
 
487
623
  /**
@@ -22,6 +22,12 @@ import {
22
22
  type ToolResultStatus,
23
23
  } from "./protocol";
24
24
  import { normalizeJson } from "./json";
25
+ import {
26
+ redactRelayResult,
27
+ redactResource,
28
+ storedCredentials,
29
+ withoutStoredCredentials,
30
+ } from "../terminal-relay/redact";
25
31
  import {
26
32
  capToolNote,
27
33
  joinToolNotes,
@@ -33,6 +39,7 @@ import {
33
39
  remoteRequestForTool,
34
40
  resolveRemoteToolBinding,
35
41
  toolExecutionTimeoutMs,
42
+ type RemoteToolBinding,
36
43
  } from "./manifest";
37
44
  import {
38
45
  ASKGUndoManager,
@@ -40,6 +47,7 @@ import {
40
47
  type InProcessRemoteControlHandler,
41
48
  } from "./undo";
42
49
  import { logFailure } from "../../../../utils/log-failure";
50
+ import { describeConfirmedOperation, planUiCall, UiCallRefusal, type UiCallPlan } from "../terminal-relay/policy";
43
51
 
44
52
  interface HeadlessExecution {
45
53
  result: unknown;
@@ -68,11 +76,33 @@ export interface ASKGToolExecutorDependencies {
68
76
 
69
77
  interface ASKGToolExecutionOptions {
70
78
  signal?: AbortSignal;
79
+ /** The person approved this call (or a dry run found nothing to approve). */
71
80
  confirmed?: boolean;
72
81
  /** The confirmKey of the preview the person approved, so the app does not ask again. */
73
82
  confirmedChange?: string;
83
+ /** The gate the call was asked about with, checked again right before it runs. */
84
+ gate?: ASKGToolGate;
85
+ /** One of Ask Gloom's confirmations waits for the person. */
86
+ promptOpen?: () => boolean;
74
87
  }
75
88
 
89
+ /**
90
+ * What the per-operation policy shared with the terminal relay
91
+ * (terminal-relay/policy.ts) says about a call that acts on what is on
92
+ * screen (a press, a submit, a command-bar row), or about a confirmed
93
+ * operation it describes (a layout delete, by the layout's name).
94
+ */
95
+ export type ASKGToolGate =
96
+ /** Refused before anything is asked: it aims at a confirmation, or one is open. */
97
+ | { kind: "refusal"; message: string }
98
+ /** Scroll, select, setValue, focus, a row that opens a ticker or a pane. */
99
+ | { kind: "silent"; recheck: UiCallPlan["recheck"] }
100
+ /** Asks first, naming the control and its pane, the row it opens, or the layout it deletes. */
101
+ | { kind: "ask"; title: string; lines: string[]; recheck: UiCallPlan["recheck"] };
102
+
103
+ /** Why a call that changes the app did not run while one of Ask Gloom's questions waited (controller.ts). */
104
+ export const CONFIRMATION_WAITING_NOTE = "Gloom is waiting for the person to answer a confirmation, and nothing else that changes the app runs until then. This call did not run; retry it after they answer.";
105
+
76
106
  /**
77
107
  * What a call needing approval will change, from the operation's own dry run:
78
108
  * the list and listing it resolved rather than the arguments as sent.
@@ -95,6 +125,11 @@ export interface ASKGToolExecutor {
95
125
  ): Promise<ToolResultPayload>;
96
126
  /** Null when the call has no dry run that says more than its arguments. */
97
127
  preview?(call: ASKGToolCallEvent, signal?: AbortSignal): Promise<ASKGToolPreview | null>;
128
+ /**
129
+ * Null when the policy has nothing to add for the call. Throws when it
130
+ * cannot tell (the screen could not be read): the call does not run.
131
+ */
132
+ gate(call: ASKGToolCallEvent, options: { promptOpen: boolean; signal?: AbortSignal }): Promise<ASKGToolGate | null>;
98
133
  undo(token: string, signal?: AbortSignal): Promise<AppliedUndo>;
99
134
  }
100
135
 
@@ -238,6 +273,15 @@ function inferRemoteRowCount(value: unknown): number | undefined {
238
273
  return 1;
239
274
  }
240
275
 
276
+ /**
277
+ * An app resource or operation result as an assistant may read it, by the
278
+ * same rules as the terminal relay: configuration without its credentials
279
+ * and broker settings, and no secret-named or typed-password value anywhere.
280
+ */
281
+ function redactRemoteData(binding: RemoteToolBinding, args: Record<string, JsonValue>, data: unknown): unknown {
282
+ return redactRelayResult(binding.kind === "resource" ? redactResource(String(args.resource), data) : data);
283
+ }
284
+
241
285
  /**
242
286
  * How much longer the server waits for this call, by its frame: its timeout,
243
287
  * and never past the time it expires.
@@ -342,20 +386,67 @@ export function createASKGToolExecutor(
342
386
  ?? defaultHeadlessExecutor(dependencies.registry, dependencies.context);
343
387
  const undoManager = dependencies.undoManager ?? new ASKGUndoManager(dependencies.remoteHandler);
344
388
 
389
+ const readResource = async (resource: string, signal?: AbortSignal): Promise<unknown> => {
390
+ const response = await runWithDeadline(
391
+ () => dependencies.remoteHandler({ type: "get", resource }),
392
+ PREVIEW_TIMEOUT_MS,
393
+ signal,
394
+ );
395
+ if (!response.ok) throw new Error(response.error.message);
396
+ return response.data;
397
+ };
398
+
399
+ const gate = async (
400
+ call: ASKGToolCallEvent,
401
+ { promptOpen, signal }: { promptOpen: boolean; signal?: AbortSignal },
402
+ ): Promise<ASKGToolGate | null> => {
403
+ if (manifests.get(call.name)?.source !== "remote-op") return null;
404
+ const binding = resolveRemoteToolBinding(call.name);
405
+ if (binding?.kind !== "operation") return null;
406
+ const read = (resource: string) => readResource(resource, signal);
407
+ try {
408
+ const plan = await planUiCall(binding.operation, call.args, { read, promptOpen });
409
+ if (plan) {
410
+ return plan.confirm
411
+ ? {
412
+ kind: "ask",
413
+ title: plan.confirm.title,
414
+ lines: plan.confirm.lines.map(({ label, value }) => `${label}: ${value}`),
415
+ recheck: plan.recheck,
416
+ }
417
+ : { kind: "silent", recheck: plan.recheck };
418
+ }
419
+ const described = await describeConfirmedOperation(binding.operation, call.args, read);
420
+ if (!described) return null;
421
+ const recheck = described.recheck;
422
+ return {
423
+ kind: "ask",
424
+ title: described.confirm.title,
425
+ lines: described.confirm.lines.map(({ label, value }) => `${label}: ${value}`),
426
+ recheck: async () => (recheck ? recheck() : null),
427
+ };
428
+ } catch (error) {
429
+ if (error instanceof UiCallRefusal) return { kind: "refusal", message: error.message };
430
+ throw error;
431
+ }
432
+ };
433
+
345
434
  const execute = async (
346
435
  call: ASKGToolCallEvent,
347
436
  options: ASKGToolExecutionOptions = {},
348
437
  ): Promise<ToolResultPayload> => {
349
438
  const startedAt = now();
439
+ // Whatever leaves the app, a pane function's rows included, without a credential the config stores.
440
+ const credentials = storedCredentials(dependencies.context?.config);
350
441
  const base = (value: ExecutionValue): ToolResultPayload => withBoundedPayload({
351
442
  turnId: call.turnId,
352
443
  toolCallId: call.toolCallId,
353
444
  status: value.status,
354
- ...(value.result !== undefined ? { result: normalizeJson(value.result) } : {}),
445
+ ...(value.result !== undefined ? { result: withoutStoredCredentials(normalizeJson(value.result), credentials) } : {}),
355
446
  ...(value.rowCount !== undefined ? { rowCount: value.rowCount } : {}),
356
447
  truncated: value.truncated ?? false,
357
448
  elapsedMs: Math.max(0, now() - startedAt),
358
- ...(value.note ? { note: capToolNote(value.note) } : {}),
449
+ ...(value.note ? { note: capToolNote(withoutStoredCredentials(value.note, credentials)) } : {}),
359
450
  ...(value.rev ? { rev: value.rev } : {}),
360
451
  ...(value.undoToken ? { undoToken: value.undoToken } : {}),
361
452
  });
@@ -373,6 +464,17 @@ export function createASKGToolExecutor(
373
464
  if ((manifest.confirm === "always" || call.requiresConfirmation) && !options.confirmed) {
374
465
  return base({ status: "denied", note: "This tool call requires local confirmation." });
375
466
  }
467
+ const promptOpen = () => options.promptOpen?.() ?? false;
468
+ let screenGate: ASKGToolGate | null;
469
+ try {
470
+ screenGate = options.gate ?? await gate(call, { promptOpen: promptOpen(), ...(options.signal ? { signal: options.signal } : {}) });
471
+ } catch (error) {
472
+ return base({ status: "error", note: toolErrorNote(error) });
473
+ }
474
+ if (screenGate?.kind === "refusal") return base({ status: "denied", note: screenGate.message });
475
+ if (screenGate?.kind === "ask" && !options.confirmed) {
476
+ return base({ status: "denied", note: "This tool call requires local confirmation." });
477
+ }
376
478
 
377
479
  const timeoutMs = Math.min(toolExecutionTimeoutMs(manifest), toolCallRemainingMs(call, now()));
378
480
  try {
@@ -403,6 +505,12 @@ export function createASKGToolExecutor(
403
505
  }
404
506
  }
405
507
 
508
+ // The last look before it acts: the screen may have changed while the person decided.
509
+ const stale = await screenGate?.recheck(promptOpen());
510
+ if (stale) return { status: "denied", note: stale };
511
+ // Nothing that changes the app runs while one of Ask Gloom's questions waits.
512
+ if (manifest.writeTier !== "read" && promptOpen()) return { status: "denied", note: CONFIRMATION_WAITING_NOTE };
513
+
406
514
  const response = await dependencies.remoteHandler(remoteRequestForTool(binding, call.args), {
407
515
  signal,
408
516
  ...(options.confirmed && options.confirmedChange ? { confirmed: options.confirmedChange } : {}),
@@ -410,7 +518,7 @@ export function createASKGToolExecutor(
410
518
  if (!response.ok) {
411
519
  return {
412
520
  status: "error",
413
- result: { code: response.error.code, ...(response.error.details !== undefined ? { details: response.error.details } : {}) },
521
+ result: redactRemoteData(binding, call.args, { code: response.error.code, ...(response.error.details !== undefined ? { details: response.error.details } : {}) }),
414
522
  note: toolErrorNote(response.error.message),
415
523
  };
416
524
  }
@@ -425,7 +533,7 @@ export function createASKGToolExecutor(
425
533
  }
426
534
  return {
427
535
  status: "ok",
428
- result: response.data,
536
+ result: redactRemoteData(binding, call.args, response.data),
429
537
  rowCount: inferRemoteRowCount(response.data),
430
538
  ...(undoNote ? { note: undoNote } : {}),
431
539
  ...(response.rev ? { rev: response.rev } : response.state?.rev ? { rev: response.state.rev } : {}),
@@ -471,6 +579,7 @@ export function createASKGToolExecutor(
471
579
  return {
472
580
  execute,
473
581
  preview,
582
+ gate,
474
583
  undo: (token, signal) => undoManager.undo(token, signal),
475
584
  };
476
585
  }
@@ -8,6 +8,7 @@ import {
8
8
  remoteOperationToolName,
9
9
  } from "../../../../remote/schema";
10
10
  import type { RemoteControlRequest } from "../../../../remote/types";
11
+ import { operationPolicy } from "../terminal-relay/policy";
11
12
  import type {
12
13
  HeadlessPaneDefinition,
13
14
  PaneDef,
@@ -29,7 +30,8 @@ const REMOTE_TOOL_TIMEOUT_MS = 10_000;
29
30
  /**
30
31
  * A tool that asks first waits for a person to read the prompt and click, so
31
32
  * the server holds the call this long: the minute the terminal relay gives a
32
- * confirmation. A server from before the window holds it 10 s.
33
+ * confirmation. A UI action that may ask declares it too. A server from
34
+ * before the window holds either 10 s.
33
35
  */
34
36
  const CONFIRM_TOOL_TIMEOUT_MS = 60_000;
35
37
  const REMOTE_RESOURCE_TOOL_NAME = "app.get_resource";
@@ -193,7 +195,7 @@ function remoteCandidates(registry: PaneFunctionCatalog): ManifestCandidate[] {
193
195
  description: descriptor.description,
194
196
  writeTier: descriptor.writeTier,
195
197
  inputSchema: descriptor.inputSchema,
196
- ...remoteConfirmation(descriptor.writeTier),
198
+ ...remoteConfirmation(operationsByName.get(descriptor.name)!.id, descriptor.writeTier),
197
199
  },
198
200
  }));
199
201
 
@@ -226,21 +228,34 @@ function remoteCandidates(registry: PaneFunctionCatalog): ManifestCandidate[] {
226
228
  return candidates;
227
229
  }
228
230
 
229
- /** Account and broker writes ask first, and get the minute that takes. */
230
- function remoteConfirmation(writeTier: ClientToolManifest["writeTier"]): Pick<ClientToolManifest, "confirm" | "timeoutMs"> {
231
- return writeTier === "user-data" || writeTier === "broker"
232
- ? { confirm: "always", timeoutMs: CONFIRM_TOOL_TIMEOUT_MS }
233
- : { confirm: "never", timeoutMs: REMOTE_TOOL_TIMEOUT_MS };
231
+ /**
232
+ * Account and broker writes ask first, and so does every operation the
233
+ * per-operation policy confirms each time (terminal-relay/policy.ts); they get
234
+ * the minute that takes. A UI action is asked about call by call instead
235
+ * (executor.ts), since scrolling or selecting asks nothing, so it says
236
+ * `never` and still declares the minute: the server holds it that long, and
237
+ * a scroll answers as soon as it ran.
238
+ */
239
+ function remoteConfirmation(
240
+ operation: string,
241
+ writeTier: ClientToolManifest["writeTier"],
242
+ ): Pick<ClientToolManifest, "confirm" | "timeoutMs"> {
243
+ const { policy } = operationPolicy(operation);
244
+ if (writeTier === "user-data" || writeTier === "broker" || policy === "confirm") {
245
+ return { confirm: "always", timeoutMs: CONFIRM_TOOL_TIMEOUT_MS };
246
+ }
247
+ if (policy === "local-ui" || policy === "navigation") return { confirm: "never", timeoutMs: CONFIRM_TOOL_TIMEOUT_MS };
248
+ return { confirm: "never", timeoutMs: REMOTE_TOOL_TIMEOUT_MS };
234
249
  }
235
250
 
236
251
  /**
237
- * How long a call may run once it starts. A tool that asks first declares the
238
- * window for the person and the write together; the write itself keeps the
239
- * budget of every app action, counted from the approval rather than from the
240
- * call. The server's deadline for the call still bounds it.
252
+ * How long a call may run once it starts. A tool that may ask first declares
253
+ * the window for the person and the action together; an app action itself
254
+ * keeps the budget of every app action, counted from the approval rather
255
+ * than from the call. The server's deadline for the call still bounds it.
241
256
  */
242
- export function toolExecutionTimeoutMs(manifest: Pick<ClientToolManifest, "confirm" | "timeoutMs">): number {
243
- return manifest.confirm === "always"
257
+ export function toolExecutionTimeoutMs(manifest: Pick<ClientToolManifest, "confirm" | "source" | "timeoutMs">): number {
258
+ return manifest.confirm === "always" || manifest.source === "remote-op"
244
259
  ? Math.min(manifest.timeoutMs, REMOTE_TOOL_TIMEOUT_MS)
245
260
  : manifest.timeoutMs;
246
261
  }
@@ -50,6 +50,11 @@ export interface ASKGToolRow {
50
50
  requiresConfirmation: boolean;
51
51
  /** Dry run description shown before a `user-data` or `broker` call runs. */
52
52
  preview?: JsonValue;
53
+ /**
54
+ * What the approval asks, when the call says more than its tool: the
55
+ * control a UI action presses, by label and role.
56
+ */
57
+ confirmTitle?: string;
53
58
  rowCount?: number;
54
59
  elapsedMs?: number;
55
60
  truncated?: boolean;
@@ -152,8 +157,11 @@ export type ASKGAction =
152
157
  | { type: "feedback"; turnId: string; feedback: ASKGTurnFeedback | null }
153
158
  | { type: "feedback-unavailable" }
154
159
  | { type: "event"; event: ASKGSseEvent }
155
- /** `preview` is what the app resolved the call to, in place of the server's account of its arguments. */
156
- | { type: "tool-awaiting-confirmation"; toolCallId: string; preview?: string }
160
+ /**
161
+ * `preview` is what the app resolved the call to, in place of the server's
162
+ * account of its arguments; `title` names what a UI action will press.
163
+ */
164
+ | { type: "tool-awaiting-confirmation"; toolCallId: string; preview?: string; title?: string }
157
165
  | { type: "tool-running"; toolCallId: string }
158
166
  | { type: "tool-result"; payload: ToolResultPayload }
159
167
  | { type: "tool-expanded"; toolCallId: string; expanded: boolean }
@@ -166,8 +174,9 @@ export type ASKGAction =
166
174
  | { type: "reset" };
167
175
 
168
176
  /**
169
- * Tiers that never run without the user saying so. `read` is silent and
170
- * `ui-write` is reversible, so only account and broker writes stop the turn.
177
+ * Tiers that never run without the user saying so. `read` is silent; a
178
+ * `ui-write` call that presses something on screen is asked about call by
179
+ * call (executor.ts gate), the rest of `ui-write` is reversible.
171
180
  */
172
181
  export function requiresLocalConfirmation(call: {
173
182
  writeTier: WriteTier;
@@ -483,6 +492,7 @@ export function askgReducer(
483
492
  ...row,
484
493
  status: "awaiting-confirmation",
485
494
  ...(action.preview !== undefined ? { preview: action.preview } : {}),
495
+ ...(action.title !== undefined ? { confirmTitle: action.title } : {}),
486
496
  }));
487
497
  case "tool-running":
488
498
  return patchToolRow(state, action.toolCallId, (row) => ({ ...row, status: "running" }));