Commit Graph

38 Commits

Author SHA1 Message Date
cg33
a82b01aa27 fix(opencode): eliminate TempDir cleanup race in TestAvailableModels under -cover (#1118) (#1254)
Root cause: AvailableModels() with a warm persistent cache calls
startPersistentModelRefresh(), which spawns a background goroutine that
writes the refreshed model list into the test's TempDir.  When the test
function returns, t.TempDir() runs RemoveAll before that goroutine
finishes its last write — manifesting as:

  TempDir RemoveAll cleanup: unlinkat /tmp/.../001: directory not empty

The race window is too small to hit reliably without -cover; coverage
instrumentation slows the goroutine enough to make it reproducible.

Fix (two-part):
1. Add refreshWg sync.WaitGroup to Agent and track every background
   refresh goroutine with Add(1)/Done() in startPersistentModelRefresh.
   This is a pure bookkeeping addition with zero production behaviour
   change.
2. In TestAvailableModels_PrefersPersistentCacheOverDiscoveredModels,
   register t.Cleanup(func() { a.refreshWg.Wait() }) immediately after
   creating the agent (before AvailableModels is called). Cleanup
   functions run LIFO: our Wait fires before t.TempDir's RemoveAll,
   guaranteeing the goroutine has finished writing before the directory
   is cleaned up.

Verified: go test -count=1 -cover ./agent/opencode/... run 10 times
consecutively — 10/10 PASS, 0 failures.

Co-authored-by: root <root@UYQQVGRAEKQKNQP>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-07 21:18:36 +08:00
cg33
f4d36dbbdf fix(opencode): surface tool rejection error as text to prevent empty response (#178) (#1247)
When opencode rejects a tool call in default mode (e.g. bash permission
denied), it emits a tool_use event with status="error" then exits without
generating any follow-up text. This caused the engine to fall through to
the "(空响应)" / "(empty response)" placeholder since textParts was empty.

Fix: when handleToolUse receives status="error" with a non-empty error
message, emit an EventText containing the rejection reason. This ensures
textParts is populated and the user sees why the command was blocked (e.g.
"The user rejected permission to use this specific tool call.") rather
than a silent empty response.

Three scenarios handled:
- Permission denied (default mode): error text surfaced ✓
- Tool completed successfully: no change ✓
- Error with no message: no spurious empty EventText ✓

To avoid permission rejections entirely, set mode="yolo" in config or
configure opencode's permission settings to allow the required tools.

Fixes #178

Co-authored-by: root <root@UYQQVGRAEKQKNQP>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-07 21:18:25 +08:00
Claude
f86c26634b fix(opencode): pass --agent flag when agent config option is set (#1210)
Adds optional 'agent' config option under [projects.agent.options] for
opencode. When set, the value is passed as --agent to every 'opencode run'
invocation, enabling plugin-defined agents (e.g. oh-my-openagent's
'Sisyphus - Ultraworker') to work correctly without falling back to the
default agent.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-04 10:17:34 +08:00
cg33
0f45c7df88 Merge pull request #1110 from woaillr-crypto/fix/opencode-yolo-skip-permissions
fix(opencode): skip permissions in yolo mode + macOS CheckLinger stub
2026-05-27 23:29:57 +08:00
kslex
5305c78403 fix(opencode): correct sessionID location and step_finish handling
- Fix handleStepStart: prefer sessionID from top-level JSON field, fallback to part
- Fix handleStepFinish: send EventResult when reason=stop, not when tool-calls
- Add resultSent atomic.Bool to prevent duplicate EventResult
- Add unit tests with JSON string construction style matching existing tests
This fixes empty response issue when opencode uses tools (issue #1094, PR #697)
2026-05-27 17:39:10 +08:00
Alloyee
9b11de3d13 fix(opencode): skip permissions in yolo mode + add macOS CheckLinger stub
1. Add --dangerously-skip-permissions flag when opencode agent is in yolo
   mode. Without this, headless runs auto-reject external-directory
   permission requests (e.g. superpowers /init trying to modify
   ~/.config/opencode/), resulting in empty responses delivered to users.

2. Add CheckLinger() stub to daemon/launchd.go for macOS. This function
   is only referenced from daemon.go but was only defined in
   systemd.go (Linux-only build tag), causing build failure on darwin.
2026-05-24 17:17:36 +08:00
Shawn
d6ee8c9671 fix(agent/opencode): capture cmd/workDir under mutex in ListSessions and ProjectMemoryFile (#1006)
ListSessions reads a.cmd and a.workDir without holding a.mu, while
SetWorkDir / SetSessionEnv / StartSession all touch those fields
under the lock. ProjectMemoryFile likewise reads a.workDir directly.
The sibling DeleteSession already uses the canonical
"capture under RLock" pattern; ListSessions and ProjectMemoryFile
were the inconsistent ones.

SetWorkDir mutates a.workDir under a.mu, so /workspace landing on
one goroutine while /list or a memory-file lookup runs on another
races on the string field. Strings carry a (ptr, len) pair, and a
torn read of a different-length string can produce a frankenstring
whose pointer doesn't match its length, leading to memory-safety
failures or empty/garbled paths.

Capture cmd and workDir inside the locked section in ListSessions;
capture workDir in ProjectMemoryFile. No public API or behaviour
change.

Regression: TestOpencodeAgent_WorkDirRaceFreeReaders spawns
concurrent SetWorkDir writers and ListSessions / ProjectMemoryFile
readers under -race. Without the production fix the test trips
"DATA RACE detected"; with the fix the detector stays quiet.
2026-05-18 21:39:18 +08:00
Claude
8ba51086d8 fix(core): harden workspace and media handling
Make local workspace init opt-in and tighten media, session close, and workdir concurrency paths uncovered by the post-merge review.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-18 11:08:17 +08:00
bingkxu
f58e75734f fix(feishu): prevent card action callback timeout on slow operations (#907)
* fix(feishu): prevent card action callback timeout on slow operations

When navigating to /list or similar card actions that call agent.ListSessions(), the synchronous cardNavHandler can exceed Feishu's 3-second callback timeout. This wraps the handler in a goroutine with a 2.5s deadline: fast responses return the card as before; slow responses return a loading toast immediately, then async-refresh the card via the Patch API once complete.

* fix: show session name in /current command with fallback to agent summary

* fix: show session name in /current via SessionTitleProvider fallback to DB query

* fix(opencode): sqlite3 CLI does not support ? placeholders, use inline query

* chore(opencode): use production opencode.db path for SessionTitleProvider

* fix(feishu): fix flaky TestCardAction_NavSlow_ReturnsToastThenRefreshes test

Use channel-based sync (refreshDone) instead of time.Sleep to wait for
async RefreshCard goroutine, eliminating race condition in test.

---------

Co-authored-by: vibecoder <16832299+vibecoder@user.noreply.gitee.com>
2026-05-18 10:13:09 +08:00
bingkxu
afee059e59 fix(opencode): pass prompt via stdin to avoid Windows .cmd newline truncation (#903)
Co-authored-by: vibecoder <16832299+vibecoder@user.noreply.gitee.com>
2026-05-18 10:03:03 +08:00
bingkxu
83b8ecf8c4 fix: handle compaction_continue to prevent engine early exit (#746)
OpenCode CLI sends compaction_continue (synthetic text with metadata) after
auto-compaction to signal continuation. Previously, cc-connect's engine exited
after receiving EventResult from the first turn, missing subsequent events
from the continuation turn (e.g. permission requests).

Changes:
- Add expectingContinue flag to opencodeSession
- Detect compaction_continue in handleText, set flag and skip EventText
- Check flag in readLoop before sending fallback EventResult
- Add Metadata and Synthetic fields to core.Event for future extensibility

Co-authored-by: vibecoder <16832299+vibecoder@user.noreply.gitee.com>
2026-05-05 09:45:43 +08:00
Claude
9613fc85c4 fix(opencode): add -- separator before prompt to prevent --file from consuming it
OpenCode CLI's --file flag is a yargs [array] type that greedily
consumes subsequent arguments as file paths. Without a -- separator,
the prompt text following --file was parsed as a filename, causing
"File not found" errors when images were attached.

Reported-by: community user via image analysis
Made-with: Cursor
2026-04-28 22:07:48 +08:00
bingkxu
e81cc1d568 fix(opencode): prevent empty response when agent process crashes (#720)
When the opencode process crashes (e.g. stale session ID causes
'Session not found'), readLoop sends a fallback EventResult before
the deferred cmd.Wait() can detect and emit an EventError. The
engine receives EventResult(Done:true) first, returns from the
event loop, and the subsequent EventError is never consumed.
The user sees an empty response with no error information.

Fix by checking stderrBuf immediately after the scanner loop exits,
before sending the fallback EventResult. If stderr contains errors
(including 'Session not found'), emit EventError instead.
cmd.Wait() remains in a defer for resource cleanup only.

Engine uses a pattern table (agentErrorHandlers) to match known
errors and show localized user-friendly messages with recovery hints.

Co-authored-by: vibecoder <16832299+vibecoder@user.noreply.gitee.com>
2026-04-27 14:30:30 +08:00
soaringk
d8573c81f6 fix(opencode): pass inbound images as files (#717) 2026-04-24 06:33:54 +08:00
Claude
7980a70a30 chore: fix golangci-lint errors flagged by CI
- management.go: check w.Write return value
- config_cmd.go: check fs.Parse return value
- web_manager.go: remove unused defaultMgmtPort/defaultBridgePort consts
- opencode.go: remove unused discoverModels wrapper
- engine.go: remove ineffectual resolvedWorkspace assignment

Made-with: Cursor
2026-04-15 20:49:13 +08:00
Mr.QiuW
9fc64898ce refactor(opencode): remove unreachable cache path check 2026-04-09 13:07:02 +08:00
Mr.QiuW
adeff4ef8d fix(opencode): handle signature writer errors 2026-04-09 01:18:10 +08:00
Mr.QiuW
1641c42269 feat(opencode): significantly speed up model switching 2026-04-09 01:11:19 +08:00
q107580018
bcb3b292c1 feat(opencode): implement SessionDeleter to enable /delete command (#452)
Add DeleteSession to the opencode agent by calling `opencode session delete <id>`
via the CLI, enabling single, batch, and range deletion from any connected platform.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 22:26:53 +08:00
Claude
fd9e347563 feat(opencode): dynamic model discovery via opencode models (#381)
AvailableModels now runs `<cmd> models` first and falls back to
provider-configured models and the built-in list only when the CLI
command fails or produces no output. Results are deduplicated and
sorted for stable /model output.

Co-authored-by: q107580018 <107580018@qq.com>
Made-with: Cursor
2026-03-31 19:44:42 +08:00
cg33
2e9d75c231 fix(opencode): add warn logs when sqlite3 CLI is missing (#319)
* feat(web): add web admin dashboard (React + Tailwind + TypeScript)

Full-featured management UI for CC-Connect instances:
- Token-based auth, dark/light/system theme, i18n (EN/ZH/ZH-TW/JA/ES)
- Dashboard with system status, project overview
- Project management with providers, heartbeat, settings tabs
- Session list and chat interface with Markdown rendering
- Cron job management (create/delete)
- Bridge adapter viewer
- System config viewer, logs, restart/reload controls
- All endpoints aligned with docs/management-api.md

Made-with: Cursor

* feat(web): improve session UI, markdown rendering, and API richness

- Enrich session list/detail API with live status, last_message preview,
  agent_type, platform, user metadata, and timestamps
- Add SessionKeyMap() helper to core/session.go for ID-to-key mapping
- Redesign SessionList as responsive grid layout with project filtering,
  time-ago display, and last message preview
- Upgrade markdown rendering: rehype-highlight for syntax highlighting,
  @tailwindcss/typography for proper prose styling, copy-to-clipboard on
  code blocks, GitHub light/dark themes
- Show live/offline session status; disable message input for non-live sessions
- Update management-api.md to document new session fields
- Remove node_modules from git tracking and add to .gitignore

Made-with: Cursor

* chore: add .vite/ to .gitignore

Made-with: Cursor

* fix(opencode): add warn logs when sqlite3 CLI is missing or query fails

The /list command silently showed 0 messages when sqlite3 was not installed
or the DB query failed. Now logs a warning so operators can diagnose the
issue. Fixes #318.

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

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-25 11:30:53 +08:00
liujing
33ca94e2f1 test(opencode): add regression tests for session list parsing (#262)
Add two focused tests to prevent regression:

1. TestOpencodeSessionEntry_Unmarshal - verifies OpenCode's JSON output
   with int64 timestamps can be unmarshaled (prevents the type mismatch
   error: cannot unmarshal number into ... of type string)

2. TestNewOpencodeSession_ContinueSessionTreatedAsFresh - verifies the
   __continue__ sentinel is not passed as literal session ID to CLI
   (regression test for PR #249)

Co-authored-by: Liujing <liujing@LiujingdeMacBook-Pro.local>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 21:38:27 +08:00
quabug
71a2f9b284 fix: ignore ContinueSession sentinel in non-Claude agents
* fix: ignore ContinueSession sentinel in non-Claude agents

The ContinueSession ("__continue__") sentinel was introduced in df5cc64
for the --continue bridge, but only the claudecode agent was updated to
handle it. All other agents (pi, gemini, codex, cursor, qoder, opencode,
iflow) stored the literal "__continue__" as their session/resume ID,
causing CLI failures like `No session found matching '__continue__'` and
persistent "(empty response)" replies.

The fix adds a `resumeID != core.ContinueSession` guard to each agent's
session constructor so the sentinel is treated as "" (fresh session).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(codex): remove --cd from exec resume args

The codex CLI's `exec resume` subcommand does not support --cd, causing
"unexpected argument '--cd'" errors on every resumed session. The process
working directory is already set via cmd.Dir, so --cd is unnecessary.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 10:21:11 +08:00
Claude
76e62c7be7 test: improve coverage across agents and platforms
- agent/claudecode: Add tests for Name, CLIBinaryName,
  CLIDisplayName, SetWorkDir, GetWorkDir, SetModel, SetSessionEnv,
  SetPlatformPrompt, stripXMLTags
- agent/opencode: Add tests for normalizeMode, Name, SetModel,
  GetMode, GetActiveProvider, ListProviders, SetActiveProvider
- agent/qoder: Add tests for normalizeMode, Name, CLIBinaryName,
  CLIDisplayName, SetWorkDir, SetModel
- platform/line: Add tests for Platform initialization, Name,
  credential validation, port/path configuration
- platform/qq: Add tests for Platform initialization, ws URL,
  token, allowFrom, shareSessionInChannel
- platform/qqbot: Add tests for Platform initialization,
  credential validation, intents, sandbox, markdown support

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 00:22:40 +08:00
Deeka Wong
9df8d494dd feat(core): align /model switching with provider flow (#246)
Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
2026-03-21 20:32:22 +08:00
Deeka Wong
1123c83edb fix(core): share provider model lookup and stabilize tests (#210)
* fix(core): share provider model lookup and stabilize tests

* fix(tests): address PR review follow-ups

---------

Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
2026-03-19 07:55:48 +08:00
Deeka Wong
80ce4a5632 Add models list to provider config for per-provider model selection via alias (#200)
* Initial plan

* Add models parameter to provider config for /model command support

Co-authored-by: huangdijia <8337659+huangdijia@users.noreply.github.com>

* Change provider models config to alias+model table format with alias-based switching

Co-authored-by: huangdijia <8337659+huangdijia@users.noreply.github.com>

* Update README and docs with /model command and [[providers.models]] alias config format

Co-authored-by: huangdijia <8337659+huangdijia@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: huangdijia <8337659+huangdijia@users.noreply.github.com>
2026-03-18 17:44:44 +08:00
Gaoyuan-SIAT
f04c7c51cd feat: add /dir command for dynamic work directory switching 2026-03-16 12:08:41 +08:00
Shawn
588b22b223 fix(agent): always close events channel on session Close timeout (#163)
Six agent session adapters (codex, cursor, gemini, iflow, opencode,
qoder) only close the events channel when wg.Wait completes within
the 8-second timeout. If the timeout fires, the channel is left open,
which can cause consumers to block indefinitely waiting for channel
closure and prevents the engine from detecting that the session has
ended.

Move close(events) after the select block so the channel is always
closed regardless of whether the timeout fires, matching the pattern
already used by piSession.
2026-03-16 06:46:04 +08:00
kevinWangSheng
be74fddca2 fix(agent): prevent panic from closing events channel while readLoop may still send
In 6 agent session implementations (codex, opencode, qoder, iflow, cursor,
gemini), Close() unconditionally calls close(events) after an 8-second
timeout, even when the readLoop goroutine may still be running and
sending events to the channel. Due to Go's select non-determinism, the
readLoop goroutine can choose the send case over the ctx.Done() case,
causing a "send on closed channel" panic.

Move close(events) into the case where wg.Wait() succeeds (readLoop has
fully exited), and skip closing on timeout to prevent the race. This
follows the same safe pattern already used by claudeSession, where the
events channel is only closed after the readLoop goroutine has finished.
2026-03-14 08:36:29 -07:00
chenhg5
c7aca28196 feat(opencode): enhance session handling and error reporting
Add message counts and timestamps to session listings. Improve error handling with detailed error message extraction. Enhance tool event handling with better input summaries. Add proper session completion events and step finish logging.

generated by llmgit

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-14 09:54:52 +08:00
zhuguanqi
9be1b78295 feat: enable file attachment support for all agents
Extract SaveFilesToDisk/AppendFileRefs helpers into core package and
wire up file handling for Cursor, Codex, OpenCode, Qoder, and iFlow.
Files are saved to .cc-connect/attachments/ and paths are appended to
the prompt so each CLI can read them with its built-in tools.
Also refactors Claude Code to reuse the shared helper.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 11:16:55 +08:00
zhuguanqi
f7cbc8c2d0 feat(feishu): add file message support
Add FileAttachment type and wire up file handling across the stack so
that files sent in Feishu are downloaded and forwarded to agents.
Claude Code saves files locally for tool-based reading; Gemini passes
them as temp file references. Other agents log a warning and ignore.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 11:16:55 +08:00
chenhg5
8818d3bed1 refactor(agent): optimize scanner buffer sizes
Updated buffer sizes for stdout scanners across all agent sessions:
- Initial buffer size reduced from 1MB to 64KB
- Max buffer size increased from 1MB to 10MB

generated by llmgit

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-12 06:34:02 +08:00
chenhg5
5e0a192b01 feat(claudecode): add provider proxy support for third-party endpoints
Add local reverse proxy support for third-party Claude providers with:
- Thinking parameter override rewriting
- Bearer token auth compatibility
- Provider clearing functionality
- Configurable thinking modes
- Improved provider management UX
- Enhanced markdown rendering for Feishu

generated by llmgit

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-04 23:57:13 +08:00
chenhg5
f2920739d8 feat: add timeout handling for agent session closure
Added timeout mechanisms with logging for graceful session closure across multiple agent types (claudecode, codex, cursor, gemini, opencode, qoder). Modified engine cleanup to handle timeouts and improve logging. Sessions now timeout after 8-10 seconds with appropriate warnings/errors.

generated by llmgit

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-04 22:02:54 +08:00
chenhg5
e8e39413e8 refactor(session): add context-aware event sending and secure arg logging
Add context-aware select statements when sending events to prevent blocking on closed channels. Implement secure argument logging using RedactArgs to mask sensitive flags. Add atomic file writes and locks for config safety. Improve session handling with mutex protection and deduplication checks.

generated by llmgit

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-04 12:38:37 +08:00
shenghui kevin
5d54487237 feat(agent): add OpenCode support
OpenCode (`opencode run --format json`) streams NDJSON events,
similar to the Gemini agent. This wires it up so users can drive
OpenCode from Telegram / Discord / Slack / etc.

- agent/opencode/opencode.go — agent struct, factory, model/mode/provider switching
- agent/opencode/session.go  — subprocess lifecycle, NDJSON event → core.Event mapping
- cmd/cc-connect/main.go     — register the "opencode" agent
2026-03-03 15:55:57 -08:00