-
Notifications
You must be signed in to change notification settings - Fork 16
feat: add skill CLI command and .opencode/tools/ auto-discovery
#342
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
Open
anandgupta42
wants to merge
8
commits into
main
Choose a base branch
from
feat/skill-cli-extension-ecosystem
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,459
−22
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1c5d575
feat: add `skill` CLI command and `.opencode/tools/` auto-discovery (…
anandgupta42 ca6ad23
fix: address code review findings for skill CLI (#341)
anandgupta42 4ff95df
feat: enrich TUI skill dialog with source and paired tools (#341)
anandgupta42 0beca8d
fix: improve skill list UX and TUI dialog (#341)
anandgupta42 50b7098
feat: add edit and test actions to TUI skills dialog (#341)
anandgupta42 4bb5474
feat: add `skill install` and `skill show` commands (#341)
anandgupta42 91dccd1
feat: align TUI skill operations with CLI commands (#341)
anandgupta42 16050f3
fix: final validation fixes from release testing (#341)
anandgupta42 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // altimate_change start — shared helpers for skill CLI commands | ||
| import path from "path" | ||
| import fs from "fs/promises" | ||
| import { Global } from "@/global" | ||
| import { Instance } from "../../project/instance" | ||
|
|
||
| /** Shell builtins, common utilities, and agent tool names to filter when detecting CLI tool references. */ | ||
| export const SHELL_BUILTINS = new Set([ | ||
| // Shell builtins | ||
| "echo", "cd", "export", "set", "if", "then", "else", "fi", "for", "do", "done", | ||
| "case", "esac", "printf", "source", "alias", "read", "local", "return", "exit", | ||
| "break", "continue", "shift", "trap", "type", "command", "builtin", "eval", "exec", | ||
| "test", "true", "false", | ||
| // Common CLI utilities (not user tools) | ||
| "cat", "grep", "awk", "sed", "rm", "cp", "mv", "mkdir", "ls", "chmod", "which", | ||
| "curl", "wget", "pwd", "touch", "head", "tail", "sort", "uniq", "wc", "tee", | ||
| "xargs", "find", "tar", "gzip", "unzip", "git", "npm", "yarn", "bun", "pip", | ||
| "python", "python3", "node", "bash", "sh", "zsh", "docker", "make", | ||
| // System utilities unlikely to be user tools | ||
| "sudo", "kill", "ps", "env", "whoami", "id", "date", "sleep", "diff", "less", "more", | ||
| // Agent tool names that appear in skill content but aren't CLI tools | ||
| "glob", "write", "edit", | ||
| ]) | ||
|
|
||
| /** Detect CLI tool references inside a skill's content (bash code blocks mentioning executables). */ | ||
| export function detectToolReferences(content: string): string[] { | ||
| const tools = new Set<string>() | ||
|
|
||
| // Match "Tools used: bash (runs `altimate-dbt` commands), ..." | ||
| const toolsUsedMatch = content.match(/Tools used:\s*(.+)/i) | ||
| if (toolsUsedMatch) { | ||
| const refs = toolsUsedMatch[1].matchAll(/`([a-z][\w-]*)`/gi) | ||
| for (const m of refs) { | ||
| if (!SHELL_BUILTINS.has(m[1])) tools.add(m[1]) | ||
| } | ||
| } | ||
|
|
||
| // Match executable names in bash code blocks: lines starting with an executable name | ||
| const bashBlocks = content.matchAll(/```(?:bash|sh)\r?\n([\s\S]*?)```/g) | ||
| for (const block of bashBlocks) { | ||
| const lines = block[1].split("\n") | ||
| for (const line of lines) { | ||
| const trimmed = line.trim() | ||
| if (!trimmed || trimmed.startsWith("#")) continue | ||
| // Extract the first word (the command) | ||
| const cmdMatch = trimmed.match(/^(?:\$\s+)?([a-z][\w.-]*(?:-[\w]+)*)/i) | ||
| if (cmdMatch) { | ||
| const cmd = cmdMatch[1] | ||
| if (!SHELL_BUILTINS.has(cmd)) { | ||
| tools.add(cmd) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return Array.from(tools) | ||
| } | ||
|
|
||
| /** Determine the source label for a skill based on its location. */ | ||
| export function skillSource(location: string): string { | ||
| if (location.startsWith("builtin:")) return "builtin" | ||
| const home = Global.Path.home | ||
| // Builtin skills shipped with altimate-code | ||
| if (location.startsWith(path.join(home, ".altimate", "builtin"))) return "builtin" | ||
| // Global user skills (~/.claude/skills/, ~/.agents/skills/, ~/.config/altimate-code/skills/) | ||
| const globalDirs = [ | ||
| path.join(home, ".claude", "skills"), | ||
| path.join(home, ".agents", "skills"), | ||
| path.join(home, ".altimate-code", "skills"), | ||
| path.join(Global.Path.config, "skills"), | ||
| ] | ||
| if (globalDirs.some((dir) => location.startsWith(dir))) return "global" | ||
| // Everything else is project-level | ||
| return "project" | ||
| } | ||
|
|
||
| /** Check if a tool is available on the current PATH (including .opencode/tools/). */ | ||
| export async function isToolOnPath(toolName: string, cwd: string): Promise<boolean> { | ||
| // Check .opencode/tools/ in both cwd and worktree (they may differ in monorepos) | ||
| const dirsToCheck = new Set([ | ||
| path.join(cwd, ".opencode", "tools"), | ||
| path.join(Instance.worktree !== "/" ? Instance.worktree : cwd, ".opencode", "tools"), | ||
| path.join(Global.Path.config, "tools"), | ||
| ]) | ||
|
|
||
| for (const dir of dirsToCheck) { | ||
| try { | ||
| await fs.access(path.join(dir, toolName), fs.constants.X_OK) | ||
| return true | ||
| } catch {} | ||
| } | ||
|
|
||
| // Check system PATH | ||
| const sep = process.platform === "win32" ? ";" : ":" | ||
| const binDir = process.env.ALTIMATE_BIN_DIR | ||
| const pathDirs = (process.env.PATH ?? "").split(sep).filter(Boolean) | ||
| if (binDir) pathDirs.unshift(binDir) | ||
|
|
||
| for (const dir of pathDirs) { | ||
| try { | ||
| await fs.access(path.join(dir, toolName), fs.constants.X_OK) | ||
| return true | ||
| } catch {} | ||
| } | ||
|
|
||
| return false | ||
| } | ||
| // altimate_change end |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a language to this fenced block.
markdownlint is already flagging this fence. Mark it as
text(or the appropriate language) so the docs stay lint-clean.🧰 Tools
🪛 markdownlint-cli2 (0.21.0)
[warning] 130-130: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents