dsh-session-superagent 0.9.173 → 0.9.175

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/CHANGELOG.md CHANGED
@@ -2,6 +2,84 @@
2
2
 
3
3
  格式参照 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## [0.9.175] - 2026-11-04 —— 吸收 PR #7 的好设计:`ghConfigDir`(去掉其中会漏路径的部分)
6
+
7
+ > 作者 **@ysl289** 一天多没回(无新提交、无新评论)。按你的意思,**我们自己吸收好的部分**,
8
+ > 不合并他的分支(那分支还基于 0.9.165,且有一处必须改)。
9
+
10
+ ### 他做对了什么(保留)
11
+ `gh` 的登录态按平台存在各自配置目录里,不指定时插件用的是**跑 DSH 这个人的账号** ——
12
+ 替团队干活的守,每条评论都挂在操作者名下。把 `GH_CONFIG_DIR` 指向一个只登录了智能体账号的目录,
13
+ 就能换成智能体身份,而且那个目录没登录时 `gh` 会直接失败(fail-closed),不会悄悄退回操作者。
14
+
15
+ ### 我改掉的那一处
16
+ 他原本把**绝对路径**直接拼进唤醒消息:
17
+
18
+ ```js
19
+ `请同样带上 GH_CONFIG_DIR=${options.ghConfigDir},否则 push 与提交会落到操作者账号上。`
20
+ ```
21
+
22
+ 唤醒消息会进模型上下文、进对话记录、可能被后续总结引用 —— 带上 `C:\Users\<用户名>\AppData\...`
23
+ 就等于把本机用户名和目录结构一并带出去。现在只说:
24
+
25
+ ```
26
+ 【提交身份】本插件的 gh 已绑定单独的智能体账号。你在会话里执行 git / git push 时如需一致身份,
27
+ 请向用户索取该账号的 gh 配置目录并设 GH_CONFIG_DIR;否则提交会落到操作者账号上。
28
+ ```
29
+
30
+ 路径由用户在需要时给出(他本来就知道)。
31
+
32
+ ### 落地清单
33
+ | 位置 | 改动 |
34
+ |---|---|
35
+ | `lib/index.js` `ghEnv()` | 带上 `GH_CONFIG_DIR`;面板配置的 token 仍优先 |
36
+ | `lib/index.js` `secretsSummary()` | 只回 `configured` / `none`,**不回路径** |
37
+ | `POST /credentials` | 接受 `ghConfigDir`;非绝对路径 400;空串清除 |
38
+ | `watch_doctor` | 新增「gh 账号」一项:未绑定 / 目录不存在 / 缺 `hosts.yml`(没登录过)/ 正常 |
39
+ | `formatWatchText` | 【提交身份】提示,**不含路径** |
40
+ | 面板「设置 → 凭证」 | 显示当前状态 + 一个新输入框(hook 追加在末尾,fixture 同步) |
41
+
42
+ ### 证据
43
+ ```
44
+ node --test → 274/274(新增 3 条:路由只收绝对路径 / 摘要不回显路径 / 唤醒消息提身份但不带路径)
45
+ preflight --fast → 全绿
46
+ 真机:formatWatchText({identityBound:true}) 含「【提交身份】」且不含 GH_CONFIG_DIR= 与 AppData
47
+ ```
48
+
49
+ ## [0.9.174] - 2026-11-04 —— 首次同步不该说「有 N 条新动态」
50
+
51
+ ### 现场(本轮唤醒)
52
+ 刚给本仓库新建守,第一轮唤醒就是:
53
+
54
+ ```
55
+ 【主理鱼】MYCF711/dsh-session-superagent 有 1 条新动态:
56
+ #7 [open] feat: ghConfigDir … 最后评论: 2026-11-04T06:41:38Z我(上一轮留的)
57
+ ```
58
+
59
+ 两条都不对:
60
+ 1. **它不是"新动态"** —— 是接上之前就开着的 PR;
61
+ 2. **"最后评论"是我自己留的** —— 等于自己叫醒自己,还以为有人在等回复。
62
+
63
+ ### 改法
64
+ `formatWatchText` 新增 `firstSync`(判据:`entry.cursor === null`,即这条守还没成功同步过):
65
+
66
+ ```
67
+ 首次: 【主理鱼】<repo> 首次同步:仓库里现有 N 条待处理(接上之前就在的,不是刚刚发生):
68
+ 平时: 【主理鱼】<repo> 有 N 条新动态:
69
+ ```
70
+
71
+ 事件类型也从 `wake` 记成 `baseline`(判定页能看到"这是基线,不是这一小时的新增")。
72
+
73
+ ### 顺带
74
+ `watch_ack` 的默认标签 `主理鱼:已处理` 在这个仓库里**原本不存在**(gh 加标签返回 422)。
75
+ 已建该标签并把 PR #7 标上 —— 插件里的 `watch_ack` 本来就会幂等创建,只是这个仓库从没跑过。
76
+
77
+ ### 证据
78
+ ```
79
+ node --test → 272/272(新增:首次同步不得出现「新动态」,平时仍是「新动态」)
80
+ 真机:gh pr view 7 → labels: ["主理鱼:已处理"]
81
+ ```
82
+
5
83
  ## [0.9.173] - 2026-11-04 —— 重启后的「会话已不在」误报:给 10 分钟宽限期
