-
Notifications
You must be signed in to change notification settings - Fork 30
feat(agent-skills): manage app agent skills from the CLI #575
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
14c6376
feat(agent-skills): add skill schema and markdown file I/O
yardend-wix 89e3754
fix(agent-skills): export skill API schemas and name regex
yardend-wix ef3bb3e
feat(agent-skills): add reconcile push API and resource
yardend-wix 8cfae69
fix(agent-skills): export fetchAgentSkills and skill schemas
yardend-wix 1c2cf11
feat(agents): make selected_skill_names a first-class field
yardend-wix 766b97c
feat(agent-skills): load skills into project config
yardend-wix e0cb3ea
feat(agent-skills): deploy skills before agents
yardend-wix 89f00c8
feat(agent-skills): add pull/push commands
yardend-wix c64b65f
fix(agent-skills): guard empty push to prevent deploy deleting all re…
yardend-wix 3594d8c
feat(agent-skills): scaffold example skill and document resource
yardend-wix 97dccae
docs(agent-skills): trim resources.md section to match contributor-do…
yardend-wix 9061da2
refactor(agent-skills): align user-facing messages with agents comman…
yardend-wix 6d1194a
chore(agent-skills): drop ponytail comment on reconcile push
yardend-wix 925c0c4
Merge remote-tracking branch 'origin/main' into feat/agent-skills-cli
yardend-wix 2e3a871
feat(agent-skills): confirm before destructive push (parity with agen…
yardend-wix 915bed4
docs(agent-skills): drop the behavior-details paragraph from resource…
yardend-wix acbb069
chore(agent-skills): remove ponytail comment from frontmatter parser
yardend-wix 185208d
test(agent-skills): close coverage gaps and align with test conventions
yardend-wix fa71ed6
refactor(agent-skills): address review — use front-matter lib, drop s…
yardend-wix 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { Command } from "commander"; | ||
| import { getAgentSkillsPullCommand } from "./pull.js"; | ||
| import { getAgentSkillsPushCommand } from "./push.js"; | ||
|
|
||
| export function getAgentSkillsCommand(): Command { | ||
| return new Command("agent-skills") | ||
| .description("Manage project agent skills") | ||
| .addCommand(getAgentSkillsPushCommand()) | ||
| .addCommand(getAgentSkillsPullCommand()); | ||
| } |
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,50 @@ | ||
| import { dirname, join } from "node:path"; | ||
| import type { Command } from "commander"; | ||
| import type { CLIContext, RunCommandResult } from "@/cli/types.js"; | ||
| import { Base44Command } from "@/cli/utils/index.js"; | ||
| import { readProjectConfig } from "@/core/index.js"; | ||
| import { | ||
| fetchAgentSkills, | ||
| writeAgentSkills, | ||
| } from "@/core/resources/agent-skill/index.js"; | ||
|
|
||
| async function pullAction({ | ||
| log, | ||
| runTask, | ||
| }: CLIContext): Promise<RunCommandResult> { | ||
| const { project } = await readProjectConfig(); | ||
| const dir = join(dirname(project.configPath), project.agentSkillsDir); | ||
|
|
||
| const remote = await runTask( | ||
| "Fetching agent skills from Base44", | ||
| () => fetchAgentSkills(), | ||
| { | ||
| successMessage: "Agent skills fetched successfully", | ||
| errorMessage: "Failed to fetch agent skills", | ||
| }, | ||
| ); | ||
|
|
||
| const { written, deleted } = await runTask( | ||
| "Syncing skill files", | ||
| () => writeAgentSkills(dir, remote.items), | ||
| { | ||
| successMessage: "Skill files synced successfully", | ||
| errorMessage: "Failed to sync skill files", | ||
| }, | ||
| ); | ||
|
|
||
| if (written.length > 0) log.success(`Written: ${written.join(", ")}`); | ||
| if (deleted.length > 0) log.warn(`Deleted: ${deleted.join(", ")}`); | ||
| if (written.length === 0 && deleted.length === 0) | ||
| log.info("All skills are already up to date"); | ||
|
|
||
| return { outroMessage: `Pulled ${remote.total} agent skills to ${dir}` }; | ||
| } | ||
|
|
||
| export function getAgentSkillsPullCommand(): Command { | ||
| return new Base44Command("pull") | ||
| .description( | ||
| "Pull agent skills from Base44 to local files (replaces all local agent skills)", | ||
| ) | ||
| .action(pullAction); | ||
| } |
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,60 @@ | ||
| import type { Command } from "commander"; | ||
| import type { CLIContext, RunCommandResult } from "@/cli/types.js"; | ||
| import { Base44Command, confirmPush } from "@/cli/utils/index.js"; | ||
| import { readProjectConfig } from "@/core/index.js"; | ||
| import { pushAgentSkills } from "@/core/resources/agent-skill/index.js"; | ||
|
|
||
| interface PushOptions { | ||
| yes?: boolean; | ||
| } | ||
|
|
||
| async function pushAction( | ||
| { isNonInteractive, log, runTask }: CLIContext, | ||
| options: PushOptions, | ||
| ): Promise<RunCommandResult> { | ||
| const { agentSkills } = await readProjectConfig(); | ||
|
|
||
| log.info( | ||
| agentSkills.length === 0 | ||
| ? "No local agent skills found - this will delete all remote skills" | ||
| : `Found ${agentSkills.length} agent skills to push`, | ||
| ); | ||
|
|
||
| const proceed = await confirmPush({ | ||
| isNonInteractive, | ||
| yes: options.yes, | ||
| log, | ||
| warning: | ||
| "This will replace all remote agent skills with your local skills and delete any not present locally.", | ||
| }); | ||
| if (!proceed) { | ||
| return { outroMessage: "Push cancelled" }; | ||
| } | ||
|
|
||
| const result = await runTask( | ||
| "Pushing agent skills to Base44", | ||
| () => pushAgentSkills(agentSkills), | ||
| { | ||
| successMessage: "Agent skills pushed successfully", | ||
| errorMessage: "Failed to push agent skills", | ||
| }, | ||
| ); | ||
|
|
||
| if (result.created.length > 0) | ||
| log.success(`Created: ${result.created.join(", ")}`); | ||
| if (result.updated.length > 0) | ||
| log.success(`Updated: ${result.updated.join(", ")}`); | ||
| if (result.deleted.length > 0) | ||
| log.warn(`Deleted: ${result.deleted.join(", ")}`); | ||
|
|
||
| return { outroMessage: "Agent skills pushed to Base44" }; | ||
| } | ||
|
|
||
| export function getAgentSkillsPushCommand(): Command { | ||
| return new Base44Command("push") | ||
| .description( | ||
| "Push local agent skills to Base44 (replaces all remote agent skills)", | ||
| ) | ||
| .option("-y, --yes", "Skip confirmation prompt") | ||
| .action(pushAction); | ||
| } |
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
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,72 @@ | ||
| import type { KyResponse } from "ky"; | ||
| import { getAppClient } from "@/core/clients/index.js"; | ||
| import { ApiError, SchemaValidationError } from "@/core/errors.js"; | ||
| import type { | ||
| AgentSkill, | ||
| ListAgentSkillsResponse, | ||
| SyncAgentSkillsResult, | ||
| } from "./schema.js"; | ||
| import { ListAgentSkillsResponseSchema } from "./schema.js"; | ||
|
|
||
| export async function fetchAgentSkills(): Promise<ListAgentSkillsResponse> { | ||
| const appClient = getAppClient(); | ||
| let response: KyResponse; | ||
| try { | ||
| response = await appClient.get("agent-skills"); | ||
| } catch (error) { | ||
| throw await ApiError.fromHttpError(error, "fetching agent skills"); | ||
| } | ||
| const result = ListAgentSkillsResponseSchema.safeParse(await response.json()); | ||
| if (!result.success) { | ||
| throw new SchemaValidationError( | ||
| "Invalid response from server", | ||
| result.error, | ||
| ); | ||
| } | ||
| return result.data; | ||
| } | ||
|
|
||
| export async function pushAgentSkills( | ||
| skills: AgentSkill[], | ||
| ): Promise<SyncAgentSkillsResult> { | ||
| if (skills.length === 0) { | ||
| return { created: [], updated: [], deleted: [] }; | ||
| } | ||
|
|
||
| const appClient = getAppClient(); | ||
| const remote = await fetchAgentSkills(); | ||
| const remoteByName = new Map(remote.items.map((s) => [s.name, s])); | ||
| const localNames = new Set(skills.map((s) => s.name)); | ||
|
|
||
| const created: string[] = []; | ||
| const updated: string[] = []; | ||
| const deleted: string[] = []; | ||
|
|
||
| try { | ||
| for (const skill of skills) { | ||
| const prev = remoteByName.get(skill.name); | ||
| if (!prev) { | ||
| await appClient.post("agent-skills", { json: skill }); | ||
| created.push(skill.name); | ||
| } else if ( | ||
| prev.description !== skill.description || | ||
| prev.body !== skill.body | ||
| ) { | ||
| await appClient.put(`agent-skills/${skill.name}`, { | ||
| json: { description: skill.description, body: skill.body }, | ||
| }); | ||
| updated.push(skill.name); | ||
| } | ||
| } | ||
| for (const remoteSkill of remote.items) { | ||
| if (!localNames.has(remoteSkill.name)) { | ||
| await appClient.delete(`agent-skills/${remoteSkill.name}`); | ||
| deleted.push(remoteSkill.name); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| throw await ApiError.fromHttpError(error, "syncing agent skills"); | ||
| } | ||
|
|
||
| return { created, updated, deleted }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.