dsh-github-flow 0.1.8 → 0.2.1
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.en.md +162 -58
- package/README.md +167 -60
- package/docs/UPGRADE-NOTES.md +93 -0
- package/docs/architecture.md +47 -17
- package/docs/images/1.png +0 -0
- package/docs/images/2.png +0 -0
- package/docs/images/3.png +0 -0
- package/docs/images/4.png +0 -0
- package/docs/npm-publish-guide.md +26 -3
- package/lib/api/route-helpers.d.ts +47 -0
- package/lib/api/route-helpers.js +134 -0
- package/lib/api/routes-actions.d.ts +23 -0
- package/lib/api/routes-actions.js +239 -0
- package/lib/api/routes-lifecycle.d.ts +9 -0
- package/lib/api/routes-lifecycle.js +126 -0
- package/lib/api/routes-overview.d.ts +11 -0
- package/lib/api/routes-overview.js +227 -0
- package/lib/api/routes-proxy.d.ts +18 -0
- package/lib/api/routes-proxy.js +63 -0
- package/lib/api/routes.d.ts +16 -6
- package/lib/api/routes.js +14 -504
- package/lib/client.js +785 -90
- package/lib/commands/gh.js +11 -2
- package/lib/executor.d.ts +17 -0
- package/lib/executor.js +146 -8
- package/lib/main.d.ts +1 -0
- package/lib/main.js +49 -9
- package/lib/proxy.d.ts +87 -0
- package/lib/proxy.js +275 -0
- package/lib/renderers/markdown.d.ts +29 -0
- package/lib/renderers/markdown.js +520 -0
- package/lib/tools/api.d.ts +4 -0
- package/lib/tools/api.js +14 -4
- package/lib/tools/help.d.ts +31 -0
- package/lib/tools/help.js +224 -0
- package/lib/tools/image-utils.d.ts +79 -0
- package/lib/tools/image-utils.js +247 -0
- package/lib/tools/issue.d.ts +40 -4
- package/lib/tools/issue.js +167 -19
- package/lib/tools/pr.d.ts +29 -4
- package/lib/tools/pr.js +144 -18
- package/lib/tools/release.d.ts +89 -0
- package/lib/tools/release.js +219 -0
- package/lib/tools/repo.d.ts +24 -4
- package/lib/tools/repo.js +114 -14
- package/lib/tools/run.d.ts +22 -1
- package/lib/tools/run.js +74 -14
- package/lib/tools/secret.d.ts +60 -0
- package/lib/tools/secret.js +175 -0
- package/lib/tools/skill.d.ts +63 -0
- package/lib/tools/skill.js +146 -0
- package/lib/types.d.ts +24 -1
- package/lib/update-settings.d.ts +18 -0
- package/lib/update-settings.js +60 -0
- package/lib/updater.d.ts +40 -1
- package/lib/updater.js +126 -9
- package/lib/upgrade-manager.d.ts +74 -1
- package/lib/upgrade-manager.js +356 -46
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +3 -2
- package/lib/client/icons.d.ts +0 -13
- package/lib/client/icons.js +0 -41
- package/lib/client/index.d.ts +0 -3
- package/lib/client/index.js +0 -36
- package/lib/client/panel.d.ts +0 -1
- package/lib/client/panel.js +0 -102
- package/lib/client/style.d.ts +0 -1
- package/lib/client/style.js +0 -555
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { GhExecutor } from '../executor.js';
|
|
2
|
+
export declare function createSecretTool(executor: GhExecutor): {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
action: {
|
|
9
|
+
type: string;
|
|
10
|
+
enum: string[];
|
|
11
|
+
description: string;
|
|
12
|
+
};
|
|
13
|
+
repo: {
|
|
14
|
+
type: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
name: {
|
|
18
|
+
type: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
value: {
|
|
22
|
+
type: string;
|
|
23
|
+
description: string;
|
|
24
|
+
};
|
|
25
|
+
org: {
|
|
26
|
+
type: string;
|
|
27
|
+
description: string;
|
|
28
|
+
};
|
|
29
|
+
env: {
|
|
30
|
+
type: string;
|
|
31
|
+
description: string;
|
|
32
|
+
};
|
|
33
|
+
app: {
|
|
34
|
+
type: string;
|
|
35
|
+
enum: string[];
|
|
36
|
+
description: string;
|
|
37
|
+
};
|
|
38
|
+
visibility: {
|
|
39
|
+
type: string;
|
|
40
|
+
enum: string[];
|
|
41
|
+
description: string;
|
|
42
|
+
};
|
|
43
|
+
confirm: {
|
|
44
|
+
type: string;
|
|
45
|
+
description: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
required: string[];
|
|
49
|
+
};
|
|
50
|
+
output: {
|
|
51
|
+
schema: {
|
|
52
|
+
type: string;
|
|
53
|
+
};
|
|
54
|
+
render(args: any, value: any): {
|
|
55
|
+
type: string;
|
|
56
|
+
text: string;
|
|
57
|
+
}[];
|
|
58
|
+
};
|
|
59
|
+
execute(args: any, execContext: any): Promise<Record<string, any>>;
|
|
60
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
function normalizeOutput(data) {
|
|
2
|
+
if (data && typeof data === 'object' && !Array.isArray(data)) {
|
|
3
|
+
return data;
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(data)) {
|
|
6
|
+
return { items: data, count: data.length };
|
|
7
|
+
}
|
|
8
|
+
return { result: data !== undefined && data !== null ? data : '' };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 渲染 secret 工具输出。
|
|
12
|
+
* 独立于 markdown.ts 渲染器的原因:这里有一条硬性安全规则——任何分支都不允许
|
|
13
|
+
* 渲染 value 字段(哪怕是调试用途)。逻辑集中在本地一眼可审,避免在通用渲染器
|
|
14
|
+
* 里混入「按字段名黑名单过滤」的隐蔽约束。
|
|
15
|
+
*/
|
|
16
|
+
function renderSecretOutput(args, value) {
|
|
17
|
+
if (!value)
|
|
18
|
+
return '无返回内容';
|
|
19
|
+
if (value.status === 'AWAITING_CONFIRMATION') {
|
|
20
|
+
return [
|
|
21
|
+
`> ### ${value.warning}`,
|
|
22
|
+
`> - **影响评估**: ${value.impact}`,
|
|
23
|
+
`> - **确认指引**: ${value.requiredAction}`,
|
|
24
|
+
].join('\n');
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(value.items) && args?.action === 'list') {
|
|
27
|
+
const list = value.items.filter(Boolean);
|
|
28
|
+
if (list.length === 0)
|
|
29
|
+
return '📭 当前仓库尚未配置任何 Secret。';
|
|
30
|
+
const rows = list.map((s) => {
|
|
31
|
+
const name = `\`${String(s.name || '-')}\``;
|
|
32
|
+
const vis = s.visibility ? String(s.visibility) : '-';
|
|
33
|
+
const date = s.updatedAt ? s.updatedAt.slice(0, 10) : '-';
|
|
34
|
+
return `| ${name} | ${vis} | ${date} |`;
|
|
35
|
+
});
|
|
36
|
+
return [
|
|
37
|
+
`**当前已配置 ${list.length} 个 Secret(仅名称,永不展示明文):**\n`,
|
|
38
|
+
'| 密钥名称 | 可见性 | 最近更新 |',
|
|
39
|
+
'| :--- | :--- | :--- |',
|
|
40
|
+
...rows,
|
|
41
|
+
].join('\n');
|
|
42
|
+
}
|
|
43
|
+
if (typeof value.message === 'string') {
|
|
44
|
+
return `**${value.message}**`;
|
|
45
|
+
}
|
|
46
|
+
return JSON.stringify(value, null, 2);
|
|
47
|
+
}
|
|
48
|
+
export function createSecretTool(executor) {
|
|
49
|
+
return {
|
|
50
|
+
name: 'github_secret',
|
|
51
|
+
description: '管理 GitHub Actions 仓库密钥 (Secrets):查看已配置的密钥名称列表、设置/更新密钥值(如 NPM_TOKEN、部署密钥)。密文经标准输入安全传递,绝不出现在命令行参数中,也不会在输出中回显。删除需 confirm: true。',
|
|
52
|
+
parameters: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
action: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
enum: ['list', 'set', 'delete'],
|
|
58
|
+
description: 'Secret 操作类型。',
|
|
59
|
+
},
|
|
60
|
+
repo: {
|
|
61
|
+
type: 'string',
|
|
62
|
+
description: '目标仓库 [owner/repo],留空则自动识别当前本地 Git 仓库。',
|
|
63
|
+
},
|
|
64
|
+
name: {
|
|
65
|
+
type: 'string',
|
|
66
|
+
description: '密钥名称(set/delete 动作使用,如 "NPM_TOKEN"、"DOCKER_PASSWORD")。',
|
|
67
|
+
},
|
|
68
|
+
value: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
description: '密钥明文内容(set 动作使用)。内部通过子进程标准输入传递,避免在进程命令行被 ps/任务管理器窃取。',
|
|
71
|
+
},
|
|
72
|
+
org: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
description: '组织级密钥的所属组织名(可选,映射 --org)。',
|
|
75
|
+
},
|
|
76
|
+
env: {
|
|
77
|
+
type: 'string',
|
|
78
|
+
description: '环境级密钥的部署环境名(可选,映射 --env)。',
|
|
79
|
+
},
|
|
80
|
+
app: {
|
|
81
|
+
type: 'string',
|
|
82
|
+
enum: ['actions', 'agents', 'codespaces', 'dependabot'],
|
|
83
|
+
description: '密钥归属的应用(可选,映射 --app,默认 actions)。',
|
|
84
|
+
},
|
|
85
|
+
visibility: {
|
|
86
|
+
type: 'string',
|
|
87
|
+
enum: ['all', 'private', 'selected'],
|
|
88
|
+
description: '组织级密钥的可见范围(可选,仅 org 场景有意义)。',
|
|
89
|
+
},
|
|
90
|
+
confirm: {
|
|
91
|
+
type: 'boolean',
|
|
92
|
+
description: '删除密钥时的确认标志。删除不可逆,未传 true 时仅输出影响评估。',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
required: ['action'],
|
|
96
|
+
},
|
|
97
|
+
output: {
|
|
98
|
+
schema: { type: 'object' },
|
|
99
|
+
render(args, value) {
|
|
100
|
+
return [{ type: 'text', text: renderSecretOutput(args, value) }];
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
async execute(args, execContext) {
|
|
104
|
+
const cwd = execContext?.cwd || process.cwd();
|
|
105
|
+
const sessionId = execContext?.sessionId || execContext?.session?.id || process.env.DSH_SESSION_ID;
|
|
106
|
+
// org 作用域的密钥挂在组织上,与具体仓库无关:既不需要仓库识别,
|
|
107
|
+
// 也不能把 -R 与 --org 同时传给 gh(两者语义冲突,gh 会报错)。
|
|
108
|
+
const isOrgScope = Boolean(args.org);
|
|
109
|
+
let repoTarget = args.repo;
|
|
110
|
+
if (!repoTarget && !isOrgScope) {
|
|
111
|
+
const meta = await executor.getRepoMetadata(cwd, sessionId);
|
|
112
|
+
if (meta?.nameWithOwner) {
|
|
113
|
+
repoTarget = meta.nameWithOwner;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!repoTarget && !isOrgScope) {
|
|
117
|
+
throw new Error('未能自动识别当前工作区关联的 GitHub 仓库。请通过 `repo` 参数显式指定目标仓库 [owner/repo],或改用 `org` 参数操作组织级密钥。');
|
|
118
|
+
}
|
|
119
|
+
const runOpts = { cwd, sessionId };
|
|
120
|
+
// org/env/app 三类作用域标志对所有动作通用;仓库作用域时三项均不追加
|
|
121
|
+
const scopeFlags = [];
|
|
122
|
+
if (args.org) {
|
|
123
|
+
scopeFlags.push('--org', args.org);
|
|
124
|
+
if (args.visibility)
|
|
125
|
+
scopeFlags.push('--visibility', args.visibility);
|
|
126
|
+
}
|
|
127
|
+
else if (args.env) {
|
|
128
|
+
scopeFlags.push('--env', args.env);
|
|
129
|
+
}
|
|
130
|
+
if (args.app)
|
|
131
|
+
scopeFlags.push('--app', args.app);
|
|
132
|
+
const targetArgs = isOrgScope ? [] : ['-R', repoTarget];
|
|
133
|
+
switch (args.action) {
|
|
134
|
+
case 'list': {
|
|
135
|
+
const res = await executor.run(['secret', 'list', ...targetArgs, ...scopeFlags, '--json', 'name,updatedAt,visibility'], runOpts);
|
|
136
|
+
if (!res.ok)
|
|
137
|
+
throw new Error(res.error);
|
|
138
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
139
|
+
}
|
|
140
|
+
case 'set': {
|
|
141
|
+
if (!args.name)
|
|
142
|
+
throw new Error('set 操作必须提供 name(密钥名称)');
|
|
143
|
+
if (typeof args.value !== 'string' || args.value.length === 0) {
|
|
144
|
+
throw new Error('set 操作必须提供 value(密钥明文),且不允许为空字符串');
|
|
145
|
+
}
|
|
146
|
+
// 安全红线:密文只走 stdin。严禁退化为 -b <value> —— 那会把明文
|
|
147
|
+
// 留在进程列表与 shell 历史里,等于密钥泄漏。gh 本地会用仓库公钥
|
|
148
|
+
// 加密后才上传,明文不落盘、不出本机。
|
|
149
|
+
const res = await executor.run(['secret', 'set', args.name, ...targetArgs, ...scopeFlags], { ...runOpts, stdin: args.value });
|
|
150
|
+
if (!res.ok)
|
|
151
|
+
throw new Error(res.error);
|
|
152
|
+
return { message: `Secret「${args.name}」已更新(值不回显)` };
|
|
153
|
+
}
|
|
154
|
+
case 'delete': {
|
|
155
|
+
if (!args.name)
|
|
156
|
+
throw new Error('delete 操作必须提供 name');
|
|
157
|
+
if (args.confirm !== true) {
|
|
158
|
+
return {
|
|
159
|
+
status: 'AWAITING_CONFIRMATION',
|
|
160
|
+
warning: `⚠️ 高危操作拦截:你即将删除 Secret「${args.name}」${args.org ? `(组织 ${args.org})` : ''}。`,
|
|
161
|
+
impact: '删除后所有引用该密钥的 CI/CD 工作流将立即无法取到值,运行中的构建会失败。',
|
|
162
|
+
requiredAction: '如确认删除,请向用户核实并附加 `confirm: true` 重新调用。',
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const res = await executor.run(['secret', 'delete', args.name, ...targetArgs, ...scopeFlags], runOpts);
|
|
166
|
+
if (!res.ok)
|
|
167
|
+
throw new Error(res.error);
|
|
168
|
+
return { message: `Secret「${args.name}」已删除` };
|
|
169
|
+
}
|
|
170
|
+
default:
|
|
171
|
+
throw new Error(`未知的 Secret 操作: ${args.action}`);
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { GhExecutor } from '../executor.js';
|
|
2
|
+
export declare function createSkillTool(executor: GhExecutor): {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
action: {
|
|
9
|
+
type: string;
|
|
10
|
+
enum: string[];
|
|
11
|
+
description: string;
|
|
12
|
+
};
|
|
13
|
+
query: {
|
|
14
|
+
type: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
owner: {
|
|
18
|
+
type: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
repository: {
|
|
22
|
+
type: string;
|
|
23
|
+
description: string;
|
|
24
|
+
};
|
|
25
|
+
skill_name: {
|
|
26
|
+
type: string;
|
|
27
|
+
description: string;
|
|
28
|
+
};
|
|
29
|
+
agent: {
|
|
30
|
+
type: string;
|
|
31
|
+
description: string;
|
|
32
|
+
};
|
|
33
|
+
scope: {
|
|
34
|
+
type: string;
|
|
35
|
+
enum: string[];
|
|
36
|
+
description: string;
|
|
37
|
+
};
|
|
38
|
+
all: {
|
|
39
|
+
type: string;
|
|
40
|
+
description: string;
|
|
41
|
+
};
|
|
42
|
+
limit: {
|
|
43
|
+
type: string;
|
|
44
|
+
description: string;
|
|
45
|
+
};
|
|
46
|
+
confirm: {
|
|
47
|
+
type: string;
|
|
48
|
+
description: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
required: string[];
|
|
52
|
+
};
|
|
53
|
+
output: {
|
|
54
|
+
schema: {
|
|
55
|
+
type: string;
|
|
56
|
+
};
|
|
57
|
+
render(args: any, value: any): {
|
|
58
|
+
type: string;
|
|
59
|
+
text: string;
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
62
|
+
execute(args: any, execContext: any): Promise<Record<string, any>>;
|
|
63
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { renderSkillMarkdown } from '../renderers/markdown.js';
|
|
2
|
+
function normalizeOutput(data) {
|
|
3
|
+
if (data && typeof data === 'object' && !Array.isArray(data)) {
|
|
4
|
+
return data;
|
|
5
|
+
}
|
|
6
|
+
if (Array.isArray(data)) {
|
|
7
|
+
return { items: data, count: data.length };
|
|
8
|
+
}
|
|
9
|
+
return { result: data !== undefined && data !== null ? data : '' };
|
|
10
|
+
}
|
|
11
|
+
export function createSkillTool(executor) {
|
|
12
|
+
return {
|
|
13
|
+
name: 'github_skill',
|
|
14
|
+
description: '通过 GitHub CLI 官方生态发现与管理 Agent Skills:跨仓库检索开源 Skills、预览 SKILL.md 内容、安装到本地 Agent 宿主(Claude Code / Cursor / Copilot 等)、查看已安装列表。install 会写入本地磁盘,需 confirm: true。基于 gh CLI preview 特性(需 gh >= 2.9x)。',
|
|
15
|
+
parameters: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
action: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
enum: ['search', 'preview', 'install', 'list'],
|
|
21
|
+
description: 'Skill 操作类型。',
|
|
22
|
+
},
|
|
23
|
+
query: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
description: '搜索关键词(search 动作使用,如 "python"、"devops"、"markdown")。',
|
|
26
|
+
},
|
|
27
|
+
owner: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: '限定作者或组织(search 动作可选,映射 --owner)。',
|
|
30
|
+
},
|
|
31
|
+
repository: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: '目标仓库全名 [owner/repo](preview/install 动作使用,如 "github/awesome-copilot")。',
|
|
34
|
+
},
|
|
35
|
+
skill_name: {
|
|
36
|
+
type: 'string',
|
|
37
|
+
description: 'Skill 名称(preview/install 动作可选)。支持 "name"、"author/name" 命名空间形式或 "name@version" 锁定版本。',
|
|
38
|
+
},
|
|
39
|
+
agent: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
description: '安装到的目标 Agent 宿主(install 动作可选,如 "claude-code"、"cursor"、"github-copilot";省略时 gh 会按环境探测)。',
|
|
42
|
+
},
|
|
43
|
+
scope: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
enum: ['project', 'user'],
|
|
46
|
+
description: '安装范围(install 动作可选,默认 project:安装进当前 git 仓库;user:安装到用户主目录全局可用)。',
|
|
47
|
+
},
|
|
48
|
+
all: {
|
|
49
|
+
type: 'boolean',
|
|
50
|
+
description: '安装仓库内全部 Skills 而非逐个选择(install 动作可选,映射 --all)。',
|
|
51
|
+
},
|
|
52
|
+
limit: {
|
|
53
|
+
type: 'number',
|
|
54
|
+
description: '搜索返回数量上限(search 动作使用,默认 15)。',
|
|
55
|
+
},
|
|
56
|
+
confirm: {
|
|
57
|
+
type: 'boolean',
|
|
58
|
+
description: '安装操作确认标志。install 会向本地磁盘写入文件,未传 true 时仅输出将要执行的安装预览。',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
required: ['action'],
|
|
62
|
+
},
|
|
63
|
+
output: {
|
|
64
|
+
schema: { type: 'object' },
|
|
65
|
+
render(args, value) {
|
|
66
|
+
return [{ type: 'text', text: renderSkillMarkdown(args, value) }];
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
async execute(args, execContext) {
|
|
70
|
+
const cwd = execContext?.cwd || process.cwd();
|
|
71
|
+
const sessionId = execContext?.sessionId || execContext?.session?.id || process.env.DSH_SESSION_ID;
|
|
72
|
+
// skill 工具天然面向跨仓库生态(search/preview 均以显式 repository 为目标),
|
|
73
|
+
// 不做当前工作区仓库自动识别——识别失败反而会误导调用方。
|
|
74
|
+
const runOpts = { cwd, sessionId };
|
|
75
|
+
switch (args.action) {
|
|
76
|
+
case 'search': {
|
|
77
|
+
if (!args.query)
|
|
78
|
+
throw new Error('search 操作必须提供 query(搜索关键词)');
|
|
79
|
+
// 显式 limit 优先;缺省回退 executor.defaultListLimit(上限 50,gh skill 默认 15)
|
|
80
|
+
const limit = typeof args.limit === 'number' && args.limit > 0 ? Math.min(args.limit, 50) : Math.min(executor.defaultListLimit ?? 15, 50);
|
|
81
|
+
const searchCmd = [
|
|
82
|
+
'skill', 'search', args.query,
|
|
83
|
+
'-L', String(limit),
|
|
84
|
+
// 字段名以 gh 2.96.0 实测为准;preview 特性字段可能随版本演进,
|
|
85
|
+
// 渲染层已对缺失字段做回退,这里不做多余防御
|
|
86
|
+
'--json', 'skillName,repo,description,namespace,stars',
|
|
87
|
+
];
|
|
88
|
+
if (args.owner)
|
|
89
|
+
searchCmd.push('--owner', args.owner);
|
|
90
|
+
const res = await executor.run(searchCmd, runOpts);
|
|
91
|
+
if (!res.ok)
|
|
92
|
+
throw new Error(res.error);
|
|
93
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
94
|
+
}
|
|
95
|
+
case 'preview': {
|
|
96
|
+
if (!args.repository)
|
|
97
|
+
throw new Error('preview 操作必须提供 repository [owner/repo]');
|
|
98
|
+
const previewCmd = ['skill', 'preview', args.repository];
|
|
99
|
+
if (args.skill_name)
|
|
100
|
+
previewCmd.push(args.skill_name);
|
|
101
|
+
// SKILL.md 是长篇 Markdown 文档,套 JSON 反而破坏可读性
|
|
102
|
+
const res = await executor.run(previewCmd, { ...runOpts, rawText: true, timeoutMs: 60_000 });
|
|
103
|
+
if (!res.ok)
|
|
104
|
+
throw new Error(res.error);
|
|
105
|
+
return { result: res.rawOutput || '未找到该 Skill 的内容' };
|
|
106
|
+
}
|
|
107
|
+
case 'install': {
|
|
108
|
+
if (!args.repository)
|
|
109
|
+
throw new Error('install 操作必须提供 repository [owner/repo]');
|
|
110
|
+
if (args.confirm !== true) {
|
|
111
|
+
return {
|
|
112
|
+
status: 'AWAITING_CONFIRMATION',
|
|
113
|
+
warning: `⚠️ 安装确认拦截:你即将从仓库「${args.repository}」安装 Skill${args.skill_name ? `「${args.skill_name}」` : ''}到本地${args.scope === 'user' ? '用户主目录(全局)' : '当前项目'}。`,
|
|
114
|
+
impact: '安装会在本地磁盘写入 SKILL.md 及附属文件,并可能影响目标 Agent 宿主的默认行为。',
|
|
115
|
+
requiredAction: '如确认安装,请向用户核实并附加 `confirm: true` 重新调用。',
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const installCmd = ['skill', 'install', args.repository];
|
|
119
|
+
if (args.skill_name)
|
|
120
|
+
installCmd.push(args.skill_name);
|
|
121
|
+
if (args.agent)
|
|
122
|
+
installCmd.push('--agent', args.agent);
|
|
123
|
+
if (args.scope)
|
|
124
|
+
installCmd.push('--scope', args.scope);
|
|
125
|
+
if (args.all === true)
|
|
126
|
+
installCmd.push('--all');
|
|
127
|
+
const res = await executor.run(installCmd, { ...runOpts, timeoutMs: 120_000 });
|
|
128
|
+
if (!res.ok)
|
|
129
|
+
throw new Error(res.error);
|
|
130
|
+
return { message: `Skill 安装成功(来源: ${args.repository})`, output: res.rawOutput };
|
|
131
|
+
}
|
|
132
|
+
case 'list': {
|
|
133
|
+
const listCmd = ['skill', 'list', '--json', 'skillName,sourceURL,scope,version,pinned,path'];
|
|
134
|
+
if (args.scope)
|
|
135
|
+
listCmd.push('--scope', args.scope);
|
|
136
|
+
const res = await executor.run(listCmd, runOpts);
|
|
137
|
+
if (!res.ok)
|
|
138
|
+
throw new Error(res.error);
|
|
139
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
140
|
+
}
|
|
141
|
+
default:
|
|
142
|
+
throw new Error(`未知的 Skill 操作: ${args.action}`);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
package/lib/types.d.ts
CHANGED
|
@@ -14,12 +14,22 @@ export interface PluginConfig {
|
|
|
14
14
|
cacheTtlMs?: number;
|
|
15
15
|
/** 查询列表默认限制条数,默认 20 */
|
|
16
16
|
defaultListLimit?: number;
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* 是否开启新版本自动检查提示,默认 true。
|
|
19
|
+
* false 时熔断全部版本探测入口(Web 横幅/启动日志/概览数据),用户显式
|
|
20
|
+
* 请求升级(如一键升级按钮)不受此限制——关闭的是「提示」,不是「能力」。
|
|
21
|
+
*/
|
|
18
22
|
checkUpdate?: boolean;
|
|
19
23
|
/** 检查更新间隔毫秒数,默认 86,400,000 (24小时) */
|
|
20
24
|
updateCheckIntervalMs?: number;
|
|
21
25
|
/** 自定义 npm Registry 镜像地址,留空则自动选用 npmmirror 与 npmjs */
|
|
22
26
|
registryUrl?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 代理地址预置默认值(如 "http://127.0.0.1:7890")。
|
|
29
|
+
* 仅在用户未在驾驶舱保存过代理设置时生效;运行时 UI 保存的值优先级更高。
|
|
30
|
+
* 注意:放在 Cordis Config 意味着修改此项会触发插件 reload(静态默认值,可接受)。
|
|
31
|
+
*/
|
|
32
|
+
proxyUrl?: string;
|
|
23
33
|
}
|
|
24
34
|
export interface GhExecutionOptions {
|
|
25
35
|
/** 命令执行的工作目录,优先使用当前 Agent 会话所在的 Workspace 物理路径 */
|
|
@@ -32,6 +42,17 @@ export interface GhExecutionOptions {
|
|
|
32
42
|
env?: NodeJS.ProcessEnv;
|
|
33
43
|
/** 是否强制以纯文本形式返回,不进行 JSON 尝试解析 */
|
|
34
44
|
rawText?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* 二进制输出模式:stdout 保持 Buffer 原样返回(不做 UTF-8 转换与截断)。
|
|
47
|
+
* 用于 gh api 下载图片/附件等字节流场景;GhResult.data 此时是 Buffer。
|
|
48
|
+
*/
|
|
49
|
+
binary?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* 写入子进程标准输入的内容。
|
|
52
|
+
* 为什么需要:gh secret set 不带 -b 时从 stdin 读取密文,这是唯一不把敏感值
|
|
53
|
+
* 暴露在进程命令行(ps / 任务管理器 / 审计日志可见)的传入通道。
|
|
54
|
+
*/
|
|
55
|
+
stdin?: string;
|
|
35
56
|
}
|
|
36
57
|
export interface GhResult<T = unknown> {
|
|
37
58
|
ok: boolean;
|
|
@@ -40,6 +61,8 @@ export interface GhResult<T = unknown> {
|
|
|
40
61
|
error?: string;
|
|
41
62
|
/** 是否因超出安全阈值而被截断 */
|
|
42
63
|
truncated?: boolean;
|
|
64
|
+
/** 二进制模式下的字节长度(data 为 Buffer 时存在) */
|
|
65
|
+
binaryBytes?: number;
|
|
43
66
|
}
|
|
44
67
|
export interface AuthInstallGuide {
|
|
45
68
|
/** 推荐包管理器命令,例如 Windows 下 "winget install --id GitHub.cli" */
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type UpdateSourceMode = 'official' | 'mirror' | 'off';
|
|
2
|
+
/** mode 白名单校验:持久化文件可能被手改成任意串,不能成为绕过校验的后门 */
|
|
3
|
+
export declare function isValidUpdateMode(v: unknown): v is UpdateSourceMode;
|
|
4
|
+
/**
|
|
5
|
+
* 读取持久化设置。容灾语义:文件不存在/损坏/mode 非法 → 返回默认 'official',
|
|
6
|
+
* 绝不让设置读取失败阻断插件启动(默认值即官方源,与 UI 默认选中一致)。
|
|
7
|
+
*/
|
|
8
|
+
export declare function loadUpdateSettings(): UpdateSourceMode;
|
|
9
|
+
/**
|
|
10
|
+
* 原子写(tmp + rename):并发/崩溃不产生半截 JSON。写盘失败不抛出——
|
|
11
|
+
* 内存态已生效,仅丢失重启恢复能力(尽力持久化语义,同 proxy.ts persist)。
|
|
12
|
+
*/
|
|
13
|
+
export declare function saveUpdateSettings(mode: UpdateSourceMode): {
|
|
14
|
+
ok: boolean;
|
|
15
|
+
error?: string;
|
|
16
|
+
};
|
|
17
|
+
/** mode → 人类可读名(命令行输出与 UI 共用,避免文案漂移) */
|
|
18
|
+
export declare function describeUpdateMode(mode: UpdateSourceMode): string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 更新源设置轻量 store(官方源 / 国内镜像 / 关闭检查)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么独立于 Cordis Config:更新源变更若走 Loader 会触发插件全量 reload
|
|
5
|
+
* (工具注销重注册、面板断流),而它是高频试错型设置,必须保存即生效——
|
|
6
|
+
* 与 proxy.json 完全同范式:~/.dsh/data/dsh-github-flow/update-settings.json。
|
|
7
|
+
*/
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
/** 持久化路径:与 proxy.json 同目录(DSH 用户数据目录规范) */
|
|
12
|
+
function resolveStorePath() {
|
|
13
|
+
return path.join(os.homedir(), '.dsh', 'data', 'dsh-github-flow', 'update-settings.json');
|
|
14
|
+
}
|
|
15
|
+
/** mode 白名单校验:持久化文件可能被手改成任意串,不能成为绕过校验的后门 */
|
|
16
|
+
export function isValidUpdateMode(v) {
|
|
17
|
+
return v === 'official' || v === 'mirror' || v === 'off';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 读取持久化设置。容灾语义:文件不存在/损坏/mode 非法 → 返回默认 'official',
|
|
21
|
+
* 绝不让设置读取失败阻断插件启动(默认值即官方源,与 UI 默认选中一致)。
|
|
22
|
+
*/
|
|
23
|
+
export function loadUpdateSettings() {
|
|
24
|
+
try {
|
|
25
|
+
const raw = JSON.parse(fs.readFileSync(resolveStorePath(), 'utf8'));
|
|
26
|
+
const mode = (raw && typeof raw === 'object') ? raw.mode : undefined;
|
|
27
|
+
if (isValidUpdateMode(mode))
|
|
28
|
+
return mode;
|
|
29
|
+
}
|
|
30
|
+
catch { /* 不存在/坏 JSON → 默认值 */ }
|
|
31
|
+
return 'official';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 原子写(tmp + rename):并发/崩溃不产生半截 JSON。写盘失败不抛出——
|
|
35
|
+
* 内存态已生效,仅丢失重启恢复能力(尽力持久化语义,同 proxy.ts persist)。
|
|
36
|
+
*/
|
|
37
|
+
export function saveUpdateSettings(mode) {
|
|
38
|
+
if (!isValidUpdateMode(mode))
|
|
39
|
+
return { ok: false, error: `非法更新源模式: ${String(mode)}` };
|
|
40
|
+
try {
|
|
41
|
+
const storePath = resolveStorePath();
|
|
42
|
+
fs.mkdirSync(path.dirname(storePath), { recursive: true });
|
|
43
|
+
const tmp = `${storePath}.${process.pid}.tmp`;
|
|
44
|
+
fs.writeFileSync(tmp, JSON.stringify({ mode, savedAt: new Date().toISOString() }, null, 2), 'utf8');
|
|
45
|
+
fs.renameSync(tmp, storePath);
|
|
46
|
+
return { ok: true };
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
console.warn(`[dsh-github-flow] 更新源设置写盘失败(本次会话仍生效): ${e?.message || e}`);
|
|
50
|
+
return { ok: false, error: e?.message || String(e) };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** mode → 人类可读名(命令行输出与 UI 共用,避免文案漂移) */
|
|
54
|
+
export function describeUpdateMode(mode) {
|
|
55
|
+
if (mode === 'mirror')
|
|
56
|
+
return '国内镜像 (npmmirror)';
|
|
57
|
+
if (mode === 'off')
|
|
58
|
+
return '不检查更新';
|
|
59
|
+
return 'npm 官方源';
|
|
60
|
+
}
|
package/lib/updater.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import type { UpdateInfo } from './types.js';
|
|
2
|
+
import type { UpdateSourceMode } from './update-settings.js';
|
|
3
|
+
/**
|
|
4
|
+
* 检测当前 DSH 运行 profile 名(升级命令的 --profile 必填项,官方 CLI 语义:
|
|
5
|
+
* `dsh plugin --profile <name> add <pkg>` 在 profile 目录内转发给 pnpm)。
|
|
6
|
+
* 探测优先级(从权威到兜底,不瞎猜):
|
|
7
|
+
* 1. DSH_PROFILE 环境变量——launcher 启动时固定注入(桌面版=desktop,
|
|
8
|
+
* `dsh --profile web` 启动的 Web 版=web),是运行进程对自身 profile 的事实源;
|
|
9
|
+
* 2. DSH_PROFILE_DIR 路径含 desktop 时判定 desktop;
|
|
10
|
+
* 3. 兜底探测 ~/.dsh/profiles 下实际存在的 profile 目录(web > default 顺序),
|
|
11
|
+
* 两者皆无才回落 'default'(dsh CLI 的默认 profile 名)。
|
|
12
|
+
*/
|
|
13
|
+
export declare function detectProfileName(): string;
|
|
2
14
|
/**
|
|
3
15
|
* 极简语义化版本大小比较函数 (latest > current 时返回 true)
|
|
4
16
|
*
|
|
@@ -21,12 +33,39 @@ export declare class UpdateChecker {
|
|
|
21
33
|
private inFlightPromise;
|
|
22
34
|
private readonly intervalMs;
|
|
23
35
|
private readonly customRegistry?;
|
|
36
|
+
/** 配置总开关(checkUpdate: false 时的自动探测熔断),见 check() 内注释 */
|
|
37
|
+
private readonly enabled;
|
|
38
|
+
/**
|
|
39
|
+
* 当前更新源模式。null = 未初始化(走 legacy 双源竞速,兼容 store 不存在
|
|
40
|
+
* 且无 Cordis registryUrl 的老安装);一旦 UI 保存过任何 mode 即为权威。
|
|
41
|
+
*/
|
|
42
|
+
private sourceMode;
|
|
24
43
|
constructor(options?: {
|
|
25
44
|
intervalMs?: number;
|
|
26
45
|
customRegistry?: string;
|
|
46
|
+
enabled?: boolean;
|
|
27
47
|
});
|
|
28
48
|
/**
|
|
29
|
-
*
|
|
49
|
+
* 应用代理到 npm 探测的 fetch 链路。
|
|
50
|
+
* 由 main.ts 在 ProxyManager 初始化/变更后调用:undici dispatcher 是进程级全局,
|
|
51
|
+
* 这里只做一次转发,真正的缓存/重建逻辑在 ProxyManager.applyFetchDispatcher 内。
|
|
52
|
+
*/
|
|
53
|
+
applyProxy(manager: {
|
|
54
|
+
applyFetchDispatcher(): boolean;
|
|
55
|
+
} | null): void;
|
|
56
|
+
/**
|
|
57
|
+
* 运行时切换更新源(UI 保存即调用,无需插件 reload)。
|
|
58
|
+
* 为什么必须失效缓存:24h 缓存里存的是旧源的结果,用户切源后若不清缓存,
|
|
59
|
+
* 首次 check() 仍返回旧源的 latestVersion——用户感知「切换无效」。
|
|
60
|
+
* 'off' 与 enabled 熔断独立并存:enabled 来自 Cordis 静态配置(缺省 true),
|
|
61
|
+
* off 来自 UI 持久化设置;任一为「关」都熔断自动探测。
|
|
62
|
+
*/
|
|
63
|
+
applySettings(mode: UpdateSourceMode): void;
|
|
64
|
+
/** 当前生效的更新源模式(供命令行/升级链路展示与对齐) */
|
|
65
|
+
getSourceMode(): UpdateSourceMode | null;
|
|
66
|
+
/**
|
|
67
|
+
* 同步获取当前已知的版本状态(0ms 纯内存读取,绝不发外网请求)。
|
|
68
|
+
* 兜底命令同样按当前 profile 生成:网络探测失败时复制命令也必须开箱可用。
|
|
30
69
|
*/
|
|
31
70
|
getQuickStatus(): UpdateInfo;
|
|
32
71
|
/**
|