@openclawbrain/openclaw 0.3.6 → 0.4.0

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 (62) hide show
  1. package/README.md +23 -228
  2. package/dist/extension/index.js +3 -2
  3. package/dist/extension/index.js.map +1 -1
  4. package/dist/extension/runtime-guard.js +1 -1
  5. package/dist/extension/runtime-guard.js.map +1 -1
  6. package/dist/src/attachment-truth.d.ts +32 -22
  7. package/dist/src/attachment-truth.js +338 -186
  8. package/dist/src/index.d.ts +75 -1719
  9. package/dist/src/index.js +7 -6882
  10. package/dist/src/runtime-core.js +574 -0
  11. package/extension/index.ts +3 -2
  12. package/extension/runtime-guard.ts +1 -1
  13. package/openclaw.plugin.json +1 -1
  14. package/package.json +17 -17
  15. package/dist/src/attachment-truth.js.map +0 -1
  16. package/dist/src/cli.d.ts +0 -170
  17. package/dist/src/cli.js +0 -5583
  18. package/dist/src/cli.js.map +0 -1
  19. package/dist/src/daemon.d.ts +0 -70
  20. package/dist/src/daemon.js +0 -955
  21. package/dist/src/daemon.js.map +0 -1
  22. package/dist/src/import-export.d.ts +0 -36
  23. package/dist/src/import-export.js +0 -171
  24. package/dist/src/import-export.js.map +0 -1
  25. package/dist/src/index.js.map +0 -1
  26. package/dist/src/learning-spine.d.ts +0 -50
  27. package/dist/src/learning-spine.js.map +0 -1
  28. package/dist/src/local-session-passive-learning.d.ts +0 -61
  29. package/dist/src/local-session-passive-learning.js +0 -454
  30. package/dist/src/local-session-passive-learning.js.map +0 -1
  31. package/dist/src/ollama-client.d.ts +0 -46
  32. package/dist/src/ollama-client.js +0 -231
  33. package/dist/src/ollama-client.js.map +0 -1
  34. package/dist/src/openclaw-home-layout.d.ts +0 -17
  35. package/dist/src/openclaw-home-layout.js +0 -182
  36. package/dist/src/openclaw-home-layout.js.map +0 -1
  37. package/dist/src/openclaw-hook-truth.d.ts +0 -33
  38. package/dist/src/openclaw-hook-truth.js +0 -260
  39. package/dist/src/openclaw-hook-truth.js.map +0 -1
  40. package/dist/src/openclaw-plugin-install.d.ts +0 -40
  41. package/dist/src/openclaw-plugin-install.js +0 -282
  42. package/dist/src/provider-config.d.ts +0 -64
  43. package/dist/src/provider-config.js +0 -306
  44. package/dist/src/provider-config.js.map +0 -1
  45. package/dist/src/resolve-activation-root.d.ts +0 -27
  46. package/dist/src/resolve-activation-root.js +0 -190
  47. package/dist/src/resolve-activation-root.js.map +0 -1
  48. package/dist/src/semantic-metadata.d.ts +0 -5
  49. package/dist/src/semantic-metadata.js +0 -70
  50. package/dist/src/semantic-metadata.js.map +0 -1
  51. package/dist/src/session-store.d.ts +0 -168
  52. package/dist/src/session-store.js +0 -250
  53. package/dist/src/session-store.js.map +0 -1
  54. package/dist/src/session-tail.d.ts +0 -73
  55. package/dist/src/session-tail.js +0 -602
  56. package/dist/src/session-tail.js.map +0 -1
  57. package/dist/src/shadow-extension-proof.d.ts +0 -43
  58. package/dist/src/shadow-extension-proof.js +0 -218
  59. package/dist/src/shadow-extension-proof.js.map +0 -1
  60. package/dist/src/teacher-labeler.d.ts +0 -50
  61. package/dist/src/teacher-labeler.js +0 -424
  62. package/dist/src/teacher-labeler.js.map +0 -1
