@ridit/lens 0.3.7 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/index.mjs +105368 -274002
  2. package/package.json +13 -19
  3. package/src/colors.ts +15 -15
  4. package/src/commands/chat.tsx +32 -23
  5. package/src/commands/provider.tsx +11 -238
  6. package/src/commands/repo.tsx +66 -120
  7. package/src/commands/timeline.tsx +11 -22
  8. package/src/components/ChatView.tsx +238 -0
  9. package/src/components/Message.tsx +46 -0
  10. package/src/components/ToolCall.tsx +67 -0
  11. package/src/components/chat/ChatView.tsx +550 -0
  12. package/src/components/chat/Message.tsx +152 -0
  13. package/src/components/chat/StatusBar.tsx +214 -0
  14. package/src/components/chat/TextArea.tsx +173 -176
  15. package/src/components/provider/ApiKeyStep.tsx +207 -199
  16. package/src/components/provider/ModelStep.tsx +90 -88
  17. package/src/components/provider/ProviderSetup.tsx +331 -0
  18. package/src/components/provider/ProviderTypeStep.tsx +53 -61
  19. package/src/components/repo/StepRow.tsx +68 -69
  20. package/src/components/timeline/TimelineView.tsx +840 -0
  21. package/src/components/toolcall-utils.ts +103 -0
  22. package/src/components/watch/RunView.tsx +497 -0
  23. package/src/hooks/useChatInput.ts +49 -0
  24. package/src/hooks/useCommandHandler.ts +117 -0
  25. package/src/index.tsx +386 -139
  26. package/src/utils/git.ts +149 -155
  27. package/src/utils/repo.ts +62 -69
  28. package/src/utils/thinking.tsx +64 -0
  29. package/src/utils/watch.ts +165 -307
  30. package/tests/message.test.ts +38 -0
  31. package/tests/toolcall-utils.test.ts +111 -0
  32. package/tsconfig.json +8 -24
  33. package/CLAUDE.md +0 -50
  34. package/LENS.md +0 -48
  35. package/LICENSE +0 -21
  36. package/README.md +0 -93
  37. package/addons/README.md +0 -55
  38. package/addons/clean-cache.js +0 -48
  39. package/addons/generate-readme.js +0 -67
  40. package/addons/git-stats.js +0 -29
  41. package/addons/run-tests.js +0 -127
  42. package/src/commands/commit.tsx +0 -668
  43. package/src/commands/review.tsx +0 -294
  44. package/src/commands/run.tsx +0 -56
  45. package/src/commands/task.tsx +0 -36
  46. package/src/components/chat/ChatMessage.tsx +0 -195
  47. package/src/components/chat/ChatOverlays.tsx +0 -399
  48. package/src/components/chat/ChatRunner.tsx +0 -517
  49. package/src/components/chat/hooks/useChat.ts +0 -631
  50. package/src/components/chat/hooks/useChatInput.ts +0 -79
  51. package/src/components/chat/hooks/useCommandHandlers.ts +0 -327
  52. package/src/components/provider/ProviderPicker.tsx +0 -76
  53. package/src/components/provider/RemoveProviderStep.tsx +0 -82
  54. package/src/components/repo/DiffViewer.tsx +0 -175
  55. package/src/components/repo/FileReviewer.tsx +0 -70
  56. package/src/components/repo/FileViewer.tsx +0 -60
  57. package/src/components/repo/IssueFixer.tsx +0 -666
  58. package/src/components/repo/LensFileMenu.tsx +0 -115
  59. package/src/components/repo/NoProviderPrompt.tsx +0 -28
  60. package/src/components/repo/PreviewRunner.tsx +0 -217
  61. package/src/components/repo/RepoAnalysis.tsx +0 -534
  62. package/src/components/task/TaskRunner.tsx +0 -396
  63. package/src/components/timeline/CommitDetail.tsx +0 -272
  64. package/src/components/timeline/CommitList.tsx +0 -162
  65. package/src/components/timeline/TimelineChat.tsx +0 -166
  66. package/src/components/timeline/TimelineRunner.tsx +0 -1285
  67. package/src/components/watch/RunRunner.tsx +0 -929
  68. package/src/prompts/fewshot.ts +0 -252
  69. package/src/prompts/index.ts +0 -2
  70. package/src/prompts/system.ts +0 -285
  71. package/src/tools/chart.ts +0 -202
  72. package/src/tools/convert-image.ts +0 -312
  73. package/src/tools/files.ts +0 -253
  74. package/src/tools/git.ts +0 -603
  75. package/src/tools/index.ts +0 -17
  76. package/src/tools/pdf.ts +0 -164
  77. package/src/tools/shell.ts +0 -96
  78. package/src/tools/view-image.ts +0 -335
  79. package/src/tools/web.ts +0 -212
  80. package/src/types/chat.ts +0 -86
  81. package/src/types/config.ts +0 -20
  82. package/src/types/repo.ts +0 -54
  83. package/src/utils/addons/loadAddons.ts +0 -34
  84. package/src/utils/ai.ts +0 -321
  85. package/src/utils/chat.ts +0 -326
  86. package/src/utils/chatHistory.ts +0 -121
  87. package/src/utils/config.ts +0 -61
  88. package/src/utils/files.ts +0 -105
  89. package/src/utils/intentClassifier.ts +0 -58
  90. package/src/utils/lensfile.ts +0 -142
  91. package/src/utils/llm.ts +0 -81
  92. package/src/utils/memory.ts +0 -209
  93. package/src/utils/preview.ts +0 -119
  94. package/src/utils/stats.ts +0 -174
  95. package/src/utils/tools/builtins.ts +0 -377
  96. package/src/utils/tools/registry.ts +0 -105
