7 Commits

Author SHA1 Message Date
Omer Cohen 09efefdc4a feat(opencode): register ctx tools natively via plugin (#574) (#597)
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>
2026-05-18 17:10:16 +02:00
Ben Younes a888cac640 revert: lifecycle idle-shutdown (#568 + #595) — restore tools on 12 hosts (#602)
* 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.
2026-05-18 10:13:30 +02:00
Omer Cohen 5bcff7eda9 fix(lifecycle): make MCP idle shutdown opt-in outside OpenCode/Kilo (#592) (#595)
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>
2026-05-17 11:43:04 +03:00
Mert Koseoglu c56afc99e4 feat: global install + CLI hook dispatcher
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>
2026-03-05 19:00:06 +03:00
Mert Koseoglu 2e44ba98d1 fix: correct hook formats for VS Code Copilot and OpenCode
VS Code Copilot:
- Remove Claude Code-style matcher/hooks nesting from hook config
- Use official flat format: [{ "type": "command", "command": "..." }]
- Verified against https://code.visualstudio.com/docs/copilot/customization/hooks

OpenCode:
- Fix MCP format: command as array ["npx", "-y", "context-mode"]
- Add required "type": "local" field
- Add $schema reference
- Verified against https://opencode.ai/docs/mcp-servers/

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 18:35:37 +03:00
Mert Koseoglu 956a46ab6e feat: multi-platform session continuity hooks + OpenCode plugin
- Add OpenCode TypeScript plugin entry point (src/opencode-plugin.ts)
  with routing enforcement, event capture, and compaction snapshot
- Implement Gemini CLI session hooks (aftertool, precompress, sessionstart)
  with full lifecycle: startup cleanup, event capture, snapshot generation,
  and compaction/resume recovery
- Implement VS Code Copilot session hooks (posttooluse, precompact,
  sessionstart) with sessionId camelCase support and copilot-instructions.md
  rule capture
- Extend hooks/session-helpers.mjs with platform params (GEMINI_OPTS,
  VSCODE_OPTS, getProjectDir) for cross-platform DB/session paths
- Fix Claude Code hook import paths (packages/session/dist → build/session)
- Add 36 new tests (14 OpenCode plugin + 11 Gemini + 11 VS Code hooks)
- Update README platform tables and session continuity notes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 04:34:10 +03:00
Mert Koseoglu 75ae6ae394 feat: multi-platform adapters, session continuity, hook scripts
- Add 4 new platform adapters (Gemini CLI, VS Code Copilot, OpenCode, Codex CLI)
  with hooks.ts + config.ts per adapter, platform detection via env vars
- Add shared hook core (routing.mjs, formatters.mjs, stdin.mjs) and
  platform-specific hook scripts (gemini-cli/, vscode-copilot/)
- Add configs/ directory with per-platform install files (settings.json,
  mcp.json, hooks.json, opencode.json, config.toml, routing instructions)
- Auto-write routing instruction files (CLAUDE.md, GEMINI.md, AGENTS.md,
  copilot-instructions.md) on MCP server startup via start.mjs
- Add Session Continuity section to README with event capture table,
  compaction survival flow, and per-platform support matrix
- Add adapter TDD tests (631 total tests across 8 new test files)
- Fix plugin.json version sync, add typecheck to bundle.yml workflow
- Remove obsolete pretooluse.sh, demo.md, root llms files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 03:16:23 +03:00