context-mode 1.0.167 → 1.0.169

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 (39) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.codex-plugin/plugin.json +1 -1
  4. package/.openclaw-plugin/openclaw.plugin.json +1 -1
  5. package/.openclaw-plugin/package.json +1 -1
  6. package/build/server.js +26 -5
  7. package/build/session/analytics.d.ts +28 -0
  8. package/build/session/analytics.js +82 -1
  9. package/build/session/extract.d.ts +16 -0
  10. package/build/session/extract.js +44 -28
  11. package/build/session/retrieval-marker.d.ts +39 -0
  12. package/build/session/retrieval-marker.js +65 -0
  13. package/cli.bundle.mjs +224 -216
  14. package/configs/antigravity-cli/plugin.json +1 -1
  15. package/configs/copilot-cli/.github/plugin/plugin.json +1 -1
  16. package/hooks/posttooluse.mjs +39 -1
  17. package/hooks/session-extract.bundle.mjs +3 -3
  18. package/hooks/session-loaders.mjs +8 -1
  19. package/openclaw.plugin.json +1 -1
  20. package/package.json +1 -1
  21. package/server.bundle.mjs +138 -130
  22. package/build/cache-heal.d.ts +0 -48
  23. package/build/cache-heal.js +0 -150
  24. package/build/concurrency/runPool.d.ts +0 -36
  25. package/build/concurrency/runPool.js +0 -51
  26. package/build/openclaw/mcp-tools.d.ts +0 -54
  27. package/build/openclaw/mcp-tools.js +0 -198
  28. package/build/openclaw/workspace-router.d.ts +0 -29
  29. package/build/openclaw/workspace-router.js +0 -64
  30. package/build/openclaw-plugin.d.ts +0 -130
  31. package/build/openclaw-plugin.js +0 -626
  32. package/build/opencode-plugin.d.ts +0 -122
  33. package/build/opencode-plugin.js +0 -375
  34. package/build/pi-extension.d.ts +0 -14
  35. package/build/pi-extension.js +0 -451
  36. package/build/routing-block.d.ts +0 -8
  37. package/build/routing-block.js +0 -86
  38. package/build/tool-naming.d.ts +0 -4
  39. package/build/tool-naming.js +0 -24
