@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,138 @@
|
|
|
1
|
+
import { BoxRenderable, SyntaxStyle } from "@opentui/core";
|
|
2
|
+
import { useRenderer } from "@opentui/react";
|
|
3
|
+
import { useEffect, useMemo } from "react";
|
|
4
|
+
import { useAppColors } from "./hooks/use-app-colors.js";
|
|
5
|
+
const HEADING_LEVELS = [1, 2, 3, 4, 5, 6];
|
|
6
|
+
/**
|
|
7
|
+
* Tree-sitter capture styles for highlighted code (fenced blocks, diffs, read
|
|
8
|
+
* output). OpenTUI's `SyntaxStyle` looks up the exact capture name, then only
|
|
9
|
+
* its first segment (`keyword.function` -> `keyword`), so base names cover
|
|
10
|
+
* dotted captures here. Variables and plain identifiers keep the surrounding
|
|
11
|
+
* text color. Colors come from the active theme's `syntax` palette.
|
|
12
|
+
*/
|
|
13
|
+
export function codeStyles(c) {
|
|
14
|
+
return {
|
|
15
|
+
keyword: { fg: c.keyword },
|
|
16
|
+
conditional: { fg: c.keyword },
|
|
17
|
+
repeat: { fg: c.keyword },
|
|
18
|
+
include: { fg: c.keyword },
|
|
19
|
+
exception: { fg: c.keyword },
|
|
20
|
+
string: { fg: c.string },
|
|
21
|
+
"string.special.key": { fg: c.property },
|
|
22
|
+
character: { fg: c.string },
|
|
23
|
+
escape: { fg: c.escape },
|
|
24
|
+
number: { fg: c.number },
|
|
25
|
+
float: { fg: c.number },
|
|
26
|
+
boolean: { fg: c.constant },
|
|
27
|
+
constant: { fg: c.constant },
|
|
28
|
+
comment: { fg: c.comment, italic: true },
|
|
29
|
+
function: { fg: c.function },
|
|
30
|
+
method: { fg: c.function },
|
|
31
|
+
constructor: { fg: c.type },
|
|
32
|
+
type: { fg: c.type },
|
|
33
|
+
namespace: { fg: c.type },
|
|
34
|
+
module: { fg: c.type },
|
|
35
|
+
property: { fg: c.property },
|
|
36
|
+
field: { fg: c.property },
|
|
37
|
+
attribute: { fg: c.attribute },
|
|
38
|
+
label: { fg: c.attribute },
|
|
39
|
+
operator: { fg: c.operator },
|
|
40
|
+
punctuation: { fg: c.punctuation },
|
|
41
|
+
tag: { fg: c.tag },
|
|
42
|
+
"tag.attribute": { fg: c.attribute },
|
|
43
|
+
"tag.delimiter": { fg: c.punctuation }
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Markdown element styles (`markup.*`), shared by rendered replies and by
|
|
48
|
+
* markdown source (`.md` read output, diffs, ```markdown fences). Every full
|
|
49
|
+
* capture name the markdown grammar emits is listed: OpenTUI would resolve
|
|
50
|
+
* `markup.raw.block` only to `markup`, which has no style.
|
|
51
|
+
*/
|
|
52
|
+
export function markupStyles(md, heading, concealed) {
|
|
53
|
+
const headingStyle = { fg: heading, bold: true };
|
|
54
|
+
const link = { fg: md.link, underline: true };
|
|
55
|
+
const list = { fg: md.listMarker };
|
|
56
|
+
const code = { fg: md.code };
|
|
57
|
+
return {
|
|
58
|
+
conceal: { fg: concealed },
|
|
59
|
+
"markup.heading": headingStyle,
|
|
60
|
+
...Object.fromEntries(HEADING_LEVELS.map((level) => [`markup.heading.${level}`, headingStyle])),
|
|
61
|
+
"markup.strong": { fg: md.strong, bold: true },
|
|
62
|
+
"markup.italic": { fg: md.emphasis, italic: true },
|
|
63
|
+
"markup.strikethrough": { fg: md.strikethrough, strikethrough: true },
|
|
64
|
+
"markup.raw": code,
|
|
65
|
+
"markup.raw.block": code,
|
|
66
|
+
"markup.math": code,
|
|
67
|
+
"markup.link": link,
|
|
68
|
+
"markup.link.label": link,
|
|
69
|
+
"markup.link.url": { fg: md.linkUrl },
|
|
70
|
+
"markup.link.bracket.close": { fg: md.linkUrl },
|
|
71
|
+
"markup.list": list,
|
|
72
|
+
"markup.list.checked": list,
|
|
73
|
+
"markup.list.unchecked": list,
|
|
74
|
+
"markup.quote": { fg: md.quote }
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Styles for OpenTUI's markdown engine (`markup.*`, `conceal`, `default`) plus
|
|
79
|
+
* the code scopes for fenced blocks.
|
|
80
|
+
*/
|
|
81
|
+
export function markdownStyles(theme, colors, syntax, markdown) {
|
|
82
|
+
return {
|
|
83
|
+
...codeStyles(syntax),
|
|
84
|
+
...markupStyles(markdown, colors.heading, theme.colors.mutedForeground),
|
|
85
|
+
default: { fg: colors.base }
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A native `SyntaxStyle`, rebuilt when its colors change (`/theme`) and freed
|
|
90
|
+
* when replaced or unmounted. `deps` are the colors `build` reads.
|
|
91
|
+
*/
|
|
92
|
+
function useSyntaxStyle(build, deps) {
|
|
93
|
+
const renderer = useRenderer();
|
|
94
|
+
const style = useMemo(() => SyntaxStyle.fromStyles(build(), renderer.nativeScene), [renderer, ...deps]);
|
|
95
|
+
useEffect(() => () => style.destroy(), [style]);
|
|
96
|
+
return style;
|
|
97
|
+
}
|
|
98
|
+
export function useMarkdownStyle(theme, colors) {
|
|
99
|
+
const { syntax, markdown } = useAppColors();
|
|
100
|
+
return useSyntaxStyle(() => markdownStyles(theme, colors, syntax, markdown), [theme, colors.base, colors.heading, syntax, markdown]);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Highlighted source for `<diff>` and `<code>` (read output): code scopes, and
|
|
104
|
+
* markdown element scopes so `.md` files color their headings, emphasis,
|
|
105
|
+
* links, and code spans like a rendered reply.
|
|
106
|
+
*/
|
|
107
|
+
export function useCodeStyle(theme) {
|
|
108
|
+
const { syntax, markdown } = useAppColors();
|
|
109
|
+
return useSyntaxStyle(() => ({
|
|
110
|
+
...codeStyles(syntax),
|
|
111
|
+
...markupStyles(markdown, markdown.heading, theme.colors.mutedForeground),
|
|
112
|
+
default: { fg: theme.colors.foreground }
|
|
113
|
+
}), [theme, syntax, markdown]);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A fenced code block behind a left rail. The block itself is OpenTUI's
|
|
117
|
+
* default `CodeRenderable`, highlighted by Tree-sitter when the fence's info
|
|
118
|
+
* string names a language with a parser (`infoStringToFiletype`), plain text
|
|
119
|
+
* otherwise. Markdown reuses that renderable across streaming updates and
|
|
120
|
+
* takes it out of the old rail before dropping it. OpenTUI leaves fenced
|
|
121
|
+
* code unconcealed, so a ```markdown fence keeps its `#` and `**` markers.
|
|
122
|
+
*/
|
|
123
|
+
export function codeFence(ctx, theme, context) {
|
|
124
|
+
const code = context.defaultRender();
|
|
125
|
+
if (!code)
|
|
126
|
+
return undefined;
|
|
127
|
+
const rail = new BoxRenderable(ctx, {
|
|
128
|
+
width: "100%",
|
|
129
|
+
flexShrink: 0,
|
|
130
|
+
border: ["left"],
|
|
131
|
+
borderStyle: "single",
|
|
132
|
+
borderColor: theme.colors.border,
|
|
133
|
+
paddingLeft: 1
|
|
134
|
+
});
|
|
135
|
+
rail.add(code);
|
|
136
|
+
return rail;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=markdown-style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-style.js","sourceRoot":"","sources":["../src/markdown-style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAA0F,MAAM,eAAe,CAAC;AACnJ,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAUzD,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAU,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,CAAe;IACxC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AAE;QAClC,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,CAAC;QACb,MAAM,EAAE,CAAC,MAAM,CAAC;QAChB,WAAW,EAAE,QAAQ;QACrB,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM;QAChC,WAAW,EAAE,CAAC;KACf,CAAC,CAAC;IACH,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACf,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { BoxRenderable, SyntaxStyle, type RenderContext, type Renderable, type RenderNodeContext, type StyleDefinitionInput } from \"@opentui/core\";\nimport { useRenderer } from \"@opentui/react\";\nimport { useEffect, useMemo } from \"react\";\nimport type { MarkdownColors, SyntaxColors } from \"@onpoint-dev-tools/crewcoder-tui-core/theme/crewcoder-theme\";\nimport type { Theme } from \"./components/ui/types.js\";\nimport { useAppColors } from \"./hooks/use-app-colors.js\";\n\n/** Per-block text colors: replies and reasoning differ in body and heading color. */\nexport type MarkdownTextColors = {\n /** Body text. */\n base: string;\n /** Headings (bold). Replies use the theme's markdown heading; reasoning keeps its body color. */\n heading: string;\n};\n\nconst HEADING_LEVELS = [1, 2, 3, 4, 5, 6] as const;\n\n/**\n * Tree-sitter capture styles for highlighted code (fenced blocks, diffs, read\n * output). OpenTUI's `SyntaxStyle` looks up the exact capture name, then only\n * its first segment (`keyword.function` -> `keyword`), so base names cover\n * dotted captures here. Variables and plain identifiers keep the surrounding\n * text color. Colors come from the active theme's `syntax` palette.\n */\nexport function codeStyles(c: SyntaxColors): Record<string, StyleDefinitionInput> {\n return {\n keyword: { fg: c.keyword },\n conditional: { fg: c.keyword },\n repeat: { fg: c.keyword },\n include: { fg: c.keyword },\n exception: { fg: c.keyword },\n string: { fg: c.string },\n \"string.special.key\": { fg: c.property },\n character: { fg: c.string },\n escape: { fg: c.escape },\n number: { fg: c.number },\n float: { fg: c.number },\n boolean: { fg: c.constant },\n constant: { fg: c.constant },\n comment: { fg: c.comment, italic: true },\n function: { fg: c.function },\n method: { fg: c.function },\n constructor: { fg: c.type },\n type: { fg: c.type },\n namespace: { fg: c.type },\n module: { fg: c.type },\n property: { fg: c.property },\n field: { fg: c.property },\n attribute: { fg: c.attribute },\n label: { fg: c.attribute },\n operator: { fg: c.operator },\n punctuation: { fg: c.punctuation },\n tag: { fg: c.tag },\n \"tag.attribute\": { fg: c.attribute },\n \"tag.delimiter\": { fg: c.punctuation }\n };\n}\n\n/**\n * Markdown element styles (`markup.*`), shared by rendered replies and by\n * markdown source (`.md` read output, diffs, ```markdown fences). Every full\n * capture name the markdown grammar emits is listed: OpenTUI would resolve\n * `markup.raw.block` only to `markup`, which has no style.\n */\nexport function markupStyles(md: MarkdownColors, heading: string, concealed: string): Record<string, StyleDefinitionInput> {\n const headingStyle: StyleDefinitionInput = { fg: heading, bold: true };\n const link: StyleDefinitionInput = { fg: md.link, underline: true };\n const list: StyleDefinitionInput = { fg: md.listMarker };\n const code: StyleDefinitionInput = { fg: md.code };\n return {\n conceal: { fg: concealed },\n \"markup.heading\": headingStyle,\n ...Object.fromEntries(HEADING_LEVELS.map((level) => [`markup.heading.${level}`, headingStyle])),\n \"markup.strong\": { fg: md.strong, bold: true },\n \"markup.italic\": { fg: md.emphasis, italic: true },\n \"markup.strikethrough\": { fg: md.strikethrough, strikethrough: true },\n \"markup.raw\": code,\n \"markup.raw.block\": code,\n \"markup.math\": code,\n \"markup.link\": link,\n \"markup.link.label\": link,\n \"markup.link.url\": { fg: md.linkUrl },\n \"markup.link.bracket.close\": { fg: md.linkUrl },\n \"markup.list\": list,\n \"markup.list.checked\": list,\n \"markup.list.unchecked\": list,\n \"markup.quote\": { fg: md.quote }\n };\n}\n\n/**\n * Styles for OpenTUI's markdown engine (`markup.*`, `conceal`, `default`) plus\n * the code scopes for fenced blocks.\n */\nexport function markdownStyles(theme: Theme, colors: MarkdownTextColors, syntax: SyntaxColors, markdown: MarkdownColors): Record<string, StyleDefinitionInput> {\n return {\n ...codeStyles(syntax),\n ...markupStyles(markdown, colors.heading, theme.colors.mutedForeground),\n default: { fg: colors.base }\n };\n}\n\n/**\n * A native `SyntaxStyle`, rebuilt when its colors change (`/theme`) and freed\n * when replaced or unmounted. `deps` are the colors `build` reads.\n */\nfunction useSyntaxStyle(build: () => Record<string, StyleDefinitionInput>, deps: readonly unknown[]): SyntaxStyle {\n const renderer = useRenderer();\n const style = useMemo(() => SyntaxStyle.fromStyles(build(), renderer.nativeScene), [renderer, ...deps]);\n useEffect(() => () => style.destroy(), [style]);\n return style;\n}\n\nexport function useMarkdownStyle(theme: Theme, colors: MarkdownTextColors): SyntaxStyle {\n const { syntax, markdown } = useAppColors();\n return useSyntaxStyle(() => markdownStyles(theme, colors, syntax, markdown), [theme, colors.base, colors.heading, syntax, markdown]);\n}\n\n/**\n * Highlighted source for `<diff>` and `<code>` (read output): code scopes, and\n * markdown element scopes so `.md` files color their headings, emphasis,\n * links, and code spans like a rendered reply.\n */\nexport function useCodeStyle(theme: Theme): SyntaxStyle {\n const { syntax, markdown } = useAppColors();\n return useSyntaxStyle(() => ({\n ...codeStyles(syntax),\n ...markupStyles(markdown, markdown.heading, theme.colors.mutedForeground),\n default: { fg: theme.colors.foreground }\n }), [theme, syntax, markdown]);\n}\n\n/**\n * A fenced code block behind a left rail. The block itself is OpenTUI's\n * default `CodeRenderable`, highlighted by Tree-sitter when the fence's info\n * string names a language with a parser (`infoStringToFiletype`), plain text\n * otherwise. Markdown reuses that renderable across streaming updates and\n * takes it out of the old rail before dropping it. OpenTUI leaves fenced\n * code unconcealed, so a ```markdown fence keeps its `#` and `**` markers.\n */\nexport function codeFence(ctx: RenderContext, theme: Theme, context: RenderNodeContext): Renderable | undefined {\n const code = context.defaultRender();\n if (!code) return undefined;\n const rail = new BoxRenderable(ctx, {\n width: \"100%\",\n flexShrink: 0,\n border: [\"left\"],\n borderStyle: \"single\",\n borderColor: theme.colors.border,\n paddingLeft: 1\n });\n rail.add(code);\n return rail;\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type MentionToken, type PathLister, type PathSuggestion } from "./path-suggestions.js";
|
|
2
|
+
/** The open `@` suggestion list: the token it answers, its paths, and the highlighted row. */
|
|
3
|
+
export type MentionState = {
|
|
4
|
+
token: MentionToken;
|
|
5
|
+
items: readonly PathSuggestion[];
|
|
6
|
+
cursor: number;
|
|
7
|
+
};
|
|
8
|
+
/** What the `@` list needs from its owner (`SessionController`). */
|
|
9
|
+
export type MentionHost = {
|
|
10
|
+
cwd(): string;
|
|
11
|
+
/** The list opened, moved, or closed: re-render. */
|
|
12
|
+
changed(): void;
|
|
13
|
+
/** Listing failed (shown as a footer alert). */
|
|
14
|
+
failed(error: unknown): void;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* State and request ordering for `@` path suggestions (`docs/MENTIONS.md`).
|
|
18
|
+
* Pure string work lives in `path-suggestions.ts`; this class owns the open
|
|
19
|
+
* list, Esc dismissal, and dropping answers for tokens the user has left.
|
|
20
|
+
*/
|
|
21
|
+
export declare class Mentions {
|
|
22
|
+
current: MentionState | undefined;
|
|
23
|
+
/** Null disables listing (remote mode: the workspace is on the SSH host). */
|
|
24
|
+
private readonly listPaths;
|
|
25
|
+
private readonly host;
|
|
26
|
+
private request;
|
|
27
|
+
/** The composer text and cursor (JS index) the last update saw. */
|
|
28
|
+
private input;
|
|
29
|
+
/** `start:query` of a token closed with Esc; it stays closed until it changes. */
|
|
30
|
+
private dismissed;
|
|
31
|
+
/** `start:query` of the listing in flight. */
|
|
32
|
+
private pending;
|
|
33
|
+
constructor(listPaths: PathLister | null, host: MentionHost);
|
|
34
|
+
/**
|
|
35
|
+
* Called on every composer edit and cursor move. Opens, refreshes, or closes
|
|
36
|
+
* the list for the token at the cursor. Listing is async; an answer for a
|
|
37
|
+
* token the user has since left is dropped. Until it arrives the previous
|
|
38
|
+
* list stays up, so typing does not flicker.
|
|
39
|
+
*/
|
|
40
|
+
update(text: string, cursor: number): void;
|
|
41
|
+
move(delta: number): void;
|
|
42
|
+
/** Esc: close the list; it reopens once the token changes. */
|
|
43
|
+
dismiss(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Enter/Tab: the composer text with the highlighted path in place of the
|
|
46
|
+
* token, and where the cursor goes (JS index); undefined when nothing is
|
|
47
|
+
* highlighted. Uses the latest token, since the list can be a keystroke behind.
|
|
48
|
+
*/
|
|
49
|
+
accept(): {
|
|
50
|
+
text: string;
|
|
51
|
+
cursor: number;
|
|
52
|
+
} | undefined;
|
|
53
|
+
/** Drop any listing in flight. */
|
|
54
|
+
private cancel;
|
|
55
|
+
private close;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=mentions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mentions.d.ts","sourceRoot":"","sources":["../src/mentions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE/I,8FAA8F;AAC9F,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,SAAS,cAAc,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAErG,oEAAoE;AACpE,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,IAAI,MAAM,CAAC;IACd,oDAAoD;IACpD,OAAO,IAAI,IAAI,CAAC;IAChB,gDAAgD;IAChD,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF;;;;GAIG;AACH,qBAAa,QAAQ;IACnB,OAAO,EAAE,YAAY,GAAG,SAAS,CAAC;IAClC,6EAA6E;IAC7E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoB;IAC9C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAc;IACnC,OAAO,CAAC,OAAO,CAAK;IACpB,mEAAmE;IACnE,OAAO,CAAC,KAAK,CAA2B;IACxC,kFAAkF;IAClF,OAAO,CAAC,SAAS,CAAqB;IACtC,8CAA8C;IAC9C,OAAO,CAAC,OAAO,CAAqB;gBAExB,SAAS,EAAE,UAAU,GAAG,IAAI,EAAE,IAAI,EAAE,WAAW;IAK3D;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IA8B1C,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAQzB,8DAA8D;IAC9D,OAAO,IAAI,IAAI;IAQf;;;;OAIG;IACH,MAAM,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;IAWtD,kCAAkC;IAClC,OAAO,CAAC,MAAM;IAKd,OAAO,CAAC,KAAK;CAId"}
|
package/dist/mentions.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { currentMention, MENTION_LIMIT, replaceMention } from "./path-suggestions.js";
|
|
2
|
+
/**
|
|
3
|
+
* State and request ordering for `@` path suggestions (`docs/MENTIONS.md`).
|
|
4
|
+
* Pure string work lives in `path-suggestions.ts`; this class owns the open
|
|
5
|
+
* list, Esc dismissal, and dropping answers for tokens the user has left.
|
|
6
|
+
*/
|
|
7
|
+
export class Mentions {
|
|
8
|
+
current;
|
|
9
|
+
/** Null disables listing (remote mode: the workspace is on the SSH host). */
|
|
10
|
+
listPaths;
|
|
11
|
+
host;
|
|
12
|
+
request = 0;
|
|
13
|
+
/** The composer text and cursor (JS index) the last update saw. */
|
|
14
|
+
input = { text: "", cursor: 0 };
|
|
15
|
+
/** `start:query` of a token closed with Esc; it stays closed until it changes. */
|
|
16
|
+
dismissed;
|
|
17
|
+
/** `start:query` of the listing in flight. */
|
|
18
|
+
pending;
|
|
19
|
+
constructor(listPaths, host) {
|
|
20
|
+
this.listPaths = listPaths;
|
|
21
|
+
this.host = host;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Called on every composer edit and cursor move. Opens, refreshes, or closes
|
|
25
|
+
* the list for the token at the cursor. Listing is async; an answer for a
|
|
26
|
+
* token the user has since left is dropped. Until it arrives the previous
|
|
27
|
+
* list stays up, so typing does not flicker.
|
|
28
|
+
*/
|
|
29
|
+
update(text, cursor) {
|
|
30
|
+
this.input = { text, cursor };
|
|
31
|
+
const listPaths = this.listPaths;
|
|
32
|
+
const token = listPaths ? currentMention(text, cursor) : undefined;
|
|
33
|
+
const key = token ? `${token.start}:${token.query}` : undefined;
|
|
34
|
+
if (key !== this.dismissed)
|
|
35
|
+
this.dismissed = undefined;
|
|
36
|
+
if (!token || !listPaths || key === this.dismissed || (this.current && this.current.token.start !== token.start)) {
|
|
37
|
+
this.cancel();
|
|
38
|
+
if (this.current)
|
|
39
|
+
this.close();
|
|
40
|
+
if (!token || !listPaths || key === this.dismissed)
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (this.current && this.current.token.query === token.query)
|
|
44
|
+
return;
|
|
45
|
+
// A cursor move inside a token whose listing is still loading asks nothing new.
|
|
46
|
+
if (this.pending === key)
|
|
47
|
+
return;
|
|
48
|
+
this.pending = key;
|
|
49
|
+
const request = ++this.request;
|
|
50
|
+
listPaths(this.host.cwd(), token.query, MENTION_LIMIT).then((items) => {
|
|
51
|
+
if (request !== this.request)
|
|
52
|
+
return;
|
|
53
|
+
this.pending = undefined;
|
|
54
|
+
const latest = currentMention(this.input.text, this.input.cursor);
|
|
55
|
+
if (!latest || latest.start !== token.start || latest.query !== token.query)
|
|
56
|
+
return;
|
|
57
|
+
this.current = { token: latest, items, cursor: 0 };
|
|
58
|
+
this.host.changed();
|
|
59
|
+
}, (error) => {
|
|
60
|
+
if (request !== this.request)
|
|
61
|
+
return;
|
|
62
|
+
this.pending = undefined;
|
|
63
|
+
this.host.failed(error);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
move(delta) {
|
|
67
|
+
const mention = this.current;
|
|
68
|
+
if (!mention || mention.items.length === 0)
|
|
69
|
+
return;
|
|
70
|
+
const count = mention.items.length;
|
|
71
|
+
this.current = { ...mention, cursor: (mention.cursor + delta + count) % count };
|
|
72
|
+
this.host.changed();
|
|
73
|
+
}
|
|
74
|
+
/** Esc: close the list; it reopens once the token changes. */
|
|
75
|
+
dismiss() {
|
|
76
|
+
const mention = this.current;
|
|
77
|
+
if (!mention)
|
|
78
|
+
return;
|
|
79
|
+
this.dismissed = `${mention.token.start}:${mention.token.query}`;
|
|
80
|
+
this.cancel();
|
|
81
|
+
this.close();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Enter/Tab: the composer text with the highlighted path in place of the
|
|
85
|
+
* token, and where the cursor goes (JS index); undefined when nothing is
|
|
86
|
+
* highlighted. Uses the latest token, since the list can be a keystroke behind.
|
|
87
|
+
*/
|
|
88
|
+
accept() {
|
|
89
|
+
const mention = this.current;
|
|
90
|
+
const pick = mention?.items[mention.cursor];
|
|
91
|
+
if (!mention || !pick)
|
|
92
|
+
return undefined;
|
|
93
|
+
const { text, cursor } = this.input;
|
|
94
|
+
const token = currentMention(text, cursor) ?? mention.token;
|
|
95
|
+
this.cancel();
|
|
96
|
+
this.close();
|
|
97
|
+
return replaceMention(text, token, pick);
|
|
98
|
+
}
|
|
99
|
+
/** Drop any listing in flight. */
|
|
100
|
+
cancel() {
|
|
101
|
+
this.request += 1;
|
|
102
|
+
this.pending = undefined;
|
|
103
|
+
}
|
|
104
|
+
close() {
|
|
105
|
+
this.current = undefined;
|
|
106
|
+
this.host.changed();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=mentions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mentions.js","sourceRoot":"","sources":["../src/mentions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAA2D,MAAM,uBAAuB,CAAC;AAc/I;;;;GAIG;AACH,MAAM,OAAO,QAAQ;IACnB,OAA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CAAC;IAED,kCAAkC;IAC1B,MAAM;QACZ,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;IAC3B,CAAC;IAEO,KAAK;QACX,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IACtB,CAAC;CACF","sourcesContent":["import { currentMention, MENTION_LIMIT, replaceMention, type MentionToken, type PathLister, type PathSuggestion } from \"./path-suggestions.js\";\n\n/** The open `@` suggestion list: the token it answers, its paths, and the highlighted row. */\nexport type MentionState = { token: MentionToken; items: readonly PathSuggestion[]; cursor: number };\n\n/** What the `@` list needs from its owner (`SessionController`). */\nexport type MentionHost = {\n cwd(): string;\n /** The list opened, moved, or closed: re-render. */\n changed(): void;\n /** Listing failed (shown as a footer alert). */\n failed(error: unknown): void;\n};\n\n/**\n * State and request ordering for `@` path suggestions (`docs/MENTIONS.md`).\n * Pure string work lives in `path-suggestions.ts`; this class owns the open\n * list, Esc dismissal, and dropping answers for tokens the user has left.\n */\nexport class Mentions {\n current: MentionState | undefined;\n /** Null disables listing (remote mode: the workspace is on the SSH host). */\n private readonly listPaths: PathLister | null;\n private readonly host: MentionHost;\n private request = 0;\n /** The composer text and cursor (JS index) the last update saw. */\n private input = { text: \"\", cursor: 0 };\n /** `start:query` of a token closed with Esc; it stays closed until it changes. */\n private dismissed: string | undefined;\n /** `start:query` of the listing in flight. */\n private pending: string | undefined;\n\n constructor(listPaths: PathLister | null, host: MentionHost) {\n this.listPaths = listPaths;\n this.host = host;\n }\n\n /**\n * Called on every composer edit and cursor move. Opens, refreshes, or closes\n * the list for the token at the cursor. Listing is async; an answer for a\n * token the user has since left is dropped. Until it arrives the previous\n * list stays up, so typing does not flicker.\n */\n update(text: string, cursor: number): void {\n this.input = { text, cursor };\n const listPaths = this.listPaths;\n const token = listPaths ? currentMention(text, cursor) : undefined;\n const key = token ? `${token.start}:${token.query}` : undefined;\n if (key !== this.dismissed) this.dismissed = undefined;\n if (!token || !listPaths || key === this.dismissed || (this.current && this.current.token.start !== token.start)) {\n this.cancel();\n if (this.current) this.close();\n if (!token || !listPaths || key === this.dismissed) return;\n }\n if (this.current && this.current.token.query === token.query) return;\n // A cursor move inside a token whose listing is still loading asks nothing new.\n if (this.pending === key) return;\n this.pending = key;\n const request = ++this.request;\n listPaths(this.host.cwd(), token.query, MENTION_LIMIT).then((items) => {\n if (request !== this.request) return;\n this.pending = undefined;\n const latest = currentMention(this.input.text, this.input.cursor);\n if (!latest || latest.start !== token.start || latest.query !== token.query) return;\n this.current = { token: latest, items, cursor: 0 };\n this.host.changed();\n }, (error: unknown) => {\n if (request !== this.request) return;\n this.pending = undefined;\n this.host.failed(error);\n });\n }\n\n move(delta: number): void {\n const mention = this.current;\n if (!mention || mention.items.length === 0) return;\n const count = mention.items.length;\n this.current = { ...mention, cursor: (mention.cursor + delta + count) % count };\n this.host.changed();\n }\n\n /** Esc: close the list; it reopens once the token changes. */\n dismiss(): void {\n const mention = this.current;\n if (!mention) return;\n this.dismissed = `${mention.token.start}:${mention.token.query}`;\n this.cancel();\n this.close();\n }\n\n /**\n * Enter/Tab: the composer text with the highlighted path in place of the\n * token, and where the cursor goes (JS index); undefined when nothing is\n * highlighted. Uses the latest token, since the list can be a keystroke behind.\n */\n accept(): { text: string; cursor: number } | undefined {\n const mention = this.current;\n const pick = mention?.items[mention.cursor];\n if (!mention || !pick) return undefined;\n const { text, cursor } = this.input;\n const token = currentMention(text, cursor) ?? mention.token;\n this.cancel();\n this.close();\n return replaceMention(text, token, pick);\n }\n\n /** Drop any listing in flight. */\n private cancel(): void {\n this.request += 1;\n this.pending = undefined;\n }\n\n private close(): void {\n this.current = undefined;\n this.host.changed();\n }\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure model for the command palette and every picker built on it. The footer
|
|
3
|
+
* sizer, `App`, and `CommandPalette` all derive rows from here so the footer
|
|
4
|
+
* height always equals what renders, and the cursor always indexes the same
|
|
5
|
+
* order the rows are drawn in.
|
|
6
|
+
*/
|
|
7
|
+
export interface PaletteCommand {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
group?: string;
|
|
12
|
+
/** Marks the active value (current provider, model, mode, ...). */
|
|
13
|
+
current?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export type PickerRow = {
|
|
16
|
+
kind: "header";
|
|
17
|
+
label: string;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "item";
|
|
20
|
+
item: PaletteCommand;
|
|
21
|
+
index: number;
|
|
22
|
+
};
|
|
23
|
+
export type PickerView = {
|
|
24
|
+
/** Visible rows only (windowed around the cursor). */
|
|
25
|
+
rows: PickerRow[];
|
|
26
|
+
selectedIndex: number;
|
|
27
|
+
total: number;
|
|
28
|
+
};
|
|
29
|
+
/** Outer border (2) + search box (3) + hint row (1). */
|
|
30
|
+
export declare const COMMAND_PALETTE_CHROME_ROWS = 6;
|
|
31
|
+
/** Most list rows a picker shows before it scrolls. */
|
|
32
|
+
export declare const PICKER_MAX_ROWS = 12;
|
|
33
|
+
/** Matching items in display order: groups in first-match order, best matches first within each. */
|
|
34
|
+
export declare function pickerEntries(items: readonly PaletteCommand[], query: string): PaletteCommand[];
|
|
35
|
+
/** Rows for ordered entries: a header before each named group. */
|
|
36
|
+
export declare function pickerRows(entries: readonly PaletteCommand[]): PickerRow[];
|
|
37
|
+
/** List rows that fit a terminal of this height under the palette chrome. */
|
|
38
|
+
export declare function pickerMaxRows(terminalHeight: number): number;
|
|
39
|
+
export declare function pickerView(items: readonly PaletteCommand[], query: string, cursor: number, maxRows: number): PickerView;
|
|
40
|
+
/** Rows `CommandPalette` renders for a view: chrome plus list rows, or the single empty/loading row. */
|
|
41
|
+
export declare function pickerHeight(view: PickerView): number;
|
|
42
|
+
//# sourceMappingURL=palette-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
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,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAErD"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Outer border (2) + search box (3) + hint row (1). */
|
|
2
|
+
export const COMMAND_PALETTE_CHROME_ROWS = 6;
|
|
3
|
+
/** Most list rows a picker shows before it scrolls. */
|
|
4
|
+
export const PICKER_MAX_ROWS = 12;
|
|
5
|
+
/** Matching items in display order: groups in first-match order, best matches first within each. */
|
|
6
|
+
export function pickerEntries(items, query) {
|
|
7
|
+
const ranked = items
|
|
8
|
+
.map((item, position) => ({ item, position, score: matchScore(item, query) }))
|
|
9
|
+
.filter((entry) => entry.score !== undefined)
|
|
10
|
+
.sort((left, right) => left.score - right.score || left.position - right.position);
|
|
11
|
+
const groups = new Map();
|
|
12
|
+
for (const { item } of ranked) {
|
|
13
|
+
const members = groups.get(item.group) ?? [];
|
|
14
|
+
members.push(item);
|
|
15
|
+
groups.set(item.group, members);
|
|
16
|
+
}
|
|
17
|
+
return [...groups.values()].flat();
|
|
18
|
+
}
|
|
19
|
+
/** Rows for ordered entries: a header before each named group. */
|
|
20
|
+
export function pickerRows(entries) {
|
|
21
|
+
const rows = [];
|
|
22
|
+
let group;
|
|
23
|
+
entries.forEach((item, index) => {
|
|
24
|
+
if (item.group && (index === 0 || item.group !== group))
|
|
25
|
+
rows.push({ kind: "header", label: item.group });
|
|
26
|
+
group = item.group;
|
|
27
|
+
rows.push({ kind: "item", item, index });
|
|
28
|
+
});
|
|
29
|
+
return rows;
|
|
30
|
+
}
|
|
31
|
+
/** List rows that fit a terminal of this height under the palette chrome. */
|
|
32
|
+
export function pickerMaxRows(terminalHeight) {
|
|
33
|
+
return Math.max(1, Math.min(PICKER_MAX_ROWS, terminalHeight - COMMAND_PALETTE_CHROME_ROWS));
|
|
34
|
+
}
|
|
35
|
+
export function pickerView(items, query, cursor, maxRows) {
|
|
36
|
+
const entries = pickerEntries(items, query);
|
|
37
|
+
const rows = pickerRows(entries);
|
|
38
|
+
const selectedIndex = Math.max(0, Math.min(cursor, entries.length - 1));
|
|
39
|
+
if (rows.length <= maxRows)
|
|
40
|
+
return { rows, selectedIndex, total: entries.length };
|
|
41
|
+
const selectedRow = rows.findIndex((row) => row.kind === "item" && row.index === selectedIndex);
|
|
42
|
+
const start = Math.max(0, Math.min(selectedRow - Math.floor(maxRows / 2), rows.length - maxRows));
|
|
43
|
+
return { rows: rows.slice(start, start + maxRows), selectedIndex, total: entries.length };
|
|
44
|
+
}
|
|
45
|
+
/** Rows `CommandPalette` renders for a view: chrome plus list rows, or the single empty/loading row. */
|
|
46
|
+
export function pickerHeight(view) {
|
|
47
|
+
return COMMAND_PALETTE_CHROME_ROWS + Math.max(1, view.rows.length);
|
|
48
|
+
}
|
|
49
|
+
/** Lower is better; undefined when the item does not match. */
|
|
50
|
+
function matchScore(item, query) {
|
|
51
|
+
const needle = query.trim().toLowerCase();
|
|
52
|
+
if (!needle)
|
|
53
|
+
return 0;
|
|
54
|
+
const label = subsequenceScore(item.label.toLowerCase(), needle);
|
|
55
|
+
if (label !== undefined)
|
|
56
|
+
return label;
|
|
57
|
+
const rest = subsequenceScore(`${item.description ?? ""} ${item.group ?? ""}`.toLowerCase(), needle);
|
|
58
|
+
return rest === undefined ? undefined : 1_000 + rest;
|
|
59
|
+
}
|
|
60
|
+
/** Gap count of a subsequence match, so tighter and earlier matches rank first. */
|
|
61
|
+
function subsequenceScore(source, needle) {
|
|
62
|
+
const direct = source.indexOf(needle);
|
|
63
|
+
if (direct >= 0)
|
|
64
|
+
return direct;
|
|
65
|
+
let score = 0;
|
|
66
|
+
let last = -1;
|
|
67
|
+
let found = 0;
|
|
68
|
+
for (let index = 0; index < source.length && found < needle.length; index += 1) {
|
|
69
|
+
if (source[index] !== needle[found])
|
|
70
|
+
continue;
|
|
71
|
+
score += index - last - 1;
|
|
72
|
+
last = index;
|
|
73
|
+
found += 1;
|
|
74
|
+
}
|
|
75
|
+
return found === needle.length ? 100 + score : undefined;
|
|
76
|
+
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AAC,KAAK,GAAG,IAAI,CAAC;AACvD,CAAC;AAED,mFAAmF;AACnF,SAAS,gBAAgB,CAAC,MAAc,EAAE,MAAc;IACtD,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACtC,IAAI,MAAM,IAAI,CAAC;QAAE,OAAO,MAAM,CAAC;IAC/B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC;IACd,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC/E,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK,CAAC;YAAE,SAAS;QAC9C,KAAK,IAAI,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC;QAC1B,IAAI,GAAG,KAAK,CAAC;QACb,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;IACD,OAAO,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3D,CAAC","sourcesContent":["/**\n * Pure model for the command palette and every picker built on it. The footer\n * sizer, `App`, and `CommandPalette` all derive rows from here so the footer\n * height always equals what renders, and the cursor always indexes the same\n * order the rows are drawn in.\n */\nexport interface PaletteCommand {\n id: string;\n label: string;\n description?: string;\n group?: string;\n /** Marks the active value (current provider, model, mode, ...). */\n current?: boolean;\n}\n\nexport type PickerRow =\n | { kind: \"header\"; label: string }\n | { kind: \"item\"; item: PaletteCommand; index: number };\n\nexport type PickerView = {\n /** Visible rows only (windowed around the cursor). */\n rows: PickerRow[];\n selectedIndex: number;\n total: number;\n};\n\n/** Outer border (2) + search box (3) + hint row (1). */\nexport const COMMAND_PALETTE_CHROME_ROWS = 6;\n/** Most list rows a picker shows before it scrolls. */\nexport const PICKER_MAX_ROWS = 12;\n\n/** Matching items in display order: groups in first-match order, best matches first within each. */\nexport function pickerEntries(items: readonly PaletteCommand[], query: string): PaletteCommand[] {\n const ranked = items\n .map((item, position) => ({ item, position, score: matchScore(item, query) }))\n .filter((entry) => entry.score !== undefined)\n .sort((left, right) => left.score! - right.score! || left.position - right.position);\n const groups = new Map<string | undefined, PaletteCommand[]>();\n for (const { item } of ranked) {\n const members = groups.get(item.group) ?? [];\n members.push(item);\n groups.set(item.group, members);\n }\n return [...groups.values()].flat();\n}\n\n/** Rows for ordered entries: a header before each named group. */\nexport function pickerRows(entries: readonly PaletteCommand[]): PickerRow[] {\n const rows: PickerRow[] = [];\n let group: string | undefined;\n entries.forEach((item, index) => {\n if (item.group && (index === 0 || item.group !== group)) rows.push({ kind: \"header\", label: item.group });\n group = item.group;\n rows.push({ kind: \"item\", item, index });\n });\n return rows;\n}\n\n/** List rows that fit a terminal of this height under the palette chrome. */\nexport function pickerMaxRows(terminalHeight: number): number {\n return Math.max(1, Math.min(PICKER_MAX_ROWS, terminalHeight - COMMAND_PALETTE_CHROME_ROWS));\n}\n\nexport function pickerView(items: readonly PaletteCommand[], query: string, cursor: number, maxRows: number): PickerView {\n const entries = pickerEntries(items, query);\n const rows = pickerRows(entries);\n const selectedIndex = Math.max(0, Math.min(cursor, entries.length - 1));\n if (rows.length <= maxRows) return { rows, selectedIndex, total: entries.length };\n const selectedRow = rows.findIndex((row) => row.kind === \"item\" && row.index === selectedIndex);\n const start = Math.max(0, Math.min(selectedRow - Math.floor(maxRows / 2), rows.length - maxRows));\n return { rows: rows.slice(start, start + maxRows), selectedIndex, total: entries.length };\n}\n\n/** Rows `CommandPalette` renders for a view: chrome plus list rows, or the single empty/loading row. */\nexport function pickerHeight(view: PickerView): number {\n return COMMAND_PALETTE_CHROME_ROWS + Math.max(1, view.rows.length);\n}\n\n/** Lower is better; undefined when the item does not match. */\nfunction matchScore(item: PaletteCommand, query: string): number | undefined {\n const needle = query.trim().toLowerCase();\n if (!needle) return 0;\n const label = subsequenceScore(item.label.toLowerCase(), needle);\n if (label !== undefined) return label;\n const rest = subsequenceScore(`${item.description ?? \"\"} ${item.group ?? \"\"}`.toLowerCase(), needle);\n return rest === undefined ? undefined : 1_000 + rest;\n}\n\n/** Gap count of a subsequence match, so tighter and earlier matches rank first. */\nfunction subsequenceScore(source: string, needle: string): number | undefined {\n const direct = source.indexOf(needle);\n if (direct >= 0) return direct;\n let score = 0;\n let last = -1;\n let found = 0;\n for (let index = 0; index < source.length && found < needle.length; index += 1) {\n if (source[index] !== needle[found]) continue;\n score += index - last - 1;\n last = index;\n found += 1;\n }\n return found === needle.length ? 100 + score : undefined;\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@` path suggestions in the composer, ported from the legacy
|
|
3
|
+
* `crewcoder-tui/src/components/path-suggestions.ts`: the same walk, ignore
|
|
4
|
+
* list, limits, and matching, plus the pure token and windowing helpers the
|
|
5
|
+
* OpenTUI composer needs.
|
|
6
|
+
*/
|
|
7
|
+
export type PathSuggestion = {
|
|
8
|
+
/** Workspace-relative, POSIX separators; directories end with `/`. */
|
|
9
|
+
path: string;
|
|
10
|
+
type: "file" | "directory";
|
|
11
|
+
};
|
|
12
|
+
/** Lists workspace paths for a query; injectable so tests never walk a real tree. */
|
|
13
|
+
export type PathLister = (cwd: string, query: string, limit: number) => Promise<PathSuggestion[]>;
|
|
14
|
+
/** The `@token` around the cursor: `[start, end)` in the composer text, query without `@`. */
|
|
15
|
+
export type MentionToken = {
|
|
16
|
+
start: number;
|
|
17
|
+
end: number;
|
|
18
|
+
query: string;
|
|
19
|
+
};
|
|
20
|
+
/** Suggestions fetched per query, like the legacy UI. */
|
|
21
|
+
export declare const MENTION_LIMIT = 50;
|
|
22
|
+
/** List rows shown under the composer; longer lists scroll with the cursor. */
|
|
23
|
+
export declare const MENTION_ROWS = 8;
|
|
24
|
+
/**
|
|
25
|
+
* The mention token the cursor is in, or undefined. A token starts after
|
|
26
|
+
* whitespace (or at the start) with `@`, so `user@host` never triggers, and
|
|
27
|
+
* holds only path characters.
|
|
28
|
+
*/
|
|
29
|
+
export declare function currentMention(text: string, cursor: number): MentionToken | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* The composer text with the token replaced by the picked path, and the cursor
|
|
32
|
+
* after it. A file gets a trailing space (done); a directory (`src/`) does
|
|
33
|
+
* not, so its contents are suggested next.
|
|
34
|
+
*/
|
|
35
|
+
export declare function replaceMention(text: string, token: MentionToken, pick: PathSuggestion): {
|
|
36
|
+
text: string;
|
|
37
|
+
cursor: number;
|
|
38
|
+
};
|
|
39
|
+
/** First row to draw so `cursor` stays visible in `rows` rows. */
|
|
40
|
+
export declare function mentionWindowStart(count: number, cursor: number, rows?: number): number;
|
|
41
|
+
/** Rows the suggestion list takes under the composer (one for the empty note). */
|
|
42
|
+
export declare function mentionRows(count: number, rows?: number): number;
|
|
43
|
+
/**
|
|
44
|
+
* Up to `limit` workspace paths matching `query`, directories first at each
|
|
45
|
+
* level, skipping build output and VCS folders. Stops after MAX_VISITED
|
|
46
|
+
* entries or MAX_DEPTH levels so a huge tree never stalls typing. Unreadable
|
|
47
|
+
* directories are skipped.
|
|
48
|
+
*/
|
|
49
|
+
export declare const listPathSuggestions: PathLister;
|
|
50
|
+
//# sourceMappingURL=path-suggestions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-suggestions.d.ts","sourceRoot":"","sources":["../src/path-suggestions.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;CAC5B,CAAC;AAEF,qFAAqF;AACrF,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;AAElG,8FAA8F;AAC9F,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzE,yDAAyD;AACzD,eAAO,MAAM,aAAa,KAAK,CAAC;AAChC,+EAA+E;AAC/E,eAAO,MAAM,YAAY,IAAI,CAAC;AAM9B;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAUrF;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAGxH;AAED,kEAAkE;AAClE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,MAAqB,GAAG,MAAM,CAGrG;AAED,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,MAAqB,GAAG,MAAM,CAE9E;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,UA+BjC,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/** Suggestions fetched per query, like the legacy UI. */
|
|
4
|
+
export const MENTION_LIMIT = 50;
|
|
5
|
+
/** List rows shown under the composer; longer lists scroll with the cursor. */
|
|
6
|
+
export const MENTION_ROWS = 8;
|
|
7
|
+
const IGNORED = new Set([".git", "node_modules", "dist", "build", ".next", ".turbo", "coverage", ".cache", ".crewcoder"]);
|
|
8
|
+
const MAX_VISITED = 1500;
|
|
9
|
+
const MAX_DEPTH = 7;
|
|
10
|
+
/**
|
|
11
|
+
* The mention token the cursor is in, or undefined. A token starts after
|
|
12
|
+
* whitespace (or at the start) with `@`, so `user@host` never triggers, and
|
|
13
|
+
* holds only path characters.
|
|
14
|
+
*/
|
|
15
|
+
export function currentMention(text, cursor) {
|
|
16
|
+
const at = Math.max(0, Math.min(text.length, cursor));
|
|
17
|
+
const before = text.slice(0, at);
|
|
18
|
+
const start = Math.max(before.lastIndexOf(" "), before.lastIndexOf("\n"), before.lastIndexOf("\t")) + 1;
|
|
19
|
+
if (text[start] !== "@")
|
|
20
|
+
return undefined;
|
|
21
|
+
const rest = text.slice(at).search(/\s/);
|
|
22
|
+
const end = rest === -1 ? text.length : at + rest;
|
|
23
|
+
const token = text.slice(start, end);
|
|
24
|
+
if (!/^@[A-Za-z0-9._/\\-]*$/.test(token))
|
|
25
|
+
return undefined;
|
|
26
|
+
return { start, end, query: token.slice(1) };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The composer text with the token replaced by the picked path, and the cursor
|
|
30
|
+
* after it. A file gets a trailing space (done); a directory (`src/`) does
|
|
31
|
+
* not, so its contents are suggested next.
|
|
32
|
+
*/
|
|
33
|
+
export function replaceMention(text, token, pick) {
|
|
34
|
+
const replacement = pick.type === "directory" ? `@${pick.path}` : `@${pick.path} `;
|
|
35
|
+
return { text: text.slice(0, token.start) + replacement + text.slice(token.end), cursor: token.start + replacement.length };
|
|
36
|
+
}
|
|
37
|
+
/** First row to draw so `cursor` stays visible in `rows` rows. */
|
|
38
|
+
export function mentionWindowStart(count, cursor, rows = MENTION_ROWS) {
|
|
39
|
+
if (count <= rows)
|
|
40
|
+
return 0;
|
|
41
|
+
return Math.min(Math.max(0, cursor - rows + 1), count - rows);
|
|
42
|
+
}
|
|
43
|
+
/** Rows the suggestion list takes under the composer (one for the empty note). */
|
|
44
|
+
export function mentionRows(count, rows = MENTION_ROWS) {
|
|
45
|
+
return Math.max(1, Math.min(count, rows));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Up to `limit` workspace paths matching `query`, directories first at each
|
|
49
|
+
* level, skipping build output and VCS folders. Stops after MAX_VISITED
|
|
50
|
+
* entries or MAX_DEPTH levels so a huge tree never stalls typing. Unreadable
|
|
51
|
+
* directories are skipped.
|
|
52
|
+
*/
|
|
53
|
+
export const listPathSuggestions = async (cwd, query, limit) => {
|
|
54
|
+
const wanted = normalizeQuery(query);
|
|
55
|
+
const results = [];
|
|
56
|
+
let visited = 0;
|
|
57
|
+
async function walk(dir, depth) {
|
|
58
|
+
if (results.length >= limit || visited >= MAX_VISITED || depth > MAX_DEPTH)
|
|
59
|
+
return;
|
|
60
|
+
let entries;
|
|
61
|
+
try {
|
|
62
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
entries.sort((a, b) => Number(b.isDirectory()) - Number(a.isDirectory()) || a.name.localeCompare(b.name));
|
|
68
|
+
for (const entry of entries) {
|
|
69
|
+
if (results.length >= limit || visited >= MAX_VISITED)
|
|
70
|
+
return;
|
|
71
|
+
if (IGNORED.has(entry.name))
|
|
72
|
+
continue;
|
|
73
|
+
const full = path.join(dir, entry.name);
|
|
74
|
+
const relative = path.relative(cwd, full).split(path.sep).join("/");
|
|
75
|
+
visited += 1;
|
|
76
|
+
if (entry.isDirectory()) {
|
|
77
|
+
if (matchesQuery(relative, wanted))
|
|
78
|
+
results.push({ path: `${relative}/`, type: "directory" });
|
|
79
|
+
await walk(full, depth + 1);
|
|
80
|
+
}
|
|
81
|
+
else if (entry.isFile() && matchesQuery(relative, wanted)) {
|
|
82
|
+
results.push({ path: relative, type: "file" });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
await walk(cwd, 0);
|
|
87
|
+
return results.slice(0, limit);
|
|
88
|
+
};
|
|
89
|
+
function normalizeQuery(query) {
|
|
90
|
+
return query.replace(/^@/, "").replace(/^\.\//, "").toLowerCase();
|
|
91
|
+
}
|
|
92
|
+
/** Prefix of the path, of any path segment, or of the file name. */
|
|
93
|
+
function matchesQuery(relative, query) {
|
|
94
|
+
if (!query)
|
|
95
|
+
return true;
|
|
96
|
+
const lower = relative.toLowerCase();
|
|
97
|
+
return lower.startsWith(query) || lower.includes(`/${query}`) || path.posix.basename(lower).startsWith(query);
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=path-suggestions.js.map
|