@sage-protocol/openclaw-sage 0.1.9 → 0.1.10

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/README.md CHANGED
@@ -6,14 +6,14 @@ MCP bridge plugin that exposes Sage Protocol tools inside OpenClaw via Code Mode
6
6
 
7
7
  - **Code Mode Gateway** - Spawns `sage mcp start` and routes plugin calls through `sage_search`/`sage_execute`/`sage_status`
8
8
  - **Agent Profile (Identity Context)** - Injects wallet, active libraries, and skill counts into every turn so the agent knows who it's working for
9
- - **Auto-Context Injection** - Injects Sage tool context and skill suggestions via `before_prompt_build` (stable context cacheable by providers) with `before_agent_start` legacy fallback
9
+ - **Auto-Context Injection** - Injects Sage tool context and skill suggestions via `before_prompt_build` with stable context cached separately from per-turn dynamic context
10
10
  - **Injection Guard** - Optional prompt-injection scanning on outgoing `sage_execute` mutations
11
11
  - **Crash Recovery** - Automatically restarts the MCP subprocess on unexpected exits
12
12
  - **External Servers** - Sage internal tools are available immediately; only external MCP tools require starting servers first via the Sage app, CLI, or raw MCP `hub_*` tools
13
13
 
14
14
  ## Agent Profile (Identity Context)
15
15
 
16
- Every OpenClaw session automatically gets Sage Protocol identity context injected via the `before_prompt_build` hook (with `before_agent_start` legacy fallback). Stable context (protocol description, identity, tool docs) goes in `prependSystemContext` so providers can cache it across turns. Dynamic content (skill suggestions, security guard) goes in `prependContext` and refreshes each turn.
16
+ Every OpenClaw session automatically gets Sage Protocol identity context injected via the `before_prompt_build` hook. Stable context (protocol description, identity, tool docs) goes in `prependSystemContext` so providers can cache it across turns. Dynamic content (skill suggestions, security guard) goes in `prependContext` and refreshes each turn.
17
17
 
18
18
  Example of what gets injected:
19
19
 
@@ -52,6 +52,9 @@ openclaw plugins install @sage-protocol/openclaw-sage
52
52
 
53
53
  After install, **restart the Gateway** for the plugin to take effect.
54
54
 
55
+ CI validates the packed tarball against the latest published `openclaw` CLI by running
56
+ `npx openclaw@latest plugins install` in an isolated `OPENCLAW_HOME`.
57
+
55
58
  ### Verify
56
59
 
57
60
  ```bash
@@ -159,7 +162,7 @@ sage bounties create --mode direct --assignee 0x... --title "Task" --description
159
162
 
160
163
  ### Auto-Inject / Auto-Suggest
161
164
 
162
- This plugin uses OpenClaw's plugin hook API to inject context at the start of each agent run (`before_agent_start`).
165
+ This plugin uses OpenClaw's plugin hook API to inject context at the start of each prompt build via `before_prompt_build`.
163
166
 
164
167
  Available config fields:
165
168
 
@@ -0,0 +1,79 @@
1
+ import { type TSchema } from "@sinclair/typebox";
2
+ /**
3
+ * Minimal type stubs for OpenClaw plugin API.
4
+ *
5
+ * OpenClaw's jiti runtime resolves "openclaw/plugin-sdk" at load time.
6
+ * These stubs keep the code compilable standalone.
7
+ */
8
+ type PluginLogger = {
9
+ info: (msg: string) => void;
10
+ warn: (msg: string) => void;
11
+ error: (msg: string) => void;
12
+ };
13
+ type PluginServiceContext = {
14
+ config: unknown;
15
+ workspaceDir?: string;
16
+ stateDir: string;
17
+ logger: PluginLogger;
18
+ };
19
+ type PluginApi = {
20
+ id: string;
21
+ name: string;
22
+ logger: PluginLogger;
23
+ pluginConfig?: Record<string, unknown>;
24
+ registerTool: (tool: unknown, opts?: {
25
+ name?: string;
26
+ optional?: boolean;
27
+ }) => void;
28
+ registerService: (service: {
29
+ id: string;
30
+ start: (ctx: PluginServiceContext) => void | Promise<void>;
31
+ stop?: (ctx: PluginServiceContext) => void | Promise<void>;
32
+ }) => void;
33
+ on: (hook: string, handler: (...args: unknown[]) => unknown | Promise<unknown>, opts?: {
34
+ priority?: number;
35
+ }) => void;
36
+ };
37
+ declare function normalizePrompt(prompt: string, opts?: {
38
+ maxBytes?: number;
39
+ }): string;
40
+ declare function extractJsonFromMcpResult(result: unknown): unknown;
41
+ type SkillSearchResult = {
42
+ key?: string;
43
+ name?: string;
44
+ description?: string;
45
+ source?: string;
46
+ library?: string;
47
+ mcpServers?: string[];
48
+ };
49
+ declare function formatSkillSuggestions(results: SkillSearchResult[], limit: number): string;
50
+ /**
51
+ * Convert a single MCP JSON Schema property into a TypeBox type.
52
+ * Handles nested objects, typed arrays, and enums.
53
+ */
54
+ declare function jsonSchemaToTypebox(prop: Record<string, unknown>): TSchema;
55
+ /**
56
+ * Convert an MCP JSON Schema inputSchema into a TypeBox object schema
57
+ * that OpenClaw's tool system accepts.
58
+ */
59
+ declare function mcpSchemaToTypebox(inputSchema?: Record<string, unknown>): import("@sinclair/typebox").TObject<{}>;
60
+ declare const plugin: {
61
+ id: string;
62
+ name: string;
63
+ version: string;
64
+ description: string;
65
+ register(api: PluginApi): void;
66
+ };
67
+ /** Map common error patterns to actionable hints */
68
+ declare function enrichErrorMessage(err: Error, toolName: string): string;
69
+ export default plugin;
70
+ export declare const __test: {
71
+ PKG_VERSION: string;
72
+ SAGE_CONTEXT: string;
73
+ normalizePrompt: typeof normalizePrompt;
74
+ extractJsonFromMcpResult: typeof extractJsonFromMcpResult;
75
+ formatSkillSuggestions: typeof formatSkillSuggestions;
76
+ mcpSchemaToTypebox: typeof mcpSchemaToTypebox;
77
+ jsonSchemaToTypebox: typeof jsonSchemaToTypebox;
78
+ enrichErrorMessage: typeof enrichErrorMessage;
79
+ };