feat(guild-discovery): add purpose column to guild_nodes + cli set-purpose
Adds a free-form 'purpose' text field on GuildNode so admins can describe what each guild is for (debate broadcasts / agent triage / dev sandbox / etc.). Surfaced through: - GET /api/auth/me/guilds (existing user-facing list) - GET /api/nodes (existing admin-facing list) - new cli: node set-purpose --node-id X --purpose 'text' Admin-only writes via CLI (HangmanLab pattern) — never HTTP. Empty string clears. TypeORM synchronize auto-adds the column on first startup. Motivates: agents discover the right guild by intent (purpose substring match) before picking a channel, so dialectic/announce workflows don't need hardcoded guild ids.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ConflictException, Injectable } from '@nestjs/common';
|
||||
import { ConflictException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import bcrypt from 'bcryptjs';
|
||||
@@ -55,5 +55,26 @@ export class NodeAdminService {
|
||||
apiKey: rawApiKey,
|
||||
};
|
||||
}
|
||||
|
||||
// Admin-only via cli (never HTTP): set the free-form purpose string on
|
||||
// a guild node. Pass an empty string to clear it (null).
|
||||
async setPurpose(nodeId: string, purpose: string) {
|
||||
const node = await this.nodeRepo.findOne({ where: { nodeId } });
|
||||
if (!node) throw new NotFoundException(`node ${nodeId} not found`);
|
||||
const trimmed = String(purpose ?? '').trim();
|
||||
node.purpose = trimmed === '' ? null : trimmed;
|
||||
const saved = await this.nodeRepo.save(node);
|
||||
await this.audit.write({
|
||||
action: 'node.set_purpose',
|
||||
targetType: 'node',
|
||||
targetId: saved.nodeId,
|
||||
detail: JSON.stringify({ purpose: saved.purpose, via: 'cli' }),
|
||||
});
|
||||
return {
|
||||
nodeId: saved.nodeId,
|
||||
name: saved.name,
|
||||
purpose: saved.purpose,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user