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.

feat: project scope — collapse to agents only, validate recipient on switch, dispatch-time bindings filter

wyt9c578b0f772a
diff --git a/CLAUDE.md b/CLAUDE.md
index 564d6842..c8b66fc9 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -232,7 +232,7 @@ Sources = `src/builtin/skills/` (git-tracked, hash-synced into `data/builtin/ski
3. `chats.ts::stream/sendToConversation` — bound disabled agents return `errors.agent_disabled` directly.
4. `skill-registry.getSystemPromptBlock({disabledIds})` — render-stage filtering.
-**Project scope** is the OUTER intersection — applied BEFORE the 4 enable filters above, NOT a 5th site. The two existing render entry points (`buildAgentsIndexBlock` for agents, `getSystemPromptBlock` for skills) accept an `allowedIds` / `allowlist` parameter; group_chat resolves `projects.resolveProjectScope(uid, projectId)` once at the top of `runTurn` and threads `bindings.agents` into the agent picker call and `bindings.skills` (intersected with `agent.skill_list` for the System A render only) via `ChatOptions.projectAllowedSkillIds`. SkillStore (System B, agent self-evolved skills) is gated by `skillList` alone — project bindings must NOT block an agent from accessing its own evolved skills. Order: `project bindings ∩ skill_list ∩ enabled` for System A; `skill_list ∩ enabled` for System B. Orphan conversations (no `project_id`) skip the project step entirely (legacy behavior).
+**Project scope (current round: agents only)** is the OUTER intersection — applied BEFORE the 4 enable filters above, NOT a 5th site. group_chat resolves `projects.resolveProjectScope(uid, projectId)` once at the top of `runTurn` and threads `bindings.agents` into `buildAgentsIndexBlock(uid, allowedIds)` to collapse the commander's visible-agents list. **Skills are NOT project-scoped this round** — `bindings.skills` is read but bus does not pass it through to the runner; every skill remains globally visible (gated only by `skill_list ∩ enabled`). The runner's `projectAllowedSkillIds` parameter and `_intersectRenderAllowlist` helper are preserved for a future re-enable: when bus starts passing it again, the System A render block intersects `skillList ∩ projectAllowedSkillIds` while SkillStore (System B, agent self-evolved skills) stays gated by `skillList` alone — project bindings must NOT block an agent from accessing its own evolved skills. Order today: `project bindings ∩ enabled` for the agent picker; `skill_list ∩ enabled` for both System A and System B skills. Orphan conversations (no `project_id`) skip the project step entirely. Renderer: the recipient agent picker (`agents.js::_openAgentPicker`) refreshes `_pickerBoundAgentIds` on every open from `_resolveActiveProjectId(anchorId)` (commander chip's pid for new-chat, conv.project_id for in-chat) so the user can't pick an agent the project hasn't bound; commander remains pickable as a virtual entry; an empty-bindings project surfaces an in-picker hint to open the project page.
**Write entry points** (rename / URL/dir import): see `features/skills.ts`. Every write entry must call `invalidateSkills()`. The `<<<skill-file>>>` block can only write into the current skill directory (no cross-skill `skill=Y` attribute).
diff --git a/src/main/features/group_chat/bus.ts b/src/main/features/group_chat/bus.ts
index ccb37e10..d3b8a1fb 100644
--- a/src/main/features/group_chat/bus.ts
+++ b/src/main/features/group_chat/bus.ts
@@ -429,6 +429,36 @@ async function _enqueueBody(params: EnqueueParams, state: CidState): Promise<Gro
}
to = Array.from(new Set(to));
+ // Project scope at dispatch time: if the conversation belongs to a
+ // project, drop any recipient agent_id that isn't bound to the project
+ // (CLAUDE.md §6 — "不可用则交给指挥官处理"). Reserved ids (user /
+ // commander) always pass through. After filtering, an empty `to` falls
+ // through to the sender-default rule below — for user-initiated text
+ // that means "go to commander", which is the explicit hand-off the
+ // requirement asks for. Cheap: one project.json + bindings.json read,
+ // resolveProjectScope already memoises file existence checks. Skipped
+ // when the conv has no project_id (orphan = unrestricted).
+ try {
+ const { getConversation } = await import('../chats');
+ const conv = await getConversation(uid, cid);
+ const projectId = (conv as any)?.project_id;
+ if (typeof projectId === 'string' && projectId) {
+ const projectsFeat = await import('../projects');
+ const scope = await projectsFeat.resolveProjectScope(uid, projectId);
+ if (scope) {
+ const bound = new Set(scope.agents);
+ const before = to;
+ to = to.filter((id) => RESERVED_IDS.has(id) || bound.has(id));
+ if (to.length !== before.length) {
+ const dropped = before.filter((id) => !to.includes(id));
+ log.info(`dispatch project-scope drop cid=${cid} pid=${projectId} from=${fromActorId} dropped=${dropped.join(',')}`);
+ }
+ }
+ }
+ } catch (err) {
+ log.warn(`project-scope filter cid=${cid}: ${(err as Error).message}`);
+ }
+
// Default fallback: if nothing resolved (and no force), use sender-default.
// Mirror router.ts's rule: user → commander; commander/agent → user.
if (!to.length) {
@@ -795,10 +825,8 @@ async function runTurn(state: CidState, w: WorkerState, item: QueueItem): Promis
if (isCommander) {
systemPrompt = await buildCommanderSystemPrompt(uid, cid, turnProjectScope?.agents ?? null);
extraTools = await buildCommanderExtraTools(state, w);
- // skillList stays undefined for commander — the project filter is
- // applied via `projectAllowedSkillIds` below so the runner can fold
- // it into `getSystemPromptBlock`'s allowlist without disturbing
- // SkillStore (System B; commander has none anyway).
+ // skillList stays undefined for commander — every skill is globally
+ // visible (skills are NOT project-scoped this round; see CLAUDE.md §6).
} else {
const agent = await agentsFeat.getAgent(actor.id);
if (!agent) {
@@ -832,10 +860,9 @@ async function runTurn(state: CidState, w: WorkerState, item: QueueItem): Promis
} else {
systemPrompt = await buildAgentInGroupSystemPrompt(uid, agent, workingDir);
// Pass agent.skill_list verbatim — it carries System A + System B
- // ids the agent owns. The project filter is applied via
- // `projectAllowedSkillIds` on the streamChatWithModel call so it
- // only narrows the System A render block (`getSystemPromptBlock`),
- // never blocks the agent's own evolved-skill SkillStore (System B).
+ // ids the agent owns. Skills are NOT project-scoped this round
+ // (see CLAUDE.md §6); the runner's `projectAllowedSkillIds` hook is
+ // preserved for future re-enable but bus does not pass it.
skillList = Array.isArray(agent.skill_list) ? agent.skill_list : undefined;
}
}
@@ -1001,7 +1028,10 @@ async function runTurn(state: CidState, w: WorkerState, item: QueueItem): Promis
readOnlyExtraRoots: [...skillRoots, ...agentRoots],
...(extraTools.length ? { extraTools } : {}),
...(skillList !== undefined ? { skillList } : {}),
- ...(turnProjectScope ? { projectAllowedSkillIds: turnProjectScope.skills } : {}),
+ // Skills are NOT project-scoped this round — every conversation sees
+ // every skill (gated only by per-user enable + agent.skill_list).
+ // The runner's `projectAllowedSkillIds` plumbing is preserved for
+ // a future re-enable; bus just doesn't pass it.
})) {
// Stream events → process channel.
if (ev.type === 'final') {
diff --git a/src/renderer/index.html b/src/renderer/index.html
index 14bbf39d..60bd8c75 100644
--- a/src/renderer/index.html
+++ b/src/renderer/index.html
@@ -357,14 +357,19 @@
<section class="project-detail-card" id="project-detail-agents-section">
<div class="project-detail-card-head">
<span class="project-detail-card-title" data-i18n="project.bindings.agents_title">Agents</span>
- <button type="button" class="btn btn-sm" id="project-add-agent-btn" data-i18n="project.bindings.add_agent">+ Add</button>
+ <button type="button" class="btn btn-sm" id="project-add-agent-btn" data-i18n="project.bindings.add_agent">Add</button>
</div>
<div class="project-bindings-list" id="project-agents-list"></div>
</section>
- <section class="project-detail-card" id="project-detail-skills-section">
+ <!-- Skills section intentionally hidden this round: skills are
+ globally available regardless of project membership. The
+ storage + IPC + runner plumbing for skill bindings stays in
+ place so this card can be re-introduced without a schema
+ change later. -->
+ <section class="project-detail-card" id="project-detail-skills-section" style="display:none">
<div class="project-detail-card-head">
<span class="project-detail-card-title" data-i18n="project.bindings.skills_title">Skills</span>
- <button type="button" class="btn btn-sm" id="project-add-skill-btn" data-i18n="project.bindings.add_skill">+ Add</button>
+ <button type="button" class="btn btn-sm" id="project-add-skill-btn" data-i18n="project.bindings.add_skill">Add</button>
</div>
<div class="project-bindings-list" id="project-skills-list"></div>
</section>
diff --git a/src/renderer/locales/en.json b/src/renderer/locales/en.json
index 6518f96e..b20a78ca 100644
--- a/src/renderer/locales/en.json
+++ b/src/renderer/locales/en.json
@@ -584,6 +584,7 @@
"project.action.delete": "Delete",
"project.bindings.picker_search_placeholder": "Search by name or description",
"project.bindings.picker_no_match": "No matches found.",
+ "agents.no_project_agents": "This project has no agents bound. Open the project page to add some.",
"project.bindings.agents_title": "Agents",
"project.bindings.skills_title": "Skills",
"project.bindings.agents_desc": "Add agents to make them available inside this project.",
@@ -599,7 +600,7 @@
"project.bindings.candidates_empty_agents": "No agents available to add.",
"project.bindings.candidates_empty_skills": "No skills available to add.",
"project.bindings.stale": "Removed",
- "project.bindings.empty_in_chat": "This project has no agents or skills bound. Open the project page to add some.",
+ "project.bindings.empty_in_chat": "This project has no agents bound. Open the project page to add one.",
"project.bindings.open_settings": "Open project page",
"search.history_title": "Recent searches",
"search.history_clear": "Clear",
diff --git a/src/renderer/locales/zh.json b/src/renderer/locales/zh.json
index d497d7ef..ba6a534c 100644
--- a/src/renderer/locales/zh.json
+++ b/src/renderer/locales/zh.json
@@ -584,6 +584,7 @@
"project.action.delete": "删除",
"project.bindings.picker_search_placeholder": "按名称或描述搜索",
"project.bindings.picker_no_match": "没有匹配结果。",
+ "agents.no_project_agents": "本项目尚未添加任何智能体。请打开项目页面进行配置。",
"project.bindings.agents_title": "智能体",
"project.bindings.skills_title": "技能",
"project.bindings.agents_desc": "添加可在本项目中使用的智能体。",
@@ -594,12 +595,12 @@
"project.bindings.picker_title_skills": "添加技能到项目",
"project.bindings.picker_close": "关闭",
"project.bindings.remove": "移除",
- "project.bindings.empty_agents": "尚未挂载任何智能体。添加后才能在本项目中使用。",
- "project.bindings.empty_skills": "尚未挂载任何技能。添加后才能在本项目中使用。",
+ "project.bindings.empty_agents": "尚未添加任何智能体。添加后才能在本项目中使用。",
+ "project.bindings.empty_skills": "尚未添加任何技能。添加后才能在本项目中使用。",
"project.bindings.candidates_empty_agents": "没有可添加的智能体。",
"project.bindings.candidates_empty_skills": "没有可添加的技能。",
"project.bindings.stale": "已删除",
- "project.bindings.empty_in_chat": "本项目尚未挂载任何智能体或技能。请打开项目页面进行配置。",
+ "project.bindings.empty_in_chat": "本项目尚未添加任何智能体。请打开项目页面进行配置。",
"project.bindings.open_settings": "打开项目页面",
"search.history_title": "搜索历史",
"search.history_clear": "清空",
diff --git a/src/renderer/modules/agents.js b/src/renderer/modules/agents.js
index f6aee81c..d7a0b154 100644
--- a/src/renderer/modules/agents.js
+++ b/src/renderer/modules/agents.js
@@ -1342,10 +1342,43 @@ if (typeof window !== 'undefined') {
window.positionPickerPopover = _positionPopoverAboveOrBelow;
}
-function _openAgentPicker(anchorBtn) {
+// Project scope state for the active picker session: when the anchor's
+// active context (commander tab / current conv) belongs to a project, the
+// picker collapses to that project's bound agents. `null` = no project
+// scope active (orphan conv / no project picked) → unrestricted listing.
+// Set on every `_openAgentPicker`; consumed by `_renderAgentPickerList` and
+// the search-input change handler so live filtering stays scoped.
+let _pickerBoundAgentIds = null;
+
+function _resolveActiveProjectId(anchorId) {
+ if (anchorId === 'new-chat-recipient-chip') {
+ return (typeof getCommanderProjectId === 'function') ? getCommanderProjectId() : '';
+ }
+ if (anchorId === 'chat-recipient-chip') {
+ if (typeof currentCid !== 'undefined' && currentCid
+ && typeof conversations !== 'undefined' && Array.isArray(conversations)) {
+ const conv = conversations.find((c) => c && c.conversation_id === currentCid);
+ return (conv && conv.project_id) || '';
+ }
+ }
+ return '';
+}
+
+async function _openAgentPicker(anchorBtn) {
const picker = document.getElementById('agent-picker');
if (!anchorBtn || !picker) return;
picker.dataset.anchorId = anchorBtn.id;
+ // Refresh project-scope bindings on every open so the picker reflects
+ // whatever project the user just picked (commander chip) or whatever
+ // project the active conv belongs to.
+ _pickerBoundAgentIds = null;
+ const pid = _resolveActiveProjectId(anchorBtn.id);
+ if (pid) {
+ try {
+ const res = await window.orkas.invoke('projects.bindings.list', { projectId: pid });
+ if (res?.ok) _pickerBoundAgentIds = new Set((res.bindings && res.bindings.agents) || []);
+ } catch (_) { /* fall back to global listing */ }
+ }
// Render first so measurement in _positionPopoverAboveOrBelow reflects
// the real list height (not stale content from a previous open).
_renderAgentPickerList('');
@@ -1368,7 +1401,13 @@ function _renderAgentPickerList(filterText) {
const anchorId = picker?.dataset.anchorId || '';
// Disabled agents are filtered out — picker is a "what can I dispatch right
// now" UI, and re-enabling lives in the management page (Agents view + ⋯ menu).
- const agents = (_agentsCache || []).filter((a) => a.enabled !== false);
+ let agents = (_agentsCache || []).filter((a) => a.enabled !== false);
+ // Project scope: only show agents bound to the active context's project.
+ // Applied AFTER the enabled filter (per CLAUDE.md §6 outer-intersection
+ // rule). `null` = no project scope, full listing.
+ if (_pickerBoundAgentIds) {
+ agents = agents.filter((a) => _pickerBoundAgentIds.has(a.agent_id));
+ }
const q = (filterText || '').toLowerCase();
// Search matches across the active locale description; cross-language
// fallback via pickDesc lets users find a single-locale agent regardless
@@ -1421,7 +1460,15 @@ function _renderAgentPickerList(filterText) {
<div class="skill-picker-item-desc">${escapeHtml(t('chat.recipient_commander_hint'))}</div>
</div>`
: '';
- listEl.innerHTML = commanderHtml + groupHtml(t('agents.source_custom'), groups.custom) + groupHtml(t('agents.source_builtin'), groups.builtin);
+ // When the active context is a project AND the project has zero agents
+ // bound, surface a hint above the commander entry so the user knows
+ // "this isn't broken — go bind an agent first". Suppressed on user search
+ // (they're explicitly typing) so the search "no match" message owns the
+ // empty rendering.
+ const projectEmptyHint = (!q && _pickerBoundAgentIds && _pickerBoundAgentIds.size === 0)
+ ? `<div class="skill-picker-empty-hint">${escapeHtml(t('agents.no_project_agents'))}</div>`
+ : '';
+ listEl.innerHTML = projectEmptyHint + commanderHtml + groupHtml(t('agents.source_custom'), groups.custom) + groupHtml(t('agents.source_builtin'), groups.builtin);
for (const el of listEl.querySelectorAll('[data-id]')) {
el.addEventListener('click', async () => {
_closeAgentPicker();
diff --git a/src/renderer/modules/conversation.js b/src/renderer/modules/conversation.js
index 59b852e0..9130c853 100644
--- a/src/renderer/modules/conversation.js
+++ b/src/renderer/modules/conversation.js
@@ -220,6 +220,28 @@ function getChatRecipient(target) { return { ..._activeRecipient(target) }; }
function _onRecipientChanged(_target) { /* reserved for future hooks */ }
+/** When the active project's bindings change (commander chip → switch
+ * project, or project rename/binding edit while a chat is open), the
+ * current recipient may no longer be a valid agent for the new scope.
+ * Reset to commander silently — the user will see the chip flip and the
+ * recipient picker collapse to commander-only on next open. Called from
+ * `projects.js` post project-pick. No-op for `commander` recipients and
+ * for orphan contexts (pid empty). */
+async function validateRecipientAgainstProject(target, pid) {
+ const cur = _activeRecipient(target);
+ if (!cur || cur.kind !== 'agent') return;
+ if (!pid) return;
+ try {
+ const res = await window.orkas.invoke('projects.bindings.list', { projectId: pid });
+ if (!res || !res.ok) return;
+ const bound = new Set((res.bindings && res.bindings.agents) || []);
+ if (!bound.has(cur.id)) {
+ setChatRecipient(target, { kind: 'commander' });
+ _renderRecipientChip(target);
+ }
+ } catch (_) { /* leave as-is on failure */ }
+}
+
function setChatRecipient(target, next, _opts = {}) {
const r = _normRecipient(next);
if (!r) return;
@@ -294,10 +316,21 @@ function onEnterConversationView() {
// Workspace chip scope follows the active conv's project (resolved on
// main side via cid → conv.project_id). Refresh whenever a conv mounts.
if (typeof refreshWorkspaceChip === 'function') refreshWorkspaceChip();
+ // Recipient validation: bindings may have changed since this conv was
+ // last open (user removed the agent from the project). If the sticky
+ // recipient is no longer in the project's agents, drop back to commander
+ // so the chip matches what the dispatch path will actually route to.
+ if (currentCid && Array.isArray(conversations)) {
+ const conv = conversations.find((c) => c && c.conversation_id === currentCid);
+ const pid = (conv && conv.project_id) || '';
+ if (pid && typeof validateRecipientAgainstProject === 'function') {
+ validateRecipientAgainstProject('conversation', pid);
+ }
+ }
// Empty-bindings banner: when this conv belongs to a project and the
- // project has zero agents + zero skills bound, surface a one-line
- // notice + "Open project page" affordance. Cheap IPC; only fires for
- // in-project conversations.
+ // project has zero agents bound, surface a one-line notice + "Open
+ // project page" affordance. Cheap IPC; only fires for in-project
+ // conversations.
if (typeof refreshConvProjectEmptyBanner === 'function') refreshConvProjectEmptyBanner(currentCid);
// One-shot auto-expand: if the conv we just entered belongs to a
// project, surface the project's row in the sidebar. Skipped when the
diff --git a/src/renderer/modules/project-detail.js b/src/renderer/modules/project-detail.js
index 61eed2be..a3eba970 100644
--- a/src/renderer/modules/project-detail.js
+++ b/src/renderer/modules/project-detail.js
@@ -397,7 +397,9 @@ async function refreshConvProjectEmptyBanner(cid) {
try {
const res = await window.orkas.invoke('projects.bindings.list', { projectId: pid });
const b = res && res.bindings ? res.bindings : { agents: [], skills: [] };
- const isEmpty = !(b.agents || []).length && !(b.skills || []).length;
+ // Skills aren't project-scoped this round — only the agents bucket
+ // gates whether the user can do anything inside this project.
+ const isEmpty = !(b.agents || []).length;
banner.style.display = isEmpty ? '' : 'none';
banner.dataset.pid = pid;
} catch (_) {
diff --git a/src/renderer/modules/projects.js b/src/renderer/modules/projects.js
index 51c68eb4..7dd3a375 100644
--- a/src/renderer/modules/projects.js
+++ b/src/renderer/modules/projects.js
@@ -688,6 +688,13 @@ function _showCommanderProjectPicker(anchor) {
} catch (_) {}
_renderCommanderProjectChip();
if (typeof refreshWorkspaceChip === 'function') refreshWorkspaceChip();
+ // Recipient validation: switching to a project that doesn't include
+ // the currently-picked agent must drop the chip back to commander
+ // (otherwise the user sends @<unbound-agent> + commander has nothing
+ // to dispatch to). No-op when commander or orphan project.
+ if (typeof validateRecipientAgainstProject === 'function') {
+ validateRecipientAgainstProject('new-chat', _commanderProjectId);
+ }
_closeMenu();
});
menu.appendChild(row);
diff --git a/src/renderer/style.css b/src/renderer/style.css
index 6f15ab41..221082df 100644
--- a/src/renderer/style.css
+++ b/src/renderer/style.css
@@ -3713,6 +3713,19 @@ body.model-not-configured .main-content { flex-direction: column; }
-webkit-line-clamp: 2;
}
+/* Banner shown above the picker list when the active context is a project
+ with zero bound agents — anchors the empty state without hiding the
+ commander entry below. */
+.skill-picker-empty-hint {
+ padding: 8px 10px;
+ font-size: 11.5px;
+ color: #b45309;
+ background: #fef3c7;
+ border-radius: 6px;
+ margin: 4px 6px 6px 6px;
+ line-height: 1.4;
+}
+
.skill-picker-empty {
padding: 18px 10px;
text-align: center;