Commit graph

41 commits

Author SHA1 Message Date
Naiyuan Qing
3c303df8f1 Merge branch 'main' into exec-approvals 2026-02-05 11:06:52 +08:00
Jiang Bohan
087d1a8653 refactor(tools): remove tool profile layer from policy system
Simplify 4-layer policy to 3-layer:
- Layer 1: Global allow/deny (user config)
- Layer 2: Provider-specific rules
- Layer 3: Subagent restrictions

Removed:
- ToolProfileId type (minimal/coding/web/full)
- TOOL_PROFILES constant
- getProfilePolicy function
- profile field from ToolsConfig

Users can achieve the same effect using allow/deny with group:* syntax.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 02:58:15 +08:00
Jiang Bohan
9b16001e0e feat(subagent): pass tools to subagent system prompt
Resolve tools before building subagent system prompt so the
"## Tooling" section is included, matching OpenClaw's pattern.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 02:58:08 +08:00
yushen
89089ef866 feat(agent): wire exec approval callback into tool execution pipeline
- Add optional onApprovalNeeded callback to exec tool (backward compatible)
- Thread callback through CreateToolsOptions → AgentOptions → resolveTools
- Add ExecApprovalConfig to ProfileConfig for per-profile configuration
- Create CLI terminal approval callback (readline-based) for non-Hub mode
- Export all exec approval types and functions from tools index

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 17:07:07 +08:00
yushen
e67682cfa0 feat(agent): add exec approval type definitions and safety evaluation engine
Introduces the core exec approval system with:
- Type definitions: ExecSecurity, ExecAsk, ApprovalDecision, ExecApprovalConfig
- Command safety evaluation: shell syntax analysis, safe binary detection,
  dangerous pattern detection, allowlist matching
- Persistent allowlist management: glob pattern matching, dedup, usage tracking
- Comprehensive test coverage (76 tests)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 17:06:58 +08:00
yushen
30f23459ce fix(agent): align subagent lifecycle with openclaw 2026-02-03 17:22:41 +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
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
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
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
3797e9e58b docs: update CLI commands to use unified multica format
- Update skills/README.md: pnpm skills:cli → multica skills
- Update tools/README.md: pnpm agent:cli, pnpm tools:cli → multica run, multica tools
- Update tools/README.zh-CN.md: same changes for Chinese docs
- Update test commands: npx tsx → pnpm test

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 14:11:36 +08:00
Jiayuan
52a8b5a612 fix(web-search): use correct model name based on Perplexity API key type
- Direct Perplexity API (pplx-*) uses "sonar-pro" model name
- OpenRouter (sk-or-*) uses "perplexity/sonar-pro" model name
- Refactor inferPerplexityBaseUrl to inferPerplexityConfig returning both baseUrl and model
- Export internal functions for potential reuse

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 00:49:41 +08:00
Jiayuan
3ee8946e29 feat(credentials): add JSON5 credential system 2026-02-01 02:28:27 +08:00
Jiayuan
53bd52b137 feat(agent): add process list action for activity monitoring
Add 'list' action to process tool that displays all registered processes
with their ID, command, status, duration, and source (exec/process).

Example output:
ID                                    COMMAND        STATUS       DURATION  SOURCE
019c139c-dbb7-70ec-ab91-0a7fd2711043  curl -X POST   running         15.2s  [exec]

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 18:49:16 +08:00
Jiayuan
14bcebee2a feat(agent): add real-time streaming updates to exec tool
Utilize the onUpdate callback from pi-agent-core's AgentTool interface
to stream output updates in real-time while commands are executing.

- Accept onUpdate as 4th parameter in execute function
- Emit tailBuffer updates on each stdout/stderr data event
- Stop emitting updates once command is backgrounded (yielded)

This enables UI to show live command output progress via the
tool_execution_update agent event.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 18:31:50 +08:00
Jiayuan
cbb13b26d1 fix(agent): return collected output when exec auto-backgrounds
Previously, when a command exceeded yieldMs (default 5s) and was
auto-backgrounded, exec returned an empty output string. This caused
agents to misinterpret slow commands (like curl) as failed, leading
to infinite retry loops.

