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

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,152 @@
1
+ import { createHash } from "node:crypto";
2
+ const DEFAULT_OPENCLAW_AGENT_ID = "main";
3
+ /** OpenClaw session UUID (path-safe on Windows). */
4
+ const OPENVIKING_OV_SESSION_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
5
+ const WINDOWS_BAD_SESSION_SEGMENT = /[:<>"\\/|?\u0000-\u001f]/;
6
+ /**
7
+ * Map OpenClaw session identity to an OpenViking session_id that is safe as a single
8
+ * AGFS path segment on Windows (no `:` etc.). Prefer UUID sessionId when present;
9
+ * otherwise derive a stable sha256 from sessionKey.
10
+ */
11
+ export function openClawSessionToOvStorageId(sessionId, sessionKey) {
12
+ const sid = typeof sessionId === "string" ? sessionId.trim() : "";
13
+ const key = typeof sessionKey === "string" ? sessionKey.trim() : "";
14
+ if (sid && OPENVIKING_OV_SESSION_UUID.test(sid)) {
15
+ return sid.toLowerCase();
16
+ }
17
+ if (key) {
18
+ return createHash("sha256").update(key, "utf8").digest("hex");
19
+ }
20
+ if (sid) {
21
+ if (WINDOWS_BAD_SESSION_SEGMENT.test(sid)) {
22
+ return createHash("sha256").update(`openclaw-session:${sid}`, "utf8").digest("hex");
23
+ }
24
+ return sid;
25
+ }
26
+ throw new Error("openviking: need sessionId or sessionKey for OV session path");
27
+ }
28
+ /** Normalize a hook/tool session ref (uuid, sessionKey, or already-safe id) for OV storage. */
29
+ export function openClawSessionRefToOvStorageId(ref) {
30
+ const t = ref.trim();
31
+ if (!t) {
32
+ throw new Error("openviking: empty session ref");
33
+ }
34
+ if (OPENVIKING_OV_SESSION_UUID.test(t)) {
35
+ return t.toLowerCase();
36
+ }
37
+ if (WINDOWS_BAD_SESSION_SEGMENT.test(t)) {
38
+ return createHash("sha256").update(t, "utf8").digest("hex");
39
+ }
40
+ return t;
41
+ }
42
+ /**
43
+ * OpenViking peer identifiers allow only [a-zA-Z0-9_-].
44
+ * OpenClaw ids may contain ":"; never send raw colons in X-OpenViking-Actor-Peer.
45
+ */
46
+ export function sanitizeOpenVikingAgentIdHeader(raw) {
47
+ const trimmed = raw.trim();
48
+ if (!trimmed) {
49
+ return "default";
50
+ }
51
+ const normalized = trimmed
52
+ .replace(/[^a-zA-Z0-9_-]/g, "_")
53
+ .replace(/_+/g, "_")
54
+ .replace(/^_|_$/g, "");
55
+ return normalized.length > 0 ? normalized : "ov_agent";
56
+ }
57
+ function extractAgentIdFromSessionKey(sessionKey) {
58
+ const raw = typeof sessionKey === "string" ? sessionKey.trim() : "";
59
+ if (!raw) {
60
+ return undefined;
61
+ }
62
+ const match = raw.match(/^agent:([^:]+):/);
63
+ const agentId = match?.[1]?.trim();
64
+ return agentId || undefined;
65
+ }
66
+ function collectSessionAgentAliases(sessionId, sessionKey, ovSessionId) {
67
+ const aliases = new Set();
68
+ const sid = typeof sessionId === "string" ? sessionId.trim() : "";
69
+ const sk = typeof sessionKey === "string" ? sessionKey.trim() : "";
70
+ const ovSid = typeof ovSessionId === "string" ? ovSessionId.trim() : "";
71
+ if (sid) {
72
+ aliases.add(sid);
73
+ }
74
+ if (sk) {
75
+ aliases.add(sk);
76
+ }
77
+ if (ovSid) {
78
+ aliases.add(ovSid);
79
+ }
80
+ if (!ovSid && (sid || sk)) {
81
+ try {
82
+ aliases.add(openClawSessionToOvStorageId(sid || undefined, sk || undefined));
83
+ }
84
+ catch {
85
+ /* need a resolvable OpenClaw session identity */
86
+ }
87
+ }
88
+ return [...aliases];
89
+ }
90
+ export function createSessionAgentResolver(configAgentId) {
91
+ const configAgentPrefix = configAgentId.trim() === "default" ? "" : configAgentId.trim();
92
+ const sessionAgentIds = new Map();
93
+ const remember = (ctx) => {
94
+ const sessionScopedAgentId = extractAgentIdFromSessionKey(ctx.sessionKey) ||
95
+ extractAgentIdFromSessionKey(ctx.sessionId);
96
+ const rawAgentId = (typeof ctx.agentId === "string" ? ctx.agentId.trim() : "") ||
97
+ sessionScopedAgentId ||
98
+ "";
99
+ if (!rawAgentId) {
100
+ return;
101
+ }
102
+ const prefix = configAgentPrefix;
103
+ const resolvedBeforeSanitize = prefix ? `${prefix}_${rawAgentId}` : rawAgentId;
104
+ const resolved = sanitizeOpenVikingAgentIdHeader(resolvedBeforeSanitize);
105
+ for (const alias of collectSessionAgentAliases(ctx.sessionId, ctx.sessionKey, ctx.ovSessionId)) {
106
+ sessionAgentIds.set(alias, resolved);
107
+ }
108
+ };
109
+ const resolve = (sessionId, sessionKey, ovSessionId) => {
110
+ const aliases = collectSessionAgentAliases(sessionId, sessionKey, ovSessionId);
111
+ const mappedAlias = aliases.find((alias) => sessionAgentIds.has(alias));
112
+ const mappedResolvedAgentId = mappedAlias ? sessionAgentIds.get(mappedAlias) : undefined;
113
+ const sessionScopedAgentId = extractAgentIdFromSessionKey(sessionKey) ||
114
+ extractAgentIdFromSessionKey(sessionId);
115
+ let resolvedBeforeSanitize;
116
+ let resolved;
117
+ let branch;
118
+ const prefix = configAgentPrefix;
119
+ if (mappedResolvedAgentId) {
120
+ resolvedBeforeSanitize = mappedResolvedAgentId;
121
+ resolved = mappedResolvedAgentId;
122
+ branch = "session_resolved";
123
+ }
124
+ else if (sessionScopedAgentId) {
125
+ resolvedBeforeSanitize = prefix ? `${prefix}_${sessionScopedAgentId}` : sessionScopedAgentId;
126
+ resolved = sanitizeOpenVikingAgentIdHeader(resolvedBeforeSanitize);
127
+ branch = "session_resolved";
128
+ }
129
+ else if (!prefix) {
130
+ resolvedBeforeSanitize = DEFAULT_OPENCLAW_AGENT_ID;
131
+ resolved = DEFAULT_OPENCLAW_AGENT_ID;
132
+ branch = "default_no_session";
133
+ }
134
+ else {
135
+ resolvedBeforeSanitize = `${prefix}_${DEFAULT_OPENCLAW_AGENT_ID}`;
136
+ resolved = sanitizeOpenVikingAgentIdHeader(resolvedBeforeSanitize);
137
+ branch = "config_only_fallback";
138
+ }
139
+ return {
140
+ resolved,
141
+ resolvedBeforeSanitize,
142
+ branch,
143
+ mappedResolvedAgentId: mappedResolvedAgentId ?? null,
144
+ aliases,
145
+ fromExplicitBinding: !!(mappedResolvedAgentId || sessionScopedAgentId),
146
+ };
147
+ };
148
+ return {
149
+ remember,
150
+ resolve,
151
+ };
152
+ }
@@ -0,0 +1,7 @@
1
+ const MEMORY_URI_PATTERNS = [
2
+ /^viking:\/\/user\/(?:[^/]+(?:\/agent\/[^/]+)?\/)?memories(?:\/|$)/,
3
+ /^viking:\/\/agent\/(?:[^/]+(?:\/user\/[^/]+)?\/)?memories(?:\/|$)/,
4
+ ];
5
+ export function isMemoryUri(uri) {
6
+ return MEMORY_URI_PATTERNS.some((pattern) => pattern.test(uri));
7
+ }