6
84
 
7
85
  ### 现场(重启后你看到的那条红字)
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img src="assets/icon-180.png" width="88" height="88" alt="">
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Version](https://img.shields.io/badge/version-0.9.173-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.175-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
7
7
  [![npm](https://img.shields.io/npm/v/dsh-session-superagent.svg)](https://www.npmjs.com/package/dsh-session-superagent)
8
8
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-plugin-orange.svg)](https://github.com/topics/dsh-plugin)
9
9
 
@@ -123,7 +123,7 @@ dsh plugin install /path/to/dsh-session-superagent
123
123
  ## 开发
124
124
 
125
125
  ```sh
126
- node --test # 271 项单测
126
+ node --test # 274 项单测
127
127
  ```
128
128
 
129
129
  ### 工具输出:文本给人和 agent,JSON 给程序
package/client.js CHANGED
@@ -14,7 +14,7 @@ window.__ModuleLoader__.load({
14
14
  const { useCallback, useEffect, useRef, useState } = React
15
15
 
16
16
  // 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
17
- const CLIENT_VERSION = '0.9.173'
17
+ const CLIENT_VERSION = '0.9.175'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
@@ -988,6 +988,8 @@ window.__ModuleLoader__.load({
988
988
  const [problemsOnly, setProblemsOnly] = useState(false)
989
989
  // 统计条筛选:点「异常」只看异常。放在 hook 列表末尾,避免打乱既有下标(测试桩按位置取值)
990
990
  const [stateFilter, setStateFilter] = useState(null)
991
+ // gh 账号配置目录(只收绝对路径;留空 = 用宿主当前登录的账号)
992
+ const [ghDir, setGhDir] = useState('')
991
993
  // 建议规则弹层:给"叫醒了没回音"一个下一步动作(只提供可复制的规则,不替客户写仓库文件)
992
994
 
993
995
  // 「我现在手上有没有能渲染的数据」。判断依据必须是**当前 snap**,不是"以前拿到过一次" ——
@@ -1126,8 +1128,11 @@ window.__ModuleLoader__.load({
1126
1128
  const saveCredentials = () => run(async () => {
1127
1129
  const payload = {}
1128
1130
  if (token.trim()) payload.token = token.trim()
1131
+ if (ghDir.trim()) payload.ghConfigDir = ghDir.trim()
1132
+ else if (ghDir === '') payload.ghConfigDir = '' // 显式清空 = 回到宿主账号
1129
1133
  await call('/credentials', { method: 'POST', body: JSON.stringify(payload) })
1130
1134
  setToken('')
1135
+ setGhDir('')
1131
1136
  }, '凭证已保存')
1132
1137
 
1133
1138
  const saveGoal = () => run(async () => {
@@ -1712,10 +1717,12 @@ window.__ModuleLoader__.load({
1712
1717
  + '(合计 ' + bytesText(body.isolation.totalBytes) + ')'],
1713
1718
  ] })),
1714
1719
  h(Section, { key: 'creds', title: '凭证' },
1715
- h(KeyValues, { rows: [['GitHub token', credentials.token === 'none' ? '未配置(回退到已登录的 gh CLI)' : '已配置'], ['SSH 私钥', credentials.sshKeyPath === 'none' ? '未配置(当前版本不使用)' : '已配置']] }),
1720
+ h(KeyValues, { rows: [['GitHub token', credentials.token === 'none' ? '未配置(回退到已登录的 gh CLI)' : '已配置'], ['SSH 私钥', credentials.sshKeyPath === 'none' ? '未配置(当前版本不使用)' : '已配置'],
1721
+ ['gh 账号', credentials.ghConfigDir === 'configured' ? '已绑定独立配置目录(评论挂智能体账号)' : '宿主当前登录的账号']] }),
1716
1722
  field('Token', h(Input, { type: 'password', value: token, placeholder: 'ghp_… / github_pat_…(留空不改)', onChange: (e) => setToken(e.target.value) })),
1723
+ field('gh 账号目录', h(Input, { value: ghDir, placeholder: '绝对路径;只想让它用自己的账号时填(留空 = 用宿主账号)', onChange: (e) => setGhDir(e.target.value) })),
1717
1724
  h('div', { className: 'dt-actions' }, h(Btn, { variant: 'primary', onClick: saveCredentials }, '保存凭证')),
1718
- h(Hint, null, '不填也能用:插件直接复用已登录的 gh CLI。')),
1725
+ h(Hint, null, '不填也能用:插件直接复用已登录的 gh CLI。填了 gh 账号目录,插件就用那个目录里的账号发言(git push 仍用会话自己的身份,唤醒消息里会提醒会话)。')),
1719
1726
  h(Section, { key: 'update', title: '版本与更新' },
1720
1727
  h(KeyValues, { rows: [
1721
1728
  ['当前版本', (update && update.current) || CLIENT_VERSION],
package/lib/index.js CHANGED
@@ -40,7 +40,7 @@ import {
40
40
 
41
41
  export const name = 'dsh-session-superagent'
42
42
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
43
- export const SERVER_VERSION = '0.9.173'
43
+ export const SERVER_VERSION = '0.9.175'
44
44
  export const inject = ['tools', 'agents', 'webServer']
45
45
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
46
46
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -223,6 +223,9 @@ function secretsSummary() {
223
223
  sshKeyPath: s.sshKeyPath ? 'configured' : 'none',
224
224
  // 从不在面板回显路径(Windows 路径里的反斜杠曾让掩码整段漏出)
225
225
  sshKeyHint: null,
226
+ // 「用哪个 gh 账号」同理:只回配没配,不回路径(取自 PR #7 的设计)
227
+ ghConfigDir: s.ghConfigDir ? 'configured' : 'none',
228
+ ghConfigDirHint: null,
226
229
  updatedAt: s.updatedAt ?? null,
227
230
  }
228
231
  }
@@ -320,8 +323,16 @@ function goalView(ctx, sessionId) {
320
323
  /** Environment for every gh call: a panel token wins over the CLI login. */
321
324
  function ghEnv() {
322
325
  const s = readSecrets()
323
- if (!s.token) return process.env
324
- return { ...process.env, GH_TOKEN: String(s.token) }
326
+ const env = { ...process.env }
327
+ // 为什么要 GH_CONFIG_DIR:`gh` 的登录态按平台存在各自配置目录里
328
+ // (Windows 在 %APPDATA%\GitHub CLI,POSIX 在 ~/.config/gh)。不指定时插件用的是
329
+ // 「跑 DSH 这个人的账号」—— 替团队干活的守,每条评论都会挂在操作者名下。
330
+ // 指向一个只登录了智能体账号的目录即可换身份;该目录没登录时 gh 直接失败(fail-closed)。
331
+ // 设计取自 PR #7(@ysl289)。
332
+ if (s.ghConfigDir) env.GH_CONFIG_DIR = String(s.ghConfigDir)
333
+ // 面板里显式配的 token 优先级最高:它就是要覆盖目录里可能存在的登录态。
334
+ if (s.token) env.GH_TOKEN = String(s.token)
335
+ return env
325
336
  }
326
337
 
327
338
  /**
@@ -1171,12 +1182,19 @@ async function pollOnce(ctx, entry, baseMs) {
1171
1182
  if (isolation && isolation.dir) entry.lastWorktree = isolation.dir
1172
1183
  // 批次前几条补「最后是谁在说话」(最多 3 条,失败静默)
1173
1184
  await fetchLastComments(entry.repo, listed)
1185
+ // 首次同步:这条守刚建好,或者宿主换了机器(cursor 还是 null)。
1186
+ // 此时"有动态"其实是"仓库里本来就有这些待处理",说成新动态会让人以为刚刚发生。
1187
+ const firstSync = !entry.cursor
1174
1188
  const wakeText = formatWatchText(entry.repo, listed, {
1175
1189
  more: rest.length,
1190
+ firstSync,
1176
1191
  restNumbers: rest.map((item) => item.number),
1177
1192
  isolation,
1178
1193
  // entry.goal 之前只写不读:现在真的进唤醒消息
1179
1194
  goal: entry.goal || '',
1195
+ // 只传「绑没绑智能体账号」这个布尔量:**不把路径写进唤醒消息**(会进模型上下文与对话记录,
1196
+ // 顺带把本机用户名和目录结构带出去)。路径由用户在需要时自己给。
1197
+ identityBound: Boolean(readSecrets().ghConfigDir),
1180
1198
  // 只读仓库要在任务书里直说,否则会话会去试写然后吃 403
1181
1199
  access: accessNote(entry.repoAccess),
1182
1200
  // 完成标准要可观测(Given-When-Then 的思路):三件事缺一不算完成
@@ -1222,7 +1240,9 @@ async function pollOnce(ctx, entry, baseMs) {
1222
1240
  entry.dailyWakes = bumpDailyWakes(entry.dailyWakes)
1223
1241
  entry.lastDeferred = null
1224
1242
  entry.deferReason = null
1225
- noteEvent(entry, 'wake', '唤醒了 ' + (entry.lastBatch || []).length + ' 条:' + (entry.lastBatch || []).map((n) => '#' + n).join(' '))
1243
+ noteEvent(entry, firstSync ? 'baseline' : 'wake',
1244
+ (firstSync ? '首次同步(存量 ' : '唤醒了 ') + (entry.lastBatch || []).length + ' 条' + (firstSync ? ')' : '') +
1245
+ ':' + (entry.lastBatch || []).map((n) => '#' + n).join(' '))
1226
1246
  entry.seen = advanceSeen(entry.seen, fresh)
1227
1247
  entry.lastReported = recordReported(entry, fresh)
1228
1248
  entry.cursor = newestUpdatedAt(fresh)
@@ -1700,6 +1720,14 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1700
1720
  else if (!isAbsolute(keyPath)) return json(res, 400, { error: 'sshKeyPath must be absolute' })
1701
1721
  else next.sshKeyPath = keyPath
1702
1722
  }
1723
+ // 「用哪个 gh 账号」:指向只登录了智能体账号的配置目录;空串 = 回到宿主当前账号。
1724
+ // 只收绝对路径:相对路径会随 cwd 漂移,把设置指向一个不存在的地方。
1725
+ if (typeof body.ghConfigDir === 'string') {
1726
+ const dir = body.ghConfigDir.trim()
1727
+ if (dir === '') delete next.ghConfigDir
1728
+ else if (!isAbsolute(dir)) return json(res, 400, { error: 'ghConfigDir must be absolute' })
1729
+ else next.ghConfigDir = dir
1730
+ }
1703
1731
  next.updatedAt = new Date().toISOString()
1704
1732
  writeSecrets(next)
1705
1733
  json(res, 200, { credentials: secretsSummary() })
@@ -2111,6 +2139,19 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2111
2139
  lines.push(`FAIL ${entry.repo} 不可访问:${why.hint}`)
2112
2140
  }
2113
2141
 
2142
+ // 2b. gh 账号配置目录:设了但目录不可读 / 没登录时,客户看到的只是「一直失败」
2143
+ {
2144
+ const dir = readSecrets().ghConfigDir
2145
+ if (!dir) {
2146
+ lines.push('OK gh 账号:使用宿主当前登录的账号(未绑定独立配置目录)')
2147
+ } else if (!existsSync(dir)) {
2148
+ lines.push('FAIL gh 账号:绑定的配置目录不存在(检查设置里的路径)')
2149
+ } else if (!existsSync(join(dir, 'hosts.yml'))) {
2150
+ lines.push('FAIL gh 账号:配置目录里没有 hosts.yml(该目录还没登录过:先在那个目录下跑 gh auth login)')
2151
+ } else {
2152
+ lines.push('OK gh 账号:已绑定独立配置目录(hosts.yml 存在)')
2153
+ }
2154
+ }
2114
2155
  // 3. ack 标签是否存在
2115
2156
  const label = entry.ackLabel || DEFAULT_ACK_LABEL
2116
2157
  const labRes = await run('gh', ['api', `repos/${entry.repo}/labels/${encodeURIComponent(label)}`, '--jq', '.name'], { env: ghEnv() })
package/lib/watch.js CHANGED
@@ -153,6 +153,16 @@ export function formatWatchText(repo, fresh, options = {}) {
153
153
  const goalLine = options.goal
154
154
  ? `${String.fromCharCode(10)}本条目主理目标:${String(options.goal).split(String.fromCharCode(13)).join(' ').split(String.fromCharCode(10)).join(' ').slice(0, 200)}`
155
155
  : ''
156
+ // 身份说明:插件调 gh 用的是它绑定的账号,会话里跑的 git push 用的是会话自己的环境。
157
+ // 不说明的话,gh 评论挂智能体名下、git 提交挂操作者名下 —— 一次改动两个作者。
158
+ //
159
+ // 注意:**这里不写路径**(PR #7 原本把 GH_CONFIG_DIR=<绝对路径> 塞进来)。唤醒消息会进模型上下文、
160
+ // 进对话记录、可能被后续总结引用;带路径就等于把本机用户目录一并带出去。
161
+ // 会话只要知道「该问用户」就够了 —— 用户本来就知道自己的路径。
162
+ const identityLine = options.identityBound
163
+ ? String.fromCharCode(10) + '【提交身份】本插件的 gh 已绑定单独的智能体账号。你在会话里执行 git / git push 时如需一致身份,'
164
+ + '请向用户索取该账号的 gh 配置目录并设 GH_CONFIG_DIR;否则提交会落到操作者账号上。'
165
+ : ''
156
166
  const moreLine = more > 0
157
167
  ? `\n(另有 ${more} 条:${rest},处理完这批再看)`
158
168
  : ''
@@ -188,12 +198,15 @@ export function formatWatchText(repo, fresh, options = {}) {
188
198
  + criteria.map((line, i) => (i + 1) + '. ' + line).join(String.fromCharCode(10))
189
199
  : ''
190
200
  return (
191
- `【主理鱼】${repo} 有 ${lines.length} 条新动态:\n` +
201
+ (options.firstSync
202
+ ? `【主理鱼】${repo} 首次同步:仓库里现有 ${lines.length} 条待处理(接上之前就在的,不是刚刚发生):`
203
+ : `【主理鱼】${repo} 有 ${lines.length} 条新动态:`) + String.fromCharCode(10) +
192
204
  lines.join('\n') +
193
205
  whyLine +
194
206
  moreLine +
195
207
  isoLine +
196
208
  goalLine +
209
+ identityLine +
197
210
  accessLine +
198
211
  criteriaLine +
199
212
  '\n\n接下来:' +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.173",
3
+ "version": "0.9.175",
4
4
  "description": "Session-level superagent for DeepSeek Harness: watch a GitHub repository and wake a session when something needs doing. Credentials never reach the model.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",