Harden the seams a project sweep surfaced
A systematic review of the whole codebase (main process, renderer, IPC/migration/packaging seams) surfaced four real defects; each is fixed at its root: - Legacy catalogue drift: the operator's profile still carried 89 active skills from the removed ~/.agents import era next to the 228 built-ins. Catalogue sync now mirrors the bundle - actives whose slug the bundle does not ship retire (bindings keep resolving via their pinned revisions; retired skills leave list_skills and cannot be granted anew) - Broken-bundle guard: staging now refuses a bundle without the humanizer skill, so an empty or quarantined resources folder can never trigger the mirror pass into retiring a healthy catalogue - Duplicate agent names: @mentions, DM routing, and task assignment all resolve by name, so createAgent and updateAgent renames now reject a name already held by an active agent (case-insensitive); the mention resolver still refuses to guess between legacy duplicates - Stale DM titles: agent-to-agent conversation rows titled themselves from the frozen creation-time space name, so renames never reached the sidebar; direct titles now derive from members' current names Verified clean in the same sweep: IPC surface (82 channels, handler + preload + api aligned), per-migration transactions with rollback, quota-parking month rollover, retry-budget counting, meeting spot reuse across floor-plan rebuilds.
This commit is contained in:
1 parent
c50f17190c
commit
04093c4869
8 files changed
+156
-12
No files matched your search
@@ -29,6 +29,8 @@ export interface StagedBuiltinSkill {
|
||||
export interface BuiltinSkillSyncReport {
|
||||
imported: number;
|
||||
skipped: number;
|
||||
/** Active skills retired because the bundle no longer carries their slug. */
|
||||
retired: number;
|
||||
failures: string[];
|
||||
}
|
||||
|
||||
@@ -57,12 +59,24 @@ export function stageBuiltinSkillsLibrary(sourceRoot: string, libraryRoot: strin
|
||||
}
|
||||
staged.push(...stageCategorySkills(sourceDir, libraryRoot, seen));
|
||||
}
|
||||
// A bundle without the forced house-style skill is a broken install, not a
|
||||
// small catalogue. Failing here keeps the import (and the mirror-retire
|
||||
// pass) from wiping a healthy org catalogue against an empty directory.
|
||||
if (!seen.has("humanizer")) {
|
||||
throw new Error(`Built-in skills bundle at ${sourceRoot} is missing the humanizer skill - refusing to sync a broken bundle.`);
|
||||
}
|
||||
return staged;
|
||||
}
|
||||
|
||||
/** Publishes every staged skill the org does not already carry. */
|
||||
/**
|
||||
* Makes the org catalogue mirror the bundle: publishes every staged skill
|
||||
* the org does not carry yet, then retires active skills whose slug the
|
||||
* bundle no longer ships (legacy ~/.agents imports, removed skills).
|
||||
* Existing bindings pin revisions directly and keep working; retired skills
|
||||
* simply leave list_skills and stop being grantable.
|
||||
*/
|
||||
export function importStagedSkills(skills: SkillService, orgId: string, staged: StagedBuiltinSkill[]): BuiltinSkillSyncReport {
|
||||
const report: BuiltinSkillSyncReport = { imported: 0, skipped: 0, failures: [] };
|
||||
const report: BuiltinSkillSyncReport = { imported: 0, skipped: 0, retired: 0, failures: [] };
|
||||
for (const unit of staged) {
|
||||
try {
|
||||
if (skills.hasSkill(orgId, unit.slug)) {
|
||||
@@ -75,6 +89,7 @@ export function importStagedSkills(skills: SkillService, orgId: string, staged:
|
||||
report.failures.push(`${unit.slug}: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
report.retired = skills.retireSkillsNotIn(orgId, staged.map((unit) => unit.slug)).length;
|
||||
return report;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ export class OrganizationService {
|
||||
|
||||
createAgent(input: CreateAgentInput): string {
|
||||
assertUsableMentionName(input.name);
|
||||
this.assertAgentNameAvailable(input.orgId, input.name, null);
|
||||
const hiringPolicy = this.governance.enforceHiringPolicy(input);
|
||||
const id = createId("agt");
|
||||
const now = new Date().toISOString();
|
||||
@@ -154,7 +155,10 @@ export class OrganizationService {
|
||||
if (!role) throw new Error("Agent role is required.");
|
||||
const name = input.name === undefined ? agent.name : input.name.trim();
|
||||
if (!name) throw new Error("Agent name is required.");
|
||||
if (name !== agent.name) assertUsableMentionName(name);
|
||||
if (name !== agent.name) {
|
||||
assertUsableMentionName(name);
|
||||
this.assertAgentNameAvailable(input.orgId, name, input.agentId);
|
||||
}
|
||||
if (input.modelProviderId) {
|
||||
const provider = this.db.prepare("select id from providers where id = ? and org_id = ?")
|
||||
.get(input.modelProviderId, input.orgId) as { id: string } | undefined;
|
||||
@@ -330,6 +334,19 @@ export class OrganizationService {
|
||||
if (goalId && project.goal_id !== goalId) throw new Error("Project is linked to a different goal.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Agent names are identities: @mentions, DM routing, and task assignment
|
||||
* all resolve by name, so two active agents must never share one.
|
||||
*/
|
||||
private assertAgentNameAvailable(orgId: string, name: string, exceptAgentId: string | null): void {
|
||||
const clash = this.db.prepare(`
|
||||
select id from agents
|
||||
where org_id = ? and lifecycle = 'active' and lower(name) = lower(?) and (? is null or id <> ?)
|
||||
limit 1
|
||||
`).get(orgId, name.trim(), exceptAgentId, exceptAgentId) as { id: string } | undefined;
|
||||
if (clash) throw new Error(`An active agent named "${name.trim()}" already exists. Pick a different name.`);
|
||||
}
|
||||
|
||||
private addAgentToWorkspaceSpaces(orgId: string, agentId: string): void {
|
||||
const spaces = this.db.prepare("select id from chat_spaces where org_id = ? and visibility = ? and space_type <> ?")
|
||||
.all(orgId, "workspace", "direct") as Array<{ id: string }>;
|
||||
|
||||
@@ -48,6 +48,34 @@ export class SkillService {
|
||||
return Boolean(this.db.prepare("select id from skill_definitions where org_id = ? and slug = ?").get(orgId, slug));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retires every active skill whose slug is not in `keepSlugs`, so the org
|
||||
* catalogue mirrors the shipped bundle. Bindings pin revisions directly
|
||||
* and keep resolving; retired skills leave list_skills and cannot be
|
||||
* granted anew. Returns the retired slugs.
|
||||
*/
|
||||
retireSkillsNotIn(orgId: string, keepSlugs: string[]): string[] {
|
||||
const keep = new Set(keepSlugs);
|
||||
const active = this.db.prepare("select id, slug from skill_definitions where org_id = ? and status = 'active'")
|
||||
.all(orgId) as Array<{ id: string; slug: string }>;
|
||||
const retired: string[] = [];
|
||||
for (const skill of active) {
|
||||
if (keep.has(skill.slug)) continue;
|
||||
this.db.prepare("update skill_definitions set status = 'retired' where id = ?").run(skill.id);
|
||||
this.audit.record({
|
||||
orgId,
|
||||
entityType: "skill_definition",
|
||||
entityId: skill.id,
|
||||
actorType: "system",
|
||||
actorId: null,
|
||||
action: "retired",
|
||||
payload: { slug: skill.slug, reason: "not_in_builtin_bundle" },
|
||||
});
|
||||
retired.push(skill.slug);
|
||||
}
|
||||
return retired;
|
||||
}
|
||||
|
||||
importManifest(orgId: string, directoryPath: string, manifest: SkillManifest, explicitSlug?: string): string {
|
||||
const slug = explicitSlug ?? slugify(manifest.name);
|
||||
if (!slug) throw new Error("Skill name could not be derived.");
|
||||
|
||||
Reference in new issue
Block a user