mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-07-03 20:41:07 +02:00
move to a page for background agents
This commit is contained in:
parent
697a43ebbc
commit
d8e33afcc8
6 changed files with 507 additions and 191 deletions
|
|
@ -53,6 +53,7 @@ import { API_URL } from '@x/core/dist/config/env.js';
|
||||||
import {
|
import {
|
||||||
fetchYaml,
|
fetchYaml,
|
||||||
listNotesWithTracks,
|
listNotesWithTracks,
|
||||||
|
setNoteTracksActive,
|
||||||
updateTrackBlock,
|
updateTrackBlock,
|
||||||
replaceTrackBlockYaml,
|
replaceTrackBlockYaml,
|
||||||
deleteTrackBlock,
|
deleteTrackBlock,
|
||||||
|
|
@ -136,6 +137,14 @@ function resolveShellPath(filePath: string): string {
|
||||||
return workspace.resolveWorkspacePath(filePath);
|
return workspace.resolveWorkspacePath(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toKnowledgeTrackPath(filePath: string): string {
|
||||||
|
const normalized = filePath.replace(/\\/g, '/').replace(/^\/+/, '');
|
||||||
|
if (!normalized.startsWith('knowledge/')) {
|
||||||
|
throw new Error('Track note path must be within knowledge/')
|
||||||
|
}
|
||||||
|
return normalized.slice('knowledge/'.length)
|
||||||
|
}
|
||||||
|
|
||||||
type InvokeChannels = ipc.InvokeChannels;
|
type InvokeChannels = ipc.InvokeChannels;
|
||||||
type IPCChannels = ipc.IPCChannels;
|
type IPCChannels = ipc.IPCChannels;
|
||||||
|
|
||||||
|
|
@ -833,6 +842,15 @@ export function setupIpcHandlers() {
|
||||||
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
'track:setNoteActive': async (_event, args) => {
|
||||||
|
try {
|
||||||
|
const note = await setNoteTracksActive(toKnowledgeTrackPath(args.path), args.active);
|
||||||
|
if (!note) return { success: false, error: 'No track blocks found in note' };
|
||||||
|
return { success: true, note };
|
||||||
|
} catch (err) {
|
||||||
|
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
||||||
|
}
|
||||||
|
},
|
||||||
'track:listNotes': async () => {
|
'track:listNotes': async () => {
|
||||||
const notes = await listNotesWithTracks();
|
const notes = await listNotesWithTracks();
|
||||||
return { notes };
|
return { notes };
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import { BasesView, type BaseConfig, DEFAULT_BASE_CONFIG } from '@/components/ba
|
||||||
import { useDebounce } from './hooks/use-debounce';
|
import { useDebounce } from './hooks/use-debounce';
|
||||||
import { SidebarContentPanel } from '@/components/sidebar-content';
|
import { SidebarContentPanel } from '@/components/sidebar-content';
|
||||||
import { SuggestedTopicsView } from '@/components/suggested-topics-view';
|
import { SuggestedTopicsView } from '@/components/suggested-topics-view';
|
||||||
|
import { BackgroundAgentsView } from '@/components/background-agents-view';
|
||||||
import { SidebarSectionProvider } from '@/contexts/sidebar-context';
|
import { SidebarSectionProvider } from '@/contexts/sidebar-context';
|
||||||
import {
|
import {
|
||||||
Conversation,
|
Conversation,
|
||||||
|
|
@ -142,6 +143,7 @@ const TITLEBAR_BUTTONS_COLLAPSED = 1
|
||||||
const TITLEBAR_BUTTON_GAPS_COLLAPSED = 0
|
const TITLEBAR_BUTTON_GAPS_COLLAPSED = 0
|
||||||
const GRAPH_TAB_PATH = '__rowboat_graph_view__'
|
const GRAPH_TAB_PATH = '__rowboat_graph_view__'
|
||||||
const SUGGESTED_TOPICS_TAB_PATH = '__rowboat_suggested_topics__'
|
const SUGGESTED_TOPICS_TAB_PATH = '__rowboat_suggested_topics__'
|
||||||
|
const BACKGROUND_AGENTS_TAB_PATH = '__rowboat_background_agents__'
|
||||||
const BASES_DEFAULT_TAB_PATH = '__rowboat_bases_default__'
|
const BASES_DEFAULT_TAB_PATH = '__rowboat_bases_default__'
|
||||||
|
|
||||||
const clampNumber = (value: number, min: number, max: number) =>
|
const clampNumber = (value: number, min: number, max: number) =>
|
||||||
|
|
@ -271,6 +273,7 @@ const getAncestorDirectoryPaths = (path: string): string[] => {
|
||||||
|
|
||||||
const isGraphTabPath = (path: string) => path === GRAPH_TAB_PATH
|
const isGraphTabPath = (path: string) => path === GRAPH_TAB_PATH
|
||||||
const isSuggestedTopicsTabPath = (path: string) => path === SUGGESTED_TOPICS_TAB_PATH
|
const isSuggestedTopicsTabPath = (path: string) => path === SUGGESTED_TOPICS_TAB_PATH
|
||||||
|
const isBackgroundAgentsTabPath = (path: string) => path === BACKGROUND_AGENTS_TAB_PATH
|
||||||
const isBaseFilePath = (path: string) => path.endsWith('.base') || path === BASES_DEFAULT_TAB_PATH
|
const isBaseFilePath = (path: string) => path.endsWith('.base') || path === BASES_DEFAULT_TAB_PATH
|
||||||
|
|
||||||
const getSuggestedTopicTargetFolder = (category?: string) => {
|
const getSuggestedTopicTargetFolder = (category?: string) => {
|
||||||
|
|
@ -508,6 +511,7 @@ type ViewState =
|
||||||
| { type: 'graph' }
|
| { type: 'graph' }
|
||||||
| { type: 'task'; name: string }
|
| { type: 'task'; name: string }
|
||||||
| { type: 'suggested-topics' }
|
| { type: 'suggested-topics' }
|
||||||
|
| { type: 'background-agents' }
|
||||||
|
|
||||||
function viewStatesEqual(a: ViewState, b: ViewState): boolean {
|
function viewStatesEqual(a: ViewState, b: ViewState): boolean {
|
||||||
if (a.type !== b.type) return false
|
if (a.type !== b.type) return false
|
||||||
|
|
@ -521,12 +525,13 @@ function viewStatesEqual(a: ViewState, b: ViewState): boolean {
|
||||||
* Parse a rowboat:// deep link into a ViewState. Returns null if the URL is
|
* Parse a rowboat:// deep link into a ViewState. Returns null if the URL is
|
||||||
* malformed or names an unknown target.
|
* malformed or names an unknown target.
|
||||||
*
|
*
|
||||||
* Shape: rowboat://open?type=<file|chat|graph|task|suggested-topics>&...
|
* Shape: rowboat://open?type=<file|chat|graph|task|suggested-topics|background-agents>&...
|
||||||
* file: ?type=file&path=knowledge/foo.md
|
* file: ?type=file&path=knowledge/foo.md
|
||||||
* chat: ?type=chat&runId=abc123 (runId optional)
|
* chat: ?type=chat&runId=abc123 (runId optional)
|
||||||
* graph: ?type=graph
|
* graph: ?type=graph
|
||||||
* task: ?type=task&name=daily-brief
|
* task: ?type=task&name=daily-brief
|
||||||
* suggested-topics: ?type=suggested-topics
|
* suggested-topics: ?type=suggested-topics
|
||||||
|
* background-agents: ?type=background-agents
|
||||||
*/
|
*/
|
||||||
function parseDeepLink(input: string): ViewState | null {
|
function parseDeepLink(input: string): ViewState | null {
|
||||||
const SCHEME = 'rowboat://'
|
const SCHEME = 'rowboat://'
|
||||||
|
|
@ -551,6 +556,8 @@ function parseDeepLink(input: string): ViewState | null {
|
||||||
}
|
}
|
||||||
case 'suggested-topics':
|
case 'suggested-topics':
|
||||||
return { type: 'suggested-topics' }
|
return { type: 'suggested-topics' }
|
||||||
|
case 'background-agents':
|
||||||
|
return { type: 'background-agents' }
|
||||||
default:
|
default:
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
@ -656,7 +663,13 @@ function App() {
|
||||||
const [isGraphOpen, setIsGraphOpen] = useState(false)
|
const [isGraphOpen, setIsGraphOpen] = useState(false)
|
||||||
const [isBrowserOpen, setIsBrowserOpen] = useState(false)
|
const [isBrowserOpen, setIsBrowserOpen] = useState(false)
|
||||||
const [isSuggestedTopicsOpen, setIsSuggestedTopicsOpen] = useState(false)
|
const [isSuggestedTopicsOpen, setIsSuggestedTopicsOpen] = useState(false)
|
||||||
const [expandedFrom, setExpandedFrom] = useState<{ path: string | null; graph: boolean; suggestedTopics: boolean } | null>(null)
|
const [isBackgroundAgentsOpen, setIsBackgroundAgentsOpen] = useState(false)
|
||||||
|
const [expandedFrom, setExpandedFrom] = useState<{
|
||||||
|
path: string | null
|
||||||
|
graph: boolean
|
||||||
|
suggestedTopics: boolean
|
||||||
|
backgroundAgents: boolean
|
||||||
|
} | null>(null)
|
||||||
const [baseConfigByPath, setBaseConfigByPath] = useState<Record<string, BaseConfig>>({})
|
const [baseConfigByPath, setBaseConfigByPath] = useState<Record<string, BaseConfig>>({})
|
||||||
const [graphData, setGraphData] = useState<{ nodes: GraphNode[]; edges: GraphEdge[] }>({
|
const [graphData, setGraphData] = useState<{ nodes: GraphNode[]; edges: GraphEdge[] }>({
|
||||||
nodes: [],
|
nodes: [],
|
||||||
|
|
@ -977,6 +990,7 @@ function App() {
|
||||||
const getFileTabTitle = useCallback((tab: FileTab) => {
|
const getFileTabTitle = useCallback((tab: FileTab) => {
|
||||||
if (isGraphTabPath(tab.path)) return 'Graph View'
|
if (isGraphTabPath(tab.path)) return 'Graph View'
|
||||||
if (isSuggestedTopicsTabPath(tab.path)) return 'Suggested Topics'
|
if (isSuggestedTopicsTabPath(tab.path)) return 'Suggested Topics'
|
||||||
|
if (isBackgroundAgentsTabPath(tab.path)) return 'Background agents'
|
||||||
if (tab.path === BASES_DEFAULT_TAB_PATH) return 'Bases'
|
if (tab.path === BASES_DEFAULT_TAB_PATH) return 'Bases'
|
||||||
if (tab.path.endsWith('.base')) return tab.path.split('/').pop()?.replace(/\.base$/i, '') || 'Base'
|
if (tab.path.endsWith('.base')) return tab.path.split('/').pop()?.replace(/\.base$/i, '') || 'Base'
|
||||||
return tab.path.split('/').pop()?.replace(/\.md$/i, '') || tab.path
|
return tab.path.split('/').pop()?.replace(/\.md$/i, '') || tab.path
|
||||||
|
|
@ -2660,6 +2674,8 @@ function App() {
|
||||||
if (existingTab) {
|
if (existingTab) {
|
||||||
setActiveFileTabId(existingTab.id)
|
setActiveFileTabId(existingTab.id)
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
setSelectedPath(path)
|
setSelectedPath(path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -2667,6 +2683,8 @@ function App() {
|
||||||
setFileTabs(prev => [...prev, { id, path }])
|
setFileTabs(prev => [...prev, { id, path }])
|
||||||
setActiveFileTabId(id)
|
setActiveFileTabId(id)
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
setSelectedPath(path)
|
setSelectedPath(path)
|
||||||
}, [fileTabs, dismissBrowserOverlay])
|
}, [fileTabs, dismissBrowserOverlay])
|
||||||
|
|
||||||
|
|
@ -2685,16 +2703,26 @@ function App() {
|
||||||
setSelectedPath(null)
|
setSelectedPath(null)
|
||||||
setIsGraphOpen(true)
|
setIsGraphOpen(true)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (isSuggestedTopicsTabPath(tab.path)) {
|
if (isSuggestedTopicsTabPath(tab.path)) {
|
||||||
setSelectedPath(null)
|
setSelectedPath(null)
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
setIsSuggestedTopicsOpen(true)
|
setIsSuggestedTopicsOpen(true)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (isBackgroundAgentsTabPath(tab.path)) {
|
||||||
|
setSelectedPath(null)
|
||||||
|
setIsGraphOpen(false)
|
||||||
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
setSelectedPath(tab.path)
|
setSelectedPath(tab.path)
|
||||||
}, [fileTabs, isRightPaneMaximized, dismissBrowserOverlay])
|
}, [fileTabs, isRightPaneMaximized, dismissBrowserOverlay])
|
||||||
|
|
||||||
|
|
@ -2723,6 +2751,7 @@ function App() {
|
||||||
setSelectedPath(null)
|
setSelectedPath(null)
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
const idx = prev.findIndex(t => t.id === tabId)
|
const idx = prev.findIndex(t => t.id === tabId)
|
||||||
|
|
@ -2736,13 +2765,21 @@ function App() {
|
||||||
setSelectedPath(null)
|
setSelectedPath(null)
|
||||||
setIsGraphOpen(true)
|
setIsGraphOpen(true)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
} else if (isSuggestedTopicsTabPath(newActiveTab.path)) {
|
} else if (isSuggestedTopicsTabPath(newActiveTab.path)) {
|
||||||
setSelectedPath(null)
|
setSelectedPath(null)
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
setIsSuggestedTopicsOpen(true)
|
setIsSuggestedTopicsOpen(true)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
|
} else if (isBackgroundAgentsTabPath(newActiveTab.path)) {
|
||||||
|
setSelectedPath(null)
|
||||||
|
setIsGraphOpen(false)
|
||||||
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(true)
|
||||||
} else {
|
} else {
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
setSelectedPath(newActiveTab.path)
|
setSelectedPath(newActiveTab.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2773,8 +2810,13 @@ function App() {
|
||||||
dismissBrowserOverlay()
|
dismissBrowserOverlay()
|
||||||
handleNewChat()
|
handleNewChat()
|
||||||
// Left-pane "new chat" should always open full chat view.
|
// Left-pane "new chat" should always open full chat view.
|
||||||
if (selectedPath || isGraphOpen || isSuggestedTopicsOpen) {
|
if (selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBackgroundAgentsOpen) {
|
||||||
setExpandedFrom({ path: selectedPath, graph: isGraphOpen, suggestedTopics: isSuggestedTopicsOpen })
|
setExpandedFrom({
|
||||||
|
path: selectedPath,
|
||||||
|
graph: isGraphOpen,
|
||||||
|
suggestedTopics: isSuggestedTopicsOpen,
|
||||||
|
backgroundAgents: isBackgroundAgentsOpen,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
setExpandedFrom(null)
|
setExpandedFrom(null)
|
||||||
}
|
}
|
||||||
|
|
@ -2782,7 +2824,8 @@ function App() {
|
||||||
setSelectedPath(null)
|
setSelectedPath(null)
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
}, [chatTabs, activeChatTabId, dismissBrowserOverlay, handleNewChat, selectedPath, isGraphOpen, isSuggestedTopicsOpen])
|
setIsBackgroundAgentsOpen(false)
|
||||||
|
}, [chatTabs, activeChatTabId, dismissBrowserOverlay, handleNewChat, selectedPath, isGraphOpen, isSuggestedTopicsOpen, isBackgroundAgentsOpen])
|
||||||
|
|
||||||
// Sidebar variant: create/switch chat tab without leaving file/graph context.
|
// Sidebar variant: create/switch chat tab without leaving file/graph context.
|
||||||
const handleNewChatTabInSidebar = useCallback(() => {
|
const handleNewChatTabInSidebar = useCallback(() => {
|
||||||
|
|
@ -2897,27 +2940,40 @@ function App() {
|
||||||
|
|
||||||
const handleOpenFullScreenChat = useCallback(() => {
|
const handleOpenFullScreenChat = useCallback(() => {
|
||||||
// Remember where we came from so the close button can return
|
// Remember where we came from so the close button can return
|
||||||
if (selectedPath || isGraphOpen || isSuggestedTopicsOpen) {
|
if (selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBackgroundAgentsOpen) {
|
||||||
setExpandedFrom({ path: selectedPath, graph: isGraphOpen, suggestedTopics: isSuggestedTopicsOpen })
|
setExpandedFrom({
|
||||||
|
path: selectedPath,
|
||||||
|
graph: isGraphOpen,
|
||||||
|
suggestedTopics: isSuggestedTopicsOpen,
|
||||||
|
backgroundAgents: isBackgroundAgentsOpen,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
dismissBrowserOverlay()
|
dismissBrowserOverlay()
|
||||||
setIsRightPaneMaximized(false)
|
setIsRightPaneMaximized(false)
|
||||||
setSelectedPath(null)
|
setSelectedPath(null)
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
}, [selectedPath, isGraphOpen, isSuggestedTopicsOpen, dismissBrowserOverlay])
|
setIsBackgroundAgentsOpen(false)
|
||||||
|
}, [selectedPath, isGraphOpen, isSuggestedTopicsOpen, isBackgroundAgentsOpen, dismissBrowserOverlay])
|
||||||
|
|
||||||
const handleCloseFullScreenChat = useCallback(() => {
|
const handleCloseFullScreenChat = useCallback(() => {
|
||||||
if (expandedFrom) {
|
if (expandedFrom) {
|
||||||
if (expandedFrom.graph) {
|
if (expandedFrom.graph) {
|
||||||
setIsGraphOpen(true)
|
setIsGraphOpen(true)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
} else if (expandedFrom.suggestedTopics) {
|
} else if (expandedFrom.suggestedTopics) {
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
setIsSuggestedTopicsOpen(true)
|
setIsSuggestedTopicsOpen(true)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
|
} else if (expandedFrom.backgroundAgents) {
|
||||||
|
setIsGraphOpen(false)
|
||||||
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(true)
|
||||||
} else if (expandedFrom.path) {
|
} else if (expandedFrom.path) {
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
setSelectedPath(expandedFrom.path)
|
setSelectedPath(expandedFrom.path)
|
||||||
}
|
}
|
||||||
setExpandedFrom(null)
|
setExpandedFrom(null)
|
||||||
|
|
@ -2927,11 +2983,12 @@ function App() {
|
||||||
|
|
||||||
const currentViewState = React.useMemo<ViewState>(() => {
|
const currentViewState = React.useMemo<ViewState>(() => {
|
||||||
if (selectedBackgroundTask) return { type: 'task', name: selectedBackgroundTask }
|
if (selectedBackgroundTask) return { type: 'task', name: selectedBackgroundTask }
|
||||||
|
if (isBackgroundAgentsOpen) return { type: 'background-agents' }
|
||||||
if (isSuggestedTopicsOpen) return { type: 'suggested-topics' }
|
if (isSuggestedTopicsOpen) return { type: 'suggested-topics' }
|
||||||
if (selectedPath) return { type: 'file', path: selectedPath }
|
if (selectedPath) return { type: 'file', path: selectedPath }
|
||||||
if (isGraphOpen) return { type: 'graph' }
|
if (isGraphOpen) return { type: 'graph' }
|
||||||
return { type: 'chat', runId }
|
return { type: 'chat', runId }
|
||||||
}, [selectedBackgroundTask, isSuggestedTopicsOpen, selectedPath, isGraphOpen, runId])
|
}, [selectedBackgroundTask, isBackgroundAgentsOpen, isSuggestedTopicsOpen, selectedPath, isGraphOpen, runId])
|
||||||
|
|
||||||
const appendUnique = useCallback((stack: ViewState[], entry: ViewState) => {
|
const appendUnique = useCallback((stack: ViewState[], entry: ViewState) => {
|
||||||
const last = stack[stack.length - 1]
|
const last = stack[stack.length - 1]
|
||||||
|
|
@ -2988,6 +3045,17 @@ function App() {
|
||||||
setActiveFileTabId(id)
|
setActiveFileTabId(id)
|
||||||
}, [fileTabs])
|
}, [fileTabs])
|
||||||
|
|
||||||
|
const ensureBackgroundAgentsFileTab = useCallback(() => {
|
||||||
|
const existing = fileTabs.find((tab) => isBackgroundAgentsTabPath(tab.path))
|
||||||
|
if (existing) {
|
||||||
|
setActiveFileTabId(existing.id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const id = newFileTabId()
|
||||||
|
setFileTabs((prev) => [...prev, { id, path: BACKGROUND_AGENTS_TAB_PATH }])
|
||||||
|
setActiveFileTabId(id)
|
||||||
|
}, [fileTabs])
|
||||||
|
|
||||||
const applyViewState = useCallback(async (view: ViewState) => {
|
const applyViewState = useCallback(async (view: ViewState) => {
|
||||||
switch (view.type) {
|
switch (view.type) {
|
||||||
case 'file':
|
case 'file':
|
||||||
|
|
@ -2997,6 +3065,7 @@ function App() {
|
||||||
// visible in the middle pane.
|
// visible in the middle pane.
|
||||||
setIsBrowserOpen(false)
|
setIsBrowserOpen(false)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
setExpandedFrom(null)
|
setExpandedFrom(null)
|
||||||
// Preserve split vs knowledge-max mode when navigating knowledge files.
|
// Preserve split vs knowledge-max mode when navigating knowledge files.
|
||||||
// Only exit chat-only maximize, because that would hide the selected file.
|
// Only exit chat-only maximize, because that would hide the selected file.
|
||||||
|
|
@ -3011,6 +3080,7 @@ function App() {
|
||||||
setSelectedPath(null)
|
setSelectedPath(null)
|
||||||
setIsBrowserOpen(false)
|
setIsBrowserOpen(false)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
setExpandedFrom(null)
|
setExpandedFrom(null)
|
||||||
setIsGraphOpen(true)
|
setIsGraphOpen(true)
|
||||||
ensureGraphFileTab()
|
ensureGraphFileTab()
|
||||||
|
|
@ -3023,6 +3093,7 @@ function App() {
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
setIsBrowserOpen(false)
|
setIsBrowserOpen(false)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
setExpandedFrom(null)
|
setExpandedFrom(null)
|
||||||
setIsRightPaneMaximized(false)
|
setIsRightPaneMaximized(false)
|
||||||
setSelectedBackgroundTask(view.name)
|
setSelectedBackgroundTask(view.name)
|
||||||
|
|
@ -3035,8 +3106,20 @@ function App() {
|
||||||
setIsRightPaneMaximized(false)
|
setIsRightPaneMaximized(false)
|
||||||
setSelectedBackgroundTask(null)
|
setSelectedBackgroundTask(null)
|
||||||
setIsSuggestedTopicsOpen(true)
|
setIsSuggestedTopicsOpen(true)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
ensureSuggestedTopicsFileTab()
|
ensureSuggestedTopicsFileTab()
|
||||||
return
|
return
|
||||||
|
case 'background-agents':
|
||||||
|
setSelectedPath(null)
|
||||||
|
setIsGraphOpen(false)
|
||||||
|
setIsBrowserOpen(false)
|
||||||
|
setExpandedFrom(null)
|
||||||
|
setIsRightPaneMaximized(false)
|
||||||
|
setSelectedBackgroundTask(null)
|
||||||
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(true)
|
||||||
|
ensureBackgroundAgentsFileTab()
|
||||||
|
return
|
||||||
case 'chat':
|
case 'chat':
|
||||||
setSelectedPath(null)
|
setSelectedPath(null)
|
||||||
setIsGraphOpen(false)
|
setIsGraphOpen(false)
|
||||||
|
|
@ -3045,6 +3128,7 @@ function App() {
|
||||||
setIsRightPaneMaximized(false)
|
setIsRightPaneMaximized(false)
|
||||||
setSelectedBackgroundTask(null)
|
setSelectedBackgroundTask(null)
|
||||||
setIsSuggestedTopicsOpen(false)
|
setIsSuggestedTopicsOpen(false)
|
||||||
|
setIsBackgroundAgentsOpen(false)
|
||||||
if (view.runId) {
|
if (view.runId) {
|
||||||
await loadRun(view.runId)
|
await loadRun(view.runId)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -3052,7 +3136,7 @@ function App() {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}, [ensureFileTabForPath, ensureGraphFileTab, ensureSuggestedTopicsFileTab, handleNewChat, isRightPaneMaximized, loadRun])
|
}, [ensureBackgroundAgentsFileTab, ensureFileTabForPath, ensureGraphFileTab, ensureSuggestedTopicsFileTab, handleNewChat, isRightPaneMaximized, loadRun])
|
||||||
|
|
||||||
const navigateToView = useCallback(async (nextView: ViewState) => {
|
const navigateToView = useCallback(async (nextView: ViewState) => {
|
||||||
const current = currentViewState
|
const current = currentViewState
|
||||||
|
|
@ -3374,7 +3458,7 @@ function App() {
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Keyboard shortcut: Ctrl+L to toggle main chat view
|
// Keyboard shortcut: Ctrl+L to toggle main chat view
|
||||||
const isFullScreenChat = !selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !selectedBackgroundTask && !isBrowserOpen
|
const isFullScreenChat = !selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !isBackgroundAgentsOpen && !selectedBackgroundTask && !isBrowserOpen
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleKeyDown = (e: KeyboardEvent) => {
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
if ((e.ctrlKey || e.metaKey) && e.key === 'l') {
|
if ((e.ctrlKey || e.metaKey) && e.key === 'l') {
|
||||||
|
|
@ -3452,15 +3536,17 @@ function App() {
|
||||||
const handleTabKeyDown = (e: KeyboardEvent) => {
|
const handleTabKeyDown = (e: KeyboardEvent) => {
|
||||||
const mod = e.metaKey || e.ctrlKey
|
const mod = e.metaKey || e.ctrlKey
|
||||||
if (!mod) return
|
if (!mod) return
|
||||||
const rightPaneAvailable = Boolean((selectedPath || isGraphOpen || isSuggestedTopicsOpen) && isChatSidebarOpen)
|
const rightPaneAvailable = Boolean((selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBackgroundAgentsOpen) && isChatSidebarOpen)
|
||||||
const targetPane: ShortcutPane = rightPaneAvailable
|
const targetPane: ShortcutPane = rightPaneAvailable
|
||||||
? (isRightPaneMaximized ? 'right' : activeShortcutPane)
|
? (isRightPaneMaximized ? 'right' : activeShortcutPane)
|
||||||
: 'left'
|
: 'left'
|
||||||
const inFileView = targetPane === 'left' && Boolean(selectedPath || isGraphOpen || isSuggestedTopicsOpen)
|
const inFileView = targetPane === 'left' && Boolean(selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBackgroundAgentsOpen)
|
||||||
const selectedKnowledgePath = isGraphOpen
|
const selectedKnowledgePath = isGraphOpen
|
||||||
? GRAPH_TAB_PATH
|
? GRAPH_TAB_PATH
|
||||||
: isSuggestedTopicsOpen
|
: isSuggestedTopicsOpen
|
||||||
? SUGGESTED_TOPICS_TAB_PATH
|
? SUGGESTED_TOPICS_TAB_PATH
|
||||||
|
: isBackgroundAgentsOpen
|
||||||
|
? BACKGROUND_AGENTS_TAB_PATH
|
||||||
: selectedPath
|
: selectedPath
|
||||||
const targetFileTabId = activeFileTabId ?? (
|
const targetFileTabId = activeFileTabId ?? (
|
||||||
selectedKnowledgePath
|
selectedKnowledgePath
|
||||||
|
|
@ -3515,7 +3601,7 @@ function App() {
|
||||||
}
|
}
|
||||||
document.addEventListener('keydown', handleTabKeyDown)
|
document.addEventListener('keydown', handleTabKeyDown)
|
||||||
return () => document.removeEventListener('keydown', handleTabKeyDown)
|
return () => document.removeEventListener('keydown', handleTabKeyDown)
|
||||||
}, [selectedPath, isGraphOpen, isSuggestedTopicsOpen, isChatSidebarOpen, isRightPaneMaximized, activeShortcutPane, chatTabs, fileTabs, activeChatTabId, activeFileTabId, closeChatTab, closeFileTab, switchChatTab, switchFileTab])
|
}, [selectedPath, isGraphOpen, isSuggestedTopicsOpen, isBackgroundAgentsOpen, isChatSidebarOpen, isRightPaneMaximized, activeShortcutPane, chatTabs, fileTabs, activeChatTabId, activeFileTabId, closeChatTab, closeFileTab, switchChatTab, switchFileTab])
|
||||||
|
|
||||||
const toggleExpand = (path: string, kind: 'file' | 'dir') => {
|
const toggleExpand = (path: string, kind: 'file' | 'dir') => {
|
||||||
if (kind === 'file') {
|
if (kind === 'file') {
|
||||||
|
|
@ -3540,7 +3626,7 @@ function App() {
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
if (!selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !selectedBackgroundTask) {
|
if (!selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !isBackgroundAgentsOpen && !selectedBackgroundTask) {
|
||||||
setIsChatSidebarOpen(false)
|
setIsChatSidebarOpen(false)
|
||||||
setIsRightPaneMaximized(false)
|
setIsRightPaneMaximized(false)
|
||||||
}
|
}
|
||||||
|
|
@ -3662,14 +3748,14 @@ function App() {
|
||||||
},
|
},
|
||||||
openGraph: () => {
|
openGraph: () => {
|
||||||
// From chat-only landing state, open graph directly in full knowledge view.
|
// From chat-only landing state, open graph directly in full knowledge view.
|
||||||
if (!selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !selectedBackgroundTask) {
|
if (!selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !isBackgroundAgentsOpen && !selectedBackgroundTask) {
|
||||||
setIsChatSidebarOpen(false)
|
setIsChatSidebarOpen(false)
|
||||||
setIsRightPaneMaximized(false)
|
setIsRightPaneMaximized(false)
|
||||||
}
|
}
|
||||||
void navigateToView({ type: 'graph' })
|
void navigateToView({ type: 'graph' })
|
||||||
},
|
},
|
||||||
openBases: () => {
|
openBases: () => {
|
||||||
if (!selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !selectedBackgroundTask) {
|
if (!selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !isBackgroundAgentsOpen && !selectedBackgroundTask) {
|
||||||
setIsChatSidebarOpen(false)
|
setIsChatSidebarOpen(false)
|
||||||
setIsRightPaneMaximized(false)
|
setIsRightPaneMaximized(false)
|
||||||
}
|
}
|
||||||
|
|
@ -4253,7 +4339,7 @@ function App() {
|
||||||
const selectedTask = selectedBackgroundTask
|
const selectedTask = selectedBackgroundTask
|
||||||
? backgroundTasks.find(t => t.name === selectedBackgroundTask)
|
? backgroundTasks.find(t => t.name === selectedBackgroundTask)
|
||||||
: null
|
: null
|
||||||
const isRightPaneContext = Boolean(selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBrowserOpen)
|
const isRightPaneContext = Boolean(selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBackgroundAgentsOpen || isBrowserOpen)
|
||||||
const isRightPaneOnlyMode = isRightPaneContext && isChatSidebarOpen && isRightPaneMaximized
|
const isRightPaneOnlyMode = isRightPaneContext && isChatSidebarOpen && isRightPaneMaximized
|
||||||
const shouldCollapseLeftPane = isRightPaneOnlyMode
|
const shouldCollapseLeftPane = isRightPaneOnlyMode
|
||||||
const openMarkdownTabs = React.useMemo(() => {
|
const openMarkdownTabs = React.useMemo(() => {
|
||||||
|
|
@ -4270,7 +4356,7 @@ function App() {
|
||||||
return (
|
return (
|
||||||
<TooltipProvider delayDuration={0}>
|
<TooltipProvider delayDuration={0}>
|
||||||
<SidebarSectionProvider defaultSection="tasks" onSectionChange={(section) => {
|
<SidebarSectionProvider defaultSection="tasks" onSectionChange={(section) => {
|
||||||
if (section === 'knowledge' && !selectedPath && !isGraphOpen) {
|
if (section === 'knowledge' && !selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !isBackgroundAgentsOpen) {
|
||||||
void navigateToView({ type: 'file', path: BASES_DEFAULT_TAB_PATH })
|
void navigateToView({ type: 'file', path: BASES_DEFAULT_TAB_PATH })
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
|
|
@ -4303,7 +4389,7 @@ function App() {
|
||||||
onNewChat: handleNewChatTab,
|
onNewChat: handleNewChatTab,
|
||||||
onSelectRun: (runIdToLoad) => {
|
onSelectRun: (runIdToLoad) => {
|
||||||
cancelRecordingIfActive()
|
cancelRecordingIfActive()
|
||||||
if (selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBrowserOpen) {
|
if (selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBackgroundAgentsOpen || isBrowserOpen) {
|
||||||
setIsChatSidebarOpen(true)
|
setIsChatSidebarOpen(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4314,7 +4400,7 @@ function App() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// In two-pane mode (file/graph/browser), keep the middle pane and just swap chat context in the right sidebar.
|
// In two-pane mode (file/graph/browser), keep the middle pane and just swap chat context in the right sidebar.
|
||||||
if (selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBrowserOpen) {
|
if (selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBackgroundAgentsOpen || isBrowserOpen) {
|
||||||
setChatTabs(prev => prev.map(t => t.id === activeChatTabId ? { ...t, runId: runIdToLoad } : t))
|
setChatTabs(prev => prev.map(t => t.id === activeChatTabId ? { ...t, runId: runIdToLoad } : t))
|
||||||
loadRun(runIdToLoad)
|
loadRun(runIdToLoad)
|
||||||
return
|
return
|
||||||
|
|
@ -4338,14 +4424,14 @@ function App() {
|
||||||
} else {
|
} else {
|
||||||
// Only one tab, reset it to new chat
|
// Only one tab, reset it to new chat
|
||||||
setChatTabs([{ id: tabForRun.id, runId: null }])
|
setChatTabs([{ id: tabForRun.id, runId: null }])
|
||||||
if (selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBrowserOpen) {
|
if (selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBackgroundAgentsOpen || isBrowserOpen) {
|
||||||
handleNewChat()
|
handleNewChat()
|
||||||
} else {
|
} else {
|
||||||
void navigateToView({ type: 'chat', runId: null })
|
void navigateToView({ type: 'chat', runId: null })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (runId === runIdToDelete) {
|
} else if (runId === runIdToDelete) {
|
||||||
if (selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBrowserOpen) {
|
if (selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBackgroundAgentsOpen || isBrowserOpen) {
|
||||||
setChatTabs(prev => prev.map(t => t.id === activeChatTabId ? { ...t, runId: null } : t))
|
setChatTabs(prev => prev.map(t => t.id === activeChatTabId ? { ...t, runId: null } : t))
|
||||||
handleNewChat()
|
handleNewChat()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -4375,6 +4461,8 @@ function App() {
|
||||||
onToggleBrowser={handleToggleBrowser}
|
onToggleBrowser={handleToggleBrowser}
|
||||||
isSuggestedTopicsOpen={isSuggestedTopicsOpen}
|
isSuggestedTopicsOpen={isSuggestedTopicsOpen}
|
||||||
onOpenSuggestedTopics={() => void navigateToView({ type: 'suggested-topics' })}
|
onOpenSuggestedTopics={() => void navigateToView({ type: 'suggested-topics' })}
|
||||||
|
isBackgroundAgentsOpen={isBackgroundAgentsOpen}
|
||||||
|
onOpenBackgroundAgents={() => void navigateToView({ type: 'background-agents' })}
|
||||||
/>
|
/>
|
||||||
<SidebarInset
|
<SidebarInset
|
||||||
className={cn(
|
className={cn(
|
||||||
|
|
@ -4394,7 +4482,7 @@ function App() {
|
||||||
canNavigateForward={canNavigateForward}
|
canNavigateForward={canNavigateForward}
|
||||||
collapsedLeftPaddingPx={collapsedLeftPaddingPx}
|
collapsedLeftPaddingPx={collapsedLeftPaddingPx}
|
||||||
>
|
>
|
||||||
{(selectedPath || isGraphOpen || isSuggestedTopicsOpen) && fileTabs.length >= 1 ? (
|
{(selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBackgroundAgentsOpen) && fileTabs.length >= 1 ? (
|
||||||
<TabBar
|
<TabBar
|
||||||
tabs={fileTabs}
|
tabs={fileTabs}
|
||||||
activeTabId={activeFileTabId ?? ''}
|
activeTabId={activeFileTabId ?? ''}
|
||||||
|
|
@ -4402,7 +4490,7 @@ function App() {
|
||||||
getTabId={(t) => t.id}
|
getTabId={(t) => t.id}
|
||||||
onSwitchTab={switchFileTab}
|
onSwitchTab={switchFileTab}
|
||||||
onCloseTab={closeFileTab}
|
onCloseTab={closeFileTab}
|
||||||
allowSingleTabClose={fileTabs.length === 1 && (isGraphOpen || isSuggestedTopicsOpen || (selectedPath != null && isBaseFilePath(selectedPath)))}
|
allowSingleTabClose={fileTabs.length === 1 && (isGraphOpen || isSuggestedTopicsOpen || isBackgroundAgentsOpen || (selectedPath != null && isBaseFilePath(selectedPath)))}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<TabBar
|
<TabBar
|
||||||
|
|
@ -4455,7 +4543,7 @@ function App() {
|
||||||
<TooltipContent side="bottom">Version history</TooltipContent>
|
<TooltipContent side="bottom">Version history</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
{!selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !selectedTask && !isBrowserOpen && (
|
{!selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !isBackgroundAgentsOpen && !selectedTask && !isBrowserOpen && (
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<button
|
<button
|
||||||
|
|
@ -4470,7 +4558,7 @@ function App() {
|
||||||
<TooltipContent side="bottom">New chat tab</TooltipContent>
|
<TooltipContent side="bottom">New chat tab</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
{!selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !isBrowserOpen && expandedFrom && (
|
{!selectedPath && !isGraphOpen && !isSuggestedTopicsOpen && !isBackgroundAgentsOpen && !isBrowserOpen && expandedFrom && (
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<button
|
<button
|
||||||
|
|
@ -4485,7 +4573,7 @@ function App() {
|
||||||
<TooltipContent side="bottom">Restore two-pane view</TooltipContent>
|
<TooltipContent side="bottom">Restore two-pane view</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
{(selectedPath || isGraphOpen || isSuggestedTopicsOpen) && (
|
{(selectedPath || isGraphOpen || isSuggestedTopicsOpen || isBackgroundAgentsOpen) && (
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<button
|
<button
|
||||||
|
|
@ -4518,6 +4606,12 @@ function App() {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
) : isBackgroundAgentsOpen ? (
|
||||||
|
<div className="flex-1 min-h-0 flex flex-col overflow-hidden">
|
||||||
|
<BackgroundAgentsView
|
||||||
|
onOpenNote={(path) => navigateToFile(path)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
) : selectedPath && isBaseFilePath(selectedPath) ? (
|
) : selectedPath && isBaseFilePath(selectedPath) ? (
|
||||||
<div className="flex-1 min-h-0 flex flex-col overflow-hidden">
|
<div className="flex-1 min-h-0 flex flex-col overflow-hidden">
|
||||||
<BasesView
|
<BasesView
|
||||||
|
|
|
||||||
253
apps/x/apps/renderer/src/components/background-agents-view.tsx
Normal file
253
apps/x/apps/renderer/src/components/background-agents-view.tsx
Normal file
|
|
@ -0,0 +1,253 @@
|
||||||
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
|
import { Bot, Loader2 } from 'lucide-react'
|
||||||
|
|
||||||
|
import { Switch } from '@/components/ui/switch'
|
||||||
|
import { stripKnowledgePrefix, wikiLabel } from '@/lib/wiki-links'
|
||||||
|
import { toast } from '@/lib/toast'
|
||||||
|
|
||||||
|
type BackgroundAgentNote = {
|
||||||
|
path: string
|
||||||
|
trackCount: number
|
||||||
|
createdAt: string | null
|
||||||
|
lastRunAt: string | null
|
||||||
|
isActive: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
type BackgroundAgentsViewProps = {
|
||||||
|
onOpenNote: (path: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDateLabel(iso: string | null): string {
|
||||||
|
if (!iso) return '—'
|
||||||
|
const date = new Date(iso)
|
||||||
|
if (Number.isNaN(date.getTime())) return '—'
|
||||||
|
return date.toLocaleDateString(undefined, {
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDateTimeLabel(iso: string | null): string {
|
||||||
|
if (!iso) return 'Never'
|
||||||
|
const date = new Date(iso)
|
||||||
|
if (Number.isNaN(date.getTime())) return 'Never'
|
||||||
|
return date.toLocaleString(undefined, {
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
hour: 'numeric',
|
||||||
|
minute: '2-digit',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function isKnowledgeMarkdownPath(path: string | undefined): boolean {
|
||||||
|
return typeof path === 'string' && path.startsWith('knowledge/') && path.endsWith('.md')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function BackgroundAgentsView({ onOpenNote }: BackgroundAgentsViewProps) {
|
||||||
|
const [notes, setNotes] = useState<BackgroundAgentNote[]>([])
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
const [updatingPaths, setUpdatingPaths] = useState<Set<string>>(new Set())
|
||||||
|
|
||||||
|
const loadNotes = useCallback(async () => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const result = await window.ipc.invoke('track:listNotes', null)
|
||||||
|
setNotes(result.notes)
|
||||||
|
setError(null)
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to load background agent notes:', err)
|
||||||
|
setError('Could not load background agents.')
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadNotes()
|
||||||
|
}, [loadNotes])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let timeout: ReturnType<typeof setTimeout> | null = null
|
||||||
|
|
||||||
|
const scheduleReload = () => {
|
||||||
|
if (timeout) clearTimeout(timeout)
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
timeout = null
|
||||||
|
void loadNotes()
|
||||||
|
}, 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
const cleanupWorkspace = window.ipc.on('workspace:didChange', (event) => {
|
||||||
|
switch (event.type) {
|
||||||
|
case 'created':
|
||||||
|
case 'changed':
|
||||||
|
case 'deleted':
|
||||||
|
if (isKnowledgeMarkdownPath(event.path)) scheduleReload()
|
||||||
|
break
|
||||||
|
case 'moved':
|
||||||
|
if (isKnowledgeMarkdownPath(event.from) || isKnowledgeMarkdownPath(event.to)) {
|
||||||
|
scheduleReload()
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'bulkChanged':
|
||||||
|
if (!event.paths || event.paths.some(isKnowledgeMarkdownPath)) {
|
||||||
|
scheduleReload()
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const cleanupTracks = window.ipc.on('tracks:events', () => {
|
||||||
|
scheduleReload()
|
||||||
|
})
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cleanupWorkspace()
|
||||||
|
cleanupTracks()
|
||||||
|
if (timeout) clearTimeout(timeout)
|
||||||
|
}
|
||||||
|
}, [loadNotes])
|
||||||
|
|
||||||
|
const handleToggleState = useCallback(async (note: BackgroundAgentNote, active: boolean) => {
|
||||||
|
setUpdatingPaths((prev) => new Set(prev).add(note.path))
|
||||||
|
try {
|
||||||
|
const result = await window.ipc.invoke('track:setNoteActive', {
|
||||||
|
path: note.path,
|
||||||
|
active,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!result.success || !result.note) {
|
||||||
|
throw new Error(result.error ?? 'Failed to update background agent state')
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedNote = result.note
|
||||||
|
setNotes((prev) => prev.map((entry) => (
|
||||||
|
entry.path === note.path ? updatedNote : entry
|
||||||
|
)))
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to update background agent note state:', err)
|
||||||
|
toast(err instanceof Error ? err.message : 'Failed to update background agent state', 'error')
|
||||||
|
} finally {
|
||||||
|
setUpdatingPaths((prev) => {
|
||||||
|
const next = new Set(prev)
|
||||||
|
next.delete(note.path)
|
||||||
|
return next
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div className="flex h-full items-center justify-center">
|
||||||
|
<Loader2 className="size-5 animate-spin text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="flex h-full flex-col items-center justify-center gap-3 px-8 text-center">
|
||||||
|
<div className="rounded-full bg-muted p-3">
|
||||||
|
<Bot className="size-6 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-muted-foreground">{error}</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notes.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="flex h-full flex-col items-center justify-center gap-3 px-8 text-center">
|
||||||
|
<div className="rounded-full bg-muted p-3">
|
||||||
|
<Bot className="size-6 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
No notes with background agents yet.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-full flex-col overflow-hidden">
|
||||||
|
<div className="shrink-0 border-b border-border px-6 py-5">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Bot className="size-5 text-primary" />
|
||||||
|
<h2 className="text-base font-semibold text-foreground">Background agents</h2>
|
||||||
|
</div>
|
||||||
|
<p className="mt-1 text-xs text-muted-foreground">
|
||||||
|
Notes that contain track blocks. Toggle a note inactive to pause every background agent in it.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 overflow-auto p-6">
|
||||||
|
<div className="overflow-hidden rounded-xl border border-border/60 bg-card">
|
||||||
|
<table className="min-w-full border-collapse">
|
||||||
|
<thead>
|
||||||
|
<tr className="border-b border-border/60 bg-muted/30 text-left">
|
||||||
|
<th className="px-4 py-3 text-xs font-medium uppercase tracking-wide text-muted-foreground">Note</th>
|
||||||
|
<th className="px-4 py-3 text-xs font-medium uppercase tracking-wide text-muted-foreground">Created date</th>
|
||||||
|
<th className="px-4 py-3 text-xs font-medium uppercase tracking-wide text-muted-foreground">Last ran</th>
|
||||||
|
<th className="px-4 py-3 text-xs font-medium uppercase tracking-wide text-muted-foreground">State</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{notes.map((note) => {
|
||||||
|
const isUpdating = updatingPaths.has(note.path)
|
||||||
|
return (
|
||||||
|
<tr key={note.path} className="border-b border-border/50 last:border-b-0 hover:bg-muted/20">
|
||||||
|
<td className="px-4 py-3 align-top">
|
||||||
|
<div className="flex min-w-0 flex-col gap-1">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => onOpenNote(note.path)}
|
||||||
|
className="truncate text-left text-sm font-medium text-foreground hover:text-primary"
|
||||||
|
title={note.path}
|
||||||
|
>
|
||||||
|
{wikiLabel(note.path)}
|
||||||
|
</button>
|
||||||
|
<span className="shrink-0 rounded-full bg-muted px-2 py-0.5 text-[10px] font-medium text-muted-foreground">
|
||||||
|
{note.trackCount} {note.trackCount === 1 ? 'agent' : 'agents'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="truncate text-xs text-muted-foreground">
|
||||||
|
{stripKnowledgePrefix(note.path)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-3 text-sm text-foreground/80">
|
||||||
|
{formatDateLabel(note.createdAt)}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-3 text-sm text-foreground/80">
|
||||||
|
{formatDateTimeLabel(note.lastRunAt)}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-3">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
{isUpdating ? (
|
||||||
|
<Loader2 className="size-4 animate-spin text-muted-foreground" />
|
||||||
|
) : (
|
||||||
|
<span className="size-4 shrink-0" aria-hidden="true" />
|
||||||
|
)}
|
||||||
|
<Switch
|
||||||
|
checked={note.isActive}
|
||||||
|
onCheckedChange={(checked) => { void handleToggleState(note, checked) }}
|
||||||
|
disabled={isUpdating}
|
||||||
|
/>
|
||||||
|
<span className="min-w-16 text-xs font-medium text-foreground/80">
|
||||||
|
{note.isActive ? 'Active' : 'Inactive'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -89,7 +89,6 @@ import {
|
||||||
} from "@/components/ui/context-menu"
|
} from "@/components/ui/context-menu"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { stripKnowledgePrefix, wikiLabel } from "@/lib/wiki-links"
|
|
||||||
import { type ActiveSection, useSidebarSection } from "@/contexts/sidebar-context"
|
import { type ActiveSection, useSidebarSection } from "@/contexts/sidebar-context"
|
||||||
import { ConnectorsPopover } from "@/components/connectors-popover"
|
import { ConnectorsPopover } from "@/components/connectors-popover"
|
||||||
import { HelpPopover } from "@/components/help-popover"
|
import { HelpPopover } from "@/components/help-popover"
|
||||||
|
|
@ -145,11 +144,6 @@ type BackgroundTaskItem = {
|
||||||
lastRunAt?: string | null
|
lastRunAt?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
type TrackNoteItem = {
|
|
||||||
path: string
|
|
||||||
trackCount: number
|
|
||||||
}
|
|
||||||
|
|
||||||
type ServiceEventType = z.infer<typeof ServiceEvent>
|
type ServiceEventType = z.infer<typeof ServiceEvent>
|
||||||
|
|
||||||
const MAX_SYNC_EVENTS = 1000
|
const MAX_SYNC_EVENTS = 1000
|
||||||
|
|
@ -186,151 +180,6 @@ function collectServiceErrors(events: ServiceEventType[]): Map<string, string> {
|
||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
function isKnowledgeMarkdownPath(path: string | undefined): boolean {
|
|
||||||
return typeof path === "string" && path.startsWith("knowledge/") && path.endsWith(".md")
|
|
||||||
}
|
|
||||||
|
|
||||||
function BackgroundAgentsShortcut({
|
|
||||||
selectedPath,
|
|
||||||
onSelectFile,
|
|
||||||
}: {
|
|
||||||
selectedPath: string | null
|
|
||||||
onSelectFile: (path: string, kind: "file" | "dir") => void
|
|
||||||
}) {
|
|
||||||
const [open, setOpen] = useState(false)
|
|
||||||
const [notes, setNotes] = useState<TrackNoteItem[]>([])
|
|
||||||
const [loading, setLoading] = useState(true)
|
|
||||||
const [error, setError] = useState<string | null>(null)
|
|
||||||
const reloadTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
||||||
|
|
||||||
const loadNotes = useCallback(async () => {
|
|
||||||
setLoading(true)
|
|
||||||
try {
|
|
||||||
const result = await window.ipc.invoke("track:listNotes", null)
|
|
||||||
setNotes(result.notes)
|
|
||||||
setError(null)
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Failed to load background agent notes:", err)
|
|
||||||
setError("Couldn't load background agents.")
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
void loadNotes()
|
|
||||||
}, [loadNotes])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const scheduleReload = () => {
|
|
||||||
if (reloadTimeoutRef.current) clearTimeout(reloadTimeoutRef.current)
|
|
||||||
reloadTimeoutRef.current = setTimeout(() => {
|
|
||||||
reloadTimeoutRef.current = null
|
|
||||||
void loadNotes()
|
|
||||||
}, 200)
|
|
||||||
}
|
|
||||||
|
|
||||||
const cleanup = window.ipc.on("workspace:didChange", (event) => {
|
|
||||||
switch (event.type) {
|
|
||||||
case "created":
|
|
||||||
case "deleted":
|
|
||||||
case "changed":
|
|
||||||
if (isKnowledgeMarkdownPath(event.path)) scheduleReload()
|
|
||||||
break
|
|
||||||
case "moved":
|
|
||||||
if (isKnowledgeMarkdownPath(event.from) || isKnowledgeMarkdownPath(event.to)) {
|
|
||||||
scheduleReload()
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case "bulkChanged":
|
|
||||||
if (!event.paths || event.paths.some(isKnowledgeMarkdownPath)) {
|
|
||||||
scheduleReload()
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
cleanup()
|
|
||||||
if (reloadTimeoutRef.current) clearTimeout(reloadTimeoutRef.current)
|
|
||||||
}
|
|
||||||
}, [loadNotes])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Collapsible open={open} onOpenChange={setOpen} className="flex flex-col gap-0.5">
|
|
||||||
<CollapsibleTrigger asChild>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-sm text-sidebar-foreground/80 transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
|
|
||||||
>
|
|
||||||
<Bot className="size-4" />
|
|
||||||
<span className="min-w-0 flex-1 text-left">Background agents</span>
|
|
||||||
{loading ? (
|
|
||||||
<LoaderIcon className="size-3.5 animate-spin text-sidebar-foreground/50" />
|
|
||||||
) : notes.length > 0 ? (
|
|
||||||
<span className="rounded-full bg-sidebar-accent px-1.5 py-0.5 text-[10px] font-medium leading-none text-sidebar-foreground/70">
|
|
||||||
{notes.length}
|
|
||||||
</span>
|
|
||||||
) : null}
|
|
||||||
<ChevronRight className={cn("size-4 shrink-0 transition-transform", open && "rotate-90")} />
|
|
||||||
</button>
|
|
||||||
</CollapsibleTrigger>
|
|
||||||
<CollapsibleContent className="pl-6">
|
|
||||||
<div className="flex flex-col gap-1 py-1 pr-1">
|
|
||||||
{loading ? (
|
|
||||||
<div className="flex items-center gap-2 px-2 py-1 text-xs text-sidebar-foreground/60">
|
|
||||||
<LoaderIcon className="size-3.5 animate-spin" />
|
|
||||||
<span>Loading notes…</span>
|
|
||||||
</div>
|
|
||||||
) : error ? (
|
|
||||||
<p className="px-2 py-1 text-xs text-sidebar-foreground/60">{error}</p>
|
|
||||||
) : notes.length === 0 ? (
|
|
||||||
<p className="px-2 py-1 text-xs text-sidebar-foreground/60">
|
|
||||||
No notes with background agents yet.
|
|
||||||
</p>
|
|
||||||
) : (
|
|
||||||
notes.map((note) => {
|
|
||||||
const relativePath = stripKnowledgePrefix(note.path)
|
|
||||||
const lastSlash = relativePath.lastIndexOf("/")
|
|
||||||
const folderPath = lastSlash >= 0 ? relativePath.slice(0, lastSlash) : ""
|
|
||||||
const isSelected = selectedPath === note.path
|
|
||||||
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={note.path}
|
|
||||||
type="button"
|
|
||||||
onClick={() => onSelectFile(note.path, "file")}
|
|
||||||
title={relativePath}
|
|
||||||
className={cn(
|
|
||||||
"flex items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",
|
|
||||||
isSelected
|
|
||||||
? "bg-sidebar-accent text-sidebar-accent-foreground"
|
|
||||||
: "text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<div className="truncate text-xs font-medium">{wikiLabel(note.path)}</div>
|
|
||||||
{folderPath && (
|
|
||||||
<div className="truncate text-[10px] text-sidebar-foreground/50">
|
|
||||||
{folderPath}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{note.trackCount > 1 && (
|
|
||||||
<span className="shrink-0 rounded-full bg-sidebar-accent px-1.5 py-0.5 text-[10px] font-medium leading-none text-sidebar-foreground/70">
|
|
||||||
{note.trackCount}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</CollapsibleContent>
|
|
||||||
</Collapsible>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
type TasksActions = {
|
type TasksActions = {
|
||||||
onNewChat: () => void
|
onNewChat: () => void
|
||||||
onSelectRun: (runId: string) => void
|
onSelectRun: (runId: string) => void
|
||||||
|
|
@ -365,6 +214,8 @@ type SidebarContentPanelProps = {
|
||||||
onToggleBrowser?: () => void
|
onToggleBrowser?: () => void
|
||||||
isSuggestedTopicsOpen?: boolean
|
isSuggestedTopicsOpen?: boolean
|
||||||
onOpenSuggestedTopics?: () => void
|
onOpenSuggestedTopics?: () => void
|
||||||
|
isBackgroundAgentsOpen?: boolean
|
||||||
|
onOpenBackgroundAgents?: () => void
|
||||||
} & React.ComponentProps<typeof Sidebar>
|
} & React.ComponentProps<typeof Sidebar>
|
||||||
|
|
||||||
const sectionTabs: { id: ActiveSection; label: string }[] = [
|
const sectionTabs: { id: ActiveSection; label: string }[] = [
|
||||||
|
|
@ -642,6 +493,8 @@ export function SidebarContentPanel({
|
||||||
onToggleBrowser,
|
onToggleBrowser,
|
||||||
isSuggestedTopicsOpen = false,
|
isSuggestedTopicsOpen = false,
|
||||||
onOpenSuggestedTopics,
|
onOpenSuggestedTopics,
|
||||||
|
isBackgroundAgentsOpen = false,
|
||||||
|
onOpenBackgroundAgents,
|
||||||
...props
|
...props
|
||||||
}: SidebarContentPanelProps) {
|
}: SidebarContentPanelProps) {
|
||||||
const { activeSection, setActiveSection } = useSidebarSection()
|
const { activeSection, setActiveSection } = useSidebarSection()
|
||||||
|
|
@ -657,6 +510,7 @@ export function SidebarContentPanel({
|
||||||
const isMeetingQuickActionSelected = isMeetingActionActive
|
const isMeetingQuickActionSelected = isMeetingActionActive
|
||||||
const isBrowserQuickActionSelected = isBrowserOpen && !isSearchOpen && !isMeetingQuickActionSelected
|
const isBrowserQuickActionSelected = isBrowserOpen && !isSearchOpen && !isMeetingQuickActionSelected
|
||||||
const isSuggestedTopicsQuickActionSelected = isSuggestedTopicsOpen && !isBrowserOpen
|
const isSuggestedTopicsQuickActionSelected = isSuggestedTopicsOpen && !isBrowserOpen
|
||||||
|
const isBackgroundAgentsQuickActionSelected = isBackgroundAgentsOpen && !isBrowserOpen
|
||||||
|
|
||||||
const handleRowboatLogin = useCallback(async () => {
|
const handleRowboatLogin = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -830,10 +684,21 @@ export function SidebarContentPanel({
|
||||||
<span>Suggested Topics</span>
|
<span>Suggested Topics</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
<BackgroundAgentsShortcut
|
{onOpenBackgroundAgents && (
|
||||||
selectedPath={selectedPath}
|
<button
|
||||||
onSelectFile={onSelectFile}
|
type="button"
|
||||||
/>
|
onClick={onOpenBackgroundAgents}
|
||||||
|
className={cn(
|
||||||
|
"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-sm transition-colors",
|
||||||
|
isBackgroundAgentsQuickActionSelected
|
||||||
|
? "bg-sidebar-accent text-sidebar-accent-foreground"
|
||||||
|
: "text-sidebar-foreground/80 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Bot className="size-4" />
|
||||||
|
<span>Background agents</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</SidebarHeader>
|
</SidebarHeader>
|
||||||
<SidebarContent>
|
<SidebarContent>
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,43 @@ export async function fetch(filePath: string, trackId: string): Promise<z.infer<
|
||||||
return blocks.find(b => b.track.trackId === trackId) ?? null;
|
return blocks.find(b => b.track.trackId === trackId) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listNotesWithTracks(): Promise<Array<{ path: string; trackCount: number }>> {
|
type TrackNoteSummary = {
|
||||||
|
path: string;
|
||||||
|
trackCount: number;
|
||||||
|
createdAt: string | null;
|
||||||
|
lastRunAt: string | null;
|
||||||
|
isActive: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
async function summarizeTrackNote(
|
||||||
|
filePath: string,
|
||||||
|
tracks: z.infer<typeof TrackStateSchema>[],
|
||||||
|
): Promise<TrackNoteSummary | null> {
|
||||||
|
if (tracks.length === 0) return null;
|
||||||
|
|
||||||
|
const stats = await fs.stat(absPath(filePath));
|
||||||
|
const createdMs = stats.birthtimeMs > 0 ? stats.birthtimeMs : stats.ctimeMs;
|
||||||
|
|
||||||
|
let latestRunAt: string | null = null;
|
||||||
|
let latestRunMs = -1;
|
||||||
|
for (const { track } of tracks) {
|
||||||
|
if (!track.lastRunAt) continue;
|
||||||
|
const candidateMs = Date.parse(track.lastRunAt);
|
||||||
|
if (Number.isNaN(candidateMs) || candidateMs <= latestRunMs) continue;
|
||||||
|
latestRunMs = candidateMs;
|
||||||
|
latestRunAt = track.lastRunAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
path: `knowledge/${filePath}`,
|
||||||
|
trackCount: tracks.length,
|
||||||
|
createdAt: createdMs > 0 ? new Date(createdMs).toISOString() : null,
|
||||||
|
lastRunAt: latestRunAt,
|
||||||
|
isActive: tracks.every(({ track }) => track.active !== false),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listNotesWithTracks(): Promise<TrackNoteSummary[]> {
|
||||||
async function walk(relativeDir = ''): Promise<string[]> {
|
async function walk(relativeDir = ''): Promise<string[]> {
|
||||||
const dirPath = absPath(relativeDir);
|
const dirPath = absPath(relativeDir);
|
||||||
try {
|
try {
|
||||||
|
|
@ -102,16 +138,16 @@ export async function listNotesWithTracks(): Promise<Array<{ path: string; track
|
||||||
|
|
||||||
const markdownFiles = await walk();
|
const markdownFiles = await walk();
|
||||||
const notes = await Promise.all(markdownFiles.map(async (relativePath) => {
|
const notes = await Promise.all(markdownFiles.map(async (relativePath) => {
|
||||||
const tracks = await fetchAll(relativePath);
|
try {
|
||||||
if (tracks.length === 0) return null;
|
const tracks = await fetchAll(relativePath);
|
||||||
return {
|
return await summarizeTrackNote(relativePath, tracks);
|
||||||
path: `knowledge/${relativePath}`,
|
} catch {
|
||||||
trackCount: tracks.length,
|
return null;
|
||||||
};
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return notes
|
return notes
|
||||||
.filter((note): note is { path: string; trackCount: number } => note !== null)
|
.filter((note): note is TrackNoteSummary => note !== null)
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
const aName = path.basename(a.path, '.md').toLowerCase();
|
const aName = path.basename(a.path, '.md').toLowerCase();
|
||||||
const bName = path.basename(b.path, '.md').toLowerCase();
|
const bName = path.basename(b.path, '.md').toLowerCase();
|
||||||
|
|
@ -120,6 +156,36 @@ export async function listNotesWithTracks(): Promise<Array<{ path: string; track
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function setNoteTracksActive(filePath: string, active: boolean): Promise<TrackNoteSummary | null> {
|
||||||
|
return withFileLock(absPath(filePath), async () => {
|
||||||
|
const blocks = await fetchAll(filePath);
|
||||||
|
if (blocks.length === 0) return null;
|
||||||
|
|
||||||
|
const alreadyMatches = blocks.every(({ track }) => (track.active !== false) === active);
|
||||||
|
if (alreadyMatches) {
|
||||||
|
return summarizeTrackNote(filePath, blocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
const content = await fs.readFile(absPath(filePath), 'utf-8');
|
||||||
|
const lines = content.split('\n');
|
||||||
|
const updatedBlocks = blocks
|
||||||
|
.map((block) => ({
|
||||||
|
...block,
|
||||||
|
track: { ...block.track, active },
|
||||||
|
}))
|
||||||
|
.sort((a, b) => b.fenceStart - a.fenceStart);
|
||||||
|
|
||||||
|
for (const block of updatedBlocks) {
|
||||||
|
const yaml = stringifyYaml(block.track).trimEnd();
|
||||||
|
const yamlLines = yaml ? yaml.split('\n') : [];
|
||||||
|
lines.splice(block.fenceStart, block.fenceEnd - block.fenceStart + 1, '```track', ...yamlLines, '```');
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.writeFile(absPath(filePath), lines.join('\n'), 'utf-8');
|
||||||
|
return summarizeTrackNote(filePath, updatedBlocks);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a track block and return its canonical YAML string (or null if not found).
|
* Fetch a track block and return its canonical YAML string (or null if not found).
|
||||||
* Useful for IPC handlers that need to return the fresh YAML without taking a
|
* Useful for IPC handlers that need to return the fresh YAML without taking a
|
||||||
|
|
|
||||||
|
|
@ -662,12 +662,32 @@ const ipcSchemas = {
|
||||||
error: z.string().optional(),
|
error: z.string().optional(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
'track:setNoteActive': {
|
||||||
|
req: z.object({
|
||||||
|
path: RelPath,
|
||||||
|
active: z.boolean(),
|
||||||
|
}),
|
||||||
|
res: z.object({
|
||||||
|
success: z.boolean(),
|
||||||
|
note: z.object({
|
||||||
|
path: RelPath,
|
||||||
|
trackCount: z.number().int().positive(),
|
||||||
|
createdAt: z.string().nullable(),
|
||||||
|
lastRunAt: z.string().nullable(),
|
||||||
|
isActive: z.boolean(),
|
||||||
|
}).optional(),
|
||||||
|
error: z.string().optional(),
|
||||||
|
}),
|
||||||
|
},
|
||||||
'track:listNotes': {
|
'track:listNotes': {
|
||||||
req: z.null(),
|
req: z.null(),
|
||||||
res: z.object({
|
res: z.object({
|
||||||
notes: z.array(z.object({
|
notes: z.array(z.object({
|
||||||
path: RelPath,
|
path: RelPath,
|
||||||
trackCount: z.number().int().positive(),
|
trackCount: z.number().int().positive(),
|
||||||
|
createdAt: z.string().nullable(),
|
||||||
|
lastRunAt: z.string().nullable(),
|
||||||
|
isActive: z.boolean(),
|
||||||
})),
|
})),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue