Skip to content

armgit / Orkas

Public Imported from GitHub
0

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.

fix(automation): reveal saved tasks without opening the editor

wyt948e32139d05
diff --git a/src/renderer/modules/auto.js b/src/renderer/modules/auto.js
index 7cf97566..6df24ada 100644
--- a/src/renderer/modules/auto.js
+++ b/src/renderer/modules/auto.js
@@ -143,6 +143,9 @@ let _autoLoadedOnce = false;
// Presentation-only: preserve the selected scope across list refreshes.
let _autoActiveScope = null;
const _autoExpandedRows = new Set();
+let _autoFocusGeneration = 0;
+let _autoHighlightedTaskId = '';
+let _autoHighlightTimer = null;
let _autoFormMounted = false; // _aiSelectMount only once
let _autoEditingTaskId = null; // null = create mode, taskId = edit mode
// Current persistent installation identity — fetched lazily on first row
@@ -984,7 +987,9 @@ function _autoRenderList() {
section.appendChild(empty);
}
for (const task of group.tasks) {
- cards.appendChild(_autoRenderRow(task, { onEdit, afterChange, expanded: _autoExpandedRows.has(task.id) }));
+ const row = _autoRenderRow(task, { onEdit, afterChange, expanded: _autoExpandedRows.has(task.id) });
+ if (task.id === _autoHighlightedTaskId) row.classList.add('is-highlighted');
+ cards.appendChild(row);
}
if (group.tasks.length) section.appendChild(cards);
listEl.appendChild(section);
@@ -2269,6 +2274,36 @@ if (typeof window !== 'undefined') {
window.refreshAutoProjectGroups = _autoRenderList;
window.loadProjectAutoList = loadProjectAutoList;
window.openAutoTaskDialog = openAutoTaskDialog;
+ // Saved-task shortcuts reveal the current list entry; editing is explicit.
+ window.focusAutoTaskById = async function focusAutoTaskById(taskId) {
+ const id = String(taskId || '').trim();
+ if (!id) return false;
+ const generation = ++_autoFocusGeneration;
+ const navigationEpoch = typeof _composerNavigationEpoch === 'number' ? _composerNavigationEpoch : null;
+ await loadAutoList(true);
+ // A newer shortcut or navigation consumed this action. Do not turn a safe
+ // no-op into app navigation's unavailable-target failure.
+ if (generation !== _autoFocusGeneration
+ || (navigationEpoch !== null && navigationEpoch !== _composerNavigationEpoch)) return true;
+ if (typeof currentView !== 'undefined' && currentView !== 'auto') return false;
+ const task = _autoTasks.find((candidate) => candidate && candidate.id === id);
+ if (!task) return false;
+ _autoActiveScope = task.project_id || '';
+ _autoHighlightedTaskId = id;
+ clearTimeout(_autoHighlightTimer);
+ _autoRenderList();
+ const list = document.getElementById('auto-list');
+ const row = Array.from(list?.querySelectorAll('.auto-row') || [])
+ .find((candidate) => candidate.dataset.taskId === id);
+ row?.scrollIntoView({ block: 'center' });
+ _autoHighlightTimer = setTimeout(() => {
+ _autoHighlightedTaskId = '';
+ _autoHighlightTimer = null;
+ document.getElementById('auto-list')?.querySelectorAll('.auto-row.is-highlighted')
+ .forEach((candidate) => candidate.classList.remove('is-highlighted'));
+ }, 2500);
+ return !!row;
+ };
window.openAutoTaskById = async function openAutoTaskById(taskId) {
const id = String(taskId || '').trim();
if (!id) return false;
diff --git a/src/renderer/modules/conversation.js b/src/renderer/modules/conversation.js
index aa7e4307..555ff2df 100644
--- a/src/renderer/modules/conversation.js
+++ b/src/renderer/modules/conversation.js
@@ -5435,7 +5435,10 @@ function _mountSavedTaskChips(msg, tasks) {
button.disabled = true;
try {
if (task.kind === 'automation') {
- await _APP_NAV_SURFACES.auto.open({ action: 'configure', target_id: task.task_id });
+ await _appNavOpenFeatureView('auto', 'auto', () => {
+ if (typeof window.focusAutoTaskById !== 'function') return false;
+ return window.focusAutoTaskById(task.task_id);
+ });
} else {
await _appNavLoadFeature('project', () => {
if (typeof focusTodo !== 'function') return false;
diff --git a/src/renderer/style.css b/src/renderer/style.css
index b4d34f94..6edd023b 100644
--- a/src/renderer/style.css
+++ b/src/renderer/style.css
@@ -1735,7 +1735,8 @@ html[dir="rtl"] .project-driver-toggle[aria-pressed="true"] .project-driver-swit
.project-todo-item:hover {
background: var(--surface-2);
}
-.todo-board .project-todo-item.is-highlighted {
+.todo-board .project-todo-item.is-highlighted,
+.auto-row.is-highlighted {
background: var(--primary-soft);
box-shadow: inset 0 0 0 1px var(--primary);
}
diff --git a/test/e2e/chat_e2e_saved_tasks.spec.ts b/test/e2e/chat_e2e_saved_tasks.spec.ts
index 11b8d48e..8a69e9b6 100644
--- a/test/e2e/chat_e2e_saved_tasks.spec.ts
+++ b/test/e2e/chat_e2e_saved_tasks.spec.ts
@@ -91,6 +91,28 @@ test('keeps saved automation and todo shortcuts usable live and after restart',
await page.evaluate(() => (window as any).setLang('en'));
await expect(page.locator('#chat-history [data-saved-task-key] .chat-msg-created-agent-label').first()).toContainText('Open');
await page.locator('#chat-history [data-saved-task-key]', { hasText: 'Nightly review' }).click();
+ const autoCard = () => page.locator(`#auto-list .auto-row[data-task-id="${automation.task_id}"]`);
+ const expectAutomationFocused = async () => {
+ await expect(autoCard()).toBeInViewport();
+ await expect(autoCard()).toHaveClass(/\bis-highlighted\b/);
+ await expect(page.locator('#auto-list .auto-row.is-highlighted')).toHaveCount(1);
+ await expect(page.locator('#auto-task-dialog-overlay')).toBeHidden();
+ await expect(page.locator(`#auto-list .todo-scope-chip[data-project-id="${project.project.project_id}"]`))
+ .toHaveAttribute('aria-pressed', 'true');
+ };
+ await expectAutomationFocused();
+ const autoHighlight = await autoCard().evaluate(element => {
+ const style = getComputedStyle(element);
+ return { background: style.backgroundColor, shadow: style.boxShadow };
+ });
+ await page.screenshot({ path: testInfo.outputPath('automation-shortcut-highlight-en.png') });
+ await expect(autoCard()).not.toHaveClass(/\bis-highlighted\b/);
+ await expect(autoCard()).not.toHaveCSS('background-color', autoHighlight.background);
+ await expect(autoCard()).not.toHaveCSS('box-shadow', autoHighlight.shadow);
+ // Editing remains an explicit action in the card's menu.
+ await autoCard().hover();
+ await autoCard().locator('.auto-row-more').click();
+ await page.locator('.auto-row-menu-item[data-action="edit"]').click();
await expect(page.locator('#auto-task-dialog-overlay')).toBeVisible();
await expect(page.locator('#auto-title-input')).toHaveValue('Nightly review');
await expect(page.locator(`#auto-list .todo-scope-chip[data-project-id="${project.project.project_id}"]`))
@@ -131,10 +153,9 @@ test('keeps saved automation and todo shortcuts usable live and after restart',
await page.screenshot({ path: testInfo.outputPath('todo-shortcut-highlight-zh-narrow.png') });
await page.evaluate((id) => (window as any).setView('conversation', id), cid);
await page.locator('#chat-history [data-saved-task-key]', { hasText: 'Nightly review' }).click();
- await expect(page.locator('#auto-task-dialog-overlay')).toBeVisible();
- await expect(page.locator(`#auto-list .todo-scope-chip[data-project-id="${project.project.project_id}"]`))
- .toHaveAttribute('aria-pressed', 'true');
- await page.locator('#auto-dialog-cancel-btn').click();
+ await expectAutomationFocused();
+ await expect(autoCard()).toHaveCSS('background-color', autoHighlight.background);
+ await page.screenshot({ path: testInfo.outputPath('automation-shortcut-highlight-zh-narrow.png') });
page = await app.relaunch();
const restored = await app.invoke<{
conversations: Array<{ conversation_id: string; project_id?: string }>;
@@ -146,7 +167,5 @@ test('keeps saved automation and todo shortcuts usable live and after restart',
await page.evaluate(id => (window as any).setView('conversation', id), cid);
await expect(page.locator('#chat-history [data-saved-task-key]')).toHaveCount(2);
await page.locator('#chat-history [data-saved-task-key]', { hasText: 'Nightly review' }).click();
- await expect(page.locator('#auto-title-input')).toHaveValue('Nightly review');
- await expect(page.locator(`#auto-list .todo-scope-chip[data-project-id="${project.project.project_id}"]`))
- .toHaveAttribute('aria-pressed', 'true');
+ await expectAutomationFocused();
});
diff --git a/test/renderer/auto-project-groups.test.ts b/test/renderer/auto-project-groups.test.ts
index 4024558f..16a90b01 100644
--- a/test/renderer/auto-project-groups.test.ts
+++ b/test/renderer/auto-project-groups.test.ts
@@ -1,4 +1,4 @@
-import { describe, expect, it } from 'vitest';
+import { afterEach, describe, expect, it, vi } from 'vitest';
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as vm from 'node:vm';
@@ -16,9 +16,10 @@ const { _autoGroupTasks: groupTasks } = require('../../src/renderer/modules/auto
function loadAutoTab(options: { projects: Project[] | null; view: string }) {
let scopes: any[] = [];
let selectedGroup: any = null;
+ const rows = () => selectedGroup?.children.find((child: any) => child.className === 'auto-scope-cards')?.children || [];
const list: any = {
clears: 0,
- querySelectorAll: () => [],
+ querySelectorAll: (selector: string) => rows().filter((row: any) => !selector.includes('.is-highlighted') || row.classList.contains('is-highlighted')),
appendChild(child: any) {
if (child.className.includes('auto-scope-switcher')) scopes = child.children;
if (child.className === 'auto-scope-group') selectedGroup = child;
@@ -43,6 +44,13 @@ function loadAutoTab(options: { projects: Project[] | null; view: string }) {
escapeHtml: (value: unknown) => String(value ?? ''),
uiAlert() {},
currentView: options.view,
+ renderTaskRow: (task: Task) => {
+ const classes = new Set<string>();
+ return { task, dataset: { taskId: task.id }, scrollIntoView: vi.fn(), classList: {
+ add: (name: string) => classes.add(name), remove: (name: string) => classes.delete(name),
+ contains: (name: string) => classes.has(name),
+ } };
+ },
_projectsCache: options.projects,
loadProjects: async (force?: boolean) => {
sidebarLoads.push(force);
@@ -77,10 +85,11 @@ function loadAutoTab(options: { projects: Project[] | null; view: string }) {
_refreshAutoSyncNotice = async () => {};
_autoLoadTaskConversationCounts = async () => {};
_closeAutoRowMenu = () => {};
- _autoRenderRow = (task) => ({ task });
+ _autoRenderRow = renderTaskRow;
`, context);
return {
context,
+ rows,
create: () => elements['auto-add-btn'].click(),
sidebarLoads,
scopeNames: () => scopes.map((scope) => /todo-scope-chip-name">([^<]*)</.exec(scope.innerHTML)?.[1] || ''),
@@ -91,7 +100,109 @@ function loadAutoTab(options: { projects: Project[] | null; view: string }) {
};
}
+function deferredList() {
+ let respond!: (value: { ok: boolean; tasks: Task[] }) => void;
+ let notify!: () => void;
+ const response = new Promise<{ ok: boolean; tasks: Task[] }>(resolve => { respond = resolve; });
+ const started = new Promise<void>(resolve => { notify = resolve; });
+ return { started, respond, invoke: () => { notify(); return response; } };
+}
+
describe('automation tab and the sidebar project cache', () => {
+ afterEach(() => vi.useRealTimers());
+
+ it('keeps the newer saved automation selected when the earlier lookup finishes last', async () => {
+ vi.useFakeTimers();
+ const tab = loadAutoTab({ projects: [{ project_id: 'a', name: 'Alpha' }], view: 'auto' });
+ await tab.context.loadAutoList(true);
+ const older = deferredList();
+ const newer = deferredList();
+ const requests = [older, newer];
+ tab.context.window.orkas.invoke = vi.fn(() => requests.shift()!.invoke());
+ const pendingOlder = tab.context.window.focusAutoTaskById('t1');
+ await older.started;
+ const pendingNewer = tab.context.window.focusAutoTaskById('t2');
+ await newer.started;
+ const snapshot = { ok: true, tasks: [{ id: 't1', project_id: 'a' }, { id: 't2' }] };
+ newer.respond(snapshot);
+ expect(await pendingNewer).toBe(true);
+ expect(tab.activeScope()).toBe('');
+ const highlighted = () => tab.rows().filter((row: any) => row.classList.contains('is-highlighted')).map((row: any) => row.task.id);
+ expect(highlighted()).toEqual(['t2']);
+ vi.advanceTimersByTime(1000);
+ older.respond(snapshot);
+ // The existing app-nav caller interprets false as an unavailable-target
+ // error. A superseded click is consumed without undoing the newer action.
+ expect(await pendingOlder).toBe(true);
+ expect(tab.activeScope()).toBe('');
+ expect(highlighted()).toEqual(['t2']);
+ vi.advanceTimersByTime(1500);
+ expect(highlighted()).toEqual([]);
+ });
+
+ it.each(['away', 'returned'] as const)('does not focus an old shortcut after navigation is %s', async state => {
+ vi.useFakeTimers();
+ const tab = loadAutoTab({ projects: [{ project_id: 'a', name: 'Alpha' }], view: 'auto' });
+ tab.context._composerNavigationEpoch = 10;
+ await tab.context.loadAutoList(true);
+ const request = deferredList();
+ tab.context.window.orkas.invoke = request.invoke;
+ const pending = tab.context.window.focusAutoTaskById('t1');
+ await request.started;
+ tab.context.currentView = 'project';
+ tab.context._composerNavigationEpoch++;
+ if (state === 'returned') {
+ tab.context.currentView = 'auto';
+ tab.context._composerNavigationEpoch++;
+ }
+ request.respond({ ok: true, tasks: [{ id: 't1', project_id: 'a' }, { id: 't2' }] });
+ expect(await pending).toBe(true);
+ expect(tab.context.currentView).toBe(state === 'returned' ? 'auto' : 'project');
+ expect(tab.activeScope()).toBe('');
+ expect(tab.rows().some((row: any) => row.classList.contains('is-highlighted'))).toBe(false);
+ });
+
+ it.each([
+ ['first visit', null, 't1', 'a'],
+ ['another project selected', [{ project_id: 'a', name: 'Alpha' }], 't2', ''],
+ ['global scope selected', [{ project_id: 'a', name: 'Alpha' }], 't1', 'a'],
+ ] as const)('reveals a saved automation without editing on %s and retains its cue across refresh', async (_name, projects, taskId, scope) => {
+ vi.useFakeTimers();
+ const tab = loadAutoTab({ projects: projects ? [...projects] : null, view: 'auto' });
+ tab.context.recordEditor = vi.fn();
+ vm.runInContext('openAutoTaskDialog = recordEditor', tab.context);
+ if (projects) {
+ await tab.context.loadAutoList(true);
+ tab.selectScope(scope ? '' : 'a');
+ }
+
+ expect(await tab.context.window.focusAutoTaskById(taskId)).toBe(true);
+ expect(tab.activeScope()).toBe(scope);
+ expect(tab.rows().filter((row: any) => row.classList.contains('is-highlighted')).map((row: any) => row.task.id)).toEqual([taskId]);
+ expect(tab.rows().find((row: any) => row.task.id === taskId).scrollIntoView).toHaveBeenCalledWith({ block: 'center' });
+ expect(tab.context.recordEditor).not.toHaveBeenCalled();
+ vi.advanceTimersByTime(2000);
+ await tab.context.loadAutoList(true);
+ const refreshed = tab.rows().find((row: any) => row.task.id === taskId);
+ expect(refreshed.classList.contains('is-highlighted')).toBe(true);
+ vi.advanceTimersByTime(500);
+ expect(refreshed.classList.contains('is-highlighted')).toBe(false);
+ });
+
+ it('follows the current assignment and safely handles a removed automation', async () => {
+ vi.useFakeTimers();
+ const tab = loadAutoTab({ projects: [{ project_id: 'a', name: 'Alpha' }, { project_id: 'b', name: 'Beta' }], view: 'auto' });
+ await tab.context.loadAutoList(true);
+ tab.context.window.orkas.invoke = async () => ({ ok: true, tasks: [{ id: 't1', project_id: 'b' }, { id: 't2' }] });
+ expect(await tab.context.window.focusAutoTaskById('t1')).toBe(true);
+ expect(tab.activeScope()).toBe('b');
+ expect(await tab.context.window.focusAutoTaskById('missing')).toBe(false);
+ expect(await tab.context.window.focusAutoTaskById('')).toBe(false);
+ expect(tab.activeScope()).toBe('b');
+ vi.advanceTimersByTime(2500);
+ expect(tab.rows().some((row: any) => row.classList.contains('is-highlighted'))).toBe(false);
+ });
+
it('initializes each new draft from the currently selected scope without locking its project', async () => {
const tab = loadAutoTab({ projects: [{ project_id: 'a', name: 'Alpha' }], view: 'auto' });
const opened: any[] = [];