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 unreadable project instructions being reported as empty
wyt836a86d01350
diff --git a/src/main/features/projects.ts b/src/main/features/projects.tsindex bc79fd11..0cf3f8e4 100644--- a/src/main/features/projects.ts+++ b/src/main/features/projects.ts@@ -483,13 +483,17 @@ export function formatProjectContextPolicyForSystemPrompt(): string {export async function readProjectInstructions(uid: string,projectId: string,-): Promise<{ ok: true; content: string; limit: number } | { ok: false; error: ProjectError }> {+): Promise<{ ok: true; content: string; limit: number } | { ok: false; error: ProjectError | 'read_failed' }> {const cur = await _readProject(uid, projectId);if (!cur) return { ok: false, error: 'not_found' };let content = '';try {content = await fsp.readFile(projectInstructionsFile(uid, projectId), 'utf8');- } catch { /* missing file = no instructions yet */ }+ } catch (error) {+ // Only an absent file means no instructions. Existing consumers keep an+ // unavailable source locked instead of enabling edits on a false empty.+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') return { ok: false, error: 'read_failed' };+ }return { ok: true, content, limit: PROJECT_INSTRUCTIONS_CHAR_LIMIT };}diff --git a/test/e2e/projects_e2e_smoke.spec.ts b/test/e2e/projects_e2e_smoke.spec.tsindex 0f3d0fb3..c629dd85 100644--- a/test/e2e/projects_e2e_smoke.spec.ts+++ b/test/e2e/projects_e2e_smoke.spec.ts@@ -1,4 +1,4 @@-import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs';+import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmdirSync, writeFileSync } from 'node:fs';import path from 'node:path';import { expect, test, type OrkasTestApp } from './fixtures/orkas';@@ -285,6 +285,46 @@ test.describe('projects', () => {await expect(memory).toHaveCount(0);});+ test('locks unreadable project instructions and restores the saved rules after recovery', async ({ orkas }) => {+ const name = 'E2E Instructions Read Recovery';+ const original = 'Keep the approved venue and do not contact vendors.';+ await createProject(orkas, name);+ const page = orkas.page!;+ const listed = await orkas.invoke<{ projects: Array<{ project_id: string; name: string }> }>('projects.list');+ const projectId = listed.projects.find(project => project.name === name)!.project_id;+ await orkas.invoke('projects.instructions.set', { projectId, content: original });+ await expect(page.locator('#project-instructions-read')).toHaveText(original);+ const file = readdirSync(orkas.workspaceRoot)+ .map(uid => path.join(orkas.workspaceRoot, uid, 'cloud', 'projects', projectId, 'ORKAS.md'))+ .find(candidate => existsSync(candidate))!;+ expect(file).toBeTruthy();+ const preserved = file + '.preserved';+ // A directory at the file path triggers a real read failure without+ // relying on permission bits that elevated users or Windows may ignore.+ renameSync(file, preserved);+ mkdirSync(file);+ try {+ await page.evaluate(pid => (window as any).loadProjectDetail(pid), projectId);+ await expect(page.locator('#project-instructions-input')).toBeDisabled();+ await expect(page.locator('#project-instructions-edit-btn')).toBeDisabled();+ await expect(page.locator('#project-instructions-setup-btn')).toBeDisabled();+ await expect(page.locator('#project-instructions-save-btn')).toBeDisabled();+ await expect(page.locator('#project-instructions-modal')).not.toHaveClass(/open/);+ expect(readFileSync(preserved, 'utf8')).toBe(original);+ } finally {+ rmdirSync(file);+ renameSync(preserved, file);+ }+ await page.evaluate(pid => (window as any).loadProjectDetail(pid), projectId);+ await expect(page.locator('#project-instructions-read')).toHaveText(original);+ await page.locator('#project-instructions-edit-btn').click();+ await expect(page.locator('#project-instructions-input')).toHaveValue(original);+ await page.locator('#project-instructions-input').fill('Unsaved recovery draft.');+ await page.locator('#project-instructions-cancel-btn').click();+ expect(await orkas.invoke('projects.instructions.get', { projectId })).toMatchObject({ content: original });+ await expect(page.locator('#project-instructions-read')).toHaveText(original);+ });+test('uploads, previews, persists, and deletes a project Library file', async ({ orkas }) => {const projectName = 'E2E Project Library';const fileName = 'E2E project source.md';diff --git a/test/main/features/projects.test.ts b/test/main/features/projects.test.tsindex 096884c8..c1cad0c3 100644--- a/test/main/features/projects.test.ts+++ b/test/main/features/projects.test.ts@@ -724,6 +724,28 @@ describe('projects › instructions', () => {expect(read.limit).toBe(projects.PROJECT_INSTRUCTIONS_CHAR_LIMIT);});+ it.each(['EACCES', 'EIO'])('keeps unreadable instructions unavailable and recovers without losing saved rules (%s)', async code => {+ const projects = await loadProjects();+ const paths = await import('../../../src/main/paths');+ const created = await projects.createProject(TEST_UID, 'Instructions read recovery');+ if (!created.ok) throw new Error('Project fixture failed');+ const pid = created.project.project_id;+ const original = 'Keep the approved venue and do not contact vendors.';+ await projects.writeProjectInstructions(TEST_UID, pid, original);+ const file = paths.projectInstructionsFile(TEST_UID, pid);+ const read = fs.promises.readFile.bind(fs.promises);+ const spy = vi.spyOn(fs.promises, 'readFile').mockImplementation((...args: any[]) => {+ if (args[0] === file) return Promise.reject(Object.assign(new Error('Private instructions read failure'), { code }));+ return (read as any)(...args);+ });+ syncBuiltinESMExports();+ try {+ expect(await projects.readProjectInstructions(TEST_UID, pid)).toEqual({ ok: false, error: 'read_failed' });+ expect(fs.readFileSync(file, 'utf8')).toBe(original);+ } finally { spy.mockRestore(); syncBuiltinESMExports(); }+ expect(await projects.readProjectInstructions(TEST_UID, pid)).toMatchObject({ ok: true, content: original });+ });+it('write → persists ORKAS.md in the project dir; read round-trips; empty write clears', async () => {const projects = await loadProjects();const r = await projects.createProject(TEST_UID, 'P');