@openviking/openclaw-plugin 2026.6.2 → 2026.6.17-dev.1

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 (108) hide show
  1. package/INSTALL-AGENT.md +4 -4
  2. package/INSTALL-ZH.md +68 -8
  3. package/INSTALL.md +12 -8
  4. package/README.md +45 -35
  5. package/adapters/http-transport.ts +3 -0
  6. package/adapters/resource-packager.ts +141 -0
  7. package/auto-recall.ts +258 -27
  8. package/client.ts +201 -177
  9. package/commands/setup.ts +200 -33
  10. package/config/feature-gates.json +10 -0
  11. package/config.ts +428 -85
  12. package/context-engine.ts +71 -1402
  13. package/dist/adapters/http-transport.js +1 -0
  14. package/dist/adapters/resource-packager.js +114 -0
  15. package/dist/auto-recall.js +201 -25
  16. package/dist/client.js +125 -161
  17. package/dist/commands/setup.js +170 -32
  18. package/dist/config.js +285 -64
  19. package/dist/context-engine.js +62 -1173
  20. package/dist/index.js +209 -1489
  21. package/dist/memory-ranking.js +35 -12
  22. package/dist/plugin/command-registration.js +5 -0
  23. package/dist/plugin/openviking-archive-tools.js +210 -0
  24. package/dist/plugin/openviking-bypass-runtime.js +8 -0
  25. package/dist/plugin/openviking-client-runtime.js +28 -0
  26. package/dist/plugin/openviking-command-args.js +146 -0
  27. package/dist/plugin/openviking-command-definitions.js +206 -0
  28. package/dist/plugin/openviking-context-engine-ref.js +11 -0
  29. package/dist/plugin/openviking-context-engine-registration.js +23 -0
  30. package/dist/plugin/openviking-feature-gates.js +250 -0
  31. package/dist/plugin/openviking-import-runtime.js +50 -0
  32. package/dist/plugin/openviking-import-tools.js +86 -0
  33. package/dist/plugin/openviking-lifecycle-hooks.js +33 -0
  34. package/dist/plugin/openviking-memory-recall-tools.js +233 -0
  35. package/dist/plugin/openviking-memory-tools.js +199 -0
  36. package/dist/plugin/openviking-query-config-command.js +203 -0
  37. package/dist/plugin/openviking-query-runtime.js +367 -0
  38. package/dist/plugin/openviking-query-tools.js +91 -0
  39. package/dist/plugin/openviking-recall-trace-runtime.js +387 -0
  40. package/dist/plugin/openviking-recall-trace-tools.js +38 -0
  41. package/dist/plugin/openviking-runtime-state.js +26 -0
  42. package/dist/plugin/openviking-runtime-utils.js +62 -0
  43. package/dist/plugin/openviking-services.js +20 -0
  44. package/dist/plugin/openviking-session-routing-runtime.js +61 -0
  45. package/dist/plugin/openviking-tool-result-tools.js +268 -0
  46. package/dist/plugin/recall-trace-routes.js +77 -0
  47. package/dist/plugin/tool-registration.js +23 -0
  48. package/dist/process-manager.js +1 -1
  49. package/dist/query-config.js +336 -0
  50. package/dist/recall-trace.js +309 -0
  51. package/dist/registries/recall-resource-types.js +58 -0
  52. package/dist/routing/identity-routing.js +152 -0
  53. package/dist/routing/memory-uri.js +7 -0
  54. package/dist/services/context-lifecycle-service.js +847 -0
  55. package/dist/services/context-message-adapter.js +340 -0
  56. package/dist/session-transcript-repair.js +0 -1
  57. package/dist/text-utils.js +14 -31
  58. package/index.ts +271 -1873
  59. package/install-manifest.json +10 -1
  60. package/memory-ranking.ts +46 -10
  61. package/openclaw.plugin.json +198 -36
  62. package/package.json +14 -4
  63. package/plugin/command-registration.ts +34 -0
  64. package/plugin/openviking-archive-tools.ts +301 -0
  65. package/plugin/openviking-bypass-runtime.ts +26 -0
  66. package/plugin/openviking-client-runtime.ts +74 -0
  67. package/plugin/openviking-command-args.ts +187 -0
  68. package/plugin/openviking-command-definitions.ts +294 -0
  69. package/plugin/openviking-context-engine-ref.ts +16 -0
  70. package/plugin/openviking-context-engine-registration.ts +97 -0
  71. package/plugin/openviking-feature-gates.ts +335 -0
  72. package/plugin/openviking-import-runtime.ts +105 -0
  73. package/plugin/openviking-import-tools.ts +133 -0
  74. package/plugin/openviking-lifecycle-hooks.ts +65 -0
  75. package/plugin/openviking-memory-recall-tools.ts +368 -0
  76. package/plugin/openviking-memory-tools.ts +299 -0
  77. package/plugin/openviking-query-config-command.ts +230 -0
  78. package/plugin/openviking-query-formatters.ts +108 -0
  79. package/plugin/openviking-query-runtime.ts +476 -0
  80. package/plugin/openviking-query-tools.ts +161 -0
  81. package/plugin/openviking-recall-trace-runtime.ts +482 -0
  82. package/plugin/openviking-recall-trace-tools.ts +99 -0
  83. package/plugin/openviking-runtime-state.ts +52 -0
  84. package/plugin/openviking-runtime-utils.ts +67 -0
  85. package/plugin/openviking-services.ts +49 -0
  86. package/plugin/openviking-session-routing-runtime.ts +105 -0
  87. package/plugin/openviking-tool-result-tools.ts +397 -0
  88. package/plugin/recall-trace-routes.ts +133 -0
  89. package/plugin/tool-registration.ts +51 -0
  90. package/process-manager.ts +1 -1
  91. package/query-config.ts +400 -0
  92. package/recall-trace.ts +442 -0
  93. package/registries/openviking-tools.ts +84 -0
  94. package/registries/recall-resource-types.ts +74 -0
  95. package/routing/identity-routing.ts +210 -0
  96. package/routing/memory-uri.ts +8 -0
  97. package/services/context-lifecycle-service.ts +1209 -0
  98. package/services/context-message-adapter.ts +375 -0
  99. package/services/setup/config-writer.ts +125 -0
  100. package/services/setup/exit-utils.ts +5 -0
  101. package/services/setup/package-metadata.ts +56 -0
  102. package/services/setup/probe-service.ts +143 -0
  103. package/services/setup/setup-flow.ts +306 -0
  104. package/services/setup/version-compatibility.ts +41 -0
  105. package/session-transcript-repair.ts +0 -2
  106. package/skills/install-openviking-memory/SKILL.md +123 -50
  107. package/skills/openviking-context-database/SKILL.md +286 -0
  108. package/text-utils.ts +15 -34
