context-mode 1.0.151 → 1.0.153

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 (106) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.codex-plugin/mcp.json +5 -1
  4. package/.codex-plugin/plugin.json +1 -1
  5. package/.openclaw-plugin/openclaw.plugin.json +16 -1
  6. package/.openclaw-plugin/package.json +1 -1
  7. package/README.md +89 -3
  8. package/build/adapters/claude-code/hooks.js +2 -2
  9. package/build/adapters/claude-code/index.js +14 -13
  10. package/build/adapters/client-map.js +3 -0
  11. package/build/adapters/detect.js +13 -1
  12. package/build/adapters/gemini-cli/hooks.d.ts +10 -0
  13. package/build/adapters/gemini-cli/hooks.js +12 -2
  14. package/build/adapters/gemini-cli/index.d.ts +21 -1
  15. package/build/adapters/gemini-cli/index.js +37 -1
  16. package/build/adapters/kimi/config.d.ts +8 -0
  17. package/build/adapters/kimi/config.js +8 -0
  18. package/build/adapters/kimi/hooks.d.ts +28 -0
  19. package/build/adapters/kimi/hooks.js +34 -0
  20. package/build/adapters/kimi/index.d.ts +66 -0
  21. package/build/adapters/kimi/index.js +537 -0
  22. package/build/adapters/kimi/paths.d.ts +1 -0
  23. package/build/adapters/kimi/paths.js +12 -0
  24. package/build/adapters/kiro/hooks.js +2 -2
  25. package/build/adapters/openclaw/plugin.d.ts +14 -13
  26. package/build/adapters/openclaw/plugin.js +140 -40
  27. package/build/adapters/opencode/plugin.js +4 -3
  28. package/build/adapters/opencode/zod3tov4.js +8 -8
  29. package/build/adapters/pi/extension.js +9 -24
  30. package/build/adapters/pi/mcp-bridge.js +37 -0
  31. package/build/adapters/qwen-code/index.js +7 -7
  32. package/build/adapters/types.d.ts +39 -2
  33. package/build/adapters/types.js +55 -2
  34. package/build/cli.js +433 -25
  35. package/build/executor.js +6 -3
  36. package/build/runtime.d.ts +81 -1
  37. package/build/runtime.js +195 -9
  38. package/build/search/ctx-search-schema.d.ts +90 -0
  39. package/build/search/ctx-search-schema.js +135 -0
  40. package/build/search/unified.d.ts +12 -0
  41. package/build/search/unified.js +17 -2
  42. package/build/server.d.ts +2 -1
  43. package/build/server.js +378 -97
  44. package/build/session/analytics.d.ts +36 -3
  45. package/build/session/analytics.js +88 -26
  46. package/build/session/db.d.ts +24 -0
  47. package/build/session/db.js +41 -0
  48. package/build/session/extract.js +30 -0
  49. package/build/session/snapshot.js +24 -0
  50. package/build/store.d.ts +12 -1
  51. package/build/store.js +72 -20
  52. package/build/types.d.ts +7 -0
  53. package/build/util/project-dir.d.ts +19 -16
  54. package/build/util/project-dir.js +80 -45
  55. package/cli.bundle.mjs +370 -319
  56. package/configs/kimi/hooks.json +54 -0
  57. package/configs/pi/AGENTS.md +3 -85
  58. package/hooks/cache-heal-utils.mjs +148 -0
  59. package/hooks/core/formatters.mjs +26 -0
  60. package/hooks/core/routing.mjs +9 -1
  61. package/hooks/core/stdin.mjs +74 -3
  62. package/hooks/core/tool-naming.mjs +1 -0
  63. package/hooks/heal-partial-install.mjs +712 -0
  64. package/hooks/kimi/platform.mjs +1 -0
  65. package/hooks/kimi/posttooluse.mjs +72 -0
  66. package/hooks/kimi/precompact.mjs +80 -0
  67. package/hooks/kimi/pretooluse.mjs +42 -0
  68. package/hooks/kimi/sessionend.mjs +61 -0
  69. package/hooks/kimi/sessionstart.mjs +113 -0
  70. package/hooks/kimi/stop.mjs +61 -0
  71. package/hooks/kimi/userpromptsubmit.mjs +90 -0
  72. package/hooks/normalize-hooks.mjs +66 -12
  73. package/hooks/routing-block.mjs +8 -2
  74. package/hooks/security.bundle.mjs +1 -1
  75. package/hooks/session-db.bundle.mjs +6 -4
  76. package/hooks/session-extract.bundle.mjs +2 -2
  77. package/hooks/session-helpers.mjs +93 -3
  78. package/hooks/session-snapshot.bundle.mjs +20 -19
  79. package/hooks/sessionstart.mjs +64 -0
  80. package/insight/server.mjs +15 -3
  81. package/openclaw.plugin.json +16 -1
  82. package/package.json +1 -1
  83. package/scripts/heal-installed-plugins.mjs +31 -10
  84. package/scripts/postinstall.mjs +10 -0
  85. package/server.bundle.mjs +206 -157
  86. package/skills/ctx-index/SKILL.md +46 -0
  87. package/skills/ctx-search/SKILL.md +35 -0
  88. package/start.mjs +84 -11
  89. package/build/cache-heal.d.ts +0 -48
  90. package/build/cache-heal.js +0 -150
  91. package/build/concurrency/runPool.d.ts +0 -36
  92. package/build/concurrency/runPool.js +0 -51
  93. package/build/openclaw/mcp-tools.d.ts +0 -54
  94. package/build/openclaw/mcp-tools.js +0 -198
  95. package/build/openclaw/workspace-router.d.ts +0 -29
  96. package/build/openclaw/workspace-router.js +0 -64
  97. package/build/openclaw-plugin.d.ts +0 -130
  98. package/build/openclaw-plugin.js +0 -626
  99. package/build/opencode-plugin.d.ts +0 -122
  100. package/build/opencode-plugin.js +0 -375
  101. package/build/pi-extension.d.ts +0 -14
  102. package/build/pi-extension.js +0 -451
  103. package/build/routing-block.d.ts +0 -8
  104. package/build/routing-block.js +0 -86
  105. package/build/tool-naming.d.ts +0 -4
  106. package/build/tool-naming.js +0 -24
