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.

Funnel @<name> mention construction through router.buildMention

wyt34cb4ffdec61
diff --git a/src/main/features/group_chat/bus.ts b/src/main/features/group_chat/bus.ts
index 30e53b45..4d44665f 100644
--- a/src/main/features/group_chat/bus.ts
+++ b/src/main/features/group_chat/bus.ts
@@ -34,7 +34,7 @@ import {
GroupMessage, appendVisible, readSlice, buildReplayPrefix,
} from './visibility';
import {
- resolveRecipients, parseMentions,
+ resolveRecipients, parseMentions, buildMention,
extractFormFromFinal, computeFormId, ChatFormPayload,
extractAgentFieldBlocks, decodeSubmission,
} from './router';
@@ -471,13 +471,14 @@ async function _enqueueBody(params: EnqueueParams, state: CidState): Promise<Gro
// turns in its own session jsonl and mimics that pattern; cleaning the
// output stream is more reliable than keeping the prompt perfectly tuned.
// Only rewrites whole-token matches (regex word boundary) so embedded
- // ids inside other content don't get touched.
+ // ids inside other content don't get touched. `buildMention` preserves
+ // whitespace in multi-word display names (see its header).
let rewrittenText = text;
for (const [aid, name] of idToName) {
if (!name || name === aid) continue;
const safeAid = aid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const re = new RegExp(`@${safeAid}\\b`, 'g');
- rewrittenText = rewrittenText.replace(re, `@${name.replace(/\s+/g, '')}`);
+ rewrittenText = rewrittenText.replace(re, buildMention(name));
}
// Strip ALL `@user` / `@commander` mentions when they're the routed
@@ -1154,7 +1155,7 @@ async function runTurn(state: CidState, w: WorkerState, item: QueueItem): Promis
const ag = await agentsFeat.getAgent(d.to);
if (ag && (ag as any).name) name = (ag as any).name;
} catch { /* fall back to raw id */ }
- tags.push('@' + String(name).replace(/\s+/g, ''));
+ tags.push(buildMention(name));
}
outcome = { ...outcome, text: t('chat.commander_dispatch_only', { agents: tags.join(', ') }) };
}
@@ -1338,7 +1339,7 @@ async function buildAgentsIndexBlock(_uid: string): Promise<string> {
// Lead with `@<name>` so the LLM picks up the calling convention
// visually; id is hidden — exposing hex strings in prompts trains
// the LLM to leak them in user-visible text too.
- const head = `- @${name} (Source: ${a.source})${desc}`;
+ const head = `- ${buildMention(name)} (Source: ${a.source})${desc}`;
// Inline a slimmed inputs_schema (id / type / required / default /
// label / options / min / max / accept) so commander knows what
// params each agent expects when phrasing its `@<name>` dispatch
diff --git a/src/main/features/group_chat/index.ts b/src/main/features/group_chat/index.ts
index ed4d8c23..29a368ed 100644
--- a/src/main/features/group_chat/index.ts
+++ b/src/main/features/group_chat/index.ts
@@ -41,7 +41,7 @@ export const subscribeBus = subscribe;
export { startWatchdog, stopWatchdog } from './watchdog';
import type { GroupMessage } from './visibility';
import {
- type ChatFormPayload, encodeSubmission,
+ type ChatFormPayload, encodeSubmission, buildMention,
} from './router';
const log = createLogger('group_chat.facade');
@@ -295,19 +295,23 @@ export async function markFormSubmittedAndDispatch(
{ form_id: formId, agent_id: agentId, fields: target.form.fields },
values,
);
- // Prepend `@<agent-name>` (not the hex id) so the bubble reads naturally.
- // Bus's name → id resolver still routes correctly via `agentNameToId`,
- // and falling back to the id keeps the dispatch working if the agent
- // was renamed/disabled between form emit and submit.
- let mention = `@${agentId}`;
+ // `buildMention` keeps the display name verbatim (whitespace included);
+ // falling back to the id keeps the dispatch working if the agent was
+ // renamed/disabled between form emit and submit.
+ let mention = buildMention(agentId);
try {
const agentsFeat = await import('../agents');
const ag = await agentsFeat.getAgent(agentId);
- if (ag && ag.name) mention = `@${ag.name.replace(/\s+/g, '')}`;
+ if (ag && ag.name) mention = buildMention(ag.name);
} catch (err) {
log.warn(`form-submit name lookup failed agent=${agentId}: ${(err as Error).message}`);
}
- return { ok: true, submission: { text: `${mention} ${encoded}`, agent_id: agentId } };
+ // Newline (not space) between the @-mention and the bullet list so the
+ // markdown renderer treats them as a paragraph followed by a list. With a
+ // space, the leading `- ` of the first bullet sits inline with the mention
+ // and gets parsed as a hyphen in prose, dropping the first field out of
+ // the list and leaving subsequent bullets visually orphaned.
+ return { ok: true, submission: { text: `${mention}\n${encoded}`, agent_id: agentId } };
}
// ── Read messages (UI initial load) ──────────────────────────────────────
diff --git a/src/main/features/group_chat/plan_executor.ts b/src/main/features/group_chat/plan_executor.ts
index 2ee28149..a05f37df 100644
--- a/src/main/features/group_chat/plan_executor.ts
+++ b/src/main/features/group_chat/plan_executor.ts
@@ -32,6 +32,7 @@ import {
type PlanFile, type PlanStep, type FailurePolicy,
} from './plan';
import type { ChatFormPayload } from './router';
+import { buildMention } from './router';
/** Per-cid mutex guarding plan-state transitions. Without this, when N
* parallel-group agents finish nearly simultaneously, their reconcile
@@ -854,9 +855,9 @@ async function dispatchStep(
function assigneeDisplayPrefix(assignee: string): string {
// The bus's @<id> → @<name> rewrite handles the case where assignee was an
// id; here we just ensure the message starts with `@<assignee>` so the
- // user sees who got dispatched.
- const stripped = assignee.replace(/^@+/, '').trim();
- return `@${stripped.replace(/\s+/g, '')}`;
+ // user sees who got dispatched. `buildMention` preserves whitespace (see
+ // its header).
+ return buildMention(assignee.replace(/^@+/, ''));
}
// ── Plan-complete signal ─────────────────────────────────────────────────
diff --git a/src/main/features/group_chat/router.ts b/src/main/features/group_chat/router.ts
index 083b3aef..54245403 100644
--- a/src/main/features/group_chat/router.ts
+++ b/src/main/features/group_chat/router.ts
@@ -79,6 +79,33 @@ export function parseMentions(
return out;
}
+/**
+ * Build an `@<name>` token for output (user bubbles, dispatch prefixes,
+ * `@<id>` → `@<name>` rewrites, form-submission text, pendingDispatch
+ * synthesis — every place code constructs an at-mention that ends up in a
+ * persisted message).
+ *
+ * Whitespace inside `name` is preserved verbatim. The parser side
+ * (`_buildMentionRe`) handles multi-word names via a longest-first named-alt
+ * regex, so stripping whitespace at construction time only mangles the
+ * display ("Agent Skill X" → "AgentSkillX") without buying any routing
+ * safety. Lookup-key normalisation (lower + strip-whitespace) lives in
+ * `_normalizeNameKey` and is its own concern — do not conflate with this.
+ *
+ * **Use this helper everywhere you would otherwise write `` `@${name}` ``**:
+ * having a single construction point is the only durable fix for the
+ * recurring "agent name with spaces gets mangled" class of bug
+ * (commits `ebf76e80` → `2eeee2f6` → `98ff0d2d` → form-submission round —
+ * each round only patched the discovered call site, leaving siblings to
+ * resurface the same regression). Future contributors who reach for the
+ * helper inherit the invariant for free; reviewing for inline
+ * `'@' + name.replace(/\s+/g, '')` is still recommended but no longer
+ * load-bearing once every existing site is migrated.
+ */
+export function buildMention(name: string): string {
+ return `@${String(name || '').trim()}`;
+}
+
// ── Routing ──────────────────────────────────────────────────────────────
export interface RouteResolution {