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
Polish conv-workspace side effects: CLI session resume / empty conv-dir / lazy mkdir
claw2ddb34e63bd38
diff --git a/src/main/features/group_chat/bus.ts b/src/main/features/group_chat/bus.tsindex 34a79e27..52789bbb 100644--- a/src/main/features/group_chat/bus.ts+++ b/src/main/features/group_chat/bus.ts@@ -838,11 +838,22 @@ async function runTurn(state: CidState, w: WorkerState, item: QueueItem): Promis// and forward its events as `process` events so the same UI rail// renders. The output text becomes finalText; failures populate// errText so the existing post-stream logic surfaces a ⚠️ bubble.+ //+ // **CLI cwd = root workspace** (NOT the per-conv subdir used by the+ // in-process branch). CLI session stores are cwd-hashed —+ // `claude code` keeps sessions under `~/.claude/projects/<encoded-cwd>/`+ // — so changing cwd between dispatches breaks `--resume <id>` with+ // "No conversation found with session ID …". The per-conv subdir+ // exists to group repeat-run artefacts from the in-process LLM's+ // `write_file` tool; CLI agents have their own product-side+ // conventions and don't need that scoping. Override here:+ const userWorkspace = await import('../user_workspace');+ const cliWorkingDir = userWorkspace.getWorkspacePath(uid);try {const slice = await readSlice(uid, cid, actor.id);const cliOut = await _runCliAgentTurn({uid, cid, actor, agent: cliAgent,- item, slice, workingDir,+ item, slice, workingDir: cliWorkingDir,signal: w.abortController.signal,onProcess: data => {// Mirror the LLM path: count every event for activity, but@@ -1759,6 +1770,18 @@ async function _runCliAgentTurn(opts: {let resultText = '';let aborted = false;let backendSessionId: string | undefined;+ // Set when the CLI rejects our `--resume <id>` (e.g. claude code's+ // "No conversation found with session ID …"). Triggers a one-time+ // cleanup of the cliSessions binding so the next dispatch starts+ // fresh instead of replaying the same broken resume forever. Detect+ // by stderr-line pattern because there is no structured signal —+ // each CLI phrases it slightly differently but they all carry the+ // session-id hex.+ let resumeRejected = false;+ const _RESUME_REJECTED_PATTERNS = [+ /No conversation found with session ID/i,+ /session.*(not found|does not exist|expired|invalid)/i,+ ];const result = await runner.run({uid: opts.uid,@@ -1793,7 +1816,13 @@ async function _runCliAgentTurn(opts: {case 'tool-event':case 'process-info':case 'status':+ opts.onProcess({ type: 'event', event: { stream: 'cli', data: e as unknown as Record<string, unknown> } });+ break;case 'stderr-line':+ if (resumeSessionId && typeof (e as any).line === 'string') {+ const line = (e as any).line as string;+ if (_RESUME_REJECTED_PATTERNS.some((re) => re.test(line))) resumeRejected = true;+ }opts.onProcess({ type: 'event', event: { stream: 'cli', data: e as unknown as Record<string, unknown> } });break;case 'done':@@ -1807,6 +1836,18 @@ async function _runCliAgentTurn(opts: {},});+ // Drop the stale resume binding before returning so a user-initiated+ // retry starts a fresh CLI session instead of looping on the same+ // expired id. Done unconditionally on rejection — even if the CLI+ // somehow finished successfully, the resume id we sent is gone, and+ // the binding is at best useless / at worst will fail again.+ if (resumeRejected) {+ log.warn(`cli session expired cid=${opts.cid} agent=${opts.agent.agent_id} cli=${runtime.cli} — clearing resume binding`);+ cliSessions+ .clearForAgent(opts.uid, opts.cid, opts.agent.agent_id)+ .catch(() => { /* logged inside sessions.ts */ });+ }+if (result.status === 'missing_cli') {const msg = t('cli_agent.missing', { name: opts.agent.name || runtime.cli, cli: runtime.cli });return { text: '', error: msg, aborted: false };@@ -1816,7 +1857,10 @@ async function _runCliAgentTurn(opts: {}if (result.status === 'failed' || result.status === 'timeout') {const detail = result.error || (result.status === 'timeout' ? 'timeout' : 'failed');- return { text: resultText || accText, error: detail };+ // When the failure was a stale resume id, hint the user that a+ // simple resend will recover (the binding has been cleared above).+ const hint = resumeRejected ? ' — session expired; retry will start fresh.' : '';+ return { text: resultText || accText, error: detail + hint };}// Successful turn — persist the (possibly new) session id so the// next dispatch can resume. Claude reports its session id everydiff --git a/src/main/features/group_chat/conv_workspace.ts b/src/main/features/group_chat/conv_workspace.tsindex 9a3d2782..44363a32 100644--- a/src/main/features/group_chat/conv_workspace.ts+++ b/src/main/features/group_chat/conv_workspace.ts@@ -31,7 +31,6 @@*/import * as fs from 'node:fs';-import * as fsp from 'node:fs/promises';import * as path from 'node:path';import { getWorkspacePath } from '../user_workspace';@@ -137,14 +136,21 @@ function uniquifySlug(workspaceRoot: string, slug: string): string {/*** Resolve the absolute working directory for `(uid, cid)`. Lazy + frozen:* - if `state.json::workspace_dir` is already set → return `<workspace>/<dir>`- * (mkdir if the dir got deleted in the meantime; hot path is the existence-- * check fast path)* - else if the conv has no entry yet (genuinely a legacy conv without a* conversation record, or `state.json` not yet written) → return the* user-level workspace verbatim, do NOT persist anything (legacy behaviour)* - else → derive slug from current title, fall back to date-based name on- * placeholder, uniquify against sibling dirs, mkdir, persist to+ * placeholder, uniquify against sibling dirs, persist the slug choice to* `state.json::workspace_dir`, return the absolute path+ *+ * **Does NOT mkdir** — the directory is materialised lazily by the producing+ * tool (write_file mkdirs parent before write; markdown_to_pdf / image gen+ * follow the same pattern). For tools that need cwd-as-existing-directory+ * (bash via child_process.spawn), the wrapped `bash` tool mkdirs `cwd`+ * defensively before delegating. Skipping the eager mkdir here means a+ * commander turn that only chats (no file output, no bash) leaves zero+ * footprint on disk — which is what users expect when the conversation+ * never produced anything.*/export async function getConversationWorkspacePath(uid: string, cid: string): Promise<string> {const root = getWorkspacePath(uid);@@ -152,9 +158,7 @@ export async function getConversationWorkspacePath(uid: string, cid: string): Pr// Fast path: state already has a workspace_dir baked in.const cur = await readState(uid, cid);if (cur.workspace_dir) {- const abs = path.join(root, cur.workspace_dir);- try { await fsp.mkdir(abs, { recursive: true }); } catch { /* race with self / fs hiccup */ }- return abs;+ return path.join(root, cur.workspace_dir);}// No workspace_dir yet. Decide one.@@ -180,18 +184,11 @@ export async function getConversationWorkspacePath(uid: string, cid: string): Prif (!slug) slug = pickFallbackSlug(root);else slug = uniquifySlug(root, slug);- const abs = path.join(root, slug);- try { await fsp.mkdir(abs, { recursive: true }); }- catch (err) {- log.warn(`mkdir ${abs} failed: ${(err as Error).message} — falling back to root`);- return root;- }-// Persist the choice. setWorkspaceDirOnce is idempotent: if a concurrent- // call beat us to it, our slug is dropped and we re-read the winner —- // mkdir is forgiving about the duplicate dir.+ // call beat us to it, our slug is dropped and we re-read the winner. The+ // directory is NOT created here — see the function-level comment above.const persisted = await setWorkspaceDirOnce(uid, cid, slug);const finalSlug = persisted.workspace_dir || slug;- log.info(`cid=${cid} workspace_dir=${finalSlug} (title="${title}")`);+ log.info(`cid=${cid} workspace_dir=${finalSlug} (title="${title}", lazy-mkdir)`);return path.join(root, finalSlug);}diff --git a/src/main/model/core-agent/local-tools.ts b/src/main/model/core-agent/local-tools.tsindex 0a592ae1..bbd656e9 100644--- a/src/main/model/core-agent/local-tools.ts+++ b/src/main/model/core-agent/local-tools.ts@@ -166,6 +166,18 @@ 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 */ }+ }return coreBashTool.execute(input, ctx);},};