@@ -1,48 +0,0 @@
1
- /**
2
- * Plugin cache self-heal — fixes broken CLAUDE_PLUGIN_ROOT references.
3
- *
4
- * Claude Code's plugin auto-update can leave installed_plugins.json pointing
5
- * to a non-existent directory (anthropics/claude-code#46915). This module
6
- * detects and repairs the mismatch by creating symlinks.
7
- *
8
- * 4-layer defense:
9
- * 1. start.mjs startup — reverse heal (registry → symlink to us)
10
- * 2. server.ts first tool call — mid-session heal
11
- * 3. postinstall.mjs — backward symlink on new install
12
- * 4. global hook auto-deploy — survives total plugin cache breakage
13
- */
14
- export interface HealResult {
15
- healed: boolean;
16
- action?: "symlink" | "global-hook" | "none";
17
- from?: string;
18
- to?: string;
19
- }
20
- /**
21
- * Core heal: if installed_plugins.json points to a non-existent directory,
22
- * create a symlink from that path to our actual directory.
23
- *
24
- * @param currentDir - The directory we're actually running from
25
- * @param installedPluginsPath - Path to installed_plugins.json (injectable for testing)
26
- */
27
- export declare function healRegistryMismatch(currentDir: string, installedPluginsPath?: string): HealResult;
28
- /**
29
- * Deploy a global SessionStart hook that heals plugin cache mismatches.
30
- * This hook lives outside the plugin directory, so it survives cache breakage.
31
- *
32
- * Written to ~/.claude/hooks/context-mode-cache-heal.sh
33
- */
34
- export declare function deployGlobalHealHook(): HealResult;
35
- /**
36
- * Backward symlink: during postinstall, if the registry points to a
37
- * non-existent OLD path, create a symlink from old → new (our directory).
38
- * Same as healRegistryMismatch but called from postinstall context.
39
- */
40
- export { healRegistryMismatch as healBackwardCompat };
41
- /**
42
- * Mid-session heal — call on first MCP tool invocation.
43
- * Checks if registry path differs from our running directory.
44
- * Creates symlink if needed. Runs only once per process.
45
- */
46
- export declare function healMidSession(currentDir: string): HealResult;
47
- /** Reset mid-session flag (for testing only) */
48
- export declare function _resetMidSession(): void;
@@ -1,150 +0,0 @@
1
- /**
2
- * Plugin cache self-heal — fixes broken CLAUDE_PLUGIN_ROOT references.
3
- *
4
- * Claude Code's plugin auto-update can leave installed_plugins.json pointing
5
- * to a non-existent directory (anthropics/claude-code#46915). This module
6
- * detects and repairs the mismatch by creating symlinks.
7
- *
8
- * 4-layer defense:
9
- * 1. start.mjs startup — reverse heal (registry → symlink to us)
10
- * 2. server.ts first tool call — mid-session heal
11
- * 3. postinstall.mjs — backward symlink on new install
12
- * 4. global hook auto-deploy — survives total plugin cache breakage
13
- */
14
- import { existsSync, readFileSync, symlinkSync, mkdirSync, writeFileSync } from "node:fs";
15
- import { resolve, dirname } from "node:path";
16
- import { homedir } from "node:os";
17
- /**
18
- * Core heal: if installed_plugins.json points to a non-existent directory,
19
- * create a symlink from that path to our actual directory.
20
- *
21
- * @param currentDir - The directory we're actually running from
22
- * @param installedPluginsPath - Path to installed_plugins.json (injectable for testing)
23
- */
24
- export function healRegistryMismatch(currentDir, installedPluginsPath) {
25
- const ipPath = installedPluginsPath ?? resolve(homedir(), ".claude", "plugins", "installed_plugins.json");
26
- if (!existsSync(ipPath))
27
- return { healed: false, action: "none" };
28
- if (!existsSync(currentDir))
29
- return { healed: false, action: "none" };
30
- let ip;
31
- try {
32
- ip = JSON.parse(readFileSync(ipPath, "utf-8"));
33
- }
34
- catch {
35
- return { healed: false, action: "none" };
36
- }
37
- for (const [key, entries] of Object.entries(ip.plugins ?? {})) {
38
- if (!key.toLowerCase().includes("context-mode"))
39
- continue;
40
- for (const entry of entries) {
41
- const registryPath = entry.installPath;
42
- if (!registryPath)
43
- continue;
44
- // Registry path exists — no healing needed
45
- if (existsSync(registryPath))
46
- continue;
47
- // Registry path doesn't exist — create symlink to our directory
48
- try {
49
- const parent = dirname(registryPath);
50
- if (!existsSync(parent))
51
- mkdirSync(parent, { recursive: true });
52
- if (process.platform === "win32") {
53
- // Windows: use junction (no admin required)
54
- symlinkSync(currentDir, registryPath, "junction");
55
- }
56
- else {
57
- symlinkSync(currentDir, registryPath);
58
- }
59
- return { healed: true, action: "symlink", from: registryPath, to: currentDir };
60
- }
61
- catch {
62
- return { healed: false, action: "none" };
63
- }
64
- }
65
- }
66
- return { healed: false, action: "none" };
67
- }
68
- /**
69
- * Deploy a global SessionStart hook that heals plugin cache mismatches.
70
- * This hook lives outside the plugin directory, so it survives cache breakage.
71
- *
72
- * Written to ~/.claude/hooks/context-mode-cache-heal.sh
73
- */
74
- export function deployGlobalHealHook() {
75
- const hooksDir = resolve(homedir(), ".claude", "hooks");
76
- const hookPath = resolve(hooksDir, "context-mode-cache-heal.sh");
77
- // Already deployed
78
- if (existsSync(hookPath))
79
- return { healed: false, action: "none" };
80
- try {
81
- if (!existsSync(hooksDir))
82
- mkdirSync(hooksDir, { recursive: true });
83
- const script = `#!/usr/bin/env bash
84
- # context-mode plugin cache self-heal — auto-deployed by context-mode MCP server
85
- # Fixes anthropics/claude-code#46915: auto-update breaks CLAUDE_PLUGIN_ROOT
86
- # This hook runs at SessionStart (global, not plugin-level) so it works even
87
- # when the plugin cache is broken.
88
-
89
- set -euo pipefail
90
-
91
- PLUGINS_FILE="$HOME/.claude/plugins/installed_plugins.json"
92
- [[ -f "$PLUGINS_FILE" ]] || exit 0
93
-
94
- # Find context-mode entries and heal missing directories
95
- node -e '
96
- const fs = require("fs");
97
- const path = require("path");
98
- try {
99
- const ip = JSON.parse(fs.readFileSync(process.argv[1], "utf-8"));
100
- for (const [key, entries] of Object.entries(ip.plugins || {})) {
101
- if (!key.toLowerCase().includes("context-mode")) continue;
102
- for (const entry of entries) {
103
- const p = entry.installPath;
104
- if (!p || fs.existsSync(p)) continue;
105
- const parent = path.dirname(p);
106
- if (!fs.existsSync(parent)) continue;
107
- const dirs = fs.readdirSync(parent).filter(d => /^\\d+\\.\\d+/.test(d) && fs.statSync(path.join(parent, d)).isDirectory());
108
- if (dirs.length === 0) continue;
109
- dirs.sort((a, b) => {
110
- const pa = a.split(".").map(Number), pb = b.split(".").map(Number);
111
- for (let i = 0; i < 3; i++) { if ((pa[i]||0) !== (pb[i]||0)) return (pa[i]||0) - (pb[i]||0); }
112
- return 0;
113
- });
114
- const target = path.join(parent, dirs[dirs.length - 1]);
115
- try { fs.symlinkSync(target, p); } catch {}
116
- }
117
- }
118
- } catch {}
119
- ' "$PLUGINS_FILE" 2>/dev/null || true
120
- `;
121
- writeFileSync(hookPath, script, { mode: 0o755 });
122
- return { healed: true, action: "global-hook", from: hookPath };
123
- }
124
- catch {
125
- return { healed: false, action: "none" };
126
- }
127
- }
128
- /**
129
- * Backward symlink: during postinstall, if the registry points to a
130
- * non-existent OLD path, create a symlink from old → new (our directory).
131
- * Same as healRegistryMismatch but called from postinstall context.
132
- */
133
- export { healRegistryMismatch as healBackwardCompat };
134
- /** One-shot flag for mid-session heal in server.ts */
135
- let _midSessionHealed = false;
136
- /**
137
- * Mid-session heal — call on first MCP tool invocation.
138
- * Checks if registry path differs from our running directory.
139
- * Creates symlink if needed. Runs only once per process.
140
- */
141
- export function healMidSession(currentDir) {
142
- if (_midSessionHealed)
143
- return { healed: false, action: "none" };
144
- _midSessionHealed = true;
145
- return healRegistryMismatch(currentDir);
146
- }
147
- /** Reset mid-session flag (for testing only) */
148
- export function _resetMidSession() {
149
- _midSessionHealed = false;
150
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * Generic in-flight-capped worker pool.
3
- *
4
- * Used by:
5
- * - runBatchCommands (ctx_batch_execute parallel branch)
6
- * - runBatchFetch (ctx_fetch_and_index batch path)
7
- *
8
- * Returns Promise.allSettled-style results so one job's throw cannot
9
- * strand siblings. Caller maps fulfilled/rejected per index. Output
10
- * order is preserved by input index (not completion order).
11
- *
12
- * Designed to be the SINGLE concurrency primitive for the project —
13
- * all "run N independent operations with at most M in flight" needs
14
- * route here. Avoids the worker-pool copy-paste flagged in the
15
- * concurrency PRD architectural review (finding G).
16
- */
17
- export interface PoolJob<T> {
18
- run(): Promise<T>;
19
- }
20
- export interface RunPoolOptions {
21
- /** Hard concurrency cap (1-N). Auto-clamped to job count. */
22
- concurrency: number;
23
- /** Optional: also clamp by `os.cpus().length` (memory-pressure safety). Default false. */
24
- capByCpuCount?: boolean;
25
- /** Optional: per-settled callback (e.g. for progress reporting / metrics). */
26
- onSettled?: (idx: number, result: PromiseSettledResult<unknown>) => void;
27
- }
28
- export interface RunPoolResult<T> {
29
- /** Per-index settled result, ordered by input index. */
30
- settled: PromiseSettledResult<T>[];
31
- /** Concurrency actually used after all caps applied. */
32
- effectiveConcurrency: number;
33
- /** True when effectiveConcurrency < requested concurrency. */
34
- capped: boolean;
35
- }
36
- export declare function runPool<T>(jobs: PoolJob<T>[], opts: RunPoolOptions): Promise<RunPoolResult<T>>;
@@ -1,51 +0,0 @@
1
- /**
2
- * Generic in-flight-capped worker pool.
3
- *
4
- * Used by:
5
- * - runBatchCommands (ctx_batch_execute parallel branch)
6
- * - runBatchFetch (ctx_fetch_and_index batch path)
7
- *
8
- * Returns Promise.allSettled-style results so one job's throw cannot
9
- * strand siblings. Caller maps fulfilled/rejected per index. Output
10
- * order is preserved by input index (not completion order).
11
- *
12
- * Designed to be the SINGLE concurrency primitive for the project —
13
- * all "run N independent operations with at most M in flight" needs
14
- * route here. Avoids the worker-pool copy-paste flagged in the
15
- * concurrency PRD architectural review (finding G).
16
- */
17
- import { cpus } from "node:os";
18
- export async function runPool(jobs, opts) {
19
- const { concurrency, capByCpuCount = false, onSettled } = opts;
20
- if (jobs.length === 0) {
21
- return { settled: [], effectiveConcurrency: 0, capped: false };
22
- }
23
- const requested = Math.max(1, concurrency);
24
- const cpuCap = capByCpuCount ? Math.max(1, cpus().length) : requested;
25
- const effectiveConcurrency = Math.min(requested, cpuCap, jobs.length);
26
- const capped = effectiveConcurrency < requested;
27
- const settled = new Array(jobs.length);
28
- let nextIdx = 0;
29
- async function worker() {
30
- while (true) {
31
- const idx = nextIdx++;
32
- if (idx >= jobs.length)
33
- return;
34
- try {
35
- const value = await jobs[idx].run();
36
- settled[idx] = { status: "fulfilled", value };
37
- }
38
- catch (err) {
39
- settled[idx] = { status: "rejected", reason: err };
40
- }
41
- onSettled?.(idx, settled[idx]);
42
- }
43
- }
44
- const workers = [];
45
- for (let w = 0; w < effectiveConcurrency; w++)
46
- workers.push(worker());
47
- // allSettled defends against any promise rejection escaping a worker
48
- // (the worker already swallows its own errors, but this is belt-and-braces).
49
- await Promise.allSettled(workers);
50
- return { settled, effectiveConcurrency, capped };
51
- }
@@ -1,54 +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
- /** Minimal JSON-schema-like parameter spec accepted by OpenClaw registerTool. */
26
- export interface OpenClawToolParameters {
27
- type: "object";
28
- properties: Record<string, {
29
- type: string;
30
- description?: string;
31
- }>;
32
- required?: string[];
33
- additionalProperties?: boolean;
34
- }
35
- /** Tool definition shape returned to OpenClaw via api.registerTool. */
36
- export interface OpenClawToolDef {
37
- name: string;
38
- description: string;
39
- parameters: OpenClawToolParameters;
40
- execute: (id: string, params: Record<string, unknown>) => Promise<{
41
- content: Array<{
42
- type: "text";
43
- text: string;
44
- }>;
45
- }>;
46
- }
47
- /**
48
- * The 11 ctx_* tool definitions registered into OpenClaw via api.registerTool.
49
- * Names + descriptions mirror src/server.ts registerTool blocks 1:1 so prompts
50
- * referencing them (routing block, AGENTS.md) resolve to real callable tools.
51
- */
52
- export declare const OPENCLAW_TOOL_DEFS: readonly OpenClawToolDef[];
53
- /** Stable list of tool names — used by tests and manifest validation. */
54
- export declare const OPENCLAW_TOOL_NAMES: readonly string[];
@@ -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
- }