mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-28 16:06:22 +00:00
feat: open a folder's badge in its assistant settings section
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9fad060fe7
commit
42db2dd0a1
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
<AssistantSettingsModal bind:this={assistantSettings} />
|
||||
<Tooltip small placement="top">
|
||||
<Button
|
||||
unifiedSize="2xs"
|
||||
variant="subtle"
|
||||
iconOnly
|
||||
startIcon={{ icon: SlidersHorizontal }}
|
||||
aria-label="Assistant settings"
|
||||
onClick={() => assistantSettings?.open()}
|
||||
/>
|
||||
{#snippet text()}
|
||||
<div class="max-w-64 text-xs">
|
||||
<p class="font-semibold">Assistant settings</p>
|
||||
<p class="mt-1"
|
||||
>The tools, skills, instructions and MCP servers this chat can use.</p
|
||||
>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Tooltip>
|
||||
{/if}
|
||||
|
||||
{#if chatHost.mode === AIMode.APP && appContext && (appContext.inspectorElement || appContext.codeSelection)}
|
||||
@@ -1476,3 +1502,8 @@ the panel, or the Escape-to-stop focus check would wrongly reject them. -->
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<!-- Outside the composer: Home's folded composer drops its toolbar, and the folder badges open
|
||||
this without unfolding it. -->
|
||||
{#if chatHost.mode === AIMode.GLOBAL}
|
||||
<AssistantSettingsModal bind:this={assistantSettings} />
|
||||
{/if}
|
||||
|
||||
@@ -55,7 +55,12 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
saveFolderInstruction,
|
||||
type FolderInstructionRow
|
||||
} from './folderInstructions'
|
||||
import { buildSkillTree, countSkills, type SkillTreeNode } from './skills/skillTree'
|
||||
import {
|
||||
buildSkillTree,
|
||||
countSkills,
|
||||
foldedByDefault,
|
||||
type SkillTreeNode
|
||||
} from './skills/skillTree'
|
||||
|
||||
const operatingUser = useOperatingUser()
|
||||
const actingUser = $derived(operatingUser.current)
|
||||
@@ -63,10 +68,13 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
let {
|
||||
ws,
|
||||
active,
|
||||
focusRoot,
|
||||
blocksClose = $bindable()
|
||||
}: {
|
||||
/** The workspace the chat operates on, which is not always the one on screen. */
|
||||
ws: string
|
||||
/** The folder (`f/x` or `u/x`) the modal was opened on: the only top-level one open. */
|
||||
focusRoot?: string
|
||||
/** Whether this is the panel on screen. The list costs a settings read and a
|
||||
* resource listing, so it is fetched when someone looks at instructions rather
|
||||
* than on every open of the modal. */
|
||||
@@ -157,8 +165,9 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
let folderRows = $state<FolderInstructionRow[]>([])
|
||||
let folderLoadError = $state<string | undefined>(undefined)
|
||||
let tree = $derived(buildSkillTree(folderRows))
|
||||
/** Folders the user closed, keyed by full prefix. */
|
||||
/** Folders the user closed or opened, keyed by full prefix. */
|
||||
let collapsed = $state<Record<string, boolean>>({})
|
||||
const isFolded = (path: string) => collapsed[path] ?? foldedByDefault(path, focusRoot)
|
||||
|
||||
// The folder instruction on the detail page: what Monaco holds against what was read.
|
||||
let folderContent = $state('')
|
||||
@@ -175,7 +184,8 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
let folderChanged = $derived(
|
||||
detail?.kind === 'new'
|
||||
? folderContent.trim() !== ''
|
||||
: detail?.kind === 'folder' && folderContent !== folderOriginal
|
||||
: detail?.kind === 'folder' &&
|
||||
(folderContent !== folderOriginal || newPath !== detail.row.path)
|
||||
)
|
||||
|
||||
let dirty = $derived(workspaceChanged || userChanged || folderChanged)
|
||||
@@ -315,6 +325,12 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
bodyEditor?.setCode(next)
|
||||
}
|
||||
|
||||
/** Back on the list with the folds reset, for `focusRoot` to decide them. */
|
||||
export function showFolder() {
|
||||
closeDetail()
|
||||
collapsed = {}
|
||||
}
|
||||
|
||||
/** Lands on the rendered instructions: reading them is the common reason to open
|
||||
* them, and the header's View/Edit switch is one click from the other half. */
|
||||
async function openFolder(row: FolderInstructionRow) {
|
||||
@@ -332,6 +348,8 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
if (source !== ws || seq !== visit) return
|
||||
setFolderContent(body)
|
||||
folderOriginal = body
|
||||
newPath = row.path
|
||||
editorSeq++
|
||||
folderMode = 'view'
|
||||
opened = { workspace: source, detail: { kind: 'folder', row } }
|
||||
detailOpen = true
|
||||
@@ -387,7 +405,8 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
if (current?.kind !== 'folder' && current?.kind !== 'new') return
|
||||
if (blockedByPendingFork()) return
|
||||
const target = ws
|
||||
const path = current.kind === 'new' ? newPath : current.row.path
|
||||
const path = newPath
|
||||
const from = current.kind === 'folder' ? current.row.path : undefined
|
||||
// Monaco hands its text to `folderContent` on a debounce, so the last keystrokes
|
||||
// before a quick click would otherwise be left out of the save.
|
||||
bodyEditor?.flushPendingChanges()
|
||||
@@ -395,14 +414,17 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
const seq = visit
|
||||
saving = true
|
||||
try {
|
||||
await saveFolderInstruction(target, path, content, { create: current.kind === 'new' })
|
||||
await saveFolderInstruction(target, path, content, {
|
||||
create: current.kind === 'new',
|
||||
from
|
||||
})
|
||||
sendUserToast(current.kind === 'new' ? `Added ${path}` : `Saved ${path}`)
|
||||
await loadFolders(target)
|
||||
refreshChat(target)
|
||||
// Another instruction opened meanwhile owns the editor now.
|
||||
if (seq !== visit) return
|
||||
folderOriginal = content
|
||||
if (current.kind === 'new') {
|
||||
if (path !== from) {
|
||||
const row = folderRows.find((r) => r.path === path)
|
||||
if (row) opened = { workspace: target, detail: { kind: 'folder', row } }
|
||||
folderMode = 'view'
|
||||
@@ -599,10 +621,10 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
<button
|
||||
type="button"
|
||||
class="w-full flex items-center gap-2 px-2 py-2 text-left rounded-md hover:bg-surface-hover"
|
||||
aria-expanded={!collapsed[node.path]}
|
||||
onclick={() => (collapsed[node.path] = !collapsed[node.path])}
|
||||
aria-expanded={!isFolded(node.path)}
|
||||
onclick={() => (collapsed[node.path] = !isFolded(node.path))}
|
||||
>
|
||||
{#if collapsed[node.path]}
|
||||
{#if isFolded(node.path)}
|
||||
<ChevronRight size={14} class="text-tertiary shrink-0" />
|
||||
{:else}
|
||||
<ChevronDown size={14} class="text-tertiary shrink-0" />
|
||||
@@ -618,7 +640,7 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
<span class="text-xs font-normal text-emphasis truncate">{node.label}</span>
|
||||
<span class="text-2xs text-secondary">{countSkills(node)}</span>
|
||||
</button>
|
||||
{#if !collapsed[node.path]}
|
||||
{#if !isFolded(node.path)}
|
||||
<div class="pl-4 flex flex-col gap-0.5">
|
||||
{#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
|
||||
</div>
|
||||
</div>
|
||||
<div class="{folderMode === 'edit' ? 'flex' : 'hidden'} flex-col gap-3">
|
||||
{#if detail?.kind === 'new'}
|
||||
{#if detail?.kind === 'new' || detail?.kind === 'folder'}
|
||||
<Label label="Path">
|
||||
<span class="text-xs font-normal text-secondary">
|
||||
The folder decides what these cover: every item under it, for everyone who can
|
||||
@@ -786,7 +808,7 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
<Path
|
||||
bind:path={newPath}
|
||||
bind:error={newPathError}
|
||||
initialPath=""
|
||||
initialPath={detail.kind === 'folder' ? detail.row.path : ''}
|
||||
fullNamePlaceholder="AGENTS"
|
||||
kind="resource"
|
||||
workspaceOverride={ws}
|
||||
@@ -822,7 +844,13 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button
|
||||
onClick={() => setFolderContent(folderOriginal)}
|
||||
onClick={() => {
|
||||
setFolderContent(folderOriginal)
|
||||
if (detail?.kind === 'folder' && newPath !== detail.row.path) {
|
||||
newPath = detail.row.path
|
||||
editorSeq++
|
||||
}
|
||||
}}
|
||||
variant="subtle"
|
||||
unifiedSize="sm"
|
||||
startIcon={{ icon: RotateCcw }}
|
||||
@@ -835,15 +863,27 @@ its block on a detail page laid over the list, like a skill in the Skills sectio
|
||||
variant="accent"
|
||||
unifiedSize="sm"
|
||||
startIcon={{ icon: detail?.kind === 'new' ? Plus : Pencil }}
|
||||
disabled={saving ||
|
||||
!folderChanged ||
|
||||
(detail?.kind === 'new' && (!newPath || !!newPathError))}
|
||||
disabled={saving || !folderChanged || !newPath || !!newPathError}
|
||||
>
|
||||
{detail?.kind === 'new' ? 'Add instructions' : 'Save instructions'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{#if detail?.kind === 'folder'}
|
||||
<div class="flex items-center gap-1 text-xs text-secondary">
|
||||
Stored as an <code>ai_instruction</code> resource.
|
||||
<Button
|
||||
href="/resources?path={encodeURIComponent(detail.row.path)}&workspace={ws}"
|
||||
target="_blank"
|
||||
variant="subtle"
|
||||
unifiedSize="xs"
|
||||
endIcon={{ icon: ExternalLink }}
|
||||
>
|
||||
Open in Resources
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</Section>
|
||||
</div>
|
||||
|
||||
@@ -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<string | undefined>(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
|
||||
|
||||
<svelte:window onkeydown={onKeydown} />
|
||||
|
||||
<Tooltip small placement="top">
|
||||
<Button
|
||||
unifiedSize="2xs"
|
||||
variant="subtle"
|
||||
iconOnly
|
||||
startIcon={{ icon: SlidersHorizontal }}
|
||||
aria-label="Assistant settings"
|
||||
onClick={() => open()}
|
||||
/>
|
||||
{#snippet text()}
|
||||
<div class="max-w-64 text-xs">
|
||||
<p class="font-semibold">Assistant settings</p>
|
||||
<p class="mt-1">The tools, skills, instructions and MCP servers this chat can use.</p>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Tooltip>
|
||||
|
||||
<Modal2
|
||||
bind:isOpen
|
||||
title="Assistant settings"
|
||||
@@ -254,7 +259,9 @@ callers that already know which section they mean, such as the "+" menu's Manage
|
||||
laid over each other, and each keeps a scroll position of its own. -->
|
||||
<div class="{section === 'skills' ? 'flex' : 'hidden'} grow min-h-0 flex-col overflow-hidden">
|
||||
<AssistantSkillsSection
|
||||
bind:this={skillsSection}
|
||||
{ws}
|
||||
{focusRoot}
|
||||
active={section === 'skills'}
|
||||
bind:count={skillCount}
|
||||
bind:blocksClose={skillsBusy}
|
||||
@@ -266,7 +273,9 @@ callers that already know which section they mean, such as the "+" menu's Manage
|
||||
: 'hidden'} grow min-h-0 flex-col overflow-hidden"
|
||||
>
|
||||
<AssistantInstructionsSection
|
||||
bind:this={instructionsSection}
|
||||
{ws}
|
||||
{focusRoot}
|
||||
active={section === 'instructions'}
|
||||
bind:blocksClose={instructionsBusy}
|
||||
/>
|
||||
|
||||
@@ -30,6 +30,7 @@ and the actions that create, edit, import and delete them.
|
||||
BookOpen,
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
ExternalLink,
|
||||
Eye,
|
||||
Folder,
|
||||
FolderTree,
|
||||
@@ -45,7 +46,6 @@ and the actions that create, edit, import and delete them.
|
||||
import { forgetSkill, isSkillEnabled, setSkillEnabled } from './skills/enabledSkills'
|
||||
import { ownerRoot } from './workingScope'
|
||||
import {
|
||||
ambiguousSkillNames,
|
||||
deleteSkillResource,
|
||||
listSkillResources,
|
||||
readSkillBody,
|
||||
@@ -62,9 +62,9 @@ and the actions that create, edit, import and delete them.
|
||||
import {
|
||||
buildSkillTree,
|
||||
countSkills,
|
||||
foldedByDefault,
|
||||
folderKey,
|
||||
nodeSkills,
|
||||
skillFolderPaths,
|
||||
skillKey,
|
||||
visibleEntries,
|
||||
type SkillTreeEntry,
|
||||
@@ -74,11 +74,14 @@ and the actions that create, edit, import and delete them.
|
||||
let {
|
||||
ws,
|
||||
active,
|
||||
focusRoot,
|
||||
count = $bindable(),
|
||||
blocksClose = $bindable()
|
||||
}: {
|
||||
/** The workspace the chat operates on, which is not always the one on screen. */
|
||||
ws: string
|
||||
/** The folder (`f/x` or `u/x`) the modal was opened on: the only top-level one open. */
|
||||
focusRoot?: string
|
||||
/** Whether this is the panel on screen. Gates the editor page's build: it is
|
||||
* worth paying for once someone is looking at skills, not on every open of a
|
||||
* modal whose other three sections have nothing to do with them. */
|
||||
@@ -190,25 +193,24 @@ What the assistant should do when this skill applies.
|
||||
let pendingSkipped: string[] = $state([])
|
||||
let overwriteChoices: Record<string, boolean> = $state({})
|
||||
|
||||
let ambiguous = $derived(ambiguousSkillNames(skills))
|
||||
// Skills in one folder are a list; spread over several, the folder is what tells
|
||||
// two of them apart, so they are grouped under it instead.
|
||||
let grouped = $derived(skillFolderPaths(skills).size > 1)
|
||||
let tree = $derived(buildSkillTree(skills))
|
||||
/** Folders the user closed, keyed by full prefix. Everything opens expanded: the
|
||||
* point of this list is seeing what the assistant carries. */
|
||||
/** Folders the user closed or opened, keyed by full prefix. Everything opens expanded
|
||||
* unless a folder is focused: the point of this list is seeing what the assistant carries. */
|
||||
let collapsed = $state<Record<string, boolean>>({})
|
||||
const isFolded = (path: string) => collapsed[path] ?? foldedByDefault(path, focusRoot)
|
||||
|
||||
/** Back on the list with the folds reset, for `focusRoot` to decide them. An editor
|
||||
* holding unsaved text stays open, as it does when the section is parked. */
|
||||
export function showFolder() {
|
||||
if (!contentChanged && !pathChanged) editorOpen = false
|
||||
collapsed = {}
|
||||
}
|
||||
/** The list top to bottom as it stands, for the keyboard to walk. Empty whenever
|
||||
* the rows are not the thing on screen — a reload after a save or a delete shows
|
||||
* the loading line, and a failed one shows the error, both over the rows this
|
||||
* would otherwise still walk. Flat mode has no folders, so the same keys drive
|
||||
* both layouts. */
|
||||
* would otherwise still walk. */
|
||||
let entries: SkillTreeEntry<Row>[] = $derived(
|
||||
loading || loadError !== undefined
|
||||
? []
|
||||
: grouped
|
||||
? visibleEntries(tree, (path) => collapsed[path] === true)
|
||||
: skills.map((skill) => ({ kind: 'skill', key: skillKey(skill.path), skill }))
|
||||
loading || loadError !== undefined ? [] : visibleEntries(tree, isFolded)
|
||||
)
|
||||
/** Where each entry sits in the walk, so a row rendered deep in the tree can say
|
||||
* whether it is the highlighted one. */
|
||||
@@ -233,7 +235,7 @@ What the assistant should do when this skill applies.
|
||||
const entry = entries[index]
|
||||
if (entry === undefined) return
|
||||
if (entry.kind === 'skill') openSkill(entry.skill)
|
||||
else fold(entry.key, entry.node.path, !collapsed[entry.node.path])
|
||||
else fold(entry.key, entry.node.path, !isFolded(entry.node.path))
|
||||
}
|
||||
// No `activateEnterFrom`: Enter is answered by `onListKeydown`, which does not
|
||||
// depend on where focus happens to be.
|
||||
@@ -409,7 +411,7 @@ What the assistant should do when this skill applies.
|
||||
} else if (event.key === 'Enter') {
|
||||
answer()
|
||||
if (current.kind === 'skill') openSkill(current.skill)
|
||||
else fold(current.key, current.node.path, !collapsed[current.node.path])
|
||||
else fold(current.key, current.node.path, !isFolded(current.node.path))
|
||||
} else if (event.key === 'ArrowRight') {
|
||||
answer()
|
||||
if (current.kind === 'skill') {
|
||||
@@ -417,14 +419,14 @@ What the assistant should do when this skill applies.
|
||||
// `PagedContent`, which steps to the editor page — showing whichever skill
|
||||
// it was last parked on, not this one.
|
||||
openSkill(current.skill)
|
||||
} else if (collapsed[current.node.path]) {
|
||||
} else if (isFolded(current.node.path)) {
|
||||
fold(current.key, current.node.path, false)
|
||||
} else {
|
||||
// Into what opening it revealed: the next row down is its first child.
|
||||
highlight.move(1)
|
||||
}
|
||||
} else if (event.key === 'ArrowLeft') {
|
||||
if (current.kind === 'folder' && !collapsed[current.node.path]) {
|
||||
if (current.kind === 'folder' && !isFolded(current.node.path)) {
|
||||
answer()
|
||||
fold(current.key, current.node.path, true)
|
||||
} else if (current.parentKey !== undefined) {
|
||||
@@ -946,15 +948,9 @@ What the assistant should do when this skill applies.
|
||||
/>
|
||||
{:else}
|
||||
<div class="flex flex-col gap-0.5">
|
||||
{#if grouped}
|
||||
{#each tree as node (node.path)}
|
||||
{@render folder(node, true)}
|
||||
{/each}
|
||||
{:else}
|
||||
{#each skills as skill (skill.path)}
|
||||
{@render row(skill)}
|
||||
{/each}
|
||||
{/if}
|
||||
{#each tree as node (node.path)}
|
||||
{@render folder(node, true)}
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</Section>
|
||||
@@ -971,7 +967,7 @@ What the assistant should do when this skill applies.
|
||||
<span class="truncate leading-5">
|
||||
<!-- Grouped, the folder above the row is what tells two skills of the same
|
||||
name apart; flat, the path has to do it. -->
|
||||
{!grouped && ambiguous.has(skill.name) ? skill.path : skill.name}
|
||||
{skill.name}
|
||||
</span>
|
||||
{/snippet}
|
||||
{@const note = scopeNote(skill.path)}
|
||||
@@ -1044,10 +1040,10 @@ What the assistant should do when this skill applies.
|
||||
<button
|
||||
type="button"
|
||||
class="grow min-w-0 flex items-center gap-2 px-2 py-2 text-left"
|
||||
aria-expanded={!collapsed[node.path]}
|
||||
onclick={() => fold(folderKey(node.path), node.path, !collapsed[node.path])}
|
||||
aria-expanded={!isFolded(node.path)}
|
||||
onclick={() => fold(folderKey(node.path), node.path, !isFolded(node.path))}
|
||||
>
|
||||
{#if collapsed[node.path]}
|
||||
{#if isFolded(node.path)}
|
||||
<ChevronRight size={14} class="text-tertiary shrink-0" />
|
||||
{:else}
|
||||
<ChevronDown size={14} class="text-tertiary shrink-0" />
|
||||
@@ -1071,7 +1067,7 @@ What the assistant should do when this skill applies.
|
||||
on:change={async (e) => await toggleFolder(node, e.detail)}
|
||||
/>
|
||||
</div>
|
||||
{#if !collapsed[node.path]}
|
||||
{#if !isFolded(node.path)}
|
||||
<div class="pl-4 flex flex-col gap-0.5">
|
||||
{#each node.children as child (child.path)}
|
||||
{@render folder(child, false)}
|
||||
@@ -1103,10 +1099,10 @@ What the assistant should do when this skill applies.
|
||||
Skills
|
||||
</Button>
|
||||
</div>
|
||||
<!-- `headerClass` keeps a long skill name on one line: the View/Edit group shares
|
||||
<!-- `headerClass` keeps a long skill path on one line: the View/Edit group shares
|
||||
the header row and would otherwise wrap the title under itself. -->
|
||||
<Section
|
||||
label={editing ? editing.name : 'New skill'}
|
||||
label={editing ? editing.path : 'New skill'}
|
||||
wrapperClass="mt-1"
|
||||
headerClass="min-w-0 truncate pr-2"
|
||||
>
|
||||
@@ -1204,6 +1200,20 @@ What the assistant should do when this skill applies.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{#if editing}
|
||||
<div class="flex items-center gap-1 text-xs text-secondary">
|
||||
Stored as an <code>ai_skill</code> resource.
|
||||
<Button
|
||||
href="/resources?path={encodeURIComponent(editing.path)}&workspace={ws}"
|
||||
target="_blank"
|
||||
variant="subtle"
|
||||
unifiedSize="xs"
|
||||
endIcon={{ icon: ExternalLink }}
|
||||
>
|
||||
Open in Resources
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</Section>
|
||||
</div>
|
||||
|
||||
@@ -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<void> {
|
||||
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 } }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T> = {
|
||||
|
||||
type Skill = { path: string; name: string }
|
||||
|
||||
/** The folders holding these skills — one entry per distinct parent path. */
|
||||
export function skillFolderPaths(skills: readonly Skill[]): Set<string> {
|
||||
return new Set(skills.map((s) => s.path.split('/').slice(0, -1).join('/')))
|
||||
}
|
||||
|
||||
/** Every skill under `node`, its subfolders included. */
|
||||
export function countSkills<T>(node: SkillTreeNode<T>): number {
|
||||
return node.skills.length + node.children.reduce((n, c) => n + countSkills(c), 0)
|
||||
@@ -42,6 +33,12 @@ export type SkillTreeEntry<T> = { 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}`
|
||||
}
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<!--
|
||||
@component
|
||||
What a folder or user row carries for the assistant: its instructions, skills and MCP servers,
|
||||
counted on the row and named in a popover.
|
||||
one button each, counted. A click opens that section of Assistant settings on the folder.
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/components/common'
|
||||
import Popover from '$lib/components/meltComponents/Popover.svelte'
|
||||
import { BookOpen, ExternalLink } from 'lucide-svelte'
|
||||
import { BookOpen, Plug, ScrollText } from 'lucide-svelte'
|
||||
import { homeComposerContext } from '../sessions/homeComposerContext.svelte'
|
||||
import { scopeBadge, scopeOption, scopeRule } from '../copilot/chat/workingScope'
|
||||
import { scopeOption } from '../copilot/chat/workingScope'
|
||||
|
||||
let { root }: { root: string } = $props()
|
||||
|
||||
@@ -16,60 +15,48 @@ counted on the row and named in a popover.
|
||||
const row = $derived(
|
||||
manager ? scopeOption(root, manager.scopeIdentity, manager.scopeResources) : undefined
|
||||
)
|
||||
const badge = $derived(row ? scopeBadge(row) : '')
|
||||
const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? '' : 's'}`
|
||||
const parts = $derived(
|
||||
row
|
||||
? [
|
||||
{
|
||||
section: 'instructions' as const,
|
||||
icon: ScrollText,
|
||||
count: row.instructions.length,
|
||||
label: plural(row.instructions.length, 'instruction')
|
||||
},
|
||||
{
|
||||
section: 'skills' as const,
|
||||
icon: BookOpen,
|
||||
count: row.skills.length,
|
||||
label: plural(row.skills.length, 'skill')
|
||||
},
|
||||
{
|
||||
section: 'mcp' as const,
|
||||
icon: Plug,
|
||||
count: row.mcpServers.length,
|
||||
label: `${row.mcpServers.length} MCP`
|
||||
}
|
||||
].filter((p) => p.count > 0)
|
||||
: []
|
||||
)
|
||||
</script>
|
||||
|
||||
{#if row && badge}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div onclick={(e) => e.stopPropagation()}>
|
||||
<Popover placement="bottom-end" contentClasses="p-3 w-72 flex flex-col gap-2 text-xs">
|
||||
{#snippet trigger()}
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="2xs"
|
||||
startIcon={{ icon: BookOpen }}
|
||||
nonCaptureEvent
|
||||
>
|
||||
{badge}
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#snippet content()}
|
||||
{#if row.instructions.length}
|
||||
<div>
|
||||
<p class="text-2xs text-secondary">Instructions</p>
|
||||
{#each row.instructions as path (path)}
|
||||
<p class="font-mono text-primary">{path}</p>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{#if row.skills.length}
|
||||
<div>
|
||||
<p class="text-2xs text-secondary">Skills</p>
|
||||
{#each row.skills as path (path)}
|
||||
<p class="font-mono text-primary">{path}</p>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{#if row.mcpServers.length}
|
||||
<div>
|
||||
<p class="text-2xs text-secondary">MCP servers</p>
|
||||
{#each row.mcpServers as path (path)}
|
||||
<p class="font-mono text-primary">{path}</p>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<p class="text-2xs text-secondary">{scopeRule(root)}</p>
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="xs"
|
||||
endIcon={{ icon: ExternalLink }}
|
||||
href="/resources?owner={encodeURIComponent(root)}"
|
||||
btnClasses="!justify-start !px-0"
|
||||
>
|
||||
Open {root} in Resources
|
||||
</Button>
|
||||
{/snippet}
|
||||
</Popover>
|
||||
</div>
|
||||
{#if parts.length}
|
||||
<span class="inline-flex items-center gap-0.5">
|
||||
{#each parts as part (part.section)}
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="2xs"
|
||||
startIcon={{ icon: part.icon }}
|
||||
title="Open in Assistant settings"
|
||||
onClick={(e) => {
|
||||
e?.stopPropagation()
|
||||
homeComposerContext.openSettings(part.section, root)
|
||||
}}
|
||||
>
|
||||
{part.label}
|
||||
</Button>
|
||||
{/each}
|
||||
</span>
|
||||
{/if}
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
},
|
||||
focus: () => aiChat?.focusInput(),
|
||||
flash: () => aiChat?.flashComposer(),
|
||||
openSettings: (section, root) => aiChat?.openAssistantSettings(section, root),
|
||||
runtime
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user