@morehao/dsh-commands 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -29
- package/cordis.patch.yml +6 -0
- package/lib/index.js +137 -0
- package/package.json +37 -6
package/README.md
CHANGED
|
@@ -1,45 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-commands
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一个可扩展的 **dsh 原生斜杠命令集合包**(npm 名 `@morehao/dsh-commands`,仓库目录仍为 `commands-dsh/`)。当前内置 git-kit 的 Git 工作流命令(与 opencode 入口、自然语言入口共用 git-kit 同一实现,单一真源);将来其它 skill 的命令只需往 `lib/index.js` 的 `COMMANDS` 表加条目即可。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## 提供的命令
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
| 命令 | 参数 | 委托的 git-kit 分支 |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| `/git-message` | `<中文描述>`(必填) | commit-message |
|
|
10
|
+
| `/git-commit-push` | 无 | commit-push |
|
|
11
|
+
| `/git-branch` | `<中文描述>`(必填) | branch |
|
|
12
|
+
| `/git-pr-create` | `[目标分支]` | pr-create |
|
|
13
|
+
| `/git-pr-merge` | `[PR/MR 编号]` | pr-merge |
|
|
14
|
+
| `/git-tag` | `[tag名或分支名]` | tag |
|
|
15
|
+
| `/git-slim` | `[保留天数]` | slim |
|
|
16
|
+
| `/git-star-classify` | 无 | star-classify |
|
|
8
17
|
|
|
9
|
-
##
|
|
18
|
+
## 原理(命令 = 意图表)
|
|
10
19
|
|
|
11
|
-
|
|
12
|
-
1. Configure OIDC trusted publishing for the package name `@morehao/dsh-commands`
|
|
13
|
-
2. Enable secure, token-less publishing from CI/CD workflows
|
|
14
|
-
3. Establish provenance for packages published under this name
|
|
20
|
+
每条 dsh 命令注册到 `ctx.commands`(`name`/`description`/`input.hint`/`handler`,即 `CommandDefinition`),出现在 dsh 斜杠菜单。`COMMANDS` 表是**自包含的意图表**:一行声明 = 注册元数据 + 对应的 git-kit 分支 key,**不再读取任何仓库文件**,逻辑与路由唯一真源在 `skills/git-kit`(`SKILL.md` 意图决策树 + `references/` + `scripts/`)。
|
|
15
21
|
|
|
16
|
-
|
|
22
|
+
命令执行时 handler 校验必填输入,然后构造一条 user 消息经 `invocation.agent.followup()` 注入当前会话,由 agent 加载 `git-kit` 并落到对应分支执行——交互确认步骤与自然语言触发 git-kit 完全一致。
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
- 编辑 `skills/git-kit/` 的内容**无需重启**,下次执行即生效。
|
|
25
|
+
- 修改本插件的 `lib/index.js`(含 `COMMANDS` 表)需重启 dsh web 生效。
|
|
19
26
|
|
|
20
|
-
##
|
|
27
|
+
## 安装
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
本插件已发布到 npm(`@morehao/dsh-commands`),可通过 dsh 一条命令安装:
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
```bash
|
|
32
|
+
# 从 npm 安装已发布版本(git-kit skill 仍需由 ai-kit 提供,见下方说明)
|
|
33
|
+
dsh plugin --profile web add @morehao/dsh-commands
|
|
34
|
+
# 重启 dsh web
|
|
35
|
+
```
|
|
28
36
|
|
|
29
|
-
|
|
37
|
+
> **skill 依赖**:插件只声明「命令 → git-kit 分支」意图表,真正的执行授权给 `git-kit` skill。而 dsh 不从 node_modules 扫描 skill,所以仍需把 `skills/git-kit/` 放入 `$DSH_HOME/skills`(默认 `~/.dsh/skills`)。完整一键接入见仓库根 `./scripts/dsh-install.sh`,它同时软链 `skills/*` 并以 `link:`(开发模式,源码改动即生效)方式接入本插件。
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
- Contains no executable code
|
|
33
|
-
- Provides no functionality
|
|
34
|
-
- Should not be installed as a dependency
|
|
35
|
-
- Exists only for administrative purposes
|
|
39
|
+
本地开发 / 测试用 `link:` 方式(源码即时生效):
|
|
36
40
|
|
|
37
|
-
|
|
41
|
+
```bash
|
|
42
|
+
./scripts/dsh-install.sh
|
|
43
|
+
# 重启 dsh web
|
|
44
|
+
```
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
- [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
|
|
41
|
-
- [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
|
|
46
|
+
## 开发
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
- 增删命令:改 `lib/index.js` 的 `COMMANDS` 表即可(每条一行声明);`branch` 值必须与 git-kit `SKILL.md` 决策树的分支 key 一致。
|
|
49
|
+
- 命令与 opencode 侧 `commands-opencode/git/*.md` 是同一 git-kit 的两条入口,只声明意图、不重复逻辑。
|
|
44
50
|
|
|
45
|
-
|
|
51
|
+
## 发布(自动)
|
|
52
|
+
|
|
53
|
+
用 **changesets** 做自动版本管理与发布(见仓库根 `.github/workflows/release.yml` + `.changeset/config.json`):
|
|
54
|
+
|
|
55
|
+
- 每次改动 `lib/index.js` 或 `cordis.patch.yml` 后,在改动所在 PR 里执行
|
|
56
|
+
```bash
|
|
57
|
+
pnpm changeset
|
|
58
|
+
```
|
|
59
|
+
按提示选择 `patch`/`minor`/`major`,会在 `.changeset/` 生成一行版本描述。
|
|
60
|
+
- merge 到 `main` 后,release workflow 自动开「Version Packages」PR;合并它即把新版本发布到 npmjs。
|
|
61
|
+
- **关键约定**:`package.json` 的 `name`(npm 包名)与 `cordis.patch.yml` 的 `insert[0].name`(dsh 启动时 `import()` 的**模块标识符**)必须一致;`lib/index.js` 的 `export const name`(cordis 插件名)与 `cordis.patch.yml` 的 `insert[0].id` 保持一致即可,但与模块标识符解耦。改包名时请三者同步核对。
|
package/cordis.patch.yml
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-commands —— 把 ai-kit 的 git-kit Git 工作流以 dsh 原生命令方式接入(可扩展其他命令)。
|
|
3
|
+
*
|
|
4
|
+
* 架构(命令 = 意图表,单一真源在 git-kit skill):
|
|
5
|
+
* - 逻辑与「意图路由」的唯一真源是 `skills/git-kit`(SKILL.md 意图决策树 +
|
|
6
|
+
* references/ + scripts/)。本插件不复制逻辑,只声明「命令 → git-kit 分支」的
|
|
7
|
+
* 映射表(COMMANDS),是 dsh 斜杠侧的一条薄入口,与 opencode 的
|
|
8
|
+
* `commands-opencode/git/*.md`、自然语言触发互为入口。
|
|
9
|
+
* - 每条命令注册到 ctx.commands(CommandDefinition:name/description/input.hint/
|
|
10
|
+
* handler),出现在 dsh 斜杠菜单;handler 校验必填输入后构造一条 user 消息,
|
|
11
|
+
* 经 invocation.agent.followup() 注入当前会话,让 agent 按 git-kit 对应分支执行。
|
|
12
|
+
* - 本模块自包含:不读取 ai-kit 仓库内任何文件、无路径耦合、不依赖
|
|
13
|
+
* @deepseek-ai/* 运行时 import(消息对象手工构造为官方 createUserMessage 的
|
|
14
|
+
* 契约形状:role/source/content/id 全齐)。改 git-kit skill 无需重启;
|
|
15
|
+
* 改本文件(含 COMMANDS 表)需重启 dsh web。
|
|
16
|
+
*
|
|
17
|
+
* git-kit 分支 key 词汇表(与 SKILL.md 决策树对齐):
|
|
18
|
+
* commit-push / commit-message / branch / pr-create / pr-merge / tag / slim / star-classify
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { randomUUID } from "node:crypto";
|
|
22
|
+
|
|
23
|
+
export const name = "dsh-commands";
|
|
24
|
+
export const inject = ["commands"];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 命令意图表。每条 = 一行声明:注册元数据 + git-kit 分支 key。
|
|
28
|
+
* `branch` 必须与 skills/git-kit/SKILL.md 决策树的分支 key 一致。
|
|
29
|
+
*/
|
|
30
|
+
const COMMANDS = [
|
|
31
|
+
{
|
|
32
|
+
name: "git-message",
|
|
33
|
+
branch: "commit-message",
|
|
34
|
+
hint: "<中文描述>",
|
|
35
|
+
required: true,
|
|
36
|
+
description: "将中文描述转换为 Conventional Commits 格式的 commit message(纯生成,不提交)"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "git-commit-push",
|
|
40
|
+
branch: "commit-push",
|
|
41
|
+
description: "基于代码变更生成 commit message 并自动提交推送到远端;稳定分支(main/master/含 release)时自动创建分支"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "git-branch",
|
|
45
|
+
branch: "branch",
|
|
46
|
+
hint: "<中文描述>",
|
|
47
|
+
required: true,
|
|
48
|
+
description: "基于中文描述生成候选分支名,选择后从基准分支创建并切换"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "git-pr-create",
|
|
52
|
+
branch: "pr-create",
|
|
53
|
+
hint: "[目标分支]",
|
|
54
|
+
description: "基于代码差异向目标仓库创建或更新 PR/MR(自动识别 gh/glab)"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "git-pr-merge",
|
|
58
|
+
branch: "pr-merge",
|
|
59
|
+
hint: "[PR/MR 编号]",
|
|
60
|
+
description: "按编号合并 PR/MR(自动识别 gh/glab),删除原分支,切回主干并更新代码"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "git-tag",
|
|
64
|
+
branch: "tag",
|
|
65
|
+
hint: "[tag名或分支名]",
|
|
66
|
+
description: "查看最新 tag 与来源分支,选择分支与版本号,构建注记 tag 并推送到远端"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "git-slim",
|
|
70
|
+
branch: "slim",
|
|
71
|
+
hint: "[保留天数]",
|
|
72
|
+
description: "将当前 git 仓库瘦身为浅克隆,默认保留最近 30 天历史,保留本地未提交改动"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "git-star-classify",
|
|
76
|
+
branch: "star-classify",
|
|
77
|
+
description: "拉取并分类你自己的 GitHub star 仓库,输出按大类分组的中文 Markdown 清单"
|
|
78
|
+
}
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
/** 构造一条 user 消息(形态与官方 createUserMessage 一致,source 必填,全深冻结)。 */
|
|
82
|
+
function userMessage(text) {
|
|
83
|
+
return Object.freeze({
|
|
84
|
+
role: "user",
|
|
85
|
+
// dsh 的 Message 契约要求 source 字段(读 message.source.kind),缺失会在 agent 回合崩溃。
|
|
86
|
+
source: Object.freeze({ kind: "user" }),
|
|
87
|
+
content: Object.freeze([Object.freeze({ type: "text", text })]),
|
|
88
|
+
id: randomUUID()
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 构造注入当前会话的指令:告知用户请求,并把执行交给 git-kit 的对应分支。
|
|
94
|
+
* git-kit 分支的完整流程(references/ 与 scripts/)由 agent 加载 skill 后自行读取,
|
|
95
|
+
* 这里不复制任何逻辑,只做意图指路。
|
|
96
|
+
*/
|
|
97
|
+
function buildInstruction(def, input) {
|
|
98
|
+
return [
|
|
99
|
+
`【dsh 命令 /${def.name}】`,
|
|
100
|
+
`用户请求:${input.length > 0 ? input : "(未附加说明,按分支流程默认处理)"}`,
|
|
101
|
+
"",
|
|
102
|
+
`请用 skill 工具加载 git-kit,将本次请求视为 ${def.branch} 分支并按该分支的完整流程执行。`,
|
|
103
|
+
"如需用户决策(候选分支名 / PR·MR 编号 / tag 版本号 / 保留天数等),先向用户确认再继续。"
|
|
104
|
+
].join("\n");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function makeHandler(def) {
|
|
108
|
+
return (invocation) => {
|
|
109
|
+
const input = invocation.rawInput.trim();
|
|
110
|
+
if (def.required && input.length === 0) {
|
|
111
|
+
return { kind: "error", text: `Usage: /${def.name} ${def.hint}\n例如:/${def.name} 修复登录超时` };
|
|
112
|
+
}
|
|
113
|
+
const instruction = buildInstruction(def, input);
|
|
114
|
+
try {
|
|
115
|
+
invocation.agent.followup(userMessage(instruction));
|
|
116
|
+
} catch (error) {
|
|
117
|
+
return {
|
|
118
|
+
kind: "error",
|
|
119
|
+
text: `已生成委托指令,但无法交给当前会话执行:${error instanceof Error ? error.message : String(error)}`
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return { kind: "success", text: `已按 git-kit ${def.branch} 分支委托执行 /${def.name},agent 将按流程继续。` };
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function apply(ctx) {
|
|
127
|
+
ctx.effect(function* () {
|
|
128
|
+
for (const def of COMMANDS) {
|
|
129
|
+
yield ctx.commands.register({
|
|
130
|
+
name: def.name,
|
|
131
|
+
description: def.description,
|
|
132
|
+
...(def.hint === undefined ? {} : { input: { hint: def.hint } }),
|
|
133
|
+
handler: makeHandler(def)
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}, "dsh-commands lifecycle");
|
|
137
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morehao/dsh-commands",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "把 ai-kit 的 git-kit Git 工作流以 dsh 原生斜杠命令接入(薄意图表,委托 git-kit skill 执行)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/index.js",
|
|
9
|
+
"./cordis.patch.yml": "./cordis.patch.yml"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"lib",
|
|
13
|
+
"cordis.patch.yml"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "morehao <morehao@qq.com>",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/morehao/ai-kit.git",
|
|
20
|
+
"directory": "commands-dsh"
|
|
21
|
+
},
|
|
5
22
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
23
|
+
"dsh",
|
|
24
|
+
"dsh-plugin",
|
|
25
|
+
"dsh-command",
|
|
26
|
+
"git",
|
|
27
|
+
"git-kit",
|
|
28
|
+
"conventional-commits"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"dsh": {
|
|
37
|
+
"bundle": {
|
|
38
|
+
"patch": "./cordis.patch.yml"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
10
41
|
}
|