Commit graph

946 commits

Author SHA1 Message Date
yushen
0b50400a45 fix(desktop): read error body instead of statusText for gateway errors
res.statusText is always empty under HTTP/2, causing "Gateway error: "
with no detail. Now reads the JSON response body to surface the
server's actual error message and always includes the status code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 08:51:46 +08:00
yushen
b3a179971e chore: bump version to 0.1.1
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 08:19:15 +08:00
yushen
1a9e915d49 fix(hub): skip text processing after MessageAggregator reset
Add an `active` flag so that message_update/message_end events are
ignored after reset() until the next message_start, preventing stale
accumulated text from being re-emitted as a block.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 07:49:20 +08:00
LinYushen
733798f2a9
Merge pull request #178 from multica-ai/fix/api-url-env-bridge
fix(desktop): bridge MULTICA_API_URL for staging/test packaged builds
2026-02-14 07:40:29 +08:00
yushen
eb07f12c49 chore(desktop): add env files for dev/production and update dev scripts
- Track .env.development and .env.production for desktop app
- Add MAIN_VITE_API_URL to all env files
- Remove hardcoded GATEWAY_URL from dev scripts (now in .env.development)
- Update .env.example with full documentation of all env vars

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 07:30:54 +08:00
yushen
ef32078b3c fix(desktop): use RENDERER_VITE_API_URL for renderer API host
Read API host from import.meta.env.RENDERER_VITE_API_URL instead of
hardcoding it, so staging/dev builds point to the correct backend.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 07:30:48 +08:00
yushen
b7477cb646 feat(desktop): bridge MAIN_VITE_API_URL to process.env for packaged builds
In packaged Electron builds, @multica/core is externalized and .env
files are excluded. Bridge import.meta.env.MAIN_VITE_API_URL (injected
at build time by electron-vite) to process.env.MULTICA_API_URL so that
getApiBaseUrl() reads the correct value in staging/test environments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 07:30:42 +08:00
yushen
b8aa5ad7e6 refactor(core): convert MULTICA_API_URL constant to getApiBaseUrl() function
Lazy-read process.env at call time instead of module import time.
This ensures the env bridge in the Electron main process has time to
set process.env.MULTICA_API_URL before the first API request.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 07:30:36 +08:00
Jiayuan Zhang
87c03c1368
Merge pull request #177 from multica-ai/forrestchang/telegram-table-fmt
fix(telegram): improve Telegram bot UX — tables, tool narration, typing
2026-02-14 03:38:03 +08:00
Jiayuan Zhang
ef8b38899a fix(core): check for "toolCall" type in hasToolUse() to match pi-ai types
The hasToolUse() function was checking for "tool_use" (raw Anthropic format)
but pi-ai normalizes tool call blocks to type "toolCall". This made tool
narration non-functional in the ChannelManager (Desktop/embedded) path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 03:32:16 +08:00
Jiayuan Zhang
d1570698ac fix(telegram): fix tool narration detection and typing indicator during tool execution
- Detect both "tool_use" (Anthropic) and "toolCall" (Hub) content types
- Re-send typing indicator after sending/editing status message since
  Telegram clears typing state on any message send/edit
- Remove debug file logging (appendFileSync to /tmp)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 03:14:48 +08:00
Jiayuan Zhang
4c1365ff75 fix(telegram): strip existing bold markers in table conversion to prevent overlapping HTML tags
Table cells already containing **bold** markers got double-wrapped,
creating ****text**** which produced overlapping <b><i> tags rejected
by Telegram's HTML parser.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 03:14:41 +08:00
Jiayuan Zhang
3c911807e1 chore(channels): remove unused Desktop Telegram channel plugin
The Telegram bot is handled entirely by the Gateway
(apps/gateway/telegram/). The Desktop channel plugin was never
registered (commented out in initChannels) and is dead code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 02:28:00 +08:00
Jiayuan Zhang
dde8cc542a feat(telegram): show editable status message during tool execution
Instead of silently discarding tool narration or spamming separate
messages, send a single editable Telegram message that updates in-place
as the agent works. First tool narration sends a reply; subsequent
narrations edit the same message. The final answer is sent as a new
message.

