dsh-github-flow 0.1.2 → 0.1.3
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/lib/tools/api.d.ts +2 -2
- package/lib/tools/api.js +19 -2
- package/lib/tools/issue.d.ts +2 -2
- package/lib/tools/issue.js +28 -4
- package/lib/tools/pr.d.ts +2 -2
- package/lib/tools/pr.js +30 -6
- package/lib/tools/repo.d.ts +2 -2
- package/lib/tools/repo.js +29 -5
- package/lib/tools/run.d.ts +2 -2
- package/lib/tools/run.js +29 -5
- package/package.json +1 -1
package/lib/tools/api.d.ts
CHANGED
|
@@ -31,8 +31,8 @@ export declare function createApiTool(executor: GhExecutor): {
|
|
|
31
31
|
};
|
|
32
32
|
render(args: any, value: any): {
|
|
33
33
|
type: string;
|
|
34
|
-
text:
|
|
34
|
+
text: any;
|
|
35
35
|
}[];
|
|
36
36
|
};
|
|
37
|
-
execute(args: any, execContext: any): Promise<
|
|
37
|
+
execute(args: any, execContext: any): Promise<Record<string, any>>;
|
|
38
38
|
};
|
package/lib/tools/api.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
}
|
|
1
10
|
export function createApiTool(executor) {
|
|
2
11
|
return {
|
|
3
12
|
name: 'github_api',
|
|
@@ -28,7 +37,15 @@ export function createApiTool(executor) {
|
|
|
28
37
|
output: {
|
|
29
38
|
schema: { type: 'object' },
|
|
30
39
|
render(args, value) {
|
|
31
|
-
|
|
40
|
+
if (!value)
|
|
41
|
+
return [{ type: 'text', text: '无返回内容' }];
|
|
42
|
+
if (typeof value.result === 'string') {
|
|
43
|
+
return [{ type: 'text', text: value.result }];
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(value.items)) {
|
|
46
|
+
return [{ type: 'text', text: JSON.stringify(value.items, null, 2) }];
|
|
47
|
+
}
|
|
48
|
+
return [{ type: 'text', text: JSON.stringify(value, null, 2) }];
|
|
32
49
|
},
|
|
33
50
|
},
|
|
34
51
|
async execute(args, execContext) {
|
|
@@ -48,7 +65,7 @@ export function createApiTool(executor) {
|
|
|
48
65
|
const res = await executor.run(cmd, { cwd });
|
|
49
66
|
if (!res.ok)
|
|
50
67
|
throw new Error(res.error);
|
|
51
|
-
return res.data
|
|
68
|
+
return normalizeOutput(res.data !== undefined ? res.data : res.rawOutput);
|
|
52
69
|
},
|
|
53
70
|
};
|
|
54
71
|
}
|
package/lib/tools/issue.d.ts
CHANGED
|
@@ -49,8 +49,8 @@ export declare function createIssueTool(executor: GhExecutor): {
|
|
|
49
49
|
};
|
|
50
50
|
render(args: any, value: any): {
|
|
51
51
|
type: string;
|
|
52
|
-
text:
|
|
52
|
+
text: any;
|
|
53
53
|
}[];
|
|
54
54
|
};
|
|
55
|
-
execute(args: any, execContext: any): Promise<
|
|
55
|
+
execute(args: any, execContext: any): Promise<Record<string, any>>;
|
|
56
56
|
};
|
package/lib/tools/issue.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
}
|
|
1
10
|
export function createIssueTool(executor) {
|
|
2
11
|
return {
|
|
3
12
|
name: 'github_issue',
|
|
@@ -42,18 +51,33 @@ export function createIssueTool(executor) {
|
|
|
42
51
|
output: {
|
|
43
52
|
schema: { type: 'object' },
|
|
44
53
|
render(args, value) {
|
|
45
|
-
|
|
54
|
+
if (!value)
|
|
55
|
+
return [{ type: 'text', text: '无返回内容' }];
|
|
56
|
+
if (typeof value.result === 'string') {
|
|
57
|
+
return [{ type: 'text', text: value.result }];
|
|
58
|
+
}
|
|
59
|
+
if (Array.isArray(value.items)) {
|
|
60
|
+
return [{ type: 'text', text: JSON.stringify(value.items, null, 2) }];
|
|
61
|
+
}
|
|
62
|
+
return [{ type: 'text', text: JSON.stringify(value, null, 2) }];
|
|
46
63
|
},
|
|
47
64
|
},
|
|
48
65
|
async execute(args, execContext) {
|
|
49
66
|
const cwd = execContext?.cwd || process.cwd();
|
|
50
|
-
|
|
67
|
+
let repoTarget = args.repo;
|
|
68
|
+
if (!repoTarget) {
|
|
69
|
+
const meta = await executor.getRepoMetadata(cwd);
|
|
70
|
+
if (meta?.nameWithOwner) {
|
|
71
|
+
repoTarget = meta.nameWithOwner;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const repoArgs = repoTarget ? ['-R', repoTarget] : [];
|
|
51
75
|
switch (args.action) {
|
|
52
76
|
case 'list': {
|
|
53
77
|
const res = await executor.run(['issue', 'list', ...repoArgs, '--json', 'number,title,state,author,labels,updatedAt', '-L', '20'], { cwd });
|
|
54
78
|
if (!res.ok)
|
|
55
79
|
throw new Error(res.error);
|
|
56
|
-
return res.data || res.rawOutput;
|
|
80
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
57
81
|
}
|
|
58
82
|
case 'view': {
|
|
59
83
|
if (!args.issue_number)
|
|
@@ -61,7 +85,7 @@ export function createIssueTool(executor) {
|
|
|
61
85
|
const res = await executor.run(['issue', 'view', String(args.issue_number), ...repoArgs, '--json', 'number,title,body,state,author,labels,assignees,comments,url'], { cwd });
|
|
62
86
|
if (!res.ok)
|
|
63
87
|
throw new Error(res.error);
|
|
64
|
-
return res.data || res.rawOutput;
|
|
88
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
65
89
|
}
|
|
66
90
|
case 'create': {
|
|
67
91
|
const cmd = ['issue', 'create', ...repoArgs, '--title', args.title || '', '--body', args.body || ''];
|
package/lib/tools/pr.d.ts
CHANGED
|
@@ -53,8 +53,8 @@ export declare function createPrTool(executor: GhExecutor): {
|
|
|
53
53
|
};
|
|
54
54
|
render(args: any, value: any): {
|
|
55
55
|
type: string;
|
|
56
|
-
text:
|
|
56
|
+
text: any;
|
|
57
57
|
}[];
|
|
58
58
|
};
|
|
59
|
-
execute(args: any, execContext: any): Promise<
|
|
59
|
+
execute(args: any, execContext: any): Promise<Record<string, any>>;
|
|
60
60
|
};
|
package/lib/tools/pr.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
}
|
|
1
10
|
export function createPrTool(executor) {
|
|
2
11
|
return {
|
|
3
12
|
name: 'github_pr',
|
|
@@ -50,39 +59,54 @@ export function createPrTool(executor) {
|
|
|
50
59
|
output: {
|
|
51
60
|
schema: { type: 'object' },
|
|
52
61
|
render(args, value) {
|
|
53
|
-
|
|
62
|
+
if (!value)
|
|
63
|
+
return [{ type: 'text', text: '无返回内容' }];
|
|
64
|
+
if (typeof value.result === 'string') {
|
|
65
|
+
return [{ type: 'text', text: value.result }];
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(value.items)) {
|
|
68
|
+
return [{ type: 'text', text: JSON.stringify(value.items, null, 2) }];
|
|
69
|
+
}
|
|
70
|
+
return [{ type: 'text', text: JSON.stringify(value, null, 2) }];
|
|
54
71
|
},
|
|
55
72
|
},
|
|
56
73
|
async execute(args, execContext) {
|
|
57
74
|
const cwd = execContext?.cwd || process.cwd();
|
|
58
|
-
|
|
75
|
+
let repoTarget = args.repo;
|
|
76
|
+
if (!repoTarget) {
|
|
77
|
+
const meta = await executor.getRepoMetadata(cwd);
|
|
78
|
+
if (meta?.nameWithOwner) {
|
|
79
|
+
repoTarget = meta.nameWithOwner;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const repoArgs = repoTarget ? ['-R', repoTarget] : [];
|
|
59
83
|
switch (args.action) {
|
|
60
84
|
case 'list': {
|
|
61
85
|
const res = await executor.run(['pr', 'list', ...repoArgs, '--json', 'number,title,author,headRefName,isDraft,state,updatedAt', '-L', '20'], { cwd });
|
|
62
86
|
if (!res.ok)
|
|
63
87
|
throw new Error(res.error);
|
|
64
|
-
return res.data || res.rawOutput;
|
|
88
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
65
89
|
}
|
|
66
90
|
case 'view': {
|
|
67
91
|
const target = args.pr_number ? [String(args.pr_number)] : [];
|
|
68
92
|
const res = await executor.run(['pr', 'view', ...target, ...repoArgs, '--json', 'number,title,body,state,author,labels,assignees,reviewDecision,mergeable,statusCheckRollup,url'], { cwd });
|
|
69
93
|
if (!res.ok)
|
|
70
94
|
throw new Error(res.error);
|
|
71
|
-
return res.data || res.rawOutput;
|
|
95
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
72
96
|
}
|
|
73
97
|
case 'checks': {
|
|
74
98
|
const target = args.pr_number ? [String(args.pr_number)] : [];
|
|
75
99
|
const res = await executor.run(['pr', 'checks', ...target, ...repoArgs, '--json', 'name,state,conclusion,detailsUrl'], { cwd });
|
|
76
100
|
if (!res.ok)
|
|
77
101
|
throw new Error(res.error);
|
|
78
|
-
return res.data || res.rawOutput;
|
|
102
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
79
103
|
}
|
|
80
104
|
case 'diff': {
|
|
81
105
|
const target = args.pr_number ? [String(args.pr_number)] : [];
|
|
82
106
|
const res = await executor.run(['pr', 'diff', ...target, ...repoArgs], { cwd });
|
|
83
107
|
if (!res.ok)
|
|
84
108
|
throw new Error(res.error);
|
|
85
|
-
return res.rawOutput || '无差异内容';
|
|
109
|
+
return { result: res.rawOutput || '无差异内容' };
|
|
86
110
|
}
|
|
87
111
|
case 'create': {
|
|
88
112
|
const createCmd = ['pr', 'create', ...repoArgs, '--title', args.title || '', '--body', args.body || ''];
|
package/lib/tools/repo.d.ts
CHANGED
|
@@ -31,8 +31,8 @@ export declare function createRepoTool(executor: GhExecutor): {
|
|
|
31
31
|
};
|
|
32
32
|
render(args: any, value: any): {
|
|
33
33
|
type: string;
|
|
34
|
-
text:
|
|
34
|
+
text: any;
|
|
35
35
|
}[];
|
|
36
36
|
};
|
|
37
|
-
execute(args: any, execContext: any): Promise<
|
|
37
|
+
execute(args: any, execContext: any): Promise<Record<string, any>>;
|
|
38
38
|
};
|
package/lib/tools/repo.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
}
|
|
1
10
|
export function createRepoTool(executor) {
|
|
2
11
|
return {
|
|
3
12
|
name: 'github_repo',
|
|
@@ -28,7 +37,15 @@ export function createRepoTool(executor) {
|
|
|
28
37
|
output: {
|
|
29
38
|
schema: { type: 'object' },
|
|
30
39
|
render(args, value) {
|
|
31
|
-
|
|
40
|
+
if (!value)
|
|
41
|
+
return [{ type: 'text', text: '无返回内容' }];
|
|
42
|
+
if (typeof value.result === 'string') {
|
|
43
|
+
return [{ type: 'text', text: value.result }];
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(value.items)) {
|
|
46
|
+
return [{ type: 'text', text: JSON.stringify(value.items, null, 2) }];
|
|
47
|
+
}
|
|
48
|
+
return [{ type: 'text', text: JSON.stringify(value, null, 2) }];
|
|
32
49
|
},
|
|
33
50
|
},
|
|
34
51
|
async execute(args, execContext) {
|
|
@@ -36,11 +53,18 @@ export function createRepoTool(executor) {
|
|
|
36
53
|
const limitStr = String(args.limit || 10);
|
|
37
54
|
switch (args.action) {
|
|
38
55
|
case 'view': {
|
|
39
|
-
|
|
56
|
+
let repoTarget = args.repo;
|
|
57
|
+
if (!repoTarget) {
|
|
58
|
+
const meta = await executor.getRepoMetadata(cwd);
|
|
59
|
+
if (meta?.nameWithOwner) {
|
|
60
|
+
repoTarget = meta.nameWithOwner;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const repoArgs = repoTarget ? [repoTarget] : [];
|
|
40
64
|
const res = await executor.run(['repo', 'view', ...repoArgs, '--json', 'nameWithOwner,description,defaultBranchRef,isPrivate,stargazerCount,forkCount,url'], { cwd });
|
|
41
65
|
if (!res.ok)
|
|
42
66
|
throw new Error(res.error);
|
|
43
|
-
return res.data || res.rawOutput;
|
|
67
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
44
68
|
}
|
|
45
69
|
case 'search_code': {
|
|
46
70
|
if (!args.query)
|
|
@@ -49,7 +73,7 @@ export function createRepoTool(executor) {
|
|
|
49
73
|
const res = await executor.run(['search', 'code', args.query, ...repoArgs, '--json', 'path,repository,textMatches', '-L', limitStr], { cwd });
|
|
50
74
|
if (!res.ok)
|
|
51
75
|
throw new Error(res.error);
|
|
52
|
-
return res.data || res.rawOutput;
|
|
76
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
53
77
|
}
|
|
54
78
|
case 'search_repos': {
|
|
55
79
|
if (!args.query)
|
|
@@ -57,7 +81,7 @@ export function createRepoTool(executor) {
|
|
|
57
81
|
const res = await executor.run(['search', 'repos', args.query, '--json', 'fullName,description,stargazersCount,updatedAt', '-L', limitStr], { cwd });
|
|
58
82
|
if (!res.ok)
|
|
59
83
|
throw new Error(res.error);
|
|
60
|
-
return res.data || res.rawOutput;
|
|
84
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
61
85
|
}
|
|
62
86
|
default:
|
|
63
87
|
throw new Error(`未知的 Repo 操作: ${args.action}`);
|
package/lib/tools/run.d.ts
CHANGED
|
@@ -31,8 +31,8 @@ export declare function createRunTool(executor: GhExecutor): {
|
|
|
31
31
|
};
|
|
32
32
|
render(args: any, value: any): {
|
|
33
33
|
type: string;
|
|
34
|
-
text:
|
|
34
|
+
text: any;
|
|
35
35
|
}[];
|
|
36
36
|
};
|
|
37
|
-
execute(args: any, execContext: any): Promise<
|
|
37
|
+
execute(args: any, execContext: any): Promise<Record<string, any>>;
|
|
38
38
|
};
|
package/lib/tools/run.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
}
|
|
1
10
|
export function createRunTool(executor) {
|
|
2
11
|
return {
|
|
3
12
|
name: 'github_run',
|
|
@@ -28,18 +37,33 @@ export function createRunTool(executor) {
|
|
|
28
37
|
output: {
|
|
29
38
|
schema: { type: 'object' },
|
|
30
39
|
render(args, value) {
|
|
31
|
-
|
|
40
|
+
if (!value)
|
|
41
|
+
return [{ type: 'text', text: '无返回数据' }];
|
|
42
|
+
if (typeof value.result === 'string') {
|
|
43
|
+
return [{ type: 'text', text: value.result }];
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(value.items)) {
|
|
46
|
+
return [{ type: 'text', text: JSON.stringify(value.items, null, 2) }];
|
|
47
|
+
}
|
|
48
|
+
return [{ type: 'text', text: JSON.stringify(value, null, 2) }];
|
|
32
49
|
},
|
|
33
50
|
},
|
|
34
51
|
async execute(args, execContext) {
|
|
35
52
|
const cwd = execContext?.cwd || process.cwd();
|
|
36
|
-
|
|
53
|
+
let repoTarget = args.repo;
|
|
54
|
+
if (!repoTarget) {
|
|
55
|
+
const meta = await executor.getRepoMetadata(cwd);
|
|
56
|
+
if (meta?.nameWithOwner) {
|
|
57
|
+
repoTarget = meta.nameWithOwner;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const repoArgs = repoTarget ? ['-R', repoTarget] : [];
|
|
37
61
|
switch (args.action) {
|
|
38
62
|
case 'list': {
|
|
39
63
|
const res = await executor.run(['run', 'list', ...repoArgs, '--json', 'databaseId,name,status,conclusion,event,headBranch,createdAt', '-L', String(args.limit || 10)], { cwd });
|
|
40
64
|
if (!res.ok)
|
|
41
65
|
throw new Error(res.error);
|
|
42
|
-
return res.data || res.rawOutput;
|
|
66
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
43
67
|
}
|
|
44
68
|
case 'view': {
|
|
45
69
|
if (!args.run_id)
|
|
@@ -47,7 +71,7 @@ export function createRunTool(executor) {
|
|
|
47
71
|
const res = await executor.run(['run', 'view', String(args.run_id), ...repoArgs, '--json', 'databaseId,name,status,conclusion,jobs,url'], { cwd });
|
|
48
72
|
if (!res.ok)
|
|
49
73
|
throw new Error(res.error);
|
|
50
|
-
return res.data || res.rawOutput;
|
|
74
|
+
return normalizeOutput(res.data || res.rawOutput);
|
|
51
75
|
}
|
|
52
76
|
case 'log_failed': {
|
|
53
77
|
if (!args.run_id)
|
|
@@ -60,7 +84,7 @@ export function createRunTool(executor) {
|
|
|
60
84
|
});
|
|
61
85
|
if (!res.ok)
|
|
62
86
|
throw new Error(res.error);
|
|
63
|
-
return res.rawOutput || '未找到失败步骤的日志';
|
|
87
|
+
return { result: res.rawOutput || '未找到失败步骤的日志' };
|
|
64
88
|
}
|
|
65
89
|
case 'rerun': {
|
|
66
90
|
if (!args.run_id)
|
package/package.json
CHANGED