Move OpenCode/Kilo from plugin+MCP dual registration to plugin-native ctx_*
tools. The plugin now imports the shared server tool registry without
starting stdio, exposes all 11 ctx_* tools via the OpenCode/Kilo tool map,
and uses AsyncLocalStorage to pass project/session context into existing
handlers without a process.env race.
Upgrade safety for existing users:
- configureAllHooks removes only legacy mcp.context-mode while preserving
other MCP servers.
- doctor warns when a legacy mcp.context-mode block remains and points to
context-mode upgrade.
- stale legacy OpenCode/Kilo MCP children suppress ctx_* registration and
become no-op rather than exposing duplicate tools.
Safety cleanup:
- Remove CONTEXT_MODE_IDLE_TIMEOUT_MS entirely; plugin-native tools remove
the need for timer-driven MCP death, and timer shutdown was unsafe for
hosts that keep registered tool handles.
- Guard process-wide exception handlers so importing server.js for native
tools does not alter OpenCode/Kilo host crash semantics.
- Scope CONTEXT_MODE_EMBEDDED_PLUGIN_TOOLS to the dynamic import and restore
it so child commands do not inherit the internal guard.
Tests cover native tool registration, native ctx_stats execution, host
side-effect leakage, native session attribution, legacy MCP config cleanup,
doctor warning, and stale MCP no-op predicate.
Refs: #574, #565, #592
Co-authored-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
* Revert "fix(lifecycle): make MCP idle shutdown opt-in outside OpenCode/Kilo (#592) (#595)"
This reverts commit 5bcff7eda9.
* Revert "fix(lifecycle): idle self-shutdown + generalized sibling sweep (#565) (#568)"
This reverts commit ac11f10333.
* ci: rebuild bundles after lifecycle revert
Regenerates cli.bundle.mjs, server.bundle.mjs and hooks/session-extract.bundle.mjs
to match the source state after the revert of #568 and #595. No source change in
this commit — just minifier output realignment.
* docs(readme): remove orphan lifecycle env var section after #568+#595 revert
The section documented CONTEXT_MODE_IDLE_TIMEOUT_MS (added in #568, reverted)
and CONTEXT_MODE_STARTUP_SWEEP (added in #568 and tweaked in a follow-up commit
61e680f, the underlying startupSiblingSweep() call site reverted). Neither env
var is read anywhere in src/, tests/, or scripts/ after the revert — leaving
the README section in place would leak dead configuration knobs to users.
Issue #592 confirms the #568 idle self-shutdown default is unsafe for
Claude Code/Codex-style MCP hosts: after context-mode exits cleanly on
idle, the host can keep registered ctx_* tool handles but mark the MCP
server disconnected, leaving tools stale until the user reconnects or
restarts. #583 fixed Pi by making its bridge respawn, but Claude Code
and Codex host MCP clients are outside this repo and cannot be patched
from lifecycle.ts.
Change the policy from global default-on to host opt-in:
- idleTimeoutForEnv({}) now returns 0 (disabled), not 900000.
- malformed/negative CONTEXT_MODE_IDLE_TIMEOUT_MS also falls back to 0,
the safe default.
- positive env values still opt in exactly as before.
- OpenCode and KiloCode configs explicitly set
CONTEXT_MODE_IDLE_TIMEOUT_MS=900000 because those hosts were the
original #565 accumulation case (one MCP child per session/subagent).
- README lifecycle docs now describe the conservative default and why
Claude Code/Codex/editor MCP clients should not idle-exit unless users
explicitly opt in.
Regression tests:
- lifecycle.test.ts pins missing/malformed env => 0 and explicit env =>
honored.
- opencode-idle-config.test.ts pins OpenCode and KiloCode shipped configs
as explicit 15 min opt-ins, preventing accidental reintroduction of a
global default or removal of the targeted host opt-in.
Verification:
- npx tsc --noEmit: PASS
- npm run build: PASS
- npx vitest run tests/lifecycle.test.ts tests/adapters/opencode-idle-config.test.ts: PASS (26/26)
- npx vitest run: same 3 pre-existing environment-dependent failures on
this workstation (VSCODE_PID inheritance, JetBrains IDEA_INITIAL_DIRECTORY),
unchanged from upstream/next baseline.
Refs: #592, #568, #565, #583
Co-authored-by: Ubuntu <omer@Omer.dn3uxh3znnmu5eefnjnut0i1af.tlvx.internal.cloudapp.net>
Replace `node ./node_modules/context-mode/hooks/...` with `context-mode hook <platform> <event>`.
All platforms now use `npm install -g context-mode` as prerequisite.
MCP server configs use `context-mode` directly instead of `npx -y context-mode`.
This ensures ctx-upgrade persists across sessions (no ephemeral npx cache).
- Add `hook` subcommand to CLI with HOOK_MAP dispatcher
- Update all adapter buildHookCommand() to use CLI dispatcher
- Update all adapter configureAllHooks() and generateHookConfig()
- Update all config templates (gemini-cli, vscode-copilot, opencode, codex)
- Update README install instructions for all platforms
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>