- Add replyTextEditable/editText to ChannelOutboundAdapter interface
- Implement editFormatted + editable methods in Telegram plugin
- Track statusMessageId in ChannelManager, clear on agent_end/error
- Add sendOrEditStatus to Gateway TelegramService with same behavior

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 02:14:42 +08:00
Jiayuan Zhang
81998e6309 fix(telegram): skip tool narration messages, only send final answer
When the agent uses tools (web search, etc.), it generates intermediate
narration text like "Let me search..." before each tool call. These were
being sent as separate Telegram messages, causing message spam. Now we
detect tool_use blocks in the message content and skip sending those
intermediate messages — only the final answer reaches the user.

Applied to both Desktop channel plugin and Gateway Telegram service.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 02:04:17 +08:00
Jiayuan Zhang
8270762d66 feat(telegram): convert Markdown tables to vertical list format
Telegram doesn't support HTML tables, so pipe-delimited Markdown tables
were rendered as hard-to-read plain text on mobile. This converts tables
to a vertical "Header: Value" format with bold first column before
sending to Telegram.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 01:56:21 +08:00
Jiayuan Zhang
badcaa4a41
Merge pull request #176 from multica-ai/forrestchang/dev-local-run-log
chore(scripts): enable run log in dev:local script
2026-02-14 01:55:56 +08:00
Jiayuan Zhang
9c02ac7b91 chore(scripts): enable run log in dev:local script
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 01:50:56 +08:00
Jiayuan Zhang
9189883710
Merge pull request #175 from multica-ai/forrestchang/telegram-arch
feat(gateway): Telegram QR-based connection flow with centralized bot
2026-02-14 01:45:46 +08:00
Jiayuan Zhang
eb274d5e0c fix(desktop): resolve lint warnings for react-refresh and unused import
- Extract useQRToken and useCountdown hooks to qr-hooks.ts so qr-code.tsx
  only exports components (fixes react-refresh/only-export-components)
- Remove unused useRef import from connect-step.tsx

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 01:38:04 +08:00
Jiayuan Zhang
d6393c6718 fix(gateway): remove cleanupPendingRequests that rejects all concurrent users
cleanupPendingRequests() iterated the service-wide pendingRequests Map
and rejected every entry. Since it was called from connectUser's catch
block (a per-user error path), one user's connection failure would
spuriously reject other users' in-flight verify RPCs.

The call was also redundant: sendVerifyRpc already cleans up its own
entry in all failure paths (timeout, RPC error, route failure).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 01:31:33 +08:00
Jiayuan Zhang
7af2a0d1b1 fix(desktop): auto-approve Telegram connection during onboarding
DeviceConfirmDialog only exists in the main Layout, so verify
requests were timing out during onboarding. Since the user is
actively generating the QR code, auto-approve and show a success
state instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 01:14:25 +08:00
Jiayuan Zhang
5531379bb0 chore: add OAuth login URL to local dev script
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 01:05:24 +08:00
Jiayuan Zhang
088750326c fix(gateway): persist Telegram users to JSON file when no database
Replaces in-memory Map with file-backed store at
~/.super-multica/gateway/telegram-users.json so user bindings
survive gateway restarts during local development.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 00:48:17 +08:00
Jiayuan Zhang
24b70e6e25 fix(gateway): add in-memory fallback for TelegramUserStore when no database
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 00:45:05 +08:00
Jiayuan Zhang
a7629db01e fix(gateway): enable CORS for HTTP endpoints
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 00:42:29 +08:00
Jiayuan Zhang
005908710e chore: add local dev script for Gateway + Desktop with Telegram bot
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 00:39:43 +08:00
Jiayuan Zhang
b39a0dd2ac feat(desktop): add Telegram QR code to Clients page and Onboarding
- Create TelegramConnectQR component (fetches short code from Gateway)
- Export reusable hooks/components from qr-code.tsx
- Update ChannelsTab with Telegram QR card
- Rewrite ConnectStep for QR-based flow (replaces BotFather token input)
- Re-add ConnectStep to onboarding: Privacy → Provider → Channels → Start

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 00:30:10 +08:00
Jiayuan Zhang
d75a24714d feat(gateway): add Telegram QR deep link connection flow
Add short code store, bot commands (/start, /status, /help), and
POST /telegram/connect-code endpoint for Desktop to create QR codes.
Users scan a QR → Telegram opens → /start {code} → auto-connects.

