From 9dcdf9b2e848d2a324a43ea06fb96601c945b187 Mon Sep 17 00:00:00 2001 From: Christian Gunderman Date: Wed, 18 Mar 2026 19:52:40 -0700 Subject: [PATCH] Tilth context. --- packages/core/src/utils/environmentContext.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/core/src/utils/environmentContext.ts b/packages/core/src/utils/environmentContext.ts index abdf6faae9..83e4fac5cb 100644 --- a/packages/core/src/utils/environmentContext.ts +++ b/packages/core/src/utils/environmentContext.ts @@ -21,6 +21,18 @@ export async function getDirectoryContextString( const workspaceContext = config.getWorkspaceContext(); const workspaceDirectories = workspaceContext.getDirectories(); + + try { + const { execSync } = await import('child_process'); + // We try to run tilth using npx (which installs if missing) + const tilthOutput = execSync('npx -y tilth --map --scope ' + workspaceDirectories[0]).toString(); + const dirList = workspaceDirectories.map((dir) => ` - ${dir}`).join('\n'); + return `Use the following map to skip the need to read files and folders: + - **Workspace Directories:**\n${dirList}\n- **Directory Structure:**\n\n${tilthOutput}`; + } catch (e) { + // fallback if tilth fails + } + const folderStructures = await Promise.all( workspaceDirectories.map((dir) => getFolderStructure(dir, { @@ -76,6 +88,17 @@ My operating system is: ${platform} The project's temporary directory is: ${tempDir} ${directoryContext} + +You have access to a tool called \`tilth\` via \`run_shell_command\`. +It is a structural code reader designed for AI agents. +It understands code semantics (functions, classes, imports, etc.). + +Useful \`tilth\` commands: +1. \`tilth \` - Reads a file. If large, returns a structural outline (functions/classes) instead of truncating. +2. \`tilth --scope .\` - Finds definition and usages of a specific function or class across the codebase. +3. \`tilth --section 45-89\` - Reads a specific line range or markdown heading. + + ${environmentMemory} `.trim();