Skip to content

feat(tokenless): add Trae (TraeCode) adapter - #2530

Open
Forrest-ly wants to merge 6 commits into
alibaba:mainfrom
Forrest-ly:feat/tokenless-trae-adapter
Open

feat(tokenless): add Trae (TraeCode) adapter#2530
Forrest-ly wants to merge 6 commits into
alibaba:mainfrom
Forrest-ly:feat/tokenless-trae-adapter

Conversation

@Forrest-ly

Copy link
Copy Markdown
Collaborator

Summary

Add a trae adapter for Trae (ByteDance's AI IDE; TraeCode agent), closing #2525.

Trae ships a Claude Code-compatible hook system but has no plugin marketplace, so the adapter merges the tokenless hook groups directly into the edition's global hooks.json:

  • CN edition: ~/.trae-cn/hooks.json
  • International edition: ~/.trae/hooks.json

Changes

  • adapters/tokenless/trae/
    • hooks/hooks.json — template with @TOKENLESS_ADAPTER_DIR@ placeholder: PreToolUse RunCommandrewrite_hook.py (Trae standardizes the terminal tool name to RunCommand), catch-all PreToolUse group → tool_ready_hook.sh, PostToolUse negative-lookahead group (skips Read|Glob|LS) → compress_response_hook.py
    • hooks/run-hook.sh — symlink to the shared dispatcher (same convention as qoder/qwencode)
    • scripts/install.sh — idempotent JSON merge into every detected Trae edition home; stamps the absolute adapter directory into hook commands (Trae has no plugin-root substitution); preserves user-configured hooks; refuses invalid JSON without clobbering; graceful no-op when Trae is absent
    • scripts/uninstall.sh — removes only tokenless-owned entries (TOKENLESS_AGENT_ID=trae marker)
    • scripts/detect.sh — tri-state report aligned with claude-code/qwencode conventions
  • manifest.json.intrae target (hooks: rewrite / compress-response / compress-toon / tool-ready)
  • Makefile — trae-install / trae-uninstall targets wired into adapter-install / adapter-uninstall, help text, and the new installer test in test-adapters
  • tool_categories.json — classify Trae's standardized RunCommand as layer-2 shell (64K truncation thresholds like Bash); agentscope middleware policy copy kept in sync
  • Raw packager — materialize the trae/hooks/run-hook.sh symlink (ANOLISA ignores archive symlinks)
  • RPM spec — package the adapter files, %preun cleanup hook
  • Docs (EN/ZH) — support-matrix row, activation notes (lifecycle script, same treatment as OpenCode since the anolisa adapter enable Rust driver set is maintained outside this component), QUICKSTART table; changelog entries

Response compression is delivered via additionalContext: Trae's PostToolUse contract supports decision/reason/additionalContext only (no updatedToolOutput), matching the hermes/openclaw treatment. Rewriting uses updatedInput, which Trae documents as full input replacement.

测试情况 (Test report)

Environment: Linux x86_64; GNU bash 4.4.20; system Python 3.8.17 and user-local Python 3.11.14; GNU Make 4.2.1; Node v22.21.1.

Executed:

Test Result
tests/test-trae-adapter-install.sh (new) ✅ 10/10 passed — merge/idempotency/user-hook preservation/uninstall/both-editions/no-Trae no-op/invalid-JSON refusal/detect tri-state
tests/test-run-hook-install-scope.sh ✅ passed
tests/test-tool-ready-readable-fixer.sh ✅ passed
tests/run-all-tests.sh 69/72 — the 3 failures are the pre-existing env-check hard bypass failures, reproduced identically on the unmodified base tree
tests/test_compress_response_hook.py (py3.11) ✅ OK
tests/test_compress_schema_hook.py (py3.11) ✅ OK
tests/test_resolve_agent_id.py (py3.11) ✅ OK
tests/test_agentscope_middleware.py (py3.11) ✅ OK after syncing the middleware policy copy with tool_categories.json
tests/test-qoder-adapter-install.sh (regression) ✅ 17/17
tests/test-opencode-adapter-install.sh (regression) ✅ 13/13
tests/test-package-raw.sh ✅ passed
make stamp-adapter-templates + manifest inspection trae target present with capabilities/actions
make -n trae-install / make -n trae-uninstall ✅ resolve to the new scripts
bash -n syntax check on all new scripts

Pre-existing failures (verified identical on the unmodified base tree, unrelated to this change):

  • tests/test_rewrite_hook.py — 11 failures: a system-installed rtk in PATH shadows the sandboxed fake rtk the test stages.
  • tests/test_hermes_plugin_import.py — 1 failure: a system-installed adapter tree under /usr/local/share/... shadows the test's XDG_DATA_HOME sandbox.
  • On system Python 3.8, test_agentscope_middleware.py cannot import (StrEnum needs 3.11) and several hook tests skip — same on the base tree.

Not run (with reasons):

  • cargo build / cargo test — no Rust code is touched by this PR.
  • make test-adapters full target — its build-openclaw-plugin prerequisite performs an npm dependency build not needed for this change; the individual installer tests above were run directly instead.
  • rpmbuild of tokenless.spec.in — a full RPM build requires the complete native build chain; the spec additions mirror the existing qwencode entries line-for-line.
  • Live Trae runtime verification — Trae is not installed in the test environment; hook behavior against a running Trae/TraeCode needs verification on a machine with Trae installed (documented as follow-up in the issue).

@github-actions github-actions Bot added component:tokenless src/tokenless/ scope:documentation ./docs/|./*.md|./NOTICE labels Aug 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4fd2c03ae7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/tokenless/CHANGELOG.md Outdated

### Added

- Trae (TraeCode) adapter: hook groups are merged into the edition's global `hooks.json` (`~/.trae-cn` CN edition, `~/.trae` international edition), with command rewriting on the standardized `RunCommand` tool and response compression delivered via `additionalContext` ([#2525](https://github.com/alibaba/anolisa/issues/2525)).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove feature changelog from non-release commit

For this feature commit, no version-bearing files are bumped, but this adds an Unreleased changelog entry. The documentation standard mandated by AGENTS says daily feature/fix PRs should update README/user-guide only and reserve CHANGELOG edits for release version bump PRs, so leaving this here will make the next release aggregation duplicate or predate release notes; please remove both EN/ZH changelog entries unless this commit is converted into the release bump.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted. Per specs/documentation-standard.md §5 ("Daily feature/fix PRs update README and user-guide only; CHANGELOG is written exclusively in release version bump PRs") and the matching rule in CONTRIBUTING.md, the premature Unreleased entries were removed from both src/tokenless/CHANGELOG.md and src/tokenless/CHANGELOG_zh.md; the entry will be added by the release version bump PR instead. Following the repo commit discipline (no standalone fix commits for issues introduced within the same PR), the changelog changes were removed from the originating commit via rebase (the follow-up commit that only adjusted those entries was dropped). The README/user-guide documentation introduced by this PR is kept. New branch head: dee2a64.

@Forrest-ly
Forrest-ly force-pushed the feat/tokenless-trae-adapter branch from e4080eb to dee2a64 Compare August 14, 2026 05:52
Trae ships a Claude Code-compatible hook system but no plugin marketplace,
so the adapter merges tokenless hook groups into the edition's global
hooks.json (~/.trae-cn CN edition, ~/.trae international edition):

- hooks.json template with RunCommand rewrite matcher, catch-all tool-ready
  group, and PostToolUse compression group; install.sh stamps the absolute
  adapter directory because Trae has no plugin-root substitution
- idempotent merge preserving user-configured hooks; uninstall.sh removes
  only tokenless-owned entries (TOKENLESS_AGENT_ID=trae marker)
- detect.sh tri-state report, run-hook.sh shared dispatcher symlink
- Makefile trae-install/trae-uninstall targets and test wiring
- classify Trae's standardized RunCommand tool as layer-2 shell in
  tool_categories.json and the agentscope policy copy
- raw packager materializes the run-hook symlink; RPM packages the adapter
- bilingual docs and changelog entries

Response compression is delivered via additionalContext because Trae's
PostToolUse does not support tool-output replacement.
Every other adapter is documented in README.md / README_zh.md (directory
tree, per-adapter strategy section, make target table, project structure
table); the Trae adapter added in this branch was missing those entries.
Follow-up for the Trae (TraeCode) adapter PR.
@Forrest-ly
Forrest-ly force-pushed the feat/tokenless-trae-adapter branch from dee2a64 to ffc5935 Compare August 14, 2026 06:00
Forrest-ly and others added 4 commits August 17, 2026 10:41
Resolve conflict in tokenless_agentscope/middleware.py after main
refactored the AgentScope package into _v1/_v2 modules with a shared
anolisa_tokenless runtime and left middleware.py as a compat shim.

Keep the shim from main and port this branch's one-line change — the
Trae standardized "RunCommand" shell tool — into the canonical
SHELL_TOOLS frozenset in anolisa_tokenless/tool_response.py, which now
backs the 1.x and 2.x integrations and the policy drift test against
tool_categories.json.
Resolve additive documentation conflicts after main gained the native
DeepSeek Harness (dsh) plugin while this branch adds the Trae adapter:

- QUICKSTART (en/zh): keep main's dsh --profile guidance and extend the
  "not registered with anolisa adapter enable" note to cover both
  OpenCode and Trae lifecycle scripts
- README.md: keep both adapters in the directory tree and keep both the
  Trae adapter section and the DeepSeek Harness plugin section
- README_zh.md: keep both bullets in the integration list and both
  install sections

Co-authored-by: multica-agent <github@multica.ai>
…xonomy

Completing the merge with main surfaced two integrations between this
branch's Trae taxonomy change (RunCommand classified as layer-2 shell in
tool_categories.json) and code main gained afterwards:

- dsh/dist/index.js keeps its own publishable copy of the shell-tool set;
  add RunCommand so tests/test-dsh-adapter.sh's parity check against
  tool_categories.json passes
- tests/test-package-raw.sh fixture now creates the trae hooks dir and
  run-hook symlink and asserts the materialized hook, matching the
  packager's trae materialize_hook seam

Co-authored-by: multica-agent <github@multica.ai>
The trae materialize_hook seam added with the Trae adapter asserts the
staged file after copying, but the require_file preflight list covers
the other hook-based adapters (claude-code, qwencode) and not trae.
Require trae/hooks/run-hook.sh in the source tree as well so a
checkout missing the dispatcher fails early with the same diagnostic
as its peers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:tokenless src/tokenless/ scope:documentation ./docs/|./*.md|./NOTICE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant