Skip to content

fix(opencode): follow the recorded configuration home for plugins - #1369

Closed
nateEc wants to merge 3 commits into
Tencent:mainfrom
nateEc:fix/1221-opencode-relocated-hooks
Closed

nateEc wants to merge 3 commits into
Tencent:mainfrom
nateEc:fix/1221-opencode-relocated-hooks

Conversation

@nateEc

@nateEc nateEc commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

OpenCode's skills/rules/MCP/model files followed the relocated configuration home, but its hook plugins stayed under ~/.config/opencode/plugin. The generated plugin also embedded that old directory when reading user context, so merely moving the plugin file would still miss the user's instructions.

Resolve user plugins through the existing recorded/environment home rules and embed the same effective user home for context reads. Keep project plugin resolution unchanged, route HTTP-source hook plugins through the same directory, and update the descriptor, doctor note and bilingual reference. Copies in an old home and unrelated personal plugins are retained.

Review follow-up:

Separate legacy default-home MCP ownership from the current hooks-location descriptor. This preserves uninstall/ownership fallback and personal-server protection. Update both doctor-note tests. Old-home plugins are retained; bilingual guidance now tells upgraders when it is safe to remove the TeamAI-marked old copy.

Validation on this branch, rebased onto fc8a229e:

  • npx tsc --noEmit, npm run lint, npm run build, git diff --check: passed.
  • npx vitest run src/__tests__/opencode-hooks.test.ts src/__tests__/mcp-locate-targets.test.ts src/__tests__/uninstall.test.ts src/__tests__/doctor-agent-places.test.ts src/__tests__/doctor-rule-places.test.ts src/__tests__/tools-channels.test.ts: 499 passed.
  • After build, npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/opencode-relocated-hooks.test.ts: 1 passed, using the real CLI and isolated local Git/HOME fixtures.

Local host: macOS, Node 22.22.1, Apple Git 2.50.1. Native Windows, live vendor applications and additional provider combinations were not run locally and are left to CI. This record replaces the earlier combined-snapshot validation paragraphs.

Refs #1221; this PR addresses only its stated independent defect.

@nateEc

nateEc commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Synchronized tools-channels.test.ts with OpenCode hooks now following the relocated home. The complete Windows test selection passes locally on macOS: 29 files, 2,908 passed and one existing platform-specific skip; type checking and lint pass. The Windows CI job reruns on this commit; native Windows was not available locally.

@github-actions

Copy link
Copy Markdown

No confident findings in the specified PR diff.

The PR description satisfies the testing requirement: it documents a post-build real-CLI run covering relocated installation, generated-plugin context reads, and listing/removal using the recorded home without OPENCODE_CONFIG_DIR. Live OpenCode and native Windows limitations are explicitly disclosed and are not blocking.

No earlier findings were supplied. I only read the diff; I did not run, build, or install PR code.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This was generated by AI during triage.

@nateEc The plugin move works. With XDG_CONFIG_HOME or OPENCODE_CONFIG_DIR set, the built CLI installs the plugin in the moved home and the plugin reads the moved context, while a build of main (f3cd042) writes the default home. It reuses the shared toolHome resolver and adds no new per-tool one. Two things block, and both come from flipping settingsAtDefault for OpenCode, which other code still reads.

[P1 blocking] uninstall stops cleaning OpenCode's default home. With a record from an earlier release (no file) and XDG_CONFIG_HOME set, uninstall --force on main removes the legacy legacy-server MCP entry and the default-home plugin; on this head both stay. src/mcp-reconcile.ts:607 uses settingsAtDefault to find servers an earlier release wrote to the default home, and the doctor notes for agents, rules and blocks use the same flag.

[P1 blocking] The Lint & Test jobs are red because of this PR. All six fail on 11 tests: nine uninstall … opencode … after 'OPENCODE_CONFIG_DIR' moves it cases and names once, and keeps, the servers an earlier release wrote to OpenCode's default home after XDG_CONFIG_HOME moves it in mcp-locate-targets.test.ts, plus the OpenCode notes in doctor-agent-places.test.ts and doctor-rule-places.test.ts. The three files pass on main (194/194). Only the skills note test in doctor-delivery.test.ts was updated. Keeping a separate flag for "hooks follow the moved home", instead of reusing settingsAtDefault, would leave those readers as they are.

  • [P2 non-blocking] After the home moves, the plugin copy in the default home stays, hooks remove deletes only the moved copy, and hooks list no longer shows the leftover. OpenCode does not load it while the variable is set, and the body keeps it on purpose (docs/guide/reference.md:105 and the zh-CN line say so), but it is teamai's own file and runs again if the member unsets the variable. #1221 releases unchanged skill copies in the same situation.
  • [P2 non-blocking] #1371 makes the same settingsAtDefault change for CodeBuddy and breaks the same legacy MCP lookup. #1368, #1370 and #1371 also conflict with this PR in the shared reference.md paragraph and tools-channels.test.ts.
  • [P3 nit] Two commit subjects are in Chinese. The squash title is English.

The CI review reports no confident findings. We disagree: it read only the diff, and Lint & Test was already red at this head. CI: the six Lint & Test jobs fail as above, so Build is skipped; the GitHub-provider job is skipped by the fork policy.

- 用户插件目录遵循已记录主目录、OPENCODE_CONFIG_DIR 和 XDG_CONFIG_HOME,项目目录保持原有规则;内置及 HTTP hook 的安装、列表和删除使用同一路径。
- 将插件内嵌的用户上下文目录同步到实际配置主目录,保留旧目录副本与个人插件,更新工具描述和中英文参考。
- 三种迁移目录的回归在修改前失败;120 项相关单测、真实 CLI 安装及记录目录下的上下文读取和删除用例、构建、类型检查和 lint 通过。
- 更新默认目录工具清单,反映 OpenCode 插件已跟随记录目录和环境变量,与交付及 doctor 检查保持一致。
- 本机完整 Windows 测试集合 2908 项通过,1 项原有平台用例跳过;类型检查和 lint 通过。
- 为旧版默认目录 MCP 记录保留独立兼容判断,恢复卸载与成员配置保护。
- 更新 doctor 目录提示断言;中英文文档说明旧插件的安全清理条件。
- 499 项定向单测及迁移插件真实 CLI 场景通过,类型、lint 与构建通过。
@nateEc
nateEc force-pushed the fix/1221-opencode-relocated-hooks branch from e00b547 to b61e909 Compare October 26, 2026 04:38
@github-actions

Copy link
Copy Markdown

No confident findings in the specified PR diff.

The PR description satisfies the testing requirement: it records a post-build real-CLI run covering relocated installation, generated-plugin context reads, and listing/removal using the persisted home without OPENCODE_CONFIG_DIR. Live OpenCode and native Windows limitations are disclosed and are not blocking.

The earlier review reported no findings, so none require resolution.

I only read the specified diff; I did not run, build, or install PR code.

@nateEc

nateEc commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Updated and rebased onto main fc8a229e. Separate legacy default-home MCP ownership from the current hooks-location descriptor. This preserves uninstall/ownership fallback and personal-server protection. Update both doctor-note tests. Old-home plugins are retained; bilingual guidance now tells upgraders when it is safe to remove the TeamAI-marked old copy.

Verification: 499 focused unit tests passed; types, lint and build passed. Post-build real-CLI opencode-relocated-hooks: 1 passed. Native Windows and live vendor/provider combinations remain CI coverage. The PR body now describes this branch's current verification rather than an older combined snapshot.

