Commit Graph
1432 Commits
Author SHA1 Message Date
viettranx 3b445d6856 fix(agent): close symlink escape + path-alias dedup + TTS mime type
Review of the medium-batch landed this session surfaced three issues:

P0 — symlink-ancestor escape in extractMediaFromContent. The lexical
filepath.Rel check passed "<ws>/shared/secret" when "shared" was a
symlink pointing outside the workspace. EvalSymlinks the resolved path
(and the workspace root, since macOS uses /var → /private/var) before
the Rel containment check. Leaf symlinks still rejected by Lstat.

P1 — duplicate attachments from path aliases. parseMediaResult stores
raw tool output ("./tts/x.mp3"); extractMediaFromContent stores Abs+
Clean ("<ws>/tts/x.mp3"). deduplicateMedia's exact-string map let both
through. Normalize the dedup key via filepath.Abs + Clean so the
sources collapse.

P1 — TTS Result.Media used the non-standard "audio/mp3" via
"audio/"+Extension. SynthResult.MimeType is already populated by every
provider with the RFC-3003 "audio/mpeg" (or "audio/ogg" for opus).
Prefer it; keep the extension concat as empty-string fallback.

Tests: add symlink-leaf-rejected and ancestor-symlink-escape cases to
lock the P0 behavior.
2026-04-18 15:40:24 +07:00
viettranx 2a61365353 fix(docker): set 0755 on web static assets so nginx worker can read
pnpm build under a restrictive umask produces 0600 files; when copied
into nginx:alpine, the non-root nginx worker hits EACCES and serves
403 for every static asset. Force mode via COPY --chmod=0755 (Docker
BuildKit applies uniformly — directories need the exec bit for
traversal, static files don't care about the extra bit).

Closes #761
2026-04-18 15:34:46 +07:00
viettranx 8fb0300914 fix(tts): set Result.Media so provider bridges forward attachments
TTS relied solely on ForLLM "MEDIA:<path>" parsing. claude_cli's MCP
bridge reshapes ForLLM before the agent sees it, so rs.mediaResults
stayed empty and mp3s never attached to outbound messages.

Populate Result.Media alongside the legacy ForLLM prefix (matching
create_audio.go). The agent loop prefers explicit Result.Media over
the ForLLM fallback.

Closes #806
2026-04-18 15:34:46 +07:00
viettranx 3ed3fd9832 fix(agent): extract MEDIA: paths from LLM response before sanitize
When a tool returns its artifact via ForLLM "MEDIA:<path>" and the LLM
echoes that path in its final response (PDF from exec/weasyprint, TTS
bridged through claude_cli MCP, etc.), sanitize stripped the token
without populating rs.mediaResults — attachments never reached the
channel.

Add extractMediaFromContent() and call it right before
SanitizeAssistantContent. Tight security: workspace must be set,
relative paths resolve against workspace, absolute paths must stay
inside workspace (blocks ../ escapes and sibling-tenant access),
file must exist and be a regular file. Dedup prevents duplicates
when a tool already populated Result.Media.

Closes #882
2026-04-18 15:34:46 +07:00
viettranx 226aa8ed11 fix(make): use --pull always in up, split up-build for local source
'make up' now pulls the latest published image instead of rebuilding
from local context, which was overwriting freshly pulled images with
stale cache. New 'make up-build' target preserves the build-from-source
flow for developers iterating on the backend.

Closes #934
2026-04-18 15:09:46 +07:00
viettranx c06d15be5f fix(ui): canonicalize timezone dropdown to drop deprecated aliases
Resolve each IANA name via Intl.DateTimeFormat().resolvedOptions() so
aliases like Asia/Saigon collapse into their canonical form
(Asia/Ho_Chi_Minh). Prevents cron/heartbeat pickers from saving a
deprecated alias that diverges from the Go-side canonical name.

Closes #760
2026-04-18 15:09:46 +07:00
viettranx 001d9e23e3 feat(tools): append scope-filtered outlinks footer to vault_read
List up to 20 wikilink/reference outlinks as "## Links" after the doc
body, deduped by target, scope-filtered via existing allowed() matrix.
Non-fatal — store errors log and skip the footer.
2026-04-18 15:02:34 +07:00
viettranx e033b357cc fix(tools): route read_audio transcription models to /audio/transcriptions (#858)
Transcription-only models (whisper-1, gpt-4o-transcribe,
gpt-4o-mini-transcribe) were sent to /chat/completions with an
input_audio content part, which OpenAI rejects with "not a chat model".
Add isTranscriptionModel detection and a multipart/form-data call to
/v1/audio/transcriptions for those models; chat-audio models
(gpt-4o-audio-preview) continue to use /chat/completions.

Also fix providerTypeFromName to treat "openai-*" prefixed providers
as "openai" type so a dedicated "openai-audio" provider reaches the
OpenAI-specific path instead of falling through to the generic chat
fallback.
2026-04-18 14:54:51 +07:00
viettranx 497849f746 fix(teams): propagate local_key in team task completion/fail broadcasts (#877)
Forum topic routing (Telegram supergroup threads) relies on local_key
carried through team task events to pick the correct thread for
notifications. Four broadcast sites dropped local_key by relying on
WithContextInfo(ctx) alone — but the member agent's isolated context
does not carry the originating local_key.

Read task.Metadata[TaskMetaLocalKey] explicitly and pass via
WithLocalKey() to match the already-correct pattern in
team_tool_dispatch.go and team_tasks_blocker.go.

Covered sites:
  - team_tasks_lifecycle.executeComplete → EventTeamTaskCompleted
  - gateway_consumer_post_turn agent-error → EventTeamTaskFailed
  - gateway_consumer_post_turn loop-kill → EventTeamTaskFailed
  - gateway_consumer_post_turn auto-complete → EventTeamTaskCompleted
2026-04-18 14:53:42 +07:00
viettranx 564997cfae fix(consolidation): pass parsed agentUUID to ExistsBySourceID (#809, #824)
Line 52 parses agent_id into agentUUID but line 59 passed the raw
event.AgentID string to ExistsBySourceID. PR #826 fixed the emission
side (loop_finalize.go) so event.AgentID is now always a valid UUID,
but the consumption side kept the inconsistent parse-then-discard
pattern.

Use agentUUID.String() to keep the parse-once-use-parsed invariant,
matching the tenantUUID pattern two lines above. Fixes the
"invalid input syntax for type uuid" error reported in #809 and the
downstream "..." Telegram symptom in #824 where episodic failure
cascaded into empty agent replies.
2026-04-18 14:52:18 +07:00
viettranx 91d79ce120 fix(providers): capture claude-cli stream errors and surface real message (#884)
claude-cli emits API errors (rate limits, usage limits) via stream-json
stdout result events, not stderr. Previous code only checked
ev.Subtype == "error" and used an empty stderr buffer in the final
wrap, so users saw a generic "something went wrong" instead of the
real cause.

- Add IsError and Error fields to cliStreamEvent to parse both signals
- Capture stream error message when FinishReason flips to "error"
- Substitute captured message when stderr is empty in cmd.Wait path
- Extend gateway rate-limit classifier to recognize "usage limit"
2026-04-18 14:42:17 +07:00
viettranx 96cc940f2b fix(providers): whitelist effort env vars in filterCLIEnv + wire per-agent --effort (#886)
filterCLIEnv stripped all CLAUDE_* env vars except OAUTH_TOKEN,
preventing CLAUDE_CODE_EFFORT_LEVEL and CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING
from reaching the subprocess. Switch to an explicit allowlist map that
preserves auth + behavioral tuning vars.

Add effort parameter to buildArgs and plumb OptThinkingLevel from
req.Options through Chat/ChatStream so per-agent reasoning level maps
to --effort flag. When an explicit flag is set, strip the env var to
avoid precedence ambiguity. Validate effort with isAlphaOnly to reject
malformed input.
2026-04-18 14:42:10 +07:00
viettranx 339b13e8f0 fix(providers): return error on Codex response.failed instead of silent success (#888)
response.failed was lumped with response.completed/incomplete, causing
silent empty responses with no retry. Split into its own case that
returns a descriptive error from processSSEEvent, propagated up to
ChatStream caller for proper error surface and retry logic.

Added codexErrorDetail to codexAPIResponse to parse the error payload.
2026-04-18 14:42:02 +07:00
Raihan 222ccfbc5b fix(skills): avoid false invalid zip uploads (#893) 2026-04-18 14:23:20 +07:00
viettranx a5520044b7 feat(agent): wire vault_read into system-prompt tool summaries (#948)
Part of the vault_read feature. Amend coreToolSummaries so the LLM sees:
- read_file: workspace-scoped, redirect to vault_read for vault discovery
- vault_search: explicit chaining hint to pass doc_id to vault_read
- vault_read: new summary describing shared/personal/team access
2026-04-18 12:27:28 +07:00
viettranx 2338ca53d5 feat(tools): add vault_read tool for shared/personal/team vault docs (#948)
Agents could not read vault docs registered at the tenant workspace root
because read_file enforces a per-agent workspace boundary. vault_read
fetches content by doc_id (from vault_search) with scope-based access
checks (shared/personal/team), a 3-layer text-only gate (DocType +
extension blocklist + UTF-8 sniff), 500KB default cap / 1MB ceiling,
and symlink/hardlink guards shared with read_file. Updated system-prompt
summaries and boundary-error hints so the LLM chains vault_search →
vault_read instead of retrying read_file.
2026-04-18 12:27:28 +07:00
040b0f1944 fix(acp): Gemini ACP protocol fixes and multi-session architecture (#901)
* fix(cli): add missing X-GoClaw-User-Id header to gateway client

* feat(acp): comprehensive integration with Gemini ACP protocol

- Support nested JSON-RPC notification structures
- Add robust streaming text collection and mapping
- Increase handshake timeout to 60s for heavy model initialization
- Fix WebSocket user_id authentication and schema v47 compatibility
- Allow Google/GCP environment variables for ACP subprocesses

* refactor(acp): multi-session architecture with session tracing and temp session cleanup

- One shared Gemini process, multiple ACP sessions per process (one per goclaw conversation)
- resolveSession: per-key mutex prevents TOCTOU race on concurrent session creation
- Respawn detection via proc pointer comparison; session/load fallback after crash
- sessionReaper: purges ACP sessions idle >30min; temp- sessions purged immediately on completion
- WithGoclawSession context propagation: goclaw session key appears alongside ACP sid in all logs
- dispatchUpdate: Gemini agent_message_chunk protocol mapping normalized here
- session_test.go: full coverage of multi-session API (Initialize, NewSession, Prompt, Cancel, dispatch)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(acp): align with ACP protocol standard (SDK v0.16.1)

- InitializeRequest: "capabilities" → "clientCapabilities" (standard field name)
- LoadSessionRequest: add mcpServers field (required by standard)
- mapStopReason: add standard stop reasons (max_tokens, cancelled)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(acp): address review findings from PR #901

- B1: Restore RequiredSchemaVersion to 55 (was incorrectly set to 47)
- S1: Move X-GoClaw-User-Id header outside token check
- S2: Add env gate (ACP_GEMINI_E2E) to Gemini E2E test
- S3: Fix tab indentation in jsonrpc.go writeMessage
- Build: Extract Pdeathsig to platform-specific files for cross-platform build

* fix(acp): address S4-S7 review findings

S4/S5: Send session/cancel before purging sessions locally
- purgeSession() now cancels ACP session before deleting map entry
- sessionReaper() sends cancel notification for idle sessions
- Updated comments to reflect actual behavior

S6: Tighten GOOGLE_/GCP_ env var filtering
- Add GOOGLE_, GCP_ back to sensitiveEnvPrefixes
- Add allowedEnvExact for safe vars: GOOGLE_API_KEY,
  GOOGLE_APPLICATION_CREDENTIALS, GOOGLE_CLOUD_PROJECT, GCP_PROJECT

S7: Propagate ACP errors to callers
- Chat/ChatStream now return err alongside ChatResponse
- Enables upstream retry logic and error metrics

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: viettranx <viettranx@gmail.com>
2026-04-18 12:17:23 +07:00
Thieu Nguyen 5ee39c74af fix(docker): exclude node deps and dist from build context (#949)
Root .dockerignore did not exclude local dependency folders, so
COPY ui/web/ . shipped ui/web's local install into the web-builder
stage. Stale artifacts (e.g. leftover rollup@4.57.1 from older vite@6)
then overrode the result of `pnpm install --frozen-lockfile`,
breaking the musl build on Alpine with:

  Cannot find module @rollup/rollup-linux-arm64-musl

Add explicit ignores for ui/web dependency and dist folders plus a
catch-all for any nested dep folder so Docker builds are
deterministic and match CI regardless of local dev state. Also
speeds up build context transfer.
2026-04-18 09:17:14 +07:00
Thieu Nguyen 406022e79f fix(security): close auth bypass + default-permit RBAC (issue #866) (#950)
Fixes a 3-vuln chain enabling unauthenticated/underprivileged access to
admin surfaces:

1. Auth bypass (router.go): invalid tokens silently fell through to
   anonymous role. Now reject on token presence with invalid/expired.
2. Default-permit RBAC (policy.go): unknown methods returned a writable
   role. Now fail-closed: unknown -> RoleNone.
3. Missing admin classifications: several sensitive methods weren't in
   any allowlist and slipped through default-permit. Now explicitly
   classified (admin/write/read).

Additional hardening:
- Remove isWriteMethod prefix fallbacks; use exact allowlist only to
  prevent silent scope creep when new methods are added.
- Classify Phase-3 methods (TTS, browser, zalo, whatsapp) into
  admin/write/read per sensitivity.
- Gate empty MethodRole in router dispatcher.

Tests:
- TestMethodRole_ApprovalsList_IsViewer: asserts exec.approval.list is
  viewer and approve/deny are operator.
- TestMethodRole_DriftCoverage_AllProtocolMethodsClassified: AST-parses
  pkg/protocol/methods.go at test time; asserts every Method* constant
  resolves to a non-None role. Permanent drift guard for future adds.
2026-04-18 08:08:29 +07:00
viettranx a29938ceed fix(agent): propagate SenderID in AgentEvent emitters
Expose the original acting sender ID in agent events so group-chat
telemetry and audit logs stay aligned with the real Telegram user
instead of only the group-scoped UserID.
2026-04-17 20:45:48 +07:00
viettranx 680521a882 refactor(tts): extract saveOrFail helper in tts config handler
Collapse 16 repeated Set + slog.Error + http.Error blocks in handleSave
into a single saveOrFail helper. Net -61 LOC, easier to add new keys.
2026-04-17 20:16:21 +07:00
Junghwanandviettranx f729b2d618 Prevent TTS test-connection from bypassing provider URL guards (#937)
The repo already validates provider base URLs during provider CRUD, but
TTS test-connection built ephemeral providers from user-supplied api_base
without reusing that protection. This change applies the same validation
at test time and adds regression coverage for blocked loopback targets.

Constraint: Must preserve current local-provider SSRF policy semantics from provider validation
Rejected: Restrict test-connection to admins only | larger behavior change than needed for the bug
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep TTS test-connection URL validation aligned with validateProviderURL behavior for provider CRUD
Tested: go test ./internal/http -run 'TestTestConnection_(MissingProvider|UnsupportedProvider|MissingAPIKey|BelowOperator|BlockedAPIBase)$' -count=1 -v
Tested: go build ./...
Tested: go build -tags sqliteonly ./...
Not-tested: Full repo race test suite

Co-authored-by: viettranx <viettranx@gmail.com>
2026-04-17 20:15:44 +07:00
Junghwan 93ce4fa9d9 Restore TTS config compatibility and fail closed on save errors (#938)
The new per-tenant TTS config surface diverged from the established TTS
schema after the audio refactor, dropping UI alias fields and root-level
settings during round-trip. It also returned ok=true even when non-secret
system config writes failed. This patch accepts backward-compatible field
aliases, round-trips timeout and Edge settings, reuses tenant timeout/rate
when building ephemeral providers, and returns errors on failed saves.

Constraint: Must preserve the existing TTS config schema expected by dashboard flows and legacy config docs
Rejected: Fix only the UI payload shape | backend would still break legacy aliases and direct API callers
Confidence: high
Scope-risk: moderate
Reversibility: clean
Directive: When extending per-tenant config handlers, keep request/response structs aligned with the established config schema and do not ignore store write errors
Related: #935
Related: #936
Tested: go test ./internal/http -run 'Test(TTSConfig|TestConnection_)' -count=1 -v
Tested: go build ./...
Tested: go build -tags sqliteonly ./...
Not-tested: Full repo race test suite
2026-04-17 20:04:16 +07:00
badgerbees 544b6c6532 Providers: strip Gemma 4 reasoning leak (#933) 2026-04-17 19:58:51 +07:00
Duc Nguyen 304ce72299 fix(tests): resolve integration test compile errors (#939)
* fix(tests): resolve integration test compile errors

- Remove duplicate allowLoopbackForTest in hooks_pipeline_test.go (canonical version lives in v3_test_helper.go)
- Remove unused fakeClient assignment in mcp_grant_revoke_test.go; fakeMCPClient type retained for future use

* ci: bump unit test timeout from 90s to 5m

The internal/hooks/handlers package binary under `-race -coverpkg=./...`
now runs up against the 90s cap because HTTPHandler retry uses a real
`time.After(1 * time.Second)` backoff across three HTTP test cases, and
goja-based memory-bomb sandbox tests have large allocations that run
inline before the sandbox deadline kicks in.

Recent main CI has been red with this timeout firing on different slow
tests each run (TestHTTP_5xxRetriesOnce, TestCorpus_MemoryBombString).
Bumping to 5m keeps the deadlock safety net (still half the 10-minute
Go default) while giving slow-but-non-deadlocked packages room.

Followup: make HTTPHandler backoff configurable so tests can override
with ms-scale delays and the 90s cap can come back.

Also update `make test` in Makefile to match.

* test(mcp): skip RevokeUserGrant test pending Phase 02 implementation

Commit 8b8da3a3 added this test alongside the grant-checker, but the
user-grant revocation semantics were never implemented: ListAccessible's
SQL treats an absent mcp_user_grants row as "allowed by default"
(WHERE mug.id IS NULL OR mug.enabled = true), so RevokeFromUser's DELETE
leaves the server accessible.

The test never actually ran in CI until the prior compile fix in this PR
unblocked the integration test binary. It's safe to skip — the agent-grant
counterpart test still exercises the grant-recheck code path. Re-enable
once user-grant-required semantics land.
2026-04-17 19:55:56 +07:00
viettranx 25825fce4f fix(ui): sync chat-input textarea height on mount via useLayoutEffect
Add useLayoutEffect hook to sync textarea height whenever value changes
or component mounts. Prevents browser's default rows=1 height from
leaving a gap above the icons when textarea content is externally
reset (e.g., after send). Adjust icon padding for better vertical
alignment with multi-line textarea.
2026-04-17 19:50:17 +07:00
viettranx b536f83c1a chore: ignore nginx.staging.conf in ui/web 2026-04-17 19:50:13 +07:00
viettranx 83e4f8b907 fix(tests): add ResetStuckSummoning stub to agent store mocks
Add missing ResetStuckSummoning method stub to mock AgentStore
implementations in test files. Follows from recent agent recovery
feature (d7342fbd) which added this method to the AgentStore interface
but missed updating these 4 test mock implementations.
2026-04-17 19:50:11 +07:00
viettranx 4198084050 feat(skills): pip build-fail log hints for troubleshooting
Add pipBuildFailHint helper that suggests root causes when pip wheel build fails.
Detects missing system deps (pg_config for psycopg, libssl for cryptography, etc).
Hints suggest apt/brew/yum package names or pip alias alternatives (psycopg2→psycopg2-binary).
Wired to dep_installer stderr/stdlog post-build-failure for visibility.
2026-04-17 19:46:43 +07:00
viettranx 3d6723e7c0 feat(skills): SKILL.md deps/exclude_deps frontmatter with validation
Add manifest-origin dependency declarations in SKILL.md frontmatter.
New fields: deps (pip/npm/system) and exclude_deps (override search results).
Validates dependencies against per-category regex allowlists to prevent injection.
Manifest overrides can extend or reduce auto-discovered deps.
Backward compatible: skills without deps:/exclude_deps: behave identically.
Includes regression guard (bundled_smoke_test.go) for 5 bundled skills.
2026-04-17 19:44:50 +07:00
viettranx 526f6c11a3 fix(skills): add pip alias map entries for psycopg2/psycopg/MySQLdb/Crypto/serial/skimage/Levenshtein
Add pip package alias resolutions for commonly-misnamed or distribution-variant packages.
psycopg2 shipped as sdist-only on PyPI (requires pg_config); aliases to psycopg2-binary.
Other entries handle distribution variants (MySQLdb→mysqlclient, Crypto→pycryptodome, etc).
2026-04-17 19:44:44 +07:00
viettranx 5db1a77e6f fix(providers): close HTTP/startup parity for Anthropic + ClaudeCLI onboarding
Follow-up to #942. The HTTP onboarding path (registerInMemory) still diverged
from the startup path in two ways that #942 deliberately deferred:

1. Anthropic: startup wires WithAnthropicRegistry(modelReg) (cmd/gateway_providers.go:349),
   HTTP skipped it — forward-compat model resolution + token counting used static
   defaults for HTTP-onboarded providers.

2. Claude CLI: startup validates filepath.IsAbs + exec.LookPath before registering
   (cmd/gateway_providers.go:290-297), HTTP skipped both — DB could be poisoned
   with relative paths (resolves against CWD) or non-existent binaries that would
   pass verify but crash on first spawn.

Changes:
- Add ProvidersHandler.modelReg field + SetModelRegistry setter
- Thread modelReg through wireHTTP in cmd/gateway_http_handlers.go
- Anthropic branch: append WithAnthropicRegistry when modelReg non-nil
- Claude CLI branch: mirror startup validation (reject non-absolute, skip if LookPath fails)

Tests added:
- TestProvidersHandlerRegisterInMemorySkipsClaudeCLIWhenBinaryMissing — asserts
  provider NOT registered when binary path cannot be resolved
- TestProvidersHandlerRegisterInMemoryAnthropicUsesModelRegistry — reflection-probe
  verifies registry wiring (no public getter on AnthropicProvider)
- Updated existing CLI test to use a real temp binary so exec.LookPath succeeds
  regardless of whether \`claude\` is installed in the runner's PATH
2026-04-17 19:13:32 +07:00
viettranx bd3ab6d390 fix(ui): contact user-type badge contrast in light mode
White text on bg-primary (oklch 0.62) scored ~3:1 and failed WCAG AA.
Switch the user badge to an outline with a soft primary tint so the
label stays readable in light mode while still visually distinct from
the group (secondary) and topic (outline) types.
2026-04-17 19:07:01 +07:00
viettranx 3c39b7d2a0 fix(contacts): merge contact into existing tenant user
- user_search: return tenant_user UUID in new "uuid" field so callers
  forwarding a tenant_user foreign key receive the primary key instead
  of the user_id string (root cause of HTTP 400 "invalid JSON" on
  /v1/contacts/merge when linking to an existing tenant user)
- use-user-picker: add opt-in valueMode prop ("user_id" default | "uuid")
  so only merge-contacts-dialog commits UUID; other pickers (tenant
  add-user, MCP/CLI credentials) keep returning user_id string
- pg.MigrateUserDataOnMerge: split tClauseIns/tClauseDel with correct
  placeholder offsets (N+2 for INSERT/UPDATE, N+1 for DELETE) — reusing
  one clause caused "no parameter \$N+2" errors that silently skipped
  every cleanup DELETE, leaving orphan per-user rows after a merge
2026-04-17 19:07:01 +07:00
viettranx f2325f6d98 feat(desktop): add cancel-summon button in SummoningModal
Add Cancel button in SummoningModal after 60s threshold. Call POST
/v1/agents/{id}/cancel-summon via getApiClient(). Update agent status
to summon_failed. Add i18n strings for en/vi/zh in desktop locale.
2026-04-17 19:02:53 +07:00
viettranx 2a7a8f9a84 feat(web): add cancel-summon button in SummoningModal
Add Cancel button in SummoningModal after 60s threshold. Call POST
/v1/agents/{id}/cancel-summon via useHttp hook. Update agent status
to summon_failed. Add i18n strings for en/vi/zh in agents locale.
2026-04-17 19:02:53 +07:00
viettranx d7342fbd6e feat(agents): 3-layer recovery for agents stuck in summoning state
Add ResetStuckSummoning store method (PG + SQLite) + startup sweep to
flip ghost rows to summon_failed on boot. Drop 409 guards on resummon
and regenerate to allow retry. Add POST /v1/agents/{id}/cancel-summon
endpoint + audit event agent.summon_cancelled + i18n (en/vi/zh).
2026-04-17 19:02:53 +07:00
viettranx 7e2e66c095 fix(security): hard-deny ungranted exec for registered CLI binaries
Closes credential-scope bypass where an agent without a `secure_cli_agent_grants` row could still invoke a registered binary via shell fallthrough and pick up inherited env (`$GH_TOKEN`) or on-disk OAuth state. Registration is now an authorization boundary, not only a credential-injection hint.

- Add `SecureCLIStore.IsRegisteredBinary` on PG + SQLite backends — case-insensitive, tenant-scoped.
- New gate branch in `internal/tools/shell.go` (after normalization, before exec approval) with shell-wrapper unwrap depth 3 (sh/bash/zsh/dash -c, env K=V, nohup, stdbuf, timeout), 2s DB-lookup timeout, fail-CLOSED on error. New log events: `security.credentialed_binary_denied`, `security.credentialed_binary_gate_error`, `security.credentialed_binary_wrapper_too_deep`.
- Env scrubbing on host fall-through (`internal/tools/env_scrub.go`) strips static credential keys (GH_TOKEN, AWS_*, OPENAI_API_KEY, …) plus dynamic keys from tenant's registered binaries; preserves HOME/PATH/TERM/LANG/USER/TZ.
- Subagent ExecTool registration (`cmd/gateway_agents.go` → `buildSubagentToolsRegistry`) now receives the same `SecureCLIStore` — parent can't delegate to a child to bypass the gate.
- Binary names lowercased on Create/Update for symmetry with case-insensitive lookup.
- Thread `pgStores.SecureCLI` into `setupSubagents` in `cmd/gateway.go`.
- 25+ unit tests (gate, env-scrub, SQLite IsRegisteredBinary) + 5 PG integration tests (deny-ungranted, allow-granted, unregistered-unchanged, is_global-not-denied regression, shell-wrapper-bypass denied). All green.
2026-04-17 19:02:53 +07:00
Duc Nguyen 92dbb12c84 fix(tests): resolve integration test compile errors
- Remove duplicate allowLoopbackForTest in hooks_pipeline_test.go (canonical version lives in v3_test_helper.go)
- Remove unused fakeClient assignment in mcp_grant_revoke_test.go; fakeMCPClient type retained for future use
2026-04-17 19:02:53 +07:00
Duy /zuey/ 3e542e7087 fix(providers): use DB name for Anthropic/ClaudeCLI in HTTP onboarding (#942)
* fix(providers): use DB name for Anthropic/ClaudeCLI in HTTP onboarding

Commit 7fcf0327 added WithAnthropicName/WithClaudeCLIName on the startup
registration path (cmd/gateway_providers.go) but missed the HTTP onboarding
path (internal/http/providers.go). Providers created via POST /v1/providers
were registered in-memory with the hardcoded default name ("anthropic",
"claude-cli") instead of the user's chosen DB name.

Symptom: user onboards an Anthropic provider named e.g. "my-anthropic",
picks a model, hits verify — handleVerifyProvider looks up via
GetForTenant(tenantID, p.Name) and fails with "provider not registered:
my-anthropic" because the registry key was "anthropic".

Fix: mirror the startup path by passing WithAnthropicName(p.Name) and
WithClaudeCLIName(p.Name) in registerInMemory. Adds two regression tests
asserting custom-named providers are locatable by their DB name and NOT
by the hardcoded default.

Closes incomplete-refactor gap in #742.

* test(providers): add negative assertion for ClaudeCLI default name

Mirrors the Anthropic test's negative guard: when a user picks a custom
provider name, the hardcoded "claude-cli" default must NOT be present in
the registry. Per Claude review on PR #942 — symmetric test coverage.
2026-04-17 19:02:35 +07:00
viettranx b1f6eadf85 feat(channels): TTS auto-apply for Discord/Telegram/WhatsApp + UI enhancements
Backend:
- Add TTS auto-apply support to Discord, Telegram, WhatsApp channels
- Improve text processing for TTS strip markdown
- Wire TTS config handler to gateway server

UI:
- Add voice recorder hook for chat input
- Add agent hooks tab with summary card
- Update i18n for agents (en/vi/zh)
- Minor CSP and credential section fixes
2026-04-16 21:30:10 +07:00
viettranx 284c9cb2cc feat(tts): per-tenant TTS config and per-agent voice override
- Add per-tenant TTS configuration endpoints (GET/POST /v1/tts/config)
  with RoleAdmin auth instead of master scope
- Implement TenantTTSResolver for channels to use tenant-specific
  TTS providers and auto mode settings
- Add per-agent voice override in channel TTS auto-apply:
  - Extend OutboundMessage with AgentID and AgentOtherConfig
  - Inject AgentAudioSnapshot in dispatch.go from outbound message
  - MaybeApply reads tts_voice_id/tts_model_id from agent context
- Fix events.go to use RunContext.TenantID directly (H3)
- Fix dispatch.go error notification to use sendCtx (H1)
- Update UI to use new /v1/tts/config endpoints
2026-04-16 21:26:45 +07:00
viettranx 01014954bd feat(chat): auto-abort agent on exact "stop" keyword during active run
When user sends exact cancel keywords (stop, cancel, abort, thôi, dừng,
hủy, 取消, 停, nevermind) while agent is busy, auto-trigger abort instead
of injecting as follow-up message. Exact match only - "stop now" still
injects normally to avoid false positives.
2026-04-16 20:32:37 +07:00
viettranx 085b89bf72 feat(agent): inject TTS [[tts]] directive guidance when auto mode is "tagged"
- Add TTSAutoMode field to LoopConfig, Loop, SystemPromptConfig
- Wire from config.Tts.Auto through resolver to system prompt
- Inject "## Voice Response" section explaining [[tts]] usage
- Update AGENTS.md: voice only when user explicitly requests
2026-04-16 18:55:43 +07:00
viettranx a050079ade fix(test): resolve data race in TTS concurrent test mock
Add stateless flag to mockTTSProvider to skip capturing opts
during concurrent tests. Prevents race on capturedOpts field.
2026-04-16 18:33:02 +07:00
viettranx a65eaa457a fix(ui): TTS page UX improvements and CSP fix for audio playback
- Add media-src 'self' blob: to CSP for TTS audio blob URLs
- Show advanced config section expanded by default
- Add Save button in credentials section
- Show Voice/Playground sections only after credentials saved
- Improve voice picker message when API key not saved yet
- Add Vite proxy timeout for large audio responses
2026-04-16 18:16:26 +07:00
viettranx c85730e423 Merge main into dev 2026-04-16 17:56:09 +07:00
viettranx 82fe289918 fix(ui): use test-connection endpoint for TTS credential validation
Update CredentialsSection to call /v1/tts/test-connection instead of
/v1/tts/synthesize - allows testing unsaved credentials before save.
2026-04-16 17:55:34 +07:00
Viet Tran 1aa591d314 Merge pull request #929 from nextlevelbuilder/dev
Release: Hooks System, Audio/TTS Refactor, MCP Security & UI Improvements
2026-04-16 17:45:29 +07:00
viettranx 7c5630c27b fix(desktop): add path alias to vite config for @ imports 2026-04-16 17:41:07 +07:00