Skip to content

Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.

Give a package skill's slug the shape the skills API accepts (#688)

Omkar Chebalea98cf5382eda
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7decbee8..6c5401d0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,14 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.
## Unreleased
+### A package skill's slug has the same shape as one made in the app
+
+The skills screen, the skills API and the store all accept a slug of 2 to 40 lowercase letters,
+digits and hyphens that starts and ends with a letter or digit. `skills.yaml` accepted any length
+and a trailing hyphen, so a package could seed `a`, `a-` or a sixty-character slug that nobody
+could then edit. A package with such a slug is now refused at load, with a sentence naming it.
+Every slug in `examples/fintech` already has the shape.
+
### A tenant package that repeats itself is refused by name, instead of failing at boot
Validation now refuses each of these, with a sentence naming the file and the repeated id:
diff --git a/server/src/tenant-package.ts b/server/src/tenant-package.ts
index 46ee6423..cdd7455b 100644
--- a/server/src/tenant-package.ts
+++ b/server/src/tenant-package.ts
@@ -653,9 +653,11 @@ function parseTenantSkills(value: unknown): TenantSkill[] {
throw new Error(`skill "${slug}" is declared twice in skills.yaml`);
}
slugs.add(slug);
- if (!/^[a-z0-9][a-z0-9-]*$/.test(slug)) {
+ // The same pattern as the skills route, the store and the app's form. Looser, it seeded slugs
+ // such as `a`, `a-` or sixty characters that none of those would accept or let anybody edit.
+ if (!/^[a-z0-9][a-z0-9-]{0,38}[a-z0-9]$/.test(slug)) {
throw new Error(
- `skill.slug "${slug}" must be lowercase letters, digits and hyphens, and start with a letter or digit`,
+ `skill.slug "${slug}" must be lowercase letters, digits and hyphens, 2 to 40 characters, starting and ending with a letter or digit`,
);
}
const tools =
diff --git a/server/tests/tenant-package-agent-files.test.ts b/server/tests/tenant-package-agent-files.test.ts
index d77349c2..8aab644b 100644
--- a/server/tests/tenant-package-agent-files.test.ts
+++ b/server/tests/tenant-package-agent-files.test.ts
@@ -205,3 +205,25 @@ describe("reading the agents directory from disk", () => {
await rm(directory, { recursive: true, force: true });
});
});
+
+describe("a package skill's slug", () => {
+ const withSkill = (slug: string) =>
+ validateTenantPackage({
+ ...base,
+ skills: `skills: [{ slug: "${slug}", title: T, summary: S, instructions: I }]`,
+ });
+
+ test.each(["find-a-document", "a1", "x".repeat(40)])(
+ "%s has the shape the skills API accepts",
+ (slug) => {
+ expect(withSkill(slug).skills.map((skill) => skill.slug)).toEqual([slug]);
+ },
+ );
+
+ test.each(["a", "a-", "-a", "x".repeat(41)])(
+ "%s is refused, as the skills API would refuse it",
+ (slug) => {
+ expect(() => withSkill(slug)).toThrow(`skill.slug "${slug}" must be`);
+ },
+ );
+});