@timurproko/a1 0.2.7-dev.820 → 0.2.7-dev.828

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 (157) hide show
  1. package/README.md +7 -1
  2. package/bin/automatic-update.js +7 -0
  3. package/bin/tab-launch-context.d.ts +1 -0
  4. package/bin/tab-launch-context.js +3 -3
  5. package/bin/ui.js +96 -66
  6. package/dist/app/session-shell/session-shell-root.d.ts +13 -6
  7. package/dist/app/session-shell/session-shell-root.js +9 -5
  8. package/dist/app/session-shell/session-shell.js +68 -18
  9. package/dist/app/session-shell/shell-host.js +6 -3
  10. package/dist/app/session-shell/transcript-document.js +1 -1
  11. package/dist/cli/tabs.d.ts +1 -1
  12. package/dist/cli/tabs.js +10 -14
  13. package/dist/composition/owned-settings.d.ts +12 -0
  14. package/dist/composition/owned-settings.js +36 -0
  15. package/dist/composition/owned-ui.d.ts +5 -14
  16. package/dist/composition/owned-ui.js +93 -63
  17. package/dist/composition/resident-tab-bridge.d.ts +10 -1
  18. package/dist/composition/resident-tab-bridge.js +21 -0
  19. package/dist/composition/settings-route-host.d.ts +12 -2
  20. package/dist/composition/settings-route-host.js +27 -9
  21. package/dist/composition/settings-search-input.d.ts +9 -0
  22. package/dist/composition/settings-search-input.js +58 -0
  23. package/dist/composition/utility-tab.d.ts +28 -0
  24. package/dist/composition/utility-tab.js +242 -0
  25. package/dist/contracts/owned-ui/session-backend.d.ts +2 -0
  26. package/dist/contracts/owned-ui/session-workflows.d.ts +7 -3
  27. package/dist/contracts/presentation/index.d.ts +11 -0
  28. package/dist/contracts/presentation/index.js +12 -0
  29. package/dist/features/launch/development-launch.js +6 -0
  30. package/dist/features/launch/profile-paths.js +4 -0
  31. package/dist/features/owned-ui/plus-menu-dialog.d.ts +22 -0
  32. package/dist/features/owned-ui/plus-menu-dialog.js +76 -0
  33. package/dist/features/owned-ui/project-trust-dialog.d.ts +1 -1
  34. package/dist/features/owned-ui/project-trust-dialog.js +6 -8
  35. package/dist/features/owned-ui/project-trust-prompt.d.ts +1 -0
  36. package/dist/features/owned-ui/project-trust-prompt.js +7 -3
  37. package/dist/features/owned-ui/reference-screen-app.d.ts +2 -0
  38. package/dist/features/owned-ui/reference-screen-app.js +12 -2
  39. package/dist/features/owned-ui/settings-app.d.ts +10 -3
  40. package/dist/features/owned-ui/settings-app.js +98 -45
  41. package/dist/features/owned-ui/settings-search-input.d.ts +29 -0
  42. package/dist/features/owned-ui/settings-search-input.js +1 -0
  43. package/dist/features/prompt-history/index.d.ts +1 -1
  44. package/dist/features/prompt-history/paths.d.ts +2 -1
  45. package/dist/features/prompt-history/paths.js +10 -2
  46. package/dist/features/prompt-history/service.d.ts +5 -0
  47. package/dist/features/prompt-history/service.js +1 -1
  48. package/dist/features/resident-tab/shortcut-declarations.d.ts +1 -1
  49. package/dist/features/resident-tab/shortcut-declarations.js +2 -0
  50. package/dist/foundation/launch-context/index.d.ts +2 -0
  51. package/dist/foundation/launch-context/index.js +1 -0
  52. package/dist/foundation/lifecycle/session-repository-context.js +16 -2
  53. package/dist/foundation/release/automatic-update.d.ts +37 -0
  54. package/dist/foundation/release/automatic-update.js +265 -0
  55. package/dist/foundation/release/bootstrap.d.ts +1 -9
  56. package/dist/foundation/release/bootstrap.js +7 -3
  57. package/dist/foundation/release/early-accent.d.ts +12 -0
  58. package/dist/foundation/release/early-accent.js +59 -0
  59. package/dist/foundation/release/index.d.ts +1 -1
  60. package/dist/foundation/release/index.js +1 -1
  61. package/dist/foundation/release/latest-release.d.ts +3 -2
  62. package/dist/foundation/release/latest-release.js +1 -1
  63. package/dist/foundation/release/progress-palette.generated.d.ts +137 -3
  64. package/dist/foundation/release/progress-palette.generated.js +137 -3
  65. package/dist/foundation/release/release-gc.js +19 -4
  66. package/dist/foundation/release/update-execution-lease.d.ts +36 -0
  67. package/dist/foundation/release/update-execution-lease.js +145 -0
  68. package/dist/foundation/release/update.d.ts +9 -7
  69. package/dist/foundation/release/update.js +244 -175
  70. package/dist/foundation/resident-tabs/bridge-client.d.ts +9 -2
  71. package/dist/foundation/resident-tabs/bridge-client.js +19 -7
  72. package/dist/foundation/resident-tabs/maintenance.d.ts +2 -6
  73. package/dist/foundation/resident-tabs/maintenance.js +5 -23
  74. package/dist/foundation/resident-tabs/progress-observation-schema.d.ts +34 -0
  75. package/dist/foundation/resident-tabs/progress-observation-schema.js +1 -0
  76. package/dist/foundation/resident-tabs/progress-observation.d.ts +3 -6
  77. package/dist/foundation/resident-tabs/progress-observation.js +43 -12
  78. package/dist/foundation/resident-tabs/release-holds.js +3 -14
  79. package/dist/foundation/resident-tabs/routes.d.ts +5 -0
  80. package/dist/foundation/resident-tabs/routes.js +5 -0
  81. package/dist/integrations/pi/components/editor-interaction.d.ts +2 -0
  82. package/dist/integrations/pi/components/modal-frame.d.ts +17 -1
  83. package/dist/integrations/pi/components/modal-frame.js +48 -9
  84. package/dist/integrations/pi/components/models-dialog.js +4 -52
  85. package/dist/integrations/pi/components/owned-editor-ux.d.ts +3 -0
  86. package/dist/integrations/pi/components/owned-editor-ux.js +75 -4
  87. package/dist/integrations/pi/components/shell-editor-autocomplete.js +57 -37
  88. package/dist/integrations/pi/components/shell-footer-status.js +19 -3
  89. package/dist/integrations/pi/components/shell-presenters-transcript.js +4 -1
  90. package/dist/integrations/pi/components/shell-selectors-dialogs.js +4 -1
  91. package/dist/integrations/pi/components/shell-shared-facade.d.ts +9 -2
  92. package/dist/integrations/pi/components/skills-dialog.js +2 -2
  93. package/dist/integrations/pi/components/upstream/components/owned-editor.d.ts +7 -5
  94. package/dist/integrations/pi/components/upstream/components/owned-editor.js +15 -8
  95. package/dist/integrations/pi/components/upstream/components/scoped-models-selector.d.ts +3 -3
  96. package/dist/integrations/pi/components/upstream/components/scoped-models-selector.js +2 -2
  97. package/dist/integrations/pi/components/upstream/components/session-footer.js +26 -23
  98. package/dist/integrations/pi/components/upstream/components/session-selector.js +7 -6
  99. package/dist/integrations/pi/components/upstream/components/thinking-selector.d.ts +7 -6
  100. package/dist/integrations/pi/components/upstream/components/thinking-selector.js +9 -8
  101. package/dist/integrations/pi/components/upstream/components/tool-execution.js +6 -4
  102. package/dist/integrations/pi/components/upstream/components/tree-selector.d.ts +8 -8
  103. package/dist/integrations/pi/components/upstream/components/tree-selector.js +10 -10
  104. package/dist/integrations/pi/components/upstream/history/editor-core.js +2 -0
  105. package/dist/integrations/pi/components/upstream/theme/theme.d.ts +2 -0
  106. package/dist/integrations/pi/components/upstream/theme/theme.js +5 -1
  107. package/dist/integrations/pi/engine/adapter.js +7 -2
  108. package/dist/integrations/pi/engine/offline-settings-port.d.ts +23 -0
  109. package/dist/integrations/pi/engine/offline-settings-port.js +53 -0
  110. package/dist/integrations/pi/engine/ports.d.ts +1 -1
  111. package/dist/integrations/pi/engine/ports.js +4 -0
  112. package/dist/integrations/pi/engine/settings-bridge.d.ts +5 -0
  113. package/dist/integrations/pi/engine/settings-bridge.js +13 -0
  114. package/dist/integrations/pi/engine/settings-port.js +1 -14
  115. package/dist/integrations/pi/engine/workflow-runner.js +9 -2
  116. package/dist/native/darwin-arm64/manifest.json +1 -1
  117. package/dist/native/darwin-arm64/terminal-host.manifest.json +3 -3
  118. package/dist/native/darwin-arm64/terminal-host.node +0 -0
  119. package/dist/native/darwin-x64/manifest.json +1 -1
  120. package/dist/native/darwin-x64/terminal-host.manifest.json +3 -3
  121. package/dist/native/darwin-x64/terminal-host.node +0 -0
  122. package/dist/native/linux-x64/manifest.json +1 -1
  123. package/dist/native/linux-x64/terminal-host.manifest.json +3 -3
  124. package/dist/native/linux-x64/terminal-host.node +0 -0
  125. package/dist/native/win32-x64/manifest.json +2 -2
  126. package/dist/native/win32-x64/process-guardian.node +0 -0
  127. package/dist/native/win32-x64/terminal-host.manifest.json +3 -3
  128. package/dist/native/win32-x64/terminal-host.node +0 -0
  129. package/dist/product-identity.d.ts +1 -1
  130. package/dist/product-identity.js +2 -2
  131. package/dist/product-identity.json +2 -0
  132. package/dist/ui/apps/host.d.ts +2 -0
  133. package/dist/ui/apps/host.js +7 -1
  134. package/dist/ui/components/dialog-panel.js +35 -30
  135. package/dist/ui/components/line-input.d.ts +3 -0
  136. package/dist/ui/components/line-input.js +3 -1
  137. package/dist/ui/components/prompt-input.d.ts +3 -2
  138. package/dist/ui/components/prompt-input.js +6 -4
  139. package/dist/ui/components/spans.js +2 -2
  140. package/dist/ui/components/surface.js +4 -2
  141. package/dist/ui/components/text.d.ts +3 -6
  142. package/dist/ui/components/text.js +6 -8
  143. package/dist/ui/settings/declarations.d.ts +56 -10
  144. package/dist/ui/settings/declarations.js +38 -9
  145. package/dist/ui/settings/early-accent.d.ts +81 -0
  146. package/dist/ui/settings/early-accent.js +50 -0
  147. package/dist/ui/settings/manager.js +7 -3
  148. package/dist/ui/settings/migrations.js +15 -0
  149. package/dist/ui/settings/progress-palette.generated.d.ts +139 -0
  150. package/dist/ui/settings/progress-palette.generated.js +139 -0
  151. package/dist/ui/settings/sections.d.ts +4 -0
  152. package/dist/ui/settings/sections.js +9 -3
  153. package/docs/architecture/resident-tabs.md +48 -17
  154. package/docs/architecture/tool-image-presentation.md +2 -1
  155. package/docs/features/prompt-history.md +41 -20
  156. package/docs/validation.md +25 -5
  157. package/package.json +1 -1
