@mxalbert/context-mode 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +33 -0
- package/.claude-plugin/plugin.json +31 -0
- package/.codex-plugin/hooks.json +65 -0
- package/.codex-plugin/mcp.json +13 -0
- package/.codex-plugin/plugin.json +31 -0
- package/.openclaw-plugin/index.ts +12 -0
- package/.openclaw-plugin/openclaw.plugin.json +38 -0
- package/.openclaw-plugin/package.json +28 -0
- package/LICENSE +94 -0
- package/README.md +1619 -0
- package/bin/statusline.mjs +378 -0
- package/build/adapters/antigravity/index.d.ts +51 -0
- package/build/adapters/antigravity/index.js +169 -0
- package/build/adapters/antigravity-cli/index.d.ts +51 -0
- package/build/adapters/antigravity-cli/index.js +342 -0
- package/build/adapters/base.d.ts +92 -0
- package/build/adapters/base.js +135 -0
- package/build/adapters/claude-code/config.d.ts +8 -0
- package/build/adapters/claude-code/config.js +8 -0
- package/build/adapters/claude-code/hooks.d.ts +106 -0
- package/build/adapters/claude-code/hooks.js +183 -0
- package/build/adapters/claude-code/index.d.ts +80 -0
- package/build/adapters/claude-code/index.js +569 -0
- package/build/adapters/claude-code-base.d.ts +49 -0
- package/build/adapters/claude-code-base.js +113 -0
- package/build/adapters/client-map.d.ts +10 -0
- package/build/adapters/client-map.js +42 -0
- package/build/adapters/codex/config.d.ts +8 -0
- package/build/adapters/codex/config.js +8 -0
- package/build/adapters/codex/hooks.d.ts +55 -0
- package/build/adapters/codex/hooks.js +64 -0
- package/build/adapters/codex/index.d.ts +87 -0
- package/build/adapters/codex/index.js +995 -0
- package/build/adapters/codex/paths.d.ts +1 -0
- package/build/adapters/codex/paths.js +12 -0
- package/build/adapters/codex/usage.d.ts +107 -0
- package/build/adapters/codex/usage.js +227 -0
- package/build/adapters/copilot-base.d.ts +94 -0
- package/build/adapters/copilot-base.js +297 -0
- package/build/adapters/copilot-cli/hooks.d.ts +33 -0
- package/build/adapters/copilot-cli/hooks.js +64 -0
- package/build/adapters/copilot-cli/index.d.ts +48 -0
- package/build/adapters/copilot-cli/index.js +341 -0
- package/build/adapters/cursor/config.d.ts +4 -0
- package/build/adapters/cursor/config.js +4 -0
- package/build/adapters/cursor/hooks.d.ts +55 -0
- package/build/adapters/cursor/hooks.js +82 -0
- package/build/adapters/cursor/index.d.ts +64 -0
- package/build/adapters/cursor/index.js +517 -0
- package/build/adapters/detect.d.ts +136 -0
- package/build/adapters/detect.js +623 -0
- package/build/adapters/gemini-cli/config.d.ts +8 -0
- package/build/adapters/gemini-cli/config.js +8 -0
- package/build/adapters/gemini-cli/hooks.d.ts +83 -0
- package/build/adapters/gemini-cli/hooks.js +115 -0
- package/build/adapters/gemini-cli/index.d.ts +80 -0
- package/build/adapters/gemini-cli/index.js +483 -0
- package/build/adapters/jetbrains-copilot/config.d.ts +8 -0
- package/build/adapters/jetbrains-copilot/config.js +8 -0
- package/build/adapters/jetbrains-copilot/hooks.d.ts +59 -0
- package/build/adapters/jetbrains-copilot/hooks.js +87 -0
- package/build/adapters/jetbrains-copilot/index.d.ts +31 -0
- package/build/adapters/jetbrains-copilot/index.js +131 -0
- package/build/adapters/kimi/config.d.ts +8 -0
- package/build/adapters/kimi/config.js +8 -0
- package/build/adapters/kimi/hooks.d.ts +28 -0
- package/build/adapters/kimi/hooks.js +34 -0
- package/build/adapters/kimi/index.d.ts +66 -0
- package/build/adapters/kimi/index.js +537 -0
- package/build/adapters/kimi/paths.d.ts +21 -0
- package/build/adapters/kimi/paths.js +52 -0
- package/build/adapters/kimi/usage.d.ts +82 -0
- package/build/adapters/kimi/usage.js +217 -0
- package/build/adapters/kiro/hooks.d.ts +61 -0
- package/build/adapters/kiro/hooks.js +94 -0
- package/build/adapters/kiro/index.d.ts +61 -0
- package/build/adapters/kiro/index.js +301 -0
- package/build/adapters/omp/index.d.ts +65 -0
- package/build/adapters/omp/index.js +182 -0
- package/build/adapters/omp/plugin.d.ts +81 -0
- package/build/adapters/omp/plugin.js +331 -0
- package/build/adapters/omp/usage.d.ts +49 -0
- package/build/adapters/omp/usage.js +110 -0
- package/build/adapters/openclaw/config.d.ts +8 -0
- package/build/adapters/openclaw/config.js +8 -0
- package/build/adapters/openclaw/hooks.d.ts +50 -0
- package/build/adapters/openclaw/hooks.js +61 -0
- package/build/adapters/openclaw/index.d.ts +74 -0
- package/build/adapters/openclaw/index.js +439 -0
- package/build/adapters/openclaw/mcp-tools.d.ts +54 -0
- package/build/adapters/openclaw/mcp-tools.js +207 -0
- package/build/adapters/openclaw/plugin.d.ts +141 -0
- package/build/adapters/openclaw/plugin.js +818 -0
- package/build/adapters/openclaw/session-db.d.ts +55 -0
- package/build/adapters/openclaw/session-db.js +88 -0
- package/build/adapters/openclaw/usage.d.ts +34 -0
- package/build/adapters/openclaw/usage.js +52 -0
- package/build/adapters/openclaw/workspace-router.d.ts +29 -0
- package/build/adapters/openclaw/workspace-router.js +64 -0
- package/build/adapters/opencode/config.d.ts +8 -0
- package/build/adapters/opencode/config.js +8 -0
- package/build/adapters/opencode/hooks.d.ts +38 -0
- package/build/adapters/opencode/hooks.js +50 -0
- package/build/adapters/opencode/index.d.ts +144 -0
- package/build/adapters/opencode/index.js +638 -0
- package/build/adapters/opencode/plugin.d.ts +249 -0
- package/build/adapters/opencode/plugin.js +1536 -0
- package/build/adapters/opencode/v2.d.ts +117 -0
- package/build/adapters/opencode/v2.js +224 -0
- package/build/adapters/opencode/zod3tov4.d.ts +1 -0
- package/build/adapters/opencode/zod3tov4.js +132 -0
- package/build/adapters/pi/extension.d.ts +81 -0
- package/build/adapters/pi/extension.js +861 -0
- package/build/adapters/pi/index.d.ts +57 -0
- package/build/adapters/pi/index.js +173 -0
- package/build/adapters/pi/mcp-bridge.d.ts +268 -0
- package/build/adapters/pi/mcp-bridge.js +894 -0
- package/build/adapters/qwen-code/hooks.d.ts +26 -0
- package/build/adapters/qwen-code/hooks.js +29 -0
- package/build/adapters/qwen-code/index.d.ts +40 -0
- package/build/adapters/qwen-code/index.js +361 -0
- package/build/adapters/qwen-code/usage.d.ts +90 -0
- package/build/adapters/qwen-code/usage.js +222 -0
- package/build/adapters/types.d.ts +360 -0
- package/build/adapters/types.js +118 -0
- package/build/adapters/vscode-copilot/config.d.ts +8 -0
- package/build/adapters/vscode-copilot/config.js +8 -0
- package/build/adapters/vscode-copilot/hooks.d.ts +71 -0
- package/build/adapters/vscode-copilot/hooks.js +98 -0
- package/build/adapters/vscode-copilot/index.d.ts +32 -0
- package/build/adapters/vscode-copilot/index.js +222 -0
- package/build/adapters/zed/index.d.ts +40 -0
- package/build/adapters/zed/index.js +163 -0
- package/build/cli.d.ts +34 -0
- package/build/cli.js +1828 -0
- package/build/db-base.d.ts +250 -0
- package/build/db-base.js +756 -0
- package/build/executor.d.ts +72 -0
- package/build/executor.js +678 -0
- package/build/exit-classify.d.ts +19 -0
- package/build/exit-classify.js +12 -0
- package/build/fetch/blocks.d.ts +145 -0
- package/build/fetch/blocks.js +244 -0
- package/build/fetch/extract.d.ts +68 -0
- package/build/fetch/extract.js +123 -0
- package/build/fetch/page-store.d.ts +66 -0
- package/build/fetch/page-store.js +174 -0
- package/build/fetch-cache.d.ts +13 -0
- package/build/fetch-cache.js +15 -0
- package/build/lifecycle.d.ts +124 -0
- package/build/lifecycle.js +278 -0
- package/build/package-identity.d.ts +26 -0
- package/build/package-identity.js +28 -0
- package/build/runPool.d.ts +36 -0
- package/build/runPool.js +51 -0
- package/build/runtime.d.ts +71 -0
- package/build/runtime.js +659 -0
- package/build/search/auto-memory.d.ts +47 -0
- package/build/search/auto-memory.js +170 -0
- package/build/search/ctx-search-schema.d.ts +90 -0
- package/build/search/ctx-search-schema.js +135 -0
- package/build/search/flood-guard.d.ts +57 -0
- package/build/search/flood-guard.js +80 -0
- package/build/search/unified.d.ts +56 -0
- package/build/search/unified.js +104 -0
- package/build/security.d.ts +206 -0
- package/build/security.js +780 -0
- package/build/server.d.ts +240 -0
- package/build/server.js +5034 -0
- package/build/session/analytics.d.ts +773 -0
- package/build/session/analytics.js +2420 -0
- package/build/session/db.d.ts +468 -0
- package/build/session/db.js +1330 -0
- package/build/session/error-classifier.d.ts +87 -0
- package/build/session/error-classifier.js +303 -0
- package/build/session/event-emit.d.ts +48 -0
- package/build/session/event-emit.js +101 -0
- package/build/session/extract.d.ts +333 -0
- package/build/session/extract.js +2688 -0
- package/build/session/model-prices.json +429 -0
- package/build/session/persist-tool-calls.d.ts +54 -0
- package/build/session/persist-tool-calls.js +105 -0
- package/build/session/pricing.d.ts +64 -0
- package/build/session/pricing.js +151 -0
- package/build/session/project-attribution.d.ts +73 -0
- package/build/session/project-attribution.js +245 -0
- package/build/session/purge.d.ts +138 -0
- package/build/session/purge.js +240 -0
- package/build/session/retrieval-marker.d.ts +39 -0
- package/build/session/retrieval-marker.js +65 -0
- package/build/session/snapshot.d.ts +46 -0
- package/build/session/snapshot.js +532 -0
- package/build/store-directory.d.ts +56 -0
- package/build/store-directory.js +254 -0
- package/build/store.d.ts +147 -0
- package/build/store.js +1714 -0
- package/build/truncate.d.ts +57 -0
- package/build/truncate.js +142 -0
- package/build/types.d.ts +117 -0
- package/build/types.js +20 -0
- package/build/util/claude-config.d.ts +32 -0
- package/build/util/claude-config.js +84 -0
- package/build/util/hook-config.d.ts +27 -0
- package/build/util/hook-config.js +76 -0
- package/build/util/jsonc.d.ts +14 -0
- package/build/util/jsonc.js +104 -0
- package/build/util/plugin-cache-integrity.d.ts +51 -0
- package/build/util/plugin-cache-integrity.js +146 -0
- package/build/util/project-dir.d.ts +149 -0
- package/build/util/project-dir.js +340 -0
- package/build/util/sibling-mcp.d.ts +79 -0
- package/build/util/sibling-mcp.js +181 -0
- package/cli.bundle.mjs +1495 -0
- package/configs/antigravity/GEMINI.md +68 -0
- package/configs/antigravity/mcp_config.json +7 -0
- package/configs/antigravity-cli/hooks/hooks.json +37 -0
- package/configs/antigravity-cli/hooks.json +37 -0
- package/configs/antigravity-cli/mcp_config.json +10 -0
- package/configs/antigravity-cli/plugin.json +14 -0
- package/configs/antigravity-cli/rules/context-mode.md +77 -0
- package/configs/antigravity-cli/skills/context-mode/SKILL.md +77 -0
- package/configs/claude-code/CLAUDE.md +91 -0
- package/configs/codex/AGENTS.md +99 -0
- package/configs/codex/config.toml +8 -0
- package/configs/codex/hooks.json +47 -0
- package/configs/copilot-cli/.github/plugin/plugin.json +23 -0
- package/configs/copilot-cli/.mcp.json +12 -0
- package/configs/copilot-cli/README.md +47 -0
- package/configs/copilot-cli/hooks.json +41 -0
- package/configs/copilot-cli/skills/context-mode/SKILL.md +38 -0
- package/configs/cursor/context-mode.mdc +76 -0
- package/configs/cursor/hooks.json +21 -0
- package/configs/cursor/mcp.json +7 -0
- package/configs/gemini-cli/GEMINI.md +88 -0
- package/configs/gemini-cli/mcp.json +7 -0
- package/configs/gemini-cli/settings.json +60 -0
- package/configs/jetbrains-copilot/copilot-instructions.md +80 -0
- package/configs/jetbrains-copilot/hooks.json +16 -0
- package/configs/jetbrains-copilot/mcp.json +7 -0
- package/configs/kilo/AGENTS.md +84 -0
- package/configs/kilo/kilo.json +6 -0
- package/configs/kimi/hooks.json +54 -0
- package/configs/kiro/KIRO.md +84 -0
- package/configs/kiro/agent.json +18 -0
- package/configs/kiro/mcp.json +7 -0
- package/configs/omp/SYSTEM.md +85 -0
- package/configs/omp/mcp.json +7 -0
- package/configs/openclaw/AGENTS.md +87 -0
- package/configs/openclaw/openclaw.json +13 -0
- package/configs/opencode/AGENTS.md +84 -0
- package/configs/opencode/opencode.json +6 -0
- package/configs/pi/AGENTS.md +3 -0
- package/configs/qwen-code/QWEN.md +91 -0
- package/configs/vscode-copilot/copilot-instructions.md +80 -0
- package/configs/vscode-copilot/hooks.json +16 -0
- package/configs/vscode-copilot/mcp.json +7 -0
- package/configs/zed/AGENTS.md +68 -0
- package/hooks/antigravity-cli/payload.mjs +98 -0
- package/hooks/antigravity-cli/posttooluse.mjs +138 -0
- package/hooks/antigravity-cli/pretooluse.mjs +78 -0
- package/hooks/antigravity-cli/stop.mjs +58 -0
- package/hooks/auto-injection.mjs +102 -0
- package/hooks/cache-heal-utils.mjs +379 -0
- package/hooks/codex/platform.mjs +1 -0
- package/hooks/codex/posttooluse.mjs +66 -0
- package/hooks/codex/precompact.mjs +70 -0
- package/hooks/codex/pretooluse.mjs +42 -0
- package/hooks/codex/sessionstart.mjs +121 -0
- package/hooks/codex/stop.mjs +138 -0
- package/hooks/codex/userpromptsubmit.mjs +75 -0
- package/hooks/copilot-cli/posttooluse.mjs +79 -0
- package/hooks/copilot-cli/precompact.mjs +66 -0
- package/hooks/copilot-cli/pretooluse.mjs +41 -0
- package/hooks/copilot-cli/sessionstart.mjs +121 -0
- package/hooks/copilot-cli/stop.mjs +59 -0
- package/hooks/copilot-cli/userpromptsubmit.mjs +77 -0
- package/hooks/core/codex-caps.mjs +112 -0
- package/hooks/core/formatters.mjs +356 -0
- package/hooks/core/mcp-ready.mjs +109 -0
- package/hooks/core/platform-detect.mjs +49 -0
- package/hooks/core/routing.mjs +1050 -0
- package/hooks/core/stdin.mjs +90 -0
- package/hooks/core/tool-naming.mjs +57 -0
- package/hooks/cursor/afteragentresponse.mjs +74 -0
- package/hooks/cursor/hooks.json +31 -0
- package/hooks/cursor/posttooluse.mjs +72 -0
- package/hooks/cursor/pretooluse.mjs +26 -0
- package/hooks/cursor/sessionstart.mjs +97 -0
- package/hooks/cursor/stop.mjs +48 -0
- package/hooks/ensure-deps.mjs +254 -0
- package/hooks/formatters/claude-code.mjs +113 -0
- package/hooks/formatters/cursor.mjs +37 -0
- package/hooks/formatters/gemini-cli.mjs +55 -0
- package/hooks/formatters/vscode-copilot.mjs +55 -0
- package/hooks/gemini-cli/aftermodel.mjs +70 -0
- package/hooks/gemini-cli/aftertool.mjs +61 -0
- package/hooks/gemini-cli/beforeagent.mjs +99 -0
- package/hooks/gemini-cli/beforetool.mjs +27 -0
- package/hooks/gemini-cli/precompress.mjs +55 -0
- package/hooks/gemini-cli/sessionstart.mjs +137 -0
- package/hooks/heal-partial-install.mjs +712 -0
- package/hooks/hooks.json +143 -0
- package/hooks/jetbrains-copilot/posttooluse.mjs +61 -0
- package/hooks/jetbrains-copilot/precompact.mjs +55 -0
- package/hooks/jetbrains-copilot/pretooluse.mjs +27 -0
- package/hooks/jetbrains-copilot/sessionstart.mjs +124 -0
- package/hooks/kimi/platform.mjs +1 -0
- package/hooks/kimi/posttooluse.mjs +72 -0
- package/hooks/kimi/precompact.mjs +80 -0
- package/hooks/kimi/pretooluse.mjs +42 -0
- package/hooks/kimi/sessionend.mjs +61 -0
- package/hooks/kimi/sessionstart.mjs +113 -0
- package/hooks/kimi/stop.mjs +132 -0
- package/hooks/kimi/userpromptsubmit.mjs +90 -0
- package/hooks/kiro/agentspawn.mjs +97 -0
- package/hooks/kiro/posttooluse.mjs +51 -0
- package/hooks/kiro/pretooluse.mjs +64 -0
- package/hooks/kiro/userpromptsubmit.mjs +88 -0
- package/hooks/normalize-hooks.mjs +323 -0
- package/hooks/platform-bridge.mjs +340 -0
- package/hooks/posttooluse.mjs +225 -0
- package/hooks/precompact.mjs +100 -0
- package/hooks/pretooluse.mjs +227 -0
- package/hooks/qwen-code/platform.mjs +1 -0
- package/hooks/qwen-code/stop.mjs +168 -0
- package/hooks/routing-block.mjs +105 -0
- package/hooks/run-hook.mjs +95 -0
- package/hooks/security.bundle.mjs +2 -0
- package/hooks/session-attribution.bundle.mjs +1 -0
- package/hooks/session-db.bundle.mjs +145 -0
- package/hooks/session-directive.mjs +520 -0
- package/hooks/session-extract.bundle.mjs +3 -0
- package/hooks/session-helpers.mjs +428 -0
- package/hooks/session-loaders.mjs +448 -0
- package/hooks/session-snapshot.bundle.mjs +32 -0
- package/hooks/sessionstart.mjs +464 -0
- package/hooks/stop.mjs +82 -0
- package/hooks/suppress-stderr.mjs +25 -0
- package/hooks/userpromptsubmit.mjs +108 -0
- package/hooks/vscode-copilot/posttooluse.mjs +61 -0
- package/hooks/vscode-copilot/precompact.mjs +55 -0
- package/hooks/vscode-copilot/pretooluse.mjs +27 -0
- package/hooks/vscode-copilot/sessionstart.mjs +129 -0
- package/openclaw.plugin.json +38 -0
- package/package.json +132 -0
- package/scripts/heal-better-sqlite3.mjs +430 -0
- package/scripts/heal-installed-plugins.mjs +635 -0
- package/scripts/plugin-cache-integrity.mjs +248 -0
- package/scripts/postinstall.mjs +397 -0
- package/server.bundle.mjs +1421 -0
- package/server.js +5 -0
- package/skills/.ignore +7 -0
- package/skills/context-mode/SKILL.md +300 -0
- package/skills/context-mode/references/anti-patterns.md +283 -0
- package/skills/context-mode/references/patterns-javascript.md +298 -0
- package/skills/context-mode/references/patterns-python.md +304 -0
- package/skills/context-mode/references/patterns-shell.md +277 -0
- package/skills/ctx-doctor/SKILL.md +22 -0
- package/skills/ctx-index/SKILL.md +46 -0
- package/skills/ctx-insight/SKILL.md +24 -0
- package/skills/ctx-purge/SKILL.md +49 -0
- package/skills/ctx-search/SKILL.md +35 -0
- package/skills/ctx-stats/SKILL.md +26 -0
- package/skills/ctx-upgrade/SKILL.md +31 -0
- package/start.mjs +616 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode / KiloCode TypeScript plugin entry point for context-mode.
|
|
3
|
+
*
|
|
4
|
+
* Dual-flavor compatibility (opencode v1 + v2):
|
|
5
|
+
* - v1 hosts load the plugin via `server(input)` (PluginModule default
|
|
6
|
+
* export with shape `{ id, server }`).
|
|
7
|
+
* - v2 hosts load the plugin via `setup(ctx)` on the default-export object
|
|
8
|
+
* `{ id, server?, setup }` (v2 PluginModule shape).
|
|
9
|
+
* Both entries live on the SAME default export object; each host picks the
|
|
10
|
+
* entrypoint it supports. No `tui` marker is set (it would invalidate
|
|
11
|
+
* server loading per the v2 migration guide).
|
|
12
|
+
*
|
|
13
|
+
* The v2 PluginContext surface is VERIFIED (opencode2 beta-19135 live probe
|
|
14
|
+
* + docs at opencode.ai/v2/docs/build/plugins): ctx.tool.transform(editor)
|
|
15
|
+
* registers native ctx_* tools (ToolEditor), ctx.tool.hook
|
|
16
|
+
* ("execute.before"/"execute.after") bridges routing enforcement + capture,
|
|
17
|
+
* ctx.session.hook("context"|"prompt") covers system-context injection
|
|
18
|
+
* (continuations AND compaction) and user-prompt capture, and
|
|
19
|
+
* ctx.event.subscribe() streams bus events. The v2 `setup` path probes each
|
|
20
|
+
* surface defensively (typeof checks; UNCONFIRMED payload fields are read
|
|
21
|
+
* defensively) and degrades HONESTLY — one-time log, never fake success.
|
|
22
|
+
* Mandatory for activation: native tool registration AND execute hooks;
|
|
23
|
+
* anything mandatory missing → no claim (MCP fallback stays intact); the
|
|
24
|
+
* session/event surfaces are optional and degrade with one-time logs.
|
|
25
|
+
*
|
|
26
|
+
* Hybrid-host guard: a process-global activation registry (keyed by plugin
|
|
27
|
+
* id + normalized project directory) ensures only ONE flavor activates per
|
|
28
|
+
* project per process. The second entrypoint (v1 server() or v2 setup())
|
|
29
|
+
* returns a noop/empty registration and logs once ("context-mode already
|
|
30
|
+
* active via <flavor>"). v1 claims if no claimant exists; v1 behavior is
|
|
31
|
+
* otherwise unchanged for existing users.
|
|
32
|
+
*
|
|
33
|
+
* Five hooks (v1.0.107 — Mickey OC-1..OC-4 follow-up):
|
|
34
|
+
* - tool.execute.before — Routing enforcement (deny/modify/passthrough)
|
|
35
|
+
* - tool.execute.after — Session event capture + first-fire AGENTS.md scan (OC-4)
|
|
36
|
+
* - experimental.session.compacting — Compaction snapshot + budget-capped auto-injection (OC-3)
|
|
37
|
+
* - experimental.chat.system.transform — ROUTING_BLOCK + resume snapshot injection (OC-1)
|
|
38
|
+
* - chat.message — User-prompt capture w/ CCv2 inline filter (OC-2) + AGENTS.md scan (OC-4)
|
|
39
|
+
*
|
|
40
|
+
* KiloCode loads this via: import("@mxalbert/context-mode") → expects default export
|
|
41
|
+
* with shape { server: (input) => Promise<Hooks> } (PluginModule).
|
|
42
|
+
*
|
|
43
|
+
* OpenCode loads this via: import("@mxalbert/context-mode/plugin") → also supports
|
|
44
|
+
* the named export ContextModePlugin for backward compat.
|
|
45
|
+
*
|
|
46
|
+
* Constraints:
|
|
47
|
+
* - No SessionStart hook (OpenCode doesn't support it — #14808, #5409)
|
|
48
|
+
* - context injection now via chat.system.transform surrogate (OC-1)
|
|
49
|
+
* - No routing file auto-write (avoid dirtying project trees)
|
|
50
|
+
* - Session cleanup happens at plugin init (no SessionStart)
|
|
51
|
+
*/
|
|
52
|
+
import { type PluginGlobalState } from "./index.js";
|
|
53
|
+
import { type PluginClient, type V2SetupContext } from "./v2.js";
|
|
54
|
+
type PluginContext = {
|
|
55
|
+
client: PluginClient;
|
|
56
|
+
directory: string;
|
|
57
|
+
};
|
|
58
|
+
type NativeToolContext = {
|
|
59
|
+
sessionID: string;
|
|
60
|
+
messageID: string;
|
|
61
|
+
agent: string;
|
|
62
|
+
directory: string;
|
|
63
|
+
worktree?: string;
|
|
64
|
+
abort?: AbortSignal;
|
|
65
|
+
metadata?: (input: {
|
|
66
|
+
title?: string;
|
|
67
|
+
metadata?: Record<string, unknown>;
|
|
68
|
+
}) => void;
|
|
69
|
+
};
|
|
70
|
+
type NativeToolDefinition = {
|
|
71
|
+
description: string;
|
|
72
|
+
args: Record<string, unknown>;
|
|
73
|
+
/**
|
|
74
|
+
* JSON-Schema view of the tool's Zod input schema (single shared
|
|
75
|
+
* conversion via zodSchemaToJsonSchema) — consumed by the v2 ToolEditor
|
|
76
|
+
* registration (ToolInfo.input). v1 hosts ignore this extra field.
|
|
77
|
+
*/
|
|
78
|
+
inputJsonSchema?: Record<string, unknown>;
|
|
79
|
+
execute: (args: Record<string, unknown>, ctx: NativeToolContext) => Promise<string | {
|
|
80
|
+
title?: string;
|
|
81
|
+
output: string;
|
|
82
|
+
metadata?: Record<string, unknown>;
|
|
83
|
+
}>;
|
|
84
|
+
};
|
|
85
|
+
/** OpenCode tool.execute.before — first parameter */
|
|
86
|
+
interface BeforeHookInput {
|
|
87
|
+
tool: string;
|
|
88
|
+
sessionID: string;
|
|
89
|
+
callID: string;
|
|
90
|
+
}
|
|
91
|
+
/** OpenCode tool.execute.before — second parameter */
|
|
92
|
+
interface BeforeHookOutput {
|
|
93
|
+
args: any;
|
|
94
|
+
}
|
|
95
|
+
/** OpenCode tool.execute.after — first parameter */
|
|
96
|
+
interface AfterHookInput {
|
|
97
|
+
tool: string;
|
|
98
|
+
sessionID: string;
|
|
99
|
+
callID: string;
|
|
100
|
+
args: any;
|
|
101
|
+
}
|
|
102
|
+
/** OpenCode tool.execute.after — second parameter */
|
|
103
|
+
interface AfterHookOutput {
|
|
104
|
+
title: string;
|
|
105
|
+
output: string;
|
|
106
|
+
metadata: any;
|
|
107
|
+
/**
|
|
108
|
+
* Failure signal consumed by the shared capture handler. The v1 host
|
|
109
|
+
* never sets it (OpenCode doesn't provide isError — the response text
|
|
110
|
+
* alone drives error detection); the v2 execute.after bridge sets it on
|
|
111
|
+
* `status: "error"` so failed tool calls produce error_tool events via
|
|
112
|
+
* the SAME extractEvents path (extract.ts isToolError).
|
|
113
|
+
*/
|
|
114
|
+
isError?: boolean;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* OpenCode generic bus `event` hook — single parameter.
|
|
118
|
+
* The plugin SDK delivers every bus Event here (refs/platforms/opencode/
|
|
119
|
+
* packages/plugin/src/index.ts:224). We narrow to `message.updated`, whose
|
|
120
|
+
* `properties.info` is the full assistant Message carrying tokens/cost/modelID.
|
|
121
|
+
*/
|
|
122
|
+
interface EventHookInput {
|
|
123
|
+
event?: {
|
|
124
|
+
type?: string;
|
|
125
|
+
properties?: {
|
|
126
|
+
info?: {
|
|
127
|
+
sessionID?: string;
|
|
128
|
+
} & Record<string, unknown>;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** OpenCode experimental.session.compacting — first parameter */
|
|
133
|
+
interface CompactingHookInput {
|
|
134
|
+
sessionID: string;
|
|
135
|
+
}
|
|
136
|
+
/** OpenCode experimental.session.compacting — second parameter */
|
|
137
|
+
interface CompactingHookOutput {
|
|
138
|
+
context: string[];
|
|
139
|
+
prompt?: string;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* OpenCode experimental.chat.system.transform — first parameter.
|
|
143
|
+
* Verified against sst/opencode/dev/packages/plugin/src/index.ts:
|
|
144
|
+
* input: { sessionID?: string; model: Model }
|
|
145
|
+
* `sessionID` is optional in the SDK type but is in practice always set
|
|
146
|
+
* (the transform runs *for* a session). We treat it as required and
|
|
147
|
+
* skip injection when absent rather than fall back to a fabricated ID.
|
|
148
|
+
*
|
|
149
|
+
* NOTE: We deliberately do NOT use `experimental.chat.messages.transform`.
|
|
150
|
+
* Its SDK input shape is `{}` (no sessionID) and its output is
|
|
151
|
+
* `{ messages: { info: Message; parts: Part[] }[] }` — the prior code
|
|
152
|
+
* (`output.messages.unshift({ role, content })`) wrote a value of the
|
|
153
|
+
* wrong shape and was silently dropped (Mickey / PR #376 root cause).
|
|
154
|
+
*/
|
|
155
|
+
interface SystemTransformHookInput {
|
|
156
|
+
sessionID?: string;
|
|
157
|
+
model: unknown;
|
|
158
|
+
}
|
|
159
|
+
/** OpenCode experimental.chat.system.transform — second parameter */
|
|
160
|
+
interface SystemTransformHookOutput {
|
|
161
|
+
system: string[];
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* OpenCode chat.message hook — verified against
|
|
165
|
+
* refs/platforms/opencode/packages/plugin/src/index.ts:233.
|
|
166
|
+
* input: { sessionID; agent?; model?; messageID?; variant? }
|
|
167
|
+
* output: { message: UserMessage; parts: Part[] }
|
|
168
|
+
* We read text from `parts[*].text` (the orchestrator reference at
|
|
169
|
+
* refs/plugin-examples/opencode/opencode-orchestrator/src/plugin-handlers/
|
|
170
|
+
* chat-message-handler.ts:41-65 uses the same pattern).
|
|
171
|
+
*/
|
|
172
|
+
interface ChatMessageHookInput {
|
|
173
|
+
sessionID: string;
|
|
174
|
+
agent?: string;
|
|
175
|
+
messageID?: string;
|
|
176
|
+
}
|
|
177
|
+
interface ChatMessagePart {
|
|
178
|
+
type: string;
|
|
179
|
+
text?: string;
|
|
180
|
+
}
|
|
181
|
+
interface ChatMessageHookOutput {
|
|
182
|
+
message: unknown;
|
|
183
|
+
parts: ChatMessagePart[];
|
|
184
|
+
}
|
|
185
|
+
declare const ROUTING_MARKERS: string[];
|
|
186
|
+
declare function systemHasRoutingInstructions(system: string[]): boolean;
|
|
187
|
+
/** Test-only: clear process-global activation + log-dedupe state. */
|
|
188
|
+
export declare function __resetPluginStateForTests(): void;
|
|
189
|
+
/** Test-only: expose the process-global state for assertions. */
|
|
190
|
+
export declare function __getPluginGlobalState(): PluginGlobalState;
|
|
191
|
+
/** Test-only: close the cached fd and clear the sink cache so each test gets a fresh sink. */
|
|
192
|
+
export declare function __resetPluginLogSinkForTests(): void;
|
|
193
|
+
/**
|
|
194
|
+
* Plugin factory. Called once when a v1 host (KiloCode/OpenCode ≤ v1) loads
|
|
195
|
+
* the plugin. Returns an object mapping hook event names to async handler
|
|
196
|
+
* functions over the shared runtime.
|
|
197
|
+
*
|
|
198
|
+
* Hybrid-host guard: if the v2 setup() path (or another v1 server() call)
|
|
199
|
+
* already claimed activation for this project, this returns an EMPTY
|
|
200
|
+
* registration — no hooks, no DB init — and logs once.
|
|
201
|
+
*
|
|
202
|
+
* KiloCode expects: export default { id: string, server: (input) => Promise<Hooks> }
|
|
203
|
+
* OpenCode expects: export const ContextModePlugin = (ctx) => Promise<Hooks>
|
|
204
|
+
*/
|
|
205
|
+
declare function createContextModePlugin(ctx: PluginContext): Promise<{
|
|
206
|
+
tool: {};
|
|
207
|
+
"tool.execute.before"?: undefined;
|
|
208
|
+
"tool.execute.after"?: undefined;
|
|
209
|
+
event?: undefined;
|
|
210
|
+
"chat.message"?: undefined;
|
|
211
|
+
"experimental.session.compacting"?: undefined;
|
|
212
|
+
"experimental.chat.system.transform"?: undefined;
|
|
213
|
+
} | {
|
|
214
|
+
tool: Record<string, NativeToolDefinition>;
|
|
215
|
+
"tool.execute.before": (input: BeforeHookInput, output: BeforeHookOutput) => Promise<void>;
|
|
216
|
+
"tool.execute.after": (input: AfterHookInput, output: AfterHookOutput) => Promise<void>;
|
|
217
|
+
event: (input: EventHookInput) => Promise<void>;
|
|
218
|
+
"chat.message": (input: ChatMessageHookInput, output: ChatMessageHookOutput) => Promise<void>;
|
|
219
|
+
"experimental.session.compacting": (input: CompactingHookInput, output: CompactingHookOutput) => Promise<string>;
|
|
220
|
+
"experimental.chat.system.transform": (input: SystemTransformHookInput, output: SystemTransformHookOutput) => Promise<void>;
|
|
221
|
+
}>;
|
|
222
|
+
/**
|
|
223
|
+
* v2 plugin setup. Registers the v1-equivalent behaviors against whatever
|
|
224
|
+
* v2 surfaces the host exposes (runtime capability probing) and honors the
|
|
225
|
+
* hybrid-host activation guard.
|
|
226
|
+
*
|
|
227
|
+
* ACTIVATION POLICY: v2 may claim ONLY when the FULL mandatory surface
|
|
228
|
+
* succeeds — tool execute before/after hooks AND native ctx_* tool
|
|
229
|
+
* registration. If native tools cannot be registered, v2 does NOT claim
|
|
230
|
+
* (one-time degraded-reason log, MCP fallback retained) so a v1 server()
|
|
231
|
+
* entry can still claim for this project; on pure v2 hosts the same path
|
|
232
|
+
* yields honest degraded mode with mcp.context-mode retained. Optional
|
|
233
|
+
* capabilities (session context, event bus) degrade with one-time logs —
|
|
234
|
+
* never a fake success.
|
|
235
|
+
*
|
|
236
|
+
* Returns a cleanup function (where the host supports one) that unregisters
|
|
237
|
+
* everything registered, closes the runtime DB handle, and releases the
|
|
238
|
+
* activation claim so a plugin reload can re-claim without double-registering
|
|
239
|
+
* or leaking the old DB.
|
|
240
|
+
*/
|
|
241
|
+
declare function setupV2(ctx: V2SetupContext): Promise<(() => void) | void>;
|
|
242
|
+
declare const _default: {
|
|
243
|
+
id: string;
|
|
244
|
+
server: typeof createContextModePlugin;
|
|
245
|
+
setup: typeof setupV2;
|
|
246
|
+
};
|
|
247
|
+
export default _default;
|
|
248
|
+
export { createContextModePlugin as ContextModePlugin, setupV2 as ContextModeSetup };
|
|
249
|
+
export { systemHasRoutingInstructions, ROUTING_MARKERS };
|