Add Terminal to System Settings

This commit is contained in:
Alex Gleason committed 2025-11-23 11:02:07 -06:00
1 parent 4f73d99f64
commit 199043e4bc
14 files changed
+43 -26

No files matched your search

+1 -1
View File
@@ -172,7 +172,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
nostr_read_nips_index: new NostrReadNipsIndexTool(),
nostr_generate_kind: new NostrGenerateKindTool(),
nostr_publish_events: new NostrPublishEventsTool(),
shell: new ShellTool(fs, cwd, git, projectsPath, config.corsProxy, user?.signer),
shell: new ShellTool(fs, cwd, git, config.corsProxy, user?.signer),
read_console_messages: new ReadConsoleMessagesTool(),
skill: new SkillTool(fs, pluginsPath),
};
+2 -2
View File
@@ -793,7 +793,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
</h3>
</div>
<div className="flex-1 min-h-0">
<TerminalComponent projectId={projectId} />
<TerminalComponent cwd={`${projectsPath}/${projectId}`} />
</div>
</>
) : (
@@ -887,7 +887,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
<div className="flex-1 flex min-h-0">
{desktopCodeView === 'terminal' ? (
<div className="flex-1">
<TerminalComponent projectId={projectId} />
<TerminalComponent cwd={`${projectsPath}/${projectId}`} />
</div>
) : (
<>
+7 -11
View File
@@ -5,14 +5,13 @@ import { Copy } from 'lucide-react';
import { cn } from '@/lib/utils';
import { ShellTool } from '@/lib/tools/ShellTool';
import { useFS } from '@/hooks/useFS';
import { useFSPaths } from '@/hooks/useFSPaths';
import { useGit } from '@/hooks/useGit';
import { useCurrentUser } from '@/hooks/useCurrentUser';
import { useAppContext } from '@/hooks/useAppContext';
import { ansiToHtml, containsAnsiCodes } from '@/lib/ansiToHtml';
interface TerminalProps {
projectId: string;
cwd: string;
className?: string;
}
@@ -23,7 +22,7 @@ interface TerminalLine {
timestamp: Date;
}
export function Terminal({ projectId, className }: TerminalProps) {
export function Terminal({ cwd, className }: TerminalProps) {
const [lines, setLines] = useState<TerminalLine[]>([]);
const [currentInput, setCurrentInput] = useState('');
const [isExecuting, setIsExecuting] = useState(false);
@@ -35,14 +34,13 @@ export function Terminal({ projectId, className }: TerminalProps) {
const shellToolRef = useRef<ShellTool | null>(null);
const { fs } = useFS();
const { projectsPath } = useFSPaths();
const { git } = useGit();
const { user } = useCurrentUser();
const { config } = useAppContext();
// Initialize ShellTool
useEffect(() => {
shellToolRef.current = new ShellTool(fs, `${projectsPath}/${projectId}`, git, projectsPath, config.corsProxy, user?.signer);
shellToolRef.current = new ShellTool(fs, cwd, git, config.corsProxy, user?.signer);
// Add welcome message
setLines([{
@@ -51,7 +49,7 @@ export function Terminal({ projectId, className }: TerminalProps) {
content: `Welcome to Shakespeare Terminal\nType 'help' to see available commands.`,
timestamp: new Date()
}]);
}, [projectId, fs, git, projectsPath, config.corsProxy, user?.signer]);
}, [cwd, fs, git, config.corsProxy, user?.signer]);
// Auto-scroll to bottom when new lines are added or execution state changes
useEffect(() => {
@@ -108,10 +106,8 @@ export function Terminal({ projectId, className }: TerminalProps) {
// Check if running in Electron - use real shell
if (window.electron?.shell) {
// Use the full path (with ~ if present) - Electron will expand it
const fullCwd = `${projectsPath}/${projectId}`;
const result = await window.electron.shell.exec(command, fullCwd);
// Use the provided cwd (Electron will expand ~ if present)
const result = await window.electron.shell.exec(command, cwd);
// Format output
let output = '';
@@ -159,7 +155,7 @@ export function Terminal({ projectId, className }: TerminalProps) {
} finally {
setIsExecuting(false);
}
}, [addLine, commandHistory, projectId, projectsPath]);
}, [addLine, commandHistory, cwd]);
const handleSubmit = useCallback((e: React.FormEvent) => {
e.preventDefault();
+1 -1
View File
@@ -6,7 +6,7 @@ import { Terminal } from './Terminal';
export function TerminalTest() {
return (
<div className="h-[500px] w-full">
<Terminal projectId="test" />
<Terminal cwd="/projects/test" />
</div>
);
}
+1 -1
View File
@@ -609,7 +609,7 @@ Commands are executed through the `ShellTool` which handles:
import { ShellTool } from '@/lib/tools/ShellTool';
// Create shell tool with filesystem and working directory
const shell = new ShellTool(fs, '/project/root');
const shell = new ShellTool(fs, '/project/root', ...rest);
// Execute commands
const result = await shell.execute({ command: 'cat package.json' });
+1 -1
View File
@@ -41,7 +41,7 @@ describe('ShellTool', () => {
mockFS = createMockFS();
mockNostr = createMockNostr();
mockGit = new Git({ fs: mockFS, nostr: mockNostr });
shellTool = new ShellTool(mockFS, testCwd, mockGit, '/projects', testCorsProxy);
shellTool = new ShellTool(mockFS, testCwd, mockGit, testCorsProxy);
});
it('should have correct tool properties', () => {
+1 -3
View File
@@ -51,7 +51,6 @@ export class ShellTool implements Tool<ShellToolParams> {
private cwd: string;
private git: Git;
private commands: Map<string, ShellCommand>;
private projectsPath: string;
private signer?: NostrSigner;
private corsProxy: string;
@@ -63,11 +62,10 @@ export class ShellTool implements Tool<ShellToolParams> {
),
});
constructor(fs: JSRuntimeFS, cwd: string, git: Git, projectsPath: string = '/projects', corsProxy: string, signer?: NostrSigner) {
constructor(fs: JSRuntimeFS, cwd: string, git: Git, corsProxy: string, signer?: NostrSigner) {
this.fs = fs;
this.cwd = cwd;
this.git = git;
this.projectsPath = projectsPath;
this.corsProxy = corsProxy;
this.signer = signer;
this.commands = new Map();
+2 -1
View File
@@ -512,5 +512,6 @@
"templateUpdateFailed": "Template Update Failed",
"templateUpdateFailedDescription": "Failed to update the project template from the remote repository. Using the cached version instead.",
"templatesDirectory": "Templates Directory",
"templatesDirectoryDescription": "Directory where project templates are cached in the virtual filesystem."
"templatesDirectoryDescription": "Directory where project templates are cached in the virtual filesystem.",
"terminal": "Terminal"
}
+2 -1
View File
@@ -427,5 +427,6 @@
"giftCardAlreadyRedeemed": "An riga an fanshi wannan katin kyauta.",
"modified": "An Canza",
"restoreToDefault": "Mayar da asali",
"restoredToDefault": "An Mayar da Asali"
"restoredToDefault": "An Mayar da Asali",
"terminal": "Terminal"
}
+2 -1
View File
@@ -424,5 +424,6 @@
"giftCardAlreadyRedeemed": "Egbapụtalarị kaadị onyinye a.",
"modified": "Gbanwere",
"restoreToDefault": "Weghachi na nke mbụ",
"restoredToDefault": "Weghachiri na Nke Mbụ"
"restoredToDefault": "Weghachiri na Nke Mbụ",
"terminal": "Terminal"
}
+2 -1
View File
@@ -437,5 +437,6 @@
"giftCardAlreadyRedeemed": "Este cartão presente já foi resgatado.",
"modified": "Modificado",
"restoreToDefault": "Restaurar para padrão",
"restoredToDefault": "Restaurado para Padrão"
"restoredToDefault": "Restaurado para Padrão",
"terminal": "Terminal"
}
+2 -1
View File
@@ -424,5 +424,6 @@
"giftCardAlreadyRedeemed": "A ti ra kaadi ẹbun yii tẹlẹ.",
"modified": "Ti Yipada",
"restoreToDefault": "Pada si atilẹwa",
"restoredToDefault": "Ti Pada si Atilẹwa"
"restoredToDefault": "Ti Pada si Atilẹwa",
"terminal": "Terminal"
}
+2 -1
View File
@@ -437,5 +437,6 @@
"giftCardAlreadyRedeemed": "此礼品卡已被兑换。",
"modified": "已修改",
"restoreToDefault": "恢复默认值",
"restoredToDefault": "已恢复默认值"
"restoredToDefault": "已恢复默认值",
"terminal": "终端"
}
+17
View File
@@ -13,6 +13,7 @@ import { useAppContext } from "@/hooks/useAppContext";
import { useOffline } from "@/hooks/useOffline";
import { useToast } from "@/hooks/useToast";
import { defaultSystemPrompt } from "@/lib/system";
import { Terminal } from "@/components/Terminal";
export function SystemSettings() {
const { t } = useTranslation();
@@ -1059,6 +1060,22 @@ export function SystemSettings() {
</AccordionContent>
</AccordionItem>
</Accordion>
{/* Terminal */}
<Accordion type="single" collapsible className="w-full">
<AccordionItem value="terminal" className="border rounded-lg">
<AccordionTrigger className="px-4 py-3 hover:no-underline">
<div className="flex items-center gap-2">
<h4 className="text-sm font-medium">{t('terminal')}</h4>
</div>
</AccordionTrigger>
<AccordionContent className="px-0 pb-0">
<div className="h-[500px]">
<Terminal cwd="/" />
</div>
</AccordionContent>
</AccordionItem>
</Accordion>
</div>
</div>
);