diff --git a/src/main/services/skill-service.ts b/src/main/services/skill-service.ts index 1ec573e7..2b6bb4e4 100644 --- a/src/main/services/skill-service.ts +++ b/src/main/services/skill-service.ts @@ -284,7 +284,7 @@ export class SkillService { readFileSync(row.object_key, "utf8").trim(), ].join("\n\n"); const partTokens = estimateTokens(part); - if (compiledParts.length > 0 && compiledTokens + partTokens > input.maxTokens) { + if (compiledTokens + partTokens > input.maxTokens) { omitted.push(manifest.name); continue; } diff --git a/tests/unit/builtin-skills.test.ts b/tests/unit/builtin-skills.test.ts index 8b40a4f7..a03c9d8e 100644 --- a/tests/unit/builtin-skills.test.ts +++ b/tests/unit/builtin-skills.test.ts @@ -247,4 +247,23 @@ describe("built-in skills", () => { expect(parseFrontmatter(HUMANIZER_MD).description).toContain("sound more natural and human-written"); expect(parseFrontmatter("no frontmatter")).toEqual({}); }); + + test("no skill, not even the first forced one, may exceed the skill budget", () => { + const h = harness(); + const staged = stageBuiltinSkillsLibrary(h.sourceRoot, h.libraryRoot); + h.connection.transaction(() => importStagedSkills(h.skills, h.orgId, staged)); + let agentId = ""; + h.connection.transaction(() => { + agentId = h.organization.createAgent({ + orgId: h.orgId, name: "Ada", role: "Engineer", department: "Engineering", + modelProviderId: null, modelId: null, budgetCents: 1000, managerAgentId: null, + }); + }); + const snapshotId = h.connection.transaction(() => h.skills.resolveRuntimeSnapshot({ orgId: h.orgId, agentId, runId: "run_tiny", maxTokens: 10 })); + const prompt = (h.connection.db.prepare("select compiled_prompt from skill_runtime_snapshots where id = ?").get(snapshotId) as { compiled_prompt: string }).compiled_prompt; + expect(prompt).not.toContain("# Skill:"); + expect(prompt).toContain("# Skills omitted for size"); + expect(prompt).toContain("humanizer"); + h.connection.close(); + }); });