@dyyz1993/create-agent 2.0.1 → 2.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.
Files changed (57) hide show
  1. package/package.json +1 -1
  2. package/src/commands/create.ts +31 -31
  3. package/src/commands/workspace.ts +112 -105
  4. package/src/lib/copy.ts +1 -0
  5. package/templates/agent/electron/main.js +46 -0
  6. package/templates/agent/electron/preload.js +5 -0
  7. package/templates/agent/electron-builder.json +40 -0
  8. package/templates/agent/eslint.config.mjs +2 -0
  9. package/templates/agent/package.json +60 -2
  10. package/templates/agent/src/mainview/App.tsx +29 -26
  11. package/templates/agent/src/mainview/components/chat/ChatPanel.tsx +88 -88
  12. package/templates/agent/src/mainview/components/file-preview/VirtualizedCodeView.tsx +105 -81
  13. package/templates/agent/src/mainview/components/search/SearchPanel.tsx +427 -378
  14. package/templates/agent/src/mainview/components/todo/TodoPanel.tsx +3 -3
  15. package/templates/agent/src/mainview/hooks/use-input-history.ts +70 -61
  16. package/templates/agent/src/mainview/lib/api-client.ts +1 -4
  17. package/templates/agent/src/mainview/main.tsx +4 -10
  18. package/templates/agent/src/mainview/stores/use-feed-store.ts +107 -107
  19. package/templates/agent/src/mainview/utils/drop-handler.ts +114 -115
  20. package/templates/agent/src/server-config.ts +1 -1
  21. package/templates/agent/src/server.ts +1 -2
  22. package/templates/agent/src/shared/handlers/chat.ts +5 -5
  23. package/templates/agent/src/shared/handlers/debug.ts +5 -1
  24. package/templates/agent/src/shared/handlers/git.ts +286 -243
  25. package/templates/agent/src/shared/http-routes.ts +1 -1
  26. package/templates/agent/src/shared/lib/bash-security.ts +43 -43
  27. package/templates/agent/tsconfig.ipc.json +5 -1
  28. package/templates/agent/tsconfig.json +3 -1
  29. package/templates/chat/package.json +3 -0
  30. package/templates/chat/src/mainview/hooks/use-input-history.ts +70 -61
  31. package/templates/chat/src/mainview/lib/api-client.ts +2 -5
  32. package/templates/chat/src/mainview/main.tsx +10 -7
  33. package/templates/chat/src/server-config.ts +1 -1
  34. package/templates/chat/src/server.ts +1 -2
  35. package/templates/chat/src/shared/handlers/chat.ts +5 -5
  36. package/templates/chat/src/shared/handlers/debug.ts +5 -1
  37. package/templates/chat/src/shared/http-routes.ts +1 -1
  38. package/templates/chat/tsconfig.ipc.json +5 -1
  39. package/templates/chat/tsconfig.json +12 -2
  40. package/templates/general/package.json +3 -0
  41. package/templates/general/src/mainview/components/file-preview/VirtualizedCodeView.tsx +101 -81
  42. package/templates/general/src/mainview/components/search/SearchPanel.tsx +429 -378
  43. package/templates/general/src/mainview/hooks/use-input-history.ts +70 -61
  44. package/templates/general/src/mainview/lib/api-client.ts +2 -5
  45. package/templates/general/src/mainview/main.tsx +10 -7
  46. package/templates/general/src/mainview/stores/use-feed-store.ts +107 -107
  47. package/templates/general/src/mainview/utils/drop-handler.ts +114 -115
  48. package/templates/general/src/server-config.ts +1 -1
  49. package/templates/general/src/server.ts +1 -2
  50. package/templates/general/src/shared/handlers/chat.ts +5 -5
  51. package/templates/general/src/shared/handlers/debug.ts +5 -1
  52. package/templates/general/src/shared/handlers/git.ts +286 -243
  53. package/templates/general/src/shared/http-routes.ts +1 -1
  54. package/templates/general/tsconfig.ipc.json +5 -1
  55. package/templates/general/tsconfig.json +12 -2
  56. package/templates/shared/components/ErrorBoundary.tsx +50 -49
  57. package/templates/shared/http-routes.ts +210 -190
