@coolclaw/coolclaw 0.1.1 → 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.
|
@@ -11,6 +11,10 @@ import {
|
|
|
11
11
|
touchBinding
|
|
12
12
|
} from "./chunk-4WOJKMUY.js";
|
|
13
13
|
|
|
14
|
+
// src/setup.ts
|
|
15
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
16
|
+
import path3 from "path";
|
|
17
|
+
|
|
14
18
|
// src/identity.ts
|
|
15
19
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
16
20
|
import path from "path";
|
|
@@ -153,7 +157,11 @@ async function runCoolclawSetup(options = {}) {
|
|
|
153
157
|
const binding = canReuse ? existingBinding : await registerAndPersistBinding({
|
|
154
158
|
gatewayUrl,
|
|
155
159
|
bindingFile,
|
|
156
|
-
registration:
|
|
160
|
+
registration: await resolveRegistrationInput(
|
|
161
|
+
options.registration,
|
|
162
|
+
options.workspaceDir,
|
|
163
|
+
openclawConfigPath
|
|
164
|
+
)
|
|
157
165
|
});
|
|
158
166
|
const tokenFile = tokenFileFromBinding(binding, bindingFile);
|
|
159
167
|
if (!options.dryRun) {
|
|
@@ -207,12 +215,88 @@ function tokenFileFromBinding(binding, bindingFile) {
|
|
|
207
215
|
}
|
|
208
216
|
return defaultTokenFile(bindingFile, binding.agentId);
|
|
209
217
|
}
|
|
210
|
-
|
|
218
|
+
var IDENTITY_PLACEHOLDERS = /* @__PURE__ */ new Set([
|
|
219
|
+
"pick something you like",
|
|
220
|
+
"ai? robot? familiar? ghost in the machine? something weirder?",
|
|
221
|
+
"how do you come across? sharp? warm? chaotic? calm?",
|
|
222
|
+
"your signature - pick one that feels right",
|
|
223
|
+
"workspace-relative path, http(s) url, or data uri"
|
|
224
|
+
]);
|
|
225
|
+
function parseIdentityMarkdown(content) {
|
|
226
|
+
const result = {};
|
|
227
|
+
for (const line of content.split(/\r?\n/)) {
|
|
228
|
+
const cleaned = line.trim().replace(/^\s*-\s*/, "");
|
|
229
|
+
const colonIdx = cleaned.indexOf(":");
|
|
230
|
+
if (colonIdx === -1) continue;
|
|
231
|
+
const label = cleaned.slice(0, colonIdx).replace(/[*_]/g, "").trim().toLowerCase();
|
|
232
|
+
const value = cleaned.slice(colonIdx + 1).replace(/^[*_]+|[*_]+$/g, "").trim();
|
|
233
|
+
if (!value || IDENTITY_PLACEHOLDERS.has(value.toLowerCase().replace(/[()]/g, "").trim())) continue;
|
|
234
|
+
if (label === "name") result.name = value;
|
|
235
|
+
if (label === "creature") result.creature = value;
|
|
236
|
+
if (label === "vibe") result.vibe = value;
|
|
237
|
+
if (label === "theme") result.theme = value;
|
|
238
|
+
}
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
async function readWorkspaceDirFromOpenclawConfig(configPath) {
|
|
242
|
+
try {
|
|
243
|
+
const content = await readFile3(configPath, "utf-8");
|
|
244
|
+
const config = JSON.parse(content);
|
|
245
|
+
const workspace = config.agents?.defaults?.workspace;
|
|
246
|
+
return typeof workspace === "string" && workspace.trim() ? workspace.trim() : void 0;
|
|
247
|
+
} catch {
|
|
248
|
+
return void 0;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
async function readIdentityFromWorkspace(workspaceDir) {
|
|
252
|
+
try {
|
|
253
|
+
const content = await readFile3(path3.join(workspaceDir, "IDENTITY.md"), "utf-8");
|
|
254
|
+
return parseIdentityMarkdown(content);
|
|
255
|
+
} catch {
|
|
256
|
+
return {};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
async function readIdentityFromOpenclawConfig(configPath) {
|
|
260
|
+
try {
|
|
261
|
+
const content = await readFile3(configPath, "utf-8");
|
|
262
|
+
const config = JSON.parse(content);
|
|
263
|
+
const defaultsName = config.agents?.defaults?.identity?.name || config.agents?.defaults?.name;
|
|
264
|
+
if (defaultsName) return { name: defaultsName };
|
|
265
|
+
const mainAgent = config.agents?.list?.find((a) => a.id === "main") || config.agents?.list?.[0];
|
|
266
|
+
if (mainAgent?.identity?.name || mainAgent?.name) {
|
|
267
|
+
return { name: mainAgent.identity?.name || mainAgent.name };
|
|
268
|
+
}
|
|
269
|
+
return {};
|
|
270
|
+
} catch {
|
|
271
|
+
return {};
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
async function resolveRegistrationInput(explicitRegistration, workspaceDir, openclawConfigPath) {
|
|
275
|
+
if (explicitRegistration?.name && explicitRegistration?.bio && explicitRegistration.name !== "CoolClaw Agent" && explicitRegistration.bio !== "OpenClaw agent connected through CoolClaw channel.") {
|
|
276
|
+
return explicitRegistration;
|
|
277
|
+
}
|
|
278
|
+
let identityName;
|
|
279
|
+
let identityBio;
|
|
280
|
+
const resolvedWorkspaceDir = workspaceDir ?? await readWorkspaceDirFromOpenclawConfig(openclawConfigPath);
|
|
281
|
+
if (resolvedWorkspaceDir) {
|
|
282
|
+
const identity = await readIdentityFromWorkspace(resolvedWorkspaceDir);
|
|
283
|
+
if (identity.name) {
|
|
284
|
+
identityName = identity.name;
|
|
285
|
+
}
|
|
286
|
+
const bioParts = [identity.creature, identity.vibe, identity.theme].filter(Boolean);
|
|
287
|
+
if (bioParts.length > 0) {
|
|
288
|
+
identityBio = bioParts.join(". ") + ".";
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (!identityName) {
|
|
292
|
+
const configIdentity = await readIdentityFromOpenclawConfig(openclawConfigPath);
|
|
293
|
+
identityName = configIdentity.name;
|
|
294
|
+
}
|
|
211
295
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:T]/g, "").slice(4, 12);
|
|
212
296
|
return {
|
|
213
|
-
name: `RiddleAgent-${stamp}`,
|
|
214
|
-
bio: "OpenClaw agent connected through CoolClaw channel.",
|
|
215
|
-
tags: JSON.stringify(["assistant", "openclaw", "coolclaw"])
|
|
297
|
+
name: explicitRegistration?.name && explicitRegistration.name !== "CoolClaw Agent" ? explicitRegistration.name : identityName ?? `RiddleAgent-${stamp}`,
|
|
298
|
+
bio: explicitRegistration?.bio && explicitRegistration.bio !== "OpenClaw agent connected through CoolClaw channel." ? explicitRegistration.bio : identityBio ?? "OpenClaw agent connected through CoolClaw channel.",
|
|
299
|
+
tags: explicitRegistration?.tags ?? JSON.stringify(["assistant", "openclaw", "coolclaw"])
|
|
216
300
|
};
|
|
217
301
|
}
|
|
218
302
|
|
|
@@ -234,16 +318,18 @@ function readActionOptions(args) {
|
|
|
234
318
|
return typeof candidate === "object" && candidate !== null ? candidate : {};
|
|
235
319
|
}
|
|
236
320
|
function toSetupOptions(raw) {
|
|
321
|
+
const explicitName = stringOption(raw.name);
|
|
322
|
+
const explicitBio = stringOption(raw.bio);
|
|
237
323
|
return {
|
|
238
324
|
gatewayUrl: stringOption(raw.gatewayUrl),
|
|
239
325
|
bindingFile: stringOption(raw.bindingFile),
|
|
240
326
|
openclawConfigPath: stringOption(raw.openclawConfig),
|
|
241
327
|
workspaceDir: stringOption(raw.workspaceDir),
|
|
242
|
-
registration: {
|
|
243
|
-
name:
|
|
244
|
-
bio:
|
|
328
|
+
registration: explicitName || explicitBio ? {
|
|
329
|
+
name: explicitName ?? "CoolClaw Agent",
|
|
330
|
+
bio: explicitBio ?? "OpenClaw agent connected through CoolClaw channel.",
|
|
245
331
|
tags: stringOption(raw.tags) ?? JSON.stringify(["assistant", "openclaw", "coolclaw"])
|
|
246
|
-
},
|
|
332
|
+
} : void 0,
|
|
247
333
|
allowFrom: splitCsv(stringOption(raw.allowFrom)),
|
|
248
334
|
dmPolicy: raw.dmPolicy === "pairing" ? "pairing" : "allowlist",
|
|
249
335
|
forceRegister: Boolean(raw.forceRegister),
|
package/dist/cli-metadata.js
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coolclaw/coolclaw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "OpenClaw native channel plugin for Riddle/CoolClaw chat.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"runtimeSetupEntry": "./dist/setup-entry.js",
|
|
59
59
|
"install": {
|
|
60
60
|
"npmSpec": "@coolclaw/coolclaw",
|
|
61
|
-
"expectedIntegrity": "sha512-
|
|
61
|
+
"expectedIntegrity": "sha512-u84VC6FSLmE/+I3FKwQujzgnCx7fjyDwxT4IOe4CZCpnsdLk3e0RvDVf2nz+M6/amy96MLMc2nqPy24S0NpqyQ==",
|
|
62
62
|
"defaultChoice": "npm",
|
|
63
63
|
"minHostVersion": ">=2026.3.13"
|
|
64
64
|
},
|