- ShortCodeStore: in-memory Map with TTL for connection info
- Bot commands registered via setMyCommands
- Refactor handleConnectionLink into shared connectUser method
- Fetch bot username via getMe() for deep link URL

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 00:30:01 +08:00
Jiayuan Zhang
c2a2c75b24
Merge pull request #174 from multica-ai/forrestchang/arch-analysis
test(core): migrate tests to strict mock policy with real implementations
2026-02-14 00:13:24 +08:00
Jiayuan Zhang
5010d87284 feat(gateway): add long-polling fallback for local Telegram development
When TELEGRAM_WEBHOOK_URL is not set, the bot automatically starts in
long-polling mode (bot.start()) instead of waiting for webhook calls.
This allows local development without ngrok or a public URL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 00:05:19 +08:00
Bohan Jiang
597f24a436
Merge pull request #173 from multica-ai/chore/api-host-multica
chore: switch API host to api.multica.ai
2026-02-13 23:30:54 +08:00
Jiang Bohan
a86709a4cd chore: switch API host from api-dev.copilothub.ai to api.multica.ai
Update all backend API base URLs to use the production multica.ai domain.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 23:25:00 +08:00
Jiayuan Zhang
4cb8b93f93 refactor(desktop): hide manual Telegram bot creation, use official Gateway bot only
Remove the user-facing ability to create custom Telegram bots via BotFather.
Non-technical users should only need to message @multica_bot on Telegram.
- Disable telegramChannel plugin registration in initChannels()
- Remove ConnectStep from onboarding flow (Privacy → Provider → Start)
- Replace TelegramCard with simple text pointing to @multica_bot

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:20:39 +08:00
Jiayuan Zhang
f6b6c2909b test(core): migrate 5 tests from internal mocks to real implementations
- store.test.ts: use baseDir option instead of mocking paths.js
- session-file-repair.test.ts: remove write-lock mock, assert behavior
- announce-findings.test.ts: use real storage with temp dirs
- sessions-list.test.ts: use real registry with seed helper
- compaction.test.ts: mock only third-party pi-coding-agent, use real
  context-window internals

All tests exercise real code paths, improving confidence in actual
behavior per the strict mock policy.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:17:52 +08:00
Jiayuan Zhang
37e550200c refactor(core): add baseDir DI and test helpers for mock-free testing
Add AuthStoreOptions with baseDir to auth-profiles/store.ts functions,
add baseDir option to announce.ts readLatestAssistantReply, and add
seedSubagentRunForTests helper to registry.ts. These enable tests to
use real implementations with temp directories instead of mocking
internal modules.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:17:41 +08:00
Jiayuan Zhang
38181ab4db refactor(gateway): remove group chat support from Telegram bot
Group chats have unresolved issues in the Gateway context:
- Per-user deviceId causes context overwrites across groups
- Reply chains across users route to wrong Hubs
- Welcome messages are noisy in groups

Restrict to private chats only until a proper group model is designed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:12:26 +08:00
Jiayuan Zhang
9646b08306 feat(gateway): port Desktop Telegram channel features to Gateway webhook bot
Port all 7 features from the Desktop long-polling Telegram channel plugin
to the Gateway webhook-based Telegram bot:

