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
fix(library): keep editor paths current after rename and move
BlueSkyID666edf8b5c9847a
diff --git a/src/renderer/modules/contexts.js b/src/renderer/modules/contexts.jsindex b2da2a24..69c5c439 100644--- a/src/renderer/modules/contexts.js+++ b/src/renderer/modules/contexts.js@@ -1182,20 +1182,7 @@ async function _commitInlineRename(rel, nextBase) {}trackResult('success');try {- if (_ctxActive && _ctxActive.id === rel) _ctxActive.id = dst;- // Re-key any drafts (file rename: one entry; dir rename: every entry- // under the old prefix) so the draft survives the rename. Iterate a- // snapshot since we're mutating the map.- for (const [key, val] of Array.from(_ctxDrafts.entries())) {- if (key === rel) {- _ctxDrafts.set(dst, val);- _ctxDrafts.delete(rel);- } else if (key.startsWith(rel + '/')) {- _ctxDrafts.set(dst + key.slice(rel.length), val);- _ctxDrafts.delete(key);- }- }- _retargetCtxViewerAfterRename(rel, dst);+ _applyCtxPathChange(rel, dst);await loadContexts();} catch (err) {_contextsLog.warn('refresh after library entry rename failed', err);@@ -1926,7 +1913,11 @@ function _ctxClearDraft(path) {function _showCtxTextViewer(rel, content) {const els = _prepCtxViewerShell(rel);if (!els) return;- _ctxMveController = mountMdViewEdit({+ const drafts = _ctxDrafts;+ // Capture this mount, so late callbacks never read a later file's source.+ let controller = null;+ const currentRel = () => controller?.getSource?.()?.rel || rel;+ controller = mountMdViewEdit({bodyEl: els.bodyEl,actionsEl: els.actionsEl,source: { kind: 'context', rel },@@ -1934,19 +1925,20 @@ function _showCtxTextViewer(rel, content) {initialContent: content,// Restore in-progress edits if the user was previously typing in this// file. mountMdViewEdit forces edit mode when `initialDraft` is present.- initialDraft: _ctxDrafts.get(rel) || null,+ initialDraft: drafts.get(rel) || null,callbacks: {// Mirror draft state into the per-file Map so it survives switching// to another file in the tree and back.onDraftChange: (draft) => {- if (draft === null) _ctxDrafts.delete(rel);- else _ctxDrafts.set(rel, draft);+ if (draft === null) drafts.delete(currentRel());+ else drafts.set(currentRel(), draft);},- onReveal: () => revealCtxFile(rel),+ onReveal: () => revealCtxFile(currentRel()),onDelete: () => _deleteCtxFromViewer(),onSaved: async () => { await loadContexts(); },},});+ _ctxMveController = controller;els.bodyEl.scrollTop = 0;}diff --git a/test/renderer/contexts-external-drop.test.ts b/test/renderer/contexts-external-drop.test.tsindex 7163dfc2..06f04fb9 100644--- a/test/renderer/contexts-external-drop.test.ts+++ b/test/renderer/contexts-external-drop.test.ts@@ -104,6 +104,47 @@ function dropEvent(dataTransfer: any, closestEntry: any = null) {}describe('Library external file drag-and-drop', () => {+ it.each(['rename-file', 'rename-dir', 'move'])(+ 'keeps save, draft and reveal paths current after %s', async (action) => {+ const context = loadContextsScript();+ vm.runInContext(fs.readFileSync(path.join(__dirname, '../../src/renderer/modules/md-view-edit.js'), 'utf8'), context);+ vm.runInContext('_ctxActive = { id: "notes/draft.md" };', context);+ context._prepCtxViewerShell = () => ({ bodyEl: {}, actionsEl: {} });+ context.loadContexts = vi.fn();+ context.revealCtxFile = vi.fn();+ context.apiFetch = vi.fn(async () => ({ json: async () => ({ ok: true }) }));+ context.window.orkas = { invoke: vi.fn(async () => ({ ok: true })) };+ // Only the editor DOM is replaced. Save uses its real source dispatcher.+ let controller: any;+ let callbacks: any;+ context.mountMdViewEdit = (options: any) => {+ let source = options.source;+ callbacks = options.callbacks;+ controller = {+ getSource: () => source,+ setSource: (next: any) => { source = next; },+ save: (content: string) => context._mveWriteSource(source, content),+ };+ return controller;+ };+ context._showCtxTextViewer('notes/draft.md', 'Original');+ callbacks.onDraftChange({ content: 'Before rename', dirty: true });+ const next = action === 'rename-file' ? 'notes/final.md'+ : action === 'rename-dir' ? 'archive/draft.md' : 'archive/notes/draft.md';+ if (action === 'move') context._applyCtxPathChange('notes', 'archive/notes', 'archive');+ else await context._commitInlineRename(action === 'rename-dir' ? 'notes' : 'notes/draft.md', action === 'rename-dir' ? 'archive' : 'final.md');+ expect(vm.runInContext('_ctxActive.id', context)).toBe(next);+ callbacks.onDraftChange({ content: 'After rename', dirty: false });+ expect([...vm.runInContext('_ctxDrafts.entries()', context)]).toEqual([[next, { content: 'After rename', dirty: false }]]);+ callbacks.onReveal();+ expect(context.revealCtxFile).toHaveBeenCalledWith(next);+ expect(await controller.save('After rename')).toEqual({ ok: true });+ expect(context.apiFetch).toHaveBeenCalledWith('/api/contexts/update', expect.objectContaining({ body: JSON.stringify({ path: next, content: 'After rename' }) }));+ callbacks.onDraftChange(null);+ expect(vm.runInContext('_ctxDrafts.size', context)).toBe(0);+ },+ );+it('accepts the successful KB status snapshot returned by the IPC handler', () => {const context = loadContextsScript();