@clawcipes/recipes 0.1.1 → 0.1.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.
- package/index.ts +68 -2
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -200,8 +200,46 @@ function upsertAgentInConfig(cfgObj: any, snippet: AgentConfigSnippet) {
|
|
|
200
200
|
tools: snippet.tools ? { ...snippet.tools } : prev?.tools,
|
|
201
201
|
};
|
|
202
202
|
|
|
203
|
-
if (idx >= 0)
|
|
204
|
-
|
|
203
|
+
if (idx >= 0) {
|
|
204
|
+
list[idx] = nextAgent;
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// New agent: append to end of list.
|
|
209
|
+
// (We still separately enforce that main exists and stays first/default.)
|
|
210
|
+
list.push(nextAgent);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function ensureMainFirstInAgentsList(cfgObj: any, api: OpenClawPluginApi) {
|
|
214
|
+
if (!cfgObj.agents) cfgObj.agents = {};
|
|
215
|
+
if (!Array.isArray(cfgObj.agents.list)) cfgObj.agents.list = [];
|
|
216
|
+
|
|
217
|
+
const list: any[] = cfgObj.agents.list;
|
|
218
|
+
|
|
219
|
+
const workspaceRoot =
|
|
220
|
+
cfgObj.agents?.defaults?.workspace ??
|
|
221
|
+
api.config.agents?.defaults?.workspace ??
|
|
222
|
+
"~/.openclaw/workspace";
|
|
223
|
+
|
|
224
|
+
const idx = list.findIndex((a) => a?.id === "main");
|
|
225
|
+
const prevMain = idx >= 0 ? list[idx] : {};
|
|
226
|
+
|
|
227
|
+
// Enforce: main exists, is first, and is the default.
|
|
228
|
+
const main = {
|
|
229
|
+
...prevMain,
|
|
230
|
+
id: "main",
|
|
231
|
+
default: true,
|
|
232
|
+
workspace: prevMain?.workspace ?? workspaceRoot,
|
|
233
|
+
sandbox: prevMain?.sandbox ?? { mode: "off" },
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// Ensure only one default.
|
|
237
|
+
for (const a of list) {
|
|
238
|
+
if (a?.id !== "main" && a?.default) a.default = false;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (idx >= 0) list.splice(idx, 1);
|
|
242
|
+
list.unshift(main);
|
|
205
243
|
}
|
|
206
244
|
|
|
207
245
|
async function applyAgentSnippetsToOpenClawConfig(api: OpenClawPluginApi, snippets: AgentConfigSnippet[]) {
|
|
@@ -211,8 +249,15 @@ async function applyAgentSnippetsToOpenClawConfig(api: OpenClawPluginApi, snippe
|
|
|
211
249
|
|
|
212
250
|
// Some loaders return { cfg, ... }. If so, normalize.
|
|
213
251
|
const cfgObj = (current.cfg ?? current) as any;
|
|
252
|
+
|
|
253
|
+
// Always keep main first/default when multi-agent workflows are in play.
|
|
254
|
+
ensureMainFirstInAgentsList(cfgObj, api);
|
|
255
|
+
|
|
214
256
|
for (const s of snippets) upsertAgentInConfig(cfgObj, s);
|
|
215
257
|
|
|
258
|
+
// Re-assert ordering/default after upserts.
|
|
259
|
+
ensureMainFirstInAgentsList(cfgObj, api);
|
|
260
|
+
|
|
216
261
|
await (api.runtime as any).config?.writeConfigFile?.(cfgObj);
|
|
217
262
|
return { updatedAgents: snippets.map((s) => s.id) };
|
|
218
263
|
}
|
|
@@ -269,6 +314,27 @@ const recipesPlugin = {
|
|
|
269
314
|
properties: {},
|
|
270
315
|
},
|
|
271
316
|
register(api: OpenClawPluginApi) {
|
|
317
|
+
// On plugin load, ensure multi-agent config has an explicit agents.list with main at top.
|
|
318
|
+
// This is idempotent and only writes if a change is required.
|
|
319
|
+
(async () => {
|
|
320
|
+
try {
|
|
321
|
+
const current = (api.runtime as any).config?.loadConfig?.();
|
|
322
|
+
if (!current) return;
|
|
323
|
+
const cfgObj = (current.cfg ?? current) as any;
|
|
324
|
+
|
|
325
|
+
const before = JSON.stringify(cfgObj.agents?.list ?? null);
|
|
326
|
+
ensureMainFirstInAgentsList(cfgObj, api);
|
|
327
|
+
const after = JSON.stringify(cfgObj.agents?.list ?? null);
|
|
328
|
+
|
|
329
|
+
if (before !== after) {
|
|
330
|
+
await (api.runtime as any).config?.writeConfigFile?.(cfgObj);
|
|
331
|
+
console.error("[recipes] ensured agents.list includes main as first/default");
|
|
332
|
+
}
|
|
333
|
+
} catch (e) {
|
|
334
|
+
console.error(`[recipes] warning: failed to ensure main agent in agents.list: ${(e as Error).message}`);
|
|
335
|
+
}
|
|
336
|
+
})();
|
|
337
|
+
|
|
272
338
|
api.registerCli(
|
|
273
339
|
({ program }) => {
|
|
274
340
|
const cmd = program.command("recipes").description("Manage markdown recipes (scaffold agents/teams)");
|