@modesto_ma/dsh-guanxiang 0.1.0-beta.1 → 0.1.0-beta.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/README.md CHANGED
@@ -57,13 +57,14 @@
57
57
  父 Agent 按应用分节汇总,涉及多个应用时给出跨应用的推演
58
58
  ```
59
59
 
60
- - **一个入口。** 插件只提供用户斜杠入口 `/guanxiang`(模型不会自行加载)。dsh 在 Web、TUI、ACP 以及经 dsh_channels 的飞书消息中都能识别它。
60
+ - **一个入口,两种触发。** 入口 SKILL 是 `/guanxiang`,dsh 在 Web、TUI、ACP 以及经 dsh_channels 的飞书消息中都能识别它。有可用应用且 `autoInvoke` 开启(默认)时,模型也能自行加载:dsh 给顶层 Agent 的 skill 目录里,观象的描述会列出每个可用应用的名称、id、别名和日志特征(总长不超过 500 字,放不下的只计数),用户说「分析这份订单服务的日志」或贴出带 `OrderController` 的报错时,模型会先加载观象。日志明显不属于任何已注册应用时,入口 SKILL 让模型按普通方式处理,不派发也不追问。子 Agent 的工作目录在 `reposDir` 内,那里不列出观象。应用增删时 dsh 会追加一条新的 skill 目录消息;想要确定触发时仍用 `/guanxiang`。
61
61
  - **派发由代码完成。** 模型只给出应用 id、问题和日志位置;仓库目录、应用 SKILL、并发上限都由插件决定。应用 id 必须与注册表一一对应,否则整次派发被拒绝。
62
62
  - **日志一律以绝对路径交给子 Agent。** 附件和本机文件直接传路径;消息里的对象存储下载链接由派发工具下载(只允许白名单域名,不带鉴权,限制大小与耗时)。日志包不解压,由应用的日志分析 SKILL 在运行目录里解压。
63
63
  - **应用目录随时最新。** 每次加载 `/guanxiang` 都先 `git fetch` 各仓库(间隔由 `fetchIntervalMs` 控制,默认每次),再从远端分支最新提交的 git 对象读取应用描述生成应用目录。fetch 不改动任何检出,所以正在进行的分析不会挡住更新。最多等待 `refreshWaitMs`,超时就先用已有的目录,fetch 在后台继续。
64
64
  - **代码快照不可变。** 子 Agent 在 `<reposDir>/.snapshots/<仓库名>/` 下按提交创建的 `git worktree` 快照里工作。快照创建后不再改动,同一提交的派发共用一份;没有分析在用、且已不是最新提交的快照会被删除。
65
65
  - **运行目录。** 每次派发在父会话目录下创建 `.guanxiang/runs/<runId>/<序号>-<应用 id>/`,下载的日志放在这里,子 Agent 也只在这里写文件;应用仓库对子 Agent 只读。
66
66
  - **等待式派发。** 工具等待所有子 Agent 结束后一次返回,一条消息对应一张完整回复;超过派发超时或调用被取消时停止仍在运行的子 Agent。子会话中不提供派发工具。
67
+ - **SKILL 改进(可选,默认关闭)。** 子 Agent 发现应用的日志分析 SKILL 有欠缺时,可以在运行目录写出修改提议;经用户授权后,观象把它推送到应用仓库的新分支并创建合并请求,见 [SKILL 改进](#skill-改进)。
67
68
 
68
69
  ## 安装与配置
69
70
 
@@ -93,6 +94,10 @@ npm 发行包已包含构建产物;本地 `link:` 安装前必须先执行 `pn
93
94
  - url: git@github.com:example/order-service.git
94
95
  - url: https://github.com/example/pay-service.git
95
96
  branch: release # 可选,默认跟随远端默认分支
97
+ gitCredentials: # https 仓库的访问令牌,只写令牌名称,不写令牌值
98
+ - url: https://gitlab.example.com # 地址前缀;其下的 https 仓库使用该令牌
99
+ username: oauth2 # 可选,默认 oauth2
100
+ tokenEnv: GITLAB_TOKEN # DSH 凭据库中的令牌名称,也可以是同名环境变量
96
101
  fetchIntervalMs: 0 # 加载 /guanxiang 时距上次拉取超过该时间的仓库先 fetch;0 = 每次
97
102
  maxAppsPerRequest: 4 # 单次派发的任务上限
98
103
  dispatchTimeoutMs: 1800000 # 等待全部子 Agent 的上限
