Commit graph

308 commits

Author SHA1 Message Date
yushen
f2ca86aa1f fix(session): harden write lock and repair 2026-02-03 17:47:41 +08:00
yushen
f1334349ca Merge remote-tracking branch 'origin/main' into session-writelock-repair 2026-02-03 17:45:56 +08:00
LinYushen
0332c90f40
Merge pull request #67 from multica-ai/subagent-orchestration
feat(agent): add subagent orchestration system
2026-02-03 17:37:36 +08:00
yushen
30f23459ce fix(agent): align subagent lifecycle with openclaw 2026-02-03 17:22:41 +08:00
yushen
0c549f76e6 feat(session): integrate write lock and auto-repair into session flow
- storage.ts: acquire/release write lock in appendEntry and writeEntries
- session-manager.ts: add repairIfNeeded() method, apply transcript
  sanitization in loadMessages()
- runner.ts: move message loading to lazy async init in run(), call
  repair before loading messages (following OpenClaw's pattern)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 17:21:26 +08:00
yushen
37e5b2ce7f feat(session): add write lock, file repair, and transcript repair modules
Port from OpenClaw:
- session-write-lock: file-level write lock with atomic creation, reference
  counting, stale lock detection, and process cleanup handlers
- session-file-repair: auto-detect and repair malformed JSONL lines with
  backup and atomic rename
- session-transcript-repair: fix tool call/result pairing issues including
  displaced results, duplicates, orphans, and missing inputs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 17:21:15 +08:00
yushen
1cd778b845 fix(agent): add task minLength validation, remove unused parentSessionId
Add minLength:1 to sessions_spawn task parameter to prevent empty
task strings. Remove parentSessionId from AgentOptions as the
subagent registry tracks lineage via requesterSessionId.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 17:02:03 +08:00
yushen
6bd068a97f fix(hub): init subagent registry on startup and cleanup on shutdown
Call initSubagentRegistry() after setHub() in Hub constructor to
restore persisted runs. Call shutdownSubagentRegistry() before
closing agents in shutdown() to mark active runs as ended.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 17:01:56 +08:00
yushen
918b5d294d fix(agent): resolve stream race condition and add lifecycle tests
Replace for-await stream consumption in watchChildAgent with
waitForIdle() + onClose() callbacks on AsyncAgent. This prevents
conflict with Hub.consumeAgent() which also reads the Channel.

Add shutdownSubagentRegistry() for clean Hub shutdown, guard
Hub access with isHubInitialized(), and clean resumedRuns in sweep.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 17:01:49 +08:00
yushen
83b557a6fc feat(agent): add sessions_spawn tool for subagent orchestration
Register sessions_spawn tool in the tool system with TypeBox schema.
Subagents are blocked from spawning nested subagents via both tool
policy (DEFAULT_SUBAGENT_TOOL_DENY) and runtime guard. Add group:subagent
tool group and parentSessionId to AgentOptions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 16:49:27 +08:00
yushen
5b6a1c6953 feat(hub): add singleton pattern and subagent spawning
Add global Hub singleton for cross-module access by subagent tools.
Add createSubagent() method to Hub for spawning ephemeral child agents
with isSubagent flag and custom system prompts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 16:49:05 +08:00
yushen
85f71e0084 feat(agent): add subagent orchestration core
Implement subagent registry, persistence store, and announcement flow
for child agent lifecycle management. Includes types, registry with
auto-archive sweeper, session JSONL reading for result extraction,
and formatted announcement message delivery.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 16:48:49 +08:00
Naiyuan Qing
e0c16cde38
Merge pull request #66 from multica-ai/feat/mobile-init
feat(mobile): initialize mobile app
2026-02-03 16:47:32 +08:00
Naiyuan Qing
01c82b296d feat(mobile): 移动端初始化
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 16:39:53 +08:00
LinYushen
09f7e93496
Merge pull request #64 from multica-ai/agent-intermediate-steps
feat(agent): stream raw AgentEvent to Hub via Gateway
2026-02-03 15:23:50 +08:00
yushen
203d760034 feat(hub): filter forwarded events to 5 types useful for frontend
Only forward message_start/update/end (assistant role) and
tool_execution_start/end to clients. Drop agent_start, agent_end,
turn_start, turn_end, and tool_execution_update at the Hub layer.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 15:08:46 +08:00
Naiyuan Qing
d6f79d2df6
Merge pull request #65 from multica-ai/feat/pwa-support
feat(web): add PWA support
2026-02-03 14:51:39 +08:00
yushen
37ec8ff5e0 fix(streaming): use per-message stream ids and oauth resolver 2026-02-03 14:51:19 +08:00
Naiyuan Qing
2d83c91ea1 fix(web): split maskable icon into separate entries for type safety
Next.js MetadataRoute.Manifest types only accept single-value purpose
fields, not space-separated combinations like "any maskable".

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 14:49:28 +08:00
Naiyuan Qing
ba1a90cd8d feat(web): add PWA support for installability and offline fallback
Enable the web app to be installed as a standalone PWA on mobile and
desktop. Uses Next.js built-in Metadata API for manifest generation,
a lightweight service worker for navigation offline fallback, and
proper Apple Web App metadata for iOS support.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 14:43:58 +08:00
yushen
273e49f678 feat(agent): stream raw AgentEvent from engine to Hub via Gateway
Expose PiAgentCore events through the full backend pipeline:
- Agent.subscribe() transparently forwards engine events
- AsyncAgent pushes all AgentEvent into Channel alongside error Messages
- Hub discriminates ChannelItem and forwards events via StreamAction

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 14:22:49 +08:00
Naiyuan Qing
57097dfe57
Merge pull request #63 from multica-ai/feat/electron-init
feat(desktop): initialize electron app
2026-02-03 14:21:17 +08:00
Naiyuan Qing
a8143735e9 feat(desktop): initialize electron app with routing and cleanup
Remove template boilerplate (sample SVGs, test IPC message, comments),
add react-router-dom v7 with createHashRouter, scaffold home and chat
pages using @multica/ui components, and add READMEs for desktop, ui,
and store packages documenting import conventions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 14:17:31 +08:00
Jiayuan Zhang
03347d99fd
Merge pull request #62 from multica-ai/forrestchang/agent-error-handling
Fix tool error handling
2026-02-03 02:59:51 +08:00
Jiayuan
0385b0e025 test(agent): convert tool policy test 2026-02-03 02:30:47 +08:00
Naiyuan Qing
7122b12ad5
Merge pull request #61 from multica-ai/feat/text-stream
feat: streaming AI message rendering
2026-02-02 17:45:30 +08:00
Bohan Jiang
a87aee9f3d
Merge pull request #58 from multica-ai/feat/provider-switch
feat(providers): OAuth provider support, /provider and /model commands
2026-02-02 17:38:52 +08:00
Jiang Bohan
c55bb5a864 feat(cli): add /model command for switching models within provider
Add /model command to interactively switch models:
- /model: Show current model and list available models for provider
- /model <name>: Switch to specified model (preserves session)

Example usage:
  /model                    # Shows claude-opus-4-5, claude-sonnet-4-5, etc.
  /model claude-sonnet-4-5  # Switch to sonnet model

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 17:35:40 +08:00
Jiang Bohan
932ecb5dbb refactor(providers): move oauth/ to providers/oauth/ and simplify model names
- Move src/agent/oauth/ to src/agent/providers/oauth/ (parent-child structure)
- Delete deprecated oauth/providers.ts re-export file
- Simplify Claude model names: claude-opus-4-5 (without date suffix)
- Update Codex models to current lineup (gpt-5.2, gpt-5.1-codex, etc.)
- Set claude-opus-4-5 as default model for claude-code provider

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 17:35:35 +08:00
Jiang Bohan
1592e0c211 fix(types): add undefined to optional properties for exactOptionalPropertyTypes
- MemoryStorageOptions.baseDir: add | undefined
- FilterToolsOptions: add | undefined to all optional properties
- CreateToolsOptions: add | undefined to optional properties
2026-02-02 17:20:10 +08:00
Jiang Bohan
6723aa8561 refactor(providers): extract provider management to dedicated module
- Create src/agent/providers/ with registry.ts and resolver.ts
- registry.ts: Provider metadata, status checking, login instructions
- resolver.ts: API key resolution, model resolution
- oauth/providers.ts now re-exports from providers/ (deprecated)
- tools.ts: Remove PROVIDER_ALIAS and DEFAULT_MODELS (moved to providers/)
- Update imports in runner.ts and chat.ts

This separates concerns:
- oauth/ only handles OAuth credential reading
- providers/ manages all provider metadata and resolution
2026-02-02 17:20:02 +08:00
Naiyuan Qing
86d00bb134 feat(ui): render AI messages with streaming markdown
Messages store gains streamingIds set and startStream/appendStream/
endStream actions. Gateway store routes stream action payloads to
these new actions. Chat component switches to StreamingMarkdown
for in-progress messages, providing incremental block-level rendering.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 17:18:35 +08:00
Naiyuan Qing
d04bed8175 feat(agent): add streaming support for AI message generation
AsyncAgent now subscribes to pi-agent-core events (message_start,
message_update, message_end) and forwards incremental text deltas
through a stream callback. Hub registers the callback and sends
stream payloads to the requesting client via Gateway.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 17:18:10 +08:00
Jiang Bohan
5952f22ca2 docs: add LLM providers documentation
- Document OAuth providers (claude-code, openai-codex)
- Document API Key providers
- Add /provider command usage example
- Add OAuth login instructions
2026-02-02 17:10:14 +08:00
Jiang Bohan
35b13f976d feat(runner): validate provider credentials on startup
- Add isOAuthProvider() and isProviderAvailable() helpers
- Show login instructions for OAuth providers without credentials
- Show configuration example for API Key providers without keys
- Fail early with helpful error message instead of cryptic API errors
2026-02-02 17:10:10 +08:00
Jiang Bohan
051e56dbf6 feat(cli): improve /provider command display with ID column
- Add ID column to show actual provider keys for --provider flag
- Add usage examples with actual command syntax
- Improve visual formatting with table headers
2026-02-02 17:10:05 +08:00
Naiyuan Qing
6b0340480b
Merge pull request #60 from multica-ai/fix/sdk-source-exports
fix(sdk): point exports to source, remove .js suffixes
2026-02-02 17:01:44 +08:00
Naiyuan Qing
441c2059a8 fix(sdk): point exports to source and remove .js import suffixes
- Change package exports from dist/ to src/ (consistent with @multica/store and @multica/ui)
- Add private: true since SDK is an internal monorepo package
- Switch tsconfig from NodeNext to bundler moduleResolution
- Remove .js suffixes from all internal imports for Turbopack compatibility

Eliminates the need to build SDK before running dev server or Next.js build.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:23 +08:00
Jiang Bohan
9b8aebdf76 chore(skills): remove redundant provider skill
The /provider command is now a built-in CLI command in chat.ts,
which directly calls oauth/providers.ts for accurate status.
The skill was redundant and could produce inconsistent results
since it relied on LLM reading files instead of using the API.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:54:42 +08:00
Jiang Bohan
da11e65d35 refactor(oauth): rename credentials/ to oauth/ for clarity
Separate OAuth credential reading (external CLI tools) from the main
CredentialManager (API Key configuration in credentials.json5).

- credentials.ts: API Key configuration management
- oauth/: External OAuth credential reading (Claude Code, Codex)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:52:04 +08:00
Jiang Bohan
307b381e6c feat(skills): add provider skill for LLM provider management
Provides instructions for viewing and switching LLM providers,
including OAuth (Claude Code, Codex) and API Key based providers.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:43:10 +08:00
Jiang Bohan
9504eeab62 feat(cli): add /provider command to show and switch providers
The /provider command shows:
- Current provider and model
- List of available providers (OAuth and API Key)
- Status of each provider (configured/not configured)
- Instructions for switching providers

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:43:05 +08:00
Jiang Bohan
b9ce4da28f feat(runner): support OAuth providers (claude-code, openai-codex)
- Add provider alias mapping (claude-code -> anthropic)
- Resolve API key from OAuth credentials for claude-code and codex
- Add default models for each provider

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:43:00 +08:00
Jiang Bohan
05138029de feat(credentials): add CLI credentials reader for OAuth providers
Add support for reading OAuth credentials from external CLI tools:
- Claude Code: ~/.claude/.credentials.json or macOS Keychain
- Codex: ~/.codex/auth.json or macOS Keychain

Includes provider management with status checking and login instructions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:42:55 +08:00
Naiyuan Qing
ebcab2477a
Merge pull request #57 from multica-ai/feature/ws-migration
feat: migrate frontend to pure WebSocket RPC
2026-02-02 16:35:19 +08:00
Naiyuan Qing
a62ac2e075 chore: remove @multica/fetch package
No consumers remain after migrating to pure WebSocket RPC.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:29:27 +08:00
Naiyuan Qing
e491949749 refactor(store): remove @multica/fetch dependency
- Move gatewayUrl into gateway store state with setGatewayUrl action
- layout.tsx uses useGatewayStore.getState().setGatewayUrl() directly
- Remove @multica/fetch from store and web package.json dependencies

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:23:06 +08:00
Naiyuan Qing
a1c28b3d04 feat(ui): add auto-scroll to bottom for chat messages
- Add useAutoScroll hook using ResizeObserver + MutationObserver
- Observes content children for size changes (streaming, images)
- Watches for new DOM nodes (new messages, history load)
- Respects user scroll position: no force-scroll when reading above
- Integrate in Chat component alongside existing useScrollFade

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:14:18 +08:00
Naiyuan Qing
4d6d57187c feat(store): load agent message history via RPC
- Add typed AgentMessageItem to SDK with proper content block types
- Add fetchAgentMessages action to hub store using getAgentMessages RPC
- Extract text from complex content blocks (user string, assistant array)
- Auto-load history when selecting an agent with no local messages

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:13:59 +08:00
Naiyuan Qing
3622f82a7b feat(gateway): add auto-connect, hub discovery via list-devices
- Add LIST_DEVICES event and "hub" device type to SDK
- Add listDevices() method to GatewayClient
- Add handleListDevices handler in Gateway
- Change Hub deviceType from "client" to "hub"
- Refactor gateway store: auto-connect WS, separate hubId selection
- Hub-init: auto-connect on mount, discover hubs on registered
- Hub-sidebar: show discovered hubs list with connect/disconnect UI

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:13:40 +08:00