@@ -1,198 +0,0 @@
1
- /**
2
- * OpenClaw MCP tool registry.
3
- *
4
- * Catalogs the 11 ctx_* tools that OpenClaw plugin must register via
5
- * api.registerTool(...) so the routing block (which nudges agents toward
6
- * ctx_execute, ctx_search, etc.) actually has tools to call. Without this,
7
- * Phase 7 audit (v1.0.107-adapter-openclaw.json) flagged severity=CRITICAL —
8
- * routing-block premise is broken when the named tools don't exist.
9
- *
10
- * Pattern mirrors the swarmvault MCP plugin
11
- * (refs/plugin-examples/openclaw/swarmvault/packages/engine/src/mcp.ts:46-51):
12
- * server.registerTool(name, { description, inputSchema }, handler)
13
- *
14
- * OpenClaw signature is slightly different — see building-plugins.md:116
15
- * api.registerTool({ name, description, parameters: TypeBox, execute(id, params) })
16
- *
17
- * Tool handlers are intentionally thin shims that delegate to the bundled CLI
18
- * (cli.bundle.mjs) — same fall-through pattern already used by ctx-doctor and
19
- * ctx-upgrade slash commands. This keeps the plugin's blast radius minimal:
20
- * we don't re-export the entire MCP server stack inside OpenClaw's process.
21
- *
22
- * The 11 tools mirror src/server.ts registerTool calls (lines 897, 1226, 1371,
23
- * 1497, 2034, 2256, 2440, 2501, 2592, 2712, 2808).
24
- */
25
- /** Wrap any handler so failures become a well-formed text error rather than crashing. */
26
- function safe(handler) {
27
- return async (_id, params) => {
28
- try {
29
- return await handler(params ?? {});
30
- }
31
- catch (err) {
32
- const message = err instanceof Error ? err.message : String(err);
33
- return {
34
- content: [
35
- {
36
- type: "text",
37
- text: `[context-mode] tool error: ${message}`,
38
- },
39
- ],
40
- };
41
- }
42
- };
43
- }
44
- /** Stub handler — points users at the bundled CLI for full functionality. */
45
- function cliRedirect(toolName) {
46
- return safe(async () => ({
47
- content: [
48
- {
49
- type: "text",
50
- text: `[context-mode] ${toolName} is exposed via the bundled context-mode CLI. Run 'context-mode ${toolName}' or invoke the MCP server directly. This OpenClaw stub registers the tool name so the routing block remains valid; full execution requires the standalone MCP transport.`,
51
- },
52
- ],
53
- }));
54
- }
55
- /**
56
- * The 11 ctx_* tool definitions registered into OpenClaw via api.registerTool.
57
- * Names + descriptions mirror src/server.ts registerTool blocks 1:1 so prompts
58
- * referencing them (routing block, AGENTS.md) resolve to real callable tools.
59
- */
60
- export const OPENCLAW_TOOL_DEFS = [
61
- {
62
- name: "ctx_execute",
63
- description: "Execute code in a sandboxed subprocess. Only stdout enters context. Prefer over Bash for any command producing >20 lines.",
64
- parameters: {
65
- type: "object",
66
- properties: {
67
- language: { type: "string", description: "Runtime language" },
68
- code: { type: "string", description: "Source code to execute" },
69
- timeout: { type: "number", description: "Max execution time in ms" },
70
- },
71
- required: ["language", "code"],
72
- additionalProperties: true,
73
- },
74
- execute: cliRedirect("ctx_execute"),
75
- },
76
- {
77
- name: "ctx_execute_file",
78
- description: "Execute code with a file path. Only printed summary enters context — raw file stays in sandbox.",
79
- parameters: {
80
- type: "object",
81
- properties: {
82
- path: { type: "string", description: "File path" },
83
- language: { type: "string", description: "Runtime language" },
84
- code: { type: "string", description: "Source code" },
85
- },
86
- required: ["path", "language", "code"],
87
- additionalProperties: true,
88
- },
89
- execute: cliRedirect("ctx_execute_file"),
90
- },
91
- {
92
- name: "ctx_index",
93
- description: "Store content in the FTS5 knowledge base for later search.",
94
- parameters: {
95
- type: "object",
96
- properties: {
97
- content: { type: "string", description: "Text to index" },
98
- source: { type: "string", description: "Descriptive source label" },
99
- },
100
- required: ["content", "source"],
101
- additionalProperties: true,
102
- },
103
- execute: cliRedirect("ctx_index"),
104
- },
105
- {
106
- name: "ctx_search",
107
- description: "Query indexed content via FTS5. Pass all questions as an array in ONE call.",
108
- parameters: {
109
- type: "object",
110
- properties: {
111
- queries: { type: "array", description: "Search queries" },
112
- source: { type: "string", description: "Optional source filter" },
113
- sort: { type: "string", description: "relevance | timeline" },
114
- },
115
- additionalProperties: true,
116
- },
117
- execute: cliRedirect("ctx_search"),
118
- },
119
- {
120
- name: "ctx_fetch_and_index",
121
- description: "Fetch a URL, chunk it, and index — raw HTML never enters context.",
122
- parameters: {
123
- type: "object",
124
- properties: {
125
- url: { type: "string", description: "URL to fetch" },
126
- source: { type: "string", description: "Source label for indexed chunks" },
127
- },
128
- required: ["url"],
129
- additionalProperties: true,
130
- },
131
- execute: cliRedirect("ctx_fetch_and_index"),
132
- },
133
- {
134
- name: "ctx_batch_execute",
135
- description: "Run multiple commands and search queries in ONE call. Primary research tool — replaces 30+ individual calls.",
136
- parameters: {
137
- type: "object",
138
- properties: {
139
- commands: { type: "array", description: "Array of {label, command} objects" },
140
- queries: { type: "array", description: "Search queries to run after indexing" },
141
- },
142
- additionalProperties: true,
143
- },
144
- execute: cliRedirect("ctx_batch_execute"),
145
- },
146
- {
147
- name: "ctx_stats",
148
- description: "Show context-mode session statistics — token consumption and per-tool breakdown.",
149
- parameters: {
150
- type: "object",
151
- properties: {},
152
- additionalProperties: true,
153
- },
154
- execute: cliRedirect("ctx_stats"),
155
- },
156
- {
157
- name: "ctx_doctor",
158
- description: "Run context-mode diagnostics — runtimes, hooks, FTS5, plugin registration.",
159
- parameters: {
160
- type: "object",
161
- properties: {},
162
- additionalProperties: true,
163
- },
164
- execute: cliRedirect("ctx_doctor"),
165
- },
166
- {
167
- name: "ctx_upgrade",
168
- description: "Upgrade context-mode to the latest version.",
169
- parameters: {
170
- type: "object",
171
- properties: {},
172
- additionalProperties: true,
173
- },
174
- execute: cliRedirect("ctx_upgrade"),
175
- },
176
- {
177
- name: "ctx_purge",
178
- description: "Permanently delete all indexed content and reset session stats. Destructive.",
179
- parameters: {
180
- type: "object",
181
- properties: {},
182
- additionalProperties: true,
183
- },
184
- execute: cliRedirect("ctx_purge"),
185
- },
186
- {
187
- name: "ctx_insight",
188
- description: "Open the context-mode Insight analytics dashboard in the browser.",
189
- parameters: {
190
- type: "object",
191
- properties: {},
192
- additionalProperties: true,
193
- },
194
- execute: cliRedirect("ctx_insight"),
195
- },
196
- ];
197
- /** Stable list of tool names — used by tests and manifest validation. */
198
- export const OPENCLAW_TOOL_NAMES = OPENCLAW_TOOL_DEFS.map((def) => def.name);
@@ -1,29 +0,0 @@
1
- /**
2
- * Extract the agent workspace path from tool call params.
3
- * Looks for /openclaw/workspace-<name> patterns in cwd, file_path, and command.
4
- * Returns the workspace root (e.g. "/openclaw/workspace-trainer") or null.
5
- */
6
- export declare function extractWorkspace(params: Record<string, unknown>): string | null;
7
- /**
8
- * Maps agent workspaces to sessionIds using sessionKey convention.
9
- * sessionKey pattern: "agent:<name>:main" → workspace "/openclaw/workspace-<name>"
10
- *
11
- * Why this exists alongside per-session closures:
12
- * Each register() call creates its own closure with its own sessionId, which
13
- * naturally isolates sessions. The WorkspaceRouter acts as a safety net for
14
- * after_tool_call events where OpenClaw may deliver the event to the wrong
15
- * closure (e.g. tool calls interleaving across agents). It resolves the correct
16
- * sessionId from workspace paths in tool params, falling back to the closure
17
- * sessionId when no workspace is detected.
18
- */
19
- export declare class WorkspaceRouter {
20
- private map;
21
- /** Register a session from session_start event. */
22
- registerSession(sessionKey: string, sessionId: string): void;
23
- /** Remove a session (e.g. on command:stop). */
24
- removeSession(sessionKey: string): void;
25
- /** Resolve sessionId from tool call params. Returns null if no match. */
26
- resolveSessionId(params: Record<string, unknown>): string | null;
27
- /** Derive workspace path from sessionKey. */
28
- private workspaceFromKey;
29
- }
@@ -1,64 +0,0 @@
1
- /**
2
- * Extract the agent workspace path from tool call params.
3
- * Looks for /openclaw/workspace-<name> patterns in cwd, file_path, and command.
4
- * Returns the workspace root (e.g. "/openclaw/workspace-trainer") or null.
5
- */
6
- export function extractWorkspace(params) {
7
- // Priority: cwd > file_path > command (most specific first)
8
- const sources = [
9
- params.cwd,
10
- params.file_path,
11
- params.command,
12
- ].filter((v) => typeof v === "string");
13
- for (const src of sources) {
14
- const match = src.match(/\/openclaw\/workspace-[a-zA-Z0-9_-]+/);
15
- if (match)
16
- return match[0];
17
- }
18
- return null;
19
- }
20
- /**
21
- * Maps agent workspaces to sessionIds using sessionKey convention.
22
- * sessionKey pattern: "agent:<name>:main" → workspace "/openclaw/workspace-<name>"
23
- *
24
- * Why this exists alongside per-session closures:
25
- * Each register() call creates its own closure with its own sessionId, which
26
- * naturally isolates sessions. The WorkspaceRouter acts as a safety net for
27
- * after_tool_call events where OpenClaw may deliver the event to the wrong
28
- * closure (e.g. tool calls interleaving across agents). It resolves the correct
29
- * sessionId from workspace paths in tool params, falling back to the closure
30
- * sessionId when no workspace is detected.
31
- */
32
- export class WorkspaceRouter {
33
- // workspace path → sessionId
34
- map = new Map();
35
- /** Register a session from session_start event. */
36
- registerSession(sessionKey, sessionId) {
37
- const workspace = this.workspaceFromKey(sessionKey);
38
- if (workspace) {
39
- this.map.set(workspace, sessionId);
40
- }
41
- }
42
- /** Remove a session (e.g. on command:stop). */
43
- removeSession(sessionKey) {
44
- const workspace = this.workspaceFromKey(sessionKey);
45
- if (workspace) {
46
- this.map.delete(workspace);
47
- }
48
- }
49
- /** Resolve sessionId from tool call params. Returns null if no match. */
50
- resolveSessionId(params) {
51
- const workspace = extractWorkspace(params);
52
- if (!workspace)
53
- return null;
54
- return this.map.get(workspace) ?? null;
55
- }
56
- /** Derive workspace path from sessionKey. */
57
- workspaceFromKey(key) {
58
- // Pattern: "agent:<name>:main" or "agent:<name>:<channel>"
59
- const match = key.match(/^agent:([^:]+):/);
60
- if (!match)
61
- return null;
62
- return `/openclaw/workspace-${match[1]}`;
63
- }
64
- }
@@ -1,130 +0,0 @@
1
- /**
2
- * OpenClaw TypeScript plugin entry point for context-mode.
3
- *
4
- * Exports an object with { id, name, configSchema, register(api) } for
5
- * declarative metadata and config validation before code execution.
6
- *
7
- * register(api) registers:
8
- * - before_tool_call hook — Routing enforcement (deny/modify/passthrough)
9
- * - after_tool_call hook — Session event capture
10
- * - command:new hook — Session initialization and cleanup
11
- * - session_start hook — Re-key DB session to OpenClaw's session ID
12
- * - before_compaction hook — Flush events to resume snapshot
13
- * - after_compaction hook — Increment compact count
14
- * - before_prompt_build (p=10) — Resume snapshot injection into system context
15
- * - before_prompt_build (p=5) — Routing instruction injection into system context
16
- * - context-mode engine — Context engine with compaction management
17
- * - /ctx-stats command — Auto-reply command for session statistics
18
- * - /ctx-doctor command — Auto-reply command for diagnostics
19
- * - /ctx-upgrade command — Auto-reply command for upgrade
20
- *
21
- * Loaded by OpenClaw via: openclaw.extensions entry in package.json
22
- *
23
- * OpenClaw plugin paradigm:
24
- * - Plugins export { id, name, configSchema, register(api) } for metadata
25
- * - api.registerHook() for event-driven hooks
26
- * - api.on() for typed lifecycle hooks
27
- * - api.registerContextEngine() for compaction ownership
28
- * - api.registerCommand() for auto-reply slash commands
29
- * - Plugins run in-process with the Gateway (trusted code)
30
- */
31
- import type { OpenClawToolDef } from "./openclaw/mcp-tools.js";
32
- /** Context for auto-reply command handlers. */
33
- interface CommandContext {
34
- senderId?: string;
35
- channel?: string;
36
- isAuthorizedSender?: boolean;
37
- args?: string;
38
- commandBody?: string;
39
- config?: Record<string, unknown>;
40
- }
41
- /** OpenClaw plugin API provided to the register function. */
42
- interface OpenClawPluginApi {
43
- registerHook(event: string, handler: (...args: unknown[]) => unknown, meta: {
44
- name: string;
45
- description: string;
46
- }): void;
47
- /**
48
- * Register a typed lifecycle hook.
49
- * Supported names: "session_start", "before_compaction", "after_compaction",
50
- * "before_prompt_build"
51
- */
52
- on(event: string, handler: (...args: unknown[]) => unknown, opts?: {
53
- priority?: number;
54
- }): void;
55
- registerContextEngine(id: string, factory: () => ContextEngineInstance): void;
56
- registerCommand?(cmd: {
57
- name: string;
58
- description: string;
59
- acceptsArgs?: boolean;
60
- requireAuth?: boolean;
61
- handler: (ctx: CommandContext) => {
62
- text: string;
63
- } | Promise<{
64
- text: string;
65
- }>;
66
- }): void;
67
- registerCli?(factory: (ctx: {
68
- program: unknown;
69
- }) => void, meta: {
70
- commands: string[];
71
- }): void;
72
- /**
73
- * Register an agent tool (OpenClaw native registerTool) — see
74
- * refs/platforms/openclaw/docs/plugins/building-plugins.md:116. Optional in
75
- * the type so we degrade silently on legacy hosts that pre-date this API.
76
- */
77
- registerTool?(tool: OpenClawToolDef, opts?: {
78
- optional?: boolean;
79
- }): void;
80
- logger?: {
81
- info: (...args: unknown[]) => void;
82
- error: (...args: unknown[]) => void;
83
- debug?: (...args: unknown[]) => void;
84
- warn?: (...args: unknown[]) => void;
85
- };
86
- }
87
- /** Context engine instance returned by the factory. */
88
- interface ContextEngineInstance {
89
- info: {
90
- id: string;
91
- name: string;
92
- ownsCompaction: boolean;
93
- };
94
- ingest(data: unknown): Promise<{
95
- ingested: boolean;
96
- }>;
97
- assemble(ctx: {
98
- messages: unknown[];
99
- }): Promise<{
100
- messages: unknown[];
101
- estimatedTokens: number;
102
- }>;
103
- compact(): Promise<{
104
- ok: boolean;
105
- compacted: boolean;
106
- }>;
107
- }
108
- /**
109
- * OpenClaw plugin definition. The object form provides declarative metadata
110
- * (id, name, configSchema) that OpenClaw can read without executing code.
111
- * register() is called once per agent session with a fresh api object.
112
- * Each call creates isolated closures (db, sessionId, hooks) — no shared state.
113
- */
114
- declare const _default: {
115
- id: string;
116
- name: string;
117
- configSchema: {
118
- type: "object";
119
- properties: {
120
- enabled: {
121
- type: "boolean";
122
- default: boolean;
123
- description: string;
124
- };
125
- };
126
- additionalProperties: boolean;
127
- };
128
- register(api: OpenClawPluginApi): void;
129
- };
130
- export default _default;