Repository navigation
feat: add selective reusable skills #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
carbongotfound
wants to merge
5
commits into
milind-soni:main
from
carbongotfound:feat/selective-skills-registry
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8529afa
feat: add selective reusable skills
carbongotfound e7659f9
Merge remote-tracking branch 'upstream/main' into feat/selective-skil…
carbongotfound 7fc0379
fix: harden skill identifiers and assignments
carbongotfound 5307c5e
fix: serialize skill manager mutations
carbongotfound 5cd1b16
merge: rebase selective skills on current upstream
carbongotfound File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { normalizeSkill, skillPrompt, skillSnapshot } from "./skills.ts"; | ||
|
|
||
| describe("selective skills", () => { | ||
| it("keeps content out of catalog snapshots", () => { | ||
| const skill = normalizeSkill({ id: "write", name: "Writing", instructions: "Secret local guidance", description: "Write clearly" }); | ||
| expect(skillSnapshot(skill)).not.toHaveProperty("instructions"); | ||
| }); | ||
| it("loads only assigned, enabled skills", () => { | ||
| const writing = normalizeSkill({ id: "write", name: "Writing", instructions: "Use short sentences" }); | ||
| const disabled = normalizeSkill({ id: "disabled", name: "Disabled", instructions: "Never show", enabled: false }); | ||
| expect(skillPrompt([writing, disabled], ["write", "disabled", "unknown"])).toContain("Use short sentences"); | ||
| expect(skillPrompt([writing, disabled], ["write", "disabled", "unknown"])).not.toContain("Never show"); | ||
| expect(skillPrompt([writing], [])).toBe(""); | ||
| }); | ||
| it("rejects incomplete skills", () => expect(() => normalizeSkill({ name: "Missing instructions" })).toThrow(/needs a name and instructions/)); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import type { SkillConfig } from "./config.ts"; | ||
|
|
||
| export interface SkillSnapshot { id: string; name: string; description: string; version: string; source: "built-in" | "imported" | "custom" | "taught"; enabled: boolean; } | ||
|
|
||
| export function normalizeSkill(raw: unknown, existingId?: string): SkillConfig { | ||
| if (!raw || typeof raw !== "object") throw new Error("Skill configuration is required"); | ||
| const input = raw as Record<string, unknown>; | ||
| const name = typeof input.name === "string" ? input.name.trim().slice(0, 120) : ""; | ||
| const instructions = typeof input.instructions === "string" ? input.instructions.trim().slice(0, 20_000) : ""; | ||
| if (!name || !instructions) throw new Error("A skill needs a name and instructions"); | ||
| const source = ["built-in", "imported", "custom", "taught"].includes(String(input.source)) ? input.source as SkillConfig["source"] : "custom"; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| return { id: typeof input.id === "string" && input.id ? input.id.slice(0, 100) : existingId ?? crypto.randomUUID(), name, instructions, description: typeof input.description === "string" ? input.description.trim().slice(0, 500) : "", version: typeof input.version === "string" ? input.version.trim().slice(0, 40) : "1", source, enabled: input.enabled !== false }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| export function skillSnapshot(skill: SkillConfig): SkillSnapshot { return { id: skill.id, name: skill.name, description: skill.description ?? "", version: skill.version ?? "1", source: skill.source ?? "custom", enabled: skill.enabled !== false }; } | ||
|
|
||
| /** Inject only enabled skills explicitly assigned to the current bot. */ | ||
| export function skillPrompt(items: SkillConfig[] | undefined, ids: string[] | undefined): string { | ||
| if (!ids?.length) return ""; | ||
| const available = new Map((items ?? []).filter((skill) => skill.enabled !== false).map((skill) => [skill.id, skill])); | ||
| const selected = ids.flatMap((id) => { const skill = available.get(id); return skill ? [`[Skill: ${skill.name}]\n${skill.instructions}`] : []; }); | ||
| return selected.length ? `\n\nFollow these assigned reusable skills when relevant:\n\n${selected.join("\n\n")}` : ""; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { Plus, Trash2 } from "lucide-react"; | ||
| import { useState } from "react"; | ||
| import { api, useStore, type ConfigStatus } from "@/state/store"; | ||
|
|
||
| export function SkillsManager() { | ||
| const { state, dispatch } = useStore(); | ||
| const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [instructions, setInstructions] = useState(""); const [error, setError] = useState<string | null>(null); | ||
| const items = state.config?.skills?.items ?? []; | ||
| const refresh = () => api("/api/config").then((config: ConfigStatus) => dispatch({ type: "configStatus", config })); | ||
| const add = async () => { try { setError(null); await api("/api/skills", { method: "POST", body: JSON.stringify({ name, description, instructions }) }); setName(""); setDescription(""); setInstructions(""); await refresh(); } catch (reason) { setError(reason instanceof Error ? reason.message : "Could not save skill"); } }; | ||
| const toggle = async (id: string, enabled: boolean) => { try { await api(`/api/skills/${id}`, { method: "PATCH", body: JSON.stringify({ enabled: !enabled }) }); await refresh(); } catch (reason) { setError(reason instanceof Error ? reason.message : "Could not update skill"); } }; | ||
| const remove = async (id: string) => { try { await api(`/api/skills/${id}`, { method: "DELETE" }); await refresh(); } catch (reason) { setError(reason instanceof Error ? reason.message : "Could not remove skill"); } }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| const input = "w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:border-hairline focus:outline-none"; | ||
| return <div className="mt-4 rounded-xl bg-card p-4"><div className="text-[15px] font-medium text-ink">Skills library</div><div className="mt-0.5 text-[13px] text-ink-secondary">Reusable local instructions. Enable and assign them per bot.</div><div className="mt-3 flex flex-col gap-2"><input className={input} value={name} onChange={(e) => setName(e.target.value)} placeholder="Skill name" /><input className={input} value={description} onChange={(e) => setDescription(e.target.value)} placeholder="What this skill helps with" /><textarea className={`${input} min-h-[76px] resize-y`} value={instructions} onChange={(e) => setInstructions(e.target.value)} placeholder="Instructions the selected bot should follow" /><button disabled={!name.trim() || !instructions.trim()} onClick={() => void add()} className="flex items-center justify-center gap-1 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-white disabled:opacity-50"><Plus size={14} /> Add skill</button></div>{error && <div className="mt-2 text-[12px] text-danger">{error}</div>}<div className="mt-3 flex flex-col gap-2">{items.length === 0 && <div className="rounded-lg bg-inset px-3 py-2 text-[13px] text-ink-secondary">No skills yet.</div>}{items.map((skill) => <div key={skill.id} className="flex items-start justify-between gap-2 rounded-lg bg-inset px-3 py-2"><div><div className="text-[13px] font-medium text-ink">{skill.name}</div><div className="text-[11px] text-ink-secondary">{skill.description || `${skill.source} · v${skill.version}`}</div></div><div className="flex gap-1"><button onClick={() => void toggle(skill.id, skill.enabled)} className="rounded px-2 py-1 text-[11px] text-ink-secondary hover:bg-raised">{skill.enabled ? "On" : "Off"}</button><button onClick={() => void remove(skill.id)} className="rounded p-1 text-danger hover:bg-raised" aria-label={`Remove ${skill.name}`}><Trash2 size={14} /></button></div></div>)}</div></div>; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.