From 199043e4bc50441e09207eed5d0279c76bb8434c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 23 Nov 2025 10:57:16 -0600 Subject: [PATCH] Add Terminal to System Settings --- src/components/Shakespeare/ChatPane.tsx | 2 +- src/components/Shakespeare/PreviewPane.tsx | 4 ++-- src/components/Terminal.tsx | 18 +++++++----------- src/components/TerminalTest.tsx | 2 +- src/lib/commands/README.md | 2 +- src/lib/tools/ShellTool.test.ts | 2 +- src/lib/tools/ShellTool.ts | 4 +--- src/locales/en.json | 3 ++- src/locales/ha.json | 3 ++- src/locales/ig.json | 3 ++- src/locales/pt.json | 3 ++- src/locales/yo.json | 3 ++- src/locales/zh.json | 3 ++- src/pages/SystemSettings.tsx | 17 +++++++++++++++++ 14 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index b3fdeb4b..9e7b0f72 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -172,7 +172,7 @@ export const ChatPane = forwardRef(({ 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), }; diff --git a/src/components/Shakespeare/PreviewPane.tsx b/src/components/Shakespeare/PreviewPane.tsx index 6ab9e75b..4b3b5633 100644 --- a/src/components/Shakespeare/PreviewPane.tsx +++ b/src/components/Shakespeare/PreviewPane.tsx @@ -793,7 +793,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
- +
) : ( @@ -887,7 +887,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
{desktopCodeView === 'terminal' ? (
- +
) : ( <> diff --git a/src/components/Terminal.tsx b/src/components/Terminal.tsx index 2fccd501..a7934fbe 100644 --- a/src/components/Terminal.tsx +++ b/src/components/Terminal.tsx @@ -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([]); const [currentInput, setCurrentInput] = useState(''); const [isExecuting, setIsExecuting] = useState(false); @@ -35,14 +34,13 @@ export function Terminal({ projectId, className }: TerminalProps) { const shellToolRef = useRef(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(); diff --git a/src/components/TerminalTest.tsx b/src/components/TerminalTest.tsx index 0f7574e8..4fe01acc 100644 --- a/src/components/TerminalTest.tsx +++ b/src/components/TerminalTest.tsx @@ -6,7 +6,7 @@ import { Terminal } from './Terminal'; export function TerminalTest() { return (
- +
); } diff --git a/src/lib/commands/README.md b/src/lib/commands/README.md index 5bf08cfa..9a8d45f2 100644 --- a/src/lib/commands/README.md +++ b/src/lib/commands/README.md @@ -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' }); diff --git a/src/lib/tools/ShellTool.test.ts b/src/lib/tools/ShellTool.test.ts index 3eca52e6..64f3dae1 100644 --- a/src/lib/tools/ShellTool.test.ts +++ b/src/lib/tools/ShellTool.test.ts @@ -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', () => { diff --git a/src/lib/tools/ShellTool.ts b/src/lib/tools/ShellTool.ts index a312fb1b..8679bb36 100644 --- a/src/lib/tools/ShellTool.ts +++ b/src/lib/tools/ShellTool.ts @@ -51,7 +51,6 @@ export class ShellTool implements Tool { private cwd: string; private git: Git; private commands: Map; - private projectsPath: string; private signer?: NostrSigner; private corsProxy: string; @@ -63,11 +62,10 @@ export class ShellTool implements Tool { ), }); - 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(); diff --git a/src/locales/en.json b/src/locales/en.json index 796f2bd3..832f3674 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -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" } diff --git a/src/locales/ha.json b/src/locales/ha.json index 54be4ae1..59488473 100644 --- a/src/locales/ha.json +++ b/src/locales/ha.json @@ -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" } diff --git a/src/locales/ig.json b/src/locales/ig.json index 922b34b9..5f0c3e8e 100644 --- a/src/locales/ig.json +++ b/src/locales/ig.json @@ -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" } diff --git a/src/locales/pt.json b/src/locales/pt.json index 3b9bc08a..c680028e 100644 --- a/src/locales/pt.json +++ b/src/locales/pt.json @@ -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" } diff --git a/src/locales/yo.json b/src/locales/yo.json index 916f7618..b7de4fd1 100644 --- a/src/locales/yo.json +++ b/src/locales/yo.json @@ -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" } diff --git a/src/locales/zh.json b/src/locales/zh.json index ef097093..a60f7538 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -437,5 +437,6 @@ "giftCardAlreadyRedeemed": "此礼品卡已被兑换。", "modified": "已修改", "restoreToDefault": "恢复默认值", - "restoredToDefault": "已恢复默认值" + "restoredToDefault": "已恢复默认值", + "terminal": "终端" } diff --git a/src/pages/SystemSettings.tsx b/src/pages/SystemSettings.tsx index 06b3541e..0c46aaa3 100644 --- a/src/pages/SystemSettings.tsx +++ b/src/pages/SystemSettings.tsx @@ -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() { + + {/* Terminal */} + + + +
+

{t('terminal')}

+
+
+ +
+ +
+
+
+
);