dsh-github-console 0.5.0 → 0.6.2
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 +19 -0
- package/.github/workflows/publish.yml +31 -0
- package/README.md +34 -10
- package/index.js +296 -180
- package/lib/collect.mjs +73 -0
- package/lib/pure.mjs +196 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +3 -2
- package/scripts/check.mjs +79 -0
- package/test/collect.test.mjs +61 -0
- package/test/pure.test.mjs +137 -0
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
18
|
+
- name: Unit tests
|
|
19
|
+
run: node --test test/
|
|
@@ -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
|
|
|
@@ -104,15 +108,20 @@ manifest 的三步必须在 **1 小时**内完成,`state` 一次性、5 分钟
|
|
|
104
108
|
|
|
105
109
|
发布步骤(全部通过 GitHub REST 完成,不需要本机 git,也不执行任何 `npm install` / `prepare` / `postinstall`):
|
|
106
110
|
|
|
107
|
-
1. **体检** —— `package.json
|
|
111
|
+
1. **体检** —— `package.json`(容忍 BOM)、`dsh.bundle.patch`、入口文件、README/LICENSE/.gitignore、疑似密钥正则、本机绝对路径、npm 同名同版本、**敏感文件名拦截**(`.env*`、`.npmrc`、`*.pem/key/p12` 等直接 block)、**分支保护探测**
|
|
108
112
|
2. **仓库** —— 确认仓库可访问(不存在时给出 `github.com/new?name=…` 链接)
|
|
109
|
-
3. **推送** —— 收集目录内文件(跳过 `node_modules`、`.git`),经 blobs → tree → commit → ref
|
|
110
|
-
|
|
113
|
+
3. **推送** —— 收集目录内文件(跳过 `node_modules`、`.git`),经 blobs → tree → commit → ref 提交到目标分支:
|
|
114
|
+
- **删除同步**:远端有、本地没有的文件会被删除,但 `.github/workflows/*` 与 `.github/dependabot.yml` 属受保护路径,永不删除
|
|
115
|
+
- **执行位**:本地可执行文件按 `100755` 提交,其余 `100644`;提交后回读 tree 校验,结果写进推送步骤详情
|
|
116
|
+
- **文件数上限 300**:达到上限即 block(不再静默截断),超大文件会计入「跳过」并在详情里显示
|
|
117
|
+
4. **topic** —— 读出原有 topics,与配置里的 `topic`(默认 `dsh-plugin`)并集后整体写回;需要 `Administration: write`,没有权限时跳过而不是让发布失败
|
|
111
118
|
5. **Release** —— `v<version>`;已存在则跳过并提示
|
|
112
119
|
6. **市场探测** —— npm、仓库 topic、Release tag、`config.marketIndexUrls` 里的每个索引
|
|
113
120
|
|
|
114
121
|
探测失败记作 `unknown`,不会写成「未收录」——收录通常滞后 1–2 天。
|
|
115
122
|
|
|
123
|
+
npm 与市场索引的探测走的是插件自己的传输层(同一个代理 / 公共 DNS / CA 设置),不会绕过你的网络配置。
|
|
124
|
+
|
|
116
125
|
## 配置(`cordis.patch.yml` 的 config)
|
|
117
126
|
|
|
118
127
|
| 字段 | 默认 | 说明 |
|
|
@@ -139,17 +148,32 @@ manifest 的三步必须在 **1 小时**内完成,`state` 一次性、5 分钟
|
|
|
139
148
|
## 已知限制
|
|
140
149
|
|
|
141
150
|
- **个人仓库创建不在 API 内**:GitHub App 安装令牌结构上无法调用 `POST /user/repos`。请先建仓,或建空仓后让插件推送。
|
|
142
|
-
-
|
|
151
|
+
- **不在本机执行 npm**:npm 发布通过 GitHub Actions + Trusted Publisher(OIDC)完成;本机没有任何 npm 调用,也不保存 npm 令牌。
|
|
152
|
+
- 不自动提交第三方市场 PR:awesome-dsh-plugin 的条目录入仍需你提一次 PR(面板可生成条目字段)。
|
|
143
153
|
- 不接收 webhook(本地无公网入口),收件箱是拉取式。
|
|
144
154
|
- 只处理单个 installation;多账号需在面板里切换。
|
|
145
155
|
- 合并 PR / 重跑 CI 需要显式 `confirm: true`;它们不会走宿主的审批弹窗。
|
|
146
156
|
- 体检只做静态读取:命中的密钥会阻断发布并给出行号。
|
|
157
|
+
- 写请求(`POST/PATCH/DELETE`)**不自动重试**:超时后可能已经在服务端生效,重发会重复建 Issue/评论;读请求与 `PUT`(contents API 用 `sha` 做乐观锁)才重试。
|
|
158
|
+
- 推送后的执行位校验只能读回 GitHub 侧结果;本机是 Windows 时本地 `chmod` 语义受限,执行位规则的单元测试因此只在 Linux CI 上真跑。
|
|
159
|
+
|
|
160
|
+
## 测试与一致性
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
node scripts/check.mjs # 工具数/版本/README/locale 一致性 + 安全标记存在性
|
|
164
|
+
node --test test/ # 纯函数与目录收集规则(CI 上跑,Linux 才检查执行位)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
`test/pure.test.mjs` 覆盖:敏感文件名拦截、受保护路径、写操作能力映射、市场索引文档(单/多条目、时间戳稳定)、ZIP 解析(含 GitHub 日志那种「数据描述符导致本地头长度为 0」的回归用例);`test/collect.test.mjs` 覆盖:拒绝敏感文件、300 上限标记 `truncated`、超大文件计入 `skipped`、执行位映射。
|
|
147
168
|
|
|
148
169
|
## 安全
|
|
149
170
|
|
|
150
171
|
- 私钥、安装令牌、桥令牌只在 Host 侧;面板用同源 `/github-console/api/*` + `Authorization: Bearer`,无令牌返回 401。
|
|
151
172
|
- 回调与 setup 路由只在本机 webServer 上注册,不额外开端口。
|
|
152
173
|
- 所有对外错误信息不含凭据原文。
|
|
174
|
+
- **单一写闸门**:`readOnly` 与能力校验都在 `gh.call()` 里,工具与面板路由共用,无法绕过;每个写请求(成功或被拒)都写审计。
|
|
175
|
+
- **审计轮转**:`audit.ndjson` 超过 2 MB 时改名为 `audit.ndjson.1`(只保留上一份),长期运行不会撑爆磁盘。
|
|
176
|
+
- **限流可见**:面板状态页显示 core / search / graphql 的剩余额度与重置时间(每分钟最多读一次)。
|
|
153
177
|
|
|
154
178
|
## License
|
|
155
179
|
|