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
Remove conversation sampling remnants
wytbad9db06caf9
diff --git a/src/main/features/local_agents/backends/acp-diagnostics.ts b/src/main/features/local_agents/backends/acp-diagnostics.tsindex 8f63f449..9cc7fe7a 100644--- a/src/main/features/local_agents/backends/acp-diagnostics.ts+++ b/src/main/features/local_agents/backends/acp-diagnostics.ts@@ -1,5 +1,5 @@/** Content-free ACP observations, independent of tool-result presentation.- * One snapshot per dispatch, consumed by local logs and task-turn sampling.+ * One bounded snapshot per dispatch is emitted into the local process log.* Tool IDs stay private and bounded; missing/overflowed IDs make counts partial.* A progress update is not evidence that a tool completed.*/diff --git a/src/main/features/local_agents/bridge.ts b/src/main/features/local_agents/bridge.tsindex 01b47061..6a41cddf 100644--- a/src/main/features/local_agents/bridge.ts+++ b/src/main/features/local_agents/bridge.ts@@ -341,7 +341,7 @@ function _buildMethods(if (capabilities.has('browser')) {// CLI runtimes may issue parallel calls; never race a page mutation with- // another observation/action. Capture the task turn once, not per call.+ // another observation/action. Reuse one browser scope for the active run.let signal: AbortSignal | undefined;const browser = buildConversationBrowserTool(opts.uid, opts.cid,() => isBridgeActive() && !signal?.aborted && getActiveUserId() === opts.uid);diff --git a/src/main/index.ts b/src/main/index.tsindex 2323ef0d..19bca970 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -242,7 +242,7 @@ function setTaskNotificationBadgeCount(count: number): void {app.setBadgeCount(normalized);}-let taskTurnRendererReady = false;+let mainRendererReady = false;// Renderer channels replay what the window could not take while loading; the// owner-scoped ones never hand one account's rows to the next (see@@ -251,7 +251,7 @@ let taskTurnRendererReady = false;const rendererChannels: RendererChannel[] = [];const rendererChannelDeps: RendererChannelDeps = {broadcast: (channel, payload) => ipc.broadcastToRenderer(channel, payload),- rendererReady: () => taskTurnRendererReady,+ rendererReady: () => mainRendererReady,activeUserId: () => (users.hasActiveUser() ? users.getActiveUserId() : null),};function rendererChannel(channel: string, options: RendererChannelOptions): RendererChannel {@@ -299,17 +299,17 @@ function createWindow(): BrowserWindow {// Embedded previews also trigger did-start-loading, but only a new main// document replaces our subscribers and later emits did-finish-load.if (!isMainFrame || isInPlace) return;- taskTurnRendererReady = false;+ mainRendererReady = false;});win.webContents.on('did-finish-load', () => {- taskTurnRendererReady = true;+ mainRendererReady = true;for (const channel of rendererChannels) channel.flush();});win.webContents.on('render-process-gone', () => {- taskTurnRendererReady = false;+ mainRendererReady = false;});win.on('closed', () => {- taskTurnRendererReady = false;+ mainRendererReady = false;});// Block HTML <title> from populating the native titlebar — we want adiff --git a/src/renderer/modules/conversation.js b/src/renderer/modules/conversation.jsindex 90c1274b..987da600 100644--- a/src/renderer/modules/conversation.js+++ b/src/renderer/modules/conversation.js@@ -11419,322 +11419,6 @@ function _observerShouldDeferCleanup(cid, allowWithController) {return !!allowWithController && _convChatCtrls.has(cid);}-const _taskTurnRuns = new Map();-const _TASK_TURN_PROCESS_MAX_ITEMS = 120;-const _TASK_TURN_PROCESS_MAX_CHARS = 500;--function _taskTurnRunId() {- try {- if (crypto && typeof crypto.randomUUID === 'function') return crypto.randomUUID();- } catch (_) { /* ignore */ }- return `run_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 12)}`;-}--function _taskTurnStart(cid, content, extra, startedAt, context = {}) {- if (!cid) return;- const attachments = Array.isArray(extra && extra.attachments) ? extra.attachments.map(String) : [];- const ts = Math.round(startedAt || Date.now());- _taskTurnRuns.set(cid, {- cid,- runId: _taskTurnRunId(),- userText: String(content || ''),- startedAtMs: ts,- messages: [{- role: 'user',- actor: 'user',- text: String(content || ''),- created_at_ms: ts,- attachment_count: attachments.length,- attachment_names: attachments,- initial: true,- }],- messageKeys: new Set(['initial_user']),- initialUserEventMatched: false,- assistantMessages: [],- agentIds: [],- agentNameById: {},- skillIds: [],- skillNameById: {},- toolNames: [],- toolCallCount: 0,- processEvents: [],- processKeys: new Set(),- attachmentNames: attachments,- attachmentCount: attachments.length,- errorMessage: '',- errorType: '',- errorStage: '',- partial: false,- });-}--function _taskTurnRun(cid) {- return _taskTurnRuns.get(cid) || null;-}--function _taskTurnAgentName(actorId, cid) {- const id = String(actorId || '').trim();- if (!id || id === 'user') return '';- if (id === 'commander') {- return (typeof t === 'function') ? t('chat.from_commander') : 'Commander';- }- if (typeof _agentsCache !== 'undefined' && Array.isArray(_agentsCache)) {- const found = _agentsCache.find((a) => a && a.agent_id === id);- if (found && found.name) return String(found.name);- }- const cached = _groupMembersCache.get(cid || currentCid);- if (cached) {- const found = cached.find((a) => a && a.id === id);- if (found && found.name) return String(found.name);- }- return '';-}--function _taskTurnSkillName(skillId) {- const id = String(skillId || '').trim();- if (!id) return '';- const skills = _skillsForDisplayNameRewrite();- const found = skills.find((s) => s && s.id === id);- return found && found.name ? String(found.name) : '';-}--function _taskTurnAddAgent(run, actorId) {- const id = String(actorId || '').trim();- if (!id || id === 'user') return;- if (!run.agentIds.includes(id)) run.agentIds.push(id);- const name = _taskTurnAgentName(id, run.cid);- if (name) run.agentNameById[id] = name;-}--function _taskTurnAddSkill(run, skillId, skillName) {- const id = String(skillId || '').trim();- if (!id) return;- if (!run.skillIds.includes(id)) run.skillIds.push(id);- const name = String(skillName || _taskTurnSkillName(id) || '').trim();- if (name) run.skillNameById[id] = name;-}--function _taskTurnAddTool(run, name) {- const n = String(name || '').trim().slice(0, 128);- if (!n) return;- if (!run.toolNames.includes(n)) run.toolNames.push(n);-}--function _taskTurnAddProcessLine(run, evData, lineText, evt) {- if (!run || !lineText || run.processEvents.length >= _TASK_TURN_PROCESS_MAX_ITEMS) return;- const text = _processLineText(lineText).replace(/\s+/g, ' ').trim();- if (!text) return;- const key = [- evData && evData.actor || '',- evt && evt.stream || '',- text.slice(0, 180),- ].join(':');- if (key && run.processKeys.has(key)) return;- if (key) run.processKeys.add(key);- const actor = String(evData && evData.actor || '').slice(0, 128);- run.processEvents.push({- index: run.processEvents.length,- actor: actor,- actor_name: _taskTurnAgentName(actor, run.cid),- kind: _eventProcessKind(evt, lineText) || _processKindOf(lineText) || '',- text: text.length > _TASK_TURN_PROCESS_MAX_CHARS ? text.slice(0, _TASK_TURN_PROCESS_MAX_CHARS - 1) + '…' : text,- created_at_ms: Date.now(),- });-}--function _taskTurnMessageKey(role, gm, fallbackText) {- if (gm && gm.id) return `${role}:id:${gm.id}`;- return `${role}:${gm && gm.from ? gm.from : ''}:${gm && gm.ts ? gm.ts : ''}:${String(fallbackText || '').slice(0, 120)}`;-}--function _taskTurnAddMessage(run, msg) {- if (!run || !msg) return;- const role = msg.role === 'user' ? 'user' : 'assistant';- const text = String(msg.text || '');- const hasSkillCard = role === 'assistant' && msg.has_skill_card === true;- if (!text.trim() && !hasSkillCard) return;- const key = msg.key || `${role}:${msg.actor || ''}:${msg.created_at_ms || ''}:${text.slice(0, 120)}`;- if (run.messageKeys.has(key)) return;- run.messageKeys.add(key);- const actor = String(msg.actor || (role === 'user' ? 'user' : ''));- const actorName = role === 'assistant'- ? String(msg.actor_name || _taskTurnAgentName(actor, run.cid) || '').trim()- : '';- run.messages.push({- role,- actor,- ...(actorName ? { actor_name: actorName } : {}),- text,- ...(hasSkillCard ? { has_skill_card: true } : {}),- created_at_ms: Math.max(0, Math.round(Number(msg.created_at_ms) || Date.now())),- ...(msg.message_id ? { message_id: String(msg.message_id).slice(0, 64) } : {}),- ...(msg.partial ? { partial: true } : {}),- ...(msg.attachment_count ? { attachment_count: msg.attachment_count } : {}),- ...(Array.isArray(msg.attachment_names) && msg.attachment_names.length ? { attachment_names: msg.attachment_names.map(String) } : {}),- });-}--function _taskTurnSampleMessage(msg) {- const role = msg && msg.role === 'user' ? 'user' : 'assistant';- const rawText = String(msg && msg.text || '');- let text = rawText;- if (role === 'user') {- try {- text = _stripUserStructuralBlocksForDisplay(rawText);- } catch (_) {- text = rawText;- }- }- // Sampling-only host description. Keep card contents/identity out, and- // leave the original prose untouched for runtime outcome classification.- if (role === 'assistant' && msg.has_skill_card === true) {- text = text.trim() ? `${text}\n\n[Skill card]` : '[Skill card]';- }- const actorName = role === 'assistant'- ? String(msg && msg.actor_name || '').trim().slice(0, 128)- : '';- return {- role,- actor: String(msg && msg.actor || (role === 'user' ? 'user' : '')).slice(0, 128),- ...(actorName ? { actor_name: actorName } : {}),- text,- created_at_ms: Math.max(0, Math.round(Number(msg && msg.created_at_ms) || 0)),- ...(msg && msg.message_id ? { message_id: String(msg.message_id).slice(0, 64) } : {}),- ...(msg && msg.partial ? { partial: true } : {}),- ...(msg && msg.attachment_count ? { attachment_count: msg.attachment_count } : {}),- ...(msg && Array.isArray(msg.attachment_names) && msg.attachment_names.length- ? { attachment_names: msg.attachment_names.map(String) }- : {}),- };-}--function _taskTurnRecordProcess(run, evData) {- const processData = evData && evData.data ? evData.data : {};- let processLine = '';- let processEvt = null;- try {- if (processData.type === 'progress' && processData.text) {- processLine = String(processData.text || '');- } else if (processData.type === 'event' && processData.event) {- processEvt = processData.event;- // Host-generated ACP summaries are sampled without adding a user-facing- // process row. Ordinary CLI diagnostics remain excluded from sampling.- const acpSummary = processEvt.stream === 'cli'- && processEvt.data?.type === 'log' && processEvt.data?.source === 'acp-diagnostics';- processLine = acpSummary ? String(processEvt.data.message || '')- : processEvt.stream === 'command_output' ? '' : (_formatEventLine(processEvt) || '');- }- } catch (_) {- processLine = '';- }- if (processLine) _taskTurnAddProcessLine(run, evData, processLine, processEvt);- const payload = processData && processData.event && typeof processData.event === 'object'- ? processData.event- : processData;- const stream = String(payload.stream || '');- const data = payload.data && typeof payload.data === 'object' ? payload.data : {};- const cliType = stream === 'cli' ? String(data.type || '').toLowerCase() : '';- const phase = String(data.phase || data.status || '').toLowerCase();- const isTool = stream === 'tool' || cliType === 'tool-event';- if (!isTool) return;- _taskTurnAddSkill(run, data.skill_id || data.skillId, data.skill_name || data.skillName);- if (phase && !/^(start|running|request|call|begin)$/.test(phase)) return;- run.toolCallCount += 1;- _taskTurnAddTool(run, data.name || data.tool || data.tool_name || data.command || payload.name);-}--function _taskTurnRecordStreamEvent(cid, ev) {- const run = _taskTurnRun(cid);- if (!run || !ev) return;- if (ev.type === 'final' && ev.text) {- const text = String(ev.text || '');- run.assistantMessages.push({ actor: '', text });- _taskTurnAddMessage(run, {- role: 'assistant',- actor: '',- text,- created_at_ms: Date.now(),- key: `assistant:final:${text.slice(0, 120)}`,- });- return;- }- if (ev.type === 'error') {- run.errorMessage = String(ev.text || '');- run.errorType = ev.aborted ? 'abort' : 'model_output';- run.errorStage = 'stream_event';- return;- }- const inner = ev.event || {};- const evData = inner.stream === 'group' ? inner.data : null;- if (!evData || typeof evData !== 'object') return;- if (evData.type === 'message' && evData.msg && !evData.msg.dispatch) {- const gm = evData.msg;- const text = String(gm.text || '');- const role = gm.from === 'user' ? 'user' : 'assistant';- const actor = String(gm.from || evData.actor || (role === 'user' ? 'user' : ''));- if (role === 'user') {- if (!run.initialUserEventMatched && text === run.userText) {- run.initialUserEventMatched = true;- const first = run.messages.find((m) => m.initial);- if (first) {- first.created_at_ms = Math.max(0, Math.round(Number(gm.ts ? Date.parse(gm.ts) : 0) || first.created_at_ms || run.startedAtMs));- if (gm.id) first.message_id = String(gm.id).slice(0, 64);- }- return;- }- _taskTurnAddMessage(run, {- role: 'user',- actor: 'user',- text,- created_at_ms: gm.ts ? Date.parse(gm.ts) : Date.now(),- message_id: gm.id || '',- key: _taskTurnMessageKey('user', gm, text),- attachment_count: Array.isArray(gm.attachments) ? gm.attachments.length : 0,- attachment_names: Array.isArray(gm.attachments) ? gm.attachments : [],- });- } else if (text.trim()) {- _taskTurnAddAgent(run, actor);- run.assistantMessages.push({ actor, text });- _taskTurnAddMessage(run, {- role: 'assistant',- actor,- text,- created_at_ms: gm.ts ? Date.parse(gm.ts) : Date.now(),- message_id: gm.id || '',- key: _taskTurnMessageKey('assistant', gm, text),- partial: !!evData.partial,- });- }- return;- }- if (evData.type === 'process') {- const processData = evData.data && typeof evData.data === 'object' ? evData.data : {};- const processEvent = processData.event && typeof processData.event === 'object'- ? processData.event- : null;- if (processData.type === 'delta') return;- _taskTurnAddAgent(run, evData.actor);- _taskTurnRecordProcess(run, evData);- return;- }- if (evData.type === 'artifact_created') {- _taskTurnAddAgent(run, evData.actor);- }-}--function _taskTurnVisibleModelFailure(text) {- const s = String(text || '');- if (!s) return false;- return /模型调用失败|Model (?:exceeded|failed|errored)|GenerateContentRequest|INVALID_ARGUMENT|Bad Request|ProviderError/i.test(s);-}--function _taskTurnFinish(cid, opts = {}) {- const run = _taskTurnRun(cid);- if (!run) return;- _taskTurnRuns.delete(cid);- void opts;-}-function _notifyAgentRunFinished(agentId, payload = {}) {const id = String(agentId || '');if (!id || typeof window === 'undefined') return;@@ -11844,14 +11528,6 @@ function _makeConvChatController(cid, options = {}) {if (state) state.aborted = true;// `onDone` is the single owner of task settlement.},- onError(text, _msgEl, id) {- const run = _taskTurnRun(id);- if (run) {- run.errorMessage = String(text || '');- run.errorType = 'model_output';- run.errorStage = 'stream';- }- },onDone(msgEl, id, result = {}) {// Restore a rejected send before settlement clears its snapshot.if (_convChatCtrls.get(id) === self && options.restoreComposerOnFailure && result.accepted === false && result.errored && !result.aborted@@ -11915,8 +11591,7 @@ async function sendInConversation(cid, content, extra, options = {}) {// observer stream renders the bubble and the row. Same transport as the// composer's busy branch in handleChatSubmit; the renderer-local queue// is retired. No controller: queued input starts a new execution stream- // after the current one ends, so it must not be merged into the active- // task-turn sample.+ // after the current one ends, so it must keep an independent lifecycle.try {const res = await apiFetch(`/api/conversations/${encodeURIComponent(cid)}/send`, {method: 'POST',diff --git a/test/renderer/conversation-sidebar.test.ts b/test/renderer/conversation-sidebar.test.tsindex 3492e295..007bd384 100644--- a/test/renderer/conversation-sidebar.test.ts+++ b/test/renderer/conversation-sidebar.test.ts@@ -9066,7 +9066,6 @@ describe('conversation controller settlement', () => {hooks = config.hooks;return { abort() {} };};- context._taskTurnFinish = () => {};context._finishStreamingMsg = (cid: string) => cleanups.push(cid);context._scheduleHistoryReconcileAfterStream = () => {};context._updateConvSendUI = () => {};@@ -9317,16 +9316,14 @@ describe('conversation controller settlement', () => {context._streamingStopActivity(msg);});- it('cleans an aborted send from onDone without locally finalizing bus-owned sampling', () => {+ it('cleans an aborted send from onDone without locally finalizing bus-owned lifecycle state', () => {const context = loadConversationRenderer();- const finishes: any[] = [];const cleanups: string[] = [];let hooks: any = null;context.createChatController = (config: any) => {hooks = config.hooks;return { abort() {} };};- context._taskTurnFinish = (...args: any[]) => finishes.push(args);context._finishStreamingMsg = (cid: string) => cleanups.push(cid);context._updateConvSendUI = () => {};context._updateConvSidebarBadge = () => {};@@ -9348,15 +9345,12 @@ describe('conversation controller settlement', () => {expect(browserTurnStarts).toEqual(['c1']);expect(context.pendingConvs.get('c1').controller).toBe(ctrl);hooks.onAbort(msg, 'c1');- expect(finishes).toHaveLength(0);expect(cleanups).toHaveLength(0);hooks.onDone(msg, 'c1', { started: true, aborted: true, errored: false });- expect(finishes).toHaveLength(0);expect(cleanups).toEqual(['c1']);hooks.onDone(msg, 'c1', { started: true, aborted: true, errored: false });- expect(finishes).toHaveLength(0);expect(cleanups).toEqual(['c1']);});@@ -9493,7 +9487,6 @@ describe('conversation controller settlement', () => {])('returns the terminal chat result from controller state %#', async (terminal, expected) => {const context = loadConversationRenderer();context.performance = performance;- context._taskTurnStart = () => {};context._makeConvChatController = (_cid: string, options: any) => ({abort() {},async send() {