@@ -0,0 +1,294 @@
1
+ import type { CommandDefinition, CommandResult, PluginCommandContext } from "./command-registration.js";
2
+ import type { RecallTraceEntry, RecallTraceSource } from "../recall-trace.js";
3
+
4
+ export type OpenVikingCommandSession = {
5
+ sessionId?: string;
6
+ sessionKey?: string;
7
+ ovSessionId?: string;
8
+ agentId: string;
9
+ };
10
+
11
+ export type OpenVikingCommandToolResult = {
12
+ content: Array<{ type: "text"; text: string }>;
13
+ details?: Record<string, unknown>;
14
+ };
15
+
16
+ export type AddResourceCommandInput = {
17
+ source?: string;
18
+ to?: string;
19
+ parent?: string;
20
+ reason?: string;
21
+ instruction?: string;
22
+ wait?: boolean;
23
+ timeout?: number;
24
+ };
25
+
26
+ export type AddSkillCommandInput = {
27
+ source?: string;
28
+ data?: unknown;
29
+ wait?: boolean;
30
+ timeout?: number;
31
+ };
32
+
33
+ export type OVSearchCommandInput = {
34
+ query: string;
35
+ uri?: string;
36
+ limit?: number;
37
+ };
38
+
39
+ export type RecallTraceCommandInput = {
40
+ turn?: "latest" | "all";
41
+ traceId?: string;
42
+ sessionId?: string;
43
+ sessionKey?: string;
44
+ ovSessionId?: string;
45
+ source?: RecallTraceSource;
46
+ resourceTypes?: string;
47
+ since?: number;
48
+ until?: number;
49
+ includeContent?: boolean;
50
+ limit?: number;
51
+ };
52
+
53
+ export type RecallTraceCommandResult = {
54
+ entries: RecallTraceEntry[];
55
+ lookupLayer: string;
56
+ warnings: string[];
57
+ };
58
+
59
+ export type OpenVikingCommandDefinitionsDeps = {
60
+ resolvePluginSessionRouting: (ctx?: PluginCommandContext) => OpenVikingCommandSession;
61
+ isBypassedSession: (ctx?: PluginCommandContext) => boolean;
62
+ makeBypassedToolResult: (toolName: string) => OpenVikingCommandToolResult;
63
+ parseAddResourceCommandArgs: (args: string) => AddResourceCommandInput;
64
+ parseAddSkillCommandArgs: (args: string) => AddSkillCommandInput;
65
+ parseOVSearchCommandArgs: (args: string) => OVSearchCommandInput;
66
+ addResourceOpenViking: (input: AddResourceCommandInput, agentId?: string) => Promise<OpenVikingCommandToolResult>;
67
+ addSkillOpenViking: (input: AddSkillCommandInput, agentId?: string) => Promise<OpenVikingCommandToolResult>;
68
+ searchOpenViking: (
69
+ input: OVSearchCommandInput,
70
+ agentId?: string,
71
+ traceCtx?: OpenVikingCommandSession,
72
+ ) => Promise<OpenVikingCommandToolResult>;
73
+ handleQueryConfigCommand: (ctx: PluginCommandContext) => Promise<CommandResult>;
74
+ queryRecallTraces: (
75
+ input: RecallTraceCommandInput,
76
+ session: OpenVikingCommandSession,
77
+ ) => Promise<RecallTraceCommandResult>;
78
+ formatRecallTraceText: (result: RecallTraceCommandResult) => string;
79
+ };
80
+
81
+ function tokenizeCommandArgs(args: string): string[] {
82
+ const tokens: string[] = [];
83
+ let current = "";
84
+ let quote: "'" | '"' | null = null;
85
+ let escaping = false;
86
+
87
+ for (let i = 0; i < args.length; i += 1) {
88
+ const ch = args[i]!;
89
+ const next = args[i + 1];
90
+ if (escaping) {
91
+ current += ch;
92
+ escaping = false;
93
+ continue;
94
+ }
95
+ if (ch === "\\") {
96
+ const shouldEscape =
97
+ quote === '"'
98
+ ? next === '"' || next === "\\"
99
+ : !quote && Boolean(next && (/\s/.test(next) || next === '"' || next === "'"));
100
+ if (shouldEscape) {
101
+ escaping = true;
102
+ continue;
103
+ }
104
+ current += ch;
105
+ continue;
106
+ }
107
+ if ((ch === '"' || ch === "'") && (!quote || quote === ch)) {
108
+ quote = quote ? null : ch;
109
+ continue;
110
+ }
111
+ if (!quote && /\s/.test(ch)) {
112
+ if (current) {
113
+ tokens.push(current);
114
+ current = "";
115
+ }
116
+ continue;
117
+ }
118
+ current += ch;
119
+ }
120
+
121
+ if (escaping) {
122
+ current += "\\";
123
+ }
124
+ if (quote) {
125
+ throw new Error("Unterminated quoted argument");
126
+ }
127
+ if (current) {
128
+ tokens.push(current);
129
+ }
130
+ return tokens;
131
+ }
132
+
133
+ function parseFlagArgs(args: string): { flags: Map<string, string | boolean> } {
134
+ const tokens = tokenizeCommandArgs(args);
135
+ const flags = new Map<string, string | boolean>();
136
+
137
+ for (let i = 0; i < tokens.length; i += 1) {
138
+ const token = tokens[i]!;
139
+ if (!token.startsWith("--")) {
140
+ continue;
141
+ }
142
+ const raw = token.slice(2);
143
+ if (!raw) {
144
+ continue;
145
+ }
146
+ const eqIndex = raw.indexOf("=");
147
+ if (eqIndex >= 0) {
148
+ flags.set(raw.slice(0, eqIndex), raw.slice(eqIndex + 1));
149
+ continue;
150
+ }
151
+ const next = tokens[i + 1];
152
+ if (next && !next.startsWith("--")) {
153
+ flags.set(raw, next);
154
+ i += 1;
155
+ } else {
156
+ flags.set(raw, true);
157
+ }
158
+ }
159
+
160
+ return { flags };
161
+ }
162
+
163
+ function getStringFlag(flags: Map<string, string | boolean>, name: string): string | undefined {
164
+ const value = flags.get(name);
165
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
166
+ }
167
+
168
+ function getNumberFlag(flags: Map<string, string | boolean>, name: string): number | undefined {
169
+ const raw = getStringFlag(flags, name);
170
+ if (!raw) {
171
+ return undefined;
172
+ }
173
+ const value = Number(raw);
174
+ if (!Number.isFinite(value)) {
175
+ throw new Error(`--${name} must be a number`);
176
+ }
177
+ return value;
178
+ }
179
+
180
+ function getBoolFlag(flags: Map<string, string | boolean>, name: string): boolean {
181
+ return flags.get(name) === true;
182
+ }
183
+
184
+ function parseRecallTraceCommandArgs(args: string): RecallTraceCommandInput {
185
+ const flags = parseFlagArgs(args).flags;
186
+ return {
187
+ turn: getStringFlag(flags, "turn") as "latest" | "all" | undefined,
188
+ traceId: getStringFlag(flags, "trace-id"),
189
+ sessionId: getStringFlag(flags, "session-id"),
190
+ sessionKey: getStringFlag(flags, "session-key"),
191
+ ovSessionId: getStringFlag(flags, "ov-session-id"),
192
+ source: getStringFlag(flags, "source") as RecallTraceSource | undefined,
193
+ resourceTypes: getStringFlag(flags, "resource-types"),
194
+ since: getNumberFlag(flags, "since"),
195
+ until: getNumberFlag(flags, "until"),
196
+ includeContent: getBoolFlag(flags, "include-content"),
197
+ limit: getNumberFlag(flags, "limit"),
198
+ };
199
+ }
200
+
201
+ function toCommandResult(result: OpenVikingCommandToolResult): CommandResult {
202
+ return { text: result.content[0]!.text, details: result.details };
203
+ }
204
+
205
+ export function createOpenVikingCommandDefinitions(
206
+ deps: OpenVikingCommandDefinitionsDeps,
207
+ ): CommandDefinition[] {
208
+ return [
209
+ {
210
+ name: "add-resource",
211
+ description: "Add a resource into OpenViking.",
212
+ acceptsArgs: true,
213
+ handler: async (ctx: PluginCommandContext) => {
214
+ try {
215
+ if (deps.isBypassedSession(ctx)) {
216
+ return toCommandResult(deps.makeBypassedToolResult("add_resource"));
217
+ }
218
+ const session = deps.resolvePluginSessionRouting(ctx);
219
+ const input = deps.parseAddResourceCommandArgs(ctx.args ?? "");
220
+ return toCommandResult(await deps.addResourceOpenViking(input, session.agentId));
221
+ } catch (err) {
222
+ return { text: `OpenViking add resource failed: ${err instanceof Error ? err.message : String(err)}` };
223
+ }
224
+ },
225
+ },
226
+ {
227
+ name: "add-skill",
228
+ description: "Add a skill into OpenViking.",
229
+ acceptsArgs: true,
230
+ handler: async (ctx: PluginCommandContext) => {
231
+ try {
232
+ if (deps.isBypassedSession(ctx)) {
233
+ return toCommandResult(deps.makeBypassedToolResult("add_skill"));
234
+ }
235
+ const session = deps.resolvePluginSessionRouting(ctx);
236
+ const input = deps.parseAddSkillCommandArgs(ctx.args ?? "");
237
+ return toCommandResult(await deps.addSkillOpenViking(input, session.agentId));
238
+ } catch (err) {
239
+ return { text: `OpenViking add skill failed: ${err instanceof Error ? err.message : String(err)}` };
240
+ }
241
+ },
242
+ },
243
+ {
244
+ name: "ov-search",
245
+ description: "Search OpenViking resources and skills.",
246
+ acceptsArgs: true,
247
+ handler: async (ctx: PluginCommandContext) => {
248
+ try {
249
+ if (deps.isBypassedSession(ctx)) {
250
+ return toCommandResult(deps.makeBypassedToolResult("ov_search"));
251
+ }
252
+ const session = deps.resolvePluginSessionRouting(ctx);
253
+ const input = deps.parseOVSearchCommandArgs(ctx.args ?? "");
254
+ return toCommandResult(await deps.searchOpenViking(input, session.agentId, session));
255
+ } catch (err) {
256
+ return { text: `OpenViking search failed: ${err instanceof Error ? err.message : String(err)}` };
257
+ }
258
+ },
259
+ },
260
+ {
261
+ name: "ov-query-config",
262
+ description: "Get or set runtime OpenViking query parameters for the current claw/session.",
263
+ acceptsArgs: true,
264
+ handler: async (ctx: PluginCommandContext) => {
265
+ try {
266
+ return await deps.handleQueryConfigCommand(ctx);
267
+ } catch (err) {
268
+ return { text: `OpenViking query config failed: ${err instanceof Error ? err.message : String(err)}` };
269
+ }
270
+ },
271
+ },
272
+ {
273
+ name: "ov-recall-trace",
274
+ description: "Query OpenViking recall trace records.",
275
+ acceptsArgs: true,
276
+ handler: async (ctx: PluginCommandContext) => {
277
+ try {
278
+ if (deps.isBypassedSession(ctx)) {
279
+ return toCommandResult(deps.makeBypassedToolResult("ov_recall_trace"));
280
+ }
281
+ const session = deps.resolvePluginSessionRouting(ctx);
282
+ const input = parseRecallTraceCommandArgs(ctx.args ?? "");
283
+ const result = await deps.queryRecallTraces(input, session);
284
+ return {
285
+ text: deps.formatRecallTraceText(result),
286
+ details: { count: result.entries.length, lookupLayer: result.lookupLayer, warnings: result.warnings, entries: result.entries },
287
+ };
288
+ } catch (err) {
289
+ return { text: `OpenViking recall trace query failed: ${err instanceof Error ? err.message : String(err)}` };
290
+ }
291
+ },
292
+ },
293
+ ];
294
+ }
@@ -0,0 +1,16 @@
1
+ import type { ContextEngineWithCommit } from "../context-engine.js";
2
+
3
+ export function createOpenVikingContextEngineRef() {
4
+ let contextEngineRef: ContextEngineWithCommit | null = null;
5
+
6
+ const getContextEngine = (): ContextEngineWithCommit | null => contextEngineRef;
7
+
8
+ const setContextEngineRef = (engine: ContextEngineWithCommit): void => {
9
+ contextEngineRef = engine;
10
+ };
11
+
12
+ return {
13
+ getContextEngine,
14
+ setContextEngineRef,
15
+ };
16
+ }
@@ -0,0 +1,97 @@
1
+ export type OpenVikingContextEngineRegistrationApi = {
2
+ registerContextEngine?: (id: string, factory: () => unknown) => void;
3
+ };
4
+
5
+ export type OpenVikingContextEngineLogger = {
6
+ info: (message: string) => void;
7
+ warn: (message: string) => void;
8
+ };
9
+
10
+ export type OpenVikingContextEnginePluginInfo = {
11
+ id: string;
12
+ name: string;
13
+ };
14
+
15
+ export type OpenVikingContextEngineCreateParams<
16
+ TCfg = unknown,
17
+ TClient = unknown,
18
+ TQueryConfigStore = unknown,
19
+ TTraceRecorder = unknown,
20
+ TLogger extends OpenVikingContextEngineLogger = OpenVikingContextEngineLogger,
21
+ > = {
22
+ id: string;
23
+ name: string;
24
+ version: string;
25
+ cfg: TCfg;
26
+ logger: TLogger;
27
+ getClient: () => Promise<TClient>;
28
+ resolveAgentId: (sessionId: string, sessionKey?: string, ovSessionId?: string) => string;
29
+ rememberSessionAgentId: (ctx: {
30
+ agentId?: string;
31
+ sessionId?: string;
32
+ sessionKey?: string;
33
+ ovSessionId?: string;
34
+ }) => void;
35
+ queryConfigStore: TQueryConfigStore;
36
+ traceRecorder: TTraceRecorder;
37
+ };
38
+
39
+ export type OpenVikingContextEngineRegistrationDeps<
40
+ TEngine,
41
+ TCfg = unknown,
42
+ TClient = unknown,
43
+ TQueryConfigStore = unknown,
44
+ TTraceRecorder = unknown,
45
+ TLogger extends OpenVikingContextEngineLogger = OpenVikingContextEngineLogger,
46
+ > = {
47
+ api: OpenVikingContextEngineRegistrationApi;
48
+ plugin: OpenVikingContextEnginePluginInfo;
49
+ version: string;
50
+ cfg: TCfg;
51
+ logger: TLogger;
52
+ getClient: () => Promise<TClient>;
53
+ resolveAgentId: (sessionId: string, sessionKey?: string, ovSessionId?: string) => string;
54
+ rememberSessionAgentId: OpenVikingContextEngineCreateParams["rememberSessionAgentId"];
55
+ queryConfigStore: TQueryConfigStore;
56
+ traceRecorder: TTraceRecorder;
57
+ createContextEngine: (params: OpenVikingContextEngineCreateParams<TCfg, TClient, TQueryConfigStore, TTraceRecorder, TLogger>) => TEngine;
58
+ setContextEngineRef: (engine: TEngine) => void;
59
+ };
60
+
61
+ export function registerOpenVikingContextEngine<
62
+ TEngine,
63
+ TCfg,
64
+ TClient,
65
+ TQueryConfigStore,
66
+ TTraceRecorder,
67
+ TLogger extends OpenVikingContextEngineLogger,
68
+ >(
69
+ deps: OpenVikingContextEngineRegistrationDeps<TEngine, TCfg, TClient, TQueryConfigStore, TTraceRecorder, TLogger>,
70
+ ): void {
71
+ if (typeof deps.api.registerContextEngine !== "function") {
72
+ deps.logger.warn(
73
+ "openviking: registerContextEngine is unavailable; context-engine behavior will not run",
74
+ );
75
+ return;
76
+ }
77
+
78
+ deps.api.registerContextEngine(deps.plugin.id, () => {
79
+ const contextEngine = deps.createContextEngine({
80
+ id: deps.plugin.id,
81
+ name: deps.plugin.name,
82
+ version: deps.version,
83
+ cfg: deps.cfg,
84
+ logger: deps.logger,
85
+ getClient: deps.getClient,
86
+ resolveAgentId: deps.resolveAgentId,
87
+ rememberSessionAgentId: deps.rememberSessionAgentId,
88
+ queryConfigStore: deps.queryConfigStore,
89
+ traceRecorder: deps.traceRecorder,
90
+ });
91
+ deps.setContextEngineRef(contextEngine);
92
+ return contextEngine;
93
+ });
94
+ deps.logger.info(
95
+ "openviking: registered context-engine (assemble=archive+active+auto-recall, afterTurn=auto-capture, session→OV id=uuid-or-sha256 + diag/Phase2 options)",
96
+ );
97
+ }