-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
33 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 c5e6055
fix: replace fake slash commands with real TUI dialogs for create/ins…
anandgupta42 461fefa
fix: use `process.argv[0]` instead of `"altimate-code"` in TUI subpro…
anandgupta42 f219664
fix: improve TUI error reporting for skill create/install/test (#341)
anandgupta42 1301169
fix: inline skill operations in TUI instead of spawning subprocess (#…
anandgupta42 4cf5800
fix: use async `Bun.spawn` for git clone in TUI install (#341)
anandgupta42 a581e6f
fix: invalidate skill cache after TUI create/install so new skills ap…
anandgupta42 c5c6acf
fix: invalidate server-side skill cache via API after TUI install/cre…
anandgupta42 eb0b88c
fix: improve TUI install/create confirmation UX (#341)
anandgupta42 72f342b
fix: add try/catch and input sanitization to TUI install/create (#341)
anandgupta42 f31d0da
fix: use 10min timeout for in-progress toast so it never disappears b…
anandgupta42 8e48701
feat: show live progress log in TUI install toast (#341)
anandgupta42 6a27faa
fix: remove Instance/Global usage from TUI dialog — use sdk.directory…
anandgupta42 0096aeb
fix: use git root for TUI skill install target directory (#341)
anandgupta42 4c7f19b
feat: add `skill remove` command and ctrl+d in TUI (#341)
anandgupta42 8b1d44d
fix: parse GitHub web URLs and reduce TUI keybind clutter (#341)
anandgupta42 01c9f9b
fix: restore show/test keybinds and wrap footer to fit (#341)
anandgupta42 879f84c
feat: replace 6 keybinds with single ctrl+a action picker (#341)
anandgupta42 1c14ff7
fix: return to skill list after action picker completes (#341)
anandgupta42 3355b6e
fix: open skill editor in system app instead of inline terminal (#341)
anandgupta42 0cb0829
fix: separate per-skill actions from global actions in TUI (#341)
anandgupta42 21e00b1
fix: Esc on action picker goes back to skill list (#341)
anandgupta42 fce05fd
docs: update skills and custom tools docs with all new commands (#341)
anandgupta42 8f918d9
fix: address code review findings from 6-model consensus review (#341)
anandgupta42 8a21f5d
feat: add telemetry for skill create/install/remove (#341)
anandgupta42 e9f7603
fix: strip .git suffix from CLI install source to prevent double-appe…
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
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