@@ -1,260 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import path from "node:path";
3
- import { describeOpenClawBrainInstallIdentity, describeOpenClawBrainInstallLayout, findInstalledOpenClawBrainPlugin, getOpenClawBrainKnownPluginIds } from "./openclaw-plugin-install.js";
4
- function toErrorMessage(error) {
5
- return error instanceof Error ? error.message : String(error);
6
- }
7
- function readJsonObjectRecord(value) {
8
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
9
- return null;
10
- }
11
- return value;
12
- }
13
- function readOpenClawJsonConfig(openclawHome) {
14
- const openclawJsonPath = path.join(openclawHome, "openclaw.json");
15
- let parsed;
16
- try {
17
- parsed = JSON.parse(readFileSync(openclawJsonPath, "utf8"));
18
- }
19
- catch (error) {
20
- throw new Error(`Failed to read ${openclawJsonPath}: ${toErrorMessage(error)}`);
21
- }
22
- const config = readJsonObjectRecord(parsed);
23
- if (config === null) {
24
- throw new Error(`Failed to read ${openclawJsonPath}: openclaw.json must contain a top-level object`);
25
- }
26
- return {
27
- path: openclawJsonPath,
28
- config
29
- };
30
- }
31
- function shortenPath(fullPath) {
32
- const homeDir = process.env.HOME ?? "";
33
- if (homeDir.length > 0 && fullPath.startsWith(homeDir)) {
34
- return "~" + fullPath.slice(homeDir.length);
35
- }
36
- return fullPath;
37
- }
38
- function inspectInstalledHookActivationRoot(loaderEntryPath) {
39
- let content;
40
- try {
41
- content = readFileSync(loaderEntryPath, "utf8");
42
- }
43
- catch (error) {
44
- return {
45
- ready: false,
46
- detail: `installed loader entry ${shortenPath(loaderEntryPath)} could not be read: ${toErrorMessage(error)}`
47
- };
48
- }
49
- const match = content.match(/const\s+ACTIVATION_ROOT\s*=\s*["'`]([^"'`]+)["'`]/) ??
50
- content.match(/activationRoot:\s*["'`]([^"'`]+)["'`]/);
51
- if (!match || !match[1]) {
52
- return {
53
- ready: false,
54
- detail: `installed loader entry ${shortenPath(loaderEntryPath)} does not declare a pinned activation root`
55
- };
56
- }
57
- const activationRoot = match[1].trim();
58
- if (activationRoot === "__ACTIVATION_ROOT__" || activationRoot === "__ACTIVATION_" + "ROOT__") {
59
- return {
60
- ready: false,
61
- detail: `installed loader entry ${shortenPath(loaderEntryPath)} still contains the ACTIVATION_ROOT placeholder; rerun openclawbrain install/attach to pin the runtime hook`
62
- };
63
- }
64
- return {
65
- ready: true,
66
- detail: `installed loader entry ${shortenPath(loaderEntryPath)} pins activation root ${shortenPath(path.resolve(activationRoot))}`
67
- };
68
- }
69
- function describeAdditionalInstallDetail(additionalInstalls) {
70
- if (additionalInstalls.length === 0) {
71
- return "";
72
- }
73
- return `; additional OpenClawBrain installs also exist at ${additionalInstalls
74
- .map((install) => `${shortenPath(install.extensionDir)} (${describeOpenClawBrainInstallLayout(install.installLayout)}, ${describeOpenClawBrainInstallIdentity(install)})`)
75
- .join(", ")}`;
76
- }
77
- export function inspectOpenClawBrainPluginAllowlist(openclawHome) {
78
- const { path: openclawJsonPath, config } = readOpenClawJsonConfig(openclawHome);
79
- const installedPlugin = findInstalledOpenClawBrainPlugin(openclawHome);
80
- const knownPluginIds = getOpenClawBrainKnownPluginIds(installedPlugin.selectedInstall);
81
- const plugins = readJsonObjectRecord(config.plugins);
82
- if (plugins === null) {
83
- return {
84
- state: "unrestricted",
85
- detail: `${shortenPath(openclawJsonPath)} has no plugins object; the on-disk hook is not blocked by an allowlist`
86
- };
87
- }
88
- if (!Object.prototype.hasOwnProperty.call(plugins, "allow")) {
89
- return {
90
- state: "unrestricted",
91
- detail: `${shortenPath(openclawJsonPath)} does not pin plugins.allow; the on-disk hook is not blocked by an allowlist`
92
- };
93
- }
94
- if (!Array.isArray(plugins.allow)) {
95
- return {
96
- state: "invalid",
97
- detail: `${shortenPath(openclawJsonPath)} has a non-array plugins.allow value, so OpenClawBrain load cannot be proven from config`
98
- };
99
- }
100
- const matchedPluginId = knownPluginIds.find((pluginId) => plugins.allow.includes(pluginId)) ?? null;
101
- return matchedPluginId !== null
102
- ? {
103
- state: "allowed",
104
- detail: `${shortenPath(openclawJsonPath)} plugins.allow explicitly includes ${matchedPluginId}; recognized OpenClawBrain ids are ${knownPluginIds.join(", ")}`
105
- }
106
- : {
107
- state: "blocked",
108
- detail: `${shortenPath(openclawJsonPath)} plugins.allow excludes recognized OpenClawBrain ids ${knownPluginIds.join(", ")}`
109
- };
110
- }
111
- export function inspectOpenClawBrainHookStatus(openclawHome) {
112
- if (openclawHome === null || openclawHome === undefined || openclawHome.trim().length === 0) {
113
- return {
114
- scope: "activation_root_only",
115
- openclawHome: null,
116
- extensionDir: null,
117
- hookPath: null,
118
- runtimeGuardPath: null,
119
- manifestPath: null,
120
- packageJsonPath: null,
121
- manifestId: null,
122
- installId: null,
123
- packageName: null,
124
- installLayout: null,
125
- additionalInstallCount: 0,
126
- installState: "unverified",
127
- loadability: "unverified",
128
- pluginAllowlistState: "unverified",
129
- desynced: false,
130
- detail: "profile hook state is unknown from activation-root-only status; pin --openclaw-home to prove install state"
131
- };
132
- }
133
- const resolvedHome = path.resolve(openclawHome);
134
- const installedPlugin = findInstalledOpenClawBrainPlugin(resolvedHome);
135
- if (installedPlugin.selectedInstall === null ||
136
- installedPlugin.selectedInstall.loaderEntryPath === null ||
137
- installedPlugin.selectedInstall.runtimeGuardPath === null) {
138
- const incompleteInstall = installedPlugin.selectedInstall;
139
- return {
140
- scope: "exact_openclaw_home",
141
- openclawHome: resolvedHome,
142
- extensionDir: incompleteInstall?.extensionDir ?? null,
143
- hookPath: incompleteInstall?.loaderEntryPath ?? null,
144
- runtimeGuardPath: incompleteInstall?.runtimeGuardPath ?? null,
145
- manifestPath: incompleteInstall?.manifestPath ?? null,
146
- packageJsonPath: incompleteInstall?.packageJsonPath ?? null,
147
- manifestId: incompleteInstall?.manifestId ?? null,
148
- installId: incompleteInstall?.installId ?? null,
149
- packageName: incompleteInstall?.packageName ?? null,
150
- installLayout: incompleteInstall?.installLayout ?? null,
151
- additionalInstallCount: installedPlugin.additionalInstalls.length,
152
- installState: "not_installed",
153
- loadability: "not_installed",
154
- pluginAllowlistState: "unverified",
155
- desynced: false,
156
- detail: incompleteInstall === null
157
- ? `profile hook is not present under ${shortenPath(installedPlugin.extensionsDir)}`
158
- : `profile hook is incomplete under ${shortenPath(incompleteInstall.extensionDir)} (${describeOpenClawBrainInstallIdentity(incompleteInstall)})`
159
- };
160
- }
161
- const selectedInstall = installedPlugin.selectedInstall;
162
- const additionalInstallDetail = describeAdditionalInstallDetail(installedPlugin.additionalInstalls);
163
- const allowlist = inspectOpenClawBrainPluginAllowlist(resolvedHome);
164
- const layoutLabel = describeOpenClawBrainInstallLayout(selectedInstall.installLayout);
165
- const identityDetail = describeOpenClawBrainInstallIdentity(selectedInstall);
166
- const activationRootState = inspectInstalledHookActivationRoot(selectedInstall.loaderEntryPath);
167
- if (allowlist.state === "blocked") {
168
- return {
169
- scope: "exact_openclaw_home",
170
- openclawHome: resolvedHome,
171
- extensionDir: selectedInstall.extensionDir,
172
- hookPath: selectedInstall.loaderEntryPath,
173
- runtimeGuardPath: selectedInstall.runtimeGuardPath,
174
- manifestPath: selectedInstall.manifestPath,
175
- packageJsonPath: selectedInstall.packageJsonPath,
176
- manifestId: selectedInstall.manifestId,
177
- installId: selectedInstall.installId,
178
- packageName: selectedInstall.packageName,
179
- installLayout: selectedInstall.installLayout,
180
- additionalInstallCount: installedPlugin.additionalInstalls.length,
181
- installState: "blocked_by_allowlist",
182
- loadability: "blocked",
183
- pluginAllowlistState: allowlist.state,
184
- desynced: true,
185
- detail: `profile hook is installed via ${layoutLabel} at ${shortenPath(selectedInstall.extensionDir)} (${identityDetail}), but ${allowlist.detail}; ` +
186
- `the on-disk hook is not loadable and OpenClaw will not load it${additionalInstallDetail}`
187
- };
188
- }
189
- if (allowlist.state === "invalid") {
190
- return {
191
- scope: "exact_openclaw_home",
192
- openclawHome: resolvedHome,
193
- extensionDir: selectedInstall.extensionDir,
194
- hookPath: selectedInstall.loaderEntryPath,
195
- runtimeGuardPath: selectedInstall.runtimeGuardPath,
196
- manifestPath: selectedInstall.manifestPath,
197
- packageJsonPath: selectedInstall.packageJsonPath,
198
- manifestId: selectedInstall.manifestId,
199
- installId: selectedInstall.installId,
200
- packageName: selectedInstall.packageName,
201
- installLayout: selectedInstall.installLayout,
202
- additionalInstallCount: installedPlugin.additionalInstalls.length,
203
- installState: "blocked_by_allowlist",
204
- loadability: "blocked",
205
- pluginAllowlistState: allowlist.state,
206
- desynced: true,
207
- detail: `profile hook is installed via ${layoutLabel} at ${shortenPath(selectedInstall.extensionDir)} (${identityDetail}), but ${allowlist.detail}; ` +
208
- `treat hook-load state as broken until install/attach repairs the config${additionalInstallDetail}`
209
- };
210
- }
211
- if (!activationRootState.ready) {
212
- return {
213
- scope: "exact_openclaw_home",
214
- openclawHome: resolvedHome,
215
- extensionDir: selectedInstall.extensionDir,
216
- hookPath: selectedInstall.loaderEntryPath,
217
- runtimeGuardPath: selectedInstall.runtimeGuardPath,
218
- manifestPath: selectedInstall.manifestPath,
219
- packageJsonPath: selectedInstall.packageJsonPath,
220
- manifestId: selectedInstall.manifestId,
221
- installId: selectedInstall.installId,
222
- packageName: selectedInstall.packageName,
223
- installLayout: selectedInstall.installLayout,
224
- additionalInstallCount: installedPlugin.additionalInstalls.length,
225
- installState: "installed",
226
- loadability: "blocked",
227
- pluginAllowlistState: allowlist.state,
228
- desynced: true,
229
- detail: `profile hook is installed via ${layoutLabel} at ${shortenPath(selectedInstall.extensionDir)} (${identityDetail}), but ${activationRootState.detail}${additionalInstallDetail}`
230
- };
231
- }
232
- return {
233
- scope: "exact_openclaw_home",
234
- openclawHome: resolvedHome,
235
- extensionDir: selectedInstall.extensionDir,
236
- hookPath: selectedInstall.loaderEntryPath,
237
- runtimeGuardPath: selectedInstall.runtimeGuardPath,
238
- manifestPath: selectedInstall.manifestPath,
239
- packageJsonPath: selectedInstall.packageJsonPath,
240
- manifestId: selectedInstall.manifestId,
241
- installId: selectedInstall.installId,
242
- packageName: selectedInstall.packageName,
243
- installLayout: selectedInstall.installLayout,
244
- additionalInstallCount: installedPlugin.additionalInstalls.length,
245
- installState: "installed",
246
- loadability: "loadable",
247
- pluginAllowlistState: allowlist.state,
248
- desynced: false,
249
- detail: `profile hook is installed via ${layoutLabel} at ${shortenPath(selectedInstall.extensionDir)} (${identityDetail})${additionalInstallDetail}`
250
- };
251
- }
252
- export function summarizeOpenClawBrainHookLoad(inspection, statusProbeReady) {
253
- return {
254
- ...inspection,
255
- loadProof: inspection.loadability === "loadable" && statusProbeReady
256
- ? "status_probe_ready"
257
- : "not_ready"
258
- };
259
- }
260
- //# sourceMappingURL=openclaw-hook-truth.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openclaw-hook-truth.js","sourceRoot":"","sources":["../../src/openclaw-hook-truth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY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EzB,OAAO;QACL,GAAG,UAAU;QACb,SAAS,EACP,UAAU,CAAC,WAAW,KAAK,UAAU,IAAI,gBAAgB;YACvD,CAAC,CAAC,oBAAoB;YACtB,CAAC,CAAC,WAAW;KAClB,CAAC;AACJ,CAAC"}
@@ -1,40 +0,0 @@
1
- export type OpenClawBrainInstallLayout = "generated_shadow_extension" | "native_package_plugin";
2
- export interface OpenClawBrainInstalledPlugin {
3
- openclawHome: string;
4
- extensionsDir: string;
5
- extensionDir: string;
6
- manifestPath: string;
7
- packageJsonPath: string;
8
- loaderEntryPath: string | null;
9
- runtimeGuardPath: string | null;
10
- configuredEntries: string[];
11
- manifestId: string | null;
12
- installId: string | null;
13
- packageName: string | null;
14
- installLayout: OpenClawBrainInstallLayout;
15
- }
16
- export interface OpenClawBrainInstallTarget {
17
- installLayout: OpenClawBrainInstallLayout;
18
- extensionDir: string;
19
- hookPath: string;
20
- writeMode: "pin_native_package" | "write_shadow_extension";
21
- selectedInstall: OpenClawBrainInstalledPlugin | null;
22
- additionalInstalls: OpenClawBrainInstalledPlugin[];
23
- }
24
- export interface OpenClawBrainInstalledPluginLookup {
25
- openclawHome: string;
26
- extensionsDir: string;
27
- selectedInstall: OpenClawBrainInstalledPlugin | null;
28
- additionalInstalls: OpenClawBrainInstalledPlugin[];
29
- }
30
- export declare const OPENCLAWBRAIN_PLUGIN_ID = "openclawbrain";
31
- export declare const OPENCLAWBRAIN_SHADOW_PACKAGE_NAME = "openclawbrain";
32
- export declare const OPENCLAWBRAIN_NATIVE_PACKAGE_NAME = "@openclawbrain/openclaw";
33
- export declare const OPENCLAWBRAIN_NATIVE_INSTALL_ID = "openclaw";
34
- export declare function describeOpenClawBrainInstallLayout(installLayout: OpenClawBrainInstallLayout): string;
35
- export declare function getOpenClawBrainKnownPluginIds(install: OpenClawBrainInstalledPlugin | null | undefined): string[];
36
- export declare function describeOpenClawBrainInstallIdentity(install: OpenClawBrainInstalledPlugin): string;
37
- export declare function findInstalledOpenClawBrainPlugin(openclawHome: string, pluginId?: string): OpenClawBrainInstalledPluginLookup;
38
- export declare function resolveOpenClawBrainInstallTarget(openclawHome: string): OpenClawBrainInstallTarget;
39
- export declare function pinInstalledOpenClawBrainPluginActivationRoot(loaderEntryPath: string, activationRoot: string): void;
40
- export declare function resolveOpenClawHomeFromExtensionEntryPath(extensionEntryPath: string): string | null;
@@ -1,282 +0,0 @@
1
- import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
2
- import path from "node:path";
3
- export const OPENCLAWBRAIN_PLUGIN_ID = "openclawbrain";
4
- export const OPENCLAWBRAIN_SHADOW_PACKAGE_NAME = "openclawbrain";
5
- export const OPENCLAWBRAIN_NATIVE_PACKAGE_NAME = "@openclawbrain/openclaw";
6
- export const OPENCLAWBRAIN_NATIVE_INSTALL_ID = "openclaw";
7
- function readJsonObject(filePath) {
8
- try {
9
- const parsed = JSON.parse(readFileSync(filePath, "utf8"));
10
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
11
- return null;
12
- }
13
- return parsed;
14
- }
15
- catch {
16
- return null;
17
- }
18
- }
19
- function resolveConfiguredEntries(packageJson) {
20
- const entries = packageJson?.openclaw?.extensions;
21
- if (!Array.isArray(entries)) {
22
- return [];
23
- }
24
- return entries
25
- .filter((entry) => typeof entry === "string")
26
- .map((entry) => entry.trim())
27
- .filter((entry) => entry.length > 0);
28
- }
29
- function resolveLoaderEntryPath(extensionDir, configuredEntries) {
30
- for (const configuredEntry of configuredEntries) {
31
- const candidate = path.join(extensionDir, configuredEntry);
32
- if (existsSync(candidate)) {
33
- return candidate;
34
- }
35
- }
36
- return null;
37
- }
38
- function resolveRuntimeGuardPath(loaderEntryPath) {
39
- const runtimeGuardPath = path.join(path.dirname(loaderEntryPath), "runtime-guard.js");
40
- return existsSync(runtimeGuardPath) ? runtimeGuardPath : null;
41
- }
42
- function normalizeOptionalString(value) {
43
- if (typeof value !== "string") {
44
- return null;
45
- }
46
- const trimmed = value.trim();
47
- return trimmed.length > 0 ? trimmed : null;
48
- }
49
- function normalizeInstallId(value) {
50
- const normalized = normalizeOptionalString(value);
51
- if (normalized === null) {
52
- return null;
53
- }
54
- if (!normalized.startsWith("@")) {
55
- return normalized;
56
- }
57
- const parts = normalized.split("/");
58
- return normalizeOptionalString(parts[1] ?? null);
59
- }
60
- function listCandidateExtensionDirs(extensionsDir) {
61
- const candidates = [];
62
- let entries;
63
- try {
64
- entries = readdirSync(extensionsDir, { withFileTypes: true });
65
- }
66
- catch {
67
- return [];
68
- }
69
- for (const entry of entries) {
70
- if (!entry.isDirectory()) {
71
- continue;
72
- }
73
- const directPath = path.join(extensionsDir, entry.name);
74
- candidates.push(directPath);
75
- if (!entry.name.startsWith("@")) {
76
- continue;
77
- }
78
- let scopedEntries;
79
- try {
80
- scopedEntries = readdirSync(directPath, { withFileTypes: true });
81
- }
82
- catch {
83
- continue;
84
- }
85
- for (const scopedEntry of scopedEntries) {
86
- if (!scopedEntry.isDirectory()) {
87
- continue;
88
- }
89
- candidates.push(path.join(directPath, scopedEntry.name));
90
- }
91
- }
92
- return candidates.sort((left, right) => left.localeCompare(right));
93
- }
94
- function inferInstallLayout(input) {
95
- if (input.packageName === OPENCLAWBRAIN_NATIVE_PACKAGE_NAME) {
96
- return "native_package_plugin";
97
- }
98
- if (input.packageName === OPENCLAWBRAIN_SHADOW_PACKAGE_NAME) {
99
- return "generated_shadow_extension";
100
- }
101
- if (input.installId === OPENCLAWBRAIN_NATIVE_INSTALL_ID &&
102
- input.loaderEntryPath !== null &&
103
- input.loaderEntryPath.endsWith(path.join("dist", "extension", "index.js"))) {
104
- return "native_package_plugin";
105
- }
106
- if (input.loaderEntryPath !== null &&
107
- input.loaderEntryPath.endsWith(path.join("dist", "extension", "index.js"))) {
108
- return "native_package_plugin";
109
- }
110
- if (input.loaderEntryPath !== null &&
111
- path.basename(input.loaderEntryPath) === "index.ts" &&
112
- (input.installId === OPENCLAWBRAIN_PLUGIN_ID ||
113
- path.basename(input.extensionDir) === OPENCLAWBRAIN_PLUGIN_ID)) {
114
- return "generated_shadow_extension";
115
- }
116
- return null;
117
- }
118
- function compareInstalledPluginPriority(left, right) {
119
- const leftCompleteness = Number(left.loaderEntryPath !== null) + Number(left.runtimeGuardPath !== null);
120
- const rightCompleteness = Number(right.loaderEntryPath !== null) + Number(right.runtimeGuardPath !== null);
121
- if (leftCompleteness !== rightCompleteness) {
122
- return rightCompleteness - leftCompleteness;
123
- }
124
- const leftLayoutRank = left.installLayout === "native_package_plugin" ? 0 : 1;
125
- const rightLayoutRank = right.installLayout === "native_package_plugin" ? 0 : 1;
126
- if (leftLayoutRank !== rightLayoutRank) {
127
- return leftLayoutRank - rightLayoutRank;
128
- }
129
- return left.extensionDir.localeCompare(right.extensionDir);
130
- }
131
- function inspectOpenClawBrainPluginInstall(extensionDir, pluginId) {
132
- const manifestPath = path.join(extensionDir, "openclaw.plugin.json");
133
- if (!existsSync(manifestPath)) {
134
- return null;
135
- }
136
- const manifest = readJsonObject(manifestPath);
137
- const manifestId = normalizeOptionalString(manifest?.id);
138
- if (manifestId !== pluginId) {
139
- return null;
140
- }
141
- const packageJsonPath = path.join(extensionDir, "package.json");
142
- if (!existsSync(packageJsonPath)) {
143
- return null;
144
- }
145
- const packageJson = readJsonObject(packageJsonPath);
146
- if (packageJson === null) {
147
- return null;
148
- }
149
- const configuredEntries = resolveConfiguredEntries(packageJson);
150
- const loaderEntryPath = resolveLoaderEntryPath(extensionDir, configuredEntries);
151
- const packageName = typeof packageJson.name === "string" && packageJson.name.trim().length > 0
152
- ? packageJson.name.trim()
153
- : null;
154
- const installId = normalizeInstallId(packageName) ?? normalizeInstallId(path.basename(extensionDir));
155
- const installLayout = inferInstallLayout({
156
- extensionDir,
157
- packageName,
158
- installId,
159
- loaderEntryPath
160
- });
161
- if (installLayout === null) {
162
- return null;
163
- }
164
- return {
165
- extensionDir,
166
- manifestPath,
167
- packageJsonPath,
168
- loaderEntryPath,
169
- runtimeGuardPath: loaderEntryPath === null ? null : resolveRuntimeGuardPath(loaderEntryPath),
170
- configuredEntries,
171
- manifestId,
172
- installId,
173
- packageName,
174
- installLayout
175
- };
176
- }
177
- export function describeOpenClawBrainInstallLayout(installLayout) {
178
- return installLayout === "native_package_plugin"
179
- ? "native package plugin"
180
- : "generated shadow extension";
181
- }
182
- export function getOpenClawBrainKnownPluginIds(install) {
183
- const ids = [];
184
- const push = (value) => {
185
- const normalized = normalizeOptionalString(value);
186
- if (normalized === null || ids.includes(normalized)) {
187
- return;
188
- }
189
- ids.push(normalized);
190
- };
191
- push(OPENCLAWBRAIN_PLUGIN_ID);
192
- push(install?.manifestId ?? null);
193
- push(install?.installId ?? null);
194
- if (install?.packageName === OPENCLAWBRAIN_NATIVE_PACKAGE_NAME) {
195
- push(OPENCLAWBRAIN_NATIVE_INSTALL_ID);
196
- }
197
- return ids;
198
- }
199
- export function describeOpenClawBrainInstallIdentity(install) {
200
- return [
201
- `manifest=${install.manifestId ?? OPENCLAWBRAIN_PLUGIN_ID}`,
202
- `install=${install.installId ?? path.basename(install.extensionDir)}`,
203
- `package=${install.packageName ?? "unknown"}`
204
- ].join(" ");
205
- }
206
- export function findInstalledOpenClawBrainPlugin(openclawHome, pluginId = OPENCLAWBRAIN_PLUGIN_ID) {
207
- const resolvedOpenclawHome = path.resolve(openclawHome);
208
- const extensionsDir = path.join(resolvedOpenclawHome, "extensions");
209
- if (!existsSync(extensionsDir)) {
210
- return {
211
- openclawHome: resolvedOpenclawHome,
212
- extensionsDir,
213
- selectedInstall: null,
214
- additionalInstalls: []
215
- };
216
- }
217
- const installs = listCandidateExtensionDirs(extensionsDir)
218
- .map((extensionDir) => inspectOpenClawBrainPluginInstall(extensionDir, pluginId))
219
- .filter((install) => install !== null)
220
- .map((install) => ({
221
- ...install,
222
- openclawHome: resolvedOpenclawHome,
223
- extensionsDir
224
- }))
225
- .sort(compareInstalledPluginPriority);
226
- return {
227
- openclawHome: resolvedOpenclawHome,
228
- extensionsDir,
229
- selectedInstall: installs[0] ?? null,
230
- additionalInstalls: installs.slice(1)
231
- };
232
- }
233
- export function resolveOpenClawBrainInstallTarget(openclawHome) {
234
- const installedPlugin = findInstalledOpenClawBrainPlugin(openclawHome);
235
- const selectedInstall = installedPlugin.selectedInstall;
236
- if (selectedInstall !== null &&
237
- selectedInstall.installLayout === "native_package_plugin" &&
238
- selectedInstall.loaderEntryPath !== null &&
239
- selectedInstall.runtimeGuardPath !== null) {
240
- return {
241
- installLayout: selectedInstall.installLayout,
242
- extensionDir: selectedInstall.extensionDir,
243
- hookPath: selectedInstall.loaderEntryPath,
244
- writeMode: "pin_native_package",
245
- selectedInstall,
246
- additionalInstalls: installedPlugin.additionalInstalls
247
- };
248
- }
249
- const extensionDir = path.join(openclawHome, "extensions", OPENCLAWBRAIN_PLUGIN_ID);
250
- return {
251
- installLayout: "generated_shadow_extension",
252
- extensionDir,
253
- hookPath: path.join(extensionDir, "index.ts"),
254
- writeMode: "write_shadow_extension",
255
- selectedInstall,
256
- additionalInstalls: installedPlugin.additionalInstalls
257
- };
258
- }
259
- export function pinInstalledOpenClawBrainPluginActivationRoot(loaderEntryPath, activationRoot) {
260
- const loaderSource = readFileSync(loaderEntryPath, "utf8");
261
- const pinnedActivationRoot = `const ACTIVATION_ROOT = ${JSON.stringify(activationRoot)};`;
262
- const nextLoaderSource = loaderSource.replace(/const\s+ACTIVATION_ROOT\s*=\s*["'`][^"'`]*["'`];/, pinnedActivationRoot);
263
- if (nextLoaderSource === loaderSource) {
264
- throw new Error(`Installed loader entry ${loaderEntryPath} does not expose a patchable ACTIVATION_ROOT constant`);
265
- }
266
- writeFileSync(loaderEntryPath, nextLoaderSource, "utf8");
267
- }
268
- export function resolveOpenClawHomeFromExtensionEntryPath(extensionEntryPath) {
269
- let currentPath = path.resolve(extensionEntryPath);
270
- while (true) {
271
- const parentPath = path.dirname(currentPath);
272
- if (parentPath === currentPath) {
273
- break;
274
- }
275
- if (path.basename(parentPath) === "extensions") {
276
- return path.dirname(parentPath);
277
- }
278
- currentPath = parentPath;
279
- }
280
- return null;
281
- }
282
- //# sourceMappingURL=openclaw-plugin-install.js.map
@@ -1,64 +0,0 @@
1
- declare const OPENCLAWBRAIN_PROVIDER_DEFAULTS_CONTRACT = "openclawbrain_provider_defaults.v1";
2
- declare const ALLOWED_TEACHER_PROVIDERS: readonly ["heuristic", "ollama", "off"];
3
- declare const ALLOWED_EMBEDDER_PROVIDERS: readonly ["keywords", "ollama", "off"];
4
- export type OpenClawBrainProviderConfigEnv = Readonly<Record<string, string | undefined>>;
5
- export type OpenClawBrainTeacherProvider = (typeof ALLOWED_TEACHER_PROVIDERS)[number];
6
- export type OpenClawBrainEmbedderProvider = (typeof ALLOWED_EMBEDDER_PROVIDERS)[number];
7
- export type OpenClawBrainProviderResolvedNote = string;
8
- export interface OpenClawBrainProviderDefaultsRecord {
9
- contract: typeof OPENCLAWBRAIN_PROVIDER_DEFAULTS_CONTRACT;
10
- writtenAt: string;
11
- source: "install";
12
- teacherBaseUrl?: string;
13
- embedderBaseUrl?: string;
14
- teacher?: {
15
- provider?: OpenClawBrainTeacherProvider;
16
- model?: string | null;
17
- timeoutMs?: number;
18
- maxPromptChars?: number;
19
- maxResponseChars?: number;
20
- maxOutputTokens?: number;
21
- maxArtifactsPerExport?: number;
22
- maxInteractionsPerExport?: number;
23
- detectedLocally?: boolean;
24
- detectedFromModel?: string | null;
25
- };
26
- embedder?: {
27
- provider?: OpenClawBrainEmbedderProvider;
28
- model?: string | null;
29
- };
30
- }
31
- export interface OpenClawBrainProviderDefaultsReadResult {
32
- defaults: OpenClawBrainProviderDefaultsRecord | null;
33
- warnings: string[];
34
- }
35
- export interface ReadOpenClawBrainProviderConfigInput {
36
- env?: OpenClawBrainProviderConfigEnv;
37
- activationRoot?: string | null;
38
- defaults?: OpenClawBrainProviderDefaultsRecord | null;
39
- }
40
- export interface OpenClawBrainProviderSelection<TProvider extends string> {
41
- provider: TProvider;
42
- model: string;
43
- }
44
- export interface OpenClawBrainTeacherConfig extends OpenClawBrainProviderSelection<OpenClawBrainTeacherProvider> {
45
- timeoutMs?: number;
46
- maxPromptChars?: number;
47
- maxResponseChars?: number;
48
- maxOutputTokens?: number;
49
- maxArtifactsPerExport?: number;
50
- maxInteractionsPerExport?: number;
51
- }
52
- export interface OpenClawBrainProviderConfig {
53
- teacherBaseUrl: string;
54
- embedderBaseUrl: string;
55
- teacher: OpenClawBrainTeacherConfig;
56
- embedder: OpenClawBrainProviderSelection<OpenClawBrainEmbedderProvider>;
57
- warnings: string[];
58
- }
59
- export declare function resolveOpenClawBrainProviderDefaultsPath(activationRoot: string): string;
60
- export declare function readOpenClawBrainProviderDefaults(activationRoot: string): OpenClawBrainProviderDefaultsReadResult;
61
- export declare function resolveOpenClawBrainProviderConfigNotes(config: OpenClawBrainProviderConfig): OpenClawBrainProviderResolvedNote[];
62
- export declare function readOpenClawBrainProviderConfig(env?: OpenClawBrainProviderConfigEnv): OpenClawBrainProviderConfig;
63
- export declare function readOpenClawBrainProviderConfigFromSources(input?: ReadOpenClawBrainProviderConfigInput): OpenClawBrainProviderConfig;
64
- export {};