dsh-github-console 0.4.1 → 0.6.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/.github/workflows/ci.yml +17 -0
- package/.github/workflows/publish.yml +31 -0
- package/README.md +12 -7
- package/client.js +107 -2
- package/index.js +678 -79
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
- package/scripts/check.mjs +79 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: check
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
pull_request:
|
|
5
|
+
workflow_dispatch:
|
|
6
|
+
permissions:
|
|
7
|
+
contents: read
|
|
8
|
+
jobs:
|
|
9
|
+
check:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-node@v4
|
|
14
|
+
with:
|
|
15
|
+
node-version: '22'
|
|
16
|
+
- name: Bundle consistency
|
|
17
|
+
run: node scripts/check.mjs
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
on:
|
|
3
|
+
workflow_dispatch:
|
|
4
|
+
inputs:
|
|
5
|
+
dry_run:
|
|
6
|
+
description: 'Run npm publish --dry-run'
|
|
7
|
+
type: boolean
|
|
8
|
+
default: false
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
id-token: write
|
|
12
|
+
concurrency:
|
|
13
|
+
group: npm-publish
|
|
14
|
+
cancel-in-progress: false
|
|
15
|
+
jobs:
|
|
16
|
+
publish:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- uses: actions/setup-node@v4
|
|
21
|
+
with:
|
|
22
|
+
node-version: '22'
|
|
23
|
+
registry-url: 'https://registry.npmjs.org'
|
|
24
|
+
- name: Ensure npm supports trusted publishing (needs >= 11.5.1)
|
|
25
|
+
run: npm install -g npm@11 && npm --version
|
|
26
|
+
- name: Show target
|
|
27
|
+
run: node -e "const p=require('./package.json');console.log(p.name+'@'+p.version)"
|
|
28
|
+
- name: Publish
|
|
29
|
+
run: npm publish --provenance --access public ${{ inputs.dry_run && '--dry-run' || '' }}
|
|
30
|
+
env:
|
|
31
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
CHANGED
|
@@ -7,7 +7,8 @@ DSH 的 GitHub 插件:在你自己的账号下注册一个私有 GitHub App,
|
|
|
7
7
|
- 左侧栏「**GitHub 控制台**」页签 → 主面板(状态 / 仓库 / 收件箱 / 发布 / 市场)
|
|
8
8
|
- 设置页同名分区 → 同一个面板
|
|
9
9
|
- 仓库页可以打开文件、点「编辑」直接提交到默认分支(带 sha 冲突保护,不自动开 PR)
|
|
10
|
-
- Agent
|
|
10
|
+
- Agent 工具(**38 个**,由代码生成核对):gh_status, gh_auth, gh_audit, gh_repos, gh_tree, gh_file_read, gh_file_write, gh_issues, gh_issue_create, gh_issue_comment, gh_pulls, gh_pull_create, gh_pull_merge, gh_pull_detail, gh_pull_comment, gh_pull_review, gh_issue_update, gh_actions, gh_actions_rerun, gh_actions_log, gh_workflows, gh_workflow_dispatch, gh_notifications, gh_notifications_read, gh_code_search, gh_releases, gh_commits, gh_compare, plugin_discover, plugin_preflight, plugin_publish, plugin_publish_status, plugin_release_asset, plugin_npm_publish, plugin_market_index, plugin_market_attach, plugin_market_probe, plugin_market_readiness
|
|
11
|
+
- 连接方式 5 种:GitHub App 安装、App 用户授权(OAuth 回调)、**设备码授权(Device Flow)**、个人访问令牌、环境变量
|
|
11
12
|
|
|
12
13
|
## 第一次打开:不需要先登录
|
|
13
14
|
|
|
@@ -85,18 +86,21 @@ manifest 的三步必须在 **1 小时**内完成,`state` 一次性、5 分钟
|
|
|
85
86
|
- 仓库/包里没有任何硬编码密钥;每个用户注册的是自己的 App。
|
|
86
87
|
- 撤销:面板「清除本地 App 凭据」删本机记录;App 本身到 GitHub → Settings → Applications 删除。
|
|
87
88
|
|
|
88
|
-
##
|
|
89
|
+
## 连接方式(五选一,面板里切换)
|
|
89
90
|
|
|
90
91
|
| 方式 | 怎么连 | 能做什么 | 代价 |
|
|
91
92
|
|---|---|---|---|
|
|
92
|
-
| **GitHub App**(默认) | 注册 → 安装 → 选 installation | 仓库读写、PR、Issue、Actions、Workflows
|
|
93
|
+
| **GitHub App**(默认) | 注册 → 安装 → 选 installation | 仓库读写、PR、Issue、Actions、Workflows;**拿不到通知与代码搜索** | 1 小时安装令牌,最安全 |
|
|
94
|
+
| **设备码授权**(推荐补全) | App 设置里勾 Enable Device Flow → 面板点「设备码授权」→ 输 8 位码 | 在 App 权限之上再加用户级身份:**代码搜索可用**;通知不可用(见下) | 8 小时用户令牌,到期自动续 |
|
|
95
|
+
| **App 用户授权(OAuth 回调)** | App 设置里登记回调 URL `http://127.0.0.1:<端口>/github-console/oauth/callback` → 面板授权 | 同设备码 | 端口变了要重新登记,不如设备码省事 |
|
|
93
96
|
| **个人访问令牌(PAT)** | 面板粘贴,存进凭据服务,只显示末四位 | 用户级能力全开(含通知、代码搜索、个人仓建仓) | 长期令牌,建议 fine-grained + 有效期 |
|
|
94
97
|
| **环境变量** | 配置 `patEnvName`(默认 `GITHUB_TOKEN`),值不落盘 | 同 PAT | 你自己管理变量 |
|
|
95
98
|
|
|
96
|
-
- 选择存进 `github-console/active`,切换不会丢另一种连接的凭据;`authMode` 可固定成 `app|pat|env`。
|
|
99
|
+
- 选择存进 `github-console/active`,切换不会丢另一种连接的凭据;`authMode` 可固定成 `app|oauth|pat|env`。
|
|
100
|
+
- **通知只有 PAT / 环境变量能读**:GitHub 不对 GitHub App 令牌(含 App 用户令牌)开放 `/notifications`,实测返回 `Resource not accessible by integration`。
|
|
97
101
|
- 面板「状态 → 连接方式」显示**能力矩阵**(代码读写 / PR / Issue / Actions / Workflow / 管理 / 通知 / 代码搜索),灰度即代表当前连接做不到。
|
|
98
|
-
- **只读降级**:`readOnly: true
|
|
99
|
-
-
|
|
102
|
+
- **只读降级**:`readOnly: true` 时,**任何**写请求(面板路由或 Agent 工具)都在唯一出口 `gh.call()` 被拒绝并留痕,不依赖各工具自觉。
|
|
103
|
+
- **审计留痕**:每个写请求(方法 + 路径 + 连接类型 + 结果)追加到 `$DSH_HOME/storages/dsh-github-console/audit.ndjson`,被拒绝的写同样留痕,可用 `gh_audit` 或面板查看。
|
|
100
104
|
|
|
101
105
|
## 发布一个插件
|
|
102
106
|
|
|
@@ -139,7 +143,8 @@ manifest 的三步必须在 **1 小时**内完成,`state` 一次性、5 分钟
|
|
|
139
143
|
## 已知限制
|
|
140
144
|
|
|
141
145
|
- **个人仓库创建不在 API 内**:GitHub App 安装令牌结构上无法调用 `POST /user/repos`。请先建仓,或建空仓后让插件推送。
|
|
142
|
-
-
|
|
146
|
+
- **不在本机执行 npm**:npm 发布通过 GitHub Actions + Trusted Publisher(OIDC)完成;本机没有任何 npm 调用,也不保存 npm 令牌。
|
|
147
|
+
- 不自动提交第三方市场 PR:awesome-dsh-plugin 的条目录入仍需你提一次 PR(面板可生成条目字段)。
|
|
143
148
|
- 不接收 webhook(本地无公网入口),收件箱是拉取式。
|
|
144
149
|
- 只处理单个 installation;多账号需在面板里切换。
|
|
145
150
|
- 合并 PR / 重跑 CI 需要显式 `confirm: true`;它们不会走宿主的审批弹窗。
|
package/client.js
CHANGED
|
@@ -245,6 +245,10 @@ window.__ModuleLoader__.load({
|
|
|
245
245
|
const [reviewNote, setReviewNote] = useState('')
|
|
246
246
|
const [inlineTarget, setInlineTarget] = useState('')
|
|
247
247
|
const [runLog, setRunLog] = useState(null)
|
|
248
|
+
const [searchQuery, setSearchQuery] = useState('')
|
|
249
|
+
const [searchResults, setSearchResults] = useState(null)
|
|
250
|
+
const [commits, setCommits] = useState(null)
|
|
251
|
+
const [notifications, setNotifications] = useState(null)
|
|
248
252
|
|
|
249
253
|
const [publishDir, setPublishDir] = useState('')
|
|
250
254
|
const [report, setReport] = useState(null)
|
|
@@ -522,8 +526,39 @@ window.__ModuleLoader__.load({
|
|
|
522
526
|
})
|
|
523
527
|
}
|
|
524
528
|
|
|
525
|
-
const
|
|
529
|
+
const runCodeSearch = () => {
|
|
530
|
+
if (!searchQuery.trim()) {
|
|
531
|
+
setError('先输入搜索词')
|
|
532
|
+
return
|
|
533
|
+
}
|
|
534
|
+
const ref = repoRef()
|
|
535
|
+
void run('search', async () => {
|
|
536
|
+
setSearchResults(await api('search/code', { q: searchQuery.trim(), ...(ref || {}) }))
|
|
537
|
+
})
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const loadCommits = () => {
|
|
526
541
|
const ref = repoRef()
|
|
542
|
+
if (!ref) return
|
|
543
|
+
void run('commits', async () => {
|
|
544
|
+
setCommits(await api('commits', { ...ref, limit: 20 }))
|
|
545
|
+
})
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const loadNotifications = () => {
|
|
549
|
+
void run('notice', async () => {
|
|
550
|
+
setNotifications(await api('notifications', { limit: 30 }))
|
|
551
|
+
})
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const readAllNotifications = () => {
|
|
555
|
+
void run('notice-read', async () => {
|
|
556
|
+
await api('notifications/read', { all: true })
|
|
557
|
+
setNotifications(await api('notifications', { limit: 30 }))
|
|
558
|
+
})
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const toggleIssue = (item) => { const ref = repoRef()
|
|
527
562
|
if (!ref) return
|
|
528
563
|
void run('issue', async () => {
|
|
529
564
|
await api('issue/update', { ...ref, number: item.number, state: item.state === 'open' ? 'closed' : 'open' })
|
|
@@ -990,7 +1025,18 @@ window.__ModuleLoader__.load({
|
|
|
990
1025
|
}, '撤销用户授权')
|
|
991
1026
|
: null,
|
|
992
1027
|
),
|
|
993
|
-
authMessage ? h('p', { style: S.notice }, authMessage) : null,
|
|
1028
|
+
authMessage ? h('p', { style: /失败|没有|拒绝|过期|不能|需要/.test(authMessage) ? S.warn : S.notice }, authMessage) : null,
|
|
1029
|
+
status && status.app && status.app.slug
|
|
1030
|
+
? h('p', { style: S.notice },
|
|
1031
|
+
'App 设置页(Device Flow / 回调地址都在这里):',
|
|
1032
|
+
h('a', {
|
|
1033
|
+
href: `https://github.com/settings/apps/${status.app.slug}`,
|
|
1034
|
+
target: '_blank',
|
|
1035
|
+
rel: 'noreferrer',
|
|
1036
|
+
style: { color: 'var(--dsw-alias-brand-primary)', overflowWrap: 'anywhere' },
|
|
1037
|
+
}, `github.com/settings/apps/${status.app.slug}`),
|
|
1038
|
+
)
|
|
1039
|
+
: null,
|
|
994
1040
|
device
|
|
995
1041
|
? h('p', { style: S.notice },
|
|
996
1042
|
'在浏览器打开 ',
|
|
@@ -1000,6 +1046,16 @@ window.__ModuleLoader__.load({
|
|
|
1000
1046
|
' 并确认。插件会自动轮询结果。',
|
|
1001
1047
|
)
|
|
1002
1048
|
: null,
|
|
1049
|
+
h('p', { style: S.notice },
|
|
1050
|
+
'按钮没反应?直接打开这个页面授权(不依赖面板):',
|
|
1051
|
+
h('br'),
|
|
1052
|
+
h('a', {
|
|
1053
|
+
href: '/github-console/device',
|
|
1054
|
+
target: '_blank',
|
|
1055
|
+
rel: 'noreferrer',
|
|
1056
|
+
style: { color: 'var(--dsw-alias-brand-primary)', overflowWrap: 'anywhere' },
|
|
1057
|
+
}, `${typeof window !== 'undefined' ? window.location.origin : ''}/github-console/device`),
|
|
1058
|
+
),
|
|
1003
1059
|
status && status.auth && status.auth.capabilities
|
|
1004
1060
|
? h('div', { style: { marginTop: 6 } },
|
|
1005
1061
|
h('div', { style: S.meta }, '当前连接的能力'),
|
|
@@ -1103,6 +1159,34 @@ window.__ModuleLoader__.load({
|
|
|
1103
1159
|
h('input', { style: S.input, value: repoQuery, placeholder: '按 owner/name 过滤', onChange: (event) => setRepoQuery(event.target.value), onKeyDown: (event) => { if (event.key === 'Enter') void loadRepos() } }),
|
|
1104
1160
|
h('button', { style: S.button, disabled: busy === 'repos', onClick: loadRepos }, busy === 'repos' ? '查询中…' : '查询'),
|
|
1105
1161
|
),
|
|
1162
|
+
h('div', { style: { display: 'flex', gap: 6, marginBottom: 8, flexWrap: 'wrap' } },
|
|
1163
|
+
h('input', { style: { ...S.input, flex: 1, minWidth: 180 }, value: searchQuery, placeholder: '代码搜索(需要用户连接;按当前仓库限定)', onChange: (event) => setSearchQuery(event.target.value), onKeyDown: (event) => { if (event.key === 'Enter') runCodeSearch() } }),
|
|
1164
|
+
h('button', { style: S.button, disabled: busy === 'search', onClick: runCodeSearch }, busy === 'search' ? '搜索中…' : '搜索'),
|
|
1165
|
+
h('button', { style: S.button, disabled: busy === 'commits', onClick: loadCommits }, busy === 'commits' ? '读取中…' : '提交历史'),
|
|
1166
|
+
),
|
|
1167
|
+
searchResults
|
|
1168
|
+
? h('div', { style: S.card },
|
|
1169
|
+
h('strong', { style: { fontSize: 13 } }, `代码搜索:${searchResults.total} 条`),
|
|
1170
|
+
searchResults.items.map((item) =>
|
|
1171
|
+
h('div', { key: item.sha + item.path, style: S.row },
|
|
1172
|
+
h('span', { style: S.name }, item.path),
|
|
1173
|
+
h('span', { style: S.meta }, item.repo),
|
|
1174
|
+
),
|
|
1175
|
+
),
|
|
1176
|
+
)
|
|
1177
|
+
: null,
|
|
1178
|
+
commits
|
|
1179
|
+
? h('div', { style: S.card },
|
|
1180
|
+
h('strong', { style: { fontSize: 13 } }, `提交历史(${commits.items.length})`),
|
|
1181
|
+
commits.items.map((item) =>
|
|
1182
|
+
h('div', { key: item.sha, style: S.row },
|
|
1183
|
+
h('span', { style: { ...S.meta, width: 64 } }, item.short),
|
|
1184
|
+
h('span', { style: S.name }, item.message),
|
|
1185
|
+
h('span', { style: S.meta }, `${item.author} · ${(item.date || '').slice(0, 10)}`),
|
|
1186
|
+
),
|
|
1187
|
+
),
|
|
1188
|
+
)
|
|
1189
|
+
: null,
|
|
1106
1190
|
!reposLoaded
|
|
1107
1191
|
? h('p', { style: S.notice }, '点「查询」列出 App 安装范围内的仓库。')
|
|
1108
1192
|
: repos.length === 0
|
|
@@ -1178,6 +1262,27 @@ window.__ModuleLoader__.load({
|
|
|
1178
1262
|
inbox.errors && inbox.errors.length
|
|
1179
1263
|
? inbox.errors.map((item, index) => h('div', { key: index, style: S.warn }, item))
|
|
1180
1264
|
: null,
|
|
1265
|
+
h('div', { style: S.card },
|
|
1266
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
1267
|
+
h('strong', { style: { fontSize: 13 } }, '通知'),
|
|
1268
|
+
h('div', { style: { display: 'flex', gap: 6 } },
|
|
1269
|
+
h('button', { style: { ...S.button, padding: '1px 8px', fontSize: 11 }, disabled: busy === 'notice', onClick: loadNotifications }, '拉取'),
|
|
1270
|
+
h('button', { style: { ...S.button, padding: '1px 8px', fontSize: 11 }, disabled: busy === 'notice-read', onClick: readAllNotifications }, '全部已读'),
|
|
1271
|
+
),
|
|
1272
|
+
),
|
|
1273
|
+
h('p', { style: S.notice }, '通知只有「个人访问令牌 / 环境变量」连接能读;GitHub 不对 App 令牌开放这个接口。'),
|
|
1274
|
+
notifications
|
|
1275
|
+
? notifications.items.length
|
|
1276
|
+
? notifications.items.map((item) =>
|
|
1277
|
+
h('div', { key: item.id, style: S.row },
|
|
1278
|
+
h('span', { style: { ...S.meta, width: 64 } }, item.reason),
|
|
1279
|
+
h('span', { style: S.name }, item.title || item.type),
|
|
1280
|
+
h('span', { style: S.meta }, item.repo),
|
|
1281
|
+
),
|
|
1282
|
+
)
|
|
1283
|
+
: h('p', { style: S.notice }, `没有未读通知(${notifications.count} 条)`)
|
|
1284
|
+
: null,
|
|
1285
|
+
),
|
|
1181
1286
|
inbox.issues
|
|
1182
1287
|
? h('div', { style: S.card },
|
|
1183
1288
|
h('strong', { style: { fontSize: 13 } }, `Issues (${inbox.issues.returned})`),
|