Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
Cure empty conv-slug dirs left by bash tool runs (cold-prune + boot sweep)
wyt9ab8325f5e3b
diff --git a/src/main/features/user_workspace.ts b/src/main/features/user_workspace.tsindex 2e459f1f..5579c729 100644--- a/src/main/features/user_workspace.ts+++ b/src/main/features/user_workspace.ts@@ -204,6 +204,38 @@ export async function selectDirectory(): Promise<string | null> {return result.filePaths[0];}+/**+ * Sweep the active workspace root, removing any empty top-level+ * subdirectory. Existing empty per-conversation slug dirs (legacy from+ * before bash's cold-path rmdir-if-empty was added in `local-tools.ts`,+ * or any future tool that mkdir'd then produced nothing) get cleaned up+ * on every boot. Best-effort: any rmdir failure (non-empty / EACCES /+ * concurrent in-flight bash) is silently swallowed.+ *+ * Only the immediate top level of the workspace is scanned; deeper+ * empty subdirs are the user's own scaffolding and out of scope.+ */+export function sweepEmptyConvDirs(userId: string): { swept: number } {+ const root = getWorkspacePath(userId);+ let swept = 0;+ let entries: string[];+ try { entries = fs.readdirSync(root); }+ catch { return { swept: 0 }; }+ for (const name of entries) {+ if (name.startsWith('.')) continue; // .DS_Store, .git, etc.+ const sub = path.join(root, name);+ try {+ const st = fs.statSync(sub);+ if (!st.isDirectory()) continue;+ if (fs.readdirSync(sub).length !== 0) continue;+ fs.rmdirSync(sub);+ swept++;+ } catch { /* best-effort */ }+ }+ if (swept > 0) log.info('swept empty workspace subdirs', { userId, swept, root });+ return { swept };+}+/*** Reveal a user's current workspace directory in the OS file manager* (Finder / Explorer / Nautilus). Falls back to the default directory if thediff --git a/src/main/index.ts b/src/main/index.tsindex 35237cd3..f16ccf4d 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -298,6 +298,18 @@ async function runBootSelfCheck(): Promise<void> {if (deleted) log.info('file_cache pruned', { deleted });}} catch (err) { log.warn('file_cache sweep failed', { error: (err as Error).message }); }++ // Stage 5: workspace empty-subdir sweep — clean up legacy per-conv slug+ // dirs that were materialised by bash's defensive mkdir on a turn that+ // produced nothing. Boot-time is the safe moment: no in-flight bash+ // process is holding cwd open. Top-level scan only.+ try {+ const uid = users.getActiveUserId();+ if (uid) {+ const userWs = await import('./features/user_workspace');+ userWs.sweepEmptyConvDirs(uid);+ }+ } catch (err) { log.warn('workspace empty-dir sweep failed', { error: (err as Error).message }); }}// `kb-file://<relpath>` — maps a KB-relative path to the active user'sdiff --git a/src/main/model/core-agent/local-tools.ts b/src/main/model/core-agent/local-tools.tsindex bbd656e9..67815a49 100644--- a/src/main/model/core-agent/local-tools.ts+++ b/src/main/model/core-agent/local-tools.ts@@ -166,19 +166,41 @@ function createBashTool(): AgentTool {inputSchema: coreBashTool.inputSchema,async execute(input, ctx) {if (!getLocalExecGranted()) return deniedResult();- // Defensive mkdir on cwd before delegating: `conv_workspace.ts`- // intentionally defers materialising the per-conversation workspace- // dir until something actually needs it on disk (so empty-output- // conversations don't litter the user's workspace with empty- // subdirs). `child_process.spawn` fails ENOENT if cwd doesn't- // exist, so this is the natural materialisation point — mkdir- // -p the cwd, then run the command. Failures here fall through;- // spawn will surface a clearer error if it really can't proceed.- if (ctx.workingDir) {- try { fs.mkdirSync(ctx.workingDir, { recursive: true }); }- catch { /* let spawn produce the canonical error */ }+ // `conv_workspace.ts` intentionally defers materialising the+ // per-conversation workspace dir; bash is a frequent first toucher+ // because `child_process.spawn` fails ENOENT if cwd doesn't exist.+ // Two distinct paths so the rmdir-if-empty cleanup only runs on+ // the cold path (this call is the FIRST to need the dir):+ //+ // hot path — `ctx.workingDir` already exists (a prior write_file+ // or earlier bash call materialised it). Skip mkdir,+ // skip post-check, just delegate. This is every bash+ // call from the second one onward in a productive+ // conversation, and stays zero-overhead.+ //+ // cold path — `ctx.workingDir` doesn't exist yet. We create it,+ // run bash, then if the command produced nothing+ // (`ls` / `cat` / `pwd` / `gh search` / pure python+ // heredoc returning via stdout) the dir is rmdir'd+ // so a read-only conversation leaves no footprint.+ // Best-effort cleanup: any rmdir failure (concurrent+ // bash on same cwd, ENOTEMPTY, EACCES) is silently+ // swallowed.+ if (!ctx.workingDir) return coreBashTool.execute(input, ctx);+ if (fs.existsSync(ctx.workingDir)) {+ return coreBashTool.execute(input, ctx);+ }+ try { fs.mkdirSync(ctx.workingDir, { recursive: true }); }+ catch { /* let spawn produce the canonical error */ }+ try {+ return await coreBashTool.execute(input, ctx);+ } finally {+ try {+ if (fs.readdirSync(ctx.workingDir).length === 0) {+ fs.rmdirSync(ctx.workingDir);+ }+ } catch { /* best-effort */ }}- return coreBashTool.execute(input, ctx);},};}