dsh-session-superagent 0.9.260 → 0.9.262
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 +93 -0
- package/README.md +3 -3
- package/SETUP.md +109 -0
- package/client.js +2 -1
- package/docs/README.md +2 -0
- package/lib/gitee.js +6 -0
- package/lib/index.js +116 -14
- package/lib/state-migration.js +25 -0
- package/lib/watch.js +46 -33
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,99 @@
|
|
|
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.262] - 2026-11-05 —— 状态可迁移、唤醒可分段、安装可复述
|
|
6
|
+
|
|
7
|
+
继续吸收官方工程纪律,不引入多角色或独立 Runtime。
|
|
8
|
+
|
|
9
|
+
### ① `watchers.json` 增加显式 `schemaVersion`
|
|
10
|
+
|
|
11
|
+
新增 `lib/state-migration.js`:
|
|
12
|
+
|
|
13
|
+
- v0(没有版本号的历史文件)→ v1,只补版本与必需容器,已有字段全部保留;
|
|
14
|
+
- `readState()` **先迁移、再 normalize**;
|
|
15
|
+
- 未来版本或非法版本拒绝按旧代码读取,自动退回 `.bak`,并把迁移后的备份写回主文件;
|
|
16
|
+
- `writeState()` 始终落当前版本。
|
|
17
|
+
|
|
18
|
+
同时补了两道清单:`sync-profile.mjs` 与 `package.json.files`。
|
|
19
|
+
并新增永久门禁:`lib/` 下任何 `.js` 没进 npm files,测试直接失败——本机硬链接能跑、发布包缺模块这类问题不能再漏。
|
|
20
|
+
|
|
21
|
+
### ② 唤醒消息变成稳定 sections
|
|
22
|
+
|
|
23
|
+
`buildWakeSections()` 返回有序 `{ id, lines }`:
|
|
24
|
+
`header / facts / selection? / overflow? / isolation? / goal? / identity? / access? / criteria? / next`。
|
|
25
|
+
|
|
26
|
+
`formatWatchText()` 只消费 sections。没有引入提示词编辑器或多角色。
|
|
27
|
+
goal 与标题中的换行、伪 `【完成标准】`、伪「接下来」都不能跳出所属段落。
|
|
28
|
+
|
|
29
|
+
旧新实现对拍 **7/7 IDENTICAL**,包括空 facts 的历史空行与合并场景。
|
|
30
|
+
|
|
31
|
+
### ③ 精简 `SETUP.md`
|
|
32
|
+
|
|
33
|
+
根目录新增 109 行安装剧本:
|
|
34
|
+
|
|
35
|
+
- 先只读探测,一次只问一个短问题;
|
|
36
|
+
- 收齐仓库、会话、过滤、隔离、goal 后给完整计划;
|
|
37
|
+
- 明确确认后才安装和写配置;
|
|
38
|
+
- 密钥只在操作者终端或面板凭证字段,不进入聊天;
|
|
39
|
+
- 验收覆盖 `watch_start / watch_status / watch_doctor`、面板、首轮唤醒与 `watch_ack`;
|
|
40
|
+
- 保留当前 profile 和一条安装命令,不复制官方 tmux/独立 profile。
|
|
41
|
+
|
|
42
|
+
并修正剧本中的 Gitee 默认标签为 `主理鱼-已处理`(半角冒号不被 Gitee 接受)。
|
|
43
|
+
|
|
44
|
+
### 证据
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
npm test → 442/442(新增:迁移 4 + 打包清单 2 + wake sections 7)
|
|
48
|
+
wake-samples → 7 个旧场景逐字兼容
|
|
49
|
+
npm pack --dry-run → 22 个文件,lib/state-migration.js 与 SETUP.md 均已包含
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## [0.9.261] - 2026-11-05 —— 完整解构官方结构树,并落地 Delivery + Outbox
|
|
53
|
+
|
|
54
|
+
### 完整解构,不只列功能清单
|
|
55
|
+
|
|
56
|
+
新增 `docs/official-decomp/` 五篇文档(约 1900 行):
|
|
57
|
+
|
|
58
|
+
- `01-structure-tree.md`:完整目录树、分层图、吸收取舍与落地状态;
|
|
59
|
+
- `02-runtime-execution.md`:61 个运行时文件、Trigger→Eval→Ticket→Executor 全链;
|
|
60
|
+
- `03-sources.md`:26 个来源文件、GitHub/Feishu 数据流、读位与幂等;
|
|
61
|
+
- `04-panel-tree.md`:6 Tab、Thread/Ticket 详情、设置分区与全部二三级页面;
|
|
62
|
+
- `05-prompts-skills-operations.md`:提示词、skills、SETUP、迁移、i18n 与测试组织。
|
|
63
|
+
|
|
64
|
+
所有关键结论锚定官方提交 `8c32a9d` 的文件与行号;不吸收的团队级复杂度也写明理由。
|
|
65
|
+
|
|
66
|
+
### 吸收 ①:Delivery —— 处理结论可以回写原条目
|
|
67
|
+
|
|
68
|
+
`watch_ack` 新增 `comment: true`:把同一个 `note` 评论到原 issue/PR,而不是只存在本地。
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
watch_ack({ number: 7, note: '已修,见 #57', comment: true })
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- 默认仍只打标签,不自动发评论;
|
|
75
|
+
- Gitee 通过 `kind: 'issue' | 'pull'` 选择正确端点;
|
|
76
|
+
- `comment:true` 缺 `note` 时,在**任何外部写操作之前**拒绝;
|
|
77
|
+
- 评论失败会明确区分 `phase:'comment'`,不会把「标签已打」误报成完整成功。
|
|
78
|
+
|
|
79
|
+
### 吸收 ②:Outbox FIFO —— 会话忙时排队,空闲按顺序送
|
|
80
|
+
|
|
81
|
+
以前忙时只保留水位、下轮重算:不丢事件,但没有真正的队列。
|
|
82
|
+
现在同一会话的唤醒进入 FIFO:
|
|
83
|
+
|
|
84
|
+
- 忙时入队,回调仍 `ok:false`,**不计次数、不推进水位**;
|
|
85
|
+
- 空闲后按顺序 `followup`,真正发送成功才结算;
|
|
86
|
+
- 相同 `queueKey` 去重,不重复排队;
|
|
87
|
+
- 插件实例隔离,热重载不会误送旧实例消息;
|
|
88
|
+
- 队列在内存中,重启后由未推进的水位重建;
|
|
89
|
+
- 面板行内显示「排队 N」。
|
|
90
|
+
|
|
91
|
+
### 证据
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
npm test → 429/429(新增:Delivery 3 + FIFO 3;旧 wake-accounting 也全过)
|
|
95
|
+
test/entry-parity-final.test.mjs → 3/3(上一轮 W9-W11 仍全绿)
|
|
96
|
+
```
|
|
97
|
+
|
|
5
98
|
## [0.9.260] - 2026-11-05 —— T40 入口对等收尾:同一件事,不再两套行为
|
|
6
99
|
|
|
7
100
|
### 工具新建也会做「添加前体检」
|
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)
|
|
6
|
-
[](https://github.com/MYCF711/dsh-session-superagent/releases)
|
|
7
7
|
[](https://www.npmjs.com/package/dsh-session-superagent)
|
|
8
8
|
[](https://github.com/topics/dsh-plugin)
|
|
9
9
|
[](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
|
|
@@ -146,7 +146,7 @@ Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不
|
|
|
146
146
|
## 开发
|
|
147
147
|
|
|
148
148
|
```sh
|
|
149
|
-
npm test #
|
|
149
|
+
npm test # 442 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
|
|
150
150
|
```
|
|
151
151
|
|
|
152
152
|
### 工具输出:文本给人和 agent,JSON 给程序
|
|
@@ -206,7 +206,7 @@ dsh plugin --profile <profile> add dsh-session-superagent@latest
|
|
|
206
206
|
|
|
207
207
|
|
|
208
208
|
```bash
|
|
209
|
-
npm test #
|
|
209
|
+
npm test # 442 项单测(带离线开关,约 1.6 秒)
|
|
210
210
|
node scripts/ui-audit.mjs # 11 项 UI 指标(写死颜色 / 自造 token / 官方结构采用 …)
|
|
211
211
|
node scripts/preflight.mjs # 41 项门禁(含上面两条,外加 profile 一致性、路由面、包内容)
|
|
212
212
|
node scripts/render-preview.mjs preview.html # 双主题静态预览,直接浏览器打开
|
package/SETUP.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# SETUP:主理鱼安装剧本
|
|
2
|
+
|
|
3
|
+
> 给 coding agent:陪操作者把 `dsh-session-superagent` 装进当前 DSH,并绑到一个现有会话。
|
|
4
|
+
> 操作者只需对自己的 agent 说:「读仓库根目录的 SETUP.md,按它带我安装主理鱼。」
|
|
5
|
+
|
|
6
|
+
## 0. 纪律
|
|
7
|
+
|
|
8
|
+
- 收齐全部答案前,只读 [README](README.md) 和 [为什么做这个产品](docs/为什么做这个产品.md),再跑一次下面的探测;除探测外不读别的文件、不改配置。
|
|
9
|
+
- 一条消息只问一个短问题,等回答再问下一题;每题给推荐答案和一句理由。上下文已经明确回答的题跳过。
|
|
10
|
+
- 提问期间不执行安装或配置。收齐全部答案后,一次给出完整计划;操作者明确确认后才执行。
|
|
11
|
+
- 密钥永远不在聊天里索要。登录只给操作者自己终端里的命令;token 只指向面板「主理鱼 → 设置 → 凭证」字段。
|
|
12
|
+
- 保留轻量形态:当前 profile、当前会话、一条插件安装命令。不另建 profile,不引入 tmux、独立 agent 账号或多角色执行体。
|
|
13
|
+
|
|
14
|
+
## 1. 只读探测
|
|
15
|
+
|
|
16
|
+
在仓库目录运行一次;逐项记录结果,缺失项进入计划,不变成追加问题:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
dsh --version
|
|
20
|
+
gh --version
|
|
21
|
+
printf 'DSH_PROFILE=%s\nDSH_HOME=%s\n' "${DSH_PROFILE-}" "${DSH_HOME-}"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
再按需调用现有工具:
|
|
25
|
+
|
|
26
|
+
- `repo_here`:只读当前 GitHub 仓库,作为第 1 题的推荐值;不可用就不猜仓库。
|
|
27
|
+
- `watch_doctor({format:"json"})`:插件已挂载时做安装前诊断;工具不存在就记为「尚未挂载或尚未加载」。它自己的隔离目录临时探针会自动删除。
|
|
28
|
+
|
|
29
|
+
除 `watch_doctor` 自身的检查外,不运行 `gh api`、`curl` 等网络探测,不运行 `gh auth token`,不读取凭证文件。
|
|
30
|
+
`DSH_PROFILE` 作为安装 profile;为空时在计划中列 `desktop`,由操作者随完整计划一起确认。
|
|
31
|
+
|
|
32
|
+
## 2. 一次一问
|
|
33
|
+
|
|
34
|
+
按顺序问以下五项。引号内是可改写的短模板,不要合并成问卷。
|
|
35
|
+
|
|
36
|
+
1. **仓库**
|
|
37
|
+
「要盯哪个仓库?推荐:当前仓库(GitHub 用 `owner/name`,Gitee 用 `gitee:owner/name`);直接用当前仓库最少抄录,也不容易绑错。」
|
|
38
|
+
2. **绑定会话**
|
|
39
|
+
「绑到当前这个会话吗?推荐:当前会话;`watch_start` 只唤醒调用它的会话,不必新开窗口或 agent。」
|
|
40
|
+
若答案是否,让操作者打开目标会话后从本剧本继续;不要编造 `sessionId` 参数。
|
|
41
|
+
3. **过滤与作者白名单**
|
|
42
|
+
「首轮过滤怎么设?推荐:`labels` 留空、`allowAuthors` 只含你的登录名(回复『默认:登录名』即可);先只让可信赖的人派活,噪音最小。」
|
|
43
|
+
操作者选择其他过滤时,在同一题收齐 `labels` / `ignoreLabels` / `allowAuthors` / `onlyAssigned` 等值。
|
|
44
|
+
4. **隔离**
|
|
45
|
+
「是否用一次性 worktree 隔离?推荐:首轮 `isolated:false`,先验证盯与唤醒,不创建副本;若选 `true`,请同答给出本地仓库的绝对 `workdir`。」
|
|
46
|
+
5. **goal**
|
|
47
|
+
「每次唤醒要附带什么目标?推荐:『按仓库 AGENTS.md 分诊并推进已确认事项,处理后 watch_ack』;这样唤醒本身就是可执行的任务书。」
|
|
48
|
+
|
|
49
|
+
轮询间隔、限流、凭证和 profile 不另起问题:采用默认值或写进完整计划。
|
|
50
|
+
|
|
51
|
+
## 3. 收齐后给完整计划
|
|
52
|
+
|
|
53
|
+
用一条消息列全以下内容,末尾只问「按此计划执行吗?」:
|
|
54
|
+
|
|
55
|
+
- **安装**:目标 profile;执行 `dsh plugin --profile <profile> add dsh-session-superagent`,已挂载则跳过重复安装。
|
|
56
|
+
- **绑定**:仓库、当前会话、过滤/作者白名单、`isolated`(开启时含 `workdir`)、goal。
|
|
57
|
+
- **默认值**:`intervalSec:60`、单次 5 条、单 watcher 每小时 6 次、整会话每小时 12 次、默认 ack 标签(GitHub `主理鱼:已处理` / Gitee `主理鱼-已处理`);未选的过滤参数省略。
|
|
58
|
+
- **操作者步骤**:需要登录时在自己终端跑 `gh auth login`;token 只填面板凭证字段。Gitee 需要 ack 时先建标签 `主理鱼-已处理`(Gitee 不允许半角冒号),GitHub 首次 ack 会自动建 `主理鱼:已处理`。
|
|
59
|
+
- **写入与回滚**:`watch_start` 会保存 watcher 并开始轮询;可用 `watch_stop({repo})` 暂停,确认不再需要时用 `watch_stop({repo,delete:true})` 删除配置。
|
|
60
|
+
- **验收**:下列第 5 节全部步骤;`watch_ack` 是否执行、是否回写评论,以及评论正文,都列清楚。
|
|
61
|
+
|
|
62
|
+
计划未获明确确认前,不调用安装命令、`watch_start`、`watch_ack`,也不替操作者创建测试 issue。
|
|
63
|
+
|
|
64
|
+
## 4. 确认后执行
|
|
65
|
+
|
|
66
|
+
1. **先做操作者步骤**。等待其完成登录或面板凭证填写;凭证失效时只重复给出 `gh auth login` 或凭证字段位置。
|
|
67
|
+
2. **装进当前 profile**(把占位符换成已确认值):
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
dsh plugin --profile <profile> add dsh-session-superagent
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
不用 `npm i` 代替 profile 安装。`dsh` 不在 PATH 时保留原报错,把同一条命令交给操作者在自己的 DSH 终端执行。
|
|
74
|
+
3. **登记 watcher**。将计划中确认的参数传给 `watch_start`,例如:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"repo": "owner/name",
|
|
79
|
+
"intervalSec": 60,
|
|
80
|
+
"allowAuthors": ["operator-login"],
|
|
81
|
+
"isolated": false,
|
|
82
|
+
"goal": "按仓库 AGENTS.md 分诊并推进已确认事项,处理后 watch_ack"
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
示例不是固定答案:替换占位值;未选 `allowAuthors` 就省略,开启隔离则加入绝对路径 `workdir`。同一仓库重复调用会更新配置,不另造会话。
|
|
87
|
+
4. 任一步失败就报告原文;只修复已确认计划内的原因,新增外部写入先回到计划确认。
|
|
88
|
+
|
|
89
|
+
## 5. 安装后验收
|
|
90
|
+
|
|
91
|
+
| 顺序 | 动作 | 通过标准 |
|
|
92
|
+
|---|---|---|
|
|
93
|
+
| 1 | 已确认计划中的 `watch_start` 返回后,调用 `watch_status({format:"json"})` | 目标仓库出现,绑定当前会话,配置与计划一致,未处于意外暂停 |
|
|
94
|
+
| 2 | 调用 `watch_doctor({repo:"owner/name",format:"json"})` | gh 登录、仓库访问、挂载与隔离目录检查无 `FAIL`;GitHub 首次缺少 ack 标签的 `WARN` 可由首次 ack 消除 |
|
|
95
|
+
| 3 | 操作者看当前 DSH 面板 | 中间栏出现「主理鱼」,输入框下方总卫星环可展开,目标仓库可见;不另起面板服务 |
|
|
96
|
+
| 4 | 操作者用白名单账号新建一个测试 issue,或按计划更新既有 issue/PR | 在活跃时段和限额内,当前会话收到首轮「【主理鱼】」唤醒;面板「判定」能解释结果 |
|
|
97
|
+
| 5 | 首轮处理后执行已确认的 `watch_ack` | 返回成功,ack 标签与本地水位更新;同一条目不会无变化重复唤醒 |
|
|
98
|
+
| 6 | 再跑 `watch_status`,需要时复查面板「总览 / 判定」 | watcher 仍在运行,首轮结果与 ack 可追溯 |
|
|
99
|
+
|
|
100
|
+
第 5 步的最小形式(替换仓库与编号):
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
watch_ack({repo:"owner/name", number:123, note:"安装验收:首轮唤醒已处理", comment:false})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`watch_ack` 即使 `comment:false` 也会写远端 ack 标签并推进本地水位,必须已包含在确认计划里。
|
|
107
|
+
`comment:true` 是另一项**显式写操作**:会把 `note` 作为评论发布到原 issue/PR,只有操作者明确同意评论正文后才使用;Gitee 回写 PR 时还要传 `kind:"pull"`。
|
|
108
|
+
|
|
109
|
+
最后交付:仓库与绑定会话、面板所见、首轮唤醒条目、ack 结果,以及 `watch_stop` 回滚方式。首轮先窄后宽,噪音偏大时优先收紧白名单或过滤,而不是增加唤醒频率。
|
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.
|
|
17
|
+
const CLIENT_VERSION = '0.9.262'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
|
@@ -1335,6 +1335,7 @@ window.__ModuleLoader__.load({
|
|
|
1335
1335
|
filterText(watcher.filters) ? h(Tag, null, filterText(watcher.filters)) : null,
|
|
1336
1336
|
// ack 标签决定这条是否还会被叫醒,不能只在工具参数里出现。
|
|
1337
1337
|
h(Tag, { tone: 'quiet' }, '回执 ' + (watcher.ackLabel || (watcher.provider === 'gitee' ? '主理鱼-已处理' : '主理鱼:已处理'))),
|
|
1338
|
+
watcher.queuedWakes > 0 ? h(Tag, { tone: 'warning' }, '排队 ' + watcher.queuedWakes) : null,
|
|
1338
1339
|
backoffText(watcher) ? h(Tag, { tone: 'warning' }, backoffText(watcher)) : null),
|
|
1339
1340
|
// 三行,各管一件事:① 是谁 ② 节律与最近结果 ③ 目标
|
|
1340
1341
|
// 原来六段用 ' · ' 串成一行(会话 · 每 60s · 轮询 · 唤醒 · 上次唤醒 · 目标),
|
package/docs/README.md
CHANGED
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
| 文档 | 什么时候读 |
|
|
6
6
|
|---|---|
|
|
7
7
|
| [README](../README.md) | 第一次接触这个插件:它做什么、怎么装、界面在哪、故障排查 |
|
|
8
|
+
| [SETUP](../SETUP.md) | 让 coding agent 陪操作者安装:只读探测、一次一问、计划确认、首轮唤醒验收 |
|
|
8
9
|
| [01-架构](01-架构.md) | 要改服务端逻辑:分层、11 步轮询管线、状态文件与落盘规则 |
|
|
9
10
|
| [design-system](design-system.md) | 要改界面:35 个设计 token、常用组件类、加页面的检查清单 |
|
|
10
11
|
| [official-gui-ia](official-gui-ia.md) | 想知道「官方原版长什么样、我们砍了什么、为什么」 |
|
|
11
12
|
| [awesome-submission](awesome-submission.md) | 要提交到 awesome-dsh-plugin:现成的 YAML、图标、核对结论 |
|
|
12
13
|
| [为什么做这个产品](为什么做这个产品.md) | **动任何功能之前先读**:谁在痛、三条不变量(不打断 / 不留手尾 / 不失控)、明确不做什么 |
|
|
13
14
|
| [对比-官方原型](对比-官方原型.md) | 想知道和官方 `dsh-superagent-prototype` 的功能差距、哪些该抄哪些不该 |
|
|
15
|
+
| [official-decomp/](official-decomp/01-structure-tree.md) | **完整官方结构树**:运行时/事件源/面板/提示词运维逐文件解构,以及已落地与待吸收清单 |
|
|
14
16
|
| [competitive-analysis](competitive-analysis.md) | 想知道和 Sweep / CodeRabbit 这类工具的差别 |
|
|
15
17
|
| [deepseek-papers](deepseek-papers.md) | 想知道设计取舍背后的研究依据 |
|
|
16
18
|
| [真机验证清单](真机验证清单.md) | 重启后三条命令 + 三个动作,5 分钟确认新代码在跑 |
|
package/lib/gitee.js
CHANGED
|
@@ -163,6 +163,12 @@ export async function addGiteeLabel({ repo, token = '', number, label, fetchImpl
|
|
|
163
163
|
return request(`/repos/${repo}/issues/${number}/labels`, { token, method: 'POST', body: { labels: [label] }, fetchImpl })
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
/** 回写处理结论(ack 的可选 Delivery)。PR 与 issue 的端点不同,调用方必须给 kind。 */
|
|
167
|
+
export async function addGiteeComment({ repo, token = '', number, body, kind = 'issue', fetchImpl } = {}) {
|
|
168
|
+
const segment = kind === 'pull' ? 'pulls' : 'issues'
|
|
169
|
+
return request(`/repos/${repo}/${segment}/${number}/comments`, { token, method: 'POST', body: { body: String(body || '') }, fetchImpl })
|
|
170
|
+
}
|
|
171
|
+
|
|
166
172
|
/** 当前 token 是谁(doctor 用)。 */
|
|
167
173
|
export async function giteeWhoami({ token = '', fetchImpl } = {}) {
|
|
168
174
|
return request('/user', { token, fetchImpl })
|
package/lib/index.js
CHANGED
|
@@ -24,7 +24,8 @@ import { zstdDecompressSync } from 'node:zlib'
|
|
|
24
24
|
import { redact } from './redact.js'
|
|
25
25
|
import { decodeBody, truncateUtf8 } from './body.js'
|
|
26
26
|
import { quotaDeferText, isOfflineMode } from './gh-format.js'
|
|
27
|
-
import { listGiteeItems, fetchGiteeLastComment, addGiteeLabel, ensureGiteeLabel, giteeWhoami, giteeRepo, mapGiteeRepoAccess, DEFAULT_ACK_LABEL_GITEE, giteeLabels, giteeHasLabel, isValidGiteeLabel, suggestGiteeLabel } from './gitee.js'
|
|
27
|
+
import { listGiteeItems, fetchGiteeLastComment, addGiteeLabel, addGiteeComment, ensureGiteeLabel, giteeWhoami, giteeRepo, mapGiteeRepoAccess, DEFAULT_ACK_LABEL_GITEE, giteeLabels, giteeHasLabel, isValidGiteeLabel, suggestGiteeLabel } from './gitee.js'
|
|
28
|
+
import { migrateState, CURRENT_STATE_SCHEMA } from './state-migration.js'
|
|
28
29
|
import {
|
|
29
30
|
effectiveIntervalMs, planWakeSettlement, advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, DEFAULT_PRIORITY, formatWatchText,
|
|
30
31
|
recordPendingWake, clearPending, pendingRetry,
|
|
@@ -46,7 +47,7 @@ import {
|
|
|
46
47
|
|
|
47
48
|
export const name = 'dsh-session-superagent'
|
|
48
49
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
49
|
-
export const SERVER_VERSION = '0.9.
|
|
50
|
+
export const SERVER_VERSION = '0.9.262'
|
|
50
51
|
export const inject = ['tools', 'agents', 'webServer']
|
|
51
52
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
52
53
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
|
@@ -111,7 +112,7 @@ const MAX_WATCHERS_TOTAL = 200
|
|
|
111
112
|
const CLEANUP_INTERVAL_MS = 10 * 60 * 1000
|
|
112
113
|
|
|
113
114
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
114
|
-
export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
|
|
115
|
+
export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, flushWakeQueue, wakeQueueCount, clearWakeQueues, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
|
|
115
116
|
|
|
116
117
|
// 审核 T30:这四个路径以前在**模块加载那一刻**定死 ——
|
|
117
118
|
// 测试里改 `process.env.DSH_SUPERAGENT_STATE` 之后,已经加载的实例仍然指着老目录,
|
|
@@ -172,14 +173,15 @@ function readState() {
|
|
|
172
173
|
return { watchers: {} }
|
|
173
174
|
}
|
|
174
175
|
try {
|
|
175
|
-
|
|
176
|
+
// 先显式迁移,再做兼容归一;未来版本会抛错并落到 .bak,不盲目按旧代码读取。
|
|
177
|
+
const parsed = migrateState(JSON.parse(raw)).state
|
|
176
178
|
for (const entry of Object.values(parsed.watchers || {})) { normalizePaused(entry); normalizeAckLabel(entry) }
|
|
177
179
|
stateSource = 'ok'
|
|
178
180
|
return parsed
|
|
179
181
|
} catch {
|
|
180
182
|
// 主文件坏了:试试备份
|
|
181
183
|
try {
|
|
182
|
-
const backup = JSON.parse(readFileSync(stateFile() + '.bak', 'utf8'))
|
|
184
|
+
const backup = migrateState(JSON.parse(readFileSync(stateFile() + '.bak', 'utf8'))).state
|
|
183
185
|
for (const entry of Object.values(backup.watchers || {})) { normalizePaused(entry); normalizeAckLabel(entry) }
|
|
184
186
|
stateSource = 'backup'
|
|
185
187
|
// 把备份写回主文件,避免下次还走恢复路径
|
|
@@ -291,6 +293,7 @@ function writeState(state, options = {}) {
|
|
|
291
293
|
if (Object.keys(tombstones).length > 0) merged.deleted = tombstones
|
|
292
294
|
else delete merged.deleted
|
|
293
295
|
|
|
296
|
+
merged.schemaVersion = CURRENT_STATE_SCHEMA
|
|
294
297
|
const text = JSON.stringify(merged, null, 1)
|
|
295
298
|
// 原子写:写一半崩掉不该把全部 watcher 清空
|
|
296
299
|
const tmp = stateFile() + '.tmp'
|
|
@@ -757,7 +760,81 @@ function defineTool(options) {
|
|
|
757
760
|
const WAKE_WINDOW_MS = Number(process.env.DSH_SUPERAGENT_WAKE_WINDOW_MS) || 3000
|
|
758
761
|
const wakeBuffers = new Map()
|
|
759
762
|
|
|
760
|
-
|
|
763
|
+
// 会话级 FIFO Outbox:忙时排队,空闲按顺序送。
|
|
764
|
+
// 只存内存;**未送达不推进水位**,所以宿主重启后下一轮会按原事件重建队列,不会丢。
|
|
765
|
+
const WAKE_QUEUE_RETRY_MS = Number(process.env.DSH_SUPERAGENT_WAKE_QUEUE_RETRY_MS) || 5000
|
|
766
|
+
const wakeQueues = new Map()
|
|
767
|
+
const isBusyWakeResult = (result) => /agent busy|会话正忙/i.test(String(result && result.reason || ''))
|
|
768
|
+
|
|
769
|
+
function wakeQueueCount(sessionId, ctx) {
|
|
770
|
+
const queue = wakeQueues.get(sessionId)
|
|
771
|
+
if (ctx && queue && queue.ctx !== ctx) return 0
|
|
772
|
+
return queue ? queue.items.length : 0
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function scheduleWakeFlush(ctx, sessionId, delay = WAKE_QUEUE_RETRY_MS) {
|
|
776
|
+
const queue = wakeQueues.get(sessionId)
|
|
777
|
+
if (!queue || queue.timer || queue.items.length === 0) return
|
|
778
|
+
queue.timer = setTimeout(() => {
|
|
779
|
+
queue.timer = null
|
|
780
|
+
flushWakeQueue(ctx, sessionId)
|
|
781
|
+
}, delay)
|
|
782
|
+
if (queue.timer && typeof queue.timer.unref === 'function') queue.timer.unref()
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
function flushWakeQueue(ctx, sessionId) {
|
|
786
|
+
const queue = wakeQueues.get(sessionId)
|
|
787
|
+
if (!queue || queue.items.length === 0 || (queue.ctx && queue.ctx !== ctx)) return
|
|
788
|
+
const item = queue.items[0]
|
|
789
|
+
const result = wake(ctx, sessionId, item.text)
|
|
790
|
+
if (isBusyWakeResult(result)) {
|
|
791
|
+
scheduleWakeFlush(ctx, sessionId)
|
|
792
|
+
return
|
|
793
|
+
}
|
|
794
|
+
// 只有离开队首的这一条才结算:成功记已送达;非 busy 失败交给原有错误/重试逻辑。
|
|
795
|
+
queue.items.shift()
|
|
796
|
+
for (const cb of item.settled) {
|
|
797
|
+
try { cb(result) } catch { /* 单个 watcher 的结算失败不能堵住后面的队列 */ }
|
|
798
|
+
}
|
|
799
|
+
if (queue.items.length > 0) scheduleWakeFlush(ctx, sessionId, 0)
|
|
800
|
+
else wakeQueues.delete(sessionId)
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function enqueueWake(ctx, sessionId, text, settled, key) {
|
|
804
|
+
let queue = wakeQueues.get(sessionId)
|
|
805
|
+
// 热重载后的新实例不能接管旧实例的回调与上下文;未送达水位未推进,旧事件会由新轮询重建。
|
|
806
|
+
if (queue && queue.ctx !== ctx) {
|
|
807
|
+
if (queue.timer) clearTimeout(queue.timer)
|
|
808
|
+
queue = null
|
|
809
|
+
}
|
|
810
|
+
queue = queue || { items: [], timer: null, ctx }
|
|
811
|
+
queue.items.push({ text, settled, key, queuedAt: new Date().toISOString() })
|
|
812
|
+
wakeQueues.set(sessionId, queue)
|
|
813
|
+
scheduleWakeFlush(ctx, sessionId)
|
|
814
|
+
return { ok: false, queued: true, reason: '会话正忙(agent busy),已排队(第 ' + queue.items.length + ' 条)—— 空闲后按顺序送达' }
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
function hasQueuedWake(sessionId, key, ctx) {
|
|
818
|
+
const queue = wakeQueues.get(sessionId)
|
|
819
|
+
return Boolean(key && queue && (!ctx || queue.ctx === ctx) && queue.items.some((item) => item.key === key))
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
function clearWakeQueues(ctx) {
|
|
823
|
+
for (const [sessionId, queue] of wakeQueues) {
|
|
824
|
+
if (ctx && queue.ctx !== ctx) continue
|
|
825
|
+
if (queue.timer) clearTimeout(queue.timer)
|
|
826
|
+
wakeQueues.delete(sessionId)
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
function wakeMerged(ctx, sessionId, text, onSettled, queueKey = '') {
|
|
831
|
+
// 同一事件已在队列里时不重复入队;先尝试 flush,空闲时会立即把旧队列送完。
|
|
832
|
+
flushWakeQueue(ctx, sessionId)
|
|
833
|
+
if (hasQueuedWake(sessionId, queueKey, ctx)) {
|
|
834
|
+
const result = { ok: false, queued: true, reason: '会话正忙(agent busy),该事件已在队列中,不重复入队' }
|
|
835
|
+
if (onSettled) onSettled(result)
|
|
836
|
+
return { ok: true, merged: false, queued: true }
|
|
837
|
+
}
|
|
761
838
|
const now = Date.now()
|
|
762
839
|
const buf = wakeBuffers.get(sessionId) || { parts: [], timer: null, openedAt: now, settled: [] }
|
|
763
840
|
buf.parts.push(text)
|
|
@@ -768,7 +845,10 @@ function wakeMerged(ctx, sessionId, text, onSettled) {
|
|
|
768
845
|
let result = { ok: false, reason: '合并后没有内容可发(这几条都已被处理过)—— 不用管,下一轮会重新判断' }
|
|
769
846
|
try {
|
|
770
847
|
const merged = mergeWakeTexts(buf.parts)
|
|
771
|
-
if (merged)
|
|
848
|
+
if (merged) {
|
|
849
|
+
result = wake(ctx, sessionId, merged)
|
|
850
|
+
if (isBusyWakeResult(result)) result = enqueueWake(ctx, sessionId, merged, buf.settled, queueKey)
|
|
851
|
+
}
|
|
772
852
|
} catch (error) {
|
|
773
853
|
result = { ok: false, reason: String((error && error.message) || error) }
|
|
774
854
|
}
|
|
@@ -1521,6 +1601,7 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
|
1521
1601
|
// 记账一律放到「真正发送之后」:
|
|
1522
1602
|
// 之前是入队即记账 —— 会话忙时 decideWake 会拒绝,次数却已经记了、seen 也已经推进,
|
|
1523
1603
|
// 于是那几条既不会重试(seen 已推进)又白白占掉名额。这是会丢消息的 bug。
|
|
1604
|
+
const wakeQueueKey = entry.id + '|' + fresh.map((item) => String(item.number) + '@' + String(item.updated_at || '')).join(',')
|
|
1524
1605
|
wakeMerged(ctx, entry.sessionId, wakeText, (result) => {
|
|
1525
1606
|
// 审核 T20:结算逻辑抽成纯函数 planWakeSettlement()(有单测),这里只负责落副作用。
|
|
1526
1607
|
const settled = planWakeSettlement(entry, {
|
|
@@ -1560,7 +1641,7 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
|
1560
1641
|
if (settled.lastDeferred) entry.lastDeferred = settled.lastDeferred
|
|
1561
1642
|
if (settled.bumpBackoff) bumpFailure(entry, baseMs)
|
|
1562
1643
|
} persistEntry(entry)
|
|
1563
|
-
})
|
|
1644
|
+
}, wakeQueueKey)
|
|
1564
1645
|
}
|
|
1565
1646
|
|
|
1566
1647
|
export function apply(ctx) {
|
|
@@ -1781,6 +1862,8 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1781
1862
|
// 面板要能一眼分出 GitHub / Gitee:否则行内只能靠 id 前缀猜
|
|
1782
1863
|
provider: w.provider === 'gitee' ? 'gitee' : 'github',
|
|
1783
1864
|
ackLabel: w.ackLabel || defaultAckLabel(w.provider),
|
|
1865
|
+
// 会话忙时真正排在 FIFO 里的条数;0 表示没有排队,不靠猜 lastDeferred。
|
|
1866
|
+
queuedWakes: wakeQueueCount(w.sessionId, ctx),
|
|
1784
1867
|
sessionId: w.sessionId,
|
|
1785
1868
|
intervalSec: w.intervalSec,
|
|
1786
1869
|
enabled: isEnabled(w),
|
|
@@ -2323,6 +2406,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2323
2406
|
// 插件卸载/热重载后旧定时器不能继续跑:它们还持有已 dispose 的 ctx
|
|
2324
2407
|
for (const handle of timers.values()) { try { clearInterval(handle) } catch {} }
|
|
2325
2408
|
timers.clear()
|
|
2409
|
+
clearWakeQueues(ctx)
|
|
2326
2410
|
try { clearInterval(sweepHandle) } catch {}
|
|
2327
2411
|
}
|
|
2328
2412
|
// 两条路都挂上:ctx.effect 的清理函数在 effect 作用域销毁时一定被调用;
|
|
@@ -2383,6 +2467,8 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2383
2467
|
numbers: { type: 'string', description: '逗号分隔的多个编号,如 "12,13,14"(number 与 numbers 至少填一个)' },
|
|
2384
2468
|
label: { type: 'string', description: 'ack label, default 主理鱼:已处理' },
|
|
2385
2469
|
note: { type: 'string', description: '可选:一句话记下这条最后怎么处理的(如「已修,见 #57」「不修,上游已修」)。下次这条再被叫醒时会带回来,省得会话重新判一遍。' },
|
|
2470
|
+
comment: { type: 'boolean', description: '把 note 作为评论回写到原 issue/PR(默认 false)。必须同时给 note;这是显式写操作。' },
|
|
2471
|
+
kind: { type: 'string', description: "Gitee 评论回写时的条目类型:'issue'(默认)或 'pull';GitHub 不需要。" },
|
|
2386
2472
|
format: { type: 'string', description: "'text' (default) or 'json'." },
|
|
2387
2473
|
},
|
|
2388
2474
|
async execute(args) {
|
|
@@ -2406,6 +2492,8 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2406
2492
|
: watchers.find((w) => w && w.enabled)
|
|
2407
2493
|
if (!entry) return toolError(args, 'no watcher for that repo — start one with watch_start first')
|
|
2408
2494
|
const label = String(args.label || entry.ackLabel || defaultAckLabel(entry.provider))
|
|
2495
|
+
const note = typeof args.note === 'string' ? args.note.trim().slice(0, 200) : ''
|
|
2496
|
+
if (args.comment === true && !note) return toolError(args, 'comment:true 需要同时提供 note —— 不会发一条空评论')
|
|
2409
2497
|
// GitHub 不会因为加标签而自动建标签:不存在时返回 422。先幂等建一次(已存在也返回 422,忽略)。
|
|
2410
2498
|
// Gitee 没有「建标签」的独立端点(标签必须先存在),所以这边只打标签;
|
|
2411
2499
|
// 标签不存在时它会 404 —— 让调用方看到真实原因,别假装成功。
|
|
@@ -2429,9 +2517,22 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2429
2517
|
})()
|
|
2430
2518
|
: await run('gh', ['api', '-X', 'POST', `repos/${entry.repo}/issues/${number}/labels`, '-f', `labels[]=${label}`], { env: ghEnv() })
|
|
2431
2519
|
if (res.code !== 0) {
|
|
2432
|
-
failed = { number, text: redact([res.stdout, res.stderr].filter(Boolean).join(' ').trim()).slice(0, 200) }
|
|
2520
|
+
failed = { number, text: redact([res.stdout, res.stderr].filter(Boolean).join(' ').trim()).slice(0, 200), phase: 'label' }
|
|
2433
2521
|
break
|
|
2434
2522
|
}
|
|
2523
|
+
// Delivery(官方原型可吸收的一部分):处理结论不只留在本地,显式 comment:true 时回写原条目。
|
|
2524
|
+
if (args.comment === true) {
|
|
2525
|
+
const posted = entry.provider === 'gitee'
|
|
2526
|
+
? await (async () => {
|
|
2527
|
+
const r = await addGiteeComment({ repo: entry.repo, token: String(readSecrets().giteeToken || ''), number, body: note, kind: args.kind === 'pull' ? 'pull' : 'issue' })
|
|
2528
|
+
return { code: r.ok ? 0 : 1, stdout: '', stderr: r.ok ? '' : String(r.status || '') + ' ' + String(r.error || '') }
|
|
2529
|
+
})()
|
|
2530
|
+
: await run('gh', ['api', '-X', 'POST', `repos/${entry.repo}/issues/${number}/comments`, '-f', `body=${note}`], { env: ghEnv() })
|
|
2531
|
+
if (posted.code !== 0) {
|
|
2532
|
+
failed = { number, text: redact([posted.stdout, posted.stderr].filter(Boolean).join(' ').trim()).slice(0, 200), phase: 'comment' }
|
|
2533
|
+
break
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2435
2536
|
results.push(number)
|
|
2436
2537
|
}
|
|
2437
2538
|
if (failed) {
|
|
@@ -2450,12 +2551,13 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2450
2551
|
if (args && args.format === 'json') {
|
|
2451
2552
|
return JSON.stringify({
|
|
2452
2553
|
schemaVersion: 1, ok: false, repo: entry.repo, acked: results,
|
|
2453
|
-
failed: { number: failed.number, text: failed.text, kind: why.kind, retryable, advice },
|
|
2554
|
+
failed: { number: failed.number, text: failed.text, kind: why.kind, retryable, advice, phase: failed.phase || 'label' },
|
|
2454
2555
|
})
|
|
2455
2556
|
}
|
|
2557
|
+
const phaseNote = failed.phase === 'comment' ? '(标签已打,评论回写失败)' : ''
|
|
2456
2558
|
return retryable
|
|
2457
|
-
? `[error: #${failed.number} ${advice}(${label})]`
|
|
2458
|
-
: `[error: #${failed.number} ${advice}] ${why.hint}`
|
|
2559
|
+
? `[error: #${failed.number} ${advice}(${label})]${phaseNote}`
|
|
2560
|
+
: `[error: #${failed.number} ${advice}] ${why.hint}${phaseNote}`
|
|
2459
2561
|
}
|
|
2460
2562
|
const latest = readState()
|
|
2461
2563
|
const live = latest.watchers && latest.watchers[entry.id]
|
|
@@ -2470,7 +2572,6 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2470
2572
|
// 「叫醒之后」的闭环(见 docs/为什么做这个产品.md 诉求 2):
|
|
2471
2573
|
// 以前只记「叫醒过」,不记「怎么处理的」—— 同一条被重开时会话只能重新判一遍。
|
|
2472
2574
|
// 有界:只留最近 20 条,超出丢最旧的。
|
|
2473
|
-
const note = typeof args.note === 'string' ? args.note.trim().slice(0, 200) : ''
|
|
2474
2575
|
if (note) {
|
|
2475
2576
|
const acked = { ...(live.acked || {}) }
|
|
2476
2577
|
for (const number of results) acked[String(number)] = { at: nowIso, note }
|
|
@@ -2481,10 +2582,11 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2481
2582
|
}
|
|
2482
2583
|
if (args && args.format === 'json') {
|
|
2483
2584
|
// labelNote 是「标签是新建的还是本来就有的」——JSON 分支以前把它丢了,消费方只能猜
|
|
2484
|
-
return JSON.stringify({ schemaVersion: 1, ok: true, repo: entry.repo, label, acked: results, at: nowIso, labelNote: labelNote || null })
|
|
2585
|
+
return JSON.stringify({ schemaVersion: 1, ok: true, repo: entry.repo, label, acked: results, at: nowIso, labelNote: labelNote || null, ...(args.comment === true ? { commented: true } : {}) })
|
|
2485
2586
|
}
|
|
2486
2587
|
return `acked ${entry.repo} #${results.join(' #')} with label "${label}"` + labelNote
|
|
2487
2588
|
+ (typeof args.note === 'string' && args.note.trim() ? '|记下了:' + args.note.trim().slice(0, 200) : '')
|
|
2589
|
+
+ (args.comment === true ? '|已回写评论' : '')
|
|
2488
2590
|
},
|
|
2489
2591
|
}))
|
|
2490
2592
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* watchers.json 的显式 schema 迁移入口。
|
|
3
|
+
*
|
|
4
|
+
* 吸收官方 migration 的最小纪律:先迁移、再 normalize;未知未来版本拒绝;
|
|
5
|
+
* 失败交给 readState 的 .bak 恢复,不把半新半旧的状态当成正常状态。
|
|
6
|
+
* 这里只做我们实际需要的 v0 → v1,不搬 SQLite 迁移框架。
|
|
7
|
+
*/
|
|
8
|
+
export const CURRENT_STATE_SCHEMA = 1
|
|
9
|
+
|
|
10
|
+
export function migrateState(input) {
|
|
11
|
+
const raw = input && typeof input === 'object' && !Array.isArray(input) ? input : {}
|
|
12
|
+
const version = raw.schemaVersion === undefined ? 0 : Number(raw.schemaVersion)
|
|
13
|
+
if (!Number.isInteger(version) || version < 0) throw new Error('invalid state schemaVersion: ' + String(raw.schemaVersion))
|
|
14
|
+
if (version > CURRENT_STATE_SCHEMA) {
|
|
15
|
+
throw new Error('state schemaVersion ' + version + ' is newer than supported ' + CURRENT_STATE_SCHEMA)
|
|
16
|
+
}
|
|
17
|
+
if (version === CURRENT_STATE_SCHEMA) return { state: raw, changed: false, from: version }
|
|
18
|
+
// v0:没有 schemaVersion 的历史文件。保留所有已有字段,只补版本与必需容器。
|
|
19
|
+
const state = {
|
|
20
|
+
...raw,
|
|
21
|
+
schemaVersion: CURRENT_STATE_SCHEMA,
|
|
22
|
+
watchers: raw.watchers && typeof raw.watchers === 'object' && !Array.isArray(raw.watchers) ? raw.watchers : {},
|
|
23
|
+
}
|
|
24
|
+
return { state, changed: true, from: version }
|
|
25
|
+
}
|
package/lib/watch.js
CHANGED
|
@@ -108,11 +108,6 @@ export function advanceSeen(seen, fresh) {
|
|
|
108
108
|
return next
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
/** Build the wake text. Stable shape: one line per item, then the rule reminder. */
|
|
112
|
-
/**
|
|
113
|
-
* 唤醒消息 = 任务书。竞品的触发都带足上下文(类型、状态、作者、标签、是否草稿),
|
|
114
|
-
* 否则 agent 醒来还得自己查一遍。这里一次给全。
|
|
115
|
-
*/
|
|
116
111
|
/**
|
|
117
112
|
* 唤醒消息里的「完成标准」三条。
|
|
118
113
|
*
|
|
@@ -135,8 +130,15 @@ export function wakeCriteria({ isolation } = {}) {
|
|
|
135
130
|
// KB: actionable-suggestion.md —— 每个提示都要能回答「我现在该做什么」
|
|
136
131
|
// KB: actionable-does-not-mean-repeated.md —— 可执行 ≠ 把同一份指令印 N 遍(见 mergeWakeTexts)
|
|
137
132
|
// KB: error-must-have-next-step.md —— 每个错误都要带下一步
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
/**
|
|
134
|
+
* 唤醒消息 = 有序 section,而不是按角色拆分。竞品的触发都带足上下文
|
|
135
|
+
* (类型、状态、作者、标签、是否草稿),否则 agent 醒来还得自己查一遍。
|
|
136
|
+
*
|
|
137
|
+
* 每个 section 都是 `{ id, lines }`:id 稳定、lines 可直接断言或覆盖;
|
|
138
|
+
* 没有内容的可选 section 省略,header / facts / next 始终保留。
|
|
139
|
+
*/
|
|
140
|
+
export function buildWakeSections(repo, items, options = {}) {
|
|
141
|
+
const list = items ?? []
|
|
140
142
|
const more = Number(options.more) || 0
|
|
141
143
|
const lines = list.map((item) => {
|
|
142
144
|
const kind = item.pull_request ? 'PR' : 'issue'
|
|
@@ -202,12 +204,12 @@ export function formatWatchText(repo, fresh, options = {}) {
|
|
|
202
204
|
const rest = (options.restNumbers ?? []).map((n) => '#' + n).join(' ')
|
|
203
205
|
const iso = options.isolation
|
|
204
206
|
const isoLine = iso && iso.dir
|
|
205
|
-
?
|
|
207
|
+
? `【隔离工作区】${iso.dir}(分支 ${iso.branch})—— 只在这里改,推这个分支开 PR,别碰主工作区;用完 git worktree remove 掉。`
|
|
206
208
|
: iso && iso.error
|
|
207
|
-
?
|
|
209
|
+
? `【隔离失败】${iso.error};这次请谨慎,改完别留下未提交内容。`
|
|
208
210
|
: ''
|
|
209
211
|
const goalLine = options.goal
|
|
210
|
-
?
|
|
212
|
+
? `本条目主理目标:${String(options.goal).split(String.fromCharCode(13)).join(' ').split(String.fromCharCode(10)).join(' ').slice(0, 200)}`
|
|
211
213
|
: ''
|
|
212
214
|
// 身份说明:插件调 gh 用的是它绑定的账号,会话里跑的 git push 用的是会话自己的环境。
|
|
213
215
|
// 不说明的话,gh 评论挂智能体名下、git 提交挂操作者名下 —— 一次改动两个作者。
|
|
@@ -216,11 +218,11 @@ export function formatWatchText(repo, fresh, options = {}) {
|
|
|
216
218
|
// 进对话记录、可能被后续总结引用;带路径就等于把本机用户目录一并带出去。
|
|
217
219
|
// 会话只要知道「该问用户」就够了 —— 用户本来就知道自己的路径。
|
|
218
220
|
const identityLine = options.identityBound
|
|
219
|
-
?
|
|
221
|
+
? '【提交身份】本插件的 gh 已绑定单独的智能体账号。你在会话里执行 git / git push 时如需一致身份,'
|
|
220
222
|
+ '请向用户索取该账号的 gh 配置目录并设 GH_CONFIG_DIR;否则提交会落到操作者账号上。'
|
|
221
223
|
: ''
|
|
222
224
|
const moreLine = more > 0
|
|
223
|
-
?
|
|
225
|
+
? `(另有 ${more} 条:${rest},处理完这批再看)`
|
|
224
226
|
: ''
|
|
225
227
|
// 「为什么是这几条」:只给结果不给依据,会话/客户都没法判断要不要调过滤条件。
|
|
226
228
|
// 依据:GitHub 的通知带 reason(为什么通知你)、Slack 摘要会说明分组依据 —— 同一个道理。
|
|
@@ -250,34 +252,45 @@ export function formatWatchText(repo, fresh, options = {}) {
|
|
|
250
252
|
const more = Object.keys(options.skippedReasons).length > skipped.length ? ' 等' : ''
|
|
251
253
|
parts.push('本轮跳过 ' + total + ' 条(' + skipped.map(([reason, n]) => reason + ' × ' + n).join('、') + more + ')')
|
|
252
254
|
}
|
|
253
|
-
return parts.length > 0 ?
|
|
255
|
+
return parts.length > 0 ? '【为什么是这几条】' + parts.join(';') : ''
|
|
254
256
|
})()
|
|
255
257
|
// 完成标准要「可观测」:只说"做好它"等于没说。
|
|
256
258
|
// 依据:Given-When-Then 的核心是把验收写成可观察的结果(martinfowler.com/bliki/GivenWhenThen.html)。
|
|
257
|
-
const accessLine = options.access ?
|
|
259
|
+
const accessLine = options.access ? '【权限提示】' + options.access : ''
|
|
258
260
|
const criteria = Array.isArray(options.criteria) ? options.criteria.filter(Boolean).slice(0, 4) : []
|
|
259
|
-
const
|
|
260
|
-
?
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
lines.join('\n') +
|
|
268
|
-
whyLine +
|
|
269
|
-
moreLine +
|
|
270
|
-
isoLine +
|
|
271
|
-
goalLine +
|
|
272
|
-
identityLine +
|
|
273
|
-
accessLine +
|
|
274
|
-
criteriaLine +
|
|
275
|
-
'\n\n接下来:先读仓库 AGENTS.md 定「修 / 回 / 待定」;没有测试结果不算完成;' +
|
|
276
|
-
(options.provider === 'gitee'
|
|
261
|
+
const criteriaLines = criteria.length > 0
|
|
262
|
+
? ['【完成标准】', ...criteria.map((line, i) => (i + 1) + '. ' + line)]
|
|
263
|
+
: []
|
|
264
|
+
const headerLine = options.firstSync
|
|
265
|
+
? `【主理鱼】${repo} 首次同步:仓库里现有 ${lines.length} 条待处理(接上之前就在的,不是刚刚发生):`
|
|
266
|
+
: `【主理鱼】${repo} 有 ${lines.length} 条新动态:`
|
|
267
|
+
const nextLine = '接下来:先读仓库 AGENTS.md 定「修 / 回 / 待定」;没有测试结果不算完成;'
|
|
268
|
+
+ (options.provider === 'gitee'
|
|
277
269
|
// Gitee 没有 gh CLI:回写走网页/API,别让会话去跑 gh 命令
|
|
278
270
|
? '做完一条就写回 Gitee(网页或 API 都行)+ watch_ack 打标签,不要扩大范围。'
|
|
279
271
|
: '做完一条就写回 GitHub + watch_ack 打标签,不要扩大范围。')
|
|
280
|
-
|
|
272
|
+
|
|
273
|
+
const sections = [
|
|
274
|
+
{ id: 'header', lines: [headerLine] },
|
|
275
|
+
{ id: 'facts', lines },
|
|
276
|
+
]
|
|
277
|
+
if (whyLine) sections.push({ id: 'selection', lines: [whyLine] })
|
|
278
|
+
if (moreLine) sections.push({ id: 'overflow', lines: [moreLine] })
|
|
279
|
+
if (isoLine) sections.push({ id: 'isolation', lines: [isoLine] })
|
|
280
|
+
if (goalLine) sections.push({ id: 'goal', lines: [goalLine] })
|
|
281
|
+
if (identityLine) sections.push({ id: 'identity', lines: [identityLine] })
|
|
282
|
+
if (accessLine) sections.push({ id: 'access', lines: [accessLine] })
|
|
283
|
+
if (criteriaLines.length > 0) sections.push({ id: 'criteria', lines: criteriaLines })
|
|
284
|
+
// 空行属于 next section:无论 criteria 是否存在,收尾前都保持原有的一个空行。
|
|
285
|
+
sections.push({ id: 'next', lines: ['', nextLine] })
|
|
286
|
+
return sections
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** 把有序 sections 渲染成唤醒文本;两层 join 也保留空 facts 的旧空行行为。 */
|
|
290
|
+
export function formatWatchText(repo, fresh, options = {}) {
|
|
291
|
+
return buildWakeSections(repo, fresh, options)
|
|
292
|
+
.map((section) => section.lines.join('\n'))
|
|
293
|
+
.join('\n')
|
|
281
294
|
}
|
|
282
295
|
|
|
283
296
|
// ── 竞品蒸馏出来的四道闸(见 docs/competitive-analysis.md) ────────────────
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.262",
|
|
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",
|
|
@@ -18,8 +18,10 @@
|
|
|
18
18
|
"lib/redact.js",
|
|
19
19
|
"lib/body.js",
|
|
20
20
|
"lib/gitee.js",
|
|
21
|
+
"lib/state-migration.js",
|
|
21
22
|
"cordis.patch.yml",
|
|
22
23
|
"README.md",
|
|
24
|
+
"SETUP.md",
|
|
23
25
|
"CHANGELOG.md",
|
|
24
26
|
"LICENSE",
|
|
25
27
|
"client.js",
|