context-mode 0.9.21 → 1.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.
Files changed (102) hide show
  1. package/.claude-plugin/hooks/hooks.json +46 -4
  2. package/.claude-plugin/marketplace.json +2 -2
  3. package/.claude-plugin/plugin.json +4 -4
  4. package/README.md +377 -191
  5. package/build/adapters/claude-code/config.d.ts +8 -0
  6. package/build/adapters/claude-code/config.js +8 -0
  7. package/build/adapters/claude-code/hooks.d.ts +53 -0
  8. package/build/adapters/claude-code/hooks.js +88 -0
  9. package/build/adapters/claude-code/index.d.ts +50 -0
  10. package/build/adapters/claude-code/index.js +523 -0
  11. package/build/adapters/codex/config.d.ts +8 -0
  12. package/build/adapters/codex/config.js +8 -0
  13. package/build/adapters/codex/hooks.d.ts +21 -0
  14. package/build/adapters/codex/hooks.js +27 -0
  15. package/build/adapters/codex/index.d.ts +44 -0
  16. package/build/adapters/codex/index.js +223 -0
  17. package/build/adapters/detect.d.ts +26 -0
  18. package/build/adapters/detect.js +131 -0
  19. package/build/adapters/gemini-cli/config.d.ts +8 -0
  20. package/build/adapters/gemini-cli/config.js +8 -0
  21. package/build/adapters/gemini-cli/hooks.d.ts +44 -0
  22. package/build/adapters/gemini-cli/hooks.js +64 -0
  23. package/build/adapters/gemini-cli/index.d.ts +57 -0
  24. package/build/adapters/gemini-cli/index.js +468 -0
  25. package/build/adapters/opencode/config.d.ts +8 -0
  26. package/build/adapters/opencode/config.js +8 -0
  27. package/build/adapters/opencode/hooks.d.ts +38 -0
  28. package/build/adapters/opencode/hooks.js +50 -0
  29. package/build/adapters/opencode/index.d.ts +52 -0
  30. package/build/adapters/opencode/index.js +386 -0
  31. package/build/adapters/types.d.ts +218 -0
  32. package/build/adapters/types.js +13 -0
  33. package/build/adapters/vscode-copilot/config.d.ts +8 -0
  34. package/build/adapters/vscode-copilot/config.js +8 -0
  35. package/build/adapters/vscode-copilot/hooks.d.ts +49 -0
  36. package/build/adapters/vscode-copilot/hooks.js +76 -0
  37. package/build/adapters/vscode-copilot/index.d.ts +58 -0
  38. package/build/adapters/vscode-copilot/index.js +512 -0
  39. package/build/cli.d.ts +9 -6
  40. package/build/cli.js +133 -423
  41. package/build/db-base.d.ts +84 -0
  42. package/build/db-base.js +128 -0
  43. package/build/executor.d.ts +6 -7
  44. package/build/executor.js +111 -51
  45. package/build/opencode-plugin.d.ts +37 -0
  46. package/build/opencode-plugin.js +118 -0
  47. package/build/runtime.js +1 -1
  48. package/build/server.js +436 -117
  49. package/build/session/db.d.ts +110 -0
  50. package/build/session/db.js +285 -0
  51. package/build/session/extract.d.ts +51 -0
  52. package/build/session/extract.js +407 -0
  53. package/build/session/snapshot.d.ts +70 -0
  54. package/build/session/snapshot.js +309 -0
  55. package/build/store.d.ts +4 -22
  56. package/build/store.js +67 -55
  57. package/build/truncate.d.ts +59 -0
  58. package/build/truncate.js +157 -0
  59. package/build/types.d.ts +101 -0
  60. package/build/types.js +20 -0
  61. package/configs/claude-code/CLAUDE.md +62 -0
  62. package/configs/codex/AGENTS.md +58 -0
  63. package/configs/codex/config.toml +5 -0
  64. package/configs/gemini-cli/GEMINI.md +58 -0
  65. package/configs/gemini-cli/mcp.json +7 -0
  66. package/configs/gemini-cli/settings.json +49 -0
  67. package/configs/opencode/AGENTS.md +58 -0
  68. package/configs/opencode/opencode.json +10 -0
  69. package/configs/vscode-copilot/copilot-instructions.md +58 -0
  70. package/configs/vscode-copilot/hooks.json +16 -0
  71. package/configs/vscode-copilot/mcp.json +8 -0
  72. package/hooks/core/formatters.mjs +86 -0
  73. package/hooks/core/routing.mjs +262 -0
  74. package/hooks/core/stdin.mjs +19 -0
  75. package/hooks/formatters/claude-code.mjs +57 -0
  76. package/hooks/formatters/gemini-cli.mjs +55 -0
  77. package/hooks/formatters/vscode-copilot.mjs +55 -0
  78. package/hooks/gemini-cli/aftertool.mjs +58 -0
  79. package/hooks/gemini-cli/beforetool.mjs +25 -0
  80. package/hooks/gemini-cli/precompress.mjs +51 -0
  81. package/hooks/gemini-cli/sessionstart.mjs +117 -0
  82. package/hooks/hooks.json +46 -4
  83. package/hooks/posttooluse.mjs +53 -0
  84. package/hooks/precompact.mjs +55 -0
  85. package/hooks/pretooluse.mjs +23 -266
  86. package/hooks/routing-block.mjs +19 -6
  87. package/hooks/session-directive.mjs +353 -0
  88. package/hooks/session-helpers.mjs +112 -0
  89. package/hooks/sessionstart.mjs +123 -16
  90. package/hooks/userpromptsubmit.mjs +58 -0
  91. package/hooks/vscode-copilot/posttooluse.mjs +58 -0
  92. package/hooks/vscode-copilot/precompact.mjs +51 -0
  93. package/hooks/vscode-copilot/pretooluse.mjs +25 -0
  94. package/hooks/vscode-copilot/sessionstart.mjs +115 -0
  95. package/package.json +20 -17
  96. package/skills/context-mode/SKILL.md +49 -49
  97. package/skills/{doctor → ctx-doctor}/SKILL.md +3 -3
  98. package/skills/{stats → ctx-stats}/SKILL.md +3 -3
  99. package/skills/{upgrade → ctx-upgrade}/SKILL.md +3 -3
  100. package/start.mjs +47 -0
  101. package/hooks/pretooluse.sh +0 -147
  102. package/server.bundle.mjs +0 -341
