@linkclaw/clawpool 0.2.0 → 0.2.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 (2) hide show
  1. package/clawpool.ts +45 -5
  2. package/package.json +1 -1
package/clawpool.ts CHANGED
@@ -154,18 +154,58 @@ async function syncStatus(
154
154
  }
155
155
  }
156
156
 
157
- function openclawConfig(token: string): string {
158
- return JSON.stringify({
157
+ const HOST_OC_CONFIG = join(homedir(), ".openclaw", "openclaw.json");
158
+
159
+ function loadHostOpenClawConfig(): Record<string, unknown> {
160
+ if (!existsSync(HOST_OC_CONFIG)) return {};
161
+ try {
162
+ const raw = require("fs").readFileSync(HOST_OC_CONFIG, "utf-8");
163
+ return JSON.parse(raw);
164
+ } catch {
165
+ return {};
166
+ }
167
+ }
168
+
169
+ function deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown> {
170
+ const result = { ...target };
171
+ for (const key of Object.keys(source)) {
172
+ if (
173
+ source[key] &&
174
+ typeof source[key] === "object" &&
175
+ !Array.isArray(source[key]) &&
176
+ target[key] &&
177
+ typeof target[key] === "object" &&
178
+ !Array.isArray(target[key])
179
+ ) {
180
+ result[key] = deepMerge(
181
+ target[key] as Record<string, unknown>,
182
+ source[key] as Record<string, unknown>
183
+ );
184
+ } else {
185
+ result[key] = source[key];
186
+ }
187
+ }
188
+ return result;
189
+ }
190
+
191
+ function buildOpenClawConfig(token: string): string {
192
+ const hostConfig = loadHostOpenClawConfig();
193
+ // Gateway config is always overridden per-instance
194
+ const instanceOverrides: Record<string, unknown> = {
159
195
  gateway: {
160
196
  auth: { mode: "token", token },
161
197
  controlUi: { dangerouslyAllowHostHeaderOriginFallback: true },
162
198
  },
163
- });
199
+ };
200
+ // Strip host gateway settings (we manage those), keep everything else
201
+ const { gateway: _gw, meta: _meta, ...hostSettings } = hostConfig;
202
+ const merged = deepMerge(hostSettings, instanceOverrides);
203
+ return JSON.stringify(merged);
164
204
  }
165
205
 
166
206
  function buildRunArgs(config: Config, inst: Instance): string[] {
167
- const ocConfig = openclawConfig(inst.gateway_token);
168
- // Init as root to fix volume permissions, write config, then drop to node user
207
+ const ocConfig = buildOpenClawConfig(inst.gateway_token);
208
+ // Always write config on start merges host ~/.openclaw/openclaw.json with per-instance gateway auth
169
209
  const entrypoint = [
170
210
  "sh",
171
211
  "-c",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linkclaw/clawpool",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "clawpool": "./clawpool.ts"