context-mode 1.0.169 → 2.0.0-next.6
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 +4 -22
- package/.claude-plugin/plugin.json +9 -24
- package/.codex-plugin/hooks.json +18 -33
- package/.codex-plugin/mcp.json +5 -4
- package/.codex-plugin/plugin.json +8 -27
- package/SHA256SUMS +37 -0
- package/claude-code/skills/ctx-doctor/SKILL.md +6 -0
- package/claude-code/skills/ctx-stats/SKILL.md +6 -0
- package/claude-code/skills/ctx-upgrade/SKILL.md +6 -0
- package/cli.mjs +6859 -0
- package/codex/skills/ctx-doctor/SKILL.md +6 -0
- package/codex/skills/ctx-stats/SKILL.md +6 -0
- package/codex/skills/ctx-upgrade/SKILL.md +6 -0
- package/copilot/plugin.json +14 -0
- package/fixtures/hook-roundtrip.json +22 -0
- package/gemini-extension.json +14 -0
- package/hook.mjs +202 -0
- package/hooks/claude-code.json +50 -0
- package/hooks/codex.json +50 -0
- package/hooks/copilot-cli.json +33 -0
- package/hooks/hooks.json +16 -111
- package/hooks/kiro.json +69 -0
- package/hooks/qwen.json +50 -0
- package/hooks/vscode.json +40 -0
- package/hooks/zcode.json +53 -0
- package/opencode/plugin.js +22491 -0
- package/package.json +32 -114
- package/pi/index.js +50876 -0
- package/pi/skills/ctx-doctor/SKILL.md +6 -0
- package/pi/skills/ctx-stats/SKILL.md +6 -0
- package/pi/skills/ctx-upgrade/SKILL.md +6 -0
- package/qwen-extension.json +15 -0
- package/run.mjs +5639 -0
- package/search.mjs +5639 -0
- package/server.mjs +48214 -0
- package/skills/ctx-doctor/SKILL.md +3 -19
- package/skills/ctx-stats/SKILL.md +3 -23
- package/skills/ctx-upgrade/SKILL.md +3 -28
- package/.openclaw-plugin/index.ts +0 -12
- package/.openclaw-plugin/openclaw.plugin.json +0 -38
- package/.openclaw-plugin/package.json +0 -28
- package/LICENSE +0 -94
- package/README.md +0 -1619
- package/bin/statusline.mjs +0 -378
- package/build/adapters/antigravity/index.d.ts +0 -51
- package/build/adapters/antigravity/index.js +0 -169
- package/build/adapters/antigravity-cli/index.d.ts +0 -51
- package/build/adapters/antigravity-cli/index.js +0 -342
- package/build/adapters/base.d.ts +0 -92
- package/build/adapters/base.js +0 -135
- package/build/adapters/claude-code/config.d.ts +0 -8
- package/build/adapters/claude-code/config.js +0 -8
- package/build/adapters/claude-code/hooks.d.ts +0 -106
- package/build/adapters/claude-code/hooks.js +0 -183
- package/build/adapters/claude-code/index.d.ts +0 -80
- package/build/adapters/claude-code/index.js +0 -569
- package/build/adapters/claude-code-base.d.ts +0 -49
- package/build/adapters/claude-code-base.js +0 -113
- package/build/adapters/client-map.d.ts +0 -10
- package/build/adapters/client-map.js +0 -42
- package/build/adapters/codex/config.d.ts +0 -8
- package/build/adapters/codex/config.js +0 -8
- package/build/adapters/codex/hooks.d.ts +0 -55
- package/build/adapters/codex/hooks.js +0 -64
- package/build/adapters/codex/index.d.ts +0 -87
- package/build/adapters/codex/index.js +0 -992
- package/build/adapters/codex/paths.d.ts +0 -1
- package/build/adapters/codex/paths.js +0 -12
- package/build/adapters/codex/usage.d.ts +0 -107
- package/build/adapters/codex/usage.js +0 -227
- package/build/adapters/copilot-base.d.ts +0 -94
- package/build/adapters/copilot-base.js +0 -297
- package/build/adapters/copilot-cli/hooks.d.ts +0 -33
- package/build/adapters/copilot-cli/hooks.js +0 -64
- package/build/adapters/copilot-cli/index.d.ts +0 -48
- package/build/adapters/copilot-cli/index.js +0 -341
- package/build/adapters/cursor/config.d.ts +0 -4
- package/build/adapters/cursor/config.js +0 -4
- package/build/adapters/cursor/hooks.d.ts +0 -55
- package/build/adapters/cursor/hooks.js +0 -82
- package/build/adapters/cursor/index.d.ts +0 -64
- package/build/adapters/cursor/index.js +0 -517
- package/build/adapters/detect.d.ts +0 -136
- package/build/adapters/detect.js +0 -623
- package/build/adapters/gemini-cli/config.d.ts +0 -8
- package/build/adapters/gemini-cli/config.js +0 -8
- package/build/adapters/gemini-cli/hooks.d.ts +0 -83
- package/build/adapters/gemini-cli/hooks.js +0 -115
- package/build/adapters/gemini-cli/index.d.ts +0 -80
- package/build/adapters/gemini-cli/index.js +0 -483
- package/build/adapters/jetbrains-copilot/config.d.ts +0 -8
- package/build/adapters/jetbrains-copilot/config.js +0 -8
- package/build/adapters/jetbrains-copilot/hooks.d.ts +0 -59
- package/build/adapters/jetbrains-copilot/hooks.js +0 -87
- package/build/adapters/jetbrains-copilot/index.d.ts +0 -31
- package/build/adapters/jetbrains-copilot/index.js +0 -131
- package/build/adapters/kimi/config.d.ts +0 -8
- package/build/adapters/kimi/config.js +0 -8
- package/build/adapters/kimi/hooks.d.ts +0 -28
- package/build/adapters/kimi/hooks.js +0 -34
- package/build/adapters/kimi/index.d.ts +0 -66
- package/build/adapters/kimi/index.js +0 -537
- package/build/adapters/kimi/paths.d.ts +0 -21
- package/build/adapters/kimi/paths.js +0 -52
- package/build/adapters/kimi/usage.d.ts +0 -82
- package/build/adapters/kimi/usage.js +0 -217
- package/build/adapters/kiro/hooks.d.ts +0 -61
- package/build/adapters/kiro/hooks.js +0 -94
- package/build/adapters/kiro/index.d.ts +0 -61
- package/build/adapters/kiro/index.js +0 -301
- package/build/adapters/omp/index.d.ts +0 -65
- package/build/adapters/omp/index.js +0 -182
- package/build/adapters/omp/plugin.d.ts +0 -81
- package/build/adapters/omp/plugin.js +0 -331
- package/build/adapters/omp/usage.d.ts +0 -49
- package/build/adapters/omp/usage.js +0 -110
- package/build/adapters/openclaw/config.d.ts +0 -8
- package/build/adapters/openclaw/config.js +0 -8
- package/build/adapters/openclaw/hooks.d.ts +0 -50
- package/build/adapters/openclaw/hooks.js +0 -61
- package/build/adapters/openclaw/index.d.ts +0 -74
- package/build/adapters/openclaw/index.js +0 -439
- package/build/adapters/openclaw/mcp-tools.d.ts +0 -54
- package/build/adapters/openclaw/mcp-tools.js +0 -207
- package/build/adapters/openclaw/plugin.d.ts +0 -141
- package/build/adapters/openclaw/plugin.js +0 -818
- package/build/adapters/openclaw/session-db.d.ts +0 -55
- package/build/adapters/openclaw/session-db.js +0 -88
- package/build/adapters/openclaw/usage.d.ts +0 -34
- package/build/adapters/openclaw/usage.js +0 -52
- package/build/adapters/openclaw/workspace-router.d.ts +0 -29
- package/build/adapters/openclaw/workspace-router.js +0 -64
- package/build/adapters/opencode/config.d.ts +0 -8
- package/build/adapters/opencode/config.js +0 -8
- package/build/adapters/opencode/hooks.d.ts +0 -38
- package/build/adapters/opencode/hooks.js +0 -50
- package/build/adapters/opencode/index.d.ts +0 -67
- package/build/adapters/opencode/index.js +0 -463
- package/build/adapters/opencode/plugin.d.ts +0 -184
- package/build/adapters/opencode/plugin.js +0 -558
- package/build/adapters/opencode/zod3tov4.d.ts +0 -1
- package/build/adapters/opencode/zod3tov4.js +0 -132
- package/build/adapters/pi/extension.d.ts +0 -81
- package/build/adapters/pi/extension.js +0 -861
- package/build/adapters/pi/index.d.ts +0 -57
- package/build/adapters/pi/index.js +0 -173
- package/build/adapters/pi/mcp-bridge.d.ts +0 -268
- package/build/adapters/pi/mcp-bridge.js +0 -894
- package/build/adapters/qwen-code/hooks.d.ts +0 -26
- package/build/adapters/qwen-code/hooks.js +0 -29
- package/build/adapters/qwen-code/index.d.ts +0 -40
- package/build/adapters/qwen-code/index.js +0 -361
- package/build/adapters/qwen-code/usage.d.ts +0 -90
- package/build/adapters/qwen-code/usage.js +0 -222
- package/build/adapters/types.d.ts +0 -360
- package/build/adapters/types.js +0 -118
- package/build/adapters/vscode-copilot/config.d.ts +0 -8
- package/build/adapters/vscode-copilot/config.js +0 -8
- package/build/adapters/vscode-copilot/hooks.d.ts +0 -71
- package/build/adapters/vscode-copilot/hooks.js +0 -98
- package/build/adapters/vscode-copilot/index.d.ts +0 -32
- package/build/adapters/vscode-copilot/index.js +0 -222
- package/build/adapters/zed/index.d.ts +0 -40
- package/build/adapters/zed/index.js +0 -163
- package/build/cli.d.ts +0 -34
- package/build/cli.js +0 -1827
- package/build/db-base.d.ts +0 -179
- package/build/db-base.js +0 -569
- package/build/executor.d.ts +0 -72
- package/build/executor.js +0 -678
- package/build/exit-classify.d.ts +0 -19
- package/build/exit-classify.js +0 -12
- package/build/fetch-cache.d.ts +0 -13
- package/build/fetch-cache.js +0 -15
- package/build/lifecycle.d.ts +0 -124
- package/build/lifecycle.js +0 -278
- package/build/runPool.d.ts +0 -36
- package/build/runPool.js +0 -51
- package/build/runtime.d.ts +0 -71
- package/build/runtime.js +0 -659
- package/build/search/auto-memory.d.ts +0 -47
- package/build/search/auto-memory.js +0 -170
- package/build/search/ctx-search-schema.d.ts +0 -90
- package/build/search/ctx-search-schema.js +0 -135
- package/build/search/flood-guard.d.ts +0 -57
- package/build/search/flood-guard.js +0 -80
- package/build/search/unified.d.ts +0 -56
- package/build/search/unified.js +0 -104
- package/build/security.d.ts +0 -206
- package/build/security.js +0 -780
- package/build/server.d.ts +0 -184
- package/build/server.js +0 -4563
- package/build/session/analytics.d.ts +0 -773
- package/build/session/analytics.js +0 -2420
- package/build/session/db.d.ts +0 -468
- package/build/session/db.js +0 -1308
- package/build/session/error-classifier.d.ts +0 -87
- package/build/session/error-classifier.js +0 -303
- package/build/session/event-emit.d.ts +0 -48
- package/build/session/event-emit.js +0 -101
- package/build/session/extract.d.ts +0 -333
- package/build/session/extract.js +0 -2688
- package/build/session/model-prices.json +0 -429
- package/build/session/persist-tool-calls.d.ts +0 -54
- package/build/session/persist-tool-calls.js +0 -105
- package/build/session/pricing.d.ts +0 -64
- package/build/session/pricing.js +0 -151
- package/build/session/project-attribution.d.ts +0 -73
- package/build/session/project-attribution.js +0 -245
- package/build/session/purge.d.ts +0 -138
- package/build/session/purge.js +0 -240
- package/build/session/retrieval-marker.d.ts +0 -39
- package/build/session/retrieval-marker.js +0 -65
- package/build/session/snapshot.d.ts +0 -46
- package/build/session/snapshot.js +0 -532
- package/build/store-directory.d.ts +0 -56
- package/build/store-directory.js +0 -254
- package/build/store.d.ts +0 -147
- package/build/store.js +0 -1714
- package/build/truncate.d.ts +0 -57
- package/build/truncate.js +0 -142
- package/build/types.d.ts +0 -117
- package/build/types.js +0 -20
- package/build/util/claude-config.d.ts +0 -32
- package/build/util/claude-config.js +0 -84
- package/build/util/hook-config.d.ts +0 -27
- package/build/util/hook-config.js +0 -76
- package/build/util/jsonc.d.ts +0 -14
- package/build/util/jsonc.js +0 -104
- package/build/util/plugin-cache-integrity.d.ts +0 -51
- package/build/util/plugin-cache-integrity.js +0 -146
- package/build/util/project-dir.d.ts +0 -149
- package/build/util/project-dir.js +0 -340
- package/build/util/sibling-mcp.d.ts +0 -79
- package/build/util/sibling-mcp.js +0 -181
- package/cli.bundle.mjs +0 -1236
- package/configs/antigravity/GEMINI.md +0 -68
- package/configs/antigravity/mcp_config.json +0 -7
- package/configs/antigravity-cli/hooks/hooks.json +0 -37
- package/configs/antigravity-cli/hooks.json +0 -37
- package/configs/antigravity-cli/mcp_config.json +0 -10
- package/configs/antigravity-cli/plugin.json +0 -14
- package/configs/antigravity-cli/rules/context-mode.md +0 -77
- package/configs/antigravity-cli/skills/context-mode/SKILL.md +0 -77
- package/configs/claude-code/CLAUDE.md +0 -91
- package/configs/codex/AGENTS.md +0 -99
- package/configs/codex/config.toml +0 -8
- package/configs/codex/hooks.json +0 -47
- package/configs/copilot-cli/.github/plugin/plugin.json +0 -23
- package/configs/copilot-cli/.mcp.json +0 -12
- package/configs/copilot-cli/README.md +0 -47
- package/configs/copilot-cli/hooks.json +0 -41
- package/configs/copilot-cli/skills/context-mode/SKILL.md +0 -38
- package/configs/cursor/context-mode.mdc +0 -76
- package/configs/cursor/hooks.json +0 -21
- package/configs/cursor/mcp.json +0 -7
- package/configs/gemini-cli/GEMINI.md +0 -88
- package/configs/gemini-cli/mcp.json +0 -7
- package/configs/gemini-cli/settings.json +0 -60
- package/configs/jetbrains-copilot/copilot-instructions.md +0 -80
- package/configs/jetbrains-copilot/hooks.json +0 -16
- package/configs/jetbrains-copilot/mcp.json +0 -7
- package/configs/kilo/AGENTS.md +0 -84
- package/configs/kilo/kilo.json +0 -6
- package/configs/kimi/hooks.json +0 -54
- package/configs/kiro/KIRO.md +0 -84
- package/configs/kiro/agent.json +0 -18
- package/configs/kiro/mcp.json +0 -7
- package/configs/omp/SYSTEM.md +0 -85
- package/configs/omp/mcp.json +0 -7
- package/configs/openclaw/AGENTS.md +0 -87
- package/configs/openclaw/openclaw.json +0 -13
- package/configs/opencode/AGENTS.md +0 -84
- package/configs/opencode/opencode.json +0 -6
- package/configs/pi/AGENTS.md +0 -3
- package/configs/qwen-code/QWEN.md +0 -91
- package/configs/vscode-copilot/copilot-instructions.md +0 -80
- package/configs/vscode-copilot/hooks.json +0 -16
- package/configs/vscode-copilot/mcp.json +0 -7
- package/configs/zed/AGENTS.md +0 -68
- package/hooks/antigravity-cli/payload.mjs +0 -98
- package/hooks/antigravity-cli/posttooluse.mjs +0 -138
- package/hooks/antigravity-cli/pretooluse.mjs +0 -78
- package/hooks/antigravity-cli/stop.mjs +0 -58
- package/hooks/auto-injection.mjs +0 -102
- package/hooks/cache-heal-utils.mjs +0 -379
- package/hooks/codex/platform.mjs +0 -1
- package/hooks/codex/posttooluse.mjs +0 -66
- package/hooks/codex/precompact.mjs +0 -70
- package/hooks/codex/pretooluse.mjs +0 -42
- package/hooks/codex/sessionstart.mjs +0 -121
- package/hooks/codex/stop.mjs +0 -138
- package/hooks/codex/userpromptsubmit.mjs +0 -75
- package/hooks/copilot-cli/posttooluse.mjs +0 -79
- package/hooks/copilot-cli/precompact.mjs +0 -66
- package/hooks/copilot-cli/pretooluse.mjs +0 -41
- package/hooks/copilot-cli/sessionstart.mjs +0 -121
- package/hooks/copilot-cli/stop.mjs +0 -59
- package/hooks/copilot-cli/userpromptsubmit.mjs +0 -77
- package/hooks/core/codex-caps.mjs +0 -112
- package/hooks/core/formatters.mjs +0 -356
- package/hooks/core/mcp-ready.mjs +0 -109
- package/hooks/core/platform-detect.mjs +0 -49
- package/hooks/core/routing.mjs +0 -1017
- package/hooks/core/stdin.mjs +0 -90
- package/hooks/core/tool-naming.mjs +0 -57
- package/hooks/cursor/afteragentresponse.mjs +0 -74
- package/hooks/cursor/hooks.json +0 -31
- package/hooks/cursor/posttooluse.mjs +0 -72
- package/hooks/cursor/pretooluse.mjs +0 -26
- package/hooks/cursor/sessionstart.mjs +0 -97
- package/hooks/cursor/stop.mjs +0 -48
- package/hooks/ensure-deps.mjs +0 -254
- package/hooks/formatters/claude-code.mjs +0 -113
- package/hooks/formatters/cursor.mjs +0 -37
- package/hooks/formatters/gemini-cli.mjs +0 -55
- package/hooks/formatters/vscode-copilot.mjs +0 -55
- package/hooks/gemini-cli/aftermodel.mjs +0 -70
- package/hooks/gemini-cli/aftertool.mjs +0 -61
- package/hooks/gemini-cli/beforeagent.mjs +0 -99
- package/hooks/gemini-cli/beforetool.mjs +0 -27
- package/hooks/gemini-cli/precompress.mjs +0 -55
- package/hooks/gemini-cli/sessionstart.mjs +0 -137
- package/hooks/heal-partial-install.mjs +0 -712
- package/hooks/jetbrains-copilot/posttooluse.mjs +0 -61
- package/hooks/jetbrains-copilot/precompact.mjs +0 -55
- package/hooks/jetbrains-copilot/pretooluse.mjs +0 -27
- package/hooks/jetbrains-copilot/sessionstart.mjs +0 -124
- package/hooks/kimi/platform.mjs +0 -1
- package/hooks/kimi/posttooluse.mjs +0 -72
- package/hooks/kimi/precompact.mjs +0 -80
- package/hooks/kimi/pretooluse.mjs +0 -42
- package/hooks/kimi/sessionend.mjs +0 -61
- package/hooks/kimi/sessionstart.mjs +0 -113
- package/hooks/kimi/stop.mjs +0 -132
- package/hooks/kimi/userpromptsubmit.mjs +0 -90
- package/hooks/kiro/agentspawn.mjs +0 -97
- package/hooks/kiro/posttooluse.mjs +0 -51
- package/hooks/kiro/pretooluse.mjs +0 -64
- package/hooks/kiro/userpromptsubmit.mjs +0 -88
- package/hooks/normalize-hooks.mjs +0 -323
- package/hooks/platform-bridge.mjs +0 -340
- package/hooks/posttooluse.mjs +0 -225
- package/hooks/precompact.mjs +0 -100
- package/hooks/pretooluse.mjs +0 -227
- package/hooks/qwen-code/platform.mjs +0 -1
- package/hooks/qwen-code/stop.mjs +0 -168
- package/hooks/routing-block.mjs +0 -105
- package/hooks/run-hook.mjs +0 -95
- package/hooks/security.bundle.mjs +0 -2
- package/hooks/session-attribution.bundle.mjs +0 -1
- package/hooks/session-db.bundle.mjs +0 -144
- package/hooks/session-directive.mjs +0 -520
- package/hooks/session-extract.bundle.mjs +0 -3
- package/hooks/session-helpers.mjs +0 -428
- package/hooks/session-loaders.mjs +0 -448
- package/hooks/session-snapshot.bundle.mjs +0 -32
- package/hooks/sessionstart.mjs +0 -464
- package/hooks/stop.mjs +0 -82
- package/hooks/suppress-stderr.mjs +0 -25
- package/hooks/userpromptsubmit.mjs +0 -108
- package/hooks/vscode-copilot/posttooluse.mjs +0 -61
- package/hooks/vscode-copilot/precompact.mjs +0 -55
- package/hooks/vscode-copilot/pretooluse.mjs +0 -27
- package/hooks/vscode-copilot/sessionstart.mjs +0 -129
- package/openclaw.plugin.json +0 -38
- package/scripts/heal-better-sqlite3.mjs +0 -430
- package/scripts/heal-installed-plugins.mjs +0 -598
- package/scripts/plugin-cache-integrity.mjs +0 -248
- package/scripts/postinstall.mjs +0 -384
- package/server.bundle.mjs +0 -1162
- package/skills/.ignore +0 -7
- package/skills/context-mode/SKILL.md +0 -300
- package/skills/context-mode/references/anti-patterns.md +0 -283
- package/skills/context-mode/references/patterns-javascript.md +0 -298
- package/skills/context-mode/references/patterns-python.md +0 -304
- package/skills/context-mode/references/patterns-shell.md +0 -277
- package/skills/ctx-index/SKILL.md +0 -46
- package/skills/ctx-insight/SKILL.md +0 -24
- package/skills/ctx-purge/SKILL.md +0 -49
- package/skills/ctx-search/SKILL.md +0 -35
- package/start.mjs +0 -616
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* adapters/opencode — OpenCode platform adapter.
|
|
3
|
-
*
|
|
4
|
-
* Implements HookAdapter for OpenCode's TypeScript plugin paradigm.
|
|
5
|
-
*
|
|
6
|
-
* OpenCode hook specifics:
|
|
7
|
-
* - I/O: TS plugin functions (not JSON stdin/stdout)
|
|
8
|
-
* - Hook names: tool.execute.before, tool.execute.after, experimental.session.compacting
|
|
9
|
-
* - Arg modification: output.args mutation
|
|
10
|
-
* - Blocking: throw Error in tool.execute.before
|
|
11
|
-
* - Output modification: output.output mutation (TUI bug for bash #13575)
|
|
12
|
-
* - SessionStart: broken (#14808, no hook #5409)
|
|
13
|
-
* - Session ID: input.sessionID (camelCase!)
|
|
14
|
-
* - Project dir: ctx.directory in plugin init (no env var)
|
|
15
|
-
* - Config: opencode.json plugin array, .opencode/plugins/*.ts
|
|
16
|
-
* - Session dir: ~/.config/opencode/context-mode/sessions/
|
|
17
|
-
*/
|
|
18
|
-
import { readFileSync, writeFileSync, mkdirSync, copyFileSync, accessSync, existsSync, constants, } from "node:fs";
|
|
19
|
-
import { resolve, join } from "node:path";
|
|
20
|
-
import { homedir } from "node:os";
|
|
21
|
-
import { BaseAdapter, resolveContextModeDataRoot } from "../base.js";
|
|
22
|
-
import { stripJsonComments } from "../../util/jsonc.js";
|
|
23
|
-
// ─────────────────────────────────────────────────────────
|
|
24
|
-
// Hook constants (re-exported from hooks.ts)
|
|
25
|
-
// ─────────────────────────────────────────────────────────
|
|
26
|
-
import { HOOK_TYPES as OPENCODE_HOOK_NAMES } from "./hooks.js";
|
|
27
|
-
export class OpenCodeAdapter extends BaseAdapter {
|
|
28
|
-
get name() {
|
|
29
|
-
return this.platform === "kilo" ? "KiloCode" : "OpenCode";
|
|
30
|
-
}
|
|
31
|
-
paradigm = "ts-plugin";
|
|
32
|
-
settingsPath;
|
|
33
|
-
capabilities = {
|
|
34
|
-
preToolUse: true,
|
|
35
|
-
postToolUse: true,
|
|
36
|
-
preCompact: true, // experimental
|
|
37
|
-
sessionStart: true,
|
|
38
|
-
canModifyArgs: true,
|
|
39
|
-
canModifyOutput: true, // with TUI bug caveat for bash (#13575)
|
|
40
|
-
canInjectSessionContext: true,
|
|
41
|
-
};
|
|
42
|
-
platform;
|
|
43
|
-
constructor(platform = "opencode") {
|
|
44
|
-
// sessionDirSegments unused — opencode overrides getSessionDir()
|
|
45
|
-
// with XDG_CONFIG_HOME / APPDATA logic
|
|
46
|
-
super([".config", platform]);
|
|
47
|
-
this.platform = platform;
|
|
48
|
-
}
|
|
49
|
-
// ── Input parsing ──────────────────────────────────────
|
|
50
|
-
parsePreToolUseInput(raw) {
|
|
51
|
-
const input = raw;
|
|
52
|
-
return {
|
|
53
|
-
toolName: input.tool ?? "",
|
|
54
|
-
toolInput: input.args ?? {},
|
|
55
|
-
sessionId: this.extractSessionId(input),
|
|
56
|
-
projectDir: process.env.OPENCODE_PROJECT_DIR || process.cwd(),
|
|
57
|
-
raw,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
parsePostToolUseInput(raw) {
|
|
61
|
-
const input = raw;
|
|
62
|
-
return {
|
|
63
|
-
toolName: input.tool ?? "",
|
|
64
|
-
toolInput: input.args ?? {},
|
|
65
|
-
toolOutput: input.output,
|
|
66
|
-
isError: undefined, // OpenCode doesn't provide isError
|
|
67
|
-
sessionId: this.extractSessionId(input),
|
|
68
|
-
projectDir: process.env.OPENCODE_PROJECT_DIR || process.cwd(),
|
|
69
|
-
raw,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
parsePreCompactInput(raw) {
|
|
73
|
-
const input = raw;
|
|
74
|
-
return {
|
|
75
|
-
sessionId: this.extractSessionId(input),
|
|
76
|
-
projectDir: process.env.OPENCODE_PROJECT_DIR || process.cwd(),
|
|
77
|
-
raw,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
parseSessionStartInput(raw) {
|
|
81
|
-
const input = raw;
|
|
82
|
-
const rawSource = input.source ?? "startup";
|
|
83
|
-
let source;
|
|
84
|
-
switch (rawSource) {
|
|
85
|
-
case "compact":
|
|
86
|
-
source = "compact";
|
|
87
|
-
break;
|
|
88
|
-
case "resume":
|
|
89
|
-
source = "resume";
|
|
90
|
-
break;
|
|
91
|
-
case "clear":
|
|
92
|
-
source = "clear";
|
|
93
|
-
break;
|
|
94
|
-
default:
|
|
95
|
-
source = "startup";
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
sessionId: this.extractSessionId(input),
|
|
99
|
-
source,
|
|
100
|
-
projectDir: process.env.OPENCODE_PROJECT_DIR || process.cwd(),
|
|
101
|
-
raw,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
// ── Response formatting ────────────────────────────────
|
|
105
|
-
formatPreToolUseResponse(response) {
|
|
106
|
-
if (response.decision === "deny") {
|
|
107
|
-
// OpenCode TS plugin paradigm: throw Error to block
|
|
108
|
-
throw new Error(response.reason ?? "Blocked by context-mode hook");
|
|
109
|
-
}
|
|
110
|
-
if (response.decision === "modify" && response.updatedInput) {
|
|
111
|
-
// OpenCode: output.args mutation
|
|
112
|
-
return { args: response.updatedInput };
|
|
113
|
-
}
|
|
114
|
-
if (response.decision === "ask") {
|
|
115
|
-
// OpenCode: no native "ask" mechanism — throw to be safe
|
|
116
|
-
throw new Error(response.reason ?? "Action requires user confirmation (security policy)");
|
|
117
|
-
}
|
|
118
|
-
// "context" — OpenCode's tool.execute.before cannot inject additionalContext
|
|
119
|
-
// in PreToolUse (platform limitation). The guidance is delivered via
|
|
120
|
-
// CLAUDE.md/AGENTS.md routing instructions instead. Passthrough.
|
|
121
|
-
// "allow" — passthrough
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
formatPostToolUseResponse(response) {
|
|
125
|
-
const result = {};
|
|
126
|
-
if (response.updatedOutput) {
|
|
127
|
-
// OpenCode: output.output mutation (TUI bug for bash #13575)
|
|
128
|
-
result.output = response.updatedOutput;
|
|
129
|
-
}
|
|
130
|
-
if (response.additionalContext) {
|
|
131
|
-
result.additionalContext = response.additionalContext;
|
|
132
|
-
}
|
|
133
|
-
return Object.keys(result).length > 0 ? result : undefined;
|
|
134
|
-
}
|
|
135
|
-
formatPreCompactResponse(response) {
|
|
136
|
-
// experimental.session.compacting — return context string
|
|
137
|
-
return response.context ?? "";
|
|
138
|
-
}
|
|
139
|
-
formatSessionStartResponse(response) {
|
|
140
|
-
return response.context ?? "";
|
|
141
|
-
}
|
|
142
|
-
// ── Configuration ──────────────────────────────────────
|
|
143
|
-
getSettingsPath() {
|
|
144
|
-
if (this.settingsPath)
|
|
145
|
-
return this.settingsPath;
|
|
146
|
-
// Edge case (#849): writeSettings() called without a prior readSettings()
|
|
147
|
-
// (which is what populates this.settingsPath). Never create a `.json` that
|
|
148
|
-
// would shadow an existing `.jsonc` — OpenCode merges the project-root
|
|
149
|
-
// `.jsonc` LAST, so it is the authoritative config
|
|
150
|
-
// (refs/platforms/opencode/packages/opencode/src/config/config.ts:406-408
|
|
151
|
-
// + paths.ts:15-22). Prefer the existing `.jsonc` as the write target.
|
|
152
|
-
const jsoncPath = resolve(`${this.platform}.jsonc`);
|
|
153
|
-
if (existsSync(jsoncPath))
|
|
154
|
-
return jsoncPath;
|
|
155
|
-
return resolve(`${this.platform}.json`);
|
|
156
|
-
}
|
|
157
|
-
paths() {
|
|
158
|
-
// `.jsonc` is listed BEFORE `.json` so it is selected as the write target
|
|
159
|
-
// when both exist (#849). OpenCode loads the project-root `.json` then
|
|
160
|
-
// `.jsonc` and merges `.jsonc` last — scalars override-last, arrays concat
|
|
161
|
-
// (refs/platforms/opencode/packages/opencode/src/config/config.ts:406-408,
|
|
162
|
-
// 258-260 + paths.ts:15-22). The `.jsonc` is therefore the authoritative
|
|
163
|
-
// file holding the user's real config; a `.json` is often an empty/auto-
|
|
164
|
-
// generated placeholder. Writing into the placeholder would create a
|
|
165
|
-
// file that shadows the user's real `.jsonc`. Preferring `.jsonc` for the
|
|
166
|
-
// write target avoids that silent config destruction. Read order is
|
|
167
|
-
// irrelevant for the plugin early-return (hasContextModePlugin) path.
|
|
168
|
-
if (this.platform === "kilo") {
|
|
169
|
-
// Kilo runtime accepts `.kilo/`, `.kilocode/`, and `.opencode/` as
|
|
170
|
-
// project config dirs (refs/platforms/kilo/packages/opencode/src/
|
|
171
|
-
// kilocode/config/config.ts:50,408). Mirror that here so context-mode
|
|
172
|
-
// discovers config regardless of which suffix the user adopted.
|
|
173
|
-
return [
|
|
174
|
-
resolve("kilo.jsonc"),
|
|
175
|
-
resolve("kilo.json"),
|
|
176
|
-
resolve(".kilo", "kilo.jsonc"),
|
|
177
|
-
resolve(".kilo", "kilo.json"),
|
|
178
|
-
resolve(".kilocode", "kilo.jsonc"),
|
|
179
|
-
resolve(".kilocode", "kilo.json"),
|
|
180
|
-
join(homedir(), ".config", "kilo", "kilo.jsonc"),
|
|
181
|
-
join(homedir(), ".config", "kilo", "kilo.json"),
|
|
182
|
-
];
|
|
183
|
-
}
|
|
184
|
-
return [
|
|
185
|
-
resolve("opencode.jsonc"),
|
|
186
|
-
resolve("opencode.json"),
|
|
187
|
-
resolve(".opencode", "opencode.jsonc"),
|
|
188
|
-
resolve(".opencode", "opencode.json"),
|
|
189
|
-
join(homedir(), ".config", "opencode", "opencode.jsonc"),
|
|
190
|
-
join(homedir(), ".config", "opencode", "opencode.json"),
|
|
191
|
-
];
|
|
192
|
-
}
|
|
193
|
-
getSessionDir() {
|
|
194
|
-
// Issue #649: honor CONTEXT_MODE_DATA_DIR universal storage override
|
|
195
|
-
// ahead of OpenCode/Kilo's XDG-rooted default. opencode.json + plugin
|
|
196
|
-
// discovery stay under getConfigDir() so OpenCode itself sees its own
|
|
197
|
-
// config in the expected location.
|
|
198
|
-
const override = resolveContextModeDataRoot();
|
|
199
|
-
const dir = override
|
|
200
|
-
? join(override, "context-mode", "sessions")
|
|
201
|
-
: join(this.getConfigDir(), "context-mode", "sessions");
|
|
202
|
-
mkdirSync(dir, { recursive: true });
|
|
203
|
-
return dir;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* OpenCode/KiloCode honor XDG_CONFIG_HOME on POSIX and APPDATA on Windows.
|
|
207
|
-
* Falls back to ~/.config/<platform> (or %APPDATA%\<platform>).
|
|
208
|
-
* Always absolute. `_projectDir` is accepted for interface symmetry but
|
|
209
|
-
* unused — config is home/XDG-rooted, never project-scoped.
|
|
210
|
-
*/
|
|
211
|
-
getConfigDir(_projectDir) {
|
|
212
|
-
let root;
|
|
213
|
-
if (process.platform === "win32") {
|
|
214
|
-
root = process.env.APPDATA || join(homedir(), "AppData", "Roaming");
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
root = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
|
|
218
|
-
}
|
|
219
|
-
return join(root, this.platform);
|
|
220
|
-
}
|
|
221
|
-
getInstructionFiles() {
|
|
222
|
-
return ["AGENTS.md"];
|
|
223
|
-
}
|
|
224
|
-
generateHookConfig(_pluginRoot) {
|
|
225
|
-
// OpenCode uses TS plugin paradigm — hooks are registered via plugin array
|
|
226
|
-
// in opencode.json, not via command-based hook entries.
|
|
227
|
-
// Return the hook name mapping for documentation purposes.
|
|
228
|
-
return {
|
|
229
|
-
[OPENCODE_HOOK_NAMES.BEFORE]: [
|
|
230
|
-
{
|
|
231
|
-
matcher: "",
|
|
232
|
-
hooks: [
|
|
233
|
-
{
|
|
234
|
-
type: "plugin",
|
|
235
|
-
command: "context-mode",
|
|
236
|
-
},
|
|
237
|
-
],
|
|
238
|
-
},
|
|
239
|
-
],
|
|
240
|
-
[OPENCODE_HOOK_NAMES.AFTER]: [
|
|
241
|
-
{
|
|
242
|
-
matcher: "",
|
|
243
|
-
hooks: [
|
|
244
|
-
{
|
|
245
|
-
type: "plugin",
|
|
246
|
-
command: "context-mode",
|
|
247
|
-
},
|
|
248
|
-
],
|
|
249
|
-
},
|
|
250
|
-
],
|
|
251
|
-
[OPENCODE_HOOK_NAMES.COMPACTING]: [
|
|
252
|
-
{
|
|
253
|
-
matcher: "",
|
|
254
|
-
hooks: [
|
|
255
|
-
{
|
|
256
|
-
type: "plugin",
|
|
257
|
-
command: "context-mode",
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
},
|
|
261
|
-
],
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
readSettings() {
|
|
265
|
-
this.settingsPath = undefined;
|
|
266
|
-
const configPaths = this.paths();
|
|
267
|
-
const globalPaths = new Set(configPaths.filter(p => p.includes(homedir())));
|
|
268
|
-
let firstValidSettings = null;
|
|
269
|
-
let firstValidPath;
|
|
270
|
-
for (const configPath of configPaths) {
|
|
271
|
-
try {
|
|
272
|
-
const raw = readFileSync(configPath, "utf-8");
|
|
273
|
-
const text = configPath.endsWith(".jsonc") ? stripJsonComments(raw) : raw;
|
|
274
|
-
const settings = JSON.parse(text);
|
|
275
|
-
if (!firstValidSettings) {
|
|
276
|
-
firstValidSettings = settings;
|
|
277
|
-
firstValidPath = configPath;
|
|
278
|
-
}
|
|
279
|
-
const isGlobalConfig = globalPaths.has(configPath);
|
|
280
|
-
if (this.hasContextModePlugin(settings) || isGlobalConfig) {
|
|
281
|
-
this.settingsPath = configPath;
|
|
282
|
-
return settings;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
catch {
|
|
286
|
-
continue;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
if (firstValidSettings) {
|
|
290
|
-
this.settingsPath = firstValidPath;
|
|
291
|
-
return firstValidSettings;
|
|
292
|
-
}
|
|
293
|
-
return null;
|
|
294
|
-
}
|
|
295
|
-
writeSettings(settings) {
|
|
296
|
-
// Write to opencode.json(c)/kilo.json(c) in current directory
|
|
297
|
-
writeFileSync(this.getSettingsPath(), JSON.stringify(settings, null, 2) + "\n", "utf-8");
|
|
298
|
-
}
|
|
299
|
-
// ── Diagnostics (doctor) ─────────────────────────────────
|
|
300
|
-
validateHooks(_pluginRoot) {
|
|
301
|
-
const results = [];
|
|
302
|
-
const settings = this.readSettings();
|
|
303
|
-
if (!settings) {
|
|
304
|
-
results.push({
|
|
305
|
-
check: "Plugin configuration",
|
|
306
|
-
status: "fail",
|
|
307
|
-
message: `Could not read ${this.platform}.json or ${this.platform}.jsonc`,
|
|
308
|
-
fix: "context-mode upgrade",
|
|
309
|
-
});
|
|
310
|
-
return results;
|
|
311
|
-
}
|
|
312
|
-
// Check for "context-mode" in plugin array
|
|
313
|
-
const hasPlugin = this.hasContextModePlugin(settings);
|
|
314
|
-
if (Array.isArray(settings.plugin)) {
|
|
315
|
-
results.push({
|
|
316
|
-
check: "Plugin registration",
|
|
317
|
-
status: hasPlugin ? "pass" : "fail",
|
|
318
|
-
message: hasPlugin
|
|
319
|
-
? "context-mode found in plugin array"
|
|
320
|
-
: "context-mode not found in plugin array",
|
|
321
|
-
fix: hasPlugin
|
|
322
|
-
? undefined
|
|
323
|
-
: "context-mode upgrade",
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
results.push({
|
|
328
|
-
check: "Plugin registration",
|
|
329
|
-
status: "fail",
|
|
330
|
-
message: `No plugin array found in ${this.platform}.json or ${this.platform}.jsonc`,
|
|
331
|
-
fix: "context-mode upgrade",
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
if (this.hasLegacyContextModeMcp(settings)) {
|
|
335
|
-
results.push({
|
|
336
|
-
check: "Legacy MCP registration",
|
|
337
|
-
status: "warn",
|
|
338
|
-
message: "mcp.context-mode is redundant: ctx_* tools are now provided by the plugin",
|
|
339
|
-
fix: "context-mode upgrade (removes only mcp.context-mode; preserves other MCP servers)",
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
// Note: SessionStart handled via experimental.chat.system.transform surrogate
|
|
343
|
-
results.push({
|
|
344
|
-
check: "SessionStart hook",
|
|
345
|
-
status: "pass",
|
|
346
|
-
message: `SessionStart via experimental.chat.system.transform surrogate (native hook pending #14808, #5409)`,
|
|
347
|
-
});
|
|
348
|
-
return results;
|
|
349
|
-
}
|
|
350
|
-
checkPluginRegistration() {
|
|
351
|
-
const settings = this.readSettings();
|
|
352
|
-
if (!settings) {
|
|
353
|
-
return {
|
|
354
|
-
check: "Plugin registration",
|
|
355
|
-
status: "warn",
|
|
356
|
-
message: `Could not read ${this.platform}.json or ${this.platform}.jsonc`,
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
if (this.hasContextModePlugin(settings)) {
|
|
360
|
-
return {
|
|
361
|
-
check: "Plugin registration",
|
|
362
|
-
status: "pass",
|
|
363
|
-
message: "context-mode found in plugin array",
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
return {
|
|
367
|
-
check: "Plugin registration",
|
|
368
|
-
status: "fail",
|
|
369
|
-
message: `context-mode not found in ${this.platform}.json plugin array`,
|
|
370
|
-
fix: "context-mode upgrade",
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
getInstalledVersion() {
|
|
374
|
-
// Check ~/.cache/opencode/node_modules/ for context-mode
|
|
375
|
-
try {
|
|
376
|
-
const pkgPath = resolve(homedir(), ".cache", this.platform, "node_modules", "context-mode", "package.json");
|
|
377
|
-
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
378
|
-
if (typeof pkg.version === "string")
|
|
379
|
-
return pkg.version;
|
|
380
|
-
}
|
|
381
|
-
catch {
|
|
382
|
-
/* not found */
|
|
383
|
-
}
|
|
384
|
-
return "not installed";
|
|
385
|
-
}
|
|
386
|
-
// ── Upgrade ────────────────────────────────────────────
|
|
387
|
-
configureAllHooks(_pluginRoot) {
|
|
388
|
-
const settings = this.readSettings() ?? {};
|
|
389
|
-
const changes = [];
|
|
390
|
-
// Add "context-mode" to the plugin array
|
|
391
|
-
const plugins = (settings.plugin ?? []);
|
|
392
|
-
if (!plugins.some((p) => p.includes("context-mode"))) {
|
|
393
|
-
plugins.push("context-mode");
|
|
394
|
-
changes.push("Added context-mode to plugin array");
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
changes.push("context-mode already in plugin array");
|
|
398
|
-
}
|
|
399
|
-
settings.plugin = plugins;
|
|
400
|
-
const mcp = settings.mcp;
|
|
401
|
-
if (mcp && typeof mcp === "object" && !Array.isArray(mcp)) {
|
|
402
|
-
const servers = mcp;
|
|
403
|
-
if (Object.prototype.hasOwnProperty.call(servers, "context-mode")) {
|
|
404
|
-
delete servers["context-mode"];
|
|
405
|
-
changes.push("Removed legacy context-mode MCP block (plugin-native tools)");
|
|
406
|
-
}
|
|
407
|
-
if (Object.keys(servers).length === 0)
|
|
408
|
-
delete settings.mcp;
|
|
409
|
-
}
|
|
410
|
-
this.writeSettings(settings);
|
|
411
|
-
return changes;
|
|
412
|
-
}
|
|
413
|
-
backupSettings() {
|
|
414
|
-
const check = this.checkPluginRegistration();
|
|
415
|
-
if (!this.settingsPath)
|
|
416
|
-
return null;
|
|
417
|
-
if (check.status === "pass") {
|
|
418
|
-
return this.settingsPath;
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
try {
|
|
422
|
-
accessSync(this.settingsPath, constants.R_OK);
|
|
423
|
-
const backupPath = this.settingsPath + ".bak";
|
|
424
|
-
copyFileSync(this.settingsPath, backupPath);
|
|
425
|
-
return backupPath;
|
|
426
|
-
}
|
|
427
|
-
catch {
|
|
428
|
-
return null;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
setHookPermissions(_pluginRoot) {
|
|
433
|
-
// OpenCode uses TS plugin paradigm — no shell scripts to chmod
|
|
434
|
-
return [];
|
|
435
|
-
}
|
|
436
|
-
updatePluginRegistry(_pluginRoot, _version) {
|
|
437
|
-
// OpenCode manages plugins through npm/opencode.json — no separate registry
|
|
438
|
-
}
|
|
439
|
-
// ── Internal helpers ───────────────────────────────────
|
|
440
|
-
/**
|
|
441
|
-
* Check whether a settings object has the context-mode plugin registered.
|
|
442
|
-
*/
|
|
443
|
-
hasContextModePlugin(settings) {
|
|
444
|
-
const plugins = settings.plugin;
|
|
445
|
-
return Array.isArray(plugins) && plugins.some((p) => typeof p === "string" && p.includes("context-mode"));
|
|
446
|
-
}
|
|
447
|
-
hasLegacyContextModeMcp(settings) {
|
|
448
|
-
const mcp = settings.mcp;
|
|
449
|
-
return !!(mcp &&
|
|
450
|
-
typeof mcp === "object" &&
|
|
451
|
-
!Array.isArray(mcp) &&
|
|
452
|
-
Object.prototype.hasOwnProperty.call(mcp, "context-mode"));
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Extract session ID from OpenCode hook input.
|
|
456
|
-
* OpenCode uses camelCase sessionID.
|
|
457
|
-
*/
|
|
458
|
-
extractSessionId(input) {
|
|
459
|
-
if (input.sessionID)
|
|
460
|
-
return input.sessionID;
|
|
461
|
-
return `pid-${process.ppid}`;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenCode / KiloCode TypeScript plugin entry point for context-mode.
|
|
3
|
-
*
|
|
4
|
-
* Provides five hooks (v1.0.107 — Mickey OC-1..OC-4 follow-up):
|
|
5
|
-
* - tool.execute.before — Routing enforcement (deny/modify/passthrough)
|
|
6
|
-
* - tool.execute.after — Session event capture + first-fire AGENTS.md scan (OC-4)
|
|
7
|
-
* - experimental.session.compacting — Compaction snapshot + budget-capped auto-injection (OC-3)
|
|
8
|
-
* - experimental.chat.system.transform — ROUTING_BLOCK + resume snapshot injection (OC-1)
|
|
9
|
-
* - chat.message — User-prompt capture w/ CCv2 inline filter (OC-2) + AGENTS.md scan (OC-4)
|
|
10
|
-
*
|
|
11
|
-
* KiloCode loads this via: import("context-mode") → expects default export
|
|
12
|
-
* with shape { server: (input) => Promise<Hooks> } (PluginModule).
|
|
13
|
-
*
|
|
14
|
-
* OpenCode loads this via: import("context-mode/plugin") → also supports
|
|
15
|
-
* the named export ContextModePlugin for backward compat.
|
|
16
|
-
*
|
|
17
|
-
* Constraints:
|
|
18
|
-
* - No SessionStart hook (OpenCode doesn't support it — #14808, #5409)
|
|
19
|
-
* - context injection now via chat.system.transform surrogate (OC-1)
|
|
20
|
-
* - No routing file auto-write (avoid dirtying project trees)
|
|
21
|
-
* - Session cleanup happens at plugin init (no SessionStart)
|
|
22
|
-
*/
|
|
23
|
-
/** KiloCode/OpenCode plugin input — both platforms pass at least `directory`. */
|
|
24
|
-
type PluginClientAppLogBodyExtra = {
|
|
25
|
-
sessionId?: string;
|
|
26
|
-
source?: string;
|
|
27
|
-
};
|
|
28
|
-
type PluginClientAppLogBody = {
|
|
29
|
-
service: string;
|
|
30
|
-
level: "info" | "warn" | "error" | "debug";
|
|
31
|
-
message: string;
|
|
32
|
-
extra?: PluginClientAppLogBodyExtra;
|
|
33
|
-
};
|
|
34
|
-
type PluginClientAppLogOptions = {
|
|
35
|
-
body: PluginClientAppLogBody;
|
|
36
|
-
};
|
|
37
|
-
type PluginClientApp = {
|
|
38
|
-
log: (options: PluginClientAppLogOptions) => Promise<void>;
|
|
39
|
-
};
|
|
40
|
-
type PluginClient = {
|
|
41
|
-
app: PluginClientApp;
|
|
42
|
-
};
|
|
43
|
-
type PluginContext = {
|
|
44
|
-
client: PluginClient;
|
|
45
|
-
directory: string;
|
|
46
|
-
};
|
|
47
|
-
type NativeToolContext = {
|
|
48
|
-
sessionID: string;
|
|
49
|
-
messageID: string;
|
|
50
|
-
agent: string;
|
|
51
|
-
directory: string;
|
|
52
|
-
worktree?: string;
|
|
53
|
-
abort?: AbortSignal;
|
|
54
|
-
metadata?: (input: {
|
|
55
|
-
title?: string;
|
|
56
|
-
metadata?: Record<string, unknown>;
|
|
57
|
-
}) => void;
|
|
58
|
-
};
|
|
59
|
-
type NativeToolDefinition = {
|
|
60
|
-
description: string;
|
|
61
|
-
args: Record<string, unknown>;
|
|
62
|
-
execute: (args: Record<string, unknown>, ctx: NativeToolContext) => Promise<string | {
|
|
63
|
-
title?: string;
|
|
64
|
-
output: string;
|
|
65
|
-
metadata?: Record<string, unknown>;
|
|
66
|
-
}>;
|
|
67
|
-
};
|
|
68
|
-
/** OpenCode tool.execute.before — first parameter */
|
|
69
|
-
interface BeforeHookInput {
|
|
70
|
-
tool: string;
|
|
71
|
-
sessionID: string;
|
|
72
|
-
callID: string;
|
|
73
|
-
}
|
|
74
|
-
/** OpenCode tool.execute.before — second parameter */
|
|
75
|
-
interface BeforeHookOutput {
|
|
76
|
-
args: any;
|
|
77
|
-
}
|
|
78
|
-
/** OpenCode tool.execute.after — first parameter */
|
|
79
|
-
interface AfterHookInput {
|
|
80
|
-
tool: string;
|
|
81
|
-
sessionID: string;
|
|
82
|
-
callID: string;
|
|
83
|
-
args: any;
|
|
84
|
-
}
|
|
85
|
-
/** OpenCode tool.execute.after — second parameter */
|
|
86
|
-
interface AfterHookOutput {
|
|
87
|
-
title: string;
|
|
88
|
-
output: string;
|
|
89
|
-
metadata: any;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* OpenCode generic bus `event` hook — single parameter.
|
|
93
|
-
* The plugin SDK delivers every bus Event here (refs/platforms/opencode/
|
|
94
|
-
* packages/plugin/src/index.ts:224). We narrow to `message.updated`, whose
|
|
95
|
-
* `properties.info` is the full assistant Message carrying tokens/cost/modelID.
|
|
96
|
-
*/
|
|
97
|
-
interface EventHookInput {
|
|
98
|
-
event?: {
|
|
99
|
-
type?: string;
|
|
100
|
-
properties?: {
|
|
101
|
-
info?: {
|
|
102
|
-
sessionID?: string;
|
|
103
|
-
} & Record<string, unknown>;
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/** OpenCode experimental.session.compacting — first parameter */
|
|
108
|
-
interface CompactingHookInput {
|
|
109
|
-
sessionID: string;
|
|
110
|
-
}
|
|
111
|
-
/** OpenCode experimental.session.compacting — second parameter */
|
|
112
|
-
interface CompactingHookOutput {
|
|
113
|
-
context: string[];
|
|
114
|
-
prompt?: string;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* OpenCode experimental.chat.system.transform — first parameter.
|
|
118
|
-
* Verified against sst/opencode/dev/packages/plugin/src/index.ts:
|
|
119
|
-
* input: { sessionID?: string; model: Model }
|
|
120
|
-
* `sessionID` is optional in the SDK type but is in practice always set
|
|
121
|
-
* (the transform runs *for* a session). We treat it as required and
|
|
122
|
-
* skip injection when absent rather than fall back to a fabricated ID.
|
|
123
|
-
*
|
|
124
|
-
* NOTE: We deliberately do NOT use `experimental.chat.messages.transform`.
|
|
125
|
-
* Its SDK input shape is `{}` (no sessionID) and its output is
|
|
126
|
-
* `{ messages: { info: Message; parts: Part[] }[] }` — the prior code
|
|
127
|
-
* (`output.messages.unshift({ role, content })`) wrote a value of the
|
|
128
|
-
* wrong shape and was silently dropped (Mickey / PR #376 root cause).
|
|
129
|
-
*/
|
|
130
|
-
interface SystemTransformHookInput {
|
|
131
|
-
sessionID?: string;
|
|
132
|
-
model: unknown;
|
|
133
|
-
}
|
|
134
|
-
/** OpenCode experimental.chat.system.transform — second parameter */
|
|
135
|
-
interface SystemTransformHookOutput {
|
|
136
|
-
system: string[];
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* OpenCode chat.message hook — verified against
|
|
140
|
-
* refs/platforms/opencode/packages/plugin/src/index.ts:233.
|
|
141
|
-
* input: { sessionID; agent?; model?; messageID?; variant? }
|
|
142
|
-
* output: { message: UserMessage; parts: Part[] }
|
|
143
|
-
* We read text from `parts[*].text` (the orchestrator reference at
|
|
144
|
-
* refs/plugin-examples/opencode/opencode-orchestrator/src/plugin-handlers/
|
|
145
|
-
* chat-message-handler.ts:41-65 uses the same pattern).
|
|
146
|
-
*/
|
|
147
|
-
interface ChatMessageHookInput {
|
|
148
|
-
sessionID: string;
|
|
149
|
-
agent?: string;
|
|
150
|
-
messageID?: string;
|
|
151
|
-
}
|
|
152
|
-
interface ChatMessagePart {
|
|
153
|
-
type: string;
|
|
154
|
-
text?: string;
|
|
155
|
-
}
|
|
156
|
-
interface ChatMessageHookOutput {
|
|
157
|
-
message: unknown;
|
|
158
|
-
parts: ChatMessagePart[];
|
|
159
|
-
}
|
|
160
|
-
declare const ROUTING_MARKERS: string[];
|
|
161
|
-
declare function systemHasRoutingInstructions(system: string[]): boolean;
|
|
162
|
-
/**
|
|
163
|
-
* Plugin factory. Called once when KiloCode/OpenCode loads the plugin.
|
|
164
|
-
* Returns an object mapping hook event names to async handler functions.
|
|
165
|
-
*
|
|
166
|
-
* KiloCode expects: export default { id: string, server: (input) => Promise<Hooks> }
|
|
167
|
-
* OpenCode expects: export const ContextModePlugin = (ctx) => Promise<Hooks>
|
|
168
|
-
*/
|
|
169
|
-
declare function createContextModePlugin(ctx: PluginContext): Promise<{
|
|
170
|
-
tool: Record<string, NativeToolDefinition>;
|
|
171
|
-
"tool.execute.before": (input: BeforeHookInput, output: BeforeHookOutput) => Promise<void>;
|
|
172
|
-
"tool.execute.after": (input: AfterHookInput, output: AfterHookOutput) => Promise<void>;
|
|
173
|
-
event: (input: EventHookInput) => Promise<void>;
|
|
174
|
-
"chat.message": (input: ChatMessageHookInput, output: ChatMessageHookOutput) => Promise<void>;
|
|
175
|
-
"experimental.session.compacting": (input: CompactingHookInput, output: CompactingHookOutput) => Promise<string>;
|
|
176
|
-
"experimental.chat.system.transform": (input: SystemTransformHookInput, output: SystemTransformHookOutput) => Promise<void>;
|
|
177
|
-
}>;
|
|
178
|
-
declare const _default: {
|
|
179
|
-
id: string;
|
|
180
|
-
server: typeof createContextModePlugin;
|
|
181
|
-
};
|
|
182
|
-
export default _default;
|
|
183
|
-
export { createContextModePlugin as ContextModePlugin };
|
|
184
|
-
export { systemHasRoutingInstructions, ROUTING_MARKERS };
|