@@ -21,7 +21,7 @@ export interface MaintenanceOptions {
21
21
  readonly profileRoot: string;
22
22
  readonly dataDir: string;
23
23
  readonly runtimeDir: string;
24
- /** Installed release roots whose verified terminal host may run maintenance, in preference order. */
24
+ /** The first root is the invoking release; other roots never substitute for it. */
25
25
  readonly releaseRoots: readonly string[];
26
26
  readonly environment: NodeJS.ProcessEnv;
27
27
  readonly platform?: NodeJS.Platform;
@@ -33,11 +33,7 @@ export interface MaintenanceOptions {
33
33
  readonly stdout: string;
34
34
  }>;
35
35
  }
36
- /**
37
- * Runs one maintenance form through a verified terminal host. When the running host speaks
38
- * another protocol generation, it retries once with the addon from the release that host
39
- * recorded, after verifying that release's manifest; it never loads an unverified addon.
40
- */
36
+ /** Runs maintenance only through the invoking release; another cohort is never a retry target. */
41
37
  export declare function runTerminalHostMaintenance(options: MaintenanceOptions): Promise<MaintenanceReport>;
42
38
  /** The largest maintenance report accepted from the terminal host. */
43
39
  export declare const MAX_MAINTENANCE_REPORT_BYTES: number;
@@ -4,26 +4,14 @@ import { PRODUCT_IDENTITY } from "../../product-identity.js";
4
4
  import { runBoundedHostCommand } from "./bounded-host-command.js";
5
5
  import { resolveTerminalHostEntryPath, resolveTerminalHostPath } from "./ensure-terminal-host.js";
6
6
  import { verifyTerminalHostArtifact } from "./terminal-host-artifact.js";
7
- const INCOMPATIBLE_EXIT = 4;
8
- /**
9
- * Runs one maintenance form through a verified terminal host. When the running host speaks
10
- * another protocol generation, it retries once with the addon from the release that host
11
- * recorded, after verifying that release's manifest; it never loads an unverified addon.
12
- */
7
+ /** Runs maintenance only through the invoking release; another cohort is never a retry target. */
13
8
  export async function runTerminalHostMaintenance(options) {
14
9
  const platform = options.platform ?? process.platform;
15
10
  const architecture = options.architecture ?? process.arch;
16
- const command = await firstVerifiedHost(options, options.releaseRoots, platform, architecture);
11
+ const command = await firstVerifiedHost(options, options.releaseRoots.slice(0, 1), platform, architecture);
17
12
  if (command === undefined)
18
- return unavailable(options.action, "no verified terminal host is installed");
19
- const report = await invoke(options, command);
20
- if (report.exitCode !== INCOMPATIBLE_EXIT || typeof report.releaseRoot !== "string")
21
- return report;
22
- const cohort = await firstVerifiedHost({ ...options, environment: {} }, [report.releaseRoot], platform, architecture);
23
- if (cohort === undefined || cohort.entry === command.entry) {
24
- return { ...report, message: "the running tabs use another version whose terminal host cannot be verified" };
25
- }
26
- return await invoke({ ...options, environment: installedEnvironment(options.environment) }, cohort);
13
+ return unavailable(options.action, "the invoking release has no verified terminal host");
14
+ return await invoke(options, command);
27
15
  }
28
16
  function arguments_(options) {
29
17
  const command = options.action === "stop" ? ["stop", options.tabId ?? ""] : [options.action];
@@ -67,17 +55,11 @@ async function firstVerifiedHost(options, roots, platform, architecture) {
67
55
  return { executable: process.execPath, entry: resolveTerminalHostEntryPath(root) };
68
56
  }
69
57
  catch {
70
- // Rationale: an older retained release may predate the packaged host; try the next one.
58
+ // Invariant: a missing or altered invoking artifact fails closed.
71
59
  }
72
60
  }
73
61
  return undefined;
74
62
  }
75
- function installedEnvironment(environment) {
76
- const sanitized = { ...environment };
77
- delete sanitized[PRODUCT_IDENTITY.environment.developmentInstanceId];
78
- delete sanitized[PRODUCT_IDENTITY.environment.terminalHostPath];
79
- return sanitized;
80
- }
81
63
  function unavailable(action, message) {
82
64
  return { schema: "a1-tabs-maintenance-v1", command: action, host: "unavailable", message, exitCode: 3 };
83
65
  }
