pi-suite 0.0.0-stage → 0.3.0

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 (220) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +100 -2
  3. package/README.zh-CN.md +101 -0
  4. package/package.json +63 -4
  5. package/skills/pi-suite-jobs/SKILL.md +76 -0
  6. package/skills/pi-suite-workflow/SKILL.md +114 -0
  7. package/src/agents/catalog.ts +80 -0
  8. package/src/agents/child.ts +79 -0
  9. package/src/agents/commands.ts +17 -0
  10. package/src/agents/defaults.ts +78 -0
  11. package/src/agents/history.ts +112 -0
  12. package/src/agents/index.ts +211 -0
  13. package/src/agents/manager.ts +438 -0
  14. package/src/agents/mentions/clone.ts +51 -0
  15. package/src/agents/mentions/grammar.ts +64 -0
  16. package/src/agents/mentions/index.ts +76 -0
  17. package/src/agents/mentions/provider.ts +79 -0
  18. package/src/agents/model-editor.ts +95 -0
  19. package/src/agents/models.ts +43 -0
  20. package/src/agents/output/schema.ts +101 -0
  21. package/src/agents/output/tool.ts +98 -0
  22. package/src/agents/parent.ts +13 -0
  23. package/src/agents/questions.ts +63 -0
  24. package/src/agents/records.ts +90 -0
  25. package/src/agents/registry.ts +20 -0
  26. package/src/agents/render.ts +85 -0
  27. package/src/agents/resources/context.ts +48 -0
  28. package/src/agents/resources/loader.ts +86 -0
  29. package/src/agents/resources/memory.ts +67 -0
  30. package/src/agents/resources/packages.ts +96 -0
  31. package/src/agents/resources/paths.ts +8 -0
  32. package/src/agents/resources/prompts.ts +11 -0
  33. package/src/agents/resources/scope.ts +147 -0
  34. package/src/agents/resources/selectors.ts +186 -0
  35. package/src/agents/retry.ts +20 -0
  36. package/src/agents/rpc/handlers.ts +62 -0
  37. package/src/agents/rpc/index.ts +73 -0
  38. package/src/agents/rpc/options.ts +44 -0
  39. package/src/agents/run-groups.ts +16 -0
  40. package/src/agents/runner.ts +131 -0
  41. package/src/agents/runtime.ts +40 -0
  42. package/src/agents/schedules/index.ts +136 -0
  43. package/src/agents/schedules/menu.ts +38 -0
  44. package/src/agents/schedules/parse.ts +42 -0
  45. package/src/agents/schedules/store.ts +78 -0
  46. package/src/agents/schema.ts +5 -0
  47. package/src/agents/session.ts +29 -0
  48. package/src/agents/tools.ts +177 -0
  49. package/src/agents/types.ts +87 -0
  50. package/src/agents/ui/index.ts +42 -0
  51. package/src/agents/ui/runs.ts +122 -0
  52. package/src/agents/ui/types.ts +91 -0
  53. package/src/agents/viewer-info.ts +36 -0
  54. package/src/agents/viewer.ts +160 -0
  55. package/src/agents/workflow/collisions.ts +124 -0
  56. package/src/agents/workflow/entry.ts +93 -0
  57. package/src/agents/workflow/host.ts +119 -0
  58. package/src/agents/workflow/index.ts +100 -0
  59. package/src/agents/workflow/journal.ts +147 -0
  60. package/src/agents/workflow/literal.ts +57 -0
  61. package/src/agents/workflow/manager.ts +169 -0
  62. package/src/agents/workflow/meta.ts +323 -0
  63. package/src/agents/workflow/progress/format.ts +184 -0
  64. package/src/agents/workflow/progress/index.ts +3 -0
  65. package/src/agents/workflow/progress/model.ts +224 -0
  66. package/src/agents/workflow/progress/types.ts +144 -0
  67. package/src/agents/workflow/render.ts +46 -0
  68. package/src/agents/workflow/runtime/helpers.ts +236 -0
  69. package/src/agents/workflow/runtime/index.ts +3 -0
  70. package/src/agents/workflow/runtime/run.ts +646 -0
  71. package/src/agents/workflow/runtime/types.ts +273 -0
  72. package/src/agents/workflow/saved.ts +74 -0
  73. package/src/agents/workflow/store.ts +23 -0
  74. package/src/agents/workflow/task.ts +277 -0
  75. package/src/agents/workflow/tool-description.ts +32 -0
  76. package/src/agents/workflow/tools.ts +66 -0
  77. package/src/agents/workflow/ui/menu.ts +144 -0
  78. package/src/agents/workflow/ui/progress.ts +91 -0
  79. package/src/agents/workflow/worker/bootstrap.ts +316 -0
  80. package/src/agents/workflow/worker/flow.ts +218 -0
  81. package/src/agents/workflow/worker/index.ts +7 -0
  82. package/src/agents/workflow/worker/scope.ts +215 -0
  83. package/src/ask/.gitkeep +0 -0
  84. package/src/ask/form.ts +67 -0
  85. package/src/ask/index.ts +73 -0
  86. package/src/ask/keys.ts +32 -0
  87. package/src/ask/layout.ts +78 -0
  88. package/src/ask/queue.ts +40 -0
  89. package/src/ask/render.ts +62 -0
  90. package/src/ask/result.ts +56 -0
  91. package/src/ask/schema.ts +67 -0
  92. package/src/ask/tool-render.ts +49 -0
  93. package/src/ask/view.ts +406 -0
  94. package/src/goal/.gitkeep +0 -0
  95. package/src/goal/activity.ts +50 -0
  96. package/src/goal/commands.ts +75 -0
  97. package/src/goal/context.ts +36 -0
  98. package/src/goal/index.ts +38 -0
  99. package/src/goal/manager.ts +386 -0
  100. package/src/goal/presentation.ts +15 -0
  101. package/src/goal/render.ts +36 -0
  102. package/src/goal/snapshot.ts +78 -0
  103. package/src/goal/state.ts +39 -0
  104. package/src/goal/store.ts +59 -0
  105. package/src/goal/tools.ts +59 -0
  106. package/src/goal/wait.ts +39 -0
  107. package/src/index.ts +20 -0
  108. package/src/jobs/backends/linux-tree.ts +87 -0
  109. package/src/jobs/backends/pipe.ts +74 -0
  110. package/src/jobs/backends/process.ts +79 -0
  111. package/src/jobs/backends/pty-job.ts +45 -0
  112. package/src/jobs/backends/pty.ts +502 -0
  113. package/src/jobs/backends/windows-tree.ts +289 -0
  114. package/src/jobs/commands.ts +7 -0
  115. package/src/jobs/control.ts +13 -0
  116. package/src/jobs/index.ts +331 -0
  117. package/src/jobs/launch/config.ts +26 -0
  118. package/src/jobs/launch/name.ts +16 -0
  119. package/src/jobs/launch/presets.ts +61 -0
  120. package/src/jobs/log-viewer.ts +147 -0
  121. package/src/jobs/manager.ts +507 -0
  122. package/src/jobs/monitors/compile.ts +101 -0
  123. package/src/jobs/monitors/hands-free.ts +108 -0
  124. package/src/jobs/monitors/runtime.ts +165 -0
  125. package/src/jobs/output.ts +54 -0
  126. package/src/jobs/query.ts +62 -0
  127. package/src/jobs/render.ts +103 -0
  128. package/src/jobs/runtime.ts +89 -0
  129. package/src/jobs/state.ts +25 -0
  130. package/src/jobs/store.ts +168 -0
  131. package/src/jobs/terminal/keys.ts +292 -0
  132. package/src/jobs/terminal/protocol.ts +37 -0
  133. package/src/jobs/terminal/read.ts +131 -0
  134. package/src/jobs/terminal/render.ts +70 -0
  135. package/src/jobs/terminal/screen.ts +92 -0
  136. package/src/jobs/terminal/session.ts +100 -0
  137. package/src/jobs/terminal/shell.ts +22 -0
  138. package/src/jobs/terminal/snapshot.ts +8 -0
  139. package/src/jobs/terminal/visible-text.ts +53 -0
  140. package/src/jobs/tools.ts +203 -0
  141. package/src/jobs/types.ts +60 -0
  142. package/src/jobs/viewer/component.ts +209 -0
  143. package/src/jobs/viewer/metadata.ts +9 -0
  144. package/src/jobs/viewer.ts +149 -0
  145. package/src/jobs/workspace.ts +31 -0
  146. package/src/runtime/.gitkeep +0 -0
  147. package/src/runtime/binding.ts +26 -0
  148. package/src/runtime/cli-prompt.ts +24 -0
  149. package/src/runtime/clipboard.ts +16 -0
  150. package/src/runtime/config-edit.ts +31 -0
  151. package/src/runtime/config-fields.ts +65 -0
  152. package/src/runtime/config.ts +111 -0
  153. package/src/runtime/errors.ts +11 -0
  154. package/src/runtime/json-store.ts +156 -0
  155. package/src/runtime/notification-render.ts +35 -0
  156. package/src/runtime/notifications.ts +98 -0
  157. package/src/runtime/owner.ts +54 -0
  158. package/src/runtime/read.ts +200 -0
  159. package/src/runtime/renderers.ts +50 -0
  160. package/src/runtime/responses/index.ts +108 -0
  161. package/src/runtime/responses/payload.ts +78 -0
  162. package/src/runtime/settings/index.ts +24 -0
  163. package/src/runtime/settings/view.ts +84 -0
  164. package/src/runtime/suite.ts +192 -0
  165. package/src/runtime/text.ts +6 -0
  166. package/src/runtime/tools.ts +131 -0
  167. package/src/runtime/wait-render.ts +33 -0
  168. package/src/runtime/wait.ts +134 -0
  169. package/src/tasks/commands.ts +41 -0
  170. package/src/tasks/index.ts +305 -0
  171. package/src/tasks/model.ts +152 -0
  172. package/src/tasks/presentation.ts +40 -0
  173. package/src/tasks/query.ts +38 -0
  174. package/src/tasks/render.ts +54 -0
  175. package/src/tasks/schema.ts +25 -0
  176. package/src/tasks/store.ts +164 -0
  177. package/src/tasks/tools.ts +69 -0
  178. package/src/tasks/types.ts +61 -0
  179. package/src/tasks/viewer.ts +68 -0
  180. package/src/ui/.gitkeep +0 -0
  181. package/src/ui/actions.ts +50 -0
  182. package/src/ui/browser-chrome.ts +175 -0
  183. package/src/ui/browser.ts +292 -0
  184. package/src/ui/details.ts +111 -0
  185. package/src/ui/dock/line.ts +14 -0
  186. package/src/ui/dock/rows.ts +78 -0
  187. package/src/ui/dock.ts +224 -0
  188. package/src/ui/format.ts +25 -0
  189. package/src/ui/frame.ts +8 -0
  190. package/src/ui/inline-input.ts +98 -0
  191. package/src/ui/reading.ts +105 -0
  192. package/src/ui/rendering/builtin-command.ts +34 -0
  193. package/src/ui/rendering/command.ts +60 -0
  194. package/src/ui/rendering/read-page.ts +15 -0
  195. package/src/ui/rendering/shell/bash.ts +281 -0
  196. package/src/ui/rendering/shell/index.ts +24 -0
  197. package/src/ui/rendering/shell/powershell.ts +155 -0
  198. package/src/ui/rendering/shell/spans.ts +28 -0
  199. package/src/ui/scroll.ts +111 -0
  200. package/src/ui/select.ts +67 -0
  201. package/src/ui/status.ts +67 -0
  202. package/src/ui/structured-details.ts +41 -0
  203. package/src/ui/terminal.ts +137 -0
  204. package/src/ui/ticker.ts +18 -0
  205. package/src/ui/tool-render.ts +152 -0
  206. package/src/ui/transcript.ts +140 -0
  207. package/src/ui/viewer/agent-information.ts +34 -0
  208. package/src/ui/viewer/editor.ts +18 -0
  209. package/src/ui/viewer/navigation.ts +25 -0
  210. package/themes/oh-my-pi.json +95 -0
  211. package/third-party/UPSTREAM.md +88 -0
  212. package/third-party/licenses/.gitkeep +0 -0
  213. package/third-party/licenses/oh-my-pi.txt +23 -0
  214. package/third-party/licenses/pi-ask-user.txt +21 -0
  215. package/third-party/licenses/pi-background-jobs.txt +21 -0
  216. package/third-party/licenses/pi-goal.txt +21 -0
  217. package/third-party/licenses/pi-interactive-shell.txt +25 -0
  218. package/third-party/licenses/pi-subagents.txt +21 -0
  219. package/third-party/licenses/pi-tasks.txt +21 -0
  220. package/third-party/sources.json +111 -0
