Files
Memoh/mise.toml
T
Acbox Liu 1680316c7f refactor(agent): remove agent gateway instead of twilight sdk (#264)
* refactor(agent): replace TypeScript agent gateway with in-process Go agent using twilight-ai SDK

- Remove apps/agent (Bun/Elysia gateway), packages/agent (@memoh/agent),
  internal/bun runtime manager, and all embedded agent/bun assets
- Add internal/agent package powered by twilight-ai SDK for LLM calls,
  tool execution, streaming, sential logic, tag extraction, and prompts
- Integrate ToolGatewayService in-process for both built-in and user MCP
  tools, eliminating HTTP round-trips to the old gateway
- Update resolver to convert between sdk.Message and ModelMessage at the
  boundary (resolver_messages.go), keeping agent package free of
  persistence concerns
- Prepend user message before storeRound since SDK only returns output
  messages (assistant + tool)
- Clean up all Docker configs, TOML configs, nginx proxy, Dockerfile.agent,
  and Go config structs related to the removed agent gateway
- Update cmd/agent and cmd/memoh entry points with setter-based
  ToolGateway injection to avoid FX dependency cycles

* fix(web): move form declaration before computed properties that reference it

The `form` reactive object was declared after computed properties like
`selectedMemoryProvider` and `isSelectedMemoryProviderPersisted` that
reference it, causing a TDZ ReferenceError during setup.

* fix: prevent UTF-8 character corruption in streaming text output

StreamTagExtractor.Push() used byte-level string slicing to hold back
buffer tails for tag detection, which could split multi-byte UTF-8
characters. After json.Marshal replaced invalid bytes with U+FFFD,
the corruption became permanent — causing garbled CJK characters (�)
in agent responses.

Add safeUTF8SplitIndex() to back up split points to valid character
boundaries. Also fix byte-level truncation in command/formatter.go
and command/fs.go to use rune-aware slicing.

* fix: add agent error logging and fix Gemini tool schema validation

- Log agent stream errors in both SSE and WebSocket paths with bot/model context
- Fix send tool `attachments` parameter: empty `items` schema rejected by
  Google Gemini API (INVALID_ARGUMENT), now specifies `{"type": "string"}`
- Upgrade twilight-ai to d898f0b (includes raw body in API error messages)

* chore(ci): remove agent gateway from Docker build and release pipelines

Agent gateway has been replaced by in-process Go agent; remove the
obsolete Docker image matrix entry, Bun/UPX CI steps, and agent-binary
build logic from the release script.

* fix: preserve attachment filename, metadata, and container path through persistence

- Add `name` column to `bot_history_message_assets` (migration 0034) to
  persist original filenames across page refreshes.
- Add `metadata` JSONB column (migration 0035) to store source_path,
  source_url, and other context alongside each asset.
- Update SQL queries, sqlc-generated code, and all Go types (MessageAsset,
  AssetRef, OutboundAssetRef, FileAttachment) to carry name and metadata
  through the full lifecycle.
- Extract filenames from path/URL in AttachmentsResolver before clearing
  raw paths; enrich streaming event metadata with name, source_path, and
  source_url in both the WebSocket and channel inbound ingestion paths.
- Implement `LinkAssets` on message service and `LinkOutboundAssets` on
  flow resolver so WebSocket-streamed bot attachments are persisted to the
  correct assistant message after streaming completes.
- Frontend: update MessageAsset type with metadata field, pass metadata
  through to attachment items, and reorder attachment-block.vue template
  so container files (identified by metadata.source_path) open in the
  sidebar file manager instead of triggering a download.

* refactor(agent): decouple built-in tools from MCP, load via ToolProvider interface

Migrate all 13 built-in tool providers from internal/mcp/providers/ to
internal/agent/tools/ using the twilight-ai sdk.Tool structure. The agent
now loads tools through a ToolProvider interface instead of the MCP
ToolGatewayService, which is simplified to only manage external federation
sources. This enables selective tool loading and removes the coupling
between business tools and the MCP protocol layer.

* refactor(flow): split monolithic resolver.go into focused modules

Break the 1959-line resolver.go into 12 files organized by concern:
- resolver.go: core orchestration (Resolver struct, resolve, Chat, prepareRunConfig)
- resolver_stream.go: streaming (StreamChat, StreamChatWS, tryStoreStream)
- resolver_trigger.go: schedule/heartbeat triggers
- resolver_attachments.go: attachment routing, inlining, encoding
- resolver_history.go: message loading, deduplication, token trimming
- resolver_store.go: persistence (storeRound, storeMessages, asset linking)
- resolver_memory.go: memory provider integration
- resolver_model_selection.go: model selection and candidate matching
- resolver_identity.go: display name and channel identity resolution
- resolver_settings.go: bot settings, loop detection, inbox
- user_header.go: YAML front-matter formatting
- resolver_util.go: shared utilities (sanitize, normalize, dedup, UUID)

* fix(agent): enable Anthropic extended thinking by passing ReasoningConfig to provider

Anthropic's thinking requires WithThinking() at provider creation time,
unlike OpenAI which uses per-request ReasoningEffort. The config was
never wired through, so Claude models could not trigger thinking.

* refactor(agent): extract prompts into embedded markdown templates

Move inline prompt strings from prompt.go into separate .md files under
internal/agent/prompts/, using {{key}} placeholders and a simple render
engine. Remove obsolete SystemPromptParams fields (Language,
MaxContextLoadTime, Channels, CurrentChannel) and their call-site usage.

* fix: lint
2026-03-19 13:31:54 +08:00

171 lines
3.7 KiB
TOML

experimental_monorepo_root = true
[tools]
# Go version from go.mod
go = "1.25.6"
# Node.js for frontend packages
node = "25"
# Bun for browser gateway
bun = "latest"
# pnpm for workspace management
pnpm = "10"
# sqlc for sql management
sqlc = "latest"
# typos for spell check
typos = "latest"
# golangci-lint for Go linting
"golangci-lint" = "2.10.1"
[task_config]
dir = "{{cwd}}"
[settings]
experimental = true
[tasks.pnpm-install]
description = "Install dependencies"
env = { CI = "true" }
run = "pnpm install"
[tasks.docs]
description = "start documentation"
run = "pnpm docs:dev"
[tasks.go-install]
description = "Install Go dependencies"
run = "go mod download"
[tasks.swagger-generate]
description = "Generate Swagger documentation"
depends = [
"//:go-install",
]
run = "cd internal/handlers && go generate"
[tasks.sdk-generate]
description = "Generate SDK code"
run = "pnpm run generate-sdk"
depends = [
"//:pnpm-install",
"//:swagger-generate"
]
[tasks.sqlc-generate]
description = "Generate SQL code"
run = "sqlc generate"
[tasks.dev]
description = "Start development environment"
run = """
#!/bin/bash
set -e
docker compose -f devenv/docker-compose.yml up --build
"""
[tasks."dev:down"]
description = "Stop development environment"
run = "docker compose -f devenv/docker-compose.yml down --remove-orphans"
[tasks."dev:logs"]
description = "View development logs"
run = "docker compose -f devenv/docker-compose.yml logs -f"
[tasks."dev:restart"]
description = "Restart a service (usage: mise run dev:restart -- server)"
run = "docker compose -f devenv/docker-compose.yml restart $@"
[tasks."bridge:build"]
description = "Manually rebuild bridge binary in dev container (normally auto-triggered by air)"
run = """
#!/bin/bash
set -e
docker compose -f devenv/docker-compose.yml exec server \
sh -c 'cd /workspace && sh devenv/bridge-build.sh'
"""
[tasks.db-up]
description = "Initialize and Migrate Database"
run = "scripts/db-up.sh"
[tasks.db-down]
description = "Drop Database"
run = "scripts/db-drop.sh"
[tasks.release]
description = "Release new version"
run = "pnpm release"
[tasks.build-embedded-assets]
description = "Build and stage embedded web assets"
run = "scripts/release.sh --prepare-assets"
depends = ["//:pnpm-install"]
[tasks.build-unified]
description = "Build unified memoh binary"
depends = ["//:build-embedded-assets"]
run = "go build -o bin/memoh ./cmd/memoh"
[tasks.release-binaries]
description = "Build release archive for one target (requires TARGET_OS TARGET_ARCH)"
depends = ["//:pnpm-install"]
run = "scripts/release.sh"
[tasks.install-cli]
description = "Install CLI"
depends = ["//:pnpm-install"]
run = "cd packages/cli && npm install -g"
[tasks.install-socktainer]
description = "Install socktainer"
run = "brew tap socktainer/tap && brew install socktainer"
[tasks.install-workspace-toolkit]
description = "Install workspace toolkit"
run = "cd docker/toolkit && ./install.sh"
[tasks.lint]
description = "Run all linters"
depends = [
"//:lint:go",
"//:lint:es",
]
[tasks."lint:fix"]
description = "Run all linters with auto-fix"
depends = [
"//:lint:go:fix",
"//:lint:es:fix",
]
[tasks."lint:go"]
description = "Run Go linter"
run = "golangci-lint run ./..."
[tasks."lint:go:fix"]
description = "Run Go linter with auto-fix"
run = "golangci-lint run --fix ./..."
[tasks."lint:es"]
description = "Run ESLint"
run = "pnpm lint"
[tasks."lint:es:fix"]
description = "Run ESLint with auto-fix"
run = "pnpm lint:fix"
[tasks.setup]
description = "Setup development environment"
depends = [
"//:install-workspace-toolkit",
"//:sqlc-generate",
"//:pnpm-install",
"//:go-install",
"//:install-cli",
]
run = """
#!/bin/bash
set -e
echo '✓ Setup complete! Run: mise run dev'
echo ' Dev web UI will be available at http://localhost:18082'
"""