Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

feat(bots): a bot can be renamed, and its deliverables stay where they are (#241)

tournierjc383816179426
diff --git a/src/bots/bot-manager.ts b/src/bots/bot-manager.ts
index 2ccd5c13..164e0349 100644
--- a/src/bots/bot-manager.ts
+++ b/src/bots/bot-manager.ts
@@ -1945,7 +1945,9 @@ export class BotManager {
}
const isCrew = Boolean(manifest.parent);
const final = Boolean(options.final) && !isCrew;
- const botFolder = this.store.deliverablesDir(botId);
+ // Pin before the folder is created: from here on the folder name belongs to the files, not to
+ // whatever the bot is called today.
+ const botFolder = this.store.pinDeliverablesFolder(botId);
const destDir = isCrew ? botFolder : final ? botFolder : join(botFolder, 'work');
mkdirSync(destDir, { recursive: true });
const sourceName = options.saveAs || basename(candidate);
@@ -1992,6 +1994,12 @@ export class BotManager {
* behind so an owner with a bookmark finds the new place.
*/
migrateDeliverables(): { moved: number } {
+ // Existing bots: pin the folder they already use, so the first rename after this upgrade does
+ // not move their deliverables. Runs before the legacy scan, which may return early.
+ for (const manifest of this.store.list()) {
+ if (manifest.parent) continue;
+ this.store.pinDeliverablesFolder(manifest.id);
+ }
const legacy = this.store.outputsDir();
if (!existsSync(legacy)) return { moved: 0 };
let moved = 0;
diff --git a/src/bots/store.ts b/src/bots/store.ts
index 7e371326..206237d6 100644
--- a/src/bots/store.ts
+++ b/src/bots/store.ts
@@ -252,7 +252,22 @@ export class BotStore {
if (manifest.parent && manifest.parent !== id) {
return join(this.deliverablesDir(manifest.parent), 'work', id);
}
- return join(this.deliverablesRootDir, deliverablesFolderName(manifest.name, manifest.id));
+ return join(this.deliverablesRootDir, manifest.deliverablesFolder ?? deliverablesFolderName(manifest.name, manifest.id));
+ }
+
+ /**
+ * Freeze the folder name of a lead's or a solo's deliverables, so a rename moves the label and
+ * not the files. Called when the folder is first written to; a crew bot has no folder of its own
+ * (it lives under its lead's `work/`), so there is nothing to pin.
+ */
+ pinDeliverablesFolder(id: string): string {
+ const manifest = this.get(id);
+ if (!manifest) return join(this.deliverablesRootDir, id);
+ if (manifest.parent && manifest.parent !== id) return this.deliverablesDir(id);
+ if (manifest.deliverablesFolder) return this.deliverablesDir(id);
+ manifest.deliverablesFolder = deliverablesFolderName(manifest.name, manifest.id);
+ this.save(manifest);
+ return this.deliverablesDir(id);
}
/** Rewrite the README index of a deliverables folder (finals on top, stages under work/). */
diff --git a/src/bots/types.ts b/src/bots/types.ts
index 070ca0a9..b887eb83 100644
--- a/src/bots/types.ts
+++ b/src/bots/types.ts
@@ -110,6 +110,14 @@ export interface BotManifest {
id: string;
name: string;
description?: string;
+ /**
+ * The name of this bot's deliverables folder, decided once and then remembered.
+ *
+ * The folder used to be recomputed from `name` on every call, so renaming a bot silently moved
+ * its results: the next delivery landed in a fresh folder and the old one was orphaned. The name
+ * is a label the owner can change; this is the pointer that keeps the files where they are.
+ */
+ deliverablesFolder?: string;
enabled: boolean;
/** Persona file name inside the bot dir. Default 'persona.md'. */
persona?: string;
diff --git a/src/web/api/bots.ts b/src/web/api/bots.ts
index 2cf88689..3eda386c 100644
--- a/src/web/api/bots.ts
+++ b/src/web/api/bots.ts
@@ -208,7 +208,15 @@ app.patch('/api/bots/:id', async (c: any) => {
if (!patch) return c.json({ error: 'Invalid JSON body' }, 400);
try {
const updated = botManager.store.update(id, m => {
- // Only config-editable fields; id/name identity fields are immutable here.
+ // The id is the identity and stays immutable: directories, crew links, journals, threads and
+ // avatars are all keyed by it. The name is a label the owner reads, so it is mutable — a bot
+ // created with a placeholder name was stuck with it forever, and editing bot.yaml behind the
+ // API's back (the only way until now) needs a daemon restart.
+ if (patch.name !== undefined) {
+ const name = typeof patch.name === 'string' ? patch.name.replace(/\s+/g, ' ').trim() : '';
+ if (!name) throw new Error('Bot name must not be empty');
+ m.name = name.slice(0, 60);
+ }
if (patch.enabled !== undefined) m.enabled = patch.enabled;
if (patch.description !== undefined) m.description = patch.description;
if (patch.model !== undefined) m.model = patch.model;