@@ -0,0 +1,281 @@
1
+ import { ShellCursor, type CommandRole, type CommandSpan } from './spans.ts';
2
+
3
+ type HereDoc = {delimiter: string; quoted: boolean; tabs: boolean};
4
+ const keywords = new Set(['if', 'then', 'else', 'elif', 'fi', 'for', 'select', 'while', 'until', 'do', 'done', 'case', 'esac', 'function', 'time', '!']);
5
+
6
+ class BashScanner extends ShellCursor {
7
+ /** A substitution/group gets its own command position and heredoc queue. */
8
+ sequence(close = ''): void {
9
+ let command = true, options = true, target = false;
10
+ let header: 'forName' | 'forIn' | 'forValues' | 'caseWord' | 'caseIn' | 'function' | 'functionBody' | undefined;
11
+ const cases: ('pattern' | 'body')[] = [], docs: HereDoc[] = [];
12
+ while (this.pos < this.code.length) {
13
+ const char = this.code[this.pos];
14
+ if (close && char === close && !(char === ')' && cases.at(-1) === 'pattern')) {
15
+ this.emit(this.pos + 1, 'operator'); return;
16
+ }
17
+ const space = this.match(/[ \t]+/y);
18
+ if (space) { this.emit(this.pos + space.length); continue; }
19
+ if (char === '\n') {
20
+ this.emit(this.pos + 1);
21
+ for (const doc of docs) this.heredoc(doc);
22
+ docs.length = 0; command = true; options = true; target = false;
23
+ if (header === 'forValues') header = undefined;
24
+ continue;
25
+ }
26
+ // Here # is at a word boundary; embedded file#name is consumed by word().
27
+ if (char === '#') {
28
+ const end = this.code.indexOf('\n', this.pos);
29
+ this.emit(end < 0 ? this.code.length : end, 'comment'); continue;
30
+ }
31
+ if (this.code.startsWith('\\\n', this.pos)) { this.emit(this.pos + 2); continue; }
32
+ if (this.code.startsWith('$((', this.pos) || this.code.startsWith('((', this.pos)) {
33
+ const length = char === '$' ? 3 : 2;
34
+ this.emit(this.pos + length, 'operator'); this.expression('))');
35
+ command = false; if (header === 'forName') header = undefined; continue;
36
+ }
37
+ if (this.code.startsWith('[[', this.pos)) {
38
+ this.emit(this.pos + 2, 'operator'); this.expression(']]'); command = false; continue;
39
+ }
40
+ // Process substitutions are words, not redirections with '(' as a target.
41
+ const process = this.code.startsWith('<(', this.pos) || this.code.startsWith('>(', this.pos);
42
+ const redirect = !process && this.match(/(?:[0-9]+|&)?(?:<<<|<<-|<<|>>|<>|>\||>|<)(?:&(?:[0-9]+|-)?)?/y);
43
+ if (redirect) {
44
+ this.emit(this.pos + redirect.length, 'operator');
45
+ if (/<<-?$/.test(redirect)) {
46
+ const whitespace = this.match(/[ \t]+/y);
47
+ if (whitespace) this.emit(this.pos + whitespace.length);
48
+ docs.push(this.delimiter(redirect.endsWith('-')));
49
+ target = false;
50
+ } else target = !/&(?:[0-9]+|-)$/.test(redirect);
51
+ continue;
52
+ }
53
+ if (char === '(' && cases.at(-1) === 'pattern') { this.emit(this.pos + 1, 'operator'); continue; }
54
+ if (char === '(') {
55
+ const empty = this.match(/\([ \t]*\)/y);
56
+ if (empty) { this.emit(this.pos + empty.length, 'operator'); command = true; continue; }
57
+ this.emit(this.pos + 1, 'operator'); this.sequence(')'); command = false; continue;
58
+ }
59
+ if (char === ')' && cases.at(-1) === 'pattern') {
60
+ this.emit(this.pos + 1, 'operator'); cases[cases.length - 1] = 'body'; command = true; continue;
61
+ }
62
+ const separator = this.match(/;;&|;;|;&|&&|\|\||\|&|[;&|]/y);
63
+ if (separator) {
64
+ this.emit(this.pos + separator.length, 'operator');
65
+ if (separator.startsWith(';;') || separator === ';&') cases[cases.length - 1] = 'pattern';
66
+ command = cases.at(-1) !== 'pattern'; options = true; target = false;
67
+ if (header === 'forValues') header = undefined;
68
+ continue;
69
+ }
70
+ const literal = this.match(/[^ \t\n;&|()<>'"\\$`]+/y);
71
+ const whole = literal && (!this.code[this.pos + literal.length] || /[ \t\n;&|()<>]/.test(this.code[this.pos + literal.length]));
72
+ if (whole && !target) {
73
+ if (header === 'forName') {
74
+ this.emit(this.pos + literal.length, 'variable'); header = 'forIn'; continue;
75
+ }
76
+ if (header === 'forIn' && literal === 'in') {
77
+ this.emit(this.pos + literal.length, 'keyword'); header = 'forValues'; continue;
78
+ }
79
+ if (header === 'caseIn' && literal === 'in') {
80
+ this.emit(this.pos + literal.length, 'keyword'); header = undefined; cases.push('pattern'); command = false; continue;
81
+ }
82
+ const patternEnd = cases.at(-1) === 'pattern' && literal === 'esac';
83
+ if ((command || patternEnd || header === 'functionBody' && literal === '{') && (keywords.has(literal) || literal === '{' || literal === '}')) {
84
+ this.emit(this.pos + literal.length, 'keyword');
85
+ if (literal === 'for' || literal === 'select') { header = 'forName'; command = false; }
86
+ else if (literal === 'case') { header = 'caseWord'; command = false; }
87
+ else if (literal === 'function') { header = 'function'; command = false; }
88
+ else if (literal === 'esac') { cases.pop(); command = false; }
89
+ else { command = !['fi', 'done', '}'].includes(literal); header = undefined; }
90
+ options = true; continue;
91
+ }
92
+ }
93
+ const assignment = command && !target && this.match(/[A-Za-z_][A-Za-z_0-9]*\+?=/y);
94
+ if (assignment) {
95
+ const name = assignment.replace(/\+?=$/, '');
96
+ this.emit(this.pos + name.length, 'variable'); this.emit(this.pos + assignment.length - name.length, 'operator');
97
+ this.word(close); continue;
98
+ }
99
+ let role: CommandRole | undefined;
100
+ if (!target && cases.at(-1) !== 'pattern' && !header) {
101
+ if (command) role = 'command';
102
+ else if (options && whole && literal === '--') options = false;
103
+ else if (options && this.match(/--?[A-Za-z_][A-Za-z_0-9-]*/y)) role = 'option';
104
+ else if (whole && /^-?\d+(?:\.\d+)?$/.test(literal)) role = 'number';
105
+ } else if (header === 'function') role = 'command';
106
+ const start = this.pos;
107
+ this.word(close, role);
108
+ if (this.pos === start) this.emit(this.pos + 1); // An unmatched closing token in a partial call remains visible.
109
+ if (target) target = false;
110
+ else if (header === 'caseWord') header = 'caseIn';
111
+ else if (header === 'function') { header = 'functionBody'; command = false; }
112
+ else if (!header && cases.at(-1) !== 'pattern') command = false;
113
+ }
114
+ }
115
+
116
+ /** Quote/expansion segments override the containing word's role without recoloring ANSI. */
117
+ private word(close: string, role?: CommandRole): void {
118
+ let optionName = role === 'option';
119
+ while (this.pos < this.code.length) {
120
+ const char = this.code[this.pos];
121
+ if (char === close || /[ \t\n;&|()]/.test(char)) return;
122
+ if (this.code.startsWith('<(', this.pos) || this.code.startsWith('>(', this.pos)) {
123
+ this.emit(this.pos + 2, 'operator'); this.sequence(')'); continue;
124
+ }
125
+ if (char === '<' || char === '>') return;
126
+ if (char === '"' || char === "'") { this.quote(char); continue; }
127
+ if (char === '$' && this.expansion()) continue;
128
+ if (char === '`') { this.emit(this.pos + 1, 'operator'); this.sequence('`'); continue; }
129
+ if (char === '\\') { this.emit(Math.min(this.pos + 2, this.code.length), role); continue; }
130
+ const text = this.match(/[^ \t\n;&|()<>'"\\$`=]+/y);
131
+ if (text) this.emit(this.pos + text.length, optionName ? 'option' : role);
132
+ else {
133
+ // --key=value highlights the name only; the value keeps its own quotes/variables.
134
+ if (char === '=' && optionName) { this.emit(this.pos + 1, 'operator'); optionName = false; role = undefined; }
135
+ else this.emit(this.pos + 1, optionName ? 'option' : role);
136
+ }
137
+ }
138
+ }
139
+
140
+ private quote(quote: string, ansi = false): void {
141
+ this.emit(this.pos + 1, 'string');
142
+ while (this.pos < this.code.length) {
143
+ const char = this.code[this.pos];
144
+ if (char === quote) { this.emit(this.pos + 1, 'string'); return; }
145
+ if (char === '\\' && (ansi || quote === '"' && /[$`"\\\n]/.test(this.code[this.pos + 1] ?? ''))) {
146
+ this.emit(Math.min(this.pos + 2, this.code.length), 'string'); continue;
147
+ }
148
+ if (quote === '"' && char === '$' && this.expansion(true)) continue;
149
+ if (quote === '"' && char === '`') { this.emit(this.pos + 1, 'operator'); this.sequence('`'); continue; }
150
+ const text = this.match(quote === "'" && !ansi ? /[^']+/y : quote === "'" ? /[^'\\]+/y : /[^"\\$`]+/y);
151
+ this.emit(this.pos + (text?.length ?? 1), 'string');
152
+ }
153
+ }
154
+
155
+ private expansion(inDouble = false): boolean {
156
+ if (this.code.startsWith('$(', this.pos)) {
157
+ const arithmetic = this.code.startsWith('$((', this.pos);
158
+ this.emit(this.pos + (arithmetic ? 3 : 2), 'operator');
159
+ if (arithmetic) this.expression('))'); else this.sequence(')');
160
+ return true;
161
+ }
162
+ if (this.code.startsWith('${', this.pos)) {
163
+ this.emit(this.pos + 2, 'variable');
164
+ let braces = 1;
165
+ while (this.pos < this.code.length) {
166
+ const char = this.code[this.pos];
167
+ if (char === '$' && this.expansion(inDouble)) continue;
168
+ // Single quotes in a double-quoted ${...} default are literal, not a new quoting scope.
169
+ if (char === '"' || char === "'" && !inDouble) { this.quote(char); continue; }
170
+ if (char === '\\') { this.emit(Math.min(this.pos + 2, this.code.length), 'variable'); continue; }
171
+ if (char === '{') braces++;
172
+ this.emit(this.pos + 1, 'variable');
173
+ if (char === '}' && --braces === 0) return true;
174
+ }
175
+ return true;
176
+ }
177
+ if (this.code.startsWith("$'", this.pos) || this.code.startsWith('$"', this.pos)) {
178
+ const quote = this.code[this.pos + 1];
179
+ this.emit(this.pos + 1, 'string'); this.quote(quote, quote === "'"); return true;
180
+ }
181
+ const variable = this.match(/\$(?:[A-Za-z_][A-Za-z_0-9]*|[0-9]+|[?@*#$!_-])/y);
182
+ if (!variable) return false;
183
+ this.emit(this.pos + variable.length, 'variable'); return true;
184
+ }
185
+
186
+ /** Test/arithmetic contexts share quoting/expansion, but never claim a bare operand is a program. */
187
+ private expression(close: string): void {
188
+ let depth = 0;
189
+ while (this.pos < this.code.length) {
190
+ if (!depth && this.code.startsWith(close, this.pos)) { this.emit(this.pos + close.length, 'operator'); return; }
191
+ const char = this.code[this.pos];
192
+ if (char === '$' && this.expansion()) continue;
193
+ if (char === '"' || char === "'") { this.quote(char); continue; }
194
+ if (char === '\\') { this.emit(Math.min(this.pos + 2, this.code.length)); continue; }
195
+ if (char === '(' || char === ')') {
196
+ depth += char === '(' ? 1 : -1; this.emit(this.pos + 1, 'operator'); continue;
197
+ }
198
+ const operator = this.match(/(?:-[A-Za-z]+\b|[+*/%<>=!&|^~?:,-]+)/y);
199
+ if (operator) { this.emit(this.pos + operator.length, 'operator'); continue; }
200
+ const number = this.match(/\d+(?:#[A-Za-z_0-9]+|\.\d+)?/y);
201
+ if (number) { this.emit(this.pos + number.length, 'number'); continue; }
202
+ const text = this.match(/[A-Za-z_][A-Za-z_0-9]*/y);
203
+ this.emit(this.pos + (text?.length ?? 1));
204
+ }
205
+ }
206
+
207
+ /** Delimiters undergo quote removal, not expansion; queued bodies begin only after the command's LF. */
208
+ private delimiter(tabs: boolean): HereDoc {
209
+ let delimiter = '', quoted = false, quote = '', ansi = false;
210
+ while (this.pos < this.code.length) {
211
+ const char = this.code[this.pos], next = this.code[this.pos + 1];
212
+ if (!quote && /[ \t\n;&|()<>]/.test(char)) break;
213
+ if (!quote && this.code.startsWith("$'", this.pos)) {
214
+ quote = "'"; ansi = true; quoted = true; this.emit(this.pos + 2, 'string');
215
+ } else if (!quote && (char === '"' || char === "'")) { quote = char; quoted = true; this.emit(this.pos + 1, 'string'); }
216
+ else if (quote && char === quote) { quote = ''; ansi = false; this.emit(this.pos + 1, 'string'); }
217
+ else if (char === '\\' && (ansi || quote !== "'")) {
218
+ if (quote === '"' && !/[$`"\\\n]/.test(next ?? '')) { delimiter += char; this.emit(this.pos + 1, 'string'); continue; }
219
+ quoted ||= next !== '\n';
220
+ const escape = ansi && this.match(/\\(?:[abefnrtv\\'"?]|[0-7]{1,3}|x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{1,8})/y);
221
+ if (escape) {
222
+ const value = escape.slice(1), named: Record<string, string> = {a: '\x07', b: '\b', e: '\x1b', f: '\f', n: '\n', r: '\r', t: '\t', v: '\v'};
223
+ const point = /^[0-7]/.test(value) ? parseInt(value, 8) : /^[xuU]/.test(value) ? parseInt(value.slice(1), 16) : undefined;
224
+ delimiter += point === undefined ? named[value] ?? value : point <= 0x10ffff ? String.fromCodePoint(point) : escape;
225
+ this.emit(this.pos + escape.length, 'string');
226
+ } else {
227
+ if (next && next !== '\n') delimiter += ansi ? `\\${next}` : next;
228
+ this.emit(Math.min(this.pos + 2, this.code.length), 'string');
229
+ }
230
+ } else { delimiter += char; this.emit(this.pos + 1, 'string'); }
231
+ }
232
+ return {delimiter, quoted, tabs};
233
+ }
234
+
235
+ private heredoc(doc: HereDoc): void {
236
+ const start = this.pos;
237
+ let scan = start, bodyEnd = this.code.length, end = bodyEnd;
238
+ while (scan < this.code.length) {
239
+ const logical: string[] = [];
240
+ const lineStart = scan;
241
+ let continuation: boolean;
242
+ do {
243
+ const newline = this.code.indexOf('\n', scan), lineEnd = newline < 0 ? this.code.length : newline;
244
+ let line = this.code.slice(scan, lineEnd);
245
+ if (doc.tabs) line = line.replace(/^\t+/, '');
246
+ let slashes = 0;
247
+ for (let i = line.length - 1; i >= 0 && line[i] === '\\'; i--) slashes++;
248
+ continuation = !doc.quoted && newline >= 0 && slashes % 2 === 1;
249
+ logical.push(continuation ? line.slice(0, -1) : line);
250
+ scan = newline < 0 ? lineEnd : lineEnd + 1;
251
+ } while (continuation);
252
+ if (logical.join('') === doc.delimiter) { bodyEnd = lineStart; end = scan; break; }
253
+ }
254
+ // Bash gathers the document before expansion. A partial ${...} cannot eat its terminator
255
+ // and the following outer command. The bounded second pass stays linear and owns no cache.
256
+ const body = new BashScanner(this.code.slice(start, bodyEnd));
257
+ body.heredocText(doc.quoted);
258
+ for (const span of body.spans) { this.emit(start + span.start); this.emit(start + span.end, span.role); }
259
+ this.emit(bodyEnd); this.emit(end, 'string');
260
+ }
261
+
262
+ private heredocText(quoted: boolean): void {
263
+ if (quoted) { this.emit(this.code.length, 'string'); return; }
264
+ while (this.pos < this.code.length) {
265
+ const char = this.code[this.pos];
266
+ if (char === '$' && this.expansion(true)) continue;
267
+ if (char === '`') { this.emit(this.pos + 1, 'operator'); this.sequence('`'); continue; }
268
+ if (char === '\\' && /[$`\\\n]/.test(this.code[this.pos + 1] ?? '')) {
269
+ this.emit(Math.min(this.pos + 2, this.code.length), 'string'); continue;
270
+ }
271
+ const text = this.match(/[^$`\\]+/y);
272
+ this.emit(this.pos + (text?.length ?? 1), 'string');
273
+ }
274
+ }
275
+ }
276
+
277
+ export function scanBash(code: string): CommandSpan[] {
278
+ const scanner = new BashScanner(code);
279
+ scanner.sequence();
280
+ return scanner.spans;
281
+ }
@@ -0,0 +1,24 @@
1
+ import type { Theme, ThemeColor } from '@earendil-works/pi-coding-agent';
2
+ import { scanBash } from './bash.ts';
3
+ import { scanPowerShell } from './powershell.ts';
4
+ import { commandColors, type CommandSpan } from './spans.ts';
5
+
6
+ export type CommandShell = 'bash' | 'powershell';
7
+ export function commandSpans(code: string, shell: CommandShell): CommandSpan[] {
8
+ return shell === 'bash' ? scanBash(code) : scanPowerShell(code);
9
+ }
10
+
11
+ /** Offsets describe sanitized source, never ANSI; plain arguments retain the theme's code foreground. */
12
+ export function colorCommand(code: string, spans: CommandSpan[], theme: Theme): string {
13
+ const pieces: string[] = [];
14
+ // Pi resets each physical line; reopen colors for multiline strings/comments before Text wraps them.
15
+ const paint = (text: string, token: ThemeColor) => text.split('\n').map(line => line ? theme.fg(token, line) : '').join('\n');
16
+ let end = 0;
17
+ for (const span of spans) {
18
+ if (span.start > end) pieces.push(paint(code.slice(end, span.start), 'mdCodeBlock'));
19
+ pieces.push(paint(code.slice(span.start, span.end), commandColors[span.role]));
20
+ end = span.end;
21
+ }
22
+ if (end < code.length) pieces.push(paint(code.slice(end), 'mdCodeBlock'));
23
+ return pieces.join('');
24
+ }
@@ -0,0 +1,155 @@
1
+ import { ShellCursor, type CommandRole, type CommandSpan } from './spans.ts';
2
+
3
+ const keywords = new Set(['if', 'else', 'elseif', 'foreach', 'return', 'do', 'while', 'until', 'begin', 'for', 'trap', 'data',
4
+ 'dynamicparam', 'end', 'break', 'throw', 'param', 'continue', 'finally', 'in', 'switch', 'exit', 'filter', 'try', 'process',
5
+ 'catch', 'hidden', 'static', 'parameter', 'function', 'class', 'enum', 'using']);
6
+ const comparisons = new Set(('and or xor not band bnot bor bxor as is isnot in notin contains notcontains ccontains cnotcontains ' +
7
+ 'icontains inotcontains eq ne gt ge lt le ceq cne cgt cge clt cle ieq ine igt ige ilt ile like notlike clike cnotlike ilike inotlike ' +
8
+ 'match notmatch cmatch cnotmatch imatch inotmatch replace creplace ireplace split csplit isplit join shl shr f').split(' '));
9
+
10
+ class PowerShellScanner extends ShellCursor {
11
+ sequence(close = '', hashtable = false): void {
12
+ let command = !hashtable, args = false, options = true, target = false, invoke = false;
13
+ while (this.pos < this.code.length) {
14
+ const char = this.code[this.pos];
15
+ if (char === close) { this.emit(this.pos + 1, 'operator'); return; }
16
+ const space = this.match(/[ \t]+/y);
17
+ if (space) { this.emit(this.pos + space.length); continue; }
18
+ if (char === '\n' || char === ';') {
19
+ this.emit(this.pos + 1, char === ';' ? 'operator' : undefined);
20
+ command = !hashtable; args = false; options = true; target = false; invoke = false; continue;
21
+ }
22
+ if (this.code.startsWith('<#', this.pos)) { this.blockComment(); continue; }
23
+ if (char === '#') {
24
+ const end = this.code.indexOf('\n', this.pos);
25
+ this.emit(end < 0 ? this.code.length : end, 'comment'); continue;
26
+ }
27
+ if (this.code.startsWith('`\n', this.pos)) { this.emit(this.pos + 2); continue; }
28
+ if (args && this.code.startsWith('--%', this.pos)) {
29
+ this.emit(this.pos + 3, 'operator');
30
+ const end = this.code.indexOf('\n', this.pos);
31
+ this.emit(end < 0 ? this.code.length : end, 'string'); continue;
32
+ }
33
+ const opening = this.match(/@['"]\n/y);
34
+ if (opening) { const quote = opening[1]; this.emit(this.pos + opening.length, 'string'); this.hereString(quote); command = false; continue; }
35
+ const redirect = this.match(/(?:[1-6]|\*)?(?:>>|>)(?:&[1-6])?/y);
36
+ if (redirect) { this.emit(this.pos + redirect.length, 'operator'); target = !/>&[1-6]$/.test(redirect); continue; }
37
+ if (char === '(' || char === '{' || this.code.startsWith('@(', this.pos) || this.code.startsWith('@{', this.pos)) {
38
+ const grouping = char === '@' ? this.code[this.pos + 1] : char;
39
+ this.emit(this.pos + (char === '@' ? 2 : 1), 'operator'); this.sequence(grouping === '(' ? ')' : '}', char === '@' && grouping === '{');
40
+ command = grouping === '{' && char !== '@'; target = false; continue;
41
+ }
42
+ const separator = this.match(/&&|\|\||\||&/y);
43
+ if (separator) {
44
+ this.emit(this.pos + separator.length, 'operator'); command = true; args = false; options = true; target = false;
45
+ invoke = separator === '&'; continue;
46
+ }
47
+ // Assignment RHS can itself be a command pipeline. '=' inside an argument is consumed by word().
48
+ const assignment = !args && this.match(/(?:\+|-|\*|\/|%|\?\?)?=/y);
49
+ if (assignment) { this.emit(this.pos + assignment.length, 'operator'); command = true; continue; }
50
+ if (!args && char === '[' && /[A-Za-z_]/.test(this.code[this.pos + 1] ?? '')) {
51
+ // Scan an incomplete nested type once, rather than retrying a greedy suffix regex at each '['.
52
+ let depth = 0;
53
+ do { const bracket = this.code[this.pos]; depth += bracket === '[' ? 1 : bracket === ']' ? -1 : 0; this.emit(this.pos + 1, 'type'); }
54
+ while (depth && this.pos < this.code.length);
55
+ command = false; continue;
56
+ }
57
+ const number = this.match(/-?(?:0x[0-9a-fA-F]+|\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)(?:[kKmMgGtTpP][bB]|[dDlLnN])?\b/y);
58
+ if (number && (!args || !this.code[this.pos + number.length] || /[ \t\n;|&(){}]/.test(this.code[this.pos + number.length]))) {
59
+ this.emit(this.pos + number.length, 'number'); command = false; target = false; continue;
60
+ }
61
+ const bare = this.match(command || args ? /[^ \t\n;|&(){}<>'"`$=]+/y : /-?[A-Za-z_][A-Za-z_0-9-]*/y);
62
+ const whole = bare && (!this.code[this.pos + bare.length] || /[ \t\n;|&(){}<>]/.test(this.code[this.pos + bare.length]));
63
+ if (whole && !target && command && keywords.has(bare.toLowerCase())) {
64
+ this.emit(this.pos + bare.length, 'keyword'); continue;
65
+ }
66
+ if (!args && whole && bare.startsWith('-') && comparisons.has(bare.toLowerCase().slice(1))) {
67
+ this.emit(this.pos + bare.length, 'operator'); continue;
68
+ }
69
+ let role: CommandRole | undefined;
70
+ if (!target && command && char !== '$' && char !== '"' && char !== "'") role = 'command';
71
+ else if (!target && args && options && whole && bare === '--') options = false;
72
+ else if (!target && args && options && this.match(/--?[A-Za-z_][A-Za-z_0-9-]*/y)) role = 'option';
73
+ const start = this.pos;
74
+ this.word(role, args || role === 'command' || invoke, close);
75
+ if (this.pos === start) {
76
+ const operator = this.match(/\+\+|--|\?\?|::|\.\.|[+*/%!,:[\]<>?=-]/y);
77
+ this.emit(this.pos + (operator?.length ?? 1), operator ? 'operator' : undefined);
78
+ } else {
79
+ if (target) target = false;
80
+ else { if (role === 'command' || invoke) args = true; command = false; invoke = false; }
81
+ }
82
+ }
83
+ }
84
+
85
+ /** Adjacent quotes/escaped spaces stay in one argument; paths are words, not '/' or ':' expressions. */
86
+ private word(role: CommandRole | undefined, argument: boolean, close: string): void {
87
+ let option = role === 'option';
88
+ while (this.pos < this.code.length) {
89
+ const char = this.code[this.pos];
90
+ if (char === close || /[ \t\n;|&(){}<>]/.test(char)) return;
91
+ if (char === '"' || char === "'") { this.quote(char); continue; }
92
+ if (char === '$' && this.expansion()) continue;
93
+ if (char === '`') { this.emit(Math.min(this.pos + 2, this.code.length), role); continue; }
94
+ if (!argument && /[=,+*/%!:[\]?-]/.test(char)) return;
95
+ if (option && (char === '=' || char === ':')) {
96
+ this.emit(this.pos + 1, 'operator'); option = false; role = undefined; continue;
97
+ }
98
+ const text = this.match(argument ? /[^ \t\n;|&(){}<>'"`$=:]+/y : /[^ \t\n;|&(){}<>'"`$=,+*/%!:[\]?-]+/y);
99
+ this.emit(this.pos + (text?.length ?? 1), role);
100
+ }
101
+ }
102
+
103
+ private expansion(): boolean {
104
+ if (this.code.startsWith('$(', this.pos)) { this.emit(this.pos + 2, 'operator'); this.sequence(')'); return true; }
105
+ if (this.code.startsWith('${', this.pos)) {
106
+ const end = this.code.indexOf('}', this.pos + 2);
107
+ this.emit(end < 0 ? this.code.length : end + 1, 'variable'); return true;
108
+ }
109
+ const variable = this.match(/\$(?:[A-Za-z_][A-Za-z_0-9:]*|[0-9]+|[?^$])/y);
110
+ if (!variable) return false;
111
+ this.emit(this.pos + variable.length, /^\$(?:true|false|null)$/i.test(variable) ? 'number' : 'variable'); return true;
112
+ }
113
+
114
+ private quote(quote: string): void {
115
+ this.emit(this.pos + 1, 'string');
116
+ while (this.pos < this.code.length) {
117
+ const char = this.code[this.pos];
118
+ if (char === quote) {
119
+ if (this.code[this.pos + 1] === quote) { this.emit(this.pos + 2, 'string'); continue; }
120
+ this.emit(this.pos + 1, 'string'); return;
121
+ }
122
+ if (quote === '"' && char === '`') { this.emit(Math.min(this.pos + 2, this.code.length), 'string'); continue; }
123
+ if (quote === '"' && char === '$' && this.expansion()) continue;
124
+ const text = this.match(quote === "'" ? /[^']+/y : /[^"`$]+/y);
125
+ this.emit(this.pos + (text?.length ?? 1), 'string');
126
+ }
127
+ }
128
+
129
+ private blockComment(): void {
130
+ let depth = 1;
131
+ this.emit(this.pos + 2, 'comment');
132
+ while (this.pos < this.code.length) {
133
+ if (this.code.startsWith('<#', this.pos)) { depth++; this.emit(this.pos + 2, 'comment'); }
134
+ else if (this.code.startsWith('#>', this.pos)) { this.emit(this.pos + 2, 'comment'); if (--depth === 0) return; }
135
+ else this.emit(this.pos + 1, 'comment');
136
+ }
137
+ }
138
+
139
+ private hereString(quote: string): void {
140
+ while (this.pos < this.code.length) {
141
+ if (this.code[this.pos - 1] === '\n' && this.code.startsWith(`${quote}@`, this.pos)) { this.emit(this.pos + 2, 'string'); return; }
142
+ const char = this.code[this.pos];
143
+ if (quote === '"' && char === '`') { this.emit(Math.min(this.pos + 2, this.code.length), 'string'); continue; }
144
+ if (quote === '"' && char === '$' && this.expansion()) continue;
145
+ const text = this.match(quote === "'" ? /[^\n]+/y : /[^\n`$]+/y);
146
+ this.emit(this.pos + (text?.length ?? 1), 'string');
147
+ }
148
+ }
149
+ }
150
+
151
+ export function scanPowerShell(code: string): CommandSpan[] {
152
+ const scanner = new PowerShellScanner(code);
153
+ scanner.sequence();
154
+ return scanner.spans;
155
+ }
@@ -0,0 +1,28 @@
1
+ import type { ThemeColor } from '@earendil-works/pi-coding-agent';
2
+
3
+ export type CommandRole = 'command' | 'keyword' | 'option' | 'type' | 'variable' | 'string' | 'operator' | 'comment' | 'number' | 'punctuation';
4
+ export interface CommandSpan { start: number; end: number; role: CommandRole }
5
+ export const commandColors: Record<CommandRole, ThemeColor> = {
6
+ command: 'syntaxFunction', keyword: 'syntaxKeyword', option: 'syntaxType', type: 'syntaxType', variable: 'syntaxVariable',
7
+ string: 'syntaxString', operator: 'syntaxOperator', comment: 'syntaxComment', number: 'syntaxNumber', punctuation: 'syntaxPunctuation',
8
+ };
9
+
10
+ /** Both shells scan the original text once; offsets never refer to HTML or generated ANSI. */
11
+ export class ShellCursor {
12
+ pos = 0;
13
+ readonly spans: CommandSpan[] = [];
14
+ constructor(readonly code: string) {}
15
+ match(pattern: RegExp): string | undefined {
16
+ // Sticky patterns avoid searching or copying every remaining suffix of a long command.
17
+ pattern.lastIndex = this.pos;
18
+ return pattern.exec(this.code)?.[0];
19
+ }
20
+ emit(end: number, role?: CommandRole): void {
21
+ if (role && end > this.pos) {
22
+ const previous = this.spans.at(-1);
23
+ if (previous?.end === this.pos && previous.role === role) previous.end = end;
24
+ else this.spans.push({start: this.pos, end, role});
25
+ }
26
+ this.pos = end;
27
+ }
28
+ }
@@ -0,0 +1,111 @@
1
+ import { stripVTControlCharacters } from 'node:util';
2
+ import { Container, Input, Key, ScrollView as NativeScrollView, matchesKey,
3
+ type Component } from '@earendil-works/pi-tui';
4
+ import { readingWindow } from './reading.ts';
5
+
6
+ /** Stable content components keep native Markdown/tool caches while the shared reader clips lines. */
7
+ class ReadingContent extends Container {
8
+ constructor(content: Component, private measured: (lines: readonly string[]) => void) { super(); this.addChild(content); }
9
+ // Container returns its cached array; the search index only reads it.
10
+ override render(width: number): readonly string[] { const lines = super.render(width); this.measured(lines); return lines; }
11
+ }
12
+
13
+ /** Search is an index, not a second viewport: Pi owns clipping, follow-end and the only offset. */
14
+ export class ScrollView extends NativeScrollView {
15
+ private lines: readonly string[] = [];
16
+ private document: ReadingContent;
17
+ private content: Component;
18
+ readonly search = new Input();
19
+ searching = false;
20
+ query = '';
21
+ hasNewOutput = false;
22
+ onScroll?: () => void;
23
+
24
+ constructor(content: Component, following = false) {
25
+ const document = new ReadingContent(content, lines => this.measured(lines));
26
+ // Reading is keyboard-driven; a hidden native scrollbar creates no activity timers.
27
+ super(document, {follow: 'end', scrollbar: 'hidden', overscroll: 'contain'});
28
+ this.document = document; this.content = content;
29
+ this.scrollTo(0, {disableFollow: !following});
30
+ this.search.onSubmit = text => { this.query = text; this.searching = false; this.find(1); };
31
+ }
32
+ get offset(): number { return this.scrollTop; }
33
+ set offset(value: number) { this.scrollTo(value, {disableFollow: true}); }
34
+ get following(): boolean { return this.isFollowingEnd; }
35
+ follow(): void { this.scrollToEnd(); this.hasNewOutput = false; }
36
+ pause(): void { this.scrollTo(this.offset, {disableFollow: true}); }
37
+ markNewOutput(): void { if (!this.following) this.hasNewOutput = true; }
38
+ private measured(lines: readonly string[]): void {
39
+ // Source events mark unread output. Layout growth (for example expanding a tool)
40
+ // only updates the search index and must not masquerade as provider output.
41
+ this.lines = lines;
42
+ }
43
+ override updateLayout(contentHeight: number, viewportHeight: number, requestRender: () => void): void {
44
+ const paused = !this.following;
45
+ super.updateLayout(contentHeight, viewportHeight, requestRender);
46
+ // Stock Pi can enable follow when a shrinking document clamps to its end. Layout
47
+ // is not a navigation action: retain an explicit pause using its public API.
48
+ if (paused) super.scrollTo(this.offset, {disableFollow: true});
49
+ if (this.following) this.hasNewOutput = false;
50
+ }
51
+ override scrollBy(lines: number): number {
52
+ const offset = this.offset, following = this.following;
53
+ const remaining = super.scrollBy(lines);
54
+ if (offset !== this.offset || following !== this.following) this.onScroll?.();
55
+ return remaining;
56
+ }
57
+ override scrollTo(offset: number, options?: Parameters<NativeScrollView['scrollTo']>[1]): void {
58
+ const previous = this.offset, following = this.following;
59
+ super.scrollTo(offset, options);
60
+ if (previous !== this.offset || following !== this.following) this.onScroll?.();
61
+ }
62
+ override scrollToEnd(): void {
63
+ const offset = this.offset, following = this.following;
64
+ super.scrollToEnd();
65
+ if (offset !== this.offset || following !== this.following) this.onScroll?.();
66
+ }
67
+ /** Stock ScrollView owns the only offset; overlays supply explicit clipping and height. */
68
+ viewport(width: number, height: number, requestRender: () => void = () => {}): string[] {
69
+ const lines = super.render(width);
70
+ this.updateLayout(lines.length, height, requestRender);
71
+ return readingWindow(lines.slice(this.offset, this.offset + height), height);
72
+ }
73
+ get position(): string { return `${this.lines.length ? this.offset + 1 : 0}/${this.lines.length}`; }
74
+ get atBottom(): boolean { return this.offset >= Math.max(0, this.lines.length - this.viewportHeight); }
75
+ setContent(content: Component): void {
76
+ if (this.content === content) return;
77
+ this.content = content; this.document.clear(); this.document.addChild(content);
78
+ }
79
+ dispose(): void {
80
+ this.onScroll = undefined;
81
+ // Detach the public layout callback without resetting the retained reading state.
82
+ this.updateLayout(this.lines.length, this.viewportHeight, () => {});
83
+ }
84
+ handleInput(data: string): void {
85
+ if (this.searching) {
86
+ if (matchesKey(data, Key.escape)) this.searching = false;
87
+ else this.search.handleInput(data);
88
+ return;
89
+ }
90
+ if (data === '/') { this.pause(); this.searching = true; return; }
91
+ if (data === 'n') { this.find(1); return; }
92
+ if (data === 'N') { this.find(-1); return; }
93
+ if (matchesKey(data, Key.home)) this.scrollTo(0, {disableFollow: true});
94
+ else if (matchesKey(data, Key.end)) this.follow();
95
+ else if (matchesKey(data, Key.up)) this.scroll(-1);
96
+ else if (matchesKey(data, Key.down)) this.scroll(1);
97
+ else if (matchesKey(data, Key.pageUp)) this.scroll(-this.viewportHeight);
98
+ else if (matchesKey(data, Key.pageDown)) this.scroll(this.viewportHeight);
99
+ }
100
+ scroll(delta: number): void { this.scrollBy(delta); if (this.following) this.hasNewOutput = false; }
101
+ private find(direction: number): void {
102
+ if (!this.query) return;
103
+ const query = this.query.toLocaleLowerCase();
104
+ for (let step = 1; step <= this.lines.length; step++) {
105
+ const index = (this.offset + direction * step + this.lines.length) % this.lines.length;
106
+ if (stripVTControlCharacters(this.lines[index]).toLocaleLowerCase().includes(query)) {
107
+ this.scrollTo(index, {disableFollow: true}); return;
108
+ }
109
+ }
110
+ }
111
+ }