diff --git a/frontend/src/lib/components/copilot/chat/AIChat.svelte b/frontend/src/lib/components/copilot/chat/AIChat.svelte index cb6bdc22e3..7344ab77b4 100644 --- a/frontend/src/lib/components/copilot/chat/AIChat.svelte +++ b/frontend/src/lib/components/copilot/chat/AIChat.svelte @@ -130,6 +130,13 @@ aiChatDisplay?.flashComposer() } + export function openAssistantSettings( + section: import('./AssistantSettingsModal.svelte').AssistantSettingsSection, + root?: string + ) { + aiChatDisplay?.openAssistantSettings(section, root) + } + export async function attachContext(element: import('./context').ContextElement) { await aiChatDisplay?.attachContext(element) } diff --git a/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte b/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte index 749e3cde0b..4b9dfe22cc 100644 --- a/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte +++ b/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte @@ -18,6 +18,7 @@ MousePointer2, Plug, Plus, + SlidersHorizontal, TextSelect, X, XIcon @@ -34,7 +35,9 @@ import ContextUsageIndicator from './ContextUsageIndicator.svelte' import AIChatModelSettings from './AIChatModelSettings.svelte' import ScrollFade from '$lib/components/ScrollFade.svelte' - import AssistantSettingsModal from './AssistantSettingsModal.svelte' + import AssistantSettingsModal, { + type AssistantSettingsSection + } from './AssistantSettingsModal.svelte' import WorkingInPicker from './WorkingInPicker.svelte' import { scopeLabel } from './workingScope' import { SkillsMenu } from './skills/skillsMenu.svelte' @@ -316,6 +319,12 @@ aiChatInput?.focusInput(selection) } + /** With `root`, focused on that folder. */ + export function openAssistantSettings(section: AssistantSettingsSection, root?: string) { + if (root) void assistantSettings?.openFolder(section, root) + else assistantSettings?.open(section) + } + /** Mention a workspace item in the draft, as "+" → Mention file does, and hand the user * the caret after it. Focusing is what opens Home's one-line composer. */ export async function attachContext(element: ContextElement) { @@ -1393,7 +1402,24 @@ the panel, or the Escape-to-stop focus check would wrongly reject them. --> {/if} {@render footerSettings?.()} {#if chatHost.mode === AIMode.GLOBAL} - + + - {#if !collapsed[node.path]} + {#if !isFolded(node.path)}
{#each node.children as child (child.path)} {@render folder(child, false)} @@ -776,7 +798,7 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
- {#if detail?.kind === 'new'} + {#if detail?.kind === 'new' || detail?.kind === 'folder'}
+ {#if detail?.kind === 'folder'} +
+ Stored as an ai_instruction resource. + +
+ {/if} diff --git a/frontend/src/lib/components/copilot/chat/AssistantSettingsModal.svelte b/frontend/src/lib/components/copilot/chat/AssistantSettingsModal.svelte index c030fe5c9d..0eda197b3d 100644 --- a/frontend/src/lib/components/copilot/chat/AssistantSettingsModal.svelte +++ b/frontend/src/lib/components/copilot/chat/AssistantSettingsModal.svelte @@ -27,19 +27,18 @@ callers that already know which section they mean, such as the "+" menu's Manage Paperclip, Plug, ScrollText, - ShieldCheck, - SlidersHorizontal + ShieldCheck } from 'lucide-svelte' import Button from '$lib/components/common/button/Button.svelte' import Modal2 from '$lib/components/common/modal/Modal2.svelte' import SidebarNavigation from '$lib/components/common/sidebar/SidebarNavigation.svelte' - import Tooltip from '$lib/components/meltComponents/Tooltip.svelte' import { logFeatureUsage } from '$lib/utils/featureUsage' import { getAiChatManager } from './aiChatManagerContext' import { summarizeTools } from './agentContext' import AssistantToolsSection from './AssistantToolsSection.svelte' import AssistantSkillsSection from './AssistantSkillsSection.svelte' import AssistantInstructionsSection from './AssistantInstructionsSection.svelte' + import { tick } from 'svelte' import AssistantMcpSection from './AssistantMcpSection.svelte' import AssistantFilesSection from './AssistantFilesSection.svelte' import AssistantPermissionsSection from './AssistantPermissionsSection.svelte' @@ -121,12 +120,22 @@ callers that already know which section they mean, such as the "+" menu's Manage let tools = $derived(summarizeTools(aiChatManager.availableTools)) let providerTools = $derived(aiChatManager.providerTools) + /** The folder (`f/x` or `u/x`) the modal was opened on, from a folder's badge: in Skills + * and Instructions it is the only top-level folder open. */ + let focusRoot = $state(undefined) + // `SidebarNavigation`'s item shape, which is what the instance and workspace settings // navs are built from too. let sections = $derived([ { id: 'tools', label: 'Tools', icon: Boxes, count: tools.length + providerTools.length }, { id: 'skills', label: 'Skills', icon: BookOpen, count: skillCount }, - { id: 'instructions', label: 'Instructions', icon: ScrollText }, + // Folder instructions only: the workspace's and yours are fixed rows, set or not. + { + id: 'instructions', + label: 'Instructions', + icon: ScrollText, + count: aiChatManager.scopeResources.instructions.length + }, { id: 'mcp', label: 'MCP connections', icon: Plug, count: mcpCount }, // The count is what is readable rather than what is attached: a locked folder under // a heading about what the assistant can use would say the opposite of the truth. @@ -136,6 +145,7 @@ callers that already know which section they mean, such as the "+" menu's Manage /** Opens on `target`, or back on whichever section was last read. */ export function open(target: AssistantSettingsSection = section) { + focusRoot = undefined section = target isOpen = true refresh() @@ -143,6 +153,17 @@ callers that already know which section they mean, such as the "+" menu's Manage record(target) } + let skillsSection: AssistantSkillsSection | undefined = $state() + let instructionsSection: AssistantInstructionsSection | undefined = $state() + /** Opens on `target` focused on `root`. The sections mount with the modal. */ + export async function openFolder(target: AssistantSettingsSection, root: string) { + open(target) + focusRoot = root + await tick() + skillsSection?.showFolder() + instructionsSection?.showFolder() + } + // `context_panel` is the kind registered in `feature_usage_ee.rs`; an unregistered // pair is dropped silently, so the name is fixed there rather than here. // @@ -172,6 +193,7 @@ callers that already know which section they mean, such as the "+" menu's Manage // values the turn was actually given, which is the honest answer anyway. if (!aiChatManager.loading && !aiChatManager.sendInFlight) { void aiChatManager.refreshGlobalSkills() + void aiChatManager.refreshGlobalFolderInstructions() void aiChatManager.refreshMcpServers() void aiChatManager.refreshSessionAccess() } @@ -180,23 +202,6 @@ callers that already know which section they mean, such as the "+" menu's Manage - - -
@@ -1204,6 +1200,20 @@ What the assistant should do when this skill applies. + {#if editing} +
+ Stored as an ai_skill resource. + +
+ {/if}
diff --git a/frontend/src/lib/components/copilot/chat/folderInstructions.ts b/frontend/src/lib/components/copilot/chat/folderInstructions.ts index dd9101a1c3..df5d340c91 100644 --- a/frontend/src/lib/components/copilot/chat/folderInstructions.ts +++ b/frontend/src/lib/components/copilot/chat/folderInstructions.ts @@ -86,7 +86,7 @@ export async function saveFolderInstruction( workspace: string, path: string, content: string, - { create = false }: { create?: boolean } = {} + { create = false, from = path }: { create?: boolean; from?: string } = {} ): Promise { if (create) { await ResourceService.createResource({ @@ -98,7 +98,11 @@ export async function saveFolderInstruction( } }) } else { - await ResourceService.updateResource({ workspace, path, requestBody: { value: { content } } }) + await ResourceService.updateResource({ + workspace, + path: from, + requestBody: { path, value: { content } } + }) } } diff --git a/frontend/src/lib/components/copilot/chat/skills/skillTree.ts b/frontend/src/lib/components/copilot/chat/skills/skillTree.ts index d2de4eb655..0e0ed1694a 100644 --- a/frontend/src/lib/components/copilot/chat/skills/skillTree.ts +++ b/frontend/src/lib/components/copilot/chat/skills/skillTree.ts @@ -1,8 +1,4 @@ -/** Grouping for the Skills list: skills sorted into the folders that hold them. - * - * Only worth showing when the skills are spread over more than one folder — see - * `skillFolderPaths` — since a tree over a single folder is a list with a header - * on top of it. */ +/** Grouping for the Skills list: skills sorted into the folders that hold them. */ /** A folder in the skills tree. `path` is the whole prefix the node covers, so it * is unique across the tree and can key collapsed state. */ @@ -19,11 +15,6 @@ export type SkillTreeNode = { type Skill = { path: string; name: string } -/** The folders holding these skills — one entry per distinct parent path. */ -export function skillFolderPaths(skills: readonly Skill[]): Set { - return new Set(skills.map((s) => s.path.split('/').slice(0, -1).join('/'))) -} - /** Every skill under `node`, its subfolders included. */ export function countSkills(node: SkillTreeNode): number { return node.skills.length + node.children.reduce((n, c) => n + countSkills(c), 0) @@ -42,6 +33,12 @@ export type SkillTreeEntry = { key: string; parentKey?: string } & ( /** A folder and a skill can hold the same path — `f/skills/deploy` names both when * `f/skills/deploy/rollback` exists beside it — so the kind is part of the key. */ +/** Whether a folder the user has not folded or unfolded starts folded: with a folder focused + * (`f/x` or `u/x`), every other top-level folder does, so the focused one is what is left. */ +export function foldedByDefault(path: string, focusRoot: string | undefined): boolean { + return focusRoot !== undefined && path.split('/').length === 2 && path !== focusRoot +} + export function folderKey(path: string): string { return `folder:${path}` } diff --git a/frontend/src/lib/components/copilot/chat/skills/skills.test.ts b/frontend/src/lib/components/copilot/chat/skills/skills.test.ts index ae2e737af2..aaeb82bc2c 100644 --- a/frontend/src/lib/components/copilot/chat/skills/skills.test.ts +++ b/frontend/src/lib/components/copilot/chat/skills/skills.test.ts @@ -12,7 +12,7 @@ vi.mock('$lib/stores', () => ({ import { isMcpEnabled } from '$lib/components/mcp/enabledServers' import { isSkillEnabled, setSkillEnabled } from './enabledSkills' import { ambiguousSkillNames, truncateChars, truncateForPrompt } from './skillResources' -import { buildSkillTree, countSkills, skillFolderPaths, visibleEntries } from './skillTree' +import { buildSkillTree, countSkills, visibleEntries } from './skillTree' describe('enabledSkills', () => { beforeEach(() => { @@ -112,12 +112,6 @@ describe('skill tree', () => { 'folder:f/skills' ]) }) - - // What the list uses to choose between the tree and a flat list. - it('counts the folders holding the skills, not the skills', () => { - expect(skillFolderPaths(skills).size).toBe(3) - expect(skillFolderPaths([skills[1], { path: 'f/skills/deploy', name: 'deploy' }]).size).toBe(1) - }) }) describe('skill names', () => { diff --git a/frontend/src/lib/components/copilot/chat/workingScope.ts b/frontend/src/lib/components/copilot/chat/workingScope.ts index 30ae5becc7..0c1d270ad7 100644 --- a/frontend/src/lib/components/copilot/chat/workingScope.ts +++ b/frontend/src/lib/components/copilot/chat/workingScope.ts @@ -221,12 +221,6 @@ export function scopeBadge(option: ScopeOption): string { ].join(' · ') } -/** How a folder's instructions and skills reach the AI, in the one wording the picker and the - * tree badge share. */ -export function scopeRule(root: string): string { - return `Working in ${root} puts its instructions in the AI's prompt and keeps its skills on; skills from other folders are off. Outside it, the AI gets a folder's instructions the first time it touches that folder.` -} - export type ScopeKind = 'workspace' | 'none' | 'folder' | 'user_space' | 'several' export type ScopeSource = 'default' | 'preset' | 'manual' diff --git a/frontend/src/lib/components/home/HomeFolderBadge.svelte b/frontend/src/lib/components/home/HomeFolderBadge.svelte index 7014fe62a0..6002fcfaba 100644 --- a/frontend/src/lib/components/home/HomeFolderBadge.svelte +++ b/frontend/src/lib/components/home/HomeFolderBadge.svelte @@ -1,14 +1,13 @@ -{#if row && badge} - - -
e.stopPropagation()}> - - {#snippet trigger()} - - {/snippet} - {#snippet content()} - {#if row.instructions.length} -
-

Instructions

- {#each row.instructions as path (path)} -

{path}

- {/each} -
- {/if} - {#if row.skills.length} -
-

Skills

- {#each row.skills as path (path)} -

{path}

- {/each} -
- {/if} - {#if row.mcpServers.length} -
-

MCP servers

- {#each row.mcpServers as path (path)} -

{path}

- {/each} -
- {/if} -

{scopeRule(root)}

- - {/snippet} -
-
+{#if parts.length} + + {#each parts as part (part.section)} + + {/each} + {/if} diff --git a/frontend/src/lib/components/sessions/HomeSessionStarter.svelte b/frontend/src/lib/components/sessions/HomeSessionStarter.svelte index 868dd613fb..a388149005 100644 --- a/frontend/src/lib/components/sessions/HomeSessionStarter.svelte +++ b/frontend/src/lib/components/sessions/HomeSessionStarter.svelte @@ -93,6 +93,7 @@ }, focus: () => aiChat?.focusInput(), flash: () => aiChat?.flashComposer(), + openSettings: (section, root) => aiChat?.openAssistantSettings(section, root), runtime }) }) diff --git a/frontend/src/lib/components/sessions/homeComposerContext.svelte.ts b/frontend/src/lib/components/sessions/homeComposerContext.svelte.ts index 29a35feb45..651266ad63 100644 --- a/frontend/src/lib/components/sessions/homeComposerContext.svelte.ts +++ b/frontend/src/lib/components/sessions/homeComposerContext.svelte.ts @@ -33,6 +33,8 @@ type Registration = { focus: () => void /** The box's accent outline, for a composer the user is sent to without it moving. */ flash: () => void + /** Assistant settings on `section`; Instructions opens with only `root`'s folder open. */ + openSettings: (section: 'instructions' | 'skills' | 'mcp', root: string) => void runtime: SessionRuntime } @@ -66,6 +68,9 @@ export const homeComposerContext = { flash(): void { registered?.flash() }, + openSettings(section: 'instructions' | 'skills' | 'mcp', root: string): void { + registered?.openSettings(section, root) + }, /** Returns the unregister, which only clears its own registration: a remount registers * the new composer before the old one is destroyed. */ register(registration: Registration): () => void {