@@ -0,0 +1,34 @@
1
+ /** Payload-free fixture schema; type-only imports keep it outside the evaluated startup graph. */
2
+ export type ResidentInputPhase = "receipt" | "semantic-start" | "semantic-end" | "composition-start" | "composition-end" | "write-start" | "write-end";
3
+ export interface ProgressFields {
4
+ readonly eventSequence?: number;
5
+ readonly revision?: number;
6
+ readonly geometryGeneration?: number;
7
+ readonly bytes?: number;
8
+ readonly count?: number;
9
+ readonly eventKind?: string;
10
+ readonly frameId?: number;
11
+ readonly renderCause?: string;
12
+ readonly fragmentCount?: number;
13
+ readonly transactionKind?: "synchronized-output" | "ordinary";
14
+ }
15
+ export interface ProgressRecord extends ProgressFields {
16
+ readonly schema: "a1-resident-progress-observation-v1";
17
+ readonly runId: string;
18
+ readonly role: "child";
19
+ readonly stage: "engine-delivery" | "child-render-write" | "child-input-phase";
20
+ readonly pid: number;
21
+ readonly processInstance: string;
22
+ readonly timestampUnixUs: number;
23
+ readonly clockErrorUs: number;
24
+ readonly sequence: number;
25
+ readonly tabId: string;
26
+ readonly incarnation: number;
27
+ readonly lostBefore: number;
28
+ }
29
+ export interface ResidentProgressObserverPort {
30
+ readonly tabId: string;
31
+ engineDelivery(event: unknown): void;
32
+ inputPhase?(phase: ResidentInputPhase, revision: number): void;
33
+ childRenderWrite(bytes: number, fragments: number, transaction: "synchronized-output" | "ordinary", frameId?: number, renderCause?: string): void;
34
+ }
@@ -1,7 +1,4 @@
1
- export interface ResidentProgressObserverPort {
2
- readonly tabId: string;
3
- engineDelivery(event: unknown): void;
4
- childRenderWrite(bytes: number, fragments: number, transaction: "synchronized-output" | "ordinary", frameId?: number, renderCause?: string): void;
5
- }
6
- /** Returns the opt-in payload-free observer for a resident child, or null on ordinary launches. */
1
+ import type { ResidentProgressObserverPort } from "./progress-observation-schema.js";
2
+ export type { ResidentProgressObserverPort } from "./progress-observation-schema.js";
3
+ /** Opt-in payload-free child observer; ordinary launches return null. */
7
4
  export declare function residentProgressObserver(environment?: NodeJS.ProcessEnv): ResidentProgressObserverPort | null;
