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.

Add quote-reply button on group chat bubbles

wyt8bbc3a259ad6
diff --git a/src/renderer/index.html b/src/renderer/index.html
index f115327a..7a5cc14f 100644
--- a/src/renderer/index.html
+++ b/src/renderer/index.html
@@ -117,6 +117,7 @@
<div class="chat-attachments" id="chat-attachments" style="display:none"></div>
<div class="chat-input-toolbar"></div>
</div>
+ <div class="chat-quote-preview" id="chat-quote-preview" style="display:none"></div>
<textarea id="chat-input" data-i18n-placeholder="chat.input_placeholder" placeholder="继续对话..." rows="2"></textarea>
<div class="chat-bottom-bar">
<button type="button" class="chat-attach-btn" id="chat-attach-btn" data-i18n-title="chat.attach_title" title="上传附件(文本/PDF/Word/图片)">+</button>
diff --git a/src/renderer/locales/en.json b/src/renderer/locales/en.json
index 791a8eaf..a0ad59eb 100644
--- a/src/renderer/locales/en.json
+++ b/src/renderer/locales/en.json
@@ -84,6 +84,11 @@
"chat.copy_btn": "Copy",
"chat.copy_done": "Copied ✓",
"chat.copy_failed": "Copy failed",
+ "chat.quote_btn_title": "Quote this message and send to a target agent",
+ "chat.quote_btn": "Quote",
+ "chat.quote_from": "Quoted from @{name}:",
+ "chat.quote_remove_title": "Remove quote",
+ "chat.quote_files_label": "Attached files (readable directly via read_file):",
"chat.attach_still_uploading": "Attachments are still uploading; please wait before sending.",
"chat.create_conv_failed": "Failed to create conversation",
"chat.create_conv_failed_with_reason": "Failed to create conversation: {reason}",
diff --git a/src/renderer/locales/zh.json b/src/renderer/locales/zh.json
index 1c1ea2ec..efb53c5a 100644
--- a/src/renderer/locales/zh.json
+++ b/src/renderer/locales/zh.json
@@ -84,6 +84,11 @@
"chat.copy_btn": "复制",
"chat.copy_done": "已复制 ✓",
"chat.copy_failed": "复制失败",
+ "chat.quote_btn_title": "引用此消息发送给目标智能体",
+ "chat.quote_btn": "引用",
+ "chat.quote_from": "引用自 @{name}:",
+ "chat.quote_remove_title": "移除引用",
+ "chat.quote_files_label": "附带文件(可用 read_file 直接读取):",
"chat.attach_still_uploading": "附件仍在上传中,请稍候再发送。",
"chat.create_conv_failed": "创建对话失败",
"chat.create_conv_failed_with_reason": "创建对话失败:{reason}",
diff --git a/src/renderer/modules/conversation.js b/src/renderer/modules/conversation.js
index 71bad1bc..4cbf138b 100644
--- a/src/renderer/modules/conversation.js
+++ b/src/renderer/modules/conversation.js
@@ -197,6 +197,13 @@ function _saveRecipientMap() {
try { localStorage.setItem(_RECIPIENT_LS_KEY, JSON.stringify(_recipientByCid)); } catch (_) {}
}
+// Quote-reply state (per-cid, in-memory). Declared early so the
+// DOMContentLoaded init branch below — which may invoke _renderQuotePreview
+// synchronously when the document is already loaded — doesn't hit a TDZ on
+// the binding. The helper functions live further down with the rest of the
+// quote infrastructure (_setQuote / _getQuote / _clearQuote / _renderQuotePreview).
+const _quoteByCid = new Map(); // cid → { fromActor, fromName, msgId, text, produced[] } | undefined
+
function _normRecipient(next) {
if (!next || (next.kind !== 'commander' && next.kind !== 'agent')) return null;
if (next.kind === 'commander') return { ..._COMMANDER };
@@ -291,16 +298,24 @@ function onEnterConversationView() {
// loadConversationHistory is intentionally skipped). Without this hook,
// the rail would keep displaying the previous cid's plan content.
if (window.PlanRail) window.PlanRail.bind(currentCid || null);
+ // Quote preview is per-cid; rerender so a quote captured in another conv
+ // doesn't bleed into this one (and a quote left in this conv reappears
+ // when the user navigates back).
+ _renderQuotePreview();
}
// Called by queue-draft.js::_forgetConvLocal when a conv is deleted so we
// don't accumulate dead entries in localStorage forever.
function _forgetCidRecipient(cid) {
- if (!cid || !_recipientByCid[cid]) return;
- delete _recipientByCid[cid];
- _saveRecipientMap();
+ if (!cid) return;
+ if (_recipientByCid[cid]) {
+ delete _recipientByCid[cid];
+ _saveRecipientMap();
+ }
_latestInFlight.delete(cid);
_lastInteractiveTurnAgent.delete(cid);
+ // Drop any pending quote for the deleted conv (memory only — no localStorage).
+ _quoteByCid.delete(cid);
}
// ─── Auto-recipient: follow the interactive agent on plan dispatch ───────
@@ -474,17 +489,23 @@ function applyRecipientPrefix(raw, target) {
}
if (!display) display = r.name || r.id;
const tag = '@' + String(display);
- return tag + ' ' + text;
+ // When the raw body starts with a blockquote (e.g. the quote-reply prefix
+ // injected by applyQuotePrefix), use a newline separator so the @-mention
+ // ends up on its own line — markdown only treats `>` as a blockquote when
+ // it sits at column 0, and `@AgentB > ...` on one line collapses the
+ // blockquote into plain prose. Plain-text bodies keep the original space.
+ const sep = /^>/.test(text) ? '\n' : ' ';
+ return tag + sep + text;
}
if (typeof window !== 'undefined') {
- const initChip = () => _renderRecipientChip();
+ const initChip = () => { _renderRecipientChip(); _renderQuotePreview(); };
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initChip, { once: true });
} else {
initChip();
}
- window.addEventListener('i18n-change', () => _renderRecipientChip());
+ window.addEventListener('i18n-change', () => { _renderRecipientChip(); _renderQuotePreview(); });
}
// ─── Group-chat translation layer ─────────────────────────────────────────
@@ -1398,6 +1419,14 @@ function appendChatMessage(message, autoScroll = true, opts = {}) {
if (message._msg_id) msgDiv.dataset.msgId = String(message._msg_id);
if (message._from) msgDiv.dataset.fromActor = String(message._from);
msgDiv.dataset.ts = String(_msTs(message.time));
+ // Stash chip-tracked produced paths on the DOM so the 引用 handler can
+ // attach them to the quote payload without plumbing message into every
+ // _attachBubbleArchiveBtn call site. Only chip-tracked files belong here
+ // (write_file / edit_file / markdown_to_pdf / html_to_pdf / generate_image);
+ // bash scratch is intentionally outside this set.
+ if (Array.isArray(message.produced) && message.produced.length) {
+ msgDiv.dataset.produced = JSON.stringify(message.produced);
+ }
_insertByTimestamp(container, msgDiv);
if (!isHtmlSnippet && typeof typesetMath === 'function') {
const md = msgDiv.querySelector('.markdown-body');
@@ -1524,6 +1553,96 @@ function _renderPersistedProcess(msgDiv, items, { expanded = false } = {}) {
bubble.insertBefore(details, bubble.firstChild);
}
+// ─── Quote-reply (per-cid) ───────────────────────────────────────────────
+// Feishu-style: clicking 引用 on an assistant bubble captures its text +
+// chip-tracked produced files into a per-cid payload. The payload renders as
+// a preview block above the textarea (with × to drop), survives conv switch
+// (in-memory, not localStorage — drafts are ephemeral), and is prepended as
+// a markdown blockquote when the user finally hits send. Routing reuses the
+// existing 给:picker — quote does NOT change the recipient.
+//
+// Why dataset-driven: produced[] sits on the message object during render but
+// the bubble action row only sees `msgDiv` + a getContent closure. Putting
+// produced on `msgDiv.dataset.produced` (set in appendChatMessage and the
+// stream-finalize path) lets the quote handler stay zero-arg without
+// plumbing message into every _attachBubbleArchiveBtn call site.
+//
+// `_quoteByCid` itself is declared early (above `_recipientByCid`'s neighbour
+// block) so the DOMContentLoaded init can call _renderQuotePreview before
+// this section evaluates without hitting a TDZ.
+
+function _setQuote(cid, payload) {
+ if (!cid) return;
+ if (!payload) _quoteByCid.delete(cid);
+ else _quoteByCid.set(cid, payload);
+ if (cid === currentCid) _renderQuotePreview();
+}
+function _getQuote(cid) { return cid ? _quoteByCid.get(cid) || null : null; }
+function _clearQuote(cid) { _setQuote(cid, null); }
+
+// Render (or hide) the preview block for the active cid. Idempotent — safe
+// to call on conv switch / i18n change / quote set / quote clear.
+function _renderQuotePreview() {
+ const wrap = document.getElementById('chat-quote-preview');
+ if (!wrap) return;
+ const q = _getQuote(currentCid);
+ if (!q) {
+ wrap.style.display = 'none';
+ wrap.innerHTML = '';
+ return;
+ }
+ // fromName resolved at render time (not at click time) so renames after
+ // capture flow through naturally; fall back to the click-time snapshot
+ // when the actor was deleted between capture and render.
+ const liveName = q.fromActor === 'commander'
+ ? (t('chat.from_commander') || '指挥官')
+ : _groupActorLabel(q.fromActor);
+ const fromName = liveName || q.fromName || (t('chat.from_agent_unknown') || '智能体');
+ const trunc = String(q.text || '');
+ const fileChips = (q.produced || []).map((p) => {
+ const base = String(p || '').split(/[\\/]/).pop() || p;
+ return `<span class="chat-quote-file" title="${escapeHtml(p)}">📎 ${escapeHtml(base)}</span>`;
+ }).join('');
+ wrap.innerHTML = `
+ <div class="chat-quote-header">
+ <span class="chat-quote-from">${escapeHtml(t('chat.quote_from', { name: fromName }))}</span>
+ <button type="button" class="chat-quote-close" title="${escapeHtml(t('chat.quote_remove_title'))}">×</button>
+ </div>
+ <div class="chat-quote-body">${escapeHtml(trunc)}</div>
+ ${fileChips ? `<div class="chat-quote-files">${fileChips}</div>` : ''}
+ `;
+ wrap.style.display = '';
+ const closeBtn = wrap.querySelector('.chat-quote-close');
+ if (closeBtn) closeBtn.addEventListener('click', () => _clearQuote(currentCid));
+}
+
+// Prepend the active quote as a markdown blockquote so the receiving agent
+// sees it as inbound message body (no special parsing needed). File paths
+// land as absolute paths — same shape `produced[]` already stores; the agent
+// can `read_file('<abs>')` directly without any cwd assumptions.
+//
+// **No `引用自 @<sender>` attribution line in the persisted text.** Earlier
+// versions prefixed the block with `> **引用自 @<name>:**` for context, but
+// `bus.ts::resolveRecipients` scans the message body for `@<token>` mentions
+// (including aliases `@指挥官` / `@user`) and union-routes to every match —
+// so the attribution `@<sender>` was being parsed as a second recipient,
+// re-triggering the original agent / commander on every quote-forward. The
+// sender's name is still shown in the input-area preview (renderer-only,
+// never serialised), which is enough context for the user pressing send.
+function applyQuotePrefix(raw, target) {
+ if (target !== 'conversation') return raw;
+ const q = _getQuote(currentCid);
+ if (!q) return raw;
+ const bodyLines = String(q.text || '').split('\n').map((l) => `> ${l}`).join('\n');
+ let block = bodyLines;
+ if (Array.isArray(q.produced) && q.produced.length) {
+ const filesHead = t('chat.quote_files_label');
+ const fileLines = q.produced.map((p) => `> - \`${p}\``).join('\n');
+ block += `\n>\n> ${filesHead}\n${fileLines}`;
+ }
+ return raw ? `${block}\n\n${raw}` : block;
+}
+
// Attach a small "存档" button next to the time in the chat-meta row. Kept
// outside the bubble so it never overlaps bubble content. `getContent` is a
// callback so it can return the latest text after streaming completes.
@@ -1544,9 +1663,31 @@ function _attachBubbleArchiveBtn(msgDiv, getContent) {
actions.innerHTML = `
<button class="bubble-archive-btn" title="${escapeHtml(t('chat.archive_btn_title'))}">${escapeHtml(t('chat.archive_btn'))}</button>
<button class="bubble-copy-btn" title="${escapeHtml(t('chat.copy_btn_title'))}">${escapeHtml(t('chat.copy_btn'))}</button>
+ <button class="bubble-quote-btn" title="${escapeHtml(t('chat.quote_btn_title'))}">${escapeHtml(t('chat.quote_btn'))}</button>
`;
const btn = actions.querySelector('.bubble-archive-btn');
const copyBtn = actions.querySelector('.bubble-copy-btn');
+ const quoteBtn = actions.querySelector('.bubble-quote-btn');
+ quoteBtn.addEventListener('click', (e) => {
+ e.stopPropagation();
+ const text = typeof getContent === 'function' ? (getContent() || '') : '';
+ if (!text.trim()) return;
+ const fromActor = msgDiv.dataset.fromActor || '';
+ const msgId = msgDiv.dataset.msgId || '';
+ let produced = [];
+ try {
+ const raw = msgDiv.dataset.produced || '';
+ if (raw) produced = JSON.parse(raw);
+ if (!Array.isArray(produced)) produced = [];
+ } catch (_) { produced = []; }
+ const fromName = fromActor === 'commander'
+ ? (t('chat.from_commander') || '指挥官')
+ : (_groupActorLabel(fromActor) || '');
+ _setQuote(currentCid, { fromActor, fromName, msgId, text, produced });
+ const input = document.getElementById('chat-input');
+ if (input) { input.focus(); }
+ if (window.Monitor) Monitor.click('bubble_quote', { cid: currentCid, has_files: produced.length > 0 });
+ });
copyBtn.addEventListener('click', async (e) => {
e.stopPropagation();
const text = typeof getContent === 'function' ? (getContent() || '') : '';
@@ -1706,7 +1847,10 @@ async function handleNewChatSubmit() {
async function handleChatSubmit() {
const input = document.getElementById('chat-input');
const raw = (input.value || '').trim();
- if (!raw || !currentCid) return;
+ if (!currentCid) return;
+ // A bare quote with no extra text is a legitimate "look at this" forward;
+ // only reject when both the textarea AND the quote are empty.
+ if (!raw && !_getQuote(currentCid)) return;
if (!ensureModelConfigured()) return;
const cid = currentCid;
const skill = _chatSkill['conversation'] || '';
@@ -1721,19 +1865,26 @@ async function handleChatSubmit() {
// If this conversation is already streaming OR has queued items waiting,
// enqueue the new message instead of sending it now. Keep the raw text +
// skill so the prefix is applied fresh when it's actually sent.
+ // Quote is baked into the queued content here (rather than carried as a
+ // sidecar field on the queue entry) — by the time the queue dispatches,
+ // the user may have already cleared/replaced the quote in the preview;
+ // capture-at-enqueue keeps each queued message tied to the quote that was
+ // visible when the user pressed send.
if (isConvPending(cid) || (messageQueues.get(cid) || []).length) {
if (attachments.length) {
await uiAlert(t('chat.attach_queue_blocked'));
return;
}
- enqueueMessage(cid, raw, skill);
+ enqueueMessage(cid, applyQuotePrefix(raw, 'conversation'), skill);
+ _clearQuote(cid);
input.value = '';
autoGrow(input, 200);
_clearDraft(cid);
return;
}
- const content = applyRecipientPrefix(transformWithSkill(raw, skill), 'conversation');
+ const content = applyRecipientPrefix(applyQuotePrefix(transformWithSkill(raw, skill), 'conversation'), 'conversation');
+ _clearQuote(cid);
input.value = '';
autoGrow(input, 200);
_clearDraft(cid);
@@ -2878,6 +3029,10 @@ function _finalizeActorPlaceholder(ph, gm, cid, archive) {
_hydrateMessageProducedChips(ph);
}
}
+ // Mirror dataset.produced so the 引用 button can read it (same contract
+ // as appendChatMessage above; without this, post-stream finalize would
+ // leave the chip row in place but the quote payload would carry no files).
+ ph.dataset.produced = JSON.stringify(gm.produced);
}
// Created-agent chip (commander quick-create) — same actions row.
diff --git a/src/renderer/style.css b/src/renderer/style.css
index ad4aebdb..1acb6797 100644
--- a/src/renderer/style.css
+++ b/src/renderer/style.css
@@ -1829,6 +1829,78 @@ body.model-not-configured .main-content { flex-direction: column; }
to { transform: rotate(360deg); }
}
+/* Quote-reply preview — a Feishu-style block that sits above the textarea
+ inside .chat-input-area when the user clicks 引用 on an assistant bubble.
+ The block is a normal flex-column child, so adding it just pushes the
+ textarea down; the input area visually grows to fit. */
+.chat-quote-preview {
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+ padding: 6px 10px 8px;
+ margin-top: 2px;
+ background: rgba(37, 99, 235, 0.04);
+ border-left: 3px solid rgba(37, 99, 235, 0.45);
+ border-radius: 4px;
+ font-size: 12.5px;
+ color: #475569;
+}
+.chat-quote-preview .chat-quote-header {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+}
+.chat-quote-preview .chat-quote-from {
+ flex: 1 1 auto;
+ font-weight: 500;
+ color: #2563eb;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.chat-quote-preview .chat-quote-close {
+ flex: 0 0 auto;
+ cursor: pointer;
+ background: transparent;
+ border: none;
+ color: #94a3b8;
+ font-size: 16px;
+ line-height: 1;
+ padding: 0 4px;
+}
+.chat-quote-preview .chat-quote-close:hover { color: #ef4444; }
+.chat-quote-preview .chat-quote-body {
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 3;
+ overflow: hidden;
+ white-space: pre-wrap;
+ word-break: break-word;
+ color: #475569;
+ line-height: 1.45;
+}
+.chat-quote-preview .chat-quote-files {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 4px 6px;
+ margin-top: 2px;
+}
+.chat-quote-preview .chat-quote-file {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ padding: 2px 6px;
+ background: #fff;
+ border: 1px solid var(--border);
+ border-radius: 8px;
+ font-size: 11.5px;
+ color: #475569;
+ max-width: 220px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
/* "+" button — sits left of the textarea inside .chat-input-area */
.chat-attach-btn {
flex-shrink: 0;
@@ -2533,7 +2605,8 @@ body.model-not-configured .main-content { flex-direction: column; }
order: -1;
}
.bubble-archive-btn,
-.bubble-copy-btn {
+.bubble-copy-btn,
+.bubble-quote-btn {
border: 1px solid var(--border);
background: #fff;
color: var(--muted);
@@ -2546,14 +2619,16 @@ body.model-not-configured .main-content { flex-direction: column; }
font-family: inherit;
}
.bubble-archive-btn:hover,
-.bubble-copy-btn:hover {
+.bubble-copy-btn:hover,
+.bubble-quote-btn:hover {
color: var(--primary);
border-color: rgba(37, 99, 235, 0.25);
background: rgba(37, 99, 235, 0.04);
box-shadow: 0 2px 6px rgba(37, 99, 235, 0.15);
}
.bubble-archive-btn:disabled,
-.bubble-copy-btn:disabled {
+.bubble-copy-btn:disabled,
+.bubble-quote-btn:disabled {
cursor: default;
opacity: 0.7;
}
@@ -2728,6 +2803,22 @@ body.model-not-configured .main-content { flex-direction: column; }
overflow-wrap: anywhere;
}
+/* Forward-quote blockquotes in user bubbles — clamp to 2 lines to keep the
+ sent-message bubble compact. The receiving agent still gets the full text
+ (the markdown is sent intact via bus.enqueue); this only affects the
+ sender's view of their own outgoing bubble. Why user bubbles only:
+ `applyQuotePrefix` is the sole producer of these blockquotes, and it
+ only runs on the renderer's send path → the result always lands in a
+ user-role bubble. Assistant blockquotes (citations, web fetches, etc.)
+ stay unclamped so the model's quoted content remains fully readable. */
+.chat-message.user .chat-bubble blockquote {
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 2;
+ line-clamp: 2;
+ overflow: hidden;
+}
+
/* 其它易撑破气泡的块级内容(表格、长 URL/图片)也约束到气泡宽度以内。 */
.chat-bubble .markdown-body table { display: block; max-width: 100%; overflow-x: auto; }
.chat-bubble .markdown-body img { max-width: 100%; height: auto; }