{"id":34979191,"url":"https://github.com/lwmacct/251215-go-pkg-scmd","last_synced_at":"2026-04-27T02:33:37.689Z","repository":{"id":329937337,"uuid":"1120984653","full_name":"lwmacct/251215-go-pkg-scmd","owner":"lwmacct","description":"为 Go 语言 AI Agent 生态提供 Claude Code slash-commands 兼容加载能力","archived":false,"fork":false,"pushed_at":"2025-12-22T11:41:35.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-23T22:46:43.974Z","etag":null,"topics":["claude","claude-code"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lwmacct.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-22T08:56:41.000Z","updated_at":"2025-12-22T11:43:21.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/lwmacct/251215-go-pkg-scmd","commit_stats":null,"previous_names":["lwmacct/251215-go-pkg-scmd"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/lwmacct/251215-go-pkg-scmd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwmacct%2F251215-go-pkg-scmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwmacct%2F251215-go-pkg-scmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwmacct%2F251215-go-pkg-scmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwmacct%2F251215-go-pkg-scmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lwmacct","download_url":"https://codeload.github.com/lwmacct/251215-go-pkg-scmd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwmacct%2F251215-go-pkg-scmd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32320508,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["claude","claude-code"],"created_at":"2025-12-27T00:51:42.143Z","updated_at":"2026-04-27T02:33:37.682Z","avatar_url":"https://github.com/lwmacct.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scmd\n\nGo 语言的 Claude Code Slash Commands 加载和管理库。\n\n[![License](https://img.shields.io/github/license/lwmacct/251215-go-pkg-scmd)](LICENSE)\n[![Go Reference](https://pkg.go.dev/badge/github.com/lwmacct/251215-go-pkg-scmd.svg)](https://pkg.go.dev/github.com/lwmacct/251215-go-pkg-scmd)\n[![Go CI](https://github.com/lwmacct/251215-go-pkg-scmd/actions/workflows/go-ci.yml/badge.svg)](https://github.com/lwmacct/251215-go-pkg-scmd/actions/workflows/go-ci.yml)\n[![codecov](https://codecov.io/gh/lwmacct/251215-go-pkg-scmd/branch/main/graph/badge.svg)](https://codecov.io/gh/lwmacct/251215-go-pkg-scmd)\n[![Go Report Card](https://goreportcard.com/badge/github.com/lwmacct/251215-go-pkg-scmd)](https://goreportcard.com/report/github.com/lwmacct/251215-go-pkg-scmd)\n[![GitHub Tag](https://img.shields.io/github/v/tag/lwmacct/251215-go-pkg-scmd?sort=semver)](https://github.com/lwmacct/251215-go-pkg-scmd/tags)\n\n\u003c!--TOC--\u003e\n\n## Table of Contents\n\n- [Features](#features) `:31+11`\n- [Installation](#installation) `:42+6`\n- [Quick Start](#quick-start) `:48+48`\n  - [Basic Usage](#basic-usage) `:50+23`\n  - [Using Presets](#using-presets) `:73+23`\n- [API Reference](#api-reference) `:96+56`\n  - [Manager](#manager) `:98+14`\n  - [Options](#options) `:112+18`\n  - [Presets](#presets) `:130+22`\n- [Command File Format](#command-file-format) `:152+41`\n- [Development](#development) `:193+16`\n- [Related Links](#related-links) `:209+5`\n\n\u003c!--TOC--\u003e\n\n## Features\n\n- 兼容 Claude Code 的 slash commands 格式\n- 支持项目命令 (`.claude/commands/`)、个人命令 (`~/.claude/commands/`)、插件命令\n- 自动处理命令优先级：Project \u003e Personal \u003e Plugin\n- 支持 YAML frontmatter 元数据解析\n- 参数占位符替换：`$ARGUMENTS`、`$1`、`${N}`\n- Bash 命令执行：`!`\\`command\\``\n- 文件引用解析：`@path/to/file`\n- 预设配置模式，简化初始化\n\n## Installation\n\n```shell\ngo get github.com/lwmacct/251215-go-pkg-scmd\n```\n\n## Quick Start\n\n### Basic Usage\n\n```go\npackage main\n\nimport \"github.com/lwmacct/251215-go-pkg-scmd/pkg/scmd\"\n\nfunc main() {\n    // 创建管理器（自动检测目录）\n    mgr := scmd.NewDefault()\n    mgr.Reload()\n\n    // 列出所有命令\n    for _, cmd := range mgr.List() {\n        fmt.Printf(\"/%s - %s\\n\", cmd.FullName(), cmd.GetDescription())\n    }\n\n    // 执行命令\n    result, _ := mgr.Execute(\"review\", []string{\"file.go\"})\n    fmt.Println(result)\n}\n```\n\n### Using Presets\n\n```go\n// 默认预设\nmgr := scmd.New(scmd.PresetDefault()...)\n\n// 指定项目目录\nmgr := scmd.New(scmd.PresetProject(\"/path/to/project\")...)\n\n// 安全模式（禁用 Bash 执行）\nmgr := scmd.New(scmd.PresetSafe()...)\n\n// 组合预设\nmgr := scmd.New(append(\n    scmd.PresetProject(\"/myproject\"),\n    scmd.PresetSafe()...,\n)...)\n\n// 从环境变量读取配置\n// SCMD_PROJECT_DIR=/custom SCMD_SAFE_MODE=true\nmgr := scmd.New(scmd.PresetFromEnv()...)\n```\n\n## API Reference\n\n### Manager\n\n```go\n// 构造函数\nNew(opts ...Option) *Manager      // 创建管理器\nNewDefault() *Manager             // 使用默认配置创建\n\n// 方法\nReload() error                    // 重新加载命令\nList() []*Command                 // 列出所有命令\nGet(name string) (*Command, bool) // 获取指定命令\nExecute(name string, args []string) (string, error) // 执行命令\n```\n\n### Options\n\n```go\nWithWorkDir(dir)          // 设置工作目录（自动配置项目命令目录）\nWithHomeDir(dir)          // 设置 home 目录（自动配置个人命令目录）\nWithProjectDir(dir)       // 直接设置项目命令目录\nWithPersonalDir(dir)      // 直接设置个人命令目录\nWithPluginDir(name, dir)  // 添加插件命令目录\nWithBashExecutor(e)       // 自定义 Bash 执行器\nWithFileResolver(r)       // 自定义文件解析器\nWithNoBash()              // 禁用 Bash 执行\nWithNoFileResolve()       // 禁用文件引用解析\nWithBashTimeout(seconds)  // 设置 Bash 超时\nWithBashShell(shell)      // 设置 Shell 路径\nWithBashWorkDir(dir)      // 设置 Bash 执行工作目录\nWithFileBaseDir(dir)      // 设置文件解析器基础目录\n```\n\n### Presets\n\n| 函数                              | 用途                             |\n| --------------------------------- | -------------------------------- |\n| `PresetDefault()`                 | 自动检测工作目录和用户主目录     |\n| `PresetProject(dir)`              | 指定项目目录                     |\n| `PresetFull(projectDir, homeDir)` | 同时配置项目和用户目录           |\n| `PresetSafe()`                    | 禁用 Bash 和文件引用（安全模式） |\n| `PresetNoBash()`                  | 仅禁用 Bash 执行                 |\n| `PresetFromEnv()`                 | 从环境变量读取配置               |\n| `PresetClaudeCode()`              | Claude Code 标准目录结构         |\n\n**环境变量支持：**\n\n| 变量                | 说明                    |\n| ------------------- | ----------------------- |\n| `SCMD_PROJECT_DIR`  | 项目命令目录            |\n| `SCMD_PERSONAL_DIR` | 个人命令目录            |\n| `SCMD_SAFE_MODE`    | `true`/`1` 启用安全模式 |\n| `SCMD_NO_BASH`      | `true`/`1` 禁用 Bash    |\n| `SCMD_BASH_TIMEOUT` | Bash 超时秒数           |\n\n## Command File Format\n\n命令文件为 Markdown 格式（`.md`），支持 YAML frontmatter：\n\n```markdown\n---\ndescription: 命令描述\nargument-hint: \"[file] [options]\"\nallowed-tools:\n  - Read\n  - Write\nmodel: claude-3-5-sonnet\n---\n\n审查 @$1 文件的代码质量。\n\n当前分支: !`git branch --show-current`\n\n参数: $ARGUMENTS\n```\n\n**Frontmatter 字段：**\n\n| 字段                       | 类型     | 说明           |\n| -------------------------- | -------- | -------------- |\n| `description`              | string   | 命令描述       |\n| `argument-hint`            | string   | 参数提示       |\n| `allowed-tools`            | []string | 允许的工具列表 |\n| `model`                    | string   | 指定模型       |\n| `disable-model-invocation` | bool     | 禁止模型调用   |\n\n**占位符语法：**\n\n| 语法             | 说明               |\n| ---------------- | ------------------ |\n| `$ARGUMENTS`     | 所有参数的空格连接 |\n| `$1`, `$2`, `$N` | 位置参数           |\n| `${N}`           | 带花括号的位置参数 |\n| `!`\\`cmd\\``      | 执行 Bash 命令     |\n| `@path`          | 引用文件内容       |\n\n## Development\n\n```shell\n# 初始化开发环境\npre-commit install\n\n# 运行测试\ngo test ./pkg/scmd/... -v\n\n# 运行 lint\ngolangci-lint run ./pkg/scmd/...\n\n# 查看所有任务\ntask -a\n```\n\n## Related Links\n\n- [Claude Code Slash Commands 官方文档](https://docs.anthropic.com/en/docs/claude-code/slash-commands)\n- [Taskfile](https://taskfile.dev) - 项目 CLI 管理\n- [Pre-commit](https://pre-commit.com/) - Git hooks 管理\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flwmacct%2F251215-go-pkg-scmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flwmacct%2F251215-go-pkg-scmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flwmacct%2F251215-go-pkg-scmd/lists"}