@@ -17,7 +17,10 @@ class ResidentProgressObserver {
17
17
  #engineSequence = 0;
18
18
  #pendingBytes = 0;
19
19
  #lost = 0;
20
- #writing = Promise.resolve();
20
+ #writing = false;
21
+ #pending = [];
22
+ #scheduled = false;
23
+ #directoryReady = false;
21
24
  #failed = false;
22
25
  get tabId() { return this.#tabId; }
23
26
  constructor(directory, runId, tabId, incarnation) {
@@ -36,6 +39,9 @@ class ResidentProgressObserver {
36
39
  count: 1,
37
40
  });
38
41
  }
42
+ inputPhase(phase, revision) {
43
+ this.#observe("child-input-phase", { eventKind: phase, revision, count: 1 });
44
+ }
39
45
  childRenderWrite(bytes, fragments, transaction, frameId, renderCause) {
40
46
  this.#observe("child-render-write", {
41
47
  eventSequence: this.#engineSequence,
@@ -59,7 +65,7 @@ class ResidentProgressObserver {
59
65
  pid: process.pid,
60
66
  processInstance: this.#processInstance,
61
67
  timestampUnixUs: Math.round((performance.timeOrigin + performance.now()) * 1_000),
62
- // Rationale: timeOrigin is calibrated to the Unix epoch; retain a conservative cross-process error.
68
+ // Rationale: epoch-calibrated timeOrigin retains conservative cross-process clock error.
63
69
  clockErrorUs: 1_000,
64
70
  sequence: ++this.#sequence,
65
71
  tabId: this.#tabId,
@@ -75,18 +81,44 @@ class ResidentProgressObserver {
75
81
  }
76
82
  this.#lost = 0;
77
83
  this.#pendingBytes += length;
78
- this.#writing = this.#writing.then(async () => {
79
- await mkdir(this.#directory, { recursive: true });
80
- await appendFile(this.#path, line, "utf8");
81
- }).catch(() => {
84
+ this.#pending.push(line);
85
+ this.#schedule();
86
+ }
87
+ #schedule() {
88
+ if (this.#scheduled || this.#writing || this.#failed)
89
+ return;
90
+ this.#scheduled = true;
91
+ // Performance: check-phase batches yield to input and amortize file opens and promises.
92
+ setImmediate(() => { this.#scheduled = false; void this.#flush(); });
93
+ }
94
+ async #flush() {
95
+ if (this.#failed || this.#pending.length === 0)
96
+ return;
97
+ this.#writing = true;
98
+ const batch = this.#pending.join("");
99
+ this.#pending = [];
100
+ // Rationale: cap pending only.
101
+ this.#pendingBytes = 0;
102
+ try {
103
+ if (!this.#directoryReady) {
104
+ await mkdir(this.#directory, { recursive: true });
105
+ this.#directoryReady = true;
106
+ }
107
+ await appendFile(this.#path, batch, "utf8");
108
+ }
109
+ catch {
82
110
  this.#failed = true;
83
- }).finally(() => {
84
- this.#pendingBytes -= length;
85
- });
111
+ this.#pending = [];
112
+ }
113
+ finally {
114
+ this.#writing = false;
115
+ if (this.#pending.length > 0)
116
+ this.#schedule();
117
+ }
86
118
  }
87
119
  }
88
120
  let observer;
89
- /** Returns the opt-in payload-free observer for a resident child, or null on ordinary launches. */
121
+ /** Opt-in payload-free child observer; ordinary launches return null. */
90
122
  export function residentProgressObserver(environment = process.env) {
91
123
  if (environment === process.env && observer !== undefined)
92
124
  return observer;
@@ -99,8 +131,7 @@ export function residentProgressObserver(environment = process.env) {
99
131
  : null;
100
132
  if (environment === process.env) {
101
133
  observer = value;
102
- // Security: test evidence paths and tab identity are not child/tool configuration. Retain them only in
103
- // this observer instance so extensions and spawned tools cannot append to the fixture trace.
134
+ // Security: keep evidence paths and identity private; erase them before extensions/tools inherit env.
104
135
  for (const name of [
105
136
  OBSERVATION_DIRECTORY_ENV,
106
137
  OBSERVATION_RUN_ENV,
@@ -1,4 +1,4 @@
1
- import { readdir, stat } from "node:fs/promises";
1
+ import { readdir } from "node:fs/promises";
2
2
  import { resolve } from "node:path";
3
3
  import { PRODUCT_IDENTITY } from "../../product-identity.js";
4
4
  import { runBoundedHostCommand } from "./bounded-host-command.js";
@@ -51,19 +51,8 @@ async function hasResidentRecords(dataDir) {
51
51
  catch (error) {
52
52
  return !(error instanceof Error && "code" in error && error.code === "ENOENT");
53
53
  }
54
- for (const profile of profiles) {
55
- for (const record of ["server.json", "registry.json"]) {
56
- try {
57
- await stat(resolve(dataDir, "tabs", profile, record));
58
- return true;
59
- }
60
- catch (error) {
61
- if (!(error instanceof Error && "code" in error && error.code === "ENOENT"))
62
- return true;
63
- }
64
- }
65
- }
66
- return false;
54
+ // Invariant: native inspection, not a following stat, judges unknown or linked namespace entries.
55
+ return profiles.length > 0;
67
56
  }
68
57
  function incomplete(reason) {
69
58
  return { complete: false, releaseRoots: [], uncertain: [reason] };
@@ -0,0 +1,5 @@
1
+ /** The owned screens the server opens in a utility tab; each names its tab id stem, `<route>-…`. */
2
+ export type ResidentTabRoute = "settings" | "changelog";
3
+ export declare const RESIDENT_TAB_ROUTES: readonly ResidentTabRoute[];
4
+ /** The utility route whose screen is the resident tab `tabId`, or `null` for an Agent tab. */
5
+ export declare function residentUtilityRoute(tabId: string): ResidentTabRoute | null;
@@ -0,0 +1,5 @@
1
+ export const RESIDENT_TAB_ROUTES = ["settings", "changelog"];
2
+ /** The utility route whose screen is the resident tab `tabId`, or `null` for an Agent tab. */
3
+ export function residentUtilityRoute(tabId) {
4
+ return RESIDENT_TAB_ROUTES.find(route => tabId.startsWith(`${route}-`)) ?? null;
5
+ }
@@ -25,6 +25,8 @@ export interface EditorRecallPort {
25
25
  };
26
26
  observe(listener: () => void): () => void;
27
27
  reset(): void;
28
+ /** Exit a recall browse cycle by restoring the unsent draft rather than keeping the recalled entry. */
29
+ restoreDraft?(): void;
28
30
  }
29
31
  export interface EditorSurface extends Pick<Editor, Exclude<keyof Editor, "setText" | "render" | "handleInput">> {
30
32
  setText(text: string): void;
@@ -1,5 +1,21 @@
1
- import { Container, type Component, type TUI } from "@earendil-works/pi-tui";
1
+ import { Container, Input, type Component, type Focusable, type TUI, type TuiMouseEvent, type TuiMouseEventResult } from "@earendil-works/pi-tui";
2
2
  export declare const PI_MODAL_CONTENT_PADDING_X = 1;
3
+ /** Paints the standard Pi Input prompt as a live-themed dialog-search marker. */
4
+ export declare function renderPiModalSearchInput(input: Input, width: number): string[];
5
+ /** Keeps Pi Input behavior and geometry while owning only its standard dialog-search presentation. */
6
+ export declare class PiModalSearchInput implements Component, Focusable {
7
+ #private;
8
+ constructor(input: Input);
9
+ get focused(): boolean;
10
+ set focused(value: boolean);
11
+ invalidate(): void;
12
+ render(width: number): string[];
13
+ handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined;
14
+ }
15
+ /** Replaces one explicitly identified direct Input child with the standard search presentation. */
16
+ export declare function adoptPiModalSearchInput(container: Container, input: Component): PiModalSearchInput;
17
+ /** Adds one standard dialog-search presentation while callers retain the Input controller. */
18
+ export declare function addPiModalSearchInput(container: Container, input: Input): PiModalSearchInput;
3
19
  /** Adds the standard navigation/select/close footer before a dependency component's bottom rule. */
4
20
  export declare function addPiModalSelectFooter(container: Container): void;
5
21
  /** Owned cancellable operation frame with the canonical dialog close guidance. */
@@ -1,7 +1,47 @@
1
- import { CancellableLoader, Container, Spacer, Text } from "@earendil-works/pi-tui";
1
+ import { CancellableLoader, Container, Input, Spacer, Text, } from "@earendil-works/pi-tui";
2
+ import { DIALOG_CONTENT_PADDING_X, dialogFrameGeometry, insetDialogContent } from "../../../contracts/presentation/index.js";
2
3
  import { DynamicBorder } from "../startup-public.js";
3
4
  import { DIALOG_CLOSE_SHORTCUT_HINT, paintPiBorder, piTheme, renderPiModalShortcutHints } from "./theme.js";
4
- export const PI_MODAL_CONTENT_PADDING_X = 1;
5
+ export const PI_MODAL_CONTENT_PADDING_X = DIALOG_CONTENT_PADDING_X;
6
+ /** Paints the standard Pi Input prompt as a live-themed dialog-search marker. */
7
+ export function renderPiModalSearchInput(input, width) {
8
+ return input.render(width).map(row => {
9
+ if (row.length === 0)
10
+ return row;
11
+ if (!row.startsWith(">"))
12
+ throw new TypeError("modal search input does not use the standard prompt");
13
+ return `${piTheme().fg("accent", ">")}${row.slice(1)}`;
14
+ });
15
+ }
16
+ /** Keeps Pi Input behavior and geometry while owning only its standard dialog-search presentation. */
17
+ export class PiModalSearchInput {
18
+ #input;
19
+ constructor(input) {
20
+ this.#input = input;
21
+ }
22
+ get focused() { return this.#input.focused; }
23
+ set focused(value) { this.#input.focused = value; }
24
+ invalidate() { this.#input.invalidate(); }
25
+ render(width) { return renderPiModalSearchInput(this.#input, width); }
26
+ handleMouse(event) { return this.#input.handleMouse(event); }
27
+ }
28
+ /** Replaces one explicitly identified direct Input child with the standard search presentation. */
29
+ export function adoptPiModalSearchInput(container, input) {
30
+ if (!(input instanceof Input))
31
+ throw new TypeError("modal search component is not an Input");
32
+ const index = container.children.indexOf(input);
33
+ if (index === -1)
34
+ throw new TypeError("modal search Input is not a direct child");
35
+ const presentation = new PiModalSearchInput(input);
36
+ container.children.splice(index, 1, presentation);
37
+ return presentation;
38
+ }
39
+ /** Adds one standard dialog-search presentation while callers retain the Input controller. */
40
+ export function addPiModalSearchInput(container, input) {
41
+ const presentation = new PiModalSearchInput(input);
42
+ container.addChild(presentation);
43
+ return presentation;
44
+ }
5
45
  /** Adds the standard navigation/select/close footer before a dependency component's bottom rule. */
6
46
  export function addPiModalSelectFooter(container) {
7
47
  container.children.splice(container.children.length - 1, 0, new Text(renderPiModalShortcutHints([
@@ -67,21 +107,20 @@ export class PiModalFrame {
67
107
  this.#bottomRule.invalidate();
68
108
  }
69
109
  render(width) {
70
- const padding = Math.min(PI_MODAL_CONTENT_PADDING_X, Math.max(0, width));
71
- const contentWidth = Math.max(0, width - padding);
72
- const rows = [...this.#topRule.render(width)];
110
+ const geometry = dialogFrameGeometry(width);
111
+ const rows = [...this.#topRule.render(geometry.frameWidth)];
73
112
  for (const component of this.#content) {
74
113
  if (this.#fullWidthContent.has(component) || this.#preInsetContent.has(component)) {
75
- rows.push(...component.render(width));
114
+ rows.push(...component.render(geometry.frameWidth));
76
115
  }
77
116
  else if (component instanceof Spacer) {
78
- rows.push(...component.render(contentWidth));
117
+ rows.push(...component.render(geometry.contentWidth));
79
118
  }
80
119
  else {
81
- rows.push(...component.render(contentWidth).map(row => `${" ".repeat(padding)}${row}`));
120
+ rows.push(...component.render(geometry.contentWidth).map(row => insetDialogContent(row, geometry)));
82
121
  }
83
122
  }
84
- rows.push(...this.#bottomRule.render(width));
123
+ rows.push(...this.#bottomRule.render(geometry.frameWidth));
85
124
  return rows;
86
125
  }
87
126
  }
@@ -1,6 +1,6 @@
1
1
  import { Input, getKeybindings, matchesKey, truncateToWidth, visibleWidth, } from "@earendil-works/pi-tui";
2
2
  import { DynamicBorder } from "../startup-public.js";
3
- import { PiModalFrame } from "./modal-frame.js";
3
+ import { PiModalFrame, renderPiModalSearchInput } from "./modal-frame.js";
4
4
  import { DIALOG_CLOSE_SHORTCUT_HINT, paintPiBorder, piTheme, renderPiModalListRow, renderPiModalShortcutHints, } from "./theme.js";
5
5
  function renderHintsWithClose(entries, width) {
6
6
  const body = renderPiModalShortcutHints(entries.slice(0, -1));
@@ -13,7 +13,6 @@ function renderHintsWithClose(entries, width) {
13
13
  }
14
14
  const MAX_VISIBLE_ROWS = 10;
15
15
  const MODELS_TITLE = "Models";
16
- const REFRESHING_TITLE_MIN_DURATION_MS = 1_000;
17
16
  class ModalTitleLine {
18
17
  #text = "";
19
18
  setText(text) { this.#text = text; }
@@ -60,9 +59,6 @@ export class ModelsDialogComponent {
60
59
  #selectedIndex = 0;
61
60
  #preferredId;
62
61
  #refreshStatus;
63
- #refreshing = false;
64
- #refreshStartedAt;
65
- #refreshOutcomeTimer;
66
62
  #disposed = false;
67
63
  #focused = false;
68
64
  constructor(config, callbacks) {
@@ -71,10 +67,6 @@ export class ModelsDialogComponent {
71
67
  this.#scopeIds = [...config.scopeIds];
72
68
  this.#savedScopeIds = [...config.savedScopeIds];
73
69
  this.#filter = config.initialFilter ?? "all";
74
- if (config.refreshStatus !== undefined) {
75
- this.#refreshing = true;
76
- this.#refreshStartedAt = Date.now();
77
- }
78
70
  if (config.initialQuery)
79
71
  this.#input.setValue(config.initialQuery);
80
72
  this.#replaceModels(config.models);
@@ -114,38 +106,10 @@ export class ModelsDialogComponent {
114
106
  setRefreshStatus(message, kind) {
115
107
  if (this.#disposed)
116
108
  return;
117
- if (kind === "muted") {
118
- this.#clearRefreshOutcome();
119
- this.#refreshStatus = undefined;
120
- this.#refreshing = true;
121
- this.#refreshStartedAt = Date.now();
122
- return;
123
- }
124
- const visibleMs = this.#refreshStartedAt === undefined ? REFRESHING_TITLE_MIN_DURATION_MS : Date.now() - this.#refreshStartedAt;
125
- const remainingMs = Math.max(0, REFRESHING_TITLE_MIN_DURATION_MS - visibleMs);
126
- if (this.#refreshing && remainingMs > 0) {
127
- this.#clearRefreshOutcome();
128
- const timer = setTimeout(() => {
129
- if (this.#refreshOutcomeTimer !== timer)
130
- return;
131
- this.#refreshOutcomeTimer = undefined;
132
- if (this.#disposed)
133
- return;
134
- this.#applyRefreshOutcome(message, kind);
135
- this.#callbacks.requestRender();
136
- }, remainingMs);
137
- timer.unref?.();
138
- this.#refreshOutcomeTimer = timer;
139
- return;
140
- }
141
- this.#clearRefreshOutcome();
142
- this.#applyRefreshOutcome(message, kind);
109
+ this.#refreshStatus = kind === "warning" ? { message, kind } : undefined;
143
110
  }
144
111
  dispose() {
145
112
  this.#disposed = true;
146
- this.#clearRefreshOutcome();
147
- this.#refreshing = false;
148
- this.#refreshStartedAt = undefined;
149
113
  }
150
114
  invalidate() {
151
115
  this.#input.invalidate();
@@ -235,21 +199,9 @@ export class ModelsDialogComponent {
235
199
  render(width) {
236
200
  const theme = piTheme();
237
201
  this.#title.setText(theme.fg("accent", theme.bold(MODELS_TITLE))
238
- + (this.dirty ? theme.fg("warning", " (unsaved)") : "")
239
- + (this.#refreshing ? theme.fg("muted", " (refreshing)") : ""));
202
+ + (this.dirty ? theme.fg("warning", " (unsaved)") : ""));
240
203
  return this.#frame.render(width);
241
204
  }
242
- #applyRefreshOutcome(message, kind) {
243
- this.#refreshing = false;
244
- this.#refreshStartedAt = undefined;
245
- this.#refreshStatus = kind === "warning" ? { message, kind } : undefined;
246
- }
247
- #clearRefreshOutcome() {
248
- if (this.#refreshOutcomeTimer === undefined)
249
- return;
250
- clearTimeout(this.#refreshOutcomeTimer);
251
- this.#refreshOutcomeTimer = undefined;
252
- }
253
205
  #renderBody(width) {
254
206
  const theme = piTheme();
255
207
  const lines = [];
@@ -261,7 +213,7 @@ export class ModelsDialogComponent {
261
213
  + theme.fg("dim", " | ")
262
214
  + theme.fg(this.#filter === "scoped" ? "mdHeading" : "dim", "scoped"));
263
215
  push();
264
- for (const line of this.#input.render(width))
216
+ for (const line of renderPiModalSearchInput(this.#input, width))
265
217
  push(line);
266
218
  push();
267
219
  if (rows.length === 0) {
@@ -51,6 +51,8 @@ export interface PromptSelectionUxOptions {
51
51
  readonly beginClipboardPaste?: () => PiShellPasteReservation;
52
52
  readonly beginTextPaste?: (text: string) => PiShellPasteReservation;
53
53
  readonly deferTextPaste?: (text: string) => boolean;
54
+ /** False consumes every paste transport without changing editor text. */
55
+ readonly pasteEnabled?: boolean;
54
56
  readonly onPasteRejected?: (error: unknown) => void;
55
57
  readonly onPasteInput?: (bytes: number, phase: "framing" | "inserting" | "settled") => void;
56
58
  readonly transformPastedContent: (content: PiShellClipboardContent) => string;
@@ -72,5 +74,6 @@ export interface PromptSelectionUxOptions {
72
74
  };
73
75
  }
74
76
  export declare function createPromptSelectionInterceptor(editor: Editor, keybindings: KeybindingsManager, options: PromptSelectionUxOptions): OwnedEditorUxInterceptor;
77
+ export declare function editorInsertedText(data: string): string | undefined;
75
78
  /** Shares the existing atomic-aware body layout with prompt/menu composition. */
76
79
  export declare function editorVisualLineCount(editor: Editor, width: number): number | undefined;
@@ -81,7 +81,7 @@ class PromptSelectionInterceptor {
81
81
  installAtomicSegmentation(editor, options.atomicRanges, () => this.#wordDirection);
82
82
  }
83
83
  handleInput(data, next) {
84
- if (this.#handleTerminalPaste(data, next))
84
+ if (this.options.pasteEnabled === false ? discardTerminalPaste(this, data, value => this.handleInput(value, next)) : this.#handleTerminalPaste(data, next))
85
85
  return;
86
86
  if (this.keybindings.matches(data, "owned.editor.selectAll")) {
87
87
  this.#selectAll();
@@ -107,7 +107,8 @@ class PromptSelectionInterceptor {
107
107
  return;
108
108
  }
109
109
  if (this.keybindings.matches(data, "owned.editor.paste")) {
110
- this.pasteClipboard();
110
+ if (this.options.pasteEnabled !== false)
111
+ this.pasteClipboard();
111
112
  return;
112
113
  }
113
114
  if (this.keybindings.matches(data, "owned.editor.redo")) {
@@ -132,7 +133,7 @@ class PromptSelectionInterceptor {
132
133
  this.#deleteSelection();
133
134
  return;
134
135
  }
135
- const inserted = insertedText(data);
136
+ const inserted = editorInsertedText(data);
136
137
  if (inserted !== undefined) {
137
138
  this.#replaceSelection(inserted);
138
139
  return;
@@ -280,11 +281,13 @@ class PromptSelectionInterceptor {
280
281
  this.#pointerSelecting = false;
281
282
  this.#lastClick = undefined;
282
283
  this.#redoStack = [];
284
+ DISABLED_TERMINAL_PASTES.delete(this);
283
285
  this.#selectionRevision += 1;
284
286
  }
285
287
  cancelPendingPastes() {
286
288
  this.#pasteGeneration += 1;
287
289
  this.#terminalPaste = undefined;
290
+ DISABLED_TERMINAL_PASTES.delete(this);
288
291
  }
289
292
  hasSelection() {
290
293
  return this.#activeRange() !== undefined;
@@ -295,6 +298,8 @@ class PromptSelectionInterceptor {
295
298
  : this.options.expandCopiedText(this.#selectedText());
296
299
  }
297
300
  pasteClipboard() {
301
+ if (this.options.pasteEnabled === false)
302
+ return false;
298
303
  this.#pasteFromClipboard();
299
304
  return true;
300
305
  }
@@ -933,7 +938,73 @@ function isEditorSegment(value) {
933
938
  const input = Reflect.get(value, "input");
934
939
  return typeof segment === "string" && typeof index === "number" && typeof input === "string";
935
940
  }
936
- function insertedText(data) {
941
+ const DISABLED_TERMINAL_PASTES = new WeakMap();
942
+ function discardTerminalPaste(owner, data, forward) {
943
+ const startMarker = "\x1b[200~";
944
+ const endMarker = "\x1b[201~";
945
+ const state = DISABLED_TERMINAL_PASTES.get(owner) ?? { startTail: "", bodyTail: null };
946
+ if (state.bodyTail !== null) {
947
+ const framed = state.bodyTail + data;
948
+ const end = framed.indexOf(endMarker);
949
+ if (end < 0) {
950
+ state.bodyTail = delimiterTail(framed, endMarker);
951
+ DISABLED_TERMINAL_PASTES.set(owner, state);
952
+ return true;
953
+ }
954
+ DISABLED_TERMINAL_PASTES.delete(owner);
955
+ const remaining = framed.slice(end + endMarker.length);
956
+ if (remaining.length > 0)
957
+ forward(remaining);
958
+ return true;
959
+ }
960
+ const hadStartTail = state.startTail.length > 0;
961
+ const candidate = state.startTail + data;
962
+ state.startTail = "";
963
+ const start = candidate.indexOf(startMarker);
964
+ if (start >= 0) {
965
+ if (start > 0)
966
+ forward(candidate.slice(0, start));
967
+ const framed = candidate.slice(start + startMarker.length);
968
+ const end = framed.indexOf(endMarker);
969
+ if (end < 0) {
970
+ state.bodyTail = delimiterTail(framed, endMarker);
971
+ DISABLED_TERMINAL_PASTES.set(owner, state);
972
+ }
973
+ else {
974
+ DISABLED_TERMINAL_PASTES.delete(owner);
975
+ const remaining = framed.slice(end + endMarker.length);
976
+ if (remaining.length > 0)
977
+ forward(remaining);
978
+ }
979
+ return true;
980
+ }
981
+ const partial = delimiterTail(candidate, startMarker);
982
+ // Compatibility: standalone Escape still cancels; marker fragments stay pending.
983
+ if (partial.length > 1) {
984
+ const before = candidate.slice(0, candidate.length - partial.length);
985
+ if (before.length > 0)
986
+ forward(before);
987
+ state.startTail = partial;
988
+ DISABLED_TERMINAL_PASTES.set(owner, state);
989
+ return true;
990
+ }
991
+ DISABLED_TERMINAL_PASTES.delete(owner);
992
+ if (hadStartTail) {
993
+ forward(candidate);
994
+ return true;
995
+ }
996
+ return false;
997
+ }
998
+ function delimiterTail(text, delimiter) {
999
+ const limit = Math.min(text.length, delimiter.length - 1);
1000
+ for (let length = limit; length > 0; length -= 1) {
1001
+ const suffix = text.slice(text.length - length);
1002
+ if (delimiter.startsWith(suffix))
1003
+ return suffix;
1004
+ }
1005
+ return "";
1006
+ }
1007
+ export function editorInsertedText(data) {
937
1008
  if (!data || data.includes("\u001b[200~"))
938
1009
  return undefined;
939
1010
  const kitty = decodeKittyPrintable(data);