context-mode 1.0.141 → 1.0.142
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 +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.openclaw-plugin/openclaw.plugin.json +1 -1
- package/.openclaw-plugin/package.json +1 -1
- package/build/adapters/opencode/plugin.js +5 -20
- package/build/adapters/opencode/zod3tov4.d.ts +1 -0
- package/build/adapters/opencode/zod3tov4.js +111 -0
- package/cli.bundle.mjs +2 -2
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/server.bundle.mjs +2 -2
- package/start.mjs +40 -9
- package/build/openclaw-plugin.d.ts +0 -130
- package/build/openclaw-plugin.js +0 -626
- package/build/opencode-plugin.d.ts +0 -122
- package/build/opencode-plugin.js +0 -372
- package/build/pi-extension.d.ts +0 -14
- package/build/pi-extension.js +0 -451
- package/build/util/db-lock.d.ts +0 -65
- package/build/util/db-lock.js +0 -166
package/start.mjs
CHANGED
|
@@ -364,16 +364,47 @@ if (!process.env.VITEST) {
|
|
|
364
364
|
// Ensure native dependencies + ABI compatibility (shared with hooks via ensure-deps.mjs)
|
|
365
365
|
// ensure-deps handles better-sqlite3 install + ABI cache/rebuild automatically (#148, #203)
|
|
366
366
|
import "./hooks/ensure-deps.mjs";
|
|
367
|
-
//
|
|
368
|
-
|
|
369
|
-
|
|
367
|
+
// Pure-JS runtime deps used only by `ctx_fetch_and_index` (HTML → Markdown
|
|
368
|
+
// pipeline runs in a sandboxed subprocess that `require.resolve()`s these at
|
|
369
|
+
// call time). Plugin distributions that bypass `npm install` — most notably
|
|
370
|
+
// codex's marketplace, which git-clones into `~/.codex/plugins/cache/<pkg>/`
|
|
371
|
+
// without installing dependencies — land here with no `node_modules/`.
|
|
372
|
+
//
|
|
373
|
+
// Before #634: synchronous `execSync("npm install …")` per package
|
|
374
|
+
// (turndown + turndown-plugin-gfm + @mixmark-io/domino) blocked MCP boot
|
|
375
|
+
// for ~15–25s cold. Codex's per-MCP `startup_timeout_sec` is 30s, so on
|
|
376
|
+
// any host where its prewarm + DNS already eats a few seconds the timer
|
|
377
|
+
// fires before context-mode replies to `initialize` and the MCP child is
|
|
378
|
+
// dropped with "MCP client for `context-mode` timed out after 30 seconds".
|
|
379
|
+
//
|
|
380
|
+
// Fix: spawn each `npm install` detached + unref'd so it runs in the
|
|
381
|
+
// background while the MCP server proceeds with its handshake. The deps
|
|
382
|
+
// land asynchronously, well before any LLM-driven `ctx_fetch_and_index`
|
|
383
|
+
// call can plausibly fire. If a user invokes that tool faster than the
|
|
384
|
+
// install completes, the subprocess's own `require.resolve("turndown")`
|
|
385
|
+
// failure surfaces a typed error to the caller — same posture as any
|
|
386
|
+
// other missing-runtime-dep situation in that code path.
|
|
387
|
+
{
|
|
388
|
+
const NPM_INSTALL_BG_PKGS = ["turndown", "turndown-plugin-gfm", "@mixmark-io/domino"];
|
|
389
|
+
const IS_WIN32 = process.platform === "win32";
|
|
390
|
+
const NPM_BIN = IS_WIN32 ? "npm.cmd" : "npm";
|
|
391
|
+
for (const pkg of NPM_INSTALL_BG_PKGS) {
|
|
392
|
+
if (existsSync(resolve(__dirname, "node_modules", pkg))) continue;
|
|
370
393
|
try {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
394
|
+
const child = spawn(
|
|
395
|
+
NPM_BIN,
|
|
396
|
+
["install", pkg, "--no-package-lock", "--no-save", "--silent", "--no-audit", "--no-fund"],
|
|
397
|
+
{
|
|
398
|
+
cwd: __dirname,
|
|
399
|
+
stdio: "ignore",
|
|
400
|
+
detached: true,
|
|
401
|
+
// npm on Windows ships as a `.cmd` shim — must go through cmd.exe.
|
|
402
|
+
shell: IS_WIN32,
|
|
403
|
+
},
|
|
404
|
+
);
|
|
405
|
+
child.on("error", () => { /* best effort — npm missing, broken cache, etc. */ });
|
|
406
|
+
child.unref();
|
|
407
|
+
} catch { /* best effort — never block MCP boot */ }
|
|
377
408
|
}
|
|
378
409
|
}
|
|
379
410
|
|
|
@@ -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;
|