@@ -103,9 +108,28 @@ npm 发行包已包含构建产物;本地 `link:` 安装前必须先执行 `pn
103
108
  subagentProvider: spawn # 子 Agent 使用的 ctx.subagents provider
104
109
  gitTimeoutMs: 600000 # 单条 git 命令的超时
105
110
  refreshWaitMs: 15000 # 加载 /guanxiang 时等待 fetch 的上限;0 = 不等待
111
+ autoInvoke: true # 任务匹配已注册应用时模型可自行加载入口 SKILL;false = 只能输入 /guanxiang
112
+ skillUpdates: # SKILL 改进,见下文
113
+ enabled: false # 默认关闭
114
+ maxFiles: 16 # 一次提议最多新增或修改的文件数
115
+ maxFileBytes: 262144 # 提议中单个文件的大小上限
116
+ skillUpdateAuthor: # 可选:SKILL 改进提交的作者;省略时使用本机 git 的 user.name / user.email
117
+ name: 观象
118
+ email: guanxiang@example.com
106
119
  ```
107
120
 
108
- 配置在加载时校验,不合法时插件加载失败。git 地址支持 https/http/ssh/git/file URL、`user@host:path` 和绝对路径,拉取时使用本机已有的 git 凭据(SSH key 或 credential helper),插件不保存密码或 token,也不会弹出交互式输入。
121
+ 配置在加载时校验,不合法时插件加载失败。git 地址支持 https/http/ssh/git/file URL、`user@host:path` 和绝对路径,拉取时使用本机已有的 git 凭据(SSH key 或 credential helper),不会弹出交互式输入。
122
+
123
+ ### 访问令牌
124
+
125
+ 用 https 地址拉取 GitLab 等私有仓库时,可以配置个人访问令牌(GitLab 需要 `read_repository` 权限;开启 [SKILL 改进](#skill-改进) 时需要 `write_repository`):
126
+
127
+ - **配置只写名称。** `gitCredentials` 的每一项把一个地址前缀(`https://主机[:端口][/路径]`)对应到一个令牌名称 `tokenEnv`;地址在前缀下的 https 仓库使用该令牌,多个前缀匹配时取路径最长的。ssh、`user@host:path` 和本地路径不受影响。
128
+ - **令牌值在 DSH 凭据库。** 令牌通过 DSH 的 `ctx.credentials` 读取(默认组合加载的 `@deepseek-ai/dsh-credentials-local`,文件 `$DSH_HOME/.credentials.yaml`,仅本机用户可读),可以在设置面板的「访问令牌」分页保存,也可以设置同名环境变量或写进 `.env`。每次拉取都重新读取,更换令牌不用重启。面板接口只接受已保存的配置引用的名称,也从不返回令牌值。
129
+ - **只交给 git。** 拉取时令牌经环境变量交给这一次的 git 进程,由只对该主机生效的凭据助手在服务器要求认证时提供,本机为该主机配置的其他凭据助手不参与;令牌不出现在命令行参数、`.git/config`、日志或模型上下文里。需要 git 2.31 及以上版本。
130
+ - **缺失时明确报错。** 地址匹配了令牌配置但令牌未设置,或 DSH 组合没有凭据服务时,该仓库拉取失败,原因显示在设置面板。
131
+
132
+ 凭据库文件只防其他系统用户。与 DSH 中的模型 API Key 一样,Agent 的命令以同一系统用户运行,文件权限不能把令牌与 Agent 隔离(见 `@deepseek-ai/dsh-credentials-local` 文档);建议使用只读权限、设置过期时间的令牌。
109
133
 
110
134
  子 Agent 的命令在 dsh 的文件沙箱中运行:仓库只读,只有父会话的项目目录可写,运行目录就在其中。Linux 的 bubblewrap 沙箱会把 `/tmp` 换成空的临时目录,所以 `reposDir` 不要放在 `/tmp` 下,否则子 Agent 的命令看不到仓库。
111
135
 
@@ -118,10 +142,11 @@ DSH Web 左侧栏的「观象」入口打开整页设置面板:
118
142
  | 分页 | 内容 |
119
143
  |---|---|
120
144
  | 应用仓库 | git 地址列表(分支可选)、每个仓库的拉取状态、提交号、应用描述与不可用原因,单个或全部重新拉取 |
145
+ | 访问令牌 | https 地址前缀、用户名与令牌名称;保存后填入令牌,显示是否已设置及来源,可清除 |
121
146
  | 日志下载 | 允许下载的域名、单文件大小上限、下载超时 |
122
- | 高级 | 拉取目录、更新间隔、单次应用数上限、派发超时,恢复 cordis.yml 配置 |
147
+ | 高级 | 拉取目录、更新间隔、单次应用数上限、派发超时、SKILL 改进开关与提议上限,恢复 cordis.yml 配置 |
123
148
 
124
- 面板保存的值写入 `$DSH_HOME/guanxiang/settings.json`(只保存与 cordis.yml 不同的字段),按与配置相同的规则校验。面板接口 `/guanxiang/*` 使用 DSH 自己的登录与来源校验,写操作另做同源校验。
149
+ 面板保存的值写入 `$DSH_HOME/guanxiang/settings.json`(只保存与 cordis.yml 不同的字段),按与配置相同的规则校验;令牌值不在其中,存入 DSH 凭据库。面板接口 `/guanxiang/*` 使用 DSH 自己的登录与来源校验,写操作另做同源校验。
125
150
 
126
151
  ## 应用仓库约定
127
152
 
@@ -142,6 +167,23 @@ skill: log-analysis # 对应 .dsh/skills/log-analysis/SKILL.md
142
167
 
143
168
  插件拉取仓库后检查这两个文件;缺失、不合法,或多个仓库声明同一个 id 时,相关应用不可用,原因显示在设置面板。应用描述和 SKILL 必须是普通文件,不能是符号链接。删除地址不会删除本地克隆,它的快照在没有分析使用后删除。
144
169
 
170
+ ## SKILL 改进
171
+
172
+ 开启 `skillUpdates.enabled`(设置面板「高级」→「SKILL 改进」)后,分析中发现的 SKILL 欠缺可以经用户授权后提交为合并请求:
173
+
174
+ 1. **子 Agent 写提议。** 子 Agent 的任务消息多出一节说明:把要改的文件从 `.dsh/skills/<skill>/` 复制到运行目录的 `skill-proposal/files/`(保持相对路径)后修改,理由写进 `skill-proposal/reason.md`。仓库对子 Agent 仍然只读。
175
+ 2. **派发结果标出提议。** 派发结束后,观象检查已完成任务的提议:只接受普通文件和受限的文件名、UTF-8 文本、文件数与大小上限,`SKILL.md` 不能设置 `user-invocable: false`。合格的提议在结果中给出改动行数,并在运行目录写出 `skill-proposal.diff`;不合格的给出原因。
176
+ 3. **父 Agent 展示并提交。** 入口 SKILL 让父 Agent 在汇总回复后附上改动和 diff,再调用 `guanxiang_propose_skill`(参数为任务的运行目录和一句话摘要)。只接受本次 DSH 运行中由同一会话派发过的任务;应用、仓库和分析时的提交取自派发记录。
177
+ 4. **请求授权。** 工具通过 DSH 的审批服务(`ctx.approval`,`@deepseek-ai/dsh-user-approval`)请求一次性授权,说明将推送的仓库、分支、目标分支、改动文件和理由。经 dsh_channels 使用时显示为飞书决策卡片,在 DSH Web 中显示为审批提示;观象与 dsh_channels 之间没有代码依赖。只有「允许」才推送;拒绝、撤回或没有可回答的界面时都不推送。会话的审批策略为 `never`(例如 DSH 的「完全访问」权限模式)时请求一律被拒绝,所以要在「询问」类权限模式下使用;DSH 组合没有审批服务时工具报错。
178
+ 5. **推送新分支并创建合并请求。** 观象进程(不是 Agent)在拉取仓库中以分析时的提交为父提交生成提交,只改 `.dsh/skills/<skill>/` 下的文件,不动任何检出和快照;然后推送到新分支 `guanxiang/skill-<应用 id>-<树对象前缀>`,用 GitLab push options(`merge_request.create`、`merge_request.target`、`merge_request.title`、`merge_request.description`)创建合入跟踪分支的合并请求,返回服务器给出的合并请求链接。同一改动的分支已存在时不再请求授权,也不推送。从不推送已有分支或默认分支,合并由仓库的评审流程决定;合并后下次 `/guanxiang` 拉取即生效。
179
+
180
+ 注意:
181
+
182
+ - 只支持 GitLab:不支持 push options 的服务器会拒绝这次推送。https 仓库的令牌需要 `write_repository`(不需要 `api`);ssh 地址使用本机的 SSH key。
183
+ - 个人访问令牌加了写权限后,可以推送你有权限的所有项目。建议改用只覆盖应用仓库的项目或组访问令牌,设置过期时间,并保护应用仓库的默认分支。
184
+ - 合并请求以令牌主人的身份创建,提交作者是 `skillUpdateAuthor` 或本机 git 身份。飞书群里点「允许」的人可能不是令牌主人;合并请求描述写明了来源会话与分析提交。
185
+ - 日志内容不可信,可能诱导模型写出不当的 SKILL。观象只限制改动范围,内容需要授权的人和合并请求的评审者把关。
186
+
145
187
  ## 通过飞书使用
146
188
 
147
189
  观象与 [dsh_channels](https://github.com/modestoma/dsh_channels) 没有代码耦合。dsh_channels 把不在自己命令表中的 `/` 开头消息作为普通 prompt 交给 dsh,dsh 识别 `/guanxiang` 后展开入口 SKILL。飞书附件的宿主路径会出现在消息里,入口 SKILL 会把它作为日志路径派发。
@@ -168,9 +210,10 @@ pnpm check # 类型检查(Host 与 Client)+ 单元测试 + 构建 +
168
210
  |---|---|
169
211
  | `src/index.ts` | Cordis 插件入口 |
170
212
  | `src/service.ts` | 生效设置、注册表、入口 SKILL 与派发工具的注册 |
171
- | `src/repos/` | git 拉取、应用描述校验、应用注册表 |
213
+ | `src/repos/` | git 拉取、访问令牌、应用描述校验、应用注册表 |
172
214
  | `src/skill/entry.ts` | `/guanxiang` 入口 SKILL |
173
215
  | `src/dispatch/` | 派发工具、日志下载、子 Agent 首条消息 |
216
+ | `src/skill-update/` | SKILL 修改提议的校验、提交、授权与推送 |
174
217
  | `src/settings/` | 面板契约、覆盖文件、HTTP 路由 |
175
218
  | `src/client/` | 左侧栏入口与设置页面 |
176
219
  | `examples/order-service/` | 示例应用仓库 |
package/lib/client.js CHANGED
@@ -48,6 +48,8 @@ window.__ModuleLoader__.load({
48
48
  const SETTINGS_ROUTE = "/guanxiang/settings";
49
49
  /** POST:立即重新拉取全部仓库,或 body `{ url }` 指定的一个仓库。 */
50
50
  const SYNC_ROUTE = "/guanxiang/sync";
51
+ /** PUT:body `{ tokenEnv, value }` 把令牌存入 DSH 凭据库;DELETE:body `{ tokenEnv }` 删除已存的值。只接受已保存的访问令牌配置引用的名称。 */
52
+ const TOKEN_ROUTE = "/guanxiang/token";
51
53
  //#endregion
52
54
  //#region src/client/api.ts
53
55
  /**
@@ -126,16 +128,44 @@ window.__ModuleLoader__.load({
126
128
  body: JSON.stringify(url === void 0 ? {} : { url })
127
129
  })).state;
128
130
  }
131
+ /**
132
+ * Store an access token in DSH's credential store.
133
+ * @param tokenEnv - credential reference named by a saved access-token configuration.
134
+ * @param value - token value.
135
+ * @returns the new state, which reports only whether the token is set.
136
+ */
137
+ async function saveToken(tokenEnv, value) {
138
+ return (await request(TOKEN_ROUTE, {
139
+ method: "PUT",
140
+ body: JSON.stringify({
141
+ tokenEnv,
142
+ value
143
+ })
144
+ })).state;
145
+ }
146
+ /**
147
+ * Remove a stored access token.
148
+ * @param tokenEnv - credential reference named by a saved access-token configuration.
149
+ * @returns the new state.
150
+ */
151
+ async function clearToken(tokenEnv) {
152
+ return (await request(TOKEN_ROUTE, {
153
+ method: "DELETE",
154
+ body: JSON.stringify({ tokenEnv })
155
+ })).state;
156
+ }
129
157
  //#endregion
130
158
  //#region src/client/page.tsx
131
159
  /**
132
- * 左侧栏「观象」主区页面:应用仓库、日志下载、高级三个分页,共用一份草稿和
133
- * 底部保存条。仓库拉取中时每 2 秒刷新状态。
160
+ * 左侧栏「观象」主区页面:应用仓库、访问令牌、日志下载、高级(含 SKILL 改进)四个分页,共用
161
+ * 一份草稿和底部保存条;令牌值不进草稿,单独存入 DSH 凭据库。仓库拉取中时
162
+ * 每 2 秒刷新状态。
134
163
  *
135
164
  * @module dsh-guanxiang/client/page
136
165
  */
137
166
  /** Sidebar label and page title. */
138
167
  const PANEL_TITLE = "观象";
168
+ const KB = 1024;
139
169
  const MB = 1024 * 1024;
140
170
  const MINUTE = 60 * 1e3;
141
171
  const TABS = [
@@ -143,6 +173,10 @@ window.__ModuleLoader__.load({
143
173
  id: "repos",
144
174
  label: "应用仓库"
145
175
  },
176
+ {
177
+ id: "tokens",
178
+ label: "访问令牌"
179
+ },
146
180
  {
147
181
  id: "download",
148
182
  label: "日志下载"
@@ -159,12 +193,16 @@ window.__ModuleLoader__.load({
159
193
  return {
160
194
  reposDir: settings.reposDir,
161
195
  repos: settings.repos.map((repo) => ({ ...repo })),
196
+ gitCredentials: settings.gitCredentials.map((credential) => ({ ...credential })),
162
197
  fetchIntervalMin: trimNumber(settings.fetchIntervalMs / MINUTE),
163
198
  maxAppsPerRequest: String(settings.maxAppsPerRequest),
164
199
  dispatchTimeoutMin: trimNumber(settings.dispatchTimeoutMs / MINUTE),
165
200
  allowedHosts: [...settings.download.allowedHosts],
166
201
  maxMb: trimNumber(settings.download.maxBytes / MB),
167
- timeoutSec: trimNumber(settings.download.timeoutMs / 1e3)
202
+ timeoutSec: trimNumber(settings.download.timeoutMs / 1e3),
203
+ skillUpdatesEnabled: settings.skillUpdates.enabled,
204
+ skillMaxFiles: String(settings.skillUpdates.maxFiles),
205
+ skillMaxKb: trimNumber(settings.skillUpdates.maxFileBytes / KB)
168
206
  };
169
207
  }
170
208
  function positive(text, label, allowZero = false) {
@@ -175,12 +213,19 @@ window.__ModuleLoader__.load({
175
213
  function fromDraft(draft) {
176
214
  const maxApps = positive(draft.maxAppsPerRequest, "单次应用数上限");
177
215
  if (!Number.isInteger(maxApps)) throw new Error("单次应用数上限必须是整数");
216
+ const maxFiles = positive(draft.skillMaxFiles, "提议文件数上限");
217
+ if (!Number.isInteger(maxFiles)) throw new Error("提议文件数上限必须是整数");
178
218
  return {
179
219
  reposDir: draft.reposDir.trim(),
180
220
  repos: draft.repos.map((repo) => repo.branch === void 0 || repo.branch.trim() === "" ? { url: repo.url.trim() } : {
181
221
  url: repo.url.trim(),
182
222
  branch: repo.branch.trim()
183
223
  }),
224
+ gitCredentials: draft.gitCredentials.map((credential) => ({
225
+ url: credential.url.trim(),
226
+ username: credential.username.trim(),
227
+ tokenEnv: credential.tokenEnv.trim()
228
+ })),
184
229
  fetchIntervalMs: Math.round(positive(draft.fetchIntervalMin, "更新间隔", true) * MINUTE),
185
230
  maxAppsPerRequest: maxApps,
186
231
  dispatchTimeoutMs: Math.round(positive(draft.dispatchTimeoutMin, "派发超时") * MINUTE),
@@ -188,6 +233,11 @@ window.__ModuleLoader__.load({
188
233
  allowedHosts: draft.allowedHosts.map((host) => host.trim()).filter((host) => host !== ""),
189
234
  maxBytes: Math.round(positive(draft.maxMb, "单文件大小上限") * MB),
190
235
  timeoutMs: Math.round(positive(draft.timeoutSec, "下载超时") * 1e3)
236
+ },
237
+ skillUpdates: {
238
+ enabled: draft.skillUpdatesEnabled,
239
+ maxFiles,
240
+ maxFileBytes: Math.round(positive(draft.skillMaxKb, "提议单文件大小上限") * KB)
191
241
  }
192
242
  };
193
243
  }
@@ -291,11 +341,13 @@ window.__ModuleLoader__.load({
291
341
  kind: "ok",
292
342
  text: success
293
343
  });
344
+ return true;
294
345
  } catch (error) {
295
346
  setNotice({
296
347
  kind: "error",
297
348
  text: messageOf(error)
298
349
  });
350
+ return false;
299
351
  } finally {
300
352
  setBusy(false);
301
353
  }
@@ -404,6 +456,14 @@ window.__ModuleLoader__.load({
404
456
  run(() => syncRepos(url), url === void 0 ? "已开始重新拉取全部仓库" : "已开始重新拉取", false);
405
457
  }
406
458
  }) : null,
459
+ tab === "tokens" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TokensTab, {
460
+ draft,
461
+ setDraft,
462
+ state,
463
+ busy,
464
+ onSave: (tokenEnv, value) => run(() => saveToken(tokenEnv, value), `已保存 ${tokenEnv},使用它的仓库会重新拉取`, false),
465
+ onClear: (tokenEnv) => run(() => clearToken(tokenEnv), `已清除面板保存的 ${tokenEnv}`, false)
466
+ }) : null,
407
467
  tab === "download" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DownloadTab, {
408
468
  draft,
409
469
  setDraft,
@@ -617,7 +677,7 @@ window.__ModuleLoader__.load({
617
677
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
618
678
  className: "gx__secFoot",
619
679
  children: [
620
- "使用本机已有的 git 凭据(SSH key 或 credential helper)拉取,不留分支时跟随远端默认分支。每个仓库需包含 ",
680
+ "使用本机已有的 git 凭据(SSH key 或 credential helper)拉取;https 地址可在「访问令牌」中配置个人访问令牌。不留分支时跟随远端默认分支。每个仓库需包含 ",
621
681
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
622
682
  className: "gx__mono",
623
683
  children: ".dsh/guanxiang.yaml"
@@ -637,6 +697,232 @@ window.__ModuleLoader__.load({
637
697
  ]
638
698
  });
639
699
  }
700
+ const DEFAULT_USERNAME = "oauth2";
701
+ const DEFAULT_TOKEN_ENV = "GITLAB_TOKEN";
702
+ /** Credential store layers of `@deepseek-ai/dsh-credentials-local` other than its own file. */
703
+ const TOKEN_SOURCES = {
704
+ "env": "启动环境变量",
705
+ "project-env": "项目 .env",
706
+ "user-env": "$DSH_HOME/.env"
707
+ };
708
+ function tokenPill(token) {
709
+ if (token === void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
710
+ className: "gx__pill",
711
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "gx__dot" }), "保存后设置令牌"]
712
+ });
713
+ if (token.error !== void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
714
+ className: "gx__pill gx__pill--bad",
715
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "gx__dot" }), "无法读取"]
716
+ });
717
+ if (!token.configured) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
718
+ className: "gx__pill gx__pill--warn",
719
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "gx__dot" }), "未设置令牌"]
720
+ });
721
+ const source = token.source === void 0 || token.source === "file" ? void 0 : TOKEN_SOURCES[token.source] ?? token.source;
722
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
723
+ className: "gx__pill gx__pill--ok",
724
+ children: [
725
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "gx__dot" }),
726
+ "已设置",
727
+ source === void 0 ? "" : `(来自${source})`
728
+ ]
729
+ });
730
+ }
731
+ function TokensTab({ draft, setDraft, state, busy, onSave, onClear }) {
732
+ const [url, setUrl] = (0, react.useState)("");
733
+ const [username, setUsername] = (0, react.useState)(DEFAULT_USERNAME);
734
+ const [tokenEnv, setTokenEnv] = (0, react.useState)(DEFAULT_TOKEN_ENV);
735
+ const [values, setValues] = (0, react.useState)({});
736
+ const tokens = (0, react.useMemo)(() => new Map(state.credentials.tokens.map((token) => [token.tokenEnv, token])), [state.credentials.tokens]);
737
+ const saved = (0, react.useMemo)(() => new Set(state.settings.gitCredentials.map((credential) => credential.tokenEnv)), [state.settings.gitCredentials]);
738
+ const add = () => {
739
+ const trimmed = url.trim();
740
+ if (trimmed === "" || draft.gitCredentials.some((credential) => credential.url === trimmed)) return;
741
+ setDraft({
742
+ ...draft,
743
+ gitCredentials: [...draft.gitCredentials, {
744
+ url: trimmed,
745
+ username: username.trim() === "" ? DEFAULT_USERNAME : username.trim(),
746
+ tokenEnv: tokenEnv.trim() === "" ? DEFAULT_TOKEN_ENV : tokenEnv.trim()
747
+ }]
748
+ });
749
+ setUrl("");
750
+ };
751
+ const save = (name) => {
752
+ const value = values[name]?.trim() ?? "";
753
+ if (value === "") return;
754
+ onSave(name, value).then((ok) => {
755
+ if (ok) setValues((current) => ({
756
+ ...current,
757
+ [name]: ""
758
+ }));
759
+ });
760
+ };
761
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
762
+ className: "gx__sec",
763
+ children: [
764
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("h2", {
765
+ className: "gx__secTitle",
766
+ children: ["HTTPS 访问令牌 ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Overridden, {
767
+ keys: state.overridden,
768
+ name: "gitCredentials"
769
+ })]
770
+ }),
771
+ state.credentials.available ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
772
+ className: "gx__notice gx__notice--error",
773
+ children: "当前 DSH 组合没有加载凭据服务(@deepseek-ai/dsh-credentials-local),无法保存或读取令牌。"
774
+ }),
775
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
776
+ className: "gx__list",
777
+ children: [
778
+ draft.gitCredentials.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
779
+ className: "gx__emptyRow",
780
+ children: "还没有访问令牌。用 https 地址拉取 GitLab 等私有仓库时,添加服务器地址后保存,再填入个人访问令牌。"
781
+ }) : null,
782
+ draft.gitCredentials.map((credential, index) => {
783
+ const token = saved.has(credential.tokenEnv) ? tokens.get(credential.tokenEnv) : void 0;
784
+ const value = values[credential.tokenEnv] ?? "";
785
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
786
+ className: "gx__row gx__row--top",
787
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
788
+ className: "gx__rowText",
789
+ children: [
790
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
791
+ className: "gx__rowLabel",
792
+ children: [
793
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
794
+ className: "gx__mono",
795
+ children: credential.url
796
+ }),
797
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
798
+ className: "gx__tag",
799
+ children: ["用户名 ", credential.username]
800
+ }),
801
+ tokenPill(token)
802
+ ]
803
+ }),
804
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
805
+ className: "gx__rowSummary",
806
+ children: ["令牌名称 ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
807
+ className: "gx__mono",
808
+ children: credential.tokenEnv
809
+ })]
810
+ }),
811
+ token?.error === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
812
+ className: "gx__rowError",
813
+ children: token.error
814
+ }),
815
+ token !== void 0 && token.writable ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
816
+ className: "gx__addRow gx__addRow--flush",
817
+ children: [
818
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
819
+ className: "gx__input gx__mono",
820
+ type: "password",
821
+ autoComplete: "new-password",
822
+ spellCheck: false,
823
+ placeholder: token.configured ? "输入新令牌以替换" : "粘贴个人访问令牌,例如 glpat-…",
824
+ value,
825
+ onChange: (event) => {
826
+ setValues({
827
+ ...values,
828
+ [credential.tokenEnv]: event.target.value
829
+ });
830
+ },
831
+ onKeyDown: (event) => {
832
+ if (event.key === "Enter") save(credential.tokenEnv);
833
+ }
834
+ }),
835
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
836
+ type: "button",
837
+ className: "gx__btn",
838
+ disabled: busy || value.trim() === "",
839
+ onClick: () => {
840
+ save(credential.tokenEnv);
841
+ },
842
+ children: "保存令牌"
843
+ }),
844
+ token.configured && token.source === "file" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
845
+ type: "button",
846
+ className: "gx__btn gx__btn--ghost",
847
+ disabled: busy,
848
+ onClick: () => {
849
+ onClear(credential.tokenEnv);
850
+ },
851
+ children: "清除"
852
+ }) : null
853
+ ]
854
+ }) : null
855
+ ]
856
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
857
+ className: "gx__rowCtl",
858
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
859
+ type: "button",
860
+ className: "gx__btn gx__btn--danger",
861
+ onClick: () => {
862
+ setDraft({
863
+ ...draft,
864
+ gitCredentials: draft.gitCredentials.filter((_, position) => position !== index)
865
+ });
866
+ },
867
+ children: "删除"
868
+ })
869
+ })]
870
+ }, credential.url);
871
+ }),
872
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
873
+ className: "gx__addRow",
874
+ children: [
875
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
876
+ className: "gx__input",
877
+ placeholder: "服务器地址,例如 https://gitlab.example.com",
878
+ value: url,
879
+ onChange: (event) => {
880
+ setUrl(event.target.value);
881
+ },
882
+ onKeyDown: (event) => {
883
+ if (event.key === "Enter") add();
884
+ }
885
+ }),
886
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
887
+ className: "gx__input gx__input--branch",
888
+ placeholder: `用户名(默认 ${DEFAULT_USERNAME})`,
889
+ value: username,
890
+ onChange: (event) => {
891
+ setUsername(event.target.value);
892
+ },
893
+ onKeyDown: (event) => {
894
+ if (event.key === "Enter") add();
895
+ }
896
+ }),
897
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
898
+ className: "gx__input gx__input--branch gx__mono",
899
+ placeholder: "令牌名称",
900
+ value: tokenEnv,
901
+ onChange: (event) => {
902
+ setTokenEnv(event.target.value);
903
+ },
904
+ onKeyDown: (event) => {
905
+ if (event.key === "Enter") add();
906
+ }
907
+ }),
908
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
909
+ type: "button",
910
+ className: "gx__btn",
911
+ disabled: url.trim() === "",
912
+ onClick: add,
913
+ children: "添加"
914
+ })
915
+ ]
916
+ })
917
+ ]
918
+ }),
919
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
920
+ className: "gx__secFoot",
921
+ children: "地址在这个前缀下的 https 仓库使用对应令牌拉取(多个匹配时取路径最长的),ssh 地址不受影响。GitLab 个人访问令牌需要 read_repository 权限,用户名填 oauth2 即可。令牌保存在 DSH 凭据库(默认 $DSH_HOME/.credentials.yaml,仅本机用户可读),面板只显示是否已设置;也可以设置与令牌名称同名的环境变量。拉取时令牌只经环境变量交给 git,不写入仓库配置、日志或模型上下文。"
922
+ })
923
+ ]
924
+ });
925
+ }
640
926
  function DownloadTab({ draft, setDraft, overridden }) {
641
927
  const [host, setHost] = (0, react.useState)("");
642
928
  const add = () => {
@@ -831,6 +1117,69 @@ window.__ModuleLoader__.load({
831
1117
  })]
832
1118
  })]
