fix: refresh skills block when reusing existing block (#135)

This commit is contained in:
mruderman
2025-12-03 13:07:32 -08:00
committed by GitHub
parent baf3faf969
commit 35e0282281

View File

@@ -156,6 +156,9 @@ export async function createAgent(
? defaultMemoryBlocks.filter((b) => allowedBlockLabels.has(b.label))
: defaultMemoryBlocks;
// Cache the formatted skills block value so we can update an existing block
let skillsBlockValue: string | undefined;
// Resolve absolute path for skills directory
const resolvedSkillsDirectory =
skillsDirectory || join(process.cwd(), SKILLS_DIR);
@@ -175,10 +178,9 @@ export async function createAgent(
// Find and update the skills memory block with discovered skills
const skillsBlock = filteredMemoryBlocks.find((b) => b.label === "skills");
if (skillsBlock) {
skillsBlock.value = formatSkillsForMemory(
skills,
resolvedSkillsDirectory,
);
const formatted = formatSkillsForMemory(skills, resolvedSkillsDirectory);
skillsBlock.value = formatted;
skillsBlockValue = formatted;
}
} catch (error) {
console.warn(
@@ -246,7 +248,19 @@ export async function createAgent(
for (const defaultBlock of filteredMemoryBlocks) {
const existingBlock = existingBlocks.get(defaultBlock.label);
if (existingBlock?.id) {
// Reuse existing shared block
// Reuse existing global/shared block, but refresh skills content if it changed
if (defaultBlock.label === "skills" && skillsBlockValue !== undefined) {
try {
await client.blocks.update(existingBlock.id, {
value: skillsBlockValue,
});
} catch (error) {
console.warn(
`Failed to update skills block ${existingBlock.id}:`,
error instanceof Error ? error.message : String(error),
);
}
}
blockIds.push(existingBlock.id);
// Record provenance based on where it came from
if (globalBlockLabels.has(defaultBlock.label)) {