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
Update saved app context with the committed revision
wytb0d2b7f031b2
diff --git a/src/main/features/saved_apps.ts b/src/main/features/saved_apps.tsindex c5adbe59..704edf9f 100644--- a/src/main/features/saved_apps.ts+++ b/src/main/features/saved_apps.ts@@ -1131,7 +1131,7 @@ function refreshEditSnapshot(uid: string,cid: string,context: EditContext,sourceif(fs.existsSync(snapshot))fs.renameSync(snapshot,previous);try {fs.renameSync(next,snapshot);} catch(error) {if(fs.existsSync(previous))fs.renameSync(previous,snapshot);throw error;}context.fingerprint=fingerprintApp(source);- fs.writeFileSync(path.join(root,'context.json'),JSON.stringify(context));+ writeTextAtomicSync(path.join(root,'context.json'),JSON.stringify(context));fs.rmSync(previous,{recursive:true,force:true});}diff --git a/test/main/features/saved_apps.test.ts b/test/main/features/saved_apps.test.tsindex c9b25a92..2665b1d1 100644--- a/test/main/features/saved_apps.test.ts+++ b/test/main/features/saved_apps.test.ts@@ -67,6 +67,62 @@ async function makeArtifact(title: string, extra: Array<{ path: string; content:}describe('saved_apps › saveFromArtifact', () => {+ it('preserves the editing destination after a short context refresh write and recovers the next update', async () => {+ const { savedApps, chatArtifacts } = await mods();+ const saved = await savedApps.saveFromArtifact(UID, CID, await makeArtifact('Original'));+ if (!saved.ok) throw new Error(saved.error);+ const edit = await savedApps.openForEditing(UID, saved.id);+ if (!edit.ok) throw new Error(edit.error);+ const cid = (edit.conversation as any).conversation_id;+ const root = path.join(tmpDir, UID, 'local/app-edits', cid);+ const contextFile = path.join(root, 'context.json');+ const before = fs.readFileSync(contextFile, 'utf8');+ const revision = await chatArtifacts.createArtifact(UID, cid, 'helper', {+ files: [{ path: 'index.html', content: '<h1>Committed revision</h1>' }],+ });+ if (!revision.ok) throw new Error(revision.error);+ const nodeFs = (await import('node:fs')).default;+ const { syncBuiltinESMExports } = await import('node:module');+ const originalWrite = nodeFs.writeFileSync;+ const canonicalRoot = fs.realpathSync(root);+ let injected = 0;+ const spy = vi.spyOn(nodeFs, 'writeFileSync').mockImplementation(((file: any, data: any, options?: any) => {+ if (typeof file === 'string' && fs.realpathSync(path.dirname(file)) === canonicalRoot+ && path.basename(file).startsWith('context.json')) {+ injected++;+ originalWrite(file, String(data).slice(0, 5), options);+ throw Object.assign(new Error('synthetic context disk full'), { code: 'ENOSPC' });+ }+ return originalWrite(file, data, options);+ }) as any);+ syncBuiltinESMExports();+ try {+ expect(await savedApps.saveFromArtifact(UID, cid, revision.artifactId, 'update'))+ .toMatchObject({ ok: true, id: saved.id });+ } finally { spy.mockRestore(); syncBuiltinESMExports(); }+ expect(injected).toBe(1);+ expect.soft(fs.readFileSync(contextFile, 'utf8')).toBe(before);+ await expect.soft(savedApps.getEditTarget(UID, cid)).resolves.toMatchObject({ appId: saved.id });+ const entry = path.join(APPS_ROOT(), saved.id, 'index.html');+ expect(fs.readFileSync(entry, 'utf8')).toContain('Committed revision');+ expect(fs.existsSync(path.join(root, 'save-journal.json'))).toBe(true);++ // Reopening the list performs the normal journal recovery, without replaying the save.+ expect(savedApps.listSavedApps(UID).map(app => app.id)).toEqual([saved.id]);+ await expect.soft(savedApps.getEditTarget(UID, cid)).resolves.toMatchObject({ appId: saved.id });+ expect(fs.existsSync(path.join(root, 'save-journal.json'))).toBe(false);+ const next = await chatArtifacts.createArtifact(UID, cid, 'helper', {+ files: [{ path: 'index.html', content: '<h1>Next revision</h1>' }],+ });+ if (!next.ok) throw new Error(next.error);+ expect(await savedApps.saveFromArtifact(UID, cid, next.artifactId, 'update'))+ .toMatchObject({ ok: true, id: saved.id });+ expect(savedApps.listSavedApps(UID).map(app => app.id)).toEqual([saved.id]);+ expect(savedApps.resolveSavedAppIndex(UID, saved.id)).toMatchObject({ ok: true });+ expect(fs.readFileSync(entry, 'utf8')).toContain('Next revision');+ expect(fs.readdirSync(APPS_ROOT())).toEqual([saved.id]);+ });+it.each(['update', 'export'] as const)('preserves committed %s results and releases the data lease when backup cleanup fails', async mode => {const logging = await import('../../../src/main/logger');const createLogger = logging.createLogger;