π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(hetero): show the CLI model and usage while streaming (#16963)
Arvin Xub2436817c8ac
diff --git a/.agents/skills/agent-testing/references/probe-mock-patterns.md b/.agents/skills/agent-testing/references/probe-mock-patterns.mdindex ed5377af05b..489442ab381 100644--- a/.agents/skills/agent-testing/references/probe-mock-patterns.md+++ b/.agents/skills/agent-testing/references/probe-mock-patterns.md@@ -543,10 +543,27 @@the shell env). This authenticates BOTH the renderer (BackendProxyProtocolManager injects thesame token) and any main-process fetch, so the whole app comes up signed in. Revert with`git checkout --` + `grep -rn AGENT-TEST` afterwards, and never echo the token.+- **Works β alternative, no source edit, when you can approve a browser prompt**: seed a+ PRISTINE profile so the app takes the signed-out path and renders the real login screen+ instead of hanging:+ ```bash+ mkdir -p /tmp/empty-golden+ LOBE_GOLDEN_PROFILE=/tmp/empty-golden ./electron-dev.sh start <id>+ ```+ Drive onboarding (`εΌε§` β `δΈδΈζ₯` Γ2 β `η»ε½ LobeHub Cloud`). The device-code flow opens the+ browser and auto-approves against an existing app.lobehub.com session, giving the instance its+ OWN token β so it never rotates the one the user's resident app holds.+- **Why the blank shell has no login button**: the failed refresh leaves `isUserStateInit:false`+ (with `isLoaded:true, user:null`), and the desktop first-frame gate waits on it forever. Every+ route β `/`, `/desktop-onboarding` β renders empty. Reloading, soft-navving, and waiting all+ fail to resolve it, so it reads exactly like a Case-1 blank page.- **Gotcha**: a worktree installed with `pnpm install --ignore-scripts` has NO electron binary(`node_modules/.pnpm/electron@*/node_modules/electron/dist` missing). Fix with`cd apps/desktop && pnpm rebuild electron`. Also remember `apps/desktop` and `apps/cli` areNOT in the root pnpm workspace β install inside each.+- **Gotcha**: `electron-dev.sh restart <id>` keeps the userData dir, but a device-code session+ did NOT survive it β budget for one more login after any restart (e.g. when a main-process+ change forces one, see E9).### C5. β WORKS β main-process `logger.info` is invisible unless `DEBUG` is set@@ -561,3 +578,15 @@ session:')` line. In development `createLogger().info` routes to the `debug` pac`grep -oE "controllers:HeterogeneousAgentCtr INFO: [^']*" /tmp/lobe-electron-pool/instance-<id>.log`.Don't trust the hetero tracing dir for this β it is gated and the copied golden profile shipsSTALE trace sessions from months earlier that look like a fresh run.+### E9. Main-process code changes need a restart; Vite HMR only covers the renderer++- Adapters under `packages/heterogeneous-agents` run in the **main** process+ (JSONL framing + adapter + `toStreamEvent`). Editing one and reloading the+ renderer verifies nothing β the old adapter is still running.+- Prove which code each process has before trusting a run:+ ```bash+ # renderer: vite serves working-tree src (VITE_BASE + id)+ curl -s --noproxy '*' "http://127.0.0.1:<vitePort>/src/<path>.ts" | grep -c '<marker>'+ # main: rebuilt on start into the desktop dist bundle+ grep -c '<marker>' apps/desktop/dist/main/index.js+ ```diff --git a/packages/heterogeneous-agents/src/adapters/claudeCode.test.ts b/packages/heterogeneous-agents/src/adapters/claudeCode.test.tsindex 2dcbf104c27..b1518ddbd39 100644--- a/packages/heterogeneous-agents/src/adapters/claudeCode.test.ts+++ b/packages/heterogeneous-agents/src/adapters/claudeCode.test.ts@@ -18,6 +18,32 @@ describe('ClaudeCodeAdapter', () => {expect(adapter.sessionId).toBe('sess_123');});+ // `system init` beta-tags the id; every later event reports it clean. The+ // renderer stamps the assistant from this event, so the tag must not leak.+ it('strips the beta marker from the init model id', () => {+ const adapter = new ClaudeCodeAdapter();+ const events = adapter.adapt({+ model: 'claude-opus-4-8[1m]',+ session_id: 'sess_123',+ subtype: 'init',+ type: 'system',+ });+ expect(events[0].data.model).toBe('claude-opus-4-8');+ });++ // Only a TRAILING marker is a beta tag β a bracket anywhere else is part of+ // the id and must survive.+ it('leaves an id without a trailing marker untouched', () => {+ const adapter = new ClaudeCodeAdapter();+ const events = adapter.adapt({+ model: 'claude-opus[4]-8',+ session_id: 'sess_123',+ subtype: 'init',+ type: 'system',+ });+ expect(events[0].data.model).toBe('claude-opus[4]-8');+ });+it('emits visible_output_end before agent_runtime_end on success result', () => {const adapter = new ClaudeCodeAdapter();adapter.adapt({ subtype: 'init', type: 'system' });diff --git a/packages/heterogeneous-agents/src/adapters/claudeCode.ts b/packages/heterogeneous-agents/src/adapters/claudeCode.tsindex 1a219886d01..d7f70a94295 100644--- a/packages/heterogeneous-agents/src/adapters/claudeCode.ts+++ b/packages/heterogeneous-agents/src/adapters/claudeCode.ts@@ -107,6 +107,21 @@ const TASK_UPDATE_RESULT_PATTERN = /^Updated task #\d+/;*/const TASK_LIST_LINE_PATTERN = /^#(\d+) \[(pending|in_progress|completed)\] (.+)$/;+/**+ * `system init` tags the model id with a beta marker (`claude-opus-4-8[1m]`)+ * that no other event β and no model-bank entry β uses. Strip it so the id the+ * run opens with is the same canonical one `turn_metadata` later confirms;+ * otherwise the assistant renders the tagged id until the first turn ends.+ *+ * Sliced rather than matched: an unanchored `/\[[^\]]*\]$/` rescans from every+ * start offset, which is quadratic on a `[[[[β¦` input (CodeQL flags it).+ */+const stripModelBetaMarker = (model?: string) => {+ if (!model?.endsWith(']')) return model;+ const markerStart = model.lastIndexOf('[');+ return markerStart === -1 ? model : model.slice(0, markerStart);+};+/*** Tool name CC sees for the LobeHub-hosted MCP `ask_user_question` server.* Source of truth lives in `../askUser/constants.ts`; replicated here as a@@ -782,7 +797,7 @@ export class ClaudeCodeAdapter implements AgentEventAdapter {this.started = true;return [this.makeEvent('stream_start', {- model: raw.model,+ model: stripModelBetaMarker(raw.model),provider: 'claude-code',// The CC session id every message this run produces belongs to. A// change in this value across a topic means CC forked a new session.diff --git a/src/store/chat/slices/agentRun/actions/__tests__/heterogeneousAgentExecutor.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/heterogeneousAgentExecutor.test.tsindex a4bee456a69..2d797fa5c3b 100644--- a/src/store/chat/slices/agentRun/actions/__tests__/heterogeneousAgentExecutor.test.ts+++ b/src/store/chat/slices/agentRun/actions/__tests__/heterogeneousAgentExecutor.test.ts@@ -927,6 +927,64 @@ describe('heterogeneousAgentExecutor DB persistence', () => {expect(finalWrite![1].provider).toBe('claude-code');});+ // The run's first assistant already exists in `dbMessagesMap` before the+ // executor starts, so the gateway handler's stream_start seed-insert (its+ // only model/provider β store path) is skipped for it. The executor must+ // therefore mirror the flush into the store itself, or the row renders+ // without a model until the next refetch.+ it('should dispatch model + provider into the store for the initial assistant', async () => {+ const seeded = [+ {+ agentId: 'agent-1',+ content: '',+ id: 'ast-initial',+ role: 'assistant',+ topicId: 'topic-1',+ },+ ];+ const store = createMockStore({+ dbMessagesMap: { 'main_agent-1_topic-1': seeded },+ messagesMap: { 'main_agent-1_topic-1': seeded },+ });++ await runWithEvents([ccInit(), ccText('msg_01', 'hi'), ccResult()], { store });++ const dispatched = store.internal_dispatchMessage.mock.calls.find(+ ([payload]: any) =>+ payload.type === 'updateMessage' &&+ payload.id === 'ast-initial' &&+ payload.value?.provider === 'claude-code',+ );+ expect(dispatched).toBeDefined();+ expect(dispatched![0].value.model).toBe('claude-sonnet-4-6');+ });++ // `recordUsage` is the main-agent twin of the subagent interpreter's+ // `recordUsage`, which updates its thread bucket via `stream.update`.+ // Without the store dispatch, per-turn usage never renders live.+ it('should dispatch turn usage into the store', async () => {+ const store = createMockStore();++ await runWithEvents(+ [+ ccInit(),+ ccMessageStart('msg_01', 'claude-opus-4-6'),+ ccAssistant('msg_01', [{ text: 'Hello', type: 'text' }], { model: 'claude-opus-4-6' }),+ ccMessageDelta({ input_tokens: 100, output_tokens: 20 }),+ ccResult(),+ ],+ { store },+ );++ const dispatched = store.internal_dispatchMessage.mock.calls.find(+ ([payload]: any) =>+ payload.type === 'updateMessage' && payload.value?.metadata?.usage !== undefined,+ );+ expect(dispatched).toBeDefined();+ expect(dispatched![0].value.model).toBe('claude-opus-4-6');+ expect(dispatched![0].value.provider).toBe('claude-code');+ });+it('should write accumulated reasoning', async () => {await runWithEvents([ccInit(),diff --git a/src/store/chat/slices/agentRun/actions/transports/hetero/heterogeneousAgentExecutor.ts b/src/store/chat/slices/agentRun/actions/transports/hetero/heterogeneousAgentExecutor.tsindex 8928117c900..c3a6695a6d5 100644--- a/src/store/chat/slices/agentRun/actions/transports/hetero/heterogeneousAgentExecutor.ts+++ b/src/store/chat/slices/agentRun/actions/transports/hetero/heterogeneousAgentExecutor.ts@@ -1478,6 +1478,22 @@ export const executeHeterogeneousAgent = async (});},);+ // Mirror ONLY model/provider into the store: content/reasoning already+ // stream live via the gateway handler's raw stream_chunk forward. The+ // CLI's model has no live path at all β the run's FIRST assistant is+ // already in `dbMessagesMap` when the run starts, so the gateway's+ // stream_start seed insert (its one modelβstore hop) is skipped for it+ // and the flush above is DB-only. `provider` is already seeded from the+ // agent config; re-stamping it keeps the store and the row identical.+ const liveUpdate: Record<string, any> = {};+ if (intent.model) liveUpdate.model = intent.model;+ if (intent.provider) liveUpdate.provider = intent.provider;+ if (Object.keys(liveUpdate).length > 0) {+ get().internal_dispatchMessage(+ { id: intent.messageId, type: 'updateMessage', value: liveUpdate },+ { operationId },+ );+ }return;}@@ -1605,6 +1621,14 @@ export const executeHeterogeneousAgent = async (messageWriteBatcher.enqueueUpdateMessage(intent.messageId, update, messageWriteCtx, (err) =>console.error('[HeterogeneousAgent] Failed to record main usage:', err),);+ // Same payload into the store so usage + model/provider render live β+ // the subagent interpreter's `recordUsage` already does this via+ // `stream.update`. Dispatching `update` verbatim keeps the store's+ // metadata identical to the row the batcher writes.+ get().internal_dispatchMessage(+ { id: intent.messageId, type: 'updateMessage', value: update as any },+ { operationId },+ );return;}