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(agents): propagate name change into existing conversation rosters
aiservice8f8c60d70937
diff --git a/src/main/features/agents.ts b/src/main/features/agents.tsindex acd7f136..a73fcbae 100644--- a/src/main/features/agents.ts+++ b/src/main/features/agents.ts@@ -43,6 +43,7 @@ import {} from '../storage';import { listSkillSpecs } from '../model/core-agent/skill-registry';import { readDisabledSets, setAgentEnabled } from './component_enabled';+import { renameAgentInMembers } from './group_chat/state';import * as search from './search';export type AgentSource = 'builtin' | 'custom';@@ -691,6 +692,7 @@ export async function updateCustomAgent(const f = customAgentFile(agentId);if (!fs.existsSync(f)) return null;const data = await readJson<AgentRaw>(f);+ const oldName = typeof (data as any).name === 'string' ? (data as any).name : '';if (Object.prototype.hasOwnProperty.call(updates || {}, 'name')) {assertAgentNameAllowed(typeof updates.name === 'string' ? updates.name : '');}@@ -831,6 +833,15 @@ export async function updateCustomAgent(await writeJson(f, data);_invalidateAgentListCache();log.info(`updated id=${agentId}`);+ // Propagate a name change into every conversation roster that already+ // lists this agent. members.json snapshots the name at join time and the+ // @-router resolves on roster-first, so without this sweep `@<old-name>`+ // would keep matching in old chats.+ const newName = typeof (data as any).name === 'string' ? (data as any).name : '';+ if (newName && newName !== oldName) {+ try { await renameAgentInMembers(getActiveUserId(), agentId, newName); }+ catch (err) { log.warn(`rename roster sweep failed id=${agentId}: ${(err as Error).message}`); }+ }return normalizeAgent(data, 'custom');}diff --git a/src/main/features/group_chat/state.ts b/src/main/features/group_chat/state.tsindex 95c557d4..f3b804bc 100644--- a/src/main/features/group_chat/state.ts+++ b/src/main/features/group_chat/state.ts@@ -23,7 +23,7 @@ import * as path from 'node:path';import { Mutex } from 'async-mutex';import {- groupChatDir, groupChatMembersFile, groupChatStateFile,+ groupChatDir, groupChatMembersFile, groupChatStateFile, userChatsDir,} from '../../paths';import { nowIso, readJson, writeJson, safeId } from '../../storage';import { createLogger } from '../../logger';@@ -145,6 +145,50 @@ export async function ensureAgentMember(return addMember(uid, cid, { kind: 'agent', id: agentId, ...(name ? { name } : {}) });}+/** Sync an agent's display name into every conversation roster that already+ * has it as a member. Called by `agents.updateCustomAgent` when the name+ * changes — without it, the @-router's roster-first lookup keeps resolving+ * on the snapshot copied at member-join time, so old conversations would+ * still respond to `@<old-name>`. Returns the number of rosters touched. */+export async function renameAgentInMembers(+ uid: string, agentId: string, newName: string,+): Promise<number> {+ if (!uid || !safeId(agentId) || RESERVED_IDS.has(agentId) || !newName) return 0;+ const indexFile = path.join(userChatsDir(uid), '_index.json');+ if (!fs.existsSync(indexFile)) return 0;+ let cids: string[] = [];+ try {+ const data: any = await readJson(indexFile);+ const items: any[] = Array.isArray(data) ? data+ : (data && Array.isArray(data.items) ? data.items : []);+ cids = items+ .map((c) => c && typeof c.conversation_id === 'string' ? c.conversation_id : '')+ .filter((s) => s && safeId(s));+ } catch (err) {+ log.warn(`read conv index failed user=${uid}: ${(err as Error).message}`);+ return 0;+ }+ let touched = 0;+ for (const cid of cids) {+ const file = groupChatMembersFile(uid, cid);+ if (!fs.existsSync(file)) continue;+ let m: MembersFile;+ try { m = await readMembers(uid, cid); }+ catch { continue; }+ const actor = m.actors.find((a) => a.id === agentId);+ if (!actor || actor.name === newName) continue;+ actor.name = newName;+ try {+ await writeMembers(uid, cid, m);+ touched += 1;+ } catch (err) {+ log.warn(`write members failed user=${uid} cid=${cid}: ${(err as Error).message}`);+ }+ }+ if (touched > 0) log.info(`renamed agent=${agentId} → "${newName}" in ${touched} conv(s) user=${uid}`);+ return touched;+}+// ── State IO ─────────────────────────────────────────────────────────────export async function readState(uid: string, cid: string): Promise<StateFile> {diff --git a/test/main/features/group_chat/state.test.ts b/test/main/features/group_chat/state.test.tsindex 53a453e0..8fc9b4b6 100644--- a/test/main/features/group_chat/state.test.ts+++ b/test/main/features/group_chat/state.test.ts@@ -67,6 +67,73 @@ describe('group_chat state › addMember + ensureAgentMember', () => {});});+describe('group_chat state › renameAgentInMembers', () => {+ // Drive the rename sweep through a seeded `_index.json` + a couple of+ // pre-populated members.json files. The bug this guards: members.name is a+ // join-time snapshot the @-router resolves on first, so without the sweep+ // old conversations would keep matching `@<old-name>` after a rename.+ async function seedConv(uid: string, cid: string, actors: any[]): Promise<void> {+ const paths = await import('../../../../src/main/paths');+ const dir = path.join(paths.userChatsDir(uid), cid);+ fs.mkdirSync(dir, { recursive: true });+ fs.writeFileSync(path.join(dir, 'members.json'), JSON.stringify({ version: 1, actors }));+ }+ async function seedIndex(uid: string, cids: string[]): Promise<void> {+ const paths = await import('../../../../src/main/paths');+ const dir = paths.userChatsDir(uid);+ fs.mkdirSync(dir, { recursive: true });+ fs.writeFileSync(+ path.join(dir, '_index.json'),+ JSON.stringify({ items: cids.map((c) => ({ conversation_id: c })) }),+ );+ }++ it('updates the name on every roster carrying the agent and skips others', async () => {+ const s = await import('../../../../src/main/features/group_chat/state');+ await seedConv(TEST_UID, 'cidA', [+ { kind: 'agent', id: 'writer', name: 'OldWriter', joined_at: 't' },+ { kind: 'commander', id: 'commander', name: 'Commander', joined_at: 't' },+ ]);+ await seedConv(TEST_UID, 'cidB', [+ { kind: 'agent', id: 'reviewer', name: 'Reviewer', joined_at: 't' },+ ]);+ await seedConv(TEST_UID, 'cidC', [+ { kind: 'agent', id: 'writer', name: 'OldWriter', joined_at: 't' },+ ]);+ await seedIndex(TEST_UID, ['cidA', 'cidB', 'cidC']);++ const touched = await s.renameAgentInMembers(TEST_UID, 'writer', 'NewWriter');+ expect(touched).toBe(2);++ const a = await s.readMembers(TEST_UID, 'cidA');+ expect(a.actors.find((x) => x.id === 'writer')?.name).toBe('NewWriter');+ expect(a.actors.find((x) => x.id === 'commander')?.name).toBe('Commander');++ const b = await s.readMembers(TEST_UID, 'cidB');+ expect(b.actors.find((x) => x.id === 'reviewer')?.name).toBe('Reviewer');++ const c = await s.readMembers(TEST_UID, 'cidC');+ expect(c.actors.find((x) => x.id === 'writer')?.name).toBe('NewWriter');+ });++ it('rejects reserved ids and non-safeId tokens', async () => {+ const s = await import('../../../../src/main/features/group_chat/state');+ await seedIndex(TEST_UID, ['cidA']);+ expect(await s.renameAgentInMembers(TEST_UID, 'commander', 'X')).toBe(0);+ expect(await s.renameAgentInMembers(TEST_UID, 'user', 'X')).toBe(0);+ expect(await s.renameAgentInMembers(TEST_UID, '../etc', 'X')).toBe(0);+ });++ it('returns 0 when the same name is already on the roster (no-op write)', async () => {+ const s = await import('../../../../src/main/features/group_chat/state');+ await seedConv(TEST_UID, 'cidA', [+ { kind: 'agent', id: 'writer', name: 'Writer', joined_at: 't' },+ ]);+ await seedIndex(TEST_UID, ['cidA']);+ expect(await s.renameAgentInMembers(TEST_UID, 'writer', 'Writer')).toBe(0);+ });+});+describe('group_chat state › markInFlight does NOT touch status', () => {it('flipping in_flight on/off leaves status untouched (status is owned by bus)', async () => {const s = await import('../../../../src/main/features/group_chat/state');