From 1d3fcb4a06c26f0007a95fbe40cc55761d4988f5 Mon Sep 17 00:00:00 2001 From: hugocasa Date: Mon, 23 Nov 2026 21:26:18 +0100 Subject: [PATCH 01/28] fix: harden telemetry submission (#12606) * [ee] fix: harden telemetry submission Co-Authored-By: Claude Opus 5.5 * chore: update ee-repo-ref to fe0b119cd8292b1dcaf12100192ab7f4ec53fb48 This commit updates the EE repository reference after PR #1003 was merged in windmill-ee-private. Previous ee-repo-ref: ddad2700daf20a9680de917ab0ff78a5e1444758 New ee-repo-ref: fe0b119cd8292b1dcaf12100192ab7f4ec53fb48 Automated by sync-ee-ref workflow. --------- Co-authored-by: Claude Opus 5.5 Co-authored-by: windmill-internal-app[bot] --- backend/ee-repo-ref.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/ee-repo-ref.txt b/backend/ee-repo-ref.txt index 771a86c39d..2765a40dd8 100644 --- a/backend/ee-repo-ref.txt +++ b/backend/ee-repo-ref.txt @@ -1 +1 @@ -6c06d688fe435630e2827bc177f066d2646bb768 +fe0b119cd8292b1dcaf12100192ab7f4ec53fb48 From 3a720da989416caabed08e9659b81f04cf510ac1 Mon Sep 17 00:00:00 2001 From: Guilhem Date: Mon, 23 Nov 2026 21:26:33 +0100 Subject: [PATCH 02/28] fix: derive chat lookup grouping from tool definitions (#12596) Co-authored-by: Claude Opus 5.5 --- .../copilot/chat/AIChatDisplay.svelte | 2 +- .../copilot/chat/AIChatManager.svelte.ts | 6 ++ .../lib/components/copilot/chat/app/core.ts | 6 ++ .../copilot/chat/artifacts/artifactTools.ts | 3 + .../components/copilot/chat/chatViewHost.ts | 4 + .../copilot/chat/datatableMigrationTools.ts | 1 + .../components/copilot/chat/datatableTools.ts | 2 + .../lib/components/copilot/chat/docs/core.ts | 2 + .../components/copilot/chat/ducklakeTools.ts | 2 + .../copilot/chat/files/fileTools.ts | 2 + .../lib/components/copilot/chat/flow/core.ts | 4 + .../components/copilot/chat/global/core.ts | 21 ++++ .../copilot/chat/global/mcpTools.ts | 3 +- .../chat/global/sessionToolset.test.ts | 15 +++ .../chat/global/workspaceSettingsTools.ts | 1 + .../components/copilot/chat/lookupTools.ts | 41 +++++++ .../components/copilot/chat/navigator/core.ts | 3 + .../components/copilot/chat/pipeline/core.ts | 2 + .../chat/readOnlyChatViewHost.svelte.ts | 2 + .../components/copilot/chat/script/core.ts | 4 + .../src/lib/components/copilot/chat/shared.ts | 8 ++ .../copilot/chat/toolGroups.test.ts | 50 ++++++--- .../lib/components/copilot/chat/toolGroups.ts | 100 ++++++++---------- .../lib/components/copilot/chat/web/core.ts | 2 + .../components/copilot/chat/workspaceTools.ts | 8 +- .../conversations/flowChatViewHost.svelte.ts | 3 + .../recording/AgentRecordingTranscript.svelte | 3 +- .../sessions/SharedSessionTranscript.svelte | 3 +- 28 files changed, 226 insertions(+), 77 deletions(-) create mode 100644 frontend/src/lib/components/copilot/chat/lookupTools.ts diff --git a/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte b/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte index ecc11a99e5..ab3bdbc532 100644 --- a/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte +++ b/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte @@ -200,7 +200,7 @@ let plusMenuOpen = $state(false) let editingMessageIndex = $state(null) const groupChatItems = createChatItemGrouper() - const chatItems = $derived(groupChatItems(messages)) + const chatItems = $derived(groupChatItems(messages, chatHost.lookupTools)) // Mounting a message parses its markdown, so a long transcript mounted at once blocks the // page for every message in it. Only the tail is mounted when a transcript arrives; older diff --git a/frontend/src/lib/components/copilot/chat/AIChatManager.svelte.ts b/frontend/src/lib/components/copilot/chat/AIChatManager.svelte.ts index d09f452b3e..0504d1673b 100644 --- a/frontend/src/lib/components/copilot/chat/AIChatManager.svelte.ts +++ b/frontend/src/lib/components/copilot/chat/AIChatManager.svelte.ts @@ -203,6 +203,8 @@ import { assembleGlobalTools, type GlobalAssemblyOpts } from './global/globalAssembly' +import type { LookupTools } from './toolGroups' +import { chatLookupTools } from './lookupTools' import { formatChatJobCompletion } from './datatableTools' import { loadMcpServers, type McpServer } from './global/mcpTools' import type { PipelineAIChatHelpers } from './pipeline/core' @@ -927,6 +929,10 @@ export class AIChatManager implements ChatViewHost { ...(this.workModesAvailable && !this.#useOnly ? Object.values(this.#workModeSwitches) : []) ]) ) + // A getter: the manager is built while the tool modules that lookupTools.ts imports still load. + get lookupTools(): LookupTools { + return chatLookupTools() + } /** Whether a tool the call was made with is no longer shipped: a switch to Use withdraws * every write while its card waits. The mode transitions are not assembled, so never are. */ isToolWithdrawn = (toolName: string): boolean => { diff --git a/frontend/src/lib/components/copilot/chat/app/core.ts b/frontend/src/lib/components/copilot/chat/app/core.ts index 5a0ff5cc6d..d276a6f5d2 100644 --- a/frontend/src/lib/components/copilot/chat/app/core.ts +++ b/frontend/src/lib/components/copilot/chat/app/core.ts @@ -524,6 +524,7 @@ export const getAppTools = memo((): Tool[] => [ { def: getListFilesToolDef(), planModeSafe: true, + lookup: true, fn: async ({ helpers, toolId, toolCallbacks }) => { toolCallbacks.setToolStatus(toolId, { content: 'Listing files...' }) const files = helpers.getFiles() @@ -560,6 +561,7 @@ export const getAppTools = memo((): Tool[] => [ { def: getGetFrontendFileToolDef(), planModeSafe: true, + lookup: true, fn: async ({ args, helpers, toolId, toolCallbacks }) => { const parsedArgs = getGetFrontendFileSchema().parse(args) toolCallbacks.setToolStatus(toolId, { @@ -693,6 +695,7 @@ export const getAppTools = memo((): Tool[] => [ { def: getGetBackendRunnableToolDef(), planModeSafe: true, + lookup: true, fn: async ({ args, helpers, toolId, toolCallbacks }) => { const parsedArgs = getGetBackendRunnableSchema().parse(args) toolCallbacks.setToolStatus(toolId, { @@ -781,6 +784,7 @@ export const getAppTools = memo((): Tool[] => [ { def: getLintToolDef(), planModeSafe: true, + lookup: true, fn: async ({ helpers, toolId, toolCallbacks }) => { toolCallbacks.setToolStatus(toolId, { content: 'Linting app...' }) const lintResult = helpers.lint() @@ -803,6 +807,7 @@ export const getAppTools = memo((): Tool[] => [ { def: getListDatatablesToolDef(), planModeSafe: true, + lookup: true, fn: async ({ helpers, toolId, toolCallbacks }) => { toolCallbacks.setToolStatus(toolId, { content: 'Listing datatables...' }) try { @@ -826,6 +831,7 @@ export const getAppTools = memo((): Tool[] => [ { def: getGetDatatableTableSchemaToolDef(), planModeSafe: true, + lookup: true, fn: async ({ args, helpers, toolId, toolCallbacks }) => { const parsedArgs = getGetDatatableTableSchemaSchema().parse(args) toolCallbacks.setToolStatus(toolId, { diff --git a/frontend/src/lib/components/copilot/chat/artifacts/artifactTools.ts b/frontend/src/lib/components/copilot/chat/artifacts/artifactTools.ts index 80f124d383..e064a8a445 100644 --- a/frontend/src/lib/components/copilot/chat/artifacts/artifactTools.ts +++ b/frontend/src/lib/components/copilot/chat/artifacts/artifactTools.ts @@ -234,6 +234,7 @@ export const artifactTools: SessionTool<{}>[] = [ "List the current session's artifacts (id, name, kind, version, role, approvedVersion). `version` is the latest one saved, which is not necessarily the one the user is reading — get_preview_status reports the version they have pinned. `role` is `plan` on the session's one plan document and on nothing else. On that one, `approvedVersion` is the version the user signed off: below `version` means the current text is a proposal they have not agreed to, and absent means nothing here was ever approved." ), planModeSafe: true, + lookup: true, fn: async ({ toolId, toolCallbacks, helpers }) => { const h = helpers as ArtifactToolHelpers const sessionId = h.sessionId @@ -269,6 +270,7 @@ export const artifactTools: SessionTool<{}>[] = [ "Read an artifact's full markdown content by id, at its current or an earlier version." ), planModeSafe: true, + lookup: true, fn: async ({ args, toolId, toolCallbacks, helpers }) => { const parsed = readArtifactSchema.parse(args) const h = helpers as ArtifactToolHelpers @@ -337,6 +339,7 @@ export const artifactTools: SessionTool<{}>[] = [ // How the model recovers the approved plan once a refused draft stands in front of it; // the fail-closed gate would otherwise block that in the posture that needs it. planModeSafe: true, + lookup: true, fn: async ({ args, toolId, toolCallbacks, helpers }) => { const parsed = listArtifactVersionsSchema.parse(args) const h = helpers as ArtifactToolHelpers diff --git a/frontend/src/lib/components/copilot/chat/chatViewHost.ts b/frontend/src/lib/components/copilot/chat/chatViewHost.ts index 0b5f02cfff..6246012827 100644 --- a/frontend/src/lib/components/copilot/chat/chatViewHost.ts +++ b/frontend/src/lib/components/copilot/chat/chatViewHost.ts @@ -11,6 +11,7 @@ import type { AttachedImage } from './imageUtils' import type { AttachedTextFile } from './textFileUtils' import type { PasteAttachment } from './pasteTokens' import type { ScopeDecision } from './workingScope' +import type { LookupTools } from './toolGroups' import type { AttachedFilesStore } from './files/attachedFiles.svelte' import type { SessionArtifactsStore } from './artifacts/artifactsState.svelte' import type { ArtifactVersionTarget } from '$lib/components/sessions/previewRouter' @@ -183,6 +184,9 @@ export interface ChatViewHost { * included. A consumer narrows it by tool metadata; assembling its own list from the * sources behind it is how the advertised set and the sent set drift apart. */ readonly tools: readonly Tool[] + /** Tools whose rows may fold into a run of lookups. Every tool the transcript's chat could + * have called, not only `tools`: a row outlives the request that carried its tool. */ + readonly lookupTools: LookupTools autonomyMode: AIAutonomyMode setAutonomyMode: (mode: AIAutonomyMode) => void /** Use, Plan or Build: offered by a session chat only. */ diff --git a/frontend/src/lib/components/copilot/chat/datatableMigrationTools.ts b/frontend/src/lib/components/copilot/chat/datatableMigrationTools.ts index 8a96c05423..44da8314d7 100644 --- a/frontend/src/lib/components/copilot/chat/datatableMigrationTools.ts +++ b/frontend/src/lib/components/copilot/chat/datatableMigrationTools.ts @@ -124,6 +124,7 @@ export function getDatatableMigrationTools(): SessionTool<{}>[] { requires: NONE, def: getListMigrationsToolDef(), planModeSafe: true, + lookup: true, fn: async (ctx) => { const { datatable_name } = getListMigrationsSchema().parse(ctx.args) ctx.toolCallbacks.setToolStatus(ctx.toolId, { diff --git a/frontend/src/lib/components/copilot/chat/datatableTools.ts b/frontend/src/lib/components/copilot/chat/datatableTools.ts index 97b1524fb0..43f9eddfde 100644 --- a/frontend/src/lib/components/copilot/chat/datatableTools.ts +++ b/frontend/src/lib/components/copilot/chat/datatableTools.ts @@ -216,6 +216,7 @@ export function getDatatableTools(): SessionTool<{}>[] { requires: NONE, def: getListDatatablesToolDef(), planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { toolCallbacks.setToolStatus(toolId, { content: 'Listing datatables...' }) getListDatatablesSchema().parse(args ?? {}) @@ -245,6 +246,7 @@ export function getDatatableTools(): SessionTool<{}>[] { requires: NONE, def: getGetDatatableTableSchemaToolDef(), planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { const parsedArgs = getGetDatatableTableSchemaSchema().parse(args) toolCallbacks.setToolStatus(toolId, { diff --git a/frontend/src/lib/components/copilot/chat/docs/core.ts b/frontend/src/lib/components/copilot/chat/docs/core.ts index ee0c04983f..c8ac9552f8 100644 --- a/frontend/src/lib/components/copilot/chat/docs/core.ts +++ b/frontend/src/lib/components/copilot/chat/docs/core.ts @@ -37,6 +37,7 @@ export const readDocsPageTool: SessionTool<{}> = { requires: NONE, def: READ_DOCS_PAGE_TOOL, planModeSafe: true, + lookup: true, fn: async ({ args, toolId, toolCallbacks }) => { const url = typeof args?.url === 'string' ? args.url : '' const section = @@ -90,6 +91,7 @@ export const searchDocsTool: SessionTool<{}> = { requires: NONE, def: SEARCH_DOCS_TOOL, planModeSafe: true, + lookup: true, fn: async ({ args, toolId, toolCallbacks }) => { const query = typeof args?.query === 'string' ? args.query.trim() : '' toolCallbacks.setToolStatus(toolId, { diff --git a/frontend/src/lib/components/copilot/chat/ducklakeTools.ts b/frontend/src/lib/components/copilot/chat/ducklakeTools.ts index ebe193778f..02a52f06f8 100644 --- a/frontend/src/lib/components/copilot/chat/ducklakeTools.ts +++ b/frontend/src/lib/components/copilot/chat/ducklakeTools.ts @@ -61,6 +61,7 @@ export function getDucklakeTools(): SessionTool<{}>[] { requires: NONE, def: listDataMetricsToolDef, planModeSafe: true, + lookup: true, showDetails: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { listDataMetricsSchema.parse(args) @@ -77,6 +78,7 @@ export function getDucklakeTools(): SessionTool<{}>[] { requires: NONE, def: listDucklakesToolDef, planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { toolCallbacks.setToolStatus(toolId, { content: 'Listing DuckLake catalogs...' }) const { text } = await runOnServer('list_ducklakes', workspace, args) diff --git a/frontend/src/lib/components/copilot/chat/files/fileTools.ts b/frontend/src/lib/components/copilot/chat/files/fileTools.ts index b0d5554173..d9b1f89e44 100644 --- a/frontend/src/lib/components/copilot/chat/files/fileTools.ts +++ b/frontend/src/lib/components/copilot/chat/files/fileTools.ts @@ -100,6 +100,7 @@ export const searchFilesTool: SessionTool<{}> = { requires: NONE, def: searchFilesToolDef, planModeSafe: true, + lookup: true, fn: async ({ args, helpers, toolId, toolCallbacks }) => { const store = storeFrom(helpers) if (!store || store.count === 0) { @@ -170,6 +171,7 @@ export const readFileTool: SessionTool<{}> = { requires: NONE, def: readFileToolDef, planModeSafe: true, + lookup: true, fn: async ({ args, helpers, toolId, toolCallbacks }) => { const store = storeFrom(helpers) if (!store || store.count === 0) { diff --git a/frontend/src/lib/components/copilot/chat/flow/core.ts b/frontend/src/lib/components/copilot/chat/flow/core.ts index 9f20c2e684..f58eb5601e 100644 --- a/frontend/src/lib/components/copilot/chat/flow/core.ts +++ b/frontend/src/lib/components/copilot/chat/flow/core.ts @@ -376,6 +376,7 @@ export const flowTools: Tool[] = [ { def: resourceTypeToolDef, planModeSafe: true, + lookup: true, fn: async ({ args, toolId, workspace, toolCallbacks }) => { const parsedArgs = resourceTypeToolSchema.parse(args) toolCallbacks.setToolStatus(toolId, { @@ -395,6 +396,7 @@ export const flowTools: Tool[] = [ { def: getInstructionsForCodeGenerationToolDef, planModeSafe: true, + lookup: true, fn: async ({ args, toolId, toolCallbacks }) => { const parsedArgs = getInstructionsForCodeGenerationToolSchema.parse(args) const langContext = getLangContext(parsedArgs.language, { @@ -498,6 +500,7 @@ export const flowTools: Tool[] = [ { def: inspectInlineScriptToolDef, planModeSafe: true, + lookup: true, fn: async ({ args, helpers, toolCallbacks, toolId }) => { const parsedArgs = inspectInlineScriptSchema.parse(args) const moduleId = parsedArgs.moduleId @@ -835,6 +838,7 @@ export const flowTools: Tool[] = [ { def: getLintErrorsToolDef, planModeSafe: true, + lookup: true, fn: async ({ args, helpers, toolCallbacks, toolId }) => { const parsedArgs = getLintErrorsSchema.parse(args) diff --git a/frontend/src/lib/components/copilot/chat/global/core.ts b/frontend/src/lib/components/copilot/chat/global/core.ts index e3aef23365..64ea27e19c 100644 --- a/frontend/src/lib/components/copilot/chat/global/core.ts +++ b/frontend/src/lib/components/copilot/chat/global/core.ts @@ -2594,6 +2594,7 @@ export const readSkillTool: SessionTool<{}> = { 'Load the full instructions for an AI skill by resource path. Skills are listed in the system prompt under "Skills"; call this before acting on a task a skill covers, then follow its instructions.' ), planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { const parsed = readSkillSchema.parse(args) const name = skillNameFromPath(parsed.path) @@ -3380,6 +3381,7 @@ export const globalTools: SessionTool<{}>[] = [ 'Get authoring guidance for scripts, flows, AI agents, data pipelines, resources, apps, or data tables: their migrations and permissions, and the SQL SDK (wmill.datatable()) used inside runnables.' ), planModeSafe: true, + lookup: true, fn: async (ctx) => { const { args, toolId, toolCallbacks } = ctx const parsed = getInstructionsSchema.parse(args) @@ -3592,6 +3594,7 @@ export const globalTools: SessionTool<{}>[] = [ 'List workspace items and drafts. Returns metadata only, up to limit items per item type per page (default 50); pass page to continue past a full page.' ), planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { listWorkspaceItemsSchema.parse(args) toolCallbacks.setToolStatus(toolId, { content: 'Listing workspace items...' }) @@ -3613,6 +3616,7 @@ export const globalTools: SessionTool<{}>[] = [ 'List the data pipelines of the workspace: each folder holding at least one pipeline script, with its number of scripts. A pipeline is named by its folder, not by an item path.' ), planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { toolCallbacks.setToolStatus(toolId, { content: 'Listing data pipelines...' }) const { text } = await runOnServer('list_pipelines', workspace, args) @@ -3630,6 +3634,7 @@ export const globalTools: SessionTool<{}>[] = [ 'Read one workspace item or draft. Prefers your draft when one exists; pass version: "deployed" to read the deployed state instead. A deployed item carries extraPerms (a draft does not; pass version: "deployed" for it): who it is shared with beyond its owner, as u/ or g/ → true (write) or false (read-only). A folder returns its owners and extraPerms; a group returns its members and extraPerms (who may manage it). For a folder or group, path is its name. A g/ entry grants every member of that group (g/all is everyone), and workspace admins can read and write every folder and item whatever these lists say.' ), planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { const parsed = readWorkspaceItemSchema.parse(args) const { type } = parsed @@ -3780,6 +3785,7 @@ export const globalTools: SessionTool<{}>[] = [ 'Get the configuration schema for one trigger kind — its config fields differ per kind.' ), planModeSafe: true, + lookup: true, fn: async (ctx) => { const { kind } = getTriggerSchemaSchema.parse(ctx.args) return triggerConfigJsonSchema(kind) @@ -3793,6 +3799,7 @@ export const globalTools: SessionTool<{}>[] = [ "Get the shape of a schedule's `advanced` object: retry, pausing, tags, and error-handler tuning." ), planModeSafe: true, + lookup: true, fn: async () => JSON.stringify(advancedScheduleShape(), null, 2) }, { @@ -3961,6 +3968,7 @@ export const globalTools: SessionTool<{}>[] = [ 'List recent runs (jobs), most recent first. Optionally filter by path, creator, label, or status. Returns compact metadata only — use get_run with a returned id to see what a run was called with, returned and logged.' ), planModeSafe: true, + lookup: true, showDetails: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { listRunsSchema.parse(args) @@ -3981,6 +3989,7 @@ export const globalTools: SessionTool<{}>[] = [ 'List the workers connected to this Windmill instance (those that pinged in the last 5 minutes), with their worker group, custom tags, seconds since their last ping, and jobs executed. Pair with list_runs to diagnose a stuck queue: runs queued on a tag no listed worker picks up will never start. Three blind spots to report rather than reason past: an empty result states whether no worker is connected or whether workers may be hidden from you, so relay the one it gives instead of picking; a missing custom_tags can mean tags are hidden from you, not unset; and only the 100 most recently pinging workers are listed, so on a bigger instance a tag none of them carries may still be served.' ), planModeSafe: true, + lookup: true, showDetails: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { toolCallbacks.setToolStatus(toolId, { content: 'Listing workers...' }) @@ -4006,6 +4015,7 @@ export const globalTools: SessionTool<{}>[] = [ "Inspect one run: its status, arguments, result and logs, plus — for a flow — the per-step execution tree with each step's status and truncated result (subflow steps, loop iterations, branches and retries included). Works on running jobs too. Pass step to fetch one step's result in full (up to 12k chars)." ), planModeSafe: true, + lookup: true, showDetails: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { const parsed = getRunSchema.parse(args) @@ -4129,6 +4139,7 @@ export const globalTools: SessionTool<{}>[] = [ // Safe while planning: diff only flushes user-authored parked autosaves, honors the // autosave toggle, and never changes content, deploys, or runs user code. planModeSafe: true, + lookup: true, showDetails: true, fn: async (ctx) => { const parsed = diffSchema.parse(ctx.args) @@ -4263,6 +4274,7 @@ export const globalTools: SessionTool<{}>[] = [ 'Search workspace resource types and schemas.' ), planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { const parsed = searchResourceTypesSchema.parse(args) toolCallbacks.setToolStatus(toolId, { @@ -4313,6 +4325,7 @@ export const globalTools: SessionTool<{}>[] = [ 'Read inline script code from one flow module.' ), planModeSafe: true, + lookup: true, fn: async (ctx) => { const parsed = readFlowModuleCodeSchema.parse(ctx.args) ctx.toolCallbacks.setToolStatus(ctx.toolId, { @@ -4363,6 +4376,7 @@ export const globalTools: SessionTool<{}>[] = [ 'Read one raw app frontend file or inline backend runnable. Large files are truncated to a head slice; pass offset/limit to page through the rest.' ), planModeSafe: true, + lookup: true, fn: async (ctx) => { const parsed = readAppFileSchema.parse(ctx.args) ctx.toolCallbacks.setToolStatus(ctx.toolId, { @@ -4379,6 +4393,7 @@ export const globalTools: SessionTool<{}>[] = [ "Grep across all of a raw app's frontend files and inline backend runnables in one call. Returns matching file:line rows (capped), not file bodies — use it to locate a symbol or string before read_app_file instead of reading whole files one by one." ), planModeSafe: true, + lookup: true, fn: async (ctx) => { const parsed = searchAppSchema.parse(ctx.args) if (parsed.query.length > 0) { @@ -4537,6 +4552,7 @@ export const globalTools: SessionTool<{}>[] = [ 'Check whether the side-panel preview is open in this AI session and which item (kind + path) it is showing — for an artifact tab, also the version the user has pinned in its version picker, which may be older than the latest. Call this before offering or calling open_preview so you do not re-open a preview that is already showing the item you just edited, and whenever the user asks what they are looking at with no ACTIVE PREVIEW section to answer from. Only meaningful inside a session.' ), planModeSafe: true, + lookup: true, fn: async (ctx) => getSessionPreviewStatus(sessionIdFromCtx(ctx)) }, { @@ -4560,6 +4576,7 @@ export const globalTools: SessionTool<{}>[] = [ 'Fetch the most recent browser console logs (and uncaught errors) from the raw app preview currently open in this AI session. Also reports the build: right after an edit it waits (up to 20s) for the rebuild, and when the build failed it returns the build error and bundler logs first.' ), planModeSafe: true, + lookup: true, showDetails: true, fn: async (ctx) => { const parsed = getRuntimeLogsSchema.parse(ctx.args) @@ -4584,6 +4601,7 @@ export const globalTools: SessionTool<{}>[] = [ 'List the backend runnable executions (jobs) the raw app preview currently open in this AI session has triggered, newest first.' ), planModeSafe: true, + lookup: true, showDetails: true, fn: async (ctx) => { const parsed = listAppRunsSchema.parse(ctx.args) @@ -4604,6 +4622,7 @@ export const globalTools: SessionTool<{}>[] = [ 'Search the live rendered HTML of the raw app preview open in this AI session with a regex, returning matching lines with their line numbers. Use it to check what actually rendered (verify an edit landed, diagnose a blank/empty view). Scope to an element with `selector`, or omit it for the whole page. The DOM is read live, so it reflects the current state.' ), planModeSafe: true, + lookup: true, showDetails: true, fn: async (ctx) => { const parsed = searchDomSchema.parse(ctx.args) @@ -4633,6 +4652,7 @@ export const globalTools: SessionTool<{}>[] = [ 'Read a bounded window of the live rendered HTML of the raw app preview open in this AI session, pretty-printed and line-numbered. Scope to an element with `selector`, or omit it for the whole page. Use search_dom first to locate content, then read_dom to see a specific region. The DOM is read live.' ), planModeSafe: true, + lookup: true, showDetails: true, fn: async (ctx) => { const parsed = readDomSchema.parse(ctx.args) @@ -4664,6 +4684,7 @@ export const globalTools: SessionTool<{}>[] = [ 'Capture a screenshot of the raw app preview currently open in this AI session and attach it as an image so you can see the rendered UI. Use it when the user raises how the app looks, whether reporting a problem or asking for the design improved, rather than to check your own edits. The image is attached in the following message. Requires the raw app preview open (open_preview kind="raw_app").' ), planModeSafe: true, + lookup: true, showDetails: true, fn: async (ctx) => { // A known text-only model would reject the follow-up image message and fail diff --git a/frontend/src/lib/components/copilot/chat/global/mcpTools.ts b/frontend/src/lib/components/copilot/chat/global/mcpTools.ts index 0898837658..b91df4c769 100644 --- a/frontend/src/lib/components/copilot/chat/global/mcpTools.ts +++ b/frontend/src/lib/components/copilot/chat/global/mcpTools.ts @@ -363,7 +363,7 @@ function createCallTool(servers: McpServer[], mode: 'read' | 'write'): SessionTo ), showDetails: true, ...(isRead - ? { planModeSafe: true } + ? { planModeSafe: true, lookup: true } : { // Changes the external system, never the workspace, like a deployed run does. readOnlySafe: true, @@ -437,6 +437,7 @@ export function createMcpTools(servers: McpServer[]): SessionTool<{}>[] { 'Search the tools exposed by the MCP servers connected to this workspace (listed in the system prompt). Returns server + tool names to pass to call_mcp_read_tool or call_mcp_write_tool, each with the input schema its arguments must follow.' ), planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { const parsed = searchMcpToolsSchema.parse(args) toolCallbacks.setToolStatus(toolId, { content: 'Searching MCP tools...' }) diff --git a/frontend/src/lib/components/copilot/chat/global/sessionToolset.test.ts b/frontend/src/lib/components/copilot/chat/global/sessionToolset.test.ts index e8174808b5..34d413acf2 100644 --- a/frontend/src/lib/components/copilot/chat/global/sessionToolset.test.ts +++ b/frontend/src/lib/components/copilot/chat/global/sessionToolset.test.ts @@ -25,6 +25,8 @@ import { globalTools, prepareGlobalSystemMessage, type SessionPromptContext } fr import { appendPlanModeInstructions } from '../planMode' import { PlanModeController } from '../planModeController.svelte' import { pipelineTools } from '../pipeline/core' +import type { Tool } from '../shared' +import { everyChatTool } from '../lookupTools' import { assembleGlobalSystemMessage, assembleGlobalTools } from './globalAssembly' import { filterSessionTools, sessionToolAllowed } from './sessionToolset' import { capabilitiesForRole, fullSessionAccess } from './sessionAccess' @@ -402,3 +404,16 @@ describe('session tool policies', () => { expect(prompt({ manage_schedules: false })).not.toContain('schedule a deployed script') }) }) + +describe('lookup tools', () => { + // A lookup's row folds into a collapsed group, so it must be a call plan mode lets run; and + // the transcript looks a name up across modes, so a name is a lookup everywhere or nowhere. + it('are plan-mode-safe, and agree on every name across modes', () => { + const tools = everyChatTool() + const name = (t: Tool) => t.def.function.name + expect(tools.filter((t) => t.lookup && !t.planModeSafe).map(name)).toEqual([]) + const lookup = new Map>() + for (const t of tools) lookup.set(name(t), (lookup.get(name(t)) ?? new Set()).add(!!t.lookup)) + expect([...lookup].filter(([, values]) => values.size > 1).map(([n]) => n)).toEqual([]) + }) +}) diff --git a/frontend/src/lib/components/copilot/chat/global/workspaceSettingsTools.ts b/frontend/src/lib/components/copilot/chat/global/workspaceSettingsTools.ts index eb7175b20f..156f13bb3f 100644 --- a/frontend/src/lib/components/copilot/chat/global/workspaceSettingsTools.ts +++ b/frontend/src/lib/components/copilot/chat/global/workspaceSettingsTools.ts @@ -53,6 +53,7 @@ export const workspaceSettingsTools: SessionTool<{}>[] = [ 'Read the workspace settings as YAML, in the layout of the settings.yaml file the CLI syncs. Secrets read as `__SENSITIVE_AND_UNCHANGED__`.' ), planModeSafe: true, + lookup: true, showDetails: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { const parsed = getWorkspaceSettingsSchema.parse(args) diff --git a/frontend/src/lib/components/copilot/chat/lookupTools.ts b/frontend/src/lib/components/copilot/chat/lookupTools.ts new file mode 100644 index 0000000000..449686e031 --- /dev/null +++ b/frontend/src/lib/components/copilot/chat/lookupTools.ts @@ -0,0 +1,41 @@ +import type { AIProviderModel } from '$lib/gen' +import type { ContextElement } from './context' +import type { Tool } from './shared' +import { lookupToolNames, type LookupTools } from './toolGroups' +import { assembleGlobalTools } from './global/globalAssembly' +import { flowTools } from './flow/core' +import { getAppTools } from './app/core' +import { prepareScriptTools } from './script/core' +import { navigatorTools } from './navigator/core' +import { askTools } from './ask/core' +import { fetchWebPageTool, searchWebTool } from './web/core' + +/** Every tool any copilot mode can offer, each mode assembled with every option on. A + * transcript outlives the mode and options its calls were made in (`change_mode` keeps the + * transcript, an MCP server is removed, a pipeline editor closes), so grouping reads this + * whole set rather than the tools assembled now. */ +export function everyChatTool(): Tool[] { + return [ + ...assembleGlobalTools({ + previewTools: true, + pipelineFolders: [''], + mcpServers: [{ path: '' }] + }), + ...flowTools, + ...getAppTools(), + ...prepareScriptTools({ provider: 'openai', model: 'gpt-4o' } as AIProviderModel, 'bun', [ + { type: 'db' } as ContextElement + ]), + ...navigatorTools, + ...askTools, + // Added per request by withWebSearchFallback, so no assembly above carries them. + searchWebTool, + fetchWebPageTool + ] +} + +let lookups: LookupTools | undefined +export function chatLookupTools(): LookupTools { + lookups ??= lookupToolNames(everyChatTool()) + return lookups +} diff --git a/frontend/src/lib/components/copilot/chat/navigator/core.ts b/frontend/src/lib/components/copilot/chat/navigator/core.ts index 9def7d99d8..a839ff4059 100644 --- a/frontend/src/lib/components/copilot/chat/navigator/core.ts +++ b/frontend/src/lib/components/copilot/chat/navigator/core.ts @@ -241,6 +241,7 @@ const triggerComponentTool: Tool<{}> = { const getTriggerableComponentsTool: Tool<{}> = { def: GET_TRIGGERABLE_COMPONENTS_TOOL, planModeSafe: true, + lookup: true, fn: async ({ toolId, toolCallbacks }) => { toolCallbacks.setToolStatus(toolId, { content: 'Scanning the page...' @@ -256,6 +257,7 @@ const getTriggerableComponentsTool: Tool<{}> = { const getCurrentPageNameTool: Tool<{}> = { def: GET_CURRENT_PAGE_NAME_TOOL, planModeSafe: true, + lookup: true, fn: async ({ toolId, toolCallbacks }) => { const pageName = getCurrentPageName() toolCallbacks.setToolStatus(toolId, { content: 'Retrieved current page name' }) @@ -266,6 +268,7 @@ const getCurrentPageNameTool: Tool<{}> = { const getAvailableResourcesTool: Tool<{}> = { def: GET_AVAILABLE_RESOURCES_TOOL, planModeSafe: true, + lookup: true, fn: async ({ args, toolId, toolCallbacks }) => { toolCallbacks.setToolStatus(toolId, { content: 'Getting available resources...' }) try { diff --git a/frontend/src/lib/components/copilot/chat/pipeline/core.ts b/frontend/src/lib/components/copilot/chat/pipeline/core.ts index 62d7c2e6f5..05aa338366 100644 --- a/frontend/src/lib/components/copilot/chat/pipeline/core.ts +++ b/frontend/src/lib/components/copilot/chat/pipeline/core.ts @@ -400,6 +400,7 @@ export const pipelineTools: SessionTool[] = [ requires: NONE, def: getPipelineGraphToolDef, planModeSafe: true, + lookup: true, fn: async ({ args, helpers, toolId, toolCallbacks }) => { const { folder } = getPipelineGraphSchema.parse(args ?? {}) const pipeline = await pipelineForFolder(helpers, folder) @@ -416,6 +417,7 @@ export const pipelineTools: SessionTool[] = [ requires: NONE, def: readPipelineNodeToolDef, planModeSafe: true, + lookup: true, fn: async ({ args, helpers, toolId, toolCallbacks }) => { const { path } = readPipelineNodeSchema.parse(args) const pipeline = await pipelineForPath(helpers, path) diff --git a/frontend/src/lib/components/copilot/chat/readOnlyChatViewHost.svelte.ts b/frontend/src/lib/components/copilot/chat/readOnlyChatViewHost.svelte.ts index e861b97165..f87b663860 100644 --- a/frontend/src/lib/components/copilot/chat/readOnlyChatViewHost.svelte.ts +++ b/frontend/src/lib/components/copilot/chat/readOnlyChatViewHost.svelte.ts @@ -1,6 +1,7 @@ import { AIAutonomyMode } from './AIChatManager.svelte' import { AIWorkMode } from './workMode' import type { ChatViewHost } from './chatViewHost' +import { chatLookupTools } from './lookupTools' import type { DisplayMessage } from './shared' import { AttachedFilesStore } from './files/attachedFiles.svelte' import { SessionArtifactsStore } from './artifacts/artifactsState.svelte' @@ -79,6 +80,7 @@ export function readOnlyChatViewHost(options: { attachmentAccept: '', attachmentsAsBlobs: false, tools: [], + lookupTools: chatLookupTools(), autonomyMode: AIAutonomyMode.DEFAULT, setAutonomyMode: noop, workModesAvailable: false, diff --git a/frontend/src/lib/components/copilot/chat/script/core.ts b/frontend/src/lib/components/copilot/chat/script/core.ts index 79f8621e40..4106e1bc77 100644 --- a/frontend/src/lib/components/copilot/chat/script/core.ts +++ b/frontend/src/lib/components/copilot/chat/script/core.ts @@ -512,6 +512,7 @@ export interface ScriptChatHelpers { export const resourceTypeTool: Tool = { def: RESOURCE_TYPE_FUNCTION_DEF, planModeSafe: true, + lookup: true, fn: async ({ args, workspace, helpers, toolCallbacks, toolId }) => { toolCallbacks.setToolStatus(toolId, { content: 'Searching resource types for "' + args.query + '"...' @@ -544,6 +545,7 @@ export function createDbSchemaTool( // codebase authors, never the user's code, and writes nothing. Planning a change to a // database is not possible without its schema. planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolCallbacks, toolId }) => { if (!args.resourcePath) { throw new Error('Database path not provided') @@ -690,6 +692,7 @@ export const searchNpmPackagesTool: SessionTool<{}> = { requires: NONE, def: SEARCH_NPM_PACKAGES_TOOL, planModeSafe: true, + lookup: true, fn: async ({ args, toolId, toolCallbacks, helpers }) => { toolCallbacks.setToolStatus(toolId, { content: 'Searching for relevant packages...' }) const sessionAi = (helpers as { sessionAi?: () => SessionAi } | undefined)?.sessionAi @@ -1026,6 +1029,7 @@ export const testRunScriptTool: Tool = { export const getLintErrorsTool: Tool = { def: GET_LINT_ERRORS_TOOL, planModeSafe: true, + lookup: true, fn: async function ({ helpers, toolCallbacks, toolId }) { toolCallbacks.setToolStatus(toolId, { content: 'Getting lint errors...' }) diff --git a/frontend/src/lib/components/copilot/chat/shared.ts b/frontend/src/lib/components/copilot/chat/shared.ts index ba2f67668b..a8f4cfeff8 100644 --- a/frontend/src/lib/components/copilot/chat/shared.ts +++ b/frontend/src/lib/components/copilot/chat/shared.ts @@ -1414,6 +1414,10 @@ export interface Tool { schemaFor?: (helpers: any) => Promise /** Safe to run while plan mode is active. Absence fails closed. */ planModeSafe?: boolean + /** Only looks something up, so the transcript may fold its row into a run of other + * lookups. Requires `planModeSafe`, which also admits writes (plan documents, artifacts) + * and a test run; absence keeps the row on its own. */ + lookup?: boolean /** Shows an item without changing or running it, though not `planModeSafe`: working * folders never hold it, so the AI can show what it reads in any folder. */ viewOnly?: boolean @@ -1878,6 +1882,7 @@ export const getHubIntegrationTool = { def: getHubIntegrationToolDef, // Reads one hub document over a GET and writes nothing, so planning may use it. planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { const { integration } = getHubIntegrationSchema.parse(args) toolCallbacks.setToolStatus(toolId, { content: `Reading the ${integration} integration...` }) @@ -1899,6 +1904,7 @@ export const createSearchHubScriptsTool = (withContent: boolean = false) => ({ requires: NONE, def: searchHubScriptsToolDef, planModeSafe: true, + lookup: true, fn: async ({ args, toolId, toolCallbacks }) => { const parsedArgs = searchHubScriptsSchema.parse(args) // The hub's own query param is `app`; the tool exposes it as `integration`, @@ -3046,6 +3052,7 @@ export const workspaceRunnablesSearch = new WorkspaceRunnablesSearch() export const createSearchWorkspaceTool = () => ({ def: searchWorkspaceToolDef, planModeSafe: true, + lookup: true, fn: async ({ args, workspace, @@ -3097,6 +3104,7 @@ const getRunnableDetailsToolDef = createToolDef( export const createGetRunnableDetailsTool = () => ({ def: getRunnableDetailsToolDef, planModeSafe: true, + lookup: true, fn: async ({ args, workspace, diff --git a/frontend/src/lib/components/copilot/chat/toolGroups.test.ts b/frontend/src/lib/components/copilot/chat/toolGroups.test.ts index 2b11286830..319b430dd8 100644 --- a/frontend/src/lib/components/copilot/chat/toolGroups.test.ts +++ b/frontend/src/lib/components/copilot/chat/toolGroups.test.ts @@ -8,6 +8,25 @@ import { type ToolGroup } from './toolGroups' +// What the chat's tool definitions mark `lookup`, for the calls these cases make. +const LOOKUPS = new Set([ + 'read_workspace_item', + 'list_workspace_items', + 'search_workspace', + 'search_docs', + 'list_runs', + 'list_workers', + 'read_flow_module_code', + 'inspect_inline_script', + 'get_lint_errors', + 'read_app_file', + 'search_app', + 'search_mcp_tools', + 'call_mcp_read_tool', + 'get_db_schema', + 'search_hub_scripts' +]) + let nextId = 0 function tool( toolName: string, @@ -28,13 +47,13 @@ function assistant(content: string, extra = {}): DisplayMessage { } function shape(messages: DisplayMessage[]) { - return groupToolRuns(messages).map((item) => + return groupToolRuns(messages, LOOKUPS).map((item) => item.kind === 'group' ? { [item.groupKind]: item.entries.map((e) => e.index) } : item.index ) } function header(messages: DisplayMessage[], state: GroupState = 'settled') { - const group = groupToolRuns(messages).find((item) => item.kind === 'group') as ToolGroup + const group = groupToolRuns(messages, LOOKUPS).find((item) => item.kind === 'group') as ToolGroup const { prefix, label } = groupHeader(group, state) return prefix ? `${prefix} ${label}` : label } @@ -303,14 +322,17 @@ describe('groupToolRuns', () => { }) it('names the first three kinds of call and leaves the rest to `more`', () => { - const group = groupToolRuns([ - tool('search_workspace'), - tool('list_runs'), - tool('read_workspace_item'), - tool('search_docs'), - tool('search_workspace'), - tool('list_workers') - ]).find((item) => item.kind === 'group') as ToolGroup + const group = groupToolRuns( + [ + tool('search_workspace'), + tool('list_runs'), + tool('read_workspace_item'), + tool('search_docs'), + tool('search_workspace'), + tool('list_workers') + ], + LOOKUPS + ).find((item) => item.kind === 'group') as ToolGroup expect(groupHeader(group, 'settled')).toEqual({ prefix: '', label: 'Search workspace 2 times, list runs, read workspace item', @@ -328,8 +350,8 @@ describe('createChatItemGrouper', () => { tool('list_runs'), assistant('more') ] - const first = group([...history, assistant('a', { streaming: true })]) - const second = group([...history, assistant('ab', { streaming: true })]) + const first = group([...history, assistant('a', { streaming: true })], LOOKUPS) + const second = group([...history, assistant('ab', { streaming: true })], LOOKUPS) expect(second).toHaveLength(first.length) second.slice(0, -1).forEach((item, i) => expect(item).toBe(first[i])) expect(second.at(-1)).toMatchObject({ kind: 'message', index: 4, message: { content: 'ab' } }) @@ -343,9 +365,9 @@ describe('createChatItemGrouper', () => { it('keeps every row but the one a tool status change replaced', () => { const group = createChatItemGrouper() const history = [assistant('done'), tool('run_script'), assistant('more')] - const first = group(history) + const first = group(history, LOOKUPS) const updated = [history[0], { ...history[1], isLoading: false }, history[2]] - const second = group(updated) + const second = group(updated, LOOKUPS) expect(second[0]).toBe(first[0]) expect(second[1]).not.toBe(first[1]) expect(second[1]).toMatchObject({ message: updated[1] }) diff --git a/frontend/src/lib/components/copilot/chat/toolGroups.ts b/frontend/src/lib/components/copilot/chat/toolGroups.ts index 5d3f582a6c..8a95543709 100644 --- a/frontend/src/lib/components/copilot/chat/toolGroups.ts +++ b/frontend/src/lib/components/copilot/chat/toolGroups.ts @@ -1,9 +1,9 @@ -import type { DisplayMessage, ToolDisplayMessage } from './shared' +import type { DisplayMessage, Tool, ToolDisplayMessage } from './shared' import { DRAFT_CONFLICT_RESULT, DRAFT_SAVE_FAILED_RESULT } from './draftWriteResults' import { webSearchResultOf } from './webSearchResult' -// A tool missing from these lists always renders as its own row, so a new write never gets -// hidden by default. +// A tool missing from these lists, whose definition does not set `lookup` either, renders as +// its own row, so a new write never gets hidden by default. type EditedItemKind = 'flow' | 'app' @@ -45,47 +45,15 @@ const PATHLESS_FLOW_MODE_TOOLS = new Set([ 'inspect_inline_script', 'get_lint_errors' ]) -// Calls that only look things up. Not derived from `planModeSafe`, which also admits test -// runs and plan-document writes. -const READ_TOOLS = new Set([ - ...Object.keys(ITEM_READ_TOOLS), - 'list_workspace_items', - 'read_workspace_item', - 'search_workspace', - 'get_runnable_details', - 'search_hub_scripts', - 'search_resource_types', - 'resource_type', - 'search_docs', - 'read_docs_page', - 'get_db_schema', - 'search_npm_packages', - 'get_instructions', - 'get_instructions_for_code_generation', - 'read_skill', - 'get_trigger_schema', - 'get_schedule_schema', - 'list_runs', - 'list_workers', - 'list_app_runs', - 'get_app_runtime_logs', - 'get_preview_status', - 'get_current_page_name', - 'search_dom', - 'read_dom', - 'read_file', - 'search_files', - 'list_data_metrics', - 'list_ducklakes', - 'get_pipeline_graph', - 'read_pipeline_node', - 'list_artifacts', - 'read_artifact', - 'list_artifact_versions', - 'search_mcp_tools', - 'call_mcp_read_tool' -]) +/** The tool names whose definition sets `lookup` in the chat showing the transcript. A name + * that chat does not define (a flow's own agent tools) is not one. */ +export type LookupTools = ReadonlySet +export function lookupToolNames(tools: Iterable>): Set { + const names = new Set() + for (const tool of tools) if (tool.lookup) names.add(tool.def.function.name) + return names +} export type ToolGroup = { kind: 'group' /** 'edit': edits of one flow or app. 'explore': consecutive lookups of anything. @@ -178,9 +146,9 @@ function sameItem(a: Membership | undefined, b: Membership): boolean { return a !== undefined && a.kind === b.kind && (a.path === undefined || a.path === b.path) } -function isReadCall(message: DisplayMessage): boolean { +function isReadCall(message: DisplayMessage, lookups: LookupTools): boolean { const call = groupableCall(message) - return call !== undefined && READ_TOOLS.has(call.toolName!) + return call !== undefined && lookups.has(call.toolName!) } // Thinking between two calls stays inside the group; visible text ends it. The live @@ -251,13 +219,18 @@ function inFlight(message: DisplayMessage): boolean { function waitingGroupAt( messages: DisplayMessage[], start: number, - previous: ChatItem | undefined + previous: ChatItem | undefined, + lookups: LookupTools ): ToolGroup | undefined { if (!isWaitingCall(messages[start]) || !previous) return undefined const ahead = previous.kind === 'group' ? previous.entries.map((e) => e.message) : [previous.message] if (!ahead.some(inFlight)) return undefined - const end = runEnd(messages, start, (m, j) => isWaitingCall(m) && !kindGroupAt(messages, j)) + const end = runEnd( + messages, + start, + (m, j) => isWaitingCall(m) && !kindGroupAt(messages, j, lookups) + ) return { kind: 'group', groupKind: 'waiting', @@ -270,21 +243,27 @@ function waitingGroupAt( // An edit group wins over an explore group: its reads belong to the edits they prepare, so an // explore run also stops before a read that starts one. Both win over a waiting row, which // stops before either: its header says less than `Edit f/a/flow · 2 changes`. -function kindGroupAt(messages: DisplayMessage[], start: number): ToolGroup | undefined { - const explores = (m: DisplayMessage, j: number) => isReadCall(m) && !editGroupAt(messages, j) +function kindGroupAt( + messages: DisplayMessage[], + start: number, + lookups: LookupTools +): ToolGroup | undefined { + const explores = (m: DisplayMessage, j: number) => + isReadCall(m, lookups) && !editGroupAt(messages, j) return ( editGroupAt(messages, start) ?? - (isReadCall(messages[start]) + (isReadCall(messages[start], lookups) ? toolGroup(messages, start, runEnd(messages, start, explores), 'explore', '') : undefined) ) } -export function groupToolRuns(messages: DisplayMessage[]): ChatItem[] { +export function groupToolRuns(messages: DisplayMessage[], lookups: LookupTools): ChatItem[] { const items: ChatItem[] = [] let i = 0 while (i < messages.length) { - const group = kindGroupAt(messages, i) ?? waitingGroupAt(messages, i, items.at(-1)) + const group = + kindGroupAt(messages, i, lookups) ?? waitingGroupAt(messages, i, items.at(-1), lookups) if (group) { items.push(group) i = group.entries.at(-1)!.index + 1 @@ -317,20 +296,29 @@ function sameChatItem(a: ChatItem, b: ChatItem): boolean { * * A changed message is told apart by identity alone, so a row must be replaced, never mutated * in place, for its grouping to update. */ -export function createChatItemGrouper(): (messages: DisplayMessage[]) => ChatItem[] { +export function createChatItemGrouper(): ( + messages: DisplayMessage[], + lookups: LookupTools +) => ChatItem[] { let settled: DisplayMessage[] = [] let settledItems: ChatItem[] = [] - return (messages) => { + let settledLookups: LookupTools | undefined + return (messages, lookups) => { // The live answer only ever comes last, and it can neither join nor end a group // differently than the end of the transcript does, so it is grouped on its own and the // rows before it are not regrouped while it streams. const last = messages.at(-1) const live = last?.role === 'assistant' && last.streaming ? last : undefined const n = live ? messages.length - 1 : messages.length - if (n !== settled.length || settled.some((m, i) => m !== messages[i])) { + if ( + lookups !== settledLookups || + n !== settled.length || + settled.some((m, i) => m !== messages[i]) + ) { const previous = new Map(settledItems.map((item) => [chatItemKey(item), item])) settled = messages.slice(0, n) - settledItems = groupToolRuns(settled).map((item) => { + settledLookups = lookups + settledItems = groupToolRuns(settled, lookups).map((item) => { const before = previous.get(chatItemKey(item)) return before && sameChatItem(before, item) ? before : item }) diff --git a/frontend/src/lib/components/copilot/chat/web/core.ts b/frontend/src/lib/components/copilot/chat/web/core.ts index a321c90251..9465d6463d 100644 --- a/frontend/src/lib/components/copilot/chat/web/core.ts +++ b/frontend/src/lib/components/copilot/chat/web/core.ts @@ -46,6 +46,7 @@ export const searchWebTool: SessionTool<{}> = { requires: NONE, def: SEARCH_WEB_TOOL, planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { const query = typeof args?.query === 'string' ? args.query.trim() : '' if (!query) return 'No search query was provided. Provide a `query`.' @@ -85,6 +86,7 @@ export const fetchWebPageTool: SessionTool<{}> = { requires: NONE, def: FETCH_WEB_PAGE_TOOL, planModeSafe: true, + lookup: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { const url = typeof args?.url === 'string' ? args.url.trim() : '' if (!url) return 'No URL was provided. Provide a `url`.' diff --git a/frontend/src/lib/components/copilot/chat/workspaceTools.ts b/frontend/src/lib/components/copilot/chat/workspaceTools.ts index 7590f3b686..656f0f153b 100644 --- a/frontend/src/lib/components/copilot/chat/workspaceTools.ts +++ b/frontend/src/lib/components/copilot/chat/workspaceTools.ts @@ -87,6 +87,8 @@ const getScheduleSchemaTool: Tool = { 'get_schedule_schema', "Get the shape of create_schedule's `advanced` object: retry, pausing, tags, and error-handler tuning." ), + planModeSafe: true, + lookup: true, fn: async () => JSON.stringify(advancedScheduleShape(SCHEDULE_TOOL_OPTIONS), null, 2) } @@ -155,6 +157,8 @@ const getTriggerSchemaTool: Tool = { 'get_trigger_schema', 'Get the configuration schema for one trigger kind. Call before create_trigger.' ), + planModeSafe: true, + lookup: true, fn: async ({ args }) => { const { kind } = parseWithExplicitErrors(getTriggerSchemaToolSchema, args, 'Trigger kind') const schema = z.toJSONSchema(triggerConfigSchemas[kind]) as Record @@ -333,9 +337,7 @@ const createScheduleTool: Tool = { ) const dropped = droppedOptionKeys(merged, requestBody) if (dropped.length) { - throw new Error( - describeDroppedScheduleOptions(dropped) - ) + throw new Error(describeDroppedScheduleOptions(dropped)) } toolCallbacks.setToolStatus(toolId, { diff --git a/frontend/src/lib/components/flows/conversations/flowChatViewHost.svelte.ts b/frontend/src/lib/components/flows/conversations/flowChatViewHost.svelte.ts index 5c593e0c26..0e16d814dd 100644 --- a/frontend/src/lib/components/flows/conversations/flowChatViewHost.svelte.ts +++ b/frontend/src/lib/components/flows/conversations/flowChatViewHost.svelte.ts @@ -944,6 +944,9 @@ export class FlowChatViewHost implements ChatViewHost, DraftSender() // The enum's value, written out so this module never imports the copilot manager at // runtime: its unit test would otherwise load the manager and the editor it pulls in. autonomyMode = 'default' as AIAutonomyMode.DEFAULT diff --git a/frontend/src/lib/components/recording/AgentRecordingTranscript.svelte b/frontend/src/lib/components/recording/AgentRecordingTranscript.svelte index 940a7d756c..a7d0214f21 100644 --- a/frontend/src/lib/components/recording/AgentRecordingTranscript.svelte +++ b/frontend/src/lib/components/recording/AgentRecordingTranscript.svelte @@ -11,6 +11,7 @@ Shared by the recorder and the Hub page so the two cannot show different things. import { setChatViewHost } from '$lib/components/copilot/chat/chatViewHost' import { readOnlyChatViewHost } from '$lib/components/copilot/chat/readOnlyChatViewHost.svelte' import { chatItemKey, groupToolRuns } from '$lib/components/copilot/chat/toolGroups' + import { chatLookupTools } from '$lib/components/copilot/chat/lookupTools' import type { DisplayMessage } from '$lib/components/copilot/chat/shared' import { agentRecordingMessages } from './agentRecording' import type { AgentTurn } from './types' @@ -52,7 +53,7 @@ Shared by the recorder and the Hub page so the two cannot show different things. untrack(() => shown.splice(0, shown.length, ...next)) }) - const chatItems = $derived(groupToolRuns(shown)) + const chatItems = $derived(groupToolRuns(shown, chatLookupTools())) const waiting = $derived( pending !== undefined || (playing && count !== undefined && count < all.length && all[count]?.role !== 'user') diff --git a/frontend/src/lib/components/sessions/SharedSessionTranscript.svelte b/frontend/src/lib/components/sessions/SharedSessionTranscript.svelte index 52934afd52..032aff1b22 100644 --- a/frontend/src/lib/components/sessions/SharedSessionTranscript.svelte +++ b/frontend/src/lib/components/sessions/SharedSessionTranscript.svelte @@ -14,6 +14,7 @@ import { setUntrustedImages } from '$lib/components/copilot/chat/untrustedImages' import { readOnlyChatViewHost } from '$lib/components/copilot/chat/readOnlyChatViewHost.svelte' import { chatItemKey, groupToolRuns } from '$lib/components/copilot/chat/toolGroups' + import { chatLookupTools } from '$lib/components/copilot/chat/lookupTools' import type { DisplayMessage } from '$lib/components/copilot/chat/shared' import type { SessionSnapshot } from './sessionSharing' import { untrack } from 'svelte' @@ -99,7 +100,7 @@ const openTabs = $derived(openIds.flatMap((id) => artifacts.find((a) => a.id === id) ?? [])) const messages = $derived(snapshot.messages) - const chatItems = $derived(groupToolRuns(messages)) + const chatItems = $derived(groupToolRuns(messages, chatLookupTools())) // An answer's copy row shows once per turn, on its last answer, as in the live chat. const showsAnswerActions = $derived.by(() => { From 344694ada73c857724cb8244e7e7f8188efa2611 Mon Sep 17 00:00:00 2001 From: Guilhem Date: Mon, 23 Nov 2026 21:26:50 +0100 Subject: [PATCH 03/28] feat: redesign the token scope picker and add a scope search (#12595) * feat: redesign the token scope picker and add a scope search Put label and expiration before permissions and hold the picker in one card: selected scopes on top, a search over groups and scopes, and one checkbox per scope showing its exact scope string. Read-only groups (Trigger History, Documentation, Data Metrics) can now be ticked as a whole, and the first row of selected scopes no longer shifts the list. Co-Authored-By: Claude Opus 5.5 * feat: pick token scope paths with a path picker Restricting a scope to paths now uses one select-like field per scope: browse folders, search items, or type a path that matches nothing. It reuses the workspace tree the chat context picker builds, so drafts show under their friendly path, and offers empty folders for scopes on other resources. The group counter now counts the read scope implied by write. Co-Authored-By: Claude Opus 5.5 * fix: list the token's workspace in the path picker and keep Escape for its list - The path picker lists the folders and items of the token's own workspace, which an edited token may hold apart from the workspace on screen. - An open picker sits on the overlay stack, so Escape closes its list instead of the token edit dialog around it. - A group checkbox also grants bare run scopes (apps:run, resources:run). Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- .../components/pathPicker/PathPicker.svelte | 472 +++++++++++++++ .../components/settings/CreateToken.svelte | 42 +- .../components/settings/ScopeSelector.svelte | 565 +++++++----------- .../components/settings/ScopesPicker.svelte | 22 +- .../src/lib/components/workspacePicker.ts | 5 + 5 files changed, 733 insertions(+), 373 deletions(-) create mode 100644 frontend/src/lib/components/pathPicker/PathPicker.svelte diff --git a/frontend/src/lib/components/pathPicker/PathPicker.svelte b/frontend/src/lib/components/pathPicker/PathPicker.svelte new file mode 100644 index 0000000000..124f0ab9ad --- /dev/null +++ b/frontend/src/lib/components/pathPicker/PathPicker.svelte @@ -0,0 +1,472 @@ + + + +{#snippet chip(path: string)} + + {path} + + +{/snippet} + +{#snippet selectedMark(path: string)} + {#if isSelected(path)} + + {/if} +{/snippet} + + + + +
+
{ + openPicker() + fieldInput?.focus() + }} + role={searchIn === 'dropdown' ? 'button' : undefined} + tabindex={searchIn === 'dropdown' && !disabled ? 0 : undefined} + onkeydown={searchIn === 'dropdown' ? onKeydown : undefined} + > + {#if multiple} + {#each value as path, i (i)} + {@render chip(path)} + {/each} + {/if} + {#if searchIn === 'field'} + setQuery(e.currentTarget.value)} + onfocus={openPicker} + onkeydown={onKeydown} + placeholder={multiple ? (value.length > 0 ? '' : placeholder) : (value[0] ?? placeholder)} + class={twMerge( + 'no-default-style flex-1 min-w-16 h-5 !p-0 !pl-0.5 !border-0 !bg-transparent !shadow-none !ring-0 outline-none text-xs', + !multiple && value[0] && !open + ? 'placeholder:text-primary font-mono' + : 'placeholder:text-hint' + )} + /> + {:else if !multiple && value[0]} + {value[0]} + {:else if value.length === 0} + {placeholder} + {/if} + +
+ + triggerEl!.getBoundingClientRect())} + > + {#if searchIn === 'dropdown'} +
+ + setQuery(e.currentTarget.value)} + onkeydown={onKeydown} + placeholder="Search or type a path" + class="no-default-style flex-1 min-w-0 !p-0 !border-0 !bg-transparent !shadow-none !ring-0 outline-none text-xs placeholder:text-hint" + /> +
+ {/if} +
    + {#if loading} +
  • + Loading +
  • + {/if} + {#each rows as row, i (row.key)} + {@const hl = i === highlighted} +
  • + + +
  • + {:else} + {#if !loading} +
  • No folders or items
  • + {/if} + {/each} +
+
+
diff --git a/frontend/src/lib/components/settings/CreateToken.svelte b/frontend/src/lib/components/settings/CreateToken.svelte index 41799824f8..e96cfad47d 100644 --- a/frontend/src/lib/components/settings/CreateToken.svelte +++ b/frontend/src/lib/components/settings/CreateToken.svelte @@ -362,7 +362,7 @@ {/if} {#if maxExpirationSecs != undefined}
- Expires In + Expires in {#if maxExpirationSecs != undefined} -

+

This instance limits tokens to {maxExpirationLabel}.

{/if}
+ {#if !scopes || scopes.length === 0} +
+ +
+ {/if} +
{#if !mcpOnly} {/snippet} -
+
{#if loading} -
- +
+ + Loading scopes
{:else if error} -
-

{error}

- +
+

{error}

+
{:else if scopeDomains} -
-
-

- Selected Scopes ({selectedScopes.length}) -

- -
- - {#if selectedScopes.length === 0} -

{emptyLabel}

- {:else if hasAdministratorScope} -

Administrator scope grants full access to all resources.

- {:else} -
- {#each selectedScopes.slice(0, 10) as scope} - {@render scopeChip(scope, 'Remove scope', () => removeSelectedScope(scope), { - wrapLabel: true - })} - {/each} - {#if selectedScopes.length > 10} - - +{selectedScopes.length - 10} more - - {/if} -
- {/if} -
- {#if topSlot} -
- {@render topSlot()} -
+ {@render topSlot()} {/if} -
- {#each scopeDomains as domain} - {@const domainState = getDomainState(domain.name)} - {@const isExpanded = domainState?.isExpanded || false} - {@const isDomainSelected = domainState?.hasFullAccess || false} - {@const selectedScopes = getSelectedScopesForDomain(domain)} +
+
+ + Scopes + · {selectedScopes.length} selected + + +
+ {#if selectedScopes.length > 0} + + {/if} + +
+
-
- - -
toggleDomainExpansion(domain.name)} - > -
-
- -
+ +
+ {#if selectedScopes.length === 0 || hasAdministratorScope} +

+ {selectedScopes.length === 0 + ? emptyLabel + : 'Administrator scope grants full access to all resources.'} +

+ {:else} +
+ {#each selectedScopes as scope} + {@render scopeChip(scope, 'Remove scope', () => removeSelectedScope(scope), disabled)} + {/each} +
+ {/if} +
-
- handleDomainCheckboxChange(domain, e.currentTarget.checked)} - onclick={(e) => e.stopPropagation()} - class="!w-4 !h-4 cursor-pointer" - /> -
+
+ {#each visibleDomains as domain (domain.name)} + {@const domainState = getDomainState(domain.name)} + {@const isExpanded = query !== '' || domainState?.isExpanded || false} + {@const isDomainSelected = domainState?.hasFullAccess || false} + + {@const selectedCount = domain.scopes.filter( + (s) => domainState?.scopes[s.value]?.isSelected || isScopeDisabled(s, domain) + ).length} -
- -
- - - {#each selectedScopes as scope} - {@render scopeChip(scope, 'Remove scope', (e) => { - e.stopPropagation() - removeSelectedScope(scope) - })} - {/each} -
+
+ + +
toggleDomainExpansion(domain.name)} + > + + 0} + {disabled} + title={`Grant every ${domain.name} scope`} + onChange={() => handleDomainCheckboxChange(domain, !isDomainSelected)} + onClick={(e) => e.stopPropagation()} + /> +
+
{domain.name}
{#if domain.description} -

{domain.description}

+
{domain.description}
{/if}
+ {#if selectedCount > 0} + + {selectedCount} of {domain.scopes.length} + + {/if}
-
- {#if isExpanded} -
-
- {#each domain.scopes as scope} - {@const scopeState = domainState?.scopes[scope.value]} - {@const isSelected = scopeState?.isSelected || false} - {@const resourcePathArray = scopeState?.resourcePaths || []} - {@const currentInput = scopeState?.currentInputValue || ''} - {@const pathError = scopeState?.pathError} + {#if isExpanded} + +
+ {#each getVisibleScopes(domain) as scope (scope.value)} + {@const isSelected = domainState?.scopes[scope.value]?.isSelected || false} + {@const isImplied = !isSelected && isScopeDisabled(scope, domain)} {@const isDisabled = disabled || isScopeDisabled(scope, domain)} -
-
-
- - {#if scope.requires_resource_path && resourcePathArray.length > 0} -
- {#each resourcePathArray as path} - {@render scopeChip( - path, - 'Remove path', - () => removeResourcePath(scope.value, path), - { removeDisabled: isDisabled } - )} - {/each} -
+ {scope.label} + + {scope.value} + + {#if scope.requires_resource_path && isSelected} + domainState?.scopes[scope.value]?.resourcePaths ?? [], + (paths) => setResourcePaths(scope.value, paths) + } + kinds={pathPickerKinds(scope.value)} + validate={validateResourcePath} + {workspaceId} + {disabled} + /> + {:else} +
{/if}
{/each}
-
- {/if} -
- {/each} + {/if} +
+ {:else} +

No scope matches "{search.trim()}".

+ {/each} +
{/if}
diff --git a/frontend/src/lib/components/settings/ScopesPicker.svelte b/frontend/src/lib/components/settings/ScopesPicker.svelte index e8cdccf40c..c4a8026d14 100644 --- a/frontend/src/lib/components/settings/ScopesPicker.svelte +++ b/frontend/src/lib/components/settings/ScopesPicker.svelte @@ -70,19 +70,17 @@ size="xs" /> {#if limited} - + {#snippet topSlot()} -
- -
+ {/snippet}
{/if} diff --git a/frontend/src/lib/components/workspacePicker.ts b/frontend/src/lib/components/workspacePicker.ts index 34bf3f07ef..bba92751bf 100644 --- a/frontend/src/lib/components/workspacePicker.ts +++ b/frontend/src/lib/components/workspacePicker.ts @@ -51,6 +51,11 @@ export const KIND_LABEL_LOWER: Record = { * (leaves always belong to a real kind). */ export const kindKey = (k: WorkspaceItemKind | 'all') => `kind:${k}` export const dirKey = (k: WorkspaceItemKind | 'all', fullPath: string) => `dir:${k}:${fullPath}` +/** The folder path a `dirKey` names, or `undefined` for any other key. */ +export function dirPathFromKey(key: string): string | undefined { + if (!key.startsWith('dir:')) return undefined + return key.slice(key.indexOf(':', 4) + 1) +} export const leafKeyFor = (k: WorkspaceItemKind, path: string) => `leaf:${k}:${path}` export function editPathFor(item: WorkspaceItem): string { From 1fe370451576689215678e4da9098b4b342d1220 Mon Sep 17 00:00:00 2001 From: Guilhem Date: Mon, 23 Nov 2026 21:27:05 +0100 Subject: [PATCH 04/28] fix: make schedule and trigger lists usable on small screens (#12594) * fix: make schedule and trigger lists usable on small screens * fix: keep row actions on the title line for draft rows on phones * fix: let native trigger titles shrink on phones --- .../components/schedules/SchedulesList.svelte | 119 ++++++++++-------- .../components/triggers/TriggerList.svelte | 47 +++++-- .../triggers/native/NativeTriggerTable.svelte | 12 +- 3 files changed, 107 insertions(+), 71 deletions(-) diff --git a/frontend/src/lib/components/schedules/SchedulesList.svelte b/frontend/src/lib/components/schedules/SchedulesList.svelte index 38801dd38d..2afb824e32 100644 --- a/frontend/src/lib/components/schedules/SchedulesList.svelte +++ b/frontend/src/lib/components/schedules/SchedulesList.svelte @@ -19,6 +19,7 @@ import SharedBadge from '$lib/components/SharedBadge.svelte' import DraftBadge from '$lib/components/DraftBadge.svelte' import InheritedLabels from '$lib/components/InheritedLabels.svelte' + import LabelBadge from '$lib/components/common/badge/LabelBadge.svelte' import ShareModal from '$lib/components/ShareModal.svelte' import Toggle from '$lib/components/Toggle.svelte' import { enterpriseLicense } from '$lib/stores' @@ -34,6 +35,7 @@ Play, Plus, SearchX, + Tag, Trash, TriangleAlert, UserPlus @@ -420,7 +422,7 @@ )} style={depth > 0 ? `padding-left: ${(depth + 1) * 16}px;` : ''} > -
+
{summary || script_path}{hasDraft ? '*' : ''} @@ -439,59 +441,62 @@ schedule: {path}
- {#if labels?.length} - {#each labels as label} - { - const arr = (filters.val.label ?? '').split(',').filter(Boolean) - const idx = arr.indexOf(label) - if (idx >= 0) arr.splice(idx, 1) - else arr.push(label) - const newFilters = { ...filters.val } - if (arr.length) newFilters.label = arr.join(',') - else delete newFilters.label - filters.val = newFilters - }}>{label} - {/each} - {/if} - + +
+ {#if labels?.length} + {#each labels as label (label)} + { + const arr = (filters.val.label ?? '').split(',').filter(Boolean) + const idx = arr.indexOf(label) + if (idx >= 0) arr.splice(idx, 1) + else arr.push(label) + const newFilters = { ...filters.val } + if (arr.length) newFilters.label = arr.join(',') + else delete newFilters.label + filters.val = newFilters + }}>{label} + {/each} + {/if} + - {#if paused_until && new Date(paused_until) > new Date()} -
+ {#if paused_until && new Date(paused_until) > new Date()} Paused until {new Date(paused_until).toLocaleString()} + {/if} + +
+ + {schedule} + {#snippet text()} + + {/snippet} + + {timezone}
- {/if} - - - -
+ +
{#if error} @@ -531,7 +536,7 @@ {/if}
-
+
{#key toggleResetVersions[path] ?? 0} {/key}
-
+
+ @@ -576,6 +583,7 @@ unifiedSize="md" startIcon={{ icon: canEdit ? Pen : Eye }} variant="subtle" + wrapperClasses="max-md:hidden" > {canEdit ? 'Edit' : 'View'} @@ -635,6 +643,7 @@ { displayName: 'View runs', icon: List, + disabled: draft_only, href: `/runs/?schedule_path=${path}&job_trigger_kind=schedule&show_future_jobs=true` }, { @@ -660,7 +669,7 @@ />
-
+
{#if loadingSchedulesWithJobStats}
@@ -690,7 +699,7 @@
{/if}
{#if edited_by}
edited by {edited_by}
{/if}
{edited_by ? 'at ' : ''}{displayDate(edited_at)}
-
+
{#snippet children({ item })} @@ -744,7 +753,7 @@
diff --git a/frontend/src/lib/components/triggers/TriggerList.svelte b/frontend/src/lib/components/triggers/TriggerList.svelte index 73e4c300fb..b3db2eb2df 100644 --- a/frontend/src/lib/components/triggers/TriggerList.svelte +++ b/frontend/src/lib/components/triggers/TriggerList.svelte @@ -39,14 +39,16 @@ Pen, Plus, Route, + Tag, Trash, Unplug, UserPlus } from 'lucide-svelte' import CenteredPage from '$lib/components/CenteredPage.svelte' - import { Alert, Badge, Button, EmptyState, Skeleton } from '$lib/components/common' + import { Alert, Button, EmptyState, Skeleton } from '$lib/components/common' import ConfirmationModal from '$lib/components/common/confirmationModal/ConfirmationModal.svelte' import RowIcon from '$lib/components/common/table/RowIcon.svelte' + import LabelBadge from '$lib/components/common/badge/LabelBadge.svelte' import TreeViewRoot from '$lib/components/home/TreeViewRoot.svelte' import { twMerge } from 'tailwind-merge' import TreeViewControls from '$lib/components/home/TreeViewControls.svelte' @@ -613,7 +615,9 @@ {@const pinging = ping && ping.getTime() > new Date().getTime() - 15 * 1000} {@const effectiveMode = row.draft_only ? 'disabled' : row.mode} {@const enabled = effectiveMode === 'enabled' || effectiveMode === 'suspended'} -
+ +
{#if (enabled && (!pinging || row.error)) || (!enabled && row.error) || (enabled && !row.server_id)} @@ -730,7 +734,7 @@ )} style={depth > 0 ? `padding-left: ${(depth + 1) * 16}px;` : ''} > -
+
{@render rowTitle(row, hasDraft)} -