Template-driven file and directory generator for project workflows
Project description
sprout CLI (v0.1)
sprout 是一个项目内模板驱动的文件/目录生成 CLI,面向 Agent 协同开发场景。
核心特性
- 发现规则:从当前目录向上查找首个
.sprout/(类似.git) - 命令包目录:
.sprout/commands/<command>/ - 默认 authoring 格式:YAML(便于注释、示例和值说明)
- 输入模式:支持
key=value、--json、--json-file;TTY 下缺参可引导进入交互 - 基础类型:
string/number/enum(number支持可选min/max) - 插值语法:支持输入变量、时间变量、
assets.<ref>.<suffix>、rand.str[:N]/rand.num[:N](仅纯文本替换,不支持逻辑流) - 可选 post-action:生成完成后执行
run: [...]或shell: "..." - 冲突策略:
fail/overwrite/skip/rename init支持自定义骨架、可选示例命令包,并生成项目内sprout-authoringSkill 文档- 运行时兼容
yaml/yml/json配置与 manifest
快速开始
# 0) 可选:安装 YAML 支持(推荐)
uv add --optional yaml
# 或使用 pip: pip install pyyaml
# 1) 初始化
sprout init --with-examples
# 2) 查看命令
sprout list --all
# 3) 执行命令(默认参数模式,使用 = 连接键值)
sprout new issue name=my-task type=bug
# 4) 结构化输入(适合 Agent / 长文本 / 含空格值)
sprout new issue --json '{"name":"my task","type":"bug"}'
sprout new issue --json-file ./inputs.json
# 5) 交互模式
sprout new issue -i
# 或者直接 `sprout new issue`
# 若当前终端是 TTY 且缺少必填参数,sprout 会先询问是否进入交互模式
# 交互中可输入 q / quit / exit 取消
# 6) 预览模式(不实际创建文件)
sprout new issue name=test type=feat --dry-run
命令
sprout init [--profile minimal|docs] [--profile-file ./profile.json] [--with-examples]
sprout list [--all]
sprout doctor
sprout new <command> [key=value ...] [--json '{...}' | --json-file ./inputs.json] [--set key=value] [-i|--interactive] [--no-input] [-n|--dry-run] [--conflict fail|overwrite|skip|rename]
.sprout/ 结构
.sprout/
config.yaml
commands/
issue/
manifest.yaml
issue.md
skills/
sprout-authoring/
SKILL.md
如何填写 .sprout/config.yaml
# sprout project defaults
version: 1
# Default conflict policy for generated assets.
# Allowed: fail | overwrite | skip | rename
conflict: fail
字段说明:
version:整数,当前固定为1conflict:项目级默认冲突策略;可选fail/overwrite/skip/rename
如何填写 manifest.yaml
name: issue
description: Create issue
# Optional per-command conflict override.
# If omitted, sprout uses `.sprout/config.yaml`.
conflict: fail
inputs:
- name: name
type: string
required: true
description: Issue slug
- name: type
type: enum
enum:
- bug
- feat
- refactor
default: bug
description: Issue category
- name: priority
type: number
required: false
min: 1
max: 5
default: 3
description: Optional priority
assets:
- type: dir
path: issues
ref: issues_dir
- type: file
path: "{{assets.issues_dir.rel_path}}/{{YY}}-{{MM}}-{{DD}}_{{name}}-{{rand.str:6}}.md"
template: issue.md
ref: issue_file
actions:
- phase: post
run: ["git", "status"]
cwd: "{{project.root}}"
字段说明
inputs[*]
name:必填,且在同一命令内唯一type:string/number/enumrequired:可选,默认truedescription:可选,但建议填写,方便 Agent 理解用途default:可选默认值enum:当type: enum时必填min/max:仅number类型可用
assets[*]
type:dir或filepath:项目内相对路径template:文件资产引用的模板文件,路径相对当前命令目录content:简单文件可直接内联内容;与template二选一即可ref:可选资源引用名,供后续 asset 或 action 使用;同一命令内必须唯一
actions[*]
phase:当前仅支持postrun:推荐写法,参数数组形式执行命令shell:便捷写法,执行单条 shell 命令cwd:可选工作目录;支持模板插值,且必须仍在项目根目录内run/shell必须二选一
变量上下文
除了输入变量,内置时间变量:
YYYY,YY,MM,DDhh,mm,ssdate,time,datetime,timestamp
还支持:
project.root:项目根目录绝对路径project.root_name:项目根目录名rand.str/rand.str:N:随机字母数字串,默认长度8rand.num/rand.num:N:随机数字串,默认长度8
Asset 引用变量
当 asset 定义了 ref 后,可在后续 asset 与 actions 中使用:
assets.<ref>.abs_pathassets.<ref>.rel_pathassets.<ref>.nameassets.<ref>.parent_absassets.<ref>.parent_rel
规则:
- 在
assets[*].path中,只允许引用前面已定义的ref - 在
assets[*].path中,必须显式写后缀,推荐{{assets.<ref>.rel_path}} - 在
actions[*]中,允许直接写{{assets.<ref>}},默认等价于{{assets.<ref>.abs_path}} - 所有路径变量字符串统一使用
/分隔符
冲突策略说明
当生成的文件或目录已存在时,sprout 会根据冲突策略处理:
fail(默认):报错并停止skip:跳过已存在的文件overwrite:覆盖已存在的文件rename:重命名新文件(添加_02、_03等后缀)
目录特殊处理:目录被视为容器而非内容,已存在的目录会自动复用(REUSE),不受冲突策略影响。只有文件冲突才会应用冲突策略。
示例:
# 第一次执行
sprout new issue name=test type=bug
# 输出:
# + CREATE issues
# + CREATE issues/26-04-11_test.md
# 第二次执行(目录已存在)
sprout new issue name=another type=feat
# 输出:
# = REUSE issues # 目录自动复用
# + CREATE issues/26-04-11_another.md
# 第三次执行(文件冲突)
sprout new issue name=another type=feat
# 输出:
# Error: Target already exists: issues/26-04-11_another.md
# Hint: Use --conflict=skip or --conflict=overwrite
Action 输出示例
sprout new issue name=test --dry-run
# 输出:
# [DRY-RUN] Executed command: issue
# [DRY-RUN] Conflict policy: fail
# [DRY-RUN] + CREATE issues
# [DRY-RUN] + CREATE issues/26-04-12_test-a1B2c3.md
# [DRY-RUN] > ACTION [post] git status (cwd=.)
交互与 Agent 调用建议
- TTY 下缺参:sprout 会先说明缺了哪些字段,再询问是否进入交互模式
- 非 TTY 下缺参:sprout 不会等待输入,而是直接失败,避免脚本或 Agent 卡住
- 显式
-i但非 TTY:会报错Interactive mode requires a TTY - 复杂输入:优先使用
--json或--json-file,比 shell 中拼接key=value更稳 - 临时覆盖:可在
--json/--json-file基础上再用--set key=value覆盖字段
Agent authoring 建议
如果让 Agent 帮你写 .sprout,先让它读取:
.sprout/skills/sprout-authoring/SKILL.md
然后先对齐:
- 命令目的
- 输入字段及类型
- 输出文件/目录
- 冲突策略
不要一上来直接让 Agent 写 manifest。
常见问题
- 找不到项目模板根:确认当前目录或父目录存在
.sprout/ - 命令不可用:执行
sprout doctor检查 invalid/conflict 报告 - YAML 无法读取:安装
PyYAML,或改用 JSON
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sprout_files-0.4.0.tar.gz.
File metadata
- Download URL: sprout_files-0.4.0.tar.gz
- Upload date:
- Size: 772.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e36ffe2769e69b57c72d5d6815834ebbee22e1a03a8d1a12d5511e5b0fe7aeb3
|
|
| MD5 |
51b38842677721b5b894ccca3e04bbf0
|
|
| BLAKE2b-256 |
a602e96d2fa79aa5ecdd691ab02191ea2a14348c33d176745fedc92f6d17460b
|
File details
Details for the file sprout_files-0.4.0-py3-none-any.whl.
File metadata
- Download URL: sprout_files-0.4.0-py3-none-any.whl
- Upload date:
- Size: 42.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
671929d3ae056b1112aad6f746112806715c0ce40bc5ecea865613fd429fca2a
|
|
| MD5 |
0d0a8158d858a3c0a99926cb79352c41
|
|
| BLAKE2b-256 |
ee1e6eaa9c9c587751d5930011bd7a8078cfa4db9c7a354d892d642650561eb5
|