@@ -0,0 +1,8 @@
1
+ /**
2
+ * adapters/claude-code/config — Thin re-exports from ClaudeCodeAdapter.
3
+ *
4
+ * This module exists for backward compatibility. All logic lives in the
5
+ * adapter class (index.ts). New code should use getAdapter() from detect.ts.
6
+ */
7
+ export { ClaudeCodeAdapter } from "./index.js";
8
+ export { HOOK_TYPES, HOOK_SCRIPTS, PRE_TOOL_USE_MATCHER_PATTERN } from "./hooks.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * adapters/claude-code/config — Thin re-exports from ClaudeCodeAdapter.
3
+ *
4
+ * This module exists for backward compatibility. All logic lives in the
5
+ * adapter class (index.ts). New code should use getAdapter() from detect.ts.
6
+ */
7
+ export { ClaudeCodeAdapter } from "./index.js";
8
+ export { HOOK_TYPES, HOOK_SCRIPTS, PRE_TOOL_USE_MATCHER_PATTERN } from "./hooks.js";
@@ -0,0 +1,53 @@
1
+ /**
2
+ * adapters/claude-code/hooks — Claude Code hook definitions and matchers.
3
+ *
4
+ * Defines the hook types, matchers, and registration format specific to
5
+ * Claude Code's hook system. This module is used by:
6
+ * - CLI setup/upgrade commands (to configure hooks in settings.json)
7
+ * - Doctor command (to validate hook configuration)
8
+ * - hooks.json generation
9
+ *
10
+ * Claude Code hook system reference:
11
+ * - Hooks are registered in ~/.claude/settings.json under "hooks" key
12
+ * - Each hook type maps to an array of { matcher, hooks } entries
13
+ * - matcher: tool name pattern (empty = match all tools)
14
+ * - hooks: array of { type: "command", command: "..." }
15
+ * - Input: JSON on stdin
16
+ * - Output: JSON on stdout (or empty for passthrough)
17
+ */
18
+ /** Claude Code hook types. */
19
+ export declare const HOOK_TYPES: {
20
+ readonly PRE_TOOL_USE: "PreToolUse";
21
+ readonly POST_TOOL_USE: "PostToolUse";
22
+ readonly PRE_COMPACT: "PreCompact";
23
+ readonly SESSION_START: "SessionStart";
24
+ readonly USER_PROMPT_SUBMIT: "UserPromptSubmit";
25
+ };
26
+ export type HookType = (typeof HOOK_TYPES)[keyof typeof HOOK_TYPES];
27
+ /** Tools that context-mode's PreToolUse hook intercepts. */
28
+ export declare const PRE_TOOL_USE_MATCHERS: readonly ["Bash", "WebFetch", "Read", "Grep", "Agent", "Task", "mcp__plugin_context-mode_context-mode__ctx_execute", "mcp__plugin_context-mode_context-mode__ctx_execute_file", "mcp__plugin_context-mode_context-mode__ctx_batch_execute"];
29
+ /**
30
+ * Combined matcher pattern for settings.json (pipe-separated).
31
+ * Used by the upgrade command when writing a single consolidated entry.
32
+ */
33
+ export declare const PRE_TOOL_USE_MATCHER_PATTERN: string;
34
+ /** Map of hook types to their script file names. */
35
+ export declare const HOOK_SCRIPTS: Record<HookType, string>;
36
+ /** Required hooks that must be configured for context-mode to function. */
37
+ export declare const REQUIRED_HOOKS: HookType[];
38
+ /** Optional hooks that enhance functionality but aren't critical. */
39
+ export declare const OPTIONAL_HOOKS: HookType[];
40
+ /**
41
+ * Check if a hook entry points to a context-mode hook script.
42
+ */
43
+ export declare function isContextModeHook(entry: {
44
+ hooks?: Array<{
45
+ command?: string;
46
+ }>;
47
+ }, hookType: HookType): boolean;
48
+ /**
49
+ * Build the hook command string for a given hook type.
50
+ * Uses the CLI dispatcher: `context-mode hook claude-code <event>`
51
+ * Requires global install: `npm install -g context-mode`
52
+ */
53
+ export declare function buildHookCommand(hookType: HookType): string;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * adapters/claude-code/hooks — Claude Code hook definitions and matchers.
3
+ *
4
+ * Defines the hook types, matchers, and registration format specific to
5
+ * Claude Code's hook system. This module is used by:
6
+ * - CLI setup/upgrade commands (to configure hooks in settings.json)
7
+ * - Doctor command (to validate hook configuration)
8
+ * - hooks.json generation
9
+ *
10
+ * Claude Code hook system reference:
11
+ * - Hooks are registered in ~/.claude/settings.json under "hooks" key
12
+ * - Each hook type maps to an array of { matcher, hooks } entries
13
+ * - matcher: tool name pattern (empty = match all tools)
14
+ * - hooks: array of { type: "command", command: "..." }
15
+ * - Input: JSON on stdin
16
+ * - Output: JSON on stdout (or empty for passthrough)
17
+ */
18
+ // ─────────────────────────────────────────────────────────
19
+ // Hook type constants
20
+ // ─────────────────────────────────────────────────────────
21
+ /** Claude Code hook types. */
22
+ export const HOOK_TYPES = {
23
+ PRE_TOOL_USE: "PreToolUse",
24
+ POST_TOOL_USE: "PostToolUse",
25
+ PRE_COMPACT: "PreCompact",
26
+ SESSION_START: "SessionStart",
27
+ USER_PROMPT_SUBMIT: "UserPromptSubmit",
28
+ };
29
+ // ─────────────────────────────────────────────────────────
30
+ // PreToolUse matchers
31
+ // ─────────────────────────────────────────────────────────
32
+ /** Tools that context-mode's PreToolUse hook intercepts. */
33
+ export const PRE_TOOL_USE_MATCHERS = [
34
+ "Bash",
35
+ "WebFetch",
36
+ "Read",
37
+ "Grep",
38
+ "Agent",
39
+ "Task",
40
+ "mcp__plugin_context-mode_context-mode__ctx_execute",
41
+ "mcp__plugin_context-mode_context-mode__ctx_execute_file",
42
+ "mcp__plugin_context-mode_context-mode__ctx_batch_execute",
43
+ ];
44
+ /**
45
+ * Combined matcher pattern for settings.json (pipe-separated).
46
+ * Used by the upgrade command when writing a single consolidated entry.
47
+ */
48
+ export const PRE_TOOL_USE_MATCHER_PATTERN = PRE_TOOL_USE_MATCHERS.join("|");
49
+ // ─────────────────────────────────────────────────────────
50
+ // Hook script file names
51
+ // ─────────────────────────────────────────────────────────
52
+ /** Map of hook types to their script file names. */
53
+ export const HOOK_SCRIPTS = {
54
+ PreToolUse: "pretooluse.mjs",
55
+ PostToolUse: "posttooluse.mjs",
56
+ PreCompact: "precompact.mjs",
57
+ SessionStart: "sessionstart.mjs",
58
+ UserPromptSubmit: "userpromptsubmit.mjs",
59
+ };
60
+ // ─────────────────────────────────────────────────────────
61
+ // Hook validation
62
+ // ─────────────────────────────────────────────────────────
63
+ /** Required hooks that must be configured for context-mode to function. */
64
+ export const REQUIRED_HOOKS = [
65
+ HOOK_TYPES.PRE_TOOL_USE,
66
+ HOOK_TYPES.SESSION_START,
67
+ ];
68
+ /** Optional hooks that enhance functionality but aren't critical. */
69
+ export const OPTIONAL_HOOKS = [
70
+ HOOK_TYPES.POST_TOOL_USE,
71
+ HOOK_TYPES.PRE_COMPACT,
72
+ HOOK_TYPES.USER_PROMPT_SUBMIT,
73
+ ];
74
+ /**
75
+ * Check if a hook entry points to a context-mode hook script.
76
+ */
77
+ export function isContextModeHook(entry, hookType) {
78
+ const scriptName = HOOK_SCRIPTS[hookType];
79
+ return (entry.hooks?.some((h) => h.command?.includes(scriptName)) ?? false);
80
+ }
81
+ /**
82
+ * Build the hook command string for a given hook type.
83
+ * Uses the CLI dispatcher: `context-mode hook claude-code <event>`
84
+ * Requires global install: `npm install -g context-mode`
85
+ */
86
+ export function buildHookCommand(hookType) {
87
+ return `context-mode hook claude-code ${hookType.toLowerCase()}`;
88
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * adapters/claude-code — Claude Code platform adapter.
3
+ *
4
+ * Implements HookAdapter for Claude Code's JSON stdin/stdout hook paradigm.
5
+ *
6
+ * Claude Code hook specifics:
7
+ * - I/O: JSON on stdin, JSON on stdout
8
+ * - Arg modification: `updatedInput` field in response
9
+ * - Blocking: `permissionDecision: "deny"` in response
10
+ * - PostToolUse output: `updatedMCPToolOutput` field
11
+ * - PreCompact: stdout on exit 0
12
+ * - Session ID: transcript_path UUID > session_id > CLAUDE_SESSION_ID > ppid
13
+ * - Config: ~/.claude/settings.json
14
+ * - Session dir: ~/.claude/context-mode/sessions/
15
+ */
16
+ import type { HookAdapter, HookParadigm, PlatformCapabilities, DiagnosticResult, PreToolUseEvent, PostToolUseEvent, PreCompactEvent, SessionStartEvent, PreToolUseResponse, PostToolUseResponse, PreCompactResponse, SessionStartResponse, HookRegistration, RoutingInstructionsConfig } from "../types.js";
17
+ export declare class ClaudeCodeAdapter implements HookAdapter {
18
+ readonly name = "Claude Code";
19
+ readonly paradigm: HookParadigm;
20
+ readonly capabilities: PlatformCapabilities;
21
+ parsePreToolUseInput(raw: unknown): PreToolUseEvent;
22
+ parsePostToolUseInput(raw: unknown): PostToolUseEvent;
23
+ parsePreCompactInput(raw: unknown): PreCompactEvent;
24
+ parseSessionStartInput(raw: unknown): SessionStartEvent;
25
+ formatPreToolUseResponse(response: PreToolUseResponse): unknown;
26
+ formatPostToolUseResponse(response: PostToolUseResponse): unknown;
27
+ formatPreCompactResponse(response: PreCompactResponse): unknown;
28
+ formatSessionStartResponse(response: SessionStartResponse): unknown;
29
+ getSettingsPath(): string;
30
+ getSessionDir(): string;
31
+ getSessionDBPath(projectDir: string): string;
32
+ getSessionEventsPath(projectDir: string): string;
33
+ generateHookConfig(pluginRoot: string): HookRegistration;
34
+ readSettings(): Record<string, unknown> | null;
35
+ writeSettings(settings: Record<string, unknown>): void;
36
+ validateHooks(pluginRoot: string): DiagnosticResult[];
37
+ checkPluginRegistration(): DiagnosticResult;
38
+ getInstalledVersion(): string;
39
+ configureAllHooks(pluginRoot: string): string[];
40
+ backupSettings(): string | null;
41
+ setHookPermissions(pluginRoot: string): string[];
42
+ updatePluginRegistry(pluginRoot: string, version: string): void;
43
+ getRoutingInstructionsConfig(): RoutingInstructionsConfig;
44
+ writeRoutingInstructions(projectDir: string, pluginRoot: string): string | null;
45
+ /**
46
+ * Extract session ID from Claude Code hook input.
47
+ * Priority: transcript_path UUID > session_id field > CLAUDE_SESSION_ID env > ppid fallback.
48
+ */
49
+ private extractSessionId;
50
+ }