Changes:
- Implement three-layer buffer system (pending 30KB + aggregated 200KB + tail 1KB)
- Return collected output snapshot when backgrounding instead of empty string
- Increase default yieldMs from 5s to 10s for better coverage
- Add auto sweeper for terminated process cleanup (30min TTL)
- Register process immediately on spawn to capture all output

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 18:31:50 +08:00
Jiang Bohan
22d60f889c docs(tools): simplify roadmap and add Chinese translation
- Replace phased roadmap with simple future tools list
- Add Chinese README (README.zh-CN.md)
- Add language switching links between EN/CN docs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:42 +08:00
Jiang Bohan
22536fd24c fix(memory): handle exactOptionalPropertyTypes for optional fields
Use spread operator to conditionally add description property
instead of assigning undefined to optional fields.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:42 +08:00
Jiang Bohan
424a330972 fix(memory): fix TypeScript discriminated union narrowing
Use `validation.valid === false` instead of `!validation.valid`
to properly narrow the discriminated union type.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:42 +08:00
Jiang Bohan
1a98446a4c docs(tools): document memory tools
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:42 +08:00
Jiang Bohan
d9cd79f847 feat(tools): register memory tools and add group:memory
- Update createAllTools to accept options object with profileId
- Add memory tools when profileId is provided
- Add group:memory tool group for memory tools

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:42 +08:00
Jiang Bohan
4a9220b09f test(memory): add storage layer tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:42 +08:00
Jiang Bohan
8484ba6cb2 feat(memory): add persistent key-value storage for agents
- Add memory tool types (MemoryEntry, MemoryStorageOptions, etc.)
- Implement file-based storage layer with validateKey, memoryGet,
  memorySet, memoryDelete, memoryList functions