Updated head: b61e909f.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@nateEc Re-checked at b61e909. The MCP half of the uninstall blocker is fixed: with the built CLI, uninstall --force removes legacy-server from the default home. Lint & Test is green again, and the new e2e and the related OpenCode and uninstall e2e files pass. One blocker remains.

  • [P1 blocking] uninstall --force leaves teamai's own plugin in the default home once XDG_CONFIG_HOME has moved the OpenCode home. On main, the same fixture prints Removed teamai OpenCode hook from ~/.config/opencode/plugin/teamai-hooks.ts and the file is gone. On this head the uninstall exits 0 and teamai-hooks.ts is still there, so any shell without the variable loads teamai's plugin again after an uninstall. The docs now call this retention deliberate, but the file carries teamai's marker, and it is the copy main removes. Please remove the teamai-marked default-home copy on uninstall, as main does, and keep leaving unmarked personal plugins alone.
  • [P2 non-blocking] fix(codebuddy): follow the recorded home for hooks #1371 adds the same legacyDefaultMcp helper. Whichever lands second should reuse the first instead of keeping two copies.
  • [P3 nit] docs/guide/reference.md still says "only part of it follows" for OpenCode. legacyDefaultHome and legacyDefaultMcp name one concept two ways.

The CI review's line saying the earlier review had no findings is not right: our review at e00b547 had two blocking findings. CI passes on this head except the GitHub-provider e2e job, which the fork policy skips.

SaulMoro added a commit that referenced this pull request Oct 26, 2026
…use and CodeBuddy

Each test records a moved home, then runs pull or hooks inject, hooks list
and hooks remove through the built CLI with the variable unset, so the
recorded home alone decides where the hooks go. The OpenCode case also
checks that the plugin reads the user context from the moved home. All four
fail on main and pass here. They come from #1368, #1369, #1370 and #1371,
which this branch replaces.

Co-authored-by: Nathan Shan <[email protected]>
@SaulMoro

Copy link
Copy Markdown
Collaborator

Closing in favor of #1405, which locates every tool's hooks from its descriptor and fixes the moved Pi, OpenCode, Muse and CodeBuddy homes together. Your end-to-end test fails on main and passes on #1405 unchanged, so I carried it into that PR with you as co-author. Thanks for tracking this down.

@SaulMoro SaulMoro closed this Oct 26, 2026
hz89Dev pushed a commit to hz89Dev/teamai-cli that referenced this pull request Oct 27, 2026
…use and CodeBuddy

Each test records a moved home, then runs pull or hooks inject, hooks list
and hooks remove through the built CLI with the variable unset, so the
recorded home alone decides where the hooks go. The OpenCode case also
checks that the plugin reads the user context from the moved home. All four
fail on main and pass here. They come from Tencent#1368, Tencent#1369, Tencent#1370 and Tencent#1371,
which this branch replaces.

Co-authored-by: Nathan Shan <[email protected]>
jeff-r2026 pushed a commit that referenced this pull request Oct 27, 2026
…ollow a moved home (#1221) (#1405)

* feat(tools): state every tool's hook channel in the descriptor (#1221)

Each built-in tool now names, for the user scope and for self mode, how
teamai installs its hooks: entries in a settings file with the shape of
its hook list, a file of teamai's own its adapter writes (OpenCode's
plugin, Pi's and OMP's extension, Hermes, OpenClaw, dsh), 'none' or
'unknown'. Leaving it out fails tsc (tools.type-test.ts).

hooks.ts takes each tool's hook shape from the descriptor (hookFormatOf)
instead of its own tool sets; a test pins it to the table it replaced.

* feat(locate): locate each tool's hooks from the descriptor (#1221)

