From 9fad060fe729a537c4ccadac076cd71f4bfaea71 Mon Sep 17 00:00:00 2001 From: Guilhem Lemouel Date: Thu, 29 Oct 2026 03:53:27 -0700 Subject: [PATCH] feat: mention cards, folders and users from home's lists Co-Authored-By: Claude Opus 5.5 --- .../lib/components/copilot/chat/context.ts | 24 +++++++---- .../components/copilot/chat/global/core.ts | 8 ++-- .../src/lib/components/copilot/chat/shared.ts | 8 ++-- .../components/home/HomeQuickAccess.svelte | 43 +++++++++++++++---- .../src/lib/components/home/TreeView.svelte | 36 +++++++++++++--- 5 files changed, 90 insertions(+), 29 deletions(-) diff --git a/frontend/src/lib/components/copilot/chat/context.ts b/frontend/src/lib/components/copilot/chat/context.ts index 465f3bbb92..b025a3d407 100644 --- a/frontend/src/lib/components/copilot/chat/context.ts +++ b/frontend/src/lib/components/copilot/chat/context.ts @@ -290,7 +290,8 @@ export interface WorkspaceAppElement { summary?: string } -/** Workspace folder context element — a whole `f/`, its items read by the chat on +/** Workspace folder context element — everything under a path prefix: a folder (`f/team`, or a + * subfolder of an owner) or a user's own items (`u/alice`). Its items are read by the chat on * demand like any other workspace reference. */ export interface WorkspaceFolderElement { type: 'workspace_folder' @@ -298,26 +299,33 @@ export interface WorkspaceFolderElement { title: string } -export function folderContextElement(path: string): WorkspaceFolderElement & { deletable: boolean } { +export function folderContextElement( + path: string +): WorkspaceFolderElement & { deletable: boolean } { return { type: 'workspace_folder', path, title: path, deletable: true } } -const FOLDER_DIR_PREFIX = dirKey('all', 'f/') +/** Whether a folder context path is a user's own items (`u/alice`) rather than a folder. */ +export function isUserContextPath(path: string): boolean { + return /^u\/[^/]+$/.test(path) +} -/** Opens every `f/` folder of a flat workspace tree (any depth) on a leaf that picks the folder - * itself, so a folder is taken as context from inside it, or by searching its path. */ +const DIR_PREFIX = dirKey('all', '') + +/** Opens every `f/` and `u/` directory of a flat workspace tree (any depth) on a leaf that picks + * the directory itself, so it is taken as context from inside it, or by searching its path. */ export function withFolderContextLeaves( nodes: DrillNode[] ): DrillNode[] { return nodes.map((node) => { if (node.type !== 'branch') return node const children = withFolderContextLeaves(node.children) - if (!node.key.startsWith(FOLDER_DIR_PREFIX)) return { ...node, children } - const path = node.key.slice(FOLDER_DIR_PREFIX.length - 'f/'.length) + const path = node.key.startsWith(DIR_PREFIX) ? node.key.slice(DIR_PREFIX.length) : '' + if (!/^[fu]\/./.test(path)) return { ...node, children } const leaf: DrillLeaf = { type: 'leaf', key: `folder:${path}`, - label: 'Whole folder', + label: isUserContextPath(path) ? 'All their items' : 'Whole folder', secondary: path, icon: Folder, data: folderContextElement(path), diff --git a/frontend/src/lib/components/copilot/chat/global/core.ts b/frontend/src/lib/components/copilot/chat/global/core.ts index c1634e9897..7011a65bdf 100644 --- a/frontend/src/lib/components/copilot/chat/global/core.ts +++ b/frontend/src/lib/components/copilot/chat/global/core.ts @@ -173,7 +173,7 @@ import { scriptLangToEditorLang } from '$lib/scripts' import { appFileEditorLang } from '../appFileEditorLang' import { searchDocsTool, readDocsPageTool } from '../docs/core' import { createDbSchemaTool } from '../script/core' -import { isMentionContext, type ContextElement } from '../context' +import { isMentionContext, isUserContextPath, type ContextElement } from '../context' import { getDatatableTools } from '../datatableTools' import { getDatatableMigrationTools } from '../datatableMigrationTools' import { getDucklakeTools } from '../ducklakeTools' @@ -5886,7 +5886,9 @@ function createVariableToDraftState( // `null` clears and omitted keeps the base's. The draft stores a cleared expiry as // `undefined`, since a stored draft goes through a JSON round-trip. value_valid_until: - args.value_valid_until === null ? undefined : (args.value_valid_until ?? base?.value_valid_until) + args.value_valid_until === null + ? undefined + : (args.value_valid_until ?? base?.value_valid_until) } } @@ -9785,7 +9787,7 @@ export function prepareGlobalUserMessage( content += '## SELECTED CONTEXT\n' for (const context of selectedWorkspaceItems) { if (context.type === 'workspace_folder') { - content += `- type: folder, path: ${context.path} (its items: list_workspace_items with path_prefix "${context.path}/")\n` + content += `- type: ${isUserContextPath(context.path) ? 'user' : 'folder'}, path: ${context.path} (its items: list_workspace_items with path_prefix "${context.path}/")\n` continue } const itemType = diff --git a/frontend/src/lib/components/copilot/chat/shared.ts b/frontend/src/lib/components/copilot/chat/shared.ts index 389175bd6b..b87121be25 100644 --- a/frontend/src/lib/components/copilot/chat/shared.ts +++ b/frontend/src/lib/components/copilot/chat/shared.ts @@ -39,6 +39,7 @@ import type { PasteAttachment } from './pasteTokens' import { dataUrlToImagePart, type AttachedImage } from './imageUtils' import type { AttachedTextFile } from './textFileUtils' import type { CodePieceElement, ContextElement, FlowModuleCodePieceElement } from './context' +import { isUserContextPath } from './context' import { workspaceStore } from '$lib/stores' import type { ExtendedOpenFlow } from '$lib/components/flows/types' import { findModuleInFlow, findModuleInModules } from '$lib/components/flows/flowTree' @@ -469,7 +470,7 @@ export function buildContextString(selectedContext: ContextElement[]): string { if (!workspaceItemsContext) { workspaceItemsContext = 'SELECTED WORKSPACE ITEMS:\n' } - workspaceItemsContext += `- type: folder, path: ${context.path}\n` + workspaceItemsContext += `- type: ${isUserContextPath(context.path) ? 'user' : 'folder'}, path: ${context.path}\n` } } @@ -1162,10 +1163,7 @@ export async function processToolCall({ // call back for a retry: asked before it, the user would answer twice. const workingScope = toolCallbacks.workingScope const writes = - !!tool && - tool.planModeSafe !== true && - !tool.viewOnly && - !isRunTool(tool.def.function.name) + !!tool && tool.planModeSafe !== true && !tool.viewOnly && !isRunTool(tool.def.function.name) const scope = writes ? workingScope?.scope() : undefined const outsidePath = scope?.outsidePath(args) let scopeNote = '' diff --git a/frontend/src/lib/components/home/HomeQuickAccess.svelte b/frontend/src/lib/components/home/HomeQuickAccess.svelte index fe173c1c36..fc9c664fe6 100644 --- a/frontend/src/lib/components/home/HomeQuickAccess.svelte +++ b/frontend/src/lib/components/home/HomeQuickAccess.svelte @@ -125,17 +125,26 @@ } } - // The row menus' actions that need nothing but the kind and path. Moving, deleting, - // deploying and sharing need the full item and the row's own drawers, so they stay there. - async function menuItems(item: Entry, favorite: boolean): Promise { - const kind = await editorKind(item) - const base = kind === 'raw_app' ? 'apps_raw' : `${kind}s` - const contextElement = itemContextElement({ + function contextElementFor(item: Entry, kind: RecentKind) { + return itemContextElement({ kind: kind === 'raw_app' ? 'app' : kind, rawApp: kind === 'raw_app', path: item.path, summary: item.title === item.path ? undefined : item.title }) + } + + async function mention(item: Entry) { + const element = contextElementFor(item, await editorKind(item)) + if (element) await homeComposerContext.attach(element) + } + + // The row menus' actions that need nothing but the kind and path. Moving, deleting, + // deploying and sharing need the full item and the row's own drawers, so they stay there. + async function menuItems(item: Entry, favorite: boolean): Promise { + const kind = await editorKind(item) + const base = kind === 'raw_app' ? 'apps_raw' : `${kind}s` + const contextElement = contextElementFor(item, kind) return [ { displayName: 'Add to AI session context', @@ -365,7 +374,7 @@ > {#if !favorite && item.at} (now = Date.now())} role="note" @@ -373,9 +382,27 @@ {/if} -
+ +
menuItems(item, favorite)} size="xs" fixedHeight={false} />
+ +
{/snippet} diff --git a/frontend/src/lib/components/home/TreeView.svelte b/frontend/src/lib/components/home/TreeView.svelte index 0a189ebef5..758a443072 100644 --- a/frontend/src/lib/components/home/TreeView.svelte +++ b/frontend/src/lib/components/home/TreeView.svelte @@ -109,6 +109,7 @@ ? `f/${item.folderName}` : undefined ) + const mentionRoot = $derived(homeComposerContext.available ? badgeRoot : undefined) // Hidden while searching: pipelines aren't part of the text filter (the list // view hides their rows on a query too), so a folder matching the search @@ -287,10 +288,35 @@ } -{#snippet folderBadge()} - {#if badgeRoot} - - {/if} +{#snippet folderTrailing()} + + {#if badgeRoot} + + {/if} + {#if mentionRoot} + {@const path = mentionRoot} + + + + + {/if} + {/snippet} {#snippet manageFolderMenu()} @@ -332,7 +358,7 @@ onToggle={toggleOwner} indent={visualDepth * 16} actions={onManageFolder && depth === 0 && isFolder(item) ? manageFolderMenu : undefined} - trailing={badgeRoot ? folderBadge : undefined} + trailing={badgeRoot ? folderTrailing : undefined} > {#snippet detail()} {#if ownerCount != undefined}