- Create memory_get, memory_set, memory_delete, memory_list tools
- Store data in profile directory: ~/.super-multica/agent-profiles/<id>/memory/

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:42 +08:00
Jiang Bohan
cd0888dc33 docs(tools): add Agent Profile integration section
Add architecture diagram showing Hub-Agent-Client relationship and
document how Profile config.json integrates with tools configuration.
Mark Phase 2 as complete.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:42 +08:00
Jiang Bohan
3c0f132ff8 feat(tools): integrate Profile tools config with runner
Add mergeToolsConfig function to combine Profile tools config with
CLI options. Profile config serves as base, CLI options override.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:42 +08:00
Jiang Bohan
11e2564aac docs(tools): add comprehensive README with architecture diagram
Document the 4-layer policy filter system, tool groups, profiles,
and usage examples for both CLI and programmatic interfaces.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:42 +08:00
Jiang Bohan
e44861b56c fix(tools): resolve exactOptionalPropertyTypes errors
Handle undefined values correctly in optional object properties
for TypeScript strict mode compatibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:42 +08:00
Jiang Bohan
7d04253791 fix(tools): replace replaceAll with replace for ES2020 compatibility
Use regex replace instead of replaceAll to support older target versions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:42 +08:00
Jiang Bohan
ab7c0774ba test(tools): add policy system unit tests
Test coverage for:
- Tool group expansion
- Profile policies
- Allow/deny filtering
- Provider-specific rules
- Subagent restrictions
- Combined policy layers

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:22 +08:00
Jiang Bohan
57f31b2f79 feat(tools): add tool policy system with 4-layer filtering
Implement a flexible tool policy system that supports:
- Tool groups (group:fs, group:runtime, group:web)
- Predefined profiles (minimal, coding, web, full)
- Global allow/deny lists
- Provider-specific rules
- Subagent restrictions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 02:25:22 +08:00
Jiayuan
f6360c32d9 test(ssrf): expand SSRF test coverage
Add tests for createPinnedLookup, resolvePinnedHostname,
createPinnedDispatcher, and closeDispatcher functions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 14:01:00 +08:00
Jiayuan
44d0cef838 test(tools): add unit tests for glob and param-helpers
Add tests for:
- Glob tool pattern matching, limits, and ignore patterns
- Parameter helpers for string/number parsing and JSON results

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 14:00:53 +08:00
Jiayuan
9f5424eb5c test(web): add unit tests for SSRF, cache, and HTML utilities
Add comprehensive tests for:
- SSRF protection (isPrivateIpAddress, isBlockedHostname)
- Cache utilities (readCache, writeCache, TTL handling)
- HTML utilities (htmlToMarkdownSimple, markdownToText, truncateText)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 13:54:44 +08:00
Jiayuan
9b3ffd1e90
feat(agent): add web_fetch and web_search tools (#20)
* chore(deps): add web tools dependencies

Add undici, @mozilla/readability, linkedom, and turndown for
web fetching and HTML content extraction capabilities.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* feat(agent): add web_fetch and web_search tools

Port network tools from moltbot with the following features:

web_fetch:
- Fetch and extract readable content from URLs
- Dual extraction mode: readability (smart) or turndown (full page)
- SSRF protection (blocks private IPs, localhost)
- Response caching with TTL
- Redirect handling

web_search:
- Brave Search API for traditional results
- Perplexity API for AI-synthesized answers
- Region/language settings
- Freshness filtering (Brave only)
- Auto-detects provider from available API keys

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* feat(agent): register web_fetch and web_search tools

Add web tools to the agent's tool registry.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 05:09:16 +08:00
Jiayuan
95e6ae439d
feat(agent): add glob tool for file pattern matching (#18)
Add a glob tool that allows agents to find files matching glob patterns.
Features:
- Supports standard glob patterns (e.g., **/*.ts, src/**/*.{js,jsx})
- Results sorted by modification time (most recent first)
- Configurable result limit and ignore patterns
- Default ignores for node_modules, .git, dist, etc.

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 04:33:01 +08:00
Jiayuan
5931e8f84e
feat(agent): add auto-backgrounding and process management (#17)
* feat(agent): add auto-backgrounding to exec tool

- Add yieldMs parameter to exec tool (default 5s) - commands that don't
  complete within this time automatically run in background
- Create shared process-registry.ts for unified process management
- Refactor process.ts to use shared registry
- Add --debug CLI flag for session message logging
- Signal isolation: backgrounded processes ignore abort signals

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(session): preserve tool_use/tool_result pairs during compaction

Previously, session compaction simply kept the last N messages, which
could break tool_use/tool_result pairs if the cut point fell between
them. This caused "tool_call_id is not found" errors from the API.

Now compaction finds a safe cut point that starts from either:
- A user message without tool_result
- An assistant message whose tool_use is needed by the next tool_result

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* feat(session): use Kimi as default model for summary compaction

- Auto-detect MOONSHOT_API_KEY from environment
- Use moonshot-v1-128k (cheaper than k2-thinking)
- Fall back to tokens mode if API key not available

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* docs: add rule to never use git commit --amend

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* docs: clarify git amend rule for immediate fixes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 04:22:42 +08:00
Jiayuan
3a435aac8a
docs: translate comments from Chinese to English (#15)
Translate all comments, JSDoc strings, and documentation text from Chinese to English across 19 files for improved accessibility and consistency with the broader developer community.

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
2026-01-30 04:01:14 +08:00
Jiayuan
99473af854 fix(agent): prevent memory leak and buffer overflow in process tool
- Add TTL-based auto-cleanup for terminated processes (1 hour)
- Add 'cleanup' action for manual removal of terminated processes
- Fix buffer overflow when single chunk exceeds MAX_OUTPUT_BUFFER
- Track terminatedAt timestamp for cleanup eligibility

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 03:08:24 +08:00
Jiayuan
200b2cefda feat(agent): add profile system and improve tools
- Add Agent Profile module for managing agent identity, soul, tools,
  memory, and bootstrap configuration
- Add profile CLI (pnpm agent:profile) for creating/listing/showing profiles
- Default sessionId to UUIDv7 instead of "default"
- Expose Agent.sessionId as public readonly property
- Improve exec/process tools error handling (no more crashes on spawn errors)
- Add 'output' action to process tool for reading stdout/stderr
- Better tool descriptions to guide agent in choosing exec vs process

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:47:30 +08:00
Jiayuan
1097ef5144 feat(agent): add exec/process tools 2026-01-30 01:52:10 +08:00