- Markdown → Telegram HTML formatting with parse-error fallback
- Text chunking for messages >4096 chars (paragraph-boundary split)
- Reply-to original message + 👀 ack reaction lifecycle
- Group chat support (mention/reply filtering, @mention stripping)
- Per-chat message serialization (prevents race conditions)
- Inbound media handling (voice/audio/photo/video/document)
  with transcription (Whisper) and description (Vision API)
- Outbound file captions with HTML formatting

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:06:43 +08:00
Jiayuan Zhang
f525d6ccfe test: add vitest setup with static mock policy checker
Scans test files at startup and warns when vi.mock() targets internal
modules (relative paths or @multica/* packages). Reports file paths
and line numbers for all violations without interfering with test
execution.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:03:36 +08:00
Jiayuan Zhang
8f73cfdf9d docs: add strict mock policy and testing guidelines to CLAUDE.md
Establish "external-only mock" rule: only third-party dependencies
may be mocked in tests. Internal modules must use real implementations
with temp directories, reset functions, or dependency injection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:03:29 +08:00
Jiayuan Zhang
d6a1edaee1
Merge pull request #172 from multica-ai/forrestchang/agent-test-logging
feat(agent): add structured run logging for debugging
2026-02-13 21:50:35 +08:00
Jiayuan Zhang
0ab26d415b docs: add run log debugging section to CLAUDE.md
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 21:40:27 +08:00
Jiayuan Zhang
b6db23c4b3 feat(agent): add structured run logging for debugging
Introduce a RunLog system that records agent execution events as
structured JSONL to ~/.super-multica/sessions/{id}/run-log.jsonl.
Enable via MULTICA_RUN_LOG=1 env var or AgentOptions.enableRunLog.

Logs: run lifecycle, LLM calls, tool execution timing, context
overflow recovery, auth profile rotation, error classification,
and compaction events.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 21:38:02 +08:00
Jiayuan Zhang
13e5492993
Merge pull request #171 from multica-ai/forrestchang/markdown-accept
feat(web): add Accept: text/markdown header for Cloudflare Markdown for Agents
2026-02-13 21:00:08 +08:00
yushen
8881ae8f4b chore: bump version to 0.1.0
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 20:00:25 +08:00
Jiayuan Zhang
27c3ba5682 feat(web): add Accept: text/markdown header for Cloudflare Markdown for Agents
Prefer markdown responses from servers that support Cloudflare's Markdown
for Agents feature, reducing token usage by ~80% when available. Non-supporting
servers fall back to HTML as before.

- Update Accept header to prefer text/markdown in web_fetch requests
- Add text/markdown content-type handling to skip HTML parsing pipeline
- Capture x-markdown-tokens response header in WebFetchResult
- Add extractMarkdownTitle() helper for native markdown title extraction

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 19:47:17 +08:00
yushen
faecc32aff chore(desktop): fix electron-builder config for releases
- Fix publish repo from "multica" to "super-multica"
- Add zip to mac targets (required for electron-updater auto-updates)
- Enable hardenedRuntime (required for notarization)
- Add notarize config with teamId placeholder

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 19:46:30 +08:00
LinYushen
882dc8592b
Merge pull request #157 from multica-ai/feat/improve-compaction
feat(compaction): improve summary mode with fallback, split-turn, and metadata
2026-02-13 19:15:38 +08:00
LinYushen
77aff992c1
Merge pull request #170 from multica-ai/feat/desktop-api-client
feat(core): add auth-store and shared API client for desktop auth
2026-02-13 19:12:00 +08:00
yushen
882e34c491 fix(core): preserve context-specific auth error messages
Add optional context parameter to getAuthHeaders() so callers can
provide feature-specific suffixes (e.g. "to use web search") in the
not-logged-in error message, restoring the original behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:58:27 +08:00