@@ -6,97 +6,97 @@ import { useChatStore } from "../../stores/use-chat-store";
6
6
  import { MessageBubble } from "./MessageBubble";
7
7
 
8
8
  export function ChatPanel() {
9
- const { t } = useTranslation();
10
- const messages = useChatStore((s) => s.messages);
11
- const inputText = useChatStore((s) => s.inputText);
12
- const setInputText = useChatStore((s) => s.setInputText);
13
- const sendMessage = useChatStore((s) => s.sendMessage);
14
- const parentRef = useRef<HTMLDivElement>(null);
15
- const prevMessageCountRef = useRef(0);
9
+ const { t } = useTranslation();
10
+ const messages = useChatStore((s) => s.messages);
11
+ const inputText = useChatStore((s) => s.inputText);
12
+ const setInputText = useChatStore((s) => s.setInputText);
13
+ const sendMessage = useChatStore((s) => s.sendMessage);
14
+ const parentRef = useRef<HTMLDivElement>(null);
15
+ const prevMessageCountRef = useRef(0);
16
16
 
17
- const virtualizer = useVirtualizer({
18
- count: messages.length,
19
- getScrollElement: () => parentRef.current,
20
- estimateSize: () => 80,
21
- overscan: 5,
22
- measureElement: (element) => element?.getBoundingClientRect().height ?? 80,
23
- });
17
+ const virtualizer = useVirtualizer({
18
+ count: messages.length,
19
+ getScrollElement: () => parentRef.current,
20
+ estimateSize: () => 80,
21
+ overscan: 5,
22
+ measureElement: (element) => element?.getBoundingClientRect().height ?? 80,
23
+ });
24
24
 
25
- useEffect(() => {
26
- if (messages.length > prevMessageCountRef.current) {
27
- virtualizer.scrollToIndex(messages.length - 1, { align: "end" });
28
- }
29
- prevMessageCountRef.current = messages.length;
30
- }, [messages.length, virtualizer]);
25
+ useEffect(() => {
26
+ if (messages.length > prevMessageCountRef.current) {
27
+ virtualizer.scrollToIndex(messages.length - 1, { align: "end" });
28
+ }
29
+ prevMessageCountRef.current = messages.length;
30
+ }, [messages.length, virtualizer]);
31
31
 
32
- return (
33
- <div className="flex-1 flex flex-col overflow-hidden relative">
34
- <div className="px-4 py-2 bg-[var(--color-bg-secondary)] border-b border-[var(--color-border-primary)] flex items-center justify-between flex-shrink-0">
35
- <h2 className="text-sm font-semibold flex items-center gap-1.5">
36
- <MessageSquare className="w-4 h-4 text-[var(--color-text-accent)]" />
37
- {t("chat.title")}
38
- {messages.length > 0 && (
39
- <span className="ml-1 px-2 py-0.5 bg-[var(--color-accent)]/30 text-[var(--color-text-accent)] rounded text-[10px]">
40
- {messages.length}
41
- </span>
42
- )}
43
- </h2>
44
- </div>
32
+ return (
33
+ <div className="flex-1 flex flex-col overflow-hidden relative">
34
+ <div className="px-4 py-2 bg-[var(--color-bg-secondary)] border-b border-[var(--color-border-primary)] flex items-center justify-between flex-shrink-0">
35
+ <h2 className="text-sm font-semibold flex items-center gap-1.5">
36
+ <MessageSquare className="w-4 h-4 text-[var(--color-text-accent)]" />
37
+ {t("chat.title")}
38
+ {messages.length > 0 && (
39
+ <span className="ml-1 px-2 py-0.5 bg-[var(--color-accent)]/30 text-[var(--color-text-accent)] rounded text-[10px]">
40
+ {messages.length}
41
+ </span>
42
+ )}
43
+ </h2>
44
+ </div>
45
45
 
46
- <div ref={parentRef} className="flex-1 overflow-y-auto">
47
- {messages.length === 0 ? (
48
- <div className="flex items-center justify-center h-full text-[var(--color-text-placeholder)] text-sm">
49
- {t("chat.empty")}
50
- </div>
51
- ) : (
52
- <div
53
- style={{
54
- height: virtualizer.getTotalSize(),
55
- width: "100%",
56
- position: "relative",
57
- }}
58
- >
59
- {virtualizer.getVirtualItems().map((virtualItem) => {
60
- const msg = messages[virtualItem.index];
61
- return (
62
- <div
63
- key={msg.id}
64
- data-index={virtualItem.index}
65
- ref={virtualizer.measureElement}
66
- style={{
67
- position: "absolute",
68
- top: 0,
69
- left: 0,
70
- width: "100%",
71
- transform: `translateY(${virtualItem.start}px)`,
72
- padding: "6px 16px",
73
- }}
74
- >
75
- <MessageBubble message={msg} />
76
- </div>
77
- );
78
- })}
79
- </div>
80
- )}
81
- </div>
46
+ <div ref={parentRef} className="flex-1 overflow-y-auto">
47
+ {messages.length === 0 ? (
48
+ <div className="flex items-center justify-center h-full text-[var(--color-text-placeholder)] text-sm">
49
+ {t("chat.empty")}
50
+ </div>
51
+ ) : (
52
+ <div
53
+ style={{
54
+ height: virtualizer.getTotalSize(),
55
+ width: "100%",
56
+ position: "relative",
57
+ }}
58
+ >
59
+ {virtualizer.getVirtualItems().map((virtualItem) => {
60
+ const msg = messages[virtualItem.index]!;
61
+ return (
62
+ <div
63
+ key={msg.id}
64
+ data-index={virtualItem.index}
65
+ ref={virtualizer.measureElement}
66
+ style={{
67
+ position: "absolute",
68
+ top: 0,
69
+ left: 0,
70
+ width: "100%",
71
+ transform: `translateY(${virtualItem.start}px)`,
72
+ padding: "6px 16px",
73
+ }}
74
+ >
75
+ <MessageBubble message={msg} />
76
+ </div>
77
+ );
78
+ })}
79
+ </div>
80
+ )}
81
+ </div>
82
82
 
83
- <div className="px-4 py-3 bg-[var(--color-bg-secondary)] border-t border-[var(--color-border-primary)] flex gap-2 flex-shrink-0">
84
- <input
85
- type="text"
86
- value={inputText}
87
- onChange={(e) => setInputText(e.target.value)}
88
- onKeyDown={(e) => e.key === "Enter" && !e.shiftKey && sendMessage()}
89
- placeholder={t("chat.placeholder")}
90
- className="flex-1 px-3 py-2 text-sm bg-[var(--color-bg-tertiary)] rounded-lg text-[var(--color-text-primary)] border border-[var(--color-border-secondary)] focus:border-[var(--color-accent)] focus:outline-none"
91
- />
92
- <button
93
- onClick={sendMessage}
94
- className="px-4 py-2 text-sm bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] rounded-lg transition-colors flex items-center gap-1.5"
95
- >
96
- <Send className="w-4 h-4" />
97
- {t("chat.send")}
98
- </button>
99
- </div>
100
- </div>
101
- );
83
+ <div className="px-4 py-3 bg-[var(--color-bg-secondary)] border-t border-[var(--color-border-primary)] flex gap-2 flex-shrink-0">
84
+ <input
85
+ type="text"
86
+ value={inputText}
87
+ onChange={(e) => setInputText(e.target.value)}
88
+ onKeyDown={(e) => e.key === "Enter" && !e.shiftKey && sendMessage()}
89
+ placeholder={t("chat.placeholder")}
90
+ className="flex-1 px-3 py-2 text-sm bg-[var(--color-bg-tertiary)] rounded-lg text-[var(--color-text-primary)] border border-[var(--color-border-secondary)] focus:border-[var(--color-accent)] focus:outline-none"
91
+ />
92
+ <button
93
+ onClick={sendMessage}
94
+ className="px-4 py-2 text-sm bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] rounded-lg transition-colors flex items-center gap-1.5"
95
+ >
96
+ <Send className="w-4 h-4" />
97
+ {t("chat.send")}
98
+ </button>
99
+ </div>
100
+ </div>
101
+ );
102
102
  }
