@timurproko/a1 0.1.1-dev.5 → 0.1.1-dev.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/README.md +32 -9
  2. package/bin/a1-guardian.js +22 -0
  3. package/bin/a1-ui.js +7 -4
  4. package/dist/native/darwin-arm64/a1-process-guardian +0 -0
  5. package/dist/native/darwin-arm64/manifest.json +20 -0
  6. package/dist/native/linux-x64/a1-process-guardian +0 -0
  7. package/dist/native/linux-x64/manifest.json +20 -0
  8. package/dist/native/win32-x64/a1-process-guardian.exe +0 -0
  9. package/dist/native/win32-x64/manifest.json +20 -0
  10. package/dist/src/composition/index.d.ts +26 -0
  11. package/dist/src/composition/index.js +88 -2
  12. package/dist/src/features/launch/runtime-selection.d.ts +2 -1
  13. package/dist/src/features/launch/runtime-selection.js +2 -2
  14. package/dist/src/features/owned-ui/index.d.ts +1 -0
  15. package/dist/src/features/owned-ui/index.js +1 -0
  16. package/dist/src/features/owned-ui/run.d.ts +6 -0
  17. package/dist/src/features/owned-ui/run.js +3 -1
  18. package/dist/src/features/owned-ui/settings-app.d.ts +22 -0
  19. package/dist/src/features/owned-ui/settings-app.js +631 -0
  20. package/dist/src/foundation/agent-engine-contracts/domain.d.ts +26 -0
  21. package/dist/src/foundation/launch-guardian/index.d.ts +1 -0
  22. package/dist/src/foundation/launch-guardian/index.js +1 -0
  23. package/dist/src/foundation/launch-guardian/main.d.ts +31 -0
  24. package/dist/src/foundation/launch-guardian/main.js +165 -0
  25. package/dist/src/foundation/lifecycle/commands.d.ts +40 -0
  26. package/dist/src/foundation/lifecycle/commands.js +1 -0
  27. package/dist/src/foundation/lifecycle/index.d.ts +2 -0
  28. package/dist/src/foundation/lifecycle/index.js +2 -0
  29. package/dist/src/foundation/lifecycle/launch-instance.d.ts +46 -0
  30. package/dist/src/foundation/lifecycle/launch-instance.js +134 -0
  31. package/dist/src/foundation/lifecycle/model.d.ts +6 -42
  32. package/dist/src/foundation/owned-ui-settings/declarations.d.ts +13 -0
  33. package/dist/src/foundation/owned-ui-settings/declarations.js +39 -0
  34. package/dist/src/foundation/owned-ui-settings/index.d.ts +6 -0
  35. package/dist/src/foundation/owned-ui-settings/index.js +6 -0
  36. package/dist/src/foundation/owned-ui-settings/migrations.d.ts +13 -0
  37. package/dist/src/foundation/owned-ui-settings/migrations.js +28 -0
  38. package/dist/src/foundation/owned-ui-settings/resolution.d.ts +45 -0
  39. package/dist/src/foundation/owned-ui-settings/resolution.js +147 -0
  40. package/dist/src/foundation/owned-ui-settings/sections.d.ts +70 -0
  41. package/dist/src/foundation/owned-ui-settings/sections.js +93 -0
  42. package/dist/src/foundation/owned-ui-settings/session.d.ts +44 -0
  43. package/dist/src/foundation/owned-ui-settings/session.js +145 -0
  44. package/dist/src/foundation/owned-ui-settings/store.d.ts +28 -0
  45. package/dist/src/foundation/owned-ui-settings/store.js +90 -0
  46. package/dist/src/foundation/pi-component-adapter/index.d.ts +1 -0
  47. package/dist/src/foundation/pi-component-adapter/index.js +1 -0
  48. package/dist/src/foundation/pi-component-adapter/shell-selectors-dialogs.d.ts +9 -1
  49. package/dist/src/foundation/pi-component-adapter/shell-selectors-dialogs.js +10 -8
  50. package/dist/src/foundation/pi-engine-adapter/adapter.d.ts +12 -3
  51. package/dist/src/foundation/pi-engine-adapter/adapter.js +73 -7
  52. package/dist/src/foundation/pi-engine-adapter/pi-settings-metadata.json +374 -0
  53. package/dist/src/foundation/pi-engine-adapter/public-main-entry.js +10 -1
  54. package/dist/src/foundation/pi-engine-adapter/settings-integration.d.ts +42 -2
  55. package/dist/src/foundation/pi-engine-adapter/settings-integration.js +185 -24
  56. package/dist/src/foundation/pi-engine-adapter/workflows.d.ts +9 -0
  57. package/dist/src/foundation/pi-owned-ui-integration/index.d.ts +1 -0
  58. package/dist/src/foundation/pi-owned-ui-integration/index.js +1 -0
  59. package/dist/src/foundation/pi-owned-ui-integration/route-host.d.ts +29 -0
  60. package/dist/src/foundation/pi-owned-ui-integration/route-host.js +1 -0
  61. package/dist/src/foundation/pi-owned-ui-integration/session-shell.d.ts +6 -0
  62. package/dist/src/foundation/pi-owned-ui-integration/session-shell.js +71 -1
  63. package/dist/src/foundation/pi-tui-runtime-adapter/adapter.d.ts +6 -0
  64. package/dist/src/foundation/pi-tui-runtime-adapter/adapter.js +9 -0
  65. package/dist/src/foundation/process-containment/artifact.d.ts +1 -0
  66. package/dist/src/foundation/process-containment/artifact.js +34 -0
  67. package/dist/src/foundation/process-containment/contracts.d.ts +31 -0
  68. package/dist/src/foundation/process-containment/contracts.js +35 -0
  69. package/dist/src/foundation/process-containment/index.d.ts +5 -0
  70. package/dist/src/foundation/process-containment/index.js +5 -0
  71. package/dist/src/foundation/process-containment/linux-process-inspector.d.ts +6 -0
  72. package/dist/src/foundation/process-containment/linux-process-inspector.js +26 -0
  73. package/dist/src/foundation/process-containment/native-guardian-containment.d.ts +16 -0
  74. package/dist/src/foundation/process-containment/native-guardian-containment.js +139 -0
  75. package/dist/src/foundation/process-containment/windows-process-inspector.d.ts +17 -0
  76. package/dist/src/foundation/process-containment/windows-process-inspector.js +53 -0
  77. package/dist/src/foundation/protocol/client.d.ts +2 -1
  78. package/dist/src/foundation/protocol/client.js +3 -0
  79. package/dist/src/foundation/protocol/messages.d.ts +5 -5
  80. package/dist/src/foundation/protocol/messages.js +1 -1
  81. package/dist/src/foundation/release/bootstrap.js +29 -10
  82. package/dist/src/foundation/release/cohort-selection.js +3 -3
  83. package/dist/src/foundation/release/cohort-state.d.ts +3 -2
  84. package/dist/src/foundation/release/process-cleanup.d.ts +1 -1
  85. package/dist/src/foundation/release/process-cleanup.js +2 -2
  86. package/dist/src/foundation/release/update.js +2 -2
  87. package/dist/src/foundation/storage/control-store.d.ts +8 -7
  88. package/dist/src/foundation/storage/control-store.js +105 -55
  89. package/dist/src/foundation/supervision/server.d.ts +4 -2
  90. package/dist/src/foundation/supervision/server.js +254 -87
  91. package/dist/src/foundation/transparent-terminal/command-resolution.js +6 -3
  92. package/dist/src/foundation/transparent-terminal/foreground-broker.d.ts +5 -13
  93. package/dist/src/foundation/transparent-terminal/foreground-broker.js +11 -68
  94. package/dist/src/foundation/transparent-terminal/main.js +1 -8
  95. package/dist/src/foundation/ui-apps/contracts.d.ts +42 -0
  96. package/dist/src/foundation/ui-apps/contracts.js +12 -0
  97. package/dist/src/foundation/ui-apps/host.d.ts +42 -0
  98. package/dist/src/foundation/ui-apps/host.js +152 -0
  99. package/dist/src/foundation/ui-apps/index.d.ts +3 -0
  100. package/dist/src/foundation/ui-apps/index.js +3 -0
  101. package/dist/src/foundation/ui-apps/registry.d.ts +11 -0
  102. package/dist/src/foundation/ui-apps/registry.js +32 -0
  103. package/dist/src/foundation/ui-components/dialog-panel.d.ts +36 -0
  104. package/dist/src/foundation/ui-components/dialog-panel.js +47 -0
  105. package/dist/src/foundation/ui-components/frame.d.ts +21 -0
  106. package/dist/src/foundation/ui-components/frame.js +54 -0
  107. package/dist/src/foundation/ui-components/index.d.ts +18 -0
  108. package/dist/src/foundation/ui-components/index.js +18 -0
  109. package/dist/src/foundation/ui-components/label.d.ts +8 -0
  110. package/dist/src/foundation/ui-components/label.js +36 -0
  111. package/dist/src/foundation/ui-components/line-input.d.ts +74 -0
  112. package/dist/src/foundation/ui-components/line-input.js +245 -0
  113. package/dist/src/foundation/ui-components/list-block.d.ts +66 -0
  114. package/dist/src/foundation/ui-components/list-block.js +176 -0
  115. package/dist/src/foundation/ui-components/list-view.d.ts +66 -0
  116. package/dist/src/foundation/ui-components/list-view.js +76 -0
  117. package/dist/src/foundation/ui-components/mouse.d.ts +15 -0
  118. package/dist/src/foundation/ui-components/mouse.js +46 -0
  119. package/dist/src/foundation/ui-components/pane.d.ts +33 -0
  120. package/dist/src/foundation/ui-components/pane.js +7 -0
  121. package/dist/src/foundation/ui-components/revision.d.ts +35 -0
  122. package/dist/src/foundation/ui-components/revision.js +79 -0
  123. package/dist/src/foundation/ui-components/scrollbar.d.ts +62 -0
  124. package/dist/src/foundation/ui-components/scrollbar.js +102 -0
  125. package/dist/src/foundation/ui-components/shortcuts.d.ts +57 -0
  126. package/dist/src/foundation/ui-components/shortcuts.js +81 -0
  127. package/dist/src/foundation/ui-components/spans.d.ts +7 -0
  128. package/dist/src/foundation/ui-components/spans.js +59 -0
  129. package/dist/src/foundation/ui-components/status-line.d.ts +16 -0
  130. package/dist/src/foundation/ui-components/status-line.js +14 -0
  131. package/dist/src/foundation/ui-components/stepper.d.ts +24 -0
  132. package/dist/src/foundation/ui-components/stepper.js +33 -0
  133. package/dist/src/foundation/ui-components/surface.d.ts +20 -0
  134. package/dist/src/foundation/ui-components/surface.js +38 -0
  135. package/dist/src/foundation/ui-components/text.d.ts +24 -0
  136. package/dist/src/foundation/ui-components/text.js +123 -0
  137. package/dist/src/foundation/ui-components/theme.d.ts +17 -0
  138. package/dist/src/foundation/ui-components/theme.js +12 -0
  139. package/dist/src/foundation/ui-components/value-menu.d.ts +41 -0
  140. package/dist/src/foundation/ui-components/value-menu.js +33 -0
  141. package/dist/src/product-identity.d.ts +2 -2
  142. package/dist/src/product-identity.js +2 -1
  143. package/dist/src/product-identity.json +3 -0
  144. package/docs/architecture/boundaries.md +31 -13
  145. package/docs/architecture/process-guardian-provenance.md +26 -0
  146. package/docs/architecture/toolchain.md +6 -0
  147. package/docs/architecture/ui-reference-provenance.md +50 -0
  148. package/docs/ci-release-runbook.md +38 -42
  149. package/docs/features/launch-profiles.md +7 -1
  150. package/docs/manual-launch-instance-acceptance.md +66 -0
  151. package/package.json +11 -12
