Skip to content

refactor: migrate LLM, MCP, and tool layers to AI SDK - #226

Merged
minorcell merged 13 commits into
mainfrom
refactor/ai-sdk
Aug 2, 2026
Merged

refactor: migrate LLM, MCP, and tool layers to AI SDK#226
minorcell merged 13 commits into
mainfrom
refactor/ai-sdk

Conversation

@minorcell

Copy link
Copy Markdown
Owner

Migrates the core LLM layer, MCP client, and tool execution onto the AI SDK, restructures packages/core into domain modules, and ships TUI/CI improvements plus a security hardening pass.

Highlights

  • AI SDK migration: LLM layer (b6925f6), MCP client → @ai-sdk/mcp (a160f1b, 4185304), tool layer → standard AI SDK tools (ddb8ee8); dropped custom ToolDefinition/ToolUseBlock/API DTO types in favor of AI SDK equivalents
  • Core restructure: packages/core reorganized into features/ / agent/ / tools domain modules; tokenizer switched from tiktoken to byte-based estimation; session kernel renamed and boundaries tightened
  • Agent capabilities: in-process multi-agent runtime, per-session model overrides, compaction hardening (budget/retry/restore), agent fork/registry/status modules, runtime thinking override, redesigned skills system with dedup and lazy loading
  • TUI: streaming markdown rendering, live output queue, plan progress, session UI restore on resume, memo init, builtin skill-creator, terminal-width wrapping
  • CI/tooling: format/lint/test/build split into parallel jobs, Node ≥22 aligned with engines
  • Security (97fefac): minimatch/brace-expansion/picomatch/undici upgrades (ReDoS, CRLF/smuggling), OAuth callback XSS escape, Windows cmd /c start command injection replaced with PowerShell, 16 MiB exec output cap with kill, 50/10 MiB file/media read caps, session history files now 0o600

Verification

  • 640 tests passing (82 files)
  • pnpm build clean

Closes #225

The root site:* scripts filtered a workspace package (@memo-code/site)
that does not exist - site is a standalone pnpm project. Switch to
pnpm --dir site, matching the deploy workflow. Also fill in the
allowBuilds placeholders in site/pnpm-workspace.yaml that pnpm 11
rejected (native binaries for next dev/build).
Align with Codex: compact at 90% of the context window instead of 80%,
so the effective context before compaction grows while the hard limit
still sits at 100%.
The per-message 4k-char truncation cut most tool outputs (file contents,
search results, command output) out of the compaction request, so the
summary lost the actual work done - plans, decisions, and context. After
compaction the model had to re-explore from scratch.

Now only the budget selector limits the request: it drops the oldest
messages to fit the window, and only truncates a single message when it
alone exceeds the budget (tail kept). Normal transcripts reach the
compaction model in full, including update_plan tool results, so the
plan survives into the summary.
DeepSeek-V4 (pro/flash) supports a 1M-token context window, which the
120k default underused by 8x. Models with a smaller real window can
still override via model_profiles context_window; the hard limit check
and 90% auto-compact threshold scale with the configured window.
Core: add fork (spawn child sessions with filtered history), agent
registry (name lookup for collaboration), communication (subagent
messaging), and status (agent state) modules, wiring them through
withDefaultDeps via createChildHistory.

Site: restructure docs (project-guide replaces soul, drop web-console),
refresh en/zh guides, components, and i18n messages.
Context window is decided by config/defaults only: remove the session
history round-trip (record in session_start, parse back, restore into
the session options) that let a restored session override the
configured window. Provider, model, thinking, and tool permission mode
restore stay.
- deps: minimatch 10.2.6, brace-expansion 5.0.9, picomatch 2.3.2, undici 6.28.0
- oauth: escape callback error text; use PowerShell for Windows URL opening
- exec: 16 MiB output cap with process kill; free completed session buffers
- fs: 50 MiB read cap, 10 MiB media cap
- history: owner-only session file permissions
@minorcell
minorcell merged commit 7aefc29 into main Aug 2, 2026
4 checks passed
@minorcell
minorcell deleted the refactor/ai-sdk branch August 2, 2026 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security audit: dependency ReDoS, OAuth XSS/cmd injection, unbounded memory, and more

1 participant