@@ -4,96 +4,120 @@ import { Highlight, themes } from "prism-react-renderer";
4
4
  import { getLanguage } from "../../utils/file-utils";
5
5
 
6
6
  interface VirtualizedCodeViewProps {
7
- code: string;
8
- filename: string;
7
+ code: string;
8
+ filename: string;
9
9
  }
10
10
 
11
11
  /** Lines longer than this skip syntax highlighting (plain text instead) */
12
12
  const LONG_LINE_THRESHOLD = 5000;
13
13
 
14
14
  export function VirtualizedCodeView({ code, filename }: VirtualizedCodeViewProps) {
15
- const parentRef = useRef<HTMLDivElement>(null);
16
- const language = getLanguage(filename);
17
- const lines = useMemo(() => code.split("\n"), [code]);
15
+ const parentRef = useRef<HTMLDivElement>(null);
16
+ const language = getLanguage(filename);
17
+ const lines = useMemo(() => code.split("\n"), [code]);
18
18
 
19
- // Detect minified files: avg line length > 500 chars
20
- const avgLineLength = code.length / Math.max(lines.length, 1);
21
- const usePlainText = !language || avgLineLength > 500;
19
+ // Detect minified files: avg line length > 500 chars
20
+ const avgLineLength = code.length / Math.max(lines.length, 1);
21
+ const usePlainText = !language || avgLineLength > 500;
22
22
 
23
- const virtualizer = useVirtualizer({
24
- count: lines.length,
25
- getScrollElement: () => parentRef.current,
26
- estimateSize: () => 20,
27
- overscan: 20,
28
- });
23
+ const virtualizer = useVirtualizer({
24
+ count: lines.length,
25
+ getScrollElement: () => parentRef.current,
26
+ estimateSize: () => 20,
27
+ overscan: 20,
28
+ });
29
29
 
30
- // --- Plain text path: no Prism tokenization ---
31
- if (usePlainText) {
32
- return (
33
- <div ref={parentRef} className="flex-1 min-h-0 overflow-auto" style={{ background: "#011627" }}>
34
- <div
35
- style={{ height: `${virtualizer.getTotalSize()}px`, width: "100%", position: "relative" }}
36
- >
37
- {virtualizer.getVirtualItems().map((vr) => (
38
- <div
39
- key={vr.key}
40
- style={{
41
- position: "absolute", top: 0, left: 0, width: "100%",
42
- height: `${vr.size}px`, transform: `translateY(${vr.start}px)`,
43
- }}
44
- className="flex text-xs leading-5 font-mono"
45
- >
46
- <span className="inline-block w-10 text-right pr-4 text-gray-600 select-none shrink-0">
47
- {vr.index + 1}
48
- </span>
49
- <span className="flex-1 text-[var(--color-text-secondary)] whitespace-pre">{lines[vr.index]}</span>
50
- </div>
51
- ))}
52
- </div>
53
- </div>
54
- );
55
- }
30
+ // --- Plain text path: no Prism tokenization ---
31
+ if (usePlainText) {
32
+ return (
33
+ <div
34
+ ref={parentRef}
35
+ className="flex-1 min-h-0 overflow-auto"
36
+ style={{ background: "#011627" }}
37
+ >
38
+ <div
39
+ style={{ height: `${virtualizer.getTotalSize()}px`, width: "100%", position: "relative" }}
40
+ >
41
+ {virtualizer.getVirtualItems().map((vr) => (
42
+ <div
43
+ key={vr.key}
44
+ style={{
45
+ position: "absolute",
46
+ top: 0,
47
+ left: 0,
48
+ width: "100%",
49
+ height: `${vr.size}px`,
50
+ transform: `translateY(${vr.start}px)`,
51
+ }}
52
+ className="flex text-xs leading-5 font-mono"
53
+ >
54
+ <span className="inline-block w-10 text-right pr-4 text-gray-600 select-none shrink-0">
55
+ {vr.index + 1}
56
+ </span>
57
+ <span className="flex-1 text-[var(--color-text-secondary)] whitespace-pre">
58
+ {lines[vr.index]}
59
+ </span>
60
+ </div>
61
+ ))}
62
+ </div>
63
+ </div>
64
+ );
65
+ }
56
66
 
57
- // --- Highlighted path: tokenize ONCE for the whole file, virtualize rendering ---
58
- return (
59
- <Highlight theme={themes.nightOwl} code={code} language={language}>
60
- {({ tokens, getTokenProps }) => (
61
- <div ref={parentRef} className="flex-1 min-h-0 overflow-auto" style={{ background: "#011627" }}>
62
- <div
63
- style={{ height: `${virtualizer.getTotalSize()}px`, width: "100%", position: "relative" }}
64
- >
65
- {virtualizer.getVirtualItems().map((vr) => {
66
- const lineTokens = tokens[vr.index];
67
- const lineText = lines[vr.index];
68
- const isLongLine = (lineText?.length ?? 0) > LONG_LINE_THRESHOLD;
67
+ // --- Highlighted path: tokenize ONCE for the whole file, virtualize rendering ---
68
+ return (
69
+ <Highlight theme={themes.nightOwl} code={code} language={language}>
70
+ {({ tokens, getTokenProps }) => (
71
+ <div
72
+ ref={parentRef}
73
+ className="flex-1 min-h-0 overflow-auto"
74
+ style={{ background: "#011627" }}
75
+ >
76
+ <div
77
+ style={{
78
+ height: `${virtualizer.getTotalSize()}px`,
79
+ width: "100%",
80
+ position: "relative",
81
+ }}
82
+ >
83
+ {virtualizer.getVirtualItems().map((vr) => {
84
+ const lineTokens = tokens[vr.index];
85
+ const lineText = lines[vr.index];
86
+ const isLongLine = (lineText?.length ?? 0) > LONG_LINE_THRESHOLD;
69
87
 
70
- return (
71
- <div
72
- key={vr.key}
73
- style={{
74
- position: "absolute", top: 0, left: 0, width: "100%",
75
- height: `${vr.size}px`, transform: `translateY(${vr.start}px)`,
76
- }}
77
- className="flex text-xs leading-5 font-mono"
78
- >
79
- <span className="inline-block w-10 text-right pr-4 text-gray-600 select-none shrink-0">
80
- {vr.index + 1}
81
- </span>
82
- {isLongLine ? (
83
- <span className="flex-1 text-[var(--color-text-secondary)] whitespace-pre">{lineText}</span>
84
- ) : (
85
- <span className="flex-1">
86
- {lineTokens.map((token, key) => (
87
- <span key={key} {...getTokenProps({ token })} />
88
- ))}
89
- </span>
90
- )}
91
- </div>
92
- );
93
- })}
94
- </div>
95
- </div>
96
- )}
97
- </Highlight>
98
- );
88
+ return (
89
+ <div
90
+ key={vr.key}
91
+ style={{
92
+ position: "absolute",
93
+ top: 0,
94
+ left: 0,
95
+ width: "100%",
96
+ height: `${vr.size}px`,
97
+ transform: `translateY(${vr.start}px)`,
98
+ }}
99
+ className="flex text-xs leading-5 font-mono"
100
+ >
101
+ <span className="inline-block w-10 text-right pr-4 text-gray-600 select-none shrink-0">
102
+ {vr.index + 1}
103
+ </span>
104
+ {isLongLine ? (
105
+ <span className="flex-1 text-[var(--color-text-secondary)] whitespace-pre">
106
+ {lineText}
107
+ </span>
108
+ ) : (
109
+ <span className="flex-1">
110
+ {lineTokens!.map((token, key) => (
111
+ <span key={key} {...getTokenProps({ token })} />
112
+ ))}
113
+ </span>
114
+ )}
115
+ </div>
116
+ );
117
+ })}
118
+ </div>
119
+ </div>
120
+ )}
121
+ </Highlight>
122
+ );
99
123
  }