mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Merge remote-tracking branch 'origin/main' into electron
This commit is contained in:
42 files changed
+383
-115
No files matched your search
+10
-4
@@ -12,6 +12,7 @@ import { TooltipProvider } from "@/components/ui/tooltip";
|
|||||||
import { NostrLoginProvider } from '@nostrify/react/login';
|
import { NostrLoginProvider } from '@nostrify/react/login';
|
||||||
import { AppProvider } from '@/components/AppProvider';
|
import { AppProvider } from '@/components/AppProvider';
|
||||||
import { AppConfig } from '@/contexts/AppContext';
|
import { AppConfig } from '@/contexts/AppContext';
|
||||||
|
import { useAppContext } from '@/hooks/useAppContext';
|
||||||
import { AISettingsProvider } from '@/components/AISettingsProvider';
|
import { AISettingsProvider } from '@/components/AISettingsProvider';
|
||||||
import { GitSettingsProvider } from '@/components/GitSettingsProvider';
|
import { GitSettingsProvider } from '@/components/GitSettingsProvider';
|
||||||
import { DeploySettingsProvider } from '@/components/DeploySettingsProvider';
|
import { DeploySettingsProvider } from '@/components/DeploySettingsProvider';
|
||||||
@@ -51,6 +52,9 @@ const defaultConfig: AppConfig = {
|
|||||||
showcaseEnabled: true,
|
showcaseEnabled: true,
|
||||||
showcaseModerator: "npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc",
|
showcaseModerator: "npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc",
|
||||||
ngitServers: ["git.shakespeare.diy", "relay.ngit.dev"],
|
ngitServers: ["git.shakespeare.diy", "relay.ngit.dev"],
|
||||||
|
fsPathProjects: "/projects",
|
||||||
|
fsPathConfig: "/config",
|
||||||
|
fsPathTmp: "/tmp",
|
||||||
};
|
};
|
||||||
|
|
||||||
const presetRelays = [
|
const presetRelays = [
|
||||||
@@ -65,13 +69,15 @@ const lightningFS = new LightningFS('shakespeare-fs');
|
|||||||
const fs = new LightningFSAdapter(lightningFS.promises);
|
const fs = new LightningFSAdapter(lightningFS.promises);
|
||||||
|
|
||||||
// Component to handle filesystem cleanup on startup
|
// Component to handle filesystem cleanup on startup
|
||||||
// Automatically removes files older than 1 hour from /tmp directory
|
// Automatically removes files older than 1 hour from tmp directory
|
||||||
function FSCleanupHandler() {
|
function FSCleanupHandler() {
|
||||||
|
const { config } = useAppContext();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Run cleanup on application startup to remove stale temporary files
|
// Run cleanup on application startup to remove stale temporary files
|
||||||
// This helps prevent the VFS from accumulating old files over time
|
// This helps prevent the VFS from accumulating old files over time
|
||||||
cleanupTmpDirectory(fs).catch(console.error);
|
cleanupTmpDirectory(fs, config.fsPathTmp).catch(console.error);
|
||||||
}, []);
|
}, [config.fsPathTmp]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -82,8 +88,8 @@ export function App() {
|
|||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<AppProvider storageKey="nostr:app-config" defaultConfig={defaultConfig} presetRelays={presetRelays}>
|
<AppProvider storageKey="nostr:app-config" defaultConfig={defaultConfig} presetRelays={presetRelays}>
|
||||||
<FSProvider fs={fs}>
|
<FSProvider fs={fs}>
|
||||||
<FSCleanupHandler />
|
|
||||||
<ConsoleErrorProvider>
|
<ConsoleErrorProvider>
|
||||||
|
<FSCleanupHandler />
|
||||||
<NostrLoginProvider storageKey='nostr:login'>
|
<NostrLoginProvider storageKey='nostr:login'>
|
||||||
<NostrProvider>
|
<NostrProvider>
|
||||||
<AISettingsProvider>
|
<AISettingsProvider>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useQueryClient } from '@tanstack/react-query';
|
|||||||
import { ReactNode, useState, useEffect } from 'react';
|
import { ReactNode, useState, useEffect } from 'react';
|
||||||
import { AISettingsContext, type AISettings, type AIProvider, type AISettingsContextType } from '@/contexts/AISettingsContext';
|
import { AISettingsContext, type AISettings, type AIProvider, type AISettingsContextType } from '@/contexts/AISettingsContext';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { readAISettings, writeAISettings } from '@/lib/configUtils';
|
import { readAISettings, writeAISettings } from '@/lib/configUtils';
|
||||||
|
|
||||||
interface AISettingsProviderProps {
|
interface AISettingsProviderProps {
|
||||||
@@ -16,6 +17,7 @@ const DEFAULT_SETTINGS: AISettings = {
|
|||||||
export function AISettingsProvider({ children }: AISettingsProviderProps) {
|
export function AISettingsProvider({ children }: AISettingsProviderProps) {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
|
const { configPath } = useFSPaths();
|
||||||
const [settings, setSettings] = useState<AISettings>(DEFAULT_SETTINGS);
|
const [settings, setSettings] = useState<AISettings>(DEFAULT_SETTINGS);
|
||||||
const [isInitialized, setIsInitialized] = useState(false);
|
const [isInitialized, setIsInitialized] = useState(false);
|
||||||
|
|
||||||
@@ -23,7 +25,7 @@ export function AISettingsProvider({ children }: AISettingsProviderProps) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const initializeSettings = async () => {
|
const initializeSettings = async () => {
|
||||||
try {
|
try {
|
||||||
const settings = await readAISettings(fs);
|
const settings = await readAISettings(fs, configPath);
|
||||||
setSettings(settings);
|
setSettings(settings);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to initialize AI settings:', error);
|
console.error('Failed to initialize AI settings:', error);
|
||||||
@@ -34,7 +36,7 @@ export function AISettingsProvider({ children }: AISettingsProviderProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
initializeSettings();
|
initializeSettings();
|
||||||
}, [fs]);
|
}, [fs, configPath]);
|
||||||
|
|
||||||
// Save settings to VFS whenever they change (but not during initialization)
|
// Save settings to VFS whenever they change (but not during initialization)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -42,14 +44,14 @@ export function AISettingsProvider({ children }: AISettingsProviderProps) {
|
|||||||
|
|
||||||
const saveSettings = async () => {
|
const saveSettings = async () => {
|
||||||
try {
|
try {
|
||||||
await writeAISettings(fs, settings);
|
await writeAISettings(fs, settings, configPath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to save AI settings:', error);
|
console.error('Failed to save AI settings:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
saveSettings();
|
saveSettings();
|
||||||
}, [fs, settings, isInitialized]);
|
}, [fs, settings, isInitialized, configPath]);
|
||||||
|
|
||||||
const updateSettings = (newSettings: Partial<AISettings>) => {
|
const updateSettings = (newSettings: Partial<AISettings>) => {
|
||||||
setSettings(prev => ({ ...prev, ...newSettings }));
|
setSettings(prev => ({ ...prev, ...newSettings }));
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ const AppConfigSchema = z.object({
|
|||||||
showcaseEnabled: z.boolean(),
|
showcaseEnabled: z.boolean(),
|
||||||
showcaseModerator: z.string(),
|
showcaseModerator: z.string(),
|
||||||
ngitServers: z.array(z.string()),
|
ngitServers: z.array(z.string()),
|
||||||
|
fsPathProjects: z.string().min(1),
|
||||||
|
fsPathConfig: z.string().min(1),
|
||||||
|
fsPathTmp: z.string().min(1),
|
||||||
}) satisfies z.ZodType<AppConfig>;
|
}) satisfies z.ZodType<AppConfig>;
|
||||||
|
|
||||||
export function AppProvider(props: AppProviderProps) {
|
export function AppProvider(props: AppProviderProps) {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import { useDeploySettings } from '@/hooks/useDeploySettings';
|
|||||||
import { useProjectDeploySettings } from '@/hooks/useProjectDeploySettings';
|
import { useProjectDeploySettings } from '@/hooks/useProjectDeploySettings';
|
||||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useAppContext } from '@/hooks/useAppContext';
|
import { useAppContext } from '@/hooks/useAppContext';
|
||||||
import { useNostr } from '@nostrify/react';
|
import { useNostr } from '@nostrify/react';
|
||||||
import { ShakespeareAdapter, NetlifyAdapter, VercelAdapter, NsiteAdapter, DeployAdapter } from '@/lib/deploy';
|
import { ShakespeareAdapter, NetlifyAdapter, VercelAdapter, NsiteAdapter, DeployAdapter } from '@/lib/deploy';
|
||||||
@@ -115,6 +116,7 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
|||||||
const { settings: projectSettings, updateSettings: updateProjectSettings } = useProjectDeploySettings(projectId);
|
const { settings: projectSettings, updateSettings: updateProjectSettings } = useProjectDeploySettings(projectId);
|
||||||
const { user } = useCurrentUser();
|
const { user } = useCurrentUser();
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { config } = useAppContext();
|
const { config } = useAppContext();
|
||||||
const { nostr } = useNostr();
|
const { nostr } = useNostr();
|
||||||
|
|
||||||
@@ -165,7 +167,7 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
|||||||
setDeployResult(null);
|
setDeployResult(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const projectPath = `/projects/${projectId}`;
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
let adapter: DeployAdapter;
|
let adapter: DeployAdapter;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useState, useEffect, useMemo, type ReactNode } from 'react';
|
import { useState, useEffect, useMemo, type ReactNode } from 'react';
|
||||||
import { DeploySettingsContext, type DeploySettings, type DeployProvider } from '@/contexts/DeploySettingsContext';
|
import { DeploySettingsContext, type DeploySettings, type DeployProvider } from '@/contexts/DeploySettingsContext';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { readDeploySettings, writeDeploySettings } from '@/lib/configUtils';
|
import { readDeploySettings, writeDeploySettings } from '@/lib/configUtils';
|
||||||
|
|
||||||
const DEFAULT_SETTINGS: DeploySettings = {
|
const DEFAULT_SETTINGS: DeploySettings = {
|
||||||
@@ -9,6 +10,7 @@ const DEFAULT_SETTINGS: DeploySettings = {
|
|||||||
|
|
||||||
export function DeploySettingsProvider({ children }: { children: ReactNode }) {
|
export function DeploySettingsProvider({ children }: { children: ReactNode }) {
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
|
const { configPath } = useFSPaths();
|
||||||
const [settings, setSettings] = useState<DeploySettings>(DEFAULT_SETTINGS);
|
const [settings, setSettings] = useState<DeploySettings>(DEFAULT_SETTINGS);
|
||||||
const [isInitialized, setIsInitialized] = useState(false);
|
const [isInitialized, setIsInitialized] = useState(false);
|
||||||
|
|
||||||
@@ -16,7 +18,7 @@ export function DeploySettingsProvider({ children }: { children: ReactNode }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const initializeSettings = async () => {
|
const initializeSettings = async () => {
|
||||||
try {
|
try {
|
||||||
const settings = await readDeploySettings(fs);
|
const settings = await readDeploySettings(fs, configPath);
|
||||||
setSettings(settings);
|
setSettings(settings);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to initialize deploy settings:', error);
|
console.error('Failed to initialize deploy settings:', error);
|
||||||
@@ -27,7 +29,7 @@ export function DeploySettingsProvider({ children }: { children: ReactNode }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
initializeSettings();
|
initializeSettings();
|
||||||
}, [fs]);
|
}, [fs, configPath]);
|
||||||
|
|
||||||
// Save settings to VFS whenever they change (but not during initialization)
|
// Save settings to VFS whenever they change (but not during initialization)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -35,14 +37,14 @@ export function DeploySettingsProvider({ children }: { children: ReactNode }) {
|
|||||||
|
|
||||||
const saveSettings = async () => {
|
const saveSettings = async () => {
|
||||||
try {
|
try {
|
||||||
await writeDeploySettings(fs, settings);
|
await writeDeploySettings(fs, settings, configPath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to save deploy settings:', error);
|
console.error('Failed to save deploy settings:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
saveSettings();
|
saveSettings();
|
||||||
}, [fs, settings, isInitialized]);
|
}, [fs, settings, isInitialized, configPath]);
|
||||||
|
|
||||||
const updateSettings = (updates: Partial<DeploySettings>) => {
|
const updateSettings = (updates: Partial<DeploySettings>) => {
|
||||||
setSettings(prev => ({ ...prev, ...updates }));
|
setSettings(prev => ({ ...prev, ...updates }));
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import {
|
|||||||
import { useGitStatus } from '@/hooks/useGitStatus';
|
import { useGitStatus } from '@/hooks/useGitStatus';
|
||||||
import { useGitSettings } from '@/hooks/useGitSettings';
|
import { useGitSettings } from '@/hooks/useGitSettings';
|
||||||
import { useGit } from '@/hooks/useGit';
|
import { useGit } from '@/hooks/useGit';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||||
import { useNostr } from '@nostrify/react';
|
import { useNostr } from '@nostrify/react';
|
||||||
@@ -91,6 +92,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
|
|||||||
const { data: gitStatus, refetch: refetchGitStatus } = useGitStatus(projectId);
|
const { data: gitStatus, refetch: refetchGitStatus } = useGitStatus(projectId);
|
||||||
const { settings } = useGitSettings();
|
const { settings } = useGitSettings();
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { user } = useCurrentUser();
|
const { user } = useCurrentUser();
|
||||||
const { nostr } = useNostr();
|
const { nostr } = useNostr();
|
||||||
@@ -98,7 +100,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
|
|||||||
const { data: pullRequests, isLoading: isLoadingPRs } = usePullRequests(originUrl);
|
const { data: pullRequests, isLoading: isLoadingPRs } = usePullRequests(originUrl);
|
||||||
const { config } = useAppContext();
|
const { config } = useAppContext();
|
||||||
|
|
||||||
const projectPath = `/projects/${projectId}`;
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
// Initialize origin URL from git status
|
// Initialize origin URL from git status
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -171,7 +171,8 @@ describe('GitSettingsProvider', () => {
|
|||||||
password: 'test-token',
|
password: 'test-token',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
|
'/config' // configPath
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ReactNode, useState, useEffect } from 'react';
|
import { ReactNode, useState, useEffect } from 'react';
|
||||||
import { GitSettingsContext, type GitSettings, type GitCredential, type GitHostToken, type GitSettingsContextType } from '@/contexts/GitSettingsContext';
|
import { GitSettingsContext, type GitSettings, type GitCredential, type GitHostToken, type GitSettingsContextType } from '@/contexts/GitSettingsContext';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { readGitSettings, writeGitSettings } from '@/lib/configUtils';
|
import { readGitSettings, writeGitSettings } from '@/lib/configUtils';
|
||||||
|
|
||||||
interface GitSettingsProviderProps {
|
interface GitSettingsProviderProps {
|
||||||
@@ -14,6 +15,7 @@ const DEFAULT_SETTINGS: GitSettings = {
|
|||||||
|
|
||||||
export function GitSettingsProvider({ children }: GitSettingsProviderProps) {
|
export function GitSettingsProvider({ children }: GitSettingsProviderProps) {
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
|
const { configPath } = useFSPaths();
|
||||||
const [settings, setSettings] = useState<GitSettings>(DEFAULT_SETTINGS);
|
const [settings, setSettings] = useState<GitSettings>(DEFAULT_SETTINGS);
|
||||||
const [isInitialized, setIsInitialized] = useState(false);
|
const [isInitialized, setIsInitialized] = useState(false);
|
||||||
|
|
||||||
@@ -21,7 +23,7 @@ export function GitSettingsProvider({ children }: GitSettingsProviderProps) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const initializeSettings = async () => {
|
const initializeSettings = async () => {
|
||||||
try {
|
try {
|
||||||
const settings = await readGitSettings(fs);
|
const settings = await readGitSettings(fs, configPath);
|
||||||
setSettings(settings);
|
setSettings(settings);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to initialize Git settings:', error);
|
console.error('Failed to initialize Git settings:', error);
|
||||||
@@ -32,7 +34,7 @@ export function GitSettingsProvider({ children }: GitSettingsProviderProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
initializeSettings();
|
initializeSettings();
|
||||||
}, [fs]);
|
}, [fs, configPath]);
|
||||||
|
|
||||||
// Save settings to VFS whenever they change (but not during initialization)
|
// Save settings to VFS whenever they change (but not during initialization)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -40,14 +42,14 @@ export function GitSettingsProvider({ children }: GitSettingsProviderProps) {
|
|||||||
|
|
||||||
const saveSettings = async () => {
|
const saveSettings = async () => {
|
||||||
try {
|
try {
|
||||||
await writeGitSettings(fs, settings);
|
await writeGitSettings(fs, settings, configPath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to save Git settings:', error);
|
console.error('Failed to save Git settings:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
saveSettings();
|
saveSettings();
|
||||||
}, [fs, settings, isInitialized]);
|
}, [fs, settings, isInitialized, configPath]);
|
||||||
|
|
||||||
const updateSettings = (newSettings: Partial<GitSettings>) => {
|
const updateSettings = (newSettings: Partial<GitSettings>) => {
|
||||||
setSettings(prev => ({ ...prev, ...newSettings }));
|
setSettings(prev => ({ ...prev, ...newSettings }));
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { Input } from '@/components/ui/input';
|
|||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
@@ -50,6 +51,7 @@ export function ProjectDetailsDialog({ project, open, onOpenChange, onProjectDel
|
|||||||
const [newProjectName, setNewProjectName] = useState(project.id);
|
const [newProjectName, setNewProjectName] = useState(project.id);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const projectsManager = useProjectsManager();
|
const projectsManager = useProjectsManager();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
@@ -143,7 +145,7 @@ export function ProjectDetailsDialog({ project, open, onOpenChange, onProjectDel
|
|||||||
setIsExporting(true);
|
setIsExporting(true);
|
||||||
try {
|
try {
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
const projectPath = `/projects/${project.id}`;
|
const projectPath = `${projectsPath}/${project.id}`;
|
||||||
|
|
||||||
// Recursive function to add files and directories to zip from a specific project
|
// Recursive function to add files and directories to zip from a specific project
|
||||||
const addFolderToZip = async (dirPath: string, zipFolder: JSZip) => {
|
const addFolderToZip = async (dirPath: string, zipFolder: JSZip) => {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { ReactNode, useMemo, useEffect } from 'react';
|
|||||||
import { SessionManagerContext } from '@/contexts/SessionManagerContext';
|
import { SessionManagerContext } from '@/contexts/SessionManagerContext';
|
||||||
import { SessionManager } from '@/lib/SessionManager';
|
import { SessionManager } from '@/lib/SessionManager';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useAISettings } from '@/hooks/useAISettings';
|
import { useAISettings } from '@/hooks/useAISettings';
|
||||||
import { useProviderModels } from '@/hooks/useProviderModels';
|
import { useProviderModels } from '@/hooks/useProviderModels';
|
||||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||||
@@ -16,6 +17,7 @@ interface SessionManagerProviderProps {
|
|||||||
*/
|
*/
|
||||||
export function SessionManagerProvider({ children }: SessionManagerProviderProps) {
|
export function SessionManagerProvider({ children }: SessionManagerProviderProps) {
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { settings } = useAISettings();
|
const { settings } = useAISettings();
|
||||||
const { models } = useProviderModels();
|
const { models } = useProviderModels();
|
||||||
const { user, metadata } = useCurrentUser();
|
const { user, metadata } = useCurrentUser();
|
||||||
@@ -24,8 +26,8 @@ export function SessionManagerProvider({ children }: SessionManagerProviderProps
|
|||||||
const sessionManager = useMemo(() => {
|
const sessionManager = useMemo(() => {
|
||||||
const getProviderModels = () => models;
|
const getProviderModels = () => models;
|
||||||
const getCurrentUser = () => ({ user, metadata });
|
const getCurrentUser = () => ({ user, metadata });
|
||||||
return new SessionManager(fs, settings, getProviderModels, getCurrentUser, config.corsProxy);
|
return new SessionManager(fs, settings, getProviderModels, getCurrentUser, config.corsProxy, projectsPath);
|
||||||
}, [fs, settings, models, user, metadata, config.corsProxy]);
|
}, [fs, settings, models, user, metadata, config.corsProxy, projectsPath]);
|
||||||
|
|
||||||
// Cleanup on unmount
|
// Cleanup on unmount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { OnboardingDialog } from '@/components/OnboardingDialog';
|
|||||||
import { Loader2, ChevronDown } from 'lucide-react';
|
import { Loader2, ChevronDown } from 'lucide-react';
|
||||||
import { useAISettings } from '@/hooks/useAISettings';
|
import { useAISettings } from '@/hooks/useAISettings';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||||
import { useKeepAlive } from '@/hooks/useKeepAlive';
|
import { useKeepAlive } from '@/hooks/useKeepAlive';
|
||||||
import { useAppContext } from '@/hooks/useAppContext';
|
import { useAppContext } from '@/hooks/useAppContext';
|
||||||
@@ -75,6 +76,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
const { user } = useCurrentUser();
|
const { user } = useCurrentUser();
|
||||||
const { models } = useProviderModels();
|
const { models } = useProviderModels();
|
||||||
const { config } = useAppContext();
|
const { config } = useAppContext();
|
||||||
|
const { projectsPath, tmpPath } = useFSPaths();
|
||||||
const [showScrollToBottom, setShowScrollToBottom] = useState(false);
|
const [showScrollToBottom, setShowScrollToBottom] = useState(false);
|
||||||
const [isDragOver, setIsDragOver] = useState(false);
|
const [isDragOver, setIsDragOver] = useState(false);
|
||||||
const [scrolledProjects] = useState(() => new Set<string>());
|
const [scrolledProjects] = useState(() => new Set<string>());
|
||||||
@@ -133,14 +135,14 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
}, [projectId, providerModel]);
|
}, [projectId, providerModel]);
|
||||||
|
|
||||||
// Initialize AI chat with tools
|
// Initialize AI chat with tools
|
||||||
const cwd = `/projects/${projectId}`;
|
const cwd = `${projectsPath}/${projectId}`;
|
||||||
const esmUrlRef = useRef(config.esmUrl);
|
const esmUrlRef = useRef(config.esmUrl);
|
||||||
const customTools = useMemo(() => {
|
const customTools = useMemo(() => {
|
||||||
const baseTools = {
|
const baseTools = {
|
||||||
git_commit: new GitCommitTool(fs, cwd, git),
|
git_commit: new GitCommitTool(fs, cwd, git),
|
||||||
text_editor_view: new TextEditorViewTool(fs, cwd),
|
text_editor_view: new TextEditorViewTool(fs, cwd, { projectsPath }),
|
||||||
text_editor_write: new TextEditorWriteTool(fs, cwd),
|
text_editor_write: new TextEditorWriteTool(fs, cwd, { projectsPath, tmpPath }),
|
||||||
text_editor_str_replace: new TextEditorStrReplaceTool(fs, cwd),
|
text_editor_str_replace: new TextEditorStrReplaceTool(fs, cwd, { projectsPath, tmpPath }),
|
||||||
npm_add_package: new NpmAddPackageTool(fs, cwd),
|
npm_add_package: new NpmAddPackageTool(fs, cwd),
|
||||||
npm_remove_package: new NpmRemovePackageTool(fs, cwd),
|
npm_remove_package: new NpmRemovePackageTool(fs, cwd),
|
||||||
build_project: new BuildProjectTool(fs, cwd, esmUrlRef.current),
|
build_project: new BuildProjectTool(fs, cwd, esmUrlRef.current),
|
||||||
@@ -165,7 +167,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return baseTools;
|
return baseTools;
|
||||||
}, [fs, git, cwd, user, projectId]);
|
}, [fs, git, cwd, user, projectId, projectsPath, tmpPath]);
|
||||||
|
|
||||||
// Convert tools to OpenAI format
|
// Convert tools to OpenAI format
|
||||||
const tools = useMemo(() => {
|
const tools = useMemo(() => {
|
||||||
@@ -438,7 +440,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
if (attachedFiles.length > 0) {
|
if (attachedFiles.length > 0) {
|
||||||
const filePromises = attachedFiles.map(async (file) => {
|
const filePromises = attachedFiles.map(async (file) => {
|
||||||
try {
|
try {
|
||||||
const savedPath = await saveFileToTmp(fs, file);
|
const savedPath = await saveFileToTmp(fs, file, tmpPath);
|
||||||
return `Added file: ${savedPath}`;
|
return `Added file: ${savedPath}`;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to save file:', error);
|
console.error('Failed to save file:', error);
|
||||||
@@ -463,7 +465,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
// Send as text parts if we have multiple parts, otherwise send as string for simplicity
|
// Send as text parts if we have multiple parts, otherwise send as string for simplicity
|
||||||
const messageContent = contentParts.length === 1 ? contentParts[0].text : contentParts;
|
const messageContent = contentParts.length === 1 ? contentParts[0].text : contentParts;
|
||||||
await sendMessage(messageContent, modelToUse);
|
await sendMessage(messageContent, modelToUse);
|
||||||
}, [addRecentlyUsedModel, fs, isConfigured, isLoading, providerModel, sendMessage]);
|
}, [addRecentlyUsedModel, fs, isConfigured, isLoading, providerModel, sendMessage, tmpPath]);
|
||||||
|
|
||||||
// Handle textarea focus - show onboarding if not configured
|
// Handle textarea focus - show onboarding if not configured
|
||||||
const handleTextareaFocus = useCallback(() => {
|
const handleTextareaFocus = useCallback(() => {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useState, useEffect, useCallback, useRef } from 'react';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { addConsoleMessage, getConsoleMessages, type ConsoleMessage } from '@/lib/consoleMessages';
|
import { addConsoleMessage, getConsoleMessages, type ConsoleMessage } from '@/lib/consoleMessages';
|
||||||
import { useConsoleError } from '@/hooks/useConsoleError';
|
import { useConsoleError } from '@/hooks/useConsoleError';
|
||||||
import { useBuildProject } from '@/hooks/useBuildProject';
|
import { useBuildProject } from '@/hooks/useBuildProject';
|
||||||
@@ -89,6 +90,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
|||||||
const [deployDialogOpen, setDeployDialogOpen] = useState(false);
|
const [deployDialogOpen, setDeployDialogOpen] = useState(false);
|
||||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const projectsManager = useProjectsManager();
|
const projectsManager = useProjectsManager();
|
||||||
|
|
||||||
// Use console error state from provider
|
// Use console error state from provider
|
||||||
@@ -506,7 +508,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
|||||||
if (!selectedFile) return;
|
if (!selectedFile) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.writeFile(`/projects/${projectId}/${selectedFile}`, content);
|
await fs.writeFile(`${projectsPath}/${projectId}/${selectedFile}`, content);
|
||||||
setFileContent(content);
|
setFileContent(content);
|
||||||
|
|
||||||
// Automatically trigger a rebuild after saving a file
|
// Automatically trigger a rebuild after saving a file
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Copy } from 'lucide-react';
|
|||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { ShellTool } from '@/lib/tools/ShellTool';
|
import { ShellTool } from '@/lib/tools/ShellTool';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useGit } from '@/hooks/useGit';
|
import { useGit } from '@/hooks/useGit';
|
||||||
import { ansiToHtml, containsAnsiCodes } from '@/lib/ansiToHtml';
|
import { ansiToHtml, containsAnsiCodes } from '@/lib/ansiToHtml';
|
||||||
|
|
||||||
@@ -32,11 +33,12 @@ export function Terminal({ projectId, className }: TerminalProps) {
|
|||||||
const shellToolRef = useRef<ShellTool | null>(null);
|
const shellToolRef = useRef<ShellTool | null>(null);
|
||||||
|
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
|
|
||||||
// Initialize ShellTool
|
// Initialize ShellTool
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
shellToolRef.current = new ShellTool(fs, `/projects/${projectId}`, git);
|
shellToolRef.current = new ShellTool(fs, `${projectsPath}/${projectId}`, git);
|
||||||
|
|
||||||
// Add welcome message
|
// Add welcome message
|
||||||
setLines([{
|
setLines([{
|
||||||
@@ -45,7 +47,7 @@ export function Terminal({ projectId, className }: TerminalProps) {
|
|||||||
content: `Welcome to Shakespeare Terminal\nType 'help' to see available commands.`,
|
content: `Welcome to Shakespeare Terminal\nType 'help' to see available commands.`,
|
||||||
timestamp: new Date()
|
timestamp: new Date()
|
||||||
}]);
|
}]);
|
||||||
}, [projectId, fs, git]);
|
}, [projectId, fs, git, projectsPath]);
|
||||||
|
|
||||||
// Auto-scroll to bottom when new lines are added or execution state changes
|
// Auto-scroll to bottom when new lines are added or execution state changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Button } from '@/components/ui/button';
|
|||||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||||
import { History, GitCommit, RotateCcw, AlertTriangle, ChevronDown, ChevronUp } from 'lucide-react';
|
import { History, GitCommit, RotateCcw, AlertTriangle, ChevronDown, ChevronUp } from 'lucide-react';
|
||||||
import { useGit } from '@/hooks/useGit';
|
import { useGit } from '@/hooks/useGit';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
import { useGitStatus } from '@/hooks/useGitStatus';
|
import { useGitStatus } from '@/hooks/useGitStatus';
|
||||||
@@ -45,6 +46,7 @@ export function GitHistoryDialog({ projectId, open: controlledOpen, onOpenChange
|
|||||||
const [isRollingBack, setIsRollingBack] = useState<string | null>(null);
|
const [isRollingBack, setIsRollingBack] = useState<string | null>(null);
|
||||||
const [expandedCommits, setExpandedCommits] = useState<Set<string>>(new Set());
|
const [expandedCommits, setExpandedCommits] = useState<Set<string>>(new Set());
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -55,7 +57,7 @@ export function GitHistoryDialog({ projectId, open: controlledOpen, onOpenChange
|
|||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const projectPath = `/projects/${projectId}`;
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
// Check if git repository exists
|
// Check if git repository exists
|
||||||
try {
|
try {
|
||||||
@@ -78,7 +80,7 @@ export function GitHistoryDialog({ projectId, open: controlledOpen, onOpenChange
|
|||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
}, [git, projectId]);
|
}, [git, projectId, projectsPath]);
|
||||||
|
|
||||||
const rollbackToCommit = useCallback(async (targetCommit: GitCommit) => {
|
const rollbackToCommit = useCallback(async (targetCommit: GitCommit) => {
|
||||||
if (!fs) return;
|
if (!fs) return;
|
||||||
@@ -86,7 +88,7 @@ export function GitHistoryDialog({ projectId, open: controlledOpen, onOpenChange
|
|||||||
setIsRollingBack(targetCommit.oid);
|
setIsRollingBack(targetCommit.oid);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const projectPath = `/projects/${projectId}`;
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
// Get the current HEAD commit
|
// Get the current HEAD commit
|
||||||
const currentCommit = await git.resolveRef({
|
const currentCommit = await git.resolveRef({
|
||||||
@@ -227,7 +229,7 @@ ${commitsToRevert.map(c => {
|
|||||||
} finally {
|
} finally {
|
||||||
setIsRollingBack(null);
|
setIsRollingBack(null);
|
||||||
}
|
}
|
||||||
}, [git, fs, projectId, toast, navigate, setIsOpen]);
|
}, [git, fs, projectId, toast, navigate, setIsOpen, projectsPath]);
|
||||||
|
|
||||||
const resetToHead = useCallback(async () => {
|
const resetToHead = useCallback(async () => {
|
||||||
if (!fs) return;
|
if (!fs) return;
|
||||||
@@ -235,7 +237,7 @@ ${commitsToRevert.map(c => {
|
|||||||
setIsRollingBack('HEAD');
|
setIsRollingBack('HEAD');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const projectPath = `/projects/${projectId}`;
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
// Get the current HEAD commit
|
// Get the current HEAD commit
|
||||||
const headCommit = await git.resolveRef({
|
const headCommit = await git.resolveRef({
|
||||||
@@ -326,7 +328,7 @@ ${commitsToRevert.map(c => {
|
|||||||
} finally {
|
} finally {
|
||||||
setIsRollingBack(null);
|
setIsRollingBack(null);
|
||||||
}
|
}
|
||||||
}, [git, fs, projectId, toast, navigate, setIsOpen]);
|
}, [git, fs, projectId, toast, navigate, setIsOpen, projectsPath]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
Megaphone,
|
Megaphone,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useGit } from '@/hooks/useGit';
|
import { useGit } from '@/hooks/useGit';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||||
import { useNostr } from '@/hooks/useNostr';
|
import { useNostr } from '@/hooks/useNostr';
|
||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
@@ -59,11 +60,12 @@ export function AnnounceRepositoryDialog({
|
|||||||
const [newRelay, setNewRelay] = useState('');
|
const [newRelay, setNewRelay] = useState('');
|
||||||
|
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { user } = useCurrentUser();
|
const { user } = useCurrentUser();
|
||||||
const { nostr } = useNostr();
|
const { nostr } = useNostr();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
const projectPath = `/projects/${projectId}`;
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open !== undefined) {
|
if (open !== undefined) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import {
|
|||||||
ArrowUpRight,
|
ArrowUpRight,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useGit } from '@/hooks/useGit';
|
import { useGit } from '@/hooks/useGit';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
@@ -59,8 +60,9 @@ export function BranchManager({ projectId, currentBranch, onBranchChange }: Bran
|
|||||||
const [switchingToBranch, setSwitchingToBranch] = useState<string | null>(null);
|
const [switchingToBranch, setSwitchingToBranch] = useState<string | null>(null);
|
||||||
|
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const projectPath = `/projects/${projectId}`;
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
const loadBranches = useCallback(async () => {
|
const loadBranches = useCallback(async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
|
|||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||||
import { GitCompare, Loader2, GitCommit, FileIcon } from 'lucide-react';
|
import { GitCompare, Loader2, GitCommit, FileIcon } from 'lucide-react';
|
||||||
import { useGit } from '@/hooks/useGit';
|
import { useGit } from '@/hooks/useGit';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
import { DiffViewer } from './DiffViewer';
|
import { DiffViewer } from './DiffViewer';
|
||||||
|
|
||||||
@@ -38,8 +39,9 @@ export function CompareView({ projectId }: CompareViewProps) {
|
|||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const projectPath = `/projects/${projectId}`;
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
const loadReferences = useCallback(async () => {
|
const loadReferences = useCallback(async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
Check,
|
Check,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useGit } from '@/hooks/useGit';
|
import { useGit } from '@/hooks/useGit';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
@@ -57,9 +58,10 @@ export function DiffViewer({ projectId, compareFrom = 'HEAD', compareTo, filepat
|
|||||||
const [copiedHunk, setCopiedHunk] = useState<number | null>(null);
|
const [copiedHunk, setCopiedHunk] = useState<number | null>(null);
|
||||||
|
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const projectPath = `/projects/${projectId}`;
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
const getChangedFilesBetweenRefs = useCallback(async (from: string, to: string): Promise<string[]> => {
|
const getChangedFilesBetweenRefs = useCallback(async (from: string, to: string): Promise<string[]> => {
|
||||||
// Get list of files from both refs and find differences
|
// Get list of files from both refs and find differences
|
||||||
|
|||||||
@@ -20,8 +20,9 @@ import { DiffViewer } from './DiffViewer';
|
|||||||
import { PullRequestForm } from './PullRequestForm';
|
import { PullRequestForm } from './PullRequestForm';
|
||||||
import { useGitStatus } from '@/hooks/useGitStatus';
|
import { useGitStatus } from '@/hooks/useGitStatus';
|
||||||
import { useGit } from '@/hooks/useGit';
|
import { useGit } from '@/hooks/useGit';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
|
|
||||||
interface GitManagementDialogProps {
|
interface GitManagementDialogProps{
|
||||||
projectId: string;
|
projectId: string;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
open?: boolean;
|
open?: boolean;
|
||||||
@@ -39,7 +40,8 @@ export function GitManagementDialog({
|
|||||||
const [activeTab, setActiveTab] = useState(defaultTab);
|
const [activeTab, setActiveTab] = useState(defaultTab);
|
||||||
const [remoteUrl, setRemoteUrl] = useState<string | null>(null);
|
const [remoteUrl, setRemoteUrl] = useState<string | null>(null);
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
const projectPath = `/projects/${projectId}`;
|
const { projectsPath } = useFSPaths();
|
||||||
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
const { data: gitStatus, refetch: refetchGitStatus } = useGitStatus(projectId);
|
const { data: gitStatus, refetch: refetchGitStatus } = useGitStatus(projectId);
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
AlertTriangle,
|
AlertTriangle,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useGit } from '@/hooks/useGit';
|
import { useGit } from '@/hooks/useGit';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
import { useSearchParams } from 'react-router-dom';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
@@ -77,9 +78,10 @@ export function MergeDialog({
|
|||||||
const [mergeComplete, setMergeComplete] = useState(false);
|
const [mergeComplete, setMergeComplete] = useState(false);
|
||||||
|
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const [searchParams, setSearchParams] = useSearchParams();
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
const projectPath = `/projects/${projectId}`;
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open !== undefined) {
|
if (open !== undefined) {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import {
|
|||||||
GitFork,
|
GitFork,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useGit } from '@/hooks/useGit';
|
import { useGit } from '@/hooks/useGit';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useGitSettings } from '@/hooks/useGitSettings';
|
import { useGitSettings } from '@/hooks/useGitSettings';
|
||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||||
@@ -84,12 +85,13 @@ export function PullRequestDialog({
|
|||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { settings } = useGitSettings();
|
const { settings } = useGitSettings();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { user } = useCurrentUser();
|
const { user } = useCurrentUser();
|
||||||
const { nostr } = useNostr();
|
const { nostr } = useNostr();
|
||||||
const { config } = useAppContext();
|
const { config } = useAppContext();
|
||||||
const projectPath = `/projects/${projectId}`;
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open !== undefined) {
|
if (open !== undefined) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
GitFork,
|
GitFork,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useGit } from '@/hooks/useGit';
|
import { useGit } from '@/hooks/useGit';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useGitSettings } from '@/hooks/useGitSettings';
|
import { useGitSettings } from '@/hooks/useGitSettings';
|
||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
import { findCredentialsForRepo } from '@/lib/gitCredentials';
|
import { findCredentialsForRepo } from '@/lib/gitCredentials';
|
||||||
@@ -59,9 +60,10 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq
|
|||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { settings } = useGitSettings();
|
const { settings } = useGitSettings();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const projectPath = `/projects/${projectId}`;
|
const projectPath = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
// All the helper functions from PullRequestDialog can be reused here
|
// All the helper functions from PullRequestDialog can be reused here
|
||||||
// (parseRemoteUrl, checkPushPermissions, ensureFork, etc.)
|
// (parseRemoteUrl, checkPushPermissions, ensureFork, etc.)
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ export interface AppConfig {
|
|||||||
showcaseModerator: string;
|
showcaseModerator: string;
|
||||||
/** Nostr Git Servers (hostnames) */
|
/** Nostr Git Servers (hostnames) */
|
||||||
ngitServers: string[];
|
ngitServers: string[];
|
||||||
|
/** VFS path for projects directory */
|
||||||
|
fsPathProjects: string;
|
||||||
|
/** VFS path for config directory */
|
||||||
|
fsPathConfig: string;
|
||||||
|
/** VFS path for temporary files directory */
|
||||||
|
fsPathTmp: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppContextType {
|
export interface AppContextType {
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ describe('useAIProjectId', () => {
|
|||||||
showcaseEnabled: true,
|
showcaseEnabled: true,
|
||||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||||
|
fsPathProjects: '/projects',
|
||||||
|
fsPathConfig: '/config',
|
||||||
|
fsPathTmp: '/tmp',
|
||||||
},
|
},
|
||||||
updateConfig: vi.fn(),
|
updateConfig: vi.fn(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
import { useMutation } from "@tanstack/react-query";
|
import { useMutation } from "@tanstack/react-query";
|
||||||
import { buildProject } from "@/lib/build";
|
import { buildProject } from "@/lib/build";
|
||||||
import { useFS } from "./useFS";
|
import { useFS } from "./useFS";
|
||||||
|
import { useFSPaths } from "./useFSPaths";
|
||||||
import { useAppContext } from "./useAppContext";
|
import { useAppContext } from "./useAppContext";
|
||||||
|
|
||||||
export function useBuildProject(projectId: string) {
|
export function useBuildProject(projectId: string) {
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const { config } = useAppContext();
|
const { config } = useAppContext();
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
return await buildProject({
|
return await buildProject({
|
||||||
fs,
|
fs,
|
||||||
projectPath: `/projects/${projectId}`,
|
projectPath: `${projectsPath}/${projectId}`,
|
||||||
domParser: new DOMParser(),
|
domParser: new DOMParser(),
|
||||||
esmUrl: config.esmUrl,
|
esmUrl: config.esmUrl,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { useAppContext } from '@/hooks/useAppContext';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook to access configured virtual filesystem paths
|
||||||
|
*
|
||||||
|
* @returns Object containing VFS path configurations
|
||||||
|
*/
|
||||||
|
export function useFSPaths() {
|
||||||
|
const { config } = useAppContext();
|
||||||
|
|
||||||
|
return {
|
||||||
|
/** Projects directory path (default: /projects) */
|
||||||
|
projectsPath: config.fsPathProjects,
|
||||||
|
/** Config directory path (default: /config) */
|
||||||
|
configPath: config.fsPathConfig,
|
||||||
|
/** Temporary files directory path (default: /tmp) */
|
||||||
|
tmpPath: config.fsPathTmp,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -42,6 +42,9 @@ function createWrapper(corsProxy: string) {
|
|||||||
showcaseEnabled: true,
|
showcaseEnabled: true,
|
||||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||||
|
fsPathProjects: '/projects',
|
||||||
|
fsPathConfig: '/config',
|
||||||
|
fsPathTmp: '/tmp',
|
||||||
};
|
};
|
||||||
|
|
||||||
return createElement(
|
return createElement(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useGit } from './useGit';
|
import { useGit } from './useGit';
|
||||||
|
import { useFSPaths } from './useFSPaths';
|
||||||
|
|
||||||
interface GitFileChange {
|
interface GitFileChange {
|
||||||
filepath: string;
|
filepath: string;
|
||||||
@@ -41,6 +42,7 @@ interface GitStatus {
|
|||||||
|
|
||||||
export function useGitStatus(projectId: string | null) {
|
export function useGitStatus(projectId: string | null) {
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['git-status', projectId],
|
queryKey: ['git-status', projectId],
|
||||||
@@ -61,7 +63,7 @@ export function useGitStatus(projectId: string | null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const cwd = `/projects/${projectId}`;
|
const cwd = `${projectsPath}/${projectId}`;
|
||||||
|
|
||||||
// Check if we're in a git repository
|
// Check if we're in a git repository
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useState, useEffect, useCallback } from 'react';
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
import { useFS } from './useFS';
|
import { useFS } from './useFS';
|
||||||
|
import { useFSPaths } from './useFSPaths';
|
||||||
|
|
||||||
export interface ShakespeareProjectConfig {
|
export interface ShakespeareProjectConfig {
|
||||||
type: 'shakespeare';
|
type: 'shakespeare';
|
||||||
@@ -43,10 +44,11 @@ export interface ProjectDeploySettings {
|
|||||||
*/
|
*/
|
||||||
export function useProjectDeploySettings(projectId: string) {
|
export function useProjectDeploySettings(projectId: string) {
|
||||||
const fs = useFS();
|
const fs = useFS();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
const [settings, setSettings] = useState<ProjectDeploySettings>({ providers: {} });
|
const [settings, setSettings] = useState<ProjectDeploySettings>({ providers: {} });
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
const settingsPath = `/projects/${projectId}/.git/shakespeare/deploy.json`;
|
const settingsPath = `${projectsPath}/${projectId}/.git/shakespeare/deploy.json`;
|
||||||
|
|
||||||
const loadSettings = useCallback(async () => {
|
const loadSettings = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -78,7 +80,7 @@ export function useProjectDeploySettings(projectId: string) {
|
|||||||
const saveSettings = async (newSettings: ProjectDeploySettings) => {
|
const saveSettings = async (newSettings: ProjectDeploySettings) => {
|
||||||
try {
|
try {
|
||||||
// Ensure .git/shakespeare directory exists
|
// Ensure .git/shakespeare directory exists
|
||||||
const shakespeareDir = `/projects/${projectId}/.git/shakespeare`;
|
const shakespeareDir = `${projectsPath}/${projectId}/.git/shakespeare`;
|
||||||
try {
|
try {
|
||||||
await fs.fs.stat(shakespeareDir);
|
await fs.fs.stat(shakespeareDir);
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { ProjectsManager } from '@/lib/ProjectsManager';
|
import { ProjectsManager } from '@/lib/ProjectsManager';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { useGit } from './useGit';
|
import { useGit } from './useGit';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook that provides a ProjectsManager instance.
|
* Hook that provides a ProjectsManager instance.
|
||||||
* The ProjectsManager is memoized based on the fs instance.
|
* The ProjectsManager is memoized based on the fs instance and configured paths.
|
||||||
*/
|
*/
|
||||||
export function useProjectsManager() {
|
export function useProjectsManager() {
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
|
const { projectsPath } = useFSPaths();
|
||||||
|
|
||||||
const projectsManager = useMemo(() => {
|
const projectsManager = useMemo(() => {
|
||||||
return new ProjectsManager({ fs, git });
|
return new ProjectsManager({ fs, git, projectsPath });
|
||||||
}, [fs, git]);
|
}, [fs, git, projectsPath]);
|
||||||
|
|
||||||
return projectsManager;
|
return projectsManager;
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,8 @@ export interface Project {
|
|||||||
export interface ProjectsManagerOptions {
|
export interface ProjectsManagerOptions {
|
||||||
fs: JSRuntimeFS;
|
fs: JSRuntimeFS;
|
||||||
git: Git;
|
git: Git;
|
||||||
|
/** Projects directory path (default: /projects) */
|
||||||
|
projectsPath?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ProjectsManager {
|
export class ProjectsManager {
|
||||||
@@ -29,7 +31,7 @@ export class ProjectsManager {
|
|||||||
constructor(options: ProjectsManagerOptions) {
|
constructor(options: ProjectsManagerOptions) {
|
||||||
this.fs = options.fs;
|
this.fs = options.fs;
|
||||||
this.git = options.git;
|
this.git = options.git;
|
||||||
this.dir = '/projects';
|
this.dir = options.projectsPath || '/projects';
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ export class SessionManager {
|
|||||||
private getProviderModels?: () => Array<{ id: string; provider: string; contextLength?: number; pricing?: { prompt: import('decimal.js').Decimal; completion: import('decimal.js').Decimal } }>;
|
private getProviderModels?: () => Array<{ id: string; provider: string; contextLength?: number; pricing?: { prompt: import('decimal.js').Decimal; completion: import('decimal.js').Decimal } }>;
|
||||||
private getCurrentUser?: () => { user?: NUser; metadata?: NostrMetadata };
|
private getCurrentUser?: () => { user?: NUser; metadata?: NostrMetadata };
|
||||||
private corsProxy?: string;
|
private corsProxy?: string;
|
||||||
|
private projectsPath: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
fs: JSRuntimeFS,
|
fs: JSRuntimeFS,
|
||||||
@@ -68,11 +69,13 @@ export class SessionManager {
|
|||||||
getProviderModels?: () => Array<{ id: string; provider: string; contextLength?: number; pricing?: { prompt: import('decimal.js').Decimal; completion: import('decimal.js').Decimal } }>,
|
getProviderModels?: () => Array<{ id: string; provider: string; contextLength?: number; pricing?: { prompt: import('decimal.js').Decimal; completion: import('decimal.js').Decimal } }>,
|
||||||
getCurrentUser?: () => { user?: NUser; metadata?: NostrMetadata },
|
getCurrentUser?: () => { user?: NUser; metadata?: NostrMetadata },
|
||||||
corsProxy?: string,
|
corsProxy?: string,
|
||||||
|
projectsPath = '/projects',
|
||||||
) {
|
) {
|
||||||
this.fs = fs;
|
this.fs = fs;
|
||||||
this.aiSettings = aiSettings;
|
this.aiSettings = aiSettings;
|
||||||
this.getProviderModels = getProviderModels;
|
this.getProviderModels = getProviderModels;
|
||||||
this.getCurrentUser = getCurrentUser;
|
this.getCurrentUser = getCurrentUser;
|
||||||
|
this.projectsPath = projectsPath;
|
||||||
this.corsProxy = corsProxy;
|
this.corsProxy = corsProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +93,7 @@ export class SessionManager {
|
|||||||
|
|
||||||
// Try to load existing history
|
// Try to load existing history
|
||||||
try {
|
try {
|
||||||
const dotAI = new DotAI(this.fs, `/projects/${projectId}`);
|
const dotAI = new DotAI(this.fs, `${this.projectsPath}/${projectId}`);
|
||||||
const lastSession = await dotAI.readLastSessionHistory();
|
const lastSession = await dotAI.readLastSessionHistory();
|
||||||
if (lastSession) {
|
if (lastSession) {
|
||||||
messages = lastSession.messages;
|
messages = lastSession.messages;
|
||||||
@@ -232,7 +235,7 @@ export class SessionManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const systemPrompt = await makeSystemPrompt({
|
const systemPrompt = await makeSystemPrompt({
|
||||||
cwd: `/projects/${projectId}`,
|
cwd: `${this.projectsPath}/${projectId}`,
|
||||||
fs: this.fs,
|
fs: this.fs,
|
||||||
mode: "agent",
|
mode: "agent",
|
||||||
name: "Shakespeare",
|
name: "Shakespeare",
|
||||||
@@ -568,7 +571,7 @@ export class SessionManager {
|
|||||||
if (!session) return;
|
if (!session) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const dotAI = new DotAI(this.fs, `/projects/${session.projectId}`);
|
const dotAI = new DotAI(this.fs, `${this.projectsPath}/${session.projectId}`);
|
||||||
await dotAI.setHistory(session.sessionName, session.messages);
|
await dotAI.setHistory(session.sessionName, session.messages);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('Failed to save session history:', error);
|
console.warn('Failed to save session history:', error);
|
||||||
|
|||||||
+64
-22
@@ -5,10 +5,29 @@ import type { AIProvider, AISettings } from '@/contexts/AISettingsContext';
|
|||||||
import type { GitSettings } from '@/contexts/GitSettingsContext';
|
import type { GitSettings } from '@/contexts/GitSettingsContext';
|
||||||
import type { DeployProvider, DeploySettings } from '@/contexts/DeploySettingsContext';
|
import type { DeployProvider, DeploySettings } from '@/contexts/DeploySettingsContext';
|
||||||
|
|
||||||
const CONFIG_DIR = '/config';
|
/**
|
||||||
const AI_CONFIG_PATH = `${CONFIG_DIR}/ai.json`;
|
* Get AI config file path
|
||||||
const GIT_CONFIG_PATH = `${CONFIG_DIR}/git.json`;
|
* @param configPath - Custom config path (default: /config)
|
||||||
const DEPLOY_CONFIG_PATH = `${CONFIG_DIR}/deploy.json`;
|
*/
|
||||||
|
function getAIConfigPath(configPath = '/config'): string {
|
||||||
|
return `${configPath}/ai.json`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Git config file path
|
||||||
|
* @param configPath - Custom config path (default: /config)
|
||||||
|
*/
|
||||||
|
function getGitConfigPath(configPath = '/config'): string {
|
||||||
|
return `${configPath}/git.json`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Deploy config file path
|
||||||
|
* @param configPath - Custom config path (default: /config)
|
||||||
|
*/
|
||||||
|
function getDeployConfigPath(configPath = '/config'): string {
|
||||||
|
return `${configPath}/deploy.json`;
|
||||||
|
}
|
||||||
|
|
||||||
const aiProviderSchema: z.ZodType<AIProvider> = z.object({
|
const aiProviderSchema: z.ZodType<AIProvider> = z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
@@ -91,26 +110,31 @@ const deploySettingsSchema = z.object({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures the config directory exists
|
* Ensures the config directory exists
|
||||||
|
* @param fs - Filesystem instance
|
||||||
|
* @param configPath - Custom config path (default: /config)
|
||||||
*/
|
*/
|
||||||
async function ensureConfigDir(fs: JSRuntimeFS): Promise<void> {
|
async function ensureConfigDir(fs: JSRuntimeFS, configPath = '/config'): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await fs.stat(CONFIG_DIR);
|
await fs.stat(configPath);
|
||||||
} catch {
|
} catch {
|
||||||
await fs.mkdir(CONFIG_DIR, { recursive: true });
|
await fs.mkdir(configPath, { recursive: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read AI settings from VFS
|
* Read AI settings from VFS
|
||||||
|
* @param fs - Filesystem instance
|
||||||
|
* @param configPath - Custom config path (default: /config)
|
||||||
*/
|
*/
|
||||||
export async function readAISettings(fs: JSRuntimeFS): Promise<AISettings> {
|
export async function readAISettings(fs: JSRuntimeFS, configPath = '/config'): Promise<AISettings> {
|
||||||
const defaultSettings: AISettings = {
|
const defaultSettings: AISettings = {
|
||||||
providers: [],
|
providers: [],
|
||||||
recentlyUsedModels: [],
|
recentlyUsedModels: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const content = await fs.readFile(AI_CONFIG_PATH, 'utf8');
|
const aiConfigPath = getAIConfigPath(configPath);
|
||||||
|
const content = await fs.readFile(aiConfigPath, 'utf8');
|
||||||
const data = JSON.parse(content);
|
const data = JSON.parse(content);
|
||||||
return aiSettingsSchema.parse(data);
|
return aiSettingsSchema.parse(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -123,16 +147,22 @@ export async function readAISettings(fs: JSRuntimeFS): Promise<AISettings> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Write AI settings to VFS
|
* Write AI settings to VFS
|
||||||
|
* @param fs - Filesystem instance
|
||||||
|
* @param settings - AI settings to write
|
||||||
|
* @param configPath - Custom config path (default: /config)
|
||||||
*/
|
*/
|
||||||
export async function writeAISettings(fs: JSRuntimeFS, settings: AISettings): Promise<void> {
|
export async function writeAISettings(fs: JSRuntimeFS, settings: AISettings, configPath = '/config'): Promise<void> {
|
||||||
await ensureConfigDir(fs);
|
await ensureConfigDir(fs, configPath);
|
||||||
await fs.writeFile(AI_CONFIG_PATH, JSON.stringify(settings, null, 2), 'utf8');
|
const aiConfigPath = getAIConfigPath(configPath);
|
||||||
|
await fs.writeFile(aiConfigPath, JSON.stringify(settings, null, 2), 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read Git settings from VFS
|
* Read Git settings from VFS
|
||||||
|
* @param fs - Filesystem instance
|
||||||
|
* @param configPath - Custom config path (default: /config)
|
||||||
*/
|
*/
|
||||||
export async function readGitSettings(fs: JSRuntimeFS): Promise<GitSettings> {
|
export async function readGitSettings(fs: JSRuntimeFS, configPath = '/config'): Promise<GitSettings> {
|
||||||
const defaultSettings: GitSettings = {
|
const defaultSettings: GitSettings = {
|
||||||
credentials: {},
|
credentials: {},
|
||||||
hostTokens: {},
|
hostTokens: {},
|
||||||
@@ -141,7 +171,8 @@ export async function readGitSettings(fs: JSRuntimeFS): Promise<GitSettings> {
|
|||||||
|
|
||||||
// Try to read from VFS first
|
// Try to read from VFS first
|
||||||
try {
|
try {
|
||||||
const content = await fs.readFile(GIT_CONFIG_PATH, 'utf8');
|
const gitConfigPath = getGitConfigPath(configPath);
|
||||||
|
const content = await fs.readFile(gitConfigPath, 'utf8');
|
||||||
const data = JSON.parse(content);
|
const data = JSON.parse(content);
|
||||||
const parsed = gitSettingsSchema.parse(data);
|
const parsed = gitSettingsSchema.parse(data);
|
||||||
// Ensure hostTokens exists even if not in parsed data
|
// Ensure hostTokens exists even if not in parsed data
|
||||||
@@ -156,22 +187,29 @@ export async function readGitSettings(fs: JSRuntimeFS): Promise<GitSettings> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Write Git settings to VFS
|
* Write Git settings to VFS
|
||||||
|
* @param fs - Filesystem instance
|
||||||
|
* @param settings - Git settings to write
|
||||||
|
* @param configPath - Custom config path (default: /config)
|
||||||
*/
|
*/
|
||||||
export async function writeGitSettings(fs: JSRuntimeFS, settings: GitSettings): Promise<void> {
|
export async function writeGitSettings(fs: JSRuntimeFS, settings: GitSettings, configPath = '/config'): Promise<void> {
|
||||||
await ensureConfigDir(fs);
|
await ensureConfigDir(fs, configPath);
|
||||||
await fs.writeFile(GIT_CONFIG_PATH, JSON.stringify(settings, null, 2), 'utf8');
|
const gitConfigPath = getGitConfigPath(configPath);
|
||||||
|
await fs.writeFile(gitConfigPath, JSON.stringify(settings, null, 2), 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read Deploy settings from VFS
|
* Read Deploy settings from VFS
|
||||||
|
* @param fs - Filesystem instance
|
||||||
|
* @param configPath - Custom config path (default: /config)
|
||||||
*/
|
*/
|
||||||
export async function readDeploySettings(fs: JSRuntimeFS): Promise<DeploySettings> {
|
export async function readDeploySettings(fs: JSRuntimeFS, configPath = '/config'): Promise<DeploySettings> {
|
||||||
const defaultSettings: DeploySettings = {
|
const defaultSettings: DeploySettings = {
|
||||||
providers: [],
|
providers: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const content = await fs.readFile(DEPLOY_CONFIG_PATH, 'utf8');
|
const deployConfigPath = getDeployConfigPath(configPath);
|
||||||
|
const content = await fs.readFile(deployConfigPath, 'utf8');
|
||||||
const data = JSON.parse(content);
|
const data = JSON.parse(content);
|
||||||
return deploySettingsSchema.parse(data);
|
return deploySettingsSchema.parse(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -184,9 +222,13 @@ export async function readDeploySettings(fs: JSRuntimeFS): Promise<DeploySetting
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Write Deploy settings to VFS
|
* Write Deploy settings to VFS
|
||||||
|
* @param fs - Filesystem instance
|
||||||
|
* @param settings - Deploy settings to write
|
||||||
|
* @param configPath - Custom config path (default: /config)
|
||||||
*/
|
*/
|
||||||
export async function writeDeploySettings(fs: JSRuntimeFS, settings: DeploySettings): Promise<void> {
|
export async function writeDeploySettings(fs: JSRuntimeFS, settings: DeploySettings, configPath = '/config'): Promise<void> {
|
||||||
await ensureConfigDir(fs);
|
await ensureConfigDir(fs, configPath);
|
||||||
await fs.writeFile(DEPLOY_CONFIG_PATH, JSON.stringify(settings, null, 2), 'utf8');
|
const deployConfigPath = getDeployConfigPath(configPath);
|
||||||
|
await fs.writeFile(deployConfigPath, JSON.stringify(settings, null, 2), 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,13 +46,14 @@ export async function generateUniqueFilename(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a file to the /tmp directory with deduplication
|
* Save a file to the tmp directory with deduplication
|
||||||
* @param fs - Filesystem instance
|
* @param fs - Filesystem instance
|
||||||
* @param file - File object to save
|
* @param file - File object to save
|
||||||
|
* @param tmpPath - Custom tmp path (default: /tmp)
|
||||||
* @returns Promise<string> - Full path where the file was saved
|
* @returns Promise<string> - Full path where the file was saved
|
||||||
*/
|
*/
|
||||||
export async function saveFileToTmp(fs: JSRuntimeFS, file: File): Promise<string> {
|
export async function saveFileToTmp(fs: JSRuntimeFS, file: File, tmpPath = '/tmp'): Promise<string> {
|
||||||
const tmpDir = '/tmp';
|
const tmpDir = tmpPath;
|
||||||
// Convert spaces to underscores in the filename
|
// Convert spaces to underscores in the filename
|
||||||
const sanitizedFilename = file.name.replace(/\s+/g, '_');
|
const sanitizedFilename = file.name.replace(/\s+/g, '_');
|
||||||
const uniqueFilename = await generateUniqueFilename(fs, tmpDir, sanitizedFilename);
|
const uniqueFilename = await generateUniqueFilename(fs, tmpDir, sanitizedFilename);
|
||||||
|
|||||||
+52
-16
@@ -15,12 +15,23 @@ export function isAbsolutePath(path: string): boolean {
|
|||||||
* Check if write operations are allowed for the given path
|
* Check if write operations are allowed for the given path
|
||||||
*
|
*
|
||||||
* Write operations are only allowed in:
|
* Write operations are only allowed in:
|
||||||
* - /tmp/ directory and its subdirectories
|
* - Configured tmp directory and its subdirectories
|
||||||
* - /projects/ directory and its subdirectories (project directories)
|
* - Configured projects directory and its subdirectories (project directories)
|
||||||
* - Relative paths (always allowed, regardless of where they resolve to)
|
* - Relative paths (always allowed, regardless of where they resolve to)
|
||||||
* - Absolute paths that resolve to within the current working directory
|
* - Absolute paths that resolve to within the current working directory
|
||||||
|
*
|
||||||
|
* @param path - The path to check
|
||||||
|
* @param cwd - Current working directory (optional)
|
||||||
|
* @param options - Optional configuration for allowed paths
|
||||||
*/
|
*/
|
||||||
export function isWriteAllowed(path: string, cwd?: string): boolean {
|
export function isWriteAllowed(
|
||||||
|
path: string,
|
||||||
|
cwd?: string,
|
||||||
|
options?: {
|
||||||
|
tmpPath?: string;
|
||||||
|
projectsPath?: string;
|
||||||
|
}
|
||||||
|
): boolean {
|
||||||
// Always allow relative paths (this follows traditional Unix security model)
|
// Always allow relative paths (this follows traditional Unix security model)
|
||||||
if (!isAbsolutePath(path)) {
|
if (!isAbsolutePath(path)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -29,13 +40,17 @@ export function isWriteAllowed(path: string, cwd?: string): boolean {
|
|||||||
// For absolute paths, apply restrictions
|
// For absolute paths, apply restrictions
|
||||||
const absolutePath = normalize(path);
|
const absolutePath = normalize(path);
|
||||||
|
|
||||||
// Allow writes to /tmp/ and its subdirectories
|
// Get configured paths with defaults
|
||||||
if (absolutePath.startsWith('/tmp/') || absolutePath === '/tmp') {
|
const tmpPath = options?.tmpPath || '/tmp';
|
||||||
|
const projectsPath = options?.projectsPath || '/projects';
|
||||||
|
|
||||||
|
// Allow writes to tmp directory and its subdirectories
|
||||||
|
if (absolutePath.startsWith(tmpPath + '/') || absolutePath === tmpPath) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow writes to /projects/ and its subdirectories (project directories)
|
// Allow writes to projects directory and its subdirectories (project directories)
|
||||||
if (absolutePath.startsWith('/projects/') || absolutePath === '/projects') {
|
if (absolutePath.startsWith(projectsPath + '/') || absolutePath === projectsPath) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,14 +72,24 @@ export function isWriteAllowed(path: string, cwd?: string): boolean {
|
|||||||
* @param path - The path to validate (can be absolute or relative)
|
* @param path - The path to validate (can be absolute or relative)
|
||||||
* @param operationName - Name of the operation for error messages (e.g., 'touch', 'mkdir')
|
* @param operationName - Name of the operation for error messages (e.g., 'touch', 'mkdir')
|
||||||
* @param cwd - Current working directory for context in error messages
|
* @param cwd - Current working directory for context in error messages
|
||||||
|
* @param options - Optional configuration for allowed paths
|
||||||
* @throws Error if the path is not allowed for write operations
|
* @throws Error if the path is not allowed for write operations
|
||||||
*/
|
*/
|
||||||
export function validateWritePath(path: string, operationName: string, cwd?: string): void {
|
export function validateWritePath(
|
||||||
if (!isWriteAllowed(path, cwd)) {
|
path: string,
|
||||||
|
operationName: string,
|
||||||
|
cwd?: string,
|
||||||
|
options?: {
|
||||||
|
tmpPath?: string;
|
||||||
|
projectsPath?: string;
|
||||||
|
}
|
||||||
|
): void {
|
||||||
|
if (!isWriteAllowed(path, cwd, options)) {
|
||||||
|
const tmpPath = options?.tmpPath || '/tmp';
|
||||||
const cwdInfo = cwd ? `\n\nCurrent working directory: ${cwd}` : '';
|
const cwdInfo = cwd ? `\n\nCurrent working directory: ${cwd}` : '';
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`${operationName}: write access denied to ${path}. ` +
|
`${operationName}: write access denied to ${path}. ` +
|
||||||
`Write operations are only allowed in project directories and /tmp/${cwdInfo}`
|
`Write operations are only allowed in project directories and ${tmpPath}${cwdInfo}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,23 +100,34 @@ export function validateWritePath(path: string, operationName: string, cwd?: str
|
|||||||
* @param path - The path that was denied
|
* @param path - The path that was denied
|
||||||
* @param toolName - Name of the tool/command for context
|
* @param toolName - Name of the tool/command for context
|
||||||
* @param cwd - Current working directory for context
|
* @param cwd - Current working directory for context
|
||||||
|
* @param options - Optional configuration for allowed paths
|
||||||
* @returns Formatted error message
|
* @returns Formatted error message
|
||||||
*/
|
*/
|
||||||
export function createWriteAccessDeniedError(path: string, toolName?: string, cwd?: string): string {
|
export function createWriteAccessDeniedError(
|
||||||
|
path: string,
|
||||||
|
toolName?: string,
|
||||||
|
cwd?: string,
|
||||||
|
options?: {
|
||||||
|
tmpPath?: string;
|
||||||
|
projectsPath?: string;
|
||||||
|
}
|
||||||
|
): string {
|
||||||
const prefix = toolName ? `❌ Write access denied to "${path}".` : `Write access denied to ${path}.`;
|
const prefix = toolName ? `❌ Write access denied to "${path}".` : `Write access denied to ${path}.`;
|
||||||
const cwdInfo = cwd ? `\n\nCurrent working directory: ${cwd}` : '';
|
const cwdInfo = cwd ? `\n\nCurrent working directory: ${cwd}` : '';
|
||||||
|
const tmpPath = options?.tmpPath || '/tmp';
|
||||||
|
const projectsPath = options?.projectsPath || '/projects';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
`${prefix}\n\n` +
|
`${prefix}\n\n` +
|
||||||
`Write operations are only allowed in:\n` +
|
`Write operations are only allowed in:\n` +
|
||||||
`- Current working directory and subdirectories\n` +
|
`- Current working directory and subdirectories\n` +
|
||||||
`- Project directories (/projects/ and subdirectories)\n` +
|
`- Project directories (${projectsPath}/ and subdirectories)\n` +
|
||||||
`- Temporary directory (/tmp/ and subdirectories)\n` +
|
`- Temporary directory (${tmpPath}/ and subdirectories)\n` +
|
||||||
`- Relative paths (resolved relative to current directory)\n\n` +
|
`- Relative paths (resolved relative to current directory)\n\n` +
|
||||||
`💡 Examples of allowed paths:\n` +
|
`💡 Examples of allowed paths:\n` +
|
||||||
`- "src/index.ts" (relative to current directory)\n` +
|
`- "src/index.ts" (relative to current directory)\n` +
|
||||||
`- "/projects/my-project/src/file.js" (absolute project path)\n` +
|
`- "${projectsPath}/my-project/src/file.js" (absolute project path)\n` +
|
||||||
`- "/tmp/temp-file.txt" (temporary files)\n` +
|
`- "${tmpPath}/temp-file.txt" (temporary files)\n` +
|
||||||
`- "/tmp/workspace/file.js" (temporary workspace)${cwdInfo}`
|
`- "${tmpPath}/workspace/file.js" (temporary workspace)${cwdInfo}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -62,19 +62,19 @@ async function cleanupDirectory(fs: JSRuntimeFS, dirPath: string, maxAgeMs: numb
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleans up the /tmp directory by removing files older than 1 hour
|
* Cleans up the tmp directory by removing files older than 1 hour
|
||||||
* @param fs - The filesystem instance
|
* @param fs - The filesystem instance
|
||||||
|
* @param tmpPath - Custom tmp path (default: /tmp)
|
||||||
*/
|
*/
|
||||||
export async function cleanupTmpDirectory(fs: JSRuntimeFS): Promise<void> {
|
export async function cleanupTmpDirectory(fs: JSRuntimeFS, tmpPath = '/tmp'): Promise<void> {
|
||||||
const ONE_HOUR_MS = 60 * 60 * 1000; // 1 hour in milliseconds
|
const ONE_HOUR_MS = 60 * 60 * 1000; // 1 hour in milliseconds
|
||||||
const tmpPath = '/tmp';
|
|
||||||
|
|
||||||
console.log('Starting /tmp directory cleanup...');
|
console.log(`Starting ${tmpPath} directory cleanup...`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await cleanupDirectory(fs, tmpPath, ONE_HOUR_MS);
|
await cleanupDirectory(fs, tmpPath, ONE_HOUR_MS);
|
||||||
console.log('Completed /tmp directory cleanup');
|
console.log(`Completed ${tmpPath} directory cleanup`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error during /tmp cleanup:', error);
|
console.error(`Error during ${tmpPath} cleanup:`, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,8 @@ interface TextEditorStrReplaceParams {
|
|||||||
export class TextEditorStrReplaceTool implements Tool<TextEditorStrReplaceParams> {
|
export class TextEditorStrReplaceTool implements Tool<TextEditorStrReplaceParams> {
|
||||||
private fs: JSRuntimeFS;
|
private fs: JSRuntimeFS;
|
||||||
private cwd: string;
|
private cwd: string;
|
||||||
|
private projectsPath: string;
|
||||||
|
private tmpPath: string;
|
||||||
|
|
||||||
readonly description = "Replace a string in a file with a new string";
|
readonly description = "Replace a string in a file with a new string";
|
||||||
|
|
||||||
@@ -27,17 +29,19 @@ export class TextEditorStrReplaceTool implements Tool<TextEditorStrReplaceParams
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(fs: JSRuntimeFS, cwd: string) {
|
constructor(fs: JSRuntimeFS, cwd: string, options?: { projectsPath?: string; tmpPath?: string }) {
|
||||||
this.fs = fs;
|
this.fs = fs;
|
||||||
this.cwd = cwd;
|
this.cwd = cwd;
|
||||||
|
this.projectsPath = options?.projectsPath || '/projects';
|
||||||
|
this.tmpPath = options?.tmpPath || '/tmp';
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(args: TextEditorStrReplaceParams): Promise<string> {
|
async execute(args: TextEditorStrReplaceParams): Promise<string> {
|
||||||
const { path, old_str, new_str, normalize_whitespace = true } = args;
|
const { path, old_str, new_str, normalize_whitespace = true } = args;
|
||||||
|
|
||||||
// Check write permissions
|
// Check write permissions
|
||||||
if (!isWriteAllowed(path, this.cwd)) {
|
if (!isWriteAllowed(path, this.cwd, { projectsPath: this.projectsPath, tmpPath: this.tmpPath })) {
|
||||||
throw new Error(createWriteAccessDeniedError(path, undefined, this.cwd));
|
throw new Error(createWriteAccessDeniedError(path, undefined, this.cwd, { projectsPath: this.projectsPath, tmpPath: this.tmpPath }));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ban editing dependencies in package.json
|
// Ban editing dependencies in package.json
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ interface TextEditorViewParams {
|
|||||||
export class TextEditorViewTool implements Tool<TextEditorViewParams> {
|
export class TextEditorViewTool implements Tool<TextEditorViewParams> {
|
||||||
private fs: JSRuntimeFS;
|
private fs: JSRuntimeFS;
|
||||||
private cwd: string;
|
private cwd: string;
|
||||||
|
private projectsPath: string;
|
||||||
|
|
||||||
readonly description = "View the contents of a text file or directory";
|
readonly description = "View the contents of a text file or directory";
|
||||||
|
|
||||||
@@ -28,9 +29,10 @@ export class TextEditorViewTool implements Tool<TextEditorViewParams> {
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(fs: JSRuntimeFS, cwd: string) {
|
constructor(fs: JSRuntimeFS, cwd: string, options?: { projectsPath?: string }) {
|
||||||
this.fs = fs;
|
this.fs = fs;
|
||||||
this.cwd = cwd;
|
this.cwd = cwd;
|
||||||
|
this.projectsPath = options?.projectsPath || '/projects';
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(args: TextEditorViewParams): Promise<string> {
|
async execute(args: TextEditorViewParams): Promise<string> {
|
||||||
@@ -52,9 +54,9 @@ export class TextEditorViewTool implements Tool<TextEditorViewParams> {
|
|||||||
const stats = await this.fs.stat(absolutePath);
|
const stats = await this.fs.stat(absolutePath);
|
||||||
|
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
// Special handling for /projects directory - only show project directories, not their contents
|
// Special handling for projects directory - only show project directories, not their contents
|
||||||
const normalizedPath = absolutePath.replace(/\/$/, ''); // Remove trailing slash
|
const normalizedPath = absolutePath.replace(/\/$/, ''); // Remove trailing slash
|
||||||
if (normalizedPath === '/projects') {
|
if (normalizedPath === this.projectsPath) {
|
||||||
const tree = await this.generateDirectoryTree(absolutePath, "", 1); // Only show immediate children
|
const tree = await this.generateDirectoryTree(absolutePath, "", 1); // Only show immediate children
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ interface TextEditorWriteParams {
|
|||||||
export class TextEditorWriteTool implements Tool<TextEditorWriteParams> {
|
export class TextEditorWriteTool implements Tool<TextEditorWriteParams> {
|
||||||
private fs: JSRuntimeFS;
|
private fs: JSRuntimeFS;
|
||||||
private cwd: string;
|
private cwd: string;
|
||||||
|
private projectsPath: string;
|
||||||
|
private tmpPath: string;
|
||||||
|
|
||||||
readonly description = "Create or overwrite a file with new content";
|
readonly description = "Create or overwrite a file with new content";
|
||||||
|
|
||||||
@@ -23,17 +25,19 @@ export class TextEditorWriteTool implements Tool<TextEditorWriteParams> {
|
|||||||
file_text: z.string().describe("Content to write to the file"),
|
file_text: z.string().describe("Content to write to the file"),
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(fs: JSRuntimeFS, cwd: string) {
|
constructor(fs: JSRuntimeFS, cwd: string, options?: { projectsPath?: string; tmpPath?: string }) {
|
||||||
this.fs = fs;
|
this.fs = fs;
|
||||||
this.cwd = cwd;
|
this.cwd = cwd;
|
||||||
|
this.projectsPath = options?.projectsPath || '/projects';
|
||||||
|
this.tmpPath = options?.tmpPath || '/tmp';
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(args: TextEditorWriteParams): Promise<string> {
|
async execute(args: TextEditorWriteParams): Promise<string> {
|
||||||
const { path, file_text } = args;
|
const { path, file_text } = args;
|
||||||
|
|
||||||
// Check write permissions
|
// Check write permissions
|
||||||
if (!isWriteAllowed(path, this.cwd)) {
|
if (!isWriteAllowed(path, this.cwd, { projectsPath: this.projectsPath, tmpPath: this.tmpPath })) {
|
||||||
throw new Error(createWriteAccessDeniedError(path, undefined, this.cwd));
|
throw new Error(createWriteAccessDeniedError(path, undefined, this.cwd, { projectsPath: this.projectsPath, tmpPath: this.tmpPath }));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
+1
-1
@@ -236,7 +236,7 @@ export default function Index() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store the initial message in chat history using DotAI
|
// Store the initial message in chat history using DotAI
|
||||||
const dotAI = new DotAI(fs, `/projects/${project.id}`);
|
const dotAI = new DotAI(fs, `${config.fsPathProjects}/${project.id}`);
|
||||||
const sessionName = DotAI.generateSessionName();
|
const sessionName = DotAI.generateSessionName();
|
||||||
|
|
||||||
// Create initial message with content parts (same format as ChatPane)
|
// Create initial message with content parts (same format as ChatPane)
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ export function SystemSettings() {
|
|||||||
const [faviconUrlInput, setFaviconUrlInput] = useState(config.faviconUrl);
|
const [faviconUrlInput, setFaviconUrlInput] = useState(config.faviconUrl);
|
||||||
const [previewDomainInput, setPreviewDomainInput] = useState(config.previewDomain);
|
const [previewDomainInput, setPreviewDomainInput] = useState(config.previewDomain);
|
||||||
const [showcaseModeratorInput, setShowcaseModeratorInput] = useState(config.showcaseModerator);
|
const [showcaseModeratorInput, setShowcaseModeratorInput] = useState(config.showcaseModerator);
|
||||||
|
const [fsPathProjectsInput, setFsPathProjectsInput] = useState(config.fsPathProjects);
|
||||||
|
const [fsPathConfigInput, setFsPathConfigInput] = useState(config.fsPathConfig);
|
||||||
|
const [fsPathTmpInput, setFsPathTmpInput] = useState(config.fsPathTmp);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-6 space-y-6">
|
||||||
@@ -264,6 +267,87 @@ export function SystemSettings() {
|
|||||||
</AccordionContent>
|
</AccordionContent>
|
||||||
</AccordionItem>
|
</AccordionItem>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
|
{/* Filesystem Paths Configuration */}
|
||||||
|
<Accordion type="single" collapsible className="w-full">
|
||||||
|
<AccordionItem value="filesystem-paths" className="border rounded-lg">
|
||||||
|
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||||
|
<h4 className="text-sm font-medium">Filesystem Paths</h4>
|
||||||
|
</AccordionTrigger>
|
||||||
|
<AccordionContent className="px-4 pb-4">
|
||||||
|
<div className="py-1 space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="fs-path-projects" className="text-sm font-medium">
|
||||||
|
Projects Directory
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="fs-path-projects"
|
||||||
|
type="text"
|
||||||
|
placeholder="/projects"
|
||||||
|
value={fsPathProjectsInput}
|
||||||
|
onChange={(e) => {
|
||||||
|
const value = e.target.value;
|
||||||
|
setFsPathProjectsInput(value);
|
||||||
|
updateConfig((current) => ({
|
||||||
|
...current,
|
||||||
|
fsPathProjects: value,
|
||||||
|
}));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Filesystem path where projects are stored
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="fs-path-config" className="text-sm font-medium">
|
||||||
|
Config Directory
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="fs-path-config"
|
||||||
|
type="text"
|
||||||
|
placeholder="/config"
|
||||||
|
value={fsPathConfigInput}
|
||||||
|
onChange={(e) => {
|
||||||
|
const value = e.target.value;
|
||||||
|
setFsPathConfigInput(value);
|
||||||
|
updateConfig((current) => ({
|
||||||
|
...current,
|
||||||
|
fsPathConfig: value,
|
||||||
|
}));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Filesystem path where configuration files are stored
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="fs-path-tmp" className="text-sm font-medium">
|
||||||
|
Temporary Directory
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="fs-path-tmp"
|
||||||
|
type="text"
|
||||||
|
placeholder="/tmp"
|
||||||
|
value={fsPathTmpInput}
|
||||||
|
onChange={(e) => {
|
||||||
|
const value = e.target.value;
|
||||||
|
setFsPathTmpInput(value);
|
||||||
|
updateConfig((current) => ({
|
||||||
|
...current,
|
||||||
|
fsPathTmp: value,
|
||||||
|
}));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Filesystem path for temporary files
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</AccordionContent>
|
||||||
|
</AccordionItem>
|
||||||
|
</Accordion>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ export function TestApp({ children }: TestAppProps) {
|
|||||||
showcaseEnabled: true,
|
showcaseEnabled: true,
|
||||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||||
|
fsPathProjects: '/projects',
|
||||||
|
fsPathConfig: '/config',
|
||||||
|
fsPathTmp: '/tmp',
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize LightningFS for testing
|
// Initialize LightningFS for testing
|
||||||
|
|||||||
Reference in new issue
Block a user