@@ -0,0 +1,214 @@
1
+ import React, { useState, useEffect } from "react";
2
+ import { Box, Text, useStdout } from "ink";
3
+ import Spinner from "ink-spinner";
4
+ import { resolve } from "path";
5
+ import { homedir } from "os";
6
+ import { TextArea } from "./TextArea";
7
+ import { ACCENT, GREEN, RED } from "../../colors";
8
+
9
+ export function AppHeader({
10
+ model,
11
+ repoPath,
12
+ }: {
13
+ model: string;
14
+ repoPath: string;
15
+ }) {
16
+ const cols = process.stdout.columns ?? 80;
17
+ const rule = "─".repeat(Math.max(1, cols));
18
+ const abs = resolve(repoPath);
19
+ const displayPath = abs.startsWith(homedir())
20
+ ? "~" + abs.slice(homedir().length)
21
+ : abs;
22
+
23
+ return (
24
+ <Box flexDirection="column" marginBottom={1}>
25
+ <Box gap={2}>
26
+ <Text color={ACCENT} bold>
27
+ ◆ lens
28
+ </Text>
29
+ <Text color="gray" dimColor>
30
+ ·
31
+ </Text>
32
+ <Text color="white" dimColor>
33
+ {model}
34
+ </Text>
35
+ <Text color="gray" dimColor>
36
+ ·
37
+ </Text>
38
+ <Text color="gray" dimColor>
39
+ {displayPath}
40
+ </Text>
41
+ </Box>
42
+ <Text color="gray" dimColor>
43
+ {rule}
44
+ </Text>
45
+ </Box>
46
+ );
47
+ }
48
+
49
+ export function InputBox({
50
+ value,
51
+ onChange,
52
+ onSubmit,
53
+ inputKey,
54
+ }: {
55
+ value: string;
56
+ onChange: (v: string) => void;
57
+ onSubmit: (v: string) => void;
58
+ inputKey?: number;
59
+ }) {
60
+ const { stdout } = useStdout();
61
+ const [cols, setCols] = useState(stdout?.columns ?? 80);
62
+
63
+ useEffect(() => {
64
+ const handler = () => setCols(stdout?.columns ?? 80);
65
+ stdout?.on("resize", handler);
66
+ return () => {
67
+ stdout?.off("resize", handler);
68
+ };
69
+ }, [stdout]);
70
+
71
+ const rule = "─".repeat(Math.max(1, cols));
72
+
73
+ return (
74
+ <Box flexDirection="column" marginTop={1}>
75
+ <Text color="gray" dimColor>
76
+ {rule}
77
+ </Text>
78
+ <Box gap={1}>
79
+ <Text color={ACCENT}>{">"}</Text>
80
+ <TextArea
81
+ key={inputKey}
82
+ value={value}
83
+ onChange={onChange}
84
+ onSubmit={onSubmit}
85
+ placeholder="ask anything..."
86
+ />
87
+ </Box>
88
+ <Text color="gray" dimColor>
89
+ {rule}
90
+ </Text>
91
+ </Box>
92
+ );
93
+ }
94
+
95
+ // ── Shortcut bar ──────────────────────────────────────────────────────────────
96
+
97
+ const SHORTCUTS = [
98
+ ["↵", "send"],
99
+ ["^↵", "line"],
100
+ ["^⌫", " word"],
101
+ ["^f", "force"],
102
+ ["^c", "exit"],
103
+ ] as const;
104
+
105
+ export function ShortcutBar({
106
+ autoApprove,
107
+ forceApprove,
108
+ isThinking = false,
109
+ model,
110
+ }: {
111
+ autoApprove?: boolean;
112
+ forceApprove?: boolean;
113
+ isThinking?: boolean;
114
+ model?: string;
115
+ }) {
116
+ const [elapsed, setElapsed] = useState(0);
117
+
118
+ useEffect(() => {
119
+ if (!isThinking) {
120
+ setElapsed(0);
121
+ return;
122
+ }
123
+ setElapsed(0);
124
+ const id = setInterval(() => setElapsed((s) => s + 1), 1000);
125
+ return () => clearInterval(id);
126
+ }, [isThinking]);
127
+
128
+ if (isThinking) {
129
+ return (
130
+ <Box marginTop={0} gap={1}>
131
+ <Text color={ACCENT}>
132
+ <Spinner type="dots" />
133
+ </Text>
134
+ {model && <Text color="gray">{model}</Text>}
135
+ <Text color="gray" dimColor>
136
+ ({elapsed}s · esc cancel)
137
+ </Text>
138
+ </Box>
139
+ );
140
+ }
141
+
142
+ return (
143
+ <Box marginTop={0} justifyContent="space-between">
144
+ <Box>
145
+ {forceApprove ? (
146
+ <>
147
+ <Text color="gray" dimColor>
148
+ {" "}
149
+ ·{" "}
150
+ </Text>
151
+ <Text color={RED} bold>
152
+ force-all
153
+ </Text>
154
+ </>
155
+ ) : autoApprove ? (
156
+ <>
157
+ <Text color="gray" dimColor>
158
+ {" "}
159
+ ·{" "}
160
+ </Text>
161
+ <Text color={GREEN}>auto</Text>
162
+ </>
163
+ ) : null}
164
+ {model && (
165
+ <>
166
+ <Text color={ACCENT}> ● </Text>
167
+ <Text color="gray">{model}</Text>
168
+ </>
169
+ )}
170
+ </Box>
171
+
172
+ <Box>
173
+ {SHORTCUTS.map(([key, desc], i) => (
174
+ <Box key={i}>
175
+ {i > 0 && <Text color="gray"> · </Text>}
176
+ <Text color="gray">{key}</Text>
177
+ <Text color="gray"> {desc}</Text>
178
+ </Box>
179
+ ))}
180
+ </Box>
181
+ </Box>
182
+ );
183
+ }
184
+
185
+ // ── Typewriter text ───────────────────────────────────────────────────────────
186
+
187
+ export function TypewriterText({
188
+ text,
189
+ color = ACCENT,
190
+ speed = 38,
191
+ }: {
192
+ text: string;
193
+ color?: string;
194
+ speed?: number;
195
+ }) {
196
+ const [displayed, setDisplayed] = React.useState("");
197
+ const [target, setTarget] = React.useState(text);
198
+
199
+ React.useEffect(() => {
200
+ setDisplayed("");
201
+ setTarget(text);
202
+ }, [text]);
203
+
204
+ React.useEffect(() => {
205
+ if (displayed.length >= target.length) return;
206
+ const t = setTimeout(
207
+ () => setDisplayed(target.slice(0, displayed.length + 1)),
208
+ speed,
209
+ );
210
+ return () => clearTimeout(t);
211
+ }, [displayed, target, speed]);
212
+
213
+ return <Text color={color}>{displayed}</Text>;
214
+ }
@@ -1,176 +1,173 @@
1
- import React, { useState, useEffect } from "react";
2
- import { Text, useInput } from "ink";
3
- import chalk from "chalk";
4
-
5
- function isWordChar(ch: string): boolean {
6
- return /[\w]/.test(ch);
7
- }
8
-
9
- function wordBoundaryLeft(text: string, pos: number): number {
10
- if (pos <= 0) return 0;
11
- let i = pos - 1;
12
-
13
- while (i > 0 && !isWordChar(text[i]!)) i--;
14
-
15
- while (i > 0 && isWordChar(text[i - 1]!)) i--;
16
- return i;
17
- }
18
-
19
- function wordBoundaryRight(text: string, pos: number): number {
20
- const len = text.length;
21
- if (pos >= len) return len;
22
- let i = pos;
23
-
24
- while (i < len && isWordChar(text[i]!)) i++;
25
-
26
- while (i < len && !isWordChar(text[i]!)) i++;
27
- return i;
28
- }
29
-
30
- export interface TextAreaProps {
31
- value: string;
32
- onChange: (value: string) => void;
33
- onSubmit: (value: string) => void;
34
- focus?: boolean;
35
- placeholder?: string;
36
- }
37
-
38
- export function TextArea({
39
- value,
40
- onChange,
41
- onSubmit,
42
- focus = true,
43
- placeholder = "",
44
- }: TextAreaProps) {
45
- const [cursor, setCursor] = useState(value.length);
46
- const [prevValue, setPrevValue] = useState(value);
47
-
48
- if (value !== prevValue) {
49
- setPrevValue(value);
50
- const lenDiff = Math.abs(value.length - prevValue.length);
51
- if (cursor > value.length || lenDiff > 1) {
52
- setCursor(value.length);
53
- }
54
- }
55
-
56
- useInput(
57
- (input, key) => {
58
- if (key.upArrow || key.downArrow) return;
59
- if (key.tab || (key.shift && key.tab)) return;
60
- if (key.ctrl && input === "c") return;
61
-
62
- if (key.return && !key.meta) {
63
- onSubmit(value);
64
- return;
65
- }
66
-
67
- if ((key.return && key.meta) || (key.ctrl && input === "j")) {
68
- const next = value.slice(0, cursor) + "\n" + value.slice(cursor);
69
- onChange(next);
70
- setCursor((c) => c + 1);
71
- return;
72
- }
73
-
74
- if (key.leftArrow && key.ctrl) {
75
- setCursor(wordBoundaryLeft(value, cursor));
76
- return;
77
- }
78
-
79
- if (key.rightArrow && key.ctrl) {
80
- setCursor(wordBoundaryRight(value, cursor));
81
- return;
82
- }
83
-
84
- if (key.leftArrow) {
85
- setCursor((c) => Math.max(0, c - 1));
86
- return;
87
- }
88
-
89
- if (key.rightArrow) {
90
- setCursor((c) => Math.min(value.length, c + 1));
91
- return;
92
- }
93
-
94
- if (key.ctrl && input === "a") {
95
- const lineStart = value.lastIndexOf("\n", cursor - 1) + 1;
96
- setCursor(lineStart);
97
- return;
98
- }
99
-
100
- if (key.ctrl && input === "e") {
101
- const lineEnd = value.indexOf("\n", cursor);
102
- setCursor(lineEnd === -1 ? value.length : lineEnd);
103
- return;
104
- }
105
-
106
- if (key.ctrl && input === "u") {
107
- const lineStart = value.lastIndexOf("\n", cursor - 1) + 1;
108
- onChange(value.slice(0, lineStart) + value.slice(cursor));
109
- setCursor(lineStart);
110
- return;
111
- }
112
-
113
- if (key.ctrl && input === "k") {
114
- const lineEnd = value.indexOf("\n", cursor);
115
- onChange(
116
- value.slice(0, cursor) + (lineEnd === -1 ? "" : value.slice(lineEnd)),
117
- );
118
- return;
119
- }
120
-
121
- if (key.ctrl && input === "w") {
122
- const to = wordBoundaryLeft(value, cursor);
123
- onChange(value.slice(0, to) + value.slice(cursor));
124
- setCursor(to);
125
- return;
126
- }
127
-
128
- if (key.ctrl && key.delete) {
129
- const to = wordBoundaryRight(value, cursor);
130
- onChange(value.slice(0, cursor) + value.slice(to));
131
- return;
132
- }
133
-
134
- if (key.backspace || key.delete) {
135
- if (cursor > 0) {
136
- onChange(value.slice(0, cursor - 1) + value.slice(cursor));
137
- setCursor((c) => c - 1);
138
- }
139
- return;
140
- }
141
-
142
- if (key.escape) return;
143
-
144
- if (input) {
145
- const next = value.slice(0, cursor) + input + value.slice(cursor);
146
- onChange(next);
147
- setCursor((c) => c + input.length);
148
- }
149
- },
150
- { isActive: focus },
151
- );
152
-
153
- if (value.length === 0 && placeholder) {
154
- return (
155
- <Text>
156
- {chalk.inverse(placeholder[0] ?? " ")}
157
- {placeholder.length > 1 ? chalk.gray(placeholder.slice(1)) : ""}
158
- </Text>
159
- );
160
- }
161
-
162
- let rendered = "";
163
- for (let i = 0; i < value.length; i++) {
164
- const ch = value[i]!;
165
- if (i === cursor) {
166
- rendered += ch === "\n" ? chalk.inverse(" ") + "\n" : chalk.inverse(ch);
167
- } else {
168
- rendered += ch;
169
- }
170
- }
171
- if (cursor === value.length) {
172
- rendered += chalk.inverse(" ");
173
- }
174
-
175
- return <Text>{rendered}</Text>;
176
- }
1
+ import React, { useState } from "react";
2
+ import { Text, useInput } from "ink";
3
+ import chalk from "chalk";
4
+
5
+ function isWordChar(ch: string): boolean {
6
+ return /[\w]/.test(ch);
7
+ }
8
+
9
+ function wordBoundaryLeft(text: string, pos: number): number {
10
+ if (pos <= 0) return 0;
11
+ let i = pos - 1;
12
+ while (i > 0 && !isWordChar(text[i]!)) i--;
13
+ while (i > 0 && isWordChar(text[i - 1]!)) i--;
14
+ return i;
15
+ }
16
+
17
+ function wordBoundaryRight(text: string, pos: number): number {
18
+ const len = text.length;
19
+ if (pos >= len) return len;
20
+ let i = pos;
21
+ while (i < len && isWordChar(text[i]!)) i++;
22
+ while (i < len && !isWordChar(text[i]!)) i++;
23
+ return i;
24
+ }
25
+
26
+ export interface TextAreaProps {
27
+ value: string;
28
+ onChange: (value: string) => void;
29
+ onSubmit: (value: string) => void;
30
+ focus?: boolean;
31
+ placeholder?: string;
32
+ }
33
+
34
+ export function TextArea({
35
+ value,
36
+ onChange,
37
+ onSubmit,
38
+ focus = true,
39
+ placeholder = "",
40
+ }: TextAreaProps) {
41
+ const [cursor, setCursor] = useState(value.length);
42
+ const [prevValue, setPrevValue] = useState(value);
43
+
44
+ if (value !== prevValue) {
45
+ setPrevValue(value);
46
+ const lenDiff = Math.abs(value.length - prevValue.length);
47
+ if (cursor > value.length || lenDiff > 1) {
48
+ setCursor(value.length);
49
+ }
50
+ }
51
+
52
+ useInput(
53
+ (input, key) => {
54
+ if (key.upArrow || key.downArrow) return;
55
+ if (key.tab || (key.shift && key.tab)) return;
56
+ if (key.ctrl && input === "c") return;
57
+
58
+ const isShiftEnter =
59
+ (key.return && key.shift) ||
60
+ input === "\x1b[27;2;13~" ||
61
+ input === "\x1b[13;2u";
62
+
63
+ if (key.return && !key.meta && !key.shift && !isShiftEnter) {
64
+ onSubmit(value);
65
+ return;
66
+ }
67
+
68
+ if (isShiftEnter) {
69
+ const next = value.slice(0, cursor) + "\n" + value.slice(cursor);
70
+ onChange(next);
71
+ setCursor((c) => c + 1);
72
+ return;
73
+ }
74
+
75
+ if (key.leftArrow && key.ctrl) {
76
+ setCursor(wordBoundaryLeft(value, cursor));
77
+ return;
78
+ }
79
+
80
+ if (key.rightArrow && key.ctrl) {
81
+ setCursor(wordBoundaryRight(value, cursor));
82
+ return;
83
+ }
84
+
85
+ if (key.leftArrow) {
86
+ setCursor((c) => Math.max(0, c - 1));
87
+ return;
88
+ }
89
+
90
+ if (key.rightArrow) {
91
+ setCursor((c) => Math.min(value.length, c + 1));
92
+ return;
93
+ }
94
+
95
+ if (key.ctrl && input === "a") {
96
+ const lineStart = value.lastIndexOf("\n", cursor - 1) + 1;
97
+ setCursor(lineStart);
98
+ return;
99
+ }
100
+
101
+ if (key.ctrl && input === "e") {
102
+ const lineEnd = value.indexOf("\n", cursor);
103
+ setCursor(lineEnd === -1 ? value.length : lineEnd);
104
+ return;
105
+ }
106
+
107
+ if (key.ctrl && input === "u") {
108
+ const lineStart = value.lastIndexOf("\n", cursor - 1) + 1;
109
+ onChange(value.slice(0, lineStart) + value.slice(cursor));
110
+ setCursor(lineStart);
111
+ return;
112
+ }
113
+
114
+ if (key.ctrl && input === "k") {
115
+ const lineEnd = value.indexOf("\n", cursor);
116
+ onChange(
117
+ value.slice(0, cursor) + (lineEnd === -1 ? "" : value.slice(lineEnd)),
118
+ );
119
+ return;
120
+ }
121
+
122
+ if (key.ctrl && input === "f") return;
123
+
124
+ if ((key.ctrl && key.delete) || input === "\x1b[3;5~") {
125
+ const to = wordBoundaryLeft(value, cursor);
126
+ onChange(value.slice(0, to) + value.slice(cursor));
127
+ setCursor(to);
128
+ return;
129
+ }
130
+
131
+ if (key.backspace || key.delete) {
132
+ if (cursor > 0) {
133
+ onChange(value.slice(0, cursor - 1) + value.slice(cursor));
134
+ setCursor((c) => c - 1);
135
+ }
136
+ return;
137
+ }
138
+
139
+ if (key.escape) return;
140
+
141
+ if (input) {
142
+ const next = value.slice(0, cursor) + input + value.slice(cursor);
143
+ onChange(next);
144
+ setCursor((c) => c + input.length);
145
+ }
146
+ },
147
+ { isActive: focus },
148
+ );
149
+
150
+ if (value.length === 0 && placeholder) {
151
+ return (
152
+ <Text>
153
+ {chalk.inverse(placeholder[0] ?? " ")}
154
+ {placeholder.length > 1 ? chalk.gray(placeholder.slice(1)) : ""}
155
+ </Text>
156
+ );
157
+ }
158
+
159
+ let rendered = "";
160
+ for (let i = 0; i < value.length; i++) {
161
+ const ch = value[i]!;
162
+ if (i === cursor) {
163
+ rendered += ch === "\n" ? chalk.inverse(" ") + "\n" : chalk.inverse(ch);
164
+ } else {
165
+ rendered += ch;
166
+ }
167
+ }
168
+ if (cursor === value.length) {
169
+ rendered += chalk.inverse(" ");
170
+ }
171
+
172
+ return <Text>{rendered}</Text>;
173
+ }