833
1119
  }),
1120
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
1121
+ className: "gx__sec",
1122
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
1123
+ className: "gx__secTitle",
1124
+ children: "SKILL 改进"
1125
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1126
+ className: "gx__list",
1127
+ children: [
1128
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1129
+ className: "gx__row",
1130
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1131
+ className: "gx__rowText",
1132
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1133
+ className: "gx__rowLabel",
1134
+ children: ["允许提出 SKILL 修改 ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Overridden, {
1135
+ keys: overridden,
1136
+ name: "skillUpdates"
1137
+ })]
1138
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1139
+ className: "gx__rowSummary",
1140
+ children: "子 Agent 发现应用的日志分析 SKILL 有欠缺时可以写出修改提议;经用户授权后,观象用访问令牌把它推送到新分支并创建合并请求(GitLab,令牌需要 write_repository 权限)。"
1141
+ })]
1142
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1143
+ className: "gx__rowCtl",
1144
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1145
+ type: "checkbox",
1146
+ className: "gx__check",
1147
+ "aria-label": "允许提出 SKILL 修改",
1148
+ checked: draft.skillUpdatesEnabled,
1149
+ onChange: (event) => {
1150
+ setDraft({
1151
+ ...draft,
1152
+ skillUpdatesEnabled: event.target.checked
1153
+ });
1154
+ }
1155
+ })
1156
+ })]
1157
+ }),
1158
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NumberRow, {
1159
+ label: "提议文件数上限",
1160
+ unit: "个",
1161
+ value: draft.skillMaxFiles,
1162
+ onChange: (value) => {
1163
+ setDraft({
1164
+ ...draft,
1165
+ skillMaxFiles: value
1166
+ });
1167
+ }
1168
+ }),
1169
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NumberRow, {
1170
+ label: "提议单文件大小上限",
1171
+ unit: "KB",
1172
+ value: draft.skillMaxKb,
1173
+ onChange: (value) => {
1174
+ setDraft({
1175
+ ...draft,
1176
+ skillMaxKb: value
1177
+ });
1178
+ }
1179
+ })
1180
+ ]
1181
+ })]
1182
+ }),
834
1183
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
835
1184
  className: "gx__sec",
