fix: scope chat work directory per-run instead of globally (#578)

* fix: scope chat work directory per-run instead of globally

* fix: refine work directory pill and search button controls

* feat: animate web search button toggle
This commit is contained in:
gagan 2026-05-27 03:09:56 +05:30 committed by GitHub
parent 45bdbfcbbc
commit d981fa9206
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 133 additions and 79 deletions

View file

@ -38,7 +38,12 @@ import { getRaw as getInlineTaskAgentRaw } from "../knowledge/inline_task_agent.
import { getRaw as getAgentNotesAgentRaw } from "../knowledge/agent_notes_agent.js";
const AGENT_NOTES_DIR = path.join(WorkDir, 'knowledge', 'Agent Notes');
const WORKDIR_CONFIG_FILE = path.join(WorkDir, 'config', 'workdir.json');
// Work directory is scoped per run (per chat). Each run gets its own sidecar
// config file so setting it in one chat does not leak into others.
function workDirConfigFile(runId: string): string {
return path.join(WorkDir, 'config', `workdir-${runId}.json`);
}
type ToolPermissionMetadataValue = z.infer<typeof ToolPermissionMetadata>;
@ -165,10 +170,11 @@ async function getToolPermissionMetadata(
};
}
function loadUserWorkDir(): string | null {
function loadUserWorkDir(runId: string): string | null {
try {
if (!fs.existsSync(WORKDIR_CONFIG_FILE)) return null;
const raw = fs.readFileSync(WORKDIR_CONFIG_FILE, 'utf-8');
const file = workDirConfigFile(runId);
if (!fs.existsSync(file)) return null;
const raw = fs.readFileSync(file, 'utf-8');
const parsed = JSON.parse(raw) as { path?: unknown };
const value = typeof parsed.path === 'string' ? parsed.path.trim() : '';
return value || null;
@ -1259,7 +1265,7 @@ export async function* streamAgent({
if (agentNotesContext) {
instructionsWithDateTime += `\n\n${agentNotesContext}`;
}
const userWorkDir = loadUserWorkDir();
const userWorkDir = loadUserWorkDir(runId);
if (userWorkDir) {
loopLogger.log('injecting user work directory', userWorkDir);
instructionsWithDateTime += `\n\n# User Work Directory