@onpoint-dev-tools/crewcoder-opentui 0.0.0-stage → 0.1.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.
- package/LICENSE +191 -0
- package/README.md +262 -2
- package/THIRD_PARTY_NOTICES.md +51 -0
- package/dist/App.d.ts +16 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/App.js +428 -0
- package/dist/App.js.map +1 -0
- package/dist/Root.d.ts +11 -0
- package/dist/Root.d.ts.map +1 -0
- package/dist/Root.js +13 -0
- package/dist/Root.js.map +1 -0
- package/dist/alert-model.d.ts +31 -0
- package/dist/alert-model.d.ts.map +1 -0
- package/dist/alert-model.js +34 -0
- package/dist/alert-model.js.map +1 -0
- package/dist/args.d.ts +13 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +63 -0
- package/dist/args.js.map +1 -0
- package/dist/attachments.d.ts +29 -0
- package/dist/attachments.d.ts.map +1 -0
- package/dist/attachments.js +38 -0
- package/dist/attachments.js.map +1 -0
- package/dist/block-panels.d.ts +43 -0
- package/dist/block-panels.d.ts.map +1 -0
- package/dist/block-panels.js +210 -0
- package/dist/block-panels.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +138 -0
- package/dist/cli.js.map +1 -0
- package/dist/command-format.d.ts +18 -0
- package/dist/command-format.d.ts.map +1 -0
- package/dist/command-format.js +66 -0
- package/dist/command-format.js.map +1 -0
- package/dist/command-runner.d.ts +128 -0
- package/dist/command-runner.d.ts.map +1 -0
- package/dist/command-runner.js +571 -0
- package/dist/command-runner.js.map +1 -0
- package/dist/commands.d.ts +47 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +108 -0
- package/dist/commands.js.map +1 -0
- package/dist/components/AttachmentRow.d.ts +11 -0
- package/dist/components/AttachmentRow.d.ts.map +1 -0
- package/dist/components/AttachmentRow.js +17 -0
- package/dist/components/AttachmentRow.js.map +1 -0
- package/dist/components/Composer.d.ts +23 -0
- package/dist/components/Composer.d.ts.map +1 -0
- package/dist/components/Composer.js +45 -0
- package/dist/components/Composer.js.map +1 -0
- package/dist/components/ExtensionQuestion.d.ts +18 -0
- package/dist/components/ExtensionQuestion.d.ts.map +1 -0
- package/dist/components/ExtensionQuestion.js +45 -0
- package/dist/components/ExtensionQuestion.js.map +1 -0
- package/dist/components/GoalForm.d.ts +18 -0
- package/dist/components/GoalForm.d.ts.map +1 -0
- package/dist/components/GoalForm.js +26 -0
- package/dist/components/GoalForm.js.map +1 -0
- package/dist/components/Home.d.ts +21 -0
- package/dist/components/Home.d.ts.map +1 -0
- package/dist/components/Home.js +48 -0
- package/dist/components/Home.js.map +1 -0
- package/dist/components/MentionList.d.ts +14 -0
- package/dist/components/MentionList.d.ts.map +1 -0
- package/dist/components/MentionList.js +24 -0
- package/dist/components/MentionList.js.map +1 -0
- package/dist/components/SearchBar.d.ts +19 -0
- package/dist/components/SearchBar.d.ts.map +1 -0
- package/dist/components/SearchBar.js +28 -0
- package/dist/components/SearchBar.js.map +1 -0
- package/dist/components/Sidebar.d.ts +19 -0
- package/dist/components/Sidebar.d.ts.map +1 -0
- package/dist/components/Sidebar.js +35 -0
- package/dist/components/Sidebar.js.map +1 -0
- package/dist/components/SummaryEditor.d.ts +16 -0
- package/dist/components/SummaryEditor.d.ts.map +1 -0
- package/dist/components/SummaryEditor.js +21 -0
- package/dist/components/SummaryEditor.js.map +1 -0
- package/dist/components/Transcript.d.ts +37 -0
- package/dist/components/Transcript.d.ts.map +1 -0
- package/dist/components/Transcript.js +314 -0
- package/dist/components/Transcript.js.map +1 -0
- package/dist/components/ui/alert.d.ts +9 -0
- package/dist/components/ui/alert.d.ts.map +1 -0
- package/dist/components/ui/alert.js +18 -0
- package/dist/components/ui/alert.js.map +1 -0
- package/dist/components/ui/command-palette.d.ts +15 -0
- package/dist/components/ui/command-palette.d.ts.map +1 -0
- package/dist/components/ui/command-palette.js +14 -0
- package/dist/components/ui/command-palette.js.map +1 -0
- package/dist/components/ui/confirm.d.ts +12 -0
- package/dist/components/ui/confirm.d.ts.map +1 -0
- package/dist/components/ui/confirm.js +16 -0
- package/dist/components/ui/confirm.js.map +1 -0
- package/dist/components/ui/select.d.ts +11 -0
- package/dist/components/ui/select.d.ts.map +1 -0
- package/dist/components/ui/select.js +29 -0
- package/dist/components/ui/select.js.map +1 -0
- package/dist/components/ui/spinner.d.ts +14 -0
- package/dist/components/ui/spinner.d.ts.map +1 -0
- package/dist/components/ui/spinner.js +17 -0
- package/dist/components/ui/spinner.js.map +1 -0
- package/dist/components/ui/tool-approval.d.ts +14 -0
- package/dist/components/ui/tool-approval.d.ts.map +1 -0
- package/dist/components/ui/tool-approval.js +37 -0
- package/dist/components/ui/tool-approval.js.map +1 -0
- package/dist/components/ui/tool-call.d.ts +12 -0
- package/dist/components/ui/tool-call.d.ts.map +1 -0
- package/dist/components/ui/tool-call.js +69 -0
- package/dist/components/ui/tool-call.js.map +1 -0
- package/dist/components/ui/types.d.ts +82 -0
- package/dist/components/ui/types.d.ts.map +1 -0
- package/dist/components/ui/types.js +2 -0
- package/dist/components/ui/types.js.map +1 -0
- package/dist/crewcoder-cli.d.ts +51 -0
- package/dist/crewcoder-cli.d.ts.map +1 -0
- package/dist/crewcoder-cli.js +26 -0
- package/dist/crewcoder-cli.js.map +1 -0
- package/dist/diff-anchors.d.ts +14 -0
- package/dist/diff-anchors.d.ts.map +1 -0
- package/dist/diff-anchors.js +43 -0
- package/dist/diff-anchors.js.map +1 -0
- package/dist/footer-layout.d.ts +49 -0
- package/dist/footer-layout.d.ts.map +1 -0
- package/dist/footer-layout.js +79 -0
- package/dist/footer-layout.js.map +1 -0
- package/dist/glyphs.d.ts +32 -0
- package/dist/glyphs.d.ts.map +1 -0
- package/dist/glyphs.js +35 -0
- package/dist/glyphs.js.map +1 -0
- package/dist/goal-form.d.ts +47 -0
- package/dist/goal-form.d.ts.map +1 -0
- package/dist/goal-form.js +59 -0
- package/dist/goal-form.js.map +1 -0
- package/dist/hooks/use-animation.d.ts +6 -0
- package/dist/hooks/use-animation.d.ts.map +1 -0
- package/dist/hooks/use-animation.js +52 -0
- package/dist/hooks/use-animation.js.map +1 -0
- package/dist/hooks/use-app-colors.d.ts +6 -0
- package/dist/hooks/use-app-colors.d.ts.map +1 -0
- package/dist/hooks/use-app-colors.js +6 -0
- package/dist/hooks/use-app-colors.js.map +1 -0
- package/dist/hooks/use-glyph-set.d.ts +8 -0
- package/dist/hooks/use-glyph-set.d.ts.map +1 -0
- package/dist/hooks/use-glyph-set.js +22 -0
- package/dist/hooks/use-glyph-set.js.map +1 -0
- package/dist/hooks/use-motion.d.ts +6 -0
- package/dist/hooks/use-motion.d.ts.map +1 -0
- package/dist/hooks/use-motion.js +8 -0
- package/dist/hooks/use-motion.js.map +1 -0
- package/dist/hooks/use-terminal-focus.d.ts +16 -0
- package/dist/hooks/use-terminal-focus.d.ts.map +1 -0
- package/dist/hooks/use-terminal-focus.js +30 -0
- package/dist/hooks/use-terminal-focus.js.map +1 -0
- package/dist/hooks/use-theme.d.ts +6 -0
- package/dist/hooks/use-theme.d.ts.map +1 -0
- package/dist/hooks/use-theme.js +11 -0
- package/dist/hooks/use-theme.js.map +1 -0
- package/dist/hunk.d.ts +27 -0
- package/dist/hunk.d.ts.map +1 -0
- package/dist/hunk.js +43 -0
- package/dist/hunk.js.map +1 -0
- package/dist/image-view.d.ts +33 -0
- package/dist/image-view.d.ts.map +1 -0
- package/dist/image-view.js +51 -0
- package/dist/image-view.js.map +1 -0
- package/dist/keybindings.d.ts +28 -0
- package/dist/keybindings.d.ts.map +1 -0
- package/dist/keybindings.js +105 -0
- package/dist/keybindings.js.map +1 -0
- package/dist/lib/terminal-themes/default.d.ts +3 -0
- package/dist/lib/terminal-themes/default.d.ts.map +1 -0
- package/dist/lib/terminal-themes/default.js +49 -0
- package/dist/lib/terminal-themes/default.js.map +1 -0
- package/dist/logo-pulse.d.ts +23 -0
- package/dist/logo-pulse.d.ts.map +1 -0
- package/dist/logo-pulse.js +30 -0
- package/dist/logo-pulse.js.map +1 -0
- package/dist/markdown-style.d.ts +47 -0
- package/dist/markdown-style.d.ts.map +1 -0
- package/dist/markdown-style.js +138 -0
- package/dist/markdown-style.js.map +1 -0
- package/dist/mentions.d.ts +57 -0
- package/dist/mentions.d.ts.map +1 -0
- package/dist/mentions.js +109 -0
- package/dist/mentions.js.map +1 -0
- package/dist/palette-model.d.ts +42 -0
- package/dist/palette-model.d.ts.map +1 -0
- package/dist/palette-model.js +77 -0
- package/dist/palette-model.js.map +1 -0
- package/dist/path-suggestions.d.ts +50 -0
- package/dist/path-suggestions.d.ts.map +1 -0
- package/dist/path-suggestions.js +99 -0
- package/dist/path-suggestions.js.map +1 -0
- package/dist/picker-flows.d.ts +78 -0
- package/dist/picker-flows.d.ts.map +1 -0
- package/dist/picker-flows.js +444 -0
- package/dist/picker-flows.js.map +1 -0
- package/dist/pickers.d.ts +34 -0
- package/dist/pickers.d.ts.map +1 -0
- package/dist/pickers.js +136 -0
- package/dist/pickers.js.map +1 -0
- package/dist/prompt-history.d.ts +32 -0
- package/dist/prompt-history.d.ts.map +1 -0
- package/dist/prompt-history.js +40 -0
- package/dist/prompt-history.js.map +1 -0
- package/dist/providers/app-theme-provider.d.ts +12 -0
- package/dist/providers/app-theme-provider.d.ts.map +1 -0
- package/dist/providers/app-theme-provider.js +14 -0
- package/dist/providers/app-theme-provider.js.map +1 -0
- package/dist/providers/theme-provider.d.ts +10 -0
- package/dist/providers/theme-provider.d.ts.map +1 -0
- package/dist/providers/theme-provider.js +57 -0
- package/dist/providers/theme-provider.js.map +1 -0
- package/dist/question-model.d.ts +71 -0
- package/dist/question-model.d.ts.map +1 -0
- package/dist/question-model.js +176 -0
- package/dist/question-model.js.map +1 -0
- package/dist/search-controller.d.ts +46 -0
- package/dist/search-controller.d.ts.map +1 -0
- package/dist/search-controller.js +89 -0
- package/dist/search-controller.js.map +1 -0
- package/dist/search-jump.d.ts +27 -0
- package/dist/search-jump.d.ts.map +1 -0
- package/dist/search-jump.js +65 -0
- package/dist/search-jump.js.map +1 -0
- package/dist/session-controller.d.ts +268 -0
- package/dist/session-controller.d.ts.map +1 -0
- package/dist/session-controller.js +941 -0
- package/dist/session-controller.js.map +1 -0
- package/dist/sidebar-model.d.ts +45 -0
- package/dist/sidebar-model.d.ts.map +1 -0
- package/dist/sidebar-model.js +223 -0
- package/dist/sidebar-model.js.map +1 -0
- package/dist/sidebar.d.ts +49 -0
- package/dist/sidebar.d.ts.map +1 -0
- package/dist/sidebar.js +106 -0
- package/dist/sidebar.js.map +1 -0
- package/dist/status-line.d.ts +32 -0
- package/dist/status-line.d.ts.map +1 -0
- package/dist/status-line.js +69 -0
- package/dist/status-line.js.map +1 -0
- package/dist/syntax/filetype.d.ts +12 -0
- package/dist/syntax/filetype.d.ts.map +1 -0
- package/dist/syntax/filetype.js +28 -0
- package/dist/syntax/filetype.js.map +1 -0
- package/dist/syntax/grammars.d.ts +42 -0
- package/dist/syntax/grammars.d.ts.map +1 -0
- package/dist/syntax/grammars.js +52 -0
- package/dist/syntax/grammars.js.map +1 -0
- package/dist/text-offset.d.ts +5 -0
- package/dist/text-offset.d.ts.map +1 -0
- package/dist/text-offset.js +38 -0
- package/dist/text-offset.js.map +1 -0
- package/dist/text-wrap.d.ts +12 -0
- package/dist/text-wrap.d.ts.map +1 -0
- package/dist/text-wrap.js +53 -0
- package/dist/text-wrap.js.map +1 -0
- package/dist/theme-controller.d.ts +77 -0
- package/dist/theme-controller.d.ts.map +1 -0
- package/dist/theme-controller.js +178 -0
- package/dist/theme-controller.js.map +1 -0
- package/dist/theme.d.ts +51 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +86 -0
- package/dist/theme.js.map +1 -0
- package/dist/tmux-check.d.ts +35 -0
- package/dist/tmux-check.d.ts.map +1 -0
- package/dist/tmux-check.js +66 -0
- package/dist/tmux-check.js.map +1 -0
- package/dist/tmux.d.ts +69 -0
- package/dist/tmux.d.ts.map +1 -0
- package/dist/tmux.js +135 -0
- package/dist/tmux.js.map +1 -0
- package/dist/tool-diff.d.ts +51 -0
- package/dist/tool-diff.d.ts.map +1 -0
- package/dist/tool-diff.js +158 -0
- package/dist/tool-diff.js.map +1 -0
- package/dist/tool-presentation.d.ts +46 -0
- package/dist/tool-presentation.d.ts.map +1 -0
- package/dist/tool-presentation.js +148 -0
- package/dist/tool-presentation.js.map +1 -0
- package/dist/tool-renderer-view.d.ts +14 -0
- package/dist/tool-renderer-view.d.ts.map +1 -0
- package/dist/tool-renderer-view.js +10 -0
- package/dist/tool-renderer-view.js.map +1 -0
- package/dist/transcript-search.d.ts +54 -0
- package/dist/transcript-search.d.ts.map +1 -0
- package/dist/transcript-search.js +160 -0
- package/dist/transcript-search.js.map +1 -0
- package/dist/transcript.d.ts +59 -0
- package/dist/transcript.d.ts.map +1 -0
- package/dist/transcript.js +123 -0
- package/dist/transcript.js.map +1 -0
- package/dist/workflow-tools.d.ts +42 -0
- package/dist/workflow-tools.d.ts.map +1 -0
- package/dist/workflow-tools.js +89 -0
- package/dist/workflow-tools.js.map +1 -0
- package/examples/themes/ember.json +75 -0
- package/grammars/bash/LICENSE +21 -0
- package/grammars/bash/highlights.scm +56 -0
- package/grammars/bash/tree-sitter-bash.wasm +0 -0
- package/grammars/css/LICENSE +21 -0
- package/grammars/css/highlights.scm +76 -0
- package/grammars/css/tree-sitter-css.wasm +0 -0
- package/grammars/go/LICENSE +21 -0
- package/grammars/go/highlights.scm +123 -0
- package/grammars/go/tree-sitter-go.wasm +0 -0
- package/grammars/html/LICENSE +21 -0
- package/grammars/html/highlights.scm +13 -0
- package/grammars/html/tree-sitter-html.wasm +0 -0
- package/grammars/json/LICENSE +21 -0
- package/grammars/json/highlights.scm +16 -0
- package/grammars/json/tree-sitter-json.wasm +0 -0
- package/grammars/python/LICENSE +21 -0
- package/grammars/python/highlights.scm +137 -0
- package/grammars/python/tree-sitter-python.wasm +0 -0
- package/grammars/rust/LICENSE +21 -0
- package/grammars/rust/highlights.scm +161 -0
- package/grammars/rust/tree-sitter-rust.wasm +0 -0
- package/grammars/yaml/LICENSE +20 -0
- package/grammars/yaml/highlights.scm +79 -0
- package/grammars/yaml/tree-sitter-yaml.wasm +0 -0
- package/package.json +56 -5
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { TuiEventBlock } from "@onpoint-dev-tools/crewcoder-tui-core/state/tui-store";
|
|
2
|
+
/**
|
|
3
|
+
* Pure model for extension UI questions (`extension_ui_request`). The footer
|
|
4
|
+
* sizer, `App`, and `ExtensionQuestion` all derive rows from `questionView`, so
|
|
5
|
+
* the footer height always equals what renders and the cursor indexes the same
|
|
6
|
+
* options that are drawn.
|
|
7
|
+
*
|
|
8
|
+
* Question text, option labels, and option descriptions wrap rather than
|
|
9
|
+
* truncate: agent-authored questions are usually a full sentence and their
|
|
10
|
+
* options carry the rationale needed to choose (see the legacy
|
|
11
|
+
* `ExtensionUiOverlay`).
|
|
12
|
+
*/
|
|
13
|
+
export type QuestionBlock = Extract<TuiEventBlock, {
|
|
14
|
+
type: "extension_ui";
|
|
15
|
+
}>;
|
|
16
|
+
/** The value written back over the `ui_response` control channel; `null` cancels. */
|
|
17
|
+
export type QuestionAnswer = string | boolean | null;
|
|
18
|
+
export type QuestionOption = {
|
|
19
|
+
label: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
};
|
|
22
|
+
/** One drawn row of an option list; every row of an option maps back to it (mouse clicks). */
|
|
23
|
+
export type OptionRow = {
|
|
24
|
+
option: number;
|
|
25
|
+
text: string;
|
|
26
|
+
kind: "label" | "description" | "spacer";
|
|
27
|
+
leading: boolean;
|
|
28
|
+
};
|
|
29
|
+
export type QuestionLine = {
|
|
30
|
+
text: string;
|
|
31
|
+
title: boolean;
|
|
32
|
+
};
|
|
33
|
+
export type QuestionView = {
|
|
34
|
+
kind: QuestionBlock["uiKind"];
|
|
35
|
+
/** Visible question lines (title, then message), windowed by `offset`. */
|
|
36
|
+
question: QuestionLine[];
|
|
37
|
+
/** The question is longer than its share; a scroll hint row is drawn. */
|
|
38
|
+
clipped: boolean;
|
|
39
|
+
/** The applied (clamped) question scroll offset. */
|
|
40
|
+
offset: number;
|
|
41
|
+
/** Declarative component content (`component` kind). */
|
|
42
|
+
body: string[];
|
|
43
|
+
/** Visible option rows (select options or component actions), windowed around the cursor. */
|
|
44
|
+
options: OptionRow[];
|
|
45
|
+
/** The applied (clamped) cursor. */
|
|
46
|
+
cursor: number;
|
|
47
|
+
/** Total rows, including border, separator, and hint. */
|
|
48
|
+
height: number;
|
|
49
|
+
};
|
|
50
|
+
/** Border (2) + blank row between question and reply (1) + hint row (1). */
|
|
51
|
+
export declare const QUESTION_CHROME_ROWS = 4;
|
|
52
|
+
/** Border (2) + left/right padding (2). */
|
|
53
|
+
export declare const QUESTION_HORIZONTAL_CHROME = 4;
|
|
54
|
+
/** Most rows the question card may take on a terminal this tall. */
|
|
55
|
+
export declare function questionMaxRows(terminalHeight: number): number;
|
|
56
|
+
/** Text columns inside the card on a terminal this wide. */
|
|
57
|
+
export declare function questionContentWidth(terminalWidth: number): number;
|
|
58
|
+
/** Choices the cursor moves over: select options, component actions, or Yes/No. */
|
|
59
|
+
export declare function questionChoices(block: QuestionBlock): QuestionOption[];
|
|
60
|
+
/** The answer for the choice at `cursor`. Input answers come from the text field instead. */
|
|
61
|
+
export declare function choiceAnswer(block: QuestionBlock, cursor: number): QuestionAnswer;
|
|
62
|
+
export declare function questionView(block: QuestionBlock, width: number, maxRows: number, cursor?: number, offset?: number): QuestionView;
|
|
63
|
+
/** Word-wrap `text` to `width` columns, splitting words longer than a row. */
|
|
64
|
+
export declare function wrapText(text: string, width: number): string[];
|
|
65
|
+
/**
|
|
66
|
+
* Bulleted, wrapped label rows, then the description indented beneath them. A
|
|
67
|
+
* blank row separates options only when some option has a description, so a
|
|
68
|
+
* plain list stays compact.
|
|
69
|
+
*/
|
|
70
|
+
export declare function optionRows(options: readonly QuestionOption[], width: number): OptionRow[];
|
|
71
|
+
//# sourceMappingURL=question-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question-model.d.ts","sourceRoot":"","sources":["../src/question-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uDAAuD,CAAC;AAG3F;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,EAAE;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC,CAAC;AAE7E,qFAAqF;AACrF,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAErD,MAAM,MAAM,cAAc,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErE,8FAA8F;AAC9F,MAAM,MAAM,SAAS,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,GAAG,aAAa,GAAG,QAAQ,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAErH,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAE5D,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC9B,0EAA0E;IAC1E,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,yEAAyE;IACzE,OAAO,EAAE,OAAO,CAAC;IACjB,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,6FAA6F;IAC7F,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,IAAI,CAAC;AACtC,2CAA2C;AAC3C,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAU5C,oEAAoE;AACpE,wBAAgB,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED,4DAA4D;AAC5D,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,mFAAmF;AACnF,wBAAgB,eAAe,CAAC,KAAK,EAAE,aAAa,GAAG,cAAc,EAAE,CAKtE;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAKjF;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAI,EAAE,MAAM,SAAI,GAAG,YAAY,CA+BvH;AAED,8EAA8E;AAC9E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAqB9D;AAWD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAczF"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { normalize } from "./transcript.js";
|
|
2
|
+
/** Border (2) + blank row between question and reply (1) + hint row (1). */
|
|
3
|
+
export const QUESTION_CHROME_ROWS = 4;
|
|
4
|
+
/** Border (2) + left/right padding (2). */
|
|
5
|
+
export const QUESTION_HORIZONTAL_CHROME = 4;
|
|
6
|
+
/** Reply rows kept visible before a long question is windowed. */
|
|
7
|
+
const REPLY_RESERVE_ROWS = 6;
|
|
8
|
+
const MAX_QUESTION_ROWS = 30;
|
|
9
|
+
const MAX_COMPONENT_ROWS = 8;
|
|
10
|
+
const MAX_TABLE_COLUMNS = 4;
|
|
11
|
+
const MAX_TABLE_ROWS = 6;
|
|
12
|
+
const LABEL_INDENT = 2;
|
|
13
|
+
const DESCRIPTION_INDENT = 4;
|
|
14
|
+
/** Most rows the question card may take on a terminal this tall. */
|
|
15
|
+
export function questionMaxRows(terminalHeight) {
|
|
16
|
+
return Math.max(QUESTION_CHROME_ROWS + 2, Math.min(MAX_QUESTION_ROWS, terminalHeight - 2));
|
|
17
|
+
}
|
|
18
|
+
/** Text columns inside the card on a terminal this wide. */
|
|
19
|
+
export function questionContentWidth(terminalWidth) {
|
|
20
|
+
return Math.max(8, terminalWidth - QUESTION_HORIZONTAL_CHROME);
|
|
21
|
+
}
|
|
22
|
+
/** Choices the cursor moves over: select options, component actions, or Yes/No. */
|
|
23
|
+
export function questionChoices(block) {
|
|
24
|
+
if (block.uiKind === "select")
|
|
25
|
+
return (block.options ?? []).map(({ label, description }) => ({ label: normalize(label), description: description ? normalize(description) : undefined }));
|
|
26
|
+
if (block.uiKind === "component")
|
|
27
|
+
return componentActions(block).map(({ label, description }) => ({ label: normalize(label), description: description ? normalize(description) : undefined }));
|
|
28
|
+
if (block.uiKind === "confirm")
|
|
29
|
+
return [{ label: "Yes" }, { label: "No" }];
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
/** The answer for the choice at `cursor`. Input answers come from the text field instead. */
|
|
33
|
+
export function choiceAnswer(block, cursor) {
|
|
34
|
+
if (block.uiKind === "confirm")
|
|
35
|
+
return cursor === 0;
|
|
36
|
+
if (block.uiKind === "select")
|
|
37
|
+
return block.options?.[cursor]?.value ?? null;
|
|
38
|
+
if (block.uiKind === "component")
|
|
39
|
+
return componentActions(block)[cursor]?.id ?? "close";
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
export function questionView(block, width, maxRows, cursor = 0, offset = 0) {
|
|
43
|
+
const inner = Math.max(1, maxRows - QUESTION_CHROME_ROWS);
|
|
44
|
+
const choices = questionChoices(block);
|
|
45
|
+
const clampedCursor = Math.max(0, Math.min(Math.max(0, choices.length - 1), cursor));
|
|
46
|
+
const allOptions = block.uiKind === "select" || block.uiKind === "component" ? optionRows(choices, width) : [];
|
|
47
|
+
const allBody = block.uiKind === "component" ? componentBody(block, width) : [];
|
|
48
|
+
const replyFull = block.uiKind === "component"
|
|
49
|
+
? allBody.length + (allBody.length ? 1 : 0) + allOptions.length
|
|
50
|
+
: block.uiKind === "select" ? Math.max(1, allOptions.length) : 1;
|
|
51
|
+
const allQuestion = questionLines(block, width);
|
|
52
|
+
const questionBudget = Math.max(1, inner - Math.min(replyFull, REPLY_RESERVE_ROWS));
|
|
53
|
+
const clipped = allQuestion.length > questionBudget;
|
|
54
|
+
const shown = clipped ? Math.max(1, questionBudget - 1) : allQuestion.length;
|
|
55
|
+
const appliedOffset = Math.max(0, Math.min(allQuestion.length - shown, offset));
|
|
56
|
+
const question = allQuestion.slice(appliedOffset, appliedOffset + shown);
|
|
57
|
+
const replyBudget = Math.max(1, inner - shown - (clipped ? 1 : 0));
|
|
58
|
+
let body = [];
|
|
59
|
+
let options = [];
|
|
60
|
+
if (block.uiKind === "select") {
|
|
61
|
+
options = windowOptions(allOptions, clampedCursor, replyBudget);
|
|
62
|
+
}
|
|
63
|
+
else if (block.uiKind === "component") {
|
|
64
|
+
options = windowOptions(allOptions, clampedCursor, Math.max(1, Math.min(allOptions.length, replyBudget - 2)));
|
|
65
|
+
body = allBody.slice(0, Math.max(0, replyBudget - options.length - 1));
|
|
66
|
+
}
|
|
67
|
+
const replyRows = block.uiKind === "component"
|
|
68
|
+
? body.length + (body.length ? 1 : 0) + options.length
|
|
69
|
+
: block.uiKind === "select" ? Math.max(1, options.length) : 1;
|
|
70
|
+
const height = QUESTION_CHROME_ROWS + question.length + (clipped ? 1 : 0) + replyRows;
|
|
71
|
+
return { kind: block.uiKind, question, clipped, offset: appliedOffset, body, options, cursor: clampedCursor, height };
|
|
72
|
+
}
|
|
73
|
+
/** Word-wrap `text` to `width` columns, splitting words longer than a row. */
|
|
74
|
+
export function wrapText(text, width) {
|
|
75
|
+
const columns = Math.max(1, Math.floor(width));
|
|
76
|
+
const lines = [];
|
|
77
|
+
for (const logical of text.split("\n")) {
|
|
78
|
+
let line = "";
|
|
79
|
+
for (const word of logical.split(/\s+/).filter(Boolean)) {
|
|
80
|
+
let rest = word;
|
|
81
|
+
if (line && line.length + 1 + rest.length <= columns) {
|
|
82
|
+
line = `${line} ${rest}`;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (line)
|
|
86
|
+
lines.push(line);
|
|
87
|
+
while (rest.length > columns) {
|
|
88
|
+
lines.push(rest.slice(0, columns));
|
|
89
|
+
rest = rest.slice(columns);
|
|
90
|
+
}
|
|
91
|
+
line = rest;
|
|
92
|
+
}
|
|
93
|
+
lines.push(line);
|
|
94
|
+
}
|
|
95
|
+
return lines;
|
|
96
|
+
}
|
|
97
|
+
function questionLines(block, width) {
|
|
98
|
+
const lines = wrapText(normalize(block.title), width).map((text) => ({ text, title: true }));
|
|
99
|
+
if (block.message) {
|
|
100
|
+
lines.push({ text: "", title: false });
|
|
101
|
+
for (const text of wrapText(normalize(block.message), width))
|
|
102
|
+
lines.push({ text, title: false });
|
|
103
|
+
}
|
|
104
|
+
return lines;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Bulleted, wrapped label rows, then the description indented beneath them. A
|
|
108
|
+
* blank row separates options only when some option has a description, so a
|
|
109
|
+
* plain list stays compact.
|
|
110
|
+
*/
|
|
111
|
+
export function optionRows(options, width) {
|
|
112
|
+
const spaced = options.some((option) => option.description);
|
|
113
|
+
const rows = [];
|
|
114
|
+
options.forEach((option, index) => {
|
|
115
|
+
if (index > 0 && spaced)
|
|
116
|
+
rows.push({ option: -1, text: "", kind: "spacer", leading: false });
|
|
117
|
+
wrapText(option.label, Math.max(1, width - LABEL_INDENT)).forEach((text, line) => {
|
|
118
|
+
rows.push({ option: index, text, kind: "label", leading: line === 0 });
|
|
119
|
+
});
|
|
120
|
+
if (!option.description)
|
|
121
|
+
return;
|
|
122
|
+
for (const text of wrapText(option.description, Math.max(1, width - DESCRIPTION_INDENT))) {
|
|
123
|
+
rows.push({ option: index, text, kind: "description", leading: false });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return rows;
|
|
127
|
+
}
|
|
128
|
+
/** Scroll the option rows so the whole selected option stays visible. */
|
|
129
|
+
function windowOptions(rows, selected, height) {
|
|
130
|
+
if (rows.length <= height)
|
|
131
|
+
return rows;
|
|
132
|
+
const first = rows.findIndex((row) => row.option === selected);
|
|
133
|
+
if (first < 0)
|
|
134
|
+
return rows.slice(0, height);
|
|
135
|
+
let last = first;
|
|
136
|
+
while (last + 1 < rows.length && rows[last + 1].option === selected)
|
|
137
|
+
last += 1;
|
|
138
|
+
const start = last >= height ? Math.min(last - height + 1, rows.length - height) : 0;
|
|
139
|
+
const from = Math.max(0, Math.min(start, first));
|
|
140
|
+
return rows.slice(from, from + height);
|
|
141
|
+
}
|
|
142
|
+
function componentActions(block) {
|
|
143
|
+
if (block.actions?.length)
|
|
144
|
+
return block.actions;
|
|
145
|
+
if (block.component?.kind === "actionList")
|
|
146
|
+
return block.component.actions;
|
|
147
|
+
return [{ id: "close", label: "Close" }];
|
|
148
|
+
}
|
|
149
|
+
/** Plain-text rows for a declarative component. `actionList` has none: its actions are the choices. */
|
|
150
|
+
function componentBody(block, width) {
|
|
151
|
+
const component = block.component;
|
|
152
|
+
if (!component)
|
|
153
|
+
return ["(component payload unavailable)"];
|
|
154
|
+
if (component.kind === "markdown")
|
|
155
|
+
return wrapText(normalize(component.text), width).slice(0, MAX_COMPONENT_ROWS);
|
|
156
|
+
if (component.kind === "details") {
|
|
157
|
+
return component.items.flatMap((item) => wrapText(`${normalize(item.label)}: ${normalize(item.value)}`, width)).slice(0, MAX_COMPONENT_ROWS);
|
|
158
|
+
}
|
|
159
|
+
if (component.kind === "table") {
|
|
160
|
+
const columns = component.columns.slice(0, MAX_TABLE_COLUMNS);
|
|
161
|
+
if (!columns.length)
|
|
162
|
+
return ["(no columns)"];
|
|
163
|
+
const cell = Math.max(4, Math.floor(width / columns.length));
|
|
164
|
+
const row = (values) => values.map((value) => fit(normalize(value), cell - 1).padEnd(cell)).join("").trimEnd();
|
|
165
|
+
return [
|
|
166
|
+
row(columns.map((column) => column.label)),
|
|
167
|
+
...component.rows.slice(0, MAX_TABLE_ROWS).map((values) => row(columns.map((column) => String(values[column.key] ?? ""))))
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
function fit(text, width) {
|
|
173
|
+
const flat = text.replace(/\s+/g, " ");
|
|
174
|
+
return flat.length <= width ? flat : `${flat.slice(0, Math.max(0, width - 1))}…`;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=question-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question-model.js","sourceRoot":"","sources":["../src/question-model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA2C5C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,2CAA2C;AAC3C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAC5C,kEAAkE;AAClE,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B,oEAAoE;AACpE,MAAM,UAAU,eAAe,CAAC,cAAsB;IACpD,OAAO,IAAI,CAAC,GAAG,CAAC,oBAAoB,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE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GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7D,MAAM,GAAG,GAAG,CAAC,MAAgB,EAAU,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACjI,OAAO;YACL,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1C,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;SAC3H,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,GAAG,CAAC,IAAY,EAAE,KAAa;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACvC,OAAO,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AACnF,CAAC","sourcesContent":["import type { TuiEventBlock } from \"@onpoint-dev-tools/crewcoder-tui-core/state/tui-store\";\nimport { normalize } from \"./transcript.js\";\n\n/**\n * Pure model for extension UI questions (`extension_ui_request`). The footer\n * sizer, `App`, and `ExtensionQuestion` all derive rows from `questionView`, so\n * the footer height always equals what renders and the cursor indexes the same\n * options that are drawn.\n *\n * Question text, option labels, and option descriptions wrap rather than\n * truncate: agent-authored questions are usually a full sentence and their\n * options carry the rationale needed to choose (see the legacy\n * `ExtensionUiOverlay`).\n */\nexport type QuestionBlock = Extract<TuiEventBlock, { type: \"extension_ui\" }>;\n\n/** The value written back over the `ui_response` control channel; `null` cancels. */\nexport type QuestionAnswer = string | boolean | null;\n\nexport type QuestionOption = { label: string; description?: string };\n\n/** One drawn row of an option list; every row of an option maps back to it (mouse clicks). */\nexport type OptionRow = { option: number; text: string; kind: \"label\" | \"description\" | \"spacer\"; leading: boolean };\n\nexport type QuestionLine = { text: string; title: boolean };\n\nexport type QuestionView = {\n kind: QuestionBlock[\"uiKind\"];\n /** Visible question lines (title, then message), windowed by `offset`. */\n question: QuestionLine[];\n /** The question is longer than its share; a scroll hint row is drawn. */\n clipped: boolean;\n /** The applied (clamped) question scroll offset. */\n offset: number;\n /** Declarative component content (`component` kind). */\n body: string[];\n /** Visible option rows (select options or component actions), windowed around the cursor. */\n options: OptionRow[];\n /** The applied (clamped) cursor. */\n cursor: number;\n /** Total rows, including border, separator, and hint. */\n height: number;\n};\n\n/** Border (2) + blank row between question and reply (1) + hint row (1). */\nexport const QUESTION_CHROME_ROWS = 4;\n/** Border (2) + left/right padding (2). */\nexport const QUESTION_HORIZONTAL_CHROME = 4;\n/** Reply rows kept visible before a long question is windowed. */\nconst REPLY_RESERVE_ROWS = 6;\nconst MAX_QUESTION_ROWS = 30;\nconst MAX_COMPONENT_ROWS = 8;\nconst MAX_TABLE_COLUMNS = 4;\nconst MAX_TABLE_ROWS = 6;\nconst LABEL_INDENT = 2;\nconst DESCRIPTION_INDENT = 4;\n\n/** Most rows the question card may take on a terminal this tall. */\nexport function questionMaxRows(terminalHeight: number): number {\n return Math.max(QUESTION_CHROME_ROWS + 2, Math.min(MAX_QUESTION_ROWS, terminalHeight - 2));\n}\n\n/** Text columns inside the card on a terminal this wide. */\nexport function questionContentWidth(terminalWidth: number): number {\n return Math.max(8, terminalWidth - QUESTION_HORIZONTAL_CHROME);\n}\n\n/** Choices the cursor moves over: select options, component actions, or Yes/No. */\nexport function questionChoices(block: QuestionBlock): QuestionOption[] {\n if (block.uiKind === \"select\") return (block.options ?? []).map(({ label, description }) => ({ label: normalize(label), description: description ? normalize(description) : undefined }));\n if (block.uiKind === \"component\") return componentActions(block).map(({ label, description }) => ({ label: normalize(label), description: description ? normalize(description) : undefined }));\n if (block.uiKind === \"confirm\") return [{ label: \"Yes\" }, { label: \"No\" }];\n return [];\n}\n\n/** The answer for the choice at `cursor`. Input answers come from the text field instead. */\nexport function choiceAnswer(block: QuestionBlock, cursor: number): QuestionAnswer {\n if (block.uiKind === \"confirm\") return cursor === 0;\n if (block.uiKind === \"select\") return block.options?.[cursor]?.value ?? null;\n if (block.uiKind === \"component\") return componentActions(block)[cursor]?.id ?? \"close\";\n return null;\n}\n\nexport function questionView(block: QuestionBlock, width: number, maxRows: number, cursor = 0, offset = 0): QuestionView {\n const inner = Math.max(1, maxRows - QUESTION_CHROME_ROWS);\n const choices = questionChoices(block);\n const clampedCursor = Math.max(0, Math.min(Math.max(0, choices.length - 1), cursor));\n const allOptions = block.uiKind === \"select\" || block.uiKind === \"component\" ? optionRows(choices, width) : [];\n const allBody = block.uiKind === \"component\" ? componentBody(block, width) : [];\n const replyFull = block.uiKind === \"component\"\n ? allBody.length + (allBody.length ? 1 : 0) + allOptions.length\n : block.uiKind === \"select\" ? Math.max(1, allOptions.length) : 1;\n\n const allQuestion = questionLines(block, width);\n const questionBudget = Math.max(1, inner - Math.min(replyFull, REPLY_RESERVE_ROWS));\n const clipped = allQuestion.length > questionBudget;\n const shown = clipped ? Math.max(1, questionBudget - 1) : allQuestion.length;\n const appliedOffset = Math.max(0, Math.min(allQuestion.length - shown, offset));\n const question = allQuestion.slice(appliedOffset, appliedOffset + shown);\n\n const replyBudget = Math.max(1, inner - shown - (clipped ? 1 : 0));\n let body: string[] = [];\n let options: OptionRow[] = [];\n if (block.uiKind === \"select\") {\n options = windowOptions(allOptions, clampedCursor, replyBudget);\n } else if (block.uiKind === \"component\") {\n options = windowOptions(allOptions, clampedCursor, Math.max(1, Math.min(allOptions.length, replyBudget - 2)));\n body = allBody.slice(0, Math.max(0, replyBudget - options.length - 1));\n }\n const replyRows = block.uiKind === \"component\"\n ? body.length + (body.length ? 1 : 0) + options.length\n : block.uiKind === \"select\" ? Math.max(1, options.length) : 1;\n const height = QUESTION_CHROME_ROWS + question.length + (clipped ? 1 : 0) + replyRows;\n return { kind: block.uiKind, question, clipped, offset: appliedOffset, body, options, cursor: clampedCursor, height };\n}\n\n/** Word-wrap `text` to `width` columns, splitting words longer than a row. */\nexport function wrapText(text: string, width: number): string[] {\n const columns = Math.max(1, Math.floor(width));\n const lines: string[] = [];\n for (const logical of text.split(\"\\n\")) {\n let line = \"\";\n for (const word of logical.split(/\\s+/).filter(Boolean)) {\n let rest = word;\n if (line && line.length + 1 + rest.length <= columns) {\n line = `${line} ${rest}`;\n continue;\n }\n if (line) lines.push(line);\n while (rest.length > columns) {\n lines.push(rest.slice(0, columns));\n rest = rest.slice(columns);\n }\n line = rest;\n }\n lines.push(line);\n }\n return lines;\n}\n\nfunction questionLines(block: QuestionBlock, width: number): QuestionLine[] {\n const lines = wrapText(normalize(block.title), width).map((text) => ({ text, title: true }));\n if (block.message) {\n lines.push({ text: \"\", title: false });\n for (const text of wrapText(normalize(block.message), width)) lines.push({ text, title: false });\n }\n return lines;\n}\n\n/**\n * Bulleted, wrapped label rows, then the description indented beneath them. A\n * blank row separates options only when some option has a description, so a\n * plain list stays compact.\n */\nexport function optionRows(options: readonly QuestionOption[], width: number): OptionRow[] {\n const spaced = options.some((option) => option.description);\n const rows: OptionRow[] = [];\n options.forEach((option, index) => {\n if (index > 0 && spaced) rows.push({ option: -1, text: \"\", kind: \"spacer\", leading: false });\n wrapText(option.label, Math.max(1, width - LABEL_INDENT)).forEach((text, line) => {\n rows.push({ option: index, text, kind: \"label\", leading: line === 0 });\n });\n if (!option.description) return;\n for (const text of wrapText(option.description, Math.max(1, width - DESCRIPTION_INDENT))) {\n rows.push({ option: index, text, kind: \"description\", leading: false });\n }\n });\n return rows;\n}\n\n/** Scroll the option rows so the whole selected option stays visible. */\nfunction windowOptions(rows: OptionRow[], selected: number, height: number): OptionRow[] {\n if (rows.length <= height) return rows;\n const first = rows.findIndex((row) => row.option === selected);\n if (first < 0) return rows.slice(0, height);\n let last = first;\n while (last + 1 < rows.length && rows[last + 1]!.option === selected) last += 1;\n const start = last >= height ? Math.min(last - height + 1, rows.length - height) : 0;\n const from = Math.max(0, Math.min(start, first));\n return rows.slice(from, from + height);\n}\n\nfunction componentActions(block: QuestionBlock): Array<{ id: string; label: string; description?: string }> {\n if (block.actions?.length) return block.actions;\n if (block.component?.kind === \"actionList\") return block.component.actions;\n return [{ id: \"close\", label: \"Close\" }];\n}\n\n/** Plain-text rows for a declarative component. `actionList` has none: its actions are the choices. */\nfunction componentBody(block: QuestionBlock, width: number): string[] {\n const component = block.component;\n if (!component) return [\"(component payload unavailable)\"];\n if (component.kind === \"markdown\") return wrapText(normalize(component.text), width).slice(0, MAX_COMPONENT_ROWS);\n if (component.kind === \"details\") {\n return component.items.flatMap((item) => wrapText(`${normalize(item.label)}: ${normalize(item.value)}`, width)).slice(0, MAX_COMPONENT_ROWS);\n }\n if (component.kind === \"table\") {\n const columns = component.columns.slice(0, MAX_TABLE_COLUMNS);\n if (!columns.length) return [\"(no columns)\"];\n const cell = Math.max(4, Math.floor(width / columns.length));\n const row = (values: string[]): string => values.map((value) => fit(normalize(value), cell - 1).padEnd(cell)).join(\"\").trimEnd();\n return [\n row(columns.map((column) => column.label)),\n ...component.rows.slice(0, MAX_TABLE_ROWS).map((values) => row(columns.map((column) => String(values[column.key] ?? \"\"))))\n ];\n }\n return [];\n}\n\nfunction fit(text: string, width: number): string {\n const flat = text.replace(/\\s+/g, \" \");\n return flat.length <= width ? flat : `${flat.slice(0, Math.max(0, width - 1))}…`;\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { TuiState } from "@onpoint-dev-tools/crewcoder-tui-core/state/tui-store";
|
|
2
|
+
import type { ToolExpansion } from "./transcript.js";
|
|
3
|
+
import { type SearchMatch } from "./transcript-search.js";
|
|
4
|
+
/** What transcript search needs from `SessionController`. */
|
|
5
|
+
export type SearchHost = {
|
|
6
|
+
readonly state: TuiState;
|
|
7
|
+
/** Expansion state to reveal a hidden match; its line anchors keep diff lines as drawn. */
|
|
8
|
+
readonly toolExpansion: ToolExpansion;
|
|
9
|
+
changed(): void;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Transcript search state (`docs/TRANSCRIPT.md#search`): the query, its
|
|
13
|
+
* matches, and the current one. Matching is the pure `transcript-search.ts`;
|
|
14
|
+
* App scrolls to `current` and marks its line whenever `jumpVersion` changes.
|
|
15
|
+
* Search starts at the newest match, since the transcript sits at the bottom.
|
|
16
|
+
*/
|
|
17
|
+
export declare class TranscriptSearch {
|
|
18
|
+
private readonly host;
|
|
19
|
+
isOpen: boolean;
|
|
20
|
+
query: string;
|
|
21
|
+
matches: SearchMatch[];
|
|
22
|
+
/** Index into `matches`; undefined when nothing matches. */
|
|
23
|
+
index: number | undefined;
|
|
24
|
+
/** Bumped on every jump, so App scrolls again even to the same match. */
|
|
25
|
+
jumpVersion: number;
|
|
26
|
+
constructor(host: SearchHost);
|
|
27
|
+
get current(): SearchMatch | undefined;
|
|
28
|
+
open(query?: string): void;
|
|
29
|
+
/** Close the bar; the transcript stays where the last match left it. */
|
|
30
|
+
close(): void;
|
|
31
|
+
/** A new query: jump to its newest match. */
|
|
32
|
+
setQuery(query: string): void;
|
|
33
|
+
/** Enter / Up: the previous (older) match, wrapping to the newest. */
|
|
34
|
+
older(): void;
|
|
35
|
+
/** Shift+Enter / Down: the next (newer) match, wrapping to the oldest. */
|
|
36
|
+
newer(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Re-run the search first: the transcript may have grown since the last key.
|
|
39
|
+
* The step counts from the current match's new position.
|
|
40
|
+
*/
|
|
41
|
+
private step;
|
|
42
|
+
private find;
|
|
43
|
+
/** Make the current match drawable (expand collapsed output, show a hidden diff), then ask App to scroll. */
|
|
44
|
+
private jump;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=search-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-controller.d.ts","sourceRoot":"","sources":["../src/search-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uDAAuD,CAAC;AACtF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErF,6DAA6D;AAC7D,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,2FAA2F;IAC3F,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,MAAM,UAAS;IACf,KAAK,SAAM;IACX,OAAO,EAAE,WAAW,EAAE,CAAM;IAC5B,4DAA4D;IAC5D,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,yEAAyE;IACzE,WAAW,SAAK;gBAEJ,IAAI,EAAE,UAAU;IAI5B,IAAI,OAAO,IAAI,WAAW,GAAG,SAAS,CAErC;IAED,IAAI,CAAC,KAAK,SAAK,GAAG,IAAI;IAKtB,wEAAwE;IACxE,KAAK,IAAI,IAAI;IASb,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAO7B,sEAAsE;IACtE,KAAK,IAAI,IAAI;IAIb,0EAA0E;IAC1E,KAAK,IAAI,IAAI;IAIb;;;OAGG;IACH,OAAO,CAAC,IAAI;IAcZ,OAAO,CAAC,IAAI;IAKZ,6GAA6G;IAC7G,OAAO,CAAC,IAAI;CAYb"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { findMatches, revealNeeded } from "./transcript-search.js";
|
|
2
|
+
/**
|
|
3
|
+
* Transcript search state (`docs/TRANSCRIPT.md#search`): the query, its
|
|
4
|
+
* matches, and the current one. Matching is the pure `transcript-search.ts`;
|
|
5
|
+
* App scrolls to `current` and marks its line whenever `jumpVersion` changes.
|
|
6
|
+
* Search starts at the newest match, since the transcript sits at the bottom.
|
|
7
|
+
*/
|
|
8
|
+
export class TranscriptSearch {
|
|
9
|
+
host;
|
|
10
|
+
isOpen = false;
|
|
11
|
+
query = "";
|
|
12
|
+
matches = [];
|
|
13
|
+
/** Index into `matches`; undefined when nothing matches. */
|
|
14
|
+
index;
|
|
15
|
+
/** Bumped on every jump, so App scrolls again even to the same match. */
|
|
16
|
+
jumpVersion = 0;
|
|
17
|
+
constructor(host) {
|
|
18
|
+
this.host = host;
|
|
19
|
+
}
|
|
20
|
+
get current() {
|
|
21
|
+
return this.index === undefined ? undefined : this.matches[this.index];
|
|
22
|
+
}
|
|
23
|
+
open(query = "") {
|
|
24
|
+
this.isOpen = true;
|
|
25
|
+
this.setQuery(query);
|
|
26
|
+
}
|
|
27
|
+
/** Close the bar; the transcript stays where the last match left it. */
|
|
28
|
+
close() {
|
|
29
|
+
if (!this.isOpen)
|
|
30
|
+
return;
|
|
31
|
+
this.isOpen = false;
|
|
32
|
+
this.query = "";
|
|
33
|
+
this.matches = [];
|
|
34
|
+
this.index = undefined;
|
|
35
|
+
this.host.changed();
|
|
36
|
+
}
|
|
37
|
+
/** A new query: jump to its newest match. */
|
|
38
|
+
setQuery(query) {
|
|
39
|
+
this.query = query;
|
|
40
|
+
this.matches = this.find();
|
|
41
|
+
this.index = this.matches.length > 0 ? this.matches.length - 1 : undefined;
|
|
42
|
+
this.jump();
|
|
43
|
+
}
|
|
44
|
+
/** Enter / Up: the previous (older) match, wrapping to the newest. */
|
|
45
|
+
older() {
|
|
46
|
+
this.step(-1);
|
|
47
|
+
}
|
|
48
|
+
/** Shift+Enter / Down: the next (newer) match, wrapping to the oldest. */
|
|
49
|
+
newer() {
|
|
50
|
+
this.step(1);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Re-run the search first: the transcript may have grown since the last key.
|
|
54
|
+
* The step counts from the current match's new position.
|
|
55
|
+
*/
|
|
56
|
+
step(delta) {
|
|
57
|
+
const previous = this.current;
|
|
58
|
+
this.matches = this.find();
|
|
59
|
+
const count = this.matches.length;
|
|
60
|
+
if (count === 0) {
|
|
61
|
+
this.index = undefined;
|
|
62
|
+
return this.jump();
|
|
63
|
+
}
|
|
64
|
+
const at = previous ? this.matches.findIndex((match) => match.block === previous.block && match.ordinal === previous.ordinal) : -1;
|
|
65
|
+
const from = at === -1 ? (delta < 0 ? count : -1) : at;
|
|
66
|
+
this.index = (((from + delta) % count) + count) % count;
|
|
67
|
+
this.jump();
|
|
68
|
+
}
|
|
69
|
+
find() {
|
|
70
|
+
const state = this.host.state;
|
|
71
|
+
return findMatches(state.blocks, this.query, state.cwd, (block) => this.host.toolExpansion.lineAnchors(block), state.rendererHooks);
|
|
72
|
+
}
|
|
73
|
+
/** Make the current match drawable (expand collapsed output, show a hidden diff), then ask App to scroll. */
|
|
74
|
+
jump() {
|
|
75
|
+
const match = this.current;
|
|
76
|
+
const block = match ? this.host.state.blocks[match.block] : undefined;
|
|
77
|
+
if (match && block?.type === "tool") {
|
|
78
|
+
const { expand, showDiff } = revealNeeded(match);
|
|
79
|
+
const expansion = this.host.toolExpansion;
|
|
80
|
+
if (expand && !expansion.isExpanded(block))
|
|
81
|
+
expansion.toggle(block);
|
|
82
|
+
if (showDiff && !expansion.isDiffShown(block))
|
|
83
|
+
expansion.toggleDiff(block);
|
|
84
|
+
}
|
|
85
|
+
this.jumpVersion += 1;
|
|
86
|
+
this.host.changed();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=search-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-controller.js","sourceRoot":"","sources":["../src/search-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAoB,MAAM,wBAAwB,CAAC;AAUrF;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IACV,IAAI,CAAa;IAClC,MAAM,GAAG,KAAK,CAAC;IACf,KAAK,GAAG,EAAE,CAAC;IACX,OAAO,GAAkB,EAAE,CAAC;IAC5B,4DAA4D;IAC5D,KAAK,CAAqB;IAC1B,yEAAyE;IACzE,WAAW,GAAG,CAAC,CAAC;IAEhB,YAAY,IAAgB;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACzE,CAAC;IAED,IAAI,CAAC,KAAK,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,wEAAwE;IACxE,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO;QACzB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IACtB,CAAC;IAED,6CAA6C;IAC7C,QAAQ,CAAC,KAAa;QACpB,IA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,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IACtB,CAAC;CACF","sourcesContent":["import type { TuiState } from \"@onpoint-dev-tools/crewcoder-tui-core/state/tui-store\";\nimport type { ToolExpansion } from \"./transcript.js\";\nimport { findMatches, revealNeeded, type SearchMatch } from \"./transcript-search.js\";\n\n/** What transcript search needs from `SessionController`. */\nexport type SearchHost = {\n readonly state: TuiState;\n /** Expansion state to reveal a hidden match; its line anchors keep diff lines as drawn. */\n readonly toolExpansion: ToolExpansion;\n changed(): void;\n};\n\n/**\n * Transcript search state (`docs/TRANSCRIPT.md#search`): the query, its\n * matches, and the current one. Matching is the pure `transcript-search.ts`;\n * App scrolls to `current` and marks its line whenever `jumpVersion` changes.\n * Search starts at the newest match, since the transcript sits at the bottom.\n */\nexport class TranscriptSearch {\n private readonly host: SearchHost;\n isOpen = false;\n query = \"\";\n matches: SearchMatch[] = [];\n /** Index into `matches`; undefined when nothing matches. */\n index: number | undefined;\n /** Bumped on every jump, so App scrolls again even to the same match. */\n jumpVersion = 0;\n\n constructor(host: SearchHost) {\n this.host = host;\n }\n\n get current(): SearchMatch | undefined {\n return this.index === undefined ? undefined : this.matches[this.index];\n }\n\n open(query = \"\"): void {\n this.isOpen = true;\n this.setQuery(query);\n }\n\n /** Close the bar; the transcript stays where the last match left it. */\n close(): void {\n if (!this.isOpen) return;\n this.isOpen = false;\n this.query = \"\";\n this.matches = [];\n this.index = undefined;\n this.host.changed();\n }\n\n /** A new query: jump to its newest match. */\n setQuery(query: string): void {\n this.query = query;\n this.matches = this.find();\n this.index = this.matches.length > 0 ? this.matches.length - 1 : undefined;\n this.jump();\n }\n\n /** Enter / Up: the previous (older) match, wrapping to the newest. */\n older(): void {\n this.step(-1);\n }\n\n /** Shift+Enter / Down: the next (newer) match, wrapping to the oldest. */\n newer(): void {\n this.step(1);\n }\n\n /**\n * Re-run the search first: the transcript may have grown since the last key.\n * The step counts from the current match's new position.\n */\n private step(delta: number): void {\n const previous = this.current;\n this.matches = this.find();\n const count = this.matches.length;\n if (count === 0) {\n this.index = undefined;\n return this.jump();\n }\n const at = previous ? this.matches.findIndex((match) => match.block === previous.block && match.ordinal === previous.ordinal) : -1;\n const from = at === -1 ? (delta < 0 ? count : -1) : at;\n this.index = (((from + delta) % count) + count) % count;\n this.jump();\n }\n\n private find(): SearchMatch[] {\n const state = this.host.state;\n return findMatches(state.blocks, this.query, state.cwd, (block) => this.host.toolExpansion.lineAnchors(block), state.rendererHooks);\n }\n\n /** Make the current match drawable (expand collapsed output, show a hidden diff), then ask App to scroll. */\n private jump(): void {\n const match = this.current;\n const block = match ? this.host.state.blocks[match.block] : undefined;\n if (match && block?.type === \"tool\") {\n const { expand, showDiff } = revealNeeded(match);\n const expansion = this.host.toolExpansion;\n if (expand && !expansion.isExpanded(block)) expansion.toggle(block);\n if (showDiff && !expansion.isDiffShown(block)) expansion.toggleDiff(block);\n }\n this.jumpVersion += 1;\n this.host.changed();\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TextBufferRenderable, type ScrollBoxRenderable } from "@opentui/core";
|
|
2
|
+
import { type SearchMatch } from "./transcript-search.js";
|
|
3
|
+
/**
|
|
4
|
+
* Finds a search match in the laid-out transcript (`docs/TRANSCRIPT.md#search`)
|
|
5
|
+
* through OpenTUI's public renderable tree: each block's box has
|
|
6
|
+
* `blockElementId`, and every text, markdown paragraph, code block, and diff
|
|
7
|
+
* inside it is a `TextBufferRenderable` with its drawn `plainText` and wrapped
|
|
8
|
+
* `lineInfo`. Labels and toggles (`chromeId`) are skipped so occurrence
|
|
9
|
+
* numbers line up with `findMatches`, which never searches them.
|
|
10
|
+
*/
|
|
11
|
+
/** The id of a block's box in the transcript. */
|
|
12
|
+
export declare function blockElementId(index: number): string;
|
|
13
|
+
/** Id for transcript text that is not block content (labels, toggles, headers); search skips it. */
|
|
14
|
+
export declare function chromeId(name: string, index?: number | string): string;
|
|
15
|
+
/**
|
|
16
|
+
* The content row (0 = top of the scrolled content) of the match's line, or
|
|
17
|
+
* undefined when its block is not on screen. Falls back to the block's top row
|
|
18
|
+
* when its drawn text has fewer occurrences than the model (rendered markdown
|
|
19
|
+
* hides markers the source has).
|
|
20
|
+
*/
|
|
21
|
+
export declare function locateMatchRow(scroll: ScrollBoxRenderable, match: SearchMatch, query: string): number | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The wrapped row of character `index` inside a text renderable. `lineStartCols`
|
|
24
|
+
* are display columns counted over the whole text, a newline counting as one.
|
|
25
|
+
*/
|
|
26
|
+
export declare function visualRow(text: Pick<TextBufferRenderable, "plainText" | "lineInfo">, index: number): number;
|
|
27
|
+
//# sourceMappingURL=search-jump.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-jump.d.ts","sourceRoot":"","sources":["../src/search-jump.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAmB,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEhG,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAEvE;;;;;;;GAOG;AAEH,iDAAiD;AACjD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpD;AAID,oGAAoG;AACpG,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAEtE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,mBAAmB,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CASjH;AAWD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,oBAAoB,EAAE,WAAW,GAAG,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAU3G"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { TextBufferRenderable } from "@opentui/core";
|
|
2
|
+
import stringWidth from "string-width";
|
|
3
|
+
import { occurrences } from "./transcript-search.js";
|
|
4
|
+
/**
|
|
5
|
+
* Finds a search match in the laid-out transcript (`docs/TRANSCRIPT.md#search`)
|
|
6
|
+
* through OpenTUI's public renderable tree: each block's box has
|
|
7
|
+
* `blockElementId`, and every text, markdown paragraph, code block, and diff
|
|
8
|
+
* inside it is a `TextBufferRenderable` with its drawn `plainText` and wrapped
|
|
9
|
+
* `lineInfo`. Labels and toggles (`chromeId`) are skipped so occurrence
|
|
10
|
+
* numbers line up with `findMatches`, which never searches them.
|
|
11
|
+
*/
|
|
12
|
+
/** The id of a block's box in the transcript. */
|
|
13
|
+
export function blockElementId(index) {
|
|
14
|
+
return `transcript-block-${index}`;
|
|
15
|
+
}
|
|
16
|
+
const CHROME_PREFIX = "chrome-";
|
|
17
|
+
/** Id for transcript text that is not block content (labels, toggles, headers); search skips it. */
|
|
18
|
+
export function chromeId(name, index) {
|
|
19
|
+
return index === undefined ? `${CHROME_PREFIX}${name}` : `${CHROME_PREFIX}${name}-${index}`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The content row (0 = top of the scrolled content) of the match's line, or
|
|
23
|
+
* undefined when its block is not on screen. Falls back to the block's top row
|
|
24
|
+
* when its drawn text has fewer occurrences than the model (rendered markdown
|
|
25
|
+
* hides markers the source has).
|
|
26
|
+
*/
|
|
27
|
+
export function locateMatchRow(scroll, match, query) {
|
|
28
|
+
const box = scroll.findDescendantById(blockElementId(match.block));
|
|
29
|
+
const origin = scroll.getChildren()[0];
|
|
30
|
+
if (!box || !origin)
|
|
31
|
+
return undefined;
|
|
32
|
+
const found = [];
|
|
33
|
+
collectOccurrences(box, query, found);
|
|
34
|
+
const hit = found[Math.min(match.ordinal, found.length - 1)];
|
|
35
|
+
const top = hit ? hit.text.y + visualRow(hit.text, hit.start) : box.y;
|
|
36
|
+
return top - origin.y;
|
|
37
|
+
}
|
|
38
|
+
function collectOccurrences(node, query, found) {
|
|
39
|
+
if (node.id.startsWith(CHROME_PREFIX))
|
|
40
|
+
return;
|
|
41
|
+
if (node instanceof TextBufferRenderable) {
|
|
42
|
+
for (const [start] of occurrences(node.plainText, query))
|
|
43
|
+
found.push({ text: node, start });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
for (const child of node.getChildren())
|
|
47
|
+
collectOccurrences(child, query, found);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The wrapped row of character `index` inside a text renderable. `lineStartCols`
|
|
51
|
+
* are display columns counted over the whole text, a newline counting as one.
|
|
52
|
+
*/
|
|
53
|
+
export function visualRow(text, index) {
|
|
54
|
+
const before = text.plainText.slice(0, index);
|
|
55
|
+
const column = before.split("\n").reduce((sum, line, at) => sum + stringWidth(line) + (at > 0 ? 1 : 0), 0);
|
|
56
|
+
const starts = text.lineInfo.lineStartCols;
|
|
57
|
+
let row = 0;
|
|
58
|
+
for (const [at, start] of starts.entries()) {
|
|
59
|
+
if (start > column)
|
|
60
|
+
break;
|
|
61
|
+
row = at;
|
|
62
|
+
}
|
|
63
|
+
return row;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=search-jump.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-jump.js","sourceRoot":"","sources":["../src/search-jump.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAA6C,MAAM,eAAe,CAAC;AAChG,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,WAAW,EAAoB,MAAM,wBAAwB,CAAC;AAEvE;;;;;;;GAOG;AAEH,iDAAiD;AACjD,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,OAAO,oBAAoB,KAAK,EAAE,CAAC;AACrC,CAAC;AAED,MAAM,aAAa,GAAG,SAAS,CAAC;AAEhC,oGAAoG;AACpG,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,KAAuB;IAC5D,OAAO,KAAK,KAAK,SAAS,CAAC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IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5F,OAAO;IACT,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,WAAW,EAAE;QAAE,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAClF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAA0D,EAAE,KAAa;IACjG,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3G,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC;IAC3C,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QAC3C,IAAI,KAAK,GAAG,MAAM;YAAE,MAAM;QAC1B,GAAG,GAAG,EAAE,CAAC;IACX,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { TextBufferRenderable, type Renderable, type ScrollBoxRenderable } from \"@opentui/core\";\nimport stringWidth from \"string-width\";\nimport { occurrences, type SearchMatch } from \"./transcript-search.js\";\n\n/**\n * Finds a search match in the laid-out transcript (`docs/TRANSCRIPT.md#search`)\n * through OpenTUI's public renderable tree: each block's box has\n * `blockElementId`, and every text, markdown paragraph, code block, and diff\n * inside it is a `TextBufferRenderable` with its drawn `plainText` and wrapped\n * `lineInfo`. Labels and toggles (`chromeId`) are skipped so occurrence\n * numbers line up with `findMatches`, which never searches them.\n */\n\n/** The id of a block's box in the transcript. */\nexport function blockElementId(index: number): string {\n return `transcript-block-${index}`;\n}\n\nconst CHROME_PREFIX = \"chrome-\";\n\n/** Id for transcript text that is not block content (labels, toggles, headers); search skips it. */\nexport function chromeId(name: string, index?: number | string): string {\n return index === undefined ? `${CHROME_PREFIX}${name}` : `${CHROME_PREFIX}${name}-${index}`;\n}\n\n/**\n * The content row (0 = top of the scrolled content) of the match's line, or\n * undefined when its block is not on screen. Falls back to the block's top row\n * when its drawn text has fewer occurrences than the model (rendered markdown\n * hides markers the source has).\n */\nexport function locateMatchRow(scroll: ScrollBoxRenderable, match: SearchMatch, query: string): number | undefined {\n const box = scroll.findDescendantById(blockElementId(match.block));\n const origin = scroll.getChildren()[0];\n if (!box || !origin) return undefined;\n const found: Array<{ text: TextBufferRenderable; start: number }> = [];\n collectOccurrences(box, query, found);\n const hit = found[Math.min(match.ordinal, found.length - 1)];\n const top = hit ? hit.text.y + visualRow(hit.text, hit.start) : box.y;\n return top - origin.y;\n}\n\nfunction collectOccurrences(node: Renderable, query: string, found: Array<{ text: TextBufferRenderable; start: number }>): void {\n if (node.id.startsWith(CHROME_PREFIX)) return;\n if (node instanceof TextBufferRenderable) {\n for (const [start] of occurrences(node.plainText, query)) found.push({ text: node, start });\n return;\n }\n for (const child of node.getChildren()) collectOccurrences(child, query, found);\n}\n\n/**\n * The wrapped row of character `index` inside a text renderable. `lineStartCols`\n * are display columns counted over the whole text, a newline counting as one.\n */\nexport function visualRow(text: Pick<TextBufferRenderable, \"plainText\" | \"lineInfo\">, index: number): number {\n const before = text.plainText.slice(0, index);\n const column = before.split(\"\\n\").reduce((sum, line, at) => sum + stringWidth(line) + (at > 0 ? 1 : 0), 0);\n const starts = text.lineInfo.lineStartCols;\n let row = 0;\n for (const [at, start] of starts.entries()) {\n if (start > column) break;\n row = at;\n }\n return row;\n}\n"]}
|