Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
Merge remote-tracking branch 'origin/dev' into feat/native-tool-discovery
Alfredo Lopez541dee82c7a5
diff --cc control-api/package-lock.jsonindex 7d6bad938,7d6bad938..ff69417b7--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@@ -1,12 -1,12 +1,12 @@@{"name": "clerum-control-api",-- "version": "0.1.711",++ "version": "0.1.712","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",-- "version": "0.1.711",++ "version": "0.1.712","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --cc control-api/package.jsonindex 0882b95ab,0882b95ab..7488e270c--- a/control-api/package.json+++ b/control-api/package.json@@@ -1,6 -1,6 +1,6 @@@{"name": "clerum-control-api",-- "version": "0.1.711",++ "version": "0.1.712","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --cc mcp-host/src/agent/taskExecutor.tsindex 7bdc97c05,27c9081fa..23f952914--- a/mcp-host/src/agent/taskExecutor.ts+++ b/mcp-host/src/agent/taskExecutor.ts@@@ -62,10 -61,11 +63,11 @@@ importCAPABILITY_CONTRACT_TEXT,DESKTOP_ENVIRONMENT_HINT,DefaultPromptBuilder,+ GFS_WORKSPACE_FILE_GUIDANCE_TEXT,MCP_SERVER_SELECTION_TEXT,MEMORY_GUIDANCE_TEXT,- TOOL_DISCOVERY_TEXT,WORKFLOW_RECIPES_TEXT,+ toolDiscoveryText,} from '../core/reasoning/promptBuilder'import type { SystemPromptParts } from '../core/reasoning/systemPrompt'import { BasicSafety } from '../core/safety/safety'@@@ -1907,10 -1984,9 +1989,11 @@@ export class TaskExecutortools.some(t => t.name === 'clerum__get_capabilities'),tools.some(t => t.name.startsWith('desktop_') || t.name.startsWith('browser_')),tools.some(t => t.name.startsWith('workflow_')),+ tools.some(t => t.name === 'clerum__gfs_download'),tools.some(t => t.name.includes('__')),tools.some(t => t.name === 'clerum__tool_search'),+ // #1003 — the discovery guidance text depends on the native presentation.+ appConfig.nativeToolPresentation,])// R2 — the system prompt embeds the model name, so a cache entry built for a// different (e.g. just-swapped) model is a miss: rebuild, but keep the frozen@@@ -1963,10 -2038,9 +2047,11 @@@platformHints,capabilities,workflowGuidance: hasWorkflowTools ? WORKFLOW_RECIPES_TEXT : '',+ gfsWorkspaceGuidance: hasGfsDownloadTool ? GFS_WORKSPACE_FILE_GUIDANCE_TEXT : '',mcpServerGuidance: hasMcpTools ? MCP_SERVER_SELECTION_TEXT : '',- toolDiscoveryGuidance: hasToolDiscovery ? TOOL_DISCOVERY_TEXT : '',+ toolDiscoveryGuidance: hasToolDiscovery+ ? toolDiscoveryText(appConfig.nativeToolPresentation)+ : '',memoryGuidance: hasMemoryTools ? MEMORY_GUIDANCE_TEXT : '',})this.deps.promptCache.set(sessionKey, {@@@ -2064,9 -2130,34 +2141,37 @@@appConfig,this.deps.failover?.policy.fallbacks)+ // #1003 — native-tool presentation is host-wide and provider-independent:+ // it never depends on the MCP presentation resolved above.+ const nativeAuto = appConfig.nativeToolPresentation === 'auto'+ const gfsCallerIdentity = this.task.sourceMessage?.sender ?? GFS_SYSTEM_CALLER_IDENTITY+ const gfsProcessingLeaseProvider =+ this.deps.gfsProcessingLeaseProvider ??+ (this.deps.gfsDownloadStore && gfsCallerIdentity+ ? this.deps.gfsDownloadStore.processingLeaseProvider(gfsCallerIdentity)+ : undefined)+ const gfsWorkspace = gfsManagedWorkspaceExecution({+ approvalEnabled: appConfig.enableApproval,+ source: this.task.source,+ callerIdentity: gfsCallerIdentity,+ store: this.deps.gfsDownloadStore,+ callerWorkspacePath: this.deps.gfsCallerWorkspacePath,+ processingLeaseProvider: gfsProcessingLeaseProvider,+ approvalConfig: this.deps.approvalConfig,+ retentionOwnerId: this.taskId,+ })+ const gfsDeliveryEligible = gfsWorkspace+ ? gfsWorkspaceExecutionEnabled({+ approvalEnabled: appConfig.enableApproval,+ source: this.task.source,+ callerIdentity: this.task.sourceMessage?.sender,+ store: gfsWorkspace.store,+ callerWorkspacePath: gfsWorkspace.callerWorkspacePath,+ processingLeaseProvider: gfsWorkspace.processingLeaseProvider,+ approvalConfig: this.deps.approvalConfig,+ retentionOwnerId: this.taskId,+ })+ : falseconst nativeRegistry = new NativeToolRegistry(// The spillover threshold is a top-level setting; clerum__attachment_read// states it in its description (#666).@@@ -2090,12 -2181,11 +2195,13 @@@// (clerum__tool_search / clerum__tool_describe). Reuses the same manager// already threaded into the MCP tool registry below.this.deps.mcpManager ?? undefined,- presentation.bridgeEnabled,+ // #1003 — MCP discovery and native discovery are separate decisions;+ // either one registers the bridge tools.+ { mcpDiscovery: presentation.bridgeEnabled, nativeDiscovery: nativeAuto },// §13 (stateless agents): the active provider's credential slot is the// only one that survives into shell_exec's child env.- this.deps.llmProvider.getProviderType()+ this.deps.llmProvider.getProviderType(),+ gfsWorkspace ? { ...gfsWorkspace, deliveryAvailable: gfsDeliveryEligible } : undefined)await registerDesktopTools(nativeRegistry)// Eagerly open this caller's remote OAuth partitions before the catalog is@@@ -2159,52 -2258,13 +2274,53 @@@: baseControllerconst mcpManager = this.deps.mcpManager+ // Exact native membership preserves every native/plugin capability.+ const nativeDefinitions = nativeRegistry.listDefinitions()+ const nativeNames = new Set(nativeDefinitions.map(d => d.name))++ // #1003 — native presentation wraps OUTSIDE the MCP decision on every+ // return, so it can only remove natives from the list the MCP presentation+ // produced. In `direct` it returns that list unchanged.+ const withNativePresentation = (controller: LoopController): LoopController =>+ new NativeToolPresentationController(controller, nativeDefinitions, {+ mode: appConfig.nativeToolPresentation,+ discoveryBytes: appConfig.nativeToolDiscoveryBytes,+ })++ // The bridge intercept (executeToolCalls) needs `nativeNames` + the live+ // deferrable catalog. It exists exactly when NativeToolRegistry registered+ // the bridge tools (MCP discovery with an McpManager, or native `auto`), so+ // it is derived from the registry rather than repeating that predicate.+ // Codex direct with native `direct` observes presentation without+ // installing discovery interception or registering bridge tools.+ const bridge: LoopConfig['bridge'] = [...BRIDGE_TOOL_NAMES].every(name => nativeNames.has(name))+ ? {+ nativeNames,+ getDeferrableCatalogNames: () =>+ mcpManager+ ? new Set(+ mcpManager+ .getAllTools()+ .map(t => t.name)+ .filter(name => !nativeNames.has(name))+ )+ : new Set<string>(),+ nativeTargets: nativeAuto,+ }+ : undefined+// Codex direct still observes the live catalog; observation must not enable discovery.if (!presentation.bridgeEnabled && presentation.codexMode === undefined) {- return { registry: compositeRegistry, nativeRegistry, loopController: innerController }+ return {+ registry: compositeRegistry,++ nativeRegistry,+ loopController: withNativePresentation(innerController),+ // Native `auto` only: MCP presentation is unchanged (no MCP decision on+ // this path) but the bridge serves natives and keeps MCP tools callable.+ bridge,+ }}- // Exact native membership preserves every native/plugin capability.- const nativeNames = new Set(nativeRegistry.listDefinitions().map(d => d.name))// LOCKED #6: the latch lives on the session-scoped Conversation, NOT on the// per-task controller, so a server connecting/disconnecting BETWEEN turns// cannot flip `tools[]` and re-introduce cache invalidation. Ephemeral RAM@@@ -2227,11 -2287,24 +2343,12 @@@})- // The bridge intercept (executeToolCalls) needs `nativeNames` + the live- // deferrable catalog. Direct mode observes presentation without installing- // discovery interception or registering bridge tools.- const bridge: LoopConfig['bridge'] =- presentation.bridgeEnabled && mcpManager- ? {- nativeNames,- getDeferrableCatalogNames: () =>- new Set(- mcpManager- .getAllTools()- .map(t => t.name)- .filter(name => !nativeNames.has(name))- ),- }- : undefined-- return { registry: compositeRegistry, nativeRegistry, loopController, bridge }+ return {+ registry: compositeRegistry,++ nativeRegistry,+ loopController: withNativePresentation(loopController),+ bridge,+ }}private async prepareChannelWorkflowCallerContext(): Promise<diff --cc mcp-host/src/core/orchestration/__tests__/nativeDirectDevBaseline.tsindex 0935c17ef,000000000..4a53a097emode 100644,000000..100644--- a/mcp-host/src/core/orchestration/__tests__/nativeDirectDevBaseline.ts+++ b/mcp-host/src/core/orchestration/__tests__/nativeDirectDevBaseline.ts@@@ -1,405 -1,0 +1,405 @@@+/**+ * I4 baseline (#1003): first-turn `tools[]` and system prompt that `origin/dev`- * (2d7d9c523, before native presentation existed) sends to the provider for each++ * (8abf414a6, before native presentation existed) sends to the provider for each+ * MCP presentation cell. Captured by running the scenario of+ * `nativeToolPresentation.integration.test.ts` (I4 block) against that commit.+ * Native `direct` must reproduce it byte for byte. Regenerate only from a+ * pre-#1003 `dev` commit, never from this branch.+ */+export const NATIVE_DIRECT_DEV_BASELINE: Record<+ string,+ { toolNames: string[]; toolsSha256: string; systemSha256: string }+> = {+ 'codex-direct/2': {+ toolNames: [+ 'file_read',+ 'file_write',+ 'shell_exec',+ 'http_request',+ 'system_info',+ 'json_transform',+ 'clerum__generate_markdown',+ 'clerum__generate_pdf',+ 'clerum__generate_docx',+ 'clerum__generate_xlsx',+ 'clerum__generate_pptx',+ 'clerum__generate_chart',+ 'clerum__generate_dashboard',+ 'clerum__get_capabilities',+ 'alpha__record__read_000',+ 'beta__record__read_001',+ ],- toolsSha256: '2409a12dd875a5df8e1c987fdd0e5eab5ea861faa0d55f1658be82a885b48312',- systemSha256: 'c02a41728de2957c682e05613b3b74ac9a7ff25aba2cd815a93afaf7bd14655a',++ toolsSha256: 'a992e7d77c57570a3fefc06bef7f0429a99c7532615d99f8a6ac8c0c4e1406c8',++ systemSha256: 'dd9c0cce6dc45afc3cbe6be82fed77104d36304fb93312ab224b4d964c1f58b2',+ },+ 'codex-direct/83': {+ toolNames: [+ 'file_read',+ 'file_write',+ 'shell_exec',+ 'http_request',+ 'system_info',+ 'json_transform',+ 'clerum__generate_markdown',+ 'clerum__generate_pdf',+ 'clerum__generate_docx',+ 'clerum__generate_xlsx',+ 'clerum__generate_pptx',+ 'clerum__generate_chart',+ 'clerum__generate_dashboard',+ 'clerum__get_capabilities',+ 'alpha__record__read_000',+ 'alpha__record__read_002',+ 'alpha__record__read_004',+ 'alpha__record__read_006',+ 'alpha__record__read_008',+ 'alpha__record__read_010',+ 'alpha__record__read_012',+ 'alpha__record__read_014',+ 'alpha__record__read_016',+ 'alpha__record__read_018',+ 'alpha__record__read_020',+ 'alpha__record__read_022',+ 'alpha__record__read_024',+ 'alpha__record__read_026',+ 'alpha__record__read_028',+ 'alpha__record__read_030',+ 'alpha__record__read_032',+ 'alpha__record__read_034',+ 'alpha__record__read_036',+ 'alpha__record__read_038',+ 'alpha__record__read_040',+ 'alpha__record__read_042',+ 'alpha__record__read_044',+ 'alpha__record__read_046',+ 'alpha__record__read_048',+ 'alpha__record__read_050',+ 'alpha__record__read_052',+ 'alpha__record__read_054',+ 'alpha__record__read_056',+ 'alpha__record__read_058',+ 'alpha__record__read_060',+ 'alpha__record__read_062',+ 'alpha__record__read_064',+ 'alpha__record__read_066',+ 'alpha__record__read_068',+ 'alpha__record__read_070',+ 'alpha__record__read_072',+ 'alpha__record__read_074',+ 'alpha__record__read_076',+ 'alpha__record__read_078',+ 'alpha__record__read_080',+ 'alpha__record__read_082',+ 'beta__record__read_001',+ 'beta__record__read_003',+ 'beta__record__read_005',+ 'beta__record__read_007',+ 'beta__record__read_009',+ 'beta__record__read_011',+ 'beta__record__read_013',+ 'beta__record__read_015',+ 'beta__record__read_017',+ 'beta__record__read_019',+ 'beta__record__read_021',+ 'beta__record__read_023',+ 'beta__record__read_025',+ 'beta__record__read_027',+ 'beta__record__read_029',+ 'beta__record__read_031',+ 'beta__record__read_033',+ 'beta__record__read_035',+ 'beta__record__read_037',+ 'beta__record__read_039',+ 'beta__record__read_041',+ 'beta__record__read_043',+ 'beta__record__read_045',+ 'beta__record__read_047',+ 'beta__record__read_049',+ 'beta__record__read_051',+ 'beta__record__read_053',+ 'beta__record__read_055',+ 'beta__record__read_057',+ 'beta__record__read_059',+ 'beta__record__read_061',+ 'beta__record__read_063',+ 'beta__record__read_065',+ 'beta__record__read_067',+ 'beta__record__read_069',+ 'beta__record__read_071',+ 'beta__record__read_073',+ 'beta__record__read_075',+ 'beta__record__read_077',+ 'beta__record__read_079',+ 'beta__record__read_081',+ ],- toolsSha256: '9d9d6efb1c88559a45054d080f1a63af1518c293c15e23346fe8a03d86c3ae65',- systemSha256: 'ba66736355feed08bd74ba6ad6599422a397cc0b154355925c4e2df5eebee339',++ toolsSha256: 'a073baee0a6366af9b23104a9a208069ff856f923ad15bd716d3fa0a3f2b06b3',++ systemSha256: 'dd4e68e963a5374dde8c1941409a571d10e430ddb99dcf2dee8ccb2803d09695',+ },+ 'codex-auto/2': {+ toolNames: [+ 'file_read',+ 'file_write',+ 'shell_exec',+ 'http_request',+ 'system_info',+ 'json_transform',+ 'clerum__generate_markdown',+ 'clerum__generate_pdf',+ 'clerum__generate_docx',+ 'clerum__generate_xlsx',+ 'clerum__generate_pptx',+ 'clerum__generate_chart',+ 'clerum__generate_dashboard',+ 'clerum__get_capabilities',+ 'clerum__tool_search',+ 'clerum__tool_describe',+ 'clerum__tool_call',+ 'alpha__record__read_000',+ 'beta__record__read_001',+ ],- toolsSha256: 'a91bd4aeee6e490f01433c021ee6bff097a65676899b70ac1d2d37504d5bbe63',- systemSha256: 'a28b3d927a8f43ac0cd9c4e4ad586f2caceb025fcb443bfc7ff7d95ab9236fce',++ toolsSha256: '2c91046edb89e11f5a73b5b72f12a2f23ea74863231785f7e4f0a97397a4e5bd',++ systemSha256: 'c365b44ba88b717873344d1e6e1bf9b0ed086a523886bc7f2b7acbb2143c783c',+ },+ 'codex-auto/83': {+ toolNames: [+ 'file_read',+ 'file_write',+ 'shell_exec',+ 'http_request',+ 'system_info',+ 'json_transform',+ 'clerum__generate_markdown',+ 'clerum__generate_pdf',+ 'clerum__generate_docx',+ 'clerum__generate_xlsx',+ 'clerum__generate_pptx',+ 'clerum__generate_chart',+ 'clerum__generate_dashboard',+ 'clerum__get_capabilities',+ 'clerum__tool_search',+ 'clerum__tool_describe',+ 'clerum__tool_call',+ ],- toolsSha256: '6b3b9f2af53857e7a6dfc36b412c416a0f133166b02f0906ae343653dc7fbbec',- systemSha256: '4ee65193fda51cb111cf594c75d2dcd8c9e73f972b3e80053fd43dd6f4ebd3eb',++ toolsSha256: 'f899756077ce4b6f3f177efc6af3ccfcf850b19e06a7b46b44364c9632da0e5f',++ systemSha256: '605cb923321cf52f148b1d3da8e2d28de9aafb94aee274a3ef581de32c656105',+ },+ 'codex-discovery/2': {+ toolNames: [+ 'file_read',+ 'file_write',+ 'shell_exec',+ 'http_request',+ 'system_info',+ 'json_transform',+ 'clerum__generate_markdown',+ 'clerum__generate_pdf',+ 'clerum__generate_docx',+ 'clerum__generate_xlsx',+ 'clerum__generate_pptx',+ 'clerum__generate_chart',+ 'clerum__generate_dashboard',+ 'clerum__get_capabilities',+ 'clerum__tool_search',+ 'clerum__tool_describe',+ 'clerum__tool_call',+ ],- toolsSha256: '6b3b9f2af53857e7a6dfc36b412c416a0f133166b02f0906ae343653dc7fbbec',- systemSha256: '4ee65193fda51cb111cf594c75d2dcd8c9e73f972b3e80053fd43dd6f4ebd3eb',++ toolsSha256: 'f899756077ce4b6f3f177efc6af3ccfcf850b19e06a7b46b44364c9632da0e5f',++ systemSha256: '605cb923321cf52f148b1d3da8e2d28de9aafb94aee274a3ef581de32c656105',+ },+ 'codex-discovery/83': {+ toolNames: [+ 'file_read',+ 'file_write',+ 'shell_exec',+ 'http_request',+ 'system_info',+ 'json_transform',+ 'clerum__generate_markdown',+ 'clerum__generate_pdf',+ 'clerum__generate_docx',+ 'clerum__generate_xlsx',+ 'clerum__generate_pptx',+ 'clerum__generate_chart',+ 'clerum__generate_dashboard',+ 'clerum__get_capabilities',+ 'clerum__tool_search',+ 'clerum__tool_describe',+ 'clerum__tool_call',+ ],- toolsSha256: '6b3b9f2af53857e7a6dfc36b412c416a0f133166b02f0906ae343653dc7fbbec',- systemSha256: '4ee65193fda51cb111cf594c75d2dcd8c9e73f972b3e80053fd43dd6f4ebd3eb',++ toolsSha256: 'f899756077ce4b6f3f177efc6af3ccfcf850b19e06a7b46b44364c9632da0e5f',++ systemSha256: '605cb923321cf52f148b1d3da8e2d28de9aafb94aee274a3ef581de32c656105',+ },+ 'legacy-on/2': {+ toolNames: [+ 'file_read',+ 'file_write',+ 'shell_exec',+ 'http_request',+ 'system_info',+ 'json_transform',+ 'clerum__generate_markdown',+ 'clerum__generate_pdf',+ 'clerum__generate_docx',+ 'clerum__generate_xlsx',+ 'clerum__generate_pptx',+ 'clerum__generate_chart',+ 'clerum__generate_dashboard',+ 'clerum__get_capabilities',+ 'clerum__tool_search',+ 'clerum__tool_describe',+ 'clerum__tool_call',+ 'alpha__record__read_000',+ 'beta__record__read_001',+ ],- toolsSha256: 'a91bd4aeee6e490f01433c021ee6bff097a65676899b70ac1d2d37504d5bbe63',- systemSha256: '1f684a652923a48fea40e97afcea5d73a804d89c84a8e5a60a4f50f49d2c71ed',++ toolsSha256: '2c91046edb89e11f5a73b5b72f12a2f23ea74863231785f7e4f0a97397a4e5bd',++ systemSha256: 'b7900c1272b49f5a19efaa8936f2ad673d1f1ab3814b6d467a93eef2cf1826ac',+ },+ 'legacy-on/83': {+ toolNames: [+ 'file_read',+ 'file_write',+ 'shell_exec',+ 'http_request',+ 'system_info',+ 'json_transform',+ 'clerum__generate_markdown',+ 'clerum__generate_pdf',+ 'clerum__generate_docx',+ 'clerum__generate_xlsx',+ 'clerum__generate_pptx',+ 'clerum__generate_chart',+ 'clerum__generate_dashboard',+ 'clerum__get_capabilities',+ 'clerum__tool_search',+ 'clerum__tool_describe',+ 'clerum__tool_call',+ ],- toolsSha256: '6b3b9f2af53857e7a6dfc36b412c416a0f133166b02f0906ae343653dc7fbbec',- systemSha256: '35dc262baf35dbe2e3d7947d36e49002341fb31009b16452286bdc8d05a03f96',++ toolsSha256: 'f899756077ce4b6f3f177efc6af3ccfcf850b19e06a7b46b44364c9632da0e5f',++ systemSha256: '5cb20ca95229506beeb15a420c0f938d105c29a77791a334075616647d5fb171',+ },+ 'legacy-off/2': {+ toolNames: [+ 'file_read',+ 'file_write',+ 'shell_exec',+ 'http_request',+ 'system_info',+ 'json_transform',+ 'clerum__generate_markdown',+ 'clerum__generate_pdf',+ 'clerum__generate_docx',+ 'clerum__generate_xlsx',+ 'clerum__generate_pptx',+ 'clerum__generate_chart',+ 'clerum__generate_dashboard',+ 'clerum__get_capabilities',+ 'alpha__record__read_000',+ 'beta__record__read_001',+ ],- toolsSha256: '2409a12dd875a5df8e1c987fdd0e5eab5ea861faa0d55f1658be82a885b48312',- systemSha256: '62762345b6123fd199dda6068ebfe5d993a8c181318c0b889a66c65581b620e3',++ toolsSha256: 'a992e7d77c57570a3fefc06bef7f0429a99c7532615d99f8a6ac8c0c4e1406c8',++ systemSha256: '3fc842ee48973be65169922a23933a9bdd94da0af6a8d979a91cd135190ec6f4',+ },+ 'legacy-off/83': {+ toolNames: [+ 'file_read',+ 'file_write',+ 'shell_exec',+ 'http_request',+ 'system_info',+ 'json_transform',+ 'clerum__generate_markdown',+ 'clerum__generate_pdf',+ 'clerum__generate_docx',+ 'clerum__generate_xlsx',+ 'clerum__generate_pptx',+ 'clerum__generate_chart',+ 'clerum__generate_dashboard',+ 'clerum__get_capabilities',+ 'alpha__record__read_000',+ 'alpha__record__read_002',+ 'alpha__record__read_004',+ 'alpha__record__read_006',+ 'alpha__record__read_008',+ 'alpha__record__read_010',+ 'alpha__record__read_012',+ 'alpha__record__read_014',+ 'alpha__record__read_016',+ 'alpha__record__read_018',+ 'alpha__record__read_020',+ 'alpha__record__read_022',+ 'alpha__record__read_024',+ 'alpha__record__read_026',+ 'alpha__record__read_028',+ 'alpha__record__read_030',+ 'alpha__record__read_032',+ 'alpha__record__read_034',+ 'alpha__record__read_036',+ 'alpha__record__read_038',+ 'alpha__record__read_040',+ 'alpha__record__read_042',+ 'alpha__record__read_044',+ 'alpha__record__read_046',+ 'alpha__record__read_048',+ 'alpha__record__read_050',+ 'alpha__record__read_052',+ 'alpha__record__read_054',+ 'alpha__record__read_056',+ 'alpha__record__read_058',+ 'alpha__record__read_060',+ 'alpha__record__read_062',+ 'alpha__record__read_064',+ 'alpha__record__read_066',+ 'alpha__record__read_068',+ 'alpha__record__read_070',+ 'alpha__record__read_072',+ 'alpha__record__read_074',+ 'alpha__record__read_076',+ 'alpha__record__read_078',+ 'alpha__record__read_080',+ 'alpha__record__read_082',+ 'beta__record__read_001',+ 'beta__record__read_003',+ 'beta__record__read_005',+ 'beta__record__read_007',+ 'beta__record__read_009',+ 'beta__record__read_011',+ 'beta__record__read_013',+ 'beta__record__read_015',+ 'beta__record__read_017',+ 'beta__record__read_019',+ 'beta__record__read_021',+ 'beta__record__read_023',+ 'beta__record__read_025',+ 'beta__record__read_027',+ 'beta__record__read_029',+ 'beta__record__read_031',+ 'beta__record__read_033',+ 'beta__record__read_035',+ 'beta__record__read_037',+ 'beta__record__read_039',+ 'beta__record__read_041',+ 'beta__record__read_043',+ 'beta__record__read_045',+ 'beta__record__read_047',+ 'beta__record__read_049',+ 'beta__record__read_051',+ 'beta__record__read_053',+ 'beta__record__read_055',+ 'beta__record__read_057',+ 'beta__record__read_059',+ 'beta__record__read_061',+ 'beta__record__read_063',+ 'beta__record__read_065',+ 'beta__record__read_067',+ 'beta__record__read_069',+ 'beta__record__read_071',+ 'beta__record__read_073',+ 'beta__record__read_075',+ 'beta__record__read_077',+ 'beta__record__read_079',+ 'beta__record__read_081',+ ],- toolsSha256: '9d9d6efb1c88559a45054d080f1a63af1518c293c15e23346fe8a03d86c3ae65',- systemSha256: '88e5dff88b70e5bf8d90fccd3bbc2dd7347750edb20068c4d41d5596f1349452',++ toolsSha256: 'a073baee0a6366af9b23104a9a208069ff856f923ad15bd716d3fa0a3f2b06b3',++ systemSha256: 'd8376f2fc625ae71154fb63608d60aeca997a085bc3d0723f598b49e01b55bbd',+ },+}diff --cc mcp-host/src/core/orchestration/toolUseLoopToolBatch.tsindex ddea8f351,c8e957521..94644724f--- a/mcp-host/src/core/orchestration/toolUseLoopToolBatch.ts+++ b/mcp-host/src/core/orchestration/toolUseLoopToolBatch.ts@@@ -1,5 -1,3 +1,4 @@@- import { randomUUID } from 'crypto'+import { BRIDGE_TOOL_NAMES } from '../../capabilities/toolCatalogTools'import { extractToolIntent, getDisplayName } from '../../progress/intentExtraction.js'import {buildConnectRequiredApproval,@@@ -20,36 -12,19 +13,11 @@@ import typeToolResult,} from '../types'import type { LoopConfig } from './loopConfig'+ import { admitToolCall, executeAdmittedTool } from './toolCallPolicy'import { collectToolAttachments } from './toolUseLoopMessages'- import { executeSingleTool, reportToolComplete, reportToolStart } from './toolUseLoopSingleTool'+ import { reportToolComplete, reportToolStart } from './toolUseLoopSingleTool'import { isWorkflowTriggerNotFoundToolResult } from './toolUseLoopWorkflowTriggerFallbacks'- /**- * Build a guardrail-originated approval suspension (spec §6.3), shaped like the- * existing approval gate so the batch loop's suspend path handles it unchanged.- */- function buildGuardrailSuspension(- call: ToolCall,- config: LoopConfig,- reasonCode: string- ): { type: 'suspend'; approval: PendingApproval } {- const descriptor = config.toolRegistry.get(call.name)?.traceDescriptor?.(call.arguments) ?? {- kind: 'internal_tool' as const,- sourceRef: 'mcp-host',- }- const approval: PendingApproval = {- request_id: randomUUID(),- tool_name: call.name,- tool_kind: descriptor.kind,- tool_source_ref: descriptor.sourceRef,- parameters: call.arguments,- description: `Guardrail requires approval (${reasonCode})`,- tool_call_id: '', // filled below from call.id- context_snapshot: [],- }- return { type: 'suspend', approval }- }-/** The 3 dynamic-tool-loading bridge tools. They are native and must never be- * the TARGET of `clerum__tool_call` (LOCKED #11 — no recursion). */-const BRIDGE_TOOL_NAMES = new Set([- 'clerum__tool_search',- 'clerum__tool_describe',- 'clerum__tool_call',-])--function bridgeError(call: ToolCall, message: string): ToolResult {// Preserve the original `call.id`/name so the provider pairs the result with// the model's `clerum__tool_call` tool_use block (LOCKED #9).diff --cc mcp-host/src/core/reasoning/__tests__/promptBuilder.test.tsindex db8e99bf2,88eecead9..466ea793e--- a/mcp-host/src/core/reasoning/__tests__/promptBuilder.test.ts+++ b/mcp-host/src/core/reasoning/__tests__/promptBuilder.test.ts@@@ -34,3 -38,22 +38,22 @@@ describe('DefaultPromptBuilder — memoexpect(occurrences).toBe(1)})})++ describe('DefaultPromptBuilder — governed GFS workspace files', () => {+ it('includes the guidance when the explicit download tool is registered', () => {- const builder = new DefaultPromptBuilder()++ const builder = new DefaultPromptBuilder({ nativeToolPresentation: 'direct' })+ const msg = builder.buildSystemPrompt([tool('clerum__gfs_download')])+ expect(msg.content).toContain(GFS_WORKSPACE_FILE_GUIDANCE_TEXT)+ expect(msg.content).toContain('never invent a resourceId')+ expect(msg.content).toContain('call `clerum__gfs_download` and use the exact `path`')+ expect(msg.content).toContain('never guess a `.gfs-downloads/<filename>` path')+ expect(msg.content).toContain('copy the complete parsed header array verbatim')+ expect(msg.content).toContain('write outputs outside `.gfs-downloads`')+ })++ it('omits the guidance when workspace download is unavailable', () => {- const builder = new DefaultPromptBuilder()++ const builder = new DefaultPromptBuilder({ nativeToolPresentation: 'direct' })+ const msg = builder.buildSystemPrompt([tool('clerum__gfs_read')])+ expect(msg.content).not.toContain(GFS_WORKSPACE_FILE_GUIDANCE_TEXT)+ })+ })diff --cc mcp-host/src/core/reasoning/promptBuilder.tsindex e77b4c685,f5e97d3d6..f92e48f58--- a/mcp-host/src/core/reasoning/promptBuilder.ts+++ b/mcp-host/src/core/reasoning/promptBuilder.ts@@@ -1,7 -1,7 +1,8 @@@import { createHash } from 'node:crypto'+ import { GFS_LOCAL_PROCESSING_GUIDANCE } from '../../internalTools/gfsReadTypes'import { logger } from '../../logger'import { PromptBuilder } from '../interfaces'+import type { NativeToolPresentation } from '../orchestration/toolPresentationPolicy'import { ChatMessage, ToolDefinition } from '../types'import type { BuilderInput, SystemPromptParts } from './systemPrompt'diff --cc mcp-host/src/workspace/__tests__/gfsCallerRootBinding.test.tsindex 000000000,e22a8612f..105d6e508mode 000000,100644..100644--- a/mcp-host/src/workspace/__tests__/gfsCallerRootBinding.test.ts+++ b/mcp-host/src/workspace/__tests__/gfsCallerRootBinding.test.ts@@@ -1,0 -1,284 +1,284 @@@+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+ import { spawn } from 'node:child_process'+ import * as fs from 'node:fs'+ import * as os from 'node:os'+ import * as path from 'node:path'+ import type { NativeToolConfig } from '../../core/interfaces'+ import { NativeToolRegistry } from '../../core/tools/nativeToolRegistry'+ import { GfsDownloadStore } from '../../internalTools/gfsDownloadStore'+ import type { IncomingMessage } from '../../server/types'+ import { type CallerRootBinding, resolveCallerRootBinding } from '../callerRootBinding'+ import { ScopedWorkspaceProvider } from '../scopedWorkspace'+ import { deriveUserKeyFromSource } from '../userKey'++ const config: NativeToolConfig = {+ workspacePath: '',+ shellTimeout: 5_000,+ toolTimeout: 60_000,+ toolProgressInterval: 0,+ httpAllowlist: [],+ envAllowlist: ['PATH'],+ memoryMaxSize: 1_048_576,+ }++ vi.mock('node:child_process', async importOriginal => {+ const actual = await importOriginal<typeof import('node:child_process')>()+ return { ...actual, spawn: vi.fn(actual.spawn) }+ })++ describe('NativeRegistry GFS caller file-tool binding', () => {+ let root: string+ let store: GfsDownloadStore+ const stores: GfsDownloadStore[] = []++ beforeEach(() => {+ vi.clearAllMocks()+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'gfs-caller-binding-'))+ })++ afterEach(async () => {+ for (const item of stores.splice(0)) await item.close().catch(() => undefined)+ fs.rmSync(root, { recursive: true, force: true })+ })++ function source(): IncomingMessage {+ return {+ content: 'process file',+ channelType: 'rpc',+ channelId: 'agent',+ sender: 'alice',+ timestamp: new Date().toISOString(),+ messageId: 'message-1',+ hostRef: 'host-1',+ }+ }++ function registry(callerRoot: string | undefined, deliveryAvailable = true) {+ return new NativeToolRegistry(+ { ...config, workspacePath: root },+ 'conversation-1',+ undefined,+ source(),+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,- false,++ { mcpDiscovery: false, nativeDiscovery: false },+ undefined,+ {+ store,+ deliveryAvailable,+ callerIdentity: 'alice',+ callerWorkspacePath: callerRoot,+ processingLeaseProvider: store.processingLeaseProvider('alice'),+ retentionOwnerId: '11111111-1111-4111-8111-111111111111',+ }+ )+ }++ it('binds memory-off file tools to the verified caller root and reserves store accounting', async () => {+ store = new GfsDownloadStore(root)+ stores.push(store)+ await store.initialize()+ const callerRoot = new ScopedWorkspaceProvider(root).forSource(source()).userRootPath+ const registryForCaller = registry(callerRoot)++ await registryForCaller.get('file_write')!.execute({ path: 'own.txt', content: 'own' })+ expect(fs.existsSync(path.join(callerRoot, 'own.txt'))).toBe(true)+ expect(fs.existsSync(path.join(root, 'own.txt'))).toBe(false)++ const ledger = path.join(root, '.gfs-download-store', 'ledger-v1.json')+ const before = fs.readFileSync(ledger, 'utf-8')+ const directRead = await registryForCaller.get('file_read')!.execute({+ path: '.gfs-download-store/ledger-v1.json',+ })+ const directWrite = await registryForCaller.get('file_write')!.execute({+ path: '.gfs-download-store/ledger-v1.json',+ content: 'stolen',+ })+ expect(directRead.is_error).toBe(true)+ expect(directWrite.is_error).toBe(true)+ expect(fs.readFileSync(ledger, 'utf-8')).toBe(before)+ })++ it('blocks another caller cache and symlink aliases through the caller root', async () => {+ store = new GfsDownloadStore(root)+ stores.push(store)+ await store.initialize()+ const provider = new ScopedWorkspaceProvider(root)+ const aliceRoot = provider.forSource(source()).userRootPath+ const bobRoot = provider.forUser('bob').userRootPath+ const bobLedger = path.join(bobRoot, '.gfs-download-store', 'ledger-v2.json')+ fs.mkdirSync(path.dirname(bobLedger), { recursive: true })+ fs.writeFileSync(bobLedger, 'bob accounting', 'utf-8')+ fs.symlinkSync(bobLedger, path.join(aliceRoot, 'other-caller-ledger.md'))+ const registryForCaller = registry(aliceRoot)++ const sibling = await registryForCaller.get('file_read')!.execute({+ path: 'other-caller-ledger.md',+ })+ const traversal = await registryForCaller.get('file_read')!.execute({+ path: '../bob/.gfs-download-store/ledger-v2.json',+ })+ expect(sibling.is_error).toBe(true)+ expect(traversal.is_error).toBe(true)+ })++ it('keeps the verified caller root when delivery is recovery-required', async () => {+ fs.mkdirSync(path.join(root, '.gfs-download-store'), { recursive: true })+ fs.writeFileSync(path.join(root, '.gfs-download-store', 'ledger-v1.json'), '{invalid')+ store = new GfsDownloadStore(root)+ stores.push(store)+ await store.initialize().catch(() => undefined)+ const callerRoot = new ScopedWorkspaceProvider(root).forSource(source()).userRootPath+ const degraded = registry(callerRoot, false)++ await degraded.get('file_write')!.execute({ path: 'degraded.txt', content: 'still scoped' })+ expect(fs.existsSync(path.join(callerRoot, 'degraded.txt'))).toBe(true)+ expect(fs.existsSync(path.join(root, 'degraded.txt'))).toBe(false)+ })++ it('rejects a caller root redirected directly to Host accounting', async () => {+ store = new GfsDownloadStore(root)+ stores.push(store)+ await store.initialize()+ const provider = new ScopedWorkspaceProvider(root)+ const lexicalCallerRoot = provider.forSource(source()).userRootPath+ fs.rmSync(lexicalCallerRoot, { recursive: true, force: true })+ fs.symlinkSync(path.join(root, '.gfs-download-store'), lexicalCallerRoot)++ const binding = resolveCallerRootBinding(provider, source())+ expect(binding.root).toBeUndefined()++ const redirected = registry(binding.root, false)+ expect(redirected.get('file_read')).toBeNull()+ expect(redirected.get('file_write')).toBeNull()+ const shell = await redirected.get('shell_exec')!.execute({ command: 'pwd' })+ expect(shell.is_error).toBe(true)+ expect(shell.content).toContain('Managed shell unavailable')+ expect(vi.mocked(spawn)).not.toHaveBeenCalled()+ })++ it('rejects a redirected users parent without falling back to another namespace', async () => {+ store = new GfsDownloadStore(root)+ stores.push(store)+ await store.initialize()+ const redirectedUsers = path.join(root, 'redirected-users')+ fs.mkdirSync(path.join(redirectedUsers), { recursive: true })+ fs.symlinkSync(redirectedUsers, path.join(root, 'users'))+ const provider = new ScopedWorkspaceProvider(root)++ const binding = resolveCallerRootBinding(provider, source())++ expect(binding.root).toBeUndefined()+ expect(fs.readdirSync(redirectedUsers)).toEqual([])+ const omitted = registry(binding.root, false)+ expect(omitted.get('file_read')).toBeNull()+ expect(omitted.get('file_write')).toBeNull()+ })++ it('does not create a caller child through a redirected users parent', async () => {+ store = new GfsDownloadStore(root)+ stores.push(store)+ await store.initialize()+ const accountingRoot = path.join(root, '.gfs-download-store')+ const ledger = path.join(accountingRoot, 'ledger-v1.json')+ const before = fs.readFileSync(ledger, 'utf-8')+ fs.symlinkSync(accountingRoot, path.join(root, 'users'))+ const provider = new ScopedWorkspaceProvider(root)+ const callerKey = deriveUserKeyFromSource(source())++ const binding = resolveCallerRootBinding(provider, source())++ expect(binding).toEqual({ failureCode: 'EEXIST' })+ expect(fs.existsSync(path.join(accountingRoot, callerKey))).toBe(false)+ expect(fs.readdirSync(accountingRoot)).not.toContain(callerKey)+ expect(fs.readFileSync(ledger, 'utf-8')).toBe(before)+ })++ it('creates and verifies the first healthy caller beneath a Host-owned users parent', () => {+ const provider = new ScopedWorkspaceProvider(root)+ expect(fs.existsSync(path.join(root, 'users'))).toBe(false)++ const binding = resolveCallerRootBinding(provider, source())+ const callerKey = deriveUserKeyFromSource(source())+ const expectedRoot = path.join(fs.realpathSync(root), 'users', callerKey)++ expect(binding).toEqual({ root: expectedRoot })+ expect(fs.statSync(path.join(root, 'users')).isDirectory()).toBe(true)+ expect(fs.statSync(expectedRoot).isDirectory()).toBe(true)+ })++ it('rejects a bound caller root replaced by accounting after Registry construction', async () => {+ store = new GfsDownloadStore(root)+ stores.push(store)+ await store.initialize()+ const provider = new ScopedWorkspaceProvider(root)+ const binding = resolveCallerRootBinding(provider, source())+ expect(binding.root).toBeDefined()+ const bound = registry(binding.root)+ const ledger = path.join(root, '.gfs-download-store', 'ledger-v1.json')+ const before = fs.readFileSync(ledger, 'utf-8')++ fs.rmSync(binding.root!, { recursive: true, force: true })+ fs.symlinkSync(path.join(root, '.gfs-download-store'), binding.root!)+ const read = await bound.get('file_read')!.execute({ path: 'ledger-v1.json' })+ const write = await bound.get('file_write')!.execute({+ path: 'ledger-v1.json',+ content: 'replacement',+ })+ const shell = await bound.get('shell_exec')!.execute({ command: 'pwd' })++ expect(read.is_error).toBe(true)+ expect(write.is_error).toBe(true)+ expect(shell.is_error).toBe(true)+ expect(fs.readFileSync(ledger, 'utf-8')).toBe(before)+ expect(vi.mocked(spawn)).not.toHaveBeenCalled()+ })++ it('uses the canonical healthy caller root for managed shell execution', async () => {+ store = new GfsDownloadStore(root)+ stores.push(store)+ await store.initialize()+ const provider = new ScopedWorkspaceProvider(root)+ const binding = resolveCallerRootBinding(provider, source())+ const healthy = registry(binding.root)++ const shell = await healthy.get('shell_exec')!.execute({ command: 'pwd' })++ expect(shell.is_error).toBe(false)+ expect(vi.mocked(spawn)).toHaveBeenCalledTimes(1)+ expect(vi.mocked(spawn).mock.calls[0][2]).toMatchObject({ cwd: binding.root })+ })++ it('omits managed file tools when no verified caller root exists', () => {+ store = new GfsDownloadStore(root)+ stores.push(store)+ const missingRoot = registry(undefined, false)+ expect(missingRoot.get('file_read')).toBeNull()+ expect(missingRoot.get('file_write')).toBeNull()+ })++ it('contains concrete filesystem binding failures and propagates programming errors', () => {+ const eaccES = () => {+ const error = new Error('unit') as NodeJS.ErrnoException+ error.code = 'EACCES'+ throw error+ }+ const unexpected = () => {+ throw new TypeError('unit programming error')+ }+ const provider = (thrower: () => never) =>+ ({ baseRootPath: root, forSource: thrower }) as unknown as ScopedWorkspaceProvider+ const expected: CallerRootBinding = resolveCallerRootBindingForTest(provider(eaccES))+ expect(expected).toEqual({ failureCode: 'EACCES' })+ expect(() => resolveCallerRootBindingForTest(provider(unexpected))).toThrow(TypeError)+ })+ })++ function resolveCallerRootBindingForTest(provider: ScopedWorkspaceProvider): CallerRootBinding {+ return resolveCallerRootBinding(provider, undefined)+ }