836
1185
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
@@ -942,10 +1291,12 @@ window.__ModuleLoader__.load({
942
1291
  .gx__input:focus{border-color:var(--gx-accent)}
943
1292
  .gx__input--num{width:120px;text-align:right;font-variant-numeric:tabular-nums}
944
1293
  .gx__input--wide{width:320px}
1294
+ .gx__check{width:16px;height:16px;margin:0;accent-color:var(--gx-accent);cursor:pointer}
945
1295
  .gx__unit{min-width:36px;color:var(--gx-fg3);font-size:12px}
946
1296
  .gx__addRow{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:10px 14px}
947
1297
  .gx__addRow .gx__input{flex:1 1 160px;width:auto}
948
1298
  .gx__addRow .gx__input--branch{flex:0 1 140px}
1299
+ .gx__addRow--flush{padding:6px 0 0}
949
1300
  .gx__emptyRow{padding:11px 14px;color:var(--gx-fg3);font-size:12px}
950
1301
  .gx__btn{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:4px;height:28px;padding:0 12px;border:1px solid var(--gx-line);border-radius:7px;background:transparent;color:inherit;font:inherit;font-size:13px;cursor:pointer;white-space:nowrap}
951
1302
  .gx__btn:hover:not(:disabled){background:var(--gx-hover)}