@abacus-ai/cli 1.106.25007 → 2.0.0-canary.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/.oxlintrc.json +8 -0
- package/dist/index.mjs +12603 -0
- package/package.json +7 -39
- package/resources/abacus.ico +0 -0
- package/resources/entitlements.plist +9 -0
- package/src/__e2e__/README.md +196 -0
- package/src/__e2e__/agent-interactions.e2e.test.tsx +61 -0
- package/src/__e2e__/cli-commands.e2e.test.tsx +77 -0
- package/src/__e2e__/conversation-throttle.e2e.test.ts +453 -0
- package/src/__e2e__/conversation.e2e.test.tsx +56 -0
- package/src/__e2e__/diff-preview.e2e.test.tsx +3399 -0
- package/src/__e2e__/file-creation.e2e.test.tsx +149 -0
- package/src/__e2e__/helpers/test-helpers.ts +450 -0
- package/src/__e2e__/keyboard-navigation.e2e.test.tsx +34 -0
- package/src/__e2e__/llm-models.e2e.test.ts +402 -0
- package/src/__e2e__/mcp/mcp-callback-flow.e2e.test.tsx +71 -0
- package/src/__e2e__/mcp/mcp-full-app-ui.e2e.test.tsx +167 -0
- package/src/__e2e__/mcp/mcp-ui-rendering.e2e.test.tsx +185 -0
- package/src/__e2e__/repl.e2e.test.tsx +78 -0
- package/src/__e2e__/shell-compatibility.e2e.test.tsx +76 -0
- package/src/__e2e__/theme-mcp.e2e.test.tsx +98 -0
- package/src/__e2e__/tool-permissions.e2e.test.tsx +66 -0
- package/src/args.ts +22 -0
- package/src/components/__tests__/react-compiler.test.tsx +78 -0
- package/src/components/__tests__/status-indicator.test.tsx +403 -0
- package/src/components/composer/__tests__/bash-runner.test.tsx +263 -0
- package/src/components/composer/agent-mode-indicator.tsx +63 -0
- package/src/components/composer/bash-runner.tsx +54 -0
- package/src/components/composer/commands/default-commands.tsx +615 -0
- package/src/components/composer/commands/handler.tsx +59 -0
- package/src/components/composer/commands/picker.tsx +273 -0
- package/src/components/composer/commands/registry.ts +233 -0
- package/src/components/composer/commands/types.ts +33 -0
- package/src/components/composer/context.tsx +88 -0
- package/src/components/composer/file-mention-picker.tsx +83 -0
- package/src/components/composer/help.tsx +44 -0
- package/src/components/composer/index.tsx +1006 -0
- package/src/components/composer/mentions.ts +57 -0
- package/src/components/composer/message-queue.tsx +70 -0
- package/src/components/composer/mode-panel.tsx +35 -0
- package/src/components/composer/modes/__tests__/bash-handler.test.tsx +755 -0
- package/src/components/composer/modes/__tests__/bash-renderer.test.tsx +1108 -0
- package/src/components/composer/modes/bash-handler.tsx +132 -0
- package/src/components/composer/modes/bash-renderer.tsx +175 -0
- package/src/components/composer/modes/default-handlers.tsx +33 -0
- package/src/components/composer/modes/index.ts +41 -0
- package/src/components/composer/modes/types.ts +21 -0
- package/src/components/composer/persistent-shell.ts +283 -0
- package/src/components/composer/process.ts +65 -0
- package/src/components/composer/types.ts +9 -0
- package/src/components/composer/use-mention-search.ts +68 -0
- package/src/components/error-boundry.tsx +60 -0
- package/src/components/exit-message.tsx +29 -0
- package/src/components/expanded-view.tsx +74 -0
- package/src/components/file-completion.tsx +127 -0
- package/src/components/header.tsx +47 -0
- package/src/components/logo.tsx +37 -0
- package/src/components/segments.tsx +356 -0
- package/src/components/status-indicator.tsx +306 -0
- package/src/components/tool-group-summary.tsx +263 -0
- package/src/components/tool-permissions/ask-user-question-permission-ui.tsx +312 -0
- package/src/components/tool-permissions/diff-preview.tsx +355 -0
- package/src/components/tool-permissions/index.ts +5 -0
- package/src/components/tool-permissions/permission-options.tsx +375 -0
- package/src/components/tool-permissions/permission-preview-header.tsx +57 -0
- package/src/components/tool-permissions/tool-permission-ui.tsx +398 -0
- package/src/components/tools/agent/ask-user-question.tsx +101 -0
- package/src/components/tools/agent/enter-plan-mode.tsx +49 -0
- package/src/components/tools/agent/exit-plan-mode.tsx +75 -0
- package/src/components/tools/agent/handoff-to-main.tsx +27 -0
- package/src/components/tools/agent/subagent.tsx +37 -0
- package/src/components/tools/agent/todo-write.tsx +104 -0
- package/src/components/tools/browser/close-tab.tsx +58 -0
- package/src/components/tools/browser/computer.tsx +70 -0
- package/src/components/tools/browser/get-interactive-elements.tsx +54 -0
- package/src/components/tools/browser/get-tab-content.tsx +51 -0
- package/src/components/tools/browser/navigate-to.tsx +59 -0
- package/src/components/tools/browser/new-tab.tsx +60 -0
- package/src/components/tools/browser/perform-action.tsx +63 -0
- package/src/components/tools/browser/refresh-tab.tsx +43 -0
- package/src/components/tools/browser/switch-tab.tsx +58 -0
- package/src/components/tools/filesystem/delete-file.tsx +104 -0
- package/src/components/tools/filesystem/edit.tsx +220 -0
- package/src/components/tools/filesystem/list-dir.tsx +78 -0
- package/src/components/tools/filesystem/read-file.tsx +180 -0
- package/src/components/tools/filesystem/upload-image.tsx +76 -0
- package/src/components/tools/ide/ide-diagnostics.tsx +62 -0
- package/src/components/tools/index.ts +91 -0
- package/src/components/tools/mcp/mcp-tool.tsx +158 -0
- package/src/components/tools/search/fetch-url.tsx +73 -0
- package/src/components/tools/search/file-search.tsx +78 -0
- package/src/components/tools/search/grep.tsx +90 -0
- package/src/components/tools/search/semantic-search.tsx +66 -0
- package/src/components/tools/search/web-search.tsx +71 -0
- package/src/components/tools/shared/index.tsx +48 -0
- package/src/components/tools/shared/zod-coercion.ts +35 -0
- package/src/components/tools/terminal/bash-tool-output.tsx +174 -0
- package/src/components/tools/terminal/get-terminal-output.tsx +85 -0
- package/src/components/tools/terminal/run-in-terminal.tsx +106 -0
- package/src/components/tools/types.ts +16 -0
- package/src/components/tools.tsx +66 -0
- package/src/components/ui/__tests__/divider.test.tsx +61 -0
- package/src/components/ui/__tests__/gradient.test.tsx +125 -0
- package/src/components/ui/__tests__/input.test.tsx +166 -0
- package/src/components/ui/__tests__/select.test.tsx +273 -0
- package/src/components/ui/__tests__/shimmer.test.tsx +99 -0
- package/src/components/ui/blinking-indicator.tsx +25 -0
- package/src/components/ui/divider.tsx +162 -0
- package/src/components/ui/gradient.tsx +56 -0
- package/src/components/ui/input.tsx +228 -0
- package/src/components/ui/select.tsx +151 -0
- package/src/components/ui/shimmer.tsx +84 -0
- package/src/context/agent-mode.tsx +95 -0
- package/src/context/extension-file.tsx +136 -0
- package/src/context/network-activity.tsx +45 -0
- package/src/context/notification.tsx +62 -0
- package/src/context/shell-size.tsx +49 -0
- package/src/context/shell-title.tsx +38 -0
- package/src/entrypoints/print-mode.ts +312 -0
- package/src/entrypoints/repl.tsx +401 -0
- package/src/hooks/use-agent.ts +15 -0
- package/src/hooks/use-api-client.ts +1 -0
- package/src/hooks/use-available-height.ts +8 -0
- package/src/hooks/use-cleanup.ts +29 -0
- package/src/hooks/use-interrupt-manager.ts +242 -0
- package/src/hooks/use-models.ts +22 -0
- package/src/index.ts +217 -0
- package/src/lib/__tests__/ansi.test.ts +255 -0
- package/src/lib/__tests__/cli.test.ts +122 -0
- package/src/lib/__tests__/commands.test.ts +325 -0
- package/src/lib/__tests__/constants.test.ts +15 -0
- package/src/lib/__tests__/focusables.test.ts +25 -0
- package/src/lib/__tests__/fs.test.ts +231 -0
- package/src/lib/__tests__/markdown.test.tsx +348 -0
- package/src/lib/__tests__/mcpCommandHandler.test.ts +173 -0
- package/src/lib/__tests__/mcpManagement.test.ts +38 -0
- package/src/lib/__tests__/path-paste.test.ts +144 -0
- package/src/lib/__tests__/path.test.ts +300 -0
- package/src/lib/__tests__/queries.test.ts +39 -0
- package/src/lib/__tests__/standaloneMcpService.test.ts +71 -0
- package/src/lib/__tests__/text-buffer.test.ts +328 -0
- package/src/lib/__tests__/text-utils.test.ts +32 -0
- package/src/lib/__tests__/timing.test.ts +78 -0
- package/src/lib/__tests__/utils.test.ts +238 -0
- package/src/lib/__tests__/vim-buffer-actions.test.ts +154 -0
- package/src/lib/ansi.ts +150 -0
- package/src/lib/cli-push-server.ts +112 -0
- package/src/lib/cli.ts +44 -0
- package/src/lib/clipboard.ts +226 -0
- package/src/lib/command-utils.ts +93 -0
- package/src/lib/commands.ts +270 -0
- package/src/lib/constants.ts +3 -0
- package/src/lib/extension-connection.ts +181 -0
- package/src/lib/focusables.ts +7 -0
- package/src/lib/fs.ts +533 -0
- package/src/lib/markdown/code-block.tsx +63 -0
- package/src/lib/markdown/index.ts +4 -0
- package/src/lib/markdown/link.tsx +19 -0
- package/src/lib/markdown/markdown.tsx +372 -0
- package/src/lib/markdown/types.ts +15 -0
- package/src/lib/mcpCommandHandler.ts +121 -0
- package/src/lib/mcpManagement.ts +44 -0
- package/src/lib/path-paste.ts +185 -0
- package/src/lib/path.ts +179 -0
- package/src/lib/queries.ts +15 -0
- package/src/lib/standaloneMcpService.ts +688 -0
- package/src/lib/status-utils.ts +237 -0
- package/src/lib/test-utils.tsx +72 -0
- package/src/lib/text-buffer.ts +2415 -0
- package/src/lib/text-utils.ts +272 -0
- package/src/lib/timing.ts +63 -0
- package/src/lib/types.ts +295 -0
- package/src/lib/utils.ts +182 -0
- package/src/lib/vim-buffer-actions.ts +732 -0
- package/src/providers/agent.tsx +1075 -0
- package/src/providers/api-client.tsx +43 -0
- package/src/services/logger.ts +85 -0
- package/src/terminal/detection.ts +187 -0
- package/src/terminal/exit.ts +279 -0
- package/src/terminal/notification.ts +83 -0
- package/src/terminal/progress.ts +201 -0
- package/src/terminal/setup.ts +797 -0
- package/src/terminal/suspend.ts +58 -0
- package/src/terminal/types.ts +51 -0
- package/src/theme/context.tsx +57 -0
- package/src/theme/index.ts +4 -0
- package/src/theme/themed.tsx +35 -0
- package/src/theme/themes.json +546 -0
- package/src/theme/types.ts +110 -0
- package/src/tools/types.ts +59 -0
- package/src/tools/utils/__tests__/zod-coercion.test.ts +33 -0
- package/src/tools/utils/tool-ui-components.tsx +631 -0
- package/src/tools/utils/zod-coercion.ts +35 -0
- package/tsconfig.json +11 -0
- package/tsconfig.node.json +29 -0
- package/tsconfig.test.json +27 -0
- package/tsdown.config.ts +17 -0
- package/vitest.config.ts +76 -0
- package/README.md +0 -28
- package/dist/index.js +0 -26
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { View, type ViewStyle } from "@codellm/jar";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Props for the Divider component.
|
|
5
|
+
*/
|
|
6
|
+
interface DividerProps {
|
|
7
|
+
/**
|
|
8
|
+
* Width of the divider.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <Divider width={50} />
|
|
13
|
+
*
|
|
14
|
+
* // ──────────────────────────────────────────────────
|
|
15
|
+
* ```
|
|
16
|
+
* @default 'auto'
|
|
17
|
+
*/
|
|
18
|
+
width?: "auto" | number;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Padding at the start and the end of the divider.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <Divider padding={2} />
|
|
26
|
+
*
|
|
27
|
+
* // ··─────────────────────────────··
|
|
28
|
+
* ```
|
|
29
|
+
* @default 0
|
|
30
|
+
*/
|
|
31
|
+
padding?: number;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Char used as a divider.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* <Divider dividerChar="=" />
|
|
39
|
+
*
|
|
40
|
+
* // =============================
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @default '─'
|
|
44
|
+
*/
|
|
45
|
+
dividerChar?: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Color of the divider's border. Matches the type of `borderColor` in the Ink `Box` component.
|
|
49
|
+
* Accepts standard Ink color names or hex codes.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```tsx
|
|
53
|
+
* <Divider dividerColor="red" />
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @default 'gray'
|
|
57
|
+
*/
|
|
58
|
+
dividerColor?: ViewStyle["borderColor"];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Padding at the start and the end of the divider.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```tsx
|
|
65
|
+
* <Divider padding={2} />
|
|
66
|
+
*
|
|
67
|
+
* // ··─────────────────────────────··
|
|
68
|
+
* ```
|
|
69
|
+
* @default 0
|
|
70
|
+
*/
|
|
71
|
+
childrenPadding?: number;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Additional props to be passed to the underlying Ink `Box` component.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```tsx
|
|
78
|
+
* <Divider boxProps={{ marginTop: 2 }} />
|
|
79
|
+
*
|
|
80
|
+
*
|
|
81
|
+
* //
|
|
82
|
+
* //
|
|
83
|
+
* // ─────────────────────────────
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
boxProps?: ViewStyle;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const BaseDivider: React.FC<DividerProps> = ({
|
|
90
|
+
width = "auto",
|
|
91
|
+
dividerChar,
|
|
92
|
+
dividerColor = "gray",
|
|
93
|
+
boxProps,
|
|
94
|
+
}) => (
|
|
95
|
+
<View
|
|
96
|
+
width={width}
|
|
97
|
+
// @ts-expect-error
|
|
98
|
+
borderStyle={{
|
|
99
|
+
bottom: dividerChar,
|
|
100
|
+
}}
|
|
101
|
+
borderColor={dividerColor}
|
|
102
|
+
//
|
|
103
|
+
flexGrow={1}
|
|
104
|
+
//
|
|
105
|
+
borderBottom={true}
|
|
106
|
+
//
|
|
107
|
+
borderTop={false}
|
|
108
|
+
borderLeft={false}
|
|
109
|
+
borderRight={false}
|
|
110
|
+
//
|
|
111
|
+
{...boxProps}
|
|
112
|
+
/>
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* A horizontal divider component styled as a single border line.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```tsx
|
|
120
|
+
* import { render } from 'ink'
|
|
121
|
+
* import Divider from 'ink-divider'
|
|
122
|
+
*
|
|
123
|
+
* render(<Divider title='Title' />)
|
|
124
|
+
*
|
|
125
|
+
* // ─────────── Title ───────────
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @returns A styled divider.
|
|
129
|
+
*/
|
|
130
|
+
export const Divider: React.FC<React.PropsWithChildren<DividerProps>> = ({
|
|
131
|
+
width = "auto",
|
|
132
|
+
padding = 0,
|
|
133
|
+
dividerChar = "─",
|
|
134
|
+
dividerColor = "gray",
|
|
135
|
+
childrenPadding = 0,
|
|
136
|
+
boxProps,
|
|
137
|
+
children,
|
|
138
|
+
}) => {
|
|
139
|
+
const dividerLine = (
|
|
140
|
+
<BaseDivider dividerChar={dividerChar} dividerColor={dividerColor} boxProps={boxProps} />
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
// If there is no title, return only the divider line
|
|
144
|
+
if (!children) {
|
|
145
|
+
return (
|
|
146
|
+
<View paddingLeft={padding} paddingRight={padding}>
|
|
147
|
+
{dividerLine}
|
|
148
|
+
</View>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Otherwise, return the divider line with the title in the middle
|
|
153
|
+
return (
|
|
154
|
+
<View width={width} paddingLeft={padding} paddingRight={padding} gap={childrenPadding}>
|
|
155
|
+
{dividerLine}
|
|
156
|
+
|
|
157
|
+
<View>{children}</View>
|
|
158
|
+
|
|
159
|
+
{dividerLine}
|
|
160
|
+
</View>
|
|
161
|
+
);
|
|
162
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Text } from "@codellm/jar";
|
|
2
|
+
import * as gradientString from "gradient-string";
|
|
3
|
+
import { memo, useMemo } from "react";
|
|
4
|
+
import stripAnsi from "strip-ansi";
|
|
5
|
+
|
|
6
|
+
type GradientName =
|
|
7
|
+
| "atlas"
|
|
8
|
+
| "cristal"
|
|
9
|
+
| "teen"
|
|
10
|
+
| "mind"
|
|
11
|
+
| "morning"
|
|
12
|
+
| "vice"
|
|
13
|
+
| "passion"
|
|
14
|
+
| "fruit"
|
|
15
|
+
| "instagram"
|
|
16
|
+
| "retro"
|
|
17
|
+
| "summer"
|
|
18
|
+
| "pastel"
|
|
19
|
+
| "rainbow";
|
|
20
|
+
|
|
21
|
+
type GradientColors = Array<tinycolor.ColorInput>;
|
|
22
|
+
|
|
23
|
+
type GradientProps = {
|
|
24
|
+
readonly children: React.ReactNode;
|
|
25
|
+
} & (
|
|
26
|
+
| {
|
|
27
|
+
/**
|
|
28
|
+
* The name of a [built-in gradient](https://github.com/bokub/gradient-string#available-built-in-gradients).
|
|
29
|
+
* Mutually exclusive with `colors`.
|
|
30
|
+
*/
|
|
31
|
+
readonly name: GradientName;
|
|
32
|
+
readonly colors?: never;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
/**
|
|
36
|
+
* [Colors to use to make the gradient.](https://github.com/bokub/gradient-string#initialize-a-gradient)
|
|
37
|
+
* Mutually exclusive with `name`.
|
|
38
|
+
*/
|
|
39
|
+
readonly colors: GradientColors;
|
|
40
|
+
readonly name?: never;
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export const Gradient = memo((props: GradientProps) => {
|
|
45
|
+
const gradient = useMemo(() => {
|
|
46
|
+
if (props.name) {
|
|
47
|
+
return gradientString[props.name];
|
|
48
|
+
}
|
|
49
|
+
return gradientString.default(...props.colors);
|
|
50
|
+
}, [props.name, props.colors]);
|
|
51
|
+
|
|
52
|
+
const applyGradient = (text: string) => gradient.multiline(stripAnsi(text));
|
|
53
|
+
|
|
54
|
+
return <Text transform={applyGradient}>{props.children}</Text>;
|
|
55
|
+
});
|
|
56
|
+
Gradient.displayName = "Gradient";
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { View, Text } from "@codellm/jar";
|
|
2
|
+
import { type Key, useInput, useFocusState } from "@codellm/jar";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { memo, useCallback, useEffect, useMemo } from "react";
|
|
5
|
+
|
|
6
|
+
import { TextBuffer, useTextBuffer } from "../../lib/text-buffer.js";
|
|
7
|
+
|
|
8
|
+
export interface InputKeyDownEvent {
|
|
9
|
+
input: string;
|
|
10
|
+
key: Key;
|
|
11
|
+
target: TextBuffer;
|
|
12
|
+
preventDefault: () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type GrammarRule = {
|
|
16
|
+
regex: RegExp;
|
|
17
|
+
color: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
interface InputProps extends Omit<React.ComponentProps<typeof View>, "children" | "ref"> {
|
|
21
|
+
ref?: React.RefObject<TextBuffer | null>;
|
|
22
|
+
initialValue?: string;
|
|
23
|
+
onKeyDown?: (e: InputKeyDownEvent) => void;
|
|
24
|
+
onChange?: (value: string, buffer: TextBuffer) => void;
|
|
25
|
+
onSubmit?: (value: string) => void;
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
placeholderProps?: Omit<React.ComponentProps<typeof Text>, "children">;
|
|
28
|
+
grammar?: ReadonlyArray<GrammarRule>;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
width?: number;
|
|
31
|
+
height?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const HEX_COLOR_RE = /^#(?:[0-9a-fA-F]{3}){1,2}$/;
|
|
35
|
+
|
|
36
|
+
function colorizeWithChalk(text: string, color: string): string {
|
|
37
|
+
if (!text) return text;
|
|
38
|
+
if (HEX_COLOR_RE.test(color)) return chalk.hex(color)(text);
|
|
39
|
+
const maybe = (chalk as unknown as Record<string, unknown>)[color];
|
|
40
|
+
if (typeof maybe === "function") {
|
|
41
|
+
const fn = maybe as (input: string) => string;
|
|
42
|
+
return fn(text);
|
|
43
|
+
}
|
|
44
|
+
return text;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function ensureGlobalRegex(regex: RegExp): RegExp {
|
|
48
|
+
const flags = regex.flags.includes("g") ? regex.flags : `${regex.flags}g`;
|
|
49
|
+
return new RegExp(regex.source, flags);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function highlightTextWithGrammar(text: string, rules?: ReadonlyArray<GrammarRule>): string {
|
|
53
|
+
if (!rules?.length || !text) return text;
|
|
54
|
+
|
|
55
|
+
type Token = { text: string; styled: boolean };
|
|
56
|
+
let tokens: Token[] = [{ text, styled: false }];
|
|
57
|
+
|
|
58
|
+
for (const rule of rules) {
|
|
59
|
+
const regex = ensureGlobalRegex(rule.regex);
|
|
60
|
+
const nextTokens: Token[] = [];
|
|
61
|
+
|
|
62
|
+
for (const token of tokens) {
|
|
63
|
+
if (token.styled || !token.text) {
|
|
64
|
+
nextTokens.push(token);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let lastIndex = 0;
|
|
69
|
+
let match: RegExpExecArray | null;
|
|
70
|
+
while ((match = regex.exec(token.text)) !== null) {
|
|
71
|
+
const start = match.index;
|
|
72
|
+
const end = start + match[0].length;
|
|
73
|
+
|
|
74
|
+
if (start > lastIndex) {
|
|
75
|
+
nextTokens.push({ text: token.text.slice(lastIndex, start), styled: false });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const matched = token.text.slice(start, end);
|
|
79
|
+
const colored = colorizeWithChalk(matched, rule.color);
|
|
80
|
+
nextTokens.push({ text: colored, styled: true });
|
|
81
|
+
|
|
82
|
+
if (end === lastIndex) {
|
|
83
|
+
regex.lastIndex += 1;
|
|
84
|
+
}
|
|
85
|
+
lastIndex = end;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (lastIndex < token.text.length) {
|
|
89
|
+
nextTokens.push({ text: token.text.slice(lastIndex), styled: false });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
tokens = nextTokens;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return tokens.map((t) => t.text).join("");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const Input = memo(
|
|
100
|
+
({
|
|
101
|
+
initialValue,
|
|
102
|
+
onChange,
|
|
103
|
+
onSubmit,
|
|
104
|
+
placeholder = "Type text...",
|
|
105
|
+
ref,
|
|
106
|
+
placeholderProps,
|
|
107
|
+
onKeyDown,
|
|
108
|
+
grammar,
|
|
109
|
+
disabled,
|
|
110
|
+
width = Number.MAX_SAFE_INTEGER,
|
|
111
|
+
height = Number.MAX_SAFE_INTEGER,
|
|
112
|
+
...props
|
|
113
|
+
}: InputProps) => {
|
|
114
|
+
const { isFocused } = useFocusState();
|
|
115
|
+
|
|
116
|
+
const buffer = useTextBuffer({
|
|
117
|
+
initialText: initialValue,
|
|
118
|
+
initialCursorOffset: 0,
|
|
119
|
+
viewport: { width, height },
|
|
120
|
+
onChange: (value) => onChange?.(value, buffer),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (ref) {
|
|
125
|
+
ref.current = buffer;
|
|
126
|
+
}
|
|
127
|
+
}, [buffer, ref]);
|
|
128
|
+
|
|
129
|
+
const handleSubmit = useCallback(() => {
|
|
130
|
+
const value = buffer.text;
|
|
131
|
+
if (!value.trim()) return;
|
|
132
|
+
onSubmit?.(value);
|
|
133
|
+
buffer.setText("");
|
|
134
|
+
}, [buffer, onSubmit]);
|
|
135
|
+
|
|
136
|
+
const handleKeypress = useCallback(
|
|
137
|
+
(input: string, key: Key) => {
|
|
138
|
+
let prevented = false;
|
|
139
|
+
onKeyDown?.({
|
|
140
|
+
input,
|
|
141
|
+
key,
|
|
142
|
+
target: buffer,
|
|
143
|
+
preventDefault: () => {
|
|
144
|
+
prevented = true;
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
if (prevented) return;
|
|
148
|
+
if (disabled) return;
|
|
149
|
+
|
|
150
|
+
if (!disabled && key.return && !key.ctrl && !key.meta && !key.shift) {
|
|
151
|
+
// Check for backslash-enter pattern for newline
|
|
152
|
+
const text = buffer.text;
|
|
153
|
+
if (text.endsWith("\\")) {
|
|
154
|
+
// Remove the backslash and insert a newline
|
|
155
|
+
buffer.backspace();
|
|
156
|
+
buffer.newline();
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
handleSubmit();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
buffer.handleInput(input, key);
|
|
164
|
+
},
|
|
165
|
+
[buffer, handleSubmit, onKeyDown, disabled],
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
useInput(handleKeypress, { isActive: true });
|
|
169
|
+
|
|
170
|
+
const linesToRender = buffer.viewportVisualLines;
|
|
171
|
+
const [cursorVisualRowAbsolute, cursorVisualColAbsolute] = buffer.visualCursor;
|
|
172
|
+
const scrollVisualRow = buffer.visualScrollRow;
|
|
173
|
+
|
|
174
|
+
const showCursor = isFocused;
|
|
175
|
+
const applyGrammar = useMemo(
|
|
176
|
+
() => (text: string) => highlightTextWithGrammar(text, grammar),
|
|
177
|
+
[grammar],
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
if (!buffer.text && placeholder) {
|
|
181
|
+
return (
|
|
182
|
+
<View {...props}>
|
|
183
|
+
{showCursor ? (
|
|
184
|
+
<Text dimColor {...placeholderProps}>
|
|
185
|
+
{chalk.inverse(placeholder.slice(0, 1))}
|
|
186
|
+
{placeholder.slice(1)}
|
|
187
|
+
</Text>
|
|
188
|
+
) : (
|
|
189
|
+
<Text color="gray" {...placeholderProps}>
|
|
190
|
+
{placeholder}
|
|
191
|
+
</Text>
|
|
192
|
+
)}
|
|
193
|
+
</View>
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<View flexDirection="column" flexGrow={1} {...props}>
|
|
199
|
+
{linesToRender.map((lineText, visualIdxInRenderedSet) => {
|
|
200
|
+
const absoluteVisualIdx = scrollVisualRow + visualIdxInRenderedSet;
|
|
201
|
+
const cursorVisualRow = cursorVisualRowAbsolute - scrollVisualRow;
|
|
202
|
+
const isOnCursorLine = showCursor && visualIdxInRenderedSet === cursorVisualRow;
|
|
203
|
+
|
|
204
|
+
if (!isOnCursorLine) {
|
|
205
|
+
const content = grammar?.length ? applyGrammar(lineText) : lineText;
|
|
206
|
+
return <Text key={`line-${absoluteVisualIdx}`}>{content || " "}</Text>;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const before = lineText.slice(0, cursorVisualColAbsolute);
|
|
210
|
+
const cursorChar = lineText[cursorVisualColAbsolute] ?? " ";
|
|
211
|
+
const after = lineText.slice(cursorVisualColAbsolute + 1);
|
|
212
|
+
const beforeHighlighted = grammar?.length ? applyGrammar(before) : before;
|
|
213
|
+
const afterHighlighted = grammar?.length ? applyGrammar(after) : after;
|
|
214
|
+
|
|
215
|
+
return (
|
|
216
|
+
<Text key={`line-${absoluteVisualIdx}`}>
|
|
217
|
+
{beforeHighlighted}
|
|
218
|
+
{chalk.inverse(cursorChar)}
|
|
219
|
+
{afterHighlighted}
|
|
220
|
+
</Text>
|
|
221
|
+
);
|
|
222
|
+
})}
|
|
223
|
+
</View>
|
|
224
|
+
);
|
|
225
|
+
},
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
Input.displayName = "Input";
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { View, Text, useInput } from "@codellm/jar";
|
|
2
|
+
import { memo, useCallback, useEffect, useMemo, useState } from "react";
|
|
3
|
+
|
|
4
|
+
interface SelectProps {
|
|
5
|
+
items: string[];
|
|
6
|
+
limit?: number;
|
|
7
|
+
maxHeight?: number;
|
|
8
|
+
initialIndex?: number;
|
|
9
|
+
isActive?: boolean;
|
|
10
|
+
showIndex?: boolean;
|
|
11
|
+
showIndicators?: boolean;
|
|
12
|
+
onHighlight?: (item: string, index: number) => void;
|
|
13
|
+
onSubmit?: (item: string, index: number) => void;
|
|
14
|
+
onTab?: (item: string, index: number) => void;
|
|
15
|
+
onCancel?: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const Select = memo(
|
|
19
|
+
({
|
|
20
|
+
items,
|
|
21
|
+
limit = 10,
|
|
22
|
+
maxHeight,
|
|
23
|
+
initialIndex = 0,
|
|
24
|
+
isActive = true,
|
|
25
|
+
showIndex = true,
|
|
26
|
+
showIndicators = false,
|
|
27
|
+
onHighlight,
|
|
28
|
+
onSubmit,
|
|
29
|
+
onTab,
|
|
30
|
+
onCancel,
|
|
31
|
+
}: SelectProps) => {
|
|
32
|
+
const total = items.length;
|
|
33
|
+
const clampedInitial = Math.max(0, Math.min(initialIndex, Math.max(0, total - 1)));
|
|
34
|
+
const [selected, setSelected] = useState(clampedInitial);
|
|
35
|
+
const [start, setStart] = useState(0);
|
|
36
|
+
|
|
37
|
+
const effectiveLimit = useMemo(() => {
|
|
38
|
+
if (maxHeight !== undefined && maxHeight > 0) {
|
|
39
|
+
const indicatorRows = (showIndicators ? 2 : 0) + (showIndex ? 1 : 0);
|
|
40
|
+
return Math.max(1, Math.min(limit, maxHeight - indicatorRows));
|
|
41
|
+
}
|
|
42
|
+
return limit;
|
|
43
|
+
}, [maxHeight, limit, showIndicators, showIndex]);
|
|
44
|
+
|
|
45
|
+
const visibleCount = Math.max(1, Math.min(effectiveLimit, total || effectiveLimit));
|
|
46
|
+
const mid = Math.floor(visibleCount / 2);
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (selected >= total) {
|
|
50
|
+
setSelected(total === 0 ? 0 : total - 1);
|
|
51
|
+
setStart(0);
|
|
52
|
+
}
|
|
53
|
+
}, [total, selected]);
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (typeof onHighlight === "function" && total > 0) {
|
|
57
|
+
onHighlight(items[selected], selected);
|
|
58
|
+
}
|
|
59
|
+
}, [selected, total, items, onHighlight]);
|
|
60
|
+
|
|
61
|
+
const clampStart = useCallback(
|
|
62
|
+
(s: number) => {
|
|
63
|
+
const maxStart = Math.max(0, total - visibleCount);
|
|
64
|
+
return Math.max(0, Math.min(s, maxStart));
|
|
65
|
+
},
|
|
66
|
+
[total, visibleCount],
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const moveUp = useCallback(() => {
|
|
70
|
+
if (total === 0) return;
|
|
71
|
+
const nextSel = (selected - 1 + total) % total;
|
|
72
|
+
setSelected(nextSel);
|
|
73
|
+
if (nextSel < start + mid) setStart(clampStart(nextSel - mid));
|
|
74
|
+
if (nextSel > start + visibleCount - 1) setStart(clampStart(nextSel - visibleCount + 1));
|
|
75
|
+
}, [total, selected, start, mid, visibleCount, clampStart]);
|
|
76
|
+
|
|
77
|
+
const moveDown = useCallback(() => {
|
|
78
|
+
if (total === 0) return;
|
|
79
|
+
const nextSel = (selected + 1) % total;
|
|
80
|
+
setSelected(nextSel);
|
|
81
|
+
if (nextSel > start + mid) setStart(clampStart(nextSel - mid));
|
|
82
|
+
if (nextSel < start) setStart(clampStart(nextSel));
|
|
83
|
+
}, [total, selected, start, mid, clampStart]);
|
|
84
|
+
|
|
85
|
+
useInput(
|
|
86
|
+
(_input, key) => {
|
|
87
|
+
if (!isActive) return;
|
|
88
|
+
if (key.upArrow) {
|
|
89
|
+
moveUp();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (key.downArrow) {
|
|
93
|
+
moveDown();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (key.escape) {
|
|
97
|
+
onCancel?.();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (key.tab && !key.ctrl && !key.meta && !key.shift) {
|
|
101
|
+
if (total > 0) onTab?.(items[selected], selected);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (key.return && !key.ctrl && !key.meta && !key.shift) {
|
|
105
|
+
if (total > 0) onSubmit?.(items[selected], selected);
|
|
106
|
+
else onCancel?.();
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
{ isActive },
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const windowed = useMemo(() => {
|
|
113
|
+
if (total === 0) return [] as string[];
|
|
114
|
+
const end = Math.min(total, start + visibleCount);
|
|
115
|
+
return items.slice(start, end);
|
|
116
|
+
}, [items, total, start, visibleCount]);
|
|
117
|
+
|
|
118
|
+
const hasSpaceForIndicators = maxHeight === undefined || maxHeight >= 3;
|
|
119
|
+
const effectiveShowIndicators = showIndicators && hasSpaceForIndicators;
|
|
120
|
+
const effectiveShowIndex = showIndex && hasSpaceForIndicators;
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<View flexDirection="column">
|
|
124
|
+
{effectiveShowIndicators && total > 0 && start > 0 && (
|
|
125
|
+
<Text dimColor>▲ {effectiveShowIndex && total > 1 && `(${selected + 1}/${total})`}</Text>
|
|
126
|
+
)}
|
|
127
|
+
{total === 0 ? (
|
|
128
|
+
<Text dimColor>No matches</Text>
|
|
129
|
+
) : (
|
|
130
|
+
windowed.map((label, idx) => {
|
|
131
|
+
const absoluteIndex = start + idx;
|
|
132
|
+
const isSelected = absoluteIndex === selected;
|
|
133
|
+
return (
|
|
134
|
+
<Text key={`${label}-${absoluteIndex}`} color={isSelected ? "cyanBright" : undefined}>
|
|
135
|
+
{isSelected ? "> " : " "}
|
|
136
|
+
{label}
|
|
137
|
+
</Text>
|
|
138
|
+
);
|
|
139
|
+
})
|
|
140
|
+
)}
|
|
141
|
+
{effectiveShowIndicators && total > 0 && start + visibleCount < total && (
|
|
142
|
+
<Text dimColor>▼ {effectiveShowIndex && total > 1 && `(${selected + 1}/${total})`}</Text>
|
|
143
|
+
)}
|
|
144
|
+
{!effectiveShowIndicators && effectiveShowIndex && total > 1 && (
|
|
145
|
+
<Text dimColor>{`(${selected + 1}/${total})`}</Text>
|
|
146
|
+
)}
|
|
147
|
+
</View>
|
|
148
|
+
);
|
|
149
|
+
},
|
|
150
|
+
);
|
|
151
|
+
Select.displayName = "Select";
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Text } from "@codellm/jar";
|
|
2
|
+
import { startTransition } from "react";
|
|
3
|
+
import { memo, useCallback, useEffect, useMemo, useState } from "react";
|
|
4
|
+
|
|
5
|
+
interface ShimmerProps {
|
|
6
|
+
text: string;
|
|
7
|
+
color?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const SHIMMER_INTERVAL = 100;
|
|
11
|
+
const DIM_FACTOR = 0.25;
|
|
12
|
+
|
|
13
|
+
export const Shimmer = memo(({ text, color = "#94a3b8" }: ShimmerProps) => {
|
|
14
|
+
const [offset, setOffset] = useState(0);
|
|
15
|
+
const textLength = text.length;
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const interval = setInterval(() => {
|
|
19
|
+
// Lowest priority: animation re-renders must never delay input or streaming.
|
|
20
|
+
startTransition(() => {
|
|
21
|
+
setOffset((prev) => prev + 1);
|
|
22
|
+
});
|
|
23
|
+
}, SHIMMER_INTERVAL);
|
|
24
|
+
|
|
25
|
+
return () => clearInterval(interval);
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
const baseRgb = useMemo(() => parseHexColor(color), [color]);
|
|
29
|
+
|
|
30
|
+
const getCharColor = useCallback(
|
|
31
|
+
(index: number): string => {
|
|
32
|
+
const peakPosition = offset % textLength;
|
|
33
|
+
|
|
34
|
+
let distance = Math.abs(index - peakPosition);
|
|
35
|
+
const wrapDistance = textLength - distance;
|
|
36
|
+
const circularDistance = Math.min(distance, wrapDistance);
|
|
37
|
+
|
|
38
|
+
const gradientWidth = Math.max(textLength * 0.6, 3);
|
|
39
|
+
const brightness = Math.max(0, 1 - circularDistance / gradientWidth);
|
|
40
|
+
|
|
41
|
+
return interpolateColor(baseRgb, brightness);
|
|
42
|
+
},
|
|
43
|
+
[offset, textLength, baseRgb],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Text>
|
|
48
|
+
{text.split("").map((char, index) => (
|
|
49
|
+
<Text key={`${char}-${index}`} color={getCharColor(index)}>
|
|
50
|
+
{char}
|
|
51
|
+
</Text>
|
|
52
|
+
))}
|
|
53
|
+
</Text>
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
Shimmer.displayName = "Shimmer";
|
|
58
|
+
|
|
59
|
+
interface RGB {
|
|
60
|
+
r: number;
|
|
61
|
+
g: number;
|
|
62
|
+
b: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function parseHexColor(hex: string): RGB {
|
|
66
|
+
const cleanHex = hex.replace("#", "");
|
|
67
|
+
return {
|
|
68
|
+
r: parseInt(cleanHex.substring(0, 2), 16),
|
|
69
|
+
g: parseInt(cleanHex.substring(2, 4), 16),
|
|
70
|
+
b: parseInt(cleanHex.substring(4, 6), 16),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function interpolateColor(base: RGB, brightness: number): string {
|
|
75
|
+
const minR = Math.floor(base.r * DIM_FACTOR);
|
|
76
|
+
const minG = Math.floor(base.g * DIM_FACTOR);
|
|
77
|
+
const minB = Math.floor(base.b * DIM_FACTOR);
|
|
78
|
+
|
|
79
|
+
const newR = Math.floor(minR + (base.r - minR) * brightness);
|
|
80
|
+
const newG = Math.floor(minG + (base.g - minG) * brightness);
|
|
81
|
+
const newB = Math.floor(minB + (base.b - minB) * brightness);
|
|
82
|
+
|
|
83
|
+
return `#${newR.toString(16).padStart(2, "0")}${newG.toString(16).padStart(2, "0")}${newB.toString(16).padStart(2, "0")}`;
|
|
84
|
+
}
|