locate(tool, 'hooks') answers with the hook list of the tool's hook file,
in its shape, or the directory its adapter writes teamai's file into. A
workspace takes the user hooks; self mode takes the project's, except for
a tool that reads its user hooks there too (ZCode's CLI, every adapter).
A user hook file follows the tool's moved home, and the default home's is
retired for the four tools whose earlier releases wrote there.

hookSettingsFile and hookAdapterDir give the writers the same answer. No
writer uses them yet. The matrix states every tool in the user scope, a
workspace and self mode, with the moved homes.

* fix(hooks): write and remove hooks where locate says the tool reads them (#1221)

Hook writers took a fixed default-home path, so a tool whose home moved
(CODEBUDDY_CONFIG_DIR, CODEX_HOME, OPENCODE_CONFIG_DIR, XDG_CONFIG_HOME,
PI_CODING_AGENT_DIR) got hooks in a file it never reads. Settings writers
now take the file from hookSettingsFile, and the Pi, OMP, OpenCode and dsh
adapters take their directory from hookAdapterDir; both sit beside locate's
hooks resolver and share its toolHome.

Uninstall checks the moved file and the default-home copy earlier releases
wrote, and the OpenCode and Pi adapter dirs locate retires. Pull leaves the
default-home copy in place, as it does for skills; the tool does not read it.

* fix(doctor): drop the note that teamai writes under a tool's default home (#1221)

Hooks now follow a moved home, so nothing teamai writes for Pi, CodeBuddy,
OpenCode or Muse stays under the default one, and doctor's "still writes
some of its other files under" notes were wrong. The descriptor flag behind
them is renamed to defaultHomeLeftovers: it now only says where earlier
releases left hooks and MCP servers, which uninstall and MCP ownership
still look for.

* fix(hooks): hooks remove also clears the default-home hooks an earlier release wrote (#1221)

A tool reads its default home again once the member unsets the variable
that moved it, so the hooks an earlier release left there would fire after
`hooks remove`. It now sweeps the places locate retires: the settings file,
with the team's hook history to find team entries whose records went with
the moved copy, and the OpenCode plugin and Pi extension directories.

The e2e test runs the real CLI with CODEBUDDY_CONFIG_DIR and
XDG_CONFIG_HOME set: hooks inject writes the moved homes, and uninstall and
hooks remove clear both copies.

* docs: hooks follow a moved OpenCode, Muse, Pi and CodeBuddy home (#1221)

* fix(hooks): clear the default-home copy first, so one team-hook record covers both copies (#1221)

A Muse team hook carries no marker, so only its manifest record names it,
and an HTTP-backed team has no hook history to fall back on. Cleaning the
moved file first consumed that record and left the team hook in the
default-home copy. That copy now goes first with keepRecords, and the moved
file's pass consumes the records.

* refactor(hooks): key HOME-hook ownership on the descriptor's self channel, not on ZCode (#1221)

A project install of a tool that keeps its user hooks reads them from HOME,
so it owns only its gated team hooks there. reconcileHooksToAllTools and
uninstall's HOME target named ZCode for this; they now read
hooks.self === 'user', as hookSettingsFile already does.

* fix(hooks): pull removes the OpenCode plugin an earlier release left in the default home (#1221)

OpenCode 1.x loads the default config dir's plugins beside
OPENCODE_CONFIG_DIR's and dedupes them by file URL, so the copy an earlier
release wrote there and the moved one both ran, firing every event twice.
Pull already deletes a project-scope copy for the same reason.

* fix(hooks): an agent hook leaves no copy in a moved tool's default home (#1221)

Withdrawing an OpenCode or Pi agent hook removed only the moved copy, so the
one an earlier release wrote under the default home ran again once the home
stopped moving. Removal now clears both. Writing an OpenCode agent hook also
removes the earlier copy, which OpenCode 1.x loads beside the moved one.

* fix(hooks): keep a moved tool's hooks and records when a copy is the same or fails (#1221)

A default home linked to the moved one is the same directory, so pull no
longer deletes the plugin it just wrote through the link. And when the
default-home copy cannot be cleaned, the moved copy's pass leaves the
records, so a retry after repairing the file still finds the team hook.

* fix(hooks): pull removes the hooks an earlier release left in a moved tool's default home (#1221)

The default-home copy was left as it was, so once the team changed a hook,
the moved file's pass replaced its record and the old Muse team hook stayed
in that copy with nothing to name it for removal. Pull now clears the copy
first, judged by the records the moved pass then replaces, for CodeBuddy and
Muse settings and Pi's extension as already for OpenCode's plugin. A copy
that is the moved file through a link is left alone.

* fix(hooks): keep a moved tool's hooks and records when its default-home copy cannot be cleaned (#1221)

* fix(models): models switch writes into the Claude and Codex roots teamai init recorded (#1221)

* fix(hooks): hooks remove exits 1 when it leaves hooks behind, as uninstall does (#1221)

* fix(hooks): write settings and agent hooks only through a channel the tool reads (#1221)

* test(hooks): cover recorded tool homes end to end for Pi, OpenCode, Muse and CodeBuddy

Each test records a moved home, then runs pull or hooks inject, hooks list
and hooks remove through the built CLI with the variable unset, so the
recorded home alone decides where the hooks go. The OpenCode case also
checks that the plugin reads the user context from the moved home. All four
fail on main and pass here. They come from #1368, #1369, #1370 and #1371,
which this branch replaces.

Co-authored-by: Nathan Shan <[email protected]>

* feat(tools): state Kiro's standalone hook file as its hook channel (#1221)

#1341 moved Kiro's session-start hook to ~/.kiro/hooks/teamai.json, which Kiro CLI V3 loads for every agent. The descriptor still said Kiro takes no hooks. It now names the file as a hook adapter, and kiroHookFile takes its directory from locate, as the other adapters do.

---------

Co-authored-by: Nathan Shan <[email protected]>
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…ollow a moved home (Tencent#1221) (Tencent#1405)

* feat(tools): state every tool's hook channel in the descriptor (Tencent#1221)

Each built-in tool now names, for the user scope and for self mode, how
teamai installs its hooks: entries in a settings file with the shape of
its hook list, a file of teamai's own its adapter writes (OpenCode's
plugin, Pi's and OMP's extension, Hermes, OpenClaw, dsh), 'none' or
'unknown'. Leaving it out fails tsc (tools.type-test.ts).

hooks.ts takes each tool's hook shape from the descriptor (hookFormatOf)
instead of its own tool sets; a test pins it to the table it replaced.

* feat(locate): locate each tool's hooks from the descriptor (Tencent#1221)

locate(tool, 'hooks') answers with the hook list of the tool's hook file,
in its shape, or the directory its adapter writes teamai's file into. A
workspace takes the user hooks; self mode takes the project's, except for
a tool that reads its user hooks there too (ZCode's CLI, every adapter).
A user hook file follows the tool's moved home, and the default home's is
retired for the four tools whose earlier releases wrote there.

hookSettingsFile and hookAdapterDir give the writers the same answer. No
writer uses them yet. The matrix states every tool in the user scope, a
workspace and self mode, with the moved homes.

* fix(hooks): write and remove hooks where locate says the tool reads them (Tencent#1221)

Hook writers took a fixed default-home path, so a tool whose home moved
(CODEBUDDY_CONFIG_DIR, CODEX_HOME, OPENCODE_CONFIG_DIR, XDG_CONFIG_HOME,
PI_CODING_AGENT_DIR) got hooks in a file it never reads. Settings writers
now take the file from hookSettingsFile, and the Pi, OMP, OpenCode and dsh
adapters take their directory from hookAdapterDir; both sit beside locate's
hooks resolver and share its toolHome.

Uninstall checks the moved file and the default-home copy earlier releases
wrote, and the OpenCode and Pi adapter dirs locate retires. Pull leaves the
default-home copy in place, as it does for skills; the tool does not read it.

* fix(doctor): drop the note that teamai writes under a tool's default home (Tencent#1221)

Hooks now follow a moved home, so nothing teamai writes for Pi, CodeBuddy,
OpenCode or Muse stays under the default one, and doctor's "still writes
some of its other files under" notes were wrong. The descriptor flag behind
them is renamed to defaultHomeLeftovers: it now only says where earlier
releases left hooks and MCP servers, which uninstall and MCP ownership
still look for.

* fix(hooks): hooks remove also clears the default-home hooks an earlier release wrote (Tencent#1221)

A tool reads its default home again once the member unsets the variable
that moved it, so the hooks an earlier release left there would fire after
`hooks remove`. It now sweeps the places locate retires: the settings file,
with the team's hook history to find team entries whose records went with
the moved copy, and the OpenCode plugin and Pi extension directories.

The e2e test runs the real CLI with CODEBUDDY_CONFIG_DIR and
XDG_CONFIG_HOME set: hooks inject writes the moved homes, and uninstall and
hooks remove clear both copies.

* docs: hooks follow a moved OpenCode, Muse, Pi and CodeBuddy home (Tencent#1221)

* fix(hooks): clear the default-home copy first, so one team-hook record covers both copies (Tencent#1221)

A Muse team hook carries no marker, so only its manifest record names it,
and an HTTP-backed team has no hook history to fall back on. Cleaning the
moved file first consumed that record and left the team hook in the
default-home copy. That copy now goes first with keepRecords, and the moved
file's pass consumes the records.

* refactor(hooks): key HOME-hook ownership on the descriptor's self channel, not on ZCode (Tencent#1221)

A project install of a tool that keeps its user hooks reads them from HOME,
so it owns only its gated team hooks there. reconcileHooksToAllTools and
uninstall's HOME target named ZCode for this; they now read
hooks.self === 'user', as hookSettingsFile already does.

* fix(hooks): pull removes the OpenCode plugin an earlier release left in the default home (Tencent#1221)

OpenCode 1.x loads the default config dir's plugins beside
OPENCODE_CONFIG_DIR's and dedupes them by file URL, so the copy an earlier
release wrote there and the moved one both ran, firing every event twice.
Pull already deletes a project-scope copy for the same reason.

* fix(hooks): an agent hook leaves no copy in a moved tool's default home (Tencent#1221)

Withdrawing an OpenCode or Pi agent hook removed only the moved copy, so the
one an earlier release wrote under the default home ran again once the home
stopped moving. Removal now clears both. Writing an OpenCode agent hook also
removes the earlier copy, which OpenCode 1.x loads beside the moved one.

* fix(hooks): keep a moved tool's hooks and records when a copy is the same or fails (Tencent#1221)

A default home linked to the moved one is the same directory, so pull no
longer deletes the plugin it just wrote through the link. And when the
default-home copy cannot be cleaned, the moved copy's pass leaves the
records, so a retry after repairing the file still finds the team hook.

* fix(hooks): pull removes the hooks an earlier release left in a moved tool's default home (Tencent#1221)

The default-home copy was left as it was, so once the team changed a hook,
the moved file's pass replaced its record and the old Muse team hook stayed
in that copy with nothing to name it for removal. Pull now clears the copy
first, judged by the records the moved pass then replaces, for CodeBuddy and
Muse settings and Pi's extension as already for OpenCode's plugin. A copy
that is the moved file through a link is left alone.

* fix(hooks): keep a moved tool's hooks and records when its default-home copy cannot be cleaned (Tencent#1221)

* fix(models): models switch writes into the Claude and Codex roots teamai init recorded (Tencent#1221)

* fix(hooks): hooks remove exits 1 when it leaves hooks behind, as uninstall does (Tencent#1221)

* fix(hooks): write settings and agent hooks only through a channel the tool reads (Tencent#1221)

* test(hooks): cover recorded tool homes end to end for Pi, OpenCode, Muse and CodeBuddy

Each test records a moved home, then runs pull or hooks inject, hooks list
and hooks remove through the built CLI with the variable unset, so the
recorded home alone decides where the hooks go. The OpenCode case also
checks that the plugin reads the user context from the moved home. All four
fail on main and pass here. They come from Tencent#1368, Tencent#1369, Tencent#1370 and Tencent#1371,
which this branch replaces.

Co-authored-by: Nathan Shan <[email protected]>

* feat(tools): state Kiro's standalone hook file as its hook channel (Tencent#1221)

Tencent#1341 moved Kiro's session-start hook to ~/.kiro/hooks/teamai.json, which Kiro CLI V3 loads for every agent. The descriptor still said Kiro takes no hooks. It now names the file as a hook adapter, and kiroHookFile takes its directory from locate, as the other adapters do.

---------

Co-authored-by: Nathan Shan <[email protected]>
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.

3 participants