@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
package/hooks/hooks.json
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Context-mode hooks — PreToolUse routing, PostToolUse session capture, UserPromptSubmit decisions, PreCompact snapshot, SessionStart context injection, Stop turn-end capture",
|
|
3
|
+
"hooks": {
|
|
4
|
+
"PostToolUse": [
|
|
5
|
+
{
|
|
6
|
+
"matcher": "Bash|Read|Write|Edit|NotebookEdit|Glob|Grep|TodoWrite|TaskCreate|TaskUpdate|EnterPlanMode|ExitPlanMode|Skill|Agent|AskUserQuestion|EnterWorktree|mcp__",
|
|
7
|
+
"hooks": [
|
|
8
|
+
{
|
|
9
|
+
"type": "command",
|
|
10
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/posttooluse.mjs\""
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"PreCompact": [
|
|
16
|
+
{
|
|
17
|
+
"matcher": "",
|
|
18
|
+
"hooks": [
|
|
19
|
+
{
|
|
20
|
+
"type": "command",
|
|
21
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/precompact.mjs\""
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"PreToolUse": [
|
|
27
|
+
{
|
|
28
|
+
"matcher": "Bash",
|
|
29
|
+
"hooks": [
|
|
30
|
+
{
|
|
31
|
+
"type": "command",
|
|
32
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.mjs\""
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"matcher": "WebFetch",
|
|
38
|
+
"hooks": [
|
|
39
|
+
{
|
|
40
|
+
"type": "command",
|
|
41
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.mjs\""
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"matcher": "Read",
|
|
47
|
+
"hooks": [
|
|
48
|
+
{
|
|
49
|
+
"type": "command",
|
|
50
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.mjs\""
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"matcher": "Grep",
|
|
56
|
+
"hooks": [
|
|
57
|
+
{
|
|
58
|
+
"type": "command",
|
|
59
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.mjs\""
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"matcher": "Agent",
|
|
65
|
+
"hooks": [
|
|
66
|
+
{
|
|
67
|
+
"type": "command",
|
|
68
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.mjs\""
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"matcher": "mcp__plugin_context-mode_context-mode__ctx_execute",
|
|
74
|
+
"hooks": [
|
|
75
|
+
{
|
|
76
|
+
"type": "command",
|
|
77
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.mjs\""
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"matcher": "mcp__plugin_context-mode_context-mode__ctx_execute_file",
|
|
83
|
+
"hooks": [
|
|
84
|
+
{
|
|
85
|
+
"type": "command",
|
|
86
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.mjs\""
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"matcher": "mcp__plugin_context-mode_context-mode__ctx_batch_execute",
|
|
92
|
+
"hooks": [
|
|
93
|
+
{
|
|
94
|
+
"type": "command",
|
|
95
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.mjs\""
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"matcher": "mcp__",
|
|
101
|
+
"hooks": [
|
|
102
|
+
{
|
|
103
|
+
"type": "command",
|
|
104
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.mjs\""
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"UserPromptSubmit": [
|
|
110
|
+
{
|
|
111
|
+
"matcher": "",
|
|
112
|
+
"hooks": [
|
|
113
|
+
{
|
|
114
|
+
"type": "command",
|
|
115
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/userpromptsubmit.mjs\""
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
"SessionStart": [
|
|
121
|
+
{
|
|
122
|
+
"matcher": "",
|
|
123
|
+
"hooks": [
|
|
124
|
+
{
|
|
125
|
+
"type": "command",
|
|
126
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/sessionstart.mjs\""
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
"Stop": [
|
|
132
|
+
{
|
|
133
|
+
"matcher": "",
|
|
134
|
+
"hooks": [
|
|
135
|
+
{
|
|
136
|
+
"type": "command",
|
|
137
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/stop.mjs\""
|
|
138
|
+
}
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "../suppress-stderr.mjs";
|
|
3
|
+
import "../ensure-deps.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* JetBrains Copilot PostToolUse hook — session event capture.
|
|
6
|
+
*
|
|
7
|
+
* Captures session events from tool calls (13 categories) and stores
|
|
8
|
+
* them in the per-project SessionDB for later resume snapshot building.
|
|
9
|
+
*
|
|
10
|
+
* Must be fast (<20ms). No network, no LLM, just SQLite writes.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { createSessionLoaders, attributeAndInsertEvents } from "../session-loaders.mjs";
|
|
14
|
+
import { readStdin, parseStdin, getSessionId, getSessionDBPath, getInputProjectDir, JETBRAINS_OPTS } from "../session-helpers.mjs";
|
|
15
|
+
import { appendFileSync } from "node:fs";
|
|
16
|
+
import { join, dirname } from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
import { homedir } from "node:os";
|
|
19
|
+
|
|
20
|
+
const HOOK_DIR = dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const { loadSessionDB, loadExtract, loadProjectAttribution } = createSessionLoaders(HOOK_DIR);
|
|
22
|
+
const OPTS = JETBRAINS_OPTS;
|
|
23
|
+
const DEBUG_LOG = join(homedir(), ".config", "JetBrains", "context-mode", "posttooluse-debug.log");
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const raw = await readStdin();
|
|
27
|
+
const input = parseStdin(raw);
|
|
28
|
+
const projectDir = getInputProjectDir(input, OPTS);
|
|
29
|
+
|
|
30
|
+
appendFileSync(DEBUG_LOG, `[${new Date().toISOString()}] CALL: ${input.tool_name}\n`);
|
|
31
|
+
|
|
32
|
+
const { extractEvents } = await loadExtract();
|
|
33
|
+
const { resolveProjectAttributions } = await loadProjectAttribution();
|
|
34
|
+
const { SessionDB } = await loadSessionDB();
|
|
35
|
+
|
|
36
|
+
const dbPath = getSessionDBPath(OPTS, projectDir);
|
|
37
|
+
const db = new SessionDB({ dbPath });
|
|
38
|
+
const sessionId = getSessionId(input, OPTS);
|
|
39
|
+
|
|
40
|
+
db.ensureSession(sessionId, projectDir);
|
|
41
|
+
|
|
42
|
+
const events = extractEvents({
|
|
43
|
+
tool_name: input.tool_name,
|
|
44
|
+
tool_input: input.tool_input ?? {},
|
|
45
|
+
tool_response: typeof input.tool_response === "string"
|
|
46
|
+
? input.tool_response
|
|
47
|
+
: JSON.stringify(input.tool_response ?? ""),
|
|
48
|
+
tool_output: input.tool_output,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
attributeAndInsertEvents(db, sessionId, events, input, projectDir, "PostToolUse", resolveProjectAttributions);
|
|
52
|
+
|
|
53
|
+
appendFileSync(DEBUG_LOG, `[${new Date().toISOString()}] OK: ${input.tool_name} → ${events.length} events\n`);
|
|
54
|
+
db.close();
|
|
55
|
+
} catch (err) {
|
|
56
|
+
try {
|
|
57
|
+
appendFileSync(DEBUG_LOG, `[${new Date().toISOString()}] ERR: ${err?.message || err}\n`);
|
|
58
|
+
} catch { /* silent */ }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// PostToolUse — no stdout output
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "../suppress-stderr.mjs";
|
|
3
|
+
import "../ensure-deps.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* JetBrains Copilot PreCompact hook — snapshot generation.
|
|
6
|
+
*
|
|
7
|
+
* Triggered when JetBrains Copilot is about to compact the conversation.
|
|
8
|
+
* Reads all captured session events, builds a priority-sorted resume
|
|
9
|
+
* snapshot (<2KB XML), and stores it for injection after compact.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { createSessionLoaders } from "../session-loaders.mjs";
|
|
13
|
+
import { readStdin, parseStdin, getSessionId, getSessionDBPath, getInputProjectDir, JETBRAINS_OPTS } from "../session-helpers.mjs";
|
|
14
|
+
import { appendFileSync } from "node:fs";
|
|
15
|
+
import { join, dirname } from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import { homedir } from "node:os";
|
|
18
|
+
|
|
19
|
+
const HOOK_DIR = dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
const { loadSessionDB, loadSnapshot } = createSessionLoaders(HOOK_DIR);
|
|
21
|
+
const OPTS = JETBRAINS_OPTS;
|
|
22
|
+
const DEBUG_LOG = join(homedir(), ".config", "JetBrains", "context-mode", "precompact-debug.log");
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const raw = await readStdin();
|
|
26
|
+
const input = parseStdin(raw);
|
|
27
|
+
const projectDir = getInputProjectDir(input, OPTS);
|
|
28
|
+
|
|
29
|
+
const { buildResumeSnapshot } = await loadSnapshot();
|
|
30
|
+
const { SessionDB } = await loadSessionDB();
|
|
31
|
+
|
|
32
|
+
const dbPath = getSessionDBPath(OPTS, projectDir);
|
|
33
|
+
const db = new SessionDB({ dbPath });
|
|
34
|
+
const sessionId = getSessionId(input, OPTS);
|
|
35
|
+
|
|
36
|
+
const events = db.getEvents(sessionId);
|
|
37
|
+
|
|
38
|
+
if (events.length > 0) {
|
|
39
|
+
const stats = db.getSessionStats(sessionId);
|
|
40
|
+
const snapshot = buildResumeSnapshot(events, {
|
|
41
|
+
compactCount: (stats?.compact_count ?? 0) + 1,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
db.upsertResume(sessionId, snapshot, events.length);
|
|
45
|
+
db.incrementCompactCount(sessionId);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
db.close();
|
|
49
|
+
} catch (err) {
|
|
50
|
+
try {
|
|
51
|
+
appendFileSync(DEBUG_LOG, `[${new Date().toISOString()}] ${err?.message || err}\n`);
|
|
52
|
+
} catch { /* silent */ }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// PreCompact — no stdout output needed
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "../suppress-stderr.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* JetBrains Copilot PreToolUse hook for context-mode
|
|
5
|
+
* Thin wrapper — uses shared routing core, no self-heal, no Claude Code-specific logic.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { dirname, resolve } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { readStdin } from "../core/stdin.mjs";
|
|
11
|
+
import { routePreToolUse, initSecurity } from "../core/routing.mjs";
|
|
12
|
+
import { formatDecision } from "../core/formatters.mjs";
|
|
13
|
+
import { parseStdin, getSessionId, JETBRAINS_OPTS } from "../session-helpers.mjs";
|
|
14
|
+
|
|
15
|
+
const __hookDir = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
await initSecurity(resolve(__hookDir, "..", "..", "build"));
|
|
17
|
+
|
|
18
|
+
const raw = await readStdin();
|
|
19
|
+
const input = parseStdin(raw);
|
|
20
|
+
const tool = input.tool_name ?? "";
|
|
21
|
+
const toolInput = input.tool_input ?? {};
|
|
22
|
+
|
|
23
|
+
const decision = routePreToolUse(tool, toolInput, process.env.IDEA_INITIAL_DIRECTORY || process.env.CLAUDE_PROJECT_DIR, "jetbrains-copilot", getSessionId(input, JETBRAINS_OPTS));
|
|
24
|
+
const response = formatDecision("jetbrains-copilot", decision);
|
|
25
|
+
if (response !== null) {
|
|
26
|
+
process.stdout.write(JSON.stringify(response) + "\n");
|
|
27
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "../suppress-stderr.mjs";
|
|
3
|
+
import "../ensure-deps.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* JetBrains Copilot SessionStart hook for context-mode
|
|
6
|
+
*
|
|
7
|
+
* Session lifecycle management:
|
|
8
|
+
* - "startup" → Cleanup old sessions, capture instruction file rules
|
|
9
|
+
* - "compact" → Write events file, inject session knowledge directive
|
|
10
|
+
* - "resume" → Load previous session events, inject directive
|
|
11
|
+
* - "clear" → No action needed
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createSessionLoaders } from "../session-loaders.mjs";
|
|
15
|
+
import { createRoutingBlock } from "../routing-block.mjs";
|
|
16
|
+
import { createToolNamer } from "../core/tool-naming.mjs";
|
|
17
|
+
|
|
18
|
+
const toolNamer = createToolNamer("jetbrains-copilot");
|
|
19
|
+
const ROUTING_BLOCK = createRoutingBlock(toolNamer);
|
|
20
|
+
import { writeSessionEventsFile, buildSessionDirective, getSessionEvents } from "../session-directive.mjs";
|
|
21
|
+
import {
|
|
22
|
+
readStdin, parseStdin, getSessionId, getSessionDBPath, getSessionEventsPath, getCleanupFlagPath,
|
|
23
|
+
getInputProjectDir, JETBRAINS_OPTS,
|
|
24
|
+
} from "../session-helpers.mjs";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
import { readFileSync, unlinkSync } from "node:fs";
|
|
27
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
28
|
+
import { homedir } from "node:os";
|
|
29
|
+
|
|
30
|
+
const HOOK_DIR = fileURLToPath(new URL(".", import.meta.url));
|
|
31
|
+
const { loadSessionDB } = createSessionLoaders(HOOK_DIR);
|
|
32
|
+
const OPTS = JETBRAINS_OPTS;
|
|
33
|
+
|
|
34
|
+
let additionalContext = ROUTING_BLOCK;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const raw = await readStdin();
|
|
38
|
+
const input = parseStdin(raw);
|
|
39
|
+
const source = input.source ?? "startup";
|
|
40
|
+
const projectDir = getInputProjectDir(input, OPTS);
|
|
41
|
+
|
|
42
|
+
if (source === "compact") {
|
|
43
|
+
const { SessionDB } = await loadSessionDB();
|
|
44
|
+
const dbPath = getSessionDBPath(OPTS, projectDir);
|
|
45
|
+
const db = new SessionDB({ dbPath });
|
|
46
|
+
const sessionId = getSessionId(input, OPTS);
|
|
47
|
+
const resume = db.getResume(sessionId);
|
|
48
|
+
|
|
49
|
+
if (resume && !resume.consumed) {
|
|
50
|
+
db.markResumeConsumed(sessionId);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const events = getSessionEvents(db, sessionId);
|
|
54
|
+
if (events.length > 0) {
|
|
55
|
+
const eventMeta = writeSessionEventsFile(events, getSessionEventsPath(OPTS, projectDir));
|
|
56
|
+
additionalContext += buildSessionDirective("compact", eventMeta, toolNamer);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
db.close();
|
|
60
|
+
} else if (source === "resume") {
|
|
61
|
+
try { unlinkSync(getCleanupFlagPath(OPTS, projectDir)); } catch { /* no flag */ }
|
|
62
|
+
|
|
63
|
+
const { SessionDB } = await loadSessionDB();
|
|
64
|
+
const dbPath = getSessionDBPath(OPTS, projectDir);
|
|
65
|
+
const db = new SessionDB({ dbPath });
|
|
66
|
+
|
|
67
|
+
// Filter events to the session being resumed. Falling back to
|
|
68
|
+
// getLatestSessionEvents(db) leaks events from any other session whose
|
|
69
|
+
// session_meta.started_at is more recent — observed cross-session bleed
|
|
70
|
+
// when a different session started after this one and before the resume.
|
|
71
|
+
const sessionId = getSessionId(input, OPTS);
|
|
72
|
+
const events = sessionId ? getSessionEvents(db, sessionId) : [];
|
|
73
|
+
if (events.length > 0) {
|
|
74
|
+
const eventMeta = writeSessionEventsFile(events, getSessionEventsPath(OPTS, projectDir));
|
|
75
|
+
additionalContext += buildSessionDirective("resume", eventMeta, toolNamer);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
db.close();
|
|
79
|
+
} else if (source === "startup") {
|
|
80
|
+
const { SessionDB } = await loadSessionDB();
|
|
81
|
+
const dbPath = getSessionDBPath(OPTS, projectDir);
|
|
82
|
+
const db = new SessionDB({ dbPath });
|
|
83
|
+
try { unlinkSync(getSessionEventsPath(OPTS, projectDir)); } catch { /* no stale file */ }
|
|
84
|
+
|
|
85
|
+
db.cleanupOldSessions(7);
|
|
86
|
+
db.db.exec(`DELETE FROM session_events WHERE session_id NOT IN (SELECT session_id FROM session_meta)`);
|
|
87
|
+
|
|
88
|
+
const sessionId = getSessionId(input, OPTS);
|
|
89
|
+
db.ensureSession(sessionId, projectDir);
|
|
90
|
+
|
|
91
|
+
const ruleFilePaths = [
|
|
92
|
+
join(projectDir, ".github", "copilot-instructions.md"),
|
|
93
|
+
];
|
|
94
|
+
for (const p of ruleFilePaths) {
|
|
95
|
+
try {
|
|
96
|
+
const content = readFileSync(p, "utf-8");
|
|
97
|
+
if (content.trim()) {
|
|
98
|
+
db.insertEvent(sessionId, { type: "rule", category: "rule", data: p, priority: 1 });
|
|
99
|
+
db.insertEvent(sessionId, { type: "rule_content", category: "rule", data: content, priority: 1 });
|
|
100
|
+
}
|
|
101
|
+
} catch { /* file doesn't exist — skip */ }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
db.close();
|
|
105
|
+
}
|
|
106
|
+
// "clear" — no action needed
|
|
107
|
+
} catch (err) {
|
|
108
|
+
try {
|
|
109
|
+
const { appendFileSync } = await import("node:fs");
|
|
110
|
+
const { join: pjoin } = await import("node:path");
|
|
111
|
+
const { homedir: hd } = await import("node:os");
|
|
112
|
+
appendFileSync(
|
|
113
|
+
pjoin(hd(), ".config", "JetBrains", "context-mode", "sessionstart-debug.log"),
|
|
114
|
+
`[${new Date().toISOString()}] ${err?.message || err}\n${err?.stack || ""}\n`,
|
|
115
|
+
);
|
|
116
|
+
} catch { /* ignore logging failure */ }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
console.log(JSON.stringify({
|
|
120
|
+
hookSpecificOutput: {
|
|
121
|
+
hookEventName: "SessionStart",
|
|
122
|
+
additionalContext,
|
|
123
|
+
},
|
|
124
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
process.env.CONTEXT_MODE_PLATFORM = "kimi";
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "./platform.mjs";
|
|
3
|
+
import "../suppress-stderr.mjs";
|
|
4
|
+
import "../ensure-deps.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Kimi Code CLI postToolUse hook — session event capture.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { readStdin, parseStdin, getSessionId, getSessionDBPath, getInputProjectDir, KIMI_OPTS } from "../session-helpers.mjs";
|
|
10
|
+
import { createSessionLoaders, attributeAndInsertEvents } from "../session-loaders.mjs";
|
|
11
|
+
import { dirname } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
|
|
14
|
+
const HOOK_DIR = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const { loadSessionDB, loadExtract, loadProjectAttribution } = createSessionLoaders(HOOK_DIR);
|
|
16
|
+
const OPTS = KIMI_OPTS;
|
|
17
|
+
|
|
18
|
+
function normalizeToolName(toolName) {
|
|
19
|
+
if (toolName === "Shell") return "Bash";
|
|
20
|
+
return toolName;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const raw = await readStdin();
|
|
25
|
+
const input = parseStdin(raw);
|
|
26
|
+
const projectDir = getInputProjectDir(input, OPTS);
|
|
27
|
+
|
|
28
|
+
const { extractEvents } = await loadExtract();
|
|
29
|
+
const { resolveProjectAttributions } = await loadProjectAttribution();
|
|
30
|
+
const { SessionDB } = await loadSessionDB();
|
|
31
|
+
|
|
32
|
+
const dbPath = getSessionDBPath(OPTS, projectDir);
|
|
33
|
+
const db = new SessionDB({ dbPath });
|
|
34
|
+
const sessionId = getSessionId(input, OPTS);
|
|
35
|
+
|
|
36
|
+
db.ensureSession(sessionId, projectDir);
|
|
37
|
+
|
|
38
|
+
// Kimi Code sends tool_output on success (no tool_response field).
|
|
39
|
+
// Normalize tool_response to a clean string — when the host omits it,
|
|
40
|
+
// surface the empty string rather than `JSON.stringify(undefined ?? "")`
|
|
41
|
+
// which yields `'""'` and tricks downstream extractEvents into treating
|
|
42
|
+
// an empty response as a non-empty payload.
|
|
43
|
+
let toolResponse = "";
|
|
44
|
+
if (typeof input.tool_response === "string") {
|
|
45
|
+
toolResponse = input.tool_response;
|
|
46
|
+
} else if (input.tool_response !== undefined && input.tool_response !== null) {
|
|
47
|
+
toolResponse = JSON.stringify(input.tool_response);
|
|
48
|
+
}
|
|
49
|
+
const normalizedInput = {
|
|
50
|
+
tool_name: normalizeToolName(input.tool_name ?? ""),
|
|
51
|
+
tool_input: input.tool_input ?? {},
|
|
52
|
+
tool_response: toolResponse,
|
|
53
|
+
tool_output: input.tool_output
|
|
54
|
+
? {
|
|
55
|
+
...input.tool_output,
|
|
56
|
+
isError: input.tool_output.isError === true || input.tool_output.is_error === true,
|
|
57
|
+
}
|
|
58
|
+
: undefined,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const events = extractEvents(normalizedInput);
|
|
62
|
+
|
|
63
|
+
attributeAndInsertEvents(db, sessionId, events, input, projectDir, "PostToolUse", resolveProjectAttributions);
|
|
64
|
+
|
|
65
|
+
db.close();
|
|
66
|
+
} catch {
|
|
67
|
+
// Swallow errors — hook must not fail
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
process.stdout.write(JSON.stringify({
|
|
71
|
+
hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: "" },
|
|
72
|
+
}) + "\n");
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "./platform.mjs";
|
|
3
|
+
import "../suppress-stderr.mjs";
|
|
4
|
+
import "../ensure-deps.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Kimi Code CLI PreCompact hook - snapshot generation.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
readStdin,
|
|
11
|
+
parseStdin,
|
|
12
|
+
getSessionId,
|
|
13
|
+
getSessionDBPath,
|
|
14
|
+
getInputProjectDir,
|
|
15
|
+
resolveConfigDir,
|
|
16
|
+
KIMI_OPTS,
|
|
17
|
+
} from "../session-helpers.mjs";
|
|
18
|
+
import { createSessionLoaders } from "../session-loaders.mjs";
|
|
19
|
+
import { appendFileSync } from "node:fs";
|
|
20
|
+
import { join, dirname } from "node:path";
|
|
21
|
+
import { fileURLToPath } from "node:url";
|
|
22
|
+
|
|
23
|
+
const HOOK_DIR = dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
const { loadSessionDB, loadSnapshot } = createSessionLoaders(HOOK_DIR);
|
|
25
|
+
const OPTS = KIMI_OPTS;
|
|
26
|
+
// Diagnostic log is opt-in via CONTEXT_MODE_DEBUG. Long-running installs hit
|
|
27
|
+
// compaction repeatedly; an unbounded append-only file under the user's data
|
|
28
|
+
// root accrues on every transient error. Gating the write behind an env flag
|
|
29
|
+
// preserves the diagnostic for contributors who want it without burdening
|
|
30
|
+
// everyone else's disk. Match the pattern used by other hooks for error
|
|
31
|
+
// telemetry — most stay silent unless explicitly enabled.
|
|
32
|
+
const DEBUG_LOG = process.env.CONTEXT_MODE_DEBUG
|
|
33
|
+
? join(resolveConfigDir(OPTS), "context-mode", "precompact-debug.log")
|
|
34
|
+
: null;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const raw = await readStdin();
|
|
38
|
+
const input = parseStdin(raw);
|
|
39
|
+
const projectDir = getInputProjectDir(input, OPTS);
|
|
40
|
+
|
|
41
|
+
const { buildResumeSnapshot } = await loadSnapshot();
|
|
42
|
+
const { SessionDB } = await loadSessionDB();
|
|
43
|
+
|
|
44
|
+
const dbPath = getSessionDBPath(OPTS, projectDir);
|
|
45
|
+
const db = new SessionDB({ dbPath });
|
|
46
|
+
const sessionId = getSessionId(input, OPTS);
|
|
47
|
+
|
|
48
|
+
const events = db.getEvents(sessionId);
|
|
49
|
+
|
|
50
|
+
if (events.length > 0) {
|
|
51
|
+
const stats = db.getSessionStats(sessionId);
|
|
52
|
+
const snapshot = buildResumeSnapshot(events, {
|
|
53
|
+
compactCount: (stats?.compact_count ?? 0) + 1,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
db.upsertResume(sessionId, snapshot, events.length);
|
|
57
|
+
db.incrementCompactCount(sessionId);
|
|
58
|
+
|
|
59
|
+
const fileEvents = events.filter((event) => event.category === "file");
|
|
60
|
+
db.insertEvent(sessionId, {
|
|
61
|
+
type: "compaction_summary",
|
|
62
|
+
category: "compaction",
|
|
63
|
+
data: `Session compacted. ${events.length} events, ${fileEvents.length} files touched.`,
|
|
64
|
+
priority: 1,
|
|
65
|
+
}, "PreCompact");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
db.close();
|
|
69
|
+
} catch (err) {
|
|
70
|
+
if (DEBUG_LOG) {
|
|
71
|
+
try {
|
|
72
|
+
appendFileSync(DEBUG_LOG, `[${new Date().toISOString()}] ${err?.message || err}\n`);
|
|
73
|
+
} catch {
|
|
74
|
+
// Hook errors must not break Kimi Code compaction.
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Without CONTEXT_MODE_DEBUG, swallow silently — same shape as other hooks.
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
process.stdout.write(JSON.stringify({}) + "\n");
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "./platform.mjs";
|
|
3
|
+
import "../suppress-stderr.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Kimi Code CLI preToolUse hook for context-mode.
|
|
6
|
+
*
|
|
7
|
+
* Kimi Code PreToolUse supports:
|
|
8
|
+
* - Exit code 0 with JSON:
|
|
9
|
+
* { hookSpecificOutput: { permissionDecision: "deny", permissionDecisionReason: "..." } }
|
|
10
|
+
* → block the tool call
|
|
11
|
+
* - Exit code 2 → block (stderr used as reason)
|
|
12
|
+
*
|
|
13
|
+
* Like Codex, Kimi Code only acts on `permissionDecision === "deny"` —
|
|
14
|
+
* `ask` / `allow + updatedInput` / `additionalContext` are explicitly stripped
|
|
15
|
+
* by the host's runner (refs/platforms/kimi-code/.../session/hooks/runner.ts:
|
|
16
|
+
* 36-39,162-178) and its HookResult type has no additionalContext field
|
|
17
|
+
* (types.ts:28-37). The central formatter at hooks/core/formatters.mjs
|
|
18
|
+
* therefore returns null for those branches; see the codex precedent at #225
|
|
19
|
+
* (commit 607dc70).
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { dirname, resolve } from "node:path";
|
|
23
|
+
import { fileURLToPath } from "node:url";
|
|
24
|
+
import { readStdin, parseStdin, getInputProjectDir, getSessionId, KIMI_OPTS } from "../session-helpers.mjs";
|
|
25
|
+
import { routePreToolUse, initSecurity } from "../core/routing.mjs";
|
|
26
|
+
import { formatDecision } from "../core/formatters.mjs";
|
|
27
|
+
|
|
28
|
+
const __hookDir = dirname(fileURLToPath(import.meta.url));
|
|
29
|
+
await initSecurity(resolve(__hookDir, "..", "..", "build"));
|
|
30
|
+
|
|
31
|
+
const raw = await readStdin();
|
|
32
|
+
const input = parseStdin(raw);
|
|
33
|
+
const tool = input.tool_name ?? "";
|
|
34
|
+
const toolInput = input.tool_input ?? {};
|
|
35
|
+
const projectDir = getInputProjectDir(input, KIMI_OPTS);
|
|
36
|
+
|
|
37
|
+
const decision = routePreToolUse(tool, toolInput, projectDir, "kimi", getSessionId(input, KIMI_OPTS));
|
|
38
|
+
const response = formatDecision("kimi", decision);
|
|
39
|
+
const output = response ?? {
|
|
40
|
+
hookSpecificOutput: { hookEventName: "PreToolUse" },
|
|
41
|
+
};
|
|
42
|
+
process.stdout.write(JSON.stringify(output) + "\n");
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "./platform.mjs";
|
|
3
|
+
import "../suppress-stderr.mjs";
|
|
4
|
+
import "../ensure-deps.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Kimi Code CLI SessionEnd hook — record genuine session close.
|
|
7
|
+
*
|
|
8
|
+
* Wired to the upstream `SessionEnd` event, distinct from `Stop`:
|
|
9
|
+
* refs/platforms/kimi-code/packages/agent-core/src/session/index.ts:
|
|
10
|
+
* 192 — `await this.triggerSessionEnd('exit')` inside `close()`
|
|
11
|
+
* 502 — `triggerSessionEnd(reason: 'exit')` signature
|
|
12
|
+
* 11 — `'SessionEnd'` in `HOOK_EVENT_TYPES` (types.ts)
|
|
13
|
+
* refs/platforms/kimi-cli/src/kimi_cli/hooks/events.py:108-114 — Python
|
|
14
|
+
* runtime emits `session_end(session_id, cwd, reason)` independently
|
|
15
|
+
* of `Stop`.
|
|
16
|
+
*
|
|
17
|
+
* Stop fires at the end of every assistant turn — writing a `session_end`
|
|
18
|
+
* SessionDB row from Stop produced one such row per turn. SessionEnd
|
|
19
|
+
* fires once when the host's session closes, which is what consumers of
|
|
20
|
+
* `type === "session_end"` (analytics, resume) actually mean.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { readStdin, parseStdin, getSessionId, getSessionDBPath, getInputProjectDir, KIMI_OPTS } from "../session-helpers.mjs";
|
|
24
|
+
import { createSessionLoaders } from "../session-loaders.mjs";
|
|
25
|
+
import { dirname } from "node:path";
|
|
26
|
+
import { fileURLToPath } from "node:url";
|
|
27
|
+
|
|
28
|
+
const HOOK_DIR = dirname(fileURLToPath(import.meta.url));
|
|
29
|
+
const { loadSessionDB } = createSessionLoaders(HOOK_DIR);
|
|
30
|
+
const OPTS = KIMI_OPTS;
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const raw = await readStdin();
|
|
34
|
+
const input = parseStdin(raw);
|
|
35
|
+
const projectDir = getInputProjectDir(input, OPTS);
|
|
36
|
+
|
|
37
|
+
const { SessionDB } = await loadSessionDB();
|
|
38
|
+
const dbPath = getSessionDBPath(OPTS, projectDir);
|
|
39
|
+
const db = new SessionDB({ dbPath });
|
|
40
|
+
const sessionId = getSessionId(input, OPTS);
|
|
41
|
+
|
|
42
|
+
db.ensureSession(sessionId, projectDir);
|
|
43
|
+
// SessionEvent contract (src/types.ts:33-47) requires `type`, `category`,
|
|
44
|
+
// `data`, `priority`. Encode the payload — including `reason`, which
|
|
45
|
+
// upstream currently only emits as `'exit'` but is typed as a free string
|
|
46
|
+
// for forward compatibility — into `data` so dedup-hashing succeeds and
|
|
47
|
+
// the row lands.
|
|
48
|
+
const reason = typeof input.reason === "string" ? input.reason : "exit";
|
|
49
|
+
db.insertEvent(sessionId, {
|
|
50
|
+
type: "session_end",
|
|
51
|
+
category: "session",
|
|
52
|
+
data: JSON.stringify({ status: "completed", reason }),
|
|
53
|
+
priority: 1,
|
|
54
|
+
}, "SessionEnd");
|
|
55
|
+
|
|
56
|
+
db.close();
|
|
57
|
+
} catch {
|
|
58
|
+
// Kimi Code hooks must not block session shutdown.
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
process.stdout.write("{}\n");
|