@@ -0,0 +1,245 @@
1
+ import { displayWidth, faint, truncateToWidth } from "./text.js";
2
+ const MAX_VALUE_LENGTH = 4_096;
3
+ const GRAPHEMES = new Intl.Segmenter(undefined, { granularity: "grapheme" });
4
+ /** Character class for a word boundary: 0 space, 1 word, 2 anything else. */
5
+ function charClass(character) {
6
+ if (/\s/.test(character))
7
+ return 0;
8
+ if (/[\p{L}\p{N}_]/u.test(character))
9
+ return 1;
10
+ return 2;
11
+ }
12
+ /**
13
+ * Where a word jump to the left lands: past any whitespace, then past the run of
14
+ * characters of one class, so a word and a run of punctuation each count as one.
15
+ */
16
+ export function wordLeft(text, from) {
17
+ const graphemes = [...GRAPHEMES.segment(text.slice(0, from))].map(entry => entry.segment);
18
+ let at = from;
19
+ let index = graphemes.length - 1;
20
+ while (index >= 0 && charClass(graphemes[index] ?? "") === 0)
21
+ at -= (graphemes[index--] ?? "").length;
22
+ if (index >= 0) {
23
+ const cls = charClass(graphemes[index] ?? "");
24
+ while (index >= 0 && charClass(graphemes[index] ?? "") === cls)
25
+ at -= (graphemes[index--] ?? "").length;
26
+ }
27
+ return at;
28
+ }
29
+ /** Where a word jump to the right lands, by the same rules mirrored. */
30
+ export function wordRight(text, from) {
31
+ const graphemes = [...GRAPHEMES.segment(text.slice(from))].map(entry => entry.segment);
32
+ let at = from;
33
+ let index = 0;
34
+ while (index < graphemes.length && charClass(graphemes[index] ?? "") === 0)
35
+ at += (graphemes[index++] ?? "").length;
36
+ if (index < graphemes.length) {
37
+ const cls = charClass(graphemes[index] ?? "");
38
+ while (index < graphemes.length && charClass(graphemes[index] ?? "") === cls)
39
+ at += (graphemes[index++] ?? "").length;
40
+ }
41
+ return at;
42
+ }
43
+ /**
44
+ * A single-line editable value with a caret and horizontal scrolling. Accept and
45
+ * cancel are reported distinctly so a caller can commit or discard; cancelling
46
+ * never changes the caller's value.
47
+ */
48
+ export class LineInput {
49
+ #value;
50
+ #caret;
51
+ #offset = 0;
52
+ constructor(value = "") {
53
+ this.#value = value.slice(0, MAX_VALUE_LENGTH);
54
+ this.#caret = this.#value.length;
55
+ }
56
+ get value() {
57
+ return this.#value;
58
+ }
59
+ get caret() {
60
+ return this.#caret;
61
+ }
62
+ setValue(value) {
63
+ this.#value = value.slice(0, MAX_VALUE_LENGTH);
64
+ this.#caret = Math.min(this.#caret, this.#value.length);
65
+ this.#offset = 0;
66
+ }
67
+ insert(text) {
68
+ const printable = [...text].filter(character => {
69
+ const code = character.codePointAt(0) ?? 0;
70
+ return code >= 0x20 && code !== 0x7f;
71
+ }).join("");
72
+ if (printable.length === 0)
73
+ return;
74
+ const next = this.#value.slice(0, this.#caret) + printable + this.#value.slice(this.#caret);
75
+ if (next.length > MAX_VALUE_LENGTH)
76
+ return;
77
+ this.#value = next;
78
+ this.#caret += printable.length;
79
+ }
80
+ backspace() {
81
+ if (this.#caret === 0)
82
+ return;
83
+ this.#value = this.#value.slice(0, this.#caret - 1) + this.#value.slice(this.#caret);
84
+ this.#caret -= 1;
85
+ }
86
+ deleteForward() {
87
+ if (this.#caret >= this.#value.length)
88
+ return;
89
+ this.#value = this.#value.slice(0, this.#caret) + this.#value.slice(this.#caret + 1);
90
+ }
91
+ moveCaret(delta) {
92
+ this.#caret = Math.min(Math.max(this.#caret + delta, 0), this.#value.length);
93
+ }
94
+ /** Moves the caret one word, in whichever direction the sign says. */
95
+ moveCaretByWord(direction) {
96
+ this.#caret = direction < 0 ? wordLeft(this.#value, this.#caret) : wordRight(this.#value, this.#caret);
97
+ }
98
+ /** Removes the word before the caret, leaving the caret where it began. */
99
+ deleteWordBefore() {
100
+ const to = wordLeft(this.#value, this.#caret);
101
+ if (to >= this.#caret)
102
+ return;
103
+ this.#value = this.#value.slice(0, to) + this.#value.slice(this.#caret);
104
+ this.#caret = to;
105
+ }
106
+ /** Removes the word after the caret, leaving the caret where it is. */
107
+ deleteWordAfter() {
108
+ const to = wordRight(this.#value, this.#caret);
109
+ if (to <= this.#caret)
110
+ return;
111
+ this.#value = this.#value.slice(0, this.#caret) + this.#value.slice(to);
112
+ }
113
+ moveCaretToStart() {
114
+ this.#caret = 0;
115
+ }
116
+ moveCaretToEnd() {
117
+ this.#caret = this.#value.length;
118
+ }
119
+ /** Visible slice for a width, scrolled so the caret stays on screen. */
120
+ view(width) {
121
+ if (width <= 0)
122
+ return { text: "", caretColumn: 0 };
123
+ const before = this.#value.slice(0, this.#caret);
124
+ const caretWidth = displayWidth(before);
125
+ if (caretWidth < this.#offset)
126
+ this.#offset = caretWidth;
127
+ if (caretWidth >= this.#offset + width)
128
+ this.#offset = caretWidth - width + 1;
129
+ if (this.#offset < 0)
130
+ this.#offset = 0;
131
+ let start = 0;
132
+ let consumed = 0;
133
+ for (const character of this.#value) {
134
+ if (consumed >= this.#offset)
135
+ break;
136
+ consumed += displayWidth(character);
137
+ start += character.length;
138
+ }
139
+ return {
140
+ text: truncateToWidth(this.#value.slice(start), width),
141
+ caretColumn: Math.max(0, Math.min(width, caretWidth - this.#offset)),
142
+ };
143
+ }
144
+ }
145
+ /** Applies one key to the input and reports whether the caller should commit. */
146
+ export function handleLineInputKey(input, data) {
147
+ if (data === "\r" || data === "\n")
148
+ return { kind: "accepted", value: input.value };
149
+ if (data === "\u001b" || data === "\u0003")
150
+ return { kind: "cancelled" };
151
+ // A word delete is decided before a plain one: on Windows Terminal the raw
152
+ // backspace byte IS ctrl+backspace, and the plain branch would swallow it.
153
+ if (data === "\b" || data === "\u001b\u007f" || data === "\u0017") {
154
+ input.deleteWordBefore();
155
+ return { kind: "editing" };
156
+ }
157
+ if (data === "\u001b[3;5~" || data === "\u001b[3;3~" || data === "\u001bd") {
158
+ input.deleteWordAfter();
159
+ return { kind: "editing" };
160
+ }
161
+ if (data === "\u007f") {
162
+ input.backspace();
163
+ return { kind: "editing" };
164
+ }
165
+ if (data === "\u001b[3~") {
166
+ input.deleteForward();
167
+ return { kind: "editing" };
168
+ }
169
+ if (data === "\u001b[1;5D" || data === "\u001b[1;3D" || data === "\u001bb") {
170
+ input.moveCaretByWord(-1);
171
+ return { kind: "editing" };
172
+ }
173
+ if (data === "\u001b[1;5C" || data === "\u001b[1;3C" || data === "\u001bf") {
174
+ input.moveCaretByWord(1);
175
+ return { kind: "editing" };
176
+ }
177
+ if (data === "\u001b[D") {
178
+ input.moveCaret(-1);
179
+ return { kind: "editing" };
180
+ }
181
+ if (data === "\u001b[C") {
182
+ input.moveCaret(1);
183
+ return { kind: "editing" };
184
+ }
185
+ if (data === "\u001b[H" || data === "\u0001") {
186
+ input.moveCaretToStart();
187
+ return { kind: "editing" };
188
+ }
189
+ if (data === "\u001b[F" || data === "\u0005") {
190
+ input.moveCaretToEnd();
191
+ return { kind: "editing" };
192
+ }
193
+ // Any other escape sequence is a key this input has no answer for - a page
194
+ // key, a function key, a chord. It is swallowed rather than typed, because the
195
+ // one thing it certainly is not is text the reader meant to enter.
196
+ if (data.startsWith("\u001b"))
197
+ return { kind: "editing" };
198
+ input.insert(data);
199
+ return { kind: "editing" };
200
+ }
201
+ /**
202
+ * The prompt the reference draws at the head of an input row, in the grey it
203
+ * uses for one (#9AA0A6), painted foreground-only so anything drawn behind the
204
+ * row survives.
205
+ */
206
+ /** A rule drawn in the prompt's own grey, as the reference rules an input row. */
207
+ export function promptRule(width) {
208
+ return `\u001b[38;2;154;160;166m${"─".repeat(Math.max(0, width))}\u001b[39m`;
209
+ }
210
+ export const PROMPT_GLYPH = `\u001b[38;2;154;160;166m❯\u001b[39m `;
211
+ /**
212
+ * The caret the reference draws: the cell under it is reversed rather than given
213
+ * a colour of its own, so it reads as a block in whatever theme is in use.
214
+ */
215
+ export function caretCell(text) {
216
+ return `\u001b[7m${text}\u001b[27m`;
217
+ }
218
+ /** The input row as the reference draws one, padded to exactly the width. */
219
+ export function renderInputRow(input, width, options = {}) {
220
+ const inner = Math.max(0, width - 2);
221
+ const view = input.view(inner);
222
+ const placeholder = options.placeholder ?? "";
223
+ const empty = view.text.length === 0 && placeholder.length > 0;
224
+ const before = view.text.slice(0, view.caretColumn);
225
+ const under = view.text.slice(view.caretColumn, view.caretColumn + 1) || " ";
226
+ const after = view.text.slice(view.caretColumn + 1);
227
+ // Typed text is left unpainted, the caret reverses its cell, and the
228
+ // placeholder is quietened by weight rather than by a colour of its own.
229
+ const body = empty
230
+ ? `${caretCell(placeholder.slice(0, 1))}${faint(placeholder.slice(1))}`
231
+ : `${before}${caretCell(under)}${after}`;
232
+ const plain = empty
233
+ ? placeholder
234
+ : `${view.text}${view.caretColumn >= view.text.length ? " " : ""}`;
235
+ const row = padVisible(truncateToWidth(`${PROMPT_GLYPH}${body}`, width), width, `❯ ${plain}`);
236
+ if (options.ruled === false)
237
+ return { lines: [row] };
238
+ const rule = promptRule(width);
239
+ return { lines: [rule, row, rule] };
240
+ }
241
+ /** Pads by visible width, so styling escapes do not shift the layout. */
242
+ function padVisible(line, width, raw) {
243
+ const visible = displayWidth(raw);
244
+ return visible >= width ? line : line + " ".repeat(width - visible);
245
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * A grouped list: group headers, selectable elements, notes, and spacers. While
3
+ * the top visible row belongs to a group, that group's header stays pinned as
4
+ * the first rendered row, so the reader always knows which group is on screen.
5
+ */
6
+ export type ListRow<T> = {
7
+ readonly kind: "group";
8
+ readonly group: string;
9
+ readonly title: string;
10
+ } | {
11
+ readonly kind: "element";
12
+ readonly group: string;
13
+ readonly key: string;
14
+ readonly selectable: boolean;
15
+ readonly value: T;
16
+ } | {
17
+ readonly kind: "note";
18
+ readonly group: string;
19
+ readonly text: string;
20
+ } | {
21
+ readonly kind: "spacer";
22
+ };
23
+ export interface ListRowSpan {
24
+ readonly from: number;
25
+ readonly to: number;
26
+ }
27
+ export declare function rowKey<T>(row: ListRow<T> | undefined): string | undefined;
28
+ export declare function selectableIndexes<T>(rows: readonly ListRow<T>[]): readonly number[];
29
+ export declare function indexOfKey<T>(rows: readonly ListRow<T>[], key: string | undefined): number;
30
+ /** Clamped movement between selectable rows. No wrap-around. */
31
+ export declare function moveSelection<T>(rows: readonly ListRow<T>[], current: number, delta: number): number;
32
+ /**
33
+ * Forward lands on the first element of the next group. Backward lands on the
34
+ * first element of the current group, or the previous group's when already
35
+ * there. Groups with no selectable element are skipped; edges stay put.
36
+ */
37
+ export declare function blockJumpTarget<T>(rows: readonly ListRow<T>[], current: number, delta: number): number | undefined;
38
+ /** The block containing `index`: its header through the row before the next header. */
39
+ export declare function blockRowSpan<T>(rows: readonly ListRow<T>[], index: number): ListRowSpan;
40
+ /** The header pinned above the body when the top visible row belongs to a group. */
41
+ export declare function stickyHeaderFor<T>(rows: readonly ListRow<T>[], scroll: number): string | undefined;
42
+ /** One blank row above the first group while the list is scrolled to the top. */
43
+ export declare function topPaddingRows(scroll: number): number;
44
+ /** Rows of content visible after the padding and any pinned header. */
45
+ export declare function visibleRowCount<T>(rows: readonly ListRow<T>[], bodyHeight: number, scroll: number): number;
46
+ export declare function maxScrollFor<T>(rows: readonly ListRow<T>[], bodyHeight: number): number;
47
+ export declare function clampScroll<T>(rows: readonly ListRow<T>[], bodyHeight: number, scroll: number): {
48
+ readonly scroll: number;
49
+ readonly visible: number;
50
+ };
51
+ /**
52
+ * Scroll that brings the selection into view, moving the least it can. A reveal
53
+ * span asks for a whole block; a block taller than the viewport is shown from
54
+ * its header instead.
55
+ */
56
+ export declare function scrollForSelection<T>(rows: readonly ListRow<T>[], bodyHeight: number, scroll: number, selected: number, reveal?: ListRowSpan): number;
57
+ export interface ListLayout {
58
+ readonly scroll: number;
59
+ readonly visible: number;
60
+ readonly stickyHeader: string | undefined;
61
+ readonly topPadding: number;
62
+ /** Row indexes rendered in the body, in order. */
63
+ readonly rowIndexes: readonly number[];
64
+ }
65
+ /** Everything a renderer needs for one frame, derived rather than remembered. */
66
+ export declare function layoutList<T>(rows: readonly ListRow<T>[], bodyHeight: number, scroll: number): ListLayout;
@@ -0,0 +1,176 @@
1
+ /**
2
+ * A grouped list: group headers, selectable elements, notes, and spacers. While
3
+ * the top visible row belongs to a group, that group's header stays pinned as
4
+ * the first rendered row, so the reader always knows which group is on screen.
5
+ */
6
+ export function rowKey(row) {
7
+ return row !== undefined && row.kind === "element" && row.selectable ? row.key : undefined;
8
+ }
9
+ export function selectableIndexes(rows) {
10
+ const indexes = [];
11
+ rows.forEach((row, index) => {
12
+ if (rowKey(row) !== undefined)
13
+ indexes.push(index);
14
+ });
15
+ return indexes;
16
+ }
17
+ export function indexOfKey(rows, key) {
18
+ if (key !== undefined) {
19
+ const found = rows.findIndex(row => rowKey(row) === key);
20
+ if (found >= 0)
21
+ return found;
22
+ }
23
+ return selectableIndexes(rows)[0] ?? -1;
24
+ }
25
+ /** Clamped movement between selectable rows. No wrap-around. */
26
+ export function moveSelection(rows, current, delta) {
27
+ const selectable = selectableIndexes(rows);
28
+ if (selectable.length === 0)
29
+ return -1;
30
+ const position = selectable.indexOf(current);
31
+ if (position < 0)
32
+ return selectable[0] ?? -1;
33
+ const next = Math.min(Math.max(position + delta, 0), selectable.length - 1);
34
+ return selectable[next] ?? current;
35
+ }
36
+ function firstElementOfBlock(rows, headerIndex) {
37
+ for (let index = headerIndex + 1; index < rows.length && rows[index]?.kind !== "group"; index++) {
38
+ if (rowKey(rows[index]) !== undefined)
39
+ return index;
40
+ }
41
+ return undefined;
42
+ }
43
+ function headerAbove(rows, index) {
44
+ for (let cursor = Math.min(index, rows.length - 1); cursor >= 0; cursor--) {
45
+ if (rows[cursor]?.kind === "group")
46
+ return cursor;
47
+ }
48
+ return -1;
49
+ }
50
+ /**
51
+ * Forward lands on the first element of the next group. Backward lands on the
52
+ * first element of the current group, or the previous group's when already
53
+ * there. Groups with no selectable element are skipped; edges stay put.
54
+ */
55
+ export function blockJumpTarget(rows, current, delta) {
56
+ if (current < 0 || rows.length === 0)
57
+ return undefined;
58
+ const header = headerAbove(rows, current);
59
+ if (header < 0)
60
+ return undefined;
61
+ const blocks = [];
62
+ for (let index = 0; index < rows.length; index++) {
63
+ if (rows[index]?.kind === "group" && firstElementOfBlock(rows, index) !== undefined)
64
+ blocks.push(index);
65
+ }
66
+ const position = blocks.indexOf(header);
67
+ if (position < 0)
68
+ return undefined;
69
+ if (delta > 0) {
70
+ if (position >= blocks.length - 1)
71
+ return undefined;
72
+ const next = blocks[position + 1];
73
+ return next === undefined ? undefined : firstElementOfBlock(rows, next);
74
+ }
75
+ const own = firstElementOfBlock(rows, header);
76
+ if (own !== undefined && own < current)
77
+ return own;
78
+ if (position <= 0)
79
+ return undefined;
80
+ const previous = blocks[position - 1];
81
+ return previous === undefined ? undefined : firstElementOfBlock(rows, previous);
82
+ }
83
+ /** The block containing `index`: its header through the row before the next header. */
84
+ export function blockRowSpan(rows, index) {
85
+ if (rows.length === 0)
86
+ return { from: 0, to: 0 };
87
+ const start = Math.min(Math.max(index, 0), rows.length - 1);
88
+ const from = Math.max(headerAbove(rows, start), 0);
89
+ let to = rows.length - 1;
90
+ for (let cursor = start + 1; cursor < rows.length; cursor++) {
91
+ if (rows[cursor]?.kind === "group") {
92
+ to = cursor - 1;
93
+ break;
94
+ }
95
+ }
96
+ return { from, to };
97
+ }
98
+ /** The header pinned above the body when the top visible row belongs to a group. */
99
+ export function stickyHeaderFor(rows, scroll) {
100
+ const row = rows[scroll];
101
+ if (row === undefined || (row.kind !== "element" && row.kind !== "note"))
102
+ return undefined;
103
+ const header = headerAbove(rows, scroll);
104
+ const headerRow = header < 0 ? undefined : rows[header];
105
+ return headerRow !== undefined && headerRow.kind === "group" ? headerRow.title : undefined;
106
+ }
107
+ /** One blank row above the first group while the list is scrolled to the top. */
108
+ export function topPaddingRows(scroll) {
109
+ return scroll <= 0 ? 1 : 0;
110
+ }
111
+ /** Rows of content visible after the padding and any pinned header. */
112
+ export function visibleRowCount(rows, bodyHeight, scroll) {
113
+ const reserved = topPaddingRows(scroll) + (stickyHeaderFor(rows, scroll) === undefined ? 0 : 1);
114
+ return Math.max(1, bodyHeight - reserved);
115
+ }
116
+ export function maxScrollFor(rows, bodyHeight) {
117
+ let scroll = Math.max(0, rows.length - 1);
118
+ for (let pass = 0; pass < 8; pass++) {
119
+ const next = Math.max(0, rows.length - visibleRowCount(rows, bodyHeight, scroll));
120
+ if (next === scroll)
121
+ break;
122
+ scroll = next;
123
+ }
124
+ return scroll;
125
+ }
126
+ export function clampScroll(rows, bodyHeight, scroll) {
127
+ const bounded = Math.min(Math.max(scroll, 0), maxScrollFor(rows, bodyHeight));
128
+ return { scroll: bounded, visible: visibleRowCount(rows, bodyHeight, bounded) };
129
+ }
130
+ /**
131
+ * Scroll that brings the selection into view, moving the least it can. A reveal
132
+ * span asks for a whole block; a block taller than the viewport is shown from
133
+ * its header instead.
134
+ */
135
+ export function scrollForSelection(rows, bodyHeight, scroll, selected, reveal) {
136
+ let next = scroll;
137
+ for (let pass = 0; pass < 2; pass++) {
138
+ const visible = visibleRowCount(rows, bodyHeight, next);
139
+ if (selected >= 0) {
140
+ if (reveal && reveal.to - reveal.from < visible) {
141
+ if (reveal.from < next)
142
+ next = reveal.from;
143
+ if (reveal.to >= next + visible)
144
+ next = reveal.to - visible + 1;
145
+ }
146
+ else if (reveal) {
147
+ next = reveal.from;
148
+ }
149
+ else {
150
+ if (selected < next)
151
+ next = selected;
152
+ if (selected >= next + visible)
153
+ next = selected - visible + 1;
154
+ }
155
+ }
156
+ next = clampScroll(rows, bodyHeight, next).scroll;
157
+ }
158
+ return next;
159
+ }
160
+ /** Everything a renderer needs for one frame, derived rather than remembered. */
161
+ export function layoutList(rows, bodyHeight, scroll) {
162
+ const clamped = clampScroll(rows, bodyHeight, scroll);
163
+ const sticky = stickyHeaderFor(rows, clamped.scroll);
164
+ const padding = topPaddingRows(clamped.scroll);
165
+ const indexes = [];
166
+ for (let offset = 0; offset < clamped.visible && clamped.scroll + offset < rows.length; offset++) {
167
+ indexes.push(clamped.scroll + offset);
168
+ }
169
+ return {
170
+ scroll: clamped.scroll,
171
+ visible: clamped.visible,
172
+ stickyHeader: sticky,
173
+ topPadding: padding,
174
+ rowIndexes: Object.freeze(indexes),
175
+ };
176
+ }
@@ -0,0 +1,66 @@
1
+ import type { UiTheme } from "./theme.js";
2
+ /**
3
+ * A list of things that each carry a label and a value. It owns where a value
4
+ * starts, how a row reads when it is selected or pointed at, and which part of a
5
+ * row the pointer is on — so a screen decides what a row means and this decides
6
+ * how it looks and where it can be touched.
7
+ */
8
+ /** The part of a row the pointer is over. A label selects; a value acts. */
9
+ export type ListRegion = "label" | "value" | "minus" | "plus";
10
+ /** Columns a stepper's controls occupy on either side of the value. */
11
+ export declare const STEPPER_RESERVE = 2;
12
+ export interface ListViewRow {
13
+ /** Identity of the row, as the screen knows it. */
14
+ readonly key: string;
15
+ readonly label: string;
16
+ /** The value as it should read. Formatting belongs to the screen. */
17
+ readonly value: string;
18
+ /** Trailing note, such as where a value came from. */
19
+ readonly suffix?: string;
20
+ /**
21
+ * Present when the value is stepped. Each end says whether it can still act;
22
+ * an end that cannot is drawn as unavailable rather than explaining itself.
23
+ */
24
+ readonly stepper?: {
25
+ readonly lower: boolean;
26
+ readonly raise: boolean;
27
+ };
28
+ }
29
+ export interface ListRowState {
30
+ /** The keyboard's row. */
31
+ readonly selected: boolean;
32
+ /** The pointer's row, and where on it the pointer is. */
33
+ readonly hovered: boolean;
34
+ readonly region: ListRegion;
35
+ }
36
+ /** Where a row was drawn, so a later pointer report can be read against it. */
37
+ export interface ListRowPlacement {
38
+ readonly key: string;
39
+ readonly screenRow: number;
40
+ readonly valueColumn: number;
41
+ readonly valueWidth: number;
42
+ readonly stepper: boolean;
43
+ }
44
+ /**
45
+ * The column every value begins at: past the widest label, with room to breathe,
46
+ * and with the stepper's columns reserved for every row when any row has one, so
47
+ * a number does not shift its own value out of the column it shares.
48
+ */
49
+ export declare function valueColumnFor(rows: readonly ListViewRow[], indent?: number, gap?: number): number;
50
+ /** A group's name, above the rows that belong to it. */
51
+ export declare function renderGroupHeader(title: string, width: number, theme: UiTheme): string;
52
+ /**
53
+ * One row, painted. The label carries the selection, the value carries the
54
+ * pointer, and the stepper appears only when the pointer is on the value it
55
+ * belongs to — an affordance, not decoration.
56
+ */
57
+ export declare function renderListRow(row: ListViewRow, state: ListRowState, valueColumn: number, width: number, theme: UiTheme): string;
58
+ /** A line that stands in for rows: why a group has none, or what it is waiting on. */
59
+ export declare function renderNote(text: string, width: number, theme: UiTheme): string;
60
+ /** Where the value of a row starts and ends, for reading a pointer against it. */
61
+ export declare function placementFor(row: ListViewRow, screenRow: number, valueColumn: number, hovered: boolean): ListRowPlacement;
62
+ /**
63
+ * The part of a row a column falls on. The stepper's controls sit in the columns
64
+ * reserved before and after the value, so they are only reachable while drawn.
65
+ */
66
+ export declare function regionAt(placement: ListRowPlacement, column: number): ListRegion;
@@ -0,0 +1,76 @@
1
+ import { displayWidth, truncateToWidth } from "./text.js";
2
+ /** Columns a stepper's controls occupy on either side of the value. */
3
+ export const STEPPER_RESERVE = 2;
4
+ /**
5
+ * The column every value begins at: past the widest label, with room to breathe,
6
+ * and with the stepper's columns reserved for every row when any row has one, so
7
+ * a number does not shift its own value out of the column it shares.
8
+ */
9
+ export function valueColumnFor(rows, indent = 4, gap = 2) {
10
+ const widest = Math.max(0, ...rows.map(row => displayWidth(row.label)));
11
+ const stepper = rows.some(row => row.stepper !== undefined) ? STEPPER_RESERVE : 0;
12
+ return indent + widest + gap + stepper;
13
+ }
14
+ /** A group's name, above the rows that belong to it. */
15
+ export function renderGroupHeader(title, width, theme) {
16
+ return truncateToWidth(theme.fg("accent", theme.bold(title)), width);
17
+ }
18
+ /**
19
+ * One row, painted. The label carries the selection, the value carries the
20
+ * pointer, and the stepper appears only when the pointer is on the value it
21
+ * belongs to — an affordance, not decoration.
22
+ */
23
+ export function renderListRow(row, state, valueColumn, width, theme) {
24
+ const cursor = state.selected ? "→ " : " ";
25
+ const leftRaw = `${cursor} ${row.label}`;
26
+ const left = `${theme.fg("accent", cursor)} ${theme.fg(state.selected ? "accent" : "text", row.label)}`;
27
+ const gap = Math.max(2, valueColumn - displayWidth(leftRaw));
28
+ // Pointing anywhere on the row is pointing at the item; pointing at the value
29
+ // is what brightens it. The selection speaks through the label alone.
30
+ const valueHovered = state.hovered && state.region !== "label";
31
+ const stepper = row.stepper !== undefined && valueHovered;
32
+ const value = theme.fg(valueHovered ? "text" : "muted", row.value);
33
+ const minus = stepper
34
+ ? row.stepper?.lower === true
35
+ ? theme.fg(state.region === "minus" ? "text" : "dim", "- ")
36
+ : theme.disabled("- ")
37
+ : "";
38
+ const plus = stepper
39
+ ? row.stepper?.raise === true
40
+ ? theme.fg(state.region === "plus" ? "text" : "dim", " +")
41
+ : theme.disabled(" +")
42
+ : "";
43
+ const indent = Math.max(2, stepper ? gap - STEPPER_RESERVE : gap);
44
+ const suffix = row.suffix === undefined ? "" : theme.fg("dim", ` ${row.suffix}`);
45
+ return truncateToWidth(`${left}${" ".repeat(indent)}${minus}${value}${plus}${suffix}`, width);
46
+ }
47
+ /** A line that stands in for rows: why a group has none, or what it is waiting on. */
48
+ export function renderNote(text, width, theme) {
49
+ return truncateToWidth(theme.fg("muted", ` ${text}`), width);
50
+ }
51
+ /** Where the value of a row starts and ends, for reading a pointer against it. */
52
+ export function placementFor(row, screenRow, valueColumn, hovered) {
53
+ const stepper = row.stepper !== undefined && hovered;
54
+ return {
55
+ key: row.key,
56
+ screenRow,
57
+ valueColumn: stepper ? valueColumn - STEPPER_RESERVE : valueColumn,
58
+ valueWidth: displayWidth(row.value),
59
+ stepper,
60
+ };
61
+ }
62
+ /**
63
+ * The part of a row a column falls on. The stepper's controls sit in the columns
64
+ * reserved before and after the value, so they are only reachable while drawn.
65
+ */
66
+ export function regionAt(placement, column) {
67
+ const start = placement.valueColumn + 1;
68
+ const end = start + placement.valueWidth;
69
+ if (column >= start && column <= end)
70
+ return "value";
71
+ if (placement.stepper && column >= start - STEPPER_RESERVE && column < start)
72
+ return "minus";
73
+ if (placement.stepper && column > end && column <= end + STEPPER_RESERVE)
74
+ return "plus";
75
+ return "label";
76
+ }
@@ -0,0 +1,15 @@
1
+ import type { PaneMouseEvent } from "./pane.js";
2
+ /**
3
+ * SGR mouse reporting. A screen that wants hover, click, and drag needs the
4
+ * terminal to send reports; nothing else in A1 turns this on, and the sequences
5
+ * are paired so the terminal is always left as it was found.
6
+ */
7
+ export declare const MOUSE_TRACKING_ON = "\u001B[?1006h\u001B[?1000h\u001B[?1003h";
8
+ export declare const MOUSE_TRACKING_OFF = "\u001B[?1003l\u001B[?1000l\u001B[?1006l";
9
+ export interface ParsedMouseInput {
10
+ readonly events: readonly PaneMouseEvent[];
11
+ /** Input with every mouse report removed, for ordinary key handling. */
12
+ readonly rest: string;
13
+ }
14
+ /** Extracts SGR mouse reports, leaving any keyboard input untouched. */
15
+ export declare function parseMouseInput(data: string): ParsedMouseInput;