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
Map unknown categories to general
wyta2c0d86292e8
diff --git a/src/renderer/modules/agents.js b/src/renderer/modules/agents.jsindex b2bc683a..36385a30 100644--- a/src/renderer/modules/agents.js+++ b/src/renderer/modules/agents.js@@ -59,17 +59,47 @@ function _agentPlatformChipsHtml(a) {const versionLabel = t('marketplace.version').replace('{version}', String(a.version));parts.push(`<span class="agent-card-chip is-version">${escapeHtml(versionLabel)}</span>`);}- if (a.category) {- const catLabel = _resolveCategoryLabel(a.category, lang);- parts.push(`<span class="agent-card-chip">${escapeHtml(catLabel)}</span>`);- }+ const catLabel = _resolveCategoryLabel(a.category, lang);+ parts.push(`<span class="agent-card-chip">${escapeHtml(catLabel)}</span>`);return parts.join('');}-/** Shared category-code → localized label. Unknown codes stay hidden behind a user-facing- * fallback while marketplace.js schedules a throttled registry refresh. */+function _generalCategoryLabel(lang) {+ const code = 'general';+ const list = (typeof _mpCategoriesCache !== 'undefined' && _mpCategoriesCache) || [];+ const c = list.find((x) => {+ const xCode = typeof _mpCanonicalCategoryCode === 'function' ? _mpCanonicalCategoryCode(x && x.code) : String(x && x.code || '').trim();+ return xCode === code;+ });+ const label = c ? pickLocalizedName(c, lang) : '';+ if (label) return label;+ if (lang === 'zh') return '通用';+ if (lang === 'ja') return '汎用';+ return 'General';+}++function _knownCategoryCodes(cats) {+ const canonicalCategoryCode = (code) => {+ return typeof _mpCanonicalCategoryCode === 'function'+ ? _mpCanonicalCategoryCode(code)+ : String(code || '').trim();+ };+ return new Set(+ (cats || []).map((c) => canonicalCategoryCode(c && c.code)).filter(Boolean),+ );+}++function _effectiveCategoryCode(code, knownCodes) {+ const canonical = typeof _mpCanonicalCategoryCode === 'function'+ ? _mpCanonicalCategoryCode(code)+ : String(code || '').trim();+ return canonical && knownCodes.has(canonical) ? canonical : 'general';+}++/** Shared category-code → localized label. Missing or non-registry codes display as General+ * while marketplace.js schedules a throttled registry refresh for possible server drift. */function _resolveCategoryLabel(code, lang) {- if (!code) return '';+ if (!code) return _generalCategoryLabel(lang);if (typeof _mpMaybeRefreshCategoriesForCodes === 'function') {_mpMaybeRefreshCategoriesForCodes([code]);}@@ -79,7 +109,7 @@ function _resolveCategoryLabel(code, lang) {const xCode = typeof _mpCanonicalCategoryCode === 'function' ? _mpCanonicalCategoryCode(x && x.code) : String(x && x.code || '').trim();return xCode === canonical;});- if (!c) return typeof _mpUnknownCategoryLabel === 'function' ? _mpUnknownCategoryLabel() : 'Unknown';+ if (!c) return _generalCategoryLabel(lang);return pickLocalizedName(c, lang) || code;}@@ -260,8 +290,8 @@ function renderAgentsGrid(agents) {return (raw && raw !== 'marketplace.all') ? raw : 'All';})();- // Build the chip strip from the marketplace category cache + one fallback- // "Unknown" chip for both missing categories and non-registry category codes.+ // Build the chip strip from the marketplace category cache. Missing categories+ // and non-registry category codes are treated as General.// If the active selection no longer matches any agent (rare — agent moved// between categories mid-session), fall back to All so the body isn't empty.const canonicalCategoryCode = (code) => {@@ -269,8 +299,14 @@ function renderAgentsGrid(agents) {? _mpCanonicalCategoryCode(code): String(code || '').trim();};- const codesPresent = new Set(agents.map((a) => canonicalCategoryCode(a && a.category)));const cats = (typeof _mpCategoriesCache !== 'undefined' && _mpCategoriesCache) || [];+ const knownCodes = _knownCategoryCodes(cats);+ const rawCodesPresent = new Set(agents.map((a) => canonicalCategoryCode(a && a.category)));+ const unknownCodes = [...rawCodesPresent].filter((c) => c && !knownCodes.has(c)).sort();+ if (unknownCodes.length && typeof _mpMaybeRefreshCategoriesForCodes === 'function') {+ _mpMaybeRefreshCategoriesForCodes(unknownCodes);+ }+ const codesPresent = new Set([...rawCodesPresent].map((c) => _effectiveCategoryCode(c, knownCodes)));const chipCodes = [];const chipCodeSeen = new Set();for (const c of cats) {@@ -279,24 +315,14 @@ function renderAgentsGrid(agents) {chipCodes.push({ code, label: pickLocalizedName(c, lang) || code });chipCodeSeen.add(code);}- const knownCodes = new Set(cats.map((c) => canonicalCategoryCode(c && c.code)).filter(Boolean));- const unknownCodes = [...codesPresent].filter((c) => c && !knownCodes.has(c)).sort();- if (unknownCodes.length && typeof _mpMaybeRefreshCategoriesForCodes === 'function') {- _mpMaybeRefreshCategoriesForCodes(unknownCodes);- }- const hasUnknownCategory = codesPresent.has('') || unknownCodes.length > 0;- if (hasUnknownCategory) {- chipCodes.push({- code: '__unknown__',- label: typeof _mpUnknownCategoryLabel === 'function' ? _mpUnknownCategoryLabel() : 'Unknown',- });+ if (codesPresent.has('general') && !chipCodeSeen.has('general')) {+ chipCodes.push({ code: 'general', label: _generalCategoryLabel(lang) });+ chipCodeSeen.add('general');}- if (_agentsActiveCategory === '__uncategorized__') _agentsActiveCategory = '__unknown__';- if (_agentsActiveCategory && _agentsActiveCategory !== '__unknown__'- && !chipCodes.some((c) => c.code === _agentsActiveCategory)) {- _agentsActiveCategory = '';+ if (_agentsActiveCategory === '__uncategorized__' || _agentsActiveCategory === '__unknown__') {+ _agentsActiveCategory = codesPresent.has('general') ? 'general' : '';}- if (_agentsActiveCategory === '__unknown__' && !hasUnknownCategory) {+ if (_agentsActiveCategory && !chipCodes.some((c) => c.code === _agentsActiveCategory)) {_agentsActiveCategory = '';}@@ -322,11 +348,7 @@ function renderAgentsGrid(agents) {const filtered = agents.filter((a) => {if (_agentsActiveCategory === '') return true;- if (_agentsActiveCategory === '__unknown__') {- const code = canonicalCategoryCode(a && a.category);- return !code || !knownCodes.has(code);- }- return canonicalCategoryCode(a && a.category) === _agentsActiveCategory;+ return _effectiveCategoryCode(a && a.category, knownCodes) === _agentsActiveCategory;});const cardHtml = (a) => {@@ -665,12 +687,9 @@ function _renderSourceMetaHtml(item) {const versionLabel = t('marketplace.version').replace('{version}', String(item.version));parts.push(`<span class="agents-detail-source is-version">${escapeHtml(versionLabel)}</span>`);}- const catCode = String(item.category || '').trim();- if (catCode) {- const lang = (typeof getLang === 'function') ? getLang() : 'zh';- const label = _resolveCategoryLabel(catCode, lang);- parts.push(`<span class="agents-detail-source is-category">${escapeHtml(label)}</span>`);- }+ const lang = (typeof getLang === 'function') ? getLang() : 'zh';+ const label = _resolveCategoryLabel(item.category, lang);+ parts.push(`<span class="agents-detail-source is-category">${escapeHtml(label)}</span>`);return parts.join('');}diff --git a/src/renderer/modules/skills.js b/src/renderer/modules/skills.jsindex 7f638bba..29071260 100644--- a/src/renderer/modules/skills.js+++ b/src/renderer/modules/skills.js@@ -33,10 +33,8 @@ function _skillPlatformChipsHtml(s) {const versionLabel = t('marketplace.version').replace('{version}', String(s.version));parts.push(`<span class="skill-card-chip is-version">${escapeHtml(versionLabel)}</span>`);}- if (s.category) {- const catLabel = _resolveCategoryLabel(s.category, lang);- parts.push(`<span class="skill-card-chip">${escapeHtml(catLabel)}</span>`);- }+ const catLabel = _resolveCategoryLabel(s.category, lang);+ parts.push(`<span class="skill-card-chip">${escapeHtml(catLabel)}</span>`);return parts.join('');}@@ -331,13 +329,20 @@ function renderSkillsGrid(skills) {})();// Chip strip — `_mpCategoriesCache` is defined in marketplace.js (flat top-level scope).+ // Missing categories and non-registry category codes are treated as General.const canonicalCategoryCode = (code) => {return typeof _mpCanonicalCategoryCode === 'function'? _mpCanonicalCategoryCode(code): String(code || '').trim();};- const codesPresent = new Set(skills.map((s) => canonicalCategoryCode(s && s.category)));const cats = (typeof _mpCategoriesCache !== 'undefined' && _mpCategoriesCache) || [];+ const knownCodes = _knownCategoryCodes(cats);+ const rawCodesPresent = new Set(skills.map((s) => canonicalCategoryCode(s && s.category)));+ const unknownCodes = [...rawCodesPresent].filter((c) => c && !knownCodes.has(c)).sort();+ if (unknownCodes.length && typeof _mpMaybeRefreshCategoriesForCodes === 'function') {+ _mpMaybeRefreshCategoriesForCodes(unknownCodes);+ }+ const codesPresent = new Set([...rawCodesPresent].map((c) => _effectiveCategoryCode(c, knownCodes)));const chipCodes = [];const chipCodeSeen = new Set();for (const c of cats) {@@ -346,24 +351,14 @@ function renderSkillsGrid(skills) {chipCodes.push({ code, label: pickLocalizedName(c, lang) || code });chipCodeSeen.add(code);}- const knownCodes = new Set(cats.map((c) => canonicalCategoryCode(c && c.code)).filter(Boolean));- const unknownCodes = [...codesPresent].filter((c) => c && !knownCodes.has(c)).sort();- if (unknownCodes.length && typeof _mpMaybeRefreshCategoriesForCodes === 'function') {- _mpMaybeRefreshCategoriesForCodes(unknownCodes);- }- const hasUnknownCategory = codesPresent.has('') || unknownCodes.length > 0;- if (hasUnknownCategory) {- chipCodes.push({- code: '__unknown__',- label: typeof _mpUnknownCategoryLabel === 'function' ? _mpUnknownCategoryLabel() : 'Unknown',- });+ if (codesPresent.has('general') && !chipCodeSeen.has('general')) {+ chipCodes.push({ code: 'general', label: _generalCategoryLabel(lang) });+ chipCodeSeen.add('general');}- if (_skillsActiveCategory === '__uncategorized__') _skillsActiveCategory = '__unknown__';- if (_skillsActiveCategory && _skillsActiveCategory !== '__unknown__'- && !chipCodes.some((c) => c.code === _skillsActiveCategory)) {- _skillsActiveCategory = '';+ if (_skillsActiveCategory === '__uncategorized__' || _skillsActiveCategory === '__unknown__') {+ _skillsActiveCategory = codesPresent.has('general') ? 'general' : '';}- if (_skillsActiveCategory === '__unknown__' && !hasUnknownCategory) {+ if (_skillsActiveCategory && !chipCodes.some((c) => c.code === _skillsActiveCategory)) {_skillsActiveCategory = '';}@@ -387,11 +382,7 @@ function renderSkillsGrid(skills) {const filtered = skills.filter((s) => {if (_skillsActiveCategory === '') return true;- if (_skillsActiveCategory === '__unknown__') {- const code = canonicalCategoryCode(s && s.category);- return !code || !knownCodes.has(code);- }- return canonicalCategoryCode(s && s.category) === _skillsActiveCategory;+ return _effectiveCategoryCode(s && s.category, knownCodes) === _skillsActiveCategory;});const cardHtml = (s) => {diff --git a/test/renderer/category-tabs.test.ts b/test/renderer/category-tabs.test.tsnew file mode 100644index 00000000..adb8953e--- /dev/null+++ b/test/renderer/category-tabs.test.ts@@ -0,0 +1,113 @@+import { describe, expect, it } from 'vitest';+import * as fs from 'node:fs';+import * as path from 'node:path';+import * as vm from 'node:vm';++class FakeClassList {+ classes = new Set<string>();+ add(cls: string) { this.classes.add(cls); }+ remove(cls: string) { this.classes.delete(cls); }+ contains(cls: string) { return this.classes.has(cls); }+ toggle(cls: string, force?: boolean) {+ const next = force === undefined ? !this.classes.has(cls) : force;+ if (next) this.classes.add(cls);+ else this.classes.delete(cls);+ }+}++class FakeElement {+ innerHTML = '';+ style: Record<string, string> = {};+ classList = new FakeClassList();+ querySelectorAll() { return []; }+ addEventListener() {}+}++function loadCategoryRenderers() {+ const elements = new Map<string, FakeElement>();+ const el = (id: string) => {+ if (!elements.has(id)) elements.set(id, new FakeElement());+ return elements.get(id)!;+ };+ const context: any = {+ console,+ createLogger: () => ({ warn: () => {}, error: () => {}, info: () => {} }),+ document: { getElementById: (id: string) => el(id), querySelectorAll: () => [] },+ window: { addEventListener: () => {}, orkas: { invoke: async () => ({ list: [] }) } },+ escapeHtml: (s: unknown) => String(s ?? '').replace(/[&<>"']/g, (ch) => ({+ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''',+ } as Record<string, string>)[ch]),+ getLang: () => 'zh',+ t: (key: string) => ({+ 'agents.custom_group': '自定义',+ 'agents.builtin_group': '平台',+ 'agents.use_tooltip': '使用',+ 'agents.more_actions': '更多',+ 'agents.placeholder_unset': '未设置',+ 'agents.unnamed': '未命名',+ 'skills.custom_group': '自定义',+ 'skills.builtin_group': '平台',+ 'skills.use_tooltip': '使用',+ 'skills.more_actions': '更多',+ 'skills.no_desc': '无描述',+ 'marketplace.all': '全部',+ } as Record<string, string>)[key] || key,+ pickLocalizedName: (c: any) => c?.name_zh || c?.name_en || c?.code || '',+ pickDesc: (item: any) => item?.description_zh || item?.description_en || item?.description || '',+ renderAvatarHtml: () => '<span class="avatar"></span>',+ normalizeCatalogSource: (source: string) => source || '',+ isMarketplaceCatalogSource: (source: string) => source === 'marketplace',+ _mpCategoriesCache: [+ { code: 'data', name_zh: '数据', name_en: 'Data' },+ { code: 'general', name_zh: '通用', name_en: 'General' },+ ],+ _mpCanonicalCategoryCode: (code: unknown) => String(code || '').trim() === 'writing' ? 'creation' : String(code || '').trim(),+ _mpMaybeRefreshCategoriesForCodes: () => {},+ };+ vm.createContext(context);+ for (const file of ['agents.js', 'skills.js']) {+ const code = fs.readFileSync(path.join(__dirname, '../../src/renderer/modules', file), 'utf8');+ vm.runInContext(code, context, { filename: file });+ }+ return { context, el };+}++describe('agent and skill category tabs', () => {+ it('maps missing and non-registry agent categories to General instead of Unknown', () => {+ const { context, el } = loadCategoryRenderers();+ const agents = [+ { agent_id: 'a1', name: 'No Category', source: 'custom', category: '' },+ { agent_id: 'a2', name: 'Bad Category', source: 'custom', category: 'not-in-registry' },+ { agent_id: 'a3', name: 'Data Agent', source: 'custom', category: 'data' },+ ];++ context.renderAgentsGrid(agents);+ expect(el('agents-categories').innerHTML).toContain('通用');+ expect(el('agents-categories').innerHTML).not.toContain('未知');++ vm.runInContext('_agentsActiveCategory = "general"', context);+ context.renderAgentsGrid(agents);+ expect(el('agents-grid').innerHTML).toContain('No Category');+ expect(el('agents-grid').innerHTML).toContain('Bad Category');+ expect(el('agents-grid').innerHTML).not.toContain('Data Agent');+ });++ it('maps missing and non-registry skill categories to General instead of Unknown', () => {+ const { context, el } = loadCategoryRenderers();+ const skills = [+ { id: 's1', name: 'No Category', source: 'custom', category: '' },+ { id: 's2', name: 'Bad Category', source: 'custom', category: 'not-in-registry' },+ { id: 's3', name: 'Data Skill', source: 'custom', category: 'data' },+ ];++ context.renderSkillsGrid(skills);+ expect(el('skills-categories').innerHTML).toContain('通用');+ expect(el('skills-categories').innerHTML).not.toContain('未知');++ vm.runInContext('_skillsActiveCategory = "general"', context);+ context.renderSkillsGrid(skills);+ expect(el('skills-grid').innerHTML).toContain('No Category');+ expect(el('skills-grid').innerHTML).toContain('Bad Category');+ expect(el('skills-grid').innerHTML).not.toContain('Data Skill');+ });+});